1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
74 #include "dispextern.h"
76 #include "termhooks.h"
84 #include "intervals.h"
90 #include <X11/Shell.h>
93 #ifdef HAVE_SYS_TIME_H
105 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
106 extern void xlwmenu_redisplay
P_ ((Widget
));
109 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
111 extern void free_frame_menubar
P_ ((struct frame
*));
112 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
117 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
119 extern void _XEditResCheckMessages ();
120 #endif /* not NO_EDITRES */
122 /* Include toolkit specific headers for the scroll bar widget. */
124 #ifdef USE_TOOLKIT_SCROLL_BARS
125 #if defined USE_MOTIF
126 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
127 #include <Xm/ScrollBar.h>
128 #else /* !USE_MOTIF i.e. use Xaw */
131 #include <X11/Xaw3d/Simple.h>
132 #include <X11/Xaw3d/Scrollbar.h>
133 #define ARROW_SCROLLBAR
134 #include <X11/Xaw3d/ScrollbarP.h>
135 #else /* !HAVE_XAW3D */
136 #include <X11/Xaw/Simple.h>
137 #include <X11/Xaw/Scrollbar.h>
138 #endif /* !HAVE_XAW3D */
140 #define XtNpickTop "pickTop"
141 #endif /* !XtNpickTop */
142 #endif /* !USE_MOTIF */
143 #endif /* USE_TOOLKIT_SCROLL_BARS */
145 #endif /* USE_X_TOOLKIT */
147 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
148 #define x_any_window_to_frame x_window_to_frame
149 #define x_top_window_to_frame x_window_to_frame
154 #ifndef XtNinitialState
155 #define XtNinitialState "initialState"
159 #define abs(x) ((x) < 0 ? -(x) : (x))
163 /* Non-nil means Emacs uses toolkit scroll bars. */
165 Lisp_Object Vx_toolkit_scroll_bars
;
167 /* Non-zero means that a HELP_EVENT has been generated since Emacs
170 static int any_help_event_p
;
172 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
173 static Lisp_Object last_window
;
175 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
177 int x_use_underline_position_properties
;
179 /* This is a chain of structures for all the X displays currently in
182 struct x_display_info
*x_display_list
;
184 /* This is a list of cons cells, each of the form (NAME
185 . FONT-LIST-CACHE), one for each element of x_display_list and in
186 the same order. NAME is the name of the frame. FONT-LIST-CACHE
187 records previous values returned by x-list-fonts. */
189 Lisp_Object x_display_name_list
;
191 /* Frame being updated by update_frame. This is declared in term.c.
192 This is set by update_begin and looked at by all the XT functions.
193 It is zero while not inside an update. In that case, the XT
194 functions assume that `selected_frame' is the frame to apply to. */
196 extern struct frame
*updating_frame
;
198 /* This is a frame waiting to be auto-raised, within XTread_socket. */
200 struct frame
*pending_autoraise_frame
;
203 /* The application context for Xt use. */
204 XtAppContext Xt_app_con
;
205 static String Xt_default_resources
[] = {0};
206 #endif /* USE_X_TOOLKIT */
208 /* Non-zero means user is interacting with a toolkit scroll bar. */
210 static int toolkit_scroll_bar_interaction
;
214 Formerly, we used PointerMotionHintMask (in standard_event_mask)
215 so that we would have to call XQueryPointer after each MotionNotify
216 event to ask for another such event. However, this made mouse tracking
217 slow, and there was a bug that made it eventually stop.
219 Simply asking for MotionNotify all the time seems to work better.
221 In order to avoid asking for motion events and then throwing most
222 of them away or busy-polling the server for mouse positions, we ask
223 the server for pointer motion hints. This means that we get only
224 one event per group of mouse movements. "Groups" are delimited by
225 other kinds of events (focus changes and button clicks, for
226 example), or by XQueryPointer calls; when one of these happens, we
227 get another MotionNotify event the next time the mouse moves. This
228 is at least as efficient as getting motion events when mouse
229 tracking is on, and I suspect only negligibly worse when tracking
232 /* Where the mouse was last time we reported a mouse event. */
234 static XRectangle last_mouse_glyph
;
235 static Lisp_Object last_mouse_press_frame
;
237 /* The scroll bar in which the last X motion event occurred.
239 If the last X motion event occurred in a scroll bar, we set this so
240 XTmouse_position can know whether to report a scroll bar motion or
243 If the last X motion event didn't occur in a scroll bar, we set
244 this to Qnil, to tell XTmouse_position to return an ordinary motion
247 static Lisp_Object last_mouse_scroll_bar
;
249 /* This is a hack. We would really prefer that XTmouse_position would
250 return the time associated with the position it returns, but there
251 doesn't seem to be any way to wrest the time-stamp from the server
252 along with the position query. So, we just keep track of the time
253 of the last movement we received, and return that in hopes that
254 it's somewhat accurate. */
256 static Time last_mouse_movement_time
;
258 /* Incremented by XTread_socket whenever it really tries to read
262 static int volatile input_signal_count
;
264 static int input_signal_count
;
267 /* Used locally within XTread_socket. */
269 static int x_noop_count
;
271 /* Initial values of argv and argc. */
273 extern char **initial_argv
;
274 extern int initial_argc
;
276 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
278 /* Tells if a window manager is present or not. */
280 extern Lisp_Object Vx_no_window_manager
;
282 extern Lisp_Object Qface
, Qmouse_face
, Qeql
;
286 /* A mask of extra modifier bits to put into every keyboard char. */
288 extern EMACS_INT extra_keyboard_modifiers
;
290 /* The keysyms to use for the various modifiers. */
292 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
293 Lisp_Object Vx_keysym_table
;
294 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
296 static Lisp_Object Qvendor_specific_keysyms
;
297 static Lisp_Object Qlatin_1
, Qutf_8
;
299 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
300 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
303 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
304 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
305 static const XColor
*x_color_cells
P_ ((Display
*, int *));
306 static void x_update_window_end
P_ ((struct window
*, int, int));
307 void x_delete_display
P_ ((struct x_display_info
*));
308 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
310 static int x_io_error_quitter
P_ ((Display
*));
311 int x_catch_errors
P_ ((Display
*));
312 void x_uncatch_errors
P_ ((Display
*, int));
313 void x_lower_frame
P_ ((struct frame
*));
314 void x_scroll_bar_clear
P_ ((struct frame
*));
315 int x_had_errors_p
P_ ((Display
*));
316 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
317 void x_raise_frame
P_ ((struct frame
*));
318 void x_set_window_size
P_ ((struct frame
*, int, int, int));
319 void x_wm_set_window_state
P_ ((struct frame
*, int));
320 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
321 void x_initialize
P_ ((void));
322 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
323 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
324 static void x_update_end
P_ ((struct frame
*));
325 static void XTframe_up_to_date
P_ ((struct frame
*));
326 static void XTset_terminal_modes
P_ ((void));
327 static void XTreset_terminal_modes
P_ ((void));
328 static void x_clear_frame
P_ ((void));
329 static void frame_highlight
P_ ((struct frame
*));
330 static void frame_unhighlight
P_ ((struct frame
*));
331 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
332 static int x_focus_changed
P_ ((int,
334 struct x_display_info
*,
336 struct input_event
*,
338 static int x_detect_focus_change
P_ ((struct x_display_info
*,
340 struct input_event
*,
342 static void XTframe_rehighlight
P_ ((struct frame
*));
343 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
344 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
345 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
346 enum text_cursor_kinds
));
348 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
350 static void x_flush
P_ ((struct frame
*f
));
351 static void x_update_begin
P_ ((struct frame
*));
352 static void x_update_window_begin
P_ ((struct window
*));
353 static void x_after_update_window_line
P_ ((struct glyph_row
*));
354 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
355 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
356 enum scroll_bar_part
*,
357 Lisp_Object
*, Lisp_Object
*,
359 static void x_check_fullscreen
P_ ((struct frame
*));
360 static void x_check_fullscreen_move
P_ ((struct frame
*));
361 static int handle_one_xevent
P_ ((struct x_display_info
*,
363 struct input_event
**,
368 /* Flush display of frame F, or of all frames if F is null. */
377 Lisp_Object rest
, frame
;
378 FOR_EACH_FRAME (rest
, frame
)
379 x_flush (XFRAME (frame
));
381 else if (FRAME_X_P (f
))
382 XFlush (FRAME_X_DISPLAY (f
));
387 /* Remove calls to XFlush by defining XFlush to an empty replacement.
388 Calls to XFlush should be unnecessary because the X output buffer
389 is flushed automatically as needed by calls to XPending,
390 XNextEvent, or XWindowEvent according to the XFlush man page.
391 XTread_socket calls XPending. Removing XFlush improves
394 #define XFlush(DISPLAY) (void) 0
397 /***********************************************************************
399 ***********************************************************************/
403 /* This is a function useful for recording debugging information about
404 the sequence of occurrences in this file. */
412 struct record event_record
[100];
414 int event_record_index
;
416 record_event (locus
, type
)
420 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
421 event_record_index
= 0;
423 event_record
[event_record_index
].locus
= locus
;
424 event_record
[event_record_index
].type
= type
;
425 event_record_index
++;
432 /* Return the struct x_display_info corresponding to DPY. */
434 struct x_display_info
*
435 x_display_info_for_display (dpy
)
438 struct x_display_info
*dpyinfo
;
440 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
441 if (dpyinfo
->display
== dpy
)
449 /***********************************************************************
450 Starting and ending an update
451 ***********************************************************************/
453 /* Start an update of frame F. This function is installed as a hook
454 for update_begin, i.e. it is called when update_begin is called.
455 This function is called prior to calls to x_update_window_begin for
456 each window being updated. Currently, there is nothing to do here
457 because all interesting stuff is done on a window basis. */
467 /* Start update of window W. Set the global variable updated_window
468 to the window being updated and set output_cursor to the cursor
472 x_update_window_begin (w
)
475 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
476 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
479 set_output_cursor (&w
->cursor
);
483 if (f
== display_info
->mouse_face_mouse_frame
)
485 /* Don't do highlighting for mouse motion during the update. */
486 display_info
->mouse_face_defer
= 1;
488 /* If F needs to be redrawn, simply forget about any prior mouse
490 if (FRAME_GARBAGED_P (f
))
491 display_info
->mouse_face_window
= Qnil
;
493 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
494 their mouse_face_p flag set, which means that they are always
495 unequal to rows in a desired matrix which never have that
496 flag set. So, rows containing mouse-face glyphs are never
497 scrolled, and we don't have to switch the mouse highlight off
498 here to prevent it from being scrolled. */
500 /* Can we tell that this update does not affect the window
501 where the mouse highlight is? If so, no need to turn off.
502 Likewise, don't do anything if the frame is garbaged;
503 in that case, the frame's current matrix that we would use
504 is all wrong, and we will redisplay that line anyway. */
505 if (!NILP (display_info
->mouse_face_window
)
506 && w
== XWINDOW (display_info
->mouse_face_window
))
510 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
511 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
514 if (i
< w
->desired_matrix
->nrows
)
515 clear_mouse_face (display_info
);
524 /* Draw a vertical window border from (x,y0) to (x,y1) */
527 x_draw_vertical_window_border (w
, x
, y0
, y1
)
531 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
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 x_draw_vertical_border (w
);
570 /* If a row with mouse-face was overwritten, arrange for
571 XTframe_up_to_date to redisplay the mouse highlight. */
572 if (mouse_face_overwritten_p
)
574 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
575 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
576 dpyinfo
->mouse_face_window
= Qnil
;
579 updated_window
= NULL
;
583 /* End update of frame F. This function is installed as a hook in
590 /* Mouse highlight may be displayed again. */
591 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
595 XFlush (FRAME_X_DISPLAY (f
));
601 /* This function is called from various places in xdisp.c whenever a
602 complete update has been performed. The global variable
603 updated_window is not available here. */
606 XTframe_up_to_date (f
)
611 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
613 if (dpyinfo
->mouse_face_deferred_gc
614 || f
== dpyinfo
->mouse_face_mouse_frame
)
617 if (dpyinfo
->mouse_face_mouse_frame
)
618 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
619 dpyinfo
->mouse_face_mouse_x
,
620 dpyinfo
->mouse_face_mouse_y
);
621 dpyinfo
->mouse_face_deferred_gc
= 0;
628 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
629 arrow bitmaps, or clear the fringes if no bitmaps are required
630 before DESIRED_ROW is made current. The window being updated is
631 found in updated_window. This function It is called from
632 update_window_line only if it is known that there are differences
633 between bitmaps to be drawn between current row and DESIRED_ROW. */
636 x_after_update_window_line (desired_row
)
637 struct glyph_row
*desired_row
;
639 struct window
*w
= updated_window
;
645 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
648 draw_row_fringe_bitmaps (w
, desired_row
);
652 /* When a window has disappeared, make sure that no rest of
653 full-width rows stays visible in the internal border. Could
654 check here if updated_window is the leftmost/rightmost window,
655 but I guess it's not worth doing since vertically split windows
656 are almost never used, internal border is rarely set, and the
657 overhead is very small. */
658 if (windows_or_buffers_changed
659 && desired_row
->full_width_p
660 && (f
= XFRAME (w
->frame
),
661 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
663 && (height
= desired_row
->visible_height
,
666 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
668 /* Internal border is drawn below the tool bar. */
669 if (WINDOWP (f
->tool_bar_window
)
670 && w
== XWINDOW (f
->tool_bar_window
))
674 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
675 0, y
, width
, height
, False
);
676 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
677 f
->output_data
.x
->pixel_width
- width
,
678 y
, width
, height
, False
);
684 x_draw_fringe_bitmap (w
, row
, p
)
686 struct glyph_row
*row
;
687 struct draw_fringe_bitmap_params
*p
;
689 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
690 Display
*display
= FRAME_X_DISPLAY (f
);
691 Window window
= FRAME_X_WINDOW (f
);
692 GC gc
= f
->output_data
.x
->normal_gc
;
693 struct face
*face
= p
->face
;
695 /* Must clip because of partially visible lines. */
696 x_clip_to_row (w
, row
, gc
, 1);
700 /* In case the same realized face is used for fringes and
701 for something displayed in the text (e.g. face `region' on
702 mono-displays, the fill style may have been changed to
703 FillSolid in x_draw_glyph_string_background. */
705 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
707 XSetForeground (display
, face
->gc
, face
->background
);
709 XFillRectangle (display
, window
, face
->gc
,
710 p
->bx
, p
->by
, p
->nx
, p
->ny
);
713 XSetForeground (display
, face
->gc
, face
->foreground
);
716 if (p
->which
!= NO_FRINGE_BITMAP
)
718 unsigned char *bits
= fringe_bitmaps
[p
->which
].bits
+ p
->dh
;
720 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
722 /* Draw the bitmap. I believe these small pixmaps can be cached
724 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
726 face
->background
, depth
);
727 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
728 p
->wd
, p
->h
, p
->x
, p
->y
);
729 XFreePixmap (display
, pixmap
);
732 XSetClipMask (display
, gc
, None
);
737 /* This is called when starting Emacs and when restarting after
738 suspend. When starting Emacs, no X window is mapped. And nothing
739 must be done to Emacs's own window if it is suspended (though that
743 XTset_terminal_modes ()
747 /* This is called when exiting or suspending Emacs. Exiting will make
748 the X-windows go away, and suspending requires no action. */
751 XTreset_terminal_modes ()
757 /***********************************************************************
759 ***********************************************************************/
761 /* Function prototypes of this page. */
763 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
766 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
767 is not contained in the font. */
770 x_per_char_metric (font
, char2b
, font_type
)
773 int font_type
; /* unused on X */
775 /* The result metric information. */
776 XCharStruct
*pcm
= NULL
;
778 xassert (font
&& char2b
);
780 if (font
->per_char
!= NULL
)
782 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
784 /* min_char_or_byte2 specifies the linear character index
785 corresponding to the first element of the per_char array,
786 max_char_or_byte2 is the index of the last character. A
787 character with non-zero CHAR2B->byte1 is not in the font.
788 A character with byte2 less than min_char_or_byte2 or
789 greater max_char_or_byte2 is not in the font. */
790 if (char2b
->byte1
== 0
791 && char2b
->byte2
>= font
->min_char_or_byte2
792 && char2b
->byte2
<= font
->max_char_or_byte2
)
793 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
797 /* If either min_byte1 or max_byte1 are nonzero, both
798 min_char_or_byte2 and max_char_or_byte2 are less than
799 256, and the 2-byte character index values corresponding
800 to the per_char array element N (counting from 0) are:
802 byte1 = N/D + min_byte1
803 byte2 = N\D + min_char_or_byte2
807 D = max_char_or_byte2 - min_char_or_byte2 + 1
809 \ = integer modulus */
810 if (char2b
->byte1
>= font
->min_byte1
811 && char2b
->byte1
<= font
->max_byte1
812 && char2b
->byte2
>= font
->min_char_or_byte2
813 && char2b
->byte2
<= font
->max_char_or_byte2
)
815 pcm
= (font
->per_char
816 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
817 * (char2b
->byte1
- font
->min_byte1
))
818 + (char2b
->byte2
- font
->min_char_or_byte2
));
824 /* If the per_char pointer is null, all glyphs between the first
825 and last character indexes inclusive have the same
826 information, as given by both min_bounds and max_bounds. */
827 if (char2b
->byte2
>= font
->min_char_or_byte2
828 && char2b
->byte2
<= font
->max_char_or_byte2
)
829 pcm
= &font
->max_bounds
;
833 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
838 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
839 the two-byte form of C. Encoding is returned in *CHAR2B. */
842 x_encode_char (c
, char2b
, font_info
, two_byte_p
)
845 struct font_info
*font_info
;
848 int charset
= CHAR_CHARSET (c
);
849 XFontStruct
*font
= font_info
->font
;
851 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
852 This may be either a program in a special encoder language or a
854 if (font_info
->font_encoder
)
856 /* It's a program. */
857 struct ccl_program
*ccl
= font_info
->font_encoder
;
859 if (CHARSET_DIMENSION (charset
) == 1)
861 ccl
->reg
[0] = charset
;
862 ccl
->reg
[1] = char2b
->byte2
;
867 ccl
->reg
[0] = charset
;
868 ccl
->reg
[1] = char2b
->byte1
;
869 ccl
->reg
[2] = char2b
->byte2
;
872 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
874 /* We assume that MSBs are appropriately set/reset by CCL
876 if (font
->max_byte1
== 0) /* 1-byte font */
877 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
879 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
881 else if (font_info
->encoding
[charset
])
883 /* Fixed encoding scheme. See fontset.h for the meaning of the
885 int enc
= font_info
->encoding
[charset
];
887 if ((enc
== 1 || enc
== 2)
888 && CHARSET_DIMENSION (charset
) == 2)
889 char2b
->byte1
|= 0x80;
891 if (enc
== 1 || enc
== 3)
892 char2b
->byte2
|= 0x80;
896 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
898 return FONT_TYPE_UNKNOWN
;
903 /***********************************************************************
905 ***********************************************************************/
909 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
910 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
911 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
913 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
914 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
915 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
916 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
917 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
918 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
919 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
920 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
921 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
922 unsigned long *, double, int));
923 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
924 double, int, unsigned long));
925 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
926 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
927 static void x_draw_image_relief
P_ ((struct glyph_string
*));
928 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
929 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
930 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
932 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
933 int, int, int, int, XRectangle
*));
934 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
935 int, int, int, XRectangle
*));
938 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
942 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
947 struct glyph_string
*s
;
949 if (s
->font
== FRAME_FONT (s
->f
)
950 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
951 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
953 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
956 /* Cursor on non-default face: must merge. */
960 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
961 xgcv
.foreground
= s
->face
->background
;
963 /* If the glyph would be invisible, try a different foreground. */
964 if (xgcv
.foreground
== xgcv
.background
)
965 xgcv
.foreground
= s
->face
->foreground
;
966 if (xgcv
.foreground
== xgcv
.background
)
967 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
968 if (xgcv
.foreground
== xgcv
.background
)
969 xgcv
.foreground
= s
->face
->foreground
;
971 /* Make sure the cursor is distinct from text in this face. */
972 if (xgcv
.background
== s
->face
->background
973 && xgcv
.foreground
== s
->face
->foreground
)
975 xgcv
.background
= s
->face
->foreground
;
976 xgcv
.foreground
= s
->face
->background
;
979 IF_DEBUG (x_check_font (s
->f
, s
->font
));
980 xgcv
.font
= s
->font
->fid
;
981 xgcv
.graphics_exposures
= False
;
982 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
984 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
985 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
988 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
989 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
991 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
996 /* Set up S->gc of glyph string S for drawing text in mouse face. */
999 x_set_mouse_face_gc (s
)
1000 struct glyph_string
*s
;
1005 /* What face has to be used last for the mouse face? */
1006 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1007 face
= FACE_FROM_ID (s
->f
, face_id
);
1009 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1011 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1012 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
1014 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
1015 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1016 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1018 /* If font in this face is same as S->font, use it. */
1019 if (s
->font
== s
->face
->font
)
1020 s
->gc
= s
->face
->gc
;
1023 /* Otherwise construct scratch_cursor_gc with values from FACE
1028 xgcv
.background
= s
->face
->background
;
1029 xgcv
.foreground
= s
->face
->foreground
;
1030 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1031 xgcv
.font
= s
->font
->fid
;
1032 xgcv
.graphics_exposures
= False
;
1033 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1035 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1036 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1039 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1040 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1042 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1045 xassert (s
->gc
!= 0);
1049 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1050 Faces to use in the mode line have already been computed when the
1051 matrix was built, so there isn't much to do, here. */
1054 x_set_mode_line_face_gc (s
)
1055 struct glyph_string
*s
;
1057 s
->gc
= s
->face
->gc
;
1061 /* Set S->gc of glyph string S for drawing that glyph string. Set
1062 S->stippled_p to a non-zero value if the face of S has a stipple
1066 x_set_glyph_string_gc (s
)
1067 struct glyph_string
*s
;
1069 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1071 if (s
->hl
== DRAW_NORMAL_TEXT
)
1073 s
->gc
= s
->face
->gc
;
1074 s
->stippled_p
= s
->face
->stipple
!= 0;
1076 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1078 x_set_mode_line_face_gc (s
);
1079 s
->stippled_p
= s
->face
->stipple
!= 0;
1081 else if (s
->hl
== DRAW_CURSOR
)
1083 x_set_cursor_gc (s
);
1086 else if (s
->hl
== DRAW_MOUSE_FACE
)
1088 x_set_mouse_face_gc (s
);
1089 s
->stippled_p
= s
->face
->stipple
!= 0;
1091 else if (s
->hl
== DRAW_IMAGE_RAISED
1092 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1094 s
->gc
= s
->face
->gc
;
1095 s
->stippled_p
= s
->face
->stipple
!= 0;
1099 s
->gc
= s
->face
->gc
;
1100 s
->stippled_p
= s
->face
->stipple
!= 0;
1103 /* GC must have been set. */
1104 xassert (s
->gc
!= 0);
1108 /* Set clipping for output of glyph string S. S may be part of a mode
1109 line or menu if we don't have X toolkit support. */
1112 x_set_glyph_string_clipping (s
)
1113 struct glyph_string
*s
;
1116 get_glyph_string_clip_rect (s
, &r
);
1117 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
1122 Compute left and right overhang of glyph string S. If S is a glyph
1123 string for a composition, assume overhangs don't exist. */
1126 x_compute_glyph_string_overhangs (s
)
1127 struct glyph_string
*s
;
1130 && s
->first_glyph
->type
== CHAR_GLYPH
)
1133 int direction
, font_ascent
, font_descent
;
1134 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1135 &font_ascent
, &font_descent
, &cs
);
1136 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1137 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1142 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1145 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1146 struct glyph_string
*s
;
1150 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1151 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1152 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1153 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1157 /* Draw the background of glyph_string S. If S->background_filled_p
1158 is non-zero don't draw it. FORCE_P non-zero means draw the
1159 background even if it wouldn't be drawn normally. This is used
1160 when a string preceding S draws into the background of S, or S
1161 contains the first component of a composition. */
1164 x_draw_glyph_string_background (s
, force_p
)
1165 struct glyph_string
*s
;
1168 /* Nothing to do if background has already been drawn or if it
1169 shouldn't be drawn in the first place. */
1170 if (!s
->background_filled_p
)
1172 int box_line_width
= max (s
->face
->box_line_width
, 0);
1176 /* Fill background with a stipple pattern. */
1177 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1178 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1179 s
->y
+ box_line_width
,
1180 s
->background_width
,
1181 s
->height
- 2 * box_line_width
);
1182 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1183 s
->background_filled_p
= 1;
1185 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1186 || s
->font_not_found_p
1187 || s
->extends_to_end_of_line_p
1190 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1191 s
->background_width
,
1192 s
->height
- 2 * box_line_width
);
1193 s
->background_filled_p
= 1;
1199 /* Draw the foreground of glyph string S. */
1202 x_draw_glyph_string_foreground (s
)
1203 struct glyph_string
*s
;
1207 /* If first glyph of S has a left box line, start drawing the text
1208 of S to the right of that box line. */
1209 if (s
->face
->box
!= FACE_NO_BOX
1210 && s
->first_glyph
->left_box_line_p
)
1211 x
= s
->x
+ abs (s
->face
->box_line_width
);
1215 /* Draw characters of S as rectangles if S's font could not be
1217 if (s
->font_not_found_p
)
1219 for (i
= 0; i
< s
->nchars
; ++i
)
1221 struct glyph
*g
= s
->first_glyph
+ i
;
1222 XDrawRectangle (s
->display
, s
->window
,
1223 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1225 x
+= g
->pixel_width
;
1230 char *char1b
= (char *) s
->char2b
;
1231 int boff
= s
->font_info
->baseline_offset
;
1233 if (s
->font_info
->vertical_centering
)
1234 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1236 /* If we can use 8-bit functions, condense S->char2b. */
1238 for (i
= 0; i
< s
->nchars
; ++i
)
1239 char1b
[i
] = s
->char2b
[i
].byte2
;
1241 /* Draw text with XDrawString if background has already been
1242 filled. Otherwise, use XDrawImageString. (Note that
1243 XDrawImageString is usually faster than XDrawString.) Always
1244 use XDrawImageString when drawing the cursor so that there is
1245 no chance that characters under a box cursor are invisible. */
1246 if (s
->for_overlaps_p
1247 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1249 /* Draw characters with 16-bit or 8-bit functions. */
1251 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1252 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1254 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1255 s
->ybase
- boff
, char1b
, s
->nchars
);
1260 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1261 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1263 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1264 s
->ybase
- boff
, char1b
, s
->nchars
);
1267 if (s
->face
->overstrike
)
1269 /* For overstriking (to simulate bold-face), draw the
1270 characters again shifted to the right by one pixel. */
1272 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1273 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1275 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1276 s
->ybase
- boff
, char1b
, s
->nchars
);
1281 /* Draw the foreground of composite glyph string S. */
1284 x_draw_composite_glyph_string_foreground (s
)
1285 struct glyph_string
*s
;
1289 /* If first glyph of S has a left box line, start drawing the text
1290 of S to the right of that box line. */
1291 if (s
->face
->box
!= FACE_NO_BOX
1292 && s
->first_glyph
->left_box_line_p
)
1293 x
= s
->x
+ abs (s
->face
->box_line_width
);
1297 /* S is a glyph string for a composition. S->gidx is the index of
1298 the first character drawn for glyphs of this composition.
1299 S->gidx == 0 means we are drawing the very first character of
1300 this composition. */
1302 /* Draw a rectangle for the composition if the font for the very
1303 first character of the composition could not be loaded. */
1304 if (s
->font_not_found_p
)
1307 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1308 s
->width
- 1, s
->height
- 1);
1312 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
1314 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1315 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
1316 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1318 if (s
->face
->overstrike
)
1319 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1320 x
+ s
->cmp
->offsets
[s
->gidx
* 2] + 1,
1321 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1328 #ifdef USE_X_TOOLKIT
1330 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1331 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1332 XrmValue
*, XrmValue
*, XtPointer
*));
1333 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1334 XrmValue
*, Cardinal
*));
1337 /* Return the frame on which widget WIDGET is used.. Abort if frame
1338 cannot be determined. */
1340 static struct frame
*
1341 x_frame_of_widget (widget
)
1344 struct x_display_info
*dpyinfo
;
1348 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1350 /* Find the top-level shell of the widget. Note that this function
1351 can be called when the widget is not yet realized, so XtWindow
1352 (widget) == 0. That's the reason we can't simply use
1353 x_any_window_to_frame. */
1354 while (!XtIsTopLevelShell (widget
))
1355 widget
= XtParent (widget
);
1357 /* Look for a frame with that top-level widget. Allocate the color
1358 on that frame to get the right gamma correction value. */
1359 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
1360 if (GC_FRAMEP (XCAR (tail
))
1361 && (f
= XFRAME (XCAR (tail
)),
1362 (f
->output_data
.nothing
!= 1
1363 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1364 && f
->output_data
.x
->widget
== widget
)
1371 /* Allocate the color COLOR->pixel on the screen and display of
1372 widget WIDGET in colormap CMAP. If an exact match cannot be
1373 allocated, try the nearest color available. Value is non-zero
1374 if successful. This is called from lwlib. */
1377 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1382 struct frame
*f
= x_frame_of_widget (widget
);
1383 return x_alloc_nearest_color (f
, cmap
, color
);
1387 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1388 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1389 If this produces the same color as PIXEL, try a color where all RGB
1390 values have DELTA added. Return the allocated color in *PIXEL.
1391 DISPLAY is the X display, CMAP is the colormap to operate on.
1392 Value is non-zero if successful. */
1395 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1399 unsigned long *pixel
;
1403 struct frame
*f
= x_frame_of_widget (widget
);
1404 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1408 /* Structure specifying which arguments should be passed by Xt to
1409 cvt_string_to_pixel. We want the widget's screen and colormap. */
1411 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1413 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1415 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1420 /* The address of this variable is returned by
1421 cvt_string_to_pixel. */
1423 static Pixel cvt_string_to_pixel_value
;
1426 /* Convert a color name to a pixel color.
1428 DPY is the display we are working on.
1430 ARGS is an array of *NARGS XrmValue structures holding additional
1431 information about the widget for which the conversion takes place.
1432 The contents of this array are determined by the specification
1433 in cvt_string_to_pixel_args.
1435 FROM is a pointer to an XrmValue which points to the color name to
1436 convert. TO is an XrmValue in which to return the pixel color.
1438 CLOSURE_RET is a pointer to user-data, in which we record if
1439 we allocated the color or not.
1441 Value is True if successful, False otherwise. */
1444 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1448 XrmValue
*from
, *to
;
1449 XtPointer
*closure_ret
;
1459 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1460 "wrongParameters", "cvt_string_to_pixel",
1462 "Screen and colormap args required", NULL
, NULL
);
1466 screen
= *(Screen
**) args
[0].addr
;
1467 cmap
= *(Colormap
*) args
[1].addr
;
1468 color_name
= (String
) from
->addr
;
1470 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1472 *closure_ret
= (XtPointer
) False
;
1473 pixel
= WhitePixelOfScreen (screen
);
1475 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1477 *closure_ret
= (XtPointer
) False
;
1478 pixel
= BlackPixelOfScreen (screen
);
1480 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1481 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1483 pixel
= color
.pixel
;
1484 *closure_ret
= (XtPointer
) True
;
1489 Cardinal nparams
= 1;
1491 params
[0] = color_name
;
1492 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1493 "badValue", "cvt_string_to_pixel",
1494 "XtToolkitError", "Invalid color `%s'",
1499 if (to
->addr
!= NULL
)
1501 if (to
->size
< sizeof (Pixel
))
1503 to
->size
= sizeof (Pixel
);
1507 *(Pixel
*) to
->addr
= pixel
;
1511 cvt_string_to_pixel_value
= pixel
;
1512 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1515 to
->size
= sizeof (Pixel
);
1520 /* Free a pixel color which was previously allocated via
1521 cvt_string_to_pixel. This is registered as the destructor
1522 for this type of resource via XtSetTypeConverter.
1524 APP is the application context in which we work.
1526 TO is a pointer to an XrmValue holding the color to free.
1527 CLOSURE is the value we stored in CLOSURE_RET for this color
1528 in cvt_string_to_pixel.
1530 ARGS and NARGS are like for cvt_string_to_pixel. */
1533 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1542 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1544 "Screen and colormap arguments required",
1547 else if (closure
!= NULL
)
1549 /* We did allocate the pixel, so free it. */
1550 Screen
*screen
= *(Screen
**) args
[0].addr
;
1551 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1552 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1553 (Pixel
*) to
->addr
, 1);
1558 #endif /* USE_X_TOOLKIT */
1561 /* Value is an array of XColor structures for the contents of the
1562 color map of display DPY. Set *NCELLS to the size of the array.
1563 Note that this probably shouldn't be called for large color maps,
1564 say a 24-bit TrueColor map. */
1566 static const XColor
*
1567 x_color_cells (dpy
, ncells
)
1571 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1573 if (dpyinfo
->color_cells
== NULL
)
1575 Screen
*screen
= dpyinfo
->screen
;
1578 dpyinfo
->ncolor_cells
1579 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1580 dpyinfo
->color_cells
1581 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1582 * sizeof *dpyinfo
->color_cells
);
1584 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1585 dpyinfo
->color_cells
[i
].pixel
= i
;
1587 XQueryColors (dpy
, dpyinfo
->cmap
,
1588 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1591 *ncells
= dpyinfo
->ncolor_cells
;
1592 return dpyinfo
->color_cells
;
1596 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1597 colors in COLORS. Use cached information, if available. */
1600 x_query_colors (f
, colors
, ncolors
)
1605 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1607 if (dpyinfo
->color_cells
)
1610 for (i
= 0; i
< ncolors
; ++i
)
1612 unsigned long pixel
= colors
[i
].pixel
;
1613 xassert (pixel
< dpyinfo
->ncolor_cells
);
1614 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1615 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1619 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1623 /* On frame F, translate pixel color to RGB values for the color in
1624 COLOR. Use cached information, if available. */
1627 x_query_color (f
, color
)
1631 x_query_colors (f
, color
, 1);
1635 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1636 exact match can't be allocated, try the nearest color available.
1637 Value is non-zero if successful. Set *COLOR to the color
1641 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1648 rc
= XAllocColor (dpy
, cmap
, color
);
1651 /* If we got to this point, the colormap is full, so we're going
1652 to try to get the next closest color. The algorithm used is
1653 a least-squares matching, which is what X uses for closest
1654 color matching with StaticColor visuals. */
1656 unsigned long nearest_delta
= ~0;
1658 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1660 for (nearest
= i
= 0; i
< ncells
; ++i
)
1662 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1663 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1664 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1665 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1667 if (delta
< nearest_delta
)
1670 nearest_delta
= delta
;
1674 color
->red
= cells
[nearest
].red
;
1675 color
->green
= cells
[nearest
].green
;
1676 color
->blue
= cells
[nearest
].blue
;
1677 rc
= XAllocColor (dpy
, cmap
, color
);
1681 /* If allocation succeeded, and the allocated pixel color is not
1682 equal to a cached pixel color recorded earlier, there was a
1683 change in the colormap, so clear the color cache. */
1684 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1685 XColor
*cached_color
;
1687 if (dpyinfo
->color_cells
1688 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1689 (cached_color
->red
!= color
->red
1690 || cached_color
->blue
!= color
->blue
1691 || cached_color
->green
!= color
->green
)))
1693 xfree (dpyinfo
->color_cells
);
1694 dpyinfo
->color_cells
= NULL
;
1695 dpyinfo
->ncolor_cells
= 0;
1699 #ifdef DEBUG_X_COLORS
1701 register_color (color
->pixel
);
1702 #endif /* DEBUG_X_COLORS */
1708 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1709 exact match can't be allocated, try the nearest color available.
1710 Value is non-zero if successful. Set *COLOR to the color
1714 x_alloc_nearest_color (f
, cmap
, color
)
1719 gamma_correct (f
, color
);
1720 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1724 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1725 It's necessary to do this instead of just using PIXEL directly to
1726 get color reference counts right. */
1729 x_copy_color (f
, pixel
)
1731 unsigned long pixel
;
1735 color
.pixel
= pixel
;
1737 x_query_color (f
, &color
);
1738 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1740 #ifdef DEBUG_X_COLORS
1741 register_color (pixel
);
1747 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1748 It's necessary to do this instead of just using PIXEL directly to
1749 get color reference counts right. */
1752 x_copy_dpy_color (dpy
, cmap
, pixel
)
1755 unsigned long pixel
;
1759 color
.pixel
= pixel
;
1761 XQueryColor (dpy
, cmap
, &color
);
1762 XAllocColor (dpy
, cmap
, &color
);
1764 #ifdef DEBUG_X_COLORS
1765 register_color (pixel
);
1771 /* Brightness beyond which a color won't have its highlight brightness
1774 Nominally, highlight colors for `3d' faces are calculated by
1775 brightening an object's color by a constant scale factor, but this
1776 doesn't yield good results for dark colors, so for colors who's
1777 brightness is less than this value (on a scale of 0-65535) have an
1778 use an additional additive factor.
1780 The value here is set so that the default menu-bar/mode-line color
1781 (grey75) will not have its highlights changed at all. */
1782 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1785 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1786 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1787 If this produces the same color as PIXEL, try a color where all RGB
1788 values have DELTA added. Return the allocated color in *PIXEL.
1789 DISPLAY is the X display, CMAP is the colormap to operate on.
1790 Value is non-zero if successful. */
1793 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
1797 unsigned long *pixel
;
1805 /* Get RGB color values. */
1806 color
.pixel
= *pixel
;
1807 x_query_color (f
, &color
);
1809 /* Change RGB values by specified FACTOR. Avoid overflow! */
1810 xassert (factor
>= 0);
1811 new.red
= min (0xffff, factor
* color
.red
);
1812 new.green
= min (0xffff, factor
* color
.green
);
1813 new.blue
= min (0xffff, factor
* color
.blue
);
1815 /* Calculate brightness of COLOR. */
1816 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1818 /* We only boost colors that are darker than
1819 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1820 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1821 /* Make an additive adjustment to NEW, because it's dark enough so
1822 that scaling by FACTOR alone isn't enough. */
1824 /* How far below the limit this color is (0 - 1, 1 being darker). */
1825 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1826 /* The additive adjustment. */
1827 int min_delta
= delta
* dimness
* factor
/ 2;
1831 new.red
= max (0, new.red
- min_delta
);
1832 new.green
= max (0, new.green
- min_delta
);
1833 new.blue
= max (0, new.blue
- min_delta
);
1837 new.red
= min (0xffff, min_delta
+ new.red
);
1838 new.green
= min (0xffff, min_delta
+ new.green
);
1839 new.blue
= min (0xffff, min_delta
+ new.blue
);
1843 /* Try to allocate the color. */
1844 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1847 if (new.pixel
== *pixel
)
1849 /* If we end up with the same color as before, try adding
1850 delta to the RGB values. */
1851 x_free_colors (f
, &new.pixel
, 1);
1853 new.red
= min (0xffff, delta
+ color
.red
);
1854 new.green
= min (0xffff, delta
+ color
.green
);
1855 new.blue
= min (0xffff, delta
+ color
.blue
);
1856 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1867 /* Set up the foreground color for drawing relief lines of glyph
1868 string S. RELIEF is a pointer to a struct relief containing the GC
1869 with which lines will be drawn. Use a color that is FACTOR or
1870 DELTA lighter or darker than the relief's background which is found
1871 in S->f->output_data.x->relief_background. If such a color cannot
1872 be allocated, use DEFAULT_PIXEL, instead. */
1875 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1877 struct relief
*relief
;
1880 unsigned long default_pixel
;
1883 struct x_output
*di
= f
->output_data
.x
;
1884 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1885 unsigned long pixel
;
1886 unsigned long background
= di
->relief_background
;
1887 Colormap cmap
= FRAME_X_COLORMAP (f
);
1888 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1889 Display
*dpy
= FRAME_X_DISPLAY (f
);
1891 xgcv
.graphics_exposures
= False
;
1892 xgcv
.line_width
= 1;
1894 /* Free previously allocated color. The color cell will be reused
1895 when it has been freed as many times as it was allocated, so this
1896 doesn't affect faces using the same colors. */
1898 && relief
->allocated_p
)
1900 x_free_colors (f
, &relief
->pixel
, 1);
1901 relief
->allocated_p
= 0;
1904 /* Allocate new color. */
1905 xgcv
.foreground
= default_pixel
;
1907 if (dpyinfo
->n_planes
!= 1
1908 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1910 relief
->allocated_p
= 1;
1911 xgcv
.foreground
= relief
->pixel
= pixel
;
1914 if (relief
->gc
== 0)
1916 xgcv
.stipple
= dpyinfo
->gray
;
1918 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1921 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1925 /* Set up colors for the relief lines around glyph string S. */
1928 x_setup_relief_colors (s
)
1929 struct glyph_string
*s
;
1931 struct x_output
*di
= s
->f
->output_data
.x
;
1932 unsigned long color
;
1934 if (s
->face
->use_box_color_for_shadows_p
)
1935 color
= s
->face
->box_color
;
1936 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1938 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1939 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1944 /* Get the background color of the face. */
1945 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1946 color
= xgcv
.background
;
1949 if (di
->white_relief
.gc
== 0
1950 || color
!= di
->relief_background
)
1952 di
->relief_background
= color
;
1953 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1954 WHITE_PIX_DEFAULT (s
->f
));
1955 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1956 BLACK_PIX_DEFAULT (s
->f
));
1961 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1962 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1963 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1964 relief. LEFT_P non-zero means draw a relief on the left side of
1965 the rectangle. RIGHT_P non-zero means draw a relief on the right
1966 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1970 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
1971 raised_p
, left_p
, right_p
, clip_rect
)
1973 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
, raised_p
;
1974 XRectangle
*clip_rect
;
1976 Display
*dpy
= FRAME_X_DISPLAY (f
);
1977 Window window
= FRAME_X_WINDOW (f
);
1982 gc
= f
->output_data
.x
->white_relief
.gc
;
1984 gc
= f
->output_data
.x
->black_relief
.gc
;
1985 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1988 for (i
= 0; i
< width
; ++i
)
1989 XDrawLine (dpy
, window
, gc
,
1990 left_x
+ i
* left_p
, top_y
+ i
,
1991 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1995 for (i
= 0; i
< width
; ++i
)
1996 XDrawLine (dpy
, window
, gc
,
1997 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
1999 XSetClipMask (dpy
, gc
, None
);
2001 gc
= f
->output_data
.x
->black_relief
.gc
;
2003 gc
= f
->output_data
.x
->white_relief
.gc
;
2004 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2007 for (i
= 0; i
< width
; ++i
)
2008 XDrawLine (dpy
, window
, gc
,
2009 left_x
+ i
* left_p
, bottom_y
- i
,
2010 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2014 for (i
= 0; i
< width
; ++i
)
2015 XDrawLine (dpy
, window
, gc
,
2016 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2018 XSetClipMask (dpy
, gc
, None
);
2022 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2023 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2024 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2025 left side of the rectangle. RIGHT_P non-zero means draw a line
2026 on the right side of the rectangle. CLIP_RECT is the clipping
2027 rectangle to use when drawing. */
2030 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2031 left_p
, right_p
, clip_rect
)
2032 struct glyph_string
*s
;
2033 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2034 XRectangle
*clip_rect
;
2038 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2039 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2040 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2043 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2044 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2048 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2049 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2052 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2053 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2057 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2058 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2060 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2061 XSetClipMask (s
->display
, s
->gc
, None
);
2065 /* Draw a box around glyph string S. */
2068 x_draw_glyph_string_box (s
)
2069 struct glyph_string
*s
;
2071 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2072 int left_p
, right_p
;
2073 struct glyph
*last_glyph
;
2074 XRectangle clip_rect
;
2076 last_x
= window_box_right (s
->w
, s
->area
);
2077 if (s
->row
->full_width_p
2078 && !s
->w
->pseudo_window_p
)
2080 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
2081 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
2082 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
2085 /* The glyph that may have a right box line. */
2086 last_glyph
= (s
->cmp
|| s
->img
2088 : s
->first_glyph
+ s
->nchars
- 1);
2090 width
= abs (s
->face
->box_line_width
);
2091 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2093 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2095 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2097 bottom_y
= top_y
+ s
->height
- 1;
2099 left_p
= (s
->first_glyph
->left_box_line_p
2100 || (s
->hl
== DRAW_MOUSE_FACE
2102 || s
->prev
->hl
!= s
->hl
)));
2103 right_p
= (last_glyph
->right_box_line_p
2104 || (s
->hl
== DRAW_MOUSE_FACE
2106 || s
->next
->hl
!= s
->hl
)));
2108 get_glyph_string_clip_rect (s
, &clip_rect
);
2110 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2111 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2112 left_p
, right_p
, &clip_rect
);
2115 x_setup_relief_colors (s
);
2116 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2117 width
, raised_p
, left_p
, right_p
, &clip_rect
);
2122 /* Draw foreground of image glyph string S. */
2125 x_draw_image_foreground (s
)
2126 struct glyph_string
*s
;
2129 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
2131 /* If first glyph of S has a left box line, start drawing it to the
2132 right of that line. */
2133 if (s
->face
->box
!= FACE_NO_BOX
2134 && s
->first_glyph
->left_box_line_p
)
2135 x
= s
->x
+ abs (s
->face
->box_line_width
);
2139 /* If there is a margin around the image, adjust x- and y-position
2141 x
+= s
->img
->hmargin
;
2142 y
+= s
->img
->vmargin
;
2148 /* We can't set both a clip mask and use XSetClipRectangles
2149 because the latter also sets a clip mask. We also can't
2150 trust on the shape extension to be available
2151 (XShapeCombineRegion). So, compute the rectangle to draw
2153 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2156 XRectangle clip_rect
, image_rect
, r
;
2158 xgcv
.clip_mask
= s
->img
->mask
;
2159 xgcv
.clip_x_origin
= x
;
2160 xgcv
.clip_y_origin
= y
;
2161 xgcv
.function
= GXcopy
;
2162 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2164 get_glyph_string_clip_rect (s
, &clip_rect
);
2167 image_rect
.width
= s
->img
->width
;
2168 image_rect
.height
= s
->img
->height
;
2169 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2170 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2171 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
2175 XRectangle clip_rect
, image_rect
, r
;
2177 get_glyph_string_clip_rect (s
, &clip_rect
);
2180 image_rect
.width
= s
->img
->width
;
2181 image_rect
.height
= s
->img
->height
;
2182 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2183 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2184 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
2186 /* When the image has a mask, we can expect that at
2187 least part of a mouse highlight or a block cursor will
2188 be visible. If the image doesn't have a mask, make
2189 a block cursor visible by drawing a rectangle around
2190 the image. I believe it's looking better if we do
2191 nothing here for mouse-face. */
2192 if (s
->hl
== DRAW_CURSOR
)
2194 int r
= s
->img
->relief
;
2196 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2197 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
2202 /* Draw a rectangle if image could not be loaded. */
2203 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2204 s
->img
->width
- 1, s
->img
->height
- 1);
2208 /* Draw a relief around the image glyph string S. */
2211 x_draw_image_relief (s
)
2212 struct glyph_string
*s
;
2214 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2217 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
2219 /* If first glyph of S has a left box line, start drawing it to the
2220 right of that line. */
2221 if (s
->face
->box
!= FACE_NO_BOX
2222 && s
->first_glyph
->left_box_line_p
)
2223 x
= s
->x
+ abs (s
->face
->box_line_width
);
2227 /* If there is a margin around the image, adjust x- and y-position
2229 x
+= s
->img
->hmargin
;
2230 y
+= s
->img
->vmargin
;
2232 if (s
->hl
== DRAW_IMAGE_SUNKEN
2233 || s
->hl
== DRAW_IMAGE_RAISED
)
2235 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2236 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2240 thick
= abs (s
->img
->relief
);
2241 raised_p
= s
->img
->relief
> 0;
2246 x1
= x
+ s
->img
->width
+ thick
- 1;
2247 y1
= y
+ s
->img
->height
+ thick
- 1;
2249 x_setup_relief_colors (s
);
2250 get_glyph_string_clip_rect (s
, &r
);
2251 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
2255 /* Draw the foreground of image glyph string S to PIXMAP. */
2258 x_draw_image_foreground_1 (s
, pixmap
)
2259 struct glyph_string
*s
;
2263 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
2265 /* If first glyph of S has a left box line, start drawing it to the
2266 right of that line. */
2267 if (s
->face
->box
!= FACE_NO_BOX
2268 && s
->first_glyph
->left_box_line_p
)
2269 x
= abs (s
->face
->box_line_width
);
2273 /* If there is a margin around the image, adjust x- and y-position
2275 x
+= s
->img
->hmargin
;
2276 y
+= s
->img
->vmargin
;
2282 /* We can't set both a clip mask and use XSetClipRectangles
2283 because the latter also sets a clip mask. We also can't
2284 trust on the shape extension to be available
2285 (XShapeCombineRegion). So, compute the rectangle to draw
2287 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2291 xgcv
.clip_mask
= s
->img
->mask
;
2292 xgcv
.clip_x_origin
= x
;
2293 xgcv
.clip_y_origin
= y
;
2294 xgcv
.function
= GXcopy
;
2295 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2297 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2298 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
2299 XSetClipMask (s
->display
, s
->gc
, None
);
2303 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2304 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
2306 /* When the image has a mask, we can expect that at
2307 least part of a mouse highlight or a block cursor will
2308 be visible. If the image doesn't have a mask, make
2309 a block cursor visible by drawing a rectangle around
2310 the image. I believe it's looking better if we do
2311 nothing here for mouse-face. */
2312 if (s
->hl
== DRAW_CURSOR
)
2314 int r
= s
->img
->relief
;
2316 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2317 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
2322 /* Draw a rectangle if image could not be loaded. */
2323 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2324 s
->img
->width
- 1, s
->img
->height
- 1);
2328 /* Draw part of the background of glyph string S. X, Y, W, and H
2329 give the rectangle to draw. */
2332 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2333 struct glyph_string
*s
;
2338 /* Fill background with a stipple pattern. */
2339 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2340 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2341 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2344 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2348 /* Draw image glyph string S.
2351 s->x +-------------------------
2354 | +-------------------------
2357 | | +-------------------
2363 x_draw_image_glyph_string (s
)
2364 struct glyph_string
*s
;
2367 int box_line_hwidth
= abs (s
->face
->box_line_width
);
2368 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2370 Pixmap pixmap
= None
;
2372 height
= s
->height
- 2 * box_line_vwidth
;
2375 /* Fill background with face under the image. Do it only if row is
2376 taller than image or if image has a clip mask to reduce
2378 s
->stippled_p
= s
->face
->stipple
!= 0;
2379 if (height
> s
->img
->height
2383 || s
->img
->pixmap
== 0
2384 || s
->width
!= s
->background_width
)
2386 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
2387 x
= s
->x
+ box_line_hwidth
;
2391 y
= s
->y
+ box_line_vwidth
;
2395 /* Create a pixmap as large as the glyph string. Fill it
2396 with the background color. Copy the image to it, using
2397 its mask. Copy the temporary pixmap to the display. */
2398 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2399 int depth
= DefaultDepthOfScreen (screen
);
2401 /* Create a pixmap as large as the glyph string. */
2402 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2403 s
->background_width
,
2406 /* Don't clip in the following because we're working on the
2408 XSetClipMask (s
->display
, s
->gc
, None
);
2410 /* Fill the pixmap with the background color/stipple. */
2413 /* Fill background with a stipple pattern. */
2414 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2415 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2416 0, 0, s
->background_width
, s
->height
);
2417 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2422 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2424 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2425 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2426 0, 0, s
->background_width
, s
->height
);
2427 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2431 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2433 s
->background_filled_p
= 1;
2436 /* Draw the foreground. */
2439 x_draw_image_foreground_1 (s
, pixmap
);
2440 x_set_glyph_string_clipping (s
);
2441 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2442 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2443 XFreePixmap (s
->display
, pixmap
);
2446 x_draw_image_foreground (s
);
2448 /* If we must draw a relief around the image, do it. */
2450 || s
->hl
== DRAW_IMAGE_RAISED
2451 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2452 x_draw_image_relief (s
);
2456 /* Draw stretch glyph string S. */
2459 x_draw_stretch_glyph_string (s
)
2460 struct glyph_string
*s
;
2462 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2463 s
->stippled_p
= s
->face
->stipple
!= 0;
2465 if (s
->hl
== DRAW_CURSOR
2466 && !x_stretch_cursor_p
)
2468 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2469 as wide as the stretch glyph. */
2470 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
2473 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
2475 /* Clear rest using the GC of the original non-cursor face. */
2476 if (width
< s
->background_width
)
2478 int x
= s
->x
+ width
, y
= s
->y
;
2479 int w
= s
->background_width
- width
, h
= s
->height
;
2483 if (s
->row
->mouse_face_p
2484 && cursor_in_mouse_face_p (s
->w
))
2486 x_set_mouse_face_gc (s
);
2492 get_glyph_string_clip_rect (s
, &r
);
2493 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2495 if (s
->face
->stipple
)
2497 /* Fill background with a stipple pattern. */
2498 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2499 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2500 XSetFillStyle (s
->display
, gc
, FillSolid
);
2505 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2506 XSetForeground (s
->display
, gc
, xgcv
.background
);
2507 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2508 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2512 else if (!s
->background_filled_p
)
2513 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
2516 s
->background_filled_p
= 1;
2520 /* Draw glyph string S. */
2523 x_draw_glyph_string (s
)
2524 struct glyph_string
*s
;
2526 int relief_drawn_p
= 0;
2528 /* If S draws into the background of its successor, draw the
2529 background of the successor first so that S can draw into it.
2530 This makes S->next use XDrawString instead of XDrawImageString. */
2531 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
2533 xassert (s
->next
->img
== NULL
);
2534 x_set_glyph_string_gc (s
->next
);
2535 x_set_glyph_string_clipping (s
->next
);
2536 x_draw_glyph_string_background (s
->next
, 1);
2539 /* Set up S->gc, set clipping and draw S. */
2540 x_set_glyph_string_gc (s
);
2542 /* Draw relief (if any) in advance for char/composition so that the
2543 glyph string can be drawn over it. */
2544 if (!s
->for_overlaps_p
2545 && s
->face
->box
!= FACE_NO_BOX
2546 && (s
->first_glyph
->type
== CHAR_GLYPH
2547 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2550 x_set_glyph_string_clipping (s
);
2551 x_draw_glyph_string_background (s
, 1);
2552 x_draw_glyph_string_box (s
);
2553 x_set_glyph_string_clipping (s
);
2557 x_set_glyph_string_clipping (s
);
2559 switch (s
->first_glyph
->type
)
2562 x_draw_image_glyph_string (s
);
2566 x_draw_stretch_glyph_string (s
);
2570 if (s
->for_overlaps_p
)
2571 s
->background_filled_p
= 1;
2573 x_draw_glyph_string_background (s
, 0);
2574 x_draw_glyph_string_foreground (s
);
2577 case COMPOSITE_GLYPH
:
2578 if (s
->for_overlaps_p
|| s
->gidx
> 0)
2579 s
->background_filled_p
= 1;
2581 x_draw_glyph_string_background (s
, 1);
2582 x_draw_composite_glyph_string_foreground (s
);
2589 if (!s
->for_overlaps_p
)
2591 /* Draw underline. */
2592 if (s
->face
->underline_p
)
2594 unsigned long tem
, h
;
2597 /* Get the underline thickness. Default is 1 pixel. */
2598 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
2601 /* Get the underline position. This is the recommended
2602 vertical offset in pixels from the baseline to the top of
2603 the underline. This is a signed value according to the
2604 specs, and its default is
2606 ROUND ((maximum descent) / 2), with
2607 ROUND(x) = floor (x + 0.5) */
2609 if (x_use_underline_position_properties
2610 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
2611 y
= s
->ybase
+ (long) tem
;
2612 else if (s
->face
->font
)
2613 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2615 y
= s
->y
+ s
->height
- h
;
2617 if (s
->face
->underline_defaulted_p
)
2618 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2619 s
->x
, y
, s
->width
, h
);
2623 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2624 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2625 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2626 s
->x
, y
, s
->width
, h
);
2627 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2631 /* Draw overline. */
2632 if (s
->face
->overline_p
)
2634 unsigned long dy
= 0, h
= 1;
2636 if (s
->face
->overline_color_defaulted_p
)
2637 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2642 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2643 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2644 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2646 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2650 /* Draw strike-through. */
2651 if (s
->face
->strike_through_p
)
2653 unsigned long h
= 1;
2654 unsigned long dy
= (s
->height
- h
) / 2;
2656 if (s
->face
->strike_through_color_defaulted_p
)
2657 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2662 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2663 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2664 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2666 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2670 /* Draw relief if not yet drawn. */
2671 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2672 x_draw_glyph_string_box (s
);
2675 /* Reset clipping. */
2676 XSetClipMask (s
->display
, s
->gc
, None
);
2679 /* Shift display to make room for inserted glyphs. */
2682 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2684 int x
, y
, width
, height
, shift_by
;
2686 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2687 f
->output_data
.x
->normal_gc
,
2688 x
, y
, width
, height
,
2692 /* Delete N glyphs at the nominal cursor position. Not implemented
2703 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2704 If they are <= 0, this is probably an error. */
2707 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
2714 xassert (width
> 0 && height
> 0);
2715 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2719 /* Clear entire frame. If updating_frame is non-null, clear that
2720 frame. Otherwise clear the selected frame. */
2730 f
= SELECTED_FRAME ();
2732 /* Clearing the frame will erase any cursor, so mark them all as no
2734 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2735 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2736 output_cursor
.x
= -1;
2738 /* We don't set the output cursor here because there will always
2739 follow an explicit cursor_to. */
2741 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2743 /* We have to clear the scroll bars, too. If we have changed
2744 colors or something like that, then they should be notified. */
2745 x_scroll_bar_clear (f
);
2747 XFlush (FRAME_X_DISPLAY (f
));
2750 xg_frame_cleared (f
);
2758 /* Invert the middle quarter of the frame for .15 sec. */
2760 /* We use the select system call to do the waiting, so we have to make
2761 sure it's available. If it isn't, we just won't do visual bells. */
2763 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2766 /* Subtract the `struct timeval' values X and Y, storing the result in
2767 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2770 timeval_subtract (result
, x
, y
)
2771 struct timeval
*result
, x
, y
;
2773 /* Perform the carry for the later subtraction by updating y. This
2774 is safer because on some systems the tv_sec member is unsigned. */
2775 if (x
.tv_usec
< y
.tv_usec
)
2777 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2778 y
.tv_usec
-= 1000000 * nsec
;
2782 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2784 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2785 y
.tv_usec
+= 1000000 * nsec
;
2789 /* Compute the time remaining to wait. tv_usec is certainly
2791 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2792 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2794 /* Return indication of whether the result should be considered
2796 return x
.tv_sec
< y
.tv_sec
;
2808 /* Create a GC that will use the GXxor function to flip foreground
2809 pixels into background pixels. */
2813 values
.function
= GXxor
;
2814 values
.foreground
= (f
->output_data
.x
->foreground_pixel
2815 ^ f
->output_data
.x
->background_pixel
);
2817 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2818 GCFunction
| GCForeground
, &values
);
2822 /* Get the height not including a menu bar widget. */
2823 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
2824 /* Height of each line to flash. */
2825 int flash_height
= FRAME_LINE_HEIGHT (f
);
2826 /* These will be the left and right margins of the rectangles. */
2827 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2828 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
2832 /* Don't flash the area between a scroll bar and the frame
2833 edge it is next to. */
2834 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
2836 case vertical_scroll_bar_left
:
2837 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2840 case vertical_scroll_bar_right
:
2841 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2848 width
= flash_right
- flash_left
;
2850 /* If window is tall, flash top and bottom line. */
2851 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2853 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2855 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2856 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
2857 width
, flash_height
);
2858 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2860 (height
- flash_height
2861 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2862 width
, flash_height
);
2865 /* If it is short, flash it all. */
2866 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2867 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2868 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2873 struct timeval wakeup
;
2875 EMACS_GET_TIME (wakeup
);
2877 /* Compute time to wait until, propagating carry from usecs. */
2878 wakeup
.tv_usec
+= 150000;
2879 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
2880 wakeup
.tv_usec
%= 1000000;
2882 /* Keep waiting until past the time wakeup or any input gets
2884 while (! detect_input_pending ())
2886 struct timeval current
;
2887 struct timeval timeout
;
2889 EMACS_GET_TIME (current
);
2891 /* Break if result would be negative. */
2892 if (timeval_subtract (¤t
, wakeup
, current
))
2895 /* How long `select' should wait. */
2897 timeout
.tv_usec
= 10000;
2899 /* Try to wait that long--but we might wake up sooner. */
2900 select (0, NULL
, NULL
, NULL
, &timeout
);
2904 /* If window is tall, flash top and bottom line. */
2905 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2907 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2909 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2910 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
2911 width
, flash_height
);
2912 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2914 (height
- flash_height
2915 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2916 width
, flash_height
);
2919 /* If it is short, flash it all. */
2920 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2921 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2922 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2924 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
2932 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
2935 /* Make audible bell. */
2940 struct frame
*f
= SELECTED_FRAME ();
2942 if (FRAME_X_DISPLAY (f
))
2944 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2951 XBell (FRAME_X_DISPLAY (f
), 0);
2952 XFlush (FRAME_X_DISPLAY (f
));
2959 /* Specify how many text lines, from the top of the window,
2960 should be affected by insert-lines and delete-lines operations.
2961 This, and those operations, are used only within an update
2962 that is bounded by calls to x_update_begin and x_update_end. */
2965 XTset_terminal_window (n
)
2968 /* This function intentionally left blank. */
2973 /***********************************************************************
2975 ***********************************************************************/
2977 /* Perform an insert-lines or delete-lines operation, inserting N
2978 lines or deleting -N lines at vertical position VPOS. */
2981 x_ins_del_lines (vpos
, n
)
2988 /* Scroll part of the display as described by RUN. */
2991 x_scroll_run (w
, run
)
2995 struct frame
*f
= XFRAME (w
->frame
);
2996 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2998 /* Get frame-relative bounding box of the text display area of W,
2999 without mode lines. Include in this box the left and right
3001 window_box (w
, -1, &x
, &y
, &width
, &height
);
3002 width
+= FRAME_X_FRINGE_WIDTH (f
);
3003 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
3005 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3006 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3007 bottom_y
= y
+ height
;
3011 /* Scrolling up. Make sure we don't copy part of the mode
3012 line at the bottom. */
3013 if (from_y
+ run
->height
> bottom_y
)
3014 height
= bottom_y
- from_y
;
3016 height
= run
->height
;
3020 /* Scolling down. Make sure we don't copy over the mode line.
3022 if (to_y
+ run
->height
> bottom_y
)
3023 height
= bottom_y
- to_y
;
3025 height
= run
->height
;
3030 /* Cursor off. Will be switched on again in x_update_window_end. */
3034 XCopyArea (FRAME_X_DISPLAY (f
),
3035 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3036 f
->output_data
.x
->normal_gc
,
3046 /***********************************************************************
3048 ***********************************************************************/
3055 /* We used to only do this if Vx_no_window_manager was non-nil, but
3056 the ICCCM (section 4.1.6) says that the window's border pixmap
3057 and border pixel are window attributes which are "private to the
3058 client", so we can always change it to whatever we want. */
3060 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3061 f
->output_data
.x
->border_pixel
);
3063 x_update_cursor (f
, 1);
3067 frame_unhighlight (f
)
3070 /* We used to only do this if Vx_no_window_manager was non-nil, but
3071 the ICCCM (section 4.1.6) says that the window's border pixmap
3072 and border pixel are window attributes which are "private to the
3073 client", so we can always change it to whatever we want. */
3075 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3076 f
->output_data
.x
->border_tile
);
3078 x_update_cursor (f
, 1);
3081 /* The focus has changed. Update the frames as necessary to reflect
3082 the new situation. Note that we can't change the selected frame
3083 here, because the Lisp code we are interrupting might become confused.
3084 Each event gets marked with the frame in which it occurred, so the
3085 Lisp code can tell when the switch took place by examining the events. */
3088 x_new_focus_frame (dpyinfo
, frame
)
3089 struct x_display_info
*dpyinfo
;
3090 struct frame
*frame
;
3092 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3094 if (frame
!= dpyinfo
->x_focus_frame
)
3096 /* Set this before calling other routines, so that they see
3097 the correct value of x_focus_frame. */
3098 dpyinfo
->x_focus_frame
= frame
;
3100 if (old_focus
&& old_focus
->auto_lower
)
3101 x_lower_frame (old_focus
);
3104 selected_frame
= frame
;
3105 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3107 Fselect_window (selected_frame
->selected_window
);
3108 choose_minibuf_frame ();
3111 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3112 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3114 pending_autoraise_frame
= 0;
3117 x_frame_rehighlight (dpyinfo
);
3120 /* Handle FocusIn and FocusOut state changes for FRAME.
3121 If FRAME has focus and there exists more than one frame, puts
3122 a FOCUS_IN_EVENT into BUFP.
3123 Returns number of events inserted into BUFP. */
3126 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
, numchars
)
3129 struct x_display_info
*dpyinfo
;
3130 struct frame
*frame
;
3131 struct input_event
*bufp
;
3136 if (type
== FocusIn
)
3138 if (dpyinfo
->x_focus_event_frame
!= frame
)
3140 x_new_focus_frame (dpyinfo
, frame
);
3141 dpyinfo
->x_focus_event_frame
= frame
;
3143 /* Don't stop displaying the initial startup message
3144 for a switch-frame event we don't need. */
3146 && GC_NILP (Vterminal_frame
)
3147 && GC_CONSP (Vframe_list
)
3148 && !GC_NILP (XCDR (Vframe_list
)))
3150 bufp
->kind
= FOCUS_IN_EVENT
;
3151 XSETFRAME (bufp
->frame_or_window
, frame
);
3159 frame
->output_data
.x
->focus_state
|= state
;
3162 if (FRAME_XIC (frame
))
3163 XSetICFocus (FRAME_XIC (frame
));
3166 else if (type
== FocusOut
)
3168 frame
->output_data
.x
->focus_state
&= ~state
;
3170 if (dpyinfo
->x_focus_event_frame
== frame
)
3172 dpyinfo
->x_focus_event_frame
= 0;
3173 x_new_focus_frame (dpyinfo
, 0);
3177 if (FRAME_XIC (frame
))
3178 XUnsetICFocus (FRAME_XIC (frame
));
3185 /* The focus may have changed. Figure out if it is a real focus change,
3186 by checking both FocusIn/Out and Enter/LeaveNotify events.
3188 Returns number of events inserted into BUFP. */
3191 x_detect_focus_change (dpyinfo
, event
, bufp
, numchars
)
3192 struct x_display_info
*dpyinfo
;
3194 struct input_event
*bufp
;
3197 struct frame
*frame
;
3200 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3201 if (! frame
) return nr_events
;
3203 switch (event
->type
)
3207 if (event
->xcrossing
.detail
!= NotifyInferior
3208 && event
->xcrossing
.focus
3209 && ! (frame
->output_data
.x
->focus_state
& FOCUS_EXPLICIT
))
3210 nr_events
= x_focus_changed ((event
->type
== EnterNotify
3211 ? FocusIn
: FocusOut
),
3221 nr_events
= x_focus_changed (event
->type
,
3222 (event
->xfocus
.detail
== NotifyPointer
3223 ? FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3235 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3238 x_mouse_leave (dpyinfo
)
3239 struct x_display_info
*dpyinfo
;
3241 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3244 /* The focus has changed, or we have redirected a frame's focus to
3245 another frame (this happens when a frame uses a surrogate
3246 mini-buffer frame). Shift the highlight as appropriate.
3248 The FRAME argument doesn't necessarily have anything to do with which
3249 frame is being highlighted or un-highlighted; we only use it to find
3250 the appropriate X display info. */
3253 XTframe_rehighlight (frame
)
3254 struct frame
*frame
;
3256 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3260 x_frame_rehighlight (dpyinfo
)
3261 struct x_display_info
*dpyinfo
;
3263 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3265 if (dpyinfo
->x_focus_frame
)
3267 dpyinfo
->x_highlight_frame
3268 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3269 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3270 : dpyinfo
->x_focus_frame
);
3271 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3273 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3274 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3278 dpyinfo
->x_highlight_frame
= 0;
3280 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3283 frame_unhighlight (old_highlight
);
3284 if (dpyinfo
->x_highlight_frame
)
3285 frame_highlight (dpyinfo
->x_highlight_frame
);
3291 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3293 /* Initialize mode_switch_bit and modifier_meaning. */
3295 x_find_modifier_meanings (dpyinfo
)
3296 struct x_display_info
*dpyinfo
;
3298 int min_code
, max_code
;
3301 XModifierKeymap
*mods
;
3303 dpyinfo
->meta_mod_mask
= 0;
3304 dpyinfo
->shift_lock_mask
= 0;
3305 dpyinfo
->alt_mod_mask
= 0;
3306 dpyinfo
->super_mod_mask
= 0;
3307 dpyinfo
->hyper_mod_mask
= 0;
3310 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3312 min_code
= dpyinfo
->display
->min_keycode
;
3313 max_code
= dpyinfo
->display
->max_keycode
;
3316 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3317 min_code
, max_code
- min_code
+ 1,
3319 mods
= XGetModifierMapping (dpyinfo
->display
);
3321 /* Scan the modifier table to see which modifier bits the Meta and
3322 Alt keysyms are on. */
3324 int row
, col
; /* The row and column in the modifier table. */
3326 for (row
= 3; row
< 8; row
++)
3327 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3330 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3332 /* Zeroes are used for filler. Skip them. */
3336 /* Are any of this keycode's keysyms a meta key? */
3340 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3342 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3348 dpyinfo
->meta_mod_mask
|= (1 << row
);
3353 dpyinfo
->alt_mod_mask
|= (1 << row
);
3358 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3363 dpyinfo
->super_mod_mask
|= (1 << row
);
3367 /* Ignore this if it's not on the lock modifier. */
3368 if ((1 << row
) == LockMask
)
3369 dpyinfo
->shift_lock_mask
= LockMask
;
3377 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3378 if (! dpyinfo
->meta_mod_mask
)
3380 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3381 dpyinfo
->alt_mod_mask
= 0;
3384 /* If some keys are both alt and meta,
3385 make them just meta, not alt. */
3386 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3388 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3391 XFree ((char *) syms
);
3392 XFreeModifiermap (mods
);
3395 /* Convert between the modifier bits X uses and the modifier bits
3399 x_x_to_emacs_modifiers (dpyinfo
, state
)
3400 struct x_display_info
*dpyinfo
;
3403 EMACS_UINT mod_meta
= meta_modifier
;
3404 EMACS_UINT mod_alt
= alt_modifier
;
3405 EMACS_UINT mod_hyper
= hyper_modifier
;
3406 EMACS_UINT mod_super
= super_modifier
;
3409 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3410 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3411 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3412 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3413 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3414 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3415 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3416 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3419 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3420 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3421 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3422 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3423 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3424 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3428 x_emacs_to_x_modifiers (dpyinfo
, state
)
3429 struct x_display_info
*dpyinfo
;
3432 EMACS_UINT mod_meta
= meta_modifier
;
3433 EMACS_UINT mod_alt
= alt_modifier
;
3434 EMACS_UINT mod_hyper
= hyper_modifier
;
3435 EMACS_UINT mod_super
= super_modifier
;
3439 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3440 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3441 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3442 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3443 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3444 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3445 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3446 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3449 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3450 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3451 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3452 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3453 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3454 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3457 /* Convert a keysym to its name. */
3460 x_get_keysym_name (keysym
)
3466 value
= XKeysymToString (keysym
);
3474 /* Mouse clicks and mouse movement. Rah. */
3476 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3478 If the event is a button press, then note that we have grabbed
3482 construct_mouse_click (result
, event
, f
)
3483 struct input_event
*result
;
3484 XButtonEvent
*event
;
3487 /* Make the event type NO_EVENT; we'll change that when we decide
3489 result
->kind
= MOUSE_CLICK_EVENT
;
3490 result
->code
= event
->button
- Button1
;
3491 result
->timestamp
= event
->time
;
3492 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3494 | (event
->type
== ButtonRelease
3498 XSETINT (result
->x
, event
->x
);
3499 XSETINT (result
->y
, event
->y
);
3500 XSETFRAME (result
->frame_or_window
, f
);
3506 /* Function to report a mouse movement to the mainstream Emacs code.
3507 The input handler calls this.
3509 We have received a mouse movement event, which is given in *event.
3510 If the mouse is over a different glyph than it was last time, tell
3511 the mainstream emacs code by setting mouse_moved. If not, ask for
3512 another motion event, so we can check again the next time it moves. */
3514 static XMotionEvent last_mouse_motion_event
;
3515 static Lisp_Object last_mouse_motion_frame
;
3518 note_mouse_movement (frame
, event
)
3520 XMotionEvent
*event
;
3522 last_mouse_movement_time
= event
->time
;
3523 last_mouse_motion_event
= *event
;
3524 XSETFRAME (last_mouse_motion_frame
, frame
);
3526 if (event
->window
!= FRAME_X_WINDOW (frame
))
3528 frame
->mouse_moved
= 1;
3529 last_mouse_scroll_bar
= Qnil
;
3530 note_mouse_highlight (frame
, -1, -1);
3533 /* Has the mouse moved off the glyph it was on at the last sighting? */
3534 else if (event
->x
< last_mouse_glyph
.x
3535 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3536 || event
->y
< last_mouse_glyph
.y
3537 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3539 frame
->mouse_moved
= 1;
3540 last_mouse_scroll_bar
= Qnil
;
3541 note_mouse_highlight (frame
, event
->x
, event
->y
);
3546 /************************************************************************
3548 ************************************************************************/
3551 redo_mouse_highlight ()
3553 if (!NILP (last_mouse_motion_frame
)
3554 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3555 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3556 last_mouse_motion_event
.x
,
3557 last_mouse_motion_event
.y
);
3561 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
3564 /* Try to determine frame pixel position and size of the glyph under
3565 frame pixel coordinates X/Y on frame F . Return the position and
3566 size in *RECT. Value is non-zero if we could compute these
3570 glyph_rect (f
, x
, y
, rect
)
3578 window
= window_from_coordinates (f
, x
, y
, 0, 0);
3581 struct window
*w
= XWINDOW (window
);
3582 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
3583 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
3585 frame_to_window_pixel_xy (w
, &x
, &y
);
3587 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
3590 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
3591 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
3594 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
3597 rect
->width
= g
->pixel_width
;
3598 rect
->height
= r
->height
;
3599 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
3600 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
3610 /* Return the current position of the mouse.
3611 *FP should be a frame which indicates which display to ask about.
3613 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3614 and *PART to the frame, window, and scroll bar part that the mouse
3615 is over. Set *X and *Y to the portion and whole of the mouse's
3616 position on the scroll bar.
3618 If the mouse movement started elsewhere, set *FP to the frame the
3619 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3622 Set *TIME to the server time-stamp for the time at which the mouse
3623 was at this position.
3625 Don't store anything if we don't have a valid set of values to report.
3627 This clears the mouse_moved flag, so we can wait for the next mouse
3631 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3634 Lisp_Object
*bar_window
;
3635 enum scroll_bar_part
*part
;
3637 unsigned long *time
;
3643 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3644 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3650 Window dummy_window
;
3653 Lisp_Object frame
, tail
;
3655 /* Clear the mouse-moved flag for every frame on this display. */
3656 FOR_EACH_FRAME (tail
, frame
)
3657 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3658 XFRAME (frame
)->mouse_moved
= 0;
3660 last_mouse_scroll_bar
= Qnil
;
3662 /* Figure out which root window we're on. */
3663 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3664 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3666 /* The root window which contains the pointer. */
3669 /* Trash which we can't trust if the pointer is on
3670 a different screen. */
3673 /* The position on that root window. */
3676 /* More trash we can't trust. */
3679 /* Modifier keys and pointer buttons, about which
3681 (unsigned int *) &dummy
);
3683 /* Now we have a position on the root; find the innermost window
3684 containing the pointer. */
3688 int parent_x
= 0, parent_y
= 0;
3693 /* XTranslateCoordinates can get errors if the window
3694 structure is changing at the same time this function
3695 is running. So at least we must not crash from them. */
3697 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
3699 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3700 && FRAME_LIVE_P (last_mouse_frame
))
3702 /* If mouse was grabbed on a frame, give coords for that frame
3703 even if the mouse is now outside it. */
3704 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3706 /* From-window, to-window. */
3707 root
, FRAME_X_WINDOW (last_mouse_frame
),
3709 /* From-position, to-position. */
3710 root_x
, root_y
, &win_x
, &win_y
,
3714 f1
= last_mouse_frame
;
3720 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3722 /* From-window, to-window. */
3725 /* From-position, to-position. */
3726 root_x
, root_y
, &win_x
, &win_y
,
3731 if (child
== None
|| child
== win
)
3739 /* Now we know that:
3740 win is the innermost window containing the pointer
3741 (XTC says it has no child containing the pointer),
3742 win_x and win_y are the pointer's position in it
3743 (XTC did this the last time through), and
3744 parent_x and parent_y are the pointer's position in win's parent.
3745 (They are what win_x and win_y were when win was child.
3746 If win is the root window, it has no parent, and
3747 parent_{x,y} are invalid, but that's okay, because we'll
3748 never use them in that case.) */
3750 /* Is win one of our frames? */
3751 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3753 #ifdef USE_X_TOOLKIT
3754 /* If we end up with the menu bar window, say it's not
3757 && f1
->output_data
.x
->menubar_widget
3758 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3760 #endif /* USE_X_TOOLKIT */
3763 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3766 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
3768 /* If not, is it one of our scroll bars? */
3771 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
3775 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3781 if (f1
== 0 && insist
> 0)
3782 f1
= SELECTED_FRAME ();
3786 /* Ok, we found a frame. Store all the values.
3787 last_mouse_glyph is a rectangle used to reduce the
3788 generation of mouse events. To not miss any motion
3789 events, we must divide the frame into rectangles of the
3790 size of the smallest character that could be displayed
3791 on it, i.e. into the same rectangles that matrices on
3792 the frame are divided into. */
3794 int width
, height
, gx
, gy
;
3797 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
3798 last_mouse_glyph
= rect
;
3801 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
3802 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
3806 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
3807 round down even for negative values. */
3812 gx
= (gx
+ width
- 1) / width
* width
;
3813 gy
= (gy
+ height
- 1) / height
* height
;
3815 last_mouse_glyph
.width
= width
;
3816 last_mouse_glyph
.height
= height
;
3817 last_mouse_glyph
.x
= gx
;
3818 last_mouse_glyph
.y
= gy
;
3824 XSETINT (*x
, win_x
);
3825 XSETINT (*y
, win_y
);
3826 *time
= last_mouse_movement_time
;
3836 /***********************************************************************
3838 ***********************************************************************/
3840 /* Scroll bar support. */
3842 /* Given an X window ID, find the struct scroll_bar which manages it.
3843 This can be called in GC, so we have to make sure to strip off mark
3846 static struct scroll_bar
*
3847 x_window_to_scroll_bar (window_id
)
3853 window_id
= (Window
) xg_get_scroll_id_for_window (window_id
);
3854 #endif /* USE_GTK */
3856 for (tail
= Vframe_list
;
3857 XGCTYPE (tail
) == Lisp_Cons
;
3860 Lisp_Object frame
, bar
, condemned
;
3862 frame
= XCAR (tail
);
3863 /* All elements of Vframe_list should be frames. */
3864 if (! GC_FRAMEP (frame
))
3867 /* Scan this frame's scroll bar list for a scroll bar with the
3869 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3870 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3871 /* This trick allows us to search both the ordinary and
3872 condemned scroll bar lists with one loop. */
3873 ! GC_NILP (bar
) || (bar
= condemned
,
3876 bar
= XSCROLL_BAR (bar
)->next
)
3877 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
3878 return XSCROLL_BAR (bar
);
3885 #if defined USE_LUCID
3887 /* Return the Lucid menu bar WINDOW is part of. Return null
3888 if WINDOW is not part of a menu bar. */
3891 x_window_to_menu_bar (window
)
3896 for (tail
= Vframe_list
;
3897 XGCTYPE (tail
) == Lisp_Cons
;
3900 Lisp_Object frame
= XCAR (tail
);
3901 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
3903 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
3910 #endif /* USE_LUCID */
3913 /************************************************************************
3915 ************************************************************************/
3917 #ifdef USE_TOOLKIT_SCROLL_BARS
3919 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
3920 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
3921 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
3922 struct scroll_bar
*));
3923 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
3927 /* Lisp window being scrolled. Set when starting to interact with
3928 a toolkit scroll bar, reset to nil when ending the interaction. */
3930 static Lisp_Object window_being_scrolled
;
3932 /* Last scroll bar part sent in xm_scroll_callback. */
3934 static int last_scroll_bar_part
;
3936 /* Whether this is an Xaw with arrow-scrollbars. This should imply
3937 that movements of 1/20 of the screen size are mapped to up/down. */
3940 /* Id of action hook installed for scroll bars. */
3942 static XtActionHookId action_hook_id
;
3944 static Boolean xaw3d_arrow_scroll
;
3946 /* Whether the drag scrolling maintains the mouse at the top of the
3947 thumb. If not, resizing the thumb needs to be done more carefully
3948 to avoid jerkyness. */
3950 static Boolean xaw3d_pick_top
;
3952 extern void set_vertical_scroll_bar
P_ ((struct window
*));
3954 /* Action hook installed via XtAppAddActionHook when toolkit scroll
3955 bars are used.. The hook is responsible for detecting when
3956 the user ends an interaction with the scroll bar, and generates
3957 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
3960 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
3963 XtPointer client_data
;
3967 Cardinal
*num_params
;
3973 scroll_bar_p
= XmIsScrollBar (widget
);
3974 end_action
= "Release";
3975 #else /* !USE_MOTIF i.e. use Xaw */
3976 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
3977 end_action
= "EndScroll";
3978 #endif /* USE_MOTIF */
3981 && strcmp (action_name
, end_action
) == 0
3982 && WINDOWP (window_being_scrolled
))
3986 x_send_scroll_bar_event (window_being_scrolled
,
3987 scroll_bar_end_scroll
, 0, 0);
3988 w
= XWINDOW (window_being_scrolled
);
3990 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
3991 /* The thumb size is incorrect while dragging: fix it. */
3992 set_vertical_scroll_bar (w
);
3994 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
3995 window_being_scrolled
= Qnil
;
3996 last_scroll_bar_part
= -1;
3998 /* Xt timeouts no longer needed. */
3999 toolkit_scroll_bar_interaction
= 0;
4002 #endif /* not USE_GTK */
4004 /* A vector of windows used for communication between
4005 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4007 static struct window
**scroll_bar_windows
;
4008 static int scroll_bar_windows_size
;
4011 /* Send a client message with message type Xatom_Scrollbar for a
4012 scroll action to the frame of WINDOW. PART is a value identifying
4013 the part of the scroll bar that was clicked on. PORTION is the
4014 amount to scroll of a whole of WHOLE. */
4017 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4019 int part
, portion
, whole
;
4022 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4023 struct window
*w
= XWINDOW (window
);
4024 struct frame
*f
= XFRAME (w
->frame
);
4029 /* Construct a ClientMessage event to send to the frame. */
4030 ev
->type
= ClientMessage
;
4031 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4032 ev
->display
= FRAME_X_DISPLAY (f
);
4033 ev
->window
= FRAME_X_WINDOW (f
);
4036 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4037 not enough to store a pointer or Lisp_Object on a 64 bit system.
4038 So, store the window in scroll_bar_windows and pass the index
4039 into that array in the event. */
4040 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4041 if (scroll_bar_windows
[i
] == NULL
)
4044 if (i
== scroll_bar_windows_size
)
4046 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4047 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4048 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4050 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4052 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4053 scroll_bar_windows_size
= new_size
;
4056 scroll_bar_windows
[i
] = w
;
4057 ev
->data
.l
[0] = (long) i
;
4058 ev
->data
.l
[1] = (long) part
;
4059 ev
->data
.l
[2] = (long) 0;
4060 ev
->data
.l
[3] = (long) portion
;
4061 ev
->data
.l
[4] = (long) whole
;
4063 /* Make Xt timeouts work while the scroll bar is active. */
4064 toolkit_scroll_bar_interaction
= 1;
4066 /* Setting the event mask to zero means that the message will
4067 be sent to the client that created the window, and if that
4068 window no longer exists, no event will be sent. */
4069 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4074 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4078 x_scroll_bar_to_input_event (event
, ievent
)
4080 struct input_event
*ievent
;
4082 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4087 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4088 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4090 XSETWINDOW (window
, w
);
4091 f
= XFRAME (w
->frame
);
4093 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4094 ievent
->frame_or_window
= window
;
4097 ievent
->timestamp
= CurrentTime
;
4099 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4101 ievent
->part
= ev
->data
.l
[1];
4102 ievent
->code
= ev
->data
.l
[2];
4103 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4104 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4105 ievent
->modifiers
= 0;
4111 /* Minimum and maximum values used for Motif scroll bars. */
4113 #define XM_SB_MAX 10000000
4116 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4117 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4118 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4121 xm_scroll_callback (widget
, client_data
, call_data
)
4123 XtPointer client_data
, call_data
;
4125 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4126 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4127 int part
= -1, whole
= 0, portion
= 0;
4131 case XmCR_DECREMENT
:
4132 bar
->dragging
= Qnil
;
4133 part
= scroll_bar_up_arrow
;
4136 case XmCR_INCREMENT
:
4137 bar
->dragging
= Qnil
;
4138 part
= scroll_bar_down_arrow
;
4141 case XmCR_PAGE_DECREMENT
:
4142 bar
->dragging
= Qnil
;
4143 part
= scroll_bar_above_handle
;
4146 case XmCR_PAGE_INCREMENT
:
4147 bar
->dragging
= Qnil
;
4148 part
= scroll_bar_below_handle
;
4152 bar
->dragging
= Qnil
;
4153 part
= scroll_bar_to_top
;
4156 case XmCR_TO_BOTTOM
:
4157 bar
->dragging
= Qnil
;
4158 part
= scroll_bar_to_bottom
;
4165 /* Get the slider size. */
4167 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4170 whole
= XM_SB_MAX
- slider_size
;
4171 portion
= min (cs
->value
, whole
);
4172 part
= scroll_bar_handle
;
4173 bar
->dragging
= make_number (cs
->value
);
4177 case XmCR_VALUE_CHANGED
:
4183 window_being_scrolled
= bar
->window
;
4184 last_scroll_bar_part
= part
;
4185 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4190 #else /* !USE_MOTIF, i.e. Xaw or GTK */
4192 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4193 bar adjustment widget. DATA is a pointer to the scroll_bar structure. */
4196 xg_scroll_callback (widget
, data
)
4200 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4206 int part
= -1, whole
= 0, portion
= 0;
4207 GtkAdjustment
*adj
= GTK_ADJUSTMENT (widget
);
4209 if (xg_ignore_gtk_scrollbar
) return;
4211 position
= gtk_adjustment_get_value (adj
);
4213 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4216 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4218 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4224 diff
= (int) (position
- previous
);
4226 if (diff
== (int) adj
->step_increment
)
4228 part
= scroll_bar_down_arrow
;
4229 bar
->dragging
= Qnil
;
4231 else if (-diff
== (int) adj
->step_increment
)
4233 part
= scroll_bar_up_arrow
;
4234 bar
->dragging
= Qnil
;
4236 else if (diff
== (int) adj
->page_increment
)
4238 part
= scroll_bar_below_handle
;
4239 bar
->dragging
= Qnil
;
4241 else if (-diff
== (int) adj
->page_increment
)
4243 part
= scroll_bar_above_handle
;
4244 bar
->dragging
= Qnil
;
4248 part
= scroll_bar_handle
;
4249 whole
= adj
->upper
- adj
->page_size
;
4250 portion
= min ((int)position
, whole
);
4251 bar
->dragging
= make_number ((int)portion
);
4256 window_being_scrolled
= bar
->window
;
4257 last_scroll_bar_part
= part
;
4258 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4262 #else /* not USE_GTK */
4264 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4265 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4266 scroll bar struct. CALL_DATA is a pointer to a float saying where
4270 xaw_jump_callback (widget
, client_data
, call_data
)
4272 XtPointer client_data
, call_data
;
4274 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4275 float top
= *(float *) call_data
;
4277 int whole
, portion
, height
;
4280 /* Get the size of the thumb, a value between 0 and 1. */
4282 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4286 portion
= shown
< 1 ? top
* whole
: 0;
4288 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
4289 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4290 the bottom, so we force the scrolling whenever we see that we're
4291 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4292 we try to ensure that we always stay two pixels away from the
4294 part
= scroll_bar_down_arrow
;
4296 part
= scroll_bar_handle
;
4298 window_being_scrolled
= bar
->window
;
4299 bar
->dragging
= make_number (portion
);
4300 last_scroll_bar_part
= part
;
4301 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4305 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4306 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4307 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4308 the scroll bar. CALL_DATA is an integer specifying the action that
4309 has taken place. Its magnitude is in the range 0..height of the
4310 scroll bar. Negative values mean scroll towards buffer start.
4311 Values < height of scroll bar mean line-wise movement. */
4314 xaw_scroll_callback (widget
, client_data
, call_data
)
4316 XtPointer client_data
, call_data
;
4318 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4319 /* The position really is stored cast to a pointer. */
4320 int position
= (long) call_data
;
4324 /* Get the height of the scroll bar. */
4326 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4329 if (abs (position
) >= height
)
4330 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4332 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4333 it maps line-movement to call_data = max(5, height/20). */
4334 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
4335 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4337 part
= scroll_bar_move_ratio
;
4339 window_being_scrolled
= bar
->window
;
4340 bar
->dragging
= Qnil
;
4341 last_scroll_bar_part
= part
;
4342 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4345 #endif /* not USE_GTK */
4346 #endif /* not USE_MOTIF */
4348 #define SCROLL_BAR_NAME "verticalScrollBar"
4350 /* Create the widget for scroll bar BAR on frame F. Record the widget
4351 and X window of the scroll bar in BAR. */
4355 x_create_toolkit_scroll_bar (f
, bar
)
4357 struct scroll_bar
*bar
;
4359 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4362 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4367 #else /* not USE_GTK */
4370 x_create_toolkit_scroll_bar (f
, bar
)
4372 struct scroll_bar
*bar
;
4378 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4379 unsigned long pixel
;
4384 /* Set resources. Create the widget. */
4385 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4386 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4387 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4388 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4389 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4390 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4391 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4393 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4396 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4400 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4403 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4407 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4408 scroll_bar_name
, av
, ac
);
4410 /* Add one callback for everything that can happen. */
4411 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4413 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4415 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4417 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4419 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4421 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4423 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4426 /* Realize the widget. Only after that is the X window created. */
4427 XtRealizeWidget (widget
);
4429 /* Set the cursor to an arrow. I didn't find a resource to do that.
4430 And I'm wondering why it hasn't an arrow cursor by default. */
4431 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4432 f
->output_data
.x
->nontext_cursor
);
4434 #else /* !USE_MOTIF i.e. use Xaw */
4436 /* Set resources. Create the widget. The background of the
4437 Xaw3d scroll bar widget is a little bit light for my taste.
4438 We don't alter it here to let users change it according
4439 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4440 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4441 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4442 /* For smoother scrolling with Xaw3d -sm */
4443 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4445 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4448 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4452 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4455 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4459 /* Top/bottom shadow colors. */
4461 /* Allocate them, if necessary. */
4462 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4464 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4465 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4466 &pixel
, 1.2, 0x8000))
4468 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4470 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4472 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4473 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4474 &pixel
, 0.6, 0x4000))
4476 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4479 /* Tell the toolkit about them. */
4480 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4481 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4482 /* We tried to allocate a color for the top/bottom shadow, and
4483 failed, so tell Xaw3d to use dithering instead. */
4485 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4489 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4490 be more consistent with other emacs 3d colors, and since Xaw3d is
4491 not good at dealing with allocation failure. */
4493 /* This tells Xaw3d to use real colors instead of dithering for
4495 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4498 /* Specify the colors. */
4499 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4502 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
4505 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4508 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
4513 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4514 f
->output_data
.x
->edit_widget
, av
, ac
);
4518 char *val
= initial
;
4519 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4520 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4522 { /* ARROW_SCROLL */
4523 xaw3d_arrow_scroll
= True
;
4524 /* Isn't that just a personal preference ? -sm */
4525 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4529 /* Define callbacks. */
4530 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4531 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4534 /* Realize the widget. Only after that is the X window created. */
4535 XtRealizeWidget (widget
);
4537 #endif /* !USE_MOTIF */
4539 /* Install an action hook that lets us detect when the user
4540 finishes interacting with a scroll bar. */
4541 if (action_hook_id
== 0)
4542 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4544 /* Remember X window and widget in the scroll bar vector. */
4545 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4546 xwindow
= XtWindow (widget
);
4547 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
4551 #endif /* not USE_GTK */
4554 /* Set the thumb size and position of scroll bar BAR. We are currently
4555 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4559 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4560 struct scroll_bar
*bar
;
4561 int portion
, position
, whole
;
4563 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4566 #else /* not USE_GTK */
4568 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4569 struct scroll_bar
*bar
;
4570 int portion
, position
, whole
;
4572 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4573 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4580 /* We use an estimate of 30 chars per line rather than the real
4581 `portion' value. This has the disadvantage that the thumb size
4582 is not very representative, but it makes our life a lot easier.
4583 Otherwise, we have to constantly adjust the thumb size, which
4584 we can't always do quickly enough: while dragging, the size of
4585 the thumb might prevent the user from dragging the thumb all the
4586 way to the end. but Motif and some versions of Xaw3d don't allow
4587 updating the thumb size while dragging. Also, even if we can update
4588 its size, the update will often happen too late.
4589 If you don't believe it, check out revision 1.650 of xterm.c to see
4590 what hoops we were going through and the still poor behavior we got. */
4591 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
4592 /* When the thumb is at the bottom, position == whole.
4593 So we need to increase `whole' to make space for the thumb. */
4600 top
= (float) position
/ whole
;
4601 shown
= (float) portion
/ whole
;
4604 if (NILP (bar
->dragging
))
4608 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4609 is the scroll bar's maximum and MIN is the scroll bar's minimum
4611 size
= shown
* XM_SB_MAX
;
4612 size
= min (size
, XM_SB_MAX
);
4613 size
= max (size
, 1);
4615 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4616 value
= top
* XM_SB_MAX
;
4617 value
= min (value
, XM_SB_MAX
- size
);
4619 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4621 #else /* !USE_MOTIF i.e. use Xaw */
4627 top
= (float) position
/ whole
;
4628 shown
= (float) portion
/ whole
;
4632 float old_top
, old_shown
;
4634 XtVaGetValues (widget
,
4635 XtNtopOfThumb
, &old_top
,
4636 XtNshown
, &old_shown
,
4640 /* Massage the top+shown values. */
4641 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4642 top
= max (0, min (1, top
));
4645 /* Keep two pixels available for moving the thumb down. */
4646 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4648 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4649 check that your system's configuration file contains a define
4650 for `NARROWPROTO'. See s/freebsd.h for an example. */
4651 if (top
!= old_top
|| shown
!= old_shown
)
4653 if (NILP (bar
->dragging
))
4654 XawScrollbarSetThumb (widget
, top
, shown
);
4658 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
4659 int scroll_mode
= 0;
4661 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
4662 if (xaw3d_arrow_scroll
)
4664 /* Xaw3d stupidly ignores resize requests while dragging
4665 so we have to make it believe it's not in dragging mode. */
4666 scroll_mode
= sb
->scrollbar
.scroll_mode
;
4667 if (scroll_mode
== 2)
4668 sb
->scrollbar
.scroll_mode
= 0;
4671 /* Try to make the scrolling a tad smoother. */
4672 if (!xaw3d_pick_top
)
4673 shown
= min (shown
, old_shown
);
4675 XawScrollbarSetThumb (widget
, top
, shown
);
4678 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
4679 sb
->scrollbar
.scroll_mode
= scroll_mode
;
4684 #endif /* !USE_MOTIF */
4688 #endif /* not USE_GTK */
4690 #endif /* USE_TOOLKIT_SCROLL_BARS */
4694 /************************************************************************
4695 Scroll bars, general
4696 ************************************************************************/
4698 /* Create a scroll bar and return the scroll bar vector for it. W is
4699 the Emacs window on which to create the scroll bar. TOP, LEFT,
4700 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4703 static struct scroll_bar
*
4704 x_scroll_bar_create (w
, top
, left
, width
, height
)
4706 int top
, left
, width
, height
;
4708 struct frame
*f
= XFRAME (w
->frame
);
4709 struct scroll_bar
*bar
4710 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4714 #ifdef USE_TOOLKIT_SCROLL_BARS
4715 x_create_toolkit_scroll_bar (f
, bar
);
4716 #else /* not USE_TOOLKIT_SCROLL_BARS */
4718 XSetWindowAttributes a
;
4722 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4723 if (a
.background_pixel
== -1)
4724 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
4726 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4727 | ButtonMotionMask
| PointerMotionHintMask
4729 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4731 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4733 /* Clear the area of W that will serve as a scroll bar. This is
4734 for the case that a window has been split horizontally. In
4735 this case, no clear_frame is generated to reduce flickering. */
4736 if (width
> 0 && height
> 0)
4737 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4739 window_box_height (w
), False
);
4741 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4742 /* Position and size of scroll bar. */
4743 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4745 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4747 /* Border width, depth, class, and visual. */
4754 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
4756 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4758 XSETWINDOW (bar
->window
, w
);
4759 XSETINT (bar
->top
, top
);
4760 XSETINT (bar
->left
, left
);
4761 XSETINT (bar
->width
, width
);
4762 XSETINT (bar
->height
, height
);
4763 XSETINT (bar
->start
, 0);
4764 XSETINT (bar
->end
, 0);
4765 bar
->dragging
= Qnil
;
4767 /* Add bar to its frame's list of scroll bars. */
4768 bar
->next
= FRAME_SCROLL_BARS (f
);
4770 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4771 if (!NILP (bar
->next
))
4772 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4774 /* Map the window/widget. */
4775 #ifdef USE_TOOLKIT_SCROLL_BARS
4778 xg_update_scrollbar_pos (f
,
4779 SCROLL_BAR_X_WINDOW (bar
),
4781 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4782 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4786 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
4787 #else /* not USE_GTK */
4788 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4789 XtConfigureWidget (scroll_bar
,
4790 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4792 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4793 max (height
, 1), 0);
4794 XtMapWidget (scroll_bar
);
4795 #endif /* not USE_GTK */
4797 #else /* not USE_TOOLKIT_SCROLL_BARS */
4798 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4799 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4806 /* Draw BAR's handle in the proper position.
4808 If the handle is already drawn from START to END, don't bother
4809 redrawing it, unless REBUILD is non-zero; in that case, always
4810 redraw it. (REBUILD is handy for drawing the handle after expose
4813 Normally, we want to constrain the start and end of the handle to
4814 fit inside its rectangle, but if the user is dragging the scroll
4815 bar handle, we want to let them drag it down all the way, so that
4816 the bar's top is as far down as it goes; otherwise, there's no way
4817 to move to the very end of the buffer. */
4819 #ifndef USE_TOOLKIT_SCROLL_BARS
4822 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4823 struct scroll_bar
*bar
;
4827 int dragging
= ! NILP (bar
->dragging
);
4828 Window w
= SCROLL_BAR_X_WINDOW (bar
);
4829 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4830 GC gc
= f
->output_data
.x
->normal_gc
;
4832 /* If the display is already accurate, do nothing. */
4834 && start
== XINT (bar
->start
)
4835 && end
== XINT (bar
->end
))
4841 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
4842 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
4843 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4845 /* Make sure the values are reasonable, and try to preserve
4846 the distance between start and end. */
4848 int length
= end
- start
;
4852 else if (start
> top_range
)
4854 end
= start
+ length
;
4858 else if (end
> top_range
&& ! dragging
)
4862 /* Store the adjusted setting in the scroll bar. */
4863 XSETINT (bar
->start
, start
);
4864 XSETINT (bar
->end
, end
);
4866 /* Clip the end position, just for display. */
4867 if (end
> top_range
)
4870 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
4871 below top positions, to make sure the handle is always at least
4872 that many pixels tall. */
4873 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4875 /* Draw the empty space above the handle. Note that we can't clear
4876 zero-height areas; that means "clear to end of window." */
4878 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4879 /* x, y, width, height, and exposures. */
4880 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4881 VERTICAL_SCROLL_BAR_TOP_BORDER
,
4882 inside_width
, start
,
4885 /* Change to proper foreground color if one is specified. */
4886 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4887 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4888 f
->output_data
.x
->scroll_bar_foreground_pixel
);
4890 /* Draw the handle itself. */
4891 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
4892 /* x, y, width, height */
4893 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4894 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
4895 inside_width
, end
- start
);
4897 /* Restore the foreground color of the GC if we changed it above. */
4898 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4899 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4900 f
->output_data
.x
->foreground_pixel
);
4902 /* Draw the empty space below the handle. Note that we can't
4903 clear zero-height areas; that means "clear to end of window." */
4904 if (end
< inside_height
)
4905 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4906 /* x, y, width, height, and exposures. */
4907 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4908 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
4909 inside_width
, inside_height
- end
,
4917 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4919 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4923 x_scroll_bar_remove (bar
)
4924 struct scroll_bar
*bar
;
4926 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4929 #ifdef USE_TOOLKIT_SCROLL_BARS
4931 xg_remove_scroll_bar (f
, SCROLL_BAR_X_WINDOW (bar
));
4932 #else /* not USE_GTK */
4933 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
4934 #endif /* not USE_GTK */
4936 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4939 /* Disassociate this scroll bar from its window. */
4940 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4946 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4947 that we are displaying PORTION characters out of a total of WHOLE
4948 characters, starting at POSITION. If WINDOW has no scroll bar,
4952 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4954 int portion
, whole
, position
;
4956 struct frame
*f
= XFRAME (w
->frame
);
4957 struct scroll_bar
*bar
;
4958 int top
, height
, left
, sb_left
, width
, sb_width
;
4959 int window_x
, window_y
, window_width
, window_height
;
4961 /* Get window dimensions. */
4962 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
4964 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
4965 height
= window_height
;
4967 /* Compute the left edge of the scroll bar area. */
4968 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4969 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
4971 left
= XFASTINT (w
->left
);
4972 left
*= CANON_X_UNIT (f
);
4973 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4975 /* Compute the width of the scroll bar which might be less than
4976 the width of the area reserved for the scroll bar. */
4977 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
4978 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
4982 /* Compute the left edge of the scroll bar. */
4983 #ifdef USE_TOOLKIT_SCROLL_BARS
4984 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4985 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
4987 sb_left
= left
+ (width
- sb_width
) / 2;
4989 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4990 sb_left
= left
+ width
- sb_width
;
4995 /* Does the scroll bar exist yet? */
4996 if (NILP (w
->vertical_scroll_bar
))
4998 if (width
> 0 && height
> 0)
5001 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5002 left
, top
, width
, height
, False
);
5006 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5010 /* It may just need to be moved and resized. */
5011 unsigned int mask
= 0;
5013 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5017 if (sb_left
!= XINT (bar
->left
))
5019 if (top
!= XINT (bar
->top
))
5021 if (sb_width
!= XINT (bar
->width
))
5023 if (height
!= XINT (bar
->height
))
5026 #ifdef USE_TOOLKIT_SCROLL_BARS
5030 xg_update_scrollbar_pos (f
,
5031 SCROLL_BAR_X_WINDOW (bar
),
5033 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5034 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5038 #else /* not USE_GTK */
5040 /* Since toolkit scroll bars are smaller than the space reserved
5041 for them on the frame, we have to clear "under" them. */
5042 if (width
> 0 && height
> 0)
5043 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5044 left
, top
, width
, height
, False
);
5045 /* Move/size the scroll bar widget. */
5047 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5048 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5050 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5051 max (height
, 1), 0);
5053 #endif /* not USE_GTK */
5054 #else /* not USE_TOOLKIT_SCROLL_BARS */
5056 /* Clear areas not covered by the scroll bar because of
5057 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5058 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5060 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5061 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5063 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5064 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5065 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5069 /* Clear areas not covered by the scroll bar because it's not as
5070 wide as the area reserved for it. This makes sure a
5071 previous mode line display is cleared after C-x 2 C-x 1, for
5074 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
5075 int rest
= area_width
- sb_width
;
5076 if (rest
> 0 && height
> 0)
5078 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
5079 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5080 left
+ area_width
- rest
, top
,
5081 rest
, height
, False
);
5083 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5084 left
, top
, rest
, height
, False
);
5088 /* Move/size the scroll bar window. */
5093 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5095 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5097 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
5101 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5103 /* Remember new settings. */
5104 XSETINT (bar
->left
, sb_left
);
5105 XSETINT (bar
->top
, top
);
5106 XSETINT (bar
->width
, sb_width
);
5107 XSETINT (bar
->height
, height
);
5112 #ifdef USE_TOOLKIT_SCROLL_BARS
5113 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5114 #else /* not USE_TOOLKIT_SCROLL_BARS */
5115 /* Set the scroll bar's current state, unless we're currently being
5117 if (NILP (bar
->dragging
))
5119 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5122 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5125 int start
= ((double) position
* top_range
) / whole
;
5126 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5127 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5130 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5132 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5136 /* The following three hooks are used when we're doing a thorough
5137 redisplay of the frame. We don't explicitly know which scroll bars
5138 are going to be deleted, because keeping track of when windows go
5139 away is a real pain - "Can you say set-window-configuration, boys
5140 and girls?" Instead, we just assert at the beginning of redisplay
5141 that *all* scroll bars are to be removed, and then save a scroll bar
5142 from the fiery pit when we actually redisplay its window. */
5144 /* Arrange for all scroll bars on FRAME to be removed at the next call
5145 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5146 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5149 XTcondemn_scroll_bars (frame
)
5152 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5153 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5156 bar
= FRAME_SCROLL_BARS (frame
);
5157 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5158 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5159 XSCROLL_BAR (bar
)->prev
= Qnil
;
5160 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5161 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5162 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5167 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5168 Note that WINDOW isn't necessarily condemned at all. */
5171 XTredeem_scroll_bar (window
)
5172 struct window
*window
;
5174 struct scroll_bar
*bar
;
5177 /* We can't redeem this window's scroll bar if it doesn't have one. */
5178 if (NILP (window
->vertical_scroll_bar
))
5181 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5183 /* Unlink it from the condemned list. */
5184 f
= XFRAME (WINDOW_FRAME (window
));
5185 if (NILP (bar
->prev
))
5187 /* If the prev pointer is nil, it must be the first in one of
5189 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5190 /* It's not condemned. Everything's fine. */
5192 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5193 window
->vertical_scroll_bar
))
5194 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5196 /* If its prev pointer is nil, it must be at the front of
5197 one or the other! */
5201 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5203 if (! NILP (bar
->next
))
5204 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5206 bar
->next
= FRAME_SCROLL_BARS (f
);
5208 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5209 if (! NILP (bar
->next
))
5210 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5213 /* Remove all scroll bars on FRAME that haven't been saved since the
5214 last call to `*condemn_scroll_bars_hook'. */
5217 XTjudge_scroll_bars (f
)
5220 Lisp_Object bar
, next
;
5222 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5224 /* Clear out the condemned list now so we won't try to process any
5225 more events on the hapless scroll bars. */
5226 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5228 for (; ! NILP (bar
); bar
= next
)
5230 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5232 x_scroll_bar_remove (b
);
5235 b
->next
= b
->prev
= Qnil
;
5238 /* Now there should be no references to the condemned scroll bars,
5239 and they should get garbage-collected. */
5243 #ifndef USE_TOOLKIT_SCROLL_BARS
5244 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5245 is a no-op when using toolkit scroll bars.
5247 This may be called from a signal handler, so we have to ignore GC
5251 x_scroll_bar_expose (bar
, event
)
5252 struct scroll_bar
*bar
;
5255 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5256 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5257 GC gc
= f
->output_data
.x
->normal_gc
;
5258 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5262 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
5264 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5265 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5267 /* x, y, width, height */
5269 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
5270 XINT (bar
->height
) - 1);
5275 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5277 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5278 is set to something other than NO_EVENT, it is enqueued.
5280 This may be called from a signal handler, so we have to ignore GC
5285 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5286 struct scroll_bar
*bar
;
5288 struct input_event
*emacs_event
;
5290 if (! GC_WINDOWP (bar
->window
))
5293 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5294 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5295 emacs_event
->modifiers
5296 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5297 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5298 event
->xbutton
.state
)
5299 | (event
->type
== ButtonRelease
5302 emacs_event
->frame_or_window
= bar
->window
;
5303 emacs_event
->arg
= Qnil
;
5304 emacs_event
->timestamp
= event
->xbutton
.time
;
5307 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5309 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5312 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5313 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5316 if (y
> top_range
) y
= top_range
;
5318 if (y
< XINT (bar
->start
))
5319 emacs_event
->part
= scroll_bar_above_handle
;
5320 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5321 emacs_event
->part
= scroll_bar_handle
;
5323 emacs_event
->part
= scroll_bar_below_handle
;
5325 /* Just because the user has clicked on the handle doesn't mean
5326 they want to drag it. Lisp code needs to be able to decide
5327 whether or not we're dragging. */
5329 /* If the user has just clicked on the handle, record where they're
5331 if (event
->type
== ButtonPress
5332 && emacs_event
->part
== scroll_bar_handle
)
5333 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
5336 #ifndef USE_TOOLKIT_SCROLL_BARS
5337 /* If the user has released the handle, set it to its final position. */
5338 if (event
->type
== ButtonRelease
5339 && ! NILP (bar
->dragging
))
5341 int new_start
= y
- XINT (bar
->dragging
);
5342 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5344 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5345 bar
->dragging
= Qnil
;
5349 /* Same deal here as the other #if 0. */
5351 /* Clicks on the handle are always reported as occurring at the top of
5353 if (emacs_event
->part
== scroll_bar_handle
)
5354 emacs_event
->x
= bar
->start
;
5356 XSETINT (emacs_event
->x
, y
);
5358 XSETINT (emacs_event
->x
, y
);
5361 XSETINT (emacs_event
->y
, top_range
);
5365 #ifndef USE_TOOLKIT_SCROLL_BARS
5367 /* Handle some mouse motion while someone is dragging the scroll bar.
5369 This may be called from a signal handler, so we have to ignore GC
5373 x_scroll_bar_note_movement (bar
, event
)
5374 struct scroll_bar
*bar
;
5377 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5379 last_mouse_movement_time
= event
->xmotion
.time
;
5382 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5384 /* If we're dragging the bar, display it. */
5385 if (! GC_NILP (bar
->dragging
))
5387 /* Where should the handle be now? */
5388 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5390 if (new_start
!= XINT (bar
->start
))
5392 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5394 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5399 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5401 /* Return information to the user about the current position of the mouse
5402 on the scroll bar. */
5405 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5407 Lisp_Object
*bar_window
;
5408 enum scroll_bar_part
*part
;
5410 unsigned long *time
;
5412 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5413 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5414 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5416 Window dummy_window
;
5418 unsigned int dummy_mask
;
5422 /* Get the mouse's position relative to the scroll bar window, and
5424 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5426 /* Root, child, root x and root y. */
5427 &dummy_window
, &dummy_window
,
5428 &dummy_coord
, &dummy_coord
,
5430 /* Position relative to scroll bar. */
5433 /* Mouse buttons and modifier keys. */
5440 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5443 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5445 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5447 if (! NILP (bar
->dragging
))
5448 win_y
-= XINT (bar
->dragging
);
5452 if (win_y
> top_range
)
5456 *bar_window
= bar
->window
;
5458 if (! NILP (bar
->dragging
))
5459 *part
= scroll_bar_handle
;
5460 else if (win_y
< XINT (bar
->start
))
5461 *part
= scroll_bar_above_handle
;
5462 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5463 *part
= scroll_bar_handle
;
5465 *part
= scroll_bar_below_handle
;
5467 XSETINT (*x
, win_y
);
5468 XSETINT (*y
, top_range
);
5471 last_mouse_scroll_bar
= Qnil
;
5474 *time
= last_mouse_movement_time
;
5480 /* The screen has been cleared so we may have changed foreground or
5481 background colors, and the scroll bars may need to be redrawn.
5482 Clear out the scroll bars, and ask for expose events, so we can
5486 x_scroll_bar_clear (f
)
5489 #ifndef USE_TOOLKIT_SCROLL_BARS
5492 /* We can have scroll bars even if this is 0,
5493 if we just turned off scroll bar mode.
5494 But in that case we should not clear them. */
5495 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5496 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5497 bar
= XSCROLL_BAR (bar
)->next
)
5498 XClearArea (FRAME_X_DISPLAY (f
),
5499 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
5501 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5505 /* Define a queue to save up SelectionRequest events for later handling. */
5507 struct selection_event_queue
5510 struct selection_event_queue
*next
;
5513 static struct selection_event_queue
*queue
;
5515 /* Nonzero means queue up certain events--don't process them yet. */
5517 static int x_queue_selection_requests
;
5519 /* Queue up an X event *EVENT, to be processed later. */
5522 x_queue_event (f
, event
)
5526 struct selection_event_queue
*queue_tmp
5527 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
5529 if (queue_tmp
!= NULL
)
5531 queue_tmp
->event
= *event
;
5532 queue_tmp
->next
= queue
;
5537 /* Take all the queued events and put them back
5538 so that they get processed afresh. */
5541 x_unqueue_events (display
)
5544 while (queue
!= NULL
)
5546 struct selection_event_queue
*queue_tmp
= queue
;
5547 XPutBackEvent (display
, &queue_tmp
->event
);
5548 queue
= queue_tmp
->next
;
5549 xfree ((char *)queue_tmp
);
5553 /* Start queuing SelectionRequest events. */
5556 x_start_queuing_selection_requests (display
)
5559 x_queue_selection_requests
++;
5562 /* Stop queuing SelectionRequest events. */
5565 x_stop_queuing_selection_requests (display
)
5568 x_queue_selection_requests
--;
5569 x_unqueue_events (display
);
5572 /* The main X event-reading loop - XTread_socket. */
5575 /* Time stamp of enter window event. This is only used by XTread_socket,
5576 but we have to put it out here, since static variables within functions
5577 sometimes don't work. */
5579 static Time enter_timestamp
;
5582 /* This holds the state XLookupString needs to implement dead keys
5583 and other tricks known as "compose processing". _X Window System_
5584 says that a portable program can't use this, but Stephen Gildea assures
5585 me that letting the compiler initialize it to zeros will work okay.
5587 This must be defined outside of XTread_socket, for the same reasons
5588 given for enter_timestamp, above. */
5590 static XComposeStatus compose_status
;
5592 /* Record the last 100 characters stored
5593 to help debug the loss-of-chars-during-GC problem. */
5595 static int temp_index
;
5596 static short temp_buffer
[100];
5598 /* Set this to nonzero to fake an "X I/O error"
5599 on a particular display. */
5601 struct x_display_info
*XTread_socket_fake_io_error
;
5603 /* When we find no input here, we occasionally do a no-op command
5604 to verify that the X server is still running and we can still talk with it.
5605 We try all the open displays, one by one.
5606 This variable is used for cycling thru the displays. */
5608 static struct x_display_info
*next_noop_dpyinfo
;
5610 #define SET_SAVED_MENU_EVENT(size) \
5613 if (f->output_data.x->saved_menu_event == 0) \
5614 f->output_data.x->saved_menu_event \
5615 = (XEvent *) xmalloc (sizeof (XEvent)); \
5616 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5617 if (numchars >= 1) \
5619 bufp->kind = MENU_BAR_ACTIVATE_EVENT; \
5620 XSETFRAME (bufp->frame_or_window, f); \
5629 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5630 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5640 /* Filter events for the current X input method.
5641 DPYINFO is the display this event is for.
5642 EVENT is the X event to filter.
5644 Returns non-zero if the event was filtered, caller shall not process
5646 Returns zero if event is wasn't filtered. */
5650 x_filter_event (dpyinfo
, event
)
5651 struct x_display_info
*dpyinfo
;
5654 /* XFilterEvent returns non-zero if the input method has
5655 consumed the event. We pass the frame's X window to
5656 XFilterEvent because that's the one for which the IC
5659 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5660 event
->xclient
.window
);
5662 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5667 static struct x_display_info
*current_dpyinfo
;
5668 static struct input_event
**current_bufp
;
5669 static int *current_numcharsp
;
5670 static int current_count
;
5671 static int current_finish
;
5673 /* This is the filter function invoked by the GTK event loop.
5674 It is invoked before the XEvent is translated to a GdkEvent,
5675 so we have a chanse to act on the event before GTK. */
5676 static GdkFilterReturn
5677 event_handler_gdk (gxev
, ev
, data
)
5682 XEvent
*xev
= (XEvent
*)gxev
;
5684 if (current_numcharsp
)
5687 /* Filter events for the current X input method.
5688 GTK calls XFilterEvent but not for key press and release,
5689 so we do it here. */
5690 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5691 if (x_filter_event (current_dpyinfo
, xev
))
5692 return GDK_FILTER_REMOVE
;
5694 current_count
+= handle_one_xevent (current_dpyinfo
,
5701 current_finish
= x_dispatch_event (xev
, GDK_DISPLAY ());
5703 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5704 return GDK_FILTER_REMOVE
;
5706 return GDK_FILTER_CONTINUE
;
5708 #endif /* USE_GTK */
5711 /* Handles the XEvent EVENT on display DPYINFO.
5713 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5714 *FINISH is zero if caller should continue reading events.
5715 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5717 Events representing keys are stored in buffer *BUFP_R,
5718 which can hold up to *NUMCHARSP characters.
5719 We return the number of characters stored into the buffer. */
5722 handle_one_xevent (dpyinfo
, eventp
, bufp_r
, numcharsp
, finish
)
5723 struct x_display_info
*dpyinfo
;
5725 /* register */ struct input_event
**bufp_r
;
5726 /* register */ int *numcharsp
;
5732 struct coding_system coding
;
5733 struct input_event
*bufp
= *bufp_r
;
5734 int numchars
= *numcharsp
;
5735 XEvent event
= *eventp
;
5737 *finish
= X_EVENT_NORMAL
;
5743 if (event
.xclient
.message_type
5744 == dpyinfo
->Xatom_wm_protocols
5745 && event
.xclient
.format
== 32)
5747 if (event
.xclient
.data
.l
[0]
5748 == dpyinfo
->Xatom_wm_take_focus
)
5750 /* Use x_any_window_to_frame because this
5751 could be the shell widget window
5752 if the frame has no title bar. */
5753 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5755 /* Not quite sure this is needed -pd */
5756 if (f
&& FRAME_XIC (f
))
5757 XSetICFocus (FRAME_XIC (f
));
5759 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5760 instructs the WM to set the input focus automatically for
5761 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5762 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5763 it has set the focus. So, XSetInputFocus below is not
5766 The call to XSetInputFocus below has also caused trouble. In
5767 cases where the XSetInputFocus done by the WM and the one
5768 below are temporally close (on a fast machine), the call
5769 below can generate additional FocusIn events which confuse
5772 /* Since we set WM_TAKE_FOCUS, we must call
5773 XSetInputFocus explicitly. But not if f is null,
5774 since that might be an event for a deleted frame. */
5777 Display
*d
= event
.xclient
.display
;
5778 /* Catch and ignore errors, in case window has been
5779 iconified by a window manager such as GWM. */
5780 int count
= x_catch_errors (d
);
5781 XSetInputFocus (d
, event
.xclient
.window
,
5782 /* The ICCCM says this is
5783 the only valid choice. */
5785 event
.xclient
.data
.l
[1]);
5786 /* This is needed to detect the error
5787 if there is an error. */
5789 x_uncatch_errors (d
, count
);
5791 /* Not certain about handling scroll bars here */
5794 else if (event
.xclient
.data
.l
[0]
5795 == dpyinfo
->Xatom_wm_save_yourself
)
5797 /* Save state modify the WM_COMMAND property to
5798 something which can reinstate us. This notifies
5799 the session manager, who's looking for such a
5800 PropertyNotify. Can restart processing when
5801 a keyboard or mouse event arrives. */
5802 /* If we have a session manager, don't set this.
5803 KDE will then start two Emacsen, one for the
5804 session manager and one for this. */
5807 && ! x_session_have_connection ()
5811 f
= x_top_window_to_frame (dpyinfo
,
5812 event
.xclient
.window
);
5813 /* This is just so we only give real data once
5814 for a single Emacs process. */
5815 if (f
== SELECTED_FRAME ())
5816 XSetCommand (FRAME_X_DISPLAY (f
),
5817 event
.xclient
.window
,
5818 initial_argv
, initial_argc
);
5820 XSetCommand (FRAME_X_DISPLAY (f
),
5821 event
.xclient
.window
,
5825 else if (event
.xclient
.data
.l
[0]
5826 == dpyinfo
->Xatom_wm_delete_window
)
5829 = x_any_window_to_frame (dpyinfo
,
5830 event
.xclient
.window
);
5837 bufp
->kind
= DELETE_WINDOW_EVENT
;
5838 XSETFRAME (bufp
->frame_or_window
, f
);
5846 goto OTHER
; /* May be a dialog that is to be removed */
5849 else if (event
.xclient
.message_type
5850 == dpyinfo
->Xatom_wm_configure_denied
)
5853 else if (event
.xclient
.message_type
5854 == dpyinfo
->Xatom_wm_window_moved
)
5858 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5860 new_x
= event
.xclient
.data
.s
[0];
5861 new_y
= event
.xclient
.data
.s
[1];
5865 f
->output_data
.x
->left_pos
= new_x
;
5866 f
->output_data
.x
->top_pos
= new_y
;
5870 else if (event
.xclient
.message_type
5871 == dpyinfo
->Xatom_editres
)
5874 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5875 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5878 #endif /* HACK_EDITRES */
5879 else if ((event
.xclient
.message_type
5880 == dpyinfo
->Xatom_DONE
)
5881 || (event
.xclient
.message_type
5882 == dpyinfo
->Xatom_PAGE
))
5884 /* Ghostview job completed. Kill it. We could
5885 reply with "Next" if we received "Page", but we
5886 currently never do because we are interested in
5887 images, only, which should have 1 page. */
5888 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5890 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5891 x_kill_gs_process (pixmap
, f
);
5892 expose_frame (f
, 0, 0, 0, 0);
5894 #ifdef USE_TOOLKIT_SCROLL_BARS
5895 /* Scroll bar callbacks send a ClientMessage from which
5896 we construct an input_event. */
5897 else if (event
.xclient
.message_type
5898 == dpyinfo
->Xatom_Scrollbar
)
5900 x_scroll_bar_to_input_event (&event
, bufp
);
5901 ++bufp
, ++count
, --numchars
;
5904 #endif /* USE_TOOLKIT_SCROLL_BARS */
5910 case SelectionNotify
:
5911 #ifdef USE_X_TOOLKIT
5912 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5914 #endif /* not USE_X_TOOLKIT */
5915 x_handle_selection_notify (&event
.xselection
);
5918 case SelectionClear
: /* Someone has grabbed ownership. */
5919 #ifdef USE_X_TOOLKIT
5920 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5922 #endif /* USE_X_TOOLKIT */
5924 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
5929 bufp
->kind
= SELECTION_CLEAR_EVENT
;
5930 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
5931 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
5932 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
5933 bufp
->frame_or_window
= Qnil
;
5942 case SelectionRequest
: /* Someone wants our selection. */
5943 #ifdef USE_X_TOOLKIT
5944 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
5946 #endif /* USE_X_TOOLKIT */
5947 if (x_queue_selection_requests
)
5948 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
5952 XSelectionRequestEvent
*eventp
5953 = (XSelectionRequestEvent
*) &event
;
5958 bufp
->kind
= SELECTION_REQUEST_EVENT
;
5959 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
5960 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
5961 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
5962 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
5963 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
5964 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
5965 bufp
->frame_or_window
= Qnil
;
5974 case PropertyNotify
:
5975 #if 0 /* This is plain wrong. In the case that we are waiting for a
5976 PropertyNotify used as an ACK in incremental selection
5977 transfer, the property will be on the receiver's window. */
5978 #if defined USE_X_TOOLKIT
5979 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
5983 x_handle_property_notify (&event
.xproperty
);
5986 case ReparentNotify
:
5987 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
5991 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
5992 x_real_positions (f
, &x
, &y
);
5993 f
->output_data
.x
->left_pos
= x
;
5994 f
->output_data
.x
->top_pos
= y
;
6000 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6003 x_check_fullscreen (f
);
6005 if (f
->async_visible
== 0)
6007 f
->async_visible
= 1;
6008 f
->async_iconified
= 0;
6009 f
->output_data
.x
->has_been_visible
= 1;
6010 SET_FRAME_GARBAGED (f
);
6013 expose_frame (x_window_to_frame (dpyinfo
,
6014 event
.xexpose
.window
),
6015 event
.xexpose
.x
, event
.xexpose
.y
,
6016 event
.xexpose
.width
, event
.xexpose
.height
);
6020 #ifndef USE_TOOLKIT_SCROLL_BARS
6021 struct scroll_bar
*bar
;
6023 #if defined USE_LUCID
6024 /* Submenus of the Lucid menu bar aren't widgets
6025 themselves, so there's no way to dispatch events
6026 to them. Recognize this case separately. */
6029 = x_window_to_menu_bar (event
.xexpose
.window
);
6031 xlwmenu_redisplay (widget
);
6033 #endif /* USE_LUCID */
6035 #ifdef USE_TOOLKIT_SCROLL_BARS
6036 /* Dispatch event to the widget. */
6038 #else /* not USE_TOOLKIT_SCROLL_BARS */
6039 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
6042 x_scroll_bar_expose (bar
, &event
);
6043 #ifdef USE_X_TOOLKIT
6046 #endif /* USE_X_TOOLKIT */
6047 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6051 case GraphicsExpose
: /* This occurs when an XCopyArea's
6052 source area was obscured or not
6054 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6058 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6059 event
.xgraphicsexpose
.width
,
6060 event
.xgraphicsexpose
.height
);
6062 #ifdef USE_X_TOOLKIT
6065 #endif /* USE_X_TOOLKIT */
6068 case NoExpose
: /* This occurs when an XCopyArea's
6069 source area was completely
6074 /* Redo the mouse-highlight after the tooltip has gone. */
6075 if (event
.xmap
.window
== tip_window
)
6078 redo_mouse_highlight ();
6081 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6082 if (f
) /* F may no longer exist if
6083 the frame was deleted. */
6085 /* While a frame is unmapped, display generation is
6086 disabled; you don't want to spend time updating a
6087 display that won't ever be seen. */
6088 f
->async_visible
= 0;
6089 /* We can't distinguish, from the event, whether the window
6090 has become iconified or invisible. So assume, if it
6091 was previously visible, than now it is iconified.
6092 But x_make_frame_invisible clears both
6093 the visible flag and the iconified flag;
6094 and that way, we know the window is not iconified now. */
6095 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6097 f
->async_iconified
= 1;
6099 bufp
->kind
= ICONIFY_EVENT
;
6100 XSETFRAME (bufp
->frame_or_window
, f
);
6110 if (event
.xmap
.window
== tip_window
)
6111 /* The tooltip has been drawn already. Avoid
6112 the SET_FRAME_GARBAGED below. */
6115 /* We use x_top_window_to_frame because map events can
6116 come for sub-windows and they don't mean that the
6117 frame is visible. */
6118 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6121 /* wait_reading_process_input will notice this and update
6122 the frame's display structures.
6123 If we where iconified, we should not set garbaged,
6124 because that stops redrawing on Expose events. This looks
6125 bad if we are called from a recursive event loop
6126 (x_dispatch_event), for example when a dialog is up. */
6127 if (! f
->async_iconified
)
6128 SET_FRAME_GARBAGED (f
);
6130 f
->async_visible
= 1;
6131 f
->async_iconified
= 0;
6132 f
->output_data
.x
->has_been_visible
= 1;
6136 bufp
->kind
= DEICONIFY_EVENT
;
6137 XSETFRAME (bufp
->frame_or_window
, f
);
6143 else if (! NILP (Vframe_list
)
6144 && ! NILP (XCDR (Vframe_list
)))
6145 /* Force a redisplay sooner or later
6146 to update the frame titles
6147 in case this is the second frame. */
6148 record_asynch_buffer_change ();
6154 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6155 /* Dispatch KeyPress events when in menu. */
6156 if (popup_activated ())
6160 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6162 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
6164 dpyinfo
->mouse_face_hidden
= 1;
6165 clear_mouse_face (dpyinfo
);
6168 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6171 /* Scroll bars consume key events, but we want
6172 the keys to go to the scroll bar's frame. */
6173 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6175 if (widget
&& XmIsScrollBar (widget
))
6177 widget
= XtParent (widget
);
6178 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6181 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6185 KeySym keysym
, orig_keysym
;
6186 /* al%imercury@uunet.uu.net says that making this 81
6187 instead of 80 fixed a bug whereby meta chars made
6190 It seems that some version of XmbLookupString has
6191 a bug of not returning XBufferOverflow in
6192 status_return even if the input is too long to
6193 fit in 81 bytes. So, we must prepare sufficient
6194 bytes for copy_buffer. 513 bytes (256 chars for
6195 two-byte character set) seems to be a fairly good
6196 approximation. -- 2000.8.10 handa@etl.go.jp */
6197 unsigned char copy_buffer
[513];
6198 unsigned char *copy_bufptr
= copy_buffer
;
6199 int copy_bufsiz
= sizeof (copy_buffer
);
6201 Lisp_Object coding_system
= Qlatin_1
;
6204 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6205 extra_keyboard_modifiers
);
6206 modifiers
= event
.xkey
.state
;
6208 /* This will have to go some day... */
6210 /* make_lispy_event turns chars into control chars.
6211 Don't do it here because XLookupString is too eager. */
6212 event
.xkey
.state
&= ~ControlMask
;
6213 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6214 | dpyinfo
->super_mod_mask
6215 | dpyinfo
->hyper_mod_mask
6216 | dpyinfo
->alt_mod_mask
);
6218 /* In case Meta is ComposeCharacter,
6219 clear its status. According to Markus Ehrnsperger
6220 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6221 this enables ComposeCharacter to work whether or
6222 not it is combined with Meta. */
6223 if (modifiers
& dpyinfo
->meta_mod_mask
)
6224 bzero (&compose_status
, sizeof (compose_status
));
6229 Status status_return
;
6231 coding_system
= Vlocale_coding_system
;
6232 nbytes
= XmbLookupString (FRAME_XIC (f
),
6233 &event
.xkey
, copy_bufptr
,
6234 copy_bufsiz
, &keysym
,
6236 if (status_return
== XBufferOverflow
)
6238 copy_bufsiz
= nbytes
+ 1;
6239 copy_bufptr
= (char *) alloca (copy_bufsiz
);
6240 nbytes
= XmbLookupString (FRAME_XIC (f
),
6241 &event
.xkey
, copy_bufptr
,
6242 copy_bufsiz
, &keysym
,
6245 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6246 #if 0 && defined X_HAVE_UTF8_STRING
6247 else if (status_return
== XLookupKeySym
)
6248 { /* Try again but with utf-8. */
6249 coding_system
= Qutf_8
;
6250 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6251 &event
.xkey
, copy_bufptr
,
6252 copy_bufsiz
, &keysym
,
6254 if (status_return
== XBufferOverflow
)
6256 copy_bufsiz
= nbytes
+ 1;
6257 copy_bufptr
= (char *) alloca (copy_bufsiz
);
6258 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6261 copy_bufsiz
, &keysym
,
6267 if (status_return
== XLookupNone
)
6269 else if (status_return
== XLookupChars
)
6274 else if (status_return
!= XLookupKeySym
6275 && status_return
!= XLookupBoth
)
6279 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6280 copy_bufsiz
, &keysym
,
6283 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6284 copy_bufsiz
, &keysym
,
6288 orig_keysym
= keysym
;
6294 /* First deal with keysyms which have defined
6295 translations to characters. */
6296 if (keysym
>= 32 && keysym
< 128)
6297 /* Avoid explicitly decoding each ASCII character. */
6299 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
6300 bufp
->code
= keysym
;
6301 XSETFRAME (bufp
->frame_or_window
, f
);
6304 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6306 bufp
->timestamp
= event
.xkey
.time
;
6311 /* Now non-ASCII. */
6312 else if (HASH_TABLE_P (Vx_keysym_table
)
6313 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6317 bufp
->kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6318 ? ASCII_KEYSTROKE_EVENT
6319 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6320 bufp
->code
= XFASTINT (c
);
6321 XSETFRAME (bufp
->frame_or_window
, f
);
6324 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6326 bufp
->timestamp
= event
.xkey
.time
;
6331 /* Random non-modifier sorts of keysyms. */
6332 else if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6333 || keysym
== XK_Delete
6334 #ifdef XK_ISO_Left_Tab
6335 || (keysym
>= XK_ISO_Left_Tab
6336 && keysym
<= XK_ISO_Enter
)
6338 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6339 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6341 /* This recognizes the "extended function
6342 keys". It seems there's no cleaner way.
6343 Test IsModifierKey to avoid handling
6344 mode_switch incorrectly. */
6345 || ((unsigned) (keysym
) >= XK_Select
6346 && (unsigned)(keysym
) < XK_KP_Space
)
6348 #ifdef XK_dead_circumflex
6349 || orig_keysym
== XK_dead_circumflex
6351 #ifdef XK_dead_grave
6352 || orig_keysym
== XK_dead_grave
6354 #ifdef XK_dead_tilde
6355 || orig_keysym
== XK_dead_tilde
6357 #ifdef XK_dead_diaeresis
6358 || orig_keysym
== XK_dead_diaeresis
6360 #ifdef XK_dead_macron
6361 || orig_keysym
== XK_dead_macron
6363 #ifdef XK_dead_degree
6364 || orig_keysym
== XK_dead_degree
6366 #ifdef XK_dead_acute
6367 || orig_keysym
== XK_dead_acute
6369 #ifdef XK_dead_cedilla
6370 || orig_keysym
== XK_dead_cedilla
6372 #ifdef XK_dead_breve
6373 || orig_keysym
== XK_dead_breve
6375 #ifdef XK_dead_ogonek
6376 || orig_keysym
== XK_dead_ogonek
6378 #ifdef XK_dead_caron
6379 || orig_keysym
== XK_dead_caron
6381 #ifdef XK_dead_doubleacute
6382 || orig_keysym
== XK_dead_doubleacute
6384 #ifdef XK_dead_abovedot
6385 || orig_keysym
== XK_dead_abovedot
6387 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6388 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6389 /* Any "vendor-specific" key is ok. */
6390 || (orig_keysym
& (1 << 28))
6391 || (keysym
!= NoSymbol
&& nbytes
== 0))
6392 && ! (IsModifierKey (orig_keysym
)
6394 #ifdef XK_Mode_switch
6395 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
6398 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
6400 #endif /* not HAVE_X11R5 */
6401 /* The symbols from XK_ISO_Lock
6402 to XK_ISO_Last_Group_Lock
6403 don't have real modifiers but
6404 should be treated similarly to
6405 Mode_switch by Emacs. */
6406 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6407 || ((unsigned)(orig_keysym
)
6409 && (unsigned)(orig_keysym
)
6410 <= XK_ISO_Last_Group_Lock
)
6414 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
6416 temp_buffer
[temp_index
++] = keysym
;
6417 /* make_lispy_event will convert this to a symbolic
6419 bufp
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
6420 bufp
->code
= keysym
;
6421 XSETFRAME (bufp
->frame_or_window
, f
);
6424 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6426 bufp
->timestamp
= event
.xkey
.time
;
6431 else if (numchars
> nbytes
)
6432 { /* Raw bytes, not keysym. */
6437 /* The input should be decoded with `coding_system'
6438 which depends on which X*LookupString function
6439 we used just above and the locale. */
6440 setup_coding_system (coding_system
, &coding
);
6441 coding
.src_multibyte
= 0;
6442 coding
.dst_multibyte
= 1;
6443 /* The input is converted to events, thus we can't
6444 handle composition. Anyway, there's no XIM that
6445 gives us composition information. */
6446 coding
.composing
= COMPOSITION_DISABLED
;
6448 for (i
= 0; i
< nbytes
; i
++)
6450 if (temp_index
== (sizeof temp_buffer
6453 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
6457 /* Decode the input data. */
6461 require
= decoding_buffer_size (&coding
, nbytes
);
6462 p
= (unsigned char *) alloca (require
);
6463 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6464 /* We explicitely disable composition
6465 handling because key data should
6466 not contain any composition
6468 coding
.composing
= COMPOSITION_DISABLED
;
6469 decode_coding (&coding
, copy_bufptr
, p
,
6471 nbytes
= coding
.produced
;
6472 nchars
= coding
.produced_char
;
6476 /* Convert the input data to a sequence of
6477 character events. */
6478 for (i
= 0; i
< nbytes
; i
+= len
)
6480 if (nchars
== nbytes
)
6481 c
= copy_bufptr
[i
], len
= 1;
6483 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6486 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
6487 ? ASCII_KEYSTROKE_EVENT
6488 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6490 XSETFRAME (bufp
->frame_or_window
, f
);
6493 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6495 bufp
->timestamp
= event
.xkey
.time
;
6502 if (keysym
== NoSymbol
)
6512 /* Don't dispatch this event since XtDispatchEvent calls
6513 XFilterEvent, and two calls in a row may freeze the
6522 /* Don't dispatch this event since XtDispatchEvent calls
6523 XFilterEvent, and two calls in a row may freeze the
6534 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6537 bufp
+= n
, count
+= n
, numchars
-= n
;
6540 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6543 if (event
.xcrossing
.focus
)
6545 /* Avoid nasty pop/raise loops. */
6546 if (f
&& (!(f
->auto_raise
)
6548 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6550 x_new_focus_frame (dpyinfo
, f
);
6551 enter_timestamp
= event
.xcrossing
.time
;
6554 else if (f
== dpyinfo
->x_focus_frame
)
6555 x_new_focus_frame (dpyinfo
, 0);
6558 /* EnterNotify counts as mouse movement,
6559 so update things that depend on mouse position. */
6560 if (f
&& !f
->output_data
.x
->hourglass_p
)
6561 note_mouse_movement (f
, &event
.xmotion
);
6569 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6572 bufp
+= n
, count
+= n
, numchars
-= n
;
6582 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6585 bufp
+= n
, count
+= n
, numchars
-= n
;
6589 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6592 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6594 /* If we move outside the frame, then we're
6595 certainly no longer on any text in the frame. */
6596 clear_mouse_face (dpyinfo
);
6597 dpyinfo
->mouse_face_mouse_frame
= 0;
6600 /* Generate a nil HELP_EVENT to cancel a help-echo.
6601 Do it only if there's something to cancel.
6602 Otherwise, the startup message is cleared when
6603 the mouse leaves the frame. */
6604 if (any_help_event_p
)
6609 XSETFRAME (frame
, f
);
6610 help_echo_string
= Qnil
;
6611 n
= gen_help_event (bufp
, numchars
,
6612 Qnil
, frame
, Qnil
, Qnil
, 0);
6613 bufp
+= n
, count
+= n
, numchars
-= n
;
6623 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6626 bufp
+= n
, count
+= n
, numchars
-= n
;
6634 previous_help_echo_string
= help_echo_string
;
6635 help_echo_string
= help_echo_object
= help_echo_window
= Qnil
;
6638 if (dpyinfo
->grabbed
&& last_mouse_frame
6639 && FRAME_LIVE_P (last_mouse_frame
))
6640 f
= last_mouse_frame
;
6642 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6644 if (dpyinfo
->mouse_face_hidden
)
6646 dpyinfo
->mouse_face_hidden
= 0;
6647 clear_mouse_face (dpyinfo
);
6653 /* Generate SELECT_WINDOW_EVENTs when needed. */
6654 if (mouse_autoselect_window
)
6658 window
= window_from_coordinates (f
,
6659 event
.xmotion
.x
, event
.xmotion
.y
,
6662 /* Window will be selected only when it is not selected now and
6663 last mouse movement event was not in it. Minibuffer window
6664 will be selected iff it is active. */
6666 && !EQ (window
, last_window
)
6667 && !EQ (window
, selected_window
)
6670 bufp
->kind
= SELECT_WINDOW_EVENT
;
6671 bufp
->frame_or_window
= window
;
6673 ++bufp
, ++count
, --numchars
;
6678 note_mouse_movement (f
, &event
.xmotion
);
6682 #ifndef USE_TOOLKIT_SCROLL_BARS
6683 struct scroll_bar
*bar
6684 = x_window_to_scroll_bar (event
.xmotion
.window
);
6687 x_scroll_bar_note_movement (bar
, &event
);
6688 #endif /* USE_TOOLKIT_SCROLL_BARS */
6690 /* If we move outside the frame, then we're
6691 certainly no longer on any text in the frame. */
6692 clear_mouse_face (dpyinfo
);
6695 /* If the contents of the global variable help_echo_string
6696 has changed, generate a HELP_EVENT. */
6697 if (!NILP (help_echo_string
)
6698 || !NILP (previous_help_echo_string
))
6704 XSETFRAME (frame
, f
);
6708 any_help_event_p
= 1;
6709 n
= gen_help_event (bufp
, numchars
, help_echo_string
, frame
,
6710 help_echo_window
, help_echo_object
,
6712 bufp
+= n
, count
+= n
, numchars
-= n
;
6718 case ConfigureNotify
:
6719 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6722 #ifndef USE_X_TOOLKIT
6724 xg_resize_widgets (f
, event
.xconfigure
.width
,
6725 event
.xconfigure
.height
);
6726 #else /* not USE_GTK */
6727 /* If there is a pending resize for fullscreen, don't
6728 do this one, the right one will come later.
6729 The toolkit version doesn't seem to need this, but we
6730 need to reset it below. */
6732 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
6733 && FRAME_NEW_WIDTH (f
) != 0);
6734 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
6735 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
6739 /* In the toolkit version, change_frame_size
6740 is called by the code that handles resizing
6741 of the EmacsFrame widget. */
6743 /* Even if the number of character rows and columns has
6744 not changed, the font size may have changed, so we need
6745 to check the pixel dimensions as well. */
6746 if (columns
!= f
->width
6747 || rows
!= f
->height
6748 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
6749 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
6751 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6752 SET_FRAME_GARBAGED (f
);
6753 cancel_mouse_face (f
);
6755 #endif /* not USE_GTK */
6758 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
6759 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
6762 /* GTK creates windows but doesn't map them.
6763 Only get real positions and check fullscreen when mapped. */
6764 if (FRAME_GTK_OUTER_WIDGET (f
)
6765 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
6768 /* What we have now is the position of Emacs's own window.
6769 Convert that to the position of the window manager window. */
6770 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
6771 &f
->output_data
.x
->top_pos
);
6773 x_check_fullscreen_move (f
);
6774 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
6775 f
->output_data
.x
->want_fullscreen
&=
6776 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
6781 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6782 xic_set_statusarea (f
);
6785 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
6787 /* Since the WM decorations come below top_pos now,
6788 we must put them below top_pos in the future. */
6789 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
6790 x_wm_set_size_hint (f
, (long) 0, 0);
6798 /* If we decide we want to generate an event to be seen
6799 by the rest of Emacs, we put it here. */
6800 struct input_event emacs_event
;
6803 emacs_event
.kind
= NO_EVENT
;
6804 bzero (&compose_status
, sizeof (compose_status
));
6806 if (dpyinfo
->grabbed
6808 && FRAME_LIVE_P (last_mouse_frame
))
6809 f
= last_mouse_frame
;
6811 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6815 /* Is this in the tool-bar? */
6816 if (WINDOWP (f
->tool_bar_window
)
6817 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
6820 int x
= event
.xbutton
.x
;
6821 int y
= event
.xbutton
.y
;
6823 window
= window_from_coordinates (f
, x
, y
, 0, 1);
6824 if (EQ (window
, f
->tool_bar_window
))
6826 if (event
.xbutton
.type
== ButtonPress
)
6827 handle_tool_bar_click (f
, x
, y
, 1, 0);
6829 handle_tool_bar_click (f
, x
, y
, 0,
6830 x_x_to_emacs_modifiers (dpyinfo
,
6831 event
.xbutton
.state
));
6837 if (!dpyinfo
->x_focus_frame
6838 || f
== dpyinfo
->x_focus_frame
)
6840 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6841 if (! popup_activated ())
6843 construct_mouse_click (&emacs_event
, &event
, f
);
6848 struct scroll_bar
*bar
6849 = x_window_to_scroll_bar (event
.xbutton
.window
);
6851 #ifdef USE_TOOLKIT_SCROLL_BARS
6852 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6854 if (bar
&& event
.xbutton
.state
& ControlMask
)
6856 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
6857 *finish
= X_EVENT_DROP
;
6859 #else /* not USE_TOOLKIT_SCROLL_BARS */
6861 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
6862 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6865 if (event
.type
== ButtonPress
)
6867 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6868 last_mouse_frame
= f
;
6869 /* Ignore any mouse motion that happened
6870 before this event; any subsequent mouse-movement
6871 Emacs events should reflect only motion after
6877 last_tool_bar_item
= -1;
6880 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6882 if (numchars
>= 1 && emacs_event
.kind
!= NO_EVENT
)
6884 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
6890 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6891 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6892 /* For a down-event in the menu bar,
6893 don't pass it to Xt right now.
6894 Instead, save it away
6895 and we will pass it to Xt from kbd_buffer_get_event.
6896 That way, we can run some Lisp code first. */
6899 ! popup_activated ()
6902 f
&& event
.type
== ButtonPress
6903 /* Verify the event is really within the menu bar
6904 and not just sent to it due to grabbing. */
6905 && event
.xbutton
.x
>= 0
6906 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
6907 && event
.xbutton
.y
>= 0
6908 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6909 && event
.xbutton
.same_screen
)
6911 SET_SAVED_BUTTON_EVENT
;
6912 XSETFRAME (last_mouse_press_frame
, f
);
6914 *finish
= X_EVENT_DROP
;
6917 else if (event
.type
== ButtonPress
)
6919 last_mouse_press_frame
= Qnil
;
6923 #ifdef USE_MOTIF /* This should do not harm for Lucid,
6924 but I am trying to be cautious. */
6925 else if (event
.type
== ButtonRelease
)
6927 if (!NILP (last_mouse_press_frame
))
6929 f
= XFRAME (last_mouse_press_frame
);
6930 if (f
->output_data
.x
)
6931 SET_SAVED_BUTTON_EVENT
;
6936 #endif /* USE_MOTIF */
6939 #endif /* USE_X_TOOLKIT || USE_GTK */
6943 case CirculateNotify
:
6946 case CirculateRequest
:
6949 case VisibilityNotify
:
6953 /* Someone has changed the keyboard mapping - update the
6955 switch (event
.xmapping
.request
)
6957 case MappingModifier
:
6958 x_find_modifier_meanings (dpyinfo
);
6959 /* This is meant to fall through. */
6960 case MappingKeyboard
:
6961 XRefreshKeyboardMapping (&event
.xmapping
);
6967 #ifdef USE_X_TOOLKIT
6969 if (*finish
!= X_EVENT_DROP
)
6970 XtDispatchEvent (&event
);
6972 #endif /* USE_X_TOOLKIT */
6979 *finish
= X_EVENT_GOTO_OUT
;
6983 *numcharsp
= numchars
;
6990 /* Handles the XEvent EVENT on display DISPLAY.
6991 This is used for event loops outside the normal event handling,
6992 i.e. looping while a popup menu or a dialog is posted.
6994 Returns the value handle_one_xevent sets in the finish argument. */
6996 x_dispatch_event (event
, display
)
7000 struct x_display_info
*dpyinfo
;
7001 struct input_event bufp
[10];
7002 struct input_event
*bufpp
= bufp
;
7004 int finish
= X_EVENT_NORMAL
;
7006 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7007 if (dpyinfo
->display
== display
)
7013 events
= handle_one_xevent (dpyinfo
,
7018 for (i
= 0; i
< events
; ++i
)
7019 kbd_buffer_store_event (&bufp
[i
]);
7026 /* Read events coming from the X server.
7027 This routine is called by the SIGIO handler.
7028 We return as soon as there are no more events to be read.
7030 Events representing keys are stored in buffer BUFP,
7031 which can hold up to NUMCHARS characters.
7032 We return the number of characters stored into the buffer,
7033 thus pretending to be `read'.
7035 EXPECTED is nonzero if the caller knows input is available. */
7038 XTread_socket (sd
, bufp
, numchars
, expected
)
7040 /* register */ struct input_event
*bufp
;
7041 /* register */ int numchars
;
7046 int event_found
= 0;
7047 struct x_display_info
*dpyinfo
;
7049 if (interrupt_input_blocked
)
7051 interrupt_input_pending
= 1;
7055 interrupt_input_pending
= 0;
7058 /* So people can tell when we have read the available input. */
7059 input_signal_count
++;
7062 abort (); /* Don't think this happens. */
7066 /* Find the display we are supposed to read input for.
7067 It's the one communicating on descriptor SD. */
7068 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7070 #if 0 /* This ought to be unnecessary; let's verify it. */
7072 /* If available, Xlib uses FIOSNBIO to make the socket
7073 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
7074 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
7075 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
7076 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
7077 #endif /* ! defined (FIOSNBIO) */
7080 #if 0 /* This code can't be made to work, with multiple displays,
7081 and appears not to be used on any system any more.
7082 Also keyboard.c doesn't turn O_NDELAY on and off
7083 for X connections. */
7086 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7088 extern int read_alarm_should_throw
;
7089 read_alarm_should_throw
= 1;
7090 XPeekEvent (dpyinfo
->display
, &event
);
7091 read_alarm_should_throw
= 0;
7093 #endif /* HAVE_SELECT */
7097 /* For debugging, this gives a way to fake an I/O error. */
7098 if (dpyinfo
== XTread_socket_fake_io_error
)
7100 XTread_socket_fake_io_error
= 0;
7101 x_io_error_quitter (dpyinfo
->display
);
7106 count
+= x_session_check_input (bufp
, &numchars
);
7111 /* For GTK we must use the GTK event loop. But XEvents gets passed
7112 to our filter function above, and then to the big event switch.
7113 We use a bunch of globals to communicate with our filter function,
7114 that is kind of ugly, but it works. */
7115 current_dpyinfo
= dpyinfo
;
7117 while (gtk_events_pending ())
7120 current_count
= count
;
7121 current_numcharsp
= &numchars
;
7122 current_bufp
= &bufp
;
7124 gtk_main_iteration ();
7126 count
= current_count
;
7128 current_numcharsp
= 0;
7130 if (current_finish
== X_EVENT_GOTO_OUT
)
7134 #else /* not USE_GTK */
7135 while (XPending (dpyinfo
->display
))
7139 XNextEvent (dpyinfo
->display
, &event
);
7142 /* Filter events for the current X input method. */
7143 if (x_filter_event (dpyinfo
, &event
))
7148 count
+= handle_one_xevent (dpyinfo
,
7154 if (finish
== X_EVENT_GOTO_OUT
)
7157 #endif /* USE_GTK */
7162 /* On some systems, an X bug causes Emacs to get no more events
7163 when the window is destroyed. Detect that. (1994.) */
7166 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7167 One XNOOP in 100 loops will make Emacs terminate.
7168 B. Bretthauer, 1994 */
7170 if (x_noop_count
>= 100)
7174 if (next_noop_dpyinfo
== 0)
7175 next_noop_dpyinfo
= x_display_list
;
7177 XNoOp (next_noop_dpyinfo
->display
);
7179 /* Each time we get here, cycle through the displays now open. */
7180 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7184 /* If the focus was just given to an auto-raising frame,
7186 /* ??? This ought to be able to handle more than one such frame. */
7187 if (pending_autoraise_frame
)
7189 x_raise_frame (pending_autoraise_frame
);
7190 pending_autoraise_frame
= 0;
7201 /***********************************************************************
7203 ***********************************************************************/
7205 /* Set clipping for output in glyph row ROW. W is the window in which
7206 we operate. GC is the graphics context to set clipping in.
7207 WHOLE_LINE_P non-zero means include the areas used for truncation
7208 mark display and alike in the clipping rectangle.
7210 ROW may be a text row or, e.g., a mode line. Text rows must be
7211 clipped to the interior of the window dedicated to text display,
7212 mode lines must be clipped to the whole window. */
7215 x_clip_to_row (w
, row
, gc
, whole_line_p
)
7217 struct glyph_row
*row
;
7221 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7222 XRectangle clip_rect
;
7223 int window_x
, window_y
, window_width
, window_height
;
7225 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7227 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
7228 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
7229 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7230 clip_rect
.width
= window_width
;
7231 clip_rect
.height
= row
->visible_height
;
7233 /* If clipping to the whole line, including trunc marks, extend
7234 the rectangle to the left and increase its width. */
7237 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
7238 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
7241 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7245 /* Draw a hollow box cursor on window W in glyph row ROW. */
7248 x_draw_hollow_cursor (w
, row
)
7250 struct glyph_row
*row
;
7252 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7253 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7254 Display
*dpy
= FRAME_X_DISPLAY (f
);
7257 struct glyph
*cursor_glyph
;
7260 /* Compute frame-relative coordinates from window-relative
7262 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7263 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
7264 + row
->ascent
- w
->phys_cursor_ascent
);
7265 h
= row
->height
- 1;
7267 /* Get the glyph the cursor is on. If we can't tell because
7268 the current matrix is invalid or such, give up. */
7269 cursor_glyph
= get_phys_cursor_glyph (w
);
7270 if (cursor_glyph
== NULL
)
7273 /* Compute the width of the rectangle to draw. If on a stretch
7274 glyph, and `x-stretch-block-cursor' is nil, don't draw a
7275 rectangle as wide as the glyph, but use a canonical character
7277 wd
= cursor_glyph
->pixel_width
- 1;
7278 if (cursor_glyph
->type
== STRETCH_GLYPH
7279 && !x_stretch_cursor_p
)
7280 wd
= min (CANON_X_UNIT (f
), wd
);
7281 w
->phys_cursor_width
= wd
;
7283 /* The foreground of cursor_gc is typically the same as the normal
7284 background color, which can cause the cursor box to be invisible. */
7285 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7286 if (dpyinfo
->scratch_cursor_gc
)
7287 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7289 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7290 GCForeground
, &xgcv
);
7291 gc
= dpyinfo
->scratch_cursor_gc
;
7293 /* Set clipping, draw the rectangle, and reset clipping again. */
7294 x_clip_to_row (w
, row
, gc
, 0);
7295 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
7296 XSetClipMask (dpy
, gc
, None
);
7300 /* Draw a bar cursor on window W in glyph row ROW.
7302 Implementation note: One would like to draw a bar cursor with an
7303 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7304 Unfortunately, I didn't find a font yet that has this property set.
7308 x_draw_bar_cursor (w
, row
, width
, kind
)
7310 struct glyph_row
*row
;
7312 enum text_cursor_kinds kind
;
7314 struct frame
*f
= XFRAME (w
->frame
);
7315 struct glyph
*cursor_glyph
;
7317 /* If cursor is out of bounds, don't draw garbage. This can happen
7318 in mini-buffer windows when switching between echo area glyphs
7320 cursor_glyph
= get_phys_cursor_glyph (w
);
7321 if (cursor_glyph
== NULL
)
7324 /* If on an image, draw like a normal cursor. That's usually better
7325 visible than drawing a bar, esp. if the image is large so that
7326 the bar might not be in the window. */
7327 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7329 struct glyph_row
*row
;
7330 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7331 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7335 Display
*dpy
= FRAME_X_DISPLAY (f
);
7336 Window window
= FRAME_X_WINDOW (f
);
7337 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7338 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7339 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7342 /* If the glyph's background equals the color we normally draw
7343 the bar cursor in, the bar cursor in its normal color is
7344 invisible. Use the glyph's foreground color instead in this
7345 case, on the assumption that the glyph's colors are chosen so
7346 that the glyph is legible. */
7347 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7348 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7350 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7351 xgcv
.graphics_exposures
= 0;
7354 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7357 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7358 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7362 width
= FRAME_CURSOR_WIDTH (f
);
7363 width
= min (cursor_glyph
->pixel_width
, width
);
7365 w
->phys_cursor_width
= width
;
7366 x_clip_to_row (w
, row
, gc
, 0);
7368 if (kind
== BAR_CURSOR
)
7369 XFillRectangle (dpy
, window
, gc
,
7370 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7371 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7372 width
, row
->height
);
7374 XFillRectangle (dpy
, window
, gc
,
7375 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7376 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7377 row
->height
- width
),
7378 cursor_glyph
->pixel_width
,
7381 XSetClipMask (dpy
, gc
, None
);
7386 /* RIF: Define cursor CURSOR on frame F. */
7389 x_define_frame_cursor (f
, cursor
)
7393 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7397 /* RIF: Clear area on frame F. */
7400 x_clear_frame_area (f
, x
, y
, width
, height
)
7402 int x
, y
, width
, height
;
7404 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7405 x
, y
, width
, height
, False
);
7409 /* RIF: Draw cursor on window W. */
7412 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7414 struct glyph_row
*glyph_row
;
7416 int cursor_type
, cursor_width
;
7419 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7423 w
->phys_cursor_type
= cursor_type
;
7424 w
->phys_cursor_on_p
= 1;
7426 switch (cursor_type
)
7428 case HOLLOW_BOX_CURSOR
:
7429 x_draw_hollow_cursor (w
, glyph_row
);
7432 case FILLED_BOX_CURSOR
:
7433 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7437 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7441 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7445 w
->phys_cursor_width
= 0;
7453 if (w
== XWINDOW (f
->selected_window
))
7454 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7455 xic_set_preeditarea (w
, x
, y
);
7460 if (updating_frame
!= f
)
7461 XFlush (FRAME_X_DISPLAY (f
));
7468 /* Make the x-window of frame F use the gnu icon bitmap. */
7471 x_bitmap_icon (f
, file
)
7477 if (FRAME_X_WINDOW (f
) == 0)
7480 /* Free up our existing icon bitmap if any. */
7481 if (f
->output_data
.x
->icon_bitmap
> 0)
7482 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7483 f
->output_data
.x
->icon_bitmap
= 0;
7486 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7489 /* Create the GNU bitmap if necessary. */
7490 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7491 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
7492 = x_create_bitmap_from_data (f
, gnu_bits
,
7493 gnu_width
, gnu_height
);
7495 /* The first time we create the GNU bitmap,
7496 this increments the ref-count one extra time.
7497 As a result, the GNU bitmap is never freed.
7498 That way, we don't have to worry about allocating it again. */
7499 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7501 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7504 x_wm_set_icon_pixmap (f
, bitmap_id
);
7505 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7511 /* Make the x-window of frame F use a rectangle with text.
7512 Use ICON_NAME as the text. */
7515 x_text_icon (f
, icon_name
)
7519 if (FRAME_X_WINDOW (f
) == 0)
7525 text
.value
= (unsigned char *) icon_name
;
7526 text
.encoding
= XA_STRING
;
7528 text
.nitems
= strlen (icon_name
);
7529 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7531 #else /* not HAVE_X11R4 */
7532 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), icon_name
);
7533 #endif /* not HAVE_X11R4 */
7535 if (f
->output_data
.x
->icon_bitmap
> 0)
7536 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7537 f
->output_data
.x
->icon_bitmap
= 0;
7538 x_wm_set_icon_pixmap (f
, 0);
7543 #define X_ERROR_MESSAGE_SIZE 200
7545 /* If non-nil, this should be a string.
7546 It means catch X errors and store the error message in this string. */
7548 static Lisp_Object x_error_message_string
;
7550 /* An X error handler which stores the error message in
7551 x_error_message_string. This is called from x_error_handler if
7552 x_catch_errors is in effect. */
7555 x_error_catcher (display
, error
)
7559 XGetErrorText (display
, error
->error_code
,
7560 SDATA (x_error_message_string
),
7561 X_ERROR_MESSAGE_SIZE
);
7564 /* Begin trapping X errors for display DPY. Actually we trap X errors
7565 for all displays, but DPY should be the display you are actually
7568 After calling this function, X protocol errors no longer cause
7569 Emacs to exit; instead, they are recorded in the string
7570 stored in x_error_message_string.
7572 Calling x_check_errors signals an Emacs error if an X error has
7573 occurred since the last call to x_catch_errors or x_check_errors.
7575 Calling x_uncatch_errors resumes the normal error handling. */
7577 void x_check_errors ();
7578 static Lisp_Object
x_catch_errors_unwind ();
7581 x_catch_errors (dpy
)
7584 int count
= SPECPDL_INDEX ();
7586 /* Make sure any errors from previous requests have been dealt with. */
7589 record_unwind_protect (x_catch_errors_unwind
,
7590 Fcons (make_save_value (dpy
, 0),
7591 x_error_message_string
));
7593 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
7594 SSET (x_error_message_string
, 0, 0);
7599 /* Unbind the binding that we made to check for X errors. */
7602 x_catch_errors_unwind (old_val
)
7603 Lisp_Object old_val
;
7607 first
= XCAR (old_val
);
7609 XSync (XSAVE_VALUE (first
)->pointer
, False
);
7611 x_error_message_string
= XCDR (old_val
);
7615 /* If any X protocol errors have arrived since the last call to
7616 x_catch_errors or x_check_errors, signal an Emacs error using
7617 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7620 x_check_errors (dpy
, format
)
7624 /* Make sure to catch any errors incurred so far. */
7627 if (SREF (x_error_message_string
, 0))
7628 error (format
, SDATA (x_error_message_string
));
7631 /* Nonzero if we had any X protocol errors
7632 since we did x_catch_errors on DPY. */
7635 x_had_errors_p (dpy
)
7638 /* Make sure to catch any errors incurred so far. */
7641 return SREF (x_error_message_string
, 0) != 0;
7644 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7647 x_clear_errors (dpy
)
7650 SSET (x_error_message_string
, 0, 0);
7653 /* Stop catching X protocol errors and let them make Emacs die.
7654 DPY should be the display that was passed to x_catch_errors.
7655 COUNT should be the value that was returned by
7656 the corresponding call to x_catch_errors. */
7659 x_uncatch_errors (dpy
, count
)
7663 unbind_to (count
, Qnil
);
7667 static unsigned int x_wire_count
;
7670 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7675 /* Handle SIGPIPE, which can happen when the connection to a server
7676 simply goes away. SIGPIPE is handled by x_connection_signal.
7677 Don't need to do anything, because the write which caused the
7678 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7679 which will do the appropriate cleanup for us. */
7682 x_connection_signal (signalnum
) /* If we don't have an argument, */
7683 int signalnum
; /* some compilers complain in signal calls. */
7686 /* USG systems forget handlers when they are used;
7687 must reestablish each time */
7688 signal (signalnum
, x_connection_signal
);
7693 /************************************************************************
7695 ************************************************************************/
7697 /* Error message passed to x_connection_closed. */
7699 static char *error_msg
;
7701 /* Function installed as fatal_error_signal_hook in
7702 x_connection_closed. Print the X error message, and exit normally,
7703 instead of dumping core when XtCloseDisplay fails. */
7706 x_fatal_error_signal ()
7708 fprintf (stderr
, "%s\n", error_msg
);
7712 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7713 the text of an error message that lead to the connection loss. */
7716 x_connection_closed (dpy
, error_message
)
7718 char *error_message
;
7720 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7721 Lisp_Object frame
, tail
;
7724 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7725 strcpy (error_msg
, error_message
);
7726 handling_signal
= 0;
7728 /* Prevent being called recursively because of an error condition
7729 below. Otherwise, we might end up with printing ``can't find per
7730 display information'' in the recursive call instead of printing
7731 the original message here. */
7732 count
= x_catch_errors (dpy
);
7734 /* We have to close the display to inform Xt that it doesn't
7735 exist anymore. If we don't, Xt will continue to wait for
7736 events from the display. As a consequence, a sequence of
7738 M-x make-frame-on-display RET :1 RET
7739 ...kill the new frame, so that we get an IO error...
7740 M-x make-frame-on-display RET :1 RET
7742 will indefinitely wait in Xt for events for display `:1', opened
7743 in the first class to make-frame-on-display.
7745 Closing the display is reported to lead to a bus error on
7746 OpenWindows in certain situations. I suspect that is a bug
7747 in OpenWindows. I don't know how to cicumvent it here. */
7749 #ifdef USE_X_TOOLKIT
7750 /* If DPYINFO is null, this means we didn't open the display
7751 in the first place, so don't try to close it. */
7754 extern void (*fatal_error_signal_hook
) P_ ((void));
7755 fatal_error_signal_hook
= x_fatal_error_signal
;
7756 XtCloseDisplay (dpy
);
7757 fatal_error_signal_hook
= NULL
;
7761 /* Indicate that this display is dead. */
7763 dpyinfo
->display
= 0;
7765 /* First delete frames whose mini-buffers are on frames
7766 that are on the dead display. */
7767 FOR_EACH_FRAME (tail
, frame
)
7769 Lisp_Object minibuf_frame
;
7771 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7772 if (FRAME_X_P (XFRAME (frame
))
7773 && FRAME_X_P (XFRAME (minibuf_frame
))
7774 && ! EQ (frame
, minibuf_frame
)
7775 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7776 Fdelete_frame (frame
, Qt
);
7779 /* Now delete all remaining frames on the dead display.
7780 We are now sure none of these is used as the mini-buffer
7781 for another frame that we need to delete. */
7782 FOR_EACH_FRAME (tail
, frame
)
7783 if (FRAME_X_P (XFRAME (frame
))
7784 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7786 /* Set this to t so that Fdelete_frame won't get confused
7787 trying to find a replacement. */
7788 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7789 Fdelete_frame (frame
, Qt
);
7793 x_delete_display (dpyinfo
);
7795 x_uncatch_errors (dpy
, count
);
7797 if (x_display_list
== 0)
7799 fprintf (stderr
, "%s\n", error_msg
);
7800 shut_down_emacs (0, 0, Qnil
);
7804 /* Ordinary stack unwind doesn't deal with these. */
7806 sigunblock (sigmask (SIGIO
));
7808 sigunblock (sigmask (SIGALRM
));
7809 TOTALLY_UNBLOCK_INPUT
;
7811 clear_waiting_for_input ();
7812 error ("%s", error_msg
);
7816 /* This is the usual handler for X protocol errors.
7817 It kills all frames on the display that we got the error for.
7818 If that was the only one, it prints an error message and kills Emacs. */
7821 x_error_quitter (display
, error
)
7825 char buf
[256], buf1
[356];
7827 /* Note that there is no real way portable across R3/R4 to get the
7828 original error handler. */
7830 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7831 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7832 buf
, error
->request_code
);
7833 x_connection_closed (display
, buf1
);
7837 /* This is the first-level handler for X protocol errors.
7838 It calls x_error_quitter or x_error_catcher. */
7841 x_error_handler (display
, error
)
7845 if (! NILP (x_error_message_string
))
7846 x_error_catcher (display
, error
);
7848 x_error_quitter (display
, error
);
7852 /* This is the handler for X IO errors, always.
7853 It kills all frames on the display that we lost touch with.
7854 If that was the only one, it prints an error message and kills Emacs. */
7857 x_io_error_quitter (display
)
7862 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7863 x_connection_closed (display
, buf
);
7867 /* Changing the font of the frame. */
7869 /* Give frame F the font named FONTNAME as its default font, and
7870 return the full name of that font. FONTNAME may be a wildcard
7871 pattern; in that case, we choose some font that fits the pattern.
7872 The return value shows which font we chose. */
7875 x_new_font (f
, fontname
)
7877 register char *fontname
;
7879 struct font_info
*fontp
7880 = FS_LOAD_FONT (f
, 0, fontname
, -1);
7885 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
7886 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
7887 f
->output_data
.x
->fontset
= -1;
7889 compute_fringe_widths (f
, 1);
7891 /* Compute the scroll bar width in character columns. */
7892 if (f
->scroll_bar_pixel_width
> 0)
7894 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
7895 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
7899 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
7900 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
7903 /* Now make the frame display the given font. */
7904 if (FRAME_X_WINDOW (f
) != 0)
7906 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
7907 f
->output_data
.x
->font
->fid
);
7908 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
7909 f
->output_data
.x
->font
->fid
);
7910 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
7911 f
->output_data
.x
->font
->fid
);
7913 frame_update_line_height (f
);
7915 /* Don't change the size of a tip frame; there's no point in
7916 doing it because it's done in Fx_show_tip, and it leads to
7917 problems because the tip frame has no widget. */
7918 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7919 x_set_window_size (f
, 0, f
->width
, f
->height
);
7922 /* If we are setting a new frame's font for the first time,
7923 there are no faces yet, so this font's height is the line height. */
7924 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
7926 return build_string (fontp
->full_name
);
7929 /* Give frame F the fontset named FONTSETNAME as its default font, and
7930 return the full name of that fontset. FONTSETNAME may be a wildcard
7931 pattern; in that case, we choose some fontset that fits the pattern.
7932 The return value shows which fontset we chose. */
7935 x_new_fontset (f
, fontsetname
)
7939 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
7945 if (f
->output_data
.x
->fontset
== fontset
)
7946 /* This fontset is already set in frame F. There's nothing more
7948 return fontset_name (fontset
);
7950 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
7952 if (!STRINGP (result
))
7953 /* Can't load ASCII font. */
7956 /* Since x_new_font doesn't update any fontset information, do it now. */
7957 f
->output_data
.x
->fontset
= fontset
;
7961 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7962 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
7965 return build_string (fontsetname
);
7969 /***********************************************************************
7971 ***********************************************************************/
7977 /* XIM destroy callback function, which is called whenever the
7978 connection to input method XIM dies. CLIENT_DATA contains a
7979 pointer to the x_display_info structure corresponding to XIM. */
7982 xim_destroy_callback (xim
, client_data
, call_data
)
7984 XPointer client_data
;
7987 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7988 Lisp_Object frame
, tail
;
7992 /* No need to call XDestroyIC.. */
7993 FOR_EACH_FRAME (tail
, frame
)
7995 struct frame
*f
= XFRAME (frame
);
7996 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
7998 FRAME_XIC (f
) = NULL
;
7999 if (FRAME_XIC_FONTSET (f
))
8001 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
8002 FRAME_XIC_FONTSET (f
) = NULL
;
8007 /* No need to call XCloseIM. */
8008 dpyinfo
->xim
= NULL
;
8009 XFree (dpyinfo
->xim_styles
);
8013 #endif /* HAVE_X11R6 */
8016 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8017 extern char *XSetIMValues
P_ ((XIM
, ...));
8020 /* Open the connection to the XIM server on display DPYINFO.
8021 RESOURCE_NAME is the resource name Emacs uses. */
8024 xim_open_dpy (dpyinfo
, resource_name
)
8025 struct x_display_info
*dpyinfo
;
8026 char *resource_name
;
8031 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
8037 XIMCallback destroy
;
8040 /* Get supported styles and XIM values. */
8041 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8044 destroy
.callback
= xim_destroy_callback
;
8045 destroy
.client_data
= (XPointer
)dpyinfo
;
8046 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8050 #else /* not USE_XIM */
8051 dpyinfo
->xim
= NULL
;
8052 #endif /* not USE_XIM */
8056 #ifdef HAVE_X11R6_XIM
8060 struct x_display_info
*dpyinfo
;
8061 char *resource_name
;
8064 /* XIM instantiate callback function, which is called whenever an XIM
8065 server is available. DISPLAY is the display of the XIM.
8066 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8067 when the callback was registered. */
8070 xim_instantiate_callback (display
, client_data
, call_data
)
8072 XPointer client_data
;
8075 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8076 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8078 /* We don't support multiple XIM connections. */
8082 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8084 /* Create XIC for the existing frames on the same display, as long
8085 as they have no XIC. */
8086 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8088 Lisp_Object tail
, frame
;
8091 FOR_EACH_FRAME (tail
, frame
)
8093 struct frame
*f
= XFRAME (frame
);
8095 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8096 if (FRAME_XIC (f
) == NULL
)
8098 create_frame_xic (f
);
8099 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8100 xic_set_statusarea (f
);
8101 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8103 struct window
*w
= XWINDOW (f
->selected_window
);
8104 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8113 #endif /* HAVE_X11R6_XIM */
8116 /* Open a connection to the XIM server on display DPYINFO.
8117 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8118 connection only at the first time. On X11R6, open the connection
8119 in the XIM instantiate callback function. */
8122 xim_initialize (dpyinfo
, resource_name
)
8123 struct x_display_info
*dpyinfo
;
8124 char *resource_name
;
8127 #ifdef HAVE_X11R6_XIM
8128 struct xim_inst_t
*xim_inst
;
8131 dpyinfo
->xim
= NULL
;
8132 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8133 xim_inst
->dpyinfo
= dpyinfo
;
8134 len
= strlen (resource_name
);
8135 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8136 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8137 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8138 resource_name
, EMACS_CLASS
,
8139 xim_instantiate_callback
,
8140 /* Fixme: This is XPointer in
8141 XFree86 but (XPointer *) on
8143 (XPointer
) xim_inst
);
8144 #else /* not HAVE_X11R6_XIM */
8145 dpyinfo
->xim
= NULL
;
8146 xim_open_dpy (dpyinfo
, resource_name
);
8147 #endif /* not HAVE_X11R6_XIM */
8149 #else /* not USE_XIM */
8150 dpyinfo
->xim
= NULL
;
8151 #endif /* not USE_XIM */
8155 /* Close the connection to the XIM server on display DPYINFO. */
8158 xim_close_dpy (dpyinfo
)
8159 struct x_display_info
*dpyinfo
;
8162 #ifdef HAVE_X11R6_XIM
8163 if (dpyinfo
->display
)
8164 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8166 xim_instantiate_callback
, NULL
);
8167 #endif /* not HAVE_X11R6_XIM */
8168 if (dpyinfo
->display
)
8169 XCloseIM (dpyinfo
->xim
);
8170 dpyinfo
->xim
= NULL
;
8171 XFree (dpyinfo
->xim_styles
);
8172 #endif /* USE_XIM */
8175 #endif /* not HAVE_X11R6_XIM */
8179 /* Calculate the absolute position in frame F
8180 from its current recorded position values and gravity. */
8183 x_calc_absolute_position (f
)
8187 int win_x
= 0, win_y
= 0;
8188 int flags
= f
->output_data
.x
->size_hint_flags
;
8191 /* We have nothing to do if the current position
8192 is already for the top-left corner. */
8193 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8196 this_window
= FRAME_OUTER_WINDOW (f
);
8198 /* Find the position of the outside upper-left corner of
8199 the inner window, with respect to the outer window.
8200 But do this only if we will need the results. */
8201 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8206 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
8209 x_clear_errors (FRAME_X_DISPLAY (f
));
8210 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
8212 /* From-window, to-window. */
8214 f
->output_data
.x
->parent_desc
,
8216 /* From-position, to-position. */
8217 0, 0, &win_x
, &win_y
,
8221 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
8223 Window newroot
, newparent
= 0xdeadbeef;
8224 Window
*newchildren
;
8225 unsigned int nchildren
;
8227 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
8228 &newparent
, &newchildren
, &nchildren
))
8231 XFree ((char *) newchildren
);
8233 f
->output_data
.x
->parent_desc
= newparent
;
8239 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
8243 /* Treat negative positions as relative to the leftmost bottommost
8244 position that fits on the screen. */
8245 if (flags
& XNegative
)
8246 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
8247 - 2 * f
->output_data
.x
->border_width
- win_x
8249 + f
->output_data
.x
->left_pos
);
8252 int height
= PIXEL_HEIGHT (f
);
8254 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8255 /* Something is fishy here. When using Motif, starting Emacs with
8256 `-g -0-0', the frame appears too low by a few pixels.
8258 This seems to be so because initially, while Emacs is starting,
8259 the column widget's height and the frame's pixel height are
8260 different. The column widget's height is the right one. In
8261 later invocations, when Emacs is up, the frame's pixel height
8264 It's not obvious where the initial small difference comes from.
8265 2000-12-01, gerd. */
8267 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8270 if (flags
& YNegative
)
8271 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
8272 - 2 * f
->output_data
.x
->border_width
8275 + f
->output_data
.x
->top_pos
);
8278 /* The left_pos and top_pos
8279 are now relative to the top and left screen edges,
8280 so the flags should correspond. */
8281 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8284 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8285 to really change the position, and 0 when calling from
8286 x_make_frame_visible (in that case, XOFF and YOFF are the current
8287 position values). It is -1 when calling from x_set_frame_parameters,
8288 which means, do adjust for borders but don't change the gravity. */
8291 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8293 register int xoff
, yoff
;
8296 int modified_top
, modified_left
;
8298 if (change_gravity
> 0)
8300 f
->output_data
.x
->top_pos
= yoff
;
8301 f
->output_data
.x
->left_pos
= xoff
;
8302 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8304 f
->output_data
.x
->size_hint_flags
|= XNegative
;
8306 f
->output_data
.x
->size_hint_flags
|= YNegative
;
8307 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
8309 x_calc_absolute_position (f
);
8312 x_wm_set_size_hint (f
, (long) 0, 0);
8314 modified_left
= f
->output_data
.x
->left_pos
;
8315 modified_top
= f
->output_data
.x
->top_pos
;
8316 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
8317 this seems to be unnecessary and incorrect. rms, 4/17/97. */
8318 /* It is a mystery why we need to add the border_width here
8319 when the frame is already visible, but experiment says we do. */
8320 if (change_gravity
!= 0)
8322 modified_left
+= f
->output_data
.x
->border_width
;
8323 modified_top
+= f
->output_data
.x
->border_width
;
8327 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8328 modified_left
, modified_top
);
8332 /* Check if we need to resize the frame due to a fullscreen request.
8333 If so needed, resize the frame. */
8335 x_check_fullscreen (f
)
8338 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
8340 int width
, height
, ign
;
8342 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
8343 &f
->output_data
.x
->top_pos
);
8345 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8347 /* We do not need to move the window, it shall be taken care of
8348 when setting WM manager hints.
8349 If the frame is visible already, the position is checked by
8350 x_check_fullscreen_move. */
8351 if (f
->width
!= width
|| f
->height
!= height
)
8353 change_frame_size (f
, height
, width
, 0, 1, 0);
8354 SET_FRAME_GARBAGED (f
);
8355 cancel_mouse_face (f
);
8357 /* Wait for the change of frame size to occur */
8358 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
8363 /* If frame parameters are set after the frame is mapped, we need to move
8364 the window. This is done in xfns.c.
8365 Some window managers moves the window to the right position, some
8366 moves the outer window manager window to the specified position.
8367 Here we check that we are in the right spot. If not, make a second
8368 move, assuming we are dealing with the second kind of window manager. */
8370 x_check_fullscreen_move (f
)
8373 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
8375 int expect_top
= f
->output_data
.x
->top_pos
;
8376 int expect_left
= f
->output_data
.x
->left_pos
;
8378 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
8380 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
8383 if (expect_top
!= f
->output_data
.x
->top_pos
8384 || expect_left
!= f
->output_data
.x
->left_pos
)
8385 x_set_offset (f
, expect_left
, expect_top
, 1);
8387 /* Just do this once */
8388 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
8393 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
8394 wanted positions of the WM window (not emacs window).
8395 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
8396 window (FRAME_X_WINDOW).
8399 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
8406 int newwidth
= f
->width
, newheight
= f
->height
;
8408 *top_pos
= f
->output_data
.x
->top_pos
;
8409 *left_pos
= f
->output_data
.x
->left_pos
;
8411 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
8415 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
8416 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
8417 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
8418 - f
->output_data
.x
->y_pixels_diff
;
8419 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
8423 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
8427 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
8428 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
8429 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
8430 - f
->output_data
.x
->x_pixels_diff
;
8431 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
8436 *height
= newheight
;
8440 /* Change the size of frame F's X window to COLS/ROWS in the case F
8441 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8442 top-left-corner window gravity for this size change and subsequent
8443 size changes. Otherwise we leave the window gravity unchanged. */
8446 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
8451 int pixelwidth
, pixelheight
;
8453 check_frame_size (f
, &rows
, &cols
);
8454 f
->output_data
.x
->vertical_scroll_bar_extra
8455 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8457 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
8458 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
8459 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
8461 compute_fringe_widths (f
, 0);
8463 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
8464 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
8466 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
8467 x_wm_set_size_hint (f
, (long) 0, 0);
8469 XSync (FRAME_X_DISPLAY (f
), False
);
8470 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8471 pixelwidth
, pixelheight
);
8473 /* Now, strictly speaking, we can't be sure that this is accurate,
8474 but the window manager will get around to dealing with the size
8475 change request eventually, and we'll hear how it went when the
8476 ConfigureNotify event gets here.
8478 We could just not bother storing any of this information here,
8479 and let the ConfigureNotify event set everything up, but that
8480 might be kind of confusing to the Lisp code, since size changes
8481 wouldn't be reported in the frame parameters until some random
8482 point in the future when the ConfigureNotify event arrives.
8484 We pass 1 for DELAY since we can't run Lisp code inside of
8486 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8487 PIXEL_WIDTH (f
) = pixelwidth
;
8488 PIXEL_HEIGHT (f
) = pixelheight
;
8490 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8491 receive in the ConfigureNotify event; if we get what we asked
8492 for, then the event won't cause the screen to become garbaged, so
8493 we have to make sure to do it here. */
8494 SET_FRAME_GARBAGED (f
);
8496 XFlush (FRAME_X_DISPLAY (f
));
8500 /* Call this to change the size of frame F's x-window.
8501 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8502 for this size change and subsequent size changes.
8503 Otherwise we leave the window gravity unchanged. */
8506 x_set_window_size (f
, change_gravity
, cols
, rows
)
8514 if (FRAME_GTK_WIDGET (f
))
8515 xg_frame_set_char_size (f
, cols
, rows
);
8517 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8520 if (f
->output_data
.x
->widget
!= NULL
)
8522 /* The x and y position of the widget is clobbered by the
8523 call to XtSetValues within EmacsFrameSetCharSize.
8524 This is a real kludge, but I don't understand Xt so I can't
8525 figure out a correct fix. Can anyone else tell me? -- rms. */
8526 int xpos
= f
->output_data
.x
->widget
->core
.x
;
8527 int ypos
= f
->output_data
.x
->widget
->core
.y
;
8528 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
8529 f
->output_data
.x
->widget
->core
.x
= xpos
;
8530 f
->output_data
.x
->widget
->core
.y
= ypos
;
8533 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8535 #else /* not USE_X_TOOLKIT */
8537 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8539 #endif /* not USE_X_TOOLKIT */
8541 /* If cursor was outside the new size, mark it as off. */
8542 mark_window_cursors_off (XWINDOW (f
->root_window
));
8544 /* Clear out any recollection of where the mouse highlighting was,
8545 since it might be in a place that's outside the new frame size.
8546 Actually checking whether it is outside is a pain in the neck,
8547 so don't try--just let the highlighting be done afresh with new size. */
8548 cancel_mouse_face (f
);
8553 /* Mouse warping. */
8556 x_set_mouse_position (f
, x
, y
)
8562 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
8563 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
8565 if (pix_x
< 0) pix_x
= 0;
8566 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
8568 if (pix_y
< 0) pix_y
= 0;
8569 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
8573 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8574 0, 0, 0, 0, pix_x
, pix_y
);
8578 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8581 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
8587 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8588 0, 0, 0, 0, pix_x
, pix_y
);
8592 /* focus shifting, raising and lowering. */
8595 x_focus_on_frame (f
)
8598 #if 0 /* This proves to be unpleasant. */
8602 /* I don't think that the ICCCM allows programs to do things like this
8603 without the interaction of the window manager. Whatever you end up
8604 doing with this code, do it to x_unfocus_frame too. */
8605 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8606 RevertToPointerRoot
, CurrentTime
);
8615 /* Look at the remarks in x_focus_on_frame. */
8616 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8617 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8618 RevertToPointerRoot
, CurrentTime
);
8622 /* Raise frame F. */
8628 if (f
->async_visible
)
8631 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8632 XFlush (FRAME_X_DISPLAY (f
));
8637 /* Lower frame F. */
8643 if (f
->async_visible
)
8646 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8647 XFlush (FRAME_X_DISPLAY (f
));
8653 XTframe_raise_lower (f
, raise_flag
)
8663 /* Change of visibility. */
8665 /* This tries to wait until the frame is really visible.
8666 However, if the window manager asks the user where to position
8667 the frame, this will return before the user finishes doing that.
8668 The frame will not actually be visible at that time,
8669 but it will become visible later when the window manager
8670 finishes with it. */
8673 x_make_frame_visible (f
)
8677 int original_top
, original_left
;
8678 int retry_count
= 2;
8684 type
= x_icon_type (f
);
8686 x_bitmap_icon (f
, type
);
8688 if (! FRAME_VISIBLE_P (f
))
8690 /* We test FRAME_GARBAGED_P here to make sure we don't
8691 call x_set_offset a second time
8692 if we get to x_make_frame_visible a second time
8693 before the window gets really visible. */
8694 if (! FRAME_ICONIFIED_P (f
)
8695 && ! f
->output_data
.x
->asked_for_visible
)
8696 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
8698 f
->output_data
.x
->asked_for_visible
= 1;
8700 if (! EQ (Vx_no_window_manager
, Qt
))
8701 x_wm_set_window_state (f
, NormalState
);
8702 #ifdef USE_X_TOOLKIT
8703 /* This was XtPopup, but that did nothing for an iconified frame. */
8704 XtMapWidget (f
->output_data
.x
->widget
);
8705 #else /* not USE_X_TOOLKIT */
8707 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8708 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8710 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8711 #endif /* not USE_GTK */
8712 #endif /* not USE_X_TOOLKIT */
8713 #if 0 /* This seems to bring back scroll bars in the wrong places
8714 if the window configuration has changed. They seem
8715 to come back ok without this. */
8716 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8717 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8721 XFlush (FRAME_X_DISPLAY (f
));
8723 /* Synchronize to ensure Emacs knows the frame is visible
8724 before we do anything else. We do this loop with input not blocked
8725 so that incoming events are handled. */
8729 /* This must be before UNBLOCK_INPUT
8730 since events that arrive in response to the actions above
8731 will set it when they are handled. */
8732 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8734 original_left
= f
->output_data
.x
->left_pos
;
8735 original_top
= f
->output_data
.x
->top_pos
;
8737 /* This must come after we set COUNT. */
8740 /* We unblock here so that arriving X events are processed. */
8742 /* Now move the window back to where it was "supposed to be".
8743 But don't do it if the gravity is negative.
8744 When the gravity is negative, this uses a position
8745 that is 3 pixels too low. Perhaps that's really the border width.
8747 Don't do this if the window has never been visible before,
8748 because the window manager may choose the position
8749 and we don't want to override it. */
8751 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
8752 && f
->output_data
.x
->win_gravity
== NorthWestGravity
8753 && previously_visible
)
8757 unsigned int width
, height
, border
, depth
;
8761 /* On some window managers (such as FVWM) moving an existing
8762 window, even to the same place, causes the window manager
8763 to introduce an offset. This can cause the window to move
8764 to an unexpected location. Check the geometry (a little
8765 slow here) and then verify that the window is in the right
8766 place. If the window is not in the right place, move it
8767 there, and take the potential window manager hit. */
8768 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8769 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
8771 if (original_left
!= x
|| original_top
!= y
)
8772 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8773 original_left
, original_top
);
8778 XSETFRAME (frame
, f
);
8780 /* Wait until the frame is visible. Process X events until a
8781 MapNotify event has been seen, or until we think we won't get a
8782 MapNotify at all.. */
8783 for (count
= input_signal_count
+ 10;
8784 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
8786 /* Force processing of queued events. */
8789 /* Machines that do polling rather than SIGIO have been
8790 observed to go into a busy-wait here. So we'll fake an
8791 alarm signal to let the handler know that there's something
8792 to be read. We used to raise a real alarm, but it seems
8793 that the handler isn't always enabled here. This is
8795 if (input_polling_used ())
8797 /* It could be confusing if a real alarm arrives while
8798 processing the fake one. Turn it off and let the
8799 handler reset it. */
8800 extern void poll_for_input_1
P_ ((void));
8801 int old_poll_suppress_count
= poll_suppress_count
;
8802 poll_suppress_count
= 1;
8803 poll_for_input_1 ();
8804 poll_suppress_count
= old_poll_suppress_count
;
8807 /* See if a MapNotify event has been processed. */
8808 FRAME_SAMPLE_VISIBILITY (f
);
8813 (let ((f (selected-frame)))
8817 the frame is not raised with various window managers on
8818 FreeBSD, Linux and Solaris. It turns out that, for some
8819 unknown reason, the call to XtMapWidget is completely ignored.
8820 Mapping the widget a second time works. */
8822 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
8827 /* Change from mapped state to withdrawn state. */
8829 /* Make the frame visible (mapped and not iconified). */
8832 x_make_frame_invisible (f
)
8837 /* Use the frame's outermost window, not the one we normally draw on. */
8838 window
= FRAME_OUTER_WINDOW (f
);
8840 /* Don't keep the highlight on an invisible frame. */
8841 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
8842 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
8844 #if 0/* This might add unreliability; I don't trust it -- rms. */
8845 if (! f
->async_visible
&& ! f
->async_iconified
)
8851 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
8852 that the current position of the window is user-specified, rather than
8853 program-specified, so that when the window is mapped again, it will be
8854 placed at the same location, without forcing the user to position it
8855 by hand again (they have already done that once for this window.) */
8856 x_wm_set_size_hint (f
, (long) 0, 1);
8859 if (FRAME_GTK_OUTER_WIDGET (f
))
8860 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
8866 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
8867 DefaultScreen (FRAME_X_DISPLAY (f
))))
8869 UNBLOCK_INPUT_RESIGNAL
;
8870 error ("Can't notify window manager of window withdrawal");
8872 #else /* ! defined (HAVE_X11R4) */
8874 /* Tell the window manager what we're going to do. */
8875 if (! EQ (Vx_no_window_manager
, Qt
))
8879 unmap
.xunmap
.type
= UnmapNotify
;
8880 unmap
.xunmap
.window
= window
;
8881 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
8882 unmap
.xunmap
.from_configure
= False
;
8883 if (! XSendEvent (FRAME_X_DISPLAY (f
),
8884 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
8886 SubstructureRedirectMaskSubstructureNotifyMask
,
8889 UNBLOCK_INPUT_RESIGNAL
;
8890 error ("Can't notify window manager of withdrawal");
8894 /* Unmap the window ourselves. Cheeky! */
8895 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
8896 #endif /* ! defined (HAVE_X11R4) */
8899 /* We can't distinguish this from iconification
8900 just by the event that we get from the server.
8901 So we can't win using the usual strategy of letting
8902 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
8903 and synchronize with the server to make sure we agree. */
8905 FRAME_ICONIFIED_P (f
) = 0;
8906 f
->async_visible
= 0;
8907 f
->async_iconified
= 0;
8914 /* Change window state from mapped to iconified. */
8923 /* Don't keep the highlight on an invisible frame. */
8924 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
8925 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
8927 if (f
->async_iconified
)
8932 FRAME_SAMPLE_VISIBILITY (f
);
8934 type
= x_icon_type (f
);
8936 x_bitmap_icon (f
, type
);
8939 if (FRAME_GTK_OUTER_WIDGET (f
))
8941 if (! FRAME_VISIBLE_P (f
))
8942 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8944 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8947 f
->async_iconified
= 1;
8948 f
->async_visible
= 0;
8954 #ifdef USE_X_TOOLKIT
8956 if (! FRAME_VISIBLE_P (f
))
8958 if (! EQ (Vx_no_window_manager
, Qt
))
8959 x_wm_set_window_state (f
, IconicState
);
8960 /* This was XtPopup, but that did nothing for an iconified frame. */
8961 XtMapWidget (f
->output_data
.x
->widget
);
8962 /* The server won't give us any event to indicate
8963 that an invisible frame was changed to an icon,
8964 so we have to record it here. */
8967 f
->async_iconified
= 1;
8968 f
->async_visible
= 0;
8973 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
8974 XtWindow (f
->output_data
.x
->widget
),
8975 DefaultScreen (FRAME_X_DISPLAY (f
)));
8979 error ("Can't notify window manager of iconification");
8981 f
->async_iconified
= 1;
8982 f
->async_visible
= 0;
8986 XFlush (FRAME_X_DISPLAY (f
));
8988 #else /* not USE_X_TOOLKIT */
8990 /* Make sure the X server knows where the window should be positioned,
8991 in case the user deiconifies with the window manager. */
8992 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
8993 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
8995 /* Since we don't know which revision of X we're running, we'll use both
8996 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
8998 /* X11R4: send a ClientMessage to the window manager using the
8999 WM_CHANGE_STATE type. */
9003 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9004 message
.xclient
.type
= ClientMessage
;
9005 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9006 message
.xclient
.format
= 32;
9007 message
.xclient
.data
.l
[0] = IconicState
;
9009 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9010 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9012 SubstructureRedirectMask
| SubstructureNotifyMask
,
9015 UNBLOCK_INPUT_RESIGNAL
;
9016 error ("Can't notify window manager of iconification");
9020 /* X11R3: set the initial_state field of the window manager hints to
9022 x_wm_set_window_state (f
, IconicState
);
9024 if (!FRAME_VISIBLE_P (f
))
9026 /* If the frame was withdrawn, before, we must map it. */
9027 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9030 f
->async_iconified
= 1;
9031 f
->async_visible
= 0;
9033 XFlush (FRAME_X_DISPLAY (f
));
9035 #endif /* not USE_X_TOOLKIT */
9039 /* Free X resources of frame F. */
9042 x_free_frame_resources (f
)
9045 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9047 struct scroll_bar
*b
;
9051 /* If a display connection is dead, don't try sending more
9052 commands to the X server. */
9053 if (dpyinfo
->display
)
9055 if (f
->output_data
.x
->icon_desc
)
9056 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9058 #ifdef USE_X_TOOLKIT
9059 /* Explicitly destroy the scroll bars of the frame. Without
9060 this, we get "BadDrawable" errors from the toolkit later on,
9061 presumably from expose events generated for the disappearing
9062 toolkit scroll bars. */
9063 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9065 b
= XSCROLL_BAR (bar
);
9066 x_scroll_bar_remove (b
);
9075 #ifdef USE_X_TOOLKIT
9076 if (f
->output_data
.x
->widget
)
9078 XtDestroyWidget (f
->output_data
.x
->widget
);
9079 f
->output_data
.x
->widget
= NULL
;
9081 /* Tooltips don't have widgets, only a simple X window, even if
9082 we are using a toolkit. */
9083 else if (FRAME_X_WINDOW (f
))
9084 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9086 free_frame_menubar (f
);
9087 #else /* !USE_X_TOOLKIT */
9090 /* In the GTK version, tooltips are normal X
9091 frames. We must check and free both types. */
9092 if (FRAME_GTK_OUTER_WIDGET (f
))
9094 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9095 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9096 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9098 #endif /* USE_GTK */
9100 if (FRAME_X_WINDOW (f
))
9101 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9102 #endif /* !USE_X_TOOLKIT */
9104 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
9105 unload_color (f
, f
->output_data
.x
->background_pixel
);
9106 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9107 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9108 unload_color (f
, f
->output_data
.x
->border_pixel
);
9109 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9111 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9112 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9113 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9114 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9115 #ifdef USE_TOOLKIT_SCROLL_BARS
9116 /* Scrollbar shadow colors. */
9117 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9118 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9119 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9120 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9121 #endif /* USE_TOOLKIT_SCROLL_BARS */
9122 if (f
->output_data
.x
->white_relief
.allocated_p
)
9123 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9124 if (f
->output_data
.x
->black_relief
.allocated_p
)
9125 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9127 if (FRAME_FACE_CACHE (f
))
9128 free_frame_faces (f
);
9131 XFlush (FRAME_X_DISPLAY (f
));
9134 if (f
->output_data
.x
->saved_menu_event
)
9135 xfree (f
->output_data
.x
->saved_menu_event
);
9137 xfree (f
->output_data
.x
);
9138 f
->output_data
.x
= NULL
;
9140 if (f
== dpyinfo
->x_focus_frame
)
9141 dpyinfo
->x_focus_frame
= 0;
9142 if (f
== dpyinfo
->x_focus_event_frame
)
9143 dpyinfo
->x_focus_event_frame
= 0;
9144 if (f
== dpyinfo
->x_highlight_frame
)
9145 dpyinfo
->x_highlight_frame
= 0;
9147 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9149 dpyinfo
->mouse_face_beg_row
9150 = dpyinfo
->mouse_face_beg_col
= -1;
9151 dpyinfo
->mouse_face_end_row
9152 = dpyinfo
->mouse_face_end_col
= -1;
9153 dpyinfo
->mouse_face_window
= Qnil
;
9154 dpyinfo
->mouse_face_deferred_gc
= 0;
9155 dpyinfo
->mouse_face_mouse_frame
= 0;
9162 /* Destroy the X window of frame F. */
9165 x_destroy_window (f
)
9168 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9170 /* If a display connection is dead, don't try sending more
9171 commands to the X server. */
9172 if (dpyinfo
->display
!= 0)
9173 x_free_frame_resources (f
);
9175 dpyinfo
->reference_count
--;
9179 /* Setting window manager hints. */
9181 /* Set the normal size hints for the window manager, for frame F.
9182 FLAGS is the flags word to use--or 0 meaning preserve the flags
9183 that the window now has.
9184 If USER_POSITION is nonzero, we set the USPosition
9185 flag (this is useful when FLAGS is 0).
9186 The GTK version is in gtkutils.c */
9190 x_wm_set_size_hint (f
, flags
, user_position
)
9195 XSizeHints size_hints
;
9197 #ifdef USE_X_TOOLKIT
9200 Dimension widget_width
, widget_height
;
9203 Window window
= FRAME_OUTER_WINDOW (f
);
9205 /* Setting PMaxSize caused various problems. */
9206 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9208 size_hints
.x
= f
->output_data
.x
->left_pos
;
9209 size_hints
.y
= f
->output_data
.x
->top_pos
;
9211 #ifdef USE_X_TOOLKIT
9212 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9213 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9214 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9215 size_hints
.height
= widget_height
;
9216 size_hints
.width
= widget_width
;
9217 #else /* not USE_X_TOOLKIT */
9218 size_hints
.height
= PIXEL_HEIGHT (f
);
9219 size_hints
.width
= PIXEL_WIDTH (f
);
9220 #endif /* not USE_X_TOOLKIT */
9222 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
9223 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
9224 size_hints
.max_width
9225 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
9226 size_hints
.max_height
9227 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
9229 /* Calculate the base and minimum sizes.
9231 (When we use the X toolkit, we don't do it here.
9232 Instead we copy the values that the widgets are using, below.) */
9233 #ifndef USE_X_TOOLKIT
9235 int base_width
, base_height
;
9236 int min_rows
= 0, min_cols
= 0;
9238 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
9239 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
9241 check_frame_size (f
, &min_rows
, &min_cols
);
9243 /* The window manager uses the base width hints to calculate the
9244 current number of rows and columns in the frame while
9245 resizing; min_width and min_height aren't useful for this
9246 purpose, since they might not give the dimensions for a
9247 zero-row, zero-column frame.
9249 We use the base_width and base_height members if we have
9250 them; otherwise, we set the min_width and min_height members
9251 to the size for a zero x zero frame. */
9254 size_hints
.flags
|= PBaseSize
;
9255 size_hints
.base_width
= base_width
;
9256 size_hints
.base_height
= base_height
;
9257 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9258 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9260 size_hints
.min_width
= base_width
;
9261 size_hints
.min_height
= base_height
;
9265 /* If we don't need the old flags, we don't need the old hint at all. */
9268 size_hints
.flags
|= flags
;
9271 #endif /* not USE_X_TOOLKIT */
9274 XSizeHints hints
; /* Sometimes I hate X Windows... */
9275 long supplied_return
;
9279 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9282 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
9285 #ifdef USE_X_TOOLKIT
9286 size_hints
.base_height
= hints
.base_height
;
9287 size_hints
.base_width
= hints
.base_width
;
9288 size_hints
.min_height
= hints
.min_height
;
9289 size_hints
.min_width
= hints
.min_width
;
9293 size_hints
.flags
|= flags
;
9298 if (hints
.flags
& PSize
)
9299 size_hints
.flags
|= PSize
;
9300 if (hints
.flags
& PPosition
)
9301 size_hints
.flags
|= PPosition
;
9302 if (hints
.flags
& USPosition
)
9303 size_hints
.flags
|= USPosition
;
9304 if (hints
.flags
& USSize
)
9305 size_hints
.flags
|= USSize
;
9309 #ifndef USE_X_TOOLKIT
9314 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
9315 size_hints
.flags
|= PWinGravity
;
9319 size_hints
.flags
&= ~ PPosition
;
9320 size_hints
.flags
|= USPosition
;
9322 #endif /* PWinGravity */
9325 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9327 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9330 #endif /* not USE_GTK */
9332 /* Used for IconicState or NormalState */
9335 x_wm_set_window_state (f
, state
)
9339 #ifdef USE_X_TOOLKIT
9342 XtSetArg (al
[0], XtNinitialState
, state
);
9343 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9344 #else /* not USE_X_TOOLKIT */
9345 Window window
= FRAME_X_WINDOW (f
);
9347 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9348 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9350 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9351 #endif /* not USE_X_TOOLKIT */
9355 x_wm_set_icon_pixmap (f
, pixmap_id
)
9361 #ifndef USE_X_TOOLKIT
9362 Window window
= FRAME_OUTER_WINDOW (f
);
9367 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9368 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9372 /* It seems there is no way to turn off use of an icon pixmap.
9373 The following line does it, only if no icon has yet been created,
9374 for some window managers. But with mwm it crashes.
9375 Some people say it should clear the IconPixmapHint bit in this case,
9376 but that doesn't work, and the X consortium said it isn't the
9377 right thing at all. Since there is no way to win,
9378 best to explicitly give up. */
9380 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
9386 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
9390 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9391 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9394 #else /* not USE_X_TOOLKIT */
9396 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
9397 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9399 #endif /* not USE_X_TOOLKIT */
9403 x_wm_set_icon_position (f
, icon_x
, icon_y
)
9407 Window window
= FRAME_OUTER_WINDOW (f
);
9409 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9410 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9411 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9413 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9417 /***********************************************************************
9419 ***********************************************************************/
9421 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
9424 x_get_font_info (f
, font_idx
)
9428 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
9432 /* Return a list of names of available fonts matching PATTERN on frame F.
9434 If SIZE is > 0, it is the size (maximum bounds width) of fonts
9437 SIZE < 0 means include scalable fonts.
9439 Frame F null means we have not yet created any frame on X, and
9440 consult the first display in x_display_list. MAXNAMES sets a limit
9441 on how many fonts to match. */
9444 x_list_fonts (f
, pattern
, size
, maxnames
)
9446 Lisp_Object pattern
;
9450 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
9451 Lisp_Object tem
, second_best
;
9452 struct x_display_info
*dpyinfo
9453 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
9454 Display
*dpy
= dpyinfo
->display
;
9455 int try_XLoadQueryFont
= 0;
9457 int allow_scalable_fonts_p
= 0;
9461 allow_scalable_fonts_p
= 1;
9465 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
9466 if (NILP (patterns
))
9467 patterns
= Fcons (pattern
, Qnil
);
9469 if (maxnames
== 1 && !size
)
9470 /* We can return any single font matching PATTERN. */
9471 try_XLoadQueryFont
= 1;
9473 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
9476 char **names
= NULL
;
9478 pattern
= XCAR (patterns
);
9479 /* See if we cached the result for this particular query.
9480 The cache is an alist of the form:
9481 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
9482 tem
= XCDR (dpyinfo
->name_list_element
);
9483 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
9484 allow_scalable_fonts_p
? Qt
: Qnil
);
9485 list
= Fassoc (key
, tem
);
9488 list
= Fcdr_safe (list
);
9489 /* We have a cashed list. Don't have to get the list again. */
9493 /* At first, put PATTERN in the cache. */
9496 count
= x_catch_errors (dpy
);
9498 if (try_XLoadQueryFont
)
9501 unsigned long value
;
9503 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
9504 if (x_had_errors_p (dpy
))
9506 /* This error is perhaps due to insufficient memory on X
9507 server. Let's just ignore it. */
9509 x_clear_errors (dpy
);
9513 && XGetFontProperty (font
, XA_FONT
, &value
))
9515 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
9516 int len
= strlen (name
);
9519 /* If DXPC (a Differential X Protocol Compressor)
9520 Ver.3.7 is running, XGetAtomName will return null
9521 string. We must avoid such a name. */
9523 try_XLoadQueryFont
= 0;
9527 names
= (char **) alloca (sizeof (char *));
9528 /* Some systems only allow alloca assigned to a
9530 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
9531 bcopy (name
, names
[0], len
+ 1);
9536 try_XLoadQueryFont
= 0;
9539 XFreeFont (dpy
, font
);
9542 if (!try_XLoadQueryFont
)
9544 /* We try at least 10 fonts because XListFonts will return
9545 auto-scaled fonts at the head. */
9552 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
9553 if (num_fonts
== limit
)
9556 XFreeFontNames (names
);
9565 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
9568 if (x_had_errors_p (dpy
))
9570 /* This error is perhaps due to insufficient memory on X
9571 server. Let's just ignore it. */
9573 x_clear_errors (dpy
);
9577 x_uncatch_errors (dpy
, count
);
9584 /* Make a list of all the fonts we got back.
9585 Store that in the font cache for the display. */
9586 for (i
= 0; i
< num_fonts
; i
++)
9590 int average_width
= -1, dashes
= 0;
9592 /* Count the number of dashes in NAMES[I]. If there are
9593 14 dashes, and the field value following 12th dash
9594 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
9595 is usually too ugly to be used for editing. Let's
9601 if (dashes
== 7) /* PIXEL_SIZE field */
9603 else if (dashes
== 12) /* AVERAGE_WIDTH field */
9604 average_width
= atoi (p
);
9607 if (allow_scalable_fonts_p
9608 || dashes
< 14 || average_width
!= 0)
9610 tem
= build_string (names
[i
]);
9611 if (NILP (Fassoc (tem
, list
)))
9613 if (STRINGP (Vx_pixel_size_width_font_regexp
)
9614 && ((fast_c_string_match_ignore_case
9615 (Vx_pixel_size_width_font_regexp
, names
[i
]))
9617 /* We can set the value of PIXEL_SIZE to the
9618 width of this font. */
9619 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
9621 /* For the moment, width is not known. */
9622 list
= Fcons (Fcons (tem
, Qnil
), list
);
9627 if (!try_XLoadQueryFont
)
9630 XFreeFontNames (names
);
9635 /* Now store the result in the cache. */
9636 XSETCDR (dpyinfo
->name_list_element
,
9637 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
9640 if (NILP (list
)) continue; /* Try the remaining alternatives. */
9642 newlist
= second_best
= Qnil
;
9643 /* Make a list of the fonts that have the right width. */
9644 for (; CONSP (list
); list
= XCDR (list
))
9650 if (!CONSP (tem
) || NILP (XCAR (tem
)))
9654 newlist
= Fcons (XCAR (tem
), newlist
);
9658 if (!INTEGERP (XCDR (tem
)))
9660 /* Since we have not yet known the size of this font, we
9661 must try slow function call XLoadQueryFont. */
9662 XFontStruct
*thisinfo
;
9665 count
= x_catch_errors (dpy
);
9666 thisinfo
= XLoadQueryFont (dpy
,
9667 SDATA (XCAR (tem
)));
9668 if (x_had_errors_p (dpy
))
9670 /* This error is perhaps due to insufficient memory on X
9671 server. Let's just ignore it. */
9673 x_clear_errors (dpy
);
9675 x_uncatch_errors (dpy
, count
);
9681 (thisinfo
->min_bounds
.width
== 0
9683 : make_number (thisinfo
->max_bounds
.width
)));
9685 XFreeFont (dpy
, thisinfo
);
9689 /* For unknown reason, the previous call of XListFont had
9690 returned a font which can't be opened. Record the size
9691 as 0 not to try to open it again. */
9692 XSETCDR (tem
, make_number (0));
9695 found_size
= XINT (XCDR (tem
));
9696 if (found_size
== size
)
9697 newlist
= Fcons (XCAR (tem
), newlist
);
9698 else if (found_size
> 0)
9700 if (NILP (second_best
))
9702 else if (found_size
< size
)
9704 if (XINT (XCDR (second_best
)) > size
9705 || XINT (XCDR (second_best
)) < found_size
)
9710 if (XINT (XCDR (second_best
)) > size
9711 && XINT (XCDR (second_best
)) > found_size
)
9716 if (!NILP (newlist
))
9718 else if (!NILP (second_best
))
9720 newlist
= Fcons (XCAR (second_best
), Qnil
);
9731 /* Check that FONT is valid on frame F. It is if it can be found in F's
9735 x_check_font (f
, font
)
9740 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9742 xassert (font
!= NULL
);
9744 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9745 if (dpyinfo
->font_table
[i
].name
9746 && font
== dpyinfo
->font_table
[i
].font
)
9749 xassert (i
< dpyinfo
->n_fonts
);
9752 #endif /* GLYPH_DEBUG != 0 */
9754 /* Set *W to the minimum width, *H to the minimum font height of FONT.
9755 Note: There are (broken) X fonts out there with invalid XFontStruct
9756 min_bounds contents. For example, handa@etl.go.jp reports that
9757 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
9758 have font->min_bounds.width == 0. */
9761 x_font_min_bounds (font
, w
, h
)
9765 *h
= FONT_HEIGHT (font
);
9766 *w
= font
->min_bounds
.width
;
9768 /* Try to handle the case where FONT->min_bounds has invalid
9769 contents. Since the only font known to have invalid min_bounds
9770 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
9772 *w
= font
->max_bounds
.width
;
9776 /* Compute the smallest character width and smallest font height over
9777 all fonts available on frame F. Set the members smallest_char_width
9778 and smallest_font_height in F's x_display_info structure to
9779 the values computed. Value is non-zero if smallest_font_height or
9780 smallest_char_width become smaller than they were before. */
9783 x_compute_min_glyph_bounds (f
)
9787 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9789 int old_width
= dpyinfo
->smallest_char_width
;
9790 int old_height
= dpyinfo
->smallest_font_height
;
9792 dpyinfo
->smallest_font_height
= 100000;
9793 dpyinfo
->smallest_char_width
= 100000;
9795 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
9796 if (dpyinfo
->font_table
[i
].name
)
9798 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
9801 font
= (XFontStruct
*) fontp
->font
;
9802 xassert (font
!= (XFontStruct
*) ~0);
9803 x_font_min_bounds (font
, &w
, &h
);
9805 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
9806 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
9809 xassert (dpyinfo
->smallest_char_width
> 0
9810 && dpyinfo
->smallest_font_height
> 0);
9812 return (dpyinfo
->n_fonts
== 1
9813 || dpyinfo
->smallest_char_width
< old_width
9814 || dpyinfo
->smallest_font_height
< old_height
);
9818 /* Load font named FONTNAME of the size SIZE for frame F, and return a
9819 pointer to the structure font_info while allocating it dynamically.
9820 If SIZE is 0, load any size of font.
9821 If loading is failed, return NULL. */
9824 x_load_font (f
, fontname
, size
)
9826 register char *fontname
;
9829 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9830 Lisp_Object font_names
;
9833 /* Get a list of all the fonts that match this name. Once we
9834 have a list of matching fonts, we compare them against the fonts
9835 we already have by comparing names. */
9836 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
9838 if (!NILP (font_names
))
9843 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9844 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
9845 if (dpyinfo
->font_table
[i
].name
9846 && (!strcmp (dpyinfo
->font_table
[i
].name
,
9847 SDATA (XCAR (tail
)))
9848 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
9849 SDATA (XCAR (tail
)))))
9850 return (dpyinfo
->font_table
+ i
);
9853 /* Load the font and add it to the table. */
9857 struct font_info
*fontp
;
9858 unsigned long value
;
9861 /* If we have found fonts by x_list_font, load one of them. If
9862 not, we still try to load a font by the name given as FONTNAME
9863 because XListFonts (called in x_list_font) of some X server has
9864 a bug of not finding a font even if the font surely exists and
9865 is loadable by XLoadQueryFont. */
9866 if (size
> 0 && !NILP (font_names
))
9867 fontname
= (char *) SDATA (XCAR (font_names
));
9870 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
9871 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
9872 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
9874 /* This error is perhaps due to insufficient memory on X
9875 server. Let's just ignore it. */
9877 x_clear_errors (FRAME_X_DISPLAY (f
));
9879 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
9884 /* Find a free slot in the font table. */
9885 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
9886 if (dpyinfo
->font_table
[i
].name
== NULL
)
9889 /* If no free slot found, maybe enlarge the font table. */
9890 if (i
== dpyinfo
->n_fonts
9891 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
9894 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
9895 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
9897 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
9900 fontp
= dpyinfo
->font_table
+ i
;
9901 if (i
== dpyinfo
->n_fonts
)
9904 /* Now fill in the slots of *FONTP. */
9907 fontp
->font_idx
= i
;
9908 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
9909 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
9911 /* Try to get the full name of FONT. Put it in FULL_NAME. */
9913 if (XGetFontProperty (font
, XA_FONT
, &value
))
9915 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
9919 /* Count the number of dashes in the "full name".
9920 If it is too few, this isn't really the font's full name,
9922 In X11R4, the fonts did not come with their canonical names
9933 full_name
= (char *) xmalloc (p
- name
+ 1);
9934 bcopy (name
, full_name
, p
- name
+ 1);
9941 fontp
->full_name
= full_name
;
9943 fontp
->full_name
= fontp
->name
;
9945 fontp
->size
= font
->max_bounds
.width
;
9946 fontp
->height
= FONT_HEIGHT (font
);
9948 if (NILP (font_names
))
9950 /* We come here because of a bug of XListFonts mentioned at
9951 the head of this block. Let's store this information in
9952 the cache for x_list_fonts. */
9953 Lisp_Object lispy_name
= build_string (fontname
);
9954 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
9955 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
9958 XSETCDR (dpyinfo
->name_list_element
,
9960 Fcons (Fcons (lispy_full_name
,
9961 make_number (fontp
->size
)),
9963 XCDR (dpyinfo
->name_list_element
)));
9966 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
9968 XSETCDR (dpyinfo
->name_list_element
,
9970 Fcons (Fcons (lispy_full_name
,
9971 make_number (fontp
->size
)),
9973 XCDR (dpyinfo
->name_list_element
)));
9977 /* The slot `encoding' specifies how to map a character
9978 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
9979 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
9980 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
9981 2:0xA020..0xFF7F). For the moment, we don't know which charset
9982 uses this font. So, we set information in fontp->encoding[1]
9983 which is never used by any charset. If mapping can't be
9984 decided, set FONT_ENCODING_NOT_DECIDED. */
9986 = (font
->max_byte1
== 0
9988 ? (font
->min_char_or_byte2
< 0x80
9989 ? (font
->max_char_or_byte2
< 0x80
9990 ? 0 /* 0x20..0x7F */
9991 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
9992 : 1) /* 0xA0..0xFF */
9994 : (font
->min_byte1
< 0x80
9995 ? (font
->max_byte1
< 0x80
9996 ? (font
->min_char_or_byte2
< 0x80
9997 ? (font
->max_char_or_byte2
< 0x80
9998 ? 0 /* 0x2020..0x7F7F */
9999 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
10000 : 3) /* 0x20A0..0x7FFF */
10001 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
10002 : (font
->min_char_or_byte2
< 0x80
10003 ? (font
->max_char_or_byte2
< 0x80
10004 ? 2 /* 0xA020..0xFF7F */
10005 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
10006 : 1))); /* 0xA0A0..0xFFFF */
10008 fontp
->baseline_offset
10009 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
10010 ? (long) value
: 0);
10011 fontp
->relative_compose
10012 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
10013 ? (long) value
: 0);
10014 fontp
->default_ascent
10015 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
10016 ? (long) value
: 0);
10018 /* Set global flag fonts_changed_p to non-zero if the font loaded
10019 has a character with a smaller width than any other character
10020 before, or if the font loaded has a smaller height than any
10021 other font loaded before. If this happens, it will make a
10022 glyph matrix reallocation necessary. */
10023 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
10030 /* Return a pointer to struct font_info of a font named FONTNAME for
10031 frame F. If no such font is loaded, return NULL. */
10034 x_query_font (f
, fontname
)
10036 register char *fontname
;
10038 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10041 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10042 if (dpyinfo
->font_table
[i
].name
10043 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
10044 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
10045 return (dpyinfo
->font_table
+ i
);
10050 /* Find a CCL program for a font specified by FONTP, and set the member
10051 `encoder' of the structure. */
10054 x_find_ccl_program (fontp
)
10055 struct font_info
*fontp
;
10057 Lisp_Object list
, elt
;
10060 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
10064 && STRINGP (XCAR (elt
))
10065 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
10067 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
10074 struct ccl_program
*ccl
10075 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
10077 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
10080 fontp
->font_encoder
= ccl
;
10086 /***********************************************************************
10088 ***********************************************************************/
10090 #ifdef USE_X_TOOLKIT
10091 static XrmOptionDescRec emacs_options
[] = {
10092 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
10093 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
10095 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
10096 XrmoptionSepArg
, NULL
},
10097 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
10099 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10100 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10101 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10102 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10103 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10104 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
10105 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
10107 #endif /* USE_X_TOOLKIT */
10109 static int x_initialized
;
10111 #ifdef MULTI_KBOARD
10112 /* Test whether two display-name strings agree up to the dot that separates
10113 the screen number from the server number. */
10115 same_x_server (name1
, name2
)
10116 const char *name1
, *name2
;
10118 int seen_colon
= 0;
10119 const unsigned char *system_name
= SDATA (Vsystem_name
);
10120 int system_name_length
= strlen (system_name
);
10121 int length_until_period
= 0;
10123 while (system_name
[length_until_period
] != 0
10124 && system_name
[length_until_period
] != '.')
10125 length_until_period
++;
10127 /* Treat `unix' like an empty host name. */
10128 if (! strncmp (name1
, "unix:", 5))
10130 if (! strncmp (name2
, "unix:", 5))
10132 /* Treat this host's name like an empty host name. */
10133 if (! strncmp (name1
, system_name
, system_name_length
)
10134 && name1
[system_name_length
] == ':')
10135 name1
+= system_name_length
;
10136 if (! strncmp (name2
, system_name
, system_name_length
)
10137 && name2
[system_name_length
] == ':')
10138 name2
+= system_name_length
;
10139 /* Treat this host's domainless name like an empty host name. */
10140 if (! strncmp (name1
, system_name
, length_until_period
)
10141 && name1
[length_until_period
] == ':')
10142 name1
+= length_until_period
;
10143 if (! strncmp (name2
, system_name
, length_until_period
)
10144 && name2
[length_until_period
] == ':')
10145 name2
+= length_until_period
;
10147 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
10151 if (seen_colon
&& *name1
== '.')
10155 && (*name1
== '.' || *name1
== '\0')
10156 && (*name2
== '.' || *name2
== '\0'));
10160 struct x_display_info
*
10161 x_term_init (display_name
, xrm_option
, resource_name
)
10162 Lisp_Object display_name
;
10164 char *resource_name
;
10168 struct x_display_info
*dpyinfo
;
10173 if (!x_initialized
)
10181 #define NUM_ARGV 10
10183 char *argv
[NUM_ARGV
];
10184 char **argv2
= argv
;
10187 /* GTK 2.0 can only handle one display, GTK 2.2 can handle more
10188 than one, but this remains to be implemented. */
10189 if (x_initialized
> 1)
10194 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
10198 argv
[argc
++] = initial_argv
[0];
10200 if (! NILP (display_name
))
10202 argv
[argc
++] = "--display";
10203 argv
[argc
++] = SDATA (display_name
);
10206 argv
[argc
++] = "--name";
10207 argv
[argc
++] = resource_name
;
10210 XSetLocaleModifiers ("");
10213 gtk_init (&argc
, &argv2
);
10215 /* gtk_init does set_locale. We must fix locale after calling it. */
10219 dpy
= GDK_DISPLAY ();
10221 /* NULL window -> events for all windows go to our function */
10222 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10224 /* Load our own gtkrc if it exists. */
10226 struct gcpro gcpro1
, gcpro2
;
10227 char *file
= "~/.emacs.d/gtkrc";
10228 Lisp_Object s
, abs_file
;
10230 GCPRO2 (s
, abs_file
);
10231 s
= make_string (file
, strlen (file
));
10232 abs_file
= Fexpand_file_name(s
, Qnil
);
10234 if (! NILP (abs_file
) && Ffile_readable_p (abs_file
))
10235 gtk_rc_parse (SDATA (abs_file
));
10240 XSetErrorHandler (x_error_handler
);
10241 XSetIOErrorHandler (x_io_error_quitter
);
10243 #else /* not USE_GTK */
10244 #ifdef USE_X_TOOLKIT
10245 /* weiner@footloose.sps.mot.com reports that this causes
10247 X protocol error: BadAtom (invalid Atom parameter)
10248 on protocol request 18skiloaf.
10249 So let's not use it until R6. */
10250 #ifdef HAVE_X11XTR6
10251 XtSetLanguageProc (NULL
, NULL
, NULL
);
10262 argv
[argc
++] = "-xrm";
10263 argv
[argc
++] = xrm_option
;
10265 turn_on_atimers (0);
10266 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
10267 resource_name
, EMACS_CLASS
,
10268 emacs_options
, XtNumber (emacs_options
),
10270 turn_on_atimers (1);
10272 #ifdef HAVE_X11XTR6
10273 /* I think this is to compensate for XtSetLanguageProc. */
10278 #else /* not USE_X_TOOLKIT */
10280 XSetLocaleModifiers ("");
10282 dpy
= XOpenDisplay (SDATA (display_name
));
10283 #endif /* not USE_X_TOOLKIT */
10284 #endif /* not USE_GTK*/
10286 /* Detect failure. */
10293 /* We have definitely succeeded. Record the new connection. */
10295 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
10296 bzero (dpyinfo
, sizeof *dpyinfo
);
10298 #ifdef MULTI_KBOARD
10300 struct x_display_info
*share
;
10303 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10304 share
= share
->next
, tail
= XCDR (tail
))
10305 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
10306 SDATA (display_name
)))
10309 dpyinfo
->kboard
= share
->kboard
;
10312 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
10313 init_kboard (dpyinfo
->kboard
);
10314 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10316 char *vendor
= ServerVendor (dpy
);
10318 dpyinfo
->kboard
->Vsystem_key_alist
10319 = call1 (Qvendor_specific_keysyms
,
10320 build_string (vendor
? vendor
: ""));
10324 dpyinfo
->kboard
->next_kboard
= all_kboards
;
10325 all_kboards
= dpyinfo
->kboard
;
10326 /* Don't let the initial kboard remain current longer than necessary.
10327 That would cause problems if a file loaded on startup tries to
10328 prompt in the mini-buffer. */
10329 if (current_kboard
== initial_kboard
)
10330 current_kboard
= dpyinfo
->kboard
;
10332 dpyinfo
->kboard
->reference_count
++;
10336 /* Put this display on the chain. */
10337 dpyinfo
->next
= x_display_list
;
10338 x_display_list
= dpyinfo
;
10340 /* Put it on x_display_name_list as well, to keep them parallel. */
10341 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10342 x_display_name_list
);
10343 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10345 dpyinfo
->display
= dpy
;
10348 XSetAfterFunction (x_current_display
, x_trace_wire
);
10352 = (char *) xmalloc (SBYTES (Vinvocation_name
)
10353 + SBYTES (Vsystem_name
)
10355 sprintf (dpyinfo
->x_id_name
, "%s@%s",
10356 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10358 /* Figure out which modifier bits mean what. */
10359 x_find_modifier_meanings (dpyinfo
);
10361 /* Get the scroll bar cursor. */
10362 dpyinfo
->vertical_scroll_bar_cursor
10363 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10365 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10366 resource_name
, EMACS_CLASS
);
10367 #ifdef HAVE_XRMSETDATABASE
10368 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10370 dpyinfo
->display
->db
= xrdb
;
10372 /* Put the rdb where we can find it in a way that works on
10374 dpyinfo
->xrdb
= xrdb
;
10376 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10377 DefaultScreen (dpyinfo
->display
));
10378 select_visual (dpyinfo
);
10379 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10380 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
10381 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
10382 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10383 dpyinfo
->grabbed
= 0;
10384 dpyinfo
->reference_count
= 0;
10385 dpyinfo
->icon_bitmap_id
= -1;
10386 dpyinfo
->font_table
= NULL
;
10387 dpyinfo
->n_fonts
= 0;
10388 dpyinfo
->font_table_size
= 0;
10389 dpyinfo
->bitmaps
= 0;
10390 dpyinfo
->bitmaps_size
= 0;
10391 dpyinfo
->bitmaps_last
= 0;
10392 dpyinfo
->scratch_cursor_gc
= 0;
10393 dpyinfo
->mouse_face_mouse_frame
= 0;
10394 dpyinfo
->mouse_face_deferred_gc
= 0;
10395 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10396 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10397 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10398 dpyinfo
->mouse_face_window
= Qnil
;
10399 dpyinfo
->mouse_face_overlay
= Qnil
;
10400 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
10401 dpyinfo
->mouse_face_defer
= 0;
10402 dpyinfo
->mouse_face_hidden
= 0;
10403 dpyinfo
->x_focus_frame
= 0;
10404 dpyinfo
->x_focus_event_frame
= 0;
10405 dpyinfo
->x_highlight_frame
= 0;
10406 dpyinfo
->image_cache
= make_image_cache ();
10408 /* See if a private colormap is requested. */
10409 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10411 if (dpyinfo
->visual
->class == PseudoColor
)
10414 value
= display_x_get_resource (dpyinfo
,
10415 build_string ("privateColormap"),
10416 build_string ("PrivateColormap"),
10418 if (STRINGP (value
)
10419 && (!strcmp (SDATA (value
), "true")
10420 || !strcmp (SDATA (value
), "on")))
10421 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10425 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10426 dpyinfo
->visual
, AllocNone
);
10429 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10430 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10431 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10432 dpyinfo
->resy
= pixels
* 25.4 / mm
;
10433 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10434 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10435 dpyinfo
->resx
= pixels
* 25.4 / mm
;
10438 dpyinfo
->Xatom_wm_protocols
10439 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10440 dpyinfo
->Xatom_wm_take_focus
10441 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10442 dpyinfo
->Xatom_wm_save_yourself
10443 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10444 dpyinfo
->Xatom_wm_delete_window
10445 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10446 dpyinfo
->Xatom_wm_change_state
10447 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10448 dpyinfo
->Xatom_wm_configure_denied
10449 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10450 dpyinfo
->Xatom_wm_window_moved
10451 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10452 dpyinfo
->Xatom_editres
10453 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10454 dpyinfo
->Xatom_CLIPBOARD
10455 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10456 dpyinfo
->Xatom_TIMESTAMP
10457 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10458 dpyinfo
->Xatom_TEXT
10459 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10460 dpyinfo
->Xatom_COMPOUND_TEXT
10461 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10462 dpyinfo
->Xatom_UTF8_STRING
10463 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10464 dpyinfo
->Xatom_DELETE
10465 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10466 dpyinfo
->Xatom_MULTIPLE
10467 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10468 dpyinfo
->Xatom_INCR
10469 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10470 dpyinfo
->Xatom_EMACS_TMP
10471 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10472 dpyinfo
->Xatom_TARGETS
10473 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10474 dpyinfo
->Xatom_NULL
10475 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10476 dpyinfo
->Xatom_ATOM_PAIR
10477 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10478 /* For properties of font. */
10479 dpyinfo
->Xatom_PIXEL_SIZE
10480 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10481 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10482 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10483 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10484 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10485 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10486 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10488 /* Ghostscript support. */
10489 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10490 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10492 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10495 dpyinfo
->cut_buffers_initialized
= 0;
10497 connection
= ConnectionNumber (dpyinfo
->display
);
10498 dpyinfo
->connection
= connection
;
10503 null_bits
[0] = 0x00;
10505 dpyinfo
->null_pixel
10506 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10507 null_bits
, 1, 1, (long) 0, (long) 0,
10512 extern int gray_bitmap_width
, gray_bitmap_height
;
10513 extern char *gray_bitmap_bits
;
10515 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10517 gray_bitmap_width
, gray_bitmap_height
,
10518 (unsigned long) 1, (unsigned long) 0, 1);
10522 xim_initialize (dpyinfo
, resource_name
);
10525 #ifdef subprocesses
10526 /* This is only needed for distinguishing keyboard and process input. */
10527 if (connection
!= 0)
10528 add_keyboard_wait_descriptor (connection
);
10531 #ifndef F_SETOWN_BUG
10533 #ifdef F_SETOWN_SOCK_NEG
10534 /* stdin is a socket here */
10535 fcntl (connection
, F_SETOWN
, -getpid ());
10536 #else /* ! defined (F_SETOWN_SOCK_NEG) */
10537 fcntl (connection
, F_SETOWN
, getpid ());
10538 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
10539 #endif /* ! defined (F_SETOWN) */
10540 #endif /* F_SETOWN_BUG */
10543 if (interrupt_input
)
10544 init_sigio (connection
);
10545 #endif /* ! defined (SIGIO) */
10548 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
10549 /* Make sure that we have a valid font for dialog boxes
10550 so that Xt does not crash. */
10552 Display
*dpy
= dpyinfo
->display
;
10553 XrmValue d
, fr
, to
;
10557 d
.addr
= (XPointer
)&dpy
;
10558 d
.size
= sizeof (Display
*);
10559 fr
.addr
= XtDefaultFont
;
10560 fr
.size
= sizeof (XtDefaultFont
);
10561 to
.size
= sizeof (Font
*);
10562 to
.addr
= (XPointer
)&font
;
10563 count
= x_catch_errors (dpy
);
10564 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10566 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10567 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10568 x_uncatch_errors (dpy
, count
);
10573 /* See if we should run in synchronous mode. This is useful
10574 for debugging X code. */
10577 value
= display_x_get_resource (dpyinfo
,
10578 build_string ("synchronous"),
10579 build_string ("Synchronous"),
10581 if (STRINGP (value
)
10582 && (!strcmp (SDATA (value
), "true")
10583 || !strcmp (SDATA (value
), "on")))
10584 XSynchronize (dpyinfo
->display
, True
);
10592 /* Get rid of display DPYINFO, assuming all frames are already gone,
10593 and without sending any more commands to the X server. */
10596 x_delete_display (dpyinfo
)
10597 struct x_display_info
*dpyinfo
;
10599 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10601 /* Discard this display from x_display_name_list and x_display_list.
10602 We can't use Fdelq because that can quit. */
10603 if (! NILP (x_display_name_list
)
10604 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10605 x_display_name_list
= XCDR (x_display_name_list
);
10610 tail
= x_display_name_list
;
10611 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10613 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10615 XSETCDR (tail
, XCDR (XCDR (tail
)));
10618 tail
= XCDR (tail
);
10622 if (next_noop_dpyinfo
== dpyinfo
)
10623 next_noop_dpyinfo
= dpyinfo
->next
;
10625 if (x_display_list
== dpyinfo
)
10626 x_display_list
= dpyinfo
->next
;
10629 struct x_display_info
*tail
;
10631 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10632 if (tail
->next
== dpyinfo
)
10633 tail
->next
= tail
->next
->next
;
10636 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
10637 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
10638 XrmDestroyDatabase (dpyinfo
->xrdb
);
10641 #ifdef MULTI_KBOARD
10642 if (--dpyinfo
->kboard
->reference_count
== 0)
10643 delete_kboard (dpyinfo
->kboard
);
10647 xim_close_dpy (dpyinfo
);
10650 xfree (dpyinfo
->font_table
);
10651 xfree (dpyinfo
->x_id_name
);
10652 xfree (dpyinfo
->color_cells
);
10656 #ifdef USE_X_TOOLKIT
10658 /* Atimer callback function for TIMER. Called every 0.1s to process
10659 Xt timeouts, if needed. We must avoid calling XtAppPending as
10660 much as possible because that function does an implicit XFlush
10661 that slows us down. */
10664 x_process_timeouts (timer
)
10665 struct atimer
*timer
;
10667 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10670 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10671 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10676 #endif /* USE_X_TOOLKIT */
10679 /* Set up use of X before we make the first connection. */
10681 static struct redisplay_interface x_redisplay_interface
=
10686 x_clear_end_of_line
,
10688 x_after_update_window_line
,
10689 x_update_window_begin
,
10690 x_update_window_end
,
10696 0, /* flush_display_optional */
10698 x_clear_window_mouse_face
,
10699 x_get_glyph_overhangs
,
10700 x_fix_overlapping_area
,
10701 x_draw_fringe_bitmap
,
10704 x_compute_glyph_string_overhangs
,
10705 x_draw_glyph_string
,
10706 x_define_frame_cursor
,
10707 x_clear_frame_area
,
10708 x_draw_window_cursor
,
10709 x_draw_vertical_window_border
,
10710 x_shift_glyphs_for_insert
10716 rif
= &x_redisplay_interface
;
10718 clear_frame_hook
= x_clear_frame
;
10719 ins_del_lines_hook
= x_ins_del_lines
;
10720 delete_glyphs_hook
= x_delete_glyphs
;
10721 ring_bell_hook
= XTring_bell
;
10722 reset_terminal_modes_hook
= XTreset_terminal_modes
;
10723 set_terminal_modes_hook
= XTset_terminal_modes
;
10724 update_begin_hook
= x_update_begin
;
10725 update_end_hook
= x_update_end
;
10726 set_terminal_window_hook
= XTset_terminal_window
;
10727 read_socket_hook
= XTread_socket
;
10728 frame_up_to_date_hook
= XTframe_up_to_date
;
10729 mouse_position_hook
= XTmouse_position
;
10730 frame_rehighlight_hook
= XTframe_rehighlight
;
10731 frame_raise_lower_hook
= XTframe_raise_lower
;
10732 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10733 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10734 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10735 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10737 scroll_region_ok
= 1; /* we'll scroll partial frames */
10738 char_ins_del_ok
= 1;
10739 line_ins_del_ok
= 1; /* we'll just blt 'em */
10740 fast_clear_end_of_line
= 1; /* X does this well */
10741 memory_below_frame
= 0; /* we don't remember what scrolls
10746 last_tool_bar_item
= -1;
10747 any_help_event_p
= 0;
10749 /* Try to use interrupt input; if we can't, then start polling. */
10750 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
10752 #ifdef USE_X_TOOLKIT
10753 XtToolkitInitialize ();
10755 Xt_app_con
= XtCreateApplicationContext ();
10757 /* Register a converter from strings to pixels, which uses
10758 Emacs' color allocation infrastructure. */
10759 XtAppSetTypeConverter (Xt_app_con
,
10760 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10761 cvt_string_to_pixel_args
,
10762 XtNumber (cvt_string_to_pixel_args
),
10763 XtCacheByDisplay
, cvt_pixel_dtor
);
10765 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10767 /* Install an asynchronous timer that processes Xt timeout events
10768 every 0.1s. This is necessary because some widget sets use
10769 timeouts internally, for example the LessTif menu bar, or the
10770 Xaw3d scroll bar. When Xt timouts aren't processed, these
10771 widgets don't behave normally. */
10773 EMACS_TIME interval
;
10774 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10775 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
10779 #ifdef USE_TOOLKIT_SCROLL_BARS
10781 xaw3d_arrow_scroll
= False
;
10782 xaw3d_pick_top
= True
;
10786 /* Note that there is no real way portable across R3/R4 to get the
10787 original error handler. */
10788 XSetErrorHandler (x_error_handler
);
10789 XSetIOErrorHandler (x_io_error_quitter
);
10791 /* Disable Window Change signals; they are handled by X events. */
10793 signal (SIGWINCH
, SIG_DFL
);
10794 #endif /* SIGWINCH */
10796 signal (SIGPIPE
, x_connection_signal
);
10799 x_session_initialize ();
10807 staticpro (&x_error_message_string
);
10808 x_error_message_string
= Qnil
;
10810 staticpro (&x_display_name_list
);
10811 x_display_name_list
= Qnil
;
10813 staticpro (&last_mouse_scroll_bar
);
10814 last_mouse_scroll_bar
= Qnil
;
10816 staticpro (&Qvendor_specific_keysyms
);
10817 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
10819 staticpro (&Qutf_8
);
10820 Qutf_8
= intern ("utf-8");
10821 staticpro (&Qlatin_1
);
10822 Qlatin_1
= intern ("latin-1");
10824 staticpro (&last_mouse_press_frame
);
10825 last_mouse_press_frame
= Qnil
;
10827 DEFVAR_BOOL ("x-use-underline-position-properties",
10828 &x_use_underline_position_properties
,
10829 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10830 nil means ignore them. If you encounter fonts with bogus
10831 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10832 to 4.1, set this to nil. */);
10833 x_use_underline_position_properties
= 1;
10835 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10836 doc
: /* What X toolkit scroll bars Emacs uses.
10837 A value of nil means Emacs doesn't use X toolkit scroll bars.
10838 Otherwise, value is a symbol describing the X toolkit. */);
10839 #ifdef USE_TOOLKIT_SCROLL_BARS
10841 Vx_toolkit_scroll_bars
= intern ("motif");
10842 #elif defined HAVE_XAW3D
10843 Vx_toolkit_scroll_bars
= intern ("xaw3d");
10845 Vx_toolkit_scroll_bars
= intern ("gtk");
10847 Vx_toolkit_scroll_bars
= intern ("xaw");
10850 Vx_toolkit_scroll_bars
= Qnil
;
10853 staticpro (&last_mouse_motion_frame
);
10854 last_mouse_motion_frame
= Qnil
;
10856 Qmodifier_value
= intern ("modifier-value");
10857 Qalt
= intern ("alt");
10858 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10859 Qhyper
= intern ("hyper");
10860 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10861 Qmeta
= intern ("meta");
10862 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10863 Qsuper
= intern ("super");
10864 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10866 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
10867 doc
: /* Which keys Emacs uses for the alt modifier.
10868 This should be one of the symbols `alt', `hyper', `meta', `super'.
10869 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10870 is nil, which is the same as `alt'. */);
10871 Vx_alt_keysym
= Qnil
;
10873 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
10874 doc
: /* Which keys Emacs uses for the hyper modifier.
10875 This should be one of the symbols `alt', `hyper', `meta', `super'.
10876 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10877 default is nil, which is the same as `hyper'. */);
10878 Vx_hyper_keysym
= Qnil
;
10880 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
10881 doc
: /* Which keys Emacs uses for the meta modifier.
10882 This should be one of the symbols `alt', `hyper', `meta', `super'.
10883 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10884 default is nil, which is the same as `meta'. */);
10885 Vx_meta_keysym
= Qnil
;
10887 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
10888 doc
: /* Which keys Emacs uses for the super modifier.
10889 This should be one of the symbols `alt', `hyper', `meta', `super'.
10890 For example, `super' means use the Super_L and Super_R keysyms. The
10891 default is nil, which is the same as `super'. */);
10892 Vx_super_keysym
= Qnil
;
10894 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
10895 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10896 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10897 make_float (DEFAULT_REHASH_SIZE
),
10898 make_float (DEFAULT_REHASH_THRESHOLD
),
10902 #endif /* HAVE_X_WINDOWS */