1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001, 2002
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> */
74 #include "dispextern.h"
76 #include "termhooks.h"
84 #include "intervals.h"
90 #include <X11/Shell.h>
93 #ifdef HAVE_SYS_TIME_H
105 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
106 extern void xlwmenu_redisplay
P_ ((Widget
));
109 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
111 extern void free_frame_menubar
P_ ((struct frame
*));
112 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
117 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
119 extern void _XEditResCheckMessages ();
120 #endif /* not NO_EDITRES */
122 /* Include toolkit specific headers for the scroll bar widget. */
124 #ifdef USE_TOOLKIT_SCROLL_BARS
125 #if defined USE_MOTIF
126 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
127 #include <Xm/ScrollBar.h>
128 #else /* !USE_MOTIF i.e. use Xaw */
131 #include <X11/Xaw3d/Simple.h>
132 #include <X11/Xaw3d/Scrollbar.h>
133 #define ARROW_SCROLLBAR
134 #include <X11/Xaw3d/ScrollbarP.h>
135 #else /* !HAVE_XAW3D */
136 #include <X11/Xaw/Simple.h>
137 #include <X11/Xaw/Scrollbar.h>
138 #endif /* !HAVE_XAW3D */
140 #define XtNpickTop "pickTop"
141 #endif /* !XtNpickTop */
142 #endif /* !USE_MOTIF */
143 #endif /* USE_TOOLKIT_SCROLL_BARS */
145 #endif /* USE_X_TOOLKIT */
147 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
148 #define x_any_window_to_frame x_window_to_frame
149 #define x_top_window_to_frame x_window_to_frame
154 #ifndef XtNinitialState
155 #define XtNinitialState "initialState"
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
;
241 /* Non-nil means Emacs uses toolkit scroll bars. */
243 Lisp_Object Vx_toolkit_scroll_bars
;
245 /* If a string, XTread_socket generates an event to display that string.
246 (The display is done in read_char.) */
248 static Lisp_Object help_echo
;
249 static Lisp_Object help_echo_window
;
250 static Lisp_Object help_echo_object
;
251 static int help_echo_pos
;
253 /* Temporary variable for XTread_socket. */
255 static Lisp_Object previous_help_echo
;
257 /* Non-zero means that a HELP_EVENT has been generated since Emacs
260 static int any_help_event_p
;
262 /* Non-zero means autoselect window with the mouse cursor. */
264 int mouse_autoselect_window
;
266 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
267 static Lisp_Object last_window
;
269 /* Non-zero means draw block and hollow cursor as wide as the glyph
270 under it. For example, if a block cursor is over a tab, it will be
271 drawn as wide as that tab on the display. */
273 int x_stretch_cursor_p
;
275 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
277 int x_use_underline_position_properties
;
279 /* This is a chain of structures for all the X displays currently in
282 struct x_display_info
*x_display_list
;
284 /* This is a list of cons cells, each of the form (NAME
285 . FONT-LIST-CACHE), one for each element of x_display_list and in
286 the same order. NAME is the name of the frame. FONT-LIST-CACHE
287 records previous values returned by x-list-fonts. */
289 Lisp_Object x_display_name_list
;
291 /* Frame being updated by update_frame. This is declared in term.c.
292 This is set by update_begin and looked at by all the XT functions.
293 It is zero while not inside an update. In that case, the XT
294 functions assume that `selected_frame' is the frame to apply to. */
296 extern struct frame
*updating_frame
;
298 /* This is a frame waiting to be auto-raised, within XTread_socket. */
300 struct frame
*pending_autoraise_frame
;
303 /* The application context for Xt use. */
304 XtAppContext Xt_app_con
;
305 static String Xt_default_resources
[] = {0};
306 #endif /* USE_X_TOOLKIT */
308 /* Nominal cursor position -- where to draw output.
309 HPOS and VPOS are window relative glyph matrix coordinates.
310 X and Y are window relative pixel coordinates. */
312 struct cursor_pos output_cursor
;
314 /* Non-zero means user is interacting with a toolkit scroll bar. */
316 static int toolkit_scroll_bar_interaction
;
320 Formerly, we used PointerMotionHintMask (in standard_event_mask)
321 so that we would have to call XQueryPointer after each MotionNotify
322 event to ask for another such event. However, this made mouse tracking
323 slow, and there was a bug that made it eventually stop.
325 Simply asking for MotionNotify all the time seems to work better.
327 In order to avoid asking for motion events and then throwing most
328 of them away or busy-polling the server for mouse positions, we ask
329 the server for pointer motion hints. This means that we get only
330 one event per group of mouse movements. "Groups" are delimited by
331 other kinds of events (focus changes and button clicks, for
332 example), or by XQueryPointer calls; when one of these happens, we
333 get another MotionNotify event the next time the mouse moves. This
334 is at least as efficient as getting motion events when mouse
335 tracking is on, and I suspect only negligibly worse when tracking
338 /* Where the mouse was last time we reported a mouse event. */
340 FRAME_PTR last_mouse_frame
;
341 static XRectangle last_mouse_glyph
;
342 static Lisp_Object last_mouse_press_frame
;
344 /* The scroll bar in which the last X motion event occurred.
346 If the last X motion event occurred in a scroll bar, we set this so
347 XTmouse_position can know whether to report a scroll bar motion or
350 If the last X motion event didn't occur in a scroll bar, we set
351 this to Qnil, to tell XTmouse_position to return an ordinary motion
354 static Lisp_Object last_mouse_scroll_bar
;
356 /* This is a hack. We would really prefer that XTmouse_position would
357 return the time associated with the position it returns, but there
358 doesn't seem to be any way to wrest the time-stamp from the server
359 along with the position query. So, we just keep track of the time
360 of the last movement we received, and return that in hopes that
361 it's somewhat accurate. */
363 static Time last_mouse_movement_time
;
365 /* Incremented by XTread_socket whenever it really tries to read
369 static int volatile input_signal_count
;
371 static int input_signal_count
;
374 /* Used locally within XTread_socket. */
376 static int x_noop_count
;
378 /* Initial values of argv and argc. */
380 extern char **initial_argv
;
381 extern int initial_argc
;
383 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
385 /* Tells if a window manager is present or not. */
387 extern Lisp_Object Vx_no_window_manager
;
389 extern Lisp_Object Qface
, Qmouse_face
, Qeql
;
393 /* A mask of extra modifier bits to put into every keyboard char. */
395 extern EMACS_INT extra_keyboard_modifiers
;
397 /* The keysyms to use for the various modifiers. */
399 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
400 Lisp_Object Vx_keysym_table
;
401 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
403 static Lisp_Object Qvendor_specific_keysyms
;
404 static Lisp_Object Qlatin_1
, Qutf_8
;
406 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
407 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
410 /* Enumeration for overriding/changing the face to use for drawing
411 glyphs in x_draw_glyphs. */
413 enum draw_glyphs_face
423 static int cursor_in_mouse_face_p
P_ ((struct window
*));
424 static int clear_mouse_face
P_ ((struct x_display_info
*));
425 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
426 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
427 static const XColor
*x_color_cells
P_ ((Display
*, int *));
428 static void x_update_window_end
P_ ((struct window
*, int, int));
429 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
430 void x_delete_display
P_ ((struct x_display_info
*));
431 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
433 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
434 int *, int *, Lisp_Object
));
435 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
436 int *, int *, int *, int *, int));
437 static void set_output_cursor
P_ ((struct cursor_pos
*));
438 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
439 int *, int *, int *, int));
440 static void note_mode_line_or_margin_highlight
P_ ((struct window
*, int,
442 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
443 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
444 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
445 static void show_mouse_face
P_ ((struct x_display_info
*,
446 enum draw_glyphs_face
));
447 static int x_io_error_quitter
P_ ((Display
*));
448 int x_catch_errors
P_ ((Display
*));
449 void x_uncatch_errors
P_ ((Display
*, int));
450 void x_lower_frame
P_ ((struct frame
*));
451 void x_scroll_bar_clear
P_ ((struct frame
*));
452 int x_had_errors_p
P_ ((Display
*));
453 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
454 void x_raise_frame
P_ ((struct frame
*));
455 void x_set_window_size
P_ ((struct frame
*, int, int, int));
456 void x_wm_set_window_state
P_ ((struct frame
*, int));
457 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
458 void x_initialize
P_ ((void));
459 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
460 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
461 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
463 enum draw_glyphs_face
));
464 static void x_update_end
P_ ((struct frame
*));
465 static void XTframe_up_to_date
P_ ((struct frame
*));
466 static void XTset_terminal_modes
P_ ((void));
467 static void XTreset_terminal_modes
P_ ((void));
468 static void XTcursor_to
P_ ((int, int, int, int));
469 static void x_write_glyphs
P_ ((struct glyph
*, int));
470 static void x_clear_end_of_line
P_ ((int));
471 static void x_clear_frame
P_ ((void));
472 static void x_clear_cursor
P_ ((struct window
*));
473 static void frame_highlight
P_ ((struct frame
*));
474 static void frame_unhighlight
P_ ((struct frame
*));
475 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
476 static int x_focus_changed
P_ ((int,
478 struct x_display_info
*,
480 struct input_event
*,
482 static int x_detect_focus_change
P_ ((struct x_display_info
*,
484 struct input_event
*,
486 static void XTframe_rehighlight
P_ ((struct frame
*));
487 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
488 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
489 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
490 enum text_cursor_kinds
));
491 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
493 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
494 static int expose_window_tree
P_ ((struct window
*, XRectangle
*));
495 static void expose_overlaps
P_ ((struct window
*, struct glyph_row
*,
496 struct glyph_row
*));
497 static int expose_window
P_ ((struct window
*, XRectangle
*));
498 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
499 XRectangle
*, enum glyph_row_area
));
500 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
502 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
503 static void x_update_window_cursor
P_ ((struct window
*, int));
504 static void x_erase_phys_cursor
P_ ((struct window
*));
505 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
506 static void x_draw_fringe_bitmap
P_ ((struct window
*, struct glyph_row
*,
507 enum fringe_bitmap_type
, int left_p
));
509 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
511 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
512 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*, struct glyph_row
*));
513 static void notice_overwritten_cursor
P_ ((struct window
*, enum glyph_row_area
,
514 int, int, int, int));
515 static void x_flush
P_ ((struct frame
*f
));
516 static void x_update_begin
P_ ((struct frame
*));
517 static void x_update_window_begin
P_ ((struct window
*));
518 static void x_draw_vertical_border
P_ ((struct window
*));
519 static void x_after_update_window_line
P_ ((struct glyph_row
*));
520 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
521 static void x_produce_stretch_glyph
P_ ((struct it
*));
522 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
523 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
524 enum scroll_bar_part
*,
525 Lisp_Object
*, Lisp_Object
*,
527 static void x_check_fullscreen
P_ ((struct frame
*));
528 static void x_check_fullscreen_move
P_ ((struct frame
*));
529 static int handle_one_xevent
P_ ((struct x_display_info
*,
531 struct input_event
**,
536 /* Flush display of frame F, or of all frames if F is null. */
545 Lisp_Object rest
, frame
;
546 FOR_EACH_FRAME (rest
, frame
)
547 x_flush (XFRAME (frame
));
549 else if (FRAME_X_P (f
))
550 XFlush (FRAME_X_DISPLAY (f
));
555 /* Remove calls to XFlush by defining XFlush to an empty replacement.
556 Calls to XFlush should be unnecessary because the X output buffer
557 is flushed automatically as needed by calls to XPending,
558 XNextEvent, or XWindowEvent according to the XFlush man page.
559 XTread_socket calls XPending. Removing XFlush improves
562 #define XFlush(DISPLAY) (void) 0
565 /***********************************************************************
567 ***********************************************************************/
571 /* This is a function useful for recording debugging information about
572 the sequence of occurrences in this file. */
580 struct record event_record
[100];
582 int event_record_index
;
584 record_event (locus
, type
)
588 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
589 event_record_index
= 0;
591 event_record
[event_record_index
].locus
= locus
;
592 event_record
[event_record_index
].type
= type
;
593 event_record_index
++;
600 /* Return the struct x_display_info corresponding to DPY. */
602 struct x_display_info
*
603 x_display_info_for_display (dpy
)
606 struct x_display_info
*dpyinfo
;
608 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
609 if (dpyinfo
->display
== dpy
)
617 /***********************************************************************
618 Starting and ending an update
619 ***********************************************************************/
621 /* Start an update of frame F. This function is installed as a hook
622 for update_begin, i.e. it is called when update_begin is called.
623 This function is called prior to calls to x_update_window_begin for
624 each window being updated. Currently, there is nothing to do here
625 because all interesting stuff is done on a window basis. */
635 /* Start update of window W. Set the global variable updated_window
636 to the window being updated and set output_cursor to the cursor
640 x_update_window_begin (w
)
643 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
644 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
647 set_output_cursor (&w
->cursor
);
651 if (f
== display_info
->mouse_face_mouse_frame
)
653 /* Don't do highlighting for mouse motion during the update. */
654 display_info
->mouse_face_defer
= 1;
656 /* If F needs to be redrawn, simply forget about any prior mouse
658 if (FRAME_GARBAGED_P (f
))
659 display_info
->mouse_face_window
= Qnil
;
661 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
662 their mouse_face_p flag set, which means that they are always
663 unequal to rows in a desired matrix which never have that
664 flag set. So, rows containing mouse-face glyphs are never
665 scrolled, and we don't have to switch the mouse highlight off
666 here to prevent it from being scrolled. */
668 /* Can we tell that this update does not affect the window
669 where the mouse highlight is? If so, no need to turn off.
670 Likewise, don't do anything if the frame is garbaged;
671 in that case, the frame's current matrix that we would use
672 is all wrong, and we will redisplay that line anyway. */
673 if (!NILP (display_info
->mouse_face_window
)
674 && w
== XWINDOW (display_info
->mouse_face_window
))
678 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
679 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
682 if (i
< w
->desired_matrix
->nrows
)
683 clear_mouse_face (display_info
);
692 /* Draw a vertical window border to the right of window W if W doesn't
693 have vertical scroll bars. */
696 x_draw_vertical_border (w
)
699 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
701 /* Redraw borders between horizontally adjacent windows. Don't
702 do it for frames with vertical scroll bars because either the
703 right scroll bar of a window, or the left scroll bar of its
704 neighbor will suffice as a border. */
705 if (!WINDOW_RIGHTMOST_P (w
)
706 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
710 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
711 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
714 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
715 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
720 /* End update of window W (which is equal to updated_window).
722 Draw vertical borders between horizontally adjacent windows, and
723 display W's cursor if CURSOR_ON_P is non-zero.
725 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
726 glyphs in mouse-face were overwritten. In that case we have to
727 make sure that the mouse-highlight is properly redrawn.
729 W may be a menu bar pseudo-window in case we don't have X toolkit
730 support. Such windows don't have a cursor, so don't display it
734 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
736 int cursor_on_p
, mouse_face_overwritten_p
;
738 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
740 if (!w
->pseudo_window_p
)
745 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
747 output_cursor
.x
, output_cursor
.y
);
749 x_draw_vertical_border (w
);
753 /* If a row with mouse-face was overwritten, arrange for
754 XTframe_up_to_date to redisplay the mouse highlight. */
755 if (mouse_face_overwritten_p
)
757 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
758 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
759 dpyinfo
->mouse_face_window
= Qnil
;
762 updated_window
= NULL
;
766 /* End update of frame F. This function is installed as a hook in
773 /* Mouse highlight may be displayed again. */
774 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
777 XFlush (FRAME_X_DISPLAY (f
));
782 /* This function is called from various places in xdisp.c whenever a
783 complete update has been performed. The global variable
784 updated_window is not available here. */
787 XTframe_up_to_date (f
)
792 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
794 if (dpyinfo
->mouse_face_deferred_gc
795 || f
== dpyinfo
->mouse_face_mouse_frame
)
798 if (dpyinfo
->mouse_face_mouse_frame
)
799 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
800 dpyinfo
->mouse_face_mouse_x
,
801 dpyinfo
->mouse_face_mouse_y
);
802 dpyinfo
->mouse_face_deferred_gc
= 0;
809 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
810 arrow bitmaps, or clear the fringes if no bitmaps are required
811 before DESIRED_ROW is made current. The window being updated is
812 found in updated_window. This function It is called from
813 update_window_line only if it is known that there are differences
814 between bitmaps to be drawn between current row and DESIRED_ROW. */
817 x_after_update_window_line (desired_row
)
818 struct glyph_row
*desired_row
;
820 struct window
*w
= updated_window
;
826 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
829 x_draw_row_fringe_bitmaps (w
, desired_row
);
833 /* When a window has disappeared, make sure that no rest of
834 full-width rows stays visible in the internal border. Could
835 check here if updated_window is the leftmost/rightmost window,
836 but I guess it's not worth doing since vertically split windows
837 are almost never used, internal border is rarely set, and the
838 overhead is very small. */
839 if (windows_or_buffers_changed
840 && desired_row
->full_width_p
841 && (f
= XFRAME (w
->frame
),
842 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
844 && (height
= desired_row
->visible_height
,
847 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
849 /* Internal border is drawn below the tool bar. */
850 if (WINDOWP (f
->tool_bar_window
)
851 && w
== XWINDOW (f
->tool_bar_window
))
855 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
856 0, y
, width
, height
, False
);
857 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
858 f
->output_data
.x
->pixel_width
- width
,
859 y
, width
, height
, False
);
865 /* Draw the bitmap WHICH in one of the left or right fringes of
866 window W. ROW is the glyph row for which to display the bitmap; it
867 determines the vertical position at which the bitmap has to be
871 x_draw_fringe_bitmap (w
, row
, which
, left_p
)
873 struct glyph_row
*row
;
874 enum fringe_bitmap_type which
;
877 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
878 Display
*display
= FRAME_X_DISPLAY (f
);
879 Window window
= FRAME_X_WINDOW (f
);
882 unsigned char *bits
= NULL
;
884 GC gc
= f
->output_data
.x
->normal_gc
;
886 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
888 /* Must clip because of partially visible lines. */
889 x_clip_to_row (w
, row
, gc
, 1);
891 /* Convert row to frame coordinates. */
892 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
896 case NO_FRINGE_BITMAP
:
901 case LEFT_TRUNCATION_BITMAP
:
907 case OVERLAY_ARROW_BITMAP
:
913 case RIGHT_TRUNCATION_BITMAP
:
919 case CONTINUED_LINE_BITMAP
:
920 wd
= continued_width
;
921 h
= continued_height
;
922 bits
= continued_bits
;
925 case CONTINUATION_LINE_BITMAP
:
926 wd
= continuation_width
;
927 h
= continuation_height
;
928 bits
= continuation_bits
;
933 h
= zv_height
- (y
% zv_period
);
934 bits
= zv_bits
+ (y
% zv_period
);
941 /* Clip bitmap if too high. */
945 /* Set dy to the offset in the row to start drawing the bitmap. */
946 dy
= (row
->height
- h
) / 2;
948 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
949 PREPARE_FACE_FOR_DISPLAY (f
, face
);
951 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
956 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
957 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
958 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
960 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
961 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
963 /* If W has a vertical border to its left, don't draw over it. */
964 int border
= ((XFASTINT (w
->left
) > 0
965 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
967 b1
= (window_box_left (w
, -1)
968 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
970 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
975 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
976 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
977 x
= (window_box_right (w
, -1)
978 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
979 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
981 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
983 b1
= window_box_right (w
, -1);
984 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
990 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
992 /* In case the same realized face is used for fringes and
993 for something displayed in the text (e.g. face `region' on
994 mono-displays, the fill style may have been changed to
995 FillSolid in x_draw_glyph_string_background. */
997 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
999 XSetForeground (display
, face
->gc
, face
->background
);
1001 XFillRectangle (display
, window
, face
->gc
,
1003 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1006 row
->visible_height
);
1008 XSetForeground (display
, face
->gc
, face
->foreground
);
1011 if (which
!= NO_FRINGE_BITMAP
)
1013 /* Draw the bitmap. I believe these small pixmaps can be cached
1015 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
1017 face
->background
, depth
);
1018 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
1019 XFreePixmap (display
, pixmap
);
1022 XSetClipMask (display
, gc
, None
);
1026 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
1027 function with input blocked. */
1030 x_draw_row_fringe_bitmaps (w
, row
)
1032 struct glyph_row
*row
;
1034 struct frame
*f
= XFRAME (w
->frame
);
1035 enum fringe_bitmap_type bitmap
;
1037 xassert (interrupt_input_blocked
);
1039 /* If row is completely invisible, because of vscrolling, we
1040 don't have to draw anything. */
1041 if (row
->visible_height
<= 0)
1044 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
1046 /* Decide which bitmap to draw in the left fringe. */
1047 if (row
->overlay_arrow_p
)
1048 bitmap
= OVERLAY_ARROW_BITMAP
;
1049 else if (row
->truncated_on_left_p
)
1050 bitmap
= LEFT_TRUNCATION_BITMAP
;
1051 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1052 bitmap
= CONTINUATION_LINE_BITMAP
;
1053 else if (row
->indicate_empty_line_p
)
1054 bitmap
= ZV_LINE_BITMAP
;
1056 bitmap
= NO_FRINGE_BITMAP
;
1058 x_draw_fringe_bitmap (w
, row
, bitmap
, 1);
1061 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1063 /* Decide which bitmap to draw in the right fringe. */
1064 if (row
->truncated_on_right_p
)
1065 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1066 else if (row
->continued_p
)
1067 bitmap
= CONTINUED_LINE_BITMAP
;
1068 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1069 bitmap
= ZV_LINE_BITMAP
;
1071 bitmap
= NO_FRINGE_BITMAP
;
1073 x_draw_fringe_bitmap (w
, row
, bitmap
, 0);
1079 /* This is called when starting Emacs and when restarting after
1080 suspend. When starting Emacs, no X window is mapped. And nothing
1081 must be done to Emacs's own window if it is suspended (though that
1085 XTset_terminal_modes ()
1089 /* This is called when exiting or suspending Emacs. Exiting will make
1090 the X-windows go away, and suspending requires no action. */
1093 XTreset_terminal_modes ()
1099 /***********************************************************************
1101 ***********************************************************************/
1103 /* Set the global variable output_cursor to CURSOR. All cursor
1104 positions are relative to updated_window. */
1107 set_output_cursor (cursor
)
1108 struct cursor_pos
*cursor
;
1110 output_cursor
.hpos
= cursor
->hpos
;
1111 output_cursor
.vpos
= cursor
->vpos
;
1112 output_cursor
.x
= cursor
->x
;
1113 output_cursor
.y
= cursor
->y
;
1117 /* Set a nominal cursor position.
1119 HPOS and VPOS are column/row positions in a window glyph matrix. X
1120 and Y are window text area relative pixel positions.
1122 If this is done during an update, updated_window will contain the
1123 window that is being updated and the position is the future output
1124 cursor position for that window. If updated_window is null, use
1125 selected_window and display the cursor at the given position. */
1128 XTcursor_to (vpos
, hpos
, y
, x
)
1129 int vpos
, hpos
, y
, x
;
1133 /* If updated_window is not set, work on selected_window. */
1137 w
= XWINDOW (selected_window
);
1139 /* Set the output cursor. */
1140 output_cursor
.hpos
= hpos
;
1141 output_cursor
.vpos
= vpos
;
1142 output_cursor
.x
= x
;
1143 output_cursor
.y
= y
;
1145 /* If not called as part of an update, really display the cursor.
1146 This will also set the cursor position of W. */
1147 if (updated_window
== NULL
)
1150 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1151 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1158 /***********************************************************************
1160 ***********************************************************************/
1162 /* Function prototypes of this page. */
1164 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1168 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1169 int, XChar2b
*, int,
1171 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1172 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1173 static void x_append_glyph
P_ ((struct it
*));
1174 static void x_append_composite_glyph
P_ ((struct it
*));
1175 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1177 static void x_produce_glyphs
P_ ((struct it
*));
1178 static void x_produce_image_glyph
P_ ((struct it
*it
));
1181 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1182 is not contained in the font. */
1184 static INLINE XCharStruct
*
1185 x_per_char_metric (font
, char2b
)
1189 /* The result metric information. */
1190 XCharStruct
*pcm
= NULL
;
1192 xassert (font
&& char2b
);
1194 if (font
->per_char
!= NULL
)
1196 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1198 /* min_char_or_byte2 specifies the linear character index
1199 corresponding to the first element of the per_char array,
1200 max_char_or_byte2 is the index of the last character. A
1201 character with non-zero CHAR2B->byte1 is not in the font.
1202 A character with byte2 less than min_char_or_byte2 or
1203 greater max_char_or_byte2 is not in the font. */
1204 if (char2b
->byte1
== 0
1205 && char2b
->byte2
>= font
->min_char_or_byte2
1206 && char2b
->byte2
<= font
->max_char_or_byte2
)
1207 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1211 /* If either min_byte1 or max_byte1 are nonzero, both
1212 min_char_or_byte2 and max_char_or_byte2 are less than
1213 256, and the 2-byte character index values corresponding
1214 to the per_char array element N (counting from 0) are:
1216 byte1 = N/D + min_byte1
1217 byte2 = N\D + min_char_or_byte2
1221 D = max_char_or_byte2 - min_char_or_byte2 + 1
1222 / = integer division
1223 \ = integer modulus */
1224 if (char2b
->byte1
>= font
->min_byte1
1225 && char2b
->byte1
<= font
->max_byte1
1226 && char2b
->byte2
>= font
->min_char_or_byte2
1227 && char2b
->byte2
<= font
->max_char_or_byte2
)
1229 pcm
= (font
->per_char
1230 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1231 * (char2b
->byte1
- font
->min_byte1
))
1232 + (char2b
->byte2
- font
->min_char_or_byte2
));
1238 /* If the per_char pointer is null, all glyphs between the first
1239 and last character indexes inclusive have the same
1240 information, as given by both min_bounds and max_bounds. */
1241 if (char2b
->byte2
>= font
->min_char_or_byte2
1242 && char2b
->byte2
<= font
->max_char_or_byte2
)
1243 pcm
= &font
->max_bounds
;
1246 return ((pcm
== NULL
1247 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1252 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1253 the two-byte form of C. Encoding is returned in *CHAR2B. */
1256 x_encode_char (c
, char2b
, font_info
)
1259 struct font_info
*font_info
;
1261 int charset
= CHAR_CHARSET (c
);
1262 XFontStruct
*font
= font_info
->font
;
1264 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1265 This may be either a program in a special encoder language or a
1267 if (font_info
->font_encoder
)
1269 /* It's a program. */
1270 struct ccl_program
*ccl
= font_info
->font_encoder
;
1272 if (CHARSET_DIMENSION (charset
) == 1)
1274 ccl
->reg
[0] = charset
;
1275 ccl
->reg
[1] = char2b
->byte2
;
1280 ccl
->reg
[0] = charset
;
1281 ccl
->reg
[1] = char2b
->byte1
;
1282 ccl
->reg
[2] = char2b
->byte2
;
1285 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1287 /* We assume that MSBs are appropriately set/reset by CCL
1289 if (font
->max_byte1
== 0) /* 1-byte font */
1290 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1292 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1294 else if (font_info
->encoding
[charset
])
1296 /* Fixed encoding scheme. See fontset.h for the meaning of the
1297 encoding numbers. */
1298 int enc
= font_info
->encoding
[charset
];
1300 if ((enc
== 1 || enc
== 2)
1301 && CHARSET_DIMENSION (charset
) == 2)
1302 char2b
->byte1
|= 0x80;
1304 if (enc
== 1 || enc
== 3)
1305 char2b
->byte2
|= 0x80;
1310 /* Get face and two-byte form of character C in face FACE_ID on frame
1311 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1312 means we want to display multibyte text. DISPLAY_P non-zero means
1313 make sure that X resources for the face returned are allocated.
1314 Value is a pointer to a realized face that is ready for display if
1315 DISPLAY_P is non-zero. */
1317 static INLINE
struct face
*
1318 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
1322 int multibyte_p
, display_p
;
1324 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1328 /* Unibyte case. We don't have to encode, but we have to make
1329 sure to use a face suitable for unibyte. */
1332 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1333 face
= FACE_FROM_ID (f
, face_id
);
1335 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1337 /* Case of ASCII in a face known to fit ASCII. */
1343 int c1
, c2
, charset
;
1345 /* Split characters into bytes. If c2 is -1 afterwards, C is
1346 really a one-byte character so that byte1 is zero. */
1347 SPLIT_CHAR (c
, charset
, c1
, c2
);
1349 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1351 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1353 /* Maybe encode the character in *CHAR2B. */
1354 if (face
->font
!= NULL
)
1356 struct font_info
*font_info
1357 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1359 x_encode_char (c
, char2b
, font_info
);
1363 /* Make sure X resources of the face are allocated. */
1366 xassert (face
!= NULL
);
1367 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1374 /* Get face and two-byte form of character glyph GLYPH on frame F.
1375 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1376 a pointer to a realized face that is ready for display. */
1378 static INLINE
struct face
*
1379 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1381 struct glyph
*glyph
;
1387 xassert (glyph
->type
== CHAR_GLYPH
);
1388 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1393 if (!glyph
->multibyte_p
)
1395 /* Unibyte case. We don't have to encode, but we have to make
1396 sure to use a face suitable for unibyte. */
1398 char2b
->byte2
= glyph
->u
.ch
;
1400 else if (glyph
->u
.ch
< 128
1401 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1403 /* Case of ASCII in a face known to fit ASCII. */
1405 char2b
->byte2
= glyph
->u
.ch
;
1409 int c1
, c2
, charset
;
1411 /* Split characters into bytes. If c2 is -1 afterwards, C is
1412 really a one-byte character so that byte1 is zero. */
1413 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1415 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1417 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1419 /* Maybe encode the character in *CHAR2B. */
1420 if (charset
!= CHARSET_ASCII
)
1422 struct font_info
*font_info
1423 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1426 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1429 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1434 /* Make sure X resources of the face are allocated. */
1435 xassert (face
!= NULL
);
1436 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1441 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1442 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1448 struct glyph
*glyph
;
1449 enum glyph_row_area area
= it
->area
;
1451 xassert (it
->glyph_row
);
1452 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1454 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1455 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1457 glyph
->charpos
= CHARPOS (it
->position
);
1458 glyph
->object
= it
->object
;
1459 glyph
->pixel_width
= it
->pixel_width
;
1460 glyph
->voffset
= it
->voffset
;
1461 glyph
->type
= CHAR_GLYPH
;
1462 glyph
->multibyte_p
= it
->multibyte_p
;
1463 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1464 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1465 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1466 || it
->phys_descent
> it
->descent
);
1467 glyph
->padding_p
= 0;
1468 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1469 glyph
->face_id
= it
->face_id
;
1470 glyph
->u
.ch
= it
->char_to_display
;
1471 ++it
->glyph_row
->used
[area
];
1475 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1476 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1479 x_append_composite_glyph (it
)
1482 struct glyph
*glyph
;
1483 enum glyph_row_area area
= it
->area
;
1485 xassert (it
->glyph_row
);
1487 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1488 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1490 glyph
->charpos
= CHARPOS (it
->position
);
1491 glyph
->object
= it
->object
;
1492 glyph
->pixel_width
= it
->pixel_width
;
1493 glyph
->voffset
= it
->voffset
;
1494 glyph
->type
= COMPOSITE_GLYPH
;
1495 glyph
->multibyte_p
= it
->multibyte_p
;
1496 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1497 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1498 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1499 || it
->phys_descent
> it
->descent
);
1500 glyph
->padding_p
= 0;
1501 glyph
->glyph_not_available_p
= 0;
1502 glyph
->face_id
= it
->face_id
;
1503 glyph
->u
.cmp_id
= it
->cmp_id
;
1504 ++it
->glyph_row
->used
[area
];
1509 /* Change IT->ascent and IT->height according to the setting of
1513 take_vertical_position_into_account (it
)
1518 if (it
->voffset
< 0)
1519 /* Increase the ascent so that we can display the text higher
1521 it
->ascent
+= abs (it
->voffset
);
1523 /* Increase the descent so that we can display the text lower
1525 it
->descent
+= it
->voffset
;
1530 /* Produce glyphs/get display metrics for the image IT is loaded with.
1531 See the description of struct display_iterator in dispextern.h for
1532 an overview of struct display_iterator. */
1535 x_produce_image_glyph (it
)
1541 xassert (it
->what
== IT_IMAGE
);
1543 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1544 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1547 /* Make sure X resources of the face and image are loaded. */
1548 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1549 prepare_image_for_display (it
->f
, img
);
1551 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1552 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1553 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1557 if (face
->box
!= FACE_NO_BOX
)
1559 if (face
->box_line_width
> 0)
1561 it
->ascent
+= face
->box_line_width
;
1562 it
->descent
+= face
->box_line_width
;
1565 if (it
->start_of_box_run_p
)
1566 it
->pixel_width
+= abs (face
->box_line_width
);
1567 if (it
->end_of_box_run_p
)
1568 it
->pixel_width
+= abs (face
->box_line_width
);
1571 take_vertical_position_into_account (it
);
1575 struct glyph
*glyph
;
1576 enum glyph_row_area area
= it
->area
;
1578 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1579 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1581 glyph
->charpos
= CHARPOS (it
->position
);
1582 glyph
->object
= it
->object
;
1583 glyph
->pixel_width
= it
->pixel_width
;
1584 glyph
->voffset
= it
->voffset
;
1585 glyph
->type
= IMAGE_GLYPH
;
1586 glyph
->multibyte_p
= it
->multibyte_p
;
1587 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1588 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1589 glyph
->overlaps_vertically_p
= 0;
1590 glyph
->padding_p
= 0;
1591 glyph
->glyph_not_available_p
= 0;
1592 glyph
->face_id
= it
->face_id
;
1593 glyph
->u
.img_id
= img
->id
;
1594 ++it
->glyph_row
->used
[area
];
1600 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1601 of the glyph, WIDTH and HEIGHT are the width and height of the
1602 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1603 ascent of the glyph (0 <= ASCENT <= 1). */
1606 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1612 struct glyph
*glyph
;
1613 enum glyph_row_area area
= it
->area
;
1615 xassert (ascent
>= 0 && ascent
<= 1);
1617 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1618 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1620 glyph
->charpos
= CHARPOS (it
->position
);
1621 glyph
->object
= object
;
1622 glyph
->pixel_width
= width
;
1623 glyph
->voffset
= it
->voffset
;
1624 glyph
->type
= STRETCH_GLYPH
;
1625 glyph
->multibyte_p
= it
->multibyte_p
;
1626 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1627 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1628 glyph
->overlaps_vertically_p
= 0;
1629 glyph
->padding_p
= 0;
1630 glyph
->glyph_not_available_p
= 0;
1631 glyph
->face_id
= it
->face_id
;
1632 glyph
->u
.stretch
.ascent
= height
* ascent
;
1633 glyph
->u
.stretch
.height
= height
;
1634 ++it
->glyph_row
->used
[area
];
1639 /* Produce a stretch glyph for iterator IT. IT->object is the value
1640 of the glyph property displayed. The value must be a list
1641 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1644 1. `:width WIDTH' specifies that the space should be WIDTH *
1645 canonical char width wide. WIDTH may be an integer or floating
1648 2. `:relative-width FACTOR' specifies that the width of the stretch
1649 should be computed from the width of the first character having the
1650 `glyph' property, and should be FACTOR times that width.
1652 3. `:align-to HPOS' specifies that the space should be wide enough
1653 to reach HPOS, a value in canonical character units.
1655 Exactly one of the above pairs must be present.
1657 4. `:height HEIGHT' specifies that the height of the stretch produced
1658 should be HEIGHT, measured in canonical character units.
1660 5. `:relative-height FACTOR' specifies that the height of the
1661 stretch should be FACTOR times the height of the characters having
1664 Either none or exactly one of 4 or 5 must be present.
1666 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1667 of the stretch should be used for the ascent of the stretch.
1668 ASCENT must be in the range 0 <= ASCENT <= 100. */
1671 ((INTEGERP (X) || FLOATP (X)) \
1677 x_produce_stretch_glyph (it
)
1680 /* (space :width WIDTH :height HEIGHT. */
1682 extern Lisp_Object Qspace
;
1684 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1685 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1686 extern Lisp_Object QCalign_to
;
1687 Lisp_Object prop
, plist
;
1688 double width
= 0, height
= 0, ascent
= 0;
1689 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1690 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1692 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1694 /* List should start with `space'. */
1695 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1696 plist
= XCDR (it
->object
);
1698 /* Compute the width of the stretch. */
1699 if (prop
= Fplist_get (plist
, QCwidth
),
1701 /* Absolute width `:width WIDTH' specified and valid. */
1702 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1703 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1706 /* Relative width `:relative-width FACTOR' specified and valid.
1707 Compute the width of the characters having the `glyph'
1710 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1713 if (it
->multibyte_p
)
1715 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1716 - IT_BYTEPOS (*it
));
1717 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1720 it2
.c
= *p
, it2
.len
= 1;
1722 it2
.glyph_row
= NULL
;
1723 it2
.what
= IT_CHARACTER
;
1724 x_produce_glyphs (&it2
);
1725 width
= NUMVAL (prop
) * it2
.pixel_width
;
1727 else if (prop
= Fplist_get (plist
, QCalign_to
),
1729 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1731 /* Nothing specified -> width defaults to canonical char width. */
1732 width
= CANON_X_UNIT (it
->f
);
1734 /* Compute height. */
1735 if (prop
= Fplist_get (plist
, QCheight
),
1737 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1738 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1740 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1742 height
= FONT_HEIGHT (font
);
1744 /* Compute percentage of height used for ascent. If
1745 `:ascent ASCENT' is present and valid, use that. Otherwise,
1746 derive the ascent from the font in use. */
1747 if (prop
= Fplist_get (plist
, QCascent
),
1748 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1749 ascent
= NUMVAL (prop
) / 100.0;
1751 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1760 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1761 if (!STRINGP (object
))
1762 object
= it
->w
->buffer
;
1763 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1766 it
->pixel_width
= width
;
1767 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1768 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1771 if (face
->box
!= FACE_NO_BOX
)
1773 if (face
->box_line_width
> 0)
1775 it
->ascent
+= face
->box_line_width
;
1776 it
->descent
+= face
->box_line_width
;
1779 if (it
->start_of_box_run_p
)
1780 it
->pixel_width
+= abs (face
->box_line_width
);
1781 if (it
->end_of_box_run_p
)
1782 it
->pixel_width
+= abs (face
->box_line_width
);
1785 take_vertical_position_into_account (it
);
1788 /* Return proper value to be used as baseline offset of font that has
1789 ASCENT and DESCENT to draw characters by the font at the vertical
1790 center of the line of frame F.
1792 Here, out task is to find the value of BOFF in the following figure;
1794 -------------------------+-----------+-
1795 -+-+---------+-+ | |
1797 | | | | F_ASCENT F_HEIGHT
1800 | | |-|-+------+-----------|------- baseline
1802 | |---------|-+-+ | |
1804 -+-+---------+-+ F_DESCENT |
1805 -------------------------+-----------+-
1807 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1808 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1809 DESCENT = FONT->descent
1810 HEIGHT = FONT_HEIGHT (FONT)
1811 F_DESCENT = (F->output_data.x->font->descent
1812 - F->output_data.x->baseline_offset)
1813 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1816 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1818 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1819 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1820 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1822 /* Produce glyphs/get display metrics for the display element IT is
1823 loaded with. See the description of struct display_iterator in
1824 dispextern.h for an overview of struct display_iterator. */
1827 x_produce_glyphs (it
)
1830 it
->glyph_not_available_p
= 0;
1832 if (it
->what
== IT_CHARACTER
)
1836 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1838 int font_not_found_p
;
1839 struct font_info
*font_info
;
1840 int boff
; /* baseline offset */
1841 /* We may change it->multibyte_p upon unibyte<->multibyte
1842 conversion. So, save the current value now and restore it
1845 Note: It seems that we don't have to record multibyte_p in
1846 struct glyph because the character code itself tells if or
1847 not the character is multibyte. Thus, in the future, we must
1848 consider eliminating the field `multibyte_p' in the struct
1850 int saved_multibyte_p
= it
->multibyte_p
;
1852 /* Maybe translate single-byte characters to multibyte, or the
1854 it
->char_to_display
= it
->c
;
1855 if (!ASCII_BYTE_P (it
->c
))
1857 if (unibyte_display_via_language_environment
1858 && SINGLE_BYTE_CHAR_P (it
->c
)
1860 || !NILP (Vnonascii_translation_table
)))
1862 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1863 it
->multibyte_p
= 1;
1864 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1865 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1867 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1868 && !it
->multibyte_p
)
1870 it
->multibyte_p
= 1;
1871 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1872 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1876 /* Get font to use. Encode IT->char_to_display. */
1877 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1878 it
->face_id
, &char2b
,
1879 it
->multibyte_p
, 0);
1882 /* When no suitable font found, use the default font. */
1883 font_not_found_p
= font
== NULL
;
1884 if (font_not_found_p
)
1886 font
= FRAME_FONT (it
->f
);
1887 boff
= it
->f
->output_data
.x
->baseline_offset
;
1892 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1893 boff
= font_info
->baseline_offset
;
1894 if (font_info
->vertical_centering
)
1895 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1898 if (it
->char_to_display
>= ' '
1899 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1901 /* Either unibyte or ASCII. */
1906 pcm
= x_per_char_metric (font
, &char2b
);
1907 it
->ascent
= font
->ascent
+ boff
;
1908 it
->descent
= font
->descent
- boff
;
1912 it
->phys_ascent
= pcm
->ascent
+ boff
;
1913 it
->phys_descent
= pcm
->descent
- boff
;
1914 it
->pixel_width
= pcm
->width
;
1918 it
->glyph_not_available_p
= 1;
1919 it
->phys_ascent
= font
->ascent
+ boff
;
1920 it
->phys_descent
= font
->descent
- boff
;
1921 it
->pixel_width
= FONT_WIDTH (font
);
1924 /* If this is a space inside a region of text with
1925 `space-width' property, change its width. */
1926 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1928 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1930 /* If face has a box, add the box thickness to the character
1931 height. If character has a box line to the left and/or
1932 right, add the box line width to the character's width. */
1933 if (face
->box
!= FACE_NO_BOX
)
1935 int thick
= face
->box_line_width
;
1939 it
->ascent
+= thick
;
1940 it
->descent
+= thick
;
1945 if (it
->start_of_box_run_p
)
1946 it
->pixel_width
+= thick
;
1947 if (it
->end_of_box_run_p
)
1948 it
->pixel_width
+= thick
;
1951 /* If face has an overline, add the height of the overline
1952 (1 pixel) and a 1 pixel margin to the character height. */
1953 if (face
->overline_p
)
1956 take_vertical_position_into_account (it
);
1958 /* If we have to actually produce glyphs, do it. */
1963 /* Translate a space with a `space-width' property
1964 into a stretch glyph. */
1965 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1966 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1967 it
->ascent
+ it
->descent
, ascent
);
1970 x_append_glyph (it
);
1972 /* If characters with lbearing or rbearing are displayed
1973 in this line, record that fact in a flag of the
1974 glyph row. This is used to optimize X output code. */
1975 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1976 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1979 else if (it
->char_to_display
== '\n')
1981 /* A newline has no width but we need the height of the line. */
1982 it
->pixel_width
= 0;
1984 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1985 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1987 if (face
->box
!= FACE_NO_BOX
1988 && face
->box_line_width
> 0)
1990 it
->ascent
+= face
->box_line_width
;
1991 it
->descent
+= face
->box_line_width
;
1994 else if (it
->char_to_display
== '\t')
1996 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1997 int x
= it
->current_x
+ it
->continuation_lines_width
;
1998 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
2000 /* If the distance from the current position to the next tab
2001 stop is less than a canonical character width, use the
2002 tab stop after that. */
2003 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
2004 next_tab_x
+= tab_width
;
2006 it
->pixel_width
= next_tab_x
- x
;
2008 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
2009 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
2013 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
2014 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
2015 it
->ascent
+ it
->descent
, ascent
);
2020 /* A multi-byte character. Assume that the display width of the
2021 character is the width of the character multiplied by the
2022 width of the font. */
2024 /* If we found a font, this font should give us the right
2025 metrics. If we didn't find a font, use the frame's
2026 default font and calculate the width of the character
2027 from the charset width; this is what old redisplay code
2029 pcm
= x_per_char_metric (font
, &char2b
);
2030 if (font_not_found_p
|| !pcm
)
2032 int charset
= CHAR_CHARSET (it
->char_to_display
);
2034 it
->glyph_not_available_p
= 1;
2035 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2036 * CHARSET_WIDTH (charset
));
2037 it
->phys_ascent
= font
->ascent
+ boff
;
2038 it
->phys_descent
= font
->descent
- boff
;
2042 it
->pixel_width
= pcm
->width
;
2043 it
->phys_ascent
= pcm
->ascent
+ boff
;
2044 it
->phys_descent
= pcm
->descent
- boff
;
2046 && (pcm
->lbearing
< 0
2047 || pcm
->rbearing
> pcm
->width
))
2048 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2051 it
->ascent
= font
->ascent
+ boff
;
2052 it
->descent
= font
->descent
- boff
;
2053 if (face
->box
!= FACE_NO_BOX
)
2055 int thick
= face
->box_line_width
;
2059 it
->ascent
+= thick
;
2060 it
->descent
+= thick
;
2065 if (it
->start_of_box_run_p
)
2066 it
->pixel_width
+= thick
;
2067 if (it
->end_of_box_run_p
)
2068 it
->pixel_width
+= thick
;
2071 /* If face has an overline, add the height of the overline
2072 (1 pixel) and a 1 pixel margin to the character height. */
2073 if (face
->overline_p
)
2076 take_vertical_position_into_account (it
);
2079 x_append_glyph (it
);
2081 it
->multibyte_p
= saved_multibyte_p
;
2083 else if (it
->what
== IT_COMPOSITION
)
2085 /* Note: A composition is represented as one glyph in the
2086 glyph matrix. There are no padding glyphs. */
2089 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2091 int font_not_found_p
;
2092 struct font_info
*font_info
;
2093 int boff
; /* baseline offset */
2094 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2096 /* Maybe translate single-byte characters to multibyte. */
2097 it
->char_to_display
= it
->c
;
2098 if (unibyte_display_via_language_environment
2099 && SINGLE_BYTE_CHAR_P (it
->c
)
2102 && !NILP (Vnonascii_translation_table
))))
2104 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2107 /* Get face and font to use. Encode IT->char_to_display. */
2108 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2109 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2110 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2111 it
->face_id
, &char2b
, it
->multibyte_p
, 0);
2114 /* When no suitable font found, use the default font. */
2115 font_not_found_p
= font
== NULL
;
2116 if (font_not_found_p
)
2118 font
= FRAME_FONT (it
->f
);
2119 boff
= it
->f
->output_data
.x
->baseline_offset
;
2124 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2125 boff
= font_info
->baseline_offset
;
2126 if (font_info
->vertical_centering
)
2127 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2130 /* There are no padding glyphs, so there is only one glyph to
2131 produce for the composition. Important is that pixel_width,
2132 ascent and descent are the values of what is drawn by
2133 draw_glyphs (i.e. the values of the overall glyphs composed). */
2136 /* If we have not yet calculated pixel size data of glyphs of
2137 the composition for the current face font, calculate them
2138 now. Theoretically, we have to check all fonts for the
2139 glyphs, but that requires much time and memory space. So,
2140 here we check only the font of the first glyph. This leads
2141 to incorrect display very rarely, and C-l (recenter) can
2142 correct the display anyway. */
2143 if (cmp
->font
!= (void *) font
)
2145 /* Ascent and descent of the font of the first character of
2146 this composition (adjusted by baseline offset). Ascent
2147 and descent of overall glyphs should not be less than
2148 them respectively. */
2149 int font_ascent
= font
->ascent
+ boff
;
2150 int font_descent
= font
->descent
- boff
;
2151 /* Bounding box of the overall glyphs. */
2152 int leftmost
, rightmost
, lowest
, highest
;
2153 int i
, width
, ascent
, descent
;
2155 cmp
->font
= (void *) font
;
2157 /* Initialize the bounding box. */
2159 && (pcm
= x_per_char_metric (font
, &char2b
)))
2162 ascent
= pcm
->ascent
;
2163 descent
= pcm
->descent
;
2167 width
= FONT_WIDTH (font
);
2168 ascent
= font
->ascent
;
2169 descent
= font
->descent
;
2173 lowest
= - descent
+ boff
;
2174 highest
= ascent
+ boff
;
2178 && font_info
->default_ascent
2179 && CHAR_TABLE_P (Vuse_default_ascent
)
2180 && !NILP (Faref (Vuse_default_ascent
,
2181 make_number (it
->char_to_display
))))
2182 highest
= font_info
->default_ascent
+ boff
;
2184 /* Draw the first glyph at the normal position. It may be
2185 shifted to right later if some other glyphs are drawn at
2187 cmp
->offsets
[0] = 0;
2188 cmp
->offsets
[1] = boff
;
2190 /* Set cmp->offsets for the remaining glyphs. */
2191 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2193 int left
, right
, btm
, top
;
2194 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2195 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2197 face
= FACE_FROM_ID (it
->f
, face_id
);
2198 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2199 it
->multibyte_p
, 0);
2203 font
= FRAME_FONT (it
->f
);
2204 boff
= it
->f
->output_data
.x
->baseline_offset
;
2210 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2211 boff
= font_info
->baseline_offset
;
2212 if (font_info
->vertical_centering
)
2213 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2217 && (pcm
= x_per_char_metric (font
, &char2b
)))
2220 ascent
= pcm
->ascent
;
2221 descent
= pcm
->descent
;
2225 width
= FONT_WIDTH (font
);
2230 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2232 /* Relative composition with or without
2234 left
= (leftmost
+ rightmost
- width
) / 2;
2235 btm
= - descent
+ boff
;
2236 if (font_info
&& font_info
->relative_compose
2237 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2238 || NILP (Faref (Vignore_relative_composition
,
2239 make_number (ch
)))))
2242 if (- descent
>= font_info
->relative_compose
)
2243 /* One extra pixel between two glyphs. */
2245 else if (ascent
<= 0)
2246 /* One extra pixel between two glyphs. */
2247 btm
= lowest
- 1 - ascent
- descent
;
2252 /* A composition rule is specified by an integer
2253 value that encodes global and new reference
2254 points (GREF and NREF). GREF and NREF are
2255 specified by numbers as below:
2263 ---3---4---5--- baseline
2265 6---7---8 -- descent
2267 int rule
= COMPOSITION_RULE (cmp
, i
);
2268 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2270 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2271 grefx
= gref
% 3, nrefx
= nref
% 3;
2272 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2275 + grefx
* (rightmost
- leftmost
) / 2
2276 - nrefx
* width
/ 2);
2277 btm
= ((grefy
== 0 ? highest
2279 : grefy
== 2 ? lowest
2280 : (highest
+ lowest
) / 2)
2281 - (nrefy
== 0 ? ascent
+ descent
2282 : nrefy
== 1 ? descent
- boff
2284 : (ascent
+ descent
) / 2));
2287 cmp
->offsets
[i
* 2] = left
;
2288 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2290 /* Update the bounding box of the overall glyphs. */
2291 right
= left
+ width
;
2292 top
= btm
+ descent
+ ascent
;
2293 if (left
< leftmost
)
2295 if (right
> rightmost
)
2303 /* If there are glyphs whose x-offsets are negative,
2304 shift all glyphs to the right and make all x-offsets
2308 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2309 cmp
->offsets
[i
* 2] -= leftmost
;
2310 rightmost
-= leftmost
;
2313 cmp
->pixel_width
= rightmost
;
2314 cmp
->ascent
= highest
;
2315 cmp
->descent
= - lowest
;
2316 if (cmp
->ascent
< font_ascent
)
2317 cmp
->ascent
= font_ascent
;
2318 if (cmp
->descent
< font_descent
)
2319 cmp
->descent
= font_descent
;
2322 it
->pixel_width
= cmp
->pixel_width
;
2323 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2324 it
->descent
= it
->phys_descent
= cmp
->descent
;
2326 if (face
->box
!= FACE_NO_BOX
)
2328 int thick
= face
->box_line_width
;
2332 it
->ascent
+= thick
;
2333 it
->descent
+= thick
;
2338 if (it
->start_of_box_run_p
)
2339 it
->pixel_width
+= thick
;
2340 if (it
->end_of_box_run_p
)
2341 it
->pixel_width
+= thick
;
2344 /* If face has an overline, add the height of the overline
2345 (1 pixel) and a 1 pixel margin to the character height. */
2346 if (face
->overline_p
)
2349 take_vertical_position_into_account (it
);
2352 x_append_composite_glyph (it
);
2354 else if (it
->what
== IT_IMAGE
)
2355 x_produce_image_glyph (it
);
2356 else if (it
->what
== IT_STRETCH
)
2357 x_produce_stretch_glyph (it
);
2359 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2360 because this isn't true for images with `:ascent 100'. */
2361 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2362 if (it
->area
== TEXT_AREA
)
2363 it
->current_x
+= it
->pixel_width
;
2365 it
->descent
+= it
->extra_line_spacing
;
2367 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2368 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2369 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2370 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2374 /* Estimate the pixel height of the mode or top line on frame F.
2375 FACE_ID specifies what line's height to estimate. */
2378 x_estimate_mode_line_height (f
, face_id
)
2380 enum face_id face_id
;
2382 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2384 /* This function is called so early when Emacs starts that the face
2385 cache and mode line face are not yet initialized. */
2386 if (FRAME_FACE_CACHE (f
))
2388 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2392 height
= FONT_HEIGHT (face
->font
);
2393 if (face
->box_line_width
> 0)
2394 height
+= 2 * face
->box_line_width
;
2402 /***********************************************************************
2404 ***********************************************************************/
2406 /* A sequence of glyphs to be drawn in the same face.
2408 This data structure is not really completely X specific, so it
2409 could possibly, at least partially, be useful for other systems. It
2410 is currently not part of the external redisplay interface because
2411 it's not clear what other systems will need. */
2415 /* X-origin of the string. */
2418 /* Y-origin and y-position of the base line of this string. */
2421 /* The width of the string, not including a face extension. */
2424 /* The width of the string, including a face extension. */
2425 int background_width
;
2427 /* The height of this string. This is the height of the line this
2428 string is drawn in, and can be different from the height of the
2429 font the string is drawn in. */
2432 /* Number of pixels this string overwrites in front of its x-origin.
2433 This number is zero if the string has an lbearing >= 0; it is
2434 -lbearing, if the string has an lbearing < 0. */
2437 /* Number of pixels this string overwrites past its right-most
2438 nominal x-position, i.e. x + width. Zero if the string's
2439 rbearing is <= its nominal width, rbearing - width otherwise. */
2442 /* The frame on which the glyph string is drawn. */
2445 /* The window on which the glyph string is drawn. */
2448 /* X display and window for convenience. */
2452 /* The glyph row for which this string was built. It determines the
2453 y-origin and height of the string. */
2454 struct glyph_row
*row
;
2456 /* The area within row. */
2457 enum glyph_row_area area
;
2459 /* Characters to be drawn, and number of characters. */
2463 /* A face-override for drawing cursors, mouse face and similar. */
2464 enum draw_glyphs_face hl
;
2466 /* Face in which this string is to be drawn. */
2469 /* Font in which this string is to be drawn. */
2472 /* Font info for this string. */
2473 struct font_info
*font_info
;
2475 /* Non-null means this string describes (part of) a composition.
2476 All characters from char2b are drawn composed. */
2477 struct composition
*cmp
;
2479 /* Index of this glyph string's first character in the glyph
2480 definition of CMP. If this is zero, this glyph string describes
2481 the first character of a composition. */
2484 /* 1 means this glyph strings face has to be drawn to the right end
2485 of the window's drawing area. */
2486 unsigned extends_to_end_of_line_p
: 1;
2488 /* 1 means the background of this string has been drawn. */
2489 unsigned background_filled_p
: 1;
2491 /* 1 means glyph string must be drawn with 16-bit functions. */
2492 unsigned two_byte_p
: 1;
2494 /* 1 means that the original font determined for drawing this glyph
2495 string could not be loaded. The member `font' has been set to
2496 the frame's default font in this case. */
2497 unsigned font_not_found_p
: 1;
2499 /* 1 means that the face in which this glyph string is drawn has a
2501 unsigned stippled_p
: 1;
2503 /* 1 means only the foreground of this glyph string must be drawn,
2504 and we should use the physical height of the line this glyph
2505 string appears in as clip rect. */
2506 unsigned for_overlaps_p
: 1;
2508 /* The GC to use for drawing this glyph string. */
2511 /* A pointer to the first glyph in the string. This glyph
2512 corresponds to char2b[0]. Needed to draw rectangles if
2513 font_not_found_p is 1. */
2514 struct glyph
*first_glyph
;
2516 /* Image, if any. */
2519 struct glyph_string
*next
, *prev
;
2526 x_dump_glyph_string (s
)
2527 struct glyph_string
*s
;
2529 fprintf (stderr
, "glyph string\n");
2530 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2531 s
->x
, s
->y
, s
->width
, s
->height
);
2532 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2533 fprintf (stderr
, " hl = %d\n", s
->hl
);
2534 fprintf (stderr
, " left overhang = %d, right = %d\n",
2535 s
->left_overhang
, s
->right_overhang
);
2536 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2537 fprintf (stderr
, " extends to end of line = %d\n",
2538 s
->extends_to_end_of_line_p
);
2539 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2540 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2543 #endif /* GLYPH_DEBUG */
2547 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2548 struct glyph_string
**,
2549 struct glyph_string
*,
2550 struct glyph_string
*));
2551 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2552 struct glyph_string
**,
2553 struct glyph_string
*,
2554 struct glyph_string
*));
2555 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2556 struct glyph_string
**,
2557 struct glyph_string
*));
2558 static int x_left_overwritten
P_ ((struct glyph_string
*));
2559 static int x_left_overwriting
P_ ((struct glyph_string
*));
2560 static int x_right_overwritten
P_ ((struct glyph_string
*));
2561 static int x_right_overwriting
P_ ((struct glyph_string
*));
2562 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2564 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2565 XChar2b
*, struct window
*,
2567 enum glyph_row_area
, int,
2568 enum draw_glyphs_face
));
2569 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2570 enum glyph_row_area
, int, int,
2571 enum draw_glyphs_face
, int));
2572 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2573 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2574 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2576 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2577 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2578 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2579 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2580 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2581 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2582 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2583 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2584 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2586 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2587 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2588 unsigned long *, double, int));
2589 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2590 double, int, unsigned long));
2591 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2592 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2593 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2594 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2595 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2596 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2597 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2599 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2600 int, int, int, int, XRectangle
*));
2601 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2602 int, int, int, XRectangle
*));
2603 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2604 enum glyph_row_area
));
2605 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2607 enum glyph_row_area
, int, int));
2610 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2614 /* Append the list of glyph strings with head H and tail T to the list
2615 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2618 x_append_glyph_string_lists (head
, tail
, h
, t
)
2619 struct glyph_string
**head
, **tail
;
2620 struct glyph_string
*h
, *t
;
2634 /* Prepend the list of glyph strings with head H and tail T to the
2635 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2639 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2640 struct glyph_string
**head
, **tail
;
2641 struct glyph_string
*h
, *t
;
2655 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2656 Set *HEAD and *TAIL to the resulting list. */
2659 x_append_glyph_string (head
, tail
, s
)
2660 struct glyph_string
**head
, **tail
;
2661 struct glyph_string
*s
;
2663 s
->next
= s
->prev
= NULL
;
2664 x_append_glyph_string_lists (head
, tail
, s
, s
);
2668 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2673 struct glyph_string
*s
;
2675 if (s
->font
== FRAME_FONT (s
->f
)
2676 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2677 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2679 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2682 /* Cursor on non-default face: must merge. */
2686 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2687 xgcv
.foreground
= s
->face
->background
;
2689 /* If the glyph would be invisible, try a different foreground. */
2690 if (xgcv
.foreground
== xgcv
.background
)
2691 xgcv
.foreground
= s
->face
->foreground
;
2692 if (xgcv
.foreground
== xgcv
.background
)
2693 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2694 if (xgcv
.foreground
== xgcv
.background
)
2695 xgcv
.foreground
= s
->face
->foreground
;
2697 /* Make sure the cursor is distinct from text in this face. */
2698 if (xgcv
.background
== s
->face
->background
2699 && xgcv
.foreground
== s
->face
->foreground
)
2701 xgcv
.background
= s
->face
->foreground
;
2702 xgcv
.foreground
= s
->face
->background
;
2705 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2706 xgcv
.font
= s
->font
->fid
;
2707 xgcv
.graphics_exposures
= False
;
2708 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2710 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2711 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2714 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2715 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2717 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2722 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2725 x_set_mouse_face_gc (s
)
2726 struct glyph_string
*s
;
2731 /* What face has to be used last for the mouse face? */
2732 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2733 face
= FACE_FROM_ID (s
->f
, face_id
);
2735 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2737 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2738 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2740 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2741 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2742 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2744 /* If font in this face is same as S->font, use it. */
2745 if (s
->font
== s
->face
->font
)
2746 s
->gc
= s
->face
->gc
;
2749 /* Otherwise construct scratch_cursor_gc with values from FACE
2754 xgcv
.background
= s
->face
->background
;
2755 xgcv
.foreground
= s
->face
->foreground
;
2756 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2757 xgcv
.font
= s
->font
->fid
;
2758 xgcv
.graphics_exposures
= False
;
2759 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2761 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2762 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2765 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2766 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2768 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2771 xassert (s
->gc
!= 0);
2775 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2776 Faces to use in the mode line have already been computed when the
2777 matrix was built, so there isn't much to do, here. */
2780 x_set_mode_line_face_gc (s
)
2781 struct glyph_string
*s
;
2783 s
->gc
= s
->face
->gc
;
2787 /* Set S->gc of glyph string S for drawing that glyph string. Set
2788 S->stippled_p to a non-zero value if the face of S has a stipple
2792 x_set_glyph_string_gc (s
)
2793 struct glyph_string
*s
;
2795 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2797 if (s
->hl
== DRAW_NORMAL_TEXT
)
2799 s
->gc
= s
->face
->gc
;
2800 s
->stippled_p
= s
->face
->stipple
!= 0;
2802 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2804 x_set_mode_line_face_gc (s
);
2805 s
->stippled_p
= s
->face
->stipple
!= 0;
2807 else if (s
->hl
== DRAW_CURSOR
)
2809 x_set_cursor_gc (s
);
2812 else if (s
->hl
== DRAW_MOUSE_FACE
)
2814 x_set_mouse_face_gc (s
);
2815 s
->stippled_p
= s
->face
->stipple
!= 0;
2817 else if (s
->hl
== DRAW_IMAGE_RAISED
2818 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2820 s
->gc
= s
->face
->gc
;
2821 s
->stippled_p
= s
->face
->stipple
!= 0;
2825 s
->gc
= s
->face
->gc
;
2826 s
->stippled_p
= s
->face
->stipple
!= 0;
2829 /* GC must have been set. */
2830 xassert (s
->gc
!= 0);
2834 /* Return in *R the clipping rectangle for glyph string S. */
2837 x_get_glyph_string_clip_rect (s
, r
)
2838 struct glyph_string
*s
;
2841 if (s
->row
->full_width_p
)
2843 /* Draw full-width. X coordinates are relative to S->w->left. */
2844 int canon_x
= CANON_X_UNIT (s
->f
);
2846 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2847 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2849 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2851 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2852 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2856 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2858 /* Unless displaying a mode or menu bar line, which are always
2859 fully visible, clip to the visible part of the row. */
2860 if (s
->w
->pseudo_window_p
)
2861 r
->height
= s
->row
->visible_height
;
2863 r
->height
= s
->height
;
2867 /* This is a text line that may be partially visible. */
2868 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2869 r
->width
= window_box_width (s
->w
, s
->area
);
2870 r
->height
= s
->row
->visible_height
;
2873 /* If S draws overlapping rows, it's sufficient to use the top and
2874 bottom of the window for clipping because this glyph string
2875 intentionally draws over other lines. */
2876 if (s
->for_overlaps_p
)
2878 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2879 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2883 /* Don't use S->y for clipping because it doesn't take partially
2884 visible lines into account. For example, it can be negative for
2885 partially visible lines at the top of a window. */
2886 if (!s
->row
->full_width_p
2887 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2888 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2890 r
->y
= max (0, s
->row
->y
);
2892 /* If drawing a tool-bar window, draw it over the internal border
2893 at the top of the window. */
2894 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2895 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2898 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2902 /* Set clipping for output of glyph string S. S may be part of a mode
2903 line or menu if we don't have X toolkit support. */
2906 x_set_glyph_string_clipping (s
)
2907 struct glyph_string
*s
;
2910 x_get_glyph_string_clip_rect (s
, &r
);
2911 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2915 /* Compute left and right overhang of glyph string S. If S is a glyph
2916 string for a composition, assume overhangs don't exist. */
2919 x_compute_glyph_string_overhangs (s
)
2920 struct glyph_string
*s
;
2923 && s
->first_glyph
->type
== CHAR_GLYPH
)
2926 int direction
, font_ascent
, font_descent
;
2927 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2928 &font_ascent
, &font_descent
, &cs
);
2929 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2930 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2935 /* Compute overhangs and x-positions for glyph string S and its
2936 predecessors, or successors. X is the starting x-position for S.
2937 BACKWARD_P non-zero means process predecessors. */
2940 x_compute_overhangs_and_x (s
, x
, backward_p
)
2941 struct glyph_string
*s
;
2949 x_compute_glyph_string_overhangs (s
);
2959 x_compute_glyph_string_overhangs (s
);
2968 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2969 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2970 assumed to be zero. */
2973 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2974 struct glyph
*glyph
;
2980 if (glyph
->type
== CHAR_GLYPH
)
2984 struct font_info
*font_info
;
2988 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2990 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2992 && (pcm
= x_per_char_metric (font
, &char2b
)))
2994 if (pcm
->rbearing
> pcm
->width
)
2995 *right
= pcm
->rbearing
- pcm
->width
;
2996 if (pcm
->lbearing
< 0)
2997 *left
= -pcm
->lbearing
;
3003 /* Return the index of the first glyph preceding glyph string S that
3004 is overwritten by S because of S's left overhang. Value is -1
3005 if no glyphs are overwritten. */
3008 x_left_overwritten (s
)
3009 struct glyph_string
*s
;
3013 if (s
->left_overhang
)
3016 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3017 int first
= s
->first_glyph
- glyphs
;
3019 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
3020 x
-= glyphs
[i
].pixel_width
;
3031 /* Return the index of the first glyph preceding glyph string S that
3032 is overwriting S because of its right overhang. Value is -1 if no
3033 glyph in front of S overwrites S. */
3036 x_left_overwriting (s
)
3037 struct glyph_string
*s
;
3040 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3041 int first
= s
->first_glyph
- glyphs
;
3045 for (i
= first
- 1; i
>= 0; --i
)
3048 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3051 x
-= glyphs
[i
].pixel_width
;
3058 /* Return the index of the last glyph following glyph string S that is
3059 not overwritten by S because of S's right overhang. Value is -1 if
3060 no such glyph is found. */
3063 x_right_overwritten (s
)
3064 struct glyph_string
*s
;
3068 if (s
->right_overhang
)
3071 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3072 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3073 int end
= s
->row
->used
[s
->area
];
3075 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3076 x
+= glyphs
[i
].pixel_width
;
3085 /* Return the index of the last glyph following glyph string S that
3086 overwrites S because of its left overhang. Value is negative
3087 if no such glyph is found. */
3090 x_right_overwriting (s
)
3091 struct glyph_string
*s
;
3094 int end
= s
->row
->used
[s
->area
];
3095 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3096 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3100 for (i
= first
; i
< end
; ++i
)
3103 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3106 x
+= glyphs
[i
].pixel_width
;
3113 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3116 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3117 struct glyph_string
*s
;
3121 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3122 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3123 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3124 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3128 /* Draw the background of glyph_string S. If S->background_filled_p
3129 is non-zero don't draw it. FORCE_P non-zero means draw the
3130 background even if it wouldn't be drawn normally. This is used
3131 when a string preceding S draws into the background of S, or S
3132 contains the first component of a composition. */
3135 x_draw_glyph_string_background (s
, force_p
)
3136 struct glyph_string
*s
;
3139 /* Nothing to do if background has already been drawn or if it
3140 shouldn't be drawn in the first place. */
3141 if (!s
->background_filled_p
)
3143 int box_line_width
= max (s
->face
->box_line_width
, 0);
3147 /* Fill background with a stipple pattern. */
3148 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3149 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3150 s
->y
+ box_line_width
,
3151 s
->background_width
,
3152 s
->height
- 2 * box_line_width
);
3153 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3154 s
->background_filled_p
= 1;
3156 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3157 || s
->font_not_found_p
3158 || s
->extends_to_end_of_line_p
3161 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3162 s
->background_width
,
3163 s
->height
- 2 * box_line_width
);
3164 s
->background_filled_p
= 1;
3170 /* Draw the foreground of glyph string S. */
3173 x_draw_glyph_string_foreground (s
)
3174 struct glyph_string
*s
;
3178 /* If first glyph of S has a left box line, start drawing the text
3179 of S to the right of that box line. */
3180 if (s
->face
->box
!= FACE_NO_BOX
3181 && s
->first_glyph
->left_box_line_p
)
3182 x
= s
->x
+ abs (s
->face
->box_line_width
);
3186 /* Draw characters of S as rectangles if S's font could not be
3188 if (s
->font_not_found_p
)
3190 for (i
= 0; i
< s
->nchars
; ++i
)
3192 struct glyph
*g
= s
->first_glyph
+ i
;
3193 XDrawRectangle (s
->display
, s
->window
,
3194 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3196 x
+= g
->pixel_width
;
3201 char *char1b
= (char *) s
->char2b
;
3202 int boff
= s
->font_info
->baseline_offset
;
3204 if (s
->font_info
->vertical_centering
)
3205 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3207 /* If we can use 8-bit functions, condense S->char2b. */
3209 for (i
= 0; i
< s
->nchars
; ++i
)
3210 char1b
[i
] = s
->char2b
[i
].byte2
;
3212 /* Draw text with XDrawString if background has already been
3213 filled. Otherwise, use XDrawImageString. (Note that
3214 XDrawImageString is usually faster than XDrawString.) Always
3215 use XDrawImageString when drawing the cursor so that there is
3216 no chance that characters under a box cursor are invisible. */
3217 if (s
->for_overlaps_p
3218 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3220 /* Draw characters with 16-bit or 8-bit functions. */
3222 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3223 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3225 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3226 s
->ybase
- boff
, char1b
, s
->nchars
);
3231 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3232 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3234 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3235 s
->ybase
- boff
, char1b
, s
->nchars
);
3238 if (s
->face
->overstrike
)
3240 /* For overstriking (to simulate bold-face), draw the
3241 characters again shifted to the right by one pixel. */
3243 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
3244 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3246 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
3247 s
->ybase
- boff
, char1b
, s
->nchars
);
3252 /* Draw the foreground of composite glyph string S. */
3255 x_draw_composite_glyph_string_foreground (s
)
3256 struct glyph_string
*s
;
3260 /* If first glyph of S has a left box line, start drawing the text
3261 of S to the right of that box line. */
3262 if (s
->face
->box
!= FACE_NO_BOX
3263 && s
->first_glyph
->left_box_line_p
)
3264 x
= s
->x
+ abs (s
->face
->box_line_width
);
3268 /* S is a glyph string for a composition. S->gidx is the index of
3269 the first character drawn for glyphs of this composition.
3270 S->gidx == 0 means we are drawing the very first character of
3271 this composition. */
3273 /* Draw a rectangle for the composition if the font for the very
3274 first character of the composition could not be loaded. */
3275 if (s
->font_not_found_p
)
3278 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3279 s
->width
- 1, s
->height
- 1);
3283 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3285 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3286 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3287 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3289 if (s
->face
->overstrike
)
3290 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3291 x
+ s
->cmp
->offsets
[s
->gidx
* 2] + 1,
3292 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3299 #ifdef USE_X_TOOLKIT
3301 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3302 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3303 XrmValue
*, XrmValue
*, XtPointer
*));
3304 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3305 XrmValue
*, Cardinal
*));
3308 /* Return the frame on which widget WIDGET is used.. Abort if frame
3309 cannot be determined. */
3311 static struct frame
*
3312 x_frame_of_widget (widget
)
3315 struct x_display_info
*dpyinfo
;
3319 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3321 /* Find the top-level shell of the widget. Note that this function
3322 can be called when the widget is not yet realized, so XtWindow
3323 (widget) == 0. That's the reason we can't simply use
3324 x_any_window_to_frame. */
3325 while (!XtIsTopLevelShell (widget
))
3326 widget
= XtParent (widget
);
3328 /* Look for a frame with that top-level widget. Allocate the color
3329 on that frame to get the right gamma correction value. */
3330 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3331 if (GC_FRAMEP (XCAR (tail
))
3332 && (f
= XFRAME (XCAR (tail
)),
3333 (f
->output_data
.nothing
!= 1
3334 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3335 && f
->output_data
.x
->widget
== widget
)
3342 /* Allocate the color COLOR->pixel on the screen and display of
3343 widget WIDGET in colormap CMAP. If an exact match cannot be
3344 allocated, try the nearest color available. Value is non-zero
3345 if successful. This is called from lwlib. */
3348 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3353 struct frame
*f
= x_frame_of_widget (widget
);
3354 return x_alloc_nearest_color (f
, cmap
, color
);
3358 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3359 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3360 If this produces the same color as PIXEL, try a color where all RGB
3361 values have DELTA added. Return the allocated color in *PIXEL.
3362 DISPLAY is the X display, CMAP is the colormap to operate on.
3363 Value is non-zero if successful. */
3366 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3370 unsigned long *pixel
;
3374 struct frame
*f
= x_frame_of_widget (widget
);
3375 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3379 /* Structure specifying which arguments should be passed by Xt to
3380 cvt_string_to_pixel. We want the widget's screen and colormap. */
3382 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3384 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3386 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3391 /* The address of this variable is returned by
3392 cvt_string_to_pixel. */
3394 static Pixel cvt_string_to_pixel_value
;
3397 /* Convert a color name to a pixel color.
3399 DPY is the display we are working on.
3401 ARGS is an array of *NARGS XrmValue structures holding additional
3402 information about the widget for which the conversion takes place.
3403 The contents of this array are determined by the specification
3404 in cvt_string_to_pixel_args.
3406 FROM is a pointer to an XrmValue which points to the color name to
3407 convert. TO is an XrmValue in which to return the pixel color.
3409 CLOSURE_RET is a pointer to user-data, in which we record if
3410 we allocated the color or not.
3412 Value is True if successful, False otherwise. */
3415 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3419 XrmValue
*from
, *to
;
3420 XtPointer
*closure_ret
;
3430 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3431 "wrongParameters", "cvt_string_to_pixel",
3433 "Screen and colormap args required", NULL
, NULL
);
3437 screen
= *(Screen
**) args
[0].addr
;
3438 cmap
= *(Colormap
*) args
[1].addr
;
3439 color_name
= (String
) from
->addr
;
3441 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3443 *closure_ret
= (XtPointer
) False
;
3444 pixel
= WhitePixelOfScreen (screen
);
3446 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3448 *closure_ret
= (XtPointer
) False
;
3449 pixel
= BlackPixelOfScreen (screen
);
3451 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3452 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3454 pixel
= color
.pixel
;
3455 *closure_ret
= (XtPointer
) True
;
3460 Cardinal nparams
= 1;
3462 params
[0] = color_name
;
3463 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3464 "badValue", "cvt_string_to_pixel",
3465 "XtToolkitError", "Invalid color `%s'",
3470 if (to
->addr
!= NULL
)
3472 if (to
->size
< sizeof (Pixel
))
3474 to
->size
= sizeof (Pixel
);
3478 *(Pixel
*) to
->addr
= pixel
;
3482 cvt_string_to_pixel_value
= pixel
;
3483 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3486 to
->size
= sizeof (Pixel
);
3491 /* Free a pixel color which was previously allocated via
3492 cvt_string_to_pixel. This is registered as the destructor
3493 for this type of resource via XtSetTypeConverter.
3495 APP is the application context in which we work.
3497 TO is a pointer to an XrmValue holding the color to free.
3498 CLOSURE is the value we stored in CLOSURE_RET for this color
3499 in cvt_string_to_pixel.
3501 ARGS and NARGS are like for cvt_string_to_pixel. */
3504 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3513 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3515 "Screen and colormap arguments required",
3518 else if (closure
!= NULL
)
3520 /* We did allocate the pixel, so free it. */
3521 Screen
*screen
= *(Screen
**) args
[0].addr
;
3522 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3523 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3524 (Pixel
*) to
->addr
, 1);
3529 #endif /* USE_X_TOOLKIT */
3532 /* Value is an array of XColor structures for the contents of the
3533 color map of display DPY. Set *NCELLS to the size of the array.
3534 Note that this probably shouldn't be called for large color maps,
3535 say a 24-bit TrueColor map. */
3537 static const XColor
*
3538 x_color_cells (dpy
, ncells
)
3542 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3544 if (dpyinfo
->color_cells
== NULL
)
3546 Screen
*screen
= dpyinfo
->screen
;
3549 dpyinfo
->ncolor_cells
3550 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3551 dpyinfo
->color_cells
3552 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3553 * sizeof *dpyinfo
->color_cells
);
3555 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3556 dpyinfo
->color_cells
[i
].pixel
= i
;
3558 XQueryColors (dpy
, dpyinfo
->cmap
,
3559 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3562 *ncells
= dpyinfo
->ncolor_cells
;
3563 return dpyinfo
->color_cells
;
3567 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3568 colors in COLORS. Use cached information, if available. */
3571 x_query_colors (f
, colors
, ncolors
)
3576 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3578 if (dpyinfo
->color_cells
)
3581 for (i
= 0; i
< ncolors
; ++i
)
3583 unsigned long pixel
= colors
[i
].pixel
;
3584 xassert (pixel
< dpyinfo
->ncolor_cells
);
3585 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3586 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3590 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3594 /* On frame F, translate pixel color to RGB values for the color in
3595 COLOR. Use cached information, if available. */
3598 x_query_color (f
, color
)
3602 x_query_colors (f
, color
, 1);
3606 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3607 exact match can't be allocated, try the nearest color available.
3608 Value is non-zero if successful. Set *COLOR to the color
3612 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3619 rc
= XAllocColor (dpy
, cmap
, color
);
3622 /* If we got to this point, the colormap is full, so we're going
3623 to try to get the next closest color. The algorithm used is
3624 a least-squares matching, which is what X uses for closest
3625 color matching with StaticColor visuals. */
3627 unsigned long nearest_delta
= ~0;
3629 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3631 for (nearest
= i
= 0; i
< ncells
; ++i
)
3633 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3634 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3635 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3636 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3638 if (delta
< nearest_delta
)
3641 nearest_delta
= delta
;
3645 color
->red
= cells
[nearest
].red
;
3646 color
->green
= cells
[nearest
].green
;
3647 color
->blue
= cells
[nearest
].blue
;
3648 rc
= XAllocColor (dpy
, cmap
, color
);
3652 /* If allocation succeeded, and the allocated pixel color is not
3653 equal to a cached pixel color recorded earlier, there was a
3654 change in the colormap, so clear the color cache. */
3655 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3656 XColor
*cached_color
;
3658 if (dpyinfo
->color_cells
3659 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3660 (cached_color
->red
!= color
->red
3661 || cached_color
->blue
!= color
->blue
3662 || cached_color
->green
!= color
->green
)))
3664 xfree (dpyinfo
->color_cells
);
3665 dpyinfo
->color_cells
= NULL
;
3666 dpyinfo
->ncolor_cells
= 0;
3670 #ifdef DEBUG_X_COLORS
3672 register_color (color
->pixel
);
3673 #endif /* DEBUG_X_COLORS */
3679 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3680 exact match can't be allocated, try the nearest color available.
3681 Value is non-zero if successful. Set *COLOR to the color
3685 x_alloc_nearest_color (f
, cmap
, color
)
3690 gamma_correct (f
, color
);
3691 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3695 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3696 It's necessary to do this instead of just using PIXEL directly to
3697 get color reference counts right. */
3700 x_copy_color (f
, pixel
)
3702 unsigned long pixel
;
3706 color
.pixel
= pixel
;
3708 x_query_color (f
, &color
);
3709 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3711 #ifdef DEBUG_X_COLORS
3712 register_color (pixel
);
3718 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3719 It's necessary to do this instead of just using PIXEL directly to
3720 get color reference counts right. */
3723 x_copy_dpy_color (dpy
, cmap
, pixel
)
3726 unsigned long pixel
;
3730 color
.pixel
= pixel
;
3732 XQueryColor (dpy
, cmap
, &color
);
3733 XAllocColor (dpy
, cmap
, &color
);
3735 #ifdef DEBUG_X_COLORS
3736 register_color (pixel
);
3742 /* Brightness beyond which a color won't have its highlight brightness
3745 Nominally, highlight colors for `3d' faces are calculated by
3746 brightening an object's color by a constant scale factor, but this
3747 doesn't yield good results for dark colors, so for colors who's
3748 brightness is less than this value (on a scale of 0-65535) have an
3749 use an additional additive factor.
3751 The value here is set so that the default menu-bar/mode-line color
3752 (grey75) will not have its highlights changed at all. */
3753 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3756 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3757 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3758 If this produces the same color as PIXEL, try a color where all RGB
3759 values have DELTA added. Return the allocated color in *PIXEL.
3760 DISPLAY is the X display, CMAP is the colormap to operate on.
3761 Value is non-zero if successful. */
3764 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3768 unsigned long *pixel
;
3776 /* Get RGB color values. */
3777 color
.pixel
= *pixel
;
3778 x_query_color (f
, &color
);
3780 /* Change RGB values by specified FACTOR. Avoid overflow! */
3781 xassert (factor
>= 0);
3782 new.red
= min (0xffff, factor
* color
.red
);
3783 new.green
= min (0xffff, factor
* color
.green
);
3784 new.blue
= min (0xffff, factor
* color
.blue
);
3786 /* Calculate brightness of COLOR. */
3787 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3789 /* We only boost colors that are darker than
3790 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3791 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3792 /* Make an additive adjustment to NEW, because it's dark enough so
3793 that scaling by FACTOR alone isn't enough. */
3795 /* How far below the limit this color is (0 - 1, 1 being darker). */
3796 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3797 /* The additive adjustment. */
3798 int min_delta
= delta
* dimness
* factor
/ 2;
3802 new.red
= max (0, new.red
- min_delta
);
3803 new.green
= max (0, new.green
- min_delta
);
3804 new.blue
= max (0, new.blue
- min_delta
);
3808 new.red
= min (0xffff, min_delta
+ new.red
);
3809 new.green
= min (0xffff, min_delta
+ new.green
);
3810 new.blue
= min (0xffff, min_delta
+ new.blue
);
3814 /* Try to allocate the color. */
3815 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3818 if (new.pixel
== *pixel
)
3820 /* If we end up with the same color as before, try adding
3821 delta to the RGB values. */
3822 x_free_colors (f
, &new.pixel
, 1);
3824 new.red
= min (0xffff, delta
+ color
.red
);
3825 new.green
= min (0xffff, delta
+ color
.green
);
3826 new.blue
= min (0xffff, delta
+ color
.blue
);
3827 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3838 /* Set up the foreground color for drawing relief lines of glyph
3839 string S. RELIEF is a pointer to a struct relief containing the GC
3840 with which lines will be drawn. Use a color that is FACTOR or
3841 DELTA lighter or darker than the relief's background which is found
3842 in S->f->output_data.x->relief_background. If such a color cannot
3843 be allocated, use DEFAULT_PIXEL, instead. */
3846 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3848 struct relief
*relief
;
3851 unsigned long default_pixel
;
3854 struct x_output
*di
= f
->output_data
.x
;
3855 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3856 unsigned long pixel
;
3857 unsigned long background
= di
->relief_background
;
3858 Colormap cmap
= FRAME_X_COLORMAP (f
);
3859 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3860 Display
*dpy
= FRAME_X_DISPLAY (f
);
3862 xgcv
.graphics_exposures
= False
;
3863 xgcv
.line_width
= 1;
3865 /* Free previously allocated color. The color cell will be reused
3866 when it has been freed as many times as it was allocated, so this
3867 doesn't affect faces using the same colors. */
3869 && relief
->allocated_p
)
3871 x_free_colors (f
, &relief
->pixel
, 1);
3872 relief
->allocated_p
= 0;
3875 /* Allocate new color. */
3876 xgcv
.foreground
= default_pixel
;
3878 if (dpyinfo
->n_planes
!= 1
3879 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3881 relief
->allocated_p
= 1;
3882 xgcv
.foreground
= relief
->pixel
= pixel
;
3885 if (relief
->gc
== 0)
3887 xgcv
.stipple
= dpyinfo
->gray
;
3889 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3892 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3896 /* Set up colors for the relief lines around glyph string S. */
3899 x_setup_relief_colors (s
)
3900 struct glyph_string
*s
;
3902 struct x_output
*di
= s
->f
->output_data
.x
;
3903 unsigned long color
;
3905 if (s
->face
->use_box_color_for_shadows_p
)
3906 color
= s
->face
->box_color
;
3907 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3909 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3910 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3915 /* Get the background color of the face. */
3916 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3917 color
= xgcv
.background
;
3920 if (di
->white_relief
.gc
== 0
3921 || color
!= di
->relief_background
)
3923 di
->relief_background
= color
;
3924 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3925 WHITE_PIX_DEFAULT (s
->f
));
3926 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3927 BLACK_PIX_DEFAULT (s
->f
));
3932 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3933 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3934 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3935 relief. LEFT_P non-zero means draw a relief on the left side of
3936 the rectangle. RIGHT_P non-zero means draw a relief on the right
3937 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3941 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3942 raised_p
, left_p
, right_p
, clip_rect
)
3944 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
, raised_p
;
3945 XRectangle
*clip_rect
;
3947 Display
*dpy
= FRAME_X_DISPLAY (f
);
3948 Window window
= FRAME_X_WINDOW (f
);
3953 gc
= f
->output_data
.x
->white_relief
.gc
;
3955 gc
= f
->output_data
.x
->black_relief
.gc
;
3956 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3959 for (i
= 0; i
< width
; ++i
)
3960 XDrawLine (dpy
, window
, gc
,
3961 left_x
+ i
* left_p
, top_y
+ i
,
3962 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3966 for (i
= 0; i
< width
; ++i
)
3967 XDrawLine (dpy
, window
, gc
,
3968 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3970 XSetClipMask (dpy
, gc
, None
);
3972 gc
= f
->output_data
.x
->black_relief
.gc
;
3974 gc
= f
->output_data
.x
->white_relief
.gc
;
3975 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3978 for (i
= 0; i
< width
; ++i
)
3979 XDrawLine (dpy
, window
, gc
,
3980 left_x
+ i
* left_p
, bottom_y
- i
,
3981 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3985 for (i
= 0; i
< width
; ++i
)
3986 XDrawLine (dpy
, window
, gc
,
3987 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3989 XSetClipMask (dpy
, gc
, None
);
3993 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3994 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3995 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3996 left side of the rectangle. RIGHT_P non-zero means draw a line
3997 on the right side of the rectangle. CLIP_RECT is the clipping
3998 rectangle to use when drawing. */
4001 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4002 left_p
, right_p
, clip_rect
)
4003 struct glyph_string
*s
;
4004 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
4005 XRectangle
*clip_rect
;
4009 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4010 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
4011 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
4014 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4015 left_x
, top_y
, right_x
- left_x
+ 1, width
);
4019 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4020 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
4023 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4024 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
4028 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4029 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
4031 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4032 XSetClipMask (s
->display
, s
->gc
, None
);
4036 /* Draw a box around glyph string S. */
4039 x_draw_glyph_string_box (s
)
4040 struct glyph_string
*s
;
4042 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
4043 int left_p
, right_p
;
4044 struct glyph
*last_glyph
;
4045 XRectangle clip_rect
;
4047 last_x
= window_box_right (s
->w
, s
->area
);
4048 if (s
->row
->full_width_p
4049 && !s
->w
->pseudo_window_p
)
4051 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
4052 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
4053 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
4056 /* The glyph that may have a right box line. */
4057 last_glyph
= (s
->cmp
|| s
->img
4059 : s
->first_glyph
+ s
->nchars
- 1);
4061 width
= abs (s
->face
->box_line_width
);
4062 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
4064 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
4066 : min (last_x
, s
->x
+ s
->background_width
) - 1);
4068 bottom_y
= top_y
+ s
->height
- 1;
4070 left_p
= (s
->first_glyph
->left_box_line_p
4071 || (s
->hl
== DRAW_MOUSE_FACE
4073 || s
->prev
->hl
!= s
->hl
)));
4074 right_p
= (last_glyph
->right_box_line_p
4075 || (s
->hl
== DRAW_MOUSE_FACE
4077 || s
->next
->hl
!= s
->hl
)));
4079 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4081 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4082 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4083 left_p
, right_p
, &clip_rect
);
4086 x_setup_relief_colors (s
);
4087 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4088 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4093 /* Draw foreground of image glyph string S. */
4096 x_draw_image_foreground (s
)
4097 struct glyph_string
*s
;
4100 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4102 /* If first glyph of S has a left box line, start drawing it to the
4103 right of that line. */
4104 if (s
->face
->box
!= FACE_NO_BOX
4105 && s
->first_glyph
->left_box_line_p
)
4106 x
= s
->x
+ abs (s
->face
->box_line_width
);
4110 /* If there is a margin around the image, adjust x- and y-position
4112 x
+= s
->img
->hmargin
;
4113 y
+= s
->img
->vmargin
;
4119 /* We can't set both a clip mask and use XSetClipRectangles
4120 because the latter also sets a clip mask. We also can't
4121 trust on the shape extension to be available
4122 (XShapeCombineRegion). So, compute the rectangle to draw
4124 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4127 XRectangle clip_rect
, image_rect
, r
;
4129 xgcv
.clip_mask
= s
->img
->mask
;
4130 xgcv
.clip_x_origin
= x
;
4131 xgcv
.clip_y_origin
= y
;
4132 xgcv
.function
= GXcopy
;
4133 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4135 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4138 image_rect
.width
= s
->img
->width
;
4139 image_rect
.height
= s
->img
->height
;
4140 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4141 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4142 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4146 XRectangle clip_rect
, image_rect
, r
;
4148 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4151 image_rect
.width
= s
->img
->width
;
4152 image_rect
.height
= s
->img
->height
;
4153 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4154 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4155 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4157 /* When the image has a mask, we can expect that at
4158 least part of a mouse highlight or a block cursor will
4159 be visible. If the image doesn't have a mask, make
4160 a block cursor visible by drawing a rectangle around
4161 the image. I believe it's looking better if we do
4162 nothing here for mouse-face. */
4163 if (s
->hl
== DRAW_CURSOR
)
4165 int r
= s
->img
->relief
;
4167 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
4168 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4173 /* Draw a rectangle if image could not be loaded. */
4174 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4175 s
->img
->width
- 1, s
->img
->height
- 1);
4179 /* Draw a relief around the image glyph string S. */
4182 x_draw_image_relief (s
)
4183 struct glyph_string
*s
;
4185 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4188 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4190 /* If first glyph of S has a left box line, start drawing it to the
4191 right of that line. */
4192 if (s
->face
->box
!= FACE_NO_BOX
4193 && s
->first_glyph
->left_box_line_p
)
4194 x
= s
->x
+ abs (s
->face
->box_line_width
);
4198 /* If there is a margin around the image, adjust x- and y-position
4200 x
+= s
->img
->hmargin
;
4201 y
+= s
->img
->vmargin
;
4203 if (s
->hl
== DRAW_IMAGE_SUNKEN
4204 || s
->hl
== DRAW_IMAGE_RAISED
)
4206 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
4207 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4211 thick
= abs (s
->img
->relief
);
4212 raised_p
= s
->img
->relief
> 0;
4217 x1
= x
+ s
->img
->width
+ thick
- 1;
4218 y1
= y
+ s
->img
->height
+ thick
- 1;
4220 x_setup_relief_colors (s
);
4221 x_get_glyph_string_clip_rect (s
, &r
);
4222 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4226 /* Draw the foreground of image glyph string S to PIXMAP. */
4229 x_draw_image_foreground_1 (s
, pixmap
)
4230 struct glyph_string
*s
;
4234 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4236 /* If first glyph of S has a left box line, start drawing it to the
4237 right of that line. */
4238 if (s
->face
->box
!= FACE_NO_BOX
4239 && s
->first_glyph
->left_box_line_p
)
4240 x
= abs (s
->face
->box_line_width
);
4244 /* If there is a margin around the image, adjust x- and y-position
4246 x
+= s
->img
->hmargin
;
4247 y
+= s
->img
->vmargin
;
4253 /* We can't set both a clip mask and use XSetClipRectangles
4254 because the latter also sets a clip mask. We also can't
4255 trust on the shape extension to be available
4256 (XShapeCombineRegion). So, compute the rectangle to draw
4258 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4262 xgcv
.clip_mask
= s
->img
->mask
;
4263 xgcv
.clip_x_origin
= x
;
4264 xgcv
.clip_y_origin
= y
;
4265 xgcv
.function
= GXcopy
;
4266 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4268 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4269 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4270 XSetClipMask (s
->display
, s
->gc
, None
);
4274 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4275 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4277 /* When the image has a mask, we can expect that at
4278 least part of a mouse highlight or a block cursor will
4279 be visible. If the image doesn't have a mask, make
4280 a block cursor visible by drawing a rectangle around
4281 the image. I believe it's looking better if we do
4282 nothing here for mouse-face. */
4283 if (s
->hl
== DRAW_CURSOR
)
4285 int r
= s
->img
->relief
;
4287 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
4288 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
4293 /* Draw a rectangle if image could not be loaded. */
4294 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4295 s
->img
->width
- 1, s
->img
->height
- 1);
4299 /* Draw part of the background of glyph string S. X, Y, W, and H
4300 give the rectangle to draw. */
4303 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4304 struct glyph_string
*s
;
4309 /* Fill background with a stipple pattern. */
4310 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4311 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4312 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4315 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4319 /* Draw image glyph string S.
4322 s->x +-------------------------
4325 | +-------------------------
4328 | | +-------------------
4334 x_draw_image_glyph_string (s
)
4335 struct glyph_string
*s
;
4338 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4339 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4341 Pixmap pixmap
= None
;
4343 height
= s
->height
- 2 * box_line_vwidth
;
4346 /* Fill background with face under the image. Do it only if row is
4347 taller than image or if image has a clip mask to reduce
4349 s
->stippled_p
= s
->face
->stipple
!= 0;
4350 if (height
> s
->img
->height
4354 || s
->img
->pixmap
== 0
4355 || s
->width
!= s
->background_width
)
4357 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4358 x
= s
->x
+ box_line_hwidth
;
4362 y
= s
->y
+ box_line_vwidth
;
4366 /* Create a pixmap as large as the glyph string. Fill it
4367 with the background color. Copy the image to it, using
4368 its mask. Copy the temporary pixmap to the display. */
4369 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4370 int depth
= DefaultDepthOfScreen (screen
);
4372 /* Create a pixmap as large as the glyph string. */
4373 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4374 s
->background_width
,
4377 /* Don't clip in the following because we're working on the
4379 XSetClipMask (s
->display
, s
->gc
, None
);
4381 /* Fill the pixmap with the background color/stipple. */
4384 /* Fill background with a stipple pattern. */
4385 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4386 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4387 0, 0, s
->background_width
, s
->height
);
4388 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4393 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4395 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4396 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4397 0, 0, s
->background_width
, s
->height
);
4398 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4402 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4404 s
->background_filled_p
= 1;
4407 /* Draw the foreground. */
4410 x_draw_image_foreground_1 (s
, pixmap
);
4411 x_set_glyph_string_clipping (s
);
4412 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4413 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4414 XFreePixmap (s
->display
, pixmap
);
4417 x_draw_image_foreground (s
);
4419 /* If we must draw a relief around the image, do it. */
4421 || s
->hl
== DRAW_IMAGE_RAISED
4422 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4423 x_draw_image_relief (s
);
4427 /* Draw stretch glyph string S. */
4430 x_draw_stretch_glyph_string (s
)
4431 struct glyph_string
*s
;
4433 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4434 s
->stippled_p
= s
->face
->stipple
!= 0;
4436 if (s
->hl
== DRAW_CURSOR
4437 && !x_stretch_cursor_p
)
4439 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4440 as wide as the stretch glyph. */
4441 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4444 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4446 /* Clear rest using the GC of the original non-cursor face. */
4447 if (width
< s
->background_width
)
4449 int x
= s
->x
+ width
, y
= s
->y
;
4450 int w
= s
->background_width
- width
, h
= s
->height
;
4454 if (s
->row
->mouse_face_p
4455 && cursor_in_mouse_face_p (s
->w
))
4457 x_set_mouse_face_gc (s
);
4463 x_get_glyph_string_clip_rect (s
, &r
);
4464 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4466 if (s
->face
->stipple
)
4468 /* Fill background with a stipple pattern. */
4469 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4470 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4471 XSetFillStyle (s
->display
, gc
, FillSolid
);
4476 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4477 XSetForeground (s
->display
, gc
, xgcv
.background
);
4478 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4479 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4483 else if (!s
->background_filled_p
)
4484 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4487 s
->background_filled_p
= 1;
4491 /* Draw glyph string S. */
4494 x_draw_glyph_string (s
)
4495 struct glyph_string
*s
;
4497 int relief_drawn_p
= 0;
4499 /* If S draws into the background of its successor, draw the
4500 background of the successor first so that S can draw into it.
4501 This makes S->next use XDrawString instead of XDrawImageString. */
4502 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4504 xassert (s
->next
->img
== NULL
);
4505 x_set_glyph_string_gc (s
->next
);
4506 x_set_glyph_string_clipping (s
->next
);
4507 x_draw_glyph_string_background (s
->next
, 1);
4510 /* Set up S->gc, set clipping and draw S. */
4511 x_set_glyph_string_gc (s
);
4513 /* Draw relief (if any) in advance for char/composition so that the
4514 glyph string can be drawn over it. */
4515 if (!s
->for_overlaps_p
4516 && s
->face
->box
!= FACE_NO_BOX
4517 && (s
->first_glyph
->type
== CHAR_GLYPH
4518 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4521 x_set_glyph_string_clipping (s
);
4522 x_draw_glyph_string_background (s
, 1);
4523 x_draw_glyph_string_box (s
);
4524 x_set_glyph_string_clipping (s
);
4528 x_set_glyph_string_clipping (s
);
4530 switch (s
->first_glyph
->type
)
4533 x_draw_image_glyph_string (s
);
4537 x_draw_stretch_glyph_string (s
);
4541 if (s
->for_overlaps_p
)
4542 s
->background_filled_p
= 1;
4544 x_draw_glyph_string_background (s
, 0);
4545 x_draw_glyph_string_foreground (s
);
4548 case COMPOSITE_GLYPH
:
4549 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4550 s
->background_filled_p
= 1;
4552 x_draw_glyph_string_background (s
, 1);
4553 x_draw_composite_glyph_string_foreground (s
);
4560 if (!s
->for_overlaps_p
)
4562 /* Draw underline. */
4563 if (s
->face
->underline_p
)
4565 unsigned long tem
, h
;
4568 /* Get the underline thickness. Default is 1 pixel. */
4569 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4572 /* Get the underline position. This is the recommended
4573 vertical offset in pixels from the baseline to the top of
4574 the underline. This is a signed value according to the
4575 specs, and its default is
4577 ROUND ((maximum descent) / 2), with
4578 ROUND(x) = floor (x + 0.5) */
4580 if (x_use_underline_position_properties
4581 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4582 y
= s
->ybase
+ (long) tem
;
4583 else if (s
->face
->font
)
4584 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4586 y
= s
->y
+ s
->height
- h
;
4588 if (s
->face
->underline_defaulted_p
)
4589 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4590 s
->x
, y
, s
->width
, h
);
4594 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4595 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4596 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4597 s
->x
, y
, s
->width
, h
);
4598 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4602 /* Draw overline. */
4603 if (s
->face
->overline_p
)
4605 unsigned long dy
= 0, h
= 1;
4607 if (s
->face
->overline_color_defaulted_p
)
4608 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4613 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4614 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4615 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4617 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4621 /* Draw strike-through. */
4622 if (s
->face
->strike_through_p
)
4624 unsigned long h
= 1;
4625 unsigned long dy
= (s
->height
- h
) / 2;
4627 if (s
->face
->strike_through_color_defaulted_p
)
4628 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4633 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4634 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4635 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4637 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4641 /* Draw relief if not yet drawn. */
4642 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4643 x_draw_glyph_string_box (s
);
4646 /* Reset clipping. */
4647 XSetClipMask (s
->display
, s
->gc
, None
);
4651 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4652 struct face
**, int));
4655 /* Fill glyph string S with composition components specified by S->cmp.
4657 FACES is an array of faces for all components of this composition.
4658 S->gidx is the index of the first component for S.
4659 OVERLAPS_P non-zero means S should draw the foreground only, and
4660 use its physical height for clipping.
4662 Value is the index of a component not in S. */
4665 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4666 struct glyph_string
*s
;
4667 struct face
**faces
;
4674 s
->for_overlaps_p
= overlaps_p
;
4676 s
->face
= faces
[s
->gidx
];
4677 s
->font
= s
->face
->font
;
4678 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4680 /* For all glyphs of this composition, starting at the offset
4681 S->gidx, until we reach the end of the definition or encounter a
4682 glyph that requires the different face, add it to S. */
4684 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4687 /* All glyph strings for the same composition has the same width,
4688 i.e. the width set for the first component of the composition. */
4690 s
->width
= s
->first_glyph
->pixel_width
;
4692 /* If the specified font could not be loaded, use the frame's
4693 default font, but record the fact that we couldn't load it in
4694 the glyph string so that we can draw rectangles for the
4695 characters of the glyph string. */
4696 if (s
->font
== NULL
)
4698 s
->font_not_found_p
= 1;
4699 s
->font
= FRAME_FONT (s
->f
);
4702 /* Adjust base line for subscript/superscript text. */
4703 s
->ybase
+= s
->first_glyph
->voffset
;
4705 xassert (s
->face
&& s
->face
->gc
);
4707 /* This glyph string must always be drawn with 16-bit functions. */
4710 return s
->gidx
+ s
->nchars
;
4714 /* Fill glyph string S from a sequence of character glyphs.
4716 FACE_ID is the face id of the string. START is the index of the
4717 first glyph to consider, END is the index of the last + 1.
4718 OVERLAPS_P non-zero means S should draw the foreground only, and
4719 use its physical height for clipping.
4721 Value is the index of the first glyph not in S. */
4724 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4725 struct glyph_string
*s
;
4727 int start
, end
, overlaps_p
;
4729 struct glyph
*glyph
, *last
;
4731 int glyph_not_available_p
;
4733 xassert (s
->f
== XFRAME (s
->w
->frame
));
4734 xassert (s
->nchars
== 0);
4735 xassert (start
>= 0 && end
> start
);
4737 s
->for_overlaps_p
= overlaps_p
,
4738 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4739 last
= s
->row
->glyphs
[s
->area
] + end
;
4740 voffset
= glyph
->voffset
;
4742 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4745 && glyph
->type
== CHAR_GLYPH
4746 && glyph
->voffset
== voffset
4747 /* Same face id implies same font, nowadays. */
4748 && glyph
->face_id
== face_id
4749 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4753 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4754 s
->char2b
+ s
->nchars
,
4756 s
->two_byte_p
= two_byte_p
;
4758 xassert (s
->nchars
<= end
- start
);
4759 s
->width
+= glyph
->pixel_width
;
4763 s
->font
= s
->face
->font
;
4764 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4766 /* If the specified font could not be loaded, use the frame's font,
4767 but record the fact that we couldn't load it in
4768 S->font_not_found_p so that we can draw rectangles for the
4769 characters of the glyph string. */
4770 if (s
->font
== NULL
|| glyph_not_available_p
)
4772 s
->font_not_found_p
= 1;
4773 s
->font
= FRAME_FONT (s
->f
);
4776 /* Adjust base line for subscript/superscript text. */
4777 s
->ybase
+= voffset
;
4779 xassert (s
->face
&& s
->face
->gc
);
4780 return glyph
- s
->row
->glyphs
[s
->area
];
4784 /* Fill glyph string S from image glyph S->first_glyph. */
4787 x_fill_image_glyph_string (s
)
4788 struct glyph_string
*s
;
4790 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4791 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4793 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4794 s
->font
= s
->face
->font
;
4795 s
->width
= s
->first_glyph
->pixel_width
;
4797 /* Adjust base line for subscript/superscript text. */
4798 s
->ybase
+= s
->first_glyph
->voffset
;
4802 /* Fill glyph string S from a sequence of stretch glyphs.
4804 ROW is the glyph row in which the glyphs are found, AREA is the
4805 area within the row. START is the index of the first glyph to
4806 consider, END is the index of the last + 1.
4808 Value is the index of the first glyph not in S. */
4811 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4812 struct glyph_string
*s
;
4813 struct glyph_row
*row
;
4814 enum glyph_row_area area
;
4817 struct glyph
*glyph
, *last
;
4818 int voffset
, face_id
;
4820 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4822 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4823 last
= s
->row
->glyphs
[s
->area
] + end
;
4824 face_id
= glyph
->face_id
;
4825 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4826 s
->font
= s
->face
->font
;
4827 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4828 s
->width
= glyph
->pixel_width
;
4829 voffset
= glyph
->voffset
;
4833 && glyph
->type
== STRETCH_GLYPH
4834 && glyph
->voffset
== voffset
4835 && glyph
->face_id
== face_id
);
4837 s
->width
+= glyph
->pixel_width
;
4839 /* Adjust base line for subscript/superscript text. */
4840 s
->ybase
+= voffset
;
4842 /* The case that face->gc == 0 is handled when drawing the glyph
4843 string by calling PREPARE_FACE_FOR_DISPLAY. */
4845 return glyph
- s
->row
->glyphs
[s
->area
];
4849 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4850 of XChar2b structures for S; it can't be allocated in
4851 x_init_glyph_string because it must be allocated via `alloca'. W
4852 is the window on which S is drawn. ROW and AREA are the glyph row
4853 and area within the row from which S is constructed. START is the
4854 index of the first glyph structure covered by S. HL is a
4855 face-override for drawing S. */
4858 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4859 struct glyph_string
*s
;
4862 struct glyph_row
*row
;
4863 enum glyph_row_area area
;
4865 enum draw_glyphs_face hl
;
4867 bzero (s
, sizeof *s
);
4869 s
->f
= XFRAME (w
->frame
);
4870 s
->display
= FRAME_X_DISPLAY (s
->f
);
4871 s
->window
= FRAME_X_WINDOW (s
->f
);
4876 s
->first_glyph
= row
->glyphs
[area
] + start
;
4877 s
->height
= row
->height
;
4878 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4880 /* Display the internal border below the tool-bar window. */
4881 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4882 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4884 s
->ybase
= s
->y
+ row
->ascent
;
4888 /* Set background width of glyph string S. START is the index of the
4889 first glyph following S. LAST_X is the right-most x-position + 1
4890 in the drawing area. */
4893 x_set_glyph_string_background_width (s
, start
, last_x
)
4894 struct glyph_string
*s
;
4898 /* If the face of this glyph string has to be drawn to the end of
4899 the drawing area, set S->extends_to_end_of_line_p. */
4900 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4902 if (start
== s
->row
->used
[s
->area
]
4903 && s
->area
== TEXT_AREA
4904 && ((s
->hl
== DRAW_NORMAL_TEXT
4905 && (s
->row
->fill_line_p
4906 || s
->face
->background
!= default_face
->background
4907 || s
->face
->stipple
!= default_face
->stipple
4908 || s
->row
->mouse_face_p
))
4909 || s
->hl
== DRAW_MOUSE_FACE
4910 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4911 && s
->row
->fill_line_p
)))
4912 s
->extends_to_end_of_line_p
= 1;
4914 /* If S extends its face to the end of the line, set its
4915 background_width to the distance to the right edge of the drawing
4917 if (s
->extends_to_end_of_line_p
)
4918 s
->background_width
= last_x
- s
->x
+ 1;
4920 s
->background_width
= s
->width
;
4924 /* Add a glyph string for a stretch glyph to the list of strings
4925 between HEAD and TAIL. START is the index of the stretch glyph in
4926 row area AREA of glyph row ROW. END is the index of the last glyph
4927 in that glyph row area. X is the current output position assigned
4928 to the new glyph string constructed. HL overrides that face of the
4929 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4930 is the right-most x-position of the drawing area. */
4932 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4933 and below -- keep them on one line. */
4934 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4937 s = (struct glyph_string *) alloca (sizeof *s); \
4938 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4939 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4940 x_append_glyph_string (&HEAD, &TAIL, s); \
4946 /* Add a glyph string for an image glyph to the list of strings
4947 between HEAD and TAIL. START is the index of the image glyph in
4948 row area AREA of glyph row ROW. END is the index of the last glyph
4949 in that glyph row area. X is the current output position assigned
4950 to the new glyph string constructed. HL overrides that face of the
4951 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4952 is the right-most x-position of the drawing area. */
4954 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4957 s = (struct glyph_string *) alloca (sizeof *s); \
4958 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4959 x_fill_image_glyph_string (s); \
4960 x_append_glyph_string (&HEAD, &TAIL, s); \
4967 /* Add a glyph string for a sequence of character glyphs to the list
4968 of strings between HEAD and TAIL. START is the index of the first
4969 glyph in row area AREA of glyph row ROW that is part of the new
4970 glyph string. END is the index of the last glyph in that glyph row
4971 area. X is the current output position assigned to the new glyph
4972 string constructed. HL overrides that face of the glyph; e.g. it
4973 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4974 right-most x-position of the drawing area. */
4976 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4982 c = (ROW)->glyphs[AREA][START].u.ch; \
4983 face_id = (ROW)->glyphs[AREA][START].face_id; \
4985 s = (struct glyph_string *) alloca (sizeof *s); \
4986 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4987 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4988 x_append_glyph_string (&HEAD, &TAIL, s); \
4990 START = x_fill_glyph_string (s, face_id, START, END, \
4996 /* Add a glyph string for a composite sequence to the list of strings
4997 between HEAD and TAIL. START is the index of the first glyph in
4998 row area AREA of glyph row ROW that is part of the new glyph
4999 string. END is the index of the last glyph in that glyph row area.
5000 X is the current output position assigned to the new glyph string
5001 constructed. HL overrides that face of the glyph; e.g. it is
5002 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
5003 x-position of the drawing area. */
5005 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5007 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
5008 int face_id = (ROW)->glyphs[AREA][START].face_id; \
5009 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
5010 struct composition *cmp = composition_table[cmp_id]; \
5011 int glyph_len = cmp->glyph_len; \
5013 struct face **faces; \
5014 struct glyph_string *first_s = NULL; \
5017 base_face = base_face->ascii_face; \
5018 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
5019 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
5020 /* At first, fill in `char2b' and `faces'. */ \
5021 for (n = 0; n < glyph_len; n++) \
5023 int c = COMPOSITION_GLYPH (cmp, n); \
5024 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
5025 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
5026 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
5027 this_face_id, char2b + n, 1, 1); \
5030 /* Make glyph_strings for each glyph sequence that is drawable by \
5031 the same face, and append them to HEAD/TAIL. */ \
5032 for (n = 0; n < cmp->glyph_len;) \
5034 s = (struct glyph_string *) alloca (sizeof *s); \
5035 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
5036 x_append_glyph_string (&(HEAD), &(TAIL), s); \
5044 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
5052 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
5053 of AREA of glyph row ROW on window W between indices START and END.
5054 HL overrides the face for drawing glyph strings, e.g. it is
5055 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
5056 x-positions of the drawing area.
5058 This is an ugly monster macro construct because we must use alloca
5059 to allocate glyph strings (because x_draw_glyphs can be called
5062 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5065 HEAD = TAIL = NULL; \
5066 while (START < END) \
5068 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
5069 switch (first_glyph->type) \
5072 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
5073 TAIL, HL, X, LAST_X, \
5077 case COMPOSITE_GLYPH: \
5078 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
5079 HEAD, TAIL, HL, X, LAST_X,\
5083 case STRETCH_GLYPH: \
5084 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5085 HEAD, TAIL, HL, X, LAST_X); \
5089 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5090 TAIL, HL, X, LAST_X); \
5097 x_set_glyph_string_background_width (s, START, LAST_X); \
5104 /* Draw glyphs between START and END in AREA of ROW on window W,
5105 starting at x-position X. X is relative to AREA in W. HL is a
5106 face-override with the following meaning:
5108 DRAW_NORMAL_TEXT draw normally
5109 DRAW_CURSOR draw in cursor face
5110 DRAW_MOUSE_FACE draw in mouse face.
5111 DRAW_INVERSE_VIDEO draw in mode line face
5112 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5113 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5115 If OVERLAPS_P is non-zero, draw only the foreground of characters
5116 and clip to the physical height of ROW.
5118 Value is the x-position reached, relative to AREA of W. */
5121 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
5124 struct glyph_row
*row
;
5125 enum glyph_row_area area
;
5127 enum draw_glyphs_face hl
;
5130 struct glyph_string
*head
, *tail
;
5131 struct glyph_string
*s
;
5132 int last_x
, area_width
;
5136 /* Let's rather be paranoid than getting a SEGV. */
5137 end
= min (end
, row
->used
[area
]);
5138 start
= max (0, start
);
5139 start
= min (end
, start
);
5141 /* Translate X to frame coordinates. Set last_x to the right
5142 end of the drawing area. */
5143 if (row
->full_width_p
)
5145 /* X is relative to the left edge of W, without scroll bars
5147 struct frame
*f
= XFRAME (w
->frame
);
5148 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5151 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5152 last_x
= window_left_x
+ area_width
;
5154 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5156 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5157 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5163 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5164 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5168 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5169 area_width
= window_box_width (w
, area
);
5170 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5173 /* Build a doubly-linked list of glyph_string structures between
5174 head and tail from what we have to draw. Note that the macro
5175 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5176 the reason we use a separate variable `i'. */
5178 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5181 x_reached
= tail
->x
+ tail
->background_width
;
5185 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5186 the row, redraw some glyphs in front or following the glyph
5187 strings built above. */
5188 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5191 struct glyph_string
*h
, *t
;
5193 /* Compute overhangs for all glyph strings. */
5194 for (s
= head
; s
; s
= s
->next
)
5195 x_compute_glyph_string_overhangs (s
);
5197 /* Prepend glyph strings for glyphs in front of the first glyph
5198 string that are overwritten because of the first glyph
5199 string's left overhang. The background of all strings
5200 prepended must be drawn because the first glyph string
5202 i
= x_left_overwritten (head
);
5206 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5207 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5210 x_compute_overhangs_and_x (t
, head
->x
, 1);
5211 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5214 /* Prepend glyph strings for glyphs in front of the first glyph
5215 string that overwrite that glyph string because of their
5216 right overhang. For these strings, only the foreground must
5217 be drawn, because it draws over the glyph string at `head'.
5218 The background must not be drawn because this would overwrite
5219 right overhangs of preceding glyphs for which no glyph
5221 i
= x_left_overwriting (head
);
5224 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5225 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5227 for (s
= h
; s
; s
= s
->next
)
5228 s
->background_filled_p
= 1;
5229 x_compute_overhangs_and_x (t
, head
->x
, 1);
5230 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5233 /* Append glyphs strings for glyphs following the last glyph
5234 string tail that are overwritten by tail. The background of
5235 these strings has to be drawn because tail's foreground draws
5237 i
= x_right_overwritten (tail
);
5240 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5241 DRAW_NORMAL_TEXT
, x
, last_x
,
5243 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5244 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5247 /* Append glyph strings for glyphs following the last glyph
5248 string tail that overwrite tail. The foreground of such
5249 glyphs has to be drawn because it writes into the background
5250 of tail. The background must not be drawn because it could
5251 paint over the foreground of following glyphs. */
5252 i
= x_right_overwriting (tail
);
5255 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5256 DRAW_NORMAL_TEXT
, x
, last_x
,
5258 for (s
= h
; s
; s
= s
->next
)
5259 s
->background_filled_p
= 1;
5260 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5261 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5265 /* Draw all strings. */
5266 for (s
= head
; s
; s
= s
->next
)
5267 x_draw_glyph_string (s
);
5269 if (area
== TEXT_AREA
5270 && !row
->full_width_p
5271 /* When drawing overlapping rows, only the glyph strings'
5272 foreground is drawn, which doesn't erase a cursor
5276 int x0
= head
? head
->x
: x
;
5277 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5279 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5280 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5282 if (XFASTINT (w
->left_margin_width
) != 0)
5284 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5285 x0
-= left_area_width
;
5286 x1
-= left_area_width
;
5289 notice_overwritten_cursor (w
, area
, x0
, x1
,
5290 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5293 /* Value is the x-position up to which drawn, relative to AREA of W.
5294 This doesn't include parts drawn because of overhangs. */
5295 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5296 if (!row
->full_width_p
)
5298 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
5299 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5300 if (area
> TEXT_AREA
)
5301 x_reached
-= window_box_width (w
, TEXT_AREA
);
5308 /* Fix the display of area AREA of overlapping row ROW in window W. */
5311 x_fix_overlapping_area (w
, row
, area
)
5313 struct glyph_row
*row
;
5314 enum glyph_row_area area
;
5320 if (area
== LEFT_MARGIN_AREA
)
5322 else if (area
== TEXT_AREA
)
5323 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5325 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5326 + window_box_width (w
, TEXT_AREA
));
5328 for (i
= 0; i
< row
->used
[area
];)
5330 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5332 int start
= i
, start_x
= x
;
5336 x
+= row
->glyphs
[area
][i
].pixel_width
;
5339 while (i
< row
->used
[area
]
5340 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5342 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5343 DRAW_NORMAL_TEXT
, 1);
5347 x
+= row
->glyphs
[area
][i
].pixel_width
;
5356 /* Output LEN glyphs starting at START at the nominal cursor position.
5357 Advance the nominal cursor over the text. The global variable
5358 updated_window contains the window being updated, updated_row is
5359 the glyph row being updated, and updated_area is the area of that
5360 row being updated. */
5363 x_write_glyphs (start
, len
)
5364 struct glyph
*start
;
5369 xassert (updated_window
&& updated_row
);
5374 hpos
= start
- updated_row
->glyphs
[updated_area
];
5375 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5376 updated_row
, updated_area
,
5378 DRAW_NORMAL_TEXT
, 0);
5380 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
5381 if (updated_area
== TEXT_AREA
5382 && updated_window
->phys_cursor_on_p
5383 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
5384 && updated_window
->phys_cursor
.hpos
>= hpos
5385 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
5386 updated_window
->phys_cursor_on_p
= 0;
5390 /* Advance the output cursor. */
5391 output_cursor
.hpos
+= len
;
5392 output_cursor
.x
= x
;
5396 /* Insert LEN glyphs from START at the nominal cursor position. */
5399 x_insert_glyphs (start
, len
)
5400 struct glyph
*start
;
5405 int line_height
, shift_by_width
, shifted_region_width
;
5406 struct glyph_row
*row
;
5407 struct glyph
*glyph
;
5408 int frame_x
, frame_y
, hpos
;
5410 xassert (updated_window
&& updated_row
);
5413 f
= XFRAME (WINDOW_FRAME (w
));
5415 /* Get the height of the line we are in. */
5417 line_height
= row
->height
;
5419 /* Get the width of the glyphs to insert. */
5421 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5422 shift_by_width
+= glyph
->pixel_width
;
5424 /* Get the width of the region to shift right. */
5425 shifted_region_width
= (window_box_width (w
, updated_area
)
5430 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5431 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5432 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5433 f
->output_data
.x
->normal_gc
,
5435 shifted_region_width
, line_height
,
5436 frame_x
+ shift_by_width
, frame_y
);
5438 /* Write the glyphs. */
5439 hpos
= start
- row
->glyphs
[updated_area
];
5440 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5441 DRAW_NORMAL_TEXT
, 0);
5443 /* Advance the output cursor. */
5444 output_cursor
.hpos
+= len
;
5445 output_cursor
.x
+= shift_by_width
;
5450 /* Delete N glyphs at the nominal cursor position. Not implemented
5461 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5462 If they are <= 0, this is probably an error. */
5465 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5472 xassert (width
> 0 && height
> 0);
5473 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5477 /* Erase the current text line from the nominal cursor position
5478 (inclusive) to pixel column TO_X (exclusive). The idea is that
5479 everything from TO_X onward is already erased.
5481 TO_X is a pixel position relative to updated_area of
5482 updated_window. TO_X == -1 means clear to the end of this area. */
5485 x_clear_end_of_line (to_x
)
5489 struct window
*w
= updated_window
;
5490 int max_x
, min_y
, max_y
;
5491 int from_x
, from_y
, to_y
;
5493 xassert (updated_window
&& updated_row
);
5494 f
= XFRAME (w
->frame
);
5496 if (updated_row
->full_width_p
)
5498 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5499 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5500 && !w
->pseudo_window_p
)
5501 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5504 max_x
= window_box_width (w
, updated_area
);
5505 max_y
= window_text_bottom_y (w
);
5507 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5508 of window. For TO_X > 0, truncate to end of drawing area. */
5514 to_x
= min (to_x
, max_x
);
5516 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5518 /* Notice if the cursor will be cleared by this operation. */
5519 if (!updated_row
->full_width_p
)
5520 notice_overwritten_cursor (w
, updated_area
,
5521 output_cursor
.x
, -1,
5523 MATRIX_ROW_BOTTOM_Y (updated_row
));
5525 from_x
= output_cursor
.x
;
5527 /* Translate to frame coordinates. */
5528 if (updated_row
->full_width_p
)
5530 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5531 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5535 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5536 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5539 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5540 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5541 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5543 /* Prevent inadvertently clearing to end of the X window. */
5544 if (to_x
> from_x
&& to_y
> from_y
)
5547 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5548 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5555 /* Clear entire frame. If updating_frame is non-null, clear that
5556 frame. Otherwise clear the selected frame. */
5566 f
= SELECTED_FRAME ();
5568 /* Clearing the frame will erase any cursor, so mark them all as no
5570 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5571 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5572 output_cursor
.x
= -1;
5574 /* We don't set the output cursor here because there will always
5575 follow an explicit cursor_to. */
5577 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5579 /* We have to clear the scroll bars, too. If we have changed
5580 colors or something like that, then they should be notified. */
5581 x_scroll_bar_clear (f
);
5583 XFlush (FRAME_X_DISPLAY (f
));
5589 /* Invert the middle quarter of the frame for .15 sec. */
5591 /* We use the select system call to do the waiting, so we have to make
5592 sure it's available. If it isn't, we just won't do visual bells. */
5594 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5597 /* Subtract the `struct timeval' values X and Y, storing the result in
5598 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5601 timeval_subtract (result
, x
, y
)
5602 struct timeval
*result
, x
, y
;
5604 /* Perform the carry for the later subtraction by updating y. This
5605 is safer because on some systems the tv_sec member is unsigned. */
5606 if (x
.tv_usec
< y
.tv_usec
)
5608 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5609 y
.tv_usec
-= 1000000 * nsec
;
5613 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5615 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5616 y
.tv_usec
+= 1000000 * nsec
;
5620 /* Compute the time remaining to wait. tv_usec is certainly
5622 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5623 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5625 /* Return indication of whether the result should be considered
5627 return x
.tv_sec
< y
.tv_sec
;
5639 /* Create a GC that will use the GXxor function to flip foreground
5640 pixels into background pixels. */
5644 values
.function
= GXxor
;
5645 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5646 ^ f
->output_data
.x
->background_pixel
);
5648 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5649 GCFunction
| GCForeground
, &values
);
5653 /* Get the height not including a menu bar widget. */
5654 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5655 /* Height of each line to flash. */
5656 int flash_height
= FRAME_LINE_HEIGHT (f
);
5657 /* These will be the left and right margins of the rectangles. */
5658 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5659 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5663 /* Don't flash the area between a scroll bar and the frame
5664 edge it is next to. */
5665 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5667 case vertical_scroll_bar_left
:
5668 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5671 case vertical_scroll_bar_right
:
5672 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5679 width
= flash_right
- flash_left
;
5681 /* If window is tall, flash top and bottom line. */
5682 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5684 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5686 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5687 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5688 width
, flash_height
);
5689 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5691 (height
- flash_height
5692 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5693 width
, flash_height
);
5696 /* If it is short, flash it all. */
5697 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5698 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5699 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5704 struct timeval wakeup
;
5706 EMACS_GET_TIME (wakeup
);
5708 /* Compute time to wait until, propagating carry from usecs. */
5709 wakeup
.tv_usec
+= 150000;
5710 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5711 wakeup
.tv_usec
%= 1000000;
5713 /* Keep waiting until past the time wakeup or any input gets
5715 while (! detect_input_pending ())
5717 struct timeval current
;
5718 struct timeval timeout
;
5720 EMACS_GET_TIME (current
);
5722 /* Break if result would be negative. */
5723 if (timeval_subtract (¤t
, wakeup
, current
))
5726 /* How long `select' should wait. */
5728 timeout
.tv_usec
= 10000;
5730 /* Try to wait that long--but we might wake up sooner. */
5731 select (0, NULL
, NULL
, NULL
, &timeout
);
5735 /* If window is tall, flash top and bottom line. */
5736 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5738 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5740 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5741 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5742 width
, flash_height
);
5743 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5745 (height
- flash_height
5746 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5747 width
, flash_height
);
5750 /* If it is short, flash it all. */
5751 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5752 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5753 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5755 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5763 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5766 /* Make audible bell. */
5771 struct frame
*f
= SELECTED_FRAME ();
5773 if (FRAME_X_DISPLAY (f
))
5775 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5782 XBell (FRAME_X_DISPLAY (f
), 0);
5783 XFlush (FRAME_X_DISPLAY (f
));
5790 /* Specify how many text lines, from the top of the window,
5791 should be affected by insert-lines and delete-lines operations.
5792 This, and those operations, are used only within an update
5793 that is bounded by calls to x_update_begin and x_update_end. */
5796 XTset_terminal_window (n
)
5799 /* This function intentionally left blank. */
5804 /***********************************************************************
5806 ***********************************************************************/
5808 /* Perform an insert-lines or delete-lines operation, inserting N
5809 lines or deleting -N lines at vertical position VPOS. */
5812 x_ins_del_lines (vpos
, n
)
5819 /* Scroll part of the display as described by RUN. */
5822 x_scroll_run (w
, run
)
5826 struct frame
*f
= XFRAME (w
->frame
);
5827 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5829 /* Get frame-relative bounding box of the text display area of W,
5830 without mode lines. Include in this box the left and right
5832 window_box (w
, -1, &x
, &y
, &width
, &height
);
5833 width
+= FRAME_X_FRINGE_WIDTH (f
);
5834 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5836 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5837 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5838 bottom_y
= y
+ height
;
5842 /* Scrolling up. Make sure we don't copy part of the mode
5843 line at the bottom. */
5844 if (from_y
+ run
->height
> bottom_y
)
5845 height
= bottom_y
- from_y
;
5847 height
= run
->height
;
5851 /* Scolling down. Make sure we don't copy over the mode line.
5853 if (to_y
+ run
->height
> bottom_y
)
5854 height
= bottom_y
- to_y
;
5856 height
= run
->height
;
5861 /* Cursor off. Will be switched on again in x_update_window_end. */
5865 XCopyArea (FRAME_X_DISPLAY (f
),
5866 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5867 f
->output_data
.x
->normal_gc
,
5877 /***********************************************************************
5879 ***********************************************************************/
5881 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5882 corner of the exposed rectangle. W and H are width and height of
5883 the exposed area. All are pixel values. W or H zero means redraw
5884 the entire frame. */
5887 expose_frame (f
, x
, y
, w
, h
)
5892 int mouse_face_overwritten_p
= 0;
5894 TRACE ((stderr
, "expose_frame "));
5896 /* No need to redraw if frame will be redrawn soon. */
5897 if (FRAME_GARBAGED_P (f
))
5899 TRACE ((stderr
, " garbaged\n"));
5903 /* If basic faces haven't been realized yet, there is no point in
5904 trying to redraw anything. This can happen when we get an expose
5905 event while Emacs is starting, e.g. by moving another window. */
5906 if (FRAME_FACE_CACHE (f
) == NULL
5907 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5909 TRACE ((stderr
, " no faces\n"));
5913 if (w
== 0 || h
== 0)
5916 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5917 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5927 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5928 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5930 if (WINDOWP (f
->tool_bar_window
))
5931 mouse_face_overwritten_p
5932 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5934 #ifndef USE_X_TOOLKIT
5935 if (WINDOWP (f
->menu_bar_window
))
5936 mouse_face_overwritten_p
5937 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5938 #endif /* not USE_X_TOOLKIT */
5940 /* Some window managers support a focus-follows-mouse style with
5941 delayed raising of frames. Imagine a partially obscured frame,
5942 and moving the mouse into partially obscured mouse-face on that
5943 frame. The visible part of the mouse-face will be highlighted,
5944 then the WM raises the obscured frame. With at least one WM, KDE
5945 2.1, Emacs is not getting any event for the raising of the frame
5946 (even tried with SubstructureRedirectMask), only Expose events.
5947 These expose events will draw text normally, i.e. not
5948 highlighted. Which means we must redo the highlight here.
5949 Subsume it under ``we love X''. --gerd 2001-08-15 */
5950 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5952 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5953 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5955 int x
= dpyinfo
->mouse_face_mouse_x
;
5956 int y
= dpyinfo
->mouse_face_mouse_y
;
5957 clear_mouse_face (dpyinfo
);
5958 note_mouse_highlight (f
, x
, y
);
5964 /* Redraw (parts) of all windows in the window tree rooted at W that
5965 intersect R. R contains frame pixel coordinates. Value is
5966 non-zero if the exposure overwrites mouse-face. */
5969 expose_window_tree (w
, r
)
5973 struct frame
*f
= XFRAME (w
->frame
);
5974 int mouse_face_overwritten_p
= 0;
5976 while (w
&& !FRAME_GARBAGED_P (f
))
5978 if (!NILP (w
->hchild
))
5979 mouse_face_overwritten_p
5980 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5981 else if (!NILP (w
->vchild
))
5982 mouse_face_overwritten_p
5983 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5985 mouse_face_overwritten_p
|= expose_window (w
, r
);
5987 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5990 return mouse_face_overwritten_p
;
5994 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5995 which intersects rectangle R. R is in window-relative coordinates. */
5998 expose_area (w
, row
, r
, area
)
6000 struct glyph_row
*row
;
6002 enum glyph_row_area area
;
6004 struct glyph
*first
= row
->glyphs
[area
];
6005 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
6007 int first_x
, start_x
, x
;
6009 if (area
== TEXT_AREA
&& row
->fill_line_p
)
6010 /* If row extends face to end of line write the whole line. */
6011 x_draw_glyphs (w
, 0, row
, area
, 0, row
->used
[area
],
6012 DRAW_NORMAL_TEXT
, 0);
6015 /* Set START_X to the window-relative start position for drawing glyphs of
6016 AREA. The first glyph of the text area can be partially visible.
6017 The first glyphs of other areas cannot. */
6018 if (area
== LEFT_MARGIN_AREA
)
6020 else if (area
== TEXT_AREA
)
6021 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
6023 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
6024 + window_box_width (w
, TEXT_AREA
));
6027 /* Find the first glyph that must be redrawn. */
6029 && x
+ first
->pixel_width
< r
->x
)
6031 x
+= first
->pixel_width
;
6035 /* Find the last one. */
6039 && x
< r
->x
+ r
->width
)
6041 x
+= last
->pixel_width
;
6047 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
6048 first
- row
->glyphs
[area
],
6049 last
- row
->glyphs
[area
],
6050 DRAW_NORMAL_TEXT
, 0);
6055 /* Redraw the parts of the glyph row ROW on window W intersecting
6056 rectangle R. R is in window-relative coordinates. Value is
6057 non-zero if mouse-face was overwritten. */
6060 expose_line (w
, row
, r
)
6062 struct glyph_row
*row
;
6065 xassert (row
->enabled_p
);
6067 if (row
->mode_line_p
|| w
->pseudo_window_p
)
6068 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
6069 DRAW_NORMAL_TEXT
, 0);
6072 if (row
->used
[LEFT_MARGIN_AREA
])
6073 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
6074 if (row
->used
[TEXT_AREA
])
6075 expose_area (w
, row
, r
, TEXT_AREA
);
6076 if (row
->used
[RIGHT_MARGIN_AREA
])
6077 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
6078 x_draw_row_fringe_bitmaps (w
, row
);
6081 return row
->mouse_face_p
;
6085 /* Return non-zero if W's cursor intersects rectangle R. */
6088 x_phys_cursor_in_rect_p (w
, r
)
6092 XRectangle cr
, result
;
6093 struct glyph
*cursor_glyph
;
6095 cursor_glyph
= get_phys_cursor_glyph (w
);
6098 cr
.x
= w
->phys_cursor
.x
;
6099 cr
.y
= w
->phys_cursor
.y
;
6100 cr
.width
= cursor_glyph
->pixel_width
;
6101 cr
.height
= w
->phys_cursor_height
;
6102 return x_intersect_rectangles (&cr
, r
, &result
);
6109 /* Redraw those parts of glyphs rows during expose event handling that
6110 overlap other rows. Redrawing of an exposed line writes over parts
6111 of lines overlapping that exposed line; this function fixes that.
6113 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
6114 row in W's current matrix that is exposed and overlaps other rows.
6115 LAST_OVERLAPPING_ROW is the last such row. */
6118 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
6120 struct glyph_row
*first_overlapping_row
;
6121 struct glyph_row
*last_overlapping_row
;
6123 struct glyph_row
*row
;
6125 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
6126 if (row
->overlapping_p
)
6128 xassert (row
->enabled_p
&& !row
->mode_line_p
);
6130 if (row
->used
[LEFT_MARGIN_AREA
])
6131 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
6133 if (row
->used
[TEXT_AREA
])
6134 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
6136 if (row
->used
[RIGHT_MARGIN_AREA
])
6137 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
6142 /* Redraw the part of window W intersection rectangle FR. Pixel
6143 coordinates in FR are frame-relative. Call this function with
6144 input blocked. Value is non-zero if the exposure overwrites
6148 expose_window (w
, fr
)
6152 struct frame
*f
= XFRAME (w
->frame
);
6154 int mouse_face_overwritten_p
= 0;
6156 /* If window is not yet fully initialized, do nothing. This can
6157 happen when toolkit scroll bars are used and a window is split.
6158 Reconfiguring the scroll bar will generate an expose for a newly
6160 if (w
->current_matrix
== NULL
)
6163 /* When we're currently updating the window, display and current
6164 matrix usually don't agree. Arrange for a thorough display
6166 if (w
== updated_window
)
6168 SET_FRAME_GARBAGED (f
);
6172 /* Frame-relative pixel rectangle of W. */
6173 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6174 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6175 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6176 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6178 if (x_intersect_rectangles (fr
, &wr
, &r
))
6180 int yb
= window_text_bottom_y (w
);
6181 struct glyph_row
*row
;
6182 int cursor_cleared_p
;
6183 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
6185 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6186 r
.x
, r
.y
, r
.width
, r
.height
));
6188 /* Convert to window coordinates. */
6189 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
6190 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
6192 /* Turn off the cursor. */
6193 if (!w
->pseudo_window_p
6194 && x_phys_cursor_in_rect_p (w
, &r
))
6197 cursor_cleared_p
= 1;
6200 cursor_cleared_p
= 0;
6202 /* Update lines intersecting rectangle R. */
6203 first_overlapping_row
= last_overlapping_row
= NULL
;
6204 for (row
= w
->current_matrix
->rows
;
6209 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6211 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
6212 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
6213 || (r
.y
>= y0
&& r
.y
< y1
)
6214 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
6216 if (row
->overlapping_p
)
6218 if (first_overlapping_row
== NULL
)
6219 first_overlapping_row
= row
;
6220 last_overlapping_row
= row
;
6223 if (expose_line (w
, row
, &r
))
6224 mouse_face_overwritten_p
= 1;
6231 /* Display the mode line if there is one. */
6232 if (WINDOW_WANTS_MODELINE_P (w
)
6233 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6235 && row
->y
< r
.y
+ r
.height
)
6237 if (expose_line (w
, row
, &r
))
6238 mouse_face_overwritten_p
= 1;
6241 if (!w
->pseudo_window_p
)
6243 /* Fix the display of overlapping rows. */
6244 if (first_overlapping_row
)
6245 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
6247 /* Draw border between windows. */
6248 x_draw_vertical_border (w
);
6250 /* Turn the cursor on again. */
6251 if (cursor_cleared_p
)
6252 x_update_window_cursor (w
, 1);
6256 return mouse_face_overwritten_p
;
6260 /* Determine the intersection of two rectangles R1 and R2. Return
6261 the intersection in *RESULT. Value is non-zero if RESULT is not
6265 x_intersect_rectangles (r1
, r2
, result
)
6266 XRectangle
*r1
, *r2
, *result
;
6268 XRectangle
*left
, *right
;
6269 XRectangle
*upper
, *lower
;
6270 int intersection_p
= 0;
6272 /* Rearrange so that R1 is the left-most rectangle. */
6274 left
= r1
, right
= r2
;
6276 left
= r2
, right
= r1
;
6278 /* X0 of the intersection is right.x0, if this is inside R1,
6279 otherwise there is no intersection. */
6280 if (right
->x
<= left
->x
+ left
->width
)
6282 result
->x
= right
->x
;
6284 /* The right end of the intersection is the minimum of the
6285 the right ends of left and right. */
6286 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6289 /* Same game for Y. */
6291 upper
= r1
, lower
= r2
;
6293 upper
= r2
, lower
= r1
;
6295 /* The upper end of the intersection is lower.y0, if this is inside
6296 of upper. Otherwise, there is no intersection. */
6297 if (lower
->y
<= upper
->y
+ upper
->height
)
6299 result
->y
= lower
->y
;
6301 /* The lower end of the intersection is the minimum of the lower
6302 ends of upper and lower. */
6303 result
->height
= (min (lower
->y
+ lower
->height
,
6304 upper
->y
+ upper
->height
)
6310 return intersection_p
;
6321 /* We used to only do this if Vx_no_window_manager was non-nil, but
6322 the ICCCM (section 4.1.6) says that the window's border pixmap
6323 and border pixel are window attributes which are "private to the
6324 client", so we can always change it to whatever we want. */
6326 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6327 f
->output_data
.x
->border_pixel
);
6329 x_update_cursor (f
, 1);
6333 frame_unhighlight (f
)
6336 /* We used to only do this if Vx_no_window_manager was non-nil, but
6337 the ICCCM (section 4.1.6) says that the window's border pixmap
6338 and border pixel are window attributes which are "private to the
6339 client", so we can always change it to whatever we want. */
6341 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6342 f
->output_data
.x
->border_tile
);
6344 x_update_cursor (f
, 1);
6347 /* The focus has changed. Update the frames as necessary to reflect
6348 the new situation. Note that we can't change the selected frame
6349 here, because the Lisp code we are interrupting might become confused.
6350 Each event gets marked with the frame in which it occurred, so the
6351 Lisp code can tell when the switch took place by examining the events. */
6354 x_new_focus_frame (dpyinfo
, frame
)
6355 struct x_display_info
*dpyinfo
;
6356 struct frame
*frame
;
6358 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6360 if (frame
!= dpyinfo
->x_focus_frame
)
6362 /* Set this before calling other routines, so that they see
6363 the correct value of x_focus_frame. */
6364 dpyinfo
->x_focus_frame
= frame
;
6366 if (old_focus
&& old_focus
->auto_lower
)
6367 x_lower_frame (old_focus
);
6370 selected_frame
= frame
;
6371 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6373 Fselect_window (selected_frame
->selected_window
);
6374 choose_minibuf_frame ();
6377 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6378 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6380 pending_autoraise_frame
= 0;
6383 x_frame_rehighlight (dpyinfo
);
6386 /* Handle FocusIn and FocusOut state changes for FRAME.
6387 If FRAME has focus and there exists more than one frame, puts
6388 a FOCUS_IN_EVENT into BUFP.
6389 Returns number of events inserted into BUFP. */
6392 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
, numchars
)
6395 struct x_display_info
*dpyinfo
;
6396 struct frame
*frame
;
6397 struct input_event
*bufp
;
6402 if (type
== FocusIn
)
6404 if (dpyinfo
->x_focus_event_frame
!= frame
)
6406 x_new_focus_frame (dpyinfo
, frame
);
6407 dpyinfo
->x_focus_event_frame
= frame
;
6409 /* Don't stop displaying the initial startup message
6410 for a switch-frame event we don't need. */
6412 && GC_NILP (Vterminal_frame
)
6413 && GC_CONSP (Vframe_list
)
6414 && !GC_NILP (XCDR (Vframe_list
)))
6416 bufp
->kind
= FOCUS_IN_EVENT
;
6417 XSETFRAME (bufp
->frame_or_window
, frame
);
6425 frame
->output_data
.x
->focus_state
|= state
;
6428 if (FRAME_XIC (frame
))
6429 XSetICFocus (FRAME_XIC (frame
));
6432 else if (type
== FocusOut
)
6434 frame
->output_data
.x
->focus_state
&= ~state
;
6436 if (dpyinfo
->x_focus_event_frame
== frame
)
6438 dpyinfo
->x_focus_event_frame
= 0;
6439 x_new_focus_frame (dpyinfo
, 0);
6443 if (FRAME_XIC (frame
))
6444 XUnsetICFocus (FRAME_XIC (frame
));
6451 /* The focus may have changed. Figure out if it is a real focus change,
6452 by checking both FocusIn/Out and Enter/LeaveNotify events.
6454 Returns number of events inserted into BUFP. */
6457 x_detect_focus_change (dpyinfo
, event
, bufp
, numchars
)
6458 struct x_display_info
*dpyinfo
;
6460 struct input_event
*bufp
;
6463 struct frame
*frame
;
6466 frame
= x_top_window_to_frame (dpyinfo
, event
->xany
.window
);
6467 if (! frame
) return nr_events
;
6469 switch (event
->type
)
6473 if (event
->xcrossing
.detail
!= NotifyInferior
6474 && event
->xcrossing
.focus
6475 && ! (frame
->output_data
.x
->focus_state
& FOCUS_EXPLICIT
))
6476 nr_events
= x_focus_changed ((event
->type
== EnterNotify
6477 ? FocusIn
: FocusOut
),
6487 nr_events
= x_focus_changed (event
->type
,
6488 (event
->xfocus
.detail
== NotifyPointer
6489 ? FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
6501 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6504 x_mouse_leave (dpyinfo
)
6505 struct x_display_info
*dpyinfo
;
6507 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6510 /* The focus has changed, or we have redirected a frame's focus to
6511 another frame (this happens when a frame uses a surrogate
6512 mini-buffer frame). Shift the highlight as appropriate.
6514 The FRAME argument doesn't necessarily have anything to do with which
6515 frame is being highlighted or un-highlighted; we only use it to find
6516 the appropriate X display info. */
6519 XTframe_rehighlight (frame
)
6520 struct frame
*frame
;
6522 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6526 x_frame_rehighlight (dpyinfo
)
6527 struct x_display_info
*dpyinfo
;
6529 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6531 if (dpyinfo
->x_focus_frame
)
6533 dpyinfo
->x_highlight_frame
6534 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6535 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6536 : dpyinfo
->x_focus_frame
);
6537 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6539 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6540 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6544 dpyinfo
->x_highlight_frame
= 0;
6546 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6549 frame_unhighlight (old_highlight
);
6550 if (dpyinfo
->x_highlight_frame
)
6551 frame_highlight (dpyinfo
->x_highlight_frame
);
6557 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6559 /* Initialize mode_switch_bit and modifier_meaning. */
6561 x_find_modifier_meanings (dpyinfo
)
6562 struct x_display_info
*dpyinfo
;
6564 int min_code
, max_code
;
6567 XModifierKeymap
*mods
;
6569 dpyinfo
->meta_mod_mask
= 0;
6570 dpyinfo
->shift_lock_mask
= 0;
6571 dpyinfo
->alt_mod_mask
= 0;
6572 dpyinfo
->super_mod_mask
= 0;
6573 dpyinfo
->hyper_mod_mask
= 0;
6576 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6578 min_code
= dpyinfo
->display
->min_keycode
;
6579 max_code
= dpyinfo
->display
->max_keycode
;
6582 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6583 min_code
, max_code
- min_code
+ 1,
6585 mods
= XGetModifierMapping (dpyinfo
->display
);
6587 /* Scan the modifier table to see which modifier bits the Meta and
6588 Alt keysyms are on. */
6590 int row
, col
; /* The row and column in the modifier table. */
6592 for (row
= 3; row
< 8; row
++)
6593 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6596 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6598 /* Zeroes are used for filler. Skip them. */
6602 /* Are any of this keycode's keysyms a meta key? */
6606 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6608 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6614 dpyinfo
->meta_mod_mask
|= (1 << row
);
6619 dpyinfo
->alt_mod_mask
|= (1 << row
);
6624 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6629 dpyinfo
->super_mod_mask
|= (1 << row
);
6633 /* Ignore this if it's not on the lock modifier. */
6634 if ((1 << row
) == LockMask
)
6635 dpyinfo
->shift_lock_mask
= LockMask
;
6643 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6644 if (! dpyinfo
->meta_mod_mask
)
6646 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6647 dpyinfo
->alt_mod_mask
= 0;
6650 /* If some keys are both alt and meta,
6651 make them just meta, not alt. */
6652 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6654 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6657 XFree ((char *) syms
);
6658 XFreeModifiermap (mods
);
6661 /* Convert between the modifier bits X uses and the modifier bits
6665 x_x_to_emacs_modifiers (dpyinfo
, state
)
6666 struct x_display_info
*dpyinfo
;
6669 EMACS_UINT mod_meta
= meta_modifier
;
6670 EMACS_UINT mod_alt
= alt_modifier
;
6671 EMACS_UINT mod_hyper
= hyper_modifier
;
6672 EMACS_UINT mod_super
= super_modifier
;
6675 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6676 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6677 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6678 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6679 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6680 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6681 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6682 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6685 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6686 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6687 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
6688 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
6689 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
6690 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
6694 x_emacs_to_x_modifiers (dpyinfo
, state
)
6695 struct x_display_info
*dpyinfo
;
6698 EMACS_UINT mod_meta
= meta_modifier
;
6699 EMACS_UINT mod_alt
= alt_modifier
;
6700 EMACS_UINT mod_hyper
= hyper_modifier
;
6701 EMACS_UINT mod_super
= super_modifier
;
6705 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6706 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6707 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6708 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6709 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6710 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6711 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6712 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6715 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
6716 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
6717 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
6718 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6719 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6720 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
6723 /* Convert a keysym to its name. */
6726 x_get_keysym_name (keysym
)
6732 value
= XKeysymToString (keysym
);
6740 /* Mouse clicks and mouse movement. Rah. */
6742 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6743 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6744 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6745 not force the value into range. */
6748 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6750 register int pix_x
, pix_y
;
6751 register int *x
, *y
;
6755 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6756 even for negative values. */
6758 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6760 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6762 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6763 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6767 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6768 bounds
->height
= f
->output_data
.x
->line_height
;
6769 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6770 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6777 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6778 pix_x
= FRAME_WINDOW_WIDTH (f
);
6782 else if (pix_y
> f
->height
)
6791 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6792 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6793 can't tell the positions because W's display is not up to date,
6797 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6800 int *frame_x
, *frame_y
;
6804 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6805 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6807 if (display_completed
)
6809 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6810 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6811 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6817 *frame_x
+= glyph
->pixel_width
;
6825 *frame_y
= *frame_x
= 0;
6829 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6830 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6835 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6837 If the event is a button press, then note that we have grabbed
6841 construct_mouse_click (result
, event
, f
)
6842 struct input_event
*result
;
6843 XButtonEvent
*event
;
6846 /* Make the event type NO_EVENT; we'll change that when we decide
6848 result
->kind
= MOUSE_CLICK_EVENT
;
6849 result
->code
= event
->button
- Button1
;
6850 result
->timestamp
= event
->time
;
6851 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6853 | (event
->type
== ButtonRelease
6857 XSETINT (result
->x
, event
->x
);
6858 XSETINT (result
->y
, event
->y
);
6859 XSETFRAME (result
->frame_or_window
, f
);
6865 /* Function to report a mouse movement to the mainstream Emacs code.
6866 The input handler calls this.
6868 We have received a mouse movement event, which is given in *event.
6869 If the mouse is over a different glyph than it was last time, tell
6870 the mainstream emacs code by setting mouse_moved. If not, ask for
6871 another motion event, so we can check again the next time it moves. */
6873 static XMotionEvent last_mouse_motion_event
;
6874 static Lisp_Object last_mouse_motion_frame
;
6877 note_mouse_movement (frame
, event
)
6879 XMotionEvent
*event
;
6881 last_mouse_movement_time
= event
->time
;
6882 last_mouse_motion_event
= *event
;
6883 XSETFRAME (last_mouse_motion_frame
, frame
);
6885 if (event
->window
!= FRAME_X_WINDOW (frame
))
6887 frame
->mouse_moved
= 1;
6888 last_mouse_scroll_bar
= Qnil
;
6889 note_mouse_highlight (frame
, -1, -1);
6892 /* Has the mouse moved off the glyph it was on at the last sighting? */
6893 else if (event
->x
< last_mouse_glyph
.x
6894 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6895 || event
->y
< last_mouse_glyph
.y
6896 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6898 frame
->mouse_moved
= 1;
6899 last_mouse_scroll_bar
= Qnil
;
6900 note_mouse_highlight (frame
, event
->x
, event
->y
);
6905 /************************************************************************
6907 ************************************************************************/
6909 /* Find the glyph under window-relative coordinates X/Y in window W.
6910 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6911 strings. Return in *HPOS and *VPOS the row and column number of
6912 the glyph found. Return in *AREA the glyph area containing X.
6913 Value is a pointer to the glyph found or null if X/Y is not on
6914 text, or we can't tell because W's current matrix is not up to
6917 static struct glyph
*
6918 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6921 int *hpos
, *vpos
, *area
;
6924 struct glyph
*glyph
, *end
;
6925 struct glyph_row
*row
= NULL
;
6926 int x0
, i
, left_area_width
;
6928 /* Find row containing Y. Give up if some row is not enabled. */
6929 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6931 row
= MATRIX_ROW (w
->current_matrix
, i
);
6932 if (!row
->enabled_p
)
6934 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6941 /* Give up if Y is not in the window. */
6942 if (i
== w
->current_matrix
->nrows
)
6945 /* Get the glyph area containing X. */
6946 if (w
->pseudo_window_p
)
6953 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6954 if (x
< left_area_width
)
6956 *area
= LEFT_MARGIN_AREA
;
6959 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6962 x0
= row
->x
+ left_area_width
;
6966 *area
= RIGHT_MARGIN_AREA
;
6967 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6971 /* Find glyph containing X. */
6972 glyph
= row
->glyphs
[*area
];
6973 end
= glyph
+ row
->used
[*area
];
6976 if (x
< x0
+ glyph
->pixel_width
)
6978 if (w
->pseudo_window_p
)
6980 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6984 x0
+= glyph
->pixel_width
;
6991 *hpos
= glyph
- row
->glyphs
[*area
];
6996 /* Convert frame-relative x/y to coordinates relative to window W.
6997 Takes pseudo-windows into account. */
7000 frame_to_window_pixel_xy (w
, x
, y
)
7004 if (w
->pseudo_window_p
)
7006 /* A pseudo-window is always full-width, and starts at the
7007 left edge of the frame, plus a frame border. */
7008 struct frame
*f
= XFRAME (w
->frame
);
7009 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
7010 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
7014 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
7015 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
7020 /* Take proper action when mouse has moved to the mode or header line
7021 or marginal area of window W, x-position X and y-position Y. Area
7022 is 1, 3, 6 or 7 for the mode line, header line, left and right
7023 marginal area respectively. X is relative to the start of the text
7024 display area of W, so the width of bitmap areas and scroll bars
7025 must be subtracted to get a position relative to the start of the
7029 note_mode_line_or_margin_highlight (w
, x
, y
, portion
)
7033 struct frame
*f
= XFRAME (w
->frame
);
7034 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7035 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
7037 Lisp_Object string
, help
, map
, pos
;
7039 if (portion
== 1 || portion
== 3)
7040 string
= mode_line_string (w
, x
, y
, portion
== 1, &charpos
);
7042 string
= marginal_area_string (w
, x
, y
, portion
, &charpos
);
7044 if (STRINGP (string
))
7046 pos
= make_number (charpos
);
7048 /* If we're on a string with `help-echo' text property, arrange
7049 for the help to be displayed. This is done by setting the
7050 global variable help_echo to the help string. */
7051 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
7055 XSETWINDOW (help_echo_window
, w
);
7056 help_echo_object
= string
;
7057 help_echo_pos
= charpos
;
7060 /* Change the mouse pointer according to what is under X/Y. */
7061 map
= Fget_text_property (pos
, Qlocal_map
, string
);
7063 map
= Fget_text_property (pos
, Qkeymap
, string
);
7065 cursor
= f
->output_data
.x
->nontext_cursor
;
7068 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7072 /* Take proper action when the mouse has moved to position X, Y on
7073 frame F as regards highlighting characters that have mouse-face
7074 properties. Also de-highlighting chars where the mouse was before.
7075 X and Y can be negative or out of range. */
7078 note_mouse_highlight (f
, x
, y
)
7082 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7086 Cursor cursor
= None
;
7089 /* When a menu is active, don't highlight because this looks odd. */
7090 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7091 if (popup_activated ())
7095 if (NILP (Vmouse_highlight
)
7096 || !f
->glyphs_initialized_p
)
7099 dpyinfo
->mouse_face_mouse_x
= x
;
7100 dpyinfo
->mouse_face_mouse_y
= y
;
7101 dpyinfo
->mouse_face_mouse_frame
= f
;
7103 if (dpyinfo
->mouse_face_defer
)
7108 dpyinfo
->mouse_face_deferred_gc
= 1;
7112 /* Which window is that in? */
7113 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
7115 /* If we were displaying active text in another window, clear that. */
7116 if (! EQ (window
, dpyinfo
->mouse_face_window
))
7117 clear_mouse_face (dpyinfo
);
7119 /* Not on a window -> return. */
7120 if (!WINDOWP (window
))
7123 /* Convert to window-relative pixel coordinates. */
7124 w
= XWINDOW (window
);
7125 frame_to_window_pixel_xy (w
, &x
, &y
);
7127 /* Handle tool-bar window differently since it doesn't display a
7129 if (EQ (window
, f
->tool_bar_window
))
7131 note_tool_bar_highlight (f
, x
, y
);
7135 /* Mouse is on the mode, header line or margin? */
7136 if (portion
== 1 || portion
== 3 || portion
== 6 || portion
== 7)
7138 note_mode_line_or_margin_highlight (w
, x
, y
, portion
);
7143 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
7145 cursor
= f
->output_data
.x
->text_cursor
;
7147 /* Are we in a window whose display is up to date?
7148 And verify the buffer's text has not changed. */
7149 b
= XBUFFER (w
->buffer
);
7150 if (/* Within text portion of the window. */
7152 && EQ (w
->window_end_valid
, w
->buffer
)
7153 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
7154 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
7156 int hpos
, vpos
, pos
, i
, area
;
7157 struct glyph
*glyph
;
7159 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
7160 Lisp_Object
*overlay_vec
= NULL
;
7162 struct buffer
*obuf
;
7163 int obegv
, ozv
, same_region
;
7165 /* Find the glyph under X/Y. */
7166 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
7168 /* Clear mouse face if X/Y not over text. */
7170 || area
!= TEXT_AREA
7171 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
7173 if (clear_mouse_face (dpyinfo
))
7178 pos
= glyph
->charpos
;
7179 object
= glyph
->object
;
7180 if (!STRINGP (object
) && !BUFFERP (object
))
7183 /* If we get an out-of-range value, return now; avoid an error. */
7184 if (BUFFERP (object
) && pos
> BUF_Z (b
))
7187 /* Make the window's buffer temporarily current for
7188 overlays_at and compute_char_face. */
7189 obuf
= current_buffer
;
7196 /* Is this char mouse-active or does it have help-echo? */
7197 position
= make_number (pos
);
7199 if (BUFFERP (object
))
7201 /* Put all the overlays we want in a vector in overlay_vec.
7202 Store the length in len. If there are more than 10, make
7203 enough space for all, and try again. */
7205 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7206 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
7207 if (noverlays
> len
)
7210 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7211 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
7214 /* Sort overlays into increasing priority order. */
7215 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7220 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
7221 && vpos
>= dpyinfo
->mouse_face_beg_row
7222 && vpos
<= dpyinfo
->mouse_face_end_row
7223 && (vpos
> dpyinfo
->mouse_face_beg_row
7224 || hpos
>= dpyinfo
->mouse_face_beg_col
)
7225 && (vpos
< dpyinfo
->mouse_face_end_row
7226 || hpos
< dpyinfo
->mouse_face_end_col
7227 || dpyinfo
->mouse_face_past_end
));
7232 /* Check mouse-face highlighting. */
7234 /* If there exists an overlay with mouse-face overlapping
7235 the one we are currently highlighting, we have to
7236 check if we enter the overlapping overlay, and then
7237 highlight only that. */
7238 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
7239 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
7241 /* Find the highest priority overlay that has a mouse-face
7244 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
7246 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
7247 if (!NILP (mouse_face
))
7248 overlay
= overlay_vec
[i
];
7251 /* If we're actually highlighting the same overlay as
7252 before, there's no need to do that again. */
7254 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
7255 goto check_help_echo
;
7257 dpyinfo
->mouse_face_overlay
= overlay
;
7259 /* Clear the display of the old active region, if any. */
7260 if (clear_mouse_face (dpyinfo
))
7263 /* If no overlay applies, get a text property. */
7265 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7267 /* Handle the overlay case. */
7268 if (!NILP (overlay
))
7270 /* Find the range of text around this char that
7271 should be active. */
7272 Lisp_Object before
, after
;
7275 before
= Foverlay_start (overlay
);
7276 after
= Foverlay_end (overlay
);
7277 /* Record this as the current active region. */
7278 fast_find_position (w
, XFASTINT (before
),
7279 &dpyinfo
->mouse_face_beg_col
,
7280 &dpyinfo
->mouse_face_beg_row
,
7281 &dpyinfo
->mouse_face_beg_x
,
7282 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7284 dpyinfo
->mouse_face_past_end
7285 = !fast_find_position (w
, XFASTINT (after
),
7286 &dpyinfo
->mouse_face_end_col
,
7287 &dpyinfo
->mouse_face_end_row
,
7288 &dpyinfo
->mouse_face_end_x
,
7289 &dpyinfo
->mouse_face_end_y
, Qnil
);
7290 dpyinfo
->mouse_face_window
= window
;
7291 dpyinfo
->mouse_face_face_id
7292 = face_at_buffer_position (w
, pos
, 0, 0,
7294 !dpyinfo
->mouse_face_hidden
);
7296 /* Display it as active. */
7297 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7300 /* Handle the text property case. */
7301 else if (!NILP (mouse_face
) && BUFFERP (object
))
7303 /* Find the range of text around this char that
7304 should be active. */
7305 Lisp_Object before
, after
, beginning
, end
;
7308 beginning
= Fmarker_position (w
->start
);
7309 end
= make_number (BUF_Z (XBUFFER (object
))
7310 - XFASTINT (w
->window_end_pos
));
7312 = Fprevious_single_property_change (make_number (pos
+ 1),
7316 = Fnext_single_property_change (position
, Qmouse_face
,
7319 /* Record this as the current active region. */
7320 fast_find_position (w
, XFASTINT (before
),
7321 &dpyinfo
->mouse_face_beg_col
,
7322 &dpyinfo
->mouse_face_beg_row
,
7323 &dpyinfo
->mouse_face_beg_x
,
7324 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7325 dpyinfo
->mouse_face_past_end
7326 = !fast_find_position (w
, XFASTINT (after
),
7327 &dpyinfo
->mouse_face_end_col
,
7328 &dpyinfo
->mouse_face_end_row
,
7329 &dpyinfo
->mouse_face_end_x
,
7330 &dpyinfo
->mouse_face_end_y
, Qnil
);
7331 dpyinfo
->mouse_face_window
= window
;
7333 if (BUFFERP (object
))
7334 dpyinfo
->mouse_face_face_id
7335 = face_at_buffer_position (w
, pos
, 0, 0,
7337 !dpyinfo
->mouse_face_hidden
);
7339 /* Display it as active. */
7340 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7343 else if (!NILP (mouse_face
) && STRINGP (object
))
7348 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7351 e
= Fnext_single_property_change (position
, Qmouse_face
,
7354 b
= make_number (0);
7356 e
= make_number (SCHARS (object
) - 1);
7357 fast_find_string_pos (w
, XINT (b
), object
,
7358 &dpyinfo
->mouse_face_beg_col
,
7359 &dpyinfo
->mouse_face_beg_row
,
7360 &dpyinfo
->mouse_face_beg_x
,
7361 &dpyinfo
->mouse_face_beg_y
, 0);
7362 fast_find_string_pos (w
, XINT (e
), object
,
7363 &dpyinfo
->mouse_face_end_col
,
7364 &dpyinfo
->mouse_face_end_row
,
7365 &dpyinfo
->mouse_face_end_x
,
7366 &dpyinfo
->mouse_face_end_y
, 1);
7367 dpyinfo
->mouse_face_past_end
= 0;
7368 dpyinfo
->mouse_face_window
= window
;
7369 dpyinfo
->mouse_face_face_id
7370 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7372 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7375 else if (STRINGP (object
) && NILP (mouse_face
))
7377 /* A string which doesn't have mouse-face, but
7378 the text ``under'' it might have. */
7379 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7380 int start
= MATRIX_ROW_START_CHARPOS (r
);
7382 pos
= string_buffer_position (w
, object
, start
);
7384 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7388 if (!NILP (mouse_face
) && !NILP (overlay
))
7390 Lisp_Object before
= Foverlay_start (overlay
);
7391 Lisp_Object after
= Foverlay_end (overlay
);
7394 /* Note that we might not be able to find position
7395 BEFORE in the glyph matrix if the overlay is
7396 entirely covered by a `display' property. In
7397 this case, we overshoot. So let's stop in
7398 the glyph matrix before glyphs for OBJECT. */
7399 fast_find_position (w
, XFASTINT (before
),
7400 &dpyinfo
->mouse_face_beg_col
,
7401 &dpyinfo
->mouse_face_beg_row
,
7402 &dpyinfo
->mouse_face_beg_x
,
7403 &dpyinfo
->mouse_face_beg_y
,
7406 dpyinfo
->mouse_face_past_end
7407 = !fast_find_position (w
, XFASTINT (after
),
7408 &dpyinfo
->mouse_face_end_col
,
7409 &dpyinfo
->mouse_face_end_row
,
7410 &dpyinfo
->mouse_face_end_x
,
7411 &dpyinfo
->mouse_face_end_y
,
7413 dpyinfo
->mouse_face_window
= window
;
7414 dpyinfo
->mouse_face_face_id
7415 = face_at_buffer_position (w
, pos
, 0, 0,
7417 !dpyinfo
->mouse_face_hidden
);
7419 /* Display it as active. */
7420 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7428 /* Look for a `help-echo' property. */
7430 Lisp_Object help
, overlay
;
7432 /* Check overlays first. */
7433 help
= overlay
= Qnil
;
7434 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7436 overlay
= overlay_vec
[i
];
7437 help
= Foverlay_get (overlay
, Qhelp_echo
);
7443 help_echo_window
= window
;
7444 help_echo_object
= overlay
;
7445 help_echo_pos
= pos
;
7449 Lisp_Object object
= glyph
->object
;
7450 int charpos
= glyph
->charpos
;
7452 /* Try text properties. */
7453 if (STRINGP (object
)
7455 && charpos
< SCHARS (object
))
7457 help
= Fget_text_property (make_number (charpos
),
7458 Qhelp_echo
, object
);
7461 /* If the string itself doesn't specify a help-echo,
7462 see if the buffer text ``under'' it does. */
7464 = MATRIX_ROW (w
->current_matrix
, vpos
);
7465 int start
= MATRIX_ROW_START_CHARPOS (r
);
7466 int pos
= string_buffer_position (w
, object
, start
);
7469 help
= Fget_char_property (make_number (pos
),
7470 Qhelp_echo
, w
->buffer
);
7479 else if (BUFFERP (object
)
7482 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7488 help_echo_window
= window
;
7489 help_echo_object
= object
;
7490 help_echo_pos
= charpos
;
7497 current_buffer
= obuf
;
7503 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7507 redo_mouse_highlight ()
7509 if (!NILP (last_mouse_motion_frame
)
7510 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7511 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7512 last_mouse_motion_event
.x
,
7513 last_mouse_motion_event
.y
);
7518 /***********************************************************************
7520 ***********************************************************************/
7522 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7523 struct glyph
**, int *, int *, int *));
7525 /* Tool-bar item index of the item on which a mouse button was pressed
7528 static int last_tool_bar_item
;
7531 /* Get information about the tool-bar item at position X/Y on frame F.
7532 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7533 the current matrix of the tool-bar window of F, or NULL if not
7534 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7535 item in F->tool_bar_items. Value is
7537 -1 if X/Y is not on a tool-bar item
7538 0 if X/Y is on the same item that was highlighted before.
7542 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7545 struct glyph
**glyph
;
7546 int *hpos
, *vpos
, *prop_idx
;
7548 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7549 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7552 /* Find the glyph under X/Y. */
7553 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7557 /* Get the start of this tool-bar item's properties in
7558 f->tool_bar_items. */
7559 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7562 /* Is mouse on the highlighted item? */
7563 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7564 && *vpos
>= dpyinfo
->mouse_face_beg_row
7565 && *vpos
<= dpyinfo
->mouse_face_end_row
7566 && (*vpos
> dpyinfo
->mouse_face_beg_row
7567 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7568 && (*vpos
< dpyinfo
->mouse_face_end_row
7569 || *hpos
< dpyinfo
->mouse_face_end_col
7570 || dpyinfo
->mouse_face_past_end
))
7577 /* Handle mouse button event on the tool-bar of frame F, at
7578 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
7582 x_handle_tool_bar_click (f
, button_event
)
7584 XButtonEvent
*button_event
;
7586 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7587 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7588 int hpos
, vpos
, prop_idx
;
7589 struct glyph
*glyph
;
7590 Lisp_Object enabled_p
;
7591 int x
= button_event
->x
;
7592 int y
= button_event
->y
;
7594 /* If not on the highlighted tool-bar item, return. */
7595 frame_to_window_pixel_xy (w
, &x
, &y
);
7596 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7599 /* If item is disabled, do nothing. */
7600 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7601 if (NILP (enabled_p
))
7604 if (button_event
->type
== ButtonPress
)
7606 /* Show item in pressed state. */
7607 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7608 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7609 last_tool_bar_item
= prop_idx
;
7613 Lisp_Object key
, frame
;
7614 struct input_event event
;
7616 /* Show item in released state. */
7617 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7618 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7620 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7622 XSETFRAME (frame
, f
);
7623 event
.kind
= TOOL_BAR_EVENT
;
7624 event
.frame_or_window
= frame
;
7626 kbd_buffer_store_event (&event
);
7628 event
.kind
= TOOL_BAR_EVENT
;
7629 event
.frame_or_window
= frame
;
7631 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7632 button_event
->state
);
7633 kbd_buffer_store_event (&event
);
7634 last_tool_bar_item
= -1;
7639 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7640 tool-bar window-relative coordinates X/Y. Called from
7641 note_mouse_highlight. */
7644 note_tool_bar_highlight (f
, x
, y
)
7648 Lisp_Object window
= f
->tool_bar_window
;
7649 struct window
*w
= XWINDOW (window
);
7650 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7652 struct glyph
*glyph
;
7653 struct glyph_row
*row
;
7655 Lisp_Object enabled_p
;
7657 enum draw_glyphs_face draw
;
7658 int mouse_down_p
, rc
;
7660 /* Function note_mouse_highlight is called with negative x(y
7661 values when mouse moves outside of the frame. */
7662 if (x
<= 0 || y
<= 0)
7664 clear_mouse_face (dpyinfo
);
7668 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7671 /* Not on tool-bar item. */
7672 clear_mouse_face (dpyinfo
);
7678 clear_mouse_face (dpyinfo
);
7680 /* Mouse is down, but on different tool-bar item? */
7681 mouse_down_p
= (dpyinfo
->grabbed
7682 && f
== last_mouse_frame
7683 && FRAME_LIVE_P (f
));
7685 && last_tool_bar_item
!= prop_idx
)
7688 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7689 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7691 /* If tool-bar item is not enabled, don't highlight it. */
7692 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7693 if (!NILP (enabled_p
))
7695 /* Compute the x-position of the glyph. In front and past the
7696 image is a space. We include this is the highlighted area. */
7697 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7698 for (i
= x
= 0; i
< hpos
; ++i
)
7699 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7701 /* Record this as the current active region. */
7702 dpyinfo
->mouse_face_beg_col
= hpos
;
7703 dpyinfo
->mouse_face_beg_row
= vpos
;
7704 dpyinfo
->mouse_face_beg_x
= x
;
7705 dpyinfo
->mouse_face_beg_y
= row
->y
;
7706 dpyinfo
->mouse_face_past_end
= 0;
7708 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7709 dpyinfo
->mouse_face_end_row
= vpos
;
7710 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7711 dpyinfo
->mouse_face_end_y
= row
->y
;
7712 dpyinfo
->mouse_face_window
= window
;
7713 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7715 /* Display it as active. */
7716 show_mouse_face (dpyinfo
, draw
);
7717 dpyinfo
->mouse_face_image_state
= draw
;
7722 /* Set help_echo to a help string to display for this tool-bar item.
7723 XTread_socket does the rest. */
7724 help_echo_object
= help_echo_window
= Qnil
;
7726 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7727 if (NILP (help_echo
))
7728 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7733 /* Find the glyph matrix position of buffer position CHARPOS in window
7734 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7735 current glyphs must be up to date. If CHARPOS is above window
7736 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7737 of last line in W. In the row containing CHARPOS, stop before glyphs
7738 having STOP as object. */
7740 #if 0 /* This is a version of fast_find_position that's more correct
7741 in the presence of hscrolling, for example. I didn't install
7742 it right away because the problem fixed is minor, it failed
7743 in 20.x as well, and I think it's too risky to install
7744 so near the release of 21.1. 2001-09-25 gerd. */
7747 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7750 int *hpos
, *vpos
, *x
, *y
;
7753 struct glyph_row
*row
, *first
;
7754 struct glyph
*glyph
, *end
;
7755 int i
, past_end
= 0;
7757 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7758 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7761 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7763 *x
= *y
= *hpos
= *vpos
= 0;
7768 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7775 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7777 glyph
= row
->glyphs
[TEXT_AREA
];
7778 end
= glyph
+ row
->used
[TEXT_AREA
];
7780 /* Skip over glyphs not having an object at the start of the row.
7781 These are special glyphs like truncation marks on terminal
7783 if (row
->displays_text_p
)
7785 && INTEGERP (glyph
->object
)
7786 && !EQ (stop
, glyph
->object
)
7787 && glyph
->charpos
< 0)
7789 *x
+= glyph
->pixel_width
;
7794 && !INTEGERP (glyph
->object
)
7795 && !EQ (stop
, glyph
->object
)
7796 && (!BUFFERP (glyph
->object
)
7797 || glyph
->charpos
< charpos
))
7799 *x
+= glyph
->pixel_width
;
7803 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7810 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7813 int *hpos
, *vpos
, *x
, *y
;
7818 int maybe_next_line_p
= 0;
7819 int line_start_position
;
7820 int yb
= window_text_bottom_y (w
);
7821 struct glyph_row
*row
, *best_row
;
7822 int row_vpos
, best_row_vpos
;
7825 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7826 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7830 if (row
->used
[TEXT_AREA
])
7831 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7833 line_start_position
= 0;
7835 if (line_start_position
> pos
)
7837 /* If the position sought is the end of the buffer,
7838 don't include the blank lines at the bottom of the window. */
7839 else if (line_start_position
== pos
7840 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7842 maybe_next_line_p
= 1;
7845 else if (line_start_position
> 0)
7848 best_row_vpos
= row_vpos
;
7851 if (row
->y
+ row
->height
>= yb
)
7858 /* Find the right column within BEST_ROW. */
7860 current_x
= best_row
->x
;
7861 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7863 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7864 int charpos
= glyph
->charpos
;
7866 if (BUFFERP (glyph
->object
))
7871 *vpos
= best_row_vpos
;
7876 else if (charpos
> pos
)
7879 else if (EQ (glyph
->object
, stop
))
7884 current_x
+= glyph
->pixel_width
;
7887 /* If we're looking for the end of the buffer,
7888 and we didn't find it in the line we scanned,
7889 use the start of the following line. */
7890 if (maybe_next_line_p
)
7895 current_x
= best_row
->x
;
7898 *vpos
= best_row_vpos
;
7899 *hpos
= lastcol
+ 1;
7908 /* Find the position of the glyph for position POS in OBJECT in
7909 window W's current matrix, and return in *X, *Y the pixel
7910 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
7912 RIGHT_P non-zero means return the position of the right edge of the
7913 glyph, RIGHT_P zero means return the left edge position.
7915 If no glyph for POS exists in the matrix, return the position of
7916 the glyph with the next smaller position that is in the matrix, if
7917 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7918 exists in the matrix, return the position of the glyph with the
7919 next larger position in OBJECT.
7921 Value is non-zero if a glyph was found. */
7924 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7928 int *hpos
, *vpos
, *x
, *y
;
7931 int yb
= window_text_bottom_y (w
);
7932 struct glyph_row
*r
;
7933 struct glyph
*best_glyph
= NULL
;
7934 struct glyph_row
*best_row
= NULL
;
7937 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7938 r
->enabled_p
&& r
->y
< yb
;
7941 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7942 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7945 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7946 if (EQ (g
->object
, object
))
7948 if (g
->charpos
== pos
)
7955 else if (best_glyph
== NULL
7956 || ((abs (g
->charpos
- pos
)
7957 < abs (best_glyph
->charpos
- pos
))
7960 : g
->charpos
> pos
)))
7974 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7978 *x
+= best_glyph
->pixel_width
;
7983 *vpos
= best_row
- w
->current_matrix
->rows
;
7986 return best_glyph
!= NULL
;
7990 /* Display the active region described by mouse_face_*
7991 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7994 show_mouse_face (dpyinfo
, draw
)
7995 struct x_display_info
*dpyinfo
;
7996 enum draw_glyphs_face draw
;
7998 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7999 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8001 if (/* If window is in the process of being destroyed, don't bother
8003 w
->current_matrix
!= NULL
8004 /* Don't update mouse highlight if hidden */
8005 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
8006 /* Recognize when we are called to operate on rows that don't exist
8007 anymore. This can happen when a window is split. */
8008 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
8010 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
8011 struct glyph_row
*row
, *first
, *last
;
8013 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
8014 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
8016 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
8018 int start_hpos
, end_hpos
, start_x
;
8020 /* For all but the first row, the highlight starts at column 0. */
8023 start_hpos
= dpyinfo
->mouse_face_beg_col
;
8024 start_x
= dpyinfo
->mouse_face_beg_x
;
8033 end_hpos
= dpyinfo
->mouse_face_end_col
;
8035 end_hpos
= row
->used
[TEXT_AREA
];
8037 if (end_hpos
> start_hpos
)
8039 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
8040 start_hpos
, end_hpos
, draw
, 0);
8043 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
8047 /* When we've written over the cursor, arrange for it to
8048 be displayed again. */
8049 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
8050 x_display_cursor (w
, 1,
8051 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
8052 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
8055 /* Change the mouse cursor. */
8056 if (draw
== DRAW_NORMAL_TEXT
)
8057 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8058 f
->output_data
.x
->text_cursor
);
8059 else if (draw
== DRAW_MOUSE_FACE
)
8060 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8061 f
->output_data
.x
->cross_cursor
);
8063 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8064 f
->output_data
.x
->nontext_cursor
);
8067 /* Clear out the mouse-highlighted active region.
8068 Redraw it un-highlighted first. Value is non-zero if mouse
8069 face was actually drawn unhighlighted. */
8072 clear_mouse_face (dpyinfo
)
8073 struct x_display_info
*dpyinfo
;
8077 if (!NILP (dpyinfo
->mouse_face_window
))
8079 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
8083 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
8084 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
8085 dpyinfo
->mouse_face_window
= Qnil
;
8086 dpyinfo
->mouse_face_overlay
= Qnil
;
8091 /* Clear any mouse-face on window W. This function is part of the
8092 redisplay interface, and is called from try_window_id and similar
8093 functions to ensure the mouse-highlight is off. */
8096 x_clear_mouse_face (w
)
8099 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
8103 XSETWINDOW (window
, w
);
8104 if (EQ (window
, dpyinfo
->mouse_face_window
))
8105 clear_mouse_face (dpyinfo
);
8110 /* Just discard the mouse face information for frame F, if any.
8111 This is used when the size of F is changed. */
8114 cancel_mouse_face (f
)
8118 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8120 window
= dpyinfo
->mouse_face_window
;
8121 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
8123 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
8124 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
8125 dpyinfo
->mouse_face_window
= Qnil
;
8130 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
8133 /* Try to determine frame pixel position and size of the glyph under
8134 frame pixel coordinates X/Y on frame F . Return the position and
8135 size in *RECT. Value is non-zero if we could compute these
8139 glyph_rect (f
, x
, y
, rect
)
8145 int part
, found
= 0;
8147 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
8150 struct window
*w
= XWINDOW (window
);
8151 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
8152 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
8154 frame_to_window_pixel_xy (w
, &x
, &y
);
8156 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
8159 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
8160 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
8163 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
8166 rect
->width
= g
->pixel_width
;
8167 rect
->height
= r
->height
;
8168 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
8169 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
8179 /* Return the current position of the mouse.
8180 *FP should be a frame which indicates which display to ask about.
8182 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
8183 and *PART to the frame, window, and scroll bar part that the mouse
8184 is over. Set *X and *Y to the portion and whole of the mouse's
8185 position on the scroll bar.
8187 If the mouse movement started elsewhere, set *FP to the frame the
8188 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
8191 Set *TIME to the server time-stamp for the time at which the mouse
8192 was at this position.
8194 Don't store anything if we don't have a valid set of values to report.
8196 This clears the mouse_moved flag, so we can wait for the next mouse
8200 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
8203 Lisp_Object
*bar_window
;
8204 enum scroll_bar_part
*part
;
8206 unsigned long *time
;
8212 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
8213 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
8219 Window dummy_window
;
8222 Lisp_Object frame
, tail
;
8224 /* Clear the mouse-moved flag for every frame on this display. */
8225 FOR_EACH_FRAME (tail
, frame
)
8226 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
8227 XFRAME (frame
)->mouse_moved
= 0;
8229 last_mouse_scroll_bar
= Qnil
;
8231 /* Figure out which root window we're on. */
8232 XQueryPointer (FRAME_X_DISPLAY (*fp
),
8233 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
8235 /* The root window which contains the pointer. */
8238 /* Trash which we can't trust if the pointer is on
8239 a different screen. */
8242 /* The position on that root window. */
8245 /* More trash we can't trust. */
8248 /* Modifier keys and pointer buttons, about which
8250 (unsigned int *) &dummy
);
8252 /* Now we have a position on the root; find the innermost window
8253 containing the pointer. */
8257 int parent_x
= 0, parent_y
= 0;
8262 /* XTranslateCoordinates can get errors if the window
8263 structure is changing at the same time this function
8264 is running. So at least we must not crash from them. */
8266 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
8268 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
8269 && FRAME_LIVE_P (last_mouse_frame
))
8271 /* If mouse was grabbed on a frame, give coords for that frame
8272 even if the mouse is now outside it. */
8273 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8275 /* From-window, to-window. */
8276 root
, FRAME_X_WINDOW (last_mouse_frame
),
8278 /* From-position, to-position. */
8279 root_x
, root_y
, &win_x
, &win_y
,
8283 f1
= last_mouse_frame
;
8289 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8291 /* From-window, to-window. */
8294 /* From-position, to-position. */
8295 root_x
, root_y
, &win_x
, &win_y
,
8300 if (child
== None
|| child
== win
)
8308 /* Now we know that:
8309 win is the innermost window containing the pointer
8310 (XTC says it has no child containing the pointer),
8311 win_x and win_y are the pointer's position in it
8312 (XTC did this the last time through), and
8313 parent_x and parent_y are the pointer's position in win's parent.
8314 (They are what win_x and win_y were when win was child.
8315 If win is the root window, it has no parent, and
8316 parent_{x,y} are invalid, but that's okay, because we'll
8317 never use them in that case.) */
8319 /* Is win one of our frames? */
8320 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
8322 #ifdef USE_X_TOOLKIT
8323 /* If we end up with the menu bar window, say it's not
8326 && f1
->output_data
.x
->menubar_widget
8327 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
8329 #endif /* USE_X_TOOLKIT */
8332 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
8335 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
8337 /* If not, is it one of our scroll bars? */
8340 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
8344 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8350 if (f1
== 0 && insist
> 0)
8351 f1
= SELECTED_FRAME ();
8355 /* Ok, we found a frame. Store all the values.
8356 last_mouse_glyph is a rectangle used to reduce the
8357 generation of mouse events. To not miss any motion
8358 events, we must divide the frame into rectangles of the
8359 size of the smallest character that could be displayed
8360 on it, i.e. into the same rectangles that matrices on
8361 the frame are divided into. */
8363 int width
, height
, gx
, gy
;
8366 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
8367 last_mouse_glyph
= rect
;
8370 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8371 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8375 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8376 round down even for negative values. */
8381 gx
= (gx
+ width
- 1) / width
* width
;
8382 gy
= (gy
+ height
- 1) / height
* height
;
8384 last_mouse_glyph
.width
= width
;
8385 last_mouse_glyph
.height
= height
;
8386 last_mouse_glyph
.x
= gx
;
8387 last_mouse_glyph
.y
= gy
;
8393 XSETINT (*x
, win_x
);
8394 XSETINT (*y
, win_y
);
8395 *time
= last_mouse_movement_time
;
8404 #ifdef USE_X_TOOLKIT
8406 /* Atimer callback function for TIMER. Called every 0.1s to process
8407 Xt timeouts, if needed. We must avoid calling XtAppPending as
8408 much as possible because that function does an implicit XFlush
8409 that slows us down. */
8412 x_process_timeouts (timer
)
8413 struct atimer
*timer
;
8415 if (toolkit_scroll_bar_interaction
|| popup_activated ())
8418 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8419 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8424 #endif /* USE_X_TOOLKIT */
8427 /* Scroll bar support. */
8429 /* Given an X window ID, find the struct scroll_bar which manages it.
8430 This can be called in GC, so we have to make sure to strip off mark
8433 static struct scroll_bar
*
8434 x_window_to_scroll_bar (window_id
)
8439 for (tail
= Vframe_list
;
8440 XGCTYPE (tail
) == Lisp_Cons
;
8443 Lisp_Object frame
, bar
, condemned
;
8445 frame
= XCAR (tail
);
8446 /* All elements of Vframe_list should be frames. */
8447 if (! GC_FRAMEP (frame
))
8450 /* Scan this frame's scroll bar list for a scroll bar with the
8452 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8453 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8454 /* This trick allows us to search both the ordinary and
8455 condemned scroll bar lists with one loop. */
8456 ! GC_NILP (bar
) || (bar
= condemned
,
8459 bar
= XSCROLL_BAR (bar
)->next
)
8460 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8461 return XSCROLL_BAR (bar
);
8468 #if defined USE_LUCID
8470 /* Return the Lucid menu bar WINDOW is part of. Return null
8471 if WINDOW is not part of a menu bar. */
8474 x_window_to_menu_bar (window
)
8479 for (tail
= Vframe_list
;
8480 XGCTYPE (tail
) == Lisp_Cons
;
8483 Lisp_Object frame
= XCAR (tail
);
8484 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8486 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8493 #endif /* USE_LUCID */
8496 /************************************************************************
8498 ************************************************************************/
8500 #ifdef USE_TOOLKIT_SCROLL_BARS
8502 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8503 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8504 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8505 struct scroll_bar
*));
8506 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8510 /* Lisp window being scrolled. Set when starting to interact with
8511 a toolkit scroll bar, reset to nil when ending the interaction. */
8513 static Lisp_Object window_being_scrolled
;
8515 /* Last scroll bar part sent in xm_scroll_callback. */
8517 static int last_scroll_bar_part
;
8519 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8520 that movements of 1/20 of the screen size are mapped to up/down. */
8523 /* Id of action hook installed for scroll bars. */
8525 static XtActionHookId action_hook_id
;
8527 static Boolean xaw3d_arrow_scroll
;
8529 /* Whether the drag scrolling maintains the mouse at the top of the
8530 thumb. If not, resizing the thumb needs to be done more carefully
8531 to avoid jerkyness. */
8533 static Boolean xaw3d_pick_top
;
8536 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8537 bars are used.. The hook is responsible for detecting when
8538 the user ends an interaction with the scroll bar, and generates
8539 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
8542 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8545 XtPointer client_data
;
8549 Cardinal
*num_params
;
8555 scroll_bar_p
= XmIsScrollBar (widget
);
8556 end_action
= "Release";
8557 #else /* !USE_MOTIF i.e. use Xaw */
8558 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8559 end_action
= "EndScroll";
8560 #endif /* USE_MOTIF */
8563 && strcmp (action_name
, end_action
) == 0
8564 && WINDOWP (window_being_scrolled
))
8568 x_send_scroll_bar_event (window_being_scrolled
,
8569 scroll_bar_end_scroll
, 0, 0);
8570 w
= XWINDOW (window_being_scrolled
);
8571 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8572 window_being_scrolled
= Qnil
;
8573 last_scroll_bar_part
= -1;
8575 /* Xt timeouts no longer needed. */
8576 toolkit_scroll_bar_interaction
= 0;
8579 #endif /* not USE_GTK */
8581 /* A vector of windows used for communication between
8582 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8584 static struct window
**scroll_bar_windows
;
8585 static int scroll_bar_windows_size
;
8588 /* Send a client message with message type Xatom_Scrollbar for a
8589 scroll action to the frame of WINDOW. PART is a value identifying
8590 the part of the scroll bar that was clicked on. PORTION is the
8591 amount to scroll of a whole of WHOLE. */
8594 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8596 int part
, portion
, whole
;
8599 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8600 struct window
*w
= XWINDOW (window
);
8601 struct frame
*f
= XFRAME (w
->frame
);
8606 /* Construct a ClientMessage event to send to the frame. */
8607 ev
->type
= ClientMessage
;
8608 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8609 ev
->display
= FRAME_X_DISPLAY (f
);
8610 ev
->window
= FRAME_X_WINDOW (f
);
8613 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8614 not enough to store a pointer or Lisp_Object on a 64 bit system.
8615 So, store the window in scroll_bar_windows and pass the index
8616 into that array in the event. */
8617 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8618 if (scroll_bar_windows
[i
] == NULL
)
8621 if (i
== scroll_bar_windows_size
)
8623 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8624 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8625 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8627 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8629 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8630 scroll_bar_windows_size
= new_size
;
8633 scroll_bar_windows
[i
] = w
;
8634 ev
->data
.l
[0] = (long) i
;
8635 ev
->data
.l
[1] = (long) part
;
8636 ev
->data
.l
[2] = (long) 0;
8637 ev
->data
.l
[3] = (long) portion
;
8638 ev
->data
.l
[4] = (long) whole
;
8640 /* Make Xt timeouts work while the scroll bar is active. */
8641 toolkit_scroll_bar_interaction
= 1;
8643 /* Setting the event mask to zero means that the message will
8644 be sent to the client that created the window, and if that
8645 window no longer exists, no event will be sent. */
8646 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8651 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8655 x_scroll_bar_to_input_event (event
, ievent
)
8657 struct input_event
*ievent
;
8659 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8664 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8665 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8667 XSETWINDOW (window
, w
);
8668 f
= XFRAME (w
->frame
);
8670 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
8671 ievent
->frame_or_window
= window
;
8674 ievent
->timestamp
= CurrentTime
;
8676 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8678 ievent
->part
= ev
->data
.l
[1];
8679 ievent
->code
= ev
->data
.l
[2];
8680 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8681 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8682 ievent
->modifiers
= 0;
8688 /* Minimum and maximum values used for Motif scroll bars. */
8691 #define XM_SB_MAX 10000000
8692 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8695 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8696 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8697 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
8700 xm_scroll_callback (widget
, client_data
, call_data
)
8702 XtPointer client_data
, call_data
;
8704 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8705 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8706 int part
= -1, whole
= 0, portion
= 0;
8710 case XmCR_DECREMENT
:
8711 bar
->dragging
= Qnil
;
8712 part
= scroll_bar_up_arrow
;
8715 case XmCR_INCREMENT
:
8716 bar
->dragging
= Qnil
;
8717 part
= scroll_bar_down_arrow
;
8720 case XmCR_PAGE_DECREMENT
:
8721 bar
->dragging
= Qnil
;
8722 part
= scroll_bar_above_handle
;
8725 case XmCR_PAGE_INCREMENT
:
8726 bar
->dragging
= Qnil
;
8727 part
= scroll_bar_below_handle
;
8731 bar
->dragging
= Qnil
;
8732 part
= scroll_bar_to_top
;
8735 case XmCR_TO_BOTTOM
:
8736 bar
->dragging
= Qnil
;
8737 part
= scroll_bar_to_bottom
;
8743 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8744 && XINT (bar
->dragging
) <= cs
->value
);
8746 /* Get the slider size. */
8748 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8751 whole
= XM_SB_RANGE
- slider_size
;
8752 portion
= min (cs
->value
- XM_SB_MIN
, whole
);
8753 part
= scroll_bar_handle
;
8754 bar
->dragging
= make_number (cs
->value
);
8758 case XmCR_VALUE_CHANGED
:
8764 window_being_scrolled
= bar
->window
;
8765 last_scroll_bar_part
= part
;
8766 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8771 #else /* !USE_MOTIF, i.e. Xaw or GTK */
8773 /* Scroll bar callback for Gtk scroll bars. WIDGET is the scroll
8774 bar adjustment widget. DATA is a pointer to the scroll_bar structure. */
8777 xg_scroll_callback (widget
, data
)
8781 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
8787 int part
= -1, whole
= 0, portion
= 0;
8788 GtkAdjustment
*adj
= GTK_ADJUSTMENT (widget
);
8790 if (xg_ignore_gtk_scrollbar
) return;
8792 position
= gtk_adjustment_get_value (adj
);
8794 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
8797 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
8799 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
8805 diff
= (int) (position
- previous
);
8807 if (diff
== (int) adj
->step_increment
)
8809 part
= scroll_bar_down_arrow
;
8810 bar
->dragging
= Qnil
;
8812 else if (-diff
== (int) adj
->step_increment
)
8814 part
= scroll_bar_up_arrow
;
8815 bar
->dragging
= Qnil
;
8817 else if (diff
== (int) adj
->page_increment
)
8819 part
= scroll_bar_below_handle
;
8820 bar
->dragging
= Qnil
;
8822 else if (-diff
== (int) adj
->page_increment
)
8824 part
= scroll_bar_above_handle
;
8825 bar
->dragging
= Qnil
;
8829 part
= scroll_bar_handle
;
8830 whole
= adj
->upper
- adj
->page_size
;
8831 portion
= min (position
, whole
);
8832 bar
->dragging
= make_number (portion
);
8837 xg_ignore_next_thumb
= 1;
8838 window_being_scrolled
= bar
->window
;
8839 last_scroll_bar_part
= part
;
8840 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8844 #else /* not USE_GTK */
8846 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8847 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8848 scroll bar struct. CALL_DATA is a pointer to a float saying where
8852 xaw_jump_callback (widget
, client_data
, call_data
)
8854 XtPointer client_data
, call_data
;
8856 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8857 float top
= *(float *) call_data
;
8859 int whole
, portion
, height
;
8862 /* Get the size of the thumb, a value between 0 and 1. */
8864 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8868 portion
= shown
< 1 ? top
* whole
: 0;
8870 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8871 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8872 the bottom, so we force the scrolling whenever we see that we're
8873 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8874 we try to ensure that we always stay two pixels away from the
8876 part
= scroll_bar_down_arrow
;
8878 part
= scroll_bar_handle
;
8880 window_being_scrolled
= bar
->window
;
8881 bar
->dragging
= make_number (portion
);
8882 last_scroll_bar_part
= part
;
8883 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8887 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8888 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8889 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8890 the scroll bar. CALL_DATA is an integer specifying the action that
8891 has taken place. Its magnitude is in the range 0..height of the
8892 scroll bar. Negative values mean scroll towards buffer start.
8893 Values < height of scroll bar mean line-wise movement. */
8896 xaw_scroll_callback (widget
, client_data
, call_data
)
8898 XtPointer client_data
, call_data
;
8900 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8901 /* The position really is stored cast to a pointer. */
8902 int position
= (long) call_data
;
8906 /* Get the height of the scroll bar. */
8908 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8911 if (abs (position
) >= height
)
8912 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8914 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8915 it maps line-movement to call_data = max(5, height/20). */
8916 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8917 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8919 part
= scroll_bar_move_ratio
;
8921 window_being_scrolled
= bar
->window
;
8922 bar
->dragging
= Qnil
;
8923 last_scroll_bar_part
= part
;
8924 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8927 #endif /* not USE_GTK */
8928 #endif /* not USE_MOTIF */
8930 #define SCROLL_BAR_NAME "verticalScrollBar"
8932 /* Create the widget for scroll bar BAR on frame F. Record the widget
8933 and X window of the scroll bar in BAR. */
8937 x_create_toolkit_scroll_bar (f
, bar
)
8939 struct scroll_bar
*bar
;
8941 char *scroll_bar_name
= SCROLL_BAR_NAME
;
8944 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
8949 #else /* not USE_GTK */
8952 x_create_toolkit_scroll_bar (f
, bar
)
8954 struct scroll_bar
*bar
;
8960 char *scroll_bar_name
= SCROLL_BAR_NAME
;
8961 unsigned long pixel
;
8966 /* Set resources. Create the widget. */
8967 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8968 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8969 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8970 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8971 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8972 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8973 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8975 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8978 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8982 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8985 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8989 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8990 scroll_bar_name
, av
, ac
);
8992 /* Add one callback for everything that can happen. */
8993 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8995 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8997 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8999 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
9001 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
9003 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
9005 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
9008 /* Realize the widget. Only after that is the X window created. */
9009 XtRealizeWidget (widget
);
9011 /* Set the cursor to an arrow. I didn't find a resource to do that.
9012 And I'm wondering why it hasn't an arrow cursor by default. */
9013 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
9014 f
->output_data
.x
->nontext_cursor
);
9016 #else /* !USE_MOTIF i.e. use Xaw */
9018 /* Set resources. Create the widget. The background of the
9019 Xaw3d scroll bar widget is a little bit light for my taste.
9020 We don't alter it here to let users change it according
9021 to their taste with `emacs*verticalScrollBar.background: xxx'. */
9022 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
9023 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
9024 /* For smoother scrolling with Xaw3d -sm */
9025 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
9027 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
9030 XtSetArg (av
[ac
], XtNforeground
, pixel
);
9034 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
9037 XtSetArg (av
[ac
], XtNbackground
, pixel
);
9041 /* Top/bottom shadow colors. */
9043 /* Allocate them, if necessary. */
9044 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
9046 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
9047 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
9048 &pixel
, 1.2, 0x8000))
9050 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
9052 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
9054 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
9055 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
9056 &pixel
, 0.6, 0x4000))
9058 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
9061 /* Tell the toolkit about them. */
9062 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
9063 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
9064 /* We tried to allocate a color for the top/bottom shadow, and
9065 failed, so tell Xaw3d to use dithering instead. */
9067 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
9071 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
9072 be more consistent with other emacs 3d colors, and since Xaw3d is
9073 not good at dealing with allocation failure. */
9075 /* This tells Xaw3d to use real colors instead of dithering for
9077 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
9080 /* Specify the colors. */
9081 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
9084 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
9087 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
9090 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
9095 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
9096 f
->output_data
.x
->edit_widget
, av
, ac
);
9100 char *val
= initial
;
9101 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
9102 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
9104 { /* ARROW_SCROLL */
9105 xaw3d_arrow_scroll
= True
;
9106 /* Isn't that just a personal preference ? -sm */
9107 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
9111 /* Define callbacks. */
9112 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
9113 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
9116 /* Realize the widget. Only after that is the X window created. */
9117 XtRealizeWidget (widget
);
9119 #endif /* !USE_MOTIF */
9121 /* Install an action hook that lets us detect when the user
9122 finishes interacting with a scroll bar. */
9123 if (action_hook_id
== 0)
9124 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
9126 /* Remember X window and widget in the scroll bar vector. */
9127 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
9128 xwindow
= XtWindow (widget
);
9129 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
9133 #endif /* not USE_GTK */
9136 /* Set the thumb size and position of scroll bar BAR. We are currently
9137 displaying PORTION out of a whole WHOLE, and our position POSITION. */
9141 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
9142 struct scroll_bar
*bar
;
9143 int portion
, position
, whole
;
9145 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9148 #else /* not USE_GTK */
9150 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
9151 struct scroll_bar
*bar
;
9152 int portion
, position
, whole
;
9154 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9155 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
9162 /* We use an estimate of 30 chars per line rather than the real
9163 `portion' value. This has the disadvantage that the thumb size
9164 is not very representative, but it makes our life a lot easier.
9165 Otherwise, we have to constantly adjust the thumb size, which
9166 we can't always do quickly enough: while dragging, the size of
9167 the thumb might prevent the user from dragging the thumb all the
9168 way to the end. but Motif and some versions of Xaw3d don't allow
9169 updating the thumb size while dragging. Also, even if we can update
9170 its size, the update will often happen too late.
9171 If you don't believe it, check out revision 1.650 of xterm.c to see
9172 what hoops we were going through and the still poor behavior we got. */
9173 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
9174 /* When the thumb is at the bottom, position == whole.
9175 So we need to increase `whole' to make space for the thumb. */
9182 top
= (float) position
/ whole
;
9183 shown
= (float) portion
/ whole
;
9186 if (NILP (bar
->dragging
))
9190 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
9191 is the scroll bar's maximum and MIN is the scroll bar's minimum
9193 size
= shown
* XM_SB_RANGE
;
9194 size
= min (size
, XM_SB_RANGE
);
9195 size
= max (size
, 1);
9197 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
9198 value
= top
* XM_SB_RANGE
;
9199 value
= min (value
, XM_SB_MAX
- size
);
9200 value
= max (value
, XM_SB_MIN
);
9202 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
9204 #else /* !USE_MOTIF i.e. use Xaw */
9210 top
= (float) position
/ whole
;
9211 shown
= (float) portion
/ whole
;
9215 float old_top
, old_shown
;
9217 XtVaGetValues (widget
,
9218 XtNtopOfThumb
, &old_top
,
9219 XtNshown
, &old_shown
,
9223 /* Massage the top+shown values. */
9224 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
9225 top
= max (0, min (1, top
));
9228 /* Keep two pixels available for moving the thumb down. */
9229 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
9231 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
9232 check that your system's configuration file contains a define
9233 for `NARROWPROTO'. See s/freebsd.h for an example. */
9234 if (top
!= old_top
|| shown
!= old_shown
)
9236 if (NILP (bar
->dragging
))
9237 XawScrollbarSetThumb (widget
, top
, shown
);
9241 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
9242 int scroll_mode
= 0;
9244 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
9245 if (xaw3d_arrow_scroll
)
9247 /* Xaw3d stupidly ignores resize requests while dragging
9248 so we have to make it believe it's not in dragging mode. */
9249 scroll_mode
= sb
->scrollbar
.scroll_mode
;
9250 if (scroll_mode
== 2)
9251 sb
->scrollbar
.scroll_mode
= 0;
9254 /* Try to make the scrolling a tad smoother. */
9255 if (!xaw3d_pick_top
)
9256 shown
= min (shown
, old_shown
);
9258 XawScrollbarSetThumb (widget
, top
, shown
);
9261 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
9262 sb
->scrollbar
.scroll_mode
= scroll_mode
;
9267 #endif /* !USE_MOTIF */
9271 #endif /* not USE_GTK */
9273 #endif /* USE_TOOLKIT_SCROLL_BARS */
9277 /************************************************************************
9278 Scroll bars, general
9279 ************************************************************************/
9281 /* Create a scroll bar and return the scroll bar vector for it. W is
9282 the Emacs window on which to create the scroll bar. TOP, LEFT,
9283 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
9286 static struct scroll_bar
*
9287 x_scroll_bar_create (w
, top
, left
, width
, height
)
9289 int top
, left
, width
, height
;
9291 struct frame
*f
= XFRAME (w
->frame
);
9292 struct scroll_bar
*bar
9293 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
9297 #ifdef USE_TOOLKIT_SCROLL_BARS
9298 x_create_toolkit_scroll_bar (f
, bar
);
9299 #else /* not USE_TOOLKIT_SCROLL_BARS */
9301 XSetWindowAttributes a
;
9305 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
9306 if (a
.background_pixel
== -1)
9307 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
9309 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
9310 | ButtonMotionMask
| PointerMotionHintMask
9312 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
9314 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
9316 /* Clear the area of W that will serve as a scroll bar. This is
9317 for the case that a window has been split horizontally. In
9318 this case, no clear_frame is generated to reduce flickering. */
9319 if (width
> 0 && height
> 0)
9320 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9322 window_box_height (w
), False
);
9324 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9325 /* Position and size of scroll bar. */
9326 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9328 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9330 /* Border width, depth, class, and visual. */
9337 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
9339 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9341 XSETWINDOW (bar
->window
, w
);
9342 XSETINT (bar
->top
, top
);
9343 XSETINT (bar
->left
, left
);
9344 XSETINT (bar
->width
, width
);
9345 XSETINT (bar
->height
, height
);
9346 XSETINT (bar
->start
, 0);
9347 XSETINT (bar
->end
, 0);
9348 bar
->dragging
= Qnil
;
9350 /* Add bar to its frame's list of scroll bars. */
9351 bar
->next
= FRAME_SCROLL_BARS (f
);
9353 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9354 if (!NILP (bar
->next
))
9355 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9357 /* Map the window/widget. */
9358 #ifdef USE_TOOLKIT_SCROLL_BARS
9361 xg_update_scrollbar_pos (f
,
9362 SCROLL_BAR_X_WINDOW (bar
),
9364 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9365 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9367 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
9368 #else /* not USE_GTK */
9369 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
9370 XtConfigureWidget (scroll_bar
,
9371 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9373 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9374 max (height
, 1), 0);
9375 XtMapWidget (scroll_bar
);
9376 #endif /* not USE_GTK */
9378 #else /* not USE_TOOLKIT_SCROLL_BARS */
9379 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9380 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9387 /* Draw BAR's handle in the proper position.
9389 If the handle is already drawn from START to END, don't bother
9390 redrawing it, unless REBUILD is non-zero; in that case, always
9391 redraw it. (REBUILD is handy for drawing the handle after expose
9394 Normally, we want to constrain the start and end of the handle to
9395 fit inside its rectangle, but if the user is dragging the scroll
9396 bar handle, we want to let them drag it down all the way, so that
9397 the bar's top is as far down as it goes; otherwise, there's no way
9398 to move to the very end of the buffer. */
9400 #ifndef USE_TOOLKIT_SCROLL_BARS
9403 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
9404 struct scroll_bar
*bar
;
9408 int dragging
= ! NILP (bar
->dragging
);
9409 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9410 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9411 GC gc
= f
->output_data
.x
->normal_gc
;
9413 /* If the display is already accurate, do nothing. */
9415 && start
== XINT (bar
->start
)
9416 && end
== XINT (bar
->end
))
9422 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
9423 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9424 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9426 /* Make sure the values are reasonable, and try to preserve
9427 the distance between start and end. */
9429 int length
= end
- start
;
9433 else if (start
> top_range
)
9435 end
= start
+ length
;
9439 else if (end
> top_range
&& ! dragging
)
9443 /* Store the adjusted setting in the scroll bar. */
9444 XSETINT (bar
->start
, start
);
9445 XSETINT (bar
->end
, end
);
9447 /* Clip the end position, just for display. */
9448 if (end
> top_range
)
9451 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
9452 below top positions, to make sure the handle is always at least
9453 that many pixels tall. */
9454 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
9456 /* Draw the empty space above the handle. Note that we can't clear
9457 zero-height areas; that means "clear to end of window." */
9459 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9460 /* x, y, width, height, and exposures. */
9461 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9462 VERTICAL_SCROLL_BAR_TOP_BORDER
,
9463 inside_width
, start
,
9466 /* Change to proper foreground color if one is specified. */
9467 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9468 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9469 f
->output_data
.x
->scroll_bar_foreground_pixel
);
9471 /* Draw the handle itself. */
9472 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9473 /* x, y, width, height */
9474 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9475 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
9476 inside_width
, end
- start
);
9478 /* Restore the foreground color of the GC if we changed it above. */
9479 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9480 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9481 f
->output_data
.x
->foreground_pixel
);
9483 /* Draw the empty space below the handle. Note that we can't
9484 clear zero-height areas; that means "clear to end of window." */
9485 if (end
< inside_height
)
9486 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9487 /* x, y, width, height, and exposures. */
9488 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9489 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
9490 inside_width
, inside_height
- end
,
9498 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9500 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
9504 x_scroll_bar_remove (bar
)
9505 struct scroll_bar
*bar
;
9507 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9510 #ifdef USE_TOOLKIT_SCROLL_BARS
9512 xg_remove_scroll_bar (f
, SCROLL_BAR_X_WINDOW (bar
));
9513 #else /* not USE_GTK */
9514 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
9515 #endif /* not USE_GTK */
9517 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9520 /* Disassociate this scroll bar from its window. */
9521 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
9527 /* Set the handle of the vertical scroll bar for WINDOW to indicate
9528 that we are displaying PORTION characters out of a total of WHOLE
9529 characters, starting at POSITION. If WINDOW has no scroll bar,
9533 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
9535 int portion
, whole
, position
;
9537 struct frame
*f
= XFRAME (w
->frame
);
9538 struct scroll_bar
*bar
;
9539 int top
, height
, left
, sb_left
, width
, sb_width
;
9540 int window_x
, window_y
, window_width
, window_height
;
9542 /* Get window dimensions. */
9543 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9545 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9546 height
= window_height
;
9548 /* Compute the left edge of the scroll bar area. */
9549 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9550 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
9552 left
= XFASTINT (w
->left
);
9553 left
*= CANON_X_UNIT (f
);
9554 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
9556 /* Compute the width of the scroll bar which might be less than
9557 the width of the area reserved for the scroll bar. */
9558 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
9559 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
9563 /* Compute the left edge of the scroll bar. */
9564 #ifdef USE_TOOLKIT_SCROLL_BARS
9565 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9566 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
9568 sb_left
= left
+ (width
- sb_width
) / 2;
9570 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9571 sb_left
= left
+ width
- sb_width
;
9576 /* Does the scroll bar exist yet? */
9577 if (NILP (w
->vertical_scroll_bar
))
9579 if (width
> 0 && height
> 0)
9582 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9583 left
, top
, width
, height
, False
);
9587 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9591 /* It may just need to be moved and resized. */
9592 unsigned int mask
= 0;
9594 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9598 if (sb_left
!= XINT (bar
->left
))
9600 if (top
!= XINT (bar
->top
))
9602 if (sb_width
!= XINT (bar
->width
))
9604 if (height
!= XINT (bar
->height
))
9607 #ifdef USE_TOOLKIT_SCROLL_BARS
9611 xg_update_scrollbar_pos (f
,
9612 SCROLL_BAR_X_WINDOW (bar
),
9614 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9615 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9617 #else /* not USE_GTK */
9619 /* Since toolkit scroll bars are smaller than the space reserved
9620 for them on the frame, we have to clear "under" them. */
9621 if (width
> 0 && height
> 0)
9622 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9623 left
, top
, width
, height
, False
);
9624 /* Move/size the scroll bar widget. */
9626 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9627 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9629 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9630 max (height
, 1), 0);
9632 #endif /* not USE_GTK */
9633 #else /* not USE_TOOLKIT_SCROLL_BARS */
9635 /* Clear areas not covered by the scroll bar because of
9636 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9637 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9639 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9640 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9642 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9643 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9644 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9648 /* Clear areas not covered by the scroll bar because it's not as
9649 wide as the area reserved for it. This makes sure a
9650 previous mode line display is cleared after C-x 2 C-x 1, for
9653 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9654 int rest
= area_width
- sb_width
;
9655 if (rest
> 0 && height
> 0)
9657 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
9658 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9659 left
+ area_width
- rest
, top
,
9660 rest
, height
, False
);
9662 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9663 left
, top
, rest
, height
, False
);
9667 /* Move/size the scroll bar window. */
9672 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9674 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9676 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9680 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9682 /* Remember new settings. */
9683 XSETINT (bar
->left
, sb_left
);
9684 XSETINT (bar
->top
, top
);
9685 XSETINT (bar
->width
, sb_width
);
9686 XSETINT (bar
->height
, height
);
9691 #ifdef USE_TOOLKIT_SCROLL_BARS
9692 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9693 #else /* not USE_TOOLKIT_SCROLL_BARS */
9694 /* Set the scroll bar's current state, unless we're currently being
9696 if (NILP (bar
->dragging
))
9698 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9701 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9704 int start
= ((double) position
* top_range
) / whole
;
9705 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9706 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9709 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9711 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9715 /* The following three hooks are used when we're doing a thorough
9716 redisplay of the frame. We don't explicitly know which scroll bars
9717 are going to be deleted, because keeping track of when windows go
9718 away is a real pain - "Can you say set-window-configuration, boys
9719 and girls?" Instead, we just assert at the beginning of redisplay
9720 that *all* scroll bars are to be removed, and then save a scroll bar
9721 from the fiery pit when we actually redisplay its window. */
9723 /* Arrange for all scroll bars on FRAME to be removed at the next call
9724 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9725 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9728 XTcondemn_scroll_bars (frame
)
9731 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9732 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9735 bar
= FRAME_SCROLL_BARS (frame
);
9736 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9737 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9738 XSCROLL_BAR (bar
)->prev
= Qnil
;
9739 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9740 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9741 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9746 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9747 Note that WINDOW isn't necessarily condemned at all. */
9750 XTredeem_scroll_bar (window
)
9751 struct window
*window
;
9753 struct scroll_bar
*bar
;
9756 /* We can't redeem this window's scroll bar if it doesn't have one. */
9757 if (NILP (window
->vertical_scroll_bar
))
9760 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9762 /* Unlink it from the condemned list. */
9763 f
= XFRAME (WINDOW_FRAME (window
));
9764 if (NILP (bar
->prev
))
9766 /* If the prev pointer is nil, it must be the first in one of
9768 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9769 /* It's not condemned. Everything's fine. */
9771 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9772 window
->vertical_scroll_bar
))
9773 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9775 /* If its prev pointer is nil, it must be at the front of
9776 one or the other! */
9780 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9782 if (! NILP (bar
->next
))
9783 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9785 bar
->next
= FRAME_SCROLL_BARS (f
);
9787 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9788 if (! NILP (bar
->next
))
9789 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9792 /* Remove all scroll bars on FRAME that haven't been saved since the
9793 last call to `*condemn_scroll_bars_hook'. */
9796 XTjudge_scroll_bars (f
)
9799 Lisp_Object bar
, next
;
9801 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9803 /* Clear out the condemned list now so we won't try to process any
9804 more events on the hapless scroll bars. */
9805 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9807 for (; ! NILP (bar
); bar
= next
)
9809 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9811 x_scroll_bar_remove (b
);
9814 b
->next
= b
->prev
= Qnil
;
9817 /* Now there should be no references to the condemned scroll bars,
9818 and they should get garbage-collected. */
9822 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9823 is a no-op when using toolkit scroll bars.
9825 This may be called from a signal handler, so we have to ignore GC
9829 x_scroll_bar_expose (bar
, event
)
9830 struct scroll_bar
*bar
;
9833 #ifndef USE_TOOLKIT_SCROLL_BARS
9835 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9836 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9837 GC gc
= f
->output_data
.x
->normal_gc
;
9838 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9842 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9844 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9845 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9847 /* x, y, width, height */
9849 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9850 XINT (bar
->height
) - 1);
9854 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9857 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9858 is set to something other than NO_EVENT, it is enqueued.
9860 This may be called from a signal handler, so we have to ignore GC
9863 #ifndef USE_TOOLKIT_SCROLL_BARS
9866 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9867 struct scroll_bar
*bar
;
9869 struct input_event
*emacs_event
;
9871 if (! GC_WINDOWP (bar
->window
))
9874 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
9875 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9876 emacs_event
->modifiers
9877 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9878 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9879 event
->xbutton
.state
)
9880 | (event
->type
== ButtonRelease
9883 emacs_event
->frame_or_window
= bar
->window
;
9884 emacs_event
->arg
= Qnil
;
9885 emacs_event
->timestamp
= event
->xbutton
.time
;
9888 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9890 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9893 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9894 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9897 if (y
> top_range
) y
= top_range
;
9899 if (y
< XINT (bar
->start
))
9900 emacs_event
->part
= scroll_bar_above_handle
;
9901 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9902 emacs_event
->part
= scroll_bar_handle
;
9904 emacs_event
->part
= scroll_bar_below_handle
;
9906 /* Just because the user has clicked on the handle doesn't mean
9907 they want to drag it. Lisp code needs to be able to decide
9908 whether or not we're dragging. */
9910 /* If the user has just clicked on the handle, record where they're
9912 if (event
->type
== ButtonPress
9913 && emacs_event
->part
== scroll_bar_handle
)
9914 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9917 /* If the user has released the handle, set it to its final position. */
9918 if (event
->type
== ButtonRelease
9919 && ! NILP (bar
->dragging
))
9921 int new_start
= y
- XINT (bar
->dragging
);
9922 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9924 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9925 bar
->dragging
= Qnil
;
9928 /* Same deal here as the other #if 0. */
9930 /* Clicks on the handle are always reported as occurring at the top of
9932 if (emacs_event
->part
== scroll_bar_handle
)
9933 emacs_event
->x
= bar
->start
;
9935 XSETINT (emacs_event
->x
, y
);
9937 XSETINT (emacs_event
->x
, y
);
9940 XSETINT (emacs_event
->y
, top_range
);
9944 /* Handle some mouse motion while someone is dragging the scroll bar.
9946 This may be called from a signal handler, so we have to ignore GC
9950 x_scroll_bar_note_movement (bar
, event
)
9951 struct scroll_bar
*bar
;
9954 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9956 last_mouse_movement_time
= event
->xmotion
.time
;
9959 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9961 /* If we're dragging the bar, display it. */
9962 if (! GC_NILP (bar
->dragging
))
9964 /* Where should the handle be now? */
9965 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9967 if (new_start
!= XINT (bar
->start
))
9969 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9971 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9976 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9978 /* Return information to the user about the current position of the mouse
9979 on the scroll bar. */
9982 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9984 Lisp_Object
*bar_window
;
9985 enum scroll_bar_part
*part
;
9987 unsigned long *time
;
9989 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9990 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9991 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9993 Window dummy_window
;
9995 unsigned int dummy_mask
;
9999 /* Get the mouse's position relative to the scroll bar window, and
10001 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
10003 /* Root, child, root x and root y. */
10004 &dummy_window
, &dummy_window
,
10005 &dummy_coord
, &dummy_coord
,
10007 /* Position relative to scroll bar. */
10010 /* Mouse buttons and modifier keys. */
10017 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
10020 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
10022 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
10024 if (! NILP (bar
->dragging
))
10025 win_y
-= XINT (bar
->dragging
);
10029 if (win_y
> top_range
)
10033 *bar_window
= bar
->window
;
10035 if (! NILP (bar
->dragging
))
10036 *part
= scroll_bar_handle
;
10037 else if (win_y
< XINT (bar
->start
))
10038 *part
= scroll_bar_above_handle
;
10039 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
10040 *part
= scroll_bar_handle
;
10042 *part
= scroll_bar_below_handle
;
10044 XSETINT (*x
, win_y
);
10045 XSETINT (*y
, top_range
);
10047 f
->mouse_moved
= 0;
10048 last_mouse_scroll_bar
= Qnil
;
10051 *time
= last_mouse_movement_time
;
10057 /* The screen has been cleared so we may have changed foreground or
10058 background colors, and the scroll bars may need to be redrawn.
10059 Clear out the scroll bars, and ask for expose events, so we can
10063 x_scroll_bar_clear (f
)
10066 #ifndef USE_TOOLKIT_SCROLL_BARS
10069 /* We can have scroll bars even if this is 0,
10070 if we just turned off scroll bar mode.
10071 But in that case we should not clear them. */
10072 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
10073 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
10074 bar
= XSCROLL_BAR (bar
)->next
)
10075 XClearArea (FRAME_X_DISPLAY (f
),
10076 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
10078 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10082 /* Define a queue to save up SelectionRequest events for later handling. */
10084 struct selection_event_queue
10087 struct selection_event_queue
*next
;
10090 static struct selection_event_queue
*queue
;
10092 /* Nonzero means queue up certain events--don't process them yet. */
10094 static int x_queue_selection_requests
;
10096 /* Queue up an X event *EVENT, to be processed later. */
10099 x_queue_event (f
, event
)
10103 struct selection_event_queue
*queue_tmp
10104 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
10106 if (queue_tmp
!= NULL
)
10108 queue_tmp
->event
= *event
;
10109 queue_tmp
->next
= queue
;
10114 /* Take all the queued events and put them back
10115 so that they get processed afresh. */
10118 x_unqueue_events (display
)
10121 while (queue
!= NULL
)
10123 struct selection_event_queue
*queue_tmp
= queue
;
10124 XPutBackEvent (display
, &queue_tmp
->event
);
10125 queue
= queue_tmp
->next
;
10126 xfree ((char *)queue_tmp
);
10130 /* Start queuing SelectionRequest events. */
10133 x_start_queuing_selection_requests (display
)
10136 x_queue_selection_requests
++;
10139 /* Stop queuing SelectionRequest events. */
10142 x_stop_queuing_selection_requests (display
)
10145 x_queue_selection_requests
--;
10146 x_unqueue_events (display
);
10149 /* The main X event-reading loop - XTread_socket. */
10152 /* Time stamp of enter window event. This is only used by XTread_socket,
10153 but we have to put it out here, since static variables within functions
10154 sometimes don't work. */
10156 static Time enter_timestamp
;
10159 /* This holds the state XLookupString needs to implement dead keys
10160 and other tricks known as "compose processing". _X Window System_
10161 says that a portable program can't use this, but Stephen Gildea assures
10162 me that letting the compiler initialize it to zeros will work okay.
10164 This must be defined outside of XTread_socket, for the same reasons
10165 given for enter_timestamp, above. */
10167 static XComposeStatus compose_status
;
10169 /* Record the last 100 characters stored
10170 to help debug the loss-of-chars-during-GC problem. */
10172 static int temp_index
;
10173 static short temp_buffer
[100];
10175 /* Set this to nonzero to fake an "X I/O error"
10176 on a particular display. */
10178 struct x_display_info
*XTread_socket_fake_io_error
;
10180 /* When we find no input here, we occasionally do a no-op command
10181 to verify that the X server is still running and we can still talk with it.
10182 We try all the open displays, one by one.
10183 This variable is used for cycling thru the displays. */
10185 static struct x_display_info
*next_noop_dpyinfo
;
10187 #define SET_SAVED_MENU_EVENT(size) \
10190 if (f->output_data.x->saved_menu_event == 0) \
10191 f->output_data.x->saved_menu_event \
10192 = (XEvent *) xmalloc (sizeof (XEvent)); \
10193 bcopy (&event, f->output_data.x->saved_menu_event, size); \
10194 if (numchars >= 1) \
10196 bufp->kind = MENU_BAR_ACTIVATE_EVENT; \
10197 XSETFRAME (bufp->frame_or_window, f); \
10198 bufp->arg = Qnil; \
10206 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
10207 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
10218 static struct x_display_info
*current_dpyinfo
;
10219 static struct input_event
**current_bufp
;
10220 static int *current_numcharsp
;
10221 static int current_count
;
10222 static int current_finish
;
10224 /* This is the filter function invoked by the GTK event loop.
10225 It is invoked before the XEvent is translated to a GdkEvent,
10226 so we have a chanse to act on the event before GTK. */
10227 static GdkFilterReturn
10228 event_handler_gdk (gxev
, ev
, data
)
10233 XEvent
*xev
= (XEvent
*)gxev
;
10235 if (current_numcharsp
)
10236 current_count
+= handle_one_xevent (current_dpyinfo
,
10242 x_dispatch_event (xev
, GDK_DISPLAY ());
10244 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
10245 return GDK_FILTER_REMOVE
;
10247 return GDK_FILTER_CONTINUE
;
10249 #endif /* USE_GTK */
10252 /* Handles the XEvent EVENT on display DPYINFO.
10254 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
10255 *FINISH is zero if caller should continue reading events.
10256 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
10258 Events representing keys are stored in buffer *BUFP_R,
10259 which can hold up to *NUMCHARSP characters.
10260 We return the number of characters stored into the buffer. */
10263 handle_one_xevent (dpyinfo
, eventp
, bufp_r
, numcharsp
, finish
)
10264 struct x_display_info
*dpyinfo
;
10266 /* register */ struct input_event
**bufp_r
;
10267 /* register */ int *numcharsp
;
10273 struct coding_system coding
;
10274 struct input_event
*bufp
= *bufp_r
;
10275 int numchars
= *numcharsp
;
10276 XEvent event
= *eventp
;
10278 *finish
= X_EVENT_NORMAL
;
10280 switch (event
.type
)
10282 case ClientMessage
:
10284 if (event
.xclient
.message_type
10285 == dpyinfo
->Xatom_wm_protocols
10286 && event
.xclient
.format
== 32)
10288 if (event
.xclient
.data
.l
[0]
10289 == dpyinfo
->Xatom_wm_take_focus
)
10291 /* Use x_any_window_to_frame because this
10292 could be the shell widget window
10293 if the frame has no title bar. */
10294 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10296 /* Not quite sure this is needed -pd */
10297 if (f
&& FRAME_XIC (f
))
10298 XSetICFocus (FRAME_XIC (f
));
10300 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
10301 instructs the WM to set the input focus automatically for
10302 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
10303 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
10304 it has set the focus. So, XSetInputFocus below is not
10307 The call to XSetInputFocus below has also caused trouble. In
10308 cases where the XSetInputFocus done by the WM and the one
10309 below are temporally close (on a fast machine), the call
10310 below can generate additional FocusIn events which confuse
10313 /* Since we set WM_TAKE_FOCUS, we must call
10314 XSetInputFocus explicitly. But not if f is null,
10315 since that might be an event for a deleted frame. */
10318 Display
*d
= event
.xclient
.display
;
10319 /* Catch and ignore errors, in case window has been
10320 iconified by a window manager such as GWM. */
10321 int count
= x_catch_errors (d
);
10322 XSetInputFocus (d
, event
.xclient
.window
,
10323 /* The ICCCM says this is
10324 the only valid choice. */
10326 event
.xclient
.data
.l
[1]);
10327 /* This is needed to detect the error
10328 if there is an error. */
10330 x_uncatch_errors (d
, count
);
10332 /* Not certain about handling scroll bars here */
10335 else if (event
.xclient
.data
.l
[0]
10336 == dpyinfo
->Xatom_wm_save_yourself
)
10338 /* Save state modify the WM_COMMAND property to
10339 something which can reinstate us. This notifies
10340 the session manager, who's looking for such a
10341 PropertyNotify. Can restart processing when
10342 a keyboard or mouse event arrives. */
10343 /* If we have a session manager, don't set this.
10344 KDE will then start two Emacsen, one for the
10345 session manager and one for this. */
10348 && ! x_session_have_connection ()
10352 f
= x_top_window_to_frame (dpyinfo
,
10353 event
.xclient
.window
);
10354 /* This is just so we only give real data once
10355 for a single Emacs process. */
10356 if (f
== SELECTED_FRAME ())
10357 XSetCommand (FRAME_X_DISPLAY (f
),
10358 event
.xclient
.window
,
10359 initial_argv
, initial_argc
);
10361 XSetCommand (FRAME_X_DISPLAY (f
),
10362 event
.xclient
.window
,
10366 else if (event
.xclient
.data
.l
[0]
10367 == dpyinfo
->Xatom_wm_delete_window
)
10370 = x_any_window_to_frame (dpyinfo
,
10371 event
.xclient
.window
);
10378 bufp
->kind
= DELETE_WINDOW_EVENT
;
10379 XSETFRAME (bufp
->frame_or_window
, f
);
10387 goto OTHER
; /* May be a dialog that is to be removed */
10390 else if (event
.xclient
.message_type
10391 == dpyinfo
->Xatom_wm_configure_denied
)
10394 else if (event
.xclient
.message_type
10395 == dpyinfo
->Xatom_wm_window_moved
)
10399 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10401 new_x
= event
.xclient
.data
.s
[0];
10402 new_y
= event
.xclient
.data
.s
[1];
10406 f
->output_data
.x
->left_pos
= new_x
;
10407 f
->output_data
.x
->top_pos
= new_y
;
10410 #ifdef HACK_EDITRES
10411 else if (event
.xclient
.message_type
10412 == dpyinfo
->Xatom_editres
)
10415 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10416 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
10419 #endif /* HACK_EDITRES */
10420 else if ((event
.xclient
.message_type
10421 == dpyinfo
->Xatom_DONE
)
10422 || (event
.xclient
.message_type
10423 == dpyinfo
->Xatom_PAGE
))
10425 /* Ghostview job completed. Kill it. We could
10426 reply with "Next" if we received "Page", but we
10427 currently never do because we are interested in
10428 images, only, which should have 1 page. */
10429 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
10431 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10432 x_kill_gs_process (pixmap
, f
);
10433 expose_frame (f
, 0, 0, 0, 0);
10435 #ifdef USE_TOOLKIT_SCROLL_BARS
10436 /* Scroll bar callbacks send a ClientMessage from which
10437 we construct an input_event. */
10438 else if (event
.xclient
.message_type
10439 == dpyinfo
->Xatom_Scrollbar
)
10441 x_scroll_bar_to_input_event (&event
, bufp
);
10442 ++bufp
, ++count
, --numchars
;
10445 #endif /* USE_TOOLKIT_SCROLL_BARS */
10451 case SelectionNotify
:
10452 #ifdef USE_X_TOOLKIT
10453 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
10455 #endif /* not USE_X_TOOLKIT */
10456 x_handle_selection_notify (&event
.xselection
);
10459 case SelectionClear
: /* Someone has grabbed ownership. */
10460 #ifdef USE_X_TOOLKIT
10461 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
10463 #endif /* USE_X_TOOLKIT */
10465 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
10470 bufp
->kind
= SELECTION_CLEAR_EVENT
;
10471 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10472 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10473 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10474 bufp
->frame_or_window
= Qnil
;
10483 case SelectionRequest
: /* Someone wants our selection. */
10484 #ifdef USE_X_TOOLKIT
10485 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
10487 #endif /* USE_X_TOOLKIT */
10488 if (x_queue_selection_requests
)
10489 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
10493 XSelectionRequestEvent
*eventp
10494 = (XSelectionRequestEvent
*) &event
;
10499 bufp
->kind
= SELECTION_REQUEST_EVENT
;
10500 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10501 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
10502 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10503 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
10504 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
10505 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10506 bufp
->frame_or_window
= Qnil
;
10515 case PropertyNotify
:
10516 #if 0 /* This is plain wrong. In the case that we are waiting for a
10517 PropertyNotify used as an ACK in incremental selection
10518 transfer, the property will be on the receiver's window. */
10519 #if defined USE_X_TOOLKIT
10520 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10524 x_handle_property_notify (&event
.xproperty
);
10527 case ReparentNotify
:
10528 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10532 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10533 x_real_positions (f
, &x
, &y
);
10534 f
->output_data
.x
->left_pos
= x
;
10535 f
->output_data
.x
->top_pos
= y
;
10541 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10544 x_check_fullscreen (f
);
10546 if (f
->async_visible
== 0)
10548 f
->async_visible
= 1;
10549 f
->async_iconified
= 0;
10550 f
->output_data
.x
->has_been_visible
= 1;
10551 SET_FRAME_GARBAGED (f
);
10554 expose_frame (x_window_to_frame (dpyinfo
,
10555 event
.xexpose
.window
),
10556 event
.xexpose
.x
, event
.xexpose
.y
,
10557 event
.xexpose
.width
, event
.xexpose
.height
);
10561 #ifndef USE_TOOLKIT_SCROLL_BARS
10562 struct scroll_bar
*bar
;
10564 #if defined USE_LUCID
10565 /* Submenus of the Lucid menu bar aren't widgets
10566 themselves, so there's no way to dispatch events
10567 to them. Recognize this case separately. */
10570 = x_window_to_menu_bar (event
.xexpose
.window
);
10572 xlwmenu_redisplay (widget
);
10574 #endif /* USE_LUCID */
10576 #ifdef USE_TOOLKIT_SCROLL_BARS
10577 /* Dispatch event to the widget. */
10579 #else /* not USE_TOOLKIT_SCROLL_BARS */
10580 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10583 x_scroll_bar_expose (bar
, &event
);
10584 #ifdef USE_X_TOOLKIT
10587 #endif /* USE_X_TOOLKIT */
10588 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10592 case GraphicsExpose
: /* This occurs when an XCopyArea's
10593 source area was obscured or not
10595 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10599 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10600 event
.xgraphicsexpose
.width
,
10601 event
.xgraphicsexpose
.height
);
10603 #ifdef USE_X_TOOLKIT
10606 #endif /* USE_X_TOOLKIT */
10609 case NoExpose
: /* This occurs when an XCopyArea's
10610 source area was completely
10615 /* Redo the mouse-highlight after the tooltip has gone. */
10616 if (event
.xmap
.window
== tip_window
)
10619 redo_mouse_highlight ();
10622 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10623 if (f
) /* F may no longer exist if
10624 the frame was deleted. */
10626 /* While a frame is unmapped, display generation is
10627 disabled; you don't want to spend time updating a
10628 display that won't ever be seen. */
10629 f
->async_visible
= 0;
10630 /* We can't distinguish, from the event, whether the window
10631 has become iconified or invisible. So assume, if it
10632 was previously visible, than now it is iconified.
10633 But x_make_frame_invisible clears both
10634 the visible flag and the iconified flag;
10635 and that way, we know the window is not iconified now. */
10636 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10638 f
->async_iconified
= 1;
10640 bufp
->kind
= ICONIFY_EVENT
;
10641 XSETFRAME (bufp
->frame_or_window
, f
);
10651 if (event
.xmap
.window
== tip_window
)
10652 /* The tooltip has been drawn already. Avoid
10653 the SET_FRAME_GARBAGED below. */
10656 /* We use x_top_window_to_frame because map events can
10657 come for sub-windows and they don't mean that the
10658 frame is visible. */
10659 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10662 /* wait_reading_process_input will notice this and update
10663 the frame's display structures.
10664 If we where iconified, we should not set garbaged,
10665 because that stops redrawing on Expose events. This looks
10666 bad if we are called from a recursive event loop
10667 (x_dispatch_event), for example when a dialog is up. */
10668 if (! f
->async_iconified
)
10669 SET_FRAME_GARBAGED (f
);
10671 f
->async_visible
= 1;
10672 f
->async_iconified
= 0;
10673 f
->output_data
.x
->has_been_visible
= 1;
10677 bufp
->kind
= DEICONIFY_EVENT
;
10678 XSETFRAME (bufp
->frame_or_window
, f
);
10684 else if (! NILP (Vframe_list
)
10685 && ! NILP (XCDR (Vframe_list
)))
10686 /* Force a redisplay sooner or later
10687 to update the frame titles
10688 in case this is the second frame. */
10689 record_asynch_buffer_change ();
10695 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10696 /* Dispatch KeyPress events when in menu. */
10697 if (popup_activated ())
10701 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10703 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
10705 dpyinfo
->mouse_face_hidden
= 1;
10706 clear_mouse_face (dpyinfo
);
10709 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10712 /* Scroll bars consume key events, but we want
10713 the keys to go to the scroll bar's frame. */
10714 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10715 event
.xkey
.window
);
10716 if (widget
&& XmIsScrollBar (widget
))
10718 widget
= XtParent (widget
);
10719 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10722 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10726 KeySym keysym
, orig_keysym
;
10727 /* al%imercury@uunet.uu.net says that making this 81
10728 instead of 80 fixed a bug whereby meta chars made
10731 It seems that some version of XmbLookupString has
10732 a bug of not returning XBufferOverflow in
10733 status_return even if the input is too long to
10734 fit in 81 bytes. So, we must prepare sufficient
10735 bytes for copy_buffer. 513 bytes (256 chars for
10736 two-byte character set) seems to be a fairly good
10737 approximation. -- 2000.8.10 handa@etl.go.jp */
10738 unsigned char copy_buffer
[513];
10739 unsigned char *copy_bufptr
= copy_buffer
;
10740 int copy_bufsiz
= sizeof (copy_buffer
);
10742 Lisp_Object coding_system
= Qlatin_1
;
10745 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10746 extra_keyboard_modifiers
);
10747 modifiers
= event
.xkey
.state
;
10749 /* This will have to go some day... */
10751 /* make_lispy_event turns chars into control chars.
10752 Don't do it here because XLookupString is too eager. */
10753 event
.xkey
.state
&= ~ControlMask
;
10754 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10755 | dpyinfo
->super_mod_mask
10756 | dpyinfo
->hyper_mod_mask
10757 | dpyinfo
->alt_mod_mask
);
10759 /* In case Meta is ComposeCharacter,
10760 clear its status. According to Markus Ehrnsperger
10761 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10762 this enables ComposeCharacter to work whether or
10763 not it is combined with Meta. */
10764 if (modifiers
& dpyinfo
->meta_mod_mask
)
10765 bzero (&compose_status
, sizeof (compose_status
));
10770 Status status_return
;
10772 coding_system
= Vlocale_coding_system
;
10773 nbytes
= XmbLookupString (FRAME_XIC (f
),
10774 &event
.xkey
, copy_bufptr
,
10775 copy_bufsiz
, &keysym
,
10777 if (status_return
== XBufferOverflow
)
10779 copy_bufsiz
= nbytes
+ 1;
10780 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10781 nbytes
= XmbLookupString (FRAME_XIC (f
),
10782 &event
.xkey
, copy_bufptr
,
10783 copy_bufsiz
, &keysym
,
10786 /* Xutf8LookupString is a new but already deprecated interface. -stef */
10787 #if 0 && defined X_HAVE_UTF8_STRING
10788 else if (status_return
== XLookupKeySym
)
10789 { /* Try again but with utf-8. */
10790 coding_system
= Qutf_8
;
10791 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
10792 &event
.xkey
, copy_bufptr
,
10793 copy_bufsiz
, &keysym
,
10795 if (status_return
== XBufferOverflow
)
10797 copy_bufsiz
= nbytes
+ 1;
10798 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10799 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
10802 copy_bufsiz
, &keysym
,
10808 if (status_return
== XLookupNone
)
10810 else if (status_return
== XLookupChars
)
10815 else if (status_return
!= XLookupKeySym
10816 && status_return
!= XLookupBoth
)
10820 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10821 copy_bufsiz
, &keysym
,
10824 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10825 copy_bufsiz
, &keysym
,
10829 orig_keysym
= keysym
;
10835 /* First deal with keysyms which have defined
10836 translations to characters. */
10837 if (keysym
>= 32 && keysym
< 128)
10838 /* Avoid explicitly decoding each ASCII character. */
10840 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
10841 bufp
->code
= keysym
;
10842 XSETFRAME (bufp
->frame_or_window
, f
);
10845 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10847 bufp
->timestamp
= event
.xkey
.time
;
10852 /* Now non-ASCII. */
10853 else if (HASH_TABLE_P (Vx_keysym_table
)
10854 && (NATNUMP (c
= Fgethash (make_number (keysym
),
10858 bufp
->kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
10859 ? ASCII_KEYSTROKE_EVENT
10860 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
10861 bufp
->code
= XFASTINT (c
);
10862 XSETFRAME (bufp
->frame_or_window
, f
);
10865 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10867 bufp
->timestamp
= event
.xkey
.time
;
10872 /* Random non-modifier sorts of keysyms. */
10873 else if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10874 || keysym
== XK_Delete
10875 #ifdef XK_ISO_Left_Tab
10876 || (keysym
>= XK_ISO_Left_Tab
10877 && keysym
<= XK_ISO_Enter
)
10879 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10880 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10882 /* This recognizes the "extended function
10883 keys". It seems there's no cleaner way.
10884 Test IsModifierKey to avoid handling
10885 mode_switch incorrectly. */
10886 || ((unsigned) (keysym
) >= XK_Select
10887 && (unsigned)(keysym
) < XK_KP_Space
)
10889 #ifdef XK_dead_circumflex
10890 || orig_keysym
== XK_dead_circumflex
10892 #ifdef XK_dead_grave
10893 || orig_keysym
== XK_dead_grave
10895 #ifdef XK_dead_tilde
10896 || orig_keysym
== XK_dead_tilde
10898 #ifdef XK_dead_diaeresis
10899 || orig_keysym
== XK_dead_diaeresis
10901 #ifdef XK_dead_macron
10902 || orig_keysym
== XK_dead_macron
10904 #ifdef XK_dead_degree
10905 || orig_keysym
== XK_dead_degree
10907 #ifdef XK_dead_acute
10908 || orig_keysym
== XK_dead_acute
10910 #ifdef XK_dead_cedilla
10911 || orig_keysym
== XK_dead_cedilla
10913 #ifdef XK_dead_breve
10914 || orig_keysym
== XK_dead_breve
10916 #ifdef XK_dead_ogonek
10917 || orig_keysym
== XK_dead_ogonek
10919 #ifdef XK_dead_caron
10920 || orig_keysym
== XK_dead_caron
10922 #ifdef XK_dead_doubleacute
10923 || orig_keysym
== XK_dead_doubleacute
10925 #ifdef XK_dead_abovedot
10926 || orig_keysym
== XK_dead_abovedot
10928 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10929 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10930 /* Any "vendor-specific" key is ok. */
10931 || (orig_keysym
& (1 << 28))
10932 || (keysym
!= NoSymbol
&& nbytes
== 0))
10933 && ! (IsModifierKey (orig_keysym
)
10935 #ifdef XK_Mode_switch
10936 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10939 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10941 #endif /* not HAVE_X11R5 */
10942 /* The symbols from XK_ISO_Lock
10943 to XK_ISO_Last_Group_Lock
10944 don't have real modifiers but
10945 should be treated similarly to
10946 Mode_switch by Emacs. */
10947 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
10948 || ((unsigned)(orig_keysym
)
10950 && (unsigned)(orig_keysym
)
10951 <= XK_ISO_Last_Group_Lock
)
10955 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10957 temp_buffer
[temp_index
++] = keysym
;
10958 /* make_lispy_event will convert this to a symbolic
10960 bufp
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
10961 bufp
->code
= keysym
;
10962 XSETFRAME (bufp
->frame_or_window
, f
);
10965 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10967 bufp
->timestamp
= event
.xkey
.time
;
10972 else if (numchars
> nbytes
)
10973 { /* Raw bytes, not keysym. */
10978 /* The input should be decoded with `coding_system'
10979 which depends on which X*LookupString function
10980 we used just above and the locale. */
10981 setup_coding_system (coding_system
, &coding
);
10982 coding
.src_multibyte
= 0;
10983 coding
.dst_multibyte
= 1;
10984 /* The input is converted to events, thus we can't
10985 handle composition. Anyway, there's no XIM that
10986 gives us composition information. */
10987 coding
.composing
= COMPOSITION_DISABLED
;
10989 for (i
= 0; i
< nbytes
; i
++)
10991 if (temp_index
== (sizeof temp_buffer
10994 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10998 /* Decode the input data. */
11002 require
= decoding_buffer_size (&coding
, nbytes
);
11003 p
= (unsigned char *) alloca (require
);
11004 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
11005 /* We explicitely disable composition
11006 handling because key data should
11007 not contain any composition
11009 coding
.composing
= COMPOSITION_DISABLED
;
11010 decode_coding (&coding
, copy_bufptr
, p
,
11012 nbytes
= coding
.produced
;
11013 nchars
= coding
.produced_char
;
11017 /* Convert the input data to a sequence of
11018 character events. */
11019 for (i
= 0; i
< nbytes
; i
+= len
)
11021 if (nchars
== nbytes
)
11022 c
= copy_bufptr
[i
], len
= 1;
11024 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
11027 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
11028 ? ASCII_KEYSTROKE_EVENT
11029 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
11031 XSETFRAME (bufp
->frame_or_window
, f
);
11034 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
11036 bufp
->timestamp
= event
.xkey
.time
;
11041 numchars
-= nchars
;
11043 if (keysym
== NoSymbol
)
11053 /* Don't dispatch this event since XtDispatchEvent calls
11054 XFilterEvent, and two calls in a row may freeze the
11063 /* Don't dispatch this event since XtDispatchEvent calls
11064 XFilterEvent, and two calls in a row may freeze the
11075 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
11078 bufp
+= n
, count
+= n
, numchars
-= n
;
11081 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
11084 if (event
.xcrossing
.focus
)
11086 /* Avoid nasty pop/raise loops. */
11087 if (f
&& (!(f
->auto_raise
)
11088 || !(f
->auto_lower
)
11089 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
11091 x_new_focus_frame (dpyinfo
, f
);
11092 enter_timestamp
= event
.xcrossing
.time
;
11095 else if (f
== dpyinfo
->x_focus_frame
)
11096 x_new_focus_frame (dpyinfo
, 0);
11099 /* EnterNotify counts as mouse movement,
11100 so update things that depend on mouse position. */
11101 if (f
&& !f
->output_data
.x
->hourglass_p
)
11102 note_mouse_movement (f
, &event
.xmotion
);
11110 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
11113 bufp
+= n
, count
+= n
, numchars
-= n
;
11123 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
11126 bufp
+= n
, count
+= n
, numchars
-= n
;
11130 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
11133 if (f
== dpyinfo
->mouse_face_mouse_frame
)
11135 /* If we move outside the frame, then we're
11136 certainly no longer on any text in the frame. */
11137 clear_mouse_face (dpyinfo
);
11138 dpyinfo
->mouse_face_mouse_frame
= 0;
11141 /* Generate a nil HELP_EVENT to cancel a help-echo.
11142 Do it only if there's something to cancel.
11143 Otherwise, the startup message is cleared when
11144 the mouse leaves the frame. */
11145 if (any_help_event_p
)
11150 XSETFRAME (frame
, f
);
11152 n
= gen_help_event (bufp
, numchars
,
11153 Qnil
, frame
, Qnil
, Qnil
, 0);
11154 bufp
+= n
, count
+= n
, numchars
-= n
;
11164 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
11167 bufp
+= n
, count
+= n
, numchars
-= n
;
11175 previous_help_echo
= help_echo
;
11176 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
11177 help_echo_pos
= -1;
11179 if (dpyinfo
->grabbed
&& last_mouse_frame
11180 && FRAME_LIVE_P (last_mouse_frame
))
11181 f
= last_mouse_frame
;
11183 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
11185 if (dpyinfo
->mouse_face_hidden
)
11187 dpyinfo
->mouse_face_hidden
= 0;
11188 clear_mouse_face (dpyinfo
);
11194 /* Generate SELECT_WINDOW_EVENTs when needed. */
11195 if (mouse_autoselect_window
)
11197 Lisp_Object window
;
11200 window
= window_from_coordinates (f
,
11201 event
.xmotion
.x
, event
.xmotion
.y
,
11204 /* Window will be selected only when it is not selected now and
11205 last mouse movement event was not in it. Minibuffer window
11206 will be selected iff it is active. */
11207 if (WINDOWP(window
)
11208 && !EQ (window
, last_window
)
11209 && !EQ (window
, selected_window
)
11212 bufp
->kind
= SELECT_WINDOW_EVENT
;
11213 bufp
->frame_or_window
= window
;
11215 ++bufp
, ++count
, --numchars
;
11218 last_window
=window
;
11220 note_mouse_movement (f
, &event
.xmotion
);
11224 #ifndef USE_TOOLKIT_SCROLL_BARS
11225 struct scroll_bar
*bar
11226 = x_window_to_scroll_bar (event
.xmotion
.window
);
11229 x_scroll_bar_note_movement (bar
, &event
);
11230 #endif /* USE_TOOLKIT_SCROLL_BARS */
11232 /* If we move outside the frame, then we're
11233 certainly no longer on any text in the frame. */
11234 clear_mouse_face (dpyinfo
);
11237 /* If the contents of the global variable help_echo
11238 has changed, generate a HELP_EVENT. */
11239 if (!NILP (help_echo
)
11240 || !NILP (previous_help_echo
))
11246 XSETFRAME (frame
, f
);
11250 any_help_event_p
= 1;
11251 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
11252 help_echo_window
, help_echo_object
,
11254 bufp
+= n
, count
+= n
, numchars
-= n
;
11260 case ConfigureNotify
:
11261 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
11264 #ifndef USE_X_TOOLKIT
11266 xg_resize_widgets (f
, event
.xconfigure
.width
,
11267 event
.xconfigure
.height
);
11268 #else /* not USE_GTK */
11269 /* If there is a pending resize for fullscreen, don't
11270 do this one, the right one will come later.
11271 The toolkit version doesn't seem to need this, but we
11272 need to reset it below. */
11274 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
11275 && FRAME_NEW_WIDTH (f
) != 0);
11276 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
11277 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
11281 /* In the toolkit version, change_frame_size
11282 is called by the code that handles resizing
11283 of the EmacsFrame widget. */
11285 /* Even if the number of character rows and columns has
11286 not changed, the font size may have changed, so we need
11287 to check the pixel dimensions as well. */
11288 if (columns
!= f
->width
11289 || rows
!= f
->height
11290 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
11291 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
11293 change_frame_size (f
, rows
, columns
, 0, 1, 0);
11294 SET_FRAME_GARBAGED (f
);
11295 cancel_mouse_face (f
);
11297 #endif /* not USE_GTK */
11300 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
11301 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
11304 /* GTK creates windows but doesn't map them.
11305 Only get real positions and check fullscreen when mapped. */
11306 if (FRAME_GTK_OUTER_WIDGET (f
)
11307 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
11310 /* What we have now is the position of Emacs's own window.
11311 Convert that to the position of the window manager window. */
11312 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
11313 &f
->output_data
.x
->top_pos
);
11315 x_check_fullscreen_move (f
);
11316 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
11317 f
->output_data
.x
->want_fullscreen
&=
11318 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
11323 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
11324 xic_set_statusarea (f
);
11327 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11329 /* Since the WM decorations come below top_pos now,
11330 we must put them below top_pos in the future. */
11331 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11332 x_wm_set_size_hint (f
, (long) 0, 0);
11337 case ButtonRelease
:
11340 /* If we decide we want to generate an event to be seen
11341 by the rest of Emacs, we put it here. */
11342 struct input_event emacs_event
;
11343 int tool_bar_p
= 0;
11345 emacs_event
.kind
= NO_EVENT
;
11346 bzero (&compose_status
, sizeof (compose_status
));
11348 if (dpyinfo
->grabbed
11349 && last_mouse_frame
11350 && FRAME_LIVE_P (last_mouse_frame
))
11351 f
= last_mouse_frame
;
11353 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11357 /* Is this in the tool-bar? */
11358 if (WINDOWP (f
->tool_bar_window
)
11359 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
11361 Lisp_Object window
;
11364 x
= event
.xbutton
.x
;
11365 y
= event
.xbutton
.y
;
11368 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
11369 if (EQ (window
, f
->tool_bar_window
))
11371 x_handle_tool_bar_click (f
, &event
.xbutton
);
11377 if (!dpyinfo
->x_focus_frame
11378 || f
== dpyinfo
->x_focus_frame
)
11380 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
11381 if (! popup_activated ())
11383 construct_mouse_click (&emacs_event
, &event
, f
);
11388 #ifndef USE_TOOLKIT_SCROLL_BARS
11389 struct scroll_bar
*bar
11390 = x_window_to_scroll_bar (event
.xbutton
.window
);
11393 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
11394 #endif /* not USE_TOOLKIT_SCROLL_BARS */
11397 if (event
.type
== ButtonPress
)
11399 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
11400 last_mouse_frame
= f
;
11401 /* Ignore any mouse motion that happened
11402 before this event; any subsequent mouse-movement
11403 Emacs events should reflect only motion after
11404 the ButtonPress. */
11406 f
->mouse_moved
= 0;
11409 last_tool_bar_item
= -1;
11412 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
11414 if (numchars
>= 1 && emacs_event
.kind
!= NO_EVENT
)
11416 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
11422 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
11423 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11424 /* For a down-event in the menu bar,
11425 don't pass it to Xt right now.
11426 Instead, save it away
11427 and we will pass it to Xt from kbd_buffer_get_event.
11428 That way, we can run some Lisp code first. */
11431 ! popup_activated ()
11434 f
&& event
.type
== ButtonPress
11435 /* Verify the event is really within the menu bar
11436 and not just sent to it due to grabbing. */
11437 && event
.xbutton
.x
>= 0
11438 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
11439 && event
.xbutton
.y
>= 0
11440 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
11441 && event
.xbutton
.same_screen
)
11443 SET_SAVED_BUTTON_EVENT
;
11444 XSETFRAME (last_mouse_press_frame
, f
);
11446 *finish
= X_EVENT_DROP
;
11449 else if (event
.type
== ButtonPress
)
11451 last_mouse_press_frame
= Qnil
;
11455 #ifdef USE_MOTIF /* This should do not harm for Lucid,
11456 but I am trying to be cautious. */
11457 else if (event
.type
== ButtonRelease
)
11459 if (!NILP (last_mouse_press_frame
))
11461 f
= XFRAME (last_mouse_press_frame
);
11462 if (f
->output_data
.x
)
11463 SET_SAVED_BUTTON_EVENT
;
11468 #endif /* USE_MOTIF */
11471 #endif /* USE_X_TOOLKIT || USE_GTK */
11475 case CirculateNotify
:
11478 case CirculateRequest
:
11481 case VisibilityNotify
:
11484 case MappingNotify
:
11485 /* Someone has changed the keyboard mapping - update the
11487 switch (event
.xmapping
.request
)
11489 case MappingModifier
:
11490 x_find_modifier_meanings (dpyinfo
);
11491 /* This is meant to fall through. */
11492 case MappingKeyboard
:
11493 XRefreshKeyboardMapping (&event
.xmapping
);
11499 #ifdef USE_X_TOOLKIT
11501 XtDispatchEvent (&event
);
11503 #endif /* USE_X_TOOLKIT */
11510 *finish
= X_EVENT_GOTO_OUT
;
11514 *numcharsp
= numchars
;
11521 /* Handles the XEvent EVENT on display DISPLAY.
11522 This is used for event loops outside the normal event handling,
11523 i.e. looping while a popup menu or a dialog is posted. */
11525 x_dispatch_event (event
, display
)
11529 struct x_display_info
*dpyinfo
;
11530 struct input_event bufp
[10];
11531 struct input_event
*bufpp
= bufp
;
11535 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
11536 if (dpyinfo
->display
== display
)
11542 events
= handle_one_xevent (dpyinfo
,
11547 for (i
= 0; i
< events
; ++i
)
11548 kbd_buffer_store_event (&bufp
[i
]);
11553 /* Read events coming from the X server.
11554 This routine is called by the SIGIO handler.
11555 We return as soon as there are no more events to be read.
11557 Events representing keys are stored in buffer BUFP,
11558 which can hold up to NUMCHARS characters.
11559 We return the number of characters stored into the buffer,
11560 thus pretending to be `read'.
11562 EXPECTED is nonzero if the caller knows input is available. */
11565 XTread_socket (sd
, bufp
, numchars
, expected
)
11567 /* register */ struct input_event
*bufp
;
11568 /* register */ int numchars
;
11574 int event_found
= 0;
11575 struct x_display_info
*dpyinfo
;
11577 if (interrupt_input_blocked
)
11579 interrupt_input_pending
= 1;
11583 interrupt_input_pending
= 0;
11586 /* So people can tell when we have read the available input. */
11587 input_signal_count
++;
11590 abort (); /* Don't think this happens. */
11594 /* Find the display we are supposed to read input for.
11595 It's the one communicating on descriptor SD. */
11596 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
11598 #if 0 /* This ought to be unnecessary; let's verify it. */
11600 /* If available, Xlib uses FIOSNBIO to make the socket
11601 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
11602 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
11603 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
11604 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
11605 #endif /* ! defined (FIOSNBIO) */
11608 #if 0 /* This code can't be made to work, with multiple displays,
11609 and appears not to be used on any system any more.
11610 Also keyboard.c doesn't turn O_NDELAY on and off
11611 for X connections. */
11613 #ifndef HAVE_SELECT
11614 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
11616 extern int read_alarm_should_throw
;
11617 read_alarm_should_throw
= 1;
11618 XPeekEvent (dpyinfo
->display
, &event
);
11619 read_alarm_should_throw
= 0;
11621 #endif /* HAVE_SELECT */
11625 /* For debugging, this gives a way to fake an I/O error. */
11626 if (dpyinfo
== XTread_socket_fake_io_error
)
11628 XTread_socket_fake_io_error
= 0;
11629 x_io_error_quitter (dpyinfo
->display
);
11634 count
+= x_session_check_input (bufp
, &numchars
);
11639 /* For GTK we must use the GTK event loop. But XEvents gets passed
11640 to our filter function above, and then to the big event switch.
11641 We use a bunch of globals to communicate with our filter function,
11642 that is kind of ugly, but it works. */
11643 current_dpyinfo
= dpyinfo
;
11645 while (gtk_events_pending ())
11648 current_count
= count
;
11649 current_numcharsp
= &numchars
;
11650 current_bufp
= &bufp
;
11652 gtk_main_iteration ();
11654 count
= current_count
;
11656 current_numcharsp
= 0;
11658 if (current_finish
== X_EVENT_GOTO_OUT
)
11662 #else /* not USE_GTK */
11663 while (XPending (dpyinfo
->display
))
11667 XNextEvent (dpyinfo
->display
, &event
);
11671 /* Filter events for the current X input method.
11672 XFilterEvent returns non-zero if the input method has
11673 consumed the event. We pass the frame's X window to
11674 XFilterEvent because that's the one for which the IC
11676 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
11677 event
.xclient
.window
);
11678 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
11684 count
+= handle_one_xevent (dpyinfo
,
11690 if (finish
== X_EVENT_GOTO_OUT
)
11693 #endif /* USE_GTK */
11698 /* On some systems, an X bug causes Emacs to get no more events
11699 when the window is destroyed. Detect that. (1994.) */
11702 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
11703 One XNOOP in 100 loops will make Emacs terminate.
11704 B. Bretthauer, 1994 */
11706 if (x_noop_count
>= 100)
11710 if (next_noop_dpyinfo
== 0)
11711 next_noop_dpyinfo
= x_display_list
;
11713 XNoOp (next_noop_dpyinfo
->display
);
11715 /* Each time we get here, cycle through the displays now open. */
11716 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
11720 /* If the focus was just given to an auto-raising frame,
11722 /* ??? This ought to be able to handle more than one such frame. */
11723 if (pending_autoraise_frame
)
11725 x_raise_frame (pending_autoraise_frame
);
11726 pending_autoraise_frame
= 0;
11737 /***********************************************************************
11739 ***********************************************************************/
11741 /* Notice when the text cursor of window W has been completely
11742 overwritten by a drawing operation that outputs glyphs in AREA
11743 starting at X0 and ending at X1 in the line starting at Y0 and
11744 ending at Y1. X coordinates are area-relative. X1 < 0 means all
11745 the rest of the line after X0 has been written. Y coordinates
11746 are window-relative. */
11749 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
11751 enum glyph_row_area area
;
11752 int x0
, y0
, x1
, y1
;
11754 if (area
== TEXT_AREA
&& w
->phys_cursor_on_p
)
11756 int cx0
= w
->phys_cursor
.x
;
11757 int cx1
= cx0
+ w
->phys_cursor_width
;
11758 int cy0
= w
->phys_cursor
.y
;
11759 int cy1
= cy0
+ w
->phys_cursor_height
;
11761 if (x0
<= cx0
&& (x1
< 0 || x1
>= cx1
))
11763 /* The cursor image will be completely removed from the
11764 screen if the output area intersects the cursor area in
11765 y-direction. When we draw in [y0 y1[, and some part of
11766 the cursor is at y < y0, that part must have been drawn
11767 before. When scrolling, the cursor is erased before
11768 actually scrolling, so we don't come here. When not
11769 scrolling, the rows above the old cursor row must have
11770 changed, and in this case these rows must have written
11771 over the cursor image.
11773 Likewise if part of the cursor is below y1, with the
11774 exception of the cursor being in the first blank row at
11775 the buffer and window end because update_text_area
11776 doesn't draw that row. (Except when it does, but
11777 that's handled in update_text_area.) */
11779 if (((y0
>= cy0
&& y0
< cy1
) || (y1
> cy0
&& y1
< cy1
))
11780 && w
->current_matrix
->rows
[w
->phys_cursor
.vpos
].displays_text_p
)
11781 w
->phys_cursor_on_p
= 0;
11787 /* Set clipping for output in glyph row ROW. W is the window in which
11788 we operate. GC is the graphics context to set clipping in.
11789 WHOLE_LINE_P non-zero means include the areas used for truncation
11790 mark display and alike in the clipping rectangle.
11792 ROW may be a text row or, e.g., a mode line. Text rows must be
11793 clipped to the interior of the window dedicated to text display,
11794 mode lines must be clipped to the whole window. */
11797 x_clip_to_row (w
, row
, gc
, whole_line_p
)
11799 struct glyph_row
*row
;
11803 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11804 XRectangle clip_rect
;
11805 int window_x
, window_y
, window_width
, window_height
;
11807 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
11809 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
11810 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
11811 clip_rect
.y
= max (clip_rect
.y
, window_y
);
11812 clip_rect
.width
= window_width
;
11813 clip_rect
.height
= row
->visible_height
;
11815 /* If clipping to the whole line, including trunc marks, extend
11816 the rectangle to the left and increase its width. */
11819 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
11820 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
11823 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
11827 /* Draw a hollow box cursor on window W in glyph row ROW. */
11830 x_draw_hollow_cursor (w
, row
)
11832 struct glyph_row
*row
;
11834 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11835 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11836 Display
*dpy
= FRAME_X_DISPLAY (f
);
11839 struct glyph
*cursor_glyph
;
11842 /* Compute frame-relative coordinates from window-relative
11844 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11845 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
11846 + row
->ascent
- w
->phys_cursor_ascent
);
11847 h
= row
->height
- 1;
11849 /* Get the glyph the cursor is on. If we can't tell because
11850 the current matrix is invalid or such, give up. */
11851 cursor_glyph
= get_phys_cursor_glyph (w
);
11852 if (cursor_glyph
== NULL
)
11855 /* Compute the width of the rectangle to draw. If on a stretch
11856 glyph, and `x-stretch-block-cursor' is nil, don't draw a
11857 rectangle as wide as the glyph, but use a canonical character
11859 wd
= cursor_glyph
->pixel_width
- 1;
11860 if (cursor_glyph
->type
== STRETCH_GLYPH
11861 && !x_stretch_cursor_p
)
11862 wd
= min (CANON_X_UNIT (f
), wd
);
11863 w
->phys_cursor_width
= wd
;
11865 /* The foreground of cursor_gc is typically the same as the normal
11866 background color, which can cause the cursor box to be invisible. */
11867 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11868 if (dpyinfo
->scratch_cursor_gc
)
11869 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11871 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11872 GCForeground
, &xgcv
);
11873 gc
= dpyinfo
->scratch_cursor_gc
;
11875 /* Set clipping, draw the rectangle, and reset clipping again. */
11876 x_clip_to_row (w
, row
, gc
, 0);
11877 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11878 XSetClipMask (dpy
, gc
, None
);
11882 /* Draw a bar cursor on window W in glyph row ROW.
11884 Implementation note: One would like to draw a bar cursor with an
11885 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11886 Unfortunately, I didn't find a font yet that has this property set.
11890 x_draw_bar_cursor (w
, row
, width
, kind
)
11892 struct glyph_row
*row
;
11894 enum text_cursor_kinds kind
;
11896 struct frame
*f
= XFRAME (w
->frame
);
11897 struct glyph
*cursor_glyph
;
11899 /* If cursor is out of bounds, don't draw garbage. This can happen
11900 in mini-buffer windows when switching between echo area glyphs
11901 and mini-buffer. */
11902 cursor_glyph
= get_phys_cursor_glyph (w
);
11903 if (cursor_glyph
== NULL
)
11906 /* If on an image, draw like a normal cursor. That's usually better
11907 visible than drawing a bar, esp. if the image is large so that
11908 the bar might not be in the window. */
11909 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11911 struct glyph_row
*row
;
11912 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11913 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11917 Display
*dpy
= FRAME_X_DISPLAY (f
);
11918 Window window
= FRAME_X_WINDOW (f
);
11919 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11920 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11921 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
11924 /* If the glyph's background equals the color we normally draw
11925 the bar cursor in, the bar cursor in its normal color is
11926 invisible. Use the glyph's foreground color instead in this
11927 case, on the assumption that the glyph's colors are chosen so
11928 that the glyph is legible. */
11929 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
11930 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
11932 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11933 xgcv
.graphics_exposures
= 0;
11936 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11939 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11940 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11944 width
= FRAME_CURSOR_WIDTH (f
);
11945 width
= min (cursor_glyph
->pixel_width
, width
);
11947 w
->phys_cursor_width
= width
;
11948 x_clip_to_row (w
, row
, gc
, 0);
11950 if (kind
== BAR_CURSOR
)
11951 XFillRectangle (dpy
, window
, gc
,
11952 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11953 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11954 width
, row
->height
);
11956 XFillRectangle (dpy
, window
, gc
,
11957 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11958 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
11959 row
->height
- width
),
11960 cursor_glyph
->pixel_width
,
11963 XSetClipMask (dpy
, gc
, None
);
11968 /* Clear the cursor of window W to background color, and mark the
11969 cursor as not shown. This is used when the text where the cursor
11970 is is about to be rewritten. */
11976 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11977 x_update_window_cursor (w
, 0);
11981 /* Draw the cursor glyph of window W in glyph row ROW. See the
11982 comment of x_draw_glyphs for the meaning of HL. */
11985 x_draw_phys_cursor_glyph (w
, row
, hl
)
11987 struct glyph_row
*row
;
11988 enum draw_glyphs_face hl
;
11990 /* If cursor hpos is out of bounds, don't draw garbage. This can
11991 happen in mini-buffer windows when switching between echo area
11992 glyphs and mini-buffer. */
11993 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11995 int on_p
= w
->phys_cursor_on_p
;
11998 x1
= x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11999 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
12001 w
->phys_cursor_on_p
= on_p
;
12003 if (hl
== DRAW_CURSOR
)
12004 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
12006 /* When we erase the cursor, and ROW is overlapped by other
12007 rows, make sure that these overlapping parts of other rows
12009 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
12011 if (row
> w
->current_matrix
->rows
12012 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
12013 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
12015 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
12016 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
12017 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
12023 /* Erase the image of a cursor of window W from the screen. */
12026 x_erase_phys_cursor (w
)
12029 struct frame
*f
= XFRAME (w
->frame
);
12030 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12031 int hpos
= w
->phys_cursor
.hpos
;
12032 int vpos
= w
->phys_cursor
.vpos
;
12033 int mouse_face_here_p
= 0;
12034 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
12035 struct glyph_row
*cursor_row
;
12036 struct glyph
*cursor_glyph
;
12037 enum draw_glyphs_face hl
;
12039 /* No cursor displayed or row invalidated => nothing to do on the
12041 if (w
->phys_cursor_type
== NO_CURSOR
)
12042 goto mark_cursor_off
;
12044 /* VPOS >= active_glyphs->nrows means that window has been resized.
12045 Don't bother to erase the cursor. */
12046 if (vpos
>= active_glyphs
->nrows
)
12047 goto mark_cursor_off
;
12049 /* If row containing cursor is marked invalid, there is nothing we
12051 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
12052 if (!cursor_row
->enabled_p
)
12053 goto mark_cursor_off
;
12055 /* If row is completely invisible, don't attempt to delete a cursor which
12056 isn't there. This can happen if cursor is at top of a window, and
12057 we switch to a buffer with a header line in that window. */
12058 if (cursor_row
->visible_height
<= 0)
12059 goto mark_cursor_off
;
12061 /* This can happen when the new row is shorter than the old one.
12062 In this case, either x_draw_glyphs or clear_end_of_line
12063 should have cleared the cursor. Note that we wouldn't be
12064 able to erase the cursor in this case because we don't have a
12065 cursor glyph at hand. */
12066 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
12067 goto mark_cursor_off
;
12069 /* If the cursor is in the mouse face area, redisplay that when
12070 we clear the cursor. */
12071 if (! NILP (dpyinfo
->mouse_face_window
)
12072 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
12073 && (vpos
> dpyinfo
->mouse_face_beg_row
12074 || (vpos
== dpyinfo
->mouse_face_beg_row
12075 && hpos
>= dpyinfo
->mouse_face_beg_col
))
12076 && (vpos
< dpyinfo
->mouse_face_end_row
12077 || (vpos
== dpyinfo
->mouse_face_end_row
12078 && hpos
< dpyinfo
->mouse_face_end_col
))
12079 /* Don't redraw the cursor's spot in mouse face if it is at the
12080 end of a line (on a newline). The cursor appears there, but
12081 mouse highlighting does not. */
12082 && cursor_row
->used
[TEXT_AREA
] > hpos
)
12083 mouse_face_here_p
= 1;
12085 /* Maybe clear the display under the cursor. */
12086 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
12089 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
12091 cursor_glyph
= get_phys_cursor_glyph (w
);
12092 if (cursor_glyph
== NULL
)
12093 goto mark_cursor_off
;
12095 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
12097 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12099 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
12101 cursor_glyph
->pixel_width
,
12102 cursor_row
->visible_height
,
12106 /* Erase the cursor by redrawing the character underneath it. */
12107 if (mouse_face_here_p
)
12108 hl
= DRAW_MOUSE_FACE
;
12110 hl
= DRAW_NORMAL_TEXT
;
12111 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
12114 w
->phys_cursor_on_p
= 0;
12115 w
->phys_cursor_type
= NO_CURSOR
;
12119 /* Non-zero if physical cursor of window W is within mouse face. */
12122 cursor_in_mouse_face_p (w
)
12125 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
12126 int in_mouse_face
= 0;
12128 if (WINDOWP (dpyinfo
->mouse_face_window
)
12129 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
12131 int hpos
= w
->phys_cursor
.hpos
;
12132 int vpos
= w
->phys_cursor
.vpos
;
12134 if (vpos
>= dpyinfo
->mouse_face_beg_row
12135 && vpos
<= dpyinfo
->mouse_face_end_row
12136 && (vpos
> dpyinfo
->mouse_face_beg_row
12137 || hpos
>= dpyinfo
->mouse_face_beg_col
)
12138 && (vpos
< dpyinfo
->mouse_face_end_row
12139 || hpos
< dpyinfo
->mouse_face_end_col
12140 || dpyinfo
->mouse_face_past_end
))
12144 return in_mouse_face
;
12148 /* Display or clear cursor of window W. If ON is zero, clear the
12149 cursor. If it is non-zero, display the cursor. If ON is nonzero,
12150 where to put the cursor is specified by HPOS, VPOS, X and Y. */
12153 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
12155 int on
, hpos
, vpos
, x
, y
;
12157 struct frame
*f
= XFRAME (w
->frame
);
12158 int new_cursor_type
;
12159 int new_cursor_width
;
12161 struct glyph_matrix
*current_glyphs
;
12162 struct glyph_row
*glyph_row
;
12163 struct glyph
*glyph
;
12165 /* This is pointless on invisible frames, and dangerous on garbaged
12166 windows and frames; in the latter case, the frame or window may
12167 be in the midst of changing its size, and x and y may be off the
12169 if (! FRAME_VISIBLE_P (f
)
12170 || FRAME_GARBAGED_P (f
)
12171 || vpos
>= w
->current_matrix
->nrows
12172 || hpos
>= w
->current_matrix
->matrix_w
)
12175 /* If cursor is off and we want it off, return quickly. */
12176 if (!on
&& !w
->phys_cursor_on_p
)
12179 current_glyphs
= w
->current_matrix
;
12180 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
12181 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
12183 /* If cursor row is not enabled, we don't really know where to
12184 display the cursor. */
12185 if (!glyph_row
->enabled_p
)
12187 w
->phys_cursor_on_p
= 0;
12191 xassert (interrupt_input_blocked
);
12193 /* Set new_cursor_type to the cursor we want to be displayed. */
12194 new_cursor_type
= get_window_cursor_type (w
, &new_cursor_width
, &active_cursor
);
12196 /* If cursor is currently being shown and we don't want it to be or
12197 it is in the wrong place, or the cursor type is not what we want,
12199 if (w
->phys_cursor_on_p
12201 || w
->phys_cursor
.x
!= x
12202 || w
->phys_cursor
.y
!= y
12203 || new_cursor_type
!= w
->phys_cursor_type
12204 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
12205 && new_cursor_width
!= w
->phys_cursor_width
)))
12206 x_erase_phys_cursor (w
);
12208 /* Don't check phys_cursor_on_p here because that flag is only set
12209 to zero in some cases where we know that the cursor has been
12210 completely erased, to avoid the extra work of erasing the cursor
12211 twice. In other words, phys_cursor_on_p can be 1 and the cursor
12212 still not be visible, or it has only been partly erased. */
12215 w
->phys_cursor_ascent
= glyph_row
->ascent
;
12216 w
->phys_cursor_height
= glyph_row
->height
;
12218 /* Set phys_cursor_.* before x_draw_.* is called because some
12219 of them may need the information. */
12220 w
->phys_cursor
.x
= x
;
12221 w
->phys_cursor
.y
= glyph_row
->y
;
12222 w
->phys_cursor
.hpos
= hpos
;
12223 w
->phys_cursor
.vpos
= vpos
;
12224 w
->phys_cursor_type
= new_cursor_type
;
12225 w
->phys_cursor_on_p
= 1;
12227 switch (new_cursor_type
)
12229 case HOLLOW_BOX_CURSOR
:
12230 x_draw_hollow_cursor (w
, glyph_row
);
12233 case FILLED_BOX_CURSOR
:
12234 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
12238 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
, BAR_CURSOR
);
12242 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
, HBAR_CURSOR
);
12246 w
->phys_cursor_width
= 0;
12254 if (w
== XWINDOW (f
->selected_window
))
12255 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
12256 xic_set_preeditarea (w
, x
, y
);
12261 if (updating_frame
!= f
)
12262 XFlush (FRAME_X_DISPLAY (f
));
12267 /* Display the cursor on window W, or clear it. X and Y are window
12268 relative pixel coordinates. HPOS and VPOS are glyph matrix
12269 positions. If W is not the selected window, display a hollow
12270 cursor. ON non-zero means display the cursor at X, Y which
12271 correspond to HPOS, VPOS, otherwise it is cleared. */
12274 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
12276 int on
, hpos
, vpos
, x
, y
;
12279 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
12284 /* Display the cursor on window W, or clear it, according to ON_P.
12285 Don't change the cursor's position. */
12288 x_update_cursor (f
, on_p
)
12292 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
12296 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
12297 in the window tree rooted at W. */
12300 x_update_cursor_in_window_tree (w
, on_p
)
12306 if (!NILP (w
->hchild
))
12307 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
12308 else if (!NILP (w
->vchild
))
12309 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
12311 x_update_window_cursor (w
, on_p
);
12313 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
12318 /* Switch the display of W's cursor on or off, according to the value
12322 x_update_window_cursor (w
, on
)
12326 /* Don't update cursor in windows whose frame is in the process
12327 of being deleted. */
12328 if (w
->current_matrix
)
12331 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
12332 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
12342 /* Make the x-window of frame F use the gnu icon bitmap. */
12345 x_bitmap_icon (f
, file
)
12351 if (FRAME_X_WINDOW (f
) == 0)
12354 /* Free up our existing icon bitmap if any. */
12355 if (f
->output_data
.x
->icon_bitmap
> 0)
12356 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
12357 f
->output_data
.x
->icon_bitmap
= 0;
12359 if (STRINGP (file
))
12360 bitmap_id
= x_create_bitmap_from_file (f
, file
);
12363 /* Create the GNU bitmap if necessary. */
12364 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
12365 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
12366 = x_create_bitmap_from_data (f
, gnu_bits
,
12367 gnu_width
, gnu_height
);
12369 /* The first time we create the GNU bitmap,
12370 this increments the ref-count one extra time.
12371 As a result, the GNU bitmap is never freed.
12372 That way, we don't have to worry about allocating it again. */
12373 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
12375 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
12378 x_wm_set_icon_pixmap (f
, bitmap_id
);
12379 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
12385 /* Make the x-window of frame F use a rectangle with text.
12386 Use ICON_NAME as the text. */
12389 x_text_icon (f
, icon_name
)
12393 if (FRAME_X_WINDOW (f
) == 0)
12398 XTextProperty text
;
12399 text
.value
= (unsigned char *) icon_name
;
12400 text
.encoding
= XA_STRING
;
12402 text
.nitems
= strlen (icon_name
);
12403 #ifdef USE_X_TOOLKIT
12404 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12406 #else /* not USE_X_TOOLKIT */
12407 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
12408 #endif /* not USE_X_TOOLKIT */
12410 #else /* not HAVE_X11R4 */
12411 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
12412 #endif /* not HAVE_X11R4 */
12414 if (f
->output_data
.x
->icon_bitmap
> 0)
12415 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
12416 f
->output_data
.x
->icon_bitmap
= 0;
12417 x_wm_set_icon_pixmap (f
, 0);
12422 #define X_ERROR_MESSAGE_SIZE 200
12424 /* If non-nil, this should be a string.
12425 It means catch X errors and store the error message in this string. */
12427 static Lisp_Object x_error_message_string
;
12429 /* An X error handler which stores the error message in
12430 x_error_message_string. This is called from x_error_handler if
12431 x_catch_errors is in effect. */
12434 x_error_catcher (display
, error
)
12436 XErrorEvent
*error
;
12438 XGetErrorText (display
, error
->error_code
,
12439 SDATA (x_error_message_string
),
12440 X_ERROR_MESSAGE_SIZE
);
12443 /* Begin trapping X errors for display DPY. Actually we trap X errors
12444 for all displays, but DPY should be the display you are actually
12447 After calling this function, X protocol errors no longer cause
12448 Emacs to exit; instead, they are recorded in the string
12449 stored in x_error_message_string.
12451 Calling x_check_errors signals an Emacs error if an X error has
12452 occurred since the last call to x_catch_errors or x_check_errors.
12454 Calling x_uncatch_errors resumes the normal error handling. */
12456 void x_check_errors ();
12457 static Lisp_Object
x_catch_errors_unwind ();
12460 x_catch_errors (dpy
)
12463 int count
= SPECPDL_INDEX ();
12465 /* Make sure any errors from previous requests have been dealt with. */
12466 XSync (dpy
, False
);
12468 record_unwind_protect (x_catch_errors_unwind
,
12469 Fcons (make_save_value (dpy
, 0),
12470 x_error_message_string
));
12472 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
12473 SSET (x_error_message_string
, 0, 0);
12478 /* Unbind the binding that we made to check for X errors. */
12481 x_catch_errors_unwind (old_val
)
12482 Lisp_Object old_val
;
12486 first
= XCAR (old_val
);
12488 XSync (XSAVE_VALUE (first
)->pointer
, False
);
12490 x_error_message_string
= XCDR (old_val
);
12494 /* If any X protocol errors have arrived since the last call to
12495 x_catch_errors or x_check_errors, signal an Emacs error using
12496 sprintf (a buffer, FORMAT, the x error message text) as the text. */
12499 x_check_errors (dpy
, format
)
12503 /* Make sure to catch any errors incurred so far. */
12504 XSync (dpy
, False
);
12506 if (SREF (x_error_message_string
, 0))
12507 error (format
, SDATA (x_error_message_string
));
12510 /* Nonzero if we had any X protocol errors
12511 since we did x_catch_errors on DPY. */
12514 x_had_errors_p (dpy
)
12517 /* Make sure to catch any errors incurred so far. */
12518 XSync (dpy
, False
);
12520 return SREF (x_error_message_string
, 0) != 0;
12523 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
12526 x_clear_errors (dpy
)
12529 SSET (x_error_message_string
, 0, 0);
12532 /* Stop catching X protocol errors and let them make Emacs die.
12533 DPY should be the display that was passed to x_catch_errors.
12534 COUNT should be the value that was returned by
12535 the corresponding call to x_catch_errors. */
12538 x_uncatch_errors (dpy
, count
)
12542 unbind_to (count
, Qnil
);
12546 static unsigned int x_wire_count
;
12549 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
12554 /* Handle SIGPIPE, which can happen when the connection to a server
12555 simply goes away. SIGPIPE is handled by x_connection_signal.
12556 Don't need to do anything, because the write which caused the
12557 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
12558 which will do the appropriate cleanup for us. */
12561 x_connection_signal (signalnum
) /* If we don't have an argument, */
12562 int signalnum
; /* some compilers complain in signal calls. */
12565 /* USG systems forget handlers when they are used;
12566 must reestablish each time */
12567 signal (signalnum
, x_connection_signal
);
12572 /************************************************************************
12574 ************************************************************************/
12576 /* Error message passed to x_connection_closed. */
12578 static char *error_msg
;
12580 /* Function installed as fatal_error_signal_hook in
12581 x_connection_closed. Print the X error message, and exit normally,
12582 instead of dumping core when XtCloseDisplay fails. */
12585 x_fatal_error_signal ()
12587 fprintf (stderr
, "%s\n", error_msg
);
12591 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
12592 the text of an error message that lead to the connection loss. */
12595 x_connection_closed (dpy
, error_message
)
12597 char *error_message
;
12599 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
12600 Lisp_Object frame
, tail
;
12603 error_msg
= (char *) alloca (strlen (error_message
) + 1);
12604 strcpy (error_msg
, error_message
);
12605 handling_signal
= 0;
12607 /* Prevent being called recursively because of an error condition
12608 below. Otherwise, we might end up with printing ``can't find per
12609 display information'' in the recursive call instead of printing
12610 the original message here. */
12611 count
= x_catch_errors (dpy
);
12613 /* We have to close the display to inform Xt that it doesn't
12614 exist anymore. If we don't, Xt will continue to wait for
12615 events from the display. As a consequence, a sequence of
12617 M-x make-frame-on-display RET :1 RET
12618 ...kill the new frame, so that we get an IO error...
12619 M-x make-frame-on-display RET :1 RET
12621 will indefinitely wait in Xt for events for display `:1', opened
12622 in the first class to make-frame-on-display.
12624 Closing the display is reported to lead to a bus error on
12625 OpenWindows in certain situations. I suspect that is a bug
12626 in OpenWindows. I don't know how to cicumvent it here. */
12628 #ifdef USE_X_TOOLKIT
12629 /* If DPYINFO is null, this means we didn't open the display
12630 in the first place, so don't try to close it. */
12633 extern void (*fatal_error_signal_hook
) P_ ((void));
12634 fatal_error_signal_hook
= x_fatal_error_signal
;
12635 XtCloseDisplay (dpy
);
12636 fatal_error_signal_hook
= NULL
;
12640 /* Indicate that this display is dead. */
12642 dpyinfo
->display
= 0;
12644 /* First delete frames whose mini-buffers are on frames
12645 that are on the dead display. */
12646 FOR_EACH_FRAME (tail
, frame
)
12648 Lisp_Object minibuf_frame
;
12650 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
12651 if (FRAME_X_P (XFRAME (frame
))
12652 && FRAME_X_P (XFRAME (minibuf_frame
))
12653 && ! EQ (frame
, minibuf_frame
)
12654 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
12655 Fdelete_frame (frame
, Qt
);
12658 /* Now delete all remaining frames on the dead display.
12659 We are now sure none of these is used as the mini-buffer
12660 for another frame that we need to delete. */
12661 FOR_EACH_FRAME (tail
, frame
)
12662 if (FRAME_X_P (XFRAME (frame
))
12663 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
12665 /* Set this to t so that Fdelete_frame won't get confused
12666 trying to find a replacement. */
12667 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
12668 Fdelete_frame (frame
, Qt
);
12672 x_delete_display (dpyinfo
);
12674 x_uncatch_errors (dpy
, count
);
12676 if (x_display_list
== 0)
12678 fprintf (stderr
, "%s\n", error_msg
);
12679 shut_down_emacs (0, 0, Qnil
);
12683 /* Ordinary stack unwind doesn't deal with these. */
12685 sigunblock (sigmask (SIGIO
));
12687 sigunblock (sigmask (SIGALRM
));
12688 TOTALLY_UNBLOCK_INPUT
;
12690 clear_waiting_for_input ();
12691 error ("%s", error_msg
);
12695 /* This is the usual handler for X protocol errors.
12696 It kills all frames on the display that we got the error for.
12697 If that was the only one, it prints an error message and kills Emacs. */
12700 x_error_quitter (display
, error
)
12702 XErrorEvent
*error
;
12704 char buf
[256], buf1
[356];
12706 /* Note that there is no real way portable across R3/R4 to get the
12707 original error handler. */
12709 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
12710 sprintf (buf1
, "X protocol error: %s on protocol request %d",
12711 buf
, error
->request_code
);
12712 x_connection_closed (display
, buf1
);
12716 /* This is the first-level handler for X protocol errors.
12717 It calls x_error_quitter or x_error_catcher. */
12720 x_error_handler (display
, error
)
12722 XErrorEvent
*error
;
12724 if (! NILP (x_error_message_string
))
12725 x_error_catcher (display
, error
);
12727 x_error_quitter (display
, error
);
12731 /* This is the handler for X IO errors, always.
12732 It kills all frames on the display that we lost touch with.
12733 If that was the only one, it prints an error message and kills Emacs. */
12736 x_io_error_quitter (display
)
12741 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
12742 x_connection_closed (display
, buf
);
12746 /* Changing the font of the frame. */
12748 /* Give frame F the font named FONTNAME as its default font, and
12749 return the full name of that font. FONTNAME may be a wildcard
12750 pattern; in that case, we choose some font that fits the pattern.
12751 The return value shows which font we chose. */
12754 x_new_font (f
, fontname
)
12756 register char *fontname
;
12758 struct font_info
*fontp
12759 = FS_LOAD_FONT (f
, 0, fontname
, -1);
12764 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
12765 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
12766 f
->output_data
.x
->fontset
= -1;
12768 x_compute_fringe_widths (f
, 1);
12770 /* Compute the scroll bar width in character columns. */
12771 if (f
->scroll_bar_pixel_width
> 0)
12773 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12774 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
12778 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12779 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
12782 /* Now make the frame display the given font. */
12783 if (FRAME_X_WINDOW (f
) != 0)
12785 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
12786 f
->output_data
.x
->font
->fid
);
12787 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
12788 f
->output_data
.x
->font
->fid
);
12789 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
12790 f
->output_data
.x
->font
->fid
);
12792 frame_update_line_height (f
);
12794 /* Don't change the size of a tip frame; there's no point in
12795 doing it because it's done in Fx_show_tip, and it leads to
12796 problems because the tip frame has no widget. */
12797 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
12798 x_set_window_size (f
, 0, f
->width
, f
->height
);
12801 /* If we are setting a new frame's font for the first time,
12802 there are no faces yet, so this font's height is the line height. */
12803 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
12805 return build_string (fontp
->full_name
);
12808 /* Give frame F the fontset named FONTSETNAME as its default font, and
12809 return the full name of that fontset. FONTSETNAME may be a wildcard
12810 pattern; in that case, we choose some fontset that fits the pattern.
12811 The return value shows which fontset we chose. */
12814 x_new_fontset (f
, fontsetname
)
12818 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
12819 Lisp_Object result
;
12824 if (f
->output_data
.x
->fontset
== fontset
)
12825 /* This fontset is already set in frame F. There's nothing more
12827 return fontset_name (fontset
);
12829 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
12831 if (!STRINGP (result
))
12832 /* Can't load ASCII font. */
12835 /* Since x_new_font doesn't update any fontset information, do it now. */
12836 f
->output_data
.x
->fontset
= fontset
;
12840 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
12841 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
12844 return build_string (fontsetname
);
12847 /* Compute actual fringe widths */
12850 x_compute_fringe_widths (f
, redraw
)
12854 int o_left
= f
->output_data
.x
->left_fringe_width
;
12855 int o_right
= f
->output_data
.x
->right_fringe_width
;
12856 int o_cols
= f
->output_data
.x
->fringe_cols
;
12858 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
12859 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
12860 int left_fringe_width
, right_fringe_width
;
12862 if (!NILP (left_fringe
))
12863 left_fringe
= Fcdr (left_fringe
);
12864 if (!NILP (right_fringe
))
12865 right_fringe
= Fcdr (right_fringe
);
12867 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
12868 XINT (left_fringe
));
12869 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
12870 XINT (right_fringe
));
12872 if (left_fringe_width
|| right_fringe_width
)
12874 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
12875 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
12876 int conf_wid
= left_wid
+ right_wid
;
12877 int font_wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12878 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
12879 int real_wid
= cols
* font_wid
;
12880 if (left_wid
&& right_wid
)
12882 if (left_fringe_width
< 0)
12884 /* Left fringe width is fixed, adjust right fringe if necessary */
12885 f
->output_data
.x
->left_fringe_width
= left_wid
;
12886 f
->output_data
.x
->right_fringe_width
= real_wid
- left_wid
;
12888 else if (right_fringe_width
< 0)
12890 /* Right fringe width is fixed, adjust left fringe if necessary */
12891 f
->output_data
.x
->left_fringe_width
= real_wid
- right_wid
;
12892 f
->output_data
.x
->right_fringe_width
= right_wid
;
12896 /* Adjust both fringes with an equal amount.
12897 Note that we are doing integer arithmetic here, so don't
12898 lose a pixel if the total width is an odd number. */
12899 int fill
= real_wid
- conf_wid
;
12900 f
->output_data
.x
->left_fringe_width
= left_wid
+ fill
/2;
12901 f
->output_data
.x
->right_fringe_width
= right_wid
+ fill
- fill
/2;
12904 else if (left_fringe_width
)
12906 f
->output_data
.x
->left_fringe_width
= real_wid
;
12907 f
->output_data
.x
->right_fringe_width
= 0;
12911 f
->output_data
.x
->left_fringe_width
= 0;
12912 f
->output_data
.x
->right_fringe_width
= real_wid
;
12914 f
->output_data
.x
->fringe_cols
= cols
;
12915 f
->output_data
.x
->fringes_extra
= real_wid
;
12919 f
->output_data
.x
->left_fringe_width
= 0;
12920 f
->output_data
.x
->right_fringe_width
= 0;
12921 f
->output_data
.x
->fringe_cols
= 0;
12922 f
->output_data
.x
->fringes_extra
= 0;
12925 if (redraw
&& FRAME_VISIBLE_P (f
))
12926 if (o_left
!= f
->output_data
.x
->left_fringe_width
||
12927 o_right
!= f
->output_data
.x
->right_fringe_width
||
12928 o_cols
!= f
->output_data
.x
->fringe_cols
)
12932 /***********************************************************************
12934 ***********************************************************************/
12940 /* XIM destroy callback function, which is called whenever the
12941 connection to input method XIM dies. CLIENT_DATA contains a
12942 pointer to the x_display_info structure corresponding to XIM. */
12945 xim_destroy_callback (xim
, client_data
, call_data
)
12947 XPointer client_data
;
12948 XPointer call_data
;
12950 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
12951 Lisp_Object frame
, tail
;
12955 /* No need to call XDestroyIC.. */
12956 FOR_EACH_FRAME (tail
, frame
)
12958 struct frame
*f
= XFRAME (frame
);
12959 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
12961 FRAME_XIC (f
) = NULL
;
12962 if (FRAME_XIC_FONTSET (f
))
12964 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
12965 FRAME_XIC_FONTSET (f
) = NULL
;
12970 /* No need to call XCloseIM. */
12971 dpyinfo
->xim
= NULL
;
12972 XFree (dpyinfo
->xim_styles
);
12976 #endif /* HAVE_X11R6 */
12979 /* This isn't prototyped in OSF 5.0 or 5.1a. */
12980 extern char *XSetIMValues
P_ ((XIM
, ...));
12983 /* Open the connection to the XIM server on display DPYINFO.
12984 RESOURCE_NAME is the resource name Emacs uses. */
12987 xim_open_dpy (dpyinfo
, resource_name
)
12988 struct x_display_info
*dpyinfo
;
12989 char *resource_name
;
12994 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
12995 dpyinfo
->xim
= xim
;
13000 XIMCallback destroy
;
13003 /* Get supported styles and XIM values. */
13004 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
13007 destroy
.callback
= xim_destroy_callback
;
13008 destroy
.client_data
= (XPointer
)dpyinfo
;
13009 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
13013 #else /* not USE_XIM */
13014 dpyinfo
->xim
= NULL
;
13015 #endif /* not USE_XIM */
13019 #ifdef HAVE_X11R6_XIM
13023 struct x_display_info
*dpyinfo
;
13024 char *resource_name
;
13027 /* XIM instantiate callback function, which is called whenever an XIM
13028 server is available. DISPLAY is teh display of the XIM.
13029 CLIENT_DATA contains a pointer to an xim_inst_t structure created
13030 when the callback was registered. */
13033 xim_instantiate_callback (display
, client_data
, call_data
)
13035 XPointer client_data
;
13036 XPointer call_data
;
13038 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
13039 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
13041 /* We don't support multiple XIM connections. */
13045 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
13047 /* Create XIC for the existing frames on the same display, as long
13048 as they have no XIC. */
13049 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
13051 Lisp_Object tail
, frame
;
13054 FOR_EACH_FRAME (tail
, frame
)
13056 struct frame
*f
= XFRAME (frame
);
13058 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
13059 if (FRAME_XIC (f
) == NULL
)
13061 create_frame_xic (f
);
13062 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
13063 xic_set_statusarea (f
);
13064 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
13066 struct window
*w
= XWINDOW (f
->selected_window
);
13067 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
13076 #endif /* HAVE_X11R6_XIM */
13079 /* Open a connection to the XIM server on display DPYINFO.
13080 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
13081 connection only at the first time. On X11R6, open the connection
13082 in the XIM instantiate callback function. */
13085 xim_initialize (dpyinfo
, resource_name
)
13086 struct x_display_info
*dpyinfo
;
13087 char *resource_name
;
13090 #ifdef HAVE_X11R6_XIM
13091 struct xim_inst_t
*xim_inst
;
13094 dpyinfo
->xim
= NULL
;
13095 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
13096 xim_inst
->dpyinfo
= dpyinfo
;
13097 len
= strlen (resource_name
);
13098 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
13099 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
13100 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
13101 resource_name
, EMACS_CLASS
,
13102 xim_instantiate_callback
,
13103 /* Fixme: This is XPointer in
13104 XFree86 but (XPointer *) on
13105 Tru64, at least. */
13106 (XPointer
) xim_inst
);
13107 #else /* not HAVE_X11R6_XIM */
13108 dpyinfo
->xim
= NULL
;
13109 xim_open_dpy (dpyinfo
, resource_name
);
13110 #endif /* not HAVE_X11R6_XIM */
13112 #else /* not USE_XIM */
13113 dpyinfo
->xim
= NULL
;
13114 #endif /* not USE_XIM */
13118 /* Close the connection to the XIM server on display DPYINFO. */
13121 xim_close_dpy (dpyinfo
)
13122 struct x_display_info
*dpyinfo
;
13125 #ifdef HAVE_X11R6_XIM
13126 if (dpyinfo
->display
)
13127 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
13129 xim_instantiate_callback
, NULL
);
13130 #endif /* not HAVE_X11R6_XIM */
13131 if (dpyinfo
->display
)
13132 XCloseIM (dpyinfo
->xim
);
13133 dpyinfo
->xim
= NULL
;
13134 XFree (dpyinfo
->xim_styles
);
13135 #endif /* USE_XIM */
13138 #endif /* not HAVE_X11R6_XIM */
13142 /* Calculate the absolute position in frame F
13143 from its current recorded position values and gravity. */
13146 x_calc_absolute_position (f
)
13150 int win_x
= 0, win_y
= 0;
13151 int flags
= f
->output_data
.x
->size_hint_flags
;
13154 /* We have nothing to do if the current position
13155 is already for the top-left corner. */
13156 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
13159 this_window
= FRAME_OUTER_WINDOW (f
);
13161 /* Find the position of the outside upper-left corner of
13162 the inner window, with respect to the outer window.
13163 But do this only if we will need the results. */
13164 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
13169 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
13172 x_clear_errors (FRAME_X_DISPLAY (f
));
13173 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
13175 /* From-window, to-window. */
13177 f
->output_data
.x
->parent_desc
,
13179 /* From-position, to-position. */
13180 0, 0, &win_x
, &win_y
,
13182 /* Child of win. */
13184 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
13186 Window newroot
, newparent
= 0xdeadbeef;
13187 Window
*newchildren
;
13188 unsigned int nchildren
;
13190 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
13191 &newparent
, &newchildren
, &nchildren
))
13194 XFree ((char *) newchildren
);
13196 f
->output_data
.x
->parent_desc
= newparent
;
13202 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
13206 /* Treat negative positions as relative to the leftmost bottommost
13207 position that fits on the screen. */
13208 if (flags
& XNegative
)
13209 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
13210 - 2 * f
->output_data
.x
->border_width
- win_x
13212 + f
->output_data
.x
->left_pos
);
13215 int height
= PIXEL_HEIGHT (f
);
13217 #if defined USE_X_TOOLKIT && defined USE_MOTIF
13218 /* Something is fishy here. When using Motif, starting Emacs with
13219 `-g -0-0', the frame appears too low by a few pixels.
13221 This seems to be so because initially, while Emacs is starting,
13222 the column widget's height and the frame's pixel height are
13223 different. The column widget's height is the right one. In
13224 later invocations, when Emacs is up, the frame's pixel height
13227 It's not obvious where the initial small difference comes from.
13228 2000-12-01, gerd. */
13230 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
13233 if (flags
& YNegative
)
13234 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
13235 - 2 * f
->output_data
.x
->border_width
13238 + f
->output_data
.x
->top_pos
);
13241 /* The left_pos and top_pos
13242 are now relative to the top and left screen edges,
13243 so the flags should correspond. */
13244 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
13247 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
13248 to really change the position, and 0 when calling from
13249 x_make_frame_visible (in that case, XOFF and YOFF are the current
13250 position values). It is -1 when calling from x_set_frame_parameters,
13251 which means, do adjust for borders but don't change the gravity. */
13254 x_set_offset (f
, xoff
, yoff
, change_gravity
)
13256 register int xoff
, yoff
;
13257 int change_gravity
;
13259 int modified_top
, modified_left
;
13261 if (change_gravity
> 0)
13263 f
->output_data
.x
->top_pos
= yoff
;
13264 f
->output_data
.x
->left_pos
= xoff
;
13265 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
13267 f
->output_data
.x
->size_hint_flags
|= XNegative
;
13269 f
->output_data
.x
->size_hint_flags
|= YNegative
;
13270 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
13272 x_calc_absolute_position (f
);
13275 x_wm_set_size_hint (f
, (long) 0, 0);
13277 modified_left
= f
->output_data
.x
->left_pos
;
13278 modified_top
= f
->output_data
.x
->top_pos
;
13279 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
13280 this seems to be unnecessary and incorrect. rms, 4/17/97. */
13281 /* It is a mystery why we need to add the border_width here
13282 when the frame is already visible, but experiment says we do. */
13283 if (change_gravity
!= 0)
13285 modified_left
+= f
->output_data
.x
->border_width
;
13286 modified_top
+= f
->output_data
.x
->border_width
;
13290 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13291 modified_left
, modified_top
);
13295 /* Check if we need to resize the frame due to a fullscreen request.
13296 If so needed, resize the frame. */
13298 x_check_fullscreen (f
)
13301 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
13303 int width
, height
, ign
;
13305 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
13306 &f
->output_data
.x
->top_pos
);
13308 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
13310 /* We do not need to move the window, it shall be taken care of
13311 when setting WM manager hints.
13312 If the frame is visible already, the position is checked by
13313 x_check_fullscreen_move. */
13314 if (f
->width
!= width
|| f
->height
!= height
)
13316 change_frame_size (f
, height
, width
, 0, 1, 0);
13317 SET_FRAME_GARBAGED (f
);
13318 cancel_mouse_face (f
);
13320 /* Wait for the change of frame size to occur */
13321 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
13327 /* If frame parameters are set after the frame is mapped, we need to move
13328 the window. This is done in xfns.c.
13329 Some window managers moves the window to the right position, some
13330 moves the outer window manager window to the specified position.
13331 Here we check that we are in the right spot. If not, make a second
13332 move, assuming we are dealing with the second kind of window manager. */
13334 x_check_fullscreen_move (f
)
13337 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
13339 int expect_top
= f
->output_data
.x
->top_pos
;
13340 int expect_left
= f
->output_data
.x
->left_pos
;
13342 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
13344 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
13347 if (expect_top
!= f
->output_data
.x
->top_pos
13348 || expect_left
!= f
->output_data
.x
->left_pos
)
13349 x_set_offset (f
, expect_left
, expect_top
, 1);
13351 /* Just do this once */
13352 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
13357 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
13358 wanted positions of the WM window (not emacs window).
13359 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
13360 window (FRAME_X_WINDOW).
13363 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
13370 int newwidth
= f
->width
, newheight
= f
->height
;
13372 *top_pos
= f
->output_data
.x
->top_pos
;
13373 *left_pos
= f
->output_data
.x
->left_pos
;
13375 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
13379 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
13380 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
13381 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
13382 - f
->output_data
.x
->y_pixels_diff
;
13383 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
13387 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
13391 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
13392 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
13393 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
13394 - f
->output_data
.x
->x_pixels_diff
;
13395 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
13400 *height
= newheight
;
13404 /* Change the size of frame F's X window to COLS/ROWS in the case F
13405 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
13406 top-left-corner window gravity for this size change and subsequent
13407 size changes. Otherwise we leave the window gravity unchanged. */
13410 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
13412 int change_gravity
;
13415 int pixelwidth
, pixelheight
;
13417 check_frame_size (f
, &rows
, &cols
);
13418 f
->output_data
.x
->vertical_scroll_bar_extra
13419 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
13421 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
13422 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
13423 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
13425 x_compute_fringe_widths (f
, 0);
13427 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
13428 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
13430 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
13431 x_wm_set_size_hint (f
, (long) 0, 0);
13433 XSync (FRAME_X_DISPLAY (f
), False
);
13434 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13435 pixelwidth
, pixelheight
);
13437 /* Now, strictly speaking, we can't be sure that this is accurate,
13438 but the window manager will get around to dealing with the size
13439 change request eventually, and we'll hear how it went when the
13440 ConfigureNotify event gets here.
13442 We could just not bother storing any of this information here,
13443 and let the ConfigureNotify event set everything up, but that
13444 might be kind of confusing to the Lisp code, since size changes
13445 wouldn't be reported in the frame parameters until some random
13446 point in the future when the ConfigureNotify event arrives.
13448 We pass 1 for DELAY since we can't run Lisp code inside of
13450 change_frame_size (f
, rows
, cols
, 0, 1, 0);
13451 PIXEL_WIDTH (f
) = pixelwidth
;
13452 PIXEL_HEIGHT (f
) = pixelheight
;
13454 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
13455 receive in the ConfigureNotify event; if we get what we asked
13456 for, then the event won't cause the screen to become garbaged, so
13457 we have to make sure to do it here. */
13458 SET_FRAME_GARBAGED (f
);
13460 XFlush (FRAME_X_DISPLAY (f
));
13464 /* Call this to change the size of frame F's x-window.
13465 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
13466 for this size change and subsequent size changes.
13467 Otherwise we leave the window gravity unchanged. */
13470 x_set_window_size (f
, change_gravity
, cols
, rows
)
13472 int change_gravity
;
13478 if (FRAME_GTK_WIDGET (f
))
13479 xg_frame_set_char_size (f
, cols
, rows
);
13481 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13482 #elif USE_X_TOOLKIT
13484 if (f
->output_data
.x
->widget
!= NULL
)
13486 /* The x and y position of the widget is clobbered by the
13487 call to XtSetValues within EmacsFrameSetCharSize.
13488 This is a real kludge, but I don't understand Xt so I can't
13489 figure out a correct fix. Can anyone else tell me? -- rms. */
13490 int xpos
= f
->output_data
.x
->widget
->core
.x
;
13491 int ypos
= f
->output_data
.x
->widget
->core
.y
;
13492 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
13493 f
->output_data
.x
->widget
->core
.x
= xpos
;
13494 f
->output_data
.x
->widget
->core
.y
= ypos
;
13497 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13499 #else /* not USE_X_TOOLKIT */
13501 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
13503 #endif /* not USE_X_TOOLKIT */
13505 /* If cursor was outside the new size, mark it as off. */
13506 mark_window_cursors_off (XWINDOW (f
->root_window
));
13508 /* Clear out any recollection of where the mouse highlighting was,
13509 since it might be in a place that's outside the new frame size.
13510 Actually checking whether it is outside is a pain in the neck,
13511 so don't try--just let the highlighting be done afresh with new size. */
13512 cancel_mouse_face (f
);
13517 /* Mouse warping. */
13520 x_set_mouse_position (f
, x
, y
)
13526 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
13527 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
13529 if (pix_x
< 0) pix_x
= 0;
13530 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
13532 if (pix_y
< 0) pix_y
= 0;
13533 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
13537 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13538 0, 0, 0, 0, pix_x
, pix_y
);
13542 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
13545 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
13551 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13552 0, 0, 0, 0, pix_x
, pix_y
);
13556 /* focus shifting, raising and lowering. */
13559 x_focus_on_frame (f
)
13562 #if 0 /* This proves to be unpleasant. */
13566 /* I don't think that the ICCCM allows programs to do things like this
13567 without the interaction of the window manager. Whatever you end up
13568 doing with this code, do it to x_unfocus_frame too. */
13569 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13570 RevertToPointerRoot
, CurrentTime
);
13575 x_unfocus_frame (f
)
13579 /* Look at the remarks in x_focus_on_frame. */
13580 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
13581 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
13582 RevertToPointerRoot
, CurrentTime
);
13586 /* Raise frame F. */
13592 if (f
->async_visible
)
13595 #ifdef USE_X_TOOLKIT
13596 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13597 #else /* not USE_X_TOOLKIT */
13598 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13599 #endif /* not USE_X_TOOLKIT */
13600 XFlush (FRAME_X_DISPLAY (f
));
13605 /* Lower frame F. */
13611 if (f
->async_visible
)
13614 #ifdef USE_X_TOOLKIT
13615 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13616 #else /* not USE_X_TOOLKIT */
13617 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13618 #endif /* not USE_X_TOOLKIT */
13619 XFlush (FRAME_X_DISPLAY (f
));
13625 XTframe_raise_lower (f
, raise_flag
)
13635 /* Change of visibility. */
13637 /* This tries to wait until the frame is really visible.
13638 However, if the window manager asks the user where to position
13639 the frame, this will return before the user finishes doing that.
13640 The frame will not actually be visible at that time,
13641 but it will become visible later when the window manager
13642 finishes with it. */
13645 x_make_frame_visible (f
)
13649 int original_top
, original_left
;
13650 int retry_count
= 2;
13656 type
= x_icon_type (f
);
13658 x_bitmap_icon (f
, type
);
13660 if (! FRAME_VISIBLE_P (f
))
13662 /* We test FRAME_GARBAGED_P here to make sure we don't
13663 call x_set_offset a second time
13664 if we get to x_make_frame_visible a second time
13665 before the window gets really visible. */
13666 if (! FRAME_ICONIFIED_P (f
)
13667 && ! f
->output_data
.x
->asked_for_visible
)
13668 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13670 f
->output_data
.x
->asked_for_visible
= 1;
13672 if (! EQ (Vx_no_window_manager
, Qt
))
13673 x_wm_set_window_state (f
, NormalState
);
13674 #ifdef USE_X_TOOLKIT
13675 /* This was XtPopup, but that did nothing for an iconified frame. */
13676 XtMapWidget (f
->output_data
.x
->widget
);
13677 #else /* not USE_X_TOOLKIT */
13679 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
13681 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13682 #endif /* not USE_GTK */
13683 #endif /* not USE_X_TOOLKIT */
13684 #if 0 /* This seems to bring back scroll bars in the wrong places
13685 if the window configuration has changed. They seem
13686 to come back ok without this. */
13687 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
13688 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13692 XFlush (FRAME_X_DISPLAY (f
));
13694 /* Synchronize to ensure Emacs knows the frame is visible
13695 before we do anything else. We do this loop with input not blocked
13696 so that incoming events are handled. */
13700 /* This must be before UNBLOCK_INPUT
13701 since events that arrive in response to the actions above
13702 will set it when they are handled. */
13703 int previously_visible
= f
->output_data
.x
->has_been_visible
;
13705 original_left
= f
->output_data
.x
->left_pos
;
13706 original_top
= f
->output_data
.x
->top_pos
;
13708 /* This must come after we set COUNT. */
13711 /* We unblock here so that arriving X events are processed. */
13713 /* Now move the window back to where it was "supposed to be".
13714 But don't do it if the gravity is negative.
13715 When the gravity is negative, this uses a position
13716 that is 3 pixels too low. Perhaps that's really the border width.
13718 Don't do this if the window has never been visible before,
13719 because the window manager may choose the position
13720 and we don't want to override it. */
13722 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
13723 && f
->output_data
.x
->win_gravity
== NorthWestGravity
13724 && previously_visible
)
13728 unsigned int width
, height
, border
, depth
;
13732 /* On some window managers (such as FVWM) moving an existing
13733 window, even to the same place, causes the window manager
13734 to introduce an offset. This can cause the window to move
13735 to an unexpected location. Check the geometry (a little
13736 slow here) and then verify that the window is in the right
13737 place. If the window is not in the right place, move it
13738 there, and take the potential window manager hit. */
13739 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13740 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
13742 if (original_left
!= x
|| original_top
!= y
)
13743 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13744 original_left
, original_top
);
13749 XSETFRAME (frame
, f
);
13751 /* Wait until the frame is visible. Process X events until a
13752 MapNotify event has been seen, or until we think we won't get a
13753 MapNotify at all.. */
13754 for (count
= input_signal_count
+ 10;
13755 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
13757 /* Force processing of queued events. */
13760 /* Machines that do polling rather than SIGIO have been
13761 observed to go into a busy-wait here. So we'll fake an
13762 alarm signal to let the handler know that there's something
13763 to be read. We used to raise a real alarm, but it seems
13764 that the handler isn't always enabled here. This is
13766 if (input_polling_used ())
13768 /* It could be confusing if a real alarm arrives while
13769 processing the fake one. Turn it off and let the
13770 handler reset it. */
13771 extern void poll_for_input_1
P_ ((void));
13772 int old_poll_suppress_count
= poll_suppress_count
;
13773 poll_suppress_count
= 1;
13774 poll_for_input_1 ();
13775 poll_suppress_count
= old_poll_suppress_count
;
13778 /* See if a MapNotify event has been processed. */
13779 FRAME_SAMPLE_VISIBILITY (f
);
13784 (let ((f (selected-frame)))
13788 the frame is not raised with various window managers on
13789 FreeBSD, Linux and Solaris. It turns out that, for some
13790 unknown reason, the call to XtMapWidget is completely ignored.
13791 Mapping the widget a second time works. */
13793 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
13798 /* Change from mapped state to withdrawn state. */
13800 /* Make the frame visible (mapped and not iconified). */
13803 x_make_frame_invisible (f
)
13808 #ifdef USE_X_TOOLKIT
13809 /* Use the frame's outermost window, not the one we normally draw on. */
13810 window
= XtWindow (f
->output_data
.x
->widget
);
13811 #else /* not USE_X_TOOLKIT */
13812 window
= FRAME_X_WINDOW (f
);
13813 #endif /* not USE_X_TOOLKIT */
13815 /* Don't keep the highlight on an invisible frame. */
13816 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13817 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13819 #if 0/* This might add unreliability; I don't trust it -- rms. */
13820 if (! f
->async_visible
&& ! f
->async_iconified
)
13826 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
13827 that the current position of the window is user-specified, rather than
13828 program-specified, so that when the window is mapped again, it will be
13829 placed at the same location, without forcing the user to position it
13830 by hand again (they have already done that once for this window.) */
13831 x_wm_set_size_hint (f
, (long) 0, 1);
13834 if (FRAME_GTK_OUTER_WIDGET (f
))
13836 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
13843 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
13844 DefaultScreen (FRAME_X_DISPLAY (f
))))
13846 UNBLOCK_INPUT_RESIGNAL
;
13847 error ("Can't notify window manager of window withdrawal");
13849 #else /* ! defined (HAVE_X11R4) */
13851 /* Tell the window manager what we're going to do. */
13852 if (! EQ (Vx_no_window_manager
, Qt
))
13856 unmap
.xunmap
.type
= UnmapNotify
;
13857 unmap
.xunmap
.window
= window
;
13858 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
13859 unmap
.xunmap
.from_configure
= False
;
13860 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13861 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13863 SubstructureRedirectMaskSubstructureNotifyMask
,
13866 UNBLOCK_INPUT_RESIGNAL
;
13867 error ("Can't notify window manager of withdrawal");
13871 /* Unmap the window ourselves. Cheeky! */
13872 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
13873 #endif /* ! defined (HAVE_X11R4) */
13876 /* We can't distinguish this from iconification
13877 just by the event that we get from the server.
13878 So we can't win using the usual strategy of letting
13879 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
13880 and synchronize with the server to make sure we agree. */
13882 FRAME_ICONIFIED_P (f
) = 0;
13883 f
->async_visible
= 0;
13884 f
->async_iconified
= 0;
13891 /* Change window state from mapped to iconified. */
13894 x_iconify_frame (f
)
13900 /* Don't keep the highlight on an invisible frame. */
13901 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13902 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13904 if (f
->async_iconified
)
13909 FRAME_SAMPLE_VISIBILITY (f
);
13911 type
= x_icon_type (f
);
13913 x_bitmap_icon (f
, type
);
13916 if (FRAME_GTK_OUTER_WIDGET (f
))
13918 if (! FRAME_VISIBLE_P (f
))
13919 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
13921 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
13924 f
->async_iconified
= 1;
13925 f
->async_visible
= 0;
13931 #ifdef USE_X_TOOLKIT
13933 if (! FRAME_VISIBLE_P (f
))
13935 if (! EQ (Vx_no_window_manager
, Qt
))
13936 x_wm_set_window_state (f
, IconicState
);
13937 /* This was XtPopup, but that did nothing for an iconified frame. */
13938 XtMapWidget (f
->output_data
.x
->widget
);
13939 /* The server won't give us any event to indicate
13940 that an invisible frame was changed to an icon,
13941 so we have to record it here. */
13944 f
->async_iconified
= 1;
13945 f
->async_visible
= 0;
13950 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
13951 XtWindow (f
->output_data
.x
->widget
),
13952 DefaultScreen (FRAME_X_DISPLAY (f
)));
13956 error ("Can't notify window manager of iconification");
13958 f
->async_iconified
= 1;
13959 f
->async_visible
= 0;
13963 XFlush (FRAME_X_DISPLAY (f
));
13965 #else /* not USE_X_TOOLKIT */
13967 /* Make sure the X server knows where the window should be positioned,
13968 in case the user deiconifies with the window manager. */
13969 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
13970 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13972 /* Since we don't know which revision of X we're running, we'll use both
13973 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
13975 /* X11R4: send a ClientMessage to the window manager using the
13976 WM_CHANGE_STATE type. */
13980 message
.xclient
.window
= FRAME_X_WINDOW (f
);
13981 message
.xclient
.type
= ClientMessage
;
13982 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
13983 message
.xclient
.format
= 32;
13984 message
.xclient
.data
.l
[0] = IconicState
;
13986 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13987 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13989 SubstructureRedirectMask
| SubstructureNotifyMask
,
13992 UNBLOCK_INPUT_RESIGNAL
;
13993 error ("Can't notify window manager of iconification");
13997 /* X11R3: set the initial_state field of the window manager hints to
13999 x_wm_set_window_state (f
, IconicState
);
14001 if (!FRAME_VISIBLE_P (f
))
14003 /* If the frame was withdrawn, before, we must map it. */
14004 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
14007 f
->async_iconified
= 1;
14008 f
->async_visible
= 0;
14010 XFlush (FRAME_X_DISPLAY (f
));
14012 #endif /* not USE_X_TOOLKIT */
14016 /* Free X resources of frame F. */
14019 x_free_frame_resources (f
)
14022 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14024 struct scroll_bar
*b
;
14028 /* If a display connection is dead, don't try sending more
14029 commands to the X server. */
14030 if (dpyinfo
->display
)
14032 if (f
->output_data
.x
->icon_desc
)
14033 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
14035 #ifdef USE_X_TOOLKIT
14036 /* Explicitly destroy the scroll bars of the frame. Without
14037 this, we get "BadDrawable" errors from the toolkit later on,
14038 presumably from expose events generated for the disappearing
14039 toolkit scroll bars. */
14040 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
14042 b
= XSCROLL_BAR (bar
);
14043 x_scroll_bar_remove (b
);
14049 free_frame_xic (f
);
14052 #ifdef USE_X_TOOLKIT
14053 if (f
->output_data
.x
->widget
)
14055 XtDestroyWidget (f
->output_data
.x
->widget
);
14056 f
->output_data
.x
->widget
= NULL
;
14058 /* Tooltips don't have widgets, only a simple X window, even if
14059 we are using a toolkit. */
14060 else if (FRAME_X_WINDOW (f
))
14061 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
14063 free_frame_menubar (f
);
14064 #else /* !USE_X_TOOLKIT */
14067 /* In the GTK version, tooltips are normal X
14068 frames. We must check and free both types. */
14069 if (FRAME_GTK_OUTER_WIDGET (f
))
14071 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
14072 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
14073 FRAME_GTK_OUTER_WIDGET (f
) = 0;
14075 #endif /* USE_GTK */
14077 if (FRAME_X_WINDOW (f
))
14078 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
14079 #endif /* !USE_X_TOOLKIT */
14081 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
14082 unload_color (f
, f
->output_data
.x
->background_pixel
);
14083 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
14084 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
14085 unload_color (f
, f
->output_data
.x
->border_pixel
);
14086 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
14088 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
14089 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
14090 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
14091 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
14092 #ifdef USE_TOOLKIT_SCROLL_BARS
14093 /* Scrollbar shadow colors. */
14094 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
14095 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
14096 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
14097 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
14098 #endif /* USE_TOOLKIT_SCROLL_BARS */
14099 if (f
->output_data
.x
->white_relief
.allocated_p
)
14100 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
14101 if (f
->output_data
.x
->black_relief
.allocated_p
)
14102 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
14104 if (FRAME_FACE_CACHE (f
))
14105 free_frame_faces (f
);
14108 XFlush (FRAME_X_DISPLAY (f
));
14111 if (f
->output_data
.x
->saved_menu_event
)
14112 xfree (f
->output_data
.x
->saved_menu_event
);
14114 xfree (f
->output_data
.x
);
14115 f
->output_data
.x
= NULL
;
14117 if (f
== dpyinfo
->x_focus_frame
)
14118 dpyinfo
->x_focus_frame
= 0;
14119 if (f
== dpyinfo
->x_focus_event_frame
)
14120 dpyinfo
->x_focus_event_frame
= 0;
14121 if (f
== dpyinfo
->x_highlight_frame
)
14122 dpyinfo
->x_highlight_frame
= 0;
14124 if (f
== dpyinfo
->mouse_face_mouse_frame
)
14126 dpyinfo
->mouse_face_beg_row
14127 = dpyinfo
->mouse_face_beg_col
= -1;
14128 dpyinfo
->mouse_face_end_row
14129 = dpyinfo
->mouse_face_end_col
= -1;
14130 dpyinfo
->mouse_face_window
= Qnil
;
14131 dpyinfo
->mouse_face_deferred_gc
= 0;
14132 dpyinfo
->mouse_face_mouse_frame
= 0;
14139 /* Destroy the X window of frame F. */
14142 x_destroy_window (f
)
14145 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14147 /* If a display connection is dead, don't try sending more
14148 commands to the X server. */
14149 if (dpyinfo
->display
!= 0)
14150 x_free_frame_resources (f
);
14152 dpyinfo
->reference_count
--;
14156 /* Setting window manager hints. */
14158 /* Set the normal size hints for the window manager, for frame F.
14159 FLAGS is the flags word to use--or 0 meaning preserve the flags
14160 that the window now has.
14161 If USER_POSITION is nonzero, we set the USPosition
14162 flag (this is useful when FLAGS is 0).
14163 The GTK version is in gtkutils.c */
14167 x_wm_set_size_hint (f
, flags
, user_position
)
14172 XSizeHints size_hints
;
14174 #ifdef USE_X_TOOLKIT
14177 Dimension widget_width
, widget_height
;
14180 Window window
= FRAME_OUTER_WINDOW (f
);
14182 /* Setting PMaxSize caused various problems. */
14183 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
14185 size_hints
.x
= f
->output_data
.x
->left_pos
;
14186 size_hints
.y
= f
->output_data
.x
->top_pos
;
14188 #ifdef USE_X_TOOLKIT
14189 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
14190 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
14191 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
14192 size_hints
.height
= widget_height
;
14193 size_hints
.width
= widget_width
;
14194 #else /* not USE_X_TOOLKIT */
14195 size_hints
.height
= PIXEL_HEIGHT (f
);
14196 size_hints
.width
= PIXEL_WIDTH (f
);
14197 #endif /* not USE_X_TOOLKIT */
14199 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
14200 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
14201 size_hints
.max_width
14202 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
14203 size_hints
.max_height
14204 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
14206 /* Calculate the base and minimum sizes.
14208 (When we use the X toolkit, we don't do it here.
14209 Instead we copy the values that the widgets are using, below.) */
14210 #ifndef USE_X_TOOLKIT
14212 int base_width
, base_height
;
14213 int min_rows
= 0, min_cols
= 0;
14215 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
14216 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
14218 check_frame_size (f
, &min_rows
, &min_cols
);
14220 /* The window manager uses the base width hints to calculate the
14221 current number of rows and columns in the frame while
14222 resizing; min_width and min_height aren't useful for this
14223 purpose, since they might not give the dimensions for a
14224 zero-row, zero-column frame.
14226 We use the base_width and base_height members if we have
14227 them; otherwise, we set the min_width and min_height members
14228 to the size for a zero x zero frame. */
14231 size_hints
.flags
|= PBaseSize
;
14232 size_hints
.base_width
= base_width
;
14233 size_hints
.base_height
= base_height
;
14234 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
14235 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
14237 size_hints
.min_width
= base_width
;
14238 size_hints
.min_height
= base_height
;
14242 /* If we don't need the old flags, we don't need the old hint at all. */
14245 size_hints
.flags
|= flags
;
14248 #endif /* not USE_X_TOOLKIT */
14251 XSizeHints hints
; /* Sometimes I hate X Windows... */
14252 long supplied_return
;
14256 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
14259 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
14262 #ifdef USE_X_TOOLKIT
14263 size_hints
.base_height
= hints
.base_height
;
14264 size_hints
.base_width
= hints
.base_width
;
14265 size_hints
.min_height
= hints
.min_height
;
14266 size_hints
.min_width
= hints
.min_width
;
14270 size_hints
.flags
|= flags
;
14275 if (hints
.flags
& PSize
)
14276 size_hints
.flags
|= PSize
;
14277 if (hints
.flags
& PPosition
)
14278 size_hints
.flags
|= PPosition
;
14279 if (hints
.flags
& USPosition
)
14280 size_hints
.flags
|= USPosition
;
14281 if (hints
.flags
& USSize
)
14282 size_hints
.flags
|= USSize
;
14286 #ifndef USE_X_TOOLKIT
14291 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
14292 size_hints
.flags
|= PWinGravity
;
14296 size_hints
.flags
&= ~ PPosition
;
14297 size_hints
.flags
|= USPosition
;
14299 #endif /* PWinGravity */
14302 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
14304 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
14307 #endif /* not USE_GTK */
14309 /* Used for IconicState or NormalState */
14312 x_wm_set_window_state (f
, state
)
14316 #ifdef USE_X_TOOLKIT
14319 XtSetArg (al
[0], XtNinitialState
, state
);
14320 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
14321 #else /* not USE_X_TOOLKIT */
14322 Window window
= FRAME_X_WINDOW (f
);
14324 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
14325 f
->output_data
.x
->wm_hints
.initial_state
= state
;
14327 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
14328 #endif /* not USE_X_TOOLKIT */
14332 x_wm_set_icon_pixmap (f
, pixmap_id
)
14336 Pixmap icon_pixmap
;
14338 #ifndef USE_X_TOOLKIT
14339 Window window
= FRAME_OUTER_WINDOW (f
);
14344 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
14345 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
14349 /* It seems there is no way to turn off use of an icon pixmap.
14350 The following line does it, only if no icon has yet been created,
14351 for some window managers. But with mwm it crashes.
14352 Some people say it should clear the IconPixmapHint bit in this case,
14353 but that doesn't work, and the X consortium said it isn't the
14354 right thing at all. Since there is no way to win,
14355 best to explicitly give up. */
14357 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
14363 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
14367 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
14368 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
14371 #else /* not USE_X_TOOLKIT */
14373 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
14374 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
14376 #endif /* not USE_X_TOOLKIT */
14380 x_wm_set_icon_position (f
, icon_x
, icon_y
)
14382 int icon_x
, icon_y
;
14384 #ifdef USE_X_TOOLKIT
14385 Window window
= XtWindow (f
->output_data
.x
->widget
);
14387 Window window
= FRAME_X_WINDOW (f
);
14390 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
14391 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
14392 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
14394 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
14398 /***********************************************************************
14400 ***********************************************************************/
14402 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
14405 x_get_font_info (f
, font_idx
)
14409 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
14413 /* Return a list of names of available fonts matching PATTERN on frame F.
14415 If SIZE is > 0, it is the size (maximum bounds width) of fonts
14418 SIZE < 0 means include scalable fonts.
14420 Frame F null means we have not yet created any frame on X, and
14421 consult the first display in x_display_list. MAXNAMES sets a limit
14422 on how many fonts to match. */
14425 x_list_fonts (f
, pattern
, size
, maxnames
)
14427 Lisp_Object pattern
;
14431 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
14432 Lisp_Object tem
, second_best
;
14433 struct x_display_info
*dpyinfo
14434 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
14435 Display
*dpy
= dpyinfo
->display
;
14436 int try_XLoadQueryFont
= 0;
14438 int allow_scalable_fonts_p
= 0;
14442 allow_scalable_fonts_p
= 1;
14446 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
14447 if (NILP (patterns
))
14448 patterns
= Fcons (pattern
, Qnil
);
14450 if (maxnames
== 1 && !size
)
14451 /* We can return any single font matching PATTERN. */
14452 try_XLoadQueryFont
= 1;
14454 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
14457 char **names
= NULL
;
14459 pattern
= XCAR (patterns
);
14460 /* See if we cached the result for this particular query.
14461 The cache is an alist of the form:
14462 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
14463 tem
= XCDR (dpyinfo
->name_list_element
);
14464 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
14465 allow_scalable_fonts_p
? Qt
: Qnil
);
14466 list
= Fassoc (key
, tem
);
14469 list
= Fcdr_safe (list
);
14470 /* We have a cashed list. Don't have to get the list again. */
14474 /* At first, put PATTERN in the cache. */
14477 count
= x_catch_errors (dpy
);
14479 if (try_XLoadQueryFont
)
14482 unsigned long value
;
14484 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
14485 if (x_had_errors_p (dpy
))
14487 /* This error is perhaps due to insufficient memory on X
14488 server. Let's just ignore it. */
14490 x_clear_errors (dpy
);
14494 && XGetFontProperty (font
, XA_FONT
, &value
))
14496 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
14497 int len
= strlen (name
);
14500 /* If DXPC (a Differential X Protocol Compressor)
14501 Ver.3.7 is running, XGetAtomName will return null
14502 string. We must avoid such a name. */
14504 try_XLoadQueryFont
= 0;
14508 names
= (char **) alloca (sizeof (char *));
14509 /* Some systems only allow alloca assigned to a
14511 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
14512 bcopy (name
, names
[0], len
+ 1);
14517 try_XLoadQueryFont
= 0;
14520 XFreeFont (dpy
, font
);
14523 if (!try_XLoadQueryFont
)
14525 /* We try at least 10 fonts because XListFonts will return
14526 auto-scaled fonts at the head. */
14527 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
14529 if (x_had_errors_p (dpy
))
14531 /* This error is perhaps due to insufficient memory on X
14532 server. Let's just ignore it. */
14534 x_clear_errors (dpy
);
14538 x_uncatch_errors (dpy
, count
);
14545 /* Make a list of all the fonts we got back.
14546 Store that in the font cache for the display. */
14547 for (i
= 0; i
< num_fonts
; i
++)
14550 char *p
= names
[i
];
14551 int average_width
= -1, dashes
= 0;
14553 /* Count the number of dashes in NAMES[I]. If there are
14554 14 dashes, and the field value following 12th dash
14555 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
14556 is usually too ugly to be used for editing. Let's
14562 if (dashes
== 7) /* PIXEL_SIZE field */
14564 else if (dashes
== 12) /* AVERAGE_WIDTH field */
14565 average_width
= atoi (p
);
14568 if (allow_scalable_fonts_p
14569 || dashes
< 14 || average_width
!= 0)
14571 tem
= build_string (names
[i
]);
14572 if (NILP (Fassoc (tem
, list
)))
14574 if (STRINGP (Vx_pixel_size_width_font_regexp
)
14575 && ((fast_c_string_match_ignore_case
14576 (Vx_pixel_size_width_font_regexp
, names
[i
]))
14578 /* We can set the value of PIXEL_SIZE to the
14579 width of this font. */
14580 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
14582 /* For the moment, width is not known. */
14583 list
= Fcons (Fcons (tem
, Qnil
), list
);
14588 if (!try_XLoadQueryFont
)
14591 XFreeFontNames (names
);
14596 /* Now store the result in the cache. */
14597 XSETCDR (dpyinfo
->name_list_element
,
14598 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
14601 if (NILP (list
)) continue; /* Try the remaining alternatives. */
14603 newlist
= second_best
= Qnil
;
14604 /* Make a list of the fonts that have the right width. */
14605 for (; CONSP (list
); list
= XCDR (list
))
14611 if (!CONSP (tem
) || NILP (XCAR (tem
)))
14615 newlist
= Fcons (XCAR (tem
), newlist
);
14619 if (!INTEGERP (XCDR (tem
)))
14621 /* Since we have not yet known the size of this font, we
14622 must try slow function call XLoadQueryFont. */
14623 XFontStruct
*thisinfo
;
14626 count
= x_catch_errors (dpy
);
14627 thisinfo
= XLoadQueryFont (dpy
,
14628 SDATA (XCAR (tem
)));
14629 if (x_had_errors_p (dpy
))
14631 /* This error is perhaps due to insufficient memory on X
14632 server. Let's just ignore it. */
14634 x_clear_errors (dpy
);
14636 x_uncatch_errors (dpy
, count
);
14642 (thisinfo
->min_bounds
.width
== 0
14644 : make_number (thisinfo
->max_bounds
.width
)));
14646 XFreeFont (dpy
, thisinfo
);
14650 /* For unknown reason, the previous call of XListFont had
14651 returned a font which can't be opened. Record the size
14652 as 0 not to try to open it again. */
14653 XSETCDR (tem
, make_number (0));
14656 found_size
= XINT (XCDR (tem
));
14657 if (found_size
== size
)
14658 newlist
= Fcons (XCAR (tem
), newlist
);
14659 else if (found_size
> 0)
14661 if (NILP (second_best
))
14663 else if (found_size
< size
)
14665 if (XINT (XCDR (second_best
)) > size
14666 || XINT (XCDR (second_best
)) < found_size
)
14671 if (XINT (XCDR (second_best
)) > size
14672 && XINT (XCDR (second_best
)) > found_size
)
14677 if (!NILP (newlist
))
14679 else if (!NILP (second_best
))
14681 newlist
= Fcons (XCAR (second_best
), Qnil
);
14692 /* Check that FONT is valid on frame F. It is if it can be found in F's
14696 x_check_font (f
, font
)
14701 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14703 xassert (font
!= NULL
);
14705 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14706 if (dpyinfo
->font_table
[i
].name
14707 && font
== dpyinfo
->font_table
[i
].font
)
14710 xassert (i
< dpyinfo
->n_fonts
);
14713 #endif /* GLYPH_DEBUG != 0 */
14715 /* Set *W to the minimum width, *H to the minimum font height of FONT.
14716 Note: There are (broken) X fonts out there with invalid XFontStruct
14717 min_bounds contents. For example, handa@etl.go.jp reports that
14718 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
14719 have font->min_bounds.width == 0. */
14722 x_font_min_bounds (font
, w
, h
)
14726 *h
= FONT_HEIGHT (font
);
14727 *w
= font
->min_bounds
.width
;
14729 /* Try to handle the case where FONT->min_bounds has invalid
14730 contents. Since the only font known to have invalid min_bounds
14731 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
14733 *w
= font
->max_bounds
.width
;
14737 /* Compute the smallest character width and smallest font height over
14738 all fonts available on frame F. Set the members smallest_char_width
14739 and smallest_font_height in F's x_display_info structure to
14740 the values computed. Value is non-zero if smallest_font_height or
14741 smallest_char_width become smaller than they were before. */
14744 x_compute_min_glyph_bounds (f
)
14748 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14750 int old_width
= dpyinfo
->smallest_char_width
;
14751 int old_height
= dpyinfo
->smallest_font_height
;
14753 dpyinfo
->smallest_font_height
= 100000;
14754 dpyinfo
->smallest_char_width
= 100000;
14756 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14757 if (dpyinfo
->font_table
[i
].name
)
14759 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
14762 font
= (XFontStruct
*) fontp
->font
;
14763 xassert (font
!= (XFontStruct
*) ~0);
14764 x_font_min_bounds (font
, &w
, &h
);
14766 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
14767 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
14770 xassert (dpyinfo
->smallest_char_width
> 0
14771 && dpyinfo
->smallest_font_height
> 0);
14773 return (dpyinfo
->n_fonts
== 1
14774 || dpyinfo
->smallest_char_width
< old_width
14775 || dpyinfo
->smallest_font_height
< old_height
);
14779 /* Load font named FONTNAME of the size SIZE for frame F, and return a
14780 pointer to the structure font_info while allocating it dynamically.
14781 If SIZE is 0, load any size of font.
14782 If loading is failed, return NULL. */
14785 x_load_font (f
, fontname
, size
)
14787 register char *fontname
;
14790 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14791 Lisp_Object font_names
;
14794 /* Get a list of all the fonts that match this name. Once we
14795 have a list of matching fonts, we compare them against the fonts
14796 we already have by comparing names. */
14797 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
14799 if (!NILP (font_names
))
14804 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14805 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
14806 if (dpyinfo
->font_table
[i
].name
14807 && (!strcmp (dpyinfo
->font_table
[i
].name
,
14808 SDATA (XCAR (tail
)))
14809 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
14810 SDATA (XCAR (tail
)))))
14811 return (dpyinfo
->font_table
+ i
);
14814 /* Load the font and add it to the table. */
14818 struct font_info
*fontp
;
14819 unsigned long value
;
14822 /* If we have found fonts by x_list_font, load one of them. If
14823 not, we still try to load a font by the name given as FONTNAME
14824 because XListFonts (called in x_list_font) of some X server has
14825 a bug of not finding a font even if the font surely exists and
14826 is loadable by XLoadQueryFont. */
14827 if (size
> 0 && !NILP (font_names
))
14828 fontname
= (char *) SDATA (XCAR (font_names
));
14831 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
14832 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
14833 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
14835 /* This error is perhaps due to insufficient memory on X
14836 server. Let's just ignore it. */
14838 x_clear_errors (FRAME_X_DISPLAY (f
));
14840 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
14845 /* Find a free slot in the font table. */
14846 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14847 if (dpyinfo
->font_table
[i
].name
== NULL
)
14850 /* If no free slot found, maybe enlarge the font table. */
14851 if (i
== dpyinfo
->n_fonts
14852 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
14855 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
14856 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
14857 dpyinfo
->font_table
14858 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
14861 fontp
= dpyinfo
->font_table
+ i
;
14862 if (i
== dpyinfo
->n_fonts
)
14863 ++dpyinfo
->n_fonts
;
14865 /* Now fill in the slots of *FONTP. */
14867 fontp
->font
= font
;
14868 fontp
->font_idx
= i
;
14869 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
14870 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
14872 /* Try to get the full name of FONT. Put it in FULL_NAME. */
14874 if (XGetFontProperty (font
, XA_FONT
, &value
))
14876 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
14880 /* Count the number of dashes in the "full name".
14881 If it is too few, this isn't really the font's full name,
14883 In X11R4, the fonts did not come with their canonical names
14894 full_name
= (char *) xmalloc (p
- name
+ 1);
14895 bcopy (name
, full_name
, p
- name
+ 1);
14901 if (full_name
!= 0)
14902 fontp
->full_name
= full_name
;
14904 fontp
->full_name
= fontp
->name
;
14906 fontp
->size
= font
->max_bounds
.width
;
14907 fontp
->height
= FONT_HEIGHT (font
);
14909 if (NILP (font_names
))
14911 /* We come here because of a bug of XListFonts mentioned at
14912 the head of this block. Let's store this information in
14913 the cache for x_list_fonts. */
14914 Lisp_Object lispy_name
= build_string (fontname
);
14915 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
14916 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
14919 XSETCDR (dpyinfo
->name_list_element
,
14921 Fcons (Fcons (lispy_full_name
,
14922 make_number (fontp
->size
)),
14924 XCDR (dpyinfo
->name_list_element
)));
14927 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
14929 XSETCDR (dpyinfo
->name_list_element
,
14931 Fcons (Fcons (lispy_full_name
,
14932 make_number (fontp
->size
)),
14934 XCDR (dpyinfo
->name_list_element
)));
14938 /* The slot `encoding' specifies how to map a character
14939 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
14940 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
14941 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
14942 2:0xA020..0xFF7F). For the moment, we don't know which charset
14943 uses this font. So, we set information in fontp->encoding[1]
14944 which is never used by any charset. If mapping can't be
14945 decided, set FONT_ENCODING_NOT_DECIDED. */
14947 = (font
->max_byte1
== 0
14949 ? (font
->min_char_or_byte2
< 0x80
14950 ? (font
->max_char_or_byte2
< 0x80
14951 ? 0 /* 0x20..0x7F */
14952 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
14953 : 1) /* 0xA0..0xFF */
14955 : (font
->min_byte1
< 0x80
14956 ? (font
->max_byte1
< 0x80
14957 ? (font
->min_char_or_byte2
< 0x80
14958 ? (font
->max_char_or_byte2
< 0x80
14959 ? 0 /* 0x2020..0x7F7F */
14960 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
14961 : 3) /* 0x20A0..0x7FFF */
14962 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
14963 : (font
->min_char_or_byte2
< 0x80
14964 ? (font
->max_char_or_byte2
< 0x80
14965 ? 2 /* 0xA020..0xFF7F */
14966 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
14967 : 1))); /* 0xA0A0..0xFFFF */
14969 fontp
->baseline_offset
14970 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
14971 ? (long) value
: 0);
14972 fontp
->relative_compose
14973 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
14974 ? (long) value
: 0);
14975 fontp
->default_ascent
14976 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
14977 ? (long) value
: 0);
14979 /* Set global flag fonts_changed_p to non-zero if the font loaded
14980 has a character with a smaller width than any other character
14981 before, or if the font loaded has a smaller height than any
14982 other font loaded before. If this happens, it will make a
14983 glyph matrix reallocation necessary. */
14984 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
14991 /* Return a pointer to struct font_info of a font named FONTNAME for
14992 frame F. If no such font is loaded, return NULL. */
14995 x_query_font (f
, fontname
)
14997 register char *fontname
;
14999 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
15002 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
15003 if (dpyinfo
->font_table
[i
].name
15004 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
15005 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
15006 return (dpyinfo
->font_table
+ i
);
15011 /* Find a CCL program for a font specified by FONTP, and set the member
15012 `encoder' of the structure. */
15015 x_find_ccl_program (fontp
)
15016 struct font_info
*fontp
;
15018 Lisp_Object list
, elt
;
15021 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
15025 && STRINGP (XCAR (elt
))
15026 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
15028 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
15035 struct ccl_program
*ccl
15036 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
15038 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
15041 fontp
->font_encoder
= ccl
;
15047 /***********************************************************************
15049 ***********************************************************************/
15051 #ifdef USE_X_TOOLKIT
15052 static XrmOptionDescRec emacs_options
[] = {
15053 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
15054 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
15056 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
15057 XrmoptionSepArg
, NULL
},
15058 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
15060 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
15061 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
15062 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
15063 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
15064 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
15065 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
15066 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
15068 #endif /* USE_X_TOOLKIT */
15070 static int x_initialized
;
15072 #ifdef MULTI_KBOARD
15073 /* Test whether two display-name strings agree up to the dot that separates
15074 the screen number from the server number. */
15076 same_x_server (name1
, name2
)
15077 const char *name1
, *name2
;
15079 int seen_colon
= 0;
15080 const unsigned char *system_name
= SDATA (Vsystem_name
);
15081 int system_name_length
= strlen (system_name
);
15082 int length_until_period
= 0;
15084 while (system_name
[length_until_period
] != 0
15085 && system_name
[length_until_period
] != '.')
15086 length_until_period
++;
15088 /* Treat `unix' like an empty host name. */
15089 if (! strncmp (name1
, "unix:", 5))
15091 if (! strncmp (name2
, "unix:", 5))
15093 /* Treat this host's name like an empty host name. */
15094 if (! strncmp (name1
, system_name
, system_name_length
)
15095 && name1
[system_name_length
] == ':')
15096 name1
+= system_name_length
;
15097 if (! strncmp (name2
, system_name
, system_name_length
)
15098 && name2
[system_name_length
] == ':')
15099 name2
+= system_name_length
;
15100 /* Treat this host's domainless name like an empty host name. */
15101 if (! strncmp (name1
, system_name
, length_until_period
)
15102 && name1
[length_until_period
] == ':')
15103 name1
+= length_until_period
;
15104 if (! strncmp (name2
, system_name
, length_until_period
)
15105 && name2
[length_until_period
] == ':')
15106 name2
+= length_until_period
;
15108 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
15112 if (seen_colon
&& *name1
== '.')
15116 && (*name1
== '.' || *name1
== '\0')
15117 && (*name2
== '.' || *name2
== '\0'));
15121 struct x_display_info
*
15122 x_term_init (display_name
, xrm_option
, resource_name
)
15123 Lisp_Object display_name
;
15125 char *resource_name
;
15129 struct x_display_info
*dpyinfo
;
15134 if (!x_initialized
)
15142 #define NUM_ARGV 10
15144 char *argv
[NUM_ARGV
];
15145 char **argv2
= argv
;
15148 /* GTK 2.0 can only handle one display, GTK 2.2 can handle more
15149 than one, but this remains to be implemented. */
15150 if (x_initialized
> 1)
15155 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
15159 argv
[argc
++] = initial_argv
[0];
15161 if (! NILP (display_name
))
15163 argv
[argc
++] = "--display";
15164 argv
[argc
++] = SDATA (display_name
);
15167 argv
[argc
++] = "--name";
15168 argv
[argc
++] = resource_name
;
15170 gtk_init (&argc
, &argv2
);
15172 /* gtk_init does set_locale. We must fix locale after calling it. */
15176 dpy
= GDK_DISPLAY ();
15178 /* NULL window -> events for all windows go to our function */
15179 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
15181 /* Load our own gtkrc if it exists. */
15183 struct gcpro gcpro1
, gcpro2
;
15184 char *file
= "~/.emacs.d/gtkrc";
15185 Lisp_Object s
, abs_file
;
15187 GCPRO2 (str
, abs_file
);
15188 s
= make_string (file
, strlen (file
));
15189 abs_file
= Fexpand_file_name(s
, Qnil
);
15191 if (! NILP (abs_file
) && Ffile_readable_p (abs_file
))
15192 gtk_rc_parse (SDATA (abs_file
));
15197 XSetErrorHandler (x_error_handler
);
15198 XSetIOErrorHandler (x_io_error_quitter
);
15200 #else /* not USE_GTK */
15201 #ifdef USE_X_TOOLKIT
15202 /* weiner@footloose.sps.mot.com reports that this causes
15204 X protocol error: BadAtom (invalid Atom parameter)
15205 on protocol request 18skiloaf.
15206 So let's not use it until R6. */
15207 #ifdef HAVE_X11XTR6
15208 XtSetLanguageProc (NULL
, NULL
, NULL
);
15219 argv
[argc
++] = "-xrm";
15220 argv
[argc
++] = xrm_option
;
15222 turn_on_atimers (0);
15223 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
15224 resource_name
, EMACS_CLASS
,
15225 emacs_options
, XtNumber (emacs_options
),
15227 turn_on_atimers (1);
15229 #ifdef HAVE_X11XTR6
15230 /* I think this is to compensate for XtSetLanguageProc. */
15235 #else /* not USE_X_TOOLKIT */
15237 XSetLocaleModifiers ("");
15239 dpy
= XOpenDisplay (SDATA (display_name
));
15240 #endif /* not USE_X_TOOLKIT */
15241 #endif /* not USE_GTK*/
15243 /* Detect failure. */
15250 /* We have definitely succeeded. Record the new connection. */
15252 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
15253 bzero (dpyinfo
, sizeof *dpyinfo
);
15255 #ifdef MULTI_KBOARD
15257 struct x_display_info
*share
;
15260 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
15261 share
= share
->next
, tail
= XCDR (tail
))
15262 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
15263 SDATA (display_name
)))
15266 dpyinfo
->kboard
= share
->kboard
;
15269 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
15270 init_kboard (dpyinfo
->kboard
);
15271 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
15273 char *vendor
= ServerVendor (dpy
);
15275 dpyinfo
->kboard
->Vsystem_key_alist
15276 = call1 (Qvendor_specific_keysyms
,
15277 build_string (vendor
? vendor
: ""));
15281 dpyinfo
->kboard
->next_kboard
= all_kboards
;
15282 all_kboards
= dpyinfo
->kboard
;
15283 /* Don't let the initial kboard remain current longer than necessary.
15284 That would cause problems if a file loaded on startup tries to
15285 prompt in the mini-buffer. */
15286 if (current_kboard
== initial_kboard
)
15287 current_kboard
= dpyinfo
->kboard
;
15289 dpyinfo
->kboard
->reference_count
++;
15293 /* Put this display on the chain. */
15294 dpyinfo
->next
= x_display_list
;
15295 x_display_list
= dpyinfo
;
15297 /* Put it on x_display_name_list as well, to keep them parallel. */
15298 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
15299 x_display_name_list
);
15300 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
15302 dpyinfo
->display
= dpy
;
15305 XSetAfterFunction (x_current_display
, x_trace_wire
);
15309 = (char *) xmalloc (SBYTES (Vinvocation_name
)
15310 + SBYTES (Vsystem_name
)
15312 sprintf (dpyinfo
->x_id_name
, "%s@%s",
15313 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
15315 /* Figure out which modifier bits mean what. */
15316 x_find_modifier_meanings (dpyinfo
);
15318 /* Get the scroll bar cursor. */
15319 dpyinfo
->vertical_scroll_bar_cursor
15320 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
15322 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
15323 resource_name
, EMACS_CLASS
);
15324 #ifdef HAVE_XRMSETDATABASE
15325 XrmSetDatabase (dpyinfo
->display
, xrdb
);
15327 dpyinfo
->display
->db
= xrdb
;
15329 /* Put the rdb where we can find it in a way that works on
15331 dpyinfo
->xrdb
= xrdb
;
15333 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
15334 DefaultScreen (dpyinfo
->display
));
15335 select_visual (dpyinfo
);
15336 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
15337 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
15338 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
15339 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
15340 dpyinfo
->grabbed
= 0;
15341 dpyinfo
->reference_count
= 0;
15342 dpyinfo
->icon_bitmap_id
= -1;
15343 dpyinfo
->font_table
= NULL
;
15344 dpyinfo
->n_fonts
= 0;
15345 dpyinfo
->font_table_size
= 0;
15346 dpyinfo
->bitmaps
= 0;
15347 dpyinfo
->bitmaps_size
= 0;
15348 dpyinfo
->bitmaps_last
= 0;
15349 dpyinfo
->scratch_cursor_gc
= 0;
15350 dpyinfo
->mouse_face_mouse_frame
= 0;
15351 dpyinfo
->mouse_face_deferred_gc
= 0;
15352 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
15353 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
15354 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
15355 dpyinfo
->mouse_face_window
= Qnil
;
15356 dpyinfo
->mouse_face_overlay
= Qnil
;
15357 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
15358 dpyinfo
->mouse_face_defer
= 0;
15359 dpyinfo
->mouse_face_hidden
= 0;
15360 dpyinfo
->x_focus_frame
= 0;
15361 dpyinfo
->x_focus_event_frame
= 0;
15362 dpyinfo
->x_highlight_frame
= 0;
15363 dpyinfo
->image_cache
= make_image_cache ();
15365 /* See if a private colormap is requested. */
15366 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
15368 if (dpyinfo
->visual
->class == PseudoColor
)
15371 value
= display_x_get_resource (dpyinfo
,
15372 build_string ("privateColormap"),
15373 build_string ("PrivateColormap"),
15375 if (STRINGP (value
)
15376 && (!strcmp (SDATA (value
), "true")
15377 || !strcmp (SDATA (value
), "on")))
15378 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
15382 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
15383 dpyinfo
->visual
, AllocNone
);
15386 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
15387 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
15388 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
15389 dpyinfo
->resy
= pixels
* 25.4 / mm
;
15390 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
15391 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
15392 dpyinfo
->resx
= pixels
* 25.4 / mm
;
15395 dpyinfo
->Xatom_wm_protocols
15396 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
15397 dpyinfo
->Xatom_wm_take_focus
15398 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
15399 dpyinfo
->Xatom_wm_save_yourself
15400 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
15401 dpyinfo
->Xatom_wm_delete_window
15402 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
15403 dpyinfo
->Xatom_wm_change_state
15404 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
15405 dpyinfo
->Xatom_wm_configure_denied
15406 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
15407 dpyinfo
->Xatom_wm_window_moved
15408 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
15409 dpyinfo
->Xatom_editres
15410 = XInternAtom (dpyinfo
->display
, "Editres", False
);
15411 dpyinfo
->Xatom_CLIPBOARD
15412 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
15413 dpyinfo
->Xatom_TIMESTAMP
15414 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
15415 dpyinfo
->Xatom_TEXT
15416 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
15417 dpyinfo
->Xatom_COMPOUND_TEXT
15418 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
15419 dpyinfo
->Xatom_UTF8_STRING
15420 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
15421 dpyinfo
->Xatom_DELETE
15422 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
15423 dpyinfo
->Xatom_MULTIPLE
15424 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
15425 dpyinfo
->Xatom_INCR
15426 = XInternAtom (dpyinfo
->display
, "INCR", False
);
15427 dpyinfo
->Xatom_EMACS_TMP
15428 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
15429 dpyinfo
->Xatom_TARGETS
15430 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
15431 dpyinfo
->Xatom_NULL
15432 = XInternAtom (dpyinfo
->display
, "NULL", False
);
15433 dpyinfo
->Xatom_ATOM_PAIR
15434 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
15435 /* For properties of font. */
15436 dpyinfo
->Xatom_PIXEL_SIZE
15437 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
15438 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
15439 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
15440 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
15441 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
15442 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
15443 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
15445 /* Ghostscript support. */
15446 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
15447 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
15449 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
15452 dpyinfo
->cut_buffers_initialized
= 0;
15454 connection
= ConnectionNumber (dpyinfo
->display
);
15455 dpyinfo
->connection
= connection
;
15460 null_bits
[0] = 0x00;
15462 dpyinfo
->null_pixel
15463 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
15464 null_bits
, 1, 1, (long) 0, (long) 0,
15469 extern int gray_bitmap_width
, gray_bitmap_height
;
15470 extern char *gray_bitmap_bits
;
15472 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
15474 gray_bitmap_width
, gray_bitmap_height
,
15475 (unsigned long) 1, (unsigned long) 0, 1);
15479 xim_initialize (dpyinfo
, resource_name
);
15482 #ifdef subprocesses
15483 /* This is only needed for distinguishing keyboard and process input. */
15484 if (connection
!= 0)
15485 add_keyboard_wait_descriptor (connection
);
15488 #ifndef F_SETOWN_BUG
15490 #ifdef F_SETOWN_SOCK_NEG
15491 /* stdin is a socket here */
15492 fcntl (connection
, F_SETOWN
, -getpid ());
15493 #else /* ! defined (F_SETOWN_SOCK_NEG) */
15494 fcntl (connection
, F_SETOWN
, getpid ());
15495 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
15496 #endif /* ! defined (F_SETOWN) */
15497 #endif /* F_SETOWN_BUG */
15500 if (interrupt_input
)
15501 init_sigio (connection
);
15502 #endif /* ! defined (SIGIO) */
15505 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
15506 /* Make sure that we have a valid font for dialog boxes
15507 so that Xt does not crash. */
15509 Display
*dpy
= dpyinfo
->display
;
15510 XrmValue d
, fr
, to
;
15514 d
.addr
= (XPointer
)&dpy
;
15515 d
.size
= sizeof (Display
*);
15516 fr
.addr
= XtDefaultFont
;
15517 fr
.size
= sizeof (XtDefaultFont
);
15518 to
.size
= sizeof (Font
*);
15519 to
.addr
= (XPointer
)&font
;
15520 count
= x_catch_errors (dpy
);
15521 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
15523 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
15524 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
15525 x_uncatch_errors (dpy
, count
);
15530 /* See if we should run in synchronous mode. This is useful
15531 for debugging X code. */
15534 value
= display_x_get_resource (dpyinfo
,
15535 build_string ("synchronous"),
15536 build_string ("Synchronous"),
15538 if (STRINGP (value
)
15539 && (!strcmp (SDATA (value
), "true")
15540 || !strcmp (SDATA (value
), "on")))
15541 XSynchronize (dpyinfo
->display
, True
);
15549 /* Get rid of display DPYINFO, assuming all frames are already gone,
15550 and without sending any more commands to the X server. */
15553 x_delete_display (dpyinfo
)
15554 struct x_display_info
*dpyinfo
;
15556 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
15558 /* Discard this display from x_display_name_list and x_display_list.
15559 We can't use Fdelq because that can quit. */
15560 if (! NILP (x_display_name_list
)
15561 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
15562 x_display_name_list
= XCDR (x_display_name_list
);
15567 tail
= x_display_name_list
;
15568 while (CONSP (tail
) && CONSP (XCDR (tail
)))
15570 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
15572 XSETCDR (tail
, XCDR (XCDR (tail
)));
15575 tail
= XCDR (tail
);
15579 if (next_noop_dpyinfo
== dpyinfo
)
15580 next_noop_dpyinfo
= dpyinfo
->next
;
15582 if (x_display_list
== dpyinfo
)
15583 x_display_list
= dpyinfo
->next
;
15586 struct x_display_info
*tail
;
15588 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
15589 if (tail
->next
== dpyinfo
)
15590 tail
->next
= tail
->next
->next
;
15593 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
15594 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
15595 XrmDestroyDatabase (dpyinfo
->xrdb
);
15598 #ifdef MULTI_KBOARD
15599 if (--dpyinfo
->kboard
->reference_count
== 0)
15600 delete_kboard (dpyinfo
->kboard
);
15604 xim_close_dpy (dpyinfo
);
15607 xfree (dpyinfo
->font_table
);
15608 xfree (dpyinfo
->x_id_name
);
15609 xfree (dpyinfo
->color_cells
);
15614 /* Set up use of X before we make the first connection. */
15616 static struct redisplay_interface x_redisplay_interface
=
15621 x_clear_end_of_line
,
15623 x_after_update_window_line
,
15624 x_update_window_begin
,
15625 x_update_window_end
,
15628 x_clear_mouse_face
,
15629 x_get_glyph_overhangs
,
15630 x_fix_overlapping_area
15636 rif
= &x_redisplay_interface
;
15638 clear_frame_hook
= x_clear_frame
;
15639 ins_del_lines_hook
= x_ins_del_lines
;
15640 delete_glyphs_hook
= x_delete_glyphs
;
15641 ring_bell_hook
= XTring_bell
;
15642 reset_terminal_modes_hook
= XTreset_terminal_modes
;
15643 set_terminal_modes_hook
= XTset_terminal_modes
;
15644 update_begin_hook
= x_update_begin
;
15645 update_end_hook
= x_update_end
;
15646 set_terminal_window_hook
= XTset_terminal_window
;
15647 read_socket_hook
= XTread_socket
;
15648 frame_up_to_date_hook
= XTframe_up_to_date
;
15649 mouse_position_hook
= XTmouse_position
;
15650 frame_rehighlight_hook
= XTframe_rehighlight
;
15651 frame_raise_lower_hook
= XTframe_raise_lower
;
15652 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
15653 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
15654 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
15655 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
15656 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
15658 scroll_region_ok
= 1; /* we'll scroll partial frames */
15659 char_ins_del_ok
= 1;
15660 line_ins_del_ok
= 1; /* we'll just blt 'em */
15661 fast_clear_end_of_line
= 1; /* X does this well */
15662 memory_below_frame
= 0; /* we don't remember what scrolls
15667 last_tool_bar_item
= -1;
15668 any_help_event_p
= 0;
15670 /* Try to use interrupt input; if we can't, then start polling. */
15671 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
15673 #ifdef USE_X_TOOLKIT
15674 XtToolkitInitialize ();
15676 Xt_app_con
= XtCreateApplicationContext ();
15678 /* Register a converter from strings to pixels, which uses
15679 Emacs' color allocation infrastructure. */
15680 XtAppSetTypeConverter (Xt_app_con
,
15681 XtRString
, XtRPixel
, cvt_string_to_pixel
,
15682 cvt_string_to_pixel_args
,
15683 XtNumber (cvt_string_to_pixel_args
),
15684 XtCacheByDisplay
, cvt_pixel_dtor
);
15686 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
15688 /* Install an asynchronous timer that processes Xt timeout events
15689 every 0.1s. This is necessary because some widget sets use
15690 timeouts internally, for example the LessTif menu bar, or the
15691 Xaw3d scroll bar. When Xt timouts aren't processed, these
15692 widgets don't behave normally. */
15694 EMACS_TIME interval
;
15695 EMACS_SET_SECS_USECS (interval
, 0, 100000);
15696 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
15700 #ifdef USE_TOOLKIT_SCROLL_BARS
15702 xaw3d_arrow_scroll
= False
;
15703 xaw3d_pick_top
= True
;
15707 /* Note that there is no real way portable across R3/R4 to get the
15708 original error handler. */
15709 XSetErrorHandler (x_error_handler
);
15710 XSetIOErrorHandler (x_io_error_quitter
);
15712 /* Disable Window Change signals; they are handled by X events. */
15714 signal (SIGWINCH
, SIG_DFL
);
15715 #endif /* SIGWINCH */
15717 signal (SIGPIPE
, x_connection_signal
);
15720 x_session_initialize ();
15728 staticpro (&x_error_message_string
);
15729 x_error_message_string
= Qnil
;
15731 staticpro (&x_display_name_list
);
15732 x_display_name_list
= Qnil
;
15734 staticpro (&last_mouse_scroll_bar
);
15735 last_mouse_scroll_bar
= Qnil
;
15737 staticpro (&Qvendor_specific_keysyms
);
15738 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
15740 staticpro (&Qutf_8
);
15741 Qutf_8
= intern ("utf-8");
15742 staticpro (&Qlatin_1
);
15743 Qlatin_1
= intern ("latin-1");
15745 staticpro (&last_mouse_press_frame
);
15746 last_mouse_press_frame
= Qnil
;
15749 staticpro (&help_echo
);
15750 help_echo_object
= Qnil
;
15751 staticpro (&help_echo_object
);
15752 help_echo_window
= Qnil
;
15753 staticpro (&help_echo_window
);
15754 previous_help_echo
= Qnil
;
15755 staticpro (&previous_help_echo
);
15756 help_echo_pos
= -1;
15758 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
15759 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
15760 mouse_autoselect_window
= 0;
15762 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
15763 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
15764 For example, if a block cursor is over a tab, it will be drawn as
15765 wide as that tab on the display. */);
15766 x_stretch_cursor_p
= 0;
15768 DEFVAR_BOOL ("x-use-underline-position-properties",
15769 &x_use_underline_position_properties
,
15770 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
15771 nil means ignore them. If you encounter fonts with bogus
15772 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
15773 to 4.1, set this to nil. */);
15774 x_use_underline_position_properties
= 1;
15776 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
15777 doc
: /* What X toolkit scroll bars Emacs uses.
15778 A value of nil means Emacs doesn't use X toolkit scroll bars.
15779 Otherwise, value is a symbol describing the X toolkit. */);
15780 #ifdef USE_TOOLKIT_SCROLL_BARS
15782 Vx_toolkit_scroll_bars
= intern ("motif");
15783 #elif defined HAVE_XAW3D
15784 Vx_toolkit_scroll_bars
= intern ("xaw3d");
15786 Vx_toolkit_scroll_bars
= intern ("gtk");
15788 Vx_toolkit_scroll_bars
= intern ("xaw");
15791 Vx_toolkit_scroll_bars
= Qnil
;
15794 staticpro (&last_mouse_motion_frame
);
15795 last_mouse_motion_frame
= Qnil
;
15797 Qmodifier_value
= intern ("modifier-value");
15798 Qalt
= intern ("alt");
15799 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
15800 Qhyper
= intern ("hyper");
15801 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
15802 Qmeta
= intern ("meta");
15803 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
15804 Qsuper
= intern ("super");
15805 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
15807 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
15808 doc
: /* Which keys Emacs uses for the alt modifier.
15809 This should be one of the symbols `alt', `hyper', `meta', `super'.
15810 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
15811 is nil, which is the same as `alt'. */);
15812 Vx_alt_keysym
= Qnil
;
15814 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
15815 doc
: /* Which keys Emacs uses for the hyper modifier.
15816 This should be one of the symbols `alt', `hyper', `meta', `super'.
15817 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
15818 default is nil, which is the same as `hyper'. */);
15819 Vx_hyper_keysym
= Qnil
;
15821 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
15822 doc
: /* Which keys Emacs uses for the meta modifier.
15823 This should be one of the symbols `alt', `hyper', `meta', `super'.
15824 For example, `meta' means use the Meta_L and Meta_R keysyms. The
15825 default is nil, which is the same as `meta'. */);
15826 Vx_meta_keysym
= Qnil
;
15828 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
15829 doc
: /* Which keys Emacs uses for the super modifier.
15830 This should be one of the symbols `alt', `hyper', `meta', `super'.
15831 For example, `super' means use the Super_L and Super_R keysyms. The
15832 default is nil, which is the same as `super'. */);
15833 Vx_super_keysym
= Qnil
;
15835 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
15836 doc
: /* Hash table of character codes indexed by X keysym codes. */);
15837 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
15838 make_float (DEFAULT_REHASH_SIZE
),
15839 make_float (DEFAULT_REHASH_THRESHOLD
),
15843 #endif /* HAVE_X_WINDOWS */