1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, 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 #include <X11/Xaw3d/ThreeD.h>
134 #else /* !HAVE_XAW3D */
135 #include <X11/Xaw/Simple.h>
136 #include <X11/Xaw/Scrollbar.h>
137 #endif /* !HAVE_XAW3D */
139 #define XtNpickTop "pickTop"
140 #endif /* !XtNpickTop */
141 #endif /* !USE_MOTIF */
142 #endif /* USE_TOOLKIT_SCROLL_BARS */
144 #endif /* USE_X_TOOLKIT */
146 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
147 #define x_any_window_to_frame x_window_to_frame
148 #define x_top_window_to_frame x_window_to_frame
153 #ifndef XtNinitialState
154 #define XtNinitialState "initialState"
158 #define abs(x) ((x) < 0 ? -(x) : (x))
160 /* Default to using XIM if available. */
164 int use_xim
= 0; /* configure --without-xim */
169 /* Non-nil means Emacs uses toolkit scroll bars. */
171 Lisp_Object Vx_toolkit_scroll_bars
;
173 /* Non-zero means that a HELP_EVENT has been generated since Emacs
176 static int any_help_event_p
;
178 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
179 static Lisp_Object last_window
;
181 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
183 int x_use_underline_position_properties
;
185 /* This is a chain of structures for all the X displays currently in
188 struct x_display_info
*x_display_list
;
190 /* This is a list of cons cells, each of the form (NAME
191 . FONT-LIST-CACHE), one for each element of x_display_list and in
192 the same order. NAME is the name of the frame. FONT-LIST-CACHE
193 records previous values returned by x-list-fonts. */
195 Lisp_Object x_display_name_list
;
197 /* Frame being updated by update_frame. This is declared in term.c.
198 This is set by update_begin and looked at by all the XT functions.
199 It is zero while not inside an update. In that case, the XT
200 functions assume that `selected_frame' is the frame to apply to. */
202 extern struct frame
*updating_frame
;
204 /* This is a frame waiting to be auto-raised, within XTread_socket. */
206 struct frame
*pending_autoraise_frame
;
209 /* The application context for Xt use. */
210 XtAppContext Xt_app_con
;
211 static String Xt_default_resources
[] = {0};
212 #endif /* USE_X_TOOLKIT */
214 /* Non-zero means user is interacting with a toolkit scroll bar. */
216 static int toolkit_scroll_bar_interaction
;
218 /* Non-zero means to not move point as a result of clicking on a
219 frame to focus it (when focus-follows-mouse is nil). */
221 int x_mouse_click_focus_ignore_position
;
223 /* Non-zero timeout value means ignore next mouse click if it arrives
224 before that timeout elapses (i.e. as part of the same sequence of
225 events resulting from clicking on a frame to select it). */
227 static unsigned long ignore_next_mouse_click_timeout
;
231 Formerly, we used PointerMotionHintMask (in standard_event_mask)
232 so that we would have to call XQueryPointer after each MotionNotify
233 event to ask for another such event. However, this made mouse tracking
234 slow, and there was a bug that made it eventually stop.
236 Simply asking for MotionNotify all the time seems to work better.
238 In order to avoid asking for motion events and then throwing most
239 of them away or busy-polling the server for mouse positions, we ask
240 the server for pointer motion hints. This means that we get only
241 one event per group of mouse movements. "Groups" are delimited by
242 other kinds of events (focus changes and button clicks, for
243 example), or by XQueryPointer calls; when one of these happens, we
244 get another MotionNotify event the next time the mouse moves. This
245 is at least as efficient as getting motion events when mouse
246 tracking is on, and I suspect only negligibly worse when tracking
249 /* Where the mouse was last time we reported a mouse event. */
251 static XRectangle last_mouse_glyph
;
252 static FRAME_PTR last_mouse_glyph_frame
;
253 static Lisp_Object last_mouse_press_frame
;
255 /* The scroll bar in which the last X motion event occurred.
257 If the last X motion event occurred in a scroll bar, we set this so
258 XTmouse_position can know whether to report a scroll bar motion or
261 If the last X motion event didn't occur in a scroll bar, we set
262 this to Qnil, to tell XTmouse_position to return an ordinary motion
265 static Lisp_Object last_mouse_scroll_bar
;
267 /* This is a hack. We would really prefer that XTmouse_position would
268 return the time associated with the position it returns, but there
269 doesn't seem to be any way to wrest the time-stamp from the server
270 along with the position query. So, we just keep track of the time
271 of the last movement we received, and return that in hopes that
272 it's somewhat accurate. */
274 static Time last_mouse_movement_time
;
276 /* Incremented by XTread_socket whenever it really tries to read
280 static int volatile input_signal_count
;
282 static int input_signal_count
;
285 /* Used locally within XTread_socket. */
287 static int x_noop_count
;
289 /* Initial values of argv and argc. */
291 extern char **initial_argv
;
292 extern int initial_argc
;
294 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
296 /* Tells if a window manager is present or not. */
298 extern Lisp_Object Vx_no_window_manager
;
300 extern Lisp_Object Qeql
;
304 /* A mask of extra modifier bits to put into every keyboard char. */
306 extern EMACS_INT extra_keyboard_modifiers
;
308 /* The keysyms to use for the various modifiers. */
310 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
311 Lisp_Object Vx_keysym_table
;
312 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
314 static Lisp_Object Qvendor_specific_keysyms
;
315 static Lisp_Object Qlatin_1
;
317 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
318 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
320 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
321 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
322 static const XColor
*x_color_cells
P_ ((Display
*, int *));
323 static void x_update_window_end
P_ ((struct window
*, int, int));
325 static int x_io_error_quitter
P_ ((Display
*));
326 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
327 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
328 static void x_update_end
P_ ((struct frame
*));
329 static void XTframe_up_to_date
P_ ((struct frame
*));
330 static void XTset_terminal_modes
P_ ((void));
331 static void XTreset_terminal_modes
P_ ((void));
332 static void x_clear_frame
P_ ((void));
333 static void frame_highlight
P_ ((struct frame
*));
334 static void frame_unhighlight
P_ ((struct frame
*));
335 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
336 static void x_focus_changed
P_ ((int, int, struct x_display_info
*,
337 struct frame
*, struct input_event
*));
338 static void x_detect_focus_change
P_ ((struct x_display_info
*,
339 XEvent
*, struct input_event
*));
340 static void XTframe_rehighlight
P_ ((struct frame
*));
341 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
342 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
343 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
344 enum text_cursor_kinds
));
346 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
347 static void x_flush
P_ ((struct frame
*f
));
348 static void x_update_begin
P_ ((struct frame
*));
349 static void x_update_window_begin
P_ ((struct window
*));
350 static void x_after_update_window_line
P_ ((struct glyph_row
*));
351 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Display
*, Window
));
352 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
353 enum scroll_bar_part
*,
354 Lisp_Object
*, Lisp_Object
*,
356 static void x_check_fullscreen
P_ ((struct frame
*));
357 static void x_check_expected_move
P_ ((struct frame
*));
358 static int handle_one_xevent
P_ ((struct x_display_info
*, XEvent
*,
359 int *, struct input_event
*));
362 /* Flush display of frame F, or of all frames if F is null. */
371 Lisp_Object rest
, frame
;
372 FOR_EACH_FRAME (rest
, frame
)
373 x_flush (XFRAME (frame
));
375 else if (FRAME_X_P (f
))
376 XFlush (FRAME_X_DISPLAY (f
));
381 /* Remove calls to XFlush by defining XFlush to an empty replacement.
382 Calls to XFlush should be unnecessary because the X output buffer
383 is flushed automatically as needed by calls to XPending,
384 XNextEvent, or XWindowEvent according to the XFlush man page.
385 XTread_socket calls XPending. Removing XFlush improves
388 #define XFlush(DISPLAY) (void) 0
391 /***********************************************************************
393 ***********************************************************************/
397 /* This is a function useful for recording debugging information about
398 the sequence of occurrences in this file. */
406 struct record event_record
[100];
408 int event_record_index
;
410 record_event (locus
, type
)
414 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
415 event_record_index
= 0;
417 event_record
[event_record_index
].locus
= locus
;
418 event_record
[event_record_index
].type
= type
;
419 event_record_index
++;
426 /* Return the struct x_display_info corresponding to DPY. */
428 struct x_display_info
*
429 x_display_info_for_display (dpy
)
432 struct x_display_info
*dpyinfo
;
434 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
435 if (dpyinfo
->display
== dpy
)
443 /***********************************************************************
444 Starting and ending an update
445 ***********************************************************************/
447 /* Start an update of frame F. This function is installed as a hook
448 for update_begin, i.e. it is called when update_begin is called.
449 This function is called prior to calls to x_update_window_begin for
450 each window being updated. Currently, there is nothing to do here
451 because all interesting stuff is done on a window basis. */
461 /* Start update of window W. Set the global variable updated_window
462 to the window being updated and set output_cursor to the cursor
466 x_update_window_begin (w
)
469 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
470 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
473 set_output_cursor (&w
->cursor
);
477 if (f
== display_info
->mouse_face_mouse_frame
)
479 /* Don't do highlighting for mouse motion during the update. */
480 display_info
->mouse_face_defer
= 1;
482 /* If F needs to be redrawn, simply forget about any prior mouse
484 if (FRAME_GARBAGED_P (f
))
485 display_info
->mouse_face_window
= Qnil
;
487 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
488 their mouse_face_p flag set, which means that they are always
489 unequal to rows in a desired matrix which never have that
490 flag set. So, rows containing mouse-face glyphs are never
491 scrolled, and we don't have to switch the mouse highlight off
492 here to prevent it from being scrolled. */
494 /* Can we tell that this update does not affect the window
495 where the mouse highlight is? If so, no need to turn off.
496 Likewise, don't do anything if the frame is garbaged;
497 in that case, the frame's current matrix that we would use
498 is all wrong, and we will redisplay that line anyway. */
499 if (!NILP (display_info
->mouse_face_window
)
500 && w
== XWINDOW (display_info
->mouse_face_window
))
504 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
505 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
508 if (i
< w
->desired_matrix
->nrows
)
509 clear_mouse_face (display_info
);
518 /* Draw a vertical window border from (x,y0) to (x,y1) */
521 x_draw_vertical_window_border (w
, x
, y0
, y1
)
525 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
528 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
530 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
533 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
534 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
537 /* End update of window W (which is equal to updated_window).
539 Draw vertical borders between horizontally adjacent windows, and
540 display W's cursor if CURSOR_ON_P is non-zero.
542 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
543 glyphs in mouse-face were overwritten. In that case we have to
544 make sure that the mouse-highlight is properly redrawn.
546 W may be a menu bar pseudo-window in case we don't have X toolkit
547 support. Such windows don't have a cursor, so don't display it
551 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
553 int cursor_on_p
, mouse_face_overwritten_p
;
555 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
557 if (!w
->pseudo_window_p
)
562 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
564 output_cursor
.x
, output_cursor
.y
);
566 if (draw_window_fringes (w
, 1))
567 x_draw_vertical_border (w
);
572 /* If a row with mouse-face was overwritten, arrange for
573 XTframe_up_to_date to redisplay the mouse highlight. */
574 if (mouse_face_overwritten_p
)
576 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
577 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
578 dpyinfo
->mouse_face_window
= Qnil
;
581 updated_window
= NULL
;
585 /* End update of frame F. This function is installed as a hook in
592 /* Mouse highlight may be displayed again. */
593 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
597 XFlush (FRAME_X_DISPLAY (f
));
603 /* This function is called from various places in xdisp.c whenever a
604 complete update has been performed. The global variable
605 updated_window is not available here. */
608 XTframe_up_to_date (f
)
613 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
615 if (dpyinfo
->mouse_face_deferred_gc
616 || f
== dpyinfo
->mouse_face_mouse_frame
)
619 if (dpyinfo
->mouse_face_mouse_frame
)
620 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
621 dpyinfo
->mouse_face_mouse_x
,
622 dpyinfo
->mouse_face_mouse_y
);
623 dpyinfo
->mouse_face_deferred_gc
= 0;
630 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
631 arrow bitmaps, or clear the fringes if no bitmaps are required
632 before DESIRED_ROW is made current. The window being updated is
633 found in updated_window. This function It is called from
634 update_window_line only if it is known that there are differences
635 between bitmaps to be drawn between current row and DESIRED_ROW. */
638 x_after_update_window_line (desired_row
)
639 struct glyph_row
*desired_row
;
641 struct window
*w
= updated_window
;
647 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
648 desired_row
->redraw_fringe_bitmaps_p
= 1;
650 /* When a window has disappeared, make sure that no rest of
651 full-width rows stays visible in the internal border. Could
652 check here if updated_window is the leftmost/rightmost window,
653 but I guess it's not worth doing since vertically split windows
654 are almost never used, internal border is rarely set, and the
655 overhead is very small. */
656 if (windows_or_buffers_changed
657 && desired_row
->full_width_p
658 && (f
= XFRAME (w
->frame
),
659 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
661 && (height
= desired_row
->visible_height
,
664 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
666 /* Internal border is drawn below the tool bar. */
667 if (WINDOWP (f
->tool_bar_window
)
668 && w
== XWINDOW (f
->tool_bar_window
))
672 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
673 0, y
, width
, height
, False
);
674 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
675 FRAME_PIXEL_WIDTH (f
) - width
,
676 y
, width
, height
, False
);
682 x_draw_fringe_bitmap (w
, row
, p
)
684 struct glyph_row
*row
;
685 struct draw_fringe_bitmap_params
*p
;
687 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
688 Display
*display
= FRAME_X_DISPLAY (f
);
689 Window window
= FRAME_X_WINDOW (f
);
690 GC gc
= f
->output_data
.x
->normal_gc
;
691 struct face
*face
= p
->face
;
694 /* Must clip because of partially visible lines. */
695 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
698 /* Adjust position of "bottom aligned" bitmap on partially
701 int oldVH
= row
->visible_height
;
702 row
->visible_height
= p
->h
;
703 row
->y
-= rowY
- p
->y
;
704 x_clip_to_row (w
, row
, -1, gc
);
706 row
->visible_height
= oldVH
;
709 x_clip_to_row (w
, row
, -1, gc
);
711 if (p
->bx
>= 0 && !p
->overlay_p
)
713 /* In case the same realized face is used for fringes and
714 for something displayed in the text (e.g. face `region' on
715 mono-displays, the fill style may have been changed to
716 FillSolid in x_draw_glyph_string_background. */
718 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
720 XSetForeground (display
, face
->gc
, face
->background
);
722 XFillRectangle (display
, window
, face
->gc
,
723 p
->bx
, p
->by
, p
->nx
, p
->ny
);
726 XSetForeground (display
, face
->gc
, face
->foreground
);
732 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
733 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
737 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
739 bits
= (unsigned char *)p
->bits
+ p
->dh
;
741 /* Draw the bitmap. I believe these small pixmaps can be cached
743 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
745 ? (p
->overlay_p
? face
->background
746 : f
->output_data
.x
->cursor_pixel
)
748 face
->background
, depth
);
752 clipmask
= XCreatePixmapFromBitmapData (display
,
753 FRAME_X_DISPLAY_INFO (f
)->root_window
,
756 gcv
.clip_mask
= clipmask
;
757 gcv
.clip_x_origin
= p
->x
;
758 gcv
.clip_y_origin
= p
->y
;
759 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
762 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
763 p
->wd
, p
->h
, p
->x
, p
->y
);
764 XFreePixmap (display
, pixmap
);
768 gcv
.clip_mask
= (Pixmap
) 0;
769 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
770 XFreePixmap (display
, clipmask
);
774 XSetClipMask (display
, gc
, None
);
779 /* This is called when starting Emacs and when restarting after
780 suspend. When starting Emacs, no X window is mapped. And nothing
781 must be done to Emacs's own window if it is suspended (though that
785 XTset_terminal_modes ()
789 /* This is called when exiting or suspending Emacs. Exiting will make
790 the X-windows go away, and suspending requires no action. */
793 XTreset_terminal_modes ()
799 /***********************************************************************
801 ***********************************************************************/
803 /* Function prototypes of this page. */
805 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
808 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
809 is not contained in the font. */
812 x_per_char_metric (font
, char2b
, font_type
)
815 int font_type
; /* unused on X */
817 /* The result metric information. */
818 XCharStruct
*pcm
= NULL
;
820 xassert (font
&& char2b
);
822 if (font
->per_char
!= NULL
)
824 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
826 /* min_char_or_byte2 specifies the linear character index
827 corresponding to the first element of the per_char array,
828 max_char_or_byte2 is the index of the last character. A
829 character with non-zero CHAR2B->byte1 is not in the font.
830 A character with byte2 less than min_char_or_byte2 or
831 greater max_char_or_byte2 is not in the font. */
832 if (char2b
->byte1
== 0
833 && char2b
->byte2
>= font
->min_char_or_byte2
834 && char2b
->byte2
<= font
->max_char_or_byte2
)
835 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
839 /* If either min_byte1 or max_byte1 are nonzero, both
840 min_char_or_byte2 and max_char_or_byte2 are less than
841 256, and the 2-byte character index values corresponding
842 to the per_char array element N (counting from 0) are:
844 byte1 = N/D + min_byte1
845 byte2 = N\D + min_char_or_byte2
849 D = max_char_or_byte2 - min_char_or_byte2 + 1
851 \ = integer modulus */
852 if (char2b
->byte1
>= font
->min_byte1
853 && char2b
->byte1
<= font
->max_byte1
854 && char2b
->byte2
>= font
->min_char_or_byte2
855 && char2b
->byte2
<= font
->max_char_or_byte2
)
857 pcm
= (font
->per_char
858 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
859 * (char2b
->byte1
- font
->min_byte1
))
860 + (char2b
->byte2
- font
->min_char_or_byte2
));
866 /* If the per_char pointer is null, all glyphs between the first
867 and last character indexes inclusive have the same
868 information, as given by both min_bounds and max_bounds. */
869 if (char2b
->byte2
>= font
->min_char_or_byte2
870 && char2b
->byte2
<= font
->max_char_or_byte2
)
871 pcm
= &font
->max_bounds
;
875 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
880 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
881 the two-byte form of C. Encoding is returned in *CHAR2B. */
884 x_encode_char (c
, char2b
, font_info
, two_byte_p
)
887 struct font_info
*font_info
;
890 int charset
= CHAR_CHARSET (c
);
891 XFontStruct
*font
= font_info
->font
;
893 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
894 This may be either a program in a special encoder language or a
896 if (font_info
->font_encoder
)
898 /* It's a program. */
899 struct ccl_program
*ccl
= font_info
->font_encoder
;
901 check_ccl_update (ccl
);
902 if (CHARSET_DIMENSION (charset
) == 1)
904 ccl
->reg
[0] = charset
;
905 ccl
->reg
[1] = char2b
->byte2
;
910 ccl
->reg
[0] = charset
;
911 ccl
->reg
[1] = char2b
->byte1
;
912 ccl
->reg
[2] = char2b
->byte2
;
915 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
917 /* We assume that MSBs are appropriately set/reset by CCL
919 if (font
->max_byte1
== 0) /* 1-byte font */
920 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
922 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
924 else if (font_info
->encoding
[charset
])
926 /* Fixed encoding scheme. See fontset.h for the meaning of the
928 int enc
= font_info
->encoding
[charset
];
930 if ((enc
== 1 || enc
== 2)
931 && CHARSET_DIMENSION (charset
) == 2)
932 char2b
->byte1
|= 0x80;
934 if (enc
== 1 || enc
== 3)
935 char2b
->byte2
|= 0x80;
939 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
941 return FONT_TYPE_UNKNOWN
;
946 /***********************************************************************
948 ***********************************************************************/
952 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
953 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
954 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
956 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
957 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
958 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
959 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
960 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
961 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
962 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
963 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
964 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
965 unsigned long *, double, int));
966 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
967 double, int, unsigned long));
968 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
969 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
970 static void x_draw_image_relief
P_ ((struct glyph_string
*));
971 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
972 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
973 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
975 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
976 int, int, int, int, int, int,
978 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
979 int, int, int, XRectangle
*));
982 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
986 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
991 struct glyph_string
*s
;
993 if (s
->font
== FRAME_FONT (s
->f
)
994 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
995 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
997 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1000 /* Cursor on non-default face: must merge. */
1004 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1005 xgcv
.foreground
= s
->face
->background
;
1007 /* If the glyph would be invisible, try a different foreground. */
1008 if (xgcv
.foreground
== xgcv
.background
)
1009 xgcv
.foreground
= s
->face
->foreground
;
1010 if (xgcv
.foreground
== xgcv
.background
)
1011 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1012 if (xgcv
.foreground
== xgcv
.background
)
1013 xgcv
.foreground
= s
->face
->foreground
;
1015 /* Make sure the cursor is distinct from text in this face. */
1016 if (xgcv
.background
== s
->face
->background
1017 && xgcv
.foreground
== s
->face
->foreground
)
1019 xgcv
.background
= s
->face
->foreground
;
1020 xgcv
.foreground
= s
->face
->background
;
1023 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1024 xgcv
.font
= s
->font
->fid
;
1025 xgcv
.graphics_exposures
= False
;
1026 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1028 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1029 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1032 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1033 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1035 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1040 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1043 x_set_mouse_face_gc (s
)
1044 struct glyph_string
*s
;
1049 /* What face has to be used last for the mouse face? */
1050 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1051 face
= FACE_FROM_ID (s
->f
, face_id
);
1053 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1055 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1056 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
1058 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
1059 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1060 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1062 /* If font in this face is same as S->font, use it. */
1063 if (s
->font
== s
->face
->font
)
1064 s
->gc
= s
->face
->gc
;
1067 /* Otherwise construct scratch_cursor_gc with values from FACE
1072 xgcv
.background
= s
->face
->background
;
1073 xgcv
.foreground
= s
->face
->foreground
;
1074 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1075 xgcv
.font
= s
->font
->fid
;
1076 xgcv
.graphics_exposures
= False
;
1077 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1079 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1080 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1083 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1084 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1086 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1089 xassert (s
->gc
!= 0);
1093 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1094 Faces to use in the mode line have already been computed when the
1095 matrix was built, so there isn't much to do, here. */
1098 x_set_mode_line_face_gc (s
)
1099 struct glyph_string
*s
;
1101 s
->gc
= s
->face
->gc
;
1105 /* Set S->gc of glyph string S for drawing that glyph string. Set
1106 S->stippled_p to a non-zero value if the face of S has a stipple
1110 x_set_glyph_string_gc (s
)
1111 struct glyph_string
*s
;
1113 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1115 if (s
->hl
== DRAW_NORMAL_TEXT
)
1117 s
->gc
= s
->face
->gc
;
1118 s
->stippled_p
= s
->face
->stipple
!= 0;
1120 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1122 x_set_mode_line_face_gc (s
);
1123 s
->stippled_p
= s
->face
->stipple
!= 0;
1125 else if (s
->hl
== DRAW_CURSOR
)
1127 x_set_cursor_gc (s
);
1130 else if (s
->hl
== DRAW_MOUSE_FACE
)
1132 x_set_mouse_face_gc (s
);
1133 s
->stippled_p
= s
->face
->stipple
!= 0;
1135 else if (s
->hl
== DRAW_IMAGE_RAISED
1136 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1138 s
->gc
= s
->face
->gc
;
1139 s
->stippled_p
= s
->face
->stipple
!= 0;
1143 s
->gc
= s
->face
->gc
;
1144 s
->stippled_p
= s
->face
->stipple
!= 0;
1147 /* GC must have been set. */
1148 xassert (s
->gc
!= 0);
1152 /* Set clipping for output of glyph string S. S may be part of a mode
1153 line or menu if we don't have X toolkit support. */
1156 x_set_glyph_string_clipping (s
)
1157 struct glyph_string
*s
;
1160 get_glyph_string_clip_rect (s
, &r
);
1161 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
1166 Compute left and right overhang of glyph string S. If S is a glyph
1167 string for a composition, assume overhangs don't exist. */
1170 x_compute_glyph_string_overhangs (s
)
1171 struct glyph_string
*s
;
1174 && s
->first_glyph
->type
== CHAR_GLYPH
)
1177 int direction
, font_ascent
, font_descent
;
1178 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1179 &font_ascent
, &font_descent
, &cs
);
1180 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1181 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1186 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1189 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1190 struct glyph_string
*s
;
1194 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1195 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1196 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1197 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1201 /* Draw the background of glyph_string S. If S->background_filled_p
1202 is non-zero don't draw it. FORCE_P non-zero means draw the
1203 background even if it wouldn't be drawn normally. This is used
1204 when a string preceding S draws into the background of S, or S
1205 contains the first component of a composition. */
1208 x_draw_glyph_string_background (s
, force_p
)
1209 struct glyph_string
*s
;
1212 /* Nothing to do if background has already been drawn or if it
1213 shouldn't be drawn in the first place. */
1214 if (!s
->background_filled_p
)
1216 int box_line_width
= max (s
->face
->box_line_width
, 0);
1220 /* Fill background with a stipple pattern. */
1221 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1222 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1223 s
->y
+ box_line_width
,
1224 s
->background_width
,
1225 s
->height
- 2 * box_line_width
);
1226 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1227 s
->background_filled_p
= 1;
1229 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1230 || s
->font_not_found_p
1231 || s
->extends_to_end_of_line_p
1234 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1235 s
->background_width
,
1236 s
->height
- 2 * box_line_width
);
1237 s
->background_filled_p
= 1;
1243 /* Draw the foreground of glyph string S. */
1246 x_draw_glyph_string_foreground (s
)
1247 struct glyph_string
*s
;
1251 /* If first glyph of S has a left box line, start drawing the text
1252 of S to the right of that box line. */
1253 if (s
->face
->box
!= FACE_NO_BOX
1254 && s
->first_glyph
->left_box_line_p
)
1255 x
= s
->x
+ abs (s
->face
->box_line_width
);
1259 /* Draw characters of S as rectangles if S's font could not be
1261 if (s
->font_not_found_p
)
1263 for (i
= 0; i
< s
->nchars
; ++i
)
1265 struct glyph
*g
= s
->first_glyph
+ i
;
1266 XDrawRectangle (s
->display
, s
->window
,
1267 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1269 x
+= g
->pixel_width
;
1274 char *char1b
= (char *) s
->char2b
;
1275 int boff
= s
->font_info
->baseline_offset
;
1277 if (s
->font_info
->vertical_centering
)
1278 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1280 /* If we can use 8-bit functions, condense S->char2b. */
1282 for (i
= 0; i
< s
->nchars
; ++i
)
1283 char1b
[i
] = s
->char2b
[i
].byte2
;
1285 /* Draw text with XDrawString if background has already been
1286 filled. Otherwise, use XDrawImageString. (Note that
1287 XDrawImageString is usually faster than XDrawString.) Always
1288 use XDrawImageString when drawing the cursor so that there is
1289 no chance that characters under a box cursor are invisible. */
1291 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1293 /* Draw characters with 16-bit or 8-bit functions. */
1295 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1296 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1298 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1299 s
->ybase
- boff
, char1b
, s
->nchars
);
1304 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1305 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1307 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1308 s
->ybase
- boff
, char1b
, s
->nchars
);
1311 if (s
->face
->overstrike
)
1313 /* For overstriking (to simulate bold-face), draw the
1314 characters again shifted to the right by one pixel. */
1316 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1317 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1319 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1320 s
->ybase
- boff
, char1b
, s
->nchars
);
1325 /* Draw the foreground of composite glyph string S. */
1328 x_draw_composite_glyph_string_foreground (s
)
1329 struct glyph_string
*s
;
1333 /* If first glyph of S has a left box line, start drawing the text
1334 of S to the right of that box line. */
1335 if (s
->face
->box
!= FACE_NO_BOX
1336 && s
->first_glyph
->left_box_line_p
)
1337 x
= s
->x
+ abs (s
->face
->box_line_width
);
1341 /* S is a glyph string for a composition. S->gidx is the index of
1342 the first character drawn for glyphs of this composition.
1343 S->gidx == 0 means we are drawing the very first character of
1344 this composition. */
1346 /* Draw a rectangle for the composition if the font for the very
1347 first character of the composition could not be loaded. */
1348 if (s
->font_not_found_p
)
1351 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1352 s
->width
- 1, s
->height
- 1);
1356 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
1358 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1359 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
1360 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1362 if (s
->face
->overstrike
)
1363 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1364 x
+ s
->cmp
->offsets
[s
->gidx
* 2] + 1,
1365 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1372 #ifdef USE_X_TOOLKIT
1374 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1375 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1376 XrmValue
*, XrmValue
*, XtPointer
*));
1377 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1378 XrmValue
*, Cardinal
*));
1381 /* Return the frame on which widget WIDGET is used.. Abort if frame
1382 cannot be determined. */
1384 static struct frame
*
1385 x_frame_of_widget (widget
)
1388 struct x_display_info
*dpyinfo
;
1392 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1394 /* Find the top-level shell of the widget. Note that this function
1395 can be called when the widget is not yet realized, so XtWindow
1396 (widget) == 0. That's the reason we can't simply use
1397 x_any_window_to_frame. */
1398 while (!XtIsTopLevelShell (widget
))
1399 widget
= XtParent (widget
);
1401 /* Look for a frame with that top-level widget. Allocate the color
1402 on that frame to get the right gamma correction value. */
1403 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
1404 if (GC_FRAMEP (XCAR (tail
))
1405 && (f
= XFRAME (XCAR (tail
)),
1406 (f
->output_data
.nothing
!= 1
1407 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1408 && f
->output_data
.x
->widget
== widget
)
1415 /* Allocate the color COLOR->pixel on the screen and display of
1416 widget WIDGET in colormap CMAP. If an exact match cannot be
1417 allocated, try the nearest color available. Value is non-zero
1418 if successful. This is called from lwlib. */
1421 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1426 struct frame
*f
= x_frame_of_widget (widget
);
1427 return x_alloc_nearest_color (f
, cmap
, color
);
1431 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1432 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1433 If this produces the same color as PIXEL, try a color where all RGB
1434 values have DELTA added. Return the allocated color in *PIXEL.
1435 DISPLAY is the X display, CMAP is the colormap to operate on.
1436 Value is non-zero if successful. */
1439 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1443 unsigned long *pixel
;
1447 struct frame
*f
= x_frame_of_widget (widget
);
1448 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1452 /* Structure specifying which arguments should be passed by Xt to
1453 cvt_string_to_pixel. We want the widget's screen and colormap. */
1455 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1457 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1459 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1464 /* The address of this variable is returned by
1465 cvt_string_to_pixel. */
1467 static Pixel cvt_string_to_pixel_value
;
1470 /* Convert a color name to a pixel color.
1472 DPY is the display we are working on.
1474 ARGS is an array of *NARGS XrmValue structures holding additional
1475 information about the widget for which the conversion takes place.
1476 The contents of this array are determined by the specification
1477 in cvt_string_to_pixel_args.
1479 FROM is a pointer to an XrmValue which points to the color name to
1480 convert. TO is an XrmValue in which to return the pixel color.
1482 CLOSURE_RET is a pointer to user-data, in which we record if
1483 we allocated the color or not.
1485 Value is True if successful, False otherwise. */
1488 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1492 XrmValue
*from
, *to
;
1493 XtPointer
*closure_ret
;
1503 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1504 "wrongParameters", "cvt_string_to_pixel",
1506 "Screen and colormap args required", NULL
, NULL
);
1510 screen
= *(Screen
**) args
[0].addr
;
1511 cmap
= *(Colormap
*) args
[1].addr
;
1512 color_name
= (String
) from
->addr
;
1514 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1516 *closure_ret
= (XtPointer
) False
;
1517 pixel
= WhitePixelOfScreen (screen
);
1519 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1521 *closure_ret
= (XtPointer
) False
;
1522 pixel
= BlackPixelOfScreen (screen
);
1524 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1525 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1527 pixel
= color
.pixel
;
1528 *closure_ret
= (XtPointer
) True
;
1533 Cardinal nparams
= 1;
1535 params
[0] = color_name
;
1536 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1537 "badValue", "cvt_string_to_pixel",
1538 "XtToolkitError", "Invalid color `%s'",
1543 if (to
->addr
!= NULL
)
1545 if (to
->size
< sizeof (Pixel
))
1547 to
->size
= sizeof (Pixel
);
1551 *(Pixel
*) to
->addr
= pixel
;
1555 cvt_string_to_pixel_value
= pixel
;
1556 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1559 to
->size
= sizeof (Pixel
);
1564 /* Free a pixel color which was previously allocated via
1565 cvt_string_to_pixel. This is registered as the destructor
1566 for this type of resource via XtSetTypeConverter.
1568 APP is the application context in which we work.
1570 TO is a pointer to an XrmValue holding the color to free.
1571 CLOSURE is the value we stored in CLOSURE_RET for this color
1572 in cvt_string_to_pixel.
1574 ARGS and NARGS are like for cvt_string_to_pixel. */
1577 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1586 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1588 "Screen and colormap arguments required",
1591 else if (closure
!= NULL
)
1593 /* We did allocate the pixel, so free it. */
1594 Screen
*screen
= *(Screen
**) args
[0].addr
;
1595 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1596 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1597 (Pixel
*) to
->addr
, 1);
1602 #endif /* USE_X_TOOLKIT */
1605 /* Value is an array of XColor structures for the contents of the
1606 color map of display DPY. Set *NCELLS to the size of the array.
1607 Note that this probably shouldn't be called for large color maps,
1608 say a 24-bit TrueColor map. */
1610 static const XColor
*
1611 x_color_cells (dpy
, ncells
)
1615 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1617 if (dpyinfo
->color_cells
== NULL
)
1619 Screen
*screen
= dpyinfo
->screen
;
1622 dpyinfo
->ncolor_cells
1623 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1624 dpyinfo
->color_cells
1625 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1626 * sizeof *dpyinfo
->color_cells
);
1628 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1629 dpyinfo
->color_cells
[i
].pixel
= i
;
1631 XQueryColors (dpy
, dpyinfo
->cmap
,
1632 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1635 *ncells
= dpyinfo
->ncolor_cells
;
1636 return dpyinfo
->color_cells
;
1640 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1641 colors in COLORS. Use cached information, if available. */
1644 x_query_colors (f
, colors
, ncolors
)
1649 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1651 if (dpyinfo
->color_cells
)
1654 for (i
= 0; i
< ncolors
; ++i
)
1656 unsigned long pixel
= colors
[i
].pixel
;
1657 xassert (pixel
< dpyinfo
->ncolor_cells
);
1658 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1659 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1663 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1667 /* On frame F, translate pixel color to RGB values for the color in
1668 COLOR. Use cached information, if available. */
1671 x_query_color (f
, color
)
1675 x_query_colors (f
, color
, 1);
1679 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1680 exact match can't be allocated, try the nearest color available.
1681 Value is non-zero if successful. Set *COLOR to the color
1685 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1692 rc
= XAllocColor (dpy
, cmap
, color
);
1695 /* If we got to this point, the colormap is full, so we're going
1696 to try to get the next closest color. The algorithm used is
1697 a least-squares matching, which is what X uses for closest
1698 color matching with StaticColor visuals. */
1700 unsigned long nearest_delta
= ~0;
1702 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1704 for (nearest
= i
= 0; i
< ncells
; ++i
)
1706 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1707 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1708 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1709 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1711 if (delta
< nearest_delta
)
1714 nearest_delta
= delta
;
1718 color
->red
= cells
[nearest
].red
;
1719 color
->green
= cells
[nearest
].green
;
1720 color
->blue
= cells
[nearest
].blue
;
1721 rc
= XAllocColor (dpy
, cmap
, color
);
1725 /* If allocation succeeded, and the allocated pixel color is not
1726 equal to a cached pixel color recorded earlier, there was a
1727 change in the colormap, so clear the color cache. */
1728 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1729 XColor
*cached_color
;
1731 if (dpyinfo
->color_cells
1732 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1733 (cached_color
->red
!= color
->red
1734 || cached_color
->blue
!= color
->blue
1735 || cached_color
->green
!= color
->green
)))
1737 xfree (dpyinfo
->color_cells
);
1738 dpyinfo
->color_cells
= NULL
;
1739 dpyinfo
->ncolor_cells
= 0;
1743 #ifdef DEBUG_X_COLORS
1745 register_color (color
->pixel
);
1746 #endif /* DEBUG_X_COLORS */
1752 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1753 exact match can't be allocated, try the nearest color available.
1754 Value is non-zero if successful. Set *COLOR to the color
1758 x_alloc_nearest_color (f
, cmap
, color
)
1763 gamma_correct (f
, color
);
1764 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1768 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1769 It's necessary to do this instead of just using PIXEL directly to
1770 get color reference counts right. */
1773 x_copy_color (f
, pixel
)
1775 unsigned long pixel
;
1779 color
.pixel
= pixel
;
1781 x_query_color (f
, &color
);
1782 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1784 #ifdef DEBUG_X_COLORS
1785 register_color (pixel
);
1791 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1792 It's necessary to do this instead of just using PIXEL directly to
1793 get color reference counts right. */
1796 x_copy_dpy_color (dpy
, cmap
, pixel
)
1799 unsigned long pixel
;
1803 color
.pixel
= pixel
;
1805 XQueryColor (dpy
, cmap
, &color
);
1806 XAllocColor (dpy
, cmap
, &color
);
1808 #ifdef DEBUG_X_COLORS
1809 register_color (pixel
);
1815 /* Brightness beyond which a color won't have its highlight brightness
1818 Nominally, highlight colors for `3d' faces are calculated by
1819 brightening an object's color by a constant scale factor, but this
1820 doesn't yield good results for dark colors, so for colors who's
1821 brightness is less than this value (on a scale of 0-65535) have an
1822 use an additional additive factor.
1824 The value here is set so that the default menu-bar/mode-line color
1825 (grey75) will not have its highlights changed at all. */
1826 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1829 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1830 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1831 If this produces the same color as PIXEL, try a color where all RGB
1832 values have DELTA added. Return the allocated color in *PIXEL.
1833 DISPLAY is the X display, CMAP is the colormap to operate on.
1834 Value is non-zero if successful. */
1837 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
1841 unsigned long *pixel
;
1849 /* Get RGB color values. */
1850 color
.pixel
= *pixel
;
1851 x_query_color (f
, &color
);
1853 /* Change RGB values by specified FACTOR. Avoid overflow! */
1854 xassert (factor
>= 0);
1855 new.red
= min (0xffff, factor
* color
.red
);
1856 new.green
= min (0xffff, factor
* color
.green
);
1857 new.blue
= min (0xffff, factor
* color
.blue
);
1859 /* Calculate brightness of COLOR. */
1860 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1862 /* We only boost colors that are darker than
1863 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1864 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1865 /* Make an additive adjustment to NEW, because it's dark enough so
1866 that scaling by FACTOR alone isn't enough. */
1868 /* How far below the limit this color is (0 - 1, 1 being darker). */
1869 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1870 /* The additive adjustment. */
1871 int min_delta
= delta
* dimness
* factor
/ 2;
1875 new.red
= max (0, new.red
- min_delta
);
1876 new.green
= max (0, new.green
- min_delta
);
1877 new.blue
= max (0, new.blue
- min_delta
);
1881 new.red
= min (0xffff, min_delta
+ new.red
);
1882 new.green
= min (0xffff, min_delta
+ new.green
);
1883 new.blue
= min (0xffff, min_delta
+ new.blue
);
1887 /* Try to allocate the color. */
1888 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1891 if (new.pixel
== *pixel
)
1893 /* If we end up with the same color as before, try adding
1894 delta to the RGB values. */
1895 x_free_colors (f
, &new.pixel
, 1);
1897 new.red
= min (0xffff, delta
+ color
.red
);
1898 new.green
= min (0xffff, delta
+ color
.green
);
1899 new.blue
= min (0xffff, delta
+ color
.blue
);
1900 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1911 /* Set up the foreground color for drawing relief lines of glyph
1912 string S. RELIEF is a pointer to a struct relief containing the GC
1913 with which lines will be drawn. Use a color that is FACTOR or
1914 DELTA lighter or darker than the relief's background which is found
1915 in S->f->output_data.x->relief_background. If such a color cannot
1916 be allocated, use DEFAULT_PIXEL, instead. */
1919 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1921 struct relief
*relief
;
1924 unsigned long default_pixel
;
1927 struct x_output
*di
= f
->output_data
.x
;
1928 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1929 unsigned long pixel
;
1930 unsigned long background
= di
->relief_background
;
1931 Colormap cmap
= FRAME_X_COLORMAP (f
);
1932 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1933 Display
*dpy
= FRAME_X_DISPLAY (f
);
1935 xgcv
.graphics_exposures
= False
;
1936 xgcv
.line_width
= 1;
1938 /* Free previously allocated color. The color cell will be reused
1939 when it has been freed as many times as it was allocated, so this
1940 doesn't affect faces using the same colors. */
1942 && relief
->allocated_p
)
1944 x_free_colors (f
, &relief
->pixel
, 1);
1945 relief
->allocated_p
= 0;
1948 /* Allocate new color. */
1949 xgcv
.foreground
= default_pixel
;
1951 if (dpyinfo
->n_planes
!= 1
1952 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1954 relief
->allocated_p
= 1;
1955 xgcv
.foreground
= relief
->pixel
= pixel
;
1958 if (relief
->gc
== 0)
1960 xgcv
.stipple
= dpyinfo
->gray
;
1962 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1965 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1969 /* Set up colors for the relief lines around glyph string S. */
1972 x_setup_relief_colors (s
)
1973 struct glyph_string
*s
;
1975 struct x_output
*di
= s
->f
->output_data
.x
;
1976 unsigned long color
;
1978 if (s
->face
->use_box_color_for_shadows_p
)
1979 color
= s
->face
->box_color
;
1980 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1982 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1983 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1988 /* Get the background color of the face. */
1989 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1990 color
= xgcv
.background
;
1993 if (di
->white_relief
.gc
== 0
1994 || color
!= di
->relief_background
)
1996 di
->relief_background
= color
;
1997 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1998 WHITE_PIX_DEFAULT (s
->f
));
1999 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2000 BLACK_PIX_DEFAULT (s
->f
));
2005 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2006 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2007 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2008 relief. LEFT_P non-zero means draw a relief on the left side of
2009 the rectangle. RIGHT_P non-zero means draw a relief on the right
2010 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2014 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2015 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2017 int left_x
, top_y
, right_x
, bottom_y
, width
;
2018 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2019 XRectangle
*clip_rect
;
2021 Display
*dpy
= FRAME_X_DISPLAY (f
);
2022 Window window
= FRAME_X_WINDOW (f
);
2027 gc
= f
->output_data
.x
->white_relief
.gc
;
2029 gc
= f
->output_data
.x
->black_relief
.gc
;
2030 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2034 for (i
= 0; i
< width
; ++i
)
2035 XDrawLine (dpy
, window
, gc
,
2036 left_x
+ i
* left_p
, top_y
+ i
,
2037 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2041 for (i
= 0; i
< width
; ++i
)
2042 XDrawLine (dpy
, window
, gc
,
2043 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2045 XSetClipMask (dpy
, gc
, None
);
2047 gc
= f
->output_data
.x
->black_relief
.gc
;
2049 gc
= f
->output_data
.x
->white_relief
.gc
;
2050 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2054 for (i
= 0; i
< width
; ++i
)
2055 XDrawLine (dpy
, window
, gc
,
2056 left_x
+ i
* left_p
, bottom_y
- i
,
2057 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2061 for (i
= 0; i
< width
; ++i
)
2062 XDrawLine (dpy
, window
, gc
,
2063 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2065 XSetClipMask (dpy
, gc
, None
);
2069 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2070 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2071 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2072 left side of the rectangle. RIGHT_P non-zero means draw a line
2073 on the right side of the rectangle. CLIP_RECT is the clipping
2074 rectangle to use when drawing. */
2077 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2078 left_p
, right_p
, clip_rect
)
2079 struct glyph_string
*s
;
2080 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2081 XRectangle
*clip_rect
;
2085 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2086 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2087 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2090 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2091 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2095 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2096 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2099 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2100 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2104 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2105 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2107 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2108 XSetClipMask (s
->display
, s
->gc
, None
);
2112 /* Draw a box around glyph string S. */
2115 x_draw_glyph_string_box (s
)
2116 struct glyph_string
*s
;
2118 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2119 int left_p
, right_p
;
2120 struct glyph
*last_glyph
;
2121 XRectangle clip_rect
;
2123 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2124 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2125 : window_box_right (s
->w
, s
->area
));
2127 /* The glyph that may have a right box line. */
2128 last_glyph
= (s
->cmp
|| s
->img
2130 : s
->first_glyph
+ s
->nchars
- 1);
2132 width
= abs (s
->face
->box_line_width
);
2133 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2135 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2137 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2139 bottom_y
= top_y
+ s
->height
- 1;
2141 left_p
= (s
->first_glyph
->left_box_line_p
2142 || (s
->hl
== DRAW_MOUSE_FACE
2144 || s
->prev
->hl
!= s
->hl
)));
2145 right_p
= (last_glyph
->right_box_line_p
2146 || (s
->hl
== DRAW_MOUSE_FACE
2148 || s
->next
->hl
!= s
->hl
)));
2150 get_glyph_string_clip_rect (s
, &clip_rect
);
2152 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2153 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2154 left_p
, right_p
, &clip_rect
);
2157 x_setup_relief_colors (s
);
2158 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2159 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2164 /* Draw foreground of image glyph string S. */
2167 x_draw_image_foreground (s
)
2168 struct glyph_string
*s
;
2171 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2173 /* If first glyph of S has a left box line, start drawing it to the
2174 right of that line. */
2175 if (s
->face
->box
!= FACE_NO_BOX
2176 && s
->first_glyph
->left_box_line_p
2178 x
+= abs (s
->face
->box_line_width
);
2180 /* If there is a margin around the image, adjust x- and y-position
2182 if (s
->slice
.x
== 0)
2183 x
+= s
->img
->hmargin
;
2184 if (s
->slice
.y
== 0)
2185 y
+= s
->img
->vmargin
;
2191 /* We can't set both a clip mask and use XSetClipRectangles
2192 because the latter also sets a clip mask. We also can't
2193 trust on the shape extension to be available
2194 (XShapeCombineRegion). So, compute the rectangle to draw
2196 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2199 XRectangle clip_rect
, image_rect
, r
;
2201 xgcv
.clip_mask
= s
->img
->mask
;
2202 xgcv
.clip_x_origin
= x
;
2203 xgcv
.clip_y_origin
= y
;
2204 xgcv
.function
= GXcopy
;
2205 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2207 get_glyph_string_clip_rect (s
, &clip_rect
);
2210 image_rect
.width
= s
->slice
.width
;
2211 image_rect
.height
= s
->slice
.height
;
2212 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2213 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2214 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2215 r
.width
, r
.height
, r
.x
, r
.y
);
2219 XRectangle clip_rect
, image_rect
, r
;
2221 get_glyph_string_clip_rect (s
, &clip_rect
);
2224 image_rect
.width
= s
->slice
.width
;
2225 image_rect
.height
= s
->slice
.height
;
2226 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2227 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2228 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2229 r
.width
, r
.height
, r
.x
, r
.y
);
2231 /* When the image has a mask, we can expect that at
2232 least part of a mouse highlight or a block cursor will
2233 be visible. If the image doesn't have a mask, make
2234 a block cursor visible by drawing a rectangle around
2235 the image. I believe it's looking better if we do
2236 nothing here for mouse-face. */
2237 if (s
->hl
== DRAW_CURSOR
)
2239 int r
= s
->img
->relief
;
2241 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2243 s
->slice
.width
+ r
*2 - 1,
2244 s
->slice
.height
+ r
*2 - 1);
2249 /* Draw a rectangle if image could not be loaded. */
2250 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2251 s
->slice
.width
- 1, s
->slice
.height
- 1);
2255 /* Draw a relief around the image glyph string S. */
2258 x_draw_image_relief (s
)
2259 struct glyph_string
*s
;
2261 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2264 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2266 /* If first glyph of S has a left box line, start drawing it to the
2267 right of that line. */
2268 if (s
->face
->box
!= FACE_NO_BOX
2269 && s
->first_glyph
->left_box_line_p
2271 x
+= abs (s
->face
->box_line_width
);
2273 /* If there is a margin around the image, adjust x- and y-position
2275 if (s
->slice
.x
== 0)
2276 x
+= s
->img
->hmargin
;
2277 if (s
->slice
.y
== 0)
2278 y
+= s
->img
->vmargin
;
2280 if (s
->hl
== DRAW_IMAGE_SUNKEN
2281 || s
->hl
== DRAW_IMAGE_RAISED
)
2283 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2284 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2288 thick
= abs (s
->img
->relief
);
2289 raised_p
= s
->img
->relief
> 0;
2294 x1
= x
+ s
->slice
.width
+ thick
- 1;
2295 y1
= y
+ s
->slice
.height
+ thick
- 1;
2297 x_setup_relief_colors (s
);
2298 get_glyph_string_clip_rect (s
, &r
);
2299 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2301 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2303 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2308 /* Draw the foreground of image glyph string S to PIXMAP. */
2311 x_draw_image_foreground_1 (s
, pixmap
)
2312 struct glyph_string
*s
;
2316 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2318 /* If first glyph of S has a left box line, start drawing it to the
2319 right of that line. */
2320 if (s
->face
->box
!= FACE_NO_BOX
2321 && s
->first_glyph
->left_box_line_p
2323 x
+= abs (s
->face
->box_line_width
);
2325 /* If there is a margin around the image, adjust x- and y-position
2327 if (s
->slice
.x
== 0)
2328 x
+= s
->img
->hmargin
;
2329 if (s
->slice
.y
== 0)
2330 y
+= s
->img
->vmargin
;
2336 /* We can't set both a clip mask and use XSetClipRectangles
2337 because the latter also sets a clip mask. We also can't
2338 trust on the shape extension to be available
2339 (XShapeCombineRegion). So, compute the rectangle to draw
2341 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2345 xgcv
.clip_mask
= s
->img
->mask
;
2346 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2347 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2348 xgcv
.function
= GXcopy
;
2349 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2351 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2352 s
->slice
.x
, s
->slice
.y
,
2353 s
->slice
.width
, s
->slice
.height
, x
, y
);
2354 XSetClipMask (s
->display
, s
->gc
, None
);
2358 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2359 s
->slice
.x
, s
->slice
.y
,
2360 s
->slice
.width
, s
->slice
.height
, x
, y
);
2362 /* When the image has a mask, we can expect that at
2363 least part of a mouse highlight or a block cursor will
2364 be visible. If the image doesn't have a mask, make
2365 a block cursor visible by drawing a rectangle around
2366 the image. I believe it's looking better if we do
2367 nothing here for mouse-face. */
2368 if (s
->hl
== DRAW_CURSOR
)
2370 int r
= s
->img
->relief
;
2372 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2373 s
->slice
.width
+ r
*2 - 1,
2374 s
->slice
.height
+ r
*2 - 1);
2379 /* Draw a rectangle if image could not be loaded. */
2380 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2381 s
->slice
.width
- 1, s
->slice
.height
- 1);
2385 /* Draw part of the background of glyph string S. X, Y, W, and H
2386 give the rectangle to draw. */
2389 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2390 struct glyph_string
*s
;
2395 /* Fill background with a stipple pattern. */
2396 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2397 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2398 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2401 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2405 /* Draw image glyph string S.
2408 s->x +-------------------------
2411 | +-------------------------
2414 | | +-------------------
2420 x_draw_image_glyph_string (s
)
2421 struct glyph_string
*s
;
2423 int box_line_hwidth
= abs (s
->face
->box_line_width
);
2424 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2426 Pixmap pixmap
= None
;
2429 if (s
->slice
.y
== 0)
2430 height
-= box_line_vwidth
;
2431 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2432 height
-= box_line_vwidth
;
2434 /* Fill background with face under the image. Do it only if row is
2435 taller than image or if image has a clip mask to reduce
2437 s
->stippled_p
= s
->face
->stipple
!= 0;
2438 if (height
> s
->slice
.height
2442 || s
->img
->pixmap
== 0
2443 || s
->width
!= s
->background_width
)
2447 /* Create a pixmap as large as the glyph string. Fill it
2448 with the background color. Copy the image to it, using
2449 its mask. Copy the temporary pixmap to the display. */
2450 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2451 int depth
= DefaultDepthOfScreen (screen
);
2453 /* Create a pixmap as large as the glyph string. */
2454 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2455 s
->background_width
,
2458 /* Don't clip in the following because we're working on the
2460 XSetClipMask (s
->display
, s
->gc
, None
);
2462 /* Fill the pixmap with the background color/stipple. */
2465 /* Fill background with a stipple pattern. */
2466 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2467 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2468 0, 0, s
->background_width
, s
->height
);
2469 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2474 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2476 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2477 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2478 0, 0, s
->background_width
, s
->height
);
2479 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2487 if (s
->first_glyph
->left_box_line_p
2489 x
+= box_line_hwidth
;
2491 if (s
->slice
.y
== 0)
2492 y
+= box_line_vwidth
;
2494 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2497 s
->background_filled_p
= 1;
2500 /* Draw the foreground. */
2503 x_draw_image_foreground_1 (s
, pixmap
);
2504 x_set_glyph_string_clipping (s
);
2505 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2506 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2507 XFreePixmap (s
->display
, pixmap
);
2510 x_draw_image_foreground (s
);
2512 /* If we must draw a relief around the image, do it. */
2514 || s
->hl
== DRAW_IMAGE_RAISED
2515 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2516 x_draw_image_relief (s
);
2520 /* Draw stretch glyph string S. */
2523 x_draw_stretch_glyph_string (s
)
2524 struct glyph_string
*s
;
2526 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2527 s
->stippled_p
= s
->face
->stipple
!= 0;
2529 if (s
->hl
== DRAW_CURSOR
2530 && !x_stretch_cursor_p
)
2532 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2533 as wide as the stretch glyph. */
2534 int width
, background_width
= s
->background_width
;
2535 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2539 background_width
-= left_x
- x
;
2542 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2545 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2547 /* Clear rest using the GC of the original non-cursor face. */
2548 if (width
< background_width
)
2551 int w
= background_width
- width
, h
= s
->height
;
2556 if (s
->row
->mouse_face_p
2557 && cursor_in_mouse_face_p (s
->w
))
2559 x_set_mouse_face_gc (s
);
2565 get_glyph_string_clip_rect (s
, &r
);
2566 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2568 if (s
->face
->stipple
)
2570 /* Fill background with a stipple pattern. */
2571 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2572 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2573 XSetFillStyle (s
->display
, gc
, FillSolid
);
2578 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2579 XSetForeground (s
->display
, gc
, xgcv
.background
);
2580 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2581 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2585 else if (!s
->background_filled_p
)
2587 int background_width
= s
->background_width
;
2588 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2592 background_width
-= left_x
- x
;
2595 if (background_width
> 0)
2596 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2599 s
->background_filled_p
= 1;
2603 /* Draw glyph string S. */
2606 x_draw_glyph_string (s
)
2607 struct glyph_string
*s
;
2609 int relief_drawn_p
= 0;
2611 /* If S draws into the background of its successor, draw the
2612 background of the successor first so that S can draw into it.
2613 This makes S->next use XDrawString instead of XDrawImageString. */
2614 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2616 xassert (s
->next
->img
== NULL
);
2617 x_set_glyph_string_gc (s
->next
);
2618 x_set_glyph_string_clipping (s
->next
);
2619 x_draw_glyph_string_background (s
->next
, 1);
2622 /* Set up S->gc, set clipping and draw S. */
2623 x_set_glyph_string_gc (s
);
2625 /* Draw relief (if any) in advance for char/composition so that the
2626 glyph string can be drawn over it. */
2627 if (!s
->for_overlaps
2628 && s
->face
->box
!= FACE_NO_BOX
2629 && (s
->first_glyph
->type
== CHAR_GLYPH
2630 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2633 x_set_glyph_string_clipping (s
);
2634 x_draw_glyph_string_background (s
, 1);
2635 x_draw_glyph_string_box (s
);
2636 x_set_glyph_string_clipping (s
);
2640 x_set_glyph_string_clipping (s
);
2642 switch (s
->first_glyph
->type
)
2645 x_draw_image_glyph_string (s
);
2649 x_draw_stretch_glyph_string (s
);
2653 if (s
->for_overlaps
)
2654 s
->background_filled_p
= 1;
2656 x_draw_glyph_string_background (s
, 0);
2657 x_draw_glyph_string_foreground (s
);
2660 case COMPOSITE_GLYPH
:
2661 if (s
->for_overlaps
|| s
->gidx
> 0)
2662 s
->background_filled_p
= 1;
2664 x_draw_glyph_string_background (s
, 1);
2665 x_draw_composite_glyph_string_foreground (s
);
2672 if (!s
->for_overlaps
)
2674 /* Draw underline. */
2675 if (s
->face
->underline_p
)
2677 unsigned long tem
, h
;
2680 /* Get the underline thickness. Default is 1 pixel. */
2681 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
2684 /* Get the underline position. This is the recommended
2685 vertical offset in pixels from the baseline to the top of
2686 the underline. This is a signed value according to the
2687 specs, and its default is
2689 ROUND ((maximum descent) / 2), with
2690 ROUND(x) = floor (x + 0.5) */
2692 if (x_use_underline_position_properties
2693 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
2694 y
= s
->ybase
+ (long) tem
;
2695 else if (s
->face
->font
)
2696 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2698 y
= s
->y
+ s
->height
- h
;
2700 if (s
->face
->underline_defaulted_p
)
2701 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2702 s
->x
, y
, s
->width
, h
);
2706 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2707 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2708 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2709 s
->x
, y
, s
->width
, h
);
2710 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2714 /* Draw overline. */
2715 if (s
->face
->overline_p
)
2717 unsigned long dy
= 0, h
= 1;
2719 if (s
->face
->overline_color_defaulted_p
)
2720 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2725 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2726 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2727 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2729 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2733 /* Draw strike-through. */
2734 if (s
->face
->strike_through_p
)
2736 unsigned long h
= 1;
2737 unsigned long dy
= (s
->height
- h
) / 2;
2739 if (s
->face
->strike_through_color_defaulted_p
)
2740 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2745 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2746 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2747 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2749 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2753 /* Draw relief if not yet drawn. */
2754 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2755 x_draw_glyph_string_box (s
);
2758 /* Reset clipping. */
2759 XSetClipMask (s
->display
, s
->gc
, None
);
2762 /* Shift display to make room for inserted glyphs. */
2765 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2767 int x
, y
, width
, height
, shift_by
;
2769 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2770 f
->output_data
.x
->normal_gc
,
2771 x
, y
, width
, height
,
2775 /* Delete N glyphs at the nominal cursor position. Not implemented
2786 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2787 If they are <= 0, this is probably an error. */
2790 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
2797 xassert (width
> 0 && height
> 0);
2798 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2802 /* Clear entire frame. If updating_frame is non-null, clear that
2803 frame. Otherwise clear the selected frame. */
2813 f
= SELECTED_FRAME ();
2815 /* Clearing the frame will erase any cursor, so mark them all as no
2817 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2818 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2819 output_cursor
.x
= -1;
2821 /* We don't set the output cursor here because there will always
2822 follow an explicit cursor_to. */
2824 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2826 /* We have to clear the scroll bars, too. If we have changed
2827 colors or something like that, then they should be notified. */
2828 x_scroll_bar_clear (f
);
2830 XFlush (FRAME_X_DISPLAY (f
));
2837 /* Invert the middle quarter of the frame for .15 sec. */
2839 /* We use the select system call to do the waiting, so we have to make
2840 sure it's available. If it isn't, we just won't do visual bells. */
2842 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2845 /* Subtract the `struct timeval' values X and Y, storing the result in
2846 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2849 timeval_subtract (result
, x
, y
)
2850 struct timeval
*result
, x
, y
;
2852 /* Perform the carry for the later subtraction by updating y. This
2853 is safer because on some systems the tv_sec member is unsigned. */
2854 if (x
.tv_usec
< y
.tv_usec
)
2856 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2857 y
.tv_usec
-= 1000000 * nsec
;
2861 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2863 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2864 y
.tv_usec
+= 1000000 * nsec
;
2868 /* Compute the time remaining to wait. tv_usec is certainly
2870 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2871 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2873 /* Return indication of whether the result should be considered
2875 return x
.tv_sec
< y
.tv_sec
;
2887 /* Create a GC that will use the GXxor function to flip foreground
2888 pixels into background pixels. */
2892 values
.function
= GXxor
;
2893 values
.foreground
= (f
->output_data
.x
->foreground_pixel
2894 ^ f
->output_data
.x
->background_pixel
);
2896 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2897 GCFunction
| GCForeground
, &values
);
2901 /* Get the height not including a menu bar widget. */
2902 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
2903 /* Height of each line to flash. */
2904 int flash_height
= FRAME_LINE_HEIGHT (f
);
2905 /* These will be the left and right margins of the rectangles. */
2906 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2907 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
2911 /* Don't flash the area between a scroll bar and the frame
2912 edge it is next to. */
2913 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
2915 case vertical_scroll_bar_left
:
2916 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2919 case vertical_scroll_bar_right
:
2920 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2927 width
= flash_right
- flash_left
;
2929 /* If window is tall, flash top and bottom line. */
2930 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2932 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2934 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2935 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
2936 width
, flash_height
);
2937 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2939 (height
- flash_height
2940 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2941 width
, flash_height
);
2944 /* If it is short, flash it all. */
2945 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2946 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2947 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2952 struct timeval wakeup
;
2954 EMACS_GET_TIME (wakeup
);
2956 /* Compute time to wait until, propagating carry from usecs. */
2957 wakeup
.tv_usec
+= 150000;
2958 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
2959 wakeup
.tv_usec
%= 1000000;
2961 /* Keep waiting until past the time wakeup or any input gets
2963 while (! detect_input_pending ())
2965 struct timeval current
;
2966 struct timeval timeout
;
2968 EMACS_GET_TIME (current
);
2970 /* Break if result would be negative. */
2971 if (timeval_subtract (¤t
, wakeup
, current
))
2974 /* How long `select' should wait. */
2976 timeout
.tv_usec
= 10000;
2978 /* Try to wait that long--but we might wake up sooner. */
2979 select (0, NULL
, NULL
, NULL
, &timeout
);
2983 /* If window is tall, flash top and bottom line. */
2984 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2986 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2988 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2989 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
2990 width
, flash_height
);
2991 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2993 (height
- flash_height
2994 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2995 width
, flash_height
);
2998 /* If it is short, flash it all. */
2999 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3000 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3001 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3003 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3011 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3014 /* Make audible bell. */
3019 struct frame
*f
= SELECTED_FRAME ();
3021 if (FRAME_X_DISPLAY (f
))
3023 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3030 XBell (FRAME_X_DISPLAY (f
), 0);
3031 XFlush (FRAME_X_DISPLAY (f
));
3038 /* Specify how many text lines, from the top of the window,
3039 should be affected by insert-lines and delete-lines operations.
3040 This, and those operations, are used only within an update
3041 that is bounded by calls to x_update_begin and x_update_end. */
3044 XTset_terminal_window (n
)
3047 /* This function intentionally left blank. */
3052 /***********************************************************************
3054 ***********************************************************************/
3056 /* Perform an insert-lines or delete-lines operation, inserting N
3057 lines or deleting -N lines at vertical position VPOS. */
3060 x_ins_del_lines (vpos
, n
)
3067 /* Scroll part of the display as described by RUN. */
3070 x_scroll_run (w
, run
)
3074 struct frame
*f
= XFRAME (w
->frame
);
3075 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3077 /* Get frame-relative bounding box of the text display area of W,
3078 without mode lines. Include in this box the left and right
3080 window_box (w
, -1, &x
, &y
, &width
, &height
);
3082 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3083 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3084 bottom_y
= y
+ height
;
3088 /* Scrolling up. Make sure we don't copy part of the mode
3089 line at the bottom. */
3090 if (from_y
+ run
->height
> bottom_y
)
3091 height
= bottom_y
- from_y
;
3093 height
= run
->height
;
3097 /* Scolling down. Make sure we don't copy over the mode line.
3099 if (to_y
+ run
->height
> bottom_y
)
3100 height
= bottom_y
- to_y
;
3102 height
= run
->height
;
3107 /* Cursor off. Will be switched on again in x_update_window_end. */
3111 XCopyArea (FRAME_X_DISPLAY (f
),
3112 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3113 f
->output_data
.x
->normal_gc
,
3123 /***********************************************************************
3125 ***********************************************************************/
3132 /* We used to only do this if Vx_no_window_manager was non-nil, but
3133 the ICCCM (section 4.1.6) says that the window's border pixmap
3134 and border pixel are window attributes which are "private to the
3135 client", so we can always change it to whatever we want. */
3137 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3138 f
->output_data
.x
->border_pixel
);
3140 x_update_cursor (f
, 1);
3144 frame_unhighlight (f
)
3147 /* We used to only do this if Vx_no_window_manager was non-nil, but
3148 the ICCCM (section 4.1.6) says that the window's border pixmap
3149 and border pixel are window attributes which are "private to the
3150 client", so we can always change it to whatever we want. */
3152 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3153 f
->output_data
.x
->border_tile
);
3155 x_update_cursor (f
, 1);
3158 /* The focus has changed. Update the frames as necessary to reflect
3159 the new situation. Note that we can't change the selected frame
3160 here, because the Lisp code we are interrupting might become confused.
3161 Each event gets marked with the frame in which it occurred, so the
3162 Lisp code can tell when the switch took place by examining the events. */
3165 x_new_focus_frame (dpyinfo
, frame
)
3166 struct x_display_info
*dpyinfo
;
3167 struct frame
*frame
;
3169 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3171 if (frame
!= dpyinfo
->x_focus_frame
)
3173 /* Set this before calling other routines, so that they see
3174 the correct value of x_focus_frame. */
3175 dpyinfo
->x_focus_frame
= frame
;
3177 if (old_focus
&& old_focus
->auto_lower
)
3178 x_lower_frame (old_focus
);
3181 selected_frame
= frame
;
3182 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3184 Fselect_window (selected_frame
->selected_window
, Qnil
);
3185 choose_minibuf_frame ();
3188 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3189 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3191 pending_autoraise_frame
= 0;
3194 x_frame_rehighlight (dpyinfo
);
3197 /* Handle FocusIn and FocusOut state changes for FRAME.
3198 If FRAME has focus and there exists more than one frame, puts
3199 a FOCUS_IN_EVENT into *BUFP. */
3202 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
)
3205 struct x_display_info
*dpyinfo
;
3206 struct frame
*frame
;
3207 struct input_event
*bufp
;
3209 if (type
== FocusIn
)
3211 if (dpyinfo
->x_focus_event_frame
!= frame
)
3213 x_new_focus_frame (dpyinfo
, frame
);
3214 dpyinfo
->x_focus_event_frame
= frame
;
3216 /* Don't stop displaying the initial startup message
3217 for a switch-frame event we don't need. */
3218 if (GC_NILP (Vterminal_frame
)
3219 && GC_CONSP (Vframe_list
)
3220 && !GC_NILP (XCDR (Vframe_list
)))
3222 bufp
->kind
= FOCUS_IN_EVENT
;
3223 XSETFRAME (bufp
->frame_or_window
, frame
);
3227 frame
->output_data
.x
->focus_state
|= state
;
3230 if (FRAME_XIC (frame
))
3231 XSetICFocus (FRAME_XIC (frame
));
3234 else if (type
== FocusOut
)
3236 frame
->output_data
.x
->focus_state
&= ~state
;
3238 if (dpyinfo
->x_focus_event_frame
== frame
)
3240 dpyinfo
->x_focus_event_frame
= 0;
3241 x_new_focus_frame (dpyinfo
, 0);
3245 if (FRAME_XIC (frame
))
3246 XUnsetICFocus (FRAME_XIC (frame
));
3251 /* The focus may have changed. Figure out if it is a real focus change,
3252 by checking both FocusIn/Out and Enter/LeaveNotify events.
3254 Returns FOCUS_IN_EVENT event in *BUFP. */
3257 x_detect_focus_change (dpyinfo
, event
, bufp
)
3258 struct x_display_info
*dpyinfo
;
3260 struct input_event
*bufp
;
3262 struct frame
*frame
;
3264 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3268 switch (event
->type
)
3273 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3275 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3277 if (event
->xcrossing
.detail
!= NotifyInferior
3278 && event
->xcrossing
.focus
3279 && ! (focus_state
& FOCUS_EXPLICIT
))
3280 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3282 dpyinfo
, frame
, bufp
);
3288 x_focus_changed (event
->type
,
3289 (event
->xfocus
.detail
== NotifyPointer
?
3290 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3291 dpyinfo
, frame
, bufp
);
3297 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3300 x_mouse_leave (dpyinfo
)
3301 struct x_display_info
*dpyinfo
;
3303 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3306 /* The focus has changed, or we have redirected a frame's focus to
3307 another frame (this happens when a frame uses a surrogate
3308 mini-buffer frame). Shift the highlight as appropriate.
3310 The FRAME argument doesn't necessarily have anything to do with which
3311 frame is being highlighted or un-highlighted; we only use it to find
3312 the appropriate X display info. */
3315 XTframe_rehighlight (frame
)
3316 struct frame
*frame
;
3318 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3322 x_frame_rehighlight (dpyinfo
)
3323 struct x_display_info
*dpyinfo
;
3325 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3327 if (dpyinfo
->x_focus_frame
)
3329 dpyinfo
->x_highlight_frame
3330 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3331 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3332 : dpyinfo
->x_focus_frame
);
3333 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3335 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3336 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3340 dpyinfo
->x_highlight_frame
= 0;
3342 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3345 frame_unhighlight (old_highlight
);
3346 if (dpyinfo
->x_highlight_frame
)
3347 frame_highlight (dpyinfo
->x_highlight_frame
);
3353 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3355 /* Initialize mode_switch_bit and modifier_meaning. */
3357 x_find_modifier_meanings (dpyinfo
)
3358 struct x_display_info
*dpyinfo
;
3360 int min_code
, max_code
;
3363 XModifierKeymap
*mods
;
3365 dpyinfo
->meta_mod_mask
= 0;
3366 dpyinfo
->shift_lock_mask
= 0;
3367 dpyinfo
->alt_mod_mask
= 0;
3368 dpyinfo
->super_mod_mask
= 0;
3369 dpyinfo
->hyper_mod_mask
= 0;
3372 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3374 min_code
= dpyinfo
->display
->min_keycode
;
3375 max_code
= dpyinfo
->display
->max_keycode
;
3378 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3379 min_code
, max_code
- min_code
+ 1,
3381 mods
= XGetModifierMapping (dpyinfo
->display
);
3383 /* Scan the modifier table to see which modifier bits the Meta and
3384 Alt keysyms are on. */
3386 int row
, col
; /* The row and column in the modifier table. */
3387 int found_alt_or_meta
;
3389 for (row
= 3; row
< 8; row
++)
3391 found_alt_or_meta
= 0;
3392 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3394 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3396 /* Zeroes are used for filler. Skip them. */
3400 /* Are any of this keycode's keysyms a meta key? */
3404 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3406 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3412 found_alt_or_meta
= 1;
3413 dpyinfo
->meta_mod_mask
|= (1 << row
);
3418 found_alt_or_meta
= 1;
3419 dpyinfo
->alt_mod_mask
|= (1 << row
);
3424 if (!found_alt_or_meta
)
3425 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3426 code_col
= syms_per_code
;
3427 col
= mods
->max_keypermod
;
3432 if (!found_alt_or_meta
)
3433 dpyinfo
->super_mod_mask
|= (1 << row
);
3434 code_col
= syms_per_code
;
3435 col
= mods
->max_keypermod
;
3439 /* Ignore this if it's not on the lock modifier. */
3440 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3441 dpyinfo
->shift_lock_mask
= LockMask
;
3442 code_col
= syms_per_code
;
3443 col
= mods
->max_keypermod
;
3452 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3453 if (! dpyinfo
->meta_mod_mask
)
3455 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3456 dpyinfo
->alt_mod_mask
= 0;
3459 /* If some keys are both alt and meta,
3460 make them just meta, not alt. */
3461 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3463 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3466 XFree ((char *) syms
);
3467 XFreeModifiermap (mods
);
3470 /* Convert between the modifier bits X uses and the modifier bits
3474 x_x_to_emacs_modifiers (dpyinfo
, state
)
3475 struct x_display_info
*dpyinfo
;
3478 EMACS_UINT mod_meta
= meta_modifier
;
3479 EMACS_UINT mod_alt
= alt_modifier
;
3480 EMACS_UINT mod_hyper
= hyper_modifier
;
3481 EMACS_UINT mod_super
= super_modifier
;
3484 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3485 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3486 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3487 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3488 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3489 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3490 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3491 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3494 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3495 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3496 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3497 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3498 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3499 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3503 x_emacs_to_x_modifiers (dpyinfo
, state
)
3504 struct x_display_info
*dpyinfo
;
3507 EMACS_UINT mod_meta
= meta_modifier
;
3508 EMACS_UINT mod_alt
= alt_modifier
;
3509 EMACS_UINT mod_hyper
= hyper_modifier
;
3510 EMACS_UINT mod_super
= super_modifier
;
3514 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3515 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3516 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3517 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3518 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3519 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3520 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3521 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3524 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3525 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3526 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3527 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3528 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3529 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3532 /* Convert a keysym to its name. */
3535 x_get_keysym_name (keysym
)
3541 value
= XKeysymToString (keysym
);
3549 /* Mouse clicks and mouse movement. Rah. */
3551 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3553 If the event is a button press, then note that we have grabbed
3557 construct_mouse_click (result
, event
, f
)
3558 struct input_event
*result
;
3559 XButtonEvent
*event
;
3562 /* Make the event type NO_EVENT; we'll change that when we decide
3564 result
->kind
= MOUSE_CLICK_EVENT
;
3565 result
->code
= event
->button
- Button1
;
3566 result
->timestamp
= event
->time
;
3567 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3569 | (event
->type
== ButtonRelease
3573 XSETINT (result
->x
, event
->x
);
3574 XSETINT (result
->y
, event
->y
);
3575 XSETFRAME (result
->frame_or_window
, f
);
3581 /* Function to report a mouse movement to the mainstream Emacs code.
3582 The input handler calls this.
3584 We have received a mouse movement event, which is given in *event.
3585 If the mouse is over a different glyph than it was last time, tell
3586 the mainstream emacs code by setting mouse_moved. If not, ask for
3587 another motion event, so we can check again the next time it moves. */
3589 static XMotionEvent last_mouse_motion_event
;
3590 static Lisp_Object last_mouse_motion_frame
;
3593 note_mouse_movement (frame
, event
)
3595 XMotionEvent
*event
;
3597 last_mouse_movement_time
= event
->time
;
3598 last_mouse_motion_event
= *event
;
3599 XSETFRAME (last_mouse_motion_frame
, frame
);
3601 if (!FRAME_X_OUTPUT (frame
))
3604 if (event
->window
!= FRAME_X_WINDOW (frame
))
3606 frame
->mouse_moved
= 1;
3607 last_mouse_scroll_bar
= Qnil
;
3608 note_mouse_highlight (frame
, -1, -1);
3609 last_mouse_glyph_frame
= 0;
3614 /* Has the mouse moved off the glyph it was on at the last sighting? */
3615 if (frame
!= last_mouse_glyph_frame
3616 || event
->x
< last_mouse_glyph
.x
3617 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3618 || event
->y
< last_mouse_glyph
.y
3619 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3621 frame
->mouse_moved
= 1;
3622 last_mouse_scroll_bar
= Qnil
;
3623 note_mouse_highlight (frame
, event
->x
, event
->y
);
3624 /* Remember which glyph we're now on. */
3625 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3626 last_mouse_glyph_frame
= frame
;
3634 /************************************************************************
3636 ************************************************************************/
3639 redo_mouse_highlight ()
3641 if (!NILP (last_mouse_motion_frame
)
3642 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3643 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3644 last_mouse_motion_event
.x
,
3645 last_mouse_motion_event
.y
);
3650 /* Return the current position of the mouse.
3651 *FP should be a frame which indicates which display to ask about.
3653 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3654 and *PART to the frame, window, and scroll bar part that the mouse
3655 is over. Set *X and *Y to the portion and whole of the mouse's
3656 position on the scroll bar.
3658 If the mouse movement started elsewhere, set *FP to the frame the
3659 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3662 Set *TIME to the server time-stamp for the time at which the mouse
3663 was at this position.
3665 Don't store anything if we don't have a valid set of values to report.
3667 This clears the mouse_moved flag, so we can wait for the next mouse
3671 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3674 Lisp_Object
*bar_window
;
3675 enum scroll_bar_part
*part
;
3677 unsigned long *time
;
3683 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3684 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3690 Window dummy_window
;
3693 Lisp_Object frame
, tail
;
3695 /* Clear the mouse-moved flag for every frame on this display. */
3696 FOR_EACH_FRAME (tail
, frame
)
3697 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3698 XFRAME (frame
)->mouse_moved
= 0;
3700 last_mouse_scroll_bar
= Qnil
;
3702 /* Figure out which root window we're on. */
3703 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3704 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3706 /* The root window which contains the pointer. */
3709 /* Trash which we can't trust if the pointer is on
3710 a different screen. */
3713 /* The position on that root window. */
3716 /* More trash we can't trust. */
3719 /* Modifier keys and pointer buttons, about which
3721 (unsigned int *) &dummy
);
3723 /* Now we have a position on the root; find the innermost window
3724 containing the pointer. */
3728 int parent_x
= 0, parent_y
= 0;
3732 /* XTranslateCoordinates can get errors if the window
3733 structure is changing at the same time this function
3734 is running. So at least we must not crash from them. */
3736 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3738 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3739 && FRAME_LIVE_P (last_mouse_frame
))
3741 /* If mouse was grabbed on a frame, give coords for that frame
3742 even if the mouse is now outside it. */
3743 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3745 /* From-window, to-window. */
3746 root
, FRAME_X_WINDOW (last_mouse_frame
),
3748 /* From-position, to-position. */
3749 root_x
, root_y
, &win_x
, &win_y
,
3753 f1
= last_mouse_frame
;
3759 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3761 /* From-window, to-window. */
3764 /* From-position, to-position. */
3765 root_x
, root_y
, &win_x
, &win_y
,
3770 if (child
== None
|| child
== win
)
3778 /* Now we know that:
3779 win is the innermost window containing the pointer
3780 (XTC says it has no child containing the pointer),
3781 win_x and win_y are the pointer's position in it
3782 (XTC did this the last time through), and
3783 parent_x and parent_y are the pointer's position in win's parent.
3784 (They are what win_x and win_y were when win was child.
3785 If win is the root window, it has no parent, and
3786 parent_{x,y} are invalid, but that's okay, because we'll
3787 never use them in that case.) */
3789 /* Is win one of our frames? */
3790 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3792 #ifdef USE_X_TOOLKIT
3793 /* If we end up with the menu bar window, say it's not
3796 && f1
->output_data
.x
->menubar_widget
3797 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3799 #endif /* USE_X_TOOLKIT */
3802 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3805 x_uncatch_errors ();
3807 /* If not, is it one of our scroll bars? */
3810 struct scroll_bar
*bar
;
3812 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3816 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3822 if (f1
== 0 && insist
> 0)
3823 f1
= SELECTED_FRAME ();
3827 /* Ok, we found a frame. Store all the values.
3828 last_mouse_glyph is a rectangle used to reduce the
3829 generation of mouse events. To not miss any motion
3830 events, we must divide the frame into rectangles of the
3831 size of the smallest character that could be displayed
3832 on it, i.e. into the same rectangles that matrices on
3833 the frame are divided into. */
3835 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
3836 last_mouse_glyph_frame
= f1
;
3841 XSETINT (*x
, win_x
);
3842 XSETINT (*y
, win_y
);
3843 *time
= last_mouse_movement_time
;
3853 /***********************************************************************
3855 ***********************************************************************/
3857 /* Scroll bar support. */
3859 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
3861 This can be called in GC, so we have to make sure to strip off mark
3864 static struct scroll_bar
*
3865 x_window_to_scroll_bar (display
, window_id
)
3871 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3872 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
3873 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
3875 for (tail
= Vframe_list
;
3876 XGCTYPE (tail
) == Lisp_Cons
;
3879 Lisp_Object frame
, bar
, condemned
;
3881 frame
= XCAR (tail
);
3882 /* All elements of Vframe_list should be frames. */
3883 if (! GC_FRAMEP (frame
))
3886 /* Scan this frame's scroll bar list for a scroll bar with the
3888 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3889 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3890 /* This trick allows us to search both the ordinary and
3891 condemned scroll bar lists with one loop. */
3892 ! GC_NILP (bar
) || (bar
= condemned
,
3895 bar
= XSCROLL_BAR (bar
)->next
)
3896 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
&&
3897 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
3898 return XSCROLL_BAR (bar
);
3905 #if defined USE_LUCID
3907 /* Return the Lucid menu bar WINDOW is part of. Return null
3908 if WINDOW is not part of a menu bar. */
3911 x_window_to_menu_bar (window
)
3916 for (tail
= Vframe_list
;
3917 XGCTYPE (tail
) == Lisp_Cons
;
3920 Lisp_Object frame
= XCAR (tail
);
3921 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
3923 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
3930 #endif /* USE_LUCID */
3933 /************************************************************************
3935 ************************************************************************/
3937 #ifdef USE_TOOLKIT_SCROLL_BARS
3939 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
3940 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
3941 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
3942 struct scroll_bar
*));
3943 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
3947 /* Lisp window being scrolled. Set when starting to interact with
3948 a toolkit scroll bar, reset to nil when ending the interaction. */
3950 static Lisp_Object window_being_scrolled
;
3952 /* Last scroll bar part sent in xm_scroll_callback. */
3954 static int last_scroll_bar_part
;
3956 /* Whether this is an Xaw with arrow-scrollbars. This should imply
3957 that movements of 1/20 of the screen size are mapped to up/down. */
3960 /* Id of action hook installed for scroll bars. */
3962 static XtActionHookId action_hook_id
;
3964 static Boolean xaw3d_arrow_scroll
;
3966 /* Whether the drag scrolling maintains the mouse at the top of the
3967 thumb. If not, resizing the thumb needs to be done more carefully
3968 to avoid jerkyness. */
3970 static Boolean xaw3d_pick_top
;
3972 /* Action hook installed via XtAppAddActionHook when toolkit scroll
3973 bars are used.. The hook is responsible for detecting when
3974 the user ends an interaction with the scroll bar, and generates
3975 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
3978 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
3981 XtPointer client_data
;
3985 Cardinal
*num_params
;
3991 scroll_bar_p
= XmIsScrollBar (widget
);
3992 end_action
= "Release";
3993 #else /* !USE_MOTIF i.e. use Xaw */
3994 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
3995 end_action
= "EndScroll";
3996 #endif /* USE_MOTIF */
3999 && strcmp (action_name
, end_action
) == 0
4000 && WINDOWP (window_being_scrolled
))
4004 x_send_scroll_bar_event (window_being_scrolled
,
4005 scroll_bar_end_scroll
, 0, 0);
4006 w
= XWINDOW (window_being_scrolled
);
4008 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4010 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4011 /* The thumb size is incorrect while dragging: fix it. */
4012 set_vertical_scroll_bar (w
);
4014 window_being_scrolled
= Qnil
;
4015 last_scroll_bar_part
= -1;
4017 /* Xt timeouts no longer needed. */
4018 toolkit_scroll_bar_interaction
= 0;
4021 #endif /* not USE_GTK */
4023 /* A vector of windows used for communication between
4024 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4026 static struct window
**scroll_bar_windows
;
4027 static int scroll_bar_windows_size
;
4030 /* Send a client message with message type Xatom_Scrollbar for a
4031 scroll action to the frame of WINDOW. PART is a value identifying
4032 the part of the scroll bar that was clicked on. PORTION is the
4033 amount to scroll of a whole of WHOLE. */
4036 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4038 int part
, portion
, whole
;
4041 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4042 struct window
*w
= XWINDOW (window
);
4043 struct frame
*f
= XFRAME (w
->frame
);
4048 /* Construct a ClientMessage event to send to the frame. */
4049 ev
->type
= ClientMessage
;
4050 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4051 ev
->display
= FRAME_X_DISPLAY (f
);
4052 ev
->window
= FRAME_X_WINDOW (f
);
4055 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4056 not enough to store a pointer or Lisp_Object on a 64 bit system.
4057 So, store the window in scroll_bar_windows and pass the index
4058 into that array in the event. */
4059 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4060 if (scroll_bar_windows
[i
] == NULL
)
4063 if (i
== scroll_bar_windows_size
)
4065 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4066 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4067 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4069 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4071 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4072 scroll_bar_windows_size
= new_size
;
4075 scroll_bar_windows
[i
] = w
;
4076 ev
->data
.l
[0] = (long) i
;
4077 ev
->data
.l
[1] = (long) part
;
4078 ev
->data
.l
[2] = (long) 0;
4079 ev
->data
.l
[3] = (long) portion
;
4080 ev
->data
.l
[4] = (long) whole
;
4082 /* Make Xt timeouts work while the scroll bar is active. */
4083 toolkit_scroll_bar_interaction
= 1;
4085 /* Setting the event mask to zero means that the message will
4086 be sent to the client that created the window, and if that
4087 window no longer exists, no event will be sent. */
4088 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4093 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4097 x_scroll_bar_to_input_event (event
, ievent
)
4099 struct input_event
*ievent
;
4101 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4106 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4107 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4109 XSETWINDOW (window
, w
);
4110 f
= XFRAME (w
->frame
);
4112 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4113 ievent
->frame_or_window
= window
;
4116 ievent
->timestamp
= CurrentTime
;
4118 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4120 ievent
->part
= ev
->data
.l
[1];
4121 ievent
->code
= ev
->data
.l
[2];
4122 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4123 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4124 ievent
->modifiers
= 0;
4130 /* Minimum and maximum values used for Motif scroll bars. */
4132 #define XM_SB_MAX 10000000
4135 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4136 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4137 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4140 xm_scroll_callback (widget
, client_data
, call_data
)
4142 XtPointer client_data
, call_data
;
4144 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4145 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4146 int part
= -1, whole
= 0, portion
= 0;
4150 case XmCR_DECREMENT
:
4151 bar
->dragging
= Qnil
;
4152 part
= scroll_bar_up_arrow
;
4155 case XmCR_INCREMENT
:
4156 bar
->dragging
= Qnil
;
4157 part
= scroll_bar_down_arrow
;
4160 case XmCR_PAGE_DECREMENT
:
4161 bar
->dragging
= Qnil
;
4162 part
= scroll_bar_above_handle
;
4165 case XmCR_PAGE_INCREMENT
:
4166 bar
->dragging
= Qnil
;
4167 part
= scroll_bar_below_handle
;
4171 bar
->dragging
= Qnil
;
4172 part
= scroll_bar_to_top
;
4175 case XmCR_TO_BOTTOM
:
4176 bar
->dragging
= Qnil
;
4177 part
= scroll_bar_to_bottom
;
4184 /* Get the slider size. */
4186 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4189 whole
= XM_SB_MAX
- slider_size
;
4190 portion
= min (cs
->value
, whole
);
4191 part
= scroll_bar_handle
;
4192 bar
->dragging
= make_number (cs
->value
);
4196 case XmCR_VALUE_CHANGED
:
4202 window_being_scrolled
= bar
->window
;
4203 last_scroll_bar_part
= part
;
4204 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4209 #else /* !USE_MOTIF, i.e. Xaw or GTK */
4211 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4212 bar widget. DATA is a pointer to the scroll_bar structure. */
4215 xg_scroll_callback (widget
, data
)
4219 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4225 int part
= -1, whole
= 0, portion
= 0;
4226 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4228 position
= gtk_adjustment_get_value (adj
);
4230 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4233 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4235 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4241 if (xg_ignore_gtk_scrollbar
) return;
4243 diff
= (int) (position
- previous
);
4245 if (diff
== (int) adj
->step_increment
)
4247 part
= scroll_bar_down_arrow
;
4248 bar
->dragging
= Qnil
;
4250 else if (-diff
== (int) adj
->step_increment
)
4252 part
= scroll_bar_up_arrow
;
4253 bar
->dragging
= Qnil
;
4255 else if (diff
== (int) adj
->page_increment
)
4257 part
= scroll_bar_below_handle
;
4258 bar
->dragging
= Qnil
;
4260 else if (-diff
== (int) adj
->page_increment
)
4262 part
= scroll_bar_above_handle
;
4263 bar
->dragging
= Qnil
;
4267 part
= scroll_bar_handle
;
4268 whole
= adj
->upper
- adj
->page_size
;
4269 portion
= min ((int)position
, whole
);
4270 bar
->dragging
= make_number ((int)portion
);
4275 window_being_scrolled
= bar
->window
;
4276 last_scroll_bar_part
= part
;
4277 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4281 #else /* not USE_GTK */
4283 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4284 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4285 scroll bar struct. CALL_DATA is a pointer to a float saying where
4289 xaw_jump_callback (widget
, client_data
, call_data
)
4291 XtPointer client_data
, call_data
;
4293 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4294 float top
= *(float *) call_data
;
4296 int whole
, portion
, height
;
4299 /* Get the size of the thumb, a value between 0 and 1. */
4301 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4305 portion
= shown
< 1 ? top
* whole
: 0;
4307 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
4308 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4309 the bottom, so we force the scrolling whenever we see that we're
4310 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4311 we try to ensure that we always stay two pixels away from the
4313 part
= scroll_bar_down_arrow
;
4315 part
= scroll_bar_handle
;
4317 window_being_scrolled
= bar
->window
;
4318 bar
->dragging
= make_number (portion
);
4319 last_scroll_bar_part
= part
;
4320 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4324 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4325 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4326 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4327 the scroll bar. CALL_DATA is an integer specifying the action that
4328 has taken place. Its magnitude is in the range 0..height of the
4329 scroll bar. Negative values mean scroll towards buffer start.
4330 Values < height of scroll bar mean line-wise movement. */
4333 xaw_scroll_callback (widget
, client_data
, call_data
)
4335 XtPointer client_data
, call_data
;
4337 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4338 /* The position really is stored cast to a pointer. */
4339 int position
= (long) call_data
;
4343 /* Get the height of the scroll bar. */
4345 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4348 if (abs (position
) >= height
)
4349 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4351 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4352 it maps line-movement to call_data = max(5, height/20). */
4353 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
4354 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4356 part
= scroll_bar_move_ratio
;
4358 window_being_scrolled
= bar
->window
;
4359 bar
->dragging
= Qnil
;
4360 last_scroll_bar_part
= part
;
4361 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4364 #endif /* not USE_GTK */
4365 #endif /* not USE_MOTIF */
4367 #define SCROLL_BAR_NAME "verticalScrollBar"
4369 /* Create the widget for scroll bar BAR on frame F. Record the widget
4370 and X window of the scroll bar in BAR. */
4374 x_create_toolkit_scroll_bar (f
, bar
)
4376 struct scroll_bar
*bar
;
4378 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4381 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4386 #else /* not USE_GTK */
4389 x_create_toolkit_scroll_bar (f
, bar
)
4391 struct scroll_bar
*bar
;
4397 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4398 unsigned long pixel
;
4403 /* Set resources. Create the widget. */
4404 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4405 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4406 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4407 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4408 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4409 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4410 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4412 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4415 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4419 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4422 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4426 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4427 scroll_bar_name
, av
, ac
);
4429 /* Add one callback for everything that can happen. */
4430 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4432 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4434 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4436 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4438 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4440 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4442 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4445 /* Realize the widget. Only after that is the X window created. */
4446 XtRealizeWidget (widget
);
4448 /* Set the cursor to an arrow. I didn't find a resource to do that.
4449 And I'm wondering why it hasn't an arrow cursor by default. */
4450 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4451 f
->output_data
.x
->nontext_cursor
);
4453 #else /* !USE_MOTIF i.e. use Xaw */
4455 /* Set resources. Create the widget. The background of the
4456 Xaw3d scroll bar widget is a little bit light for my taste.
4457 We don't alter it here to let users change it according
4458 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4459 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4460 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4461 /* For smoother scrolling with Xaw3d -sm */
4462 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4464 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4467 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4471 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4474 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4478 /* Top/bottom shadow colors. */
4480 /* Allocate them, if necessary. */
4481 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4483 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4484 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4485 &pixel
, 1.2, 0x8000))
4487 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4489 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4491 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4492 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4493 &pixel
, 0.6, 0x4000))
4495 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4498 #ifdef XtNbeNiceToColormap
4499 /* Tell the toolkit about them. */
4500 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4501 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4502 /* We tried to allocate a color for the top/bottom shadow, and
4503 failed, so tell Xaw3d to use dithering instead. */
4505 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4509 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4510 be more consistent with other emacs 3d colors, and since Xaw3d is
4511 not good at dealing with allocation failure. */
4513 /* This tells Xaw3d to use real colors instead of dithering for
4515 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4518 /* Specify the colors. */
4519 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4522 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4525 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4528 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4534 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4535 f
->output_data
.x
->edit_widget
, av
, ac
);
4539 char *val
= initial
;
4540 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4541 #ifdef XtNarrowScrollbars
4542 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4544 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4545 if (xaw3d_arrow_scroll
|| val
== initial
)
4546 { /* ARROW_SCROLL */
4547 xaw3d_arrow_scroll
= True
;
4548 /* Isn't that just a personal preference ? --Stef */
4549 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4553 /* Define callbacks. */
4554 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4555 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4558 /* Realize the widget. Only after that is the X window created. */
4559 XtRealizeWidget (widget
);
4561 #endif /* !USE_MOTIF */
4563 /* Install an action hook that lets us detect when the user
4564 finishes interacting with a scroll bar. */
4565 if (action_hook_id
== 0)
4566 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4568 /* Remember X window and widget in the scroll bar vector. */
4569 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4570 xwindow
= XtWindow (widget
);
4571 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
4575 #endif /* not USE_GTK */
4578 /* Set the thumb size and position of scroll bar BAR. We are currently
4579 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4583 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4584 struct scroll_bar
*bar
;
4585 int portion
, position
, whole
;
4587 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4590 #else /* not USE_GTK */
4592 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4593 struct scroll_bar
*bar
;
4594 int portion
, position
, whole
;
4596 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4597 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4604 /* We use an estimate of 30 chars per line rather than the real
4605 `portion' value. This has the disadvantage that the thumb size
4606 is not very representative, but it makes our life a lot easier.
4607 Otherwise, we have to constantly adjust the thumb size, which
4608 we can't always do quickly enough: while dragging, the size of
4609 the thumb might prevent the user from dragging the thumb all the
4610 way to the end. but Motif and some versions of Xaw3d don't allow
4611 updating the thumb size while dragging. Also, even if we can update
4612 its size, the update will often happen too late.
4613 If you don't believe it, check out revision 1.650 of xterm.c to see
4614 what hoops we were going through and the still poor behavior we got. */
4615 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4616 /* When the thumb is at the bottom, position == whole.
4617 So we need to increase `whole' to make space for the thumb. */
4624 top
= (float) position
/ whole
;
4625 shown
= (float) portion
/ whole
;
4628 if (NILP (bar
->dragging
))
4632 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4633 is the scroll bar's maximum and MIN is the scroll bar's minimum
4635 size
= shown
* XM_SB_MAX
;
4636 size
= min (size
, XM_SB_MAX
);
4637 size
= max (size
, 1);
4639 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4640 value
= top
* XM_SB_MAX
;
4641 value
= min (value
, XM_SB_MAX
- size
);
4643 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4645 #else /* !USE_MOTIF i.e. use Xaw */
4651 top
= (float) position
/ whole
;
4652 shown
= (float) portion
/ whole
;
4656 float old_top
, old_shown
;
4658 XtVaGetValues (widget
,
4659 XtNtopOfThumb
, &old_top
,
4660 XtNshown
, &old_shown
,
4664 /* Massage the top+shown values. */
4665 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4666 top
= max (0, min (1, top
));
4669 /* Keep two pixels available for moving the thumb down. */
4670 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4672 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4673 check that your system's configuration file contains a define
4674 for `NARROWPROTO'. See s/freebsd.h for an example. */
4675 if (top
!= old_top
|| shown
!= old_shown
)
4677 if (NILP (bar
->dragging
))
4678 XawScrollbarSetThumb (widget
, top
, shown
);
4681 /* Try to make the scrolling a tad smoother. */
4682 if (!xaw3d_pick_top
)
4683 shown
= min (shown
, old_shown
);
4685 XawScrollbarSetThumb (widget
, top
, shown
);
4689 #endif /* !USE_MOTIF */
4693 #endif /* not USE_GTK */
4695 #endif /* USE_TOOLKIT_SCROLL_BARS */
4699 /************************************************************************
4700 Scroll bars, general
4701 ************************************************************************/
4703 /* Create a scroll bar and return the scroll bar vector for it. W is
4704 the Emacs window on which to create the scroll bar. TOP, LEFT,
4705 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4708 static struct scroll_bar
*
4709 x_scroll_bar_create (w
, top
, left
, width
, height
)
4711 int top
, left
, width
, height
;
4713 struct frame
*f
= XFRAME (w
->frame
);
4714 struct scroll_bar
*bar
4715 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4719 #ifdef USE_TOOLKIT_SCROLL_BARS
4720 x_create_toolkit_scroll_bar (f
, bar
);
4721 #else /* not USE_TOOLKIT_SCROLL_BARS */
4723 XSetWindowAttributes a
;
4727 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4728 if (a
.background_pixel
== -1)
4729 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
4731 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4732 | ButtonMotionMask
| PointerMotionHintMask
4734 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4736 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4738 /* Clear the area of W that will serve as a scroll bar. This is
4739 for the case that a window has been split horizontally. In
4740 this case, no clear_frame is generated to reduce flickering. */
4741 if (width
> 0 && height
> 0)
4742 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4744 window_box_height (w
), False
);
4746 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4747 /* Position and size of scroll bar. */
4748 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4750 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4752 /* Border width, depth, class, and visual. */
4759 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
4761 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4763 XSETWINDOW (bar
->window
, w
);
4764 XSETINT (bar
->top
, top
);
4765 XSETINT (bar
->left
, left
);
4766 XSETINT (bar
->width
, width
);
4767 XSETINT (bar
->height
, height
);
4768 XSETINT (bar
->start
, 0);
4769 XSETINT (bar
->end
, 0);
4770 bar
->dragging
= Qnil
;
4772 /* Add bar to its frame's list of scroll bars. */
4773 bar
->next
= FRAME_SCROLL_BARS (f
);
4775 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4776 if (!NILP (bar
->next
))
4777 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4779 /* Map the window/widget. */
4780 #ifdef USE_TOOLKIT_SCROLL_BARS
4783 xg_update_scrollbar_pos (f
,
4784 SCROLL_BAR_X_WINDOW (bar
),
4786 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4787 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4789 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
4790 #else /* not USE_GTK */
4791 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4792 XtConfigureWidget (scroll_bar
,
4793 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4795 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4796 max (height
, 1), 0);
4797 XtMapWidget (scroll_bar
);
4798 #endif /* not USE_GTK */
4800 #else /* not USE_TOOLKIT_SCROLL_BARS */
4801 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4802 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4809 /* Draw BAR's handle in the proper position.
4811 If the handle is already drawn from START to END, don't bother
4812 redrawing it, unless REBUILD is non-zero; in that case, always
4813 redraw it. (REBUILD is handy for drawing the handle after expose
4816 Normally, we want to constrain the start and end of the handle to
4817 fit inside its rectangle, but if the user is dragging the scroll
4818 bar handle, we want to let them drag it down all the way, so that
4819 the bar's top is as far down as it goes; otherwise, there's no way
4820 to move to the very end of the buffer. */
4822 #ifndef USE_TOOLKIT_SCROLL_BARS
4825 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4826 struct scroll_bar
*bar
;
4830 int dragging
= ! NILP (bar
->dragging
);
4831 Window w
= SCROLL_BAR_X_WINDOW (bar
);
4832 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4833 GC gc
= f
->output_data
.x
->normal_gc
;
4835 /* If the display is already accurate, do nothing. */
4837 && start
== XINT (bar
->start
)
4838 && end
== XINT (bar
->end
))
4844 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
4845 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
4846 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4848 /* Make sure the values are reasonable, and try to preserve
4849 the distance between start and end. */
4851 int length
= end
- start
;
4855 else if (start
> top_range
)
4857 end
= start
+ length
;
4861 else if (end
> top_range
&& ! dragging
)
4865 /* Store the adjusted setting in the scroll bar. */
4866 XSETINT (bar
->start
, start
);
4867 XSETINT (bar
->end
, end
);
4869 /* Clip the end position, just for display. */
4870 if (end
> top_range
)
4873 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
4874 below top positions, to make sure the handle is always at least
4875 that many pixels tall. */
4876 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4878 /* Draw the empty space above the handle. Note that we can't clear
4879 zero-height areas; that means "clear to end of window." */
4881 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4882 /* x, y, width, height, and exposures. */
4883 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4884 VERTICAL_SCROLL_BAR_TOP_BORDER
,
4885 inside_width
, start
,
4888 /* Change to proper foreground color if one is specified. */
4889 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4890 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4891 f
->output_data
.x
->scroll_bar_foreground_pixel
);
4893 /* Draw the handle itself. */
4894 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
4895 /* x, y, width, height */
4896 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4897 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
4898 inside_width
, end
- start
);
4900 /* Restore the foreground color of the GC if we changed it above. */
4901 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4902 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4903 f
->output_data
.x
->foreground_pixel
);
4905 /* Draw the empty space below the handle. Note that we can't
4906 clear zero-height areas; that means "clear to end of window." */
4907 if (end
< inside_height
)
4908 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4909 /* x, y, width, height, and exposures. */
4910 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4911 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
4912 inside_width
, inside_height
- end
,
4920 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4922 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4926 x_scroll_bar_remove (bar
)
4927 struct scroll_bar
*bar
;
4929 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4932 #ifdef USE_TOOLKIT_SCROLL_BARS
4934 xg_remove_scroll_bar (f
, SCROLL_BAR_X_WINDOW (bar
));
4935 #else /* not USE_GTK */
4936 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
4937 #endif /* not USE_GTK */
4939 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4942 /* Disassociate this scroll bar from its window. */
4943 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4949 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4950 that we are displaying PORTION characters out of a total of WHOLE
4951 characters, starting at POSITION. If WINDOW has no scroll bar,
4955 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4957 int portion
, whole
, position
;
4959 struct frame
*f
= XFRAME (w
->frame
);
4960 struct scroll_bar
*bar
;
4961 int top
, height
, left
, sb_left
, width
, sb_width
;
4962 int window_y
, window_height
;
4964 /* Get window dimensions. */
4965 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4967 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4968 height
= window_height
;
4970 /* Compute the left edge of the scroll bar area. */
4971 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4973 /* Compute the width of the scroll bar which might be less than
4974 the width of the area reserved for the scroll bar. */
4975 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4976 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
4980 /* Compute the left edge of the scroll bar. */
4981 #ifdef USE_TOOLKIT_SCROLL_BARS
4982 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4984 (WINDOW_RIGHTMOST_P (w
)
4985 ? width
- sb_width
- (width
- sb_width
) / 2
4989 (WINDOW_LEFTMOST_P (w
)
4990 ? (width
- sb_width
) / 2
4991 : width
- sb_width
));
4993 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4994 sb_left
= left
+ width
- sb_width
;
4999 /* Does the scroll bar exist yet? */
5000 if (NILP (w
->vertical_scroll_bar
))
5002 if (width
> 0 && height
> 0)
5005 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5006 left
, top
, width
, height
, False
);
5010 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5014 /* It may just need to be moved and resized. */
5015 unsigned int mask
= 0;
5017 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5021 if (sb_left
!= XINT (bar
->left
))
5023 if (top
!= XINT (bar
->top
))
5025 if (sb_width
!= XINT (bar
->width
))
5027 if (height
!= XINT (bar
->height
))
5030 #ifdef USE_TOOLKIT_SCROLL_BARS
5032 /* Move/size the scroll bar widget. */
5035 /* Since toolkit scroll bars are smaller than the space reserved
5036 for them on the frame, we have to clear "under" them. */
5037 if (width
> 0 && height
> 0)
5038 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5039 left
, top
, width
, height
, False
);
5041 xg_update_scrollbar_pos (f
,
5042 SCROLL_BAR_X_WINDOW (bar
),
5044 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5045 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5047 #else /* not USE_GTK */
5048 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5049 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5051 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5052 max (height
, 1), 0);
5053 #endif /* not USE_GTK */
5055 #else /* not USE_TOOLKIT_SCROLL_BARS */
5057 /* Clear areas not covered by the scroll bar because of
5058 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5059 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5061 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5062 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5064 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5065 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5066 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5070 /* Clear areas not covered by the scroll bar because it's not as
5071 wide as the area reserved for it. This makes sure a
5072 previous mode line display is cleared after C-x 2 C-x 1, for
5075 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5076 int rest
= area_width
- sb_width
;
5077 if (rest
> 0 && height
> 0)
5079 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5080 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5081 left
+ area_width
- rest
, top
,
5082 rest
, height
, False
);
5084 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5085 left
, top
, rest
, height
, False
);
5089 /* Move/size the scroll bar window. */
5094 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5096 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5098 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
5102 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5104 /* Remember new settings. */
5105 XSETINT (bar
->left
, sb_left
);
5106 XSETINT (bar
->top
, top
);
5107 XSETINT (bar
->width
, sb_width
);
5108 XSETINT (bar
->height
, height
);
5113 #ifdef USE_TOOLKIT_SCROLL_BARS
5114 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5115 #else /* not USE_TOOLKIT_SCROLL_BARS */
5116 /* Set the scroll bar's current state, unless we're currently being
5118 if (NILP (bar
->dragging
))
5120 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5123 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5126 int start
= ((double) position
* top_range
) / whole
;
5127 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5128 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5131 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5133 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5137 /* The following three hooks are used when we're doing a thorough
5138 redisplay of the frame. We don't explicitly know which scroll bars
5139 are going to be deleted, because keeping track of when windows go
5140 away is a real pain - "Can you say set-window-configuration, boys
5141 and girls?" Instead, we just assert at the beginning of redisplay
5142 that *all* scroll bars are to be removed, and then save a scroll bar
5143 from the fiery pit when we actually redisplay its window. */
5145 /* Arrange for all scroll bars on FRAME to be removed at the next call
5146 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5147 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5150 XTcondemn_scroll_bars (frame
)
5153 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5154 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5157 bar
= FRAME_SCROLL_BARS (frame
);
5158 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5159 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5160 XSCROLL_BAR (bar
)->prev
= Qnil
;
5161 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5162 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5163 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5168 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5169 Note that WINDOW isn't necessarily condemned at all. */
5172 XTredeem_scroll_bar (window
)
5173 struct window
*window
;
5175 struct scroll_bar
*bar
;
5178 /* We can't redeem this window's scroll bar if it doesn't have one. */
5179 if (NILP (window
->vertical_scroll_bar
))
5182 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5184 /* Unlink it from the condemned list. */
5185 f
= XFRAME (WINDOW_FRAME (window
));
5186 if (NILP (bar
->prev
))
5188 /* If the prev pointer is nil, it must be the first in one of
5190 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5191 /* It's not condemned. Everything's fine. */
5193 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5194 window
->vertical_scroll_bar
))
5195 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5197 /* If its prev pointer is nil, it must be at the front of
5198 one or the other! */
5202 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5204 if (! NILP (bar
->next
))
5205 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5207 bar
->next
= FRAME_SCROLL_BARS (f
);
5209 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5210 if (! NILP (bar
->next
))
5211 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5214 /* Remove all scroll bars on FRAME that haven't been saved since the
5215 last call to `*condemn_scroll_bars_hook'. */
5218 XTjudge_scroll_bars (f
)
5221 Lisp_Object bar
, next
;
5223 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5225 /* Clear out the condemned list now so we won't try to process any
5226 more events on the hapless scroll bars. */
5227 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5229 for (; ! NILP (bar
); bar
= next
)
5231 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5233 x_scroll_bar_remove (b
);
5236 b
->next
= b
->prev
= Qnil
;
5239 /* Now there should be no references to the condemned scroll bars,
5240 and they should get garbage-collected. */
5244 #ifndef USE_TOOLKIT_SCROLL_BARS
5245 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5246 is a no-op when using toolkit scroll bars.
5248 This may be called from a signal handler, so we have to ignore GC
5252 x_scroll_bar_expose (bar
, event
)
5253 struct scroll_bar
*bar
;
5256 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5257 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5258 GC gc
= f
->output_data
.x
->normal_gc
;
5259 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5263 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
5265 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5266 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5268 /* x, y, width, height */
5270 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
5271 XINT (bar
->height
) - 1);
5276 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5278 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5279 is set to something other than NO_EVENT, it is enqueued.
5281 This may be called from a signal handler, so we have to ignore GC
5286 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5287 struct scroll_bar
*bar
;
5289 struct input_event
*emacs_event
;
5291 if (! GC_WINDOWP (bar
->window
))
5294 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5295 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5296 emacs_event
->modifiers
5297 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5298 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5299 event
->xbutton
.state
)
5300 | (event
->type
== ButtonRelease
5303 emacs_event
->frame_or_window
= bar
->window
;
5304 emacs_event
->arg
= Qnil
;
5305 emacs_event
->timestamp
= event
->xbutton
.time
;
5308 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5310 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5313 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5314 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5317 if (y
> top_range
) y
= top_range
;
5319 if (y
< XINT (bar
->start
))
5320 emacs_event
->part
= scroll_bar_above_handle
;
5321 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5322 emacs_event
->part
= scroll_bar_handle
;
5324 emacs_event
->part
= scroll_bar_below_handle
;
5326 /* Just because the user has clicked on the handle doesn't mean
5327 they want to drag it. Lisp code needs to be able to decide
5328 whether or not we're dragging. */
5330 /* If the user has just clicked on the handle, record where they're
5332 if (event
->type
== ButtonPress
5333 && emacs_event
->part
== scroll_bar_handle
)
5334 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
5337 #ifndef USE_TOOLKIT_SCROLL_BARS
5338 /* If the user has released the handle, set it to its final position. */
5339 if (event
->type
== ButtonRelease
5340 && ! NILP (bar
->dragging
))
5342 int new_start
= y
- XINT (bar
->dragging
);
5343 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5345 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5346 bar
->dragging
= Qnil
;
5350 /* Same deal here as the other #if 0. */
5352 /* Clicks on the handle are always reported as occurring at the top of
5354 if (emacs_event
->part
== scroll_bar_handle
)
5355 emacs_event
->x
= bar
->start
;
5357 XSETINT (emacs_event
->x
, y
);
5359 XSETINT (emacs_event
->x
, y
);
5362 XSETINT (emacs_event
->y
, top_range
);
5366 #ifndef USE_TOOLKIT_SCROLL_BARS
5368 /* Handle some mouse motion while someone is dragging the scroll bar.
5370 This may be called from a signal handler, so we have to ignore GC
5374 x_scroll_bar_note_movement (bar
, event
)
5375 struct scroll_bar
*bar
;
5378 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5380 last_mouse_movement_time
= event
->xmotion
.time
;
5383 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5385 /* If we're dragging the bar, display it. */
5386 if (! GC_NILP (bar
->dragging
))
5388 /* Where should the handle be now? */
5389 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5391 if (new_start
!= XINT (bar
->start
))
5393 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5395 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5400 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5402 /* Return information to the user about the current position of the mouse
5403 on the scroll bar. */
5406 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5408 Lisp_Object
*bar_window
;
5409 enum scroll_bar_part
*part
;
5411 unsigned long *time
;
5413 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5414 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5415 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5417 Window dummy_window
;
5419 unsigned int dummy_mask
;
5423 /* Get the mouse's position relative to the scroll bar window, and
5425 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5427 /* Root, child, root x and root y. */
5428 &dummy_window
, &dummy_window
,
5429 &dummy_coord
, &dummy_coord
,
5431 /* Position relative to scroll bar. */
5434 /* Mouse buttons and modifier keys. */
5441 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5444 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5446 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5448 if (! NILP (bar
->dragging
))
5449 win_y
-= XINT (bar
->dragging
);
5453 if (win_y
> top_range
)
5457 *bar_window
= bar
->window
;
5459 if (! NILP (bar
->dragging
))
5460 *part
= scroll_bar_handle
;
5461 else if (win_y
< XINT (bar
->start
))
5462 *part
= scroll_bar_above_handle
;
5463 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5464 *part
= scroll_bar_handle
;
5466 *part
= scroll_bar_below_handle
;
5468 XSETINT (*x
, win_y
);
5469 XSETINT (*y
, top_range
);
5472 last_mouse_scroll_bar
= Qnil
;
5475 *time
= last_mouse_movement_time
;
5481 /* The screen has been cleared so we may have changed foreground or
5482 background colors, and the scroll bars may need to be redrawn.
5483 Clear out the scroll bars, and ask for expose events, so we can
5487 x_scroll_bar_clear (f
)
5490 #ifndef USE_TOOLKIT_SCROLL_BARS
5493 /* We can have scroll bars even if this is 0,
5494 if we just turned off scroll bar mode.
5495 But in that case we should not clear them. */
5496 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5497 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5498 bar
= XSCROLL_BAR (bar
)->next
)
5499 XClearArea (FRAME_X_DISPLAY (f
),
5500 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
5502 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5506 /* The main X event-reading loop - XTread_socket. */
5509 /* Time stamp of enter window event. This is only used by XTread_socket,
5510 but we have to put it out here, since static variables within functions
5511 sometimes don't work. */
5513 static Time enter_timestamp
;
5516 /* This holds the state XLookupString needs to implement dead keys
5517 and other tricks known as "compose processing". _X Window System_
5518 says that a portable program can't use this, but Stephen Gildea assures
5519 me that letting the compiler initialize it to zeros will work okay.
5521 This must be defined outside of XTread_socket, for the same reasons
5522 given for enter_timestamp, above. */
5524 static XComposeStatus compose_status
;
5526 /* Record the last 100 characters stored
5527 to help debug the loss-of-chars-during-GC problem. */
5529 static int temp_index
;
5530 static short temp_buffer
[100];
5532 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5533 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5535 temp_buffer[temp_index++] = (keysym)
5537 /* Set this to nonzero to fake an "X I/O error"
5538 on a particular display. */
5540 struct x_display_info
*XTread_socket_fake_io_error
;
5542 /* When we find no input here, we occasionally do a no-op command
5543 to verify that the X server is still running and we can still talk with it.
5544 We try all the open displays, one by one.
5545 This variable is used for cycling thru the displays. */
5547 static struct x_display_info
*next_noop_dpyinfo
;
5549 #define SET_SAVED_MENU_EVENT(size) \
5552 if (f->output_data.x->saved_menu_event == 0) \
5553 f->output_data.x->saved_menu_event \
5554 = (XEvent *) xmalloc (sizeof (XEvent)); \
5555 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5556 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5557 XSETFRAME (inev.ie.frame_or_window, f); \
5561 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5562 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5572 /* Filter events for the current X input method.
5573 DPYINFO is the display this event is for.
5574 EVENT is the X event to filter.
5576 Returns non-zero if the event was filtered, caller shall not process
5578 Returns zero if event is wasn't filtered. */
5582 x_filter_event (dpyinfo
, event
)
5583 struct x_display_info
*dpyinfo
;
5586 /* XFilterEvent returns non-zero if the input method has
5587 consumed the event. We pass the frame's X window to
5588 XFilterEvent because that's the one for which the IC
5591 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5592 event
->xclient
.window
);
5594 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5599 static int current_count
;
5600 static int current_finish
;
5601 static struct input_event
*current_hold_quit
;
5603 /* This is the filter function invoked by the GTK event loop.
5604 It is invoked before the XEvent is translated to a GdkEvent,
5605 so we have a chance to act on the event before GTK. */
5606 static GdkFilterReturn
5607 event_handler_gdk (gxev
, ev
, data
)
5612 XEvent
*xev
= (XEvent
*) gxev
;
5614 if (current_count
>= 0)
5616 struct x_display_info
*dpyinfo
;
5618 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5621 /* Filter events for the current X input method.
5622 GTK calls XFilterEvent but not for key press and release,
5623 so we do it here. */
5624 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5625 if (dpyinfo
&& x_filter_event (dpyinfo
, xev
))
5626 return GDK_FILTER_REMOVE
;
5630 current_finish
= X_EVENT_NORMAL
;
5634 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5639 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5641 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5642 return GDK_FILTER_REMOVE
;
5644 return GDK_FILTER_CONTINUE
;
5646 #endif /* USE_GTK */
5649 /* Handles the XEvent EVENT on display DPYINFO.
5651 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5652 *FINISH is zero if caller should continue reading events.
5653 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5655 We return the number of characters stored into the buffer. */
5658 handle_one_xevent (dpyinfo
, eventp
, finish
, hold_quit
)
5659 struct x_display_info
*dpyinfo
;
5662 struct input_event
*hold_quit
;
5665 struct input_event ie
;
5666 struct selection_input_event sie
;
5672 struct coding_system coding
;
5673 XEvent event
= *eventp
;
5675 *finish
= X_EVENT_NORMAL
;
5677 EVENT_INIT (inev
.ie
);
5678 inev
.ie
.kind
= NO_EVENT
;
5685 if (event
.xclient
.message_type
5686 == dpyinfo
->Xatom_wm_protocols
5687 && event
.xclient
.format
== 32)
5689 if (event
.xclient
.data
.l
[0]
5690 == dpyinfo
->Xatom_wm_take_focus
)
5692 /* Use x_any_window_to_frame because this
5693 could be the shell widget window
5694 if the frame has no title bar. */
5695 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5697 /* Not quite sure this is needed -pd */
5698 if (f
&& FRAME_XIC (f
))
5699 XSetICFocus (FRAME_XIC (f
));
5701 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5702 instructs the WM to set the input focus automatically for
5703 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5704 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5705 it has set the focus. So, XSetInputFocus below is not
5708 The call to XSetInputFocus below has also caused trouble. In
5709 cases where the XSetInputFocus done by the WM and the one
5710 below are temporally close (on a fast machine), the call
5711 below can generate additional FocusIn events which confuse
5714 /* Since we set WM_TAKE_FOCUS, we must call
5715 XSetInputFocus explicitly. But not if f is null,
5716 since that might be an event for a deleted frame. */
5719 Display
*d
= event
.xclient
.display
;
5720 /* Catch and ignore errors, in case window has been
5721 iconified by a window manager such as GWM. */
5723 XSetInputFocus (d
, event
.xclient
.window
,
5724 /* The ICCCM says this is
5725 the only valid choice. */
5727 event
.xclient
.data
.l
[1]);
5728 /* This is needed to detect the error
5729 if there is an error. */
5731 x_uncatch_errors ();
5733 /* Not certain about handling scroll bars here */
5738 if (event
.xclient
.data
.l
[0]
5739 == dpyinfo
->Xatom_wm_save_yourself
)
5741 /* Save state modify the WM_COMMAND property to
5742 something which can reinstate us. This notifies
5743 the session manager, who's looking for such a
5744 PropertyNotify. Can restart processing when
5745 a keyboard or mouse event arrives. */
5746 /* If we have a session manager, don't set this.
5747 KDE will then start two Emacsen, one for the
5748 session manager and one for this. */
5750 if (! x_session_have_connection ())
5753 f
= x_top_window_to_frame (dpyinfo
,
5754 event
.xclient
.window
);
5755 /* This is just so we only give real data once
5756 for a single Emacs process. */
5757 if (f
== SELECTED_FRAME ())
5758 XSetCommand (FRAME_X_DISPLAY (f
),
5759 event
.xclient
.window
,
5760 initial_argv
, initial_argc
);
5762 XSetCommand (FRAME_X_DISPLAY (f
),
5763 event
.xclient
.window
,
5769 if (event
.xclient
.data
.l
[0]
5770 == dpyinfo
->Xatom_wm_delete_window
)
5772 f
= x_any_window_to_frame (dpyinfo
,
5773 event
.xclient
.window
);
5775 goto OTHER
; /* May be a dialog that is to be removed */
5777 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5778 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5785 if (event
.xclient
.message_type
5786 == dpyinfo
->Xatom_wm_configure_denied
)
5791 if (event
.xclient
.message_type
5792 == dpyinfo
->Xatom_wm_window_moved
)
5795 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5797 new_x
= event
.xclient
.data
.s
[0];
5798 new_y
= event
.xclient
.data
.s
[1];
5802 f
->left_pos
= new_x
;
5809 if (event
.xclient
.message_type
5810 == dpyinfo
->Xatom_editres
)
5812 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5814 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5818 #endif /* HACK_EDITRES */
5820 if ((event
.xclient
.message_type
5821 == dpyinfo
->Xatom_DONE
)
5822 || (event
.xclient
.message_type
5823 == dpyinfo
->Xatom_PAGE
))
5825 /* Ghostview job completed. Kill it. We could
5826 reply with "Next" if we received "Page", but we
5827 currently never do because we are interested in
5828 images, only, which should have 1 page. */
5829 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5830 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5833 x_kill_gs_process (pixmap
, f
);
5834 expose_frame (f
, 0, 0, 0, 0);
5838 #ifdef USE_TOOLKIT_SCROLL_BARS
5839 /* Scroll bar callbacks send a ClientMessage from which
5840 we construct an input_event. */
5841 if (event
.xclient
.message_type
5842 == dpyinfo
->Xatom_Scrollbar
)
5844 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
5845 *finish
= X_EVENT_GOTO_OUT
;
5848 #endif /* USE_TOOLKIT_SCROLL_BARS */
5850 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5853 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
5854 *finish
= X_EVENT_DROP
;
5858 case SelectionNotify
:
5859 #ifdef USE_X_TOOLKIT
5860 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5862 #endif /* not USE_X_TOOLKIT */
5863 x_handle_selection_notify (&event
.xselection
);
5866 case SelectionClear
: /* Someone has grabbed ownership. */
5867 #ifdef USE_X_TOOLKIT
5868 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5870 #endif /* USE_X_TOOLKIT */
5872 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
5874 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
5875 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5876 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5877 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5878 inev
.ie
.frame_or_window
= Qnil
;
5882 case SelectionRequest
: /* Someone wants our selection. */
5883 #ifdef USE_X_TOOLKIT
5884 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
5886 #endif /* USE_X_TOOLKIT */
5888 XSelectionRequestEvent
*eventp
5889 = (XSelectionRequestEvent
*) &event
;
5891 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
5892 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5893 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
5894 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5895 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
5896 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
5897 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5898 inev
.ie
.frame_or_window
= Qnil
;
5902 case PropertyNotify
:
5903 #if 0 /* This is plain wrong. In the case that we are waiting for a
5904 PropertyNotify used as an ACK in incremental selection
5905 transfer, the property will be on the receiver's window. */
5906 #if defined USE_X_TOOLKIT
5907 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
5911 x_handle_property_notify (&event
.xproperty
);
5914 case ReparentNotify
:
5915 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
5919 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
5920 x_real_positions (f
, &x
, &y
);
5924 /* Perhaps reparented due to a WM restart. Reset this. */
5925 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
5930 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
5933 x_check_fullscreen (f
);
5936 /* This seems to be needed for GTK 2.6. */
5937 x_clear_area (event
.xexpose
.display
,
5938 event
.xexpose
.window
,
5939 event
.xexpose
.x
, event
.xexpose
.y
,
5940 event
.xexpose
.width
, event
.xexpose
.height
,
5943 if (f
->async_visible
== 0)
5945 f
->async_visible
= 1;
5946 f
->async_iconified
= 0;
5947 f
->output_data
.x
->has_been_visible
= 1;
5948 SET_FRAME_GARBAGED (f
);
5952 event
.xexpose
.x
, event
.xexpose
.y
,
5953 event
.xexpose
.width
, event
.xexpose
.height
);
5957 #ifndef USE_TOOLKIT_SCROLL_BARS
5958 struct scroll_bar
*bar
;
5960 #if defined USE_LUCID
5961 /* Submenus of the Lucid menu bar aren't widgets
5962 themselves, so there's no way to dispatch events
5963 to them. Recognize this case separately. */
5966 = x_window_to_menu_bar (event
.xexpose
.window
);
5968 xlwmenu_redisplay (widget
);
5970 #endif /* USE_LUCID */
5972 #ifdef USE_TOOLKIT_SCROLL_BARS
5973 /* Dispatch event to the widget. */
5975 #else /* not USE_TOOLKIT_SCROLL_BARS */
5976 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
5977 event
.xexpose
.window
);
5980 x_scroll_bar_expose (bar
, &event
);
5981 #ifdef USE_X_TOOLKIT
5984 #endif /* USE_X_TOOLKIT */
5985 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5989 case GraphicsExpose
: /* This occurs when an XCopyArea's
5990 source area was obscured or not
5992 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
5996 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
5997 event
.xgraphicsexpose
.width
,
5998 event
.xgraphicsexpose
.height
);
6000 #ifdef USE_X_TOOLKIT
6003 #endif /* USE_X_TOOLKIT */
6006 case NoExpose
: /* This occurs when an XCopyArea's
6007 source area was completely
6012 /* Redo the mouse-highlight after the tooltip has gone. */
6013 if (event
.xmap
.window
== tip_window
)
6016 redo_mouse_highlight ();
6019 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6020 if (f
) /* F may no longer exist if
6021 the frame was deleted. */
6023 /* While a frame is unmapped, display generation is
6024 disabled; you don't want to spend time updating a
6025 display that won't ever be seen. */
6026 f
->async_visible
= 0;
6027 /* We can't distinguish, from the event, whether the window
6028 has become iconified or invisible. So assume, if it
6029 was previously visible, than now it is iconified.
6030 But x_make_frame_invisible clears both
6031 the visible flag and the iconified flag;
6032 and that way, we know the window is not iconified now. */
6033 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6035 f
->async_iconified
= 1;
6037 inev
.ie
.kind
= ICONIFY_EVENT
;
6038 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6044 if (event
.xmap
.window
== tip_window
)
6045 /* The tooltip has been drawn already. Avoid
6046 the SET_FRAME_GARBAGED below. */
6049 /* We use x_top_window_to_frame because map events can
6050 come for sub-windows and they don't mean that the
6051 frame is visible. */
6052 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6055 /* wait_reading_process_output will notice this and update
6056 the frame's display structures.
6057 If we where iconified, we should not set garbaged,
6058 because that stops redrawing on Expose events. This looks
6059 bad if we are called from a recursive event loop
6060 (x_dispatch_event), for example when a dialog is up. */
6061 if (! f
->async_iconified
)
6062 SET_FRAME_GARBAGED (f
);
6064 f
->async_visible
= 1;
6065 f
->async_iconified
= 0;
6066 f
->output_data
.x
->has_been_visible
= 1;
6070 inev
.ie
.kind
= DEICONIFY_EVENT
;
6071 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6073 else if (! NILP (Vframe_list
)
6074 && ! NILP (XCDR (Vframe_list
)))
6075 /* Force a redisplay sooner or later
6076 to update the frame titles
6077 in case this is the second frame. */
6078 record_asynch_buffer_change ();
6084 ignore_next_mouse_click_timeout
= 0;
6086 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6087 /* Dispatch KeyPress events when in menu. */
6088 if (popup_activated ())
6092 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6094 /* If mouse-highlight is an integer, input clears out
6095 mouse highlighting. */
6096 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6098 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6100 clear_mouse_face (dpyinfo
);
6101 dpyinfo
->mouse_face_hidden
= 1;
6104 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6107 /* Scroll bars consume key events, but we want
6108 the keys to go to the scroll bar's frame. */
6109 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6111 if (widget
&& XmIsScrollBar (widget
))
6113 widget
= XtParent (widget
);
6114 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6117 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6121 KeySym keysym
, orig_keysym
;
6122 /* al%imercury@uunet.uu.net says that making this 81
6123 instead of 80 fixed a bug whereby meta chars made
6126 It seems that some version of XmbLookupString has
6127 a bug of not returning XBufferOverflow in
6128 status_return even if the input is too long to
6129 fit in 81 bytes. So, we must prepare sufficient
6130 bytes for copy_buffer. 513 bytes (256 chars for
6131 two-byte character set) seems to be a fairly good
6132 approximation. -- 2000.8.10 handa@etl.go.jp */
6133 unsigned char copy_buffer
[513];
6134 unsigned char *copy_bufptr
= copy_buffer
;
6135 int copy_bufsiz
= sizeof (copy_buffer
);
6137 Lisp_Object coding_system
= Qlatin_1
;
6141 /* Don't pass keys to GTK. A Tab will shift focus to the
6142 tool bar in GTK 2.4. Keys will still go to menus and
6143 dialogs because in that case popup_activated is TRUE
6145 *finish
= X_EVENT_DROP
;
6149 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6150 extra_keyboard_modifiers
);
6151 modifiers
= event
.xkey
.state
;
6153 /* This will have to go some day... */
6155 /* make_lispy_event turns chars into control chars.
6156 Don't do it here because XLookupString is too eager. */
6157 event
.xkey
.state
&= ~ControlMask
;
6158 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6159 | dpyinfo
->super_mod_mask
6160 | dpyinfo
->hyper_mod_mask
6161 | dpyinfo
->alt_mod_mask
);
6163 /* In case Meta is ComposeCharacter,
6164 clear its status. According to Markus Ehrnsperger
6165 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6166 this enables ComposeCharacter to work whether or
6167 not it is combined with Meta. */
6168 if (modifiers
& dpyinfo
->meta_mod_mask
)
6169 bzero (&compose_status
, sizeof (compose_status
));
6174 Status status_return
;
6176 coding_system
= Vlocale_coding_system
;
6177 nbytes
= XmbLookupString (FRAME_XIC (f
),
6178 &event
.xkey
, copy_bufptr
,
6179 copy_bufsiz
, &keysym
,
6181 if (status_return
== XBufferOverflow
)
6183 copy_bufsiz
= nbytes
+ 1;
6184 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6185 nbytes
= XmbLookupString (FRAME_XIC (f
),
6186 &event
.xkey
, copy_bufptr
,
6187 copy_bufsiz
, &keysym
,
6190 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6191 #if 0 && defined X_HAVE_UTF8_STRING
6192 else if (status_return
== XLookupKeySym
)
6193 { /* Try again but with utf-8. */
6194 coding_system
= Qutf_8
;
6195 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6196 &event
.xkey
, copy_bufptr
,
6197 copy_bufsiz
, &keysym
,
6199 if (status_return
== XBufferOverflow
)
6201 copy_bufsiz
= nbytes
+ 1;
6202 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6203 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6206 copy_bufsiz
, &keysym
,
6212 if (status_return
== XLookupNone
)
6214 else if (status_return
== XLookupChars
)
6219 else if (status_return
!= XLookupKeySym
6220 && status_return
!= XLookupBoth
)
6224 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6225 copy_bufsiz
, &keysym
,
6228 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6229 copy_bufsiz
, &keysym
,
6233 /* If not using XIM/XIC, and a compose sequence is in progress,
6234 we break here. Otherwise, chars_matched is always 0. */
6235 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6238 bzero (&compose_status
, sizeof (compose_status
));
6239 orig_keysym
= keysym
;
6241 /* Common for all keysym input events. */
6242 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6244 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6245 inev
.ie
.timestamp
= event
.xkey
.time
;
6247 /* First deal with keysyms which have defined
6248 translations to characters. */
6249 if (keysym
>= 32 && keysym
< 128)
6250 /* Avoid explicitly decoding each ASCII character. */
6252 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6253 inev
.ie
.code
= keysym
;
6257 /* Keysyms directly mapped to supported Unicode characters. */
6258 if ((keysym
>= 0x01000000 && keysym
<= 0x010033ff)
6259 || (keysym
>= 0x0100e000 && keysym
<= 0x0100ffff))
6261 int code
= keysym
& 0xFFFF, charset_id
, c1
, c2
;
6265 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6266 inev
.ie
.code
= code
;
6268 else if (code
< 0x100)
6271 charset_id
= CHARSET_8_BIT_CONTROL
;
6273 charset_id
= charset_latin_iso8859_1
;
6274 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6275 inev
.ie
.code
= MAKE_CHAR (charset_id
, code
, 0);
6280 charset_id
= charset_mule_unicode_0100_24ff
,
6282 else if (code
< 0xE000)
6283 charset_id
= charset_mule_unicode_2500_33ff
,
6286 charset_id
= charset_mule_unicode_e000_ffff
,
6288 c1
= (code
/ 96) + 32, c2
= (code
% 96) + 32;
6289 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6290 inev
.ie
.code
= MAKE_CHAR (charset_id
, c1
, c2
);
6295 /* Now non-ASCII. */
6296 if (HASH_TABLE_P (Vx_keysym_table
)
6297 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6301 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6302 ? ASCII_KEYSTROKE_EVENT
6303 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6304 inev
.ie
.code
= XFASTINT (c
);
6308 /* Random non-modifier sorts of keysyms. */
6309 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6310 || keysym
== XK_Delete
6311 #ifdef XK_ISO_Left_Tab
6312 || (keysym
>= XK_ISO_Left_Tab
6313 && keysym
<= XK_ISO_Enter
)
6315 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6316 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6318 /* This recognizes the "extended function
6319 keys". It seems there's no cleaner way.
6320 Test IsModifierKey to avoid handling
6321 mode_switch incorrectly. */
6322 || ((unsigned) (keysym
) >= XK_Select
6323 && (unsigned)(keysym
) < XK_KP_Space
)
6325 #ifdef XK_dead_circumflex
6326 || orig_keysym
== XK_dead_circumflex
6328 #ifdef XK_dead_grave
6329 || orig_keysym
== XK_dead_grave
6331 #ifdef XK_dead_tilde
6332 || orig_keysym
== XK_dead_tilde
6334 #ifdef XK_dead_diaeresis
6335 || orig_keysym
== XK_dead_diaeresis
6337 #ifdef XK_dead_macron
6338 || orig_keysym
== XK_dead_macron
6340 #ifdef XK_dead_degree
6341 || orig_keysym
== XK_dead_degree
6343 #ifdef XK_dead_acute
6344 || orig_keysym
== XK_dead_acute
6346 #ifdef XK_dead_cedilla
6347 || orig_keysym
== XK_dead_cedilla
6349 #ifdef XK_dead_breve
6350 || orig_keysym
== XK_dead_breve
6352 #ifdef XK_dead_ogonek
6353 || orig_keysym
== XK_dead_ogonek
6355 #ifdef XK_dead_caron
6356 || orig_keysym
== XK_dead_caron
6358 #ifdef XK_dead_doubleacute
6359 || orig_keysym
== XK_dead_doubleacute
6361 #ifdef XK_dead_abovedot
6362 || orig_keysym
== XK_dead_abovedot
6364 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6365 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6366 /* Any "vendor-specific" key is ok. */
6367 || (orig_keysym
& (1 << 28))
6368 || (keysym
!= NoSymbol
&& nbytes
== 0))
6369 && ! (IsModifierKey (orig_keysym
)
6371 #ifdef XK_Mode_switch
6372 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
6375 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
6377 #endif /* not HAVE_X11R5 */
6378 /* The symbols from XK_ISO_Lock
6379 to XK_ISO_Last_Group_Lock
6380 don't have real modifiers but
6381 should be treated similarly to
6382 Mode_switch by Emacs. */
6383 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6384 || ((unsigned)(orig_keysym
)
6386 && (unsigned)(orig_keysym
)
6387 <= XK_ISO_Last_Group_Lock
)
6391 STORE_KEYSYM_FOR_DEBUG (keysym
);
6392 /* make_lispy_event will convert this to a symbolic
6394 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6395 inev
.ie
.code
= keysym
;
6399 { /* Raw bytes, not keysym. */
6404 /* The input should be decoded with `coding_system'
6405 which depends on which X*LookupString function
6406 we used just above and the locale. */
6407 setup_coding_system (coding_system
, &coding
);
6408 coding
.src_multibyte
= 0;
6409 coding
.dst_multibyte
= 1;
6410 /* The input is converted to events, thus we can't
6411 handle composition. Anyway, there's no XIM that
6412 gives us composition information. */
6413 coding
.composing
= COMPOSITION_DISABLED
;
6415 for (i
= 0; i
< nbytes
; i
++)
6417 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6421 /* Decode the input data. */
6425 require
= decoding_buffer_size (&coding
, nbytes
);
6426 p
= (unsigned char *) alloca (require
);
6427 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6428 /* We explicitly disable composition handling because
6429 key data should not contain any composition sequence. */
6430 coding
.composing
= COMPOSITION_DISABLED
;
6431 decode_coding (&coding
, copy_bufptr
, p
, nbytes
, require
);
6432 nbytes
= coding
.produced
;
6433 nchars
= coding
.produced_char
;
6437 /* Convert the input data to a sequence of
6438 character events. */
6439 for (i
= 0; i
< nbytes
; i
+= len
)
6441 if (nchars
== nbytes
)
6442 c
= copy_bufptr
[i
], len
= 1;
6444 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6446 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6447 ? ASCII_KEYSTROKE_EVENT
6448 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6450 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6453 /* Previous code updated count by nchars rather than nbytes,
6454 but that seems bogus to me. ++kfs */
6457 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6459 if (keysym
== NoSymbol
)
6465 /* Don't dispatch this event since XtDispatchEvent calls
6466 XFilterEvent, and two calls in a row may freeze the
6475 /* Don't dispatch this event since XtDispatchEvent calls
6476 XFilterEvent, and two calls in a row may freeze the
6484 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6486 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6488 if (f
&& x_mouse_click_focus_ignore_position
)
6489 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6492 if (event
.xcrossing
.focus
)
6494 /* Avoid nasty pop/raise loops. */
6495 if (f
&& (!(f
->auto_raise
)
6497 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6499 x_new_focus_frame (dpyinfo
, f
);
6500 enter_timestamp
= event
.xcrossing
.time
;
6503 else if (f
== dpyinfo
->x_focus_frame
)
6504 x_new_focus_frame (dpyinfo
, 0);
6507 /* EnterNotify counts as mouse movement,
6508 so update things that depend on mouse position. */
6509 if (f
&& !f
->output_data
.x
->hourglass_p
)
6510 note_mouse_movement (f
, &event
.xmotion
);
6512 /* We may get an EnterNotify on the buttons in the toolbar. In that
6513 case we moved out of any highlighted area and need to note this. */
6514 if (!f
&& last_mouse_glyph_frame
)
6515 note_mouse_movement (last_mouse_glyph_frame
, &event
);
6520 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6524 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6526 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6529 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6531 /* If we move outside the frame, then we're
6532 certainly no longer on any text in the frame. */
6533 clear_mouse_face (dpyinfo
);
6534 dpyinfo
->mouse_face_mouse_frame
= 0;
6537 /* Generate a nil HELP_EVENT to cancel a help-echo.
6538 Do it only if there's something to cancel.
6539 Otherwise, the startup message is cleared when
6540 the mouse leaves the frame. */
6541 if (any_help_event_p
)
6545 /* See comment in EnterNotify above */
6546 else if (last_mouse_glyph_frame
)
6547 note_mouse_movement (last_mouse_glyph_frame
, &event
);
6552 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6557 previous_help_echo_string
= help_echo_string
;
6558 help_echo_string
= Qnil
;
6560 if (dpyinfo
->grabbed
&& last_mouse_frame
6561 && FRAME_LIVE_P (last_mouse_frame
))
6562 f
= last_mouse_frame
;
6564 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6566 if (dpyinfo
->mouse_face_hidden
)
6568 dpyinfo
->mouse_face_hidden
= 0;
6569 clear_mouse_face (dpyinfo
);
6575 /* Generate SELECT_WINDOW_EVENTs when needed. */
6576 if (mouse_autoselect_window
)
6580 window
= window_from_coordinates (f
,
6581 event
.xmotion
.x
, event
.xmotion
.y
,
6584 /* Window will be selected only when it is not selected now and
6585 last mouse movement event was not in it. Minibuffer window
6586 will be selected iff it is active. */
6587 if (WINDOWP (window
)
6588 && !EQ (window
, last_window
)
6589 && !EQ (window
, selected_window
))
6591 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6592 inev
.ie
.frame_or_window
= window
;
6597 if (!note_mouse_movement (f
, &event
.xmotion
))
6598 help_echo_string
= previous_help_echo_string
;
6602 #ifndef USE_TOOLKIT_SCROLL_BARS
6603 struct scroll_bar
*bar
6604 = x_window_to_scroll_bar (event
.xmotion
.display
,
6605 event
.xmotion
.window
);
6608 x_scroll_bar_note_movement (bar
, &event
);
6609 #endif /* USE_TOOLKIT_SCROLL_BARS */
6611 /* If we move outside the frame, then we're
6612 certainly no longer on any text in the frame. */
6613 clear_mouse_face (dpyinfo
);
6616 /* If the contents of the global variable help_echo_string
6617 has changed, generate a HELP_EVENT. */
6618 if (!NILP (help_echo_string
)
6619 || !NILP (previous_help_echo_string
))
6624 case ConfigureNotify
:
6625 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6628 #ifndef USE_X_TOOLKIT
6630 xg_resize_widgets (f
, event
.xconfigure
.width
,
6631 event
.xconfigure
.height
);
6632 #else /* not USE_GTK */
6633 /* If there is a pending resize for fullscreen, don't
6634 do this one, the right one will come later.
6635 The toolkit version doesn't seem to need this, but we
6636 need to reset it below. */
6638 = ((f
->want_fullscreen
& FULLSCREEN_WAIT
)
6639 && f
->new_text_cols
!= 0);
6640 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6641 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6646 /* In the toolkit version, change_frame_size
6647 is called by the code that handles resizing
6648 of the EmacsFrame widget. */
6650 /* Even if the number of character rows and columns has
6651 not changed, the font size may have changed, so we need
6652 to check the pixel dimensions as well. */
6653 if (columns
!= FRAME_COLS (f
)
6654 || rows
!= FRAME_LINES (f
)
6655 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6656 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6658 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6659 SET_FRAME_GARBAGED (f
);
6660 cancel_mouse_face (f
);
6662 #endif /* not USE_GTK */
6665 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6666 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6669 /* GTK creates windows but doesn't map them.
6670 Only get real positions and check fullscreen when mapped. */
6671 if (FRAME_GTK_OUTER_WIDGET (f
)
6672 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
6675 /* What we have now is the position of Emacs's own window.
6676 Convert that to the position of the window manager window. */
6677 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6679 x_check_expected_move (f
);
6680 if (f
->want_fullscreen
& FULLSCREEN_WAIT
)
6681 f
->want_fullscreen
&= ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
6685 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6686 xic_set_statusarea (f
);
6689 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
6691 /* Since the WM decorations come below top_pos now,
6692 we must put them below top_pos in the future. */
6693 f
->win_gravity
= NorthWestGravity
;
6694 x_wm_set_size_hint (f
, (long) 0, 0);
6702 /* If we decide we want to generate an event to be seen
6703 by the rest of Emacs, we put it here. */
6706 bzero (&compose_status
, sizeof (compose_status
));
6707 last_mouse_glyph_frame
= 0;
6709 if (dpyinfo
->grabbed
6711 && FRAME_LIVE_P (last_mouse_frame
))
6712 f
= last_mouse_frame
;
6714 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6718 /* Is this in the tool-bar? */
6719 if (WINDOWP (f
->tool_bar_window
)
6720 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6723 int x
= event
.xbutton
.x
;
6724 int y
= event
.xbutton
.y
;
6726 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6727 if (EQ (window
, f
->tool_bar_window
))
6729 if (event
.xbutton
.type
== ButtonPress
)
6730 handle_tool_bar_click (f
, x
, y
, 1, 0);
6732 handle_tool_bar_click (f
, x
, y
, 0,
6733 x_x_to_emacs_modifiers (dpyinfo
,
6734 event
.xbutton
.state
));
6740 if (!dpyinfo
->x_focus_frame
6741 || f
== dpyinfo
->x_focus_frame
)
6743 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6744 if (! popup_activated ())
6747 if (ignore_next_mouse_click_timeout
)
6749 if (event
.type
== ButtonPress
6750 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6752 ignore_next_mouse_click_timeout
= 0;
6753 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6755 if (event
.type
== ButtonRelease
)
6756 ignore_next_mouse_click_timeout
= 0;
6759 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6765 struct scroll_bar
*bar
6766 = x_window_to_scroll_bar (event
.xbutton
.display
,
6767 event
.xbutton
.window
);
6769 #ifdef USE_TOOLKIT_SCROLL_BARS
6770 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6772 if (bar
&& event
.xbutton
.state
& ControlMask
)
6774 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6775 *finish
= X_EVENT_DROP
;
6777 #else /* not USE_TOOLKIT_SCROLL_BARS */
6779 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6780 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6783 if (event
.type
== ButtonPress
)
6785 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6786 last_mouse_frame
= f
;
6789 last_tool_bar_item
= -1;
6792 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6794 /* Ignore any mouse motion that happened before this event;
6795 any subsequent mouse-movement Emacs events should reflect
6796 only motion after the ButtonPress/Release. */
6800 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6801 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6802 /* For a down-event in the menu bar,
6803 don't pass it to Xt right now.
6804 Instead, save it away
6805 and we will pass it to Xt from kbd_buffer_get_event.
6806 That way, we can run some Lisp code first. */
6809 ! popup_activated ()
6812 f
&& event
.type
== ButtonPress
6813 /* Verify the event is really within the menu bar
6814 and not just sent to it due to grabbing. */
6815 && event
.xbutton
.x
>= 0
6816 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6817 && event
.xbutton
.y
>= 0
6818 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6819 && event
.xbutton
.same_screen
)
6821 SET_SAVED_BUTTON_EVENT
;
6822 XSETFRAME (last_mouse_press_frame
, f
);
6824 *finish
= X_EVENT_DROP
;
6827 else if (event
.type
== ButtonPress
)
6829 last_mouse_press_frame
= Qnil
;
6833 #ifdef USE_MOTIF /* This should do not harm for Lucid,
6834 but I am trying to be cautious. */
6835 else if (event
.type
== ButtonRelease
)
6837 if (!NILP (last_mouse_press_frame
))
6839 f
= XFRAME (last_mouse_press_frame
);
6840 if (f
->output_data
.x
)
6841 SET_SAVED_BUTTON_EVENT
;
6846 #endif /* USE_MOTIF */
6849 #endif /* USE_X_TOOLKIT || USE_GTK */
6853 case CirculateNotify
:
6856 case CirculateRequest
:
6859 case VisibilityNotify
:
6863 /* Someone has changed the keyboard mapping - update the
6865 switch (event
.xmapping
.request
)
6867 case MappingModifier
:
6868 x_find_modifier_meanings (dpyinfo
);
6869 /* This is meant to fall through. */
6870 case MappingKeyboard
:
6871 XRefreshKeyboardMapping (&event
.xmapping
);
6877 #ifdef USE_X_TOOLKIT
6879 if (*finish
!= X_EVENT_DROP
)
6880 XtDispatchEvent (&event
);
6882 #endif /* USE_X_TOOLKIT */
6887 if (inev
.ie
.kind
!= NO_EVENT
)
6889 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6894 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
6899 XSETFRAME (frame
, f
);
6905 any_help_event_p
= 1;
6906 gen_help_event (help_echo_string
, frame
, help_echo_window
,
6907 help_echo_object
, help_echo_pos
);
6911 help_echo_string
= Qnil
;
6912 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
6922 /* Handles the XEvent EVENT on display DISPLAY.
6923 This is used for event loops outside the normal event handling,
6924 i.e. looping while a popup menu or a dialog is posted.
6926 Returns the value handle_one_xevent sets in the finish argument. */
6928 x_dispatch_event (event
, display
)
6932 struct x_display_info
*dpyinfo
;
6933 int finish
= X_EVENT_NORMAL
;
6935 dpyinfo
= x_display_info_for_display (display
);
6938 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
6944 /* Read events coming from the X server.
6945 This routine is called by the SIGIO handler.
6946 We return as soon as there are no more events to be read.
6948 We return the number of characters stored into the buffer,
6949 thus pretending to be `read'.
6951 EXPECTED is nonzero if the caller knows input is available. */
6954 XTread_socket (sd
, expected
, hold_quit
)
6957 struct input_event
*hold_quit
;
6961 int event_found
= 0;
6962 struct x_display_info
*dpyinfo
;
6964 if (interrupt_input_blocked
)
6966 interrupt_input_pending
= 1;
6970 interrupt_input_pending
= 0;
6973 /* So people can tell when we have read the available input. */
6974 input_signal_count
++;
6978 /* Find the display we are supposed to read input for.
6979 It's the one communicating on descriptor SD. */
6980 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
6982 #if 0 /* This ought to be unnecessary; let's verify it. */
6984 /* If available, Xlib uses FIOSNBIO to make the socket
6985 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
6986 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
6987 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
6988 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
6989 #endif /* ! defined (FIOSNBIO) */
6992 #if 0 /* This code can't be made to work, with multiple displays,
6993 and appears not to be used on any system any more.
6994 Also keyboard.c doesn't turn O_NDELAY on and off
6995 for X connections. */
6998 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7000 extern int read_alarm_should_throw
;
7001 read_alarm_should_throw
= 1;
7002 XPeekEvent (dpyinfo
->display
, &event
);
7003 read_alarm_should_throw
= 0;
7005 #endif /* HAVE_SELECT */
7009 /* For debugging, this gives a way to fake an I/O error. */
7010 if (dpyinfo
== XTread_socket_fake_io_error
)
7012 XTread_socket_fake_io_error
= 0;
7013 x_io_error_quitter (dpyinfo
->display
);
7018 struct input_event inev
;
7020 /* We don't need to EVENT_INIT (inev) here, as
7021 x_session_check_input copies an entire input_event. */
7022 if (x_session_check_input (&inev
))
7024 kbd_buffer_store_event_hold (&inev
, hold_quit
);
7032 while (XPending (dpyinfo
->display
))
7036 XNextEvent (dpyinfo
->display
, &event
);
7039 /* Filter events for the current X input method. */
7040 if (x_filter_event (dpyinfo
, &event
))
7045 count
+= handle_one_xevent (dpyinfo
, &event
, &finish
, hold_quit
);
7047 if (finish
== X_EVENT_GOTO_OUT
)
7050 #endif /* not USE_GTK */
7055 /* For GTK we must use the GTK event loop. But XEvents gets passed
7056 to our filter function above, and then to the big event switch.
7057 We use a bunch of globals to communicate with our filter function,
7058 that is kind of ugly, but it works.
7060 There is no way to do one display at the time, GTK just does events
7061 from all displays. */
7063 while (gtk_events_pending ())
7065 current_count
= count
;
7066 current_hold_quit
= hold_quit
;
7068 gtk_main_iteration ();
7070 count
= current_count
;
7072 current_hold_quit
= 0;
7074 if (current_finish
== X_EVENT_GOTO_OUT
)
7077 #endif /* USE_GTK */
7081 /* On some systems, an X bug causes Emacs to get no more events
7082 when the window is destroyed. Detect that. (1994.) */
7085 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7086 One XNOOP in 100 loops will make Emacs terminate.
7087 B. Bretthauer, 1994 */
7089 if (x_noop_count
>= 100)
7093 if (next_noop_dpyinfo
== 0)
7094 next_noop_dpyinfo
= x_display_list
;
7096 XNoOp (next_noop_dpyinfo
->display
);
7098 /* Each time we get here, cycle through the displays now open. */
7099 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7103 /* If the focus was just given to an auto-raising frame,
7105 /* ??? This ought to be able to handle more than one such frame. */
7106 if (pending_autoraise_frame
)
7108 x_raise_frame (pending_autoraise_frame
);
7109 pending_autoraise_frame
= 0;
7121 /***********************************************************************
7123 ***********************************************************************/
7125 /* Set clipping for output in glyph row ROW. W is the window in which
7126 we operate. GC is the graphics context to set clipping in.
7128 ROW may be a text row or, e.g., a mode line. Text rows must be
7129 clipped to the interior of the window dedicated to text display,
7130 mode lines must be clipped to the whole window. */
7133 x_clip_to_row (w
, row
, area
, gc
)
7135 struct glyph_row
*row
;
7139 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7140 XRectangle clip_rect
;
7141 int window_x
, window_y
, window_width
;
7143 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7145 clip_rect
.x
= window_x
;
7146 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7147 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7148 clip_rect
.width
= window_width
;
7149 clip_rect
.height
= row
->visible_height
;
7151 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7155 /* Draw a hollow box cursor on window W in glyph row ROW. */
7158 x_draw_hollow_cursor (w
, row
)
7160 struct glyph_row
*row
;
7162 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7163 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7164 Display
*dpy
= FRAME_X_DISPLAY (f
);
7167 struct glyph
*cursor_glyph
;
7170 /* Get the glyph the cursor is on. If we can't tell because
7171 the current matrix is invalid or such, give up. */
7172 cursor_glyph
= get_phys_cursor_glyph (w
);
7173 if (cursor_glyph
== NULL
)
7176 /* Compute frame-relative coordinates for phys cursor. */
7177 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7178 wd
= w
->phys_cursor_width
;
7180 /* The foreground of cursor_gc is typically the same as the normal
7181 background color, which can cause the cursor box to be invisible. */
7182 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7183 if (dpyinfo
->scratch_cursor_gc
)
7184 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7186 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7187 GCForeground
, &xgcv
);
7188 gc
= dpyinfo
->scratch_cursor_gc
;
7190 /* Set clipping, draw the rectangle, and reset clipping again. */
7191 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7192 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7193 XSetClipMask (dpy
, gc
, None
);
7197 /* Draw a bar cursor on window W in glyph row ROW.
7199 Implementation note: One would like to draw a bar cursor with an
7200 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7201 Unfortunately, I didn't find a font yet that has this property set.
7205 x_draw_bar_cursor (w
, row
, width
, kind
)
7207 struct glyph_row
*row
;
7209 enum text_cursor_kinds kind
;
7211 struct frame
*f
= XFRAME (w
->frame
);
7212 struct glyph
*cursor_glyph
;
7214 /* If cursor is out of bounds, don't draw garbage. This can happen
7215 in mini-buffer windows when switching between echo area glyphs
7217 cursor_glyph
= get_phys_cursor_glyph (w
);
7218 if (cursor_glyph
== NULL
)
7221 /* If on an image, draw like a normal cursor. That's usually better
7222 visible than drawing a bar, esp. if the image is large so that
7223 the bar might not be in the window. */
7224 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7226 struct glyph_row
*row
;
7227 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7228 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7232 Display
*dpy
= FRAME_X_DISPLAY (f
);
7233 Window window
= FRAME_X_WINDOW (f
);
7234 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7235 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7236 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7239 /* If the glyph's background equals the color we normally draw
7240 the bar cursor in, the bar cursor in its normal color is
7241 invisible. Use the glyph's foreground color instead in this
7242 case, on the assumption that the glyph's colors are chosen so
7243 that the glyph is legible. */
7244 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7245 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7247 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7248 xgcv
.graphics_exposures
= 0;
7251 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7254 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7255 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7259 width
= FRAME_CURSOR_WIDTH (f
);
7260 width
= min (cursor_glyph
->pixel_width
, width
);
7262 w
->phys_cursor_width
= width
;
7263 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7265 if (kind
== BAR_CURSOR
)
7266 XFillRectangle (dpy
, window
, gc
,
7267 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7268 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7269 width
, row
->height
);
7271 XFillRectangle (dpy
, window
, gc
,
7272 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7273 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7274 row
->height
- width
),
7275 cursor_glyph
->pixel_width
,
7278 XSetClipMask (dpy
, gc
, None
);
7283 /* RIF: Define cursor CURSOR on frame F. */
7286 x_define_frame_cursor (f
, cursor
)
7290 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7294 /* RIF: Clear area on frame F. */
7297 x_clear_frame_area (f
, x
, y
, width
, height
)
7299 int x
, y
, width
, height
;
7301 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7302 x
, y
, width
, height
, False
);
7306 /* RIF: Draw cursor on window W. */
7309 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7311 struct glyph_row
*glyph_row
;
7313 int cursor_type
, cursor_width
;
7316 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7320 w
->phys_cursor_type
= cursor_type
;
7321 w
->phys_cursor_on_p
= 1;
7323 if (glyph_row
->exact_window_width_line_p
7324 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7326 glyph_row
->cursor_in_fringe_p
= 1;
7327 draw_fringe_bitmap (w
, glyph_row
, 0);
7330 switch (cursor_type
)
7332 case HOLLOW_BOX_CURSOR
:
7333 x_draw_hollow_cursor (w
, glyph_row
);
7336 case FILLED_BOX_CURSOR
:
7337 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7341 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7345 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7349 w
->phys_cursor_width
= 0;
7357 if (w
== XWINDOW (f
->selected_window
))
7358 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7359 xic_set_preeditarea (w
, x
, y
);
7364 if (updating_frame
!= f
)
7365 XFlush (FRAME_X_DISPLAY (f
));
7372 /* Make the x-window of frame F use the gnu icon bitmap. */
7375 x_bitmap_icon (f
, file
)
7381 if (FRAME_X_WINDOW (f
) == 0)
7384 /* Free up our existing icon bitmap and mask if any. */
7385 if (f
->output_data
.x
->icon_bitmap
> 0)
7386 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7387 f
->output_data
.x
->icon_bitmap
= 0;
7392 /* Use gtk_window_set_icon_from_file () if available,
7393 It's not restricted to bitmaps */
7394 if (xg_set_icon (f
, file
))
7396 #endif /* USE_GTK */
7397 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7398 x_create_bitmap_mask (f
, bitmap_id
);
7402 /* Create the GNU bitmap and mask if necessary. */
7403 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7407 #if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7409 if (xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7412 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7414 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7415 #endif /* USE_GTK */
7416 #endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
7418 /* If all else fails, use the (black and white) xbm image. */
7421 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7422 gnu_xbm_width
, gnu_xbm_height
);
7426 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7427 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7431 /* The first time we create the GNU bitmap and mask,
7432 this increments the ref-count one extra time.
7433 As a result, the GNU bitmap and mask are never freed.
7434 That way, we don't have to worry about allocating it again. */
7435 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7437 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7440 x_wm_set_icon_pixmap (f
, bitmap_id
);
7441 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7447 /* Make the x-window of frame F use a rectangle with text.
7448 Use ICON_NAME as the text. */
7451 x_text_icon (f
, icon_name
)
7455 if (FRAME_X_WINDOW (f
) == 0)
7461 text
.value
= (unsigned char *) icon_name
;
7462 text
.encoding
= XA_STRING
;
7464 text
.nitems
= strlen (icon_name
);
7465 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7467 #else /* not HAVE_X11R4 */
7468 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), icon_name
);
7469 #endif /* not HAVE_X11R4 */
7471 if (f
->output_data
.x
->icon_bitmap
> 0)
7472 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7473 f
->output_data
.x
->icon_bitmap
= 0;
7474 x_wm_set_icon_pixmap (f
, 0);
7479 #define X_ERROR_MESSAGE_SIZE 200
7481 /* If non-nil, this should be a string.
7482 It means catch X errors and store the error message in this string.
7484 The reason we use a stack is that x_catch_error/x_uncatch_error can
7485 be called from a signal handler.
7488 struct x_error_message_stack
{
7489 char string
[X_ERROR_MESSAGE_SIZE
];
7491 struct x_error_message_stack
*prev
;
7493 static struct x_error_message_stack
*x_error_message
;
7495 /* An X error handler which stores the error message in
7496 x_error_message_string. This is called from x_error_handler if
7497 x_catch_errors is in effect. */
7500 x_error_catcher (display
, error
)
7504 XGetErrorText (display
, error
->error_code
,
7505 x_error_message
->string
,
7506 X_ERROR_MESSAGE_SIZE
);
7509 /* Begin trapping X errors for display DPY. Actually we trap X errors
7510 for all displays, but DPY should be the display you are actually
7513 After calling this function, X protocol errors no longer cause
7514 Emacs to exit; instead, they are recorded in the string
7515 stored in x_error_message_string.
7517 Calling x_check_errors signals an Emacs error if an X error has
7518 occurred since the last call to x_catch_errors or x_check_errors.
7520 Calling x_uncatch_errors resumes the normal error handling. */
7522 void x_check_errors ();
7525 x_catch_errors (dpy
)
7528 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7530 /* Make sure any errors from previous requests have been dealt with. */
7534 data
->string
[0] = 0;
7535 data
->prev
= x_error_message
;
7536 x_error_message
= data
;
7539 /* Undo the last x_catch_errors call.
7540 DPY should be the display that was passed to x_catch_errors. */
7545 struct x_error_message_stack
*tmp
;
7549 /* The display may have been closed before this function is called.
7550 Check if it is still open before calling XSync. */
7551 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7552 XSync (x_error_message
->dpy
, False
);
7554 tmp
= x_error_message
;
7555 x_error_message
= x_error_message
->prev
;
7560 /* If any X protocol errors have arrived since the last call to
7561 x_catch_errors or x_check_errors, signal an Emacs error using
7562 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7565 x_check_errors (dpy
, format
)
7569 /* Make sure to catch any errors incurred so far. */
7572 if (x_error_message
->string
[0])
7574 char string
[X_ERROR_MESSAGE_SIZE
];
7575 bcopy (x_error_message
->string
, string
, X_ERROR_MESSAGE_SIZE
);
7576 x_uncatch_errors ();
7577 error (format
, string
);
7581 /* Nonzero if we had any X protocol errors
7582 since we did x_catch_errors on DPY. */
7585 x_had_errors_p (dpy
)
7588 /* Make sure to catch any errors incurred so far. */
7591 return x_error_message
->string
[0] != 0;
7594 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7597 x_clear_errors (dpy
)
7600 x_error_message
->string
[0] = 0;
7603 /* Close off all unclosed x_catch_errors calls. */
7606 x_fully_uncatch_errors ()
7608 while (x_error_message
)
7609 x_uncatch_errors ();
7612 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7615 x_catching_errors ()
7617 return x_error_message
!= 0;
7621 static unsigned int x_wire_count
;
7624 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7629 /* Handle SIGPIPE, which can happen when the connection to a server
7630 simply goes away. SIGPIPE is handled by x_connection_signal.
7631 Don't need to do anything, because the write which caused the
7632 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7633 which will do the appropriate cleanup for us. */
7636 x_connection_signal (signalnum
) /* If we don't have an argument, */
7637 int signalnum
; /* some compilers complain in signal calls. */
7640 /* USG systems forget handlers when they are used;
7641 must reestablish each time */
7642 signal (signalnum
, x_connection_signal
);
7647 /************************************************************************
7649 ************************************************************************/
7651 /* Error message passed to x_connection_closed. */
7653 static char *error_msg
;
7655 /* Function installed as fatal_error_signal_hook in
7656 x_connection_closed. Print the X error message, and exit normally,
7657 instead of dumping core when XtCloseDisplay fails. */
7660 x_fatal_error_signal ()
7662 fprintf (stderr
, "%s\n", error_msg
);
7666 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7667 the text of an error message that lead to the connection loss. */
7670 x_connection_closed (dpy
, error_message
)
7672 char *error_message
;
7674 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7675 Lisp_Object frame
, tail
;
7677 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7678 strcpy (error_msg
, error_message
);
7679 handling_signal
= 0;
7681 /* Prevent being called recursively because of an error condition
7682 below. Otherwise, we might end up with printing ``can't find per
7683 display information'' in the recursive call instead of printing
7684 the original message here. */
7685 x_catch_errors (dpy
);
7687 /* We have to close the display to inform Xt that it doesn't
7688 exist anymore. If we don't, Xt will continue to wait for
7689 events from the display. As a consequence, a sequence of
7691 M-x make-frame-on-display RET :1 RET
7692 ...kill the new frame, so that we get an IO error...
7693 M-x make-frame-on-display RET :1 RET
7695 will indefinitely wait in Xt for events for display `:1', opened
7696 in the first class to make-frame-on-display.
7698 Closing the display is reported to lead to a bus error on
7699 OpenWindows in certain situations. I suspect that is a bug
7700 in OpenWindows. I don't know how to cicumvent it here. */
7702 #ifdef USE_X_TOOLKIT
7703 /* If DPYINFO is null, this means we didn't open the display
7704 in the first place, so don't try to close it. */
7707 extern void (*fatal_error_signal_hook
) P_ ((void));
7708 fatal_error_signal_hook
= x_fatal_error_signal
;
7709 XtCloseDisplay (dpy
);
7710 fatal_error_signal_hook
= NULL
;
7716 xg_display_close (dpyinfo
->display
);
7719 /* Indicate that this display is dead. */
7721 dpyinfo
->display
= 0;
7723 /* First delete frames whose mini-buffers are on frames
7724 that are on the dead display. */
7725 FOR_EACH_FRAME (tail
, frame
)
7727 Lisp_Object minibuf_frame
;
7729 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7730 if (FRAME_X_P (XFRAME (frame
))
7731 && FRAME_X_P (XFRAME (minibuf_frame
))
7732 && ! EQ (frame
, minibuf_frame
)
7733 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7734 Fdelete_frame (frame
, Qt
);
7737 /* Now delete all remaining frames on the dead display.
7738 We are now sure none of these is used as the mini-buffer
7739 for another frame that we need to delete. */
7740 FOR_EACH_FRAME (tail
, frame
)
7741 if (FRAME_X_P (XFRAME (frame
))
7742 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7744 /* Set this to t so that Fdelete_frame won't get confused
7745 trying to find a replacement. */
7746 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7747 Fdelete_frame (frame
, Qt
);
7751 x_delete_display (dpyinfo
);
7753 x_uncatch_errors ();
7755 if (x_display_list
== 0)
7757 fprintf (stderr
, "%s\n", error_msg
);
7758 shut_down_emacs (0, 0, Qnil
);
7762 /* Ordinary stack unwind doesn't deal with these. */
7764 sigunblock (sigmask (SIGIO
));
7766 sigunblock (sigmask (SIGALRM
));
7767 TOTALLY_UNBLOCK_INPUT
;
7769 clear_waiting_for_input ();
7770 error ("%s", error_msg
);
7773 /* We specifically use it before defining it, so that gcc doesn't inline it,
7774 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7775 static void x_error_quitter (Display
*display
, XErrorEvent
*error
);
7777 /* This is the first-level handler for X protocol errors.
7778 It calls x_error_quitter or x_error_catcher. */
7781 x_error_handler (display
, error
)
7785 if (x_error_message
)
7786 x_error_catcher (display
, error
);
7788 x_error_quitter (display
, error
);
7792 /* This is the usual handler for X protocol errors.
7793 It kills all frames on the display that we got the error for.
7794 If that was the only one, it prints an error message and kills Emacs. */
7796 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7798 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
7799 #define NO_INLINE __attribute__((noinline))
7804 /* Some versions of GNU/Linux define noinline in their headers. */
7810 /* On older GCC versions, just putting x_error_quitter
7811 after x_error_handler prevents inlining into the former. */
7813 static void NO_INLINE
7814 x_error_quitter (display
, error
)
7818 char buf
[256], buf1
[356];
7820 /* Note that there is no real way portable across R3/R4 to get the
7821 original error handler. */
7823 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7824 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7825 buf
, error
->request_code
);
7826 x_connection_closed (display
, buf1
);
7830 /* This is the handler for X IO errors, always.
7831 It kills all frames on the display that we lost touch with.
7832 If that was the only one, it prints an error message and kills Emacs. */
7835 x_io_error_quitter (display
)
7840 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7841 x_connection_closed (display
, buf
);
7845 /* Changing the font of the frame. */
7847 /* Give frame F the font named FONTNAME as its default font, and
7848 return the full name of that font. FONTNAME may be a wildcard
7849 pattern; in that case, we choose some font that fits the pattern.
7850 The return value shows which font we chose. */
7853 x_new_font (f
, fontname
)
7855 register char *fontname
;
7857 struct font_info
*fontp
7858 = FS_LOAD_FONT (f
, 0, fontname
, -1);
7863 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
7864 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
7865 FRAME_FONTSET (f
) = -1;
7867 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
7868 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
7869 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
7871 compute_fringe_widths (f
, 1);
7873 /* Compute the scroll bar width in character columns. */
7874 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7876 int wid
= FRAME_COLUMN_WIDTH (f
);
7877 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7878 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7882 int wid
= FRAME_COLUMN_WIDTH (f
);
7883 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7886 /* Now make the frame display the given font. */
7887 if (FRAME_X_WINDOW (f
) != 0)
7889 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
7890 FRAME_FONT (f
)->fid
);
7891 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
7892 FRAME_FONT (f
)->fid
);
7893 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
7894 FRAME_FONT (f
)->fid
);
7896 /* Don't change the size of a tip frame; there's no point in
7897 doing it because it's done in Fx_show_tip, and it leads to
7898 problems because the tip frame has no widget. */
7899 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7900 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7903 return build_string (fontp
->full_name
);
7906 /* Give frame F the fontset named FONTSETNAME as its default font, and
7907 return the full name of that fontset. FONTSETNAME may be a wildcard
7908 pattern; in that case, we choose some fontset that fits the pattern.
7909 The return value shows which fontset we chose. */
7912 x_new_fontset (f
, fontsetname
)
7916 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
7922 if (FRAME_FONTSET (f
) == fontset
)
7923 /* This fontset is already set in frame F. There's nothing more
7925 return fontset_name (fontset
);
7927 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
7929 if (!STRINGP (result
))
7930 /* Can't load ASCII font. */
7933 /* Since x_new_font doesn't update any fontset information, do it now. */
7934 FRAME_FONTSET (f
) = fontset
;
7938 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7939 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
7942 return build_string (fontsetname
);
7946 /***********************************************************************
7948 ***********************************************************************/
7954 /* XIM destroy callback function, which is called whenever the
7955 connection to input method XIM dies. CLIENT_DATA contains a
7956 pointer to the x_display_info structure corresponding to XIM. */
7959 xim_destroy_callback (xim
, client_data
, call_data
)
7961 XPointer client_data
;
7964 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7965 Lisp_Object frame
, tail
;
7969 /* No need to call XDestroyIC.. */
7970 FOR_EACH_FRAME (tail
, frame
)
7972 struct frame
*f
= XFRAME (frame
);
7973 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
7975 FRAME_XIC (f
) = NULL
;
7976 xic_free_xfontset (f
);
7980 /* No need to call XCloseIM. */
7981 dpyinfo
->xim
= NULL
;
7982 XFree (dpyinfo
->xim_styles
);
7986 #endif /* HAVE_X11R6 */
7989 /* This isn't prototyped in OSF 5.0 or 5.1a. */
7990 extern char *XSetIMValues
P_ ((XIM
, ...));
7993 /* Open the connection to the XIM server on display DPYINFO.
7994 RESOURCE_NAME is the resource name Emacs uses. */
7997 xim_open_dpy (dpyinfo
, resource_name
)
7998 struct x_display_info
*dpyinfo
;
7999 char *resource_name
;
8006 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8013 XIMCallback destroy
;
8016 /* Get supported styles and XIM values. */
8017 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8020 destroy
.callback
= xim_destroy_callback
;
8021 destroy
.client_data
= (XPointer
)dpyinfo
;
8022 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8028 #endif /* HAVE_XIM */
8029 dpyinfo
->xim
= NULL
;
8033 #ifdef HAVE_X11R6_XIM
8037 struct x_display_info
*dpyinfo
;
8038 char *resource_name
;
8041 /* XIM instantiate callback function, which is called whenever an XIM
8042 server is available. DISPLAY is the display of the XIM.
8043 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8044 when the callback was registered. */
8047 xim_instantiate_callback (display
, client_data
, call_data
)
8049 XPointer client_data
;
8052 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8053 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8055 /* We don't support multiple XIM connections. */
8059 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8061 /* Create XIC for the existing frames on the same display, as long
8062 as they have no XIC. */
8063 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8065 Lisp_Object tail
, frame
;
8068 FOR_EACH_FRAME (tail
, frame
)
8070 struct frame
*f
= XFRAME (frame
);
8072 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8073 if (FRAME_XIC (f
) == NULL
)
8075 create_frame_xic (f
);
8076 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8077 xic_set_statusarea (f
);
8078 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8080 struct window
*w
= XWINDOW (f
->selected_window
);
8081 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8090 #endif /* HAVE_X11R6_XIM */
8093 /* Open a connection to the XIM server on display DPYINFO.
8094 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8095 connection only at the first time. On X11R6, open the connection
8096 in the XIM instantiate callback function. */
8099 xim_initialize (dpyinfo
, resource_name
)
8100 struct x_display_info
*dpyinfo
;
8101 char *resource_name
;
8106 #ifdef HAVE_X11R6_XIM
8107 struct xim_inst_t
*xim_inst
;
8110 dpyinfo
->xim
= NULL
;
8111 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8112 xim_inst
->dpyinfo
= dpyinfo
;
8113 len
= strlen (resource_name
);
8114 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8115 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8116 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8117 resource_name
, EMACS_CLASS
,
8118 xim_instantiate_callback
,
8119 /* This is XPointer in XFree86
8120 but (XPointer *) on Tru64, at
8121 least, hence the configure test. */
8122 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8123 #else /* not HAVE_X11R6_XIM */
8124 dpyinfo
->xim
= NULL
;
8125 xim_open_dpy (dpyinfo
, resource_name
);
8126 #endif /* not HAVE_X11R6_XIM */
8130 #endif /* HAVE_XIM */
8131 dpyinfo
->xim
= NULL
;
8135 /* Close the connection to the XIM server on display DPYINFO. */
8138 xim_close_dpy (dpyinfo
)
8139 struct x_display_info
*dpyinfo
;
8144 #ifdef HAVE_X11R6_XIM
8145 if (dpyinfo
->display
)
8146 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8148 xim_instantiate_callback
, NULL
);
8149 #endif /* not HAVE_X11R6_XIM */
8150 if (dpyinfo
->display
)
8151 XCloseIM (dpyinfo
->xim
);
8152 dpyinfo
->xim
= NULL
;
8153 XFree (dpyinfo
->xim_styles
);
8155 #endif /* HAVE_XIM */
8158 #endif /* not HAVE_X11R6_XIM */
8162 /* Calculate the absolute position in frame F
8163 from its current recorded position values and gravity. */
8166 x_calc_absolute_position (f
)
8169 int flags
= f
->size_hint_flags
;
8171 /* We have nothing to do if the current position
8172 is already for the top-left corner. */
8173 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8176 /* Treat negative positions as relative to the leftmost bottommost
8177 position that fits on the screen. */
8178 if (flags
& XNegative
)
8179 f
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
8180 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
);
8183 int height
= FRAME_PIXEL_HEIGHT (f
);
8185 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8186 /* Something is fishy here. When using Motif, starting Emacs with
8187 `-g -0-0', the frame appears too low by a few pixels.
8189 This seems to be so because initially, while Emacs is starting,
8190 the column widget's height and the frame's pixel height are
8191 different. The column widget's height is the right one. In
8192 later invocations, when Emacs is up, the frame's pixel height
8195 It's not obvious where the initial small difference comes from.
8196 2000-12-01, gerd. */
8198 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8201 if (flags
& YNegative
)
8202 f
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
- height
+ f
->top_pos
);
8205 /* The left_pos and top_pos
8206 are now relative to the top and left screen edges,
8207 so the flags should correspond. */
8208 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8211 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8212 to really change the position, and 0 when calling from
8213 x_make_frame_visible (in that case, XOFF and YOFF are the current
8214 position values). It is -1 when calling from x_set_frame_parameters,
8215 which means, do adjust for borders but don't change the gravity. */
8218 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8220 register int xoff
, yoff
;
8223 int modified_top
, modified_left
;
8225 if (change_gravity
> 0)
8229 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8231 f
->size_hint_flags
|= XNegative
;
8233 f
->size_hint_flags
|= YNegative
;
8234 f
->win_gravity
= NorthWestGravity
;
8236 x_calc_absolute_position (f
);
8239 x_wm_set_size_hint (f
, (long) 0, 0);
8241 modified_left
= f
->left_pos
;
8242 modified_top
= f
->top_pos
;
8244 if (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8246 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8247 than the WM decorations. So we use the calculated offset instead
8248 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8249 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8250 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8253 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8254 modified_left
, modified_top
);
8256 if (FRAME_VISIBLE_P (f
)
8257 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
)
8259 FRAME_X_OUTPUT (f
)->check_expected_move
= 1;
8260 FRAME_X_OUTPUT (f
)->expected_top
= f
->top_pos
;
8261 FRAME_X_OUTPUT (f
)->expected_left
= f
->left_pos
;
8267 /* Check if we need to resize the frame due to a fullscreen request.
8268 If so needed, resize the frame. */
8270 x_check_fullscreen (f
)
8273 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
8275 int width
, height
, ign
;
8277 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8279 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8281 /* We do not need to move the window, it shall be taken care of
8282 when setting WM manager hints.
8283 If the frame is visible already, the position is checked by
8284 x_check_expected_move. */
8285 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8287 change_frame_size (f
, height
, width
, 0, 1, 0);
8288 SET_FRAME_GARBAGED (f
);
8289 cancel_mouse_face (f
);
8291 /* Wait for the change of frame size to occur */
8292 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
8297 /* If frame parameters are set after the frame is mapped, we need to move
8299 Some window managers moves the window to the right position, some
8300 moves the outer window manager window to the specified position.
8301 Here we check that we are in the right spot. If not, make a second
8302 move, assuming we are dealing with the second kind of window manager. */
8304 x_check_expected_move (f
)
8307 if (FRAME_X_OUTPUT (f
)->check_expected_move
)
8309 int expect_top
= FRAME_X_OUTPUT (f
)->expected_top
;
8310 int expect_left
= FRAME_X_OUTPUT (f
)->expected_left
;
8312 if (expect_top
!= f
->top_pos
|| expect_left
!= f
->left_pos
)
8314 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8315 FRAME_X_OUTPUT (f
)->move_offset_left
= expect_left
- f
->left_pos
;
8316 FRAME_X_OUTPUT (f
)->move_offset_top
= expect_top
- f
->top_pos
;
8318 f
->left_pos
= expect_left
;
8319 f
->top_pos
= expect_top
;
8320 x_set_offset (f
, expect_left
, expect_top
, 0);
8322 else if (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
)
8323 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8325 /* Just do this once */
8326 FRAME_X_OUTPUT (f
)->check_expected_move
= 0;
8331 /* Change the size of frame F's X window to COLS/ROWS in the case F
8332 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8333 top-left-corner window gravity for this size change and subsequent
8334 size changes. Otherwise we leave the window gravity unchanged. */
8337 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
8342 int pixelwidth
, pixelheight
;
8344 check_frame_size (f
, &rows
, &cols
);
8345 f
->scroll_bar_actual_width
8346 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8348 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
8349 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
8350 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
8352 compute_fringe_widths (f
, 0);
8354 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
8355 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8357 f
->win_gravity
= NorthWestGravity
;
8358 x_wm_set_size_hint (f
, (long) 0, 0);
8360 XSync (FRAME_X_DISPLAY (f
), False
);
8361 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8362 pixelwidth
, pixelheight
);
8364 /* Now, strictly speaking, we can't be sure that this is accurate,
8365 but the window manager will get around to dealing with the size
8366 change request eventually, and we'll hear how it went when the
8367 ConfigureNotify event gets here.
8369 We could just not bother storing any of this information here,
8370 and let the ConfigureNotify event set everything up, but that
8371 might be kind of confusing to the Lisp code, since size changes
8372 wouldn't be reported in the frame parameters until some random
8373 point in the future when the ConfigureNotify event arrives.
8375 We pass 1 for DELAY since we can't run Lisp code inside of
8377 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8378 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8379 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8381 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8382 receive in the ConfigureNotify event; if we get what we asked
8383 for, then the event won't cause the screen to become garbaged, so
8384 we have to make sure to do it here. */
8385 SET_FRAME_GARBAGED (f
);
8387 XFlush (FRAME_X_DISPLAY (f
));
8391 /* Call this to change the size of frame F's x-window.
8392 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8393 for this size change and subsequent size changes.
8394 Otherwise we leave the window gravity unchanged. */
8397 x_set_window_size (f
, change_gravity
, cols
, rows
)
8405 if (FRAME_GTK_WIDGET (f
))
8406 xg_frame_set_char_size (f
, cols
, rows
);
8408 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8411 if (f
->output_data
.x
->widget
!= NULL
)
8413 /* The x and y position of the widget is clobbered by the
8414 call to XtSetValues within EmacsFrameSetCharSize.
8415 This is a real kludge, but I don't understand Xt so I can't
8416 figure out a correct fix. Can anyone else tell me? -- rms. */
8417 int xpos
= f
->output_data
.x
->widget
->core
.x
;
8418 int ypos
= f
->output_data
.x
->widget
->core
.y
;
8419 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
8420 f
->output_data
.x
->widget
->core
.x
= xpos
;
8421 f
->output_data
.x
->widget
->core
.y
= ypos
;
8424 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8426 #else /* not USE_X_TOOLKIT */
8428 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8430 #endif /* not USE_X_TOOLKIT */
8432 /* If cursor was outside the new size, mark it as off. */
8433 mark_window_cursors_off (XWINDOW (f
->root_window
));
8435 /* Clear out any recollection of where the mouse highlighting was,
8436 since it might be in a place that's outside the new frame size.
8437 Actually checking whether it is outside is a pain in the neck,
8438 so don't try--just let the highlighting be done afresh with new size. */
8439 cancel_mouse_face (f
);
8444 /* Mouse warping. */
8447 x_set_mouse_position (f
, x
, y
)
8453 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8454 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8456 if (pix_x
< 0) pix_x
= 0;
8457 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8459 if (pix_y
< 0) pix_y
= 0;
8460 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8464 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8465 0, 0, 0, 0, pix_x
, pix_y
);
8469 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8472 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
8478 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8479 0, 0, 0, 0, pix_x
, pix_y
);
8483 /* focus shifting, raising and lowering. */
8486 x_focus_on_frame (f
)
8489 #if 0 /* This proves to be unpleasant. */
8493 /* I don't think that the ICCCM allows programs to do things like this
8494 without the interaction of the window manager. Whatever you end up
8495 doing with this code, do it to x_unfocus_frame too. */
8496 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8497 RevertToPointerRoot
, CurrentTime
);
8506 /* Look at the remarks in x_focus_on_frame. */
8507 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8508 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8509 RevertToPointerRoot
, CurrentTime
);
8513 /* Raise frame F. */
8519 if (f
->async_visible
)
8522 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8523 XFlush (FRAME_X_DISPLAY (f
));
8528 /* Lower frame F. */
8534 if (f
->async_visible
)
8537 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8538 XFlush (FRAME_X_DISPLAY (f
));
8544 XTframe_raise_lower (f
, raise_flag
)
8554 /* Change of visibility. */
8556 /* This tries to wait until the frame is really visible.
8557 However, if the window manager asks the user where to position
8558 the frame, this will return before the user finishes doing that.
8559 The frame will not actually be visible at that time,
8560 but it will become visible later when the window manager
8561 finishes with it. */
8564 x_make_frame_visible (f
)
8568 int original_top
, original_left
;
8569 int retry_count
= 2;
8575 type
= x_icon_type (f
);
8577 x_bitmap_icon (f
, type
);
8579 if (! FRAME_VISIBLE_P (f
))
8581 /* We test FRAME_GARBAGED_P here to make sure we don't
8582 call x_set_offset a second time
8583 if we get to x_make_frame_visible a second time
8584 before the window gets really visible. */
8585 if (! FRAME_ICONIFIED_P (f
)
8586 && ! f
->output_data
.x
->asked_for_visible
)
8587 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8589 f
->output_data
.x
->asked_for_visible
= 1;
8591 if (! EQ (Vx_no_window_manager
, Qt
))
8592 x_wm_set_window_state (f
, NormalState
);
8593 #ifdef USE_X_TOOLKIT
8594 /* This was XtPopup, but that did nothing for an iconified frame. */
8595 XtMapWidget (f
->output_data
.x
->widget
);
8596 #else /* not USE_X_TOOLKIT */
8598 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8599 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8601 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8602 #endif /* not USE_GTK */
8603 #endif /* not USE_X_TOOLKIT */
8604 #if 0 /* This seems to bring back scroll bars in the wrong places
8605 if the window configuration has changed. They seem
8606 to come back ok without this. */
8607 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8608 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8612 XFlush (FRAME_X_DISPLAY (f
));
8614 /* Synchronize to ensure Emacs knows the frame is visible
8615 before we do anything else. We do this loop with input not blocked
8616 so that incoming events are handled. */
8620 /* This must be before UNBLOCK_INPUT
8621 since events that arrive in response to the actions above
8622 will set it when they are handled. */
8623 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8625 original_left
= f
->left_pos
;
8626 original_top
= f
->top_pos
;
8628 /* This must come after we set COUNT. */
8631 /* We unblock here so that arriving X events are processed. */
8633 /* Now move the window back to where it was "supposed to be".
8634 But don't do it if the gravity is negative.
8635 When the gravity is negative, this uses a position
8636 that is 3 pixels too low. Perhaps that's really the border width.
8638 Don't do this if the window has never been visible before,
8639 because the window manager may choose the position
8640 and we don't want to override it. */
8642 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
8643 && f
->win_gravity
== NorthWestGravity
8644 && previously_visible
)
8648 unsigned int width
, height
, border
, depth
;
8652 /* On some window managers (such as FVWM) moving an existing
8653 window, even to the same place, causes the window manager
8654 to introduce an offset. This can cause the window to move
8655 to an unexpected location. Check the geometry (a little
8656 slow here) and then verify that the window is in the right
8657 place. If the window is not in the right place, move it
8658 there, and take the potential window manager hit. */
8659 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8660 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
8662 if (original_left
!= x
|| original_top
!= y
)
8663 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8664 original_left
, original_top
);
8669 XSETFRAME (frame
, f
);
8671 /* Wait until the frame is visible. Process X events until a
8672 MapNotify event has been seen, or until we think we won't get a
8673 MapNotify at all.. */
8674 for (count
= input_signal_count
+ 10;
8675 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
8677 /* Force processing of queued events. */
8680 /* Machines that do polling rather than SIGIO have been
8681 observed to go into a busy-wait here. So we'll fake an
8682 alarm signal to let the handler know that there's something
8683 to be read. We used to raise a real alarm, but it seems
8684 that the handler isn't always enabled here. This is
8686 if (input_polling_used ())
8688 /* It could be confusing if a real alarm arrives while
8689 processing the fake one. Turn it off and let the
8690 handler reset it. */
8691 extern void poll_for_input_1
P_ ((void));
8692 int old_poll_suppress_count
= poll_suppress_count
;
8693 poll_suppress_count
= 1;
8694 poll_for_input_1 ();
8695 poll_suppress_count
= old_poll_suppress_count
;
8698 /* See if a MapNotify event has been processed. */
8699 FRAME_SAMPLE_VISIBILITY (f
);
8704 (let ((f (selected-frame)))
8708 the frame is not raised with various window managers on
8709 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
8710 unknown reason, the call to XtMapWidget is completely ignored.
8711 Mapping the widget a second time works. */
8713 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
8718 /* Change from mapped state to withdrawn state. */
8720 /* Make the frame visible (mapped and not iconified). */
8723 x_make_frame_invisible (f
)
8728 /* Use the frame's outermost window, not the one we normally draw on. */
8729 window
= FRAME_OUTER_WINDOW (f
);
8731 /* Don't keep the highlight on an invisible frame. */
8732 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
8733 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
8735 #if 0/* This might add unreliability; I don't trust it -- rms. */
8736 if (! f
->async_visible
&& ! f
->async_iconified
)
8742 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
8743 that the current position of the window is user-specified, rather than
8744 program-specified, so that when the window is mapped again, it will be
8745 placed at the same location, without forcing the user to position it
8746 by hand again (they have already done that once for this window.) */
8747 x_wm_set_size_hint (f
, (long) 0, 1);
8750 if (FRAME_GTK_OUTER_WIDGET (f
))
8751 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
8757 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
8758 DefaultScreen (FRAME_X_DISPLAY (f
))))
8760 UNBLOCK_INPUT_RESIGNAL
;
8761 error ("Can't notify window manager of window withdrawal");
8763 #else /* ! defined (HAVE_X11R4) */
8765 /* Tell the window manager what we're going to do. */
8766 if (! EQ (Vx_no_window_manager
, Qt
))
8770 unmap
.xunmap
.type
= UnmapNotify
;
8771 unmap
.xunmap
.window
= window
;
8772 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
8773 unmap
.xunmap
.from_configure
= False
;
8774 if (! XSendEvent (FRAME_X_DISPLAY (f
),
8775 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
8777 SubstructureRedirectMaskSubstructureNotifyMask
,
8780 UNBLOCK_INPUT_RESIGNAL
;
8781 error ("Can't notify window manager of withdrawal");
8785 /* Unmap the window ourselves. Cheeky! */
8786 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
8787 #endif /* ! defined (HAVE_X11R4) */
8790 /* We can't distinguish this from iconification
8791 just by the event that we get from the server.
8792 So we can't win using the usual strategy of letting
8793 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
8794 and synchronize with the server to make sure we agree. */
8796 FRAME_ICONIFIED_P (f
) = 0;
8797 f
->async_visible
= 0;
8798 f
->async_iconified
= 0;
8805 /* Change window state from mapped to iconified. */
8814 /* Don't keep the highlight on an invisible frame. */
8815 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
8816 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
8818 if (f
->async_iconified
)
8823 FRAME_SAMPLE_VISIBILITY (f
);
8825 type
= x_icon_type (f
);
8827 x_bitmap_icon (f
, type
);
8830 if (FRAME_GTK_OUTER_WIDGET (f
))
8832 if (! FRAME_VISIBLE_P (f
))
8833 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8835 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8838 f
->async_iconified
= 1;
8839 f
->async_visible
= 0;
8845 #ifdef USE_X_TOOLKIT
8847 if (! FRAME_VISIBLE_P (f
))
8849 if (! EQ (Vx_no_window_manager
, Qt
))
8850 x_wm_set_window_state (f
, IconicState
);
8851 /* This was XtPopup, but that did nothing for an iconified frame. */
8852 XtMapWidget (f
->output_data
.x
->widget
);
8853 /* The server won't give us any event to indicate
8854 that an invisible frame was changed to an icon,
8855 so we have to record it here. */
8858 f
->async_iconified
= 1;
8859 f
->async_visible
= 0;
8864 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
8865 XtWindow (f
->output_data
.x
->widget
),
8866 DefaultScreen (FRAME_X_DISPLAY (f
)));
8870 error ("Can't notify window manager of iconification");
8872 f
->async_iconified
= 1;
8873 f
->async_visible
= 0;
8877 XFlush (FRAME_X_DISPLAY (f
));
8879 #else /* not USE_X_TOOLKIT */
8881 /* Make sure the X server knows where the window should be positioned,
8882 in case the user deiconifies with the window manager. */
8883 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
8884 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8886 /* Since we don't know which revision of X we're running, we'll use both
8887 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
8889 /* X11R4: send a ClientMessage to the window manager using the
8890 WM_CHANGE_STATE type. */
8894 message
.xclient
.window
= FRAME_X_WINDOW (f
);
8895 message
.xclient
.type
= ClientMessage
;
8896 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
8897 message
.xclient
.format
= 32;
8898 message
.xclient
.data
.l
[0] = IconicState
;
8900 if (! XSendEvent (FRAME_X_DISPLAY (f
),
8901 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
8903 SubstructureRedirectMask
| SubstructureNotifyMask
,
8906 UNBLOCK_INPUT_RESIGNAL
;
8907 error ("Can't notify window manager of iconification");
8911 /* X11R3: set the initial_state field of the window manager hints to
8913 x_wm_set_window_state (f
, IconicState
);
8915 if (!FRAME_VISIBLE_P (f
))
8917 /* If the frame was withdrawn, before, we must map it. */
8918 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8921 f
->async_iconified
= 1;
8922 f
->async_visible
= 0;
8924 XFlush (FRAME_X_DISPLAY (f
));
8926 #endif /* not USE_X_TOOLKIT */
8930 /* Free X resources of frame F. */
8933 x_free_frame_resources (f
)
8936 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8938 struct scroll_bar
*b
;
8942 /* If a display connection is dead, don't try sending more
8943 commands to the X server. */
8944 if (dpyinfo
->display
)
8946 if (f
->output_data
.x
->icon_desc
)
8947 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
8949 #ifdef USE_X_TOOLKIT
8950 /* Explicitly destroy the scroll bars of the frame. Without
8951 this, we get "BadDrawable" errors from the toolkit later on,
8952 presumably from expose events generated for the disappearing
8953 toolkit scroll bars. */
8954 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
8956 b
= XSCROLL_BAR (bar
);
8957 x_scroll_bar_remove (b
);
8966 #ifdef USE_X_TOOLKIT
8967 if (f
->output_data
.x
->widget
)
8969 XtDestroyWidget (f
->output_data
.x
->widget
);
8970 f
->output_data
.x
->widget
= NULL
;
8972 /* Tooltips don't have widgets, only a simple X window, even if
8973 we are using a toolkit. */
8974 else if (FRAME_X_WINDOW (f
))
8975 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8977 free_frame_menubar (f
);
8978 #else /* !USE_X_TOOLKIT */
8981 /* In the GTK version, tooltips are normal X
8982 frames. We must check and free both types. */
8983 if (FRAME_GTK_OUTER_WIDGET (f
))
8985 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
8986 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
8987 FRAME_GTK_OUTER_WIDGET (f
) = 0;
8989 #endif /* USE_GTK */
8991 if (FRAME_X_WINDOW (f
))
8992 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8993 #endif /* !USE_X_TOOLKIT */
8995 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
8996 unload_color (f
, f
->output_data
.x
->background_pixel
);
8997 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
8998 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
8999 unload_color (f
, f
->output_data
.x
->border_pixel
);
9000 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9002 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9003 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9004 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9005 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9006 #ifdef USE_TOOLKIT_SCROLL_BARS
9007 /* Scrollbar shadow colors. */
9008 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9009 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9010 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9011 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9012 #endif /* USE_TOOLKIT_SCROLL_BARS */
9013 if (f
->output_data
.x
->white_relief
.allocated_p
)
9014 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9015 if (f
->output_data
.x
->black_relief
.allocated_p
)
9016 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9018 if (FRAME_FACE_CACHE (f
))
9019 free_frame_faces (f
);
9022 XFlush (FRAME_X_DISPLAY (f
));
9025 if (f
->output_data
.x
->saved_menu_event
)
9026 xfree (f
->output_data
.x
->saved_menu_event
);
9028 xfree (f
->output_data
.x
);
9029 f
->output_data
.x
= NULL
;
9031 if (f
== dpyinfo
->x_focus_frame
)
9032 dpyinfo
->x_focus_frame
= 0;
9033 if (f
== dpyinfo
->x_focus_event_frame
)
9034 dpyinfo
->x_focus_event_frame
= 0;
9035 if (f
== dpyinfo
->x_highlight_frame
)
9036 dpyinfo
->x_highlight_frame
= 0;
9038 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9040 dpyinfo
->mouse_face_beg_row
9041 = dpyinfo
->mouse_face_beg_col
= -1;
9042 dpyinfo
->mouse_face_end_row
9043 = dpyinfo
->mouse_face_end_col
= -1;
9044 dpyinfo
->mouse_face_window
= Qnil
;
9045 dpyinfo
->mouse_face_deferred_gc
= 0;
9046 dpyinfo
->mouse_face_mouse_frame
= 0;
9053 /* Destroy the X window of frame F. */
9056 x_destroy_window (f
)
9059 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9061 /* If a display connection is dead, don't try sending more
9062 commands to the X server. */
9063 if (dpyinfo
->display
!= 0)
9064 x_free_frame_resources (f
);
9066 dpyinfo
->reference_count
--;
9070 /* Setting window manager hints. */
9072 /* Set the normal size hints for the window manager, for frame F.
9073 FLAGS is the flags word to use--or 0 meaning preserve the flags
9074 that the window now has.
9075 If USER_POSITION is nonzero, we set the USPosition
9076 flag (this is useful when FLAGS is 0).
9077 The GTK version is in gtkutils.c */
9081 x_wm_set_size_hint (f
, flags
, user_position
)
9086 XSizeHints size_hints
;
9088 #ifdef USE_X_TOOLKIT
9091 Dimension widget_width
, widget_height
;
9094 Window window
= FRAME_OUTER_WINDOW (f
);
9096 /* Setting PMaxSize caused various problems. */
9097 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9099 size_hints
.x
= f
->left_pos
;
9100 size_hints
.y
= f
->top_pos
;
9102 #ifdef USE_X_TOOLKIT
9103 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9104 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9105 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9106 size_hints
.height
= widget_height
;
9107 size_hints
.width
= widget_width
;
9108 #else /* not USE_X_TOOLKIT */
9109 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9110 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9111 #endif /* not USE_X_TOOLKIT */
9113 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9114 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9115 size_hints
.max_width
9116 = FRAME_X_DISPLAY_INFO (f
)->width
- FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9117 size_hints
.max_height
9118 = FRAME_X_DISPLAY_INFO (f
)->height
- FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9120 /* Calculate the base and minimum sizes.
9122 (When we use the X toolkit, we don't do it here.
9123 Instead we copy the values that the widgets are using, below.) */
9124 #ifndef USE_X_TOOLKIT
9126 int base_width
, base_height
;
9127 int min_rows
= 0, min_cols
= 0;
9129 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9130 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9132 check_frame_size (f
, &min_rows
, &min_cols
);
9134 /* The window manager uses the base width hints to calculate the
9135 current number of rows and columns in the frame while
9136 resizing; min_width and min_height aren't useful for this
9137 purpose, since they might not give the dimensions for a
9138 zero-row, zero-column frame.
9140 We use the base_width and base_height members if we have
9141 them; otherwise, we set the min_width and min_height members
9142 to the size for a zero x zero frame. */
9145 size_hints
.flags
|= PBaseSize
;
9146 size_hints
.base_width
= base_width
;
9147 size_hints
.base_height
= base_height
;
9148 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9149 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9151 size_hints
.min_width
= base_width
;
9152 size_hints
.min_height
= base_height
;
9156 /* If we don't need the old flags, we don't need the old hint at all. */
9159 size_hints
.flags
|= flags
;
9162 #endif /* not USE_X_TOOLKIT */
9165 XSizeHints hints
; /* Sometimes I hate X Windows... */
9166 long supplied_return
;
9170 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9173 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
9176 #ifdef USE_X_TOOLKIT
9177 size_hints
.base_height
= hints
.base_height
;
9178 size_hints
.base_width
= hints
.base_width
;
9179 size_hints
.min_height
= hints
.min_height
;
9180 size_hints
.min_width
= hints
.min_width
;
9184 size_hints
.flags
|= flags
;
9189 if (hints
.flags
& PSize
)
9190 size_hints
.flags
|= PSize
;
9191 if (hints
.flags
& PPosition
)
9192 size_hints
.flags
|= PPosition
;
9193 if (hints
.flags
& USPosition
)
9194 size_hints
.flags
|= USPosition
;
9195 if (hints
.flags
& USSize
)
9196 size_hints
.flags
|= USSize
;
9200 #ifndef USE_X_TOOLKIT
9205 size_hints
.win_gravity
= f
->win_gravity
;
9206 size_hints
.flags
|= PWinGravity
;
9210 size_hints
.flags
&= ~ PPosition
;
9211 size_hints
.flags
|= USPosition
;
9213 #endif /* PWinGravity */
9216 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9218 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9221 #endif /* not USE_GTK */
9223 /* Used for IconicState or NormalState */
9226 x_wm_set_window_state (f
, state
)
9230 #ifdef USE_X_TOOLKIT
9233 XtSetArg (al
[0], XtNinitialState
, state
);
9234 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9235 #else /* not USE_X_TOOLKIT */
9236 Window window
= FRAME_X_WINDOW (f
);
9238 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9239 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9241 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9242 #endif /* not USE_X_TOOLKIT */
9246 x_wm_set_icon_pixmap (f
, pixmap_id
)
9250 Pixmap icon_pixmap
, icon_mask
;
9252 #ifndef USE_X_TOOLKIT
9253 Window window
= FRAME_OUTER_WINDOW (f
);
9258 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9259 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9260 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9261 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9265 /* It seems there is no way to turn off use of an icon pixmap.
9266 The following line does it, only if no icon has yet been created,
9267 for some window managers. But with mwm it crashes.
9268 Some people say it should clear the IconPixmapHint bit in this case,
9269 but that doesn't work, and the X consortium said it isn't the
9270 right thing at all. Since there is no way to win,
9271 best to explicitly give up. */
9273 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
9274 f
->output_data
.x
->wm_hints
.icon_mask
= None
;
9283 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9287 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9291 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9292 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9293 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9294 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9297 #else /* not USE_X_TOOLKIT && not USE_GTK */
9299 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9300 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9302 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9306 x_wm_set_icon_position (f
, icon_x
, icon_y
)
9310 Window window
= FRAME_OUTER_WINDOW (f
);
9312 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9313 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9314 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9316 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9320 /***********************************************************************
9322 ***********************************************************************/
9324 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
9327 x_get_font_info (f
, font_idx
)
9331 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
9335 /* Return a list of names of available fonts matching PATTERN on frame F.
9337 If SIZE is > 0, it is the size (maximum bounds width) of fonts
9340 SIZE < 0 means include scalable fonts.
9342 Frame F null means we have not yet created any frame on X, and
9343 consult the first display in x_display_list. MAXNAMES sets a limit
9344 on how many fonts to match. */
9347 x_list_fonts (f
, pattern
, size
, maxnames
)
9349 Lisp_Object pattern
;
9353 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
9354 Lisp_Object tem
, second_best
;
9355 struct x_display_info
*dpyinfo
9356 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
9357 Display
*dpy
= dpyinfo
->display
;
9358 int try_XLoadQueryFont
= 0;
9359 int allow_auto_scaled_font
= 0;
9363 allow_auto_scaled_font
= 1;
9367 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
9368 if (NILP (patterns
))
9369 patterns
= Fcons (pattern
, Qnil
);
9371 if (maxnames
== 1 && !size
)
9372 /* We can return any single font matching PATTERN. */
9373 try_XLoadQueryFont
= 1;
9375 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
9378 char **names
= NULL
;
9380 pattern
= XCAR (patterns
);
9381 /* See if we cached the result for this particular query.
9382 The cache is an alist of the form:
9383 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
9384 tem
= XCDR (dpyinfo
->name_list_element
);
9385 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
9386 allow_auto_scaled_font
? Qt
: Qnil
);
9387 list
= Fassoc (key
, tem
);
9390 list
= Fcdr_safe (list
);
9391 /* We have a cashed list. Don't have to get the list again. */
9395 /* At first, put PATTERN in the cache. */
9398 x_catch_errors (dpy
);
9400 if (try_XLoadQueryFont
)
9403 unsigned long value
;
9405 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
9406 if (x_had_errors_p (dpy
))
9408 /* This error is perhaps due to insufficient memory on X
9409 server. Let's just ignore it. */
9411 x_clear_errors (dpy
);
9415 && XGetFontProperty (font
, XA_FONT
, &value
))
9417 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
9418 int len
= strlen (name
);
9421 /* If DXPC (a Differential X Protocol Compressor)
9422 Ver.3.7 is running, XGetAtomName will return null
9423 string. We must avoid such a name. */
9425 try_XLoadQueryFont
= 0;
9429 names
= (char **) alloca (sizeof (char *));
9430 /* Some systems only allow alloca assigned to a
9432 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
9433 bcopy (name
, names
[0], len
+ 1);
9438 try_XLoadQueryFont
= 0;
9441 XFreeFont (dpy
, font
);
9444 if (!try_XLoadQueryFont
)
9446 /* We try at least 10 fonts because XListFonts will return
9447 auto-scaled fonts at the head. */
9454 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
9455 if (num_fonts
== limit
)
9458 XFreeFontNames (names
);
9467 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
9470 if (x_had_errors_p (dpy
))
9472 /* This error is perhaps due to insufficient memory on X
9473 server. Let's just ignore it. */
9475 x_clear_errors (dpy
);
9479 x_uncatch_errors ();
9486 /* Make a list of all the fonts we got back.
9487 Store that in the font cache for the display. */
9488 for (i
= 0; i
< num_fonts
; i
++)
9492 int average_width
= -1, resx
= 0, dashes
= 0;
9494 /* Count the number of dashes in NAMES[I]. If there are
9495 14 dashes, the field value following 9th dash
9496 (RESOLUTION_X) is nonzero, and the field value
9497 following 12th dash (AVERAGE_WIDTH) is 0, this is a
9498 auto-scaled font which is usually too ugly to be used
9499 for editing. Let's ignore it. */
9504 if (dashes
== 7) /* PIXEL_SIZE field */
9506 else if (dashes
== 9)
9508 else if (dashes
== 12) /* AVERAGE_WIDTH field */
9509 average_width
= atoi (p
);
9512 if (allow_auto_scaled_font
9513 || dashes
< 14 || average_width
!= 0 || resx
== 0)
9515 tem
= build_string (names
[i
]);
9516 if (NILP (Fassoc (tem
, list
)))
9518 if (STRINGP (Vx_pixel_size_width_font_regexp
)
9519 && ((fast_c_string_match_ignore_case
9520 (Vx_pixel_size_width_font_regexp
, names
[i
]))
9522 /* We can set the value of PIXEL_SIZE to the
9523 width of this font. */
9524 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
9526 /* For the moment, width is not known. */
9527 list
= Fcons (Fcons (tem
, Qnil
), list
);
9532 if (!try_XLoadQueryFont
)
9535 XFreeFontNames (names
);
9540 /* Now store the result in the cache. */
9541 XSETCDR (dpyinfo
->name_list_element
,
9542 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
9545 if (NILP (list
)) continue; /* Try the remaining alternatives. */
9547 newlist
= second_best
= Qnil
;
9548 /* Make a list of the fonts that have the right width. */
9549 for (; CONSP (list
); list
= XCDR (list
))
9555 if (!CONSP (tem
) || NILP (XCAR (tem
)))
9559 newlist
= Fcons (XCAR (tem
), newlist
);
9563 if (!INTEGERP (XCDR (tem
)))
9565 /* Since we have not yet known the size of this font, we
9566 must try slow function call XLoadQueryFont. */
9567 XFontStruct
*thisinfo
;
9570 x_catch_errors (dpy
);
9571 thisinfo
= XLoadQueryFont (dpy
,
9572 SDATA (XCAR (tem
)));
9573 if (x_had_errors_p (dpy
))
9575 /* This error is perhaps due to insufficient memory on X
9576 server. Let's just ignore it. */
9578 x_clear_errors (dpy
);
9580 x_uncatch_errors ();
9586 (thisinfo
->min_bounds
.width
== 0
9588 : make_number (thisinfo
->max_bounds
.width
)));
9590 XFreeFont (dpy
, thisinfo
);
9594 /* For unknown reason, the previous call of XListFont had
9595 returned a font which can't be opened. Record the size
9596 as 0 not to try to open it again. */
9597 XSETCDR (tem
, make_number (0));
9600 found_size
= XINT (XCDR (tem
));
9601 if (found_size
== size
)
9602 newlist
= Fcons (XCAR (tem
), newlist
);
9603 else if (found_size
> 0)
9605 if (NILP (second_best
))
9607 else if (found_size
< size
)
9609 if (XINT (XCDR (second_best
)) > size
9610 || XINT (XCDR (second_best
)) < found_size
)
9615 if (XINT (XCDR (second_best
)) > size
9616 && XINT (XCDR (second_best
)) > found_size
)
9621 if (!NILP (newlist
))
9623 else if (!NILP (second_best
))
9625 newlist
= Fcons (XCAR (second_best
), Qnil
);
9636 /* Check that FONT is valid on frame F. It is if it can be found in F's
9640 x_check_font (f
, font
)
9645 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9647 xassert (font
!= NULL
);
9649 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9650 if (dpyinfo
->font_table
[i
].name
9651 && font
== dpyinfo
->font_table
[i
].font
)
9654 xassert (i
< dpyinfo
->n_fonts
);
9657 #endif /* GLYPH_DEBUG != 0 */
9659 /* Set *W to the minimum width, *H to the minimum font height of FONT.
9660 Note: There are (broken) X fonts out there with invalid XFontStruct
9661 min_bounds contents. For example, handa@etl.go.jp reports that
9662 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
9663 have font->min_bounds.width == 0. */
9666 x_font_min_bounds (font
, w
, h
)
9670 *h
= FONT_HEIGHT (font
);
9671 *w
= font
->min_bounds
.width
;
9673 /* Try to handle the case where FONT->min_bounds has invalid
9674 contents. Since the only font known to have invalid min_bounds
9675 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
9677 *w
= font
->max_bounds
.width
;
9681 /* Compute the smallest character width and smallest font height over
9682 all fonts available on frame F. Set the members smallest_char_width
9683 and smallest_font_height in F's x_display_info structure to
9684 the values computed. Value is non-zero if smallest_font_height or
9685 smallest_char_width become smaller than they were before. */
9688 x_compute_min_glyph_bounds (f
)
9692 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9694 int old_width
= dpyinfo
->smallest_char_width
;
9695 int old_height
= dpyinfo
->smallest_font_height
;
9697 dpyinfo
->smallest_font_height
= 100000;
9698 dpyinfo
->smallest_char_width
= 100000;
9700 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
9701 if (dpyinfo
->font_table
[i
].name
)
9703 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
9706 font
= (XFontStruct
*) fontp
->font
;
9707 xassert (font
!= (XFontStruct
*) ~0);
9708 x_font_min_bounds (font
, &w
, &h
);
9710 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
9711 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
9714 xassert (dpyinfo
->smallest_char_width
> 0
9715 && dpyinfo
->smallest_font_height
> 0);
9717 return (dpyinfo
->n_fonts
== 1
9718 || dpyinfo
->smallest_char_width
< old_width
9719 || dpyinfo
->smallest_font_height
< old_height
);
9723 /* Load font named FONTNAME of the size SIZE for frame F, and return a
9724 pointer to the structure font_info while allocating it dynamically.
9725 If SIZE is 0, load any size of font.
9726 If loading is failed, return NULL. */
9729 x_load_font (f
, fontname
, size
)
9731 register char *fontname
;
9734 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9735 Lisp_Object font_names
;
9737 /* Get a list of all the fonts that match this name. Once we
9738 have a list of matching fonts, we compare them against the fonts
9739 we already have by comparing names. */
9740 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
9742 if (!NILP (font_names
))
9747 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9748 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
9749 if (dpyinfo
->font_table
[i
].name
9750 && (!strcmp (dpyinfo
->font_table
[i
].name
,
9751 SDATA (XCAR (tail
)))
9752 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
9753 SDATA (XCAR (tail
)))))
9754 return (dpyinfo
->font_table
+ i
);
9757 /* Load the font and add it to the table. */
9761 struct font_info
*fontp
;
9762 unsigned long value
;
9765 /* If we have found fonts by x_list_font, load one of them. If
9766 not, we still try to load a font by the name given as FONTNAME
9767 because XListFonts (called in x_list_font) of some X server has
9768 a bug of not finding a font even if the font surely exists and
9769 is loadable by XLoadQueryFont. */
9770 if (size
> 0 && !NILP (font_names
))
9771 fontname
= (char *) SDATA (XCAR (font_names
));
9774 x_catch_errors (FRAME_X_DISPLAY (f
));
9775 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
9776 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
9778 /* This error is perhaps due to insufficient memory on X
9779 server. Let's just ignore it. */
9781 x_clear_errors (FRAME_X_DISPLAY (f
));
9783 x_uncatch_errors ();
9788 /* Find a free slot in the font table. */
9789 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
9790 if (dpyinfo
->font_table
[i
].name
== NULL
)
9793 /* If no free slot found, maybe enlarge the font table. */
9794 if (i
== dpyinfo
->n_fonts
9795 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
9798 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
9799 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
9801 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
9804 fontp
= dpyinfo
->font_table
+ i
;
9805 if (i
== dpyinfo
->n_fonts
)
9808 /* Now fill in the slots of *FONTP. */
9810 bzero (fontp
, sizeof (*fontp
));
9812 fontp
->font_idx
= i
;
9813 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
9814 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
9816 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
9818 /* Fixed width font. */
9819 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
9826 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
9827 pcm
= x_per_char_metric (font
, &char2b
, 0);
9829 fontp
->space_width
= pcm
->width
;
9831 fontp
->space_width
= FONT_WIDTH (font
);
9833 fontp
->average_width
9834 = (XGetFontProperty (font
, dpyinfo
->Xatom_AVERAGE_WIDTH
, &value
)
9835 ? (long) value
/ 10 : 0);
9836 if (fontp
->average_width
< 0)
9837 fontp
->average_width
= - fontp
->average_width
;
9838 if (fontp
->average_width
== 0)
9842 int width
= pcm
->width
;
9843 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
9844 if ((pcm
= x_per_char_metric (font
, &char2b
, 0)) != NULL
)
9845 width
+= pcm
->width
;
9846 fontp
->average_width
= width
/ 95;
9849 fontp
->average_width
= FONT_WIDTH (font
);
9853 /* Try to get the full name of FONT. Put it in FULL_NAME. */
9855 if (XGetFontProperty (font
, XA_FONT
, &value
))
9857 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
9861 /* Count the number of dashes in the "full name".
9862 If it is too few, this isn't really the font's full name,
9864 In X11R4, the fonts did not come with their canonical names
9875 full_name
= (char *) xmalloc (p
- name
+ 1);
9876 bcopy (name
, full_name
, p
- name
+ 1);
9883 fontp
->full_name
= full_name
;
9885 fontp
->full_name
= fontp
->name
;
9887 fontp
->size
= font
->max_bounds
.width
;
9888 fontp
->height
= FONT_HEIGHT (font
);
9890 if (NILP (font_names
))
9892 /* We come here because of a bug of XListFonts mentioned at
9893 the head of this block. Let's store this information in
9894 the cache for x_list_fonts. */
9895 Lisp_Object lispy_name
= build_string (fontname
);
9896 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
9897 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
9900 XSETCDR (dpyinfo
->name_list_element
,
9902 Fcons (Fcons (lispy_full_name
,
9903 make_number (fontp
->size
)),
9905 XCDR (dpyinfo
->name_list_element
)));
9908 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
9910 XSETCDR (dpyinfo
->name_list_element
,
9912 Fcons (Fcons (lispy_full_name
,
9913 make_number (fontp
->size
)),
9915 XCDR (dpyinfo
->name_list_element
)));
9919 /* The slot `encoding' specifies how to map a character
9920 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
9921 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
9922 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
9923 2:0xA020..0xFF7F). For the moment, we don't know which charset
9924 uses this font. So, we set information in fontp->encoding[1]
9925 which is never used by any charset. If mapping can't be
9926 decided, set FONT_ENCODING_NOT_DECIDED. */
9928 = (font
->max_byte1
== 0
9930 ? (font
->min_char_or_byte2
< 0x80
9931 ? (font
->max_char_or_byte2
< 0x80
9932 ? 0 /* 0x20..0x7F */
9933 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
9934 : 1) /* 0xA0..0xFF */
9936 : (font
->min_byte1
< 0x80
9937 ? (font
->max_byte1
< 0x80
9938 ? (font
->min_char_or_byte2
< 0x80
9939 ? (font
->max_char_or_byte2
< 0x80
9940 ? 0 /* 0x2020..0x7F7F */
9941 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
9942 : 3) /* 0x20A0..0x7FFF */
9943 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
9944 : (font
->min_char_or_byte2
< 0x80
9945 ? (font
->max_char_or_byte2
< 0x80
9946 ? 2 /* 0xA020..0xFF7F */
9947 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
9948 : 1))); /* 0xA0A0..0xFFFF */
9950 fontp
->baseline_offset
9951 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
9952 ? (long) value
: 0);
9953 fontp
->relative_compose
9954 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
9955 ? (long) value
: 0);
9956 fontp
->default_ascent
9957 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
9958 ? (long) value
: 0);
9960 /* Set global flag fonts_changed_p to non-zero if the font loaded
9961 has a character with a smaller width than any other character
9962 before, or if the font loaded has a smaller height than any
9963 other font loaded before. If this happens, it will make a
9964 glyph matrix reallocation necessary. */
9965 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
9972 /* Return a pointer to struct font_info of a font named FONTNAME for
9973 frame F. If no such font is loaded, return NULL. */
9976 x_query_font (f
, fontname
)
9978 register char *fontname
;
9980 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9983 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9984 if (dpyinfo
->font_table
[i
].name
9985 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
9986 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
9987 return (dpyinfo
->font_table
+ i
);
9992 /* Find a CCL program for a font specified by FONTP, and set the member
9993 `encoder' of the structure. */
9996 x_find_ccl_program (fontp
)
9997 struct font_info
*fontp
;
9999 Lisp_Object list
, elt
;
10002 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
10006 && STRINGP (XCAR (elt
))
10007 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
10009 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
10016 struct ccl_program
*ccl
10017 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
10019 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
10022 fontp
->font_encoder
= ccl
;
10028 /***********************************************************************
10030 ***********************************************************************/
10032 #ifdef USE_X_TOOLKIT
10033 static XrmOptionDescRec emacs_options
[] = {
10034 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
10035 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
10037 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
10038 XrmoptionSepArg
, NULL
},
10039 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
10041 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10042 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10043 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10044 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10045 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10046 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
10047 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
10049 #endif /* USE_X_TOOLKIT */
10051 static int x_initialized
;
10054 static int x_session_initialized
;
10057 #ifdef MULTI_KBOARD
10058 /* Test whether two display-name strings agree up to the dot that separates
10059 the screen number from the server number. */
10061 same_x_server (name1
, name2
)
10062 const char *name1
, *name2
;
10064 int seen_colon
= 0;
10065 const unsigned char *system_name
= SDATA (Vsystem_name
);
10066 int system_name_length
= strlen (system_name
);
10067 int length_until_period
= 0;
10069 while (system_name
[length_until_period
] != 0
10070 && system_name
[length_until_period
] != '.')
10071 length_until_period
++;
10073 /* Treat `unix' like an empty host name. */
10074 if (! strncmp (name1
, "unix:", 5))
10076 if (! strncmp (name2
, "unix:", 5))
10078 /* Treat this host's name like an empty host name. */
10079 if (! strncmp (name1
, system_name
, system_name_length
)
10080 && name1
[system_name_length
] == ':')
10081 name1
+= system_name_length
;
10082 if (! strncmp (name2
, system_name
, system_name_length
)
10083 && name2
[system_name_length
] == ':')
10084 name2
+= system_name_length
;
10085 /* Treat this host's domainless name like an empty host name. */
10086 if (! strncmp (name1
, system_name
, length_until_period
)
10087 && name1
[length_until_period
] == ':')
10088 name1
+= length_until_period
;
10089 if (! strncmp (name2
, system_name
, length_until_period
)
10090 && name2
[length_until_period
] == ':')
10091 name2
+= length_until_period
;
10093 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
10097 if (seen_colon
&& *name1
== '.')
10101 && (*name1
== '.' || *name1
== '\0')
10102 && (*name2
== '.' || *name2
== '\0'));
10106 /* Count number of set bits in mask and number of bits to shift to
10107 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
10110 get_bits_and_offset (mask
, bits
, offset
)
10111 unsigned long mask
;
10118 while (!(mask
& 1))
10135 x_display_ok (display
)
10136 const char * display
;
10141 dpy
= XOpenDisplay (display
);
10143 XCloseDisplay (dpy
);
10149 struct x_display_info
*
10150 x_term_init (display_name
, xrm_option
, resource_name
)
10151 Lisp_Object display_name
;
10153 char *resource_name
;
10157 struct x_display_info
*dpyinfo
;
10162 if (!x_initialized
)
10170 #define NUM_ARGV 10
10172 char *argv
[NUM_ARGV
];
10173 char **argv2
= argv
;
10176 if (x_initialized
++ > 1)
10178 /* Opening another display. If xg_display_open returns less
10179 than zero, we are probably on GTK 2.0, which can only handle
10180 one display. GTK 2.2 or later can handle more than one. */
10181 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
10182 error ("Sorry, this version of GTK can only handle one display");
10186 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
10190 argv
[argc
++] = initial_argv
[0];
10192 if (! NILP (display_name
))
10194 argv
[argc
++] = "--display";
10195 argv
[argc
++] = SDATA (display_name
);
10198 argv
[argc
++] = "--name";
10199 argv
[argc
++] = resource_name
;
10202 XSetLocaleModifiers ("");
10205 gtk_init (&argc
, &argv2
);
10207 /* gtk_init does set_locale. We must fix locale after calling it. */
10211 dpy
= GDK_DISPLAY ();
10213 /* NULL window -> events for all windows go to our function */
10214 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10216 /* Load our own gtkrc if it exists. */
10218 char *file
= "~/.emacs.d/gtkrc";
10219 Lisp_Object s
, abs_file
;
10221 s
= make_string (file
, strlen (file
));
10222 abs_file
= Fexpand_file_name (s
, Qnil
);
10224 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10225 gtk_rc_parse (SDATA (abs_file
));
10228 XSetErrorHandler (x_error_handler
);
10229 XSetIOErrorHandler (x_io_error_quitter
);
10232 #else /* not USE_GTK */
10233 #ifdef USE_X_TOOLKIT
10234 /* weiner@footloose.sps.mot.com reports that this causes
10236 X protocol error: BadAtom (invalid Atom parameter)
10237 on protocol request 18skiloaf.
10238 So let's not use it until R6. */
10239 #ifdef HAVE_X11XTR6
10240 XtSetLanguageProc (NULL
, NULL
, NULL
);
10251 argv
[argc
++] = "-xrm";
10252 argv
[argc
++] = xrm_option
;
10254 turn_on_atimers (0);
10255 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
10256 resource_name
, EMACS_CLASS
,
10257 emacs_options
, XtNumber (emacs_options
),
10259 turn_on_atimers (1);
10261 #ifdef HAVE_X11XTR6
10262 /* I think this is to compensate for XtSetLanguageProc. */
10267 #else /* not USE_X_TOOLKIT */
10269 XSetLocaleModifiers ("");
10271 dpy
= XOpenDisplay (SDATA (display_name
));
10272 #endif /* not USE_X_TOOLKIT */
10273 #endif /* not USE_GTK*/
10275 /* Detect failure. */
10282 /* We have definitely succeeded. Record the new connection. */
10284 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
10285 bzero (dpyinfo
, sizeof *dpyinfo
);
10287 #ifdef MULTI_KBOARD
10289 struct x_display_info
*share
;
10292 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10293 share
= share
->next
, tail
= XCDR (tail
))
10294 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
10295 SDATA (display_name
)))
10298 dpyinfo
->kboard
= share
->kboard
;
10301 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
10302 init_kboard (dpyinfo
->kboard
);
10303 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10305 char *vendor
= ServerVendor (dpy
);
10307 dpyinfo
->kboard
->Vsystem_key_alist
10308 = call1 (Qvendor_specific_keysyms
,
10309 build_string (vendor
? vendor
: ""));
10313 dpyinfo
->kboard
->next_kboard
= all_kboards
;
10314 all_kboards
= dpyinfo
->kboard
;
10315 /* Don't let the initial kboard remain current longer than necessary.
10316 That would cause problems if a file loaded on startup tries to
10317 prompt in the mini-buffer. */
10318 if (current_kboard
== initial_kboard
)
10319 current_kboard
= dpyinfo
->kboard
;
10321 dpyinfo
->kboard
->reference_count
++;
10325 /* Put this display on the chain. */
10326 dpyinfo
->next
= x_display_list
;
10327 x_display_list
= dpyinfo
;
10329 /* Put it on x_display_name_list as well, to keep them parallel. */
10330 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10331 x_display_name_list
);
10332 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10334 dpyinfo
->display
= dpy
;
10337 XSetAfterFunction (x_current_display
, x_trace_wire
);
10341 = (char *) xmalloc (SBYTES (Vinvocation_name
)
10342 + SBYTES (Vsystem_name
)
10344 sprintf (dpyinfo
->x_id_name
, "%s@%s",
10345 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10347 /* Figure out which modifier bits mean what. */
10348 x_find_modifier_meanings (dpyinfo
);
10350 /* Get the scroll bar cursor. */
10352 /* We must create a GTK cursor, it is required for GTK widgets. */
10353 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10354 #endif /* USE_GTK */
10356 dpyinfo
->vertical_scroll_bar_cursor
10357 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10359 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10360 resource_name
, EMACS_CLASS
);
10361 #ifdef HAVE_XRMSETDATABASE
10362 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10364 dpyinfo
->display
->db
= xrdb
;
10366 /* Put the rdb where we can find it in a way that works on
10368 dpyinfo
->xrdb
= xrdb
;
10370 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10371 DefaultScreen (dpyinfo
->display
));
10372 select_visual (dpyinfo
);
10373 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10374 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
10375 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
10376 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10377 dpyinfo
->client_leader_window
= 0;
10378 dpyinfo
->grabbed
= 0;
10379 dpyinfo
->reference_count
= 0;
10380 dpyinfo
->icon_bitmap_id
= -1;
10381 dpyinfo
->font_table
= NULL
;
10382 dpyinfo
->n_fonts
= 0;
10383 dpyinfo
->font_table_size
= 0;
10384 dpyinfo
->bitmaps
= 0;
10385 dpyinfo
->bitmaps_size
= 0;
10386 dpyinfo
->bitmaps_last
= 0;
10387 dpyinfo
->scratch_cursor_gc
= 0;
10388 dpyinfo
->mouse_face_mouse_frame
= 0;
10389 dpyinfo
->mouse_face_deferred_gc
= 0;
10390 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10391 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10392 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10393 dpyinfo
->mouse_face_window
= Qnil
;
10394 dpyinfo
->mouse_face_overlay
= Qnil
;
10395 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
10396 dpyinfo
->mouse_face_defer
= 0;
10397 dpyinfo
->mouse_face_hidden
= 0;
10398 dpyinfo
->x_focus_frame
= 0;
10399 dpyinfo
->x_focus_event_frame
= 0;
10400 dpyinfo
->x_highlight_frame
= 0;
10401 dpyinfo
->image_cache
= make_image_cache ();
10402 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10404 /* See if we can construct pixel values from RGB values. */
10405 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
10406 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
10408 if (dpyinfo
->visual
->class == TrueColor
)
10410 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10411 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10412 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10413 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10414 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10415 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10418 /* See if a private colormap is requested. */
10419 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10421 if (dpyinfo
->visual
->class == PseudoColor
)
10424 value
= display_x_get_resource (dpyinfo
,
10425 build_string ("privateColormap"),
10426 build_string ("PrivateColormap"),
10428 if (STRINGP (value
)
10429 && (!strcmp (SDATA (value
), "true")
10430 || !strcmp (SDATA (value
), "on")))
10431 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10435 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10436 dpyinfo
->visual
, AllocNone
);
10439 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10440 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10441 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10442 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10443 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10444 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10445 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10446 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10447 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10450 dpyinfo
->Xatom_wm_protocols
10451 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10452 dpyinfo
->Xatom_wm_take_focus
10453 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10454 dpyinfo
->Xatom_wm_save_yourself
10455 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10456 dpyinfo
->Xatom_wm_delete_window
10457 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10458 dpyinfo
->Xatom_wm_change_state
10459 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10460 dpyinfo
->Xatom_wm_configure_denied
10461 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10462 dpyinfo
->Xatom_wm_window_moved
10463 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10464 dpyinfo
->Xatom_wm_client_leader
10465 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10466 dpyinfo
->Xatom_editres
10467 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10468 dpyinfo
->Xatom_CLIPBOARD
10469 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10470 dpyinfo
->Xatom_TIMESTAMP
10471 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10472 dpyinfo
->Xatom_TEXT
10473 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10474 dpyinfo
->Xatom_COMPOUND_TEXT
10475 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10476 dpyinfo
->Xatom_UTF8_STRING
10477 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10478 dpyinfo
->Xatom_DELETE
10479 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10480 dpyinfo
->Xatom_MULTIPLE
10481 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10482 dpyinfo
->Xatom_INCR
10483 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10484 dpyinfo
->Xatom_EMACS_TMP
10485 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10486 dpyinfo
->Xatom_TARGETS
10487 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10488 dpyinfo
->Xatom_NULL
10489 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10490 dpyinfo
->Xatom_ATOM_PAIR
10491 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10492 /* For properties of font. */
10493 dpyinfo
->Xatom_PIXEL_SIZE
10494 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10495 dpyinfo
->Xatom_AVERAGE_WIDTH
10496 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
10497 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10498 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10499 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10500 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10501 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10502 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10504 /* Ghostscript support. */
10505 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10506 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10508 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10511 dpyinfo
->cut_buffers_initialized
= 0;
10513 connection
= ConnectionNumber (dpyinfo
->display
);
10514 dpyinfo
->connection
= connection
;
10519 null_bits
[0] = 0x00;
10521 dpyinfo
->null_pixel
10522 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10523 null_bits
, 1, 1, (long) 0, (long) 0,
10528 extern int gray_bitmap_width
, gray_bitmap_height
;
10529 extern char *gray_bitmap_bits
;
10531 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10533 gray_bitmap_width
, gray_bitmap_height
,
10534 (unsigned long) 1, (unsigned long) 0, 1);
10538 xim_initialize (dpyinfo
, resource_name
);
10541 #ifdef subprocesses
10542 /* This is only needed for distinguishing keyboard and process input. */
10543 if (connection
!= 0)
10544 add_keyboard_wait_descriptor (connection
);
10547 #ifndef F_SETOWN_BUG
10549 #ifdef F_SETOWN_SOCK_NEG
10550 /* stdin is a socket here */
10551 fcntl (connection
, F_SETOWN
, -getpid ());
10552 #else /* ! defined (F_SETOWN_SOCK_NEG) */
10553 fcntl (connection
, F_SETOWN
, getpid ());
10554 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
10555 #endif /* ! defined (F_SETOWN) */
10556 #endif /* F_SETOWN_BUG */
10559 if (interrupt_input
)
10560 init_sigio (connection
);
10561 #endif /* ! defined (SIGIO) */
10564 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
10565 /* Make sure that we have a valid font for dialog boxes
10566 so that Xt does not crash. */
10568 Display
*dpy
= dpyinfo
->display
;
10569 XrmValue d
, fr
, to
;
10572 d
.addr
= (XPointer
)&dpy
;
10573 d
.size
= sizeof (Display
*);
10574 fr
.addr
= XtDefaultFont
;
10575 fr
.size
= sizeof (XtDefaultFont
);
10576 to
.size
= sizeof (Font
*);
10577 to
.addr
= (XPointer
)&font
;
10578 x_catch_errors (dpy
);
10579 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10581 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10582 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10583 x_uncatch_errors ();
10588 /* See if we should run in synchronous mode. This is useful
10589 for debugging X code. */
10592 value
= display_x_get_resource (dpyinfo
,
10593 build_string ("synchronous"),
10594 build_string ("Synchronous"),
10596 if (STRINGP (value
)
10597 && (!strcmp (SDATA (value
), "true")
10598 || !strcmp (SDATA (value
), "on")))
10599 XSynchronize (dpyinfo
->display
, True
);
10604 value
= display_x_get_resource (dpyinfo
,
10605 build_string ("useXIM"),
10606 build_string ("UseXIM"),
10609 if (STRINGP (value
)
10610 && (!strcmp (XSTRING (value
)->data
, "false")
10611 || !strcmp (XSTRING (value
)->data
, "off")))
10614 if (STRINGP (value
)
10615 && (!strcmp (XSTRING (value
)->data
, "true")
10616 || !strcmp (XSTRING (value
)->data
, "on")))
10622 /* Only do this for the first display. */
10623 if (!x_session_initialized
++)
10624 x_session_initialize (dpyinfo
);
10632 /* Get rid of display DPYINFO, assuming all frames are already gone,
10633 and without sending any more commands to the X server. */
10636 x_delete_display (dpyinfo
)
10637 struct x_display_info
*dpyinfo
;
10641 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10643 /* Discard this display from x_display_name_list and x_display_list.
10644 We can't use Fdelq because that can quit. */
10645 if (! NILP (x_display_name_list
)
10646 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10647 x_display_name_list
= XCDR (x_display_name_list
);
10652 tail
= x_display_name_list
;
10653 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10655 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10657 XSETCDR (tail
, XCDR (XCDR (tail
)));
10660 tail
= XCDR (tail
);
10664 if (next_noop_dpyinfo
== dpyinfo
)
10665 next_noop_dpyinfo
= dpyinfo
->next
;
10667 if (x_display_list
== dpyinfo
)
10668 x_display_list
= dpyinfo
->next
;
10671 struct x_display_info
*tail
;
10673 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10674 if (tail
->next
== dpyinfo
)
10675 tail
->next
= tail
->next
->next
;
10678 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
10679 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
10680 XrmDestroyDatabase (dpyinfo
->xrdb
);
10683 #ifdef MULTI_KBOARD
10684 if (--dpyinfo
->kboard
->reference_count
== 0)
10685 delete_kboard (dpyinfo
->kboard
);
10689 xim_close_dpy (dpyinfo
);
10692 /* Free the font names in the font table. */
10693 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10694 if (dpyinfo
->font_table
[i
].name
)
10696 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
10697 xfree (dpyinfo
->font_table
[i
].full_name
);
10698 xfree (dpyinfo
->font_table
[i
].name
);
10701 if (dpyinfo
->font_table
->font_encoder
)
10702 xfree (dpyinfo
->font_table
->font_encoder
);
10704 xfree (dpyinfo
->font_table
);
10705 xfree (dpyinfo
->x_id_name
);
10706 xfree (dpyinfo
->color_cells
);
10710 #ifdef USE_X_TOOLKIT
10712 /* Atimer callback function for TIMER. Called every 0.1s to process
10713 Xt timeouts, if needed. We must avoid calling XtAppPending as
10714 much as possible because that function does an implicit XFlush
10715 that slows us down. */
10718 x_process_timeouts (timer
)
10719 struct atimer
*timer
;
10721 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10724 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10725 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10730 #endif /* USE_X_TOOLKIT */
10733 /* Set up use of X before we make the first connection. */
10735 extern frame_parm_handler x_frame_parm_handlers
[];
10737 static struct redisplay_interface x_redisplay_interface
=
10739 x_frame_parm_handlers
,
10743 x_clear_end_of_line
,
10745 x_after_update_window_line
,
10746 x_update_window_begin
,
10747 x_update_window_end
,
10753 0, /* flush_display_optional */
10755 x_clear_window_mouse_face
,
10756 x_get_glyph_overhangs
,
10757 x_fix_overlapping_area
,
10758 x_draw_fringe_bitmap
,
10759 0, /* define_fringe_bitmap */
10760 0, /* destroy_fringe_bitmap */
10763 x_compute_glyph_string_overhangs
,
10764 x_draw_glyph_string
,
10765 x_define_frame_cursor
,
10766 x_clear_frame_area
,
10767 x_draw_window_cursor
,
10768 x_draw_vertical_window_border
,
10769 x_shift_glyphs_for_insert
10775 rif
= &x_redisplay_interface
;
10777 clear_frame_hook
= x_clear_frame
;
10778 ins_del_lines_hook
= x_ins_del_lines
;
10779 delete_glyphs_hook
= x_delete_glyphs
;
10780 ring_bell_hook
= XTring_bell
;
10781 reset_terminal_modes_hook
= XTreset_terminal_modes
;
10782 set_terminal_modes_hook
= XTset_terminal_modes
;
10783 update_begin_hook
= x_update_begin
;
10784 update_end_hook
= x_update_end
;
10785 set_terminal_window_hook
= XTset_terminal_window
;
10786 read_socket_hook
= XTread_socket
;
10787 frame_up_to_date_hook
= XTframe_up_to_date
;
10788 mouse_position_hook
= XTmouse_position
;
10789 frame_rehighlight_hook
= XTframe_rehighlight
;
10790 frame_raise_lower_hook
= XTframe_raise_lower
;
10791 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10792 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10793 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10794 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10796 scroll_region_ok
= 1; /* we'll scroll partial frames */
10797 char_ins_del_ok
= 1;
10798 line_ins_del_ok
= 1; /* we'll just blt 'em */
10799 fast_clear_end_of_line
= 1; /* X does this well */
10800 memory_below_frame
= 0; /* we don't remember what scrolls
10805 last_tool_bar_item
= -1;
10806 any_help_event_p
= 0;
10807 ignore_next_mouse_click_timeout
= 0;
10809 x_session_initialized
= 0;
10813 current_count
= -1;
10816 /* Try to use interrupt input; if we can't, then start polling. */
10817 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
10819 #ifdef USE_X_TOOLKIT
10820 XtToolkitInitialize ();
10822 Xt_app_con
= XtCreateApplicationContext ();
10824 /* Register a converter from strings to pixels, which uses
10825 Emacs' color allocation infrastructure. */
10826 XtAppSetTypeConverter (Xt_app_con
,
10827 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10828 cvt_string_to_pixel_args
,
10829 XtNumber (cvt_string_to_pixel_args
),
10830 XtCacheByDisplay
, cvt_pixel_dtor
);
10832 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10834 /* Install an asynchronous timer that processes Xt timeout events
10835 every 0.1s. This is necessary because some widget sets use
10836 timeouts internally, for example the LessTif menu bar, or the
10837 Xaw3d scroll bar. When Xt timouts aren't processed, these
10838 widgets don't behave normally. */
10840 EMACS_TIME interval
;
10841 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10842 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
10846 #ifdef USE_TOOLKIT_SCROLL_BARS
10848 xaw3d_arrow_scroll
= False
;
10849 xaw3d_pick_top
= True
;
10853 /* Note that there is no real way portable across R3/R4 to get the
10854 original error handler. */
10855 XSetErrorHandler (x_error_handler
);
10856 XSetIOErrorHandler (x_io_error_quitter
);
10858 /* Disable Window Change signals; they are handled by X events. */
10860 signal (SIGWINCH
, SIG_DFL
);
10861 #endif /* SIGWINCH */
10863 signal (SIGPIPE
, x_connection_signal
);
10870 x_error_message
= NULL
;
10872 staticpro (&x_display_name_list
);
10873 x_display_name_list
= Qnil
;
10875 staticpro (&last_mouse_scroll_bar
);
10876 last_mouse_scroll_bar
= Qnil
;
10878 staticpro (&Qvendor_specific_keysyms
);
10879 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
10881 staticpro (&Qutf_8
);
10882 Qutf_8
= intern ("utf-8");
10883 staticpro (&Qlatin_1
);
10884 Qlatin_1
= intern ("latin-1");
10886 staticpro (&last_mouse_press_frame
);
10887 last_mouse_press_frame
= Qnil
;
10889 DEFVAR_BOOL ("x-use-underline-position-properties",
10890 &x_use_underline_position_properties
,
10891 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10892 nil means ignore them. If you encounter fonts with bogus
10893 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10894 to 4.1, set this to nil. */);
10895 x_use_underline_position_properties
= 1;
10897 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10898 &x_mouse_click_focus_ignore_position
,
10899 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10900 This variable is only used when the window manager requires that you
10901 click on a frame to select it (give it focus). In that case, a value
10902 of nil, means that the selected window and cursor position changes to
10903 reflect the mouse click position, while a non-nil value means that the
10904 selected window or cursor position is preserved. */);
10905 x_mouse_click_focus_ignore_position
= 0;
10907 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10908 doc
: /* What X toolkit scroll bars Emacs uses.
10909 A value of nil means Emacs doesn't use X toolkit scroll bars.
10910 Otherwise, value is a symbol describing the X toolkit. */);
10911 #ifdef USE_TOOLKIT_SCROLL_BARS
10913 Vx_toolkit_scroll_bars
= intern ("motif");
10914 #elif defined HAVE_XAW3D
10915 Vx_toolkit_scroll_bars
= intern ("xaw3d");
10917 Vx_toolkit_scroll_bars
= intern ("gtk");
10919 Vx_toolkit_scroll_bars
= intern ("xaw");
10922 Vx_toolkit_scroll_bars
= Qnil
;
10925 staticpro (&last_mouse_motion_frame
);
10926 last_mouse_motion_frame
= Qnil
;
10928 Qmodifier_value
= intern ("modifier-value");
10929 Qalt
= intern ("alt");
10930 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10931 Qhyper
= intern ("hyper");
10932 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10933 Qmeta
= intern ("meta");
10934 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10935 Qsuper
= intern ("super");
10936 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10938 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
10939 doc
: /* Which keys Emacs uses for the alt modifier.
10940 This should be one of the symbols `alt', `hyper', `meta', `super'.
10941 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10942 is nil, which is the same as `alt'. */);
10943 Vx_alt_keysym
= Qnil
;
10945 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
10946 doc
: /* Which keys Emacs uses for the hyper modifier.
10947 This should be one of the symbols `alt', `hyper', `meta', `super'.
10948 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10949 default is nil, which is the same as `hyper'. */);
10950 Vx_hyper_keysym
= Qnil
;
10952 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
10953 doc
: /* Which keys Emacs uses for the meta modifier.
10954 This should be one of the symbols `alt', `hyper', `meta', `super'.
10955 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10956 default is nil, which is the same as `meta'. */);
10957 Vx_meta_keysym
= Qnil
;
10959 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
10960 doc
: /* Which keys Emacs uses for the super modifier.
10961 This should be one of the symbols `alt', `hyper', `meta', `super'.
10962 For example, `super' means use the Super_L and Super_R keysyms. The
10963 default is nil, which is the same as `super'. */);
10964 Vx_super_keysym
= Qnil
;
10966 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
10967 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10968 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10969 make_float (DEFAULT_REHASH_SIZE
),
10970 make_float (DEFAULT_REHASH_THRESHOLD
),
10974 #endif /* HAVE_X_WINDOWS */
10976 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
10977 (do not change this comment) */