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) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
71 #include "character.h"
75 #include "dispextern.h"
77 #include "termhooks.h"
85 #include "intervals.h"
91 #include <X11/Shell.h>
94 #ifdef HAVE_SYS_TIME_H
105 #ifdef USE_FONT_BACKEND
107 #endif /* USE_FONT_BACKEND */
110 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
111 extern void xlwmenu_redisplay
P_ ((Widget
));
114 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
116 extern void free_frame_menubar
P_ ((struct frame
*));
117 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
122 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
124 extern void _XEditResCheckMessages ();
125 #endif /* not NO_EDITRES */
127 /* Include toolkit specific headers for the scroll bar widget. */
129 #ifdef USE_TOOLKIT_SCROLL_BARS
130 #if defined USE_MOTIF
131 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
132 #include <Xm/ScrollBar.h>
133 #else /* !USE_MOTIF i.e. use Xaw */
136 #include <X11/Xaw3d/Simple.h>
137 #include <X11/Xaw3d/Scrollbar.h>
138 #include <X11/Xaw3d/ThreeD.h>
139 #else /* !HAVE_XAW3D */
140 #include <X11/Xaw/Simple.h>
141 #include <X11/Xaw/Scrollbar.h>
142 #endif /* !HAVE_XAW3D */
144 #define XtNpickTop "pickTop"
145 #endif /* !XtNpickTop */
146 #endif /* !USE_MOTIF */
147 #endif /* USE_TOOLKIT_SCROLL_BARS */
149 #endif /* USE_X_TOOLKIT */
151 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
152 #define x_any_window_to_frame x_window_to_frame
153 #define x_top_window_to_frame x_window_to_frame
158 #ifndef XtNinitialState
159 #define XtNinitialState "initialState"
163 /* Default to using XIM if available. */
167 int use_xim
= 0; /* configure --without-xim */
172 /* Non-nil means Emacs uses toolkit scroll bars. */
174 Lisp_Object Vx_toolkit_scroll_bars
;
176 /* Non-zero means that a HELP_EVENT has been generated since Emacs
179 static int any_help_event_p
;
181 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
182 static Lisp_Object last_window
;
184 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
186 int x_use_underline_position_properties
;
188 /* Non-zero means to draw the underline at the same place as the descent line. */
190 int x_underline_at_descent_line
;
192 /* This is a chain of structures for all the X displays currently in
195 struct x_display_info
*x_display_list
;
197 /* This is a list of cons cells, each of the form (NAME
198 . FONT-LIST-CACHE), one for each element of x_display_list and in
199 the same order. NAME is the name of the frame. FONT-LIST-CACHE
200 records previous values returned by x-list-fonts. */
202 Lisp_Object x_display_name_list
;
204 /* Frame being updated by update_frame. This is declared in term.c.
205 This is set by update_begin and looked at by all the XT functions.
206 It is zero while not inside an update. In that case, the XT
207 functions assume that `selected_frame' is the frame to apply to. */
209 extern struct frame
*updating_frame
;
211 /* This is a frame waiting to be auto-raised, within XTread_socket. */
213 struct frame
*pending_autoraise_frame
;
216 /* The application context for Xt use. */
217 XtAppContext Xt_app_con
;
218 static String Xt_default_resources
[] = {0};
219 #endif /* USE_X_TOOLKIT */
221 /* Non-zero means user is interacting with a toolkit scroll bar. */
223 static int toolkit_scroll_bar_interaction
;
225 /* Non-zero means to not move point as a result of clicking on a
226 frame to focus it (when focus-follows-mouse is nil). */
228 int x_mouse_click_focus_ignore_position
;
230 /* Non-zero timeout value means ignore next mouse click if it arrives
231 before that timeout elapses (i.e. as part of the same sequence of
232 events resulting from clicking on a frame to select it). */
234 static unsigned long ignore_next_mouse_click_timeout
;
238 Formerly, we used PointerMotionHintMask (in standard_event_mask)
239 so that we would have to call XQueryPointer after each MotionNotify
240 event to ask for another such event. However, this made mouse tracking
241 slow, and there was a bug that made it eventually stop.
243 Simply asking for MotionNotify all the time seems to work better.
245 In order to avoid asking for motion events and then throwing most
246 of them away or busy-polling the server for mouse positions, we ask
247 the server for pointer motion hints. This means that we get only
248 one event per group of mouse movements. "Groups" are delimited by
249 other kinds of events (focus changes and button clicks, for
250 example), or by XQueryPointer calls; when one of these happens, we
251 get another MotionNotify event the next time the mouse moves. This
252 is at least as efficient as getting motion events when mouse
253 tracking is on, and I suspect only negligibly worse when tracking
256 /* Where the mouse was last time we reported a mouse event. */
258 static XRectangle last_mouse_glyph
;
259 static FRAME_PTR last_mouse_glyph_frame
;
260 static Lisp_Object last_mouse_press_frame
;
262 /* The scroll bar in which the last X motion event occurred.
264 If the last X motion event occurred in a scroll bar, we set this so
265 XTmouse_position can know whether to report a scroll bar motion or
268 If the last X motion event didn't occur in a scroll bar, we set
269 this to Qnil, to tell XTmouse_position to return an ordinary motion
272 static Lisp_Object last_mouse_scroll_bar
;
274 /* This is a hack. We would really prefer that XTmouse_position would
275 return the time associated with the position it returns, but there
276 doesn't seem to be any way to wrest the time-stamp from the server
277 along with the position query. So, we just keep track of the time
278 of the last movement we received, and return that in hopes that
279 it's somewhat accurate. */
281 static Time last_mouse_movement_time
;
283 /* Time for last user interaction as returned in X events. */
285 static Time last_user_time
;
287 /* Incremented by XTread_socket whenever it really tries to read
291 static int volatile input_signal_count
;
293 static int input_signal_count
;
296 /* Used locally within XTread_socket. */
298 static int x_noop_count
;
300 /* Initial values of argv and argc. */
302 extern char **initial_argv
;
303 extern int initial_argc
;
305 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
307 /* Tells if a window manager is present or not. */
309 extern Lisp_Object Vx_no_window_manager
;
311 extern Lisp_Object Qeql
;
315 /* A mask of extra modifier bits to put into every keyboard char. */
317 extern EMACS_INT extra_keyboard_modifiers
;
319 /* The keysyms to use for the various modifiers. */
321 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
322 Lisp_Object Vx_keysym_table
;
323 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
325 static Lisp_Object Qvendor_specific_keysyms
;
326 static Lisp_Object Qlatin_1
;
328 /* Used in x_flush. */
330 extern Lisp_Object Vinhibit_redisplay
;
332 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
333 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
335 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
336 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
337 static const XColor
*x_color_cells
P_ ((Display
*, int *));
338 static void x_update_window_end
P_ ((struct window
*, int, int));
340 static int x_io_error_quitter
P_ ((Display
*));
341 static struct terminal
*x_create_terminal
P_ ((struct x_display_info
*));
342 void x_delete_terminal
P_ ((struct terminal
*));
343 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
344 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
345 static void x_update_end
P_ ((struct frame
*));
346 static void XTframe_up_to_date
P_ ((struct frame
*));
347 static void XTset_terminal_modes
P_ ((struct terminal
*));
348 static void XTreset_terminal_modes
P_ ((struct terminal
*));
349 static void x_clear_frame
P_ ((struct frame
*));
350 static void frame_highlight
P_ ((struct frame
*));
351 static void frame_unhighlight
P_ ((struct frame
*));
352 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
353 static void x_focus_changed
P_ ((int, int, struct x_display_info
*,
354 struct frame
*, struct input_event
*));
355 static void x_detect_focus_change
P_ ((struct x_display_info
*,
356 XEvent
*, struct input_event
*));
357 static void XTframe_rehighlight
P_ ((struct frame
*));
358 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
359 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
360 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
361 enum text_cursor_kinds
));
363 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
364 static void x_flush
P_ ((struct frame
*f
));
365 static void x_update_begin
P_ ((struct frame
*));
366 static void x_update_window_begin
P_ ((struct window
*));
367 static void x_after_update_window_line
P_ ((struct glyph_row
*));
368 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Display
*, Window
));
369 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
370 enum scroll_bar_part
*,
371 Lisp_Object
*, Lisp_Object
*,
373 static void x_check_fullscreen
P_ ((struct frame
*));
374 static void x_check_expected_move
P_ ((struct frame
*, int, int));
375 static void x_sync_with_move
P_ ((struct frame
*, int, int, int));
376 static int handle_one_xevent
P_ ((struct x_display_info
*, XEvent
*,
377 int *, struct input_event
*));
378 /* Don't declare this NO_RETURN because we want no
379 interference with debugging failing X calls. */
380 static SIGTYPE x_connection_closed
P_ ((Display
*, char *));
383 /* Flush display of frame F, or of all frames if F is null. */
389 /* Don't call XFlush when it is not safe to redisplay; the X
390 connection may be broken. */
391 if (!NILP (Vinhibit_redisplay
))
397 Lisp_Object rest
, frame
;
398 FOR_EACH_FRAME (rest
, frame
)
399 if (FRAME_X_P (XFRAME (frame
)))
400 x_flush (XFRAME (frame
));
402 else if (FRAME_X_P (f
))
403 XFlush (FRAME_X_DISPLAY (f
));
408 /* Remove calls to XFlush by defining XFlush to an empty replacement.
409 Calls to XFlush should be unnecessary because the X output buffer
410 is flushed automatically as needed by calls to XPending,
411 XNextEvent, or XWindowEvent according to the XFlush man page.
412 XTread_socket calls XPending. Removing XFlush improves
415 #define XFlush(DISPLAY) (void) 0
418 /***********************************************************************
420 ***********************************************************************/
424 /* This is a function useful for recording debugging information about
425 the sequence of occurrences in this file. */
433 struct record event_record
[100];
435 int event_record_index
;
437 record_event (locus
, type
)
441 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
442 event_record_index
= 0;
444 event_record
[event_record_index
].locus
= locus
;
445 event_record
[event_record_index
].type
= type
;
446 event_record_index
++;
453 /* Return the struct x_display_info corresponding to DPY. */
455 struct x_display_info
*
456 x_display_info_for_display (dpy
)
459 struct x_display_info
*dpyinfo
;
461 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
462 if (dpyinfo
->display
== dpy
)
470 /***********************************************************************
471 Starting and ending an update
472 ***********************************************************************/
474 /* Start an update of frame F. This function is installed as a hook
475 for update_begin, i.e. it is called when update_begin is called.
476 This function is called prior to calls to x_update_window_begin for
477 each window being updated. Currently, there is nothing to do here
478 because all interesting stuff is done on a window basis. */
488 /* Start update of window W. Set the global variable updated_window
489 to the window being updated and set output_cursor to the cursor
493 x_update_window_begin (w
)
496 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
497 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
500 set_output_cursor (&w
->cursor
);
504 if (f
== display_info
->mouse_face_mouse_frame
)
506 /* Don't do highlighting for mouse motion during the update. */
507 display_info
->mouse_face_defer
= 1;
509 /* If F needs to be redrawn, simply forget about any prior mouse
511 if (FRAME_GARBAGED_P (f
))
512 display_info
->mouse_face_window
= Qnil
;
514 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
515 their mouse_face_p flag set, which means that they are always
516 unequal to rows in a desired matrix which never have that
517 flag set. So, rows containing mouse-face glyphs are never
518 scrolled, and we don't have to switch the mouse highlight off
519 here to prevent it from being scrolled. */
521 /* Can we tell that this update does not affect the window
522 where the mouse highlight is? If so, no need to turn off.
523 Likewise, don't do anything if the frame is garbaged;
524 in that case, the frame's current matrix that we would use
525 is all wrong, and we will redisplay that line anyway. */
526 if (!NILP (display_info
->mouse_face_window
)
527 && w
== XWINDOW (display_info
->mouse_face_window
))
531 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
532 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
535 if (i
< w
->desired_matrix
->nrows
)
536 clear_mouse_face (display_info
);
545 /* Draw a vertical window border from (x,y0) to (x,y1) */
548 x_draw_vertical_window_border (w
, x
, y0
, y1
)
552 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
555 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
557 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
560 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
561 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
564 /* End update of window W (which is equal to updated_window).
566 Draw vertical borders between horizontally adjacent windows, and
567 display W's cursor if CURSOR_ON_P is non-zero.
569 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
570 glyphs in mouse-face were overwritten. In that case we have to
571 make sure that the mouse-highlight is properly redrawn.
573 W may be a menu bar pseudo-window in case we don't have X toolkit
574 support. Such windows don't have a cursor, so don't display it
578 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
580 int cursor_on_p
, mouse_face_overwritten_p
;
582 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
584 if (!w
->pseudo_window_p
)
589 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
591 output_cursor
.x
, output_cursor
.y
);
593 if (draw_window_fringes (w
, 1))
594 x_draw_vertical_border (w
);
599 /* If a row with mouse-face was overwritten, arrange for
600 XTframe_up_to_date to redisplay the mouse highlight. */
601 if (mouse_face_overwritten_p
)
603 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
604 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
605 dpyinfo
->mouse_face_window
= Qnil
;
608 updated_window
= NULL
;
612 /* End update of frame F. This function is installed as a hook in
619 /* Mouse highlight may be displayed again. */
620 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
624 XFlush (FRAME_X_DISPLAY (f
));
630 /* This function is called from various places in xdisp.c whenever a
631 complete update has been performed. The global variable
632 updated_window is not available here. */
635 XTframe_up_to_date (f
)
640 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
642 if (dpyinfo
->mouse_face_deferred_gc
643 || f
== dpyinfo
->mouse_face_mouse_frame
)
646 if (dpyinfo
->mouse_face_mouse_frame
)
647 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
648 dpyinfo
->mouse_face_mouse_x
,
649 dpyinfo
->mouse_face_mouse_y
);
650 dpyinfo
->mouse_face_deferred_gc
= 0;
657 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
658 arrow bitmaps, or clear the fringes if no bitmaps are required
659 before DESIRED_ROW is made current. The window being updated is
660 found in updated_window. This function It is called from
661 update_window_line only if it is known that there are differences
662 between bitmaps to be drawn between current row and DESIRED_ROW. */
665 x_after_update_window_line (desired_row
)
666 struct glyph_row
*desired_row
;
668 struct window
*w
= updated_window
;
674 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
675 desired_row
->redraw_fringe_bitmaps_p
= 1;
677 /* When a window has disappeared, make sure that no rest of
678 full-width rows stays visible in the internal border. Could
679 check here if updated_window is the leftmost/rightmost window,
680 but I guess it's not worth doing since vertically split windows
681 are almost never used, internal border is rarely set, and the
682 overhead is very small. */
683 if (windows_or_buffers_changed
684 && desired_row
->full_width_p
685 && (f
= XFRAME (w
->frame
),
686 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
688 && (height
= desired_row
->visible_height
,
691 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
693 /* Internal border is drawn below the tool bar. */
694 if (WINDOWP (f
->tool_bar_window
)
695 && w
== XWINDOW (f
->tool_bar_window
))
699 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
700 0, y
, width
, height
, False
);
701 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
702 FRAME_PIXEL_WIDTH (f
) - width
,
703 y
, width
, height
, False
);
709 x_draw_fringe_bitmap (w
, row
, p
)
711 struct glyph_row
*row
;
712 struct draw_fringe_bitmap_params
*p
;
714 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
715 Display
*display
= FRAME_X_DISPLAY (f
);
716 Window window
= FRAME_X_WINDOW (f
);
717 GC gc
= f
->output_data
.x
->normal_gc
;
718 struct face
*face
= p
->face
;
721 /* Must clip because of partially visible lines. */
722 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
725 /* Adjust position of "bottom aligned" bitmap on partially
728 int oldVH
= row
->visible_height
;
729 row
->visible_height
= p
->h
;
730 row
->y
-= rowY
- p
->y
;
731 x_clip_to_row (w
, row
, -1, gc
);
733 row
->visible_height
= oldVH
;
736 x_clip_to_row (w
, row
, -1, gc
);
740 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
742 /* In case the same realized face is used for fringes and
743 for something displayed in the text (e.g. face `region' on
744 mono-displays, the fill style may have been changed to
745 FillSolid in x_draw_glyph_string_background. */
747 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
749 XSetForeground (display
, face
->gc
, face
->background
);
751 #ifdef USE_TOOLKIT_SCROLL_BARS
752 /* If the fringe is adjacent to the left (right) scroll bar of a
753 leftmost (rightmost, respectively) window, then extend its
754 background to the gap between the fringe and the bar. */
755 if ((WINDOW_LEFTMOST_P (w
)
756 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
757 || (WINDOW_RIGHTMOST_P (w
)
758 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
760 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
764 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
765 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
766 * FRAME_COLUMN_WIDTH (f
));
770 /* Bitmap fills the fringe. */
771 if (left
+ width
== p
->x
)
772 bx
= left
+ sb_width
;
773 else if (p
->x
+ p
->wd
== left
)
777 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
779 nx
= width
- sb_width
;
780 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
782 ny
= row
->visible_height
;
787 if (left
+ width
== bx
)
789 bx
= left
+ sb_width
;
790 nx
+= width
- sb_width
;
792 else if (bx
+ nx
== left
)
793 nx
+= width
- sb_width
;
798 if (bx
>= 0 && nx
> 0)
799 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
802 XSetForeground (display
, face
->gc
, face
->foreground
);
808 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
809 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
813 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
815 bits
= (unsigned char *)p
->bits
+ p
->dh
;
817 /* Draw the bitmap. I believe these small pixmaps can be cached
819 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
821 ? (p
->overlay_p
? face
->background
822 : f
->output_data
.x
->cursor_pixel
)
824 face
->background
, depth
);
828 clipmask
= XCreatePixmapFromBitmapData (display
,
829 FRAME_X_DISPLAY_INFO (f
)->root_window
,
832 gcv
.clip_mask
= clipmask
;
833 gcv
.clip_x_origin
= p
->x
;
834 gcv
.clip_y_origin
= p
->y
;
835 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
838 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
839 p
->wd
, p
->h
, p
->x
, p
->y
);
840 XFreePixmap (display
, pixmap
);
844 gcv
.clip_mask
= (Pixmap
) 0;
845 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
846 XFreePixmap (display
, clipmask
);
850 XSetClipMask (display
, gc
, None
);
855 /* This is called when starting Emacs and when restarting after
856 suspend. When starting Emacs, no X window is mapped. And nothing
857 must be done to Emacs's own window if it is suspended (though that
861 XTset_terminal_modes (struct terminal
*terminal
)
865 /* This is called when exiting or suspending Emacs. Exiting will make
866 the X-windows go away, and suspending requires no action. */
869 XTreset_terminal_modes (struct terminal
*terminal
)
875 /***********************************************************************
877 ***********************************************************************/
879 /* Function prototypes of this page. */
881 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*,
882 struct charset
*, int *));
885 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
886 is not contained in the font. */
889 x_per_char_metric (font
, char2b
, font_type
)
892 int font_type
; /* unused on X */
894 /* The result metric information. */
895 XCharStruct
*pcm
= NULL
;
897 xassert (font
&& char2b
);
899 if (font
->per_char
!= NULL
)
901 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
903 /* min_char_or_byte2 specifies the linear character index
904 corresponding to the first element of the per_char array,
905 max_char_or_byte2 is the index of the last character. A
906 character with non-zero CHAR2B->byte1 is not in the font.
907 A character with byte2 less than min_char_or_byte2 or
908 greater max_char_or_byte2 is not in the font. */
909 if (char2b
->byte1
== 0
910 && char2b
->byte2
>= font
->min_char_or_byte2
911 && char2b
->byte2
<= font
->max_char_or_byte2
)
912 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
916 /* If either min_byte1 or max_byte1 are nonzero, both
917 min_char_or_byte2 and max_char_or_byte2 are less than
918 256, and the 2-byte character index values corresponding
919 to the per_char array element N (counting from 0) are:
921 byte1 = N/D + min_byte1
922 byte2 = N\D + min_char_or_byte2
926 D = max_char_or_byte2 - min_char_or_byte2 + 1
928 \ = integer modulus */
929 if (char2b
->byte1
>= font
->min_byte1
930 && char2b
->byte1
<= font
->max_byte1
931 && char2b
->byte2
>= font
->min_char_or_byte2
932 && char2b
->byte2
<= font
->max_char_or_byte2
)
934 pcm
= (font
->per_char
935 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
936 * (char2b
->byte1
- font
->min_byte1
))
937 + (char2b
->byte2
- font
->min_char_or_byte2
));
943 /* If the per_char pointer is null, all glyphs between the first
944 and last character indexes inclusive have the same
945 information, as given by both min_bounds and max_bounds. */
946 if (char2b
->byte2
>= font
->min_char_or_byte2
947 && char2b
->byte2
<= font
->max_char_or_byte2
)
948 pcm
= &font
->max_bounds
;
952 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
957 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
958 the two-byte form of C. Encoding is returned in *CHAR2B. */
961 x_encode_char (c
, char2b
, font_info
, charset
, two_byte_p
)
964 struct font_info
*font_info
;
965 struct charset
*charset
;
968 XFontStruct
*font
= font_info
->font
;
970 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
971 This may be either a program in a special encoder language or a
973 if (font_info
->font_encoder
)
975 /* It's a program. */
976 struct ccl_program
*ccl
= font_info
->font_encoder
;
978 check_ccl_update (ccl
);
979 if (CHARSET_DIMENSION (charset
) == 1)
981 ccl
->reg
[0] = CHARSET_ID (charset
);
982 ccl
->reg
[1] = char2b
->byte2
;
987 ccl
->reg
[0] = CHARSET_ID (charset
);
988 ccl
->reg
[1] = char2b
->byte1
;
989 ccl
->reg
[2] = char2b
->byte2
;
992 ccl_driver (ccl
, NULL
, NULL
, 0, 0, Qnil
);
994 /* We assume that MSBs are appropriately set/reset by CCL
996 if (font
->max_byte1
== 0) /* 1-byte font */
997 STORE_XCHAR2B (char2b
, 0, ccl
->reg
[1]);
999 STORE_XCHAR2B (char2b
, ccl
->reg
[1], ccl
->reg
[2]);
1001 else if (font_info
->encoding_type
)
1003 /* Fixed encoding scheme. See fontset.h for the meaning of the
1004 encoding numbers. */
1005 unsigned char enc
= font_info
->encoding_type
;
1007 if ((enc
== 1 || enc
== 2)
1008 && CHARSET_DIMENSION (charset
) == 2)
1009 char2b
->byte1
|= 0x80;
1011 if (enc
== 1 || enc
== 3)
1012 char2b
->byte2
|= 0x80;
1016 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1018 return FONT_TYPE_UNKNOWN
;
1023 /***********************************************************************
1025 ***********************************************************************/
1029 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
1030 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
1031 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
1033 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
1034 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
1035 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
1036 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
1037 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
1038 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
1039 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
1040 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
1041 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
1042 unsigned long *, double, int));
1043 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
1044 double, int, unsigned long));
1045 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
1046 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
1047 static void x_draw_image_relief
P_ ((struct glyph_string
*));
1048 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
1049 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
1050 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
1052 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
1053 int, int, int, int, int, int,
1055 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
1056 int, int, int, XRectangle
*));
1059 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
1063 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1068 struct glyph_string
*s
;
1070 if (s
->font
== FRAME_FONT (s
->f
)
1071 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1072 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1074 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1077 /* Cursor on non-default face: must merge. */
1081 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1082 xgcv
.foreground
= s
->face
->background
;
1084 /* If the glyph would be invisible, try a different foreground. */
1085 if (xgcv
.foreground
== xgcv
.background
)
1086 xgcv
.foreground
= s
->face
->foreground
;
1087 if (xgcv
.foreground
== xgcv
.background
)
1088 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1089 if (xgcv
.foreground
== xgcv
.background
)
1090 xgcv
.foreground
= s
->face
->foreground
;
1092 /* Make sure the cursor is distinct from text in this face. */
1093 if (xgcv
.background
== s
->face
->background
1094 && xgcv
.foreground
== s
->face
->foreground
)
1096 xgcv
.background
= s
->face
->foreground
;
1097 xgcv
.foreground
= s
->face
->background
;
1100 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1101 xgcv
.font
= s
->font
->fid
;
1102 xgcv
.graphics_exposures
= False
;
1103 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1105 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1106 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1109 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1110 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1112 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1117 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1120 x_set_mouse_face_gc (s
)
1121 struct glyph_string
*s
;
1126 /* What face has to be used last for the mouse face? */
1127 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1128 face
= FACE_FROM_ID (s
->f
, face_id
);
1130 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1132 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1133 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1135 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1136 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1137 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1139 /* If font in this face is same as S->font, use it. */
1140 if (s
->font
== s
->face
->font
)
1141 s
->gc
= s
->face
->gc
;
1142 #ifdef USE_FONT_BACKEND
1143 else if (enable_font_backend
)
1144 /* No need of setting a font for s->gc. */
1145 s
->gc
= s
->face
->gc
;
1146 #endif /* USE_FONT_BACKEND */
1149 /* Otherwise construct scratch_cursor_gc with values from FACE
1154 xgcv
.background
= s
->face
->background
;
1155 xgcv
.foreground
= s
->face
->foreground
;
1156 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1157 xgcv
.font
= s
->font
->fid
;
1158 xgcv
.graphics_exposures
= False
;
1159 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1161 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1162 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1165 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1166 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1168 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1171 xassert (s
->gc
!= 0);
1175 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1176 Faces to use in the mode line have already been computed when the
1177 matrix was built, so there isn't much to do, here. */
1180 x_set_mode_line_face_gc (s
)
1181 struct glyph_string
*s
;
1183 s
->gc
= s
->face
->gc
;
1187 /* Set S->gc of glyph string S for drawing that glyph string. Set
1188 S->stippled_p to a non-zero value if the face of S has a stipple
1192 x_set_glyph_string_gc (s
)
1193 struct glyph_string
*s
;
1195 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1197 if (s
->hl
== DRAW_NORMAL_TEXT
)
1199 s
->gc
= s
->face
->gc
;
1200 s
->stippled_p
= s
->face
->stipple
!= 0;
1202 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1204 x_set_mode_line_face_gc (s
);
1205 s
->stippled_p
= s
->face
->stipple
!= 0;
1207 else if (s
->hl
== DRAW_CURSOR
)
1209 x_set_cursor_gc (s
);
1212 else if (s
->hl
== DRAW_MOUSE_FACE
)
1214 x_set_mouse_face_gc (s
);
1215 s
->stippled_p
= s
->face
->stipple
!= 0;
1217 else if (s
->hl
== DRAW_IMAGE_RAISED
1218 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1220 s
->gc
= s
->face
->gc
;
1221 s
->stippled_p
= s
->face
->stipple
!= 0;
1225 s
->gc
= s
->face
->gc
;
1226 s
->stippled_p
= s
->face
->stipple
!= 0;
1229 /* GC must have been set. */
1230 xassert (s
->gc
!= 0);
1234 /* Set clipping for output of glyph string S. S may be part of a mode
1235 line or menu if we don't have X toolkit support. */
1238 x_set_glyph_string_clipping (s
)
1239 struct glyph_string
*s
;
1241 #ifdef USE_FONT_BACKEND
1242 XRectangle
*r
= s
->clip
;
1246 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1249 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1250 #ifdef USE_FONT_BACKEND
1256 /* Set SRC's clipping for output of glyph string DST. This is called
1257 when we are drawing DST's left_overhang or right_overhang only in
1261 x_set_glyph_string_clipping_exactly (src
, dst
)
1262 struct glyph_string
*src
, *dst
;
1266 #ifdef USE_FONT_BACKEND
1267 if (enable_font_backend
)
1270 r
.width
= src
->width
;
1272 r
.height
= src
->height
;
1278 #endif /* USE_FONT_BACKEND */
1279 struct glyph_string
*clip_head
= src
->clip_head
;
1280 struct glyph_string
*clip_tail
= src
->clip_tail
;
1282 /* This foces clipping just this glyph string. */
1283 src
->clip_head
= src
->clip_tail
= src
;
1284 get_glyph_string_clip_rect (src
, &r
);
1285 src
->clip_head
= clip_head
, src
->clip_tail
= clip_tail
;
1286 #ifdef USE_FONT_BACKEND
1288 #endif /* USE_FONT_BACKEND */
1289 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1294 Compute left and right overhang of glyph string S. */
1297 x_compute_glyph_string_overhangs (s
)
1298 struct glyph_string
*s
;
1301 && s
->first_glyph
->type
== CHAR_GLYPH
)
1304 int direction
, font_ascent
, font_descent
;
1306 #ifdef USE_FONT_BACKEND
1307 if (enable_font_backend
)
1309 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1310 struct font
*font
= (struct font
*) s
->font_info
;
1311 struct font_metrics metrics
;
1314 for (i
= 0; i
< s
->nchars
; i
++)
1315 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1316 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1317 cs
.rbearing
= metrics
.rbearing
;
1318 cs
.lbearing
= metrics
.lbearing
;
1319 cs
.width
= metrics
.width
;
1322 #endif /* USE_FONT_BACKEND */
1323 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1324 &font_ascent
, &font_descent
, &cs
);
1325 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1326 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1330 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1331 s
->left_overhang
= - s
->cmp
->lbearing
;
1336 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1339 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1340 struct glyph_string
*s
;
1344 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1345 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1346 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1347 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1351 /* Draw the background of glyph_string S. If S->background_filled_p
1352 is non-zero don't draw it. FORCE_P non-zero means draw the
1353 background even if it wouldn't be drawn normally. This is used
1354 when a string preceding S draws into the background of S, or S
1355 contains the first component of a composition. */
1358 x_draw_glyph_string_background (s
, force_p
)
1359 struct glyph_string
*s
;
1362 /* Nothing to do if background has already been drawn or if it
1363 shouldn't be drawn in the first place. */
1364 if (!s
->background_filled_p
)
1366 int box_line_width
= max (s
->face
->box_line_width
, 0);
1370 /* Fill background with a stipple pattern. */
1371 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1372 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1373 s
->y
+ box_line_width
,
1374 s
->background_width
,
1375 s
->height
- 2 * box_line_width
);
1376 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1377 s
->background_filled_p
= 1;
1379 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1380 || s
->font_not_found_p
1381 || s
->extends_to_end_of_line_p
1384 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1385 s
->background_width
,
1386 s
->height
- 2 * box_line_width
);
1387 s
->background_filled_p
= 1;
1393 /* Draw the foreground of glyph string S. */
1396 x_draw_glyph_string_foreground (s
)
1397 struct glyph_string
*s
;
1401 /* If first glyph of S has a left box line, start drawing the text
1402 of S to the right of that box line. */
1403 if (s
->face
->box
!= FACE_NO_BOX
1404 && s
->first_glyph
->left_box_line_p
)
1405 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1409 /* Draw characters of S as rectangles if S's font could not be
1411 if (s
->font_not_found_p
)
1413 for (i
= 0; i
< s
->nchars
; ++i
)
1415 struct glyph
*g
= s
->first_glyph
+ i
;
1416 XDrawRectangle (s
->display
, s
->window
,
1417 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1419 x
+= g
->pixel_width
;
1422 #ifdef USE_FONT_BACKEND
1423 else if (enable_font_backend
)
1425 int boff
= s
->font_info
->baseline_offset
;
1426 struct font
*font
= (struct font
*) s
->font_info
;
1429 if (s
->font_info
->vertical_centering
)
1430 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1432 y
= s
->ybase
- boff
;
1434 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1435 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1437 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1438 if (s
->face
->overstrike
)
1439 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1441 #endif /* USE_FONT_BACKEND */
1444 char *char1b
= (char *) s
->char2b
;
1445 int boff
= s
->font_info
->baseline_offset
;
1447 if (s
->font_info
->vertical_centering
)
1448 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1450 /* If we can use 8-bit functions, condense S->char2b. */
1452 for (i
= 0; i
< s
->nchars
; ++i
)
1453 char1b
[i
] = s
->char2b
[i
].byte2
;
1455 /* Draw text with XDrawString if background has already been
1456 filled. Otherwise, use XDrawImageString. (Note that
1457 XDrawImageString is usually faster than XDrawString.) Always
1458 use XDrawImageString when drawing the cursor so that there is
1459 no chance that characters under a box cursor are invisible. */
1461 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1463 /* Draw characters with 16-bit or 8-bit functions. */
1465 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1466 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1468 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1469 s
->ybase
- boff
, char1b
, s
->nchars
);
1474 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1475 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1477 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1478 s
->ybase
- boff
, char1b
, s
->nchars
);
1481 if (s
->face
->overstrike
)
1483 /* For overstriking (to simulate bold-face), draw the
1484 characters again shifted to the right by one pixel. */
1486 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1487 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1489 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1490 s
->ybase
- boff
, char1b
, s
->nchars
);
1495 /* Draw the foreground of composite glyph string S. */
1498 x_draw_composite_glyph_string_foreground (s
)
1499 struct glyph_string
*s
;
1503 /* If first glyph of S has a left box line, start drawing the text
1504 of S to the right of that box line. */
1505 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1506 && s
->first_glyph
->left_box_line_p
)
1507 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1511 /* S is a glyph string for a composition. S->gidx is the index of
1512 the first character drawn for glyphs of this composition.
1513 S->gidx == 0 means we are drawing the very first character of
1514 this composition. */
1516 /* Draw a rectangle for the composition if the font for the very
1517 first character of the composition could not be loaded. */
1518 if (s
->font_not_found_p
)
1521 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1522 s
->width
- 1, s
->height
- 1);
1524 #ifdef USE_FONT_BACKEND
1525 else if (enable_font_backend
)
1527 struct font
*font
= (struct font
*) s
->font_info
;
1531 if (s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
1533 Lisp_Object gstring
= AREF (XHASH_TABLE (composition_hash_table
)
1535 s
->cmp
->hash_index
* 2);
1538 for (i
= from
= 0; i
< s
->nchars
; i
++)
1540 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
1541 Lisp_Object adjustment
= LGLYPH_ADJUSTMENT (g
);
1542 int xoff
, yoff
, wadjust
;
1544 if (! VECTORP (adjustment
))
1546 width
+= LGLYPH_WIDTH (g
);
1551 font
->driver
->draw (s
, from
, i
, x
, y
, 0);
1554 xoff
= XINT (AREF (adjustment
, 0));
1555 yoff
= XINT (AREF (adjustment
, 1));
1556 wadjust
= XINT (AREF (adjustment
, 2));
1558 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1564 font
->driver
->draw (s
, from
, i
, x
, y
, 0);
1568 for (i
= 0, j
= s
->gidx
; i
< s
->nchars
; i
++, j
++)
1569 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1571 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1572 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1574 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1575 if (s
->face
->overstrike
)
1576 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1580 #endif /* USE_FONT_BACKEND */
1583 for (i
= 0, j
= s
->gidx
; i
< s
->nchars
; i
++, j
++)
1586 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1587 x
+ s
->cmp
->offsets
[j
* 2],
1588 s
->ybase
- s
->cmp
->offsets
[j
* 2 + 1],
1590 if (s
->face
->overstrike
)
1591 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1592 x
+ s
->cmp
->offsets
[j
* 2] + 1,
1593 s
->ybase
- s
->cmp
->offsets
[j
* 2 + 1],
1600 #ifdef USE_X_TOOLKIT
1602 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1603 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1604 XrmValue
*, XrmValue
*, XtPointer
*));
1605 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1606 XrmValue
*, Cardinal
*));
1609 /* Return the frame on which widget WIDGET is used.. Abort if frame
1610 cannot be determined. */
1612 static struct frame
*
1613 x_frame_of_widget (widget
)
1616 struct x_display_info
*dpyinfo
;
1620 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1622 /* Find the top-level shell of the widget. Note that this function
1623 can be called when the widget is not yet realized, so XtWindow
1624 (widget) == 0. That's the reason we can't simply use
1625 x_any_window_to_frame. */
1626 while (!XtIsTopLevelShell (widget
))
1627 widget
= XtParent (widget
);
1629 /* Look for a frame with that top-level widget. Allocate the color
1630 on that frame to get the right gamma correction value. */
1631 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1632 if (FRAMEP (XCAR (tail
))
1633 && (f
= XFRAME (XCAR (tail
)),
1635 && f
->output_data
.nothing
!= 1
1636 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1637 && f
->output_data
.x
->widget
== widget
)
1644 /* Allocate the color COLOR->pixel on the screen and display of
1645 widget WIDGET in colormap CMAP. If an exact match cannot be
1646 allocated, try the nearest color available. Value is non-zero
1647 if successful. This is called from lwlib. */
1650 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1655 struct frame
*f
= x_frame_of_widget (widget
);
1656 return x_alloc_nearest_color (f
, cmap
, color
);
1660 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1661 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1662 If this produces the same color as PIXEL, try a color where all RGB
1663 values have DELTA added. Return the allocated color in *PIXEL.
1664 DISPLAY is the X display, CMAP is the colormap to operate on.
1665 Value is non-zero if successful. */
1668 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1672 unsigned long *pixel
;
1676 struct frame
*f
= x_frame_of_widget (widget
);
1677 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1681 /* Structure specifying which arguments should be passed by Xt to
1682 cvt_string_to_pixel. We want the widget's screen and colormap. */
1684 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1686 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1688 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1693 /* The address of this variable is returned by
1694 cvt_string_to_pixel. */
1696 static Pixel cvt_string_to_pixel_value
;
1699 /* Convert a color name to a pixel color.
1701 DPY is the display we are working on.
1703 ARGS is an array of *NARGS XrmValue structures holding additional
1704 information about the widget for which the conversion takes place.
1705 The contents of this array are determined by the specification
1706 in cvt_string_to_pixel_args.
1708 FROM is a pointer to an XrmValue which points to the color name to
1709 convert. TO is an XrmValue in which to return the pixel color.
1711 CLOSURE_RET is a pointer to user-data, in which we record if
1712 we allocated the color or not.
1714 Value is True if successful, False otherwise. */
1717 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1721 XrmValue
*from
, *to
;
1722 XtPointer
*closure_ret
;
1732 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1733 "wrongParameters", "cvt_string_to_pixel",
1735 "Screen and colormap args required", NULL
, NULL
);
1739 screen
= *(Screen
**) args
[0].addr
;
1740 cmap
= *(Colormap
*) args
[1].addr
;
1741 color_name
= (String
) from
->addr
;
1743 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1745 *closure_ret
= (XtPointer
) False
;
1746 pixel
= WhitePixelOfScreen (screen
);
1748 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1750 *closure_ret
= (XtPointer
) False
;
1751 pixel
= BlackPixelOfScreen (screen
);
1753 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1754 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1756 pixel
= color
.pixel
;
1757 *closure_ret
= (XtPointer
) True
;
1762 Cardinal nparams
= 1;
1764 params
[0] = color_name
;
1765 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1766 "badValue", "cvt_string_to_pixel",
1767 "XtToolkitError", "Invalid color `%s'",
1772 if (to
->addr
!= NULL
)
1774 if (to
->size
< sizeof (Pixel
))
1776 to
->size
= sizeof (Pixel
);
1780 *(Pixel
*) to
->addr
= pixel
;
1784 cvt_string_to_pixel_value
= pixel
;
1785 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1788 to
->size
= sizeof (Pixel
);
1793 /* Free a pixel color which was previously allocated via
1794 cvt_string_to_pixel. This is registered as the destructor
1795 for this type of resource via XtSetTypeConverter.
1797 APP is the application context in which we work.
1799 TO is a pointer to an XrmValue holding the color to free.
1800 CLOSURE is the value we stored in CLOSURE_RET for this color
1801 in cvt_string_to_pixel.
1803 ARGS and NARGS are like for cvt_string_to_pixel. */
1806 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1815 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1817 "Screen and colormap arguments required",
1820 else if (closure
!= NULL
)
1822 /* We did allocate the pixel, so free it. */
1823 Screen
*screen
= *(Screen
**) args
[0].addr
;
1824 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1825 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1826 (Pixel
*) to
->addr
, 1);
1831 #endif /* USE_X_TOOLKIT */
1834 /* Value is an array of XColor structures for the contents of the
1835 color map of display DPY. Set *NCELLS to the size of the array.
1836 Note that this probably shouldn't be called for large color maps,
1837 say a 24-bit TrueColor map. */
1839 static const XColor
*
1840 x_color_cells (dpy
, ncells
)
1844 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1846 if (dpyinfo
->color_cells
== NULL
)
1848 Screen
*screen
= dpyinfo
->screen
;
1851 dpyinfo
->ncolor_cells
1852 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1853 dpyinfo
->color_cells
1854 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1855 * sizeof *dpyinfo
->color_cells
);
1857 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1858 dpyinfo
->color_cells
[i
].pixel
= i
;
1860 XQueryColors (dpy
, dpyinfo
->cmap
,
1861 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1864 *ncells
= dpyinfo
->ncolor_cells
;
1865 return dpyinfo
->color_cells
;
1869 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1870 colors in COLORS. Use cached information, if available. */
1873 x_query_colors (f
, colors
, ncolors
)
1878 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1880 if (dpyinfo
->color_cells
)
1883 for (i
= 0; i
< ncolors
; ++i
)
1885 unsigned long pixel
= colors
[i
].pixel
;
1886 xassert (pixel
< dpyinfo
->ncolor_cells
);
1887 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1888 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1892 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1896 /* On frame F, translate pixel color to RGB values for the color in
1897 COLOR. Use cached information, if available. */
1900 x_query_color (f
, color
)
1904 x_query_colors (f
, color
, 1);
1908 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1909 exact match can't be allocated, try the nearest color available.
1910 Value is non-zero if successful. Set *COLOR to the color
1914 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1921 rc
= XAllocColor (dpy
, cmap
, color
);
1924 /* If we got to this point, the colormap is full, so we're going
1925 to try to get the next closest color. The algorithm used is
1926 a least-squares matching, which is what X uses for closest
1927 color matching with StaticColor visuals. */
1929 unsigned long nearest_delta
= ~0;
1931 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1933 for (nearest
= i
= 0; i
< ncells
; ++i
)
1935 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1936 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1937 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1938 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1940 if (delta
< nearest_delta
)
1943 nearest_delta
= delta
;
1947 color
->red
= cells
[nearest
].red
;
1948 color
->green
= cells
[nearest
].green
;
1949 color
->blue
= cells
[nearest
].blue
;
1950 rc
= XAllocColor (dpy
, cmap
, color
);
1954 /* If allocation succeeded, and the allocated pixel color is not
1955 equal to a cached pixel color recorded earlier, there was a
1956 change in the colormap, so clear the color cache. */
1957 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1958 XColor
*cached_color
;
1960 if (dpyinfo
->color_cells
1961 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1962 (cached_color
->red
!= color
->red
1963 || cached_color
->blue
!= color
->blue
1964 || cached_color
->green
!= color
->green
)))
1966 xfree (dpyinfo
->color_cells
);
1967 dpyinfo
->color_cells
= NULL
;
1968 dpyinfo
->ncolor_cells
= 0;
1972 #ifdef DEBUG_X_COLORS
1974 register_color (color
->pixel
);
1975 #endif /* DEBUG_X_COLORS */
1981 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1982 exact match can't be allocated, try the nearest color available.
1983 Value is non-zero if successful. Set *COLOR to the color
1987 x_alloc_nearest_color (f
, cmap
, color
)
1992 gamma_correct (f
, color
);
1993 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1997 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1998 It's necessary to do this instead of just using PIXEL directly to
1999 get color reference counts right. */
2002 x_copy_color (f
, pixel
)
2004 unsigned long pixel
;
2008 color
.pixel
= pixel
;
2010 x_query_color (f
, &color
);
2011 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2013 #ifdef DEBUG_X_COLORS
2014 register_color (pixel
);
2020 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
2021 It's necessary to do this instead of just using PIXEL directly to
2022 get color reference counts right. */
2025 x_copy_dpy_color (dpy
, cmap
, pixel
)
2028 unsigned long pixel
;
2032 color
.pixel
= pixel
;
2034 XQueryColor (dpy
, cmap
, &color
);
2035 XAllocColor (dpy
, cmap
, &color
);
2037 #ifdef DEBUG_X_COLORS
2038 register_color (pixel
);
2044 /* Brightness beyond which a color won't have its highlight brightness
2047 Nominally, highlight colors for `3d' faces are calculated by
2048 brightening an object's color by a constant scale factor, but this
2049 doesn't yield good results for dark colors, so for colors who's
2050 brightness is less than this value (on a scale of 0-65535) have an
2051 use an additional additive factor.
2053 The value here is set so that the default menu-bar/mode-line color
2054 (grey75) will not have its highlights changed at all. */
2055 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
2058 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
2059 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2060 If this produces the same color as PIXEL, try a color where all RGB
2061 values have DELTA added. Return the allocated color in *PIXEL.
2062 DISPLAY is the X display, CMAP is the colormap to operate on.
2063 Value is non-zero if successful. */
2066 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
2070 unsigned long *pixel
;
2078 /* Get RGB color values. */
2079 color
.pixel
= *pixel
;
2080 x_query_color (f
, &color
);
2082 /* Change RGB values by specified FACTOR. Avoid overflow! */
2083 xassert (factor
>= 0);
2084 new.red
= min (0xffff, factor
* color
.red
);
2085 new.green
= min (0xffff, factor
* color
.green
);
2086 new.blue
= min (0xffff, factor
* color
.blue
);
2088 /* Calculate brightness of COLOR. */
2089 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
2091 /* We only boost colors that are darker than
2092 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2093 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2094 /* Make an additive adjustment to NEW, because it's dark enough so
2095 that scaling by FACTOR alone isn't enough. */
2097 /* How far below the limit this color is (0 - 1, 1 being darker). */
2098 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2099 /* The additive adjustment. */
2100 int min_delta
= delta
* dimness
* factor
/ 2;
2104 new.red
= max (0, new.red
- min_delta
);
2105 new.green
= max (0, new.green
- min_delta
);
2106 new.blue
= max (0, new.blue
- min_delta
);
2110 new.red
= min (0xffff, min_delta
+ new.red
);
2111 new.green
= min (0xffff, min_delta
+ new.green
);
2112 new.blue
= min (0xffff, min_delta
+ new.blue
);
2116 /* Try to allocate the color. */
2117 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2120 if (new.pixel
== *pixel
)
2122 /* If we end up with the same color as before, try adding
2123 delta to the RGB values. */
2124 x_free_colors (f
, &new.pixel
, 1);
2126 new.red
= min (0xffff, delta
+ color
.red
);
2127 new.green
= min (0xffff, delta
+ color
.green
);
2128 new.blue
= min (0xffff, delta
+ color
.blue
);
2129 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2140 /* Set up the foreground color for drawing relief lines of glyph
2141 string S. RELIEF is a pointer to a struct relief containing the GC
2142 with which lines will be drawn. Use a color that is FACTOR or
2143 DELTA lighter or darker than the relief's background which is found
2144 in S->f->output_data.x->relief_background. If such a color cannot
2145 be allocated, use DEFAULT_PIXEL, instead. */
2148 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
2150 struct relief
*relief
;
2153 unsigned long default_pixel
;
2156 struct x_output
*di
= f
->output_data
.x
;
2157 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
2158 unsigned long pixel
;
2159 unsigned long background
= di
->relief_background
;
2160 Colormap cmap
= FRAME_X_COLORMAP (f
);
2161 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2162 Display
*dpy
= FRAME_X_DISPLAY (f
);
2164 xgcv
.graphics_exposures
= False
;
2165 xgcv
.line_width
= 1;
2167 /* Free previously allocated color. The color cell will be reused
2168 when it has been freed as many times as it was allocated, so this
2169 doesn't affect faces using the same colors. */
2171 && relief
->allocated_p
)
2173 x_free_colors (f
, &relief
->pixel
, 1);
2174 relief
->allocated_p
= 0;
2177 /* Allocate new color. */
2178 xgcv
.foreground
= default_pixel
;
2180 if (dpyinfo
->n_planes
!= 1
2181 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
2183 relief
->allocated_p
= 1;
2184 xgcv
.foreground
= relief
->pixel
= pixel
;
2187 if (relief
->gc
== 0)
2189 xgcv
.stipple
= dpyinfo
->gray
;
2191 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
2194 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
2198 /* Set up colors for the relief lines around glyph string S. */
2201 x_setup_relief_colors (s
)
2202 struct glyph_string
*s
;
2204 struct x_output
*di
= s
->f
->output_data
.x
;
2205 unsigned long color
;
2207 if (s
->face
->use_box_color_for_shadows_p
)
2208 color
= s
->face
->box_color
;
2209 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2211 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2212 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2217 /* Get the background color of the face. */
2218 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2219 color
= xgcv
.background
;
2222 if (di
->white_relief
.gc
== 0
2223 || color
!= di
->relief_background
)
2225 di
->relief_background
= color
;
2226 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2227 WHITE_PIX_DEFAULT (s
->f
));
2228 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2229 BLACK_PIX_DEFAULT (s
->f
));
2234 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2235 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2236 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2237 relief. LEFT_P non-zero means draw a relief on the left side of
2238 the rectangle. RIGHT_P non-zero means draw a relief on the right
2239 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2243 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2244 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2246 int left_x
, top_y
, right_x
, bottom_y
, width
;
2247 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2248 XRectangle
*clip_rect
;
2250 Display
*dpy
= FRAME_X_DISPLAY (f
);
2251 Window window
= FRAME_X_WINDOW (f
);
2256 gc
= f
->output_data
.x
->white_relief
.gc
;
2258 gc
= f
->output_data
.x
->black_relief
.gc
;
2259 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2263 for (i
= 0; i
< width
; ++i
)
2264 XDrawLine (dpy
, window
, gc
,
2265 left_x
+ i
* left_p
, top_y
+ i
,
2266 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2270 for (i
= 0; i
< width
; ++i
)
2271 XDrawLine (dpy
, window
, gc
,
2272 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2274 XSetClipMask (dpy
, gc
, None
);
2276 gc
= f
->output_data
.x
->black_relief
.gc
;
2278 gc
= f
->output_data
.x
->white_relief
.gc
;
2279 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2283 for (i
= 0; i
< width
; ++i
)
2284 XDrawLine (dpy
, window
, gc
,
2285 left_x
+ i
* left_p
, bottom_y
- i
,
2286 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2290 for (i
= 0; i
< width
; ++i
)
2291 XDrawLine (dpy
, window
, gc
,
2292 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2294 XSetClipMask (dpy
, gc
, None
);
2298 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2299 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2300 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2301 left side of the rectangle. RIGHT_P non-zero means draw a line
2302 on the right side of the rectangle. CLIP_RECT is the clipping
2303 rectangle to use when drawing. */
2306 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2307 left_p
, right_p
, clip_rect
)
2308 struct glyph_string
*s
;
2309 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2310 XRectangle
*clip_rect
;
2314 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2315 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2316 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2319 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2320 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2324 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2325 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2328 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2329 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2333 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2334 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2336 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2337 XSetClipMask (s
->display
, s
->gc
, None
);
2341 /* Draw a box around glyph string S. */
2344 x_draw_glyph_string_box (s
)
2345 struct glyph_string
*s
;
2347 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2348 int left_p
, right_p
;
2349 struct glyph
*last_glyph
;
2350 XRectangle clip_rect
;
2352 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2353 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2354 : window_box_right (s
->w
, s
->area
));
2356 /* The glyph that may have a right box line. */
2357 last_glyph
= (s
->cmp
|| s
->img
2359 : s
->first_glyph
+ s
->nchars
- 1);
2361 width
= eabs (s
->face
->box_line_width
);
2362 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2364 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2366 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2368 bottom_y
= top_y
+ s
->height
- 1;
2370 left_p
= (s
->first_glyph
->left_box_line_p
2371 || (s
->hl
== DRAW_MOUSE_FACE
2373 || s
->prev
->hl
!= s
->hl
)));
2374 right_p
= (last_glyph
->right_box_line_p
2375 || (s
->hl
== DRAW_MOUSE_FACE
2377 || s
->next
->hl
!= s
->hl
)));
2379 get_glyph_string_clip_rect (s
, &clip_rect
);
2381 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2382 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2383 left_p
, right_p
, &clip_rect
);
2386 x_setup_relief_colors (s
);
2387 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2388 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2393 /* Draw foreground of image glyph string S. */
2396 x_draw_image_foreground (s
)
2397 struct glyph_string
*s
;
2400 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2402 /* If first glyph of S has a left box line, start drawing it to the
2403 right of that line. */
2404 if (s
->face
->box
!= FACE_NO_BOX
2405 && s
->first_glyph
->left_box_line_p
2407 x
+= eabs (s
->face
->box_line_width
);
2409 /* If there is a margin around the image, adjust x- and y-position
2411 if (s
->slice
.x
== 0)
2412 x
+= s
->img
->hmargin
;
2413 if (s
->slice
.y
== 0)
2414 y
+= s
->img
->vmargin
;
2420 /* We can't set both a clip mask and use XSetClipRectangles
2421 because the latter also sets a clip mask. We also can't
2422 trust on the shape extension to be available
2423 (XShapeCombineRegion). So, compute the rectangle to draw
2425 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2428 XRectangle clip_rect
, image_rect
, r
;
2430 xgcv
.clip_mask
= s
->img
->mask
;
2431 xgcv
.clip_x_origin
= x
;
2432 xgcv
.clip_y_origin
= y
;
2433 xgcv
.function
= GXcopy
;
2434 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2436 get_glyph_string_clip_rect (s
, &clip_rect
);
2439 image_rect
.width
= s
->slice
.width
;
2440 image_rect
.height
= s
->slice
.height
;
2441 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2442 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2443 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2444 r
.width
, r
.height
, r
.x
, r
.y
);
2448 XRectangle clip_rect
, image_rect
, r
;
2450 get_glyph_string_clip_rect (s
, &clip_rect
);
2453 image_rect
.width
= s
->slice
.width
;
2454 image_rect
.height
= s
->slice
.height
;
2455 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2456 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2457 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2458 r
.width
, r
.height
, r
.x
, r
.y
);
2460 /* When the image has a mask, we can expect that at
2461 least part of a mouse highlight or a block cursor will
2462 be visible. If the image doesn't have a mask, make
2463 a block cursor visible by drawing a rectangle around
2464 the image. I believe it's looking better if we do
2465 nothing here for mouse-face. */
2466 if (s
->hl
== DRAW_CURSOR
)
2468 int r
= s
->img
->relief
;
2470 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2472 s
->slice
.width
+ r
*2 - 1,
2473 s
->slice
.height
+ r
*2 - 1);
2478 /* Draw a rectangle if image could not be loaded. */
2479 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2480 s
->slice
.width
- 1, s
->slice
.height
- 1);
2484 /* Draw a relief around the image glyph string S. */
2487 x_draw_image_relief (s
)
2488 struct glyph_string
*s
;
2490 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2493 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2495 /* If first glyph of S has a left box line, start drawing it to the
2496 right of that line. */
2497 if (s
->face
->box
!= FACE_NO_BOX
2498 && s
->first_glyph
->left_box_line_p
2500 x
+= eabs (s
->face
->box_line_width
);
2502 /* If there is a margin around the image, adjust x- and y-position
2504 if (s
->slice
.x
== 0)
2505 x
+= s
->img
->hmargin
;
2506 if (s
->slice
.y
== 0)
2507 y
+= s
->img
->vmargin
;
2509 if (s
->hl
== DRAW_IMAGE_SUNKEN
2510 || s
->hl
== DRAW_IMAGE_RAISED
)
2512 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2513 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2517 thick
= eabs (s
->img
->relief
);
2518 raised_p
= s
->img
->relief
> 0;
2523 x1
= x
+ s
->slice
.width
+ thick
- 1;
2524 y1
= y
+ s
->slice
.height
+ thick
- 1;
2526 x_setup_relief_colors (s
);
2527 get_glyph_string_clip_rect (s
, &r
);
2528 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2530 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2532 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2537 /* Draw the foreground of image glyph string S to PIXMAP. */
2540 x_draw_image_foreground_1 (s
, pixmap
)
2541 struct glyph_string
*s
;
2545 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2547 /* If first glyph of S has a left box line, start drawing it to the
2548 right of that line. */
2549 if (s
->face
->box
!= FACE_NO_BOX
2550 && s
->first_glyph
->left_box_line_p
2552 x
+= eabs (s
->face
->box_line_width
);
2554 /* If there is a margin around the image, adjust x- and y-position
2556 if (s
->slice
.x
== 0)
2557 x
+= s
->img
->hmargin
;
2558 if (s
->slice
.y
== 0)
2559 y
+= s
->img
->vmargin
;
2565 /* We can't set both a clip mask and use XSetClipRectangles
2566 because the latter also sets a clip mask. We also can't
2567 trust on the shape extension to be available
2568 (XShapeCombineRegion). So, compute the rectangle to draw
2570 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2574 xgcv
.clip_mask
= s
->img
->mask
;
2575 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2576 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2577 xgcv
.function
= GXcopy
;
2578 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2580 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2581 s
->slice
.x
, s
->slice
.y
,
2582 s
->slice
.width
, s
->slice
.height
, x
, y
);
2583 XSetClipMask (s
->display
, s
->gc
, None
);
2587 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2588 s
->slice
.x
, s
->slice
.y
,
2589 s
->slice
.width
, s
->slice
.height
, x
, y
);
2591 /* When the image has a mask, we can expect that at
2592 least part of a mouse highlight or a block cursor will
2593 be visible. If the image doesn't have a mask, make
2594 a block cursor visible by drawing a rectangle around
2595 the image. I believe it's looking better if we do
2596 nothing here for mouse-face. */
2597 if (s
->hl
== DRAW_CURSOR
)
2599 int r
= s
->img
->relief
;
2601 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2602 s
->slice
.width
+ r
*2 - 1,
2603 s
->slice
.height
+ r
*2 - 1);
2608 /* Draw a rectangle if image could not be loaded. */
2609 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2610 s
->slice
.width
- 1, s
->slice
.height
- 1);
2614 /* Draw part of the background of glyph string S. X, Y, W, and H
2615 give the rectangle to draw. */
2618 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2619 struct glyph_string
*s
;
2624 /* Fill background with a stipple pattern. */
2625 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2626 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2627 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2630 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2634 /* Draw image glyph string S.
2637 s->x +-------------------------
2640 | +-------------------------
2643 | | +-------------------
2649 x_draw_image_glyph_string (s
)
2650 struct glyph_string
*s
;
2652 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2653 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2655 Pixmap pixmap
= None
;
2658 if (s
->slice
.y
== 0)
2659 height
-= box_line_vwidth
;
2660 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2661 height
-= box_line_vwidth
;
2663 /* Fill background with face under the image. Do it only if row is
2664 taller than image or if image has a clip mask to reduce
2666 s
->stippled_p
= s
->face
->stipple
!= 0;
2667 if (height
> s
->slice
.height
2671 || s
->img
->pixmap
== 0
2672 || s
->width
!= s
->background_width
)
2676 /* Create a pixmap as large as the glyph string. Fill it
2677 with the background color. Copy the image to it, using
2678 its mask. Copy the temporary pixmap to the display. */
2679 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2680 int depth
= DefaultDepthOfScreen (screen
);
2682 /* Create a pixmap as large as the glyph string. */
2683 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2684 s
->background_width
,
2687 /* Don't clip in the following because we're working on the
2689 XSetClipMask (s
->display
, s
->gc
, None
);
2691 /* Fill the pixmap with the background color/stipple. */
2694 /* Fill background with a stipple pattern. */
2695 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2696 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2697 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2698 0, 0, s
->background_width
, s
->height
);
2699 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2700 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2705 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2707 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2708 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2709 0, 0, s
->background_width
, s
->height
);
2710 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2718 if (s
->first_glyph
->left_box_line_p
2720 x
+= box_line_hwidth
;
2722 if (s
->slice
.y
== 0)
2723 y
+= box_line_vwidth
;
2725 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2728 s
->background_filled_p
= 1;
2731 /* Draw the foreground. */
2734 x_draw_image_foreground_1 (s
, pixmap
);
2735 x_set_glyph_string_clipping (s
);
2736 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2737 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2738 XFreePixmap (s
->display
, pixmap
);
2741 x_draw_image_foreground (s
);
2743 /* If we must draw a relief around the image, do it. */
2745 || s
->hl
== DRAW_IMAGE_RAISED
2746 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2747 x_draw_image_relief (s
);
2751 /* Draw stretch glyph string S. */
2754 x_draw_stretch_glyph_string (s
)
2755 struct glyph_string
*s
;
2757 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2759 if (s
->hl
== DRAW_CURSOR
2760 && !x_stretch_cursor_p
)
2762 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2763 as wide as the stretch glyph. */
2764 int width
, background_width
= s
->background_width
;
2765 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2769 background_width
-= left_x
- x
;
2772 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2775 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2777 /* Clear rest using the GC of the original non-cursor face. */
2778 if (width
< background_width
)
2781 int w
= background_width
- width
, h
= s
->height
;
2786 if (s
->row
->mouse_face_p
2787 && cursor_in_mouse_face_p (s
->w
))
2789 x_set_mouse_face_gc (s
);
2795 get_glyph_string_clip_rect (s
, &r
);
2796 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2798 if (s
->face
->stipple
)
2800 /* Fill background with a stipple pattern. */
2801 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2802 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2803 XSetFillStyle (s
->display
, gc
, FillSolid
);
2808 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2809 XSetForeground (s
->display
, gc
, xgcv
.background
);
2810 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2811 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2815 else if (!s
->background_filled_p
)
2817 int background_width
= s
->background_width
;
2818 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2820 /* Don't draw into left margin, fringe or scrollbar area
2821 except for header line and mode line. */
2822 if (x
< left_x
&& !s
->row
->mode_line_p
)
2824 background_width
-= left_x
- x
;
2827 if (background_width
> 0)
2828 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2831 s
->background_filled_p
= 1;
2835 /* Draw glyph string S. */
2838 x_draw_glyph_string (s
)
2839 struct glyph_string
*s
;
2841 int relief_drawn_p
= 0;
2843 /* If S draws into the background of its successors, draw the
2844 background of the successors first so that S can draw into it.
2845 This makes S->next use XDrawString instead of XDrawImageString. */
2846 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2849 struct glyph_string
*next
;
2851 for (width
= 0, next
= s
->next
; next
;
2852 width
+= next
->width
, next
= next
->next
)
2853 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2855 x_set_glyph_string_gc (next
);
2856 x_set_glyph_string_clipping (next
);
2857 x_draw_glyph_string_background (next
, 1);
2858 #ifdef USE_FONT_BACKEND
2859 next
->num_clips
= 0;
2860 #endif /* USE_FONT_BACKEND */
2864 /* Set up S->gc, set clipping and draw S. */
2865 x_set_glyph_string_gc (s
);
2867 /* Draw relief (if any) in advance for char/composition so that the
2868 glyph string can be drawn over it. */
2869 if (!s
->for_overlaps
2870 && s
->face
->box
!= FACE_NO_BOX
2871 && (s
->first_glyph
->type
== CHAR_GLYPH
2872 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2875 x_set_glyph_string_clipping (s
);
2876 x_draw_glyph_string_background (s
, 1);
2877 x_draw_glyph_string_box (s
);
2878 x_set_glyph_string_clipping (s
);
2881 else if ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2882 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
))
2883 /* We must clip just this glyph. left_overhang part has already
2884 drawn when s->prev was drawn, and right_overhang part will be
2885 drawn later when s->next is drawn. */
2886 x_set_glyph_string_clipping_exactly (s
, s
);
2888 x_set_glyph_string_clipping (s
);
2890 switch (s
->first_glyph
->type
)
2893 x_draw_image_glyph_string (s
);
2897 x_draw_stretch_glyph_string (s
);
2901 if (s
->for_overlaps
)
2902 s
->background_filled_p
= 1;
2904 x_draw_glyph_string_background (s
, 0);
2905 x_draw_glyph_string_foreground (s
);
2908 case COMPOSITE_GLYPH
:
2909 if (s
->for_overlaps
|| s
->gidx
> 0)
2910 s
->background_filled_p
= 1;
2912 x_draw_glyph_string_background (s
, 1);
2913 x_draw_composite_glyph_string_foreground (s
);
2920 if (!s
->for_overlaps
)
2922 /* Draw underline. */
2923 if (s
->face
->underline_p
)
2925 unsigned long tem
, h
;
2928 /* Get the underline thickness. Default is 1 pixel. */
2929 #ifdef USE_FONT_BACKEND
2930 if (enable_font_backend
)
2931 /* In the future, we must use information of font. */
2934 #endif /* USE_FONT_BACKEND */
2935 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
2938 #ifdef USE_FONT_BACKEND
2939 if (enable_font_backend
)
2942 /* In the future, we must use information of font. */
2943 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2945 y
= s
->y
+ s
->height
- h
;
2950 y
= s
->y
+ s
->height
- h
;
2951 if (!x_underline_at_descent_line
)
2953 /* Get the underline position. This is the recommended
2954 vertical offset in pixels from the baseline to the top of
2955 the underline. This is a signed value according to the
2956 specs, and its default is
2958 ROUND ((maximum descent) / 2), with
2959 ROUND(x) = floor (x + 0.5) */
2961 if (x_use_underline_position_properties
2962 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
2963 y
= s
->ybase
+ (long) tem
;
2964 else if (s
->face
->font
)
2965 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2969 if (s
->face
->underline_defaulted_p
)
2970 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2971 s
->x
, y
, s
->background_width
, h
);
2975 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2976 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2977 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2978 s
->x
, y
, s
->background_width
, h
);
2979 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2983 /* Draw overline. */
2984 if (s
->face
->overline_p
)
2986 unsigned long dy
= 0, h
= 1;
2988 if (s
->face
->overline_color_defaulted_p
)
2989 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2990 s
->background_width
, h
);
2994 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2995 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2996 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2997 s
->background_width
, h
);
2998 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3002 /* Draw strike-through. */
3003 if (s
->face
->strike_through_p
)
3005 unsigned long h
= 1;
3006 unsigned long dy
= (s
->height
- h
) / 2;
3008 if (s
->face
->strike_through_color_defaulted_p
)
3009 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3014 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3015 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3016 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3018 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3022 /* Draw relief if not yet drawn. */
3023 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3024 x_draw_glyph_string_box (s
);
3028 struct glyph_string
*prev
;
3030 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
3031 if (prev
->hl
!= s
->hl
3032 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
3034 /* As prev was drawn while clipped to its own area, we
3035 must draw the right_overhang part using s->hl now. */
3036 enum draw_glyphs_face save
= prev
->hl
;
3039 x_set_glyph_string_gc (prev
);
3040 x_set_glyph_string_clipping_exactly (s
, prev
);
3041 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
3042 x_draw_glyph_string_foreground (prev
);
3044 x_draw_composite_glyph_string_foreground (prev
);
3045 XSetClipMask (prev
->display
, prev
->gc
, None
);
3047 #ifdef USE_FONT_BACKEND
3048 prev
->num_clips
= 0;
3049 #endif /* USE_FONT_BACKEND */
3055 struct glyph_string
*next
;
3057 for (next
= s
->next
; next
; next
= next
->next
)
3058 if (next
->hl
!= s
->hl
3059 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
3061 /* As next will be drawn while clipped to its own area,
3062 we must draw the left_overhang part using s->hl now. */
3063 enum draw_glyphs_face save
= next
->hl
;
3066 x_set_glyph_string_gc (next
);
3067 x_set_glyph_string_clipping_exactly (s
, next
);
3068 if (next
->first_glyph
->type
== CHAR_GLYPH
)
3069 x_draw_glyph_string_foreground (next
);
3071 x_draw_composite_glyph_string_foreground (next
);
3072 XSetClipMask (next
->display
, next
->gc
, None
);
3074 #ifdef USE_FONT_BACKEND
3075 next
->num_clips
= 0;
3076 #endif /* USE_FONT_BACKEND */
3081 /* Reset clipping. */
3082 XSetClipMask (s
->display
, s
->gc
, None
);
3083 #ifdef USE_FONT_BACKEND
3085 #endif /* USE_FONT_BACKEND */
3088 /* Shift display to make room for inserted glyphs. */
3091 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
3093 int x
, y
, width
, height
, shift_by
;
3095 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3096 f
->output_data
.x
->normal_gc
,
3097 x
, y
, width
, height
,
3101 /* Delete N glyphs at the nominal cursor position. Not implemented
3105 x_delete_glyphs (f
, n
)
3113 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
3114 If they are <= 0, this is probably an error. */
3117 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
3124 xassert (width
> 0 && height
> 0);
3125 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
3129 /* Clear an entire frame. */
3132 x_clear_frame (struct frame
*f
)
3134 /* Clearing the frame will erase any cursor, so mark them all as no
3136 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3137 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3138 output_cursor
.x
= -1;
3140 /* We don't set the output cursor here because there will always
3141 follow an explicit cursor_to. */
3143 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
3145 /* We have to clear the scroll bars, too. If we have changed
3146 colors or something like that, then they should be notified. */
3147 x_scroll_bar_clear (f
);
3149 XFlush (FRAME_X_DISPLAY (f
));
3156 /* Invert the middle quarter of the frame for .15 sec. */
3158 /* We use the select system call to do the waiting, so we have to make
3159 sure it's available. If it isn't, we just won't do visual bells. */
3161 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3164 /* Subtract the `struct timeval' values X and Y, storing the result in
3165 *RESULT. Return 1 if the difference is negative, otherwise 0. */
3168 timeval_subtract (result
, x
, y
)
3169 struct timeval
*result
, x
, y
;
3171 /* Perform the carry for the later subtraction by updating y. This
3172 is safer because on some systems the tv_sec member is unsigned. */
3173 if (x
.tv_usec
< y
.tv_usec
)
3175 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
3176 y
.tv_usec
-= 1000000 * nsec
;
3180 if (x
.tv_usec
- y
.tv_usec
> 1000000)
3182 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
3183 y
.tv_usec
+= 1000000 * nsec
;
3187 /* Compute the time remaining to wait. tv_usec is certainly
3189 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
3190 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3192 /* Return indication of whether the result should be considered
3194 return x
.tv_sec
< y
.tv_sec
;
3206 /* Create a GC that will use the GXxor function to flip foreground
3207 pixels into background pixels. */
3211 values
.function
= GXxor
;
3212 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3213 ^ FRAME_BACKGROUND_PIXEL (f
));
3215 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3216 GCFunction
| GCForeground
, &values
);
3220 /* Get the height not including a menu bar widget. */
3221 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3222 /* Height of each line to flash. */
3223 int flash_height
= FRAME_LINE_HEIGHT (f
);
3224 /* These will be the left and right margins of the rectangles. */
3225 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3226 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3230 /* Don't flash the area between a scroll bar and the frame
3231 edge it is next to. */
3232 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3234 case vertical_scroll_bar_left
:
3235 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3238 case vertical_scroll_bar_right
:
3239 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3246 width
= flash_right
- flash_left
;
3248 /* If window is tall, flash top and bottom line. */
3249 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3251 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3253 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3254 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3255 width
, flash_height
);
3256 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3258 (height
- flash_height
3259 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3260 width
, flash_height
);
3263 /* If it is short, flash it all. */
3264 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3265 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3266 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3271 struct timeval wakeup
;
3273 EMACS_GET_TIME (wakeup
);
3275 /* Compute time to wait until, propagating carry from usecs. */
3276 wakeup
.tv_usec
+= 150000;
3277 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3278 wakeup
.tv_usec
%= 1000000;
3280 /* Keep waiting until past the time wakeup or any input gets
3282 while (! detect_input_pending ())
3284 struct timeval current
;
3285 struct timeval timeout
;
3287 EMACS_GET_TIME (current
);
3289 /* Break if result would be negative. */
3290 if (timeval_subtract (¤t
, wakeup
, current
))
3293 /* How long `select' should wait. */
3295 timeout
.tv_usec
= 10000;
3297 /* Try to wait that long--but we might wake up sooner. */
3298 select (0, NULL
, NULL
, NULL
, &timeout
);
3302 /* If window is tall, flash top and bottom line. */
3303 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3305 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3307 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3308 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3309 width
, flash_height
);
3310 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3312 (height
- flash_height
3313 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3314 width
, flash_height
);
3317 /* If it is short, flash it all. */
3318 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3319 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3320 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3322 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3330 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3333 /* Make audible bell. */
3338 struct frame
*f
= SELECTED_FRAME ();
3340 if (FRAME_X_DISPLAY (f
))
3342 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3349 XBell (FRAME_X_DISPLAY (f
), 0);
3350 XFlush (FRAME_X_DISPLAY (f
));
3357 /* Specify how many text lines, from the top of the window,
3358 should be affected by insert-lines and delete-lines operations.
3359 This, and those operations, are used only within an update
3360 that is bounded by calls to x_update_begin and x_update_end. */
3363 XTset_terminal_window (n
)
3366 /* This function intentionally left blank. */
3371 /***********************************************************************
3373 ***********************************************************************/
3375 /* Perform an insert-lines or delete-lines operation, inserting N
3376 lines or deleting -N lines at vertical position VPOS. */
3379 x_ins_del_lines (f
, vpos
, n
)
3387 /* Scroll part of the display as described by RUN. */
3390 x_scroll_run (w
, run
)
3394 struct frame
*f
= XFRAME (w
->frame
);
3395 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3397 /* Get frame-relative bounding box of the text display area of W,
3398 without mode lines. Include in this box the left and right
3400 window_box (w
, -1, &x
, &y
, &width
, &height
);
3402 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3403 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3404 bottom_y
= y
+ height
;
3408 /* Scrolling up. Make sure we don't copy part of the mode
3409 line at the bottom. */
3410 if (from_y
+ run
->height
> bottom_y
)
3411 height
= bottom_y
- from_y
;
3413 height
= run
->height
;
3417 /* Scolling down. Make sure we don't copy over the mode line.
3419 if (to_y
+ run
->height
> bottom_y
)
3420 height
= bottom_y
- to_y
;
3422 height
= run
->height
;
3427 /* Cursor off. Will be switched on again in x_update_window_end. */
3431 XCopyArea (FRAME_X_DISPLAY (f
),
3432 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3433 f
->output_data
.x
->normal_gc
,
3443 /***********************************************************************
3445 ***********************************************************************/
3452 /* We used to only do this if Vx_no_window_manager was non-nil, but
3453 the ICCCM (section 4.1.6) says that the window's border pixmap
3454 and border pixel are window attributes which are "private to the
3455 client", so we can always change it to whatever we want. */
3457 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3458 f
->output_data
.x
->border_pixel
);
3460 x_update_cursor (f
, 1);
3464 frame_unhighlight (f
)
3467 /* We used to only do this if Vx_no_window_manager was non-nil, but
3468 the ICCCM (section 4.1.6) says that the window's border pixmap
3469 and border pixel are window attributes which are "private to the
3470 client", so we can always change it to whatever we want. */
3472 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3473 f
->output_data
.x
->border_tile
);
3475 x_update_cursor (f
, 1);
3478 /* The focus has changed. Update the frames as necessary to reflect
3479 the new situation. Note that we can't change the selected frame
3480 here, because the Lisp code we are interrupting might become confused.
3481 Each event gets marked with the frame in which it occurred, so the
3482 Lisp code can tell when the switch took place by examining the events. */
3485 x_new_focus_frame (dpyinfo
, frame
)
3486 struct x_display_info
*dpyinfo
;
3487 struct frame
*frame
;
3489 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3491 if (frame
!= dpyinfo
->x_focus_frame
)
3493 /* Set this before calling other routines, so that they see
3494 the correct value of x_focus_frame. */
3495 dpyinfo
->x_focus_frame
= frame
;
3497 if (old_focus
&& old_focus
->auto_lower
)
3498 x_lower_frame (old_focus
);
3501 selected_frame
= frame
;
3502 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3504 Fselect_window (selected_frame
->selected_window
, Qnil
);
3505 choose_minibuf_frame ();
3508 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3509 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3511 pending_autoraise_frame
= 0;
3514 x_frame_rehighlight (dpyinfo
);
3517 /* Handle FocusIn and FocusOut state changes for FRAME.
3518 If FRAME has focus and there exists more than one frame, puts
3519 a FOCUS_IN_EVENT into *BUFP. */
3522 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
)
3525 struct x_display_info
*dpyinfo
;
3526 struct frame
*frame
;
3527 struct input_event
*bufp
;
3529 if (type
== FocusIn
)
3531 if (dpyinfo
->x_focus_event_frame
!= frame
)
3533 x_new_focus_frame (dpyinfo
, frame
);
3534 dpyinfo
->x_focus_event_frame
= frame
;
3536 /* Don't stop displaying the initial startup message
3537 for a switch-frame event we don't need. */
3538 if (NILP (Vterminal_frame
)
3539 && CONSP (Vframe_list
)
3540 && !NILP (XCDR (Vframe_list
)))
3542 bufp
->kind
= FOCUS_IN_EVENT
;
3543 XSETFRAME (bufp
->frame_or_window
, frame
);
3547 frame
->output_data
.x
->focus_state
|= state
;
3550 if (FRAME_XIC (frame
))
3551 XSetICFocus (FRAME_XIC (frame
));
3554 else if (type
== FocusOut
)
3556 frame
->output_data
.x
->focus_state
&= ~state
;
3558 if (dpyinfo
->x_focus_event_frame
== frame
)
3560 dpyinfo
->x_focus_event_frame
= 0;
3561 x_new_focus_frame (dpyinfo
, 0);
3565 if (FRAME_XIC (frame
))
3566 XUnsetICFocus (FRAME_XIC (frame
));
3571 /* The focus may have changed. Figure out if it is a real focus change,
3572 by checking both FocusIn/Out and Enter/LeaveNotify events.
3574 Returns FOCUS_IN_EVENT event in *BUFP. */
3577 x_detect_focus_change (dpyinfo
, event
, bufp
)
3578 struct x_display_info
*dpyinfo
;
3580 struct input_event
*bufp
;
3582 struct frame
*frame
;
3584 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3588 switch (event
->type
)
3593 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3595 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3597 if (event
->xcrossing
.detail
!= NotifyInferior
3598 && event
->xcrossing
.focus
3599 && ! (focus_state
& FOCUS_EXPLICIT
))
3600 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3602 dpyinfo
, frame
, bufp
);
3608 x_focus_changed (event
->type
,
3609 (event
->xfocus
.detail
== NotifyPointer
?
3610 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3611 dpyinfo
, frame
, bufp
);
3615 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3617 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3618 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3619 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3626 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3629 x_mouse_leave (dpyinfo
)
3630 struct x_display_info
*dpyinfo
;
3632 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3635 /* The focus has changed, or we have redirected a frame's focus to
3636 another frame (this happens when a frame uses a surrogate
3637 mini-buffer frame). Shift the highlight as appropriate.
3639 The FRAME argument doesn't necessarily have anything to do with which
3640 frame is being highlighted or un-highlighted; we only use it to find
3641 the appropriate X display info. */
3644 XTframe_rehighlight (frame
)
3645 struct frame
*frame
;
3647 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3651 x_frame_rehighlight (dpyinfo
)
3652 struct x_display_info
*dpyinfo
;
3654 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3656 if (dpyinfo
->x_focus_frame
)
3658 dpyinfo
->x_highlight_frame
3659 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3660 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3661 : dpyinfo
->x_focus_frame
);
3662 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3664 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3665 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3669 dpyinfo
->x_highlight_frame
= 0;
3671 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3674 frame_unhighlight (old_highlight
);
3675 if (dpyinfo
->x_highlight_frame
)
3676 frame_highlight (dpyinfo
->x_highlight_frame
);
3682 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3684 /* Initialize mode_switch_bit and modifier_meaning. */
3686 x_find_modifier_meanings (dpyinfo
)
3687 struct x_display_info
*dpyinfo
;
3689 int min_code
, max_code
;
3692 XModifierKeymap
*mods
;
3694 dpyinfo
->meta_mod_mask
= 0;
3695 dpyinfo
->shift_lock_mask
= 0;
3696 dpyinfo
->alt_mod_mask
= 0;
3697 dpyinfo
->super_mod_mask
= 0;
3698 dpyinfo
->hyper_mod_mask
= 0;
3700 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3702 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3703 min_code
, max_code
- min_code
+ 1,
3705 mods
= XGetModifierMapping (dpyinfo
->display
);
3707 /* Scan the modifier table to see which modifier bits the Meta and
3708 Alt keysyms are on. */
3710 int row
, col
; /* The row and column in the modifier table. */
3711 int found_alt_or_meta
;
3713 for (row
= 3; row
< 8; row
++)
3715 found_alt_or_meta
= 0;
3716 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3718 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3720 /* Zeroes are used for filler. Skip them. */
3724 /* Are any of this keycode's keysyms a meta key? */
3728 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3730 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3736 found_alt_or_meta
= 1;
3737 dpyinfo
->meta_mod_mask
|= (1 << row
);
3742 found_alt_or_meta
= 1;
3743 dpyinfo
->alt_mod_mask
|= (1 << row
);
3748 if (!found_alt_or_meta
)
3749 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3750 code_col
= syms_per_code
;
3751 col
= mods
->max_keypermod
;
3756 if (!found_alt_or_meta
)
3757 dpyinfo
->super_mod_mask
|= (1 << row
);
3758 code_col
= syms_per_code
;
3759 col
= mods
->max_keypermod
;
3763 /* Ignore this if it's not on the lock modifier. */
3764 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3765 dpyinfo
->shift_lock_mask
= LockMask
;
3766 code_col
= syms_per_code
;
3767 col
= mods
->max_keypermod
;
3776 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3777 if (! dpyinfo
->meta_mod_mask
)
3779 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3780 dpyinfo
->alt_mod_mask
= 0;
3783 /* If some keys are both alt and meta,
3784 make them just meta, not alt. */
3785 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3787 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3790 XFree ((char *) syms
);
3791 XFreeModifiermap (mods
);
3794 /* Convert between the modifier bits X uses and the modifier bits
3798 x_x_to_emacs_modifiers (dpyinfo
, state
)
3799 struct x_display_info
*dpyinfo
;
3802 EMACS_UINT mod_meta
= meta_modifier
;
3803 EMACS_UINT mod_alt
= alt_modifier
;
3804 EMACS_UINT mod_hyper
= hyper_modifier
;
3805 EMACS_UINT mod_super
= super_modifier
;
3808 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3809 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3810 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3811 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3812 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3813 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3814 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3815 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3818 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3819 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3820 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3821 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3822 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3823 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3827 x_emacs_to_x_modifiers (dpyinfo
, state
)
3828 struct x_display_info
*dpyinfo
;
3831 EMACS_UINT mod_meta
= meta_modifier
;
3832 EMACS_UINT mod_alt
= alt_modifier
;
3833 EMACS_UINT mod_hyper
= hyper_modifier
;
3834 EMACS_UINT mod_super
= super_modifier
;
3838 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3839 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3840 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3841 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3842 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3843 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3844 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3845 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3848 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3849 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3850 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3851 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3852 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3853 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3856 /* Convert a keysym to its name. */
3859 x_get_keysym_name (keysym
)
3865 value
= XKeysymToString (keysym
);
3873 /* Mouse clicks and mouse movement. Rah. */
3875 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3877 If the event is a button press, then note that we have grabbed
3881 construct_mouse_click (result
, event
, f
)
3882 struct input_event
*result
;
3883 XButtonEvent
*event
;
3886 /* Make the event type NO_EVENT; we'll change that when we decide
3888 result
->kind
= MOUSE_CLICK_EVENT
;
3889 result
->code
= event
->button
- Button1
;
3890 result
->timestamp
= event
->time
;
3891 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3893 | (event
->type
== ButtonRelease
3897 XSETINT (result
->x
, event
->x
);
3898 XSETINT (result
->y
, event
->y
);
3899 XSETFRAME (result
->frame_or_window
, f
);
3905 /* Function to report a mouse movement to the mainstream Emacs code.
3906 The input handler calls this.
3908 We have received a mouse movement event, which is given in *event.
3909 If the mouse is over a different glyph than it was last time, tell
3910 the mainstream emacs code by setting mouse_moved. If not, ask for
3911 another motion event, so we can check again the next time it moves. */
3913 static XMotionEvent last_mouse_motion_event
;
3914 static Lisp_Object last_mouse_motion_frame
;
3917 note_mouse_movement (frame
, event
)
3919 XMotionEvent
*event
;
3921 last_mouse_movement_time
= event
->time
;
3922 last_mouse_motion_event
= *event
;
3923 XSETFRAME (last_mouse_motion_frame
, frame
);
3925 if (!FRAME_X_OUTPUT (frame
))
3928 if (event
->window
!= FRAME_X_WINDOW (frame
))
3930 frame
->mouse_moved
= 1;
3931 last_mouse_scroll_bar
= Qnil
;
3932 note_mouse_highlight (frame
, -1, -1);
3933 last_mouse_glyph_frame
= 0;
3938 /* Has the mouse moved off the glyph it was on at the last sighting? */
3939 if (frame
!= last_mouse_glyph_frame
3940 || event
->x
< last_mouse_glyph
.x
3941 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3942 || event
->y
< last_mouse_glyph
.y
3943 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3945 frame
->mouse_moved
= 1;
3946 last_mouse_scroll_bar
= Qnil
;
3947 note_mouse_highlight (frame
, event
->x
, event
->y
);
3948 /* Remember which glyph we're now on. */
3949 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3950 last_mouse_glyph_frame
= frame
;
3958 /************************************************************************
3960 ************************************************************************/
3963 redo_mouse_highlight ()
3965 if (!NILP (last_mouse_motion_frame
)
3966 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3967 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3968 last_mouse_motion_event
.x
,
3969 last_mouse_motion_event
.y
);
3974 /* Return the current position of the mouse.
3975 *FP should be a frame which indicates which display to ask about.
3977 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3978 and *PART to the frame, window, and scroll bar part that the mouse
3979 is over. Set *X and *Y to the portion and whole of the mouse's
3980 position on the scroll bar.
3982 If the mouse movement started elsewhere, set *FP to the frame the
3983 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3986 Set *TIME to the server time-stamp for the time at which the mouse
3987 was at this position.
3989 Don't store anything if we don't have a valid set of values to report.
3991 This clears the mouse_moved flag, so we can wait for the next mouse
3995 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3998 Lisp_Object
*bar_window
;
3999 enum scroll_bar_part
*part
;
4001 unsigned long *time
;
4007 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
4008 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
4014 Window dummy_window
;
4017 Lisp_Object frame
, tail
;
4019 /* Clear the mouse-moved flag for every frame on this display. */
4020 FOR_EACH_FRAME (tail
, frame
)
4021 if (FRAME_X_P (XFRAME (frame
))
4022 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
4023 XFRAME (frame
)->mouse_moved
= 0;
4025 last_mouse_scroll_bar
= Qnil
;
4027 /* Figure out which root window we're on. */
4028 XQueryPointer (FRAME_X_DISPLAY (*fp
),
4029 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
4031 /* The root window which contains the pointer. */
4034 /* Trash which we can't trust if the pointer is on
4035 a different screen. */
4038 /* The position on that root window. */
4041 /* More trash we can't trust. */
4044 /* Modifier keys and pointer buttons, about which
4046 (unsigned int *) &dummy
);
4048 /* Now we have a position on the root; find the innermost window
4049 containing the pointer. */
4053 int parent_x
= 0, parent_y
= 0;
4057 /* XTranslateCoordinates can get errors if the window
4058 structure is changing at the same time this function
4059 is running. So at least we must not crash from them. */
4061 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4063 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4064 && FRAME_LIVE_P (last_mouse_frame
))
4066 /* If mouse was grabbed on a frame, give coords for that frame
4067 even if the mouse is now outside it. */
4068 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4070 /* From-window, to-window. */
4071 root
, FRAME_X_WINDOW (last_mouse_frame
),
4073 /* From-position, to-position. */
4074 root_x
, root_y
, &win_x
, &win_y
,
4078 f1
= last_mouse_frame
;
4084 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4086 /* From-window, to-window. */
4089 /* From-position, to-position. */
4090 root_x
, root_y
, &win_x
, &win_y
,
4095 if (child
== None
|| child
== win
)
4103 /* Now we know that:
4104 win is the innermost window containing the pointer
4105 (XTC says it has no child containing the pointer),
4106 win_x and win_y are the pointer's position in it
4107 (XTC did this the last time through), and
4108 parent_x and parent_y are the pointer's position in win's parent.
4109 (They are what win_x and win_y were when win was child.
4110 If win is the root window, it has no parent, and
4111 parent_{x,y} are invalid, but that's okay, because we'll
4112 never use them in that case.) */
4114 /* Is win one of our frames? */
4115 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
4117 #ifdef USE_X_TOOLKIT
4118 /* If we end up with the menu bar window, say it's not
4121 && f1
->output_data
.x
->menubar_widget
4122 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4124 #endif /* USE_X_TOOLKIT */
4127 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4130 x_uncatch_errors ();
4132 /* If not, is it one of our scroll bars? */
4135 struct scroll_bar
*bar
;
4137 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
4141 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4147 if (f1
== 0 && insist
> 0)
4148 f1
= SELECTED_FRAME ();
4152 /* Ok, we found a frame. Store all the values.
4153 last_mouse_glyph is a rectangle used to reduce the
4154 generation of mouse events. To not miss any motion
4155 events, we must divide the frame into rectangles of the
4156 size of the smallest character that could be displayed
4157 on it, i.e. into the same rectangles that matrices on
4158 the frame are divided into. */
4160 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
4161 last_mouse_glyph_frame
= f1
;
4166 XSETINT (*x
, win_x
);
4167 XSETINT (*y
, win_y
);
4168 *time
= last_mouse_movement_time
;
4178 /***********************************************************************
4180 ***********************************************************************/
4182 /* Scroll bar support. */
4184 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4186 This can be called in GC, so we have to make sure to strip off mark
4189 static struct scroll_bar
*
4190 x_window_to_scroll_bar (display
, window_id
)
4196 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4197 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4198 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4200 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4202 Lisp_Object frame
, bar
, condemned
;
4204 frame
= XCAR (tail
);
4205 /* All elements of Vframe_list should be frames. */
4206 if (! FRAMEP (frame
))
4209 if (! FRAME_X_P (XFRAME (frame
)))
4212 /* Scan this frame's scroll bar list for a scroll bar with the
4214 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4215 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4216 /* This trick allows us to search both the ordinary and
4217 condemned scroll bar lists with one loop. */
4218 ! NILP (bar
) || (bar
= condemned
,
4221 bar
= XSCROLL_BAR (bar
)->next
)
4222 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4223 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4224 return XSCROLL_BAR (bar
);
4231 #if defined USE_LUCID
4233 /* Return the Lucid menu bar WINDOW is part of. Return null
4234 if WINDOW is not part of a menu bar. */
4237 x_window_to_menu_bar (window
)
4242 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4244 if (FRAME_X_P (XFRAME (XCAR (tail
))))
4246 Lisp_Object frame
= XCAR (tail
);
4247 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4249 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4257 #endif /* USE_LUCID */
4260 /************************************************************************
4262 ************************************************************************/
4264 #ifdef USE_TOOLKIT_SCROLL_BARS
4266 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
4267 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
4268 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
4269 struct scroll_bar
*));
4270 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4274 /* Lisp window being scrolled. Set when starting to interact with
4275 a toolkit scroll bar, reset to nil when ending the interaction. */
4277 static Lisp_Object window_being_scrolled
;
4279 /* Last scroll bar part sent in xm_scroll_callback. */
4281 static int last_scroll_bar_part
;
4283 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4284 that movements of 1/20 of the screen size are mapped to up/down. */
4287 /* Id of action hook installed for scroll bars. */
4289 static XtActionHookId action_hook_id
;
4291 static Boolean xaw3d_arrow_scroll
;
4293 /* Whether the drag scrolling maintains the mouse at the top of the
4294 thumb. If not, resizing the thumb needs to be done more carefully
4295 to avoid jerkyness. */
4297 static Boolean xaw3d_pick_top
;
4299 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4300 bars are used.. The hook is responsible for detecting when
4301 the user ends an interaction with the scroll bar, and generates
4302 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4305 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
4308 XtPointer client_data
;
4312 Cardinal
*num_params
;
4318 scroll_bar_p
= XmIsScrollBar (widget
);
4319 end_action
= "Release";
4320 #else /* !USE_MOTIF i.e. use Xaw */
4321 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4322 end_action
= "EndScroll";
4323 #endif /* USE_MOTIF */
4326 && strcmp (action_name
, end_action
) == 0
4327 && WINDOWP (window_being_scrolled
))
4331 x_send_scroll_bar_event (window_being_scrolled
,
4332 scroll_bar_end_scroll
, 0, 0);
4333 w
= XWINDOW (window_being_scrolled
);
4335 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4337 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4338 /* The thumb size is incorrect while dragging: fix it. */
4339 set_vertical_scroll_bar (w
);
4341 window_being_scrolled
= Qnil
;
4342 last_scroll_bar_part
= -1;
4344 /* Xt timeouts no longer needed. */
4345 toolkit_scroll_bar_interaction
= 0;
4348 #endif /* not USE_GTK */
4350 /* A vector of windows used for communication between
4351 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4353 static struct window
**scroll_bar_windows
;
4354 static int scroll_bar_windows_size
;
4357 /* Send a client message with message type Xatom_Scrollbar for a
4358 scroll action to the frame of WINDOW. PART is a value identifying
4359 the part of the scroll bar that was clicked on. PORTION is the
4360 amount to scroll of a whole of WHOLE. */
4363 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4365 int part
, portion
, whole
;
4368 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4369 struct window
*w
= XWINDOW (window
);
4370 struct frame
*f
= XFRAME (w
->frame
);
4375 /* Construct a ClientMessage event to send to the frame. */
4376 ev
->type
= ClientMessage
;
4377 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4378 ev
->display
= FRAME_X_DISPLAY (f
);
4379 ev
->window
= FRAME_X_WINDOW (f
);
4382 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4383 not enough to store a pointer or Lisp_Object on a 64 bit system.
4384 So, store the window in scroll_bar_windows and pass the index
4385 into that array in the event. */
4386 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4387 if (scroll_bar_windows
[i
] == NULL
)
4390 if (i
== scroll_bar_windows_size
)
4392 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4393 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4394 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4396 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4398 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4399 scroll_bar_windows_size
= new_size
;
4402 scroll_bar_windows
[i
] = w
;
4403 ev
->data
.l
[0] = (long) i
;
4404 ev
->data
.l
[1] = (long) part
;
4405 ev
->data
.l
[2] = (long) 0;
4406 ev
->data
.l
[3] = (long) portion
;
4407 ev
->data
.l
[4] = (long) whole
;
4409 /* Make Xt timeouts work while the scroll bar is active. */
4410 toolkit_scroll_bar_interaction
= 1;
4411 #ifdef USE_X_TOOLKIT
4412 x_activate_timeout_atimer ();
4415 /* Setting the event mask to zero means that the message will
4416 be sent to the client that created the window, and if that
4417 window no longer exists, no event will be sent. */
4418 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4423 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4427 x_scroll_bar_to_input_event (event
, ievent
)
4429 struct input_event
*ievent
;
4431 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4436 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4437 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4439 XSETWINDOW (window
, w
);
4440 f
= XFRAME (w
->frame
);
4442 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4443 ievent
->frame_or_window
= window
;
4446 ievent
->timestamp
= CurrentTime
;
4448 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4450 ievent
->part
= ev
->data
.l
[1];
4451 ievent
->code
= ev
->data
.l
[2];
4452 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4453 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4454 ievent
->modifiers
= 0;
4460 /* Minimum and maximum values used for Motif scroll bars. */
4462 #define XM_SB_MAX 10000000
4465 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4466 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4467 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4470 xm_scroll_callback (widget
, client_data
, call_data
)
4472 XtPointer client_data
, call_data
;
4474 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4475 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4476 int part
= -1, whole
= 0, portion
= 0;
4480 case XmCR_DECREMENT
:
4481 bar
->dragging
= Qnil
;
4482 part
= scroll_bar_up_arrow
;
4485 case XmCR_INCREMENT
:
4486 bar
->dragging
= Qnil
;
4487 part
= scroll_bar_down_arrow
;
4490 case XmCR_PAGE_DECREMENT
:
4491 bar
->dragging
= Qnil
;
4492 part
= scroll_bar_above_handle
;
4495 case XmCR_PAGE_INCREMENT
:
4496 bar
->dragging
= Qnil
;
4497 part
= scroll_bar_below_handle
;
4501 bar
->dragging
= Qnil
;
4502 part
= scroll_bar_to_top
;
4505 case XmCR_TO_BOTTOM
:
4506 bar
->dragging
= Qnil
;
4507 part
= scroll_bar_to_bottom
;
4514 /* Get the slider size. */
4516 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4519 whole
= XM_SB_MAX
- slider_size
;
4520 portion
= min (cs
->value
, whole
);
4521 part
= scroll_bar_handle
;
4522 bar
->dragging
= make_number (cs
->value
);
4526 case XmCR_VALUE_CHANGED
:
4532 window_being_scrolled
= bar
->window
;
4533 last_scroll_bar_part
= part
;
4534 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4538 #elif defined USE_GTK
4540 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4541 bar widget. DATA is a pointer to the scroll_bar structure. */
4544 xg_scroll_callback (widget
, data
)
4548 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4554 int part
= -1, whole
= 0, portion
= 0;
4555 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4557 position
= gtk_adjustment_get_value (adj
);
4559 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4562 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4564 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4570 if (xg_ignore_gtk_scrollbar
) return;
4572 diff
= (int) (position
- previous
);
4574 if (diff
== (int) adj
->step_increment
)
4576 part
= scroll_bar_down_arrow
;
4577 bar
->dragging
= Qnil
;
4579 else if (-diff
== (int) adj
->step_increment
)
4581 part
= scroll_bar_up_arrow
;
4582 bar
->dragging
= Qnil
;
4584 else if (diff
== (int) adj
->page_increment
)
4586 part
= scroll_bar_below_handle
;
4587 bar
->dragging
= Qnil
;
4589 else if (-diff
== (int) adj
->page_increment
)
4591 part
= scroll_bar_above_handle
;
4592 bar
->dragging
= Qnil
;
4596 part
= scroll_bar_handle
;
4597 whole
= adj
->upper
- adj
->page_size
;
4598 portion
= min ((int)position
, whole
);
4599 bar
->dragging
= make_number ((int)portion
);
4604 window_being_scrolled
= bar
->window
;
4605 last_scroll_bar_part
= part
;
4606 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4610 #else /* not USE_GTK and not USE_MOTIF */
4612 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4613 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4614 scroll bar struct. CALL_DATA is a pointer to a float saying where
4618 xaw_jump_callback (widget
, client_data
, call_data
)
4620 XtPointer client_data
, call_data
;
4622 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4623 float top
= *(float *) call_data
;
4625 int whole
, portion
, height
;
4628 /* Get the size of the thumb, a value between 0 and 1. */
4630 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4634 portion
= shown
< 1 ? top
* whole
: 0;
4636 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4637 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4638 the bottom, so we force the scrolling whenever we see that we're
4639 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4640 we try to ensure that we always stay two pixels away from the
4642 part
= scroll_bar_down_arrow
;
4644 part
= scroll_bar_handle
;
4646 window_being_scrolled
= bar
->window
;
4647 bar
->dragging
= make_number (portion
);
4648 last_scroll_bar_part
= part
;
4649 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4653 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4654 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4655 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4656 the scroll bar. CALL_DATA is an integer specifying the action that
4657 has taken place. Its magnitude is in the range 0..height of the
4658 scroll bar. Negative values mean scroll towards buffer start.
4659 Values < height of scroll bar mean line-wise movement. */
4662 xaw_scroll_callback (widget
, client_data
, call_data
)
4664 XtPointer client_data
, call_data
;
4666 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4667 /* The position really is stored cast to a pointer. */
4668 int position
= (long) call_data
;
4672 /* Get the height of the scroll bar. */
4674 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4677 if (eabs (position
) >= height
)
4678 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4680 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4681 it maps line-movement to call_data = max(5, height/20). */
4682 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4683 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4685 part
= scroll_bar_move_ratio
;
4687 window_being_scrolled
= bar
->window
;
4688 bar
->dragging
= Qnil
;
4689 last_scroll_bar_part
= part
;
4690 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4693 #endif /* not USE_GTK and not USE_MOTIF */
4695 #define SCROLL_BAR_NAME "verticalScrollBar"
4697 /* Create the widget for scroll bar BAR on frame F. Record the widget
4698 and X window of the scroll bar in BAR. */
4702 x_create_toolkit_scroll_bar (f
, bar
)
4704 struct scroll_bar
*bar
;
4706 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4709 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4714 #else /* not USE_GTK */
4717 x_create_toolkit_scroll_bar (f
, bar
)
4719 struct scroll_bar
*bar
;
4725 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4726 unsigned long pixel
;
4731 /* Set resources. Create the widget. */
4732 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4733 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4734 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4735 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4736 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4737 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4738 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4740 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4743 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4747 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4750 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4754 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4755 scroll_bar_name
, av
, ac
);
4757 /* Add one callback for everything that can happen. */
4758 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4760 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4762 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4764 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4766 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4768 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4770 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4773 /* Realize the widget. Only after that is the X window created. */
4774 XtRealizeWidget (widget
);
4776 /* Set the cursor to an arrow. I didn't find a resource to do that.
4777 And I'm wondering why it hasn't an arrow cursor by default. */
4778 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4779 f
->output_data
.x
->nontext_cursor
);
4781 #else /* !USE_MOTIF i.e. use Xaw */
4783 /* Set resources. Create the widget. The background of the
4784 Xaw3d scroll bar widget is a little bit light for my taste.
4785 We don't alter it here to let users change it according
4786 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4787 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4788 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4789 /* For smoother scrolling with Xaw3d -sm */
4790 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4792 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4795 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4799 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4802 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4806 /* Top/bottom shadow colors. */
4808 /* Allocate them, if necessary. */
4809 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4811 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4812 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4813 &pixel
, 1.2, 0x8000))
4815 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4817 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4819 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4820 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4821 &pixel
, 0.6, 0x4000))
4823 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4826 #ifdef XtNbeNiceToColormap
4827 /* Tell the toolkit about them. */
4828 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4829 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4830 /* We tried to allocate a color for the top/bottom shadow, and
4831 failed, so tell Xaw3d to use dithering instead. */
4833 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4837 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4838 be more consistent with other emacs 3d colors, and since Xaw3d is
4839 not good at dealing with allocation failure. */
4841 /* This tells Xaw3d to use real colors instead of dithering for
4843 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4846 /* Specify the colors. */
4847 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4850 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4853 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4856 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4862 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4863 f
->output_data
.x
->edit_widget
, av
, ac
);
4867 char *val
= initial
;
4868 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4869 #ifdef XtNarrowScrollbars
4870 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4872 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4873 if (xaw3d_arrow_scroll
|| val
== initial
)
4874 { /* ARROW_SCROLL */
4875 xaw3d_arrow_scroll
= True
;
4876 /* Isn't that just a personal preference ? --Stef */
4877 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4881 /* Define callbacks. */
4882 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4883 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4886 /* Realize the widget. Only after that is the X window created. */
4887 XtRealizeWidget (widget
);
4889 #endif /* !USE_MOTIF */
4891 /* Install an action hook that lets us detect when the user
4892 finishes interacting with a scroll bar. */
4893 if (action_hook_id
== 0)
4894 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4896 /* Remember X window and widget in the scroll bar vector. */
4897 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4898 xwindow
= XtWindow (widget
);
4899 bar
->x_window
= xwindow
;
4903 #endif /* not USE_GTK */
4906 /* Set the thumb size and position of scroll bar BAR. We are currently
4907 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4911 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4912 struct scroll_bar
*bar
;
4913 int portion
, position
, whole
;
4915 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4918 #else /* not USE_GTK */
4920 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4921 struct scroll_bar
*bar
;
4922 int portion
, position
, whole
;
4924 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4925 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4932 /* We use an estimate of 30 chars per line rather than the real
4933 `portion' value. This has the disadvantage that the thumb size
4934 is not very representative, but it makes our life a lot easier.
4935 Otherwise, we have to constantly adjust the thumb size, which
4936 we can't always do quickly enough: while dragging, the size of
4937 the thumb might prevent the user from dragging the thumb all the
4938 way to the end. but Motif and some versions of Xaw3d don't allow
4939 updating the thumb size while dragging. Also, even if we can update
4940 its size, the update will often happen too late.
4941 If you don't believe it, check out revision 1.650 of xterm.c to see
4942 what hoops we were going through and the still poor behavior we got. */
4943 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4944 /* When the thumb is at the bottom, position == whole.
4945 So we need to increase `whole' to make space for the thumb. */
4952 top
= (float) position
/ whole
;
4953 shown
= (float) portion
/ whole
;
4956 if (NILP (bar
->dragging
))
4960 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4961 is the scroll bar's maximum and MIN is the scroll bar's minimum
4963 size
= shown
* XM_SB_MAX
;
4964 size
= min (size
, XM_SB_MAX
);
4965 size
= max (size
, 1);
4967 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4968 value
= top
* XM_SB_MAX
;
4969 value
= min (value
, XM_SB_MAX
- size
);
4971 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4973 #else /* !USE_MOTIF i.e. use Xaw */
4979 top
= (float) position
/ whole
;
4980 shown
= (float) portion
/ whole
;
4984 float old_top
, old_shown
;
4986 XtVaGetValues (widget
,
4987 XtNtopOfThumb
, &old_top
,
4988 XtNshown
, &old_shown
,
4992 /* Massage the top+shown values. */
4993 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4994 top
= max (0, min (1, top
));
4997 /* Keep two pixels available for moving the thumb down. */
4998 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
5000 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
5001 check that your system's configuration file contains a define
5002 for `NARROWPROTO'. See s/freebsd.h for an example. */
5003 if (top
!= old_top
|| shown
!= old_shown
)
5005 if (NILP (bar
->dragging
))
5006 XawScrollbarSetThumb (widget
, top
, shown
);
5009 /* Try to make the scrolling a tad smoother. */
5010 if (!xaw3d_pick_top
)
5011 shown
= min (shown
, old_shown
);
5013 XawScrollbarSetThumb (widget
, top
, shown
);
5017 #endif /* !USE_MOTIF */
5021 #endif /* not USE_GTK */
5023 #endif /* USE_TOOLKIT_SCROLL_BARS */
5027 /************************************************************************
5028 Scroll bars, general
5029 ************************************************************************/
5031 /* Create a scroll bar and return the scroll bar vector for it. W is
5032 the Emacs window on which to create the scroll bar. TOP, LEFT,
5033 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
5036 static struct scroll_bar
*
5037 x_scroll_bar_create (w
, top
, left
, width
, height
)
5039 int top
, left
, width
, height
;
5041 struct frame
*f
= XFRAME (w
->frame
);
5042 struct scroll_bar
*bar
5043 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
5047 #ifdef USE_TOOLKIT_SCROLL_BARS
5048 x_create_toolkit_scroll_bar (f
, bar
);
5049 #else /* not USE_TOOLKIT_SCROLL_BARS */
5051 XSetWindowAttributes a
;
5055 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5056 if (a
.background_pixel
== -1)
5057 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5059 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
5060 | ButtonMotionMask
| PointerMotionHintMask
5062 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
5064 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
5066 /* Clear the area of W that will serve as a scroll bar. This is
5067 for the case that a window has been split horizontally. In
5068 this case, no clear_frame is generated to reduce flickering. */
5069 if (width
> 0 && height
> 0)
5070 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5072 window_box_height (w
), False
);
5074 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5075 /* Position and size of scroll bar. */
5076 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5078 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5080 /* Border width, depth, class, and visual. */
5087 bar
->x_window
= window
;
5089 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5091 XSETWINDOW (bar
->window
, w
);
5095 bar
->height
= height
;
5098 bar
->dragging
= Qnil
;
5099 bar
->fringe_extended_p
= 0;
5101 /* Add bar to its frame's list of scroll bars. */
5102 bar
->next
= FRAME_SCROLL_BARS (f
);
5104 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5105 if (!NILP (bar
->next
))
5106 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5108 /* Map the window/widget. */
5109 #ifdef USE_TOOLKIT_SCROLL_BARS
5112 xg_update_scrollbar_pos (f
,
5115 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5116 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5118 xg_show_scroll_bar (bar
->x_window
);
5119 #else /* not USE_GTK */
5120 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5121 XtConfigureWidget (scroll_bar
,
5122 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5124 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5125 max (height
, 1), 0);
5126 XtMapWidget (scroll_bar
);
5127 #endif /* not USE_GTK */
5129 #else /* not USE_TOOLKIT_SCROLL_BARS */
5130 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
5131 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5138 #ifndef USE_TOOLKIT_SCROLL_BARS
5140 /* Draw BAR's handle in the proper position.
5142 If the handle is already drawn from START to END, don't bother
5143 redrawing it, unless REBUILD is non-zero; in that case, always
5144 redraw it. (REBUILD is handy for drawing the handle after expose
5147 Normally, we want to constrain the start and end of the handle to
5148 fit inside its rectangle, but if the user is dragging the scroll
5149 bar handle, we want to let them drag it down all the way, so that
5150 the bar's top is as far down as it goes; otherwise, there's no way
5151 to move to the very end of the buffer. */
5154 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
5155 struct scroll_bar
*bar
;
5159 int dragging
= ! NILP (bar
->dragging
);
5160 Window w
= bar
->x_window
;
5161 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5162 GC gc
= f
->output_data
.x
->normal_gc
;
5164 /* If the display is already accurate, do nothing. */
5166 && start
== bar
->start
5173 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5174 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5175 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5177 /* Make sure the values are reasonable, and try to preserve
5178 the distance between start and end. */
5180 int length
= end
- start
;
5184 else if (start
> top_range
)
5186 end
= start
+ length
;
5190 else if (end
> top_range
&& ! dragging
)
5194 /* Store the adjusted setting in the scroll bar. */
5198 /* Clip the end position, just for display. */
5199 if (end
> top_range
)
5202 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5203 below top positions, to make sure the handle is always at least
5204 that many pixels tall. */
5205 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5207 /* Draw the empty space above the handle. Note that we can't clear
5208 zero-height areas; that means "clear to end of window." */
5210 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5211 /* x, y, width, height, and exposures. */
5212 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5213 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5214 inside_width
, start
,
5217 /* Change to proper foreground color if one is specified. */
5218 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5219 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5220 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5222 /* Draw the handle itself. */
5223 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5224 /* x, y, width, height */
5225 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5226 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5227 inside_width
, end
- start
);
5229 /* Restore the foreground color of the GC if we changed it above. */
5230 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5231 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5232 FRAME_FOREGROUND_PIXEL (f
));
5234 /* Draw the empty space below the handle. Note that we can't
5235 clear zero-height areas; that means "clear to end of window." */
5236 if (end
< inside_height
)
5237 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5238 /* x, y, width, height, and exposures. */
5239 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5240 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5241 inside_width
, inside_height
- end
,
5249 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5251 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5255 x_scroll_bar_remove (bar
)
5256 struct scroll_bar
*bar
;
5258 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5261 #ifdef USE_TOOLKIT_SCROLL_BARS
5263 xg_remove_scroll_bar (f
, bar
->x_window
);
5264 #else /* not USE_GTK */
5265 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5266 #endif /* not USE_GTK */
5268 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5271 /* Disassociate this scroll bar from its window. */
5272 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
5278 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5279 that we are displaying PORTION characters out of a total of WHOLE
5280 characters, starting at POSITION. If WINDOW has no scroll bar,
5284 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
5286 int portion
, whole
, position
;
5288 struct frame
*f
= XFRAME (w
->frame
);
5289 struct scroll_bar
*bar
;
5290 int top
, height
, left
, sb_left
, width
, sb_width
;
5291 int window_y
, window_height
;
5292 #ifdef USE_TOOLKIT_SCROLL_BARS
5293 int fringe_extended_p
;
5296 /* Get window dimensions. */
5297 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
5299 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5300 height
= window_height
;
5302 /* Compute the left edge of the scroll bar area. */
5303 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5305 /* Compute the width of the scroll bar which might be less than
5306 the width of the area reserved for the scroll bar. */
5307 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5308 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5312 /* Compute the left edge of the scroll bar. */
5313 #ifdef USE_TOOLKIT_SCROLL_BARS
5314 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5315 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5317 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5319 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5320 sb_left
= left
+ width
- sb_width
;
5325 #ifdef USE_TOOLKIT_SCROLL_BARS
5326 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5327 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5328 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5329 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5330 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5332 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5333 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5334 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5335 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5338 /* Does the scroll bar exist yet? */
5339 if (NILP (w
->vertical_scroll_bar
))
5341 if (width
> 0 && height
> 0)
5344 #ifdef USE_TOOLKIT_SCROLL_BARS
5345 if (fringe_extended_p
)
5346 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5347 sb_left
, top
, sb_width
, height
, False
);
5350 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5351 left
, top
, width
, height
, False
);
5355 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5359 /* It may just need to be moved and resized. */
5360 unsigned int mask
= 0;
5362 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5366 if (sb_left
!= bar
->left
)
5368 if (top
!= bar
->top
)
5370 if (sb_width
!= bar
->width
)
5372 if (height
!= bar
->height
)
5375 #ifdef USE_TOOLKIT_SCROLL_BARS
5377 /* Move/size the scroll bar widget. */
5378 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5380 /* Since toolkit scroll bars are smaller than the space reserved
5381 for them on the frame, we have to clear "under" them. */
5382 if (width
> 0 && height
> 0)
5384 if (fringe_extended_p
)
5385 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5386 sb_left
, top
, sb_width
, height
, False
);
5388 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5389 left
, top
, width
, height
, False
);
5392 xg_update_scrollbar_pos (f
,
5395 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5396 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5398 #else /* not USE_GTK */
5399 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5400 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5402 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5403 max (height
, 1), 0);
5404 #endif /* not USE_GTK */
5406 #else /* not USE_TOOLKIT_SCROLL_BARS */
5408 /* Clear areas not covered by the scroll bar because of
5409 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5410 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5412 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5413 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5415 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5416 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5417 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5421 /* Clear areas not covered by the scroll bar because it's not as
5422 wide as the area reserved for it. This makes sure a
5423 previous mode line display is cleared after C-x 2 C-x 1, for
5426 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5427 int rest
= area_width
- sb_width
;
5428 if (rest
> 0 && height
> 0)
5430 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5431 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5432 left
+ area_width
- rest
, top
,
5433 rest
, height
, False
);
5435 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5436 left
, top
, rest
, height
, False
);
5440 /* Move/size the scroll bar window. */
5445 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5447 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5449 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5453 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5455 /* Remember new settings. */
5456 bar
->left
= sb_left
;
5458 bar
->width
= sb_width
;
5459 bar
->height
= height
;
5464 #ifdef USE_TOOLKIT_SCROLL_BARS
5465 bar
->fringe_extended_p
= fringe_extended_p
;
5467 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5468 #else /* not USE_TOOLKIT_SCROLL_BARS */
5469 /* Set the scroll bar's current state, unless we're currently being
5471 if (NILP (bar
->dragging
))
5473 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5476 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5479 int start
= ((double) position
* top_range
) / whole
;
5480 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5481 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5484 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5486 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5490 /* The following three hooks are used when we're doing a thorough
5491 redisplay of the frame. We don't explicitly know which scroll bars
5492 are going to be deleted, because keeping track of when windows go
5493 away is a real pain - "Can you say set-window-configuration, boys
5494 and girls?" Instead, we just assert at the beginning of redisplay
5495 that *all* scroll bars are to be removed, and then save a scroll bar
5496 from the fiery pit when we actually redisplay its window. */
5498 /* Arrange for all scroll bars on FRAME to be removed at the next call
5499 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5500 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5503 XTcondemn_scroll_bars (frame
)
5506 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5507 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5510 bar
= FRAME_SCROLL_BARS (frame
);
5511 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5512 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5513 XSCROLL_BAR (bar
)->prev
= Qnil
;
5514 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5515 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5516 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5521 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5522 Note that WINDOW isn't necessarily condemned at all. */
5525 XTredeem_scroll_bar (window
)
5526 struct window
*window
;
5528 struct scroll_bar
*bar
;
5531 /* We can't redeem this window's scroll bar if it doesn't have one. */
5532 if (NILP (window
->vertical_scroll_bar
))
5535 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5537 /* Unlink it from the condemned list. */
5538 f
= XFRAME (WINDOW_FRAME (window
));
5539 if (NILP (bar
->prev
))
5541 /* If the prev pointer is nil, it must be the first in one of
5543 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5544 /* It's not condemned. Everything's fine. */
5546 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5547 window
->vertical_scroll_bar
))
5548 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5550 /* If its prev pointer is nil, it must be at the front of
5551 one or the other! */
5555 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5557 if (! NILP (bar
->next
))
5558 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5560 bar
->next
= FRAME_SCROLL_BARS (f
);
5562 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5563 if (! NILP (bar
->next
))
5564 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5567 /* Remove all scroll bars on FRAME that haven't been saved since the
5568 last call to `*condemn_scroll_bars_hook'. */
5571 XTjudge_scroll_bars (f
)
5574 Lisp_Object bar
, next
;
5576 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5578 /* Clear out the condemned list now so we won't try to process any
5579 more events on the hapless scroll bars. */
5580 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5582 for (; ! NILP (bar
); bar
= next
)
5584 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5586 x_scroll_bar_remove (b
);
5589 b
->next
= b
->prev
= Qnil
;
5592 /* Now there should be no references to the condemned scroll bars,
5593 and they should get garbage-collected. */
5597 #ifndef USE_TOOLKIT_SCROLL_BARS
5598 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5599 is a no-op when using toolkit scroll bars.
5601 This may be called from a signal handler, so we have to ignore GC
5605 x_scroll_bar_expose (bar
, event
)
5606 struct scroll_bar
*bar
;
5609 Window w
= bar
->x_window
;
5610 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5611 GC gc
= f
->output_data
.x
->normal_gc
;
5612 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5616 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5618 /* Switch to scroll bar foreground color. */
5619 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5620 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5621 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5623 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5624 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5626 /* x, y, width, height */
5628 bar
->width
- 1 - width_trim
- width_trim
,
5631 /* Restore the foreground color of the GC if we changed it above. */
5632 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5633 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5634 FRAME_FOREGROUND_PIXEL (f
));
5639 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5641 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5642 is set to something other than NO_EVENT, it is enqueued.
5644 This may be called from a signal handler, so we have to ignore GC
5649 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5650 struct scroll_bar
*bar
;
5652 struct input_event
*emacs_event
;
5654 if (! WINDOWP (bar
->window
))
5657 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5658 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5659 emacs_event
->modifiers
5660 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5661 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5662 event
->xbutton
.state
)
5663 | (event
->type
== ButtonRelease
5666 emacs_event
->frame_or_window
= bar
->window
;
5667 emacs_event
->arg
= Qnil
;
5668 emacs_event
->timestamp
= event
->xbutton
.time
;
5671 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5673 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5676 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5677 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5680 if (y
> top_range
) y
= top_range
;
5683 emacs_event
->part
= scroll_bar_above_handle
;
5684 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5685 emacs_event
->part
= scroll_bar_handle
;
5687 emacs_event
->part
= scroll_bar_below_handle
;
5689 /* Just because the user has clicked on the handle doesn't mean
5690 they want to drag it. Lisp code needs to be able to decide
5691 whether or not we're dragging. */
5693 /* If the user has just clicked on the handle, record where they're
5695 if (event
->type
== ButtonPress
5696 && emacs_event
->part
== scroll_bar_handle
)
5697 XSETINT (bar
->dragging
, y
- bar
->start
);
5700 #ifndef USE_TOOLKIT_SCROLL_BARS
5701 /* If the user has released the handle, set it to its final position. */
5702 if (event
->type
== ButtonRelease
5703 && ! NILP (bar
->dragging
))
5705 int new_start
= y
- XINT (bar
->dragging
);
5706 int new_end
= new_start
+ bar
->end
- bar
->start
;
5708 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5709 bar
->dragging
= Qnil
;
5713 /* Same deal here as the other #if 0. */
5715 /* Clicks on the handle are always reported as occurring at the top of
5717 if (emacs_event
->part
== scroll_bar_handle
)
5718 emacs_event
->x
= bar
->start
;
5720 XSETINT (emacs_event
->x
, y
);
5722 XSETINT (emacs_event
->x
, y
);
5725 XSETINT (emacs_event
->y
, top_range
);
5729 #ifndef USE_TOOLKIT_SCROLL_BARS
5731 /* Handle some mouse motion while someone is dragging the scroll bar.
5733 This may be called from a signal handler, so we have to ignore GC
5737 x_scroll_bar_note_movement (bar
, event
)
5738 struct scroll_bar
*bar
;
5741 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5743 last_mouse_movement_time
= event
->xmotion
.time
;
5746 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5748 /* If we're dragging the bar, display it. */
5749 if (! NILP (bar
->dragging
))
5751 /* Where should the handle be now? */
5752 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5754 if (new_start
!= bar
->start
)
5756 int new_end
= new_start
+ bar
->end
- bar
->start
;
5758 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5763 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5765 /* Return information to the user about the current position of the mouse
5766 on the scroll bar. */
5769 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5771 Lisp_Object
*bar_window
;
5772 enum scroll_bar_part
*part
;
5774 unsigned long *time
;
5776 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5777 Window w
= bar
->x_window
;
5778 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5780 Window dummy_window
;
5782 unsigned int dummy_mask
;
5786 /* Get the mouse's position relative to the scroll bar window, and
5788 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5790 /* Root, child, root x and root y. */
5791 &dummy_window
, &dummy_window
,
5792 &dummy_coord
, &dummy_coord
,
5794 /* Position relative to scroll bar. */
5797 /* Mouse buttons and modifier keys. */
5804 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5807 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5809 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5811 if (! NILP (bar
->dragging
))
5812 win_y
-= XINT (bar
->dragging
);
5816 if (win_y
> top_range
)
5820 *bar_window
= bar
->window
;
5822 if (! NILP (bar
->dragging
))
5823 *part
= scroll_bar_handle
;
5824 else if (win_y
< bar
->start
)
5825 *part
= scroll_bar_above_handle
;
5826 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5827 *part
= scroll_bar_handle
;
5829 *part
= scroll_bar_below_handle
;
5831 XSETINT (*x
, win_y
);
5832 XSETINT (*y
, top_range
);
5835 last_mouse_scroll_bar
= Qnil
;
5838 *time
= last_mouse_movement_time
;
5844 /* The screen has been cleared so we may have changed foreground or
5845 background colors, and the scroll bars may need to be redrawn.
5846 Clear out the scroll bars, and ask for expose events, so we can
5850 x_scroll_bar_clear (f
)
5853 #ifndef USE_TOOLKIT_SCROLL_BARS
5856 /* We can have scroll bars even if this is 0,
5857 if we just turned off scroll bar mode.
5858 But in that case we should not clear them. */
5859 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5860 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5861 bar
= XSCROLL_BAR (bar
)->next
)
5862 XClearArea (FRAME_X_DISPLAY (f
),
5863 XSCROLL_BAR (bar
)->x_window
,
5865 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5869 /* The main X event-reading loop - XTread_socket. */
5872 /* Time stamp of enter window event. This is only used by XTread_socket,
5873 but we have to put it out here, since static variables within functions
5874 sometimes don't work. */
5876 static Time enter_timestamp
;
5879 /* This holds the state XLookupString needs to implement dead keys
5880 and other tricks known as "compose processing". _X Window System_
5881 says that a portable program can't use this, but Stephen Gildea assures
5882 me that letting the compiler initialize it to zeros will work okay.
5884 This must be defined outside of XTread_socket, for the same reasons
5885 given for enter_timestamp, above. */
5887 static XComposeStatus compose_status
;
5889 /* Record the last 100 characters stored
5890 to help debug the loss-of-chars-during-GC problem. */
5892 static int temp_index
;
5893 static short temp_buffer
[100];
5895 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5896 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5898 temp_buffer[temp_index++] = (keysym)
5900 /* Set this to nonzero to fake an "X I/O error"
5901 on a particular display. */
5903 struct x_display_info
*XTread_socket_fake_io_error
;
5905 /* When we find no input here, we occasionally do a no-op command
5906 to verify that the X server is still running and we can still talk with it.
5907 We try all the open displays, one by one.
5908 This variable is used for cycling thru the displays. */
5910 static struct x_display_info
*next_noop_dpyinfo
;
5912 #define SET_SAVED_MENU_EVENT(size) \
5915 if (f->output_data.x->saved_menu_event == 0) \
5916 f->output_data.x->saved_menu_event \
5917 = (XEvent *) xmalloc (sizeof (XEvent)); \
5918 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5919 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5920 XSETFRAME (inev.ie.frame_or_window, f); \
5924 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5925 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5935 /* Filter events for the current X input method.
5936 DPYINFO is the display this event is for.
5937 EVENT is the X event to filter.
5939 Returns non-zero if the event was filtered, caller shall not process
5941 Returns zero if event is wasn't filtered. */
5945 x_filter_event (dpyinfo
, event
)
5946 struct x_display_info
*dpyinfo
;
5949 /* XFilterEvent returns non-zero if the input method has
5950 consumed the event. We pass the frame's X window to
5951 XFilterEvent because that's the one for which the IC
5954 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5955 event
->xclient
.window
);
5957 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5962 static int current_count
;
5963 static int current_finish
;
5964 static struct input_event
*current_hold_quit
;
5966 /* This is the filter function invoked by the GTK event loop.
5967 It is invoked before the XEvent is translated to a GdkEvent,
5968 so we have a chance to act on the event before GTK. */
5969 static GdkFilterReturn
5970 event_handler_gdk (gxev
, ev
, data
)
5975 XEvent
*xev
= (XEvent
*) gxev
;
5977 if (current_count
>= 0)
5979 struct x_display_info
*dpyinfo
;
5981 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5984 /* Filter events for the current X input method.
5985 GTK calls XFilterEvent but not for key press and release,
5986 so we do it here. */
5987 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5988 if (dpyinfo
&& x_filter_event (dpyinfo
, xev
))
5989 return GDK_FILTER_REMOVE
;
5993 current_finish
= X_EVENT_NORMAL
;
5997 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
6002 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
6004 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
6005 return GDK_FILTER_REMOVE
;
6007 return GDK_FILTER_CONTINUE
;
6009 #endif /* USE_GTK */
6012 /* Handles the XEvent EVENT on display DPYINFO.
6014 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
6015 *FINISH is zero if caller should continue reading events.
6016 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
6018 We return the number of characters stored into the buffer. */
6021 handle_one_xevent (dpyinfo
, eventp
, finish
, hold_quit
)
6022 struct x_display_info
*dpyinfo
;
6025 struct input_event
*hold_quit
;
6028 struct input_event ie
;
6029 struct selection_input_event sie
;
6034 struct frame
*f
= NULL
;
6035 struct coding_system coding
;
6036 XEvent event
= *eventp
;
6038 *finish
= X_EVENT_NORMAL
;
6040 EVENT_INIT (inev
.ie
);
6041 inev
.ie
.kind
= NO_EVENT
;
6048 if (event
.xclient
.message_type
6049 == dpyinfo
->Xatom_wm_protocols
6050 && event
.xclient
.format
== 32)
6052 if (event
.xclient
.data
.l
[0]
6053 == dpyinfo
->Xatom_wm_take_focus
)
6055 /* Use x_any_window_to_frame because this
6056 could be the shell widget window
6057 if the frame has no title bar. */
6058 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6060 /* Not quite sure this is needed -pd */
6061 if (f
&& FRAME_XIC (f
))
6062 XSetICFocus (FRAME_XIC (f
));
6064 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
6065 instructs the WM to set the input focus automatically for
6066 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
6067 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
6068 it has set the focus. So, XSetInputFocus below is not
6071 The call to XSetInputFocus below has also caused trouble. In
6072 cases where the XSetInputFocus done by the WM and the one
6073 below are temporally close (on a fast machine), the call
6074 below can generate additional FocusIn events which confuse
6077 /* Since we set WM_TAKE_FOCUS, we must call
6078 XSetInputFocus explicitly. But not if f is null,
6079 since that might be an event for a deleted frame. */
6082 Display
*d
= event
.xclient
.display
;
6083 /* Catch and ignore errors, in case window has been
6084 iconified by a window manager such as GWM. */
6086 XSetInputFocus (d
, event
.xclient
.window
,
6087 /* The ICCCM says this is
6088 the only valid choice. */
6090 event
.xclient
.data
.l
[1]);
6091 /* This is needed to detect the error
6092 if there is an error. */
6094 x_uncatch_errors ();
6096 /* Not certain about handling scroll bars here */
6101 if (event
.xclient
.data
.l
[0]
6102 == dpyinfo
->Xatom_wm_save_yourself
)
6104 /* Save state modify the WM_COMMAND property to
6105 something which can reinstate us. This notifies
6106 the session manager, who's looking for such a
6107 PropertyNotify. Can restart processing when
6108 a keyboard or mouse event arrives. */
6109 /* If we have a session manager, don't set this.
6110 KDE will then start two Emacsen, one for the
6111 session manager and one for this. */
6113 if (! x_session_have_connection ())
6116 f
= x_top_window_to_frame (dpyinfo
,
6117 event
.xclient
.window
);
6118 /* This is just so we only give real data once
6119 for a single Emacs process. */
6120 if (f
== SELECTED_FRAME ())
6121 XSetCommand (FRAME_X_DISPLAY (f
),
6122 event
.xclient
.window
,
6123 initial_argv
, initial_argc
);
6125 XSetCommand (FRAME_X_DISPLAY (f
),
6126 event
.xclient
.window
,
6132 if (event
.xclient
.data
.l
[0]
6133 == dpyinfo
->Xatom_wm_delete_window
)
6135 f
= x_any_window_to_frame (dpyinfo
,
6136 event
.xclient
.window
);
6138 goto OTHER
; /* May be a dialog that is to be removed */
6140 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
6141 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6148 if (event
.xclient
.message_type
6149 == dpyinfo
->Xatom_wm_configure_denied
)
6154 if (event
.xclient
.message_type
6155 == dpyinfo
->Xatom_wm_window_moved
)
6158 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6160 new_x
= event
.xclient
.data
.s
[0];
6161 new_y
= event
.xclient
.data
.s
[1];
6165 f
->left_pos
= new_x
;
6172 if (event
.xclient
.message_type
6173 == dpyinfo
->Xatom_editres
)
6175 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6177 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
6181 #endif /* HACK_EDITRES */
6183 if ((event
.xclient
.message_type
6184 == dpyinfo
->Xatom_DONE
)
6185 || (event
.xclient
.message_type
6186 == dpyinfo
->Xatom_PAGE
))
6188 /* Ghostview job completed. Kill it. We could
6189 reply with "Next" if we received "Page", but we
6190 currently never do because we are interested in
6191 images, only, which should have 1 page. */
6192 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
6193 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6196 x_kill_gs_process (pixmap
, f
);
6197 expose_frame (f
, 0, 0, 0, 0);
6201 #ifdef USE_TOOLKIT_SCROLL_BARS
6202 /* Scroll bar callbacks send a ClientMessage from which
6203 we construct an input_event. */
6204 if (event
.xclient
.message_type
6205 == dpyinfo
->Xatom_Scrollbar
)
6207 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
6208 *finish
= X_EVENT_GOTO_OUT
;
6211 #endif /* USE_TOOLKIT_SCROLL_BARS */
6213 /* XEmbed messages from the embedder (if any). */
6214 if (event
.xclient
.message_type
6215 == dpyinfo
->Xatom_XEMBED
)
6217 enum xembed_message msg
= event
.xclient
.data
.l
[1];
6218 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6219 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6221 *finish
= X_EVENT_GOTO_OUT
;
6225 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6228 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6229 *finish
= X_EVENT_DROP
;
6233 case SelectionNotify
:
6234 last_user_time
= event
.xselection
.time
;
6235 #ifdef USE_X_TOOLKIT
6236 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6238 #endif /* not USE_X_TOOLKIT */
6239 x_handle_selection_notify (&event
.xselection
);
6242 case SelectionClear
: /* Someone has grabbed ownership. */
6243 last_user_time
= event
.xselectionclear
.time
;
6244 #ifdef USE_X_TOOLKIT
6245 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6247 #endif /* USE_X_TOOLKIT */
6249 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
6251 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6252 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6253 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6254 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6255 inev
.ie
.frame_or_window
= Qnil
;
6259 case SelectionRequest
: /* Someone wants our selection. */
6260 last_user_time
= event
.xselectionrequest
.time
;
6261 #ifdef USE_X_TOOLKIT
6262 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6264 #endif /* USE_X_TOOLKIT */
6266 XSelectionRequestEvent
*eventp
6267 = (XSelectionRequestEvent
*) &event
;
6269 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6270 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6271 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6272 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6273 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6274 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6275 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6276 inev
.ie
.frame_or_window
= Qnil
;
6280 case PropertyNotify
:
6281 last_user_time
= event
.xproperty
.time
;
6282 #if 0 /* This is plain wrong. In the case that we are waiting for a
6283 PropertyNotify used as an ACK in incremental selection
6284 transfer, the property will be on the receiver's window. */
6285 #if defined USE_X_TOOLKIT
6286 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
6290 x_handle_property_notify (&event
.xproperty
);
6293 case ReparentNotify
:
6294 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6298 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6299 x_real_positions (f
, &x
, &y
);
6303 /* Perhaps reparented due to a WM restart. Reset this. */
6304 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6305 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
6310 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6313 x_check_fullscreen (f
);
6316 /* This seems to be needed for GTK 2.6. */
6317 x_clear_area (event
.xexpose
.display
,
6318 event
.xexpose
.window
,
6319 event
.xexpose
.x
, event
.xexpose
.y
,
6320 event
.xexpose
.width
, event
.xexpose
.height
,
6323 if (f
->async_visible
== 0)
6325 f
->async_visible
= 1;
6326 f
->async_iconified
= 0;
6327 f
->output_data
.x
->has_been_visible
= 1;
6328 SET_FRAME_GARBAGED (f
);
6332 event
.xexpose
.x
, event
.xexpose
.y
,
6333 event
.xexpose
.width
, event
.xexpose
.height
);
6337 #ifndef USE_TOOLKIT_SCROLL_BARS
6338 struct scroll_bar
*bar
;
6340 #if defined USE_LUCID
6341 /* Submenus of the Lucid menu bar aren't widgets
6342 themselves, so there's no way to dispatch events
6343 to them. Recognize this case separately. */
6346 = x_window_to_menu_bar (event
.xexpose
.window
);
6348 xlwmenu_redisplay (widget
);
6350 #endif /* USE_LUCID */
6352 #ifdef USE_TOOLKIT_SCROLL_BARS
6353 /* Dispatch event to the widget. */
6355 #else /* not USE_TOOLKIT_SCROLL_BARS */
6356 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6357 event
.xexpose
.window
);
6360 x_scroll_bar_expose (bar
, &event
);
6361 #ifdef USE_X_TOOLKIT
6364 #endif /* USE_X_TOOLKIT */
6365 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6369 case GraphicsExpose
: /* This occurs when an XCopyArea's
6370 source area was obscured or not
6372 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6376 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6377 event
.xgraphicsexpose
.width
,
6378 event
.xgraphicsexpose
.height
);
6380 #ifdef USE_X_TOOLKIT
6383 #endif /* USE_X_TOOLKIT */
6386 case NoExpose
: /* This occurs when an XCopyArea's
6387 source area was completely
6392 /* Redo the mouse-highlight after the tooltip has gone. */
6393 if (event
.xmap
.window
== tip_window
)
6396 redo_mouse_highlight ();
6399 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6400 if (f
) /* F may no longer exist if
6401 the frame was deleted. */
6403 /* While a frame is unmapped, display generation is
6404 disabled; you don't want to spend time updating a
6405 display that won't ever be seen. */
6406 f
->async_visible
= 0;
6407 /* We can't distinguish, from the event, whether the window
6408 has become iconified or invisible. So assume, if it
6409 was previously visible, than now it is iconified.
6410 But x_make_frame_invisible clears both
6411 the visible flag and the iconified flag;
6412 and that way, we know the window is not iconified now. */
6413 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6415 f
->async_iconified
= 1;
6417 inev
.ie
.kind
= ICONIFY_EVENT
;
6418 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6424 if (event
.xmap
.window
== tip_window
)
6425 /* The tooltip has been drawn already. Avoid
6426 the SET_FRAME_GARBAGED below. */
6429 /* We use x_top_window_to_frame because map events can
6430 come for sub-windows and they don't mean that the
6431 frame is visible. */
6432 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6435 /* wait_reading_process_output will notice this and update
6436 the frame's display structures.
6437 If we where iconified, we should not set garbaged,
6438 because that stops redrawing on Expose events. This looks
6439 bad if we are called from a recursive event loop
6440 (x_dispatch_event), for example when a dialog is up. */
6441 if (! f
->async_iconified
)
6442 SET_FRAME_GARBAGED (f
);
6444 f
->async_visible
= 1;
6445 f
->async_iconified
= 0;
6446 f
->output_data
.x
->has_been_visible
= 1;
6450 inev
.ie
.kind
= DEICONIFY_EVENT
;
6451 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6453 else if (! NILP (Vframe_list
)
6454 && ! NILP (XCDR (Vframe_list
)))
6455 /* Force a redisplay sooner or later
6456 to update the frame titles
6457 in case this is the second frame. */
6458 record_asynch_buffer_change ();
6464 last_user_time
= event
.xkey
.time
;
6465 ignore_next_mouse_click_timeout
= 0;
6467 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6468 /* Dispatch KeyPress events when in menu. */
6469 if (popup_activated ())
6473 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6475 /* If mouse-highlight is an integer, input clears out
6476 mouse highlighting. */
6477 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6479 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6481 clear_mouse_face (dpyinfo
);
6482 dpyinfo
->mouse_face_hidden
= 1;
6485 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6488 /* Scroll bars consume key events, but we want
6489 the keys to go to the scroll bar's frame. */
6490 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6492 if (widget
&& XmIsScrollBar (widget
))
6494 widget
= XtParent (widget
);
6495 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6498 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6502 KeySym keysym
, orig_keysym
;
6503 /* al%imercury@uunet.uu.net says that making this 81
6504 instead of 80 fixed a bug whereby meta chars made
6507 It seems that some version of XmbLookupString has
6508 a bug of not returning XBufferOverflow in
6509 status_return even if the input is too long to
6510 fit in 81 bytes. So, we must prepare sufficient
6511 bytes for copy_buffer. 513 bytes (256 chars for
6512 two-byte character set) seems to be a fairly good
6513 approximation. -- 2000.8.10 handa@etl.go.jp */
6514 unsigned char copy_buffer
[513];
6515 unsigned char *copy_bufptr
= copy_buffer
;
6516 int copy_bufsiz
= sizeof (copy_buffer
);
6518 Lisp_Object coding_system
= Qlatin_1
;
6522 /* Don't pass keys to GTK. A Tab will shift focus to the
6523 tool bar in GTK 2.4. Keys will still go to menus and
6524 dialogs because in that case popup_activated is TRUE
6526 *finish
= X_EVENT_DROP
;
6530 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6531 extra_keyboard_modifiers
);
6532 modifiers
= event
.xkey
.state
;
6534 /* This will have to go some day... */
6536 /* make_lispy_event turns chars into control chars.
6537 Don't do it here because XLookupString is too eager. */
6538 event
.xkey
.state
&= ~ControlMask
;
6539 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6540 | dpyinfo
->super_mod_mask
6541 | dpyinfo
->hyper_mod_mask
6542 | dpyinfo
->alt_mod_mask
);
6544 /* In case Meta is ComposeCharacter,
6545 clear its status. According to Markus Ehrnsperger
6546 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6547 this enables ComposeCharacter to work whether or
6548 not it is combined with Meta. */
6549 if (modifiers
& dpyinfo
->meta_mod_mask
)
6550 bzero (&compose_status
, sizeof (compose_status
));
6555 Status status_return
;
6557 coding_system
= Vlocale_coding_system
;
6558 nbytes
= XmbLookupString (FRAME_XIC (f
),
6559 &event
.xkey
, copy_bufptr
,
6560 copy_bufsiz
, &keysym
,
6562 if (status_return
== XBufferOverflow
)
6564 copy_bufsiz
= nbytes
+ 1;
6565 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6566 nbytes
= XmbLookupString (FRAME_XIC (f
),
6567 &event
.xkey
, copy_bufptr
,
6568 copy_bufsiz
, &keysym
,
6571 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6572 #if 0 && defined X_HAVE_UTF8_STRING
6573 else if (status_return
== XLookupKeySym
)
6574 { /* Try again but with utf-8. */
6575 coding_system
= Qutf_8
;
6576 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6577 &event
.xkey
, copy_bufptr
,
6578 copy_bufsiz
, &keysym
,
6580 if (status_return
== XBufferOverflow
)
6582 copy_bufsiz
= nbytes
+ 1;
6583 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6584 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6587 copy_bufsiz
, &keysym
,
6593 if (status_return
== XLookupNone
)
6595 else if (status_return
== XLookupChars
)
6600 else if (status_return
!= XLookupKeySym
6601 && status_return
!= XLookupBoth
)
6605 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6606 copy_bufsiz
, &keysym
,
6609 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6610 copy_bufsiz
, &keysym
,
6614 /* If not using XIM/XIC, and a compose sequence is in progress,
6615 we break here. Otherwise, chars_matched is always 0. */
6616 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6619 bzero (&compose_status
, sizeof (compose_status
));
6620 orig_keysym
= keysym
;
6622 /* Common for all keysym input events. */
6623 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6625 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6626 inev
.ie
.timestamp
= event
.xkey
.time
;
6628 /* First deal with keysyms which have defined
6629 translations to characters. */
6630 if (keysym
>= 32 && keysym
< 128)
6631 /* Avoid explicitly decoding each ASCII character. */
6633 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6634 inev
.ie
.code
= keysym
;
6638 /* Keysyms directly mapped to Unicode characters. */
6639 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6641 if (keysym
< 0x01000080)
6642 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6644 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6645 inev
.ie
.code
= keysym
& 0xFFFFFF;
6649 /* Now non-ASCII. */
6650 if (HASH_TABLE_P (Vx_keysym_table
)
6651 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6655 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6656 ? ASCII_KEYSTROKE_EVENT
6657 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6658 inev
.ie
.code
= XFASTINT (c
);
6662 /* Random non-modifier sorts of keysyms. */
6663 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6664 || keysym
== XK_Delete
6665 #ifdef XK_ISO_Left_Tab
6666 || (keysym
>= XK_ISO_Left_Tab
6667 && keysym
<= XK_ISO_Enter
)
6669 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6670 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6672 /* This recognizes the "extended function
6673 keys". It seems there's no cleaner way.
6674 Test IsModifierKey to avoid handling
6675 mode_switch incorrectly. */
6676 || ((unsigned) (keysym
) >= XK_Select
6677 && (unsigned)(keysym
) < XK_KP_Space
)
6679 #ifdef XK_dead_circumflex
6680 || orig_keysym
== XK_dead_circumflex
6682 #ifdef XK_dead_grave
6683 || orig_keysym
== XK_dead_grave
6685 #ifdef XK_dead_tilde
6686 || orig_keysym
== XK_dead_tilde
6688 #ifdef XK_dead_diaeresis
6689 || orig_keysym
== XK_dead_diaeresis
6691 #ifdef XK_dead_macron
6692 || orig_keysym
== XK_dead_macron
6694 #ifdef XK_dead_degree
6695 || orig_keysym
== XK_dead_degree
6697 #ifdef XK_dead_acute
6698 || orig_keysym
== XK_dead_acute
6700 #ifdef XK_dead_cedilla
6701 || orig_keysym
== XK_dead_cedilla
6703 #ifdef XK_dead_breve
6704 || orig_keysym
== XK_dead_breve
6706 #ifdef XK_dead_ogonek
6707 || orig_keysym
== XK_dead_ogonek
6709 #ifdef XK_dead_caron
6710 || orig_keysym
== XK_dead_caron
6712 #ifdef XK_dead_doubleacute
6713 || orig_keysym
== XK_dead_doubleacute
6715 #ifdef XK_dead_abovedot
6716 || orig_keysym
== XK_dead_abovedot
6718 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6719 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6720 /* Any "vendor-specific" key is ok. */
6721 || (orig_keysym
& (1 << 28))
6722 || (keysym
!= NoSymbol
&& nbytes
== 0))
6723 && ! (IsModifierKey (orig_keysym
)
6724 /* The symbols from XK_ISO_Lock
6725 to XK_ISO_Last_Group_Lock
6726 don't have real modifiers but
6727 should be treated similarly to
6728 Mode_switch by Emacs. */
6729 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6730 || ((unsigned)(orig_keysym
)
6732 && (unsigned)(orig_keysym
)
6733 <= XK_ISO_Last_Group_Lock
)
6737 STORE_KEYSYM_FOR_DEBUG (keysym
);
6738 /* make_lispy_event will convert this to a symbolic
6740 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6741 inev
.ie
.code
= keysym
;
6745 { /* Raw bytes, not keysym. */
6750 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6752 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6754 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6757 if (nchars
< nbytes
)
6759 /* Decode the input data. */
6763 /* The input should be decoded with `coding_system'
6764 which depends on which X*LookupString function
6765 we used just above and the locale. */
6766 setup_coding_system (coding_system
, &coding
);
6767 coding
.src_multibyte
= 0;
6768 coding
.dst_multibyte
= 1;
6769 /* The input is converted to events, thus we can't
6770 handle composition. Anyway, there's no XIM that
6771 gives us composition information. */
6772 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6774 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6775 coding
.destination
= alloca (require
);
6776 coding
.dst_bytes
= require
;
6777 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6778 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6779 nbytes
= coding
.produced
;
6780 nchars
= coding
.produced_char
;
6781 copy_bufptr
= coding
.destination
;
6784 /* Convert the input data to a sequence of
6785 character events. */
6786 for (i
= 0; i
< nbytes
; i
+= len
)
6788 if (nchars
== nbytes
)
6789 c
= copy_bufptr
[i
], len
= 1;
6791 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6793 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6794 ? ASCII_KEYSTROKE_EVENT
6795 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6797 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6802 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6804 if (keysym
== NoSymbol
)
6810 /* Don't dispatch this event since XtDispatchEvent calls
6811 XFilterEvent, and two calls in a row may freeze the
6819 last_user_time
= event
.xkey
.time
;
6821 /* Don't dispatch this event since XtDispatchEvent calls
6822 XFilterEvent, and two calls in a row may freeze the
6830 last_user_time
= event
.xcrossing
.time
;
6831 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6833 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6835 if (f
&& x_mouse_click_focus_ignore_position
)
6836 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6839 if (event
.xcrossing
.focus
)
6841 /* Avoid nasty pop/raise loops. */
6842 if (f
&& (!(f
->auto_raise
)
6844 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6846 x_new_focus_frame (dpyinfo
, f
);
6847 enter_timestamp
= event
.xcrossing
.time
;
6850 else if (f
== dpyinfo
->x_focus_frame
)
6851 x_new_focus_frame (dpyinfo
, 0);
6854 /* EnterNotify counts as mouse movement,
6855 so update things that depend on mouse position. */
6856 if (f
&& !f
->output_data
.x
->hourglass_p
)
6857 note_mouse_movement (f
, &event
.xmotion
);
6859 /* We may get an EnterNotify on the buttons in the toolbar. In that
6860 case we moved out of any highlighted area and need to note this. */
6861 if (!f
&& last_mouse_glyph_frame
)
6862 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6867 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6871 last_user_time
= event
.xcrossing
.time
;
6872 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6874 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6877 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6879 /* If we move outside the frame, then we're
6880 certainly no longer on any text in the frame. */
6881 clear_mouse_face (dpyinfo
);
6882 dpyinfo
->mouse_face_mouse_frame
= 0;
6885 /* Generate a nil HELP_EVENT to cancel a help-echo.
6886 Do it only if there's something to cancel.
6887 Otherwise, the startup message is cleared when
6888 the mouse leaves the frame. */
6889 if (any_help_event_p
)
6893 /* See comment in EnterNotify above */
6894 else if (last_mouse_glyph_frame
)
6895 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6900 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6905 last_user_time
= event
.xmotion
.time
;
6906 previous_help_echo_string
= help_echo_string
;
6907 help_echo_string
= Qnil
;
6909 if (dpyinfo
->grabbed
&& last_mouse_frame
6910 && FRAME_LIVE_P (last_mouse_frame
))
6911 f
= last_mouse_frame
;
6913 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6915 if (dpyinfo
->mouse_face_hidden
)
6917 dpyinfo
->mouse_face_hidden
= 0;
6918 clear_mouse_face (dpyinfo
);
6924 /* Generate SELECT_WINDOW_EVENTs when needed. */
6925 if (!NILP (Vmouse_autoselect_window
))
6929 window
= window_from_coordinates (f
,
6930 event
.xmotion
.x
, event
.xmotion
.y
,
6933 /* Window will be selected only when it is not selected now and
6934 last mouse movement event was not in it. Minibuffer window
6935 will be selected only when it is active. */
6936 if (WINDOWP (window
)
6937 && !EQ (window
, last_window
)
6938 && !EQ (window
, selected_window
)
6939 /* For click-to-focus window managers
6940 create event iff we don't leave the
6942 && (focus_follows_mouse
6943 || (EQ (XWINDOW (window
)->frame
,
6944 XWINDOW (selected_window
)->frame
))))
6946 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6947 inev
.ie
.frame_or_window
= window
;
6952 if (!note_mouse_movement (f
, &event
.xmotion
))
6953 help_echo_string
= previous_help_echo_string
;
6957 #ifndef USE_TOOLKIT_SCROLL_BARS
6958 struct scroll_bar
*bar
6959 = x_window_to_scroll_bar (event
.xmotion
.display
,
6960 event
.xmotion
.window
);
6963 x_scroll_bar_note_movement (bar
, &event
);
6964 #endif /* USE_TOOLKIT_SCROLL_BARS */
6966 /* If we move outside the frame, then we're
6967 certainly no longer on any text in the frame. */
6968 clear_mouse_face (dpyinfo
);
6971 /* If the contents of the global variable help_echo_string
6972 has changed, generate a HELP_EVENT. */
6973 if (!NILP (help_echo_string
)
6974 || !NILP (previous_help_echo_string
))
6979 case ConfigureNotify
:
6980 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6983 #ifndef USE_X_TOOLKIT
6985 xg_resize_widgets (f
, event
.xconfigure
.width
,
6986 event
.xconfigure
.height
);
6987 #else /* not USE_GTK */
6988 /* If there is a pending resize for fullscreen, don't
6989 do this one, the right one will come later.
6990 The toolkit version doesn't seem to need this, but we
6991 need to reset it below. */
6993 = ((f
->want_fullscreen
& FULLSCREEN_WAIT
)
6994 && f
->new_text_cols
!= 0);
6995 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6996 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
7001 /* In the toolkit version, change_frame_size
7002 is called by the code that handles resizing
7003 of the EmacsFrame widget. */
7005 /* Even if the number of character rows and columns has
7006 not changed, the font size may have changed, so we need
7007 to check the pixel dimensions as well. */
7008 if (columns
!= FRAME_COLS (f
)
7009 || rows
!= FRAME_LINES (f
)
7010 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
7011 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
7013 change_frame_size (f
, rows
, columns
, 0, 1, 0);
7014 SET_FRAME_GARBAGED (f
);
7015 cancel_mouse_face (f
);
7017 #endif /* not USE_GTK */
7020 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
7021 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
7024 /* GTK creates windows but doesn't map them.
7025 Only get real positions and check fullscreen when mapped. */
7026 if (FRAME_GTK_OUTER_WIDGET (f
)
7027 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
7030 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
7032 if (f
->want_fullscreen
& FULLSCREEN_WAIT
)
7033 f
->want_fullscreen
&= ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
7037 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
7038 xic_set_statusarea (f
);
7041 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
7043 /* Since the WM decorations come below top_pos now,
7044 we must put them below top_pos in the future. */
7045 f
->win_gravity
= NorthWestGravity
;
7046 x_wm_set_size_hint (f
, (long) 0, 0);
7054 /* If we decide we want to generate an event to be seen
7055 by the rest of Emacs, we put it here. */
7058 bzero (&compose_status
, sizeof (compose_status
));
7059 last_mouse_glyph_frame
= 0;
7060 last_user_time
= event
.xbutton
.time
;
7062 if (dpyinfo
->grabbed
7064 && FRAME_LIVE_P (last_mouse_frame
))
7065 f
= last_mouse_frame
;
7067 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
7071 /* Is this in the tool-bar? */
7072 if (WINDOWP (f
->tool_bar_window
)
7073 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
7076 int x
= event
.xbutton
.x
;
7077 int y
= event
.xbutton
.y
;
7079 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
7080 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
7082 if (tool_bar_p
&& event
.xbutton
.button
< 4)
7084 handle_tool_bar_click (f
, x
, y
,
7085 event
.xbutton
.type
== ButtonPress
,
7086 x_x_to_emacs_modifiers (dpyinfo
,
7087 event
.xbutton
.state
));
7092 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7093 if (! popup_activated ())
7096 if (ignore_next_mouse_click_timeout
)
7098 if (event
.type
== ButtonPress
7099 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
7101 ignore_next_mouse_click_timeout
= 0;
7102 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
7104 if (event
.type
== ButtonRelease
)
7105 ignore_next_mouse_click_timeout
= 0;
7108 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
7110 if (FRAME_X_EMBEDDED_P (f
))
7111 xembed_send_message (f
, event
.xbutton
.time
,
7112 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
7116 struct scroll_bar
*bar
7117 = x_window_to_scroll_bar (event
.xbutton
.display
,
7118 event
.xbutton
.window
);
7120 #ifdef USE_TOOLKIT_SCROLL_BARS
7121 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
7123 if (bar
&& event
.xbutton
.state
& ControlMask
)
7125 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
7126 *finish
= X_EVENT_DROP
;
7128 #else /* not USE_TOOLKIT_SCROLL_BARS */
7130 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
7131 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7134 if (event
.type
== ButtonPress
)
7136 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
7137 last_mouse_frame
= f
;
7140 last_tool_bar_item
= -1;
7143 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
7145 /* Ignore any mouse motion that happened before this event;
7146 any subsequent mouse-movement Emacs events should reflect
7147 only motion after the ButtonPress/Release. */
7151 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7152 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
7153 /* For a down-event in the menu bar,
7154 don't pass it to Xt right now.
7155 Instead, save it away
7156 and we will pass it to Xt from kbd_buffer_get_event.
7157 That way, we can run some Lisp code first. */
7160 ! popup_activated ()
7163 f
&& event
.type
== ButtonPress
7164 /* Verify the event is really within the menu bar
7165 and not just sent to it due to grabbing. */
7166 && event
.xbutton
.x
>= 0
7167 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
7168 && event
.xbutton
.y
>= 0
7169 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
7170 && event
.xbutton
.same_screen
)
7172 SET_SAVED_BUTTON_EVENT
;
7173 XSETFRAME (last_mouse_press_frame
, f
);
7175 *finish
= X_EVENT_DROP
;
7178 else if (event
.type
== ButtonPress
)
7180 last_mouse_press_frame
= Qnil
;
7184 #ifdef USE_MOTIF /* This should do not harm for Lucid,
7185 but I am trying to be cautious. */
7186 else if (event
.type
== ButtonRelease
)
7188 if (!NILP (last_mouse_press_frame
))
7190 f
= XFRAME (last_mouse_press_frame
);
7191 if (f
->output_data
.x
)
7192 SET_SAVED_BUTTON_EVENT
;
7197 #endif /* USE_MOTIF */
7200 #endif /* USE_X_TOOLKIT || USE_GTK */
7204 case CirculateNotify
:
7207 case CirculateRequest
:
7210 case VisibilityNotify
:
7214 /* Someone has changed the keyboard mapping - update the
7216 switch (event
.xmapping
.request
)
7218 case MappingModifier
:
7219 x_find_modifier_meanings (dpyinfo
);
7220 /* This is meant to fall through. */
7221 case MappingKeyboard
:
7222 XRefreshKeyboardMapping (&event
.xmapping
);
7228 #ifdef USE_X_TOOLKIT
7230 if (*finish
!= X_EVENT_DROP
)
7231 XtDispatchEvent (&event
);
7233 #endif /* USE_X_TOOLKIT */
7238 if (inev
.ie
.kind
!= NO_EVENT
)
7240 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7245 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7250 XSETFRAME (frame
, f
);
7256 any_help_event_p
= 1;
7257 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7258 help_echo_object
, help_echo_pos
);
7262 help_echo_string
= Qnil
;
7263 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7273 /* Handles the XEvent EVENT on display DISPLAY.
7274 This is used for event loops outside the normal event handling,
7275 i.e. looping while a popup menu or a dialog is posted.
7277 Returns the value handle_one_xevent sets in the finish argument. */
7279 x_dispatch_event (event
, display
)
7283 struct x_display_info
*dpyinfo
;
7284 int finish
= X_EVENT_NORMAL
;
7286 dpyinfo
= x_display_info_for_display (display
);
7289 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7295 /* Read events coming from the X server.
7296 This routine is called by the SIGIO handler.
7297 We return as soon as there are no more events to be read.
7299 We return the number of characters stored into the buffer,
7300 thus pretending to be `read' (except the characters we store
7301 in the keyboard buffer can be multibyte, so are not necessarily
7304 EXPECTED is nonzero if the caller knows input is available. */
7307 XTread_socket (terminal
, expected
, hold_quit
)
7308 struct terminal
*terminal
;
7310 struct input_event
*hold_quit
;
7314 int event_found
= 0;
7315 struct x_display_info
*dpyinfo
;
7317 if (interrupt_input_blocked
)
7319 interrupt_input_pending
= 1;
7323 interrupt_input_pending
= 0;
7326 /* So people can tell when we have read the available input. */
7327 input_signal_count
++;
7332 /* Only check session manager input for the primary display. */
7333 if (terminal
->id
== 1 && x_session_have_connection ())
7335 struct input_event inev
;
7337 /* We don't need to EVENT_INIT (inev) here, as
7338 x_session_check_input copies an entire input_event. */
7339 if (x_session_check_input (&inev
))
7341 kbd_buffer_store_event_hold (&inev
, hold_quit
);
7348 /* For debugging, this gives a way to fake an I/O error. */
7349 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7351 XTread_socket_fake_io_error
= 0;
7352 x_io_error_quitter (dpyinfo
->display
);
7355 #if 0 /* This loop is a noop now. */
7356 /* Find the display we are supposed to read input for.
7357 It's the one communicating on descriptor SD. */
7358 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7360 #if 0 /* This ought to be unnecessary; let's verify it. */
7362 /* If available, Xlib uses FIOSNBIO to make the socket
7363 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
7364 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
7365 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
7366 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
7367 #endif /* ! defined (FIOSNBIO) */
7370 #if 0 /* This code can't be made to work, with multiple displays,
7371 and appears not to be used on any system any more.
7372 Also keyboard.c doesn't turn O_NDELAY on and off
7373 for X connections. */
7376 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7378 extern int read_alarm_should_throw
;
7379 read_alarm_should_throw
= 1;
7380 XPeekEvent (dpyinfo
->display
, &event
);
7381 read_alarm_should_throw
= 0;
7383 #endif /* HAVE_SELECT */
7390 while (XPending (terminal
->display_info
.x
->display
))
7394 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7397 /* Filter events for the current X input method. */
7398 if (x_filter_event (terminal
->display_info
.x
, &event
))
7403 count
+= handle_one_xevent (terminal
->display_info
.x
,
7404 &event
, &finish
, hold_quit
);
7406 if (finish
== X_EVENT_GOTO_OUT
)
7412 /* For GTK we must use the GTK event loop. But XEvents gets passed
7413 to our filter function above, and then to the big event switch.
7414 We use a bunch of globals to communicate with our filter function,
7415 that is kind of ugly, but it works.
7417 There is no way to do one display at the time, GTK just does events
7418 from all displays. */
7420 while (gtk_events_pending ())
7422 current_count
= count
;
7423 current_hold_quit
= hold_quit
;
7425 gtk_main_iteration ();
7427 count
= current_count
;
7429 current_hold_quit
= 0;
7431 if (current_finish
== X_EVENT_GOTO_OUT
)
7434 #endif /* USE_GTK */
7438 /* On some systems, an X bug causes Emacs to get no more events
7439 when the window is destroyed. Detect that. (1994.) */
7442 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7443 One XNOOP in 100 loops will make Emacs terminate.
7444 B. Bretthauer, 1994 */
7446 if (x_noop_count
>= 100)
7450 if (next_noop_dpyinfo
== 0)
7451 next_noop_dpyinfo
= x_display_list
;
7453 XNoOp (next_noop_dpyinfo
->display
);
7455 /* Each time we get here, cycle through the displays now open. */
7456 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7460 /* If the focus was just given to an auto-raising frame,
7462 /* ??? This ought to be able to handle more than one such frame. */
7463 if (pending_autoraise_frame
)
7465 x_raise_frame (pending_autoraise_frame
);
7466 pending_autoraise_frame
= 0;
7478 /***********************************************************************
7480 ***********************************************************************/
7482 /* Set clipping for output in glyph row ROW. W is the window in which
7483 we operate. GC is the graphics context to set clipping in.
7485 ROW may be a text row or, e.g., a mode line. Text rows must be
7486 clipped to the interior of the window dedicated to text display,
7487 mode lines must be clipped to the whole window. */
7490 x_clip_to_row (w
, row
, area
, gc
)
7492 struct glyph_row
*row
;
7496 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7497 XRectangle clip_rect
;
7498 int window_x
, window_y
, window_width
;
7500 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7502 clip_rect
.x
= window_x
;
7503 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7504 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7505 clip_rect
.width
= window_width
;
7506 clip_rect
.height
= row
->visible_height
;
7508 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7512 /* Draw a hollow box cursor on window W in glyph row ROW. */
7515 x_draw_hollow_cursor (w
, row
)
7517 struct glyph_row
*row
;
7519 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7520 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7521 Display
*dpy
= FRAME_X_DISPLAY (f
);
7524 struct glyph
*cursor_glyph
;
7527 /* Get the glyph the cursor is on. If we can't tell because
7528 the current matrix is invalid or such, give up. */
7529 cursor_glyph
= get_phys_cursor_glyph (w
);
7530 if (cursor_glyph
== NULL
)
7533 /* Compute frame-relative coordinates for phys cursor. */
7534 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7535 wd
= w
->phys_cursor_width
;
7537 /* The foreground of cursor_gc is typically the same as the normal
7538 background color, which can cause the cursor box to be invisible. */
7539 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7540 if (dpyinfo
->scratch_cursor_gc
)
7541 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7543 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7544 GCForeground
, &xgcv
);
7545 gc
= dpyinfo
->scratch_cursor_gc
;
7547 /* Set clipping, draw the rectangle, and reset clipping again. */
7548 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7549 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7550 XSetClipMask (dpy
, gc
, None
);
7554 /* Draw a bar cursor on window W in glyph row ROW.
7556 Implementation note: One would like to draw a bar cursor with an
7557 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7558 Unfortunately, I didn't find a font yet that has this property set.
7562 x_draw_bar_cursor (w
, row
, width
, kind
)
7564 struct glyph_row
*row
;
7566 enum text_cursor_kinds kind
;
7568 struct frame
*f
= XFRAME (w
->frame
);
7569 struct glyph
*cursor_glyph
;
7571 /* If cursor is out of bounds, don't draw garbage. This can happen
7572 in mini-buffer windows when switching between echo area glyphs
7574 cursor_glyph
= get_phys_cursor_glyph (w
);
7575 if (cursor_glyph
== NULL
)
7578 /* If on an image, draw like a normal cursor. That's usually better
7579 visible than drawing a bar, esp. if the image is large so that
7580 the bar might not be in the window. */
7581 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7583 struct glyph_row
*row
;
7584 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7585 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7589 Display
*dpy
= FRAME_X_DISPLAY (f
);
7590 Window window
= FRAME_X_WINDOW (f
);
7591 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7592 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7593 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7596 /* If the glyph's background equals the color we normally draw
7597 the bar cursor in, the bar cursor in its normal color is
7598 invisible. Use the glyph's foreground color instead in this
7599 case, on the assumption that the glyph's colors are chosen so
7600 that the glyph is legible. */
7601 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7602 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7604 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7605 xgcv
.graphics_exposures
= 0;
7608 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7611 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7612 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7616 width
= FRAME_CURSOR_WIDTH (f
);
7617 width
= min (cursor_glyph
->pixel_width
, width
);
7619 w
->phys_cursor_width
= width
;
7620 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7622 if (kind
== BAR_CURSOR
)
7623 XFillRectangle (dpy
, window
, gc
,
7624 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7625 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7626 width
, row
->height
);
7628 XFillRectangle (dpy
, window
, gc
,
7629 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7630 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7631 row
->height
- width
),
7632 cursor_glyph
->pixel_width
,
7635 XSetClipMask (dpy
, gc
, None
);
7640 /* RIF: Define cursor CURSOR on frame F. */
7643 x_define_frame_cursor (f
, cursor
)
7647 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7651 /* RIF: Clear area on frame F. */
7654 x_clear_frame_area (f
, x
, y
, width
, height
)
7656 int x
, y
, width
, height
;
7658 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7659 x
, y
, width
, height
, False
);
7663 /* RIF: Draw cursor on window W. */
7666 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7668 struct glyph_row
*glyph_row
;
7670 int cursor_type
, cursor_width
;
7673 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7677 w
->phys_cursor_type
= cursor_type
;
7678 w
->phys_cursor_on_p
= 1;
7680 if (glyph_row
->exact_window_width_line_p
7681 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7683 glyph_row
->cursor_in_fringe_p
= 1;
7684 draw_fringe_bitmap (w
, glyph_row
, 0);
7687 switch (cursor_type
)
7689 case HOLLOW_BOX_CURSOR
:
7690 x_draw_hollow_cursor (w
, glyph_row
);
7693 case FILLED_BOX_CURSOR
:
7694 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7698 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7702 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7706 w
->phys_cursor_width
= 0;
7714 if (w
== XWINDOW (f
->selected_window
))
7715 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7716 xic_set_preeditarea (w
, x
, y
);
7721 XFlush (FRAME_X_DISPLAY (f
));
7728 /* Make the x-window of frame F use the gnu icon bitmap. */
7731 x_bitmap_icon (f
, file
)
7737 if (FRAME_X_WINDOW (f
) == 0)
7740 /* Free up our existing icon bitmap and mask if any. */
7741 if (f
->output_data
.x
->icon_bitmap
> 0)
7742 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7743 f
->output_data
.x
->icon_bitmap
= 0;
7748 /* Use gtk_window_set_icon_from_file () if available,
7749 It's not restricted to bitmaps */
7750 if (xg_set_icon (f
, file
))
7752 #endif /* USE_GTK */
7753 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7754 x_create_bitmap_mask (f
, bitmap_id
);
7758 /* Create the GNU bitmap and mask if necessary. */
7759 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7763 #if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7765 if (xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7768 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7770 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7771 #endif /* USE_GTK */
7772 #endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
7774 /* If all else fails, use the (black and white) xbm image. */
7777 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7778 gnu_xbm_width
, gnu_xbm_height
);
7782 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7783 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7787 /* The first time we create the GNU bitmap and mask,
7788 this increments the ref-count one extra time.
7789 As a result, the GNU bitmap and mask are never freed.
7790 That way, we don't have to worry about allocating it again. */
7791 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7793 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7796 x_wm_set_icon_pixmap (f
, bitmap_id
);
7797 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7803 /* Make the x-window of frame F use a rectangle with text.
7804 Use ICON_NAME as the text. */
7807 x_text_icon (f
, icon_name
)
7811 if (FRAME_X_WINDOW (f
) == 0)
7816 text
.value
= (unsigned char *) icon_name
;
7817 text
.encoding
= XA_STRING
;
7819 text
.nitems
= strlen (icon_name
);
7820 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7823 if (f
->output_data
.x
->icon_bitmap
> 0)
7824 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7825 f
->output_data
.x
->icon_bitmap
= 0;
7826 x_wm_set_icon_pixmap (f
, 0);
7831 #define X_ERROR_MESSAGE_SIZE 200
7833 /* If non-nil, this should be a string.
7834 It means catch X errors and store the error message in this string.
7836 The reason we use a stack is that x_catch_error/x_uncatch_error can
7837 be called from a signal handler.
7840 struct x_error_message_stack
{
7841 char string
[X_ERROR_MESSAGE_SIZE
];
7843 struct x_error_message_stack
*prev
;
7845 static struct x_error_message_stack
*x_error_message
;
7847 /* An X error handler which stores the error message in
7848 *x_error_message. This is called from x_error_handler if
7849 x_catch_errors is in effect. */
7852 x_error_catcher (display
, error
)
7856 XGetErrorText (display
, error
->error_code
,
7857 x_error_message
->string
,
7858 X_ERROR_MESSAGE_SIZE
);
7861 /* Begin trapping X errors for display DPY. Actually we trap X errors
7862 for all displays, but DPY should be the display you are actually
7865 After calling this function, X protocol errors no longer cause
7866 Emacs to exit; instead, they are recorded in the string
7867 stored in *x_error_message.
7869 Calling x_check_errors signals an Emacs error if an X error has
7870 occurred since the last call to x_catch_errors or x_check_errors.
7872 Calling x_uncatch_errors resumes the normal error handling. */
7874 void x_check_errors ();
7877 x_catch_errors (dpy
)
7880 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7882 /* Make sure any errors from previous requests have been dealt with. */
7886 data
->string
[0] = 0;
7887 data
->prev
= x_error_message
;
7888 x_error_message
= data
;
7891 /* Undo the last x_catch_errors call.
7892 DPY should be the display that was passed to x_catch_errors. */
7897 struct x_error_message_stack
*tmp
;
7901 /* The display may have been closed before this function is called.
7902 Check if it is still open before calling XSync. */
7903 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7904 XSync (x_error_message
->dpy
, False
);
7906 tmp
= x_error_message
;
7907 x_error_message
= x_error_message
->prev
;
7912 /* If any X protocol errors have arrived since the last call to
7913 x_catch_errors or x_check_errors, signal an Emacs error using
7914 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7917 x_check_errors (dpy
, format
)
7921 /* Make sure to catch any errors incurred so far. */
7924 if (x_error_message
->string
[0])
7926 char string
[X_ERROR_MESSAGE_SIZE
];
7927 bcopy (x_error_message
->string
, string
, X_ERROR_MESSAGE_SIZE
);
7928 x_uncatch_errors ();
7929 error (format
, string
);
7933 /* Nonzero if we had any X protocol errors
7934 since we did x_catch_errors on DPY. */
7937 x_had_errors_p (dpy
)
7940 /* Make sure to catch any errors incurred so far. */
7943 return x_error_message
->string
[0] != 0;
7946 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7949 x_clear_errors (dpy
)
7952 x_error_message
->string
[0] = 0;
7955 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7956 * idea. --lorentey */
7957 /* Close off all unclosed x_catch_errors calls. */
7960 x_fully_uncatch_errors ()
7962 while (x_error_message
)
7963 x_uncatch_errors ();
7967 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7970 x_catching_errors ()
7972 return x_error_message
!= 0;
7976 static unsigned int x_wire_count
;
7979 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7984 /* Handle SIGPIPE, which can happen when the connection to a server
7985 simply goes away. SIGPIPE is handled by x_connection_signal.
7986 Don't need to do anything, because the write which caused the
7987 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7988 which will do the appropriate cleanup for us. */
7991 x_connection_signal (signalnum
) /* If we don't have an argument, */
7992 int signalnum
; /* some compilers complain in signal calls. */
7995 /* USG systems forget handlers when they are used;
7996 must reestablish each time */
7997 signal (signalnum
, x_connection_signal
);
8002 /************************************************************************
8004 ************************************************************************/
8006 /* Error message passed to x_connection_closed. */
8008 static char *error_msg
;
8010 /* Function installed as fatal_error_signal_hook in
8011 x_connection_closed. Print the X error message, and exit normally,
8012 instead of dumping core when XtCloseDisplay fails. */
8015 x_fatal_error_signal ()
8017 fprintf (stderr
, "%s\n", error_msg
);
8021 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
8022 the text of an error message that lead to the connection loss. */
8025 x_connection_closed (dpy
, error_message
)
8027 char *error_message
;
8029 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
8030 Lisp_Object frame
, tail
;
8031 int index
= SPECPDL_INDEX ();
8033 error_msg
= (char *) alloca (strlen (error_message
) + 1);
8034 strcpy (error_msg
, error_message
);
8035 handling_signal
= 0;
8037 /* Prevent being called recursively because of an error condition
8038 below. Otherwise, we might end up with printing ``can't find per
8039 display information'' in the recursive call instead of printing
8040 the original message here. */
8041 x_catch_errors (dpy
);
8043 /* Inhibit redisplay while frames are being deleted. */
8044 specbind (Qinhibit_redisplay
, Qt
);
8048 /* Protect display from being closed when we delete the last
8050 dpyinfo
->reference_count
++;
8051 dpyinfo
->terminal
->reference_count
++;
8054 /* First delete frames whose mini-buffers are on frames
8055 that are on the dead display. */
8056 FOR_EACH_FRAME (tail
, frame
)
8058 Lisp_Object minibuf_frame
;
8060 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
8061 if (FRAME_X_P (XFRAME (frame
))
8062 && FRAME_X_P (XFRAME (minibuf_frame
))
8063 && ! EQ (frame
, minibuf_frame
)
8064 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
8065 Fdelete_frame (frame
, Qt
);
8068 /* Now delete all remaining frames on the dead display.
8069 We are now sure none of these is used as the mini-buffer
8070 for another frame that we need to delete. */
8071 FOR_EACH_FRAME (tail
, frame
)
8072 if (FRAME_X_P (XFRAME (frame
))
8073 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
8075 /* Set this to t so that Fdelete_frame won't get confused
8076 trying to find a replacement. */
8077 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
8078 Fdelete_frame (frame
, Qt
);
8081 /* We have to close the display to inform Xt that it doesn't
8082 exist anymore. If we don't, Xt will continue to wait for
8083 events from the display. As a consequence, a sequence of
8085 M-x make-frame-on-display RET :1 RET
8086 ...kill the new frame, so that we get an IO error...
8087 M-x make-frame-on-display RET :1 RET
8089 will indefinitely wait in Xt for events for display `:1', opened
8090 in the first class to make-frame-on-display.
8092 Closing the display is reported to lead to a bus error on
8093 OpenWindows in certain situations. I suspect that is a bug
8094 in OpenWindows. I don't know how to circumvent it here. */
8096 #ifdef USE_X_TOOLKIT
8097 /* If DPYINFO is null, this means we didn't open the display
8098 in the first place, so don't try to close it. */
8101 extern void (*fatal_error_signal_hook
) P_ ((void));
8102 fatal_error_signal_hook
= x_fatal_error_signal
;
8103 XtCloseDisplay (dpy
);
8104 fatal_error_signal_hook
= NULL
;
8110 xg_display_close (dpyinfo
->display
);
8115 /* Indicate that this display is dead. */
8116 dpyinfo
->display
= 0;
8118 dpyinfo
->reference_count
--;
8119 dpyinfo
->terminal
->reference_count
--;
8120 if (dpyinfo
->reference_count
!= 0)
8121 /* We have just closed all frames on this display. */
8124 x_delete_display (dpyinfo
);
8127 x_uncatch_errors ();
8129 if (terminal_list
== 0)
8131 fprintf (stderr
, "%s\n", error_msg
);
8132 shut_down_emacs (0, 0, Qnil
);
8136 /* Ordinary stack unwind doesn't deal with these. */
8138 sigunblock (sigmask (SIGIO
));
8140 sigunblock (sigmask (SIGALRM
));
8141 TOTALLY_UNBLOCK_INPUT
;
8143 unbind_to (index
, Qnil
);
8144 clear_waiting_for_input ();
8145 /* FIXME: This is an asynchronous interrupt w.r.t elisp, so signalling an
8146 error might not be the best thing to do. I'd vote for creating an
8147 elisp event and stuffing it in the queue so people can bind to it via
8148 the global map. --Stef */
8149 error ("%s", error_msg
);
8152 /* We specifically use it before defining it, so that gcc doesn't inline it,
8153 otherwise gdb doesn't know how to properly put a breakpoint on it. */
8154 static void x_error_quitter
P_ ((Display
*, XErrorEvent
*));
8156 /* This is the first-level handler for X protocol errors.
8157 It calls x_error_quitter or x_error_catcher. */
8160 x_error_handler (display
, error
)
8164 if (x_error_message
)
8165 x_error_catcher (display
, error
);
8167 x_error_quitter (display
, error
);
8171 /* This is the usual handler for X protocol errors.
8172 It kills all frames on the display that we got the error for.
8173 If that was the only one, it prints an error message and kills Emacs. */
8175 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
8177 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
8178 #define NO_INLINE __attribute__((noinline))
8183 /* Some versions of GNU/Linux define noinline in their headers. */
8189 /* On older GCC versions, just putting x_error_quitter
8190 after x_error_handler prevents inlining into the former. */
8192 static void NO_INLINE
8193 x_error_quitter (display
, error
)
8197 char buf
[256], buf1
[356];
8199 /* Ignore BadName errors. They can happen because of fonts
8200 or colors that are not defined. */
8202 if (error
->error_code
== BadName
)
8205 /* Note that there is no real way portable across R3/R4 to get the
8206 original error handler. */
8208 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
8209 sprintf (buf1
, "X protocol error: %s on protocol request %d",
8210 buf
, error
->request_code
);
8211 x_connection_closed (display
, buf1
);
8215 /* This is the handler for X IO errors, always.
8216 It kills all frames on the display that we lost touch with.
8217 If that was the only one, it prints an error message and kills Emacs. */
8220 x_io_error_quitter (display
)
8225 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
8226 x_connection_closed (display
, buf
);
8230 /* Changing the font of the frame. */
8232 /* Give frame F the font named FONTNAME as its default font, and
8233 return the full name of that font. FONTNAME may be a wildcard
8234 pattern; in that case, we choose some font that fits the pattern.
8235 The return value shows which font we chose. */
8238 x_new_font (f
, fontname
)
8240 register char *fontname
;
8242 struct font_info
*fontp
8243 = FS_LOAD_FONT (f
, fontname
);
8248 if (FRAME_FONT (f
) == (XFontStruct
*) (fontp
->font
))
8249 /* This font is already set in frame F. There's nothing more to
8251 return build_string (fontp
->full_name
);
8253 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
8254 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
8255 FRAME_FONTSET (f
) = -1;
8257 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
8258 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
8259 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
8261 compute_fringe_widths (f
, 1);
8263 /* Compute the scroll bar width in character columns. */
8264 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8266 int wid
= FRAME_COLUMN_WIDTH (f
);
8267 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8268 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
8272 int wid
= FRAME_COLUMN_WIDTH (f
);
8273 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8276 /* Now make the frame display the given font. */
8277 if (FRAME_X_WINDOW (f
) != 0)
8279 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
8280 FRAME_FONT (f
)->fid
);
8281 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
8282 FRAME_FONT (f
)->fid
);
8283 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
8284 FRAME_FONT (f
)->fid
);
8286 /* Don't change the size of a tip frame; there's no point in
8287 doing it because it's done in Fx_show_tip, and it leads to
8288 problems because the tip frame has no widget. */
8289 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8290 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8293 return build_string (fontp
->full_name
);
8296 /* Give frame F the fontset named FONTSETNAME as its default fontset,
8297 and return the full name of that fontset. FONTSETNAME may be a
8298 wildcard pattern; in that case, we choose some fontset that fits
8299 the pattern. FONTSETNAME may be a font name for ASCII characters;
8300 in that case, we create a fontset from that font name.
8302 The return value shows which fontset we chose.
8303 If FONTSETNAME specifies the default fontset, return Qt.
8304 If an ASCII font in the specified fontset can't be loaded, return
8308 x_new_fontset (f
, fontsetname
)
8310 Lisp_Object fontsetname
;
8312 int fontset
= fs_query_fontset (fontsetname
, 0);
8315 if (fontset
> 0 && f
->output_data
.x
->fontset
== fontset
)
8316 /* This fontset is already set in frame F. There's nothing more
8318 return fontset_name (fontset
);
8319 else if (fontset
== 0)
8320 /* The default fontset can't be the default font. */
8324 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
8326 result
= x_new_font (f
, SDATA (fontsetname
));
8328 if (!STRINGP (result
))
8329 /* Can't load ASCII font. */
8333 fontset
= new_fontset_from_font_name (result
);
8335 /* Since x_new_font doesn't update any fontset information, do it now. */
8336 FRAME_FONTSET (f
) = fontset
;
8340 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8341 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8344 return fontset_name (fontset
);
8347 #ifdef USE_FONT_BACKEND
8349 x_new_fontset2 (f
, fontset
, font_object
)
8352 Lisp_Object font_object
;
8354 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
8356 if (FRAME_FONT_OBJECT (f
) == font
)
8357 /* This font is already set in frame F. There's nothing more to
8359 return fontset_name (fontset
);
8363 FRAME_FONT_OBJECT (f
) = font
;
8364 FRAME_FONT (f
) = font
->font
.font
;
8365 FRAME_BASELINE_OFFSET (f
) = font
->font
.baseline_offset
;
8366 FRAME_FONTSET (f
) = fontset
;
8368 FRAME_COLUMN_WIDTH (f
) = font
->font
.average_width
;
8369 FRAME_SPACE_WIDTH (f
) = font
->font
.space_width
;
8370 FRAME_LINE_HEIGHT (f
) = font
->font
.height
;
8372 compute_fringe_widths (f
, 1);
8374 /* Compute the scroll bar width in character columns. */
8375 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8377 int wid
= FRAME_COLUMN_WIDTH (f
);
8378 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8379 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
- 1) / wid
;
8383 int wid
= FRAME_COLUMN_WIDTH (f
);
8384 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8387 /* Now make the frame display the given font. */
8388 if (FRAME_X_WINDOW (f
) != 0)
8390 /* Don't change the size of a tip frame; there's no point in
8391 doing it because it's done in Fx_show_tip, and it leads to
8392 problems because the tip frame has no widget. */
8393 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8394 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8399 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8400 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8405 return fontset_name (fontset
);
8407 #endif /* USE_FONT_BACKEND */
8410 /***********************************************************************
8412 ***********************************************************************/
8418 /* XIM destroy callback function, which is called whenever the
8419 connection to input method XIM dies. CLIENT_DATA contains a
8420 pointer to the x_display_info structure corresponding to XIM. */
8423 xim_destroy_callback (xim
, client_data
, call_data
)
8425 XPointer client_data
;
8428 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8429 Lisp_Object frame
, tail
;
8433 /* No need to call XDestroyIC.. */
8434 FOR_EACH_FRAME (tail
, frame
)
8436 struct frame
*f
= XFRAME (frame
);
8437 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8439 FRAME_XIC (f
) = NULL
;
8440 xic_free_xfontset (f
);
8444 /* No need to call XCloseIM. */
8445 dpyinfo
->xim
= NULL
;
8446 XFree (dpyinfo
->xim_styles
);
8450 #endif /* HAVE_X11R6 */
8453 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8454 extern char *XSetIMValues
P_ ((XIM
, ...));
8457 /* Open the connection to the XIM server on display DPYINFO.
8458 RESOURCE_NAME is the resource name Emacs uses. */
8461 xim_open_dpy (dpyinfo
, resource_name
)
8462 struct x_display_info
*dpyinfo
;
8463 char *resource_name
;
8470 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8477 XIMCallback destroy
;
8480 /* Get supported styles and XIM values. */
8481 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8484 destroy
.callback
= xim_destroy_callback
;
8485 destroy
.client_data
= (XPointer
)dpyinfo
;
8486 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8492 #endif /* HAVE_XIM */
8493 dpyinfo
->xim
= NULL
;
8497 #ifdef HAVE_X11R6_XIM
8501 struct x_display_info
*dpyinfo
;
8502 char *resource_name
;
8505 /* XIM instantiate callback function, which is called whenever an XIM
8506 server is available. DISPLAY is the display of the XIM.
8507 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8508 when the callback was registered. */
8511 xim_instantiate_callback (display
, client_data
, call_data
)
8513 XPointer client_data
;
8516 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8517 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8519 /* We don't support multiple XIM connections. */
8523 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8525 /* Create XIC for the existing frames on the same display, as long
8526 as they have no XIC. */
8527 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8529 Lisp_Object tail
, frame
;
8532 FOR_EACH_FRAME (tail
, frame
)
8534 struct frame
*f
= XFRAME (frame
);
8537 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8538 if (FRAME_XIC (f
) == NULL
)
8540 create_frame_xic (f
);
8541 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8542 xic_set_statusarea (f
);
8543 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8545 struct window
*w
= XWINDOW (f
->selected_window
);
8546 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8555 #endif /* HAVE_X11R6_XIM */
8558 /* Open a connection to the XIM server on display DPYINFO.
8559 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8560 connection only at the first time. On X11R6, open the connection
8561 in the XIM instantiate callback function. */
8564 xim_initialize (dpyinfo
, resource_name
)
8565 struct x_display_info
*dpyinfo
;
8566 char *resource_name
;
8571 #ifdef HAVE_X11R6_XIM
8572 struct xim_inst_t
*xim_inst
;
8575 dpyinfo
->xim
= NULL
;
8576 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8577 xim_inst
->dpyinfo
= dpyinfo
;
8578 len
= strlen (resource_name
);
8579 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8580 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8581 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8582 resource_name
, EMACS_CLASS
,
8583 xim_instantiate_callback
,
8584 /* This is XPointer in XFree86
8585 but (XPointer *) on Tru64, at
8586 least, hence the configure test. */
8587 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8588 #else /* not HAVE_X11R6_XIM */
8589 dpyinfo
->xim
= NULL
;
8590 xim_open_dpy (dpyinfo
, resource_name
);
8591 #endif /* not HAVE_X11R6_XIM */
8595 #endif /* HAVE_XIM */
8596 dpyinfo
->xim
= NULL
;
8600 /* Close the connection to the XIM server on display DPYINFO. */
8603 xim_close_dpy (dpyinfo
)
8604 struct x_display_info
*dpyinfo
;
8609 #ifdef HAVE_X11R6_XIM
8610 if (dpyinfo
->display
)
8611 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8613 xim_instantiate_callback
, NULL
);
8614 #endif /* not HAVE_X11R6_XIM */
8615 if (dpyinfo
->display
)
8616 XCloseIM (dpyinfo
->xim
);
8617 dpyinfo
->xim
= NULL
;
8618 XFree (dpyinfo
->xim_styles
);
8620 #endif /* HAVE_XIM */
8623 #endif /* not HAVE_X11R6_XIM */
8627 /* Calculate the absolute position in frame F
8628 from its current recorded position values and gravity. */
8631 x_calc_absolute_position (f
)
8634 int flags
= f
->size_hint_flags
;
8636 /* We have nothing to do if the current position
8637 is already for the top-left corner. */
8638 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8641 /* Treat negative positions as relative to the leftmost bottommost
8642 position that fits on the screen. */
8643 if (flags
& XNegative
)
8644 f
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
8645 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
);
8648 int height
= FRAME_PIXEL_HEIGHT (f
);
8650 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8651 /* Something is fishy here. When using Motif, starting Emacs with
8652 `-g -0-0', the frame appears too low by a few pixels.
8654 This seems to be so because initially, while Emacs is starting,
8655 the column widget's height and the frame's pixel height are
8656 different. The column widget's height is the right one. In
8657 later invocations, when Emacs is up, the frame's pixel height
8660 It's not obvious where the initial small difference comes from.
8661 2000-12-01, gerd. */
8663 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8666 if (flags
& YNegative
)
8667 f
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
- height
+ f
->top_pos
);
8670 /* The left_pos and top_pos
8671 are now relative to the top and left screen edges,
8672 so the flags should correspond. */
8673 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8676 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8677 to really change the position, and 0 when calling from
8678 x_make_frame_visible (in that case, XOFF and YOFF are the current
8679 position values). It is -1 when calling from x_set_frame_parameters,
8680 which means, do adjust for borders but don't change the gravity. */
8683 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8685 register int xoff
, yoff
;
8688 int modified_top
, modified_left
;
8690 if (change_gravity
!= 0)
8692 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8693 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8697 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8699 f
->size_hint_flags
|= XNegative
;
8701 f
->size_hint_flags
|= YNegative
;
8702 f
->win_gravity
= NorthWestGravity
;
8704 x_calc_absolute_position (f
);
8707 x_wm_set_size_hint (f
, (long) 0, 0);
8709 modified_left
= f
->left_pos
;
8710 modified_top
= f
->top_pos
;
8712 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8714 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8715 than the WM decorations. So we use the calculated offset instead
8716 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8717 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8718 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8721 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8722 modified_left
, modified_top
);
8724 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8725 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8728 /* change_gravity is non-zero when this function is called from Lisp to
8729 programmatically move a frame. In that case, we call
8730 x_check_expected_move to discover if we have a "Type A" or "Type B"
8731 window manager, and, for a "Type A" window manager, adjust the position
8734 We call x_check_expected_move if a programmatic move occurred, and
8735 either the window manager type (A/B) is unknown or it is Type A but we
8736 need to compute the top/left offset adjustment for this frame. */
8738 if (change_gravity
!= 0 &&
8739 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8740 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8741 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8742 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8743 x_check_expected_move (f
, modified_left
, modified_top
);
8748 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8749 on the root window for frame F contains ATOMNAME.
8750 This is how a WM check shall be done according to the Window Manager
8751 Specification/Extended Window Manager Hints at
8752 http://freedesktop.org/wiki/Specifications/wm-spec. */
8755 wm_supports (f
, atomname
)
8757 const char *atomname
;
8760 unsigned long actual_size
, bytes_remaining
;
8761 int i
, rc
, actual_format
;
8763 Window wmcheck_window
;
8764 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8765 Window target_window
= dpyinfo
->root_window
;
8766 long max_len
= 65536;
8767 Display
*dpy
= FRAME_X_DISPLAY (f
);
8768 unsigned char *tmp_data
= NULL
;
8769 Atom target_type
= XA_WINDOW
;
8774 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8776 x_catch_errors (dpy
);
8777 rc
= XGetWindowProperty (dpy
, target_window
,
8778 prop_atom
, 0, max_len
, False
, target_type
,
8779 &actual_type
, &actual_format
, &actual_size
,
8780 &bytes_remaining
, &tmp_data
);
8782 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8784 if (tmp_data
) XFree (tmp_data
);
8785 x_uncatch_errors ();
8790 wmcheck_window
= *(Window
*) tmp_data
;
8793 /* Check if window exists. */
8794 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8796 if (x_had_errors_p (dpy
))
8798 x_uncatch_errors ();
8803 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8805 /* Window changed, reload atoms */
8806 if (dpyinfo
->net_supported_atoms
!= NULL
)
8807 XFree (dpyinfo
->net_supported_atoms
);
8808 dpyinfo
->net_supported_atoms
= NULL
;
8809 dpyinfo
->nr_net_supported_atoms
= 0;
8810 dpyinfo
->net_supported_window
= 0;
8812 target_type
= XA_ATOM
;
8813 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8815 rc
= XGetWindowProperty (dpy
, target_window
,
8816 prop_atom
, 0, max_len
, False
, target_type
,
8817 &actual_type
, &actual_format
, &actual_size
,
8818 &bytes_remaining
, &tmp_data
);
8820 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8822 if (tmp_data
) XFree (tmp_data
);
8823 x_uncatch_errors ();
8828 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8829 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8830 dpyinfo
->net_supported_window
= wmcheck_window
;
8834 want_atom
= XInternAtom (dpy
, atomname
, False
);
8836 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8837 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8839 x_uncatch_errors ();
8845 /* Do fullscreen as specified in extended window manager hints */
8848 do_ewmh_fullscreen (f
)
8851 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8853 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8854 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8856 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8861 const char *atom
= "_NET_WM_STATE";
8862 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8863 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8864 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8865 const char *what
= NULL
;
8867 XSETFRAME (frame
, f
);
8869 /* If there are _NET_ atoms we assume we have extended window manager
8871 switch (f
->want_fullscreen
)
8873 case FULLSCREEN_BOTH
:
8876 case FULLSCREEN_WIDTH
:
8879 case FULLSCREEN_HEIGHT
:
8884 if (what
!= NULL
&& !wm_supports (f
, what
)) return 0;
8887 Fx_send_client_event (frame
, make_number (0), frame
,
8888 make_unibyte_string (atom
, strlen (atom
)),
8890 Fcons (make_number (0), /* Remove */
8892 (make_unibyte_string (fs
,
8895 Fx_send_client_event (frame
, make_number (0), frame
,
8896 make_unibyte_string (atom
, strlen (atom
)),
8898 Fcons (make_number (0), /* Remove */
8900 (make_unibyte_string (fh
,
8903 Fx_send_client_event (frame
, make_number (0), frame
,
8904 make_unibyte_string (atom
, strlen (atom
)),
8906 Fcons (make_number (0), /* Remove */
8908 (make_unibyte_string (fw
,
8911 f
->want_fullscreen
= FULLSCREEN_NONE
;
8913 Fx_send_client_event (frame
, make_number (0), frame
,
8914 make_unibyte_string (atom
, strlen (atom
)),
8916 Fcons (make_number (1), /* Add */
8918 (make_unibyte_string (what
,
8923 return have_net_atom
;
8927 XTfullscreen_hook (f
)
8930 if (f
->async_visible
)
8933 do_ewmh_fullscreen (f
);
8940 /* Check if we need to resize the frame due to a fullscreen request.
8941 If so needed, resize the frame. */
8943 x_check_fullscreen (f
)
8946 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
8948 int width
, height
, ign
;
8950 if (do_ewmh_fullscreen (f
))
8953 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8955 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8957 /* We do not need to move the window, it shall be taken care of
8958 when setting WM manager hints.
8959 If the frame is visible already, the position is checked by
8960 x_check_expected_move. */
8961 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8963 change_frame_size (f
, height
, width
, 0, 1, 0);
8964 SET_FRAME_GARBAGED (f
);
8965 cancel_mouse_face (f
);
8967 /* Wait for the change of frame size to occur */
8968 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
8973 /* This function is called by x_set_offset to determine whether the window
8974 manager interfered with the positioning of the frame. Type A window
8975 managers position the surrounding window manager decorations a small
8976 amount above and left of the user-supplied position. Type B window
8977 managers position the surrounding window manager decorations at the
8978 user-specified position. If we detect a Type A window manager, we
8979 compensate by moving the window right and down by the proper amount. */
8982 x_check_expected_move (f
, expected_left
, expected_top
)
8987 int current_left
= 0, current_top
= 0;
8989 /* x_real_positions returns the left and top offsets of the outermost
8990 window manager window around the frame. */
8992 x_real_positions (f
, ¤t_left
, ¤t_top
);
8994 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8996 /* It's a "Type A" window manager. */
9001 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
9002 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
9003 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
9005 /* Now fix the mispositioned frame's location. */
9007 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
9008 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
9010 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9011 adjusted_left
, adjusted_top
);
9013 x_sync_with_move (f
, expected_left
, expected_top
, 0);
9016 /* It's a "Type B" window manager. We don't have to adjust the
9017 frame's position. */
9019 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
9023 /* Wait for XGetGeometry to return up-to-date position information for a
9024 recently-moved frame. Call this immediately after calling XMoveWindow.
9025 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
9026 frame has been moved to, so we use a fuzzy position comparison instead
9027 of an exact comparison. */
9030 x_sync_with_move (f
, left
, top
, fuzzy
)
9032 int left
, top
, fuzzy
;
9036 while (count
++ < 50)
9038 int current_left
= 0, current_top
= 0;
9040 /* In theory, this call to XSync only needs to happen once, but in
9041 practice, it doesn't seem to work, hence the need for the surrounding
9044 XSync (FRAME_X_DISPLAY (f
), False
);
9045 x_real_positions (f
, ¤t_left
, ¤t_top
);
9049 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
9052 if (eabs (current_left
- left
) <= 10
9053 && eabs (current_top
- top
) <= 40)
9056 else if (current_left
== left
&& current_top
== top
)
9060 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
9061 will then return up-to-date position info. */
9063 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
9067 /* Change the size of frame F's X window to COLS/ROWS in the case F
9068 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
9069 top-left-corner window gravity for this size change and subsequent
9070 size changes. Otherwise we leave the window gravity unchanged. */
9073 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
9078 int pixelwidth
, pixelheight
;
9080 check_frame_size (f
, &rows
, &cols
);
9081 f
->scroll_bar_actual_width
9082 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
9084 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
9085 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
9086 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
9088 compute_fringe_widths (f
, 0);
9090 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
9091 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
9093 f
->win_gravity
= NorthWestGravity
;
9094 x_wm_set_size_hint (f
, (long) 0, 0);
9096 XSync (FRAME_X_DISPLAY (f
), False
);
9097 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9098 pixelwidth
, pixelheight
);
9100 /* Now, strictly speaking, we can't be sure that this is accurate,
9101 but the window manager will get around to dealing with the size
9102 change request eventually, and we'll hear how it went when the
9103 ConfigureNotify event gets here.
9105 We could just not bother storing any of this information here,
9106 and let the ConfigureNotify event set everything up, but that
9107 might be kind of confusing to the Lisp code, since size changes
9108 wouldn't be reported in the frame parameters until some random
9109 point in the future when the ConfigureNotify event arrives.
9111 We pass 1 for DELAY since we can't run Lisp code inside of
9113 change_frame_size (f
, rows
, cols
, 0, 1, 0);
9114 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
9115 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
9117 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9118 receive in the ConfigureNotify event; if we get what we asked
9119 for, then the event won't cause the screen to become garbaged, so
9120 we have to make sure to do it here. */
9121 SET_FRAME_GARBAGED (f
);
9123 XFlush (FRAME_X_DISPLAY (f
));
9127 /* Call this to change the size of frame F's x-window.
9128 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
9129 for this size change and subsequent size changes.
9130 Otherwise we leave the window gravity unchanged. */
9133 x_set_window_size (f
, change_gravity
, cols
, rows
)
9141 if (FRAME_GTK_WIDGET (f
))
9142 xg_frame_set_char_size (f
, cols
, rows
);
9144 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9147 if (f
->output_data
.x
->widget
!= NULL
)
9149 /* The x and y position of the widget is clobbered by the
9150 call to XtSetValues within EmacsFrameSetCharSize.
9151 This is a real kludge, but I don't understand Xt so I can't
9152 figure out a correct fix. Can anyone else tell me? -- rms. */
9153 int xpos
= f
->output_data
.x
->widget
->core
.x
;
9154 int ypos
= f
->output_data
.x
->widget
->core
.y
;
9155 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
9156 f
->output_data
.x
->widget
->core
.x
= xpos
;
9157 f
->output_data
.x
->widget
->core
.y
= ypos
;
9160 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9162 #else /* not USE_X_TOOLKIT */
9164 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9166 #endif /* not USE_X_TOOLKIT */
9168 /* If cursor was outside the new size, mark it as off. */
9169 mark_window_cursors_off (XWINDOW (f
->root_window
));
9171 /* Clear out any recollection of where the mouse highlighting was,
9172 since it might be in a place that's outside the new frame size.
9173 Actually checking whether it is outside is a pain in the neck,
9174 so don't try--just let the highlighting be done afresh with new size. */
9175 cancel_mouse_face (f
);
9180 /* Mouse warping. */
9183 x_set_mouse_position (f
, x
, y
)
9189 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
9190 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
9192 if (pix_x
< 0) pix_x
= 0;
9193 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
9195 if (pix_y
< 0) pix_y
= 0;
9196 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
9200 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9201 0, 0, 0, 0, pix_x
, pix_y
);
9205 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
9208 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9214 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9215 0, 0, 0, 0, pix_x
, pix_y
);
9219 /* focus shifting, raising and lowering. */
9222 x_focus_on_frame (f
)
9225 #if 0 /* This proves to be unpleasant. */
9229 /* I don't think that the ICCCM allows programs to do things like this
9230 without the interaction of the window manager. Whatever you end up
9231 doing with this code, do it to x_unfocus_frame too. */
9232 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9233 RevertToPointerRoot
, CurrentTime
);
9242 /* Look at the remarks in x_focus_on_frame. */
9243 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
9244 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
9245 RevertToPointerRoot
, CurrentTime
);
9249 /* Raise frame F. */
9256 if (f
->async_visible
)
9257 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9259 XFlush (FRAME_X_DISPLAY (f
));
9263 /* Lower frame F. */
9269 if (f
->async_visible
)
9272 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9273 XFlush (FRAME_X_DISPLAY (f
));
9278 /* Activate frame with Extended Window Manager Hints */
9281 x_ewmh_activate_frame (f
)
9284 /* See Window Manager Specification/Extended Window Manager Hints at
9285 http://freedesktop.org/wiki/Specifications/wm-spec */
9287 const char *atom
= "_NET_ACTIVE_WINDOW";
9288 if (f
->async_visible
&& wm_supports (f
, atom
))
9291 XSETFRAME (frame
, f
);
9292 Fx_send_client_event (frame
, make_number (0), frame
,
9293 make_unibyte_string (atom
, strlen (atom
)),
9295 Fcons (make_number (1),
9296 Fcons (make_number (last_user_time
),
9302 XTframe_raise_lower (f
, raise_flag
)
9312 /* XEmbed implementation. */
9315 xembed_set_info (f
, flags
)
9317 enum xembed_info flags
;
9320 unsigned long data
[2];
9322 atom
= XInternAtom (FRAME_X_DISPLAY (f
), "_XEMBED_INFO", False
);
9324 data
[0] = XEMBED_VERSION
;
9327 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), atom
, atom
,
9328 32, PropModeReplace
, (unsigned char *) data
, 2);
9332 xembed_send_message (f
, time
, message
, detail
, data1
, data2
)
9335 enum xembed_message message
;
9342 event
.xclient
.type
= ClientMessage
;
9343 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
9344 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
9345 event
.xclient
.format
= 32;
9346 event
.xclient
.data
.l
[0] = time
;
9347 event
.xclient
.data
.l
[1] = message
;
9348 event
.xclient
.data
.l
[2] = detail
;
9349 event
.xclient
.data
.l
[3] = data1
;
9350 event
.xclient
.data
.l
[4] = data2
;
9352 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9353 False
, NoEventMask
, &event
);
9354 XSync (FRAME_X_DISPLAY (f
), False
);
9357 /* Change of visibility. */
9359 /* This tries to wait until the frame is really visible.
9360 However, if the window manager asks the user where to position
9361 the frame, this will return before the user finishes doing that.
9362 The frame will not actually be visible at that time,
9363 but it will become visible later when the window manager
9364 finishes with it. */
9367 x_make_frame_visible (f
)
9371 int original_top
, original_left
;
9372 int retry_count
= 2;
9378 type
= x_icon_type (f
);
9380 x_bitmap_icon (f
, type
);
9382 if (! FRAME_VISIBLE_P (f
))
9384 /* We test FRAME_GARBAGED_P here to make sure we don't
9385 call x_set_offset a second time
9386 if we get to x_make_frame_visible a second time
9387 before the window gets really visible. */
9388 if (! FRAME_ICONIFIED_P (f
)
9389 && ! FRAME_X_EMBEDDED_P (f
)
9390 && ! f
->output_data
.x
->asked_for_visible
)
9391 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9393 f
->output_data
.x
->asked_for_visible
= 1;
9395 if (! EQ (Vx_no_window_manager
, Qt
))
9396 x_wm_set_window_state (f
, NormalState
);
9397 #ifdef USE_X_TOOLKIT
9398 if (FRAME_X_EMBEDDED_P (f
))
9399 xembed_set_info (f
, XEMBED_MAPPED
);
9402 /* This was XtPopup, but that did nothing for an iconified frame. */
9403 XtMapWidget (f
->output_data
.x
->widget
);
9405 #else /* not USE_X_TOOLKIT */
9407 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9408 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9410 if (FRAME_X_EMBEDDED_P (f
))
9411 xembed_set_info (f
, XEMBED_MAPPED
);
9413 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9414 #endif /* not USE_GTK */
9415 #endif /* not USE_X_TOOLKIT */
9416 #if 0 /* This seems to bring back scroll bars in the wrong places
9417 if the window configuration has changed. They seem
9418 to come back ok without this. */
9419 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9420 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9424 XFlush (FRAME_X_DISPLAY (f
));
9426 /* Synchronize to ensure Emacs knows the frame is visible
9427 before we do anything else. We do this loop with input not blocked
9428 so that incoming events are handled. */
9432 /* This must be before UNBLOCK_INPUT
9433 since events that arrive in response to the actions above
9434 will set it when they are handled. */
9435 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9437 original_left
= f
->left_pos
;
9438 original_top
= f
->top_pos
;
9440 /* This must come after we set COUNT. */
9443 /* We unblock here so that arriving X events are processed. */
9445 /* Now move the window back to where it was "supposed to be".
9446 But don't do it if the gravity is negative.
9447 When the gravity is negative, this uses a position
9448 that is 3 pixels too low. Perhaps that's really the border width.
9450 Don't do this if the window has never been visible before,
9451 because the window manager may choose the position
9452 and we don't want to override it. */
9454 if (! FRAME_VISIBLE_P (f
)
9455 && ! FRAME_ICONIFIED_P (f
)
9456 && ! FRAME_X_EMBEDDED_P (f
)
9457 && f
->win_gravity
== NorthWestGravity
9458 && previously_visible
)
9462 unsigned int width
, height
, border
, depth
;
9466 /* On some window managers (such as FVWM) moving an existing
9467 window, even to the same place, causes the window manager
9468 to introduce an offset. This can cause the window to move
9469 to an unexpected location. Check the geometry (a little
9470 slow here) and then verify that the window is in the right
9471 place. If the window is not in the right place, move it
9472 there, and take the potential window manager hit. */
9473 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9474 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9476 if (original_left
!= x
|| original_top
!= y
)
9477 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9478 original_left
, original_top
);
9483 XSETFRAME (frame
, f
);
9485 /* Wait until the frame is visible. Process X events until a
9486 MapNotify event has been seen, or until we think we won't get a
9487 MapNotify at all.. */
9488 for (count
= input_signal_count
+ 10;
9489 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9491 /* Force processing of queued events. */
9494 /* Machines that do polling rather than SIGIO have been
9495 observed to go into a busy-wait here. So we'll fake an
9496 alarm signal to let the handler know that there's something
9497 to be read. We used to raise a real alarm, but it seems
9498 that the handler isn't always enabled here. This is
9500 if (input_polling_used ())
9502 /* It could be confusing if a real alarm arrives while
9503 processing the fake one. Turn it off and let the
9504 handler reset it. */
9505 extern void poll_for_input_1
P_ ((void));
9506 int old_poll_suppress_count
= poll_suppress_count
;
9507 poll_suppress_count
= 1;
9508 poll_for_input_1 ();
9509 poll_suppress_count
= old_poll_suppress_count
;
9512 /* See if a MapNotify event has been processed. */
9513 FRAME_SAMPLE_VISIBILITY (f
);
9518 (let ((f (selected-frame)))
9522 the frame is not raised with various window managers on
9523 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9524 unknown reason, the call to XtMapWidget is completely ignored.
9525 Mapping the widget a second time works. */
9527 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9532 /* Change from mapped state to withdrawn state. */
9534 /* Make the frame visible (mapped and not iconified). */
9537 x_make_frame_invisible (f
)
9542 /* Use the frame's outermost window, not the one we normally draw on. */
9543 window
= FRAME_OUTER_WINDOW (f
);
9545 /* Don't keep the highlight on an invisible frame. */
9546 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9547 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9549 #if 0/* This might add unreliability; I don't trust it -- rms. */
9550 if (! f
->async_visible
&& ! f
->async_iconified
)
9556 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9557 that the current position of the window is user-specified, rather than
9558 program-specified, so that when the window is mapped again, it will be
9559 placed at the same location, without forcing the user to position it
9560 by hand again (they have already done that once for this window.) */
9561 x_wm_set_size_hint (f
, (long) 0, 1);
9564 if (FRAME_GTK_OUTER_WIDGET (f
))
9565 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9568 if (FRAME_X_EMBEDDED_P (f
))
9569 xembed_set_info (f
, 0);
9574 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9575 DefaultScreen (FRAME_X_DISPLAY (f
))))
9577 UNBLOCK_INPUT_RESIGNAL
;
9578 error ("Can't notify window manager of window withdrawal");
9582 /* We can't distinguish this from iconification
9583 just by the event that we get from the server.
9584 So we can't win using the usual strategy of letting
9585 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9586 and synchronize with the server to make sure we agree. */
9588 FRAME_ICONIFIED_P (f
) = 0;
9589 f
->async_visible
= 0;
9590 f
->async_iconified
= 0;
9597 /* Change window state from mapped to iconified. */
9606 /* Don't keep the highlight on an invisible frame. */
9607 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9608 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9610 if (f
->async_iconified
)
9615 FRAME_SAMPLE_VISIBILITY (f
);
9617 type
= x_icon_type (f
);
9619 x_bitmap_icon (f
, type
);
9622 if (FRAME_GTK_OUTER_WIDGET (f
))
9624 if (! FRAME_VISIBLE_P (f
))
9625 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9627 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9630 f
->async_iconified
= 1;
9631 f
->async_visible
= 0;
9637 #ifdef USE_X_TOOLKIT
9639 if (! FRAME_VISIBLE_P (f
))
9641 if (! EQ (Vx_no_window_manager
, Qt
))
9642 x_wm_set_window_state (f
, IconicState
);
9643 /* This was XtPopup, but that did nothing for an iconified frame. */
9644 XtMapWidget (f
->output_data
.x
->widget
);
9645 /* The server won't give us any event to indicate
9646 that an invisible frame was changed to an icon,
9647 so we have to record it here. */
9650 f
->async_iconified
= 1;
9651 f
->async_visible
= 0;
9656 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9657 XtWindow (f
->output_data
.x
->widget
),
9658 DefaultScreen (FRAME_X_DISPLAY (f
)));
9662 error ("Can't notify window manager of iconification");
9664 f
->async_iconified
= 1;
9665 f
->async_visible
= 0;
9669 XFlush (FRAME_X_DISPLAY (f
));
9671 #else /* not USE_X_TOOLKIT */
9673 /* Make sure the X server knows where the window should be positioned,
9674 in case the user deiconifies with the window manager. */
9675 if (! FRAME_VISIBLE_P (f
)
9676 && ! FRAME_ICONIFIED_P (f
)
9677 && ! FRAME_X_EMBEDDED_P (f
))
9678 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9680 /* Since we don't know which revision of X we're running, we'll use both
9681 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9683 /* X11R4: send a ClientMessage to the window manager using the
9684 WM_CHANGE_STATE type. */
9688 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9689 message
.xclient
.type
= ClientMessage
;
9690 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9691 message
.xclient
.format
= 32;
9692 message
.xclient
.data
.l
[0] = IconicState
;
9694 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9695 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9697 SubstructureRedirectMask
| SubstructureNotifyMask
,
9700 UNBLOCK_INPUT_RESIGNAL
;
9701 error ("Can't notify window manager of iconification");
9705 /* X11R3: set the initial_state field of the window manager hints to
9707 x_wm_set_window_state (f
, IconicState
);
9709 if (!FRAME_VISIBLE_P (f
))
9711 /* If the frame was withdrawn, before, we must map it. */
9712 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9715 f
->async_iconified
= 1;
9716 f
->async_visible
= 0;
9718 XFlush (FRAME_X_DISPLAY (f
));
9720 #endif /* not USE_X_TOOLKIT */
9724 /* Free X resources of frame F. */
9727 x_free_frame_resources (f
)
9730 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9732 struct scroll_bar
*b
;
9736 /* If a display connection is dead, don't try sending more
9737 commands to the X server. */
9738 if (dpyinfo
->display
)
9740 #ifdef USE_FONT_BACKEND
9741 /* We must free faces before destroying windows because some
9742 font-driver (e.g. xft) access a window while finishing a
9744 if (enable_font_backend
9745 && FRAME_FACE_CACHE (f
))
9746 free_frame_faces (f
);
9747 #endif /* USE_FONT_BACKEND */
9749 if (f
->output_data
.x
->icon_desc
)
9750 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9752 #ifdef USE_X_TOOLKIT
9753 /* Explicitly destroy the scroll bars of the frame. Without
9754 this, we get "BadDrawable" errors from the toolkit later on,
9755 presumably from expose events generated for the disappearing
9756 toolkit scroll bars. */
9757 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9759 b
= XSCROLL_BAR (bar
);
9760 x_scroll_bar_remove (b
);
9769 #ifdef USE_X_TOOLKIT
9770 if (f
->output_data
.x
->widget
)
9772 XtDestroyWidget (f
->output_data
.x
->widget
);
9773 f
->output_data
.x
->widget
= NULL
;
9775 /* Tooltips don't have widgets, only a simple X window, even if
9776 we are using a toolkit. */
9777 else if (FRAME_X_WINDOW (f
))
9778 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9780 free_frame_menubar (f
);
9781 #else /* !USE_X_TOOLKIT */
9784 /* In the GTK version, tooltips are normal X
9785 frames. We must check and free both types. */
9786 if (FRAME_GTK_OUTER_WIDGET (f
))
9788 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9789 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9790 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9792 #endif /* USE_GTK */
9794 if (FRAME_X_WINDOW (f
))
9795 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9796 #endif /* !USE_X_TOOLKIT */
9798 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9799 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9800 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9801 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9802 unload_color (f
, f
->output_data
.x
->border_pixel
);
9803 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9805 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9806 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9807 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9808 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9809 #ifdef USE_TOOLKIT_SCROLL_BARS
9810 /* Scrollbar shadow colors. */
9811 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9812 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9813 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9814 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9815 #endif /* USE_TOOLKIT_SCROLL_BARS */
9816 if (f
->output_data
.x
->white_relief
.allocated_p
)
9817 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9818 if (f
->output_data
.x
->black_relief
.allocated_p
)
9819 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9821 if (FRAME_FACE_CACHE (f
))
9822 free_frame_faces (f
);
9825 XFlush (FRAME_X_DISPLAY (f
));
9828 if (f
->output_data
.x
->saved_menu_event
)
9829 xfree (f
->output_data
.x
->saved_menu_event
);
9831 xfree (f
->output_data
.x
);
9832 f
->output_data
.x
= NULL
;
9834 if (f
== dpyinfo
->x_focus_frame
)
9835 dpyinfo
->x_focus_frame
= 0;
9836 if (f
== dpyinfo
->x_focus_event_frame
)
9837 dpyinfo
->x_focus_event_frame
= 0;
9838 if (f
== dpyinfo
->x_highlight_frame
)
9839 dpyinfo
->x_highlight_frame
= 0;
9841 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9843 dpyinfo
->mouse_face_beg_row
9844 = dpyinfo
->mouse_face_beg_col
= -1;
9845 dpyinfo
->mouse_face_end_row
9846 = dpyinfo
->mouse_face_end_col
= -1;
9847 dpyinfo
->mouse_face_window
= Qnil
;
9848 dpyinfo
->mouse_face_deferred_gc
= 0;
9849 dpyinfo
->mouse_face_mouse_frame
= 0;
9856 /* Destroy the X window of frame F. */
9859 x_destroy_window (f
)
9862 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9864 /* If a display connection is dead, don't try sending more
9865 commands to the X server. */
9866 if (dpyinfo
->display
!= 0)
9867 x_free_frame_resources (f
);
9869 dpyinfo
->reference_count
--;
9873 /* Setting window manager hints. */
9875 /* Set the normal size hints for the window manager, for frame F.
9876 FLAGS is the flags word to use--or 0 meaning preserve the flags
9877 that the window now has.
9878 If USER_POSITION is nonzero, we set the USPosition
9879 flag (this is useful when FLAGS is 0).
9880 The GTK version is in gtkutils.c */
9884 x_wm_set_size_hint (f
, flags
, user_position
)
9889 XSizeHints size_hints
;
9891 #ifdef USE_X_TOOLKIT
9894 Dimension widget_width
, widget_height
;
9897 Window window
= FRAME_OUTER_WINDOW (f
);
9899 /* Setting PMaxSize caused various problems. */
9900 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9902 size_hints
.x
= f
->left_pos
;
9903 size_hints
.y
= f
->top_pos
;
9905 #ifdef USE_X_TOOLKIT
9906 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9907 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9908 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9909 size_hints
.height
= widget_height
;
9910 size_hints
.width
= widget_width
;
9911 #else /* not USE_X_TOOLKIT */
9912 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9913 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9914 #endif /* not USE_X_TOOLKIT */
9916 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9917 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9918 size_hints
.max_width
9919 = FRAME_X_DISPLAY_INFO (f
)->width
- FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9920 size_hints
.max_height
9921 = FRAME_X_DISPLAY_INFO (f
)->height
- FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9923 /* Calculate the base and minimum sizes.
9925 (When we use the X toolkit, we don't do it here.
9926 Instead we copy the values that the widgets are using, below.) */
9927 #ifndef USE_X_TOOLKIT
9929 int base_width
, base_height
;
9930 int min_rows
= 0, min_cols
= 0;
9932 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9933 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9935 check_frame_size (f
, &min_rows
, &min_cols
);
9937 /* The window manager uses the base width hints to calculate the
9938 current number of rows and columns in the frame while
9939 resizing; min_width and min_height aren't useful for this
9940 purpose, since they might not give the dimensions for a
9941 zero-row, zero-column frame.
9943 We use the base_width and base_height members if we have
9944 them; otherwise, we set the min_width and min_height members
9945 to the size for a zero x zero frame. */
9947 size_hints
.flags
|= PBaseSize
;
9948 size_hints
.base_width
= base_width
;
9949 size_hints
.base_height
= base_height
;
9950 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9951 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9954 /* If we don't need the old flags, we don't need the old hint at all. */
9957 size_hints
.flags
|= flags
;
9960 #endif /* not USE_X_TOOLKIT */
9963 XSizeHints hints
; /* Sometimes I hate X Windows... */
9964 long supplied_return
;
9967 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9970 #ifdef USE_X_TOOLKIT
9971 size_hints
.base_height
= hints
.base_height
;
9972 size_hints
.base_width
= hints
.base_width
;
9973 size_hints
.min_height
= hints
.min_height
;
9974 size_hints
.min_width
= hints
.min_width
;
9978 size_hints
.flags
|= flags
;
9983 if (hints
.flags
& PSize
)
9984 size_hints
.flags
|= PSize
;
9985 if (hints
.flags
& PPosition
)
9986 size_hints
.flags
|= PPosition
;
9987 if (hints
.flags
& USPosition
)
9988 size_hints
.flags
|= USPosition
;
9989 if (hints
.flags
& USSize
)
9990 size_hints
.flags
|= USSize
;
9994 #ifndef USE_X_TOOLKIT
9999 size_hints
.win_gravity
= f
->win_gravity
;
10000 size_hints
.flags
|= PWinGravity
;
10004 size_hints
.flags
&= ~ PPosition
;
10005 size_hints
.flags
|= USPosition
;
10007 #endif /* PWinGravity */
10009 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
10011 #endif /* not USE_GTK */
10013 /* Used for IconicState or NormalState */
10016 x_wm_set_window_state (f
, state
)
10020 #ifdef USE_X_TOOLKIT
10023 XtSetArg (al
[0], XtNinitialState
, state
);
10024 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10025 #else /* not USE_X_TOOLKIT */
10026 Window window
= FRAME_X_WINDOW (f
);
10028 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
10029 f
->output_data
.x
->wm_hints
.initial_state
= state
;
10031 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10032 #endif /* not USE_X_TOOLKIT */
10036 x_wm_set_icon_pixmap (f
, pixmap_id
)
10040 Pixmap icon_pixmap
, icon_mask
;
10042 #ifndef USE_X_TOOLKIT
10043 Window window
= FRAME_OUTER_WINDOW (f
);
10048 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
10049 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
10050 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
10051 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
10055 /* It seems there is no way to turn off use of an icon pixmap.
10056 The following line does it, only if no icon has yet been created,
10057 for some window managers. But with mwm it crashes.
10058 Some people say it should clear the IconPixmapHint bit in this case,
10059 but that doesn't work, and the X consortium said it isn't the
10060 right thing at all. Since there is no way to win,
10061 best to explicitly give up. */
10063 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
10064 f
->output_data
.x
->wm_hints
.icon_mask
= None
;
10073 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
10077 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
10081 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
10082 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10083 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
10084 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10087 #else /* not USE_X_TOOLKIT && not USE_GTK */
10089 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
10090 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10092 #endif /* not USE_X_TOOLKIT && not USE_GTK */
10096 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10098 int icon_x
, icon_y
;
10100 Window window
= FRAME_OUTER_WINDOW (f
);
10102 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
10103 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
10104 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
10106 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10110 /***********************************************************************
10112 ***********************************************************************/
10114 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
10117 x_get_font_info (f
, font_idx
)
10121 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
10125 /* Return a list of names of available fonts matching PATTERN on frame F.
10127 If SIZE is > 0, it is the size (maximum bounds width) of fonts
10130 SIZE < 0 means include auto scaled fonts.
10132 Frame F null means we have not yet created any frame on X, and
10133 consult the first display in x_display_list. MAXNAMES sets a limit
10134 on how many fonts to match. */
10137 x_list_fonts (f
, pattern
, size
, maxnames
)
10139 Lisp_Object pattern
;
10143 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
10144 Lisp_Object tem
, second_best
;
10145 struct x_display_info
*dpyinfo
10146 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
10147 Display
*dpy
= dpyinfo
->display
;
10148 int try_XLoadQueryFont
= 0;
10149 int allow_auto_scaled_font
= 0;
10153 allow_auto_scaled_font
= 1;
10157 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
10158 if (NILP (patterns
))
10159 patterns
= Fcons (pattern
, Qnil
);
10161 if (maxnames
== 1 && !size
)
10162 /* We can return any single font matching PATTERN. */
10163 try_XLoadQueryFont
= 1;
10165 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
10168 char **names
= NULL
;
10170 pattern
= XCAR (patterns
);
10171 /* See if we cached the result for this particular query.
10172 The cache is an alist of the form:
10173 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
10174 tem
= XCDR (dpyinfo
->name_list_element
);
10175 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
10176 allow_auto_scaled_font
? Qt
: Qnil
);
10177 list
= Fassoc (key
, tem
);
10180 list
= Fcdr_safe (list
);
10181 /* We have a cashed list. Don't have to get the list again. */
10185 /* At first, put PATTERN in the cache. */
10188 x_catch_errors (dpy
);
10190 if (try_XLoadQueryFont
)
10193 unsigned long value
;
10195 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
10196 if (x_had_errors_p (dpy
))
10198 /* This error is perhaps due to insufficient memory on X
10199 server. Let's just ignore it. */
10201 x_clear_errors (dpy
);
10205 && XGetFontProperty (font
, XA_FONT
, &value
))
10207 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
10208 int len
= strlen (name
);
10211 /* If DXPC (a Differential X Protocol Compressor)
10212 Ver.3.7 is running, XGetAtomName will return null
10213 string. We must avoid such a name. */
10215 try_XLoadQueryFont
= 0;
10219 names
= (char **) alloca (sizeof (char *));
10220 /* Some systems only allow alloca assigned to a
10222 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
10223 bcopy (name
, names
[0], len
+ 1);
10228 try_XLoadQueryFont
= 0;
10231 XFreeFont (dpy
, font
);
10234 if (!try_XLoadQueryFont
)
10236 /* We try at least 10 fonts because XListFonts will return
10237 auto-scaled fonts at the head. */
10242 for (limit
= 500;;)
10244 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
10245 if (num_fonts
== limit
)
10248 XFreeFontNames (names
);
10257 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
10260 if (x_had_errors_p (dpy
))
10262 /* This error is perhaps due to insufficient memory on X
10263 server. Let's just ignore it. */
10265 x_clear_errors (dpy
);
10269 x_uncatch_errors ();
10276 /* Make a list of all the fonts we got back.
10277 Store that in the font cache for the display. */
10278 for (i
= 0; i
< num_fonts
; i
++)
10281 char *p
= names
[i
];
10282 int average_width
= -1, resx
= 0, dashes
= 0;
10284 /* Count the number of dashes in NAMES[I]. If there are
10285 14 dashes, the field value following 9th dash
10286 (RESOLUTION_X) is nonzero, and the field value
10287 following 12th dash (AVERAGE_WIDTH) is 0, this is a
10288 auto-scaled font which is usually too ugly to be used
10289 for editing. Let's ignore it. */
10294 if (dashes
== 7) /* PIXEL_SIZE field */
10296 else if (dashes
== 9)
10298 else if (dashes
== 12) /* AVERAGE_WIDTH field */
10299 average_width
= atoi (p
);
10302 if (allow_auto_scaled_font
10303 || dashes
< 14 || average_width
!= 0 || resx
== 0)
10305 tem
= build_string (names
[i
]);
10306 if (NILP (Fassoc (tem
, list
)))
10308 if (STRINGP (Vx_pixel_size_width_font_regexp
)
10309 && ((fast_c_string_match_ignore_case
10310 (Vx_pixel_size_width_font_regexp
, names
[i
]))
10312 /* We can set the value of PIXEL_SIZE to the
10313 width of this font. */
10314 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
10316 /* For the moment, width is not known. */
10317 list
= Fcons (Fcons (tem
, Qnil
), list
);
10322 if (!try_XLoadQueryFont
)
10325 XFreeFontNames (names
);
10330 /* Now store the result in the cache. */
10331 XSETCDR (dpyinfo
->name_list_element
,
10332 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
10335 if (NILP (list
)) continue; /* Try the remaining alternatives. */
10337 newlist
= second_best
= Qnil
;
10338 /* Make a list of the fonts that have the right width. */
10339 for (; CONSP (list
); list
= XCDR (list
))
10345 if (!CONSP (tem
) || NILP (XCAR (tem
)))
10349 newlist
= Fcons (XCAR (tem
), newlist
);
10353 if (!INTEGERP (XCDR (tem
)))
10355 /* Since we have not yet known the size of this font, we
10356 must try slow function call XLoadQueryFont. */
10357 XFontStruct
*thisinfo
;
10360 x_catch_errors (dpy
);
10361 thisinfo
= XLoadQueryFont (dpy
,
10362 SDATA (XCAR (tem
)));
10363 if (x_had_errors_p (dpy
))
10365 /* This error is perhaps due to insufficient memory on X
10366 server. Let's just ignore it. */
10368 x_clear_errors (dpy
);
10370 x_uncatch_errors ();
10376 (thisinfo
->min_bounds
.width
== 0
10378 : make_number (thisinfo
->max_bounds
.width
)));
10380 XFreeFont (dpy
, thisinfo
);
10384 /* For unknown reason, the previous call of XListFont had
10385 returned a font which can't be opened. Record the size
10386 as 0 not to try to open it again. */
10387 XSETCDR (tem
, make_number (0));
10390 found_size
= XINT (XCDR (tem
));
10391 if (found_size
== size
)
10392 newlist
= Fcons (XCAR (tem
), newlist
);
10393 else if (found_size
> 0)
10395 if (NILP (second_best
))
10397 else if (found_size
< size
)
10399 if (XINT (XCDR (second_best
)) > size
10400 || XINT (XCDR (second_best
)) < found_size
)
10405 if (XINT (XCDR (second_best
)) > size
10406 && XINT (XCDR (second_best
)) > found_size
)
10411 if (!NILP (newlist
))
10413 else if (!NILP (second_best
))
10415 newlist
= Fcons (XCAR (second_best
), Qnil
);
10426 /* Check that FONT is valid on frame F. It is if it can be found in F's
10430 x_check_font (f
, font
)
10435 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10437 xassert (font
!= NULL
);
10439 #ifdef USE_FONT_BACKEND
10440 if (enable_font_backend
)
10441 /* Fixme: Perhaps we should check all cached fonts. */
10444 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10445 if (dpyinfo
->font_table
[i
].name
10446 && font
== dpyinfo
->font_table
[i
].font
)
10449 xassert (i
< dpyinfo
->n_fonts
);
10452 #endif /* GLYPH_DEBUG != 0 */
10454 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10455 Note: There are (broken) X fonts out there with invalid XFontStruct
10456 min_bounds contents. For example, handa@etl.go.jp reports that
10457 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10458 have font->min_bounds.width == 0. */
10461 x_font_min_bounds (font
, w
, h
)
10465 *h
= FONT_HEIGHT (font
);
10466 *w
= font
->min_bounds
.width
;
10468 /* Try to handle the case where FONT->min_bounds has invalid
10469 contents. Since the only font known to have invalid min_bounds
10470 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
10472 *w
= font
->max_bounds
.width
;
10476 /* Compute the smallest character width and smallest font height over
10477 all fonts available on frame F. Set the members smallest_char_width
10478 and smallest_font_height in F's x_display_info structure to
10479 the values computed. Value is non-zero if smallest_font_height or
10480 smallest_char_width become smaller than they were before. */
10483 x_compute_min_glyph_bounds (f
)
10487 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10489 int old_width
= dpyinfo
->smallest_char_width
;
10490 int old_height
= dpyinfo
->smallest_font_height
;
10492 dpyinfo
->smallest_font_height
= 100000;
10493 dpyinfo
->smallest_char_width
= 100000;
10495 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10496 if (dpyinfo
->font_table
[i
].name
)
10498 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10501 font
= (XFontStruct
*) fontp
->font
;
10502 xassert (font
!= (XFontStruct
*) ~0);
10503 x_font_min_bounds (font
, &w
, &h
);
10505 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10506 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10509 xassert (dpyinfo
->smallest_char_width
> 0
10510 && dpyinfo
->smallest_font_height
> 0);
10512 return (dpyinfo
->n_fonts
== 1
10513 || dpyinfo
->smallest_char_width
< old_width
10514 || dpyinfo
->smallest_font_height
< old_height
);
10518 /* Load font named FONTNAME of the size SIZE for frame F, and return a
10519 pointer to the structure font_info while allocating it dynamically.
10520 If SIZE is 0, load any size of font.
10521 If loading is failed, return NULL. */
10524 x_load_font (f
, fontname
, size
)
10526 register char *fontname
;
10529 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10530 Lisp_Object font_names
;
10532 /* Get a list of all the fonts that match this name. Once we
10533 have a list of matching fonts, we compare them against the fonts
10534 we already have by comparing names. */
10535 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
10537 if (!NILP (font_names
))
10542 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10543 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
10544 if (dpyinfo
->font_table
[i
].name
10545 && (!strcmp (dpyinfo
->font_table
[i
].name
,
10546 SDATA (XCAR (tail
)))
10547 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
10548 SDATA (XCAR (tail
)))))
10549 return (dpyinfo
->font_table
+ i
);
10552 /* Load the font and add it to the table. */
10556 struct font_info
*fontp
;
10557 unsigned long value
;
10560 /* If we have found fonts by x_list_font, load one of them. If
10561 not, we still try to load a font by the name given as FONTNAME
10562 because XListFonts (called in x_list_font) of some X server has
10563 a bug of not finding a font even if the font surely exists and
10564 is loadable by XLoadQueryFont. */
10565 if (size
> 0 && !NILP (font_names
))
10566 fontname
= (char *) SDATA (XCAR (font_names
));
10569 x_catch_errors (FRAME_X_DISPLAY (f
));
10570 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
10571 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
10573 /* This error is perhaps due to insufficient memory on X
10574 server. Let's just ignore it. */
10576 x_clear_errors (FRAME_X_DISPLAY (f
));
10578 x_uncatch_errors ();
10583 /* Find a free slot in the font table. */
10584 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10585 if (dpyinfo
->font_table
[i
].name
== NULL
)
10588 /* If no free slot found, maybe enlarge the font table. */
10589 if (i
== dpyinfo
->n_fonts
10590 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
10593 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
10594 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
10595 dpyinfo
->font_table
10596 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
10599 fontp
= dpyinfo
->font_table
+ i
;
10600 if (i
== dpyinfo
->n_fonts
)
10601 ++dpyinfo
->n_fonts
;
10603 /* Now fill in the slots of *FONTP. */
10605 bzero (fontp
, sizeof (*fontp
));
10606 fontp
->font
= font
;
10607 fontp
->font_idx
= i
;
10608 fontp
->charset
= -1; /* fs_load_font sets it. */
10609 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
10610 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
10612 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
10614 /* Fixed width font. */
10615 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
10622 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
10623 pcm
= x_per_char_metric (font
, &char2b
, 0);
10625 fontp
->space_width
= pcm
->width
;
10627 fontp
->space_width
= FONT_WIDTH (font
);
10629 fontp
->average_width
10630 = (XGetFontProperty (font
, dpyinfo
->Xatom_AVERAGE_WIDTH
, &value
)
10631 ? (long) value
/ 10 : 0);
10632 if (fontp
->average_width
< 0)
10633 fontp
->average_width
= - fontp
->average_width
;
10634 if (fontp
->average_width
== 0)
10638 int width
= pcm
->width
;
10639 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
10640 if ((pcm
= x_per_char_metric (font
, &char2b
, 0)) != NULL
)
10641 width
+= pcm
->width
;
10642 fontp
->average_width
= width
/ 95;
10645 fontp
->average_width
= FONT_WIDTH (font
);
10649 /* Try to get the full name of FONT. Put it in FULL_NAME. */
10651 if (XGetFontProperty (font
, XA_FONT
, &value
))
10653 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
10657 /* Count the number of dashes in the "full name".
10658 If it is too few, this isn't really the font's full name,
10660 In X11R4, the fonts did not come with their canonical names
10671 full_name
= (char *) xmalloc (p
- name
+ 1);
10672 bcopy (name
, full_name
, p
- name
+ 1);
10678 if (full_name
!= 0)
10679 fontp
->full_name
= full_name
;
10681 fontp
->full_name
= fontp
->name
;
10683 fontp
->size
= font
->max_bounds
.width
;
10684 fontp
->height
= FONT_HEIGHT (font
);
10686 if (NILP (font_names
))
10688 /* We come here because of a bug of XListFonts mentioned at
10689 the head of this block. Let's store this information in
10690 the cache for x_list_fonts. */
10691 Lisp_Object lispy_name
= build_string (fontname
);
10692 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
10693 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
10696 XSETCDR (dpyinfo
->name_list_element
,
10698 Fcons (Fcons (lispy_full_name
,
10699 make_number (fontp
->size
)),
10701 XCDR (dpyinfo
->name_list_element
)));
10704 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
10706 XSETCDR (dpyinfo
->name_list_element
,
10708 Fcons (Fcons (lispy_full_name
,
10709 make_number (fontp
->size
)),
10711 XCDR (dpyinfo
->name_list_element
)));
10715 /* The slot `encoding' specifies how to map a character
10716 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
10717 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
10718 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
10719 2:0xA020..0xFF7F). For the moment, we don't know which charset
10720 uses this font. So, we set information in fontp->encoding_type
10721 which is never used by any charset. If mapping can't be
10722 decided, set FONT_ENCODING_NOT_DECIDED. */
10723 fontp
->encoding_type
10724 = (font
->max_byte1
== 0
10726 ? (font
->min_char_or_byte2
< 0x80
10727 ? (font
->max_char_or_byte2
< 0x80
10728 ? 0 /* 0x20..0x7F */
10729 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
10730 : 1) /* 0xA0..0xFF */
10732 : (font
->min_byte1
< 0x80
10733 ? (font
->max_byte1
< 0x80
10734 ? (font
->min_char_or_byte2
< 0x80
10735 ? (font
->max_char_or_byte2
< 0x80
10736 ? 0 /* 0x2020..0x7F7F */
10737 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
10738 : 3) /* 0x20A0..0x7FFF */
10739 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
10740 : (font
->min_char_or_byte2
< 0x80
10741 ? (font
->max_char_or_byte2
< 0x80
10742 ? 2 /* 0xA020..0xFF7F */
10743 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
10744 : 1))); /* 0xA0A0..0xFFFF */
10746 fontp
->baseline_offset
10747 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
10748 ? (long) value
: 0);
10749 fontp
->relative_compose
10750 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
10751 ? (long) value
: 0);
10752 fontp
->default_ascent
10753 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
10754 ? (long) value
: 0);
10756 /* Set global flag fonts_changed_p to non-zero if the font loaded
10757 has a character with a smaller width than any other character
10758 before, or if the font loaded has a smaller height than any
10759 other font loaded before. If this happens, it will make a
10760 glyph matrix reallocation necessary. */
10761 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
10768 /* Return a pointer to struct font_info of a font named FONTNAME for
10769 frame F. If no such font is loaded, return NULL. */
10772 x_query_font (f
, fontname
)
10774 register char *fontname
;
10776 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10779 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10780 if (dpyinfo
->font_table
[i
].name
10781 && (!xstricmp (dpyinfo
->font_table
[i
].name
, fontname
)
10782 || !xstricmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
10783 return (dpyinfo
->font_table
+ i
);
10788 /* Find a CCL program for a font specified by FONTP, and set the member
10789 `encoder' of the structure. */
10792 x_find_ccl_program (fontp
)
10793 struct font_info
*fontp
;
10795 Lisp_Object list
, elt
;
10798 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
10802 && STRINGP (XCAR (elt
))
10803 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
10805 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
10812 struct ccl_program
*ccl
10813 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
10815 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
10818 fontp
->font_encoder
= ccl
;
10823 /* Return a char-table whose elements are t if the font FONT_INFO
10824 contains a glyph for the corresponding character, and nil if
10828 x_get_font_repertory (f
, font_info
)
10830 struct font_info
*font_info
;
10832 XFontStruct
*font
= (XFontStruct
*) font_info
->font
;
10834 int min_byte1
, max_byte1
, min_byte2
, max_byte2
;
10836 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
10837 int offset
= CHARSET_OFFSET (charset
);
10839 table
= Fmake_char_table (Qnil
, Qnil
);
10841 min_byte1
= font
->min_byte1
;
10842 max_byte1
= font
->max_byte1
;
10843 min_byte2
= font
->min_char_or_byte2
;
10844 max_byte2
= font
->max_char_or_byte2
;
10845 if (min_byte1
== 0 && max_byte1
== 0)
10847 if (! font
->per_char
|| font
->all_chars_exist
== True
)
10850 char_table_set_range (table
, offset
+ min_byte2
,
10851 offset
+ max_byte2
, Qt
);
10853 for (; min_byte2
<= max_byte2
; min_byte2
++)
10855 c
= DECODE_CHAR (charset
, min_byte2
);
10856 CHAR_TABLE_SET (table
, c
, Qt
);
10861 XCharStruct
*pcm
= font
->per_char
;
10865 for (i
= min_byte2
; i
<= max_byte2
; i
++, pcm
++)
10867 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
10872 char_table_set_range (table
, offset
+ from
,
10873 offset
+ i
- 1, Qt
);
10875 for (; from
< i
; from
++)
10877 c
= DECODE_CHAR (charset
, from
);
10878 CHAR_TABLE_SET (table
, c
, Qt
);
10889 char_table_set_range (table
, offset
+ from
, offset
+ i
- 1,
10892 for (; from
< i
; from
++)
10894 c
= DECODE_CHAR (charset
, from
);
10895 CHAR_TABLE_SET (table
, c
, Qt
);
10902 if (! font
->per_char
|| font
->all_chars_exist
== True
)
10907 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10908 char_table_set_range
10909 (table
, offset
+ ((i
<< 8) | min_byte2
),
10910 offset
+ ((i
<< 8) | max_byte2
), Qt
);
10912 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10913 for (j
= min_byte2
; j
<= max_byte2
; j
++)
10915 unsigned code
= (i
<< 8) | j
;
10916 c
= DECODE_CHAR (charset
, code
);
10917 CHAR_TABLE_SET (table
, c
, Qt
);
10922 XCharStruct
*pcm
= font
->per_char
;
10925 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10930 for (j
= min_byte2
; j
<= max_byte2
; j
++, pcm
++)
10932 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
10937 char_table_set_range
10938 (table
, offset
+ ((i
<< 8) | from
),
10939 offset
+ ((i
<< 8) | (j
- 1)), Qt
);
10942 for (; from
< j
; from
++)
10944 unsigned code
= (i
<< 8) | from
;
10945 c
= ENCODE_CHAR (charset
, code
);
10946 CHAR_TABLE_SET (table
, c
, Qt
);
10958 char_table_set_range
10959 (table
, offset
+ ((i
<< 8) | from
),
10960 offset
+ ((i
<< 8) | (j
- 1)), Qt
);
10963 for (; from
< j
; from
++)
10965 unsigned code
= (i
<< 8) | from
;
10966 c
= DECODE_CHAR (charset
, code
);
10967 CHAR_TABLE_SET (table
, c
, Qt
);
10978 /***********************************************************************
10980 ***********************************************************************/
10982 #ifdef USE_X_TOOLKIT
10983 static XrmOptionDescRec emacs_options
[] = {
10984 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
10985 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
10987 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
10988 XrmoptionSepArg
, NULL
},
10989 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
10991 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10992 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10993 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10994 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10995 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10996 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
10997 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
11000 /* Whether atimer for Xt timeouts is activated or not. */
11002 static int x_timeout_atimer_activated_flag
;
11004 #endif /* USE_X_TOOLKIT */
11006 static int x_initialized
;
11009 static int x_session_initialized
;
11012 #ifdef MULTI_KBOARD
11013 /* Test whether two display-name strings agree up to the dot that separates
11014 the screen number from the server number. */
11016 same_x_server (name1
, name2
)
11017 const char *name1
, *name2
;
11019 int seen_colon
= 0;
11020 const unsigned char *system_name
= SDATA (Vsystem_name
);
11021 int system_name_length
= strlen (system_name
);
11022 int length_until_period
= 0;
11024 while (system_name
[length_until_period
] != 0
11025 && system_name
[length_until_period
] != '.')
11026 length_until_period
++;
11028 /* Treat `unix' like an empty host name. */
11029 if (! strncmp (name1
, "unix:", 5))
11031 if (! strncmp (name2
, "unix:", 5))
11033 /* Treat this host's name like an empty host name. */
11034 if (! strncmp (name1
, system_name
, system_name_length
)
11035 && name1
[system_name_length
] == ':')
11036 name1
+= system_name_length
;
11037 if (! strncmp (name2
, system_name
, system_name_length
)
11038 && name2
[system_name_length
] == ':')
11039 name2
+= system_name_length
;
11040 /* Treat this host's domainless name like an empty host name. */
11041 if (! strncmp (name1
, system_name
, length_until_period
)
11042 && name1
[length_until_period
] == ':')
11043 name1
+= length_until_period
;
11044 if (! strncmp (name2
, system_name
, length_until_period
)
11045 && name2
[length_until_period
] == ':')
11046 name2
+= length_until_period
;
11048 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
11052 if (seen_colon
&& *name1
== '.')
11056 && (*name1
== '.' || *name1
== '\0')
11057 && (*name2
== '.' || *name2
== '\0'));
11061 /* Count number of set bits in mask and number of bits to shift to
11062 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
11065 get_bits_and_offset (mask
, bits
, offset
)
11066 unsigned long mask
;
11073 while (!(mask
& 1))
11089 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
11090 But don't permanently open it, just test its availability. */
11093 x_display_ok (display
)
11094 const char *display
;
11099 dpy
= XOpenDisplay (display
);
11101 XCloseDisplay (dpy
);
11107 /* Open a connection to X display DISPLAY_NAME, and return
11108 the structure that describes the open display.
11109 If we cannot contact the display, return null. */
11111 struct x_display_info
*
11112 x_term_init (display_name
, xrm_option
, resource_name
)
11113 Lisp_Object display_name
;
11115 char *resource_name
;
11119 struct terminal
*terminal
;
11120 struct x_display_info
*dpyinfo
;
11125 if (!x_initialized
)
11131 if (! x_display_ok (SDATA (display_name
)))
11132 error ("Display %s can't be opened", SDATA (display_name
));
11136 #define NUM_ARGV 10
11138 char *argv
[NUM_ARGV
];
11139 char **argv2
= argv
;
11142 #ifndef HAVE_GTK_MULTIDISPLAY
11143 if (!EQ (Vinitial_window_system
, intern ("x")))
11144 error ("Sorry, you cannot connect to X servers with the GTK toolkit");
11147 if (x_initialized
++ > 1)
11149 #ifdef HAVE_GTK_MULTIDISPLAY
11150 /* Opening another display. If xg_display_open returns less
11151 than zero, we are probably on GTK 2.0, which can only handle
11152 one display. GTK 2.2 or later can handle more than one. */
11153 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
11155 error ("Sorry, this version of GTK can only handle one display");
11159 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
11163 argv
[argc
++] = initial_argv
[0];
11165 if (! NILP (display_name
))
11167 argv
[argc
++] = "--display";
11168 argv
[argc
++] = SDATA (display_name
);
11171 argv
[argc
++] = "--name";
11172 argv
[argc
++] = resource_name
;
11174 XSetLocaleModifiers ("");
11176 gtk_init (&argc
, &argv2
);
11178 /* gtk_init does set_locale. We must fix locale after calling it. */
11182 dpy
= GDK_DISPLAY ();
11184 /* NULL window -> events for all windows go to our function */
11185 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
11187 /* Load our own gtkrc if it exists. */
11189 char *file
= "~/.emacs.d/gtkrc";
11190 Lisp_Object s
, abs_file
;
11192 s
= make_string (file
, strlen (file
));
11193 abs_file
= Fexpand_file_name (s
, Qnil
);
11195 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
11196 gtk_rc_parse (SDATA (abs_file
));
11199 XSetErrorHandler (x_error_handler
);
11200 XSetIOErrorHandler (x_io_error_quitter
);
11203 #else /* not USE_GTK */
11204 #ifdef USE_X_TOOLKIT
11205 /* weiner@footloose.sps.mot.com reports that this causes
11207 X protocol error: BadAtom (invalid Atom parameter)
11208 on protocol request 18skiloaf.
11209 So let's not use it until R6. */
11210 #ifdef HAVE_X11XTR6
11211 XtSetLanguageProc (NULL
, NULL
, NULL
);
11222 argv
[argc
++] = "-xrm";
11223 argv
[argc
++] = xrm_option
;
11225 turn_on_atimers (0);
11226 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
11227 resource_name
, EMACS_CLASS
,
11228 emacs_options
, XtNumber (emacs_options
),
11230 turn_on_atimers (1);
11232 #ifdef HAVE_X11XTR6
11233 /* I think this is to compensate for XtSetLanguageProc. */
11238 #else /* not USE_X_TOOLKIT */
11239 XSetLocaleModifiers ("");
11240 dpy
= XOpenDisplay (SDATA (display_name
));
11241 #endif /* not USE_X_TOOLKIT */
11242 #endif /* not USE_GTK*/
11244 /* Detect failure. */
11251 /* We have definitely succeeded. Record the new connection. */
11253 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
11254 bzero (dpyinfo
, sizeof *dpyinfo
);
11256 terminal
= x_create_terminal (dpyinfo
);
11258 #ifdef MULTI_KBOARD
11260 struct x_display_info
*share
;
11263 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
11264 share
= share
->next
, tail
= XCDR (tail
))
11265 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
11266 SDATA (display_name
)))
11269 terminal
->kboard
= share
->terminal
->kboard
;
11272 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
11273 init_kboard (terminal
->kboard
);
11274 terminal
->kboard
->Vwindow_system
= intern ("x");
11275 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
11277 char *vendor
= ServerVendor (dpy
);
11279 terminal
->kboard
->Vsystem_key_alist
11280 = call1 (Qvendor_specific_keysyms
,
11281 vendor
? build_string (vendor
) : empty_unibyte_string
);
11285 terminal
->kboard
->next_kboard
= all_kboards
;
11286 all_kboards
= terminal
->kboard
;
11287 /* Don't let the initial kboard remain current longer than necessary.
11288 That would cause problems if a file loaded on startup tries to
11289 prompt in the mini-buffer. */
11290 if (current_kboard
== initial_kboard
)
11291 current_kboard
= terminal
->kboard
;
11293 terminal
->kboard
->reference_count
++;
11297 /* Put this display on the chain. */
11298 dpyinfo
->next
= x_display_list
;
11299 x_display_list
= dpyinfo
;
11301 /* Put it on x_display_name_list as well, to keep them parallel. */
11302 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
11303 x_display_name_list
);
11304 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
11306 dpyinfo
->display
= dpy
;
11308 /* Set the name of the terminal. */
11309 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
11310 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
11311 terminal
->name
[SBYTES (display_name
)] = 0;
11314 XSetAfterFunction (x_current_display
, x_trace_wire
);
11318 = (char *) xmalloc (SBYTES (Vinvocation_name
)
11319 + SBYTES (Vsystem_name
)
11321 sprintf (dpyinfo
->x_id_name
, "%s@%s",
11322 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
11324 /* Figure out which modifier bits mean what. */
11325 x_find_modifier_meanings (dpyinfo
);
11327 /* Get the scroll bar cursor. */
11329 /* We must create a GTK cursor, it is required for GTK widgets. */
11330 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
11331 #endif /* USE_GTK */
11333 dpyinfo
->vertical_scroll_bar_cursor
11334 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
11336 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
11337 resource_name
, EMACS_CLASS
);
11338 #ifdef HAVE_XRMSETDATABASE
11339 XrmSetDatabase (dpyinfo
->display
, xrdb
);
11341 dpyinfo
->display
->db
= xrdb
;
11343 /* Put the rdb where we can find it in a way that works on
11345 dpyinfo
->xrdb
= xrdb
;
11347 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
11348 DefaultScreen (dpyinfo
->display
));
11349 select_visual (dpyinfo
);
11350 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
11351 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
11352 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
11353 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
11354 dpyinfo
->client_leader_window
= 0;
11355 dpyinfo
->grabbed
= 0;
11356 dpyinfo
->reference_count
= 0;
11357 dpyinfo
->icon_bitmap_id
= -1;
11358 dpyinfo
->font_table
= NULL
;
11359 dpyinfo
->n_fonts
= 0;
11360 dpyinfo
->font_table_size
= 0;
11361 dpyinfo
->bitmaps
= 0;
11362 dpyinfo
->bitmaps_size
= 0;
11363 dpyinfo
->bitmaps_last
= 0;
11364 dpyinfo
->scratch_cursor_gc
= 0;
11365 dpyinfo
->mouse_face_mouse_frame
= 0;
11366 dpyinfo
->mouse_face_deferred_gc
= 0;
11367 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
11368 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
11369 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
11370 dpyinfo
->mouse_face_window
= Qnil
;
11371 dpyinfo
->mouse_face_overlay
= Qnil
;
11372 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
11373 dpyinfo
->mouse_face_defer
= 0;
11374 dpyinfo
->mouse_face_hidden
= 0;
11375 dpyinfo
->x_focus_frame
= 0;
11376 dpyinfo
->x_focus_event_frame
= 0;
11377 dpyinfo
->x_highlight_frame
= 0;
11378 dpyinfo
->image_cache
= make_image_cache ();
11379 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
11381 /* See if we can construct pixel values from RGB values. */
11382 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
11383 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
11385 if (dpyinfo
->visual
->class == TrueColor
)
11387 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
11388 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
11389 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
11390 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
11391 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
11392 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
11395 /* See if a private colormap is requested. */
11396 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
11398 if (dpyinfo
->visual
->class == PseudoColor
)
11401 value
= display_x_get_resource (dpyinfo
,
11402 build_string ("privateColormap"),
11403 build_string ("PrivateColormap"),
11405 if (STRINGP (value
)
11406 && (!strcmp (SDATA (value
), "true")
11407 || !strcmp (SDATA (value
), "on")))
11408 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
11412 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
11413 dpyinfo
->visual
, AllocNone
);
11416 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
11417 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
11418 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
11419 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
11420 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
11421 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
11422 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
11423 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
11424 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
11427 dpyinfo
->Xatom_wm_protocols
11428 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
11429 dpyinfo
->Xatom_wm_take_focus
11430 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
11431 dpyinfo
->Xatom_wm_save_yourself
11432 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
11433 dpyinfo
->Xatom_wm_delete_window
11434 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
11435 dpyinfo
->Xatom_wm_change_state
11436 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
11437 dpyinfo
->Xatom_wm_configure_denied
11438 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
11439 dpyinfo
->Xatom_wm_window_moved
11440 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
11441 dpyinfo
->Xatom_wm_client_leader
11442 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
11443 dpyinfo
->Xatom_editres
11444 = XInternAtom (dpyinfo
->display
, "Editres", False
);
11445 dpyinfo
->Xatom_CLIPBOARD
11446 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
11447 dpyinfo
->Xatom_TIMESTAMP
11448 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
11449 dpyinfo
->Xatom_TEXT
11450 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
11451 dpyinfo
->Xatom_COMPOUND_TEXT
11452 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
11453 dpyinfo
->Xatom_UTF8_STRING
11454 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
11455 dpyinfo
->Xatom_DELETE
11456 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
11457 dpyinfo
->Xatom_MULTIPLE
11458 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
11459 dpyinfo
->Xatom_INCR
11460 = XInternAtom (dpyinfo
->display
, "INCR", False
);
11461 dpyinfo
->Xatom_EMACS_TMP
11462 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
11463 dpyinfo
->Xatom_TARGETS
11464 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
11465 dpyinfo
->Xatom_NULL
11466 = XInternAtom (dpyinfo
->display
, "NULL", False
);
11467 dpyinfo
->Xatom_ATOM_PAIR
11468 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
11469 /* For properties of font. */
11470 dpyinfo
->Xatom_PIXEL_SIZE
11471 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
11472 dpyinfo
->Xatom_AVERAGE_WIDTH
11473 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
11474 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
11475 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
11476 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
11477 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
11478 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
11479 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
11481 /* Ghostscript support. */
11482 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
11483 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
11485 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
11488 dpyinfo
->Xatom_XEMBED
= XInternAtom (dpyinfo
->display
, "_XEMBED",
11491 dpyinfo
->cut_buffers_initialized
= 0;
11493 dpyinfo
->x_dnd_atoms_size
= 8;
11494 dpyinfo
->x_dnd_atoms_length
= 0;
11495 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
11496 * dpyinfo
->x_dnd_atoms_size
);
11498 dpyinfo
->net_supported_atoms
= NULL
;
11499 dpyinfo
->nr_net_supported_atoms
= 0;
11500 dpyinfo
->net_supported_window
= 0;
11502 connection
= ConnectionNumber (dpyinfo
->display
);
11503 dpyinfo
->connection
= connection
;
11508 null_bits
[0] = 0x00;
11510 dpyinfo
->null_pixel
11511 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
11512 null_bits
, 1, 1, (long) 0, (long) 0,
11517 extern int gray_bitmap_width
, gray_bitmap_height
;
11518 extern char *gray_bitmap_bits
;
11520 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
11522 gray_bitmap_width
, gray_bitmap_height
,
11523 (unsigned long) 1, (unsigned long) 0, 1);
11527 xim_initialize (dpyinfo
, resource_name
);
11530 #ifdef subprocesses
11531 /* This is only needed for distinguishing keyboard and process input. */
11532 if (connection
!= 0)
11533 add_keyboard_wait_descriptor (connection
);
11537 fcntl (connection
, F_SETOWN
, getpid ());
11538 #endif /* ! defined (F_SETOWN) */
11541 if (interrupt_input
)
11542 init_sigio (connection
);
11543 #endif /* ! defined (SIGIO) */
11547 Display
*dpy
= dpyinfo
->display
;
11548 XrmValue d
, fr
, to
;
11551 d
.addr
= (XPointer
)&dpy
;
11552 d
.size
= sizeof (Display
*);
11553 fr
.addr
= XtDefaultFont
;
11554 fr
.size
= sizeof (XtDefaultFont
);
11555 to
.size
= sizeof (Font
*);
11556 to
.addr
= (XPointer
)&font
;
11557 x_catch_errors (dpy
);
11558 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
11560 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
11561 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
11562 x_uncatch_errors ();
11566 /* See if we should run in synchronous mode. This is useful
11567 for debugging X code. */
11570 value
= display_x_get_resource (dpyinfo
,
11571 build_string ("synchronous"),
11572 build_string ("Synchronous"),
11574 if (STRINGP (value
)
11575 && (!strcmp (SDATA (value
), "true")
11576 || !strcmp (SDATA (value
), "on")))
11577 XSynchronize (dpyinfo
->display
, True
);
11582 value
= display_x_get_resource (dpyinfo
,
11583 build_string ("useXIM"),
11584 build_string ("UseXIM"),
11587 if (STRINGP (value
)
11588 && (!strcmp (SDATA (value
), "false")
11589 || !strcmp (SDATA (value
), "off")))
11592 if (STRINGP (value
)
11593 && (!strcmp (SDATA (value
), "true")
11594 || !strcmp (SDATA (value
), "on")))
11600 /* Only do this for the very first display in the Emacs session.
11601 Ignore X session management when Emacs was first started on a
11603 if (terminal
->id
== 1)
11604 x_session_initialize (dpyinfo
);
11612 /* Get rid of display DPYINFO, deleting all frames on it,
11613 and without sending any more commands to the X server. */
11616 x_delete_display (dpyinfo
)
11617 struct x_display_info
*dpyinfo
;
11620 struct terminal
*t
;
11622 /* Close all frames and delete the generic struct terminal for this
11624 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
11625 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
11628 /* Close X session management when we close its display. */
11629 if (t
->id
== 1 && x_session_have_connection ())
11632 delete_terminal (t
);
11636 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
11638 /* Discard this display from x_display_name_list and x_display_list.
11639 We can't use Fdelq because that can quit. */
11640 if (! NILP (x_display_name_list
)
11641 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
11642 x_display_name_list
= XCDR (x_display_name_list
);
11647 tail
= x_display_name_list
;
11648 while (CONSP (tail
) && CONSP (XCDR (tail
)))
11650 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
11652 XSETCDR (tail
, XCDR (XCDR (tail
)));
11655 tail
= XCDR (tail
);
11659 if (next_noop_dpyinfo
== dpyinfo
)
11660 next_noop_dpyinfo
= dpyinfo
->next
;
11662 if (x_display_list
== dpyinfo
)
11663 x_display_list
= dpyinfo
->next
;
11666 struct x_display_info
*tail
;
11668 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
11669 if (tail
->next
== dpyinfo
)
11670 tail
->next
= tail
->next
->next
;
11673 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
11674 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
11675 XrmDestroyDatabase (dpyinfo
->xrdb
);
11680 xim_close_dpy (dpyinfo
);
11683 #ifdef USE_FONT_BACKEND
11684 if (! enable_font_backend
)
11687 /* Free the font names in the font table. */
11688 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11689 if (dpyinfo
->font_table
[i
].name
)
11691 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
11692 xfree (dpyinfo
->font_table
[i
].full_name
);
11693 xfree (dpyinfo
->font_table
[i
].name
);
11696 if (dpyinfo
->font_table
)
11698 if (dpyinfo
->font_table
->font_encoder
)
11699 xfree (dpyinfo
->font_table
->font_encoder
);
11700 xfree (dpyinfo
->font_table
);
11702 #ifdef USE_FONT_BACKEND
11706 if (dpyinfo
->x_id_name
)
11707 xfree (dpyinfo
->x_id_name
);
11708 if (dpyinfo
->color_cells
)
11709 xfree (dpyinfo
->color_cells
);
11713 #ifdef USE_X_TOOLKIT
11715 /* Atimer callback function for TIMER. Called every 0.1s to process
11716 Xt timeouts, if needed. We must avoid calling XtAppPending as
11717 much as possible because that function does an implicit XFlush
11718 that slows us down. */
11721 x_process_timeouts (timer
)
11722 struct atimer
*timer
;
11725 x_timeout_atimer_activated_flag
= 0;
11726 if (toolkit_scroll_bar_interaction
|| popup_activated ())
11728 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
11729 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
11730 /* Reactivate the atimer for next time. */
11731 x_activate_timeout_atimer ();
11736 /* Install an asynchronous timer that processes Xt timeout events
11737 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
11738 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
11739 function whenever these variables are set. This is necessary
11740 because some widget sets use timeouts internally, for example the
11741 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
11742 processed, these widgets don't behave normally. */
11745 x_activate_timeout_atimer ()
11748 if (!x_timeout_atimer_activated_flag
)
11750 EMACS_TIME interval
;
11752 EMACS_SET_SECS_USECS (interval
, 0, 100000);
11753 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
11754 x_timeout_atimer_activated_flag
= 1;
11759 #endif /* USE_X_TOOLKIT */
11762 /* Set up use of X before we make the first connection. */
11764 extern frame_parm_handler x_frame_parm_handlers
[];
11766 static struct redisplay_interface x_redisplay_interface
=
11768 x_frame_parm_handlers
,
11772 x_clear_end_of_line
,
11774 x_after_update_window_line
,
11775 x_update_window_begin
,
11776 x_update_window_end
,
11782 0, /* flush_display_optional */
11784 x_clear_window_mouse_face
,
11785 x_get_glyph_overhangs
,
11786 x_fix_overlapping_area
,
11787 x_draw_fringe_bitmap
,
11788 0, /* define_fringe_bitmap */
11789 0, /* destroy_fringe_bitmap */
11792 x_compute_glyph_string_overhangs
,
11793 x_draw_glyph_string
,
11794 x_define_frame_cursor
,
11795 x_clear_frame_area
,
11796 x_draw_window_cursor
,
11797 x_draw_vertical_window_border
,
11798 x_shift_glyphs_for_insert
11802 /* This function is called when the last frame on a display is deleted. */
11804 x_delete_terminal (struct terminal
*terminal
)
11806 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
11809 /* Protect against recursive calls. Fdelete_frame in
11810 delete_terminal calls us back when it deletes our last frame. */
11811 if (!terminal
->name
)
11815 #ifdef USE_FONT_BACKEND
11816 if (! enable_font_backend
)
11818 /* Free the fonts in the font table. */
11819 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11820 if (dpyinfo
->font_table
[i
].name
)
11822 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
11825 x_destroy_all_bitmaps (dpyinfo
);
11826 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
11829 xg_display_close (dpyinfo
->display
);
11831 #ifdef USE_X_TOOLKIT
11832 XtCloseDisplay (dpyinfo
->display
);
11834 XCloseDisplay (dpyinfo
->display
);
11836 #endif /* ! USE_GTK */
11838 x_delete_display (dpyinfo
);
11842 /* Create a struct terminal, initialize it with the X11 specific
11843 functions and make DISPLAY->TERMINAL point to it. */
11845 static struct terminal
*
11846 x_create_terminal (struct x_display_info
*dpyinfo
)
11848 struct terminal
*terminal
;
11850 terminal
= create_terminal ();
11852 terminal
->type
= output_x_window
;
11853 terminal
->display_info
.x
= dpyinfo
;
11854 dpyinfo
->terminal
= terminal
;
11856 /* kboard is initialized in x_term_init. */
11858 terminal
->clear_frame_hook
= x_clear_frame
;
11859 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
11860 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
11861 terminal
->ring_bell_hook
= XTring_bell
;
11862 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
11863 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
11864 terminal
->update_begin_hook
= x_update_begin
;
11865 terminal
->update_end_hook
= x_update_end
;
11866 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
11867 terminal
->read_socket_hook
= XTread_socket
;
11868 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
11869 terminal
->mouse_position_hook
= XTmouse_position
;
11870 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
11871 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
11872 terminal
->fullscreen_hook
= XTfullscreen_hook
;
11873 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
11874 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
11875 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
11876 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
11878 terminal
->delete_frame_hook
= x_destroy_window
;
11879 terminal
->delete_terminal_hook
= x_delete_terminal
;
11881 terminal
->rif
= &x_redisplay_interface
;
11882 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
11883 terminal
->char_ins_del_ok
= 1;
11884 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
11885 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
11886 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
11898 last_tool_bar_item
= -1;
11899 any_help_event_p
= 0;
11900 ignore_next_mouse_click_timeout
= 0;
11902 x_session_initialized
= 0;
11906 current_count
= -1;
11909 /* Try to use interrupt input; if we can't, then start polling. */
11910 Fset_input_interrupt_mode (Qt
);
11912 #ifdef USE_X_TOOLKIT
11913 XtToolkitInitialize ();
11915 Xt_app_con
= XtCreateApplicationContext ();
11917 /* Register a converter from strings to pixels, which uses
11918 Emacs' color allocation infrastructure. */
11919 XtAppSetTypeConverter (Xt_app_con
,
11920 XtRString
, XtRPixel
, cvt_string_to_pixel
,
11921 cvt_string_to_pixel_args
,
11922 XtNumber (cvt_string_to_pixel_args
),
11923 XtCacheByDisplay
, cvt_pixel_dtor
);
11925 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
11928 #ifdef USE_TOOLKIT_SCROLL_BARS
11930 xaw3d_arrow_scroll
= False
;
11931 xaw3d_pick_top
= True
;
11935 /* Note that there is no real way portable across R3/R4 to get the
11936 original error handler. */
11937 XSetErrorHandler (x_error_handler
);
11938 XSetIOErrorHandler (x_io_error_quitter
);
11940 /* Disable Window Change signals; they are handled by X events. */
11941 #if 0 /* Don't. We may want to open tty frames later. */
11943 signal (SIGWINCH
, SIG_DFL
);
11944 #endif /* SIGWINCH */
11947 signal (SIGPIPE
, x_connection_signal
);
11954 x_error_message
= NULL
;
11956 staticpro (&x_display_name_list
);
11957 x_display_name_list
= Qnil
;
11959 staticpro (&last_mouse_scroll_bar
);
11960 last_mouse_scroll_bar
= Qnil
;
11962 staticpro (&Qvendor_specific_keysyms
);
11963 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
11965 staticpro (&Qlatin_1
);
11966 Qlatin_1
= intern ("latin-1");
11968 staticpro (&last_mouse_press_frame
);
11969 last_mouse_press_frame
= Qnil
;
11971 DEFVAR_BOOL ("x-use-underline-position-properties",
11972 &x_use_underline_position_properties
,
11973 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11974 A value of nil means ignore them. If you encounter fonts with bogus
11975 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11976 to 4.1, set this to nil. */);
11977 x_use_underline_position_properties
= 1;
11979 DEFVAR_BOOL ("x-underline-at-descent-line",
11980 &x_underline_at_descent_line
,
11981 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
11982 A value of nil means to draw the underline according to the value of the
11983 variable `x-use-underline-position-properties', which is usually at the
11984 baseline level. The default value is nil. */);
11985 x_underline_at_descent_line
= 0;
11987 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
11988 &x_mouse_click_focus_ignore_position
,
11989 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
11990 This variable is only used when the window manager requires that you
11991 click on a frame to select it (give it focus). In that case, a value
11992 of nil, means that the selected window and cursor position changes to
11993 reflect the mouse click position, while a non-nil value means that the
11994 selected window or cursor position is preserved. */);
11995 x_mouse_click_focus_ignore_position
= 0;
11997 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11998 doc
: /* What X toolkit scroll bars Emacs uses.
11999 A value of nil means Emacs doesn't use X toolkit scroll bars.
12000 Otherwise, value is a symbol describing the X toolkit. */);
12001 #ifdef USE_TOOLKIT_SCROLL_BARS
12003 Vx_toolkit_scroll_bars
= intern ("motif");
12004 #elif defined HAVE_XAW3D
12005 Vx_toolkit_scroll_bars
= intern ("xaw3d");
12007 Vx_toolkit_scroll_bars
= intern ("gtk");
12009 Vx_toolkit_scroll_bars
= intern ("xaw");
12012 Vx_toolkit_scroll_bars
= Qnil
;
12015 staticpro (&last_mouse_motion_frame
);
12016 last_mouse_motion_frame
= Qnil
;
12018 Qmodifier_value
= intern ("modifier-value");
12019 Qalt
= intern ("alt");
12020 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
12021 Qhyper
= intern ("hyper");
12022 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
12023 Qmeta
= intern ("meta");
12024 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
12025 Qsuper
= intern ("super");
12026 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
12028 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
12029 doc
: /* Which keys Emacs uses for the alt modifier.
12030 This should be one of the symbols `alt', `hyper', `meta', `super'.
12031 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
12032 is nil, which is the same as `alt'. */);
12033 Vx_alt_keysym
= Qnil
;
12035 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
12036 doc
: /* Which keys Emacs uses for the hyper modifier.
12037 This should be one of the symbols `alt', `hyper', `meta', `super'.
12038 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
12039 default is nil, which is the same as `hyper'. */);
12040 Vx_hyper_keysym
= Qnil
;
12042 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
12043 doc
: /* Which keys Emacs uses for the meta modifier.
12044 This should be one of the symbols `alt', `hyper', `meta', `super'.
12045 For example, `meta' means use the Meta_L and Meta_R keysyms. The
12046 default is nil, which is the same as `meta'. */);
12047 Vx_meta_keysym
= Qnil
;
12049 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
12050 doc
: /* Which keys Emacs uses for the super modifier.
12051 This should be one of the symbols `alt', `hyper', `meta', `super'.
12052 For example, `super' means use the Super_L and Super_R keysyms. The
12053 default is nil, which is the same as `super'. */);
12054 Vx_super_keysym
= Qnil
;
12056 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
12057 doc
: /* Hash table of character codes indexed by X keysym codes. */);
12058 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
12059 make_float (DEFAULT_REHASH_SIZE
),
12060 make_float (DEFAULT_REHASH_THRESHOLD
),
12064 #endif /* HAVE_X_WINDOWS */
12066 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
12067 (do not change this comment) */