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 (! EQ ((c
= Fgethash (make_number (keysym
),
10575 Vx_keysym_table
, Qnil
)),
10578 bufp
->kind
= (ASCII_CHAR_P (c
)
10580 : multibyte_char_keystroke
);
10582 XSETFRAME (bufp
->frame_or_window
, f
);
10585 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10587 bufp
->timestamp
= event
.xkey
.time
;
10592 else if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10593 || keysym
== XK_Delete
10594 #ifdef XK_ISO_Left_Tab
10595 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10597 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10598 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10599 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10601 /* This recognizes the "extended function
10602 keys". It seems there's no cleaner way.
10603 Test IsModifierKey to avoid handling
10604 mode_switch incorrectly. */
10605 || ((unsigned) (keysym
) >= XK_Select
10606 && (unsigned)(keysym
) < XK_KP_Space
)
10608 #ifdef XK_dead_circumflex
10609 || orig_keysym
== XK_dead_circumflex
10611 #ifdef XK_dead_grave
10612 || orig_keysym
== XK_dead_grave
10614 #ifdef XK_dead_tilde
10615 || orig_keysym
== XK_dead_tilde
10617 #ifdef XK_dead_diaeresis
10618 || orig_keysym
== XK_dead_diaeresis
10620 #ifdef XK_dead_macron
10621 || orig_keysym
== XK_dead_macron
10623 #ifdef XK_dead_degree
10624 || orig_keysym
== XK_dead_degree
10626 #ifdef XK_dead_acute
10627 || orig_keysym
== XK_dead_acute
10629 #ifdef XK_dead_cedilla
10630 || orig_keysym
== XK_dead_cedilla
10632 #ifdef XK_dead_breve
10633 || orig_keysym
== XK_dead_breve
10635 #ifdef XK_dead_ogonek
10636 || orig_keysym
== XK_dead_ogonek
10638 #ifdef XK_dead_caron
10639 || orig_keysym
== XK_dead_caron
10641 #ifdef XK_dead_doubleacute
10642 || orig_keysym
== XK_dead_doubleacute
10644 #ifdef XK_dead_abovedot
10645 || orig_keysym
== XK_dead_abovedot
10647 #ifdef XK_dead_abovering
10648 || orig_keysym
== XK_dead_abovering
10650 #ifdef XK_dead_iota
10651 || orig_keysym
== XK_dead_iota
10653 #ifdef XK_dead_belowdot
10654 || orig_keysym
== XK_dead_belowdot
10656 #ifdef XK_dead_voiced_sound
10657 || orig_keysym
== XK_dead_voiced_sound
10659 #ifdef XK_dead_semivoiced_sound
10660 || orig_keysym
== XK_dead_semivoiced_sound
10662 #ifdef XK_dead_hook
10663 || orig_keysym
== XK_dead_hook
10665 #ifdef XK_dead_horn
10666 || orig_keysym
== XK_dead_horn
10668 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10669 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10670 /* Any "vendor-specific" key is ok. */
10671 || (orig_keysym
& (1 << 28))
10672 || (keysym
!= NoSymbol
&& nbytes
== 0))
10673 && ! (IsModifierKey (orig_keysym
)
10675 #ifdef XK_Mode_switch
10676 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10679 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10681 #endif /* not HAVE_X11R5 */
10682 /* The symbols from XK_ISO_Lock to
10683 XK_ISO_Last_Group_Lock doesn't have
10684 real modifiers but should be treated
10685 similarly to Mode_switch by Emacs. */
10686 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
10687 || ((unsigned)(orig_keysym
) >= XK_ISO_Lock
10688 && (unsigned)(orig_keysym
) <= XK_ISO_Last_Group_Lock
)
10692 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10694 temp_buffer
[temp_index
++] = keysym
;
10695 /* make_lispy_event will convert this to a symbolic
10697 bufp
->kind
= non_ascii_keystroke
;
10698 bufp
->code
= keysym
;
10699 XSETFRAME (bufp
->frame_or_window
, f
);
10702 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10704 bufp
->timestamp
= event
.xkey
.time
;
10709 else if (numchars
> nbytes
)
10710 { /* Raw characters, not keysym. */
10715 for (i
= 0; i
< nbytes
; i
++)
10717 if (temp_index
== (sizeof temp_buffer
10720 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10724 /* Decode the input data. */
10726 = (unsigned char *) malloc (nbytes
);
10727 if (! coding
.destination
)
10729 coding
.dst_bytes
= nbytes
;
10730 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10731 decode_coding_c_string (&coding
, copy_bufptr
,
10733 nbytes
= coding
.produced
;
10734 nchars
= coding
.produced_char
;
10735 if (copy_bufsiz
< nbytes
)
10737 copy_bufsiz
= nbytes
;
10738 copy_bufptr
= (char *) alloca (nbytes
);
10740 bcopy (coding
.destination
, copy_bufptr
, nbytes
);
10741 free (coding
.destination
);
10744 /* Convert the input data to a sequence of
10745 character events. */
10746 for (i
= 0; i
< nbytes
; i
+= len
)
10748 if (nchars
== nbytes
)
10749 c
= copy_bufptr
[i
], len
= 1;
10751 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10754 bufp
->kind
= (ASCII_CHAR_P (c
)
10756 : multibyte_char_keystroke
);
10758 XSETFRAME (bufp
->frame_or_window
, f
);
10761 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10763 bufp
->timestamp
= event
.xkey
.time
;
10768 numchars
-= nchars
;
10770 if (keysym
== NoSymbol
)
10780 /* Don't dispatch this event since XtDispatchEvent calls
10781 XFilterEvent, and two calls in a row may freeze the
10790 /* Don't dispatch this event since XtDispatchEvent calls
10791 XFilterEvent, and two calls in a row may freeze the
10798 /* Here's a possible interpretation of the whole
10799 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10800 you get a FocusIn event, you have to get a FocusOut
10801 event before you relinquish the focus. If you
10802 haven't received a FocusIn event, then a mere
10803 LeaveNotify is enough to free you. */
10807 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10810 if (event
.xcrossing
.focus
)
10812 /* Avoid nasty pop/raise loops. */
10813 if (f
&& (!(f
->auto_raise
)
10814 || !(f
->auto_lower
)
10815 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10817 x_new_focus_frame (dpyinfo
, f
);
10818 enter_timestamp
= event
.xcrossing
.time
;
10821 else if (f
== dpyinfo
->x_focus_frame
)
10822 x_new_focus_frame (dpyinfo
, 0);
10825 /* EnterNotify counts as mouse movement,
10826 so update things that depend on mouse position. */
10827 if (f
&& !f
->output_data
.x
->hourglass_p
)
10828 note_mouse_movement (f
, &event
.xmotion
);
10833 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10834 if (event
.xfocus
.detail
!= NotifyPointer
)
10835 dpyinfo
->x_focus_event_frame
= f
;
10838 x_new_focus_frame (dpyinfo
, f
);
10840 /* Don't stop displaying the initial startup message
10841 for a switch-frame event we don't need. */
10842 if (GC_NILP (Vterminal_frame
)
10843 && GC_CONSP (Vframe_list
)
10844 && !GC_NILP (XCDR (Vframe_list
)))
10846 bufp
->kind
= FOCUS_IN_EVENT
;
10847 XSETFRAME (bufp
->frame_or_window
, f
);
10849 ++bufp
, ++count
, --numchars
;
10854 if (f
&& FRAME_XIC (f
))
10855 XSetICFocus (FRAME_XIC (f
));
10861 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10864 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10866 /* If we move outside the frame, then we're
10867 certainly no longer on any text in the frame. */
10868 clear_mouse_face (dpyinfo
);
10869 dpyinfo
->mouse_face_mouse_frame
= 0;
10872 /* Generate a nil HELP_EVENT to cancel a help-echo.
10873 Do it only if there's something to cancel.
10874 Otherwise, the startup message is cleared when
10875 the mouse leaves the frame. */
10876 if (any_help_event_p
)
10881 XSETFRAME (frame
, f
);
10883 n
= gen_help_event (bufp
, numchars
,
10884 Qnil
, frame
, Qnil
, Qnil
, 0);
10885 bufp
+= n
, count
+= n
, numchars
-= n
;
10889 if (event
.xcrossing
.focus
)
10890 x_mouse_leave (dpyinfo
);
10893 if (f
== dpyinfo
->x_focus_event_frame
)
10894 dpyinfo
->x_focus_event_frame
= 0;
10895 if (f
== dpyinfo
->x_focus_frame
)
10896 x_new_focus_frame (dpyinfo
, 0);
10903 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10904 if (event
.xfocus
.detail
!= NotifyPointer
10905 && f
== dpyinfo
->x_focus_event_frame
)
10906 dpyinfo
->x_focus_event_frame
= 0;
10907 if (f
&& f
== dpyinfo
->x_focus_frame
)
10908 x_new_focus_frame (dpyinfo
, 0);
10911 if (f
&& FRAME_XIC (f
))
10912 XUnsetICFocus (FRAME_XIC (f
));
10919 previous_help_echo
= help_echo
;
10920 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10921 help_echo_pos
= -1;
10923 if (dpyinfo
->grabbed
&& last_mouse_frame
10924 && FRAME_LIVE_P (last_mouse_frame
))
10925 f
= last_mouse_frame
;
10927 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10929 if (dpyinfo
->mouse_face_hidden
)
10931 dpyinfo
->mouse_face_hidden
= 0;
10932 clear_mouse_face (dpyinfo
);
10936 note_mouse_movement (f
, &event
.xmotion
);
10939 #ifndef USE_TOOLKIT_SCROLL_BARS
10940 struct scroll_bar
*bar
10941 = x_window_to_scroll_bar (event
.xmotion
.window
);
10944 x_scroll_bar_note_movement (bar
, &event
);
10945 #endif /* USE_TOOLKIT_SCROLL_BARS */
10947 /* If we move outside the frame, then we're
10948 certainly no longer on any text in the frame. */
10949 clear_mouse_face (dpyinfo
);
10952 /* If the contents of the global variable help_echo
10953 has changed, generate a HELP_EVENT. */
10954 if (!NILP (help_echo
)
10955 || !NILP (previous_help_echo
))
10961 XSETFRAME (frame
, f
);
10965 any_help_event_p
= 1;
10966 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10967 help_echo_window
, help_echo_object
,
10969 bufp
+= n
, count
+= n
, numchars
-= n
;
10975 case ConfigureNotify
:
10976 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10979 #ifndef USE_X_TOOLKIT
10980 /* If there is a pending resize for fullscreen, don't
10981 do this one, the right one will come later.
10982 The toolkit version doesn't seem to need this, but we
10983 need to reset it below. */
10985 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
10986 && FRAME_NEW_WIDTH (f
) != 0);
10987 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10988 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10992 /* In the toolkit version, change_frame_size
10993 is called by the code that handles resizing
10994 of the EmacsFrame widget. */
10996 /* Even if the number of character rows and columns has
10997 not changed, the font size may have changed, so we need
10998 to check the pixel dimensions as well. */
10999 if (columns
!= f
->width
11000 || rows
!= f
->height
11001 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
11002 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
11004 change_frame_size (f
, rows
, columns
, 0, 1, 0);
11005 SET_FRAME_GARBAGED (f
);
11006 cancel_mouse_face (f
);
11010 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
11011 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
11013 /* What we have now is the position of Emacs's own window.
11014 Convert that to the position of the window manager window. */
11015 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
11016 &f
->output_data
.x
->top_pos
);
11018 x_check_fullscreen_move(f
);
11019 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
11020 f
->output_data
.x
->want_fullscreen
&=
11021 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
11023 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
11024 xic_set_statusarea (f
);
11027 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11029 /* Since the WM decorations come below top_pos now,
11030 we must put them below top_pos in the future. */
11031 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11032 x_wm_set_size_hint (f
, (long) 0, 0);
11035 /* Some window managers pass (0,0) as the location of
11036 the window, and the Motif event handler stores it
11037 in the emacs widget, which messes up Motif menus. */
11038 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
11040 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
11041 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
11043 #endif /* USE_MOTIF */
11048 case ButtonRelease
:
11050 /* If we decide we want to generate an event to be seen
11051 by the rest of Emacs, we put it here. */
11052 struct input_event emacs_event
;
11053 int tool_bar_p
= 0;
11055 emacs_event
.kind
= no_event
;
11056 bzero (&compose_status
, sizeof (compose_status
));
11058 if (dpyinfo
->grabbed
11059 && last_mouse_frame
11060 && FRAME_LIVE_P (last_mouse_frame
))
11061 f
= last_mouse_frame
;
11063 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11067 /* Is this in the tool-bar? */
11068 if (WINDOWP (f
->tool_bar_window
)
11069 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
11071 Lisp_Object window
;
11074 x
= event
.xbutton
.x
;
11075 y
= event
.xbutton
.y
;
11078 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
11079 if (EQ (window
, f
->tool_bar_window
))
11081 x_handle_tool_bar_click (f
, &event
.xbutton
);
11087 if (!dpyinfo
->x_focus_frame
11088 || f
== dpyinfo
->x_focus_frame
)
11089 construct_mouse_click (&emacs_event
, &event
, f
);
11093 #ifndef USE_TOOLKIT_SCROLL_BARS
11094 struct scroll_bar
*bar
11095 = x_window_to_scroll_bar (event
.xbutton
.window
);
11098 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
11099 #endif /* not USE_TOOLKIT_SCROLL_BARS */
11102 if (event
.type
== ButtonPress
)
11104 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
11105 last_mouse_frame
= f
;
11106 /* Ignore any mouse motion that happened
11107 before this event; any subsequent mouse-movement
11108 Emacs events should reflect only motion after
11109 the ButtonPress. */
11111 f
->mouse_moved
= 0;
11114 last_tool_bar_item
= -1;
11118 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
11121 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
11123 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
11129 #ifdef USE_X_TOOLKIT
11130 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11131 /* For a down-event in the menu bar,
11132 don't pass it to Xt right now.
11133 Instead, save it away
11134 and we will pass it to Xt from kbd_buffer_get_event.
11135 That way, we can run some Lisp code first. */
11136 if (f
&& event
.type
== ButtonPress
11137 /* Verify the event is really within the menu bar
11138 and not just sent to it due to grabbing. */
11139 && event
.xbutton
.x
>= 0
11140 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
11141 && event
.xbutton
.y
>= 0
11142 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
11143 && event
.xbutton
.same_screen
)
11145 SET_SAVED_BUTTON_EVENT
;
11146 XSETFRAME (last_mouse_press_frame
, f
);
11148 else if (event
.type
== ButtonPress
)
11150 last_mouse_press_frame
= Qnil
;
11154 #ifdef USE_MOTIF /* This should do not harm for Lucid,
11155 but I am trying to be cautious. */
11156 else if (event
.type
== ButtonRelease
)
11158 if (!NILP (last_mouse_press_frame
))
11160 f
= XFRAME (last_mouse_press_frame
);
11161 if (f
->output_data
.x
)
11162 SET_SAVED_BUTTON_EVENT
;
11167 #endif /* USE_MOTIF */
11170 #endif /* USE_X_TOOLKIT */
11174 case CirculateNotify
:
11177 case CirculateRequest
:
11180 case VisibilityNotify
:
11183 case MappingNotify
:
11184 /* Someone has changed the keyboard mapping - update the
11186 switch (event
.xmapping
.request
)
11188 case MappingModifier
:
11189 x_find_modifier_meanings (dpyinfo
);
11190 /* This is meant to fall through. */
11191 case MappingKeyboard
:
11192 XRefreshKeyboardMapping (&event
.xmapping
);
11198 #ifdef USE_X_TOOLKIT
11200 XtDispatchEvent (&event
);
11202 #endif /* USE_X_TOOLKIT */
11210 /* On some systems, an X bug causes Emacs to get no more events
11211 when the window is destroyed. Detect that. (1994.) */
11214 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
11215 One XNOOP in 100 loops will make Emacs terminate.
11216 B. Bretthauer, 1994 */
11218 if (x_noop_count
>= 100)
11222 if (next_noop_dpyinfo
== 0)
11223 next_noop_dpyinfo
= x_display_list
;
11225 XNoOp (next_noop_dpyinfo
->display
);
11227 /* Each time we get here, cycle through the displays now open. */
11228 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
11232 /* If the focus was just given to an auto-raising frame,
11234 /* ??? This ought to be able to handle more than one such frame. */
11235 if (pending_autoraise_frame
)
11237 x_raise_frame (pending_autoraise_frame
);
11238 pending_autoraise_frame
= 0;
11249 /***********************************************************************
11251 ***********************************************************************/
11253 /* Notice when the text cursor of window W has been completely
11254 overwritten by a drawing operation that outputs glyphs in AREA
11255 starting at X0 and ending at X1 in the line starting at Y0 and
11256 ending at Y1. X coordinates are area-relative. X1 < 0 means all
11257 the rest of the line after X0 has been written. Y coordinates
11258 are window-relative. */
11261 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
11263 enum glyph_row_area area
;
11264 int x0
, y0
, x1
, y1
;
11266 if (area
== TEXT_AREA
11267 && w
->phys_cursor_on_p
11268 && y0
<= w
->phys_cursor
.y
11269 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
11270 && x0
<= w
->phys_cursor
.x
11271 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
11272 w
->phys_cursor_on_p
= 0;
11276 /* Set clipping for output in glyph row ROW. W is the window in which
11277 we operate. GC is the graphics context to set clipping in.
11278 WHOLE_LINE_P non-zero means include the areas used for truncation
11279 mark display and alike in the clipping rectangle.
11281 ROW may be a text row or, e.g., a mode line. Text rows must be
11282 clipped to the interior of the window dedicated to text display,
11283 mode lines must be clipped to the whole window. */
11286 x_clip_to_row (w
, row
, gc
, whole_line_p
)
11288 struct glyph_row
*row
;
11292 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11293 XRectangle clip_rect
;
11294 int window_x
, window_y
, window_width
, window_height
;
11296 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
11298 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
11299 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
11300 clip_rect
.y
= max (clip_rect
.y
, window_y
);
11301 clip_rect
.width
= window_width
;
11302 clip_rect
.height
= row
->visible_height
;
11304 /* If clipping to the whole line, including trunc marks, extend
11305 the rectangle to the left and increase its width. */
11308 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
11309 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
11312 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
11316 /* Draw a hollow box cursor on window W in glyph row ROW. */
11319 x_draw_hollow_cursor (w
, row
)
11321 struct glyph_row
*row
;
11323 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11324 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11325 Display
*dpy
= FRAME_X_DISPLAY (f
);
11328 struct glyph
*cursor_glyph
;
11331 /* Compute frame-relative coordinates from window-relative
11333 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11334 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
11335 + row
->ascent
- w
->phys_cursor_ascent
);
11336 h
= row
->height
- 1;
11338 /* Get the glyph the cursor is on. If we can't tell because
11339 the current matrix is invalid or such, give up. */
11340 cursor_glyph
= get_phys_cursor_glyph (w
);
11341 if (cursor_glyph
== NULL
)
11344 /* Compute the width of the rectangle to draw. If on a stretch
11345 glyph, and `x-stretch-block-cursor' is nil, don't draw a
11346 rectangle as wide as the glyph, but use a canonical character
11348 wd
= cursor_glyph
->pixel_width
- 1;
11349 if (cursor_glyph
->type
== STRETCH_GLYPH
11350 && !x_stretch_cursor_p
)
11351 wd
= min (CANON_X_UNIT (f
), wd
);
11353 /* The foreground of cursor_gc is typically the same as the normal
11354 background color, which can cause the cursor box to be invisible. */
11355 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11356 if (dpyinfo
->scratch_cursor_gc
)
11357 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11359 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11360 GCForeground
, &xgcv
);
11361 gc
= dpyinfo
->scratch_cursor_gc
;
11363 /* Set clipping, draw the rectangle, and reset clipping again. */
11364 x_clip_to_row (w
, row
, gc
, 0);
11365 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11366 XSetClipMask (dpy
, gc
, None
);
11370 /* Draw a bar cursor on window W in glyph row ROW.
11372 Implementation note: One would like to draw a bar cursor with an
11373 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11374 Unfortunately, I didn't find a font yet that has this property set.
11378 x_draw_bar_cursor (w
, row
, width
)
11380 struct glyph_row
*row
;
11383 struct frame
*f
= XFRAME (w
->frame
);
11384 struct glyph
*cursor_glyph
;
11386 /* If cursor is out of bounds, don't draw garbage. This can happen
11387 in mini-buffer windows when switching between echo area glyphs
11388 and mini-buffer. */
11389 cursor_glyph
= get_phys_cursor_glyph (w
);
11390 if (cursor_glyph
== NULL
)
11393 /* If on an image, draw like a normal cursor. That's usually better
11394 visible than drawing a bar, esp. if the image is large so that
11395 the bar might not be in the window. */
11396 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11398 struct glyph_row
*row
;
11399 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11400 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11404 Display
*dpy
= FRAME_X_DISPLAY (f
);
11405 Window window
= FRAME_X_WINDOW (f
);
11406 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11407 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11408 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
11411 /* If the glyph's background equals the color we normally draw
11412 the bar cursor in, the bar cursor in its normal color is
11413 invisible. Use the glyph's foreground color instead in this
11414 case, on the assumption that the glyph's colors are chosen so
11415 that the glyph is legible. */
11416 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
11417 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
11419 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11420 xgcv
.graphics_exposures
= 0;
11423 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11426 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11427 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11431 width
= f
->output_data
.x
->cursor_width
;
11432 width
= min (cursor_glyph
->pixel_width
, width
);
11434 x_clip_to_row (w
, row
, gc
, 0);
11435 XFillRectangle (dpy
, window
, gc
,
11436 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11437 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11438 width
, row
->height
);
11439 XSetClipMask (dpy
, gc
, None
);
11444 /* Clear the cursor of window W to background color, and mark the
11445 cursor as not shown. This is used when the text where the cursor
11446 is is about to be rewritten. */
11452 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11453 x_update_window_cursor (w
, 0);
11457 /* Draw the cursor glyph of window W in glyph row ROW. See the
11458 comment of x_draw_glyphs for the meaning of HL. */
11461 x_draw_phys_cursor_glyph (w
, row
, hl
)
11463 struct glyph_row
*row
;
11464 enum draw_glyphs_face hl
;
11466 /* If cursor hpos is out of bounds, don't draw garbage. This can
11467 happen in mini-buffer windows when switching between echo area
11468 glyphs and mini-buffer. */
11469 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11471 int on_p
= w
->phys_cursor_on_p
;
11473 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11474 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11476 w
->phys_cursor_on_p
= on_p
;
11478 /* When we erase the cursor, and ROW is overlapped by other
11479 rows, make sure that these overlapping parts of other rows
11481 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11483 if (row
> w
->current_matrix
->rows
11484 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11485 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11487 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11488 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11489 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11495 /* Erase the image of a cursor of window W from the screen. */
11498 x_erase_phys_cursor (w
)
11501 struct frame
*f
= XFRAME (w
->frame
);
11502 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11503 int hpos
= w
->phys_cursor
.hpos
;
11504 int vpos
= w
->phys_cursor
.vpos
;
11505 int mouse_face_here_p
= 0;
11506 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11507 struct glyph_row
*cursor_row
;
11508 struct glyph
*cursor_glyph
;
11509 enum draw_glyphs_face hl
;
11511 /* No cursor displayed or row invalidated => nothing to do on the
11513 if (w
->phys_cursor_type
== NO_CURSOR
)
11514 goto mark_cursor_off
;
11516 /* VPOS >= active_glyphs->nrows means that window has been resized.
11517 Don't bother to erase the cursor. */
11518 if (vpos
>= active_glyphs
->nrows
)
11519 goto mark_cursor_off
;
11521 /* If row containing cursor is marked invalid, there is nothing we
11523 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11524 if (!cursor_row
->enabled_p
)
11525 goto mark_cursor_off
;
11527 /* If row is completely invisible, don't attempt to delete a cursor which
11528 isn't there. This can happen if cursor is at top of a window, and
11529 we switch to a buffer with a header line in that window. */
11530 if (cursor_row
->visible_height
<= 0)
11531 goto mark_cursor_off
;
11533 /* This can happen when the new row is shorter than the old one.
11534 In this case, either x_draw_glyphs or clear_end_of_line
11535 should have cleared the cursor. Note that we wouldn't be
11536 able to erase the cursor in this case because we don't have a
11537 cursor glyph at hand. */
11538 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11539 goto mark_cursor_off
;
11541 /* If the cursor is in the mouse face area, redisplay that when
11542 we clear the cursor. */
11543 if (! NILP (dpyinfo
->mouse_face_window
)
11544 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11545 && (vpos
> dpyinfo
->mouse_face_beg_row
11546 || (vpos
== dpyinfo
->mouse_face_beg_row
11547 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11548 && (vpos
< dpyinfo
->mouse_face_end_row
11549 || (vpos
== dpyinfo
->mouse_face_end_row
11550 && hpos
< dpyinfo
->mouse_face_end_col
))
11551 /* Don't redraw the cursor's spot in mouse face if it is at the
11552 end of a line (on a newline). The cursor appears there, but
11553 mouse highlighting does not. */
11554 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11555 mouse_face_here_p
= 1;
11557 /* Maybe clear the display under the cursor. */
11558 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11561 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11563 cursor_glyph
= get_phys_cursor_glyph (w
);
11564 if (cursor_glyph
== NULL
)
11565 goto mark_cursor_off
;
11567 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11569 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11571 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11573 cursor_glyph
->pixel_width
,
11574 cursor_row
->visible_height
,
11578 /* Erase the cursor by redrawing the character underneath it. */
11579 if (mouse_face_here_p
)
11580 hl
= DRAW_MOUSE_FACE
;
11582 hl
= DRAW_NORMAL_TEXT
;
11583 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11586 w
->phys_cursor_on_p
= 0;
11587 w
->phys_cursor_type
= NO_CURSOR
;
11591 /* Non-zero if physical cursor of window W is within mouse face. */
11594 cursor_in_mouse_face_p (w
)
11597 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
11598 int in_mouse_face
= 0;
11600 if (WINDOWP (dpyinfo
->mouse_face_window
)
11601 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
11603 int hpos
= w
->phys_cursor
.hpos
;
11604 int vpos
= w
->phys_cursor
.vpos
;
11606 if (vpos
>= dpyinfo
->mouse_face_beg_row
11607 && vpos
<= dpyinfo
->mouse_face_end_row
11608 && (vpos
> dpyinfo
->mouse_face_beg_row
11609 || hpos
>= dpyinfo
->mouse_face_beg_col
)
11610 && (vpos
< dpyinfo
->mouse_face_end_row
11611 || hpos
< dpyinfo
->mouse_face_end_col
11612 || dpyinfo
->mouse_face_past_end
))
11616 return in_mouse_face
;
11620 /* Display or clear cursor of window W. If ON is zero, clear the
11621 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11622 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11625 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11627 int on
, hpos
, vpos
, x
, y
;
11629 struct frame
*f
= XFRAME (w
->frame
);
11630 int new_cursor_type
;
11631 int new_cursor_width
;
11632 struct glyph_matrix
*current_glyphs
;
11633 struct glyph_row
*glyph_row
;
11634 struct glyph
*glyph
;
11635 int cursor_non_selected
;
11637 /* This is pointless on invisible frames, and dangerous on garbaged
11638 windows and frames; in the latter case, the frame or window may
11639 be in the midst of changing its size, and x and y may be off the
11641 if (! FRAME_VISIBLE_P (f
)
11642 || FRAME_GARBAGED_P (f
)
11643 || vpos
>= w
->current_matrix
->nrows
11644 || hpos
>= w
->current_matrix
->matrix_w
)
11647 /* If cursor is off and we want it off, return quickly. */
11648 if (!on
&& !w
->phys_cursor_on_p
)
11651 current_glyphs
= w
->current_matrix
;
11652 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11653 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11655 /* If cursor row is not enabled, we don't really know where to
11656 display the cursor. */
11657 if (!glyph_row
->enabled_p
)
11659 w
->phys_cursor_on_p
= 0;
11663 xassert (interrupt_input_blocked
);
11665 /* Set new_cursor_type to the cursor we want to be displayed. In a
11666 mini-buffer window, we want the cursor only to appear if we are
11667 reading input from this window. For the selected window, we want
11668 the cursor type given by the frame parameter. If explicitly
11669 marked off, draw no cursor. In all other cases, we want a hollow
11671 cursor_non_selected
11672 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
11674 new_cursor_width
= -1;
11675 if (cursor_in_echo_area
11676 && FRAME_HAS_MINIBUF_P (f
)
11677 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11679 if (w
== XWINDOW (echo_area_window
))
11680 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11681 else if (cursor_non_selected
)
11682 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11684 new_cursor_type
= NO_CURSOR
;
11688 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11689 || w
!= XWINDOW (f
->selected_window
))
11691 if ((MINI_WINDOW_P (w
) && minibuf_level
== 0)
11692 || !cursor_non_selected
11693 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11694 new_cursor_type
= NO_CURSOR
;
11696 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11698 else if (w
->cursor_off_p
)
11699 new_cursor_type
= NO_CURSOR
;
11702 struct buffer
*b
= XBUFFER (w
->buffer
);
11704 if (EQ (b
->cursor_type
, Qt
))
11705 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11707 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11708 &new_cursor_width
);
11712 /* If cursor is currently being shown and we don't want it to be or
11713 it is in the wrong place, or the cursor type is not what we want,
11715 if (w
->phys_cursor_on_p
11717 || w
->phys_cursor
.x
!= x
11718 || w
->phys_cursor
.y
!= y
11719 || new_cursor_type
!= w
->phys_cursor_type
))
11720 x_erase_phys_cursor (w
);
11722 /* If the cursor is now invisible and we want it to be visible,
11724 if (on
&& !w
->phys_cursor_on_p
)
11726 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11727 w
->phys_cursor_height
= glyph_row
->height
;
11729 /* Set phys_cursor_.* before x_draw_.* is called because some
11730 of them may need the information. */
11731 w
->phys_cursor
.x
= x
;
11732 w
->phys_cursor
.y
= glyph_row
->y
;
11733 w
->phys_cursor
.hpos
= hpos
;
11734 w
->phys_cursor
.vpos
= vpos
;
11735 w
->phys_cursor_type
= new_cursor_type
;
11736 w
->phys_cursor_on_p
= 1;
11738 switch (new_cursor_type
)
11740 case HOLLOW_BOX_CURSOR
:
11741 x_draw_hollow_cursor (w
, glyph_row
);
11744 case FILLED_BOX_CURSOR
:
11745 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11749 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11760 if (w
== XWINDOW (f
->selected_window
))
11761 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11762 xic_set_preeditarea (w
, x
, y
);
11767 if (updating_frame
!= f
)
11768 XFlush (FRAME_X_DISPLAY (f
));
11773 /* Display the cursor on window W, or clear it. X and Y are window
11774 relative pixel coordinates. HPOS and VPOS are glyph matrix
11775 positions. If W is not the selected window, display a hollow
11776 cursor. ON non-zero means display the cursor at X, Y which
11777 correspond to HPOS, VPOS, otherwise it is cleared. */
11780 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11782 int on
, hpos
, vpos
, x
, y
;
11785 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11790 /* Display the cursor on window W, or clear it, according to ON_P.
11791 Don't change the cursor's position. */
11794 x_update_cursor (f
, on_p
)
11797 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11801 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11802 in the window tree rooted at W. */
11805 x_update_cursor_in_window_tree (w
, on_p
)
11811 if (!NILP (w
->hchild
))
11812 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11813 else if (!NILP (w
->vchild
))
11814 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11816 x_update_window_cursor (w
, on_p
);
11818 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11823 /* Switch the display of W's cursor on or off, according to the value
11827 x_update_window_cursor (w
, on
)
11831 /* Don't update cursor in windows whose frame is in the process
11832 of being deleted. */
11833 if (w
->current_matrix
)
11836 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11837 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11847 /* Make the x-window of frame F use the gnu icon bitmap. */
11850 x_bitmap_icon (f
, file
)
11856 if (FRAME_X_WINDOW (f
) == 0)
11859 /* Free up our existing icon bitmap if any. */
11860 if (f
->output_data
.x
->icon_bitmap
> 0)
11861 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11862 f
->output_data
.x
->icon_bitmap
= 0;
11864 if (STRINGP (file
))
11865 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11868 /* Create the GNU bitmap if necessary. */
11869 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11870 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11871 = x_create_bitmap_from_data (f
, gnu_bits
,
11872 gnu_width
, gnu_height
);
11874 /* The first time we create the GNU bitmap,
11875 this increments the ref-count one extra time.
11876 As a result, the GNU bitmap is never freed.
11877 That way, we don't have to worry about allocating it again. */
11878 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11880 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11883 x_wm_set_icon_pixmap (f
, bitmap_id
);
11884 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11890 /* Make the x-window of frame F use a rectangle with text.
11891 Use ICON_NAME as the text. */
11894 x_text_icon (f
, icon_name
)
11898 if (FRAME_X_WINDOW (f
) == 0)
11903 XTextProperty text
;
11904 text
.value
= (unsigned char *) icon_name
;
11905 text
.encoding
= XA_STRING
;
11907 text
.nitems
= strlen (icon_name
);
11908 #ifdef USE_X_TOOLKIT
11909 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11911 #else /* not USE_X_TOOLKIT */
11912 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11913 #endif /* not USE_X_TOOLKIT */
11915 #else /* not HAVE_X11R4 */
11916 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11917 #endif /* not HAVE_X11R4 */
11919 if (f
->output_data
.x
->icon_bitmap
> 0)
11920 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11921 f
->output_data
.x
->icon_bitmap
= 0;
11922 x_wm_set_icon_pixmap (f
, 0);
11927 #define X_ERROR_MESSAGE_SIZE 200
11929 /* If non-nil, this should be a string.
11930 It means catch X errors and store the error message in this string. */
11932 static Lisp_Object x_error_message_string
;
11934 /* An X error handler which stores the error message in
11935 x_error_message_string. This is called from x_error_handler if
11936 x_catch_errors is in effect. */
11939 x_error_catcher (display
, error
)
11941 XErrorEvent
*error
;
11943 XGetErrorText (display
, error
->error_code
,
11944 XSTRING (x_error_message_string
)->data
,
11945 X_ERROR_MESSAGE_SIZE
);
11948 /* Begin trapping X errors for display DPY. Actually we trap X errors
11949 for all displays, but DPY should be the display you are actually
11952 After calling this function, X protocol errors no longer cause
11953 Emacs to exit; instead, they are recorded in the string
11954 stored in x_error_message_string.
11956 Calling x_check_errors signals an Emacs error if an X error has
11957 occurred since the last call to x_catch_errors or x_check_errors.
11959 Calling x_uncatch_errors resumes the normal error handling. */
11961 void x_check_errors ();
11962 static Lisp_Object
x_catch_errors_unwind ();
11965 x_catch_errors (dpy
)
11968 int count
= specpdl_ptr
- specpdl
;
11970 /* Make sure any errors from previous requests have been dealt with. */
11971 XSync (dpy
, False
);
11973 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11975 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11976 XSTRING (x_error_message_string
)->data
[0] = 0;
11981 /* Unbind the binding that we made to check for X errors. */
11984 x_catch_errors_unwind (old_val
)
11985 Lisp_Object old_val
;
11987 x_error_message_string
= old_val
;
11991 /* If any X protocol errors have arrived since the last call to
11992 x_catch_errors or x_check_errors, signal an Emacs error using
11993 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11996 x_check_errors (dpy
, format
)
12000 /* Make sure to catch any errors incurred so far. */
12001 XSync (dpy
, False
);
12003 if (XSTRING (x_error_message_string
)->data
[0])
12004 error (format
, XSTRING (x_error_message_string
)->data
);
12007 /* Nonzero if we had any X protocol errors
12008 since we did x_catch_errors on DPY. */
12011 x_had_errors_p (dpy
)
12014 /* Make sure to catch any errors incurred so far. */
12015 XSync (dpy
, False
);
12017 return XSTRING (x_error_message_string
)->data
[0] != 0;
12020 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
12023 x_clear_errors (dpy
)
12026 XSTRING (x_error_message_string
)->data
[0] = 0;
12029 /* Stop catching X protocol errors and let them make Emacs die.
12030 DPY should be the display that was passed to x_catch_errors.
12031 COUNT should be the value that was returned by
12032 the corresponding call to x_catch_errors. */
12035 x_uncatch_errors (dpy
, count
)
12039 unbind_to (count
, Qnil
);
12043 static unsigned int x_wire_count
;
12046 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
12051 /* Handle SIGPIPE, which can happen when the connection to a server
12052 simply goes away. SIGPIPE is handled by x_connection_signal.
12053 Don't need to do anything, because the write which caused the
12054 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
12055 which will do the appropriate cleanup for us. */
12058 x_connection_signal (signalnum
) /* If we don't have an argument, */
12059 int signalnum
; /* some compilers complain in signal calls. */
12062 /* USG systems forget handlers when they are used;
12063 must reestablish each time */
12064 signal (signalnum
, x_connection_signal
);
12069 /************************************************************************
12071 ************************************************************************/
12073 /* Error message passed to x_connection_closed. */
12075 static char *error_msg
;
12077 /* Function installed as fatal_error_signal_hook in
12078 x_connection_closed. Print the X error message, and exit normally,
12079 instead of dumping core when XtCloseDisplay fails. */
12082 x_fatal_error_signal ()
12084 fprintf (stderr
, "%s\n", error_msg
);
12088 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
12089 the text of an error message that lead to the connection loss. */
12092 x_connection_closed (dpy
, error_message
)
12094 char *error_message
;
12096 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
12097 Lisp_Object frame
, tail
;
12100 error_msg
= (char *) alloca (strlen (error_message
) + 1);
12101 strcpy (error_msg
, error_message
);
12102 handling_signal
= 0;
12104 /* Prevent being called recursively because of an error condition
12105 below. Otherwise, we might end up with printing ``can't find per
12106 display information'' in the recursive call instead of printing
12107 the original message here. */
12108 count
= x_catch_errors (dpy
);
12110 /* We have to close the display to inform Xt that it doesn't
12111 exist anymore. If we don't, Xt will continue to wait for
12112 events from the display. As a consequence, a sequence of
12114 M-x make-frame-on-display RET :1 RET
12115 ...kill the new frame, so that we get an IO error...
12116 M-x make-frame-on-display RET :1 RET
12118 will indefinitely wait in Xt for events for display `:1', opened
12119 in the first class to make-frame-on-display.
12121 Closing the display is reported to lead to a bus error on
12122 OpenWindows in certain situations. I suspect that is a bug
12123 in OpenWindows. I don't know how to cicumvent it here. */
12125 #ifdef USE_X_TOOLKIT
12126 /* If DPYINFO is null, this means we didn't open the display
12127 in the first place, so don't try to close it. */
12130 extern void (*fatal_error_signal_hook
) P_ ((void));
12131 fatal_error_signal_hook
= x_fatal_error_signal
;
12132 XtCloseDisplay (dpy
);
12133 fatal_error_signal_hook
= NULL
;
12137 /* Indicate that this display is dead. */
12139 dpyinfo
->display
= 0;
12141 /* First delete frames whose mini-buffers are on frames
12142 that are on the dead display. */
12143 FOR_EACH_FRAME (tail
, frame
)
12145 Lisp_Object minibuf_frame
;
12147 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
12148 if (FRAME_X_P (XFRAME (frame
))
12149 && FRAME_X_P (XFRAME (minibuf_frame
))
12150 && ! EQ (frame
, minibuf_frame
)
12151 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
12152 Fdelete_frame (frame
, Qt
);
12155 /* Now delete all remaining frames on the dead display.
12156 We are now sure none of these is used as the mini-buffer
12157 for another frame that we need to delete. */
12158 FOR_EACH_FRAME (tail
, frame
)
12159 if (FRAME_X_P (XFRAME (frame
))
12160 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
12162 /* Set this to t so that Fdelete_frame won't get confused
12163 trying to find a replacement. */
12164 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
12165 Fdelete_frame (frame
, Qt
);
12169 x_delete_display (dpyinfo
);
12171 x_uncatch_errors (dpy
, count
);
12173 if (x_display_list
== 0)
12175 fprintf (stderr
, "%s\n", error_msg
);
12176 shut_down_emacs (0, 0, Qnil
);
12180 /* Ordinary stack unwind doesn't deal with these. */
12182 sigunblock (sigmask (SIGIO
));
12184 sigunblock (sigmask (SIGALRM
));
12185 TOTALLY_UNBLOCK_INPUT
;
12187 clear_waiting_for_input ();
12188 error ("%s", error_msg
);
12192 /* This is the usual handler for X protocol errors.
12193 It kills all frames on the display that we got the error for.
12194 If that was the only one, it prints an error message and kills Emacs. */
12197 x_error_quitter (display
, error
)
12199 XErrorEvent
*error
;
12201 char buf
[256], buf1
[356];
12203 /* Note that there is no real way portable across R3/R4 to get the
12204 original error handler. */
12206 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
12207 sprintf (buf1
, "X protocol error: %s on protocol request %d",
12208 buf
, error
->request_code
);
12209 x_connection_closed (display
, buf1
);
12213 /* This is the first-level handler for X protocol errors.
12214 It calls x_error_quitter or x_error_catcher. */
12217 x_error_handler (display
, error
)
12219 XErrorEvent
*error
;
12221 if (! NILP (x_error_message_string
))
12222 x_error_catcher (display
, error
);
12224 x_error_quitter (display
, error
);
12228 /* This is the handler for X IO errors, always.
12229 It kills all frames on the display that we lost touch with.
12230 If that was the only one, it prints an error message and kills Emacs. */
12233 x_io_error_quitter (display
)
12238 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
12239 x_connection_closed (display
, buf
);
12243 /* Changing the font of the frame. */
12245 /* Give frame F the font named FONTNAME as its default font, and
12246 return the full name of that font. FONTNAME may be a wildcard
12247 pattern; in that case, we choose some font that fits the pattern.
12248 The return value shows which font we chose. */
12251 x_new_font (f
, fontname
)
12253 register char *fontname
;
12255 struct font_info
*fontp
12256 = FS_LOAD_FONT (f
, fontname
);
12261 if (f
->output_data
.x
->font
== (XFontStruct
*) (fontp
->font
))
12262 /* This font is already set in frame F. There's nothing more to
12264 return build_string (fontp
->full_name
);
12266 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
12267 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
12268 f
->output_data
.x
->fontset
= -1;
12270 x_compute_fringe_widths (f
, 1);
12272 /* Compute the scroll bar width in character columns. */
12273 if (f
->scroll_bar_pixel_width
> 0)
12275 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12276 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
12280 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12281 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
12284 /* Now make the frame display the given font. */
12285 if (FRAME_X_WINDOW (f
) != 0)
12287 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
12288 f
->output_data
.x
->font
->fid
);
12289 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
12290 f
->output_data
.x
->font
->fid
);
12291 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
12292 f
->output_data
.x
->font
->fid
);
12294 frame_update_line_height (f
);
12296 /* Don't change the size of a tip frame; there's no point in
12297 doing it because it's done in Fx_show_tip, and it leads to
12298 problems because the tip frame has no widget. */
12299 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
12300 x_set_window_size (f
, 0, f
->width
, f
->height
);
12303 /* If we are setting a new frame's font for the first time,
12304 there are no faces yet, so this font's height is the line height. */
12305 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
12307 return build_string (fontp
->full_name
);
12310 /* Give frame F the fontset named FONTSETNAME as its default fontset,
12311 and return the full name of that fontset. FONTSETNAME may be a
12312 wildcard pattern; in that case, we choose some fontset that fits
12313 the pattern. FONTSETNAME may be a font name for ASCII characters;
12314 in that case, we create a fontset from that font name.
12316 The return value shows which fontset we chose.
12317 If FONTSETNAME specifies the default fontset, return Qt.
12318 If an ASCII font in the specified fontset can't be loaded, return
12322 x_new_fontset (f
, fontsetname
)
12324 Lisp_Object fontsetname
;
12326 int fontset
= fs_query_fontset (fontsetname
, 0);
12327 Lisp_Object result
;
12329 if (fontset
> 0 && f
->output_data
.x
->fontset
== fontset
)
12330 /* This fontset is already set in frame F. There's nothing more
12332 return fontset_name (fontset
);
12333 else if (fontset
== 0)
12334 /* The default fontset can't be the default font. */
12338 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
12340 result
= x_new_font (f
, XSTRING (fontsetname
)->data
);
12342 if (!STRINGP (result
))
12343 /* Can't load ASCII font. */
12347 fontset
= new_fontset_from_font_name (result
);
12349 /* Since x_new_font doesn't update any fontset information, do it now. */
12350 f
->output_data
.x
->fontset
= fontset
;
12354 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
12355 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
12358 return fontset_name (fontset
);
12361 /* Compute actual fringe widths */
12364 x_compute_fringe_widths (f
, redraw
)
12368 int o_left
= f
->output_data
.x
->left_fringe_width
;
12369 int o_right
= f
->output_data
.x
->right_fringe_width
;
12370 int o_cols
= f
->output_data
.x
->fringe_cols
;
12372 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
12373 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
12374 int left_fringe_width
, right_fringe_width
;
12376 if (!NILP (left_fringe
))
12377 left_fringe
= Fcdr (left_fringe
);
12378 if (!NILP (right_fringe
))
12379 right_fringe
= Fcdr (right_fringe
);
12381 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
12382 XINT (left_fringe
));
12383 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
12384 XINT (right_fringe
));
12386 if (left_fringe_width
|| right_fringe_width
)
12388 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
12389 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
12390 int conf_wid
= left_wid
+ right_wid
;
12391 int font_wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12392 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
12393 int real_wid
= cols
* font_wid
;
12394 if (left_wid
&& right_wid
)
12396 if (left_fringe_width
< 0)
12398 /* Left fringe width is fixed, adjust right fringe if necessary */
12399 f
->output_data
.x
->left_fringe_width
= left_wid
;
12400 f
->output_data
.x
->right_fringe_width
= real_wid
- left_wid
;
12402 else if (right_fringe_width
< 0)
12404 /* Right fringe width is fixed, adjust left fringe if necessary */
12405 f
->output_data
.x
->left_fringe_width
= real_wid
- right_wid
;
12406 f
->output_data
.x
->right_fringe_width
= right_wid
;
12410 /* Adjust both fringes with an equal amount.
12411 Note that we are doing integer arithmetic here, so don't
12412 lose a pixel if the total width is an odd number. */
12413 int fill
= real_wid
- conf_wid
;
12414 f
->output_data
.x
->left_fringe_width
= left_wid
+ fill
/2;
12415 f
->output_data
.x
->right_fringe_width
= right_wid
+ fill
- fill
/2;
12418 else if (left_fringe_width
)
12420 f
->output_data
.x
->left_fringe_width
= real_wid
;
12421 f
->output_data
.x
->right_fringe_width
= 0;
12425 f
->output_data
.x
->left_fringe_width
= 0;
12426 f
->output_data
.x
->right_fringe_width
= real_wid
;
12428 f
->output_data
.x
->fringe_cols
= cols
;
12429 f
->output_data
.x
->fringes_extra
= real_wid
;
12433 f
->output_data
.x
->left_fringe_width
= 0;
12434 f
->output_data
.x
->right_fringe_width
= 0;
12435 f
->output_data
.x
->fringe_cols
= 0;
12436 f
->output_data
.x
->fringes_extra
= 0;
12439 if (redraw
&& FRAME_VISIBLE_P (f
))
12440 if (o_left
!= f
->output_data
.x
->left_fringe_width
||
12441 o_right
!= f
->output_data
.x
->right_fringe_width
||
12442 o_cols
!= f
->output_data
.x
->fringe_cols
)
12446 /***********************************************************************
12448 ***********************************************************************/
12454 /* XIM destroy callback function, which is called whenever the
12455 connection to input method XIM dies. CLIENT_DATA contains a
12456 pointer to the x_display_info structure corresponding to XIM. */
12459 xim_destroy_callback (xim
, client_data
, call_data
)
12461 XPointer client_data
;
12462 XPointer call_data
;
12464 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
12465 Lisp_Object frame
, tail
;
12469 /* No need to call XDestroyIC.. */
12470 FOR_EACH_FRAME (tail
, frame
)
12472 struct frame
*f
= XFRAME (frame
);
12473 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
12475 FRAME_XIC (f
) = NULL
;
12476 if (FRAME_XIC_FONTSET (f
))
12478 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
12479 FRAME_XIC_FONTSET (f
) = NULL
;
12484 /* No need to call XCloseIM. */
12485 dpyinfo
->xim
= NULL
;
12486 XFree (dpyinfo
->xim_styles
);
12490 #endif /* HAVE_X11R6 */
12492 /* Open the connection to the XIM server on display DPYINFO.
12493 RESOURCE_NAME is the resource name Emacs uses. */
12496 xim_open_dpy (dpyinfo
, resource_name
)
12497 struct x_display_info
*dpyinfo
;
12498 char *resource_name
;
12504 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
12506 dpyinfo
->xim
= xim
;
12511 XIMCallback destroy
;
12514 /* Get supported styles and XIM values. */
12515 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
12518 destroy
.callback
= xim_destroy_callback
;
12519 destroy
.client_data
= (XPointer
)dpyinfo
;
12520 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
12525 dpyinfo
->xim
= NULL
;
12529 #ifdef HAVE_X11R6_XIM
12533 struct x_display_info
*dpyinfo
;
12534 char *resource_name
;
12537 /* XIM instantiate callback function, which is called whenever an XIM
12538 server is available. DISPLAY is teh display of the XIM.
12539 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12540 when the callback was registered. */
12543 xim_instantiate_callback (display
, client_data
, call_data
)
12545 XPointer client_data
;
12546 XPointer call_data
;
12548 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12549 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12551 /* We don't support multiple XIM connections. */
12555 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12557 /* Create XIC for the existing frames on the same display, as long
12558 as they have no XIC. */
12559 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12561 Lisp_Object tail
, frame
;
12564 FOR_EACH_FRAME (tail
, frame
)
12566 struct frame
*f
= XFRAME (frame
);
12568 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12569 if (FRAME_XIC (f
) == NULL
)
12571 create_frame_xic (f
);
12572 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12573 xic_set_statusarea (f
);
12574 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12576 struct window
*w
= XWINDOW (f
->selected_window
);
12577 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12586 #endif /* HAVE_X11R6_XIM */
12589 /* Open a connection to the XIM server on display DPYINFO.
12590 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12591 connection only at the first time. On X11R6, open the connection
12592 in the XIM instantiate callback function. */
12595 xim_initialize (dpyinfo
, resource_name
)
12596 struct x_display_info
*dpyinfo
;
12597 char *resource_name
;
12601 #ifdef HAVE_X11R6_XIM
12602 struct xim_inst_t
*xim_inst
;
12605 dpyinfo
->xim
= NULL
;
12606 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12607 xim_inst
->dpyinfo
= dpyinfo
;
12608 len
= strlen (resource_name
);
12609 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12610 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12611 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12612 resource_name
, EMACS_CLASS
,
12613 xim_instantiate_callback
,
12614 /* Fixme: This is XPointer in
12615 XFree86 but (XPointer *) on
12616 Tru64, at least. */
12617 (XPointer
) xim_inst
);
12618 #else /* not HAVE_X11R6_XIM */
12619 dpyinfo
->xim
= NULL
;
12620 xim_open_dpy (dpyinfo
, resource_name
);
12621 #endif /* not HAVE_X11R6_XIM */
12624 dpyinfo
->xim
= NULL
;
12628 /* Close the connection to the XIM server on display DPYINFO. */
12631 xim_close_dpy (dpyinfo
)
12632 struct x_display_info
*dpyinfo
;
12636 #ifdef HAVE_X11R6_XIM
12637 if (dpyinfo
->display
)
12638 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12640 xim_instantiate_callback
, NULL
);
12641 #endif /* not HAVE_X11R6_XIM */
12642 if (dpyinfo
->display
)
12643 XCloseIM (dpyinfo
->xim
);
12644 dpyinfo
->xim
= NULL
;
12645 XFree (dpyinfo
->xim_styles
);
12649 #endif /* not HAVE_X11R6_XIM */
12653 /* Calculate the absolute position in frame F
12654 from its current recorded position values and gravity. */
12657 x_calc_absolute_position (f
)
12661 int win_x
= 0, win_y
= 0;
12662 int flags
= f
->output_data
.x
->size_hint_flags
;
12665 /* We have nothing to do if the current position
12666 is already for the top-left corner. */
12667 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12670 #ifdef USE_X_TOOLKIT
12671 this_window
= XtWindow (f
->output_data
.x
->widget
);
12673 this_window
= FRAME_X_WINDOW (f
);
12676 /* Find the position of the outside upper-left corner of
12677 the inner window, with respect to the outer window.
12678 But do this only if we will need the results. */
12679 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12684 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12687 x_clear_errors (FRAME_X_DISPLAY (f
));
12688 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12690 /* From-window, to-window. */
12692 f
->output_data
.x
->parent_desc
,
12694 /* From-position, to-position. */
12695 0, 0, &win_x
, &win_y
,
12697 /* Child of win. */
12699 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12701 Window newroot
, newparent
= 0xdeadbeef;
12702 Window
*newchildren
;
12703 unsigned int nchildren
;
12705 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12706 &newparent
, &newchildren
, &nchildren
))
12709 XFree ((char *) newchildren
);
12711 f
->output_data
.x
->parent_desc
= newparent
;
12717 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12721 /* Treat negative positions as relative to the leftmost bottommost
12722 position that fits on the screen. */
12723 if (flags
& XNegative
)
12724 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12725 - 2 * f
->output_data
.x
->border_width
- win_x
12727 + f
->output_data
.x
->left_pos
);
12730 int height
= PIXEL_HEIGHT (f
);
12732 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12733 /* Something is fishy here. When using Motif, starting Emacs with
12734 `-g -0-0', the frame appears too low by a few pixels.
12736 This seems to be so because initially, while Emacs is starting,
12737 the column widget's height and the frame's pixel height are
12738 different. The column widget's height is the right one. In
12739 later invocations, when Emacs is up, the frame's pixel height
12742 It's not obvious where the initial small difference comes from.
12743 2000-12-01, gerd. */
12745 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12748 if (flags
& YNegative
)
12749 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12750 - 2 * f
->output_data
.x
->border_width
12753 + f
->output_data
.x
->top_pos
);
12756 /* The left_pos and top_pos
12757 are now relative to the top and left screen edges,
12758 so the flags should correspond. */
12759 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12762 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12763 to really change the position, and 0 when calling from
12764 x_make_frame_visible (in that case, XOFF and YOFF are the current
12765 position values). It is -1 when calling from x_set_frame_parameters,
12766 which means, do adjust for borders but don't change the gravity. */
12769 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12771 register int xoff
, yoff
;
12772 int change_gravity
;
12774 int modified_top
, modified_left
;
12776 if (change_gravity
> 0)
12778 f
->output_data
.x
->top_pos
= yoff
;
12779 f
->output_data
.x
->left_pos
= xoff
;
12780 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12782 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12784 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12785 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12787 x_calc_absolute_position (f
);
12790 x_wm_set_size_hint (f
, (long) 0, 0);
12792 modified_left
= f
->output_data
.x
->left_pos
;
12793 modified_top
= f
->output_data
.x
->top_pos
;
12794 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12795 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12796 /* It is a mystery why we need to add the border_width here
12797 when the frame is already visible, but experiment says we do. */
12798 if (change_gravity
!= 0)
12800 modified_left
+= f
->output_data
.x
->border_width
;
12801 modified_top
+= f
->output_data
.x
->border_width
;
12805 #ifdef USE_X_TOOLKIT
12806 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12807 modified_left
, modified_top
);
12808 #else /* not USE_X_TOOLKIT */
12809 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12810 modified_left
, modified_top
);
12811 #endif /* not USE_X_TOOLKIT */
12815 /* Check if we need to resize the frame due to a fullscreen request.
12816 If so needed, resize the frame. */
12818 x_check_fullscreen (f
)
12821 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
12823 int width
, height
, ign
;
12825 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
12826 &f
->output_data
.x
->top_pos
);
12828 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
12830 /* We do not need to move the window, it shall be taken care of
12831 when setting WM manager hints.
12832 If the frame is visible already, the position is checked by
12833 x_check_fullscreen_move. */
12834 if (f
->width
!= width
|| f
->height
!= height
)
12836 change_frame_size (f
, height
, width
, 0, 1, 0);
12837 SET_FRAME_GARBAGED (f
);
12838 cancel_mouse_face (f
);
12840 /* Wait for the change of frame size to occur */
12841 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
12847 /* If frame parameters are set after the frame is mapped, we need to move
12848 the window. This is done in xfns.c.
12849 Some window managers moves the window to the right position, some
12850 moves the outer window manager window to the specified position.
12851 Here we check that we are in the right spot. If not, make a second
12852 move, assuming we are dealing with the second kind of window manager. */
12854 x_check_fullscreen_move (f
)
12857 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
12859 int expect_top
= f
->output_data
.x
->top_pos
;
12860 int expect_left
= f
->output_data
.x
->left_pos
;
12862 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
12864 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
12867 if (expect_top
!= f
->output_data
.x
->top_pos
12868 || expect_left
!= f
->output_data
.x
->left_pos
)
12869 x_set_offset (f
, expect_left
, expect_top
, 1);
12871 /* Just do this once */
12872 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
12877 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
12878 wanted positions of the WM window (not emacs window).
12879 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
12880 window (FRAME_X_WINDOW).
12883 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
12890 int newwidth
= f
->width
, newheight
= f
->height
;
12892 *top_pos
= f
->output_data
.x
->top_pos
;
12893 *left_pos
= f
->output_data
.x
->left_pos
;
12895 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
12899 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
12900 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
12901 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
12902 - f
->output_data
.x
->y_pixels_diff
;
12903 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
12907 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
12911 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
12912 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
12913 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
12914 - f
->output_data
.x
->x_pixels_diff
;
12915 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
12920 *height
= newheight
;
12924 /* Change the size of frame F's X window to COLS/ROWS in the case F
12925 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12926 top-left-corner window gravity for this size change and subsequent
12927 size changes. Otherwise we leave the window gravity unchanged. */
12930 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12932 int change_gravity
;
12935 int pixelwidth
, pixelheight
;
12937 check_frame_size (f
, &rows
, &cols
);
12938 f
->output_data
.x
->vertical_scroll_bar_extra
12939 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12941 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12942 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12943 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12945 x_compute_fringe_widths (f
, 0);
12947 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12948 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12950 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12951 x_wm_set_size_hint (f
, (long) 0, 0);
12953 XSync (FRAME_X_DISPLAY (f
), False
);
12954 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12955 pixelwidth
, pixelheight
);
12957 /* Now, strictly speaking, we can't be sure that this is accurate,
12958 but the window manager will get around to dealing with the size
12959 change request eventually, and we'll hear how it went when the
12960 ConfigureNotify event gets here.
12962 We could just not bother storing any of this information here,
12963 and let the ConfigureNotify event set everything up, but that
12964 might be kind of confusing to the Lisp code, since size changes
12965 wouldn't be reported in the frame parameters until some random
12966 point in the future when the ConfigureNotify event arrives.
12968 We pass 1 for DELAY since we can't run Lisp code inside of
12970 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12971 PIXEL_WIDTH (f
) = pixelwidth
;
12972 PIXEL_HEIGHT (f
) = pixelheight
;
12974 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12975 receive in the ConfigureNotify event; if we get what we asked
12976 for, then the event won't cause the screen to become garbaged, so
12977 we have to make sure to do it here. */
12978 SET_FRAME_GARBAGED (f
);
12980 XFlush (FRAME_X_DISPLAY (f
));
12984 /* Call this to change the size of frame F's x-window.
12985 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12986 for this size change and subsequent size changes.
12987 Otherwise we leave the window gravity unchanged. */
12990 x_set_window_size (f
, change_gravity
, cols
, rows
)
12992 int change_gravity
;
12997 #ifdef USE_X_TOOLKIT
12999 if (f
->output_data
.x
->widget
!= NULL
)
13001 /* The x and y position of the widget is clobbered by the
13002 call to XtSetValues within EmacsFrameSetCharSize.
13003 This is a real kludge, but I don't understand Xt so I can't
13004 figure out a correct fix. Can anyone else tell me? -- rms. */
13005 int xpos
= f
->output_data
.x
->widget
->core
.x
;
13006 int ypos
= f
->output_data
.x
->widget
->core
.y
;
13007 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
13008 f
->output_data
.x
->widget
->core
.x
= xpos
;
13009 f
->output_data
.x
->widget
->core
.y
= ypos
;
13012 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13014 #else /* not USE_X_TOOLKIT */
13016 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13018 #endif /* not USE_X_TOOLKIT */
13020 /* If cursor was outside the new size, mark it as off. */
13021 mark_window_cursors_off (XWINDOW (f
->root_window
));
13023 /* Clear out any recollection of where the mouse highlighting was,
13024 since it might be in a place that's outside the new frame size.
13025 Actually checking whether it is outside is a pain in the neck,
13026 so don't try--just let the highlighting be done afresh with new size. */
13027 cancel_mouse_face (f
);
13032 /* Mouse warping. */
13035 x_set_mouse_position (f
, x
, y
)
13041 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
13042 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
13044 if (pix_x
< 0) pix_x
= 0;
13045 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
13047 if (pix_y
< 0) pix_y
= 0;
13048 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
13052 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13053 0, 0, 0, 0, pix_x
, pix_y
);
13057 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
13060 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
13066 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13067 0, 0, 0, 0, pix_x
, pix_y
);
13071 /* focus shifting, raising and lowering. */
13074 x_focus_on_frame (f
)
13077 #if 0 /* This proves to be unpleasant. */
13081 /* I don't think that the ICCCM allows programs to do things like this
13082 without the interaction of the window manager. Whatever you end up
13083 doing with this code, do it to x_unfocus_frame too. */
13084 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13085 RevertToPointerRoot
, CurrentTime
);
13090 x_unfocus_frame (f
)
13094 /* Look at the remarks in x_focus_on_frame. */
13095 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
13096 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
13097 RevertToPointerRoot
, CurrentTime
);
13101 /* Raise frame F. */
13107 if (f
->async_visible
)
13110 #ifdef USE_X_TOOLKIT
13111 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13112 #else /* not USE_X_TOOLKIT */
13113 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13114 #endif /* not USE_X_TOOLKIT */
13115 XFlush (FRAME_X_DISPLAY (f
));
13120 /* Lower frame F. */
13126 if (f
->async_visible
)
13129 #ifdef USE_X_TOOLKIT
13130 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13131 #else /* not USE_X_TOOLKIT */
13132 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13133 #endif /* not USE_X_TOOLKIT */
13134 XFlush (FRAME_X_DISPLAY (f
));
13140 XTframe_raise_lower (f
, raise_flag
)
13150 /* Change of visibility. */
13152 /* This tries to wait until the frame is really visible.
13153 However, if the window manager asks the user where to position
13154 the frame, this will return before the user finishes doing that.
13155 The frame will not actually be visible at that time,
13156 but it will become visible later when the window manager
13157 finishes with it. */
13160 x_make_frame_visible (f
)
13164 int original_top
, original_left
;
13165 int retry_count
= 2;
13171 type
= x_icon_type (f
);
13173 x_bitmap_icon (f
, type
);
13175 if (! FRAME_VISIBLE_P (f
))
13177 /* We test FRAME_GARBAGED_P here to make sure we don't
13178 call x_set_offset a second time
13179 if we get to x_make_frame_visible a second time
13180 before the window gets really visible. */
13181 if (! FRAME_ICONIFIED_P (f
)
13182 && ! f
->output_data
.x
->asked_for_visible
)
13183 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13185 f
->output_data
.x
->asked_for_visible
= 1;
13187 if (! EQ (Vx_no_window_manager
, Qt
))
13188 x_wm_set_window_state (f
, NormalState
);
13189 #ifdef USE_X_TOOLKIT
13190 /* This was XtPopup, but that did nothing for an iconified frame. */
13191 XtMapWidget (f
->output_data
.x
->widget
);
13192 #else /* not USE_X_TOOLKIT */
13193 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13194 #endif /* not USE_X_TOOLKIT */
13195 #if 0 /* This seems to bring back scroll bars in the wrong places
13196 if the window configuration has changed. They seem
13197 to come back ok without this. */
13198 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
13199 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13203 XFlush (FRAME_X_DISPLAY (f
));
13205 /* Synchronize to ensure Emacs knows the frame is visible
13206 before we do anything else. We do this loop with input not blocked
13207 so that incoming events are handled. */
13211 /* This must be before UNBLOCK_INPUT
13212 since events that arrive in response to the actions above
13213 will set it when they are handled. */
13214 int previously_visible
= f
->output_data
.x
->has_been_visible
;
13216 original_left
= f
->output_data
.x
->left_pos
;
13217 original_top
= f
->output_data
.x
->top_pos
;
13219 /* This must come after we set COUNT. */
13222 /* We unblock here so that arriving X events are processed. */
13224 /* Now move the window back to where it was "supposed to be".
13225 But don't do it if the gravity is negative.
13226 When the gravity is negative, this uses a position
13227 that is 3 pixels too low. Perhaps that's really the border width.
13229 Don't do this if the window has never been visible before,
13230 because the window manager may choose the position
13231 and we don't want to override it. */
13233 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
13234 && f
->output_data
.x
->win_gravity
== NorthWestGravity
13235 && previously_visible
)
13239 unsigned int width
, height
, border
, depth
;
13243 /* On some window managers (such as FVWM) moving an existing
13244 window, even to the same place, causes the window manager
13245 to introduce an offset. This can cause the window to move
13246 to an unexpected location. Check the geometry (a little
13247 slow here) and then verify that the window is in the right
13248 place. If the window is not in the right place, move it
13249 there, and take the potential window manager hit. */
13250 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13251 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
13253 if (original_left
!= x
|| original_top
!= y
)
13254 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13255 original_left
, original_top
);
13260 XSETFRAME (frame
, f
);
13262 /* Wait until the frame is visible. Process X events until a
13263 MapNotify event has been seen, or until we think we won't get a
13264 MapNotify at all.. */
13265 for (count
= input_signal_count
+ 10;
13266 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
13268 /* Force processing of queued events. */
13271 /* Machines that do polling rather than SIGIO have been
13272 observed to go into a busy-wait here. So we'll fake an
13273 alarm signal to let the handler know that there's something
13274 to be read. We used to raise a real alarm, but it seems
13275 that the handler isn't always enabled here. This is
13277 if (input_polling_used ())
13279 /* It could be confusing if a real alarm arrives while
13280 processing the fake one. Turn it off and let the
13281 handler reset it. */
13282 extern void poll_for_input_1
P_ ((void));
13283 int old_poll_suppress_count
= poll_suppress_count
;
13284 poll_suppress_count
= 1;
13285 poll_for_input_1 ();
13286 poll_suppress_count
= old_poll_suppress_count
;
13289 /* See if a MapNotify event has been processed. */
13290 FRAME_SAMPLE_VISIBILITY (f
);
13295 (let ((f (selected-frame)))
13299 the frame is not raised with various window managers on
13300 FreeBSD, Linux and Solaris. It turns out that, for some
13301 unknown reason, the call to XtMapWidget is completely ignored.
13302 Mapping the widget a second time works. */
13304 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
13309 /* Change from mapped state to withdrawn state. */
13311 /* Make the frame visible (mapped and not iconified). */
13314 x_make_frame_invisible (f
)
13319 #ifdef USE_X_TOOLKIT
13320 /* Use the frame's outermost window, not the one we normally draw on. */
13321 window
= XtWindow (f
->output_data
.x
->widget
);
13322 #else /* not USE_X_TOOLKIT */
13323 window
= FRAME_X_WINDOW (f
);
13324 #endif /* not USE_X_TOOLKIT */
13326 /* Don't keep the highlight on an invisible frame. */
13327 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13328 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13330 #if 0/* This might add unreliability; I don't trust it -- rms. */
13331 if (! f
->async_visible
&& ! f
->async_iconified
)
13337 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
13338 that the current position of the window is user-specified, rather than
13339 program-specified, so that when the window is mapped again, it will be
13340 placed at the same location, without forcing the user to position it
13341 by hand again (they have already done that once for this window.) */
13342 x_wm_set_size_hint (f
, (long) 0, 1);
13346 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
13347 DefaultScreen (FRAME_X_DISPLAY (f
))))
13349 UNBLOCK_INPUT_RESIGNAL
;
13350 error ("Can't notify window manager of window withdrawal");
13352 #else /* ! defined (HAVE_X11R4) */
13354 /* Tell the window manager what we're going to do. */
13355 if (! EQ (Vx_no_window_manager
, Qt
))
13359 unmap
.xunmap
.type
= UnmapNotify
;
13360 unmap
.xunmap
.window
= window
;
13361 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
13362 unmap
.xunmap
.from_configure
= False
;
13363 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13364 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13366 SubstructureRedirectMaskSubstructureNotifyMask
,
13369 UNBLOCK_INPUT_RESIGNAL
;
13370 error ("Can't notify window manager of withdrawal");
13374 /* Unmap the window ourselves. Cheeky! */
13375 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
13376 #endif /* ! defined (HAVE_X11R4) */
13378 /* We can't distinguish this from iconification
13379 just by the event that we get from the server.
13380 So we can't win using the usual strategy of letting
13381 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
13382 and synchronize with the server to make sure we agree. */
13384 FRAME_ICONIFIED_P (f
) = 0;
13385 f
->async_visible
= 0;
13386 f
->async_iconified
= 0;
13393 /* Change window state from mapped to iconified. */
13396 x_iconify_frame (f
)
13402 /* Don't keep the highlight on an invisible frame. */
13403 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13404 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13406 if (f
->async_iconified
)
13411 FRAME_SAMPLE_VISIBILITY (f
);
13413 type
= x_icon_type (f
);
13415 x_bitmap_icon (f
, type
);
13417 #ifdef USE_X_TOOLKIT
13419 if (! FRAME_VISIBLE_P (f
))
13421 if (! EQ (Vx_no_window_manager
, Qt
))
13422 x_wm_set_window_state (f
, IconicState
);
13423 /* This was XtPopup, but that did nothing for an iconified frame. */
13424 XtMapWidget (f
->output_data
.x
->widget
);
13425 /* The server won't give us any event to indicate
13426 that an invisible frame was changed to an icon,
13427 so we have to record it here. */
13430 f
->async_iconified
= 1;
13431 f
->async_visible
= 0;
13436 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
13437 XtWindow (f
->output_data
.x
->widget
),
13438 DefaultScreen (FRAME_X_DISPLAY (f
)));
13442 error ("Can't notify window manager of iconification");
13444 f
->async_iconified
= 1;
13445 f
->async_visible
= 0;
13449 XFlush (FRAME_X_DISPLAY (f
));
13451 #else /* not USE_X_TOOLKIT */
13453 /* Make sure the X server knows where the window should be positioned,
13454 in case the user deiconifies with the window manager. */
13455 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
13456 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13458 /* Since we don't know which revision of X we're running, we'll use both
13459 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
13461 /* X11R4: send a ClientMessage to the window manager using the
13462 WM_CHANGE_STATE type. */
13466 message
.xclient
.window
= FRAME_X_WINDOW (f
);
13467 message
.xclient
.type
= ClientMessage
;
13468 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
13469 message
.xclient
.format
= 32;
13470 message
.xclient
.data
.l
[0] = IconicState
;
13472 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13473 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13475 SubstructureRedirectMask
| SubstructureNotifyMask
,
13478 UNBLOCK_INPUT_RESIGNAL
;
13479 error ("Can't notify window manager of iconification");
13483 /* X11R3: set the initial_state field of the window manager hints to
13485 x_wm_set_window_state (f
, IconicState
);
13487 if (!FRAME_VISIBLE_P (f
))
13489 /* If the frame was withdrawn, before, we must map it. */
13490 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13493 f
->async_iconified
= 1;
13494 f
->async_visible
= 0;
13496 XFlush (FRAME_X_DISPLAY (f
));
13498 #endif /* not USE_X_TOOLKIT */
13502 /* Free X resources of frame F. */
13505 x_free_frame_resources (f
)
13508 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13510 struct scroll_bar
*b
;
13514 /* If a display connection is dead, don't try sending more
13515 commands to the X server. */
13516 if (dpyinfo
->display
)
13518 if (f
->output_data
.x
->icon_desc
)
13519 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
13521 #ifdef USE_X_TOOLKIT
13522 /* Explicitly destroy the scroll bars of the frame. Without
13523 this, we get "BadDrawable" errors from the toolkit later on,
13524 presumably from expose events generated for the disappearing
13525 toolkit scroll bars. */
13526 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
13528 b
= XSCROLL_BAR (bar
);
13529 x_scroll_bar_remove (b
);
13535 free_frame_xic (f
);
13538 #ifdef USE_X_TOOLKIT
13539 if (f
->output_data
.x
->widget
)
13541 XtDestroyWidget (f
->output_data
.x
->widget
);
13542 f
->output_data
.x
->widget
= NULL
;
13544 /* Tooltips don't have widgets, only a simple X window, even if
13545 we are using a toolkit. */
13546 else if (FRAME_X_WINDOW (f
))
13547 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13549 free_frame_menubar (f
);
13550 #else /* !USE_X_TOOLKIT */
13551 if (FRAME_X_WINDOW (f
))
13552 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13553 #endif /* !USE_X_TOOLKIT */
13555 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
13556 unload_color (f
, f
->output_data
.x
->background_pixel
);
13557 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
13558 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
13559 unload_color (f
, f
->output_data
.x
->border_pixel
);
13560 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
13562 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
13563 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
13564 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
13565 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
13566 #ifdef USE_TOOLKIT_SCROLL_BARS
13567 /* Scrollbar shadow colors. */
13568 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
13569 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
13570 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
13571 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
13572 #endif /* USE_TOOLKIT_SCROLL_BARS */
13573 if (f
->output_data
.x
->white_relief
.allocated_p
)
13574 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
13575 if (f
->output_data
.x
->black_relief
.allocated_p
)
13576 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
13578 if (FRAME_FACE_CACHE (f
))
13579 free_frame_faces (f
);
13582 XFlush (FRAME_X_DISPLAY (f
));
13585 if (f
->output_data
.x
->saved_menu_event
)
13586 xfree (f
->output_data
.x
->saved_menu_event
);
13588 xfree (f
->output_data
.x
);
13589 f
->output_data
.x
= NULL
;
13591 if (f
== dpyinfo
->x_focus_frame
)
13592 dpyinfo
->x_focus_frame
= 0;
13593 if (f
== dpyinfo
->x_focus_event_frame
)
13594 dpyinfo
->x_focus_event_frame
= 0;
13595 if (f
== dpyinfo
->x_highlight_frame
)
13596 dpyinfo
->x_highlight_frame
= 0;
13598 if (f
== dpyinfo
->mouse_face_mouse_frame
)
13600 dpyinfo
->mouse_face_beg_row
13601 = dpyinfo
->mouse_face_beg_col
= -1;
13602 dpyinfo
->mouse_face_end_row
13603 = dpyinfo
->mouse_face_end_col
= -1;
13604 dpyinfo
->mouse_face_window
= Qnil
;
13605 dpyinfo
->mouse_face_deferred_gc
= 0;
13606 dpyinfo
->mouse_face_mouse_frame
= 0;
13613 /* Destroy the X window of frame F. */
13616 x_destroy_window (f
)
13619 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13621 /* If a display connection is dead, don't try sending more
13622 commands to the X server. */
13623 if (dpyinfo
->display
!= 0)
13624 x_free_frame_resources (f
);
13626 dpyinfo
->reference_count
--;
13630 /* Setting window manager hints. */
13632 /* Set the normal size hints for the window manager, for frame F.
13633 FLAGS is the flags word to use--or 0 meaning preserve the flags
13634 that the window now has.
13635 If USER_POSITION is nonzero, we set the USPosition
13636 flag (this is useful when FLAGS is 0). */
13639 x_wm_set_size_hint (f
, flags
, user_position
)
13644 XSizeHints size_hints
;
13646 #ifdef USE_X_TOOLKIT
13649 Dimension widget_width
, widget_height
;
13650 Window window
= XtWindow (f
->output_data
.x
->widget
);
13651 #else /* not USE_X_TOOLKIT */
13652 Window window
= FRAME_X_WINDOW (f
);
13653 #endif /* not USE_X_TOOLKIT */
13655 /* Setting PMaxSize caused various problems. */
13656 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
13658 size_hints
.x
= f
->output_data
.x
->left_pos
;
13659 size_hints
.y
= f
->output_data
.x
->top_pos
;
13661 #ifdef USE_X_TOOLKIT
13662 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
13663 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
13664 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
13665 size_hints
.height
= widget_height
;
13666 size_hints
.width
= widget_width
;
13667 #else /* not USE_X_TOOLKIT */
13668 size_hints
.height
= PIXEL_HEIGHT (f
);
13669 size_hints
.width
= PIXEL_WIDTH (f
);
13670 #endif /* not USE_X_TOOLKIT */
13672 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13673 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13674 size_hints
.max_width
13675 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13676 size_hints
.max_height
13677 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13679 /* Calculate the base and minimum sizes.
13681 (When we use the X toolkit, we don't do it here.
13682 Instead we copy the values that the widgets are using, below.) */
13683 #ifndef USE_X_TOOLKIT
13685 int base_width
, base_height
;
13686 int min_rows
= 0, min_cols
= 0;
13688 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13689 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13691 check_frame_size (f
, &min_rows
, &min_cols
);
13693 /* The window manager uses the base width hints to calculate the
13694 current number of rows and columns in the frame while
13695 resizing; min_width and min_height aren't useful for this
13696 purpose, since they might not give the dimensions for a
13697 zero-row, zero-column frame.
13699 We use the base_width and base_height members if we have
13700 them; otherwise, we set the min_width and min_height members
13701 to the size for a zero x zero frame. */
13704 size_hints
.flags
|= PBaseSize
;
13705 size_hints
.base_width
= base_width
;
13706 size_hints
.base_height
= base_height
;
13707 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13708 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13710 size_hints
.min_width
= base_width
;
13711 size_hints
.min_height
= base_height
;
13715 /* If we don't need the old flags, we don't need the old hint at all. */
13718 size_hints
.flags
|= flags
;
13721 #endif /* not USE_X_TOOLKIT */
13724 XSizeHints hints
; /* Sometimes I hate X Windows... */
13725 long supplied_return
;
13729 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13732 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13735 #ifdef USE_X_TOOLKIT
13736 size_hints
.base_height
= hints
.base_height
;
13737 size_hints
.base_width
= hints
.base_width
;
13738 size_hints
.min_height
= hints
.min_height
;
13739 size_hints
.min_width
= hints
.min_width
;
13743 size_hints
.flags
|= flags
;
13748 if (hints
.flags
& PSize
)
13749 size_hints
.flags
|= PSize
;
13750 if (hints
.flags
& PPosition
)
13751 size_hints
.flags
|= PPosition
;
13752 if (hints
.flags
& USPosition
)
13753 size_hints
.flags
|= USPosition
;
13754 if (hints
.flags
& USSize
)
13755 size_hints
.flags
|= USSize
;
13759 #ifndef USE_X_TOOLKIT
13764 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
13765 size_hints
.flags
|= PWinGravity
;
13769 size_hints
.flags
&= ~ PPosition
;
13770 size_hints
.flags
|= USPosition
;
13772 #endif /* PWinGravity */
13775 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13777 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13781 /* Used for IconicState or NormalState */
13784 x_wm_set_window_state (f
, state
)
13788 #ifdef USE_X_TOOLKIT
13791 XtSetArg (al
[0], XtNinitialState
, state
);
13792 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13793 #else /* not USE_X_TOOLKIT */
13794 Window window
= FRAME_X_WINDOW (f
);
13796 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
13797 f
->output_data
.x
->wm_hints
.initial_state
= state
;
13799 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13800 #endif /* not USE_X_TOOLKIT */
13804 x_wm_set_icon_pixmap (f
, pixmap_id
)
13808 Pixmap icon_pixmap
;
13810 #ifndef USE_X_TOOLKIT
13811 Window window
= FRAME_X_WINDOW (f
);
13816 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
13817 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
13821 /* It seems there is no way to turn off use of an icon pixmap.
13822 The following line does it, only if no icon has yet been created,
13823 for some window managers. But with mwm it crashes.
13824 Some people say it should clear the IconPixmapHint bit in this case,
13825 but that doesn't work, and the X consortium said it isn't the
13826 right thing at all. Since there is no way to win,
13827 best to explicitly give up. */
13829 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
13835 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
13839 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
13840 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13843 #else /* not USE_X_TOOLKIT */
13845 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
13846 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13848 #endif /* not USE_X_TOOLKIT */
13852 x_wm_set_icon_position (f
, icon_x
, icon_y
)
13854 int icon_x
, icon_y
;
13856 #ifdef USE_X_TOOLKIT
13857 Window window
= XtWindow (f
->output_data
.x
->widget
);
13859 Window window
= FRAME_X_WINDOW (f
);
13862 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
13863 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
13864 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
13866 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13870 /***********************************************************************
13872 ***********************************************************************/
13874 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
13877 x_get_font_info (f
, font_idx
)
13881 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
13885 /* Return a list of names of available fonts matching PATTERN on frame F.
13887 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13890 SIZE < 0 means include scalable fonts.
13892 Frame F null means we have not yet created any frame on X, and
13893 consult the first display in x_display_list. MAXNAMES sets a limit
13894 on how many fonts to match. */
13897 x_list_fonts (f
, pattern
, size
, maxnames
)
13899 Lisp_Object pattern
;
13903 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13904 Lisp_Object tem
, second_best
;
13905 struct x_display_info
*dpyinfo
13906 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13907 Display
*dpy
= dpyinfo
->display
;
13908 int try_XLoadQueryFont
= 0;
13910 int allow_scalable_fonts_p
= 0;
13914 allow_scalable_fonts_p
= 1;
13918 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13919 if (NILP (patterns
))
13920 patterns
= Fcons (pattern
, Qnil
);
13922 if (maxnames
== 1 && !size
)
13923 /* We can return any single font matching PATTERN. */
13924 try_XLoadQueryFont
= 1;
13926 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13929 char **names
= NULL
;
13931 pattern
= XCAR (patterns
);
13932 /* See if we cached the result for this particular query.
13933 The cache is an alist of the form:
13934 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13935 tem
= XCDR (dpyinfo
->name_list_element
);
13936 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13937 allow_scalable_fonts_p
? Qt
: Qnil
);
13938 list
= Fassoc (key
, tem
);
13941 list
= Fcdr_safe (list
);
13942 /* We have a cashed list. Don't have to get the list again. */
13946 /* At first, put PATTERN in the cache. */
13949 count
= x_catch_errors (dpy
);
13951 if (try_XLoadQueryFont
)
13954 unsigned long value
;
13956 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13957 if (x_had_errors_p (dpy
))
13959 /* This error is perhaps due to insufficient memory on X
13960 server. Let's just ignore it. */
13962 x_clear_errors (dpy
);
13966 && XGetFontProperty (font
, XA_FONT
, &value
))
13968 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13969 int len
= strlen (name
);
13972 /* If DXPC (a Differential X Protocol Compressor)
13973 Ver.3.7 is running, XGetAtomName will return null
13974 string. We must avoid such a name. */
13976 try_XLoadQueryFont
= 0;
13980 names
= (char **) alloca (sizeof (char *));
13981 /* Some systems only allow alloca assigned to a
13983 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13984 bcopy (name
, names
[0], len
+ 1);
13989 try_XLoadQueryFont
= 0;
13992 XFreeFont (dpy
, font
);
13995 if (!try_XLoadQueryFont
)
13997 /* We try at least 10 fonts because XListFonts will return
13998 auto-scaled fonts at the head. */
13999 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
14001 if (x_had_errors_p (dpy
))
14003 /* This error is perhaps due to insufficient memory on X
14004 server. Let's just ignore it. */
14006 x_clear_errors (dpy
);
14010 x_uncatch_errors (dpy
, count
);
14017 /* Make a list of all the fonts we got back.
14018 Store that in the font cache for the display. */
14019 for (i
= 0; i
< num_fonts
; i
++)
14022 char *p
= names
[i
];
14023 int average_width
= -1, dashes
= 0;
14025 /* Count the number of dashes in NAMES[I]. If there are
14026 14 dashes, and the field value following 12th dash
14027 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
14028 is usually too ugly to be used for editing. Let's
14034 if (dashes
== 7) /* PIXEL_SIZE field */
14036 else if (dashes
== 12) /* AVERAGE_WIDTH field */
14037 average_width
= atoi (p
);
14040 if (allow_scalable_fonts_p
14041 || dashes
< 14 || average_width
!= 0)
14043 tem
= build_string (names
[i
]);
14044 if (NILP (Fassoc (tem
, list
)))
14046 if (STRINGP (Vx_pixel_size_width_font_regexp
)
14047 && ((fast_c_string_match_ignore_case
14048 (Vx_pixel_size_width_font_regexp
, names
[i
]))
14050 /* We can set the value of PIXEL_SIZE to the
14051 width of this font. */
14052 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
14054 /* For the moment, width is not known. */
14055 list
= Fcons (Fcons (tem
, Qnil
), list
);
14060 if (!try_XLoadQueryFont
)
14063 XFreeFontNames (names
);
14068 /* Now store the result in the cache. */
14069 XSETCDR (dpyinfo
->name_list_element
,
14070 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
14073 if (NILP (list
)) continue; /* Try the remaining alternatives. */
14075 newlist
= second_best
= Qnil
;
14076 /* Make a list of the fonts that have the right width. */
14077 for (; CONSP (list
); list
= XCDR (list
))
14083 if (!CONSP (tem
) || NILP (XCAR (tem
)))
14087 newlist
= Fcons (XCAR (tem
), newlist
);
14091 if (!INTEGERP (XCDR (tem
)))
14093 /* Since we have not yet known the size of this font, we
14094 must try slow function call XLoadQueryFont. */
14095 XFontStruct
*thisinfo
;
14098 count
= x_catch_errors (dpy
);
14099 thisinfo
= XLoadQueryFont (dpy
,
14100 XSTRING (XCAR (tem
))->data
);
14101 if (x_had_errors_p (dpy
))
14103 /* This error is perhaps due to insufficient memory on X
14104 server. Let's just ignore it. */
14106 x_clear_errors (dpy
);
14108 x_uncatch_errors (dpy
, count
);
14114 (thisinfo
->min_bounds
.width
== 0
14116 : make_number (thisinfo
->max_bounds
.width
)));
14118 XFreeFont (dpy
, thisinfo
);
14122 /* For unknown reason, the previous call of XListFont had
14123 returned a font which can't be opened. Record the size
14124 as 0 not to try to open it again. */
14125 XSETCDR (tem
, make_number (0));
14128 found_size
= XINT (XCDR (tem
));
14129 if (found_size
== size
)
14130 newlist
= Fcons (XCAR (tem
), newlist
);
14131 else if (found_size
> 0)
14133 if (NILP (second_best
))
14135 else if (found_size
< size
)
14137 if (XINT (XCDR (second_best
)) > size
14138 || XINT (XCDR (second_best
)) < found_size
)
14143 if (XINT (XCDR (second_best
)) > size
14144 && XINT (XCDR (second_best
)) > found_size
)
14149 if (!NILP (newlist
))
14151 else if (!NILP (second_best
))
14153 newlist
= Fcons (XCAR (second_best
), Qnil
);
14164 /* Check that FONT is valid on frame F. It is if it can be found in F's
14168 x_check_font (f
, font
)
14173 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14175 xassert (font
!= NULL
);
14177 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14178 if (dpyinfo
->font_table
[i
].name
14179 && font
== dpyinfo
->font_table
[i
].font
)
14182 xassert (i
< dpyinfo
->n_fonts
);
14185 #endif /* GLYPH_DEBUG != 0 */
14187 /* Set *W to the minimum width, *H to the minimum font height of FONT.
14188 Note: There are (broken) X fonts out there with invalid XFontStruct
14189 min_bounds contents. For example, handa@etl.go.jp reports that
14190 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
14191 have font->min_bounds.width == 0. */
14194 x_font_min_bounds (font
, w
, h
)
14198 *h
= FONT_HEIGHT (font
);
14199 *w
= font
->min_bounds
.width
;
14201 /* Try to handle the case where FONT->min_bounds has invalid
14202 contents. Since the only font known to have invalid min_bounds
14203 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
14205 *w
= font
->max_bounds
.width
;
14209 /* Compute the smallest character width and smallest font height over
14210 all fonts available on frame F. Set the members smallest_char_width
14211 and smallest_font_height in F's x_display_info structure to
14212 the values computed. Value is non-zero if smallest_font_height or
14213 smallest_char_width become smaller than they were before. */
14216 x_compute_min_glyph_bounds (f
)
14220 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14222 int old_width
= dpyinfo
->smallest_char_width
;
14223 int old_height
= dpyinfo
->smallest_font_height
;
14225 dpyinfo
->smallest_font_height
= 100000;
14226 dpyinfo
->smallest_char_width
= 100000;
14228 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14229 if (dpyinfo
->font_table
[i
].name
)
14231 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
14234 font
= (XFontStruct
*) fontp
->font
;
14235 xassert (font
!= (XFontStruct
*) ~0);
14236 x_font_min_bounds (font
, &w
, &h
);
14238 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
14239 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
14242 xassert (dpyinfo
->smallest_char_width
> 0
14243 && dpyinfo
->smallest_font_height
> 0);
14245 return (dpyinfo
->n_fonts
== 1
14246 || dpyinfo
->smallest_char_width
< old_width
14247 || dpyinfo
->smallest_font_height
< old_height
);
14251 /* Load font named FONTNAME of the size SIZE for frame F, and return a
14252 pointer to the structure font_info while allocating it dynamically.
14253 If SIZE is 0, load any size of font.
14254 If loading is failed, return NULL. */
14257 x_load_font (f
, fontname
, size
)
14259 register char *fontname
;
14262 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14263 Lisp_Object font_names
;
14266 /* Get a list of all the fonts that match this name. Once we
14267 have a list of matching fonts, we compare them against the fonts
14268 we already have by comparing names. */
14269 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
14271 if (!NILP (font_names
))
14276 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14277 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
14278 if (dpyinfo
->font_table
[i
].name
14279 && (!strcmp (dpyinfo
->font_table
[i
].name
,
14280 XSTRING (XCAR (tail
))->data
)
14281 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
14282 XSTRING (XCAR (tail
))->data
)))
14283 return (dpyinfo
->font_table
+ i
);
14286 /* Load the font and add it to the table. */
14290 struct font_info
*fontp
;
14291 unsigned long value
;
14294 /* If we have found fonts by x_list_font, load one of them. If
14295 not, we still try to load a font by the name given as FONTNAME
14296 because XListFonts (called in x_list_font) of some X server has
14297 a bug of not finding a font even if the font surely exists and
14298 is loadable by XLoadQueryFont. */
14299 if (size
> 0 && !NILP (font_names
))
14300 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
14303 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
14304 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
14305 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
14307 /* This error is perhaps due to insufficient memory on X
14308 server. Let's just ignore it. */
14310 x_clear_errors (FRAME_X_DISPLAY (f
));
14312 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
14317 /* Find a free slot in the font table. */
14318 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14319 if (dpyinfo
->font_table
[i
].name
== NULL
)
14322 /* If no free slot found, maybe enlarge the font table. */
14323 if (i
== dpyinfo
->n_fonts
14324 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
14327 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
14328 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
14329 dpyinfo
->font_table
14330 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
14333 fontp
= dpyinfo
->font_table
+ i
;
14334 if (i
== dpyinfo
->n_fonts
)
14335 ++dpyinfo
->n_fonts
;
14337 /* Now fill in the slots of *FONTP. */
14339 fontp
->font
= font
;
14340 fontp
->font_idx
= i
;
14341 fontp
->charset
= -1; /* fs_load_font sets it. */
14342 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
14343 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
14345 /* Try to get the full name of FONT. Put it in FULL_NAME. */
14347 if (XGetFontProperty (font
, XA_FONT
, &value
))
14349 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
14353 /* Count the number of dashes in the "full name".
14354 If it is too few, this isn't really the font's full name,
14356 In X11R4, the fonts did not come with their canonical names
14367 full_name
= (char *) xmalloc (p
- name
+ 1);
14368 bcopy (name
, full_name
, p
- name
+ 1);
14374 if (full_name
!= 0)
14375 fontp
->full_name
= full_name
;
14377 fontp
->full_name
= fontp
->name
;
14379 fontp
->size
= font
->max_bounds
.width
;
14380 fontp
->height
= FONT_HEIGHT (font
);
14382 if (NILP (font_names
))
14384 /* We come here because of a bug of XListFonts mentioned at
14385 the head of this block. Let's store this information in
14386 the cache for x_list_fonts. */
14387 Lisp_Object lispy_name
= build_string (fontname
);
14388 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
14389 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
14392 XSETCDR (dpyinfo
->name_list_element
,
14394 Fcons (Fcons (lispy_full_name
,
14395 make_number (fontp
->size
)),
14397 XCDR (dpyinfo
->name_list_element
)));
14400 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
14402 XSETCDR (dpyinfo
->name_list_element
,
14404 Fcons (Fcons (lispy_full_name
,
14405 make_number (fontp
->size
)),
14407 XCDR (dpyinfo
->name_list_element
)));
14411 /* The slot `encoding' specifies how to map a character
14412 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
14413 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
14414 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
14415 2:0xA020..0xFF7F). For the moment, we don't know which charset
14416 uses this font. So, we set information in fontp->encoding[1]
14417 which is never used by any charset. If mapping can't be
14418 decided, set FONT_ENCODING_NOT_DECIDED. */
14419 fontp
->encoding_type
14420 = (font
->max_byte1
== 0
14422 ? (font
->min_char_or_byte2
< 0x80
14423 ? (font
->max_char_or_byte2
< 0x80
14424 ? 0 /* 0x20..0x7F */
14425 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
14426 : 1) /* 0xA0..0xFF */
14428 : (font
->min_byte1
< 0x80
14429 ? (font
->max_byte1
< 0x80
14430 ? (font
->min_char_or_byte2
< 0x80
14431 ? (font
->max_char_or_byte2
< 0x80
14432 ? 0 /* 0x2020..0x7F7F */
14433 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
14434 : 3) /* 0x20A0..0x7FFF */
14435 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
14436 : (font
->min_char_or_byte2
< 0x80
14437 ? (font
->max_char_or_byte2
< 0x80
14438 ? 2 /* 0xA020..0xFF7F */
14439 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
14440 : 1))); /* 0xA0A0..0xFFFF */
14442 fontp
->baseline_offset
14443 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
14444 ? (long) value
: 0);
14445 fontp
->relative_compose
14446 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
14447 ? (long) value
: 0);
14448 fontp
->default_ascent
14449 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
14450 ? (long) value
: 0);
14452 /* Set global flag fonts_changed_p to non-zero if the font loaded
14453 has a character with a smaller width than any other character
14454 before, or if the font loaded has a smaller height than any
14455 other font loaded before. If this happens, it will make a
14456 glyph matrix reallocation necessary. */
14457 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
14464 /* Return a pointer to struct font_info of a font named FONTNAME for
14465 frame F. If no such font is loaded, return NULL. */
14468 x_query_font (f
, fontname
)
14470 register char *fontname
;
14472 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14475 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14476 if (dpyinfo
->font_table
[i
].name
14477 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
14478 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
14479 return (dpyinfo
->font_table
+ i
);
14484 /* Find a CCL program for a font specified by FONTP, and set the member
14485 `encoder' of the structure. */
14488 x_find_ccl_program (fontp
)
14489 struct font_info
*fontp
;
14491 Lisp_Object list
, elt
;
14494 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
14498 && STRINGP (XCAR (elt
))
14499 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
14501 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
14508 struct ccl_program
*ccl
14509 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
14511 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
14514 fontp
->font_encoder
= ccl
;
14519 /* Return a char-table whose elements are t if the font FONT_INFO
14520 contains a glyph for the corresponding character, and nil if not.
14522 Fixme: For the moment, this function works only for fonts whose
14523 glyph encoding is the same as Unicode (e.g. ISO10646-1 fonts). */
14526 x_get_font_repertory (f
, font_info
)
14528 struct font_info
*font_info
;
14530 XFontStruct
*font
= (XFontStruct
*) font_info
->font
;
14532 int min_byte1
, max_byte1
, min_byte2
, max_byte2
;
14534 table
= Fmake_char_table (Qnil
, Qnil
);
14536 min_byte1
= font
->min_byte1
;
14537 max_byte1
= font
->max_byte1
;
14538 min_byte2
= font
->min_char_or_byte2
;
14539 max_byte2
= font
->max_char_or_byte2
;
14540 if (min_byte1
== 0 && max_byte1
== 0)
14542 if (! font
->per_char
|| font
->all_chars_exist
== True
)
14543 char_table_set_range (table
, min_byte2
, max_byte2
, Qt
);
14546 XCharStruct
*pcm
= font
->per_char
;
14550 for (i
= min_byte2
; i
<= max_byte2
; i
++, pcm
++)
14552 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
14556 char_table_set_range (table
, from
, i
- 1, Qt
);
14564 char_table_set_range (table
, from
, i
- 1, Qt
);
14569 if (! font
->per_char
|| font
->all_chars_exist
== True
)
14573 for (i
= min_byte1
; i
<= max_byte1
; i
++)
14574 char_table_set_range (table
,
14575 (i
<< 8) | min_byte2
, (i
<< 8) | max_byte2
,
14580 XCharStruct
*pcm
= font
->per_char
;
14583 for (i
= min_byte1
; i
<= max_byte1
; i
++)
14588 for (j
= min_byte2
; j
<= max_byte2
; j
++, pcm
++)
14590 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
14594 char_table_set_range (table
, (i
<< 8) | from
,
14595 (i
<< 8) | (j
- 1), Qt
);
14603 char_table_set_range (table
, (i
<< 8) | from
,
14604 (i
<< 8) | (j
- 1), Qt
);
14614 /***********************************************************************
14616 ***********************************************************************/
14618 #ifdef USE_X_TOOLKIT
14619 static XrmOptionDescRec emacs_options
[] = {
14620 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
14621 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
14623 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
14624 XrmoptionSepArg
, NULL
},
14625 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
14627 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14628 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14629 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14630 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14631 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14632 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
14633 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
14635 #endif /* USE_X_TOOLKIT */
14637 static int x_initialized
;
14639 #ifdef MULTI_KBOARD
14640 /* Test whether two display-name strings agree up to the dot that separates
14641 the screen number from the server number. */
14643 same_x_server (name1
, name2
)
14644 char *name1
, *name2
;
14646 int seen_colon
= 0;
14647 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
14648 int system_name_length
= strlen (system_name
);
14649 int length_until_period
= 0;
14651 while (system_name
[length_until_period
] != 0
14652 && system_name
[length_until_period
] != '.')
14653 length_until_period
++;
14655 /* Treat `unix' like an empty host name. */
14656 if (! strncmp (name1
, "unix:", 5))
14658 if (! strncmp (name2
, "unix:", 5))
14660 /* Treat this host's name like an empty host name. */
14661 if (! strncmp (name1
, system_name
, system_name_length
)
14662 && name1
[system_name_length
] == ':')
14663 name1
+= system_name_length
;
14664 if (! strncmp (name2
, system_name
, system_name_length
)
14665 && name2
[system_name_length
] == ':')
14666 name2
+= system_name_length
;
14667 /* Treat this host's domainless name like an empty host name. */
14668 if (! strncmp (name1
, system_name
, length_until_period
)
14669 && name1
[length_until_period
] == ':')
14670 name1
+= length_until_period
;
14671 if (! strncmp (name2
, system_name
, length_until_period
)
14672 && name2
[length_until_period
] == ':')
14673 name2
+= length_until_period
;
14675 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
14679 if (seen_colon
&& *name1
== '.')
14683 && (*name1
== '.' || *name1
== '\0')
14684 && (*name2
== '.' || *name2
== '\0'));
14688 struct x_display_info
*
14689 x_term_init (display_name
, xrm_option
, resource_name
)
14690 Lisp_Object display_name
;
14692 char *resource_name
;
14696 struct x_display_info
*dpyinfo
;
14701 if (!x_initialized
)
14707 #ifdef USE_X_TOOLKIT
14708 /* weiner@footloose.sps.mot.com reports that this causes
14710 X protocol error: BadAtom (invalid Atom parameter)
14711 on protocol request 18skiloaf.
14712 So let's not use it until R6. */
14713 #ifdef HAVE_X11XTR6
14714 XtSetLanguageProc (NULL
, NULL
, NULL
);
14725 argv
[argc
++] = "-xrm";
14726 argv
[argc
++] = xrm_option
;
14728 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
14729 resource_name
, EMACS_CLASS
,
14730 emacs_options
, XtNumber (emacs_options
),
14733 #ifdef HAVE_X11XTR6
14734 /* I think this is to compensate for XtSetLanguageProc. */
14739 #else /* not USE_X_TOOLKIT */
14741 XSetLocaleModifiers ("");
14743 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
14744 #endif /* not USE_X_TOOLKIT */
14746 /* Detect failure. */
14753 /* We have definitely succeeded. Record the new connection. */
14755 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
14756 bzero (dpyinfo
, sizeof *dpyinfo
);
14758 #ifdef MULTI_KBOARD
14760 struct x_display_info
*share
;
14763 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
14764 share
= share
->next
, tail
= XCDR (tail
))
14765 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
14766 XSTRING (display_name
)->data
))
14769 dpyinfo
->kboard
= share
->kboard
;
14772 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
14773 init_kboard (dpyinfo
->kboard
);
14774 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
14776 char *vendor
= ServerVendor (dpy
);
14778 dpyinfo
->kboard
->Vsystem_key_alist
14779 = call1 (Qvendor_specific_keysyms
,
14780 build_string (vendor
? vendor
: ""));
14784 dpyinfo
->kboard
->next_kboard
= all_kboards
;
14785 all_kboards
= dpyinfo
->kboard
;
14786 /* Don't let the initial kboard remain current longer than necessary.
14787 That would cause problems if a file loaded on startup tries to
14788 prompt in the mini-buffer. */
14789 if (current_kboard
== initial_kboard
)
14790 current_kboard
= dpyinfo
->kboard
;
14792 dpyinfo
->kboard
->reference_count
++;
14796 /* Put this display on the chain. */
14797 dpyinfo
->next
= x_display_list
;
14798 x_display_list
= dpyinfo
;
14800 /* Put it on x_display_name_list as well, to keep them parallel. */
14801 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
14802 x_display_name_list
);
14803 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
14805 dpyinfo
->display
= dpy
;
14808 XSetAfterFunction (x_current_display
, x_trace_wire
);
14812 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
14813 + STRING_BYTES (XSTRING (Vsystem_name
))
14815 sprintf (dpyinfo
->x_id_name
, "%s@%s",
14816 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
14818 /* Figure out which modifier bits mean what. */
14819 x_find_modifier_meanings (dpyinfo
);
14821 /* Get the scroll bar cursor. */
14822 dpyinfo
->vertical_scroll_bar_cursor
14823 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
14825 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
14826 resource_name
, EMACS_CLASS
);
14827 #ifdef HAVE_XRMSETDATABASE
14828 XrmSetDatabase (dpyinfo
->display
, xrdb
);
14830 dpyinfo
->display
->db
= xrdb
;
14832 /* Put the rdb where we can find it in a way that works on
14834 dpyinfo
->xrdb
= xrdb
;
14836 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
14837 DefaultScreen (dpyinfo
->display
));
14838 select_visual (dpyinfo
);
14839 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
14840 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
14841 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
14842 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
14843 dpyinfo
->grabbed
= 0;
14844 dpyinfo
->reference_count
= 0;
14845 dpyinfo
->icon_bitmap_id
= -1;
14846 dpyinfo
->font_table
= NULL
;
14847 dpyinfo
->n_fonts
= 0;
14848 dpyinfo
->font_table_size
= 0;
14849 dpyinfo
->bitmaps
= 0;
14850 dpyinfo
->bitmaps_size
= 0;
14851 dpyinfo
->bitmaps_last
= 0;
14852 dpyinfo
->scratch_cursor_gc
= 0;
14853 dpyinfo
->mouse_face_mouse_frame
= 0;
14854 dpyinfo
->mouse_face_deferred_gc
= 0;
14855 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
14856 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
14857 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
14858 dpyinfo
->mouse_face_window
= Qnil
;
14859 dpyinfo
->mouse_face_overlay
= Qnil
;
14860 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
14861 dpyinfo
->mouse_face_defer
= 0;
14862 dpyinfo
->mouse_face_hidden
= 0;
14863 dpyinfo
->x_focus_frame
= 0;
14864 dpyinfo
->x_focus_event_frame
= 0;
14865 dpyinfo
->x_highlight_frame
= 0;
14866 dpyinfo
->image_cache
= make_image_cache ();
14868 /* See if a private colormap is requested. */
14869 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
14871 if (dpyinfo
->visual
->class == PseudoColor
)
14874 value
= display_x_get_resource (dpyinfo
,
14875 build_string ("privateColormap"),
14876 build_string ("PrivateColormap"),
14878 if (STRINGP (value
)
14879 && (!strcmp (XSTRING (value
)->data
, "true")
14880 || !strcmp (XSTRING (value
)->data
, "on")))
14881 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
14885 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
14886 dpyinfo
->visual
, AllocNone
);
14889 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
14890 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
14891 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
14892 dpyinfo
->resy
= pixels
* 25.4 / mm
;
14893 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
14894 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
14895 dpyinfo
->resx
= pixels
* 25.4 / mm
;
14898 dpyinfo
->Xatom_wm_protocols
14899 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
14900 dpyinfo
->Xatom_wm_take_focus
14901 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
14902 dpyinfo
->Xatom_wm_save_yourself
14903 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
14904 dpyinfo
->Xatom_wm_delete_window
14905 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
14906 dpyinfo
->Xatom_wm_change_state
14907 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
14908 dpyinfo
->Xatom_wm_configure_denied
14909 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
14910 dpyinfo
->Xatom_wm_window_moved
14911 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
14912 dpyinfo
->Xatom_editres
14913 = XInternAtom (dpyinfo
->display
, "Editres", False
);
14914 dpyinfo
->Xatom_CLIPBOARD
14915 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
14916 dpyinfo
->Xatom_TIMESTAMP
14917 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
14918 dpyinfo
->Xatom_TEXT
14919 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
14920 dpyinfo
->Xatom_COMPOUND_TEXT
14921 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
14922 dpyinfo
->Xatom_DELETE
14923 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
14924 dpyinfo
->Xatom_MULTIPLE
14925 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
14926 dpyinfo
->Xatom_INCR
14927 = XInternAtom (dpyinfo
->display
, "INCR", False
);
14928 dpyinfo
->Xatom_EMACS_TMP
14929 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
14930 dpyinfo
->Xatom_TARGETS
14931 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
14932 dpyinfo
->Xatom_NULL
14933 = XInternAtom (dpyinfo
->display
, "NULL", False
);
14934 dpyinfo
->Xatom_ATOM_PAIR
14935 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
14936 /* For properties of font. */
14937 dpyinfo
->Xatom_PIXEL_SIZE
14938 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
14939 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
14940 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
14941 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
14942 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
14943 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
14944 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
14946 /* Ghostscript support. */
14947 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
14948 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
14950 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
14953 dpyinfo
->cut_buffers_initialized
= 0;
14955 connection
= ConnectionNumber (dpyinfo
->display
);
14956 dpyinfo
->connection
= connection
;
14961 null_bits
[0] = 0x00;
14963 dpyinfo
->null_pixel
14964 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14965 null_bits
, 1, 1, (long) 0, (long) 0,
14970 extern int gray_bitmap_width
, gray_bitmap_height
;
14971 extern char *gray_bitmap_bits
;
14973 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14975 gray_bitmap_width
, gray_bitmap_height
,
14976 (unsigned long) 1, (unsigned long) 0, 1);
14980 xim_initialize (dpyinfo
, resource_name
);
14983 #ifdef subprocesses
14984 /* This is only needed for distinguishing keyboard and process input. */
14985 if (connection
!= 0)
14986 add_keyboard_wait_descriptor (connection
);
14989 #ifndef F_SETOWN_BUG
14991 #ifdef F_SETOWN_SOCK_NEG
14992 /* stdin is a socket here */
14993 fcntl (connection
, F_SETOWN
, -getpid ());
14994 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14995 fcntl (connection
, F_SETOWN
, getpid ());
14996 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14997 #endif /* ! defined (F_SETOWN) */
14998 #endif /* F_SETOWN_BUG */
15001 if (interrupt_input
)
15002 init_sigio (connection
);
15003 #endif /* ! defined (SIGIO) */
15006 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
15007 /* Make sure that we have a valid font for dialog boxes
15008 so that Xt does not crash. */
15010 Display
*dpy
= dpyinfo
->display
;
15011 XrmValue d
, fr
, to
;
15015 d
.addr
= (XPointer
)&dpy
;
15016 d
.size
= sizeof (Display
*);
15017 fr
.addr
= XtDefaultFont
;
15018 fr
.size
= sizeof (XtDefaultFont
);
15019 to
.size
= sizeof (Font
*);
15020 to
.addr
= (XPointer
)&font
;
15021 count
= x_catch_errors (dpy
);
15022 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
15024 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
15025 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
15026 x_uncatch_errors (dpy
, count
);
15031 /* See if we should run in synchronous mode. This is useful
15032 for debugging X code. */
15035 value
= display_x_get_resource (dpyinfo
,
15036 build_string ("synchronous"),
15037 build_string ("Synchronous"),
15039 if (STRINGP (value
)
15040 && (!strcmp (XSTRING (value
)->data
, "true")
15041 || !strcmp (XSTRING (value
)->data
, "on")))
15042 XSynchronize (dpyinfo
->display
, True
);
15047 value
= display_x_get_resource (dpyinfo
,
15048 build_string ("useXIM"),
15049 build_string ("UseXIM"),
15051 if (STRINGP (value
)
15052 && (!strcmp (XSTRING (value
)->data
, "false")
15053 || !strcmp (XSTRING (value
)->data
, "off")))
15062 /* Get rid of display DPYINFO, assuming all frames are already gone,
15063 and without sending any more commands to the X server. */
15066 x_delete_display (dpyinfo
)
15067 struct x_display_info
*dpyinfo
;
15069 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
15071 /* Discard this display from x_display_name_list and x_display_list.
15072 We can't use Fdelq because that can quit. */
15073 if (! NILP (x_display_name_list
)
15074 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
15075 x_display_name_list
= XCDR (x_display_name_list
);
15080 tail
= x_display_name_list
;
15081 while (CONSP (tail
) && CONSP (XCDR (tail
)))
15083 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
15085 XSETCDR (tail
, XCDR (XCDR (tail
)));
15088 tail
= XCDR (tail
);
15092 if (next_noop_dpyinfo
== dpyinfo
)
15093 next_noop_dpyinfo
= dpyinfo
->next
;
15095 if (x_display_list
== dpyinfo
)
15096 x_display_list
= dpyinfo
->next
;
15099 struct x_display_info
*tail
;
15101 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
15102 if (tail
->next
== dpyinfo
)
15103 tail
->next
= tail
->next
->next
;
15106 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
15107 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
15108 XrmDestroyDatabase (dpyinfo
->xrdb
);
15111 #ifdef MULTI_KBOARD
15112 if (--dpyinfo
->kboard
->reference_count
== 0)
15113 delete_kboard (dpyinfo
->kboard
);
15117 xim_close_dpy (dpyinfo
);
15120 xfree (dpyinfo
->font_table
);
15121 xfree (dpyinfo
->x_id_name
);
15122 xfree (dpyinfo
->color_cells
);
15127 /* Set up use of X before we make the first connection. */
15129 static struct redisplay_interface x_redisplay_interface
=
15134 x_clear_end_of_line
,
15136 x_after_update_window_line
,
15137 x_update_window_begin
,
15138 x_update_window_end
,
15141 x_clear_mouse_face
,
15142 x_get_glyph_overhangs
,
15143 x_fix_overlapping_area
15149 rif
= &x_redisplay_interface
;
15151 clear_frame_hook
= x_clear_frame
;
15152 ins_del_lines_hook
= x_ins_del_lines
;
15153 delete_glyphs_hook
= x_delete_glyphs
;
15154 ring_bell_hook
= XTring_bell
;
15155 reset_terminal_modes_hook
= XTreset_terminal_modes
;
15156 set_terminal_modes_hook
= XTset_terminal_modes
;
15157 update_begin_hook
= x_update_begin
;
15158 update_end_hook
= x_update_end
;
15159 set_terminal_window_hook
= XTset_terminal_window
;
15160 read_socket_hook
= XTread_socket
;
15161 frame_up_to_date_hook
= XTframe_up_to_date
;
15162 mouse_position_hook
= XTmouse_position
;
15163 frame_rehighlight_hook
= XTframe_rehighlight
;
15164 frame_raise_lower_hook
= XTframe_raise_lower
;
15165 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
15166 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
15167 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
15168 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
15169 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
15171 scroll_region_ok
= 1; /* we'll scroll partial frames */
15172 char_ins_del_ok
= 1;
15173 line_ins_del_ok
= 1; /* we'll just blt 'em */
15174 fast_clear_end_of_line
= 1; /* X does this well */
15175 memory_below_frame
= 0; /* we don't remember what scrolls
15180 last_tool_bar_item
= -1;
15181 any_help_event_p
= 0;
15183 /* Try to use interrupt input; if we can't, then start polling. */
15184 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
15186 #ifdef USE_X_TOOLKIT
15187 XtToolkitInitialize ();
15189 Xt_app_con
= XtCreateApplicationContext ();
15191 /* Register a converter from strings to pixels, which uses
15192 Emacs' color allocation infrastructure. */
15193 XtAppSetTypeConverter (Xt_app_con
,
15194 XtRString
, XtRPixel
, cvt_string_to_pixel
,
15195 cvt_string_to_pixel_args
,
15196 XtNumber (cvt_string_to_pixel_args
),
15197 XtCacheByDisplay
, cvt_pixel_dtor
);
15199 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
15201 /* Install an asynchronous timer that processes Xt timeout events
15202 every 0.1s. This is necessary because some widget sets use
15203 timeouts internally, for example the LessTif menu bar, or the
15204 Xaw3d scroll bar. When Xt timouts aren't processed, these
15205 widgets don't behave normally. */
15207 EMACS_TIME interval
;
15208 EMACS_SET_SECS_USECS (interval
, 0, 100000);
15209 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
15213 #ifdef USE_TOOLKIT_SCROLL_BARS
15214 xaw3d_arrow_scroll
= False
;
15215 xaw3d_pick_top
= True
;
15218 /* Note that there is no real way portable across R3/R4 to get the
15219 original error handler. */
15220 XSetErrorHandler (x_error_handler
);
15221 XSetIOErrorHandler (x_io_error_quitter
);
15223 /* Disable Window Change signals; they are handled by X events. */
15225 signal (SIGWINCH
, SIG_DFL
);
15226 #endif /* ! defined (SIGWINCH) */
15228 signal (SIGPIPE
, x_connection_signal
);
15235 staticpro (&x_error_message_string
);
15236 x_error_message_string
= Qnil
;
15238 staticpro (&x_display_name_list
);
15239 x_display_name_list
= Qnil
;
15241 staticpro (&last_mouse_scroll_bar
);
15242 last_mouse_scroll_bar
= Qnil
;
15244 staticpro (&Qvendor_specific_keysyms
);
15245 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
15247 staticpro (&last_mouse_press_frame
);
15248 last_mouse_press_frame
= Qnil
;
15251 staticpro (&help_echo
);
15252 help_echo_object
= Qnil
;
15253 staticpro (&help_echo_object
);
15254 help_echo_window
= Qnil
;
15255 staticpro (&help_echo_window
);
15256 previous_help_echo
= Qnil
;
15257 staticpro (&previous_help_echo
);
15258 help_echo_pos
= -1;
15260 DEFVAR_BOOL ("x-autoselect-window", &x_autoselect_window_p
,
15261 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
15262 x_autoselect_window_p
= 0;
15264 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
15265 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
15266 For example, if a block cursor is over a tab, it will be drawn as
15267 wide as that tab on the display. */);
15268 x_stretch_cursor_p
= 0;
15270 DEFVAR_BOOL ("x-use-underline-position-properties",
15271 &x_use_underline_position_properties
,
15272 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
15273 nil means ignore them. If you encounter fonts with bogus
15274 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
15275 to 4.1, set this to nil. */);
15276 x_use_underline_position_properties
= 1;
15278 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
15279 doc
: /* What X toolkit scroll bars Emacs uses.
15280 A value of nil means Emacs doesn't use X toolkit scroll bars.
15281 Otherwise, value is a symbol describing the X toolkit. */);
15282 #ifdef USE_TOOLKIT_SCROLL_BARS
15284 Vx_toolkit_scroll_bars
= intern ("motif");
15285 #elif defined HAVE_XAW3D
15286 Vx_toolkit_scroll_bars
= intern ("xaw3d");
15288 Vx_toolkit_scroll_bars
= intern ("xaw");
15291 Vx_toolkit_scroll_bars
= Qnil
;
15294 staticpro (&last_mouse_motion_frame
);
15295 last_mouse_motion_frame
= Qnil
;
15297 Qmodifier_value
= intern ("modifier-value");
15298 Qalt
= intern ("alt");
15299 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
15300 Qhyper
= intern ("hyper");
15301 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
15302 Qmeta
= intern ("meta");
15303 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
15304 Qsuper
= intern ("super");
15305 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
15307 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
15308 doc
: /* Which keys Emacs uses for the alt modifier.
15309 This should be one of the symbols `alt', `hyper', `meta', `super'.
15310 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
15311 is nil, which is the same as `alt'. */);
15312 Vx_alt_keysym
= Qnil
;
15314 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
15315 doc
: /* Which keys Emacs uses for the hyper modifier.
15316 This should be one of the symbols `alt', `hyper', `meta', `super'.
15317 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
15318 default is nil, which is the same as `hyper'. */);
15319 Vx_hyper_keysym
= Qnil
;
15321 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
15322 doc
: /* Which keys Emacs uses for the meta modifier.
15323 This should be one of the symbols `alt', `hyper', `meta', `super'.
15324 For example, `meta' means use the Meta_L and Meta_R keysyms. The
15325 default is nil, which is the same as `meta'. */);
15326 Vx_meta_keysym
= Qnil
;
15328 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
15329 doc
: /* Which keys Emacs uses for the super modifier.
15330 This should be one of the symbols `alt', `hyper', `meta', `super'.
15331 For example, `super' means use the Super_L and Super_R keysyms. The
15332 default is nil, which is the same as `super'. */);
15333 Vx_super_keysym
= Qnil
;
15335 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
15336 doc
: /* Hash table of character codes indexed by X keysym codes. */);
15337 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
15338 make_float (DEFAULT_REHASH_SIZE
),
15339 make_float (DEFAULT_REHASH_THRESHOLD
),
15343 #endif /* HAVE_X_WINDOWS */