1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 97, 98, 1999, 2000, 01, 02, 2003
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) */
59 #ifndef INCLUDED_FCNTL
66 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
67 /* #include <sys/param.h> */
73 #include "dispextern.h"
75 #include "termhooks.h"
83 #include "intervals.h"
89 #include <X11/Shell.h>
92 #ifdef HAVE_SYS_TIME_H
104 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
105 extern void xlwmenu_redisplay
P_ ((Widget
));
108 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
110 extern void free_frame_menubar
P_ ((struct frame
*));
111 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
116 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
118 extern void _XEditResCheckMessages ();
119 #endif /* not NO_EDITRES */
121 /* Include toolkit specific headers for the scroll bar widget. */
123 #ifdef USE_TOOLKIT_SCROLL_BARS
124 #if defined USE_MOTIF
125 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
126 #include <Xm/ScrollBar.h>
127 #else /* !USE_MOTIF i.e. use Xaw */
130 #include <X11/Xaw3d/Simple.h>
131 #include <X11/Xaw3d/Scrollbar.h>
132 #define ARROW_SCROLLBAR
133 #define XAW_ARROW_SCROLLBARS
134 #include <X11/Xaw3d/ScrollbarP.h>
135 #else /* !HAVE_XAW3D */
136 #include <X11/Xaw/Simple.h>
137 #include <X11/Xaw/Scrollbar.h>
138 #endif /* !HAVE_XAW3D */
140 #define XtNpickTop "pickTop"
141 #endif /* !XtNpickTop */
142 #endif /* !USE_MOTIF */
143 #endif /* USE_TOOLKIT_SCROLL_BARS */
145 #endif /* USE_X_TOOLKIT */
147 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
148 #define x_any_window_to_frame x_window_to_frame
149 #define x_top_window_to_frame x_window_to_frame
154 #ifndef XtNinitialState
155 #define XtNinitialState "initialState"
159 #define abs(x) ((x) < 0 ? -(x) : (x))
161 /* Default to using XIM if available. */
165 int use_xim
= 0; /* configure --without-xim */
170 /* Non-nil means Emacs uses toolkit scroll bars. */
172 Lisp_Object Vx_toolkit_scroll_bars
;
174 /* Non-zero means that a HELP_EVENT has been generated since Emacs
177 static int any_help_event_p
;
179 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
180 static Lisp_Object last_window
;
182 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
184 int x_use_underline_position_properties
;
186 /* This is a chain of structures for all the X displays currently in
189 struct x_display_info
*x_display_list
;
191 /* This is a list of cons cells, each of the form (NAME
192 . FONT-LIST-CACHE), one for each element of x_display_list and in
193 the same order. NAME is the name of the frame. FONT-LIST-CACHE
194 records previous values returned by x-list-fonts. */
196 Lisp_Object x_display_name_list
;
198 /* Frame being updated by update_frame. This is declared in term.c.
199 This is set by update_begin and looked at by all the XT functions.
200 It is zero while not inside an update. In that case, the XT
201 functions assume that `selected_frame' is the frame to apply to. */
203 extern struct frame
*updating_frame
;
205 /* This is a frame waiting to be auto-raised, within XTread_socket. */
207 struct frame
*pending_autoraise_frame
;
210 /* The application context for Xt use. */
211 XtAppContext Xt_app_con
;
212 static String Xt_default_resources
[] = {0};
213 #endif /* USE_X_TOOLKIT */
215 /* Non-zero means user is interacting with a toolkit scroll bar. */
217 static int toolkit_scroll_bar_interaction
;
221 Formerly, we used PointerMotionHintMask (in standard_event_mask)
222 so that we would have to call XQueryPointer after each MotionNotify
223 event to ask for another such event. However, this made mouse tracking
224 slow, and there was a bug that made it eventually stop.
226 Simply asking for MotionNotify all the time seems to work better.
228 In order to avoid asking for motion events and then throwing most
229 of them away or busy-polling the server for mouse positions, we ask
230 the server for pointer motion hints. This means that we get only
231 one event per group of mouse movements. "Groups" are delimited by
232 other kinds of events (focus changes and button clicks, for
233 example), or by XQueryPointer calls; when one of these happens, we
234 get another MotionNotify event the next time the mouse moves. This
235 is at least as efficient as getting motion events when mouse
236 tracking is on, and I suspect only negligibly worse when tracking
239 /* Where the mouse was last time we reported a mouse event. */
241 static XRectangle last_mouse_glyph
;
242 static Lisp_Object last_mouse_press_frame
;
244 /* The scroll bar in which the last X motion event occurred.
246 If the last X motion event occurred in a scroll bar, we set this so
247 XTmouse_position can know whether to report a scroll bar motion or
250 If the last X motion event didn't occur in a scroll bar, we set
251 this to Qnil, to tell XTmouse_position to return an ordinary motion
254 static Lisp_Object last_mouse_scroll_bar
;
256 /* This is a hack. We would really prefer that XTmouse_position would
257 return the time associated with the position it returns, but there
258 doesn't seem to be any way to wrest the time-stamp from the server
259 along with the position query. So, we just keep track of the time
260 of the last movement we received, and return that in hopes that
261 it's somewhat accurate. */
263 static Time last_mouse_movement_time
;
265 /* Incremented by XTread_socket whenever it really tries to read
269 static int volatile input_signal_count
;
271 static int input_signal_count
;
274 /* Used locally within XTread_socket. */
276 static int x_noop_count
;
278 /* Initial values of argv and argc. */
280 extern char **initial_argv
;
281 extern int initial_argc
;
283 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
285 /* Tells if a window manager is present or not. */
287 extern Lisp_Object Vx_no_window_manager
;
289 extern Lisp_Object Qeql
;
293 /* A mask of extra modifier bits to put into every keyboard char. */
295 extern EMACS_INT extra_keyboard_modifiers
;
297 /* The keysyms to use for the various modifiers. */
299 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
300 Lisp_Object Vx_keysym_table
;
301 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
303 static Lisp_Object Qvendor_specific_keysyms
;
304 static Lisp_Object Qlatin_1
;
306 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
307 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
309 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
310 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
311 static const XColor
*x_color_cells
P_ ((Display
*, int *));
312 static void x_update_window_end
P_ ((struct window
*, int, int));
313 void x_delete_display
P_ ((struct x_display_info
*));
314 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
316 static int x_io_error_quitter
P_ ((Display
*));
317 int x_catch_errors
P_ ((Display
*));
318 void x_uncatch_errors
P_ ((Display
*, int));
319 void x_lower_frame
P_ ((struct frame
*));
320 void x_scroll_bar_clear
P_ ((struct frame
*));
321 int x_had_errors_p
P_ ((Display
*));
322 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
323 void x_raise_frame
P_ ((struct frame
*));
324 void x_set_window_size
P_ ((struct frame
*, int, int, int));
325 void x_wm_set_window_state
P_ ((struct frame
*, int));
326 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
327 struct display
*x_create_frame_display
P_ ((struct x_display_info
*));
328 void x_delete_frame_display
P_ ((struct display
*));
329 void x_initialize
P_ ((void));
330 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
331 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
332 static void x_update_end
P_ ((struct frame
*));
333 static void XTframe_up_to_date
P_ ((struct frame
*));
334 static void XTset_terminal_modes
P_ ((struct display
*));
335 static void XTreset_terminal_modes
P_ ((struct display
*));
336 static void x_clear_frame
P_ ((void));
337 static void frame_highlight
P_ ((struct frame
*));
338 static void frame_unhighlight
P_ ((struct frame
*));
339 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
340 static int x_focus_changed
P_ ((int,
342 struct x_display_info
*,
344 struct input_event
*,
346 static int x_detect_focus_change
P_ ((struct x_display_info
*,
348 struct input_event
*,
350 static void XTframe_rehighlight
P_ ((struct frame
*));
351 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
352 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
353 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
354 enum text_cursor_kinds
));
356 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, GC
));
357 static void x_flush
P_ ((struct frame
*f
));
358 static void x_update_begin
P_ ((struct frame
*));
359 static void x_update_window_begin
P_ ((struct window
*));
360 static void x_after_update_window_line
P_ ((struct glyph_row
*));
361 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Display
*, Window
));
362 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
363 enum scroll_bar_part
*,
364 Lisp_Object
*, Lisp_Object
*,
366 static void x_check_fullscreen
P_ ((struct frame
*));
367 static void x_check_expected_move
P_ ((struct frame
*));
368 static int handle_one_xevent
P_ ((struct x_display_info
*,
370 struct input_event
**,
375 /* Flush display of frame F, or of all frames if F is null. */
384 Lisp_Object rest
, frame
;
385 FOR_EACH_FRAME (rest
, frame
)
386 if (FRAME_X_P (XFRAME (frame
)))
387 x_flush (XFRAME (frame
));
389 else if (FRAME_X_P (f
))
390 XFlush (FRAME_X_DISPLAY (f
));
395 /* Remove calls to XFlush by defining XFlush to an empty replacement.
396 Calls to XFlush should be unnecessary because the X output buffer
397 is flushed automatically as needed by calls to XPending,
398 XNextEvent, or XWindowEvent according to the XFlush man page.
399 XTread_socket calls XPending. Removing XFlush improves
402 #define XFlush(DISPLAY) (void) 0
405 /***********************************************************************
407 ***********************************************************************/
411 /* This is a function useful for recording debugging information about
412 the sequence of occurrences in this file. */
420 struct record event_record
[100];
422 int event_record_index
;
424 record_event (locus
, type
)
428 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
429 event_record_index
= 0;
431 event_record
[event_record_index
].locus
= locus
;
432 event_record
[event_record_index
].type
= type
;
433 event_record_index
++;
440 /* Return the struct x_display_info corresponding to DPY. */
442 struct x_display_info
*
443 x_display_info_for_display (dpy
)
446 struct x_display_info
*dpyinfo
;
448 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
449 if (dpyinfo
->display
== dpy
)
457 /***********************************************************************
458 Starting and ending an update
459 ***********************************************************************/
461 /* Start an update of frame F. This function is installed as a hook
462 for update_begin, i.e. it is called when update_begin is called.
463 This function is called prior to calls to x_update_window_begin for
464 each window being updated. Currently, there is nothing to do here
465 because all interesting stuff is done on a window basis. */
474 /* Start update of window W. Set the global variable updated_window
475 to the window being updated and set output_cursor to the cursor
479 x_update_window_begin (w
)
482 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
483 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
486 set_output_cursor (&w
->cursor
);
490 if (f
== display_info
->mouse_face_mouse_frame
)
492 /* Don't do highlighting for mouse motion during the update. */
493 display_info
->mouse_face_defer
= 1;
495 /* If F needs to be redrawn, simply forget about any prior mouse
497 if (FRAME_GARBAGED_P (f
))
498 display_info
->mouse_face_window
= Qnil
;
500 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
501 their mouse_face_p flag set, which means that they are always
502 unequal to rows in a desired matrix which never have that
503 flag set. So, rows containing mouse-face glyphs are never
504 scrolled, and we don't have to switch the mouse highlight off
505 here to prevent it from being scrolled. */
507 /* Can we tell that this update does not affect the window
508 where the mouse highlight is? If so, no need to turn off.
509 Likewise, don't do anything if the frame is garbaged;
510 in that case, the frame's current matrix that we would use
511 is all wrong, and we will redisplay that line anyway. */
512 if (!NILP (display_info
->mouse_face_window
)
513 && w
== XWINDOW (display_info
->mouse_face_window
))
517 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
518 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
521 if (i
< w
->desired_matrix
->nrows
)
522 clear_mouse_face (display_info
);
531 /* Draw a vertical window border from (x,y0) to (x,y1) */
534 x_draw_vertical_window_border (w
, x
, y0
, y1
)
538 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
540 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
541 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
544 /* End update of window W (which is equal to updated_window).
546 Draw vertical borders between horizontally adjacent windows, and
547 display W's cursor if CURSOR_ON_P is non-zero.
549 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
550 glyphs in mouse-face were overwritten. In that case we have to
551 make sure that the mouse-highlight is properly redrawn.
553 W may be a menu bar pseudo-window in case we don't have X toolkit
554 support. Such windows don't have a cursor, so don't display it
558 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
560 int cursor_on_p
, mouse_face_overwritten_p
;
562 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
564 if (!w
->pseudo_window_p
)
569 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
571 output_cursor
.x
, output_cursor
.y
);
573 x_draw_vertical_border (w
);
575 draw_window_fringes (w
);
580 /* If a row with mouse-face was overwritten, arrange for
581 XTframe_up_to_date to redisplay the mouse highlight. */
582 if (mouse_face_overwritten_p
)
584 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
585 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
586 dpyinfo
->mouse_face_window
= Qnil
;
589 updated_window
= NULL
;
593 /* End update of frame F. This function is installed as a hook in
600 /* Mouse highlight may be displayed again. */
601 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
605 XFlush (FRAME_X_DISPLAY (f
));
611 /* This function is called from various places in xdisp.c whenever a
612 complete update has been performed. The global variable
613 updated_window is not available here. */
616 XTframe_up_to_date (f
)
621 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
623 if (dpyinfo
->mouse_face_deferred_gc
624 || f
== dpyinfo
->mouse_face_mouse_frame
)
627 if (dpyinfo
->mouse_face_mouse_frame
)
628 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
629 dpyinfo
->mouse_face_mouse_x
,
630 dpyinfo
->mouse_face_mouse_y
);
631 dpyinfo
->mouse_face_deferred_gc
= 0;
638 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
639 arrow bitmaps, or clear the fringes if no bitmaps are required
640 before DESIRED_ROW is made current. The window being updated is
641 found in updated_window. This function It is called from
642 update_window_line only if it is known that there are differences
643 between bitmaps to be drawn between current row and DESIRED_ROW. */
646 x_after_update_window_line (desired_row
)
647 struct glyph_row
*desired_row
;
649 struct window
*w
= updated_window
;
655 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
656 desired_row
->redraw_fringe_bitmaps_p
= 1;
658 /* When a window has disappeared, make sure that no rest of
659 full-width rows stays visible in the internal border. Could
660 check here if updated_window is the leftmost/rightmost window,
661 but I guess it's not worth doing since vertically split windows
662 are almost never used, internal border is rarely set, and the
663 overhead is very small. */
664 if (windows_or_buffers_changed
665 && desired_row
->full_width_p
666 && (f
= XFRAME (w
->frame
),
667 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
669 && (height
= desired_row
->visible_height
,
672 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
674 /* Internal border is drawn below the tool bar. */
675 if (WINDOWP (f
->tool_bar_window
)
676 && w
== XWINDOW (f
->tool_bar_window
))
680 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
681 0, y
, width
, height
, False
);
682 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
683 FRAME_PIXEL_WIDTH (f
) - width
,
684 y
, width
, height
, False
);
690 x_draw_fringe_bitmap (w
, row
, p
)
692 struct glyph_row
*row
;
693 struct draw_fringe_bitmap_params
*p
;
695 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
696 Display
*display
= FRAME_X_DISPLAY (f
);
697 Window window
= FRAME_X_WINDOW (f
);
698 GC gc
= f
->output_data
.x
->normal_gc
;
699 struct face
*face
= p
->face
;
702 /* Must clip because of partially visible lines. */
703 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
706 /* Adjust position of "bottom aligned" bitmap on partially
709 int oldVH
= row
->visible_height
;
710 row
->visible_height
= p
->h
;
711 row
->y
-= rowY
- p
->y
;
712 x_clip_to_row (w
, row
, gc
);
714 row
->visible_height
= oldVH
;
717 x_clip_to_row (w
, row
, gc
);
721 /* In case the same realized face is used for fringes and
722 for something displayed in the text (e.g. face `region' on
723 mono-displays, the fill style may have been changed to
724 FillSolid in x_draw_glyph_string_background. */
726 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
728 XSetForeground (display
, face
->gc
, face
->background
);
730 XFillRectangle (display
, window
, face
->gc
,
731 p
->bx
, p
->by
, p
->nx
, p
->ny
);
734 XSetForeground (display
, face
->gc
, face
->foreground
);
737 if (p
->which
!= NO_FRINGE_BITMAP
)
739 unsigned char *bits
= fringe_bitmaps
[p
->which
].bits
+ p
->dh
;
741 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
743 /* Draw the bitmap. I believe these small pixmaps can be cached
745 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
747 face
->background
, depth
);
748 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
749 p
->wd
, p
->h
, p
->x
, p
->y
);
750 XFreePixmap (display
, pixmap
);
753 XSetClipMask (display
, gc
, None
);
758 /* This is called when starting Emacs and when restarting after
759 suspend. When starting Emacs, no X window is mapped. And nothing
760 must be done to Emacs's own window if it is suspended (though that
764 XTset_terminal_modes (struct display
*display
)
768 /* This is called when exiting or suspending Emacs. Exiting will make
769 the X-windows go away, and suspending requires no action. */
772 XTreset_terminal_modes (struct display
*display
)
778 /***********************************************************************
780 ***********************************************************************/
782 /* Function prototypes of this page. */
784 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
787 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
788 is not contained in the font. */
791 x_per_char_metric (font
, char2b
, font_type
)
794 int font_type
; /* unused on X */
796 /* The result metric information. */
797 XCharStruct
*pcm
= NULL
;
799 xassert (font
&& char2b
);
801 if (font
->per_char
!= NULL
)
803 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
805 /* min_char_or_byte2 specifies the linear character index
806 corresponding to the first element of the per_char array,
807 max_char_or_byte2 is the index of the last character. A
808 character with non-zero CHAR2B->byte1 is not in the font.
809 A character with byte2 less than min_char_or_byte2 or
810 greater max_char_or_byte2 is not in the font. */
811 if (char2b
->byte1
== 0
812 && char2b
->byte2
>= font
->min_char_or_byte2
813 && char2b
->byte2
<= font
->max_char_or_byte2
)
814 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
818 /* If either min_byte1 or max_byte1 are nonzero, both
819 min_char_or_byte2 and max_char_or_byte2 are less than
820 256, and the 2-byte character index values corresponding
821 to the per_char array element N (counting from 0) are:
823 byte1 = N/D + min_byte1
824 byte2 = N\D + min_char_or_byte2
828 D = max_char_or_byte2 - min_char_or_byte2 + 1
830 \ = integer modulus */
831 if (char2b
->byte1
>= font
->min_byte1
832 && char2b
->byte1
<= font
->max_byte1
833 && char2b
->byte2
>= font
->min_char_or_byte2
834 && char2b
->byte2
<= font
->max_char_or_byte2
)
836 pcm
= (font
->per_char
837 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
838 * (char2b
->byte1
- font
->min_byte1
))
839 + (char2b
->byte2
- font
->min_char_or_byte2
));
845 /* If the per_char pointer is null, all glyphs between the first
846 and last character indexes inclusive have the same
847 information, as given by both min_bounds and max_bounds. */
848 if (char2b
->byte2
>= font
->min_char_or_byte2
849 && char2b
->byte2
<= font
->max_char_or_byte2
)
850 pcm
= &font
->max_bounds
;
854 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
859 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
860 the two-byte form of C. Encoding is returned in *CHAR2B. */
863 x_encode_char (c
, char2b
, font_info
, two_byte_p
)
866 struct font_info
*font_info
;
869 int charset
= CHAR_CHARSET (c
);
870 XFontStruct
*font
= font_info
->font
;
872 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
873 This may be either a program in a special encoder language or a
875 if (font_info
->font_encoder
)
877 /* It's a program. */
878 struct ccl_program
*ccl
= font_info
->font_encoder
;
880 if (CHARSET_DIMENSION (charset
) == 1)
882 ccl
->reg
[0] = charset
;
883 ccl
->reg
[1] = char2b
->byte2
;
888 ccl
->reg
[0] = charset
;
889 ccl
->reg
[1] = char2b
->byte1
;
890 ccl
->reg
[2] = char2b
->byte2
;
893 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
895 /* We assume that MSBs are appropriately set/reset by CCL
897 if (font
->max_byte1
== 0) /* 1-byte font */
898 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
900 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
902 else if (font_info
->encoding
[charset
])
904 /* Fixed encoding scheme. See fontset.h for the meaning of the
906 int enc
= font_info
->encoding
[charset
];
908 if ((enc
== 1 || enc
== 2)
909 && CHARSET_DIMENSION (charset
) == 2)
910 char2b
->byte1
|= 0x80;
912 if (enc
== 1 || enc
== 3)
913 char2b
->byte2
|= 0x80;
917 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
919 return FONT_TYPE_UNKNOWN
;
924 /***********************************************************************
926 ***********************************************************************/
930 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
931 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
932 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
934 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
935 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
936 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
937 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
938 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
939 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
940 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
941 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
942 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
943 unsigned long *, double, int));
944 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
945 double, int, unsigned long));
946 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
947 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
948 static void x_draw_image_relief
P_ ((struct glyph_string
*));
949 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
950 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
951 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
953 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
954 int, int, int, int, XRectangle
*));
955 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
956 int, int, int, XRectangle
*));
959 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
963 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
968 struct glyph_string
*s
;
970 if (s
->font
== FRAME_FONT (s
->f
)
971 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
972 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
974 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
977 /* Cursor on non-default face: must merge. */
981 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
982 xgcv
.foreground
= s
->face
->background
;
984 /* If the glyph would be invisible, try a different foreground. */
985 if (xgcv
.foreground
== xgcv
.background
)
986 xgcv
.foreground
= s
->face
->foreground
;
987 if (xgcv
.foreground
== xgcv
.background
)
988 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
989 if (xgcv
.foreground
== xgcv
.background
)
990 xgcv
.foreground
= s
->face
->foreground
;
992 /* Make sure the cursor is distinct from text in this face. */
993 if (xgcv
.background
== s
->face
->background
994 && xgcv
.foreground
== s
->face
->foreground
)
996 xgcv
.background
= s
->face
->foreground
;
997 xgcv
.foreground
= s
->face
->background
;
1000 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1001 xgcv
.font
= s
->font
->fid
;
1002 xgcv
.graphics_exposures
= False
;
1003 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1005 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1006 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1009 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1010 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1012 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1017 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1020 x_set_mouse_face_gc (s
)
1021 struct glyph_string
*s
;
1026 /* What face has to be used last for the mouse face? */
1027 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1028 face
= FACE_FROM_ID (s
->f
, face_id
);
1030 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1032 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1033 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
1035 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
1036 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1037 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1039 /* If font in this face is same as S->font, use it. */
1040 if (s
->font
== s
->face
->font
)
1041 s
->gc
= s
->face
->gc
;
1044 /* Otherwise construct scratch_cursor_gc with values from FACE
1049 xgcv
.background
= s
->face
->background
;
1050 xgcv
.foreground
= s
->face
->foreground
;
1051 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1052 xgcv
.font
= s
->font
->fid
;
1053 xgcv
.graphics_exposures
= False
;
1054 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1056 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1057 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1060 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1061 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1063 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1066 xassert (s
->gc
!= 0);
1070 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1071 Faces to use in the mode line have already been computed when the
1072 matrix was built, so there isn't much to do, here. */
1075 x_set_mode_line_face_gc (s
)
1076 struct glyph_string
*s
;
1078 s
->gc
= s
->face
->gc
;
1082 /* Set S->gc of glyph string S for drawing that glyph string. Set
1083 S->stippled_p to a non-zero value if the face of S has a stipple
1087 x_set_glyph_string_gc (s
)
1088 struct glyph_string
*s
;
1090 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1092 if (s
->hl
== DRAW_NORMAL_TEXT
)
1094 s
->gc
= s
->face
->gc
;
1095 s
->stippled_p
= s
->face
->stipple
!= 0;
1097 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1099 x_set_mode_line_face_gc (s
);
1100 s
->stippled_p
= s
->face
->stipple
!= 0;
1102 else if (s
->hl
== DRAW_CURSOR
)
1104 x_set_cursor_gc (s
);
1107 else if (s
->hl
== DRAW_MOUSE_FACE
)
1109 x_set_mouse_face_gc (s
);
1110 s
->stippled_p
= s
->face
->stipple
!= 0;
1112 else if (s
->hl
== DRAW_IMAGE_RAISED
1113 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1115 s
->gc
= s
->face
->gc
;
1116 s
->stippled_p
= s
->face
->stipple
!= 0;
1120 s
->gc
= s
->face
->gc
;
1121 s
->stippled_p
= s
->face
->stipple
!= 0;
1124 /* GC must have been set. */
1125 xassert (s
->gc
!= 0);
1129 /* Set clipping for output of glyph string S. S may be part of a mode
1130 line or menu if we don't have X toolkit support. */
1133 x_set_glyph_string_clipping (s
)
1134 struct glyph_string
*s
;
1137 get_glyph_string_clip_rect (s
, &r
);
1138 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
1143 Compute left and right overhang of glyph string S. If S is a glyph
1144 string for a composition, assume overhangs don't exist. */
1147 x_compute_glyph_string_overhangs (s
)
1148 struct glyph_string
*s
;
1151 && s
->first_glyph
->type
== CHAR_GLYPH
)
1154 int direction
, font_ascent
, font_descent
;
1155 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1156 &font_ascent
, &font_descent
, &cs
);
1157 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1158 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1163 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1166 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1167 struct glyph_string
*s
;
1171 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1172 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1173 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1174 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1178 /* Draw the background of glyph_string S. If S->background_filled_p
1179 is non-zero don't draw it. FORCE_P non-zero means draw the
1180 background even if it wouldn't be drawn normally. This is used
1181 when a string preceding S draws into the background of S, or S
1182 contains the first component of a composition. */
1185 x_draw_glyph_string_background (s
, force_p
)
1186 struct glyph_string
*s
;
1189 /* Nothing to do if background has already been drawn or if it
1190 shouldn't be drawn in the first place. */
1191 if (!s
->background_filled_p
)
1193 int box_line_width
= max (s
->face
->box_line_width
, 0);
1197 /* Fill background with a stipple pattern. */
1198 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1199 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1200 s
->y
+ box_line_width
,
1201 s
->background_width
,
1202 s
->height
- 2 * box_line_width
);
1203 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1204 s
->background_filled_p
= 1;
1206 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1207 || s
->font_not_found_p
1208 || s
->extends_to_end_of_line_p
1211 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1212 s
->background_width
,
1213 s
->height
- 2 * box_line_width
);
1214 s
->background_filled_p
= 1;
1220 /* Draw the foreground of glyph string S. */
1223 x_draw_glyph_string_foreground (s
)
1224 struct glyph_string
*s
;
1228 /* If first glyph of S has a left box line, start drawing the text
1229 of S to the right of that box line. */
1230 if (s
->face
->box
!= FACE_NO_BOX
1231 && s
->first_glyph
->left_box_line_p
)
1232 x
= s
->x
+ abs (s
->face
->box_line_width
);
1236 /* Draw characters of S as rectangles if S's font could not be
1238 if (s
->font_not_found_p
)
1240 for (i
= 0; i
< s
->nchars
; ++i
)
1242 struct glyph
*g
= s
->first_glyph
+ i
;
1243 XDrawRectangle (s
->display
, s
->window
,
1244 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1246 x
+= g
->pixel_width
;
1251 char *char1b
= (char *) s
->char2b
;
1252 int boff
= s
->font_info
->baseline_offset
;
1254 if (s
->font_info
->vertical_centering
)
1255 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1257 /* If we can use 8-bit functions, condense S->char2b. */
1259 for (i
= 0; i
< s
->nchars
; ++i
)
1260 char1b
[i
] = s
->char2b
[i
].byte2
;
1262 /* Draw text with XDrawString if background has already been
1263 filled. Otherwise, use XDrawImageString. (Note that
1264 XDrawImageString is usually faster than XDrawString.) Always
1265 use XDrawImageString when drawing the cursor so that there is
1266 no chance that characters under a box cursor are invisible. */
1267 if (s
->for_overlaps_p
1268 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1270 /* Draw characters with 16-bit or 8-bit functions. */
1272 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1273 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1275 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1276 s
->ybase
- boff
, char1b
, s
->nchars
);
1281 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1282 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1284 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1285 s
->ybase
- boff
, char1b
, s
->nchars
);
1288 if (s
->face
->overstrike
)
1290 /* For overstriking (to simulate bold-face), draw the
1291 characters again shifted to the right by one pixel. */
1293 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1294 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1296 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1297 s
->ybase
- boff
, char1b
, s
->nchars
);
1302 /* Draw the foreground of composite glyph string S. */
1305 x_draw_composite_glyph_string_foreground (s
)
1306 struct glyph_string
*s
;
1310 /* If first glyph of S has a left box line, start drawing the text
1311 of S to the right of that box line. */
1312 if (s
->face
->box
!= FACE_NO_BOX
1313 && s
->first_glyph
->left_box_line_p
)
1314 x
= s
->x
+ abs (s
->face
->box_line_width
);
1318 /* S is a glyph string for a composition. S->gidx is the index of
1319 the first character drawn for glyphs of this composition.
1320 S->gidx == 0 means we are drawing the very first character of
1321 this composition. */
1323 /* Draw a rectangle for the composition if the font for the very
1324 first character of the composition could not be loaded. */
1325 if (s
->font_not_found_p
)
1328 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1329 s
->width
- 1, s
->height
- 1);
1333 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
1335 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1336 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
1337 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1339 if (s
->face
->overstrike
)
1340 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1341 x
+ s
->cmp
->offsets
[s
->gidx
* 2] + 1,
1342 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1349 #ifdef USE_X_TOOLKIT
1351 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1352 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1353 XrmValue
*, XrmValue
*, XtPointer
*));
1354 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1355 XrmValue
*, Cardinal
*));
1358 /* Return the frame on which widget WIDGET is used.. Abort if frame
1359 cannot be determined. */
1361 static struct frame
*
1362 x_frame_of_widget (widget
)
1365 struct x_display_info
*dpyinfo
;
1369 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1371 /* Find the top-level shell of the widget. Note that this function
1372 can be called when the widget is not yet realized, so XtWindow
1373 (widget) == 0. That's the reason we can't simply use
1374 x_any_window_to_frame. */
1375 while (!XtIsTopLevelShell (widget
))
1376 widget
= XtParent (widget
);
1378 /* Look for a frame with that top-level widget. Allocate the color
1379 on that frame to get the right gamma correction value. */
1380 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
1381 if (GC_FRAMEP (XCAR (tail
))
1382 && (f
= XFRAME (XCAR (tail
)),
1384 && f
->output_data
.nothing
!= 1
1385 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1386 && f
->output_data
.x
->widget
== widget
)
1393 /* Allocate the color COLOR->pixel on the screen and display of
1394 widget WIDGET in colormap CMAP. If an exact match cannot be
1395 allocated, try the nearest color available. Value is non-zero
1396 if successful. This is called from lwlib. */
1399 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1404 struct frame
*f
= x_frame_of_widget (widget
);
1405 return x_alloc_nearest_color (f
, cmap
, color
);
1409 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1410 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1411 If this produces the same color as PIXEL, try a color where all RGB
1412 values have DELTA added. Return the allocated color in *PIXEL.
1413 DISPLAY is the X display, CMAP is the colormap to operate on.
1414 Value is non-zero if successful. */
1417 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1421 unsigned long *pixel
;
1425 struct frame
*f
= x_frame_of_widget (widget
);
1426 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1430 /* Structure specifying which arguments should be passed by Xt to
1431 cvt_string_to_pixel. We want the widget's screen and colormap. */
1433 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1435 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1437 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1442 /* The address of this variable is returned by
1443 cvt_string_to_pixel. */
1445 static Pixel cvt_string_to_pixel_value
;
1448 /* Convert a color name to a pixel color.
1450 DPY is the display we are working on.
1452 ARGS is an array of *NARGS XrmValue structures holding additional
1453 information about the widget for which the conversion takes place.
1454 The contents of this array are determined by the specification
1455 in cvt_string_to_pixel_args.
1457 FROM is a pointer to an XrmValue which points to the color name to
1458 convert. TO is an XrmValue in which to return the pixel color.
1460 CLOSURE_RET is a pointer to user-data, in which we record if
1461 we allocated the color or not.
1463 Value is True if successful, False otherwise. */
1466 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1470 XrmValue
*from
, *to
;
1471 XtPointer
*closure_ret
;
1481 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1482 "wrongParameters", "cvt_string_to_pixel",
1484 "Screen and colormap args required", NULL
, NULL
);
1488 screen
= *(Screen
**) args
[0].addr
;
1489 cmap
= *(Colormap
*) args
[1].addr
;
1490 color_name
= (String
) from
->addr
;
1492 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1494 *closure_ret
= (XtPointer
) False
;
1495 pixel
= WhitePixelOfScreen (screen
);
1497 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1499 *closure_ret
= (XtPointer
) False
;
1500 pixel
= BlackPixelOfScreen (screen
);
1502 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1503 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1505 pixel
= color
.pixel
;
1506 *closure_ret
= (XtPointer
) True
;
1511 Cardinal nparams
= 1;
1513 params
[0] = color_name
;
1514 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1515 "badValue", "cvt_string_to_pixel",
1516 "XtToolkitError", "Invalid color `%s'",
1521 if (to
->addr
!= NULL
)
1523 if (to
->size
< sizeof (Pixel
))
1525 to
->size
= sizeof (Pixel
);
1529 *(Pixel
*) to
->addr
= pixel
;
1533 cvt_string_to_pixel_value
= pixel
;
1534 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1537 to
->size
= sizeof (Pixel
);
1542 /* Free a pixel color which was previously allocated via
1543 cvt_string_to_pixel. This is registered as the destructor
1544 for this type of resource via XtSetTypeConverter.
1546 APP is the application context in which we work.
1548 TO is a pointer to an XrmValue holding the color to free.
1549 CLOSURE is the value we stored in CLOSURE_RET for this color
1550 in cvt_string_to_pixel.
1552 ARGS and NARGS are like for cvt_string_to_pixel. */
1555 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1564 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1566 "Screen and colormap arguments required",
1569 else if (closure
!= NULL
)
1571 /* We did allocate the pixel, so free it. */
1572 Screen
*screen
= *(Screen
**) args
[0].addr
;
1573 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1574 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1575 (Pixel
*) to
->addr
, 1);
1580 #endif /* USE_X_TOOLKIT */
1583 /* Value is an array of XColor structures for the contents of the
1584 color map of display DPY. Set *NCELLS to the size of the array.
1585 Note that this probably shouldn't be called for large color maps,
1586 say a 24-bit TrueColor map. */
1588 static const XColor
*
1589 x_color_cells (dpy
, ncells
)
1593 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1595 if (dpyinfo
->color_cells
== NULL
)
1597 Screen
*screen
= dpyinfo
->screen
;
1600 dpyinfo
->ncolor_cells
1601 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1602 dpyinfo
->color_cells
1603 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1604 * sizeof *dpyinfo
->color_cells
);
1606 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1607 dpyinfo
->color_cells
[i
].pixel
= i
;
1609 XQueryColors (dpy
, dpyinfo
->cmap
,
1610 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1613 *ncells
= dpyinfo
->ncolor_cells
;
1614 return dpyinfo
->color_cells
;
1618 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1619 colors in COLORS. Use cached information, if available. */
1622 x_query_colors (f
, colors
, ncolors
)
1627 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1629 if (dpyinfo
->color_cells
)
1632 for (i
= 0; i
< ncolors
; ++i
)
1634 unsigned long pixel
= colors
[i
].pixel
;
1635 xassert (pixel
< dpyinfo
->ncolor_cells
);
1636 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1637 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1641 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1645 /* On frame F, translate pixel color to RGB values for the color in
1646 COLOR. Use cached information, if available. */
1649 x_query_color (f
, color
)
1653 x_query_colors (f
, color
, 1);
1657 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1658 exact match can't be allocated, try the nearest color available.
1659 Value is non-zero if successful. Set *COLOR to the color
1663 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1670 rc
= XAllocColor (dpy
, cmap
, color
);
1673 /* If we got to this point, the colormap is full, so we're going
1674 to try to get the next closest color. The algorithm used is
1675 a least-squares matching, which is what X uses for closest
1676 color matching with StaticColor visuals. */
1678 unsigned long nearest_delta
= ~0;
1680 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1682 for (nearest
= i
= 0; i
< ncells
; ++i
)
1684 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1685 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1686 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1687 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1689 if (delta
< nearest_delta
)
1692 nearest_delta
= delta
;
1696 color
->red
= cells
[nearest
].red
;
1697 color
->green
= cells
[nearest
].green
;
1698 color
->blue
= cells
[nearest
].blue
;
1699 rc
= XAllocColor (dpy
, cmap
, color
);
1703 /* If allocation succeeded, and the allocated pixel color is not
1704 equal to a cached pixel color recorded earlier, there was a
1705 change in the colormap, so clear the color cache. */
1706 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1707 XColor
*cached_color
;
1709 if (dpyinfo
->color_cells
1710 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1711 (cached_color
->red
!= color
->red
1712 || cached_color
->blue
!= color
->blue
1713 || cached_color
->green
!= color
->green
)))
1715 xfree (dpyinfo
->color_cells
);
1716 dpyinfo
->color_cells
= NULL
;
1717 dpyinfo
->ncolor_cells
= 0;
1721 #ifdef DEBUG_X_COLORS
1723 register_color (color
->pixel
);
1724 #endif /* DEBUG_X_COLORS */
1730 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1731 exact match can't be allocated, try the nearest color available.
1732 Value is non-zero if successful. Set *COLOR to the color
1736 x_alloc_nearest_color (f
, cmap
, color
)
1741 gamma_correct (f
, color
);
1742 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1746 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1747 It's necessary to do this instead of just using PIXEL directly to
1748 get color reference counts right. */
1751 x_copy_color (f
, pixel
)
1753 unsigned long pixel
;
1757 color
.pixel
= pixel
;
1759 x_query_color (f
, &color
);
1760 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1762 #ifdef DEBUG_X_COLORS
1763 register_color (pixel
);
1769 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1770 It's necessary to do this instead of just using PIXEL directly to
1771 get color reference counts right. */
1774 x_copy_dpy_color (dpy
, cmap
, pixel
)
1777 unsigned long pixel
;
1781 color
.pixel
= pixel
;
1783 XQueryColor (dpy
, cmap
, &color
);
1784 XAllocColor (dpy
, cmap
, &color
);
1786 #ifdef DEBUG_X_COLORS
1787 register_color (pixel
);
1793 /* Brightness beyond which a color won't have its highlight brightness
1796 Nominally, highlight colors for `3d' faces are calculated by
1797 brightening an object's color by a constant scale factor, but this
1798 doesn't yield good results for dark colors, so for colors who's
1799 brightness is less than this value (on a scale of 0-65535) have an
1800 use an additional additive factor.
1802 The value here is set so that the default menu-bar/mode-line color
1803 (grey75) will not have its highlights changed at all. */
1804 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1807 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1808 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1809 If this produces the same color as PIXEL, try a color where all RGB
1810 values have DELTA added. Return the allocated color in *PIXEL.
1811 DISPLAY is the X display, CMAP is the colormap to operate on.
1812 Value is non-zero if successful. */
1815 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
1819 unsigned long *pixel
;
1827 /* Get RGB color values. */
1828 color
.pixel
= *pixel
;
1829 x_query_color (f
, &color
);
1831 /* Change RGB values by specified FACTOR. Avoid overflow! */
1832 xassert (factor
>= 0);
1833 new.red
= min (0xffff, factor
* color
.red
);
1834 new.green
= min (0xffff, factor
* color
.green
);
1835 new.blue
= min (0xffff, factor
* color
.blue
);
1837 /* Calculate brightness of COLOR. */
1838 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1840 /* We only boost colors that are darker than
1841 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1842 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1843 /* Make an additive adjustment to NEW, because it's dark enough so
1844 that scaling by FACTOR alone isn't enough. */
1846 /* How far below the limit this color is (0 - 1, 1 being darker). */
1847 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1848 /* The additive adjustment. */
1849 int min_delta
= delta
* dimness
* factor
/ 2;
1853 new.red
= max (0, new.red
- min_delta
);
1854 new.green
= max (0, new.green
- min_delta
);
1855 new.blue
= max (0, new.blue
- min_delta
);
1859 new.red
= min (0xffff, min_delta
+ new.red
);
1860 new.green
= min (0xffff, min_delta
+ new.green
);
1861 new.blue
= min (0xffff, min_delta
+ new.blue
);
1865 /* Try to allocate the color. */
1866 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1869 if (new.pixel
== *pixel
)
1871 /* If we end up with the same color as before, try adding
1872 delta to the RGB values. */
1873 x_free_colors (f
, &new.pixel
, 1);
1875 new.red
= min (0xffff, delta
+ color
.red
);
1876 new.green
= min (0xffff, delta
+ color
.green
);
1877 new.blue
= min (0xffff, delta
+ color
.blue
);
1878 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1889 /* Set up the foreground color for drawing relief lines of glyph
1890 string S. RELIEF is a pointer to a struct relief containing the GC
1891 with which lines will be drawn. Use a color that is FACTOR or
1892 DELTA lighter or darker than the relief's background which is found
1893 in S->f->output_data.x->relief_background. If such a color cannot
1894 be allocated, use DEFAULT_PIXEL, instead. */
1897 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1899 struct relief
*relief
;
1902 unsigned long default_pixel
;
1905 struct x_output
*di
= f
->output_data
.x
;
1906 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1907 unsigned long pixel
;
1908 unsigned long background
= di
->relief_background
;
1909 Colormap cmap
= FRAME_X_COLORMAP (f
);
1910 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1911 Display
*dpy
= FRAME_X_DISPLAY (f
);
1913 xgcv
.graphics_exposures
= False
;
1914 xgcv
.line_width
= 1;
1916 /* Free previously allocated color. The color cell will be reused
1917 when it has been freed as many times as it was allocated, so this
1918 doesn't affect faces using the same colors. */
1920 && relief
->allocated_p
)
1922 x_free_colors (f
, &relief
->pixel
, 1);
1923 relief
->allocated_p
= 0;
1926 /* Allocate new color. */
1927 xgcv
.foreground
= default_pixel
;
1929 if (dpyinfo
->n_planes
!= 1
1930 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1932 relief
->allocated_p
= 1;
1933 xgcv
.foreground
= relief
->pixel
= pixel
;
1936 if (relief
->gc
== 0)
1938 xgcv
.stipple
= dpyinfo
->gray
;
1940 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1943 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1947 /* Set up colors for the relief lines around glyph string S. */
1950 x_setup_relief_colors (s
)
1951 struct glyph_string
*s
;
1953 struct x_output
*di
= s
->f
->output_data
.x
;
1954 unsigned long color
;
1956 if (s
->face
->use_box_color_for_shadows_p
)
1957 color
= s
->face
->box_color
;
1958 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1960 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1961 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1966 /* Get the background color of the face. */
1967 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1968 color
= xgcv
.background
;
1971 if (di
->white_relief
.gc
== 0
1972 || color
!= di
->relief_background
)
1974 di
->relief_background
= color
;
1975 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1976 WHITE_PIX_DEFAULT (s
->f
));
1977 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1978 BLACK_PIX_DEFAULT (s
->f
));
1983 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1984 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1985 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1986 relief. LEFT_P non-zero means draw a relief on the left side of
1987 the rectangle. RIGHT_P non-zero means draw a relief on the right
1988 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1992 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
1993 raised_p
, left_p
, right_p
, clip_rect
)
1995 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
, raised_p
;
1996 XRectangle
*clip_rect
;
1998 Display
*dpy
= FRAME_X_DISPLAY (f
);
1999 Window window
= FRAME_X_WINDOW (f
);
2004 gc
= f
->output_data
.x
->white_relief
.gc
;
2006 gc
= f
->output_data
.x
->black_relief
.gc
;
2007 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2010 for (i
= 0; i
< width
; ++i
)
2011 XDrawLine (dpy
, window
, gc
,
2012 left_x
+ i
* left_p
, top_y
+ i
,
2013 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2017 for (i
= 0; i
< width
; ++i
)
2018 XDrawLine (dpy
, window
, gc
,
2019 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2021 XSetClipMask (dpy
, gc
, None
);
2023 gc
= f
->output_data
.x
->black_relief
.gc
;
2025 gc
= f
->output_data
.x
->white_relief
.gc
;
2026 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2029 for (i
= 0; i
< width
; ++i
)
2030 XDrawLine (dpy
, window
, gc
,
2031 left_x
+ i
* left_p
, bottom_y
- i
,
2032 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2036 for (i
= 0; i
< width
; ++i
)
2037 XDrawLine (dpy
, window
, gc
,
2038 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2040 XSetClipMask (dpy
, gc
, None
);
2044 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2045 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2046 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2047 left side of the rectangle. RIGHT_P non-zero means draw a line
2048 on the right side of the rectangle. CLIP_RECT is the clipping
2049 rectangle to use when drawing. */
2052 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2053 left_p
, right_p
, clip_rect
)
2054 struct glyph_string
*s
;
2055 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2056 XRectangle
*clip_rect
;
2060 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2061 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2062 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2065 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2066 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2070 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2071 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2074 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2075 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2079 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2080 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2082 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2083 XSetClipMask (s
->display
, s
->gc
, None
);
2087 /* Draw a box around glyph string S. */
2090 x_draw_glyph_string_box (s
)
2091 struct glyph_string
*s
;
2093 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2094 int left_p
, right_p
;
2095 struct glyph
*last_glyph
;
2096 XRectangle clip_rect
;
2098 last_x
= window_box_right (s
->w
, s
->area
);
2099 if (s
->row
->full_width_p
2100 && !s
->w
->pseudo_window_p
)
2102 last_x
+= WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH (s
->w
);
2103 if (s
->area
!= RIGHT_MARGIN_AREA
2104 || WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (s
->w
))
2105 last_x
+= WINDOW_RIGHT_FRINGE_WIDTH (s
->w
);
2108 /* The glyph that may have a right box line. */
2109 last_glyph
= (s
->cmp
|| s
->img
2111 : s
->first_glyph
+ s
->nchars
- 1);
2113 width
= abs (s
->face
->box_line_width
);
2114 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2116 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2118 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2120 bottom_y
= top_y
+ s
->height
- 1;
2122 left_p
= (s
->first_glyph
->left_box_line_p
2123 || (s
->hl
== DRAW_MOUSE_FACE
2125 || s
->prev
->hl
!= s
->hl
)));
2126 right_p
= (last_glyph
->right_box_line_p
2127 || (s
->hl
== DRAW_MOUSE_FACE
2129 || s
->next
->hl
!= s
->hl
)));
2131 get_glyph_string_clip_rect (s
, &clip_rect
);
2133 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2134 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2135 left_p
, right_p
, &clip_rect
);
2138 x_setup_relief_colors (s
);
2139 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2140 width
, raised_p
, left_p
, right_p
, &clip_rect
);
2145 /* Draw foreground of image glyph string S. */
2148 x_draw_image_foreground (s
)
2149 struct glyph_string
*s
;
2152 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
2154 /* If first glyph of S has a left box line, start drawing it to the
2155 right of that line. */
2156 if (s
->face
->box
!= FACE_NO_BOX
2157 && s
->first_glyph
->left_box_line_p
)
2158 x
= s
->x
+ abs (s
->face
->box_line_width
);
2162 /* If there is a margin around the image, adjust x- and y-position
2164 x
+= s
->img
->hmargin
;
2165 y
+= s
->img
->vmargin
;
2171 /* We can't set both a clip mask and use XSetClipRectangles
2172 because the latter also sets a clip mask. We also can't
2173 trust on the shape extension to be available
2174 (XShapeCombineRegion). So, compute the rectangle to draw
2176 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2179 XRectangle clip_rect
, image_rect
, r
;
2181 xgcv
.clip_mask
= s
->img
->mask
;
2182 xgcv
.clip_x_origin
= x
;
2183 xgcv
.clip_y_origin
= y
;
2184 xgcv
.function
= GXcopy
;
2185 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2187 get_glyph_string_clip_rect (s
, &clip_rect
);
2190 image_rect
.width
= s
->img
->width
;
2191 image_rect
.height
= s
->img
->height
;
2192 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2193 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2194 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
2198 XRectangle clip_rect
, image_rect
, r
;
2200 get_glyph_string_clip_rect (s
, &clip_rect
);
2203 image_rect
.width
= s
->img
->width
;
2204 image_rect
.height
= s
->img
->height
;
2205 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2206 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2207 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
2209 /* When the image has a mask, we can expect that at
2210 least part of a mouse highlight or a block cursor will
2211 be visible. If the image doesn't have a mask, make
2212 a block cursor visible by drawing a rectangle around
2213 the image. I believe it's looking better if we do
2214 nothing here for mouse-face. */
2215 if (s
->hl
== DRAW_CURSOR
)
2217 int r
= s
->img
->relief
;
2219 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2220 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
2225 /* Draw a rectangle if image could not be loaded. */
2226 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2227 s
->img
->width
- 1, s
->img
->height
- 1);
2231 /* Draw a relief around the image glyph string S. */
2234 x_draw_image_relief (s
)
2235 struct glyph_string
*s
;
2237 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2240 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
2242 /* If first glyph of S has a left box line, start drawing it to the
2243 right of that line. */
2244 if (s
->face
->box
!= FACE_NO_BOX
2245 && s
->first_glyph
->left_box_line_p
)
2246 x
= s
->x
+ abs (s
->face
->box_line_width
);
2250 /* If there is a margin around the image, adjust x- and y-position
2252 x
+= s
->img
->hmargin
;
2253 y
+= s
->img
->vmargin
;
2255 if (s
->hl
== DRAW_IMAGE_SUNKEN
2256 || s
->hl
== DRAW_IMAGE_RAISED
)
2258 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2259 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2263 thick
= abs (s
->img
->relief
);
2264 raised_p
= s
->img
->relief
> 0;
2269 x1
= x
+ s
->img
->width
+ thick
- 1;
2270 y1
= y
+ s
->img
->height
+ thick
- 1;
2272 x_setup_relief_colors (s
);
2273 get_glyph_string_clip_rect (s
, &r
);
2274 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
2278 /* Draw the foreground of image glyph string S to PIXMAP. */
2281 x_draw_image_foreground_1 (s
, pixmap
)
2282 struct glyph_string
*s
;
2286 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
2288 /* If first glyph of S has a left box line, start drawing it to the
2289 right of that line. */
2290 if (s
->face
->box
!= FACE_NO_BOX
2291 && s
->first_glyph
->left_box_line_p
)
2292 x
= abs (s
->face
->box_line_width
);
2296 /* If there is a margin around the image, adjust x- and y-position
2298 x
+= s
->img
->hmargin
;
2299 y
+= s
->img
->vmargin
;
2305 /* We can't set both a clip mask and use XSetClipRectangles
2306 because the latter also sets a clip mask. We also can't
2307 trust on the shape extension to be available
2308 (XShapeCombineRegion). So, compute the rectangle to draw
2310 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2314 xgcv
.clip_mask
= s
->img
->mask
;
2315 xgcv
.clip_x_origin
= x
;
2316 xgcv
.clip_y_origin
= y
;
2317 xgcv
.function
= GXcopy
;
2318 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2320 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2321 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
2322 XSetClipMask (s
->display
, s
->gc
, None
);
2326 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2327 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
2329 /* When the image has a mask, we can expect that at
2330 least part of a mouse highlight or a block cursor will
2331 be visible. If the image doesn't have a mask, make
2332 a block cursor visible by drawing a rectangle around
2333 the image. I believe it's looking better if we do
2334 nothing here for mouse-face. */
2335 if (s
->hl
== DRAW_CURSOR
)
2337 int r
= s
->img
->relief
;
2339 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2340 s
->img
->width
+ r
*2 - 1, s
->img
->height
+ r
*2 - 1);
2345 /* Draw a rectangle if image could not be loaded. */
2346 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2347 s
->img
->width
- 1, s
->img
->height
- 1);
2351 /* Draw part of the background of glyph string S. X, Y, W, and H
2352 give the rectangle to draw. */
2355 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2356 struct glyph_string
*s
;
2361 /* Fill background with a stipple pattern. */
2362 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2363 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2364 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2367 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2371 /* Draw image glyph string S.
2374 s->x +-------------------------
2377 | +-------------------------
2380 | | +-------------------
2386 x_draw_image_glyph_string (s
)
2387 struct glyph_string
*s
;
2390 int box_line_hwidth
= abs (s
->face
->box_line_width
);
2391 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2393 Pixmap pixmap
= None
;
2395 height
= s
->height
- 2 * box_line_vwidth
;
2398 /* Fill background with face under the image. Do it only if row is
2399 taller than image or if image has a clip mask to reduce
2401 s
->stippled_p
= s
->face
->stipple
!= 0;
2402 if (height
> s
->img
->height
2406 || s
->img
->pixmap
== 0
2407 || s
->width
!= s
->background_width
)
2409 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
2410 x
= s
->x
+ box_line_hwidth
;
2414 y
= s
->y
+ box_line_vwidth
;
2418 /* Create a pixmap as large as the glyph string. Fill it
2419 with the background color. Copy the image to it, using
2420 its mask. Copy the temporary pixmap to the display. */
2421 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2422 int depth
= DefaultDepthOfScreen (screen
);
2424 /* Create a pixmap as large as the glyph string. */
2425 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2426 s
->background_width
,
2429 /* Don't clip in the following because we're working on the
2431 XSetClipMask (s
->display
, s
->gc
, None
);
2433 /* Fill the pixmap with the background color/stipple. */
2436 /* Fill background with a stipple pattern. */
2437 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2438 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2439 0, 0, s
->background_width
, s
->height
);
2440 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2445 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2447 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2448 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2449 0, 0, s
->background_width
, s
->height
);
2450 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2454 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2456 s
->background_filled_p
= 1;
2459 /* Draw the foreground. */
2462 x_draw_image_foreground_1 (s
, pixmap
);
2463 x_set_glyph_string_clipping (s
);
2464 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2465 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2466 XFreePixmap (s
->display
, pixmap
);
2469 x_draw_image_foreground (s
);
2471 /* If we must draw a relief around the image, do it. */
2473 || s
->hl
== DRAW_IMAGE_RAISED
2474 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2475 x_draw_image_relief (s
);
2479 /* Draw stretch glyph string S. */
2482 x_draw_stretch_glyph_string (s
)
2483 struct glyph_string
*s
;
2485 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2486 s
->stippled_p
= s
->face
->stipple
!= 0;
2488 if (s
->hl
== DRAW_CURSOR
2489 && !x_stretch_cursor_p
)
2491 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2492 as wide as the stretch glyph. */
2493 int width
= min (FRAME_COLUMN_WIDTH (s
->f
), s
->background_width
);
2496 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
2498 /* Clear rest using the GC of the original non-cursor face. */
2499 if (width
< s
->background_width
)
2501 int x
= s
->x
+ width
, y
= s
->y
;
2502 int w
= s
->background_width
- width
, h
= s
->height
;
2506 if (s
->row
->mouse_face_p
2507 && cursor_in_mouse_face_p (s
->w
))
2509 x_set_mouse_face_gc (s
);
2515 get_glyph_string_clip_rect (s
, &r
);
2516 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2518 if (s
->face
->stipple
)
2520 /* Fill background with a stipple pattern. */
2521 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2522 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2523 XSetFillStyle (s
->display
, gc
, FillSolid
);
2528 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2529 XSetForeground (s
->display
, gc
, xgcv
.background
);
2530 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2531 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2535 else if (!s
->background_filled_p
)
2536 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
2539 s
->background_filled_p
= 1;
2543 /* Draw glyph string S. */
2546 x_draw_glyph_string (s
)
2547 struct glyph_string
*s
;
2549 int relief_drawn_p
= 0;
2551 /* If S draws into the background of its successor, draw the
2552 background of the successor first so that S can draw into it.
2553 This makes S->next use XDrawString instead of XDrawImageString. */
2554 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
2556 xassert (s
->next
->img
== NULL
);
2557 x_set_glyph_string_gc (s
->next
);
2558 x_set_glyph_string_clipping (s
->next
);
2559 x_draw_glyph_string_background (s
->next
, 1);
2562 /* Set up S->gc, set clipping and draw S. */
2563 x_set_glyph_string_gc (s
);
2565 /* Draw relief (if any) in advance for char/composition so that the
2566 glyph string can be drawn over it. */
2567 if (!s
->for_overlaps_p
2568 && s
->face
->box
!= FACE_NO_BOX
2569 && (s
->first_glyph
->type
== CHAR_GLYPH
2570 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2573 x_set_glyph_string_clipping (s
);
2574 x_draw_glyph_string_background (s
, 1);
2575 x_draw_glyph_string_box (s
);
2576 x_set_glyph_string_clipping (s
);
2580 x_set_glyph_string_clipping (s
);
2582 switch (s
->first_glyph
->type
)
2585 x_draw_image_glyph_string (s
);
2589 x_draw_stretch_glyph_string (s
);
2593 if (s
->for_overlaps_p
)
2594 s
->background_filled_p
= 1;
2596 x_draw_glyph_string_background (s
, 0);
2597 x_draw_glyph_string_foreground (s
);
2600 case COMPOSITE_GLYPH
:
2601 if (s
->for_overlaps_p
|| s
->gidx
> 0)
2602 s
->background_filled_p
= 1;
2604 x_draw_glyph_string_background (s
, 1);
2605 x_draw_composite_glyph_string_foreground (s
);
2612 if (!s
->for_overlaps_p
)
2614 /* Draw underline. */
2615 if (s
->face
->underline_p
)
2617 unsigned long tem
, h
;
2620 /* Get the underline thickness. Default is 1 pixel. */
2621 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
2624 /* Get the underline position. This is the recommended
2625 vertical offset in pixels from the baseline to the top of
2626 the underline. This is a signed value according to the
2627 specs, and its default is
2629 ROUND ((maximum descent) / 2), with
2630 ROUND(x) = floor (x + 0.5) */
2632 if (x_use_underline_position_properties
2633 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
2634 y
= s
->ybase
+ (long) tem
;
2635 else if (s
->face
->font
)
2636 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2638 y
= s
->y
+ s
->height
- h
;
2640 if (s
->face
->underline_defaulted_p
)
2641 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2642 s
->x
, y
, s
->width
, h
);
2646 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2647 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2648 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2649 s
->x
, y
, s
->width
, h
);
2650 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2654 /* Draw overline. */
2655 if (s
->face
->overline_p
)
2657 unsigned long dy
= 0, h
= 1;
2659 if (s
->face
->overline_color_defaulted_p
)
2660 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2665 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2666 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2667 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2669 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2673 /* Draw strike-through. */
2674 if (s
->face
->strike_through_p
)
2676 unsigned long h
= 1;
2677 unsigned long dy
= (s
->height
- h
) / 2;
2679 if (s
->face
->strike_through_color_defaulted_p
)
2680 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2685 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2686 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2687 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2689 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2693 /* Draw relief if not yet drawn. */
2694 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2695 x_draw_glyph_string_box (s
);
2698 /* Reset clipping. */
2699 XSetClipMask (s
->display
, s
->gc
, None
);
2702 /* Shift display to make room for inserted glyphs. */
2705 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2707 int x
, y
, width
, height
, shift_by
;
2709 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2710 f
->output_data
.x
->normal_gc
,
2711 x
, y
, width
, height
,
2715 /* Delete N glyphs at the nominal cursor position. Not implemented
2726 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2727 If they are <= 0, this is probably an error. */
2730 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
2737 xassert (width
> 0 && height
> 0);
2738 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2742 /* Clear entire frame. If updating_frame is non-null, clear that
2743 frame. Otherwise clear the selected frame. */
2753 f
= SELECTED_FRAME ();
2755 /* Clearing the frame will erase any cursor, so mark them all as no
2757 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2758 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2759 output_cursor
.x
= -1;
2761 /* We don't set the output cursor here because there will always
2762 follow an explicit cursor_to. */
2764 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2766 /* We have to clear the scroll bars, too. If we have changed
2767 colors or something like that, then they should be notified. */
2768 x_scroll_bar_clear (f
);
2770 XFlush (FRAME_X_DISPLAY (f
));
2773 xg_frame_cleared (f
);
2781 /* Invert the middle quarter of the frame for .15 sec. */
2783 /* We use the select system call to do the waiting, so we have to make
2784 sure it's available. If it isn't, we just won't do visual bells. */
2786 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2789 /* Subtract the `struct timeval' values X and Y, storing the result in
2790 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2793 timeval_subtract (result
, x
, y
)
2794 struct timeval
*result
, x
, y
;
2796 /* Perform the carry for the later subtraction by updating y. This
2797 is safer because on some systems the tv_sec member is unsigned. */
2798 if (x
.tv_usec
< y
.tv_usec
)
2800 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2801 y
.tv_usec
-= 1000000 * nsec
;
2805 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2807 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2808 y
.tv_usec
+= 1000000 * nsec
;
2812 /* Compute the time remaining to wait. tv_usec is certainly
2814 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2815 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2817 /* Return indication of whether the result should be considered
2819 return x
.tv_sec
< y
.tv_sec
;
2831 /* Create a GC that will use the GXxor function to flip foreground
2832 pixels into background pixels. */
2836 values
.function
= GXxor
;
2837 values
.foreground
= (f
->output_data
.x
->foreground_pixel
2838 ^ f
->output_data
.x
->background_pixel
);
2840 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2841 GCFunction
| GCForeground
, &values
);
2845 /* Get the height not including a menu bar widget. */
2846 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
2847 /* Height of each line to flash. */
2848 int flash_height
= FRAME_LINE_HEIGHT (f
);
2849 /* These will be the left and right margins of the rectangles. */
2850 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2851 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
2855 /* Don't flash the area between a scroll bar and the frame
2856 edge it is next to. */
2857 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
2859 case vertical_scroll_bar_left
:
2860 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2863 case vertical_scroll_bar_right
:
2864 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2871 width
= flash_right
- flash_left
;
2873 /* If window is tall, flash top and bottom line. */
2874 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2876 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2878 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2879 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
2880 width
, flash_height
);
2881 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2883 (height
- flash_height
2884 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2885 width
, flash_height
);
2888 /* If it is short, flash it all. */
2889 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2890 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2891 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2896 struct timeval wakeup
;
2898 EMACS_GET_TIME (wakeup
);
2900 /* Compute time to wait until, propagating carry from usecs. */
2901 wakeup
.tv_usec
+= 150000;
2902 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
2903 wakeup
.tv_usec
%= 1000000;
2905 /* Keep waiting until past the time wakeup or any input gets
2907 while (! detect_input_pending ())
2909 struct timeval current
;
2910 struct timeval timeout
;
2912 EMACS_GET_TIME (current
);
2914 /* Break if result would be negative. */
2915 if (timeval_subtract (¤t
, wakeup
, current
))
2918 /* How long `select' should wait. */
2920 timeout
.tv_usec
= 10000;
2922 /* Try to wait that long--but we might wake up sooner. */
2923 select (0, NULL
, NULL
, NULL
, &timeout
);
2927 /* If window is tall, flash top and bottom line. */
2928 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2930 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2932 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2933 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
2934 width
, flash_height
);
2935 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2937 (height
- flash_height
2938 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2939 width
, flash_height
);
2942 /* If it is short, flash it all. */
2943 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2944 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2945 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2947 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
2955 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
2958 /* Make audible bell. */
2963 struct frame
*f
= SELECTED_FRAME ();
2965 if (FRAME_X_DISPLAY (f
))
2967 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2974 XBell (FRAME_X_DISPLAY (f
), 0);
2975 XFlush (FRAME_X_DISPLAY (f
));
2982 /* Specify how many text lines, from the top of the window,
2983 should be affected by insert-lines and delete-lines operations.
2984 This, and those operations, are used only within an update
2985 that is bounded by calls to x_update_begin and x_update_end. */
2988 XTset_terminal_window (n
)
2991 /* This function intentionally left blank. */
2996 /***********************************************************************
2998 ***********************************************************************/
3000 /* Perform an insert-lines or delete-lines operation, inserting N
3001 lines or deleting -N lines at vertical position VPOS. */
3004 x_ins_del_lines (vpos
, n
)
3011 /* Scroll part of the display as described by RUN. */
3014 x_scroll_run (w
, run
)
3018 struct frame
*f
= XFRAME (w
->frame
);
3019 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3021 /* Get frame-relative bounding box of the text display area of W,
3022 without mode lines. Include in this box the left and right
3024 window_box (w
, -1, &x
, &y
, &width
, &height
);
3026 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3027 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3028 bottom_y
= y
+ height
;
3032 /* Scrolling up. Make sure we don't copy part of the mode
3033 line at the bottom. */
3034 if (from_y
+ run
->height
> bottom_y
)
3035 height
= bottom_y
- from_y
;
3037 height
= run
->height
;
3041 /* Scolling down. Make sure we don't copy over the mode line.
3043 if (to_y
+ run
->height
> bottom_y
)
3044 height
= bottom_y
- to_y
;
3046 height
= run
->height
;
3051 /* Cursor off. Will be switched on again in x_update_window_end. */
3055 XCopyArea (FRAME_X_DISPLAY (f
),
3056 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3057 f
->output_data
.x
->normal_gc
,
3067 /***********************************************************************
3069 ***********************************************************************/
3076 /* We used to only do this if Vx_no_window_manager was non-nil, but
3077 the ICCCM (section 4.1.6) says that the window's border pixmap
3078 and border pixel are window attributes which are "private to the
3079 client", so we can always change it to whatever we want. */
3081 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3082 f
->output_data
.x
->border_pixel
);
3084 x_update_cursor (f
, 1);
3088 frame_unhighlight (f
)
3091 /* We used to only do this if Vx_no_window_manager was non-nil, but
3092 the ICCCM (section 4.1.6) says that the window's border pixmap
3093 and border pixel are window attributes which are "private to the
3094 client", so we can always change it to whatever we want. */
3096 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3097 f
->output_data
.x
->border_tile
);
3099 x_update_cursor (f
, 1);
3102 /* The focus has changed. Update the frames as necessary to reflect
3103 the new situation. Note that we can't change the selected frame
3104 here, because the Lisp code we are interrupting might become confused.
3105 Each event gets marked with the frame in which it occurred, so the
3106 Lisp code can tell when the switch took place by examining the events. */
3109 x_new_focus_frame (dpyinfo
, frame
)
3110 struct x_display_info
*dpyinfo
;
3111 struct frame
*frame
;
3113 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3115 if (frame
!= dpyinfo
->x_focus_frame
)
3117 /* Set this before calling other routines, so that they see
3118 the correct value of x_focus_frame. */
3119 dpyinfo
->x_focus_frame
= frame
;
3121 if (old_focus
&& old_focus
->auto_lower
)
3122 x_lower_frame (old_focus
);
3125 selected_frame
= frame
;
3126 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3128 Fselect_window (selected_frame
->selected_window
, Qnil
);
3129 choose_minibuf_frame ();
3132 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3133 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3135 pending_autoraise_frame
= 0;
3138 x_frame_rehighlight (dpyinfo
);
3141 /* Handle FocusIn and FocusOut state changes for FRAME.
3142 If FRAME has focus and there exists more than one frame, puts
3143 a FOCUS_IN_EVENT into BUFP.
3144 Returns number of events inserted into BUFP. */
3147 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
, numchars
)
3150 struct x_display_info
*dpyinfo
;
3151 struct frame
*frame
;
3152 struct input_event
*bufp
;
3157 if (type
== FocusIn
)
3159 if (dpyinfo
->x_focus_event_frame
!= frame
)
3161 x_new_focus_frame (dpyinfo
, frame
);
3162 dpyinfo
->x_focus_event_frame
= frame
;
3164 /* Don't stop displaying the initial startup message
3165 for a switch-frame event we don't need. */
3167 && GC_NILP (Vterminal_frame
)
3168 && GC_CONSP (Vframe_list
)
3169 && !GC_NILP (XCDR (Vframe_list
)))
3171 bufp
->kind
= FOCUS_IN_EVENT
;
3172 XSETFRAME (bufp
->frame_or_window
, frame
);
3180 frame
->output_data
.x
->focus_state
|= state
;
3183 if (FRAME_XIC (frame
))
3184 XSetICFocus (FRAME_XIC (frame
));
3187 else if (type
== FocusOut
)
3189 frame
->output_data
.x
->focus_state
&= ~state
;
3191 if (dpyinfo
->x_focus_event_frame
== frame
)
3193 dpyinfo
->x_focus_event_frame
= 0;
3194 x_new_focus_frame (dpyinfo
, 0);
3198 if (FRAME_XIC (frame
))
3199 XUnsetICFocus (FRAME_XIC (frame
));
3206 /* The focus may have changed. Figure out if it is a real focus change,
3207 by checking both FocusIn/Out and Enter/LeaveNotify events.
3209 Returns number of events inserted into BUFP. */
3212 x_detect_focus_change (dpyinfo
, event
, bufp
, numchars
)
3213 struct x_display_info
*dpyinfo
;
3215 struct input_event
*bufp
;
3218 struct frame
*frame
;
3221 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3222 if (! frame
) return nr_events
;
3224 switch (event
->type
)
3229 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3231 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3233 if (event
->xcrossing
.detail
!= NotifyInferior
3234 && event
->xcrossing
.focus
3235 && ! (focus_state
& FOCUS_EXPLICIT
))
3236 nr_events
= x_focus_changed ((event
->type
== EnterNotify
3237 ? FocusIn
: FocusOut
),
3248 nr_events
= x_focus_changed (event
->type
,
3249 (event
->xfocus
.detail
== NotifyPointer
3250 ? FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3262 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3265 x_mouse_leave (dpyinfo
)
3266 struct x_display_info
*dpyinfo
;
3268 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3271 /* The focus has changed, or we have redirected a frame's focus to
3272 another frame (this happens when a frame uses a surrogate
3273 mini-buffer frame). Shift the highlight as appropriate.
3275 The FRAME argument doesn't necessarily have anything to do with which
3276 frame is being highlighted or un-highlighted; we only use it to find
3277 the appropriate X display info. */
3280 XTframe_rehighlight (frame
)
3281 struct frame
*frame
;
3283 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3287 x_frame_rehighlight (dpyinfo
)
3288 struct x_display_info
*dpyinfo
;
3290 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3292 if (dpyinfo
->x_focus_frame
)
3294 dpyinfo
->x_highlight_frame
3295 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3296 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3297 : dpyinfo
->x_focus_frame
);
3298 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3300 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3301 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3305 dpyinfo
->x_highlight_frame
= 0;
3307 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3310 frame_unhighlight (old_highlight
);
3311 if (dpyinfo
->x_highlight_frame
)
3312 frame_highlight (dpyinfo
->x_highlight_frame
);
3318 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3320 /* Initialize mode_switch_bit and modifier_meaning. */
3322 x_find_modifier_meanings (dpyinfo
)
3323 struct x_display_info
*dpyinfo
;
3325 int min_code
, max_code
;
3328 XModifierKeymap
*mods
;
3330 dpyinfo
->meta_mod_mask
= 0;
3331 dpyinfo
->shift_lock_mask
= 0;
3332 dpyinfo
->alt_mod_mask
= 0;
3333 dpyinfo
->super_mod_mask
= 0;
3334 dpyinfo
->hyper_mod_mask
= 0;
3337 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3339 min_code
= dpyinfo
->display
->min_keycode
;
3340 max_code
= dpyinfo
->display
->max_keycode
;
3343 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3344 min_code
, max_code
- min_code
+ 1,
3346 mods
= XGetModifierMapping (dpyinfo
->display
);
3348 /* Scan the modifier table to see which modifier bits the Meta and
3349 Alt keysyms are on. */
3351 int row
, col
; /* The row and column in the modifier table. */
3353 for (row
= 3; row
< 8; row
++)
3354 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3357 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3359 /* Zeroes are used for filler. Skip them. */
3363 /* Are any of this keycode's keysyms a meta key? */
3367 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3369 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3375 dpyinfo
->meta_mod_mask
|= (1 << row
);
3380 dpyinfo
->alt_mod_mask
|= (1 << row
);
3385 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3390 dpyinfo
->super_mod_mask
|= (1 << row
);
3394 /* Ignore this if it's not on the lock modifier. */
3395 if ((1 << row
) == LockMask
)
3396 dpyinfo
->shift_lock_mask
= LockMask
;
3404 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3405 if (! dpyinfo
->meta_mod_mask
)
3407 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3408 dpyinfo
->alt_mod_mask
= 0;
3411 /* If some keys are both alt and meta,
3412 make them just meta, not alt. */
3413 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3415 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3418 XFree ((char *) syms
);
3419 XFreeModifiermap (mods
);
3422 /* Convert between the modifier bits X uses and the modifier bits
3426 x_x_to_emacs_modifiers (dpyinfo
, state
)
3427 struct x_display_info
*dpyinfo
;
3430 EMACS_UINT mod_meta
= meta_modifier
;
3431 EMACS_UINT mod_alt
= alt_modifier
;
3432 EMACS_UINT mod_hyper
= hyper_modifier
;
3433 EMACS_UINT mod_super
= super_modifier
;
3436 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3437 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3438 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3439 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3440 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3441 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3442 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3443 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3446 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3447 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3448 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3449 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3450 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3451 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3455 x_emacs_to_x_modifiers (dpyinfo
, state
)
3456 struct x_display_info
*dpyinfo
;
3459 EMACS_UINT mod_meta
= meta_modifier
;
3460 EMACS_UINT mod_alt
= alt_modifier
;
3461 EMACS_UINT mod_hyper
= hyper_modifier
;
3462 EMACS_UINT mod_super
= super_modifier
;
3466 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3467 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3468 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3469 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3470 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3471 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3472 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3473 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3476 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3477 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3478 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3479 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3480 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3481 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3484 /* Convert a keysym to its name. */
3487 x_get_keysym_name (keysym
)
3493 value
= XKeysymToString (keysym
);
3501 /* Mouse clicks and mouse movement. Rah. */
3503 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3505 If the event is a button press, then note that we have grabbed
3509 construct_mouse_click (result
, event
, f
)
3510 struct input_event
*result
;
3511 XButtonEvent
*event
;
3514 /* Make the event type NO_EVENT; we'll change that when we decide
3516 result
->kind
= MOUSE_CLICK_EVENT
;
3517 result
->code
= event
->button
- Button1
;
3518 result
->timestamp
= event
->time
;
3519 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3521 | (event
->type
== ButtonRelease
3525 XSETINT (result
->x
, event
->x
);
3526 XSETINT (result
->y
, event
->y
);
3527 XSETFRAME (result
->frame_or_window
, f
);
3533 /* Function to report a mouse movement to the mainstream Emacs code.
3534 The input handler calls this.
3536 We have received a mouse movement event, which is given in *event.
3537 If the mouse is over a different glyph than it was last time, tell
3538 the mainstream emacs code by setting mouse_moved. If not, ask for
3539 another motion event, so we can check again the next time it moves. */
3541 static XMotionEvent last_mouse_motion_event
;
3542 static Lisp_Object last_mouse_motion_frame
;
3545 note_mouse_movement (frame
, event
)
3547 XMotionEvent
*event
;
3549 last_mouse_movement_time
= event
->time
;
3550 last_mouse_motion_event
= *event
;
3551 XSETFRAME (last_mouse_motion_frame
, frame
);
3553 if (event
->window
!= FRAME_X_WINDOW (frame
))
3555 frame
->mouse_moved
= 1;
3556 last_mouse_scroll_bar
= Qnil
;
3557 note_mouse_highlight (frame
, -1, -1);
3560 /* Has the mouse moved off the glyph it was on at the last sighting? */
3561 else if (event
->x
< last_mouse_glyph
.x
3562 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3563 || event
->y
< last_mouse_glyph
.y
3564 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3566 frame
->mouse_moved
= 1;
3567 last_mouse_scroll_bar
= Qnil
;
3568 note_mouse_highlight (frame
, event
->x
, event
->y
);
3573 /************************************************************************
3575 ************************************************************************/
3578 redo_mouse_highlight ()
3580 if (!NILP (last_mouse_motion_frame
)
3581 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3582 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3583 last_mouse_motion_event
.x
,
3584 last_mouse_motion_event
.y
);
3588 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
3591 /* Try to determine frame pixel position and size of the glyph under
3592 frame pixel coordinates X/Y on frame F . Return the position and
3593 size in *RECT. Value is non-zero if we could compute these
3597 glyph_rect (f
, x
, y
, rect
)
3605 window
= window_from_coordinates (f
, x
, y
, 0, &x
, &y
, 0);
3608 struct window
*w
= XWINDOW (window
);
3609 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
3610 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
3612 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
3615 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
3616 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
3619 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
3622 rect
->width
= g
->pixel_width
;
3623 rect
->height
= r
->height
;
3624 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
3625 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
3635 /* Return the current position of the mouse.
3636 *FP should be a frame which indicates which display to ask about.
3638 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3639 and *PART to the frame, window, and scroll bar part that the mouse
3640 is over. Set *X and *Y to the portion and whole of the mouse's
3641 position on the scroll bar.
3643 If the mouse movement started elsewhere, set *FP to the frame the
3644 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3647 Set *TIME to the server time-stamp for the time at which the mouse
3648 was at this position.
3650 Don't store anything if we don't have a valid set of values to report.
3652 This clears the mouse_moved flag, so we can wait for the next mouse
3656 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3659 Lisp_Object
*bar_window
;
3660 enum scroll_bar_part
*part
;
3662 unsigned long *time
;
3668 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3669 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3675 Window dummy_window
;
3678 Lisp_Object frame
, tail
;
3680 /* Clear the mouse-moved flag for every frame on this display. */
3681 FOR_EACH_FRAME (tail
, frame
)
3682 if (FRAME_X_P (XFRAME (frame
))
3683 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3684 XFRAME (frame
)->mouse_moved
= 0;
3686 last_mouse_scroll_bar
= Qnil
;
3688 /* Figure out which root window we're on. */
3689 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3690 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3692 /* The root window which contains the pointer. */
3695 /* Trash which we can't trust if the pointer is on
3696 a different screen. */
3699 /* The position on that root window. */
3702 /* More trash we can't trust. */
3705 /* Modifier keys and pointer buttons, about which
3707 (unsigned int *) &dummy
);
3709 /* Now we have a position on the root; find the innermost window
3710 containing the pointer. */
3714 int parent_x
= 0, parent_y
= 0;
3719 /* XTranslateCoordinates can get errors if the window
3720 structure is changing at the same time this function
3721 is running. So at least we must not crash from them. */
3723 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
3725 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3726 && FRAME_LIVE_P (last_mouse_frame
))
3728 /* If mouse was grabbed on a frame, give coords for that frame
3729 even if the mouse is now outside it. */
3730 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3732 /* From-window, to-window. */
3733 root
, FRAME_X_WINDOW (last_mouse_frame
),
3735 /* From-position, to-position. */
3736 root_x
, root_y
, &win_x
, &win_y
,
3740 f1
= last_mouse_frame
;
3746 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3748 /* From-window, to-window. */
3751 /* From-position, to-position. */
3752 root_x
, root_y
, &win_x
, &win_y
,
3757 if (child
== None
|| child
== win
)
3765 /* Now we know that:
3766 win is the innermost window containing the pointer
3767 (XTC says it has no child containing the pointer),
3768 win_x and win_y are the pointer's position in it
3769 (XTC did this the last time through), and
3770 parent_x and parent_y are the pointer's position in win's parent.
3771 (They are what win_x and win_y were when win was child.
3772 If win is the root window, it has no parent, and
3773 parent_{x,y} are invalid, but that's okay, because we'll
3774 never use them in that case.) */
3776 /* Is win one of our frames? */
3777 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3779 #ifdef USE_X_TOOLKIT
3780 /* If we end up with the menu bar window, say it's not
3783 && f1
->output_data
.x
->menubar_widget
3784 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3786 #endif /* USE_X_TOOLKIT */
3789 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3792 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
3794 /* If not, is it one of our scroll bars? */
3797 struct scroll_bar
*bar
;
3799 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3803 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3809 if (f1
== 0 && insist
> 0)
3810 f1
= SELECTED_FRAME ();
3814 /* Ok, we found a frame. Store all the values.
3815 last_mouse_glyph is a rectangle used to reduce the
3816 generation of mouse events. To not miss any motion
3817 events, we must divide the frame into rectangles of the
3818 size of the smallest character that could be displayed
3819 on it, i.e. into the same rectangles that matrices on
3820 the frame are divided into. */
3822 int width
, height
, gx
, gy
;
3825 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
3826 last_mouse_glyph
= rect
;
3829 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
3830 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
3834 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
3835 round down even for negative values. */
3840 gx
= (gx
+ width
- 1) / width
* width
;
3841 gy
= (gy
+ height
- 1) / height
* height
;
3843 last_mouse_glyph
.width
= width
;
3844 last_mouse_glyph
.height
= height
;
3845 last_mouse_glyph
.x
= gx
;
3846 last_mouse_glyph
.y
= gy
;
3852 XSETINT (*x
, win_x
);
3853 XSETINT (*y
, win_y
);
3854 *time
= last_mouse_movement_time
;
3864 /***********************************************************************
3866 ***********************************************************************/
3868 /* Scroll bar support. */
3870 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
3872 This can be called in GC, so we have to make sure to strip off mark
3875 static struct scroll_bar
*
3876 x_window_to_scroll_bar (display
, window_id
)
3883 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
3884 #endif /* USE_GTK */
3886 for (tail
= Vframe_list
;
3887 XGCTYPE (tail
) == Lisp_Cons
;
3890 Lisp_Object frame
, bar
, condemned
;
3892 frame
= XCAR (tail
);
3893 /* All elements of Vframe_list should be frames. */
3894 if (! GC_FRAMEP (frame
))
3897 if (! FRAME_X_P (XFRAME (frame
)))
3900 /* Scan this frame's scroll bar list for a scroll bar with the
3902 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3903 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3904 /* This trick allows us to search both the ordinary and
3905 condemned scroll bar lists with one loop. */
3906 ! GC_NILP (bar
) || (bar
= condemned
,
3909 bar
= XSCROLL_BAR (bar
)->next
)
3910 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
&&
3911 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
3912 return XSCROLL_BAR (bar
);
3919 #if defined USE_LUCID
3921 /* Return the Lucid menu bar WINDOW is part of. Return null
3922 if WINDOW is not part of a menu bar. */
3925 x_window_to_menu_bar (window
)
3930 for (tail
= Vframe_list
;
3931 XGCTYPE (tail
) == Lisp_Cons
;
3934 if (FRAME_X_P (XFRAME (XCAR (tail
))))
3936 Lisp_Object frame
= XCAR (tail
);
3937 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
3939 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
3947 #endif /* USE_LUCID */
3950 /************************************************************************
3952 ************************************************************************/
3954 #ifdef USE_TOOLKIT_SCROLL_BARS
3956 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
3957 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
3958 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
3959 struct scroll_bar
*));
3960 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
3964 /* Lisp window being scrolled. Set when starting to interact with
3965 a toolkit scroll bar, reset to nil when ending the interaction. */
3967 static Lisp_Object window_being_scrolled
;
3969 /* Last scroll bar part sent in xm_scroll_callback. */
3971 static int last_scroll_bar_part
;
3973 /* Whether this is an Xaw with arrow-scrollbars. This should imply
3974 that movements of 1/20 of the screen size are mapped to up/down. */
3977 /* Id of action hook installed for scroll bars. */
3979 static XtActionHookId action_hook_id
;
3981 static Boolean xaw3d_arrow_scroll
;
3983 /* Whether the drag scrolling maintains the mouse at the top of the
3984 thumb. If not, resizing the thumb needs to be done more carefully
3985 to avoid jerkyness. */
3987 static Boolean xaw3d_pick_top
;
3989 extern void set_vertical_scroll_bar
P_ ((struct window
*));
3991 /* Action hook installed via XtAppAddActionHook when toolkit scroll
3992 bars are used.. The hook is responsible for detecting when
3993 the user ends an interaction with the scroll bar, and generates
3994 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
3997 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
4000 XtPointer client_data
;
4004 Cardinal
*num_params
;
4010 scroll_bar_p
= XmIsScrollBar (widget
);
4011 end_action
= "Release";
4012 #else /* !USE_MOTIF i.e. use Xaw */
4013 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4014 end_action
= "EndScroll";
4015 #endif /* USE_MOTIF */
4018 && strcmp (action_name
, end_action
) == 0
4019 && WINDOWP (window_being_scrolled
))
4023 x_send_scroll_bar_event (window_being_scrolled
,
4024 scroll_bar_end_scroll
, 0, 0);
4025 w
= XWINDOW (window_being_scrolled
);
4027 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4029 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4030 /* The thumb size is incorrect while dragging: fix it. */
4031 set_vertical_scroll_bar (w
);
4033 window_being_scrolled
= Qnil
;
4034 last_scroll_bar_part
= -1;
4036 /* Xt timeouts no longer needed. */
4037 toolkit_scroll_bar_interaction
= 0;
4040 #endif /* not USE_GTK */
4042 /* A vector of windows used for communication between
4043 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4045 static struct window
**scroll_bar_windows
;
4046 static int scroll_bar_windows_size
;
4049 /* Send a client message with message type Xatom_Scrollbar for a
4050 scroll action to the frame of WINDOW. PART is a value identifying
4051 the part of the scroll bar that was clicked on. PORTION is the
4052 amount to scroll of a whole of WHOLE. */
4055 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4057 int part
, portion
, whole
;
4060 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4061 struct window
*w
= XWINDOW (window
);
4062 struct frame
*f
= XFRAME (w
->frame
);
4067 /* Construct a ClientMessage event to send to the frame. */
4068 ev
->type
= ClientMessage
;
4069 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4070 ev
->display
= FRAME_X_DISPLAY (f
);
4071 ev
->window
= FRAME_X_WINDOW (f
);
4074 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4075 not enough to store a pointer or Lisp_Object on a 64 bit system.
4076 So, store the window in scroll_bar_windows and pass the index
4077 into that array in the event. */
4078 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4079 if (scroll_bar_windows
[i
] == NULL
)
4082 if (i
== scroll_bar_windows_size
)
4084 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4085 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4086 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4088 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4090 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4091 scroll_bar_windows_size
= new_size
;
4094 scroll_bar_windows
[i
] = w
;
4095 ev
->data
.l
[0] = (long) i
;
4096 ev
->data
.l
[1] = (long) part
;
4097 ev
->data
.l
[2] = (long) 0;
4098 ev
->data
.l
[3] = (long) portion
;
4099 ev
->data
.l
[4] = (long) whole
;
4101 /* Make Xt timeouts work while the scroll bar is active. */
4102 toolkit_scroll_bar_interaction
= 1;
4104 /* Setting the event mask to zero means that the message will
4105 be sent to the client that created the window, and if that
4106 window no longer exists, no event will be sent. */
4107 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4112 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4116 x_scroll_bar_to_input_event (event
, ievent
)
4118 struct input_event
*ievent
;
4120 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4125 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4126 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4128 XSETWINDOW (window
, w
);
4129 f
= XFRAME (w
->frame
);
4131 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4132 ievent
->frame_or_window
= window
;
4135 ievent
->timestamp
= CurrentTime
;
4137 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4139 ievent
->part
= ev
->data
.l
[1];
4140 ievent
->code
= ev
->data
.l
[2];
4141 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4142 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4143 ievent
->modifiers
= 0;
4149 /* Minimum and maximum values used for Motif scroll bars. */
4151 #define XM_SB_MAX 10000000
4154 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4155 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4156 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4159 xm_scroll_callback (widget
, client_data
, call_data
)
4161 XtPointer client_data
, call_data
;
4163 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4164 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4165 int part
= -1, whole
= 0, portion
= 0;
4169 case XmCR_DECREMENT
:
4170 bar
->dragging
= Qnil
;
4171 part
= scroll_bar_up_arrow
;
4174 case XmCR_INCREMENT
:
4175 bar
->dragging
= Qnil
;
4176 part
= scroll_bar_down_arrow
;
4179 case XmCR_PAGE_DECREMENT
:
4180 bar
->dragging
= Qnil
;
4181 part
= scroll_bar_above_handle
;
4184 case XmCR_PAGE_INCREMENT
:
4185 bar
->dragging
= Qnil
;
4186 part
= scroll_bar_below_handle
;
4190 bar
->dragging
= Qnil
;
4191 part
= scroll_bar_to_top
;
4194 case XmCR_TO_BOTTOM
:
4195 bar
->dragging
= Qnil
;
4196 part
= scroll_bar_to_bottom
;
4203 /* Get the slider size. */
4205 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4208 whole
= XM_SB_MAX
- slider_size
;
4209 portion
= min (cs
->value
, whole
);
4210 part
= scroll_bar_handle
;
4211 bar
->dragging
= make_number (cs
->value
);
4215 case XmCR_VALUE_CHANGED
:
4221 window_being_scrolled
= bar
->window
;
4222 last_scroll_bar_part
= part
;
4223 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4228 #else /* !USE_MOTIF, i.e. Xaw or GTK */
4230 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4231 bar widget. DATA is a pointer to the scroll_bar structure. */
4234 xg_scroll_callback (widget
, data
)
4238 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4244 int part
= -1, whole
= 0, portion
= 0;
4245 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4247 if (xg_ignore_gtk_scrollbar
) return;
4249 position
= gtk_adjustment_get_value (adj
);
4251 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4254 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4256 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4262 diff
= (int) (position
- previous
);
4264 if (diff
== (int) adj
->step_increment
)
4266 part
= scroll_bar_down_arrow
;
4267 bar
->dragging
= Qnil
;
4269 else if (-diff
== (int) adj
->step_increment
)
4271 part
= scroll_bar_up_arrow
;
4272 bar
->dragging
= Qnil
;
4274 else if (diff
== (int) adj
->page_increment
)
4276 part
= scroll_bar_below_handle
;
4277 bar
->dragging
= Qnil
;
4279 else if (-diff
== (int) adj
->page_increment
)
4281 part
= scroll_bar_above_handle
;
4282 bar
->dragging
= Qnil
;
4286 part
= scroll_bar_handle
;
4287 whole
= adj
->upper
- adj
->page_size
;
4288 portion
= min ((int)position
, whole
);
4289 bar
->dragging
= make_number ((int)portion
);
4294 window_being_scrolled
= bar
->window
;
4295 last_scroll_bar_part
= part
;
4296 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4300 #else /* not USE_GTK */
4302 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4303 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4304 scroll bar struct. CALL_DATA is a pointer to a float saying where
4308 xaw_jump_callback (widget
, client_data
, call_data
)
4310 XtPointer client_data
, call_data
;
4312 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4313 float top
= *(float *) call_data
;
4315 int whole
, portion
, height
;
4318 /* Get the size of the thumb, a value between 0 and 1. */
4320 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4324 portion
= shown
< 1 ? top
* whole
: 0;
4326 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
4327 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4328 the bottom, so we force the scrolling whenever we see that we're
4329 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4330 we try to ensure that we always stay two pixels away from the
4332 part
= scroll_bar_down_arrow
;
4334 part
= scroll_bar_handle
;
4336 window_being_scrolled
= bar
->window
;
4337 bar
->dragging
= make_number (portion
);
4338 last_scroll_bar_part
= part
;
4339 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4343 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4344 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4345 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4346 the scroll bar. CALL_DATA is an integer specifying the action that
4347 has taken place. Its magnitude is in the range 0..height of the
4348 scroll bar. Negative values mean scroll towards buffer start.
4349 Values < height of scroll bar mean line-wise movement. */
4352 xaw_scroll_callback (widget
, client_data
, call_data
)
4354 XtPointer client_data
, call_data
;
4356 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4357 /* The position really is stored cast to a pointer. */
4358 int position
= (long) call_data
;
4362 /* Get the height of the scroll bar. */
4364 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4367 if (abs (position
) >= height
)
4368 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4370 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4371 it maps line-movement to call_data = max(5, height/20). */
4372 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
4373 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4375 part
= scroll_bar_move_ratio
;
4377 window_being_scrolled
= bar
->window
;
4378 bar
->dragging
= Qnil
;
4379 last_scroll_bar_part
= part
;
4380 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4383 #endif /* not USE_GTK */
4384 #endif /* not USE_MOTIF */
4386 #define SCROLL_BAR_NAME "verticalScrollBar"
4388 /* Create the widget for scroll bar BAR on frame F. Record the widget
4389 and X window of the scroll bar in BAR. */
4393 x_create_toolkit_scroll_bar (f
, bar
)
4395 struct scroll_bar
*bar
;
4397 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4400 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4405 #else /* not USE_GTK */
4408 x_create_toolkit_scroll_bar (f
, bar
)
4410 struct scroll_bar
*bar
;
4416 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4417 unsigned long pixel
;
4422 /* Set resources. Create the widget. */
4423 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4424 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4425 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4426 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4427 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4428 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4429 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4431 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4434 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4438 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4441 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4445 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4446 scroll_bar_name
, av
, ac
);
4448 /* Add one callback for everything that can happen. */
4449 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4451 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4453 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4455 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4457 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4459 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4461 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4464 /* Realize the widget. Only after that is the X window created. */
4465 XtRealizeWidget (widget
);
4467 /* Set the cursor to an arrow. I didn't find a resource to do that.
4468 And I'm wondering why it hasn't an arrow cursor by default. */
4469 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4470 f
->output_data
.x
->nontext_cursor
);
4472 #else /* !USE_MOTIF i.e. use Xaw */
4474 /* Set resources. Create the widget. The background of the
4475 Xaw3d scroll bar widget is a little bit light for my taste.
4476 We don't alter it here to let users change it according
4477 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4478 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4479 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4480 /* For smoother scrolling with Xaw3d -sm */
4481 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4483 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4486 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4490 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4493 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4497 /* Top/bottom shadow colors. */
4499 /* Allocate them, if necessary. */
4500 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4502 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4503 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4504 &pixel
, 1.2, 0x8000))
4506 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4508 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4510 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4511 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4512 &pixel
, 0.6, 0x4000))
4514 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4517 /* Tell the toolkit about them. */
4518 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4519 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4520 /* We tried to allocate a color for the top/bottom shadow, and
4521 failed, so tell Xaw3d to use dithering instead. */
4523 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4527 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4528 be more consistent with other emacs 3d colors, and since Xaw3d is
4529 not good at dealing with allocation failure. */
4531 /* This tells Xaw3d to use real colors instead of dithering for
4533 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4536 /* Specify the colors. */
4537 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4540 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
4543 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4546 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
4551 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4552 f
->output_data
.x
->edit_widget
, av
, ac
);
4556 char *val
= initial
;
4557 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4558 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4560 { /* ARROW_SCROLL */
4561 xaw3d_arrow_scroll
= True
;
4562 /* Isn't that just a personal preference ? -sm */
4563 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4567 /* Define callbacks. */
4568 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4569 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4572 /* Realize the widget. Only after that is the X window created. */
4573 XtRealizeWidget (widget
);
4575 #endif /* !USE_MOTIF */
4577 /* Install an action hook that lets us detect when the user
4578 finishes interacting with a scroll bar. */
4579 if (action_hook_id
== 0)
4580 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4582 /* Remember X window and widget in the scroll bar vector. */
4583 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4584 xwindow
= XtWindow (widget
);
4585 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
4589 #endif /* not USE_GTK */
4592 /* Set the thumb size and position of scroll bar BAR. We are currently
4593 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4597 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4598 struct scroll_bar
*bar
;
4599 int portion
, position
, whole
;
4601 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4604 #else /* not USE_GTK */
4606 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4607 struct scroll_bar
*bar
;
4608 int portion
, position
, whole
;
4610 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4611 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4618 /* We use an estimate of 30 chars per line rather than the real
4619 `portion' value. This has the disadvantage that the thumb size
4620 is not very representative, but it makes our life a lot easier.
4621 Otherwise, we have to constantly adjust the thumb size, which
4622 we can't always do quickly enough: while dragging, the size of
4623 the thumb might prevent the user from dragging the thumb all the
4624 way to the end. but Motif and some versions of Xaw3d don't allow
4625 updating the thumb size while dragging. Also, even if we can update
4626 its size, the update will often happen too late.
4627 If you don't believe it, check out revision 1.650 of xterm.c to see
4628 what hoops we were going through and the still poor behavior we got. */
4629 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4630 /* When the thumb is at the bottom, position == whole.
4631 So we need to increase `whole' to make space for the thumb. */
4638 top
= (float) position
/ whole
;
4639 shown
= (float) portion
/ whole
;
4642 if (NILP (bar
->dragging
))
4646 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4647 is the scroll bar's maximum and MIN is the scroll bar's minimum
4649 size
= shown
* XM_SB_MAX
;
4650 size
= min (size
, XM_SB_MAX
);
4651 size
= max (size
, 1);
4653 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4654 value
= top
* XM_SB_MAX
;
4655 value
= min (value
, XM_SB_MAX
- size
);
4657 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4659 #else /* !USE_MOTIF i.e. use Xaw */
4665 top
= (float) position
/ whole
;
4666 shown
= (float) portion
/ whole
;
4670 float old_top
, old_shown
;
4672 XtVaGetValues (widget
,
4673 XtNtopOfThumb
, &old_top
,
4674 XtNshown
, &old_shown
,
4678 /* Massage the top+shown values. */
4679 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4680 top
= max (0, min (1, top
));
4683 /* Keep two pixels available for moving the thumb down. */
4684 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4686 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4687 check that your system's configuration file contains a define
4688 for `NARROWPROTO'. See s/freebsd.h for an example. */
4689 if (top
!= old_top
|| shown
!= old_shown
)
4691 if (NILP (bar
->dragging
))
4692 XawScrollbarSetThumb (widget
, top
, shown
);
4696 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
4697 int scroll_mode
= 0;
4699 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
4700 if (xaw3d_arrow_scroll
)
4702 /* Xaw3d stupidly ignores resize requests while dragging
4703 so we have to make it believe it's not in dragging mode. */
4704 scroll_mode
= sb
->scrollbar
.scroll_mode
;
4705 if (scroll_mode
== 2)
4706 sb
->scrollbar
.scroll_mode
= 0;
4709 /* Try to make the scrolling a tad smoother. */
4710 if (!xaw3d_pick_top
)
4711 shown
= min (shown
, old_shown
);
4713 XawScrollbarSetThumb (widget
, top
, shown
);
4716 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
4717 sb
->scrollbar
.scroll_mode
= scroll_mode
;
4722 #endif /* !USE_MOTIF */
4726 #endif /* not USE_GTK */
4728 #endif /* USE_TOOLKIT_SCROLL_BARS */
4732 /************************************************************************
4733 Scroll bars, general
4734 ************************************************************************/
4736 /* Create a scroll bar and return the scroll bar vector for it. W is
4737 the Emacs window on which to create the scroll bar. TOP, LEFT,
4738 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4741 static struct scroll_bar
*
4742 x_scroll_bar_create (w
, top
, left
, width
, height
)
4744 int top
, left
, width
, height
;
4746 struct frame
*f
= XFRAME (w
->frame
);
4747 struct scroll_bar
*bar
4748 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4752 #ifdef USE_TOOLKIT_SCROLL_BARS
4753 x_create_toolkit_scroll_bar (f
, bar
);
4754 #else /* not USE_TOOLKIT_SCROLL_BARS */
4756 XSetWindowAttributes a
;
4760 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4761 if (a
.background_pixel
== -1)
4762 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
4764 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4765 | ButtonMotionMask
| PointerMotionHintMask
4767 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4769 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4771 /* Clear the area of W that will serve as a scroll bar. This is
4772 for the case that a window has been split horizontally. In
4773 this case, no clear_frame is generated to reduce flickering. */
4774 if (width
> 0 && height
> 0)
4775 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4777 window_box_height (w
), False
);
4779 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4780 /* Position and size of scroll bar. */
4781 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4783 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4785 /* Border width, depth, class, and visual. */
4792 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
4794 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4796 XSETWINDOW (bar
->window
, w
);
4797 XSETINT (bar
->top
, top
);
4798 XSETINT (bar
->left
, left
);
4799 XSETINT (bar
->width
, width
);
4800 XSETINT (bar
->height
, height
);
4801 XSETINT (bar
->start
, 0);
4802 XSETINT (bar
->end
, 0);
4803 bar
->dragging
= Qnil
;
4805 /* Add bar to its frame's list of scroll bars. */
4806 bar
->next
= FRAME_SCROLL_BARS (f
);
4808 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4809 if (!NILP (bar
->next
))
4810 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4812 /* Map the window/widget. */
4813 #ifdef USE_TOOLKIT_SCROLL_BARS
4816 xg_update_scrollbar_pos (f
,
4817 SCROLL_BAR_X_WINDOW (bar
),
4819 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4820 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4824 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
4825 #else /* not USE_GTK */
4826 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4827 XtConfigureWidget (scroll_bar
,
4828 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4830 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4831 max (height
, 1), 0);
4832 XtMapWidget (scroll_bar
);
4833 #endif /* not USE_GTK */
4835 #else /* not USE_TOOLKIT_SCROLL_BARS */
4836 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4837 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4844 /* Draw BAR's handle in the proper position.
4846 If the handle is already drawn from START to END, don't bother
4847 redrawing it, unless REBUILD is non-zero; in that case, always
4848 redraw it. (REBUILD is handy for drawing the handle after expose
4851 Normally, we want to constrain the start and end of the handle to
4852 fit inside its rectangle, but if the user is dragging the scroll
4853 bar handle, we want to let them drag it down all the way, so that
4854 the bar's top is as far down as it goes; otherwise, there's no way
4855 to move to the very end of the buffer. */
4857 #ifndef USE_TOOLKIT_SCROLL_BARS
4860 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4861 struct scroll_bar
*bar
;
4865 int dragging
= ! NILP (bar
->dragging
);
4866 Window w
= SCROLL_BAR_X_WINDOW (bar
);
4867 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4868 GC gc
= f
->output_data
.x
->normal_gc
;
4870 /* If the display is already accurate, do nothing. */
4872 && start
== XINT (bar
->start
)
4873 && end
== XINT (bar
->end
))
4879 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
4880 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
4881 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4883 /* Make sure the values are reasonable, and try to preserve
4884 the distance between start and end. */
4886 int length
= end
- start
;
4890 else if (start
> top_range
)
4892 end
= start
+ length
;
4896 else if (end
> top_range
&& ! dragging
)
4900 /* Store the adjusted setting in the scroll bar. */
4901 XSETINT (bar
->start
, start
);
4902 XSETINT (bar
->end
, end
);
4904 /* Clip the end position, just for display. */
4905 if (end
> top_range
)
4908 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
4909 below top positions, to make sure the handle is always at least
4910 that many pixels tall. */
4911 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4913 /* Draw the empty space above the handle. Note that we can't clear
4914 zero-height areas; that means "clear to end of window." */
4916 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4917 /* x, y, width, height, and exposures. */
4918 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4919 VERTICAL_SCROLL_BAR_TOP_BORDER
,
4920 inside_width
, start
,
4923 /* Change to proper foreground color if one is specified. */
4924 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4925 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4926 f
->output_data
.x
->scroll_bar_foreground_pixel
);
4928 /* Draw the handle itself. */
4929 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
4930 /* x, y, width, height */
4931 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4932 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
4933 inside_width
, end
- start
);
4935 /* Restore the foreground color of the GC if we changed it above. */
4936 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4937 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4938 f
->output_data
.x
->foreground_pixel
);
4940 /* Draw the empty space below the handle. Note that we can't
4941 clear zero-height areas; that means "clear to end of window." */
4942 if (end
< inside_height
)
4943 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4944 /* x, y, width, height, and exposures. */
4945 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4946 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
4947 inside_width
, inside_height
- end
,
4955 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4957 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4961 x_scroll_bar_remove (bar
)
4962 struct scroll_bar
*bar
;
4964 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4967 #ifdef USE_TOOLKIT_SCROLL_BARS
4969 xg_remove_scroll_bar (f
, SCROLL_BAR_X_WINDOW (bar
));
4970 #else /* not USE_GTK */
4971 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
4972 #endif /* not USE_GTK */
4974 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4977 /* Disassociate this scroll bar from its window. */
4978 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4984 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4985 that we are displaying PORTION characters out of a total of WHOLE
4986 characters, starting at POSITION. If WINDOW has no scroll bar,
4990 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4992 int portion
, whole
, position
;
4994 struct frame
*f
= XFRAME (w
->frame
);
4995 struct scroll_bar
*bar
;
4996 int top
, height
, left
, sb_left
, width
, sb_width
;
4997 int window_y
, window_height
;
4999 /* Get window dimensions. */
5000 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
5002 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5003 height
= window_height
;
5005 /* Compute the left edge of the scroll bar area. */
5006 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5008 /* Compute the width of the scroll bar which might be less than
5009 the width of the area reserved for the scroll bar. */
5010 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5011 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5015 /* Compute the left edge of the scroll bar. */
5016 #ifdef USE_TOOLKIT_SCROLL_BARS
5017 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5018 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
5020 sb_left
= left
+ (width
- sb_width
) / 2;
5022 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5023 sb_left
= left
+ width
- sb_width
;
5028 /* Does the scroll bar exist yet? */
5029 if (NILP (w
->vertical_scroll_bar
))
5031 if (width
> 0 && height
> 0)
5034 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5035 left
, top
, width
, height
, False
);
5039 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5043 /* It may just need to be moved and resized. */
5044 unsigned int mask
= 0;
5046 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5050 if (sb_left
!= XINT (bar
->left
))
5052 if (top
!= XINT (bar
->top
))
5054 if (sb_width
!= XINT (bar
->width
))
5056 if (height
!= XINT (bar
->height
))
5059 #ifdef USE_TOOLKIT_SCROLL_BARS
5063 xg_update_scrollbar_pos (f
,
5064 SCROLL_BAR_X_WINDOW (bar
),
5066 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5067 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5071 #else /* not USE_GTK */
5073 /* Since toolkit scroll bars are smaller than the space reserved
5074 for them on the frame, we have to clear "under" them. */
5075 if (width
> 0 && height
> 0)
5076 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5077 left
, top
, width
, height
, False
);
5078 /* Move/size the scroll bar widget. */
5080 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5081 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5083 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5084 max (height
, 1), 0);
5086 #endif /* not USE_GTK */
5087 #else /* not USE_TOOLKIT_SCROLL_BARS */
5089 /* Clear areas not covered by the scroll bar because of
5090 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5091 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5093 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5094 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5096 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5097 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5098 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5102 /* Clear areas not covered by the scroll bar because it's not as
5103 wide as the area reserved for it. This makes sure a
5104 previous mode line display is cleared after C-x 2 C-x 1, for
5107 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5108 int rest
= area_width
- sb_width
;
5109 if (rest
> 0 && height
> 0)
5111 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5112 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5113 left
+ area_width
- rest
, top
,
5114 rest
, height
, False
);
5116 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5117 left
, top
, rest
, height
, False
);
5121 /* Move/size the scroll bar window. */
5126 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5128 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5130 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
5134 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5136 /* Remember new settings. */
5137 XSETINT (bar
->left
, sb_left
);
5138 XSETINT (bar
->top
, top
);
5139 XSETINT (bar
->width
, sb_width
);
5140 XSETINT (bar
->height
, height
);
5145 #ifdef USE_TOOLKIT_SCROLL_BARS
5146 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5147 #else /* not USE_TOOLKIT_SCROLL_BARS */
5148 /* Set the scroll bar's current state, unless we're currently being
5150 if (NILP (bar
->dragging
))
5152 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5155 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5158 int start
= ((double) position
* top_range
) / whole
;
5159 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5160 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5163 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5165 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5169 /* The following three hooks are used when we're doing a thorough
5170 redisplay of the frame. We don't explicitly know which scroll bars
5171 are going to be deleted, because keeping track of when windows go
5172 away is a real pain - "Can you say set-window-configuration, boys
5173 and girls?" Instead, we just assert at the beginning of redisplay
5174 that *all* scroll bars are to be removed, and then save a scroll bar
5175 from the fiery pit when we actually redisplay its window. */
5177 /* Arrange for all scroll bars on FRAME to be removed at the next call
5178 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5179 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5182 XTcondemn_scroll_bars (frame
)
5185 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5186 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5189 bar
= FRAME_SCROLL_BARS (frame
);
5190 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5191 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5192 XSCROLL_BAR (bar
)->prev
= Qnil
;
5193 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5194 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5195 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5200 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5201 Note that WINDOW isn't necessarily condemned at all. */
5204 XTredeem_scroll_bar (window
)
5205 struct window
*window
;
5207 struct scroll_bar
*bar
;
5210 /* We can't redeem this window's scroll bar if it doesn't have one. */
5211 if (NILP (window
->vertical_scroll_bar
))
5214 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5216 /* Unlink it from the condemned list. */
5217 f
= XFRAME (WINDOW_FRAME (window
));
5218 if (NILP (bar
->prev
))
5220 /* If the prev pointer is nil, it must be the first in one of
5222 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5223 /* It's not condemned. Everything's fine. */
5225 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5226 window
->vertical_scroll_bar
))
5227 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5229 /* If its prev pointer is nil, it must be at the front of
5230 one or the other! */
5234 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5236 if (! NILP (bar
->next
))
5237 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5239 bar
->next
= FRAME_SCROLL_BARS (f
);
5241 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5242 if (! NILP (bar
->next
))
5243 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5246 /* Remove all scroll bars on FRAME that haven't been saved since the
5247 last call to `*condemn_scroll_bars_hook'. */
5250 XTjudge_scroll_bars (f
)
5253 Lisp_Object bar
, next
;
5255 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5257 /* Clear out the condemned list now so we won't try to process any
5258 more events on the hapless scroll bars. */
5259 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5261 for (; ! NILP (bar
); bar
= next
)
5263 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5265 x_scroll_bar_remove (b
);
5268 b
->next
= b
->prev
= Qnil
;
5271 /* Now there should be no references to the condemned scroll bars,
5272 and they should get garbage-collected. */
5276 #ifndef USE_TOOLKIT_SCROLL_BARS
5277 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5278 is a no-op when using toolkit scroll bars.
5280 This may be called from a signal handler, so we have to ignore GC
5284 x_scroll_bar_expose (bar
, event
)
5285 struct scroll_bar
*bar
;
5288 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5289 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5290 GC gc
= f
->output_data
.x
->normal_gc
;
5291 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5295 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
5297 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5298 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5300 /* x, y, width, height */
5302 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
5303 XINT (bar
->height
) - 1);
5308 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5310 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5311 is set to something other than NO_EVENT, it is enqueued.
5313 This may be called from a signal handler, so we have to ignore GC
5318 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5319 struct scroll_bar
*bar
;
5321 struct input_event
*emacs_event
;
5323 if (! GC_WINDOWP (bar
->window
))
5326 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5327 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5328 emacs_event
->modifiers
5329 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5330 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5331 event
->xbutton
.state
)
5332 | (event
->type
== ButtonRelease
5335 emacs_event
->frame_or_window
= bar
->window
;
5336 emacs_event
->arg
= Qnil
;
5337 emacs_event
->timestamp
= event
->xbutton
.time
;
5340 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5342 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5345 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5346 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5349 if (y
> top_range
) y
= top_range
;
5351 if (y
< XINT (bar
->start
))
5352 emacs_event
->part
= scroll_bar_above_handle
;
5353 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5354 emacs_event
->part
= scroll_bar_handle
;
5356 emacs_event
->part
= scroll_bar_below_handle
;
5358 /* Just because the user has clicked on the handle doesn't mean
5359 they want to drag it. Lisp code needs to be able to decide
5360 whether or not we're dragging. */
5362 /* If the user has just clicked on the handle, record where they're
5364 if (event
->type
== ButtonPress
5365 && emacs_event
->part
== scroll_bar_handle
)
5366 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
5369 #ifndef USE_TOOLKIT_SCROLL_BARS
5370 /* If the user has released the handle, set it to its final position. */
5371 if (event
->type
== ButtonRelease
5372 && ! NILP (bar
->dragging
))
5374 int new_start
= y
- XINT (bar
->dragging
);
5375 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5377 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5378 bar
->dragging
= Qnil
;
5382 /* Same deal here as the other #if 0. */
5384 /* Clicks on the handle are always reported as occurring at the top of
5386 if (emacs_event
->part
== scroll_bar_handle
)
5387 emacs_event
->x
= bar
->start
;
5389 XSETINT (emacs_event
->x
, y
);
5391 XSETINT (emacs_event
->x
, y
);
5394 XSETINT (emacs_event
->y
, top_range
);
5398 #ifndef USE_TOOLKIT_SCROLL_BARS
5400 /* Handle some mouse motion while someone is dragging the scroll bar.
5402 This may be called from a signal handler, so we have to ignore GC
5406 x_scroll_bar_note_movement (bar
, event
)
5407 struct scroll_bar
*bar
;
5410 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5412 last_mouse_movement_time
= event
->xmotion
.time
;
5415 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5417 /* If we're dragging the bar, display it. */
5418 if (! GC_NILP (bar
->dragging
))
5420 /* Where should the handle be now? */
5421 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5423 if (new_start
!= XINT (bar
->start
))
5425 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
5427 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5432 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5434 /* Return information to the user about the current position of the mouse
5435 on the scroll bar. */
5438 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5440 Lisp_Object
*bar_window
;
5441 enum scroll_bar_part
*part
;
5443 unsigned long *time
;
5445 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5446 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5447 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5449 Window dummy_window
;
5451 unsigned int dummy_mask
;
5455 /* Get the mouse's position relative to the scroll bar window, and
5457 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5459 /* Root, child, root x and root y. */
5460 &dummy_window
, &dummy_window
,
5461 &dummy_coord
, &dummy_coord
,
5463 /* Position relative to scroll bar. */
5466 /* Mouse buttons and modifier keys. */
5473 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5476 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5478 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5480 if (! NILP (bar
->dragging
))
5481 win_y
-= XINT (bar
->dragging
);
5485 if (win_y
> top_range
)
5489 *bar_window
= bar
->window
;
5491 if (! NILP (bar
->dragging
))
5492 *part
= scroll_bar_handle
;
5493 else if (win_y
< XINT (bar
->start
))
5494 *part
= scroll_bar_above_handle
;
5495 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5496 *part
= scroll_bar_handle
;
5498 *part
= scroll_bar_below_handle
;
5500 XSETINT (*x
, win_y
);
5501 XSETINT (*y
, top_range
);
5504 last_mouse_scroll_bar
= Qnil
;
5507 *time
= last_mouse_movement_time
;
5513 /* The screen has been cleared so we may have changed foreground or
5514 background colors, and the scroll bars may need to be redrawn.
5515 Clear out the scroll bars, and ask for expose events, so we can
5519 x_scroll_bar_clear (f
)
5522 #ifndef USE_TOOLKIT_SCROLL_BARS
5525 /* We can have scroll bars even if this is 0,
5526 if we just turned off scroll bar mode.
5527 But in that case we should not clear them. */
5528 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5529 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5530 bar
= XSCROLL_BAR (bar
)->next
)
5531 XClearArea (FRAME_X_DISPLAY (f
),
5532 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
5534 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5538 /* Define a queue to save up SelectionRequest events for later handling. */
5540 struct selection_event_queue
5543 struct selection_event_queue
*next
;
5546 static struct selection_event_queue
*queue
;
5548 /* Nonzero means queue up certain events--don't process them yet. */
5550 static int x_queue_selection_requests
;
5552 /* Queue up an X event *EVENT, to be processed later. */
5555 x_queue_event (f
, event
)
5559 struct selection_event_queue
*queue_tmp
5560 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
5562 if (queue_tmp
!= NULL
)
5564 queue_tmp
->event
= *event
;
5565 queue_tmp
->next
= queue
;
5570 /* Take all the queued events and put them back
5571 so that they get processed afresh. */
5574 x_unqueue_events (display
)
5577 while (queue
!= NULL
)
5579 struct selection_event_queue
*queue_tmp
= queue
;
5580 XPutBackEvent (display
, &queue_tmp
->event
);
5581 queue
= queue_tmp
->next
;
5582 xfree ((char *)queue_tmp
);
5586 /* Start queuing SelectionRequest events. */
5589 x_start_queuing_selection_requests (display
)
5592 x_queue_selection_requests
++;
5595 /* Stop queuing SelectionRequest events. */
5598 x_stop_queuing_selection_requests (display
)
5601 x_queue_selection_requests
--;
5602 x_unqueue_events (display
);
5605 /* The main X event-reading loop - XTread_socket. */
5608 /* Time stamp of enter window event. This is only used by XTread_socket,
5609 but we have to put it out here, since static variables within functions
5610 sometimes don't work. */
5612 static Time enter_timestamp
;
5615 /* This holds the state XLookupString needs to implement dead keys
5616 and other tricks known as "compose processing". _X Window System_
5617 says that a portable program can't use this, but Stephen Gildea assures
5618 me that letting the compiler initialize it to zeros will work okay.
5620 This must be defined outside of XTread_socket, for the same reasons
5621 given for enter_timestamp, above. */
5623 static XComposeStatus compose_status
;
5625 /* Record the last 100 characters stored
5626 to help debug the loss-of-chars-during-GC problem. */
5628 static int temp_index
;
5629 static short temp_buffer
[100];
5631 /* Set this to nonzero to fake an "X I/O error"
5632 on a particular display. */
5634 struct x_display_info
*XTread_socket_fake_io_error
;
5636 /* When we find no input here, we occasionally do a no-op command
5637 to verify that the X server is still running and we can still talk with it.
5638 We try all the open displays, one by one.
5639 This variable is used for cycling thru the displays. */
5641 static struct x_display_info
*next_noop_dpyinfo
;
5643 #define SET_SAVED_MENU_EVENT(size) \
5646 if (f->output_data.x->saved_menu_event == 0) \
5647 f->output_data.x->saved_menu_event \
5648 = (XEvent *) xmalloc (sizeof (XEvent)); \
5649 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5650 if (numchars >= 1) \
5652 bufp->kind = MENU_BAR_ACTIVATE_EVENT; \
5653 XSETFRAME (bufp->frame_or_window, f); \
5662 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5663 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5673 /* Filter events for the current X input method.
5674 DPYINFO is the display this event is for.
5675 EVENT is the X event to filter.
5677 Returns non-zero if the event was filtered, caller shall not process
5679 Returns zero if event is wasn't filtered. */
5683 x_filter_event (dpyinfo
, event
)
5684 struct x_display_info
*dpyinfo
;
5687 /* XFilterEvent returns non-zero if the input method has
5688 consumed the event. We pass the frame's X window to
5689 XFilterEvent because that's the one for which the IC
5692 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5693 event
->xclient
.window
);
5695 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5700 static struct input_event
**current_bufp
;
5701 static int *current_numcharsp
;
5702 static int current_count
;
5703 static int current_finish
;
5705 /* This is the filter function invoked by the GTK event loop.
5706 It is invoked before the XEvent is translated to a GdkEvent,
5707 so we have a chanse to act on the event before GTK. */
5708 static GdkFilterReturn
5709 event_handler_gdk (gxev
, ev
, data
)
5714 XEvent
*xev
= (XEvent
*) gxev
;
5716 if (current_numcharsp
)
5718 struct x_display_info
*dpyinfo
;
5720 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5723 /* Filter events for the current X input method.
5724 GTK calls XFilterEvent but not for key press and release,
5725 so we do it here. */
5726 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5727 if (dpyinfo
&& x_filter_event (dpyinfo
, xev
))
5728 return GDK_FILTER_REMOVE
;
5732 current_finish
= X_EVENT_NORMAL
;
5734 current_count
+= handle_one_xevent (dpyinfo
,
5741 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5743 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5744 return GDK_FILTER_REMOVE
;
5746 return GDK_FILTER_CONTINUE
;
5748 #endif /* USE_GTK */
5751 /* Handles the XEvent EVENT on display DPYINFO.
5753 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5754 *FINISH is zero if caller should continue reading events.
5755 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5757 Events representing keys are stored in buffer *BUFP_R,
5758 which can hold up to *NUMCHARSP characters.
5759 We return the number of characters stored into the buffer. */
5762 handle_one_xevent (dpyinfo
, eventp
, bufp_r
, numcharsp
, finish
)
5763 struct x_display_info
*dpyinfo
;
5765 /* register */ struct input_event
**bufp_r
;
5766 /* register */ int *numcharsp
;
5772 struct coding_system coding
;
5773 struct input_event
*bufp
= *bufp_r
;
5774 int numchars
= *numcharsp
;
5775 XEvent event
= *eventp
;
5777 *finish
= X_EVENT_NORMAL
;
5783 if (event
.xclient
.message_type
5784 == dpyinfo
->Xatom_wm_protocols
5785 && event
.xclient
.format
== 32)
5787 if (event
.xclient
.data
.l
[0]
5788 == dpyinfo
->Xatom_wm_take_focus
)
5790 /* Use x_any_window_to_frame because this
5791 could be the shell widget window
5792 if the frame has no title bar. */
5793 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5795 /* Not quite sure this is needed -pd */
5796 if (f
&& FRAME_XIC (f
))
5797 XSetICFocus (FRAME_XIC (f
));
5799 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5800 instructs the WM to set the input focus automatically for
5801 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5802 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5803 it has set the focus. So, XSetInputFocus below is not
5806 The call to XSetInputFocus below has also caused trouble. In
5807 cases where the XSetInputFocus done by the WM and the one
5808 below are temporally close (on a fast machine), the call
5809 below can generate additional FocusIn events which confuse
5812 /* Since we set WM_TAKE_FOCUS, we must call
5813 XSetInputFocus explicitly. But not if f is null,
5814 since that might be an event for a deleted frame. */
5817 Display
*d
= event
.xclient
.display
;
5818 /* Catch and ignore errors, in case window has been
5819 iconified by a window manager such as GWM. */
5820 int count
= x_catch_errors (d
);
5821 XSetInputFocus (d
, event
.xclient
.window
,
5822 /* The ICCCM says this is
5823 the only valid choice. */
5825 event
.xclient
.data
.l
[1]);
5826 /* This is needed to detect the error
5827 if there is an error. */
5829 x_uncatch_errors (d
, count
);
5831 /* Not certain about handling scroll bars here */
5834 else if (event
.xclient
.data
.l
[0]
5835 == dpyinfo
->Xatom_wm_save_yourself
)
5837 /* Save state modify the WM_COMMAND property to
5838 something which can reinstate us. This notifies
5839 the session manager, who's looking for such a
5840 PropertyNotify. Can restart processing when
5841 a keyboard or mouse event arrives. */
5842 /* If we have a session manager, don't set this.
5843 KDE will then start two Emacsen, one for the
5844 session manager and one for this. */
5847 && ! x_session_have_connection ()
5851 f
= x_top_window_to_frame (dpyinfo
,
5852 event
.xclient
.window
);
5853 /* This is just so we only give real data once
5854 for a single Emacs process. */
5855 if (f
== SELECTED_FRAME ())
5856 XSetCommand (FRAME_X_DISPLAY (f
),
5857 event
.xclient
.window
,
5858 initial_argv
, initial_argc
);
5860 XSetCommand (FRAME_X_DISPLAY (f
),
5861 event
.xclient
.window
,
5865 else if (event
.xclient
.data
.l
[0]
5866 == dpyinfo
->Xatom_wm_delete_window
)
5869 = x_any_window_to_frame (dpyinfo
,
5870 event
.xclient
.window
);
5877 bufp
->kind
= DELETE_WINDOW_EVENT
;
5878 XSETFRAME (bufp
->frame_or_window
, f
);
5886 goto OTHER
; /* May be a dialog that is to be removed */
5889 else if (event
.xclient
.message_type
5890 == dpyinfo
->Xatom_wm_configure_denied
)
5893 else if (event
.xclient
.message_type
5894 == dpyinfo
->Xatom_wm_window_moved
)
5898 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5900 new_x
= event
.xclient
.data
.s
[0];
5901 new_y
= event
.xclient
.data
.s
[1];
5905 f
->left_pos
= new_x
;
5910 else if (event
.xclient
.message_type
5911 == dpyinfo
->Xatom_editres
)
5914 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5915 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5918 #endif /* HACK_EDITRES */
5919 else if ((event
.xclient
.message_type
5920 == dpyinfo
->Xatom_DONE
)
5921 || (event
.xclient
.message_type
5922 == dpyinfo
->Xatom_PAGE
))
5924 /* Ghostview job completed. Kill it. We could
5925 reply with "Next" if we received "Page", but we
5926 currently never do because we are interested in
5927 images, only, which should have 1 page. */
5928 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5930 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5931 x_kill_gs_process (pixmap
, f
);
5932 expose_frame (f
, 0, 0, 0, 0);
5934 #ifdef USE_TOOLKIT_SCROLL_BARS
5935 /* Scroll bar callbacks send a ClientMessage from which
5936 we construct an input_event. */
5937 else if (event
.xclient
.message_type
5938 == dpyinfo
->Xatom_Scrollbar
)
5940 x_scroll_bar_to_input_event (&event
, bufp
);
5941 ++bufp
, ++count
, --numchars
;
5944 #endif /* USE_TOOLKIT_SCROLL_BARS */
5950 case SelectionNotify
:
5951 #ifdef USE_X_TOOLKIT
5952 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5954 #endif /* not USE_X_TOOLKIT */
5955 x_handle_selection_notify (&event
.xselection
);
5958 case SelectionClear
: /* Someone has grabbed ownership. */
5959 #ifdef USE_X_TOOLKIT
5960 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5962 #endif /* USE_X_TOOLKIT */
5964 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
5969 bufp
->kind
= SELECTION_CLEAR_EVENT
;
5970 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
5971 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
5972 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
5973 bufp
->frame_or_window
= Qnil
;
5982 case SelectionRequest
: /* Someone wants our selection. */
5983 #ifdef USE_X_TOOLKIT
5984 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
5986 #endif /* USE_X_TOOLKIT */
5987 if (x_queue_selection_requests
)
5988 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
5992 XSelectionRequestEvent
*eventp
5993 = (XSelectionRequestEvent
*) &event
;
5998 bufp
->kind
= SELECTION_REQUEST_EVENT
;
5999 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
6000 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
6001 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
6002 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
6003 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
6004 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
6005 bufp
->frame_or_window
= Qnil
;
6014 case PropertyNotify
:
6015 #if 0 /* This is plain wrong. In the case that we are waiting for a
6016 PropertyNotify used as an ACK in incremental selection
6017 transfer, the property will be on the receiver's window. */
6018 #if defined USE_X_TOOLKIT
6019 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
6023 x_handle_property_notify (&event
.xproperty
);
6026 case ReparentNotify
:
6027 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6031 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6032 x_real_positions (f
, &x
, &y
);
6036 /* Perhaps reparented due to a WM restart. Reset this. */
6037 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6043 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6046 x_check_fullscreen (f
);
6048 if (f
->async_visible
== 0)
6050 f
->async_visible
= 1;
6051 f
->async_iconified
= 0;
6052 f
->output_data
.x
->has_been_visible
= 1;
6053 SET_FRAME_GARBAGED (f
);
6057 event
.xexpose
.x
, event
.xexpose
.y
,
6058 event
.xexpose
.width
, event
.xexpose
.height
);
6062 #ifndef USE_TOOLKIT_SCROLL_BARS
6063 struct scroll_bar
*bar
;
6065 #if defined USE_LUCID
6066 /* Submenus of the Lucid menu bar aren't widgets
6067 themselves, so there's no way to dispatch events
6068 to them. Recognize this case separately. */
6071 = x_window_to_menu_bar (event
.xexpose
.window
);
6073 xlwmenu_redisplay (widget
);
6075 #endif /* USE_LUCID */
6077 #ifdef USE_TOOLKIT_SCROLL_BARS
6078 /* Dispatch event to the widget. */
6080 #else /* not USE_TOOLKIT_SCROLL_BARS */
6081 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6082 event
.xexpose
.window
);
6085 x_scroll_bar_expose (bar
, &event
);
6086 #ifdef USE_X_TOOLKIT
6089 #endif /* USE_X_TOOLKIT */
6090 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6094 case GraphicsExpose
: /* This occurs when an XCopyArea's
6095 source area was obscured or not
6097 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6101 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6102 event
.xgraphicsexpose
.width
,
6103 event
.xgraphicsexpose
.height
);
6105 #ifdef USE_X_TOOLKIT
6108 #endif /* USE_X_TOOLKIT */
6111 case NoExpose
: /* This occurs when an XCopyArea's
6112 source area was completely
6117 /* Redo the mouse-highlight after the tooltip has gone. */
6118 if (event
.xmap
.window
== tip_window
)
6121 redo_mouse_highlight ();
6124 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6125 if (f
) /* F may no longer exist if
6126 the frame was deleted. */
6128 /* While a frame is unmapped, display generation is
6129 disabled; you don't want to spend time updating a
6130 display that won't ever be seen. */
6131 f
->async_visible
= 0;
6132 /* We can't distinguish, from the event, whether the window
6133 has become iconified or invisible. So assume, if it
6134 was previously visible, than now it is iconified.
6135 But x_make_frame_invisible clears both
6136 the visible flag and the iconified flag;
6137 and that way, we know the window is not iconified now. */
6138 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6140 f
->async_iconified
= 1;
6142 bufp
->kind
= ICONIFY_EVENT
;
6143 XSETFRAME (bufp
->frame_or_window
, f
);
6153 if (event
.xmap
.window
== tip_window
)
6154 /* The tooltip has been drawn already. Avoid
6155 the SET_FRAME_GARBAGED below. */
6158 /* We use x_top_window_to_frame because map events can
6159 come for sub-windows and they don't mean that the
6160 frame is visible. */
6161 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6164 /* wait_reading_process_input will notice this and update
6165 the frame's display structures.
6166 If we where iconified, we should not set garbaged,
6167 because that stops redrawing on Expose events. This looks
6168 bad if we are called from a recursive event loop
6169 (x_dispatch_event), for example when a dialog is up. */
6170 if (! f
->async_iconified
)
6171 SET_FRAME_GARBAGED (f
);
6173 f
->async_visible
= 1;
6174 f
->async_iconified
= 0;
6175 f
->output_data
.x
->has_been_visible
= 1;
6179 bufp
->kind
= DEICONIFY_EVENT
;
6180 XSETFRAME (bufp
->frame_or_window
, f
);
6186 else if (! NILP (Vframe_list
)
6187 && ! NILP (XCDR (Vframe_list
)))
6188 /* Force a redisplay sooner or later
6189 to update the frame titles
6190 in case this is the second frame. */
6191 record_asynch_buffer_change ();
6197 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6198 /* Dispatch KeyPress events when in menu. */
6199 if (popup_activated ())
6203 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6205 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
6207 dpyinfo
->mouse_face_hidden
= 1;
6208 clear_mouse_face (dpyinfo
);
6211 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6214 /* Scroll bars consume key events, but we want
6215 the keys to go to the scroll bar's frame. */
6216 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6218 if (widget
&& XmIsScrollBar (widget
))
6220 widget
= XtParent (widget
);
6221 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6224 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6228 KeySym keysym
, orig_keysym
;
6229 /* al%imercury@uunet.uu.net says that making this 81
6230 instead of 80 fixed a bug whereby meta chars made
6233 It seems that some version of XmbLookupString has
6234 a bug of not returning XBufferOverflow in
6235 status_return even if the input is too long to
6236 fit in 81 bytes. So, we must prepare sufficient
6237 bytes for copy_buffer. 513 bytes (256 chars for
6238 two-byte character set) seems to be a fairly good
6239 approximation. -- 2000.8.10 handa@etl.go.jp */
6240 unsigned char copy_buffer
[513];
6241 unsigned char *copy_bufptr
= copy_buffer
;
6242 int copy_bufsiz
= sizeof (copy_buffer
);
6244 Lisp_Object coding_system
= Qlatin_1
;
6247 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6248 extra_keyboard_modifiers
);
6249 modifiers
= event
.xkey
.state
;
6251 /* This will have to go some day... */
6253 /* make_lispy_event turns chars into control chars.
6254 Don't do it here because XLookupString is too eager. */
6255 event
.xkey
.state
&= ~ControlMask
;
6256 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6257 | dpyinfo
->super_mod_mask
6258 | dpyinfo
->hyper_mod_mask
6259 | dpyinfo
->alt_mod_mask
);
6261 /* In case Meta is ComposeCharacter,
6262 clear its status. According to Markus Ehrnsperger
6263 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6264 this enables ComposeCharacter to work whether or
6265 not it is combined with Meta. */
6266 if (modifiers
& dpyinfo
->meta_mod_mask
)
6267 bzero (&compose_status
, sizeof (compose_status
));
6272 Status status_return
;
6274 coding_system
= Vlocale_coding_system
;
6275 nbytes
= XmbLookupString (FRAME_XIC (f
),
6276 &event
.xkey
, copy_bufptr
,
6277 copy_bufsiz
, &keysym
,
6279 if (status_return
== XBufferOverflow
)
6281 copy_bufsiz
= nbytes
+ 1;
6282 copy_bufptr
= (char *) alloca (copy_bufsiz
);
6283 nbytes
= XmbLookupString (FRAME_XIC (f
),
6284 &event
.xkey
, copy_bufptr
,
6285 copy_bufsiz
, &keysym
,
6288 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6289 #if 0 && defined X_HAVE_UTF8_STRING
6290 else if (status_return
== XLookupKeySym
)
6291 { /* Try again but with utf-8. */
6292 coding_system
= Qutf_8
;
6293 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6294 &event
.xkey
, copy_bufptr
,
6295 copy_bufsiz
, &keysym
,
6297 if (status_return
== XBufferOverflow
)
6299 copy_bufsiz
= nbytes
+ 1;
6300 copy_bufptr
= (char *) alloca (copy_bufsiz
);
6301 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6304 copy_bufsiz
, &keysym
,
6310 if (status_return
== XLookupNone
)
6312 else if (status_return
== XLookupChars
)
6317 else if (status_return
!= XLookupKeySym
6318 && status_return
!= XLookupBoth
)
6322 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6323 copy_bufsiz
, &keysym
,
6326 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6327 copy_bufsiz
, &keysym
,
6331 /* If not using XIM/XIC, and a compose sequence is in progress,
6332 we break here. Otherwise, chars_matched is always 0. */
6333 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6336 orig_keysym
= keysym
;
6342 /* First deal with keysyms which have defined
6343 translations to characters. */
6344 if (keysym
>= 32 && keysym
< 128)
6345 /* Avoid explicitly decoding each ASCII character. */
6347 bufp
->kind
= ASCII_KEYSTROKE_EVENT
;
6348 bufp
->code
= keysym
;
6349 XSETFRAME (bufp
->frame_or_window
, f
);
6352 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6354 bufp
->timestamp
= event
.xkey
.time
;
6359 /* Now non-ASCII. */
6360 else if (HASH_TABLE_P (Vx_keysym_table
)
6361 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6365 bufp
->kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6366 ? ASCII_KEYSTROKE_EVENT
6367 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6368 bufp
->code
= XFASTINT (c
);
6369 XSETFRAME (bufp
->frame_or_window
, f
);
6372 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6374 bufp
->timestamp
= event
.xkey
.time
;
6379 /* Random non-modifier sorts of keysyms. */
6380 else if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6381 || keysym
== XK_Delete
6382 #ifdef XK_ISO_Left_Tab
6383 || (keysym
>= XK_ISO_Left_Tab
6384 && keysym
<= XK_ISO_Enter
)
6386 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6387 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6389 /* This recognizes the "extended function
6390 keys". It seems there's no cleaner way.
6391 Test IsModifierKey to avoid handling
6392 mode_switch incorrectly. */
6393 || ((unsigned) (keysym
) >= XK_Select
6394 && (unsigned)(keysym
) < XK_KP_Space
)
6396 #ifdef XK_dead_circumflex
6397 || orig_keysym
== XK_dead_circumflex
6399 #ifdef XK_dead_grave
6400 || orig_keysym
== XK_dead_grave
6402 #ifdef XK_dead_tilde
6403 || orig_keysym
== XK_dead_tilde
6405 #ifdef XK_dead_diaeresis
6406 || orig_keysym
== XK_dead_diaeresis
6408 #ifdef XK_dead_macron
6409 || orig_keysym
== XK_dead_macron
6411 #ifdef XK_dead_degree
6412 || orig_keysym
== XK_dead_degree
6414 #ifdef XK_dead_acute
6415 || orig_keysym
== XK_dead_acute
6417 #ifdef XK_dead_cedilla
6418 || orig_keysym
== XK_dead_cedilla
6420 #ifdef XK_dead_breve
6421 || orig_keysym
== XK_dead_breve
6423 #ifdef XK_dead_ogonek
6424 || orig_keysym
== XK_dead_ogonek
6426 #ifdef XK_dead_caron
6427 || orig_keysym
== XK_dead_caron
6429 #ifdef XK_dead_doubleacute
6430 || orig_keysym
== XK_dead_doubleacute
6432 #ifdef XK_dead_abovedot
6433 || orig_keysym
== XK_dead_abovedot
6435 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6436 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6437 /* Any "vendor-specific" key is ok. */
6438 || (orig_keysym
& (1 << 28))
6439 || (keysym
!= NoSymbol
&& nbytes
== 0))
6440 && ! (IsModifierKey (orig_keysym
)
6442 #ifdef XK_Mode_switch
6443 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
6446 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
6448 #endif /* not HAVE_X11R5 */
6449 /* The symbols from XK_ISO_Lock
6450 to XK_ISO_Last_Group_Lock
6451 don't have real modifiers but
6452 should be treated similarly to
6453 Mode_switch by Emacs. */
6454 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6455 || ((unsigned)(orig_keysym
)
6457 && (unsigned)(orig_keysym
)
6458 <= XK_ISO_Last_Group_Lock
)
6462 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
6464 temp_buffer
[temp_index
++] = keysym
;
6465 /* make_lispy_event will convert this to a symbolic
6467 bufp
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
6468 bufp
->code
= keysym
;
6469 XSETFRAME (bufp
->frame_or_window
, f
);
6472 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6474 bufp
->timestamp
= event
.xkey
.time
;
6479 else if (numchars
> nbytes
)
6480 { /* Raw bytes, not keysym. */
6485 /* The input should be decoded with `coding_system'
6486 which depends on which X*LookupString function
6487 we used just above and the locale. */
6488 setup_coding_system (coding_system
, &coding
);
6489 coding
.src_multibyte
= 0;
6490 coding
.dst_multibyte
= 1;
6491 /* The input is converted to events, thus we can't
6492 handle composition. Anyway, there's no XIM that
6493 gives us composition information. */
6494 coding
.composing
= COMPOSITION_DISABLED
;
6496 for (i
= 0; i
< nbytes
; i
++)
6498 if (temp_index
== (sizeof temp_buffer
6501 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
6505 /* Decode the input data. */
6509 require
= decoding_buffer_size (&coding
, nbytes
);
6510 p
= (unsigned char *) alloca (require
);
6511 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6512 /* We explicitly disable composition
6513 handling because key data should
6514 not contain any composition
6516 coding
.composing
= COMPOSITION_DISABLED
;
6517 decode_coding (&coding
, copy_bufptr
, p
,
6519 nbytes
= coding
.produced
;
6520 nchars
= coding
.produced_char
;
6524 /* Convert the input data to a sequence of
6525 character events. */
6526 for (i
= 0; i
< nbytes
; i
+= len
)
6528 if (nchars
== nbytes
)
6529 c
= copy_bufptr
[i
], len
= 1;
6531 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6534 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
6535 ? ASCII_KEYSTROKE_EVENT
6536 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6538 XSETFRAME (bufp
->frame_or_window
, f
);
6541 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6543 bufp
->timestamp
= event
.xkey
.time
;
6550 if (keysym
== NoSymbol
)
6560 /* Don't dispatch this event since XtDispatchEvent calls
6561 XFilterEvent, and two calls in a row may freeze the
6570 /* Don't dispatch this event since XtDispatchEvent calls
6571 XFilterEvent, and two calls in a row may freeze the
6582 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6585 bufp
+= n
, count
+= n
, numchars
-= n
;
6588 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6591 if (event
.xcrossing
.focus
)
6593 /* Avoid nasty pop/raise loops. */
6594 if (f
&& (!(f
->auto_raise
)
6596 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6598 x_new_focus_frame (dpyinfo
, f
);
6599 enter_timestamp
= event
.xcrossing
.time
;
6602 else if (f
== dpyinfo
->x_focus_frame
)
6603 x_new_focus_frame (dpyinfo
, 0);
6606 /* EnterNotify counts as mouse movement,
6607 so update things that depend on mouse position. */
6608 if (f
&& !f
->output_data
.x
->hourglass_p
)
6609 note_mouse_movement (f
, &event
.xmotion
);
6617 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6620 bufp
+= n
, count
+= n
, numchars
-= n
;
6630 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6633 bufp
+= n
, count
+= n
, numchars
-= n
;
6637 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6640 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6642 /* If we move outside the frame, then we're
6643 certainly no longer on any text in the frame. */
6644 clear_mouse_face (dpyinfo
);
6645 dpyinfo
->mouse_face_mouse_frame
= 0;
6648 /* Generate a nil HELP_EVENT to cancel a help-echo.
6649 Do it only if there's something to cancel.
6650 Otherwise, the startup message is cleared when
6651 the mouse leaves the frame. */
6652 if (any_help_event_p
)
6657 XSETFRAME (frame
, f
);
6658 help_echo_string
= Qnil
;
6659 n
= gen_help_event (bufp
, numchars
,
6660 Qnil
, frame
, Qnil
, Qnil
, 0);
6661 bufp
+= n
, count
+= n
, numchars
-= n
;
6671 n
= x_detect_focus_change (dpyinfo
, &event
, bufp
, numchars
);
6674 bufp
+= n
, count
+= n
, numchars
-= n
;
6682 previous_help_echo_string
= help_echo_string
;
6683 help_echo_string
= help_echo_object
= help_echo_window
= Qnil
;
6686 if (dpyinfo
->grabbed
&& last_mouse_frame
6687 && FRAME_LIVE_P (last_mouse_frame
))
6688 f
= last_mouse_frame
;
6690 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6692 if (dpyinfo
->mouse_face_hidden
)
6694 dpyinfo
->mouse_face_hidden
= 0;
6695 clear_mouse_face (dpyinfo
);
6701 /* Generate SELECT_WINDOW_EVENTs when needed. */
6702 if (mouse_autoselect_window
)
6706 window
= window_from_coordinates (f
,
6707 event
.xmotion
.x
, event
.xmotion
.y
,
6710 /* Window will be selected only when it is not selected now and
6711 last mouse movement event was not in it. Minibuffer window
6712 will be selected iff it is active. */
6713 if (WINDOWP (window
)
6714 && !EQ (window
, last_window
)
6715 && !EQ (window
, selected_window
)
6718 bufp
->kind
= SELECT_WINDOW_EVENT
;
6719 bufp
->frame_or_window
= window
;
6721 ++bufp
, ++count
, --numchars
;
6726 note_mouse_movement (f
, &event
.xmotion
);
6730 #ifndef USE_TOOLKIT_SCROLL_BARS
6731 struct scroll_bar
*bar
6732 = x_window_to_scroll_bar (event
.xmotion
.display
,
6733 event
.xmotion
.window
);
6736 x_scroll_bar_note_movement (bar
, &event
);
6737 #endif /* USE_TOOLKIT_SCROLL_BARS */
6739 /* If we move outside the frame, then we're
6740 certainly no longer on any text in the frame. */
6741 clear_mouse_face (dpyinfo
);
6744 /* If the contents of the global variable help_echo_string
6745 has changed, generate a HELP_EVENT. */
6746 if (!NILP (help_echo_string
)
6747 || !NILP (previous_help_echo_string
))
6753 XSETFRAME (frame
, f
);
6757 any_help_event_p
= 1;
6758 n
= gen_help_event (bufp
, numchars
, help_echo_string
, frame
,
6759 help_echo_window
, help_echo_object
,
6761 bufp
+= n
, count
+= n
, numchars
-= n
;
6767 case ConfigureNotify
:
6768 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6771 #ifndef USE_X_TOOLKIT
6773 xg_resize_widgets (f
, event
.xconfigure
.width
,
6774 event
.xconfigure
.height
);
6775 #else /* not USE_GTK */
6776 /* If there is a pending resize for fullscreen, don't
6777 do this one, the right one will come later.
6778 The toolkit version doesn't seem to need this, but we
6779 need to reset it below. */
6781 = ((f
->want_fullscreen
& FULLSCREEN_WAIT
)
6782 && f
->new_text_cols
!= 0);
6783 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6784 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6789 /* In the toolkit version, change_frame_size
6790 is called by the code that handles resizing
6791 of the EmacsFrame widget. */
6793 /* Even if the number of character rows and columns has
6794 not changed, the font size may have changed, so we need
6795 to check the pixel dimensions as well. */
6796 if (columns
!= FRAME_COLS (f
)
6797 || rows
!= FRAME_LINES (f
)
6798 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6799 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6801 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6802 SET_FRAME_GARBAGED (f
);
6803 cancel_mouse_face (f
);
6805 #endif /* not USE_GTK */
6808 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6809 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6812 /* GTK creates windows but doesn't map them.
6813 Only get real positions and check fullscreen when mapped. */
6814 if (FRAME_GTK_OUTER_WIDGET (f
)
6815 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
6818 /* What we have now is the position of Emacs's own window.
6819 Convert that to the position of the window manager window. */
6820 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6822 x_check_expected_move (f
);
6823 if (f
->want_fullscreen
& FULLSCREEN_WAIT
)
6824 f
->want_fullscreen
&= ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
6828 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6829 xic_set_statusarea (f
);
6832 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
6834 /* Since the WM decorations come below top_pos now,
6835 we must put them below top_pos in the future. */
6836 f
->win_gravity
= NorthWestGravity
;
6837 x_wm_set_size_hint (f
, (long) 0, 0);
6845 /* If we decide we want to generate an event to be seen
6846 by the rest of Emacs, we put it here. */
6847 struct input_event emacs_event
;
6850 emacs_event
.kind
= NO_EVENT
;
6851 bzero (&compose_status
, sizeof (compose_status
));
6853 if (dpyinfo
->grabbed
6855 && FRAME_LIVE_P (last_mouse_frame
))
6856 f
= last_mouse_frame
;
6858 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6862 /* Is this in the tool-bar? */
6863 if (WINDOWP (f
->tool_bar_window
)
6864 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6867 int x
= event
.xbutton
.x
;
6868 int y
= event
.xbutton
.y
;
6870 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6871 if (EQ (window
, f
->tool_bar_window
))
6873 if (event
.xbutton
.type
== ButtonPress
)
6874 handle_tool_bar_click (f
, x
, y
, 1, 0);
6876 handle_tool_bar_click (f
, x
, y
, 0,
6877 x_x_to_emacs_modifiers (dpyinfo
,
6878 event
.xbutton
.state
));
6884 if (!dpyinfo
->x_focus_frame
6885 || f
== dpyinfo
->x_focus_frame
)
6887 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6888 if (! popup_activated ())
6890 construct_mouse_click (&emacs_event
, &event
, f
);
6895 struct scroll_bar
*bar
6896 = x_window_to_scroll_bar (event
.xbutton
.display
,
6897 event
.xbutton
.window
);
6899 #ifdef USE_TOOLKIT_SCROLL_BARS
6900 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6902 if (bar
&& event
.xbutton
.state
& ControlMask
)
6904 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
6905 *finish
= X_EVENT_DROP
;
6907 #else /* not USE_TOOLKIT_SCROLL_BARS */
6909 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
6910 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6913 if (event
.type
== ButtonPress
)
6915 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6916 last_mouse_frame
= f
;
6917 /* Ignore any mouse motion that happened
6918 before this event; any subsequent mouse-movement
6919 Emacs events should reflect only motion after
6925 last_tool_bar_item
= -1;
6928 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6930 if (numchars
>= 1 && emacs_event
.kind
!= NO_EVENT
)
6932 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
6938 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6939 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6940 /* For a down-event in the menu bar,
6941 don't pass it to Xt right now.
6942 Instead, save it away
6943 and we will pass it to Xt from kbd_buffer_get_event.
6944 That way, we can run some Lisp code first. */
6947 ! popup_activated ()
6950 f
&& event
.type
== ButtonPress
6951 /* Verify the event is really within the menu bar
6952 and not just sent to it due to grabbing. */
6953 && event
.xbutton
.x
>= 0
6954 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6955 && event
.xbutton
.y
>= 0
6956 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6957 && event
.xbutton
.same_screen
)
6959 SET_SAVED_BUTTON_EVENT
;
6960 XSETFRAME (last_mouse_press_frame
, f
);
6962 *finish
= X_EVENT_DROP
;
6965 else if (event
.type
== ButtonPress
)
6967 last_mouse_press_frame
= Qnil
;
6971 #ifdef USE_MOTIF /* This should do not harm for Lucid,
6972 but I am trying to be cautious. */
6973 else if (event
.type
== ButtonRelease
)
6975 if (!NILP (last_mouse_press_frame
))
6977 f
= XFRAME (last_mouse_press_frame
);
6978 if (f
->output_data
.x
)
6979 SET_SAVED_BUTTON_EVENT
;
6984 #endif /* USE_MOTIF */
6987 #endif /* USE_X_TOOLKIT || USE_GTK */
6991 case CirculateNotify
:
6994 case CirculateRequest
:
6997 case VisibilityNotify
:
7001 /* Someone has changed the keyboard mapping - update the
7003 switch (event
.xmapping
.request
)
7005 case MappingModifier
:
7006 x_find_modifier_meanings (dpyinfo
);
7007 /* This is meant to fall through. */
7008 case MappingKeyboard
:
7009 XRefreshKeyboardMapping (&event
.xmapping
);
7015 #ifdef USE_X_TOOLKIT
7017 if (*finish
!= X_EVENT_DROP
)
7018 XtDispatchEvent (&event
);
7020 #endif /* USE_X_TOOLKIT */
7027 *finish
= X_EVENT_GOTO_OUT
;
7031 *numcharsp
= numchars
;
7038 /* Handles the XEvent EVENT on display DISPLAY.
7039 This is used for event loops outside the normal event handling,
7040 i.e. looping while a popup menu or a dialog is posted.
7042 Returns the value handle_one_xevent sets in the finish argument. */
7044 x_dispatch_event (event
, display
)
7048 struct x_display_info
*dpyinfo
;
7049 struct input_event bufp
[10];
7050 struct input_event
*bufpp
;
7052 int finish
= X_EVENT_NORMAL
;
7054 for (bufpp
= bufp
; bufpp
!= bufp
+ 10; bufpp
++)
7055 EVENT_INIT (*bufpp
);
7058 dpyinfo
= x_display_info_for_display (display
);
7063 events
= handle_one_xevent (dpyinfo
,
7068 for (i
= 0; i
< events
; ++i
)
7069 kbd_buffer_store_event (&bufp
[i
]);
7076 /* Read events coming from the X server.
7077 This routine is called by the SIGIO handler.
7078 We return as soon as there are no more events to be read.
7080 Events representing keys are stored in buffer BUFP,
7081 which can hold up to NUMCHARS characters.
7082 We return the number of characters stored into the buffer,
7083 thus pretending to be `read'.
7085 EXPECTED is nonzero if the caller knows input is available. */
7088 XTread_socket (display
, bufp
, numchars
, expected
)
7089 struct display
*display
;
7090 struct input_event
*bufp
;
7096 int event_found
= 0;
7097 struct x_display_info
*dpyinfo
;
7099 if (interrupt_input_blocked
)
7101 interrupt_input_pending
= 1;
7105 interrupt_input_pending
= 0;
7108 /* So people can tell when we have read the available input. */
7109 input_signal_count
++;
7112 abort (); /* Don't think this happens. */
7116 /* Find the display we are supposed to read input for.
7117 It's the one communicating on descriptor SD. */
7118 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7120 #if 0 /* This ought to be unnecessary; let's verify it. */
7122 /* If available, Xlib uses FIOSNBIO to make the socket
7123 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
7124 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
7125 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
7126 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
7127 #endif /* ! defined (FIOSNBIO) */
7130 #if 0 /* This code can't be made to work, with multiple displays,
7131 and appears not to be used on any system any more.
7132 Also keyboard.c doesn't turn O_NDELAY on and off
7133 for X connections. */
7136 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7138 extern int read_alarm_should_throw
;
7139 read_alarm_should_throw
= 1;
7140 XPeekEvent (dpyinfo
->display
, &event
);
7141 read_alarm_should_throw
= 0;
7143 #endif /* HAVE_SELECT */
7147 /* For debugging, this gives a way to fake an I/O error. */
7148 if (dpyinfo
== XTread_socket_fake_io_error
)
7150 XTread_socket_fake_io_error
= 0;
7151 x_io_error_quitter (dpyinfo
->display
);
7156 count
+= x_session_check_input (bufp
, &numchars
);
7161 while (XPending (dpyinfo
->display
))
7165 XNextEvent (dpyinfo
->display
, &event
);
7168 /* Filter events for the current X input method. */
7169 if (x_filter_event (dpyinfo
, &event
))
7174 count
+= handle_one_xevent (dpyinfo
,
7180 if (finish
== X_EVENT_GOTO_OUT
)
7183 #endif /* not USE_GTK */
7188 /* For GTK we must use the GTK event loop. But XEvents gets passed
7189 to our filter function above, and then to the big event switch.
7190 We use a bunch of globals to communicate with our filter function,
7191 that is kind of ugly, but it works.
7193 There is no way to do one display at the time, GTK just does events
7194 from all displays. */
7196 while (gtk_events_pending ())
7198 current_count
= count
;
7199 current_numcharsp
= &numchars
;
7200 current_bufp
= &bufp
;
7202 gtk_main_iteration ();
7204 count
= current_count
;
7206 current_numcharsp
= 0;
7208 if (current_finish
== X_EVENT_GOTO_OUT
)
7211 #endif /* USE_GTK */
7215 /* On some systems, an X bug causes Emacs to get no more events
7216 when the window is destroyed. Detect that. (1994.) */
7219 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7220 One XNOOP in 100 loops will make Emacs terminate.
7221 B. Bretthauer, 1994 */
7223 if (x_noop_count
>= 100)
7227 if (next_noop_dpyinfo
== 0)
7228 next_noop_dpyinfo
= x_display_list
;
7230 XNoOp (next_noop_dpyinfo
->display
);
7232 /* Each time we get here, cycle through the displays now open. */
7233 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7237 /* If the focus was just given to an auto-raising frame,
7239 /* ??? This ought to be able to handle more than one such frame. */
7240 if (pending_autoraise_frame
)
7242 x_raise_frame (pending_autoraise_frame
);
7243 pending_autoraise_frame
= 0;
7254 /***********************************************************************
7256 ***********************************************************************/
7258 /* Set clipping for output in glyph row ROW. W is the window in which
7259 we operate. GC is the graphics context to set clipping in.
7261 ROW may be a text row or, e.g., a mode line. Text rows must be
7262 clipped to the interior of the window dedicated to text display,
7263 mode lines must be clipped to the whole window. */
7266 x_clip_to_row (w
, row
, gc
)
7268 struct glyph_row
*row
;
7271 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7272 XRectangle clip_rect
;
7273 int window_y
, window_width
;
7275 window_box (w
, -1, 0, &window_y
, &window_width
, 0);
7277 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
7278 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
7279 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7280 clip_rect
.width
= window_width
;
7281 clip_rect
.height
= row
->visible_height
;
7283 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7287 /* Draw a hollow box cursor on window W in glyph row ROW. */
7290 x_draw_hollow_cursor (w
, row
)
7292 struct glyph_row
*row
;
7294 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7295 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7296 Display
*dpy
= FRAME_X_DISPLAY (f
);
7299 struct glyph
*cursor_glyph
;
7302 /* Get the glyph the cursor is on. If we can't tell because
7303 the current matrix is invalid or such, give up. */
7304 cursor_glyph
= get_phys_cursor_glyph (w
);
7305 if (cursor_glyph
== NULL
)
7308 /* Compute the width of the rectangle to draw. If on a stretch
7309 glyph, and `x-stretch-block-cursor' is nil, don't draw a
7310 rectangle as wide as the glyph, but use a canonical character
7312 wd
= cursor_glyph
->pixel_width
- 1;
7313 if (cursor_glyph
->type
== STRETCH_GLYPH
7314 && !x_stretch_cursor_p
)
7315 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
7316 w
->phys_cursor_width
= wd
;
7318 /* Compute frame-relative coordinates from window-relative
7320 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7321 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
);
7323 /* Compute the proper height and ascent of the rectangle, based
7324 on the actual glyph. Using the full height of the row looks
7325 bad when there are tall images on that row. */
7326 h
= max (FRAME_LINE_HEIGHT (f
), cursor_glyph
->ascent
+ cursor_glyph
->descent
);
7327 if (h
< row
->height
)
7328 y
+= row
->ascent
/* - w->phys_cursor_ascent */ + cursor_glyph
->descent
- h
;
7331 /* The foreground of cursor_gc is typically the same as the normal
7332 background color, which can cause the cursor box to be invisible. */
7333 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7334 if (dpyinfo
->scratch_cursor_gc
)
7335 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7337 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7338 GCForeground
, &xgcv
);
7339 gc
= dpyinfo
->scratch_cursor_gc
;
7341 /* Set clipping, draw the rectangle, and reset clipping again. */
7342 x_clip_to_row (w
, row
, gc
);
7343 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
7344 XSetClipMask (dpy
, gc
, None
);
7348 /* Draw a bar cursor on window W in glyph row ROW.
7350 Implementation note: One would like to draw a bar cursor with an
7351 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7352 Unfortunately, I didn't find a font yet that has this property set.
7356 x_draw_bar_cursor (w
, row
, width
, kind
)
7358 struct glyph_row
*row
;
7360 enum text_cursor_kinds kind
;
7362 struct frame
*f
= XFRAME (w
->frame
);
7363 struct glyph
*cursor_glyph
;
7365 /* If cursor is out of bounds, don't draw garbage. This can happen
7366 in mini-buffer windows when switching between echo area glyphs
7368 cursor_glyph
= get_phys_cursor_glyph (w
);
7369 if (cursor_glyph
== NULL
)
7372 /* If on an image, draw like a normal cursor. That's usually better
7373 visible than drawing a bar, esp. if the image is large so that
7374 the bar might not be in the window. */
7375 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7377 struct glyph_row
*row
;
7378 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7379 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7383 Display
*dpy
= FRAME_X_DISPLAY (f
);
7384 Window window
= FRAME_X_WINDOW (f
);
7385 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7386 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7387 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7390 /* If the glyph's background equals the color we normally draw
7391 the bar cursor in, the bar cursor in its normal color is
7392 invisible. Use the glyph's foreground color instead in this
7393 case, on the assumption that the glyph's colors are chosen so
7394 that the glyph is legible. */
7395 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7396 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7398 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7399 xgcv
.graphics_exposures
= 0;
7402 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7405 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7406 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7410 width
= FRAME_CURSOR_WIDTH (f
);
7411 width
= min (cursor_glyph
->pixel_width
, width
);
7413 w
->phys_cursor_width
= width
;
7414 x_clip_to_row (w
, row
, gc
);
7416 if (kind
== BAR_CURSOR
)
7417 XFillRectangle (dpy
, window
, gc
,
7418 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7419 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7420 width
, row
->height
);
7422 XFillRectangle (dpy
, window
, gc
,
7423 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7424 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7425 row
->height
- width
),
7426 cursor_glyph
->pixel_width
,
7429 XSetClipMask (dpy
, gc
, None
);
7434 /* RIF: Define cursor CURSOR on frame F. */
7437 x_define_frame_cursor (f
, cursor
)
7441 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7445 /* RIF: Clear area on frame F. */
7448 x_clear_frame_area (f
, x
, y
, width
, height
)
7450 int x
, y
, width
, height
;
7452 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7453 x
, y
, width
, height
, False
);
7457 /* RIF: Draw cursor on window W. */
7460 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7462 struct glyph_row
*glyph_row
;
7464 int cursor_type
, cursor_width
;
7467 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7471 w
->phys_cursor_type
= cursor_type
;
7472 w
->phys_cursor_on_p
= 1;
7474 if (glyph_row
->exact_window_width_line_p
7475 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7477 glyph_row
->cursor_in_fringe_p
= 1;
7478 draw_fringe_bitmap (w
, glyph_row
, 0);
7481 switch (cursor_type
)
7483 case HOLLOW_BOX_CURSOR
:
7484 x_draw_hollow_cursor (w
, glyph_row
);
7487 case FILLED_BOX_CURSOR
:
7488 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7492 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7496 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7500 w
->phys_cursor_width
= 0;
7508 if (w
== XWINDOW (f
->selected_window
))
7509 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7510 xic_set_preeditarea (w
, x
, y
);
7515 if (updating_frame
!= f
)
7516 XFlush (FRAME_X_DISPLAY (f
));
7523 /* Make the x-window of frame F use the gnu icon bitmap. */
7526 x_bitmap_icon (f
, file
)
7532 if (FRAME_X_WINDOW (f
) == 0)
7535 /* Free up our existing icon bitmap and mask if any. */
7536 if (f
->output_data
.x
->icon_bitmap
> 0)
7537 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7538 f
->output_data
.x
->icon_bitmap
= 0;
7543 /* Use gtk_window_set_icon_from_file () if available,
7544 It's not restricted to bitmaps */
7545 if (xg_set_icon (f
, file
))
7547 #endif /* USE_GTK */
7548 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7549 x_create_bitmap_mask (f
, bitmap_id
);
7553 /* Create the GNU bitmap and mask if necessary. */
7554 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7556 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
7557 = x_create_bitmap_from_data (f
, gnu_bits
,
7558 gnu_width
, gnu_height
);
7559 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7562 /* The first time we create the GNU bitmap and mask,
7563 this increments the ref-count one extra time.
7564 As a result, the GNU bitmap and mask are never freed.
7565 That way, we don't have to worry about allocating it again. */
7566 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7568 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7571 x_wm_set_icon_pixmap (f
, bitmap_id
);
7572 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7578 /* Make the x-window of frame F use a rectangle with text.
7579 Use ICON_NAME as the text. */
7582 x_text_icon (f
, icon_name
)
7586 if (FRAME_X_WINDOW (f
) == 0)
7592 text
.value
= (unsigned char *) icon_name
;
7593 text
.encoding
= XA_STRING
;
7595 text
.nitems
= strlen (icon_name
);
7596 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7598 #else /* not HAVE_X11R4 */
7599 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), icon_name
);
7600 #endif /* not HAVE_X11R4 */
7602 if (f
->output_data
.x
->icon_bitmap
> 0)
7603 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7604 f
->output_data
.x
->icon_bitmap
= 0;
7605 x_wm_set_icon_pixmap (f
, 0);
7610 #define X_ERROR_MESSAGE_SIZE 200
7612 /* If non-nil, this should be a string.
7613 It means catch X errors and store the error message in this string. */
7615 static Lisp_Object x_error_message_string
;
7617 /* An X error handler which stores the error message in
7618 x_error_message_string. This is called from x_error_handler if
7619 x_catch_errors is in effect. */
7622 x_error_catcher (display
, error
)
7626 XGetErrorText (display
, error
->error_code
,
7627 SDATA (x_error_message_string
),
7628 X_ERROR_MESSAGE_SIZE
);
7631 /* Begin trapping X errors for display DPY. Actually we trap X errors
7632 for all displays, but DPY should be the display you are actually
7635 After calling this function, X protocol errors no longer cause
7636 Emacs to exit; instead, they are recorded in the string
7637 stored in x_error_message_string.
7639 Calling x_check_errors signals an Emacs error if an X error has
7640 occurred since the last call to x_catch_errors or x_check_errors.
7642 Calling x_uncatch_errors resumes the normal error handling. */
7644 void x_check_errors ();
7645 static Lisp_Object
x_catch_errors_unwind ();
7648 x_catch_errors (dpy
)
7651 int count
= SPECPDL_INDEX ();
7653 /* Make sure any errors from previous requests have been dealt with. */
7656 record_unwind_protect (x_catch_errors_unwind
,
7657 Fcons (make_save_value (dpy
, 0),
7658 x_error_message_string
));
7660 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
7661 SSET (x_error_message_string
, 0, 0);
7666 /* Unbind the binding that we made to check for X errors. */
7669 x_catch_errors_unwind (old_val
)
7670 Lisp_Object old_val
;
7674 first
= XCAR (old_val
);
7676 XSync (XSAVE_VALUE (first
)->pointer
, False
);
7678 x_error_message_string
= XCDR (old_val
);
7682 /* If any X protocol errors have arrived since the last call to
7683 x_catch_errors or x_check_errors, signal an Emacs error using
7684 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7687 x_check_errors (dpy
, format
)
7691 /* Make sure to catch any errors incurred so far. */
7694 if (SREF (x_error_message_string
, 0))
7695 error (format
, SDATA (x_error_message_string
));
7698 /* Nonzero if we had any X protocol errors
7699 since we did x_catch_errors on DPY. */
7702 x_had_errors_p (dpy
)
7705 /* Make sure to catch any errors incurred so far. */
7708 return SREF (x_error_message_string
, 0) != 0;
7711 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7714 x_clear_errors (dpy
)
7717 SSET (x_error_message_string
, 0, 0);
7720 /* Stop catching X protocol errors and let them make Emacs die.
7721 DPY should be the display that was passed to x_catch_errors.
7722 COUNT should be the value that was returned by
7723 the corresponding call to x_catch_errors. */
7726 x_uncatch_errors (dpy
, count
)
7730 unbind_to (count
, Qnil
);
7734 static unsigned int x_wire_count
;
7737 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7742 /* Handle SIGPIPE, which can happen when the connection to a server
7743 simply goes away. SIGPIPE is handled by x_connection_signal.
7744 Don't need to do anything, because the write which caused the
7745 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7746 which will do the appropriate cleanup for us. */
7749 x_connection_signal (signalnum
) /* If we don't have an argument, */
7750 int signalnum
; /* some compilers complain in signal calls. */
7753 /* USG systems forget handlers when they are used;
7754 must reestablish each time */
7755 signal (signalnum
, x_connection_signal
);
7760 /************************************************************************
7762 ************************************************************************/
7764 /* Error message passed to x_connection_closed. */
7766 static char *error_msg
;
7768 /* Function installed as fatal_error_signal_hook in
7769 x_connection_closed. Print the X error message, and exit normally,
7770 instead of dumping core when XtCloseDisplay fails. */
7773 x_fatal_error_signal ()
7775 fprintf (stderr
, "%s\n", error_msg
);
7779 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7780 the text of an error message that lead to the connection loss. */
7783 x_connection_closed (dpy
, error_message
)
7785 char *error_message
;
7787 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7788 Lisp_Object frame
, tail
;
7791 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7792 strcpy (error_msg
, error_message
);
7793 handling_signal
= 0;
7795 /* Prevent being called recursively because of an error condition
7796 below. Otherwise, we might end up with printing ``can't find per
7797 display information'' in the recursive call instead of printing
7798 the original message here. */
7799 count
= x_catch_errors (dpy
);
7801 /* We have to close the display to inform Xt that it doesn't
7802 exist anymore. If we don't, Xt will continue to wait for
7803 events from the display. As a consequence, a sequence of
7805 M-x make-frame-on-display RET :1 RET
7806 ...kill the new frame, so that we get an IO error...
7807 M-x make-frame-on-display RET :1 RET
7809 will indefinitely wait in Xt for events for display `:1', opened
7810 in the first class to make-frame-on-display.
7812 Closing the display is reported to lead to a bus error on
7813 OpenWindows in certain situations. I suspect that is a bug
7814 in OpenWindows. I don't know how to cicumvent it here. */
7816 #ifdef USE_X_TOOLKIT
7817 /* If DPYINFO is null, this means we didn't open the display
7818 in the first place, so don't try to close it. */
7821 extern void (*fatal_error_signal_hook
) P_ ((void));
7822 fatal_error_signal_hook
= x_fatal_error_signal
;
7823 XtCloseDisplay (dpy
);
7824 fatal_error_signal_hook
= NULL
;
7830 xg_display_close (dpyinfo
->display
);
7833 /* Indicate that this display is dead. */
7835 dpyinfo
->display
= 0;
7837 /* First delete frames whose mini-buffers are on frames
7838 that are on the dead display. */
7839 FOR_EACH_FRAME (tail
, frame
)
7841 Lisp_Object minibuf_frame
;
7843 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7844 if (FRAME_X_P (XFRAME (frame
))
7845 && FRAME_X_P (XFRAME (minibuf_frame
))
7846 && ! EQ (frame
, minibuf_frame
)
7847 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7848 Fdelete_frame (frame
, Qt
);
7851 /* Now delete all remaining frames on the dead display.
7852 We are now sure none of these is used as the mini-buffer
7853 for another frame that we need to delete. */
7854 FOR_EACH_FRAME (tail
, frame
)
7855 if (FRAME_X_P (XFRAME (frame
))
7856 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7858 /* Set this to t so that Fdelete_frame won't get confused
7859 trying to find a replacement. */
7860 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7861 Fdelete_frame (frame
, Qt
);
7865 x_delete_display (dpyinfo
);
7867 x_uncatch_errors (dpy
, count
);
7869 if (x_display_list
== 0)
7871 fprintf (stderr
, "%s\n", error_msg
);
7872 shut_down_emacs (0, 0, Qnil
);
7876 /* Ordinary stack unwind doesn't deal with these. */
7878 sigunblock (sigmask (SIGIO
));
7880 sigunblock (sigmask (SIGALRM
));
7881 TOTALLY_UNBLOCK_INPUT
;
7883 clear_waiting_for_input ();
7884 error ("%s", error_msg
);
7888 /* This is the usual handler for X protocol errors.
7889 It kills all frames on the display that we got the error for.
7890 If that was the only one, it prints an error message and kills Emacs. */
7893 x_error_quitter (display
, error
)
7897 char buf
[256], buf1
[356];
7899 /* Note that there is no real way portable across R3/R4 to get the
7900 original error handler. */
7902 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7903 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7904 buf
, error
->request_code
);
7905 x_connection_closed (display
, buf1
);
7909 /* This is the first-level handler for X protocol errors.
7910 It calls x_error_quitter or x_error_catcher. */
7913 x_error_handler (display
, error
)
7917 if (! NILP (x_error_message_string
))
7918 x_error_catcher (display
, error
);
7920 x_error_quitter (display
, error
);
7924 /* This is the handler for X IO errors, always.
7925 It kills all frames on the display that we lost touch with.
7926 If that was the only one, it prints an error message and kills Emacs. */
7929 x_io_error_quitter (display
)
7934 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7935 x_connection_closed (display
, buf
);
7939 /* Changing the font of the frame. */
7941 /* Give frame F the font named FONTNAME as its default font, and
7942 return the full name of that font. FONTNAME may be a wildcard
7943 pattern; in that case, we choose some font that fits the pattern.
7944 The return value shows which font we chose. */
7947 x_new_font (f
, fontname
)
7949 register char *fontname
;
7951 struct font_info
*fontp
7952 = FS_LOAD_FONT (f
, 0, fontname
, -1);
7957 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
7958 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
7959 FRAME_FONTSET (f
) = -1;
7961 FRAME_COLUMN_WIDTH (f
) = FONT_WIDTH (FRAME_FONT (f
));
7962 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
7964 compute_fringe_widths (f
, 1);
7966 /* Compute the scroll bar width in character columns. */
7967 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7969 int wid
= FRAME_COLUMN_WIDTH (f
);
7970 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7971 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7975 int wid
= FRAME_COLUMN_WIDTH (f
);
7976 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7979 /* Now make the frame display the given font. */
7980 if (FRAME_X_WINDOW (f
) != 0)
7982 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
7983 FRAME_FONT (f
)->fid
);
7984 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
7985 FRAME_FONT (f
)->fid
);
7986 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
7987 FRAME_FONT (f
)->fid
);
7989 /* Don't change the size of a tip frame; there's no point in
7990 doing it because it's done in Fx_show_tip, and it leads to
7991 problems because the tip frame has no widget. */
7992 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7993 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7996 return build_string (fontp
->full_name
);
7999 /* Give frame F the fontset named FONTSETNAME as its default font, and
8000 return the full name of that fontset. FONTSETNAME may be a wildcard
8001 pattern; in that case, we choose some fontset that fits the pattern.
8002 The return value shows which fontset we chose. */
8005 x_new_fontset (f
, fontsetname
)
8009 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
8015 if (FRAME_FONTSET (f
) == fontset
)
8016 /* This fontset is already set in frame F. There's nothing more
8018 return fontset_name (fontset
);
8020 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
8022 if (!STRINGP (result
))
8023 /* Can't load ASCII font. */
8026 /* Since x_new_font doesn't update any fontset information, do it now. */
8027 FRAME_FONTSET (f
) = fontset
;
8031 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8032 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8035 return build_string (fontsetname
);
8039 /***********************************************************************
8041 ***********************************************************************/
8047 /* XIM destroy callback function, which is called whenever the
8048 connection to input method XIM dies. CLIENT_DATA contains a
8049 pointer to the x_display_info structure corresponding to XIM. */
8052 xim_destroy_callback (xim
, client_data
, call_data
)
8054 XPointer client_data
;
8057 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8058 Lisp_Object frame
, tail
;
8062 /* No need to call XDestroyIC.. */
8063 FOR_EACH_FRAME (tail
, frame
)
8065 struct frame
*f
= XFRAME (frame
);
8066 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8068 FRAME_XIC (f
) = NULL
;
8069 if (FRAME_XIC_FONTSET (f
))
8071 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
8072 FRAME_XIC_FONTSET (f
) = NULL
;
8077 /* No need to call XCloseIM. */
8078 dpyinfo
->xim
= NULL
;
8079 XFree (dpyinfo
->xim_styles
);
8083 #endif /* HAVE_X11R6 */
8086 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8087 extern char *XSetIMValues
P_ ((XIM
, ...));
8090 /* Open the connection to the XIM server on display DPYINFO.
8091 RESOURCE_NAME is the resource name Emacs uses. */
8094 xim_open_dpy (dpyinfo
, resource_name
)
8095 struct x_display_info
*dpyinfo
;
8096 char *resource_name
;
8103 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8110 XIMCallback destroy
;
8113 /* Get supported styles and XIM values. */
8114 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8117 destroy
.callback
= xim_destroy_callback
;
8118 destroy
.client_data
= (XPointer
)dpyinfo
;
8119 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8125 #endif /* HAVE_XIM */
8126 dpyinfo
->xim
= NULL
;
8130 #ifdef HAVE_X11R6_XIM
8134 struct x_display_info
*dpyinfo
;
8135 char *resource_name
;
8138 /* XIM instantiate callback function, which is called whenever an XIM
8139 server is available. DISPLAY is the display of the XIM.
8140 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8141 when the callback was registered. */
8144 xim_instantiate_callback (display
, client_data
, call_data
)
8146 XPointer client_data
;
8149 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8150 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8152 /* We don't support multiple XIM connections. */
8156 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8158 /* Create XIC for the existing frames on the same display, as long
8159 as they have no XIC. */
8160 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8162 Lisp_Object tail
, frame
;
8165 FOR_EACH_FRAME (tail
, frame
)
8167 struct frame
*f
= XFRAME (frame
);
8170 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8171 if (FRAME_XIC (f
) == NULL
)
8173 create_frame_xic (f
);
8174 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8175 xic_set_statusarea (f
);
8176 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8178 struct window
*w
= XWINDOW (f
->selected_window
);
8179 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8188 #endif /* HAVE_X11R6_XIM */
8191 /* Open a connection to the XIM server on display DPYINFO.
8192 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8193 connection only at the first time. On X11R6, open the connection
8194 in the XIM instantiate callback function. */
8197 xim_initialize (dpyinfo
, resource_name
)
8198 struct x_display_info
*dpyinfo
;
8199 char *resource_name
;
8204 #ifdef HAVE_X11R6_XIM
8205 struct xim_inst_t
*xim_inst
;
8208 dpyinfo
->xim
= NULL
;
8209 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8210 xim_inst
->dpyinfo
= dpyinfo
;
8211 len
= strlen (resource_name
);
8212 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8213 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8214 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8215 resource_name
, EMACS_CLASS
,
8216 xim_instantiate_callback
,
8217 /* This is XPointer in XFree86
8218 but (XPointer *) on Tru64, at
8219 least, hence the configure test. */
8220 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8221 #else /* not HAVE_X11R6_XIM */
8222 dpyinfo
->xim
= NULL
;
8223 xim_open_dpy (dpyinfo
, resource_name
);
8224 #endif /* not HAVE_X11R6_XIM */
8228 #endif /* HAVE_XIM */
8229 dpyinfo
->xim
= NULL
;
8233 /* Close the connection to the XIM server on display DPYINFO. */
8236 xim_close_dpy (dpyinfo
)
8237 struct x_display_info
*dpyinfo
;
8242 #ifdef HAVE_X11R6_XIM
8243 if (dpyinfo
->display
)
8244 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8246 xim_instantiate_callback
, NULL
);
8247 #endif /* not HAVE_X11R6_XIM */
8248 if (dpyinfo
->display
)
8249 XCloseIM (dpyinfo
->xim
);
8250 dpyinfo
->xim
= NULL
;
8251 XFree (dpyinfo
->xim_styles
);
8253 #endif /* HAVE_XIM */
8256 #endif /* not HAVE_X11R6_XIM */
8260 /* Calculate the absolute position in frame F
8261 from its current recorded position values and gravity. */
8264 x_calc_absolute_position (f
)
8268 int win_x
= 0, win_y
= 0;
8269 int flags
= f
->size_hint_flags
;
8272 /* We have nothing to do if the current position
8273 is already for the top-left corner. */
8274 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8277 this_window
= FRAME_OUTER_WINDOW (f
);
8279 /* Find the position of the outside upper-left corner of
8280 the inner window, with respect to the outer window.
8281 But do this only if we will need the results. */
8282 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8287 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
8290 x_clear_errors (FRAME_X_DISPLAY (f
));
8291 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
8293 /* From-window, to-window. */
8295 f
->output_data
.x
->parent_desc
,
8297 /* From-position, to-position. */
8298 0, 0, &win_x
, &win_y
,
8302 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
8304 Window newroot
, newparent
= 0xdeadbeef;
8305 Window
*newchildren
;
8306 unsigned int nchildren
;
8308 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
8309 &newparent
, &newchildren
, &nchildren
))
8312 XFree ((char *) newchildren
);
8314 f
->output_data
.x
->parent_desc
= newparent
;
8320 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
8324 /* Treat negative positions as relative to the leftmost bottommost
8325 position that fits on the screen. */
8326 if (flags
& XNegative
)
8327 f
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
8328 - 2 * f
->border_width
- win_x
8329 - FRAME_PIXEL_WIDTH (f
)
8333 int height
= FRAME_PIXEL_HEIGHT (f
);
8335 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8336 /* Something is fishy here. When using Motif, starting Emacs with
8337 `-g -0-0', the frame appears too low by a few pixels.
8339 This seems to be so because initially, while Emacs is starting,
8340 the column widget's height and the frame's pixel height are
8341 different. The column widget's height is the right one. In
8342 later invocations, when Emacs is up, the frame's pixel height
8345 It's not obvious where the initial small difference comes from.
8346 2000-12-01, gerd. */
8348 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8351 if (flags
& YNegative
)
8352 f
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
8353 - 2 * f
->border_width
8359 /* The left_pos and top_pos
8360 are now relative to the top and left screen edges,
8361 so the flags should correspond. */
8362 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8365 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8366 to really change the position, and 0 when calling from
8367 x_make_frame_visible (in that case, XOFF and YOFF are the current
8368 position values). It is -1 when calling from x_set_frame_parameters,
8369 which means, do adjust for borders but don't change the gravity. */
8372 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8374 register int xoff
, yoff
;
8377 int modified_top
, modified_left
;
8379 if (change_gravity
> 0)
8383 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8385 f
->size_hint_flags
|= XNegative
;
8387 f
->size_hint_flags
|= YNegative
;
8388 f
->win_gravity
= NorthWestGravity
;
8390 x_calc_absolute_position (f
);
8393 x_wm_set_size_hint (f
, (long) 0, 0);
8395 modified_left
= f
->left_pos
;
8396 modified_top
= f
->top_pos
;
8398 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
8399 this seems to be unnecessary and incorrect. rms, 4/17/97. */
8400 /* It is a mystery why we need to add the border_width here
8401 when the frame is already visible, but experiment says we do. */
8402 if (change_gravity
!= 0)
8404 modified_left
+= f
->border_width
;
8405 modified_top
+= f
->border_width
;
8409 if (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8411 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8412 than the WM decorations. So we use the calculated offset instead
8413 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8414 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8415 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8418 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8419 modified_left
, modified_top
);
8421 if (FRAME_VISIBLE_P (f
)
8422 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
)
8424 FRAME_X_OUTPUT (f
)->check_expected_move
= 1;
8425 FRAME_X_OUTPUT (f
)->expected_top
= f
->top_pos
;
8426 FRAME_X_OUTPUT (f
)->expected_left
= f
->left_pos
;
8432 /* Check if we need to resize the frame due to a fullscreen request.
8433 If so needed, resize the frame. */
8435 x_check_fullscreen (f
)
8438 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
8440 int width
, height
, ign
;
8442 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8444 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8446 /* We do not need to move the window, it shall be taken care of
8447 when setting WM manager hints.
8448 If the frame is visible already, the position is checked by
8449 x_check_expected_move. */
8450 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8452 change_frame_size (f
, height
, width
, 0, 1, 0);
8453 SET_FRAME_GARBAGED (f
);
8454 cancel_mouse_face (f
);
8456 /* Wait for the change of frame size to occur */
8457 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
8462 /* If frame parameters are set after the frame is mapped, we need to move
8464 Some window managers moves the window to the right position, some
8465 moves the outer window manager window to the specified position.
8466 Here we check that we are in the right spot. If not, make a second
8467 move, assuming we are dealing with the second kind of window manager. */
8469 x_check_expected_move (f
)
8472 if (FRAME_X_OUTPUT (f
)->check_expected_move
)
8474 int expect_top
= FRAME_X_OUTPUT (f
)->expected_top
;
8475 int expect_left
= FRAME_X_OUTPUT (f
)->expected_left
;
8477 if (expect_top
!= f
->top_pos
|| expect_left
!= f
->left_pos
)
8479 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8480 FRAME_X_OUTPUT (f
)->move_offset_left
= expect_left
- f
->left_pos
;
8481 FRAME_X_OUTPUT (f
)->move_offset_top
= expect_top
- f
->top_pos
;
8483 x_set_offset (f
, expect_left
, expect_top
, 1);
8485 else if (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
)
8486 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8488 /* Just do this once */
8489 FRAME_X_OUTPUT (f
)->check_expected_move
= 0;
8494 /* Change the size of frame F's X window to COLS/ROWS in the case F
8495 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8496 top-left-corner window gravity for this size change and subsequent
8497 size changes. Otherwise we leave the window gravity unchanged. */
8500 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
8505 int pixelwidth
, pixelheight
;
8507 check_frame_size (f
, &rows
, &cols
);
8508 f
->scroll_bar_actual_width
8509 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8511 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
8512 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
8513 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
8515 compute_fringe_widths (f
, 0);
8517 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
8518 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8520 f
->win_gravity
= NorthWestGravity
;
8521 x_wm_set_size_hint (f
, (long) 0, 0);
8523 XSync (FRAME_X_DISPLAY (f
), False
);
8524 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8525 pixelwidth
, pixelheight
);
8527 /* Now, strictly speaking, we can't be sure that this is accurate,
8528 but the window manager will get around to dealing with the size
8529 change request eventually, and we'll hear how it went when the
8530 ConfigureNotify event gets here.
8532 We could just not bother storing any of this information here,
8533 and let the ConfigureNotify event set everything up, but that
8534 might be kind of confusing to the Lisp code, since size changes
8535 wouldn't be reported in the frame parameters until some random
8536 point in the future when the ConfigureNotify event arrives.
8538 We pass 1 for DELAY since we can't run Lisp code inside of
8540 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8541 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8542 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8544 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8545 receive in the ConfigureNotify event; if we get what we asked
8546 for, then the event won't cause the screen to become garbaged, so
8547 we have to make sure to do it here. */
8548 SET_FRAME_GARBAGED (f
);
8550 XFlush (FRAME_X_DISPLAY (f
));
8554 /* Call this to change the size of frame F's x-window.
8555 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8556 for this size change and subsequent size changes.
8557 Otherwise we leave the window gravity unchanged. */
8560 x_set_window_size (f
, change_gravity
, cols
, rows
)
8568 if (FRAME_GTK_WIDGET (f
))
8569 xg_frame_set_char_size (f
, cols
, rows
);
8571 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8574 if (f
->output_data
.x
->widget
!= NULL
)
8576 /* The x and y position of the widget is clobbered by the
8577 call to XtSetValues within EmacsFrameSetCharSize.
8578 This is a real kludge, but I don't understand Xt so I can't
8579 figure out a correct fix. Can anyone else tell me? -- rms. */
8580 int xpos
= f
->output_data
.x
->widget
->core
.x
;
8581 int ypos
= f
->output_data
.x
->widget
->core
.y
;
8582 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
8583 f
->output_data
.x
->widget
->core
.x
= xpos
;
8584 f
->output_data
.x
->widget
->core
.y
= ypos
;
8587 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8589 #else /* not USE_X_TOOLKIT */
8591 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8593 #endif /* not USE_X_TOOLKIT */
8595 /* If cursor was outside the new size, mark it as off. */
8596 mark_window_cursors_off (XWINDOW (f
->root_window
));
8598 /* Clear out any recollection of where the mouse highlighting was,
8599 since it might be in a place that's outside the new frame size.
8600 Actually checking whether it is outside is a pain in the neck,
8601 so don't try--just let the highlighting be done afresh with new size. */
8602 cancel_mouse_face (f
);
8607 /* Mouse warping. */
8610 x_set_mouse_position (f
, x
, y
)
8616 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8617 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8619 if (pix_x
< 0) pix_x
= 0;
8620 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8622 if (pix_y
< 0) pix_y
= 0;
8623 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8627 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8628 0, 0, 0, 0, pix_x
, pix_y
);
8632 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8635 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
8641 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8642 0, 0, 0, 0, pix_x
, pix_y
);
8646 /* focus shifting, raising and lowering. */
8649 x_focus_on_frame (f
)
8652 #if 0 /* This proves to be unpleasant. */
8656 /* I don't think that the ICCCM allows programs to do things like this
8657 without the interaction of the window manager. Whatever you end up
8658 doing with this code, do it to x_unfocus_frame too. */
8659 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8660 RevertToPointerRoot
, CurrentTime
);
8669 /* Look at the remarks in x_focus_on_frame. */
8670 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8671 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8672 RevertToPointerRoot
, CurrentTime
);
8676 /* Raise frame F. */
8682 if (f
->async_visible
)
8685 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8686 XFlush (FRAME_X_DISPLAY (f
));
8691 /* Lower frame F. */
8697 if (f
->async_visible
)
8700 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8701 XFlush (FRAME_X_DISPLAY (f
));
8707 XTframe_raise_lower (f
, raise_flag
)
8717 /* Change of visibility. */
8719 /* This tries to wait until the frame is really visible.
8720 However, if the window manager asks the user where to position
8721 the frame, this will return before the user finishes doing that.
8722 The frame will not actually be visible at that time,
8723 but it will become visible later when the window manager
8724 finishes with it. */
8727 x_make_frame_visible (f
)
8731 int original_top
, original_left
;
8732 int retry_count
= 2;
8738 type
= x_icon_type (f
);
8740 x_bitmap_icon (f
, type
);
8742 if (! FRAME_VISIBLE_P (f
))
8744 /* We test FRAME_GARBAGED_P here to make sure we don't
8745 call x_set_offset a second time
8746 if we get to x_make_frame_visible a second time
8747 before the window gets really visible. */
8748 if (! FRAME_ICONIFIED_P (f
)
8749 && ! f
->output_data
.x
->asked_for_visible
)
8750 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8752 f
->output_data
.x
->asked_for_visible
= 1;
8754 if (! EQ (Vx_no_window_manager
, Qt
))
8755 x_wm_set_window_state (f
, NormalState
);
8756 #ifdef USE_X_TOOLKIT
8757 /* This was XtPopup, but that did nothing for an iconified frame. */
8758 XtMapWidget (f
->output_data
.x
->widget
);
8759 #else /* not USE_X_TOOLKIT */
8761 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8762 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8764 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8765 #endif /* not USE_GTK */
8766 #endif /* not USE_X_TOOLKIT */
8767 #if 0 /* This seems to bring back scroll bars in the wrong places
8768 if the window configuration has changed. They seem
8769 to come back ok without this. */
8770 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8771 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8775 XFlush (FRAME_X_DISPLAY (f
));
8777 /* Synchronize to ensure Emacs knows the frame is visible
8778 before we do anything else. We do this loop with input not blocked
8779 so that incoming events are handled. */
8783 /* This must be before UNBLOCK_INPUT
8784 since events that arrive in response to the actions above
8785 will set it when they are handled. */
8786 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8788 original_left
= f
->left_pos
;
8789 original_top
= f
->top_pos
;
8791 /* This must come after we set COUNT. */
8794 /* We unblock here so that arriving X events are processed. */
8796 /* Now move the window back to where it was "supposed to be".
8797 But don't do it if the gravity is negative.
8798 When the gravity is negative, this uses a position
8799 that is 3 pixels too low. Perhaps that's really the border width.
8801 Don't do this if the window has never been visible before,
8802 because the window manager may choose the position
8803 and we don't want to override it. */
8805 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
8806 && f
->win_gravity
== NorthWestGravity
8807 && previously_visible
)
8811 unsigned int width
, height
, border
, depth
;
8815 /* On some window managers (such as FVWM) moving an existing
8816 window, even to the same place, causes the window manager
8817 to introduce an offset. This can cause the window to move
8818 to an unexpected location. Check the geometry (a little
8819 slow here) and then verify that the window is in the right
8820 place. If the window is not in the right place, move it
8821 there, and take the potential window manager hit. */
8822 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8823 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
8825 if (original_left
!= x
|| original_top
!= y
)
8826 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8827 original_left
, original_top
);
8832 XSETFRAME (frame
, f
);
8834 /* Wait until the frame is visible. Process X events until a
8835 MapNotify event has been seen, or until we think we won't get a
8836 MapNotify at all.. */
8837 for (count
= input_signal_count
+ 10;
8838 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
8840 /* Force processing of queued events. */
8843 /* Machines that do polling rather than SIGIO have been
8844 observed to go into a busy-wait here. So we'll fake an
8845 alarm signal to let the handler know that there's something
8846 to be read. We used to raise a real alarm, but it seems
8847 that the handler isn't always enabled here. This is
8849 if (input_polling_used ())
8851 /* It could be confusing if a real alarm arrives while
8852 processing the fake one. Turn it off and let the
8853 handler reset it. */
8854 extern void poll_for_input_1
P_ ((void));
8855 int old_poll_suppress_count
= poll_suppress_count
;
8856 poll_suppress_count
= 1;
8857 poll_for_input_1 ();
8858 poll_suppress_count
= old_poll_suppress_count
;
8861 /* See if a MapNotify event has been processed. */
8862 FRAME_SAMPLE_VISIBILITY (f
);
8867 (let ((f (selected-frame)))
8871 the frame is not raised with various window managers on
8872 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
8873 unknown reason, the call to XtMapWidget is completely ignored.
8874 Mapping the widget a second time works. */
8876 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
8881 /* Change from mapped state to withdrawn state. */
8883 /* Make the frame visible (mapped and not iconified). */
8886 x_make_frame_invisible (f
)
8891 /* Use the frame's outermost window, not the one we normally draw on. */
8892 window
= FRAME_OUTER_WINDOW (f
);
8894 /* Don't keep the highlight on an invisible frame. */
8895 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
8896 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
8898 #if 0/* This might add unreliability; I don't trust it -- rms. */
8899 if (! f
->async_visible
&& ! f
->async_iconified
)
8905 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
8906 that the current position of the window is user-specified, rather than
8907 program-specified, so that when the window is mapped again, it will be
8908 placed at the same location, without forcing the user to position it
8909 by hand again (they have already done that once for this window.) */
8910 x_wm_set_size_hint (f
, (long) 0, 1);
8913 if (FRAME_GTK_OUTER_WIDGET (f
))
8914 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
8920 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
8921 DefaultScreen (FRAME_X_DISPLAY (f
))))
8923 UNBLOCK_INPUT_RESIGNAL
;
8924 error ("Can't notify window manager of window withdrawal");
8926 #else /* ! defined (HAVE_X11R4) */
8928 /* Tell the window manager what we're going to do. */
8929 if (! EQ (Vx_no_window_manager
, Qt
))
8933 unmap
.xunmap
.type
= UnmapNotify
;
8934 unmap
.xunmap
.window
= window
;
8935 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
8936 unmap
.xunmap
.from_configure
= False
;
8937 if (! XSendEvent (FRAME_X_DISPLAY (f
),
8938 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
8940 SubstructureRedirectMaskSubstructureNotifyMask
,
8943 UNBLOCK_INPUT_RESIGNAL
;
8944 error ("Can't notify window manager of withdrawal");
8948 /* Unmap the window ourselves. Cheeky! */
8949 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
8950 #endif /* ! defined (HAVE_X11R4) */
8953 /* We can't distinguish this from iconification
8954 just by the event that we get from the server.
8955 So we can't win using the usual strategy of letting
8956 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
8957 and synchronize with the server to make sure we agree. */
8959 FRAME_ICONIFIED_P (f
) = 0;
8960 f
->async_visible
= 0;
8961 f
->async_iconified
= 0;
8968 /* Change window state from mapped to iconified. */
8977 /* Don't keep the highlight on an invisible frame. */
8978 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
8979 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
8981 if (f
->async_iconified
)
8986 FRAME_SAMPLE_VISIBILITY (f
);
8988 type
= x_icon_type (f
);
8990 x_bitmap_icon (f
, type
);
8993 if (FRAME_GTK_OUTER_WIDGET (f
))
8995 if (! FRAME_VISIBLE_P (f
))
8996 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8998 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9001 f
->async_iconified
= 1;
9002 f
->async_visible
= 0;
9008 #ifdef USE_X_TOOLKIT
9010 if (! FRAME_VISIBLE_P (f
))
9012 if (! EQ (Vx_no_window_manager
, Qt
))
9013 x_wm_set_window_state (f
, IconicState
);
9014 /* This was XtPopup, but that did nothing for an iconified frame. */
9015 XtMapWidget (f
->output_data
.x
->widget
);
9016 /* The server won't give us any event to indicate
9017 that an invisible frame was changed to an icon,
9018 so we have to record it here. */
9021 f
->async_iconified
= 1;
9022 f
->async_visible
= 0;
9027 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9028 XtWindow (f
->output_data
.x
->widget
),
9029 DefaultScreen (FRAME_X_DISPLAY (f
)));
9033 error ("Can't notify window manager of iconification");
9035 f
->async_iconified
= 1;
9036 f
->async_visible
= 0;
9040 XFlush (FRAME_X_DISPLAY (f
));
9042 #else /* not USE_X_TOOLKIT */
9044 /* Make sure the X server knows where the window should be positioned,
9045 in case the user deiconifies with the window manager. */
9046 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
9047 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9049 /* Since we don't know which revision of X we're running, we'll use both
9050 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9052 /* X11R4: send a ClientMessage to the window manager using the
9053 WM_CHANGE_STATE type. */
9057 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9058 message
.xclient
.type
= ClientMessage
;
9059 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9060 message
.xclient
.format
= 32;
9061 message
.xclient
.data
.l
[0] = IconicState
;
9063 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9064 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9066 SubstructureRedirectMask
| SubstructureNotifyMask
,
9069 UNBLOCK_INPUT_RESIGNAL
;
9070 error ("Can't notify window manager of iconification");
9074 /* X11R3: set the initial_state field of the window manager hints to
9076 x_wm_set_window_state (f
, IconicState
);
9078 if (!FRAME_VISIBLE_P (f
))
9080 /* If the frame was withdrawn, before, we must map it. */
9081 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9084 f
->async_iconified
= 1;
9085 f
->async_visible
= 0;
9087 XFlush (FRAME_X_DISPLAY (f
));
9089 #endif /* not USE_X_TOOLKIT */
9093 /* Free X resources of frame F. */
9096 x_free_frame_resources (f
)
9099 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9101 struct scroll_bar
*b
;
9105 /* If a display connection is dead, don't try sending more
9106 commands to the X server. */
9107 if (dpyinfo
->display
)
9109 if (f
->output_data
.x
->icon_desc
)
9110 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9112 #ifdef USE_X_TOOLKIT
9113 /* Explicitly destroy the scroll bars of the frame. Without
9114 this, we get "BadDrawable" errors from the toolkit later on,
9115 presumably from expose events generated for the disappearing
9116 toolkit scroll bars. */
9117 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9119 b
= XSCROLL_BAR (bar
);
9120 x_scroll_bar_remove (b
);
9129 #ifdef USE_X_TOOLKIT
9130 if (f
->output_data
.x
->widget
)
9132 XtDestroyWidget (f
->output_data
.x
->widget
);
9133 f
->output_data
.x
->widget
= NULL
;
9135 /* Tooltips don't have widgets, only a simple X window, even if
9136 we are using a toolkit. */
9137 else if (FRAME_X_WINDOW (f
))
9138 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9140 free_frame_menubar (f
);
9141 #else /* !USE_X_TOOLKIT */
9144 /* In the GTK version, tooltips are normal X
9145 frames. We must check and free both types. */
9146 if (FRAME_GTK_OUTER_WIDGET (f
))
9148 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9149 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9150 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9152 #endif /* USE_GTK */
9154 if (FRAME_X_WINDOW (f
))
9155 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9156 #endif /* !USE_X_TOOLKIT */
9158 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
9159 unload_color (f
, f
->output_data
.x
->background_pixel
);
9160 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9161 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9162 unload_color (f
, f
->output_data
.x
->border_pixel
);
9163 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9165 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9166 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9167 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9168 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9169 #ifdef USE_TOOLKIT_SCROLL_BARS
9170 /* Scrollbar shadow colors. */
9171 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9172 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9173 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9174 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9175 #endif /* USE_TOOLKIT_SCROLL_BARS */
9176 if (f
->output_data
.x
->white_relief
.allocated_p
)
9177 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9178 if (f
->output_data
.x
->black_relief
.allocated_p
)
9179 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9181 if (FRAME_FACE_CACHE (f
))
9182 free_frame_faces (f
);
9185 XFlush (FRAME_X_DISPLAY (f
));
9188 if (f
->output_data
.x
->saved_menu_event
)
9189 xfree (f
->output_data
.x
->saved_menu_event
);
9191 xfree (f
->output_data
.x
);
9192 f
->output_data
.x
= NULL
;
9194 if (f
== dpyinfo
->x_focus_frame
)
9195 dpyinfo
->x_focus_frame
= 0;
9196 if (f
== dpyinfo
->x_focus_event_frame
)
9197 dpyinfo
->x_focus_event_frame
= 0;
9198 if (f
== dpyinfo
->x_highlight_frame
)
9199 dpyinfo
->x_highlight_frame
= 0;
9201 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9203 dpyinfo
->mouse_face_beg_row
9204 = dpyinfo
->mouse_face_beg_col
= -1;
9205 dpyinfo
->mouse_face_end_row
9206 = dpyinfo
->mouse_face_end_col
= -1;
9207 dpyinfo
->mouse_face_window
= Qnil
;
9208 dpyinfo
->mouse_face_deferred_gc
= 0;
9209 dpyinfo
->mouse_face_mouse_frame
= 0;
9216 /* Destroy the X window of frame F. */
9219 x_destroy_window (f
)
9222 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9224 /* If a display connection is dead, don't try sending more
9225 commands to the X server. */
9226 if (dpyinfo
->display
!= 0)
9227 x_free_frame_resources (f
);
9229 dpyinfo
->reference_count
--;
9233 /* Setting window manager hints. */
9235 /* Set the normal size hints for the window manager, for frame F.
9236 FLAGS is the flags word to use--or 0 meaning preserve the flags
9237 that the window now has.
9238 If USER_POSITION is nonzero, we set the USPosition
9239 flag (this is useful when FLAGS is 0).
9240 The GTK version is in gtkutils.c */
9244 x_wm_set_size_hint (f
, flags
, user_position
)
9249 XSizeHints size_hints
;
9251 #ifdef USE_X_TOOLKIT
9254 Dimension widget_width
, widget_height
;
9257 Window window
= FRAME_OUTER_WINDOW (f
);
9259 /* Setting PMaxSize caused various problems. */
9260 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9262 size_hints
.x
= f
->left_pos
;
9263 size_hints
.y
= f
->top_pos
;
9265 #ifdef USE_X_TOOLKIT
9266 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9267 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9268 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9269 size_hints
.height
= widget_height
;
9270 size_hints
.width
= widget_width
;
9271 #else /* not USE_X_TOOLKIT */
9272 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9273 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9274 #endif /* not USE_X_TOOLKIT */
9276 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9277 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9278 size_hints
.max_width
9279 = FRAME_X_DISPLAY_INFO (f
)->width
- FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9280 size_hints
.max_height
9281 = FRAME_X_DISPLAY_INFO (f
)->height
- FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9283 /* Calculate the base and minimum sizes.
9285 (When we use the X toolkit, we don't do it here.
9286 Instead we copy the values that the widgets are using, below.) */
9287 #ifndef USE_X_TOOLKIT
9289 int base_width
, base_height
;
9290 int min_rows
= 0, min_cols
= 0;
9292 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9293 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9295 check_frame_size (f
, &min_rows
, &min_cols
);
9297 /* The window manager uses the base width hints to calculate the
9298 current number of rows and columns in the frame while
9299 resizing; min_width and min_height aren't useful for this
9300 purpose, since they might not give the dimensions for a
9301 zero-row, zero-column frame.
9303 We use the base_width and base_height members if we have
9304 them; otherwise, we set the min_width and min_height members
9305 to the size for a zero x zero frame. */
9308 size_hints
.flags
|= PBaseSize
;
9309 size_hints
.base_width
= base_width
;
9310 size_hints
.base_height
= base_height
;
9311 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9312 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9314 size_hints
.min_width
= base_width
;
9315 size_hints
.min_height
= base_height
;
9319 /* If we don't need the old flags, we don't need the old hint at all. */
9322 size_hints
.flags
|= flags
;
9325 #endif /* not USE_X_TOOLKIT */
9328 XSizeHints hints
; /* Sometimes I hate X Windows... */
9329 long supplied_return
;
9333 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9336 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
9339 #ifdef USE_X_TOOLKIT
9340 size_hints
.base_height
= hints
.base_height
;
9341 size_hints
.base_width
= hints
.base_width
;
9342 size_hints
.min_height
= hints
.min_height
;
9343 size_hints
.min_width
= hints
.min_width
;
9347 size_hints
.flags
|= flags
;
9352 if (hints
.flags
& PSize
)
9353 size_hints
.flags
|= PSize
;
9354 if (hints
.flags
& PPosition
)
9355 size_hints
.flags
|= PPosition
;
9356 if (hints
.flags
& USPosition
)
9357 size_hints
.flags
|= USPosition
;
9358 if (hints
.flags
& USSize
)
9359 size_hints
.flags
|= USSize
;
9363 #ifndef USE_X_TOOLKIT
9368 size_hints
.win_gravity
= f
->win_gravity
;
9369 size_hints
.flags
|= PWinGravity
;
9373 size_hints
.flags
&= ~ PPosition
;
9374 size_hints
.flags
|= USPosition
;
9376 #endif /* PWinGravity */
9379 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9381 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9384 #endif /* not USE_GTK */
9386 /* Used for IconicState or NormalState */
9389 x_wm_set_window_state (f
, state
)
9393 #ifdef USE_X_TOOLKIT
9396 XtSetArg (al
[0], XtNinitialState
, state
);
9397 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9398 #else /* not USE_X_TOOLKIT */
9399 Window window
= FRAME_X_WINDOW (f
);
9401 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9402 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9404 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9405 #endif /* not USE_X_TOOLKIT */
9409 x_wm_set_icon_pixmap (f
, pixmap_id
)
9413 Pixmap icon_pixmap
, icon_mask
;
9415 #ifndef USE_X_TOOLKIT
9416 Window window
= FRAME_OUTER_WINDOW (f
);
9421 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9422 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9423 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9424 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9428 /* It seems there is no way to turn off use of an icon pixmap.
9429 The following line does it, only if no icon has yet been created,
9430 for some window managers. But with mwm it crashes.
9431 Some people say it should clear the IconPixmapHint bit in this case,
9432 but that doesn't work, and the X consortium said it isn't the
9433 right thing at all. Since there is no way to win,
9434 best to explicitly give up. */
9436 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
9437 f
->output_data
.x
->wm_hints
.icon_mask
= None
;
9443 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
9447 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9448 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9449 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9450 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9453 #else /* not USE_X_TOOLKIT */
9455 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9456 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9458 #endif /* not USE_X_TOOLKIT */
9462 x_wm_set_icon_position (f
, icon_x
, icon_y
)
9466 Window window
= FRAME_OUTER_WINDOW (f
);
9468 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9469 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9470 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9472 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9476 /***********************************************************************
9478 ***********************************************************************/
9480 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
9483 x_get_font_info (f
, font_idx
)
9487 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
9491 /* Return a list of names of available fonts matching PATTERN on frame F.
9493 If SIZE is > 0, it is the size (maximum bounds width) of fonts
9496 SIZE < 0 means include scalable fonts.
9498 Frame F null means we have not yet created any frame on X, and
9499 consult the first display in x_display_list. MAXNAMES sets a limit
9500 on how many fonts to match. */
9503 x_list_fonts (f
, pattern
, size
, maxnames
)
9505 Lisp_Object pattern
;
9509 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
9510 Lisp_Object tem
, second_best
;
9511 struct x_display_info
*dpyinfo
9512 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
9513 Display
*dpy
= dpyinfo
->display
;
9514 int try_XLoadQueryFont
= 0;
9516 int allow_auto_scaled_font
= 0;
9520 allow_auto_scaled_font
= 1;
9524 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
9525 if (NILP (patterns
))
9526 patterns
= Fcons (pattern
, Qnil
);
9528 if (maxnames
== 1 && !size
)
9529 /* We can return any single font matching PATTERN. */
9530 try_XLoadQueryFont
= 1;
9532 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
9535 char **names
= NULL
;
9537 pattern
= XCAR (patterns
);
9538 /* See if we cached the result for this particular query.
9539 The cache is an alist of the form:
9540 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
9541 tem
= XCDR (dpyinfo
->name_list_element
);
9542 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
9543 allow_auto_scaled_font
? Qt
: Qnil
);
9544 list
= Fassoc (key
, tem
);
9547 list
= Fcdr_safe (list
);
9548 /* We have a cashed list. Don't have to get the list again. */
9552 /* At first, put PATTERN in the cache. */
9555 count
= x_catch_errors (dpy
);
9557 if (try_XLoadQueryFont
)
9560 unsigned long value
;
9562 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
9563 if (x_had_errors_p (dpy
))
9565 /* This error is perhaps due to insufficient memory on X
9566 server. Let's just ignore it. */
9568 x_clear_errors (dpy
);
9572 && XGetFontProperty (font
, XA_FONT
, &value
))
9574 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
9575 int len
= strlen (name
);
9578 /* If DXPC (a Differential X Protocol Compressor)
9579 Ver.3.7 is running, XGetAtomName will return null
9580 string. We must avoid such a name. */
9582 try_XLoadQueryFont
= 0;
9586 names
= (char **) alloca (sizeof (char *));
9587 /* Some systems only allow alloca assigned to a
9589 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
9590 bcopy (name
, names
[0], len
+ 1);
9595 try_XLoadQueryFont
= 0;
9598 XFreeFont (dpy
, font
);
9601 if (!try_XLoadQueryFont
)
9603 /* We try at least 10 fonts because XListFonts will return
9604 auto-scaled fonts at the head. */
9611 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
9612 if (num_fonts
== limit
)
9615 XFreeFontNames (names
);
9624 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
9627 if (x_had_errors_p (dpy
))
9629 /* This error is perhaps due to insufficient memory on X
9630 server. Let's just ignore it. */
9632 x_clear_errors (dpy
);
9636 x_uncatch_errors (dpy
, count
);
9643 /* Make a list of all the fonts we got back.
9644 Store that in the font cache for the display. */
9645 for (i
= 0; i
< num_fonts
; i
++)
9649 int average_width
= -1, resx
= 0, dashes
= 0;
9651 /* Count the number of dashes in NAMES[I]. If there are
9652 14 dashes, the field value following 9th dash
9653 (RESOLUTION_X) is nonzero, and the field value
9654 following 12th dash (AVERAGE_WIDTH) is 0, this is a
9655 auto-scaled font which is usually too ugly to be used
9656 for editing. Let's ignore it. */
9661 if (dashes
== 7) /* PIXEL_SIZE field */
9663 else if (dashes
== 9)
9665 else if (dashes
== 12) /* AVERAGE_WIDTH field */
9666 average_width
= atoi (p
);
9669 if (allow_auto_scaled_font
9670 || dashes
< 14 || average_width
!= 0 || resx
== 0)
9672 tem
= build_string (names
[i
]);
9673 if (NILP (Fassoc (tem
, list
)))
9675 if (STRINGP (Vx_pixel_size_width_font_regexp
)
9676 && ((fast_c_string_match_ignore_case
9677 (Vx_pixel_size_width_font_regexp
, names
[i
]))
9679 /* We can set the value of PIXEL_SIZE to the
9680 width of this font. */
9681 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
9683 /* For the moment, width is not known. */
9684 list
= Fcons (Fcons (tem
, Qnil
), list
);
9689 if (!try_XLoadQueryFont
)
9692 XFreeFontNames (names
);
9697 /* Now store the result in the cache. */
9698 XSETCDR (dpyinfo
->name_list_element
,
9699 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
9702 if (NILP (list
)) continue; /* Try the remaining alternatives. */
9704 newlist
= second_best
= Qnil
;
9705 /* Make a list of the fonts that have the right width. */
9706 for (; CONSP (list
); list
= XCDR (list
))
9712 if (!CONSP (tem
) || NILP (XCAR (tem
)))
9716 newlist
= Fcons (XCAR (tem
), newlist
);
9720 if (!INTEGERP (XCDR (tem
)))
9722 /* Since we have not yet known the size of this font, we
9723 must try slow function call XLoadQueryFont. */
9724 XFontStruct
*thisinfo
;
9727 count
= x_catch_errors (dpy
);
9728 thisinfo
= XLoadQueryFont (dpy
,
9729 SDATA (XCAR (tem
)));
9730 if (x_had_errors_p (dpy
))
9732 /* This error is perhaps due to insufficient memory on X
9733 server. Let's just ignore it. */
9735 x_clear_errors (dpy
);
9737 x_uncatch_errors (dpy
, count
);
9743 (thisinfo
->min_bounds
.width
== 0
9745 : make_number (thisinfo
->max_bounds
.width
)));
9747 XFreeFont (dpy
, thisinfo
);
9751 /* For unknown reason, the previous call of XListFont had
9752 returned a font which can't be opened. Record the size
9753 as 0 not to try to open it again. */
9754 XSETCDR (tem
, make_number (0));
9757 found_size
= XINT (XCDR (tem
));
9758 if (found_size
== size
)
9759 newlist
= Fcons (XCAR (tem
), newlist
);
9760 else if (found_size
> 0)
9762 if (NILP (second_best
))
9764 else if (found_size
< size
)
9766 if (XINT (XCDR (second_best
)) > size
9767 || XINT (XCDR (second_best
)) < found_size
)
9772 if (XINT (XCDR (second_best
)) > size
9773 && XINT (XCDR (second_best
)) > found_size
)
9778 if (!NILP (newlist
))
9780 else if (!NILP (second_best
))
9782 newlist
= Fcons (XCAR (second_best
), Qnil
);
9793 /* Check that FONT is valid on frame F. It is if it can be found in F's
9797 x_check_font (f
, font
)
9802 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9804 xassert (font
!= NULL
);
9806 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9807 if (dpyinfo
->font_table
[i
].name
9808 && font
== dpyinfo
->font_table
[i
].font
)
9811 xassert (i
< dpyinfo
->n_fonts
);
9814 #endif /* GLYPH_DEBUG != 0 */
9816 /* Set *W to the minimum width, *H to the minimum font height of FONT.
9817 Note: There are (broken) X fonts out there with invalid XFontStruct
9818 min_bounds contents. For example, handa@etl.go.jp reports that
9819 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
9820 have font->min_bounds.width == 0. */
9823 x_font_min_bounds (font
, w
, h
)
9827 *h
= FONT_HEIGHT (font
);
9828 *w
= font
->min_bounds
.width
;
9830 /* Try to handle the case where FONT->min_bounds has invalid
9831 contents. Since the only font known to have invalid min_bounds
9832 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
9834 *w
= font
->max_bounds
.width
;
9838 /* Compute the smallest character width and smallest font height over
9839 all fonts available on frame F. Set the members smallest_char_width
9840 and smallest_font_height in F's x_display_info structure to
9841 the values computed. Value is non-zero if smallest_font_height or
9842 smallest_char_width become smaller than they were before. */
9845 x_compute_min_glyph_bounds (f
)
9849 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9851 int old_width
= dpyinfo
->smallest_char_width
;
9852 int old_height
= dpyinfo
->smallest_font_height
;
9854 dpyinfo
->smallest_font_height
= 100000;
9855 dpyinfo
->smallest_char_width
= 100000;
9857 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
9858 if (dpyinfo
->font_table
[i
].name
)
9860 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
9863 font
= (XFontStruct
*) fontp
->font
;
9864 xassert (font
!= (XFontStruct
*) ~0);
9865 x_font_min_bounds (font
, &w
, &h
);
9867 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
9868 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
9871 xassert (dpyinfo
->smallest_char_width
> 0
9872 && dpyinfo
->smallest_font_height
> 0);
9874 return (dpyinfo
->n_fonts
== 1
9875 || dpyinfo
->smallest_char_width
< old_width
9876 || dpyinfo
->smallest_font_height
< old_height
);
9880 /* Load font named FONTNAME of the size SIZE for frame F, and return a
9881 pointer to the structure font_info while allocating it dynamically.
9882 If SIZE is 0, load any size of font.
9883 If loading is failed, return NULL. */
9886 x_load_font (f
, fontname
, size
)
9888 register char *fontname
;
9891 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9892 Lisp_Object font_names
;
9895 /* Get a list of all the fonts that match this name. Once we
9896 have a list of matching fonts, we compare them against the fonts
9897 we already have by comparing names. */
9898 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
9900 if (!NILP (font_names
))
9905 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9906 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
9907 if (dpyinfo
->font_table
[i
].name
9908 && (!strcmp (dpyinfo
->font_table
[i
].name
,
9909 SDATA (XCAR (tail
)))
9910 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
9911 SDATA (XCAR (tail
)))))
9912 return (dpyinfo
->font_table
+ i
);
9915 /* Load the font and add it to the table. */
9919 struct font_info
*fontp
;
9920 unsigned long value
;
9923 /* If we have found fonts by x_list_font, load one of them. If
9924 not, we still try to load a font by the name given as FONTNAME
9925 because XListFonts (called in x_list_font) of some X server has
9926 a bug of not finding a font even if the font surely exists and
9927 is loadable by XLoadQueryFont. */
9928 if (size
> 0 && !NILP (font_names
))
9929 fontname
= (char *) SDATA (XCAR (font_names
));
9932 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
9933 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
9934 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
9936 /* This error is perhaps due to insufficient memory on X
9937 server. Let's just ignore it. */
9939 x_clear_errors (FRAME_X_DISPLAY (f
));
9941 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
9946 /* Find a free slot in the font table. */
9947 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
9948 if (dpyinfo
->font_table
[i
].name
== NULL
)
9951 /* If no free slot found, maybe enlarge the font table. */
9952 if (i
== dpyinfo
->n_fonts
9953 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
9956 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
9957 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
9959 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
9962 fontp
= dpyinfo
->font_table
+ i
;
9963 if (i
== dpyinfo
->n_fonts
)
9966 /* Now fill in the slots of *FONTP. */
9968 bzero (fontp
, sizeof (*fontp
));
9970 fontp
->font_idx
= i
;
9971 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
9972 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
9974 /* Try to get the full name of FONT. Put it in FULL_NAME. */
9976 if (XGetFontProperty (font
, XA_FONT
, &value
))
9978 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
9982 /* Count the number of dashes in the "full name".
9983 If it is too few, this isn't really the font's full name,
9985 In X11R4, the fonts did not come with their canonical names
9996 full_name
= (char *) xmalloc (p
- name
+ 1);
9997 bcopy (name
, full_name
, p
- name
+ 1);
10003 if (full_name
!= 0)
10004 fontp
->full_name
= full_name
;
10006 fontp
->full_name
= fontp
->name
;
10008 fontp
->size
= font
->max_bounds
.width
;
10009 fontp
->height
= FONT_HEIGHT (font
);
10011 if (NILP (font_names
))
10013 /* We come here because of a bug of XListFonts mentioned at
10014 the head of this block. Let's store this information in
10015 the cache for x_list_fonts. */
10016 Lisp_Object lispy_name
= build_string (fontname
);
10017 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
10018 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
10021 XSETCDR (dpyinfo
->name_list_element
,
10023 Fcons (Fcons (lispy_full_name
,
10024 make_number (fontp
->size
)),
10026 XCDR (dpyinfo
->name_list_element
)));
10029 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
10031 XSETCDR (dpyinfo
->name_list_element
,
10033 Fcons (Fcons (lispy_full_name
,
10034 make_number (fontp
->size
)),
10036 XCDR (dpyinfo
->name_list_element
)));
10040 /* The slot `encoding' specifies how to map a character
10041 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
10042 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
10043 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
10044 2:0xA020..0xFF7F). For the moment, we don't know which charset
10045 uses this font. So, we set information in fontp->encoding[1]
10046 which is never used by any charset. If mapping can't be
10047 decided, set FONT_ENCODING_NOT_DECIDED. */
10049 = (font
->max_byte1
== 0
10051 ? (font
->min_char_or_byte2
< 0x80
10052 ? (font
->max_char_or_byte2
< 0x80
10053 ? 0 /* 0x20..0x7F */
10054 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
10055 : 1) /* 0xA0..0xFF */
10057 : (font
->min_byte1
< 0x80
10058 ? (font
->max_byte1
< 0x80
10059 ? (font
->min_char_or_byte2
< 0x80
10060 ? (font
->max_char_or_byte2
< 0x80
10061 ? 0 /* 0x2020..0x7F7F */
10062 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
10063 : 3) /* 0x20A0..0x7FFF */
10064 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
10065 : (font
->min_char_or_byte2
< 0x80
10066 ? (font
->max_char_or_byte2
< 0x80
10067 ? 2 /* 0xA020..0xFF7F */
10068 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
10069 : 1))); /* 0xA0A0..0xFFFF */
10071 fontp
->baseline_offset
10072 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
10073 ? (long) value
: 0);
10074 fontp
->relative_compose
10075 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
10076 ? (long) value
: 0);
10077 fontp
->default_ascent
10078 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
10079 ? (long) value
: 0);
10081 /* Set global flag fonts_changed_p to non-zero if the font loaded
10082 has a character with a smaller width than any other character
10083 before, or if the font loaded has a smaller height than any
10084 other font loaded before. If this happens, it will make a
10085 glyph matrix reallocation necessary. */
10086 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
10093 /* Return a pointer to struct font_info of a font named FONTNAME for
10094 frame F. If no such font is loaded, return NULL. */
10097 x_query_font (f
, fontname
)
10099 register char *fontname
;
10101 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10104 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10105 if (dpyinfo
->font_table
[i
].name
10106 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
10107 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
10108 return (dpyinfo
->font_table
+ i
);
10113 /* Find a CCL program for a font specified by FONTP, and set the member
10114 `encoder' of the structure. */
10117 x_find_ccl_program (fontp
)
10118 struct font_info
*fontp
;
10120 Lisp_Object list
, elt
;
10123 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
10127 && STRINGP (XCAR (elt
))
10128 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
10130 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
10137 struct ccl_program
*ccl
10138 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
10140 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
10143 fontp
->font_encoder
= ccl
;
10149 /***********************************************************************
10151 ***********************************************************************/
10153 #ifdef USE_X_TOOLKIT
10154 static XrmOptionDescRec emacs_options
[] = {
10155 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
10156 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
10158 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
10159 XrmoptionSepArg
, NULL
},
10160 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
10162 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10163 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10164 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10165 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10166 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10167 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
10168 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
10170 #endif /* USE_X_TOOLKIT */
10172 static int x_initialized
;
10174 #ifdef MULTI_KBOARD
10175 /* Test whether two display-name strings agree up to the dot that separates
10176 the screen number from the server number. */
10178 same_x_server (name1
, name2
)
10179 const char *name1
, *name2
;
10181 int seen_colon
= 0;
10182 const unsigned char *system_name
= SDATA (Vsystem_name
);
10183 int system_name_length
= strlen (system_name
);
10184 int length_until_period
= 0;
10186 while (system_name
[length_until_period
] != 0
10187 && system_name
[length_until_period
] != '.')
10188 length_until_period
++;
10190 /* Treat `unix' like an empty host name. */
10191 if (! strncmp (name1
, "unix:", 5))
10193 if (! strncmp (name2
, "unix:", 5))
10195 /* Treat this host's name like an empty host name. */
10196 if (! strncmp (name1
, system_name
, system_name_length
)
10197 && name1
[system_name_length
] == ':')
10198 name1
+= system_name_length
;
10199 if (! strncmp (name2
, system_name
, system_name_length
)
10200 && name2
[system_name_length
] == ':')
10201 name2
+= system_name_length
;
10202 /* Treat this host's domainless name like an empty host name. */
10203 if (! strncmp (name1
, system_name
, length_until_period
)
10204 && name1
[length_until_period
] == ':')
10205 name1
+= length_until_period
;
10206 if (! strncmp (name2
, system_name
, length_until_period
)
10207 && name2
[length_until_period
] == ':')
10208 name2
+= length_until_period
;
10210 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
10214 if (seen_colon
&& *name1
== '.')
10218 && (*name1
== '.' || *name1
== '\0')
10219 && (*name2
== '.' || *name2
== '\0'));
10223 /* Count number of set bits in mask and number of bits to shift to
10224 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
10227 get_bits_and_offset (mask
, bits
, offset
)
10228 unsigned long mask
;
10235 while (!(mask
& 1))
10251 struct x_display_info
*
10252 x_term_init (display_name
, xrm_option
, resource_name
)
10253 Lisp_Object display_name
;
10255 char *resource_name
;
10259 struct display
*display
;
10260 struct x_display_info
*dpyinfo
;
10265 if (!x_initialized
)
10273 #define NUM_ARGV 10
10275 char *argv
[NUM_ARGV
];
10276 char **argv2
= argv
;
10279 if (x_initialized
++ > 1)
10281 /* Opening another display. If xg_display_open returns less
10282 than zero, we are probably on GTK 2.0, which can only handle
10283 one display. GTK 2.2 or later can handle more than one. */
10284 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
10285 error ("Sorry, this version of GTK can only handle one display");
10289 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
10293 argv
[argc
++] = initial_argv
[0];
10295 if (! NILP (display_name
))
10297 argv
[argc
++] = "--display";
10298 argv
[argc
++] = SDATA (display_name
);
10301 argv
[argc
++] = "--name";
10302 argv
[argc
++] = resource_name
;
10305 XSetLocaleModifiers ("");
10308 gtk_init (&argc
, &argv2
);
10310 /* gtk_init does set_locale. We must fix locale after calling it. */
10314 dpy
= GDK_DISPLAY ();
10316 /* NULL window -> events for all windows go to our function */
10317 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10319 /* Load our own gtkrc if it exists. */
10321 struct gcpro gcpro1
, gcpro2
;
10322 char *file
= "~/.emacs.d/gtkrc";
10323 Lisp_Object s
, abs_file
;
10325 GCPRO2 (s
, abs_file
);
10326 s
= make_string (file
, strlen (file
));
10327 abs_file
= Fexpand_file_name (s
, Qnil
);
10329 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10330 gtk_rc_parse (SDATA (abs_file
));
10335 XSetErrorHandler (x_error_handler
);
10336 XSetIOErrorHandler (x_io_error_quitter
);
10339 #else /* not USE_GTK */
10340 #ifdef USE_X_TOOLKIT
10341 /* weiner@footloose.sps.mot.com reports that this causes
10343 X protocol error: BadAtom (invalid Atom parameter)
10344 on protocol request 18skiloaf.
10345 So let's not use it until R6. */
10346 #ifdef HAVE_X11XTR6
10347 XtSetLanguageProc (NULL
, NULL
, NULL
);
10358 argv
[argc
++] = "-xrm";
10359 argv
[argc
++] = xrm_option
;
10361 turn_on_atimers (0);
10362 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
10363 resource_name
, EMACS_CLASS
,
10364 emacs_options
, XtNumber (emacs_options
),
10366 turn_on_atimers (1);
10368 #ifdef HAVE_X11XTR6
10369 /* I think this is to compensate for XtSetLanguageProc. */
10374 #else /* not USE_X_TOOLKIT */
10376 XSetLocaleModifiers ("");
10378 dpy
= XOpenDisplay (SDATA (display_name
));
10379 #endif /* not USE_X_TOOLKIT */
10380 #endif /* not USE_GTK*/
10382 /* Detect failure. */
10389 /* We have definitely succeeded. Record the new connection. */
10391 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
10392 bzero (dpyinfo
, sizeof *dpyinfo
);
10394 display
= x_create_frame_display (dpyinfo
);
10396 #ifdef MULTI_KBOARD
10398 struct x_display_info
*share
;
10401 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10402 share
= share
->next
, tail
= XCDR (tail
))
10403 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
10404 SDATA (display_name
)))
10407 dpyinfo
->kboard
= share
->kboard
;
10410 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
10411 init_kboard (dpyinfo
->kboard
);
10412 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10414 char *vendor
= ServerVendor (dpy
);
10416 dpyinfo
->kboard
->Vsystem_key_alist
10417 = call1 (Qvendor_specific_keysyms
,
10418 build_string (vendor
? vendor
: ""));
10422 dpyinfo
->kboard
->next_kboard
= all_kboards
;
10423 all_kboards
= dpyinfo
->kboard
;
10424 /* Don't let the initial kboard remain current longer than necessary.
10425 That would cause problems if a file loaded on startup tries to
10426 prompt in the mini-buffer. */
10427 if (current_kboard
== initial_kboard
)
10428 current_kboard
= dpyinfo
->kboard
;
10430 dpyinfo
->kboard
->reference_count
++;
10434 /* Put this display on the chain. */
10435 dpyinfo
->next
= x_display_list
;
10436 x_display_list
= dpyinfo
;
10438 /* Put it on x_display_name_list as well, to keep them parallel. */
10439 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10440 x_display_name_list
);
10441 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10443 dpyinfo
->display
= dpy
;
10446 XSetAfterFunction (x_current_display
, x_trace_wire
);
10450 = (char *) xmalloc (SBYTES (Vinvocation_name
)
10451 + SBYTES (Vsystem_name
)
10453 sprintf (dpyinfo
->x_id_name
, "%s@%s",
10454 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10456 /* Figure out which modifier bits mean what. */
10457 x_find_modifier_meanings (dpyinfo
);
10459 /* Get the scroll bar cursor. */
10461 /* We must create a GTK cursor, it is required for GTK widgets. */
10462 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10463 #endif /* USE_GTK */
10465 dpyinfo
->vertical_scroll_bar_cursor
10466 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10468 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10469 resource_name
, EMACS_CLASS
);
10470 #ifdef HAVE_XRMSETDATABASE
10471 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10473 dpyinfo
->display
->db
= xrdb
;
10475 /* Put the rdb where we can find it in a way that works on
10477 dpyinfo
->xrdb
= xrdb
;
10479 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10480 DefaultScreen (dpyinfo
->display
));
10481 select_visual (dpyinfo
);
10482 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10483 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
10484 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
10485 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10486 dpyinfo
->client_leader_window
= 0;
10487 dpyinfo
->grabbed
= 0;
10488 dpyinfo
->reference_count
= 0;
10489 dpyinfo
->icon_bitmap_id
= -1;
10490 dpyinfo
->font_table
= NULL
;
10491 dpyinfo
->n_fonts
= 0;
10492 dpyinfo
->font_table_size
= 0;
10493 dpyinfo
->bitmaps
= 0;
10494 dpyinfo
->bitmaps_size
= 0;
10495 dpyinfo
->bitmaps_last
= 0;
10496 dpyinfo
->scratch_cursor_gc
= 0;
10497 dpyinfo
->mouse_face_mouse_frame
= 0;
10498 dpyinfo
->mouse_face_deferred_gc
= 0;
10499 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10500 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10501 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10502 dpyinfo
->mouse_face_window
= Qnil
;
10503 dpyinfo
->mouse_face_overlay
= Qnil
;
10504 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
10505 dpyinfo
->mouse_face_defer
= 0;
10506 dpyinfo
->mouse_face_hidden
= 0;
10507 dpyinfo
->x_focus_frame
= 0;
10508 dpyinfo
->x_focus_event_frame
= 0;
10509 dpyinfo
->x_highlight_frame
= 0;
10510 dpyinfo
->image_cache
= make_image_cache ();
10511 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10513 /* See if we can construct pixel values from RGB values. */
10514 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
10515 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
10517 if (dpyinfo
->visual
->class == TrueColor
)
10519 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10520 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10521 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10522 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10523 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10524 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10527 /* See if a private colormap is requested. */
10528 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10530 if (dpyinfo
->visual
->class == PseudoColor
)
10533 value
= display_x_get_resource (dpyinfo
,
10534 build_string ("privateColormap"),
10535 build_string ("PrivateColormap"),
10537 if (STRINGP (value
)
10538 && (!strcmp (SDATA (value
), "true")
10539 || !strcmp (SDATA (value
), "on")))
10540 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10544 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10545 dpyinfo
->visual
, AllocNone
);
10548 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10549 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10550 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10551 dpyinfo
->resy
= pixels
* 25.4 / mm
;
10552 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10553 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10554 dpyinfo
->resx
= pixels
* 25.4 / mm
;
10557 dpyinfo
->Xatom_wm_protocols
10558 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10559 dpyinfo
->Xatom_wm_take_focus
10560 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10561 dpyinfo
->Xatom_wm_save_yourself
10562 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10563 dpyinfo
->Xatom_wm_delete_window
10564 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10565 dpyinfo
->Xatom_wm_change_state
10566 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10567 dpyinfo
->Xatom_wm_configure_denied
10568 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10569 dpyinfo
->Xatom_wm_window_moved
10570 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10571 dpyinfo
->Xatom_wm_client_leader
10572 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10573 dpyinfo
->Xatom_editres
10574 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10575 dpyinfo
->Xatom_CLIPBOARD
10576 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10577 dpyinfo
->Xatom_TIMESTAMP
10578 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10579 dpyinfo
->Xatom_TEXT
10580 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10581 dpyinfo
->Xatom_COMPOUND_TEXT
10582 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10583 dpyinfo
->Xatom_UTF8_STRING
10584 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10585 dpyinfo
->Xatom_DELETE
10586 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10587 dpyinfo
->Xatom_MULTIPLE
10588 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10589 dpyinfo
->Xatom_INCR
10590 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10591 dpyinfo
->Xatom_EMACS_TMP
10592 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10593 dpyinfo
->Xatom_TARGETS
10594 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10595 dpyinfo
->Xatom_NULL
10596 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10597 dpyinfo
->Xatom_ATOM_PAIR
10598 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10599 /* For properties of font. */
10600 dpyinfo
->Xatom_PIXEL_SIZE
10601 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10602 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10603 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10604 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10605 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10606 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10607 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10609 /* Ghostscript support. */
10610 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10611 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10613 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10616 dpyinfo
->cut_buffers_initialized
= 0;
10618 connection
= ConnectionNumber (dpyinfo
->display
);
10619 dpyinfo
->connection
= connection
;
10624 null_bits
[0] = 0x00;
10626 dpyinfo
->null_pixel
10627 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10628 null_bits
, 1, 1, (long) 0, (long) 0,
10633 extern int gray_bitmap_width
, gray_bitmap_height
;
10634 extern char *gray_bitmap_bits
;
10636 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10638 gray_bitmap_width
, gray_bitmap_height
,
10639 (unsigned long) 1, (unsigned long) 0, 1);
10643 xim_initialize (dpyinfo
, resource_name
);
10646 #ifdef subprocesses
10647 /* This is only needed for distinguishing keyboard and process input. */
10648 if (connection
!= 0)
10649 add_keyboard_wait_descriptor (connection
);
10652 #ifndef F_SETOWN_BUG
10654 #ifdef F_SETOWN_SOCK_NEG
10655 /* stdin is a socket here */
10656 fcntl (connection
, F_SETOWN
, -getpid ());
10657 #else /* ! defined (F_SETOWN_SOCK_NEG) */
10658 fcntl (connection
, F_SETOWN
, getpid ());
10659 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
10660 #endif /* ! defined (F_SETOWN) */
10661 #endif /* F_SETOWN_BUG */
10664 if (interrupt_input
)
10665 init_sigio (connection
);
10666 #endif /* ! defined (SIGIO) */
10669 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
10670 /* Make sure that we have a valid font for dialog boxes
10671 so that Xt does not crash. */
10673 Display
*dpy
= dpyinfo
->display
;
10674 XrmValue d
, fr
, to
;
10678 d
.addr
= (XPointer
)&dpy
;
10679 d
.size
= sizeof (Display
*);
10680 fr
.addr
= XtDefaultFont
;
10681 fr
.size
= sizeof (XtDefaultFont
);
10682 to
.size
= sizeof (Font
*);
10683 to
.addr
= (XPointer
)&font
;
10684 count
= x_catch_errors (dpy
);
10685 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10687 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10688 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10689 x_uncatch_errors (dpy
, count
);
10694 /* See if we should run in synchronous mode. This is useful
10695 for debugging X code. */
10698 value
= display_x_get_resource (dpyinfo
,
10699 build_string ("synchronous"),
10700 build_string ("Synchronous"),
10702 if (STRINGP (value
)
10703 && (!strcmp (SDATA (value
), "true")
10704 || !strcmp (SDATA (value
), "on")))
10705 XSynchronize (dpyinfo
->display
, True
);
10710 value
= display_x_get_resource (dpyinfo
,
10711 build_string ("useXIM"),
10712 build_string ("UseXIM"),
10715 if (STRINGP (value
)
10716 && (!strcmp (XSTRING (value
)->data
, "false")
10717 || !strcmp (XSTRING (value
)->data
, "off")))
10720 if (STRINGP (value
)
10721 && (!strcmp (XSTRING (value
)->data
, "true")
10722 || !strcmp (XSTRING (value
)->data
, "on")))
10728 /* Only do this for the first display. */
10729 if (x_initialized
== 1)
10730 x_session_initialize (dpyinfo
);
10738 /* Get rid of display DPYINFO, assuming all frames are already gone,
10739 and without sending any more commands to the X server. */
10742 x_delete_display (dpyinfo
)
10743 struct x_display_info
*dpyinfo
;
10748 /* Delete the generic struct display for this X display. */
10750 for (d
= display_list
; d
; d
= d
->next_display
)
10751 if (d
->type
== output_x_window
&& d
->display_info
.x
!= dpyinfo
)
10753 delete_display (d
);
10758 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10760 /* Discard this display from x_display_name_list and x_display_list.
10761 We can't use Fdelq because that can quit. */
10762 if (! NILP (x_display_name_list
)
10763 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10764 x_display_name_list
= XCDR (x_display_name_list
);
10769 tail
= x_display_name_list
;
10770 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10772 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10774 XSETCDR (tail
, XCDR (XCDR (tail
)));
10777 tail
= XCDR (tail
);
10781 if (next_noop_dpyinfo
== dpyinfo
)
10782 next_noop_dpyinfo
= dpyinfo
->next
;
10784 if (x_display_list
== dpyinfo
)
10785 x_display_list
= dpyinfo
->next
;
10788 struct x_display_info
*tail
;
10790 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10791 if (tail
->next
== dpyinfo
)
10792 tail
->next
= tail
->next
->next
;
10795 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
10796 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
10797 XrmDestroyDatabase (dpyinfo
->xrdb
);
10800 #ifdef MULTI_KBOARD
10801 if (--dpyinfo
->kboard
->reference_count
== 0)
10802 delete_kboard (dpyinfo
->kboard
);
10806 xim_close_dpy (dpyinfo
);
10809 /* Free the font names in the font table. */
10810 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10811 if (dpyinfo
->font_table
[i
].name
)
10813 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
10814 xfree (dpyinfo
->font_table
[i
].full_name
);
10815 xfree (dpyinfo
->font_table
[i
].name
);
10818 if (dpyinfo
->font_table
->font_encoder
)
10819 xfree (dpyinfo
->font_table
->font_encoder
);
10821 xfree (dpyinfo
->font_table
);
10822 xfree (dpyinfo
->x_id_name
);
10823 xfree (dpyinfo
->color_cells
);
10827 #ifdef USE_X_TOOLKIT
10829 /* Atimer callback function for TIMER. Called every 0.1s to process
10830 Xt timeouts, if needed. We must avoid calling XtAppPending as
10831 much as possible because that function does an implicit XFlush
10832 that slows us down. */
10835 x_process_timeouts (timer
)
10836 struct atimer
*timer
;
10838 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10841 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10842 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10847 #endif /* USE_X_TOOLKIT */
10850 /* Set up use of X before we make the first connection. */
10852 extern frame_parm_handler x_frame_parm_handlers
[];
10854 static struct redisplay_interface x_redisplay_interface
=
10856 x_frame_parm_handlers
,
10860 x_clear_end_of_line
,
10862 x_after_update_window_line
,
10863 x_update_window_begin
,
10864 x_update_window_end
,
10870 0, /* flush_display_optional */
10872 x_clear_window_mouse_face
,
10873 x_get_glyph_overhangs
,
10874 x_fix_overlapping_area
,
10875 x_draw_fringe_bitmap
,
10878 x_compute_glyph_string_overhangs
,
10879 x_draw_glyph_string
,
10880 x_define_frame_cursor
,
10881 x_clear_frame_area
,
10882 x_draw_window_cursor
,
10883 x_draw_vertical_window_border
,
10884 x_shift_glyphs_for_insert
10888 /* This function is called when the last frame on a display is deleted. */
10890 x_delete_frame_display (struct display
*display
)
10892 /* We don't do anything, the connection to the X server must remain
10898 x_create_frame_display (struct x_display_info
*dpyinfo
)
10900 struct display
*display
;
10902 display
= create_display ();
10904 display
->type
= output_x_window
;
10905 display
->display_info
.x
= dpyinfo
;
10906 dpyinfo
->frame_display
= display
;
10908 display
->clear_frame_hook
= x_clear_frame
;
10909 display
->ins_del_lines_hook
= x_ins_del_lines
;
10910 display
->delete_glyphs_hook
= x_delete_glyphs
;
10911 display
->ring_bell_hook
= XTring_bell
;
10912 display
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
10913 display
->set_terminal_modes_hook
= XTset_terminal_modes
;
10914 display
->update_begin_hook
= x_update_begin
;
10915 display
->update_end_hook
= x_update_end
;
10916 display
->set_terminal_window_hook
= XTset_terminal_window
;
10917 display
->read_socket_hook
= XTread_socket
;
10918 display
->frame_up_to_date_hook
= XTframe_up_to_date
;
10919 display
->mouse_position_hook
= XTmouse_position
;
10920 display
->frame_rehighlight_hook
= XTframe_rehighlight
;
10921 display
->frame_raise_lower_hook
= XTframe_raise_lower
;
10922 display
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10923 display
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10924 display
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10925 display
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10927 display
->delete_frame_hook
= x_destroy_window
;
10928 display
->delete_display_hook
= x_delete_frame_display
;
10930 display
->rif
= &x_redisplay_interface
;
10931 display
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10932 display
->char_ins_del_ok
= 1;
10933 display
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10934 display
->fast_clear_end_of_line
= 1; /* X does this well. */
10935 display
->memory_below_frame
= 0; /* We don't remember what scrolls
10947 last_tool_bar_item
= -1;
10948 any_help_event_p
= 0;
10950 /* Try to use interrupt input; if we can't, then start polling. */
10951 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
10953 #ifdef USE_X_TOOLKIT
10954 XtToolkitInitialize ();
10956 Xt_app_con
= XtCreateApplicationContext ();
10958 /* Register a converter from strings to pixels, which uses
10959 Emacs' color allocation infrastructure. */
10960 XtAppSetTypeConverter (Xt_app_con
,
10961 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10962 cvt_string_to_pixel_args
,
10963 XtNumber (cvt_string_to_pixel_args
),
10964 XtCacheByDisplay
, cvt_pixel_dtor
);
10966 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10968 /* Install an asynchronous timer that processes Xt timeout events
10969 every 0.1s. This is necessary because some widget sets use
10970 timeouts internally, for example the LessTif menu bar, or the
10971 Xaw3d scroll bar. When Xt timouts aren't processed, these
10972 widgets don't behave normally. */
10974 EMACS_TIME interval
;
10975 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10976 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
10980 #ifdef USE_TOOLKIT_SCROLL_BARS
10982 xaw3d_arrow_scroll
= False
;
10983 xaw3d_pick_top
= True
;
10987 /* Note that there is no real way portable across R3/R4 to get the
10988 original error handler. */
10989 XSetErrorHandler (x_error_handler
);
10990 XSetIOErrorHandler (x_io_error_quitter
);
10992 /* Disable Window Change signals; they are handled by X events. */
10994 signal (SIGWINCH
, SIG_DFL
);
10995 #endif /* SIGWINCH */
10997 signal (SIGPIPE
, x_connection_signal
);
11004 staticpro (&x_error_message_string
);
11005 x_error_message_string
= Qnil
;
11007 staticpro (&x_display_name_list
);
11008 x_display_name_list
= Qnil
;
11010 staticpro (&last_mouse_scroll_bar
);
11011 last_mouse_scroll_bar
= Qnil
;
11013 staticpro (&Qvendor_specific_keysyms
);
11014 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
11016 staticpro (&Qutf_8
);
11017 Qutf_8
= intern ("utf-8");
11018 staticpro (&Qlatin_1
);
11019 Qlatin_1
= intern ("latin-1");
11021 staticpro (&last_mouse_press_frame
);
11022 last_mouse_press_frame
= Qnil
;
11024 DEFVAR_BOOL ("x-use-underline-position-properties",
11025 &x_use_underline_position_properties
,
11026 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11027 nil means ignore them. If you encounter fonts with bogus
11028 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11029 to 4.1, set this to nil. */);
11030 x_use_underline_position_properties
= 1;
11032 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11033 doc
: /* What X toolkit scroll bars Emacs uses.
11034 A value of nil means Emacs doesn't use X toolkit scroll bars.
11035 Otherwise, value is a symbol describing the X toolkit. */);
11036 #ifdef USE_TOOLKIT_SCROLL_BARS
11038 Vx_toolkit_scroll_bars
= intern ("motif");
11039 #elif defined HAVE_XAW3D
11040 Vx_toolkit_scroll_bars
= intern ("xaw3d");
11042 Vx_toolkit_scroll_bars
= intern ("gtk");
11044 Vx_toolkit_scroll_bars
= intern ("xaw");
11047 Vx_toolkit_scroll_bars
= Qnil
;
11050 staticpro (&last_mouse_motion_frame
);
11051 last_mouse_motion_frame
= Qnil
;
11053 Qmodifier_value
= intern ("modifier-value");
11054 Qalt
= intern ("alt");
11055 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
11056 Qhyper
= intern ("hyper");
11057 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
11058 Qmeta
= intern ("meta");
11059 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
11060 Qsuper
= intern ("super");
11061 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
11063 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
11064 doc
: /* Which keys Emacs uses for the alt modifier.
11065 This should be one of the symbols `alt', `hyper', `meta', `super'.
11066 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
11067 is nil, which is the same as `alt'. */);
11068 Vx_alt_keysym
= Qnil
;
11070 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
11071 doc
: /* Which keys Emacs uses for the hyper modifier.
11072 This should be one of the symbols `alt', `hyper', `meta', `super'.
11073 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
11074 default is nil, which is the same as `hyper'. */);
11075 Vx_hyper_keysym
= Qnil
;
11077 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
11078 doc
: /* Which keys Emacs uses for the meta modifier.
11079 This should be one of the symbols `alt', `hyper', `meta', `super'.
11080 For example, `meta' means use the Meta_L and Meta_R keysyms. The
11081 default is nil, which is the same as `meta'. */);
11082 Vx_meta_keysym
= Qnil
;
11084 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
11085 doc
: /* Which keys Emacs uses for the super modifier.
11086 This should be one of the symbols `alt', `hyper', `meta', `super'.
11087 For example, `super' means use the Super_L and Super_R keysyms. The
11088 default is nil, which is the same as `super'. */);
11089 Vx_super_keysym
= Qnil
;
11091 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
11092 doc
: /* Hash table of character codes indexed by X keysym codes. */);
11093 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
11094 make_float (DEFAULT_REHASH_SIZE
),
11095 make_float (DEFAULT_REHASH_THRESHOLD
),
11099 #endif /* HAVE_X_WINDOWS */
11101 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
11102 (do not change this comment) */