1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 01, 02
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
71 #include "character.h"
75 #include "dispextern.h"
77 #include "termhooks.h"
85 #include "intervals.h"
91 #include <X11/Shell.h>
94 #ifdef HAVE_SYS_TIME_H
102 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
103 extern void xlwmenu_redisplay
P_ ((Widget
));
108 extern void free_frame_menubar
P_ ((struct frame
*));
109 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
112 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
114 extern void _XEditResCheckMessages ();
115 #endif /* not NO_EDITRES */
117 /* Include toolkit specific headers for the scroll bar widget. */
119 #ifdef USE_TOOLKIT_SCROLL_BARS
120 #if defined USE_MOTIF
121 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
122 #include <Xm/ScrollBar.h>
123 #else /* !USE_MOTIF i.e. use Xaw */
126 #include <X11/Xaw3d/Simple.h>
127 #include <X11/Xaw3d/Scrollbar.h>
128 #define ARROW_SCROLLBAR
129 #include <X11/Xaw3d/ScrollbarP.h>
130 #else /* !HAVE_XAW3D */
131 #include <X11/Xaw/Simple.h>
132 #include <X11/Xaw/Scrollbar.h>
133 #endif /* !HAVE_XAW3D */
135 #define XtNpickTop "pickTop"
136 #endif /* !XtNpickTop */
137 #endif /* !USE_MOTIF */
138 #endif /* USE_TOOLKIT_SCROLL_BARS */
140 #endif /* USE_X_TOOLKIT */
142 #ifndef USE_X_TOOLKIT
143 #define x_any_window_to_frame x_window_to_frame
144 #define x_top_window_to_frame x_window_to_frame
149 #ifndef XtNinitialState
150 #define XtNinitialState "initialState"
155 /* This isn't prototyped in OSF 5.0 or or XFree 4.1. */
156 extern char * XSetIMValues
P_ ((XIM
, ...));
159 #define abs(x) ((x) < 0 ? -(x) : (x))
161 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
164 /* Fringe bitmaps. */
166 enum fringe_bitmap_type
169 LEFT_TRUNCATION_BITMAP
,
170 RIGHT_TRUNCATION_BITMAP
,
171 OVERLAY_ARROW_BITMAP
,
172 CONTINUED_LINE_BITMAP
,
173 CONTINUATION_LINE_BITMAP
,
177 /* Bitmap drawn to indicate lines not displaying text if
178 `indicate-empty-lines' is non-nil. */
183 static unsigned char zv_bits
[] = {
184 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
185 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
186 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
187 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
188 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
189 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
190 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
191 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 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
;
240 /* Default to using XIM if available. */
243 /* Non-nil means Emacs uses toolkit scroll bars. */
245 Lisp_Object Vx_toolkit_scroll_bars
;
247 /* If a string, XTread_socket generates an event to display that string.
248 (The display is done in read_char.) */
250 static Lisp_Object help_echo
;
251 static Lisp_Object help_echo_window
;
252 static Lisp_Object help_echo_object
;
253 static int help_echo_pos
;
255 /* Temporary variable for XTread_socket. */
257 static Lisp_Object previous_help_echo
;
259 /* Non-zero means that a HELP_EVENT has been generated since Emacs
262 static int any_help_event_p
;
264 /* Non-zero means autoselect window with the mouse cursor. */
266 int x_autoselect_window_p
;
268 /* Non-zero means draw block and hollow cursor as wide as the glyph
269 under it. For example, if a block cursor is over a tab, it will be
270 drawn as wide as that tab on the display. */
272 int x_stretch_cursor_p
;
274 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
276 int x_use_underline_position_properties
;
278 /* This is a chain of structures for all the X displays currently in
281 struct x_display_info
*x_display_list
;
283 /* This is a list of cons cells, each of the form (NAME
284 . FONT-LIST-CACHE), one for each element of x_display_list and in
285 the same order. NAME is the name of the frame. FONT-LIST-CACHE
286 records previous values returned by x-list-fonts. */
288 Lisp_Object x_display_name_list
;
290 /* Frame being updated by update_frame. This is declared in term.c.
291 This is set by update_begin and looked at by all the XT functions.
292 It is zero while not inside an update. In that case, the XT
293 functions assume that `selected_frame' is the frame to apply to. */
295 extern struct frame
*updating_frame
;
297 /* This is a frame waiting to be auto-raised, within XTread_socket. */
299 struct frame
*pending_autoraise_frame
;
302 /* The application context for Xt use. */
303 XtAppContext Xt_app_con
;
304 static String Xt_default_resources
[] = {0};
305 #endif /* USE_X_TOOLKIT */
307 /* Nominal cursor position -- where to draw output.
308 HPOS and VPOS are window relative glyph matrix coordinates.
309 X and Y are window relative pixel coordinates. */
311 struct cursor_pos output_cursor
;
313 /* Non-zero means user is interacting with a toolkit scroll bar. */
315 static int toolkit_scroll_bar_interaction
;
319 Formerly, we used PointerMotionHintMask (in standard_event_mask)
320 so that we would have to call XQueryPointer after each MotionNotify
321 event to ask for another such event. However, this made mouse tracking
322 slow, and there was a bug that made it eventually stop.
324 Simply asking for MotionNotify all the time seems to work better.
326 In order to avoid asking for motion events and then throwing most
327 of them away or busy-polling the server for mouse positions, we ask
328 the server for pointer motion hints. This means that we get only
329 one event per group of mouse movements. "Groups" are delimited by
330 other kinds of events (focus changes and button clicks, for
331 example), or by XQueryPointer calls; when one of these happens, we
332 get another MotionNotify event the next time the mouse moves. This
333 is at least as efficient as getting motion events when mouse
334 tracking is on, and I suspect only negligibly worse when tracking
337 /* Where the mouse was last time we reported a mouse event. */
339 FRAME_PTR last_mouse_frame
;
340 static XRectangle last_mouse_glyph
;
341 static Lisp_Object last_mouse_press_frame
;
343 /* The scroll bar in which the last X motion event occurred.
345 If the last X motion event occurred in a scroll bar, we set this so
346 XTmouse_position can know whether to report a scroll bar motion or
349 If the last X motion event didn't occur in a scroll bar, we set
350 this to Qnil, to tell XTmouse_position to return an ordinary motion
353 static Lisp_Object last_mouse_scroll_bar
;
355 /* This is a hack. We would really prefer that XTmouse_position would
356 return the time associated with the position it returns, but there
357 doesn't seem to be any way to wrest the time-stamp from the server
358 along with the position query. So, we just keep track of the time
359 of the last movement we received, and return that in hopes that
360 it's somewhat accurate. */
362 static Time last_mouse_movement_time
;
364 /* Incremented by XTread_socket whenever it really tries to read
368 static int volatile input_signal_count
;
370 static int input_signal_count
;
373 /* Used locally within XTread_socket. */
375 static int x_noop_count
;
377 /* Initial values of argv and argc. */
379 extern char **initial_argv
;
380 extern int initial_argc
;
382 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
384 /* Tells if a window manager is present or not. */
386 extern Lisp_Object Vx_no_window_manager
;
388 extern Lisp_Object Qface
, Qmouse_face
, Qeql
;
392 /* A mask of extra modifier bits to put into every keyboard char. */
394 extern int extra_keyboard_modifiers
;
396 /* The keysyms to use for the various modifiers. */
398 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
399 Lisp_Object Vx_keysym_table
;
400 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
402 static Lisp_Object Qvendor_specific_keysyms
;
404 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
405 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
408 /* Enumeration for overriding/changing the face to use for drawing
409 glyphs in x_draw_glyphs. */
411 enum draw_glyphs_face
421 static int cursor_in_mouse_face_p
P_ ((struct window
*));
422 static int clear_mouse_face
P_ ((struct x_display_info
*));
423 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
424 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
425 static const XColor
*x_color_cells
P_ ((Display
*, int *));
426 static void x_update_window_end
P_ ((struct window
*, int, int));
427 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
428 void x_delete_display
P_ ((struct x_display_info
*));
429 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
431 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
432 int *, int *, Lisp_Object
));
433 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
434 int *, int *, int *, int *, int));
435 static void set_output_cursor
P_ ((struct cursor_pos
*));
436 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
437 int *, int *, int *, int));
438 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
439 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
440 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
441 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
442 static void show_mouse_face
P_ ((struct x_display_info
*,
443 enum draw_glyphs_face
));
444 static int x_io_error_quitter
P_ ((Display
*));
445 int x_catch_errors
P_ ((Display
*));
446 void x_uncatch_errors
P_ ((Display
*, int));
447 void x_lower_frame
P_ ((struct frame
*));
448 void x_scroll_bar_clear
P_ ((struct frame
*));
449 int x_had_errors_p
P_ ((Display
*));
450 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
451 void x_raise_frame
P_ ((struct frame
*));
452 void x_set_window_size
P_ ((struct frame
*, int, int, int));
453 void x_wm_set_window_state
P_ ((struct frame
*, int));
454 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
455 void x_initialize
P_ ((void));
456 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
457 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
458 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
460 enum draw_glyphs_face
));
461 static void x_update_end
P_ ((struct frame
*));
462 static void XTframe_up_to_date
P_ ((struct frame
*));
463 static void XTset_terminal_modes
P_ ((void));
464 static void XTreset_terminal_modes
P_ ((void));
465 static void XTcursor_to
P_ ((int, int, int, int));
466 static void x_write_glyphs
P_ ((struct glyph
*, int));
467 static void x_clear_end_of_line
P_ ((int));
468 static void x_clear_frame
P_ ((void));
469 static void x_clear_cursor
P_ ((struct window
*));
470 static void frame_highlight
P_ ((struct frame
*));
471 static void frame_unhighlight
P_ ((struct frame
*));
472 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
473 static void XTframe_rehighlight
P_ ((struct frame
*));
474 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
475 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
476 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
477 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
479 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
480 static int expose_window_tree
P_ ((struct window
*, XRectangle
*));
481 static int expose_window
P_ ((struct window
*, XRectangle
*));
482 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
483 XRectangle
*, enum glyph_row_area
));
484 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
486 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
487 static void x_update_window_cursor
P_ ((struct window
*, int));
488 static void x_erase_phys_cursor
P_ ((struct window
*));
489 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
490 static void x_draw_fringe_bitmap
P_ ((struct window
*, struct glyph_row
*,
491 enum fringe_bitmap_type
, int left_p
));
493 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
495 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
496 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*, struct glyph_row
*));
497 static void notice_overwritten_cursor
P_ ((struct window
*, enum glyph_row_area
,
498 int, int, int, int));
499 static void x_flush
P_ ((struct frame
*f
));
500 static void x_update_begin
P_ ((struct frame
*));
501 static void x_update_window_begin
P_ ((struct window
*));
502 static void x_draw_vertical_border
P_ ((struct window
*));
503 static void x_after_update_window_line
P_ ((struct glyph_row
*));
504 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
505 static void x_produce_stretch_glyph
P_ ((struct it
*));
506 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
507 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
508 enum scroll_bar_part
*,
509 Lisp_Object
*, Lisp_Object
*,
511 static void x_check_fullscreen
P_ ((struct frame
*));
512 static void x_check_fullscreen_move
P_ ((struct frame
*));
514 /* Flush display of frame F, or of all frames if F is null. */
523 Lisp_Object rest
, frame
;
524 FOR_EACH_FRAME (rest
, frame
)
525 x_flush (XFRAME (frame
));
527 else if (FRAME_X_P (f
))
528 XFlush (FRAME_X_DISPLAY (f
));
533 /* Remove calls to XFlush by defining XFlush to an empty replacement.
534 Calls to XFlush should be unnecessary because the X output buffer
535 is flushed automatically as needed by calls to XPending,
536 XNextEvent, or XWindowEvent according to the XFlush man page.
537 XTread_socket calls XPending. Removing XFlush improves
540 #define XFlush(DISPLAY) (void) 0
543 /***********************************************************************
545 ***********************************************************************/
549 /* This is a function useful for recording debugging information about
550 the sequence of occurrences in this file. */
558 struct record event_record
[100];
560 int event_record_index
;
562 record_event (locus
, type
)
566 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
567 event_record_index
= 0;
569 event_record
[event_record_index
].locus
= locus
;
570 event_record
[event_record_index
].type
= type
;
571 event_record_index
++;
578 /* Return the struct x_display_info corresponding to DPY. */
580 struct x_display_info
*
581 x_display_info_for_display (dpy
)
584 struct x_display_info
*dpyinfo
;
586 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
587 if (dpyinfo
->display
== dpy
)
595 /***********************************************************************
596 Starting and ending an update
597 ***********************************************************************/
599 /* Start an update of frame F. This function is installed as a hook
600 for update_begin, i.e. it is called when update_begin is called.
601 This function is called prior to calls to x_update_window_begin for
602 each window being updated. Currently, there is nothing to do here
603 because all interesting stuff is done on a window basis. */
613 /* Start update of window W. Set the global variable updated_window
614 to the window being updated and set output_cursor to the cursor
618 x_update_window_begin (w
)
621 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
622 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
625 set_output_cursor (&w
->cursor
);
629 if (f
== display_info
->mouse_face_mouse_frame
)
631 /* Don't do highlighting for mouse motion during the update. */
632 display_info
->mouse_face_defer
= 1;
634 /* If F needs to be redrawn, simply forget about any prior mouse
636 if (FRAME_GARBAGED_P (f
))
637 display_info
->mouse_face_window
= Qnil
;
639 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
640 their mouse_face_p flag set, which means that they are always
641 unequal to rows in a desired matrix which never have that
642 flag set. So, rows containing mouse-face glyphs are never
643 scrolled, and we don't have to switch the mouse highlight off
644 here to prevent it from being scrolled. */
646 /* Can we tell that this update does not affect the window
647 where the mouse highlight is? If so, no need to turn off.
648 Likewise, don't do anything if the frame is garbaged;
649 in that case, the frame's current matrix that we would use
650 is all wrong, and we will redisplay that line anyway. */
651 if (!NILP (display_info
->mouse_face_window
)
652 && w
== XWINDOW (display_info
->mouse_face_window
))
656 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
657 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
660 if (i
< w
->desired_matrix
->nrows
)
661 clear_mouse_face (display_info
);
670 /* Draw a vertical window border to the right of window W if W doesn't
671 have vertical scroll bars. */
674 x_draw_vertical_border (w
)
677 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
679 /* Redraw borders between horizontally adjacent windows. Don't
680 do it for frames with vertical scroll bars because either the
681 right scroll bar of a window, or the left scroll bar of its
682 neighbor will suffice as a border. */
683 if (!WINDOW_RIGHTMOST_P (w
)
684 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
688 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
689 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
692 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
693 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
698 /* End update of window W (which is equal to updated_window).
700 Draw vertical borders between horizontally adjacent windows, and
701 display W's cursor if CURSOR_ON_P is non-zero.
703 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
704 glyphs in mouse-face were overwritten. In that case we have to
705 make sure that the mouse-highlight is properly redrawn.
707 W may be a menu bar pseudo-window in case we don't have X toolkit
708 support. Such windows don't have a cursor, so don't display it
712 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
714 int cursor_on_p
, mouse_face_overwritten_p
;
716 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
718 if (!w
->pseudo_window_p
)
723 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
725 output_cursor
.x
, output_cursor
.y
);
727 x_draw_vertical_border (w
);
731 /* If a row with mouse-face was overwritten, arrange for
732 XTframe_up_to_date to redisplay the mouse highlight. */
733 if (mouse_face_overwritten_p
)
735 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
736 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
737 dpyinfo
->mouse_face_window
= Qnil
;
740 updated_window
= NULL
;
744 /* End update of frame F. This function is installed as a hook in
751 /* Mouse highlight may be displayed again. */
752 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
755 XFlush (FRAME_X_DISPLAY (f
));
760 /* This function is called from various places in xdisp.c whenever a
761 complete update has been performed. The global variable
762 updated_window is not available here. */
765 XTframe_up_to_date (f
)
770 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
772 if (dpyinfo
->mouse_face_deferred_gc
773 || f
== dpyinfo
->mouse_face_mouse_frame
)
776 if (dpyinfo
->mouse_face_mouse_frame
)
777 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
778 dpyinfo
->mouse_face_mouse_x
,
779 dpyinfo
->mouse_face_mouse_y
);
780 dpyinfo
->mouse_face_deferred_gc
= 0;
787 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
788 arrow bitmaps, or clear the fringes if no bitmaps are required
789 before DESIRED_ROW is made current. The window being updated is
790 found in updated_window. This function It is called from
791 update_window_line only if it is known that there are differences
792 between bitmaps to be drawn between current row and DESIRED_ROW. */
795 x_after_update_window_line (desired_row
)
796 struct glyph_row
*desired_row
;
798 struct window
*w
= updated_window
;
804 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
807 x_draw_row_fringe_bitmaps (w
, desired_row
);
811 /* When a window has disappeared, make sure that no rest of
812 full-width rows stays visible in the internal border. Could
813 check here if updated_window is the leftmost/rightmost window,
814 but I guess it's not worth doing since vertically split windows
815 are almost never used, internal border is rarely set, and the
816 overhead is very small. */
817 if (windows_or_buffers_changed
818 && desired_row
->full_width_p
819 && (f
= XFRAME (w
->frame
),
820 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
822 && (height
= desired_row
->visible_height
,
825 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
827 /* Internal border is drawn below the tool bar. */
828 if (WINDOWP (f
->tool_bar_window
)
829 && w
== XWINDOW (f
->tool_bar_window
))
833 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
834 0, y
, width
, height
, False
);
835 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
836 f
->output_data
.x
->pixel_width
- width
,
837 y
, width
, height
, False
);
843 /* Draw the bitmap WHICH in one of the left or right fringes of
844 window W. ROW is the glyph row for which to display the bitmap; it
845 determines the vertical position at which the bitmap has to be
849 x_draw_fringe_bitmap (w
, row
, which
, left_p
)
851 struct glyph_row
*row
;
852 enum fringe_bitmap_type which
;
855 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
856 Display
*display
= FRAME_X_DISPLAY (f
);
857 Window window
= FRAME_X_WINDOW (f
);
862 GC gc
= f
->output_data
.x
->normal_gc
;
864 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
866 /* Must clip because of partially visible lines. */
867 x_clip_to_row (w
, row
, gc
, 1);
869 /* Convert row to frame coordinates. */
870 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
874 case NO_FRINGE_BITMAP
:
879 case LEFT_TRUNCATION_BITMAP
:
885 case OVERLAY_ARROW_BITMAP
:
891 case RIGHT_TRUNCATION_BITMAP
:
897 case CONTINUED_LINE_BITMAP
:
898 wd
= continued_width
;
899 h
= continued_height
;
900 bits
= continued_bits
;
903 case CONTINUATION_LINE_BITMAP
:
904 wd
= continuation_width
;
905 h
= continuation_height
;
906 bits
= continuation_bits
;
911 h
= zv_height
- (y
% zv_period
);
912 bits
= zv_bits
+ (y
% zv_period
);
919 /* Clip bitmap if too high. */
923 /* Set dy to the offset in the row to start drawing the bitmap. */
924 dy
= (row
->height
- h
) / 2;
926 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
927 PREPARE_FACE_FOR_DISPLAY (f
, face
);
929 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
934 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
935 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
936 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
938 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
939 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
941 /* If W has a vertical border to its left, don't draw over it. */
942 int border
= ((XFASTINT (w
->left
) > 0
943 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
945 b1
= (window_box_left (w
, -1)
946 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
948 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
953 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
954 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
955 x
= (window_box_right (w
, -1)
956 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
957 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
959 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
961 b1
= window_box_right (w
, -1);
962 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
968 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
970 /* In case the same realized face is used for fringes and
971 for something displayed in the text (e.g. face `region' on
972 mono-displays, the fill style may have been changed to
973 FillSolid in x_draw_glyph_string_background. */
975 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
977 XSetForeground (display
, face
->gc
, face
->background
);
979 XFillRectangle (display
, window
, face
->gc
,
981 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
984 row
->visible_height
);
986 XSetForeground (display
, face
->gc
, face
->foreground
);
989 if (which
!= NO_FRINGE_BITMAP
)
991 /* Draw the bitmap. I believe these small pixmaps can be cached
993 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
995 face
->background
, depth
);
996 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
997 XFreePixmap (display
, pixmap
);
1000 XSetClipMask (display
, gc
, None
);
1004 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
1005 function with input blocked. */
1008 x_draw_row_fringe_bitmaps (w
, row
)
1010 struct glyph_row
*row
;
1012 struct frame
*f
= XFRAME (w
->frame
);
1013 enum fringe_bitmap_type bitmap
;
1015 xassert (interrupt_input_blocked
);
1017 /* If row is completely invisible, because of vscrolling, we
1018 don't have to draw anything. */
1019 if (row
->visible_height
<= 0)
1022 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
1024 /* Decide which bitmap to draw in the left fringe. */
1025 if (row
->overlay_arrow_p
)
1026 bitmap
= OVERLAY_ARROW_BITMAP
;
1027 else if (row
->truncated_on_left_p
)
1028 bitmap
= LEFT_TRUNCATION_BITMAP
;
1029 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1030 bitmap
= CONTINUATION_LINE_BITMAP
;
1031 else if (row
->indicate_empty_line_p
)
1032 bitmap
= ZV_LINE_BITMAP
;
1034 bitmap
= NO_FRINGE_BITMAP
;
1036 x_draw_fringe_bitmap (w
, row
, bitmap
, 1);
1039 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1041 /* Decide which bitmap to draw in the right fringe. */
1042 if (row
->truncated_on_right_p
)
1043 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1044 else if (row
->continued_p
)
1045 bitmap
= CONTINUED_LINE_BITMAP
;
1046 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1047 bitmap
= ZV_LINE_BITMAP
;
1049 bitmap
= NO_FRINGE_BITMAP
;
1051 x_draw_fringe_bitmap (w
, row
, bitmap
, 0);
1057 /* This is called when starting Emacs and when restarting after
1058 suspend. When starting Emacs, no X window is mapped. And nothing
1059 must be done to Emacs's own window if it is suspended (though that
1063 XTset_terminal_modes ()
1067 /* This is called when exiting or suspending Emacs. Exiting will make
1068 the X-windows go away, and suspending requires no action. */
1071 XTreset_terminal_modes ()
1077 /***********************************************************************
1079 ***********************************************************************/
1081 /* Set the global variable output_cursor to CURSOR. All cursor
1082 positions are relative to updated_window. */
1085 set_output_cursor (cursor
)
1086 struct cursor_pos
*cursor
;
1088 output_cursor
.hpos
= cursor
->hpos
;
1089 output_cursor
.vpos
= cursor
->vpos
;
1090 output_cursor
.x
= cursor
->x
;
1091 output_cursor
.y
= cursor
->y
;
1095 /* Set a nominal cursor position.
1097 HPOS and VPOS are column/row positions in a window glyph matrix. X
1098 and Y are window text area relative pixel positions.
1100 If this is done during an update, updated_window will contain the
1101 window that is being updated and the position is the future output
1102 cursor position for that window. If updated_window is null, use
1103 selected_window and display the cursor at the given position. */
1106 XTcursor_to (vpos
, hpos
, y
, x
)
1107 int vpos
, hpos
, y
, x
;
1111 /* If updated_window is not set, work on selected_window. */
1115 w
= XWINDOW (selected_window
);
1117 /* Set the output cursor. */
1118 output_cursor
.hpos
= hpos
;
1119 output_cursor
.vpos
= vpos
;
1120 output_cursor
.x
= x
;
1121 output_cursor
.y
= y
;
1123 /* If not called as part of an update, really display the cursor.
1124 This will also set the cursor position of W. */
1125 if (updated_window
== NULL
)
1128 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1129 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1136 /***********************************************************************
1138 ***********************************************************************/
1140 /* Function prototypes of this page. */
1142 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1146 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1147 int, XChar2b
*, int));
1148 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1149 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*,
1151 static void x_append_glyph
P_ ((struct it
*));
1152 static void x_append_composite_glyph
P_ ((struct it
*));
1153 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1155 static void x_produce_glyphs
P_ ((struct it
*));
1156 static void x_produce_image_glyph
P_ ((struct it
*it
));
1159 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1160 is not contained in the font. */
1162 static INLINE XCharStruct
*
1163 x_per_char_metric (font
, char2b
)
1167 /* The result metric information. */
1168 XCharStruct
*pcm
= NULL
;
1170 xassert (font
&& char2b
);
1172 if (font
->per_char
!= NULL
)
1174 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1176 /* min_char_or_byte2 specifies the linear character index
1177 corresponding to the first element of the per_char array,
1178 max_char_or_byte2 is the index of the last character. A
1179 character with non-zero CHAR2B->byte1 is not in the font.
1180 A character with byte2 less than min_char_or_byte2 or
1181 greater max_char_or_byte2 is not in the font. */
1182 if (char2b
->byte1
== 0
1183 && char2b
->byte2
>= font
->min_char_or_byte2
1184 && char2b
->byte2
<= font
->max_char_or_byte2
)
1185 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1189 /* If either min_byte1 or max_byte1 are nonzero, both
1190 min_char_or_byte2 and max_char_or_byte2 are less than
1191 256, and the 2-byte character index values corresponding
1192 to the per_char array element N (counting from 0) are:
1194 byte1 = N/D + min_byte1
1195 byte2 = N\D + min_char_or_byte2
1199 D = max_char_or_byte2 - min_char_or_byte2 + 1
1200 / = integer division
1201 \ = integer modulus */
1202 if (char2b
->byte1
>= font
->min_byte1
1203 && char2b
->byte1
<= font
->max_byte1
1204 && char2b
->byte2
>= font
->min_char_or_byte2
1205 && char2b
->byte2
<= font
->max_char_or_byte2
)
1207 pcm
= (font
->per_char
1208 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1209 * (char2b
->byte1
- font
->min_byte1
))
1210 + (char2b
->byte2
- font
->min_char_or_byte2
));
1216 /* If the per_char pointer is null, all glyphs between the first
1217 and last character indexes inclusive have the same
1218 information, as given by both min_bounds and max_bounds. */
1219 if (char2b
->byte2
>= font
->min_char_or_byte2
1220 && char2b
->byte2
<= font
->max_char_or_byte2
)
1221 pcm
= &font
->max_bounds
;
1224 return ((pcm
== NULL
1225 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1230 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1231 the two-byte form of C. Encoding is returned in *CHAR2B. */
1234 x_encode_char (c
, char2b
, font_info
, charset
)
1237 struct font_info
*font_info
;
1238 struct charset
*charset
;
1240 XFontStruct
*font
= font_info
->font
;
1242 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1243 This may be either a program in a special encoder language or a
1245 if (font_info
->font_encoder
)
1247 /* It's a program. */
1248 struct ccl_program
*ccl
= font_info
->font_encoder
;
1250 if (CHARSET_DIMENSION (charset
) == 1)
1252 ccl
->reg
[0] = CHARSET_ID (charset
);
1253 ccl
->reg
[1] = char2b
->byte2
;
1257 ccl
->reg
[0] = CHARSET_ID (charset
);
1258 ccl
->reg
[1] = char2b
->byte1
;
1259 ccl
->reg
[2] = char2b
->byte2
;
1262 ccl_driver (ccl
, NULL
, NULL
, 0, 0, Qnil
);
1264 /* We assume that MSBs are appropriately set/reset by CCL
1266 if (font
->max_byte1
== 0) /* 1-byte font */
1267 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1269 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1271 else if (font_info
->encoding_type
)
1273 /* Fixed encoding scheme. See fontset.h for the meaning of the
1274 encoding numbers. */
1275 unsigned char enc
= font_info
->encoding_type
;
1277 if ((enc
== 1 || enc
== 2)
1278 && CHARSET_DIMENSION (charset
) == 2)
1279 char2b
->byte1
|= 0x80;
1281 if (enc
== 1 || enc
== 3)
1282 char2b
->byte2
|= 0x80;
1287 /* Get face and two-byte form of character C in face FACE_ID on frame
1288 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1289 means we want to display multibyte text. Value is a pointer to a
1290 realized face that is ready for display. */
1292 static INLINE
struct face
*
1293 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1299 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1303 /* Unibyte case. We don't have to encode, but we have to make
1304 sure to use a face suitable for unibyte. */
1307 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1308 face
= FACE_FROM_ID (f
, face_id
);
1310 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1312 /* Case of ASCII in a face known to fit ASCII. */
1316 else if (face
->font
!= NULL
)
1318 struct font_info
*font_info
1319 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1320 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
1321 unsigned code
= ENCODE_CHAR (charset
, c
);
1323 if (CHARSET_DIMENSION (charset
) == 1)
1324 char2b
->byte1
= 0, char2b
->byte2
= code
;
1326 char2b
->byte1
= code
>> 8, char2b
->byte2
= code
& 0xFF;
1328 /* Maybe encode the character in *CHAR2B. */
1329 x_encode_char (c
, char2b
, font_info
, charset
);
1332 /* Make sure X resources of the face are allocated. */
1333 xassert (face
!= NULL
);
1334 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1340 /* Get face and two-byte form of character glyph GLYPH on frame F.
1341 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1342 a pointer to a realized face that is ready for display. */
1344 static INLINE
struct face
*
1345 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1347 struct glyph
*glyph
;
1353 xassert (glyph
->type
== CHAR_GLYPH
);
1354 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1359 if (!glyph
->multibyte_p
)
1361 /* Unibyte case. We don't have to encode, but we have to make
1362 sure to use a face suitable for unibyte. */
1364 char2b
->byte2
= glyph
->u
.ch
;
1366 else if (glyph
->u
.ch
< 128
1367 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1369 /* Case of ASCII in a face known to fit ASCII. */
1371 char2b
->byte2
= glyph
->u
.ch
;
1375 struct font_info
*font_info
1376 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1379 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
1380 unsigned code
= ENCODE_CHAR (charset
, glyph
->u
.ch
);
1382 if (CHARSET_DIMENSION (charset
) == 1)
1383 char2b
->byte1
= 0, char2b
->byte2
= code
;
1385 char2b
->byte1
= code
>> 8, char2b
->byte2
= code
& 0xFF;
1387 /* Maybe encode the character in *CHAR2B. */
1388 if (CHARSET_ID (charset
) != charset_ascii
)
1390 x_encode_char (glyph
->u
.ch
, char2b
, font_info
, charset
);
1393 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1398 /* Make sure X resources of the face are allocated. */
1399 xassert (face
!= NULL
);
1400 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1405 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1406 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1412 struct glyph
*glyph
;
1413 enum glyph_row_area area
= it
->area
;
1415 xassert (it
->glyph_row
);
1416 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1418 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1419 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1421 glyph
->charpos
= CHARPOS (it
->position
);
1422 glyph
->object
= it
->object
;
1423 glyph
->pixel_width
= it
->pixel_width
;
1424 glyph
->voffset
= it
->voffset
;
1425 glyph
->type
= CHAR_GLYPH
;
1426 glyph
->multibyte_p
= it
->multibyte_p
;
1427 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1428 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1429 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1430 || it
->phys_descent
> it
->descent
);
1431 glyph
->padding_p
= 0;
1432 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1433 glyph
->face_id
= it
->face_id
;
1434 glyph
->u
.ch
= it
->char_to_display
;
1435 ++it
->glyph_row
->used
[area
];
1439 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1440 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1443 x_append_composite_glyph (it
)
1446 struct glyph
*glyph
;
1447 enum glyph_row_area area
= it
->area
;
1449 xassert (it
->glyph_row
);
1451 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1452 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1454 glyph
->charpos
= CHARPOS (it
->position
);
1455 glyph
->object
= it
->object
;
1456 glyph
->pixel_width
= it
->pixel_width
;
1457 glyph
->voffset
= it
->voffset
;
1458 glyph
->type
= COMPOSITE_GLYPH
;
1459 glyph
->multibyte_p
= it
->multibyte_p
;
1460 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1461 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1462 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1463 || it
->phys_descent
> it
->descent
);
1464 glyph
->padding_p
= 0;
1465 glyph
->glyph_not_available_p
= 0;
1466 glyph
->face_id
= it
->face_id
;
1467 glyph
->u
.cmp_id
= it
->cmp_id
;
1468 ++it
->glyph_row
->used
[area
];
1473 /* Change IT->ascent and IT->height according to the setting of
1477 take_vertical_position_into_account (it
)
1482 if (it
->voffset
< 0)
1483 /* Increase the ascent so that we can display the text higher
1485 it
->ascent
+= abs (it
->voffset
);
1487 /* Increase the descent so that we can display the text lower
1489 it
->descent
+= it
->voffset
;
1494 /* Produce glyphs/get display metrics for the image IT is loaded with.
1495 See the description of struct display_iterator in dispextern.h for
1496 an overview of struct display_iterator. */
1499 x_produce_image_glyph (it
)
1505 xassert (it
->what
== IT_IMAGE
);
1507 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1508 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1511 /* Make sure X resources of the face and image are loaded. */
1512 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1513 prepare_image_for_display (it
->f
, img
);
1515 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1516 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1517 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1521 if (face
->box
!= FACE_NO_BOX
)
1523 if (face
->box_line_width
> 0)
1525 it
->ascent
+= face
->box_line_width
;
1526 it
->descent
+= face
->box_line_width
;
1529 if (it
->start_of_box_run_p
)
1530 it
->pixel_width
+= abs (face
->box_line_width
);
1531 if (it
->end_of_box_run_p
)
1532 it
->pixel_width
+= abs (face
->box_line_width
);
1535 take_vertical_position_into_account (it
);
1539 struct glyph
*glyph
;
1540 enum glyph_row_area area
= it
->area
;
1542 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1543 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1545 glyph
->charpos
= CHARPOS (it
->position
);
1546 glyph
->object
= it
->object
;
1547 glyph
->pixel_width
= it
->pixel_width
;
1548 glyph
->voffset
= it
->voffset
;
1549 glyph
->type
= IMAGE_GLYPH
;
1550 glyph
->multibyte_p
= it
->multibyte_p
;
1551 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1552 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1553 glyph
->overlaps_vertically_p
= 0;
1554 glyph
->padding_p
= 0;
1555 glyph
->glyph_not_available_p
= 0;
1556 glyph
->face_id
= it
->face_id
;
1557 glyph
->u
.img_id
= img
->id
;
1558 ++it
->glyph_row
->used
[area
];
1564 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1565 of the glyph, WIDTH and HEIGHT are the width and height of the
1566 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1567 ascent of the glyph (0 <= ASCENT <= 1). */
1570 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1576 struct glyph
*glyph
;
1577 enum glyph_row_area area
= it
->area
;
1579 xassert (ascent
>= 0 && ascent
<= 1);
1581 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1582 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1584 glyph
->charpos
= CHARPOS (it
->position
);
1585 glyph
->object
= object
;
1586 glyph
->pixel_width
= width
;
1587 glyph
->voffset
= it
->voffset
;
1588 glyph
->type
= STRETCH_GLYPH
;
1589 glyph
->multibyte_p
= it
->multibyte_p
;
1590 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1591 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1592 glyph
->overlaps_vertically_p
= 0;
1593 glyph
->padding_p
= 0;
1594 glyph
->glyph_not_available_p
= 0;
1595 glyph
->face_id
= it
->face_id
;
1596 glyph
->u
.stretch
.ascent
= height
* ascent
;
1597 glyph
->u
.stretch
.height
= height
;
1598 ++it
->glyph_row
->used
[area
];
1603 /* Produce a stretch glyph for iterator IT. IT->object is the value
1604 of the glyph property displayed. The value must be a list
1605 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1608 1. `:width WIDTH' specifies that the space should be WIDTH *
1609 canonical char width wide. WIDTH may be an integer or floating
1612 2. `:relative-width FACTOR' specifies that the width of the stretch
1613 should be computed from the width of the first character having the
1614 `glyph' property, and should be FACTOR times that width.
1616 3. `:align-to HPOS' specifies that the space should be wide enough
1617 to reach HPOS, a value in canonical character units.
1619 Exactly one of the above pairs must be present.
1621 4. `:height HEIGHT' specifies that the height of the stretch produced
1622 should be HEIGHT, measured in canonical character units.
1624 5. `:relative-height FACTOR' specifies that the height of the
1625 stretch should be FACTOR times the height of the characters having
1628 Either none or exactly one of 4 or 5 must be present.
1630 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1631 of the stretch should be used for the ascent of the stretch.
1632 ASCENT must be in the range 0 <= ASCENT <= 100. */
1635 ((INTEGERP (X) || FLOATP (X)) \
1641 x_produce_stretch_glyph (it
)
1644 /* (space :width WIDTH :height HEIGHT. */
1646 extern Lisp_Object Qspace
;
1648 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1649 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1650 extern Lisp_Object QCalign_to
;
1651 Lisp_Object prop
, plist
;
1652 double width
= 0, height
= 0, ascent
= 0;
1653 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1654 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1656 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1658 /* List should start with `space'. */
1659 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1660 plist
= XCDR (it
->object
);
1662 /* Compute the width of the stretch. */
1663 if (prop
= Fplist_get (plist
, QCwidth
),
1665 /* Absolute width `:width WIDTH' specified and valid. */
1666 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1667 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1670 /* Relative width `:relative-width FACTOR' specified and valid.
1671 Compute the width of the characters having the `glyph'
1674 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1677 if (it
->multibyte_p
)
1679 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1680 - IT_BYTEPOS (*it
));
1681 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1684 it2
.c
= *p
, it2
.len
= 1;
1686 it2
.glyph_row
= NULL
;
1687 it2
.what
= IT_CHARACTER
;
1688 x_produce_glyphs (&it2
);
1689 width
= NUMVAL (prop
) * it2
.pixel_width
;
1691 else if (prop
= Fplist_get (plist
, QCalign_to
),
1693 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1695 /* Nothing specified -> width defaults to canonical char width. */
1696 width
= CANON_X_UNIT (it
->f
);
1698 /* Compute height. */
1699 if (prop
= Fplist_get (plist
, QCheight
),
1701 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1702 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1704 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1706 height
= FONT_HEIGHT (font
);
1708 /* Compute percentage of height used for ascent. If
1709 `:ascent ASCENT' is present and valid, use that. Otherwise,
1710 derive the ascent from the font in use. */
1711 if (prop
= Fplist_get (plist
, QCascent
),
1712 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1713 ascent
= NUMVAL (prop
) / 100.0;
1715 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1724 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1725 if (!STRINGP (object
))
1726 object
= it
->w
->buffer
;
1727 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1730 it
->pixel_width
= width
;
1731 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1732 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1735 if (face
->box
!= FACE_NO_BOX
)
1737 if (face
->box_line_width
> 0)
1739 it
->ascent
+= face
->box_line_width
;
1740 it
->descent
+= face
->box_line_width
;
1743 if (it
->start_of_box_run_p
)
1744 it
->pixel_width
+= abs (face
->box_line_width
);
1745 if (it
->end_of_box_run_p
)
1746 it
->pixel_width
+= abs (face
->box_line_width
);
1749 take_vertical_position_into_account (it
);
1752 /* Return proper value to be used as baseline offset of font that has
1753 ASCENT and DESCENT to draw characters by the font at the vertical
1754 center of the line of frame F.
1756 Here, out task is to find the value of BOFF in the following figure;
1758 -------------------------+-----------+-
1759 -+-+---------+-+ | |
1761 | | | | F_ASCENT F_HEIGHT
1764 | | |-|-+------+-----------|------- baseline
1766 | |---------|-+-+ | |
1768 -+-+---------+-+ F_DESCENT |
1769 -------------------------+-----------+-
1771 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1772 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1773 DESCENT = FONT->descent
1774 HEIGHT = FONT_HEIGHT (FONT)
1775 F_DESCENT = (F->output_data.x->font->descent
1776 - F->output_data.x->baseline_offset)
1777 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1780 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1782 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1783 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1784 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1786 /* Produce glyphs/get display metrics for the display element IT is
1787 loaded with. See the description of struct display_iterator in
1788 dispextern.h for an overview of struct display_iterator. */
1791 x_produce_glyphs (it
)
1794 it
->glyph_not_available_p
= 0;
1796 if (it
->what
== IT_CHARACTER
)
1800 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1802 int font_not_found_p
;
1803 struct font_info
*font_info
;
1804 int boff
; /* baseline offset */
1805 /* We may change it->multibyte_p upon unibyte<->multibyte
1806 conversion. So, save the current value now and restore it
1809 Note: It seems that we don't have to record multibyte_p in
1810 struct glyph because the character code itself tells if or
1811 not the character is multibyte. Thus, in the future, we must
1812 consider eliminating the field `multibyte_p' in the struct
1814 int saved_multibyte_p
= it
->multibyte_p
;
1816 /* Maybe translate single-byte characters to multibyte, or the
1818 it
->char_to_display
= it
->c
;
1819 if (! ASCII_CHAR_P (it
->c
)
1820 && ! it
->multibyte_p
)
1822 if (SINGLE_BYTE_CHAR_P (it
->c
)
1823 && unibyte_display_via_language_environment
)
1824 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1825 if (! SINGLE_BYTE_CHAR_P (it
->c
))
1827 it
->multibyte_p
= 1;
1828 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1829 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1833 /* Get font to use. Encode IT->char_to_display. */
1834 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1835 it
->face_id
, &char2b
,
1839 /* When no suitable font found, use the default font. */
1840 font_not_found_p
= font
== NULL
;
1841 if (font_not_found_p
)
1843 font
= FRAME_FONT (it
->f
);
1844 boff
= it
->f
->output_data
.x
->baseline_offset
;
1849 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1850 boff
= font_info
->baseline_offset
;
1851 if (font_info
->vertical_centering
)
1852 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1855 if (it
->char_to_display
>= ' '
1856 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1858 /* Either unibyte or ASCII. */
1863 pcm
= x_per_char_metric (font
, &char2b
);
1864 it
->ascent
= font
->ascent
+ boff
;
1865 it
->descent
= font
->descent
- boff
;
1869 it
->phys_ascent
= pcm
->ascent
+ boff
;
1870 it
->phys_descent
= pcm
->descent
- boff
;
1871 it
->pixel_width
= pcm
->width
;
1875 it
->glyph_not_available_p
= 1;
1876 it
->phys_ascent
= font
->ascent
+ boff
;
1877 it
->phys_descent
= font
->descent
- boff
;
1878 it
->pixel_width
= FONT_WIDTH (font
);
1881 /* If this is a space inside a region of text with
1882 `space-width' property, change its width. */
1883 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1885 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1887 /* If face has a box, add the box thickness to the character
1888 height. If character has a box line to the left and/or
1889 right, add the box line width to the character's width. */
1890 if (face
->box
!= FACE_NO_BOX
)
1892 int thick
= face
->box_line_width
;
1896 it
->ascent
+= thick
;
1897 it
->descent
+= thick
;
1902 if (it
->start_of_box_run_p
)
1903 it
->pixel_width
+= thick
;
1904 if (it
->end_of_box_run_p
)
1905 it
->pixel_width
+= thick
;
1908 /* If face has an overline, add the height of the overline
1909 (1 pixel) and a 1 pixel margin to the character height. */
1910 if (face
->overline_p
)
1913 take_vertical_position_into_account (it
);
1915 /* If we have to actually produce glyphs, do it. */
1920 /* Translate a space with a `space-width' property
1921 into a stretch glyph. */
1922 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1923 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1924 it
->ascent
+ it
->descent
, ascent
);
1927 x_append_glyph (it
);
1929 /* If characters with lbearing or rbearing are displayed
1930 in this line, record that fact in a flag of the
1931 glyph row. This is used to optimize X output code. */
1932 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1933 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1936 else if (it
->char_to_display
== '\n')
1938 /* A newline has no width but we need the height of the line. */
1939 it
->pixel_width
= 0;
1941 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1942 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1944 if (face
->box
!= FACE_NO_BOX
1945 && face
->box_line_width
> 0)
1947 it
->ascent
+= face
->box_line_width
;
1948 it
->descent
+= face
->box_line_width
;
1951 else if (it
->char_to_display
== '\t')
1953 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1954 int x
= it
->current_x
+ it
->continuation_lines_width
;
1955 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1957 /* If the distance from the current position to the next tab
1958 stop is less than a canonical character width, use the
1959 tab stop after that. */
1960 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1961 next_tab_x
+= tab_width
;
1963 it
->pixel_width
= next_tab_x
- x
;
1965 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1966 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1970 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1971 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1972 it
->ascent
+ it
->descent
, ascent
);
1977 /* A multi-byte character. Assume that the display width of the
1978 character is the width of the character multiplied by the
1979 width of the font. */
1981 /* If we found a font, this font should give us the right
1982 metrics. If we didn't find a font, use the frame's
1983 default font and calculate the width of the character by
1984 multiplying the width of font by the width of the
1986 pcm
= x_per_char_metric (font
, &char2b
);
1987 if (font_not_found_p
|| !pcm
)
1989 it
->glyph_not_available_p
= 1;
1990 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1991 * CHAR_WIDTH (it
->char_to_display
));
1992 it
->phys_ascent
= font
->ascent
+ boff
;
1993 it
->phys_descent
= font
->descent
- boff
;
1997 it
->pixel_width
= pcm
->width
;
1998 it
->phys_ascent
= pcm
->ascent
+ boff
;
1999 it
->phys_descent
= pcm
->descent
- boff
;
2001 && (pcm
->lbearing
< 0
2002 || pcm
->rbearing
> pcm
->width
))
2003 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2006 it
->ascent
= font
->ascent
+ boff
;
2007 it
->descent
= font
->descent
- boff
;
2008 if (face
->box
!= FACE_NO_BOX
)
2010 int thick
= face
->box_line_width
;
2014 it
->ascent
+= thick
;
2015 it
->descent
+= thick
;
2020 if (it
->start_of_box_run_p
)
2021 it
->pixel_width
+= thick
;
2022 if (it
->end_of_box_run_p
)
2023 it
->pixel_width
+= thick
;
2026 /* If face has an overline, add the height of the overline
2027 (1 pixel) and a 1 pixel margin to the character height. */
2028 if (face
->overline_p
)
2031 take_vertical_position_into_account (it
);
2034 x_append_glyph (it
);
2036 it
->multibyte_p
= saved_multibyte_p
;
2038 else if (it
->what
== IT_COMPOSITION
)
2040 /* Note: A composition is represented as one glyph in the
2041 glyph matrix. There are no padding glyphs. */
2044 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2046 int font_not_found_p
;
2047 struct font_info
*font_info
;
2048 int boff
; /* baseline offset */
2049 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2051 /* Maybe translate single-byte characters to multibyte. */
2052 it
->char_to_display
= it
->c
;
2053 if (unibyte_display_via_language_environment
2056 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2059 /* Get face and font to use. Encode IT->char_to_display. */
2060 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2061 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2062 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2063 it
->face_id
, &char2b
, it
->multibyte_p
);
2066 /* When no suitable font found, use the default font. */
2067 font_not_found_p
= font
== NULL
;
2068 if (font_not_found_p
)
2070 font
= FRAME_FONT (it
->f
);
2071 boff
= it
->f
->output_data
.x
->baseline_offset
;
2076 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2077 boff
= font_info
->baseline_offset
;
2078 if (font_info
->vertical_centering
)
2079 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2082 /* There are no padding glyphs, so there is only one glyph to
2083 produce for the composition. Important is that pixel_width,
2084 ascent and descent are the values of what is drawn by
2085 draw_glyphs (i.e. the values of the overall glyphs composed). */
2088 /* If we have not yet calculated pixel size data of glyphs of
2089 the composition for the current face font, calculate them
2090 now. Theoretically, we have to check all fonts for the
2091 glyphs, but that requires much time and memory space. So,
2092 here we check only the font of the first glyph. This leads
2093 to incorrect display very rarely, and C-l (recenter) can
2094 correct the display anyway. */
2095 if (cmp
->font
!= (void *) font
)
2097 /* Ascent and descent of the font of the first character of
2098 this composition (adjusted by baseline offset). Ascent
2099 and descent of overall glyphs should not be less than
2100 them respectively. */
2101 int font_ascent
= font
->ascent
+ boff
;
2102 int font_descent
= font
->descent
- boff
;
2103 /* Bounding box of the overall glyphs. */
2104 int leftmost
, rightmost
, lowest
, highest
;
2105 int i
, width
, ascent
, descent
;
2107 cmp
->font
= (void *) font
;
2109 /* Initialize the bounding box. */
2111 && (pcm
= x_per_char_metric (font
, &char2b
)))
2114 ascent
= pcm
->ascent
;
2115 descent
= pcm
->descent
;
2119 width
= FONT_WIDTH (font
);
2120 ascent
= font
->ascent
;
2121 descent
= font
->descent
;
2125 lowest
= - descent
+ boff
;
2126 highest
= ascent
+ boff
;
2130 && font_info
->default_ascent
2131 && CHAR_TABLE_P (Vuse_default_ascent
)
2132 && !NILP (Faref (Vuse_default_ascent
,
2133 make_number (it
->char_to_display
))))
2134 highest
= font_info
->default_ascent
+ boff
;
2136 /* Draw the first glyph at the normal position. It may be
2137 shifted to right later if some other glyphs are drawn at
2139 cmp
->offsets
[0] = 0;
2140 cmp
->offsets
[1] = boff
;
2142 /* Set cmp->offsets for the remaining glyphs. */
2143 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2145 int left
, right
, btm
, top
;
2146 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2147 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2149 face
= FACE_FROM_ID (it
->f
, face_id
);
2150 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2155 font
= FRAME_FONT (it
->f
);
2156 boff
= it
->f
->output_data
.x
->baseline_offset
;
2162 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2163 boff
= font_info
->baseline_offset
;
2164 if (font_info
->vertical_centering
)
2165 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2169 && (pcm
= x_per_char_metric (font
, &char2b
)))
2172 ascent
= pcm
->ascent
;
2173 descent
= pcm
->descent
;
2177 width
= FONT_WIDTH (font
);
2182 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2184 /* Relative composition with or without
2186 left
= (leftmost
+ rightmost
- width
) / 2;
2187 btm
= - descent
+ boff
;
2188 if (font_info
&& font_info
->relative_compose
2189 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2190 || NILP (Faref (Vignore_relative_composition
,
2191 make_number (ch
)))))
2194 if (- descent
>= font_info
->relative_compose
)
2195 /* One extra pixel between two glyphs. */
2197 else if (ascent
<= 0)
2198 /* One extra pixel between two glyphs. */
2199 btm
= lowest
- 1 - ascent
- descent
;
2204 /* A composition rule is specified by an integer
2205 value that encodes global and new reference
2206 points (GREF and NREF). GREF and NREF are
2207 specified by numbers as below:
2215 ---3---4---5--- baseline
2217 6---7---8 -- descent
2219 int rule
= COMPOSITION_RULE (cmp
, i
);
2220 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2222 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2223 grefx
= gref
% 3, nrefx
= nref
% 3;
2224 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2227 + grefx
* (rightmost
- leftmost
) / 2
2228 - nrefx
* width
/ 2);
2229 btm
= ((grefy
== 0 ? highest
2231 : grefy
== 2 ? lowest
2232 : (highest
+ lowest
) / 2)
2233 - (nrefy
== 0 ? ascent
+ descent
2234 : nrefy
== 1 ? descent
- boff
2236 : (ascent
+ descent
) / 2));
2239 cmp
->offsets
[i
* 2] = left
;
2240 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2242 /* Update the bounding box of the overall glyphs. */
2243 right
= left
+ width
;
2244 top
= btm
+ descent
+ ascent
;
2245 if (left
< leftmost
)
2247 if (right
> rightmost
)
2255 /* If there are glyphs whose x-offsets are negative,
2256 shift all glyphs to the right and make all x-offsets
2260 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2261 cmp
->offsets
[i
* 2] -= leftmost
;
2262 rightmost
-= leftmost
;
2265 cmp
->pixel_width
= rightmost
;
2266 cmp
->ascent
= highest
;
2267 cmp
->descent
= - lowest
;
2268 if (cmp
->ascent
< font_ascent
)
2269 cmp
->ascent
= font_ascent
;
2270 if (cmp
->descent
< font_descent
)
2271 cmp
->descent
= font_descent
;
2274 it
->pixel_width
= cmp
->pixel_width
;
2275 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2276 it
->descent
= it
->phys_descent
= cmp
->descent
;
2278 if (face
->box
!= FACE_NO_BOX
)
2280 int thick
= face
->box_line_width
;
2284 it
->ascent
+= thick
;
2285 it
->descent
+= thick
;
2290 if (it
->start_of_box_run_p
)
2291 it
->pixel_width
+= thick
;
2292 if (it
->end_of_box_run_p
)
2293 it
->pixel_width
+= thick
;
2296 /* If face has an overline, add the height of the overline
2297 (1 pixel) and a 1 pixel margin to the character height. */
2298 if (face
->overline_p
)
2301 take_vertical_position_into_account (it
);
2304 x_append_composite_glyph (it
);
2306 else if (it
->what
== IT_IMAGE
)
2307 x_produce_image_glyph (it
);
2308 else if (it
->what
== IT_STRETCH
)
2309 x_produce_stretch_glyph (it
);
2311 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2312 because this isn't true for images with `:ascent 100'. */
2313 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2314 if (it
->area
== TEXT_AREA
)
2315 it
->current_x
+= it
->pixel_width
;
2317 it
->descent
+= it
->extra_line_spacing
;
2319 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2320 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2321 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2322 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2326 /* Estimate the pixel height of the mode or top line on frame F.
2327 FACE_ID specifies what line's height to estimate. */
2330 x_estimate_mode_line_height (f
, face_id
)
2332 enum face_id face_id
;
2334 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2336 /* This function is called so early when Emacs starts that the face
2337 cache and mode line face are not yet initialized. */
2338 if (FRAME_FACE_CACHE (f
))
2340 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2344 height
= FONT_HEIGHT (face
->font
);
2345 if (face
->box_line_width
> 0)
2346 height
+= 2 * face
->box_line_width
;
2354 /***********************************************************************
2356 ***********************************************************************/
2358 /* A sequence of glyphs to be drawn in the same face.
2360 This data structure is not really completely X specific, so it
2361 could possibly, at least partially, be useful for other systems. It
2362 is currently not part of the external redisplay interface because
2363 it's not clear what other systems will need. */
2367 /* X-origin of the string. */
2370 /* Y-origin and y-position of the base line of this string. */
2373 /* The width of the string, not including a face extension. */
2376 /* The width of the string, including a face extension. */
2377 int background_width
;
2379 /* The height of this string. This is the height of the line this
2380 string is drawn in, and can be different from the height of the
2381 font the string is drawn in. */
2384 /* Number of pixels this string overwrites in front of its x-origin.
2385 This number is zero if the string has an lbearing >= 0; it is
2386 -lbearing, if the string has an lbearing < 0. */
2389 /* Number of pixels this string overwrites past its right-most
2390 nominal x-position, i.e. x + width. Zero if the string's
2391 rbearing is <= its nominal width, rbearing - width otherwise. */
2394 /* The frame on which the glyph string is drawn. */
2397 /* The window on which the glyph string is drawn. */
2400 /* X display and window for convenience. */
2404 /* The glyph row for which this string was built. It determines the
2405 y-origin and height of the string. */
2406 struct glyph_row
*row
;
2408 /* The area within row. */
2409 enum glyph_row_area area
;
2411 /* Characters to be drawn, and number of characters. */
2415 /* A face-override for drawing cursors, mouse face and similar. */
2416 enum draw_glyphs_face hl
;
2418 /* Face in which this string is to be drawn. */
2421 /* Font in which this string is to be drawn. */
2424 /* Font info for this string. */
2425 struct font_info
*font_info
;
2427 /* Non-null means this string describes (part of) a composition.
2428 All characters from char2b are drawn composed. */
2429 struct composition
*cmp
;
2431 /* Index of this glyph string's first character in the glyph
2432 definition of CMP. If this is zero, this glyph string describes
2433 the first character of a composition. */
2436 /* 1 means this glyph strings face has to be drawn to the right end
2437 of the window's drawing area. */
2438 unsigned extends_to_end_of_line_p
: 1;
2440 /* 1 means the background of this string has been drawn. */
2441 unsigned background_filled_p
: 1;
2443 /* 1 means glyph string must be drawn with 16-bit functions. */
2444 unsigned two_byte_p
: 1;
2446 /* 1 means that the original font determined for drawing this glyph
2447 string could not be loaded. The member `font' has been set to
2448 the frame's default font in this case. */
2449 unsigned font_not_found_p
: 1;
2451 /* 1 means that the face in which this glyph string is drawn has a
2453 unsigned stippled_p
: 1;
2455 /* 1 means only the foreground of this glyph string must be drawn,
2456 and we should use the physical height of the line this glyph
2457 string appears in as clip rect. */
2458 unsigned for_overlaps_p
: 1;
2460 /* The GC to use for drawing this glyph string. */
2463 /* A pointer to the first glyph in the string. This glyph
2464 corresponds to char2b[0]. Needed to draw rectangles if
2465 font_not_found_p is 1. */
2466 struct glyph
*first_glyph
;
2468 /* Image, if any. */
2471 struct glyph_string
*next
, *prev
;
2478 x_dump_glyph_string (s
)
2479 struct glyph_string
*s
;
2481 fprintf (stderr
, "glyph string\n");
2482 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2483 s
->x
, s
->y
, s
->width
, s
->height
);
2484 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2485 fprintf (stderr
, " hl = %d\n", s
->hl
);
2486 fprintf (stderr
, " left overhang = %d, right = %d\n",
2487 s
->left_overhang
, s
->right_overhang
);
2488 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2489 fprintf (stderr
, " extends to end of line = %d\n",
2490 s
->extends_to_end_of_line_p
);
2491 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2492 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2495 #endif /* GLYPH_DEBUG */
2499 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2500 struct glyph_string
**,
2501 struct glyph_string
*,
2502 struct glyph_string
*));
2503 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2504 struct glyph_string
**,
2505 struct glyph_string
*,
2506 struct glyph_string
*));
2507 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2508 struct glyph_string
**,
2509 struct glyph_string
*));
2510 static int x_left_overwritten
P_ ((struct glyph_string
*));
2511 static int x_left_overwriting
P_ ((struct glyph_string
*));
2512 static int x_right_overwritten
P_ ((struct glyph_string
*));
2513 static int x_right_overwriting
P_ ((struct glyph_string
*));
2514 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2516 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2517 XChar2b
*, struct window
*,
2519 enum glyph_row_area
, int,
2520 enum draw_glyphs_face
));
2521 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2522 enum glyph_row_area
, int, int,
2523 enum draw_glyphs_face
, int));
2524 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2525 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2526 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2528 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2529 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2530 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2531 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2532 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2533 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2534 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2535 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2536 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2538 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2539 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2540 unsigned long *, double, int));
2541 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2542 double, int, unsigned long));
2543 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2544 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2545 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2546 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2547 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2548 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2549 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2551 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2552 int, int, int, int, XRectangle
*));
2553 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2554 int, int, int, XRectangle
*));
2555 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2556 enum glyph_row_area
));
2557 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2559 enum glyph_row_area
, int, int));
2562 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2566 /* Append the list of glyph strings with head H and tail T to the list
2567 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2570 x_append_glyph_string_lists (head
, tail
, h
, t
)
2571 struct glyph_string
**head
, **tail
;
2572 struct glyph_string
*h
, *t
;
2586 /* Prepend the list of glyph strings with head H and tail T to the
2587 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2591 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2592 struct glyph_string
**head
, **tail
;
2593 struct glyph_string
*h
, *t
;
2607 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2608 Set *HEAD and *TAIL to the resulting list. */
2611 x_append_glyph_string (head
, tail
, s
)
2612 struct glyph_string
**head
, **tail
;
2613 struct glyph_string
*s
;
2615 s
->next
= s
->prev
= NULL
;
2616 x_append_glyph_string_lists (head
, tail
, s
, s
);
2620 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2625 struct glyph_string
*s
;
2627 if (s
->font
== FRAME_FONT (s
->f
)
2628 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2629 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2631 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2634 /* Cursor on non-default face: must merge. */
2638 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2639 xgcv
.foreground
= s
->face
->background
;
2641 /* If the glyph would be invisible, try a different foreground. */
2642 if (xgcv
.foreground
== xgcv
.background
)
2643 xgcv
.foreground
= s
->face
->foreground
;
2644 if (xgcv
.foreground
== xgcv
.background
)
2645 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2646 if (xgcv
.foreground
== xgcv
.background
)
2647 xgcv
.foreground
= s
->face
->foreground
;
2649 /* Make sure the cursor is distinct from text in this face. */
2650 if (xgcv
.background
== s
->face
->background
2651 && xgcv
.foreground
== s
->face
->foreground
)
2653 xgcv
.background
= s
->face
->foreground
;
2654 xgcv
.foreground
= s
->face
->background
;
2657 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2658 xgcv
.font
= s
->font
->fid
;
2659 xgcv
.graphics_exposures
= False
;
2660 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2662 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2663 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2666 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2667 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2669 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2674 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2677 x_set_mouse_face_gc (s
)
2678 struct glyph_string
*s
;
2683 /* What face has to be used last for the mouse face? */
2684 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2685 face
= FACE_FROM_ID (s
->f
, face_id
);
2687 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2689 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2690 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2692 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2693 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2694 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2696 /* If font in this face is same as S->font, use it. */
2697 if (s
->font
== s
->face
->font
)
2698 s
->gc
= s
->face
->gc
;
2701 /* Otherwise construct scratch_cursor_gc with values from FACE
2706 xgcv
.background
= s
->face
->background
;
2707 xgcv
.foreground
= s
->face
->foreground
;
2708 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2709 xgcv
.font
= s
->font
->fid
;
2710 xgcv
.graphics_exposures
= False
;
2711 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2713 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2714 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2717 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2718 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2720 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2723 xassert (s
->gc
!= 0);
2727 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2728 Faces to use in the mode line have already been computed when the
2729 matrix was built, so there isn't much to do, here. */
2732 x_set_mode_line_face_gc (s
)
2733 struct glyph_string
*s
;
2735 s
->gc
= s
->face
->gc
;
2739 /* Set S->gc of glyph string S for drawing that glyph string. Set
2740 S->stippled_p to a non-zero value if the face of S has a stipple
2744 x_set_glyph_string_gc (s
)
2745 struct glyph_string
*s
;
2747 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2749 if (s
->hl
== DRAW_NORMAL_TEXT
)
2751 s
->gc
= s
->face
->gc
;
2752 s
->stippled_p
= s
->face
->stipple
!= 0;
2754 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2756 x_set_mode_line_face_gc (s
);
2757 s
->stippled_p
= s
->face
->stipple
!= 0;
2759 else if (s
->hl
== DRAW_CURSOR
)
2761 x_set_cursor_gc (s
);
2764 else if (s
->hl
== DRAW_MOUSE_FACE
)
2766 x_set_mouse_face_gc (s
);
2767 s
->stippled_p
= s
->face
->stipple
!= 0;
2769 else if (s
->hl
== DRAW_IMAGE_RAISED
2770 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2772 s
->gc
= s
->face
->gc
;
2773 s
->stippled_p
= s
->face
->stipple
!= 0;
2777 s
->gc
= s
->face
->gc
;
2778 s
->stippled_p
= s
->face
->stipple
!= 0;
2781 /* GC must have been set. */
2782 xassert (s
->gc
!= 0);
2786 /* Return in *R the clipping rectangle for glyph string S. */
2789 x_get_glyph_string_clip_rect (s
, r
)
2790 struct glyph_string
*s
;
2793 if (s
->row
->full_width_p
)
2795 /* Draw full-width. X coordinates are relative to S->w->left. */
2796 int canon_x
= CANON_X_UNIT (s
->f
);
2798 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2799 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2801 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2803 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2804 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2808 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2810 /* Unless displaying a mode or menu bar line, which are always
2811 fully visible, clip to the visible part of the row. */
2812 if (s
->w
->pseudo_window_p
)
2813 r
->height
= s
->row
->visible_height
;
2815 r
->height
= s
->height
;
2819 /* This is a text line that may be partially visible. */
2820 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2821 r
->width
= window_box_width (s
->w
, s
->area
);
2822 r
->height
= s
->row
->visible_height
;
2825 /* If S draws overlapping rows, it's sufficient to use the top and
2826 bottom of the window for clipping because this glyph string
2827 intentionally draws over other lines. */
2828 if (s
->for_overlaps_p
)
2830 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2831 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2835 /* Don't use S->y for clipping because it doesn't take partially
2836 visible lines into account. For example, it can be negative for
2837 partially visible lines at the top of a window. */
2838 if (!s
->row
->full_width_p
2839 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2840 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2842 r
->y
= max (0, s
->row
->y
);
2844 /* If drawing a tool-bar window, draw it over the internal border
2845 at the top of the window. */
2846 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2847 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2850 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2854 /* Set clipping for output of glyph string S. S may be part of a mode
2855 line or menu if we don't have X toolkit support. */
2858 x_set_glyph_string_clipping (s
)
2859 struct glyph_string
*s
;
2862 x_get_glyph_string_clip_rect (s
, &r
);
2863 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2867 /* Compute left and right overhang of glyph string S. If S is a glyph
2868 string for a composition, assume overhangs don't exist. */
2871 x_compute_glyph_string_overhangs (s
)
2872 struct glyph_string
*s
;
2875 && s
->first_glyph
->type
== CHAR_GLYPH
)
2878 int direction
, font_ascent
, font_descent
;
2879 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2880 &font_ascent
, &font_descent
, &cs
);
2881 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2882 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2887 /* Compute overhangs and x-positions for glyph string S and its
2888 predecessors, or successors. X is the starting x-position for S.
2889 BACKWARD_P non-zero means process predecessors. */
2892 x_compute_overhangs_and_x (s
, x
, backward_p
)
2893 struct glyph_string
*s
;
2901 x_compute_glyph_string_overhangs (s
);
2911 x_compute_glyph_string_overhangs (s
);
2920 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2921 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2922 assumed to be zero. */
2925 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2926 struct glyph
*glyph
;
2932 if (glyph
->type
== CHAR_GLYPH
)
2936 struct font_info
*font_info
;
2940 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2942 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2944 && (pcm
= x_per_char_metric (font
, &char2b
)))
2946 if (pcm
->rbearing
> pcm
->width
)
2947 *right
= pcm
->rbearing
- pcm
->width
;
2948 if (pcm
->lbearing
< 0)
2949 *left
= -pcm
->lbearing
;
2955 /* Return the index of the first glyph preceding glyph string S that
2956 is overwritten by S because of S's left overhang. Value is -1
2957 if no glyphs are overwritten. */
2960 x_left_overwritten (s
)
2961 struct glyph_string
*s
;
2965 if (s
->left_overhang
)
2968 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2969 int first
= s
->first_glyph
- glyphs
;
2971 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2972 x
-= glyphs
[i
].pixel_width
;
2983 /* Return the index of the first glyph preceding glyph string S that
2984 is overwriting S because of its right overhang. Value is -1 if no
2985 glyph in front of S overwrites S. */
2988 x_left_overwriting (s
)
2989 struct glyph_string
*s
;
2992 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2993 int first
= s
->first_glyph
- glyphs
;
2997 for (i
= first
- 1; i
>= 0; --i
)
3000 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3003 x
-= glyphs
[i
].pixel_width
;
3010 /* Return the index of the last glyph following glyph string S that is
3011 not overwritten by S because of S's right overhang. Value is -1 if
3012 no such glyph is found. */
3015 x_right_overwritten (s
)
3016 struct glyph_string
*s
;
3020 if (s
->right_overhang
)
3023 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3024 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3025 int end
= s
->row
->used
[s
->area
];
3027 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3028 x
+= glyphs
[i
].pixel_width
;
3037 /* Return the index of the last glyph following glyph string S that
3038 overwrites S because of its left overhang. Value is negative
3039 if no such glyph is found. */
3042 x_right_overwriting (s
)
3043 struct glyph_string
*s
;
3046 int end
= s
->row
->used
[s
->area
];
3047 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3048 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3052 for (i
= first
; i
< end
; ++i
)
3055 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3058 x
+= glyphs
[i
].pixel_width
;
3065 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3068 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3069 struct glyph_string
*s
;
3073 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3074 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3075 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3076 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3080 /* Draw the background of glyph_string S. If S->background_filled_p
3081 is non-zero don't draw it. FORCE_P non-zero means draw the
3082 background even if it wouldn't be drawn normally. This is used
3083 when a string preceding S draws into the background of S, or S
3084 contains the first component of a composition. */
3087 x_draw_glyph_string_background (s
, force_p
)
3088 struct glyph_string
*s
;
3091 /* Nothing to do if background has already been drawn or if it
3092 shouldn't be drawn in the first place. */
3093 if (!s
->background_filled_p
)
3095 int box_line_width
= max (s
->face
->box_line_width
, 0);
3099 /* Fill background with a stipple pattern. */
3100 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3101 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3102 s
->y
+ box_line_width
,
3103 s
->background_width
,
3104 s
->height
- 2 * box_line_width
);
3105 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3106 s
->background_filled_p
= 1;
3108 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3109 || s
->font_not_found_p
3110 || s
->extends_to_end_of_line_p
3113 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3114 s
->background_width
,
3115 s
->height
- 2 * box_line_width
);
3116 s
->background_filled_p
= 1;
3122 /* Draw the foreground of glyph string S. */
3125 x_draw_glyph_string_foreground (s
)
3126 struct glyph_string
*s
;
3130 /* If first glyph of S has a left box line, start drawing the text
3131 of S to the right of that box line. */
3132 if (s
->face
->box
!= FACE_NO_BOX
3133 && s
->first_glyph
->left_box_line_p
)
3134 x
= s
->x
+ abs (s
->face
->box_line_width
);
3138 /* Draw characters of S as rectangles if S's font could not be
3140 if (s
->font_not_found_p
)
3142 for (i
= 0; i
< s
->nchars
; ++i
)
3144 struct glyph
*g
= s
->first_glyph
+ i
;
3145 XDrawRectangle (s
->display
, s
->window
,
3146 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3148 x
+= g
->pixel_width
;
3153 char *char1b
= (char *) s
->char2b
;
3154 int boff
= s
->font_info
->baseline_offset
;
3156 if (s
->font_info
->vertical_centering
)
3157 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3159 /* If we can use 8-bit functions, condense S->char2b. */
3161 for (i
= 0; i
< s
->nchars
; ++i
)
3162 char1b
[i
] = s
->char2b
[i
].byte2
;
3164 /* Draw text with XDrawString if background has already been
3165 filled. Otherwise, use XDrawImageString. (Note that
3166 XDrawImageString is usually faster than XDrawString.) Always
3167 use XDrawImageString when drawing the cursor so that there is
3168 no chance that characters under a box cursor are invisible. */
3169 if (s
->for_overlaps_p
3170 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3172 /* Draw characters with 16-bit or 8-bit functions. */
3174 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3175 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3177 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3178 s
->ybase
- boff
, char1b
, s
->nchars
);
3183 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3184 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3186 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3187 s
->ybase
- boff
, char1b
, s
->nchars
);
3192 /* Draw the foreground of composite glyph string S. */
3195 x_draw_composite_glyph_string_foreground (s
)
3196 struct glyph_string
*s
;
3200 /* If first glyph of S has a left box line, start drawing the text
3201 of S to the right of that box line. */
3202 if (s
->face
->box
!= FACE_NO_BOX
3203 && s
->first_glyph
->left_box_line_p
)
3204 x
= s
->x
+ abs (s
->face
->box_line_width
);
3208 /* S is a glyph string for a composition. S->gidx is the index of
3209 the first character drawn for glyphs of this composition.
3210 S->gidx == 0 means we are drawing the very first character of
3211 this composition. */
3213 /* Draw a rectangle for the composition if the font for the very
3214 first character of the composition could not be loaded. */
3215 if (s
->font_not_found_p
)
3218 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3219 s
->width
- 1, s
->height
- 1);
3223 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3224 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3225 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3226 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3232 #ifdef USE_X_TOOLKIT
3234 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3235 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3236 XrmValue
*, XrmValue
*, XtPointer
*));
3237 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3238 XrmValue
*, Cardinal
*));
3241 /* Return the frame on which widget WIDGET is used.. Abort if frame
3242 cannot be determined. */
3244 static struct frame
*
3245 x_frame_of_widget (widget
)
3248 struct x_display_info
*dpyinfo
;
3252 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3254 /* Find the top-level shell of the widget. Note that this function
3255 can be called when the widget is not yet realized, so XtWindow
3256 (widget) == 0. That's the reason we can't simply use
3257 x_any_window_to_frame. */
3258 while (!XtIsTopLevelShell (widget
))
3259 widget
= XtParent (widget
);
3261 /* Look for a frame with that top-level widget. Allocate the color
3262 on that frame to get the right gamma correction value. */
3263 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3264 if (GC_FRAMEP (XCAR (tail
))
3265 && (f
= XFRAME (XCAR (tail
)),
3266 (f
->output_data
.nothing
!= 1
3267 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3268 && f
->output_data
.x
->widget
== widget
)
3275 /* Allocate the color COLOR->pixel on the screen and display of
3276 widget WIDGET in colormap CMAP. If an exact match cannot be
3277 allocated, try the nearest color available. Value is non-zero
3278 if successful. This is called from lwlib. */
3281 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3286 struct frame
*f
= x_frame_of_widget (widget
);
3287 return x_alloc_nearest_color (f
, cmap
, color
);
3291 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3292 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3293 If this produces the same color as PIXEL, try a color where all RGB
3294 values have DELTA added. Return the allocated color in *PIXEL.
3295 DISPLAY is the X display, CMAP is the colormap to operate on.
3296 Value is non-zero if successful. */
3299 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3303 unsigned long *pixel
;
3307 struct frame
*f
= x_frame_of_widget (widget
);
3308 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3312 /* Structure specifying which arguments should be passed by Xt to
3313 cvt_string_to_pixel. We want the widget's screen and colormap. */
3315 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3317 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3319 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3324 /* The address of this variable is returned by
3325 cvt_string_to_pixel. */
3327 static Pixel cvt_string_to_pixel_value
;
3330 /* Convert a color name to a pixel color.
3332 DPY is the display we are working on.
3334 ARGS is an array of *NARGS XrmValue structures holding additional
3335 information about the widget for which the conversion takes place.
3336 The contents of this array are determined by the specification
3337 in cvt_string_to_pixel_args.
3339 FROM is a pointer to an XrmValue which points to the color name to
3340 convert. TO is an XrmValue in which to return the pixel color.
3342 CLOSURE_RET is a pointer to user-data, in which we record if
3343 we allocated the color or not.
3345 Value is True if successful, False otherwise. */
3348 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3352 XrmValue
*from
, *to
;
3353 XtPointer
*closure_ret
;
3363 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3364 "wrongParameters", "cvt_string_to_pixel",
3366 "Screen and colormap args required", NULL
, NULL
);
3370 screen
= *(Screen
**) args
[0].addr
;
3371 cmap
= *(Colormap
*) args
[1].addr
;
3372 color_name
= (String
) from
->addr
;
3374 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3376 *closure_ret
= (XtPointer
) False
;
3377 pixel
= WhitePixelOfScreen (screen
);
3379 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3381 *closure_ret
= (XtPointer
) False
;
3382 pixel
= BlackPixelOfScreen (screen
);
3384 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3385 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3387 pixel
= color
.pixel
;
3388 *closure_ret
= (XtPointer
) True
;
3393 Cardinal nparams
= 1;
3395 params
[0] = color_name
;
3396 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3397 "badValue", "cvt_string_to_pixel",
3398 "XtToolkitError", "Invalid color `%s'",
3403 if (to
->addr
!= NULL
)
3405 if (to
->size
< sizeof (Pixel
))
3407 to
->size
= sizeof (Pixel
);
3411 *(Pixel
*) to
->addr
= pixel
;
3415 cvt_string_to_pixel_value
= pixel
;
3416 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3419 to
->size
= sizeof (Pixel
);
3424 /* Free a pixel color which was previously allocated via
3425 cvt_string_to_pixel. This is registered as the destructor
3426 for this type of resource via XtSetTypeConverter.
3428 APP is the application context in which we work.
3430 TO is a pointer to an XrmValue holding the color to free.
3431 CLOSURE is the value we stored in CLOSURE_RET for this color
3432 in cvt_string_to_pixel.
3434 ARGS and NARGS are like for cvt_string_to_pixel. */
3437 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3446 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3448 "Screen and colormap arguments required",
3451 else if (closure
!= NULL
)
3453 /* We did allocate the pixel, so free it. */
3454 Screen
*screen
= *(Screen
**) args
[0].addr
;
3455 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3456 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3457 (Pixel
*) to
->addr
, 1);
3462 #endif /* USE_X_TOOLKIT */
3465 /* Value is an array of XColor structures for the contents of the
3466 color map of display DPY. Set *NCELLS to the size of the array.
3467 Note that this probably shouldn't be called for large color maps,
3468 say a 24-bit TrueColor map. */
3470 static const XColor
*
3471 x_color_cells (dpy
, ncells
)
3475 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3477 if (dpyinfo
->color_cells
== NULL
)
3479 Screen
*screen
= dpyinfo
->screen
;
3482 dpyinfo
->ncolor_cells
3483 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3484 dpyinfo
->color_cells
3485 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3486 * sizeof *dpyinfo
->color_cells
);
3488 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3489 dpyinfo
->color_cells
[i
].pixel
= i
;
3491 XQueryColors (dpy
, dpyinfo
->cmap
,
3492 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3495 *ncells
= dpyinfo
->ncolor_cells
;
3496 return dpyinfo
->color_cells
;
3500 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3501 colors in COLORS. Use cached information, if available. */
3504 x_query_colors (f
, colors
, ncolors
)
3509 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3511 if (dpyinfo
->color_cells
)
3514 for (i
= 0; i
< ncolors
; ++i
)
3516 unsigned long pixel
= colors
[i
].pixel
;
3517 xassert (pixel
< dpyinfo
->ncolor_cells
);
3518 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3519 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3523 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3527 /* On frame F, translate pixel color to RGB values for the color in
3528 COLOR. Use cached information, if available. */
3531 x_query_color (f
, color
)
3535 x_query_colors (f
, color
, 1);
3539 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3540 exact match can't be allocated, try the nearest color available.
3541 Value is non-zero if successful. Set *COLOR to the color
3545 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3552 rc
= XAllocColor (dpy
, cmap
, color
);
3555 /* If we got to this point, the colormap is full, so we're going
3556 to try to get the next closest color. The algorithm used is
3557 a least-squares matching, which is what X uses for closest
3558 color matching with StaticColor visuals. */
3560 unsigned long nearest_delta
= ~0;
3562 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3564 for (nearest
= i
= 0; i
< ncells
; ++i
)
3566 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3567 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3568 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3569 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3571 if (delta
< nearest_delta
)
3574 nearest_delta
= delta
;
3578 color
->red
= cells
[nearest
].red
;
3579 color
->green
= cells
[nearest
].green
;
3580 color
->blue
= cells
[nearest
].blue
;
3581 rc
= XAllocColor (dpy
, cmap
, color
);
3585 /* If allocation succeeded, and the allocated pixel color is not
3586 equal to a cached pixel color recorded earlier, there was a
3587 change in the colormap, so clear the color cache. */
3588 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3589 XColor
*cached_color
;
3591 if (dpyinfo
->color_cells
3592 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3593 (cached_color
->red
!= color
->red
3594 || cached_color
->blue
!= color
->blue
3595 || cached_color
->green
!= color
->green
)))
3597 xfree (dpyinfo
->color_cells
);
3598 dpyinfo
->color_cells
= NULL
;
3599 dpyinfo
->ncolor_cells
= 0;
3603 #ifdef DEBUG_X_COLORS
3605 register_color (color
->pixel
);
3606 #endif /* DEBUG_X_COLORS */
3612 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3613 exact match can't be allocated, try the nearest color available.
3614 Value is non-zero if successful. Set *COLOR to the color
3618 x_alloc_nearest_color (f
, cmap
, color
)
3623 gamma_correct (f
, color
);
3624 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3628 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3629 It's necessary to do this instead of just using PIXEL directly to
3630 get color reference counts right. */
3633 x_copy_color (f
, pixel
)
3635 unsigned long pixel
;
3639 color
.pixel
= pixel
;
3641 x_query_color (f
, &color
);
3642 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3644 #ifdef DEBUG_X_COLORS
3645 register_color (pixel
);
3651 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3652 It's necessary to do this instead of just using PIXEL directly to
3653 get color reference counts right. */
3656 x_copy_dpy_color (dpy
, cmap
, pixel
)
3659 unsigned long pixel
;
3663 color
.pixel
= pixel
;
3665 XQueryColor (dpy
, cmap
, &color
);
3666 XAllocColor (dpy
, cmap
, &color
);
3668 #ifdef DEBUG_X_COLORS
3669 register_color (pixel
);
3675 /* Brightness beyond which a color won't have its highlight brightness
3678 Nominally, highlight colors for `3d' faces are calculated by
3679 brightening an object's color by a constant scale factor, but this
3680 doesn't yield good results for dark colors, so for colors who's
3681 brightness is less than this value (on a scale of 0-65535) have an
3682 use an additional additive factor.
3684 The value here is set so that the default menu-bar/mode-line color
3685 (grey75) will not have its highlights changed at all. */
3686 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3689 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3690 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3691 If this produces the same color as PIXEL, try a color where all RGB
3692 values have DELTA added. Return the allocated color in *PIXEL.
3693 DISPLAY is the X display, CMAP is the colormap to operate on.
3694 Value is non-zero if successful. */
3697 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3701 unsigned long *pixel
;
3709 /* Get RGB color values. */
3710 color
.pixel
= *pixel
;
3711 x_query_color (f
, &color
);
3713 /* Change RGB values by specified FACTOR. Avoid overflow! */
3714 xassert (factor
>= 0);
3715 new.red
= min (0xffff, factor
* color
.red
);
3716 new.green
= min (0xffff, factor
* color
.green
);
3717 new.blue
= min (0xffff, factor
* color
.blue
);
3719 /* Calculate brightness of COLOR. */
3720 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3722 /* We only boost colors that are darker than
3723 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3724 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3725 /* Make an additive adjustment to NEW, because it's dark enough so
3726 that scaling by FACTOR alone isn't enough. */
3728 /* How far below the limit this color is (0 - 1, 1 being darker). */
3729 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3730 /* The additive adjustment. */
3731 int min_delta
= delta
* dimness
* factor
/ 2;
3735 new.red
= max (0, new.red
- min_delta
);
3736 new.green
= max (0, new.green
- min_delta
);
3737 new.blue
= max (0, new.blue
- min_delta
);
3741 new.red
= min (0xffff, min_delta
+ new.red
);
3742 new.green
= min (0xffff, min_delta
+ new.green
);
3743 new.blue
= min (0xffff, min_delta
+ new.blue
);
3747 /* Try to allocate the color. */
3748 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3751 if (new.pixel
== *pixel
)
3753 /* If we end up with the same color as before, try adding
3754 delta to the RGB values. */
3755 x_free_colors (f
, &new.pixel
, 1);
3757 new.red
= min (0xffff, delta
+ color
.red
);
3758 new.green
= min (0xffff, delta
+ color
.green
);
3759 new.blue
= min (0xffff, delta
+ color
.blue
);
3760 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3771 /* Set up the foreground color for drawing relief lines of glyph
3772 string S. RELIEF is a pointer to a struct relief containing the GC
3773 with which lines will be drawn. Use a color that is FACTOR or
3774 DELTA lighter or darker than the relief's background which is found
3775 in S->f->output_data.x->relief_background. If such a color cannot
3776 be allocated, use DEFAULT_PIXEL, instead. */
3779 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3781 struct relief
*relief
;
3784 unsigned long default_pixel
;
3787 struct x_output
*di
= f
->output_data
.x
;
3788 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3789 unsigned long pixel
;
3790 unsigned long background
= di
->relief_background
;
3791 Colormap cmap
= FRAME_X_COLORMAP (f
);
3792 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3793 Display
*dpy
= FRAME_X_DISPLAY (f
);
3795 xgcv
.graphics_exposures
= False
;
3796 xgcv
.line_width
= 1;
3798 /* Free previously allocated color. The color cell will be reused
3799 when it has been freed as many times as it was allocated, so this
3800 doesn't affect faces using the same colors. */
3802 && relief
->allocated_p
)
3804 x_free_colors (f
, &relief
->pixel
, 1);
3805 relief
->allocated_p
= 0;
3808 /* Allocate new color. */
3809 xgcv
.foreground
= default_pixel
;
3811 if (dpyinfo
->n_planes
!= 1
3812 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3814 relief
->allocated_p
= 1;
3815 xgcv
.foreground
= relief
->pixel
= pixel
;
3818 if (relief
->gc
== 0)
3820 xgcv
.stipple
= dpyinfo
->gray
;
3822 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3825 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3829 /* Set up colors for the relief lines around glyph string S. */
3832 x_setup_relief_colors (s
)
3833 struct glyph_string
*s
;
3835 struct x_output
*di
= s
->f
->output_data
.x
;
3836 unsigned long color
;
3838 if (s
->face
->use_box_color_for_shadows_p
)
3839 color
= s
->face
->box_color
;
3840 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3842 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3843 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3848 /* Get the background color of the face. */
3849 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3850 color
= xgcv
.background
;
3853 if (di
->white_relief
.gc
== 0
3854 || color
!= di
->relief_background
)
3856 di
->relief_background
= color
;
3857 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3858 WHITE_PIX_DEFAULT (s
->f
));
3859 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3860 BLACK_PIX_DEFAULT (s
->f
));
3865 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3866 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3867 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3868 relief. LEFT_P non-zero means draw a relief on the left side of
3869 the rectangle. RIGHT_P non-zero means draw a relief on the right
3870 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3874 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3875 raised_p
, left_p
, right_p
, clip_rect
)
3877 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3878 XRectangle
*clip_rect
;
3880 Display
*dpy
= FRAME_X_DISPLAY (f
);
3881 Window window
= FRAME_X_WINDOW (f
);
3886 gc
= f
->output_data
.x
->white_relief
.gc
;
3888 gc
= f
->output_data
.x
->black_relief
.gc
;
3889 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3892 for (i
= 0; i
< width
; ++i
)
3893 XDrawLine (dpy
, window
, gc
,
3894 left_x
+ i
* left_p
, top_y
+ i
,
3895 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3899 for (i
= 0; i
< width
; ++i
)
3900 XDrawLine (dpy
, window
, gc
,
3901 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3903 XSetClipMask (dpy
, gc
, None
);
3905 gc
= f
->output_data
.x
->black_relief
.gc
;
3907 gc
= f
->output_data
.x
->white_relief
.gc
;
3908 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3911 for (i
= 0; i
< width
; ++i
)
3912 XDrawLine (dpy
, window
, gc
,
3913 left_x
+ i
* left_p
, bottom_y
- i
,
3914 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3918 for (i
= 0; i
< width
; ++i
)
3919 XDrawLine (dpy
, window
, gc
,
3920 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3922 XSetClipMask (dpy
, gc
, None
);
3926 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3927 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3928 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3929 left side of the rectangle. RIGHT_P non-zero means draw a line
3930 on the right side of the rectangle. CLIP_RECT is the clipping
3931 rectangle to use when drawing. */
3934 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3935 left_p
, right_p
, clip_rect
)
3936 struct glyph_string
*s
;
3937 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3938 XRectangle
*clip_rect
;
3942 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3943 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3944 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3947 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3948 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3952 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3953 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3956 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3957 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3961 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3962 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3964 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3965 XSetClipMask (s
->display
, s
->gc
, None
);
3969 /* Draw a box around glyph string S. */
3972 x_draw_glyph_string_box (s
)
3973 struct glyph_string
*s
;
3975 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3976 int left_p
, right_p
;
3977 struct glyph
*last_glyph
;
3978 XRectangle clip_rect
;
3980 last_x
= window_box_right (s
->w
, s
->area
);
3981 if (s
->row
->full_width_p
3982 && !s
->w
->pseudo_window_p
)
3984 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
3985 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3986 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3989 /* The glyph that may have a right box line. */
3990 last_glyph
= (s
->cmp
|| s
->img
3992 : s
->first_glyph
+ s
->nchars
- 1);
3994 width
= abs (s
->face
->box_line_width
);
3995 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3997 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3999 : min (last_x
, s
->x
+ s
->background_width
) - 1);
4001 bottom_y
= top_y
+ s
->height
- 1;
4003 left_p
= (s
->first_glyph
->left_box_line_p
4004 || (s
->hl
== DRAW_MOUSE_FACE
4006 || s
->prev
->hl
!= s
->hl
)));
4007 right_p
= (last_glyph
->right_box_line_p
4008 || (s
->hl
== DRAW_MOUSE_FACE
4010 || s
->next
->hl
!= s
->hl
)));
4012 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4014 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4015 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4016 left_p
, right_p
, &clip_rect
);
4019 x_setup_relief_colors (s
);
4020 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4021 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4026 /* Draw foreground of image glyph string S. */
4029 x_draw_image_foreground (s
)
4030 struct glyph_string
*s
;
4033 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4035 /* If first glyph of S has a left box line, start drawing it to the
4036 right of that line. */
4037 if (s
->face
->box
!= FACE_NO_BOX
4038 && s
->first_glyph
->left_box_line_p
)
4039 x
= s
->x
+ abs (s
->face
->box_line_width
);
4043 /* If there is a margin around the image, adjust x- and y-position
4045 x
+= s
->img
->hmargin
;
4046 y
+= s
->img
->vmargin
;
4052 /* We can't set both a clip mask and use XSetClipRectangles
4053 because the latter also sets a clip mask. We also can't
4054 trust on the shape extension to be available
4055 (XShapeCombineRegion). So, compute the rectangle to draw
4057 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4060 XRectangle clip_rect
, image_rect
, r
;
4062 xgcv
.clip_mask
= s
->img
->mask
;
4063 xgcv
.clip_x_origin
= x
;
4064 xgcv
.clip_y_origin
= y
;
4065 xgcv
.function
= GXcopy
;
4066 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4068 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4071 image_rect
.width
= s
->img
->width
;
4072 image_rect
.height
= s
->img
->height
;
4073 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4074 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4075 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4079 XRectangle clip_rect
, image_rect
, r
;
4081 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4084 image_rect
.width
= s
->img
->width
;
4085 image_rect
.height
= s
->img
->height
;
4086 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4087 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4088 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4090 /* When the image has a mask, we can expect that at
4091 least part of a mouse highlight or a block cursor will
4092 be visible. If the image doesn't have a mask, make
4093 a block cursor visible by drawing a rectangle around
4094 the image. I believe it's looking better if we do
4095 nothing here for mouse-face. */
4096 if (s
->hl
== DRAW_CURSOR
)
4097 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4098 s
->img
->width
- 1, s
->img
->height
- 1);
4102 /* Draw a rectangle if image could not be loaded. */
4103 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4104 s
->img
->width
- 1, s
->img
->height
- 1);
4108 /* Draw a relief around the image glyph string S. */
4111 x_draw_image_relief (s
)
4112 struct glyph_string
*s
;
4114 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4117 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4119 /* If first glyph of S has a left box line, start drawing it to the
4120 right of that line. */
4121 if (s
->face
->box
!= FACE_NO_BOX
4122 && s
->first_glyph
->left_box_line_p
)
4123 x
= s
->x
+ abs (s
->face
->box_line_width
);
4127 /* If there is a margin around the image, adjust x- and y-position
4129 x
+= s
->img
->hmargin
;
4130 y
+= s
->img
->vmargin
;
4132 if (s
->hl
== DRAW_IMAGE_SUNKEN
4133 || s
->hl
== DRAW_IMAGE_RAISED
)
4135 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
4136 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4140 thick
= abs (s
->img
->relief
);
4141 raised_p
= s
->img
->relief
> 0;
4146 x1
= x
+ s
->img
->width
+ thick
- 1;
4147 y1
= y
+ s
->img
->height
+ thick
- 1;
4149 x_setup_relief_colors (s
);
4150 x_get_glyph_string_clip_rect (s
, &r
);
4151 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4155 /* Draw the foreground of image glyph string S to PIXMAP. */
4158 x_draw_image_foreground_1 (s
, pixmap
)
4159 struct glyph_string
*s
;
4163 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4165 /* If first glyph of S has a left box line, start drawing it to the
4166 right of that line. */
4167 if (s
->face
->box
!= FACE_NO_BOX
4168 && s
->first_glyph
->left_box_line_p
)
4169 x
= abs (s
->face
->box_line_width
);
4173 /* If there is a margin around the image, adjust x- and y-position
4175 x
+= s
->img
->hmargin
;
4176 y
+= s
->img
->vmargin
;
4182 /* We can't set both a clip mask and use XSetClipRectangles
4183 because the latter also sets a clip mask. We also can't
4184 trust on the shape extension to be available
4185 (XShapeCombineRegion). So, compute the rectangle to draw
4187 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4191 xgcv
.clip_mask
= s
->img
->mask
;
4192 xgcv
.clip_x_origin
= x
;
4193 xgcv
.clip_y_origin
= y
;
4194 xgcv
.function
= GXcopy
;
4195 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4197 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4198 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4199 XSetClipMask (s
->display
, s
->gc
, None
);
4203 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4204 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4206 /* When the image has a mask, we can expect that at
4207 least part of a mouse highlight or a block cursor will
4208 be visible. If the image doesn't have a mask, make
4209 a block cursor visible by drawing a rectangle around
4210 the image. I believe it's looking better if we do
4211 nothing here for mouse-face. */
4212 if (s
->hl
== DRAW_CURSOR
)
4213 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4214 s
->img
->width
- 1, s
->img
->height
- 1);
4218 /* Draw a rectangle if image could not be loaded. */
4219 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4220 s
->img
->width
- 1, s
->img
->height
- 1);
4224 /* Draw part of the background of glyph string S. X, Y, W, and H
4225 give the rectangle to draw. */
4228 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4229 struct glyph_string
*s
;
4234 /* Fill background with a stipple pattern. */
4235 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4236 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4237 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4240 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4244 /* Draw image glyph string S.
4247 s->x +-------------------------
4250 | +-------------------------
4253 | | +-------------------
4259 x_draw_image_glyph_string (s
)
4260 struct glyph_string
*s
;
4263 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4264 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4266 Pixmap pixmap
= None
;
4268 height
= s
->height
- 2 * box_line_vwidth
;
4270 /* Fill background with face under the image. Do it only if row is
4271 taller than image or if image has a clip mask to reduce
4273 s
->stippled_p
= s
->face
->stipple
!= 0;
4274 if (height
> s
->img
->height
4278 || s
->img
->pixmap
== 0
4279 || s
->width
!= s
->background_width
)
4281 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4282 x
= s
->x
+ box_line_hwidth
;
4286 y
= s
->y
+ box_line_vwidth
;
4290 /* Create a pixmap as large as the glyph string. Fill it
4291 with the background color. Copy the image to it, using
4292 its mask. Copy the temporary pixmap to the display. */
4293 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4294 int depth
= DefaultDepthOfScreen (screen
);
4296 /* Create a pixmap as large as the glyph string. */
4297 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4298 s
->background_width
,
4301 /* Don't clip in the following because we're working on the
4303 XSetClipMask (s
->display
, s
->gc
, None
);
4305 /* Fill the pixmap with the background color/stipple. */
4308 /* Fill background with a stipple pattern. */
4309 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4310 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4311 0, 0, s
->background_width
, s
->height
);
4312 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4317 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4319 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4320 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4321 0, 0, s
->background_width
, s
->height
);
4322 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4326 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4328 s
->background_filled_p
= 1;
4331 /* Draw the foreground. */
4334 x_draw_image_foreground_1 (s
, pixmap
);
4335 x_set_glyph_string_clipping (s
);
4336 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4337 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4338 XFreePixmap (s
->display
, pixmap
);
4341 x_draw_image_foreground (s
);
4343 /* If we must draw a relief around the image, do it. */
4345 || s
->hl
== DRAW_IMAGE_RAISED
4346 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4347 x_draw_image_relief (s
);
4351 /* Draw stretch glyph string S. */
4354 x_draw_stretch_glyph_string (s
)
4355 struct glyph_string
*s
;
4357 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4358 s
->stippled_p
= s
->face
->stipple
!= 0;
4360 if (s
->hl
== DRAW_CURSOR
4361 && !x_stretch_cursor_p
)
4363 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4364 as wide as the stretch glyph. */
4365 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4368 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4370 /* Clear rest using the GC of the original non-cursor face. */
4371 if (width
< s
->background_width
)
4373 int x
= s
->x
+ width
, y
= s
->y
;
4374 int w
= s
->background_width
- width
, h
= s
->height
;
4378 if (s
->row
->mouse_face_p
4379 && cursor_in_mouse_face_p (s
->w
))
4381 x_set_mouse_face_gc (s
);
4387 x_get_glyph_string_clip_rect (s
, &r
);
4388 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4390 if (s
->face
->stipple
)
4392 /* Fill background with a stipple pattern. */
4393 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4394 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4395 XSetFillStyle (s
->display
, gc
, FillSolid
);
4400 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4401 XSetForeground (s
->display
, gc
, xgcv
.background
);
4402 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4403 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4407 else if (!s
->background_filled_p
)
4408 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4411 s
->background_filled_p
= 1;
4415 /* Draw glyph string S. */
4418 x_draw_glyph_string (s
)
4419 struct glyph_string
*s
;
4421 int relief_drawn_p
= 0;
4423 /* If S draws into the background of its successor, draw the
4424 background of the successor first so that S can draw into it.
4425 This makes S->next use XDrawString instead of XDrawImageString. */
4426 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4428 xassert (s
->next
->img
== NULL
);
4429 x_set_glyph_string_gc (s
->next
);
4430 x_set_glyph_string_clipping (s
->next
);
4431 x_draw_glyph_string_background (s
->next
, 1);
4434 /* Set up S->gc, set clipping and draw S. */
4435 x_set_glyph_string_gc (s
);
4437 /* Draw relief (if any) in advance for char/composition so that the
4438 glyph string can be drawn over it. */
4439 if (!s
->for_overlaps_p
4440 && s
->face
->box
!= FACE_NO_BOX
4441 && (s
->first_glyph
->type
== CHAR_GLYPH
4442 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4445 x_set_glyph_string_clipping (s
);
4446 x_draw_glyph_string_background (s
, 1);
4447 x_draw_glyph_string_box (s
);
4448 x_set_glyph_string_clipping (s
);
4452 x_set_glyph_string_clipping (s
);
4454 switch (s
->first_glyph
->type
)
4457 x_draw_image_glyph_string (s
);
4461 x_draw_stretch_glyph_string (s
);
4465 if (s
->for_overlaps_p
)
4466 s
->background_filled_p
= 1;
4468 x_draw_glyph_string_background (s
, 0);
4469 x_draw_glyph_string_foreground (s
);
4472 case COMPOSITE_GLYPH
:
4473 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4474 s
->background_filled_p
= 1;
4476 x_draw_glyph_string_background (s
, 1);
4477 x_draw_composite_glyph_string_foreground (s
);
4484 if (!s
->for_overlaps_p
)
4486 /* Draw underline. */
4487 if (s
->face
->underline_p
)
4489 unsigned long tem
, h
;
4492 /* Get the underline thickness. Default is 1 pixel. */
4493 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4496 /* Get the underline position. This is the recommended
4497 vertical offset in pixels from the baseline to the top of
4498 the underline. This is a signed value according to the
4499 specs, and its default is
4501 ROUND ((maximum descent) / 2), with
4502 ROUND(x) = floor (x + 0.5) */
4504 if (x_use_underline_position_properties
4505 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4506 y
= s
->ybase
+ (long) tem
;
4507 else if (s
->face
->font
)
4508 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4510 y
= s
->y
+ s
->height
- h
;
4512 if (s
->face
->underline_defaulted_p
)
4513 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4514 s
->x
, y
, s
->width
, h
);
4518 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4519 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4520 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4521 s
->x
, y
, s
->width
, h
);
4522 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4526 /* Draw overline. */
4527 if (s
->face
->overline_p
)
4529 unsigned long dy
= 0, h
= 1;
4531 if (s
->face
->overline_color_defaulted_p
)
4532 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4537 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4538 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4539 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4541 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4545 /* Draw strike-through. */
4546 if (s
->face
->strike_through_p
)
4548 unsigned long h
= 1;
4549 unsigned long dy
= (s
->height
- h
) / 2;
4551 if (s
->face
->strike_through_color_defaulted_p
)
4552 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4557 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4558 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4559 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4561 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4565 /* Draw relief if not yet drawn. */
4566 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4567 x_draw_glyph_string_box (s
);
4570 /* Reset clipping. */
4571 XSetClipMask (s
->display
, s
->gc
, None
);
4575 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4576 struct face
**, int));
4579 /* Fill glyph string S with composition components specified by S->cmp.
4581 FACES is an array of faces for all components of this composition.
4582 S->gidx is the index of the first component for S.
4583 OVERLAPS_P non-zero means S should draw the foreground only, and
4584 use its physical height for clipping.
4586 Value is the index of a component not in S. */
4589 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4590 struct glyph_string
*s
;
4591 struct face
**faces
;
4598 s
->for_overlaps_p
= overlaps_p
;
4600 s
->face
= faces
[s
->gidx
];
4601 s
->font
= s
->face
->font
;
4602 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4604 /* For all glyphs of this composition, starting at the offset
4605 S->gidx, until we reach the end of the definition or encounter a
4606 glyph that requires the different face, add it to S. */
4608 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4611 /* All glyph strings for the same composition has the same width,
4612 i.e. the width set for the first component of the composition. */
4614 s
->width
= s
->first_glyph
->pixel_width
;
4616 /* If the specified font could not be loaded, use the frame's
4617 default font, but record the fact that we couldn't load it in
4618 the glyph string so that we can draw rectangles for the
4619 characters of the glyph string. */
4620 if (s
->font
== NULL
)
4622 s
->font_not_found_p
= 1;
4623 s
->font
= FRAME_FONT (s
->f
);
4626 /* Adjust base line for subscript/superscript text. */
4627 s
->ybase
+= s
->first_glyph
->voffset
;
4629 xassert (s
->face
&& s
->face
->gc
);
4631 /* This glyph string must always be drawn with 16-bit functions. */
4634 return s
->gidx
+ s
->nchars
;
4638 /* Fill glyph string S from a sequence of character glyphs.
4640 FACE_ID is the face id of the string. START is the index of the
4641 first glyph to consider, END is the index of the last + 1.
4642 OVERLAPS_P non-zero means S should draw the foreground only, and
4643 use its physical height for clipping.
4645 Value is the index of the first glyph not in S. */
4648 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4649 struct glyph_string
*s
;
4651 int start
, end
, overlaps_p
;
4653 struct glyph
*glyph
, *last
;
4655 int glyph_not_available_p
;
4657 xassert (s
->f
== XFRAME (s
->w
->frame
));
4658 xassert (s
->nchars
== 0);
4659 xassert (start
>= 0 && end
> start
);
4661 s
->for_overlaps_p
= overlaps_p
,
4662 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4663 last
= s
->row
->glyphs
[s
->area
] + end
;
4664 voffset
= glyph
->voffset
;
4666 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4669 && glyph
->type
== CHAR_GLYPH
4670 && glyph
->voffset
== voffset
4671 /* Same face id implies same font, nowadays. */
4672 && glyph
->face_id
== face_id
4673 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4677 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4678 s
->char2b
+ s
->nchars
,
4680 s
->two_byte_p
= two_byte_p
;
4682 xassert (s
->nchars
<= end
- start
);
4683 s
->width
+= glyph
->pixel_width
;
4687 s
->font
= s
->face
->font
;
4688 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4690 /* If the specified font could not be loaded, use the frame's font,
4691 but record the fact that we couldn't load it in
4692 S->font_not_found_p so that we can draw rectangles for the
4693 characters of the glyph string. */
4694 if (s
->font
== NULL
|| glyph_not_available_p
)
4696 s
->font_not_found_p
= 1;
4697 s
->font
= FRAME_FONT (s
->f
);
4700 /* Adjust base line for subscript/superscript text. */
4701 s
->ybase
+= voffset
;
4703 xassert (s
->face
&& s
->face
->gc
);
4704 return glyph
- s
->row
->glyphs
[s
->area
];
4708 /* Fill glyph string S from image glyph S->first_glyph. */
4711 x_fill_image_glyph_string (s
)
4712 struct glyph_string
*s
;
4714 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4715 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4717 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4718 s
->font
= s
->face
->font
;
4719 s
->width
= s
->first_glyph
->pixel_width
;
4721 /* Adjust base line for subscript/superscript text. */
4722 s
->ybase
+= s
->first_glyph
->voffset
;
4726 /* Fill glyph string S from a sequence of stretch glyphs.
4728 ROW is the glyph row in which the glyphs are found, AREA is the
4729 area within the row. START is the index of the first glyph to
4730 consider, END is the index of the last + 1.
4732 Value is the index of the first glyph not in S. */
4735 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4736 struct glyph_string
*s
;
4737 struct glyph_row
*row
;
4738 enum glyph_row_area area
;
4741 struct glyph
*glyph
, *last
;
4742 int voffset
, face_id
;
4744 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4746 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4747 last
= s
->row
->glyphs
[s
->area
] + end
;
4748 face_id
= glyph
->face_id
;
4749 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4750 s
->font
= s
->face
->font
;
4751 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4752 s
->width
= glyph
->pixel_width
;
4753 voffset
= glyph
->voffset
;
4757 && glyph
->type
== STRETCH_GLYPH
4758 && glyph
->voffset
== voffset
4759 && glyph
->face_id
== face_id
);
4761 s
->width
+= glyph
->pixel_width
;
4763 /* Adjust base line for subscript/superscript text. */
4764 s
->ybase
+= voffset
;
4766 /* The case that face->gc == 0 is handled when drawing the glyph
4767 string by calling PREPARE_FACE_FOR_DISPLAY. */
4769 return glyph
- s
->row
->glyphs
[s
->area
];
4773 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4774 of XChar2b structures for S; it can't be allocated in
4775 x_init_glyph_string because it must be allocated via `alloca'. W
4776 is the window on which S is drawn. ROW and AREA are the glyph row
4777 and area within the row from which S is constructed. START is the
4778 index of the first glyph structure covered by S. HL is a
4779 face-override for drawing S. */
4782 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4783 struct glyph_string
*s
;
4786 struct glyph_row
*row
;
4787 enum glyph_row_area area
;
4789 enum draw_glyphs_face hl
;
4791 bzero (s
, sizeof *s
);
4793 s
->f
= XFRAME (w
->frame
);
4794 s
->display
= FRAME_X_DISPLAY (s
->f
);
4795 s
->window
= FRAME_X_WINDOW (s
->f
);
4800 s
->first_glyph
= row
->glyphs
[area
] + start
;
4801 s
->height
= row
->height
;
4802 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4804 /* Display the internal border below the tool-bar window. */
4805 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4806 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4808 s
->ybase
= s
->y
+ row
->ascent
;
4812 /* Set background width of glyph string S. START is the index of the
4813 first glyph following S. LAST_X is the right-most x-position + 1
4814 in the drawing area. */
4817 x_set_glyph_string_background_width (s
, start
, last_x
)
4818 struct glyph_string
*s
;
4822 /* If the face of this glyph string has to be drawn to the end of
4823 the drawing area, set S->extends_to_end_of_line_p. */
4824 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4826 if (start
== s
->row
->used
[s
->area
]
4827 && s
->area
== TEXT_AREA
4828 && ((s
->hl
== DRAW_NORMAL_TEXT
4829 && (s
->row
->fill_line_p
4830 || s
->face
->background
!= default_face
->background
4831 || s
->face
->stipple
!= default_face
->stipple
4832 || s
->row
->mouse_face_p
))
4833 || s
->hl
== DRAW_MOUSE_FACE
4834 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4835 && s
->row
->fill_line_p
)))
4836 s
->extends_to_end_of_line_p
= 1;
4838 /* If S extends its face to the end of the line, set its
4839 background_width to the distance to the right edge of the drawing
4841 if (s
->extends_to_end_of_line_p
)
4842 s
->background_width
= last_x
- s
->x
+ 1;
4844 s
->background_width
= s
->width
;
4848 /* Add a glyph string for a stretch glyph to the list of strings
4849 between HEAD and TAIL. START is the index of the stretch glyph in
4850 row area AREA of glyph row ROW. END is the index of the last glyph
4851 in that glyph row area. X is the current output position assigned
4852 to the new glyph string constructed. HL overrides that face of the
4853 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4854 is the right-most x-position of the drawing area. */
4856 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4857 and below -- keep them on one line. */
4858 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4861 s = (struct glyph_string *) alloca (sizeof *s); \
4862 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4863 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4864 x_append_glyph_string (&HEAD, &TAIL, s); \
4870 /* Add a glyph string for an image glyph to the list of strings
4871 between HEAD and TAIL. START is the index of the image glyph in
4872 row area AREA of glyph row ROW. END is the index of the last glyph
4873 in that glyph row area. X is the current output position assigned
4874 to the new glyph string constructed. HL overrides that face of the
4875 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4876 is the right-most x-position of the drawing area. */
4878 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4881 s = (struct glyph_string *) alloca (sizeof *s); \
4882 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4883 x_fill_image_glyph_string (s); \
4884 x_append_glyph_string (&HEAD, &TAIL, s); \
4891 /* Add a glyph string for a sequence of character glyphs to the list
4892 of strings between HEAD and TAIL. START is the index of the first
4893 glyph in row area AREA of glyph row ROW that is part of the new
4894 glyph string. END is the index of the last glyph in that glyph row
4895 area. X is the current output position assigned to the new glyph
4896 string constructed. HL overrides that face of the glyph; e.g. it
4897 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4898 right-most x-position of the drawing area. */
4900 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4906 c = (ROW)->glyphs[AREA][START].u.ch; \
4907 face_id = (ROW)->glyphs[AREA][START].face_id; \
4909 s = (struct glyph_string *) alloca (sizeof *s); \
4910 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4911 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4912 x_append_glyph_string (&HEAD, &TAIL, s); \
4914 START = x_fill_glyph_string (s, face_id, START, END, \
4920 /* Add a glyph string for a composite sequence to the list of strings
4921 between HEAD and TAIL. START is the index of the first glyph in
4922 row area AREA of glyph row ROW that is part of the new glyph
4923 string. END is the index of the last glyph in that glyph row area.
4924 X is the current output position assigned to the new glyph string
4925 constructed. HL overrides that face of the glyph; e.g. it is
4926 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4927 x-position of the drawing area. */
4929 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4931 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4932 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4933 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4934 struct composition *cmp = composition_table[cmp_id]; \
4935 int glyph_len = cmp->glyph_len; \
4937 struct face **faces; \
4938 struct glyph_string *first_s = NULL; \
4941 base_face = base_face->ascii_face; \
4942 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4943 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4944 /* At first, fill in `char2b' and `faces'. */ \
4945 for (n = 0; n < glyph_len; n++) \
4947 int c = COMPOSITION_GLYPH (cmp, n); \
4948 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4949 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4950 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4951 this_face_id, char2b + n, 1); \
4954 /* Make glyph_strings for each glyph sequence that is drawable by \
4955 the same face, and append them to HEAD/TAIL. */ \
4956 for (n = 0; n < cmp->glyph_len;) \
4958 s = (struct glyph_string *) alloca (sizeof *s); \
4959 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4960 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4968 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4976 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4977 of AREA of glyph row ROW on window W between indices START and END.
4978 HL overrides the face for drawing glyph strings, e.g. it is
4979 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4980 x-positions of the drawing area.
4982 This is an ugly monster macro construct because we must use alloca
4983 to allocate glyph strings (because x_draw_glyphs can be called
4986 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4989 HEAD = TAIL = NULL; \
4990 while (START < END) \
4992 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4993 switch (first_glyph->type) \
4996 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4997 TAIL, HL, X, LAST_X, \
5001 case COMPOSITE_GLYPH: \
5002 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
5003 HEAD, TAIL, HL, X, LAST_X,\
5007 case STRETCH_GLYPH: \
5008 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5009 HEAD, TAIL, HL, X, LAST_X); \
5013 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5014 TAIL, HL, X, LAST_X); \
5021 x_set_glyph_string_background_width (s, START, LAST_X); \
5028 /* Draw glyphs between START and END in AREA of ROW on window W,
5029 starting at x-position X. X is relative to AREA in W. HL is a
5030 face-override with the following meaning:
5032 DRAW_NORMAL_TEXT draw normally
5033 DRAW_CURSOR draw in cursor face
5034 DRAW_MOUSE_FACE draw in mouse face.
5035 DRAW_INVERSE_VIDEO draw in mode line face
5036 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5037 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5039 If OVERLAPS_P is non-zero, draw only the foreground of characters
5040 and clip to the physical height of ROW.
5042 Value is the x-position reached, relative to AREA of W. */
5045 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
5048 struct glyph_row
*row
;
5049 enum glyph_row_area area
;
5051 enum draw_glyphs_face hl
;
5054 struct glyph_string
*head
, *tail
;
5055 struct glyph_string
*s
;
5056 int last_x
, area_width
;
5060 /* Let's rather be paranoid than getting a SEGV. */
5061 end
= min (end
, row
->used
[area
]);
5062 start
= max (0, start
);
5063 start
= min (end
, start
);
5065 /* Translate X to frame coordinates. Set last_x to the right
5066 end of the drawing area. */
5067 if (row
->full_width_p
)
5069 /* X is relative to the left edge of W, without scroll bars
5071 struct frame
*f
= XFRAME (w
->frame
);
5072 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5075 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5076 last_x
= window_left_x
+ area_width
;
5078 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5080 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5081 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5087 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5088 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5092 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5093 area_width
= window_box_width (w
, area
);
5094 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5097 /* Build a doubly-linked list of glyph_string structures between
5098 head and tail from what we have to draw. Note that the macro
5099 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5100 the reason we use a separate variable `i'. */
5102 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5105 x_reached
= tail
->x
+ tail
->background_width
;
5109 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5110 the row, redraw some glyphs in front or following the glyph
5111 strings built above. */
5112 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5115 struct glyph_string
*h
, *t
;
5117 /* Compute overhangs for all glyph strings. */
5118 for (s
= head
; s
; s
= s
->next
)
5119 x_compute_glyph_string_overhangs (s
);
5121 /* Prepend glyph strings for glyphs in front of the first glyph
5122 string that are overwritten because of the first glyph
5123 string's left overhang. The background of all strings
5124 prepended must be drawn because the first glyph string
5126 i
= x_left_overwritten (head
);
5130 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5131 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5134 x_compute_overhangs_and_x (t
, head
->x
, 1);
5135 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5138 /* Prepend glyph strings for glyphs in front of the first glyph
5139 string that overwrite that glyph string because of their
5140 right overhang. For these strings, only the foreground must
5141 be drawn, because it draws over the glyph string at `head'.
5142 The background must not be drawn because this would overwrite
5143 right overhangs of preceding glyphs for which no glyph
5145 i
= x_left_overwriting (head
);
5148 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5149 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5151 for (s
= h
; s
; s
= s
->next
)
5152 s
->background_filled_p
= 1;
5153 x_compute_overhangs_and_x (t
, head
->x
, 1);
5154 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5157 /* Append glyphs strings for glyphs following the last glyph
5158 string tail that are overwritten by tail. The background of
5159 these strings has to be drawn because tail's foreground draws
5161 i
= x_right_overwritten (tail
);
5164 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5165 DRAW_NORMAL_TEXT
, x
, last_x
,
5167 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5168 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5171 /* Append glyph strings for glyphs following the last glyph
5172 string tail that overwrite tail. The foreground of such
5173 glyphs has to be drawn because it writes into the background
5174 of tail. The background must not be drawn because it could
5175 paint over the foreground of following glyphs. */
5176 i
= x_right_overwriting (tail
);
5179 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5180 DRAW_NORMAL_TEXT
, x
, last_x
,
5182 for (s
= h
; s
; s
= s
->next
)
5183 s
->background_filled_p
= 1;
5184 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5185 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5189 /* Draw all strings. */
5190 for (s
= head
; s
; s
= s
->next
)
5191 x_draw_glyph_string (s
);
5193 if (area
== TEXT_AREA
5194 && !row
->full_width_p
5195 /* When drawing overlapping rows, only the glyph strings'
5196 foreground is drawn, which doesn't erase a cursor
5200 int x0
= head
? head
->x
: x
;
5201 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5203 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5204 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5206 if (XFASTINT (w
->left_margin_width
) != 0)
5208 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5209 x0
-= left_area_width
;
5210 x1
-= left_area_width
;
5213 notice_overwritten_cursor (w
, area
, x0
, x1
,
5214 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5217 /* Value is the x-position up to which drawn, relative to AREA of W.
5218 This doesn't include parts drawn because of overhangs. */
5219 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5220 if (!row
->full_width_p
)
5222 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
5223 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5224 if (area
> TEXT_AREA
)
5225 x_reached
-= window_box_width (w
, TEXT_AREA
);
5232 /* Fix the display of area AREA of overlapping row ROW in window W. */
5235 x_fix_overlapping_area (w
, row
, area
)
5237 struct glyph_row
*row
;
5238 enum glyph_row_area area
;
5244 if (area
== LEFT_MARGIN_AREA
)
5246 else if (area
== TEXT_AREA
)
5247 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5249 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5250 + window_box_width (w
, TEXT_AREA
));
5252 for (i
= 0; i
< row
->used
[area
];)
5254 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5256 int start
= i
, start_x
= x
;
5260 x
+= row
->glyphs
[area
][i
].pixel_width
;
5263 while (i
< row
->used
[area
]
5264 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5266 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5267 DRAW_NORMAL_TEXT
, 1);
5271 x
+= row
->glyphs
[area
][i
].pixel_width
;
5280 /* Output LEN glyphs starting at START at the nominal cursor position.
5281 Advance the nominal cursor over the text. The global variable
5282 updated_window contains the window being updated, updated_row is
5283 the glyph row being updated, and updated_area is the area of that
5284 row being updated. */
5287 x_write_glyphs (start
, len
)
5288 struct glyph
*start
;
5293 xassert (updated_window
&& updated_row
);
5298 hpos
= start
- updated_row
->glyphs
[updated_area
];
5299 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5300 updated_row
, updated_area
,
5302 DRAW_NORMAL_TEXT
, 0);
5306 /* Advance the output cursor. */
5307 output_cursor
.hpos
+= len
;
5308 output_cursor
.x
= x
;
5312 /* Insert LEN glyphs from START at the nominal cursor position. */
5315 x_insert_glyphs (start
, len
)
5316 struct glyph
*start
;
5321 int line_height
, shift_by_width
, shifted_region_width
;
5322 struct glyph_row
*row
;
5323 struct glyph
*glyph
;
5324 int frame_x
, frame_y
, hpos
;
5326 xassert (updated_window
&& updated_row
);
5329 f
= XFRAME (WINDOW_FRAME (w
));
5331 /* Get the height of the line we are in. */
5333 line_height
= row
->height
;
5335 /* Get the width of the glyphs to insert. */
5337 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5338 shift_by_width
+= glyph
->pixel_width
;
5340 /* Get the width of the region to shift right. */
5341 shifted_region_width
= (window_box_width (w
, updated_area
)
5346 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5347 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5348 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5349 f
->output_data
.x
->normal_gc
,
5351 shifted_region_width
, line_height
,
5352 frame_x
+ shift_by_width
, frame_y
);
5354 /* Write the glyphs. */
5355 hpos
= start
- row
->glyphs
[updated_area
];
5356 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5357 DRAW_NORMAL_TEXT
, 0);
5359 /* Advance the output cursor. */
5360 output_cursor
.hpos
+= len
;
5361 output_cursor
.x
+= shift_by_width
;
5366 /* Delete N glyphs at the nominal cursor position. Not implemented
5377 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5378 If they are <= 0, this is probably an error. */
5381 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5388 xassert (width
> 0 && height
> 0);
5389 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5393 /* Erase the current text line from the nominal cursor position
5394 (inclusive) to pixel column TO_X (exclusive). The idea is that
5395 everything from TO_X onward is already erased.
5397 TO_X is a pixel position relative to updated_area of
5398 updated_window. TO_X == -1 means clear to the end of this area. */
5401 x_clear_end_of_line (to_x
)
5405 struct window
*w
= updated_window
;
5406 int max_x
, min_y
, max_y
;
5407 int from_x
, from_y
, to_y
;
5409 xassert (updated_window
&& updated_row
);
5410 f
= XFRAME (w
->frame
);
5412 if (updated_row
->full_width_p
)
5414 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5415 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5416 && !w
->pseudo_window_p
)
5417 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5420 max_x
= window_box_width (w
, updated_area
);
5421 max_y
= window_text_bottom_y (w
);
5423 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5424 of window. For TO_X > 0, truncate to end of drawing area. */
5430 to_x
= min (to_x
, max_x
);
5432 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5434 /* Notice if the cursor will be cleared by this operation. */
5435 if (!updated_row
->full_width_p
)
5436 notice_overwritten_cursor (w
, updated_area
,
5437 output_cursor
.x
, -1,
5439 MATRIX_ROW_BOTTOM_Y (updated_row
));
5441 from_x
= output_cursor
.x
;
5443 /* Translate to frame coordinates. */
5444 if (updated_row
->full_width_p
)
5446 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5447 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5451 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5452 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5455 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5456 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5457 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5459 /* Prevent inadvertently clearing to end of the X window. */
5460 if (to_x
> from_x
&& to_y
> from_y
)
5463 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5464 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5471 /* Clear entire frame. If updating_frame is non-null, clear that
5472 frame. Otherwise clear the selected frame. */
5482 f
= SELECTED_FRAME ();
5484 /* Clearing the frame will erase any cursor, so mark them all as no
5486 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5487 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5488 output_cursor
.x
= -1;
5490 /* We don't set the output cursor here because there will always
5491 follow an explicit cursor_to. */
5493 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5495 /* We have to clear the scroll bars, too. If we have changed
5496 colors or something like that, then they should be notified. */
5497 x_scroll_bar_clear (f
);
5499 XFlush (FRAME_X_DISPLAY (f
));
5505 /* Invert the middle quarter of the frame for .15 sec. */
5507 /* We use the select system call to do the waiting, so we have to make
5508 sure it's available. If it isn't, we just won't do visual bells. */
5510 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5513 /* Subtract the `struct timeval' values X and Y, storing the result in
5514 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5517 timeval_subtract (result
, x
, y
)
5518 struct timeval
*result
, x
, y
;
5520 /* Perform the carry for the later subtraction by updating y. This
5521 is safer because on some systems the tv_sec member is unsigned. */
5522 if (x
.tv_usec
< y
.tv_usec
)
5524 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5525 y
.tv_usec
-= 1000000 * nsec
;
5529 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5531 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5532 y
.tv_usec
+= 1000000 * nsec
;
5536 /* Compute the time remaining to wait. tv_usec is certainly
5538 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5539 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5541 /* Return indication of whether the result should be considered
5543 return x
.tv_sec
< y
.tv_sec
;
5555 /* Create a GC that will use the GXxor function to flip foreground
5556 pixels into background pixels. */
5560 values
.function
= GXxor
;
5561 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5562 ^ f
->output_data
.x
->background_pixel
);
5564 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5565 GCFunction
| GCForeground
, &values
);
5569 /* Get the height not including a menu bar widget. */
5570 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5571 /* Height of each line to flash. */
5572 int flash_height
= FRAME_LINE_HEIGHT (f
);
5573 /* These will be the left and right margins of the rectangles. */
5574 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5575 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5579 /* Don't flash the area between a scroll bar and the frame
5580 edge it is next to. */
5581 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5583 case vertical_scroll_bar_left
:
5584 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5587 case vertical_scroll_bar_right
:
5588 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5595 width
= flash_right
- flash_left
;
5597 /* If window is tall, flash top and bottom line. */
5598 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5600 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5602 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5603 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5604 width
, flash_height
);
5605 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5607 (height
- flash_height
5608 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5609 width
, flash_height
);
5612 /* If it is short, flash it all. */
5613 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5614 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5615 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5620 struct timeval wakeup
;
5622 EMACS_GET_TIME (wakeup
);
5624 /* Compute time to wait until, propagating carry from usecs. */
5625 wakeup
.tv_usec
+= 150000;
5626 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5627 wakeup
.tv_usec
%= 1000000;
5629 /* Keep waiting until past the time wakeup or any input gets
5631 while (! detect_input_pending ())
5633 struct timeval current
;
5634 struct timeval timeout
;
5636 EMACS_GET_TIME (current
);
5638 /* Break if result would be negative. */
5639 if (timeval_subtract (¤t
, wakeup
, current
))
5642 /* How long `select' should wait. */
5644 timeout
.tv_usec
= 10000;
5646 /* Try to wait that long--but we might wake up sooner. */
5647 select (0, NULL
, NULL
, NULL
, &timeout
);
5651 /* If window is tall, flash top and bottom line. */
5652 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5654 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5656 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5657 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5658 width
, flash_height
);
5659 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5661 (height
- flash_height
5662 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5663 width
, flash_height
);
5666 /* If it is short, flash it all. */
5667 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5668 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5669 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5671 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5679 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5682 /* Make audible bell. */
5687 struct frame
*f
= SELECTED_FRAME ();
5689 if (FRAME_X_DISPLAY (f
))
5691 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5698 XBell (FRAME_X_DISPLAY (f
), 0);
5699 XFlush (FRAME_X_DISPLAY (f
));
5706 /* Specify how many text lines, from the top of the window,
5707 should be affected by insert-lines and delete-lines operations.
5708 This, and those operations, are used only within an update
5709 that is bounded by calls to x_update_begin and x_update_end. */
5712 XTset_terminal_window (n
)
5715 /* This function intentionally left blank. */
5720 /***********************************************************************
5722 ***********************************************************************/
5724 /* Perform an insert-lines or delete-lines operation, inserting N
5725 lines or deleting -N lines at vertical position VPOS. */
5728 x_ins_del_lines (vpos
, n
)
5735 /* Scroll part of the display as described by RUN. */
5738 x_scroll_run (w
, run
)
5742 struct frame
*f
= XFRAME (w
->frame
);
5743 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5745 /* Get frame-relative bounding box of the text display area of W,
5746 without mode lines. Include in this box the left and right
5748 window_box (w
, -1, &x
, &y
, &width
, &height
);
5749 width
+= FRAME_X_FRINGE_WIDTH (f
);
5750 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5752 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5753 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5754 bottom_y
= y
+ height
;
5758 /* Scrolling up. Make sure we don't copy part of the mode
5759 line at the bottom. */
5760 if (from_y
+ run
->height
> bottom_y
)
5761 height
= bottom_y
- from_y
;
5763 height
= run
->height
;
5767 /* Scolling down. Make sure we don't copy over the mode line.
5769 if (to_y
+ run
->height
> bottom_y
)
5770 height
= bottom_y
- to_y
;
5772 height
= run
->height
;
5777 /* Cursor off. Will be switched on again in x_update_window_end. */
5781 XCopyArea (FRAME_X_DISPLAY (f
),
5782 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5783 f
->output_data
.x
->normal_gc
,
5793 /***********************************************************************
5795 ***********************************************************************/
5797 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5798 corner of the exposed rectangle. W and H are width and height of
5799 the exposed area. All are pixel values. W or H zero means redraw
5800 the entire frame. */
5803 expose_frame (f
, x
, y
, w
, h
)
5808 int mouse_face_overwritten_p
= 0;
5810 TRACE ((stderr
, "expose_frame "));
5812 /* No need to redraw if frame will be redrawn soon. */
5813 if (FRAME_GARBAGED_P (f
))
5815 TRACE ((stderr
, " garbaged\n"));
5819 /* If basic faces haven't been realized yet, there is no point in
5820 trying to redraw anything. This can happen when we get an expose
5821 event while Emacs is starting, e.g. by moving another window. */
5822 if (FRAME_FACE_CACHE (f
) == NULL
5823 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5825 TRACE ((stderr
, " no faces\n"));
5829 if (w
== 0 || h
== 0)
5832 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5833 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5843 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5844 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5846 if (WINDOWP (f
->tool_bar_window
))
5847 mouse_face_overwritten_p
5848 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5850 #ifndef USE_X_TOOLKIT
5851 if (WINDOWP (f
->menu_bar_window
))
5852 mouse_face_overwritten_p
5853 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5854 #endif /* not USE_X_TOOLKIT */
5856 /* Some window managers support a focus-follows-mouse style with
5857 delayed raising of frames. Imagine a partially obscured frame,
5858 and moving the mouse into partially obscured mouse-face on that
5859 frame. The visible part of the mouse-face will be highlighted,
5860 then the WM raises the obscured frame. With at least one WM, KDE
5861 2.1, Emacs is not getting any event for the raising of the frame
5862 (even tried with SubstructureRedirectMask), only Expose events.
5863 These expose events will draw text normally, i.e. not
5864 highlighted. Which means we must redo the highlight here.
5865 Subsume it under ``we love X''. --gerd 2001-08-15 */
5866 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5868 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5869 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5871 int x
= dpyinfo
->mouse_face_mouse_x
;
5872 int y
= dpyinfo
->mouse_face_mouse_y
;
5873 clear_mouse_face (dpyinfo
);
5874 note_mouse_highlight (f
, x
, y
);
5880 /* Redraw (parts) of all windows in the window tree rooted at W that
5881 intersect R. R contains frame pixel coordinates. Value is
5882 non-zero if the exposure overwrites mouse-face. */
5885 expose_window_tree (w
, r
)
5889 struct frame
*f
= XFRAME (w
->frame
);
5890 int mouse_face_overwritten_p
= 0;
5892 while (w
&& !FRAME_GARBAGED_P (f
))
5894 if (!NILP (w
->hchild
))
5895 mouse_face_overwritten_p
5896 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5897 else if (!NILP (w
->vchild
))
5898 mouse_face_overwritten_p
5899 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5901 mouse_face_overwritten_p
|= expose_window (w
, r
);
5903 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5906 return mouse_face_overwritten_p
;
5910 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5911 which intersects rectangle R. R is in window-relative coordinates. */
5914 expose_area (w
, row
, r
, area
)
5916 struct glyph_row
*row
;
5918 enum glyph_row_area area
;
5920 struct glyph
*first
= row
->glyphs
[area
];
5921 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5923 int first_x
, start_x
, x
;
5925 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5926 /* If row extends face to end of line write the whole line. */
5927 x_draw_glyphs (w
, 0, row
, area
, 0, row
->used
[area
],
5928 DRAW_NORMAL_TEXT
, 0);
5931 /* Set START_X to the window-relative start position for drawing glyphs of
5932 AREA. The first glyph of the text area can be partially visible.
5933 The first glyphs of other areas cannot. */
5934 if (area
== LEFT_MARGIN_AREA
)
5936 else if (area
== TEXT_AREA
)
5937 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5939 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5940 + window_box_width (w
, TEXT_AREA
));
5943 /* Find the first glyph that must be redrawn. */
5945 && x
+ first
->pixel_width
< r
->x
)
5947 x
+= first
->pixel_width
;
5951 /* Find the last one. */
5955 && x
< r
->x
+ r
->width
)
5957 x
+= last
->pixel_width
;
5963 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5964 first
- row
->glyphs
[area
],
5965 last
- row
->glyphs
[area
],
5966 DRAW_NORMAL_TEXT
, 0);
5971 /* Redraw the parts of the glyph row ROW on window W intersecting
5972 rectangle R. R is in window-relative coordinates. Value is
5973 non-zero if mouse-face was overwritten. */
5976 expose_line (w
, row
, r
)
5978 struct glyph_row
*row
;
5981 xassert (row
->enabled_p
);
5983 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5984 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5985 DRAW_NORMAL_TEXT
, 0);
5988 if (row
->used
[LEFT_MARGIN_AREA
])
5989 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5990 if (row
->used
[TEXT_AREA
])
5991 expose_area (w
, row
, r
, TEXT_AREA
);
5992 if (row
->used
[RIGHT_MARGIN_AREA
])
5993 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5994 x_draw_row_fringe_bitmaps (w
, row
);
5997 return row
->mouse_face_p
;
6001 /* Return non-zero if W's cursor intersects rectangle R. */
6004 x_phys_cursor_in_rect_p (w
, r
)
6008 XRectangle cr
, result
;
6009 struct glyph
*cursor_glyph
;
6011 cursor_glyph
= get_phys_cursor_glyph (w
);
6014 cr
.x
= w
->phys_cursor
.x
;
6015 cr
.y
= w
->phys_cursor
.y
;
6016 cr
.width
= cursor_glyph
->pixel_width
;
6017 cr
.height
= w
->phys_cursor_height
;
6018 return x_intersect_rectangles (&cr
, r
, &result
);
6025 /* Redraw the part of window W intersection rectangle FR. Pixel
6026 coordinates in FR are frame-relative. Call this function with
6027 input blocked. Value is non-zero if the exposure overwrites
6031 expose_window (w
, fr
)
6035 struct frame
*f
= XFRAME (w
->frame
);
6037 int mouse_face_overwritten_p
= 0;
6039 /* If window is not yet fully initialized, do nothing. This can
6040 happen when toolkit scroll bars are used and a window is split.
6041 Reconfiguring the scroll bar will generate an expose for a newly
6043 if (w
->current_matrix
== NULL
)
6046 /* When we're currently updating the window, display and current
6047 matrix usually don't agree. Arrange for a thorough display
6049 if (w
== updated_window
)
6051 SET_FRAME_GARBAGED (f
);
6055 /* Frame-relative pixel rectangle of W. */
6056 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6057 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6058 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6059 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6061 if (x_intersect_rectangles (fr
, &wr
, &r
))
6063 int yb
= window_text_bottom_y (w
);
6064 struct glyph_row
*row
;
6065 int cursor_cleared_p
;
6067 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6068 r
.x
, r
.y
, r
.width
, r
.height
));
6070 /* Convert to window coordinates. */
6071 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
6072 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
6074 /* Turn off the cursor. */
6075 if (!w
->pseudo_window_p
6076 && x_phys_cursor_in_rect_p (w
, &r
))
6079 cursor_cleared_p
= 1;
6082 cursor_cleared_p
= 0;
6084 /* Find the first row intersecting the rectangle R. */
6085 for (row
= w
->current_matrix
->rows
;
6090 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6092 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
6093 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
6094 || (r
.y
>= y0
&& r
.y
< y1
)
6095 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
6097 if (expose_line (w
, row
, &r
))
6098 mouse_face_overwritten_p
= 1;
6105 /* Display the mode line if there is one. */
6106 if (WINDOW_WANTS_MODELINE_P (w
)
6107 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6109 && row
->y
< r
.y
+ r
.height
)
6111 if (expose_line (w
, row
, &r
))
6112 mouse_face_overwritten_p
= 1;
6115 if (!w
->pseudo_window_p
)
6117 /* Draw border between windows. */
6118 x_draw_vertical_border (w
);
6120 /* Turn the cursor on again. */
6121 if (cursor_cleared_p
)
6122 x_update_window_cursor (w
, 1);
6126 return mouse_face_overwritten_p
;
6130 /* Determine the intersection of two rectangles R1 and R2. Return
6131 the intersection in *RESULT. Value is non-zero if RESULT is not
6135 x_intersect_rectangles (r1
, r2
, result
)
6136 XRectangle
*r1
, *r2
, *result
;
6138 XRectangle
*left
, *right
;
6139 XRectangle
*upper
, *lower
;
6140 int intersection_p
= 0;
6142 /* Rearrange so that R1 is the left-most rectangle. */
6144 left
= r1
, right
= r2
;
6146 left
= r2
, right
= r1
;
6148 /* X0 of the intersection is right.x0, if this is inside R1,
6149 otherwise there is no intersection. */
6150 if (right
->x
<= left
->x
+ left
->width
)
6152 result
->x
= right
->x
;
6154 /* The right end of the intersection is the minimum of the
6155 the right ends of left and right. */
6156 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6159 /* Same game for Y. */
6161 upper
= r1
, lower
= r2
;
6163 upper
= r2
, lower
= r1
;
6165 /* The upper end of the intersection is lower.y0, if this is inside
6166 of upper. Otherwise, there is no intersection. */
6167 if (lower
->y
<= upper
->y
+ upper
->height
)
6169 result
->y
= lower
->y
;
6171 /* The lower end of the intersection is the minimum of the lower
6172 ends of upper and lower. */
6173 result
->height
= (min (lower
->y
+ lower
->height
,
6174 upper
->y
+ upper
->height
)
6180 return intersection_p
;
6191 /* We used to only do this if Vx_no_window_manager was non-nil, but
6192 the ICCCM (section 4.1.6) says that the window's border pixmap
6193 and border pixel are window attributes which are "private to the
6194 client", so we can always change it to whatever we want. */
6196 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6197 f
->output_data
.x
->border_pixel
);
6199 x_update_cursor (f
, 1);
6203 frame_unhighlight (f
)
6206 /* We used to only do this if Vx_no_window_manager was non-nil, but
6207 the ICCCM (section 4.1.6) says that the window's border pixmap
6208 and border pixel are window attributes which are "private to the
6209 client", so we can always change it to whatever we want. */
6211 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6212 f
->output_data
.x
->border_tile
);
6214 x_update_cursor (f
, 1);
6217 /* The focus has changed. Update the frames as necessary to reflect
6218 the new situation. Note that we can't change the selected frame
6219 here, because the Lisp code we are interrupting might become confused.
6220 Each event gets marked with the frame in which it occurred, so the
6221 Lisp code can tell when the switch took place by examining the events. */
6224 x_new_focus_frame (dpyinfo
, frame
)
6225 struct x_display_info
*dpyinfo
;
6226 struct frame
*frame
;
6228 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6230 if (frame
!= dpyinfo
->x_focus_frame
)
6232 /* Set this before calling other routines, so that they see
6233 the correct value of x_focus_frame. */
6234 dpyinfo
->x_focus_frame
= frame
;
6236 if (old_focus
&& old_focus
->auto_lower
)
6237 x_lower_frame (old_focus
);
6240 selected_frame
= frame
;
6241 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6243 Fselect_window (selected_frame
->selected_window
);
6244 choose_minibuf_frame ();
6247 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6248 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6250 pending_autoraise_frame
= 0;
6253 x_frame_rehighlight (dpyinfo
);
6256 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6259 x_mouse_leave (dpyinfo
)
6260 struct x_display_info
*dpyinfo
;
6262 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6265 /* The focus has changed, or we have redirected a frame's focus to
6266 another frame (this happens when a frame uses a surrogate
6267 mini-buffer frame). Shift the highlight as appropriate.
6269 The FRAME argument doesn't necessarily have anything to do with which
6270 frame is being highlighted or un-highlighted; we only use it to find
6271 the appropriate X display info. */
6274 XTframe_rehighlight (frame
)
6275 struct frame
*frame
;
6277 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6281 x_frame_rehighlight (dpyinfo
)
6282 struct x_display_info
*dpyinfo
;
6284 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6286 if (dpyinfo
->x_focus_frame
)
6288 dpyinfo
->x_highlight_frame
6289 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6290 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6291 : dpyinfo
->x_focus_frame
);
6292 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6294 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6295 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6299 dpyinfo
->x_highlight_frame
= 0;
6301 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6304 frame_unhighlight (old_highlight
);
6305 if (dpyinfo
->x_highlight_frame
)
6306 frame_highlight (dpyinfo
->x_highlight_frame
);
6312 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6314 /* Initialize mode_switch_bit and modifier_meaning. */
6316 x_find_modifier_meanings (dpyinfo
)
6317 struct x_display_info
*dpyinfo
;
6319 int min_code
, max_code
;
6322 XModifierKeymap
*mods
;
6324 dpyinfo
->meta_mod_mask
= 0;
6325 dpyinfo
->shift_lock_mask
= 0;
6326 dpyinfo
->alt_mod_mask
= 0;
6327 dpyinfo
->super_mod_mask
= 0;
6328 dpyinfo
->hyper_mod_mask
= 0;
6331 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6333 min_code
= dpyinfo
->display
->min_keycode
;
6334 max_code
= dpyinfo
->display
->max_keycode
;
6337 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6338 min_code
, max_code
- min_code
+ 1,
6340 mods
= XGetModifierMapping (dpyinfo
->display
);
6342 /* Scan the modifier table to see which modifier bits the Meta and
6343 Alt keysyms are on. */
6345 int row
, col
; /* The row and column in the modifier table. */
6347 for (row
= 3; row
< 8; row
++)
6348 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6351 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6353 /* Zeroes are used for filler. Skip them. */
6357 /* Are any of this keycode's keysyms a meta key? */
6361 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6363 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6369 dpyinfo
->meta_mod_mask
|= (1 << row
);
6374 dpyinfo
->alt_mod_mask
|= (1 << row
);
6379 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6384 dpyinfo
->super_mod_mask
|= (1 << row
);
6388 /* Ignore this if it's not on the lock modifier. */
6389 if ((1 << row
) == LockMask
)
6390 dpyinfo
->shift_lock_mask
= LockMask
;
6398 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6399 if (! dpyinfo
->meta_mod_mask
)
6401 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6402 dpyinfo
->alt_mod_mask
= 0;
6405 /* If some keys are both alt and meta,
6406 make them just meta, not alt. */
6407 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6409 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6412 XFree ((char *) syms
);
6413 XFreeModifiermap (mods
);
6416 /* Convert between the modifier bits X uses and the modifier bits
6420 x_x_to_emacs_modifiers (dpyinfo
, state
)
6421 struct x_display_info
*dpyinfo
;
6424 EMACS_UINT mod_meta
= meta_modifier
;
6425 EMACS_UINT mod_alt
= alt_modifier
;
6426 EMACS_UINT mod_hyper
= hyper_modifier
;
6427 EMACS_UINT mod_super
= super_modifier
;
6430 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6431 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6432 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6433 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6434 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6435 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6436 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6437 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6440 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6441 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6442 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
6443 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
6444 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
6445 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
6449 x_emacs_to_x_modifiers (dpyinfo
, state
)
6450 struct x_display_info
*dpyinfo
;
6453 EMACS_UINT mod_meta
= meta_modifier
;
6454 EMACS_UINT mod_alt
= alt_modifier
;
6455 EMACS_UINT mod_hyper
= hyper_modifier
;
6456 EMACS_UINT mod_super
= super_modifier
;
6460 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6461 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6462 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6463 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6464 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6465 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6466 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6467 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6470 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
6471 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
6472 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
6473 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6474 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6475 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
6478 /* Convert a keysym to its name. */
6481 x_get_keysym_name (keysym
)
6487 value
= XKeysymToString (keysym
);
6495 /* Mouse clicks and mouse movement. Rah. */
6497 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6498 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6499 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6500 not force the value into range. */
6503 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6505 register int pix_x
, pix_y
;
6506 register int *x
, *y
;
6510 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6511 even for negative values. */
6513 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6515 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6517 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6518 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6522 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6523 bounds
->height
= f
->output_data
.x
->line_height
;
6524 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6525 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6532 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6533 pix_x
= FRAME_WINDOW_WIDTH (f
);
6537 else if (pix_y
> f
->height
)
6546 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6547 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6548 can't tell the positions because W's display is not up to date,
6552 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6555 int *frame_x
, *frame_y
;
6559 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6560 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6562 if (display_completed
)
6564 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6565 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6566 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6572 *frame_x
+= glyph
->pixel_width
;
6580 *frame_y
= *frame_x
= 0;
6584 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6585 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6590 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6592 If the event is a button press, then note that we have grabbed
6596 construct_mouse_click (result
, event
, f
)
6597 struct input_event
*result
;
6598 XButtonEvent
*event
;
6601 /* Make the event type no_event; we'll change that when we decide
6603 result
->kind
= mouse_click
;
6604 result
->code
= event
->button
- Button1
;
6605 result
->timestamp
= event
->time
;
6606 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6608 | (event
->type
== ButtonRelease
6612 XSETINT (result
->x
, event
->x
);
6613 XSETINT (result
->y
, event
->y
);
6614 XSETFRAME (result
->frame_or_window
, f
);
6620 /* Function to report a mouse movement to the mainstream Emacs code.
6621 The input handler calls this.
6623 We have received a mouse movement event, which is given in *event.
6624 If the mouse is over a different glyph than it was last time, tell
6625 the mainstream emacs code by setting mouse_moved. If not, ask for
6626 another motion event, so we can check again the next time it moves. */
6628 static XMotionEvent last_mouse_motion_event
;
6629 static Lisp_Object last_mouse_motion_frame
;
6632 note_mouse_movement (frame
, event
)
6634 XMotionEvent
*event
;
6636 last_mouse_movement_time
= event
->time
;
6637 last_mouse_motion_event
= *event
;
6638 XSETFRAME (last_mouse_motion_frame
, frame
);
6640 if (x_autoselect_window_p
)
6644 static Lisp_Object last_window
;
6646 window
= window_from_coordinates (frame
, event
->x
, event
->y
, &area
, 0);
6648 /* Window will be selected only when it is not selected now and
6649 last mouse movement event was not in it. Minubuffer window
6650 will be selected iff it is active. */
6651 if (!EQ (window
, last_window
)
6652 && !EQ (window
, selected_window
)
6653 && (!MINI_WINDOW_P (XWINDOW (window
))
6654 || (EQ (window
, minibuf_window
) && minibuf_level
> 0)))
6655 Fselect_window (window
);
6660 if (event
->window
!= FRAME_X_WINDOW (frame
))
6662 frame
->mouse_moved
= 1;
6663 last_mouse_scroll_bar
= Qnil
;
6664 note_mouse_highlight (frame
, -1, -1);
6667 /* Has the mouse moved off the glyph it was on at the last sighting? */
6668 else if (event
->x
< last_mouse_glyph
.x
6669 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6670 || event
->y
< last_mouse_glyph
.y
6671 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6673 frame
->mouse_moved
= 1;
6674 last_mouse_scroll_bar
= Qnil
;
6675 note_mouse_highlight (frame
, event
->x
, event
->y
);
6680 /************************************************************************
6682 ************************************************************************/
6684 /* Find the glyph under window-relative coordinates X/Y in window W.
6685 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6686 strings. Return in *HPOS and *VPOS the row and column number of
6687 the glyph found. Return in *AREA the glyph area containing X.
6688 Value is a pointer to the glyph found or null if X/Y is not on
6689 text, or we can't tell because W's current matrix is not up to
6692 static struct glyph
*
6693 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6696 int *hpos
, *vpos
, *area
;
6699 struct glyph
*glyph
, *end
;
6700 struct glyph_row
*row
= NULL
;
6701 int x0
, i
, left_area_width
;
6703 /* Find row containing Y. Give up if some row is not enabled. */
6704 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6706 row
= MATRIX_ROW (w
->current_matrix
, i
);
6707 if (!row
->enabled_p
)
6709 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6716 /* Give up if Y is not in the window. */
6717 if (i
== w
->current_matrix
->nrows
)
6720 /* Get the glyph area containing X. */
6721 if (w
->pseudo_window_p
)
6728 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6729 if (x
< left_area_width
)
6731 *area
= LEFT_MARGIN_AREA
;
6734 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6737 x0
= row
->x
+ left_area_width
;
6741 *area
= RIGHT_MARGIN_AREA
;
6742 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6746 /* Find glyph containing X. */
6747 glyph
= row
->glyphs
[*area
];
6748 end
= glyph
+ row
->used
[*area
];
6751 if (x
< x0
+ glyph
->pixel_width
)
6753 if (w
->pseudo_window_p
)
6755 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6759 x0
+= glyph
->pixel_width
;
6766 *hpos
= glyph
- row
->glyphs
[*area
];
6771 /* Convert frame-relative x/y to coordinates relative to window W.
6772 Takes pseudo-windows into account. */
6775 frame_to_window_pixel_xy (w
, x
, y
)
6779 if (w
->pseudo_window_p
)
6781 /* A pseudo-window is always full-width, and starts at the
6782 left edge of the frame, plus a frame border. */
6783 struct frame
*f
= XFRAME (w
->frame
);
6784 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6785 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6789 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6790 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6795 /* Take proper action when mouse has moved to the mode or header line of
6796 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6797 mode line. X is relative to the start of the text display area of
6798 W, so the width of fringes and scroll bars must be subtracted
6799 to get a position relative to the start of the mode line. */
6802 note_mode_line_highlight (w
, x
, mode_line_p
)
6806 struct frame
*f
= XFRAME (w
->frame
);
6807 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6808 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6809 struct glyph_row
*row
;
6812 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6814 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6818 struct glyph
*glyph
, *end
;
6819 Lisp_Object help
, map
;
6822 /* Find the glyph under X. */
6823 glyph
= row
->glyphs
[TEXT_AREA
];
6824 end
= glyph
+ row
->used
[TEXT_AREA
];
6825 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6826 + FRAME_X_LEFT_FRINGE_WIDTH (f
));
6829 && x
>= x0
+ glyph
->pixel_width
)
6831 x0
+= glyph
->pixel_width
;
6836 && STRINGP (glyph
->object
)
6837 && XSTRING (glyph
->object
)->intervals
6838 && glyph
->charpos
>= 0
6839 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6841 /* If we're on a string with `help-echo' text property,
6842 arrange for the help to be displayed. This is done by
6843 setting the global variable help_echo to the help string. */
6844 help
= Fget_text_property (make_number (glyph
->charpos
),
6845 Qhelp_echo
, glyph
->object
);
6849 XSETWINDOW (help_echo_window
, w
);
6850 help_echo_object
= glyph
->object
;
6851 help_echo_pos
= glyph
->charpos
;
6854 /* Change the mouse pointer according to what is under X/Y. */
6855 map
= Fget_text_property (make_number (glyph
->charpos
),
6856 Qlocal_map
, glyph
->object
);
6858 cursor
= f
->output_data
.x
->nontext_cursor
;
6861 map
= Fget_text_property (make_number (glyph
->charpos
),
6862 Qkeymap
, glyph
->object
);
6864 cursor
= f
->output_data
.x
->nontext_cursor
;
6869 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6873 /* Take proper action when the mouse has moved to position X, Y on
6874 frame F as regards highlighting characters that have mouse-face
6875 properties. Also de-highlighting chars where the mouse was before.
6876 X and Y can be negative or out of range. */
6879 note_mouse_highlight (f
, x
, y
)
6883 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6887 Cursor cursor
= None
;
6890 /* When a menu is active, don't highlight because this looks odd. */
6891 #ifdef USE_X_TOOLKIT
6892 if (popup_activated ())
6896 if (NILP (Vmouse_highlight
)
6897 || !f
->glyphs_initialized_p
)
6900 dpyinfo
->mouse_face_mouse_x
= x
;
6901 dpyinfo
->mouse_face_mouse_y
= y
;
6902 dpyinfo
->mouse_face_mouse_frame
= f
;
6904 if (dpyinfo
->mouse_face_defer
)
6909 dpyinfo
->mouse_face_deferred_gc
= 1;
6913 /* Which window is that in? */
6914 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6916 /* If we were displaying active text in another window, clear that. */
6917 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6918 clear_mouse_face (dpyinfo
);
6920 /* Not on a window -> return. */
6921 if (!WINDOWP (window
))
6924 /* Convert to window-relative pixel coordinates. */
6925 w
= XWINDOW (window
);
6926 frame_to_window_pixel_xy (w
, &x
, &y
);
6928 /* Handle tool-bar window differently since it doesn't display a
6930 if (EQ (window
, f
->tool_bar_window
))
6932 note_tool_bar_highlight (f
, x
, y
);
6936 /* Mouse is on the mode or header line? */
6937 if (portion
== 1 || portion
== 3)
6939 note_mode_line_highlight (w
, x
, portion
== 1);
6944 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6946 cursor
= f
->output_data
.x
->text_cursor
;
6948 /* Are we in a window whose display is up to date?
6949 And verify the buffer's text has not changed. */
6950 b
= XBUFFER (w
->buffer
);
6951 if (/* Within text portion of the window. */
6953 && EQ (w
->window_end_valid
, w
->buffer
)
6954 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6955 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6957 int hpos
, vpos
, pos
, i
, area
;
6958 struct glyph
*glyph
;
6960 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6961 Lisp_Object
*overlay_vec
= NULL
;
6963 struct buffer
*obuf
;
6964 int obegv
, ozv
, same_region
;
6966 /* Find the glyph under X/Y. */
6967 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6969 /* Clear mouse face if X/Y not over text. */
6971 || area
!= TEXT_AREA
6972 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6974 if (clear_mouse_face (dpyinfo
))
6979 pos
= glyph
->charpos
;
6980 object
= glyph
->object
;
6981 if (!STRINGP (object
) && !BUFFERP (object
))
6984 /* If we get an out-of-range value, return now; avoid an error. */
6985 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6988 /* Make the window's buffer temporarily current for
6989 overlays_at and compute_char_face. */
6990 obuf
= current_buffer
;
6997 /* Is this char mouse-active or does it have help-echo? */
6998 position
= make_number (pos
);
7000 if (BUFFERP (object
))
7002 /* Put all the overlays we want in a vector in overlay_vec.
7003 Store the length in len. If there are more than 10, make
7004 enough space for all, and try again. */
7006 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7007 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
7008 if (noverlays
> len
)
7011 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7012 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
7015 /* Sort overlays into increasing priority order. */
7016 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7021 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
7022 && vpos
>= dpyinfo
->mouse_face_beg_row
7023 && vpos
<= dpyinfo
->mouse_face_end_row
7024 && (vpos
> dpyinfo
->mouse_face_beg_row
7025 || hpos
>= dpyinfo
->mouse_face_beg_col
)
7026 && (vpos
< dpyinfo
->mouse_face_end_row
7027 || hpos
< dpyinfo
->mouse_face_end_col
7028 || dpyinfo
->mouse_face_past_end
));
7033 /* Check mouse-face highlighting. */
7035 /* If there exists an overlay with mouse-face overlapping
7036 the one we are currently highlighting, we have to
7037 check if we enter the overlapping overlay, and then
7038 highlight only that. */
7039 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
7040 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
7042 /* Find the highest priority overlay that has a mouse-face
7045 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
7047 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
7048 if (!NILP (mouse_face
))
7049 overlay
= overlay_vec
[i
];
7052 /* If we're actually highlighting the same overlay as
7053 before, there's no need to do that again. */
7055 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
7056 goto check_help_echo
;
7058 dpyinfo
->mouse_face_overlay
= overlay
;
7060 /* Clear the display of the old active region, if any. */
7061 if (clear_mouse_face (dpyinfo
))
7064 /* If no overlay applies, get a text property. */
7066 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7068 /* Handle the overlay case. */
7069 if (!NILP (overlay
))
7071 /* Find the range of text around this char that
7072 should be active. */
7073 Lisp_Object before
, after
;
7076 before
= Foverlay_start (overlay
);
7077 after
= Foverlay_end (overlay
);
7078 /* Record this as the current active region. */
7079 fast_find_position (w
, XFASTINT (before
),
7080 &dpyinfo
->mouse_face_beg_col
,
7081 &dpyinfo
->mouse_face_beg_row
,
7082 &dpyinfo
->mouse_face_beg_x
,
7083 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7085 dpyinfo
->mouse_face_past_end
7086 = !fast_find_position (w
, XFASTINT (after
),
7087 &dpyinfo
->mouse_face_end_col
,
7088 &dpyinfo
->mouse_face_end_row
,
7089 &dpyinfo
->mouse_face_end_x
,
7090 &dpyinfo
->mouse_face_end_y
, Qnil
);
7091 dpyinfo
->mouse_face_window
= window
;
7092 dpyinfo
->mouse_face_face_id
7093 = face_at_buffer_position (w
, pos
, 0, 0,
7094 &ignore
, pos
+ 1, 1);
7096 /* Display it as active. */
7097 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7100 /* Handle the text property case. */
7101 else if (!NILP (mouse_face
) && BUFFERP (object
))
7103 /* Find the range of text around this char that
7104 should be active. */
7105 Lisp_Object before
, after
, beginning
, end
;
7108 beginning
= Fmarker_position (w
->start
);
7109 end
= make_number (BUF_Z (XBUFFER (object
))
7110 - XFASTINT (w
->window_end_pos
));
7112 = Fprevious_single_property_change (make_number (pos
+ 1),
7116 = Fnext_single_property_change (position
, Qmouse_face
,
7119 /* Record this as the current active region. */
7120 fast_find_position (w
, XFASTINT (before
),
7121 &dpyinfo
->mouse_face_beg_col
,
7122 &dpyinfo
->mouse_face_beg_row
,
7123 &dpyinfo
->mouse_face_beg_x
,
7124 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7125 dpyinfo
->mouse_face_past_end
7126 = !fast_find_position (w
, XFASTINT (after
),
7127 &dpyinfo
->mouse_face_end_col
,
7128 &dpyinfo
->mouse_face_end_row
,
7129 &dpyinfo
->mouse_face_end_x
,
7130 &dpyinfo
->mouse_face_end_y
, Qnil
);
7131 dpyinfo
->mouse_face_window
= window
;
7133 if (BUFFERP (object
))
7134 dpyinfo
->mouse_face_face_id
7135 = face_at_buffer_position (w
, pos
, 0, 0,
7136 &ignore
, pos
+ 1, 1);
7138 /* Display it as active. */
7139 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7142 else if (!NILP (mouse_face
) && STRINGP (object
))
7147 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7150 e
= Fnext_single_property_change (position
, Qmouse_face
,
7153 b
= make_number (0);
7155 e
= make_number (XSTRING (object
)->size
- 1);
7156 fast_find_string_pos (w
, XINT (b
), object
,
7157 &dpyinfo
->mouse_face_beg_col
,
7158 &dpyinfo
->mouse_face_beg_row
,
7159 &dpyinfo
->mouse_face_beg_x
,
7160 &dpyinfo
->mouse_face_beg_y
, 0);
7161 fast_find_string_pos (w
, XINT (e
), object
,
7162 &dpyinfo
->mouse_face_end_col
,
7163 &dpyinfo
->mouse_face_end_row
,
7164 &dpyinfo
->mouse_face_end_x
,
7165 &dpyinfo
->mouse_face_end_y
, 1);
7166 dpyinfo
->mouse_face_past_end
= 0;
7167 dpyinfo
->mouse_face_window
= window
;
7168 dpyinfo
->mouse_face_face_id
7169 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7171 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7174 else if (STRINGP (object
) && NILP (mouse_face
))
7176 /* A string which doesn't have mouse-face, but
7177 the text ``under'' it might have. */
7178 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7179 int start
= MATRIX_ROW_START_CHARPOS (r
);
7181 pos
= string_buffer_position (w
, object
, start
);
7183 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7187 if (!NILP (mouse_face
) && !NILP (overlay
))
7189 Lisp_Object before
= Foverlay_start (overlay
);
7190 Lisp_Object after
= Foverlay_end (overlay
);
7193 /* Note that we might not be able to find position
7194 BEFORE in the glyph matrix if the overlay is
7195 entirely covered by a `display' property. In
7196 this case, we overshoot. So let's stop in
7197 the glyph matrix before glyphs for OBJECT. */
7198 fast_find_position (w
, XFASTINT (before
),
7199 &dpyinfo
->mouse_face_beg_col
,
7200 &dpyinfo
->mouse_face_beg_row
,
7201 &dpyinfo
->mouse_face_beg_x
,
7202 &dpyinfo
->mouse_face_beg_y
,
7205 dpyinfo
->mouse_face_past_end
7206 = !fast_find_position (w
, XFASTINT (after
),
7207 &dpyinfo
->mouse_face_end_col
,
7208 &dpyinfo
->mouse_face_end_row
,
7209 &dpyinfo
->mouse_face_end_x
,
7210 &dpyinfo
->mouse_face_end_y
,
7212 dpyinfo
->mouse_face_window
= window
;
7213 dpyinfo
->mouse_face_face_id
7214 = face_at_buffer_position (w
, pos
, 0, 0,
7215 &ignore
, pos
+ 1, 1);
7217 /* Display it as active. */
7218 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7226 /* Look for a `help-echo' property. */
7228 Lisp_Object help
, overlay
;
7230 /* Check overlays first. */
7231 help
= overlay
= Qnil
;
7232 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7234 overlay
= overlay_vec
[i
];
7235 help
= Foverlay_get (overlay
, Qhelp_echo
);
7241 help_echo_window
= window
;
7242 help_echo_object
= overlay
;
7243 help_echo_pos
= pos
;
7247 Lisp_Object object
= glyph
->object
;
7248 int charpos
= glyph
->charpos
;
7250 /* Try text properties. */
7251 if (STRINGP (object
)
7253 && charpos
< XSTRING (object
)->size
)
7255 help
= Fget_text_property (make_number (charpos
),
7256 Qhelp_echo
, object
);
7259 /* If the string itself doesn't specify a help-echo,
7260 see if the buffer text ``under'' it does. */
7262 = MATRIX_ROW (w
->current_matrix
, vpos
);
7263 int start
= MATRIX_ROW_START_CHARPOS (r
);
7264 int pos
= string_buffer_position (w
, object
, start
);
7267 help
= Fget_char_property (make_number (pos
),
7268 Qhelp_echo
, w
->buffer
);
7277 else if (BUFFERP (object
)
7280 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7286 help_echo_window
= window
;
7287 help_echo_object
= object
;
7288 help_echo_pos
= charpos
;
7295 current_buffer
= obuf
;
7301 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7305 redo_mouse_highlight ()
7307 if (!NILP (last_mouse_motion_frame
)
7308 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7309 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7310 last_mouse_motion_event
.x
,
7311 last_mouse_motion_event
.y
);
7316 /***********************************************************************
7318 ***********************************************************************/
7320 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7321 struct glyph
**, int *, int *, int *));
7323 /* Tool-bar item index of the item on which a mouse button was pressed
7326 static int last_tool_bar_item
;
7329 /* Get information about the tool-bar item at position X/Y on frame F.
7330 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7331 the current matrix of the tool-bar window of F, or NULL if not
7332 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7333 item in F->tool_bar_items. Value is
7335 -1 if X/Y is not on a tool-bar item
7336 0 if X/Y is on the same item that was highlighted before.
7340 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7343 struct glyph
**glyph
;
7344 int *hpos
, *vpos
, *prop_idx
;
7346 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7347 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7350 /* Find the glyph under X/Y. */
7351 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7355 /* Get the start of this tool-bar item's properties in
7356 f->tool_bar_items. */
7357 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7360 /* Is mouse on the highlighted item? */
7361 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7362 && *vpos
>= dpyinfo
->mouse_face_beg_row
7363 && *vpos
<= dpyinfo
->mouse_face_end_row
7364 && (*vpos
> dpyinfo
->mouse_face_beg_row
7365 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7366 && (*vpos
< dpyinfo
->mouse_face_end_row
7367 || *hpos
< dpyinfo
->mouse_face_end_col
7368 || dpyinfo
->mouse_face_past_end
))
7375 /* Handle mouse button event on the tool-bar of frame F, at
7376 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
7380 x_handle_tool_bar_click (f
, button_event
)
7382 XButtonEvent
*button_event
;
7384 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7385 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7386 int hpos
, vpos
, prop_idx
;
7387 struct glyph
*glyph
;
7388 Lisp_Object enabled_p
;
7389 int x
= button_event
->x
;
7390 int y
= button_event
->y
;
7392 /* If not on the highlighted tool-bar item, return. */
7393 frame_to_window_pixel_xy (w
, &x
, &y
);
7394 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7397 /* If item is disabled, do nothing. */
7398 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7399 if (NILP (enabled_p
))
7402 if (button_event
->type
== ButtonPress
)
7404 /* Show item in pressed state. */
7405 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7406 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7407 last_tool_bar_item
= prop_idx
;
7411 Lisp_Object key
, frame
;
7412 struct input_event event
;
7414 /* Show item in released state. */
7415 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7416 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7418 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7420 XSETFRAME (frame
, f
);
7421 event
.kind
= TOOL_BAR_EVENT
;
7422 event
.frame_or_window
= frame
;
7424 kbd_buffer_store_event (&event
);
7426 event
.kind
= TOOL_BAR_EVENT
;
7427 event
.frame_or_window
= frame
;
7429 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7430 button_event
->state
);
7431 kbd_buffer_store_event (&event
);
7432 last_tool_bar_item
= -1;
7437 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7438 tool-bar window-relative coordinates X/Y. Called from
7439 note_mouse_highlight. */
7442 note_tool_bar_highlight (f
, x
, y
)
7446 Lisp_Object window
= f
->tool_bar_window
;
7447 struct window
*w
= XWINDOW (window
);
7448 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7450 struct glyph
*glyph
;
7451 struct glyph_row
*row
;
7453 Lisp_Object enabled_p
;
7455 enum draw_glyphs_face draw
;
7456 int mouse_down_p
, rc
;
7458 /* Function note_mouse_highlight is called with negative x(y
7459 values when mouse moves outside of the frame. */
7460 if (x
<= 0 || y
<= 0)
7462 clear_mouse_face (dpyinfo
);
7466 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7469 /* Not on tool-bar item. */
7470 clear_mouse_face (dpyinfo
);
7476 clear_mouse_face (dpyinfo
);
7478 /* Mouse is down, but on different tool-bar item? */
7479 mouse_down_p
= (dpyinfo
->grabbed
7480 && f
== last_mouse_frame
7481 && FRAME_LIVE_P (f
));
7483 && last_tool_bar_item
!= prop_idx
)
7486 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7487 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7489 /* If tool-bar item is not enabled, don't highlight it. */
7490 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7491 if (!NILP (enabled_p
))
7493 /* Compute the x-position of the glyph. In front and past the
7494 image is a space. We include this is the highlighted area. */
7495 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7496 for (i
= x
= 0; i
< hpos
; ++i
)
7497 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7499 /* Record this as the current active region. */
7500 dpyinfo
->mouse_face_beg_col
= hpos
;
7501 dpyinfo
->mouse_face_beg_row
= vpos
;
7502 dpyinfo
->mouse_face_beg_x
= x
;
7503 dpyinfo
->mouse_face_beg_y
= row
->y
;
7504 dpyinfo
->mouse_face_past_end
= 0;
7506 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7507 dpyinfo
->mouse_face_end_row
= vpos
;
7508 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7509 dpyinfo
->mouse_face_end_y
= row
->y
;
7510 dpyinfo
->mouse_face_window
= window
;
7511 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7513 /* Display it as active. */
7514 show_mouse_face (dpyinfo
, draw
);
7515 dpyinfo
->mouse_face_image_state
= draw
;
7520 /* Set help_echo to a help string to display for this tool-bar item.
7521 XTread_socket does the rest. */
7522 help_echo_object
= help_echo_window
= Qnil
;
7524 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7525 if (NILP (help_echo
))
7526 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7531 /* Find the glyph matrix position of buffer position CHARPOS in window
7532 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7533 current glyphs must be up to date. If CHARPOS is above window
7534 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7535 of last line in W. In the row containing CHARPOS, stop before glyphs
7536 having STOP as object. */
7538 #if 0 /* This is a version of fast_find_position that's more correct
7539 in the presence of hscrolling, for example. I didn't install
7540 it right away because the problem fixed is minor, it failed
7541 in 20.x as well, and I think it's too risky to install
7542 so near the release of 21.1. 2001-09-25 gerd. */
7545 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7548 int *hpos
, *vpos
, *x
, *y
;
7551 struct glyph_row
*row
, *first
;
7552 struct glyph
*glyph
, *end
;
7553 int i
, past_end
= 0;
7555 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7556 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7559 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7561 *x
= *y
= *hpos
= *vpos
= 0;
7566 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7573 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7575 glyph
= row
->glyphs
[TEXT_AREA
];
7576 end
= glyph
+ row
->used
[TEXT_AREA
];
7578 /* Skip over glyphs not having an object at the start of the row.
7579 These are special glyphs like truncation marks on terminal
7581 if (row
->displays_text_p
)
7583 && INTEGERP (glyph
->object
)
7584 && !EQ (stop
, glyph
->object
)
7585 && glyph
->charpos
< 0)
7587 *x
+= glyph
->pixel_width
;
7592 && !INTEGERP (glyph
->object
)
7593 && !EQ (stop
, glyph
->object
)
7594 && (!BUFFERP (glyph
->object
)
7595 || glyph
->charpos
< charpos
))
7597 *x
+= glyph
->pixel_width
;
7601 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7608 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7611 int *hpos
, *vpos
, *x
, *y
;
7616 int maybe_next_line_p
= 0;
7617 int line_start_position
;
7618 int yb
= window_text_bottom_y (w
);
7619 struct glyph_row
*row
, *best_row
;
7620 int row_vpos
, best_row_vpos
;
7623 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7624 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7628 if (row
->used
[TEXT_AREA
])
7629 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7631 line_start_position
= 0;
7633 if (line_start_position
> pos
)
7635 /* If the position sought is the end of the buffer,
7636 don't include the blank lines at the bottom of the window. */
7637 else if (line_start_position
== pos
7638 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7640 maybe_next_line_p
= 1;
7643 else if (line_start_position
> 0)
7646 best_row_vpos
= row_vpos
;
7649 if (row
->y
+ row
->height
>= yb
)
7656 /* Find the right column within BEST_ROW. */
7658 current_x
= best_row
->x
;
7659 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7661 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7662 int charpos
= glyph
->charpos
;
7664 if (BUFFERP (glyph
->object
))
7669 *vpos
= best_row_vpos
;
7674 else if (charpos
> pos
)
7677 else if (EQ (glyph
->object
, stop
))
7682 current_x
+= glyph
->pixel_width
;
7685 /* If we're looking for the end of the buffer,
7686 and we didn't find it in the line we scanned,
7687 use the start of the following line. */
7688 if (maybe_next_line_p
)
7693 current_x
= best_row
->x
;
7696 *vpos
= best_row_vpos
;
7697 *hpos
= lastcol
+ 1;
7706 /* Find the position of the glyph for position POS in OBJECT in
7707 window W's current matrix, and return in *X, *Y the pixel
7708 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
7710 RIGHT_P non-zero means return the position of the right edge of the
7711 glyph, RIGHT_P zero means return the left edge position.
7713 If no glyph for POS exists in the matrix, return the position of
7714 the glyph with the next smaller position that is in the matrix, if
7715 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7716 exists in the matrix, return the position of the glyph with the
7717 next larger position in OBJECT.
7719 Value is non-zero if a glyph was found. */
7722 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7726 int *hpos
, *vpos
, *x
, *y
;
7729 int yb
= window_text_bottom_y (w
);
7730 struct glyph_row
*r
;
7731 struct glyph
*best_glyph
= NULL
;
7732 struct glyph_row
*best_row
= NULL
;
7735 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7736 r
->enabled_p
&& r
->y
< yb
;
7739 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7740 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7743 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7744 if (EQ (g
->object
, object
))
7746 if (g
->charpos
== pos
)
7753 else if (best_glyph
== NULL
7754 || ((abs (g
->charpos
- pos
)
7755 < abs (best_glyph
->charpos
- pos
))
7758 : g
->charpos
> pos
)))
7772 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7776 *x
+= best_glyph
->pixel_width
;
7781 *vpos
= best_row
- w
->current_matrix
->rows
;
7784 return best_glyph
!= NULL
;
7788 /* Display the active region described by mouse_face_*
7789 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7792 show_mouse_face (dpyinfo
, draw
)
7793 struct x_display_info
*dpyinfo
;
7794 enum draw_glyphs_face draw
;
7796 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7797 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7799 if (/* If window is in the process of being destroyed, don't bother
7801 w
->current_matrix
!= NULL
7802 /* Don't update mouse highlight if hidden */
7803 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
7804 /* Recognize when we are called to operate on rows that don't exist
7805 anymore. This can happen when a window is split. */
7806 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7808 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7809 struct glyph_row
*row
, *first
, *last
;
7811 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7812 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7814 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7816 int start_hpos
, end_hpos
, start_x
;
7818 /* For all but the first row, the highlight starts at column 0. */
7821 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7822 start_x
= dpyinfo
->mouse_face_beg_x
;
7831 end_hpos
= dpyinfo
->mouse_face_end_col
;
7833 end_hpos
= row
->used
[TEXT_AREA
];
7835 if (end_hpos
> start_hpos
)
7837 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7838 start_hpos
, end_hpos
, draw
, 0);
7841 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
7845 /* When we've written over the cursor, arrange for it to
7846 be displayed again. */
7847 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
7848 x_display_cursor (w
, 1,
7849 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
7850 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
7853 /* Change the mouse cursor. */
7854 if (draw
== DRAW_NORMAL_TEXT
)
7855 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7856 f
->output_data
.x
->text_cursor
);
7857 else if (draw
== DRAW_MOUSE_FACE
)
7858 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7859 f
->output_data
.x
->cross_cursor
);
7861 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7862 f
->output_data
.x
->nontext_cursor
);
7865 /* Clear out the mouse-highlighted active region.
7866 Redraw it un-highlighted first. Value is non-zero if mouse
7867 face was actually drawn unhighlighted. */
7870 clear_mouse_face (dpyinfo
)
7871 struct x_display_info
*dpyinfo
;
7875 if (!NILP (dpyinfo
->mouse_face_window
))
7877 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7881 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7882 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7883 dpyinfo
->mouse_face_window
= Qnil
;
7884 dpyinfo
->mouse_face_overlay
= Qnil
;
7889 /* Clear any mouse-face on window W. This function is part of the
7890 redisplay interface, and is called from try_window_id and similar
7891 functions to ensure the mouse-highlight is off. */
7894 x_clear_mouse_face (w
)
7897 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7901 XSETWINDOW (window
, w
);
7902 if (EQ (window
, dpyinfo
->mouse_face_window
))
7903 clear_mouse_face (dpyinfo
);
7908 /* Just discard the mouse face information for frame F, if any.
7909 This is used when the size of F is changed. */
7912 cancel_mouse_face (f
)
7916 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7918 window
= dpyinfo
->mouse_face_window
;
7919 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7921 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7922 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7923 dpyinfo
->mouse_face_window
= Qnil
;
7928 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7931 /* Try to determine frame pixel position and size of the glyph under
7932 frame pixel coordinates X/Y on frame F . Return the position and
7933 size in *RECT. Value is non-zero if we could compute these
7937 glyph_rect (f
, x
, y
, rect
)
7943 int part
, found
= 0;
7945 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7948 struct window
*w
= XWINDOW (window
);
7949 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7950 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7952 frame_to_window_pixel_xy (w
, &x
, &y
);
7954 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7957 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7958 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7961 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7964 rect
->width
= g
->pixel_width
;
7965 rect
->height
= r
->height
;
7966 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7967 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7977 /* Return the current position of the mouse.
7978 *FP should be a frame which indicates which display to ask about.
7980 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7981 and *PART to the frame, window, and scroll bar part that the mouse
7982 is over. Set *X and *Y to the portion and whole of the mouse's
7983 position on the scroll bar.
7985 If the mouse movement started elsewhere, set *FP to the frame the
7986 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7989 Set *TIME to the server time-stamp for the time at which the mouse
7990 was at this position.
7992 Don't store anything if we don't have a valid set of values to report.
7994 This clears the mouse_moved flag, so we can wait for the next mouse
7998 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
8001 Lisp_Object
*bar_window
;
8002 enum scroll_bar_part
*part
;
8004 unsigned long *time
;
8010 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
8011 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
8017 Window dummy_window
;
8020 Lisp_Object frame
, tail
;
8022 /* Clear the mouse-moved flag for every frame on this display. */
8023 FOR_EACH_FRAME (tail
, frame
)
8024 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
8025 XFRAME (frame
)->mouse_moved
= 0;
8027 last_mouse_scroll_bar
= Qnil
;
8029 /* Figure out which root window we're on. */
8030 XQueryPointer (FRAME_X_DISPLAY (*fp
),
8031 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
8033 /* The root window which contains the pointer. */
8036 /* Trash which we can't trust if the pointer is on
8037 a different screen. */
8040 /* The position on that root window. */
8043 /* More trash we can't trust. */
8046 /* Modifier keys and pointer buttons, about which
8048 (unsigned int *) &dummy
);
8050 /* Now we have a position on the root; find the innermost window
8051 containing the pointer. */
8055 int parent_x
= 0, parent_y
= 0;
8060 /* XTranslateCoordinates can get errors if the window
8061 structure is changing at the same time this function
8062 is running. So at least we must not crash from them. */
8064 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
8066 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
8067 && FRAME_LIVE_P (last_mouse_frame
))
8069 /* If mouse was grabbed on a frame, give coords for that frame
8070 even if the mouse is now outside it. */
8071 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8073 /* From-window, to-window. */
8074 root
, FRAME_X_WINDOW (last_mouse_frame
),
8076 /* From-position, to-position. */
8077 root_x
, root_y
, &win_x
, &win_y
,
8081 f1
= last_mouse_frame
;
8087 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8089 /* From-window, to-window. */
8092 /* From-position, to-position. */
8093 root_x
, root_y
, &win_x
, &win_y
,
8098 if (child
== None
|| child
== win
)
8106 /* Now we know that:
8107 win is the innermost window containing the pointer
8108 (XTC says it has no child containing the pointer),
8109 win_x and win_y are the pointer's position in it
8110 (XTC did this the last time through), and
8111 parent_x and parent_y are the pointer's position in win's parent.
8112 (They are what win_x and win_y were when win was child.
8113 If win is the root window, it has no parent, and
8114 parent_{x,y} are invalid, but that's okay, because we'll
8115 never use them in that case.) */
8117 /* Is win one of our frames? */
8118 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
8120 #ifdef USE_X_TOOLKIT
8121 /* If we end up with the menu bar window, say it's not
8124 && f1
->output_data
.x
->menubar_widget
8125 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
8127 #endif /* USE_X_TOOLKIT */
8130 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
8133 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
8135 /* If not, is it one of our scroll bars? */
8138 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
8142 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8148 if (f1
== 0 && insist
> 0)
8149 f1
= SELECTED_FRAME ();
8153 /* Ok, we found a frame. Store all the values.
8154 last_mouse_glyph is a rectangle used to reduce the
8155 generation of mouse events. To not miss any motion
8156 events, we must divide the frame into rectangles of the
8157 size of the smallest character that could be displayed
8158 on it, i.e. into the same rectangles that matrices on
8159 the frame are divided into. */
8161 int width
, height
, gx
, gy
;
8164 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
8165 last_mouse_glyph
= rect
;
8168 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8169 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8173 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8174 round down even for negative values. */
8179 gx
= (gx
+ width
- 1) / width
* width
;
8180 gy
= (gy
+ height
- 1) / height
* height
;
8182 last_mouse_glyph
.width
= width
;
8183 last_mouse_glyph
.height
= height
;
8184 last_mouse_glyph
.x
= gx
;
8185 last_mouse_glyph
.y
= gy
;
8191 XSETINT (*x
, win_x
);
8192 XSETINT (*y
, win_y
);
8193 *time
= last_mouse_movement_time
;
8202 #ifdef USE_X_TOOLKIT
8204 /* Atimer callback function for TIMER. Called every 0.1s to process
8205 Xt timeouts, if needed. We must avoid calling XtAppPending as
8206 much as possible because that function does an implicit XFlush
8207 that slows us down. */
8210 x_process_timeouts (timer
)
8211 struct atimer
*timer
;
8213 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
8216 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8217 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8222 #endif /* USE_X_TOOLKIT */
8225 /* Scroll bar support. */
8227 /* Given an X window ID, find the struct scroll_bar which manages it.
8228 This can be called in GC, so we have to make sure to strip off mark
8231 static struct scroll_bar
*
8232 x_window_to_scroll_bar (window_id
)
8237 for (tail
= Vframe_list
;
8238 XGCTYPE (tail
) == Lisp_Cons
;
8241 Lisp_Object frame
, bar
, condemned
;
8243 frame
= XCAR (tail
);
8244 /* All elements of Vframe_list should be frames. */
8245 if (! GC_FRAMEP (frame
))
8248 /* Scan this frame's scroll bar list for a scroll bar with the
8250 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8251 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8252 /* This trick allows us to search both the ordinary and
8253 condemned scroll bar lists with one loop. */
8254 ! GC_NILP (bar
) || (bar
= condemned
,
8257 bar
= XSCROLL_BAR (bar
)->next
)
8258 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8259 return XSCROLL_BAR (bar
);
8266 #if defined USE_LUCID
8268 /* Return the Lucid menu bar WINDOW is part of. Return null
8269 if WINDOW is not part of a menu bar. */
8272 x_window_to_menu_bar (window
)
8277 for (tail
= Vframe_list
;
8278 XGCTYPE (tail
) == Lisp_Cons
;
8281 Lisp_Object frame
= XCAR (tail
);
8282 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8284 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8291 #endif /* USE_LUCID */
8294 /************************************************************************
8296 ************************************************************************/
8298 #ifdef USE_TOOLKIT_SCROLL_BARS
8300 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8301 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8302 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8303 struct scroll_bar
*));
8304 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8308 /* Id of action hook installed for scroll bars. */
8310 static XtActionHookId action_hook_id
;
8312 /* Lisp window being scrolled. Set when starting to interact with
8313 a toolkit scroll bar, reset to nil when ending the interaction. */
8315 static Lisp_Object window_being_scrolled
;
8317 /* Last scroll bar part sent in xm_scroll_callback. */
8319 static int last_scroll_bar_part
;
8321 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8322 that movements of 1/20 of the screen size are mapped to up/down. */
8324 static Boolean xaw3d_arrow_scroll
;
8326 /* Whether the drag scrolling maintains the mouse at the top of the
8327 thumb. If not, resizing the thumb needs to be done more carefully
8328 to avoid jerkyness. */
8330 static Boolean xaw3d_pick_top
;
8333 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8334 bars are used.. The hook is responsible for detecting when
8335 the user ends an interaction with the scroll bar, and generates
8336 a `end-scroll' scroll_bar_click' event if so. */
8339 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8342 XtPointer client_data
;
8346 Cardinal
*num_params
;
8352 scroll_bar_p
= XmIsScrollBar (widget
);
8353 end_action
= "Release";
8354 #else /* !USE_MOTIF i.e. use Xaw */
8355 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8356 end_action
= "EndScroll";
8357 #endif /* USE_MOTIF */
8360 && strcmp (action_name
, end_action
) == 0
8361 && WINDOWP (window_being_scrolled
))
8365 x_send_scroll_bar_event (window_being_scrolled
,
8366 scroll_bar_end_scroll
, 0, 0);
8367 w
= XWINDOW (window_being_scrolled
);
8368 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8369 window_being_scrolled
= Qnil
;
8370 last_scroll_bar_part
= -1;
8372 /* Xt timeouts no longer needed. */
8373 toolkit_scroll_bar_interaction
= 0;
8377 /* A vector of windows used for communication between
8378 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8380 static struct window
**scroll_bar_windows
;
8381 static int scroll_bar_windows_size
;
8384 /* Send a client message with message type Xatom_Scrollbar for a
8385 scroll action to the frame of WINDOW. PART is a value identifying
8386 the part of the scroll bar that was clicked on. PORTION is the
8387 amount to scroll of a whole of WHOLE. */
8390 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8392 int part
, portion
, whole
;
8395 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8396 struct window
*w
= XWINDOW (window
);
8397 struct frame
*f
= XFRAME (w
->frame
);
8402 /* Construct a ClientMessage event to send to the frame. */
8403 ev
->type
= ClientMessage
;
8404 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8405 ev
->display
= FRAME_X_DISPLAY (f
);
8406 ev
->window
= FRAME_X_WINDOW (f
);
8409 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8410 not enough to store a pointer or Lisp_Object on a 64 bit system.
8411 So, store the window in scroll_bar_windows and pass the index
8412 into that array in the event. */
8413 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8414 if (scroll_bar_windows
[i
] == NULL
)
8417 if (i
== scroll_bar_windows_size
)
8419 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8420 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8421 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8423 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8425 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8426 scroll_bar_windows_size
= new_size
;
8429 scroll_bar_windows
[i
] = w
;
8430 ev
->data
.l
[0] = (long) i
;
8431 ev
->data
.l
[1] = (long) part
;
8432 ev
->data
.l
[2] = (long) 0;
8433 ev
->data
.l
[3] = (long) portion
;
8434 ev
->data
.l
[4] = (long) whole
;
8436 /* Make Xt timeouts work while the scroll bar is active. */
8437 toolkit_scroll_bar_interaction
= 1;
8439 /* Setting the event mask to zero means that the message will
8440 be sent to the client that created the window, and if that
8441 window no longer exists, no event will be sent. */
8442 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8447 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8451 x_scroll_bar_to_input_event (event
, ievent
)
8453 struct input_event
*ievent
;
8455 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8460 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8461 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8463 XSETWINDOW (window
, w
);
8464 f
= XFRAME (w
->frame
);
8466 ievent
->kind
= scroll_bar_click
;
8467 ievent
->frame_or_window
= window
;
8469 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8470 ievent
->part
= ev
->data
.l
[1];
8471 ievent
->code
= ev
->data
.l
[2];
8472 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8473 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8474 ievent
->modifiers
= 0;
8480 /* Minimum and maximum values used for Motif scroll bars. */
8483 #define XM_SB_MAX 10000000
8484 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8487 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8488 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8489 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
8492 xm_scroll_callback (widget
, client_data
, call_data
)
8494 XtPointer client_data
, call_data
;
8496 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8497 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8498 int part
= -1, whole
= 0, portion
= 0;
8502 case XmCR_DECREMENT
:
8503 bar
->dragging
= Qnil
;
8504 part
= scroll_bar_up_arrow
;
8507 case XmCR_INCREMENT
:
8508 bar
->dragging
= Qnil
;
8509 part
= scroll_bar_down_arrow
;
8512 case XmCR_PAGE_DECREMENT
:
8513 bar
->dragging
= Qnil
;
8514 part
= scroll_bar_above_handle
;
8517 case XmCR_PAGE_INCREMENT
:
8518 bar
->dragging
= Qnil
;
8519 part
= scroll_bar_below_handle
;
8523 bar
->dragging
= Qnil
;
8524 part
= scroll_bar_to_top
;
8527 case XmCR_TO_BOTTOM
:
8528 bar
->dragging
= Qnil
;
8529 part
= scroll_bar_to_bottom
;
8535 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8536 && XINT (bar
->dragging
) <= cs
->value
);
8538 /* Get the slider size. */
8540 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8543 /* At the max position of the scroll bar, do a line-wise
8544 movement. Without doing anything, we would be called with
8545 the same cs->value again and again. If we want to make
8546 sure that we can reach the end of the buffer, we have to do
8549 Implementation note: setting bar->dragging always to
8550 cs->value gives a smoother movement at the max position.
8551 Setting it to nil when doing line-wise movement gives
8552 a better slider behavior. */
8554 if (cs
->value
+ slider_size
== XM_SB_MAX
8556 && last_scroll_bar_part
== scroll_bar_down_arrow
))
8558 part
= scroll_bar_down_arrow
;
8559 bar
->dragging
= Qnil
;
8563 whole
= XM_SB_RANGE
;
8564 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
8565 part
= scroll_bar_handle
;
8566 bar
->dragging
= make_number (cs
->value
);
8571 case XmCR_VALUE_CHANGED
:
8577 window_being_scrolled
= bar
->window
;
8578 last_scroll_bar_part
= part
;
8579 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8584 #else /* !USE_MOTIF, i.e. Xaw. */
8587 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8588 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8589 scroll bar struct. CALL_DATA is a pointer to a float saying where
8593 xaw_jump_callback (widget
, client_data
, call_data
)
8595 XtPointer client_data
, call_data
;
8597 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8598 float top
= *(float *) call_data
;
8600 int whole
, portion
, height
;
8603 /* Get the size of the thumb, a value between 0 and 1. */
8605 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8609 portion
= shown
< 1 ? top
* whole
: 0;
8611 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8612 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8613 the bottom, so we force the scrolling whenever we see that we're
8614 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8615 we try to ensure that we always stay two pixels away from the
8617 part
= scroll_bar_down_arrow
;
8619 part
= scroll_bar_handle
;
8621 window_being_scrolled
= bar
->window
;
8622 bar
->dragging
= make_number (portion
);
8623 last_scroll_bar_part
= part
;
8624 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8628 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8629 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8630 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8631 the scroll bar. CALL_DATA is an integer specifying the action that
8632 has taken place. Its magnitude is in the range 0..height of the
8633 scroll bar. Negative values mean scroll towards buffer start.
8634 Values < height of scroll bar mean line-wise movement. */
8637 xaw_scroll_callback (widget
, client_data
, call_data
)
8639 XtPointer client_data
, call_data
;
8641 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8642 /* The position really is stored cast to a pointer. */
8643 int position
= (long) call_data
;
8647 /* Get the height of the scroll bar. */
8649 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8652 if (abs (position
) >= height
)
8653 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8655 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8656 it maps line-movement to call_data = max(5, height/20). */
8657 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8658 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8660 part
= scroll_bar_move_ratio
;
8662 window_being_scrolled
= bar
->window
;
8663 bar
->dragging
= Qnil
;
8664 last_scroll_bar_part
= part
;
8665 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8669 #endif /* not USE_MOTIF */
8672 /* Create the widget for scroll bar BAR on frame F. Record the widget
8673 and X window of the scroll bar in BAR. */
8676 x_create_toolkit_scroll_bar (f
, bar
)
8678 struct scroll_bar
*bar
;
8684 char *scroll_bar_name
= "verticalScrollBar";
8685 unsigned long pixel
;
8690 /* Set resources. Create the widget. */
8691 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8692 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8693 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8694 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8695 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8696 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8697 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8699 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8702 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8706 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8709 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8713 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8714 scroll_bar_name
, av
, ac
);
8716 /* Add one callback for everything that can happen. */
8717 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8719 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8721 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8723 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8725 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8727 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8729 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8732 /* Realize the widget. Only after that is the X window created. */
8733 XtRealizeWidget (widget
);
8735 /* Set the cursor to an arrow. I didn't find a resource to do that.
8736 And I'm wondering why it hasn't an arrow cursor by default. */
8737 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8738 f
->output_data
.x
->nontext_cursor
);
8740 #else /* !USE_MOTIF i.e. use Xaw */
8742 /* Set resources. Create the widget. The background of the
8743 Xaw3d scroll bar widget is a little bit light for my taste.
8744 We don't alter it here to let users change it according
8745 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8746 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8747 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8748 /* For smoother scrolling with Xaw3d -sm */
8749 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8751 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8754 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8758 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8761 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8765 /* Top/bottom shadow colors. */
8767 /* Allocate them, if necessary. */
8768 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
8770 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8771 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8772 &pixel
, 1.2, 0x8000))
8774 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
8776 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8778 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8779 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8780 &pixel
, 0.6, 0x4000))
8782 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
8785 /* Tell the toolkit about them. */
8786 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
8787 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8788 /* We tried to allocate a color for the top/bottom shadow, and
8789 failed, so tell Xaw3d to use dithering instead. */
8791 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
8795 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
8796 be more consistent with other emacs 3d colors, and since Xaw3d is
8797 not good at dealing with allocation failure. */
8799 /* This tells Xaw3d to use real colors instead of dithering for
8801 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
8804 /* Specify the colors. */
8805 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
8808 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
8811 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
8814 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
8819 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8820 f
->output_data
.x
->edit_widget
, av
, ac
);
8824 char *val
= initial
;
8825 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8826 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8828 { /* ARROW_SCROLL */
8829 xaw3d_arrow_scroll
= True
;
8830 /* Isn't that just a personal preference ? -sm */
8831 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8835 /* Define callbacks. */
8836 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8837 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8840 /* Realize the widget. Only after that is the X window created. */
8841 XtRealizeWidget (widget
);
8843 #endif /* !USE_MOTIF */
8845 /* Install an action hook that let's us detect when the user
8846 finishes interacting with a scroll bar. */
8847 if (action_hook_id
== 0)
8848 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8850 /* Remember X window and widget in the scroll bar vector. */
8851 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8852 xwindow
= XtWindow (widget
);
8853 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8859 /* Set the thumb size and position of scroll bar BAR. We are currently
8860 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8863 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8864 struct scroll_bar
*bar
;
8865 int portion
, position
, whole
;
8867 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8868 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8875 top
= (float) position
/ whole
;
8876 shown
= (float) portion
/ whole
;
8885 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8886 is the scroll bar's maximum and MIN is the scroll bar's minimum
8888 size
= shown
* XM_SB_RANGE
;
8889 size
= min (size
, XM_SB_RANGE
);
8890 size
= max (size
, 1);
8892 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8893 value
= top
* XM_SB_RANGE
;
8894 value
= min (value
, XM_SB_MAX
- size
);
8895 value
= max (value
, XM_SB_MIN
);
8897 if (NILP (bar
->dragging
))
8898 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8899 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8900 /* This has the negative side effect that the slider value is
8901 not what it would be if we scrolled here using line-wise or
8902 page-wise movement. */
8903 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8906 /* If currently dragging, only update the slider size.
8907 This reduces flicker effects. */
8908 int old_value
, old_size
, increment
, page_increment
;
8910 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8911 &increment
, &page_increment
);
8912 XmScrollBarSetValues (widget
, old_value
,
8913 min (size
, XM_SB_RANGE
- old_value
),
8917 #else /* !USE_MOTIF i.e. use Xaw */
8919 float old_top
, old_shown
;
8921 XtVaGetValues (widget
,
8922 XtNtopOfThumb
, &old_top
,
8923 XtNshown
, &old_shown
,
8927 /* Massage the top+shown values. */
8928 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8929 top
= max (0, min (1, top
));
8932 /* Keep two pixels available for moving the thumb down. */
8933 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8935 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8936 check that your system's configuration file contains a define
8937 for `NARROWPROTO'. See s/freebsd.h for an example. */
8938 if (top
!= old_top
|| shown
!= old_shown
)
8940 if (NILP (bar
->dragging
))
8941 XawScrollbarSetThumb (widget
, top
, shown
);
8945 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8946 int scroll_mode
= 0;
8948 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8949 if (xaw3d_arrow_scroll
)
8951 /* Xaw3d stupidly ignores resize requests while dragging
8952 so we have to make it believe it's not in dragging mode. */
8953 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8954 if (scroll_mode
== 2)
8955 sb
->scrollbar
.scroll_mode
= 0;
8958 /* Try to make the scrolling a tad smoother. */
8959 if (!xaw3d_pick_top
)
8960 shown
= min (shown
, old_shown
);
8962 XawScrollbarSetThumb (widget
, top
, shown
);
8965 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8966 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8971 #endif /* !USE_MOTIF */
8976 #endif /* USE_TOOLKIT_SCROLL_BARS */
8980 /************************************************************************
8981 Scroll bars, general
8982 ************************************************************************/
8984 /* Create a scroll bar and return the scroll bar vector for it. W is
8985 the Emacs window on which to create the scroll bar. TOP, LEFT,
8986 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8989 static struct scroll_bar
*
8990 x_scroll_bar_create (w
, top
, left
, width
, height
)
8992 int top
, left
, width
, height
;
8994 struct frame
*f
= XFRAME (w
->frame
);
8995 struct scroll_bar
*bar
8996 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
9000 #ifdef USE_TOOLKIT_SCROLL_BARS
9001 x_create_toolkit_scroll_bar (f
, bar
);
9002 #else /* not USE_TOOLKIT_SCROLL_BARS */
9004 XSetWindowAttributes a
;
9008 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
9009 if (a
.background_pixel
== -1)
9010 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
9012 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
9013 | ButtonMotionMask
| PointerMotionHintMask
9015 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
9017 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
9019 /* Clear the area of W that will serve as a scroll bar. This is
9020 for the case that a window has been split horizontally. In
9021 this case, no clear_frame is generated to reduce flickering. */
9022 if (width
> 0 && height
> 0)
9023 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9025 window_box_height (w
), False
);
9027 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9028 /* Position and size of scroll bar. */
9029 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9031 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9033 /* Border width, depth, class, and visual. */
9040 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
9042 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9044 XSETWINDOW (bar
->window
, w
);
9045 XSETINT (bar
->top
, top
);
9046 XSETINT (bar
->left
, left
);
9047 XSETINT (bar
->width
, width
);
9048 XSETINT (bar
->height
, height
);
9049 XSETINT (bar
->start
, 0);
9050 XSETINT (bar
->end
, 0);
9051 bar
->dragging
= Qnil
;
9053 /* Add bar to its frame's list of scroll bars. */
9054 bar
->next
= FRAME_SCROLL_BARS (f
);
9056 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9057 if (!NILP (bar
->next
))
9058 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9060 /* Map the window/widget. */
9061 #ifdef USE_TOOLKIT_SCROLL_BARS
9063 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
9064 XtConfigureWidget (scroll_bar
,
9065 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9067 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9068 max (height
, 1), 0);
9069 XtMapWidget (scroll_bar
);
9071 #else /* not USE_TOOLKIT_SCROLL_BARS */
9072 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9073 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9080 /* Draw BAR's handle in the proper position.
9082 If the handle is already drawn from START to END, don't bother
9083 redrawing it, unless REBUILD is non-zero; in that case, always
9084 redraw it. (REBUILD is handy for drawing the handle after expose
9087 Normally, we want to constrain the start and end of the handle to
9088 fit inside its rectangle, but if the user is dragging the scroll
9089 bar handle, we want to let them drag it down all the way, so that
9090 the bar's top is as far down as it goes; otherwise, there's no way
9091 to move to the very end of the buffer. */
9093 #ifndef USE_TOOLKIT_SCROLL_BARS
9096 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
9097 struct scroll_bar
*bar
;
9101 int dragging
= ! NILP (bar
->dragging
);
9102 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9103 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9104 GC gc
= f
->output_data
.x
->normal_gc
;
9106 /* If the display is already accurate, do nothing. */
9108 && start
== XINT (bar
->start
)
9109 && end
== XINT (bar
->end
))
9115 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
9116 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9117 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9119 /* Make sure the values are reasonable, and try to preserve
9120 the distance between start and end. */
9122 int length
= end
- start
;
9126 else if (start
> top_range
)
9128 end
= start
+ length
;
9132 else if (end
> top_range
&& ! dragging
)
9136 /* Store the adjusted setting in the scroll bar. */
9137 XSETINT (bar
->start
, start
);
9138 XSETINT (bar
->end
, end
);
9140 /* Clip the end position, just for display. */
9141 if (end
> top_range
)
9144 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
9145 below top positions, to make sure the handle is always at least
9146 that many pixels tall. */
9147 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
9149 /* Draw the empty space above the handle. Note that we can't clear
9150 zero-height areas; that means "clear to end of window." */
9152 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9153 /* x, y, width, height, and exposures. */
9154 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9155 VERTICAL_SCROLL_BAR_TOP_BORDER
,
9156 inside_width
, start
,
9159 /* Change to proper foreground color if one is specified. */
9160 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9161 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9162 f
->output_data
.x
->scroll_bar_foreground_pixel
);
9164 /* Draw the handle itself. */
9165 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9166 /* x, y, width, height */
9167 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9168 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
9169 inside_width
, end
- start
);
9171 /* Restore the foreground color of the GC if we changed it above. */
9172 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9173 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9174 f
->output_data
.x
->foreground_pixel
);
9176 /* Draw the empty space below the handle. Note that we can't
9177 clear zero-height areas; that means "clear to end of window." */
9178 if (end
< inside_height
)
9179 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9180 /* x, y, width, height, and exposures. */
9181 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9182 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
9183 inside_width
, inside_height
- end
,
9191 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9193 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
9197 x_scroll_bar_remove (bar
)
9198 struct scroll_bar
*bar
;
9200 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9203 #ifdef USE_TOOLKIT_SCROLL_BARS
9204 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
9206 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9209 /* Disassociate this scroll bar from its window. */
9210 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
9216 /* Set the handle of the vertical scroll bar for WINDOW to indicate
9217 that we are displaying PORTION characters out of a total of WHOLE
9218 characters, starting at POSITION. If WINDOW has no scroll bar,
9222 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
9224 int portion
, whole
, position
;
9226 struct frame
*f
= XFRAME (w
->frame
);
9227 struct scroll_bar
*bar
;
9228 int top
, height
, left
, sb_left
, width
, sb_width
;
9229 int window_x
, window_y
, window_width
, window_height
;
9231 /* Get window dimensions. */
9232 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9234 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9235 height
= window_height
;
9237 /* Compute the left edge of the scroll bar area. */
9238 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9239 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
9241 left
= XFASTINT (w
->left
);
9242 left
*= CANON_X_UNIT (f
);
9243 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
9245 /* Compute the width of the scroll bar which might be less than
9246 the width of the area reserved for the scroll bar. */
9247 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
9248 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
9252 /* Compute the left edge of the scroll bar. */
9253 #ifdef USE_TOOLKIT_SCROLL_BARS
9254 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9255 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
9257 sb_left
= left
+ (width
- sb_width
) / 2;
9259 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9260 sb_left
= left
+ width
- sb_width
;
9265 /* Does the scroll bar exist yet? */
9266 if (NILP (w
->vertical_scroll_bar
))
9268 if (width
> 0 && height
> 0)
9271 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9272 left
, top
, width
, height
, False
);
9276 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9280 /* It may just need to be moved and resized. */
9281 unsigned int mask
= 0;
9283 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9287 if (sb_left
!= XINT (bar
->left
))
9289 if (top
!= XINT (bar
->top
))
9291 if (sb_width
!= XINT (bar
->width
))
9293 if (height
!= XINT (bar
->height
))
9296 #ifdef USE_TOOLKIT_SCROLL_BARS
9298 /* Since toolkit scroll bars are smaller than the space reserved
9299 for them on the frame, we have to clear "under" them. */
9300 if (width
> 0 && height
> 0)
9301 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9302 left
, top
, width
, height
, False
);
9304 /* Move/size the scroll bar widget. */
9306 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9307 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9309 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9310 max (height
, 1), 0);
9312 #else /* not USE_TOOLKIT_SCROLL_BARS */
9314 /* Clear areas not covered by the scroll bar because of
9315 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9316 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9318 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9319 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9321 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9322 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9323 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9327 /* Clear areas not covered by the scroll bar because it's not as
9328 wide as the area reserved for it . This makes sure a
9329 previous mode line display is cleared after C-x 2 C-x 1, for
9332 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9333 int rest
= area_width
- sb_width
;
9334 if (rest
> 0 && height
> 0)
9336 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
9337 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9338 left
+ area_width
- rest
, top
,
9339 rest
, height
, False
);
9341 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9342 left
, top
, rest
, height
, False
);
9346 /* Move/size the scroll bar window. */
9351 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9353 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9355 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9359 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9361 /* Remember new settings. */
9362 XSETINT (bar
->left
, sb_left
);
9363 XSETINT (bar
->top
, top
);
9364 XSETINT (bar
->width
, sb_width
);
9365 XSETINT (bar
->height
, height
);
9370 #ifdef USE_TOOLKIT_SCROLL_BARS
9371 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9372 #else /* not USE_TOOLKIT_SCROLL_BARS */
9373 /* Set the scroll bar's current state, unless we're currently being
9375 if (NILP (bar
->dragging
))
9377 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9380 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9383 int start
= ((double) position
* top_range
) / whole
;
9384 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9385 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9388 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9390 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9394 /* The following three hooks are used when we're doing a thorough
9395 redisplay of the frame. We don't explicitly know which scroll bars
9396 are going to be deleted, because keeping track of when windows go
9397 away is a real pain - "Can you say set-window-configuration, boys
9398 and girls?" Instead, we just assert at the beginning of redisplay
9399 that *all* scroll bars are to be removed, and then save a scroll bar
9400 from the fiery pit when we actually redisplay its window. */
9402 /* Arrange for all scroll bars on FRAME to be removed at the next call
9403 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9404 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9407 XTcondemn_scroll_bars (frame
)
9410 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9411 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9414 bar
= FRAME_SCROLL_BARS (frame
);
9415 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9416 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9417 XSCROLL_BAR (bar
)->prev
= Qnil
;
9418 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9419 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9420 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9425 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9426 Note that WINDOW isn't necessarily condemned at all. */
9429 XTredeem_scroll_bar (window
)
9430 struct window
*window
;
9432 struct scroll_bar
*bar
;
9435 /* We can't redeem this window's scroll bar if it doesn't have one. */
9436 if (NILP (window
->vertical_scroll_bar
))
9439 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9441 /* Unlink it from the condemned list. */
9442 f
= XFRAME (WINDOW_FRAME (window
));
9443 if (NILP (bar
->prev
))
9445 /* If the prev pointer is nil, it must be the first in one of
9447 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9448 /* It's not condemned. Everything's fine. */
9450 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9451 window
->vertical_scroll_bar
))
9452 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9454 /* If its prev pointer is nil, it must be at the front of
9455 one or the other! */
9459 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9461 if (! NILP (bar
->next
))
9462 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9464 bar
->next
= FRAME_SCROLL_BARS (f
);
9466 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9467 if (! NILP (bar
->next
))
9468 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9471 /* Remove all scroll bars on FRAME that haven't been saved since the
9472 last call to `*condemn_scroll_bars_hook'. */
9475 XTjudge_scroll_bars (f
)
9478 Lisp_Object bar
, next
;
9480 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9482 /* Clear out the condemned list now so we won't try to process any
9483 more events on the hapless scroll bars. */
9484 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9486 for (; ! NILP (bar
); bar
= next
)
9488 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9490 x_scroll_bar_remove (b
);
9493 b
->next
= b
->prev
= Qnil
;
9496 /* Now there should be no references to the condemned scroll bars,
9497 and they should get garbage-collected. */
9501 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9502 is a no-op when using toolkit scroll bars.
9504 This may be called from a signal handler, so we have to ignore GC
9508 x_scroll_bar_expose (bar
, event
)
9509 struct scroll_bar
*bar
;
9512 #ifndef USE_TOOLKIT_SCROLL_BARS
9514 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9515 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9516 GC gc
= f
->output_data
.x
->normal_gc
;
9517 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9521 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9523 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9524 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9526 /* x, y, width, height */
9528 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9529 XINT (bar
->height
) - 1);
9533 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9536 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9537 is set to something other than no_event, it is enqueued.
9539 This may be called from a signal handler, so we have to ignore GC
9542 #ifndef USE_TOOLKIT_SCROLL_BARS
9545 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9546 struct scroll_bar
*bar
;
9548 struct input_event
*emacs_event
;
9550 if (! GC_WINDOWP (bar
->window
))
9553 emacs_event
->kind
= scroll_bar_click
;
9554 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9555 emacs_event
->modifiers
9556 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9557 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9558 event
->xbutton
.state
)
9559 | (event
->type
== ButtonRelease
9562 emacs_event
->frame_or_window
= bar
->window
;
9563 emacs_event
->arg
= Qnil
;
9564 emacs_event
->timestamp
= event
->xbutton
.time
;
9567 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9569 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9572 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9573 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9576 if (y
> top_range
) y
= top_range
;
9578 if (y
< XINT (bar
->start
))
9579 emacs_event
->part
= scroll_bar_above_handle
;
9580 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9581 emacs_event
->part
= scroll_bar_handle
;
9583 emacs_event
->part
= scroll_bar_below_handle
;
9585 /* Just because the user has clicked on the handle doesn't mean
9586 they want to drag it. Lisp code needs to be able to decide
9587 whether or not we're dragging. */
9589 /* If the user has just clicked on the handle, record where they're
9591 if (event
->type
== ButtonPress
9592 && emacs_event
->part
== scroll_bar_handle
)
9593 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9596 /* If the user has released the handle, set it to its final position. */
9597 if (event
->type
== ButtonRelease
9598 && ! NILP (bar
->dragging
))
9600 int new_start
= y
- XINT (bar
->dragging
);
9601 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9603 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9604 bar
->dragging
= Qnil
;
9607 /* Same deal here as the other #if 0. */
9609 /* Clicks on the handle are always reported as occurring at the top of
9611 if (emacs_event
->part
== scroll_bar_handle
)
9612 emacs_event
->x
= bar
->start
;
9614 XSETINT (emacs_event
->x
, y
);
9616 XSETINT (emacs_event
->x
, y
);
9619 XSETINT (emacs_event
->y
, top_range
);
9623 /* Handle some mouse motion while someone is dragging the scroll bar.
9625 This may be called from a signal handler, so we have to ignore GC
9629 x_scroll_bar_note_movement (bar
, event
)
9630 struct scroll_bar
*bar
;
9633 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9635 last_mouse_movement_time
= event
->xmotion
.time
;
9638 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9640 /* If we're dragging the bar, display it. */
9641 if (! GC_NILP (bar
->dragging
))
9643 /* Where should the handle be now? */
9644 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9646 if (new_start
!= XINT (bar
->start
))
9648 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9650 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9655 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9657 /* Return information to the user about the current position of the mouse
9658 on the scroll bar. */
9661 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9663 Lisp_Object
*bar_window
;
9664 enum scroll_bar_part
*part
;
9666 unsigned long *time
;
9668 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9669 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9670 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9672 Window dummy_window
;
9674 unsigned int dummy_mask
;
9678 /* Get the mouse's position relative to the scroll bar window, and
9680 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9682 /* Root, child, root x and root y. */
9683 &dummy_window
, &dummy_window
,
9684 &dummy_coord
, &dummy_coord
,
9686 /* Position relative to scroll bar. */
9689 /* Mouse buttons and modifier keys. */
9696 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9699 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9701 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9703 if (! NILP (bar
->dragging
))
9704 win_y
-= XINT (bar
->dragging
);
9708 if (win_y
> top_range
)
9712 *bar_window
= bar
->window
;
9714 if (! NILP (bar
->dragging
))
9715 *part
= scroll_bar_handle
;
9716 else if (win_y
< XINT (bar
->start
))
9717 *part
= scroll_bar_above_handle
;
9718 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9719 *part
= scroll_bar_handle
;
9721 *part
= scroll_bar_below_handle
;
9723 XSETINT (*x
, win_y
);
9724 XSETINT (*y
, top_range
);
9727 last_mouse_scroll_bar
= Qnil
;
9730 *time
= last_mouse_movement_time
;
9736 /* The screen has been cleared so we may have changed foreground or
9737 background colors, and the scroll bars may need to be redrawn.
9738 Clear out the scroll bars, and ask for expose events, so we can
9742 x_scroll_bar_clear (f
)
9745 #ifndef USE_TOOLKIT_SCROLL_BARS
9748 /* We can have scroll bars even if this is 0,
9749 if we just turned off scroll bar mode.
9750 But in that case we should not clear them. */
9751 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9752 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9753 bar
= XSCROLL_BAR (bar
)->next
)
9754 XClearArea (FRAME_X_DISPLAY (f
),
9755 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9757 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9760 /* This processes Expose events from the menu-bar specific X event
9761 loop in xmenu.c. This allows to redisplay the frame if necessary
9762 when handling menu-bar or pop-up items. */
9765 process_expose_from_menu (event
)
9769 struct x_display_info
*dpyinfo
;
9770 int frame_exposed_p
= 0;
9774 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9775 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9778 if (f
->async_visible
== 0)
9780 f
->async_visible
= 1;
9781 f
->async_iconified
= 0;
9782 f
->output_data
.x
->has_been_visible
= 1;
9783 SET_FRAME_GARBAGED (f
);
9787 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9788 event
.xexpose
.x
, event
.xexpose
.y
,
9789 event
.xexpose
.width
, event
.xexpose
.height
);
9790 frame_exposed_p
= 1;
9795 struct scroll_bar
*bar
9796 = x_window_to_scroll_bar (event
.xexpose
.window
);
9799 x_scroll_bar_expose (bar
, &event
);
9803 return frame_exposed_p
;
9806 /* Define a queue to save up SelectionRequest events for later handling. */
9808 struct selection_event_queue
9811 struct selection_event_queue
*next
;
9814 static struct selection_event_queue
*queue
;
9816 /* Nonzero means queue up certain events--don't process them yet. */
9818 static int x_queue_selection_requests
;
9820 /* Queue up an X event *EVENT, to be processed later. */
9823 x_queue_event (f
, event
)
9827 struct selection_event_queue
*queue_tmp
9828 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9830 if (queue_tmp
!= NULL
)
9832 queue_tmp
->event
= *event
;
9833 queue_tmp
->next
= queue
;
9838 /* Take all the queued events and put them back
9839 so that they get processed afresh. */
9842 x_unqueue_events (display
)
9845 while (queue
!= NULL
)
9847 struct selection_event_queue
*queue_tmp
= queue
;
9848 XPutBackEvent (display
, &queue_tmp
->event
);
9849 queue
= queue_tmp
->next
;
9850 xfree ((char *)queue_tmp
);
9854 /* Start queuing SelectionRequest events. */
9857 x_start_queuing_selection_requests (display
)
9860 x_queue_selection_requests
++;
9863 /* Stop queuing SelectionRequest events. */
9866 x_stop_queuing_selection_requests (display
)
9869 x_queue_selection_requests
--;
9870 x_unqueue_events (display
);
9873 /* The main X event-reading loop - XTread_socket. */
9876 /* Time stamp of enter window event. This is only used by XTread_socket,
9877 but we have to put it out here, since static variables within functions
9878 sometimes don't work. */
9880 static Time enter_timestamp
;
9883 /* This holds the state XLookupString needs to implement dead keys
9884 and other tricks known as "compose processing". _X Window System_
9885 says that a portable program can't use this, but Stephen Gildea assures
9886 me that letting the compiler initialize it to zeros will work okay.
9888 This must be defined outside of XTread_socket, for the same reasons
9889 given for enter_timestamp, above. */
9891 static XComposeStatus compose_status
;
9893 /* Record the last 100 characters stored
9894 to help debug the loss-of-chars-during-GC problem. */
9896 static int temp_index
;
9897 static short temp_buffer
[100];
9899 /* Set this to nonzero to fake an "X I/O error"
9900 on a particular display. */
9902 struct x_display_info
*XTread_socket_fake_io_error
;
9904 /* When we find no input here, we occasionally do a no-op command
9905 to verify that the X server is still running and we can still talk with it.
9906 We try all the open displays, one by one.
9907 This variable is used for cycling thru the displays. */
9909 static struct x_display_info
*next_noop_dpyinfo
;
9911 #define SET_SAVED_MENU_EVENT(size) \
9914 if (f->output_data.x->saved_menu_event == 0) \
9915 f->output_data.x->saved_menu_event \
9916 = (XEvent *) xmalloc (sizeof (XEvent)); \
9917 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9918 if (numchars >= 1) \
9920 bufp->kind = menu_bar_activate_event; \
9921 XSETFRAME (bufp->frame_or_window, f); \
9930 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9931 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9933 /* Read events coming from the X server.
9934 This routine is called by the SIGIO handler.
9935 We return as soon as there are no more events to be read.
9937 Events representing keys are stored in buffer BUFP,
9938 which can hold up to NUMCHARS characters.
9939 We return the number of characters stored into the buffer,
9940 thus pretending to be `read'.
9942 EXPECTED is nonzero if the caller knows input is available. */
9945 XTread_socket (sd
, bufp
, numchars
, expected
)
9947 /* register */ struct input_event
*bufp
;
9948 /* register */ int numchars
;
9955 int event_found
= 0;
9956 struct x_display_info
*dpyinfo
;
9957 struct coding_system coding
;
9959 if (interrupt_input_blocked
)
9961 interrupt_input_pending
= 1;
9965 interrupt_input_pending
= 0;
9968 /* So people can tell when we have read the available input. */
9969 input_signal_count
++;
9972 abort (); /* Don't think this happens. */
9976 /* The input should be decoded if it is from XIM. Currently the
9977 locale of XIM is the same as that of the system. So, we can use
9978 Vlocale_coding_system which is initialized properly at Emacs
9980 setup_coding_system (Vlocale_coding_system
, &coding
);
9981 coding
.src_multibyte
= 0;
9982 coding
.dst_multibyte
= 1;
9983 /* The input is converted to events, thus we can't handle
9984 composition. Anyway, there's no XIM that gives us composition
9986 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
9988 /* Find the display we are supposed to read input for.
9989 It's the one communicating on descriptor SD. */
9990 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9992 #if 0 /* This ought to be unnecessary; let's verify it. */
9994 /* If available, Xlib uses FIOSNBIO to make the socket
9995 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9996 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9997 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9998 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9999 #endif /* ! defined (FIOSNBIO) */
10002 #if 0 /* This code can't be made to work, with multiple displays,
10003 and appears not to be used on any system any more.
10004 Also keyboard.c doesn't turn O_NDELAY on and off
10005 for X connections. */
10007 #ifndef HAVE_SELECT
10008 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
10010 extern int read_alarm_should_throw
;
10011 read_alarm_should_throw
= 1;
10012 XPeekEvent (dpyinfo
->display
, &event
);
10013 read_alarm_should_throw
= 0;
10015 #endif /* HAVE_SELECT */
10019 /* For debugging, this gives a way to fake an I/O error. */
10020 if (dpyinfo
== XTread_socket_fake_io_error
)
10022 XTread_socket_fake_io_error
= 0;
10023 x_io_error_quitter (dpyinfo
->display
);
10026 while (XPending (dpyinfo
->display
))
10028 XNextEvent (dpyinfo
->display
, &event
);
10032 /* Filter events for the current X input method.
10033 XFilterEvent returns non-zero if the input method has
10034 consumed the event. We pass the frame's X window to
10035 XFilterEvent because that's the one for which the IC
10037 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
10038 event
.xclient
.window
);
10039 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
10045 switch (event
.type
)
10047 case ClientMessage
:
10049 if (event
.xclient
.message_type
10050 == dpyinfo
->Xatom_wm_protocols
10051 && event
.xclient
.format
== 32)
10053 if (event
.xclient
.data
.l
[0]
10054 == dpyinfo
->Xatom_wm_take_focus
)
10056 /* Use x_any_window_to_frame because this
10057 could be the shell widget window
10058 if the frame has no title bar. */
10059 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10061 /* Not quite sure this is needed -pd */
10062 if (f
&& FRAME_XIC (f
))
10063 XSetICFocus (FRAME_XIC (f
));
10065 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
10066 instructs the WM to set the input focus automatically for
10067 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
10068 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
10069 it has set the focus. So, XSetInputFocus below is not
10072 The call to XSetInputFocus below has also caused trouble. In
10073 cases where the XSetInputFocus done by the WM and the one
10074 below are temporally close (on a fast machine), the call
10075 below can generate additional FocusIn events which confuse
10078 /* Since we set WM_TAKE_FOCUS, we must call
10079 XSetInputFocus explicitly. But not if f is null,
10080 since that might be an event for a deleted frame. */
10083 Display
*d
= event
.xclient
.display
;
10084 /* Catch and ignore errors, in case window has been
10085 iconified by a window manager such as GWM. */
10086 int count
= x_catch_errors (d
);
10087 XSetInputFocus (d
, event
.xclient
.window
,
10088 /* The ICCCM says this is
10089 the only valid choice. */
10091 event
.xclient
.data
.l
[1]);
10092 /* This is needed to detect the error
10093 if there is an error. */
10095 x_uncatch_errors (d
, count
);
10097 /* Not certain about handling scroll bars here */
10100 else if (event
.xclient
.data
.l
[0]
10101 == dpyinfo
->Xatom_wm_save_yourself
)
10103 /* Save state modify the WM_COMMAND property to
10104 something which can reinstate us. This notifies
10105 the session manager, who's looking for such a
10106 PropertyNotify. Can restart processing when
10107 a keyboard or mouse event arrives. */
10110 f
= x_top_window_to_frame (dpyinfo
,
10111 event
.xclient
.window
);
10113 /* This is just so we only give real data once
10114 for a single Emacs process. */
10115 if (f
== SELECTED_FRAME ())
10116 XSetCommand (FRAME_X_DISPLAY (f
),
10117 event
.xclient
.window
,
10118 initial_argv
, initial_argc
);
10120 XSetCommand (FRAME_X_DISPLAY (f
),
10121 event
.xclient
.window
,
10125 else if (event
.xclient
.data
.l
[0]
10126 == dpyinfo
->Xatom_wm_delete_window
)
10129 = x_any_window_to_frame (dpyinfo
,
10130 event
.xclient
.window
);
10137 bufp
->kind
= delete_window_event
;
10138 XSETFRAME (bufp
->frame_or_window
, f
);
10147 else if (event
.xclient
.message_type
10148 == dpyinfo
->Xatom_wm_configure_denied
)
10151 else if (event
.xclient
.message_type
10152 == dpyinfo
->Xatom_wm_window_moved
)
10156 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10158 new_x
= event
.xclient
.data
.s
[0];
10159 new_y
= event
.xclient
.data
.s
[1];
10163 f
->output_data
.x
->left_pos
= new_x
;
10164 f
->output_data
.x
->top_pos
= new_y
;
10167 #ifdef HACK_EDITRES
10168 else if (event
.xclient
.message_type
10169 == dpyinfo
->Xatom_editres
)
10172 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10173 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
10176 #endif /* HACK_EDITRES */
10177 else if ((event
.xclient
.message_type
10178 == dpyinfo
->Xatom_DONE
)
10179 || (event
.xclient
.message_type
10180 == dpyinfo
->Xatom_PAGE
))
10182 /* Ghostview job completed. Kill it. We could
10183 reply with "Next" if we received "Page", but we
10184 currently never do because we are interested in
10185 images, only, which should have 1 page. */
10186 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
10188 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10189 x_kill_gs_process (pixmap
, f
);
10190 expose_frame (f
, 0, 0, 0, 0);
10192 #ifdef USE_TOOLKIT_SCROLL_BARS
10193 /* Scroll bar callbacks send a ClientMessage from which
10194 we construct an input_event. */
10195 else if (event
.xclient
.message_type
10196 == dpyinfo
->Xatom_Scrollbar
)
10198 x_scroll_bar_to_input_event (&event
, bufp
);
10199 ++bufp
, ++count
, --numchars
;
10202 #endif /* USE_TOOLKIT_SCROLL_BARS */
10208 case SelectionNotify
:
10209 #ifdef USE_X_TOOLKIT
10210 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
10212 #endif /* not USE_X_TOOLKIT */
10213 x_handle_selection_notify (&event
.xselection
);
10216 case SelectionClear
: /* Someone has grabbed ownership. */
10217 #ifdef USE_X_TOOLKIT
10218 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
10220 #endif /* USE_X_TOOLKIT */
10222 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
10227 bufp
->kind
= selection_clear_event
;
10228 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10229 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10230 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10231 bufp
->frame_or_window
= Qnil
;
10240 case SelectionRequest
: /* Someone wants our selection. */
10241 #ifdef USE_X_TOOLKIT
10242 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
10244 #endif /* USE_X_TOOLKIT */
10245 if (x_queue_selection_requests
)
10246 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
10250 XSelectionRequestEvent
*eventp
10251 = (XSelectionRequestEvent
*) &event
;
10256 bufp
->kind
= selection_request_event
;
10257 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10258 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
10259 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10260 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
10261 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
10262 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10263 bufp
->frame_or_window
= Qnil
;
10272 case PropertyNotify
:
10273 #if 0 /* This is plain wrong. In the case that we are waiting for a
10274 PropertyNotify used as an ACK in incremental selection
10275 transfer, the property will be on the receiver's window. */
10276 #if defined USE_X_TOOLKIT
10277 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10281 x_handle_property_notify (&event
.xproperty
);
10284 case ReparentNotify
:
10285 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10289 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10290 x_real_positions (f
, &x
, &y
);
10291 f
->output_data
.x
->left_pos
= x
;
10292 f
->output_data
.x
->top_pos
= y
;
10297 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10300 x_check_fullscreen (f
);
10302 if (f
->async_visible
== 0)
10304 f
->async_visible
= 1;
10305 f
->async_iconified
= 0;
10306 f
->output_data
.x
->has_been_visible
= 1;
10307 SET_FRAME_GARBAGED (f
);
10310 expose_frame (x_window_to_frame (dpyinfo
,
10311 event
.xexpose
.window
),
10312 event
.xexpose
.x
, event
.xexpose
.y
,
10313 event
.xexpose
.width
, event
.xexpose
.height
);
10317 #ifndef USE_TOOLKIT_SCROLL_BARS
10318 struct scroll_bar
*bar
;
10320 #if defined USE_LUCID
10321 /* Submenus of the Lucid menu bar aren't widgets
10322 themselves, so there's no way to dispatch events
10323 to them. Recognize this case separately. */
10326 = x_window_to_menu_bar (event
.xexpose
.window
);
10328 xlwmenu_redisplay (widget
);
10330 #endif /* USE_LUCID */
10332 #ifdef USE_TOOLKIT_SCROLL_BARS
10333 /* Dispatch event to the widget. */
10335 #else /* not USE_TOOLKIT_SCROLL_BARS */
10336 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10339 x_scroll_bar_expose (bar
, &event
);
10340 #ifdef USE_X_TOOLKIT
10343 #endif /* USE_X_TOOLKIT */
10344 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10348 case GraphicsExpose
: /* This occurs when an XCopyArea's
10349 source area was obscured or not
10351 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10355 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10356 event
.xgraphicsexpose
.width
,
10357 event
.xgraphicsexpose
.height
);
10359 #ifdef USE_X_TOOLKIT
10362 #endif /* USE_X_TOOLKIT */
10365 case NoExpose
: /* This occurs when an XCopyArea's
10366 source area was completely
10371 /* Redo the mouse-highlight after the tooltip has gone. */
10372 if (event
.xmap
.window
== tip_window
)
10375 redo_mouse_highlight ();
10378 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10379 if (f
) /* F may no longer exist if
10380 the frame was deleted. */
10382 /* While a frame is unmapped, display generation is
10383 disabled; you don't want to spend time updating a
10384 display that won't ever be seen. */
10385 f
->async_visible
= 0;
10386 /* We can't distinguish, from the event, whether the window
10387 has become iconified or invisible. So assume, if it
10388 was previously visible, than now it is iconified.
10389 But x_make_frame_invisible clears both
10390 the visible flag and the iconified flag;
10391 and that way, we know the window is not iconified now. */
10392 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10394 f
->async_iconified
= 1;
10396 bufp
->kind
= iconify_event
;
10397 XSETFRAME (bufp
->frame_or_window
, f
);
10407 if (event
.xmap
.window
== tip_window
)
10408 /* The tooltip has been drawn already. Avoid
10409 the SET_FRAME_GARBAGED below. */
10412 /* We use x_top_window_to_frame because map events can
10413 come for sub-windows and they don't mean that the
10414 frame is visible. */
10415 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10418 f
->async_visible
= 1;
10419 f
->async_iconified
= 0;
10420 f
->output_data
.x
->has_been_visible
= 1;
10422 /* wait_reading_process_input will notice this and update
10423 the frame's display structures. */
10424 SET_FRAME_GARBAGED (f
);
10428 bufp
->kind
= deiconify_event
;
10429 XSETFRAME (bufp
->frame_or_window
, f
);
10435 else if (! NILP (Vframe_list
)
10436 && ! NILP (XCDR (Vframe_list
)))
10437 /* Force a redisplay sooner or later
10438 to update the frame titles
10439 in case this is the second frame. */
10440 record_asynch_buffer_change ();
10445 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10447 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
10449 dpyinfo
->mouse_face_hidden
= 1;
10450 clear_mouse_face (dpyinfo
);
10453 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10456 /* Scroll bars consume key events, but we want
10457 the keys to go to the scroll bar's frame. */
10458 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10459 event
.xkey
.window
);
10460 if (widget
&& XmIsScrollBar (widget
))
10462 widget
= XtParent (widget
);
10463 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10466 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10470 KeySym keysym
, orig_keysym
;
10471 /* al%imercury@uunet.uu.net says that making this 81
10472 instead of 80 fixed a bug whereby meta chars made
10475 It seems that some version of XmbLookupString has
10476 a bug of not returning XBufferOverflow in
10477 status_return even if the input is too long to
10478 fit in 81 bytes. So, we must prepare sufficient
10479 bytes for copy_buffer. 513 bytes (256 chars for
10480 two-byte character set) seems to be a fairly good
10481 approximation. -- 2000.8.10 handa@etl.go.jp */
10482 unsigned char copy_buffer
[513];
10483 unsigned char *copy_bufptr
= copy_buffer
;
10484 int copy_bufsiz
= sizeof (copy_buffer
);
10488 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10489 extra_keyboard_modifiers
);
10490 modifiers
= event
.xkey
.state
;
10492 /* This will have to go some day... */
10494 /* make_lispy_event turns chars into control chars.
10495 Don't do it here because XLookupString is too eager. */
10496 event
.xkey
.state
&= ~ControlMask
;
10497 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10498 | dpyinfo
->super_mod_mask
10499 | dpyinfo
->hyper_mod_mask
10500 | dpyinfo
->alt_mod_mask
);
10502 /* In case Meta is ComposeCharacter,
10503 clear its status. According to Markus Ehrnsperger
10504 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10505 this enables ComposeCharacter to work whether or
10506 not it is combined with Meta. */
10507 if (modifiers
& dpyinfo
->meta_mod_mask
)
10508 bzero (&compose_status
, sizeof (compose_status
));
10513 Status status_return
;
10515 nbytes
= XmbLookupString (FRAME_XIC (f
),
10516 &event
.xkey
, copy_bufptr
,
10517 copy_bufsiz
, &keysym
,
10519 if (status_return
== XBufferOverflow
)
10521 copy_bufsiz
= nbytes
+ 1;
10522 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10523 nbytes
= XmbLookupString (FRAME_XIC (f
),
10524 &event
.xkey
, copy_bufptr
,
10525 copy_bufsiz
, &keysym
,
10529 if (status_return
== XLookupNone
)
10531 else if (status_return
== XLookupChars
)
10536 else if (status_return
!= XLookupKeySym
10537 && status_return
!= XLookupBoth
)
10541 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10542 copy_bufsiz
, &keysym
,
10545 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10546 copy_bufsiz
, &keysym
,
10550 orig_keysym
= keysym
;
10556 /* First deal with keysyms which have defined
10557 translations to characters. */
10558 if (keysym
>= 32 && keysym
< 128)
10559 /* Avoid explicitly decoding each ASCII character. */
10561 bufp
->kind
= ascii_keystroke
;
10562 bufp
->code
= keysym
;
10563 XSETFRAME (bufp
->frame_or_window
, f
);
10566 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10568 bufp
->timestamp
= event
.xkey
.time
;
10573 /* Now non-ASCII. */
10574 else if (HASH_TABLE_P (Vx_keysym_table
)
10575 && (CHARACTERP (c
= Fgethash (make_number (keysym
),
10579 bufp
->kind
= (ASCII_CHAR_P (XFASTINT (c
))
10581 : multibyte_char_keystroke
);
10582 bufp
->code
= XFASTINT (c
);
10583 XSETFRAME (bufp
->frame_or_window
, f
);
10586 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10588 bufp
->timestamp
= event
.xkey
.time
;
10593 else if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10594 || keysym
== XK_Delete
10595 #ifdef XK_ISO_Left_Tab
10596 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10598 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10599 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10600 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10602 /* This recognizes the "extended function
10603 keys". It seems there's no cleaner way.
10604 Test IsModifierKey to avoid handling
10605 mode_switch incorrectly. */
10606 || ((unsigned) (keysym
) >= XK_Select
10607 && (unsigned)(keysym
) < XK_KP_Space
)
10609 #ifdef XK_dead_circumflex
10610 || orig_keysym
== XK_dead_circumflex
10612 #ifdef XK_dead_grave
10613 || orig_keysym
== XK_dead_grave
10615 #ifdef XK_dead_tilde
10616 || orig_keysym
== XK_dead_tilde
10618 #ifdef XK_dead_diaeresis
10619 || orig_keysym
== XK_dead_diaeresis
10621 #ifdef XK_dead_macron
10622 || orig_keysym
== XK_dead_macron
10624 #ifdef XK_dead_degree
10625 || orig_keysym
== XK_dead_degree
10627 #ifdef XK_dead_acute
10628 || orig_keysym
== XK_dead_acute
10630 #ifdef XK_dead_cedilla
10631 || orig_keysym
== XK_dead_cedilla
10633 #ifdef XK_dead_breve
10634 || orig_keysym
== XK_dead_breve
10636 #ifdef XK_dead_ogonek
10637 || orig_keysym
== XK_dead_ogonek
10639 #ifdef XK_dead_caron
10640 || orig_keysym
== XK_dead_caron
10642 #ifdef XK_dead_doubleacute
10643 || orig_keysym
== XK_dead_doubleacute
10645 #ifdef XK_dead_abovedot
10646 || orig_keysym
== XK_dead_abovedot
10648 #ifdef XK_dead_abovering
10649 || orig_keysym
== XK_dead_abovering
10651 #ifdef XK_dead_iota
10652 || orig_keysym
== XK_dead_iota
10654 #ifdef XK_dead_belowdot
10655 || orig_keysym
== XK_dead_belowdot
10657 #ifdef XK_dead_voiced_sound
10658 || orig_keysym
== XK_dead_voiced_sound
10660 #ifdef XK_dead_semivoiced_sound
10661 || orig_keysym
== XK_dead_semivoiced_sound
10663 #ifdef XK_dead_hook
10664 || orig_keysym
== XK_dead_hook
10666 #ifdef XK_dead_horn
10667 || orig_keysym
== XK_dead_horn
10669 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10670 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10671 /* Any "vendor-specific" key is ok. */
10672 || (orig_keysym
& (1 << 28))
10673 || (keysym
!= NoSymbol
&& nbytes
== 0))
10674 && ! (IsModifierKey (orig_keysym
)
10676 #ifdef XK_Mode_switch
10677 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10680 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10682 #endif /* not HAVE_X11R5 */
10683 /* The symbols from XK_ISO_Lock to
10684 XK_ISO_Last_Group_Lock doesn't have
10685 real modifiers but should be treated
10686 similarly to Mode_switch by Emacs. */
10687 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
10688 || ((unsigned)(orig_keysym
) >= XK_ISO_Lock
10689 && (unsigned)(orig_keysym
) <= XK_ISO_Last_Group_Lock
)
10693 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10695 temp_buffer
[temp_index
++] = keysym
;
10696 /* make_lispy_event will convert this to a symbolic
10698 bufp
->kind
= non_ascii_keystroke
;
10699 bufp
->code
= keysym
;
10700 XSETFRAME (bufp
->frame_or_window
, f
);
10703 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10705 bufp
->timestamp
= event
.xkey
.time
;
10710 else if (numchars
> nbytes
)
10711 { /* Raw characters, not keysym. */
10716 for (i
= 0; i
< nbytes
; i
++)
10718 if (temp_index
== (sizeof temp_buffer
10721 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10725 /* Decode the input data. */
10727 = (unsigned char *) malloc (nbytes
);
10728 if (! coding
.destination
)
10730 coding
.dst_bytes
= nbytes
;
10731 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10732 decode_coding_c_string (&coding
, copy_bufptr
,
10734 nbytes
= coding
.produced
;
10735 nchars
= coding
.produced_char
;
10736 if (copy_bufsiz
< nbytes
)
10738 copy_bufsiz
= nbytes
;
10739 copy_bufptr
= (char *) alloca (nbytes
);
10741 bcopy (coding
.destination
, copy_bufptr
, nbytes
);
10742 free (coding
.destination
);
10745 /* Convert the input data to a sequence of
10746 character events. */
10747 for (i
= 0; i
< nbytes
; i
+= len
)
10749 if (nchars
== nbytes
)
10750 c
= copy_bufptr
[i
], len
= 1;
10752 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10755 bufp
->kind
= (ASCII_CHAR_P (c
)
10757 : multibyte_char_keystroke
);
10759 XSETFRAME (bufp
->frame_or_window
, f
);
10762 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10764 bufp
->timestamp
= event
.xkey
.time
;
10769 numchars
-= nchars
;
10771 if (keysym
== NoSymbol
)
10781 /* Don't dispatch this event since XtDispatchEvent calls
10782 XFilterEvent, and two calls in a row may freeze the
10791 /* Don't dispatch this event since XtDispatchEvent calls
10792 XFilterEvent, and two calls in a row may freeze the
10799 /* Here's a possible interpretation of the whole
10800 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10801 you get a FocusIn event, you have to get a FocusOut
10802 event before you relinquish the focus. If you
10803 haven't received a FocusIn event, then a mere
10804 LeaveNotify is enough to free you. */
10808 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10811 if (event
.xcrossing
.focus
)
10813 /* Avoid nasty pop/raise loops. */
10814 if (f
&& (!(f
->auto_raise
)
10815 || !(f
->auto_lower
)
10816 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10818 x_new_focus_frame (dpyinfo
, f
);
10819 enter_timestamp
= event
.xcrossing
.time
;
10822 else if (f
== dpyinfo
->x_focus_frame
)
10823 x_new_focus_frame (dpyinfo
, 0);
10826 /* EnterNotify counts as mouse movement,
10827 so update things that depend on mouse position. */
10828 if (f
&& !f
->output_data
.x
->hourglass_p
)
10829 note_mouse_movement (f
, &event
.xmotion
);
10834 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10835 if (event
.xfocus
.detail
!= NotifyPointer
)
10836 dpyinfo
->x_focus_event_frame
= f
;
10839 x_new_focus_frame (dpyinfo
, f
);
10841 /* Don't stop displaying the initial startup message
10842 for a switch-frame event we don't need. */
10843 if (GC_NILP (Vterminal_frame
)
10844 && GC_CONSP (Vframe_list
)
10845 && !GC_NILP (XCDR (Vframe_list
)))
10847 bufp
->kind
= FOCUS_IN_EVENT
;
10848 XSETFRAME (bufp
->frame_or_window
, f
);
10850 ++bufp
, ++count
, --numchars
;
10855 if (f
&& FRAME_XIC (f
))
10856 XSetICFocus (FRAME_XIC (f
));
10862 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10865 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10867 /* If we move outside the frame, then we're
10868 certainly no longer on any text in the frame. */
10869 clear_mouse_face (dpyinfo
);
10870 dpyinfo
->mouse_face_mouse_frame
= 0;
10873 /* Generate a nil HELP_EVENT to cancel a help-echo.
10874 Do it only if there's something to cancel.
10875 Otherwise, the startup message is cleared when
10876 the mouse leaves the frame. */
10877 if (any_help_event_p
)
10882 XSETFRAME (frame
, f
);
10884 n
= gen_help_event (bufp
, numchars
,
10885 Qnil
, frame
, Qnil
, Qnil
, 0);
10886 bufp
+= n
, count
+= n
, numchars
-= n
;
10890 if (event
.xcrossing
.focus
)
10891 x_mouse_leave (dpyinfo
);
10894 if (f
== dpyinfo
->x_focus_event_frame
)
10895 dpyinfo
->x_focus_event_frame
= 0;
10896 if (f
== dpyinfo
->x_focus_frame
)
10897 x_new_focus_frame (dpyinfo
, 0);
10904 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10905 if (event
.xfocus
.detail
!= NotifyPointer
10906 && f
== dpyinfo
->x_focus_event_frame
)
10907 dpyinfo
->x_focus_event_frame
= 0;
10908 if (f
&& f
== dpyinfo
->x_focus_frame
)
10909 x_new_focus_frame (dpyinfo
, 0);
10912 if (f
&& FRAME_XIC (f
))
10913 XUnsetICFocus (FRAME_XIC (f
));
10920 previous_help_echo
= help_echo
;
10921 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10922 help_echo_pos
= -1;
10924 if (dpyinfo
->grabbed
&& last_mouse_frame
10925 && FRAME_LIVE_P (last_mouse_frame
))
10926 f
= last_mouse_frame
;
10928 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10930 if (dpyinfo
->mouse_face_hidden
)
10932 dpyinfo
->mouse_face_hidden
= 0;
10933 clear_mouse_face (dpyinfo
);
10937 note_mouse_movement (f
, &event
.xmotion
);
10940 #ifndef USE_TOOLKIT_SCROLL_BARS
10941 struct scroll_bar
*bar
10942 = x_window_to_scroll_bar (event
.xmotion
.window
);
10945 x_scroll_bar_note_movement (bar
, &event
);
10946 #endif /* USE_TOOLKIT_SCROLL_BARS */
10948 /* If we move outside the frame, then we're
10949 certainly no longer on any text in the frame. */
10950 clear_mouse_face (dpyinfo
);
10953 /* If the contents of the global variable help_echo
10954 has changed, generate a HELP_EVENT. */
10955 if (!NILP (help_echo
)
10956 || !NILP (previous_help_echo
))
10962 XSETFRAME (frame
, f
);
10966 any_help_event_p
= 1;
10967 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10968 help_echo_window
, help_echo_object
,
10970 bufp
+= n
, count
+= n
, numchars
-= n
;
10976 case ConfigureNotify
:
10977 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10980 #ifndef USE_X_TOOLKIT
10981 /* If there is a pending resize for fullscreen, don't
10982 do this one, the right one will come later.
10983 The toolkit version doesn't seem to need this, but we
10984 need to reset it below. */
10986 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
10987 && FRAME_NEW_WIDTH (f
) != 0);
10988 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10989 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10993 /* In the toolkit version, change_frame_size
10994 is called by the code that handles resizing
10995 of the EmacsFrame widget. */
10997 /* Even if the number of character rows and columns has
10998 not changed, the font size may have changed, so we need
10999 to check the pixel dimensions as well. */
11000 if (columns
!= f
->width
11001 || rows
!= f
->height
11002 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
11003 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
11005 change_frame_size (f
, rows
, columns
, 0, 1, 0);
11006 SET_FRAME_GARBAGED (f
);
11007 cancel_mouse_face (f
);
11011 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
11012 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
11014 /* What we have now is the position of Emacs's own window.
11015 Convert that to the position of the window manager window. */
11016 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
11017 &f
->output_data
.x
->top_pos
);
11019 x_check_fullscreen_move(f
);
11020 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
11021 f
->output_data
.x
->want_fullscreen
&=
11022 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
11024 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
11025 xic_set_statusarea (f
);
11028 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11030 /* Since the WM decorations come below top_pos now,
11031 we must put them below top_pos in the future. */
11032 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11033 x_wm_set_size_hint (f
, (long) 0, 0);
11036 /* Some window managers pass (0,0) as the location of
11037 the window, and the Motif event handler stores it
11038 in the emacs widget, which messes up Motif menus. */
11039 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
11041 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
11042 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
11044 #endif /* USE_MOTIF */
11049 case ButtonRelease
:
11051 /* If we decide we want to generate an event to be seen
11052 by the rest of Emacs, we put it here. */
11053 struct input_event emacs_event
;
11054 int tool_bar_p
= 0;
11056 emacs_event
.kind
= no_event
;
11057 bzero (&compose_status
, sizeof (compose_status
));
11059 if (dpyinfo
->grabbed
11060 && last_mouse_frame
11061 && FRAME_LIVE_P (last_mouse_frame
))
11062 f
= last_mouse_frame
;
11064 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11068 /* Is this in the tool-bar? */
11069 if (WINDOWP (f
->tool_bar_window
)
11070 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
11072 Lisp_Object window
;
11075 x
= event
.xbutton
.x
;
11076 y
= event
.xbutton
.y
;
11079 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
11080 if (EQ (window
, f
->tool_bar_window
))
11082 x_handle_tool_bar_click (f
, &event
.xbutton
);
11088 if (!dpyinfo
->x_focus_frame
11089 || f
== dpyinfo
->x_focus_frame
)
11090 construct_mouse_click (&emacs_event
, &event
, f
);
11094 #ifndef USE_TOOLKIT_SCROLL_BARS
11095 struct scroll_bar
*bar
11096 = x_window_to_scroll_bar (event
.xbutton
.window
);
11099 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
11100 #endif /* not USE_TOOLKIT_SCROLL_BARS */
11103 if (event
.type
== ButtonPress
)
11105 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
11106 last_mouse_frame
= f
;
11107 /* Ignore any mouse motion that happened
11108 before this event; any subsequent mouse-movement
11109 Emacs events should reflect only motion after
11110 the ButtonPress. */
11112 f
->mouse_moved
= 0;
11115 last_tool_bar_item
= -1;
11119 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
11122 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
11124 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
11130 #ifdef USE_X_TOOLKIT
11131 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11132 /* For a down-event in the menu bar,
11133 don't pass it to Xt right now.
11134 Instead, save it away
11135 and we will pass it to Xt from kbd_buffer_get_event.
11136 That way, we can run some Lisp code first. */
11137 if (f
&& event
.type
== ButtonPress
11138 /* Verify the event is really within the menu bar
11139 and not just sent to it due to grabbing. */
11140 && event
.xbutton
.x
>= 0
11141 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
11142 && event
.xbutton
.y
>= 0
11143 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
11144 && event
.xbutton
.same_screen
)
11146 SET_SAVED_BUTTON_EVENT
;
11147 XSETFRAME (last_mouse_press_frame
, f
);
11149 else if (event
.type
== ButtonPress
)
11151 last_mouse_press_frame
= Qnil
;
11155 #ifdef USE_MOTIF /* This should do not harm for Lucid,
11156 but I am trying to be cautious. */
11157 else if (event
.type
== ButtonRelease
)
11159 if (!NILP (last_mouse_press_frame
))
11161 f
= XFRAME (last_mouse_press_frame
);
11162 if (f
->output_data
.x
)
11163 SET_SAVED_BUTTON_EVENT
;
11168 #endif /* USE_MOTIF */
11171 #endif /* USE_X_TOOLKIT */
11175 case CirculateNotify
:
11178 case CirculateRequest
:
11181 case VisibilityNotify
:
11184 case MappingNotify
:
11185 /* Someone has changed the keyboard mapping - update the
11187 switch (event
.xmapping
.request
)
11189 case MappingModifier
:
11190 x_find_modifier_meanings (dpyinfo
);
11191 /* This is meant to fall through. */
11192 case MappingKeyboard
:
11193 XRefreshKeyboardMapping (&event
.xmapping
);
11199 #ifdef USE_X_TOOLKIT
11201 XtDispatchEvent (&event
);
11203 #endif /* USE_X_TOOLKIT */
11211 /* On some systems, an X bug causes Emacs to get no more events
11212 when the window is destroyed. Detect that. (1994.) */
11215 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
11216 One XNOOP in 100 loops will make Emacs terminate.
11217 B. Bretthauer, 1994 */
11219 if (x_noop_count
>= 100)
11223 if (next_noop_dpyinfo
== 0)
11224 next_noop_dpyinfo
= x_display_list
;
11226 XNoOp (next_noop_dpyinfo
->display
);
11228 /* Each time we get here, cycle through the displays now open. */
11229 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
11233 /* If the focus was just given to an auto-raising frame,
11235 /* ??? This ought to be able to handle more than one such frame. */
11236 if (pending_autoraise_frame
)
11238 x_raise_frame (pending_autoraise_frame
);
11239 pending_autoraise_frame
= 0;
11250 /***********************************************************************
11252 ***********************************************************************/
11254 /* Notice when the text cursor of window W has been completely
11255 overwritten by a drawing operation that outputs glyphs in AREA
11256 starting at X0 and ending at X1 in the line starting at Y0 and
11257 ending at Y1. X coordinates are area-relative. X1 < 0 means all
11258 the rest of the line after X0 has been written. Y coordinates
11259 are window-relative. */
11262 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
11264 enum glyph_row_area area
;
11265 int x0
, y0
, x1
, y1
;
11267 if (area
== TEXT_AREA
11268 && w
->phys_cursor_on_p
11269 && y0
<= w
->phys_cursor
.y
11270 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
11271 && x0
<= w
->phys_cursor
.x
11272 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
11273 w
->phys_cursor_on_p
= 0;
11277 /* Set clipping for output in glyph row ROW. W is the window in which
11278 we operate. GC is the graphics context to set clipping in.
11279 WHOLE_LINE_P non-zero means include the areas used for truncation
11280 mark display and alike in the clipping rectangle.
11282 ROW may be a text row or, e.g., a mode line. Text rows must be
11283 clipped to the interior of the window dedicated to text display,
11284 mode lines must be clipped to the whole window. */
11287 x_clip_to_row (w
, row
, gc
, whole_line_p
)
11289 struct glyph_row
*row
;
11293 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11294 XRectangle clip_rect
;
11295 int window_x
, window_y
, window_width
, window_height
;
11297 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
11299 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
11300 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
11301 clip_rect
.y
= max (clip_rect
.y
, window_y
);
11302 clip_rect
.width
= window_width
;
11303 clip_rect
.height
= row
->visible_height
;
11305 /* If clipping to the whole line, including trunc marks, extend
11306 the rectangle to the left and increase its width. */
11309 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
11310 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
11313 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
11317 /* Draw a hollow box cursor on window W in glyph row ROW. */
11320 x_draw_hollow_cursor (w
, row
)
11322 struct glyph_row
*row
;
11324 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11325 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11326 Display
*dpy
= FRAME_X_DISPLAY (f
);
11329 struct glyph
*cursor_glyph
;
11332 /* Compute frame-relative coordinates from window-relative
11334 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11335 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
11336 + row
->ascent
- w
->phys_cursor_ascent
);
11337 h
= row
->height
- 1;
11339 /* Get the glyph the cursor is on. If we can't tell because
11340 the current matrix is invalid or such, give up. */
11341 cursor_glyph
= get_phys_cursor_glyph (w
);
11342 if (cursor_glyph
== NULL
)
11345 /* Compute the width of the rectangle to draw. If on a stretch
11346 glyph, and `x-stretch-block-cursor' is nil, don't draw a
11347 rectangle as wide as the glyph, but use a canonical character
11349 wd
= cursor_glyph
->pixel_width
- 1;
11350 if (cursor_glyph
->type
== STRETCH_GLYPH
11351 && !x_stretch_cursor_p
)
11352 wd
= min (CANON_X_UNIT (f
), wd
);
11354 /* The foreground of cursor_gc is typically the same as the normal
11355 background color, which can cause the cursor box to be invisible. */
11356 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11357 if (dpyinfo
->scratch_cursor_gc
)
11358 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11360 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11361 GCForeground
, &xgcv
);
11362 gc
= dpyinfo
->scratch_cursor_gc
;
11364 /* Set clipping, draw the rectangle, and reset clipping again. */
11365 x_clip_to_row (w
, row
, gc
, 0);
11366 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11367 XSetClipMask (dpy
, gc
, None
);
11371 /* Draw a bar cursor on window W in glyph row ROW.
11373 Implementation note: One would like to draw a bar cursor with an
11374 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11375 Unfortunately, I didn't find a font yet that has this property set.
11379 x_draw_bar_cursor (w
, row
, width
)
11381 struct glyph_row
*row
;
11384 struct frame
*f
= XFRAME (w
->frame
);
11385 struct glyph
*cursor_glyph
;
11387 /* If cursor is out of bounds, don't draw garbage. This can happen
11388 in mini-buffer windows when switching between echo area glyphs
11389 and mini-buffer. */
11390 cursor_glyph
= get_phys_cursor_glyph (w
);
11391 if (cursor_glyph
== NULL
)
11394 /* If on an image, draw like a normal cursor. That's usually better
11395 visible than drawing a bar, esp. if the image is large so that
11396 the bar might not be in the window. */
11397 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11399 struct glyph_row
*row
;
11400 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11401 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11405 Display
*dpy
= FRAME_X_DISPLAY (f
);
11406 Window window
= FRAME_X_WINDOW (f
);
11407 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11408 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11409 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
11412 /* If the glyph's background equals the color we normally draw
11413 the bar cursor in, the bar cursor in its normal color is
11414 invisible. Use the glyph's foreground color instead in this
11415 case, on the assumption that the glyph's colors are chosen so
11416 that the glyph is legible. */
11417 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
11418 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
11420 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11421 xgcv
.graphics_exposures
= 0;
11424 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11427 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11428 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11432 width
= f
->output_data
.x
->cursor_width
;
11433 width
= min (cursor_glyph
->pixel_width
, width
);
11435 x_clip_to_row (w
, row
, gc
, 0);
11436 XFillRectangle (dpy
, window
, gc
,
11437 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11438 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11439 width
, row
->height
);
11440 XSetClipMask (dpy
, gc
, None
);
11445 /* Clear the cursor of window W to background color, and mark the
11446 cursor as not shown. This is used when the text where the cursor
11447 is is about to be rewritten. */
11453 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11454 x_update_window_cursor (w
, 0);
11458 /* Draw the cursor glyph of window W in glyph row ROW. See the
11459 comment of x_draw_glyphs for the meaning of HL. */
11462 x_draw_phys_cursor_glyph (w
, row
, hl
)
11464 struct glyph_row
*row
;
11465 enum draw_glyphs_face hl
;
11467 /* If cursor hpos is out of bounds, don't draw garbage. This can
11468 happen in mini-buffer windows when switching between echo area
11469 glyphs and mini-buffer. */
11470 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11472 int on_p
= w
->phys_cursor_on_p
;
11474 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11475 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11477 w
->phys_cursor_on_p
= on_p
;
11479 /* When we erase the cursor, and ROW is overlapped by other
11480 rows, make sure that these overlapping parts of other rows
11482 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11484 if (row
> w
->current_matrix
->rows
11485 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11486 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11488 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11489 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11490 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11496 /* Erase the image of a cursor of window W from the screen. */
11499 x_erase_phys_cursor (w
)
11502 struct frame
*f
= XFRAME (w
->frame
);
11503 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11504 int hpos
= w
->phys_cursor
.hpos
;
11505 int vpos
= w
->phys_cursor
.vpos
;
11506 int mouse_face_here_p
= 0;
11507 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11508 struct glyph_row
*cursor_row
;
11509 struct glyph
*cursor_glyph
;
11510 enum draw_glyphs_face hl
;
11512 /* No cursor displayed or row invalidated => nothing to do on the
11514 if (w
->phys_cursor_type
== NO_CURSOR
)
11515 goto mark_cursor_off
;
11517 /* VPOS >= active_glyphs->nrows means that window has been resized.
11518 Don't bother to erase the cursor. */
11519 if (vpos
>= active_glyphs
->nrows
)
11520 goto mark_cursor_off
;
11522 /* If row containing cursor is marked invalid, there is nothing we
11524 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11525 if (!cursor_row
->enabled_p
)
11526 goto mark_cursor_off
;
11528 /* If row is completely invisible, don't attempt to delete a cursor which
11529 isn't there. This can happen if cursor is at top of a window, and
11530 we switch to a buffer with a header line in that window. */
11531 if (cursor_row
->visible_height
<= 0)
11532 goto mark_cursor_off
;
11534 /* This can happen when the new row is shorter than the old one.
11535 In this case, either x_draw_glyphs or clear_end_of_line
11536 should have cleared the cursor. Note that we wouldn't be
11537 able to erase the cursor in this case because we don't have a
11538 cursor glyph at hand. */
11539 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11540 goto mark_cursor_off
;
11542 /* If the cursor is in the mouse face area, redisplay that when
11543 we clear the cursor. */
11544 if (! NILP (dpyinfo
->mouse_face_window
)
11545 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11546 && (vpos
> dpyinfo
->mouse_face_beg_row
11547 || (vpos
== dpyinfo
->mouse_face_beg_row
11548 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11549 && (vpos
< dpyinfo
->mouse_face_end_row
11550 || (vpos
== dpyinfo
->mouse_face_end_row
11551 && hpos
< dpyinfo
->mouse_face_end_col
))
11552 /* Don't redraw the cursor's spot in mouse face if it is at the
11553 end of a line (on a newline). The cursor appears there, but
11554 mouse highlighting does not. */
11555 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11556 mouse_face_here_p
= 1;
11558 /* Maybe clear the display under the cursor. */
11559 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11562 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11564 cursor_glyph
= get_phys_cursor_glyph (w
);
11565 if (cursor_glyph
== NULL
)
11566 goto mark_cursor_off
;
11568 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11570 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11572 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11574 cursor_glyph
->pixel_width
,
11575 cursor_row
->visible_height
,
11579 /* Erase the cursor by redrawing the character underneath it. */
11580 if (mouse_face_here_p
)
11581 hl
= DRAW_MOUSE_FACE
;
11583 hl
= DRAW_NORMAL_TEXT
;
11584 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11587 w
->phys_cursor_on_p
= 0;
11588 w
->phys_cursor_type
= NO_CURSOR
;
11592 /* Non-zero if physical cursor of window W is within mouse face. */
11595 cursor_in_mouse_face_p (w
)
11598 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
11599 int in_mouse_face
= 0;
11601 if (WINDOWP (dpyinfo
->mouse_face_window
)
11602 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
11604 int hpos
= w
->phys_cursor
.hpos
;
11605 int vpos
= w
->phys_cursor
.vpos
;
11607 if (vpos
>= dpyinfo
->mouse_face_beg_row
11608 && vpos
<= dpyinfo
->mouse_face_end_row
11609 && (vpos
> dpyinfo
->mouse_face_beg_row
11610 || hpos
>= dpyinfo
->mouse_face_beg_col
)
11611 && (vpos
< dpyinfo
->mouse_face_end_row
11612 || hpos
< dpyinfo
->mouse_face_end_col
11613 || dpyinfo
->mouse_face_past_end
))
11617 return in_mouse_face
;
11621 /* Display or clear cursor of window W. If ON is zero, clear the
11622 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11623 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11626 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11628 int on
, hpos
, vpos
, x
, y
;
11630 struct frame
*f
= XFRAME (w
->frame
);
11631 int new_cursor_type
;
11632 int new_cursor_width
;
11633 struct glyph_matrix
*current_glyphs
;
11634 struct glyph_row
*glyph_row
;
11635 struct glyph
*glyph
;
11636 int cursor_non_selected
;
11638 /* This is pointless on invisible frames, and dangerous on garbaged
11639 windows and frames; in the latter case, the frame or window may
11640 be in the midst of changing its size, and x and y may be off the
11642 if (! FRAME_VISIBLE_P (f
)
11643 || FRAME_GARBAGED_P (f
)
11644 || vpos
>= w
->current_matrix
->nrows
11645 || hpos
>= w
->current_matrix
->matrix_w
)
11648 /* If cursor is off and we want it off, return quickly. */
11649 if (!on
&& !w
->phys_cursor_on_p
)
11652 current_glyphs
= w
->current_matrix
;
11653 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11654 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11656 /* If cursor row is not enabled, we don't really know where to
11657 display the cursor. */
11658 if (!glyph_row
->enabled_p
)
11660 w
->phys_cursor_on_p
= 0;
11664 xassert (interrupt_input_blocked
);
11666 /* Set new_cursor_type to the cursor we want to be displayed. In a
11667 mini-buffer window, we want the cursor only to appear if we are
11668 reading input from this window. For the selected window, we want
11669 the cursor type given by the frame parameter. If explicitly
11670 marked off, draw no cursor. In all other cases, we want a hollow
11672 cursor_non_selected
11673 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
11675 new_cursor_width
= -1;
11676 if (cursor_in_echo_area
11677 && FRAME_HAS_MINIBUF_P (f
)
11678 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11680 if (w
== XWINDOW (echo_area_window
))
11681 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11682 else if (cursor_non_selected
)
11683 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11685 new_cursor_type
= NO_CURSOR
;
11689 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11690 || w
!= XWINDOW (f
->selected_window
))
11692 if ((MINI_WINDOW_P (w
) && minibuf_level
== 0)
11693 || !cursor_non_selected
11694 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11695 new_cursor_type
= NO_CURSOR
;
11697 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11699 else if (w
->cursor_off_p
)
11700 new_cursor_type
= NO_CURSOR
;
11703 struct buffer
*b
= XBUFFER (w
->buffer
);
11705 if (EQ (b
->cursor_type
, Qt
))
11706 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11708 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11709 &new_cursor_width
);
11713 /* If cursor is currently being shown and we don't want it to be or
11714 it is in the wrong place, or the cursor type is not what we want,
11716 if (w
->phys_cursor_on_p
11718 || w
->phys_cursor
.x
!= x
11719 || w
->phys_cursor
.y
!= y
11720 || new_cursor_type
!= w
->phys_cursor_type
))
11721 x_erase_phys_cursor (w
);
11723 /* If the cursor is now invisible and we want it to be visible,
11725 if (on
&& !w
->phys_cursor_on_p
)
11727 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11728 w
->phys_cursor_height
= glyph_row
->height
;
11730 /* Set phys_cursor_.* before x_draw_.* is called because some
11731 of them may need the information. */
11732 w
->phys_cursor
.x
= x
;
11733 w
->phys_cursor
.y
= glyph_row
->y
;
11734 w
->phys_cursor
.hpos
= hpos
;
11735 w
->phys_cursor
.vpos
= vpos
;
11736 w
->phys_cursor_type
= new_cursor_type
;
11737 w
->phys_cursor_on_p
= 1;
11739 switch (new_cursor_type
)
11741 case HOLLOW_BOX_CURSOR
:
11742 x_draw_hollow_cursor (w
, glyph_row
);
11745 case FILLED_BOX_CURSOR
:
11746 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11750 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11761 if (w
== XWINDOW (f
->selected_window
))
11762 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11763 xic_set_preeditarea (w
, x
, y
);
11768 if (updating_frame
!= f
)
11769 XFlush (FRAME_X_DISPLAY (f
));
11774 /* Display the cursor on window W, or clear it. X and Y are window
11775 relative pixel coordinates. HPOS and VPOS are glyph matrix
11776 positions. If W is not the selected window, display a hollow
11777 cursor. ON non-zero means display the cursor at X, Y which
11778 correspond to HPOS, VPOS, otherwise it is cleared. */
11781 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11783 int on
, hpos
, vpos
, x
, y
;
11786 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11791 /* Display the cursor on window W, or clear it, according to ON_P.
11792 Don't change the cursor's position. */
11795 x_update_cursor (f
, on_p
)
11798 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11802 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11803 in the window tree rooted at W. */
11806 x_update_cursor_in_window_tree (w
, on_p
)
11812 if (!NILP (w
->hchild
))
11813 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11814 else if (!NILP (w
->vchild
))
11815 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11817 x_update_window_cursor (w
, on_p
);
11819 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11824 /* Switch the display of W's cursor on or off, according to the value
11828 x_update_window_cursor (w
, on
)
11832 /* Don't update cursor in windows whose frame is in the process
11833 of being deleted. */
11834 if (w
->current_matrix
)
11837 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11838 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11848 /* Make the x-window of frame F use the gnu icon bitmap. */
11851 x_bitmap_icon (f
, file
)
11857 if (FRAME_X_WINDOW (f
) == 0)
11860 /* Free up our existing icon bitmap if any. */
11861 if (f
->output_data
.x
->icon_bitmap
> 0)
11862 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11863 f
->output_data
.x
->icon_bitmap
= 0;
11865 if (STRINGP (file
))
11866 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11869 /* Create the GNU bitmap if necessary. */
11870 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11871 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11872 = x_create_bitmap_from_data (f
, gnu_bits
,
11873 gnu_width
, gnu_height
);
11875 /* The first time we create the GNU bitmap,
11876 this increments the ref-count one extra time.
11877 As a result, the GNU bitmap is never freed.
11878 That way, we don't have to worry about allocating it again. */
11879 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11881 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11884 x_wm_set_icon_pixmap (f
, bitmap_id
);
11885 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11891 /* Make the x-window of frame F use a rectangle with text.
11892 Use ICON_NAME as the text. */
11895 x_text_icon (f
, icon_name
)
11899 if (FRAME_X_WINDOW (f
) == 0)
11904 XTextProperty text
;
11905 text
.value
= (unsigned char *) icon_name
;
11906 text
.encoding
= XA_STRING
;
11908 text
.nitems
= strlen (icon_name
);
11909 #ifdef USE_X_TOOLKIT
11910 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11912 #else /* not USE_X_TOOLKIT */
11913 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11914 #endif /* not USE_X_TOOLKIT */
11916 #else /* not HAVE_X11R4 */
11917 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11918 #endif /* not HAVE_X11R4 */
11920 if (f
->output_data
.x
->icon_bitmap
> 0)
11921 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11922 f
->output_data
.x
->icon_bitmap
= 0;
11923 x_wm_set_icon_pixmap (f
, 0);
11928 #define X_ERROR_MESSAGE_SIZE 200
11930 /* If non-nil, this should be a string.
11931 It means catch X errors and store the error message in this string. */
11933 static Lisp_Object x_error_message_string
;
11935 /* An X error handler which stores the error message in
11936 x_error_message_string. This is called from x_error_handler if
11937 x_catch_errors is in effect. */
11940 x_error_catcher (display
, error
)
11942 XErrorEvent
*error
;
11944 XGetErrorText (display
, error
->error_code
,
11945 XSTRING (x_error_message_string
)->data
,
11946 X_ERROR_MESSAGE_SIZE
);
11949 /* Begin trapping X errors for display DPY. Actually we trap X errors
11950 for all displays, but DPY should be the display you are actually
11953 After calling this function, X protocol errors no longer cause
11954 Emacs to exit; instead, they are recorded in the string
11955 stored in x_error_message_string.
11957 Calling x_check_errors signals an Emacs error if an X error has
11958 occurred since the last call to x_catch_errors or x_check_errors.
11960 Calling x_uncatch_errors resumes the normal error handling. */
11962 void x_check_errors ();
11963 static Lisp_Object
x_catch_errors_unwind ();
11966 x_catch_errors (dpy
)
11969 int count
= specpdl_ptr
- specpdl
;
11971 /* Make sure any errors from previous requests have been dealt with. */
11972 XSync (dpy
, False
);
11974 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11976 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11977 XSTRING (x_error_message_string
)->data
[0] = 0;
11982 /* Unbind the binding that we made to check for X errors. */
11985 x_catch_errors_unwind (old_val
)
11986 Lisp_Object old_val
;
11988 x_error_message_string
= old_val
;
11992 /* If any X protocol errors have arrived since the last call to
11993 x_catch_errors or x_check_errors, signal an Emacs error using
11994 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11997 x_check_errors (dpy
, format
)
12001 /* Make sure to catch any errors incurred so far. */
12002 XSync (dpy
, False
);
12004 if (XSTRING (x_error_message_string
)->data
[0])
12005 error (format
, XSTRING (x_error_message_string
)->data
);
12008 /* Nonzero if we had any X protocol errors
12009 since we did x_catch_errors on DPY. */
12012 x_had_errors_p (dpy
)
12015 /* Make sure to catch any errors incurred so far. */
12016 XSync (dpy
, False
);
12018 return XSTRING (x_error_message_string
)->data
[0] != 0;
12021 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
12024 x_clear_errors (dpy
)
12027 XSTRING (x_error_message_string
)->data
[0] = 0;
12030 /* Stop catching X protocol errors and let them make Emacs die.
12031 DPY should be the display that was passed to x_catch_errors.
12032 COUNT should be the value that was returned by
12033 the corresponding call to x_catch_errors. */
12036 x_uncatch_errors (dpy
, count
)
12040 unbind_to (count
, Qnil
);
12044 static unsigned int x_wire_count
;
12047 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
12052 /* Handle SIGPIPE, which can happen when the connection to a server
12053 simply goes away. SIGPIPE is handled by x_connection_signal.
12054 Don't need to do anything, because the write which caused the
12055 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
12056 which will do the appropriate cleanup for us. */
12059 x_connection_signal (signalnum
) /* If we don't have an argument, */
12060 int signalnum
; /* some compilers complain in signal calls. */
12063 /* USG systems forget handlers when they are used;
12064 must reestablish each time */
12065 signal (signalnum
, x_connection_signal
);
12070 /************************************************************************
12072 ************************************************************************/
12074 /* Error message passed to x_connection_closed. */
12076 static char *error_msg
;
12078 /* Function installed as fatal_error_signal_hook in
12079 x_connection_closed. Print the X error message, and exit normally,
12080 instead of dumping core when XtCloseDisplay fails. */
12083 x_fatal_error_signal ()
12085 fprintf (stderr
, "%s\n", error_msg
);
12089 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
12090 the text of an error message that lead to the connection loss. */
12093 x_connection_closed (dpy
, error_message
)
12095 char *error_message
;
12097 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
12098 Lisp_Object frame
, tail
;
12101 error_msg
= (char *) alloca (strlen (error_message
) + 1);
12102 strcpy (error_msg
, error_message
);
12103 handling_signal
= 0;
12105 /* Prevent being called recursively because of an error condition
12106 below. Otherwise, we might end up with printing ``can't find per
12107 display information'' in the recursive call instead of printing
12108 the original message here. */
12109 count
= x_catch_errors (dpy
);
12111 /* We have to close the display to inform Xt that it doesn't
12112 exist anymore. If we don't, Xt will continue to wait for
12113 events from the display. As a consequence, a sequence of
12115 M-x make-frame-on-display RET :1 RET
12116 ...kill the new frame, so that we get an IO error...
12117 M-x make-frame-on-display RET :1 RET
12119 will indefinitely wait in Xt for events for display `:1', opened
12120 in the first class to make-frame-on-display.
12122 Closing the display is reported to lead to a bus error on
12123 OpenWindows in certain situations. I suspect that is a bug
12124 in OpenWindows. I don't know how to cicumvent it here. */
12126 #ifdef USE_X_TOOLKIT
12127 /* If DPYINFO is null, this means we didn't open the display
12128 in the first place, so don't try to close it. */
12131 extern void (*fatal_error_signal_hook
) P_ ((void));
12132 fatal_error_signal_hook
= x_fatal_error_signal
;
12133 XtCloseDisplay (dpy
);
12134 fatal_error_signal_hook
= NULL
;
12138 /* Indicate that this display is dead. */
12140 dpyinfo
->display
= 0;
12142 /* First delete frames whose mini-buffers are on frames
12143 that are on the dead display. */
12144 FOR_EACH_FRAME (tail
, frame
)
12146 Lisp_Object minibuf_frame
;
12148 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
12149 if (FRAME_X_P (XFRAME (frame
))
12150 && FRAME_X_P (XFRAME (minibuf_frame
))
12151 && ! EQ (frame
, minibuf_frame
)
12152 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
12153 Fdelete_frame (frame
, Qt
);
12156 /* Now delete all remaining frames on the dead display.
12157 We are now sure none of these is used as the mini-buffer
12158 for another frame that we need to delete. */
12159 FOR_EACH_FRAME (tail
, frame
)
12160 if (FRAME_X_P (XFRAME (frame
))
12161 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
12163 /* Set this to t so that Fdelete_frame won't get confused
12164 trying to find a replacement. */
12165 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
12166 Fdelete_frame (frame
, Qt
);
12170 x_delete_display (dpyinfo
);
12172 x_uncatch_errors (dpy
, count
);
12174 if (x_display_list
== 0)
12176 fprintf (stderr
, "%s\n", error_msg
);
12177 shut_down_emacs (0, 0, Qnil
);
12181 /* Ordinary stack unwind doesn't deal with these. */
12183 sigunblock (sigmask (SIGIO
));
12185 sigunblock (sigmask (SIGALRM
));
12186 TOTALLY_UNBLOCK_INPUT
;
12188 clear_waiting_for_input ();
12189 error ("%s", error_msg
);
12193 /* This is the usual handler for X protocol errors.
12194 It kills all frames on the display that we got the error for.
12195 If that was the only one, it prints an error message and kills Emacs. */
12198 x_error_quitter (display
, error
)
12200 XErrorEvent
*error
;
12202 char buf
[256], buf1
[356];
12204 /* Note that there is no real way portable across R3/R4 to get the
12205 original error handler. */
12207 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
12208 sprintf (buf1
, "X protocol error: %s on protocol request %d",
12209 buf
, error
->request_code
);
12210 x_connection_closed (display
, buf1
);
12214 /* This is the first-level handler for X protocol errors.
12215 It calls x_error_quitter or x_error_catcher. */
12218 x_error_handler (display
, error
)
12220 XErrorEvent
*error
;
12222 if (! NILP (x_error_message_string
))
12223 x_error_catcher (display
, error
);
12225 x_error_quitter (display
, error
);
12229 /* This is the handler for X IO errors, always.
12230 It kills all frames on the display that we lost touch with.
12231 If that was the only one, it prints an error message and kills Emacs. */
12234 x_io_error_quitter (display
)
12239 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
12240 x_connection_closed (display
, buf
);
12244 /* Changing the font of the frame. */
12246 /* Give frame F the font named FONTNAME as its default font, and
12247 return the full name of that font. FONTNAME may be a wildcard
12248 pattern; in that case, we choose some font that fits the pattern.
12249 The return value shows which font we chose. */
12252 x_new_font (f
, fontname
)
12254 register char *fontname
;
12256 struct font_info
*fontp
12257 = FS_LOAD_FONT (f
, fontname
);
12262 if (f
->output_data
.x
->font
== (XFontStruct
*) (fontp
->font
))
12263 /* This font is already set in frame F. There's nothing more to
12265 return build_string (fontp
->full_name
);
12267 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
12268 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
12269 f
->output_data
.x
->fontset
= -1;
12271 x_compute_fringe_widths (f
, 1);
12273 /* Compute the scroll bar width in character columns. */
12274 if (f
->scroll_bar_pixel_width
> 0)
12276 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12277 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
12281 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12282 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
12285 /* Now make the frame display the given font. */
12286 if (FRAME_X_WINDOW (f
) != 0)
12288 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
12289 f
->output_data
.x
->font
->fid
);
12290 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
12291 f
->output_data
.x
->font
->fid
);
12292 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
12293 f
->output_data
.x
->font
->fid
);
12295 frame_update_line_height (f
);
12297 /* Don't change the size of a tip frame; there's no point in
12298 doing it because it's done in Fx_show_tip, and it leads to
12299 problems because the tip frame has no widget. */
12300 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
12301 x_set_window_size (f
, 0, f
->width
, f
->height
);
12304 /* If we are setting a new frame's font for the first time,
12305 there are no faces yet, so this font's height is the line height. */
12306 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
12308 return build_string (fontp
->full_name
);
12311 /* Give frame F the fontset named FONTSETNAME as its default fontset,
12312 and return the full name of that fontset. FONTSETNAME may be a
12313 wildcard pattern; in that case, we choose some fontset that fits
12314 the pattern. FONTSETNAME may be a font name for ASCII characters;
12315 in that case, we create a fontset from that font name.
12317 The return value shows which fontset we chose.
12318 If FONTSETNAME specifies the default fontset, return Qt.
12319 If an ASCII font in the specified fontset can't be loaded, return
12323 x_new_fontset (f
, fontsetname
)
12325 Lisp_Object fontsetname
;
12327 int fontset
= fs_query_fontset (fontsetname
, 0);
12328 Lisp_Object result
;
12330 if (fontset
> 0 && f
->output_data
.x
->fontset
== fontset
)
12331 /* This fontset is already set in frame F. There's nothing more
12333 return fontset_name (fontset
);
12334 else if (fontset
== 0)
12335 /* The default fontset can't be the default font. */
12339 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
12341 result
= x_new_font (f
, XSTRING (fontsetname
)->data
);
12343 if (!STRINGP (result
))
12344 /* Can't load ASCII font. */
12348 fontset
= new_fontset_from_font_name (result
);
12350 /* Since x_new_font doesn't update any fontset information, do it now. */
12351 f
->output_data
.x
->fontset
= fontset
;
12355 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
12356 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
12359 return fontset_name (fontset
);
12362 /* Compute actual fringe widths */
12365 x_compute_fringe_widths (f
, redraw
)
12369 int o_left
= f
->output_data
.x
->left_fringe_width
;
12370 int o_right
= f
->output_data
.x
->right_fringe_width
;
12371 int o_cols
= f
->output_data
.x
->fringe_cols
;
12373 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
12374 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
12375 int left_fringe_width
, right_fringe_width
;
12377 if (!NILP (left_fringe
))
12378 left_fringe
= Fcdr (left_fringe
);
12379 if (!NILP (right_fringe
))
12380 right_fringe
= Fcdr (right_fringe
);
12382 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
12383 XINT (left_fringe
));
12384 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
12385 XINT (right_fringe
));
12387 if (left_fringe_width
|| right_fringe_width
)
12389 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
12390 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
12391 int conf_wid
= left_wid
+ right_wid
;
12392 int font_wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12393 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
12394 int real_wid
= cols
* font_wid
;
12395 if (left_wid
&& right_wid
)
12397 if (left_fringe_width
< 0)
12399 /* Left fringe width is fixed, adjust right fringe if necessary */
12400 f
->output_data
.x
->left_fringe_width
= left_wid
;
12401 f
->output_data
.x
->right_fringe_width
= real_wid
- left_wid
;
12403 else if (right_fringe_width
< 0)
12405 /* Right fringe width is fixed, adjust left fringe if necessary */
12406 f
->output_data
.x
->left_fringe_width
= real_wid
- right_wid
;
12407 f
->output_data
.x
->right_fringe_width
= right_wid
;
12411 /* Adjust both fringes with an equal amount.
12412 Note that we are doing integer arithmetic here, so don't
12413 lose a pixel if the total width is an odd number. */
12414 int fill
= real_wid
- conf_wid
;
12415 f
->output_data
.x
->left_fringe_width
= left_wid
+ fill
/2;
12416 f
->output_data
.x
->right_fringe_width
= right_wid
+ fill
- fill
/2;
12419 else if (left_fringe_width
)
12421 f
->output_data
.x
->left_fringe_width
= real_wid
;
12422 f
->output_data
.x
->right_fringe_width
= 0;
12426 f
->output_data
.x
->left_fringe_width
= 0;
12427 f
->output_data
.x
->right_fringe_width
= real_wid
;
12429 f
->output_data
.x
->fringe_cols
= cols
;
12430 f
->output_data
.x
->fringes_extra
= real_wid
;
12434 f
->output_data
.x
->left_fringe_width
= 0;
12435 f
->output_data
.x
->right_fringe_width
= 0;
12436 f
->output_data
.x
->fringe_cols
= 0;
12437 f
->output_data
.x
->fringes_extra
= 0;
12440 if (redraw
&& FRAME_VISIBLE_P (f
))
12441 if (o_left
!= f
->output_data
.x
->left_fringe_width
||
12442 o_right
!= f
->output_data
.x
->right_fringe_width
||
12443 o_cols
!= f
->output_data
.x
->fringe_cols
)
12447 /***********************************************************************
12449 ***********************************************************************/
12455 /* XIM destroy callback function, which is called whenever the
12456 connection to input method XIM dies. CLIENT_DATA contains a
12457 pointer to the x_display_info structure corresponding to XIM. */
12460 xim_destroy_callback (xim
, client_data
, call_data
)
12462 XPointer client_data
;
12463 XPointer call_data
;
12465 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
12466 Lisp_Object frame
, tail
;
12470 /* No need to call XDestroyIC.. */
12471 FOR_EACH_FRAME (tail
, frame
)
12473 struct frame
*f
= XFRAME (frame
);
12474 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
12476 FRAME_XIC (f
) = NULL
;
12477 if (FRAME_XIC_FONTSET (f
))
12479 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
12480 FRAME_XIC_FONTSET (f
) = NULL
;
12485 /* No need to call XCloseIM. */
12486 dpyinfo
->xim
= NULL
;
12487 XFree (dpyinfo
->xim_styles
);
12491 #endif /* HAVE_X11R6 */
12493 /* Open the connection to the XIM server on display DPYINFO.
12494 RESOURCE_NAME is the resource name Emacs uses. */
12497 xim_open_dpy (dpyinfo
, resource_name
)
12498 struct x_display_info
*dpyinfo
;
12499 char *resource_name
;
12505 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
12507 dpyinfo
->xim
= xim
;
12512 XIMCallback destroy
;
12515 /* Get supported styles and XIM values. */
12516 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
12519 destroy
.callback
= xim_destroy_callback
;
12520 destroy
.client_data
= (XPointer
)dpyinfo
;
12521 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
12526 dpyinfo
->xim
= NULL
;
12530 #ifdef HAVE_X11R6_XIM
12534 struct x_display_info
*dpyinfo
;
12535 char *resource_name
;
12538 /* XIM instantiate callback function, which is called whenever an XIM
12539 server is available. DISPLAY is teh display of the XIM.
12540 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12541 when the callback was registered. */
12544 xim_instantiate_callback (display
, client_data
, call_data
)
12546 XPointer client_data
;
12547 XPointer call_data
;
12549 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12550 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12552 /* We don't support multiple XIM connections. */
12556 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12558 /* Create XIC for the existing frames on the same display, as long
12559 as they have no XIC. */
12560 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12562 Lisp_Object tail
, frame
;
12565 FOR_EACH_FRAME (tail
, frame
)
12567 struct frame
*f
= XFRAME (frame
);
12569 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12570 if (FRAME_XIC (f
) == NULL
)
12572 create_frame_xic (f
);
12573 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12574 xic_set_statusarea (f
);
12575 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12577 struct window
*w
= XWINDOW (f
->selected_window
);
12578 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12587 #endif /* HAVE_X11R6_XIM */
12590 /* Open a connection to the XIM server on display DPYINFO.
12591 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12592 connection only at the first time. On X11R6, open the connection
12593 in the XIM instantiate callback function. */
12596 xim_initialize (dpyinfo
, resource_name
)
12597 struct x_display_info
*dpyinfo
;
12598 char *resource_name
;
12602 #ifdef HAVE_X11R6_XIM
12603 struct xim_inst_t
*xim_inst
;
12606 dpyinfo
->xim
= NULL
;
12607 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12608 xim_inst
->dpyinfo
= dpyinfo
;
12609 len
= strlen (resource_name
);
12610 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12611 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12612 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12613 resource_name
, EMACS_CLASS
,
12614 xim_instantiate_callback
,
12615 /* Fixme: This is XPointer in
12616 XFree86 but (XPointer *) on
12617 Tru64, at least. */
12618 (XPointer
) xim_inst
);
12619 #else /* not HAVE_X11R6_XIM */
12620 dpyinfo
->xim
= NULL
;
12621 xim_open_dpy (dpyinfo
, resource_name
);
12622 #endif /* not HAVE_X11R6_XIM */
12625 dpyinfo
->xim
= NULL
;
12629 /* Close the connection to the XIM server on display DPYINFO. */
12632 xim_close_dpy (dpyinfo
)
12633 struct x_display_info
*dpyinfo
;
12637 #ifdef HAVE_X11R6_XIM
12638 if (dpyinfo
->display
)
12639 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12641 xim_instantiate_callback
, NULL
);
12642 #endif /* not HAVE_X11R6_XIM */
12643 if (dpyinfo
->display
)
12644 XCloseIM (dpyinfo
->xim
);
12645 dpyinfo
->xim
= NULL
;
12646 XFree (dpyinfo
->xim_styles
);
12650 #endif /* not HAVE_X11R6_XIM */
12654 /* Calculate the absolute position in frame F
12655 from its current recorded position values and gravity. */
12658 x_calc_absolute_position (f
)
12662 int win_x
= 0, win_y
= 0;
12663 int flags
= f
->output_data
.x
->size_hint_flags
;
12666 /* We have nothing to do if the current position
12667 is already for the top-left corner. */
12668 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12671 #ifdef USE_X_TOOLKIT
12672 this_window
= XtWindow (f
->output_data
.x
->widget
);
12674 this_window
= FRAME_X_WINDOW (f
);
12677 /* Find the position of the outside upper-left corner of
12678 the inner window, with respect to the outer window.
12679 But do this only if we will need the results. */
12680 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12685 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12688 x_clear_errors (FRAME_X_DISPLAY (f
));
12689 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12691 /* From-window, to-window. */
12693 f
->output_data
.x
->parent_desc
,
12695 /* From-position, to-position. */
12696 0, 0, &win_x
, &win_y
,
12698 /* Child of win. */
12700 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12702 Window newroot
, newparent
= 0xdeadbeef;
12703 Window
*newchildren
;
12704 unsigned int nchildren
;
12706 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12707 &newparent
, &newchildren
, &nchildren
))
12710 XFree ((char *) newchildren
);
12712 f
->output_data
.x
->parent_desc
= newparent
;
12718 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12722 /* Treat negative positions as relative to the leftmost bottommost
12723 position that fits on the screen. */
12724 if (flags
& XNegative
)
12725 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12726 - 2 * f
->output_data
.x
->border_width
- win_x
12728 + f
->output_data
.x
->left_pos
);
12731 int height
= PIXEL_HEIGHT (f
);
12733 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12734 /* Something is fishy here. When using Motif, starting Emacs with
12735 `-g -0-0', the frame appears too low by a few pixels.
12737 This seems to be so because initially, while Emacs is starting,
12738 the column widget's height and the frame's pixel height are
12739 different. The column widget's height is the right one. In
12740 later invocations, when Emacs is up, the frame's pixel height
12743 It's not obvious where the initial small difference comes from.
12744 2000-12-01, gerd. */
12746 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12749 if (flags
& YNegative
)
12750 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12751 - 2 * f
->output_data
.x
->border_width
12754 + f
->output_data
.x
->top_pos
);
12757 /* The left_pos and top_pos
12758 are now relative to the top and left screen edges,
12759 so the flags should correspond. */
12760 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12763 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12764 to really change the position, and 0 when calling from
12765 x_make_frame_visible (in that case, XOFF and YOFF are the current
12766 position values). It is -1 when calling from x_set_frame_parameters,
12767 which means, do adjust for borders but don't change the gravity. */
12770 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12772 register int xoff
, yoff
;
12773 int change_gravity
;
12775 int modified_top
, modified_left
;
12777 if (change_gravity
> 0)
12779 f
->output_data
.x
->top_pos
= yoff
;
12780 f
->output_data
.x
->left_pos
= xoff
;
12781 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12783 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12785 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12786 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12788 x_calc_absolute_position (f
);
12791 x_wm_set_size_hint (f
, (long) 0, 0);
12793 modified_left
= f
->output_data
.x
->left_pos
;
12794 modified_top
= f
->output_data
.x
->top_pos
;
12795 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12796 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12797 /* It is a mystery why we need to add the border_width here
12798 when the frame is already visible, but experiment says we do. */
12799 if (change_gravity
!= 0)
12801 modified_left
+= f
->output_data
.x
->border_width
;
12802 modified_top
+= f
->output_data
.x
->border_width
;
12806 #ifdef USE_X_TOOLKIT
12807 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12808 modified_left
, modified_top
);
12809 #else /* not USE_X_TOOLKIT */
12810 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12811 modified_left
, modified_top
);
12812 #endif /* not USE_X_TOOLKIT */
12816 /* Check if we need to resize the frame due to a fullscreen request.
12817 If so needed, resize the frame. */
12819 x_check_fullscreen (f
)
12822 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
12824 int width
, height
, ign
;
12826 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
12827 &f
->output_data
.x
->top_pos
);
12829 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
12831 /* We do not need to move the window, it shall be taken care of
12832 when setting WM manager hints.
12833 If the frame is visible already, the position is checked by
12834 x_check_fullscreen_move. */
12835 if (f
->width
!= width
|| f
->height
!= height
)
12837 change_frame_size (f
, height
, width
, 0, 1, 0);
12838 SET_FRAME_GARBAGED (f
);
12839 cancel_mouse_face (f
);
12841 /* Wait for the change of frame size to occur */
12842 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
12848 /* If frame parameters are set after the frame is mapped, we need to move
12849 the window. This is done in xfns.c.
12850 Some window managers moves the window to the right position, some
12851 moves the outer window manager window to the specified position.
12852 Here we check that we are in the right spot. If not, make a second
12853 move, assuming we are dealing with the second kind of window manager. */
12855 x_check_fullscreen_move (f
)
12858 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
12860 int expect_top
= f
->output_data
.x
->top_pos
;
12861 int expect_left
= f
->output_data
.x
->left_pos
;
12863 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
12865 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
12868 if (expect_top
!= f
->output_data
.x
->top_pos
12869 || expect_left
!= f
->output_data
.x
->left_pos
)
12870 x_set_offset (f
, expect_left
, expect_top
, 1);
12872 /* Just do this once */
12873 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
12878 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
12879 wanted positions of the WM window (not emacs window).
12880 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
12881 window (FRAME_X_WINDOW).
12884 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
12891 int newwidth
= f
->width
, newheight
= f
->height
;
12893 *top_pos
= f
->output_data
.x
->top_pos
;
12894 *left_pos
= f
->output_data
.x
->left_pos
;
12896 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
12900 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
12901 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
12902 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
12903 - f
->output_data
.x
->y_pixels_diff
;
12904 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
12908 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
12912 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
12913 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
12914 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
12915 - f
->output_data
.x
->x_pixels_diff
;
12916 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
12921 *height
= newheight
;
12925 /* Change the size of frame F's X window to COLS/ROWS in the case F
12926 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12927 top-left-corner window gravity for this size change and subsequent
12928 size changes. Otherwise we leave the window gravity unchanged. */
12931 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12933 int change_gravity
;
12936 int pixelwidth
, pixelheight
;
12938 check_frame_size (f
, &rows
, &cols
);
12939 f
->output_data
.x
->vertical_scroll_bar_extra
12940 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12942 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12943 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12944 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12946 x_compute_fringe_widths (f
, 0);
12948 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12949 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12951 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12952 x_wm_set_size_hint (f
, (long) 0, 0);
12954 XSync (FRAME_X_DISPLAY (f
), False
);
12955 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12956 pixelwidth
, pixelheight
);
12958 /* Now, strictly speaking, we can't be sure that this is accurate,
12959 but the window manager will get around to dealing with the size
12960 change request eventually, and we'll hear how it went when the
12961 ConfigureNotify event gets here.
12963 We could just not bother storing any of this information here,
12964 and let the ConfigureNotify event set everything up, but that
12965 might be kind of confusing to the Lisp code, since size changes
12966 wouldn't be reported in the frame parameters until some random
12967 point in the future when the ConfigureNotify event arrives.
12969 We pass 1 for DELAY since we can't run Lisp code inside of
12971 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12972 PIXEL_WIDTH (f
) = pixelwidth
;
12973 PIXEL_HEIGHT (f
) = pixelheight
;
12975 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12976 receive in the ConfigureNotify event; if we get what we asked
12977 for, then the event won't cause the screen to become garbaged, so
12978 we have to make sure to do it here. */
12979 SET_FRAME_GARBAGED (f
);
12981 XFlush (FRAME_X_DISPLAY (f
));
12985 /* Call this to change the size of frame F's x-window.
12986 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12987 for this size change and subsequent size changes.
12988 Otherwise we leave the window gravity unchanged. */
12991 x_set_window_size (f
, change_gravity
, cols
, rows
)
12993 int change_gravity
;
12998 #ifdef USE_X_TOOLKIT
13000 if (f
->output_data
.x
->widget
!= NULL
)
13002 /* The x and y position of the widget is clobbered by the
13003 call to XtSetValues within EmacsFrameSetCharSize.
13004 This is a real kludge, but I don't understand Xt so I can't
13005 figure out a correct fix. Can anyone else tell me? -- rms. */
13006 int xpos
= f
->output_data
.x
->widget
->core
.x
;
13007 int ypos
= f
->output_data
.x
->widget
->core
.y
;
13008 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
13009 f
->output_data
.x
->widget
->core
.x
= xpos
;
13010 f
->output_data
.x
->widget
->core
.y
= ypos
;
13013 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13015 #else /* not USE_X_TOOLKIT */
13017 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13019 #endif /* not USE_X_TOOLKIT */
13021 /* If cursor was outside the new size, mark it as off. */
13022 mark_window_cursors_off (XWINDOW (f
->root_window
));
13024 /* Clear out any recollection of where the mouse highlighting was,
13025 since it might be in a place that's outside the new frame size.
13026 Actually checking whether it is outside is a pain in the neck,
13027 so don't try--just let the highlighting be done afresh with new size. */
13028 cancel_mouse_face (f
);
13033 /* Mouse warping. */
13036 x_set_mouse_position (f
, x
, y
)
13042 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
13043 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
13045 if (pix_x
< 0) pix_x
= 0;
13046 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
13048 if (pix_y
< 0) pix_y
= 0;
13049 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
13053 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13054 0, 0, 0, 0, pix_x
, pix_y
);
13058 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
13061 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
13067 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13068 0, 0, 0, 0, pix_x
, pix_y
);
13072 /* focus shifting, raising and lowering. */
13075 x_focus_on_frame (f
)
13078 #if 0 /* This proves to be unpleasant. */
13082 /* I don't think that the ICCCM allows programs to do things like this
13083 without the interaction of the window manager. Whatever you end up
13084 doing with this code, do it to x_unfocus_frame too. */
13085 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13086 RevertToPointerRoot
, CurrentTime
);
13091 x_unfocus_frame (f
)
13095 /* Look at the remarks in x_focus_on_frame. */
13096 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
13097 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
13098 RevertToPointerRoot
, CurrentTime
);
13102 /* Raise frame F. */
13108 if (f
->async_visible
)
13111 #ifdef USE_X_TOOLKIT
13112 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13113 #else /* not USE_X_TOOLKIT */
13114 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13115 #endif /* not USE_X_TOOLKIT */
13116 XFlush (FRAME_X_DISPLAY (f
));
13121 /* Lower frame F. */
13127 if (f
->async_visible
)
13130 #ifdef USE_X_TOOLKIT
13131 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13132 #else /* not USE_X_TOOLKIT */
13133 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13134 #endif /* not USE_X_TOOLKIT */
13135 XFlush (FRAME_X_DISPLAY (f
));
13141 XTframe_raise_lower (f
, raise_flag
)
13151 /* Change of visibility. */
13153 /* This tries to wait until the frame is really visible.
13154 However, if the window manager asks the user where to position
13155 the frame, this will return before the user finishes doing that.
13156 The frame will not actually be visible at that time,
13157 but it will become visible later when the window manager
13158 finishes with it. */
13161 x_make_frame_visible (f
)
13165 int original_top
, original_left
;
13166 int retry_count
= 2;
13172 type
= x_icon_type (f
);
13174 x_bitmap_icon (f
, type
);
13176 if (! FRAME_VISIBLE_P (f
))
13178 /* We test FRAME_GARBAGED_P here to make sure we don't
13179 call x_set_offset a second time
13180 if we get to x_make_frame_visible a second time
13181 before the window gets really visible. */
13182 if (! FRAME_ICONIFIED_P (f
)
13183 && ! f
->output_data
.x
->asked_for_visible
)
13184 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13186 f
->output_data
.x
->asked_for_visible
= 1;
13188 if (! EQ (Vx_no_window_manager
, Qt
))
13189 x_wm_set_window_state (f
, NormalState
);
13190 #ifdef USE_X_TOOLKIT
13191 /* This was XtPopup, but that did nothing for an iconified frame. */
13192 XtMapWidget (f
->output_data
.x
->widget
);
13193 #else /* not USE_X_TOOLKIT */
13194 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13195 #endif /* not USE_X_TOOLKIT */
13196 #if 0 /* This seems to bring back scroll bars in the wrong places
13197 if the window configuration has changed. They seem
13198 to come back ok without this. */
13199 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
13200 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13204 XFlush (FRAME_X_DISPLAY (f
));
13206 /* Synchronize to ensure Emacs knows the frame is visible
13207 before we do anything else. We do this loop with input not blocked
13208 so that incoming events are handled. */
13212 /* This must be before UNBLOCK_INPUT
13213 since events that arrive in response to the actions above
13214 will set it when they are handled. */
13215 int previously_visible
= f
->output_data
.x
->has_been_visible
;
13217 original_left
= f
->output_data
.x
->left_pos
;
13218 original_top
= f
->output_data
.x
->top_pos
;
13220 /* This must come after we set COUNT. */
13223 /* We unblock here so that arriving X events are processed. */
13225 /* Now move the window back to where it was "supposed to be".
13226 But don't do it if the gravity is negative.
13227 When the gravity is negative, this uses a position
13228 that is 3 pixels too low. Perhaps that's really the border width.
13230 Don't do this if the window has never been visible before,
13231 because the window manager may choose the position
13232 and we don't want to override it. */
13234 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
13235 && f
->output_data
.x
->win_gravity
== NorthWestGravity
13236 && previously_visible
)
13240 unsigned int width
, height
, border
, depth
;
13244 /* On some window managers (such as FVWM) moving an existing
13245 window, even to the same place, causes the window manager
13246 to introduce an offset. This can cause the window to move
13247 to an unexpected location. Check the geometry (a little
13248 slow here) and then verify that the window is in the right
13249 place. If the window is not in the right place, move it
13250 there, and take the potential window manager hit. */
13251 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13252 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
13254 if (original_left
!= x
|| original_top
!= y
)
13255 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13256 original_left
, original_top
);
13261 XSETFRAME (frame
, f
);
13263 /* Wait until the frame is visible. Process X events until a
13264 MapNotify event has been seen, or until we think we won't get a
13265 MapNotify at all.. */
13266 for (count
= input_signal_count
+ 10;
13267 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
13269 /* Force processing of queued events. */
13272 /* Machines that do polling rather than SIGIO have been
13273 observed to go into a busy-wait here. So we'll fake an
13274 alarm signal to let the handler know that there's something
13275 to be read. We used to raise a real alarm, but it seems
13276 that the handler isn't always enabled here. This is
13278 if (input_polling_used ())
13280 /* It could be confusing if a real alarm arrives while
13281 processing the fake one. Turn it off and let the
13282 handler reset it. */
13283 extern void poll_for_input_1
P_ ((void));
13284 int old_poll_suppress_count
= poll_suppress_count
;
13285 poll_suppress_count
= 1;
13286 poll_for_input_1 ();
13287 poll_suppress_count
= old_poll_suppress_count
;
13290 /* See if a MapNotify event has been processed. */
13291 FRAME_SAMPLE_VISIBILITY (f
);
13296 (let ((f (selected-frame)))
13300 the frame is not raised with various window managers on
13301 FreeBSD, Linux and Solaris. It turns out that, for some
13302 unknown reason, the call to XtMapWidget is completely ignored.
13303 Mapping the widget a second time works. */
13305 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
13310 /* Change from mapped state to withdrawn state. */
13312 /* Make the frame visible (mapped and not iconified). */
13315 x_make_frame_invisible (f
)
13320 #ifdef USE_X_TOOLKIT
13321 /* Use the frame's outermost window, not the one we normally draw on. */
13322 window
= XtWindow (f
->output_data
.x
->widget
);
13323 #else /* not USE_X_TOOLKIT */
13324 window
= FRAME_X_WINDOW (f
);
13325 #endif /* not USE_X_TOOLKIT */
13327 /* Don't keep the highlight on an invisible frame. */
13328 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13329 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13331 #if 0/* This might add unreliability; I don't trust it -- rms. */
13332 if (! f
->async_visible
&& ! f
->async_iconified
)
13338 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
13339 that the current position of the window is user-specified, rather than
13340 program-specified, so that when the window is mapped again, it will be
13341 placed at the same location, without forcing the user to position it
13342 by hand again (they have already done that once for this window.) */
13343 x_wm_set_size_hint (f
, (long) 0, 1);
13347 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
13348 DefaultScreen (FRAME_X_DISPLAY (f
))))
13350 UNBLOCK_INPUT_RESIGNAL
;
13351 error ("Can't notify window manager of window withdrawal");
13353 #else /* ! defined (HAVE_X11R4) */
13355 /* Tell the window manager what we're going to do. */
13356 if (! EQ (Vx_no_window_manager
, Qt
))
13360 unmap
.xunmap
.type
= UnmapNotify
;
13361 unmap
.xunmap
.window
= window
;
13362 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
13363 unmap
.xunmap
.from_configure
= False
;
13364 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13365 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13367 SubstructureRedirectMaskSubstructureNotifyMask
,
13370 UNBLOCK_INPUT_RESIGNAL
;
13371 error ("Can't notify window manager of withdrawal");
13375 /* Unmap the window ourselves. Cheeky! */
13376 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
13377 #endif /* ! defined (HAVE_X11R4) */
13379 /* We can't distinguish this from iconification
13380 just by the event that we get from the server.
13381 So we can't win using the usual strategy of letting
13382 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
13383 and synchronize with the server to make sure we agree. */
13385 FRAME_ICONIFIED_P (f
) = 0;
13386 f
->async_visible
= 0;
13387 f
->async_iconified
= 0;
13394 /* Change window state from mapped to iconified. */
13397 x_iconify_frame (f
)
13403 /* Don't keep the highlight on an invisible frame. */
13404 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13405 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13407 if (f
->async_iconified
)
13412 FRAME_SAMPLE_VISIBILITY (f
);
13414 type
= x_icon_type (f
);
13416 x_bitmap_icon (f
, type
);
13418 #ifdef USE_X_TOOLKIT
13420 if (! FRAME_VISIBLE_P (f
))
13422 if (! EQ (Vx_no_window_manager
, Qt
))
13423 x_wm_set_window_state (f
, IconicState
);
13424 /* This was XtPopup, but that did nothing for an iconified frame. */
13425 XtMapWidget (f
->output_data
.x
->widget
);
13426 /* The server won't give us any event to indicate
13427 that an invisible frame was changed to an icon,
13428 so we have to record it here. */
13431 f
->async_iconified
= 1;
13432 f
->async_visible
= 0;
13437 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
13438 XtWindow (f
->output_data
.x
->widget
),
13439 DefaultScreen (FRAME_X_DISPLAY (f
)));
13443 error ("Can't notify window manager of iconification");
13445 f
->async_iconified
= 1;
13446 f
->async_visible
= 0;
13450 XFlush (FRAME_X_DISPLAY (f
));
13452 #else /* not USE_X_TOOLKIT */
13454 /* Make sure the X server knows where the window should be positioned,
13455 in case the user deiconifies with the window manager. */
13456 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
13457 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13459 /* Since we don't know which revision of X we're running, we'll use both
13460 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
13462 /* X11R4: send a ClientMessage to the window manager using the
13463 WM_CHANGE_STATE type. */
13467 message
.xclient
.window
= FRAME_X_WINDOW (f
);
13468 message
.xclient
.type
= ClientMessage
;
13469 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
13470 message
.xclient
.format
= 32;
13471 message
.xclient
.data
.l
[0] = IconicState
;
13473 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13474 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13476 SubstructureRedirectMask
| SubstructureNotifyMask
,
13479 UNBLOCK_INPUT_RESIGNAL
;
13480 error ("Can't notify window manager of iconification");
13484 /* X11R3: set the initial_state field of the window manager hints to
13486 x_wm_set_window_state (f
, IconicState
);
13488 if (!FRAME_VISIBLE_P (f
))
13490 /* If the frame was withdrawn, before, we must map it. */
13491 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13494 f
->async_iconified
= 1;
13495 f
->async_visible
= 0;
13497 XFlush (FRAME_X_DISPLAY (f
));
13499 #endif /* not USE_X_TOOLKIT */
13503 /* Free X resources of frame F. */
13506 x_free_frame_resources (f
)
13509 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13511 struct scroll_bar
*b
;
13515 /* If a display connection is dead, don't try sending more
13516 commands to the X server. */
13517 if (dpyinfo
->display
)
13519 if (f
->output_data
.x
->icon_desc
)
13520 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
13522 #ifdef USE_X_TOOLKIT
13523 /* Explicitly destroy the scroll bars of the frame. Without
13524 this, we get "BadDrawable" errors from the toolkit later on,
13525 presumably from expose events generated for the disappearing
13526 toolkit scroll bars. */
13527 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
13529 b
= XSCROLL_BAR (bar
);
13530 x_scroll_bar_remove (b
);
13536 free_frame_xic (f
);
13539 #ifdef USE_X_TOOLKIT
13540 if (f
->output_data
.x
->widget
)
13542 XtDestroyWidget (f
->output_data
.x
->widget
);
13543 f
->output_data
.x
->widget
= NULL
;
13545 /* Tooltips don't have widgets, only a simple X window, even if
13546 we are using a toolkit. */
13547 else if (FRAME_X_WINDOW (f
))
13548 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13550 free_frame_menubar (f
);
13551 #else /* !USE_X_TOOLKIT */
13552 if (FRAME_X_WINDOW (f
))
13553 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13554 #endif /* !USE_X_TOOLKIT */
13556 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
13557 unload_color (f
, f
->output_data
.x
->background_pixel
);
13558 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
13559 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
13560 unload_color (f
, f
->output_data
.x
->border_pixel
);
13561 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
13563 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
13564 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
13565 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
13566 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
13567 #ifdef USE_TOOLKIT_SCROLL_BARS
13568 /* Scrollbar shadow colors. */
13569 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
13570 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
13571 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
13572 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
13573 #endif /* USE_TOOLKIT_SCROLL_BARS */
13574 if (f
->output_data
.x
->white_relief
.allocated_p
)
13575 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
13576 if (f
->output_data
.x
->black_relief
.allocated_p
)
13577 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
13579 if (FRAME_FACE_CACHE (f
))
13580 free_frame_faces (f
);
13583 XFlush (FRAME_X_DISPLAY (f
));
13586 if (f
->output_data
.x
->saved_menu_event
)
13587 xfree (f
->output_data
.x
->saved_menu_event
);
13589 xfree (f
->output_data
.x
);
13590 f
->output_data
.x
= NULL
;
13592 if (f
== dpyinfo
->x_focus_frame
)
13593 dpyinfo
->x_focus_frame
= 0;
13594 if (f
== dpyinfo
->x_focus_event_frame
)
13595 dpyinfo
->x_focus_event_frame
= 0;
13596 if (f
== dpyinfo
->x_highlight_frame
)
13597 dpyinfo
->x_highlight_frame
= 0;
13599 if (f
== dpyinfo
->mouse_face_mouse_frame
)
13601 dpyinfo
->mouse_face_beg_row
13602 = dpyinfo
->mouse_face_beg_col
= -1;
13603 dpyinfo
->mouse_face_end_row
13604 = dpyinfo
->mouse_face_end_col
= -1;
13605 dpyinfo
->mouse_face_window
= Qnil
;
13606 dpyinfo
->mouse_face_deferred_gc
= 0;
13607 dpyinfo
->mouse_face_mouse_frame
= 0;
13614 /* Destroy the X window of frame F. */
13617 x_destroy_window (f
)
13620 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13622 /* If a display connection is dead, don't try sending more
13623 commands to the X server. */
13624 if (dpyinfo
->display
!= 0)
13625 x_free_frame_resources (f
);
13627 dpyinfo
->reference_count
--;
13631 /* Setting window manager hints. */
13633 /* Set the normal size hints for the window manager, for frame F.
13634 FLAGS is the flags word to use--or 0 meaning preserve the flags
13635 that the window now has.
13636 If USER_POSITION is nonzero, we set the USPosition
13637 flag (this is useful when FLAGS is 0). */
13640 x_wm_set_size_hint (f
, flags
, user_position
)
13645 XSizeHints size_hints
;
13647 #ifdef USE_X_TOOLKIT
13650 Dimension widget_width
, widget_height
;
13651 Window window
= XtWindow (f
->output_data
.x
->widget
);
13652 #else /* not USE_X_TOOLKIT */
13653 Window window
= FRAME_X_WINDOW (f
);
13654 #endif /* not USE_X_TOOLKIT */
13656 /* Setting PMaxSize caused various problems. */
13657 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
13659 size_hints
.x
= f
->output_data
.x
->left_pos
;
13660 size_hints
.y
= f
->output_data
.x
->top_pos
;
13662 #ifdef USE_X_TOOLKIT
13663 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
13664 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
13665 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
13666 size_hints
.height
= widget_height
;
13667 size_hints
.width
= widget_width
;
13668 #else /* not USE_X_TOOLKIT */
13669 size_hints
.height
= PIXEL_HEIGHT (f
);
13670 size_hints
.width
= PIXEL_WIDTH (f
);
13671 #endif /* not USE_X_TOOLKIT */
13673 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13674 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13675 size_hints
.max_width
13676 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13677 size_hints
.max_height
13678 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13680 /* Calculate the base and minimum sizes.
13682 (When we use the X toolkit, we don't do it here.
13683 Instead we copy the values that the widgets are using, below.) */
13684 #ifndef USE_X_TOOLKIT
13686 int base_width
, base_height
;
13687 int min_rows
= 0, min_cols
= 0;
13689 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13690 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13692 check_frame_size (f
, &min_rows
, &min_cols
);
13694 /* The window manager uses the base width hints to calculate the
13695 current number of rows and columns in the frame while
13696 resizing; min_width and min_height aren't useful for this
13697 purpose, since they might not give the dimensions for a
13698 zero-row, zero-column frame.
13700 We use the base_width and base_height members if we have
13701 them; otherwise, we set the min_width and min_height members
13702 to the size for a zero x zero frame. */
13705 size_hints
.flags
|= PBaseSize
;
13706 size_hints
.base_width
= base_width
;
13707 size_hints
.base_height
= base_height
;
13708 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13709 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13711 size_hints
.min_width
= base_width
;
13712 size_hints
.min_height
= base_height
;
13716 /* If we don't need the old flags, we don't need the old hint at all. */
13719 size_hints
.flags
|= flags
;
13722 #endif /* not USE_X_TOOLKIT */
13725 XSizeHints hints
; /* Sometimes I hate X Windows... */
13726 long supplied_return
;
13730 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13733 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13736 #ifdef USE_X_TOOLKIT
13737 size_hints
.base_height
= hints
.base_height
;
13738 size_hints
.base_width
= hints
.base_width
;
13739 size_hints
.min_height
= hints
.min_height
;
13740 size_hints
.min_width
= hints
.min_width
;
13744 size_hints
.flags
|= flags
;
13749 if (hints
.flags
& PSize
)
13750 size_hints
.flags
|= PSize
;
13751 if (hints
.flags
& PPosition
)
13752 size_hints
.flags
|= PPosition
;
13753 if (hints
.flags
& USPosition
)
13754 size_hints
.flags
|= USPosition
;
13755 if (hints
.flags
& USSize
)
13756 size_hints
.flags
|= USSize
;
13760 #ifndef USE_X_TOOLKIT
13765 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
13766 size_hints
.flags
|= PWinGravity
;
13770 size_hints
.flags
&= ~ PPosition
;
13771 size_hints
.flags
|= USPosition
;
13773 #endif /* PWinGravity */
13776 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13778 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13782 /* Used for IconicState or NormalState */
13785 x_wm_set_window_state (f
, state
)
13789 #ifdef USE_X_TOOLKIT
13792 XtSetArg (al
[0], XtNinitialState
, state
);
13793 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13794 #else /* not USE_X_TOOLKIT */
13795 Window window
= FRAME_X_WINDOW (f
);
13797 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
13798 f
->output_data
.x
->wm_hints
.initial_state
= state
;
13800 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13801 #endif /* not USE_X_TOOLKIT */
13805 x_wm_set_icon_pixmap (f
, pixmap_id
)
13809 Pixmap icon_pixmap
;
13811 #ifndef USE_X_TOOLKIT
13812 Window window
= FRAME_X_WINDOW (f
);
13817 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
13818 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
13822 /* It seems there is no way to turn off use of an icon pixmap.
13823 The following line does it, only if no icon has yet been created,
13824 for some window managers. But with mwm it crashes.
13825 Some people say it should clear the IconPixmapHint bit in this case,
13826 but that doesn't work, and the X consortium said it isn't the
13827 right thing at all. Since there is no way to win,
13828 best to explicitly give up. */
13830 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
13836 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
13840 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
13841 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13844 #else /* not USE_X_TOOLKIT */
13846 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
13847 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13849 #endif /* not USE_X_TOOLKIT */
13853 x_wm_set_icon_position (f
, icon_x
, icon_y
)
13855 int icon_x
, icon_y
;
13857 #ifdef USE_X_TOOLKIT
13858 Window window
= XtWindow (f
->output_data
.x
->widget
);
13860 Window window
= FRAME_X_WINDOW (f
);
13863 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
13864 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
13865 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
13867 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13871 /***********************************************************************
13873 ***********************************************************************/
13875 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
13878 x_get_font_info (f
, font_idx
)
13882 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
13886 /* Return a list of names of available fonts matching PATTERN on frame F.
13888 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13891 SIZE < 0 means include scalable fonts.
13893 Frame F null means we have not yet created any frame on X, and
13894 consult the first display in x_display_list. MAXNAMES sets a limit
13895 on how many fonts to match. */
13898 x_list_fonts (f
, pattern
, size
, maxnames
)
13900 Lisp_Object pattern
;
13904 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13905 Lisp_Object tem
, second_best
;
13906 struct x_display_info
*dpyinfo
13907 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13908 Display
*dpy
= dpyinfo
->display
;
13909 int try_XLoadQueryFont
= 0;
13911 int allow_scalable_fonts_p
= 0;
13915 allow_scalable_fonts_p
= 1;
13919 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13920 if (NILP (patterns
))
13921 patterns
= Fcons (pattern
, Qnil
);
13923 if (maxnames
== 1 && !size
)
13924 /* We can return any single font matching PATTERN. */
13925 try_XLoadQueryFont
= 1;
13927 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13930 char **names
= NULL
;
13932 pattern
= XCAR (patterns
);
13933 /* See if we cached the result for this particular query.
13934 The cache is an alist of the form:
13935 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13936 tem
= XCDR (dpyinfo
->name_list_element
);
13937 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13938 allow_scalable_fonts_p
? Qt
: Qnil
);
13939 list
= Fassoc (key
, tem
);
13942 list
= Fcdr_safe (list
);
13943 /* We have a cashed list. Don't have to get the list again. */
13947 /* At first, put PATTERN in the cache. */
13950 count
= x_catch_errors (dpy
);
13952 if (try_XLoadQueryFont
)
13955 unsigned long value
;
13957 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13958 if (x_had_errors_p (dpy
))
13960 /* This error is perhaps due to insufficient memory on X
13961 server. Let's just ignore it. */
13963 x_clear_errors (dpy
);
13967 && XGetFontProperty (font
, XA_FONT
, &value
))
13969 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13970 int len
= strlen (name
);
13973 /* If DXPC (a Differential X Protocol Compressor)
13974 Ver.3.7 is running, XGetAtomName will return null
13975 string. We must avoid such a name. */
13977 try_XLoadQueryFont
= 0;
13981 names
= (char **) alloca (sizeof (char *));
13982 /* Some systems only allow alloca assigned to a
13984 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13985 bcopy (name
, names
[0], len
+ 1);
13990 try_XLoadQueryFont
= 0;
13993 XFreeFont (dpy
, font
);
13996 if (!try_XLoadQueryFont
)
13998 /* We try at least 10 fonts because XListFonts will return
13999 auto-scaled fonts at the head. */
14000 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
14002 if (x_had_errors_p (dpy
))
14004 /* This error is perhaps due to insufficient memory on X
14005 server. Let's just ignore it. */
14007 x_clear_errors (dpy
);
14011 x_uncatch_errors (dpy
, count
);
14018 /* Make a list of all the fonts we got back.
14019 Store that in the font cache for the display. */
14020 for (i
= 0; i
< num_fonts
; i
++)
14023 char *p
= names
[i
];
14024 int average_width
= -1, dashes
= 0;
14026 /* Count the number of dashes in NAMES[I]. If there are
14027 14 dashes, and the field value following 12th dash
14028 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
14029 is usually too ugly to be used for editing. Let's
14035 if (dashes
== 7) /* PIXEL_SIZE field */
14037 else if (dashes
== 12) /* AVERAGE_WIDTH field */
14038 average_width
= atoi (p
);
14041 if (allow_scalable_fonts_p
14042 || dashes
< 14 || average_width
!= 0)
14044 tem
= build_string (names
[i
]);
14045 if (NILP (Fassoc (tem
, list
)))
14047 if (STRINGP (Vx_pixel_size_width_font_regexp
)
14048 && ((fast_c_string_match_ignore_case
14049 (Vx_pixel_size_width_font_regexp
, names
[i
]))
14051 /* We can set the value of PIXEL_SIZE to the
14052 width of this font. */
14053 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
14055 /* For the moment, width is not known. */
14056 list
= Fcons (Fcons (tem
, Qnil
), list
);
14061 if (!try_XLoadQueryFont
)
14064 XFreeFontNames (names
);
14069 /* Now store the result in the cache. */
14070 XSETCDR (dpyinfo
->name_list_element
,
14071 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
14074 if (NILP (list
)) continue; /* Try the remaining alternatives. */
14076 newlist
= second_best
= Qnil
;
14077 /* Make a list of the fonts that have the right width. */
14078 for (; CONSP (list
); list
= XCDR (list
))
14084 if (!CONSP (tem
) || NILP (XCAR (tem
)))
14088 newlist
= Fcons (XCAR (tem
), newlist
);
14092 if (!INTEGERP (XCDR (tem
)))
14094 /* Since we have not yet known the size of this font, we
14095 must try slow function call XLoadQueryFont. */
14096 XFontStruct
*thisinfo
;
14099 count
= x_catch_errors (dpy
);
14100 thisinfo
= XLoadQueryFont (dpy
,
14101 XSTRING (XCAR (tem
))->data
);
14102 if (x_had_errors_p (dpy
))
14104 /* This error is perhaps due to insufficient memory on X
14105 server. Let's just ignore it. */
14107 x_clear_errors (dpy
);
14109 x_uncatch_errors (dpy
, count
);
14115 (thisinfo
->min_bounds
.width
== 0
14117 : make_number (thisinfo
->max_bounds
.width
)));
14119 XFreeFont (dpy
, thisinfo
);
14123 /* For unknown reason, the previous call of XListFont had
14124 returned a font which can't be opened. Record the size
14125 as 0 not to try to open it again. */
14126 XSETCDR (tem
, make_number (0));
14129 found_size
= XINT (XCDR (tem
));
14130 if (found_size
== size
)
14131 newlist
= Fcons (XCAR (tem
), newlist
);
14132 else if (found_size
> 0)
14134 if (NILP (second_best
))
14136 else if (found_size
< size
)
14138 if (XINT (XCDR (second_best
)) > size
14139 || XINT (XCDR (second_best
)) < found_size
)
14144 if (XINT (XCDR (second_best
)) > size
14145 && XINT (XCDR (second_best
)) > found_size
)
14150 if (!NILP (newlist
))
14152 else if (!NILP (second_best
))
14154 newlist
= Fcons (XCAR (second_best
), Qnil
);
14165 /* Check that FONT is valid on frame F. It is if it can be found in F's
14169 x_check_font (f
, font
)
14174 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14176 xassert (font
!= NULL
);
14178 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14179 if (dpyinfo
->font_table
[i
].name
14180 && font
== dpyinfo
->font_table
[i
].font
)
14183 xassert (i
< dpyinfo
->n_fonts
);
14186 #endif /* GLYPH_DEBUG != 0 */
14188 /* Set *W to the minimum width, *H to the minimum font height of FONT.
14189 Note: There are (broken) X fonts out there with invalid XFontStruct
14190 min_bounds contents. For example, handa@etl.go.jp reports that
14191 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
14192 have font->min_bounds.width == 0. */
14195 x_font_min_bounds (font
, w
, h
)
14199 *h
= FONT_HEIGHT (font
);
14200 *w
= font
->min_bounds
.width
;
14202 /* Try to handle the case where FONT->min_bounds has invalid
14203 contents. Since the only font known to have invalid min_bounds
14204 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
14206 *w
= font
->max_bounds
.width
;
14210 /* Compute the smallest character width and smallest font height over
14211 all fonts available on frame F. Set the members smallest_char_width
14212 and smallest_font_height in F's x_display_info structure to
14213 the values computed. Value is non-zero if smallest_font_height or
14214 smallest_char_width become smaller than they were before. */
14217 x_compute_min_glyph_bounds (f
)
14221 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14223 int old_width
= dpyinfo
->smallest_char_width
;
14224 int old_height
= dpyinfo
->smallest_font_height
;
14226 dpyinfo
->smallest_font_height
= 100000;
14227 dpyinfo
->smallest_char_width
= 100000;
14229 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14230 if (dpyinfo
->font_table
[i
].name
)
14232 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
14235 font
= (XFontStruct
*) fontp
->font
;
14236 xassert (font
!= (XFontStruct
*) ~0);
14237 x_font_min_bounds (font
, &w
, &h
);
14239 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
14240 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
14243 xassert (dpyinfo
->smallest_char_width
> 0
14244 && dpyinfo
->smallest_font_height
> 0);
14246 return (dpyinfo
->n_fonts
== 1
14247 || dpyinfo
->smallest_char_width
< old_width
14248 || dpyinfo
->smallest_font_height
< old_height
);
14252 /* Load font named FONTNAME of the size SIZE for frame F, and return a
14253 pointer to the structure font_info while allocating it dynamically.
14254 If SIZE is 0, load any size of font.
14255 If loading is failed, return NULL. */
14258 x_load_font (f
, fontname
, size
)
14260 register char *fontname
;
14263 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14264 Lisp_Object font_names
;
14267 /* Get a list of all the fonts that match this name. Once we
14268 have a list of matching fonts, we compare them against the fonts
14269 we already have by comparing names. */
14270 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
14272 if (!NILP (font_names
))
14277 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14278 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
14279 if (dpyinfo
->font_table
[i
].name
14280 && (!strcmp (dpyinfo
->font_table
[i
].name
,
14281 XSTRING (XCAR (tail
))->data
)
14282 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
14283 XSTRING (XCAR (tail
))->data
)))
14284 return (dpyinfo
->font_table
+ i
);
14287 /* Load the font and add it to the table. */
14291 struct font_info
*fontp
;
14292 unsigned long value
;
14295 /* If we have found fonts by x_list_font, load one of them. If
14296 not, we still try to load a font by the name given as FONTNAME
14297 because XListFonts (called in x_list_font) of some X server has
14298 a bug of not finding a font even if the font surely exists and
14299 is loadable by XLoadQueryFont. */
14300 if (size
> 0 && !NILP (font_names
))
14301 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
14304 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
14305 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
14306 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
14308 /* This error is perhaps due to insufficient memory on X
14309 server. Let's just ignore it. */
14311 x_clear_errors (FRAME_X_DISPLAY (f
));
14313 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
14318 /* Find a free slot in the font table. */
14319 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14320 if (dpyinfo
->font_table
[i
].name
== NULL
)
14323 /* If no free slot found, maybe enlarge the font table. */
14324 if (i
== dpyinfo
->n_fonts
14325 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
14328 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
14329 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
14330 dpyinfo
->font_table
14331 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
14334 fontp
= dpyinfo
->font_table
+ i
;
14335 if (i
== dpyinfo
->n_fonts
)
14336 ++dpyinfo
->n_fonts
;
14338 /* Now fill in the slots of *FONTP. */
14340 fontp
->font
= font
;
14341 fontp
->font_idx
= i
;
14342 fontp
->charset
= -1; /* fs_load_font sets it. */
14343 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
14344 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
14346 /* Try to get the full name of FONT. Put it in FULL_NAME. */
14348 if (XGetFontProperty (font
, XA_FONT
, &value
))
14350 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
14354 /* Count the number of dashes in the "full name".
14355 If it is too few, this isn't really the font's full name,
14357 In X11R4, the fonts did not come with their canonical names
14368 full_name
= (char *) xmalloc (p
- name
+ 1);
14369 bcopy (name
, full_name
, p
- name
+ 1);
14375 if (full_name
!= 0)
14376 fontp
->full_name
= full_name
;
14378 fontp
->full_name
= fontp
->name
;
14380 fontp
->size
= font
->max_bounds
.width
;
14381 fontp
->height
= FONT_HEIGHT (font
);
14383 if (NILP (font_names
))
14385 /* We come here because of a bug of XListFonts mentioned at
14386 the head of this block. Let's store this information in
14387 the cache for x_list_fonts. */
14388 Lisp_Object lispy_name
= build_string (fontname
);
14389 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
14390 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
14393 XSETCDR (dpyinfo
->name_list_element
,
14395 Fcons (Fcons (lispy_full_name
,
14396 make_number (fontp
->size
)),
14398 XCDR (dpyinfo
->name_list_element
)));
14401 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
14403 XSETCDR (dpyinfo
->name_list_element
,
14405 Fcons (Fcons (lispy_full_name
,
14406 make_number (fontp
->size
)),
14408 XCDR (dpyinfo
->name_list_element
)));
14412 /* The slot `encoding' specifies how to map a character
14413 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
14414 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
14415 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
14416 2:0xA020..0xFF7F). For the moment, we don't know which charset
14417 uses this font. So, we set information in fontp->encoding[1]
14418 which is never used by any charset. If mapping can't be
14419 decided, set FONT_ENCODING_NOT_DECIDED. */
14420 fontp
->encoding_type
14421 = (font
->max_byte1
== 0
14423 ? (font
->min_char_or_byte2
< 0x80
14424 ? (font
->max_char_or_byte2
< 0x80
14425 ? 0 /* 0x20..0x7F */
14426 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
14427 : 1) /* 0xA0..0xFF */
14429 : (font
->min_byte1
< 0x80
14430 ? (font
->max_byte1
< 0x80
14431 ? (font
->min_char_or_byte2
< 0x80
14432 ? (font
->max_char_or_byte2
< 0x80
14433 ? 0 /* 0x2020..0x7F7F */
14434 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
14435 : 3) /* 0x20A0..0x7FFF */
14436 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
14437 : (font
->min_char_or_byte2
< 0x80
14438 ? (font
->max_char_or_byte2
< 0x80
14439 ? 2 /* 0xA020..0xFF7F */
14440 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
14441 : 1))); /* 0xA0A0..0xFFFF */
14443 fontp
->baseline_offset
14444 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
14445 ? (long) value
: 0);
14446 fontp
->relative_compose
14447 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
14448 ? (long) value
: 0);
14449 fontp
->default_ascent
14450 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
14451 ? (long) value
: 0);
14453 /* Set global flag fonts_changed_p to non-zero if the font loaded
14454 has a character with a smaller width than any other character
14455 before, or if the font loaded has a smaller height than any
14456 other font loaded before. If this happens, it will make a
14457 glyph matrix reallocation necessary. */
14458 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
14465 /* Return a pointer to struct font_info of a font named FONTNAME for
14466 frame F. If no such font is loaded, return NULL. */
14469 x_query_font (f
, fontname
)
14471 register char *fontname
;
14473 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14476 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14477 if (dpyinfo
->font_table
[i
].name
14478 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
14479 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
14480 return (dpyinfo
->font_table
+ i
);
14485 /* Find a CCL program for a font specified by FONTP, and set the member
14486 `encoder' of the structure. */
14489 x_find_ccl_program (fontp
)
14490 struct font_info
*fontp
;
14492 Lisp_Object list
, elt
;
14495 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
14499 && STRINGP (XCAR (elt
))
14500 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
14502 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
14509 struct ccl_program
*ccl
14510 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
14512 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
14515 fontp
->font_encoder
= ccl
;
14520 /* Return a char-table whose elements are t if the font FONT_INFO
14521 contains a glyph for the corresponding character, and nil if not.
14523 Fixme: For the moment, this function works only for fonts whose
14524 glyph encoding is the same as Unicode (e.g. ISO10646-1 fonts). */
14527 x_get_font_repertory (f
, font_info
)
14529 struct font_info
*font_info
;
14531 XFontStruct
*font
= (XFontStruct
*) font_info
->font
;
14533 int min_byte1
, max_byte1
, min_byte2
, max_byte2
;
14535 table
= Fmake_char_table (Qnil
, Qnil
);
14537 min_byte1
= font
->min_byte1
;
14538 max_byte1
= font
->max_byte1
;
14539 min_byte2
= font
->min_char_or_byte2
;
14540 max_byte2
= font
->max_char_or_byte2
;
14541 if (min_byte1
== 0 && max_byte1
== 0)
14543 if (! font
->per_char
|| font
->all_chars_exist
== True
)
14544 char_table_set_range (table
, min_byte2
, max_byte2
, Qt
);
14547 XCharStruct
*pcm
= font
->per_char
;
14551 for (i
= min_byte2
; i
<= max_byte2
; i
++, pcm
++)
14553 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
14557 char_table_set_range (table
, from
, i
- 1, Qt
);
14565 char_table_set_range (table
, from
, i
- 1, Qt
);
14570 if (! font
->per_char
|| font
->all_chars_exist
== True
)
14574 for (i
= min_byte1
; i
<= max_byte1
; i
++)
14575 char_table_set_range (table
,
14576 (i
<< 8) | min_byte2
, (i
<< 8) | max_byte2
,
14581 XCharStruct
*pcm
= font
->per_char
;
14584 for (i
= min_byte1
; i
<= max_byte1
; i
++)
14589 for (j
= min_byte2
; j
<= max_byte2
; j
++, pcm
++)
14591 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
14595 char_table_set_range (table
, (i
<< 8) | from
,
14596 (i
<< 8) | (j
- 1), Qt
);
14604 char_table_set_range (table
, (i
<< 8) | from
,
14605 (i
<< 8) | (j
- 1), Qt
);
14615 /***********************************************************************
14617 ***********************************************************************/
14619 #ifdef USE_X_TOOLKIT
14620 static XrmOptionDescRec emacs_options
[] = {
14621 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
14622 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
14624 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
14625 XrmoptionSepArg
, NULL
},
14626 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
14628 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14629 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14630 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14631 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14632 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14633 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
14634 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
14636 #endif /* USE_X_TOOLKIT */
14638 static int x_initialized
;
14640 #ifdef MULTI_KBOARD
14641 /* Test whether two display-name strings agree up to the dot that separates
14642 the screen number from the server number. */
14644 same_x_server (name1
, name2
)
14645 char *name1
, *name2
;
14647 int seen_colon
= 0;
14648 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
14649 int system_name_length
= strlen (system_name
);
14650 int length_until_period
= 0;
14652 while (system_name
[length_until_period
] != 0
14653 && system_name
[length_until_period
] != '.')
14654 length_until_period
++;
14656 /* Treat `unix' like an empty host name. */
14657 if (! strncmp (name1
, "unix:", 5))
14659 if (! strncmp (name2
, "unix:", 5))
14661 /* Treat this host's name like an empty host name. */
14662 if (! strncmp (name1
, system_name
, system_name_length
)
14663 && name1
[system_name_length
] == ':')
14664 name1
+= system_name_length
;
14665 if (! strncmp (name2
, system_name
, system_name_length
)
14666 && name2
[system_name_length
] == ':')
14667 name2
+= system_name_length
;
14668 /* Treat this host's domainless name like an empty host name. */
14669 if (! strncmp (name1
, system_name
, length_until_period
)
14670 && name1
[length_until_period
] == ':')
14671 name1
+= length_until_period
;
14672 if (! strncmp (name2
, system_name
, length_until_period
)
14673 && name2
[length_until_period
] == ':')
14674 name2
+= length_until_period
;
14676 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
14680 if (seen_colon
&& *name1
== '.')
14684 && (*name1
== '.' || *name1
== '\0')
14685 && (*name2
== '.' || *name2
== '\0'));
14689 struct x_display_info
*
14690 x_term_init (display_name
, xrm_option
, resource_name
)
14691 Lisp_Object display_name
;
14693 char *resource_name
;
14697 struct x_display_info
*dpyinfo
;
14702 if (!x_initialized
)
14708 #ifdef USE_X_TOOLKIT
14709 /* weiner@footloose.sps.mot.com reports that this causes
14711 X protocol error: BadAtom (invalid Atom parameter)
14712 on protocol request 18skiloaf.
14713 So let's not use it until R6. */
14714 #ifdef HAVE_X11XTR6
14715 XtSetLanguageProc (NULL
, NULL
, NULL
);
14726 argv
[argc
++] = "-xrm";
14727 argv
[argc
++] = xrm_option
;
14729 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
14730 resource_name
, EMACS_CLASS
,
14731 emacs_options
, XtNumber (emacs_options
),
14734 #ifdef HAVE_X11XTR6
14735 /* I think this is to compensate for XtSetLanguageProc. */
14740 #else /* not USE_X_TOOLKIT */
14742 XSetLocaleModifiers ("");
14744 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
14745 #endif /* not USE_X_TOOLKIT */
14747 /* Detect failure. */
14754 /* We have definitely succeeded. Record the new connection. */
14756 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
14757 bzero (dpyinfo
, sizeof *dpyinfo
);
14759 #ifdef MULTI_KBOARD
14761 struct x_display_info
*share
;
14764 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
14765 share
= share
->next
, tail
= XCDR (tail
))
14766 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
14767 XSTRING (display_name
)->data
))
14770 dpyinfo
->kboard
= share
->kboard
;
14773 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
14774 init_kboard (dpyinfo
->kboard
);
14775 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
14777 char *vendor
= ServerVendor (dpy
);
14779 dpyinfo
->kboard
->Vsystem_key_alist
14780 = call1 (Qvendor_specific_keysyms
,
14781 build_string (vendor
? vendor
: ""));
14785 dpyinfo
->kboard
->next_kboard
= all_kboards
;
14786 all_kboards
= dpyinfo
->kboard
;
14787 /* Don't let the initial kboard remain current longer than necessary.
14788 That would cause problems if a file loaded on startup tries to
14789 prompt in the mini-buffer. */
14790 if (current_kboard
== initial_kboard
)
14791 current_kboard
= dpyinfo
->kboard
;
14793 dpyinfo
->kboard
->reference_count
++;
14797 /* Put this display on the chain. */
14798 dpyinfo
->next
= x_display_list
;
14799 x_display_list
= dpyinfo
;
14801 /* Put it on x_display_name_list as well, to keep them parallel. */
14802 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
14803 x_display_name_list
);
14804 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
14806 dpyinfo
->display
= dpy
;
14809 XSetAfterFunction (x_current_display
, x_trace_wire
);
14813 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
14814 + STRING_BYTES (XSTRING (Vsystem_name
))
14816 sprintf (dpyinfo
->x_id_name
, "%s@%s",
14817 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
14819 /* Figure out which modifier bits mean what. */
14820 x_find_modifier_meanings (dpyinfo
);
14822 /* Get the scroll bar cursor. */
14823 dpyinfo
->vertical_scroll_bar_cursor
14824 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
14826 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
14827 resource_name
, EMACS_CLASS
);
14828 #ifdef HAVE_XRMSETDATABASE
14829 XrmSetDatabase (dpyinfo
->display
, xrdb
);
14831 dpyinfo
->display
->db
= xrdb
;
14833 /* Put the rdb where we can find it in a way that works on
14835 dpyinfo
->xrdb
= xrdb
;
14837 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
14838 DefaultScreen (dpyinfo
->display
));
14839 select_visual (dpyinfo
);
14840 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
14841 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
14842 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
14843 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
14844 dpyinfo
->grabbed
= 0;
14845 dpyinfo
->reference_count
= 0;
14846 dpyinfo
->icon_bitmap_id
= -1;
14847 dpyinfo
->font_table
= NULL
;
14848 dpyinfo
->n_fonts
= 0;
14849 dpyinfo
->font_table_size
= 0;
14850 dpyinfo
->bitmaps
= 0;
14851 dpyinfo
->bitmaps_size
= 0;
14852 dpyinfo
->bitmaps_last
= 0;
14853 dpyinfo
->scratch_cursor_gc
= 0;
14854 dpyinfo
->mouse_face_mouse_frame
= 0;
14855 dpyinfo
->mouse_face_deferred_gc
= 0;
14856 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
14857 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
14858 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
14859 dpyinfo
->mouse_face_window
= Qnil
;
14860 dpyinfo
->mouse_face_overlay
= Qnil
;
14861 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
14862 dpyinfo
->mouse_face_defer
= 0;
14863 dpyinfo
->mouse_face_hidden
= 0;
14864 dpyinfo
->x_focus_frame
= 0;
14865 dpyinfo
->x_focus_event_frame
= 0;
14866 dpyinfo
->x_highlight_frame
= 0;
14867 dpyinfo
->image_cache
= make_image_cache ();
14869 /* See if a private colormap is requested. */
14870 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
14872 if (dpyinfo
->visual
->class == PseudoColor
)
14875 value
= display_x_get_resource (dpyinfo
,
14876 build_string ("privateColormap"),
14877 build_string ("PrivateColormap"),
14879 if (STRINGP (value
)
14880 && (!strcmp (XSTRING (value
)->data
, "true")
14881 || !strcmp (XSTRING (value
)->data
, "on")))
14882 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
14886 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
14887 dpyinfo
->visual
, AllocNone
);
14890 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
14891 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
14892 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
14893 dpyinfo
->resy
= pixels
* 25.4 / mm
;
14894 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
14895 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
14896 dpyinfo
->resx
= pixels
* 25.4 / mm
;
14899 dpyinfo
->Xatom_wm_protocols
14900 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
14901 dpyinfo
->Xatom_wm_take_focus
14902 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
14903 dpyinfo
->Xatom_wm_save_yourself
14904 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
14905 dpyinfo
->Xatom_wm_delete_window
14906 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
14907 dpyinfo
->Xatom_wm_change_state
14908 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
14909 dpyinfo
->Xatom_wm_configure_denied
14910 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
14911 dpyinfo
->Xatom_wm_window_moved
14912 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
14913 dpyinfo
->Xatom_editres
14914 = XInternAtom (dpyinfo
->display
, "Editres", False
);
14915 dpyinfo
->Xatom_CLIPBOARD
14916 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
14917 dpyinfo
->Xatom_TIMESTAMP
14918 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
14919 dpyinfo
->Xatom_TEXT
14920 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
14921 dpyinfo
->Xatom_COMPOUND_TEXT
14922 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
14923 dpyinfo
->Xatom_DELETE
14924 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
14925 dpyinfo
->Xatom_MULTIPLE
14926 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
14927 dpyinfo
->Xatom_INCR
14928 = XInternAtom (dpyinfo
->display
, "INCR", False
);
14929 dpyinfo
->Xatom_EMACS_TMP
14930 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
14931 dpyinfo
->Xatom_TARGETS
14932 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
14933 dpyinfo
->Xatom_NULL
14934 = XInternAtom (dpyinfo
->display
, "NULL", False
);
14935 dpyinfo
->Xatom_ATOM_PAIR
14936 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
14937 /* For properties of font. */
14938 dpyinfo
->Xatom_PIXEL_SIZE
14939 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
14940 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
14941 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
14942 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
14943 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
14944 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
14945 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
14947 /* Ghostscript support. */
14948 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
14949 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
14951 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
14954 dpyinfo
->cut_buffers_initialized
= 0;
14956 connection
= ConnectionNumber (dpyinfo
->display
);
14957 dpyinfo
->connection
= connection
;
14962 null_bits
[0] = 0x00;
14964 dpyinfo
->null_pixel
14965 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14966 null_bits
, 1, 1, (long) 0, (long) 0,
14971 extern int gray_bitmap_width
, gray_bitmap_height
;
14972 extern char *gray_bitmap_bits
;
14974 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14976 gray_bitmap_width
, gray_bitmap_height
,
14977 (unsigned long) 1, (unsigned long) 0, 1);
14981 xim_initialize (dpyinfo
, resource_name
);
14984 #ifdef subprocesses
14985 /* This is only needed for distinguishing keyboard and process input. */
14986 if (connection
!= 0)
14987 add_keyboard_wait_descriptor (connection
);
14990 #ifndef F_SETOWN_BUG
14992 #ifdef F_SETOWN_SOCK_NEG
14993 /* stdin is a socket here */
14994 fcntl (connection
, F_SETOWN
, -getpid ());
14995 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14996 fcntl (connection
, F_SETOWN
, getpid ());
14997 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14998 #endif /* ! defined (F_SETOWN) */
14999 #endif /* F_SETOWN_BUG */
15002 if (interrupt_input
)
15003 init_sigio (connection
);
15004 #endif /* ! defined (SIGIO) */
15007 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
15008 /* Make sure that we have a valid font for dialog boxes
15009 so that Xt does not crash. */
15011 Display
*dpy
= dpyinfo
->display
;
15012 XrmValue d
, fr
, to
;
15016 d
.addr
= (XPointer
)&dpy
;
15017 d
.size
= sizeof (Display
*);
15018 fr
.addr
= XtDefaultFont
;
15019 fr
.size
= sizeof (XtDefaultFont
);
15020 to
.size
= sizeof (Font
*);
15021 to
.addr
= (XPointer
)&font
;
15022 count
= x_catch_errors (dpy
);
15023 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
15025 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
15026 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
15027 x_uncatch_errors (dpy
, count
);
15032 /* See if we should run in synchronous mode. This is useful
15033 for debugging X code. */
15036 value
= display_x_get_resource (dpyinfo
,
15037 build_string ("synchronous"),
15038 build_string ("Synchronous"),
15040 if (STRINGP (value
)
15041 && (!strcmp (XSTRING (value
)->data
, "true")
15042 || !strcmp (XSTRING (value
)->data
, "on")))
15043 XSynchronize (dpyinfo
->display
, True
);
15048 value
= display_x_get_resource (dpyinfo
,
15049 build_string ("useXIM"),
15050 build_string ("UseXIM"),
15052 if (STRINGP (value
)
15053 && (!strcmp (XSTRING (value
)->data
, "false")
15054 || !strcmp (XSTRING (value
)->data
, "off")))
15063 /* Get rid of display DPYINFO, assuming all frames are already gone,
15064 and without sending any more commands to the X server. */
15067 x_delete_display (dpyinfo
)
15068 struct x_display_info
*dpyinfo
;
15070 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
15072 /* Discard this display from x_display_name_list and x_display_list.
15073 We can't use Fdelq because that can quit. */
15074 if (! NILP (x_display_name_list
)
15075 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
15076 x_display_name_list
= XCDR (x_display_name_list
);
15081 tail
= x_display_name_list
;
15082 while (CONSP (tail
) && CONSP (XCDR (tail
)))
15084 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
15086 XSETCDR (tail
, XCDR (XCDR (tail
)));
15089 tail
= XCDR (tail
);
15093 if (next_noop_dpyinfo
== dpyinfo
)
15094 next_noop_dpyinfo
= dpyinfo
->next
;
15096 if (x_display_list
== dpyinfo
)
15097 x_display_list
= dpyinfo
->next
;
15100 struct x_display_info
*tail
;
15102 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
15103 if (tail
->next
== dpyinfo
)
15104 tail
->next
= tail
->next
->next
;
15107 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
15108 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
15109 XrmDestroyDatabase (dpyinfo
->xrdb
);
15112 #ifdef MULTI_KBOARD
15113 if (--dpyinfo
->kboard
->reference_count
== 0)
15114 delete_kboard (dpyinfo
->kboard
);
15118 xim_close_dpy (dpyinfo
);
15121 xfree (dpyinfo
->font_table
);
15122 xfree (dpyinfo
->x_id_name
);
15123 xfree (dpyinfo
->color_cells
);
15128 /* Set up use of X before we make the first connection. */
15130 static struct redisplay_interface x_redisplay_interface
=
15135 x_clear_end_of_line
,
15137 x_after_update_window_line
,
15138 x_update_window_begin
,
15139 x_update_window_end
,
15142 x_clear_mouse_face
,
15143 x_get_glyph_overhangs
,
15144 x_fix_overlapping_area
15150 rif
= &x_redisplay_interface
;
15152 clear_frame_hook
= x_clear_frame
;
15153 ins_del_lines_hook
= x_ins_del_lines
;
15154 delete_glyphs_hook
= x_delete_glyphs
;
15155 ring_bell_hook
= XTring_bell
;
15156 reset_terminal_modes_hook
= XTreset_terminal_modes
;
15157 set_terminal_modes_hook
= XTset_terminal_modes
;
15158 update_begin_hook
= x_update_begin
;
15159 update_end_hook
= x_update_end
;
15160 set_terminal_window_hook
= XTset_terminal_window
;
15161 read_socket_hook
= XTread_socket
;
15162 frame_up_to_date_hook
= XTframe_up_to_date
;
15163 mouse_position_hook
= XTmouse_position
;
15164 frame_rehighlight_hook
= XTframe_rehighlight
;
15165 frame_raise_lower_hook
= XTframe_raise_lower
;
15166 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
15167 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
15168 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
15169 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
15170 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
15172 scroll_region_ok
= 1; /* we'll scroll partial frames */
15173 char_ins_del_ok
= 1;
15174 line_ins_del_ok
= 1; /* we'll just blt 'em */
15175 fast_clear_end_of_line
= 1; /* X does this well */
15176 memory_below_frame
= 0; /* we don't remember what scrolls
15181 last_tool_bar_item
= -1;
15182 any_help_event_p
= 0;
15184 /* Try to use interrupt input; if we can't, then start polling. */
15185 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
15187 #ifdef USE_X_TOOLKIT
15188 XtToolkitInitialize ();
15190 Xt_app_con
= XtCreateApplicationContext ();
15192 /* Register a converter from strings to pixels, which uses
15193 Emacs' color allocation infrastructure. */
15194 XtAppSetTypeConverter (Xt_app_con
,
15195 XtRString
, XtRPixel
, cvt_string_to_pixel
,
15196 cvt_string_to_pixel_args
,
15197 XtNumber (cvt_string_to_pixel_args
),
15198 XtCacheByDisplay
, cvt_pixel_dtor
);
15200 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
15202 /* Install an asynchronous timer that processes Xt timeout events
15203 every 0.1s. This is necessary because some widget sets use
15204 timeouts internally, for example the LessTif menu bar, or the
15205 Xaw3d scroll bar. When Xt timouts aren't processed, these
15206 widgets don't behave normally. */
15208 EMACS_TIME interval
;
15209 EMACS_SET_SECS_USECS (interval
, 0, 100000);
15210 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
15214 #ifdef USE_TOOLKIT_SCROLL_BARS
15215 xaw3d_arrow_scroll
= False
;
15216 xaw3d_pick_top
= True
;
15219 /* Note that there is no real way portable across R3/R4 to get the
15220 original error handler. */
15221 XSetErrorHandler (x_error_handler
);
15222 XSetIOErrorHandler (x_io_error_quitter
);
15224 /* Disable Window Change signals; they are handled by X events. */
15226 signal (SIGWINCH
, SIG_DFL
);
15227 #endif /* ! defined (SIGWINCH) */
15229 signal (SIGPIPE
, x_connection_signal
);
15236 staticpro (&x_error_message_string
);
15237 x_error_message_string
= Qnil
;
15239 staticpro (&x_display_name_list
);
15240 x_display_name_list
= Qnil
;
15242 staticpro (&last_mouse_scroll_bar
);
15243 last_mouse_scroll_bar
= Qnil
;
15245 staticpro (&Qvendor_specific_keysyms
);
15246 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
15248 staticpro (&last_mouse_press_frame
);
15249 last_mouse_press_frame
= Qnil
;
15252 staticpro (&help_echo
);
15253 help_echo_object
= Qnil
;
15254 staticpro (&help_echo_object
);
15255 help_echo_window
= Qnil
;
15256 staticpro (&help_echo_window
);
15257 previous_help_echo
= Qnil
;
15258 staticpro (&previous_help_echo
);
15259 help_echo_pos
= -1;
15261 DEFVAR_BOOL ("x-autoselect-window", &x_autoselect_window_p
,
15262 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
15263 x_autoselect_window_p
= 0;
15265 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
15266 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
15267 For example, if a block cursor is over a tab, it will be drawn as
15268 wide as that tab on the display. */);
15269 x_stretch_cursor_p
= 0;
15271 DEFVAR_BOOL ("x-use-underline-position-properties",
15272 &x_use_underline_position_properties
,
15273 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
15274 nil means ignore them. If you encounter fonts with bogus
15275 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
15276 to 4.1, set this to nil. */);
15277 x_use_underline_position_properties
= 1;
15279 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
15280 doc
: /* What X toolkit scroll bars Emacs uses.
15281 A value of nil means Emacs doesn't use X toolkit scroll bars.
15282 Otherwise, value is a symbol describing the X toolkit. */);
15283 #ifdef USE_TOOLKIT_SCROLL_BARS
15285 Vx_toolkit_scroll_bars
= intern ("motif");
15286 #elif defined HAVE_XAW3D
15287 Vx_toolkit_scroll_bars
= intern ("xaw3d");
15289 Vx_toolkit_scroll_bars
= intern ("xaw");
15292 Vx_toolkit_scroll_bars
= Qnil
;
15295 staticpro (&last_mouse_motion_frame
);
15296 last_mouse_motion_frame
= Qnil
;
15298 Qmodifier_value
= intern ("modifier-value");
15299 Qalt
= intern ("alt");
15300 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
15301 Qhyper
= intern ("hyper");
15302 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
15303 Qmeta
= intern ("meta");
15304 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
15305 Qsuper
= intern ("super");
15306 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
15308 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
15309 doc
: /* Which keys Emacs uses for the alt modifier.
15310 This should be one of the symbols `alt', `hyper', `meta', `super'.
15311 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
15312 is nil, which is the same as `alt'. */);
15313 Vx_alt_keysym
= Qnil
;
15315 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
15316 doc
: /* Which keys Emacs uses for the hyper modifier.
15317 This should be one of the symbols `alt', `hyper', `meta', `super'.
15318 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
15319 default is nil, which is the same as `hyper'. */);
15320 Vx_hyper_keysym
= Qnil
;
15322 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
15323 doc
: /* Which keys Emacs uses for the meta modifier.
15324 This should be one of the symbols `alt', `hyper', `meta', `super'.
15325 For example, `meta' means use the Meta_L and Meta_R keysyms. The
15326 default is nil, which is the same as `meta'. */);
15327 Vx_meta_keysym
= Qnil
;
15329 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
15330 doc
: /* Which keys Emacs uses for the super modifier.
15331 This should be one of the symbols `alt', `hyper', `meta', `super'.
15332 For example, `super' means use the Super_L and Super_R keysyms. The
15333 default is nil, which is the same as `super'. */);
15334 Vx_super_keysym
= Qnil
;
15336 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
15337 doc
: /* Hash table of character codes indexed by X keysym codes. */);
15338 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
15339 make_float (DEFAULT_REHASH_SIZE
),
15340 make_float (DEFAULT_REHASH_THRESHOLD
),
15344 #endif /* HAVE_X_WINDOWS */