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 INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
355 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
356 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
357 enum scroll_bar_part
*,
358 Lisp_Object
*, Lisp_Object
*,
360 static void x_check_fullscreen
P_ ((struct frame
*));
361 static void x_check_fullscreen_move
P_ ((struct frame
*));
362 static int handle_one_xevent
P_ ((struct x_display_info
*,
364 struct input_event
**,
369 /* Flush display of frame F, or of all frames if F is null. */
378 Lisp_Object rest
, frame
;
379 FOR_EACH_FRAME (rest
, frame
)
380 x_flush (XFRAME (frame
));
382 else if (FRAME_X_P (f
))
383 XFlush (FRAME_X_DISPLAY (f
));
388 /* Remove calls to XFlush by defining XFlush to an empty replacement.
389 Calls to XFlush should be unnecessary because the X output buffer
390 is flushed automatically as needed by calls to XPending,
391 XNextEvent, or XWindowEvent according to the XFlush man page.
392 XTread_socket calls XPending. Removing XFlush improves
395 #define XFlush(DISPLAY) (void) 0
398 /***********************************************************************
400 ***********************************************************************/
404 /* This is a function useful for recording debugging information about
405 the sequence of occurrences in this file. */
413 struct record event_record
[100];
415 int event_record_index
;
417 record_event (locus
, type
)
421 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
422 event_record_index
= 0;
424 event_record
[event_record_index
].locus
= locus
;
425 event_record
[event_record_index
].type
= type
;
426 event_record_index
++;
433 /* Return the struct x_display_info corresponding to DPY. */
435 struct x_display_info
*
436 x_display_info_for_display (dpy
)
439 struct x_display_info
*dpyinfo
;
441 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
442 if (dpyinfo
->display
== dpy
)
450 /***********************************************************************
451 Starting and ending an update
452 ***********************************************************************/
454 /* Start an update of frame F. This function is installed as a hook
455 for update_begin, i.e. it is called when update_begin is called.
456 This function is called prior to calls to x_update_window_begin for
457 each window being updated. Currently, there is nothing to do here
458 because all interesting stuff is done on a window basis. */
468 /* Start update of window W. Set the global variable updated_window
469 to the window being updated and set output_cursor to the cursor
473 x_update_window_begin (w
)
476 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
477 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
480 set_output_cursor (&w
->cursor
);
484 if (f
== display_info
->mouse_face_mouse_frame
)
486 /* Don't do highlighting for mouse motion during the update. */
487 display_info
->mouse_face_defer
= 1;
489 /* If F needs to be redrawn, simply forget about any prior mouse
491 if (FRAME_GARBAGED_P (f
))
492 display_info
->mouse_face_window
= Qnil
;
494 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
495 their mouse_face_p flag set, which means that they are always
496 unequal to rows in a desired matrix which never have that
497 flag set. So, rows containing mouse-face glyphs are never
498 scrolled, and we don't have to switch the mouse highlight off
499 here to prevent it from being scrolled. */
501 /* Can we tell that this update does not affect the window
502 where the mouse highlight is? If so, no need to turn off.
503 Likewise, don't do anything if the frame is garbaged;
504 in that case, the frame's current matrix that we would use
505 is all wrong, and we will redisplay that line anyway. */
506 if (!NILP (display_info
->mouse_face_window
)
507 && w
== XWINDOW (display_info
->mouse_face_window
))
511 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
512 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
515 if (i
< w
->desired_matrix
->nrows
)
516 clear_mouse_face (display_info
);
525 /* Draw a vertical window border from (x,y0) to (x,y1) */
528 x_draw_vertical_window_border (w
, x
, y0
, y1
)
532 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
534 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
535 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
538 /* End update of window W (which is equal to updated_window).
540 Draw vertical borders between horizontally adjacent windows, and
541 display W's cursor if CURSOR_ON_P is non-zero.
543 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
544 glyphs in mouse-face were overwritten. In that case we have to
545 make sure that the mouse-highlight is properly redrawn.
547 W may be a menu bar pseudo-window in case we don't have X toolkit
548 support. Such windows don't have a cursor, so don't display it
552 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
554 int cursor_on_p
, mouse_face_overwritten_p
;
556 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
558 if (!w
->pseudo_window_p
)
563 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
565 output_cursor
.x
, output_cursor
.y
);
567 x_draw_vertical_border (w
);
571 /* If a row with mouse-face was overwritten, arrange for
572 XTframe_up_to_date to redisplay the mouse highlight. */
573 if (mouse_face_overwritten_p
)
575 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
576 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
577 dpyinfo
->mouse_face_window
= Qnil
;
580 updated_window
= NULL
;
584 /* End update of frame F. This function is installed as a hook in
591 /* Mouse highlight may be displayed again. */
592 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
596 XFlush (FRAME_X_DISPLAY (f
));
602 /* This function is called from various places in xdisp.c whenever a
603 complete update has been performed. The global variable
604 updated_window is not available here. */
607 XTframe_up_to_date (f
)
612 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
614 if (dpyinfo
->mouse_face_deferred_gc
615 || f
== dpyinfo
->mouse_face_mouse_frame
)
618 if (dpyinfo
->mouse_face_mouse_frame
)
619 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
620 dpyinfo
->mouse_face_mouse_x
,
621 dpyinfo
->mouse_face_mouse_y
);
622 dpyinfo
->mouse_face_deferred_gc
= 0;
629 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
630 arrow bitmaps, or clear the fringes if no bitmaps are required
631 before DESIRED_ROW is made current. The window being updated is
632 found in updated_window. This function It is called from
633 update_window_line only if it is known that there are differences
634 between bitmaps to be drawn between current row and DESIRED_ROW. */
637 x_after_update_window_line (desired_row
)
638 struct glyph_row
*desired_row
;
640 struct window
*w
= updated_window
;
646 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
649 draw_row_fringe_bitmaps (w
, desired_row
);
653 /* When a window has disappeared, make sure that no rest of
654 full-width rows stays visible in the internal border. Could
655 check here if updated_window is the leftmost/rightmost window,
656 but I guess it's not worth doing since vertically split windows
657 are almost never used, internal border is rarely set, and the
658 overhead is very small. */
659 if (windows_or_buffers_changed
660 && desired_row
->full_width_p
661 && (f
= XFRAME (w
->frame
),
662 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
664 && (height
= desired_row
->visible_height
,
667 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
669 /* Internal border is drawn below the tool bar. */
670 if (WINDOWP (f
->tool_bar_window
)
671 && w
== XWINDOW (f
->tool_bar_window
))
675 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
676 0, y
, width
, height
, False
);
677 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
678 f
->output_data
.x
->pixel_width
- width
,
679 y
, width
, height
, False
);
685 x_draw_fringe_bitmap (w
, row
, p
)
687 struct glyph_row
*row
;
688 struct draw_fringe_bitmap_params
*p
;
690 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
691 Display
*display
= FRAME_X_DISPLAY (f
);
692 Window window
= FRAME_X_WINDOW (f
);
693 GC gc
= f
->output_data
.x
->normal_gc
;
694 struct face
*face
= p
->face
;
696 /* Must clip because of partially visible lines. */
697 x_clip_to_row (w
, row
, gc
, 1);
701 /* In case the same realized face is used for fringes and
702 for something displayed in the text (e.g. face `region' on
703 mono-displays, the fill style may have been changed to
704 FillSolid in x_draw_glyph_string_background. */
706 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
708 XSetForeground (display
, face
->gc
, face
->background
);
710 XFillRectangle (display
, window
, face
->gc
,
711 p
->bx
, p
->by
, p
->nx
, p
->ny
);
714 XSetForeground (display
, face
->gc
, face
->foreground
);
717 if (p
->which
!= NO_FRINGE_BITMAP
)
719 unsigned char *bits
= fringe_bitmaps
[p
->which
].bits
+ p
->dh
;
721 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
723 /* Draw the bitmap. I believe these small pixmaps can be cached
725 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
727 face
->background
, depth
);
728 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
729 p
->wd
, p
->h
, p
->x
, p
->y
);
730 XFreePixmap (display
, pixmap
);
733 XSetClipMask (display
, gc
, None
);
738 /* This is called when starting Emacs and when restarting after
739 suspend. When starting Emacs, no X window is mapped. And nothing
740 must be done to Emacs's own window if it is suspended (though that
744 XTset_terminal_modes ()
748 /* This is called when exiting or suspending Emacs. Exiting will make
749 the X-windows go away, and suspending requires no action. */
752 XTreset_terminal_modes ()
758 /***********************************************************************
760 ***********************************************************************/
762 /* Function prototypes of this page. */
764 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
767 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
768 is not contained in the font. */
771 x_per_char_metric (font
, char2b
, font_type
)
774 int font_type
; /* unused on X */
776 /* The result metric information. */
777 XCharStruct
*pcm
= NULL
;
779 xassert (font
&& char2b
);
781 if (font
->per_char
!= NULL
)
783 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
785 /* min_char_or_byte2 specifies the linear character index
786 corresponding to the first element of the per_char array,
787 max_char_or_byte2 is the index of the last character. A
788 character with non-zero CHAR2B->byte1 is not in the font.
789 A character with byte2 less than min_char_or_byte2 or
790 greater max_char_or_byte2 is not in the font. */
791 if (char2b
->byte1
== 0
792 && char2b
->byte2
>= font
->min_char_or_byte2
793 && char2b
->byte2
<= font
->max_char_or_byte2
)
794 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
798 /* If either min_byte1 or max_byte1 are nonzero, both
799 min_char_or_byte2 and max_char_or_byte2 are less than
800 256, and the 2-byte character index values corresponding
801 to the per_char array element N (counting from 0) are:
803 byte1 = N/D + min_byte1
804 byte2 = N\D + min_char_or_byte2
808 D = max_char_or_byte2 - min_char_or_byte2 + 1
810 \ = integer modulus */
811 if (char2b
->byte1
>= font
->min_byte1
812 && char2b
->byte1
<= font
->max_byte1
813 && char2b
->byte2
>= font
->min_char_or_byte2
814 && char2b
->byte2
<= font
->max_char_or_byte2
)
816 pcm
= (font
->per_char
817 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
818 * (char2b
->byte1
- font
->min_byte1
))
819 + (char2b
->byte2
- font
->min_char_or_byte2
));
825 /* If the per_char pointer is null, all glyphs between the first
826 and last character indexes inclusive have the same
827 information, as given by both min_bounds and max_bounds. */
828 if (char2b
->byte2
>= font
->min_char_or_byte2
829 && char2b
->byte2
<= font
->max_char_or_byte2
)
830 pcm
= &font
->max_bounds
;
834 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
839 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
840 the two-byte form of C. Encoding is returned in *CHAR2B. */
843 x_encode_char (c
, char2b
, font_info
, two_byte_p
)
846 struct font_info
*font_info
;
849 int charset
= CHAR_CHARSET (c
);
850 XFontStruct
*font
= font_info
->font
;
852 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
853 This may be either a program in a special encoder language or a
855 if (font_info
->font_encoder
)
857 /* It's a program. */
858 struct ccl_program
*ccl
= font_info
->font_encoder
;
860 if (CHARSET_DIMENSION (charset
) == 1)
862 ccl
->reg
[0] = charset
;
863 ccl
->reg
[1] = char2b
->byte2
;
868 ccl
->reg
[0] = charset
;
869 ccl
->reg
[1] = char2b
->byte1
;
870 ccl
->reg
[2] = char2b
->byte2
;
873 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
875 /* We assume that MSBs are appropriately set/reset by CCL
877 if (font
->max_byte1
== 0) /* 1-byte font */
878 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
880 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
882 else if (font_info
->encoding
[charset
])
884 /* Fixed encoding scheme. See fontset.h for the meaning of the
886 int enc
= font_info
->encoding
[charset
];
888 if ((enc
== 1 || enc
== 2)
889 && CHARSET_DIMENSION (charset
) == 2)
890 char2b
->byte1
|= 0x80;
892 if (enc
== 1 || enc
== 3)
893 char2b
->byte2
|= 0x80;
897 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
899 return FONT_TYPE_UNKNOWN
;
904 /***********************************************************************
906 ***********************************************************************/
910 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
911 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
912 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
914 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
915 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
916 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
917 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
918 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
919 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
920 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
921 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
922 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
923 unsigned long *, double, int));
924 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
925 double, int, unsigned long));
926 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
927 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
928 static void x_draw_image_relief
P_ ((struct glyph_string
*));
929 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
930 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
931 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
933 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
934 int, int, int, int, XRectangle
*));
935 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
936 int, int, int, XRectangle
*));
939 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
943 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
948 struct glyph_string
*s
;
950 if (s
->font
== FRAME_FONT (s
->f
)
951 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
952 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
954 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
957 /* Cursor on non-default face: must merge. */
961 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
962 xgcv
.foreground
= s
->face
->background
;
964 /* If the glyph would be invisible, try a different foreground. */
965 if (xgcv
.foreground
== xgcv
.background
)
966 xgcv
.foreground
= s
->face
->foreground
;
967 if (xgcv
.foreground
== xgcv
.background
)
968 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
969 if (xgcv
.foreground
== xgcv
.background
)
970 xgcv
.foreground
= s
->face
->foreground
;
972 /* Make sure the cursor is distinct from text in this face. */
973 if (xgcv
.background
== s
->face
->background
974 && xgcv
.foreground
== s
->face
->foreground
)
976 xgcv
.background
= s
->face
->foreground
;
977 xgcv
.foreground
= s
->face
->background
;
980 IF_DEBUG (x_check_font (s
->f
, s
->font
));
981 xgcv
.font
= s
->font
->fid
;
982 xgcv
.graphics_exposures
= False
;
983 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
985 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
986 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
989 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
990 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
992 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
997 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1000 x_set_mouse_face_gc (s
)
1001 struct glyph_string
*s
;
1006 /* What face has to be used last for the mouse face? */
1007 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1008 face
= FACE_FROM_ID (s
->f
, face_id
);
1010 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1012 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1013 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
1015 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
1016 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1017 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1019 /* If font in this face is same as S->font, use it. */
1020 if (s
->font
== s
->face
->font
)
1021 s
->gc
= s
->face
->gc
;
1024 /* Otherwise construct scratch_cursor_gc with values from FACE
1029 xgcv
.background
= s
->face
->background
;
1030 xgcv
.foreground
= s
->face
->foreground
;
1031 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1032 xgcv
.font
= s
->font
->fid
;
1033 xgcv
.graphics_exposures
= False
;
1034 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1036 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1037 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1040 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1041 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1043 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1046 xassert (s
->gc
!= 0);
1050 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1051 Faces to use in the mode line have already been computed when the
1052 matrix was built, so there isn't much to do, here. */
1055 x_set_mode_line_face_gc (s
)
1056 struct glyph_string
*s
;
1058 s
->gc
= s
->face
->gc
;
1062 /* Set S->gc of glyph string S for drawing that glyph string. Set
1063 S->stippled_p to a non-zero value if the face of S has a stipple
1067 x_set_glyph_string_gc (s
)
1068 struct glyph_string
*s
;
1070 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1072 if (s
->hl
== DRAW_NORMAL_TEXT
)
1074 s
->gc
= s
->face
->gc
;
1075 s
->stippled_p
= s
->face
->stipple
!= 0;
1077 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1079 x_set_mode_line_face_gc (s
);
1080 s
->stippled_p
= s
->face
->stipple
!= 0;
1082 else if (s
->hl
== DRAW_CURSOR
)
1084 x_set_cursor_gc (s
);
1087 else if (s
->hl
== DRAW_MOUSE_FACE
)
1089 x_set_mouse_face_gc (s
);
1090 s
->stippled_p
= s
->face
->stipple
!= 0;
1092 else if (s
->hl
== DRAW_IMAGE_RAISED
1093 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1095 s
->gc
= s
->face
->gc
;
1096 s
->stippled_p
= s
->face
->stipple
!= 0;
1100 s
->gc
= s
->face
->gc
;
1101 s
->stippled_p
= s
->face
->stipple
!= 0;
1104 /* GC must have been set. */
1105 xassert (s
->gc
!= 0);
1109 /* Set clipping for output of glyph string S. S may be part of a mode
1110 line or menu if we don't have X toolkit support. */
1113 x_set_glyph_string_clipping (s
)
1114 struct glyph_string
*s
;
1117 get_glyph_string_clip_rect (s
, &r
);
1118 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
1123 Compute left and right overhang of glyph string S. If S is a glyph
1124 string for a composition, assume overhangs don't exist. */
1127 x_compute_glyph_string_overhangs (s
)
1128 struct glyph_string
*s
;
1131 && s
->first_glyph
->type
== CHAR_GLYPH
)
1134 int direction
, font_ascent
, font_descent
;
1135 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1136 &font_ascent
, &font_descent
, &cs
);
1137 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1138 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1143 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1146 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1147 struct glyph_string
*s
;
1151 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1152 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1153 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1154 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1158 /* Draw the background of glyph_string S. If S->background_filled_p
1159 is non-zero don't draw it. FORCE_P non-zero means draw the
1160 background even if it wouldn't be drawn normally. This is used
1161 when a string preceding S draws into the background of S, or S
1162 contains the first component of a composition. */
1165 x_draw_glyph_string_background (s
, force_p
)
1166 struct glyph_string
*s
;
1169 /* Nothing to do if background has already been drawn or if it
1170 shouldn't be drawn in the first place. */
1171 if (!s
->background_filled_p
)
1173 int box_line_width
= max (s
->face
->box_line_width
, 0);
1177 /* Fill background with a stipple pattern. */
1178 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1179 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1180 s
->y
+ box_line_width
,
1181 s
->background_width
,
1182 s
->height
- 2 * box_line_width
);
1183 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1184 s
->background_filled_p
= 1;
1186 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1187 || s
->font_not_found_p
1188 || s
->extends_to_end_of_line_p
1191 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1192 s
->background_width
,
1193 s
->height
- 2 * box_line_width
);
1194 s
->background_filled_p
= 1;
1200 /* Draw the foreground of glyph string S. */
1203 x_draw_glyph_string_foreground (s
)
1204 struct glyph_string
*s
;
1208 /* If first glyph of S has a left box line, start drawing the text
1209 of S to the right of that box line. */
1210 if (s
->face
->box
!= FACE_NO_BOX
1211 && s
->first_glyph
->left_box_line_p
)
1212 x
= s
->x
+ abs (s
->face
->box_line_width
);
1216 /* Draw characters of S as rectangles if S's font could not be
1218 if (s
->font_not_found_p
)
1220 for (i
= 0; i
< s
->nchars
; ++i
)
1222 struct glyph
*g
= s
->first_glyph
+ i
;
1223 XDrawRectangle (s
->display
, s
->window
,
1224 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1226 x
+= g
->pixel_width
;
1231 char *char1b
= (char *) s
->char2b
;
1232 int boff
= s
->font_info
->baseline_offset
;
1234 if (s
->font_info
->vertical_centering
)
1235 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1237 /* If we can use 8-bit functions, condense S->char2b. */
1239 for (i
= 0; i
< s
->nchars
; ++i
)
1240 char1b
[i
] = s
->char2b
[i
].byte2
;
1242 /* Draw text with XDrawString if background has already been
1243 filled. Otherwise, use XDrawImageString. (Note that
1244 XDrawImageString is usually faster than XDrawString.) Always
1245 use XDrawImageString when drawing the cursor so that there is
1246 no chance that characters under a box cursor are invisible. */
1247 if (s
->for_overlaps_p
1248 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1250 /* Draw characters with 16-bit or 8-bit functions. */
1252 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1253 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1255 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1256 s
->ybase
- boff
, char1b
, s
->nchars
);
1261 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1262 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1264 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1265 s
->ybase
- boff
, char1b
, s
->nchars
);
1268 if (s
->face
->overstrike
)
1270 /* For overstriking (to simulate bold-face), draw the
1271 characters again shifted to the right by one pixel. */
1273 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1274 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1276 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1277 s
->ybase
- boff
, char1b
, s
->nchars
);
1282 /* Draw the foreground of composite glyph string S. */
1285 x_draw_composite_glyph_string_foreground (s
)
1286 struct glyph_string
*s
;
1290 /* If first glyph of S has a left box line, start drawing the text
1291 of S to the right of that box line. */
1292 if (s
->face
->box
!= FACE_NO_BOX
1293 && s
->first_glyph
->left_box_line_p
)
1294 x
= s
->x
+ abs (s
->face
->box_line_width
);
1298 /* S is a glyph string for a composition. S->gidx is the index of
1299 the first character drawn for glyphs of this composition.
1300 S->gidx == 0 means we are drawing the very first character of
1301 this composition. */
1303 /* Draw a rectangle for the composition if the font for the very
1304 first character of the composition could not be loaded. */
1305 if (s
->font_not_found_p
)
1308 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1309 s
->width
- 1, s
->height
- 1);
1313 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
1315 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1316 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
1317 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1319 if (s
->face
->overstrike
)
1320 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1321 x
+ s
->cmp
->offsets
[s
->gidx
* 2] + 1,
1322 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1329 #ifdef USE_X_TOOLKIT
1331 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1332 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1333 XrmValue
*, XrmValue
*, XtPointer
*));
1334 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1335 XrmValue
*, Cardinal
*));
1338 /* Return the frame on which widget WIDGET is used.. Abort if frame
1339 cannot be determined. */
1341 static struct frame
*
1342 x_frame_of_widget (widget
)
1345 struct x_display_info
*dpyinfo
;
1349 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1351 /* Find the top-level shell of the widget. Note that this function
1352 can be called when the widget is not yet realized, so XtWindow
1353 (widget) == 0. That's the reason we can't simply use
1354 x_any_window_to_frame. */
1355 while (!XtIsTopLevelShell (widget
))
1356 widget
= XtParent (widget
);
1358 /* Look for a frame with that top-level widget. Allocate the color
1359 on that frame to get the right gamma correction value. */
1360 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
1361 if (GC_FRAMEP (XCAR (tail
))
1362 && (f
= XFRAME (XCAR (tail
)),
1363 (f
->output_data
.nothing
!= 1
1364 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1365 && f
->output_data
.x
->widget
== widget
)
1372 /* Allocate the color COLOR->pixel on the screen and display of
1373 widget WIDGET in colormap CMAP. If an exact match cannot be
1374 allocated, try the nearest color available. Value is non-zero
1375 if successful. This is called from lwlib. */
1378 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1383 struct frame
*f
= x_frame_of_widget (widget
);
1384 return x_alloc_nearest_color (f
, cmap
, color
);
1388 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1389 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1390 If this produces the same color as PIXEL, try a color where all RGB
1391 values have DELTA added. Return the allocated color in *PIXEL.
1392 DISPLAY is the X display, CMAP is the colormap to operate on.
1393 Value is non-zero if successful. */
1396 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1400 unsigned long *pixel
;
1404 struct frame
*f
= x_frame_of_widget (widget
);
1405 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1409 /* Structure specifying which arguments should be passed by Xt to
1410 cvt_string_to_pixel. We want the widget's screen and colormap. */
1412 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1414 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1416 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1421 /* The address of this variable is returned by
1422 cvt_string_to_pixel. */
1424 static Pixel cvt_string_to_pixel_value
;
1427 /* Convert a color name to a pixel color.
1429 DPY is the display we are working on.
1431 ARGS is an array of *NARGS XrmValue structures holding additional
1432 information about the widget for which the conversion takes place.
1433 The contents of this array are determined by the specification
1434 in cvt_string_to_pixel_args.
1436 FROM is a pointer to an XrmValue which points to the color name to
1437 convert. TO is an XrmValue in which to return the pixel color.
1439 CLOSURE_RET is a pointer to user-data, in which we record if
1440 we allocated the color or not.
1442 Value is True if successful, False otherwise. */
1445 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1449 XrmValue
*from
, *to
;
1450 XtPointer
*closure_ret
;
1460 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1461 "wrongParameters", "cvt_string_to_pixel",
1463 "Screen and colormap args required", NULL
, NULL
);
1467 screen
= *(Screen
**) args
[0].addr
;
1468 cmap
= *(Colormap
*) args
[1].addr
;
1469 color_name
= (String
) from
->addr
;
1471 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1473 *closure_ret
= (XtPointer
) False
;
1474 pixel
= WhitePixelOfScreen (screen
);
1476 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1478 *closure_ret
= (XtPointer
) False
;
1479 pixel
= BlackPixelOfScreen (screen
);
1481 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1482 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1484 pixel
= color
.pixel
;
1485 *closure_ret
= (XtPointer
) True
;
1490 Cardinal nparams
= 1;
1492 params
[0] = color_name
;
1493 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1494 "badValue", "cvt_string_to_pixel",
1495 "XtToolkitError", "Invalid color `%s'",
1500 if (to
->addr
!= NULL
)
1502 if (to
->size
< sizeof (Pixel
))
1504 to
->size
= sizeof (Pixel
);
1508 *(Pixel
*) to
->addr
= pixel
;
1512 cvt_string_to_pixel_value
= pixel
;
1513 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1516 to
->size
= sizeof (Pixel
);
1521 /* Free a pixel color which was previously allocated via
1522 cvt_string_to_pixel. This is registered as the destructor
1523 for this type of resource via XtSetTypeConverter.
1525 APP is the application context in which we work.
1527 TO is a pointer to an XrmValue holding the color to free.
1528 CLOSURE is the value we stored in CLOSURE_RET for this color
1529 in cvt_string_to_pixel.
1531 ARGS and NARGS are like for cvt_string_to_pixel. */
1534 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1543 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1545 "Screen and colormap arguments required",
1548 else if (closure
!= NULL
)
1550 /* We did allocate the pixel, so free it. */
1551 Screen
*screen
= *(Screen
**) args
[0].addr
;
1552 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1553 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1554 (Pixel
*) to
->addr
, 1);
1559 #endif /* USE_X_TOOLKIT */
1562 /* Value is an array of XColor structures for the contents of the
1563 color map of display DPY. Set *NCELLS to the size of the array.
1564 Note that this probably shouldn't be called for large color maps,
1565 say a 24-bit TrueColor map. */
1567 static const XColor
*
1568 x_color_cells (dpy
, ncells
)
1572 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1574 if (dpyinfo
->color_cells
== NULL
)
1576 Screen
*screen
= dpyinfo
->screen
;
1579 dpyinfo
->ncolor_cells
1580 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1581 dpyinfo
->color_cells
1582 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1583 * sizeof *dpyinfo
->color_cells
);
1585 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1586 dpyinfo
->color_cells
[i
].pixel
= i
;
1588 XQueryColors (dpy
, dpyinfo
->cmap
,
1589 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1592 *ncells
= dpyinfo
->ncolor_cells
;
1593 return dpyinfo
->color_cells
;
1597 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1598 colors in COLORS. Use cached information, if available. */
1601 x_query_colors (f
, colors
, ncolors
)
1606 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1608 if (dpyinfo
->color_cells
)
1611 for (i
= 0; i
< ncolors
; ++i
)
1613 unsigned long pixel
= colors
[i
].pixel
;
1614 xassert (pixel
< dpyinfo
->ncolor_cells
);
1615 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1616 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1620 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1624 /* On frame F, translate pixel color to RGB values for the color in
1625 COLOR. Use cached information, if available. */
1628 x_query_color (f
, color
)
1632 x_query_colors (f
, color
, 1);
1636 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1637 exact match can't be allocated, try the nearest color available.
1638 Value is non-zero if successful. Set *COLOR to the color
1642 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1649 rc
= XAllocColor (dpy
, cmap
, color
);
1652 /* If we got to this point, the colormap is full, so we're going
1653 to try to get the next closest color. The algorithm used is
1654 a least-squares matching, which is what X uses for closest
1655 color matching with StaticColor visuals. */
1657 unsigned long nearest_delta
= ~0;
1659 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1661 for (nearest
= i
= 0; i
< ncells
; ++i
)
1663 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1664 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1665 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1666 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1668 if (delta
< nearest_delta
)
1671 nearest_delta
= delta
;
1675 color
->red
= cells
[nearest
].red
;
1676 color
->green
= cells
[nearest
].green
;
1677 color
->blue
= cells
[nearest
].blue
;
1678 rc
= XAllocColor (dpy
, cmap
, color
);
1682 /* If allocation succeeded, and the allocated pixel color is not
1683 equal to a cached pixel color recorded earlier, there was a
1684 change in the colormap, so clear the color cache. */
1685 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1686 XColor
*cached_color
;
1688 if (dpyinfo
->color_cells
1689 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1690 (cached_color
->red
!= color
->red
1691 || cached_color
->blue
!= color
->blue
1692 || cached_color
->green
!= color
->green
)))
1694 xfree (dpyinfo
->color_cells
);
1695 dpyinfo
->color_cells
= NULL
;
1696 dpyinfo
->ncolor_cells
= 0;
1700 #ifdef DEBUG_X_COLORS
1702 register_color (color
->pixel
);
1703 #endif /* DEBUG_X_COLORS */
1709 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1710 exact match can't be allocated, try the nearest color available.
1711 Value is non-zero if successful. Set *COLOR to the color
1715 x_alloc_nearest_color (f
, cmap
, color
)
1720 gamma_correct (f
, color
);
1721 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1725 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1726 It's necessary to do this instead of just using PIXEL directly to
1727 get color reference counts right. */
1730 x_copy_color (f
, pixel
)
1732 unsigned long pixel
;
1736 color
.pixel
= pixel
;
1738 x_query_color (f
, &color
);
1739 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1741 #ifdef DEBUG_X_COLORS
1742 register_color (pixel
);
1748 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1749 It's necessary to do this instead of just using PIXEL directly to
1750 get color reference counts right. */
1753 x_copy_dpy_color (dpy
, cmap
, pixel
)
1756 unsigned long pixel
;
1760 color
.pixel
= pixel
;
1762 XQueryColor (dpy
, cmap
, &color
);
1763 XAllocColor (dpy
, cmap
, &color
);
1765 #ifdef DEBUG_X_COLORS
1766 register_color (pixel
);
1772 /* Brightness beyond which a color won't have its highlight brightness
1775 Nominally, highlight colors for `3d' faces are calculated by
1776 brightening an object's color by a constant scale factor, but this
1777 doesn't yield good results for dark colors, so for colors who's
1778 brightness is less than this value (on a scale of 0-65535) have an
1779 use an additional additive factor.
1781 The value here is set so that the default menu-bar/mode-line color
1782 (grey75) will not have its highlights changed at all. */
1783 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1786 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1787 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1788 If this produces the same color as PIXEL, try a color where all RGB
1789 values have DELTA added. Return the allocated color in *PIXEL.
1790 DISPLAY is the X display, CMAP is the colormap to operate on.
1791 Value is non-zero if successful. */
1794 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
1798 unsigned long *pixel
;
1806 /* Get RGB color values. */
1807 color
.pixel
= *pixel
;
1808 x_query_color (f
, &color
);
1810 /* Change RGB values by specified FACTOR. Avoid overflow! */
1811 xassert (factor
>= 0);
1812 new.red
= min (0xffff, factor
* color
.red
);
1813 new.green
= min (0xffff, factor
* color
.green
);
1814 new.blue
= min (0xffff, factor
* color
.blue
);
1816 /* Calculate brightness of COLOR. */
1817 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1819 /* We only boost colors that are darker than
1820 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1821 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1822 /* Make an additive adjustment to NEW, because it's dark enough so
1823 that scaling by FACTOR alone isn't enough. */
1825 /* How far below the limit this color is (0 - 1, 1 being darker). */
1826 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1827 /* The additive adjustment. */
1828 int min_delta
= delta
* dimness
* factor
/ 2;
1832 new.red
= max (0, new.red
- min_delta
);
1833 new.green
= max (0, new.green
- min_delta
);
1834 new.blue
= max (0, new.blue
- min_delta
);
1838 new.red
= min (0xffff, min_delta
+ new.red
);
1839 new.green
= min (0xffff, min_delta
+ new.green
);
1840 new.blue
= min (0xffff, min_delta
+ new.blue
);
1844 /* Try to allocate the color. */
1845 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1848 if (new.pixel
== *pixel
)
1850 /* If we end up with the same color as before, try adding
1851 delta to the RGB values. */
1852 x_free_colors (f
, &new.pixel
, 1);
1854 new.red
= min (0xffff, delta
+ color
.red
);
1855 new.green
= min (0xffff, delta
+ color
.green
);
1856 new.blue
= min (0xffff, delta
+ color
.blue
);
1857 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1868 /* Set up the foreground color for drawing relief lines of glyph
1869 string S. RELIEF is a pointer to a struct relief containing the GC
1870 with which lines will be drawn. Use a color that is FACTOR or
1871 DELTA lighter or darker than the relief's background which is found
1872 in S->f->output_data.x->relief_background. If such a color cannot
1873 be allocated, use DEFAULT_PIXEL, instead. */
1876 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1878 struct relief
*relief
;
1881 unsigned long default_pixel
;
1884 struct x_output
*di
= f
->output_data
.x
;
1885 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1886 unsigned long pixel
;
1887 unsigned long background
= di
->relief_background
;
1888 Colormap cmap
= FRAME_X_COLORMAP (f
);
1889 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1890 Display
*dpy
= FRAME_X_DISPLAY (f
);
1892 xgcv
.graphics_exposures
= False
;
1893 xgcv
.line_width
= 1;
1895 /* Free previously allocated color. The color cell will be reused
1896 when it has been freed as many times as it was allocated, so this
1897 doesn't affect faces using the same colors. */
1899 && relief
->allocated_p
)
1901 x_free_colors (f
, &relief
->pixel
, 1);
1902 relief
->allocated_p
= 0;
1905 /* Allocate new color. */
1906 xgcv
.foreground
= default_pixel
;
1908 if (dpyinfo
->n_planes
!= 1
1909 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1911 relief
->allocated_p
= 1;
1912 xgcv
.foreground
= relief
->pixel
= pixel
;
1915 if (relief
->gc
== 0)
1917 xgcv
.stipple
= dpyinfo
->gray
;
1919 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1922 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1926 /* Set up colors for the relief lines around glyph string S. */
1929 x_setup_relief_colors (s
)
1930 struct glyph_string
*s
;
1932 struct x_output
*di
= s
->f
->output_data
.x
;
1933 unsigned long color
;
1935 if (s
->face
->use_box_color_for_shadows_p
)
1936 color
= s
->face
->box_color
;
1937 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1939 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1940 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1945 /* Get the background color of the face. */
1946 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1947 color
= xgcv
.background
;
1950 if (di
->white_relief
.gc
== 0
1951 || color
!= di
->relief_background
)
1953 di
->relief_background
= color
;
1954 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1955 WHITE_PIX_DEFAULT (s
->f
));
1956 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1957 BLACK_PIX_DEFAULT (s
->f
));
1962 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1963 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1964 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1965 relief. LEFT_P non-zero means draw a relief on the left side of
1966 the rectangle. RIGHT_P non-zero means draw a relief on the right
1967 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1971 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
1972 raised_p
, left_p
, right_p
, clip_rect
)
1974 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
, raised_p
;
1975 XRectangle
*clip_rect
;
1977 Display
*dpy
= FRAME_X_DISPLAY (f
);
1978 Window window
= FRAME_X_WINDOW (f
);
1983 gc
= f
->output_data
.x
->white_relief
.gc
;
1985 gc
= f
->output_data
.x
->black_relief
.gc
;
1986 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1989 for (i
= 0; i
< width
; ++i
)
1990 XDrawLine (dpy
, window
, gc
,
1991 left_x
+ i
* left_p
, top_y
+ i
,
1992 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1996 for (i
= 0; i
< width
; ++i
)
1997 XDrawLine (dpy
, window
, gc
,
1998 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2000 XSetClipMask (dpy
, gc
, None
);
2002 gc
= f
->output_data
.x
->black_relief
.gc
;
2004 gc
= f
->output_data
.x
->white_relief
.gc
;
2005 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2008 for (i
= 0; i
< width
; ++i
)
2009 XDrawLine (dpy
, window
, gc
,
2010 left_x
+ i
* left_p
, bottom_y
- i
,
2011 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2015 for (i
= 0; i
< width
; ++i
)
2016 XDrawLine (dpy
, window
, gc
,
2017 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2019 XSetClipMask (dpy
, gc
, None
);
2023 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2024 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2025 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2026 left side of the rectangle. RIGHT_P non-zero means draw a line
2027 on the right side of the rectangle. CLIP_RECT is the clipping
2028 rectangle to use when drawing. */
2031 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2032 left_p
, right_p
, clip_rect
)
2033 struct glyph_string
*s
;
2034 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2035 XRectangle
*clip_rect
;
2039 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2040 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2041 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2044 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2045 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2049 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2050 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2053 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2054 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2058 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2059 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2061 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2062 XSetClipMask (s
->display
, s
->gc
, None
);
2066 /* Draw a box around glyph string S. */
2069 x_draw_glyph_string_box (s
)
2070 struct glyph_string
*s
;
2072 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2073 int left_p
, right_p
;
2074 struct glyph
*last_glyph
;
2075 XRectangle clip_rect
;
2077 last_x
= window_box_right (s
->w
, s
->area
);
2078 if (s
->row
->full_width_p
2079 && !s
->w
->pseudo_window_p
)
2081 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
2082 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
2083 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
2086 /* The glyph that may have a right box line. */
2087 last_glyph
= (s
->cmp
|| s
->img
2089 : s
->first_glyph
+ s
->nchars
- 1);
2091 width
= abs (s
->face
->box_line_width
);
2092 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2094 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2096 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2098 bottom_y
= top_y
+ s
->height
- 1;
2100 left_p
= (s
->first_glyph
->left_box_line_p
2101 || (s
->hl
== DRAW_MOUSE_FACE
2103 || s
->prev
->hl
!= s
->hl
)));
2104 right_p
= (last_glyph
->right_box_line_p
2105 || (s
->hl
== DRAW_MOUSE_FACE
2107 || s
->next
->hl
!= s
->hl
)));
2109 get_glyph_string_clip_rect (s
, &clip_rect
);
2111 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2112 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2113 left_p
, right_p
, &clip_rect
);
2116 x_setup_relief_colors (s
);
2117 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2118 width
, raised_p
, left_p
, right_p
, &clip_rect
);
2123 /* Draw foreground of image glyph string S. */
2126 x_draw_image_foreground (s
)
2127 struct glyph_string
*s
;
2130 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
2132 /* If first glyph of S has a left box line, start drawing it to the
2133 right of that line. */
2134 if (s
->face
->box
!= FACE_NO_BOX
2135 && s
->first_glyph
->left_box_line_p
)
2136 x
= s
->x
+ abs (s
->face
->box_line_width
);
2140 /* If there is a margin around the image, adjust x- and y-position
2142 x
+= s
->img
->hmargin
;
2143 y
+= s
->img
->vmargin
;
2149 /* We can't set both a clip mask and use XSetClipRectangles
2150 because the latter also sets a clip mask. We also can't
2151 trust on the shape extension to be available
2152 (XShapeCombineRegion). So, compute the rectangle to draw
2154 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2157 XRectangle clip_rect
, image_rect
, r
;
2159 xgcv
.clip_mask
= s
->img
->mask
;
2160 xgcv
.clip_x_origin
= x
;
2161 xgcv
.clip_y_origin
= y
;
2162 xgcv
.function
= GXcopy
;
2163 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2165 get_glyph_string_clip_rect (s
, &clip_rect
);
2168 image_rect
.width
= s
->img
->width
;
2169 image_rect
.height
= s
->img
->height
;
2170 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2171 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2172 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
2176 XRectangle clip_rect
, image_rect
, r
;
2178 get_glyph_string_clip_rect (s
, &clip_rect
);
2181 image_rect
.width
= s
->img
->width
;
2182 image_rect
.height
= s
->img
->height
;
2183 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2184 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2185 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
2187 /* When the image has a mask, we can expect that at
2188 least part of a mouse highlight or a block cursor will
2189 be visible. If the image doesn't have a mask, make
2190 a block cursor visible by drawing a rectangle around
2191 the image. I believe it's looking better if we do
2192 nothing here for mouse-face. */
2193 if (s
->hl
== DRAW_CURSOR
)
2195 int r
= s
->img
->relief
;
2197 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2198 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
2203 /* Draw a rectangle if image could not be loaded. */
2204 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2205 s
->img
->width
- 1, s
->img
->height
- 1);
2209 /* Draw a relief around the image glyph string S. */
2212 x_draw_image_relief (s
)
2213 struct glyph_string
*s
;
2215 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2218 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
2220 /* If first glyph of S has a left box line, start drawing it to the
2221 right of that line. */
2222 if (s
->face
->box
!= FACE_NO_BOX
2223 && s
->first_glyph
->left_box_line_p
)
2224 x
= s
->x
+ abs (s
->face
->box_line_width
);
2228 /* If there is a margin around the image, adjust x- and y-position
2230 x
+= s
->img
->hmargin
;
2231 y
+= s
->img
->vmargin
;
2233 if (s
->hl
== DRAW_IMAGE_SUNKEN
2234 || s
->hl
== DRAW_IMAGE_RAISED
)
2236 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2237 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2241 thick
= abs (s
->img
->relief
);
2242 raised_p
= s
->img
->relief
> 0;
2247 x1
= x
+ s
->img
->width
+ thick
- 1;
2248 y1
= y
+ s
->img
->height
+ thick
- 1;
2250 x_setup_relief_colors (s
);
2251 get_glyph_string_clip_rect (s
, &r
);
2252 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
2256 /* Draw the foreground of image glyph string S to PIXMAP. */
2259 x_draw_image_foreground_1 (s
, pixmap
)
2260 struct glyph_string
*s
;
2264 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
2266 /* If first glyph of S has a left box line, start drawing it to the
2267 right of that line. */
2268 if (s
->face
->box
!= FACE_NO_BOX
2269 && s
->first_glyph
->left_box_line_p
)
2270 x
= abs (s
->face
->box_line_width
);
2274 /* If there is a margin around the image, adjust x- and y-position
2276 x
+= s
->img
->hmargin
;
2277 y
+= s
->img
->vmargin
;
2283 /* We can't set both a clip mask and use XSetClipRectangles
2284 because the latter also sets a clip mask. We also can't
2285 trust on the shape extension to be available
2286 (XShapeCombineRegion). So, compute the rectangle to draw
2288 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2292 xgcv
.clip_mask
= s
->img
->mask
;
2293 xgcv
.clip_x_origin
= x
;
2294 xgcv
.clip_y_origin
= y
;
2295 xgcv
.function
= GXcopy
;
2296 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2298 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2299 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
2300 XSetClipMask (s
->display
, s
->gc
, None
);
2304 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2305 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
2307 /* When the image has a mask, we can expect that at
2308 least part of a mouse highlight or a block cursor will
2309 be visible. If the image doesn't have a mask, make
2310 a block cursor visible by drawing a rectangle around
2311 the image. I believe it's looking better if we do
2312 nothing here for mouse-face. */
2313 if (s
->hl
== DRAW_CURSOR
)
2315 int r
= s
->img
->relief
;
2317 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2318 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
2323 /* Draw a rectangle if image could not be loaded. */
2324 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2325 s
->img
->width
- 1, s
->img
->height
- 1);
2329 /* Draw part of the background of glyph string S. X, Y, W, and H
2330 give the rectangle to draw. */
2333 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2334 struct glyph_string
*s
;
2339 /* Fill background with a stipple pattern. */
2340 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2341 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2342 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2345 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2349 /* Draw image glyph string S.
2352 s->x +-------------------------
2355 | +-------------------------
2358 | | +-------------------
2364 x_draw_image_glyph_string (s
)
2365 struct glyph_string
*s
;
2368 int box_line_hwidth
= abs (s
->face
->box_line_width
);
2369 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2371 Pixmap pixmap
= None
;
2373 height
= s
->height
- 2 * box_line_vwidth
;
2376 /* Fill background with face under the image. Do it only if row is
2377 taller than image or if image has a clip mask to reduce
2379 s
->stippled_p
= s
->face
->stipple
!= 0;
2380 if (height
> s
->img
->height
2384 || s
->img
->pixmap
== 0
2385 || s
->width
!= s
->background_width
)
2387 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
2388 x
= s
->x
+ box_line_hwidth
;
2392 y
= s
->y
+ box_line_vwidth
;
2396 /* Create a pixmap as large as the glyph string. Fill it
2397 with the background color. Copy the image to it, using
2398 its mask. Copy the temporary pixmap to the display. */
2399 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2400 int depth
= DefaultDepthOfScreen (screen
);
2402 /* Create a pixmap as large as the glyph string. */
2403 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2404 s
->background_width
,
2407 /* Don't clip in the following because we're working on the
2409 XSetClipMask (s
->display
, s
->gc
, None
);
2411 /* Fill the pixmap with the background color/stipple. */
2414 /* Fill background with a stipple pattern. */
2415 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2416 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2417 0, 0, s
->background_width
, s
->height
);
2418 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2423 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2425 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2426 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2427 0, 0, s
->background_width
, s
->height
);
2428 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2432 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2434 s
->background_filled_p
= 1;
2437 /* Draw the foreground. */
2440 x_draw_image_foreground_1 (s
, pixmap
);
2441 x_set_glyph_string_clipping (s
);
2442 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2443 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2444 XFreePixmap (s
->display
, pixmap
);
2447 x_draw_image_foreground (s
);
2449 /* If we must draw a relief around the image, do it. */
2451 || s
->hl
== DRAW_IMAGE_RAISED
2452 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2453 x_draw_image_relief (s
);
2457 /* Draw stretch glyph string S. */
2460 x_draw_stretch_glyph_string (s
)
2461 struct glyph_string
*s
;
2463 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2464 s
->stippled_p
= s
->face
->stipple
!= 0;
2466 if (s
->hl
== DRAW_CURSOR
2467 && !x_stretch_cursor_p
)
2469 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2470 as wide as the stretch glyph. */
2471 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
2474 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
2476 /* Clear rest using the GC of the original non-cursor face. */
2477 if (width
< s
->background_width
)
2479 int x
= s
->x
+ width
, y
= s
->y
;
2480 int w
= s
->background_width
- width
, h
= s
->height
;
2484 if (s
->row
->mouse_face_p
2485 && cursor_in_mouse_face_p (s
->w
))
2487 x_set_mouse_face_gc (s
);
2493 get_glyph_string_clip_rect (s
, &r
);
2494 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2496 if (s
->face
->stipple
)
2498 /* Fill background with a stipple pattern. */
2499 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2500 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2501 XSetFillStyle (s
->display
, gc
, FillSolid
);
2506 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2507 XSetForeground (s
->display
, gc
, xgcv
.background
);
2508 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2509 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2513 else if (!s
->background_filled_p
)
2514 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
2517 s
->background_filled_p
= 1;
2521 /* Draw glyph string S. */
2524 x_draw_glyph_string (s
)
2525 struct glyph_string
*s
;
2527 int relief_drawn_p
= 0;
2529 /* If S draws into the background of its successor, draw the
2530 background of the successor first so that S can draw into it.
2531 This makes S->next use XDrawString instead of XDrawImageString. */
2532 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
2534 xassert (s
->next
->img
== NULL
);
2535 x_set_glyph_string_gc (s
->next
);
2536 x_set_glyph_string_clipping (s
->next
);
2537 x_draw_glyph_string_background (s
->next
, 1);
2540 /* Set up S->gc, set clipping and draw S. */
2541 x_set_glyph_string_gc (s
);
2543 /* Draw relief (if any) in advance for char/composition so that the
2544 glyph string can be drawn over it. */
2545 if (!s
->for_overlaps_p
2546 && s
->face
->box
!= FACE_NO_BOX
2547 && (s
->first_glyph
->type
== CHAR_GLYPH
2548 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2551 x_set_glyph_string_clipping (s
);
2552 x_draw_glyph_string_background (s
, 1);
2553 x_draw_glyph_string_box (s
);
2554 x_set_glyph_string_clipping (s
);
2558 x_set_glyph_string_clipping (s
);
2560 switch (s
->first_glyph
->type
)
2563 x_draw_image_glyph_string (s
);
2567 x_draw_stretch_glyph_string (s
);
2571 if (s
->for_overlaps_p
)
2572 s
->background_filled_p
= 1;
2574 x_draw_glyph_string_background (s
, 0);
2575 x_draw_glyph_string_foreground (s
);
2578 case COMPOSITE_GLYPH
:
2579 if (s
->for_overlaps_p
|| s
->gidx
> 0)
2580 s
->background_filled_p
= 1;
2582 x_draw_glyph_string_background (s
, 1);
2583 x_draw_composite_glyph_string_foreground (s
);
2590 if (!s
->for_overlaps_p
)
2592 /* Draw underline. */
2593 if (s
->face
->underline_p
)
2595 unsigned long tem
, h
;
2598 /* Get the underline thickness. Default is 1 pixel. */
2599 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
2602 /* Get the underline position. This is the recommended
2603 vertical offset in pixels from the baseline to the top of
2604 the underline. This is a signed value according to the
2605 specs, and its default is
2607 ROUND ((maximum descent) / 2), with
2608 ROUND(x) = floor (x + 0.5) */
2610 if (x_use_underline_position_properties
2611 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
2612 y
= s
->ybase
+ (long) tem
;
2613 else if (s
->face
->font
)
2614 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2616 y
= s
->y
+ s
->height
- h
;
2618 if (s
->face
->underline_defaulted_p
)
2619 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2620 s
->x
, y
, s
->width
, h
);
2624 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2625 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2626 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2627 s
->x
, y
, s
->width
, h
);
2628 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2632 /* Draw overline. */
2633 if (s
->face
->overline_p
)
2635 unsigned long dy
= 0, h
= 1;
2637 if (s
->face
->overline_color_defaulted_p
)
2638 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2643 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2644 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2645 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2647 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2651 /* Draw strike-through. */
2652 if (s
->face
->strike_through_p
)
2654 unsigned long h
= 1;
2655 unsigned long dy
= (s
->height
- h
) / 2;
2657 if (s
->face
->strike_through_color_defaulted_p
)
2658 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2663 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2664 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2665 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2667 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2671 /* Draw relief if not yet drawn. */
2672 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2673 x_draw_glyph_string_box (s
);
2676 /* Reset clipping. */
2677 XSetClipMask (s
->display
, s
->gc
, None
);
2680 /* Shift display to make room for inserted glyphs. */
2683 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2685 int x
, y
, width
, height
, shift_by
;
2687 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2688 f
->output_data
.x
->normal_gc
,
2689 x
, y
, width
, height
,
2693 /* Delete N glyphs at the nominal cursor position. Not implemented
2704 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2705 If they are <= 0, this is probably an error. */
2708 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
2715 xassert (width
> 0 && height
> 0);
2716 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2720 /* Clear entire frame. If updating_frame is non-null, clear that
2721 frame. Otherwise clear the selected frame. */
2731 f
= SELECTED_FRAME ();
2733 /* Clearing the frame will erase any cursor, so mark them all as no
2735 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2736 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2737 output_cursor
.x
= -1;
2739 /* We don't set the output cursor here because there will always
2740 follow an explicit cursor_to. */
2742 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2744 /* We have to clear the scroll bars, too. If we have changed
2745 colors or something like that, then they should be notified. */
2746 x_scroll_bar_clear (f
);
2748 XFlush (FRAME_X_DISPLAY (f
));
2751 xg_frame_cleared (f
);
2759 /* Invert the middle quarter of the frame for .15 sec. */
2761 /* We use the select system call to do the waiting, so we have to make
2762 sure it's available. If it isn't, we just won't do visual bells. */
2764 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2767 /* Subtract the `struct timeval' values X and Y, storing the result in
2768 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2771 timeval_subtract (result
, x
, y
)
2772 struct timeval
*result
, x
, y
;
2774 /* Perform the carry for the later subtraction by updating y. This
2775 is safer because on some systems the tv_sec member is unsigned. */
2776 if (x
.tv_usec
< y
.tv_usec
)
2778 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2779 y
.tv_usec
-= 1000000 * nsec
;
2783 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2785 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2786 y
.tv_usec
+= 1000000 * nsec
;
2790 /* Compute the time remaining to wait. tv_usec is certainly
2792 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2793 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2795 /* Return indication of whether the result should be considered
2797 return x
.tv_sec
< y
.tv_sec
;
2809 /* Create a GC that will use the GXxor function to flip foreground
2810 pixels into background pixels. */
2814 values
.function
= GXxor
;
2815 values
.foreground
= (f
->output_data
.x
->foreground_pixel
2816 ^ f
->output_data
.x
->background_pixel
);
2818 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2819 GCFunction
| GCForeground
, &values
);
2823 /* Get the height not including a menu bar widget. */
2824 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
2825 /* Height of each line to flash. */
2826 int flash_height
= FRAME_LINE_HEIGHT (f
);
2827 /* These will be the left and right margins of the rectangles. */
2828 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2829 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
2833 /* Don't flash the area between a scroll bar and the frame
2834 edge it is next to. */
2835 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
2837 case vertical_scroll_bar_left
:
2838 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2841 case vertical_scroll_bar_right
:
2842 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2849 width
= flash_right
- flash_left
;
2851 /* If window is tall, flash top and bottom line. */
2852 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2854 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2856 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2857 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
2858 width
, flash_height
);
2859 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2861 (height
- flash_height
2862 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2863 width
, flash_height
);
2866 /* If it is short, flash it all. */
2867 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2868 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2869 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2874 struct timeval wakeup
;
2876 EMACS_GET_TIME (wakeup
);
2878 /* Compute time to wait until, propagating carry from usecs. */
2879 wakeup
.tv_usec
+= 150000;
2880 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
2881 wakeup
.tv_usec
%= 1000000;
2883 /* Keep waiting until past the time wakeup or any input gets
2885 while (! detect_input_pending ())
2887 struct timeval current
;
2888 struct timeval timeout
;
2890 EMACS_GET_TIME (current
);
2892 /* Break if result would be negative. */
2893 if (timeval_subtract (¤t
, wakeup
, current
))
2896 /* How long `select' should wait. */
2898 timeout
.tv_usec
= 10000;
2900 /* Try to wait that long--but we might wake up sooner. */
2901 select (0, NULL
, NULL
, NULL
, &timeout
);
2905 /* If window is tall, flash top and bottom line. */
2906 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2908 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2910 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2911 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
2912 width
, flash_height
);
2913 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2915 (height
- flash_height
2916 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2917 width
, flash_height
);
2920 /* If it is short, flash it all. */
2921 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2922 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2923 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2925 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
2933 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
2936 /* Make audible bell. */
2941 struct frame
*f
= SELECTED_FRAME ();
2943 if (FRAME_X_DISPLAY (f
))
2945 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2952 XBell (FRAME_X_DISPLAY (f
), 0);
2953 XFlush (FRAME_X_DISPLAY (f
));
2960 /* Specify how many text lines, from the top of the window,
2961 should be affected by insert-lines and delete-lines operations.
2962 This, and those operations, are used only within an update
2963 that is bounded by calls to x_update_begin and x_update_end. */
2966 XTset_terminal_window (n
)
2969 /* This function intentionally left blank. */
2974 /***********************************************************************
2976 ***********************************************************************/
2978 /* Perform an insert-lines or delete-lines operation, inserting N
2979 lines or deleting -N lines at vertical position VPOS. */
2982 x_ins_del_lines (vpos
, n
)
2989 /* Scroll part of the display as described by RUN. */
2992 x_scroll_run (w
, run
)
2996 struct frame
*f
= XFRAME (w
->frame
);
2997 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2999 /* Get frame-relative bounding box of the text display area of W,
3000 without mode lines. Include in this box the left and right
3002 window_box (w
, -1, &x
, &y
, &width
, &height
);
3003 width
+= FRAME_X_FRINGE_WIDTH (f
);
3004 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
3006 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3007 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3008 bottom_y
= y
+ height
;
3012 /* Scrolling up. Make sure we don't copy part of the mode
3013 line at the bottom. */
3014 if (from_y
+ run
->height
> bottom_y
)
3015 height
= bottom_y
- from_y
;
3017 height
= run
->height
;
3021 /* Scolling down. Make sure we don't copy over the mode line.
3023 if (to_y
+ run
->height
> bottom_y
)
3024 height
= bottom_y
- to_y
;
3026 height
= run
->height
;
3031 /* Cursor off. Will be switched on again in x_update_window_end. */
3035 XCopyArea (FRAME_X_DISPLAY (f
),
3036 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3037 f
->output_data
.x
->normal_gc
,
3047 /***********************************************************************
3049 ***********************************************************************/
3056 /* We used to only do this if Vx_no_window_manager was non-nil, but
3057 the ICCCM (section 4.1.6) says that the window's border pixmap
3058 and border pixel are window attributes which are "private to the
3059 client", so we can always change it to whatever we want. */
3061 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3062 f
->output_data
.x
->border_pixel
);
3064 x_update_cursor (f
, 1);
3068 frame_unhighlight (f
)
3071 /* We used to only do this if Vx_no_window_manager was non-nil, but
3072 the ICCCM (section 4.1.6) says that the window's border pixmap
3073 and border pixel are window attributes which are "private to the
3074 client", so we can always change it to whatever we want. */
3076 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3077 f
->output_data
.x
->border_tile
);
3079 x_update_cursor (f
, 1);
3082 /* The focus has changed. Update the frames as necessary to reflect
3083 the new situation. Note that we can't change the selected frame
3084 here, because the Lisp code we are interrupting might become confused.
3085 Each event gets marked with the frame in which it occurred, so the
3086 Lisp code can tell when the switch took place by examining the events. */
3089 x_new_focus_frame (dpyinfo
, frame
)
3090 struct x_display_info
*dpyinfo
;
3091 struct frame
*frame
;
3093 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3095 if (frame
!= dpyinfo
->x_focus_frame
)
3097 /* Set this before calling other routines, so that they see
3098 the correct value of x_focus_frame. */
3099 dpyinfo
->x_focus_frame
= frame
;
3101 if (old_focus
&& old_focus
->auto_lower
)
3102 x_lower_frame (old_focus
);
3105 selected_frame
= frame
;
3106 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3108 Fselect_window (selected_frame
->selected_window
);
3109 choose_minibuf_frame ();
3112 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3113 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3115 pending_autoraise_frame
= 0;
3118 x_frame_rehighlight (dpyinfo
);
3121 /* Handle FocusIn and FocusOut state changes for FRAME.
3122 If FRAME has focus and there exists more than one frame, puts
3123 a FOCUS_IN_EVENT into BUFP.
3124 Returns number of events inserted into BUFP. */
3127 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
, numchars
)
3130 struct x_display_info
*dpyinfo
;
3131 struct frame
*frame
;
3132 struct input_event
*bufp
;
3137 if (type
== FocusIn
)
3139 if (dpyinfo
->x_focus_event_frame
!= frame
)
3141 x_new_focus_frame (dpyinfo
, frame
);
3142 dpyinfo
->x_focus_event_frame
= frame
;
3144 /* Don't stop displaying the initial startup message
3145 for a switch-frame event we don't need. */
3147 && GC_NILP (Vterminal_frame
)
3148 && GC_CONSP (Vframe_list
)
3149 && !GC_NILP (XCDR (Vframe_list
)))
3151 bufp
->kind
= FOCUS_IN_EVENT
;
3152 XSETFRAME (bufp
->frame_or_window
, frame
);
3160 frame
->output_data
.x
->focus_state
|= state
;
3163 if (FRAME_XIC (frame
))
3164 XSetICFocus (FRAME_XIC (frame
));
3167 else if (type
== FocusOut
)
3169 frame
->output_data
.x
->focus_state
&= ~state
;
3171 if (dpyinfo
->x_focus_event_frame
== frame
)
3173 dpyinfo
->x_focus_event_frame
= 0;
3174 x_new_focus_frame (dpyinfo
, 0);
3178 if (FRAME_XIC (frame
))
3179 XUnsetICFocus (FRAME_XIC (frame
));
3186 /* The focus may have changed. Figure out if it is a real focus change,
3187 by checking both FocusIn/Out and Enter/LeaveNotify events.
3189 Returns number of events inserted into BUFP. */
3192 x_detect_focus_change (dpyinfo
, event
, bufp
, numchars
)
3193 struct x_display_info
*dpyinfo
;
3195 struct input_event
*bufp
;
3198 struct frame
*frame
;
3201 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3202 if (! frame
) return nr_events
;
3204 switch (event
->type
)
3208 if (event
->xcrossing
.detail
!= NotifyInferior
3209 && event
->xcrossing
.focus
3210 && ! (frame
->output_data
.x
->focus_state
& FOCUS_EXPLICIT
))
3211 nr_events
= x_focus_changed ((event
->type
== EnterNotify
3212 ? FocusIn
: FocusOut
),
3222 nr_events
= x_focus_changed (event
->type
,
3223 (event
->xfocus
.detail
== NotifyPointer
3224 ? FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3236 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3239 x_mouse_leave (dpyinfo
)
3240 struct x_display_info
*dpyinfo
;
3242 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3245 /* The focus has changed, or we have redirected a frame's focus to
3246 another frame (this happens when a frame uses a surrogate
3247 mini-buffer frame). Shift the highlight as appropriate.
3249 The FRAME argument doesn't necessarily have anything to do with which
3250 frame is being highlighted or un-highlighted; we only use it to find
3251 the appropriate X display info. */
3254 XTframe_rehighlight (frame
)
3255 struct frame
*frame
;
3257 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3261 x_frame_rehighlight (dpyinfo
)
3262 struct x_display_info
*dpyinfo
;
3264 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3266 if (dpyinfo
->x_focus_frame
)
3268 dpyinfo
->x_highlight_frame
3269 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3270 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3271 : dpyinfo
->x_focus_frame
);
3272 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3274 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3275 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3279 dpyinfo
->x_highlight_frame
= 0;
3281 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3284 frame_unhighlight (old_highlight
);
3285 if (dpyinfo
->x_highlight_frame
)
3286 frame_highlight (dpyinfo
->x_highlight_frame
);
3292 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3294 /* Initialize mode_switch_bit and modifier_meaning. */
3296 x_find_modifier_meanings (dpyinfo
)
3297 struct x_display_info
*dpyinfo
;
3299 int min_code
, max_code
;
3302 XModifierKeymap
*mods
;
3304 dpyinfo
->meta_mod_mask
= 0;
3305 dpyinfo
->shift_lock_mask
= 0;
3306 dpyinfo
->alt_mod_mask
= 0;
3307 dpyinfo
->super_mod_mask
= 0;
3308 dpyinfo
->hyper_mod_mask
= 0;
3311 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3313 min_code
= dpyinfo
->display
->min_keycode
;
3314 max_code
= dpyinfo
->display
->max_keycode
;
3317 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3318 min_code
, max_code
- min_code
+ 1,
3320 mods
= XGetModifierMapping (dpyinfo
->display
);
3322 /* Scan the modifier table to see which modifier bits the Meta and
3323 Alt keysyms are on. */
3325 int row
, col
; /* The row and column in the modifier table. */
3327 for (row
= 3; row
< 8; row
++)
3328 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3331 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3333 /* Zeroes are used for filler. Skip them. */
3337 /* Are any of this keycode's keysyms a meta key? */
3341 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3343 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3349 dpyinfo
->meta_mod_mask
|= (1 << row
);
3354 dpyinfo
->alt_mod_mask
|= (1 << row
);
3359 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3364 dpyinfo
->super_mod_mask
|= (1 << row
);
3368 /* Ignore this if it's not on the lock modifier. */
3369 if ((1 << row
) == LockMask
)
3370 dpyinfo
->shift_lock_mask
= LockMask
;
3378 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3379 if (! dpyinfo
->meta_mod_mask
)
3381 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3382 dpyinfo
->alt_mod_mask
= 0;
3385 /* If some keys are both alt and meta,
3386 make them just meta, not alt. */
3387 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3389 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3392 XFree ((char *) syms
);
3393 XFreeModifiermap (mods
);
3396 /* Convert between the modifier bits X uses and the modifier bits
3400 x_x_to_emacs_modifiers (dpyinfo
, state
)
3401 struct x_display_info
*dpyinfo
;
3404 EMACS_UINT mod_meta
= meta_modifier
;
3405 EMACS_UINT mod_alt
= alt_modifier
;
3406 EMACS_UINT mod_hyper
= hyper_modifier
;
3407 EMACS_UINT mod_super
= super_modifier
;
3410 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3411 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3412 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3413 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3414 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3415 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3416 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3417 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3420 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3421 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3422 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3423 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3424 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3425 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3429 x_emacs_to_x_modifiers (dpyinfo
, state
)
3430 struct x_display_info
*dpyinfo
;
3433 EMACS_UINT mod_meta
= meta_modifier
;
3434 EMACS_UINT mod_alt
= alt_modifier
;
3435 EMACS_UINT mod_hyper
= hyper_modifier
;
3436 EMACS_UINT mod_super
= super_modifier
;
3440 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3441 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3442 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3443 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3444 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3445 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3446 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3447 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3450 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3451 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3452 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3453 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3454 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3455 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3458 /* Convert a keysym to its name. */
3461 x_get_keysym_name (keysym
)
3467 value
= XKeysymToString (keysym
);
3475 /* Mouse clicks and mouse movement. Rah. */
3477 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3479 If the event is a button press, then note that we have grabbed
3483 construct_mouse_click (result
, event
, f
)
3484 struct input_event
*result
;
3485 XButtonEvent
*event
;
3488 /* Make the event type NO_EVENT; we'll change that when we decide
3490 result
->kind
= MOUSE_CLICK_EVENT
;
3491 result
->code
= event
->button
- Button1
;
3492 result
->timestamp
= event
->time
;
3493 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3495 | (event
->type
== ButtonRelease
3499 XSETINT (result
->x
, event
->x
);
3500 XSETINT (result
->y
, event
->y
);
3501 XSETFRAME (result
->frame_or_window
, f
);
3507 /* Function to report a mouse movement to the mainstream Emacs code.
3508 The input handler calls this.
3510 We have received a mouse movement event, which is given in *event.
3511 If the mouse is over a different glyph than it was last time, tell
3512 the mainstream emacs code by setting mouse_moved. If not, ask for
3513 another motion event, so we can check again the next time it moves. */
3515 static XMotionEvent last_mouse_motion_event
;
3516 static Lisp_Object last_mouse_motion_frame
;
3519 note_mouse_movement (frame
, event
)
3521 XMotionEvent
*event
;
3523 last_mouse_movement_time
= event
->time
;
3524 last_mouse_motion_event
= *event
;
3525 XSETFRAME (last_mouse_motion_frame
, frame
);
3527 if (event
->window
!= FRAME_X_WINDOW (frame
))
3529 frame
->mouse_moved
= 1;
3530 last_mouse_scroll_bar
= Qnil
;
3531 note_mouse_highlight (frame
, -1, -1);
3534 /* Has the mouse moved off the glyph it was on at the last sighting? */
3535 else if (event
->x
< last_mouse_glyph
.x
3536 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3537 || event
->y
< last_mouse_glyph
.y
3538 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3540 frame
->mouse_moved
= 1;
3541 last_mouse_scroll_bar
= Qnil
;
3542 note_mouse_highlight (frame
, event
->x
, event
->y
);
3547 /************************************************************************
3549 ************************************************************************/
3552 redo_mouse_highlight ()
3554 if (!NILP (last_mouse_motion_frame
)
3555 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3556 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3557 last_mouse_motion_event
.x
,
3558 last_mouse_motion_event
.y
);
3562 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
3565 /* Try to determine frame pixel position and size of the glyph under
3566 frame pixel coordinates X/Y on frame F . Return the position and
3567 size in *RECT. Value is non-zero if we could compute these
3571 glyph_rect (f
, x
, y
, rect
)
3579 window
= window_from_coordinates (f
, x
, y
, 0, 0);
3582 struct window
*w
= XWINDOW (window
);
3583 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
3584 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
3586 frame_to_window_pixel_xy (w
, &x
, &y
);
3588 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
3591 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
3592 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
3595 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
3598 rect
->width
= g
->pixel_width
;
3599 rect
->height
= r
->height
;
3600 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
3601 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
3611 /* Return the current position of the mouse.
3612 *FP should be a frame which indicates which display to ask about.
3614 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3615 and *PART to the frame, window, and scroll bar part that the mouse
3616 is over. Set *X and *Y to the portion and whole of the mouse's
3617 position on the scroll bar.
3619 If the mouse movement started elsewhere, set *FP to the frame the
3620 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3623 Set *TIME to the server time-stamp for the time at which the mouse
3624 was at this position.
3626 Don't store anything if we don't have a valid set of values to report.
3628 This clears the mouse_moved flag, so we can wait for the next mouse
3632 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3635 Lisp_Object
*bar_window
;
3636 enum scroll_bar_part
*part
;
3638 unsigned long *time
;
3644 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3645 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3651 Window dummy_window
;
3654 Lisp_Object frame
, tail
;
3656 /* Clear the mouse-moved flag for every frame on this display. */
3657 FOR_EACH_FRAME (tail
, frame
)
3658 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3659 XFRAME (frame
)->mouse_moved
= 0;
3661 last_mouse_scroll_bar
= Qnil
;
3663 /* Figure out which root window we're on. */
3664 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3665 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3667 /* The root window which contains the pointer. */
3670 /* Trash which we can't trust if the pointer is on
3671 a different screen. */
3674 /* The position on that root window. */
3677 /* More trash we can't trust. */
3680 /* Modifier keys and pointer buttons, about which
3682 (unsigned int *) &dummy
);
3684 /* Now we have a position on the root; find the innermost window
3685 containing the pointer. */
3689 int parent_x
= 0, parent_y
= 0;
3694 /* XTranslateCoordinates can get errors if the window
3695 structure is changing at the same time this function
3696 is running. So at least we must not crash from them. */
3698 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
3700 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3701 && FRAME_LIVE_P (last_mouse_frame
))
3703 /* If mouse was grabbed on a frame, give coords for that frame
3704 even if the mouse is now outside it. */
3705 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3707 /* From-window, to-window. */
3708 root
, FRAME_X_WINDOW (last_mouse_frame
),
3710 /* From-position, to-position. */
3711 root_x
, root_y
, &win_x
, &win_y
,
3715 f1
= last_mouse_frame
;
3721 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3723 /* From-window, to-window. */
3726 /* From-position, to-position. */
3727 root_x
, root_y
, &win_x
, &win_y
,
3732 if (child
== None
|| child
== win
)
3740 /* Now we know that:
3741 win is the innermost window containing the pointer
3742 (XTC says it has no child containing the pointer),
3743 win_x and win_y are the pointer's position in it
3744 (XTC did this the last time through), and
3745 parent_x and parent_y are the pointer's position in win's parent.
3746 (They are what win_x and win_y were when win was child.
3747 If win is the root window, it has no parent, and
3748 parent_{x,y} are invalid, but that's okay, because we'll
3749 never use them in that case.) */
3751 /* Is win one of our frames? */
3752 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3754 #ifdef USE_X_TOOLKIT
3755 /* If we end up with the menu bar window, say it's not
3758 && f1
->output_data
.x
->menubar_widget
3759 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3761 #endif /* USE_X_TOOLKIT */
3764 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3767 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
3769 /* If not, is it one of our scroll bars? */
3772 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
3776 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3782 if (f1
== 0 && insist
> 0)
3783 f1
= SELECTED_FRAME ();
3787 /* Ok, we found a frame. Store all the values.
3788 last_mouse_glyph is a rectangle used to reduce the
3789 generation of mouse events. To not miss any motion
3790 events, we must divide the frame into rectangles of the
3791 size of the smallest character that could be displayed
3792 on it, i.e. into the same rectangles that matrices on
3793 the frame are divided into. */
3795 int width
, height
, gx
, gy
;
3798 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
3799 last_mouse_glyph
= rect
;
3802 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
3803 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
3807 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
3808 round down even for negative values. */
3813 gx
= (gx
+ width
- 1) / width
* width
;
3814 gy
= (gy
+ height
- 1) / height
* height
;
3816 last_mouse_glyph
.width
= width
;
3817 last_mouse_glyph
.height
= height
;
3818 last_mouse_glyph
.x
= gx
;
3819 last_mouse_glyph
.y
= gy
;
3825 XSETINT (*x
, win_x
);
3826 XSETINT (*y
, win_y
);
3827 *time
= last_mouse_movement_time
;
3837 /***********************************************************************
3839 ***********************************************************************/
3841 /* Scroll bar support. */
3843 /* Given an X window ID, find the struct scroll_bar which manages it.
3844 This can be called in GC, so we have to make sure to strip off mark
3847 static struct scroll_bar
*
3848 x_window_to_scroll_bar (window_id
)
3854 window_id
= (Window
) xg_get_scroll_id_for_window (window_id
);
3855 #endif /* USE_GTK */
3857 for (tail
= Vframe_list
;
3858 XGCTYPE (tail
) == Lisp_Cons
;
3861 Lisp_Object frame
, bar
, condemned
;
3863 frame
= XCAR (tail
);
3864 /* All elements of Vframe_list should be frames. */
3865 if (! GC_FRAMEP (frame
))
3868 /* Scan this frame's scroll bar list for a scroll bar with the
3870 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3871 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3872 /* This trick allows us to search both the ordinary and
3873 condemned scroll bar lists with one loop. */
3874 ! GC_NILP (bar
) || (bar
= condemned
,
3877 bar
= XSCROLL_BAR (bar
)->next
)
3878 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
3879 return XSCROLL_BAR (bar
);
3886 #if defined USE_LUCID
3888 /* Return the Lucid menu bar WINDOW is part of. Return null
3889 if WINDOW is not part of a menu bar. */
3892 x_window_to_menu_bar (window
)
3897 for (tail
= Vframe_list
;
3898 XGCTYPE (tail
) == Lisp_Cons
;
3901 Lisp_Object frame
= XCAR (tail
);
3902 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
3904 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
3911 #endif /* USE_LUCID */
3914 /************************************************************************
3916 ************************************************************************/
3918 #ifdef USE_TOOLKIT_SCROLL_BARS
3920 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
3921 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
3922 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
3923 struct scroll_bar
*));
3924 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
3928 /* Lisp window being scrolled. Set when starting to interact with
3929 a toolkit scroll bar, reset to nil when ending the interaction. */
3931 static Lisp_Object window_being_scrolled
;
3933 /* Last scroll bar part sent in xm_scroll_callback. */
3935 static int last_scroll_bar_part
;
3937 /* Whether this is an Xaw with arrow-scrollbars. This should imply
3938 that movements of 1/20 of the screen size are mapped to up/down. */
3941 /* Id of action hook installed for scroll bars. */
3943 static XtActionHookId action_hook_id
;
3945 static Boolean xaw3d_arrow_scroll
;
3947 /* Whether the drag scrolling maintains the mouse at the top of the
3948 thumb. If not, resizing the thumb needs to be done more carefully
3949 to avoid jerkyness. */
3951 static Boolean xaw3d_pick_top
;
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
);
3989 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
3990 window_being_scrolled
= Qnil
;
3991 last_scroll_bar_part
= -1;
3993 /* Xt timeouts no longer needed. */
3994 toolkit_scroll_bar_interaction
= 0;
3997 #endif /* not USE_GTK */
3999 /* A vector of windows used for communication between
4000 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4002 static struct window
**scroll_bar_windows
;
4003 static int scroll_bar_windows_size
;
4006 /* Send a client message with message type Xatom_Scrollbar for a
4007 scroll action to the frame of WINDOW. PART is a value identifying
4008 the part of the scroll bar that was clicked on. PORTION is the
4009 amount to scroll of a whole of WHOLE. */
4012 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4014 int part
, portion
, whole
;
4017 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4018 struct window
*w
= XWINDOW (window
);
4019 struct frame
*f
= XFRAME (w
->frame
);
4024 /* Construct a ClientMessage event to send to the frame. */
4025 ev
->type
= ClientMessage
;
4026 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4027 ev
->display
= FRAME_X_DISPLAY (f
);
4028 ev
->window
= FRAME_X_WINDOW (f
);
4031 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4032 not enough to store a pointer or Lisp_Object on a 64 bit system.
4033 So, store the window in scroll_bar_windows and pass the index
4034 into that array in the event. */
4035 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4036 if (scroll_bar_windows
[i
] == NULL
)
4039 if (i
== scroll_bar_windows_size
)
4041 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4042 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4043 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4045 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4047 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4048 scroll_bar_windows_size
= new_size
;
4051 scroll_bar_windows
[i
] = w
;
4052 ev
->data
.l
[0] = (long) i
;
4053 ev
->data
.l
[1] = (long) part
;
4054 ev
->data
.l
[2] = (long) 0;
4055 ev
->data
.l
[3] = (long) portion
;
4056 ev
->data
.l
[4] = (long) whole
;
4058 /* Make Xt timeouts work while the scroll bar is active. */
4059 toolkit_scroll_bar_interaction
= 1;
4061 /* Setting the event mask to zero means that the message will
4062 be sent to the client that created the window, and if that
4063 window no longer exists, no event will be sent. */
4064 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4069 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4073 x_scroll_bar_to_input_event (event
, ievent
)
4075 struct input_event
*ievent
;
4077 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4082 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4083 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4085 XSETWINDOW (window
, w
);
4086 f
= XFRAME (w
->frame
);
4088 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4089 ievent
->frame_or_window
= window
;
4092 ievent
->timestamp
= CurrentTime
;
4094 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4096 ievent
->part
= ev
->data
.l
[1];
4097 ievent
->code
= ev
->data
.l
[2];
4098 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4099 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4100 ievent
->modifiers
= 0;
4106 /* Minimum and maximum values used for Motif scroll bars. */
4109 #define XM_SB_MAX 10000000
4110 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
4113 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4114 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4115 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4118 xm_scroll_callback (widget
, client_data
, call_data
)
4120 XtPointer client_data
, call_data
;
4122 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4123 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4124 int part
= -1, whole
= 0, portion
= 0;
4128 case XmCR_DECREMENT
:
4129 bar
->dragging
= Qnil
;
4130 part
= scroll_bar_up_arrow
;
4133 case XmCR_INCREMENT
:
4134 bar
->dragging
= Qnil
;
4135 part
= scroll_bar_down_arrow
;
4138 case XmCR_PAGE_DECREMENT
:
4139 bar
->dragging
= Qnil
;
4140 part
= scroll_bar_above_handle
;
4143 case XmCR_PAGE_INCREMENT
:
4144 bar
->dragging
= Qnil
;
4145 part
= scroll_bar_below_handle
;
4149 bar
->dragging
= Qnil
;
4150 part
= scroll_bar_to_top
;
4153 case XmCR_TO_BOTTOM
:
4154 bar
->dragging
= Qnil
;
4155 part
= scroll_bar_to_bottom
;
4161 int dragging_down_p
= (INTEGERP (bar
->dragging
)
4162 && XINT (bar
->dragging
) <= cs
->value
);
4164 /* Get the slider size. */
4166 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4169 whole
= XM_SB_RANGE
- slider_size
;
4170 portion
= min (cs
->value
- XM_SB_MIN
, whole
);
4171 part
= scroll_bar_handle
;
4172 bar
->dragging
= make_number (cs
->value
);
4176 case XmCR_VALUE_CHANGED
:
4182 window_being_scrolled
= bar
->window
;
4183 last_scroll_bar_part
= part
;
4184 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4189 #else /* !USE_MOTIF, i.e. Xaw or GTK */
4191 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4192 bar adjustment widget. DATA is a pointer to the scroll_bar structure. */
4195 xg_scroll_callback (widget
, data
)
4199 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4205 int part
= -1, whole
= 0, portion
= 0;
4206 GtkAdjustment
*adj
= GTK_ADJUSTMENT (widget
);
4208 if (xg_ignore_gtk_scrollbar
) return;
4210 position
= gtk_adjustment_get_value (adj
);
4212 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4215 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4217 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4223 diff
= (int) (position
- previous
);
4225 if (diff
== (int) adj
->step_increment
)
4227 part
= scroll_bar_down_arrow
;
4228 bar
->dragging
= Qnil
;
4230 else if (-diff
== (int) adj
->step_increment
)
4232 part
= scroll_bar_up_arrow
;
4233 bar
->dragging
= Qnil
;
4235 else if (diff
== (int) adj
->page_increment
)
4237 part
= scroll_bar_below_handle
;
4238 bar
->dragging
= Qnil
;
4240 else if (-diff
== (int) adj
->page_increment
)
4242 part
= scroll_bar_above_handle
;
4243 bar
->dragging
= Qnil
;
4247 part
= scroll_bar_handle
;
4248 whole
= adj
->upper
- adj
->page_size
;
4249 portion
= min ((int)position
, whole
);
4250 bar
->dragging
= make_number ((int)portion
);
4255 window_being_scrolled
= bar
->window
;
4256 last_scroll_bar_part
= part
;
4257 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4261 #else /* not USE_GTK */
4263 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4264 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4265 scroll bar struct. CALL_DATA is a pointer to a float saying where
4269 xaw_jump_callback (widget
, client_data
, call_data
)
4271 XtPointer client_data
, call_data
;
4273 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4274 float top
= *(float *) call_data
;
4276 int whole
, portion
, height
;
4279 /* Get the size of the thumb, a value between 0 and 1. */
4281 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4285 portion
= shown
< 1 ? top
* whole
: 0;
4287 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
4288 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4289 the bottom, so we force the scrolling whenever we see that we're
4290 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4291 we try to ensure that we always stay two pixels away from the
4293 part
= scroll_bar_down_arrow
;
4295 part
= scroll_bar_handle
;
4297 window_being_scrolled
= bar
->window
;
4298 bar
->dragging
= make_number (portion
);
4299 last_scroll_bar_part
= part
;
4300 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4304 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4305 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4306 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4307 the scroll bar. CALL_DATA is an integer specifying the action that
4308 has taken place. Its magnitude is in the range 0..height of the
4309 scroll bar. Negative values mean scroll towards buffer start.
4310 Values < height of scroll bar mean line-wise movement. */
4313 xaw_scroll_callback (widget
, client_data
, call_data
)
4315 XtPointer client_data
, call_data
;
4317 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4318 /* The position really is stored cast to a pointer. */
4319 int position
= (long) call_data
;
4323 /* Get the height of the scroll bar. */
4325 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4328 if (abs (position
) >= height
)
4329 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4331 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4332 it maps line-movement to call_data = max(5, height/20). */
4333 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
4334 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4336 part
= scroll_bar_move_ratio
;
4338 window_being_scrolled
= bar
->window
;
4339 bar
->dragging
= Qnil
;
4340 last_scroll_bar_part
= part
;
4341 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4344 #endif /* not USE_GTK */
4345 #endif /* not USE_MOTIF */
4347 #define SCROLL_BAR_NAME "verticalScrollBar"
4349 /* Create the widget for scroll bar BAR on frame F. Record the widget
4350 and X window of the scroll bar in BAR. */
4354 x_create_toolkit_scroll_bar (f
, bar
)
4356 struct scroll_bar
*bar
;
4358 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4361 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4366 #else /* not USE_GTK */
4369 x_create_toolkit_scroll_bar (f
, bar
)
4371 struct scroll_bar
*bar
;
4377 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4378 unsigned long pixel
;
4383 /* Set resources. Create the widget. */
4384 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4385 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
4386 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4387 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4388 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4389 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4390 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4392 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4395 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4399 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4402 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4406 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4407 scroll_bar_name
, av
, ac
);
4409 /* Add one callback for everything that can happen. */
4410 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4412 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4414 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4416 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4418 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4420 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4422 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4425 /* Realize the widget. Only after that is the X window created. */
4426 XtRealizeWidget (widget
);
4428 /* Set the cursor to an arrow. I didn't find a resource to do that.
4429 And I'm wondering why it hasn't an arrow cursor by default. */
4430 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4431 f
->output_data
.x
->nontext_cursor
);
4433 #else /* !USE_MOTIF i.e. use Xaw */
4435 /* Set resources. Create the widget. The background of the
4436 Xaw3d scroll bar widget is a little bit light for my taste.
4437 We don't alter it here to let users change it according
4438 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4439 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4440 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4441 /* For smoother scrolling with Xaw3d -sm */
4442 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4444 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4447 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4451 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4454 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4458 /* Top/bottom shadow colors. */
4460 /* Allocate them, if necessary. */
4461 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4463 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4464 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4465 &pixel
, 1.2, 0x8000))
4467 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4469 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4471 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4472 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4473 &pixel
, 0.6, 0x4000))
4475 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4478 /* Tell the toolkit about them. */
4479 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4480 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4481 /* We tried to allocate a color for the top/bottom shadow, and
4482 failed, so tell Xaw3d to use dithering instead. */
4484 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4488 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4489 be more consistent with other emacs 3d colors, and since Xaw3d is
4490 not good at dealing with allocation failure. */
4492 /* This tells Xaw3d to use real colors instead of dithering for
4494 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4497 /* Specify the colors. */
4498 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4501 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
4504 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4507 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
4512 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4513 f
->output_data
.x
->edit_widget
, av
, ac
);
4517 char *val
= initial
;
4518 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4519 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4521 { /* ARROW_SCROLL */
4522 xaw3d_arrow_scroll
= True
;
4523 /* Isn't that just a personal preference ? -sm */
4524 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4528 /* Define callbacks. */
4529 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4530 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4533 /* Realize the widget. Only after that is the X window created. */
4534 XtRealizeWidget (widget
);
4536 #endif /* !USE_MOTIF */
4538 /* Install an action hook that lets us detect when the user
4539 finishes interacting with a scroll bar. */
4540 if (action_hook_id
== 0)
4541 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4543 /* Remember X window and widget in the scroll bar vector. */
4544 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4545 xwindow
= XtWindow (widget
);
4546 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
4550 #endif /* not USE_GTK */
4553 /* Set the thumb size and position of scroll bar BAR. We are currently
4554 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4558 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4559 struct scroll_bar
*bar
;
4560 int portion
, position
, whole
;
4562 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4565 #else /* not USE_GTK */
4567 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4568 struct scroll_bar
*bar
;
4569 int portion
, position
, whole
;
4571 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4572 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4579 /* We use an estimate of 30 chars per line rather than the real
4580 `portion' value. This has the disadvantage that the thumb size
4581 is not very representative, but it makes our life a lot easier.
4582 Otherwise, we have to constantly adjust the thumb size, which
4583 we can't always do quickly enough: while dragging, the size of
4584 the thumb might prevent the user from dragging the thumb all the
4585 way to the end. but Motif and some versions of Xaw3d don't allow
4586 updating the thumb size while dragging. Also, even if we can update
4587 its size, the update will often happen too late.
4588 If you don't believe it, check out revision 1.650 of xterm.c to see
4589 what hoops we were going through and the still poor behavior we got. */
4590 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
4591 /* When the thumb is at the bottom, position == whole.
4592 So we need to increase `whole' to make space for the thumb. */
4599 top
= (float) position
/ whole
;
4600 shown
= (float) portion
/ whole
;
4603 if (NILP (bar
->dragging
))
4607 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4608 is the scroll bar's maximum and MIN is the scroll bar's minimum
4610 size
= shown
* XM_SB_RANGE
;
4611 size
= min (size
, XM_SB_RANGE
);
4612 size
= max (size
, 1);
4614 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4615 value
= top
* XM_SB_RANGE
;
4616 value
= min (value
, XM_SB_MAX
- size
);
4617 value
= max (value
, XM_SB_MIN
);
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,
4784 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
4785 #else /* not USE_GTK */
4786 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4787 XtConfigureWidget (scroll_bar
,
4788 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4790 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4791 max (height
, 1), 0);
4792 XtMapWidget (scroll_bar
);
4793 #endif /* not USE_GTK */
4795 #else /* not USE_TOOLKIT_SCROLL_BARS */
4796 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4797 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4804 /* Draw BAR's handle in the proper position.
4806 If the handle is already drawn from START to END, don't bother
4807 redrawing it, unless REBUILD is non-zero; in that case, always
4808 redraw it. (REBUILD is handy for drawing the handle after expose
4811 Normally, we want to constrain the start and end of the handle to
4812 fit inside its rectangle, but if the user is dragging the scroll
4813 bar handle, we want to let them drag it down all the way, so that
4814 the bar's top is as far down as it goes; otherwise, there's no way
4815 to move to the very end of the buffer. */
4817 #ifndef USE_TOOLKIT_SCROLL_BARS
4820 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4821 struct scroll_bar
*bar
;
4825 int dragging
= ! NILP (bar
->dragging
);
4826 Window w
= SCROLL_BAR_X_WINDOW (bar
);
4827 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4828 GC gc
= f
->output_data
.x
->normal_gc
;
4830 /* If the display is already accurate, do nothing. */
4832 && start
== XINT (bar
->start
)
4833 && end
== XINT (bar
->end
))
4839 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
4840 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
4841 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4843 /* Make sure the values are reasonable, and try to preserve
4844 the distance between start and end. */
4846 int length
= end
- start
;
4850 else if (start
> top_range
)
4852 end
= start
+ length
;
4856 else if (end
> top_range
&& ! dragging
)
4860 /* Store the adjusted setting in the scroll bar. */
4861 XSETINT (bar
->start
, start
);
4862 XSETINT (bar
->end
, end
);
4864 /* Clip the end position, just for display. */
4865 if (end
> top_range
)
4868 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
4869 below top positions, to make sure the handle is always at least
4870 that many pixels tall. */
4871 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4873 /* Draw the empty space above the handle. Note that we can't clear
4874 zero-height areas; that means "clear to end of window." */
4876 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4877 /* x, y, width, height, and exposures. */
4878 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4879 VERTICAL_SCROLL_BAR_TOP_BORDER
,
4880 inside_width
, start
,
4883 /* Change to proper foreground color if one is specified. */
4884 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4885 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4886 f
->output_data
.x
->scroll_bar_foreground_pixel
);
4888 /* Draw the handle itself. */
4889 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
4890 /* x, y, width, height */
4891 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4892 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
4893 inside_width
, end
- start
);
4895 /* Restore the foreground color of the GC if we changed it above. */
4896 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4897 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4898 f
->output_data
.x
->foreground_pixel
);
4900 /* Draw the empty space below the handle. Note that we can't
4901 clear zero-height areas; that means "clear to end of window." */
4902 if (end
< inside_height
)
4903 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4904 /* x, y, width, height, and exposures. */
4905 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4906 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
4907 inside_width
, inside_height
- end
,
4915 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4917 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4921 x_scroll_bar_remove (bar
)
4922 struct scroll_bar
*bar
;
4924 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4927 #ifdef USE_TOOLKIT_SCROLL_BARS
4929 xg_remove_scroll_bar (f
, SCROLL_BAR_X_WINDOW (bar
));
4930 #else /* not USE_GTK */
4931 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
4932 #endif /* not USE_GTK */
4934 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4937 /* Disassociate this scroll bar from its window. */
4938 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4944 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4945 that we are displaying PORTION characters out of a total of WHOLE
4946 characters, starting at POSITION. If WINDOW has no scroll bar,
4950 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4952 int portion
, whole
, position
;
4954 struct frame
*f
= XFRAME (w
->frame
);
4955 struct scroll_bar
*bar
;
4956 int top
, height
, left
, sb_left
, width
, sb_width
;
4957 int window_x
, window_y
, window_width
, window_height
;
4959 /* Get window dimensions. */
4960 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
4962 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
4963 height
= window_height
;
4965 /* Compute the left edge of the scroll bar area. */
4966 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4967 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
4969 left
= XFASTINT (w
->left
);
4970 left
*= CANON_X_UNIT (f
);
4971 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4973 /* Compute the width of the scroll bar which might be less than
4974 the width of the area reserved for the scroll bar. */
4975 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
4976 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
4980 /* Compute the left edge of the scroll bar. */
4981 #ifdef USE_TOOLKIT_SCROLL_BARS
4982 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4983 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
4985 sb_left
= left
+ (width
- sb_width
) / 2;
4987 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4988 sb_left
= left
+ width
- sb_width
;
4993 /* Does the scroll bar exist yet? */
4994 if (NILP (w
->vertical_scroll_bar
))
4996 if (width
> 0 && height
> 0)
4999 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5000 left
, top
, width
, height
, False
);
5004 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5008 /* It may just need to be moved and resized. */
5009 unsigned int mask
= 0;
5011 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5015 if (sb_left
!= XINT (bar
->left
))
5017 if (top
!= XINT (bar
->top
))
5019 if (sb_width
!= XINT (bar
->width
))
5021 if (height
!= XINT (bar
->height
))
5024 #ifdef USE_TOOLKIT_SCROLL_BARS
5028 xg_update_scrollbar_pos (f
,
5029 SCROLL_BAR_X_WINDOW (bar
),
5031 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5032 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5034 #else /* not USE_GTK */
5036 /* Since toolkit scroll bars are smaller than the space reserved
5037 for them on the frame, we have to clear "under" them. */
5038 if (width
> 0 && height
> 0)
5039 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5040 left
, top
, width
, height
, False
);
5041 /* Move/size the scroll bar widget. */
5043 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5044 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5046 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5047 max (height
, 1), 0);
5049 #endif /* not USE_GTK */
5050 #else /* not USE_TOOLKIT_SCROLL_BARS */
5052 /* Clear areas not covered by the scroll bar because of
5053 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5054 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5056 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5057 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5059 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5060 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5061 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5065 /* Clear areas not covered by the scroll bar because it's not as
5066 wide as the area reserved for it. This makes sure a
5067 previous mode line display is cleared after C-x 2 C-x 1, for
5070 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
5071 int rest
= area_width
- sb_width
;
5072 if (rest
> 0 && height
> 0)
5074 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
5075 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5076 left
+ area_width
- rest
, top
,
5077 rest
, height
, False
);
5079 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5080 left
, top
, rest
, height
, False
);
5084 /* Move/size the scroll bar window. */
5089 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5091 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5093 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
5097 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5099 /* Remember new settings. */
5100 XSETINT (bar
->left
, sb_left
);
5101 XSETINT (bar
->top
, top
);
5102 XSETINT (bar
->width
, sb_width
);
5103 XSETINT (bar
->height
, height
);
5108 #ifdef USE_TOOLKIT_SCROLL_BARS
5109 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5110 #else /* not USE_TOOLKIT_SCROLL_BARS */
5111 /* Set the scroll bar's current state, unless we're currently being
5113 if (NILP (bar
->dragging
))
5115 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5118 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5121 int start
= ((double) position
* top_range
) / whole
;
5122 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5123 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5126 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5128 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5132 /* The following three hooks are used when we're doing a thorough
5133 redisplay of the frame. We don't explicitly know which scroll bars
5134 are going to be deleted, because keeping track of when windows go
5135 away is a real pain - "Can you say set-window-configuration, boys
5136 and girls?" Instead, we just assert at the beginning of redisplay
5137 that *all* scroll bars are to be removed, and then save a scroll bar
5138 from the fiery pit when we actually redisplay its window. */
5140 /* Arrange for all scroll bars on FRAME to be removed at the next call
5141 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5142 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5145 XTcondemn_scroll_bars (frame
)
5148 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5149 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5152 bar
= FRAME_SCROLL_BARS (frame
);
5153 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5154 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5155 XSCROLL_BAR (bar
)->prev
= Qnil
;
5156 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5157 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5158 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5163 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5164 Note that WINDOW isn't necessarily condemned at all. */
5167 XTredeem_scroll_bar (window
)
5168 struct window
*window
;
5170 struct scroll_bar
*bar
;
5173 /* We can't redeem this window's scroll bar if it doesn't have one. */
5174 if (NILP (window
->vertical_scroll_bar
))
5177 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5179 /* Unlink it from the condemned list. */
5180 f
= XFRAME (WINDOW_FRAME (window
));
5181 if (NILP (bar
->prev
))
5183 /* If the prev pointer is nil, it must be the first in one of
5185 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5186 /* It's not condemned. Everything's fine. */
5188 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5189 window
->vertical_scroll_bar
))
5190 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5192 /* If its prev pointer is nil, it must be at the front of
5193 one or the other! */
5197 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5199 if (! NILP (bar
->next
))
5200 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5202 bar
->next
= FRAME_SCROLL_BARS (f
);
5204 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5205 if (! NILP (bar
->next
))
5206 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5209 /* Remove all scroll bars on FRAME that haven't been saved since the
5210 last call to `*condemn_scroll_bars_hook'. */
5213 XTjudge_scroll_bars (f
)
5216 Lisp_Object bar
, next
;
5218 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5220 /* Clear out the condemned list now so we won't try to process any
5221 more events on the hapless scroll bars. */
5222 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5224 for (; ! NILP (bar
); bar
= next
)
5226 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5228 x_scroll_bar_remove (b
);
5231 b
->next
= b
->prev
= Qnil
;
5234 /* Now there should be no references to the condemned scroll bars,
5235 and they should get garbage-collected. */
5239 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5240 is a no-op when using toolkit scroll bars.
5242 This may be called from a signal handler, so we have to ignore GC
5246 x_scroll_bar_expose (bar
, event
)
5247 struct scroll_bar
*bar
;
5250 #ifndef USE_TOOLKIT_SCROLL_BARS
5252 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5253 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5254 GC gc
= f
->output_data
.x
->normal_gc
;
5255 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5259 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
5261 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5262 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5264 /* x, y, width, height */
5266 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
5267 XINT (bar
->height
) - 1);
5271 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5274 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5275 is set to something other than NO_EVENT, it is enqueued.
5277 This may be called from a signal handler, so we have to ignore GC
5282 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5283 struct scroll_bar
*bar
;
5285 struct input_event
*emacs_event
;
5287 if (! GC_WINDOWP (bar
->window
))
5290 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5291 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5292 emacs_event
->modifiers
5293 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5294 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5295 event
->xbutton
.state
)
5296 | (event
->type
== ButtonRelease
5299 emacs_event
->frame_or_window
= bar
->window
;
5300 emacs_event
->arg
= Qnil
;
5301 emacs_event
->timestamp
= event
->xbutton
.time
;
5304 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5306 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5309 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5310 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5313 if (y
> top_range
) y
= top_range
;
5315 if (y
< XINT (bar
->start
))
5316 emacs_event
->part
= scroll_bar_above_handle
;
5317 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5318 emacs_event
->part
= scroll_bar_handle
;
5320 emacs_event
->part
= scroll_bar_below_handle
;
5322 /* Just because the user has clicked on the handle doesn't mean
5323 they want to drag it. Lisp code needs to be able to decide
5324 whether or not we're dragging. */
5326 /* If the user has just clicked on the handle, record where they're
5328 if (event
->type
== ButtonPress
5329 && emacs_event
->part
== scroll_bar_handle
)
5330 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
5333 #ifndef USE_TOOLKIT_SCROLL_BARS
5334 /* If the user has released the handle, set it to its final position. */
5335 if (event
->type
== ButtonRelease
5336 && ! NILP (bar
->dragging
))
5338 int new_start
= y
- XINT (bar
->dragging
);
5339 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5341 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5342 bar
->dragging
= Qnil
;
5346 /* Same deal here as the other #if 0. */
5348 /* Clicks on the handle are always reported as occurring at the top of
5350 if (emacs_event
->part
== scroll_bar_handle
)
5351 emacs_event
->x
= bar
->start
;
5353 XSETINT (emacs_event
->x
, y
);
5355 XSETINT (emacs_event
->x
, y
);
5358 XSETINT (emacs_event
->y
, top_range
);
5362 #ifndef USE_TOOLKIT_SCROLL_BARS
5364 /* Handle some mouse motion while someone is dragging the scroll bar.
5366 This may be called from a signal handler, so we have to ignore GC
5370 x_scroll_bar_note_movement (bar
, event
)
5371 struct scroll_bar
*bar
;
5374 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5376 last_mouse_movement_time
= event
->xmotion
.time
;
5379 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5381 /* If we're dragging the bar, display it. */
5382 if (! GC_NILP (bar
->dragging
))
5384 /* Where should the handle be now? */
5385 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5387 if (new_start
!= XINT (bar
->start
))
5389 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5391 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5396 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5398 /* Return information to the user about the current position of the mouse
5399 on the scroll bar. */
5402 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5404 Lisp_Object
*bar_window
;
5405 enum scroll_bar_part
*part
;
5407 unsigned long *time
;
5409 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5410 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5411 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5413 Window dummy_window
;
5415 unsigned int dummy_mask
;
5419 /* Get the mouse's position relative to the scroll bar window, and
5421 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5423 /* Root, child, root x and root y. */
5424 &dummy_window
, &dummy_window
,
5425 &dummy_coord
, &dummy_coord
,
5427 /* Position relative to scroll bar. */
5430 /* Mouse buttons and modifier keys. */
5437 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5440 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5442 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5444 if (! NILP (bar
->dragging
))
5445 win_y
-= XINT (bar
->dragging
);
5449 if (win_y
> top_range
)
5453 *bar_window
= bar
->window
;
5455 if (! NILP (bar
->dragging
))
5456 *part
= scroll_bar_handle
;
5457 else if (win_y
< XINT (bar
->start
))
5458 *part
= scroll_bar_above_handle
;
5459 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5460 *part
= scroll_bar_handle
;
5462 *part
= scroll_bar_below_handle
;
5464 XSETINT (*x
, win_y
);
5465 XSETINT (*y
, top_range
);
5468 last_mouse_scroll_bar
= Qnil
;
5471 *time
= last_mouse_movement_time
;
5477 /* The screen has been cleared so we may have changed foreground or
5478 background colors, and the scroll bars may need to be redrawn.
5479 Clear out the scroll bars, and ask for expose events, so we can
5483 x_scroll_bar_clear (f
)
5486 #ifndef USE_TOOLKIT_SCROLL_BARS
5489 /* We can have scroll bars even if this is 0,
5490 if we just turned off scroll bar mode.
5491 But in that case we should not clear them. */
5492 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5493 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5494 bar
= XSCROLL_BAR (bar
)->next
)
5495 XClearArea (FRAME_X_DISPLAY (f
),
5496 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
5498 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5502 /* Define a queue to save up SelectionRequest events for later handling. */
5504 struct selection_event_queue
5507 struct selection_event_queue
*next
;
5510 static struct selection_event_queue
*queue
;
5512 /* Nonzero means queue up certain events--don't process them yet. */
5514 static int x_queue_selection_requests
;
5516 /* Queue up an X event *EVENT, to be processed later. */
5519 x_queue_event (f
, event
)
5523 struct selection_event_queue
*queue_tmp
5524 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
5526 if (queue_tmp
!= NULL
)
5528 queue_tmp
->event
= *event
;
5529 queue_tmp
->next
= queue
;
5534 /* Take all the queued events and put them back
5535 so that they get processed afresh. */
5538 x_unqueue_events (display
)
5541 while (queue
!= NULL
)
5543 struct selection_event_queue
*queue_tmp
= queue
;
5544 XPutBackEvent (display
, &queue_tmp
->event
);
5545 queue
= queue_tmp
->next
;
5546 xfree ((char *)queue_tmp
);
5550 /* Start queuing SelectionRequest events. */
5553 x_start_queuing_selection_requests (display
)
5556 x_queue_selection_requests
++;
5559 /* Stop queuing SelectionRequest events. */
5562 x_stop_queuing_selection_requests (display
)
5565 x_queue_selection_requests
--;
5566 x_unqueue_events (display
);
5569 /* The main X event-reading loop - XTread_socket. */
5572 /* Time stamp of enter window event. This is only used by XTread_socket,
5573 but we have to put it out here, since static variables within functions
5574 sometimes don't work. */
5576 static Time enter_timestamp
;
5579 /* This holds the state XLookupString needs to implement dead keys
5580 and other tricks known as "compose processing". _X Window System_
5581 says that a portable program can't use this, but Stephen Gildea assures
5582 me that letting the compiler initialize it to zeros will work okay.
5584 This must be defined outside of XTread_socket, for the same reasons
5585 given for enter_timestamp, above. */
5587 static XComposeStatus compose_status
;
5589 /* Record the last 100 characters stored
5590 to help debug the loss-of-chars-during-GC problem. */
5592 static int temp_index
;
5593 static short temp_buffer
[100];
5595 /* Set this to nonzero to fake an "X I/O error"
5596 on a particular display. */
5598 struct x_display_info
*XTread_socket_fake_io_error
;
5600 /* When we find no input here, we occasionally do a no-op command
5601 to verify that the X server is still running and we can still talk with it.
5602 We try all the open displays, one by one.
5603 This variable is used for cycling thru the displays. */
5605 static struct x_display_info
*next_noop_dpyinfo
;
5607 #define SET_SAVED_MENU_EVENT(size) \
5610 if (f->output_data.x->saved_menu_event == 0) \
5611 f->output_data.x->saved_menu_event \
5612 = (XEvent *) xmalloc (sizeof (XEvent)); \
5613 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5614 if (numchars >= 1) \
5616 bufp->kind = MENU_BAR_ACTIVATE_EVENT; \
5617 XSETFRAME (bufp->frame_or_window, f); \
5626 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5627 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5637 /* Filter events for the current X input method.
5638 DPYINFO is the display this event is for.
5639 EVENT is the X event to filter.
5641 Returns non-zero if the event was filtered, caller shall not process
5643 Returns zero if event is wasn't filtered. */
5647 x_filter_event (dpyinfo
, event
)
5648 struct x_display_info
*dpyinfo
;
5651 /* XFilterEvent returns non-zero if the input method has
5652 consumed the event. We pass the frame's X window to
5653 XFilterEvent because that's the one for which the IC
5656 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5657 event
->xclient
.window
);
5659 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5664 static struct x_display_info
*current_dpyinfo
;
5665 static struct input_event
**current_bufp
;
5666 static int *current_numcharsp
;
5667 static int current_count
;
5668 static int current_finish
;
5670 /* This is the filter function invoked by the GTK event loop.
5671 It is invoked before the XEvent is translated to a GdkEvent,
5672 so we have a chanse to act on the event before GTK. */
5673 static GdkFilterReturn
5674 event_handler_gdk (gxev
, ev
, data
)
5679 XEvent
*xev
= (XEvent
*)gxev
;
5681 if (current_numcharsp
)
5684 /* Filter events for the current X input method.
5685 GTK calls XFilterEvent but not for key press and release,
5686 so we do it here. */
5687 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5688 if (x_filter_event (current_dpyinfo
, xev
))
5689 return GDK_FILTER_REMOVE
;
5691 current_count
+= handle_one_xevent (current_dpyinfo
,
5698 current_finish
= x_dispatch_event (xev
, GDK_DISPLAY ());
5700 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5701 return GDK_FILTER_REMOVE
;
5703 return GDK_FILTER_CONTINUE
;
5705 #endif /* USE_GTK */
5708 /* Handles the XEvent EVENT on display DPYINFO.
5710 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5711 *FINISH is zero if caller should continue reading events.
5712 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5714 Events representing keys are stored in buffer *BUFP_R,
5715 which can hold up to *NUMCHARSP characters.
5716 We return the number of characters stored into the buffer. */
5719 handle_one_xevent (dpyinfo
, eventp
, bufp_r
, numcharsp
, finish
)
5720 struct x_display_info
*dpyinfo
;
5722 /* register */ struct input_event
**bufp_r
;
5723 /* register */ int *numcharsp
;
5729 struct coding_system coding
;
5730 struct input_event
*bufp
= *bufp_r
;
5731 int numchars
= *numcharsp
;
5732 XEvent event
= *eventp
;
5734 *finish
= X_EVENT_NORMAL
;
5740 if (event
.xclient
.message_type
5741 == dpyinfo
->Xatom_wm_protocols
5742 && event
.xclient
.format
== 32)
5744 if (event
.xclient
.data
.l
[0]
5745 == dpyinfo
->Xatom_wm_take_focus
)
5747 /* Use x_any_window_to_frame because this
5748 could be the shell widget window
5749 if the frame has no title bar. */
5750 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5752 /* Not quite sure this is needed -pd */
5753 if (f
&& FRAME_XIC (f
))
5754 XSetICFocus (FRAME_XIC (f
));
5756 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5757 instructs the WM to set the input focus automatically for
5758 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5759 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5760 it has set the focus. So, XSetInputFocus below is not
5763 The call to XSetInputFocus below has also caused trouble. In
5764 cases where the XSetInputFocus done by the WM and the one
5765 below are temporally close (on a fast machine), the call
5766 below can generate additional FocusIn events which confuse
5769 /* Since we set WM_TAKE_FOCUS, we must call
5770 XSetInputFocus explicitly. But not if f is null,
5771 since that might be an event for a deleted frame. */
5774 Display
*d
= event
.xclient
.display
;
5775 /* Catch and ignore errors, in case window has been
5776 iconified by a window manager such as GWM. */
5777 int count
= x_catch_errors (d
);
5778 XSetInputFocus (d
, event
.xclient
.window
,
5779 /* The ICCCM says this is
5780 the only valid choice. */
5782 event
.xclient
.data
.l
[1]);
5783 /* This is needed to detect the error
5784 if there is an error. */
5786 x_uncatch_errors (d
, count
);
5788 /* Not certain about handling scroll bars here */
5791 else if (event
.xclient
.data
.l
[0]
5792 == dpyinfo
->Xatom_wm_save_yourself
)
5794 /* Save state modify the WM_COMMAND property to
5795 something which can reinstate us. This notifies
5796 the session manager, who's looking for such a
5797 PropertyNotify. Can restart processing when
5798 a keyboard or mouse event arrives. */
5799 /* If we have a session manager, don't set this.
5800 KDE will then start two Emacsen, one for the
5801 session manager and one for this. */
5804 && ! x_session_have_connection ()
5808 f
= x_top_window_to_frame (dpyinfo
,
5809 event
.xclient
.window
);
5810 /* This is just so we only give real data once
5811 for a single Emacs process. */
5812 if (f
== SELECTED_FRAME ())
5813 XSetCommand (FRAME_X_DISPLAY (f
),
5814 event
.xclient
.window
,
5815 initial_argv
, initial_argc
);
5817 XSetCommand (FRAME_X_DISPLAY (f
),
5818 event
.xclient
.window
,
5822 else if (event
.xclient
.data
.l
[0]
5823 == dpyinfo
->Xatom_wm_delete_window
)
5826 = x_any_window_to_frame (dpyinfo
,
5827 event
.xclient
.window
);
5834 bufp
->kind
= DELETE_WINDOW_EVENT
;
5835 XSETFRAME (bufp
->frame_or_window
, f
);
5843 goto OTHER
; /* May be a dialog that is to be removed */
5846 else if (event
.xclient
.message_type
5847 == dpyinfo
->Xatom_wm_configure_denied
)
5850 else if (event
.xclient
.message_type
5851 == dpyinfo
->Xatom_wm_window_moved
)
5855 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5857 new_x
= event
.xclient
.data
.s
[0];
5858 new_y
= event
.xclient
.data
.s
[1];
5862 f
->output_data
.x
->left_pos
= new_x
;
5863 f
->output_data
.x
->top_pos
= new_y
;
5867 else if (event
.xclient
.message_type
5868 == dpyinfo
->Xatom_editres
)
5871 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5872 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5875 #endif /* HACK_EDITRES */
5876 else if ((event
.xclient
.message_type
5877 == dpyinfo
->Xatom_DONE
)
5878 || (event
.xclient
.message_type
5879 == dpyinfo
->Xatom_PAGE
))
5881 /* Ghostview job completed. Kill it. We could
5882 reply with "Next" if we received "Page", but we
5883 currently never do because we are interested in
5884 images, only, which should have 1 page. */
5885 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5887 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5888 x_kill_gs_process (pixmap
, f
);
5889 expose_frame (f
, 0, 0, 0, 0);
5891 #ifdef USE_TOOLKIT_SCROLL_BARS
5892 /* Scroll bar callbacks send a ClientMessage from which
5893 we construct an input_event. */
5894 else if (event
.xclient
.message_type
5895 == dpyinfo
->Xatom_Scrollbar
)
5897 x_scroll_bar_to_input_event (&event
, bufp
);
5898 ++bufp
, ++count
, --numchars
;
5901 #endif /* USE_TOOLKIT_SCROLL_BARS */
5907 case SelectionNotify
:
5908 #ifdef USE_X_TOOLKIT
5909 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5911 #endif /* not USE_X_TOOLKIT */
5912 x_handle_selection_notify (&event
.xselection
);
5915 case SelectionClear
: /* Someone has grabbed ownership. */
5916 #ifdef USE_X_TOOLKIT
5917 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5919 #endif /* USE_X_TOOLKIT */
5921 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
5926 bufp
->kind
= SELECTION_CLEAR_EVENT
;
5927 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
5928 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
5929 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
5930 bufp
->frame_or_window
= Qnil
;
5939 case SelectionRequest
: /* Someone wants our selection. */
5940 #ifdef USE_X_TOOLKIT
5941 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
5943 #endif /* USE_X_TOOLKIT */
5944 if (x_queue_selection_requests
)
5945 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
5949 XSelectionRequestEvent
*eventp
5950 = (XSelectionRequestEvent
*) &event
;
5955 bufp
->kind
= SELECTION_REQUEST_EVENT
;
5956 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
5957 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
5958 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
5959 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
5960 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
5961 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
5962 bufp
->frame_or_window
= Qnil
;
5971 case PropertyNotify
:
5972 #if 0 /* This is plain wrong. In the case that we are waiting for a
5973 PropertyNotify used as an ACK in incremental selection
5974 transfer, the property will be on the receiver's window. */
5975 #if defined USE_X_TOOLKIT
5976 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
5980 x_handle_property_notify (&event
.xproperty
);
5983 case ReparentNotify
:
5984 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
5988 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
5989 x_real_positions (f
, &x
, &y
);
5990 f
->output_data
.x
->left_pos
= x
;
5991 f
->output_data
.x
->top_pos
= y
;
5997 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6000 x_check_fullscreen (f
);
6002 if (f
->async_visible
== 0)
6004 f
->async_visible
= 1;
6005 f
->async_iconified
= 0;
6006 f
->output_data
.x
->has_been_visible
= 1;
6007 SET_FRAME_GARBAGED (f
);
6010 expose_frame (x_window_to_frame (dpyinfo
,
6011 event
.xexpose
.window
),
6012 event
.xexpose
.x
, event
.xexpose
.y
,
6013 event
.xexpose
.width
, event
.xexpose
.height
);
6017 #ifndef USE_TOOLKIT_SCROLL_BARS
6018 struct scroll_bar
*bar
;
6020 #if defined USE_LUCID
6021 /* Submenus of the Lucid menu bar aren't widgets
6022 themselves, so there's no way to dispatch events
6023 to them. Recognize this case separately. */
6026 = x_window_to_menu_bar (event
.xexpose
.window
);
6028 xlwmenu_redisplay (widget
);
6030 #endif /* USE_LUCID */
6032 #ifdef USE_TOOLKIT_SCROLL_BARS
6033 /* Dispatch event to the widget. */
6035 #else /* not USE_TOOLKIT_SCROLL_BARS */
6036 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
6039 x_scroll_bar_expose (bar
, &event
);
6040 #ifdef USE_X_TOOLKIT
6043 #endif /* USE_X_TOOLKIT */
6044 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6048 case GraphicsExpose
: /* This occurs when an XCopyArea's
6049 source area was obscured or not
6051 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6055 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6056 event
.xgraphicsexpose
.width
,
6057 event
.xgraphicsexpose
.height
);
6059 #ifdef USE_X_TOOLKIT
6062 #endif /* USE_X_TOOLKIT */
6065 case NoExpose
: /* This occurs when an XCopyArea's
6066 source area was completely
6071 /* Redo the mouse-highlight after the tooltip has gone. */
6072 if (event
.xmap
.window
== tip_window
)
6075 redo_mouse_highlight ();
6078 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6079 if (f
) /* F may no longer exist if
6080 the frame was deleted. */
6082 /* While a frame is unmapped, display generation is
6083 disabled; you don't want to spend time updating a
6084 display that won't ever be seen. */
6085 f
->async_visible
= 0;
6086 /* We can't distinguish, from the event, whether the window
6087 has become iconified or invisible. So assume, if it
6088 was previously visible, than now it is iconified.
6089 But x_make_frame_invisible clears both
6090 the visible flag and the iconified flag;
6091 and that way, we know the window is not iconified now. */
6092 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6094 f
->async_iconified
= 1;
6096 bufp
->kind
= ICONIFY_EVENT
;
6097 XSETFRAME (bufp
->frame_or_window
, f
);
6107 if (event
.xmap
.window
== tip_window
)
6108 /* The tooltip has been drawn already. Avoid
6109 the SET_FRAME_GARBAGED below. */
6112 /* We use x_top_window_to_frame because map events can
6113 come for sub-windows and they don't mean that the
6114 frame is visible. */
6115 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6118 /* wait_reading_process_input will notice this and update
6119 the frame's display structures.
6120 If we where iconified, we should not set garbaged,
6121 because that stops redrawing on Expose events. This looks
6122 bad if we are called from a recursive event loop
6123 (x_dispatch_event), for example when a dialog is up. */
6124 if (! f
->async_iconified
)
6125 SET_FRAME_GARBAGED (f
);
6127 f
->async_visible
= 1;
6128 f
->async_iconified
= 0;
6129 f
->output_data
.x
->has_been_visible
= 1;
6133 bufp
->kind
= DEICONIFY_EVENT
;
6134 XSETFRAME (bufp
->frame_or_window
, f
);
6140 else if (! NILP (Vframe_list
)
6141 && ! NILP (XCDR (Vframe_list
)))
6142 /* Force a redisplay sooner or later
6143 to update the frame titles
6144 in case this is the second frame. */
6145 record_asynch_buffer_change ();
6151 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6152 /* Dispatch KeyPress events when in menu. */
6153 if (popup_activated ())
6157 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6159 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
6161 dpyinfo
->mouse_face_hidden
= 1;
6162 clear_mouse_face (dpyinfo
);
6165 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6168 /* Scroll bars consume key events, but we want
6169 the keys to go to the scroll bar's frame. */
6170 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6172 if (widget
&& XmIsScrollBar (widget
))
6174 widget
= XtParent (widget
);
6175 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6178 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6182 KeySym keysym
, orig_keysym
;
6183 /* al%imercury@uunet.uu.net says that making this 81
6184 instead of 80 fixed a bug whereby meta chars made
6187 It seems that some version of XmbLookupString has
6188 a bug of not returning XBufferOverflow in
6189 status_return even if the input is too long to
6190 fit in 81 bytes. So, we must prepare sufficient
6191 bytes for copy_buffer. 513 bytes (256 chars for
6192 two-byte character set) seems to be a fairly good
6193 approximation. -- 2000.8.10 handa@etl.go.jp */
6194 unsigned char copy_buffer
[513];
6195 unsigned char *copy_bufptr
= copy_buffer
;
6196 int copy_bufsiz
= sizeof (copy_buffer
);
6198 Lisp_Object coding_system
= Qlatin_1
;
6201 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6202 extra_keyboard_modifiers
);
6203 modifiers
= event
.xkey
.state
;
6205 /* This will have to go some day... */
6207 /* make_lispy_event turns chars into control chars.
6208 Don't do it here because XLookupString is too eager. */
6209 event
.xkey
.state
&= ~ControlMask
;
6210 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6211 | dpyinfo
->super_mod_mask
6212 | dpyinfo
->hyper_mod_mask
6213 | dpyinfo
->alt_mod_mask
);
6215 /* In case Meta is ComposeCharacter,
6216 clear its status. According to Markus Ehrnsperger
6217 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6218 this enables ComposeCharacter to work whether or
6219 not it is combined with Meta. */
6220 if (modifiers
& dpyinfo
->meta_mod_mask
)
6221 bzero (&compose_status
, sizeof (compose_status
));
6226 Status status_return
;
6228 coding_system
= Vlocale_coding_system
;
6229 nbytes
= XmbLookupString (FRAME_XIC (f
),
6230 &event
.xkey
, copy_bufptr
,
6231 copy_bufsiz
, &keysym
,
6233 if (status_return
== XBufferOverflow
)
6235 copy_bufsiz
= nbytes
+ 1;
6236 copy_bufptr
= (char *) alloca (copy_bufsiz
);
6237 nbytes
= XmbLookupString (FRAME_XIC (f
),
6238 &event
.xkey
, copy_bufptr
,
6239 copy_bufsiz
, &keysym
,
6242 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6243 #if 0 && defined X_HAVE_UTF8_STRING
6244 else if (status_return
== XLookupKeySym
)
6245 { /* Try again but with utf-8. */
6246 coding_system
= Qutf_8
;
6247 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6248 &event
.xkey
, copy_bufptr
,
6249 copy_bufsiz
, &keysym
,
6251 if (status_return
== XBufferOverflow
)
6253 copy_bufsiz
= nbytes
+ 1;
6254 copy_bufptr
= (char *) alloca (copy_bufsiz
);
6255 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6258 copy_bufsiz
, &keysym
,
6264 if (status_return
== XLookupNone
)
6266 else if (status_return
== XLookupChars
)
6271 else if (status_return
!= XLookupKeySym
6272 && status_return
!= XLookupBoth
)
6276 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6277 copy_bufsiz
, &keysym
,
6280 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6281 copy_bufsiz
, &keysym
,
6285 orig_keysym
= keysym
;
6291 /* First deal with keysyms which have defined
6292 translations to characters. */
6293 if (keysym
>= 32 && keysym
< 128)
6294 /* Avoid explicitly decoding each ASCII character. */
6296 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
6297 bufp
->code
= keysym
;
6298 XSETFRAME (bufp
->frame_or_window
, f
);
6301 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6303 bufp
->timestamp
= event
.xkey
.time
;
6308 /* Now non-ASCII. */
6309 else if (HASH_TABLE_P (Vx_keysym_table
)
6310 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6314 bufp
->kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6315 ? ASCII_KEYSTROKE_EVENT
6316 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6317 bufp
->code
= XFASTINT (c
);
6318 XSETFRAME (bufp
->frame_or_window
, f
);
6321 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6323 bufp
->timestamp
= event
.xkey
.time
;
6328 /* Random non-modifier sorts of keysyms. */
6329 else if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6330 || keysym
== XK_Delete
6331 #ifdef XK_ISO_Left_Tab
6332 || (keysym
>= XK_ISO_Left_Tab
6333 && keysym
<= XK_ISO_Enter
)
6335 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6336 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6338 /* This recognizes the "extended function
6339 keys". It seems there's no cleaner way.
6340 Test IsModifierKey to avoid handling
6341 mode_switch incorrectly. */
6342 || ((unsigned) (keysym
) >= XK_Select
6343 && (unsigned)(keysym
) < XK_KP_Space
)
6345 #ifdef XK_dead_circumflex
6346 || orig_keysym
== XK_dead_circumflex
6348 #ifdef XK_dead_grave
6349 || orig_keysym
== XK_dead_grave
6351 #ifdef XK_dead_tilde
6352 || orig_keysym
== XK_dead_tilde
6354 #ifdef XK_dead_diaeresis
6355 || orig_keysym
== XK_dead_diaeresis
6357 #ifdef XK_dead_macron
6358 || orig_keysym
== XK_dead_macron
6360 #ifdef XK_dead_degree
6361 || orig_keysym
== XK_dead_degree
6363 #ifdef XK_dead_acute
6364 || orig_keysym
== XK_dead_acute
6366 #ifdef XK_dead_cedilla
6367 || orig_keysym
== XK_dead_cedilla
6369 #ifdef XK_dead_breve
6370 || orig_keysym
== XK_dead_breve
6372 #ifdef XK_dead_ogonek
6373 || orig_keysym
== XK_dead_ogonek
6375 #ifdef XK_dead_caron
6376 || orig_keysym
== XK_dead_caron
6378 #ifdef XK_dead_doubleacute
6379 || orig_keysym
== XK_dead_doubleacute
6381 #ifdef XK_dead_abovedot
6382 || orig_keysym
== XK_dead_abovedot
6384 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6385 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6386 /* Any "vendor-specific" key is ok. */
6387 || (orig_keysym
& (1 << 28))
6388 || (keysym
!= NoSymbol
&& nbytes
== 0))
6389 && ! (IsModifierKey (orig_keysym
)
6391 #ifdef XK_Mode_switch
6392 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
6395 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
6397 #endif /* not HAVE_X11R5 */
6398 /* The symbols from XK_ISO_Lock
6399 to XK_ISO_Last_Group_Lock
6400 don't have real modifiers but
6401 should be treated similarly to
6402 Mode_switch by Emacs. */
6403 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6404 || ((unsigned)(orig_keysym
)
6406 && (unsigned)(orig_keysym
)
6407 <= XK_ISO_Last_Group_Lock
)
6411 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
6413 temp_buffer
[temp_index
++] = keysym
;
6414 /* make_lispy_event will convert this to a symbolic
6416 bufp
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
6417 bufp
->code
= keysym
;
6418 XSETFRAME (bufp
->frame_or_window
, f
);
6421 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6423 bufp
->timestamp
= event
.xkey
.time
;
6428 else if (numchars
> nbytes
)
6429 { /* Raw bytes, not keysym. */
6434 /* The input should be decoded with `coding_system'
6435 which depends on which X*LookupString function
6436 we used just above and the locale. */
6437 setup_coding_system (coding_system
, &coding
);
6438 coding
.src_multibyte
= 0;
6439 coding
.dst_multibyte
= 1;
6440 /* The input is converted to events, thus we can't
6441 handle composition. Anyway, there's no XIM that
6442 gives us composition information. */
6443 coding
.composing
= COMPOSITION_DISABLED
;
6445 for (i
= 0; i
< nbytes
; i
++)
6447 if (temp_index
== (sizeof temp_buffer
6450 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
6454 /* Decode the input data. */
6458 require
= decoding_buffer_size (&coding
, nbytes
);
6459 p
= (unsigned char *) alloca (require
);
6460 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6461 /* We explicitely disable composition
6462 handling because key data should
6463 not contain any composition
6465 coding
.composing
= COMPOSITION_DISABLED
;
6466 decode_coding (&coding
, copy_bufptr
, p
,
6468 nbytes
= coding
.produced
;
6469 nchars
= coding
.produced_char
;
6473 /* Convert the input data to a sequence of
6474 character events. */
6475 for (i
= 0; i
< nbytes
; i
+= len
)
6477 if (nchars
== nbytes
)
6478 c
= copy_bufptr
[i
], len
= 1;
6480 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6483 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
6484 ? ASCII_KEYSTROKE_EVENT
6485 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6487 XSETFRAME (bufp
->frame_or_window
, f
);
6490 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6492 bufp
->timestamp
= event
.xkey
.time
;
6499 if (keysym
== NoSymbol
)
6509 /* Don't dispatch this event since XtDispatchEvent calls
6510 XFilterEvent, and two calls in a row may freeze the
6519 /* Don't dispatch this event since XtDispatchEvent calls
6520 XFilterEvent, and two calls in a row may freeze the
6531 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6534 bufp
+= n
, count
+= n
, numchars
-= n
;
6537 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6540 if (event
.xcrossing
.focus
)
6542 /* Avoid nasty pop/raise loops. */
6543 if (f
&& (!(f
->auto_raise
)
6545 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6547 x_new_focus_frame (dpyinfo
, f
);
6548 enter_timestamp
= event
.xcrossing
.time
;
6551 else if (f
== dpyinfo
->x_focus_frame
)
6552 x_new_focus_frame (dpyinfo
, 0);
6555 /* EnterNotify counts as mouse movement,
6556 so update things that depend on mouse position. */
6557 if (f
&& !f
->output_data
.x
->hourglass_p
)
6558 note_mouse_movement (f
, &event
.xmotion
);
6566 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6569 bufp
+= n
, count
+= n
, numchars
-= n
;
6579 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6582 bufp
+= n
, count
+= n
, numchars
-= n
;
6586 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6589 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6591 /* If we move outside the frame, then we're
6592 certainly no longer on any text in the frame. */
6593 clear_mouse_face (dpyinfo
);
6594 dpyinfo
->mouse_face_mouse_frame
= 0;
6597 /* Generate a nil HELP_EVENT to cancel a help-echo.
6598 Do it only if there's something to cancel.
6599 Otherwise, the startup message is cleared when
6600 the mouse leaves the frame. */
6601 if (any_help_event_p
)
6606 XSETFRAME (frame
, f
);
6607 help_echo_string
= Qnil
;
6608 n
= gen_help_event (bufp
, numchars
,
6609 Qnil
, frame
, Qnil
, Qnil
, 0);
6610 bufp
+= n
, count
+= n
, numchars
-= n
;
6620 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6623 bufp
+= n
, count
+= n
, numchars
-= n
;
6631 previous_help_echo_string
= help_echo_string
;
6632 help_echo_string
= help_echo_object
= help_echo_window
= Qnil
;
6635 if (dpyinfo
->grabbed
&& last_mouse_frame
6636 && FRAME_LIVE_P (last_mouse_frame
))
6637 f
= last_mouse_frame
;
6639 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6641 if (dpyinfo
->mouse_face_hidden
)
6643 dpyinfo
->mouse_face_hidden
= 0;
6644 clear_mouse_face (dpyinfo
);
6650 /* Generate SELECT_WINDOW_EVENTs when needed. */
6651 if (mouse_autoselect_window
)
6655 window
= window_from_coordinates (f
,
6656 event
.xmotion
.x
, event
.xmotion
.y
,
6659 /* Window will be selected only when it is not selected now and
6660 last mouse movement event was not in it. Minibuffer window
6661 will be selected iff it is active. */
6663 && !EQ (window
, last_window
)
6664 && !EQ (window
, selected_window
)
6667 bufp
->kind
= SELECT_WINDOW_EVENT
;
6668 bufp
->frame_or_window
= window
;
6670 ++bufp
, ++count
, --numchars
;
6675 note_mouse_movement (f
, &event
.xmotion
);
6679 #ifndef USE_TOOLKIT_SCROLL_BARS
6680 struct scroll_bar
*bar
6681 = x_window_to_scroll_bar (event
.xmotion
.window
);
6684 x_scroll_bar_note_movement (bar
, &event
);
6685 #endif /* USE_TOOLKIT_SCROLL_BARS */
6687 /* If we move outside the frame, then we're
6688 certainly no longer on any text in the frame. */
6689 clear_mouse_face (dpyinfo
);
6692 /* If the contents of the global variable help_echo_string
6693 has changed, generate a HELP_EVENT. */
6694 if (!NILP (help_echo_string
)
6695 || !NILP (previous_help_echo_string
))
6701 XSETFRAME (frame
, f
);
6705 any_help_event_p
= 1;
6706 n
= gen_help_event (bufp
, numchars
, help_echo_string
, frame
,
6707 help_echo_window
, help_echo_object
,
6709 bufp
+= n
, count
+= n
, numchars
-= n
;
6715 case ConfigureNotify
:
6716 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6719 #ifndef USE_X_TOOLKIT
6721 xg_resize_widgets (f
, event
.xconfigure
.width
,
6722 event
.xconfigure
.height
);
6723 #else /* not USE_GTK */
6724 /* If there is a pending resize for fullscreen, don't
6725 do this one, the right one will come later.
6726 The toolkit version doesn't seem to need this, but we
6727 need to reset it below. */
6729 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
6730 && FRAME_NEW_WIDTH (f
) != 0);
6731 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
6732 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
6736 /* In the toolkit version, change_frame_size
6737 is called by the code that handles resizing
6738 of the EmacsFrame widget. */
6740 /* Even if the number of character rows and columns has
6741 not changed, the font size may have changed, so we need
6742 to check the pixel dimensions as well. */
6743 if (columns
!= f
->width
6744 || rows
!= f
->height
6745 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
6746 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
6748 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6749 SET_FRAME_GARBAGED (f
);
6750 cancel_mouse_face (f
);
6752 #endif /* not USE_GTK */
6755 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
6756 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
6759 /* GTK creates windows but doesn't map them.
6760 Only get real positions and check fullscreen when mapped. */
6761 if (FRAME_GTK_OUTER_WIDGET (f
)
6762 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
6765 /* What we have now is the position of Emacs's own window.
6766 Convert that to the position of the window manager window. */
6767 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
6768 &f
->output_data
.x
->top_pos
);
6770 x_check_fullscreen_move (f
);
6771 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
6772 f
->output_data
.x
->want_fullscreen
&=
6773 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
6778 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6779 xic_set_statusarea (f
);
6782 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
6784 /* Since the WM decorations come below top_pos now,
6785 we must put them below top_pos in the future. */
6786 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
6787 x_wm_set_size_hint (f
, (long) 0, 0);
6795 /* If we decide we want to generate an event to be seen
6796 by the rest of Emacs, we put it here. */
6797 struct input_event emacs_event
;
6800 emacs_event
.kind
= NO_EVENT
;
6801 bzero (&compose_status
, sizeof (compose_status
));
6803 if (dpyinfo
->grabbed
6805 && FRAME_LIVE_P (last_mouse_frame
))
6806 f
= last_mouse_frame
;
6808 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6812 /* Is this in the tool-bar? */
6813 if (WINDOWP (f
->tool_bar_window
)
6814 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
6817 int x
= event
.xbutton
.x
;
6818 int y
= event
.xbutton
.y
;
6820 window
= window_from_coordinates (f
, x
, y
, 0, 1);
6821 if (EQ (window
, f
->tool_bar_window
))
6823 if (event
.xbutton
.type
== ButtonPress
)
6824 handle_tool_bar_click (f
, x
, y
, 1, 0);
6826 handle_tool_bar_click (f
, x
, y
, 0,
6827 x_x_to_emacs_modifiers (dpyinfo
,
6828 event
.xbutton
.state
));
6834 if (!dpyinfo
->x_focus_frame
6835 || f
== dpyinfo
->x_focus_frame
)
6837 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6838 if (! popup_activated ())
6840 construct_mouse_click (&emacs_event
, &event
, f
);
6845 struct scroll_bar
*bar
6846 = x_window_to_scroll_bar (event
.xbutton
.window
);
6848 #ifdef USE_TOOLKIT_SCROLL_BARS
6849 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6851 if (bar
&& event
.xbutton
.state
& ControlMask
)
6853 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
6854 *finish
= X_EVENT_DROP
;
6856 #else /* not USE_TOOLKIT_SCROLL_BARS */
6858 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
6859 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6862 if (event
.type
== ButtonPress
)
6864 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6865 last_mouse_frame
= f
;
6866 /* Ignore any mouse motion that happened
6867 before this event; any subsequent mouse-movement
6868 Emacs events should reflect only motion after
6874 last_tool_bar_item
= -1;
6877 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6879 if (numchars
>= 1 && emacs_event
.kind
!= NO_EVENT
)
6881 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
6887 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6888 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6889 /* For a down-event in the menu bar,
6890 don't pass it to Xt right now.
6891 Instead, save it away
6892 and we will pass it to Xt from kbd_buffer_get_event.
6893 That way, we can run some Lisp code first. */
6896 ! popup_activated ()
6899 f
&& event
.type
== ButtonPress
6900 /* Verify the event is really within the menu bar
6901 and not just sent to it due to grabbing. */
6902 && event
.xbutton
.x
>= 0
6903 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
6904 && event
.xbutton
.y
>= 0
6905 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6906 && event
.xbutton
.same_screen
)
6908 SET_SAVED_BUTTON_EVENT
;
6909 XSETFRAME (last_mouse_press_frame
, f
);
6911 *finish
= X_EVENT_DROP
;
6914 else if (event
.type
== ButtonPress
)
6916 last_mouse_press_frame
= Qnil
;
6920 #ifdef USE_MOTIF /* This should do not harm for Lucid,
6921 but I am trying to be cautious. */
6922 else if (event
.type
== ButtonRelease
)
6924 if (!NILP (last_mouse_press_frame
))
6926 f
= XFRAME (last_mouse_press_frame
);
6927 if (f
->output_data
.x
)
6928 SET_SAVED_BUTTON_EVENT
;
6933 #endif /* USE_MOTIF */
6936 #endif /* USE_X_TOOLKIT || USE_GTK */
6940 case CirculateNotify
:
6943 case CirculateRequest
:
6946 case VisibilityNotify
:
6950 /* Someone has changed the keyboard mapping - update the
6952 switch (event
.xmapping
.request
)
6954 case MappingModifier
:
6955 x_find_modifier_meanings (dpyinfo
);
6956 /* This is meant to fall through. */
6957 case MappingKeyboard
:
6958 XRefreshKeyboardMapping (&event
.xmapping
);
6964 #ifdef USE_X_TOOLKIT
6966 if (*finish
!= X_EVENT_DROP
)
6967 XtDispatchEvent (&event
);
6969 #endif /* USE_X_TOOLKIT */
6976 *finish
= X_EVENT_GOTO_OUT
;
6980 *numcharsp
= numchars
;
6987 /* Handles the XEvent EVENT on display DISPLAY.
6988 This is used for event loops outside the normal event handling,
6989 i.e. looping while a popup menu or a dialog is posted.
6991 Returns the value handle_one_xevent sets in the finish argument. */
6993 x_dispatch_event (event
, display
)
6997 struct x_display_info
*dpyinfo
;
6998 struct input_event bufp
[10];
6999 struct input_event
*bufpp
= bufp
;
7001 int finish
= X_EVENT_NORMAL
;
7003 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7004 if (dpyinfo
->display
== display
)
7010 events
= handle_one_xevent (dpyinfo
,
7015 for (i
= 0; i
< events
; ++i
)
7016 kbd_buffer_store_event (&bufp
[i
]);
7023 /* Read events coming from the X server.
7024 This routine is called by the SIGIO handler.
7025 We return as soon as there are no more events to be read.
7027 Events representing keys are stored in buffer BUFP,
7028 which can hold up to NUMCHARS characters.
7029 We return the number of characters stored into the buffer,
7030 thus pretending to be `read'.
7032 EXPECTED is nonzero if the caller knows input is available. */
7035 XTread_socket (sd
, bufp
, numchars
, expected
)
7037 /* register */ struct input_event
*bufp
;
7038 /* register */ int numchars
;
7044 int event_found
= 0;
7045 struct x_display_info
*dpyinfo
;
7047 if (interrupt_input_blocked
)
7049 interrupt_input_pending
= 1;
7053 interrupt_input_pending
= 0;
7056 /* So people can tell when we have read the available input. */
7057 input_signal_count
++;
7060 abort (); /* Don't think this happens. */
7064 /* Find the display we are supposed to read input for.
7065 It's the one communicating on descriptor SD. */
7066 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7068 #if 0 /* This ought to be unnecessary; let's verify it. */
7070 /* If available, Xlib uses FIOSNBIO to make the socket
7071 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
7072 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
7073 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
7074 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
7075 #endif /* ! defined (FIOSNBIO) */
7078 #if 0 /* This code can't be made to work, with multiple displays,
7079 and appears not to be used on any system any more.
7080 Also keyboard.c doesn't turn O_NDELAY on and off
7081 for X connections. */
7084 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7086 extern int read_alarm_should_throw
;
7087 read_alarm_should_throw
= 1;
7088 XPeekEvent (dpyinfo
->display
, &event
);
7089 read_alarm_should_throw
= 0;
7091 #endif /* HAVE_SELECT */
7095 /* For debugging, this gives a way to fake an I/O error. */
7096 if (dpyinfo
== XTread_socket_fake_io_error
)
7098 XTread_socket_fake_io_error
= 0;
7099 x_io_error_quitter (dpyinfo
->display
);
7104 count
+= x_session_check_input (bufp
, &numchars
);
7109 /* For GTK we must use the GTK event loop. But XEvents gets passed
7110 to our filter function above, and then to the big event switch.
7111 We use a bunch of globals to communicate with our filter function,
7112 that is kind of ugly, but it works. */
7113 current_dpyinfo
= dpyinfo
;
7115 while (gtk_events_pending ())
7118 current_count
= count
;
7119 current_numcharsp
= &numchars
;
7120 current_bufp
= &bufp
;
7122 gtk_main_iteration ();
7124 count
= current_count
;
7126 current_numcharsp
= 0;
7128 if (current_finish
== X_EVENT_GOTO_OUT
)
7132 #else /* not USE_GTK */
7133 while (XPending (dpyinfo
->display
))
7137 XNextEvent (dpyinfo
->display
, &event
);
7140 /* Filter events for the current X input method. */
7141 if (x_filter_event (dpyinfo
, &event
))
7146 count
+= handle_one_xevent (dpyinfo
,
7152 if (finish
== X_EVENT_GOTO_OUT
)
7155 #endif /* USE_GTK */
7160 /* On some systems, an X bug causes Emacs to get no more events
7161 when the window is destroyed. Detect that. (1994.) */
7164 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7165 One XNOOP in 100 loops will make Emacs terminate.
7166 B. Bretthauer, 1994 */
7168 if (x_noop_count
>= 100)
7172 if (next_noop_dpyinfo
== 0)
7173 next_noop_dpyinfo
= x_display_list
;
7175 XNoOp (next_noop_dpyinfo
->display
);
7177 /* Each time we get here, cycle through the displays now open. */
7178 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7182 /* If the focus was just given to an auto-raising frame,
7184 /* ??? This ought to be able to handle more than one such frame. */
7185 if (pending_autoraise_frame
)
7187 x_raise_frame (pending_autoraise_frame
);
7188 pending_autoraise_frame
= 0;
7199 /***********************************************************************
7201 ***********************************************************************/
7203 /* Set clipping for output in glyph row ROW. W is the window in which
7204 we operate. GC is the graphics context to set clipping in.
7205 WHOLE_LINE_P non-zero means include the areas used for truncation
7206 mark display and alike in the clipping rectangle.
7208 ROW may be a text row or, e.g., a mode line. Text rows must be
7209 clipped to the interior of the window dedicated to text display,
7210 mode lines must be clipped to the whole window. */
7213 x_clip_to_row (w
, row
, gc
, whole_line_p
)
7215 struct glyph_row
*row
;
7219 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7220 XRectangle clip_rect
;
7221 int window_x
, window_y
, window_width
, window_height
;
7223 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
7225 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
7226 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
7227 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7228 clip_rect
.width
= window_width
;
7229 clip_rect
.height
= row
->visible_height
;
7231 /* If clipping to the whole line, including trunc marks, extend
7232 the rectangle to the left and increase its width. */
7235 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
7236 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
7239 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7243 /* Draw a hollow box cursor on window W in glyph row ROW. */
7246 x_draw_hollow_cursor (w
, row
)
7248 struct glyph_row
*row
;
7250 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7251 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7252 Display
*dpy
= FRAME_X_DISPLAY (f
);
7255 struct glyph
*cursor_glyph
;
7258 /* Compute frame-relative coordinates from window-relative
7260 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7261 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
7262 + row
->ascent
- w
->phys_cursor_ascent
);
7263 h
= row
->height
- 1;
7265 /* Get the glyph the cursor is on. If we can't tell because
7266 the current matrix is invalid or such, give up. */
7267 cursor_glyph
= get_phys_cursor_glyph (w
);
7268 if (cursor_glyph
== NULL
)
7271 /* Compute the width of the rectangle to draw. If on a stretch
7272 glyph, and `x-stretch-block-cursor' is nil, don't draw a
7273 rectangle as wide as the glyph, but use a canonical character
7275 wd
= cursor_glyph
->pixel_width
- 1;
7276 if (cursor_glyph
->type
== STRETCH_GLYPH
7277 && !x_stretch_cursor_p
)
7278 wd
= min (CANON_X_UNIT (f
), wd
);
7279 w
->phys_cursor_width
= wd
;
7281 /* The foreground of cursor_gc is typically the same as the normal
7282 background color, which can cause the cursor box to be invisible. */
7283 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7284 if (dpyinfo
->scratch_cursor_gc
)
7285 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7287 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7288 GCForeground
, &xgcv
);
7289 gc
= dpyinfo
->scratch_cursor_gc
;
7291 /* Set clipping, draw the rectangle, and reset clipping again. */
7292 x_clip_to_row (w
, row
, gc
, 0);
7293 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
7294 XSetClipMask (dpy
, gc
, None
);
7298 /* Draw a bar cursor on window W in glyph row ROW.
7300 Implementation note: One would like to draw a bar cursor with an
7301 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7302 Unfortunately, I didn't find a font yet that has this property set.
7306 x_draw_bar_cursor (w
, row
, width
, kind
)
7308 struct glyph_row
*row
;
7310 enum text_cursor_kinds kind
;
7312 struct frame
*f
= XFRAME (w
->frame
);
7313 struct glyph
*cursor_glyph
;
7315 /* If cursor is out of bounds, don't draw garbage. This can happen
7316 in mini-buffer windows when switching between echo area glyphs
7318 cursor_glyph
= get_phys_cursor_glyph (w
);
7319 if (cursor_glyph
== NULL
)
7322 /* If on an image, draw like a normal cursor. That's usually better
7323 visible than drawing a bar, esp. if the image is large so that
7324 the bar might not be in the window. */
7325 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7327 struct glyph_row
*row
;
7328 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7329 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7333 Display
*dpy
= FRAME_X_DISPLAY (f
);
7334 Window window
= FRAME_X_WINDOW (f
);
7335 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7336 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7337 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7340 /* If the glyph's background equals the color we normally draw
7341 the bar cursor in, the bar cursor in its normal color is
7342 invisible. Use the glyph's foreground color instead in this
7343 case, on the assumption that the glyph's colors are chosen so
7344 that the glyph is legible. */
7345 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7346 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7348 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7349 xgcv
.graphics_exposures
= 0;
7352 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7355 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7356 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7360 width
= FRAME_CURSOR_WIDTH (f
);
7361 width
= min (cursor_glyph
->pixel_width
, width
);
7363 w
->phys_cursor_width
= width
;
7364 x_clip_to_row (w
, row
, gc
, 0);
7366 if (kind
== BAR_CURSOR
)
7367 XFillRectangle (dpy
, window
, gc
,
7368 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7369 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7370 width
, row
->height
);
7372 XFillRectangle (dpy
, window
, gc
,
7373 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7374 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7375 row
->height
- width
),
7376 cursor_glyph
->pixel_width
,
7379 XSetClipMask (dpy
, gc
, None
);
7384 /* RIF: Define cursor CURSOR on frame F. */
7387 x_define_frame_cursor (f
, cursor
)
7391 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7395 /* RIF: Clear area on frame F. */
7398 x_clear_frame_area (f
, x
, y
, width
, height
)
7400 int x
, y
, width
, height
;
7402 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7403 x
, y
, width
, height
, False
);
7407 /* RIF: Draw cursor on window W. */
7410 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7412 struct glyph_row
*glyph_row
;
7414 int cursor_type
, cursor_width
;
7417 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7421 w
->phys_cursor_type
= cursor_type
;
7422 w
->phys_cursor_on_p
= 1;
7424 switch (cursor_type
)
7426 case HOLLOW_BOX_CURSOR
:
7427 x_draw_hollow_cursor (w
, glyph_row
);
7430 case FILLED_BOX_CURSOR
:
7431 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7435 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7439 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7443 w
->phys_cursor_width
= 0;
7451 if (w
== XWINDOW (f
->selected_window
))
7452 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7453 xic_set_preeditarea (w
, x
, y
);
7458 if (updating_frame
!= f
)
7459 XFlush (FRAME_X_DISPLAY (f
));
7466 /* Make the x-window of frame F use the gnu icon bitmap. */
7469 x_bitmap_icon (f
, file
)
7475 if (FRAME_X_WINDOW (f
) == 0)
7478 /* Free up our existing icon bitmap if any. */
7479 if (f
->output_data
.x
->icon_bitmap
> 0)
7480 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7481 f
->output_data
.x
->icon_bitmap
= 0;
7484 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7487 /* Create the GNU bitmap if necessary. */
7488 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7489 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
7490 = x_create_bitmap_from_data (f
, gnu_bits
,
7491 gnu_width
, gnu_height
);
7493 /* The first time we create the GNU bitmap,
7494 this increments the ref-count one extra time.
7495 As a result, the GNU bitmap is never freed.
7496 That way, we don't have to worry about allocating it again. */
7497 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7499 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7502 x_wm_set_icon_pixmap (f
, bitmap_id
);
7503 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7509 /* Make the x-window of frame F use a rectangle with text.
7510 Use ICON_NAME as the text. */
7513 x_text_icon (f
, icon_name
)
7517 if (FRAME_X_WINDOW (f
) == 0)
7523 text
.value
= (unsigned char *) icon_name
;
7524 text
.encoding
= XA_STRING
;
7526 text
.nitems
= strlen (icon_name
);
7527 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7529 #else /* not HAVE_X11R4 */
7530 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), icon_name
);
7531 #endif /* not HAVE_X11R4 */
7533 if (f
->output_data
.x
->icon_bitmap
> 0)
7534 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7535 f
->output_data
.x
->icon_bitmap
= 0;
7536 x_wm_set_icon_pixmap (f
, 0);
7541 #define X_ERROR_MESSAGE_SIZE 200
7543 /* If non-nil, this should be a string.
7544 It means catch X errors and store the error message in this string. */
7546 static Lisp_Object x_error_message_string
;
7548 /* An X error handler which stores the error message in
7549 x_error_message_string. This is called from x_error_handler if
7550 x_catch_errors is in effect. */
7553 x_error_catcher (display
, error
)
7557 XGetErrorText (display
, error
->error_code
,
7558 SDATA (x_error_message_string
),
7559 X_ERROR_MESSAGE_SIZE
);
7562 /* Begin trapping X errors for display DPY. Actually we trap X errors
7563 for all displays, but DPY should be the display you are actually
7566 After calling this function, X protocol errors no longer cause
7567 Emacs to exit; instead, they are recorded in the string
7568 stored in x_error_message_string.
7570 Calling x_check_errors signals an Emacs error if an X error has
7571 occurred since the last call to x_catch_errors or x_check_errors.
7573 Calling x_uncatch_errors resumes the normal error handling. */
7575 void x_check_errors ();
7576 static Lisp_Object
x_catch_errors_unwind ();
7579 x_catch_errors (dpy
)
7582 int count
= SPECPDL_INDEX ();
7584 /* Make sure any errors from previous requests have been dealt with. */
7587 record_unwind_protect (x_catch_errors_unwind
,
7588 Fcons (make_save_value (dpy
, 0),
7589 x_error_message_string
));
7591 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
7592 SSET (x_error_message_string
, 0, 0);
7597 /* Unbind the binding that we made to check for X errors. */
7600 x_catch_errors_unwind (old_val
)
7601 Lisp_Object old_val
;
7605 first
= XCAR (old_val
);
7607 XSync (XSAVE_VALUE (first
)->pointer
, False
);
7609 x_error_message_string
= XCDR (old_val
);
7613 /* If any X protocol errors have arrived since the last call to
7614 x_catch_errors or x_check_errors, signal an Emacs error using
7615 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7618 x_check_errors (dpy
, format
)
7622 /* Make sure to catch any errors incurred so far. */
7625 if (SREF (x_error_message_string
, 0))
7626 error (format
, SDATA (x_error_message_string
));
7629 /* Nonzero if we had any X protocol errors
7630 since we did x_catch_errors on DPY. */
7633 x_had_errors_p (dpy
)
7636 /* Make sure to catch any errors incurred so far. */
7639 return SREF (x_error_message_string
, 0) != 0;
7642 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7645 x_clear_errors (dpy
)
7648 SSET (x_error_message_string
, 0, 0);
7651 /* Stop catching X protocol errors and let them make Emacs die.
7652 DPY should be the display that was passed to x_catch_errors.
7653 COUNT should be the value that was returned by
7654 the corresponding call to x_catch_errors. */
7657 x_uncatch_errors (dpy
, count
)
7661 unbind_to (count
, Qnil
);
7665 static unsigned int x_wire_count
;
7668 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7673 /* Handle SIGPIPE, which can happen when the connection to a server
7674 simply goes away. SIGPIPE is handled by x_connection_signal.
7675 Don't need to do anything, because the write which caused the
7676 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7677 which will do the appropriate cleanup for us. */
7680 x_connection_signal (signalnum
) /* If we don't have an argument, */
7681 int signalnum
; /* some compilers complain in signal calls. */
7684 /* USG systems forget handlers when they are used;
7685 must reestablish each time */
7686 signal (signalnum
, x_connection_signal
);
7691 /************************************************************************
7693 ************************************************************************/
7695 /* Error message passed to x_connection_closed. */
7697 static char *error_msg
;
7699 /* Function installed as fatal_error_signal_hook in
7700 x_connection_closed. Print the X error message, and exit normally,
7701 instead of dumping core when XtCloseDisplay fails. */
7704 x_fatal_error_signal ()
7706 fprintf (stderr
, "%s\n", error_msg
);
7710 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7711 the text of an error message that lead to the connection loss. */
7714 x_connection_closed (dpy
, error_message
)
7716 char *error_message
;
7718 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7719 Lisp_Object frame
, tail
;
7722 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7723 strcpy (error_msg
, error_message
);
7724 handling_signal
= 0;
7726 /* Prevent being called recursively because of an error condition
7727 below. Otherwise, we might end up with printing ``can't find per
7728 display information'' in the recursive call instead of printing
7729 the original message here. */
7730 count
= x_catch_errors (dpy
);
7732 /* We have to close the display to inform Xt that it doesn't
7733 exist anymore. If we don't, Xt will continue to wait for
7734 events from the display. As a consequence, a sequence of
7736 M-x make-frame-on-display RET :1 RET
7737 ...kill the new frame, so that we get an IO error...
7738 M-x make-frame-on-display RET :1 RET
7740 will indefinitely wait in Xt for events for display `:1', opened
7741 in the first class to make-frame-on-display.
7743 Closing the display is reported to lead to a bus error on
7744 OpenWindows in certain situations. I suspect that is a bug
7745 in OpenWindows. I don't know how to cicumvent it here. */
7747 #ifdef USE_X_TOOLKIT
7748 /* If DPYINFO is null, this means we didn't open the display
7749 in the first place, so don't try to close it. */
7752 extern void (*fatal_error_signal_hook
) P_ ((void));
7753 fatal_error_signal_hook
= x_fatal_error_signal
;
7754 XtCloseDisplay (dpy
);
7755 fatal_error_signal_hook
= NULL
;
7759 /* Indicate that this display is dead. */
7761 dpyinfo
->display
= 0;
7763 /* First delete frames whose mini-buffers are on frames
7764 that are on the dead display. */
7765 FOR_EACH_FRAME (tail
, frame
)
7767 Lisp_Object minibuf_frame
;
7769 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7770 if (FRAME_X_P (XFRAME (frame
))
7771 && FRAME_X_P (XFRAME (minibuf_frame
))
7772 && ! EQ (frame
, minibuf_frame
)
7773 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7774 Fdelete_frame (frame
, Qt
);
7777 /* Now delete all remaining frames on the dead display.
7778 We are now sure none of these is used as the mini-buffer
7779 for another frame that we need to delete. */
7780 FOR_EACH_FRAME (tail
, frame
)
7781 if (FRAME_X_P (XFRAME (frame
))
7782 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7784 /* Set this to t so that Fdelete_frame won't get confused
7785 trying to find a replacement. */
7786 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7787 Fdelete_frame (frame
, Qt
);
7791 x_delete_display (dpyinfo
);
7793 x_uncatch_errors (dpy
, count
);
7795 if (x_display_list
== 0)
7797 fprintf (stderr
, "%s\n", error_msg
);
7798 shut_down_emacs (0, 0, Qnil
);
7802 /* Ordinary stack unwind doesn't deal with these. */
7804 sigunblock (sigmask (SIGIO
));
7806 sigunblock (sigmask (SIGALRM
));
7807 TOTALLY_UNBLOCK_INPUT
;
7809 clear_waiting_for_input ();
7810 error ("%s", error_msg
);
7814 /* This is the usual handler for X protocol errors.
7815 It kills all frames on the display that we got the error for.
7816 If that was the only one, it prints an error message and kills Emacs. */
7819 x_error_quitter (display
, error
)
7823 char buf
[256], buf1
[356];
7825 /* Note that there is no real way portable across R3/R4 to get the
7826 original error handler. */
7828 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7829 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7830 buf
, error
->request_code
);
7831 x_connection_closed (display
, buf1
);
7835 /* This is the first-level handler for X protocol errors.
7836 It calls x_error_quitter or x_error_catcher. */
7839 x_error_handler (display
, error
)
7843 if (! NILP (x_error_message_string
))
7844 x_error_catcher (display
, error
);
7846 x_error_quitter (display
, error
);
7850 /* This is the handler for X IO errors, always.
7851 It kills all frames on the display that we lost touch with.
7852 If that was the only one, it prints an error message and kills Emacs. */
7855 x_io_error_quitter (display
)
7860 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7861 x_connection_closed (display
, buf
);
7865 /* Changing the font of the frame. */
7867 /* Give frame F the font named FONTNAME as its default font, and
7868 return the full name of that font. FONTNAME may be a wildcard
7869 pattern; in that case, we choose some font that fits the pattern.
7870 The return value shows which font we chose. */
7873 x_new_font (f
, fontname
)
7875 register char *fontname
;
7877 struct font_info
*fontp
7878 = FS_LOAD_FONT (f
, 0, fontname
, -1);
7883 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
7884 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
7885 f
->output_data
.x
->fontset
= -1;
7887 compute_fringe_widths (f
, 1);
7889 /* Compute the scroll bar width in character columns. */
7890 if (f
->scroll_bar_pixel_width
> 0)
7892 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
7893 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
7897 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
7898 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
7901 /* Now make the frame display the given font. */
7902 if (FRAME_X_WINDOW (f
) != 0)
7904 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
7905 f
->output_data
.x
->font
->fid
);
7906 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
7907 f
->output_data
.x
->font
->fid
);
7908 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
7909 f
->output_data
.x
->font
->fid
);
7911 frame_update_line_height (f
);
7913 /* Don't change the size of a tip frame; there's no point in
7914 doing it because it's done in Fx_show_tip, and it leads to
7915 problems because the tip frame has no widget. */
7916 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7917 x_set_window_size (f
, 0, f
->width
, f
->height
);
7920 /* If we are setting a new frame's font for the first time,
7921 there are no faces yet, so this font's height is the line height. */
7922 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
7924 return build_string (fontp
->full_name
);
7927 /* Give frame F the fontset named FONTSETNAME as its default font, and
7928 return the full name of that fontset. FONTSETNAME may be a wildcard
7929 pattern; in that case, we choose some fontset that fits the pattern.
7930 The return value shows which fontset we chose. */
7933 x_new_fontset (f
, fontsetname
)
7937 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
7943 if (f
->output_data
.x
->fontset
== fontset
)
7944 /* This fontset is already set in frame F. There's nothing more
7946 return fontset_name (fontset
);
7948 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
7950 if (!STRINGP (result
))
7951 /* Can't load ASCII font. */
7954 /* Since x_new_font doesn't update any fontset information, do it now. */
7955 f
->output_data
.x
->fontset
= fontset
;
7959 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7960 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
7963 return build_string (fontsetname
);
7967 /***********************************************************************
7969 ***********************************************************************/
7975 /* XIM destroy callback function, which is called whenever the
7976 connection to input method XIM dies. CLIENT_DATA contains a
7977 pointer to the x_display_info structure corresponding to XIM. */
7980 xim_destroy_callback (xim
, client_data
, call_data
)
7982 XPointer client_data
;
7985 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7986 Lisp_Object frame
, tail
;
7990 /* No need to call XDestroyIC.. */
7991 FOR_EACH_FRAME (tail
, frame
)
7993 struct frame
*f
= XFRAME (frame
);
7994 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
7996 FRAME_XIC (f
) = NULL
;
7997 if (FRAME_XIC_FONTSET (f
))
7999 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
8000 FRAME_XIC_FONTSET (f
) = NULL
;
8005 /* No need to call XCloseIM. */
8006 dpyinfo
->xim
= NULL
;
8007 XFree (dpyinfo
->xim_styles
);
8011 #endif /* HAVE_X11R6 */
8014 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8015 extern char *XSetIMValues
P_ ((XIM
, ...));
8018 /* Open the connection to the XIM server on display DPYINFO.
8019 RESOURCE_NAME is the resource name Emacs uses. */
8022 xim_open_dpy (dpyinfo
, resource_name
)
8023 struct x_display_info
*dpyinfo
;
8024 char *resource_name
;
8029 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
8035 XIMCallback destroy
;
8038 /* Get supported styles and XIM values. */
8039 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8042 destroy
.callback
= xim_destroy_callback
;
8043 destroy
.client_data
= (XPointer
)dpyinfo
;
8044 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8048 #else /* not USE_XIM */
8049 dpyinfo
->xim
= NULL
;
8050 #endif /* not USE_XIM */
8054 #ifdef HAVE_X11R6_XIM
8058 struct x_display_info
*dpyinfo
;
8059 char *resource_name
;
8062 /* XIM instantiate callback function, which is called whenever an XIM
8063 server is available. DISPLAY is the display of the XIM.
8064 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8065 when the callback was registered. */
8068 xim_instantiate_callback (display
, client_data
, call_data
)
8070 XPointer client_data
;
8073 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8074 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8076 /* We don't support multiple XIM connections. */
8080 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8082 /* Create XIC for the existing frames on the same display, as long
8083 as they have no XIC. */
8084 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8086 Lisp_Object tail
, frame
;
8089 FOR_EACH_FRAME (tail
, frame
)
8091 struct frame
*f
= XFRAME (frame
);
8093 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8094 if (FRAME_XIC (f
) == NULL
)
8096 create_frame_xic (f
);
8097 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8098 xic_set_statusarea (f
);
8099 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8101 struct window
*w
= XWINDOW (f
->selected_window
);
8102 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8111 #endif /* HAVE_X11R6_XIM */
8114 /* Open a connection to the XIM server on display DPYINFO.
8115 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8116 connection only at the first time. On X11R6, open the connection
8117 in the XIM instantiate callback function. */
8120 xim_initialize (dpyinfo
, resource_name
)
8121 struct x_display_info
*dpyinfo
;
8122 char *resource_name
;
8125 #ifdef HAVE_X11R6_XIM
8126 struct xim_inst_t
*xim_inst
;
8129 dpyinfo
->xim
= NULL
;
8130 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8131 xim_inst
->dpyinfo
= dpyinfo
;
8132 len
= strlen (resource_name
);
8133 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8134 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8135 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8136 resource_name
, EMACS_CLASS
,
8137 xim_instantiate_callback
,
8138 /* Fixme: This is XPointer in
8139 XFree86 but (XPointer *) on
8141 (XPointer
) xim_inst
);
8142 #else /* not HAVE_X11R6_XIM */
8143 dpyinfo
->xim
= NULL
;
8144 xim_open_dpy (dpyinfo
, resource_name
);
8145 #endif /* not HAVE_X11R6_XIM */
8147 #else /* not USE_XIM */
8148 dpyinfo
->xim
= NULL
;
8149 #endif /* not USE_XIM */
8153 /* Close the connection to the XIM server on display DPYINFO. */
8156 xim_close_dpy (dpyinfo
)
8157 struct x_display_info
*dpyinfo
;
8160 #ifdef HAVE_X11R6_XIM
8161 if (dpyinfo
->display
)
8162 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8164 xim_instantiate_callback
, NULL
);
8165 #endif /* not HAVE_X11R6_XIM */
8166 if (dpyinfo
->display
)
8167 XCloseIM (dpyinfo
->xim
);
8168 dpyinfo
->xim
= NULL
;
8169 XFree (dpyinfo
->xim_styles
);
8170 #endif /* USE_XIM */
8173 #endif /* not HAVE_X11R6_XIM */
8177 /* Calculate the absolute position in frame F
8178 from its current recorded position values and gravity. */
8181 x_calc_absolute_position (f
)
8185 int win_x
= 0, win_y
= 0;
8186 int flags
= f
->output_data
.x
->size_hint_flags
;
8189 /* We have nothing to do if the current position
8190 is already for the top-left corner. */
8191 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8194 this_window
= FRAME_OUTER_WINDOW (f
);
8196 /* Find the position of the outside upper-left corner of
8197 the inner window, with respect to the outer window.
8198 But do this only if we will need the results. */
8199 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8204 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
8207 x_clear_errors (FRAME_X_DISPLAY (f
));
8208 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
8210 /* From-window, to-window. */
8212 f
->output_data
.x
->parent_desc
,
8214 /* From-position, to-position. */
8215 0, 0, &win_x
, &win_y
,
8219 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
8221 Window newroot
, newparent
= 0xdeadbeef;
8222 Window
*newchildren
;
8223 unsigned int nchildren
;
8225 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
8226 &newparent
, &newchildren
, &nchildren
))
8229 XFree ((char *) newchildren
);
8231 f
->output_data
.x
->parent_desc
= newparent
;
8237 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
8241 /* Treat negative positions as relative to the leftmost bottommost
8242 position that fits on the screen. */
8243 if (flags
& XNegative
)
8244 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
8245 - 2 * f
->output_data
.x
->border_width
- win_x
8247 + f
->output_data
.x
->left_pos
);
8250 int height
= PIXEL_HEIGHT (f
);
8252 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8253 /* Something is fishy here. When using Motif, starting Emacs with
8254 `-g -0-0', the frame appears too low by a few pixels.
8256 This seems to be so because initially, while Emacs is starting,
8257 the column widget's height and the frame's pixel height are
8258 different. The column widget's height is the right one. In
8259 later invocations, when Emacs is up, the frame's pixel height
8262 It's not obvious where the initial small difference comes from.
8263 2000-12-01, gerd. */
8265 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8268 if (flags
& YNegative
)
8269 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
8270 - 2 * f
->output_data
.x
->border_width
8273 + f
->output_data
.x
->top_pos
);
8276 /* The left_pos and top_pos
8277 are now relative to the top and left screen edges,
8278 so the flags should correspond. */
8279 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8282 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8283 to really change the position, and 0 when calling from
8284 x_make_frame_visible (in that case, XOFF and YOFF are the current
8285 position values). It is -1 when calling from x_set_frame_parameters,
8286 which means, do adjust for borders but don't change the gravity. */
8289 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8291 register int xoff
, yoff
;
8294 int modified_top
, modified_left
;
8296 if (change_gravity
> 0)
8298 f
->output_data
.x
->top_pos
= yoff
;
8299 f
->output_data
.x
->left_pos
= xoff
;
8300 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8302 f
->output_data
.x
->size_hint_flags
|= XNegative
;
8304 f
->output_data
.x
->size_hint_flags
|= YNegative
;
8305 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
8307 x_calc_absolute_position (f
);
8310 x_wm_set_size_hint (f
, (long) 0, 0);
8312 modified_left
= f
->output_data
.x
->left_pos
;
8313 modified_top
= f
->output_data
.x
->top_pos
;
8314 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
8315 this seems to be unnecessary and incorrect. rms, 4/17/97. */
8316 /* It is a mystery why we need to add the border_width here
8317 when the frame is already visible, but experiment says we do. */
8318 if (change_gravity
!= 0)
8320 modified_left
+= f
->output_data
.x
->border_width
;
8321 modified_top
+= f
->output_data
.x
->border_width
;
8325 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8326 modified_left
, modified_top
);
8330 /* Check if we need to resize the frame due to a fullscreen request.
8331 If so needed, resize the frame. */
8333 x_check_fullscreen (f
)
8336 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
8338 int width
, height
, ign
;
8340 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
8341 &f
->output_data
.x
->top_pos
);
8343 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8345 /* We do not need to move the window, it shall be taken care of
8346 when setting WM manager hints.
8347 If the frame is visible already, the position is checked by
8348 x_check_fullscreen_move. */
8349 if (f
->width
!= width
|| f
->height
!= height
)
8351 change_frame_size (f
, height
, width
, 0, 1, 0);
8352 SET_FRAME_GARBAGED (f
);
8353 cancel_mouse_face (f
);
8355 /* Wait for the change of frame size to occur */
8356 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
8361 /* If frame parameters are set after the frame is mapped, we need to move
8362 the window. This is done in xfns.c.
8363 Some window managers moves the window to the right position, some
8364 moves the outer window manager window to the specified position.
8365 Here we check that we are in the right spot. If not, make a second
8366 move, assuming we are dealing with the second kind of window manager. */
8368 x_check_fullscreen_move (f
)
8371 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
8373 int expect_top
= f
->output_data
.x
->top_pos
;
8374 int expect_left
= f
->output_data
.x
->left_pos
;
8376 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
8378 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
8381 if (expect_top
!= f
->output_data
.x
->top_pos
8382 || expect_left
!= f
->output_data
.x
->left_pos
)
8383 x_set_offset (f
, expect_left
, expect_top
, 1);
8385 /* Just do this once */
8386 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
8391 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
8392 wanted positions of the WM window (not emacs window).
8393 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
8394 window (FRAME_X_WINDOW).
8397 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
8404 int newwidth
= f
->width
, newheight
= f
->height
;
8406 *top_pos
= f
->output_data
.x
->top_pos
;
8407 *left_pos
= f
->output_data
.x
->left_pos
;
8409 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
8413 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
8414 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
8415 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
8416 - f
->output_data
.x
->y_pixels_diff
;
8417 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
8421 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
8425 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
8426 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
8427 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
8428 - f
->output_data
.x
->x_pixels_diff
;
8429 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
8434 *height
= newheight
;
8438 /* Change the size of frame F's X window to COLS/ROWS in the case F
8439 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8440 top-left-corner window gravity for this size change and subsequent
8441 size changes. Otherwise we leave the window gravity unchanged. */
8444 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
8449 int pixelwidth
, pixelheight
;
8451 check_frame_size (f
, &rows
, &cols
);
8452 f
->output_data
.x
->vertical_scroll_bar_extra
8453 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8455 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
8456 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
8457 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
8459 compute_fringe_widths (f
, 0);
8461 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
8462 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
8464 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
8465 x_wm_set_size_hint (f
, (long) 0, 0);
8467 XSync (FRAME_X_DISPLAY (f
), False
);
8468 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8469 pixelwidth
, pixelheight
);
8471 /* Now, strictly speaking, we can't be sure that this is accurate,
8472 but the window manager will get around to dealing with the size
8473 change request eventually, and we'll hear how it went when the
8474 ConfigureNotify event gets here.
8476 We could just not bother storing any of this information here,
8477 and let the ConfigureNotify event set everything up, but that
8478 might be kind of confusing to the Lisp code, since size changes
8479 wouldn't be reported in the frame parameters until some random
8480 point in the future when the ConfigureNotify event arrives.
8482 We pass 1 for DELAY since we can't run Lisp code inside of
8484 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8485 PIXEL_WIDTH (f
) = pixelwidth
;
8486 PIXEL_HEIGHT (f
) = pixelheight
;
8488 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8489 receive in the ConfigureNotify event; if we get what we asked
8490 for, then the event won't cause the screen to become garbaged, so
8491 we have to make sure to do it here. */
8492 SET_FRAME_GARBAGED (f
);
8494 XFlush (FRAME_X_DISPLAY (f
));
8498 /* Call this to change the size of frame F's x-window.
8499 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8500 for this size change and subsequent size changes.
8501 Otherwise we leave the window gravity unchanged. */
8504 x_set_window_size (f
, change_gravity
, cols
, rows
)
8512 if (FRAME_GTK_WIDGET (f
))
8513 xg_frame_set_char_size (f
, cols
, rows
);
8515 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8518 if (f
->output_data
.x
->widget
!= NULL
)
8520 /* The x and y position of the widget is clobbered by the
8521 call to XtSetValues within EmacsFrameSetCharSize.
8522 This is a real kludge, but I don't understand Xt so I can't
8523 figure out a correct fix. Can anyone else tell me? -- rms. */
8524 int xpos
= f
->output_data
.x
->widget
->core
.x
;
8525 int ypos
= f
->output_data
.x
->widget
->core
.y
;
8526 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
8527 f
->output_data
.x
->widget
->core
.x
= xpos
;
8528 f
->output_data
.x
->widget
->core
.y
= ypos
;
8531 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8533 #else /* not USE_X_TOOLKIT */
8535 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8537 #endif /* not USE_X_TOOLKIT */
8539 /* If cursor was outside the new size, mark it as off. */
8540 mark_window_cursors_off (XWINDOW (f
->root_window
));
8542 /* Clear out any recollection of where the mouse highlighting was,
8543 since it might be in a place that's outside the new frame size.
8544 Actually checking whether it is outside is a pain in the neck,
8545 so don't try--just let the highlighting be done afresh with new size. */
8546 cancel_mouse_face (f
);
8551 /* Mouse warping. */
8554 x_set_mouse_position (f
, x
, y
)
8560 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
8561 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
8563 if (pix_x
< 0) pix_x
= 0;
8564 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
8566 if (pix_y
< 0) pix_y
= 0;
8567 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
8571 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8572 0, 0, 0, 0, pix_x
, pix_y
);
8576 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8579 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
8585 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8586 0, 0, 0, 0, pix_x
, pix_y
);
8590 /* focus shifting, raising and lowering. */
8593 x_focus_on_frame (f
)
8596 #if 0 /* This proves to be unpleasant. */
8600 /* I don't think that the ICCCM allows programs to do things like this
8601 without the interaction of the window manager. Whatever you end up
8602 doing with this code, do it to x_unfocus_frame too. */
8603 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8604 RevertToPointerRoot
, CurrentTime
);
8613 /* Look at the remarks in x_focus_on_frame. */
8614 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8615 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8616 RevertToPointerRoot
, CurrentTime
);
8620 /* Raise frame F. */
8626 if (f
->async_visible
)
8629 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8630 XFlush (FRAME_X_DISPLAY (f
));
8635 /* Lower frame F. */
8641 if (f
->async_visible
)
8644 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8645 XFlush (FRAME_X_DISPLAY (f
));
8651 XTframe_raise_lower (f
, raise_flag
)
8661 /* Change of visibility. */
8663 /* This tries to wait until the frame is really visible.
8664 However, if the window manager asks the user where to position
8665 the frame, this will return before the user finishes doing that.
8666 The frame will not actually be visible at that time,
8667 but it will become visible later when the window manager
8668 finishes with it. */
8671 x_make_frame_visible (f
)
8675 int original_top
, original_left
;
8676 int retry_count
= 2;
8682 type
= x_icon_type (f
);
8684 x_bitmap_icon (f
, type
);
8686 if (! FRAME_VISIBLE_P (f
))
8688 /* We test FRAME_GARBAGED_P here to make sure we don't
8689 call x_set_offset a second time
8690 if we get to x_make_frame_visible a second time
8691 before the window gets really visible. */
8692 if (! FRAME_ICONIFIED_P (f
)
8693 && ! f
->output_data
.x
->asked_for_visible
)
8694 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
8696 f
->output_data
.x
->asked_for_visible
= 1;
8698 if (! EQ (Vx_no_window_manager
, Qt
))
8699 x_wm_set_window_state (f
, NormalState
);
8700 #ifdef USE_X_TOOLKIT
8701 /* This was XtPopup, but that did nothing for an iconified frame. */
8702 XtMapWidget (f
->output_data
.x
->widget
);
8703 #else /* not USE_X_TOOLKIT */
8705 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8706 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8708 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8709 #endif /* not USE_GTK */
8710 #endif /* not USE_X_TOOLKIT */
8711 #if 0 /* This seems to bring back scroll bars in the wrong places
8712 if the window configuration has changed. They seem
8713 to come back ok without this. */
8714 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8715 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8719 XFlush (FRAME_X_DISPLAY (f
));
8721 /* Synchronize to ensure Emacs knows the frame is visible
8722 before we do anything else. We do this loop with input not blocked
8723 so that incoming events are handled. */
8727 /* This must be before UNBLOCK_INPUT
8728 since events that arrive in response to the actions above
8729 will set it when they are handled. */
8730 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8732 original_left
= f
->output_data
.x
->left_pos
;
8733 original_top
= f
->output_data
.x
->top_pos
;
8735 /* This must come after we set COUNT. */
8738 /* We unblock here so that arriving X events are processed. */
8740 /* Now move the window back to where it was "supposed to be".
8741 But don't do it if the gravity is negative.
8742 When the gravity is negative, this uses a position
8743 that is 3 pixels too low. Perhaps that's really the border width.
8745 Don't do this if the window has never been visible before,
8746 because the window manager may choose the position
8747 and we don't want to override it. */
8749 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
8750 && f
->output_data
.x
->win_gravity
== NorthWestGravity
8751 && previously_visible
)
8755 unsigned int width
, height
, border
, depth
;
8759 /* On some window managers (such as FVWM) moving an existing
8760 window, even to the same place, causes the window manager
8761 to introduce an offset. This can cause the window to move
8762 to an unexpected location. Check the geometry (a little
8763 slow here) and then verify that the window is in the right
8764 place. If the window is not in the right place, move it
8765 there, and take the potential window manager hit. */
8766 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8767 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
8769 if (original_left
!= x
|| original_top
!= y
)
8770 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8771 original_left
, original_top
);
8776 XSETFRAME (frame
, f
);
8778 /* Wait until the frame is visible. Process X events until a
8779 MapNotify event has been seen, or until we think we won't get a
8780 MapNotify at all.. */
8781 for (count
= input_signal_count
+ 10;
8782 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
8784 /* Force processing of queued events. */
8787 /* Machines that do polling rather than SIGIO have been
8788 observed to go into a busy-wait here. So we'll fake an
8789 alarm signal to let the handler know that there's something
8790 to be read. We used to raise a real alarm, but it seems
8791 that the handler isn't always enabled here. This is
8793 if (input_polling_used ())
8795 /* It could be confusing if a real alarm arrives while
8796 processing the fake one. Turn it off and let the
8797 handler reset it. */
8798 extern void poll_for_input_1
P_ ((void));
8799 int old_poll_suppress_count
= poll_suppress_count
;
8800 poll_suppress_count
= 1;
8801 poll_for_input_1 ();
8802 poll_suppress_count
= old_poll_suppress_count
;
8805 /* See if a MapNotify event has been processed. */
8806 FRAME_SAMPLE_VISIBILITY (f
);
8811 (let ((f (selected-frame)))
8815 the frame is not raised with various window managers on
8816 FreeBSD, Linux and Solaris. It turns out that, for some
8817 unknown reason, the call to XtMapWidget is completely ignored.
8818 Mapping the widget a second time works. */
8820 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
8825 /* Change from mapped state to withdrawn state. */
8827 /* Make the frame visible (mapped and not iconified). */
8830 x_make_frame_invisible (f
)
8835 /* Use the frame's outermost window, not the one we normally draw on. */
8836 window
= FRAME_OUTER_WINDOW (f
);
8838 /* Don't keep the highlight on an invisible frame. */
8839 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
8840 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
8842 #if 0/* This might add unreliability; I don't trust it -- rms. */
8843 if (! f
->async_visible
&& ! f
->async_iconified
)
8849 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
8850 that the current position of the window is user-specified, rather than
8851 program-specified, so that when the window is mapped again, it will be
8852 placed at the same location, without forcing the user to position it
8853 by hand again (they have already done that once for this window.) */
8854 x_wm_set_size_hint (f
, (long) 0, 1);
8857 if (FRAME_GTK_OUTER_WIDGET (f
))
8859 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 */