1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
24 /* Xt features made by Fred Pierresteguy. */
28 /* On 4.3 these lose if they come after xterm.h. */
29 /* Putting these at the beginning seems to be standard for other .c files. */
37 #include "blockinput.h"
39 /* Need syssignal.h for various externs and definitions that may be required
40 by some configurations for calls to signal later in this source file. */
41 #include "syssignal.h"
43 /* This may include sys/types.h, and that somehow loses
44 if this is not done before the other system files. */
46 #include <X11/cursorfont.h>
48 /* Load sys/types.h if not already loaded.
49 In some systems loading it twice is suicidal. */
51 #include <sys/types.h>
55 #include <sys/ioctl.h>
56 #endif /* ! defined (BSD_SYSTEM) */
61 #ifndef INCLUDED_FCNTL
68 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
69 /* #include <sys/param.h> */
75 #include "dispextern.h"
77 #include "termhooks.h"
85 #include "intervals.h"
91 #include <X11/Shell.h>
94 #ifdef HAVE_SYS_TIME_H
106 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
107 extern void xlwmenu_redisplay
P_ ((Widget
));
110 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
112 extern void free_frame_menubar
P_ ((struct frame
*));
113 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
118 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
120 extern void _XEditResCheckMessages ();
121 #endif /* not NO_EDITRES */
123 /* Include toolkit specific headers for the scroll bar widget. */
125 #ifdef USE_TOOLKIT_SCROLL_BARS
126 #if defined USE_MOTIF
127 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
128 #include <Xm/ScrollBar.h>
129 #else /* !USE_MOTIF i.e. use Xaw */
132 #include <X11/Xaw3d/Simple.h>
133 #include <X11/Xaw3d/Scrollbar.h>
134 #include <X11/Xaw3d/ThreeD.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"
160 #define abs(x) ((x) < 0 ? -(x) : (x))
162 /* Default to using XIM if available. */
166 int use_xim
= 0; /* configure --without-xim */
171 /* Non-nil means Emacs uses toolkit scroll bars. */
173 Lisp_Object Vx_toolkit_scroll_bars
;
175 /* Non-zero means that a HELP_EVENT has been generated since Emacs
178 static int any_help_event_p
;
180 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
181 static Lisp_Object last_window
;
183 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
185 int x_use_underline_position_properties
;
187 /* Non-zero means to draw the underline at the same place as the descent line. */
189 int x_underline_at_descent_line
;
191 /* This is a chain of structures for all the X displays currently in
194 struct x_display_info
*x_display_list
;
196 /* This is a list of cons cells, each of the form (NAME
197 . FONT-LIST-CACHE), one for each element of x_display_list and in
198 the same order. NAME is the name of the frame. FONT-LIST-CACHE
199 records previous values returned by x-list-fonts. */
201 Lisp_Object x_display_name_list
;
203 /* Frame being updated by update_frame. This is declared in term.c.
204 This is set by update_begin and looked at by all the XT functions.
205 It is zero while not inside an update. In that case, the XT
206 functions assume that `selected_frame' is the frame to apply to. */
208 extern struct frame
*updating_frame
;
210 /* This is a frame waiting to be auto-raised, within XTread_socket. */
212 struct frame
*pending_autoraise_frame
;
215 /* The application context for Xt use. */
216 XtAppContext Xt_app_con
;
217 static String Xt_default_resources
[] = {0};
218 #endif /* USE_X_TOOLKIT */
220 /* Non-zero means user is interacting with a toolkit scroll bar. */
222 static int toolkit_scroll_bar_interaction
;
224 /* Non-zero means to not move point as a result of clicking on a
225 frame to focus it (when focus-follows-mouse is nil). */
227 int x_mouse_click_focus_ignore_position
;
229 /* Non-zero timeout value means ignore next mouse click if it arrives
230 before that timeout elapses (i.e. as part of the same sequence of
231 events resulting from clicking on a frame to select it). */
233 static unsigned long ignore_next_mouse_click_timeout
;
237 Formerly, we used PointerMotionHintMask (in standard_event_mask)
238 so that we would have to call XQueryPointer after each MotionNotify
239 event to ask for another such event. However, this made mouse tracking
240 slow, and there was a bug that made it eventually stop.
242 Simply asking for MotionNotify all the time seems to work better.
244 In order to avoid asking for motion events and then throwing most
245 of them away or busy-polling the server for mouse positions, we ask
246 the server for pointer motion hints. This means that we get only
247 one event per group of mouse movements. "Groups" are delimited by
248 other kinds of events (focus changes and button clicks, for
249 example), or by XQueryPointer calls; when one of these happens, we
250 get another MotionNotify event the next time the mouse moves. This
251 is at least as efficient as getting motion events when mouse
252 tracking is on, and I suspect only negligibly worse when tracking
255 /* Where the mouse was last time we reported a mouse event. */
257 static XRectangle last_mouse_glyph
;
258 static FRAME_PTR last_mouse_glyph_frame
;
259 static Lisp_Object last_mouse_press_frame
;
261 /* The scroll bar in which the last X motion event occurred.
263 If the last X motion event occurred in a scroll bar, we set this so
264 XTmouse_position can know whether to report a scroll bar motion or
267 If the last X motion event didn't occur in a scroll bar, we set
268 this to Qnil, to tell XTmouse_position to return an ordinary motion
271 static Lisp_Object last_mouse_scroll_bar
;
273 /* This is a hack. We would really prefer that XTmouse_position would
274 return the time associated with the position it returns, but there
275 doesn't seem to be any way to wrest the time-stamp from the server
276 along with the position query. So, we just keep track of the time
277 of the last movement we received, and return that in hopes that
278 it's somewhat accurate. */
280 static Time last_mouse_movement_time
;
282 /* Time for last user interaction as returned in X events. */
284 static Time last_user_time
;
286 /* Incremented by XTread_socket whenever it really tries to read
290 static int volatile input_signal_count
;
292 static int input_signal_count
;
295 /* Used locally within XTread_socket. */
297 static int x_noop_count
;
299 /* Initial values of argv and argc. */
301 extern char **initial_argv
;
302 extern int initial_argc
;
304 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
306 /* Tells if a window manager is present or not. */
308 extern Lisp_Object Vx_no_window_manager
;
310 extern Lisp_Object Qeql
;
314 /* A mask of extra modifier bits to put into every keyboard char. */
316 extern EMACS_INT extra_keyboard_modifiers
;
318 /* The keysyms to use for the various modifiers. */
320 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
321 Lisp_Object Vx_keysym_table
;
322 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
324 static Lisp_Object Qvendor_specific_keysyms
;
325 static Lisp_Object Qlatin_1
;
327 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
328 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
330 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
331 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
332 static const XColor
*x_color_cells
P_ ((Display
*, int *));
333 static void x_update_window_end
P_ ((struct window
*, int, int));
335 static int x_io_error_quitter
P_ ((Display
*));
336 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
337 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
338 static void x_update_end
P_ ((struct frame
*));
339 static void XTframe_up_to_date
P_ ((struct frame
*));
340 static void XTset_terminal_modes
P_ ((void));
341 static void XTreset_terminal_modes
P_ ((void));
342 static void x_clear_frame
P_ ((void));
343 static void frame_highlight
P_ ((struct frame
*));
344 static void frame_unhighlight
P_ ((struct frame
*));
345 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
346 static void x_focus_changed
P_ ((int, int, struct x_display_info
*,
347 struct frame
*, struct input_event
*));
348 static void x_detect_focus_change
P_ ((struct x_display_info
*,
349 XEvent
*, 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
*, int, 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
*, int, int));
368 static void x_sync_with_move
P_ ((struct frame
*, int, int, int));
369 static int handle_one_xevent
P_ ((struct x_display_info
*, XEvent
*,
370 int *, struct input_event
*));
371 /* Don't declare this NO_RETURN because we want no
372 interference with debugging failing X calls. */
373 static SIGTYPE x_connection_closed
P_ ((Display
*, char *));
376 /* Flush display of frame F, or of all frames if F is null. */
385 Lisp_Object rest
, frame
;
386 FOR_EACH_FRAME (rest
, 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. */
475 /* Start update of window W. Set the global variable updated_window
476 to the window being updated and set output_cursor to the cursor
480 x_update_window_begin (w
)
483 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
484 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
487 set_output_cursor (&w
->cursor
);
491 if (f
== display_info
->mouse_face_mouse_frame
)
493 /* Don't do highlighting for mouse motion during the update. */
494 display_info
->mouse_face_defer
= 1;
496 /* If F needs to be redrawn, simply forget about any prior mouse
498 if (FRAME_GARBAGED_P (f
))
499 display_info
->mouse_face_window
= Qnil
;
501 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
502 their mouse_face_p flag set, which means that they are always
503 unequal to rows in a desired matrix which never have that
504 flag set. So, rows containing mouse-face glyphs are never
505 scrolled, and we don't have to switch the mouse highlight off
506 here to prevent it from being scrolled. */
508 /* Can we tell that this update does not affect the window
509 where the mouse highlight is? If so, no need to turn off.
510 Likewise, don't do anything if the frame is garbaged;
511 in that case, the frame's current matrix that we would use
512 is all wrong, and we will redisplay that line anyway. */
513 if (!NILP (display_info
->mouse_face_window
)
514 && w
== XWINDOW (display_info
->mouse_face_window
))
518 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
519 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
522 if (i
< w
->desired_matrix
->nrows
)
523 clear_mouse_face (display_info
);
532 /* Draw a vertical window border from (x,y0) to (x,y1) */
535 x_draw_vertical_window_border (w
, x
, y0
, y1
)
539 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
542 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
544 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
547 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
548 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
551 /* End update of window W (which is equal to updated_window).
553 Draw vertical borders between horizontally adjacent windows, and
554 display W's cursor if CURSOR_ON_P is non-zero.
556 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
557 glyphs in mouse-face were overwritten. In that case we have to
558 make sure that the mouse-highlight is properly redrawn.
560 W may be a menu bar pseudo-window in case we don't have X toolkit
561 support. Such windows don't have a cursor, so don't display it
565 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
567 int cursor_on_p
, mouse_face_overwritten_p
;
569 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
571 if (!w
->pseudo_window_p
)
576 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
578 output_cursor
.x
, output_cursor
.y
);
580 if (draw_window_fringes (w
, 1))
581 x_draw_vertical_border (w
);
586 /* If a row with mouse-face was overwritten, arrange for
587 XTframe_up_to_date to redisplay the mouse highlight. */
588 if (mouse_face_overwritten_p
)
590 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
591 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
592 dpyinfo
->mouse_face_window
= Qnil
;
595 updated_window
= NULL
;
599 /* End update of frame F. This function is installed as a hook in
606 /* Mouse highlight may be displayed again. */
607 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
611 XFlush (FRAME_X_DISPLAY (f
));
617 /* This function is called from various places in xdisp.c whenever a
618 complete update has been performed. The global variable
619 updated_window is not available here. */
622 XTframe_up_to_date (f
)
627 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
629 if (dpyinfo
->mouse_face_deferred_gc
630 || f
== dpyinfo
->mouse_face_mouse_frame
)
633 if (dpyinfo
->mouse_face_mouse_frame
)
634 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
635 dpyinfo
->mouse_face_mouse_x
,
636 dpyinfo
->mouse_face_mouse_y
);
637 dpyinfo
->mouse_face_deferred_gc
= 0;
644 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
645 arrow bitmaps, or clear the fringes if no bitmaps are required
646 before DESIRED_ROW is made current. The window being updated is
647 found in updated_window. This function It is called from
648 update_window_line only if it is known that there are differences
649 between bitmaps to be drawn between current row and DESIRED_ROW. */
652 x_after_update_window_line (desired_row
)
653 struct glyph_row
*desired_row
;
655 struct window
*w
= updated_window
;
661 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
662 desired_row
->redraw_fringe_bitmaps_p
= 1;
664 /* When a window has disappeared, make sure that no rest of
665 full-width rows stays visible in the internal border. Could
666 check here if updated_window is the leftmost/rightmost window,
667 but I guess it's not worth doing since vertically split windows
668 are almost never used, internal border is rarely set, and the
669 overhead is very small. */
670 if (windows_or_buffers_changed
671 && desired_row
->full_width_p
672 && (f
= XFRAME (w
->frame
),
673 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
675 && (height
= desired_row
->visible_height
,
678 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
680 /* Internal border is drawn below the tool bar. */
681 if (WINDOWP (f
->tool_bar_window
)
682 && w
== XWINDOW (f
->tool_bar_window
))
686 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
687 0, y
, width
, height
, False
);
688 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
689 FRAME_PIXEL_WIDTH (f
) - width
,
690 y
, width
, height
, False
);
696 x_draw_fringe_bitmap (w
, row
, p
)
698 struct glyph_row
*row
;
699 struct draw_fringe_bitmap_params
*p
;
701 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
702 Display
*display
= FRAME_X_DISPLAY (f
);
703 Window window
= FRAME_X_WINDOW (f
);
704 GC gc
= f
->output_data
.x
->normal_gc
;
705 struct face
*face
= p
->face
;
708 /* Must clip because of partially visible lines. */
709 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
712 /* Adjust position of "bottom aligned" bitmap on partially
715 int oldVH
= row
->visible_height
;
716 row
->visible_height
= p
->h
;
717 row
->y
-= rowY
- p
->y
;
718 x_clip_to_row (w
, row
, -1, gc
);
720 row
->visible_height
= oldVH
;
723 x_clip_to_row (w
, row
, -1, gc
);
725 if (p
->bx
>= 0 && !p
->overlay_p
)
727 /* In case the same realized face is used for fringes and
728 for something displayed in the text (e.g. face `region' on
729 mono-displays, the fill style may have been changed to
730 FillSolid in x_draw_glyph_string_background. */
732 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
734 XSetForeground (display
, face
->gc
, face
->background
);
736 XFillRectangle (display
, window
, face
->gc
,
737 p
->bx
, p
->by
, p
->nx
, p
->ny
);
740 XSetForeground (display
, face
->gc
, face
->foreground
);
746 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
747 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
751 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
753 bits
= (unsigned char *)p
->bits
+ p
->dh
;
755 /* Draw the bitmap. I believe these small pixmaps can be cached
757 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
759 ? (p
->overlay_p
? face
->background
760 : f
->output_data
.x
->cursor_pixel
)
762 face
->background
, depth
);
766 clipmask
= XCreatePixmapFromBitmapData (display
,
767 FRAME_X_DISPLAY_INFO (f
)->root_window
,
770 gcv
.clip_mask
= clipmask
;
771 gcv
.clip_x_origin
= p
->x
;
772 gcv
.clip_y_origin
= p
->y
;
773 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
776 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
777 p
->wd
, p
->h
, p
->x
, p
->y
);
778 XFreePixmap (display
, pixmap
);
782 gcv
.clip_mask
= (Pixmap
) 0;
783 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
784 XFreePixmap (display
, clipmask
);
788 XSetClipMask (display
, gc
, None
);
793 /* This is called when starting Emacs and when restarting after
794 suspend. When starting Emacs, no X window is mapped. And nothing
795 must be done to Emacs's own window if it is suspended (though that
799 XTset_terminal_modes ()
803 /* This is called when exiting or suspending Emacs. Exiting will make
804 the X-windows go away, and suspending requires no action. */
807 XTreset_terminal_modes ()
813 /***********************************************************************
815 ***********************************************************************/
817 /* Function prototypes of this page. */
819 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*, int *));
822 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
823 is not contained in the font. */
826 x_per_char_metric (font
, char2b
, font_type
)
829 int font_type
; /* unused on X */
831 /* The result metric information. */
832 XCharStruct
*pcm
= NULL
;
834 xassert (font
&& char2b
);
836 if (font
->per_char
!= NULL
)
838 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
840 /* min_char_or_byte2 specifies the linear character index
841 corresponding to the first element of the per_char array,
842 max_char_or_byte2 is the index of the last character. A
843 character with non-zero CHAR2B->byte1 is not in the font.
844 A character with byte2 less than min_char_or_byte2 or
845 greater max_char_or_byte2 is not in the font. */
846 if (char2b
->byte1
== 0
847 && char2b
->byte2
>= font
->min_char_or_byte2
848 && char2b
->byte2
<= font
->max_char_or_byte2
)
849 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
853 /* If either min_byte1 or max_byte1 are nonzero, both
854 min_char_or_byte2 and max_char_or_byte2 are less than
855 256, and the 2-byte character index values corresponding
856 to the per_char array element N (counting from 0) are:
858 byte1 = N/D + min_byte1
859 byte2 = N\D + min_char_or_byte2
863 D = max_char_or_byte2 - min_char_or_byte2 + 1
865 \ = integer modulus */
866 if (char2b
->byte1
>= font
->min_byte1
867 && char2b
->byte1
<= font
->max_byte1
868 && char2b
->byte2
>= font
->min_char_or_byte2
869 && char2b
->byte2
<= font
->max_char_or_byte2
)
871 pcm
= (font
->per_char
872 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
873 * (char2b
->byte1
- font
->min_byte1
))
874 + (char2b
->byte2
- font
->min_char_or_byte2
));
880 /* If the per_char pointer is null, all glyphs between the first
881 and last character indexes inclusive have the same
882 information, as given by both min_bounds and max_bounds. */
883 if (char2b
->byte2
>= font
->min_char_or_byte2
884 && char2b
->byte2
<= font
->max_char_or_byte2
)
885 pcm
= &font
->max_bounds
;
889 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
894 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
895 the two-byte form of C. Encoding is returned in *CHAR2B. */
898 x_encode_char (c
, char2b
, font_info
, two_byte_p
)
901 struct font_info
*font_info
;
904 int charset
= CHAR_CHARSET (c
);
905 XFontStruct
*font
= font_info
->font
;
907 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
908 This may be either a program in a special encoder language or a
910 if (font_info
->font_encoder
)
912 /* It's a program. */
913 struct ccl_program
*ccl
= font_info
->font_encoder
;
915 check_ccl_update (ccl
);
916 if (CHARSET_DIMENSION (charset
) == 1)
918 ccl
->reg
[0] = charset
;
919 ccl
->reg
[1] = char2b
->byte2
;
924 ccl
->reg
[0] = charset
;
925 ccl
->reg
[1] = char2b
->byte1
;
926 ccl
->reg
[2] = char2b
->byte2
;
929 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
931 /* We assume that MSBs are appropriately set/reset by CCL
933 if (font
->max_byte1
== 0) /* 1-byte font */
934 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
936 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
938 else if (font_info
->encoding
[charset
])
940 /* Fixed encoding scheme. See fontset.h for the meaning of the
942 int enc
= font_info
->encoding
[charset
];
944 if ((enc
== 1 || enc
== 2)
945 && CHARSET_DIMENSION (charset
) == 2)
946 char2b
->byte1
|= 0x80;
948 if (enc
== 1 || enc
== 3)
949 char2b
->byte2
|= 0x80;
953 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
955 return FONT_TYPE_UNKNOWN
;
960 /***********************************************************************
962 ***********************************************************************/
966 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
967 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
968 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
970 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
971 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
972 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
973 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
974 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
975 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
976 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
977 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
978 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
979 unsigned long *, double, int));
980 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
981 double, int, unsigned long));
982 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
983 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
984 static void x_draw_image_relief
P_ ((struct glyph_string
*));
985 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
986 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
987 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
989 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
990 int, int, int, int, int, int,
992 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
993 int, int, int, XRectangle
*));
996 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
1000 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1005 struct glyph_string
*s
;
1007 if (s
->font
== FRAME_FONT (s
->f
)
1008 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1009 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1011 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1014 /* Cursor on non-default face: must merge. */
1018 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1019 xgcv
.foreground
= s
->face
->background
;
1021 /* If the glyph would be invisible, try a different foreground. */
1022 if (xgcv
.foreground
== xgcv
.background
)
1023 xgcv
.foreground
= s
->face
->foreground
;
1024 if (xgcv
.foreground
== xgcv
.background
)
1025 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1026 if (xgcv
.foreground
== xgcv
.background
)
1027 xgcv
.foreground
= s
->face
->foreground
;
1029 /* Make sure the cursor is distinct from text in this face. */
1030 if (xgcv
.background
== s
->face
->background
1031 && xgcv
.foreground
== s
->face
->foreground
)
1033 xgcv
.background
= s
->face
->foreground
;
1034 xgcv
.foreground
= s
->face
->background
;
1037 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1038 xgcv
.font
= s
->font
->fid
;
1039 xgcv
.graphics_exposures
= False
;
1040 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1042 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1043 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1046 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1047 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1049 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1054 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1057 x_set_mouse_face_gc (s
)
1058 struct glyph_string
*s
;
1063 /* What face has to be used last for the mouse face? */
1064 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1065 face
= FACE_FROM_ID (s
->f
, face_id
);
1067 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1069 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1070 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
1072 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
1073 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1074 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1076 /* If font in this face is same as S->font, use it. */
1077 if (s
->font
== s
->face
->font
)
1078 s
->gc
= s
->face
->gc
;
1081 /* Otherwise construct scratch_cursor_gc with values from FACE
1086 xgcv
.background
= s
->face
->background
;
1087 xgcv
.foreground
= s
->face
->foreground
;
1088 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1089 xgcv
.font
= s
->font
->fid
;
1090 xgcv
.graphics_exposures
= False
;
1091 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1093 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1094 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1097 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1098 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1100 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1103 xassert (s
->gc
!= 0);
1107 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1108 Faces to use in the mode line have already been computed when the
1109 matrix was built, so there isn't much to do, here. */
1112 x_set_mode_line_face_gc (s
)
1113 struct glyph_string
*s
;
1115 s
->gc
= s
->face
->gc
;
1119 /* Set S->gc of glyph string S for drawing that glyph string. Set
1120 S->stippled_p to a non-zero value if the face of S has a stipple
1124 x_set_glyph_string_gc (s
)
1125 struct glyph_string
*s
;
1127 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1129 if (s
->hl
== DRAW_NORMAL_TEXT
)
1131 s
->gc
= s
->face
->gc
;
1132 s
->stippled_p
= s
->face
->stipple
!= 0;
1134 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1136 x_set_mode_line_face_gc (s
);
1137 s
->stippled_p
= s
->face
->stipple
!= 0;
1139 else if (s
->hl
== DRAW_CURSOR
)
1141 x_set_cursor_gc (s
);
1144 else if (s
->hl
== DRAW_MOUSE_FACE
)
1146 x_set_mouse_face_gc (s
);
1147 s
->stippled_p
= s
->face
->stipple
!= 0;
1149 else if (s
->hl
== DRAW_IMAGE_RAISED
1150 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1152 s
->gc
= s
->face
->gc
;
1153 s
->stippled_p
= s
->face
->stipple
!= 0;
1157 s
->gc
= s
->face
->gc
;
1158 s
->stippled_p
= s
->face
->stipple
!= 0;
1161 /* GC must have been set. */
1162 xassert (s
->gc
!= 0);
1166 /* Set clipping for output of glyph string S. S may be part of a mode
1167 line or menu if we don't have X toolkit support. */
1170 x_set_glyph_string_clipping (s
)
1171 struct glyph_string
*s
;
1174 get_glyph_string_clip_rect (s
, &r
);
1175 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
1180 Compute left and right overhang of glyph string S. If S is a glyph
1181 string for a composition, assume overhangs don't exist. */
1184 x_compute_glyph_string_overhangs (s
)
1185 struct glyph_string
*s
;
1188 && s
->first_glyph
->type
== CHAR_GLYPH
)
1191 int direction
, font_ascent
, font_descent
;
1192 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1193 &font_ascent
, &font_descent
, &cs
);
1194 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1195 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1200 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1203 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1204 struct glyph_string
*s
;
1208 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1209 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1210 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1211 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1215 /* Draw the background of glyph_string S. If S->background_filled_p
1216 is non-zero don't draw it. FORCE_P non-zero means draw the
1217 background even if it wouldn't be drawn normally. This is used
1218 when a string preceding S draws into the background of S, or S
1219 contains the first component of a composition. */
1222 x_draw_glyph_string_background (s
, force_p
)
1223 struct glyph_string
*s
;
1226 /* Nothing to do if background has already been drawn or if it
1227 shouldn't be drawn in the first place. */
1228 if (!s
->background_filled_p
)
1230 int box_line_width
= max (s
->face
->box_line_width
, 0);
1234 /* Fill background with a stipple pattern. */
1235 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1236 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1237 s
->y
+ box_line_width
,
1238 s
->background_width
,
1239 s
->height
- 2 * box_line_width
);
1240 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1241 s
->background_filled_p
= 1;
1243 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1244 || s
->font_not_found_p
1245 || s
->extends_to_end_of_line_p
1248 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1249 s
->background_width
,
1250 s
->height
- 2 * box_line_width
);
1251 s
->background_filled_p
= 1;
1257 /* Draw the foreground of glyph string S. */
1260 x_draw_glyph_string_foreground (s
)
1261 struct glyph_string
*s
;
1265 /* If first glyph of S has a left box line, start drawing the text
1266 of S to the right of that box line. */
1267 if (s
->face
->box
!= FACE_NO_BOX
1268 && s
->first_glyph
->left_box_line_p
)
1269 x
= s
->x
+ abs (s
->face
->box_line_width
);
1273 /* Draw characters of S as rectangles if S's font could not be
1275 if (s
->font_not_found_p
)
1277 for (i
= 0; i
< s
->nchars
; ++i
)
1279 struct glyph
*g
= s
->first_glyph
+ i
;
1280 XDrawRectangle (s
->display
, s
->window
,
1281 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1283 x
+= g
->pixel_width
;
1288 char *char1b
= (char *) s
->char2b
;
1289 int boff
= s
->font_info
->baseline_offset
;
1291 if (s
->font_info
->vertical_centering
)
1292 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1294 /* If we can use 8-bit functions, condense S->char2b. */
1296 for (i
= 0; i
< s
->nchars
; ++i
)
1297 char1b
[i
] = s
->char2b
[i
].byte2
;
1299 /* Draw text with XDrawString if background has already been
1300 filled. Otherwise, use XDrawImageString. (Note that
1301 XDrawImageString is usually faster than XDrawString.) Always
1302 use XDrawImageString when drawing the cursor so that there is
1303 no chance that characters under a box cursor are invisible. */
1305 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1307 /* Draw characters with 16-bit or 8-bit functions. */
1309 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1310 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1312 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1313 s
->ybase
- boff
, char1b
, s
->nchars
);
1318 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1319 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1321 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1322 s
->ybase
- boff
, char1b
, s
->nchars
);
1325 if (s
->face
->overstrike
)
1327 /* For overstriking (to simulate bold-face), draw the
1328 characters again shifted to the right by one pixel. */
1330 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1331 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1333 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1334 s
->ybase
- boff
, char1b
, s
->nchars
);
1339 /* Draw the foreground of composite glyph string S. */
1342 x_draw_composite_glyph_string_foreground (s
)
1343 struct glyph_string
*s
;
1347 /* If first glyph of S has a left box line, start drawing the text
1348 of S to the right of that box line. */
1349 if (s
->face
->box
!= FACE_NO_BOX
1350 && s
->first_glyph
->left_box_line_p
)
1351 x
= s
->x
+ abs (s
->face
->box_line_width
);
1355 /* S is a glyph string for a composition. S->gidx is the index of
1356 the first character drawn for glyphs of this composition.
1357 S->gidx == 0 means we are drawing the very first character of
1358 this composition. */
1360 /* Draw a rectangle for the composition if the font for the very
1361 first character of the composition could not be loaded. */
1362 if (s
->font_not_found_p
)
1365 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1366 s
->width
- 1, s
->height
- 1);
1370 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
1372 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1373 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
1374 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1376 if (s
->face
->overstrike
)
1377 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1378 x
+ s
->cmp
->offsets
[s
->gidx
* 2] + 1,
1379 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
1386 #ifdef USE_X_TOOLKIT
1388 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1389 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1390 XrmValue
*, XrmValue
*, XtPointer
*));
1391 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1392 XrmValue
*, Cardinal
*));
1395 /* Return the frame on which widget WIDGET is used.. Abort if frame
1396 cannot be determined. */
1398 static struct frame
*
1399 x_frame_of_widget (widget
)
1402 struct x_display_info
*dpyinfo
;
1406 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1408 /* Find the top-level shell of the widget. Note that this function
1409 can be called when the widget is not yet realized, so XtWindow
1410 (widget) == 0. That's the reason we can't simply use
1411 x_any_window_to_frame. */
1412 while (!XtIsTopLevelShell (widget
))
1413 widget
= XtParent (widget
);
1415 /* Look for a frame with that top-level widget. Allocate the color
1416 on that frame to get the right gamma correction value. */
1417 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
1418 if (GC_FRAMEP (XCAR (tail
))
1419 && (f
= XFRAME (XCAR (tail
)),
1420 (f
->output_data
.nothing
!= 1
1421 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1422 && f
->output_data
.x
->widget
== widget
)
1429 /* Allocate the color COLOR->pixel on the screen and display of
1430 widget WIDGET in colormap CMAP. If an exact match cannot be
1431 allocated, try the nearest color available. Value is non-zero
1432 if successful. This is called from lwlib. */
1435 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1440 struct frame
*f
= x_frame_of_widget (widget
);
1441 return x_alloc_nearest_color (f
, cmap
, color
);
1445 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1446 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1447 If this produces the same color as PIXEL, try a color where all RGB
1448 values have DELTA added. Return the allocated color in *PIXEL.
1449 DISPLAY is the X display, CMAP is the colormap to operate on.
1450 Value is non-zero if successful. */
1453 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1457 unsigned long *pixel
;
1461 struct frame
*f
= x_frame_of_widget (widget
);
1462 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1466 /* Structure specifying which arguments should be passed by Xt to
1467 cvt_string_to_pixel. We want the widget's screen and colormap. */
1469 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1471 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1473 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1478 /* The address of this variable is returned by
1479 cvt_string_to_pixel. */
1481 static Pixel cvt_string_to_pixel_value
;
1484 /* Convert a color name to a pixel color.
1486 DPY is the display we are working on.
1488 ARGS is an array of *NARGS XrmValue structures holding additional
1489 information about the widget for which the conversion takes place.
1490 The contents of this array are determined by the specification
1491 in cvt_string_to_pixel_args.
1493 FROM is a pointer to an XrmValue which points to the color name to
1494 convert. TO is an XrmValue in which to return the pixel color.
1496 CLOSURE_RET is a pointer to user-data, in which we record if
1497 we allocated the color or not.
1499 Value is True if successful, False otherwise. */
1502 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1506 XrmValue
*from
, *to
;
1507 XtPointer
*closure_ret
;
1517 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1518 "wrongParameters", "cvt_string_to_pixel",
1520 "Screen and colormap args required", NULL
, NULL
);
1524 screen
= *(Screen
**) args
[0].addr
;
1525 cmap
= *(Colormap
*) args
[1].addr
;
1526 color_name
= (String
) from
->addr
;
1528 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1530 *closure_ret
= (XtPointer
) False
;
1531 pixel
= WhitePixelOfScreen (screen
);
1533 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1535 *closure_ret
= (XtPointer
) False
;
1536 pixel
= BlackPixelOfScreen (screen
);
1538 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1539 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1541 pixel
= color
.pixel
;
1542 *closure_ret
= (XtPointer
) True
;
1547 Cardinal nparams
= 1;
1549 params
[0] = color_name
;
1550 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1551 "badValue", "cvt_string_to_pixel",
1552 "XtToolkitError", "Invalid color `%s'",
1557 if (to
->addr
!= NULL
)
1559 if (to
->size
< sizeof (Pixel
))
1561 to
->size
= sizeof (Pixel
);
1565 *(Pixel
*) to
->addr
= pixel
;
1569 cvt_string_to_pixel_value
= pixel
;
1570 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1573 to
->size
= sizeof (Pixel
);
1578 /* Free a pixel color which was previously allocated via
1579 cvt_string_to_pixel. This is registered as the destructor
1580 for this type of resource via XtSetTypeConverter.
1582 APP is the application context in which we work.
1584 TO is a pointer to an XrmValue holding the color to free.
1585 CLOSURE is the value we stored in CLOSURE_RET for this color
1586 in cvt_string_to_pixel.
1588 ARGS and NARGS are like for cvt_string_to_pixel. */
1591 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1600 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1602 "Screen and colormap arguments required",
1605 else if (closure
!= NULL
)
1607 /* We did allocate the pixel, so free it. */
1608 Screen
*screen
= *(Screen
**) args
[0].addr
;
1609 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1610 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1611 (Pixel
*) to
->addr
, 1);
1616 #endif /* USE_X_TOOLKIT */
1619 /* Value is an array of XColor structures for the contents of the
1620 color map of display DPY. Set *NCELLS to the size of the array.
1621 Note that this probably shouldn't be called for large color maps,
1622 say a 24-bit TrueColor map. */
1624 static const XColor
*
1625 x_color_cells (dpy
, ncells
)
1629 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1631 if (dpyinfo
->color_cells
== NULL
)
1633 Screen
*screen
= dpyinfo
->screen
;
1636 dpyinfo
->ncolor_cells
1637 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1638 dpyinfo
->color_cells
1639 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1640 * sizeof *dpyinfo
->color_cells
);
1642 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1643 dpyinfo
->color_cells
[i
].pixel
= i
;
1645 XQueryColors (dpy
, dpyinfo
->cmap
,
1646 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1649 *ncells
= dpyinfo
->ncolor_cells
;
1650 return dpyinfo
->color_cells
;
1654 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1655 colors in COLORS. Use cached information, if available. */
1658 x_query_colors (f
, colors
, ncolors
)
1663 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1665 if (dpyinfo
->color_cells
)
1668 for (i
= 0; i
< ncolors
; ++i
)
1670 unsigned long pixel
= colors
[i
].pixel
;
1671 xassert (pixel
< dpyinfo
->ncolor_cells
);
1672 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1673 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1677 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1681 /* On frame F, translate pixel color to RGB values for the color in
1682 COLOR. Use cached information, if available. */
1685 x_query_color (f
, color
)
1689 x_query_colors (f
, color
, 1);
1693 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1694 exact match can't be allocated, try the nearest color available.
1695 Value is non-zero if successful. Set *COLOR to the color
1699 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1706 rc
= XAllocColor (dpy
, cmap
, color
);
1709 /* If we got to this point, the colormap is full, so we're going
1710 to try to get the next closest color. The algorithm used is
1711 a least-squares matching, which is what X uses for closest
1712 color matching with StaticColor visuals. */
1714 unsigned long nearest_delta
= ~0;
1716 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1718 for (nearest
= i
= 0; i
< ncells
; ++i
)
1720 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1721 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1722 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1723 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1725 if (delta
< nearest_delta
)
1728 nearest_delta
= delta
;
1732 color
->red
= cells
[nearest
].red
;
1733 color
->green
= cells
[nearest
].green
;
1734 color
->blue
= cells
[nearest
].blue
;
1735 rc
= XAllocColor (dpy
, cmap
, color
);
1739 /* If allocation succeeded, and the allocated pixel color is not
1740 equal to a cached pixel color recorded earlier, there was a
1741 change in the colormap, so clear the color cache. */
1742 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1743 XColor
*cached_color
;
1745 if (dpyinfo
->color_cells
1746 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1747 (cached_color
->red
!= color
->red
1748 || cached_color
->blue
!= color
->blue
1749 || cached_color
->green
!= color
->green
)))
1751 xfree (dpyinfo
->color_cells
);
1752 dpyinfo
->color_cells
= NULL
;
1753 dpyinfo
->ncolor_cells
= 0;
1757 #ifdef DEBUG_X_COLORS
1759 register_color (color
->pixel
);
1760 #endif /* DEBUG_X_COLORS */
1766 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1767 exact match can't be allocated, try the nearest color available.
1768 Value is non-zero if successful. Set *COLOR to the color
1772 x_alloc_nearest_color (f
, cmap
, color
)
1777 gamma_correct (f
, color
);
1778 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1782 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1783 It's necessary to do this instead of just using PIXEL directly to
1784 get color reference counts right. */
1787 x_copy_color (f
, pixel
)
1789 unsigned long pixel
;
1793 color
.pixel
= pixel
;
1795 x_query_color (f
, &color
);
1796 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1798 #ifdef DEBUG_X_COLORS
1799 register_color (pixel
);
1805 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1806 It's necessary to do this instead of just using PIXEL directly to
1807 get color reference counts right. */
1810 x_copy_dpy_color (dpy
, cmap
, pixel
)
1813 unsigned long pixel
;
1817 color
.pixel
= pixel
;
1819 XQueryColor (dpy
, cmap
, &color
);
1820 XAllocColor (dpy
, cmap
, &color
);
1822 #ifdef DEBUG_X_COLORS
1823 register_color (pixel
);
1829 /* Brightness beyond which a color won't have its highlight brightness
1832 Nominally, highlight colors for `3d' faces are calculated by
1833 brightening an object's color by a constant scale factor, but this
1834 doesn't yield good results for dark colors, so for colors who's
1835 brightness is less than this value (on a scale of 0-65535) have an
1836 use an additional additive factor.
1838 The value here is set so that the default menu-bar/mode-line color
1839 (grey75) will not have its highlights changed at all. */
1840 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1843 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1844 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1845 If this produces the same color as PIXEL, try a color where all RGB
1846 values have DELTA added. Return the allocated color in *PIXEL.
1847 DISPLAY is the X display, CMAP is the colormap to operate on.
1848 Value is non-zero if successful. */
1851 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
1855 unsigned long *pixel
;
1863 /* Get RGB color values. */
1864 color
.pixel
= *pixel
;
1865 x_query_color (f
, &color
);
1867 /* Change RGB values by specified FACTOR. Avoid overflow! */
1868 xassert (factor
>= 0);
1869 new.red
= min (0xffff, factor
* color
.red
);
1870 new.green
= min (0xffff, factor
* color
.green
);
1871 new.blue
= min (0xffff, factor
* color
.blue
);
1873 /* Calculate brightness of COLOR. */
1874 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1876 /* We only boost colors that are darker than
1877 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1878 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1879 /* Make an additive adjustment to NEW, because it's dark enough so
1880 that scaling by FACTOR alone isn't enough. */
1882 /* How far below the limit this color is (0 - 1, 1 being darker). */
1883 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1884 /* The additive adjustment. */
1885 int min_delta
= delta
* dimness
* factor
/ 2;
1889 new.red
= max (0, new.red
- min_delta
);
1890 new.green
= max (0, new.green
- min_delta
);
1891 new.blue
= max (0, new.blue
- min_delta
);
1895 new.red
= min (0xffff, min_delta
+ new.red
);
1896 new.green
= min (0xffff, min_delta
+ new.green
);
1897 new.blue
= min (0xffff, min_delta
+ new.blue
);
1901 /* Try to allocate the color. */
1902 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1905 if (new.pixel
== *pixel
)
1907 /* If we end up with the same color as before, try adding
1908 delta to the RGB values. */
1909 x_free_colors (f
, &new.pixel
, 1);
1911 new.red
= min (0xffff, delta
+ color
.red
);
1912 new.green
= min (0xffff, delta
+ color
.green
);
1913 new.blue
= min (0xffff, delta
+ color
.blue
);
1914 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1925 /* Set up the foreground color for drawing relief lines of glyph
1926 string S. RELIEF is a pointer to a struct relief containing the GC
1927 with which lines will be drawn. Use a color that is FACTOR or
1928 DELTA lighter or darker than the relief's background which is found
1929 in S->f->output_data.x->relief_background. If such a color cannot
1930 be allocated, use DEFAULT_PIXEL, instead. */
1933 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1935 struct relief
*relief
;
1938 unsigned long default_pixel
;
1941 struct x_output
*di
= f
->output_data
.x
;
1942 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1943 unsigned long pixel
;
1944 unsigned long background
= di
->relief_background
;
1945 Colormap cmap
= FRAME_X_COLORMAP (f
);
1946 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1947 Display
*dpy
= FRAME_X_DISPLAY (f
);
1949 xgcv
.graphics_exposures
= False
;
1950 xgcv
.line_width
= 1;
1952 /* Free previously allocated color. The color cell will be reused
1953 when it has been freed as many times as it was allocated, so this
1954 doesn't affect faces using the same colors. */
1956 && relief
->allocated_p
)
1958 x_free_colors (f
, &relief
->pixel
, 1);
1959 relief
->allocated_p
= 0;
1962 /* Allocate new color. */
1963 xgcv
.foreground
= default_pixel
;
1965 if (dpyinfo
->n_planes
!= 1
1966 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1968 relief
->allocated_p
= 1;
1969 xgcv
.foreground
= relief
->pixel
= pixel
;
1972 if (relief
->gc
== 0)
1974 xgcv
.stipple
= dpyinfo
->gray
;
1976 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1979 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1983 /* Set up colors for the relief lines around glyph string S. */
1986 x_setup_relief_colors (s
)
1987 struct glyph_string
*s
;
1989 struct x_output
*di
= s
->f
->output_data
.x
;
1990 unsigned long color
;
1992 if (s
->face
->use_box_color_for_shadows_p
)
1993 color
= s
->face
->box_color
;
1994 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1996 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1997 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2002 /* Get the background color of the face. */
2003 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2004 color
= xgcv
.background
;
2007 if (di
->white_relief
.gc
== 0
2008 || color
!= di
->relief_background
)
2010 di
->relief_background
= color
;
2011 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2012 WHITE_PIX_DEFAULT (s
->f
));
2013 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2014 BLACK_PIX_DEFAULT (s
->f
));
2019 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2020 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2021 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2022 relief. LEFT_P non-zero means draw a relief on the left side of
2023 the rectangle. RIGHT_P non-zero means draw a relief on the right
2024 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2028 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2029 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2031 int left_x
, top_y
, right_x
, bottom_y
, width
;
2032 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2033 XRectangle
*clip_rect
;
2035 Display
*dpy
= FRAME_X_DISPLAY (f
);
2036 Window window
= FRAME_X_WINDOW (f
);
2041 gc
= f
->output_data
.x
->white_relief
.gc
;
2043 gc
= f
->output_data
.x
->black_relief
.gc
;
2044 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2048 for (i
= 0; i
< width
; ++i
)
2049 XDrawLine (dpy
, window
, gc
,
2050 left_x
+ i
* left_p
, top_y
+ i
,
2051 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2055 for (i
= 0; i
< width
; ++i
)
2056 XDrawLine (dpy
, window
, gc
,
2057 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2059 XSetClipMask (dpy
, gc
, None
);
2061 gc
= f
->output_data
.x
->black_relief
.gc
;
2063 gc
= f
->output_data
.x
->white_relief
.gc
;
2064 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2068 for (i
= 0; i
< width
; ++i
)
2069 XDrawLine (dpy
, window
, gc
,
2070 left_x
+ i
* left_p
, bottom_y
- i
,
2071 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2075 for (i
= 0; i
< width
; ++i
)
2076 XDrawLine (dpy
, window
, gc
,
2077 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2079 XSetClipMask (dpy
, gc
, None
);
2083 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2084 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2085 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2086 left side of the rectangle. RIGHT_P non-zero means draw a line
2087 on the right side of the rectangle. CLIP_RECT is the clipping
2088 rectangle to use when drawing. */
2091 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2092 left_p
, right_p
, clip_rect
)
2093 struct glyph_string
*s
;
2094 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2095 XRectangle
*clip_rect
;
2099 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2100 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2101 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2104 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2105 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2109 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2110 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2113 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2114 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2118 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2119 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2121 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2122 XSetClipMask (s
->display
, s
->gc
, None
);
2126 /* Draw a box around glyph string S. */
2129 x_draw_glyph_string_box (s
)
2130 struct glyph_string
*s
;
2132 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2133 int left_p
, right_p
;
2134 struct glyph
*last_glyph
;
2135 XRectangle clip_rect
;
2137 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2138 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2139 : window_box_right (s
->w
, s
->area
));
2141 /* The glyph that may have a right box line. */
2142 last_glyph
= (s
->cmp
|| s
->img
2144 : s
->first_glyph
+ s
->nchars
- 1);
2146 width
= abs (s
->face
->box_line_width
);
2147 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2149 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2151 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2153 bottom_y
= top_y
+ s
->height
- 1;
2155 left_p
= (s
->first_glyph
->left_box_line_p
2156 || (s
->hl
== DRAW_MOUSE_FACE
2158 || s
->prev
->hl
!= s
->hl
)));
2159 right_p
= (last_glyph
->right_box_line_p
2160 || (s
->hl
== DRAW_MOUSE_FACE
2162 || s
->next
->hl
!= s
->hl
)));
2164 get_glyph_string_clip_rect (s
, &clip_rect
);
2166 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2167 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2168 left_p
, right_p
, &clip_rect
);
2171 x_setup_relief_colors (s
);
2172 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2173 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2178 /* Draw foreground of image glyph string S. */
2181 x_draw_image_foreground (s
)
2182 struct glyph_string
*s
;
2185 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2187 /* If first glyph of S has a left box line, start drawing it to the
2188 right of that line. */
2189 if (s
->face
->box
!= FACE_NO_BOX
2190 && s
->first_glyph
->left_box_line_p
2192 x
+= abs (s
->face
->box_line_width
);
2194 /* If there is a margin around the image, adjust x- and y-position
2196 if (s
->slice
.x
== 0)
2197 x
+= s
->img
->hmargin
;
2198 if (s
->slice
.y
== 0)
2199 y
+= s
->img
->vmargin
;
2205 /* We can't set both a clip mask and use XSetClipRectangles
2206 because the latter also sets a clip mask. We also can't
2207 trust on the shape extension to be available
2208 (XShapeCombineRegion). So, compute the rectangle to draw
2210 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2213 XRectangle clip_rect
, image_rect
, r
;
2215 xgcv
.clip_mask
= s
->img
->mask
;
2216 xgcv
.clip_x_origin
= x
;
2217 xgcv
.clip_y_origin
= y
;
2218 xgcv
.function
= GXcopy
;
2219 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2221 get_glyph_string_clip_rect (s
, &clip_rect
);
2224 image_rect
.width
= s
->slice
.width
;
2225 image_rect
.height
= s
->slice
.height
;
2226 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2227 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2228 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2229 r
.width
, r
.height
, r
.x
, r
.y
);
2233 XRectangle clip_rect
, image_rect
, r
;
2235 get_glyph_string_clip_rect (s
, &clip_rect
);
2238 image_rect
.width
= s
->slice
.width
;
2239 image_rect
.height
= s
->slice
.height
;
2240 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2241 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2242 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2243 r
.width
, r
.height
, r
.x
, r
.y
);
2245 /* When the image has a mask, we can expect that at
2246 least part of a mouse highlight or a block cursor will
2247 be visible. If the image doesn't have a mask, make
2248 a block cursor visible by drawing a rectangle around
2249 the image. I believe it's looking better if we do
2250 nothing here for mouse-face. */
2251 if (s
->hl
== DRAW_CURSOR
)
2253 int r
= s
->img
->relief
;
2255 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2257 s
->slice
.width
+ r
*2 - 1,
2258 s
->slice
.height
+ r
*2 - 1);
2263 /* Draw a rectangle if image could not be loaded. */
2264 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2265 s
->slice
.width
- 1, s
->slice
.height
- 1);
2269 /* Draw a relief around the image glyph string S. */
2272 x_draw_image_relief (s
)
2273 struct glyph_string
*s
;
2275 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2278 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2280 /* If first glyph of S has a left box line, start drawing it to the
2281 right of that line. */
2282 if (s
->face
->box
!= FACE_NO_BOX
2283 && s
->first_glyph
->left_box_line_p
2285 x
+= abs (s
->face
->box_line_width
);
2287 /* If there is a margin around the image, adjust x- and y-position
2289 if (s
->slice
.x
== 0)
2290 x
+= s
->img
->hmargin
;
2291 if (s
->slice
.y
== 0)
2292 y
+= s
->img
->vmargin
;
2294 if (s
->hl
== DRAW_IMAGE_SUNKEN
2295 || s
->hl
== DRAW_IMAGE_RAISED
)
2297 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2298 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2302 thick
= abs (s
->img
->relief
);
2303 raised_p
= s
->img
->relief
> 0;
2308 x1
= x
+ s
->slice
.width
+ thick
- 1;
2309 y1
= y
+ s
->slice
.height
+ thick
- 1;
2311 x_setup_relief_colors (s
);
2312 get_glyph_string_clip_rect (s
, &r
);
2313 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2315 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2317 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2322 /* Draw the foreground of image glyph string S to PIXMAP. */
2325 x_draw_image_foreground_1 (s
, pixmap
)
2326 struct glyph_string
*s
;
2330 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2332 /* If first glyph of S has a left box line, start drawing it to the
2333 right of that line. */
2334 if (s
->face
->box
!= FACE_NO_BOX
2335 && s
->first_glyph
->left_box_line_p
2337 x
+= abs (s
->face
->box_line_width
);
2339 /* If there is a margin around the image, adjust x- and y-position
2341 if (s
->slice
.x
== 0)
2342 x
+= s
->img
->hmargin
;
2343 if (s
->slice
.y
== 0)
2344 y
+= s
->img
->vmargin
;
2350 /* We can't set both a clip mask and use XSetClipRectangles
2351 because the latter also sets a clip mask. We also can't
2352 trust on the shape extension to be available
2353 (XShapeCombineRegion). So, compute the rectangle to draw
2355 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2359 xgcv
.clip_mask
= s
->img
->mask
;
2360 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2361 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2362 xgcv
.function
= GXcopy
;
2363 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2365 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2366 s
->slice
.x
, s
->slice
.y
,
2367 s
->slice
.width
, s
->slice
.height
, x
, y
);
2368 XSetClipMask (s
->display
, s
->gc
, None
);
2372 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2373 s
->slice
.x
, s
->slice
.y
,
2374 s
->slice
.width
, s
->slice
.height
, x
, y
);
2376 /* When the image has a mask, we can expect that at
2377 least part of a mouse highlight or a block cursor will
2378 be visible. If the image doesn't have a mask, make
2379 a block cursor visible by drawing a rectangle around
2380 the image. I believe it's looking better if we do
2381 nothing here for mouse-face. */
2382 if (s
->hl
== DRAW_CURSOR
)
2384 int r
= s
->img
->relief
;
2386 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2387 s
->slice
.width
+ r
*2 - 1,
2388 s
->slice
.height
+ r
*2 - 1);
2393 /* Draw a rectangle if image could not be loaded. */
2394 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2395 s
->slice
.width
- 1, s
->slice
.height
- 1);
2399 /* Draw part of the background of glyph string S. X, Y, W, and H
2400 give the rectangle to draw. */
2403 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2404 struct glyph_string
*s
;
2409 /* Fill background with a stipple pattern. */
2410 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2411 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2412 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2415 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2419 /* Draw image glyph string S.
2422 s->x +-------------------------
2425 | +-------------------------
2428 | | +-------------------
2434 x_draw_image_glyph_string (s
)
2435 struct glyph_string
*s
;
2437 int box_line_hwidth
= abs (s
->face
->box_line_width
);
2438 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2440 Pixmap pixmap
= None
;
2443 if (s
->slice
.y
== 0)
2444 height
-= box_line_vwidth
;
2445 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2446 height
-= box_line_vwidth
;
2448 /* Fill background with face under the image. Do it only if row is
2449 taller than image or if image has a clip mask to reduce
2451 s
->stippled_p
= s
->face
->stipple
!= 0;
2452 if (height
> s
->slice
.height
2456 || s
->img
->pixmap
== 0
2457 || s
->width
!= s
->background_width
)
2461 /* Create a pixmap as large as the glyph string. Fill it
2462 with the background color. Copy the image to it, using
2463 its mask. Copy the temporary pixmap to the display. */
2464 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2465 int depth
= DefaultDepthOfScreen (screen
);
2467 /* Create a pixmap as large as the glyph string. */
2468 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2469 s
->background_width
,
2472 /* Don't clip in the following because we're working on the
2474 XSetClipMask (s
->display
, s
->gc
, None
);
2476 /* Fill the pixmap with the background color/stipple. */
2479 /* Fill background with a stipple pattern. */
2480 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2481 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2482 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2483 0, 0, s
->background_width
, s
->height
);
2484 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2485 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2490 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2492 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2493 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2494 0, 0, s
->background_width
, s
->height
);
2495 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2503 if (s
->first_glyph
->left_box_line_p
2505 x
+= box_line_hwidth
;
2507 if (s
->slice
.y
== 0)
2508 y
+= box_line_vwidth
;
2510 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2513 s
->background_filled_p
= 1;
2516 /* Draw the foreground. */
2519 x_draw_image_foreground_1 (s
, pixmap
);
2520 x_set_glyph_string_clipping (s
);
2521 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2522 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2523 XFreePixmap (s
->display
, pixmap
);
2526 x_draw_image_foreground (s
);
2528 /* If we must draw a relief around the image, do it. */
2530 || s
->hl
== DRAW_IMAGE_RAISED
2531 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2532 x_draw_image_relief (s
);
2536 /* Draw stretch glyph string S. */
2539 x_draw_stretch_glyph_string (s
)
2540 struct glyph_string
*s
;
2542 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2544 if (s
->hl
== DRAW_CURSOR
2545 && !x_stretch_cursor_p
)
2547 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2548 as wide as the stretch glyph. */
2549 int width
, background_width
= s
->background_width
;
2550 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2554 background_width
-= left_x
- x
;
2557 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2560 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2562 /* Clear rest using the GC of the original non-cursor face. */
2563 if (width
< background_width
)
2566 int w
= background_width
- width
, h
= s
->height
;
2571 if (s
->row
->mouse_face_p
2572 && cursor_in_mouse_face_p (s
->w
))
2574 x_set_mouse_face_gc (s
);
2580 get_glyph_string_clip_rect (s
, &r
);
2581 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2583 if (s
->face
->stipple
)
2585 /* Fill background with a stipple pattern. */
2586 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2587 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2588 XSetFillStyle (s
->display
, gc
, FillSolid
);
2593 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2594 XSetForeground (s
->display
, gc
, xgcv
.background
);
2595 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2596 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2600 else if (!s
->background_filled_p
)
2602 int background_width
= s
->background_width
;
2603 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2605 /* Don't draw into left margin, fringe or scrollbar area
2606 except for header line and mode line. */
2607 if (x
< left_x
&& !s
->row
->mode_line_p
)
2609 background_width
-= left_x
- x
;
2612 if (background_width
> 0)
2613 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2616 s
->background_filled_p
= 1;
2620 /* Draw glyph string S. */
2623 x_draw_glyph_string (s
)
2624 struct glyph_string
*s
;
2626 int relief_drawn_p
= 0;
2628 /* If S draws into the background of its successor, draw the
2629 background of the successor first so that S can draw into it.
2630 This makes S->next use XDrawString instead of XDrawImageString. */
2631 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2633 xassert (s
->next
->img
== NULL
);
2634 x_set_glyph_string_gc (s
->next
);
2635 x_set_glyph_string_clipping (s
->next
);
2636 x_draw_glyph_string_background (s
->next
, 1);
2639 /* Set up S->gc, set clipping and draw S. */
2640 x_set_glyph_string_gc (s
);
2642 /* Draw relief (if any) in advance for char/composition so that the
2643 glyph string can be drawn over it. */
2644 if (!s
->for_overlaps
2645 && s
->face
->box
!= FACE_NO_BOX
2646 && (s
->first_glyph
->type
== CHAR_GLYPH
2647 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2650 x_set_glyph_string_clipping (s
);
2651 x_draw_glyph_string_background (s
, 1);
2652 x_draw_glyph_string_box (s
);
2653 x_set_glyph_string_clipping (s
);
2657 x_set_glyph_string_clipping (s
);
2659 switch (s
->first_glyph
->type
)
2662 x_draw_image_glyph_string (s
);
2666 x_draw_stretch_glyph_string (s
);
2670 if (s
->for_overlaps
)
2671 s
->background_filled_p
= 1;
2673 x_draw_glyph_string_background (s
, 0);
2674 x_draw_glyph_string_foreground (s
);
2677 case COMPOSITE_GLYPH
:
2678 if (s
->for_overlaps
|| s
->gidx
> 0)
2679 s
->background_filled_p
= 1;
2681 x_draw_glyph_string_background (s
, 1);
2682 x_draw_composite_glyph_string_foreground (s
);
2689 if (!s
->for_overlaps
)
2691 /* Draw underline. */
2692 if (s
->face
->underline_p
)
2694 unsigned long tem
, h
;
2697 /* Get the underline thickness. Default is 1 pixel. */
2698 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
2701 y
= s
->y
+ s
->height
- h
;
2702 if (!x_underline_at_descent_line
)
2704 /* Get the underline position. This is the recommended
2705 vertical offset in pixels from the baseline to the top of
2706 the underline. This is a signed value according to the
2707 specs, and its default is
2709 ROUND ((maximum descent) / 2), with
2710 ROUND(x) = floor (x + 0.5) */
2712 if (x_use_underline_position_properties
2713 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
2714 y
= s
->ybase
+ (long) tem
;
2715 else if (s
->face
->font
)
2716 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2719 if (s
->face
->underline_defaulted_p
)
2720 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2721 s
->x
, y
, s
->background_width
, h
);
2725 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2726 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2727 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2728 s
->x
, y
, s
->background_width
, h
);
2729 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2733 /* Draw overline. */
2734 if (s
->face
->overline_p
)
2736 unsigned long dy
= 0, h
= 1;
2738 if (s
->face
->overline_color_defaulted_p
)
2739 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2740 s
->background_width
, h
);
2744 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2745 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2746 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2747 s
->background_width
, h
);
2748 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2752 /* Draw strike-through. */
2753 if (s
->face
->strike_through_p
)
2755 unsigned long h
= 1;
2756 unsigned long dy
= (s
->height
- h
) / 2;
2758 if (s
->face
->strike_through_color_defaulted_p
)
2759 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2764 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2765 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2766 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2768 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2772 /* Draw relief if not yet drawn. */
2773 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2774 x_draw_glyph_string_box (s
);
2777 /* Reset clipping. */
2778 XSetClipMask (s
->display
, s
->gc
, None
);
2781 /* Shift display to make room for inserted glyphs. */
2784 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2786 int x
, y
, width
, height
, shift_by
;
2788 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2789 f
->output_data
.x
->normal_gc
,
2790 x
, y
, width
, height
,
2794 /* Delete N glyphs at the nominal cursor position. Not implemented
2805 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2806 If they are <= 0, this is probably an error. */
2809 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
2816 xassert (width
> 0 && height
> 0);
2817 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2821 /* Clear entire frame. If updating_frame is non-null, clear that
2822 frame. Otherwise clear the selected frame. */
2832 f
= SELECTED_FRAME ();
2834 /* Clearing the frame will erase any cursor, so mark them all as no
2836 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2837 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2838 output_cursor
.x
= -1;
2840 /* We don't set the output cursor here because there will always
2841 follow an explicit cursor_to. */
2843 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2845 /* We have to clear the scroll bars, too. If we have changed
2846 colors or something like that, then they should be notified. */
2847 x_scroll_bar_clear (f
);
2849 XFlush (FRAME_X_DISPLAY (f
));
2856 /* Invert the middle quarter of the frame for .15 sec. */
2858 /* We use the select system call to do the waiting, so we have to make
2859 sure it's available. If it isn't, we just won't do visual bells. */
2861 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2864 /* Subtract the `struct timeval' values X and Y, storing the result in
2865 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2868 timeval_subtract (result
, x
, y
)
2869 struct timeval
*result
, x
, y
;
2871 /* Perform the carry for the later subtraction by updating y. This
2872 is safer because on some systems the tv_sec member is unsigned. */
2873 if (x
.tv_usec
< y
.tv_usec
)
2875 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2876 y
.tv_usec
-= 1000000 * nsec
;
2880 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2882 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2883 y
.tv_usec
+= 1000000 * nsec
;
2887 /* Compute the time remaining to wait. tv_usec is certainly
2889 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2890 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2892 /* Return indication of whether the result should be considered
2894 return x
.tv_sec
< y
.tv_sec
;
2906 /* Create a GC that will use the GXxor function to flip foreground
2907 pixels into background pixels. */
2911 values
.function
= GXxor
;
2912 values
.foreground
= (f
->output_data
.x
->foreground_pixel
2913 ^ f
->output_data
.x
->background_pixel
);
2915 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2916 GCFunction
| GCForeground
, &values
);
2920 /* Get the height not including a menu bar widget. */
2921 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
2922 /* Height of each line to flash. */
2923 int flash_height
= FRAME_LINE_HEIGHT (f
);
2924 /* These will be the left and right margins of the rectangles. */
2925 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2926 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
2930 /* Don't flash the area between a scroll bar and the frame
2931 edge it is next to. */
2932 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
2934 case vertical_scroll_bar_left
:
2935 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2938 case vertical_scroll_bar_right
:
2939 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2946 width
= flash_right
- flash_left
;
2948 /* If window is tall, flash top and bottom line. */
2949 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2951 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2953 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2954 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
2955 width
, flash_height
);
2956 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2958 (height
- flash_height
2959 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2960 width
, flash_height
);
2963 /* If it is short, flash it all. */
2964 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2965 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2966 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2971 struct timeval wakeup
;
2973 EMACS_GET_TIME (wakeup
);
2975 /* Compute time to wait until, propagating carry from usecs. */
2976 wakeup
.tv_usec
+= 150000;
2977 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
2978 wakeup
.tv_usec
%= 1000000;
2980 /* Keep waiting until past the time wakeup or any input gets
2982 while (! detect_input_pending ())
2984 struct timeval current
;
2985 struct timeval timeout
;
2987 EMACS_GET_TIME (current
);
2989 /* Break if result would be negative. */
2990 if (timeval_subtract (¤t
, wakeup
, current
))
2993 /* How long `select' should wait. */
2995 timeout
.tv_usec
= 10000;
2997 /* Try to wait that long--but we might wake up sooner. */
2998 select (0, NULL
, NULL
, NULL
, &timeout
);
3002 /* If window is tall, flash top and bottom line. */
3003 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3005 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3007 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3008 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3009 width
, flash_height
);
3010 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3012 (height
- flash_height
3013 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3014 width
, flash_height
);
3017 /* If it is short, flash it all. */
3018 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3019 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3020 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3022 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3030 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3033 /* Make audible bell. */
3038 struct frame
*f
= SELECTED_FRAME ();
3040 if (FRAME_X_DISPLAY (f
))
3042 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3049 XBell (FRAME_X_DISPLAY (f
), 0);
3050 XFlush (FRAME_X_DISPLAY (f
));
3057 /* Specify how many text lines, from the top of the window,
3058 should be affected by insert-lines and delete-lines operations.
3059 This, and those operations, are used only within an update
3060 that is bounded by calls to x_update_begin and x_update_end. */
3063 XTset_terminal_window (n
)
3066 /* This function intentionally left blank. */
3071 /***********************************************************************
3073 ***********************************************************************/
3075 /* Perform an insert-lines or delete-lines operation, inserting N
3076 lines or deleting -N lines at vertical position VPOS. */
3079 x_ins_del_lines (vpos
, n
)
3086 /* Scroll part of the display as described by RUN. */
3089 x_scroll_run (w
, run
)
3093 struct frame
*f
= XFRAME (w
->frame
);
3094 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3096 /* Get frame-relative bounding box of the text display area of W,
3097 without mode lines. Include in this box the left and right
3099 window_box (w
, -1, &x
, &y
, &width
, &height
);
3101 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3102 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3103 bottom_y
= y
+ height
;
3107 /* Scrolling up. Make sure we don't copy part of the mode
3108 line at the bottom. */
3109 if (from_y
+ run
->height
> bottom_y
)
3110 height
= bottom_y
- from_y
;
3112 height
= run
->height
;
3116 /* Scolling down. Make sure we don't copy over the mode line.
3118 if (to_y
+ run
->height
> bottom_y
)
3119 height
= bottom_y
- to_y
;
3121 height
= run
->height
;
3126 /* Cursor off. Will be switched on again in x_update_window_end. */
3130 XCopyArea (FRAME_X_DISPLAY (f
),
3131 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3132 f
->output_data
.x
->normal_gc
,
3142 /***********************************************************************
3144 ***********************************************************************/
3151 /* We used to only do this if Vx_no_window_manager was non-nil, but
3152 the ICCCM (section 4.1.6) says that the window's border pixmap
3153 and border pixel are window attributes which are "private to the
3154 client", so we can always change it to whatever we want. */
3156 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3157 f
->output_data
.x
->border_pixel
);
3159 x_update_cursor (f
, 1);
3163 frame_unhighlight (f
)
3166 /* We used to only do this if Vx_no_window_manager was non-nil, but
3167 the ICCCM (section 4.1.6) says that the window's border pixmap
3168 and border pixel are window attributes which are "private to the
3169 client", so we can always change it to whatever we want. */
3171 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3172 f
->output_data
.x
->border_tile
);
3174 x_update_cursor (f
, 1);
3177 /* The focus has changed. Update the frames as necessary to reflect
3178 the new situation. Note that we can't change the selected frame
3179 here, because the Lisp code we are interrupting might become confused.
3180 Each event gets marked with the frame in which it occurred, so the
3181 Lisp code can tell when the switch took place by examining the events. */
3184 x_new_focus_frame (dpyinfo
, frame
)
3185 struct x_display_info
*dpyinfo
;
3186 struct frame
*frame
;
3188 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3190 if (frame
!= dpyinfo
->x_focus_frame
)
3192 /* Set this before calling other routines, so that they see
3193 the correct value of x_focus_frame. */
3194 dpyinfo
->x_focus_frame
= frame
;
3196 if (old_focus
&& old_focus
->auto_lower
)
3197 x_lower_frame (old_focus
);
3200 selected_frame
= frame
;
3201 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3203 Fselect_window (selected_frame
->selected_window
, Qnil
);
3204 choose_minibuf_frame ();
3207 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3208 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3210 pending_autoraise_frame
= 0;
3213 x_frame_rehighlight (dpyinfo
);
3216 /* Handle FocusIn and FocusOut state changes for FRAME.
3217 If FRAME has focus and there exists more than one frame, puts
3218 a FOCUS_IN_EVENT into *BUFP. */
3221 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
)
3224 struct x_display_info
*dpyinfo
;
3225 struct frame
*frame
;
3226 struct input_event
*bufp
;
3228 if (type
== FocusIn
)
3230 if (dpyinfo
->x_focus_event_frame
!= frame
)
3232 x_new_focus_frame (dpyinfo
, frame
);
3233 dpyinfo
->x_focus_event_frame
= frame
;
3235 /* Don't stop displaying the initial startup message
3236 for a switch-frame event we don't need. */
3237 if (GC_NILP (Vterminal_frame
)
3238 && GC_CONSP (Vframe_list
)
3239 && !GC_NILP (XCDR (Vframe_list
)))
3241 bufp
->kind
= FOCUS_IN_EVENT
;
3242 XSETFRAME (bufp
->frame_or_window
, frame
);
3246 frame
->output_data
.x
->focus_state
|= state
;
3249 if (FRAME_XIC (frame
))
3250 XSetICFocus (FRAME_XIC (frame
));
3253 else if (type
== FocusOut
)
3255 frame
->output_data
.x
->focus_state
&= ~state
;
3257 if (dpyinfo
->x_focus_event_frame
== frame
)
3259 dpyinfo
->x_focus_event_frame
= 0;
3260 x_new_focus_frame (dpyinfo
, 0);
3264 if (FRAME_XIC (frame
))
3265 XUnsetICFocus (FRAME_XIC (frame
));
3270 /* The focus may have changed. Figure out if it is a real focus change,
3271 by checking both FocusIn/Out and Enter/LeaveNotify events.
3273 Returns FOCUS_IN_EVENT event in *BUFP. */
3276 x_detect_focus_change (dpyinfo
, event
, bufp
)
3277 struct x_display_info
*dpyinfo
;
3279 struct input_event
*bufp
;
3281 struct frame
*frame
;
3283 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3287 switch (event
->type
)
3292 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3294 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3296 if (event
->xcrossing
.detail
!= NotifyInferior
3297 && event
->xcrossing
.focus
3298 && ! (focus_state
& FOCUS_EXPLICIT
))
3299 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3301 dpyinfo
, frame
, bufp
);
3307 x_focus_changed (event
->type
,
3308 (event
->xfocus
.detail
== NotifyPointer
?
3309 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3310 dpyinfo
, frame
, bufp
);
3316 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3319 x_mouse_leave (dpyinfo
)
3320 struct x_display_info
*dpyinfo
;
3322 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3325 /* The focus has changed, or we have redirected a frame's focus to
3326 another frame (this happens when a frame uses a surrogate
3327 mini-buffer frame). Shift the highlight as appropriate.
3329 The FRAME argument doesn't necessarily have anything to do with which
3330 frame is being highlighted or un-highlighted; we only use it to find
3331 the appropriate X display info. */
3334 XTframe_rehighlight (frame
)
3335 struct frame
*frame
;
3337 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3341 x_frame_rehighlight (dpyinfo
)
3342 struct x_display_info
*dpyinfo
;
3344 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3346 if (dpyinfo
->x_focus_frame
)
3348 dpyinfo
->x_highlight_frame
3349 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3350 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3351 : dpyinfo
->x_focus_frame
);
3352 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3354 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3355 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3359 dpyinfo
->x_highlight_frame
= 0;
3361 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3364 frame_unhighlight (old_highlight
);
3365 if (dpyinfo
->x_highlight_frame
)
3366 frame_highlight (dpyinfo
->x_highlight_frame
);
3372 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3374 /* Initialize mode_switch_bit and modifier_meaning. */
3376 x_find_modifier_meanings (dpyinfo
)
3377 struct x_display_info
*dpyinfo
;
3379 int min_code
, max_code
;
3382 XModifierKeymap
*mods
;
3384 dpyinfo
->meta_mod_mask
= 0;
3385 dpyinfo
->shift_lock_mask
= 0;
3386 dpyinfo
->alt_mod_mask
= 0;
3387 dpyinfo
->super_mod_mask
= 0;
3388 dpyinfo
->hyper_mod_mask
= 0;
3391 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3393 min_code
= dpyinfo
->display
->min_keycode
;
3394 max_code
= dpyinfo
->display
->max_keycode
;
3397 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3398 min_code
, max_code
- min_code
+ 1,
3400 mods
= XGetModifierMapping (dpyinfo
->display
);
3402 /* Scan the modifier table to see which modifier bits the Meta and
3403 Alt keysyms are on. */
3405 int row
, col
; /* The row and column in the modifier table. */
3406 int found_alt_or_meta
;
3408 for (row
= 3; row
< 8; row
++)
3410 found_alt_or_meta
= 0;
3411 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3413 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3415 /* Zeroes are used for filler. Skip them. */
3419 /* Are any of this keycode's keysyms a meta key? */
3423 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3425 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3431 found_alt_or_meta
= 1;
3432 dpyinfo
->meta_mod_mask
|= (1 << row
);
3437 found_alt_or_meta
= 1;
3438 dpyinfo
->alt_mod_mask
|= (1 << row
);
3443 if (!found_alt_or_meta
)
3444 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3445 code_col
= syms_per_code
;
3446 col
= mods
->max_keypermod
;
3451 if (!found_alt_or_meta
)
3452 dpyinfo
->super_mod_mask
|= (1 << row
);
3453 code_col
= syms_per_code
;
3454 col
= mods
->max_keypermod
;
3458 /* Ignore this if it's not on the lock modifier. */
3459 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3460 dpyinfo
->shift_lock_mask
= LockMask
;
3461 code_col
= syms_per_code
;
3462 col
= mods
->max_keypermod
;
3471 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3472 if (! dpyinfo
->meta_mod_mask
)
3474 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3475 dpyinfo
->alt_mod_mask
= 0;
3478 /* If some keys are both alt and meta,
3479 make them just meta, not alt. */
3480 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3482 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3485 XFree ((char *) syms
);
3486 XFreeModifiermap (mods
);
3489 /* Convert between the modifier bits X uses and the modifier bits
3493 x_x_to_emacs_modifiers (dpyinfo
, state
)
3494 struct x_display_info
*dpyinfo
;
3497 EMACS_UINT mod_meta
= meta_modifier
;
3498 EMACS_UINT mod_alt
= alt_modifier
;
3499 EMACS_UINT mod_hyper
= hyper_modifier
;
3500 EMACS_UINT mod_super
= super_modifier
;
3503 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3504 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3505 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3506 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3507 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3508 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3509 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3510 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3513 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3514 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3515 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3516 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3517 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3518 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3522 x_emacs_to_x_modifiers (dpyinfo
, state
)
3523 struct x_display_info
*dpyinfo
;
3526 EMACS_UINT mod_meta
= meta_modifier
;
3527 EMACS_UINT mod_alt
= alt_modifier
;
3528 EMACS_UINT mod_hyper
= hyper_modifier
;
3529 EMACS_UINT mod_super
= super_modifier
;
3533 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3534 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3535 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3536 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3537 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3538 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3539 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3540 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3543 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3544 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3545 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3546 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3547 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3548 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3551 /* Convert a keysym to its name. */
3554 x_get_keysym_name (keysym
)
3560 value
= XKeysymToString (keysym
);
3568 /* Mouse clicks and mouse movement. Rah. */
3570 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3572 If the event is a button press, then note that we have grabbed
3576 construct_mouse_click (result
, event
, f
)
3577 struct input_event
*result
;
3578 XButtonEvent
*event
;
3581 /* Make the event type NO_EVENT; we'll change that when we decide
3583 result
->kind
= MOUSE_CLICK_EVENT
;
3584 result
->code
= event
->button
- Button1
;
3585 result
->timestamp
= event
->time
;
3586 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3588 | (event
->type
== ButtonRelease
3592 XSETINT (result
->x
, event
->x
);
3593 XSETINT (result
->y
, event
->y
);
3594 XSETFRAME (result
->frame_or_window
, f
);
3600 /* Function to report a mouse movement to the mainstream Emacs code.
3601 The input handler calls this.
3603 We have received a mouse movement event, which is given in *event.
3604 If the mouse is over a different glyph than it was last time, tell
3605 the mainstream emacs code by setting mouse_moved. If not, ask for
3606 another motion event, so we can check again the next time it moves. */
3608 static XMotionEvent last_mouse_motion_event
;
3609 static Lisp_Object last_mouse_motion_frame
;
3612 note_mouse_movement (frame
, event
)
3614 XMotionEvent
*event
;
3616 last_mouse_movement_time
= event
->time
;
3617 last_mouse_motion_event
= *event
;
3618 XSETFRAME (last_mouse_motion_frame
, frame
);
3620 if (!FRAME_X_OUTPUT (frame
))
3623 if (event
->window
!= FRAME_X_WINDOW (frame
))
3625 frame
->mouse_moved
= 1;
3626 last_mouse_scroll_bar
= Qnil
;
3627 note_mouse_highlight (frame
, -1, -1);
3628 last_mouse_glyph_frame
= 0;
3633 /* Has the mouse moved off the glyph it was on at the last sighting? */
3634 if (frame
!= last_mouse_glyph_frame
3635 || event
->x
< last_mouse_glyph
.x
3636 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3637 || event
->y
< last_mouse_glyph
.y
3638 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3640 frame
->mouse_moved
= 1;
3641 last_mouse_scroll_bar
= Qnil
;
3642 note_mouse_highlight (frame
, event
->x
, event
->y
);
3643 /* Remember which glyph we're now on. */
3644 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3645 last_mouse_glyph_frame
= frame
;
3653 /************************************************************************
3655 ************************************************************************/
3658 redo_mouse_highlight ()
3660 if (!NILP (last_mouse_motion_frame
)
3661 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3662 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3663 last_mouse_motion_event
.x
,
3664 last_mouse_motion_event
.y
);
3669 /* Return the current position of the mouse.
3670 *FP should be a frame which indicates which display to ask about.
3672 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3673 and *PART to the frame, window, and scroll bar part that the mouse
3674 is over. Set *X and *Y to the portion and whole of the mouse's
3675 position on the scroll bar.
3677 If the mouse movement started elsewhere, set *FP to the frame the
3678 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3681 Set *TIME to the server time-stamp for the time at which the mouse
3682 was at this position.
3684 Don't store anything if we don't have a valid set of values to report.
3686 This clears the mouse_moved flag, so we can wait for the next mouse
3690 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3693 Lisp_Object
*bar_window
;
3694 enum scroll_bar_part
*part
;
3696 unsigned long *time
;
3702 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3703 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3709 Window dummy_window
;
3712 Lisp_Object frame
, tail
;
3714 /* Clear the mouse-moved flag for every frame on this display. */
3715 FOR_EACH_FRAME (tail
, frame
)
3716 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3717 XFRAME (frame
)->mouse_moved
= 0;
3719 last_mouse_scroll_bar
= Qnil
;
3721 /* Figure out which root window we're on. */
3722 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3723 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3725 /* The root window which contains the pointer. */
3728 /* Trash which we can't trust if the pointer is on
3729 a different screen. */
3732 /* The position on that root window. */
3735 /* More trash we can't trust. */
3738 /* Modifier keys and pointer buttons, about which
3740 (unsigned int *) &dummy
);
3742 /* Now we have a position on the root; find the innermost window
3743 containing the pointer. */
3747 int parent_x
= 0, parent_y
= 0;
3751 /* XTranslateCoordinates can get errors if the window
3752 structure is changing at the same time this function
3753 is running. So at least we must not crash from them. */
3755 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3757 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3758 && FRAME_LIVE_P (last_mouse_frame
))
3760 /* If mouse was grabbed on a frame, give coords for that frame
3761 even if the mouse is now outside it. */
3762 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3764 /* From-window, to-window. */
3765 root
, FRAME_X_WINDOW (last_mouse_frame
),
3767 /* From-position, to-position. */
3768 root_x
, root_y
, &win_x
, &win_y
,
3772 f1
= last_mouse_frame
;
3778 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3780 /* From-window, to-window. */
3783 /* From-position, to-position. */
3784 root_x
, root_y
, &win_x
, &win_y
,
3789 if (child
== None
|| child
== win
)
3797 /* Now we know that:
3798 win is the innermost window containing the pointer
3799 (XTC says it has no child containing the pointer),
3800 win_x and win_y are the pointer's position in it
3801 (XTC did this the last time through), and
3802 parent_x and parent_y are the pointer's position in win's parent.
3803 (They are what win_x and win_y were when win was child.
3804 If win is the root window, it has no parent, and
3805 parent_{x,y} are invalid, but that's okay, because we'll
3806 never use them in that case.) */
3808 /* Is win one of our frames? */
3809 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3811 #ifdef USE_X_TOOLKIT
3812 /* If we end up with the menu bar window, say it's not
3815 && f1
->output_data
.x
->menubar_widget
3816 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3818 #endif /* USE_X_TOOLKIT */
3821 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3824 x_uncatch_errors ();
3826 /* If not, is it one of our scroll bars? */
3829 struct scroll_bar
*bar
;
3831 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3835 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3841 if (f1
== 0 && insist
> 0)
3842 f1
= SELECTED_FRAME ();
3846 /* Ok, we found a frame. Store all the values.
3847 last_mouse_glyph is a rectangle used to reduce the
3848 generation of mouse events. To not miss any motion
3849 events, we must divide the frame into rectangles of the
3850 size of the smallest character that could be displayed
3851 on it, i.e. into the same rectangles that matrices on
3852 the frame are divided into. */
3854 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
3855 last_mouse_glyph_frame
= f1
;
3860 XSETINT (*x
, win_x
);
3861 XSETINT (*y
, win_y
);
3862 *time
= last_mouse_movement_time
;
3872 /***********************************************************************
3874 ***********************************************************************/
3876 /* Scroll bar support. */
3878 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
3880 This can be called in GC, so we have to make sure to strip off mark
3883 static struct scroll_bar
*
3884 x_window_to_scroll_bar (display
, window_id
)
3890 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3891 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
3892 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
3894 for (tail
= Vframe_list
;
3895 XGCTYPE (tail
) == Lisp_Cons
;
3898 Lisp_Object frame
, bar
, condemned
;
3900 frame
= XCAR (tail
);
3901 /* All elements of Vframe_list should be frames. */
3902 if (! GC_FRAMEP (frame
))
3905 /* Scan this frame's scroll bar list for a scroll bar with the
3907 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3908 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3909 /* This trick allows us to search both the ordinary and
3910 condemned scroll bar lists with one loop. */
3911 ! GC_NILP (bar
) || (bar
= condemned
,
3914 bar
= XSCROLL_BAR (bar
)->next
)
3915 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
&&
3916 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
3917 return XSCROLL_BAR (bar
);
3924 #if defined USE_LUCID
3926 /* Return the Lucid menu bar WINDOW is part of. Return null
3927 if WINDOW is not part of a menu bar. */
3930 x_window_to_menu_bar (window
)
3935 for (tail
= Vframe_list
;
3936 XGCTYPE (tail
) == Lisp_Cons
;
3939 Lisp_Object frame
= XCAR (tail
);
3940 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
3942 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
3949 #endif /* USE_LUCID */
3952 /************************************************************************
3954 ************************************************************************/
3956 #ifdef USE_TOOLKIT_SCROLL_BARS
3958 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
3959 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
3960 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
3961 struct scroll_bar
*));
3962 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
3966 /* Lisp window being scrolled. Set when starting to interact with
3967 a toolkit scroll bar, reset to nil when ending the interaction. */
3969 static Lisp_Object window_being_scrolled
;
3971 /* Last scroll bar part sent in xm_scroll_callback. */
3973 static int last_scroll_bar_part
;
3975 /* Whether this is an Xaw with arrow-scrollbars. This should imply
3976 that movements of 1/20 of the screen size are mapped to up/down. */
3979 /* Id of action hook installed for scroll bars. */
3981 static XtActionHookId action_hook_id
;
3983 static Boolean xaw3d_arrow_scroll
;
3985 /* Whether the drag scrolling maintains the mouse at the top of the
3986 thumb. If not, resizing the thumb needs to be done more carefully
3987 to avoid jerkyness. */
3989 static Boolean xaw3d_pick_top
;
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;
4103 #ifdef USE_X_TOOLKIT
4104 x_activate_timeout_atimer ();
4107 /* Setting the event mask to zero means that the message will
4108 be sent to the client that created the window, and if that
4109 window no longer exists, no event will be sent. */
4110 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4115 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4119 x_scroll_bar_to_input_event (event
, ievent
)
4121 struct input_event
*ievent
;
4123 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4128 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4129 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4131 XSETWINDOW (window
, w
);
4132 f
= XFRAME (w
->frame
);
4134 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4135 ievent
->frame_or_window
= window
;
4138 ievent
->timestamp
= CurrentTime
;
4140 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4142 ievent
->part
= ev
->data
.l
[1];
4143 ievent
->code
= ev
->data
.l
[2];
4144 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4145 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4146 ievent
->modifiers
= 0;
4152 /* Minimum and maximum values used for Motif scroll bars. */
4154 #define XM_SB_MAX 10000000
4157 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4158 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4159 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4162 xm_scroll_callback (widget
, client_data
, call_data
)
4164 XtPointer client_data
, call_data
;
4166 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4167 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4168 int part
= -1, whole
= 0, portion
= 0;
4172 case XmCR_DECREMENT
:
4173 bar
->dragging
= Qnil
;
4174 part
= scroll_bar_up_arrow
;
4177 case XmCR_INCREMENT
:
4178 bar
->dragging
= Qnil
;
4179 part
= scroll_bar_down_arrow
;
4182 case XmCR_PAGE_DECREMENT
:
4183 bar
->dragging
= Qnil
;
4184 part
= scroll_bar_above_handle
;
4187 case XmCR_PAGE_INCREMENT
:
4188 bar
->dragging
= Qnil
;
4189 part
= scroll_bar_below_handle
;
4193 bar
->dragging
= Qnil
;
4194 part
= scroll_bar_to_top
;
4197 case XmCR_TO_BOTTOM
:
4198 bar
->dragging
= Qnil
;
4199 part
= scroll_bar_to_bottom
;
4206 /* Get the slider size. */
4208 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4211 whole
= XM_SB_MAX
- slider_size
;
4212 portion
= min (cs
->value
, whole
);
4213 part
= scroll_bar_handle
;
4214 bar
->dragging
= make_number (cs
->value
);
4218 case XmCR_VALUE_CHANGED
:
4224 window_being_scrolled
= bar
->window
;
4225 last_scroll_bar_part
= part
;
4226 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4231 #else /* !USE_MOTIF, i.e. Xaw or GTK */
4233 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4234 bar widget. DATA is a pointer to the scroll_bar structure. */
4237 xg_scroll_callback (widget
, data
)
4241 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4247 int part
= -1, whole
= 0, portion
= 0;
4248 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4250 position
= gtk_adjustment_get_value (adj
);
4252 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4255 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4257 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4263 if (xg_ignore_gtk_scrollbar
) return;
4265 diff
= (int) (position
- previous
);
4267 if (diff
== (int) adj
->step_increment
)
4269 part
= scroll_bar_down_arrow
;
4270 bar
->dragging
= Qnil
;
4272 else if (-diff
== (int) adj
->step_increment
)
4274 part
= scroll_bar_up_arrow
;
4275 bar
->dragging
= Qnil
;
4277 else if (diff
== (int) adj
->page_increment
)
4279 part
= scroll_bar_below_handle
;
4280 bar
->dragging
= Qnil
;
4282 else if (-diff
== (int) adj
->page_increment
)
4284 part
= scroll_bar_above_handle
;
4285 bar
->dragging
= Qnil
;
4289 part
= scroll_bar_handle
;
4290 whole
= adj
->upper
- adj
->page_size
;
4291 portion
= min ((int)position
, whole
);
4292 bar
->dragging
= make_number ((int)portion
);
4297 window_being_scrolled
= bar
->window
;
4298 last_scroll_bar_part
= part
;
4299 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4303 #else /* not USE_GTK */
4305 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4306 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4307 scroll bar struct. CALL_DATA is a pointer to a float saying where
4311 xaw_jump_callback (widget
, client_data
, call_data
)
4313 XtPointer client_data
, call_data
;
4315 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4316 float top
= *(float *) call_data
;
4318 int whole
, portion
, height
;
4321 /* Get the size of the thumb, a value between 0 and 1. */
4323 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4327 portion
= shown
< 1 ? top
* whole
: 0;
4329 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
4330 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4331 the bottom, so we force the scrolling whenever we see that we're
4332 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4333 we try to ensure that we always stay two pixels away from the
4335 part
= scroll_bar_down_arrow
;
4337 part
= scroll_bar_handle
;
4339 window_being_scrolled
= bar
->window
;
4340 bar
->dragging
= make_number (portion
);
4341 last_scroll_bar_part
= part
;
4342 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4346 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4347 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4348 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4349 the scroll bar. CALL_DATA is an integer specifying the action that
4350 has taken place. Its magnitude is in the range 0..height of the
4351 scroll bar. Negative values mean scroll towards buffer start.
4352 Values < height of scroll bar mean line-wise movement. */
4355 xaw_scroll_callback (widget
, client_data
, call_data
)
4357 XtPointer client_data
, call_data
;
4359 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4360 /* The position really is stored cast to a pointer. */
4361 int position
= (long) call_data
;
4365 /* Get the height of the scroll bar. */
4367 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4370 if (abs (position
) >= height
)
4371 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4373 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4374 it maps line-movement to call_data = max(5, height/20). */
4375 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
4376 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4378 part
= scroll_bar_move_ratio
;
4380 window_being_scrolled
= bar
->window
;
4381 bar
->dragging
= Qnil
;
4382 last_scroll_bar_part
= part
;
4383 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4386 #endif /* not USE_GTK */
4387 #endif /* not USE_MOTIF */
4389 #define SCROLL_BAR_NAME "verticalScrollBar"
4391 /* Create the widget for scroll bar BAR on frame F. Record the widget
4392 and X window of the scroll bar in BAR. */
4396 x_create_toolkit_scroll_bar (f
, bar
)
4398 struct scroll_bar
*bar
;
4400 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4403 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4408 #else /* not USE_GTK */
4411 x_create_toolkit_scroll_bar (f
, bar
)
4413 struct scroll_bar
*bar
;
4419 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4420 unsigned long pixel
;
4425 /* Set resources. Create the widget. */
4426 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4427 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4428 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4429 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4430 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4431 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4432 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4434 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4437 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4441 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4444 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4448 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4449 scroll_bar_name
, av
, ac
);
4451 /* Add one callback for everything that can happen. */
4452 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4454 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4456 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4458 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4460 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4462 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4464 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4467 /* Realize the widget. Only after that is the X window created. */
4468 XtRealizeWidget (widget
);
4470 /* Set the cursor to an arrow. I didn't find a resource to do that.
4471 And I'm wondering why it hasn't an arrow cursor by default. */
4472 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4473 f
->output_data
.x
->nontext_cursor
);
4475 #else /* !USE_MOTIF i.e. use Xaw */
4477 /* Set resources. Create the widget. The background of the
4478 Xaw3d scroll bar widget is a little bit light for my taste.
4479 We don't alter it here to let users change it according
4480 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4481 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4482 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4483 /* For smoother scrolling with Xaw3d -sm */
4484 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4486 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4489 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4493 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4496 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4500 /* Top/bottom shadow colors. */
4502 /* Allocate them, if necessary. */
4503 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4505 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4506 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4507 &pixel
, 1.2, 0x8000))
4509 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4511 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4513 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4514 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4515 &pixel
, 0.6, 0x4000))
4517 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4520 #ifdef XtNbeNiceToColormap
4521 /* Tell the toolkit about them. */
4522 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4523 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4524 /* We tried to allocate a color for the top/bottom shadow, and
4525 failed, so tell Xaw3d to use dithering instead. */
4527 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4531 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4532 be more consistent with other emacs 3d colors, and since Xaw3d is
4533 not good at dealing with allocation failure. */
4535 /* This tells Xaw3d to use real colors instead of dithering for
4537 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4540 /* Specify the colors. */
4541 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4544 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4547 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4550 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4556 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4557 f
->output_data
.x
->edit_widget
, av
, ac
);
4561 char *val
= initial
;
4562 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4563 #ifdef XtNarrowScrollbars
4564 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4566 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4567 if (xaw3d_arrow_scroll
|| val
== initial
)
4568 { /* ARROW_SCROLL */
4569 xaw3d_arrow_scroll
= True
;
4570 /* Isn't that just a personal preference ? --Stef */
4571 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4575 /* Define callbacks. */
4576 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4577 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4580 /* Realize the widget. Only after that is the X window created. */
4581 XtRealizeWidget (widget
);
4583 #endif /* !USE_MOTIF */
4585 /* Install an action hook that lets us detect when the user
4586 finishes interacting with a scroll bar. */
4587 if (action_hook_id
== 0)
4588 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4590 /* Remember X window and widget in the scroll bar vector. */
4591 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4592 xwindow
= XtWindow (widget
);
4593 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
4597 #endif /* not USE_GTK */
4600 /* Set the thumb size and position of scroll bar BAR. We are currently
4601 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4605 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4606 struct scroll_bar
*bar
;
4607 int portion
, position
, whole
;
4609 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4612 #else /* not USE_GTK */
4614 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4615 struct scroll_bar
*bar
;
4616 int portion
, position
, whole
;
4618 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4619 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4626 /* We use an estimate of 30 chars per line rather than the real
4627 `portion' value. This has the disadvantage that the thumb size
4628 is not very representative, but it makes our life a lot easier.
4629 Otherwise, we have to constantly adjust the thumb size, which
4630 we can't always do quickly enough: while dragging, the size of
4631 the thumb might prevent the user from dragging the thumb all the
4632 way to the end. but Motif and some versions of Xaw3d don't allow
4633 updating the thumb size while dragging. Also, even if we can update
4634 its size, the update will often happen too late.
4635 If you don't believe it, check out revision 1.650 of xterm.c to see
4636 what hoops we were going through and the still poor behavior we got. */
4637 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4638 /* When the thumb is at the bottom, position == whole.
4639 So we need to increase `whole' to make space for the thumb. */
4646 top
= (float) position
/ whole
;
4647 shown
= (float) portion
/ whole
;
4650 if (NILP (bar
->dragging
))
4654 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4655 is the scroll bar's maximum and MIN is the scroll bar's minimum
4657 size
= shown
* XM_SB_MAX
;
4658 size
= min (size
, XM_SB_MAX
);
4659 size
= max (size
, 1);
4661 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4662 value
= top
* XM_SB_MAX
;
4663 value
= min (value
, XM_SB_MAX
- size
);
4665 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4667 #else /* !USE_MOTIF i.e. use Xaw */
4673 top
= (float) position
/ whole
;
4674 shown
= (float) portion
/ whole
;
4678 float old_top
, old_shown
;
4680 XtVaGetValues (widget
,
4681 XtNtopOfThumb
, &old_top
,
4682 XtNshown
, &old_shown
,
4686 /* Massage the top+shown values. */
4687 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4688 top
= max (0, min (1, top
));
4691 /* Keep two pixels available for moving the thumb down. */
4692 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4694 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4695 check that your system's configuration file contains a define
4696 for `NARROWPROTO'. See s/freebsd.h for an example. */
4697 if (top
!= old_top
|| shown
!= old_shown
)
4699 if (NILP (bar
->dragging
))
4700 XawScrollbarSetThumb (widget
, top
, shown
);
4703 /* Try to make the scrolling a tad smoother. */
4704 if (!xaw3d_pick_top
)
4705 shown
= min (shown
, old_shown
);
4707 XawScrollbarSetThumb (widget
, top
, shown
);
4711 #endif /* !USE_MOTIF */
4715 #endif /* not USE_GTK */
4717 #endif /* USE_TOOLKIT_SCROLL_BARS */
4721 /************************************************************************
4722 Scroll bars, general
4723 ************************************************************************/
4725 /* Create a scroll bar and return the scroll bar vector for it. W is
4726 the Emacs window on which to create the scroll bar. TOP, LEFT,
4727 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4730 static struct scroll_bar
*
4731 x_scroll_bar_create (w
, top
, left
, width
, height
)
4733 int top
, left
, width
, height
;
4735 struct frame
*f
= XFRAME (w
->frame
);
4736 struct scroll_bar
*bar
4737 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
4741 #ifdef USE_TOOLKIT_SCROLL_BARS
4742 x_create_toolkit_scroll_bar (f
, bar
);
4743 #else /* not USE_TOOLKIT_SCROLL_BARS */
4745 XSetWindowAttributes a
;
4749 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4750 if (a
.background_pixel
== -1)
4751 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
4753 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4754 | ButtonMotionMask
| PointerMotionHintMask
4756 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4758 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4760 /* Clear the area of W that will serve as a scroll bar. This is
4761 for the case that a window has been split horizontally. In
4762 this case, no clear_frame is generated to reduce flickering. */
4763 if (width
> 0 && height
> 0)
4764 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4766 window_box_height (w
), False
);
4768 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4769 /* Position and size of scroll bar. */
4770 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4772 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4774 /* Border width, depth, class, and visual. */
4781 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
4783 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4785 XSETWINDOW (bar
->window
, w
);
4786 XSETINT (bar
->top
, top
);
4787 XSETINT (bar
->left
, left
);
4788 XSETINT (bar
->width
, width
);
4789 XSETINT (bar
->height
, height
);
4790 XSETINT (bar
->start
, 0);
4791 XSETINT (bar
->end
, 0);
4792 bar
->dragging
= Qnil
;
4794 /* Add bar to its frame's list of scroll bars. */
4795 bar
->next
= FRAME_SCROLL_BARS (f
);
4797 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4798 if (!NILP (bar
->next
))
4799 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4801 /* Map the window/widget. */
4802 #ifdef USE_TOOLKIT_SCROLL_BARS
4805 xg_update_scrollbar_pos (f
,
4806 SCROLL_BAR_X_WINDOW (bar
),
4808 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4809 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4811 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
4812 #else /* not USE_GTK */
4813 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4814 XtConfigureWidget (scroll_bar
,
4815 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4817 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4818 max (height
, 1), 0);
4819 XtMapWidget (scroll_bar
);
4820 #endif /* not USE_GTK */
4822 #else /* not USE_TOOLKIT_SCROLL_BARS */
4823 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4824 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4831 /* Draw BAR's handle in the proper position.
4833 If the handle is already drawn from START to END, don't bother
4834 redrawing it, unless REBUILD is non-zero; in that case, always
4835 redraw it. (REBUILD is handy for drawing the handle after expose
4838 Normally, we want to constrain the start and end of the handle to
4839 fit inside its rectangle, but if the user is dragging the scroll
4840 bar handle, we want to let them drag it down all the way, so that
4841 the bar's top is as far down as it goes; otherwise, there's no way
4842 to move to the very end of the buffer. */
4844 #ifndef USE_TOOLKIT_SCROLL_BARS
4847 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4848 struct scroll_bar
*bar
;
4852 int dragging
= ! NILP (bar
->dragging
);
4853 Window w
= SCROLL_BAR_X_WINDOW (bar
);
4854 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4855 GC gc
= f
->output_data
.x
->normal_gc
;
4857 /* If the display is already accurate, do nothing. */
4859 && start
== XINT (bar
->start
)
4860 && end
== XINT (bar
->end
))
4866 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
4867 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
4868 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
4870 /* Make sure the values are reasonable, and try to preserve
4871 the distance between start and end. */
4873 int length
= end
- start
;
4877 else if (start
> top_range
)
4879 end
= start
+ length
;
4883 else if (end
> top_range
&& ! dragging
)
4887 /* Store the adjusted setting in the scroll bar. */
4888 XSETINT (bar
->start
, start
);
4889 XSETINT (bar
->end
, end
);
4891 /* Clip the end position, just for display. */
4892 if (end
> top_range
)
4895 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
4896 below top positions, to make sure the handle is always at least
4897 that many pixels tall. */
4898 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4900 /* Draw the empty space above the handle. Note that we can't clear
4901 zero-height areas; that means "clear to end of window." */
4903 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4904 /* x, y, width, height, and exposures. */
4905 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4906 VERTICAL_SCROLL_BAR_TOP_BORDER
,
4907 inside_width
, start
,
4910 /* Change to proper foreground color if one is specified. */
4911 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4912 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4913 f
->output_data
.x
->scroll_bar_foreground_pixel
);
4915 /* Draw the handle itself. */
4916 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
4917 /* x, y, width, height */
4918 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4919 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
4920 inside_width
, end
- start
);
4922 /* Restore the foreground color of the GC if we changed it above. */
4923 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4924 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4925 f
->output_data
.x
->foreground_pixel
);
4927 /* Draw the empty space below the handle. Note that we can't
4928 clear zero-height areas; that means "clear to end of window." */
4929 if (end
< inside_height
)
4930 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4931 /* x, y, width, height, and exposures. */
4932 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4933 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
4934 inside_width
, inside_height
- end
,
4942 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4944 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4948 x_scroll_bar_remove (bar
)
4949 struct scroll_bar
*bar
;
4951 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4954 #ifdef USE_TOOLKIT_SCROLL_BARS
4956 xg_remove_scroll_bar (f
, SCROLL_BAR_X_WINDOW (bar
));
4957 #else /* not USE_GTK */
4958 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
4959 #endif /* not USE_GTK */
4961 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
4964 /* Disassociate this scroll bar from its window. */
4965 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4971 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4972 that we are displaying PORTION characters out of a total of WHOLE
4973 characters, starting at POSITION. If WINDOW has no scroll bar,
4977 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
4979 int portion
, whole
, position
;
4981 struct frame
*f
= XFRAME (w
->frame
);
4982 struct scroll_bar
*bar
;
4983 int top
, height
, left
, sb_left
, width
, sb_width
;
4984 int window_y
, window_height
;
4986 /* Get window dimensions. */
4987 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4989 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4990 height
= window_height
;
4992 /* Compute the left edge of the scroll bar area. */
4993 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4995 /* Compute the width of the scroll bar which might be less than
4996 the width of the area reserved for the scroll bar. */
4997 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4998 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5002 /* Compute the left edge of the scroll bar. */
5003 #ifdef USE_TOOLKIT_SCROLL_BARS
5004 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5006 (WINDOW_RIGHTMOST_P (w
)
5007 ? width
- sb_width
- (width
- sb_width
) / 2
5011 (WINDOW_LEFTMOST_P (w
)
5012 ? (width
- sb_width
) / 2
5013 : width
- sb_width
));
5015 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5016 sb_left
= left
+ width
- sb_width
;
5021 /* Does the scroll bar exist yet? */
5022 if (NILP (w
->vertical_scroll_bar
))
5024 if (width
> 0 && height
> 0)
5027 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5028 left
, top
, width
, height
, False
);
5032 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5036 /* It may just need to be moved and resized. */
5037 unsigned int mask
= 0;
5039 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5043 if (sb_left
!= XINT (bar
->left
))
5045 if (top
!= XINT (bar
->top
))
5047 if (sb_width
!= XINT (bar
->width
))
5049 if (height
!= XINT (bar
->height
))
5052 #ifdef USE_TOOLKIT_SCROLL_BARS
5054 /* Move/size the scroll bar widget. */
5057 /* Since toolkit scroll bars are smaller than the space reserved
5058 for them on the frame, we have to clear "under" them. */
5059 if (width
> 0 && height
> 0)
5060 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5061 left
, top
, width
, height
, False
);
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,
5069 #else /* not USE_GTK */
5070 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5071 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5073 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5074 max (height
, 1), 0);
5075 #endif /* not USE_GTK */
5077 #else /* not USE_TOOLKIT_SCROLL_BARS */
5079 /* Clear areas not covered by the scroll bar because of
5080 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5081 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5083 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5084 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5086 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5087 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5088 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5092 /* Clear areas not covered by the scroll bar because it's not as
5093 wide as the area reserved for it. This makes sure a
5094 previous mode line display is cleared after C-x 2 C-x 1, for
5097 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5098 int rest
= area_width
- sb_width
;
5099 if (rest
> 0 && height
> 0)
5101 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5102 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5103 left
+ area_width
- rest
, top
,
5104 rest
, height
, False
);
5106 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5107 left
, top
, rest
, height
, False
);
5111 /* Move/size the scroll bar window. */
5116 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5118 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5120 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
5124 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5126 /* Remember new settings. */
5127 XSETINT (bar
->left
, sb_left
);
5128 XSETINT (bar
->top
, top
);
5129 XSETINT (bar
->width
, sb_width
);
5130 XSETINT (bar
->height
, height
);
5135 #ifdef USE_TOOLKIT_SCROLL_BARS
5136 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5137 #else /* not USE_TOOLKIT_SCROLL_BARS */
5138 /* Set the scroll bar's current state, unless we're currently being
5140 if (NILP (bar
->dragging
))
5142 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5145 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5148 int start
= ((double) position
* top_range
) / whole
;
5149 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5150 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5153 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5155 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5159 /* The following three hooks are used when we're doing a thorough
5160 redisplay of the frame. We don't explicitly know which scroll bars
5161 are going to be deleted, because keeping track of when windows go
5162 away is a real pain - "Can you say set-window-configuration, boys
5163 and girls?" Instead, we just assert at the beginning of redisplay
5164 that *all* scroll bars are to be removed, and then save a scroll bar
5165 from the fiery pit when we actually redisplay its window. */
5167 /* Arrange for all scroll bars on FRAME to be removed at the next call
5168 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5169 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5172 XTcondemn_scroll_bars (frame
)
5175 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5176 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5179 bar
= FRAME_SCROLL_BARS (frame
);
5180 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5181 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5182 XSCROLL_BAR (bar
)->prev
= Qnil
;
5183 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5184 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5185 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5190 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5191 Note that WINDOW isn't necessarily condemned at all. */
5194 XTredeem_scroll_bar (window
)
5195 struct window
*window
;
5197 struct scroll_bar
*bar
;
5200 /* We can't redeem this window's scroll bar if it doesn't have one. */
5201 if (NILP (window
->vertical_scroll_bar
))
5204 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5206 /* Unlink it from the condemned list. */
5207 f
= XFRAME (WINDOW_FRAME (window
));
5208 if (NILP (bar
->prev
))
5210 /* If the prev pointer is nil, it must be the first in one of
5212 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5213 /* It's not condemned. Everything's fine. */
5215 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5216 window
->vertical_scroll_bar
))
5217 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5219 /* If its prev pointer is nil, it must be at the front of
5220 one or the other! */
5224 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5226 if (! NILP (bar
->next
))
5227 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5229 bar
->next
= FRAME_SCROLL_BARS (f
);
5231 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5232 if (! NILP (bar
->next
))
5233 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5236 /* Remove all scroll bars on FRAME that haven't been saved since the
5237 last call to `*condemn_scroll_bars_hook'. */
5240 XTjudge_scroll_bars (f
)
5243 Lisp_Object bar
, next
;
5245 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5247 /* Clear out the condemned list now so we won't try to process any
5248 more events on the hapless scroll bars. */
5249 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5251 for (; ! NILP (bar
); bar
= next
)
5253 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5255 x_scroll_bar_remove (b
);
5258 b
->next
= b
->prev
= Qnil
;
5261 /* Now there should be no references to the condemned scroll bars,
5262 and they should get garbage-collected. */
5266 #ifndef USE_TOOLKIT_SCROLL_BARS
5267 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5268 is a no-op when using toolkit scroll bars.
5270 This may be called from a signal handler, so we have to ignore GC
5274 x_scroll_bar_expose (bar
, event
)
5275 struct scroll_bar
*bar
;
5278 Window w
= SCROLL_BAR_X_WINDOW (bar
);
5279 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5280 GC gc
= f
->output_data
.x
->normal_gc
;
5281 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5285 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
5287 /* Switch to scroll bar foreground color. */
5288 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5289 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5290 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5292 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5293 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5295 /* x, y, width, height */
5297 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
5298 XINT (bar
->height
) - 1);
5300 /* Restore the foreground color of the GC if we changed it above. */
5301 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5302 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5303 f
->output_data
.x
->foreground_pixel
);
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 /* The main X event-reading loop - XTread_socket. */
5541 /* Time stamp of enter window event. This is only used by XTread_socket,
5542 but we have to put it out here, since static variables within functions
5543 sometimes don't work. */
5545 static Time enter_timestamp
;
5548 /* This holds the state XLookupString needs to implement dead keys
5549 and other tricks known as "compose processing". _X Window System_
5550 says that a portable program can't use this, but Stephen Gildea assures
5551 me that letting the compiler initialize it to zeros will work okay.
5553 This must be defined outside of XTread_socket, for the same reasons
5554 given for enter_timestamp, above. */
5556 static XComposeStatus compose_status
;
5558 /* Record the last 100 characters stored
5559 to help debug the loss-of-chars-during-GC problem. */
5561 static int temp_index
;
5562 static short temp_buffer
[100];
5564 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5565 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5567 temp_buffer[temp_index++] = (keysym)
5569 /* Set this to nonzero to fake an "X I/O error"
5570 on a particular display. */
5572 struct x_display_info
*XTread_socket_fake_io_error
;
5574 /* When we find no input here, we occasionally do a no-op command
5575 to verify that the X server is still running and we can still talk with it.
5576 We try all the open displays, one by one.
5577 This variable is used for cycling thru the displays. */
5579 static struct x_display_info
*next_noop_dpyinfo
;
5581 #define SET_SAVED_MENU_EVENT(size) \
5584 if (f->output_data.x->saved_menu_event == 0) \
5585 f->output_data.x->saved_menu_event \
5586 = (XEvent *) xmalloc (sizeof (XEvent)); \
5587 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5588 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5589 XSETFRAME (inev.ie.frame_or_window, f); \
5593 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5594 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5604 /* Filter events for the current X input method.
5605 DPYINFO is the display this event is for.
5606 EVENT is the X event to filter.
5608 Returns non-zero if the event was filtered, caller shall not process
5610 Returns zero if event is wasn't filtered. */
5614 x_filter_event (dpyinfo
, event
)
5615 struct x_display_info
*dpyinfo
;
5618 /* XFilterEvent returns non-zero if the input method has
5619 consumed the event. We pass the frame's X window to
5620 XFilterEvent because that's the one for which the IC
5623 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5624 event
->xclient
.window
);
5626 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5631 static int current_count
;
5632 static int current_finish
;
5633 static struct input_event
*current_hold_quit
;
5635 /* This is the filter function invoked by the GTK event loop.
5636 It is invoked before the XEvent is translated to a GdkEvent,
5637 so we have a chance to act on the event before GTK. */
5638 static GdkFilterReturn
5639 event_handler_gdk (gxev
, ev
, data
)
5644 XEvent
*xev
= (XEvent
*) gxev
;
5646 if (current_count
>= 0)
5648 struct x_display_info
*dpyinfo
;
5650 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5653 /* Filter events for the current X input method.
5654 GTK calls XFilterEvent but not for key press and release,
5655 so we do it here. */
5656 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5657 if (dpyinfo
&& x_filter_event (dpyinfo
, xev
))
5658 return GDK_FILTER_REMOVE
;
5662 current_finish
= X_EVENT_NORMAL
;
5666 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5671 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5673 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5674 return GDK_FILTER_REMOVE
;
5676 return GDK_FILTER_CONTINUE
;
5678 #endif /* USE_GTK */
5681 /* Handles the XEvent EVENT on display DPYINFO.
5683 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5684 *FINISH is zero if caller should continue reading events.
5685 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5687 We return the number of characters stored into the buffer. */
5690 handle_one_xevent (dpyinfo
, eventp
, finish
, hold_quit
)
5691 struct x_display_info
*dpyinfo
;
5694 struct input_event
*hold_quit
;
5697 struct input_event ie
;
5698 struct selection_input_event sie
;
5704 struct coding_system coding
;
5705 XEvent event
= *eventp
;
5707 *finish
= X_EVENT_NORMAL
;
5709 EVENT_INIT (inev
.ie
);
5710 inev
.ie
.kind
= NO_EVENT
;
5717 if (event
.xclient
.message_type
5718 == dpyinfo
->Xatom_wm_protocols
5719 && event
.xclient
.format
== 32)
5721 if (event
.xclient
.data
.l
[0]
5722 == dpyinfo
->Xatom_wm_take_focus
)
5724 /* Use x_any_window_to_frame because this
5725 could be the shell widget window
5726 if the frame has no title bar. */
5727 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5729 /* Not quite sure this is needed -pd */
5730 if (f
&& FRAME_XIC (f
))
5731 XSetICFocus (FRAME_XIC (f
));
5733 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5734 instructs the WM to set the input focus automatically for
5735 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5736 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5737 it has set the focus. So, XSetInputFocus below is not
5740 The call to XSetInputFocus below has also caused trouble. In
5741 cases where the XSetInputFocus done by the WM and the one
5742 below are temporally close (on a fast machine), the call
5743 below can generate additional FocusIn events which confuse
5746 /* Since we set WM_TAKE_FOCUS, we must call
5747 XSetInputFocus explicitly. But not if f is null,
5748 since that might be an event for a deleted frame. */
5751 Display
*d
= event
.xclient
.display
;
5752 /* Catch and ignore errors, in case window has been
5753 iconified by a window manager such as GWM. */
5755 XSetInputFocus (d
, event
.xclient
.window
,
5756 /* The ICCCM says this is
5757 the only valid choice. */
5759 event
.xclient
.data
.l
[1]);
5760 /* This is needed to detect the error
5761 if there is an error. */
5763 x_uncatch_errors ();
5765 /* Not certain about handling scroll bars here */
5770 if (event
.xclient
.data
.l
[0]
5771 == dpyinfo
->Xatom_wm_save_yourself
)
5773 /* Save state modify the WM_COMMAND property to
5774 something which can reinstate us. This notifies
5775 the session manager, who's looking for such a
5776 PropertyNotify. Can restart processing when
5777 a keyboard or mouse event arrives. */
5778 /* If we have a session manager, don't set this.
5779 KDE will then start two Emacsen, one for the
5780 session manager and one for this. */
5782 if (! x_session_have_connection ())
5785 f
= x_top_window_to_frame (dpyinfo
,
5786 event
.xclient
.window
);
5787 /* This is just so we only give real data once
5788 for a single Emacs process. */
5789 if (f
== SELECTED_FRAME ())
5790 XSetCommand (FRAME_X_DISPLAY (f
),
5791 event
.xclient
.window
,
5792 initial_argv
, initial_argc
);
5794 XSetCommand (FRAME_X_DISPLAY (f
),
5795 event
.xclient
.window
,
5801 if (event
.xclient
.data
.l
[0]
5802 == dpyinfo
->Xatom_wm_delete_window
)
5804 f
= x_any_window_to_frame (dpyinfo
,
5805 event
.xclient
.window
);
5807 goto OTHER
; /* May be a dialog that is to be removed */
5809 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5810 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5817 if (event
.xclient
.message_type
5818 == dpyinfo
->Xatom_wm_configure_denied
)
5823 if (event
.xclient
.message_type
5824 == dpyinfo
->Xatom_wm_window_moved
)
5827 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5829 new_x
= event
.xclient
.data
.s
[0];
5830 new_y
= event
.xclient
.data
.s
[1];
5834 f
->left_pos
= new_x
;
5841 if (event
.xclient
.message_type
5842 == dpyinfo
->Xatom_editres
)
5844 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5846 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5850 #endif /* HACK_EDITRES */
5852 if ((event
.xclient
.message_type
5853 == dpyinfo
->Xatom_DONE
)
5854 || (event
.xclient
.message_type
5855 == dpyinfo
->Xatom_PAGE
))
5857 /* Ghostview job completed. Kill it. We could
5858 reply with "Next" if we received "Page", but we
5859 currently never do because we are interested in
5860 images, only, which should have 1 page. */
5861 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5862 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5865 x_kill_gs_process (pixmap
, f
);
5866 expose_frame (f
, 0, 0, 0, 0);
5870 #ifdef USE_TOOLKIT_SCROLL_BARS
5871 /* Scroll bar callbacks send a ClientMessage from which
5872 we construct an input_event. */
5873 if (event
.xclient
.message_type
5874 == dpyinfo
->Xatom_Scrollbar
)
5876 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
5877 *finish
= X_EVENT_GOTO_OUT
;
5880 #endif /* USE_TOOLKIT_SCROLL_BARS */
5882 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5885 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
5886 *finish
= X_EVENT_DROP
;
5890 case SelectionNotify
:
5891 last_user_time
= event
.xselection
.time
;
5892 #ifdef USE_X_TOOLKIT
5893 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5895 #endif /* not USE_X_TOOLKIT */
5896 x_handle_selection_notify (&event
.xselection
);
5899 case SelectionClear
: /* Someone has grabbed ownership. */
5900 last_user_time
= event
.xselectionclear
.time
;
5901 #ifdef USE_X_TOOLKIT
5902 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5904 #endif /* USE_X_TOOLKIT */
5906 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
5908 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
5909 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5910 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5911 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5912 inev
.ie
.frame_or_window
= Qnil
;
5916 case SelectionRequest
: /* Someone wants our selection. */
5917 last_user_time
= event
.xselectionrequest
.time
;
5918 #ifdef USE_X_TOOLKIT
5919 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
5921 #endif /* USE_X_TOOLKIT */
5923 XSelectionRequestEvent
*eventp
5924 = (XSelectionRequestEvent
*) &event
;
5926 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
5927 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5928 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
5929 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5930 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
5931 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
5932 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5933 inev
.ie
.frame_or_window
= Qnil
;
5937 case PropertyNotify
:
5938 last_user_time
= event
.xproperty
.time
;
5939 #if 0 /* This is plain wrong. In the case that we are waiting for a
5940 PropertyNotify used as an ACK in incremental selection
5941 transfer, the property will be on the receiver's window. */
5942 #if defined USE_X_TOOLKIT
5943 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
5947 x_handle_property_notify (&event
.xproperty
);
5950 case ReparentNotify
:
5951 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
5955 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
5956 x_real_positions (f
, &x
, &y
);
5960 /* Perhaps reparented due to a WM restart. Reset this. */
5961 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
5962 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
5967 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
5970 x_check_fullscreen (f
);
5973 /* This seems to be needed for GTK 2.6. */
5974 x_clear_area (event
.xexpose
.display
,
5975 event
.xexpose
.window
,
5976 event
.xexpose
.x
, event
.xexpose
.y
,
5977 event
.xexpose
.width
, event
.xexpose
.height
,
5980 if (f
->async_visible
== 0)
5982 f
->async_visible
= 1;
5983 f
->async_iconified
= 0;
5984 f
->output_data
.x
->has_been_visible
= 1;
5985 SET_FRAME_GARBAGED (f
);
5989 event
.xexpose
.x
, event
.xexpose
.y
,
5990 event
.xexpose
.width
, event
.xexpose
.height
);
5994 #ifndef USE_TOOLKIT_SCROLL_BARS
5995 struct scroll_bar
*bar
;
5997 #if defined USE_LUCID
5998 /* Submenus of the Lucid menu bar aren't widgets
5999 themselves, so there's no way to dispatch events
6000 to them. Recognize this case separately. */
6003 = x_window_to_menu_bar (event
.xexpose
.window
);
6005 xlwmenu_redisplay (widget
);
6007 #endif /* USE_LUCID */
6009 #ifdef USE_TOOLKIT_SCROLL_BARS
6010 /* Dispatch event to the widget. */
6012 #else /* not USE_TOOLKIT_SCROLL_BARS */
6013 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6014 event
.xexpose
.window
);
6017 x_scroll_bar_expose (bar
, &event
);
6018 #ifdef USE_X_TOOLKIT
6021 #endif /* USE_X_TOOLKIT */
6022 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6026 case GraphicsExpose
: /* This occurs when an XCopyArea's
6027 source area was obscured or not
6029 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6033 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6034 event
.xgraphicsexpose
.width
,
6035 event
.xgraphicsexpose
.height
);
6037 #ifdef USE_X_TOOLKIT
6040 #endif /* USE_X_TOOLKIT */
6043 case NoExpose
: /* This occurs when an XCopyArea's
6044 source area was completely
6049 /* Redo the mouse-highlight after the tooltip has gone. */
6050 if (event
.xmap
.window
== tip_window
)
6053 redo_mouse_highlight ();
6056 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6057 if (f
) /* F may no longer exist if
6058 the frame was deleted. */
6060 /* While a frame is unmapped, display generation is
6061 disabled; you don't want to spend time updating a
6062 display that won't ever be seen. */
6063 f
->async_visible
= 0;
6064 /* We can't distinguish, from the event, whether the window
6065 has become iconified or invisible. So assume, if it
6066 was previously visible, than now it is iconified.
6067 But x_make_frame_invisible clears both
6068 the visible flag and the iconified flag;
6069 and that way, we know the window is not iconified now. */
6070 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6072 f
->async_iconified
= 1;
6074 inev
.ie
.kind
= ICONIFY_EVENT
;
6075 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6081 if (event
.xmap
.window
== tip_window
)
6082 /* The tooltip has been drawn already. Avoid
6083 the SET_FRAME_GARBAGED below. */
6086 /* We use x_top_window_to_frame because map events can
6087 come for sub-windows and they don't mean that the
6088 frame is visible. */
6089 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6092 /* wait_reading_process_output will notice this and update
6093 the frame's display structures.
6094 If we where iconified, we should not set garbaged,
6095 because that stops redrawing on Expose events. This looks
6096 bad if we are called from a recursive event loop
6097 (x_dispatch_event), for example when a dialog is up. */
6098 if (! f
->async_iconified
)
6099 SET_FRAME_GARBAGED (f
);
6101 f
->async_visible
= 1;
6102 f
->async_iconified
= 0;
6103 f
->output_data
.x
->has_been_visible
= 1;
6107 inev
.ie
.kind
= DEICONIFY_EVENT
;
6108 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6110 else if (! NILP (Vframe_list
)
6111 && ! NILP (XCDR (Vframe_list
)))
6112 /* Force a redisplay sooner or later
6113 to update the frame titles
6114 in case this is the second frame. */
6115 record_asynch_buffer_change ();
6121 last_user_time
= event
.xkey
.time
;
6122 ignore_next_mouse_click_timeout
= 0;
6124 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6125 /* Dispatch KeyPress events when in menu. */
6126 if (popup_activated ())
6130 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6132 /* If mouse-highlight is an integer, input clears out
6133 mouse highlighting. */
6134 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6136 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6138 clear_mouse_face (dpyinfo
);
6139 dpyinfo
->mouse_face_hidden
= 1;
6142 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6145 /* Scroll bars consume key events, but we want
6146 the keys to go to the scroll bar's frame. */
6147 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6149 if (widget
&& XmIsScrollBar (widget
))
6151 widget
= XtParent (widget
);
6152 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6155 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6159 KeySym keysym
, orig_keysym
;
6160 /* al%imercury@uunet.uu.net says that making this 81
6161 instead of 80 fixed a bug whereby meta chars made
6164 It seems that some version of XmbLookupString has
6165 a bug of not returning XBufferOverflow in
6166 status_return even if the input is too long to
6167 fit in 81 bytes. So, we must prepare sufficient
6168 bytes for copy_buffer. 513 bytes (256 chars for
6169 two-byte character set) seems to be a fairly good
6170 approximation. -- 2000.8.10 handa@etl.go.jp */
6171 unsigned char copy_buffer
[513];
6172 unsigned char *copy_bufptr
= copy_buffer
;
6173 int copy_bufsiz
= sizeof (copy_buffer
);
6175 Lisp_Object coding_system
= Qlatin_1
;
6179 /* Don't pass keys to GTK. A Tab will shift focus to the
6180 tool bar in GTK 2.4. Keys will still go to menus and
6181 dialogs because in that case popup_activated is TRUE
6183 *finish
= X_EVENT_DROP
;
6187 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6188 extra_keyboard_modifiers
);
6189 modifiers
= event
.xkey
.state
;
6191 /* This will have to go some day... */
6193 /* make_lispy_event turns chars into control chars.
6194 Don't do it here because XLookupString is too eager. */
6195 event
.xkey
.state
&= ~ControlMask
;
6196 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6197 | dpyinfo
->super_mod_mask
6198 | dpyinfo
->hyper_mod_mask
6199 | dpyinfo
->alt_mod_mask
);
6201 /* In case Meta is ComposeCharacter,
6202 clear its status. According to Markus Ehrnsperger
6203 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6204 this enables ComposeCharacter to work whether or
6205 not it is combined with Meta. */
6206 if (modifiers
& dpyinfo
->meta_mod_mask
)
6207 bzero (&compose_status
, sizeof (compose_status
));
6212 Status status_return
;
6214 coding_system
= Vlocale_coding_system
;
6215 nbytes
= XmbLookupString (FRAME_XIC (f
),
6216 &event
.xkey
, copy_bufptr
,
6217 copy_bufsiz
, &keysym
,
6219 if (status_return
== XBufferOverflow
)
6221 copy_bufsiz
= nbytes
+ 1;
6222 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6223 nbytes
= XmbLookupString (FRAME_XIC (f
),
6224 &event
.xkey
, copy_bufptr
,
6225 copy_bufsiz
, &keysym
,
6228 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6229 #if 0 && defined X_HAVE_UTF8_STRING
6230 else if (status_return
== XLookupKeySym
)
6231 { /* Try again but with utf-8. */
6232 coding_system
= Qutf_8
;
6233 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6234 &event
.xkey
, copy_bufptr
,
6235 copy_bufsiz
, &keysym
,
6237 if (status_return
== XBufferOverflow
)
6239 copy_bufsiz
= nbytes
+ 1;
6240 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6241 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6244 copy_bufsiz
, &keysym
,
6250 if (status_return
== XLookupNone
)
6252 else if (status_return
== XLookupChars
)
6257 else if (status_return
!= XLookupKeySym
6258 && status_return
!= XLookupBoth
)
6262 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6263 copy_bufsiz
, &keysym
,
6266 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6267 copy_bufsiz
, &keysym
,
6271 /* If not using XIM/XIC, and a compose sequence is in progress,
6272 we break here. Otherwise, chars_matched is always 0. */
6273 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6276 bzero (&compose_status
, sizeof (compose_status
));
6277 orig_keysym
= keysym
;
6279 /* Common for all keysym input events. */
6280 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6282 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6283 inev
.ie
.timestamp
= event
.xkey
.time
;
6285 /* First deal with keysyms which have defined
6286 translations to characters. */
6287 if (keysym
>= 32 && keysym
< 128)
6288 /* Avoid explicitly decoding each ASCII character. */
6290 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6291 inev
.ie
.code
= keysym
;
6295 /* Keysyms directly mapped to supported Unicode characters. */
6296 if ((keysym
>= 0x01000000 && keysym
<= 0x010033ff)
6297 || (keysym
>= 0x0100e000 && keysym
<= 0x0100ffff))
6299 int code
= keysym
& 0xFFFF, charset_id
, c1
, c2
;
6303 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6304 inev
.ie
.code
= code
;
6306 else if (code
< 0x100)
6309 charset_id
= CHARSET_8_BIT_CONTROL
;
6311 charset_id
= charset_latin_iso8859_1
;
6312 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6313 inev
.ie
.code
= MAKE_CHAR (charset_id
, code
, 0);
6318 charset_id
= charset_mule_unicode_0100_24ff
,
6320 else if (code
< 0xE000)
6321 charset_id
= charset_mule_unicode_2500_33ff
,
6324 charset_id
= charset_mule_unicode_e000_ffff
,
6326 c1
= (code
/ 96) + 32, c2
= (code
% 96) + 32;
6327 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6328 inev
.ie
.code
= MAKE_CHAR (charset_id
, c1
, c2
);
6333 /* Now non-ASCII. */
6334 if (HASH_TABLE_P (Vx_keysym_table
)
6335 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6339 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6340 ? ASCII_KEYSTROKE_EVENT
6341 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6342 inev
.ie
.code
= XFASTINT (c
);
6346 /* Random non-modifier sorts of keysyms. */
6347 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6348 || keysym
== XK_Delete
6349 #ifdef XK_ISO_Left_Tab
6350 || (keysym
>= XK_ISO_Left_Tab
6351 && keysym
<= XK_ISO_Enter
)
6353 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6354 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6356 /* This recognizes the "extended function
6357 keys". It seems there's no cleaner way.
6358 Test IsModifierKey to avoid handling
6359 mode_switch incorrectly. */
6360 || ((unsigned) (keysym
) >= XK_Select
6361 && (unsigned)(keysym
) < XK_KP_Space
)
6363 #ifdef XK_dead_circumflex
6364 || orig_keysym
== XK_dead_circumflex
6366 #ifdef XK_dead_grave
6367 || orig_keysym
== XK_dead_grave
6369 #ifdef XK_dead_tilde
6370 || orig_keysym
== XK_dead_tilde
6372 #ifdef XK_dead_diaeresis
6373 || orig_keysym
== XK_dead_diaeresis
6375 #ifdef XK_dead_macron
6376 || orig_keysym
== XK_dead_macron
6378 #ifdef XK_dead_degree
6379 || orig_keysym
== XK_dead_degree
6381 #ifdef XK_dead_acute
6382 || orig_keysym
== XK_dead_acute
6384 #ifdef XK_dead_cedilla
6385 || orig_keysym
== XK_dead_cedilla
6387 #ifdef XK_dead_breve
6388 || orig_keysym
== XK_dead_breve
6390 #ifdef XK_dead_ogonek
6391 || orig_keysym
== XK_dead_ogonek
6393 #ifdef XK_dead_caron
6394 || orig_keysym
== XK_dead_caron
6396 #ifdef XK_dead_doubleacute
6397 || orig_keysym
== XK_dead_doubleacute
6399 #ifdef XK_dead_abovedot
6400 || orig_keysym
== XK_dead_abovedot
6402 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6403 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6404 /* Any "vendor-specific" key is ok. */
6405 || (orig_keysym
& (1 << 28))
6406 || (keysym
!= NoSymbol
&& nbytes
== 0))
6407 && ! (IsModifierKey (orig_keysym
)
6409 #ifdef XK_Mode_switch
6410 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
6413 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
6415 #endif /* not HAVE_X11R5 */
6416 /* The symbols from XK_ISO_Lock
6417 to XK_ISO_Last_Group_Lock
6418 don't have real modifiers but
6419 should be treated similarly to
6420 Mode_switch by Emacs. */
6421 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6422 || ((unsigned)(orig_keysym
)
6424 && (unsigned)(orig_keysym
)
6425 <= XK_ISO_Last_Group_Lock
)
6429 STORE_KEYSYM_FOR_DEBUG (keysym
);
6430 /* make_lispy_event will convert this to a symbolic
6432 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6433 inev
.ie
.code
= keysym
;
6437 { /* Raw bytes, not keysym. */
6442 /* The input should be decoded with `coding_system'
6443 which depends on which X*LookupString function
6444 we used just above and the locale. */
6445 setup_coding_system (coding_system
, &coding
);
6446 coding
.src_multibyte
= 0;
6447 coding
.dst_multibyte
= 1;
6448 /* The input is converted to events, thus we can't
6449 handle composition. Anyway, there's no XIM that
6450 gives us composition information. */
6451 coding
.composing
= COMPOSITION_DISABLED
;
6453 for (i
= 0; i
< nbytes
; i
++)
6455 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6459 /* Decode the input data. */
6463 require
= decoding_buffer_size (&coding
, nbytes
);
6464 p
= (unsigned char *) alloca (require
);
6465 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6466 /* We explicitly disable composition handling because
6467 key data should not contain any composition sequence. */
6468 coding
.composing
= COMPOSITION_DISABLED
;
6469 decode_coding (&coding
, copy_bufptr
, p
, nbytes
, require
);
6470 nbytes
= coding
.produced
;
6471 nchars
= coding
.produced_char
;
6475 /* Convert the input data to a sequence of
6476 character events. */
6477 for (i
= 0; i
< nbytes
; i
+= len
)
6479 if (nchars
== nbytes
)
6480 c
= copy_bufptr
[i
], len
= 1;
6482 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6484 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6485 ? ASCII_KEYSTROKE_EVENT
6486 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6488 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6493 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6495 if (keysym
== NoSymbol
)
6501 /* Don't dispatch this event since XtDispatchEvent calls
6502 XFilterEvent, and two calls in a row may freeze the
6510 last_user_time
= event
.xkey
.time
;
6512 /* Don't dispatch this event since XtDispatchEvent calls
6513 XFilterEvent, and two calls in a row may freeze the
6521 last_user_time
= event
.xcrossing
.time
;
6522 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6524 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6526 if (f
&& x_mouse_click_focus_ignore_position
)
6527 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6530 if (event
.xcrossing
.focus
)
6532 /* Avoid nasty pop/raise loops. */
6533 if (f
&& (!(f
->auto_raise
)
6535 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6537 x_new_focus_frame (dpyinfo
, f
);
6538 enter_timestamp
= event
.xcrossing
.time
;
6541 else if (f
== dpyinfo
->x_focus_frame
)
6542 x_new_focus_frame (dpyinfo
, 0);
6545 /* EnterNotify counts as mouse movement,
6546 so update things that depend on mouse position. */
6547 if (f
&& !f
->output_data
.x
->hourglass_p
)
6548 note_mouse_movement (f
, &event
.xmotion
);
6550 /* We may get an EnterNotify on the buttons in the toolbar. In that
6551 case we moved out of any highlighted area and need to note this. */
6552 if (!f
&& last_mouse_glyph_frame
)
6553 note_mouse_movement (last_mouse_glyph_frame
, &event
);
6558 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6562 last_user_time
= event
.xcrossing
.time
;
6563 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6565 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6568 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6570 /* If we move outside the frame, then we're
6571 certainly no longer on any text in the frame. */
6572 clear_mouse_face (dpyinfo
);
6573 dpyinfo
->mouse_face_mouse_frame
= 0;
6576 /* Generate a nil HELP_EVENT to cancel a help-echo.
6577 Do it only if there's something to cancel.
6578 Otherwise, the startup message is cleared when
6579 the mouse leaves the frame. */
6580 if (any_help_event_p
)
6584 /* See comment in EnterNotify above */
6585 else if (last_mouse_glyph_frame
)
6586 note_mouse_movement (last_mouse_glyph_frame
, &event
);
6591 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6596 last_user_time
= event
.xmotion
.time
;
6597 previous_help_echo_string
= help_echo_string
;
6598 help_echo_string
= Qnil
;
6600 if (dpyinfo
->grabbed
&& last_mouse_frame
6601 && FRAME_LIVE_P (last_mouse_frame
))
6602 f
= last_mouse_frame
;
6604 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6606 if (dpyinfo
->mouse_face_hidden
)
6608 dpyinfo
->mouse_face_hidden
= 0;
6609 clear_mouse_face (dpyinfo
);
6615 /* Generate SELECT_WINDOW_EVENTs when needed. */
6616 if (!NILP (Vmouse_autoselect_window
))
6620 window
= window_from_coordinates (f
,
6621 event
.xmotion
.x
, event
.xmotion
.y
,
6624 /* Window will be selected only when it is not selected now and
6625 last mouse movement event was not in it. Minibuffer window
6626 will be selected only when it is active. */
6627 if (WINDOWP (window
)
6628 && !EQ (window
, last_window
)
6629 && !EQ (window
, selected_window
)
6630 /* For click-to-focus window managers
6631 create event iff we don't leave the
6633 && (focus_follows_mouse
6634 || (EQ (XWINDOW (window
)->frame
,
6635 XWINDOW (selected_window
)->frame
))))
6637 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6638 inev
.ie
.frame_or_window
= window
;
6643 if (!note_mouse_movement (f
, &event
.xmotion
))
6644 help_echo_string
= previous_help_echo_string
;
6648 #ifndef USE_TOOLKIT_SCROLL_BARS
6649 struct scroll_bar
*bar
6650 = x_window_to_scroll_bar (event
.xmotion
.display
,
6651 event
.xmotion
.window
);
6654 x_scroll_bar_note_movement (bar
, &event
);
6655 #endif /* USE_TOOLKIT_SCROLL_BARS */
6657 /* If we move outside the frame, then we're
6658 certainly no longer on any text in the frame. */
6659 clear_mouse_face (dpyinfo
);
6662 /* If the contents of the global variable help_echo_string
6663 has changed, generate a HELP_EVENT. */
6664 if (!NILP (help_echo_string
)
6665 || !NILP (previous_help_echo_string
))
6670 case ConfigureNotify
:
6671 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6674 #ifndef USE_X_TOOLKIT
6676 xg_resize_widgets (f
, event
.xconfigure
.width
,
6677 event
.xconfigure
.height
);
6678 #else /* not USE_GTK */
6679 /* If there is a pending resize for fullscreen, don't
6680 do this one, the right one will come later.
6681 The toolkit version doesn't seem to need this, but we
6682 need to reset it below. */
6684 = ((f
->want_fullscreen
& FULLSCREEN_WAIT
)
6685 && f
->new_text_cols
!= 0);
6686 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6687 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6692 /* In the toolkit version, change_frame_size
6693 is called by the code that handles resizing
6694 of the EmacsFrame widget. */
6696 /* Even if the number of character rows and columns has
6697 not changed, the font size may have changed, so we need
6698 to check the pixel dimensions as well. */
6699 if (columns
!= FRAME_COLS (f
)
6700 || rows
!= FRAME_LINES (f
)
6701 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6702 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6704 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6705 SET_FRAME_GARBAGED (f
);
6706 cancel_mouse_face (f
);
6708 #endif /* not USE_GTK */
6711 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6712 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6715 /* GTK creates windows but doesn't map them.
6716 Only get real positions and check fullscreen when mapped. */
6717 if (FRAME_GTK_OUTER_WIDGET (f
)
6718 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
6721 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6723 if (f
->want_fullscreen
& FULLSCREEN_WAIT
)
6724 f
->want_fullscreen
&= ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
6728 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6729 xic_set_statusarea (f
);
6732 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
6734 /* Since the WM decorations come below top_pos now,
6735 we must put them below top_pos in the future. */
6736 f
->win_gravity
= NorthWestGravity
;
6737 x_wm_set_size_hint (f
, (long) 0, 0);
6745 /* If we decide we want to generate an event to be seen
6746 by the rest of Emacs, we put it here. */
6749 bzero (&compose_status
, sizeof (compose_status
));
6750 last_mouse_glyph_frame
= 0;
6751 last_user_time
= event
.xbutton
.time
;
6753 if (dpyinfo
->grabbed
6755 && FRAME_LIVE_P (last_mouse_frame
))
6756 f
= last_mouse_frame
;
6758 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6762 /* Is this in the tool-bar? */
6763 if (WINDOWP (f
->tool_bar_window
)
6764 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6767 int x
= event
.xbutton
.x
;
6768 int y
= event
.xbutton
.y
;
6770 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6771 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6773 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6775 if (event
.xbutton
.type
== ButtonPress
)
6776 handle_tool_bar_click (f
, x
, y
, 1, 0);
6778 handle_tool_bar_click (f
, x
, y
, 0,
6779 x_x_to_emacs_modifiers (dpyinfo
,
6780 event
.xbutton
.state
));
6785 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6786 if (! popup_activated ())
6789 if (ignore_next_mouse_click_timeout
)
6791 if (event
.type
== ButtonPress
6792 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6794 ignore_next_mouse_click_timeout
= 0;
6795 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6797 if (event
.type
== ButtonRelease
)
6798 ignore_next_mouse_click_timeout
= 0;
6801 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6806 struct scroll_bar
*bar
6807 = x_window_to_scroll_bar (event
.xbutton
.display
,
6808 event
.xbutton
.window
);
6810 #ifdef USE_TOOLKIT_SCROLL_BARS
6811 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6813 if (bar
&& event
.xbutton
.state
& ControlMask
)
6815 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6816 *finish
= X_EVENT_DROP
;
6818 #else /* not USE_TOOLKIT_SCROLL_BARS */
6820 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6821 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6824 if (event
.type
== ButtonPress
)
6826 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6827 last_mouse_frame
= f
;
6830 last_tool_bar_item
= -1;
6833 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6835 /* Ignore any mouse motion that happened before this event;
6836 any subsequent mouse-movement Emacs events should reflect
6837 only motion after the ButtonPress/Release. */
6841 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6842 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6843 /* For a down-event in the menu bar,
6844 don't pass it to Xt right now.
6845 Instead, save it away
6846 and we will pass it to Xt from kbd_buffer_get_event.
6847 That way, we can run some Lisp code first. */
6850 ! popup_activated ()
6853 f
&& event
.type
== ButtonPress
6854 /* Verify the event is really within the menu bar
6855 and not just sent to it due to grabbing. */
6856 && event
.xbutton
.x
>= 0
6857 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6858 && event
.xbutton
.y
>= 0
6859 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6860 && event
.xbutton
.same_screen
)
6862 SET_SAVED_BUTTON_EVENT
;
6863 XSETFRAME (last_mouse_press_frame
, f
);
6865 *finish
= X_EVENT_DROP
;
6868 else if (event
.type
== ButtonPress
)
6870 last_mouse_press_frame
= Qnil
;
6874 #ifdef USE_MOTIF /* This should do not harm for Lucid,
6875 but I am trying to be cautious. */
6876 else if (event
.type
== ButtonRelease
)
6878 if (!NILP (last_mouse_press_frame
))
6880 f
= XFRAME (last_mouse_press_frame
);
6881 if (f
->output_data
.x
)
6882 SET_SAVED_BUTTON_EVENT
;
6887 #endif /* USE_MOTIF */
6890 #endif /* USE_X_TOOLKIT || USE_GTK */
6894 case CirculateNotify
:
6897 case CirculateRequest
:
6900 case VisibilityNotify
:
6904 /* Someone has changed the keyboard mapping - update the
6906 switch (event
.xmapping
.request
)
6908 case MappingModifier
:
6909 x_find_modifier_meanings (dpyinfo
);
6910 /* This is meant to fall through. */
6911 case MappingKeyboard
:
6912 XRefreshKeyboardMapping (&event
.xmapping
);
6918 #ifdef USE_X_TOOLKIT
6920 if (*finish
!= X_EVENT_DROP
)
6921 XtDispatchEvent (&event
);
6923 #endif /* USE_X_TOOLKIT */
6928 if (inev
.ie
.kind
!= NO_EVENT
)
6930 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6935 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
6940 XSETFRAME (frame
, f
);
6946 any_help_event_p
= 1;
6947 gen_help_event (help_echo_string
, frame
, help_echo_window
,
6948 help_echo_object
, help_echo_pos
);
6952 help_echo_string
= Qnil
;
6953 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
6963 /* Handles the XEvent EVENT on display DISPLAY.
6964 This is used for event loops outside the normal event handling,
6965 i.e. looping while a popup menu or a dialog is posted.
6967 Returns the value handle_one_xevent sets in the finish argument. */
6969 x_dispatch_event (event
, display
)
6973 struct x_display_info
*dpyinfo
;
6974 int finish
= X_EVENT_NORMAL
;
6976 dpyinfo
= x_display_info_for_display (display
);
6979 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
6985 /* Read events coming from the X server.
6986 This routine is called by the SIGIO handler.
6987 We return as soon as there are no more events to be read.
6989 We return the number of characters stored into the buffer,
6990 thus pretending to be `read' (except the characters we store
6991 in the keyboard buffer can be multibyte, so are not necessarily
6994 EXPECTED is nonzero if the caller knows input is available. */
6997 XTread_socket (sd
, expected
, hold_quit
)
7000 struct input_event
*hold_quit
;
7004 int event_found
= 0;
7005 struct x_display_info
*dpyinfo
;
7007 if (interrupt_input_blocked
)
7009 interrupt_input_pending
= 1;
7013 interrupt_input_pending
= 0;
7016 /* So people can tell when we have read the available input. */
7017 input_signal_count
++;
7021 /* Find the display we are supposed to read input for.
7022 It's the one communicating on descriptor SD. */
7023 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7025 #if 0 /* This ought to be unnecessary; let's verify it. */
7027 /* If available, Xlib uses FIOSNBIO to make the socket
7028 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
7029 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
7030 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
7031 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
7032 #endif /* ! defined (FIOSNBIO) */
7035 #if 0 /* This code can't be made to work, with multiple displays,
7036 and appears not to be used on any system any more.
7037 Also keyboard.c doesn't turn O_NDELAY on and off
7038 for X connections. */
7041 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7043 extern int read_alarm_should_throw
;
7044 read_alarm_should_throw
= 1;
7045 XPeekEvent (dpyinfo
->display
, &event
);
7046 read_alarm_should_throw
= 0;
7048 #endif /* HAVE_SELECT */
7052 /* For debugging, this gives a way to fake an I/O error. */
7053 if (dpyinfo
== XTread_socket_fake_io_error
)
7055 XTread_socket_fake_io_error
= 0;
7056 x_io_error_quitter (dpyinfo
->display
);
7061 struct input_event inev
;
7063 /* We don't need to EVENT_INIT (inev) here, as
7064 x_session_check_input copies an entire input_event. */
7065 if (x_session_check_input (&inev
))
7067 kbd_buffer_store_event_hold (&inev
, hold_quit
);
7075 while (XPending (dpyinfo
->display
))
7079 XNextEvent (dpyinfo
->display
, &event
);
7082 /* Filter events for the current X input method. */
7083 if (x_filter_event (dpyinfo
, &event
))
7088 count
+= handle_one_xevent (dpyinfo
, &event
, &finish
, hold_quit
);
7090 if (finish
== X_EVENT_GOTO_OUT
)
7093 #endif /* not USE_GTK */
7098 /* For GTK we must use the GTK event loop. But XEvents gets passed
7099 to our filter function above, and then to the big event switch.
7100 We use a bunch of globals to communicate with our filter function,
7101 that is kind of ugly, but it works.
7103 There is no way to do one display at the time, GTK just does events
7104 from all displays. */
7106 while (gtk_events_pending ())
7108 current_count
= count
;
7109 current_hold_quit
= hold_quit
;
7111 gtk_main_iteration ();
7113 count
= current_count
;
7115 current_hold_quit
= 0;
7117 if (current_finish
== X_EVENT_GOTO_OUT
)
7120 #endif /* USE_GTK */
7124 /* On some systems, an X bug causes Emacs to get no more events
7125 when the window is destroyed. Detect that. (1994.) */
7128 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7129 One XNOOP in 100 loops will make Emacs terminate.
7130 B. Bretthauer, 1994 */
7132 if (x_noop_count
>= 100)
7136 if (next_noop_dpyinfo
== 0)
7137 next_noop_dpyinfo
= x_display_list
;
7139 XNoOp (next_noop_dpyinfo
->display
);
7141 /* Each time we get here, cycle through the displays now open. */
7142 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7146 /* If the focus was just given to an auto-raising frame,
7148 /* ??? This ought to be able to handle more than one such frame. */
7149 if (pending_autoraise_frame
)
7151 x_raise_frame (pending_autoraise_frame
);
7152 pending_autoraise_frame
= 0;
7164 /***********************************************************************
7166 ***********************************************************************/
7168 /* Set clipping for output in glyph row ROW. W is the window in which
7169 we operate. GC is the graphics context to set clipping in.
7171 ROW may be a text row or, e.g., a mode line. Text rows must be
7172 clipped to the interior of the window dedicated to text display,
7173 mode lines must be clipped to the whole window. */
7176 x_clip_to_row (w
, row
, area
, gc
)
7178 struct glyph_row
*row
;
7182 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7183 XRectangle clip_rect
;
7184 int window_x
, window_y
, window_width
;
7186 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7188 clip_rect
.x
= window_x
;
7189 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7190 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7191 clip_rect
.width
= window_width
;
7192 clip_rect
.height
= row
->visible_height
;
7194 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7198 /* Draw a hollow box cursor on window W in glyph row ROW. */
7201 x_draw_hollow_cursor (w
, row
)
7203 struct glyph_row
*row
;
7205 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7206 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7207 Display
*dpy
= FRAME_X_DISPLAY (f
);
7210 struct glyph
*cursor_glyph
;
7213 /* Get the glyph the cursor is on. If we can't tell because
7214 the current matrix is invalid or such, give up. */
7215 cursor_glyph
= get_phys_cursor_glyph (w
);
7216 if (cursor_glyph
== NULL
)
7219 /* Compute frame-relative coordinates for phys cursor. */
7220 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7221 wd
= w
->phys_cursor_width
;
7223 /* The foreground of cursor_gc is typically the same as the normal
7224 background color, which can cause the cursor box to be invisible. */
7225 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7226 if (dpyinfo
->scratch_cursor_gc
)
7227 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7229 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7230 GCForeground
, &xgcv
);
7231 gc
= dpyinfo
->scratch_cursor_gc
;
7233 /* Set clipping, draw the rectangle, and reset clipping again. */
7234 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7235 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7236 XSetClipMask (dpy
, gc
, None
);
7240 /* Draw a bar cursor on window W in glyph row ROW.
7242 Implementation note: One would like to draw a bar cursor with an
7243 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7244 Unfortunately, I didn't find a font yet that has this property set.
7248 x_draw_bar_cursor (w
, row
, width
, kind
)
7250 struct glyph_row
*row
;
7252 enum text_cursor_kinds kind
;
7254 struct frame
*f
= XFRAME (w
->frame
);
7255 struct glyph
*cursor_glyph
;
7257 /* If cursor is out of bounds, don't draw garbage. This can happen
7258 in mini-buffer windows when switching between echo area glyphs
7260 cursor_glyph
= get_phys_cursor_glyph (w
);
7261 if (cursor_glyph
== NULL
)
7264 /* If on an image, draw like a normal cursor. That's usually better
7265 visible than drawing a bar, esp. if the image is large so that
7266 the bar might not be in the window. */
7267 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7269 struct glyph_row
*row
;
7270 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7271 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7275 Display
*dpy
= FRAME_X_DISPLAY (f
);
7276 Window window
= FRAME_X_WINDOW (f
);
7277 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7278 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7279 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7282 /* If the glyph's background equals the color we normally draw
7283 the bar cursor in, the bar cursor in its normal color is
7284 invisible. Use the glyph's foreground color instead in this
7285 case, on the assumption that the glyph's colors are chosen so
7286 that the glyph is legible. */
7287 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7288 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7290 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7291 xgcv
.graphics_exposures
= 0;
7294 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7297 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7298 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7302 width
= FRAME_CURSOR_WIDTH (f
);
7303 width
= min (cursor_glyph
->pixel_width
, width
);
7305 w
->phys_cursor_width
= width
;
7306 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7308 if (kind
== BAR_CURSOR
)
7309 XFillRectangle (dpy
, window
, gc
,
7310 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7311 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7312 width
, row
->height
);
7314 XFillRectangle (dpy
, window
, gc
,
7315 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7316 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7317 row
->height
- width
),
7318 cursor_glyph
->pixel_width
,
7321 XSetClipMask (dpy
, gc
, None
);
7326 /* RIF: Define cursor CURSOR on frame F. */
7329 x_define_frame_cursor (f
, cursor
)
7333 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7337 /* RIF: Clear area on frame F. */
7340 x_clear_frame_area (f
, x
, y
, width
, height
)
7342 int x
, y
, width
, height
;
7344 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7345 x
, y
, width
, height
, False
);
7349 /* RIF: Draw cursor on window W. */
7352 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7354 struct glyph_row
*glyph_row
;
7356 int cursor_type
, cursor_width
;
7359 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7363 w
->phys_cursor_type
= cursor_type
;
7364 w
->phys_cursor_on_p
= 1;
7366 if (glyph_row
->exact_window_width_line_p
7367 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7369 glyph_row
->cursor_in_fringe_p
= 1;
7370 draw_fringe_bitmap (w
, glyph_row
, 0);
7373 switch (cursor_type
)
7375 case HOLLOW_BOX_CURSOR
:
7376 x_draw_hollow_cursor (w
, glyph_row
);
7379 case FILLED_BOX_CURSOR
:
7380 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7384 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7388 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7392 w
->phys_cursor_width
= 0;
7400 if (w
== XWINDOW (f
->selected_window
))
7401 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7402 xic_set_preeditarea (w
, x
, y
);
7407 if (updating_frame
!= f
)
7408 XFlush (FRAME_X_DISPLAY (f
));
7415 /* Make the x-window of frame F use the gnu icon bitmap. */
7418 x_bitmap_icon (f
, file
)
7424 if (FRAME_X_WINDOW (f
) == 0)
7427 /* Free up our existing icon bitmap and mask if any. */
7428 if (f
->output_data
.x
->icon_bitmap
> 0)
7429 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7430 f
->output_data
.x
->icon_bitmap
= 0;
7435 /* Use gtk_window_set_icon_from_file () if available,
7436 It's not restricted to bitmaps */
7437 if (xg_set_icon (f
, file
))
7439 #endif /* USE_GTK */
7440 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7441 x_create_bitmap_mask (f
, bitmap_id
);
7445 /* Create the GNU bitmap and mask if necessary. */
7446 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7450 #if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7452 if (xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7455 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7457 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7458 #endif /* USE_GTK */
7459 #endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
7461 /* If all else fails, use the (black and white) xbm image. */
7464 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7465 gnu_xbm_width
, gnu_xbm_height
);
7469 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7470 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7474 /* The first time we create the GNU bitmap and mask,
7475 this increments the ref-count one extra time.
7476 As a result, the GNU bitmap and mask are never freed.
7477 That way, we don't have to worry about allocating it again. */
7478 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7480 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7483 x_wm_set_icon_pixmap (f
, bitmap_id
);
7484 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7490 /* Make the x-window of frame F use a rectangle with text.
7491 Use ICON_NAME as the text. */
7494 x_text_icon (f
, icon_name
)
7498 if (FRAME_X_WINDOW (f
) == 0)
7504 text
.value
= (unsigned char *) icon_name
;
7505 text
.encoding
= XA_STRING
;
7507 text
.nitems
= strlen (icon_name
);
7508 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7510 #else /* not HAVE_X11R4 */
7511 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), icon_name
);
7512 #endif /* not HAVE_X11R4 */
7514 if (f
->output_data
.x
->icon_bitmap
> 0)
7515 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7516 f
->output_data
.x
->icon_bitmap
= 0;
7517 x_wm_set_icon_pixmap (f
, 0);
7522 #define X_ERROR_MESSAGE_SIZE 200
7524 /* If non-nil, this should be a string.
7525 It means catch X errors and store the error message in this string.
7527 The reason we use a stack is that x_catch_error/x_uncatch_error can
7528 be called from a signal handler.
7531 struct x_error_message_stack
{
7532 char string
[X_ERROR_MESSAGE_SIZE
];
7534 struct x_error_message_stack
*prev
;
7536 static struct x_error_message_stack
*x_error_message
;
7538 /* An X error handler which stores the error message in
7539 *x_error_message. This is called from x_error_handler if
7540 x_catch_errors is in effect. */
7543 x_error_catcher (display
, error
)
7547 XGetErrorText (display
, error
->error_code
,
7548 x_error_message
->string
,
7549 X_ERROR_MESSAGE_SIZE
);
7552 /* Begin trapping X errors for display DPY. Actually we trap X errors
7553 for all displays, but DPY should be the display you are actually
7556 After calling this function, X protocol errors no longer cause
7557 Emacs to exit; instead, they are recorded in the string
7558 stored in *x_error_message.
7560 Calling x_check_errors signals an Emacs error if an X error has
7561 occurred since the last call to x_catch_errors or x_check_errors.
7563 Calling x_uncatch_errors resumes the normal error handling. */
7565 void x_check_errors ();
7568 x_catch_errors (dpy
)
7571 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7573 /* Make sure any errors from previous requests have been dealt with. */
7577 data
->string
[0] = 0;
7578 data
->prev
= x_error_message
;
7579 x_error_message
= data
;
7582 /* Undo the last x_catch_errors call.
7583 DPY should be the display that was passed to x_catch_errors. */
7588 struct x_error_message_stack
*tmp
;
7592 /* The display may have been closed before this function is called.
7593 Check if it is still open before calling XSync. */
7594 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7595 XSync (x_error_message
->dpy
, False
);
7597 tmp
= x_error_message
;
7598 x_error_message
= x_error_message
->prev
;
7603 /* If any X protocol errors have arrived since the last call to
7604 x_catch_errors or x_check_errors, signal an Emacs error using
7605 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7608 x_check_errors (dpy
, format
)
7612 /* Make sure to catch any errors incurred so far. */
7615 if (x_error_message
->string
[0])
7617 char string
[X_ERROR_MESSAGE_SIZE
];
7618 bcopy (x_error_message
->string
, string
, X_ERROR_MESSAGE_SIZE
);
7619 x_uncatch_errors ();
7620 error (format
, string
);
7624 /* Nonzero if we had any X protocol errors
7625 since we did x_catch_errors on DPY. */
7628 x_had_errors_p (dpy
)
7631 /* Make sure to catch any errors incurred so far. */
7634 return x_error_message
->string
[0] != 0;
7637 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7640 x_clear_errors (dpy
)
7643 x_error_message
->string
[0] = 0;
7646 /* Close off all unclosed x_catch_errors calls. */
7649 x_fully_uncatch_errors ()
7651 while (x_error_message
)
7652 x_uncatch_errors ();
7655 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7658 x_catching_errors ()
7660 return x_error_message
!= 0;
7664 static unsigned int x_wire_count
;
7667 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7672 /* Handle SIGPIPE, which can happen when the connection to a server
7673 simply goes away. SIGPIPE is handled by x_connection_signal.
7674 Don't need to do anything, because the write which caused the
7675 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7676 which will do the appropriate cleanup for us. */
7679 x_connection_signal (signalnum
) /* If we don't have an argument, */
7680 int signalnum
; /* some compilers complain in signal calls. */
7683 /* USG systems forget handlers when they are used;
7684 must reestablish each time */
7685 signal (signalnum
, x_connection_signal
);
7690 /************************************************************************
7692 ************************************************************************/
7694 /* Error message passed to x_connection_closed. */
7696 static char *error_msg
;
7698 /* Function installed as fatal_error_signal_hook in
7699 x_connection_closed. Print the X error message, and exit normally,
7700 instead of dumping core when XtCloseDisplay fails. */
7703 x_fatal_error_signal ()
7705 fprintf (stderr
, "%s\n", error_msg
);
7709 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7710 the text of an error message that lead to the connection loss. */
7713 x_connection_closed (dpy
, error_message
)
7715 char *error_message
;
7717 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7718 Lisp_Object frame
, tail
;
7720 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7721 strcpy (error_msg
, error_message
);
7722 handling_signal
= 0;
7724 /* Prevent being called recursively because of an error condition
7725 below. Otherwise, we might end up with printing ``can't find per
7726 display information'' in the recursive call instead of printing
7727 the original message here. */
7728 x_catch_errors (dpy
);
7730 /* We have to close the display to inform Xt that it doesn't
7731 exist anymore. If we don't, Xt will continue to wait for
7732 events from the display. As a consequence, a sequence of
7734 M-x make-frame-on-display RET :1 RET
7735 ...kill the new frame, so that we get an IO error...
7736 M-x make-frame-on-display RET :1 RET
7738 will indefinitely wait in Xt for events for display `:1', opened
7739 in the first class to make-frame-on-display.
7741 Closing the display is reported to lead to a bus error on
7742 OpenWindows in certain situations. I suspect that is a bug
7743 in OpenWindows. I don't know how to cicumvent it here. */
7745 #ifdef USE_X_TOOLKIT
7746 /* If DPYINFO is null, this means we didn't open the display
7747 in the first place, so don't try to close it. */
7750 extern void (*fatal_error_signal_hook
) P_ ((void));
7751 fatal_error_signal_hook
= x_fatal_error_signal
;
7752 XtCloseDisplay (dpy
);
7753 fatal_error_signal_hook
= NULL
;
7759 xg_display_close (dpyinfo
->display
);
7762 /* Indicate that this display is dead. */
7764 dpyinfo
->display
= 0;
7766 /* First delete frames whose mini-buffers are on frames
7767 that are on the dead display. */
7768 FOR_EACH_FRAME (tail
, frame
)
7770 Lisp_Object minibuf_frame
;
7772 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7773 if (FRAME_X_P (XFRAME (frame
))
7774 && FRAME_X_P (XFRAME (minibuf_frame
))
7775 && ! EQ (frame
, minibuf_frame
)
7776 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7777 Fdelete_frame (frame
, Qt
);
7780 /* Now delete all remaining frames on the dead display.
7781 We are now sure none of these is used as the mini-buffer
7782 for another frame that we need to delete. */
7783 FOR_EACH_FRAME (tail
, frame
)
7784 if (FRAME_X_P (XFRAME (frame
))
7785 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7787 /* Set this to t so that Fdelete_frame won't get confused
7788 trying to find a replacement. */
7789 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7790 Fdelete_frame (frame
, Qt
);
7794 x_delete_display (dpyinfo
);
7796 x_uncatch_errors ();
7798 if (x_display_list
== 0)
7800 fprintf (stderr
, "%s\n", error_msg
);
7801 shut_down_emacs (0, 0, Qnil
);
7805 /* Ordinary stack unwind doesn't deal with these. */
7807 sigunblock (sigmask (SIGIO
));
7809 sigunblock (sigmask (SIGALRM
));
7810 TOTALLY_UNBLOCK_INPUT
;
7812 clear_waiting_for_input ();
7813 error ("%s", error_msg
);
7816 /* We specifically use it before defining it, so that gcc doesn't inline it,
7817 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7818 static void x_error_quitter
P_ ((Display
*, XErrorEvent
*));
7820 /* This is the first-level handler for X protocol errors.
7821 It calls x_error_quitter or x_error_catcher. */
7824 x_error_handler (display
, error
)
7828 if (x_error_message
)
7829 x_error_catcher (display
, error
);
7831 x_error_quitter (display
, error
);
7835 /* This is the usual handler for X protocol errors.
7836 It kills all frames on the display that we got the error for.
7837 If that was the only one, it prints an error message and kills Emacs. */
7839 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7841 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
7842 #define NO_INLINE __attribute__((noinline))
7847 /* Some versions of GNU/Linux define noinline in their headers. */
7853 /* On older GCC versions, just putting x_error_quitter
7854 after x_error_handler prevents inlining into the former. */
7856 static void NO_INLINE
7857 x_error_quitter (display
, error
)
7861 char buf
[256], buf1
[356];
7863 /* Ignore BadName errors. They can happen because of fonts
7864 or colors that are not defined. */
7866 if (error
->error_code
== BadName
)
7869 /* Note that there is no real way portable across R3/R4 to get the
7870 original error handler. */
7872 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7873 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7874 buf
, error
->request_code
);
7875 x_connection_closed (display
, buf1
);
7879 /* This is the handler for X IO errors, always.
7880 It kills all frames on the display that we lost touch with.
7881 If that was the only one, it prints an error message and kills Emacs. */
7884 x_io_error_quitter (display
)
7889 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7890 x_connection_closed (display
, buf
);
7894 /* Changing the font of the frame. */
7896 /* Give frame F the font named FONTNAME as its default font, and
7897 return the full name of that font. FONTNAME may be a wildcard
7898 pattern; in that case, we choose some font that fits the pattern.
7899 The return value shows which font we chose. */
7902 x_new_font (f
, fontname
)
7904 register char *fontname
;
7906 struct font_info
*fontp
7907 = FS_LOAD_FONT (f
, 0, fontname
, -1);
7912 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
7913 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
7914 FRAME_FONTSET (f
) = -1;
7916 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
7917 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
7918 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
7920 compute_fringe_widths (f
, 1);
7922 /* Compute the scroll bar width in character columns. */
7923 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7925 int wid
= FRAME_COLUMN_WIDTH (f
);
7926 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7927 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7931 int wid
= FRAME_COLUMN_WIDTH (f
);
7932 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7935 /* Now make the frame display the given font. */
7936 if (FRAME_X_WINDOW (f
) != 0)
7938 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
7939 FRAME_FONT (f
)->fid
);
7940 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
7941 FRAME_FONT (f
)->fid
);
7942 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
7943 FRAME_FONT (f
)->fid
);
7945 /* Don't change the size of a tip frame; there's no point in
7946 doing it because it's done in Fx_show_tip, and it leads to
7947 problems because the tip frame has no widget. */
7948 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7949 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7952 return build_string (fontp
->full_name
);
7955 /* Give frame F the fontset named FONTSETNAME as its default font, and
7956 return the full name of that fontset. FONTSETNAME may be a wildcard
7957 pattern; in that case, we choose some fontset that fits the pattern.
7958 The return value shows which fontset we chose. */
7961 x_new_fontset (f
, fontsetname
)
7965 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
7971 if (FRAME_FONTSET (f
) == fontset
)
7972 /* This fontset is already set in frame F. There's nothing more
7974 return fontset_name (fontset
);
7976 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
7978 if (!STRINGP (result
))
7979 /* Can't load ASCII font. */
7982 /* Since x_new_font doesn't update any fontset information, do it now. */
7983 FRAME_FONTSET (f
) = fontset
;
7987 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7988 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
7991 return build_string (fontsetname
);
7995 /***********************************************************************
7997 ***********************************************************************/
8003 /* XIM destroy callback function, which is called whenever the
8004 connection to input method XIM dies. CLIENT_DATA contains a
8005 pointer to the x_display_info structure corresponding to XIM. */
8008 xim_destroy_callback (xim
, client_data
, call_data
)
8010 XPointer client_data
;
8013 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8014 Lisp_Object frame
, tail
;
8018 /* No need to call XDestroyIC.. */
8019 FOR_EACH_FRAME (tail
, frame
)
8021 struct frame
*f
= XFRAME (frame
);
8022 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8024 FRAME_XIC (f
) = NULL
;
8025 xic_free_xfontset (f
);
8029 /* No need to call XCloseIM. */
8030 dpyinfo
->xim
= NULL
;
8031 XFree (dpyinfo
->xim_styles
);
8035 #endif /* HAVE_X11R6 */
8038 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8039 extern char *XSetIMValues
P_ ((XIM
, ...));
8042 /* Open the connection to the XIM server on display DPYINFO.
8043 RESOURCE_NAME is the resource name Emacs uses. */
8046 xim_open_dpy (dpyinfo
, resource_name
)
8047 struct x_display_info
*dpyinfo
;
8048 char *resource_name
;
8055 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8062 XIMCallback destroy
;
8065 /* Get supported styles and XIM values. */
8066 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8069 destroy
.callback
= xim_destroy_callback
;
8070 destroy
.client_data
= (XPointer
)dpyinfo
;
8071 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8077 #endif /* HAVE_XIM */
8078 dpyinfo
->xim
= NULL
;
8082 #ifdef HAVE_X11R6_XIM
8086 struct x_display_info
*dpyinfo
;
8087 char *resource_name
;
8090 /* XIM instantiate callback function, which is called whenever an XIM
8091 server is available. DISPLAY is the display of the XIM.
8092 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8093 when the callback was registered. */
8096 xim_instantiate_callback (display
, client_data
, call_data
)
8098 XPointer client_data
;
8101 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8102 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8104 /* We don't support multiple XIM connections. */
8108 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8110 /* Create XIC for the existing frames on the same display, as long
8111 as they have no XIC. */
8112 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8114 Lisp_Object tail
, frame
;
8117 FOR_EACH_FRAME (tail
, frame
)
8119 struct frame
*f
= XFRAME (frame
);
8121 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8122 if (FRAME_XIC (f
) == NULL
)
8124 create_frame_xic (f
);
8125 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8126 xic_set_statusarea (f
);
8127 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8129 struct window
*w
= XWINDOW (f
->selected_window
);
8130 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8139 #endif /* HAVE_X11R6_XIM */
8142 /* Open a connection to the XIM server on display DPYINFO.
8143 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8144 connection only at the first time. On X11R6, open the connection
8145 in the XIM instantiate callback function. */
8148 xim_initialize (dpyinfo
, resource_name
)
8149 struct x_display_info
*dpyinfo
;
8150 char *resource_name
;
8155 #ifdef HAVE_X11R6_XIM
8156 struct xim_inst_t
*xim_inst
;
8159 dpyinfo
->xim
= NULL
;
8160 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8161 xim_inst
->dpyinfo
= dpyinfo
;
8162 len
= strlen (resource_name
);
8163 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8164 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8165 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8166 resource_name
, EMACS_CLASS
,
8167 xim_instantiate_callback
,
8168 /* This is XPointer in XFree86
8169 but (XPointer *) on Tru64, at
8170 least, hence the configure test. */
8171 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8172 #else /* not HAVE_X11R6_XIM */
8173 dpyinfo
->xim
= NULL
;
8174 xim_open_dpy (dpyinfo
, resource_name
);
8175 #endif /* not HAVE_X11R6_XIM */
8179 #endif /* HAVE_XIM */
8180 dpyinfo
->xim
= NULL
;
8184 /* Close the connection to the XIM server on display DPYINFO. */
8187 xim_close_dpy (dpyinfo
)
8188 struct x_display_info
*dpyinfo
;
8193 #ifdef HAVE_X11R6_XIM
8194 if (dpyinfo
->display
)
8195 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8197 xim_instantiate_callback
, NULL
);
8198 #endif /* not HAVE_X11R6_XIM */
8199 if (dpyinfo
->display
)
8200 XCloseIM (dpyinfo
->xim
);
8201 dpyinfo
->xim
= NULL
;
8202 XFree (dpyinfo
->xim_styles
);
8204 #endif /* HAVE_XIM */
8207 #endif /* not HAVE_X11R6_XIM */
8211 /* Calculate the absolute position in frame F
8212 from its current recorded position values and gravity. */
8215 x_calc_absolute_position (f
)
8218 int flags
= f
->size_hint_flags
;
8220 /* We have nothing to do if the current position
8221 is already for the top-left corner. */
8222 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8225 /* Treat negative positions as relative to the leftmost bottommost
8226 position that fits on the screen. */
8227 if (flags
& XNegative
)
8228 f
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
8229 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
);
8232 int height
= FRAME_PIXEL_HEIGHT (f
);
8234 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8235 /* Something is fishy here. When using Motif, starting Emacs with
8236 `-g -0-0', the frame appears too low by a few pixels.
8238 This seems to be so because initially, while Emacs is starting,
8239 the column widget's height and the frame's pixel height are
8240 different. The column widget's height is the right one. In
8241 later invocations, when Emacs is up, the frame's pixel height
8244 It's not obvious where the initial small difference comes from.
8245 2000-12-01, gerd. */
8247 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8250 if (flags
& YNegative
)
8251 f
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
- height
+ f
->top_pos
);
8254 /* The left_pos and top_pos
8255 are now relative to the top and left screen edges,
8256 so the flags should correspond. */
8257 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8260 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8261 to really change the position, and 0 when calling from
8262 x_make_frame_visible (in that case, XOFF and YOFF are the current
8263 position values). It is -1 when calling from x_set_frame_parameters,
8264 which means, do adjust for borders but don't change the gravity. */
8267 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8269 register int xoff
, yoff
;
8272 int modified_top
, modified_left
;
8274 if (change_gravity
!= 0)
8276 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8277 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8281 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8283 f
->size_hint_flags
|= XNegative
;
8285 f
->size_hint_flags
|= YNegative
;
8286 f
->win_gravity
= NorthWestGravity
;
8288 x_calc_absolute_position (f
);
8291 x_wm_set_size_hint (f
, (long) 0, 0);
8293 modified_left
= f
->left_pos
;
8294 modified_top
= f
->top_pos
;
8296 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8298 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8299 than the WM decorations. So we use the calculated offset instead
8300 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8301 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8302 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8305 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8306 modified_left
, modified_top
);
8308 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8309 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8312 /* change_gravity is non-zero when this function is called from Lisp to
8313 programmatically move a frame. In that case, we call
8314 x_check_expected_move to discover if we have a "Type A" or "Type B"
8315 window manager, and, for a "Type A" window manager, adjust the position
8318 We call x_check_expected_move if a programmatic move occurred, and
8319 either the window manager type (A/B) is unknown or it is Type A but we
8320 need to compute the top/left offset adjustment for this frame. */
8322 if (change_gravity
!= 0 &&
8323 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8324 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8325 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8326 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8327 x_check_expected_move (f
, modified_left
, modified_top
);
8332 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8333 on the root window for frame F contains ATOMNAME.
8334 This is how a WM check shall be done according to the Window Manager
8335 Specification/Extended Window Manager Hints at
8336 http://freedesktop.org/wiki/Standards_2fwm_2dspec. */
8339 wm_supports (f
, atomname
)
8341 const char *atomname
;
8344 unsigned long actual_size
, bytes_remaining
;
8345 int i
, rc
, actual_format
;
8347 Window wmcheck_window
;
8348 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8349 Window target_window
= dpyinfo
->root_window
;
8350 long max_len
= 65536;
8351 Display
*dpy
= FRAME_X_DISPLAY (f
);
8352 unsigned char *tmp_data
= NULL
;
8353 Atom target_type
= XA_WINDOW
;
8358 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8360 x_catch_errors (dpy
);
8361 rc
= XGetWindowProperty (dpy
, target_window
,
8362 prop_atom
, 0, max_len
, False
, target_type
,
8363 &actual_type
, &actual_format
, &actual_size
,
8364 &bytes_remaining
, &tmp_data
);
8366 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8368 if (tmp_data
) XFree (tmp_data
);
8369 x_uncatch_errors ();
8374 wmcheck_window
= *(Window
*) tmp_data
;
8377 /* Check if window exists. */
8378 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8380 if (x_had_errors_p (dpy
))
8382 x_uncatch_errors ();
8387 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8389 /* Window changed, reload atoms */
8390 if (dpyinfo
->net_supported_atoms
!= NULL
)
8391 XFree (dpyinfo
->net_supported_atoms
);
8392 dpyinfo
->net_supported_atoms
= NULL
;
8393 dpyinfo
->nr_net_supported_atoms
= 0;
8394 dpyinfo
->net_supported_window
= 0;
8396 target_type
= XA_ATOM
;
8397 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8399 rc
= XGetWindowProperty (dpy
, target_window
,
8400 prop_atom
, 0, max_len
, False
, target_type
,
8401 &actual_type
, &actual_format
, &actual_size
,
8402 &bytes_remaining
, &tmp_data
);
8404 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8406 if (tmp_data
) XFree (tmp_data
);
8407 x_uncatch_errors ();
8412 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8413 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8414 dpyinfo
->net_supported_window
= wmcheck_window
;
8418 want_atom
= XInternAtom (dpy
, atomname
, False
);
8420 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8421 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8423 x_uncatch_errors ();
8429 /* Do fullscreen as specified in extended window manager hints */
8432 do_ewmh_fullscreen (f
)
8435 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8437 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8438 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8440 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8445 const char *atom
= "_NET_WM_STATE";
8446 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8447 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8448 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8449 const char *what
= NULL
;
8451 XSETFRAME (frame
, f
);
8453 /* If there are _NET_ atoms we assume we have extended window manager
8455 switch (f
->want_fullscreen
)
8457 case FULLSCREEN_BOTH
:
8460 case FULLSCREEN_WIDTH
:
8463 case FULLSCREEN_HEIGHT
:
8468 if (what
!= NULL
&& !wm_supports (f
, what
)) return 0;
8471 Fx_send_client_event (frame
, make_number (0), frame
,
8472 make_unibyte_string (atom
, strlen (atom
)),
8474 Fcons (make_number (0), /* Remove */
8476 (make_unibyte_string (fs
,
8479 Fx_send_client_event (frame
, make_number (0), frame
,
8480 make_unibyte_string (atom
, strlen (atom
)),
8482 Fcons (make_number (0), /* Remove */
8484 (make_unibyte_string (fh
,
8487 Fx_send_client_event (frame
, make_number (0), frame
,
8488 make_unibyte_string (atom
, strlen (atom
)),
8490 Fcons (make_number (0), /* Remove */
8492 (make_unibyte_string (fw
,
8495 f
->want_fullscreen
= FULLSCREEN_NONE
;
8497 Fx_send_client_event (frame
, make_number (0), frame
,
8498 make_unibyte_string (atom
, strlen (atom
)),
8500 Fcons (make_number (1), /* Add */
8502 (make_unibyte_string (what
,
8507 return have_net_atom
;
8511 XTfullscreen_hook (f
)
8514 if (f
->async_visible
)
8517 do_ewmh_fullscreen (f
);
8524 /* Check if we need to resize the frame due to a fullscreen request.
8525 If so needed, resize the frame. */
8527 x_check_fullscreen (f
)
8530 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
8532 int width
, height
, ign
;
8534 if (do_ewmh_fullscreen (f
))
8537 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8539 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8541 /* We do not need to move the window, it shall be taken care of
8542 when setting WM manager hints.
8543 If the frame is visible already, the position is checked by
8544 x_check_expected_move. */
8545 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8547 change_frame_size (f
, height
, width
, 0, 1, 0);
8548 SET_FRAME_GARBAGED (f
);
8549 cancel_mouse_face (f
);
8551 /* Wait for the change of frame size to occur */
8552 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
8557 /* This function is called by x_set_offset to determine whether the window
8558 manager interfered with the positioning of the frame. Type A window
8559 managers position the surrounding window manager decorations a small
8560 amount above and left of the user-supplied position. Type B window
8561 managers position the surrounding window manager decorations at the
8562 user-specified position. If we detect a Type A window manager, we
8563 compensate by moving the window right and down by the proper amount. */
8566 x_check_expected_move (f
, expected_left
, expected_top
)
8571 int current_left
= 0, current_top
= 0;
8573 /* x_real_positions returns the left and top offsets of the outermost
8574 window manager window around the frame. */
8576 x_real_positions (f
, ¤t_left
, ¤t_top
);
8578 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8580 /* It's a "Type A" window manager. */
8585 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8586 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8587 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8589 /* Now fix the mispositioned frame's location. */
8591 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8592 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8594 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8595 adjusted_left
, adjusted_top
);
8597 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8600 /* It's a "Type B" window manager. We don't have to adjust the
8601 frame's position. */
8603 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8607 /* Wait for XGetGeometry to return up-to-date position information for a
8608 recently-moved frame. Call this immediately after calling XMoveWindow.
8609 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8610 frame has been moved to, so we use a fuzzy position comparison instead
8611 of an exact comparison. */
8614 x_sync_with_move (f
, left
, top
, fuzzy
)
8616 int left
, top
, fuzzy
;
8620 while (count
++ < 50)
8622 int current_left
= 0, current_top
= 0;
8624 /* In theory, this call to XSync only needs to happen once, but in
8625 practice, it doesn't seem to work, hence the need for the surrounding
8628 XSync (FRAME_X_DISPLAY (f
), False
);
8629 x_real_positions (f
, ¤t_left
, ¤t_top
);
8633 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8636 if (abs (current_left
- left
) <= 10 && abs (current_top
- top
) <= 40)
8639 else if (current_left
== left
&& current_top
== top
)
8643 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8644 will then return up-to-date position info. */
8646 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8650 /* Change the size of frame F's X window to COLS/ROWS in the case F
8651 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8652 top-left-corner window gravity for this size change and subsequent
8653 size changes. Otherwise we leave the window gravity unchanged. */
8656 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
8661 int pixelwidth
, pixelheight
;
8663 check_frame_size (f
, &rows
, &cols
);
8664 f
->scroll_bar_actual_width
8665 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8667 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
8668 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
8669 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
8671 compute_fringe_widths (f
, 0);
8673 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
8674 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8676 f
->win_gravity
= NorthWestGravity
;
8677 x_wm_set_size_hint (f
, (long) 0, 0);
8679 XSync (FRAME_X_DISPLAY (f
), False
);
8680 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8681 pixelwidth
, pixelheight
);
8683 /* Now, strictly speaking, we can't be sure that this is accurate,
8684 but the window manager will get around to dealing with the size
8685 change request eventually, and we'll hear how it went when the
8686 ConfigureNotify event gets here.
8688 We could just not bother storing any of this information here,
8689 and let the ConfigureNotify event set everything up, but that
8690 might be kind of confusing to the Lisp code, since size changes
8691 wouldn't be reported in the frame parameters until some random
8692 point in the future when the ConfigureNotify event arrives.
8694 We pass 1 for DELAY since we can't run Lisp code inside of
8696 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8697 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8698 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8700 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8701 receive in the ConfigureNotify event; if we get what we asked
8702 for, then the event won't cause the screen to become garbaged, so
8703 we have to make sure to do it here. */
8704 SET_FRAME_GARBAGED (f
);
8706 XFlush (FRAME_X_DISPLAY (f
));
8710 /* Call this to change the size of frame F's x-window.
8711 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8712 for this size change and subsequent size changes.
8713 Otherwise we leave the window gravity unchanged. */
8716 x_set_window_size (f
, change_gravity
, cols
, rows
)
8724 if (FRAME_GTK_WIDGET (f
))
8725 xg_frame_set_char_size (f
, cols
, rows
);
8727 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8730 if (f
->output_data
.x
->widget
!= NULL
)
8732 /* The x and y position of the widget is clobbered by the
8733 call to XtSetValues within EmacsFrameSetCharSize.
8734 This is a real kludge, but I don't understand Xt so I can't
8735 figure out a correct fix. Can anyone else tell me? -- rms. */
8736 int xpos
= f
->output_data
.x
->widget
->core
.x
;
8737 int ypos
= f
->output_data
.x
->widget
->core
.y
;
8738 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
8739 f
->output_data
.x
->widget
->core
.x
= xpos
;
8740 f
->output_data
.x
->widget
->core
.y
= ypos
;
8743 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8745 #else /* not USE_X_TOOLKIT */
8747 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8749 #endif /* not USE_X_TOOLKIT */
8751 /* If cursor was outside the new size, mark it as off. */
8752 mark_window_cursors_off (XWINDOW (f
->root_window
));
8754 /* Clear out any recollection of where the mouse highlighting was,
8755 since it might be in a place that's outside the new frame size.
8756 Actually checking whether it is outside is a pain in the neck,
8757 so don't try--just let the highlighting be done afresh with new size. */
8758 cancel_mouse_face (f
);
8763 /* Mouse warping. */
8766 x_set_mouse_position (f
, x
, y
)
8772 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8773 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8775 if (pix_x
< 0) pix_x
= 0;
8776 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8778 if (pix_y
< 0) pix_y
= 0;
8779 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8783 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8784 0, 0, 0, 0, pix_x
, pix_y
);
8788 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8791 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
8797 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8798 0, 0, 0, 0, pix_x
, pix_y
);
8802 /* focus shifting, raising and lowering. */
8805 x_focus_on_frame (f
)
8808 #if 0 /* This proves to be unpleasant. */
8812 /* I don't think that the ICCCM allows programs to do things like this
8813 without the interaction of the window manager. Whatever you end up
8814 doing with this code, do it to x_unfocus_frame too. */
8815 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8816 RevertToPointerRoot
, CurrentTime
);
8825 /* Look at the remarks in x_focus_on_frame. */
8826 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8827 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8828 RevertToPointerRoot
, CurrentTime
);
8832 /* Raise frame F. */
8839 if (f
->async_visible
)
8840 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8842 XFlush (FRAME_X_DISPLAY (f
));
8846 /* Lower frame F. */
8852 if (f
->async_visible
)
8855 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8856 XFlush (FRAME_X_DISPLAY (f
));
8862 XTframe_raise_lower (f
, raise_flag
)
8868 /* The following code is needed for `raise-frame' to work on
8869 some versions of metacity; see Window Manager
8870 Specification/Extended Window Manager Hints at
8871 http://freedesktop.org/wiki/Standards_2fwm_2dspec */
8874 /* However, on other versions (metacity 2.17.2-1.fc7), it
8875 reportedly causes hangs when resizing frames. */
8877 const char *atom
= "_NET_ACTIVE_WINDOW";
8878 if (f
->async_visible
&& wm_supports (f
, atom
))
8881 XSETFRAME (frame
, f
);
8882 Fx_send_client_event (frame
, make_number (0), frame
,
8883 make_unibyte_string (atom
, strlen (atom
)),
8885 Fcons (make_number (1),
8886 Fcons (make_number (last_user_time
),
8897 /* Change of visibility. */
8899 /* This tries to wait until the frame is really visible.
8900 However, if the window manager asks the user where to position
8901 the frame, this will return before the user finishes doing that.
8902 The frame will not actually be visible at that time,
8903 but it will become visible later when the window manager
8904 finishes with it. */
8907 x_make_frame_visible (f
)
8911 int original_top
, original_left
;
8912 int retry_count
= 2;
8918 type
= x_icon_type (f
);
8920 x_bitmap_icon (f
, type
);
8922 if (! FRAME_VISIBLE_P (f
))
8924 /* We test FRAME_GARBAGED_P here to make sure we don't
8925 call x_set_offset a second time
8926 if we get to x_make_frame_visible a second time
8927 before the window gets really visible. */
8928 if (! FRAME_ICONIFIED_P (f
)
8929 && ! f
->output_data
.x
->asked_for_visible
)
8930 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8932 f
->output_data
.x
->asked_for_visible
= 1;
8934 if (! EQ (Vx_no_window_manager
, Qt
))
8935 x_wm_set_window_state (f
, NormalState
);
8936 #ifdef USE_X_TOOLKIT
8937 /* This was XtPopup, but that did nothing for an iconified frame. */
8938 XtMapWidget (f
->output_data
.x
->widget
);
8939 #else /* not USE_X_TOOLKIT */
8941 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8942 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8944 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8945 #endif /* not USE_GTK */
8946 #endif /* not USE_X_TOOLKIT */
8947 #if 0 /* This seems to bring back scroll bars in the wrong places
8948 if the window configuration has changed. They seem
8949 to come back ok without this. */
8950 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8951 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8955 XFlush (FRAME_X_DISPLAY (f
));
8957 /* Synchronize to ensure Emacs knows the frame is visible
8958 before we do anything else. We do this loop with input not blocked
8959 so that incoming events are handled. */
8963 /* This must be before UNBLOCK_INPUT
8964 since events that arrive in response to the actions above
8965 will set it when they are handled. */
8966 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8968 original_left
= f
->left_pos
;
8969 original_top
= f
->top_pos
;
8971 /* This must come after we set COUNT. */
8974 /* We unblock here so that arriving X events are processed. */
8976 /* Now move the window back to where it was "supposed to be".
8977 But don't do it if the gravity is negative.
8978 When the gravity is negative, this uses a position
8979 that is 3 pixels too low. Perhaps that's really the border width.
8981 Don't do this if the window has never been visible before,
8982 because the window manager may choose the position
8983 and we don't want to override it. */
8985 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
8986 && f
->win_gravity
== NorthWestGravity
8987 && previously_visible
)
8991 unsigned int width
, height
, border
, depth
;
8995 /* On some window managers (such as FVWM) moving an existing
8996 window, even to the same place, causes the window manager
8997 to introduce an offset. This can cause the window to move
8998 to an unexpected location. Check the geometry (a little
8999 slow here) and then verify that the window is in the right
9000 place. If the window is not in the right place, move it
9001 there, and take the potential window manager hit. */
9002 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9003 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9005 if (original_left
!= x
|| original_top
!= y
)
9006 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9007 original_left
, original_top
);
9012 XSETFRAME (frame
, f
);
9014 /* Wait until the frame is visible. Process X events until a
9015 MapNotify event has been seen, or until we think we won't get a
9016 MapNotify at all.. */
9017 for (count
= input_signal_count
+ 10;
9018 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9020 /* Force processing of queued events. */
9023 /* Machines that do polling rather than SIGIO have been
9024 observed to go into a busy-wait here. So we'll fake an
9025 alarm signal to let the handler know that there's something
9026 to be read. We used to raise a real alarm, but it seems
9027 that the handler isn't always enabled here. This is
9029 if (input_polling_used ())
9031 /* It could be confusing if a real alarm arrives while
9032 processing the fake one. Turn it off and let the
9033 handler reset it. */
9034 extern void poll_for_input_1
P_ ((void));
9035 int old_poll_suppress_count
= poll_suppress_count
;
9036 poll_suppress_count
= 1;
9037 poll_for_input_1 ();
9038 poll_suppress_count
= old_poll_suppress_count
;
9041 /* See if a MapNotify event has been processed. */
9042 FRAME_SAMPLE_VISIBILITY (f
);
9047 (let ((f (selected-frame)))
9051 the frame is not raised with various window managers on
9052 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9053 unknown reason, the call to XtMapWidget is completely ignored.
9054 Mapping the widget a second time works. */
9056 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9061 /* Change from mapped state to withdrawn state. */
9063 /* Make the frame visible (mapped and not iconified). */
9066 x_make_frame_invisible (f
)
9071 /* Use the frame's outermost window, not the one we normally draw on. */
9072 window
= FRAME_OUTER_WINDOW (f
);
9074 /* Don't keep the highlight on an invisible frame. */
9075 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9076 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9078 #if 0/* This might add unreliability; I don't trust it -- rms. */
9079 if (! f
->async_visible
&& ! f
->async_iconified
)
9085 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9086 that the current position of the window is user-specified, rather than
9087 program-specified, so that when the window is mapped again, it will be
9088 placed at the same location, without forcing the user to position it
9089 by hand again (they have already done that once for this window.) */
9090 x_wm_set_size_hint (f
, (long) 0, 1);
9093 if (FRAME_GTK_OUTER_WIDGET (f
))
9094 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9100 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9101 DefaultScreen (FRAME_X_DISPLAY (f
))))
9103 UNBLOCK_INPUT_RESIGNAL
;
9104 error ("Can't notify window manager of window withdrawal");
9106 #else /* ! defined (HAVE_X11R4) */
9108 /* Tell the window manager what we're going to do. */
9109 if (! EQ (Vx_no_window_manager
, Qt
))
9113 unmap
.xunmap
.type
= UnmapNotify
;
9114 unmap
.xunmap
.window
= window
;
9115 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
9116 unmap
.xunmap
.from_configure
= False
;
9117 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9118 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9120 SubstructureRedirectMaskSubstructureNotifyMask
,
9123 UNBLOCK_INPUT_RESIGNAL
;
9124 error ("Can't notify window manager of withdrawal");
9128 /* Unmap the window ourselves. Cheeky! */
9129 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
9130 #endif /* ! defined (HAVE_X11R4) */
9133 /* We can't distinguish this from iconification
9134 just by the event that we get from the server.
9135 So we can't win using the usual strategy of letting
9136 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9137 and synchronize with the server to make sure we agree. */
9139 FRAME_ICONIFIED_P (f
) = 0;
9140 f
->async_visible
= 0;
9141 f
->async_iconified
= 0;
9148 /* Change window state from mapped to iconified. */
9157 /* Don't keep the highlight on an invisible frame. */
9158 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9159 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9161 if (f
->async_iconified
)
9166 FRAME_SAMPLE_VISIBILITY (f
);
9168 type
= x_icon_type (f
);
9170 x_bitmap_icon (f
, type
);
9173 if (FRAME_GTK_OUTER_WIDGET (f
))
9175 if (! FRAME_VISIBLE_P (f
))
9176 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9178 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9181 f
->async_iconified
= 1;
9182 f
->async_visible
= 0;
9188 #ifdef USE_X_TOOLKIT
9190 if (! FRAME_VISIBLE_P (f
))
9192 if (! EQ (Vx_no_window_manager
, Qt
))
9193 x_wm_set_window_state (f
, IconicState
);
9194 /* This was XtPopup, but that did nothing for an iconified frame. */
9195 XtMapWidget (f
->output_data
.x
->widget
);
9196 /* The server won't give us any event to indicate
9197 that an invisible frame was changed to an icon,
9198 so we have to record it here. */
9201 f
->async_iconified
= 1;
9202 f
->async_visible
= 0;
9207 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9208 XtWindow (f
->output_data
.x
->widget
),
9209 DefaultScreen (FRAME_X_DISPLAY (f
)));
9213 error ("Can't notify window manager of iconification");
9215 f
->async_iconified
= 1;
9216 f
->async_visible
= 0;
9220 XFlush (FRAME_X_DISPLAY (f
));
9222 #else /* not USE_X_TOOLKIT */
9224 /* Make sure the X server knows where the window should be positioned,
9225 in case the user deiconifies with the window manager. */
9226 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
9227 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9229 /* Since we don't know which revision of X we're running, we'll use both
9230 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9232 /* X11R4: send a ClientMessage to the window manager using the
9233 WM_CHANGE_STATE type. */
9237 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9238 message
.xclient
.type
= ClientMessage
;
9239 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9240 message
.xclient
.format
= 32;
9241 message
.xclient
.data
.l
[0] = IconicState
;
9243 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9244 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9246 SubstructureRedirectMask
| SubstructureNotifyMask
,
9249 UNBLOCK_INPUT_RESIGNAL
;
9250 error ("Can't notify window manager of iconification");
9254 /* X11R3: set the initial_state field of the window manager hints to
9256 x_wm_set_window_state (f
, IconicState
);
9258 if (!FRAME_VISIBLE_P (f
))
9260 /* If the frame was withdrawn, before, we must map it. */
9261 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9264 f
->async_iconified
= 1;
9265 f
->async_visible
= 0;
9267 XFlush (FRAME_X_DISPLAY (f
));
9269 #endif /* not USE_X_TOOLKIT */
9273 /* Free X resources of frame F. */
9276 x_free_frame_resources (f
)
9279 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9281 struct scroll_bar
*b
;
9285 /* If a display connection is dead, don't try sending more
9286 commands to the X server. */
9287 if (dpyinfo
->display
)
9289 if (f
->output_data
.x
->icon_desc
)
9290 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9292 #ifdef USE_X_TOOLKIT
9293 /* Explicitly destroy the scroll bars of the frame. Without
9294 this, we get "BadDrawable" errors from the toolkit later on,
9295 presumably from expose events generated for the disappearing
9296 toolkit scroll bars. */
9297 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9299 b
= XSCROLL_BAR (bar
);
9300 x_scroll_bar_remove (b
);
9309 #ifdef USE_X_TOOLKIT
9310 if (f
->output_data
.x
->widget
)
9312 XtDestroyWidget (f
->output_data
.x
->widget
);
9313 f
->output_data
.x
->widget
= NULL
;
9315 /* Tooltips don't have widgets, only a simple X window, even if
9316 we are using a toolkit. */
9317 else if (FRAME_X_WINDOW (f
))
9318 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9320 free_frame_menubar (f
);
9321 #else /* !USE_X_TOOLKIT */
9324 /* In the GTK version, tooltips are normal X
9325 frames. We must check and free both types. */
9326 if (FRAME_GTK_OUTER_WIDGET (f
))
9328 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9329 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9330 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9332 #endif /* USE_GTK */
9334 if (FRAME_X_WINDOW (f
))
9335 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9336 #endif /* !USE_X_TOOLKIT */
9338 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
9339 unload_color (f
, f
->output_data
.x
->background_pixel
);
9340 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9341 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9342 unload_color (f
, f
->output_data
.x
->border_pixel
);
9343 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9345 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9346 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9347 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9348 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9349 #ifdef USE_TOOLKIT_SCROLL_BARS
9350 /* Scrollbar shadow colors. */
9351 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9352 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9353 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9354 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9355 #endif /* USE_TOOLKIT_SCROLL_BARS */
9356 if (f
->output_data
.x
->white_relief
.allocated_p
)
9357 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9358 if (f
->output_data
.x
->black_relief
.allocated_p
)
9359 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9361 if (FRAME_FACE_CACHE (f
))
9362 free_frame_faces (f
);
9365 XFlush (FRAME_X_DISPLAY (f
));
9368 if (f
->output_data
.x
->saved_menu_event
)
9369 xfree (f
->output_data
.x
->saved_menu_event
);
9371 xfree (f
->output_data
.x
);
9372 f
->output_data
.x
= NULL
;
9374 if (f
== dpyinfo
->x_focus_frame
)
9375 dpyinfo
->x_focus_frame
= 0;
9376 if (f
== dpyinfo
->x_focus_event_frame
)
9377 dpyinfo
->x_focus_event_frame
= 0;
9378 if (f
== dpyinfo
->x_highlight_frame
)
9379 dpyinfo
->x_highlight_frame
= 0;
9381 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9383 dpyinfo
->mouse_face_beg_row
9384 = dpyinfo
->mouse_face_beg_col
= -1;
9385 dpyinfo
->mouse_face_end_row
9386 = dpyinfo
->mouse_face_end_col
= -1;
9387 dpyinfo
->mouse_face_window
= Qnil
;
9388 dpyinfo
->mouse_face_deferred_gc
= 0;
9389 dpyinfo
->mouse_face_mouse_frame
= 0;
9396 /* Destroy the X window of frame F. */
9399 x_destroy_window (f
)
9402 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9404 /* If a display connection is dead, don't try sending more
9405 commands to the X server. */
9406 if (dpyinfo
->display
!= 0)
9407 x_free_frame_resources (f
);
9409 dpyinfo
->reference_count
--;
9413 /* Setting window manager hints. */
9415 /* Set the normal size hints for the window manager, for frame F.
9416 FLAGS is the flags word to use--or 0 meaning preserve the flags
9417 that the window now has.
9418 If USER_POSITION is nonzero, we set the USPosition
9419 flag (this is useful when FLAGS is 0).
9420 The GTK version is in gtkutils.c */
9424 x_wm_set_size_hint (f
, flags
, user_position
)
9429 XSizeHints size_hints
;
9431 #ifdef USE_X_TOOLKIT
9434 Dimension widget_width
, widget_height
;
9437 Window window
= FRAME_OUTER_WINDOW (f
);
9439 /* Setting PMaxSize caused various problems. */
9440 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9442 size_hints
.x
= f
->left_pos
;
9443 size_hints
.y
= f
->top_pos
;
9445 #ifdef USE_X_TOOLKIT
9446 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9447 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9448 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9449 size_hints
.height
= widget_height
;
9450 size_hints
.width
= widget_width
;
9451 #else /* not USE_X_TOOLKIT */
9452 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9453 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9454 #endif /* not USE_X_TOOLKIT */
9456 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9457 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9458 size_hints
.max_width
9459 = FRAME_X_DISPLAY_INFO (f
)->width
- FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9460 size_hints
.max_height
9461 = FRAME_X_DISPLAY_INFO (f
)->height
- FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9463 /* Calculate the base and minimum sizes.
9465 (When we use the X toolkit, we don't do it here.
9466 Instead we copy the values that the widgets are using, below.) */
9467 #ifndef USE_X_TOOLKIT
9469 int base_width
, base_height
;
9470 int min_rows
= 0, min_cols
= 0;
9472 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9473 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9475 check_frame_size (f
, &min_rows
, &min_cols
);
9477 /* The window manager uses the base width hints to calculate the
9478 current number of rows and columns in the frame while
9479 resizing; min_width and min_height aren't useful for this
9480 purpose, since they might not give the dimensions for a
9481 zero-row, zero-column frame.
9483 We use the base_width and base_height members if we have
9484 them; otherwise, we set the min_width and min_height members
9485 to the size for a zero x zero frame. */
9488 size_hints
.flags
|= PBaseSize
;
9489 size_hints
.base_width
= base_width
;
9490 size_hints
.base_height
= base_height
;
9491 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9492 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9494 size_hints
.min_width
= base_width
;
9495 size_hints
.min_height
= base_height
;
9499 /* If we don't need the old flags, we don't need the old hint at all. */
9502 size_hints
.flags
|= flags
;
9505 #endif /* not USE_X_TOOLKIT */
9508 XSizeHints hints
; /* Sometimes I hate X Windows... */
9509 long supplied_return
;
9513 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9516 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
9519 #ifdef USE_X_TOOLKIT
9520 size_hints
.base_height
= hints
.base_height
;
9521 size_hints
.base_width
= hints
.base_width
;
9522 size_hints
.min_height
= hints
.min_height
;
9523 size_hints
.min_width
= hints
.min_width
;
9527 size_hints
.flags
|= flags
;
9532 if (hints
.flags
& PSize
)
9533 size_hints
.flags
|= PSize
;
9534 if (hints
.flags
& PPosition
)
9535 size_hints
.flags
|= PPosition
;
9536 if (hints
.flags
& USPosition
)
9537 size_hints
.flags
|= USPosition
;
9538 if (hints
.flags
& USSize
)
9539 size_hints
.flags
|= USSize
;
9543 #ifndef USE_X_TOOLKIT
9548 size_hints
.win_gravity
= f
->win_gravity
;
9549 size_hints
.flags
|= PWinGravity
;
9553 size_hints
.flags
&= ~ PPosition
;
9554 size_hints
.flags
|= USPosition
;
9556 #endif /* PWinGravity */
9559 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9561 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9564 #endif /* not USE_GTK */
9566 /* Used for IconicState or NormalState */
9569 x_wm_set_window_state (f
, state
)
9573 #ifdef USE_X_TOOLKIT
9576 XtSetArg (al
[0], XtNinitialState
, state
);
9577 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9578 #else /* not USE_X_TOOLKIT */
9579 Window window
= FRAME_X_WINDOW (f
);
9581 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9582 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9584 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9585 #endif /* not USE_X_TOOLKIT */
9589 x_wm_set_icon_pixmap (f
, pixmap_id
)
9593 Pixmap icon_pixmap
, icon_mask
;
9595 #ifndef USE_X_TOOLKIT
9596 Window window
= FRAME_OUTER_WINDOW (f
);
9601 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9602 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9603 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9604 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9608 /* It seems there is no way to turn off use of an icon pixmap.
9609 The following line does it, only if no icon has yet been created,
9610 for some window managers. But with mwm it crashes.
9611 Some people say it should clear the IconPixmapHint bit in this case,
9612 but that doesn't work, and the X consortium said it isn't the
9613 right thing at all. Since there is no way to win,
9614 best to explicitly give up. */
9616 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
9617 f
->output_data
.x
->wm_hints
.icon_mask
= None
;
9626 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9630 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9634 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9635 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9636 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9637 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9640 #else /* not USE_X_TOOLKIT && not USE_GTK */
9642 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9643 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9645 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9649 x_wm_set_icon_position (f
, icon_x
, icon_y
)
9653 Window window
= FRAME_OUTER_WINDOW (f
);
9655 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9656 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9657 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9659 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9663 /***********************************************************************
9665 ***********************************************************************/
9667 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
9670 x_get_font_info (f
, font_idx
)
9674 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
9678 /* Return a list of names of available fonts matching PATTERN on frame F.
9680 If SIZE is > 0, it is the size (maximum bounds width) of fonts
9683 SIZE < 0 means include scalable fonts.
9685 Frame F null means we have not yet created any frame on X, and
9686 consult the first display in x_display_list. MAXNAMES sets a limit
9687 on how many fonts to match. */
9690 x_list_fonts (f
, pattern
, size
, maxnames
)
9692 Lisp_Object pattern
;
9696 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
9697 Lisp_Object tem
, second_best
;
9698 struct x_display_info
*dpyinfo
9699 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
9700 Display
*dpy
= dpyinfo
->display
;
9701 int try_XLoadQueryFont
= 0;
9702 int allow_auto_scaled_font
= 0;
9706 allow_auto_scaled_font
= 1;
9710 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
9711 if (NILP (patterns
))
9712 patterns
= Fcons (pattern
, Qnil
);
9714 if (maxnames
== 1 && !size
)
9715 /* We can return any single font matching PATTERN. */
9716 try_XLoadQueryFont
= 1;
9718 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
9721 char **names
= NULL
;
9723 pattern
= XCAR (patterns
);
9724 /* See if we cached the result for this particular query.
9725 The cache is an alist of the form:
9726 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
9727 tem
= XCDR (dpyinfo
->name_list_element
);
9728 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
9729 allow_auto_scaled_font
? Qt
: Qnil
);
9730 list
= Fassoc (key
, tem
);
9733 list
= Fcdr_safe (list
);
9734 /* We have a cashed list. Don't have to get the list again. */
9738 /* At first, put PATTERN in the cache. */
9741 x_catch_errors (dpy
);
9743 if (try_XLoadQueryFont
)
9746 unsigned long value
;
9748 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
9749 if (x_had_errors_p (dpy
))
9751 /* This error is perhaps due to insufficient memory on X
9752 server. Let's just ignore it. */
9754 x_clear_errors (dpy
);
9758 && XGetFontProperty (font
, XA_FONT
, &value
))
9760 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
9761 int len
= strlen (name
);
9764 /* If DXPC (a Differential X Protocol Compressor)
9765 Ver.3.7 is running, XGetAtomName will return null
9766 string. We must avoid such a name. */
9768 try_XLoadQueryFont
= 0;
9772 names
= (char **) alloca (sizeof (char *));
9773 /* Some systems only allow alloca assigned to a
9775 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
9776 bcopy (name
, names
[0], len
+ 1);
9781 try_XLoadQueryFont
= 0;
9784 XFreeFont (dpy
, font
);
9787 if (!try_XLoadQueryFont
)
9789 /* We try at least 10 fonts because XListFonts will return
9790 auto-scaled fonts at the head. */
9797 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
9798 if (num_fonts
== limit
)
9801 XFreeFontNames (names
);
9810 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
9813 if (x_had_errors_p (dpy
))
9815 /* This error is perhaps due to insufficient memory on X
9816 server. Let's just ignore it. */
9818 x_clear_errors (dpy
);
9822 x_uncatch_errors ();
9829 /* Make a list of all the fonts we got back.
9830 Store that in the font cache for the display. */
9831 for (i
= 0; i
< num_fonts
; i
++)
9835 int average_width
= -1, resx
= 0, dashes
= 0;
9837 /* Count the number of dashes in NAMES[I]. If there are
9838 14 dashes, the field value following 9th dash
9839 (RESOLUTION_X) is nonzero, and the field value
9840 following 12th dash (AVERAGE_WIDTH) is 0, this is a
9841 auto-scaled font which is usually too ugly to be used
9842 for editing. Let's ignore it. */
9847 if (dashes
== 7) /* PIXEL_SIZE field */
9849 else if (dashes
== 9)
9851 else if (dashes
== 12) /* AVERAGE_WIDTH field */
9852 average_width
= atoi (p
);
9855 if (allow_auto_scaled_font
9856 || dashes
< 14 || average_width
!= 0 || resx
== 0)
9858 tem
= build_string (names
[i
]);
9859 if (NILP (Fassoc (tem
, list
)))
9861 if (STRINGP (Vx_pixel_size_width_font_regexp
)
9862 && ((fast_c_string_match_ignore_case
9863 (Vx_pixel_size_width_font_regexp
, names
[i
]))
9865 /* We can set the value of PIXEL_SIZE to the
9866 width of this font. */
9867 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
9869 /* For the moment, width is not known. */
9870 list
= Fcons (Fcons (tem
, Qnil
), list
);
9875 if (!try_XLoadQueryFont
)
9878 XFreeFontNames (names
);
9883 /* Now store the result in the cache. */
9884 XSETCDR (dpyinfo
->name_list_element
,
9885 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
9888 if (NILP (list
)) continue; /* Try the remaining alternatives. */
9890 newlist
= second_best
= Qnil
;
9891 /* Make a list of the fonts that have the right width. */
9892 for (; CONSP (list
); list
= XCDR (list
))
9898 if (!CONSP (tem
) || NILP (XCAR (tem
)))
9902 newlist
= Fcons (XCAR (tem
), newlist
);
9906 if (!INTEGERP (XCDR (tem
)))
9908 /* Since we have not yet known the size of this font, we
9909 must try slow function call XLoadQueryFont. */
9910 XFontStruct
*thisinfo
;
9913 x_catch_errors (dpy
);
9914 thisinfo
= XLoadQueryFont (dpy
,
9915 SDATA (XCAR (tem
)));
9916 if (x_had_errors_p (dpy
))
9918 /* This error is perhaps due to insufficient memory on X
9919 server. Let's just ignore it. */
9921 x_clear_errors (dpy
);
9923 x_uncatch_errors ();
9929 (thisinfo
->min_bounds
.width
== 0
9931 : make_number (thisinfo
->max_bounds
.width
)));
9933 XFreeFont (dpy
, thisinfo
);
9937 /* For unknown reason, the previous call of XListFont had
9938 returned a font which can't be opened. Record the size
9939 as 0 not to try to open it again. */
9940 XSETCDR (tem
, make_number (0));
9943 found_size
= XINT (XCDR (tem
));
9944 if (found_size
== size
)
9945 newlist
= Fcons (XCAR (tem
), newlist
);
9946 else if (found_size
> 0)
9948 if (NILP (second_best
))
9950 else if (found_size
< size
)
9952 if (XINT (XCDR (second_best
)) > size
9953 || XINT (XCDR (second_best
)) < found_size
)
9958 if (XINT (XCDR (second_best
)) > size
9959 && XINT (XCDR (second_best
)) > found_size
)
9964 if (!NILP (newlist
))
9966 else if (!NILP (second_best
))
9968 newlist
= Fcons (XCAR (second_best
), Qnil
);
9979 /* Check that FONT is valid on frame F. It is if it can be found in F's
9983 x_check_font (f
, font
)
9988 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9990 xassert (font
!= NULL
);
9992 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
9993 if (dpyinfo
->font_table
[i
].name
9994 && font
== dpyinfo
->font_table
[i
].font
)
9997 xassert (i
< dpyinfo
->n_fonts
);
10000 #endif /* GLYPH_DEBUG != 0 */
10002 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10003 Note: There are (broken) X fonts out there with invalid XFontStruct
10004 min_bounds contents. For example, handa@etl.go.jp reports that
10005 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10006 have font->min_bounds.width == 0. */
10009 x_font_min_bounds (font
, w
, h
)
10013 *h
= FONT_HEIGHT (font
);
10014 *w
= font
->min_bounds
.width
;
10016 /* Try to handle the case where FONT->min_bounds has invalid
10017 contents. Since the only font known to have invalid min_bounds
10018 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
10020 *w
= font
->max_bounds
.width
;
10024 /* Compute the smallest character width and smallest font height over
10025 all fonts available on frame F. Set the members smallest_char_width
10026 and smallest_font_height in F's x_display_info structure to
10027 the values computed. Value is non-zero if smallest_font_height or
10028 smallest_char_width become smaller than they were before. */
10031 x_compute_min_glyph_bounds (f
)
10035 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10037 int old_width
= dpyinfo
->smallest_char_width
;
10038 int old_height
= dpyinfo
->smallest_font_height
;
10040 dpyinfo
->smallest_font_height
= 100000;
10041 dpyinfo
->smallest_char_width
= 100000;
10043 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10044 if (dpyinfo
->font_table
[i
].name
)
10046 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10049 font
= (XFontStruct
*) fontp
->font
;
10050 xassert (font
!= (XFontStruct
*) ~0);
10051 x_font_min_bounds (font
, &w
, &h
);
10053 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10054 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10057 xassert (dpyinfo
->smallest_char_width
> 0
10058 && dpyinfo
->smallest_font_height
> 0);
10060 return (dpyinfo
->n_fonts
== 1
10061 || dpyinfo
->smallest_char_width
< old_width
10062 || dpyinfo
->smallest_font_height
< old_height
);
10066 /* Load font named FONTNAME of the size SIZE for frame F, and return a
10067 pointer to the structure font_info while allocating it dynamically.
10068 If SIZE is 0, load any size of font.
10069 If loading is failed, return NULL. */
10072 x_load_font (f
, fontname
, size
)
10074 register char *fontname
;
10077 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10078 Lisp_Object font_names
;
10080 /* Get a list of all the fonts that match this name. Once we
10081 have a list of matching fonts, we compare them against the fonts
10082 we already have by comparing names. */
10083 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
10085 if (!NILP (font_names
))
10090 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10091 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
10092 if (dpyinfo
->font_table
[i
].name
10093 && (!strcmp (dpyinfo
->font_table
[i
].name
,
10094 SDATA (XCAR (tail
)))
10095 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
10096 SDATA (XCAR (tail
)))))
10097 return (dpyinfo
->font_table
+ i
);
10100 /* Load the font and add it to the table. */
10104 struct font_info
*fontp
;
10105 unsigned long value
;
10108 /* If we have found fonts by x_list_font, load one of them. If
10109 not, we still try to load a font by the name given as FONTNAME
10110 because XListFonts (called in x_list_font) of some X server has
10111 a bug of not finding a font even if the font surely exists and
10112 is loadable by XLoadQueryFont. */
10113 if (size
> 0 && !NILP (font_names
))
10114 fontname
= (char *) SDATA (XCAR (font_names
));
10117 x_catch_errors (FRAME_X_DISPLAY (f
));
10118 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
10119 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
10121 /* This error is perhaps due to insufficient memory on X
10122 server. Let's just ignore it. */
10124 x_clear_errors (FRAME_X_DISPLAY (f
));
10126 x_uncatch_errors ();
10131 /* Find a free slot in the font table. */
10132 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10133 if (dpyinfo
->font_table
[i
].name
== NULL
)
10136 /* If no free slot found, maybe enlarge the font table. */
10137 if (i
== dpyinfo
->n_fonts
10138 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
10141 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
10142 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
10143 dpyinfo
->font_table
10144 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
10147 fontp
= dpyinfo
->font_table
+ i
;
10148 if (i
== dpyinfo
->n_fonts
)
10149 ++dpyinfo
->n_fonts
;
10151 /* Now fill in the slots of *FONTP. */
10153 bzero (fontp
, sizeof (*fontp
));
10154 fontp
->font
= font
;
10155 fontp
->font_idx
= i
;
10156 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
10157 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
10159 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
10161 /* Fixed width font. */
10162 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
10169 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
10170 pcm
= x_per_char_metric (font
, &char2b
, 0);
10172 fontp
->space_width
= pcm
->width
;
10174 fontp
->space_width
= FONT_WIDTH (font
);
10176 fontp
->average_width
10177 = (XGetFontProperty (font
, dpyinfo
->Xatom_AVERAGE_WIDTH
, &value
)
10178 ? (long) value
/ 10 : 0);
10179 if (fontp
->average_width
< 0)
10180 fontp
->average_width
= - fontp
->average_width
;
10181 if (fontp
->average_width
== 0)
10185 int width
= pcm
->width
;
10186 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
10187 if ((pcm
= x_per_char_metric (font
, &char2b
, 0)) != NULL
)
10188 width
+= pcm
->width
;
10189 fontp
->average_width
= width
/ 95;
10192 fontp
->average_width
= FONT_WIDTH (font
);
10196 /* Try to get the full name of FONT. Put it in FULL_NAME. */
10198 if (XGetFontProperty (font
, XA_FONT
, &value
))
10200 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
10204 /* Count the number of dashes in the "full name".
10205 If it is too few, this isn't really the font's full name,
10207 In X11R4, the fonts did not come with their canonical names
10218 full_name
= (char *) xmalloc (p
- name
+ 1);
10219 bcopy (name
, full_name
, p
- name
+ 1);
10225 if (full_name
!= 0)
10226 fontp
->full_name
= full_name
;
10228 fontp
->full_name
= fontp
->name
;
10230 fontp
->size
= font
->max_bounds
.width
;
10231 fontp
->height
= FONT_HEIGHT (font
);
10233 if (NILP (font_names
))
10235 /* We come here because of a bug of XListFonts mentioned at
10236 the head of this block. Let's store this information in
10237 the cache for x_list_fonts. */
10238 Lisp_Object lispy_name
= build_string (fontname
);
10239 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
10240 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
10243 XSETCDR (dpyinfo
->name_list_element
,
10245 Fcons (Fcons (lispy_full_name
,
10246 make_number (fontp
->size
)),
10248 XCDR (dpyinfo
->name_list_element
)));
10251 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
10253 XSETCDR (dpyinfo
->name_list_element
,
10255 Fcons (Fcons (lispy_full_name
,
10256 make_number (fontp
->size
)),
10258 XCDR (dpyinfo
->name_list_element
)));
10262 /* The slot `encoding' specifies how to map a character
10263 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
10264 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
10265 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
10266 2:0xA020..0xFF7F). For the moment, we don't know which charset
10267 uses this font. So, we set information in fontp->encoding[1]
10268 which is never used by any charset. If mapping can't be
10269 decided, set FONT_ENCODING_NOT_DECIDED. */
10271 = (font
->max_byte1
== 0
10273 ? (font
->min_char_or_byte2
< 0x80
10274 ? (font
->max_char_or_byte2
< 0x80
10275 ? 0 /* 0x20..0x7F */
10276 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
10277 : 1) /* 0xA0..0xFF */
10279 : (font
->min_byte1
< 0x80
10280 ? (font
->max_byte1
< 0x80
10281 ? (font
->min_char_or_byte2
< 0x80
10282 ? (font
->max_char_or_byte2
< 0x80
10283 ? 0 /* 0x2020..0x7F7F */
10284 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
10285 : 3) /* 0x20A0..0x7FFF */
10286 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
10287 : (font
->min_char_or_byte2
< 0x80
10288 ? (font
->max_char_or_byte2
< 0x80
10289 ? 2 /* 0xA020..0xFF7F */
10290 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
10291 : 1))); /* 0xA0A0..0xFFFF */
10293 fontp
->baseline_offset
10294 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
10295 ? (long) value
: 0);
10296 fontp
->relative_compose
10297 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
10298 ? (long) value
: 0);
10299 fontp
->default_ascent
10300 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
10301 ? (long) value
: 0);
10303 /* Set global flag fonts_changed_p to non-zero if the font loaded
10304 has a character with a smaller width than any other character
10305 before, or if the font loaded has a smaller height than any
10306 other font loaded before. If this happens, it will make a
10307 glyph matrix reallocation necessary. */
10308 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
10315 /* Return a pointer to struct font_info of a font named FONTNAME for
10316 frame F. If no such font is loaded, return NULL. */
10319 x_query_font (f
, fontname
)
10321 register char *fontname
;
10323 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10326 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10327 if (dpyinfo
->font_table
[i
].name
10328 && (!xstricmp (dpyinfo
->font_table
[i
].name
, fontname
)
10329 || !xstricmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
10330 return (dpyinfo
->font_table
+ i
);
10335 /* Find a CCL program for a font specified by FONTP, and set the member
10336 `encoder' of the structure. */
10339 x_find_ccl_program (fontp
)
10340 struct font_info
*fontp
;
10342 Lisp_Object list
, elt
;
10345 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
10349 && STRINGP (XCAR (elt
))
10350 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
10352 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
10359 struct ccl_program
*ccl
10360 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
10362 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
10365 fontp
->font_encoder
= ccl
;
10371 /***********************************************************************
10373 ***********************************************************************/
10375 #ifdef USE_X_TOOLKIT
10376 static XrmOptionDescRec emacs_options
[] = {
10377 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
10378 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
10380 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
10381 XrmoptionSepArg
, NULL
},
10382 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
10384 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10385 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10386 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10387 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10388 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10389 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
10390 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
10393 /* Whether atimer for Xt timeouts is activated or not. */
10395 static int x_timeout_atimer_activated_flag
;
10397 #endif /* USE_X_TOOLKIT */
10399 static int x_initialized
;
10402 static int x_session_initialized
;
10405 #ifdef MULTI_KBOARD
10406 /* Test whether two display-name strings agree up to the dot that separates
10407 the screen number from the server number. */
10409 same_x_server (name1
, name2
)
10410 const char *name1
, *name2
;
10412 int seen_colon
= 0;
10413 const unsigned char *system_name
= SDATA (Vsystem_name
);
10414 int system_name_length
= strlen (system_name
);
10415 int length_until_period
= 0;
10417 while (system_name
[length_until_period
] != 0
10418 && system_name
[length_until_period
] != '.')
10419 length_until_period
++;
10421 /* Treat `unix' like an empty host name. */
10422 if (! strncmp (name1
, "unix:", 5))
10424 if (! strncmp (name2
, "unix:", 5))
10426 /* Treat this host's name like an empty host name. */
10427 if (! strncmp (name1
, system_name
, system_name_length
)
10428 && name1
[system_name_length
] == ':')
10429 name1
+= system_name_length
;
10430 if (! strncmp (name2
, system_name
, system_name_length
)
10431 && name2
[system_name_length
] == ':')
10432 name2
+= system_name_length
;
10433 /* Treat this host's domainless name like an empty host name. */
10434 if (! strncmp (name1
, system_name
, length_until_period
)
10435 && name1
[length_until_period
] == ':')
10436 name1
+= length_until_period
;
10437 if (! strncmp (name2
, system_name
, length_until_period
)
10438 && name2
[length_until_period
] == ':')
10439 name2
+= length_until_period
;
10441 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
10445 if (seen_colon
&& *name1
== '.')
10449 && (*name1
== '.' || *name1
== '\0')
10450 && (*name2
== '.' || *name2
== '\0'));
10454 /* Count number of set bits in mask and number of bits to shift to
10455 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
10458 get_bits_and_offset (mask
, bits
, offset
)
10459 unsigned long mask
;
10466 while (!(mask
& 1))
10483 x_display_ok (display
)
10484 const char * display
;
10489 dpy
= XOpenDisplay (display
);
10491 XCloseDisplay (dpy
);
10497 struct x_display_info
*
10498 x_term_init (display_name
, xrm_option
, resource_name
)
10499 Lisp_Object display_name
;
10501 char *resource_name
;
10505 struct x_display_info
*dpyinfo
;
10510 if (!x_initialized
)
10518 #define NUM_ARGV 10
10520 char *argv
[NUM_ARGV
];
10521 char **argv2
= argv
;
10524 if (x_initialized
++ > 1)
10526 /* Opening another display. If xg_display_open returns less
10527 than zero, we are probably on GTK 2.0, which can only handle
10528 one display. GTK 2.2 or later can handle more than one. */
10529 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
10530 error ("Sorry, this version of GTK can only handle one display");
10534 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
10538 argv
[argc
++] = initial_argv
[0];
10540 if (! NILP (display_name
))
10542 argv
[argc
++] = "--display";
10543 argv
[argc
++] = SDATA (display_name
);
10546 argv
[argc
++] = "--name";
10547 argv
[argc
++] = resource_name
;
10550 XSetLocaleModifiers ("");
10553 gtk_init (&argc
, &argv2
);
10555 /* gtk_init does set_locale. We must fix locale after calling it. */
10559 dpy
= GDK_DISPLAY ();
10561 /* NULL window -> events for all windows go to our function */
10562 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10564 /* Load our own gtkrc if it exists. */
10566 char *file
= "~/.emacs.d/gtkrc";
10567 Lisp_Object s
, abs_file
;
10569 s
= make_string (file
, strlen (file
));
10570 abs_file
= Fexpand_file_name (s
, Qnil
);
10572 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10573 gtk_rc_parse (SDATA (abs_file
));
10576 XSetErrorHandler (x_error_handler
);
10577 XSetIOErrorHandler (x_io_error_quitter
);
10580 #else /* not USE_GTK */
10581 #ifdef USE_X_TOOLKIT
10582 /* weiner@footloose.sps.mot.com reports that this causes
10584 X protocol error: BadAtom (invalid Atom parameter)
10585 on protocol request 18skiloaf.
10586 So let's not use it until R6. */
10587 #ifdef HAVE_X11XTR6
10588 XtSetLanguageProc (NULL
, NULL
, NULL
);
10599 argv
[argc
++] = "-xrm";
10600 argv
[argc
++] = xrm_option
;
10602 turn_on_atimers (0);
10603 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
10604 resource_name
, EMACS_CLASS
,
10605 emacs_options
, XtNumber (emacs_options
),
10607 turn_on_atimers (1);
10609 #ifdef HAVE_X11XTR6
10610 /* I think this is to compensate for XtSetLanguageProc. */
10615 #else /* not USE_X_TOOLKIT */
10617 XSetLocaleModifiers ("");
10619 dpy
= XOpenDisplay (SDATA (display_name
));
10620 #endif /* not USE_X_TOOLKIT */
10621 #endif /* not USE_GTK*/
10623 /* Detect failure. */
10630 /* We have definitely succeeded. Record the new connection. */
10632 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
10633 bzero (dpyinfo
, sizeof *dpyinfo
);
10635 #ifdef MULTI_KBOARD
10637 struct x_display_info
*share
;
10640 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10641 share
= share
->next
, tail
= XCDR (tail
))
10642 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
10643 SDATA (display_name
)))
10646 dpyinfo
->kboard
= share
->kboard
;
10649 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
10650 init_kboard (dpyinfo
->kboard
);
10651 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10653 char *vendor
= ServerVendor (dpy
);
10655 dpyinfo
->kboard
->Vsystem_key_alist
10656 = call1 (Qvendor_specific_keysyms
,
10657 build_string (vendor
? vendor
: ""));
10661 dpyinfo
->kboard
->next_kboard
= all_kboards
;
10662 all_kboards
= dpyinfo
->kboard
;
10663 /* Don't let the initial kboard remain current longer than necessary.
10664 That would cause problems if a file loaded on startup tries to
10665 prompt in the mini-buffer. */
10666 if (current_kboard
== initial_kboard
)
10667 current_kboard
= dpyinfo
->kboard
;
10669 dpyinfo
->kboard
->reference_count
++;
10673 /* Put this display on the chain. */
10674 dpyinfo
->next
= x_display_list
;
10675 x_display_list
= dpyinfo
;
10677 /* Put it on x_display_name_list as well, to keep them parallel. */
10678 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10679 x_display_name_list
);
10680 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10682 dpyinfo
->display
= dpy
;
10685 XSetAfterFunction (x_current_display
, x_trace_wire
);
10689 = (char *) xmalloc (SBYTES (Vinvocation_name
)
10690 + SBYTES (Vsystem_name
)
10692 sprintf (dpyinfo
->x_id_name
, "%s@%s",
10693 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10695 /* Figure out which modifier bits mean what. */
10696 x_find_modifier_meanings (dpyinfo
);
10698 /* Get the scroll bar cursor. */
10700 /* We must create a GTK cursor, it is required for GTK widgets. */
10701 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10702 #endif /* USE_GTK */
10704 dpyinfo
->vertical_scroll_bar_cursor
10705 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10707 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10708 resource_name
, EMACS_CLASS
);
10709 #ifdef HAVE_XRMSETDATABASE
10710 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10712 dpyinfo
->display
->db
= xrdb
;
10714 /* Put the rdb where we can find it in a way that works on
10716 dpyinfo
->xrdb
= xrdb
;
10718 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10719 DefaultScreen (dpyinfo
->display
));
10720 select_visual (dpyinfo
);
10721 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10722 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
10723 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
10724 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10725 dpyinfo
->client_leader_window
= 0;
10726 dpyinfo
->grabbed
= 0;
10727 dpyinfo
->reference_count
= 0;
10728 dpyinfo
->icon_bitmap_id
= -1;
10729 dpyinfo
->font_table
= NULL
;
10730 dpyinfo
->n_fonts
= 0;
10731 dpyinfo
->font_table_size
= 0;
10732 dpyinfo
->bitmaps
= 0;
10733 dpyinfo
->bitmaps_size
= 0;
10734 dpyinfo
->bitmaps_last
= 0;
10735 dpyinfo
->scratch_cursor_gc
= 0;
10736 dpyinfo
->mouse_face_mouse_frame
= 0;
10737 dpyinfo
->mouse_face_deferred_gc
= 0;
10738 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10739 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10740 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10741 dpyinfo
->mouse_face_window
= Qnil
;
10742 dpyinfo
->mouse_face_overlay
= Qnil
;
10743 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
10744 dpyinfo
->mouse_face_defer
= 0;
10745 dpyinfo
->mouse_face_hidden
= 0;
10746 dpyinfo
->x_focus_frame
= 0;
10747 dpyinfo
->x_focus_event_frame
= 0;
10748 dpyinfo
->x_highlight_frame
= 0;
10749 dpyinfo
->image_cache
= make_image_cache ();
10750 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10752 /* See if we can construct pixel values from RGB values. */
10753 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
10754 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
10756 if (dpyinfo
->visual
->class == TrueColor
)
10758 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10759 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10760 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10761 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10762 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10763 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10766 /* See if a private colormap is requested. */
10767 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10769 if (dpyinfo
->visual
->class == PseudoColor
)
10772 value
= display_x_get_resource (dpyinfo
,
10773 build_string ("privateColormap"),
10774 build_string ("PrivateColormap"),
10776 if (STRINGP (value
)
10777 && (!strcmp (SDATA (value
), "true")
10778 || !strcmp (SDATA (value
), "on")))
10779 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10783 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10784 dpyinfo
->visual
, AllocNone
);
10787 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10788 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10789 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10790 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10791 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10792 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10793 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10794 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10795 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10798 dpyinfo
->Xatom_wm_protocols
10799 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10800 dpyinfo
->Xatom_wm_take_focus
10801 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10802 dpyinfo
->Xatom_wm_save_yourself
10803 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10804 dpyinfo
->Xatom_wm_delete_window
10805 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10806 dpyinfo
->Xatom_wm_change_state
10807 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10808 dpyinfo
->Xatom_wm_configure_denied
10809 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10810 dpyinfo
->Xatom_wm_window_moved
10811 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10812 dpyinfo
->Xatom_wm_client_leader
10813 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10814 dpyinfo
->Xatom_editres
10815 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10816 dpyinfo
->Xatom_CLIPBOARD
10817 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10818 dpyinfo
->Xatom_TIMESTAMP
10819 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10820 dpyinfo
->Xatom_TEXT
10821 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10822 dpyinfo
->Xatom_COMPOUND_TEXT
10823 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10824 dpyinfo
->Xatom_UTF8_STRING
10825 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10826 dpyinfo
->Xatom_DELETE
10827 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10828 dpyinfo
->Xatom_MULTIPLE
10829 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10830 dpyinfo
->Xatom_INCR
10831 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10832 dpyinfo
->Xatom_EMACS_TMP
10833 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10834 dpyinfo
->Xatom_TARGETS
10835 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10836 dpyinfo
->Xatom_NULL
10837 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10838 dpyinfo
->Xatom_ATOM_PAIR
10839 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10840 /* For properties of font. */
10841 dpyinfo
->Xatom_PIXEL_SIZE
10842 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10843 dpyinfo
->Xatom_AVERAGE_WIDTH
10844 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
10845 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10846 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10847 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10848 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10849 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10850 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10852 /* Ghostscript support. */
10853 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10854 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10856 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10859 dpyinfo
->cut_buffers_initialized
= 0;
10861 dpyinfo
->x_dnd_atoms_size
= 8;
10862 dpyinfo
->x_dnd_atoms_length
= 0;
10863 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
10864 * dpyinfo
->x_dnd_atoms_size
);
10866 dpyinfo
->net_supported_atoms
= NULL
;
10867 dpyinfo
->nr_net_supported_atoms
= 0;
10868 dpyinfo
->net_supported_window
= 0;
10870 connection
= ConnectionNumber (dpyinfo
->display
);
10871 dpyinfo
->connection
= connection
;
10876 null_bits
[0] = 0x00;
10878 dpyinfo
->null_pixel
10879 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10880 null_bits
, 1, 1, (long) 0, (long) 0,
10885 extern int gray_bitmap_width
, gray_bitmap_height
;
10886 extern char *gray_bitmap_bits
;
10888 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10890 gray_bitmap_width
, gray_bitmap_height
,
10891 (unsigned long) 1, (unsigned long) 0, 1);
10895 xim_initialize (dpyinfo
, resource_name
);
10898 #ifdef subprocesses
10899 /* This is only needed for distinguishing keyboard and process input. */
10900 if (connection
!= 0)
10901 add_keyboard_wait_descriptor (connection
);
10904 #ifndef F_SETOWN_BUG
10906 #ifdef F_SETOWN_SOCK_NEG
10907 /* stdin is a socket here */
10908 fcntl (connection
, F_SETOWN
, -getpid ());
10909 #else /* ! defined (F_SETOWN_SOCK_NEG) */
10910 fcntl (connection
, F_SETOWN
, getpid ());
10911 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
10912 #endif /* ! defined (F_SETOWN) */
10913 #endif /* F_SETOWN_BUG */
10916 if (interrupt_input
)
10917 init_sigio (connection
);
10918 #endif /* ! defined (SIGIO) */
10921 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
10922 /* Make sure that we have a valid font for dialog boxes
10923 so that Xt does not crash. */
10925 Display
*dpy
= dpyinfo
->display
;
10926 XrmValue d
, fr
, to
;
10929 d
.addr
= (XPointer
)&dpy
;
10930 d
.size
= sizeof (Display
*);
10931 fr
.addr
= XtDefaultFont
;
10932 fr
.size
= sizeof (XtDefaultFont
);
10933 to
.size
= sizeof (Font
*);
10934 to
.addr
= (XPointer
)&font
;
10935 x_catch_errors (dpy
);
10936 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10938 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10939 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10940 x_uncatch_errors ();
10945 /* See if we should run in synchronous mode. This is useful
10946 for debugging X code. */
10949 value
= display_x_get_resource (dpyinfo
,
10950 build_string ("synchronous"),
10951 build_string ("Synchronous"),
10953 if (STRINGP (value
)
10954 && (!strcmp (SDATA (value
), "true")
10955 || !strcmp (SDATA (value
), "on")))
10956 XSynchronize (dpyinfo
->display
, True
);
10961 value
= display_x_get_resource (dpyinfo
,
10962 build_string ("useXIM"),
10963 build_string ("UseXIM"),
10966 if (STRINGP (value
)
10967 && (!strcmp (XSTRING (value
)->data
, "false")
10968 || !strcmp (XSTRING (value
)->data
, "off")))
10971 if (STRINGP (value
)
10972 && (!strcmp (XSTRING (value
)->data
, "true")
10973 || !strcmp (XSTRING (value
)->data
, "on")))
10979 /* Only do this for the first display. */
10980 if (!x_session_initialized
++)
10981 x_session_initialize (dpyinfo
);
10989 /* Get rid of display DPYINFO, assuming all frames are already gone,
10990 and without sending any more commands to the X server. */
10993 x_delete_display (dpyinfo
)
10994 struct x_display_info
*dpyinfo
;
10998 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
11000 /* Discard this display from x_display_name_list and x_display_list.
11001 We can't use Fdelq because that can quit. */
11002 if (! NILP (x_display_name_list
)
11003 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
11004 x_display_name_list
= XCDR (x_display_name_list
);
11009 tail
= x_display_name_list
;
11010 while (CONSP (tail
) && CONSP (XCDR (tail
)))
11012 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
11014 XSETCDR (tail
, XCDR (XCDR (tail
)));
11017 tail
= XCDR (tail
);
11021 if (next_noop_dpyinfo
== dpyinfo
)
11022 next_noop_dpyinfo
= dpyinfo
->next
;
11024 if (x_display_list
== dpyinfo
)
11025 x_display_list
= dpyinfo
->next
;
11028 struct x_display_info
*tail
;
11030 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
11031 if (tail
->next
== dpyinfo
)
11032 tail
->next
= tail
->next
->next
;
11035 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
11036 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
11037 XrmDestroyDatabase (dpyinfo
->xrdb
);
11040 #ifdef MULTI_KBOARD
11041 if (--dpyinfo
->kboard
->reference_count
== 0)
11042 delete_kboard (dpyinfo
->kboard
);
11046 xim_close_dpy (dpyinfo
);
11049 /* Free the font names in the font table. */
11050 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11051 if (dpyinfo
->font_table
[i
].name
)
11053 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
11054 xfree (dpyinfo
->font_table
[i
].full_name
);
11055 xfree (dpyinfo
->font_table
[i
].name
);
11058 if (dpyinfo
->font_table
)
11060 if (dpyinfo
->font_table
->font_encoder
)
11061 xfree (dpyinfo
->font_table
->font_encoder
);
11062 xfree (dpyinfo
->font_table
);
11064 if (dpyinfo
->x_id_name
)
11065 xfree (dpyinfo
->x_id_name
);
11066 if (dpyinfo
->color_cells
)
11067 xfree (dpyinfo
->color_cells
);
11071 #ifdef USE_X_TOOLKIT
11073 /* Atimer callback function for TIMER. Called every 0.1s to process
11074 Xt timeouts, if needed. We must avoid calling XtAppPending as
11075 much as possible because that function does an implicit XFlush
11076 that slows us down. */
11079 x_process_timeouts (timer
)
11080 struct atimer
*timer
;
11083 x_timeout_atimer_activated_flag
= 0;
11084 if (toolkit_scroll_bar_interaction
|| popup_activated ())
11086 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
11087 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
11088 /* Reactivate the atimer for next time. */
11089 x_activate_timeout_atimer ();
11094 /* Install an asynchronous timer that processes Xt timeout events
11095 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
11096 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
11097 function whenever these variables are set. This is necessary
11098 because some widget sets use timeouts internally, for example the
11099 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
11100 processed, these widgets don't behave normally. */
11103 x_activate_timeout_atimer ()
11106 if (!x_timeout_atimer_activated_flag
)
11108 EMACS_TIME interval
;
11110 EMACS_SET_SECS_USECS (interval
, 0, 100000);
11111 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
11112 x_timeout_atimer_activated_flag
= 1;
11117 #endif /* USE_X_TOOLKIT */
11120 /* Set up use of X before we make the first connection. */
11122 extern frame_parm_handler x_frame_parm_handlers
[];
11124 static struct redisplay_interface x_redisplay_interface
=
11126 x_frame_parm_handlers
,
11130 x_clear_end_of_line
,
11132 x_after_update_window_line
,
11133 x_update_window_begin
,
11134 x_update_window_end
,
11140 0, /* flush_display_optional */
11142 x_clear_window_mouse_face
,
11143 x_get_glyph_overhangs
,
11144 x_fix_overlapping_area
,
11145 x_draw_fringe_bitmap
,
11146 0, /* define_fringe_bitmap */
11147 0, /* destroy_fringe_bitmap */
11150 x_compute_glyph_string_overhangs
,
11151 x_draw_glyph_string
,
11152 x_define_frame_cursor
,
11153 x_clear_frame_area
,
11154 x_draw_window_cursor
,
11155 x_draw_vertical_window_border
,
11156 x_shift_glyphs_for_insert
11162 rif
= &x_redisplay_interface
;
11164 clear_frame_hook
= x_clear_frame
;
11165 ins_del_lines_hook
= x_ins_del_lines
;
11166 delete_glyphs_hook
= x_delete_glyphs
;
11167 ring_bell_hook
= XTring_bell
;
11168 reset_terminal_modes_hook
= XTreset_terminal_modes
;
11169 set_terminal_modes_hook
= XTset_terminal_modes
;
11170 update_begin_hook
= x_update_begin
;
11171 update_end_hook
= x_update_end
;
11172 set_terminal_window_hook
= XTset_terminal_window
;
11173 read_socket_hook
= XTread_socket
;
11174 frame_up_to_date_hook
= XTframe_up_to_date
;
11175 mouse_position_hook
= XTmouse_position
;
11176 frame_rehighlight_hook
= XTframe_rehighlight
;
11177 frame_raise_lower_hook
= XTframe_raise_lower
;
11178 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
11179 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
11180 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
11181 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
11182 fullscreen_hook
= XTfullscreen_hook
;
11184 scroll_region_ok
= 1; /* we'll scroll partial frames */
11185 char_ins_del_ok
= 1;
11186 line_ins_del_ok
= 1; /* we'll just blt 'em */
11187 fast_clear_end_of_line
= 1; /* X does this well */
11188 memory_below_frame
= 0; /* we don't remember what scrolls
11193 last_tool_bar_item
= -1;
11194 any_help_event_p
= 0;
11195 ignore_next_mouse_click_timeout
= 0;
11197 x_session_initialized
= 0;
11201 current_count
= -1;
11204 /* Try to use interrupt input; if we can't, then start polling. */
11205 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
11207 #ifdef USE_X_TOOLKIT
11208 XtToolkitInitialize ();
11210 Xt_app_con
= XtCreateApplicationContext ();
11212 /* Register a converter from strings to pixels, which uses
11213 Emacs' color allocation infrastructure. */
11214 XtAppSetTypeConverter (Xt_app_con
,
11215 XtRString
, XtRPixel
, cvt_string_to_pixel
,
11216 cvt_string_to_pixel_args
,
11217 XtNumber (cvt_string_to_pixel_args
),
11218 XtCacheByDisplay
, cvt_pixel_dtor
);
11220 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
11223 #ifdef USE_TOOLKIT_SCROLL_BARS
11225 xaw3d_arrow_scroll
= False
;
11226 xaw3d_pick_top
= True
;
11230 /* Note that there is no real way portable across R3/R4 to get the
11231 original error handler. */
11232 XSetErrorHandler (x_error_handler
);
11233 XSetIOErrorHandler (x_io_error_quitter
);
11235 /* Disable Window Change signals; they are handled by X events. */
11237 signal (SIGWINCH
, SIG_DFL
);
11238 #endif /* SIGWINCH */
11240 signal (SIGPIPE
, x_connection_signal
);
11247 x_error_message
= NULL
;
11249 staticpro (&x_display_name_list
);
11250 x_display_name_list
= Qnil
;
11252 staticpro (&last_mouse_scroll_bar
);
11253 last_mouse_scroll_bar
= Qnil
;
11255 staticpro (&Qvendor_specific_keysyms
);
11256 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
11258 staticpro (&Qutf_8
);
11259 Qutf_8
= intern ("utf-8");
11260 staticpro (&Qlatin_1
);
11261 Qlatin_1
= intern ("latin-1");
11263 staticpro (&last_mouse_press_frame
);
11264 last_mouse_press_frame
= Qnil
;
11266 DEFVAR_BOOL ("x-use-underline-position-properties",
11267 &x_use_underline_position_properties
,
11268 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11269 A value of nil means ignore them. If you encounter fonts with bogus
11270 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11271 to 4.1, set this to nil. */);
11272 x_use_underline_position_properties
= 1;
11274 DEFVAR_BOOL ("x-underline-at-descent-line",
11275 &x_underline_at_descent_line
,
11276 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
11277 A value of nil means to draw the underline according to the value of the
11278 variable `x-use-underline-position-properties', which is usually at the
11279 baseline level. The default value is nil. */);
11280 x_underline_at_descent_line
= 0;
11282 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
11283 &x_mouse_click_focus_ignore_position
,
11284 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
11285 This variable is only used when the window manager requires that you
11286 click on a frame to select it (give it focus). In that case, a value
11287 of nil, means that the selected window and cursor position changes to
11288 reflect the mouse click position, while a non-nil value means that the
11289 selected window or cursor position is preserved. */);
11290 x_mouse_click_focus_ignore_position
= 0;
11292 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11293 doc
: /* What X toolkit scroll bars Emacs uses.
11294 A value of nil means Emacs doesn't use X toolkit scroll bars.
11295 Otherwise, value is a symbol describing the X toolkit. */);
11296 #ifdef USE_TOOLKIT_SCROLL_BARS
11298 Vx_toolkit_scroll_bars
= intern ("motif");
11299 #elif defined HAVE_XAW3D
11300 Vx_toolkit_scroll_bars
= intern ("xaw3d");
11302 Vx_toolkit_scroll_bars
= intern ("gtk");
11304 Vx_toolkit_scroll_bars
= intern ("xaw");
11307 Vx_toolkit_scroll_bars
= Qnil
;
11310 staticpro (&last_mouse_motion_frame
);
11311 last_mouse_motion_frame
= Qnil
;
11313 Qmodifier_value
= intern ("modifier-value");
11314 Qalt
= intern ("alt");
11315 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
11316 Qhyper
= intern ("hyper");
11317 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
11318 Qmeta
= intern ("meta");
11319 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
11320 Qsuper
= intern ("super");
11321 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
11323 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
11324 doc
: /* Which keys Emacs uses for the alt modifier.
11325 This should be one of the symbols `alt', `hyper', `meta', `super'.
11326 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
11327 is nil, which is the same as `alt'. */);
11328 Vx_alt_keysym
= Qnil
;
11330 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
11331 doc
: /* Which keys Emacs uses for the hyper modifier.
11332 This should be one of the symbols `alt', `hyper', `meta', `super'.
11333 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
11334 default is nil, which is the same as `hyper'. */);
11335 Vx_hyper_keysym
= Qnil
;
11337 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
11338 doc
: /* Which keys Emacs uses for the meta modifier.
11339 This should be one of the symbols `alt', `hyper', `meta', `super'.
11340 For example, `meta' means use the Meta_L and Meta_R keysyms. The
11341 default is nil, which is the same as `meta'. */);
11342 Vx_meta_keysym
= Qnil
;
11344 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
11345 doc
: /* Which keys Emacs uses for the super modifier.
11346 This should be one of the symbols `alt', `hyper', `meta', `super'.
11347 For example, `super' means use the Super_L and Super_R keysyms. The
11348 default is nil, which is the same as `super'. */);
11349 Vx_super_keysym
= Qnil
;
11351 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
11352 doc
: /* Hash table of character codes indexed by X keysym codes. */);
11353 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
11354 make_float (DEFAULT_REHASH_SIZE
),
11355 make_float (DEFAULT_REHASH_THRESHOLD
),
11359 #endif /* HAVE_X_WINDOWS */
11361 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
11362 (do not change this comment) */