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))
165 extern Lisp_Object Qhelp_echo
;
167 /* Non-nil means Emacs uses toolkit scroll bars. */
169 Lisp_Object Vx_toolkit_scroll_bars
;
171 /* If a string, XTread_socket generates an event to display that string.
172 (The display is done in read_char.) */
174 static Lisp_Object help_echo
;
175 static Lisp_Object help_echo_window
;
176 static Lisp_Object help_echo_object
;
177 static int help_echo_pos
;
179 /* Temporary variable for XTread_socket. */
181 static Lisp_Object previous_help_echo
;
183 /* Non-zero means that a HELP_EVENT has been generated since Emacs
186 static int any_help_event_p
;
188 /* Non-zero means autoselect window with the mouse cursor. */
190 int mouse_autoselect_window
;
192 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
193 static Lisp_Object last_window
;
195 /* Non-zero means draw block and hollow cursor as wide as the glyph
196 under it. For example, if a block cursor is over a tab, it will be
197 drawn as wide as that tab on the display. */
199 int x_stretch_cursor_p
;
201 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
203 int x_use_underline_position_properties
;
205 /* This is a chain of structures for all the X displays currently in
208 struct x_display_info
*x_display_list
;
210 /* This is a list of cons cells, each of the form (NAME
211 . FONT-LIST-CACHE), one for each element of x_display_list and in
212 the same order. NAME is the name of the frame. FONT-LIST-CACHE
213 records previous values returned by x-list-fonts. */
215 Lisp_Object x_display_name_list
;
217 /* Frame being updated by update_frame. This is declared in term.c.
218 This is set by update_begin and looked at by all the XT functions.
219 It is zero while not inside an update. In that case, the XT
220 functions assume that `selected_frame' is the frame to apply to. */
222 extern struct frame
*updating_frame
;
224 /* This is a frame waiting to be auto-raised, within XTread_socket. */
226 struct frame
*pending_autoraise_frame
;
229 /* The application context for Xt use. */
230 XtAppContext Xt_app_con
;
231 static String Xt_default_resources
[] = {0};
232 #endif /* USE_X_TOOLKIT */
234 /* Nominal cursor position -- where to draw output.
235 HPOS and VPOS are window relative glyph matrix coordinates.
236 X and Y are window relative pixel coordinates. */
238 struct cursor_pos output_cursor
;
240 /* Non-zero means user is interacting with a toolkit scroll bar. */
242 static int toolkit_scroll_bar_interaction
;
246 Formerly, we used PointerMotionHintMask (in standard_event_mask)
247 so that we would have to call XQueryPointer after each MotionNotify
248 event to ask for another such event. However, this made mouse tracking
249 slow, and there was a bug that made it eventually stop.
251 Simply asking for MotionNotify all the time seems to work better.
253 In order to avoid asking for motion events and then throwing most
254 of them away or busy-polling the server for mouse positions, we ask
255 the server for pointer motion hints. This means that we get only
256 one event per group of mouse movements. "Groups" are delimited by
257 other kinds of events (focus changes and button clicks, for
258 example), or by XQueryPointer calls; when one of these happens, we
259 get another MotionNotify event the next time the mouse moves. This
260 is at least as efficient as getting motion events when mouse
261 tracking is on, and I suspect only negligibly worse when tracking
264 /* Where the mouse was last time we reported a mouse event. */
266 FRAME_PTR last_mouse_frame
;
267 static XRectangle last_mouse_glyph
;
268 static Lisp_Object last_mouse_press_frame
;
270 /* The scroll bar in which the last X motion event occurred.
272 If the last X motion event occurred in a scroll bar, we set this so
273 XTmouse_position can know whether to report a scroll bar motion or
276 If the last X motion event didn't occur in a scroll bar, we set
277 this to Qnil, to tell XTmouse_position to return an ordinary motion
280 static Lisp_Object last_mouse_scroll_bar
;
282 /* This is a hack. We would really prefer that XTmouse_position would
283 return the time associated with the position it returns, but there
284 doesn't seem to be any way to wrest the time-stamp from the server
285 along with the position query. So, we just keep track of the time
286 of the last movement we received, and return that in hopes that
287 it's somewhat accurate. */
289 static Time last_mouse_movement_time
;
291 /* Incremented by XTread_socket whenever it really tries to read
295 static int volatile input_signal_count
;
297 static int input_signal_count
;
300 /* Used locally within XTread_socket. */
302 static int x_noop_count
;
304 /* Initial values of argv and argc. */
306 extern char **initial_argv
;
307 extern int initial_argc
;
309 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
311 /* Tells if a window manager is present or not. */
313 extern Lisp_Object Vx_no_window_manager
;
315 extern Lisp_Object Qface
, Qmouse_face
, Qeql
;
319 /* A mask of extra modifier bits to put into every keyboard char. */
321 extern EMACS_INT extra_keyboard_modifiers
;
323 /* The keysyms to use for the various modifiers. */
325 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
326 Lisp_Object Vx_keysym_table
;
327 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
329 static Lisp_Object Qvendor_specific_keysyms
;
330 static Lisp_Object Qlatin_1
, Qutf_8
;
332 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
333 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
336 static int cursor_in_mouse_face_p
P_ ((struct window
*));
337 static int clear_mouse_face
P_ ((struct x_display_info
*));
338 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
339 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
340 static const XColor
*x_color_cells
P_ ((Display
*, int *));
341 static void x_update_window_end
P_ ((struct window
*, int, int));
342 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
343 void x_delete_display
P_ ((struct x_display_info
*));
344 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
346 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
347 int *, int *, Lisp_Object
));
348 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
349 int *, int *, int *, int *, int));
350 static void set_output_cursor
P_ ((struct cursor_pos
*));
351 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
352 int *, int *, int *, int));
353 static void note_mode_line_or_margin_highlight
P_ ((struct window
*, int,
355 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
356 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
357 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
358 static void show_mouse_face
P_ ((struct x_display_info
*,
359 enum draw_glyphs_face
));
360 static int x_io_error_quitter
P_ ((Display
*));
361 int x_catch_errors
P_ ((Display
*));
362 void x_uncatch_errors
P_ ((Display
*, int));
363 void x_lower_frame
P_ ((struct frame
*));
364 void x_scroll_bar_clear
P_ ((struct frame
*));
365 int x_had_errors_p
P_ ((Display
*));
366 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
367 void x_raise_frame
P_ ((struct frame
*));
368 void x_set_window_size
P_ ((struct frame
*, int, int, int));
369 void x_wm_set_window_state
P_ ((struct frame
*, int));
370 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
371 void x_initialize
P_ ((void));
372 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
373 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
374 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
376 enum draw_glyphs_face
));
377 static void x_update_end
P_ ((struct frame
*));
378 static void XTframe_up_to_date
P_ ((struct frame
*));
379 static void XTset_terminal_modes
P_ ((void));
380 static void XTreset_terminal_modes
P_ ((void));
381 static void XTcursor_to
P_ ((int, int, int, int));
382 static void x_write_glyphs
P_ ((struct glyph
*, int));
383 static void x_clear_end_of_line
P_ ((int));
384 static void x_clear_frame
P_ ((void));
385 static void x_clear_cursor
P_ ((struct window
*));
386 static void frame_highlight
P_ ((struct frame
*));
387 static void frame_unhighlight
P_ ((struct frame
*));
388 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
389 static int x_focus_changed
P_ ((int,
391 struct x_display_info
*,
393 struct input_event
*,
395 static int x_detect_focus_change
P_ ((struct x_display_info
*,
397 struct input_event
*,
399 static void XTframe_rehighlight
P_ ((struct frame
*));
400 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
401 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
402 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
403 enum text_cursor_kinds
));
404 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
406 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
407 static int expose_window_tree
P_ ((struct window
*, XRectangle
*));
408 static void expose_overlaps
P_ ((struct window
*, struct glyph_row
*,
409 struct glyph_row
*));
410 static int expose_window
P_ ((struct window
*, XRectangle
*));
411 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
412 XRectangle
*, enum glyph_row_area
));
413 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
415 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
416 static void x_update_window_cursor
P_ ((struct window
*, int));
417 static void x_erase_phys_cursor
P_ ((struct window
*));
418 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
420 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
422 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
423 static void x_flush
P_ ((struct frame
*f
));
424 static void x_update_begin
P_ ((struct frame
*));
425 static void x_update_window_begin
P_ ((struct window
*));
426 static void x_draw_vertical_border
P_ ((struct window
*));
427 static void x_after_update_window_line
P_ ((struct glyph_row
*));
428 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
429 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
430 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
431 enum scroll_bar_part
*,
432 Lisp_Object
*, Lisp_Object
*,
434 static void x_check_fullscreen
P_ ((struct frame
*));
435 static void x_check_fullscreen_move
P_ ((struct frame
*));
436 static int handle_one_xevent
P_ ((struct x_display_info
*,
438 struct input_event
**,
443 /* Flush display of frame F, or of all frames if F is null. */
452 Lisp_Object rest
, frame
;
453 FOR_EACH_FRAME (rest
, frame
)
454 x_flush (XFRAME (frame
));
456 else if (FRAME_X_P (f
))
457 XFlush (FRAME_X_DISPLAY (f
));
462 /* Remove calls to XFlush by defining XFlush to an empty replacement.
463 Calls to XFlush should be unnecessary because the X output buffer
464 is flushed automatically as needed by calls to XPending,
465 XNextEvent, or XWindowEvent according to the XFlush man page.
466 XTread_socket calls XPending. Removing XFlush improves
469 #define XFlush(DISPLAY) (void) 0
472 /***********************************************************************
474 ***********************************************************************/
478 /* This is a function useful for recording debugging information about
479 the sequence of occurrences in this file. */
487 struct record event_record
[100];
489 int event_record_index
;
491 record_event (locus
, type
)
495 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
496 event_record_index
= 0;
498 event_record
[event_record_index
].locus
= locus
;
499 event_record
[event_record_index
].type
= type
;
500 event_record_index
++;
507 /* Return the struct x_display_info corresponding to DPY. */
509 struct x_display_info
*
510 x_display_info_for_display (dpy
)
513 struct x_display_info
*dpyinfo
;
515 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
516 if (dpyinfo
->display
== dpy
)
524 /***********************************************************************
525 Starting and ending an update
526 ***********************************************************************/
528 /* Start an update of frame F. This function is installed as a hook
529 for update_begin, i.e. it is called when update_begin is called.
530 This function is called prior to calls to x_update_window_begin for
531 each window being updated. Currently, there is nothing to do here
532 because all interesting stuff is done on a window basis. */
542 /* Start update of window W. Set the global variable updated_window
543 to the window being updated and set output_cursor to the cursor
547 x_update_window_begin (w
)
550 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
551 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
554 set_output_cursor (&w
->cursor
);
558 if (f
== display_info
->mouse_face_mouse_frame
)
560 /* Don't do highlighting for mouse motion during the update. */
561 display_info
->mouse_face_defer
= 1;
563 /* If F needs to be redrawn, simply forget about any prior mouse
565 if (FRAME_GARBAGED_P (f
))
566 display_info
->mouse_face_window
= Qnil
;
568 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
569 their mouse_face_p flag set, which means that they are always
570 unequal to rows in a desired matrix which never have that
571 flag set. So, rows containing mouse-face glyphs are never
572 scrolled, and we don't have to switch the mouse highlight off
573 here to prevent it from being scrolled. */
575 /* Can we tell that this update does not affect the window
576 where the mouse highlight is? If so, no need to turn off.
577 Likewise, don't do anything if the frame is garbaged;
578 in that case, the frame's current matrix that we would use
579 is all wrong, and we will redisplay that line anyway. */
580 if (!NILP (display_info
->mouse_face_window
)
581 && w
== XWINDOW (display_info
->mouse_face_window
))
585 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
586 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
589 if (i
< w
->desired_matrix
->nrows
)
590 clear_mouse_face (display_info
);
599 /* Draw a vertical window border to the right of window W if W doesn't
600 have vertical scroll bars. */
603 x_draw_vertical_border (w
)
606 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
608 /* Redraw borders between horizontally adjacent windows. Don't
609 do it for frames with vertical scroll bars because either the
610 right scroll bar of a window, or the left scroll bar of its
611 neighbor will suffice as a border. */
612 if (!WINDOW_RIGHTMOST_P (w
)
613 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
617 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
618 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
621 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
622 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
627 /* End update of window W (which is equal to updated_window).
629 Draw vertical borders between horizontally adjacent windows, and
630 display W's cursor if CURSOR_ON_P is non-zero.
632 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
633 glyphs in mouse-face were overwritten. In that case we have to
634 make sure that the mouse-highlight is properly redrawn.
636 W may be a menu bar pseudo-window in case we don't have X toolkit
637 support. Such windows don't have a cursor, so don't display it
641 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
643 int cursor_on_p
, mouse_face_overwritten_p
;
645 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
647 if (!w
->pseudo_window_p
)
652 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
654 output_cursor
.x
, output_cursor
.y
);
656 x_draw_vertical_border (w
);
660 /* If a row with mouse-face was overwritten, arrange for
661 XTframe_up_to_date to redisplay the mouse highlight. */
662 if (mouse_face_overwritten_p
)
664 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
665 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
666 dpyinfo
->mouse_face_window
= Qnil
;
669 updated_window
= NULL
;
673 /* End update of frame F. This function is installed as a hook in
680 /* Mouse highlight may be displayed again. */
681 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
684 XFlush (FRAME_X_DISPLAY (f
));
689 /* This function is called from various places in xdisp.c whenever a
690 complete update has been performed. The global variable
691 updated_window is not available here. */
694 XTframe_up_to_date (f
)
699 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
701 if (dpyinfo
->mouse_face_deferred_gc
702 || f
== dpyinfo
->mouse_face_mouse_frame
)
705 if (dpyinfo
->mouse_face_mouse_frame
)
706 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
707 dpyinfo
->mouse_face_mouse_x
,
708 dpyinfo
->mouse_face_mouse_y
);
709 dpyinfo
->mouse_face_deferred_gc
= 0;
716 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
717 arrow bitmaps, or clear the fringes if no bitmaps are required
718 before DESIRED_ROW is made current. The window being updated is
719 found in updated_window. This function It is called from
720 update_window_line only if it is known that there are differences
721 between bitmaps to be drawn between current row and DESIRED_ROW. */
724 x_after_update_window_line (desired_row
)
725 struct glyph_row
*desired_row
;
727 struct window
*w
= updated_window
;
733 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
736 draw_row_fringe_bitmaps (w
, desired_row
);
740 /* When a window has disappeared, make sure that no rest of
741 full-width rows stays visible in the internal border. Could
742 check here if updated_window is the leftmost/rightmost window,
743 but I guess it's not worth doing since vertically split windows
744 are almost never used, internal border is rarely set, and the
745 overhead is very small. */
746 if (windows_or_buffers_changed
747 && desired_row
->full_width_p
748 && (f
= XFRAME (w
->frame
),
749 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
751 && (height
= desired_row
->visible_height
,
754 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
756 /* Internal border is drawn below the tool bar. */
757 if (WINDOWP (f
->tool_bar_window
)
758 && w
== XWINDOW (f
->tool_bar_window
))
762 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
763 0, y
, width
, height
, False
);
764 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
765 f
->output_data
.x
->pixel_width
- width
,
766 y
, width
, height
, False
);
772 x_draw_fringe_bitmap (w
, row
, p
)
774 struct glyph_row
*row
;
775 struct draw_fringe_bitmap_params
*p
;
777 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
778 Display
*display
= FRAME_X_DISPLAY (f
);
779 Window window
= FRAME_X_WINDOW (f
);
780 GC gc
= f
->output_data
.x
->normal_gc
;
781 struct face
*face
= p
->face
;
783 /* Must clip because of partially visible lines. */
784 x_clip_to_row (w
, row
, gc
, 1);
788 /* In case the same realized face is used for fringes and
789 for something displayed in the text (e.g. face `region' on
790 mono-displays, the fill style may have been changed to
791 FillSolid in x_draw_glyph_string_background. */
793 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
795 XSetForeground (display
, face
->gc
, face
->background
);
797 XFillRectangle (display
, window
, face
->gc
,
798 p
->bx
, p
->by
, p
->nx
, p
->ny
);
801 XSetForeground (display
, face
->gc
, face
->foreground
);
804 if (p
->which
!= NO_FRINGE_BITMAP
)
806 unsigned char *bits
= fringe_bitmaps
[p
->which
].bits
+ p
->dh
;
808 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
810 /* Draw the bitmap. I believe these small pixmaps can be cached
812 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
814 face
->background
, depth
);
815 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
816 p
->wd
, p
->h
, p
->x
, p
->y
);
817 XFreePixmap (display
, pixmap
);
820 XSetClipMask (display
, gc
, None
);
825 /* This is called when starting Emacs and when restarting after
826 suspend. When starting Emacs, no X window is mapped. And nothing
827 must be done to Emacs's own window if it is suspended (though that
831 XTset_terminal_modes ()
835 /* This is called when exiting or suspending Emacs. Exiting will make
836 the X-windows go away, and suspending requires no action. */
839 XTreset_terminal_modes ()
845 /***********************************************************************
847 ***********************************************************************/
849 /* Set the global variable output_cursor to CURSOR. All cursor
850 positions are relative to updated_window. */
853 set_output_cursor (cursor
)
854 struct cursor_pos
*cursor
;
856 output_cursor
.hpos
= cursor
->hpos
;
857 output_cursor
.vpos
= cursor
->vpos
;
858 output_cursor
.x
= cursor
->x
;
859 output_cursor
.y
= cursor
->y
;
863 /* Set a nominal cursor position.
865 HPOS and VPOS are column/row positions in a window glyph matrix. X
866 and Y are window text area relative pixel positions.
868 If this is done during an update, updated_window will contain the
869 window that is being updated and the position is the future output
870 cursor position for that window. If updated_window is null, use
871 selected_window and display the cursor at the given position. */
874 XTcursor_to (vpos
, hpos
, y
, x
)
875 int vpos
, hpos
, y
, x
;
879 /* If updated_window is not set, work on selected_window. */
883 w
= XWINDOW (selected_window
);
885 /* Set the output cursor. */
886 output_cursor
.hpos
= hpos
;
887 output_cursor
.vpos
= vpos
;
891 /* If not called as part of an update, really display the cursor.
892 This will also set the cursor position of W. */
893 if (updated_window
== NULL
)
896 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
897 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
904 /***********************************************************************
906 ***********************************************************************/
908 /* Function prototypes of this page. */
910 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
913 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
914 is not contained in the font. */
917 x_per_char_metric (font
, char2b
, font_type
)
920 int font_type
; /* unused on X */
922 /* The result metric information. */
923 XCharStruct
*pcm
= NULL
;
925 xassert (font
&& char2b
);
927 if (font
->per_char
!= NULL
)
929 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
931 /* min_char_or_byte2 specifies the linear character index
932 corresponding to the first element of the per_char array,
933 max_char_or_byte2 is the index of the last character. A
934 character with non-zero CHAR2B->byte1 is not in the font.
935 A character with byte2 less than min_char_or_byte2 or
936 greater max_char_or_byte2 is not in the font. */
937 if (char2b
->byte1
== 0
938 && char2b
->byte2
>= font
->min_char_or_byte2
939 && char2b
->byte2
<= font
->max_char_or_byte2
)
940 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
944 /* If either min_byte1 or max_byte1 are nonzero, both
945 min_char_or_byte2 and max_char_or_byte2 are less than
946 256, and the 2-byte character index values corresponding
947 to the per_char array element N (counting from 0) are:
949 byte1 = N/D + min_byte1
950 byte2 = N\D + min_char_or_byte2
954 D = max_char_or_byte2 - min_char_or_byte2 + 1
956 \ = integer modulus */
957 if (char2b
->byte1
>= font
->min_byte1
958 && char2b
->byte1
<= font
->max_byte1
959 && char2b
->byte2
>= font
->min_char_or_byte2
960 && char2b
->byte2
<= font
->max_char_or_byte2
)
962 pcm
= (font
->per_char
963 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
964 * (char2b
->byte1
- font
->min_byte1
))
965 + (char2b
->byte2
- font
->min_char_or_byte2
));
971 /* If the per_char pointer is null, all glyphs between the first
972 and last character indexes inclusive have the same
973 information, as given by both min_bounds and max_bounds. */
974 if (char2b
->byte2
>= font
->min_char_or_byte2
975 && char2b
->byte2
<= font
->max_char_or_byte2
)
976 pcm
= &font
->max_bounds
;
980 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
985 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
986 the two-byte form of C. Encoding is returned in *CHAR2B. */
989 x_encode_char (c
, char2b
, font_info
, two_byte_p
)
992 struct font_info
*font_info
;
995 int charset
= CHAR_CHARSET (c
);
996 XFontStruct
*font
= font_info
->font
;
998 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
999 This may be either a program in a special encoder language or a
1001 if (font_info
->font_encoder
)
1003 /* It's a program. */
1004 struct ccl_program
*ccl
= font_info
->font_encoder
;
1006 if (CHARSET_DIMENSION (charset
) == 1)
1008 ccl
->reg
[0] = charset
;
1009 ccl
->reg
[1] = char2b
->byte2
;
1014 ccl
->reg
[0] = charset
;
1015 ccl
->reg
[1] = char2b
->byte1
;
1016 ccl
->reg
[2] = char2b
->byte2
;
1019 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1021 /* We assume that MSBs are appropriately set/reset by CCL
1023 if (font
->max_byte1
== 0) /* 1-byte font */
1024 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1026 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1028 else if (font_info
->encoding
[charset
])
1030 /* Fixed encoding scheme. See fontset.h for the meaning of the
1031 encoding numbers. */
1032 int enc
= font_info
->encoding
[charset
];
1034 if ((enc
== 1 || enc
== 2)
1035 && CHARSET_DIMENSION (charset
) == 2)
1036 char2b
->byte1
|= 0x80;
1038 if (enc
== 1 || enc
== 3)
1039 char2b
->byte2
|= 0x80;
1043 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1045 return FONT_TYPE_UNKNOWN
;
1049 /* Estimate the pixel height of the mode or top line on frame F.
1050 FACE_ID specifies what line's height to estimate. */
1053 x_estimate_mode_line_height (f
, face_id
)
1055 enum face_id face_id
;
1057 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1059 /* This function is called so early when Emacs starts that the face
1060 cache and mode line face are not yet initialized. */
1061 if (FRAME_FACE_CACHE (f
))
1063 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1067 height
= FONT_HEIGHT (face
->font
);
1068 if (face
->box_line_width
> 0)
1069 height
+= 2 * face
->box_line_width
;
1077 /***********************************************************************
1079 ***********************************************************************/
1083 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
1084 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
1085 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
1087 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
1088 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
1089 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
1090 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
1091 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
1092 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
1093 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
1094 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
1095 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
1096 unsigned long *, double, int));
1097 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
1098 double, int, unsigned long));
1099 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
1100 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
1101 static void x_draw_image_relief
P_ ((struct glyph_string
*));
1102 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
1103 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
1104 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
1106 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
1107 int, int, int, int, XRectangle
*));
1108 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
1109 int, int, int, XRectangle
*));
1110 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
1111 enum glyph_row_area
));
1114 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
1118 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1123 struct glyph_string
*s
;
1125 if (s
->font
== FRAME_FONT (s
->f
)
1126 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1127 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1129 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1132 /* Cursor on non-default face: must merge. */
1136 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1137 xgcv
.foreground
= s
->face
->background
;
1139 /* If the glyph would be invisible, try a different foreground. */
1140 if (xgcv
.foreground
== xgcv
.background
)
1141 xgcv
.foreground
= s
->face
->foreground
;
1142 if (xgcv
.foreground
== xgcv
.background
)
1143 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1144 if (xgcv
.foreground
== xgcv
.background
)
1145 xgcv
.foreground
= s
->face
->foreground
;
1147 /* Make sure the cursor is distinct from text in this face. */
1148 if (xgcv
.background
== s
->face
->background
1149 && xgcv
.foreground
== s
->face
->foreground
)
1151 xgcv
.background
= s
->face
->foreground
;
1152 xgcv
.foreground
= s
->face
->background
;
1155 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1156 xgcv
.font
= s
->font
->fid
;
1157 xgcv
.graphics_exposures
= False
;
1158 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1160 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1161 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1164 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1165 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1167 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1172 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1175 x_set_mouse_face_gc (s
)
1176 struct glyph_string
*s
;
1181 /* What face has to be used last for the mouse face? */
1182 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1183 face
= FACE_FROM_ID (s
->f
, face_id
);
1185 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1187 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1188 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
1190 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
1191 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1192 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1194 /* If font in this face is same as S->font, use it. */
1195 if (s
->font
== s
->face
->font
)
1196 s
->gc
= s
->face
->gc
;
1199 /* Otherwise construct scratch_cursor_gc with values from FACE
1204 xgcv
.background
= s
->face
->background
;
1205 xgcv
.foreground
= s
->face
->foreground
;
1206 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1207 xgcv
.font
= s
->font
->fid
;
1208 xgcv
.graphics_exposures
= False
;
1209 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1211 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1212 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1215 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1216 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1218 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1221 xassert (s
->gc
!= 0);
1225 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1226 Faces to use in the mode line have already been computed when the
1227 matrix was built, so there isn't much to do, here. */
1230 x_set_mode_line_face_gc (s
)
1231 struct glyph_string
*s
;
1233 s
->gc
= s
->face
->gc
;
1237 /* Set S->gc of glyph string S for drawing that glyph string. Set
1238 S->stippled_p to a non-zero value if the face of S has a stipple
1242 x_set_glyph_string_gc (s
)
1243 struct glyph_string
*s
;
1245 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1247 if (s
->hl
== DRAW_NORMAL_TEXT
)
1249 s
->gc
= s
->face
->gc
;
1250 s
->stippled_p
= s
->face
->stipple
!= 0;
1252 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1254 x_set_mode_line_face_gc (s
);
1255 s
->stippled_p
= s
->face
->stipple
!= 0;
1257 else if (s
->hl
== DRAW_CURSOR
)
1259 x_set_cursor_gc (s
);
1262 else if (s
->hl
== DRAW_MOUSE_FACE
)
1264 x_set_mouse_face_gc (s
);
1265 s
->stippled_p
= s
->face
->stipple
!= 0;
1267 else if (s
->hl
== DRAW_IMAGE_RAISED
1268 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1270 s
->gc
= s
->face
->gc
;
1271 s
->stippled_p
= s
->face
->stipple
!= 0;
1275 s
->gc
= s
->face
->gc
;
1276 s
->stippled_p
= s
->face
->stipple
!= 0;
1279 /* GC must have been set. */
1280 xassert (s
->gc
!= 0);
1284 /* Return in *R the clipping rectangle for glyph string S. */
1287 x_get_glyph_string_clip_rect (s
, r
)
1288 struct glyph_string
*s
;
1291 if (s
->row
->full_width_p
)
1293 /* Draw full-width. X coordinates are relative to S->w->left. */
1294 int canon_x
= CANON_X_UNIT (s
->f
);
1296 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
1297 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
1299 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
1301 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
1302 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
1306 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1308 /* Unless displaying a mode or menu bar line, which are always
1309 fully visible, clip to the visible part of the row. */
1310 if (s
->w
->pseudo_window_p
)
1311 r
->height
= s
->row
->visible_height
;
1313 r
->height
= s
->height
;
1317 /* This is a text line that may be partially visible. */
1318 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
1319 r
->width
= window_box_width (s
->w
, s
->area
);
1320 r
->height
= s
->row
->visible_height
;
1323 /* If S draws overlapping rows, it's sufficient to use the top and
1324 bottom of the window for clipping because this glyph string
1325 intentionally draws over other lines. */
1326 if (s
->for_overlaps_p
)
1328 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
1329 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
1333 /* Don't use S->y for clipping because it doesn't take partially
1334 visible lines into account. For example, it can be negative for
1335 partially visible lines at the top of a window. */
1336 if (!s
->row
->full_width_p
1337 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1338 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
1340 r
->y
= max (0, s
->row
->y
);
1342 /* If drawing a tool-bar window, draw it over the internal border
1343 at the top of the window. */
1344 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1345 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
1348 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
1352 /* Set clipping for output of glyph string S. S may be part of a mode
1353 line or menu if we don't have X toolkit support. */
1356 x_set_glyph_string_clipping (s
)
1357 struct glyph_string
*s
;
1360 x_get_glyph_string_clip_rect (s
, &r
);
1361 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
1366 Compute left and right overhang of glyph string S. If S is a glyph
1367 string for a composition, assume overhangs don't exist. */
1370 x_compute_glyph_string_overhangs (s
)
1371 struct glyph_string
*s
;
1374 && s
->first_glyph
->type
== CHAR_GLYPH
)
1377 int direction
, font_ascent
, font_descent
;
1378 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1379 &font_ascent
, &font_descent
, &cs
);
1380 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1381 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1386 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1389 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1390 struct glyph_string
*s
;
1394 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1395 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1396 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1397 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1401 /* Draw the background of glyph_string S. If S->background_filled_p
1402 is non-zero don't draw it. FORCE_P non-zero means draw the
1403 background even if it wouldn't be drawn normally. This is used
1404 when a string preceding S draws into the background of S, or S
1405 contains the first component of a composition. */
1408 x_draw_glyph_string_background (s
, force_p
)
1409 struct glyph_string
*s
;
1412 /* Nothing to do if background has already been drawn or if it
1413 shouldn't be drawn in the first place. */
1414 if (!s
->background_filled_p
)
1416 int box_line_width
= max (s
->face
->box_line_width
, 0);
1420 /* Fill background with a stipple pattern. */
1421 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1422 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1423 s
->y
+ box_line_width
,
1424 s
->background_width
,
1425 s
->height
- 2 * box_line_width
);
1426 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1427 s
->background_filled_p
= 1;
1429 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1430 || s
->font_not_found_p
1431 || s
->extends_to_end_of_line_p
1434 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1435 s
->background_width
,
1436 s
->height
- 2 * box_line_width
);
1437 s
->background_filled_p
= 1;
1443 /* Draw the foreground of glyph string S. */
1446 x_draw_glyph_string_foreground (s
)
1447 struct glyph_string
*s
;
1451 /* If first glyph of S has a left box line, start drawing the text
1452 of S to the right of that box line. */
1453 if (s
->face
->box
!= FACE_NO_BOX
1454 && s
->first_glyph
->left_box_line_p
)
1455 x
= s
->x
+ abs (s
->face
->box_line_width
);
1459 /* Draw characters of S as rectangles if S's font could not be
1461 if (s
->font_not_found_p
)
1463 for (i
= 0; i
< s
->nchars
; ++i
)
1465 struct glyph
*g
= s
->first_glyph
+ i
;
1466 XDrawRectangle (s
->display
, s
->window
,
1467 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1469 x
+= g
->pixel_width
;
1474 char *char1b
= (char *) s
->char2b
;
1475 int boff
= s
->font_info
->baseline_offset
;
1477 if (s
->font_info
->vertical_centering
)
1478 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1480 /* If we can use 8-bit functions, condense S->char2b. */
1482 for (i
= 0; i
< s
->nchars
; ++i
)
1483 char1b
[i
] = s
->char2b
[i
].byte2
;
1485 /* Draw text with XDrawString if background has already been
1486 filled. Otherwise, use XDrawImageString. (Note that
1487 XDrawImageString is usually faster than XDrawString.) Always
1488 use XDrawImageString when drawing the cursor so that there is
1489 no chance that characters under a box cursor are invisible. */
1490 if (s
->for_overlaps_p
1491 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1493 /* Draw characters with 16-bit or 8-bit functions. */
1495 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1496 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1498 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1499 s
->ybase
- boff
, char1b
, s
->nchars
);
1504 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1505 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1507 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1508 s
->ybase
- boff
, char1b
, s
->nchars
);
1511 if (s
->face
->overstrike
)
1513 /* For overstriking (to simulate bold-face), draw the
1514 characters again shifted to the right by one pixel. */
1516 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1517 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1519 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1520 s
->ybase
- boff
, char1b
, s
->nchars
);
1525 /* Draw the foreground of composite glyph string S. */
1528 x_draw_composite_glyph_string_foreground (s
)
1529 struct glyph_string
*s
;
1533 /* If first glyph of S has a left box line, start drawing the text
1534 of S to the right of that box line. */
1535 if (s
->face
->box
!= FACE_NO_BOX
1536 && s
->first_glyph
->left_box_line_p
)
1537 x
= s
->x
+ abs (s
->face
->box_line_width
);
1541 /* S is a glyph string for a composition. S->gidx is the index of
1542 the first character drawn for glyphs of this composition.
1543 S->gidx == 0 means we are drawing the very first character of
1544 this composition. */
1546 /* Draw a rectangle for the composition if the font for the very
1547 first character of the composition could not be loaded. */
1548 if (s
->font_not_found_p
)
1551 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1552 s
->width
- 1, s
->height
- 1);
1556 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
1558 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1559 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
1560 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1562 if (s
->face
->overstrike
)
1563 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1564 x
+ s
->cmp
->offsets
[s
->gidx
* 2] + 1,
1565 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1572 #ifdef USE_X_TOOLKIT
1574 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1575 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1576 XrmValue
*, XrmValue
*, XtPointer
*));
1577 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1578 XrmValue
*, Cardinal
*));
1581 /* Return the frame on which widget WIDGET is used.. Abort if frame
1582 cannot be determined. */
1584 static struct frame
*
1585 x_frame_of_widget (widget
)
1588 struct x_display_info
*dpyinfo
;
1592 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1594 /* Find the top-level shell of the widget. Note that this function
1595 can be called when the widget is not yet realized, so XtWindow
1596 (widget) == 0. That's the reason we can't simply use
1597 x_any_window_to_frame. */
1598 while (!XtIsTopLevelShell (widget
))
1599 widget
= XtParent (widget
);
1601 /* Look for a frame with that top-level widget. Allocate the color
1602 on that frame to get the right gamma correction value. */
1603 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
1604 if (GC_FRAMEP (XCAR (tail
))
1605 && (f
= XFRAME (XCAR (tail
)),
1606 (f
->output_data
.nothing
!= 1
1607 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1608 && f
->output_data
.x
->widget
== widget
)
1615 /* Allocate the color COLOR->pixel on the screen and display of
1616 widget WIDGET in colormap CMAP. If an exact match cannot be
1617 allocated, try the nearest color available. Value is non-zero
1618 if successful. This is called from lwlib. */
1621 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1626 struct frame
*f
= x_frame_of_widget (widget
);
1627 return x_alloc_nearest_color (f
, cmap
, color
);
1631 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1632 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1633 If this produces the same color as PIXEL, try a color where all RGB
1634 values have DELTA added. Return the allocated color in *PIXEL.
1635 DISPLAY is the X display, CMAP is the colormap to operate on.
1636 Value is non-zero if successful. */
1639 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1643 unsigned long *pixel
;
1647 struct frame
*f
= x_frame_of_widget (widget
);
1648 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1652 /* Structure specifying which arguments should be passed by Xt to
1653 cvt_string_to_pixel. We want the widget's screen and colormap. */
1655 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1657 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1659 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1664 /* The address of this variable is returned by
1665 cvt_string_to_pixel. */
1667 static Pixel cvt_string_to_pixel_value
;
1670 /* Convert a color name to a pixel color.
1672 DPY is the display we are working on.
1674 ARGS is an array of *NARGS XrmValue structures holding additional
1675 information about the widget for which the conversion takes place.
1676 The contents of this array are determined by the specification
1677 in cvt_string_to_pixel_args.
1679 FROM is a pointer to an XrmValue which points to the color name to
1680 convert. TO is an XrmValue in which to return the pixel color.
1682 CLOSURE_RET is a pointer to user-data, in which we record if
1683 we allocated the color or not.
1685 Value is True if successful, False otherwise. */
1688 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1692 XrmValue
*from
, *to
;
1693 XtPointer
*closure_ret
;
1703 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1704 "wrongParameters", "cvt_string_to_pixel",
1706 "Screen and colormap args required", NULL
, NULL
);
1710 screen
= *(Screen
**) args
[0].addr
;
1711 cmap
= *(Colormap
*) args
[1].addr
;
1712 color_name
= (String
) from
->addr
;
1714 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1716 *closure_ret
= (XtPointer
) False
;
1717 pixel
= WhitePixelOfScreen (screen
);
1719 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1721 *closure_ret
= (XtPointer
) False
;
1722 pixel
= BlackPixelOfScreen (screen
);
1724 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1725 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1727 pixel
= color
.pixel
;
1728 *closure_ret
= (XtPointer
) True
;
1733 Cardinal nparams
= 1;
1735 params
[0] = color_name
;
1736 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1737 "badValue", "cvt_string_to_pixel",
1738 "XtToolkitError", "Invalid color `%s'",
1743 if (to
->addr
!= NULL
)
1745 if (to
->size
< sizeof (Pixel
))
1747 to
->size
= sizeof (Pixel
);
1751 *(Pixel
*) to
->addr
= pixel
;
1755 cvt_string_to_pixel_value
= pixel
;
1756 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1759 to
->size
= sizeof (Pixel
);
1764 /* Free a pixel color which was previously allocated via
1765 cvt_string_to_pixel. This is registered as the destructor
1766 for this type of resource via XtSetTypeConverter.
1768 APP is the application context in which we work.
1770 TO is a pointer to an XrmValue holding the color to free.
1771 CLOSURE is the value we stored in CLOSURE_RET for this color
1772 in cvt_string_to_pixel.
1774 ARGS and NARGS are like for cvt_string_to_pixel. */
1777 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1786 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1788 "Screen and colormap arguments required",
1791 else if (closure
!= NULL
)
1793 /* We did allocate the pixel, so free it. */
1794 Screen
*screen
= *(Screen
**) args
[0].addr
;
1795 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1796 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1797 (Pixel
*) to
->addr
, 1);
1802 #endif /* USE_X_TOOLKIT */
1805 /* Value is an array of XColor structures for the contents of the
1806 color map of display DPY. Set *NCELLS to the size of the array.
1807 Note that this probably shouldn't be called for large color maps,
1808 say a 24-bit TrueColor map. */
1810 static const XColor
*
1811 x_color_cells (dpy
, ncells
)
1815 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1817 if (dpyinfo
->color_cells
== NULL
)
1819 Screen
*screen
= dpyinfo
->screen
;
1822 dpyinfo
->ncolor_cells
1823 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1824 dpyinfo
->color_cells
1825 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1826 * sizeof *dpyinfo
->color_cells
);
1828 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1829 dpyinfo
->color_cells
[i
].pixel
= i
;
1831 XQueryColors (dpy
, dpyinfo
->cmap
,
1832 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1835 *ncells
= dpyinfo
->ncolor_cells
;
1836 return dpyinfo
->color_cells
;
1840 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1841 colors in COLORS. Use cached information, if available. */
1844 x_query_colors (f
, colors
, ncolors
)
1849 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1851 if (dpyinfo
->color_cells
)
1854 for (i
= 0; i
< ncolors
; ++i
)
1856 unsigned long pixel
= colors
[i
].pixel
;
1857 xassert (pixel
< dpyinfo
->ncolor_cells
);
1858 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1859 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1863 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1867 /* On frame F, translate pixel color to RGB values for the color in
1868 COLOR. Use cached information, if available. */
1871 x_query_color (f
, color
)
1875 x_query_colors (f
, color
, 1);
1879 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1880 exact match can't be allocated, try the nearest color available.
1881 Value is non-zero if successful. Set *COLOR to the color
1885 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1892 rc
= XAllocColor (dpy
, cmap
, color
);
1895 /* If we got to this point, the colormap is full, so we're going
1896 to try to get the next closest color. The algorithm used is
1897 a least-squares matching, which is what X uses for closest
1898 color matching with StaticColor visuals. */
1900 unsigned long nearest_delta
= ~0;
1902 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1904 for (nearest
= i
= 0; i
< ncells
; ++i
)
1906 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1907 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1908 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1909 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1911 if (delta
< nearest_delta
)
1914 nearest_delta
= delta
;
1918 color
->red
= cells
[nearest
].red
;
1919 color
->green
= cells
[nearest
].green
;
1920 color
->blue
= cells
[nearest
].blue
;
1921 rc
= XAllocColor (dpy
, cmap
, color
);
1925 /* If allocation succeeded, and the allocated pixel color is not
1926 equal to a cached pixel color recorded earlier, there was a
1927 change in the colormap, so clear the color cache. */
1928 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1929 XColor
*cached_color
;
1931 if (dpyinfo
->color_cells
1932 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1933 (cached_color
->red
!= color
->red
1934 || cached_color
->blue
!= color
->blue
1935 || cached_color
->green
!= color
->green
)))
1937 xfree (dpyinfo
->color_cells
);
1938 dpyinfo
->color_cells
= NULL
;
1939 dpyinfo
->ncolor_cells
= 0;
1943 #ifdef DEBUG_X_COLORS
1945 register_color (color
->pixel
);
1946 #endif /* DEBUG_X_COLORS */
1952 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1953 exact match can't be allocated, try the nearest color available.
1954 Value is non-zero if successful. Set *COLOR to the color
1958 x_alloc_nearest_color (f
, cmap
, color
)
1963 gamma_correct (f
, color
);
1964 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1968 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1969 It's necessary to do this instead of just using PIXEL directly to
1970 get color reference counts right. */
1973 x_copy_color (f
, pixel
)
1975 unsigned long pixel
;
1979 color
.pixel
= pixel
;
1981 x_query_color (f
, &color
);
1982 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1984 #ifdef DEBUG_X_COLORS
1985 register_color (pixel
);
1991 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1992 It's necessary to do this instead of just using PIXEL directly to
1993 get color reference counts right. */
1996 x_copy_dpy_color (dpy
, cmap
, pixel
)
1999 unsigned long pixel
;
2003 color
.pixel
= pixel
;
2005 XQueryColor (dpy
, cmap
, &color
);
2006 XAllocColor (dpy
, cmap
, &color
);
2008 #ifdef DEBUG_X_COLORS
2009 register_color (pixel
);
2015 /* Brightness beyond which a color won't have its highlight brightness
2018 Nominally, highlight colors for `3d' faces are calculated by
2019 brightening an object's color by a constant scale factor, but this
2020 doesn't yield good results for dark colors, so for colors who's
2021 brightness is less than this value (on a scale of 0-65535) have an
2022 use an additional additive factor.
2024 The value here is set so that the default menu-bar/mode-line color
2025 (grey75) will not have its highlights changed at all. */
2026 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
2029 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
2030 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2031 If this produces the same color as PIXEL, try a color where all RGB
2032 values have DELTA added. Return the allocated color in *PIXEL.
2033 DISPLAY is the X display, CMAP is the colormap to operate on.
2034 Value is non-zero if successful. */
2037 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
2041 unsigned long *pixel
;
2049 /* Get RGB color values. */
2050 color
.pixel
= *pixel
;
2051 x_query_color (f
, &color
);
2053 /* Change RGB values by specified FACTOR. Avoid overflow! */
2054 xassert (factor
>= 0);
2055 new.red
= min (0xffff, factor
* color
.red
);
2056 new.green
= min (0xffff, factor
* color
.green
);
2057 new.blue
= min (0xffff, factor
* color
.blue
);
2059 /* Calculate brightness of COLOR. */
2060 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
2062 /* We only boost colors that are darker than
2063 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2064 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2065 /* Make an additive adjustment to NEW, because it's dark enough so
2066 that scaling by FACTOR alone isn't enough. */
2068 /* How far below the limit this color is (0 - 1, 1 being darker). */
2069 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2070 /* The additive adjustment. */
2071 int min_delta
= delta
* dimness
* factor
/ 2;
2075 new.red
= max (0, new.red
- min_delta
);
2076 new.green
= max (0, new.green
- min_delta
);
2077 new.blue
= max (0, new.blue
- min_delta
);
2081 new.red
= min (0xffff, min_delta
+ new.red
);
2082 new.green
= min (0xffff, min_delta
+ new.green
);
2083 new.blue
= min (0xffff, min_delta
+ new.blue
);
2087 /* Try to allocate the color. */
2088 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2091 if (new.pixel
== *pixel
)
2093 /* If we end up with the same color as before, try adding
2094 delta to the RGB values. */
2095 x_free_colors (f
, &new.pixel
, 1);
2097 new.red
= min (0xffff, delta
+ color
.red
);
2098 new.green
= min (0xffff, delta
+ color
.green
);
2099 new.blue
= min (0xffff, delta
+ color
.blue
);
2100 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2111 /* Set up the foreground color for drawing relief lines of glyph
2112 string S. RELIEF is a pointer to a struct relief containing the GC
2113 with which lines will be drawn. Use a color that is FACTOR or
2114 DELTA lighter or darker than the relief's background which is found
2115 in S->f->output_data.x->relief_background. If such a color cannot
2116 be allocated, use DEFAULT_PIXEL, instead. */
2119 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
2121 struct relief
*relief
;
2124 unsigned long default_pixel
;
2127 struct x_output
*di
= f
->output_data
.x
;
2128 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
2129 unsigned long pixel
;
2130 unsigned long background
= di
->relief_background
;
2131 Colormap cmap
= FRAME_X_COLORMAP (f
);
2132 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2133 Display
*dpy
= FRAME_X_DISPLAY (f
);
2135 xgcv
.graphics_exposures
= False
;
2136 xgcv
.line_width
= 1;
2138 /* Free previously allocated color. The color cell will be reused
2139 when it has been freed as many times as it was allocated, so this
2140 doesn't affect faces using the same colors. */
2142 && relief
->allocated_p
)
2144 x_free_colors (f
, &relief
->pixel
, 1);
2145 relief
->allocated_p
= 0;
2148 /* Allocate new color. */
2149 xgcv
.foreground
= default_pixel
;
2151 if (dpyinfo
->n_planes
!= 1
2152 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
2154 relief
->allocated_p
= 1;
2155 xgcv
.foreground
= relief
->pixel
= pixel
;
2158 if (relief
->gc
== 0)
2160 xgcv
.stipple
= dpyinfo
->gray
;
2162 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
2165 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
2169 /* Set up colors for the relief lines around glyph string S. */
2172 x_setup_relief_colors (s
)
2173 struct glyph_string
*s
;
2175 struct x_output
*di
= s
->f
->output_data
.x
;
2176 unsigned long color
;
2178 if (s
->face
->use_box_color_for_shadows_p
)
2179 color
= s
->face
->box_color
;
2180 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2182 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2183 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2188 /* Get the background color of the face. */
2189 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2190 color
= xgcv
.background
;
2193 if (di
->white_relief
.gc
== 0
2194 || color
!= di
->relief_background
)
2196 di
->relief_background
= color
;
2197 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2198 WHITE_PIX_DEFAULT (s
->f
));
2199 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2200 BLACK_PIX_DEFAULT (s
->f
));
2205 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2206 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2207 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2208 relief. LEFT_P non-zero means draw a relief on the left side of
2209 the rectangle. RIGHT_P non-zero means draw a relief on the right
2210 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2214 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2215 raised_p
, left_p
, right_p
, clip_rect
)
2217 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
, raised_p
;
2218 XRectangle
*clip_rect
;
2220 Display
*dpy
= FRAME_X_DISPLAY (f
);
2221 Window window
= FRAME_X_WINDOW (f
);
2226 gc
= f
->output_data
.x
->white_relief
.gc
;
2228 gc
= f
->output_data
.x
->black_relief
.gc
;
2229 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2232 for (i
= 0; i
< width
; ++i
)
2233 XDrawLine (dpy
, window
, gc
,
2234 left_x
+ i
* left_p
, top_y
+ i
,
2235 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2239 for (i
= 0; i
< width
; ++i
)
2240 XDrawLine (dpy
, window
, gc
,
2241 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2243 XSetClipMask (dpy
, gc
, None
);
2245 gc
= f
->output_data
.x
->black_relief
.gc
;
2247 gc
= f
->output_data
.x
->white_relief
.gc
;
2248 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2251 for (i
= 0; i
< width
; ++i
)
2252 XDrawLine (dpy
, window
, gc
,
2253 left_x
+ i
* left_p
, bottom_y
- i
,
2254 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2258 for (i
= 0; i
< width
; ++i
)
2259 XDrawLine (dpy
, window
, gc
,
2260 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2262 XSetClipMask (dpy
, gc
, None
);
2266 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2267 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2268 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2269 left side of the rectangle. RIGHT_P non-zero means draw a line
2270 on the right side of the rectangle. CLIP_RECT is the clipping
2271 rectangle to use when drawing. */
2274 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2275 left_p
, right_p
, clip_rect
)
2276 struct glyph_string
*s
;
2277 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2278 XRectangle
*clip_rect
;
2282 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2283 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2284 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2287 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2288 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2292 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2293 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2296 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2297 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2301 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2302 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2304 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2305 XSetClipMask (s
->display
, s
->gc
, None
);
2309 /* Draw a box around glyph string S. */
2312 x_draw_glyph_string_box (s
)
2313 struct glyph_string
*s
;
2315 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2316 int left_p
, right_p
;
2317 struct glyph
*last_glyph
;
2318 XRectangle clip_rect
;
2320 last_x
= window_box_right (s
->w
, s
->area
);
2321 if (s
->row
->full_width_p
2322 && !s
->w
->pseudo_window_p
)
2324 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
2325 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
2326 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
2329 /* The glyph that may have a right box line. */
2330 last_glyph
= (s
->cmp
|| s
->img
2332 : s
->first_glyph
+ s
->nchars
- 1);
2334 width
= abs (s
->face
->box_line_width
);
2335 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2337 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2339 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2341 bottom_y
= top_y
+ s
->height
- 1;
2343 left_p
= (s
->first_glyph
->left_box_line_p
2344 || (s
->hl
== DRAW_MOUSE_FACE
2346 || s
->prev
->hl
!= s
->hl
)));
2347 right_p
= (last_glyph
->right_box_line_p
2348 || (s
->hl
== DRAW_MOUSE_FACE
2350 || s
->next
->hl
!= s
->hl
)));
2352 x_get_glyph_string_clip_rect (s
, &clip_rect
);
2354 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2355 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2356 left_p
, right_p
, &clip_rect
);
2359 x_setup_relief_colors (s
);
2360 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2361 width
, raised_p
, left_p
, right_p
, &clip_rect
);
2366 /* Draw foreground of image glyph string S. */
2369 x_draw_image_foreground (s
)
2370 struct glyph_string
*s
;
2373 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
2375 /* If first glyph of S has a left box line, start drawing it to the
2376 right of that line. */
2377 if (s
->face
->box
!= FACE_NO_BOX
2378 && s
->first_glyph
->left_box_line_p
)
2379 x
= s
->x
+ abs (s
->face
->box_line_width
);
2383 /* If there is a margin around the image, adjust x- and y-position
2385 x
+= s
->img
->hmargin
;
2386 y
+= s
->img
->vmargin
;
2392 /* We can't set both a clip mask and use XSetClipRectangles
2393 because the latter also sets a clip mask. We also can't
2394 trust on the shape extension to be available
2395 (XShapeCombineRegion). So, compute the rectangle to draw
2397 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2400 XRectangle clip_rect
, image_rect
, r
;
2402 xgcv
.clip_mask
= s
->img
->mask
;
2403 xgcv
.clip_x_origin
= x
;
2404 xgcv
.clip_y_origin
= y
;
2405 xgcv
.function
= GXcopy
;
2406 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2408 x_get_glyph_string_clip_rect (s
, &clip_rect
);
2411 image_rect
.width
= s
->img
->width
;
2412 image_rect
.height
= s
->img
->height
;
2413 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2414 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2415 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
2419 XRectangle clip_rect
, image_rect
, r
;
2421 x_get_glyph_string_clip_rect (s
, &clip_rect
);
2424 image_rect
.width
= s
->img
->width
;
2425 image_rect
.height
= s
->img
->height
;
2426 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2427 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2428 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
2430 /* When the image has a mask, we can expect that at
2431 least part of a mouse highlight or a block cursor will
2432 be visible. If the image doesn't have a mask, make
2433 a block cursor visible by drawing a rectangle around
2434 the image. I believe it's looking better if we do
2435 nothing here for mouse-face. */
2436 if (s
->hl
== DRAW_CURSOR
)
2438 int r
= s
->img
->relief
;
2440 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2441 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
2446 /* Draw a rectangle if image could not be loaded. */
2447 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2448 s
->img
->width
- 1, s
->img
->height
- 1);
2452 /* Draw a relief around the image glyph string S. */
2455 x_draw_image_relief (s
)
2456 struct glyph_string
*s
;
2458 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2461 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
2463 /* If first glyph of S has a left box line, start drawing it to the
2464 right of that line. */
2465 if (s
->face
->box
!= FACE_NO_BOX
2466 && s
->first_glyph
->left_box_line_p
)
2467 x
= s
->x
+ abs (s
->face
->box_line_width
);
2471 /* If there is a margin around the image, adjust x- and y-position
2473 x
+= s
->img
->hmargin
;
2474 y
+= s
->img
->vmargin
;
2476 if (s
->hl
== DRAW_IMAGE_SUNKEN
2477 || s
->hl
== DRAW_IMAGE_RAISED
)
2479 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2480 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2484 thick
= abs (s
->img
->relief
);
2485 raised_p
= s
->img
->relief
> 0;
2490 x1
= x
+ s
->img
->width
+ thick
- 1;
2491 y1
= y
+ s
->img
->height
+ thick
- 1;
2493 x_setup_relief_colors (s
);
2494 x_get_glyph_string_clip_rect (s
, &r
);
2495 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
2499 /* Draw the foreground of image glyph string S to PIXMAP. */
2502 x_draw_image_foreground_1 (s
, pixmap
)
2503 struct glyph_string
*s
;
2507 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
2509 /* If first glyph of S has a left box line, start drawing it to the
2510 right of that line. */
2511 if (s
->face
->box
!= FACE_NO_BOX
2512 && s
->first_glyph
->left_box_line_p
)
2513 x
= abs (s
->face
->box_line_width
);
2517 /* If there is a margin around the image, adjust x- and y-position
2519 x
+= s
->img
->hmargin
;
2520 y
+= s
->img
->vmargin
;
2526 /* We can't set both a clip mask and use XSetClipRectangles
2527 because the latter also sets a clip mask. We also can't
2528 trust on the shape extension to be available
2529 (XShapeCombineRegion). So, compute the rectangle to draw
2531 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2535 xgcv
.clip_mask
= s
->img
->mask
;
2536 xgcv
.clip_x_origin
= x
;
2537 xgcv
.clip_y_origin
= y
;
2538 xgcv
.function
= GXcopy
;
2539 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2541 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2542 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
2543 XSetClipMask (s
->display
, s
->gc
, None
);
2547 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2548 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
2550 /* When the image has a mask, we can expect that at
2551 least part of a mouse highlight or a block cursor will
2552 be visible. If the image doesn't have a mask, make
2553 a block cursor visible by drawing a rectangle around
2554 the image. I believe it's looking better if we do
2555 nothing here for mouse-face. */
2556 if (s
->hl
== DRAW_CURSOR
)
2558 int r
= s
->img
->relief
;
2560 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2561 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
2566 /* Draw a rectangle if image could not be loaded. */
2567 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2568 s
->img
->width
- 1, s
->img
->height
- 1);
2572 /* Draw part of the background of glyph string S. X, Y, W, and H
2573 give the rectangle to draw. */
2576 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2577 struct glyph_string
*s
;
2582 /* Fill background with a stipple pattern. */
2583 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2584 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2585 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2588 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2592 /* Draw image glyph string S.
2595 s->x +-------------------------
2598 | +-------------------------
2601 | | +-------------------
2607 x_draw_image_glyph_string (s
)
2608 struct glyph_string
*s
;
2611 int box_line_hwidth
= abs (s
->face
->box_line_width
);
2612 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2614 Pixmap pixmap
= None
;
2616 height
= s
->height
- 2 * box_line_vwidth
;
2619 /* Fill background with face under the image. Do it only if row is
2620 taller than image or if image has a clip mask to reduce
2622 s
->stippled_p
= s
->face
->stipple
!= 0;
2623 if (height
> s
->img
->height
2627 || s
->img
->pixmap
== 0
2628 || s
->width
!= s
->background_width
)
2630 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
2631 x
= s
->x
+ box_line_hwidth
;
2635 y
= s
->y
+ box_line_vwidth
;
2639 /* Create a pixmap as large as the glyph string. Fill it
2640 with the background color. Copy the image to it, using
2641 its mask. Copy the temporary pixmap to the display. */
2642 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2643 int depth
= DefaultDepthOfScreen (screen
);
2645 /* Create a pixmap as large as the glyph string. */
2646 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2647 s
->background_width
,
2650 /* Don't clip in the following because we're working on the
2652 XSetClipMask (s
->display
, s
->gc
, None
);
2654 /* Fill the pixmap with the background color/stipple. */
2657 /* Fill background with a stipple pattern. */
2658 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2659 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2660 0, 0, s
->background_width
, s
->height
);
2661 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2666 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2668 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2669 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2670 0, 0, s
->background_width
, s
->height
);
2671 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2675 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2677 s
->background_filled_p
= 1;
2680 /* Draw the foreground. */
2683 x_draw_image_foreground_1 (s
, pixmap
);
2684 x_set_glyph_string_clipping (s
);
2685 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2686 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2687 XFreePixmap (s
->display
, pixmap
);
2690 x_draw_image_foreground (s
);
2692 /* If we must draw a relief around the image, do it. */
2694 || s
->hl
== DRAW_IMAGE_RAISED
2695 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2696 x_draw_image_relief (s
);
2700 /* Draw stretch glyph string S. */
2703 x_draw_stretch_glyph_string (s
)
2704 struct glyph_string
*s
;
2706 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2707 s
->stippled_p
= s
->face
->stipple
!= 0;
2709 if (s
->hl
== DRAW_CURSOR
2710 && !x_stretch_cursor_p
)
2712 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2713 as wide as the stretch glyph. */
2714 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
2717 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
2719 /* Clear rest using the GC of the original non-cursor face. */
2720 if (width
< s
->background_width
)
2722 int x
= s
->x
+ width
, y
= s
->y
;
2723 int w
= s
->background_width
- width
, h
= s
->height
;
2727 if (s
->row
->mouse_face_p
2728 && cursor_in_mouse_face_p (s
->w
))
2730 x_set_mouse_face_gc (s
);
2736 x_get_glyph_string_clip_rect (s
, &r
);
2737 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2739 if (s
->face
->stipple
)
2741 /* Fill background with a stipple pattern. */
2742 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2743 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2744 XSetFillStyle (s
->display
, gc
, FillSolid
);
2749 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2750 XSetForeground (s
->display
, gc
, xgcv
.background
);
2751 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2752 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2756 else if (!s
->background_filled_p
)
2757 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
2760 s
->background_filled_p
= 1;
2764 /* Draw glyph string S. */
2767 x_draw_glyph_string (s
)
2768 struct glyph_string
*s
;
2770 int relief_drawn_p
= 0;
2772 /* If S draws into the background of its successor, draw the
2773 background of the successor first so that S can draw into it.
2774 This makes S->next use XDrawString instead of XDrawImageString. */
2775 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
2777 xassert (s
->next
->img
== NULL
);
2778 x_set_glyph_string_gc (s
->next
);
2779 x_set_glyph_string_clipping (s
->next
);
2780 x_draw_glyph_string_background (s
->next
, 1);
2783 /* Set up S->gc, set clipping and draw S. */
2784 x_set_glyph_string_gc (s
);
2786 /* Draw relief (if any) in advance for char/composition so that the
2787 glyph string can be drawn over it. */
2788 if (!s
->for_overlaps_p
2789 && s
->face
->box
!= FACE_NO_BOX
2790 && (s
->first_glyph
->type
== CHAR_GLYPH
2791 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2794 x_set_glyph_string_clipping (s
);
2795 x_draw_glyph_string_background (s
, 1);
2796 x_draw_glyph_string_box (s
);
2797 x_set_glyph_string_clipping (s
);
2801 x_set_glyph_string_clipping (s
);
2803 switch (s
->first_glyph
->type
)
2806 x_draw_image_glyph_string (s
);
2810 x_draw_stretch_glyph_string (s
);
2814 if (s
->for_overlaps_p
)
2815 s
->background_filled_p
= 1;
2817 x_draw_glyph_string_background (s
, 0);
2818 x_draw_glyph_string_foreground (s
);
2821 case COMPOSITE_GLYPH
:
2822 if (s
->for_overlaps_p
|| s
->gidx
> 0)
2823 s
->background_filled_p
= 1;
2825 x_draw_glyph_string_background (s
, 1);
2826 x_draw_composite_glyph_string_foreground (s
);
2833 if (!s
->for_overlaps_p
)
2835 /* Draw underline. */
2836 if (s
->face
->underline_p
)
2838 unsigned long tem
, h
;
2841 /* Get the underline thickness. Default is 1 pixel. */
2842 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
2845 /* Get the underline position. This is the recommended
2846 vertical offset in pixels from the baseline to the top of
2847 the underline. This is a signed value according to the
2848 specs, and its default is
2850 ROUND ((maximum descent) / 2), with
2851 ROUND(x) = floor (x + 0.5) */
2853 if (x_use_underline_position_properties
2854 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
2855 y
= s
->ybase
+ (long) tem
;
2856 else if (s
->face
->font
)
2857 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2859 y
= s
->y
+ s
->height
- h
;
2861 if (s
->face
->underline_defaulted_p
)
2862 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2863 s
->x
, y
, s
->width
, h
);
2867 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2868 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2869 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2870 s
->x
, y
, s
->width
, h
);
2871 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2875 /* Draw overline. */
2876 if (s
->face
->overline_p
)
2878 unsigned long dy
= 0, h
= 1;
2880 if (s
->face
->overline_color_defaulted_p
)
2881 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2886 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2887 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2888 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2890 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2894 /* Draw strike-through. */
2895 if (s
->face
->strike_through_p
)
2897 unsigned long h
= 1;
2898 unsigned long dy
= (s
->height
- h
) / 2;
2900 if (s
->face
->strike_through_color_defaulted_p
)
2901 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2906 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2907 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2908 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2910 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2914 /* Draw relief if not yet drawn. */
2915 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2916 x_draw_glyph_string_box (s
);
2919 /* Reset clipping. */
2920 XSetClipMask (s
->display
, s
->gc
, None
);
2924 /* Fix the display of area AREA of overlapping row ROW in window W. */
2927 x_fix_overlapping_area (w
, row
, area
)
2929 struct glyph_row
*row
;
2930 enum glyph_row_area area
;
2936 if (area
== LEFT_MARGIN_AREA
)
2938 else if (area
== TEXT_AREA
)
2939 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
2941 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
2942 + window_box_width (w
, TEXT_AREA
));
2944 for (i
= 0; i
< row
->used
[area
];)
2946 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
2948 int start
= i
, start_x
= x
;
2952 x
+= row
->glyphs
[area
][i
].pixel_width
;
2955 while (i
< row
->used
[area
]
2956 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
2958 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
2959 DRAW_NORMAL_TEXT
, 1);
2963 x
+= row
->glyphs
[area
][i
].pixel_width
;
2972 /* Output LEN glyphs starting at START at the nominal cursor position.
2973 Advance the nominal cursor over the text. The global variable
2974 updated_window contains the window being updated, updated_row is
2975 the glyph row being updated, and updated_area is the area of that
2976 row being updated. */
2979 x_write_glyphs (start
, len
)
2980 struct glyph
*start
;
2985 xassert (updated_window
&& updated_row
);
2990 hpos
= start
- updated_row
->glyphs
[updated_area
];
2991 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
2992 updated_row
, updated_area
,
2994 DRAW_NORMAL_TEXT
, 0);
2996 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
2997 if (updated_area
== TEXT_AREA
2998 && updated_window
->phys_cursor_on_p
2999 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
3000 && updated_window
->phys_cursor
.hpos
>= hpos
3001 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
3002 updated_window
->phys_cursor_on_p
= 0;
3006 /* Advance the output cursor. */
3007 output_cursor
.hpos
+= len
;
3008 output_cursor
.x
= x
;
3012 /* Insert LEN glyphs from START at the nominal cursor position. */
3015 x_insert_glyphs (start
, len
)
3016 struct glyph
*start
;
3021 int line_height
, shift_by_width
, shifted_region_width
;
3022 struct glyph_row
*row
;
3023 struct glyph
*glyph
;
3024 int frame_x
, frame_y
, hpos
;
3026 xassert (updated_window
&& updated_row
);
3029 f
= XFRAME (WINDOW_FRAME (w
));
3031 /* Get the height of the line we are in. */
3033 line_height
= row
->height
;
3035 /* Get the width of the glyphs to insert. */
3037 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
3038 shift_by_width
+= glyph
->pixel_width
;
3040 /* Get the width of the region to shift right. */
3041 shifted_region_width
= (window_box_width (w
, updated_area
)
3046 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
3047 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
3048 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3049 f
->output_data
.x
->normal_gc
,
3051 shifted_region_width
, line_height
,
3052 frame_x
+ shift_by_width
, frame_y
);
3054 /* Write the glyphs. */
3055 hpos
= start
- row
->glyphs
[updated_area
];
3056 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
3057 DRAW_NORMAL_TEXT
, 0);
3059 /* Advance the output cursor. */
3060 output_cursor
.hpos
+= len
;
3061 output_cursor
.x
+= shift_by_width
;
3066 /* Delete N glyphs at the nominal cursor position. Not implemented
3077 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
3078 If they are <= 0, this is probably an error. */
3081 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
3088 xassert (width
> 0 && height
> 0);
3089 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
3093 /* Erase the current text line from the nominal cursor position
3094 (inclusive) to pixel column TO_X (exclusive). The idea is that
3095 everything from TO_X onward is already erased.
3097 TO_X is a pixel position relative to updated_area of
3098 updated_window. TO_X == -1 means clear to the end of this area. */
3101 x_clear_end_of_line (to_x
)
3105 struct window
*w
= updated_window
;
3106 int max_x
, min_y
, max_y
;
3107 int from_x
, from_y
, to_y
;
3109 xassert (updated_window
&& updated_row
);
3110 f
= XFRAME (w
->frame
);
3112 if (updated_row
->full_width_p
)
3114 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
3115 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3116 && !w
->pseudo_window_p
)
3117 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
3120 max_x
= window_box_width (w
, updated_area
);
3121 max_y
= window_text_bottom_y (w
);
3123 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
3124 of window. For TO_X > 0, truncate to end of drawing area. */
3130 to_x
= min (to_x
, max_x
);
3132 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
3134 /* Notice if the cursor will be cleared by this operation. */
3135 if (!updated_row
->full_width_p
)
3136 notice_overwritten_cursor (w
, updated_area
,
3137 output_cursor
.x
, -1,
3139 MATRIX_ROW_BOTTOM_Y (updated_row
));
3141 from_x
= output_cursor
.x
;
3143 /* Translate to frame coordinates. */
3144 if (updated_row
->full_width_p
)
3146 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
3147 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
3151 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
3152 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
3155 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
3156 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
3157 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
3159 /* Prevent inadvertently clearing to end of the X window. */
3160 if (to_x
> from_x
&& to_y
> from_y
)
3163 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3164 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
3171 /* Clear entire frame. If updating_frame is non-null, clear that
3172 frame. Otherwise clear the selected frame. */
3182 f
= SELECTED_FRAME ();
3184 /* Clearing the frame will erase any cursor, so mark them all as no
3186 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3187 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3188 output_cursor
.x
= -1;
3190 /* We don't set the output cursor here because there will always
3191 follow an explicit cursor_to. */
3193 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
3195 /* We have to clear the scroll bars, too. If we have changed
3196 colors or something like that, then they should be notified. */
3197 x_scroll_bar_clear (f
);
3199 XFlush (FRAME_X_DISPLAY (f
));
3202 xg_frame_cleared (f
);
3210 /* Invert the middle quarter of the frame for .15 sec. */
3212 /* We use the select system call to do the waiting, so we have to make
3213 sure it's available. If it isn't, we just won't do visual bells. */
3215 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3218 /* Subtract the `struct timeval' values X and Y, storing the result in
3219 *RESULT. Return 1 if the difference is negative, otherwise 0. */
3222 timeval_subtract (result
, x
, y
)
3223 struct timeval
*result
, x
, y
;
3225 /* Perform the carry for the later subtraction by updating y. This
3226 is safer because on some systems the tv_sec member is unsigned. */
3227 if (x
.tv_usec
< y
.tv_usec
)
3229 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
3230 y
.tv_usec
-= 1000000 * nsec
;
3234 if (x
.tv_usec
- y
.tv_usec
> 1000000)
3236 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
3237 y
.tv_usec
+= 1000000 * nsec
;
3241 /* Compute the time remaining to wait. tv_usec is certainly
3243 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
3244 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3246 /* Return indication of whether the result should be considered
3248 return x
.tv_sec
< y
.tv_sec
;
3260 /* Create a GC that will use the GXxor function to flip foreground
3261 pixels into background pixels. */
3265 values
.function
= GXxor
;
3266 values
.foreground
= (f
->output_data
.x
->foreground_pixel
3267 ^ f
->output_data
.x
->background_pixel
);
3269 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3270 GCFunction
| GCForeground
, &values
);
3274 /* Get the height not including a menu bar widget. */
3275 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
3276 /* Height of each line to flash. */
3277 int flash_height
= FRAME_LINE_HEIGHT (f
);
3278 /* These will be the left and right margins of the rectangles. */
3279 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3280 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3284 /* Don't flash the area between a scroll bar and the frame
3285 edge it is next to. */
3286 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3288 case vertical_scroll_bar_left
:
3289 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3292 case vertical_scroll_bar_right
:
3293 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3300 width
= flash_right
- flash_left
;
3302 /* If window is tall, flash top and bottom line. */
3303 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3305 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3307 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3308 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
3309 width
, flash_height
);
3310 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3312 (height
- flash_height
3313 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3314 width
, flash_height
);
3317 /* If it is short, flash it all. */
3318 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3319 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3320 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3325 struct timeval wakeup
;
3327 EMACS_GET_TIME (wakeup
);
3329 /* Compute time to wait until, propagating carry from usecs. */
3330 wakeup
.tv_usec
+= 150000;
3331 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3332 wakeup
.tv_usec
%= 1000000;
3334 /* Keep waiting until past the time wakeup or any input gets
3336 while (! detect_input_pending ())
3338 struct timeval current
;
3339 struct timeval timeout
;
3341 EMACS_GET_TIME (current
);
3343 /* Break if result would be negative. */
3344 if (timeval_subtract (¤t
, wakeup
, current
))
3347 /* How long `select' should wait. */
3349 timeout
.tv_usec
= 10000;
3351 /* Try to wait that long--but we might wake up sooner. */
3352 select (0, NULL
, NULL
, NULL
, &timeout
);
3356 /* If window is tall, flash top and bottom line. */
3357 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3359 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3361 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3362 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
3363 width
, flash_height
);
3364 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3366 (height
- flash_height
3367 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3368 width
, flash_height
);
3371 /* If it is short, flash it all. */
3372 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3373 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3374 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3376 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3384 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3387 /* Make audible bell. */
3392 struct frame
*f
= SELECTED_FRAME ();
3394 if (FRAME_X_DISPLAY (f
))
3396 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3403 XBell (FRAME_X_DISPLAY (f
), 0);
3404 XFlush (FRAME_X_DISPLAY (f
));
3411 /* Specify how many text lines, from the top of the window,
3412 should be affected by insert-lines and delete-lines operations.
3413 This, and those operations, are used only within an update
3414 that is bounded by calls to x_update_begin and x_update_end. */
3417 XTset_terminal_window (n
)
3420 /* This function intentionally left blank. */
3425 /***********************************************************************
3427 ***********************************************************************/
3429 /* Perform an insert-lines or delete-lines operation, inserting N
3430 lines or deleting -N lines at vertical position VPOS. */
3433 x_ins_del_lines (vpos
, n
)
3440 /* Scroll part of the display as described by RUN. */
3443 x_scroll_run (w
, run
)
3447 struct frame
*f
= XFRAME (w
->frame
);
3448 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3450 /* Get frame-relative bounding box of the text display area of W,
3451 without mode lines. Include in this box the left and right
3453 window_box (w
, -1, &x
, &y
, &width
, &height
);
3454 width
+= FRAME_X_FRINGE_WIDTH (f
);
3455 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
3457 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3458 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3459 bottom_y
= y
+ height
;
3463 /* Scrolling up. Make sure we don't copy part of the mode
3464 line at the bottom. */
3465 if (from_y
+ run
->height
> bottom_y
)
3466 height
= bottom_y
- from_y
;
3468 height
= run
->height
;
3472 /* Scolling down. Make sure we don't copy over the mode line.
3474 if (to_y
+ run
->height
> bottom_y
)
3475 height
= bottom_y
- to_y
;
3477 height
= run
->height
;
3482 /* Cursor off. Will be switched on again in x_update_window_end. */
3486 XCopyArea (FRAME_X_DISPLAY (f
),
3487 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3488 f
->output_data
.x
->normal_gc
,
3498 /***********************************************************************
3500 ***********************************************************************/
3502 /* Redisplay an exposed area of frame F. X and Y are the upper-left
3503 corner of the exposed rectangle. W and H are width and height of
3504 the exposed area. All are pixel values. W or H zero means redraw
3505 the entire frame. */
3508 expose_frame (f
, x
, y
, w
, h
)
3513 int mouse_face_overwritten_p
= 0;
3515 TRACE ((stderr
, "expose_frame "));
3517 /* No need to redraw if frame will be redrawn soon. */
3518 if (FRAME_GARBAGED_P (f
))
3520 TRACE ((stderr
, " garbaged\n"));
3524 /* If basic faces haven't been realized yet, there is no point in
3525 trying to redraw anything. This can happen when we get an expose
3526 event while Emacs is starting, e.g. by moving another window. */
3527 if (FRAME_FACE_CACHE (f
) == NULL
3528 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
3530 TRACE ((stderr
, " no faces\n"));
3534 if (w
== 0 || h
== 0)
3537 r
.width
= CANON_X_UNIT (f
) * f
->width
;
3538 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
3548 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
3549 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
3551 if (WINDOWP (f
->tool_bar_window
))
3552 mouse_face_overwritten_p
3553 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
3555 #ifndef USE_X_TOOLKIT
3556 if (WINDOWP (f
->menu_bar_window
))
3557 mouse_face_overwritten_p
3558 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
3559 #endif /* not USE_X_TOOLKIT */
3561 /* Some window managers support a focus-follows-mouse style with
3562 delayed raising of frames. Imagine a partially obscured frame,
3563 and moving the mouse into partially obscured mouse-face on that
3564 frame. The visible part of the mouse-face will be highlighted,
3565 then the WM raises the obscured frame. With at least one WM, KDE
3566 2.1, Emacs is not getting any event for the raising of the frame
3567 (even tried with SubstructureRedirectMask), only Expose events.
3568 These expose events will draw text normally, i.e. not
3569 highlighted. Which means we must redo the highlight here.
3570 Subsume it under ``we love X''. --gerd 2001-08-15 */
3571 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
3573 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3574 if (f
== dpyinfo
->mouse_face_mouse_frame
)
3576 int x
= dpyinfo
->mouse_face_mouse_x
;
3577 int y
= dpyinfo
->mouse_face_mouse_y
;
3578 clear_mouse_face (dpyinfo
);
3579 note_mouse_highlight (f
, x
, y
);
3585 /* Redraw (parts) of all windows in the window tree rooted at W that
3586 intersect R. R contains frame pixel coordinates. Value is
3587 non-zero if the exposure overwrites mouse-face. */
3590 expose_window_tree (w
, r
)
3594 struct frame
*f
= XFRAME (w
->frame
);
3595 int mouse_face_overwritten_p
= 0;
3597 while (w
&& !FRAME_GARBAGED_P (f
))
3599 if (!NILP (w
->hchild
))
3600 mouse_face_overwritten_p
3601 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
3602 else if (!NILP (w
->vchild
))
3603 mouse_face_overwritten_p
3604 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
3606 mouse_face_overwritten_p
|= expose_window (w
, r
);
3608 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
3611 return mouse_face_overwritten_p
;
3615 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
3616 which intersects rectangle R. R is in window-relative coordinates. */
3619 expose_area (w
, row
, r
, area
)
3621 struct glyph_row
*row
;
3623 enum glyph_row_area area
;
3625 struct glyph
*first
= row
->glyphs
[area
];
3626 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
3628 int first_x
, start_x
, x
;
3630 if (area
== TEXT_AREA
&& row
->fill_line_p
)
3631 /* If row extends face to end of line write the whole line. */
3632 x_draw_glyphs (w
, 0, row
, area
, 0, row
->used
[area
],
3633 DRAW_NORMAL_TEXT
, 0);
3636 /* Set START_X to the window-relative start position for drawing glyphs of
3637 AREA. The first glyph of the text area can be partially visible.
3638 The first glyphs of other areas cannot. */
3639 if (area
== LEFT_MARGIN_AREA
)
3641 else if (area
== TEXT_AREA
)
3642 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
3644 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
3645 + window_box_width (w
, TEXT_AREA
));
3648 /* Find the first glyph that must be redrawn. */
3650 && x
+ first
->pixel_width
< r
->x
)
3652 x
+= first
->pixel_width
;
3656 /* Find the last one. */
3660 && x
< r
->x
+ r
->width
)
3662 x
+= last
->pixel_width
;
3668 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
3669 first
- row
->glyphs
[area
],
3670 last
- row
->glyphs
[area
],
3671 DRAW_NORMAL_TEXT
, 0);
3676 /* Redraw the parts of the glyph row ROW on window W intersecting
3677 rectangle R. R is in window-relative coordinates. Value is
3678 non-zero if mouse-face was overwritten. */
3681 expose_line (w
, row
, r
)
3683 struct glyph_row
*row
;
3686 xassert (row
->enabled_p
);
3688 if (row
->mode_line_p
|| w
->pseudo_window_p
)
3689 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
3690 DRAW_NORMAL_TEXT
, 0);
3693 if (row
->used
[LEFT_MARGIN_AREA
])
3694 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
3695 if (row
->used
[TEXT_AREA
])
3696 expose_area (w
, row
, r
, TEXT_AREA
);
3697 if (row
->used
[RIGHT_MARGIN_AREA
])
3698 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
3699 draw_row_fringe_bitmaps (w
, row
);
3702 return row
->mouse_face_p
;
3706 /* Return non-zero if W's cursor intersects rectangle R. */
3709 x_phys_cursor_in_rect_p (w
, r
)
3713 XRectangle cr
, result
;
3714 struct glyph
*cursor_glyph
;
3716 cursor_glyph
= get_phys_cursor_glyph (w
);
3719 cr
.x
= w
->phys_cursor
.x
;
3720 cr
.y
= w
->phys_cursor
.y
;
3721 cr
.width
= cursor_glyph
->pixel_width
;
3722 cr
.height
= w
->phys_cursor_height
;
3723 return x_intersect_rectangles (&cr
, r
, &result
);
3730 /* Redraw those parts of glyphs rows during expose event handling that
3731 overlap other rows. Redrawing of an exposed line writes over parts
3732 of lines overlapping that exposed line; this function fixes that.
3734 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
3735 row in W's current matrix that is exposed and overlaps other rows.
3736 LAST_OVERLAPPING_ROW is the last such row. */
3739 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
3741 struct glyph_row
*first_overlapping_row
;
3742 struct glyph_row
*last_overlapping_row
;
3744 struct glyph_row
*row
;
3746 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
3747 if (row
->overlapping_p
)
3749 xassert (row
->enabled_p
&& !row
->mode_line_p
);
3751 if (row
->used
[LEFT_MARGIN_AREA
])
3752 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
3754 if (row
->used
[TEXT_AREA
])
3755 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
3757 if (row
->used
[RIGHT_MARGIN_AREA
])
3758 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
3763 /* Redraw the part of window W intersection rectangle FR. Pixel
3764 coordinates in FR are frame-relative. Call this function with
3765 input blocked. Value is non-zero if the exposure overwrites
3769 expose_window (w
, fr
)
3773 struct frame
*f
= XFRAME (w
->frame
);
3775 int mouse_face_overwritten_p
= 0;
3777 /* If window is not yet fully initialized, do nothing. This can
3778 happen when toolkit scroll bars are used and a window is split.
3779 Reconfiguring the scroll bar will generate an expose for a newly
3781 if (w
->current_matrix
== NULL
)
3784 /* When we're currently updating the window, display and current
3785 matrix usually don't agree. Arrange for a thorough display
3787 if (w
== updated_window
)
3789 SET_FRAME_GARBAGED (f
);
3793 /* Frame-relative pixel rectangle of W. */
3794 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
3795 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
3796 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
3797 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
3799 if (x_intersect_rectangles (fr
, &wr
, &r
))
3801 int yb
= window_text_bottom_y (w
);
3802 struct glyph_row
*row
;
3803 int cursor_cleared_p
;
3804 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
3806 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
3807 r
.x
, r
.y
, r
.width
, r
.height
));
3809 /* Convert to window coordinates. */
3810 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
3811 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
3813 /* Turn off the cursor. */
3814 if (!w
->pseudo_window_p
3815 && x_phys_cursor_in_rect_p (w
, &r
))
3818 cursor_cleared_p
= 1;
3821 cursor_cleared_p
= 0;
3823 /* Update lines intersecting rectangle R. */
3824 first_overlapping_row
= last_overlapping_row
= NULL
;
3825 for (row
= w
->current_matrix
->rows
;
3830 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
3832 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
3833 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
3834 || (r
.y
>= y0
&& r
.y
< y1
)
3835 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
3837 if (row
->overlapping_p
)
3839 if (first_overlapping_row
== NULL
)
3840 first_overlapping_row
= row
;
3841 last_overlapping_row
= row
;
3844 if (expose_line (w
, row
, &r
))
3845 mouse_face_overwritten_p
= 1;
3852 /* Display the mode line if there is one. */
3853 if (WINDOW_WANTS_MODELINE_P (w
)
3854 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
3856 && row
->y
< r
.y
+ r
.height
)
3858 if (expose_line (w
, row
, &r
))
3859 mouse_face_overwritten_p
= 1;
3862 if (!w
->pseudo_window_p
)
3864 /* Fix the display of overlapping rows. */
3865 if (first_overlapping_row
)
3866 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
3868 /* Draw border between windows. */
3869 x_draw_vertical_border (w
);
3871 /* Turn the cursor on again. */
3872 if (cursor_cleared_p
)
3873 x_update_window_cursor (w
, 1);
3877 return mouse_face_overwritten_p
;
3881 /* Determine the intersection of two rectangles R1 and R2. Return
3882 the intersection in *RESULT. Value is non-zero if RESULT is not
3886 x_intersect_rectangles (r1
, r2
, result
)
3887 XRectangle
*r1
, *r2
, *result
;
3889 XRectangle
*left
, *right
;
3890 XRectangle
*upper
, *lower
;
3891 int intersection_p
= 0;
3893 /* Rearrange so that R1 is the left-most rectangle. */
3895 left
= r1
, right
= r2
;
3897 left
= r2
, right
= r1
;
3899 /* X0 of the intersection is right.x0, if this is inside R1,
3900 otherwise there is no intersection. */
3901 if (right
->x
<= left
->x
+ left
->width
)
3903 result
->x
= right
->x
;
3905 /* The right end of the intersection is the minimum of the
3906 the right ends of left and right. */
3907 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
3910 /* Same game for Y. */
3912 upper
= r1
, lower
= r2
;
3914 upper
= r2
, lower
= r1
;
3916 /* The upper end of the intersection is lower.y0, if this is inside
3917 of upper. Otherwise, there is no intersection. */
3918 if (lower
->y
<= upper
->y
+ upper
->height
)
3920 result
->y
= lower
->y
;
3922 /* The lower end of the intersection is the minimum of the lower
3923 ends of upper and lower. */
3924 result
->height
= (min (lower
->y
+ lower
->height
,
3925 upper
->y
+ upper
->height
)
3931 return intersection_p
;
3942 /* We used to only do this if Vx_no_window_manager was non-nil, but
3943 the ICCCM (section 4.1.6) says that the window's border pixmap
3944 and border pixel are window attributes which are "private to the
3945 client", so we can always change it to whatever we want. */
3947 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3948 f
->output_data
.x
->border_pixel
);
3950 x_update_cursor (f
, 1);
3954 frame_unhighlight (f
)
3957 /* We used to only do this if Vx_no_window_manager was non-nil, but
3958 the ICCCM (section 4.1.6) says that the window's border pixmap
3959 and border pixel are window attributes which are "private to the
3960 client", so we can always change it to whatever we want. */
3962 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3963 f
->output_data
.x
->border_tile
);
3965 x_update_cursor (f
, 1);
3968 /* The focus has changed. Update the frames as necessary to reflect
3969 the new situation. Note that we can't change the selected frame
3970 here, because the Lisp code we are interrupting might become confused.
3971 Each event gets marked with the frame in which it occurred, so the
3972 Lisp code can tell when the switch took place by examining the events. */
3975 x_new_focus_frame (dpyinfo
, frame
)
3976 struct x_display_info
*dpyinfo
;
3977 struct frame
*frame
;
3979 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3981 if (frame
!= dpyinfo
->x_focus_frame
)
3983 /* Set this before calling other routines, so that they see
3984 the correct value of x_focus_frame. */
3985 dpyinfo
->x_focus_frame
= frame
;
3987 if (old_focus
&& old_focus
->auto_lower
)
3988 x_lower_frame (old_focus
);
3991 selected_frame
= frame
;
3992 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3994 Fselect_window (selected_frame
->selected_window
);
3995 choose_minibuf_frame ();
3998 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3999 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
4001 pending_autoraise_frame
= 0;
4004 x_frame_rehighlight (dpyinfo
);
4007 /* Handle FocusIn and FocusOut state changes for FRAME.
4008 If FRAME has focus and there exists more than one frame, puts
4009 a FOCUS_IN_EVENT into BUFP.
4010 Returns number of events inserted into BUFP. */
4013 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
, numchars
)
4016 struct x_display_info
*dpyinfo
;
4017 struct frame
*frame
;
4018 struct input_event
*bufp
;
4023 if (type
== FocusIn
)
4025 if (dpyinfo
->x_focus_event_frame
!= frame
)
4027 x_new_focus_frame (dpyinfo
, frame
);
4028 dpyinfo
->x_focus_event_frame
= frame
;
4030 /* Don't stop displaying the initial startup message
4031 for a switch-frame event we don't need. */
4033 && GC_NILP (Vterminal_frame
)
4034 && GC_CONSP (Vframe_list
)
4035 && !GC_NILP (XCDR (Vframe_list
)))
4037 bufp
->kind
= FOCUS_IN_EVENT
;
4038 XSETFRAME (bufp
->frame_or_window
, frame
);
4046 frame
->output_data
.x
->focus_state
|= state
;
4049 if (FRAME_XIC (frame
))
4050 XSetICFocus (FRAME_XIC (frame
));
4053 else if (type
== FocusOut
)
4055 frame
->output_data
.x
->focus_state
&= ~state
;
4057 if (dpyinfo
->x_focus_event_frame
== frame
)
4059 dpyinfo
->x_focus_event_frame
= 0;
4060 x_new_focus_frame (dpyinfo
, 0);
4064 if (FRAME_XIC (frame
))
4065 XUnsetICFocus (FRAME_XIC (frame
));
4072 /* The focus may have changed. Figure out if it is a real focus change,
4073 by checking both FocusIn/Out and Enter/LeaveNotify events.
4075 Returns number of events inserted into BUFP. */
4078 x_detect_focus_change (dpyinfo
, event
, bufp
, numchars
)
4079 struct x_display_info
*dpyinfo
;
4081 struct input_event
*bufp
;
4084 struct frame
*frame
;
4087 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
4088 if (! frame
) return nr_events
;
4090 switch (event
->type
)
4094 if (event
->xcrossing
.detail
!= NotifyInferior
4095 && event
->xcrossing
.focus
4096 && ! (frame
->output_data
.x
->focus_state
& FOCUS_EXPLICIT
))
4097 nr_events
= x_focus_changed ((event
->type
== EnterNotify
4098 ? FocusIn
: FocusOut
),
4108 nr_events
= x_focus_changed (event
->type
,
4109 (event
->xfocus
.detail
== NotifyPointer
4110 ? FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
4122 /* Handle an event saying the mouse has moved out of an Emacs frame. */
4125 x_mouse_leave (dpyinfo
)
4126 struct x_display_info
*dpyinfo
;
4128 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
4131 /* The focus has changed, or we have redirected a frame's focus to
4132 another frame (this happens when a frame uses a surrogate
4133 mini-buffer frame). Shift the highlight as appropriate.
4135 The FRAME argument doesn't necessarily have anything to do with which
4136 frame is being highlighted or un-highlighted; we only use it to find
4137 the appropriate X display info. */
4140 XTframe_rehighlight (frame
)
4141 struct frame
*frame
;
4143 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
4147 x_frame_rehighlight (dpyinfo
)
4148 struct x_display_info
*dpyinfo
;
4150 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
4152 if (dpyinfo
->x_focus_frame
)
4154 dpyinfo
->x_highlight_frame
4155 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
4156 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
4157 : dpyinfo
->x_focus_frame
);
4158 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
4160 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
4161 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
4165 dpyinfo
->x_highlight_frame
= 0;
4167 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
4170 frame_unhighlight (old_highlight
);
4171 if (dpyinfo
->x_highlight_frame
)
4172 frame_highlight (dpyinfo
->x_highlight_frame
);
4178 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
4180 /* Initialize mode_switch_bit and modifier_meaning. */
4182 x_find_modifier_meanings (dpyinfo
)
4183 struct x_display_info
*dpyinfo
;
4185 int min_code
, max_code
;
4188 XModifierKeymap
*mods
;
4190 dpyinfo
->meta_mod_mask
= 0;
4191 dpyinfo
->shift_lock_mask
= 0;
4192 dpyinfo
->alt_mod_mask
= 0;
4193 dpyinfo
->super_mod_mask
= 0;
4194 dpyinfo
->hyper_mod_mask
= 0;
4197 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
4199 min_code
= dpyinfo
->display
->min_keycode
;
4200 max_code
= dpyinfo
->display
->max_keycode
;
4203 syms
= XGetKeyboardMapping (dpyinfo
->display
,
4204 min_code
, max_code
- min_code
+ 1,
4206 mods
= XGetModifierMapping (dpyinfo
->display
);
4208 /* Scan the modifier table to see which modifier bits the Meta and
4209 Alt keysyms are on. */
4211 int row
, col
; /* The row and column in the modifier table. */
4213 for (row
= 3; row
< 8; row
++)
4214 for (col
= 0; col
< mods
->max_keypermod
; col
++)
4217 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
4219 /* Zeroes are used for filler. Skip them. */
4223 /* Are any of this keycode's keysyms a meta key? */
4227 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
4229 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
4235 dpyinfo
->meta_mod_mask
|= (1 << row
);
4240 dpyinfo
->alt_mod_mask
|= (1 << row
);
4245 dpyinfo
->hyper_mod_mask
|= (1 << row
);
4250 dpyinfo
->super_mod_mask
|= (1 << row
);
4254 /* Ignore this if it's not on the lock modifier. */
4255 if ((1 << row
) == LockMask
)
4256 dpyinfo
->shift_lock_mask
= LockMask
;
4264 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
4265 if (! dpyinfo
->meta_mod_mask
)
4267 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
4268 dpyinfo
->alt_mod_mask
= 0;
4271 /* If some keys are both alt and meta,
4272 make them just meta, not alt. */
4273 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
4275 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
4278 XFree ((char *) syms
);
4279 XFreeModifiermap (mods
);
4282 /* Convert between the modifier bits X uses and the modifier bits
4286 x_x_to_emacs_modifiers (dpyinfo
, state
)
4287 struct x_display_info
*dpyinfo
;
4290 EMACS_UINT mod_meta
= meta_modifier
;
4291 EMACS_UINT mod_alt
= alt_modifier
;
4292 EMACS_UINT mod_hyper
= hyper_modifier
;
4293 EMACS_UINT mod_super
= super_modifier
;
4296 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
4297 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
4298 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
4299 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
4300 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
4301 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
4302 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
4303 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
4306 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
4307 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
4308 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
4309 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
4310 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
4311 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
4315 x_emacs_to_x_modifiers (dpyinfo
, state
)
4316 struct x_display_info
*dpyinfo
;
4319 EMACS_UINT mod_meta
= meta_modifier
;
4320 EMACS_UINT mod_alt
= alt_modifier
;
4321 EMACS_UINT mod_hyper
= hyper_modifier
;
4322 EMACS_UINT mod_super
= super_modifier
;
4326 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
4327 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
4328 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
4329 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
4330 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
4331 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
4332 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
4333 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
4336 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
4337 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
4338 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
4339 | ((state
& shift_modifier
) ? ShiftMask
: 0)
4340 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
4341 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
4344 /* Convert a keysym to its name. */
4347 x_get_keysym_name (keysym
)
4353 value
= XKeysymToString (keysym
);
4361 /* Mouse clicks and mouse movement. Rah. */
4363 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
4364 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
4365 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
4366 not force the value into range. */
4369 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
4371 register int pix_x
, pix_y
;
4372 register int *x
, *y
;
4376 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
4377 even for negative values. */
4379 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
4381 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
4383 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
4384 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
4388 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
4389 bounds
->height
= f
->output_data
.x
->line_height
;
4390 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
4391 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
4398 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
4399 pix_x
= FRAME_WINDOW_WIDTH (f
);
4403 else if (pix_y
> f
->height
)
4412 /* Given HPOS/VPOS in the current matrix of W, return corresponding
4413 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
4414 can't tell the positions because W's display is not up to date,
4418 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
4421 int *frame_x
, *frame_y
;
4425 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
4426 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
4428 if (display_completed
)
4430 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
4431 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
4432 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
4438 *frame_x
+= glyph
->pixel_width
;
4446 *frame_y
= *frame_x
= 0;
4450 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
4451 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
4456 /* Prepare a mouse-event in *RESULT for placement in the input queue.
4458 If the event is a button press, then note that we have grabbed
4462 construct_mouse_click (result
, event
, f
)
4463 struct input_event
*result
;
4464 XButtonEvent
*event
;
4467 /* Make the event type NO_EVENT; we'll change that when we decide
4469 result
->kind
= MOUSE_CLICK_EVENT
;
4470 result
->code
= event
->button
- Button1
;
4471 result
->timestamp
= event
->time
;
4472 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
4474 | (event
->type
== ButtonRelease
4478 XSETINT (result
->x
, event
->x
);
4479 XSETINT (result
->y
, event
->y
);
4480 XSETFRAME (result
->frame_or_window
, f
);
4486 /* Function to report a mouse movement to the mainstream Emacs code.
4487 The input handler calls this.
4489 We have received a mouse movement event, which is given in *event.
4490 If the mouse is over a different glyph than it was last time, tell
4491 the mainstream emacs code by setting mouse_moved. If not, ask for
4492 another motion event, so we can check again the next time it moves. */
4494 static XMotionEvent last_mouse_motion_event
;
4495 static Lisp_Object last_mouse_motion_frame
;
4498 note_mouse_movement (frame
, event
)
4500 XMotionEvent
*event
;
4502 last_mouse_movement_time
= event
->time
;
4503 last_mouse_motion_event
= *event
;
4504 XSETFRAME (last_mouse_motion_frame
, frame
);
4506 if (event
->window
!= FRAME_X_WINDOW (frame
))
4508 frame
->mouse_moved
= 1;
4509 last_mouse_scroll_bar
= Qnil
;
4510 note_mouse_highlight (frame
, -1, -1);
4513 /* Has the mouse moved off the glyph it was on at the last sighting? */
4514 else if (event
->x
< last_mouse_glyph
.x
4515 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
4516 || event
->y
< last_mouse_glyph
.y
4517 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
4519 frame
->mouse_moved
= 1;
4520 last_mouse_scroll_bar
= Qnil
;
4521 note_mouse_highlight (frame
, event
->x
, event
->y
);
4526 /************************************************************************
4528 ************************************************************************/
4530 /* Find the glyph under window-relative coordinates X/Y in window W.
4531 Consider only glyphs from buffer text, i.e. no glyphs from overlay
4532 strings. Return in *HPOS and *VPOS the row and column number of
4533 the glyph found. Return in *AREA the glyph area containing X.
4534 Value is a pointer to the glyph found or null if X/Y is not on
4535 text, or we can't tell because W's current matrix is not up to
4538 static struct glyph
*
4539 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
4542 int *hpos
, *vpos
, *area
;
4545 struct glyph
*glyph
, *end
;
4546 struct glyph_row
*row
= NULL
;
4547 int x0
, i
, left_area_width
;
4549 /* Find row containing Y. Give up if some row is not enabled. */
4550 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
4552 row
= MATRIX_ROW (w
->current_matrix
, i
);
4553 if (!row
->enabled_p
)
4555 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
4562 /* Give up if Y is not in the window. */
4563 if (i
== w
->current_matrix
->nrows
)
4566 /* Get the glyph area containing X. */
4567 if (w
->pseudo_window_p
)
4574 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
4575 if (x
< left_area_width
)
4577 *area
= LEFT_MARGIN_AREA
;
4580 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
4583 x0
= row
->x
+ left_area_width
;
4587 *area
= RIGHT_MARGIN_AREA
;
4588 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
4592 /* Find glyph containing X. */
4593 glyph
= row
->glyphs
[*area
];
4594 end
= glyph
+ row
->used
[*area
];
4597 if (x
< x0
+ glyph
->pixel_width
)
4599 if (w
->pseudo_window_p
)
4601 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
4605 x0
+= glyph
->pixel_width
;
4612 *hpos
= glyph
- row
->glyphs
[*area
];
4617 /* Convert frame-relative x/y to coordinates relative to window W.
4618 Takes pseudo-windows into account. */
4621 frame_to_window_pixel_xy (w
, x
, y
)
4625 if (w
->pseudo_window_p
)
4627 /* A pseudo-window is always full-width, and starts at the
4628 left edge of the frame, plus a frame border. */
4629 struct frame
*f
= XFRAME (w
->frame
);
4630 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
4631 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
4635 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
4636 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
4641 /* Take proper action when mouse has moved to the mode or header line
4642 or marginal area of window W, x-position X and y-position Y. Area
4643 is 1, 3, 6 or 7 for the mode line, header line, left and right
4644 marginal area respectively. X is relative to the start of the text
4645 display area of W, so the width of bitmap areas and scroll bars
4646 must be subtracted to get a position relative to the start of the
4650 note_mode_line_or_margin_highlight (w
, x
, y
, portion
)
4654 struct frame
*f
= XFRAME (w
->frame
);
4655 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4656 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
4658 Lisp_Object string
, help
, map
, pos
;
4660 if (portion
== 1 || portion
== 3)
4661 string
= mode_line_string (w
, x
, y
, portion
== 1, &charpos
);
4663 string
= marginal_area_string (w
, x
, y
, portion
, &charpos
);
4665 if (STRINGP (string
))
4667 pos
= make_number (charpos
);
4669 /* If we're on a string with `help-echo' text property, arrange
4670 for the help to be displayed. This is done by setting the
4671 global variable help_echo to the help string. */
4672 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
4676 XSETWINDOW (help_echo_window
, w
);
4677 help_echo_object
= string
;
4678 help_echo_pos
= charpos
;
4681 /* Change the mouse pointer according to what is under X/Y. */
4682 map
= Fget_text_property (pos
, Qlocal_map
, string
);
4684 map
= Fget_text_property (pos
, Qkeymap
, string
);
4686 cursor
= f
->output_data
.x
->nontext_cursor
;
4689 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
4693 /* Take proper action when the mouse has moved to position X, Y on
4694 frame F as regards highlighting characters that have mouse-face
4695 properties. Also de-highlighting chars where the mouse was before.
4696 X and Y can be negative or out of range. */
4699 note_mouse_highlight (f
, x
, y
)
4703 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4707 Cursor cursor
= None
;
4710 /* When a menu is active, don't highlight because this looks odd. */
4711 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
4712 if (popup_activated ())
4716 if (NILP (Vmouse_highlight
)
4717 || !f
->glyphs_initialized_p
)
4720 dpyinfo
->mouse_face_mouse_x
= x
;
4721 dpyinfo
->mouse_face_mouse_y
= y
;
4722 dpyinfo
->mouse_face_mouse_frame
= f
;
4724 if (dpyinfo
->mouse_face_defer
)
4729 dpyinfo
->mouse_face_deferred_gc
= 1;
4733 /* Which window is that in? */
4734 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
4736 /* If we were displaying active text in another window, clear that. */
4737 if (! EQ (window
, dpyinfo
->mouse_face_window
))
4738 clear_mouse_face (dpyinfo
);
4740 /* Not on a window -> return. */
4741 if (!WINDOWP (window
))
4744 /* Convert to window-relative pixel coordinates. */
4745 w
= XWINDOW (window
);
4746 frame_to_window_pixel_xy (w
, &x
, &y
);
4748 /* Handle tool-bar window differently since it doesn't display a
4750 if (EQ (window
, f
->tool_bar_window
))
4752 note_tool_bar_highlight (f
, x
, y
);
4756 /* Mouse is on the mode, header line or margin? */
4757 if (portion
== 1 || portion
== 3 || portion
== 6 || portion
== 7)
4759 note_mode_line_or_margin_highlight (w
, x
, y
, portion
);
4764 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
4766 cursor
= f
->output_data
.x
->text_cursor
;
4768 /* Are we in a window whose display is up to date?
4769 And verify the buffer's text has not changed. */
4770 b
= XBUFFER (w
->buffer
);
4771 if (/* Within text portion of the window. */
4773 && EQ (w
->window_end_valid
, w
->buffer
)
4774 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
4775 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
4777 int hpos
, vpos
, pos
, i
, area
;
4778 struct glyph
*glyph
;
4780 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
4781 Lisp_Object
*overlay_vec
= NULL
;
4783 struct buffer
*obuf
;
4784 int obegv
, ozv
, same_region
;
4786 /* Find the glyph under X/Y. */
4787 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
4789 /* Clear mouse face if X/Y not over text. */
4791 || area
!= TEXT_AREA
4792 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
4794 if (clear_mouse_face (dpyinfo
))
4799 pos
= glyph
->charpos
;
4800 object
= glyph
->object
;
4801 if (!STRINGP (object
) && !BUFFERP (object
))
4804 /* If we get an out-of-range value, return now; avoid an error. */
4805 if (BUFFERP (object
) && pos
> BUF_Z (b
))
4808 /* Make the window's buffer temporarily current for
4809 overlays_at and compute_char_face. */
4810 obuf
= current_buffer
;
4817 /* Is this char mouse-active or does it have help-echo? */
4818 position
= make_number (pos
);
4820 if (BUFFERP (object
))
4822 /* Put all the overlays we want in a vector in overlay_vec.
4823 Store the length in len. If there are more than 10, make
4824 enough space for all, and try again. */
4826 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
4827 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
4828 if (noverlays
> len
)
4831 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
4832 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
4835 /* Sort overlays into increasing priority order. */
4836 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
4841 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
4842 && vpos
>= dpyinfo
->mouse_face_beg_row
4843 && vpos
<= dpyinfo
->mouse_face_end_row
4844 && (vpos
> dpyinfo
->mouse_face_beg_row
4845 || hpos
>= dpyinfo
->mouse_face_beg_col
)
4846 && (vpos
< dpyinfo
->mouse_face_end_row
4847 || hpos
< dpyinfo
->mouse_face_end_col
4848 || dpyinfo
->mouse_face_past_end
));
4853 /* Check mouse-face highlighting. */
4855 /* If there exists an overlay with mouse-face overlapping
4856 the one we are currently highlighting, we have to
4857 check if we enter the overlapping overlay, and then
4858 highlight only that. */
4859 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
4860 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
4862 /* Find the highest priority overlay that has a mouse-face
4865 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
4867 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
4868 if (!NILP (mouse_face
))
4869 overlay
= overlay_vec
[i
];
4872 /* If we're actually highlighting the same overlay as
4873 before, there's no need to do that again. */
4875 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
4876 goto check_help_echo
;
4878 dpyinfo
->mouse_face_overlay
= overlay
;
4880 /* Clear the display of the old active region, if any. */
4881 if (clear_mouse_face (dpyinfo
))
4884 /* If no overlay applies, get a text property. */
4886 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
4888 /* Handle the overlay case. */
4889 if (!NILP (overlay
))
4891 /* Find the range of text around this char that
4892 should be active. */
4893 Lisp_Object before
, after
;
4896 before
= Foverlay_start (overlay
);
4897 after
= Foverlay_end (overlay
);
4898 /* Record this as the current active region. */
4899 fast_find_position (w
, XFASTINT (before
),
4900 &dpyinfo
->mouse_face_beg_col
,
4901 &dpyinfo
->mouse_face_beg_row
,
4902 &dpyinfo
->mouse_face_beg_x
,
4903 &dpyinfo
->mouse_face_beg_y
, Qnil
);
4905 dpyinfo
->mouse_face_past_end
4906 = !fast_find_position (w
, XFASTINT (after
),
4907 &dpyinfo
->mouse_face_end_col
,
4908 &dpyinfo
->mouse_face_end_row
,
4909 &dpyinfo
->mouse_face_end_x
,
4910 &dpyinfo
->mouse_face_end_y
, Qnil
);
4911 dpyinfo
->mouse_face_window
= window
;
4912 dpyinfo
->mouse_face_face_id
4913 = face_at_buffer_position (w
, pos
, 0, 0,
4915 !dpyinfo
->mouse_face_hidden
);
4917 /* Display it as active. */
4918 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
4921 /* Handle the text property case. */
4922 else if (!NILP (mouse_face
) && BUFFERP (object
))
4924 /* Find the range of text around this char that
4925 should be active. */
4926 Lisp_Object before
, after
, beginning
, end
;
4929 beginning
= Fmarker_position (w
->start
);
4930 end
= make_number (BUF_Z (XBUFFER (object
))
4931 - XFASTINT (w
->window_end_pos
));
4933 = Fprevious_single_property_change (make_number (pos
+ 1),
4937 = Fnext_single_property_change (position
, Qmouse_face
,
4940 /* Record this as the current active region. */
4941 fast_find_position (w
, XFASTINT (before
),
4942 &dpyinfo
->mouse_face_beg_col
,
4943 &dpyinfo
->mouse_face_beg_row
,
4944 &dpyinfo
->mouse_face_beg_x
,
4945 &dpyinfo
->mouse_face_beg_y
, Qnil
);
4946 dpyinfo
->mouse_face_past_end
4947 = !fast_find_position (w
, XFASTINT (after
),
4948 &dpyinfo
->mouse_face_end_col
,
4949 &dpyinfo
->mouse_face_end_row
,
4950 &dpyinfo
->mouse_face_end_x
,
4951 &dpyinfo
->mouse_face_end_y
, Qnil
);
4952 dpyinfo
->mouse_face_window
= window
;
4954 if (BUFFERP (object
))
4955 dpyinfo
->mouse_face_face_id
4956 = face_at_buffer_position (w
, pos
, 0, 0,
4958 !dpyinfo
->mouse_face_hidden
);
4960 /* Display it as active. */
4961 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
4964 else if (!NILP (mouse_face
) && STRINGP (object
))
4969 b
= Fprevious_single_property_change (make_number (pos
+ 1),
4972 e
= Fnext_single_property_change (position
, Qmouse_face
,
4975 b
= make_number (0);
4977 e
= make_number (SCHARS (object
) - 1);
4978 fast_find_string_pos (w
, XINT (b
), object
,
4979 &dpyinfo
->mouse_face_beg_col
,
4980 &dpyinfo
->mouse_face_beg_row
,
4981 &dpyinfo
->mouse_face_beg_x
,
4982 &dpyinfo
->mouse_face_beg_y
, 0);
4983 fast_find_string_pos (w
, XINT (e
), object
,
4984 &dpyinfo
->mouse_face_end_col
,
4985 &dpyinfo
->mouse_face_end_row
,
4986 &dpyinfo
->mouse_face_end_x
,
4987 &dpyinfo
->mouse_face_end_y
, 1);
4988 dpyinfo
->mouse_face_past_end
= 0;
4989 dpyinfo
->mouse_face_window
= window
;
4990 dpyinfo
->mouse_face_face_id
4991 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
4993 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
4996 else if (STRINGP (object
) && NILP (mouse_face
))
4998 /* A string which doesn't have mouse-face, but
4999 the text ``under'' it might have. */
5000 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
5001 int start
= MATRIX_ROW_START_CHARPOS (r
);
5003 pos
= string_buffer_position (w
, object
, start
);
5005 mouse_face
= get_char_property_and_overlay (make_number (pos
),
5009 if (!NILP (mouse_face
) && !NILP (overlay
))
5011 Lisp_Object before
= Foverlay_start (overlay
);
5012 Lisp_Object after
= Foverlay_end (overlay
);
5015 /* Note that we might not be able to find position
5016 BEFORE in the glyph matrix if the overlay is
5017 entirely covered by a `display' property. In
5018 this case, we overshoot. So let's stop in
5019 the glyph matrix before glyphs for OBJECT. */
5020 fast_find_position (w
, XFASTINT (before
),
5021 &dpyinfo
->mouse_face_beg_col
,
5022 &dpyinfo
->mouse_face_beg_row
,
5023 &dpyinfo
->mouse_face_beg_x
,
5024 &dpyinfo
->mouse_face_beg_y
,
5027 dpyinfo
->mouse_face_past_end
5028 = !fast_find_position (w
, XFASTINT (after
),
5029 &dpyinfo
->mouse_face_end_col
,
5030 &dpyinfo
->mouse_face_end_row
,
5031 &dpyinfo
->mouse_face_end_x
,
5032 &dpyinfo
->mouse_face_end_y
,
5034 dpyinfo
->mouse_face_window
= window
;
5035 dpyinfo
->mouse_face_face_id
5036 = face_at_buffer_position (w
, pos
, 0, 0,
5038 !dpyinfo
->mouse_face_hidden
);
5040 /* Display it as active. */
5041 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
5049 /* Look for a `help-echo' property. */
5051 Lisp_Object help
, overlay
;
5053 /* Check overlays first. */
5054 help
= overlay
= Qnil
;
5055 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
5057 overlay
= overlay_vec
[i
];
5058 help
= Foverlay_get (overlay
, Qhelp_echo
);
5064 help_echo_window
= window
;
5065 help_echo_object
= overlay
;
5066 help_echo_pos
= pos
;
5070 Lisp_Object object
= glyph
->object
;
5071 int charpos
= glyph
->charpos
;
5073 /* Try text properties. */
5074 if (STRINGP (object
)
5076 && charpos
< SCHARS (object
))
5078 help
= Fget_text_property (make_number (charpos
),
5079 Qhelp_echo
, object
);
5082 /* If the string itself doesn't specify a help-echo,
5083 see if the buffer text ``under'' it does. */
5085 = MATRIX_ROW (w
->current_matrix
, vpos
);
5086 int start
= MATRIX_ROW_START_CHARPOS (r
);
5087 int pos
= string_buffer_position (w
, object
, start
);
5090 help
= Fget_char_property (make_number (pos
),
5091 Qhelp_echo
, w
->buffer
);
5100 else if (BUFFERP (object
)
5103 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
5109 help_echo_window
= window
;
5110 help_echo_object
= object
;
5111 help_echo_pos
= charpos
;
5118 current_buffer
= obuf
;
5124 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
5128 redo_mouse_highlight ()
5130 if (!NILP (last_mouse_motion_frame
)
5131 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
5132 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
5133 last_mouse_motion_event
.x
,
5134 last_mouse_motion_event
.y
);
5139 /***********************************************************************
5141 ***********************************************************************/
5143 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
5144 struct glyph
**, int *, int *, int *));
5146 /* Tool-bar item index of the item on which a mouse button was pressed
5149 static int last_tool_bar_item
;
5152 /* Get information about the tool-bar item at position X/Y on frame F.
5153 Return in *GLYPH a pointer to the glyph of the tool-bar item in
5154 the current matrix of the tool-bar window of F, or NULL if not
5155 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
5156 item in F->tool_bar_items. Value is
5158 -1 if X/Y is not on a tool-bar item
5159 0 if X/Y is on the same item that was highlighted before.
5163 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
5166 struct glyph
**glyph
;
5167 int *hpos
, *vpos
, *prop_idx
;
5169 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5170 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5173 /* Find the glyph under X/Y. */
5174 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
5178 /* Get the start of this tool-bar item's properties in
5179 f->tool_bar_items. */
5180 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
5183 /* Is mouse on the highlighted item? */
5184 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
5185 && *vpos
>= dpyinfo
->mouse_face_beg_row
5186 && *vpos
<= dpyinfo
->mouse_face_end_row
5187 && (*vpos
> dpyinfo
->mouse_face_beg_row
5188 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
5189 && (*vpos
< dpyinfo
->mouse_face_end_row
5190 || *hpos
< dpyinfo
->mouse_face_end_col
5191 || dpyinfo
->mouse_face_past_end
))
5198 /* Handle mouse button event on the tool-bar of frame F, at
5199 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
5203 x_handle_tool_bar_click (f
, button_event
)
5205 XButtonEvent
*button_event
;
5207 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5208 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5209 int hpos
, vpos
, prop_idx
;
5210 struct glyph
*glyph
;
5211 Lisp_Object enabled_p
;
5212 int x
= button_event
->x
;
5213 int y
= button_event
->y
;
5215 /* If not on the highlighted tool-bar item, return. */
5216 frame_to_window_pixel_xy (w
, &x
, &y
);
5217 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
5220 /* If item is disabled, do nothing. */
5221 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
5222 if (NILP (enabled_p
))
5225 if (button_event
->type
== ButtonPress
)
5227 /* Show item in pressed state. */
5228 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
5229 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
5230 last_tool_bar_item
= prop_idx
;
5234 Lisp_Object key
, frame
;
5235 struct input_event event
;
5237 /* Show item in released state. */
5238 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
5239 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
5241 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
5243 XSETFRAME (frame
, f
);
5244 event
.kind
= TOOL_BAR_EVENT
;
5245 event
.frame_or_window
= frame
;
5247 kbd_buffer_store_event (&event
);
5249 event
.kind
= TOOL_BAR_EVENT
;
5250 event
.frame_or_window
= frame
;
5252 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
5253 button_event
->state
);
5254 kbd_buffer_store_event (&event
);
5255 last_tool_bar_item
= -1;
5260 /* Possibly highlight a tool-bar item on frame F when mouse moves to
5261 tool-bar window-relative coordinates X/Y. Called from
5262 note_mouse_highlight. */
5265 note_tool_bar_highlight (f
, x
, y
)
5269 Lisp_Object window
= f
->tool_bar_window
;
5270 struct window
*w
= XWINDOW (window
);
5271 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5273 struct glyph
*glyph
;
5274 struct glyph_row
*row
;
5276 Lisp_Object enabled_p
;
5278 enum draw_glyphs_face draw
;
5279 int mouse_down_p
, rc
;
5281 /* Function note_mouse_highlight is called with negative x(y
5282 values when mouse moves outside of the frame. */
5283 if (x
<= 0 || y
<= 0)
5285 clear_mouse_face (dpyinfo
);
5289 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
5292 /* Not on tool-bar item. */
5293 clear_mouse_face (dpyinfo
);
5299 clear_mouse_face (dpyinfo
);
5301 /* Mouse is down, but on different tool-bar item? */
5302 mouse_down_p
= (dpyinfo
->grabbed
5303 && f
== last_mouse_frame
5304 && FRAME_LIVE_P (f
));
5306 && last_tool_bar_item
!= prop_idx
)
5309 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
5310 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
5312 /* If tool-bar item is not enabled, don't highlight it. */
5313 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
5314 if (!NILP (enabled_p
))
5316 /* Compute the x-position of the glyph. In front and past the
5317 image is a space. We include this is the highlighted area. */
5318 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
5319 for (i
= x
= 0; i
< hpos
; ++i
)
5320 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
5322 /* Record this as the current active region. */
5323 dpyinfo
->mouse_face_beg_col
= hpos
;
5324 dpyinfo
->mouse_face_beg_row
= vpos
;
5325 dpyinfo
->mouse_face_beg_x
= x
;
5326 dpyinfo
->mouse_face_beg_y
= row
->y
;
5327 dpyinfo
->mouse_face_past_end
= 0;
5329 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
5330 dpyinfo
->mouse_face_end_row
= vpos
;
5331 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
5332 dpyinfo
->mouse_face_end_y
= row
->y
;
5333 dpyinfo
->mouse_face_window
= window
;
5334 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
5336 /* Display it as active. */
5337 show_mouse_face (dpyinfo
, draw
);
5338 dpyinfo
->mouse_face_image_state
= draw
;
5343 /* Set help_echo to a help string to display for this tool-bar item.
5344 XTread_socket does the rest. */
5345 help_echo_object
= help_echo_window
= Qnil
;
5347 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
5348 if (NILP (help_echo
))
5349 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
5354 /* Find the glyph matrix position of buffer position CHARPOS in window
5355 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
5356 current glyphs must be up to date. If CHARPOS is above window
5357 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
5358 of last line in W. In the row containing CHARPOS, stop before glyphs
5359 having STOP as object. */
5361 #if 0 /* This is a version of fast_find_position that's more correct
5362 in the presence of hscrolling, for example. I didn't install
5363 it right away because the problem fixed is minor, it failed
5364 in 20.x as well, and I think it's too risky to install
5365 so near the release of 21.1. 2001-09-25 gerd. */
5368 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
5371 int *hpos
, *vpos
, *x
, *y
;
5374 struct glyph_row
*row
, *first
;
5375 struct glyph
*glyph
, *end
;
5376 int i
, past_end
= 0;
5378 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
5379 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
5382 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
5384 *x
= *y
= *hpos
= *vpos
= 0;
5389 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
5396 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
5398 glyph
= row
->glyphs
[TEXT_AREA
];
5399 end
= glyph
+ row
->used
[TEXT_AREA
];
5401 /* Skip over glyphs not having an object at the start of the row.
5402 These are special glyphs like truncation marks on terminal
5404 if (row
->displays_text_p
)
5406 && INTEGERP (glyph
->object
)
5407 && !EQ (stop
, glyph
->object
)
5408 && glyph
->charpos
< 0)
5410 *x
+= glyph
->pixel_width
;
5415 && !INTEGERP (glyph
->object
)
5416 && !EQ (stop
, glyph
->object
)
5417 && (!BUFFERP (glyph
->object
)
5418 || glyph
->charpos
< charpos
))
5420 *x
+= glyph
->pixel_width
;
5424 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
5431 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
5434 int *hpos
, *vpos
, *x
, *y
;
5439 int maybe_next_line_p
= 0;
5440 int line_start_position
;
5441 int yb
= window_text_bottom_y (w
);
5442 struct glyph_row
*row
, *best_row
;
5443 int row_vpos
, best_row_vpos
;
5446 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
5447 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
5451 if (row
->used
[TEXT_AREA
])
5452 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
5454 line_start_position
= 0;
5456 if (line_start_position
> pos
)
5458 /* If the position sought is the end of the buffer,
5459 don't include the blank lines at the bottom of the window. */
5460 else if (line_start_position
== pos
5461 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
5463 maybe_next_line_p
= 1;
5466 else if (line_start_position
> 0)
5469 best_row_vpos
= row_vpos
;
5472 if (row
->y
+ row
->height
>= yb
)
5479 /* Find the right column within BEST_ROW. */
5481 current_x
= best_row
->x
;
5482 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
5484 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
5485 int charpos
= glyph
->charpos
;
5487 if (BUFFERP (glyph
->object
))
5492 *vpos
= best_row_vpos
;
5497 else if (charpos
> pos
)
5500 else if (EQ (glyph
->object
, stop
))
5505 current_x
+= glyph
->pixel_width
;
5508 /* If we're looking for the end of the buffer,
5509 and we didn't find it in the line we scanned,
5510 use the start of the following line. */
5511 if (maybe_next_line_p
)
5516 current_x
= best_row
->x
;
5519 *vpos
= best_row_vpos
;
5520 *hpos
= lastcol
+ 1;
5529 /* Find the position of the glyph for position POS in OBJECT in
5530 window W's current matrix, and return in *X, *Y the pixel
5531 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
5533 RIGHT_P non-zero means return the position of the right edge of the
5534 glyph, RIGHT_P zero means return the left edge position.
5536 If no glyph for POS exists in the matrix, return the position of
5537 the glyph with the next smaller position that is in the matrix, if
5538 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
5539 exists in the matrix, return the position of the glyph with the
5540 next larger position in OBJECT.
5542 Value is non-zero if a glyph was found. */
5545 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
5549 int *hpos
, *vpos
, *x
, *y
;
5552 int yb
= window_text_bottom_y (w
);
5553 struct glyph_row
*r
;
5554 struct glyph
*best_glyph
= NULL
;
5555 struct glyph_row
*best_row
= NULL
;
5558 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
5559 r
->enabled_p
&& r
->y
< yb
;
5562 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
5563 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
5566 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
5567 if (EQ (g
->object
, object
))
5569 if (g
->charpos
== pos
)
5576 else if (best_glyph
== NULL
5577 || ((abs (g
->charpos
- pos
)
5578 < abs (best_glyph
->charpos
- pos
))
5581 : g
->charpos
> pos
)))
5595 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
5599 *x
+= best_glyph
->pixel_width
;
5604 *vpos
= best_row
- w
->current_matrix
->rows
;
5607 return best_glyph
!= NULL
;
5611 /* Display the active region described by mouse_face_*
5612 in its mouse-face if HL > 0, in its normal face if HL = 0. */
5615 show_mouse_face (dpyinfo
, draw
)
5616 struct x_display_info
*dpyinfo
;
5617 enum draw_glyphs_face draw
;
5619 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
5620 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
5622 if (/* If window is in the process of being destroyed, don't bother
5624 w
->current_matrix
!= NULL
5625 /* Don't update mouse highlight if hidden */
5626 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
5627 /* Recognize when we are called to operate on rows that don't exist
5628 anymore. This can happen when a window is split. */
5629 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
5631 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
5632 struct glyph_row
*row
, *first
, *last
;
5634 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
5635 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
5637 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
5639 int start_hpos
, end_hpos
, start_x
;
5641 /* For all but the first row, the highlight starts at column 0. */
5644 start_hpos
= dpyinfo
->mouse_face_beg_col
;
5645 start_x
= dpyinfo
->mouse_face_beg_x
;
5654 end_hpos
= dpyinfo
->mouse_face_end_col
;
5656 end_hpos
= row
->used
[TEXT_AREA
];
5658 if (end_hpos
> start_hpos
)
5660 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
5661 start_hpos
, end_hpos
, draw
, 0);
5664 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
5668 /* When we've written over the cursor, arrange for it to
5669 be displayed again. */
5670 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
5671 x_display_cursor (w
, 1,
5672 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
5673 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
5676 /* Change the mouse cursor. */
5677 if (draw
== DRAW_NORMAL_TEXT
)
5678 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5679 f
->output_data
.x
->text_cursor
);
5680 else if (draw
== DRAW_MOUSE_FACE
)
5681 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5682 f
->output_data
.x
->cross_cursor
);
5684 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5685 f
->output_data
.x
->nontext_cursor
);
5688 /* Clear out the mouse-highlighted active region.
5689 Redraw it un-highlighted first. Value is non-zero if mouse
5690 face was actually drawn unhighlighted. */
5693 clear_mouse_face (dpyinfo
)
5694 struct x_display_info
*dpyinfo
;
5698 if (!NILP (dpyinfo
->mouse_face_window
))
5700 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
5704 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
5705 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
5706 dpyinfo
->mouse_face_window
= Qnil
;
5707 dpyinfo
->mouse_face_overlay
= Qnil
;
5712 /* Clear any mouse-face on window W. This function is part of the
5713 redisplay interface, and is called from try_window_id and similar
5714 functions to ensure the mouse-highlight is off. */
5717 x_clear_mouse_face (w
)
5720 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
5724 XSETWINDOW (window
, w
);
5725 if (EQ (window
, dpyinfo
->mouse_face_window
))
5726 clear_mouse_face (dpyinfo
);
5731 /* Just discard the mouse face information for frame F, if any.
5732 This is used when the size of F is changed. */
5735 cancel_mouse_face (f
)
5739 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5741 window
= dpyinfo
->mouse_face_window
;
5742 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
5744 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
5745 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
5746 dpyinfo
->mouse_face_window
= Qnil
;
5751 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
5754 /* Try to determine frame pixel position and size of the glyph under
5755 frame pixel coordinates X/Y on frame F . Return the position and
5756 size in *RECT. Value is non-zero if we could compute these
5760 glyph_rect (f
, x
, y
, rect
)
5766 int part
, found
= 0;
5768 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
5771 struct window
*w
= XWINDOW (window
);
5772 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
5773 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
5775 frame_to_window_pixel_xy (w
, &x
, &y
);
5777 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
5780 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
5781 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
5784 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
5787 rect
->width
= g
->pixel_width
;
5788 rect
->height
= r
->height
;
5789 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
5790 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
5800 /* Return the current position of the mouse.
5801 *FP should be a frame which indicates which display to ask about.
5803 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
5804 and *PART to the frame, window, and scroll bar part that the mouse
5805 is over. Set *X and *Y to the portion and whole of the mouse's
5806 position on the scroll bar.
5808 If the mouse movement started elsewhere, set *FP to the frame the
5809 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
5812 Set *TIME to the server time-stamp for the time at which the mouse
5813 was at this position.
5815 Don't store anything if we don't have a valid set of values to report.
5817 This clears the mouse_moved flag, so we can wait for the next mouse
5821 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
5824 Lisp_Object
*bar_window
;
5825 enum scroll_bar_part
*part
;
5827 unsigned long *time
;
5833 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
5834 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
5840 Window dummy_window
;
5843 Lisp_Object frame
, tail
;
5845 /* Clear the mouse-moved flag for every frame on this display. */
5846 FOR_EACH_FRAME (tail
, frame
)
5847 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
5848 XFRAME (frame
)->mouse_moved
= 0;
5850 last_mouse_scroll_bar
= Qnil
;
5852 /* Figure out which root window we're on. */
5853 XQueryPointer (FRAME_X_DISPLAY (*fp
),
5854 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
5856 /* The root window which contains the pointer. */
5859 /* Trash which we can't trust if the pointer is on
5860 a different screen. */
5863 /* The position on that root window. */
5866 /* More trash we can't trust. */
5869 /* Modifier keys and pointer buttons, about which
5871 (unsigned int *) &dummy
);
5873 /* Now we have a position on the root; find the innermost window
5874 containing the pointer. */
5878 int parent_x
= 0, parent_y
= 0;
5883 /* XTranslateCoordinates can get errors if the window
5884 structure is changing at the same time this function
5885 is running. So at least we must not crash from them. */
5887 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
5889 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
5890 && FRAME_LIVE_P (last_mouse_frame
))
5892 /* If mouse was grabbed on a frame, give coords for that frame
5893 even if the mouse is now outside it. */
5894 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
5896 /* From-window, to-window. */
5897 root
, FRAME_X_WINDOW (last_mouse_frame
),
5899 /* From-position, to-position. */
5900 root_x
, root_y
, &win_x
, &win_y
,
5904 f1
= last_mouse_frame
;
5910 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
5912 /* From-window, to-window. */
5915 /* From-position, to-position. */
5916 root_x
, root_y
, &win_x
, &win_y
,
5921 if (child
== None
|| child
== win
)
5929 /* Now we know that:
5930 win is the innermost window containing the pointer
5931 (XTC says it has no child containing the pointer),
5932 win_x and win_y are the pointer's position in it
5933 (XTC did this the last time through), and
5934 parent_x and parent_y are the pointer's position in win's parent.
5935 (They are what win_x and win_y were when win was child.
5936 If win is the root window, it has no parent, and
5937 parent_{x,y} are invalid, but that's okay, because we'll
5938 never use them in that case.) */
5940 /* Is win one of our frames? */
5941 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
5943 #ifdef USE_X_TOOLKIT
5944 /* If we end up with the menu bar window, say it's not
5947 && f1
->output_data
.x
->menubar_widget
5948 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
5950 #endif /* USE_X_TOOLKIT */
5953 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
5956 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
5958 /* If not, is it one of our scroll bars? */
5961 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
5965 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5971 if (f1
== 0 && insist
> 0)
5972 f1
= SELECTED_FRAME ();
5976 /* Ok, we found a frame. Store all the values.
5977 last_mouse_glyph is a rectangle used to reduce the
5978 generation of mouse events. To not miss any motion
5979 events, we must divide the frame into rectangles of the
5980 size of the smallest character that could be displayed
5981 on it, i.e. into the same rectangles that matrices on
5982 the frame are divided into. */
5984 int width
, height
, gx
, gy
;
5987 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
5988 last_mouse_glyph
= rect
;
5991 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
5992 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
5996 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
5997 round down even for negative values. */
6002 gx
= (gx
+ width
- 1) / width
* width
;
6003 gy
= (gy
+ height
- 1) / height
* height
;
6005 last_mouse_glyph
.width
= width
;
6006 last_mouse_glyph
.height
= height
;
6007 last_mouse_glyph
.x
= gx
;
6008 last_mouse_glyph
.y
= gy
;
6014 XSETINT (*x
, win_x
);
6015 XSETINT (*y
, win_y
);
6016 *time
= last_mouse_movement_time
;
6025 #ifdef USE_X_TOOLKIT
6027 /* Atimer callback function for TIMER. Called every 0.1s to process
6028 Xt timeouts, if needed. We must avoid calling XtAppPending as
6029 much as possible because that function does an implicit XFlush
6030 that slows us down. */
6033 x_process_timeouts (timer
)
6034 struct atimer
*timer
;
6036 if (toolkit_scroll_bar_interaction
|| popup_activated ())
6039 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
6040 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
6045 #endif /* USE_X_TOOLKIT */
6048 /* Scroll bar support. */
6050 /* Given an X window ID, find the struct scroll_bar which manages it.
6051 This can be called in GC, so we have to make sure to strip off mark
6054 static struct scroll_bar
*
6055 x_window_to_scroll_bar (window_id
)
6061 window_id
= (Window
) xg_get_scroll_id_for_window (window_id
);
6062 #endif /* USE_GTK */
6064 for (tail
= Vframe_list
;
6065 XGCTYPE (tail
) == Lisp_Cons
;
6068 Lisp_Object frame
, bar
, condemned
;
6070 frame
= XCAR (tail
);
6071 /* All elements of Vframe_list should be frames. */
6072 if (! GC_FRAMEP (frame
))
6075 /* Scan this frame's scroll bar list for a scroll bar with the
6077 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
6078 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
6079 /* This trick allows us to search both the ordinary and
6080 condemned scroll bar lists with one loop. */
6081 ! GC_NILP (bar
) || (bar
= condemned
,
6084 bar
= XSCROLL_BAR (bar
)->next
)
6085 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
6086 return XSCROLL_BAR (bar
);
6093 #if defined USE_LUCID
6095 /* Return the Lucid menu bar WINDOW is part of. Return null
6096 if WINDOW is not part of a menu bar. */
6099 x_window_to_menu_bar (window
)
6104 for (tail
= Vframe_list
;
6105 XGCTYPE (tail
) == Lisp_Cons
;
6108 Lisp_Object frame
= XCAR (tail
);
6109 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
6111 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
6118 #endif /* USE_LUCID */
6121 /************************************************************************
6123 ************************************************************************/
6125 #ifdef USE_TOOLKIT_SCROLL_BARS
6127 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
6128 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
6129 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
6130 struct scroll_bar
*));
6131 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
6135 /* Lisp window being scrolled. Set when starting to interact with
6136 a toolkit scroll bar, reset to nil when ending the interaction. */
6138 static Lisp_Object window_being_scrolled
;
6140 /* Last scroll bar part sent in xm_scroll_callback. */
6142 static int last_scroll_bar_part
;
6144 /* Whether this is an Xaw with arrow-scrollbars. This should imply
6145 that movements of 1/20 of the screen size are mapped to up/down. */
6148 /* Id of action hook installed for scroll bars. */
6150 static XtActionHookId action_hook_id
;
6152 static Boolean xaw3d_arrow_scroll
;
6154 /* Whether the drag scrolling maintains the mouse at the top of the
6155 thumb. If not, resizing the thumb needs to be done more carefully
6156 to avoid jerkyness. */
6158 static Boolean xaw3d_pick_top
;
6161 /* Action hook installed via XtAppAddActionHook when toolkit scroll
6162 bars are used.. The hook is responsible for detecting when
6163 the user ends an interaction with the scroll bar, and generates
6164 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
6167 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
6170 XtPointer client_data
;
6174 Cardinal
*num_params
;
6180 scroll_bar_p
= XmIsScrollBar (widget
);
6181 end_action
= "Release";
6182 #else /* !USE_MOTIF i.e. use Xaw */
6183 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
6184 end_action
= "EndScroll";
6185 #endif /* USE_MOTIF */
6188 && strcmp (action_name
, end_action
) == 0
6189 && WINDOWP (window_being_scrolled
))
6193 x_send_scroll_bar_event (window_being_scrolled
,
6194 scroll_bar_end_scroll
, 0, 0);
6195 w
= XWINDOW (window_being_scrolled
);
6196 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
6197 window_being_scrolled
= Qnil
;
6198 last_scroll_bar_part
= -1;
6200 /* Xt timeouts no longer needed. */
6201 toolkit_scroll_bar_interaction
= 0;
6204 #endif /* not USE_GTK */
6206 /* A vector of windows used for communication between
6207 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
6209 static struct window
**scroll_bar_windows
;
6210 static int scroll_bar_windows_size
;
6213 /* Send a client message with message type Xatom_Scrollbar for a
6214 scroll action to the frame of WINDOW. PART is a value identifying
6215 the part of the scroll bar that was clicked on. PORTION is the
6216 amount to scroll of a whole of WHOLE. */
6219 x_send_scroll_bar_event (window
, part
, portion
, whole
)
6221 int part
, portion
, whole
;
6224 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
6225 struct window
*w
= XWINDOW (window
);
6226 struct frame
*f
= XFRAME (w
->frame
);
6231 /* Construct a ClientMessage event to send to the frame. */
6232 ev
->type
= ClientMessage
;
6233 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
6234 ev
->display
= FRAME_X_DISPLAY (f
);
6235 ev
->window
= FRAME_X_WINDOW (f
);
6238 /* We can only transfer 32 bits in the XClientMessageEvent, which is
6239 not enough to store a pointer or Lisp_Object on a 64 bit system.
6240 So, store the window in scroll_bar_windows and pass the index
6241 into that array in the event. */
6242 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
6243 if (scroll_bar_windows
[i
] == NULL
)
6246 if (i
== scroll_bar_windows_size
)
6248 int new_size
= max (10, 2 * scroll_bar_windows_size
);
6249 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
6250 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
6252 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
6254 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
6255 scroll_bar_windows_size
= new_size
;
6258 scroll_bar_windows
[i
] = w
;
6259 ev
->data
.l
[0] = (long) i
;
6260 ev
->data
.l
[1] = (long) part
;
6261 ev
->data
.l
[2] = (long) 0;
6262 ev
->data
.l
[3] = (long) portion
;
6263 ev
->data
.l
[4] = (long) whole
;
6265 /* Make Xt timeouts work while the scroll bar is active. */
6266 toolkit_scroll_bar_interaction
= 1;
6268 /* Setting the event mask to zero means that the message will
6269 be sent to the client that created the window, and if that
6270 window no longer exists, no event will be sent. */
6271 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
6276 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
6280 x_scroll_bar_to_input_event (event
, ievent
)
6282 struct input_event
*ievent
;
6284 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
6289 w
= scroll_bar_windows
[ev
->data
.l
[0]];
6290 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
6292 XSETWINDOW (window
, w
);
6293 f
= XFRAME (w
->frame
);
6295 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
6296 ievent
->frame_or_window
= window
;
6299 ievent
->timestamp
= CurrentTime
;
6301 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
6303 ievent
->part
= ev
->data
.l
[1];
6304 ievent
->code
= ev
->data
.l
[2];
6305 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
6306 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
6307 ievent
->modifiers
= 0;
6313 /* Minimum and maximum values used for Motif scroll bars. */
6316 #define XM_SB_MAX 10000000
6317 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
6320 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
6321 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
6322 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
6325 xm_scroll_callback (widget
, client_data
, call_data
)
6327 XtPointer client_data
, call_data
;
6329 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
6330 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
6331 int part
= -1, whole
= 0, portion
= 0;
6335 case XmCR_DECREMENT
:
6336 bar
->dragging
= Qnil
;
6337 part
= scroll_bar_up_arrow
;
6340 case XmCR_INCREMENT
:
6341 bar
->dragging
= Qnil
;
6342 part
= scroll_bar_down_arrow
;
6345 case XmCR_PAGE_DECREMENT
:
6346 bar
->dragging
= Qnil
;
6347 part
= scroll_bar_above_handle
;
6350 case XmCR_PAGE_INCREMENT
:
6351 bar
->dragging
= Qnil
;
6352 part
= scroll_bar_below_handle
;
6356 bar
->dragging
= Qnil
;
6357 part
= scroll_bar_to_top
;
6360 case XmCR_TO_BOTTOM
:
6361 bar
->dragging
= Qnil
;
6362 part
= scroll_bar_to_bottom
;
6368 int dragging_down_p
= (INTEGERP (bar
->dragging
)
6369 && XINT (bar
->dragging
) <= cs
->value
);
6371 /* Get the slider size. */
6373 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
6376 whole
= XM_SB_RANGE
- slider_size
;
6377 portion
= min (cs
->value
- XM_SB_MIN
, whole
);
6378 part
= scroll_bar_handle
;
6379 bar
->dragging
= make_number (cs
->value
);
6383 case XmCR_VALUE_CHANGED
:
6389 window_being_scrolled
= bar
->window
;
6390 last_scroll_bar_part
= part
;
6391 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
6396 #else /* !USE_MOTIF, i.e. Xaw or GTK */
6398 /* Scroll bar callback for Gtk scroll bars. WIDGET is the scroll
6399 bar adjustment widget. DATA is a pointer to the scroll_bar structure. */
6402 xg_scroll_callback (widget
, data
)
6406 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
6412 int part
= -1, whole
= 0, portion
= 0;
6413 GtkAdjustment
*adj
= GTK_ADJUSTMENT (widget
);
6415 if (xg_ignore_gtk_scrollbar
) return;
6417 position
= gtk_adjustment_get_value (adj
);
6419 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
6422 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
6424 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
6430 diff
= (int) (position
- previous
);
6432 if (diff
== (int) adj
->step_increment
)
6434 part
= scroll_bar_down_arrow
;
6435 bar
->dragging
= Qnil
;
6437 else if (-diff
== (int) adj
->step_increment
)
6439 part
= scroll_bar_up_arrow
;
6440 bar
->dragging
= Qnil
;
6442 else if (diff
== (int) adj
->page_increment
)
6444 part
= scroll_bar_below_handle
;
6445 bar
->dragging
= Qnil
;
6447 else if (-diff
== (int) adj
->page_increment
)
6449 part
= scroll_bar_above_handle
;
6450 bar
->dragging
= Qnil
;
6454 part
= scroll_bar_handle
;
6455 whole
= adj
->upper
- adj
->page_size
;
6456 portion
= min (position
, whole
);
6457 bar
->dragging
= make_number (portion
);
6462 xg_ignore_next_thumb
= 1;
6463 window_being_scrolled
= bar
->window
;
6464 last_scroll_bar_part
= part
;
6465 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
6469 #else /* not USE_GTK */
6471 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
6472 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
6473 scroll bar struct. CALL_DATA is a pointer to a float saying where
6477 xaw_jump_callback (widget
, client_data
, call_data
)
6479 XtPointer client_data
, call_data
;
6481 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
6482 float top
= *(float *) call_data
;
6484 int whole
, portion
, height
;
6487 /* Get the size of the thumb, a value between 0 and 1. */
6489 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
6493 portion
= shown
< 1 ? top
* whole
: 0;
6495 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
6496 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
6497 the bottom, so we force the scrolling whenever we see that we're
6498 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
6499 we try to ensure that we always stay two pixels away from the
6501 part
= scroll_bar_down_arrow
;
6503 part
= scroll_bar_handle
;
6505 window_being_scrolled
= bar
->window
;
6506 bar
->dragging
= make_number (portion
);
6507 last_scroll_bar_part
= part
;
6508 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
6512 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
6513 i.e. line or page up or down. WIDGET is the Xaw scroll bar
6514 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
6515 the scroll bar. CALL_DATA is an integer specifying the action that
6516 has taken place. Its magnitude is in the range 0..height of the
6517 scroll bar. Negative values mean scroll towards buffer start.
6518 Values < height of scroll bar mean line-wise movement. */
6521 xaw_scroll_callback (widget
, client_data
, call_data
)
6523 XtPointer client_data
, call_data
;
6525 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
6526 /* The position really is stored cast to a pointer. */
6527 int position
= (long) call_data
;
6531 /* Get the height of the scroll bar. */
6533 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
6536 if (abs (position
) >= height
)
6537 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
6539 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
6540 it maps line-movement to call_data = max(5, height/20). */
6541 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
6542 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
6544 part
= scroll_bar_move_ratio
;
6546 window_being_scrolled
= bar
->window
;
6547 bar
->dragging
= Qnil
;
6548 last_scroll_bar_part
= part
;
6549 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
6552 #endif /* not USE_GTK */
6553 #endif /* not USE_MOTIF */
6555 #define SCROLL_BAR_NAME "verticalScrollBar"
6557 /* Create the widget for scroll bar BAR on frame F. Record the widget
6558 and X window of the scroll bar in BAR. */
6562 x_create_toolkit_scroll_bar (f
, bar
)
6564 struct scroll_bar
*bar
;
6566 char *scroll_bar_name
= SCROLL_BAR_NAME
;
6569 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
6574 #else /* not USE_GTK */
6577 x_create_toolkit_scroll_bar (f
, bar
)
6579 struct scroll_bar
*bar
;
6585 char *scroll_bar_name
= SCROLL_BAR_NAME
;
6586 unsigned long pixel
;
6591 /* Set resources. Create the widget. */
6592 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
6593 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
6594 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
6595 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
6596 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
6597 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
6598 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
6600 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
6603 XtSetArg (av
[ac
], XmNforeground
, pixel
);
6607 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6610 XtSetArg (av
[ac
], XmNbackground
, pixel
);
6614 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
6615 scroll_bar_name
, av
, ac
);
6617 /* Add one callback for everything that can happen. */
6618 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
6620 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
6622 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
6624 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
6626 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
6628 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
6630 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
6633 /* Realize the widget. Only after that is the X window created. */
6634 XtRealizeWidget (widget
);
6636 /* Set the cursor to an arrow. I didn't find a resource to do that.
6637 And I'm wondering why it hasn't an arrow cursor by default. */
6638 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
6639 f
->output_data
.x
->nontext_cursor
);
6641 #else /* !USE_MOTIF i.e. use Xaw */
6643 /* Set resources. Create the widget. The background of the
6644 Xaw3d scroll bar widget is a little bit light for my taste.
6645 We don't alter it here to let users change it according
6646 to their taste with `emacs*verticalScrollBar.background: xxx'. */
6647 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
6648 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
6649 /* For smoother scrolling with Xaw3d -sm */
6650 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
6652 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
6655 XtSetArg (av
[ac
], XtNforeground
, pixel
);
6659 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6662 XtSetArg (av
[ac
], XtNbackground
, pixel
);
6666 /* Top/bottom shadow colors. */
6668 /* Allocate them, if necessary. */
6669 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
6671 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6672 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
6673 &pixel
, 1.2, 0x8000))
6675 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
6677 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
6679 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6680 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
6681 &pixel
, 0.6, 0x4000))
6683 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
6686 /* Tell the toolkit about them. */
6687 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
6688 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
6689 /* We tried to allocate a color for the top/bottom shadow, and
6690 failed, so tell Xaw3d to use dithering instead. */
6692 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
6696 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
6697 be more consistent with other emacs 3d colors, and since Xaw3d is
6698 not good at dealing with allocation failure. */
6700 /* This tells Xaw3d to use real colors instead of dithering for
6702 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
6705 /* Specify the colors. */
6706 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
6709 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
6712 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
6715 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
6720 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
6721 f
->output_data
.x
->edit_widget
, av
, ac
);
6725 char *val
= initial
;
6726 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
6727 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
6729 { /* ARROW_SCROLL */
6730 xaw3d_arrow_scroll
= True
;
6731 /* Isn't that just a personal preference ? -sm */
6732 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
6736 /* Define callbacks. */
6737 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
6738 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
6741 /* Realize the widget. Only after that is the X window created. */
6742 XtRealizeWidget (widget
);
6744 #endif /* !USE_MOTIF */
6746 /* Install an action hook that lets us detect when the user
6747 finishes interacting with a scroll bar. */
6748 if (action_hook_id
== 0)
6749 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
6751 /* Remember X window and widget in the scroll bar vector. */
6752 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
6753 xwindow
= XtWindow (widget
);
6754 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
6758 #endif /* not USE_GTK */
6761 /* Set the thumb size and position of scroll bar BAR. We are currently
6762 displaying PORTION out of a whole WHOLE, and our position POSITION. */
6766 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
6767 struct scroll_bar
*bar
;
6768 int portion
, position
, whole
;
6770 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
6773 #else /* not USE_GTK */
6775 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
6776 struct scroll_bar
*bar
;
6777 int portion
, position
, whole
;
6779 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6780 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
6787 /* We use an estimate of 30 chars per line rather than the real
6788 `portion' value. This has the disadvantage that the thumb size
6789 is not very representative, but it makes our life a lot easier.
6790 Otherwise, we have to constantly adjust the thumb size, which
6791 we can't always do quickly enough: while dragging, the size of
6792 the thumb might prevent the user from dragging the thumb all the
6793 way to the end. but Motif and some versions of Xaw3d don't allow
6794 updating the thumb size while dragging. Also, even if we can update
6795 its size, the update will often happen too late.
6796 If you don't believe it, check out revision 1.650 of xterm.c to see
6797 what hoops we were going through and the still poor behavior we got. */
6798 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
6799 /* When the thumb is at the bottom, position == whole.
6800 So we need to increase `whole' to make space for the thumb. */
6807 top
= (float) position
/ whole
;
6808 shown
= (float) portion
/ whole
;
6811 if (NILP (bar
->dragging
))
6815 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
6816 is the scroll bar's maximum and MIN is the scroll bar's minimum
6818 size
= shown
* XM_SB_RANGE
;
6819 size
= min (size
, XM_SB_RANGE
);
6820 size
= max (size
, 1);
6822 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
6823 value
= top
* XM_SB_RANGE
;
6824 value
= min (value
, XM_SB_MAX
- size
);
6825 value
= max (value
, XM_SB_MIN
);
6827 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
6829 #else /* !USE_MOTIF i.e. use Xaw */
6835 top
= (float) position
/ whole
;
6836 shown
= (float) portion
/ whole
;
6840 float old_top
, old_shown
;
6842 XtVaGetValues (widget
,
6843 XtNtopOfThumb
, &old_top
,
6844 XtNshown
, &old_shown
,
6848 /* Massage the top+shown values. */
6849 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
6850 top
= max (0, min (1, top
));
6853 /* Keep two pixels available for moving the thumb down. */
6854 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
6856 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
6857 check that your system's configuration file contains a define
6858 for `NARROWPROTO'. See s/freebsd.h for an example. */
6859 if (top
!= old_top
|| shown
!= old_shown
)
6861 if (NILP (bar
->dragging
))
6862 XawScrollbarSetThumb (widget
, top
, shown
);
6866 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
6867 int scroll_mode
= 0;
6869 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
6870 if (xaw3d_arrow_scroll
)
6872 /* Xaw3d stupidly ignores resize requests while dragging
6873 so we have to make it believe it's not in dragging mode. */
6874 scroll_mode
= sb
->scrollbar
.scroll_mode
;
6875 if (scroll_mode
== 2)
6876 sb
->scrollbar
.scroll_mode
= 0;
6879 /* Try to make the scrolling a tad smoother. */
6880 if (!xaw3d_pick_top
)
6881 shown
= min (shown
, old_shown
);
6883 XawScrollbarSetThumb (widget
, top
, shown
);
6886 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
6887 sb
->scrollbar
.scroll_mode
= scroll_mode
;
6892 #endif /* !USE_MOTIF */
6896 #endif /* not USE_GTK */
6898 #endif /* USE_TOOLKIT_SCROLL_BARS */
6902 /************************************************************************
6903 Scroll bars, general
6904 ************************************************************************/
6906 /* Create a scroll bar and return the scroll bar vector for it. W is
6907 the Emacs window on which to create the scroll bar. TOP, LEFT,
6908 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
6911 static struct scroll_bar
*
6912 x_scroll_bar_create (w
, top
, left
, width
, height
)
6914 int top
, left
, width
, height
;
6916 struct frame
*f
= XFRAME (w
->frame
);
6917 struct scroll_bar
*bar
6918 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
6922 #ifdef USE_TOOLKIT_SCROLL_BARS
6923 x_create_toolkit_scroll_bar (f
, bar
);
6924 #else /* not USE_TOOLKIT_SCROLL_BARS */
6926 XSetWindowAttributes a
;
6930 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6931 if (a
.background_pixel
== -1)
6932 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
6934 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
6935 | ButtonMotionMask
| PointerMotionHintMask
6937 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
6939 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
6941 /* Clear the area of W that will serve as a scroll bar. This is
6942 for the case that a window has been split horizontally. In
6943 this case, no clear_frame is generated to reduce flickering. */
6944 if (width
> 0 && height
> 0)
6945 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6947 window_box_height (w
), False
);
6949 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6950 /* Position and size of scroll bar. */
6951 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
6953 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
6955 /* Border width, depth, class, and visual. */
6962 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
6964 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6966 XSETWINDOW (bar
->window
, w
);
6967 XSETINT (bar
->top
, top
);
6968 XSETINT (bar
->left
, left
);
6969 XSETINT (bar
->width
, width
);
6970 XSETINT (bar
->height
, height
);
6971 XSETINT (bar
->start
, 0);
6972 XSETINT (bar
->end
, 0);
6973 bar
->dragging
= Qnil
;
6975 /* Add bar to its frame's list of scroll bars. */
6976 bar
->next
= FRAME_SCROLL_BARS (f
);
6978 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
6979 if (!NILP (bar
->next
))
6980 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
6982 /* Map the window/widget. */
6983 #ifdef USE_TOOLKIT_SCROLL_BARS
6986 xg_update_scrollbar_pos (f
,
6987 SCROLL_BAR_X_WINDOW (bar
),
6989 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
6990 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
6992 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
6993 #else /* not USE_GTK */
6994 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
6995 XtConfigureWidget (scroll_bar
,
6996 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
6998 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
6999 max (height
, 1), 0);
7000 XtMapWidget (scroll_bar
);
7001 #endif /* not USE_GTK */
7003 #else /* not USE_TOOLKIT_SCROLL_BARS */
7004 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7005 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7012 /* Draw BAR's handle in the proper position.
7014 If the handle is already drawn from START to END, don't bother
7015 redrawing it, unless REBUILD is non-zero; in that case, always
7016 redraw it. (REBUILD is handy for drawing the handle after expose
7019 Normally, we want to constrain the start and end of the handle to
7020 fit inside its rectangle, but if the user is dragging the scroll
7021 bar handle, we want to let them drag it down all the way, so that
7022 the bar's top is as far down as it goes; otherwise, there's no way
7023 to move to the very end of the buffer. */
7025 #ifndef USE_TOOLKIT_SCROLL_BARS
7028 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
7029 struct scroll_bar
*bar
;
7033 int dragging
= ! NILP (bar
->dragging
);
7034 Window w
= SCROLL_BAR_X_WINDOW (bar
);
7035 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7036 GC gc
= f
->output_data
.x
->normal_gc
;
7038 /* If the display is already accurate, do nothing. */
7040 && start
== XINT (bar
->start
)
7041 && end
== XINT (bar
->end
))
7047 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
7048 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
7049 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7051 /* Make sure the values are reasonable, and try to preserve
7052 the distance between start and end. */
7054 int length
= end
- start
;
7058 else if (start
> top_range
)
7060 end
= start
+ length
;
7064 else if (end
> top_range
&& ! dragging
)
7068 /* Store the adjusted setting in the scroll bar. */
7069 XSETINT (bar
->start
, start
);
7070 XSETINT (bar
->end
, end
);
7072 /* Clip the end position, just for display. */
7073 if (end
> top_range
)
7076 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
7077 below top positions, to make sure the handle is always at least
7078 that many pixels tall. */
7079 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
7081 /* Draw the empty space above the handle. Note that we can't clear
7082 zero-height areas; that means "clear to end of window." */
7084 x_clear_area (FRAME_X_DISPLAY (f
), w
,
7085 /* x, y, width, height, and exposures. */
7086 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7087 VERTICAL_SCROLL_BAR_TOP_BORDER
,
7088 inside_width
, start
,
7091 /* Change to proper foreground color if one is specified. */
7092 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7093 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7094 f
->output_data
.x
->scroll_bar_foreground_pixel
);
7096 /* Draw the handle itself. */
7097 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
7098 /* x, y, width, height */
7099 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7100 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
7101 inside_width
, end
- start
);
7103 /* Restore the foreground color of the GC if we changed it above. */
7104 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7105 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7106 f
->output_data
.x
->foreground_pixel
);
7108 /* Draw the empty space below the handle. Note that we can't
7109 clear zero-height areas; that means "clear to end of window." */
7110 if (end
< inside_height
)
7111 x_clear_area (FRAME_X_DISPLAY (f
), w
,
7112 /* x, y, width, height, and exposures. */
7113 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
7114 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
7115 inside_width
, inside_height
- end
,
7123 #endif /* !USE_TOOLKIT_SCROLL_BARS */
7125 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
7129 x_scroll_bar_remove (bar
)
7130 struct scroll_bar
*bar
;
7132 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7135 #ifdef USE_TOOLKIT_SCROLL_BARS
7137 xg_remove_scroll_bar (f
, SCROLL_BAR_X_WINDOW (bar
));
7138 #else /* not USE_GTK */
7139 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
7140 #endif /* not USE_GTK */
7142 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
7145 /* Disassociate this scroll bar from its window. */
7146 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
7152 /* Set the handle of the vertical scroll bar for WINDOW to indicate
7153 that we are displaying PORTION characters out of a total of WHOLE
7154 characters, starting at POSITION. If WINDOW has no scroll bar,
7158 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
7160 int portion
, whole
, position
;
7162 struct frame
*f
= XFRAME (w
->frame
);
7163 struct scroll_bar
*bar
;
7164 int top
, height
, left
, sb_left
, width
, sb_width
;
7165 int window_x
, window_y
, window_width
, window_height
;
7167 /* Get window dimensions. */
7168 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7170 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
7171 height
= window_height
;
7173 /* Compute the left edge of the scroll bar area. */
7174 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7175 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
7177 left
= XFASTINT (w
->left
);
7178 left
*= CANON_X_UNIT (f
);
7179 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
7181 /* Compute the width of the scroll bar which might be less than
7182 the width of the area reserved for the scroll bar. */
7183 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
7184 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
7188 /* Compute the left edge of the scroll bar. */
7189 #ifdef USE_TOOLKIT_SCROLL_BARS
7190 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7191 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
7193 sb_left
= left
+ (width
- sb_width
) / 2;
7195 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
7196 sb_left
= left
+ width
- sb_width
;
7201 /* Does the scroll bar exist yet? */
7202 if (NILP (w
->vertical_scroll_bar
))
7204 if (width
> 0 && height
> 0)
7207 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7208 left
, top
, width
, height
, False
);
7212 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
7216 /* It may just need to be moved and resized. */
7217 unsigned int mask
= 0;
7219 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
7223 if (sb_left
!= XINT (bar
->left
))
7225 if (top
!= XINT (bar
->top
))
7227 if (sb_width
!= XINT (bar
->width
))
7229 if (height
!= XINT (bar
->height
))
7232 #ifdef USE_TOOLKIT_SCROLL_BARS
7236 xg_update_scrollbar_pos (f
,
7237 SCROLL_BAR_X_WINDOW (bar
),
7239 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7240 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7242 #else /* not USE_GTK */
7244 /* Since toolkit scroll bars are smaller than the space reserved
7245 for them on the frame, we have to clear "under" them. */
7246 if (width
> 0 && height
> 0)
7247 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7248 left
, top
, width
, height
, False
);
7249 /* Move/size the scroll bar widget. */
7251 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
7252 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7254 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
7255 max (height
, 1), 0);
7257 #endif /* not USE_GTK */
7258 #else /* not USE_TOOLKIT_SCROLL_BARS */
7260 /* Clear areas not covered by the scroll bar because of
7261 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
7262 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
7264 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7265 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7267 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7268 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7269 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
7273 /* Clear areas not covered by the scroll bar because it's not as
7274 wide as the area reserved for it. This makes sure a
7275 previous mode line display is cleared after C-x 2 C-x 1, for
7278 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
7279 int rest
= area_width
- sb_width
;
7280 if (rest
> 0 && height
> 0)
7282 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
7283 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7284 left
+ area_width
- rest
, top
,
7285 rest
, height
, False
);
7287 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7288 left
, top
, rest
, height
, False
);
7292 /* Move/size the scroll bar window. */
7297 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
7299 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
7301 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
7305 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7307 /* Remember new settings. */
7308 XSETINT (bar
->left
, sb_left
);
7309 XSETINT (bar
->top
, top
);
7310 XSETINT (bar
->width
, sb_width
);
7311 XSETINT (bar
->height
, height
);
7316 #ifdef USE_TOOLKIT_SCROLL_BARS
7317 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
7318 #else /* not USE_TOOLKIT_SCROLL_BARS */
7319 /* Set the scroll bar's current state, unless we're currently being
7321 if (NILP (bar
->dragging
))
7323 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
7326 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
7329 int start
= ((double) position
* top_range
) / whole
;
7330 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
7331 x_scroll_bar_set_handle (bar
, start
, end
, 0);
7334 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7336 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
7340 /* The following three hooks are used when we're doing a thorough
7341 redisplay of the frame. We don't explicitly know which scroll bars
7342 are going to be deleted, because keeping track of when windows go
7343 away is a real pain - "Can you say set-window-configuration, boys
7344 and girls?" Instead, we just assert at the beginning of redisplay
7345 that *all* scroll bars are to be removed, and then save a scroll bar
7346 from the fiery pit when we actually redisplay its window. */
7348 /* Arrange for all scroll bars on FRAME to be removed at the next call
7349 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
7350 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
7353 XTcondemn_scroll_bars (frame
)
7356 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
7357 while (! NILP (FRAME_SCROLL_BARS (frame
)))
7360 bar
= FRAME_SCROLL_BARS (frame
);
7361 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
7362 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
7363 XSCROLL_BAR (bar
)->prev
= Qnil
;
7364 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
7365 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
7366 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
7371 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
7372 Note that WINDOW isn't necessarily condemned at all. */
7375 XTredeem_scroll_bar (window
)
7376 struct window
*window
;
7378 struct scroll_bar
*bar
;
7381 /* We can't redeem this window's scroll bar if it doesn't have one. */
7382 if (NILP (window
->vertical_scroll_bar
))
7385 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
7387 /* Unlink it from the condemned list. */
7388 f
= XFRAME (WINDOW_FRAME (window
));
7389 if (NILP (bar
->prev
))
7391 /* If the prev pointer is nil, it must be the first in one of
7393 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
7394 /* It's not condemned. Everything's fine. */
7396 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
7397 window
->vertical_scroll_bar
))
7398 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
7400 /* If its prev pointer is nil, it must be at the front of
7401 one or the other! */
7405 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
7407 if (! NILP (bar
->next
))
7408 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
7410 bar
->next
= FRAME_SCROLL_BARS (f
);
7412 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
7413 if (! NILP (bar
->next
))
7414 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7417 /* Remove all scroll bars on FRAME that haven't been saved since the
7418 last call to `*condemn_scroll_bars_hook'. */
7421 XTjudge_scroll_bars (f
)
7424 Lisp_Object bar
, next
;
7426 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
7428 /* Clear out the condemned list now so we won't try to process any
7429 more events on the hapless scroll bars. */
7430 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
7432 for (; ! NILP (bar
); bar
= next
)
7434 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
7436 x_scroll_bar_remove (b
);
7439 b
->next
= b
->prev
= Qnil
;
7442 /* Now there should be no references to the condemned scroll bars,
7443 and they should get garbage-collected. */
7447 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
7448 is a no-op when using toolkit scroll bars.
7450 This may be called from a signal handler, so we have to ignore GC
7454 x_scroll_bar_expose (bar
, event
)
7455 struct scroll_bar
*bar
;
7458 #ifndef USE_TOOLKIT_SCROLL_BARS
7460 Window w
= SCROLL_BAR_X_WINDOW (bar
);
7461 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7462 GC gc
= f
->output_data
.x
->normal_gc
;
7463 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
7467 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
7469 /* Draw a one-pixel border just inside the edges of the scroll bar. */
7470 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
7472 /* x, y, width, height */
7474 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
7475 XINT (bar
->height
) - 1);
7479 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7482 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
7483 is set to something other than NO_EVENT, it is enqueued.
7485 This may be called from a signal handler, so we have to ignore GC
7490 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
7491 struct scroll_bar
*bar
;
7493 struct input_event
*emacs_event
;
7495 if (! GC_WINDOWP (bar
->window
))
7498 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
7499 emacs_event
->code
= event
->xbutton
.button
- Button1
;
7500 emacs_event
->modifiers
7501 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
7502 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
7503 event
->xbutton
.state
)
7504 | (event
->type
== ButtonRelease
7507 emacs_event
->frame_or_window
= bar
->window
;
7508 emacs_event
->arg
= Qnil
;
7509 emacs_event
->timestamp
= event
->xbutton
.time
;
7512 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7514 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
7517 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7518 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
7521 if (y
> top_range
) y
= top_range
;
7523 if (y
< XINT (bar
->start
))
7524 emacs_event
->part
= scroll_bar_above_handle
;
7525 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
7526 emacs_event
->part
= scroll_bar_handle
;
7528 emacs_event
->part
= scroll_bar_below_handle
;
7530 /* Just because the user has clicked on the handle doesn't mean
7531 they want to drag it. Lisp code needs to be able to decide
7532 whether or not we're dragging. */
7534 /* If the user has just clicked on the handle, record where they're
7536 if (event
->type
== ButtonPress
7537 && emacs_event
->part
== scroll_bar_handle
)
7538 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
7541 #ifndef USE_TOOLKIT_SCROLL_BARS
7542 /* If the user has released the handle, set it to its final position. */
7543 if (event
->type
== ButtonRelease
7544 && ! NILP (bar
->dragging
))
7546 int new_start
= y
- XINT (bar
->dragging
);
7547 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
7549 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
7550 bar
->dragging
= Qnil
;
7554 /* Same deal here as the other #if 0. */
7556 /* Clicks on the handle are always reported as occurring at the top of
7558 if (emacs_event
->part
== scroll_bar_handle
)
7559 emacs_event
->x
= bar
->start
;
7561 XSETINT (emacs_event
->x
, y
);
7563 XSETINT (emacs_event
->x
, y
);
7566 XSETINT (emacs_event
->y
, top_range
);
7570 #ifndef USE_TOOLKIT_SCROLL_BARS
7572 /* Handle some mouse motion while someone is dragging the scroll bar.
7574 This may be called from a signal handler, so we have to ignore GC
7578 x_scroll_bar_note_movement (bar
, event
)
7579 struct scroll_bar
*bar
;
7582 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
7584 last_mouse_movement_time
= event
->xmotion
.time
;
7587 XSETVECTOR (last_mouse_scroll_bar
, bar
);
7589 /* If we're dragging the bar, display it. */
7590 if (! GC_NILP (bar
->dragging
))
7592 /* Where should the handle be now? */
7593 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
7595 if (new_start
!= XINT (bar
->start
))
7597 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
7599 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
7604 #endif /* !USE_TOOLKIT_SCROLL_BARS */
7606 /* Return information to the user about the current position of the mouse
7607 on the scroll bar. */
7610 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
7612 Lisp_Object
*bar_window
;
7613 enum scroll_bar_part
*part
;
7615 unsigned long *time
;
7617 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
7618 Window w
= SCROLL_BAR_X_WINDOW (bar
);
7619 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7621 Window dummy_window
;
7623 unsigned int dummy_mask
;
7627 /* Get the mouse's position relative to the scroll bar window, and
7629 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
7631 /* Root, child, root x and root y. */
7632 &dummy_window
, &dummy_window
,
7633 &dummy_coord
, &dummy_coord
,
7635 /* Position relative to scroll bar. */
7638 /* Mouse buttons and modifier keys. */
7645 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
7648 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
7650 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
7652 if (! NILP (bar
->dragging
))
7653 win_y
-= XINT (bar
->dragging
);
7657 if (win_y
> top_range
)
7661 *bar_window
= bar
->window
;
7663 if (! NILP (bar
->dragging
))
7664 *part
= scroll_bar_handle
;
7665 else if (win_y
< XINT (bar
->start
))
7666 *part
= scroll_bar_above_handle
;
7667 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
7668 *part
= scroll_bar_handle
;
7670 *part
= scroll_bar_below_handle
;
7672 XSETINT (*x
, win_y
);
7673 XSETINT (*y
, top_range
);
7676 last_mouse_scroll_bar
= Qnil
;
7679 *time
= last_mouse_movement_time
;
7685 /* The screen has been cleared so we may have changed foreground or
7686 background colors, and the scroll bars may need to be redrawn.
7687 Clear out the scroll bars, and ask for expose events, so we can
7691 x_scroll_bar_clear (f
)
7694 #ifndef USE_TOOLKIT_SCROLL_BARS
7697 /* We can have scroll bars even if this is 0,
7698 if we just turned off scroll bar mode.
7699 But in that case we should not clear them. */
7700 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
7701 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
7702 bar
= XSCROLL_BAR (bar
)->next
)
7703 XClearArea (FRAME_X_DISPLAY (f
),
7704 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
7706 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7710 /* Define a queue to save up SelectionRequest events for later handling. */
7712 struct selection_event_queue
7715 struct selection_event_queue
*next
;
7718 static struct selection_event_queue
*queue
;
7720 /* Nonzero means queue up certain events--don't process them yet. */
7722 static int x_queue_selection_requests
;
7724 /* Queue up an X event *EVENT, to be processed later. */
7727 x_queue_event (f
, event
)
7731 struct selection_event_queue
*queue_tmp
7732 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
7734 if (queue_tmp
!= NULL
)
7736 queue_tmp
->event
= *event
;
7737 queue_tmp
->next
= queue
;
7742 /* Take all the queued events and put them back
7743 so that they get processed afresh. */
7746 x_unqueue_events (display
)
7749 while (queue
!= NULL
)
7751 struct selection_event_queue
*queue_tmp
= queue
;
7752 XPutBackEvent (display
, &queue_tmp
->event
);
7753 queue
= queue_tmp
->next
;
7754 xfree ((char *)queue_tmp
);
7758 /* Start queuing SelectionRequest events. */
7761 x_start_queuing_selection_requests (display
)
7764 x_queue_selection_requests
++;
7767 /* Stop queuing SelectionRequest events. */
7770 x_stop_queuing_selection_requests (display
)
7773 x_queue_selection_requests
--;
7774 x_unqueue_events (display
);
7777 /* The main X event-reading loop - XTread_socket. */
7780 /* Time stamp of enter window event. This is only used by XTread_socket,
7781 but we have to put it out here, since static variables within functions
7782 sometimes don't work. */
7784 static Time enter_timestamp
;
7787 /* This holds the state XLookupString needs to implement dead keys
7788 and other tricks known as "compose processing". _X Window System_
7789 says that a portable program can't use this, but Stephen Gildea assures
7790 me that letting the compiler initialize it to zeros will work okay.
7792 This must be defined outside of XTread_socket, for the same reasons
7793 given for enter_timestamp, above. */
7795 static XComposeStatus compose_status
;
7797 /* Record the last 100 characters stored
7798 to help debug the loss-of-chars-during-GC problem. */
7800 static int temp_index
;
7801 static short temp_buffer
[100];
7803 /* Set this to nonzero to fake an "X I/O error"
7804 on a particular display. */
7806 struct x_display_info
*XTread_socket_fake_io_error
;
7808 /* When we find no input here, we occasionally do a no-op command
7809 to verify that the X server is still running and we can still talk with it.
7810 We try all the open displays, one by one.
7811 This variable is used for cycling thru the displays. */
7813 static struct x_display_info
*next_noop_dpyinfo
;
7815 #define SET_SAVED_MENU_EVENT(size) \
7818 if (f->output_data.x->saved_menu_event == 0) \
7819 f->output_data.x->saved_menu_event \
7820 = (XEvent *) xmalloc (sizeof (XEvent)); \
7821 bcopy (&event, f->output_data.x->saved_menu_event, size); \
7822 if (numchars >= 1) \
7824 bufp->kind = MENU_BAR_ACTIVATE_EVENT; \
7825 XSETFRAME (bufp->frame_or_window, f); \
7834 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
7835 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
7845 /* Filter events for the current X input method.
7846 DPYINFO is the display this event is for.
7847 EVENT is the X event to filter.
7849 Returns non-zero if the event was filtered, caller shall not process
7851 Returns zero if event is wasn't filtered. */
7855 x_filter_event (dpyinfo
, event
)
7856 struct x_display_info
*dpyinfo
;
7859 /* XFilterEvent returns non-zero if the input method has
7860 consumed the event. We pass the frame's X window to
7861 XFilterEvent because that's the one for which the IC
7864 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
7865 event
->xclient
.window
);
7867 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
7872 static struct x_display_info
*current_dpyinfo
;
7873 static struct input_event
**current_bufp
;
7874 static int *current_numcharsp
;
7875 static int current_count
;
7876 static int current_finish
;
7878 /* This is the filter function invoked by the GTK event loop.
7879 It is invoked before the XEvent is translated to a GdkEvent,
7880 so we have a chanse to act on the event before GTK. */
7881 static GdkFilterReturn
7882 event_handler_gdk (gxev
, ev
, data
)
7887 XEvent
*xev
= (XEvent
*)gxev
;
7889 if (current_numcharsp
)
7892 /* Filter events for the current X input method.
7893 GTK calls XFilterEvent but not for key press and release,
7894 so we do it here. */
7895 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
7896 if (x_filter_event (current_dpyinfo
, xev
))
7897 return GDK_FILTER_REMOVE
;
7899 current_count
+= handle_one_xevent (current_dpyinfo
,
7906 current_finish
= x_dispatch_event (xev
, GDK_DISPLAY ());
7908 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
7909 return GDK_FILTER_REMOVE
;
7911 return GDK_FILTER_CONTINUE
;
7913 #endif /* USE_GTK */
7916 /* Handles the XEvent EVENT on display DPYINFO.
7918 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
7919 *FINISH is zero if caller should continue reading events.
7920 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
7922 Events representing keys are stored in buffer *BUFP_R,
7923 which can hold up to *NUMCHARSP characters.
7924 We return the number of characters stored into the buffer. */
7927 handle_one_xevent (dpyinfo
, eventp
, bufp_r
, numcharsp
, finish
)
7928 struct x_display_info
*dpyinfo
;
7930 /* register */ struct input_event
**bufp_r
;
7931 /* register */ int *numcharsp
;
7937 struct coding_system coding
;
7938 struct input_event
*bufp
= *bufp_r
;
7939 int numchars
= *numcharsp
;
7940 XEvent event
= *eventp
;
7942 *finish
= X_EVENT_NORMAL
;
7948 if (event
.xclient
.message_type
7949 == dpyinfo
->Xatom_wm_protocols
7950 && event
.xclient
.format
== 32)
7952 if (event
.xclient
.data
.l
[0]
7953 == dpyinfo
->Xatom_wm_take_focus
)
7955 /* Use x_any_window_to_frame because this
7956 could be the shell widget window
7957 if the frame has no title bar. */
7958 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
7960 /* Not quite sure this is needed -pd */
7961 if (f
&& FRAME_XIC (f
))
7962 XSetICFocus (FRAME_XIC (f
));
7964 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
7965 instructs the WM to set the input focus automatically for
7966 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
7967 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
7968 it has set the focus. So, XSetInputFocus below is not
7971 The call to XSetInputFocus below has also caused trouble. In
7972 cases where the XSetInputFocus done by the WM and the one
7973 below are temporally close (on a fast machine), the call
7974 below can generate additional FocusIn events which confuse
7977 /* Since we set WM_TAKE_FOCUS, we must call
7978 XSetInputFocus explicitly. But not if f is null,
7979 since that might be an event for a deleted frame. */
7982 Display
*d
= event
.xclient
.display
;
7983 /* Catch and ignore errors, in case window has been
7984 iconified by a window manager such as GWM. */
7985 int count
= x_catch_errors (d
);
7986 XSetInputFocus (d
, event
.xclient
.window
,
7987 /* The ICCCM says this is
7988 the only valid choice. */
7990 event
.xclient
.data
.l
[1]);
7991 /* This is needed to detect the error
7992 if there is an error. */
7994 x_uncatch_errors (d
, count
);
7996 /* Not certain about handling scroll bars here */
7999 else if (event
.xclient
.data
.l
[0]
8000 == dpyinfo
->Xatom_wm_save_yourself
)
8002 /* Save state modify the WM_COMMAND property to
8003 something which can reinstate us. This notifies
8004 the session manager, who's looking for such a
8005 PropertyNotify. Can restart processing when
8006 a keyboard or mouse event arrives. */
8007 /* If we have a session manager, don't set this.
8008 KDE will then start two Emacsen, one for the
8009 session manager and one for this. */
8012 && ! x_session_have_connection ()
8016 f
= x_top_window_to_frame (dpyinfo
,
8017 event
.xclient
.window
);
8018 /* This is just so we only give real data once
8019 for a single Emacs process. */
8020 if (f
== SELECTED_FRAME ())
8021 XSetCommand (FRAME_X_DISPLAY (f
),
8022 event
.xclient
.window
,
8023 initial_argv
, initial_argc
);
8025 XSetCommand (FRAME_X_DISPLAY (f
),
8026 event
.xclient
.window
,
8030 else if (event
.xclient
.data
.l
[0]
8031 == dpyinfo
->Xatom_wm_delete_window
)
8034 = x_any_window_to_frame (dpyinfo
,
8035 event
.xclient
.window
);
8042 bufp
->kind
= DELETE_WINDOW_EVENT
;
8043 XSETFRAME (bufp
->frame_or_window
, f
);
8051 goto OTHER
; /* May be a dialog that is to be removed */
8054 else if (event
.xclient
.message_type
8055 == dpyinfo
->Xatom_wm_configure_denied
)
8058 else if (event
.xclient
.message_type
8059 == dpyinfo
->Xatom_wm_window_moved
)
8063 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
8065 new_x
= event
.xclient
.data
.s
[0];
8066 new_y
= event
.xclient
.data
.s
[1];
8070 f
->output_data
.x
->left_pos
= new_x
;
8071 f
->output_data
.x
->top_pos
= new_y
;
8075 else if (event
.xclient
.message_type
8076 == dpyinfo
->Xatom_editres
)
8079 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
8080 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
8083 #endif /* HACK_EDITRES */
8084 else if ((event
.xclient
.message_type
8085 == dpyinfo
->Xatom_DONE
)
8086 || (event
.xclient
.message_type
8087 == dpyinfo
->Xatom_PAGE
))
8089 /* Ghostview job completed. Kill it. We could
8090 reply with "Next" if we received "Page", but we
8091 currently never do because we are interested in
8092 images, only, which should have 1 page. */
8093 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
8095 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
8096 x_kill_gs_process (pixmap
, f
);
8097 expose_frame (f
, 0, 0, 0, 0);
8099 #ifdef USE_TOOLKIT_SCROLL_BARS
8100 /* Scroll bar callbacks send a ClientMessage from which
8101 we construct an input_event. */
8102 else if (event
.xclient
.message_type
8103 == dpyinfo
->Xatom_Scrollbar
)
8105 x_scroll_bar_to_input_event (&event
, bufp
);
8106 ++bufp
, ++count
, --numchars
;
8109 #endif /* USE_TOOLKIT_SCROLL_BARS */
8115 case SelectionNotify
:
8116 #ifdef USE_X_TOOLKIT
8117 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
8119 #endif /* not USE_X_TOOLKIT */
8120 x_handle_selection_notify (&event
.xselection
);
8123 case SelectionClear
: /* Someone has grabbed ownership. */
8124 #ifdef USE_X_TOOLKIT
8125 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
8127 #endif /* USE_X_TOOLKIT */
8129 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
8134 bufp
->kind
= SELECTION_CLEAR_EVENT
;
8135 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
8136 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
8137 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
8138 bufp
->frame_or_window
= Qnil
;
8147 case SelectionRequest
: /* Someone wants our selection. */
8148 #ifdef USE_X_TOOLKIT
8149 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
8151 #endif /* USE_X_TOOLKIT */
8152 if (x_queue_selection_requests
)
8153 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
8157 XSelectionRequestEvent
*eventp
8158 = (XSelectionRequestEvent
*) &event
;
8163 bufp
->kind
= SELECTION_REQUEST_EVENT
;
8164 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
8165 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
8166 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
8167 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
8168 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
8169 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
8170 bufp
->frame_or_window
= Qnil
;
8179 case PropertyNotify
:
8180 #if 0 /* This is plain wrong. In the case that we are waiting for a
8181 PropertyNotify used as an ACK in incremental selection
8182 transfer, the property will be on the receiver's window. */
8183 #if defined USE_X_TOOLKIT
8184 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
8188 x_handle_property_notify (&event
.xproperty
);
8191 case ReparentNotify
:
8192 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
8196 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
8197 x_real_positions (f
, &x
, &y
);
8198 f
->output_data
.x
->left_pos
= x
;
8199 f
->output_data
.x
->top_pos
= y
;
8205 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8208 x_check_fullscreen (f
);
8210 if (f
->async_visible
== 0)
8212 f
->async_visible
= 1;
8213 f
->async_iconified
= 0;
8214 f
->output_data
.x
->has_been_visible
= 1;
8215 SET_FRAME_GARBAGED (f
);
8218 expose_frame (x_window_to_frame (dpyinfo
,
8219 event
.xexpose
.window
),
8220 event
.xexpose
.x
, event
.xexpose
.y
,
8221 event
.xexpose
.width
, event
.xexpose
.height
);
8225 #ifndef USE_TOOLKIT_SCROLL_BARS
8226 struct scroll_bar
*bar
;
8228 #if defined USE_LUCID
8229 /* Submenus of the Lucid menu bar aren't widgets
8230 themselves, so there's no way to dispatch events
8231 to them. Recognize this case separately. */
8234 = x_window_to_menu_bar (event
.xexpose
.window
);
8236 xlwmenu_redisplay (widget
);
8238 #endif /* USE_LUCID */
8240 #ifdef USE_TOOLKIT_SCROLL_BARS
8241 /* Dispatch event to the widget. */
8243 #else /* not USE_TOOLKIT_SCROLL_BARS */
8244 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
8247 x_scroll_bar_expose (bar
, &event
);
8248 #ifdef USE_X_TOOLKIT
8251 #endif /* USE_X_TOOLKIT */
8252 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8256 case GraphicsExpose
: /* This occurs when an XCopyArea's
8257 source area was obscured or not
8259 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
8263 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
8264 event
.xgraphicsexpose
.width
,
8265 event
.xgraphicsexpose
.height
);
8267 #ifdef USE_X_TOOLKIT
8270 #endif /* USE_X_TOOLKIT */
8273 case NoExpose
: /* This occurs when an XCopyArea's
8274 source area was completely
8279 /* Redo the mouse-highlight after the tooltip has gone. */
8280 if (event
.xmap
.window
== tip_window
)
8283 redo_mouse_highlight ();
8286 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
8287 if (f
) /* F may no longer exist if
8288 the frame was deleted. */
8290 /* While a frame is unmapped, display generation is
8291 disabled; you don't want to spend time updating a
8292 display that won't ever be seen. */
8293 f
->async_visible
= 0;
8294 /* We can't distinguish, from the event, whether the window
8295 has become iconified or invisible. So assume, if it
8296 was previously visible, than now it is iconified.
8297 But x_make_frame_invisible clears both
8298 the visible flag and the iconified flag;
8299 and that way, we know the window is not iconified now. */
8300 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
8302 f
->async_iconified
= 1;
8304 bufp
->kind
= ICONIFY_EVENT
;
8305 XSETFRAME (bufp
->frame_or_window
, f
);
8315 if (event
.xmap
.window
== tip_window
)
8316 /* The tooltip has been drawn already. Avoid
8317 the SET_FRAME_GARBAGED below. */
8320 /* We use x_top_window_to_frame because map events can
8321 come for sub-windows and they don't mean that the
8322 frame is visible. */
8323 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
8326 /* wait_reading_process_input will notice this and update
8327 the frame's display structures.
8328 If we where iconified, we should not set garbaged,
8329 because that stops redrawing on Expose events. This looks
8330 bad if we are called from a recursive event loop
8331 (x_dispatch_event), for example when a dialog is up. */
8332 if (! f
->async_iconified
)
8333 SET_FRAME_GARBAGED (f
);
8335 f
->async_visible
= 1;
8336 f
->async_iconified
= 0;
8337 f
->output_data
.x
->has_been_visible
= 1;
8341 bufp
->kind
= DEICONIFY_EVENT
;
8342 XSETFRAME (bufp
->frame_or_window
, f
);
8348 else if (! NILP (Vframe_list
)
8349 && ! NILP (XCDR (Vframe_list
)))
8350 /* Force a redisplay sooner or later
8351 to update the frame titles
8352 in case this is the second frame. */
8353 record_asynch_buffer_change ();
8359 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8360 /* Dispatch KeyPress events when in menu. */
8361 if (popup_activated ())
8365 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
8367 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
8369 dpyinfo
->mouse_face_hidden
= 1;
8370 clear_mouse_face (dpyinfo
);
8373 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
8376 /* Scroll bars consume key events, but we want
8377 the keys to go to the scroll bar's frame. */
8378 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
8380 if (widget
&& XmIsScrollBar (widget
))
8382 widget
= XtParent (widget
);
8383 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
8386 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
8390 KeySym keysym
, orig_keysym
;
8391 /* al%imercury@uunet.uu.net says that making this 81
8392 instead of 80 fixed a bug whereby meta chars made
8395 It seems that some version of XmbLookupString has
8396 a bug of not returning XBufferOverflow in
8397 status_return even if the input is too long to
8398 fit in 81 bytes. So, we must prepare sufficient
8399 bytes for copy_buffer. 513 bytes (256 chars for
8400 two-byte character set) seems to be a fairly good
8401 approximation. -- 2000.8.10 handa@etl.go.jp */
8402 unsigned char copy_buffer
[513];
8403 unsigned char *copy_bufptr
= copy_buffer
;
8404 int copy_bufsiz
= sizeof (copy_buffer
);
8406 Lisp_Object coding_system
= Qlatin_1
;
8409 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
8410 extra_keyboard_modifiers
);
8411 modifiers
= event
.xkey
.state
;
8413 /* This will have to go some day... */
8415 /* make_lispy_event turns chars into control chars.
8416 Don't do it here because XLookupString is too eager. */
8417 event
.xkey
.state
&= ~ControlMask
;
8418 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
8419 | dpyinfo
->super_mod_mask
8420 | dpyinfo
->hyper_mod_mask
8421 | dpyinfo
->alt_mod_mask
);
8423 /* In case Meta is ComposeCharacter,
8424 clear its status. According to Markus Ehrnsperger
8425 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
8426 this enables ComposeCharacter to work whether or
8427 not it is combined with Meta. */
8428 if (modifiers
& dpyinfo
->meta_mod_mask
)
8429 bzero (&compose_status
, sizeof (compose_status
));
8434 Status status_return
;
8436 coding_system
= Vlocale_coding_system
;
8437 nbytes
= XmbLookupString (FRAME_XIC (f
),
8438 &event
.xkey
, copy_bufptr
,
8439 copy_bufsiz
, &keysym
,
8441 if (status_return
== XBufferOverflow
)
8443 copy_bufsiz
= nbytes
+ 1;
8444 copy_bufptr
= (char *) alloca (copy_bufsiz
);
8445 nbytes
= XmbLookupString (FRAME_XIC (f
),
8446 &event
.xkey
, copy_bufptr
,
8447 copy_bufsiz
, &keysym
,
8450 /* Xutf8LookupString is a new but already deprecated interface. -stef */
8451 #if 0 && defined X_HAVE_UTF8_STRING
8452 else if (status_return
== XLookupKeySym
)
8453 { /* Try again but with utf-8. */
8454 coding_system
= Qutf_8
;
8455 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
8456 &event
.xkey
, copy_bufptr
,
8457 copy_bufsiz
, &keysym
,
8459 if (status_return
== XBufferOverflow
)
8461 copy_bufsiz
= nbytes
+ 1;
8462 copy_bufptr
= (char *) alloca (copy_bufsiz
);
8463 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
8466 copy_bufsiz
, &keysym
,
8472 if (status_return
== XLookupNone
)
8474 else if (status_return
== XLookupChars
)
8479 else if (status_return
!= XLookupKeySym
8480 && status_return
!= XLookupBoth
)
8484 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
8485 copy_bufsiz
, &keysym
,
8488 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
8489 copy_bufsiz
, &keysym
,
8493 orig_keysym
= keysym
;
8499 /* First deal with keysyms which have defined
8500 translations to characters. */
8501 if (keysym
>= 32 && keysym
< 128)
8502 /* Avoid explicitly decoding each ASCII character. */
8504 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
8505 bufp
->code
= keysym
;
8506 XSETFRAME (bufp
->frame_or_window
, f
);
8509 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
8511 bufp
->timestamp
= event
.xkey
.time
;
8516 /* Now non-ASCII. */
8517 else if (HASH_TABLE_P (Vx_keysym_table
)
8518 && (NATNUMP (c
= Fgethash (make_number (keysym
),
8522 bufp
->kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
8523 ? ASCII_KEYSTROKE_EVENT
8524 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
8525 bufp
->code
= XFASTINT (c
);
8526 XSETFRAME (bufp
->frame_or_window
, f
);
8529 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
8531 bufp
->timestamp
= event
.xkey
.time
;
8536 /* Random non-modifier sorts of keysyms. */
8537 else if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
8538 || keysym
== XK_Delete
8539 #ifdef XK_ISO_Left_Tab
8540 || (keysym
>= XK_ISO_Left_Tab
8541 && keysym
<= XK_ISO_Enter
)
8543 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
8544 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
8546 /* This recognizes the "extended function
8547 keys". It seems there's no cleaner way.
8548 Test IsModifierKey to avoid handling
8549 mode_switch incorrectly. */
8550 || ((unsigned) (keysym
) >= XK_Select
8551 && (unsigned)(keysym
) < XK_KP_Space
)
8553 #ifdef XK_dead_circumflex
8554 || orig_keysym
== XK_dead_circumflex
8556 #ifdef XK_dead_grave
8557 || orig_keysym
== XK_dead_grave
8559 #ifdef XK_dead_tilde
8560 || orig_keysym
== XK_dead_tilde
8562 #ifdef XK_dead_diaeresis
8563 || orig_keysym
== XK_dead_diaeresis
8565 #ifdef XK_dead_macron
8566 || orig_keysym
== XK_dead_macron
8568 #ifdef XK_dead_degree
8569 || orig_keysym
== XK_dead_degree
8571 #ifdef XK_dead_acute
8572 || orig_keysym
== XK_dead_acute
8574 #ifdef XK_dead_cedilla
8575 || orig_keysym
== XK_dead_cedilla
8577 #ifdef XK_dead_breve
8578 || orig_keysym
== XK_dead_breve
8580 #ifdef XK_dead_ogonek
8581 || orig_keysym
== XK_dead_ogonek
8583 #ifdef XK_dead_caron
8584 || orig_keysym
== XK_dead_caron
8586 #ifdef XK_dead_doubleacute
8587 || orig_keysym
== XK_dead_doubleacute
8589 #ifdef XK_dead_abovedot
8590 || orig_keysym
== XK_dead_abovedot
8592 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
8593 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
8594 /* Any "vendor-specific" key is ok. */
8595 || (orig_keysym
& (1 << 28))
8596 || (keysym
!= NoSymbol
&& nbytes
== 0))
8597 && ! (IsModifierKey (orig_keysym
)
8599 #ifdef XK_Mode_switch
8600 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
8603 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
8605 #endif /* not HAVE_X11R5 */
8606 /* The symbols from XK_ISO_Lock
8607 to XK_ISO_Last_Group_Lock
8608 don't have real modifiers but
8609 should be treated similarly to
8610 Mode_switch by Emacs. */
8611 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
8612 || ((unsigned)(orig_keysym
)
8614 && (unsigned)(orig_keysym
)
8615 <= XK_ISO_Last_Group_Lock
)
8619 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
8621 temp_buffer
[temp_index
++] = keysym
;
8622 /* make_lispy_event will convert this to a symbolic
8624 bufp
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
8625 bufp
->code
= keysym
;
8626 XSETFRAME (bufp
->frame_or_window
, f
);
8629 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
8631 bufp
->timestamp
= event
.xkey
.time
;
8636 else if (numchars
> nbytes
)
8637 { /* Raw bytes, not keysym. */
8642 /* The input should be decoded with `coding_system'
8643 which depends on which X*LookupString function
8644 we used just above and the locale. */
8645 setup_coding_system (coding_system
, &coding
);
8646 coding
.src_multibyte
= 0;
8647 coding
.dst_multibyte
= 1;
8648 /* The input is converted to events, thus we can't
8649 handle composition. Anyway, there's no XIM that
8650 gives us composition information. */
8651 coding
.composing
= COMPOSITION_DISABLED
;
8653 for (i
= 0; i
< nbytes
; i
++)
8655 if (temp_index
== (sizeof temp_buffer
8658 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
8662 /* Decode the input data. */
8666 require
= decoding_buffer_size (&coding
, nbytes
);
8667 p
= (unsigned char *) alloca (require
);
8668 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
8669 /* We explicitely disable composition
8670 handling because key data should
8671 not contain any composition
8673 coding
.composing
= COMPOSITION_DISABLED
;
8674 decode_coding (&coding
, copy_bufptr
, p
,
8676 nbytes
= coding
.produced
;
8677 nchars
= coding
.produced_char
;
8681 /* Convert the input data to a sequence of
8682 character events. */
8683 for (i
= 0; i
< nbytes
; i
+= len
)
8685 if (nchars
== nbytes
)
8686 c
= copy_bufptr
[i
], len
= 1;
8688 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
8691 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
8692 ? ASCII_KEYSTROKE_EVENT
8693 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
8695 XSETFRAME (bufp
->frame_or_window
, f
);
8698 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
8700 bufp
->timestamp
= event
.xkey
.time
;
8707 if (keysym
== NoSymbol
)
8717 /* Don't dispatch this event since XtDispatchEvent calls
8718 XFilterEvent, and two calls in a row may freeze the
8727 /* Don't dispatch this event since XtDispatchEvent calls
8728 XFilterEvent, and two calls in a row may freeze the
8739 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
8742 bufp
+= n
, count
+= n
, numchars
-= n
;
8745 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
8748 if (event
.xcrossing
.focus
)
8750 /* Avoid nasty pop/raise loops. */
8751 if (f
&& (!(f
->auto_raise
)
8753 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
8755 x_new_focus_frame (dpyinfo
, f
);
8756 enter_timestamp
= event
.xcrossing
.time
;
8759 else if (f
== dpyinfo
->x_focus_frame
)
8760 x_new_focus_frame (dpyinfo
, 0);
8763 /* EnterNotify counts as mouse movement,
8764 so update things that depend on mouse position. */
8765 if (f
&& !f
->output_data
.x
->hourglass_p
)
8766 note_mouse_movement (f
, &event
.xmotion
);
8774 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
8777 bufp
+= n
, count
+= n
, numchars
-= n
;
8787 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
8790 bufp
+= n
, count
+= n
, numchars
-= n
;
8794 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
8797 if (f
== dpyinfo
->mouse_face_mouse_frame
)
8799 /* If we move outside the frame, then we're
8800 certainly no longer on any text in the frame. */
8801 clear_mouse_face (dpyinfo
);
8802 dpyinfo
->mouse_face_mouse_frame
= 0;
8805 /* Generate a nil HELP_EVENT to cancel a help-echo.
8806 Do it only if there's something to cancel.
8807 Otherwise, the startup message is cleared when
8808 the mouse leaves the frame. */
8809 if (any_help_event_p
)
8814 XSETFRAME (frame
, f
);
8816 n
= gen_help_event (bufp
, numchars
,
8817 Qnil
, frame
, Qnil
, Qnil
, 0);
8818 bufp
+= n
, count
+= n
, numchars
-= n
;
8828 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
8831 bufp
+= n
, count
+= n
, numchars
-= n
;
8839 previous_help_echo
= help_echo
;
8840 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
8843 if (dpyinfo
->grabbed
&& last_mouse_frame
8844 && FRAME_LIVE_P (last_mouse_frame
))
8845 f
= last_mouse_frame
;
8847 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
8849 if (dpyinfo
->mouse_face_hidden
)
8851 dpyinfo
->mouse_face_hidden
= 0;
8852 clear_mouse_face (dpyinfo
);
8858 /* Generate SELECT_WINDOW_EVENTs when needed. */
8859 if (mouse_autoselect_window
)
8864 window
= window_from_coordinates (f
,
8865 event
.xmotion
.x
, event
.xmotion
.y
,
8868 /* Window will be selected only when it is not selected now and
8869 last mouse movement event was not in it. Minibuffer window
8870 will be selected iff it is active. */
8872 && !EQ (window
, last_window
)
8873 && !EQ (window
, selected_window
)
8876 bufp
->kind
= SELECT_WINDOW_EVENT
;
8877 bufp
->frame_or_window
= window
;
8879 ++bufp
, ++count
, --numchars
;
8884 note_mouse_movement (f
, &event
.xmotion
);
8888 #ifndef USE_TOOLKIT_SCROLL_BARS
8889 struct scroll_bar
*bar
8890 = x_window_to_scroll_bar (event
.xmotion
.window
);
8893 x_scroll_bar_note_movement (bar
, &event
);
8894 #endif /* USE_TOOLKIT_SCROLL_BARS */
8896 /* If we move outside the frame, then we're
8897 certainly no longer on any text in the frame. */
8898 clear_mouse_face (dpyinfo
);
8901 /* If the contents of the global variable help_echo
8902 has changed, generate a HELP_EVENT. */
8903 if (!NILP (help_echo
)
8904 || !NILP (previous_help_echo
))
8910 XSETFRAME (frame
, f
);
8914 any_help_event_p
= 1;
8915 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
8916 help_echo_window
, help_echo_object
,
8918 bufp
+= n
, count
+= n
, numchars
-= n
;
8924 case ConfigureNotify
:
8925 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
8928 #ifndef USE_X_TOOLKIT
8930 xg_resize_widgets (f
, event
.xconfigure
.width
,
8931 event
.xconfigure
.height
);
8932 #else /* not USE_GTK */
8933 /* If there is a pending resize for fullscreen, don't
8934 do this one, the right one will come later.
8935 The toolkit version doesn't seem to need this, but we
8936 need to reset it below. */
8938 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
8939 && FRAME_NEW_WIDTH (f
) != 0);
8940 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
8941 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
8945 /* In the toolkit version, change_frame_size
8946 is called by the code that handles resizing
8947 of the EmacsFrame widget. */
8949 /* Even if the number of character rows and columns has
8950 not changed, the font size may have changed, so we need
8951 to check the pixel dimensions as well. */
8952 if (columns
!= f
->width
8953 || rows
!= f
->height
8954 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
8955 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
8957 change_frame_size (f
, rows
, columns
, 0, 1, 0);
8958 SET_FRAME_GARBAGED (f
);
8959 cancel_mouse_face (f
);
8961 #endif /* not USE_GTK */
8964 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
8965 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
8968 /* GTK creates windows but doesn't map them.
8969 Only get real positions and check fullscreen when mapped. */
8970 if (FRAME_GTK_OUTER_WIDGET (f
)
8971 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
8974 /* What we have now is the position of Emacs's own window.
8975 Convert that to the position of the window manager window. */
8976 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
8977 &f
->output_data
.x
->top_pos
);
8979 x_check_fullscreen_move (f
);
8980 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
8981 f
->output_data
.x
->want_fullscreen
&=
8982 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
8987 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
8988 xic_set_statusarea (f
);
8991 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8993 /* Since the WM decorations come below top_pos now,
8994 we must put them below top_pos in the future. */
8995 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
8996 x_wm_set_size_hint (f
, (long) 0, 0);
9004 /* If we decide we want to generate an event to be seen
9005 by the rest of Emacs, we put it here. */
9006 struct input_event emacs_event
;
9009 emacs_event
.kind
= NO_EVENT
;
9010 bzero (&compose_status
, sizeof (compose_status
));
9012 if (dpyinfo
->grabbed
9014 && FRAME_LIVE_P (last_mouse_frame
))
9015 f
= last_mouse_frame
;
9017 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9021 /* Is this in the tool-bar? */
9022 if (WINDOWP (f
->tool_bar_window
)
9023 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
9028 x
= event
.xbutton
.x
;
9029 y
= event
.xbutton
.y
;
9032 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
9033 if (EQ (window
, f
->tool_bar_window
))
9035 x_handle_tool_bar_click (f
, &event
.xbutton
);
9041 if (!dpyinfo
->x_focus_frame
9042 || f
== dpyinfo
->x_focus_frame
)
9044 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9045 if (! popup_activated ())
9047 construct_mouse_click (&emacs_event
, &event
, f
);
9052 struct scroll_bar
*bar
9053 = x_window_to_scroll_bar (event
.xbutton
.window
);
9055 #ifdef USE_TOOLKIT_SCROLL_BARS
9056 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
9058 if (bar
&& event
.xbutton
.state
& ControlMask
)
9060 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
9061 *finish
= X_EVENT_DROP
;
9063 #else /* not USE_TOOLKIT_SCROLL_BARS */
9065 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
9066 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9069 if (event
.type
== ButtonPress
)
9071 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
9072 last_mouse_frame
= f
;
9073 /* Ignore any mouse motion that happened
9074 before this event; any subsequent mouse-movement
9075 Emacs events should reflect only motion after
9081 last_tool_bar_item
= -1;
9084 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
9086 if (numchars
>= 1 && emacs_event
.kind
!= NO_EVENT
)
9088 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
9094 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
9095 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
9096 /* For a down-event in the menu bar,
9097 don't pass it to Xt right now.
9098 Instead, save it away
9099 and we will pass it to Xt from kbd_buffer_get_event.
9100 That way, we can run some Lisp code first. */
9103 ! popup_activated ()
9106 f
&& event
.type
== ButtonPress
9107 /* Verify the event is really within the menu bar
9108 and not just sent to it due to grabbing. */
9109 && event
.xbutton
.x
>= 0
9110 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
9111 && event
.xbutton
.y
>= 0
9112 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
9113 && event
.xbutton
.same_screen
)
9115 SET_SAVED_BUTTON_EVENT
;
9116 XSETFRAME (last_mouse_press_frame
, f
);
9118 *finish
= X_EVENT_DROP
;
9121 else if (event
.type
== ButtonPress
)
9123 last_mouse_press_frame
= Qnil
;
9127 #ifdef USE_MOTIF /* This should do not harm for Lucid,
9128 but I am trying to be cautious. */
9129 else if (event
.type
== ButtonRelease
)
9131 if (!NILP (last_mouse_press_frame
))
9133 f
= XFRAME (last_mouse_press_frame
);
9134 if (f
->output_data
.x
)
9135 SET_SAVED_BUTTON_EVENT
;
9140 #endif /* USE_MOTIF */
9143 #endif /* USE_X_TOOLKIT || USE_GTK */
9147 case CirculateNotify
:
9150 case CirculateRequest
:
9153 case VisibilityNotify
:
9157 /* Someone has changed the keyboard mapping - update the
9159 switch (event
.xmapping
.request
)
9161 case MappingModifier
:
9162 x_find_modifier_meanings (dpyinfo
);
9163 /* This is meant to fall through. */
9164 case MappingKeyboard
:
9165 XRefreshKeyboardMapping (&event
.xmapping
);
9171 #ifdef USE_X_TOOLKIT
9173 if (*finish
!= X_EVENT_DROP
)
9174 XtDispatchEvent (&event
);
9176 #endif /* USE_X_TOOLKIT */
9183 *finish
= X_EVENT_GOTO_OUT
;
9187 *numcharsp
= numchars
;
9194 /* Handles the XEvent EVENT on display DISPLAY.
9195 This is used for event loops outside the normal event handling,
9196 i.e. looping while a popup menu or a dialog is posted.
9198 Returns the value handle_one_xevent sets in the finish argument. */
9200 x_dispatch_event (event
, display
)
9204 struct x_display_info
*dpyinfo
;
9205 struct input_event bufp
[10];
9206 struct input_event
*bufpp
= bufp
;
9208 int finish
= X_EVENT_NORMAL
;
9210 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9211 if (dpyinfo
->display
== display
)
9217 events
= handle_one_xevent (dpyinfo
,
9222 for (i
= 0; i
< events
; ++i
)
9223 kbd_buffer_store_event (&bufp
[i
]);
9230 /* Read events coming from the X server.
9231 This routine is called by the SIGIO handler.
9232 We return as soon as there are no more events to be read.
9234 Events representing keys are stored in buffer BUFP,
9235 which can hold up to NUMCHARS characters.
9236 We return the number of characters stored into the buffer,
9237 thus pretending to be `read'.
9239 EXPECTED is nonzero if the caller knows input is available. */
9242 XTread_socket (sd
, bufp
, numchars
, expected
)
9244 /* register */ struct input_event
*bufp
;
9245 /* register */ int numchars
;
9251 int event_found
= 0;
9252 struct x_display_info
*dpyinfo
;
9254 if (interrupt_input_blocked
)
9256 interrupt_input_pending
= 1;
9260 interrupt_input_pending
= 0;
9263 /* So people can tell when we have read the available input. */
9264 input_signal_count
++;
9267 abort (); /* Don't think this happens. */
9271 /* Find the display we are supposed to read input for.
9272 It's the one communicating on descriptor SD. */
9273 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9275 #if 0 /* This ought to be unnecessary; let's verify it. */
9277 /* If available, Xlib uses FIOSNBIO to make the socket
9278 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9279 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9280 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9281 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9282 #endif /* ! defined (FIOSNBIO) */
9285 #if 0 /* This code can't be made to work, with multiple displays,
9286 and appears not to be used on any system any more.
9287 Also keyboard.c doesn't turn O_NDELAY on and off
9288 for X connections. */
9291 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9293 extern int read_alarm_should_throw
;
9294 read_alarm_should_throw
= 1;
9295 XPeekEvent (dpyinfo
->display
, &event
);
9296 read_alarm_should_throw
= 0;
9298 #endif /* HAVE_SELECT */
9302 /* For debugging, this gives a way to fake an I/O error. */
9303 if (dpyinfo
== XTread_socket_fake_io_error
)
9305 XTread_socket_fake_io_error
= 0;
9306 x_io_error_quitter (dpyinfo
->display
);
9311 count
+= x_session_check_input (bufp
, &numchars
);
9316 /* For GTK we must use the GTK event loop. But XEvents gets passed
9317 to our filter function above, and then to the big event switch.
9318 We use a bunch of globals to communicate with our filter function,
9319 that is kind of ugly, but it works. */
9320 current_dpyinfo
= dpyinfo
;
9322 while (gtk_events_pending ())
9325 current_count
= count
;
9326 current_numcharsp
= &numchars
;
9327 current_bufp
= &bufp
;
9329 gtk_main_iteration ();
9331 count
= current_count
;
9333 current_numcharsp
= 0;
9335 if (current_finish
== X_EVENT_GOTO_OUT
)
9339 #else /* not USE_GTK */
9340 while (XPending (dpyinfo
->display
))
9344 XNextEvent (dpyinfo
->display
, &event
);
9347 /* Filter events for the current X input method. */
9348 if (x_filter_event (dpyinfo
, &event
))
9353 count
+= handle_one_xevent (dpyinfo
,
9359 if (finish
== X_EVENT_GOTO_OUT
)
9362 #endif /* USE_GTK */
9367 /* On some systems, an X bug causes Emacs to get no more events
9368 when the window is destroyed. Detect that. (1994.) */
9371 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
9372 One XNOOP in 100 loops will make Emacs terminate.
9373 B. Bretthauer, 1994 */
9375 if (x_noop_count
>= 100)
9379 if (next_noop_dpyinfo
== 0)
9380 next_noop_dpyinfo
= x_display_list
;
9382 XNoOp (next_noop_dpyinfo
->display
);
9384 /* Each time we get here, cycle through the displays now open. */
9385 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
9389 /* If the focus was just given to an auto-raising frame,
9391 /* ??? This ought to be able to handle more than one such frame. */
9392 if (pending_autoraise_frame
)
9394 x_raise_frame (pending_autoraise_frame
);
9395 pending_autoraise_frame
= 0;
9406 /***********************************************************************
9408 ***********************************************************************/
9410 /* Set clipping for output in glyph row ROW. W is the window in which
9411 we operate. GC is the graphics context to set clipping in.
9412 WHOLE_LINE_P non-zero means include the areas used for truncation
9413 mark display and alike in the clipping rectangle.
9415 ROW may be a text row or, e.g., a mode line. Text rows must be
9416 clipped to the interior of the window dedicated to text display,
9417 mode lines must be clipped to the whole window. */
9420 x_clip_to_row (w
, row
, gc
, whole_line_p
)
9422 struct glyph_row
*row
;
9426 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9427 XRectangle clip_rect
;
9428 int window_x
, window_y
, window_width
, window_height
;
9430 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9432 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
9433 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
9434 clip_rect
.y
= max (clip_rect
.y
, window_y
);
9435 clip_rect
.width
= window_width
;
9436 clip_rect
.height
= row
->visible_height
;
9438 /* If clipping to the whole line, including trunc marks, extend
9439 the rectangle to the left and increase its width. */
9442 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
9443 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
9446 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
9450 /* Draw a hollow box cursor on window W in glyph row ROW. */
9453 x_draw_hollow_cursor (w
, row
)
9455 struct glyph_row
*row
;
9457 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9458 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9459 Display
*dpy
= FRAME_X_DISPLAY (f
);
9462 struct glyph
*cursor_glyph
;
9465 /* Compute frame-relative coordinates from window-relative
9467 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9468 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
9469 + row
->ascent
- w
->phys_cursor_ascent
);
9470 h
= row
->height
- 1;
9472 /* Get the glyph the cursor is on. If we can't tell because
9473 the current matrix is invalid or such, give up. */
9474 cursor_glyph
= get_phys_cursor_glyph (w
);
9475 if (cursor_glyph
== NULL
)
9478 /* Compute the width of the rectangle to draw. If on a stretch
9479 glyph, and `x-stretch-block-cursor' is nil, don't draw a
9480 rectangle as wide as the glyph, but use a canonical character
9482 wd
= cursor_glyph
->pixel_width
- 1;
9483 if (cursor_glyph
->type
== STRETCH_GLYPH
9484 && !x_stretch_cursor_p
)
9485 wd
= min (CANON_X_UNIT (f
), wd
);
9486 w
->phys_cursor_width
= wd
;
9488 /* The foreground of cursor_gc is typically the same as the normal
9489 background color, which can cause the cursor box to be invisible. */
9490 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9491 if (dpyinfo
->scratch_cursor_gc
)
9492 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
9494 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
9495 GCForeground
, &xgcv
);
9496 gc
= dpyinfo
->scratch_cursor_gc
;
9498 /* Set clipping, draw the rectangle, and reset clipping again. */
9499 x_clip_to_row (w
, row
, gc
, 0);
9500 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
9501 XSetClipMask (dpy
, gc
, None
);
9505 /* Draw a bar cursor on window W in glyph row ROW.
9507 Implementation note: One would like to draw a bar cursor with an
9508 angle equal to the one given by the font property XA_ITALIC_ANGLE.
9509 Unfortunately, I didn't find a font yet that has this property set.
9513 x_draw_bar_cursor (w
, row
, width
, kind
)
9515 struct glyph_row
*row
;
9517 enum text_cursor_kinds kind
;
9519 struct frame
*f
= XFRAME (w
->frame
);
9520 struct glyph
*cursor_glyph
;
9522 /* If cursor is out of bounds, don't draw garbage. This can happen
9523 in mini-buffer windows when switching between echo area glyphs
9525 cursor_glyph
= get_phys_cursor_glyph (w
);
9526 if (cursor_glyph
== NULL
)
9529 /* If on an image, draw like a normal cursor. That's usually better
9530 visible than drawing a bar, esp. if the image is large so that
9531 the bar might not be in the window. */
9532 if (cursor_glyph
->type
== IMAGE_GLYPH
)
9534 struct glyph_row
*row
;
9535 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
9536 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
9540 Display
*dpy
= FRAME_X_DISPLAY (f
);
9541 Window window
= FRAME_X_WINDOW (f
);
9542 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
9543 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
9544 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
9547 /* If the glyph's background equals the color we normally draw
9548 the bar cursor in, the bar cursor in its normal color is
9549 invisible. Use the glyph's foreground color instead in this
9550 case, on the assumption that the glyph's colors are chosen so
9551 that the glyph is legible. */
9552 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
9553 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
9555 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9556 xgcv
.graphics_exposures
= 0;
9559 XChangeGC (dpy
, gc
, mask
, &xgcv
);
9562 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
9563 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
9567 width
= FRAME_CURSOR_WIDTH (f
);
9568 width
= min (cursor_glyph
->pixel_width
, width
);
9570 w
->phys_cursor_width
= width
;
9571 x_clip_to_row (w
, row
, gc
, 0);
9573 if (kind
== BAR_CURSOR
)
9574 XFillRectangle (dpy
, window
, gc
,
9575 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
9576 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9577 width
, row
->height
);
9579 XFillRectangle (dpy
, window
, gc
,
9580 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
9581 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
9582 row
->height
- width
),
9583 cursor_glyph
->pixel_width
,
9586 XSetClipMask (dpy
, gc
, None
);
9591 /* Clear the cursor of window W to background color, and mark the
9592 cursor as not shown. This is used when the text where the cursor
9593 is is about to be rewritten. */
9599 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
9600 x_update_window_cursor (w
, 0);
9604 /* Draw the cursor glyph of window W in glyph row ROW. See the
9605 comment of x_draw_glyphs for the meaning of HL. */
9608 x_draw_phys_cursor_glyph (w
, row
, hl
)
9610 struct glyph_row
*row
;
9611 enum draw_glyphs_face hl
;
9613 /* If cursor hpos is out of bounds, don't draw garbage. This can
9614 happen in mini-buffer windows when switching between echo area
9615 glyphs and mini-buffer. */
9616 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
9618 int on_p
= w
->phys_cursor_on_p
;
9621 x1
= x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
9622 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
9624 w
->phys_cursor_on_p
= on_p
;
9626 if (hl
== DRAW_CURSOR
)
9627 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
9629 /* When we erase the cursor, and ROW is overlapped by other
9630 rows, make sure that these overlapping parts of other rows
9632 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
9634 if (row
> w
->current_matrix
->rows
9635 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
9636 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
9638 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
9639 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
9640 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
9646 /* Erase the image of a cursor of window W from the screen. */
9649 x_erase_phys_cursor (w
)
9652 struct frame
*f
= XFRAME (w
->frame
);
9653 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9654 int hpos
= w
->phys_cursor
.hpos
;
9655 int vpos
= w
->phys_cursor
.vpos
;
9656 int mouse_face_here_p
= 0;
9657 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
9658 struct glyph_row
*cursor_row
;
9659 struct glyph
*cursor_glyph
;
9660 enum draw_glyphs_face hl
;
9662 /* No cursor displayed or row invalidated => nothing to do on the
9664 if (w
->phys_cursor_type
== NO_CURSOR
)
9665 goto mark_cursor_off
;
9667 /* VPOS >= active_glyphs->nrows means that window has been resized.
9668 Don't bother to erase the cursor. */
9669 if (vpos
>= active_glyphs
->nrows
)
9670 goto mark_cursor_off
;
9672 /* If row containing cursor is marked invalid, there is nothing we
9674 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
9675 if (!cursor_row
->enabled_p
)
9676 goto mark_cursor_off
;
9678 /* If row is completely invisible, don't attempt to delete a cursor which
9679 isn't there. This can happen if cursor is at top of a window, and
9680 we switch to a buffer with a header line in that window. */
9681 if (cursor_row
->visible_height
<= 0)
9682 goto mark_cursor_off
;
9684 /* This can happen when the new row is shorter than the old one.
9685 In this case, either x_draw_glyphs or clear_end_of_line
9686 should have cleared the cursor. Note that we wouldn't be
9687 able to erase the cursor in this case because we don't have a
9688 cursor glyph at hand. */
9689 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
9690 goto mark_cursor_off
;
9692 /* If the cursor is in the mouse face area, redisplay that when
9693 we clear the cursor. */
9694 if (! NILP (dpyinfo
->mouse_face_window
)
9695 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
9696 && (vpos
> dpyinfo
->mouse_face_beg_row
9697 || (vpos
== dpyinfo
->mouse_face_beg_row
9698 && hpos
>= dpyinfo
->mouse_face_beg_col
))
9699 && (vpos
< dpyinfo
->mouse_face_end_row
9700 || (vpos
== dpyinfo
->mouse_face_end_row
9701 && hpos
< dpyinfo
->mouse_face_end_col
))
9702 /* Don't redraw the cursor's spot in mouse face if it is at the
9703 end of a line (on a newline). The cursor appears there, but
9704 mouse highlighting does not. */
9705 && cursor_row
->used
[TEXT_AREA
] > hpos
)
9706 mouse_face_here_p
= 1;
9708 /* Maybe clear the display under the cursor. */
9709 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
9712 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9714 cursor_glyph
= get_phys_cursor_glyph (w
);
9715 if (cursor_glyph
== NULL
)
9716 goto mark_cursor_off
;
9718 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9720 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9722 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
9724 cursor_glyph
->pixel_width
,
9725 cursor_row
->visible_height
,
9729 /* Erase the cursor by redrawing the character underneath it. */
9730 if (mouse_face_here_p
)
9731 hl
= DRAW_MOUSE_FACE
;
9733 hl
= DRAW_NORMAL_TEXT
;
9734 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
9737 w
->phys_cursor_on_p
= 0;
9738 w
->phys_cursor_type
= NO_CURSOR
;
9742 /* Non-zero if physical cursor of window W is within mouse face. */
9745 cursor_in_mouse_face_p (w
)
9748 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
9749 int in_mouse_face
= 0;
9751 if (WINDOWP (dpyinfo
->mouse_face_window
)
9752 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
9754 int hpos
= w
->phys_cursor
.hpos
;
9755 int vpos
= w
->phys_cursor
.vpos
;
9757 if (vpos
>= dpyinfo
->mouse_face_beg_row
9758 && vpos
<= dpyinfo
->mouse_face_end_row
9759 && (vpos
> dpyinfo
->mouse_face_beg_row
9760 || hpos
>= dpyinfo
->mouse_face_beg_col
)
9761 && (vpos
< dpyinfo
->mouse_face_end_row
9762 || hpos
< dpyinfo
->mouse_face_end_col
9763 || dpyinfo
->mouse_face_past_end
))
9767 return in_mouse_face
;
9771 /* Display or clear cursor of window W. If ON is zero, clear the
9772 cursor. If it is non-zero, display the cursor. If ON is nonzero,
9773 where to put the cursor is specified by HPOS, VPOS, X and Y. */
9776 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
9778 int on
, hpos
, vpos
, x
, y
;
9780 struct frame
*f
= XFRAME (w
->frame
);
9781 int new_cursor_type
;
9782 int new_cursor_width
;
9784 struct glyph_matrix
*current_glyphs
;
9785 struct glyph_row
*glyph_row
;
9786 struct glyph
*glyph
;
9788 /* This is pointless on invisible frames, and dangerous on garbaged
9789 windows and frames; in the latter case, the frame or window may
9790 be in the midst of changing its size, and x and y may be off the
9792 if (! FRAME_VISIBLE_P (f
)
9793 || FRAME_GARBAGED_P (f
)
9794 || vpos
>= w
->current_matrix
->nrows
9795 || hpos
>= w
->current_matrix
->matrix_w
)
9798 /* If cursor is off and we want it off, return quickly. */
9799 if (!on
&& !w
->phys_cursor_on_p
)
9802 current_glyphs
= w
->current_matrix
;
9803 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
9804 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
9806 /* If cursor row is not enabled, we don't really know where to
9807 display the cursor. */
9808 if (!glyph_row
->enabled_p
)
9810 w
->phys_cursor_on_p
= 0;
9814 xassert (interrupt_input_blocked
);
9816 /* Set new_cursor_type to the cursor we want to be displayed. */
9817 new_cursor_type
= get_window_cursor_type (w
, &new_cursor_width
, &active_cursor
);
9819 /* If cursor is currently being shown and we don't want it to be or
9820 it is in the wrong place, or the cursor type is not what we want,
9822 if (w
->phys_cursor_on_p
9824 || w
->phys_cursor
.x
!= x
9825 || w
->phys_cursor
.y
!= y
9826 || new_cursor_type
!= w
->phys_cursor_type
9827 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
9828 && new_cursor_width
!= w
->phys_cursor_width
)))
9829 x_erase_phys_cursor (w
);
9831 /* Don't check phys_cursor_on_p here because that flag is only set
9832 to zero in some cases where we know that the cursor has been
9833 completely erased, to avoid the extra work of erasing the cursor
9834 twice. In other words, phys_cursor_on_p can be 1 and the cursor
9835 still not be visible, or it has only been partly erased. */
9838 w
->phys_cursor_ascent
= glyph_row
->ascent
;
9839 w
->phys_cursor_height
= glyph_row
->height
;
9841 /* Set phys_cursor_.* before x_draw_.* is called because some
9842 of them may need the information. */
9843 w
->phys_cursor
.x
= x
;
9844 w
->phys_cursor
.y
= glyph_row
->y
;
9845 w
->phys_cursor
.hpos
= hpos
;
9846 w
->phys_cursor
.vpos
= vpos
;
9847 w
->phys_cursor_type
= new_cursor_type
;
9848 w
->phys_cursor_on_p
= 1;
9850 switch (new_cursor_type
)
9852 case HOLLOW_BOX_CURSOR
:
9853 x_draw_hollow_cursor (w
, glyph_row
);
9856 case FILLED_BOX_CURSOR
:
9857 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9861 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
, BAR_CURSOR
);
9865 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
, HBAR_CURSOR
);
9869 w
->phys_cursor_width
= 0;
9877 if (w
== XWINDOW (f
->selected_window
))
9878 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
9879 xic_set_preeditarea (w
, x
, y
);
9884 if (updating_frame
!= f
)
9885 XFlush (FRAME_X_DISPLAY (f
));
9890 /* Display the cursor on window W, or clear it. X and Y are window
9891 relative pixel coordinates. HPOS and VPOS are glyph matrix
9892 positions. If W is not the selected window, display a hollow
9893 cursor. ON non-zero means display the cursor at X, Y which
9894 correspond to HPOS, VPOS, otherwise it is cleared. */
9897 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
9899 int on
, hpos
, vpos
, x
, y
;
9902 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
9907 /* Display the cursor on window W, or clear it, according to ON_P.
9908 Don't change the cursor's position. */
9911 x_update_cursor (f
, on_p
)
9915 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
9919 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
9920 in the window tree rooted at W. */
9923 x_update_cursor_in_window_tree (w
, on_p
)
9929 if (!NILP (w
->hchild
))
9930 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
9931 else if (!NILP (w
->vchild
))
9932 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
9934 x_update_window_cursor (w
, on_p
);
9936 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
9941 /* Switch the display of W's cursor on or off, according to the value
9945 x_update_window_cursor (w
, on
)
9949 /* Don't update cursor in windows whose frame is in the process
9950 of being deleted. */
9951 if (w
->current_matrix
)
9954 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
9955 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
9965 /* Make the x-window of frame F use the gnu icon bitmap. */
9968 x_bitmap_icon (f
, file
)
9974 if (FRAME_X_WINDOW (f
) == 0)
9977 /* Free up our existing icon bitmap if any. */
9978 if (f
->output_data
.x
->icon_bitmap
> 0)
9979 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
9980 f
->output_data
.x
->icon_bitmap
= 0;
9983 bitmap_id
= x_create_bitmap_from_file (f
, file
);
9986 /* Create the GNU bitmap if necessary. */
9987 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
9988 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
9989 = x_create_bitmap_from_data (f
, gnu_bits
,
9990 gnu_width
, gnu_height
);
9992 /* The first time we create the GNU bitmap,
9993 this increments the ref-count one extra time.
9994 As a result, the GNU bitmap is never freed.
9995 That way, we don't have to worry about allocating it again. */
9996 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
9998 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10001 x_wm_set_icon_pixmap (f
, bitmap_id
);
10002 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10008 /* Make the x-window of frame F use a rectangle with text.
10009 Use ICON_NAME as the text. */
10012 x_text_icon (f
, icon_name
)
10016 if (FRAME_X_WINDOW (f
) == 0)
10021 XTextProperty text
;
10022 text
.value
= (unsigned char *) icon_name
;
10023 text
.encoding
= XA_STRING
;
10025 text
.nitems
= strlen (icon_name
);
10026 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
10028 #else /* not HAVE_X11R4 */
10029 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), icon_name
);
10030 #endif /* not HAVE_X11R4 */
10032 if (f
->output_data
.x
->icon_bitmap
> 0)
10033 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10034 f
->output_data
.x
->icon_bitmap
= 0;
10035 x_wm_set_icon_pixmap (f
, 0);
10040 #define X_ERROR_MESSAGE_SIZE 200
10042 /* If non-nil, this should be a string.
10043 It means catch X errors and store the error message in this string. */
10045 static Lisp_Object x_error_message_string
;
10047 /* An X error handler which stores the error message in
10048 x_error_message_string. This is called from x_error_handler if
10049 x_catch_errors is in effect. */
10052 x_error_catcher (display
, error
)
10054 XErrorEvent
*error
;
10056 XGetErrorText (display
, error
->error_code
,
10057 SDATA (x_error_message_string
),
10058 X_ERROR_MESSAGE_SIZE
);
10061 /* Begin trapping X errors for display DPY. Actually we trap X errors
10062 for all displays, but DPY should be the display you are actually
10065 After calling this function, X protocol errors no longer cause
10066 Emacs to exit; instead, they are recorded in the string
10067 stored in x_error_message_string.
10069 Calling x_check_errors signals an Emacs error if an X error has
10070 occurred since the last call to x_catch_errors or x_check_errors.
10072 Calling x_uncatch_errors resumes the normal error handling. */
10074 void x_check_errors ();
10075 static Lisp_Object
x_catch_errors_unwind ();
10078 x_catch_errors (dpy
)
10081 int count
= SPECPDL_INDEX ();
10083 /* Make sure any errors from previous requests have been dealt with. */
10084 XSync (dpy
, False
);
10086 record_unwind_protect (x_catch_errors_unwind
,
10087 Fcons (make_save_value (dpy
, 0),
10088 x_error_message_string
));
10090 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10091 SSET (x_error_message_string
, 0, 0);
10096 /* Unbind the binding that we made to check for X errors. */
10099 x_catch_errors_unwind (old_val
)
10100 Lisp_Object old_val
;
10104 first
= XCAR (old_val
);
10106 XSync (XSAVE_VALUE (first
)->pointer
, False
);
10108 x_error_message_string
= XCDR (old_val
);
10112 /* If any X protocol errors have arrived since the last call to
10113 x_catch_errors or x_check_errors, signal an Emacs error using
10114 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10117 x_check_errors (dpy
, format
)
10121 /* Make sure to catch any errors incurred so far. */
10122 XSync (dpy
, False
);
10124 if (SREF (x_error_message_string
, 0))
10125 error (format
, SDATA (x_error_message_string
));
10128 /* Nonzero if we had any X protocol errors
10129 since we did x_catch_errors on DPY. */
10132 x_had_errors_p (dpy
)
10135 /* Make sure to catch any errors incurred so far. */
10136 XSync (dpy
, False
);
10138 return SREF (x_error_message_string
, 0) != 0;
10141 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
10144 x_clear_errors (dpy
)
10147 SSET (x_error_message_string
, 0, 0);
10150 /* Stop catching X protocol errors and let them make Emacs die.
10151 DPY should be the display that was passed to x_catch_errors.
10152 COUNT should be the value that was returned by
10153 the corresponding call to x_catch_errors. */
10156 x_uncatch_errors (dpy
, count
)
10160 unbind_to (count
, Qnil
);
10164 static unsigned int x_wire_count
;
10167 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
10172 /* Handle SIGPIPE, which can happen when the connection to a server
10173 simply goes away. SIGPIPE is handled by x_connection_signal.
10174 Don't need to do anything, because the write which caused the
10175 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
10176 which will do the appropriate cleanup for us. */
10179 x_connection_signal (signalnum
) /* If we don't have an argument, */
10180 int signalnum
; /* some compilers complain in signal calls. */
10183 /* USG systems forget handlers when they are used;
10184 must reestablish each time */
10185 signal (signalnum
, x_connection_signal
);
10190 /************************************************************************
10192 ************************************************************************/
10194 /* Error message passed to x_connection_closed. */
10196 static char *error_msg
;
10198 /* Function installed as fatal_error_signal_hook in
10199 x_connection_closed. Print the X error message, and exit normally,
10200 instead of dumping core when XtCloseDisplay fails. */
10203 x_fatal_error_signal ()
10205 fprintf (stderr
, "%s\n", error_msg
);
10209 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
10210 the text of an error message that lead to the connection loss. */
10213 x_connection_closed (dpy
, error_message
)
10215 char *error_message
;
10217 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
10218 Lisp_Object frame
, tail
;
10221 error_msg
= (char *) alloca (strlen (error_message
) + 1);
10222 strcpy (error_msg
, error_message
);
10223 handling_signal
= 0;
10225 /* Prevent being called recursively because of an error condition
10226 below. Otherwise, we might end up with printing ``can't find per
10227 display information'' in the recursive call instead of printing
10228 the original message here. */
10229 count
= x_catch_errors (dpy
);
10231 /* We have to close the display to inform Xt that it doesn't
10232 exist anymore. If we don't, Xt will continue to wait for
10233 events from the display. As a consequence, a sequence of
10235 M-x make-frame-on-display RET :1 RET
10236 ...kill the new frame, so that we get an IO error...
10237 M-x make-frame-on-display RET :1 RET
10239 will indefinitely wait in Xt for events for display `:1', opened
10240 in the first class to make-frame-on-display.
10242 Closing the display is reported to lead to a bus error on
10243 OpenWindows in certain situations. I suspect that is a bug
10244 in OpenWindows. I don't know how to cicumvent it here. */
10246 #ifdef USE_X_TOOLKIT
10247 /* If DPYINFO is null, this means we didn't open the display
10248 in the first place, so don't try to close it. */
10251 extern void (*fatal_error_signal_hook
) P_ ((void));
10252 fatal_error_signal_hook
= x_fatal_error_signal
;
10253 XtCloseDisplay (dpy
);
10254 fatal_error_signal_hook
= NULL
;
10258 /* Indicate that this display is dead. */
10260 dpyinfo
->display
= 0;
10262 /* First delete frames whose mini-buffers are on frames
10263 that are on the dead display. */
10264 FOR_EACH_FRAME (tail
, frame
)
10266 Lisp_Object minibuf_frame
;
10268 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
10269 if (FRAME_X_P (XFRAME (frame
))
10270 && FRAME_X_P (XFRAME (minibuf_frame
))
10271 && ! EQ (frame
, minibuf_frame
)
10272 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
10273 Fdelete_frame (frame
, Qt
);
10276 /* Now delete all remaining frames on the dead display.
10277 We are now sure none of these is used as the mini-buffer
10278 for another frame that we need to delete. */
10279 FOR_EACH_FRAME (tail
, frame
)
10280 if (FRAME_X_P (XFRAME (frame
))
10281 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
10283 /* Set this to t so that Fdelete_frame won't get confused
10284 trying to find a replacement. */
10285 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
10286 Fdelete_frame (frame
, Qt
);
10290 x_delete_display (dpyinfo
);
10292 x_uncatch_errors (dpy
, count
);
10294 if (x_display_list
== 0)
10296 fprintf (stderr
, "%s\n", error_msg
);
10297 shut_down_emacs (0, 0, Qnil
);
10301 /* Ordinary stack unwind doesn't deal with these. */
10303 sigunblock (sigmask (SIGIO
));
10305 sigunblock (sigmask (SIGALRM
));
10306 TOTALLY_UNBLOCK_INPUT
;
10308 clear_waiting_for_input ();
10309 error ("%s", error_msg
);
10313 /* This is the usual handler for X protocol errors.
10314 It kills all frames on the display that we got the error for.
10315 If that was the only one, it prints an error message and kills Emacs. */
10318 x_error_quitter (display
, error
)
10320 XErrorEvent
*error
;
10322 char buf
[256], buf1
[356];
10324 /* Note that there is no real way portable across R3/R4 to get the
10325 original error handler. */
10327 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
10328 sprintf (buf1
, "X protocol error: %s on protocol request %d",
10329 buf
, error
->request_code
);
10330 x_connection_closed (display
, buf1
);
10334 /* This is the first-level handler for X protocol errors.
10335 It calls x_error_quitter or x_error_catcher. */
10338 x_error_handler (display
, error
)
10340 XErrorEvent
*error
;
10342 if (! NILP (x_error_message_string
))
10343 x_error_catcher (display
, error
);
10345 x_error_quitter (display
, error
);
10349 /* This is the handler for X IO errors, always.
10350 It kills all frames on the display that we lost touch with.
10351 If that was the only one, it prints an error message and kills Emacs. */
10354 x_io_error_quitter (display
)
10359 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
10360 x_connection_closed (display
, buf
);
10364 /* Changing the font of the frame. */
10366 /* Give frame F the font named FONTNAME as its default font, and
10367 return the full name of that font. FONTNAME may be a wildcard
10368 pattern; in that case, we choose some font that fits the pattern.
10369 The return value shows which font we chose. */
10372 x_new_font (f
, fontname
)
10374 register char *fontname
;
10376 struct font_info
*fontp
10377 = FS_LOAD_FONT (f
, 0, fontname
, -1);
10382 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
10383 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
10384 f
->output_data
.x
->fontset
= -1;
10386 compute_fringe_widths (f
, 1);
10388 /* Compute the scroll bar width in character columns. */
10389 if (f
->scroll_bar_pixel_width
> 0)
10391 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10392 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
10396 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
10397 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
10400 /* Now make the frame display the given font. */
10401 if (FRAME_X_WINDOW (f
) != 0)
10403 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
10404 f
->output_data
.x
->font
->fid
);
10405 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
10406 f
->output_data
.x
->font
->fid
);
10407 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
10408 f
->output_data
.x
->font
->fid
);
10410 frame_update_line_height (f
);
10412 /* Don't change the size of a tip frame; there's no point in
10413 doing it because it's done in Fx_show_tip, and it leads to
10414 problems because the tip frame has no widget. */
10415 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
10416 x_set_window_size (f
, 0, f
->width
, f
->height
);
10419 /* If we are setting a new frame's font for the first time,
10420 there are no faces yet, so this font's height is the line height. */
10421 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
10423 return build_string (fontp
->full_name
);
10426 /* Give frame F the fontset named FONTSETNAME as its default font, and
10427 return the full name of that fontset. FONTSETNAME may be a wildcard
10428 pattern; in that case, we choose some fontset that fits the pattern.
10429 The return value shows which fontset we chose. */
10432 x_new_fontset (f
, fontsetname
)
10436 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
10437 Lisp_Object result
;
10442 if (f
->output_data
.x
->fontset
== fontset
)
10443 /* This fontset is already set in frame F. There's nothing more
10445 return fontset_name (fontset
);
10447 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
10449 if (!STRINGP (result
))
10450 /* Can't load ASCII font. */
10453 /* Since x_new_font doesn't update any fontset information, do it now. */
10454 f
->output_data
.x
->fontset
= fontset
;
10458 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
10459 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
10462 return build_string (fontsetname
);
10466 /***********************************************************************
10468 ***********************************************************************/
10474 /* XIM destroy callback function, which is called whenever the
10475 connection to input method XIM dies. CLIENT_DATA contains a
10476 pointer to the x_display_info structure corresponding to XIM. */
10479 xim_destroy_callback (xim
, client_data
, call_data
)
10481 XPointer client_data
;
10482 XPointer call_data
;
10484 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
10485 Lisp_Object frame
, tail
;
10489 /* No need to call XDestroyIC.. */
10490 FOR_EACH_FRAME (tail
, frame
)
10492 struct frame
*f
= XFRAME (frame
);
10493 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
10495 FRAME_XIC (f
) = NULL
;
10496 if (FRAME_XIC_FONTSET (f
))
10498 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
10499 FRAME_XIC_FONTSET (f
) = NULL
;
10504 /* No need to call XCloseIM. */
10505 dpyinfo
->xim
= NULL
;
10506 XFree (dpyinfo
->xim_styles
);
10510 #endif /* HAVE_X11R6 */
10513 /* This isn't prototyped in OSF 5.0 or 5.1a. */
10514 extern char *XSetIMValues
P_ ((XIM
, ...));
10517 /* Open the connection to the XIM server on display DPYINFO.
10518 RESOURCE_NAME is the resource name Emacs uses. */
10521 xim_open_dpy (dpyinfo
, resource_name
)
10522 struct x_display_info
*dpyinfo
;
10523 char *resource_name
;
10528 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
10529 dpyinfo
->xim
= xim
;
10534 XIMCallback destroy
;
10537 /* Get supported styles and XIM values. */
10538 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
10541 destroy
.callback
= xim_destroy_callback
;
10542 destroy
.client_data
= (XPointer
)dpyinfo
;
10543 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
10547 #else /* not USE_XIM */
10548 dpyinfo
->xim
= NULL
;
10549 #endif /* not USE_XIM */
10553 #ifdef HAVE_X11R6_XIM
10557 struct x_display_info
*dpyinfo
;
10558 char *resource_name
;
10561 /* XIM instantiate callback function, which is called whenever an XIM
10562 server is available. DISPLAY is the display of the XIM.
10563 CLIENT_DATA contains a pointer to an xim_inst_t structure created
10564 when the callback was registered. */
10567 xim_instantiate_callback (display
, client_data
, call_data
)
10569 XPointer client_data
;
10570 XPointer call_data
;
10572 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
10573 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
10575 /* We don't support multiple XIM connections. */
10579 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
10581 /* Create XIC for the existing frames on the same display, as long
10582 as they have no XIC. */
10583 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
10585 Lisp_Object tail
, frame
;
10588 FOR_EACH_FRAME (tail
, frame
)
10590 struct frame
*f
= XFRAME (frame
);
10592 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
10593 if (FRAME_XIC (f
) == NULL
)
10595 create_frame_xic (f
);
10596 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
10597 xic_set_statusarea (f
);
10598 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
10600 struct window
*w
= XWINDOW (f
->selected_window
);
10601 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
10610 #endif /* HAVE_X11R6_XIM */
10613 /* Open a connection to the XIM server on display DPYINFO.
10614 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
10615 connection only at the first time. On X11R6, open the connection
10616 in the XIM instantiate callback function. */
10619 xim_initialize (dpyinfo
, resource_name
)
10620 struct x_display_info
*dpyinfo
;
10621 char *resource_name
;
10624 #ifdef HAVE_X11R6_XIM
10625 struct xim_inst_t
*xim_inst
;
10628 dpyinfo
->xim
= NULL
;
10629 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
10630 xim_inst
->dpyinfo
= dpyinfo
;
10631 len
= strlen (resource_name
);
10632 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
10633 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
10634 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
10635 resource_name
, EMACS_CLASS
,
10636 xim_instantiate_callback
,
10637 /* Fixme: This is XPointer in
10638 XFree86 but (XPointer *) on
10639 Tru64, at least. */
10640 (XPointer
) xim_inst
);
10641 #else /* not HAVE_X11R6_XIM */
10642 dpyinfo
->xim
= NULL
;
10643 xim_open_dpy (dpyinfo
, resource_name
);
10644 #endif /* not HAVE_X11R6_XIM */
10646 #else /* not USE_XIM */
10647 dpyinfo
->xim
= NULL
;
10648 #endif /* not USE_XIM */
10652 /* Close the connection to the XIM server on display DPYINFO. */
10655 xim_close_dpy (dpyinfo
)
10656 struct x_display_info
*dpyinfo
;
10659 #ifdef HAVE_X11R6_XIM
10660 if (dpyinfo
->display
)
10661 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
10663 xim_instantiate_callback
, NULL
);
10664 #endif /* not HAVE_X11R6_XIM */
10665 if (dpyinfo
->display
)
10666 XCloseIM (dpyinfo
->xim
);
10667 dpyinfo
->xim
= NULL
;
10668 XFree (dpyinfo
->xim_styles
);
10669 #endif /* USE_XIM */
10672 #endif /* not HAVE_X11R6_XIM */
10676 /* Calculate the absolute position in frame F
10677 from its current recorded position values and gravity. */
10680 x_calc_absolute_position (f
)
10684 int win_x
= 0, win_y
= 0;
10685 int flags
= f
->output_data
.x
->size_hint_flags
;
10688 /* We have nothing to do if the current position
10689 is already for the top-left corner. */
10690 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
10693 this_window
= FRAME_OUTER_WINDOW (f
);
10695 /* Find the position of the outside upper-left corner of
10696 the inner window, with respect to the outer window.
10697 But do this only if we will need the results. */
10698 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10703 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
10706 x_clear_errors (FRAME_X_DISPLAY (f
));
10707 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
10709 /* From-window, to-window. */
10711 f
->output_data
.x
->parent_desc
,
10713 /* From-position, to-position. */
10714 0, 0, &win_x
, &win_y
,
10716 /* Child of win. */
10718 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
10720 Window newroot
, newparent
= 0xdeadbeef;
10721 Window
*newchildren
;
10722 unsigned int nchildren
;
10724 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
10725 &newparent
, &newchildren
, &nchildren
))
10728 XFree ((char *) newchildren
);
10730 f
->output_data
.x
->parent_desc
= newparent
;
10736 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
10740 /* Treat negative positions as relative to the leftmost bottommost
10741 position that fits on the screen. */
10742 if (flags
& XNegative
)
10743 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
10744 - 2 * f
->output_data
.x
->border_width
- win_x
10746 + f
->output_data
.x
->left_pos
);
10749 int height
= PIXEL_HEIGHT (f
);
10751 #if defined USE_X_TOOLKIT && defined USE_MOTIF
10752 /* Something is fishy here. When using Motif, starting Emacs with
10753 `-g -0-0', the frame appears too low by a few pixels.
10755 This seems to be so because initially, while Emacs is starting,
10756 the column widget's height and the frame's pixel height are
10757 different. The column widget's height is the right one. In
10758 later invocations, when Emacs is up, the frame's pixel height
10761 It's not obvious where the initial small difference comes from.
10762 2000-12-01, gerd. */
10764 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
10767 if (flags
& YNegative
)
10768 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
10769 - 2 * f
->output_data
.x
->border_width
10772 + f
->output_data
.x
->top_pos
);
10775 /* The left_pos and top_pos
10776 are now relative to the top and left screen edges,
10777 so the flags should correspond. */
10778 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10781 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
10782 to really change the position, and 0 when calling from
10783 x_make_frame_visible (in that case, XOFF and YOFF are the current
10784 position values). It is -1 when calling from x_set_frame_parameters,
10785 which means, do adjust for borders but don't change the gravity. */
10788 x_set_offset (f
, xoff
, yoff
, change_gravity
)
10790 register int xoff
, yoff
;
10791 int change_gravity
;
10793 int modified_top
, modified_left
;
10795 if (change_gravity
> 0)
10797 f
->output_data
.x
->top_pos
= yoff
;
10798 f
->output_data
.x
->left_pos
= xoff
;
10799 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10801 f
->output_data
.x
->size_hint_flags
|= XNegative
;
10803 f
->output_data
.x
->size_hint_flags
|= YNegative
;
10804 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10806 x_calc_absolute_position (f
);
10809 x_wm_set_size_hint (f
, (long) 0, 0);
10811 modified_left
= f
->output_data
.x
->left_pos
;
10812 modified_top
= f
->output_data
.x
->top_pos
;
10813 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
10814 this seems to be unnecessary and incorrect. rms, 4/17/97. */
10815 /* It is a mystery why we need to add the border_width here
10816 when the frame is already visible, but experiment says we do. */
10817 if (change_gravity
!= 0)
10819 modified_left
+= f
->output_data
.x
->border_width
;
10820 modified_top
+= f
->output_data
.x
->border_width
;
10824 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10825 modified_left
, modified_top
);
10829 /* Check if we need to resize the frame due to a fullscreen request.
10830 If so needed, resize the frame. */
10832 x_check_fullscreen (f
)
10835 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
10837 int width
, height
, ign
;
10839 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10840 &f
->output_data
.x
->top_pos
);
10842 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
10844 /* We do not need to move the window, it shall be taken care of
10845 when setting WM manager hints.
10846 If the frame is visible already, the position is checked by
10847 x_check_fullscreen_move. */
10848 if (f
->width
!= width
|| f
->height
!= height
)
10850 change_frame_size (f
, height
, width
, 0, 1, 0);
10851 SET_FRAME_GARBAGED (f
);
10852 cancel_mouse_face (f
);
10854 /* Wait for the change of frame size to occur */
10855 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
10861 /* If frame parameters are set after the frame is mapped, we need to move
10862 the window. This is done in xfns.c.
10863 Some window managers moves the window to the right position, some
10864 moves the outer window manager window to the specified position.
10865 Here we check that we are in the right spot. If not, make a second
10866 move, assuming we are dealing with the second kind of window manager. */
10868 x_check_fullscreen_move (f
)
10871 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
10873 int expect_top
= f
->output_data
.x
->top_pos
;
10874 int expect_left
= f
->output_data
.x
->left_pos
;
10876 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
10878 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
10881 if (expect_top
!= f
->output_data
.x
->top_pos
10882 || expect_left
!= f
->output_data
.x
->left_pos
)
10883 x_set_offset (f
, expect_left
, expect_top
, 1);
10885 /* Just do this once */
10886 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
10891 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
10892 wanted positions of the WM window (not emacs window).
10893 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
10894 window (FRAME_X_WINDOW).
10897 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
10904 int newwidth
= f
->width
, newheight
= f
->height
;
10906 *top_pos
= f
->output_data
.x
->top_pos
;
10907 *left_pos
= f
->output_data
.x
->left_pos
;
10909 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
10913 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
10914 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
10915 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
10916 - f
->output_data
.x
->y_pixels_diff
;
10917 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
10921 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
10925 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
10926 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
10927 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
10928 - f
->output_data
.x
->x_pixels_diff
;
10929 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
10934 *height
= newheight
;
10938 /* Change the size of frame F's X window to COLS/ROWS in the case F
10939 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
10940 top-left-corner window gravity for this size change and subsequent
10941 size changes. Otherwise we leave the window gravity unchanged. */
10944 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
10946 int change_gravity
;
10949 int pixelwidth
, pixelheight
;
10951 check_frame_size (f
, &rows
, &cols
);
10952 f
->output_data
.x
->vertical_scroll_bar_extra
10953 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
10955 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
10956 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
10957 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
10959 compute_fringe_widths (f
, 0);
10961 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
10962 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
10964 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10965 x_wm_set_size_hint (f
, (long) 0, 0);
10967 XSync (FRAME_X_DISPLAY (f
), False
);
10968 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10969 pixelwidth
, pixelheight
);
10971 /* Now, strictly speaking, we can't be sure that this is accurate,
10972 but the window manager will get around to dealing with the size
10973 change request eventually, and we'll hear how it went when the
10974 ConfigureNotify event gets here.
10976 We could just not bother storing any of this information here,
10977 and let the ConfigureNotify event set everything up, but that
10978 might be kind of confusing to the Lisp code, since size changes
10979 wouldn't be reported in the frame parameters until some random
10980 point in the future when the ConfigureNotify event arrives.
10982 We pass 1 for DELAY since we can't run Lisp code inside of
10984 change_frame_size (f
, rows
, cols
, 0, 1, 0);
10985 PIXEL_WIDTH (f
) = pixelwidth
;
10986 PIXEL_HEIGHT (f
) = pixelheight
;
10988 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
10989 receive in the ConfigureNotify event; if we get what we asked
10990 for, then the event won't cause the screen to become garbaged, so
10991 we have to make sure to do it here. */
10992 SET_FRAME_GARBAGED (f
);
10994 XFlush (FRAME_X_DISPLAY (f
));
10998 /* Call this to change the size of frame F's x-window.
10999 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11000 for this size change and subsequent size changes.
11001 Otherwise we leave the window gravity unchanged. */
11004 x_set_window_size (f
, change_gravity
, cols
, rows
)
11006 int change_gravity
;
11012 if (FRAME_GTK_WIDGET (f
))
11013 xg_frame_set_char_size (f
, cols
, rows
);
11015 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
11016 #elif USE_X_TOOLKIT
11018 if (f
->output_data
.x
->widget
!= NULL
)
11020 /* The x and y position of the widget is clobbered by the
11021 call to XtSetValues within EmacsFrameSetCharSize.
11022 This is a real kludge, but I don't understand Xt so I can't
11023 figure out a correct fix. Can anyone else tell me? -- rms. */
11024 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11025 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11026 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11027 f
->output_data
.x
->widget
->core
.x
= xpos
;
11028 f
->output_data
.x
->widget
->core
.y
= ypos
;
11031 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
11033 #else /* not USE_X_TOOLKIT */
11035 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
11037 #endif /* not USE_X_TOOLKIT */
11039 /* If cursor was outside the new size, mark it as off. */
11040 mark_window_cursors_off (XWINDOW (f
->root_window
));
11042 /* Clear out any recollection of where the mouse highlighting was,
11043 since it might be in a place that's outside the new frame size.
11044 Actually checking whether it is outside is a pain in the neck,
11045 so don't try--just let the highlighting be done afresh with new size. */
11046 cancel_mouse_face (f
);
11051 /* Mouse warping. */
11054 x_set_mouse_position (f
, x
, y
)
11060 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11061 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11063 if (pix_x
< 0) pix_x
= 0;
11064 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11066 if (pix_y
< 0) pix_y
= 0;
11067 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11071 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11072 0, 0, 0, 0, pix_x
, pix_y
);
11076 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11079 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11085 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11086 0, 0, 0, 0, pix_x
, pix_y
);
11090 /* focus shifting, raising and lowering. */
11093 x_focus_on_frame (f
)
11096 #if 0 /* This proves to be unpleasant. */
11100 /* I don't think that the ICCCM allows programs to do things like this
11101 without the interaction of the window manager. Whatever you end up
11102 doing with this code, do it to x_unfocus_frame too. */
11103 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11104 RevertToPointerRoot
, CurrentTime
);
11109 x_unfocus_frame (f
)
11113 /* Look at the remarks in x_focus_on_frame. */
11114 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11115 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11116 RevertToPointerRoot
, CurrentTime
);
11120 /* Raise frame F. */
11126 if (f
->async_visible
)
11129 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
11130 XFlush (FRAME_X_DISPLAY (f
));
11135 /* Lower frame F. */
11141 if (f
->async_visible
)
11144 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
11145 XFlush (FRAME_X_DISPLAY (f
));
11151 XTframe_raise_lower (f
, raise_flag
)
11161 /* Change of visibility. */
11163 /* This tries to wait until the frame is really visible.
11164 However, if the window manager asks the user where to position
11165 the frame, this will return before the user finishes doing that.
11166 The frame will not actually be visible at that time,
11167 but it will become visible later when the window manager
11168 finishes with it. */
11171 x_make_frame_visible (f
)
11175 int original_top
, original_left
;
11176 int retry_count
= 2;
11182 type
= x_icon_type (f
);
11184 x_bitmap_icon (f
, type
);
11186 if (! FRAME_VISIBLE_P (f
))
11188 /* We test FRAME_GARBAGED_P here to make sure we don't
11189 call x_set_offset a second time
11190 if we get to x_make_frame_visible a second time
11191 before the window gets really visible. */
11192 if (! FRAME_ICONIFIED_P (f
)
11193 && ! f
->output_data
.x
->asked_for_visible
)
11194 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11196 f
->output_data
.x
->asked_for_visible
= 1;
11198 if (! EQ (Vx_no_window_manager
, Qt
))
11199 x_wm_set_window_state (f
, NormalState
);
11200 #ifdef USE_X_TOOLKIT
11201 /* This was XtPopup, but that did nothing for an iconified frame. */
11202 XtMapWidget (f
->output_data
.x
->widget
);
11203 #else /* not USE_X_TOOLKIT */
11205 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
11206 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
11208 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11209 #endif /* not USE_GTK */
11210 #endif /* not USE_X_TOOLKIT */
11211 #if 0 /* This seems to bring back scroll bars in the wrong places
11212 if the window configuration has changed. They seem
11213 to come back ok without this. */
11214 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11215 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11219 XFlush (FRAME_X_DISPLAY (f
));
11221 /* Synchronize to ensure Emacs knows the frame is visible
11222 before we do anything else. We do this loop with input not blocked
11223 so that incoming events are handled. */
11227 /* This must be before UNBLOCK_INPUT
11228 since events that arrive in response to the actions above
11229 will set it when they are handled. */
11230 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11232 original_left
= f
->output_data
.x
->left_pos
;
11233 original_top
= f
->output_data
.x
->top_pos
;
11235 /* This must come after we set COUNT. */
11238 /* We unblock here so that arriving X events are processed. */
11240 /* Now move the window back to where it was "supposed to be".
11241 But don't do it if the gravity is negative.
11242 When the gravity is negative, this uses a position
11243 that is 3 pixels too low. Perhaps that's really the border width.
11245 Don't do this if the window has never been visible before,
11246 because the window manager may choose the position
11247 and we don't want to override it. */
11249 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11250 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11251 && previously_visible
)
11255 unsigned int width
, height
, border
, depth
;
11259 /* On some window managers (such as FVWM) moving an existing
11260 window, even to the same place, causes the window manager
11261 to introduce an offset. This can cause the window to move
11262 to an unexpected location. Check the geometry (a little
11263 slow here) and then verify that the window is in the right
11264 place. If the window is not in the right place, move it
11265 there, and take the potential window manager hit. */
11266 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11267 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11269 if (original_left
!= x
|| original_top
!= y
)
11270 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11271 original_left
, original_top
);
11276 XSETFRAME (frame
, f
);
11278 /* Wait until the frame is visible. Process X events until a
11279 MapNotify event has been seen, or until we think we won't get a
11280 MapNotify at all.. */
11281 for (count
= input_signal_count
+ 10;
11282 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
11284 /* Force processing of queued events. */
11287 /* Machines that do polling rather than SIGIO have been
11288 observed to go into a busy-wait here. So we'll fake an
11289 alarm signal to let the handler know that there's something
11290 to be read. We used to raise a real alarm, but it seems
11291 that the handler isn't always enabled here. This is
11293 if (input_polling_used ())
11295 /* It could be confusing if a real alarm arrives while
11296 processing the fake one. Turn it off and let the
11297 handler reset it. */
11298 extern void poll_for_input_1
P_ ((void));
11299 int old_poll_suppress_count
= poll_suppress_count
;
11300 poll_suppress_count
= 1;
11301 poll_for_input_1 ();
11302 poll_suppress_count
= old_poll_suppress_count
;
11305 /* See if a MapNotify event has been processed. */
11306 FRAME_SAMPLE_VISIBILITY (f
);
11311 (let ((f (selected-frame)))
11315 the frame is not raised with various window managers on
11316 FreeBSD, Linux and Solaris. It turns out that, for some
11317 unknown reason, the call to XtMapWidget is completely ignored.
11318 Mapping the widget a second time works. */
11320 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
11325 /* Change from mapped state to withdrawn state. */
11327 /* Make the frame visible (mapped and not iconified). */
11330 x_make_frame_invisible (f
)
11335 /* Use the frame's outermost window, not the one we normally draw on. */
11336 window
= FRAME_OUTER_WINDOW (f
);
11338 /* Don't keep the highlight on an invisible frame. */
11339 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11340 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11342 #if 0/* This might add unreliability; I don't trust it -- rms. */
11343 if (! f
->async_visible
&& ! f
->async_iconified
)
11349 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11350 that the current position of the window is user-specified, rather than
11351 program-specified, so that when the window is mapped again, it will be
11352 placed at the same location, without forcing the user to position it
11353 by hand again (they have already done that once for this window.) */
11354 x_wm_set_size_hint (f
, (long) 0, 1);
11357 if (FRAME_GTK_OUTER_WIDGET (f
))
11359 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
11366 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11367 DefaultScreen (FRAME_X_DISPLAY (f
))))
11369 UNBLOCK_INPUT_RESIGNAL
;
11370 error ("Can't notify window manager of window withdrawal");
11372 #else /* ! defined (HAVE_X11R4) */
11374 /* Tell the window manager what we're going to do. */
11375 if (! EQ (Vx_no_window_manager
, Qt
))
11379 unmap
.xunmap
.type
= UnmapNotify
;
11380 unmap
.xunmap
.window
= window
;
11381 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
11382 unmap
.xunmap
.from_configure
= False
;
11383 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11384 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11386 SubstructureRedirectMaskSubstructureNotifyMask
,
11389 UNBLOCK_INPUT_RESIGNAL
;
11390 error ("Can't notify window manager of withdrawal");
11394 /* Unmap the window ourselves. Cheeky! */
11395 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
11396 #endif /* ! defined (HAVE_X11R4) */
11399 /* We can't distinguish this from iconification
11400 just by the event that we get from the server.
11401 So we can't win using the usual strategy of letting
11402 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11403 and synchronize with the server to make sure we agree. */
11405 FRAME_ICONIFIED_P (f
) = 0;
11406 f
->async_visible
= 0;
11407 f
->async_iconified
= 0;
11414 /* Change window state from mapped to iconified. */
11417 x_iconify_frame (f
)
11423 /* Don't keep the highlight on an invisible frame. */
11424 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11425 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11427 if (f
->async_iconified
)
11432 FRAME_SAMPLE_VISIBILITY (f
);
11434 type
= x_icon_type (f
);
11436 x_bitmap_icon (f
, type
);
11439 if (FRAME_GTK_OUTER_WIDGET (f
))
11441 if (! FRAME_VISIBLE_P (f
))
11442 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
11444 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
11447 f
->async_iconified
= 1;
11448 f
->async_visible
= 0;
11454 #ifdef USE_X_TOOLKIT
11456 if (! FRAME_VISIBLE_P (f
))
11458 if (! EQ (Vx_no_window_manager
, Qt
))
11459 x_wm_set_window_state (f
, IconicState
);
11460 /* This was XtPopup, but that did nothing for an iconified frame. */
11461 XtMapWidget (f
->output_data
.x
->widget
);
11462 /* The server won't give us any event to indicate
11463 that an invisible frame was changed to an icon,
11464 so we have to record it here. */
11467 f
->async_iconified
= 1;
11468 f
->async_visible
= 0;
11473 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11474 XtWindow (f
->output_data
.x
->widget
),
11475 DefaultScreen (FRAME_X_DISPLAY (f
)));
11479 error ("Can't notify window manager of iconification");
11481 f
->async_iconified
= 1;
11482 f
->async_visible
= 0;
11486 XFlush (FRAME_X_DISPLAY (f
));
11488 #else /* not USE_X_TOOLKIT */
11490 /* Make sure the X server knows where the window should be positioned,
11491 in case the user deiconifies with the window manager. */
11492 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
11493 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11495 /* Since we don't know which revision of X we're running, we'll use both
11496 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11498 /* X11R4: send a ClientMessage to the window manager using the
11499 WM_CHANGE_STATE type. */
11503 message
.xclient
.window
= FRAME_X_WINDOW (f
);
11504 message
.xclient
.type
= ClientMessage
;
11505 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11506 message
.xclient
.format
= 32;
11507 message
.xclient
.data
.l
[0] = IconicState
;
11509 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11510 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11512 SubstructureRedirectMask
| SubstructureNotifyMask
,
11515 UNBLOCK_INPUT_RESIGNAL
;
11516 error ("Can't notify window manager of iconification");
11520 /* X11R3: set the initial_state field of the window manager hints to
11522 x_wm_set_window_state (f
, IconicState
);
11524 if (!FRAME_VISIBLE_P (f
))
11526 /* If the frame was withdrawn, before, we must map it. */
11527 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11530 f
->async_iconified
= 1;
11531 f
->async_visible
= 0;
11533 XFlush (FRAME_X_DISPLAY (f
));
11535 #endif /* not USE_X_TOOLKIT */
11539 /* Free X resources of frame F. */
11542 x_free_frame_resources (f
)
11545 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11547 struct scroll_bar
*b
;
11551 /* If a display connection is dead, don't try sending more
11552 commands to the X server. */
11553 if (dpyinfo
->display
)
11555 if (f
->output_data
.x
->icon_desc
)
11556 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
11558 #ifdef USE_X_TOOLKIT
11559 /* Explicitly destroy the scroll bars of the frame. Without
11560 this, we get "BadDrawable" errors from the toolkit later on,
11561 presumably from expose events generated for the disappearing
11562 toolkit scroll bars. */
11563 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
11565 b
= XSCROLL_BAR (bar
);
11566 x_scroll_bar_remove (b
);
11572 free_frame_xic (f
);
11575 #ifdef USE_X_TOOLKIT
11576 if (f
->output_data
.x
->widget
)
11578 XtDestroyWidget (f
->output_data
.x
->widget
);
11579 f
->output_data
.x
->widget
= NULL
;
11581 /* Tooltips don't have widgets, only a simple X window, even if
11582 we are using a toolkit. */
11583 else if (FRAME_X_WINDOW (f
))
11584 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11586 free_frame_menubar (f
);
11587 #else /* !USE_X_TOOLKIT */
11590 /* In the GTK version, tooltips are normal X
11591 frames. We must check and free both types. */
11592 if (FRAME_GTK_OUTER_WIDGET (f
))
11594 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
11595 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
11596 FRAME_GTK_OUTER_WIDGET (f
) = 0;
11598 #endif /* USE_GTK */
11600 if (FRAME_X_WINDOW (f
))
11601 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11602 #endif /* !USE_X_TOOLKIT */
11604 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
11605 unload_color (f
, f
->output_data
.x
->background_pixel
);
11606 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
11607 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
11608 unload_color (f
, f
->output_data
.x
->border_pixel
);
11609 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
11611 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
11612 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
11613 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
11614 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
11615 #ifdef USE_TOOLKIT_SCROLL_BARS
11616 /* Scrollbar shadow colors. */
11617 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
11618 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
11619 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
11620 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
11621 #endif /* USE_TOOLKIT_SCROLL_BARS */
11622 if (f
->output_data
.x
->white_relief
.allocated_p
)
11623 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
11624 if (f
->output_data
.x
->black_relief
.allocated_p
)
11625 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
11627 if (FRAME_FACE_CACHE (f
))
11628 free_frame_faces (f
);
11631 XFlush (FRAME_X_DISPLAY (f
));
11634 if (f
->output_data
.x
->saved_menu_event
)
11635 xfree (f
->output_data
.x
->saved_menu_event
);
11637 xfree (f
->output_data
.x
);
11638 f
->output_data
.x
= NULL
;
11640 if (f
== dpyinfo
->x_focus_frame
)
11641 dpyinfo
->x_focus_frame
= 0;
11642 if (f
== dpyinfo
->x_focus_event_frame
)
11643 dpyinfo
->x_focus_event_frame
= 0;
11644 if (f
== dpyinfo
->x_highlight_frame
)
11645 dpyinfo
->x_highlight_frame
= 0;
11647 if (f
== dpyinfo
->mouse_face_mouse_frame
)
11649 dpyinfo
->mouse_face_beg_row
11650 = dpyinfo
->mouse_face_beg_col
= -1;
11651 dpyinfo
->mouse_face_end_row
11652 = dpyinfo
->mouse_face_end_col
= -1;
11653 dpyinfo
->mouse_face_window
= Qnil
;
11654 dpyinfo
->mouse_face_deferred_gc
= 0;
11655 dpyinfo
->mouse_face_mouse_frame
= 0;
11662 /* Destroy the X window of frame F. */
11665 x_destroy_window (f
)
11668 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11670 /* If a display connection is dead, don't try sending more
11671 commands to the X server. */
11672 if (dpyinfo
->display
!= 0)
11673 x_free_frame_resources (f
);
11675 dpyinfo
->reference_count
--;
11679 /* Setting window manager hints. */
11681 /* Set the normal size hints for the window manager, for frame F.
11682 FLAGS is the flags word to use--or 0 meaning preserve the flags
11683 that the window now has.
11684 If USER_POSITION is nonzero, we set the USPosition
11685 flag (this is useful when FLAGS is 0).
11686 The GTK version is in gtkutils.c */
11690 x_wm_set_size_hint (f
, flags
, user_position
)
11695 XSizeHints size_hints
;
11697 #ifdef USE_X_TOOLKIT
11700 Dimension widget_width
, widget_height
;
11703 Window window
= FRAME_OUTER_WINDOW (f
);
11705 /* Setting PMaxSize caused various problems. */
11706 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
11708 size_hints
.x
= f
->output_data
.x
->left_pos
;
11709 size_hints
.y
= f
->output_data
.x
->top_pos
;
11711 #ifdef USE_X_TOOLKIT
11712 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
11713 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
11714 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
11715 size_hints
.height
= widget_height
;
11716 size_hints
.width
= widget_width
;
11717 #else /* not USE_X_TOOLKIT */
11718 size_hints
.height
= PIXEL_HEIGHT (f
);
11719 size_hints
.width
= PIXEL_WIDTH (f
);
11720 #endif /* not USE_X_TOOLKIT */
11722 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
11723 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
11724 size_hints
.max_width
11725 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
11726 size_hints
.max_height
11727 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
11729 /* Calculate the base and minimum sizes.
11731 (When we use the X toolkit, we don't do it here.
11732 Instead we copy the values that the widgets are using, below.) */
11733 #ifndef USE_X_TOOLKIT
11735 int base_width
, base_height
;
11736 int min_rows
= 0, min_cols
= 0;
11738 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
11739 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
11741 check_frame_size (f
, &min_rows
, &min_cols
);
11743 /* The window manager uses the base width hints to calculate the
11744 current number of rows and columns in the frame while
11745 resizing; min_width and min_height aren't useful for this
11746 purpose, since they might not give the dimensions for a
11747 zero-row, zero-column frame.
11749 We use the base_width and base_height members if we have
11750 them; otherwise, we set the min_width and min_height members
11751 to the size for a zero x zero frame. */
11754 size_hints
.flags
|= PBaseSize
;
11755 size_hints
.base_width
= base_width
;
11756 size_hints
.base_height
= base_height
;
11757 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
11758 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
11760 size_hints
.min_width
= base_width
;
11761 size_hints
.min_height
= base_height
;
11765 /* If we don't need the old flags, we don't need the old hint at all. */
11768 size_hints
.flags
|= flags
;
11771 #endif /* not USE_X_TOOLKIT */
11774 XSizeHints hints
; /* Sometimes I hate X Windows... */
11775 long supplied_return
;
11779 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
11782 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
11785 #ifdef USE_X_TOOLKIT
11786 size_hints
.base_height
= hints
.base_height
;
11787 size_hints
.base_width
= hints
.base_width
;
11788 size_hints
.min_height
= hints
.min_height
;
11789 size_hints
.min_width
= hints
.min_width
;
11793 size_hints
.flags
|= flags
;
11798 if (hints
.flags
& PSize
)
11799 size_hints
.flags
|= PSize
;
11800 if (hints
.flags
& PPosition
)
11801 size_hints
.flags
|= PPosition
;
11802 if (hints
.flags
& USPosition
)
11803 size_hints
.flags
|= USPosition
;
11804 if (hints
.flags
& USSize
)
11805 size_hints
.flags
|= USSize
;
11809 #ifndef USE_X_TOOLKIT
11814 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
11815 size_hints
.flags
|= PWinGravity
;
11819 size_hints
.flags
&= ~ PPosition
;
11820 size_hints
.flags
|= USPosition
;
11822 #endif /* PWinGravity */
11825 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11827 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11830 #endif /* not USE_GTK */
11832 /* Used for IconicState or NormalState */
11835 x_wm_set_window_state (f
, state
)
11839 #ifdef USE_X_TOOLKIT
11842 XtSetArg (al
[0], XtNinitialState
, state
);
11843 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11844 #else /* not USE_X_TOOLKIT */
11845 Window window
= FRAME_X_WINDOW (f
);
11847 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
11848 f
->output_data
.x
->wm_hints
.initial_state
= state
;
11850 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11851 #endif /* not USE_X_TOOLKIT */
11855 x_wm_set_icon_pixmap (f
, pixmap_id
)
11859 Pixmap icon_pixmap
;
11861 #ifndef USE_X_TOOLKIT
11862 Window window
= FRAME_OUTER_WINDOW (f
);
11867 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
11868 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
11872 /* It seems there is no way to turn off use of an icon pixmap.
11873 The following line does it, only if no icon has yet been created,
11874 for some window managers. But with mwm it crashes.
11875 Some people say it should clear the IconPixmapHint bit in this case,
11876 but that doesn't work, and the X consortium said it isn't the
11877 right thing at all. Since there is no way to win,
11878 best to explicitly give up. */
11880 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
11886 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
11890 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
11891 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11894 #else /* not USE_X_TOOLKIT */
11896 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
11897 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11899 #endif /* not USE_X_TOOLKIT */
11903 x_wm_set_icon_position (f
, icon_x
, icon_y
)
11905 int icon_x
, icon_y
;
11907 Window window
= FRAME_OUTER_WINDOW (f
);
11909 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
11910 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
11911 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
11913 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11917 /***********************************************************************
11919 ***********************************************************************/
11921 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
11924 x_get_font_info (f
, font_idx
)
11928 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
11932 /* Return a list of names of available fonts matching PATTERN on frame F.
11934 If SIZE is > 0, it is the size (maximum bounds width) of fonts
11937 SIZE < 0 means include scalable fonts.
11939 Frame F null means we have not yet created any frame on X, and
11940 consult the first display in x_display_list. MAXNAMES sets a limit
11941 on how many fonts to match. */
11944 x_list_fonts (f
, pattern
, size
, maxnames
)
11946 Lisp_Object pattern
;
11950 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
11951 Lisp_Object tem
, second_best
;
11952 struct x_display_info
*dpyinfo
11953 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
11954 Display
*dpy
= dpyinfo
->display
;
11955 int try_XLoadQueryFont
= 0;
11957 int allow_scalable_fonts_p
= 0;
11961 allow_scalable_fonts_p
= 1;
11965 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
11966 if (NILP (patterns
))
11967 patterns
= Fcons (pattern
, Qnil
);
11969 if (maxnames
== 1 && !size
)
11970 /* We can return any single font matching PATTERN. */
11971 try_XLoadQueryFont
= 1;
11973 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
11976 char **names
= NULL
;
11978 pattern
= XCAR (patterns
);
11979 /* See if we cached the result for this particular query.
11980 The cache is an alist of the form:
11981 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
11982 tem
= XCDR (dpyinfo
->name_list_element
);
11983 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
11984 allow_scalable_fonts_p
? Qt
: Qnil
);
11985 list
= Fassoc (key
, tem
);
11988 list
= Fcdr_safe (list
);
11989 /* We have a cashed list. Don't have to get the list again. */
11993 /* At first, put PATTERN in the cache. */
11996 count
= x_catch_errors (dpy
);
11998 if (try_XLoadQueryFont
)
12001 unsigned long value
;
12003 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
12004 if (x_had_errors_p (dpy
))
12006 /* This error is perhaps due to insufficient memory on X
12007 server. Let's just ignore it. */
12009 x_clear_errors (dpy
);
12013 && XGetFontProperty (font
, XA_FONT
, &value
))
12015 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12016 int len
= strlen (name
);
12019 /* If DXPC (a Differential X Protocol Compressor)
12020 Ver.3.7 is running, XGetAtomName will return null
12021 string. We must avoid such a name. */
12023 try_XLoadQueryFont
= 0;
12027 names
= (char **) alloca (sizeof (char *));
12028 /* Some systems only allow alloca assigned to a
12030 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12031 bcopy (name
, names
[0], len
+ 1);
12036 try_XLoadQueryFont
= 0;
12039 XFreeFont (dpy
, font
);
12042 if (!try_XLoadQueryFont
)
12044 /* We try at least 10 fonts because XListFonts will return
12045 auto-scaled fonts at the head. */
12050 for (limit
= 500;;)
12052 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
12053 if (num_fonts
== limit
)
12056 XFreeFontNames (names
);
12065 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
12068 if (x_had_errors_p (dpy
))
12070 /* This error is perhaps due to insufficient memory on X
12071 server. Let's just ignore it. */
12073 x_clear_errors (dpy
);
12077 x_uncatch_errors (dpy
, count
);
12084 /* Make a list of all the fonts we got back.
12085 Store that in the font cache for the display. */
12086 for (i
= 0; i
< num_fonts
; i
++)
12089 char *p
= names
[i
];
12090 int average_width
= -1, dashes
= 0;
12092 /* Count the number of dashes in NAMES[I]. If there are
12093 14 dashes, and the field value following 12th dash
12094 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12095 is usually too ugly to be used for editing. Let's
12101 if (dashes
== 7) /* PIXEL_SIZE field */
12103 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12104 average_width
= atoi (p
);
12107 if (allow_scalable_fonts_p
12108 || dashes
< 14 || average_width
!= 0)
12110 tem
= build_string (names
[i
]);
12111 if (NILP (Fassoc (tem
, list
)))
12113 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12114 && ((fast_c_string_match_ignore_case
12115 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12117 /* We can set the value of PIXEL_SIZE to the
12118 width of this font. */
12119 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12121 /* For the moment, width is not known. */
12122 list
= Fcons (Fcons (tem
, Qnil
), list
);
12127 if (!try_XLoadQueryFont
)
12130 XFreeFontNames (names
);
12135 /* Now store the result in the cache. */
12136 XSETCDR (dpyinfo
->name_list_element
,
12137 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
12140 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12142 newlist
= second_best
= Qnil
;
12143 /* Make a list of the fonts that have the right width. */
12144 for (; CONSP (list
); list
= XCDR (list
))
12150 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12154 newlist
= Fcons (XCAR (tem
), newlist
);
12158 if (!INTEGERP (XCDR (tem
)))
12160 /* Since we have not yet known the size of this font, we
12161 must try slow function call XLoadQueryFont. */
12162 XFontStruct
*thisinfo
;
12165 count
= x_catch_errors (dpy
);
12166 thisinfo
= XLoadQueryFont (dpy
,
12167 SDATA (XCAR (tem
)));
12168 if (x_had_errors_p (dpy
))
12170 /* This error is perhaps due to insufficient memory on X
12171 server. Let's just ignore it. */
12173 x_clear_errors (dpy
);
12175 x_uncatch_errors (dpy
, count
);
12181 (thisinfo
->min_bounds
.width
== 0
12183 : make_number (thisinfo
->max_bounds
.width
)));
12185 XFreeFont (dpy
, thisinfo
);
12189 /* For unknown reason, the previous call of XListFont had
12190 returned a font which can't be opened. Record the size
12191 as 0 not to try to open it again. */
12192 XSETCDR (tem
, make_number (0));
12195 found_size
= XINT (XCDR (tem
));
12196 if (found_size
== size
)
12197 newlist
= Fcons (XCAR (tem
), newlist
);
12198 else if (found_size
> 0)
12200 if (NILP (second_best
))
12202 else if (found_size
< size
)
12204 if (XINT (XCDR (second_best
)) > size
12205 || XINT (XCDR (second_best
)) < found_size
)
12210 if (XINT (XCDR (second_best
)) > size
12211 && XINT (XCDR (second_best
)) > found_size
)
12216 if (!NILP (newlist
))
12218 else if (!NILP (second_best
))
12220 newlist
= Fcons (XCAR (second_best
), Qnil
);
12231 /* Check that FONT is valid on frame F. It is if it can be found in F's
12235 x_check_font (f
, font
)
12240 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12242 xassert (font
!= NULL
);
12244 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12245 if (dpyinfo
->font_table
[i
].name
12246 && font
== dpyinfo
->font_table
[i
].font
)
12249 xassert (i
< dpyinfo
->n_fonts
);
12252 #endif /* GLYPH_DEBUG != 0 */
12254 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12255 Note: There are (broken) X fonts out there with invalid XFontStruct
12256 min_bounds contents. For example, handa@etl.go.jp reports that
12257 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
12258 have font->min_bounds.width == 0. */
12261 x_font_min_bounds (font
, w
, h
)
12265 *h
= FONT_HEIGHT (font
);
12266 *w
= font
->min_bounds
.width
;
12268 /* Try to handle the case where FONT->min_bounds has invalid
12269 contents. Since the only font known to have invalid min_bounds
12270 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12272 *w
= font
->max_bounds
.width
;
12276 /* Compute the smallest character width and smallest font height over
12277 all fonts available on frame F. Set the members smallest_char_width
12278 and smallest_font_height in F's x_display_info structure to
12279 the values computed. Value is non-zero if smallest_font_height or
12280 smallest_char_width become smaller than they were before. */
12283 x_compute_min_glyph_bounds (f
)
12287 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12289 int old_width
= dpyinfo
->smallest_char_width
;
12290 int old_height
= dpyinfo
->smallest_font_height
;
12292 dpyinfo
->smallest_font_height
= 100000;
12293 dpyinfo
->smallest_char_width
= 100000;
12295 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12296 if (dpyinfo
->font_table
[i
].name
)
12298 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12301 font
= (XFontStruct
*) fontp
->font
;
12302 xassert (font
!= (XFontStruct
*) ~0);
12303 x_font_min_bounds (font
, &w
, &h
);
12305 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12306 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12309 xassert (dpyinfo
->smallest_char_width
> 0
12310 && dpyinfo
->smallest_font_height
> 0);
12312 return (dpyinfo
->n_fonts
== 1
12313 || dpyinfo
->smallest_char_width
< old_width
12314 || dpyinfo
->smallest_font_height
< old_height
);
12318 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12319 pointer to the structure font_info while allocating it dynamically.
12320 If SIZE is 0, load any size of font.
12321 If loading is failed, return NULL. */
12324 x_load_font (f
, fontname
, size
)
12326 register char *fontname
;
12329 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12330 Lisp_Object font_names
;
12333 /* Get a list of all the fonts that match this name. Once we
12334 have a list of matching fonts, we compare them against the fonts
12335 we already have by comparing names. */
12336 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12338 if (!NILP (font_names
))
12343 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12344 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12345 if (dpyinfo
->font_table
[i
].name
12346 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12347 SDATA (XCAR (tail
)))
12348 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12349 SDATA (XCAR (tail
)))))
12350 return (dpyinfo
->font_table
+ i
);
12353 /* Load the font and add it to the table. */
12357 struct font_info
*fontp
;
12358 unsigned long value
;
12361 /* If we have found fonts by x_list_font, load one of them. If
12362 not, we still try to load a font by the name given as FONTNAME
12363 because XListFonts (called in x_list_font) of some X server has
12364 a bug of not finding a font even if the font surely exists and
12365 is loadable by XLoadQueryFont. */
12366 if (size
> 0 && !NILP (font_names
))
12367 fontname
= (char *) SDATA (XCAR (font_names
));
12370 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12371 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12372 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12374 /* This error is perhaps due to insufficient memory on X
12375 server. Let's just ignore it. */
12377 x_clear_errors (FRAME_X_DISPLAY (f
));
12379 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12384 /* Find a free slot in the font table. */
12385 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12386 if (dpyinfo
->font_table
[i
].name
== NULL
)
12389 /* If no free slot found, maybe enlarge the font table. */
12390 if (i
== dpyinfo
->n_fonts
12391 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12394 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12395 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12396 dpyinfo
->font_table
12397 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12400 fontp
= dpyinfo
->font_table
+ i
;
12401 if (i
== dpyinfo
->n_fonts
)
12402 ++dpyinfo
->n_fonts
;
12404 /* Now fill in the slots of *FONTP. */
12406 fontp
->font
= font
;
12407 fontp
->font_idx
= i
;
12408 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12409 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12411 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12413 if (XGetFontProperty (font
, XA_FONT
, &value
))
12415 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12419 /* Count the number of dashes in the "full name".
12420 If it is too few, this isn't really the font's full name,
12422 In X11R4, the fonts did not come with their canonical names
12433 full_name
= (char *) xmalloc (p
- name
+ 1);
12434 bcopy (name
, full_name
, p
- name
+ 1);
12440 if (full_name
!= 0)
12441 fontp
->full_name
= full_name
;
12443 fontp
->full_name
= fontp
->name
;
12445 fontp
->size
= font
->max_bounds
.width
;
12446 fontp
->height
= FONT_HEIGHT (font
);
12448 if (NILP (font_names
))
12450 /* We come here because of a bug of XListFonts mentioned at
12451 the head of this block. Let's store this information in
12452 the cache for x_list_fonts. */
12453 Lisp_Object lispy_name
= build_string (fontname
);
12454 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
12455 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
12458 XSETCDR (dpyinfo
->name_list_element
,
12460 Fcons (Fcons (lispy_full_name
,
12461 make_number (fontp
->size
)),
12463 XCDR (dpyinfo
->name_list_element
)));
12466 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
12468 XSETCDR (dpyinfo
->name_list_element
,
12470 Fcons (Fcons (lispy_full_name
,
12471 make_number (fontp
->size
)),
12473 XCDR (dpyinfo
->name_list_element
)));
12477 /* The slot `encoding' specifies how to map a character
12478 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
12479 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
12480 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
12481 2:0xA020..0xFF7F). For the moment, we don't know which charset
12482 uses this font. So, we set information in fontp->encoding[1]
12483 which is never used by any charset. If mapping can't be
12484 decided, set FONT_ENCODING_NOT_DECIDED. */
12486 = (font
->max_byte1
== 0
12488 ? (font
->min_char_or_byte2
< 0x80
12489 ? (font
->max_char_or_byte2
< 0x80
12490 ? 0 /* 0x20..0x7F */
12491 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
12492 : 1) /* 0xA0..0xFF */
12494 : (font
->min_byte1
< 0x80
12495 ? (font
->max_byte1
< 0x80
12496 ? (font
->min_char_or_byte2
< 0x80
12497 ? (font
->max_char_or_byte2
< 0x80
12498 ? 0 /* 0x2020..0x7F7F */
12499 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
12500 : 3) /* 0x20A0..0x7FFF */
12501 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
12502 : (font
->min_char_or_byte2
< 0x80
12503 ? (font
->max_char_or_byte2
< 0x80
12504 ? 2 /* 0xA020..0xFF7F */
12505 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
12506 : 1))); /* 0xA0A0..0xFFFF */
12508 fontp
->baseline_offset
12509 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
12510 ? (long) value
: 0);
12511 fontp
->relative_compose
12512 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
12513 ? (long) value
: 0);
12514 fontp
->default_ascent
12515 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
12516 ? (long) value
: 0);
12518 /* Set global flag fonts_changed_p to non-zero if the font loaded
12519 has a character with a smaller width than any other character
12520 before, or if the font loaded has a smaller height than any
12521 other font loaded before. If this happens, it will make a
12522 glyph matrix reallocation necessary. */
12523 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
12530 /* Return a pointer to struct font_info of a font named FONTNAME for
12531 frame F. If no such font is loaded, return NULL. */
12534 x_query_font (f
, fontname
)
12536 register char *fontname
;
12538 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12541 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12542 if (dpyinfo
->font_table
[i
].name
12543 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
12544 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
12545 return (dpyinfo
->font_table
+ i
);
12550 /* Find a CCL program for a font specified by FONTP, and set the member
12551 `encoder' of the structure. */
12554 x_find_ccl_program (fontp
)
12555 struct font_info
*fontp
;
12557 Lisp_Object list
, elt
;
12560 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
12564 && STRINGP (XCAR (elt
))
12565 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
12567 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
12574 struct ccl_program
*ccl
12575 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
12577 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
12580 fontp
->font_encoder
= ccl
;
12586 /***********************************************************************
12588 ***********************************************************************/
12590 #ifdef USE_X_TOOLKIT
12591 static XrmOptionDescRec emacs_options
[] = {
12592 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
12593 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
12595 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
12596 XrmoptionSepArg
, NULL
},
12597 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
12599 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12600 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12601 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
12602 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12603 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
12604 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
12605 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
12607 #endif /* USE_X_TOOLKIT */
12609 static int x_initialized
;
12611 #ifdef MULTI_KBOARD
12612 /* Test whether two display-name strings agree up to the dot that separates
12613 the screen number from the server number. */
12615 same_x_server (name1
, name2
)
12616 const char *name1
, *name2
;
12618 int seen_colon
= 0;
12619 const unsigned char *system_name
= SDATA (Vsystem_name
);
12620 int system_name_length
= strlen (system_name
);
12621 int length_until_period
= 0;
12623 while (system_name
[length_until_period
] != 0
12624 && system_name
[length_until_period
] != '.')
12625 length_until_period
++;
12627 /* Treat `unix' like an empty host name. */
12628 if (! strncmp (name1
, "unix:", 5))
12630 if (! strncmp (name2
, "unix:", 5))
12632 /* Treat this host's name like an empty host name. */
12633 if (! strncmp (name1
, system_name
, system_name_length
)
12634 && name1
[system_name_length
] == ':')
12635 name1
+= system_name_length
;
12636 if (! strncmp (name2
, system_name
, system_name_length
)
12637 && name2
[system_name_length
] == ':')
12638 name2
+= system_name_length
;
12639 /* Treat this host's domainless name like an empty host name. */
12640 if (! strncmp (name1
, system_name
, length_until_period
)
12641 && name1
[length_until_period
] == ':')
12642 name1
+= length_until_period
;
12643 if (! strncmp (name2
, system_name
, length_until_period
)
12644 && name2
[length_until_period
] == ':')
12645 name2
+= length_until_period
;
12647 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
12651 if (seen_colon
&& *name1
== '.')
12655 && (*name1
== '.' || *name1
== '\0')
12656 && (*name2
== '.' || *name2
== '\0'));
12660 struct x_display_info
*
12661 x_term_init (display_name
, xrm_option
, resource_name
)
12662 Lisp_Object display_name
;
12664 char *resource_name
;
12668 struct x_display_info
*dpyinfo
;
12673 if (!x_initialized
)
12681 #define NUM_ARGV 10
12683 char *argv
[NUM_ARGV
];
12684 char **argv2
= argv
;
12687 /* GTK 2.0 can only handle one display, GTK 2.2 can handle more
12688 than one, but this remains to be implemented. */
12689 if (x_initialized
> 1)
12694 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
12698 argv
[argc
++] = initial_argv
[0];
12700 if (! NILP (display_name
))
12702 argv
[argc
++] = "--display";
12703 argv
[argc
++] = SDATA (display_name
);
12706 argv
[argc
++] = "--name";
12707 argv
[argc
++] = resource_name
;
12710 XSetLocaleModifiers ("");
12713 gtk_init (&argc
, &argv2
);
12715 /* gtk_init does set_locale. We must fix locale after calling it. */
12719 dpy
= GDK_DISPLAY ();
12721 /* NULL window -> events for all windows go to our function */
12722 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
12724 /* Load our own gtkrc if it exists. */
12726 struct gcpro gcpro1
, gcpro2
;
12727 char *file
= "~/.emacs.d/gtkrc";
12728 Lisp_Object s
, abs_file
;
12730 GCPRO2 (s
, abs_file
);
12731 s
= make_string (file
, strlen (file
));
12732 abs_file
= Fexpand_file_name(s
, Qnil
);
12734 if (! NILP (abs_file
) && Ffile_readable_p (abs_file
))
12735 gtk_rc_parse (SDATA (abs_file
));
12740 XSetErrorHandler (x_error_handler
);
12741 XSetIOErrorHandler (x_io_error_quitter
);
12743 #else /* not USE_GTK */
12744 #ifdef USE_X_TOOLKIT
12745 /* weiner@footloose.sps.mot.com reports that this causes
12747 X protocol error: BadAtom (invalid Atom parameter)
12748 on protocol request 18skiloaf.
12749 So let's not use it until R6. */
12750 #ifdef HAVE_X11XTR6
12751 XtSetLanguageProc (NULL
, NULL
, NULL
);
12762 argv
[argc
++] = "-xrm";
12763 argv
[argc
++] = xrm_option
;
12765 turn_on_atimers (0);
12766 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
12767 resource_name
, EMACS_CLASS
,
12768 emacs_options
, XtNumber (emacs_options
),
12770 turn_on_atimers (1);
12772 #ifdef HAVE_X11XTR6
12773 /* I think this is to compensate for XtSetLanguageProc. */
12778 #else /* not USE_X_TOOLKIT */
12780 XSetLocaleModifiers ("");
12782 dpy
= XOpenDisplay (SDATA (display_name
));
12783 #endif /* not USE_X_TOOLKIT */
12784 #endif /* not USE_GTK*/
12786 /* Detect failure. */
12793 /* We have definitely succeeded. Record the new connection. */
12795 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
12796 bzero (dpyinfo
, sizeof *dpyinfo
);
12798 #ifdef MULTI_KBOARD
12800 struct x_display_info
*share
;
12803 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
12804 share
= share
->next
, tail
= XCDR (tail
))
12805 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
12806 SDATA (display_name
)))
12809 dpyinfo
->kboard
= share
->kboard
;
12812 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
12813 init_kboard (dpyinfo
->kboard
);
12814 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
12816 char *vendor
= ServerVendor (dpy
);
12818 dpyinfo
->kboard
->Vsystem_key_alist
12819 = call1 (Qvendor_specific_keysyms
,
12820 build_string (vendor
? vendor
: ""));
12824 dpyinfo
->kboard
->next_kboard
= all_kboards
;
12825 all_kboards
= dpyinfo
->kboard
;
12826 /* Don't let the initial kboard remain current longer than necessary.
12827 That would cause problems if a file loaded on startup tries to
12828 prompt in the mini-buffer. */
12829 if (current_kboard
== initial_kboard
)
12830 current_kboard
= dpyinfo
->kboard
;
12832 dpyinfo
->kboard
->reference_count
++;
12836 /* Put this display on the chain. */
12837 dpyinfo
->next
= x_display_list
;
12838 x_display_list
= dpyinfo
;
12840 /* Put it on x_display_name_list as well, to keep them parallel. */
12841 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
12842 x_display_name_list
);
12843 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
12845 dpyinfo
->display
= dpy
;
12848 XSetAfterFunction (x_current_display
, x_trace_wire
);
12852 = (char *) xmalloc (SBYTES (Vinvocation_name
)
12853 + SBYTES (Vsystem_name
)
12855 sprintf (dpyinfo
->x_id_name
, "%s@%s",
12856 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
12858 /* Figure out which modifier bits mean what. */
12859 x_find_modifier_meanings (dpyinfo
);
12861 /* Get the scroll bar cursor. */
12862 dpyinfo
->vertical_scroll_bar_cursor
12863 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
12865 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
12866 resource_name
, EMACS_CLASS
);
12867 #ifdef HAVE_XRMSETDATABASE
12868 XrmSetDatabase (dpyinfo
->display
, xrdb
);
12870 dpyinfo
->display
->db
= xrdb
;
12872 /* Put the rdb where we can find it in a way that works on
12874 dpyinfo
->xrdb
= xrdb
;
12876 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
12877 DefaultScreen (dpyinfo
->display
));
12878 select_visual (dpyinfo
);
12879 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
12880 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
12881 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
12882 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
12883 dpyinfo
->grabbed
= 0;
12884 dpyinfo
->reference_count
= 0;
12885 dpyinfo
->icon_bitmap_id
= -1;
12886 dpyinfo
->font_table
= NULL
;
12887 dpyinfo
->n_fonts
= 0;
12888 dpyinfo
->font_table_size
= 0;
12889 dpyinfo
->bitmaps
= 0;
12890 dpyinfo
->bitmaps_size
= 0;
12891 dpyinfo
->bitmaps_last
= 0;
12892 dpyinfo
->scratch_cursor_gc
= 0;
12893 dpyinfo
->mouse_face_mouse_frame
= 0;
12894 dpyinfo
->mouse_face_deferred_gc
= 0;
12895 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
12896 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
12897 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
12898 dpyinfo
->mouse_face_window
= Qnil
;
12899 dpyinfo
->mouse_face_overlay
= Qnil
;
12900 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
12901 dpyinfo
->mouse_face_defer
= 0;
12902 dpyinfo
->mouse_face_hidden
= 0;
12903 dpyinfo
->x_focus_frame
= 0;
12904 dpyinfo
->x_focus_event_frame
= 0;
12905 dpyinfo
->x_highlight_frame
= 0;
12906 dpyinfo
->image_cache
= make_image_cache ();
12908 /* See if a private colormap is requested. */
12909 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
12911 if (dpyinfo
->visual
->class == PseudoColor
)
12914 value
= display_x_get_resource (dpyinfo
,
12915 build_string ("privateColormap"),
12916 build_string ("PrivateColormap"),
12918 if (STRINGP (value
)
12919 && (!strcmp (SDATA (value
), "true")
12920 || !strcmp (SDATA (value
), "on")))
12921 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
12925 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
12926 dpyinfo
->visual
, AllocNone
);
12929 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
12930 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
12931 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
12932 dpyinfo
->resy
= pixels
* 25.4 / mm
;
12933 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
12934 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
12935 dpyinfo
->resx
= pixels
* 25.4 / mm
;
12938 dpyinfo
->Xatom_wm_protocols
12939 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
12940 dpyinfo
->Xatom_wm_take_focus
12941 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
12942 dpyinfo
->Xatom_wm_save_yourself
12943 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
12944 dpyinfo
->Xatom_wm_delete_window
12945 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
12946 dpyinfo
->Xatom_wm_change_state
12947 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
12948 dpyinfo
->Xatom_wm_configure_denied
12949 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
12950 dpyinfo
->Xatom_wm_window_moved
12951 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
12952 dpyinfo
->Xatom_editres
12953 = XInternAtom (dpyinfo
->display
, "Editres", False
);
12954 dpyinfo
->Xatom_CLIPBOARD
12955 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
12956 dpyinfo
->Xatom_TIMESTAMP
12957 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
12958 dpyinfo
->Xatom_TEXT
12959 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
12960 dpyinfo
->Xatom_COMPOUND_TEXT
12961 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
12962 dpyinfo
->Xatom_UTF8_STRING
12963 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
12964 dpyinfo
->Xatom_DELETE
12965 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
12966 dpyinfo
->Xatom_MULTIPLE
12967 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
12968 dpyinfo
->Xatom_INCR
12969 = XInternAtom (dpyinfo
->display
, "INCR", False
);
12970 dpyinfo
->Xatom_EMACS_TMP
12971 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
12972 dpyinfo
->Xatom_TARGETS
12973 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
12974 dpyinfo
->Xatom_NULL
12975 = XInternAtom (dpyinfo
->display
, "NULL", False
);
12976 dpyinfo
->Xatom_ATOM_PAIR
12977 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
12978 /* For properties of font. */
12979 dpyinfo
->Xatom_PIXEL_SIZE
12980 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
12981 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
12982 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
12983 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
12984 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
12985 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
12986 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
12988 /* Ghostscript support. */
12989 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
12990 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
12992 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
12995 dpyinfo
->cut_buffers_initialized
= 0;
12997 connection
= ConnectionNumber (dpyinfo
->display
);
12998 dpyinfo
->connection
= connection
;
13003 null_bits
[0] = 0x00;
13005 dpyinfo
->null_pixel
13006 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13007 null_bits
, 1, 1, (long) 0, (long) 0,
13012 extern int gray_bitmap_width
, gray_bitmap_height
;
13013 extern char *gray_bitmap_bits
;
13015 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13017 gray_bitmap_width
, gray_bitmap_height
,
13018 (unsigned long) 1, (unsigned long) 0, 1);
13022 xim_initialize (dpyinfo
, resource_name
);
13025 #ifdef subprocesses
13026 /* This is only needed for distinguishing keyboard and process input. */
13027 if (connection
!= 0)
13028 add_keyboard_wait_descriptor (connection
);
13031 #ifndef F_SETOWN_BUG
13033 #ifdef F_SETOWN_SOCK_NEG
13034 /* stdin is a socket here */
13035 fcntl (connection
, F_SETOWN
, -getpid ());
13036 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13037 fcntl (connection
, F_SETOWN
, getpid ());
13038 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13039 #endif /* ! defined (F_SETOWN) */
13040 #endif /* F_SETOWN_BUG */
13043 if (interrupt_input
)
13044 init_sigio (connection
);
13045 #endif /* ! defined (SIGIO) */
13048 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13049 /* Make sure that we have a valid font for dialog boxes
13050 so that Xt does not crash. */
13052 Display
*dpy
= dpyinfo
->display
;
13053 XrmValue d
, fr
, to
;
13057 d
.addr
= (XPointer
)&dpy
;
13058 d
.size
= sizeof (Display
*);
13059 fr
.addr
= XtDefaultFont
;
13060 fr
.size
= sizeof (XtDefaultFont
);
13061 to
.size
= sizeof (Font
*);
13062 to
.addr
= (XPointer
)&font
;
13063 count
= x_catch_errors (dpy
);
13064 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13066 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13067 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13068 x_uncatch_errors (dpy
, count
);
13073 /* See if we should run in synchronous mode. This is useful
13074 for debugging X code. */
13077 value
= display_x_get_resource (dpyinfo
,
13078 build_string ("synchronous"),
13079 build_string ("Synchronous"),
13081 if (STRINGP (value
)
13082 && (!strcmp (SDATA (value
), "true")
13083 || !strcmp (SDATA (value
), "on")))
13084 XSynchronize (dpyinfo
->display
, True
);
13092 /* Get rid of display DPYINFO, assuming all frames are already gone,
13093 and without sending any more commands to the X server. */
13096 x_delete_display (dpyinfo
)
13097 struct x_display_info
*dpyinfo
;
13099 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13101 /* Discard this display from x_display_name_list and x_display_list.
13102 We can't use Fdelq because that can quit. */
13103 if (! NILP (x_display_name_list
)
13104 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13105 x_display_name_list
= XCDR (x_display_name_list
);
13110 tail
= x_display_name_list
;
13111 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13113 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13115 XSETCDR (tail
, XCDR (XCDR (tail
)));
13118 tail
= XCDR (tail
);
13122 if (next_noop_dpyinfo
== dpyinfo
)
13123 next_noop_dpyinfo
= dpyinfo
->next
;
13125 if (x_display_list
== dpyinfo
)
13126 x_display_list
= dpyinfo
->next
;
13129 struct x_display_info
*tail
;
13131 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13132 if (tail
->next
== dpyinfo
)
13133 tail
->next
= tail
->next
->next
;
13136 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13137 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13138 XrmDestroyDatabase (dpyinfo
->xrdb
);
13141 #ifdef MULTI_KBOARD
13142 if (--dpyinfo
->kboard
->reference_count
== 0)
13143 delete_kboard (dpyinfo
->kboard
);
13147 xim_close_dpy (dpyinfo
);
13150 xfree (dpyinfo
->font_table
);
13151 xfree (dpyinfo
->x_id_name
);
13152 xfree (dpyinfo
->color_cells
);
13157 /* Set up use of X before we make the first connection. */
13159 static struct redisplay_interface x_redisplay_interface
=
13164 x_clear_end_of_line
,
13166 x_after_update_window_line
,
13167 x_update_window_begin
,
13168 x_update_window_end
,
13171 x_clear_mouse_face
,
13172 x_get_glyph_overhangs
,
13173 x_fix_overlapping_area
,
13174 x_draw_fringe_bitmap
,
13177 x_compute_glyph_string_overhangs
,
13178 x_draw_glyph_string
13184 rif
= &x_redisplay_interface
;
13186 clear_frame_hook
= x_clear_frame
;
13187 ins_del_lines_hook
= x_ins_del_lines
;
13188 delete_glyphs_hook
= x_delete_glyphs
;
13189 ring_bell_hook
= XTring_bell
;
13190 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13191 set_terminal_modes_hook
= XTset_terminal_modes
;
13192 update_begin_hook
= x_update_begin
;
13193 update_end_hook
= x_update_end
;
13194 set_terminal_window_hook
= XTset_terminal_window
;
13195 read_socket_hook
= XTread_socket
;
13196 frame_up_to_date_hook
= XTframe_up_to_date
;
13197 mouse_position_hook
= XTmouse_position
;
13198 frame_rehighlight_hook
= XTframe_rehighlight
;
13199 frame_raise_lower_hook
= XTframe_raise_lower
;
13200 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13201 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13202 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13203 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13204 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13206 scroll_region_ok
= 1; /* we'll scroll partial frames */
13207 char_ins_del_ok
= 1;
13208 line_ins_del_ok
= 1; /* we'll just blt 'em */
13209 fast_clear_end_of_line
= 1; /* X does this well */
13210 memory_below_frame
= 0; /* we don't remember what scrolls
13215 last_tool_bar_item
= -1;
13216 any_help_event_p
= 0;
13218 /* Try to use interrupt input; if we can't, then start polling. */
13219 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13221 #ifdef USE_X_TOOLKIT
13222 XtToolkitInitialize ();
13224 Xt_app_con
= XtCreateApplicationContext ();
13226 /* Register a converter from strings to pixels, which uses
13227 Emacs' color allocation infrastructure. */
13228 XtAppSetTypeConverter (Xt_app_con
,
13229 XtRString
, XtRPixel
, cvt_string_to_pixel
,
13230 cvt_string_to_pixel_args
,
13231 XtNumber (cvt_string_to_pixel_args
),
13232 XtCacheByDisplay
, cvt_pixel_dtor
);
13234 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13236 /* Install an asynchronous timer that processes Xt timeout events
13237 every 0.1s. This is necessary because some widget sets use
13238 timeouts internally, for example the LessTif menu bar, or the
13239 Xaw3d scroll bar. When Xt timouts aren't processed, these
13240 widgets don't behave normally. */
13242 EMACS_TIME interval
;
13243 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13244 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13248 #ifdef USE_TOOLKIT_SCROLL_BARS
13250 xaw3d_arrow_scroll
= False
;
13251 xaw3d_pick_top
= True
;
13255 /* Note that there is no real way portable across R3/R4 to get the
13256 original error handler. */
13257 XSetErrorHandler (x_error_handler
);
13258 XSetIOErrorHandler (x_io_error_quitter
);
13260 /* Disable Window Change signals; they are handled by X events. */
13262 signal (SIGWINCH
, SIG_DFL
);
13263 #endif /* SIGWINCH */
13265 signal (SIGPIPE
, x_connection_signal
);
13268 x_session_initialize ();
13276 staticpro (&x_error_message_string
);
13277 x_error_message_string
= Qnil
;
13279 staticpro (&x_display_name_list
);
13280 x_display_name_list
= Qnil
;
13282 staticpro (&last_mouse_scroll_bar
);
13283 last_mouse_scroll_bar
= Qnil
;
13285 staticpro (&Qvendor_specific_keysyms
);
13286 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13288 staticpro (&Qutf_8
);
13289 Qutf_8
= intern ("utf-8");
13290 staticpro (&Qlatin_1
);
13291 Qlatin_1
= intern ("latin-1");
13293 staticpro (&last_mouse_press_frame
);
13294 last_mouse_press_frame
= Qnil
;
13297 staticpro (&help_echo
);
13298 help_echo_object
= Qnil
;
13299 staticpro (&help_echo_object
);
13300 help_echo_window
= Qnil
;
13301 staticpro (&help_echo_window
);
13302 previous_help_echo
= Qnil
;
13303 staticpro (&previous_help_echo
);
13304 help_echo_pos
= -1;
13306 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
13307 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
13308 mouse_autoselect_window
= 0;
13310 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13311 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
13312 For example, if a block cursor is over a tab, it will be drawn as
13313 wide as that tab on the display. */);
13314 x_stretch_cursor_p
= 0;
13316 DEFVAR_BOOL ("x-use-underline-position-properties",
13317 &x_use_underline_position_properties
,
13318 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
13319 nil means ignore them. If you encounter fonts with bogus
13320 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
13321 to 4.1, set this to nil. */);
13322 x_use_underline_position_properties
= 1;
13324 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
13325 doc
: /* What X toolkit scroll bars Emacs uses.
13326 A value of nil means Emacs doesn't use X toolkit scroll bars.
13327 Otherwise, value is a symbol describing the X toolkit. */);
13328 #ifdef USE_TOOLKIT_SCROLL_BARS
13330 Vx_toolkit_scroll_bars
= intern ("motif");
13331 #elif defined HAVE_XAW3D
13332 Vx_toolkit_scroll_bars
= intern ("xaw3d");
13334 Vx_toolkit_scroll_bars
= intern ("gtk");
13336 Vx_toolkit_scroll_bars
= intern ("xaw");
13339 Vx_toolkit_scroll_bars
= Qnil
;
13342 staticpro (&last_mouse_motion_frame
);
13343 last_mouse_motion_frame
= Qnil
;
13345 Qmodifier_value
= intern ("modifier-value");
13346 Qalt
= intern ("alt");
13347 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
13348 Qhyper
= intern ("hyper");
13349 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
13350 Qmeta
= intern ("meta");
13351 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
13352 Qsuper
= intern ("super");
13353 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
13355 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
13356 doc
: /* Which keys Emacs uses for the alt modifier.
13357 This should be one of the symbols `alt', `hyper', `meta', `super'.
13358 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
13359 is nil, which is the same as `alt'. */);
13360 Vx_alt_keysym
= Qnil
;
13362 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
13363 doc
: /* Which keys Emacs uses for the hyper modifier.
13364 This should be one of the symbols `alt', `hyper', `meta', `super'.
13365 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
13366 default is nil, which is the same as `hyper'. */);
13367 Vx_hyper_keysym
= Qnil
;
13369 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
13370 doc
: /* Which keys Emacs uses for the meta modifier.
13371 This should be one of the symbols `alt', `hyper', `meta', `super'.
13372 For example, `meta' means use the Meta_L and Meta_R keysyms. The
13373 default is nil, which is the same as `meta'. */);
13374 Vx_meta_keysym
= Qnil
;
13376 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
13377 doc
: /* Which keys Emacs uses for the super modifier.
13378 This should be one of the symbols `alt', `hyper', `meta', `super'.
13379 For example, `super' means use the Super_L and Super_R keysyms. The
13380 default is nil, which is the same as `super'. */);
13381 Vx_super_keysym
= Qnil
;
13383 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
13384 doc
: /* Hash table of character codes indexed by X keysym codes. */);
13385 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
13386 make_float (DEFAULT_REHASH_SIZE
),
13387 make_float (DEFAULT_REHASH_THRESHOLD
),
13391 #endif /* HAVE_X_WINDOWS */