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 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
59 #ifndef INCLUDED_FCNTL
66 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
67 /* #include <sys/param.h> */
70 #include "character.h"
74 #include "dispextern.h"
76 #include "termhooks.h"
84 #include "intervals.h"
90 #include <X11/Shell.h>
93 #ifdef HAVE_SYS_TIME_H
104 #ifdef USE_FONT_BACKEND
106 #endif /* USE_FONT_BACKEND */
109 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
110 extern void xlwmenu_redisplay
P_ ((Widget
));
113 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
115 extern void free_frame_menubar
P_ ((struct frame
*));
116 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
121 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
123 extern void _XEditResCheckMessages ();
124 #endif /* not NO_EDITRES */
126 /* Include toolkit specific headers for the scroll bar widget. */
128 #ifdef USE_TOOLKIT_SCROLL_BARS
129 #if defined USE_MOTIF
130 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
131 #include <Xm/ScrollBar.h>
132 #else /* !USE_MOTIF i.e. use Xaw */
135 #include <X11/Xaw3d/Simple.h>
136 #include <X11/Xaw3d/Scrollbar.h>
137 #include <X11/Xaw3d/ThreeD.h>
138 #else /* !HAVE_XAW3D */
139 #include <X11/Xaw/Simple.h>
140 #include <X11/Xaw/Scrollbar.h>
141 #endif /* !HAVE_XAW3D */
143 #define XtNpickTop "pickTop"
144 #endif /* !XtNpickTop */
145 #endif /* !USE_MOTIF */
146 #endif /* USE_TOOLKIT_SCROLL_BARS */
148 #endif /* USE_X_TOOLKIT */
150 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
151 #define x_any_window_to_frame x_window_to_frame
152 #define x_top_window_to_frame x_window_to_frame
157 #ifndef XtNinitialState
158 #define XtNinitialState "initialState"
162 /* Default to using XIM if available. */
166 int use_xim
= 0; /* configure --without-xim */
171 /* Non-nil means Emacs uses toolkit scroll bars. */
173 Lisp_Object Vx_toolkit_scroll_bars
;
175 /* Non-zero means that a HELP_EVENT has been generated since Emacs
178 static int any_help_event_p
;
180 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
181 static Lisp_Object last_window
;
183 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
185 int x_use_underline_position_properties
;
187 /* Non-zero means to draw the underline at the same place as the descent line. */
189 int x_underline_at_descent_line
;
191 /* This is a chain of structures for all the X displays currently in
194 struct x_display_info
*x_display_list
;
196 /* This is a list of cons cells, each of the form (NAME
197 . FONT-LIST-CACHE), one for each element of x_display_list and in
198 the same order. NAME is the name of the frame. FONT-LIST-CACHE
199 records previous values returned by x-list-fonts. */
201 Lisp_Object x_display_name_list
;
203 /* Frame being updated by update_frame. This is declared in term.c.
204 This is set by update_begin and looked at by all the XT functions.
205 It is zero while not inside an update. In that case, the XT
206 functions assume that `selected_frame' is the frame to apply to. */
208 extern struct frame
*updating_frame
;
210 /* This is a frame waiting to be auto-raised, within XTread_socket. */
212 struct frame
*pending_autoraise_frame
;
215 /* The application context for Xt use. */
216 XtAppContext Xt_app_con
;
217 static String Xt_default_resources
[] = {0};
218 #endif /* USE_X_TOOLKIT */
220 /* Non-zero means user is interacting with a toolkit scroll bar. */
222 static int toolkit_scroll_bar_interaction
;
224 /* Non-zero means to not move point as a result of clicking on a
225 frame to focus it (when focus-follows-mouse is nil). */
227 int x_mouse_click_focus_ignore_position
;
229 /* Non-zero timeout value means ignore next mouse click if it arrives
230 before that timeout elapses (i.e. as part of the same sequence of
231 events resulting from clicking on a frame to select it). */
233 static unsigned long ignore_next_mouse_click_timeout
;
237 Formerly, we used PointerMotionHintMask (in standard_event_mask)
238 so that we would have to call XQueryPointer after each MotionNotify
239 event to ask for another such event. However, this made mouse tracking
240 slow, and there was a bug that made it eventually stop.
242 Simply asking for MotionNotify all the time seems to work better.
244 In order to avoid asking for motion events and then throwing most
245 of them away or busy-polling the server for mouse positions, we ask
246 the server for pointer motion hints. This means that we get only
247 one event per group of mouse movements. "Groups" are delimited by
248 other kinds of events (focus changes and button clicks, for
249 example), or by XQueryPointer calls; when one of these happens, we
250 get another MotionNotify event the next time the mouse moves. This
251 is at least as efficient as getting motion events when mouse
252 tracking is on, and I suspect only negligibly worse when tracking
255 /* Where the mouse was last time we reported a mouse event. */
257 static XRectangle last_mouse_glyph
;
258 static FRAME_PTR last_mouse_glyph_frame
;
259 static Lisp_Object last_mouse_press_frame
;
261 /* The scroll bar in which the last X motion event occurred.
263 If the last X motion event occurred in a scroll bar, we set this so
264 XTmouse_position can know whether to report a scroll bar motion or
267 If the last X motion event didn't occur in a scroll bar, we set
268 this to Qnil, to tell XTmouse_position to return an ordinary motion
271 static Lisp_Object last_mouse_scroll_bar
;
273 /* This is a hack. We would really prefer that XTmouse_position would
274 return the time associated with the position it returns, but there
275 doesn't seem to be any way to wrest the time-stamp from the server
276 along with the position query. So, we just keep track of the time
277 of the last movement we received, and return that in hopes that
278 it's somewhat accurate. */
280 static Time last_mouse_movement_time
;
282 /* Time for last user interaction as returned in X events. */
284 static Time last_user_time
;
286 /* Incremented by XTread_socket whenever it really tries to read
290 static int volatile input_signal_count
;
292 static int input_signal_count
;
295 /* Used locally within XTread_socket. */
297 static int x_noop_count
;
299 /* Initial values of argv and argc. */
301 extern char **initial_argv
;
302 extern int initial_argc
;
304 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
306 /* Tells if a window manager is present or not. */
308 extern Lisp_Object Vx_no_window_manager
;
310 extern Lisp_Object Qeql
;
314 /* A mask of extra modifier bits to put into every keyboard char. */
316 extern EMACS_INT extra_keyboard_modifiers
;
318 /* The keysyms to use for the various modifiers. */
320 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
321 Lisp_Object Vx_keysym_table
;
322 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
324 static Lisp_Object Qvendor_specific_keysyms
;
325 static Lisp_Object Qlatin_1
;
327 /* Used in x_flush. */
329 extern Lisp_Object Vinhibit_redisplay
;
331 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
332 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
334 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
335 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
336 static const XColor
*x_color_cells
P_ ((Display
*, int *));
337 static void x_update_window_end
P_ ((struct window
*, int, int));
339 static int x_io_error_quitter
P_ ((Display
*));
340 static struct terminal
*x_create_terminal
P_ ((struct x_display_info
*));
341 void x_delete_terminal
P_ ((struct terminal
*));
342 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
343 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
344 static void x_update_end
P_ ((struct frame
*));
345 static void XTframe_up_to_date
P_ ((struct frame
*));
346 static void XTset_terminal_modes
P_ ((struct terminal
*));
347 static void XTreset_terminal_modes
P_ ((struct terminal
*));
348 static void x_clear_frame
P_ ((struct frame
*));
349 static void frame_highlight
P_ ((struct frame
*));
350 static void frame_unhighlight
P_ ((struct frame
*));
351 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
352 static void x_focus_changed
P_ ((int, int, struct x_display_info
*,
353 struct frame
*, struct input_event
*));
354 static void x_detect_focus_change
P_ ((struct x_display_info
*,
355 XEvent
*, struct input_event
*));
356 static void XTframe_rehighlight
P_ ((struct frame
*));
357 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
358 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
359 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
360 enum text_cursor_kinds
));
362 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
363 static void x_flush
P_ ((struct frame
*f
));
364 static void x_update_begin
P_ ((struct frame
*));
365 static void x_update_window_begin
P_ ((struct window
*));
366 static void x_after_update_window_line
P_ ((struct glyph_row
*));
367 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Display
*, Window
));
368 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
369 enum scroll_bar_part
*,
370 Lisp_Object
*, Lisp_Object
*,
372 static void x_check_fullscreen
P_ ((struct frame
*));
373 static void x_check_expected_move
P_ ((struct frame
*, int, int));
374 static void x_sync_with_move
P_ ((struct frame
*, int, int, int));
375 static int handle_one_xevent
P_ ((struct x_display_info
*, XEvent
*,
376 int *, struct input_event
*));
377 /* Don't declare this NO_RETURN because we want no
378 interference with debugging failing X calls. */
379 static SIGTYPE x_connection_closed
P_ ((Display
*, char *));
382 /* Flush display of frame F, or of all frames if F is null. */
388 /* Don't call XFlush when it is not safe to redisplay; the X
389 connection may be broken. */
390 if (!NILP (Vinhibit_redisplay
))
396 Lisp_Object rest
, frame
;
397 FOR_EACH_FRAME (rest
, frame
)
398 if (FRAME_X_P (XFRAME (frame
)))
399 x_flush (XFRAME (frame
));
401 else if (FRAME_X_P (f
))
402 XFlush (FRAME_X_DISPLAY (f
));
407 /* Remove calls to XFlush by defining XFlush to an empty replacement.
408 Calls to XFlush should be unnecessary because the X output buffer
409 is flushed automatically as needed by calls to XPending,
410 XNextEvent, or XWindowEvent according to the XFlush man page.
411 XTread_socket calls XPending. Removing XFlush improves
414 #define XFlush(DISPLAY) (void) 0
417 /***********************************************************************
419 ***********************************************************************/
423 /* This is a function useful for recording debugging information about
424 the sequence of occurrences in this file. */
432 struct record event_record
[100];
434 int event_record_index
;
436 record_event (locus
, type
)
440 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
441 event_record_index
= 0;
443 event_record
[event_record_index
].locus
= locus
;
444 event_record
[event_record_index
].type
= type
;
445 event_record_index
++;
452 /* Return the struct x_display_info corresponding to DPY. */
454 struct x_display_info
*
455 x_display_info_for_display (dpy
)
458 struct x_display_info
*dpyinfo
;
460 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
461 if (dpyinfo
->display
== dpy
)
469 /***********************************************************************
470 Starting and ending an update
471 ***********************************************************************/
473 /* Start an update of frame F. This function is installed as a hook
474 for update_begin, i.e. it is called when update_begin is called.
475 This function is called prior to calls to x_update_window_begin for
476 each window being updated. Currently, there is nothing to do here
477 because all interesting stuff is done on a window basis. */
487 /* Start update of window W. Set the global variable updated_window
488 to the window being updated and set output_cursor to the cursor
492 x_update_window_begin (w
)
495 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
496 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
499 set_output_cursor (&w
->cursor
);
503 if (f
== display_info
->mouse_face_mouse_frame
)
505 /* Don't do highlighting for mouse motion during the update. */
506 display_info
->mouse_face_defer
= 1;
508 /* If F needs to be redrawn, simply forget about any prior mouse
510 if (FRAME_GARBAGED_P (f
))
511 display_info
->mouse_face_window
= Qnil
;
513 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
514 their mouse_face_p flag set, which means that they are always
515 unequal to rows in a desired matrix which never have that
516 flag set. So, rows containing mouse-face glyphs are never
517 scrolled, and we don't have to switch the mouse highlight off
518 here to prevent it from being scrolled. */
520 /* Can we tell that this update does not affect the window
521 where the mouse highlight is? If so, no need to turn off.
522 Likewise, don't do anything if the frame is garbaged;
523 in that case, the frame's current matrix that we would use
524 is all wrong, and we will redisplay that line anyway. */
525 if (!NILP (display_info
->mouse_face_window
)
526 && w
== XWINDOW (display_info
->mouse_face_window
))
530 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
531 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
534 if (i
< w
->desired_matrix
->nrows
)
535 clear_mouse_face (display_info
);
544 /* Draw a vertical window border from (x,y0) to (x,y1) */
547 x_draw_vertical_window_border (w
, x
, y0
, y1
)
551 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
554 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
556 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
559 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
560 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
563 /* End update of window W (which is equal to updated_window).
565 Draw vertical borders between horizontally adjacent windows, and
566 display W's cursor if CURSOR_ON_P is non-zero.
568 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
569 glyphs in mouse-face were overwritten. In that case we have to
570 make sure that the mouse-highlight is properly redrawn.
572 W may be a menu bar pseudo-window in case we don't have X toolkit
573 support. Such windows don't have a cursor, so don't display it
577 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
579 int cursor_on_p
, mouse_face_overwritten_p
;
581 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
583 if (!w
->pseudo_window_p
)
588 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
590 output_cursor
.x
, output_cursor
.y
);
592 if (draw_window_fringes (w
, 1))
593 x_draw_vertical_border (w
);
598 /* If a row with mouse-face was overwritten, arrange for
599 XTframe_up_to_date to redisplay the mouse highlight. */
600 if (mouse_face_overwritten_p
)
602 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
603 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
604 dpyinfo
->mouse_face_window
= Qnil
;
607 updated_window
= NULL
;
611 /* End update of frame F. This function is installed as a hook in
618 /* Mouse highlight may be displayed again. */
619 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
623 XFlush (FRAME_X_DISPLAY (f
));
629 /* This function is called from various places in xdisp.c whenever a
630 complete update has been performed. The global variable
631 updated_window is not available here. */
634 XTframe_up_to_date (f
)
639 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
641 if (dpyinfo
->mouse_face_deferred_gc
642 || f
== dpyinfo
->mouse_face_mouse_frame
)
645 if (dpyinfo
->mouse_face_mouse_frame
)
646 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
647 dpyinfo
->mouse_face_mouse_x
,
648 dpyinfo
->mouse_face_mouse_y
);
649 dpyinfo
->mouse_face_deferred_gc
= 0;
656 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
657 arrow bitmaps, or clear the fringes if no bitmaps are required
658 before DESIRED_ROW is made current. The window being updated is
659 found in updated_window. This function It is called from
660 update_window_line only if it is known that there are differences
661 between bitmaps to be drawn between current row and DESIRED_ROW. */
664 x_after_update_window_line (desired_row
)
665 struct glyph_row
*desired_row
;
667 struct window
*w
= updated_window
;
673 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
674 desired_row
->redraw_fringe_bitmaps_p
= 1;
676 /* When a window has disappeared, make sure that no rest of
677 full-width rows stays visible in the internal border. Could
678 check here if updated_window is the leftmost/rightmost window,
679 but I guess it's not worth doing since vertically split windows
680 are almost never used, internal border is rarely set, and the
681 overhead is very small. */
682 if (windows_or_buffers_changed
683 && desired_row
->full_width_p
684 && (f
= XFRAME (w
->frame
),
685 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
687 && (height
= desired_row
->visible_height
,
690 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
692 /* Internal border is drawn below the tool bar. */
693 if (WINDOWP (f
->tool_bar_window
)
694 && w
== XWINDOW (f
->tool_bar_window
))
698 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
699 0, y
, width
, height
, False
);
700 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
701 FRAME_PIXEL_WIDTH (f
) - width
,
702 y
, width
, height
, False
);
708 x_draw_fringe_bitmap (w
, row
, p
)
710 struct glyph_row
*row
;
711 struct draw_fringe_bitmap_params
*p
;
713 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
714 Display
*display
= FRAME_X_DISPLAY (f
);
715 Window window
= FRAME_X_WINDOW (f
);
716 GC gc
= f
->output_data
.x
->normal_gc
;
717 struct face
*face
= p
->face
;
720 /* Must clip because of partially visible lines. */
721 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
724 /* Adjust position of "bottom aligned" bitmap on partially
727 int oldVH
= row
->visible_height
;
728 row
->visible_height
= p
->h
;
729 row
->y
-= rowY
- p
->y
;
730 x_clip_to_row (w
, row
, -1, gc
);
732 row
->visible_height
= oldVH
;
735 x_clip_to_row (w
, row
, -1, gc
);
739 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
741 /* In case the same realized face is used for fringes and
742 for something displayed in the text (e.g. face `region' on
743 mono-displays, the fill style may have been changed to
744 FillSolid in x_draw_glyph_string_background. */
746 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
748 XSetForeground (display
, face
->gc
, face
->background
);
750 #ifdef USE_TOOLKIT_SCROLL_BARS
751 /* If the fringe is adjacent to the left (right) scroll bar of a
752 leftmost (rightmost, respectively) window, then extend its
753 background to the gap between the fringe and the bar. */
754 if ((WINDOW_LEFTMOST_P (w
)
755 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
756 || (WINDOW_RIGHTMOST_P (w
)
757 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
759 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
763 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
764 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
765 * FRAME_COLUMN_WIDTH (f
));
769 /* Bitmap fills the fringe. */
770 if (left
+ width
== p
->x
)
771 bx
= left
+ sb_width
;
772 else if (p
->x
+ p
->wd
== left
)
776 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
778 nx
= width
- sb_width
;
779 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
781 ny
= row
->visible_height
;
786 if (left
+ width
== bx
)
788 bx
= left
+ sb_width
;
789 nx
+= width
- sb_width
;
791 else if (bx
+ nx
== left
)
792 nx
+= width
- sb_width
;
797 if (bx
>= 0 && nx
> 0)
798 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
801 XSetForeground (display
, face
->gc
, face
->foreground
);
807 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
808 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
812 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
814 bits
= (unsigned char *)p
->bits
+ p
->dh
;
816 /* Draw the bitmap. I believe these small pixmaps can be cached
818 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
820 ? (p
->overlay_p
? face
->background
821 : f
->output_data
.x
->cursor_pixel
)
823 face
->background
, depth
);
827 clipmask
= XCreatePixmapFromBitmapData (display
,
828 FRAME_X_DISPLAY_INFO (f
)->root_window
,
831 gcv
.clip_mask
= clipmask
;
832 gcv
.clip_x_origin
= p
->x
;
833 gcv
.clip_y_origin
= p
->y
;
834 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
837 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
838 p
->wd
, p
->h
, p
->x
, p
->y
);
839 XFreePixmap (display
, pixmap
);
843 gcv
.clip_mask
= (Pixmap
) 0;
844 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
845 XFreePixmap (display
, clipmask
);
849 XSetClipMask (display
, gc
, None
);
854 /* This is called when starting Emacs and when restarting after
855 suspend. When starting Emacs, no X window is mapped. And nothing
856 must be done to Emacs's own window if it is suspended (though that
860 XTset_terminal_modes (struct terminal
*terminal
)
864 /* This is called when exiting or suspending Emacs. Exiting will make
865 the X-windows go away, and suspending requires no action. */
868 XTreset_terminal_modes (struct terminal
*terminal
)
874 /***********************************************************************
876 ***********************************************************************/
878 /* Function prototypes of this page. */
880 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*,
881 struct charset
*, int *));
884 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
885 is not contained in the font. */
888 x_per_char_metric (font
, char2b
, font_type
)
891 int font_type
; /* unused on X */
893 /* The result metric information. */
894 XCharStruct
*pcm
= NULL
;
896 xassert (font
&& char2b
);
898 if (font
->per_char
!= NULL
)
900 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
902 /* min_char_or_byte2 specifies the linear character index
903 corresponding to the first element of the per_char array,
904 max_char_or_byte2 is the index of the last character. A
905 character with non-zero CHAR2B->byte1 is not in the font.
906 A character with byte2 less than min_char_or_byte2 or
907 greater max_char_or_byte2 is not in the font. */
908 if (char2b
->byte1
== 0
909 && char2b
->byte2
>= font
->min_char_or_byte2
910 && char2b
->byte2
<= font
->max_char_or_byte2
)
911 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
915 /* If either min_byte1 or max_byte1 are nonzero, both
916 min_char_or_byte2 and max_char_or_byte2 are less than
917 256, and the 2-byte character index values corresponding
918 to the per_char array element N (counting from 0) are:
920 byte1 = N/D + min_byte1
921 byte2 = N\D + min_char_or_byte2
925 D = max_char_or_byte2 - min_char_or_byte2 + 1
927 \ = integer modulus */
928 if (char2b
->byte1
>= font
->min_byte1
929 && char2b
->byte1
<= font
->max_byte1
930 && char2b
->byte2
>= font
->min_char_or_byte2
931 && char2b
->byte2
<= font
->max_char_or_byte2
)
933 pcm
= (font
->per_char
934 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
935 * (char2b
->byte1
- font
->min_byte1
))
936 + (char2b
->byte2
- font
->min_char_or_byte2
));
942 /* If the per_char pointer is null, all glyphs between the first
943 and last character indexes inclusive have the same
944 information, as given by both min_bounds and max_bounds. */
945 if (char2b
->byte2
>= font
->min_char_or_byte2
946 && char2b
->byte2
<= font
->max_char_or_byte2
)
947 pcm
= &font
->max_bounds
;
951 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
956 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
957 the two-byte form of C. Encoding is returned in *CHAR2B. */
960 x_encode_char (c
, char2b
, font_info
, charset
, two_byte_p
)
963 struct font_info
*font_info
;
964 struct charset
*charset
;
967 XFontStruct
*font
= font_info
->font
;
969 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
970 This may be either a program in a special encoder language or a
972 if (font_info
->font_encoder
)
974 /* It's a program. */
975 struct ccl_program
*ccl
= font_info
->font_encoder
;
977 check_ccl_update (ccl
);
978 if (CHARSET_DIMENSION (charset
) == 1)
980 ccl
->reg
[0] = CHARSET_ID (charset
);
981 ccl
->reg
[1] = char2b
->byte2
;
986 ccl
->reg
[0] = CHARSET_ID (charset
);
987 ccl
->reg
[1] = char2b
->byte1
;
988 ccl
->reg
[2] = char2b
->byte2
;
991 ccl_driver (ccl
, NULL
, NULL
, 0, 0, Qnil
);
993 /* We assume that MSBs are appropriately set/reset by CCL
995 if (font
->max_byte1
== 0) /* 1-byte font */
996 STORE_XCHAR2B (char2b
, 0, ccl
->reg
[1]);
998 STORE_XCHAR2B (char2b
, ccl
->reg
[1], ccl
->reg
[2]);
1000 else if (font_info
->encoding_type
)
1002 /* Fixed encoding scheme. See fontset.h for the meaning of the
1003 encoding numbers. */
1004 unsigned char enc
= font_info
->encoding_type
;
1006 if ((enc
== 1 || enc
== 2)
1007 && CHARSET_DIMENSION (charset
) == 2)
1008 char2b
->byte1
|= 0x80;
1010 if (enc
== 1 || enc
== 3)
1011 char2b
->byte2
|= 0x80;
1015 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1017 return FONT_TYPE_UNKNOWN
;
1022 /***********************************************************************
1024 ***********************************************************************/
1028 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
1029 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
1030 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
1032 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
1033 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
1034 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
1035 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
1036 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
1037 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
1038 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
1039 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
1040 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
1041 unsigned long *, double, int));
1042 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
1043 double, int, unsigned long));
1044 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
1045 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
1046 static void x_draw_image_relief
P_ ((struct glyph_string
*));
1047 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
1048 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
1049 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
1051 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
1052 int, int, int, int, int, int,
1054 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
1055 int, int, int, XRectangle
*));
1058 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
1062 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1067 struct glyph_string
*s
;
1069 if (s
->font
== FRAME_FONT (s
->f
)
1070 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1071 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1073 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1076 /* Cursor on non-default face: must merge. */
1080 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1081 xgcv
.foreground
= s
->face
->background
;
1083 /* If the glyph would be invisible, try a different foreground. */
1084 if (xgcv
.foreground
== xgcv
.background
)
1085 xgcv
.foreground
= s
->face
->foreground
;
1086 if (xgcv
.foreground
== xgcv
.background
)
1087 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1088 if (xgcv
.foreground
== xgcv
.background
)
1089 xgcv
.foreground
= s
->face
->foreground
;
1091 /* Make sure the cursor is distinct from text in this face. */
1092 if (xgcv
.background
== s
->face
->background
1093 && xgcv
.foreground
== s
->face
->foreground
)
1095 xgcv
.background
= s
->face
->foreground
;
1096 xgcv
.foreground
= s
->face
->background
;
1099 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1100 xgcv
.font
= s
->font
->fid
;
1101 xgcv
.graphics_exposures
= False
;
1102 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1104 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1105 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1108 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1109 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1111 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1116 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1119 x_set_mouse_face_gc (s
)
1120 struct glyph_string
*s
;
1125 /* What face has to be used last for the mouse face? */
1126 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1127 face
= FACE_FROM_ID (s
->f
, face_id
);
1129 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1131 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1132 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1134 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1135 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1136 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1138 /* If font in this face is same as S->font, use it. */
1139 if (s
->font
== s
->face
->font
)
1140 s
->gc
= s
->face
->gc
;
1141 #ifdef USE_FONT_BACKEND
1142 else if (enable_font_backend
)
1143 /* No need of setting a font for s->gc. */
1144 s
->gc
= s
->face
->gc
;
1145 #endif /* USE_FONT_BACKEND */
1148 /* Otherwise construct scratch_cursor_gc with values from FACE
1153 xgcv
.background
= s
->face
->background
;
1154 xgcv
.foreground
= s
->face
->foreground
;
1155 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1156 xgcv
.font
= s
->font
->fid
;
1157 xgcv
.graphics_exposures
= False
;
1158 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1160 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1161 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1164 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1165 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1167 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1170 xassert (s
->gc
!= 0);
1174 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1175 Faces to use in the mode line have already been computed when the
1176 matrix was built, so there isn't much to do, here. */
1179 x_set_mode_line_face_gc (s
)
1180 struct glyph_string
*s
;
1182 s
->gc
= s
->face
->gc
;
1186 /* Set S->gc of glyph string S for drawing that glyph string. Set
1187 S->stippled_p to a non-zero value if the face of S has a stipple
1191 x_set_glyph_string_gc (s
)
1192 struct glyph_string
*s
;
1194 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1196 if (s
->hl
== DRAW_NORMAL_TEXT
)
1198 s
->gc
= s
->face
->gc
;
1199 s
->stippled_p
= s
->face
->stipple
!= 0;
1201 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1203 x_set_mode_line_face_gc (s
);
1204 s
->stippled_p
= s
->face
->stipple
!= 0;
1206 else if (s
->hl
== DRAW_CURSOR
)
1208 x_set_cursor_gc (s
);
1211 else if (s
->hl
== DRAW_MOUSE_FACE
)
1213 x_set_mouse_face_gc (s
);
1214 s
->stippled_p
= s
->face
->stipple
!= 0;
1216 else if (s
->hl
== DRAW_IMAGE_RAISED
1217 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1219 s
->gc
= s
->face
->gc
;
1220 s
->stippled_p
= s
->face
->stipple
!= 0;
1224 s
->gc
= s
->face
->gc
;
1225 s
->stippled_p
= s
->face
->stipple
!= 0;
1228 /* GC must have been set. */
1229 xassert (s
->gc
!= 0);
1233 /* Set clipping for output of glyph string S. S may be part of a mode
1234 line or menu if we don't have X toolkit support. */
1237 x_set_glyph_string_clipping (s
)
1238 struct glyph_string
*s
;
1240 #ifdef USE_FONT_BACKEND
1241 XRectangle
*r
= s
->clip
;
1245 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1248 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1249 #ifdef USE_FONT_BACKEND
1255 /* Set SRC's clipping for output of glyph string DST. This is called
1256 when we are drawing DST's left_overhang or right_overhang only in
1260 x_set_glyph_string_clipping_exactly (src
, dst
)
1261 struct glyph_string
*src
, *dst
;
1265 #ifdef USE_FONT_BACKEND
1266 if (enable_font_backend
)
1269 r
.width
= src
->width
;
1271 r
.height
= src
->height
;
1277 #endif /* USE_FONT_BACKEND */
1278 struct glyph_string
*clip_head
= src
->clip_head
;
1279 struct glyph_string
*clip_tail
= src
->clip_tail
;
1281 /* This foces clipping just this glyph string. */
1282 src
->clip_head
= src
->clip_tail
= src
;
1283 get_glyph_string_clip_rect (src
, &r
);
1284 src
->clip_head
= clip_head
, src
->clip_tail
= clip_tail
;
1285 #ifdef USE_FONT_BACKEND
1287 #endif /* USE_FONT_BACKEND */
1288 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1293 Compute left and right overhang of glyph string S. */
1296 x_compute_glyph_string_overhangs (s
)
1297 struct glyph_string
*s
;
1300 && s
->first_glyph
->type
== CHAR_GLYPH
)
1303 int direction
, font_ascent
, font_descent
;
1305 #ifdef USE_FONT_BACKEND
1306 if (enable_font_backend
)
1308 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1309 struct font
*font
= (struct font
*) s
->font_info
;
1310 struct font_metrics metrics
;
1313 for (i
= 0; i
< s
->nchars
; i
++)
1314 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1315 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1316 cs
.rbearing
= metrics
.rbearing
;
1317 cs
.lbearing
= metrics
.lbearing
;
1318 cs
.width
= metrics
.width
;
1321 #endif /* USE_FONT_BACKEND */
1322 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1323 &font_ascent
, &font_descent
, &cs
);
1324 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1325 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1329 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1330 s
->left_overhang
= - s
->cmp
->lbearing
;
1335 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1338 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1339 struct glyph_string
*s
;
1343 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1344 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1345 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1346 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1350 /* Draw the background of glyph_string S. If S->background_filled_p
1351 is non-zero don't draw it. FORCE_P non-zero means draw the
1352 background even if it wouldn't be drawn normally. This is used
1353 when a string preceding S draws into the background of S, or S
1354 contains the first component of a composition. */
1357 x_draw_glyph_string_background (s
, force_p
)
1358 struct glyph_string
*s
;
1361 /* Nothing to do if background has already been drawn or if it
1362 shouldn't be drawn in the first place. */
1363 if (!s
->background_filled_p
)
1365 int box_line_width
= max (s
->face
->box_line_width
, 0);
1369 /* Fill background with a stipple pattern. */
1370 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1371 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1372 s
->y
+ box_line_width
,
1373 s
->background_width
,
1374 s
->height
- 2 * box_line_width
);
1375 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1376 s
->background_filled_p
= 1;
1378 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1379 || s
->font_not_found_p
1380 || s
->extends_to_end_of_line_p
1383 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1384 s
->background_width
,
1385 s
->height
- 2 * box_line_width
);
1386 s
->background_filled_p
= 1;
1392 /* Draw the foreground of glyph string S. */
1395 x_draw_glyph_string_foreground (s
)
1396 struct glyph_string
*s
;
1400 /* If first glyph of S has a left box line, start drawing the text
1401 of S to the right of that box line. */
1402 if (s
->face
->box
!= FACE_NO_BOX
1403 && s
->first_glyph
->left_box_line_p
)
1404 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1408 /* Draw characters of S as rectangles if S's font could not be
1410 if (s
->font_not_found_p
)
1412 for (i
= 0; i
< s
->nchars
; ++i
)
1414 struct glyph
*g
= s
->first_glyph
+ i
;
1415 XDrawRectangle (s
->display
, s
->window
,
1416 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1418 x
+= g
->pixel_width
;
1421 #ifdef USE_FONT_BACKEND
1422 else if (enable_font_backend
)
1424 int boff
= s
->font_info
->baseline_offset
;
1425 struct font
*font
= (struct font
*) s
->font_info
;
1428 if (s
->font_info
->vertical_centering
)
1429 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1431 y
= s
->ybase
- boff
;
1433 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1434 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1436 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1437 if (s
->face
->overstrike
)
1438 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1440 #endif /* USE_FONT_BACKEND */
1443 char *char1b
= (char *) s
->char2b
;
1444 int boff
= s
->font_info
->baseline_offset
;
1446 if (s
->font_info
->vertical_centering
)
1447 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1449 /* If we can use 8-bit functions, condense S->char2b. */
1451 for (i
= 0; i
< s
->nchars
; ++i
)
1452 char1b
[i
] = s
->char2b
[i
].byte2
;
1454 /* Draw text with XDrawString if background has already been
1455 filled. Otherwise, use XDrawImageString. (Note that
1456 XDrawImageString is usually faster than XDrawString.) Always
1457 use XDrawImageString when drawing the cursor so that there is
1458 no chance that characters under a box cursor are invisible. */
1460 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1462 /* Draw characters with 16-bit or 8-bit functions. */
1464 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1465 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1467 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1468 s
->ybase
- boff
, char1b
, s
->nchars
);
1473 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1474 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1476 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1477 s
->ybase
- boff
, char1b
, s
->nchars
);
1480 if (s
->face
->overstrike
)
1482 /* For overstriking (to simulate bold-face), draw the
1483 characters again shifted to the right by one pixel. */
1485 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1486 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1488 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1489 s
->ybase
- boff
, char1b
, s
->nchars
);
1494 /* Draw the foreground of composite glyph string S. */
1497 x_draw_composite_glyph_string_foreground (s
)
1498 struct glyph_string
*s
;
1502 /* If first glyph of S has a left box line, start drawing the text
1503 of S to the right of that box line. */
1504 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1505 && s
->first_glyph
->left_box_line_p
)
1506 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1510 /* S is a glyph string for a composition. S->gidx is the index of
1511 the first character drawn for glyphs of this composition.
1512 S->gidx == 0 means we are drawing the very first character of
1513 this composition. */
1515 /* Draw a rectangle for the composition if the font for the very
1516 first character of the composition could not be loaded. */
1517 if (s
->font_not_found_p
)
1520 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1521 s
->width
- 1, s
->height
- 1);
1523 #ifdef USE_FONT_BACKEND
1524 else if (enable_font_backend
)
1526 struct font
*font
= (struct font
*) s
->font_info
;
1530 if (s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
1532 Lisp_Object gstring
= AREF (XHASH_TABLE (composition_hash_table
)
1534 s
->cmp
->hash_index
* 2);
1537 for (i
= from
= 0; i
< s
->nchars
; i
++)
1539 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
1540 Lisp_Object adjustment
= LGLYPH_ADJUSTMENT (g
);
1541 int xoff
, yoff
, wadjust
;
1543 if (! VECTORP (adjustment
))
1545 width
+= XINT (LGLYPH_WIDTH (g
));
1550 font
->driver
->draw (s
, from
, i
, x
, y
, 0);
1553 xoff
= XINT (AREF (adjustment
, 0));
1554 yoff
= XINT (AREF (adjustment
, 1));
1555 wadjust
= XINT (AREF (adjustment
, 2));
1557 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1558 x
+= XINT (LGLYPH_WIDTH (g
)) + wadjust
;
1563 font
->driver
->draw (s
, from
, i
, x
, y
, 0);
1567 for (i
= 0, j
= s
->gidx
; i
< s
->nchars
; i
++, j
++)
1568 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1570 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1571 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1573 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1574 if (s
->face
->overstrike
)
1575 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1579 #endif /* USE_FONT_BACKEND */
1582 for (i
= 0, j
= s
->gidx
; i
< s
->nchars
; i
++, j
++)
1585 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1586 x
+ s
->cmp
->offsets
[j
* 2],
1587 s
->ybase
- s
->cmp
->offsets
[j
* 2 + 1],
1589 if (s
->face
->overstrike
)
1590 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1591 x
+ s
->cmp
->offsets
[j
* 2] + 1,
1592 s
->ybase
- s
->cmp
->offsets
[j
* 2 + 1],
1599 #ifdef USE_X_TOOLKIT
1601 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1602 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1603 XrmValue
*, XrmValue
*, XtPointer
*));
1604 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1605 XrmValue
*, Cardinal
*));
1608 /* Return the frame on which widget WIDGET is used.. Abort if frame
1609 cannot be determined. */
1611 static struct frame
*
1612 x_frame_of_widget (widget
)
1615 struct x_display_info
*dpyinfo
;
1619 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1621 /* Find the top-level shell of the widget. Note that this function
1622 can be called when the widget is not yet realized, so XtWindow
1623 (widget) == 0. That's the reason we can't simply use
1624 x_any_window_to_frame. */
1625 while (!XtIsTopLevelShell (widget
))
1626 widget
= XtParent (widget
);
1628 /* Look for a frame with that top-level widget. Allocate the color
1629 on that frame to get the right gamma correction value. */
1630 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1631 if (FRAMEP (XCAR (tail
))
1632 && (f
= XFRAME (XCAR (tail
)),
1634 && f
->output_data
.nothing
!= 1
1635 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1636 && f
->output_data
.x
->widget
== widget
)
1643 /* Allocate the color COLOR->pixel on the screen and display of
1644 widget WIDGET in colormap CMAP. If an exact match cannot be
1645 allocated, try the nearest color available. Value is non-zero
1646 if successful. This is called from lwlib. */
1649 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1654 struct frame
*f
= x_frame_of_widget (widget
);
1655 return x_alloc_nearest_color (f
, cmap
, color
);
1659 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1660 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1661 If this produces the same color as PIXEL, try a color where all RGB
1662 values have DELTA added. Return the allocated color in *PIXEL.
1663 DISPLAY is the X display, CMAP is the colormap to operate on.
1664 Value is non-zero if successful. */
1667 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1671 unsigned long *pixel
;
1675 struct frame
*f
= x_frame_of_widget (widget
);
1676 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1680 /* Structure specifying which arguments should be passed by Xt to
1681 cvt_string_to_pixel. We want the widget's screen and colormap. */
1683 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1685 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1687 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1692 /* The address of this variable is returned by
1693 cvt_string_to_pixel. */
1695 static Pixel cvt_string_to_pixel_value
;
1698 /* Convert a color name to a pixel color.
1700 DPY is the display we are working on.
1702 ARGS is an array of *NARGS XrmValue structures holding additional
1703 information about the widget for which the conversion takes place.
1704 The contents of this array are determined by the specification
1705 in cvt_string_to_pixel_args.
1707 FROM is a pointer to an XrmValue which points to the color name to
1708 convert. TO is an XrmValue in which to return the pixel color.
1710 CLOSURE_RET is a pointer to user-data, in which we record if
1711 we allocated the color or not.
1713 Value is True if successful, False otherwise. */
1716 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1720 XrmValue
*from
, *to
;
1721 XtPointer
*closure_ret
;
1731 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1732 "wrongParameters", "cvt_string_to_pixel",
1734 "Screen and colormap args required", NULL
, NULL
);
1738 screen
= *(Screen
**) args
[0].addr
;
1739 cmap
= *(Colormap
*) args
[1].addr
;
1740 color_name
= (String
) from
->addr
;
1742 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1744 *closure_ret
= (XtPointer
) False
;
1745 pixel
= WhitePixelOfScreen (screen
);
1747 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1749 *closure_ret
= (XtPointer
) False
;
1750 pixel
= BlackPixelOfScreen (screen
);
1752 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1753 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1755 pixel
= color
.pixel
;
1756 *closure_ret
= (XtPointer
) True
;
1761 Cardinal nparams
= 1;
1763 params
[0] = color_name
;
1764 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1765 "badValue", "cvt_string_to_pixel",
1766 "XtToolkitError", "Invalid color `%s'",
1771 if (to
->addr
!= NULL
)
1773 if (to
->size
< sizeof (Pixel
))
1775 to
->size
= sizeof (Pixel
);
1779 *(Pixel
*) to
->addr
= pixel
;
1783 cvt_string_to_pixel_value
= pixel
;
1784 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1787 to
->size
= sizeof (Pixel
);
1792 /* Free a pixel color which was previously allocated via
1793 cvt_string_to_pixel. This is registered as the destructor
1794 for this type of resource via XtSetTypeConverter.
1796 APP is the application context in which we work.
1798 TO is a pointer to an XrmValue holding the color to free.
1799 CLOSURE is the value we stored in CLOSURE_RET for this color
1800 in cvt_string_to_pixel.
1802 ARGS and NARGS are like for cvt_string_to_pixel. */
1805 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1814 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1816 "Screen and colormap arguments required",
1819 else if (closure
!= NULL
)
1821 /* We did allocate the pixel, so free it. */
1822 Screen
*screen
= *(Screen
**) args
[0].addr
;
1823 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1824 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1825 (Pixel
*) to
->addr
, 1);
1830 #endif /* USE_X_TOOLKIT */
1833 /* Value is an array of XColor structures for the contents of the
1834 color map of display DPY. Set *NCELLS to the size of the array.
1835 Note that this probably shouldn't be called for large color maps,
1836 say a 24-bit TrueColor map. */
1838 static const XColor
*
1839 x_color_cells (dpy
, ncells
)
1843 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1845 if (dpyinfo
->color_cells
== NULL
)
1847 Screen
*screen
= dpyinfo
->screen
;
1850 dpyinfo
->ncolor_cells
1851 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1852 dpyinfo
->color_cells
1853 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1854 * sizeof *dpyinfo
->color_cells
);
1856 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1857 dpyinfo
->color_cells
[i
].pixel
= i
;
1859 XQueryColors (dpy
, dpyinfo
->cmap
,
1860 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1863 *ncells
= dpyinfo
->ncolor_cells
;
1864 return dpyinfo
->color_cells
;
1868 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1869 colors in COLORS. Use cached information, if available. */
1872 x_query_colors (f
, colors
, ncolors
)
1877 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1879 if (dpyinfo
->color_cells
)
1882 for (i
= 0; i
< ncolors
; ++i
)
1884 unsigned long pixel
= colors
[i
].pixel
;
1885 xassert (pixel
< dpyinfo
->ncolor_cells
);
1886 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1887 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1891 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1895 /* On frame F, translate pixel color to RGB values for the color in
1896 COLOR. Use cached information, if available. */
1899 x_query_color (f
, color
)
1903 x_query_colors (f
, color
, 1);
1907 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1908 exact match can't be allocated, try the nearest color available.
1909 Value is non-zero if successful. Set *COLOR to the color
1913 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1920 rc
= XAllocColor (dpy
, cmap
, color
);
1923 /* If we got to this point, the colormap is full, so we're going
1924 to try to get the next closest color. The algorithm used is
1925 a least-squares matching, which is what X uses for closest
1926 color matching with StaticColor visuals. */
1928 unsigned long nearest_delta
= ~0;
1930 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1932 for (nearest
= i
= 0; i
< ncells
; ++i
)
1934 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1935 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1936 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1937 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1939 if (delta
< nearest_delta
)
1942 nearest_delta
= delta
;
1946 color
->red
= cells
[nearest
].red
;
1947 color
->green
= cells
[nearest
].green
;
1948 color
->blue
= cells
[nearest
].blue
;
1949 rc
= XAllocColor (dpy
, cmap
, color
);
1953 /* If allocation succeeded, and the allocated pixel color is not
1954 equal to a cached pixel color recorded earlier, there was a
1955 change in the colormap, so clear the color cache. */
1956 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1957 XColor
*cached_color
;
1959 if (dpyinfo
->color_cells
1960 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1961 (cached_color
->red
!= color
->red
1962 || cached_color
->blue
!= color
->blue
1963 || cached_color
->green
!= color
->green
)))
1965 xfree (dpyinfo
->color_cells
);
1966 dpyinfo
->color_cells
= NULL
;
1967 dpyinfo
->ncolor_cells
= 0;
1971 #ifdef DEBUG_X_COLORS
1973 register_color (color
->pixel
);
1974 #endif /* DEBUG_X_COLORS */
1980 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1981 exact match can't be allocated, try the nearest color available.
1982 Value is non-zero if successful. Set *COLOR to the color
1986 x_alloc_nearest_color (f
, cmap
, color
)
1991 gamma_correct (f
, color
);
1992 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1996 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1997 It's necessary to do this instead of just using PIXEL directly to
1998 get color reference counts right. */
2001 x_copy_color (f
, pixel
)
2003 unsigned long pixel
;
2007 color
.pixel
= pixel
;
2009 x_query_color (f
, &color
);
2010 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2012 #ifdef DEBUG_X_COLORS
2013 register_color (pixel
);
2019 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
2020 It's necessary to do this instead of just using PIXEL directly to
2021 get color reference counts right. */
2024 x_copy_dpy_color (dpy
, cmap
, pixel
)
2027 unsigned long pixel
;
2031 color
.pixel
= pixel
;
2033 XQueryColor (dpy
, cmap
, &color
);
2034 XAllocColor (dpy
, cmap
, &color
);
2036 #ifdef DEBUG_X_COLORS
2037 register_color (pixel
);
2043 /* Brightness beyond which a color won't have its highlight brightness
2046 Nominally, highlight colors for `3d' faces are calculated by
2047 brightening an object's color by a constant scale factor, but this
2048 doesn't yield good results for dark colors, so for colors who's
2049 brightness is less than this value (on a scale of 0-65535) have an
2050 use an additional additive factor.
2052 The value here is set so that the default menu-bar/mode-line color
2053 (grey75) will not have its highlights changed at all. */
2054 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
2057 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
2058 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2059 If this produces the same color as PIXEL, try a color where all RGB
2060 values have DELTA added. Return the allocated color in *PIXEL.
2061 DISPLAY is the X display, CMAP is the colormap to operate on.
2062 Value is non-zero if successful. */
2065 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
2069 unsigned long *pixel
;
2077 /* Get RGB color values. */
2078 color
.pixel
= *pixel
;
2079 x_query_color (f
, &color
);
2081 /* Change RGB values by specified FACTOR. Avoid overflow! */
2082 xassert (factor
>= 0);
2083 new.red
= min (0xffff, factor
* color
.red
);
2084 new.green
= min (0xffff, factor
* color
.green
);
2085 new.blue
= min (0xffff, factor
* color
.blue
);
2087 /* Calculate brightness of COLOR. */
2088 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
2090 /* We only boost colors that are darker than
2091 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2092 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2093 /* Make an additive adjustment to NEW, because it's dark enough so
2094 that scaling by FACTOR alone isn't enough. */
2096 /* How far below the limit this color is (0 - 1, 1 being darker). */
2097 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2098 /* The additive adjustment. */
2099 int min_delta
= delta
* dimness
* factor
/ 2;
2103 new.red
= max (0, new.red
- min_delta
);
2104 new.green
= max (0, new.green
- min_delta
);
2105 new.blue
= max (0, new.blue
- min_delta
);
2109 new.red
= min (0xffff, min_delta
+ new.red
);
2110 new.green
= min (0xffff, min_delta
+ new.green
);
2111 new.blue
= min (0xffff, min_delta
+ new.blue
);
2115 /* Try to allocate the color. */
2116 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2119 if (new.pixel
== *pixel
)
2121 /* If we end up with the same color as before, try adding
2122 delta to the RGB values. */
2123 x_free_colors (f
, &new.pixel
, 1);
2125 new.red
= min (0xffff, delta
+ color
.red
);
2126 new.green
= min (0xffff, delta
+ color
.green
);
2127 new.blue
= min (0xffff, delta
+ color
.blue
);
2128 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2139 /* Set up the foreground color for drawing relief lines of glyph
2140 string S. RELIEF is a pointer to a struct relief containing the GC
2141 with which lines will be drawn. Use a color that is FACTOR or
2142 DELTA lighter or darker than the relief's background which is found
2143 in S->f->output_data.x->relief_background. If such a color cannot
2144 be allocated, use DEFAULT_PIXEL, instead. */
2147 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
2149 struct relief
*relief
;
2152 unsigned long default_pixel
;
2155 struct x_output
*di
= f
->output_data
.x
;
2156 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
2157 unsigned long pixel
;
2158 unsigned long background
= di
->relief_background
;
2159 Colormap cmap
= FRAME_X_COLORMAP (f
);
2160 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2161 Display
*dpy
= FRAME_X_DISPLAY (f
);
2163 xgcv
.graphics_exposures
= False
;
2164 xgcv
.line_width
= 1;
2166 /* Free previously allocated color. The color cell will be reused
2167 when it has been freed as many times as it was allocated, so this
2168 doesn't affect faces using the same colors. */
2170 && relief
->allocated_p
)
2172 x_free_colors (f
, &relief
->pixel
, 1);
2173 relief
->allocated_p
= 0;
2176 /* Allocate new color. */
2177 xgcv
.foreground
= default_pixel
;
2179 if (dpyinfo
->n_planes
!= 1
2180 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
2182 relief
->allocated_p
= 1;
2183 xgcv
.foreground
= relief
->pixel
= pixel
;
2186 if (relief
->gc
== 0)
2188 xgcv
.stipple
= dpyinfo
->gray
;
2190 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
2193 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
2197 /* Set up colors for the relief lines around glyph string S. */
2200 x_setup_relief_colors (s
)
2201 struct glyph_string
*s
;
2203 struct x_output
*di
= s
->f
->output_data
.x
;
2204 unsigned long color
;
2206 if (s
->face
->use_box_color_for_shadows_p
)
2207 color
= s
->face
->box_color
;
2208 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2210 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2211 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2216 /* Get the background color of the face. */
2217 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2218 color
= xgcv
.background
;
2221 if (di
->white_relief
.gc
== 0
2222 || color
!= di
->relief_background
)
2224 di
->relief_background
= color
;
2225 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2226 WHITE_PIX_DEFAULT (s
->f
));
2227 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2228 BLACK_PIX_DEFAULT (s
->f
));
2233 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2234 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2235 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2236 relief. LEFT_P non-zero means draw a relief on the left side of
2237 the rectangle. RIGHT_P non-zero means draw a relief on the right
2238 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2242 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2243 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2245 int left_x
, top_y
, right_x
, bottom_y
, width
;
2246 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2247 XRectangle
*clip_rect
;
2249 Display
*dpy
= FRAME_X_DISPLAY (f
);
2250 Window window
= FRAME_X_WINDOW (f
);
2255 gc
= f
->output_data
.x
->white_relief
.gc
;
2257 gc
= f
->output_data
.x
->black_relief
.gc
;
2258 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2262 for (i
= 0; i
< width
; ++i
)
2263 XDrawLine (dpy
, window
, gc
,
2264 left_x
+ i
* left_p
, top_y
+ i
,
2265 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2269 for (i
= 0; i
< width
; ++i
)
2270 XDrawLine (dpy
, window
, gc
,
2271 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2273 XSetClipMask (dpy
, gc
, None
);
2275 gc
= f
->output_data
.x
->black_relief
.gc
;
2277 gc
= f
->output_data
.x
->white_relief
.gc
;
2278 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2282 for (i
= 0; i
< width
; ++i
)
2283 XDrawLine (dpy
, window
, gc
,
2284 left_x
+ i
* left_p
, bottom_y
- i
,
2285 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2289 for (i
= 0; i
< width
; ++i
)
2290 XDrawLine (dpy
, window
, gc
,
2291 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2293 XSetClipMask (dpy
, gc
, None
);
2297 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2298 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2299 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2300 left side of the rectangle. RIGHT_P non-zero means draw a line
2301 on the right side of the rectangle. CLIP_RECT is the clipping
2302 rectangle to use when drawing. */
2305 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2306 left_p
, right_p
, clip_rect
)
2307 struct glyph_string
*s
;
2308 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2309 XRectangle
*clip_rect
;
2313 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2314 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2315 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2318 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2319 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2323 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2324 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2327 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2328 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2332 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2333 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2335 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2336 XSetClipMask (s
->display
, s
->gc
, None
);
2340 /* Draw a box around glyph string S. */
2343 x_draw_glyph_string_box (s
)
2344 struct glyph_string
*s
;
2346 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2347 int left_p
, right_p
;
2348 struct glyph
*last_glyph
;
2349 XRectangle clip_rect
;
2351 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2352 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2353 : window_box_right (s
->w
, s
->area
));
2355 /* The glyph that may have a right box line. */
2356 last_glyph
= (s
->cmp
|| s
->img
2358 : s
->first_glyph
+ s
->nchars
- 1);
2360 width
= eabs (s
->face
->box_line_width
);
2361 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2363 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2365 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2367 bottom_y
= top_y
+ s
->height
- 1;
2369 left_p
= (s
->first_glyph
->left_box_line_p
2370 || (s
->hl
== DRAW_MOUSE_FACE
2372 || s
->prev
->hl
!= s
->hl
)));
2373 right_p
= (last_glyph
->right_box_line_p
2374 || (s
->hl
== DRAW_MOUSE_FACE
2376 || s
->next
->hl
!= s
->hl
)));
2378 get_glyph_string_clip_rect (s
, &clip_rect
);
2380 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2381 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2382 left_p
, right_p
, &clip_rect
);
2385 x_setup_relief_colors (s
);
2386 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2387 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2392 /* Draw foreground of image glyph string S. */
2395 x_draw_image_foreground (s
)
2396 struct glyph_string
*s
;
2399 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2401 /* If first glyph of S has a left box line, start drawing it to the
2402 right of that line. */
2403 if (s
->face
->box
!= FACE_NO_BOX
2404 && s
->first_glyph
->left_box_line_p
2406 x
+= eabs (s
->face
->box_line_width
);
2408 /* If there is a margin around the image, adjust x- and y-position
2410 if (s
->slice
.x
== 0)
2411 x
+= s
->img
->hmargin
;
2412 if (s
->slice
.y
== 0)
2413 y
+= s
->img
->vmargin
;
2419 /* We can't set both a clip mask and use XSetClipRectangles
2420 because the latter also sets a clip mask. We also can't
2421 trust on the shape extension to be available
2422 (XShapeCombineRegion). So, compute the rectangle to draw
2424 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2427 XRectangle clip_rect
, image_rect
, r
;
2429 xgcv
.clip_mask
= s
->img
->mask
;
2430 xgcv
.clip_x_origin
= x
;
2431 xgcv
.clip_y_origin
= y
;
2432 xgcv
.function
= GXcopy
;
2433 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2435 get_glyph_string_clip_rect (s
, &clip_rect
);
2438 image_rect
.width
= s
->slice
.width
;
2439 image_rect
.height
= s
->slice
.height
;
2440 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2441 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2442 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2443 r
.width
, r
.height
, r
.x
, r
.y
);
2447 XRectangle clip_rect
, image_rect
, r
;
2449 get_glyph_string_clip_rect (s
, &clip_rect
);
2452 image_rect
.width
= s
->slice
.width
;
2453 image_rect
.height
= s
->slice
.height
;
2454 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2455 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2456 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2457 r
.width
, r
.height
, r
.x
, r
.y
);
2459 /* When the image has a mask, we can expect that at
2460 least part of a mouse highlight or a block cursor will
2461 be visible. If the image doesn't have a mask, make
2462 a block cursor visible by drawing a rectangle around
2463 the image. I believe it's looking better if we do
2464 nothing here for mouse-face. */
2465 if (s
->hl
== DRAW_CURSOR
)
2467 int r
= s
->img
->relief
;
2469 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2471 s
->slice
.width
+ r
*2 - 1,
2472 s
->slice
.height
+ r
*2 - 1);
2477 /* Draw a rectangle if image could not be loaded. */
2478 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2479 s
->slice
.width
- 1, s
->slice
.height
- 1);
2483 /* Draw a relief around the image glyph string S. */
2486 x_draw_image_relief (s
)
2487 struct glyph_string
*s
;
2489 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2492 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2494 /* If first glyph of S has a left box line, start drawing it to the
2495 right of that line. */
2496 if (s
->face
->box
!= FACE_NO_BOX
2497 && s
->first_glyph
->left_box_line_p
2499 x
+= eabs (s
->face
->box_line_width
);
2501 /* If there is a margin around the image, adjust x- and y-position
2503 if (s
->slice
.x
== 0)
2504 x
+= s
->img
->hmargin
;
2505 if (s
->slice
.y
== 0)
2506 y
+= s
->img
->vmargin
;
2508 if (s
->hl
== DRAW_IMAGE_SUNKEN
2509 || s
->hl
== DRAW_IMAGE_RAISED
)
2511 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2512 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2516 thick
= eabs (s
->img
->relief
);
2517 raised_p
= s
->img
->relief
> 0;
2522 x1
= x
+ s
->slice
.width
+ thick
- 1;
2523 y1
= y
+ s
->slice
.height
+ thick
- 1;
2525 x_setup_relief_colors (s
);
2526 get_glyph_string_clip_rect (s
, &r
);
2527 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2529 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2531 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2536 /* Draw the foreground of image glyph string S to PIXMAP. */
2539 x_draw_image_foreground_1 (s
, pixmap
)
2540 struct glyph_string
*s
;
2544 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2546 /* If first glyph of S has a left box line, start drawing it to the
2547 right of that line. */
2548 if (s
->face
->box
!= FACE_NO_BOX
2549 && s
->first_glyph
->left_box_line_p
2551 x
+= eabs (s
->face
->box_line_width
);
2553 /* If there is a margin around the image, adjust x- and y-position
2555 if (s
->slice
.x
== 0)
2556 x
+= s
->img
->hmargin
;
2557 if (s
->slice
.y
== 0)
2558 y
+= s
->img
->vmargin
;
2564 /* We can't set both a clip mask and use XSetClipRectangles
2565 because the latter also sets a clip mask. We also can't
2566 trust on the shape extension to be available
2567 (XShapeCombineRegion). So, compute the rectangle to draw
2569 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2573 xgcv
.clip_mask
= s
->img
->mask
;
2574 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2575 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2576 xgcv
.function
= GXcopy
;
2577 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2579 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2580 s
->slice
.x
, s
->slice
.y
,
2581 s
->slice
.width
, s
->slice
.height
, x
, y
);
2582 XSetClipMask (s
->display
, s
->gc
, None
);
2586 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2587 s
->slice
.x
, s
->slice
.y
,
2588 s
->slice
.width
, s
->slice
.height
, x
, y
);
2590 /* When the image has a mask, we can expect that at
2591 least part of a mouse highlight or a block cursor will
2592 be visible. If the image doesn't have a mask, make
2593 a block cursor visible by drawing a rectangle around
2594 the image. I believe it's looking better if we do
2595 nothing here for mouse-face. */
2596 if (s
->hl
== DRAW_CURSOR
)
2598 int r
= s
->img
->relief
;
2600 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2601 s
->slice
.width
+ r
*2 - 1,
2602 s
->slice
.height
+ r
*2 - 1);
2607 /* Draw a rectangle if image could not be loaded. */
2608 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2609 s
->slice
.width
- 1, s
->slice
.height
- 1);
2613 /* Draw part of the background of glyph string S. X, Y, W, and H
2614 give the rectangle to draw. */
2617 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2618 struct glyph_string
*s
;
2623 /* Fill background with a stipple pattern. */
2624 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2625 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2626 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2629 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2633 /* Draw image glyph string S.
2636 s->x +-------------------------
2639 | +-------------------------
2642 | | +-------------------
2648 x_draw_image_glyph_string (s
)
2649 struct glyph_string
*s
;
2651 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2652 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2654 Pixmap pixmap
= None
;
2657 if (s
->slice
.y
== 0)
2658 height
-= box_line_vwidth
;
2659 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2660 height
-= box_line_vwidth
;
2662 /* Fill background with face under the image. Do it only if row is
2663 taller than image or if image has a clip mask to reduce
2665 s
->stippled_p
= s
->face
->stipple
!= 0;
2666 if (height
> s
->slice
.height
2670 || s
->img
->pixmap
== 0
2671 || s
->width
!= s
->background_width
)
2675 /* Create a pixmap as large as the glyph string. Fill it
2676 with the background color. Copy the image to it, using
2677 its mask. Copy the temporary pixmap to the display. */
2678 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2679 int depth
= DefaultDepthOfScreen (screen
);
2681 /* Create a pixmap as large as the glyph string. */
2682 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2683 s
->background_width
,
2686 /* Don't clip in the following because we're working on the
2688 XSetClipMask (s
->display
, s
->gc
, None
);
2690 /* Fill the pixmap with the background color/stipple. */
2693 /* Fill background with a stipple pattern. */
2694 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2695 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2696 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2697 0, 0, s
->background_width
, s
->height
);
2698 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2699 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2704 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2706 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2707 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2708 0, 0, s
->background_width
, s
->height
);
2709 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2717 if (s
->first_glyph
->left_box_line_p
2719 x
+= box_line_hwidth
;
2721 if (s
->slice
.y
== 0)
2722 y
+= box_line_vwidth
;
2724 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2727 s
->background_filled_p
= 1;
2730 /* Draw the foreground. */
2733 x_draw_image_foreground_1 (s
, pixmap
);
2734 x_set_glyph_string_clipping (s
);
2735 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2736 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2737 XFreePixmap (s
->display
, pixmap
);
2740 x_draw_image_foreground (s
);
2742 /* If we must draw a relief around the image, do it. */
2744 || s
->hl
== DRAW_IMAGE_RAISED
2745 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2746 x_draw_image_relief (s
);
2750 /* Draw stretch glyph string S. */
2753 x_draw_stretch_glyph_string (s
)
2754 struct glyph_string
*s
;
2756 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2757 s
->stippled_p
= s
->face
->stipple
!= 0;
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
);
3617 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3620 x_mouse_leave (dpyinfo
)
3621 struct x_display_info
*dpyinfo
;
3623 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3626 /* The focus has changed, or we have redirected a frame's focus to
3627 another frame (this happens when a frame uses a surrogate
3628 mini-buffer frame). Shift the highlight as appropriate.
3630 The FRAME argument doesn't necessarily have anything to do with which
3631 frame is being highlighted or un-highlighted; we only use it to find
3632 the appropriate X display info. */
3635 XTframe_rehighlight (frame
)
3636 struct frame
*frame
;
3638 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3642 x_frame_rehighlight (dpyinfo
)
3643 struct x_display_info
*dpyinfo
;
3645 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3647 if (dpyinfo
->x_focus_frame
)
3649 dpyinfo
->x_highlight_frame
3650 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3651 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3652 : dpyinfo
->x_focus_frame
);
3653 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3655 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3656 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3660 dpyinfo
->x_highlight_frame
= 0;
3662 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3665 frame_unhighlight (old_highlight
);
3666 if (dpyinfo
->x_highlight_frame
)
3667 frame_highlight (dpyinfo
->x_highlight_frame
);
3673 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3675 /* Initialize mode_switch_bit and modifier_meaning. */
3677 x_find_modifier_meanings (dpyinfo
)
3678 struct x_display_info
*dpyinfo
;
3680 int min_code
, max_code
;
3683 XModifierKeymap
*mods
;
3685 dpyinfo
->meta_mod_mask
= 0;
3686 dpyinfo
->shift_lock_mask
= 0;
3687 dpyinfo
->alt_mod_mask
= 0;
3688 dpyinfo
->super_mod_mask
= 0;
3689 dpyinfo
->hyper_mod_mask
= 0;
3692 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3694 min_code
= dpyinfo
->display
->min_keycode
;
3695 max_code
= dpyinfo
->display
->max_keycode
;
3698 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3699 min_code
, max_code
- min_code
+ 1,
3701 mods
= XGetModifierMapping (dpyinfo
->display
);
3703 /* Scan the modifier table to see which modifier bits the Meta and
3704 Alt keysyms are on. */
3706 int row
, col
; /* The row and column in the modifier table. */
3707 int found_alt_or_meta
;
3709 for (row
= 3; row
< 8; row
++)
3711 found_alt_or_meta
= 0;
3712 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3714 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3716 /* Zeroes are used for filler. Skip them. */
3720 /* Are any of this keycode's keysyms a meta key? */
3724 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3726 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3732 found_alt_or_meta
= 1;
3733 dpyinfo
->meta_mod_mask
|= (1 << row
);
3738 found_alt_or_meta
= 1;
3739 dpyinfo
->alt_mod_mask
|= (1 << row
);
3744 if (!found_alt_or_meta
)
3745 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3746 code_col
= syms_per_code
;
3747 col
= mods
->max_keypermod
;
3752 if (!found_alt_or_meta
)
3753 dpyinfo
->super_mod_mask
|= (1 << row
);
3754 code_col
= syms_per_code
;
3755 col
= mods
->max_keypermod
;
3759 /* Ignore this if it's not on the lock modifier. */
3760 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3761 dpyinfo
->shift_lock_mask
= LockMask
;
3762 code_col
= syms_per_code
;
3763 col
= mods
->max_keypermod
;
3772 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3773 if (! dpyinfo
->meta_mod_mask
)
3775 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3776 dpyinfo
->alt_mod_mask
= 0;
3779 /* If some keys are both alt and meta,
3780 make them just meta, not alt. */
3781 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3783 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3786 XFree ((char *) syms
);
3787 XFreeModifiermap (mods
);
3790 /* Convert between the modifier bits X uses and the modifier bits
3794 x_x_to_emacs_modifiers (dpyinfo
, state
)
3795 struct x_display_info
*dpyinfo
;
3798 EMACS_UINT mod_meta
= meta_modifier
;
3799 EMACS_UINT mod_alt
= alt_modifier
;
3800 EMACS_UINT mod_hyper
= hyper_modifier
;
3801 EMACS_UINT mod_super
= super_modifier
;
3804 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3805 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3806 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3807 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3808 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3809 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3810 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3811 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3814 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3815 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3816 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3817 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3818 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3819 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3823 x_emacs_to_x_modifiers (dpyinfo
, state
)
3824 struct x_display_info
*dpyinfo
;
3827 EMACS_UINT mod_meta
= meta_modifier
;
3828 EMACS_UINT mod_alt
= alt_modifier
;
3829 EMACS_UINT mod_hyper
= hyper_modifier
;
3830 EMACS_UINT mod_super
= super_modifier
;
3834 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3835 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3836 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3837 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3838 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3839 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3840 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3841 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3844 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3845 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3846 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3847 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3848 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3849 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3852 /* Convert a keysym to its name. */
3855 x_get_keysym_name (keysym
)
3861 value
= XKeysymToString (keysym
);
3869 /* Mouse clicks and mouse movement. Rah. */
3871 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3873 If the event is a button press, then note that we have grabbed
3877 construct_mouse_click (result
, event
, f
)
3878 struct input_event
*result
;
3879 XButtonEvent
*event
;
3882 /* Make the event type NO_EVENT; we'll change that when we decide
3884 result
->kind
= MOUSE_CLICK_EVENT
;
3885 result
->code
= event
->button
- Button1
;
3886 result
->timestamp
= event
->time
;
3887 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3889 | (event
->type
== ButtonRelease
3893 XSETINT (result
->x
, event
->x
);
3894 XSETINT (result
->y
, event
->y
);
3895 XSETFRAME (result
->frame_or_window
, f
);
3901 /* Function to report a mouse movement to the mainstream Emacs code.
3902 The input handler calls this.
3904 We have received a mouse movement event, which is given in *event.
3905 If the mouse is over a different glyph than it was last time, tell
3906 the mainstream emacs code by setting mouse_moved. If not, ask for
3907 another motion event, so we can check again the next time it moves. */
3909 static XMotionEvent last_mouse_motion_event
;
3910 static Lisp_Object last_mouse_motion_frame
;
3913 note_mouse_movement (frame
, event
)
3915 XMotionEvent
*event
;
3917 last_mouse_movement_time
= event
->time
;
3918 last_mouse_motion_event
= *event
;
3919 XSETFRAME (last_mouse_motion_frame
, frame
);
3921 if (!FRAME_X_OUTPUT (frame
))
3924 if (event
->window
!= FRAME_X_WINDOW (frame
))
3926 frame
->mouse_moved
= 1;
3927 last_mouse_scroll_bar
= Qnil
;
3928 note_mouse_highlight (frame
, -1, -1);
3929 last_mouse_glyph_frame
= 0;
3934 /* Has the mouse moved off the glyph it was on at the last sighting? */
3935 if (frame
!= last_mouse_glyph_frame
3936 || event
->x
< last_mouse_glyph
.x
3937 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3938 || event
->y
< last_mouse_glyph
.y
3939 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3941 frame
->mouse_moved
= 1;
3942 last_mouse_scroll_bar
= Qnil
;
3943 note_mouse_highlight (frame
, event
->x
, event
->y
);
3944 /* Remember which glyph we're now on. */
3945 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3946 last_mouse_glyph_frame
= frame
;
3954 /************************************************************************
3956 ************************************************************************/
3959 redo_mouse_highlight ()
3961 if (!NILP (last_mouse_motion_frame
)
3962 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3963 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3964 last_mouse_motion_event
.x
,
3965 last_mouse_motion_event
.y
);
3970 /* Return the current position of the mouse.
3971 *FP should be a frame which indicates which display to ask about.
3973 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3974 and *PART to the frame, window, and scroll bar part that the mouse
3975 is over. Set *X and *Y to the portion and whole of the mouse's
3976 position on the scroll bar.
3978 If the mouse movement started elsewhere, set *FP to the frame the
3979 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3982 Set *TIME to the server time-stamp for the time at which the mouse
3983 was at this position.
3985 Don't store anything if we don't have a valid set of values to report.
3987 This clears the mouse_moved flag, so we can wait for the next mouse
3991 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3994 Lisp_Object
*bar_window
;
3995 enum scroll_bar_part
*part
;
3997 unsigned long *time
;
4003 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
4004 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
4010 Window dummy_window
;
4013 Lisp_Object frame
, tail
;
4015 /* Clear the mouse-moved flag for every frame on this display. */
4016 FOR_EACH_FRAME (tail
, frame
)
4017 if (FRAME_X_P (XFRAME (frame
))
4018 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
4019 XFRAME (frame
)->mouse_moved
= 0;
4021 last_mouse_scroll_bar
= Qnil
;
4023 /* Figure out which root window we're on. */
4024 XQueryPointer (FRAME_X_DISPLAY (*fp
),
4025 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
4027 /* The root window which contains the pointer. */
4030 /* Trash which we can't trust if the pointer is on
4031 a different screen. */
4034 /* The position on that root window. */
4037 /* More trash we can't trust. */
4040 /* Modifier keys and pointer buttons, about which
4042 (unsigned int *) &dummy
);
4044 /* Now we have a position on the root; find the innermost window
4045 containing the pointer. */
4049 int parent_x
= 0, parent_y
= 0;
4053 /* XTranslateCoordinates can get errors if the window
4054 structure is changing at the same time this function
4055 is running. So at least we must not crash from them. */
4057 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4059 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4060 && FRAME_LIVE_P (last_mouse_frame
))
4062 /* If mouse was grabbed on a frame, give coords for that frame
4063 even if the mouse is now outside it. */
4064 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4066 /* From-window, to-window. */
4067 root
, FRAME_X_WINDOW (last_mouse_frame
),
4069 /* From-position, to-position. */
4070 root_x
, root_y
, &win_x
, &win_y
,
4074 f1
= last_mouse_frame
;
4080 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4082 /* From-window, to-window. */
4085 /* From-position, to-position. */
4086 root_x
, root_y
, &win_x
, &win_y
,
4091 if (child
== None
|| child
== win
)
4099 /* Now we know that:
4100 win is the innermost window containing the pointer
4101 (XTC says it has no child containing the pointer),
4102 win_x and win_y are the pointer's position in it
4103 (XTC did this the last time through), and
4104 parent_x and parent_y are the pointer's position in win's parent.
4105 (They are what win_x and win_y were when win was child.
4106 If win is the root window, it has no parent, and
4107 parent_{x,y} are invalid, but that's okay, because we'll
4108 never use them in that case.) */
4110 /* Is win one of our frames? */
4111 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
4113 #ifdef USE_X_TOOLKIT
4114 /* If we end up with the menu bar window, say it's not
4117 && f1
->output_data
.x
->menubar_widget
4118 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4120 #endif /* USE_X_TOOLKIT */
4123 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4126 x_uncatch_errors ();
4128 /* If not, is it one of our scroll bars? */
4131 struct scroll_bar
*bar
;
4133 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
4137 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4143 if (f1
== 0 && insist
> 0)
4144 f1
= SELECTED_FRAME ();
4148 /* Ok, we found a frame. Store all the values.
4149 last_mouse_glyph is a rectangle used to reduce the
4150 generation of mouse events. To not miss any motion
4151 events, we must divide the frame into rectangles of the
4152 size of the smallest character that could be displayed
4153 on it, i.e. into the same rectangles that matrices on
4154 the frame are divided into. */
4156 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
4157 last_mouse_glyph_frame
= f1
;
4162 XSETINT (*x
, win_x
);
4163 XSETINT (*y
, win_y
);
4164 *time
= last_mouse_movement_time
;
4174 /***********************************************************************
4176 ***********************************************************************/
4178 /* Scroll bar support. */
4180 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4182 This can be called in GC, so we have to make sure to strip off mark
4185 static struct scroll_bar
*
4186 x_window_to_scroll_bar (display
, window_id
)
4192 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4193 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4194 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4196 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4198 Lisp_Object frame
, bar
, condemned
;
4200 frame
= XCAR (tail
);
4201 /* All elements of Vframe_list should be frames. */
4202 if (! FRAMEP (frame
))
4205 if (! FRAME_X_P (XFRAME (frame
)))
4208 /* Scan this frame's scroll bar list for a scroll bar with the
4210 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4211 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4212 /* This trick allows us to search both the ordinary and
4213 condemned scroll bar lists with one loop. */
4214 ! NILP (bar
) || (bar
= condemned
,
4217 bar
= XSCROLL_BAR (bar
)->next
)
4218 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
&&
4219 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4220 return XSCROLL_BAR (bar
);
4227 #if defined USE_LUCID
4229 /* Return the Lucid menu bar WINDOW is part of. Return null
4230 if WINDOW is not part of a menu bar. */
4233 x_window_to_menu_bar (window
)
4238 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4240 if (FRAME_X_P (XFRAME (XCAR (tail
))))
4242 Lisp_Object frame
= XCAR (tail
);
4243 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4245 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4253 #endif /* USE_LUCID */
4256 /************************************************************************
4258 ************************************************************************/
4260 #ifdef USE_TOOLKIT_SCROLL_BARS
4262 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
4263 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
4264 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
4265 struct scroll_bar
*));
4266 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4270 /* Lisp window being scrolled. Set when starting to interact with
4271 a toolkit scroll bar, reset to nil when ending the interaction. */
4273 static Lisp_Object window_being_scrolled
;
4275 /* Last scroll bar part sent in xm_scroll_callback. */
4277 static int last_scroll_bar_part
;
4279 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4280 that movements of 1/20 of the screen size are mapped to up/down. */
4283 /* Id of action hook installed for scroll bars. */
4285 static XtActionHookId action_hook_id
;
4287 static Boolean xaw3d_arrow_scroll
;
4289 /* Whether the drag scrolling maintains the mouse at the top of the
4290 thumb. If not, resizing the thumb needs to be done more carefully
4291 to avoid jerkyness. */
4293 static Boolean xaw3d_pick_top
;
4295 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4296 bars are used.. The hook is responsible for detecting when
4297 the user ends an interaction with the scroll bar, and generates
4298 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4301 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
4304 XtPointer client_data
;
4308 Cardinal
*num_params
;
4314 scroll_bar_p
= XmIsScrollBar (widget
);
4315 end_action
= "Release";
4316 #else /* !USE_MOTIF i.e. use Xaw */
4317 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4318 end_action
= "EndScroll";
4319 #endif /* USE_MOTIF */
4322 && strcmp (action_name
, end_action
) == 0
4323 && WINDOWP (window_being_scrolled
))
4327 x_send_scroll_bar_event (window_being_scrolled
,
4328 scroll_bar_end_scroll
, 0, 0);
4329 w
= XWINDOW (window_being_scrolled
);
4331 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4333 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4334 /* The thumb size is incorrect while dragging: fix it. */
4335 set_vertical_scroll_bar (w
);
4337 window_being_scrolled
= Qnil
;
4338 last_scroll_bar_part
= -1;
4340 /* Xt timeouts no longer needed. */
4341 toolkit_scroll_bar_interaction
= 0;
4344 #endif /* not USE_GTK */
4346 /* A vector of windows used for communication between
4347 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4349 static struct window
**scroll_bar_windows
;
4350 static int scroll_bar_windows_size
;
4353 /* Send a client message with message type Xatom_Scrollbar for a
4354 scroll action to the frame of WINDOW. PART is a value identifying
4355 the part of the scroll bar that was clicked on. PORTION is the
4356 amount to scroll of a whole of WHOLE. */
4359 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4361 int part
, portion
, whole
;
4364 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4365 struct window
*w
= XWINDOW (window
);
4366 struct frame
*f
= XFRAME (w
->frame
);
4371 /* Construct a ClientMessage event to send to the frame. */
4372 ev
->type
= ClientMessage
;
4373 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4374 ev
->display
= FRAME_X_DISPLAY (f
);
4375 ev
->window
= FRAME_X_WINDOW (f
);
4378 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4379 not enough to store a pointer or Lisp_Object on a 64 bit system.
4380 So, store the window in scroll_bar_windows and pass the index
4381 into that array in the event. */
4382 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4383 if (scroll_bar_windows
[i
] == NULL
)
4386 if (i
== scroll_bar_windows_size
)
4388 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4389 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4390 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4392 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4394 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4395 scroll_bar_windows_size
= new_size
;
4398 scroll_bar_windows
[i
] = w
;
4399 ev
->data
.l
[0] = (long) i
;
4400 ev
->data
.l
[1] = (long) part
;
4401 ev
->data
.l
[2] = (long) 0;
4402 ev
->data
.l
[3] = (long) portion
;
4403 ev
->data
.l
[4] = (long) whole
;
4405 /* Make Xt timeouts work while the scroll bar is active. */
4406 toolkit_scroll_bar_interaction
= 1;
4407 #ifdef USE_X_TOOLKIT
4408 x_activate_timeout_atimer ();
4411 /* Setting the event mask to zero means that the message will
4412 be sent to the client that created the window, and if that
4413 window no longer exists, no event will be sent. */
4414 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4419 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4423 x_scroll_bar_to_input_event (event
, ievent
)
4425 struct input_event
*ievent
;
4427 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4432 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4433 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4435 XSETWINDOW (window
, w
);
4436 f
= XFRAME (w
->frame
);
4438 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4439 ievent
->frame_or_window
= window
;
4442 ievent
->timestamp
= CurrentTime
;
4444 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4446 ievent
->part
= ev
->data
.l
[1];
4447 ievent
->code
= ev
->data
.l
[2];
4448 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4449 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4450 ievent
->modifiers
= 0;
4456 /* Minimum and maximum values used for Motif scroll bars. */
4458 #define XM_SB_MAX 10000000
4461 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4462 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4463 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4466 xm_scroll_callback (widget
, client_data
, call_data
)
4468 XtPointer client_data
, call_data
;
4470 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4471 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4472 int part
= -1, whole
= 0, portion
= 0;
4476 case XmCR_DECREMENT
:
4477 bar
->dragging
= Qnil
;
4478 part
= scroll_bar_up_arrow
;
4481 case XmCR_INCREMENT
:
4482 bar
->dragging
= Qnil
;
4483 part
= scroll_bar_down_arrow
;
4486 case XmCR_PAGE_DECREMENT
:
4487 bar
->dragging
= Qnil
;
4488 part
= scroll_bar_above_handle
;
4491 case XmCR_PAGE_INCREMENT
:
4492 bar
->dragging
= Qnil
;
4493 part
= scroll_bar_below_handle
;
4497 bar
->dragging
= Qnil
;
4498 part
= scroll_bar_to_top
;
4501 case XmCR_TO_BOTTOM
:
4502 bar
->dragging
= Qnil
;
4503 part
= scroll_bar_to_bottom
;
4510 /* Get the slider size. */
4512 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4515 whole
= XM_SB_MAX
- slider_size
;
4516 portion
= min (cs
->value
, whole
);
4517 part
= scroll_bar_handle
;
4518 bar
->dragging
= make_number (cs
->value
);
4522 case XmCR_VALUE_CHANGED
:
4528 window_being_scrolled
= bar
->window
;
4529 last_scroll_bar_part
= part
;
4530 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4535 #else /* !USE_MOTIF, i.e. Xaw or GTK */
4537 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4538 bar widget. DATA is a pointer to the scroll_bar structure. */
4541 xg_scroll_callback (widget
, data
)
4545 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4551 int part
= -1, whole
= 0, portion
= 0;
4552 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4554 position
= gtk_adjustment_get_value (adj
);
4556 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4559 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4561 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4567 if (xg_ignore_gtk_scrollbar
) return;
4569 diff
= (int) (position
- previous
);
4571 if (diff
== (int) adj
->step_increment
)
4573 part
= scroll_bar_down_arrow
;
4574 bar
->dragging
= Qnil
;
4576 else if (-diff
== (int) adj
->step_increment
)
4578 part
= scroll_bar_up_arrow
;
4579 bar
->dragging
= Qnil
;
4581 else if (diff
== (int) adj
->page_increment
)
4583 part
= scroll_bar_below_handle
;
4584 bar
->dragging
= Qnil
;
4586 else if (-diff
== (int) adj
->page_increment
)
4588 part
= scroll_bar_above_handle
;
4589 bar
->dragging
= Qnil
;
4593 part
= scroll_bar_handle
;
4594 whole
= adj
->upper
- adj
->page_size
;
4595 portion
= min ((int)position
, whole
);
4596 bar
->dragging
= make_number ((int)portion
);
4601 window_being_scrolled
= bar
->window
;
4602 last_scroll_bar_part
= part
;
4603 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4607 #else /* not USE_GTK */
4609 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4610 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4611 scroll bar struct. CALL_DATA is a pointer to a float saying where
4615 xaw_jump_callback (widget
, client_data
, call_data
)
4617 XtPointer client_data
, call_data
;
4619 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4620 float top
= *(float *) call_data
;
4622 int whole
, portion
, height
;
4625 /* Get the size of the thumb, a value between 0 and 1. */
4627 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4631 portion
= shown
< 1 ? top
* whole
: 0;
4633 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4634 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4635 the bottom, so we force the scrolling whenever we see that we're
4636 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4637 we try to ensure that we always stay two pixels away from the
4639 part
= scroll_bar_down_arrow
;
4641 part
= scroll_bar_handle
;
4643 window_being_scrolled
= bar
->window
;
4644 bar
->dragging
= make_number (portion
);
4645 last_scroll_bar_part
= part
;
4646 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4650 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4651 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4652 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4653 the scroll bar. CALL_DATA is an integer specifying the action that
4654 has taken place. Its magnitude is in the range 0..height of the
4655 scroll bar. Negative values mean scroll towards buffer start.
4656 Values < height of scroll bar mean line-wise movement. */
4659 xaw_scroll_callback (widget
, client_data
, call_data
)
4661 XtPointer client_data
, call_data
;
4663 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4664 /* The position really is stored cast to a pointer. */
4665 int position
= (long) call_data
;
4669 /* Get the height of the scroll bar. */
4671 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4674 if (eabs (position
) >= height
)
4675 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4677 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4678 it maps line-movement to call_data = max(5, height/20). */
4679 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4680 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4682 part
= scroll_bar_move_ratio
;
4684 window_being_scrolled
= bar
->window
;
4685 bar
->dragging
= Qnil
;
4686 last_scroll_bar_part
= part
;
4687 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4690 #endif /* not USE_GTK */
4691 #endif /* not USE_MOTIF */
4693 #define SCROLL_BAR_NAME "verticalScrollBar"
4695 /* Create the widget for scroll bar BAR on frame F. Record the widget
4696 and X window of the scroll bar in BAR. */
4700 x_create_toolkit_scroll_bar (f
, bar
)
4702 struct scroll_bar
*bar
;
4704 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4707 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4712 #else /* not USE_GTK */
4715 x_create_toolkit_scroll_bar (f
, bar
)
4717 struct scroll_bar
*bar
;
4723 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4724 unsigned long pixel
;
4729 /* Set resources. Create the widget. */
4730 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4731 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4732 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4733 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4734 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4735 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4736 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4738 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4741 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4745 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4748 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4752 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4753 scroll_bar_name
, av
, ac
);
4755 /* Add one callback for everything that can happen. */
4756 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4758 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4760 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4762 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4764 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4766 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4768 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4771 /* Realize the widget. Only after that is the X window created. */
4772 XtRealizeWidget (widget
);
4774 /* Set the cursor to an arrow. I didn't find a resource to do that.
4775 And I'm wondering why it hasn't an arrow cursor by default. */
4776 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4777 f
->output_data
.x
->nontext_cursor
);
4779 #else /* !USE_MOTIF i.e. use Xaw */
4781 /* Set resources. Create the widget. The background of the
4782 Xaw3d scroll bar widget is a little bit light for my taste.
4783 We don't alter it here to let users change it according
4784 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4785 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4786 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4787 /* For smoother scrolling with Xaw3d -sm */
4788 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4790 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4793 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4797 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4800 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4804 /* Top/bottom shadow colors. */
4806 /* Allocate them, if necessary. */
4807 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4809 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4810 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4811 &pixel
, 1.2, 0x8000))
4813 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4815 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4817 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4818 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4819 &pixel
, 0.6, 0x4000))
4821 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4824 #ifdef XtNbeNiceToColormap
4825 /* Tell the toolkit about them. */
4826 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4827 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4828 /* We tried to allocate a color for the top/bottom shadow, and
4829 failed, so tell Xaw3d to use dithering instead. */
4831 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4835 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4836 be more consistent with other emacs 3d colors, and since Xaw3d is
4837 not good at dealing with allocation failure. */
4839 /* This tells Xaw3d to use real colors instead of dithering for
4841 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4844 /* Specify the colors. */
4845 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4848 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4851 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4854 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4860 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4861 f
->output_data
.x
->edit_widget
, av
, ac
);
4865 char *val
= initial
;
4866 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4867 #ifdef XtNarrowScrollbars
4868 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4870 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4871 if (xaw3d_arrow_scroll
|| val
== initial
)
4872 { /* ARROW_SCROLL */
4873 xaw3d_arrow_scroll
= True
;
4874 /* Isn't that just a personal preference ? --Stef */
4875 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4879 /* Define callbacks. */
4880 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4881 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4884 /* Realize the widget. Only after that is the X window created. */
4885 XtRealizeWidget (widget
);
4887 #endif /* !USE_MOTIF */
4889 /* Install an action hook that lets us detect when the user
4890 finishes interacting with a scroll bar. */
4891 if (action_hook_id
== 0)
4892 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4894 /* Remember X window and widget in the scroll bar vector. */
4895 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4896 xwindow
= XtWindow (widget
);
4897 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
4901 #endif /* not USE_GTK */
4904 /* Set the thumb size and position of scroll bar BAR. We are currently
4905 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4909 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4910 struct scroll_bar
*bar
;
4911 int portion
, position
, whole
;
4913 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4916 #else /* not USE_GTK */
4918 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4919 struct scroll_bar
*bar
;
4920 int portion
, position
, whole
;
4922 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4923 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4930 /* We use an estimate of 30 chars per line rather than the real
4931 `portion' value. This has the disadvantage that the thumb size
4932 is not very representative, but it makes our life a lot easier.
4933 Otherwise, we have to constantly adjust the thumb size, which
4934 we can't always do quickly enough: while dragging, the size of
4935 the thumb might prevent the user from dragging the thumb all the
4936 way to the end. but Motif and some versions of Xaw3d don't allow
4937 updating the thumb size while dragging. Also, even if we can update
4938 its size, the update will often happen too late.
4939 If you don't believe it, check out revision 1.650 of xterm.c to see
4940 what hoops we were going through and the still poor behavior we got. */
4941 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4942 /* When the thumb is at the bottom, position == whole.
4943 So we need to increase `whole' to make space for the thumb. */
4950 top
= (float) position
/ whole
;
4951 shown
= (float) portion
/ whole
;
4954 if (NILP (bar
->dragging
))
4958 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4959 is the scroll bar's maximum and MIN is the scroll bar's minimum
4961 size
= shown
* XM_SB_MAX
;
4962 size
= min (size
, XM_SB_MAX
);
4963 size
= max (size
, 1);
4965 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4966 value
= top
* XM_SB_MAX
;
4967 value
= min (value
, XM_SB_MAX
- size
);
4969 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4971 #else /* !USE_MOTIF i.e. use Xaw */
4977 top
= (float) position
/ whole
;
4978 shown
= (float) portion
/ whole
;
4982 float old_top
, old_shown
;
4984 XtVaGetValues (widget
,
4985 XtNtopOfThumb
, &old_top
,
4986 XtNshown
, &old_shown
,
4990 /* Massage the top+shown values. */
4991 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4992 top
= max (0, min (1, top
));
4995 /* Keep two pixels available for moving the thumb down. */
4996 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4998 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4999 check that your system's configuration file contains a define
5000 for `NARROWPROTO'. See s/freebsd.h for an example. */
5001 if (top
!= old_top
|| shown
!= old_shown
)
5003 if (NILP (bar
->dragging
))
5004 XawScrollbarSetThumb (widget
, top
, shown
);
5007 /* Try to make the scrolling a tad smoother. */
5008 if (!xaw3d_pick_top
)
5009 shown
= min (shown
, old_shown
);
5011 XawScrollbarSetThumb (widget
, top
, shown
);
5015 #endif /* !USE_MOTIF */
5019 #endif /* not USE_GTK */
5021 #endif /* USE_TOOLKIT_SCROLL_BARS */
5025 /************************************************************************
5026 Scroll bars, general
5027 ************************************************************************/
5029 /* Create a scroll bar and return the scroll bar vector for it. W is
5030 the Emacs window on which to create the scroll bar. TOP, LEFT,
5031 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
5034 static struct scroll_bar
*
5035 x_scroll_bar_create (w
, top
, left
, width
, height
)
5037 int top
, left
, width
, height
;
5039 struct frame
*f
= XFRAME (w
->frame
);
5040 struct scroll_bar
*bar
5041 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
5045 #ifdef USE_TOOLKIT_SCROLL_BARS
5046 x_create_toolkit_scroll_bar (f
, bar
);
5047 #else /* not USE_TOOLKIT_SCROLL_BARS */
5049 XSetWindowAttributes a
;
5053 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5054 if (a
.background_pixel
== -1)
5055 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5057 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
5058 | ButtonMotionMask
| PointerMotionHintMask
5060 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
5062 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
5064 /* Clear the area of W that will serve as a scroll bar. This is
5065 for the case that a window has been split horizontally. In
5066 this case, no clear_frame is generated to reduce flickering. */
5067 if (width
> 0 && height
> 0)
5068 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5070 window_box_height (w
), False
);
5072 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5073 /* Position and size of scroll bar. */
5074 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5076 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5078 /* Border width, depth, class, and visual. */
5085 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
5087 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5089 XSETWINDOW (bar
->window
, w
);
5090 XSETINT (bar
->top
, top
);
5091 XSETINT (bar
->left
, left
);
5092 XSETINT (bar
->width
, width
);
5093 XSETINT (bar
->height
, height
);
5094 XSETINT (bar
->start
, 0);
5095 XSETINT (bar
->end
, 0);
5096 bar
->dragging
= Qnil
;
5097 #ifdef USE_TOOLKIT_SCROLL_BARS
5098 bar
->fringe_extended_p
= Qnil
;
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
,
5113 SCROLL_BAR_X_WINDOW (bar
),
5115 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5116 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5118 xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar
));
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
), SCROLL_BAR_X_WINDOW (bar
));
5131 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5138 /* Draw BAR's handle in the proper position.
5140 If the handle is already drawn from START to END, don't bother
5141 redrawing it, unless REBUILD is non-zero; in that case, always
5142 redraw it. (REBUILD is handy for drawing the handle after expose
5145 Normally, we want to constrain the start and end of the handle to
5146 fit inside its rectangle, but if the user is dragging the scroll
5147 bar handle, we want to let them drag it down all the way, so that
5148 the bar's top is as far down as it goes; otherwise, there's no way
5149 to move to the very end of the buffer. */
5151 #ifndef USE_TOOLKIT_SCROLL_BARS
5154 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
5155 struct scroll_bar
*bar
;
5159 int dragging
= ! NILP (bar
->dragging
);
5160 Window w
= SCROLL_BAR_X_WINDOW (bar
);
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
== XINT (bar
->start
)
5167 && end
== XINT (bar
->end
))
5173 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
5174 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
5175 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (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. */
5195 XSETINT (bar
->start
, start
);
5196 XSETINT (bar
->end
, end
);
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
, SCROLL_BAR_X_WINDOW (bar
));
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
), SCROLL_BAR_X_WINDOW (bar
));
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
!= XINT (bar
->left
))
5368 if (top
!= XINT (bar
->top
))
5370 if (sb_width
!= XINT (bar
->width
))
5372 if (height
!= XINT (bar
->height
))
5375 #ifdef USE_TOOLKIT_SCROLL_BARS
5377 /* Move/size the scroll bar widget. */
5378 if (mask
|| !NILP (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
,
5393 SCROLL_BAR_X_WINDOW (bar
),
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
), SCROLL_BAR_X_WINDOW (bar
),
5453 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5455 /* Remember new settings. */
5456 XSETINT (bar
->left
, sb_left
);
5457 XSETINT (bar
->top
, top
);
5458 XSETINT (bar
->width
, sb_width
);
5459 XSETINT (bar
->height
, height
);
5464 #ifdef USE_TOOLKIT_SCROLL_BARS
5465 bar
->fringe_extended_p
= fringe_extended_p
? Qt
: Qnil
;
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
= SCROLL_BAR_X_WINDOW (bar
);
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
, XINT (bar
->start
), XINT (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 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
5629 XINT (bar
->height
) - 1);
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
, XINT (bar
->height
));
5676 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
5677 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5680 if (y
> top_range
) y
= top_range
;
5682 if (y
< XINT (bar
->start
))
5683 emacs_event
->part
= scroll_bar_above_handle
;
5684 else if (y
< XINT (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
- XINT (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
+ (XINT (bar
->end
) - XINT (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
!= XINT (bar
->start
))
5756 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (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
= SCROLL_BAR_X_WINDOW (bar
);
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
, XINT (bar
->height
));
5807 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (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
< XINT (bar
->start
))
5825 *part
= scroll_bar_above_handle
;
5826 else if (win_y
< XINT (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 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
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 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6216 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6217 *finish
= X_EVENT_DROP
;
6221 case SelectionNotify
:
6222 last_user_time
= event
.xselection
.time
;
6223 #ifdef USE_X_TOOLKIT
6224 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6226 #endif /* not USE_X_TOOLKIT */
6227 x_handle_selection_notify (&event
.xselection
);
6230 case SelectionClear
: /* Someone has grabbed ownership. */
6231 last_user_time
= event
.xselectionclear
.time
;
6232 #ifdef USE_X_TOOLKIT
6233 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6235 #endif /* USE_X_TOOLKIT */
6237 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
6239 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6240 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6241 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6242 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6243 inev
.ie
.frame_or_window
= Qnil
;
6247 case SelectionRequest
: /* Someone wants our selection. */
6248 last_user_time
= event
.xselectionrequest
.time
;
6249 #ifdef USE_X_TOOLKIT
6250 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6252 #endif /* USE_X_TOOLKIT */
6254 XSelectionRequestEvent
*eventp
6255 = (XSelectionRequestEvent
*) &event
;
6257 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6258 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6259 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6260 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6261 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6262 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6263 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6264 inev
.ie
.frame_or_window
= Qnil
;
6268 case PropertyNotify
:
6269 last_user_time
= event
.xproperty
.time
;
6270 #if 0 /* This is plain wrong. In the case that we are waiting for a
6271 PropertyNotify used as an ACK in incremental selection
6272 transfer, the property will be on the receiver's window. */
6273 #if defined USE_X_TOOLKIT
6274 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
6278 x_handle_property_notify (&event
.xproperty
);
6281 case ReparentNotify
:
6282 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6286 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6287 x_real_positions (f
, &x
, &y
);
6291 /* Perhaps reparented due to a WM restart. Reset this. */
6292 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6293 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
6298 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6301 x_check_fullscreen (f
);
6304 /* This seems to be needed for GTK 2.6. */
6305 x_clear_area (event
.xexpose
.display
,
6306 event
.xexpose
.window
,
6307 event
.xexpose
.x
, event
.xexpose
.y
,
6308 event
.xexpose
.width
, event
.xexpose
.height
,
6311 if (f
->async_visible
== 0)
6313 f
->async_visible
= 1;
6314 f
->async_iconified
= 0;
6315 f
->output_data
.x
->has_been_visible
= 1;
6316 SET_FRAME_GARBAGED (f
);
6320 event
.xexpose
.x
, event
.xexpose
.y
,
6321 event
.xexpose
.width
, event
.xexpose
.height
);
6325 #ifndef USE_TOOLKIT_SCROLL_BARS
6326 struct scroll_bar
*bar
;
6328 #if defined USE_LUCID
6329 /* Submenus of the Lucid menu bar aren't widgets
6330 themselves, so there's no way to dispatch events
6331 to them. Recognize this case separately. */
6334 = x_window_to_menu_bar (event
.xexpose
.window
);
6336 xlwmenu_redisplay (widget
);
6338 #endif /* USE_LUCID */
6340 #ifdef USE_TOOLKIT_SCROLL_BARS
6341 /* Dispatch event to the widget. */
6343 #else /* not USE_TOOLKIT_SCROLL_BARS */
6344 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6345 event
.xexpose
.window
);
6348 x_scroll_bar_expose (bar
, &event
);
6349 #ifdef USE_X_TOOLKIT
6352 #endif /* USE_X_TOOLKIT */
6353 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6357 case GraphicsExpose
: /* This occurs when an XCopyArea's
6358 source area was obscured or not
6360 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6364 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6365 event
.xgraphicsexpose
.width
,
6366 event
.xgraphicsexpose
.height
);
6368 #ifdef USE_X_TOOLKIT
6371 #endif /* USE_X_TOOLKIT */
6374 case NoExpose
: /* This occurs when an XCopyArea's
6375 source area was completely
6380 /* Redo the mouse-highlight after the tooltip has gone. */
6381 if (event
.xmap
.window
== tip_window
)
6384 redo_mouse_highlight ();
6387 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6388 if (f
) /* F may no longer exist if
6389 the frame was deleted. */
6391 /* While a frame is unmapped, display generation is
6392 disabled; you don't want to spend time updating a
6393 display that won't ever be seen. */
6394 f
->async_visible
= 0;
6395 /* We can't distinguish, from the event, whether the window
6396 has become iconified or invisible. So assume, if it
6397 was previously visible, than now it is iconified.
6398 But x_make_frame_invisible clears both
6399 the visible flag and the iconified flag;
6400 and that way, we know the window is not iconified now. */
6401 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6403 f
->async_iconified
= 1;
6405 inev
.ie
.kind
= ICONIFY_EVENT
;
6406 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6412 if (event
.xmap
.window
== tip_window
)
6413 /* The tooltip has been drawn already. Avoid
6414 the SET_FRAME_GARBAGED below. */
6417 /* We use x_top_window_to_frame because map events can
6418 come for sub-windows and they don't mean that the
6419 frame is visible. */
6420 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6423 /* wait_reading_process_output will notice this and update
6424 the frame's display structures.
6425 If we where iconified, we should not set garbaged,
6426 because that stops redrawing on Expose events. This looks
6427 bad if we are called from a recursive event loop
6428 (x_dispatch_event), for example when a dialog is up. */
6429 if (! f
->async_iconified
)
6430 SET_FRAME_GARBAGED (f
);
6432 f
->async_visible
= 1;
6433 f
->async_iconified
= 0;
6434 f
->output_data
.x
->has_been_visible
= 1;
6438 inev
.ie
.kind
= DEICONIFY_EVENT
;
6439 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6441 else if (! NILP (Vframe_list
)
6442 && ! NILP (XCDR (Vframe_list
)))
6443 /* Force a redisplay sooner or later
6444 to update the frame titles
6445 in case this is the second frame. */
6446 record_asynch_buffer_change ();
6452 last_user_time
= event
.xkey
.time
;
6453 ignore_next_mouse_click_timeout
= 0;
6455 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6456 /* Dispatch KeyPress events when in menu. */
6457 if (popup_activated ())
6461 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6463 /* If mouse-highlight is an integer, input clears out
6464 mouse highlighting. */
6465 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6467 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6469 clear_mouse_face (dpyinfo
);
6470 dpyinfo
->mouse_face_hidden
= 1;
6473 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6476 /* Scroll bars consume key events, but we want
6477 the keys to go to the scroll bar's frame. */
6478 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6480 if (widget
&& XmIsScrollBar (widget
))
6482 widget
= XtParent (widget
);
6483 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6486 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6490 KeySym keysym
, orig_keysym
;
6491 /* al%imercury@uunet.uu.net says that making this 81
6492 instead of 80 fixed a bug whereby meta chars made
6495 It seems that some version of XmbLookupString has
6496 a bug of not returning XBufferOverflow in
6497 status_return even if the input is too long to
6498 fit in 81 bytes. So, we must prepare sufficient
6499 bytes for copy_buffer. 513 bytes (256 chars for
6500 two-byte character set) seems to be a fairly good
6501 approximation. -- 2000.8.10 handa@etl.go.jp */
6502 unsigned char copy_buffer
[513];
6503 unsigned char *copy_bufptr
= copy_buffer
;
6504 int copy_bufsiz
= sizeof (copy_buffer
);
6506 Lisp_Object coding_system
= Qlatin_1
;
6510 /* Don't pass keys to GTK. A Tab will shift focus to the
6511 tool bar in GTK 2.4. Keys will still go to menus and
6512 dialogs because in that case popup_activated is TRUE
6514 *finish
= X_EVENT_DROP
;
6518 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6519 extra_keyboard_modifiers
);
6520 modifiers
= event
.xkey
.state
;
6522 /* This will have to go some day... */
6524 /* make_lispy_event turns chars into control chars.
6525 Don't do it here because XLookupString is too eager. */
6526 event
.xkey
.state
&= ~ControlMask
;
6527 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6528 | dpyinfo
->super_mod_mask
6529 | dpyinfo
->hyper_mod_mask
6530 | dpyinfo
->alt_mod_mask
);
6532 /* In case Meta is ComposeCharacter,
6533 clear its status. According to Markus Ehrnsperger
6534 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6535 this enables ComposeCharacter to work whether or
6536 not it is combined with Meta. */
6537 if (modifiers
& dpyinfo
->meta_mod_mask
)
6538 bzero (&compose_status
, sizeof (compose_status
));
6543 Status status_return
;
6545 coding_system
= Vlocale_coding_system
;
6546 nbytes
= XmbLookupString (FRAME_XIC (f
),
6547 &event
.xkey
, copy_bufptr
,
6548 copy_bufsiz
, &keysym
,
6550 if (status_return
== XBufferOverflow
)
6552 copy_bufsiz
= nbytes
+ 1;
6553 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6554 nbytes
= XmbLookupString (FRAME_XIC (f
),
6555 &event
.xkey
, copy_bufptr
,
6556 copy_bufsiz
, &keysym
,
6559 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6560 #if 0 && defined X_HAVE_UTF8_STRING
6561 else if (status_return
== XLookupKeySym
)
6562 { /* Try again but with utf-8. */
6563 coding_system
= Qutf_8
;
6564 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6565 &event
.xkey
, copy_bufptr
,
6566 copy_bufsiz
, &keysym
,
6568 if (status_return
== XBufferOverflow
)
6570 copy_bufsiz
= nbytes
+ 1;
6571 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6572 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6575 copy_bufsiz
, &keysym
,
6581 if (status_return
== XLookupNone
)
6583 else if (status_return
== XLookupChars
)
6588 else if (status_return
!= XLookupKeySym
6589 && status_return
!= XLookupBoth
)
6593 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6594 copy_bufsiz
, &keysym
,
6597 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6598 copy_bufsiz
, &keysym
,
6602 /* If not using XIM/XIC, and a compose sequence is in progress,
6603 we break here. Otherwise, chars_matched is always 0. */
6604 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6607 bzero (&compose_status
, sizeof (compose_status
));
6608 orig_keysym
= keysym
;
6610 /* Common for all keysym input events. */
6611 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6613 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6614 inev
.ie
.timestamp
= event
.xkey
.time
;
6616 /* First deal with keysyms which have defined
6617 translations to characters. */
6618 if (keysym
>= 32 && keysym
< 128)
6619 /* Avoid explicitly decoding each ASCII character. */
6621 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6622 inev
.ie
.code
= keysym
;
6626 /* Keysyms directly mapped to Unicode characters. */
6627 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6629 if (keysym
< 0x01000080)
6630 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6632 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6633 inev
.ie
.code
= keysym
& 0xFFFFFF;
6637 /* Now non-ASCII. */
6638 if (HASH_TABLE_P (Vx_keysym_table
)
6639 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6643 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6644 ? ASCII_KEYSTROKE_EVENT
6645 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6646 inev
.ie
.code
= XFASTINT (c
);
6650 /* Random non-modifier sorts of keysyms. */
6651 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6652 || keysym
== XK_Delete
6653 #ifdef XK_ISO_Left_Tab
6654 || (keysym
>= XK_ISO_Left_Tab
6655 && keysym
<= XK_ISO_Enter
)
6657 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6658 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6660 /* This recognizes the "extended function
6661 keys". It seems there's no cleaner way.
6662 Test IsModifierKey to avoid handling
6663 mode_switch incorrectly. */
6664 || ((unsigned) (keysym
) >= XK_Select
6665 && (unsigned)(keysym
) < XK_KP_Space
)
6667 #ifdef XK_dead_circumflex
6668 || orig_keysym
== XK_dead_circumflex
6670 #ifdef XK_dead_grave
6671 || orig_keysym
== XK_dead_grave
6673 #ifdef XK_dead_tilde
6674 || orig_keysym
== XK_dead_tilde
6676 #ifdef XK_dead_diaeresis
6677 || orig_keysym
== XK_dead_diaeresis
6679 #ifdef XK_dead_macron
6680 || orig_keysym
== XK_dead_macron
6682 #ifdef XK_dead_degree
6683 || orig_keysym
== XK_dead_degree
6685 #ifdef XK_dead_acute
6686 || orig_keysym
== XK_dead_acute
6688 #ifdef XK_dead_cedilla
6689 || orig_keysym
== XK_dead_cedilla
6691 #ifdef XK_dead_breve
6692 || orig_keysym
== XK_dead_breve
6694 #ifdef XK_dead_ogonek
6695 || orig_keysym
== XK_dead_ogonek
6697 #ifdef XK_dead_caron
6698 || orig_keysym
== XK_dead_caron
6700 #ifdef XK_dead_doubleacute
6701 || orig_keysym
== XK_dead_doubleacute
6703 #ifdef XK_dead_abovedot
6704 || orig_keysym
== XK_dead_abovedot
6706 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6707 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6708 /* Any "vendor-specific" key is ok. */
6709 || (orig_keysym
& (1 << 28))
6710 || (keysym
!= NoSymbol
&& nbytes
== 0))
6711 && ! (IsModifierKey (orig_keysym
)
6713 #ifdef XK_Mode_switch
6714 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
6717 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
6719 #endif /* not HAVE_X11R5 */
6720 /* The symbols from XK_ISO_Lock
6721 to XK_ISO_Last_Group_Lock
6722 don't have real modifiers but
6723 should be treated similarly to
6724 Mode_switch by Emacs. */
6725 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6726 || ((unsigned)(orig_keysym
)
6728 && (unsigned)(orig_keysym
)
6729 <= XK_ISO_Last_Group_Lock
)
6733 STORE_KEYSYM_FOR_DEBUG (keysym
);
6734 /* make_lispy_event will convert this to a symbolic
6736 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6737 inev
.ie
.code
= keysym
;
6741 { /* Raw bytes, not keysym. */
6746 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6748 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6750 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6753 if (nchars
< nbytes
)
6755 /* Decode the input data. */
6759 /* The input should be decoded with `coding_system'
6760 which depends on which X*LookupString function
6761 we used just above and the locale. */
6762 setup_coding_system (coding_system
, &coding
);
6763 coding
.src_multibyte
= 0;
6764 coding
.dst_multibyte
= 1;
6765 /* The input is converted to events, thus we can't
6766 handle composition. Anyway, there's no XIM that
6767 gives us composition information. */
6768 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6770 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6771 coding
.destination
= alloca (require
);
6772 coding
.dst_bytes
= require
;
6773 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6774 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6775 nbytes
= coding
.produced
;
6776 nchars
= coding
.produced_char
;
6777 copy_bufptr
= coding
.destination
;
6780 /* Convert the input data to a sequence of
6781 character events. */
6782 for (i
= 0; i
< nbytes
; i
+= len
)
6784 if (nchars
== nbytes
)
6785 c
= copy_bufptr
[i
], len
= 1;
6787 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6789 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6790 ? ASCII_KEYSTROKE_EVENT
6791 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6793 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6796 /* Previous code updated count by nchars rather than nbytes,
6797 but that seems bogus to me. ++kfs */
6800 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6802 if (keysym
== NoSymbol
)
6808 /* Don't dispatch this event since XtDispatchEvent calls
6809 XFilterEvent, and two calls in a row may freeze the
6817 last_user_time
= event
.xkey
.time
;
6819 /* Don't dispatch this event since XtDispatchEvent calls
6820 XFilterEvent, and two calls in a row may freeze the
6828 last_user_time
= event
.xcrossing
.time
;
6829 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6831 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6833 if (f
&& x_mouse_click_focus_ignore_position
)
6834 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6837 if (event
.xcrossing
.focus
)
6839 /* Avoid nasty pop/raise loops. */
6840 if (f
&& (!(f
->auto_raise
)
6842 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6844 x_new_focus_frame (dpyinfo
, f
);
6845 enter_timestamp
= event
.xcrossing
.time
;
6848 else if (f
== dpyinfo
->x_focus_frame
)
6849 x_new_focus_frame (dpyinfo
, 0);
6852 /* EnterNotify counts as mouse movement,
6853 so update things that depend on mouse position. */
6854 if (f
&& !f
->output_data
.x
->hourglass_p
)
6855 note_mouse_movement (f
, &event
.xmotion
);
6857 /* We may get an EnterNotify on the buttons in the toolbar. In that
6858 case we moved out of any highlighted area and need to note this. */
6859 if (!f
&& last_mouse_glyph_frame
)
6860 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6865 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6869 last_user_time
= event
.xcrossing
.time
;
6870 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6872 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6875 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6877 /* If we move outside the frame, then we're
6878 certainly no longer on any text in the frame. */
6879 clear_mouse_face (dpyinfo
);
6880 dpyinfo
->mouse_face_mouse_frame
= 0;
6883 /* Generate a nil HELP_EVENT to cancel a help-echo.
6884 Do it only if there's something to cancel.
6885 Otherwise, the startup message is cleared when
6886 the mouse leaves the frame. */
6887 if (any_help_event_p
)
6891 /* See comment in EnterNotify above */
6892 else if (last_mouse_glyph_frame
)
6893 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6898 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6903 last_user_time
= event
.xmotion
.time
;
6904 previous_help_echo_string
= help_echo_string
;
6905 help_echo_string
= Qnil
;
6907 if (dpyinfo
->grabbed
&& last_mouse_frame
6908 && FRAME_LIVE_P (last_mouse_frame
))
6909 f
= last_mouse_frame
;
6911 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6913 if (dpyinfo
->mouse_face_hidden
)
6915 dpyinfo
->mouse_face_hidden
= 0;
6916 clear_mouse_face (dpyinfo
);
6922 /* Generate SELECT_WINDOW_EVENTs when needed. */
6923 if (!NILP (Vmouse_autoselect_window
))
6927 window
= window_from_coordinates (f
,
6928 event
.xmotion
.x
, event
.xmotion
.y
,
6931 /* Window will be selected only when it is not selected now and
6932 last mouse movement event was not in it. Minibuffer window
6933 will be selected only when it is active. */
6934 if (WINDOWP (window
)
6935 && !EQ (window
, last_window
)
6936 && !EQ (window
, selected_window
)
6937 /* For click-to-focus window managers
6938 create event iff we don't leave the
6940 && (focus_follows_mouse
6941 || (EQ (XWINDOW (window
)->frame
,
6942 XWINDOW (selected_window
)->frame
))))
6944 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6945 inev
.ie
.frame_or_window
= window
;
6950 if (!note_mouse_movement (f
, &event
.xmotion
))
6951 help_echo_string
= previous_help_echo_string
;
6955 #ifndef USE_TOOLKIT_SCROLL_BARS
6956 struct scroll_bar
*bar
6957 = x_window_to_scroll_bar (event
.xmotion
.display
,
6958 event
.xmotion
.window
);
6961 x_scroll_bar_note_movement (bar
, &event
);
6962 #endif /* USE_TOOLKIT_SCROLL_BARS */
6964 /* If we move outside the frame, then we're
6965 certainly no longer on any text in the frame. */
6966 clear_mouse_face (dpyinfo
);
6969 /* If the contents of the global variable help_echo_string
6970 has changed, generate a HELP_EVENT. */
6971 if (!NILP (help_echo_string
)
6972 || !NILP (previous_help_echo_string
))
6977 case ConfigureNotify
:
6978 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6981 #ifndef USE_X_TOOLKIT
6983 xg_resize_widgets (f
, event
.xconfigure
.width
,
6984 event
.xconfigure
.height
);
6985 #else /* not USE_GTK */
6986 /* If there is a pending resize for fullscreen, don't
6987 do this one, the right one will come later.
6988 The toolkit version doesn't seem to need this, but we
6989 need to reset it below. */
6991 = ((f
->want_fullscreen
& FULLSCREEN_WAIT
)
6992 && f
->new_text_cols
!= 0);
6993 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6994 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6999 /* In the toolkit version, change_frame_size
7000 is called by the code that handles resizing
7001 of the EmacsFrame widget. */
7003 /* Even if the number of character rows and columns has
7004 not changed, the font size may have changed, so we need
7005 to check the pixel dimensions as well. */
7006 if (columns
!= FRAME_COLS (f
)
7007 || rows
!= FRAME_LINES (f
)
7008 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
7009 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
7011 change_frame_size (f
, rows
, columns
, 0, 1, 0);
7012 SET_FRAME_GARBAGED (f
);
7013 cancel_mouse_face (f
);
7015 #endif /* not USE_GTK */
7018 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
7019 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
7022 /* GTK creates windows but doesn't map them.
7023 Only get real positions and check fullscreen when mapped. */
7024 if (FRAME_GTK_OUTER_WIDGET (f
)
7025 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
7028 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
7030 if (f
->want_fullscreen
& FULLSCREEN_WAIT
)
7031 f
->want_fullscreen
&= ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
7035 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
7036 xic_set_statusarea (f
);
7039 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
7041 /* Since the WM decorations come below top_pos now,
7042 we must put them below top_pos in the future. */
7043 f
->win_gravity
= NorthWestGravity
;
7044 x_wm_set_size_hint (f
, (long) 0, 0);
7052 /* If we decide we want to generate an event to be seen
7053 by the rest of Emacs, we put it here. */
7056 bzero (&compose_status
, sizeof (compose_status
));
7057 last_mouse_glyph_frame
= 0;
7058 last_user_time
= event
.xbutton
.time
;
7060 if (dpyinfo
->grabbed
7062 && FRAME_LIVE_P (last_mouse_frame
))
7063 f
= last_mouse_frame
;
7065 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
7069 /* Is this in the tool-bar? */
7070 if (WINDOWP (f
->tool_bar_window
)
7071 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
7074 int x
= event
.xbutton
.x
;
7075 int y
= event
.xbutton
.y
;
7077 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
7078 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
7080 if (tool_bar_p
&& event
.xbutton
.button
< 4)
7082 if (event
.xbutton
.type
== ButtonPress
)
7083 handle_tool_bar_click (f
, x
, y
, 1, 0);
7085 handle_tool_bar_click (f
, x
, y
, 0,
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
);
7113 struct scroll_bar
*bar
7114 = x_window_to_scroll_bar (event
.xbutton
.display
,
7115 event
.xbutton
.window
);
7117 #ifdef USE_TOOLKIT_SCROLL_BARS
7118 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
7120 if (bar
&& event
.xbutton
.state
& ControlMask
)
7122 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
7123 *finish
= X_EVENT_DROP
;
7125 #else /* not USE_TOOLKIT_SCROLL_BARS */
7127 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
7128 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7131 if (event
.type
== ButtonPress
)
7133 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
7134 last_mouse_frame
= f
;
7137 last_tool_bar_item
= -1;
7140 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
7142 /* Ignore any mouse motion that happened before this event;
7143 any subsequent mouse-movement Emacs events should reflect
7144 only motion after the ButtonPress/Release. */
7148 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7149 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
7150 /* For a down-event in the menu bar,
7151 don't pass it to Xt right now.
7152 Instead, save it away
7153 and we will pass it to Xt from kbd_buffer_get_event.
7154 That way, we can run some Lisp code first. */
7157 ! popup_activated ()
7160 f
&& event
.type
== ButtonPress
7161 /* Verify the event is really within the menu bar
7162 and not just sent to it due to grabbing. */
7163 && event
.xbutton
.x
>= 0
7164 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
7165 && event
.xbutton
.y
>= 0
7166 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
7167 && event
.xbutton
.same_screen
)
7169 SET_SAVED_BUTTON_EVENT
;
7170 XSETFRAME (last_mouse_press_frame
, f
);
7172 *finish
= X_EVENT_DROP
;
7175 else if (event
.type
== ButtonPress
)
7177 last_mouse_press_frame
= Qnil
;
7181 #ifdef USE_MOTIF /* This should do not harm for Lucid,
7182 but I am trying to be cautious. */
7183 else if (event
.type
== ButtonRelease
)
7185 if (!NILP (last_mouse_press_frame
))
7187 f
= XFRAME (last_mouse_press_frame
);
7188 if (f
->output_data
.x
)
7189 SET_SAVED_BUTTON_EVENT
;
7194 #endif /* USE_MOTIF */
7197 #endif /* USE_X_TOOLKIT || USE_GTK */
7201 case CirculateNotify
:
7204 case CirculateRequest
:
7207 case VisibilityNotify
:
7211 /* Someone has changed the keyboard mapping - update the
7213 switch (event
.xmapping
.request
)
7215 case MappingModifier
:
7216 x_find_modifier_meanings (dpyinfo
);
7217 /* This is meant to fall through. */
7218 case MappingKeyboard
:
7219 XRefreshKeyboardMapping (&event
.xmapping
);
7225 #ifdef USE_X_TOOLKIT
7227 if (*finish
!= X_EVENT_DROP
)
7228 XtDispatchEvent (&event
);
7230 #endif /* USE_X_TOOLKIT */
7235 if (inev
.ie
.kind
!= NO_EVENT
)
7237 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7242 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7247 XSETFRAME (frame
, f
);
7253 any_help_event_p
= 1;
7254 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7255 help_echo_object
, help_echo_pos
);
7259 help_echo_string
= Qnil
;
7260 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7270 /* Handles the XEvent EVENT on display DISPLAY.
7271 This is used for event loops outside the normal event handling,
7272 i.e. looping while a popup menu or a dialog is posted.
7274 Returns the value handle_one_xevent sets in the finish argument. */
7276 x_dispatch_event (event
, display
)
7280 struct x_display_info
*dpyinfo
;
7281 int finish
= X_EVENT_NORMAL
;
7283 dpyinfo
= x_display_info_for_display (display
);
7286 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7292 /* Read events coming from the X server.
7293 This routine is called by the SIGIO handler.
7294 We return as soon as there are no more events to be read.
7296 We return the number of characters stored into the buffer,
7297 thus pretending to be `read'.
7299 EXPECTED is nonzero if the caller knows input is available. */
7302 XTread_socket (terminal
, expected
, hold_quit
)
7303 struct terminal
*terminal
;
7305 struct input_event
*hold_quit
;
7309 int event_found
= 0;
7310 struct x_display_info
*dpyinfo
;
7312 if (interrupt_input_blocked
)
7314 interrupt_input_pending
= 1;
7318 interrupt_input_pending
= 0;
7321 /* So people can tell when we have read the available input. */
7322 input_signal_count
++;
7327 /* Only check session manager input for the primary display. */
7328 if (terminal
->id
== 1 && x_session_have_connection ())
7330 struct input_event inev
;
7332 /* We don't need to EVENT_INIT (inev) here, as
7333 x_session_check_input copies an entire input_event. */
7334 if (x_session_check_input (&inev
))
7336 kbd_buffer_store_event_hold (&inev
, hold_quit
);
7343 /* For debugging, this gives a way to fake an I/O error. */
7344 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7346 XTread_socket_fake_io_error
= 0;
7347 x_io_error_quitter (dpyinfo
->display
);
7350 #if 0 /* This loop is a noop now. */
7351 /* Find the display we are supposed to read input for.
7352 It's the one communicating on descriptor SD. */
7353 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7355 #if 0 /* This ought to be unnecessary; let's verify it. */
7357 /* If available, Xlib uses FIOSNBIO to make the socket
7358 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
7359 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
7360 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
7361 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
7362 #endif /* ! defined (FIOSNBIO) */
7365 #if 0 /* This code can't be made to work, with multiple displays,
7366 and appears not to be used on any system any more.
7367 Also keyboard.c doesn't turn O_NDELAY on and off
7368 for X connections. */
7371 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7373 extern int read_alarm_should_throw
;
7374 read_alarm_should_throw
= 1;
7375 XPeekEvent (dpyinfo
->display
, &event
);
7376 read_alarm_should_throw
= 0;
7378 #endif /* HAVE_SELECT */
7385 while (XPending (terminal
->display_info
.x
->display
))
7389 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7392 /* Filter events for the current X input method. */
7393 if (x_filter_event (terminal
->display_info
.x
, &event
))
7398 count
+= handle_one_xevent (terminal
->display_info
.x
,
7399 &event
, &finish
, hold_quit
);
7401 if (finish
== X_EVENT_GOTO_OUT
)
7407 /* For GTK we must use the GTK event loop. But XEvents gets passed
7408 to our filter function above, and then to the big event switch.
7409 We use a bunch of globals to communicate with our filter function,
7410 that is kind of ugly, but it works.
7412 There is no way to do one display at the time, GTK just does events
7413 from all displays. */
7415 while (gtk_events_pending ())
7417 current_count
= count
;
7418 current_hold_quit
= hold_quit
;
7420 gtk_main_iteration ();
7422 count
= current_count
;
7424 current_hold_quit
= 0;
7426 if (current_finish
== X_EVENT_GOTO_OUT
)
7429 #endif /* USE_GTK */
7433 /* On some systems, an X bug causes Emacs to get no more events
7434 when the window is destroyed. Detect that. (1994.) */
7437 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7438 One XNOOP in 100 loops will make Emacs terminate.
7439 B. Bretthauer, 1994 */
7441 if (x_noop_count
>= 100)
7445 if (next_noop_dpyinfo
== 0)
7446 next_noop_dpyinfo
= x_display_list
;
7448 XNoOp (next_noop_dpyinfo
->display
);
7450 /* Each time we get here, cycle through the displays now open. */
7451 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7455 /* If the focus was just given to an auto-raising frame,
7457 /* ??? This ought to be able to handle more than one such frame. */
7458 if (pending_autoraise_frame
)
7460 x_raise_frame (pending_autoraise_frame
);
7461 pending_autoraise_frame
= 0;
7473 /***********************************************************************
7475 ***********************************************************************/
7477 /* Set clipping for output in glyph row ROW. W is the window in which
7478 we operate. GC is the graphics context to set clipping in.
7480 ROW may be a text row or, e.g., a mode line. Text rows must be
7481 clipped to the interior of the window dedicated to text display,
7482 mode lines must be clipped to the whole window. */
7485 x_clip_to_row (w
, row
, area
, gc
)
7487 struct glyph_row
*row
;
7491 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7492 XRectangle clip_rect
;
7493 int window_x
, window_y
, window_width
;
7495 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7497 clip_rect
.x
= window_x
;
7498 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7499 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7500 clip_rect
.width
= window_width
;
7501 clip_rect
.height
= row
->visible_height
;
7503 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7507 /* Draw a hollow box cursor on window W in glyph row ROW. */
7510 x_draw_hollow_cursor (w
, row
)
7512 struct glyph_row
*row
;
7514 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7515 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7516 Display
*dpy
= FRAME_X_DISPLAY (f
);
7519 struct glyph
*cursor_glyph
;
7522 /* Get the glyph the cursor is on. If we can't tell because
7523 the current matrix is invalid or such, give up. */
7524 cursor_glyph
= get_phys_cursor_glyph (w
);
7525 if (cursor_glyph
== NULL
)
7528 /* Compute frame-relative coordinates for phys cursor. */
7529 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7530 wd
= w
->phys_cursor_width
;
7532 /* The foreground of cursor_gc is typically the same as the normal
7533 background color, which can cause the cursor box to be invisible. */
7534 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7535 if (dpyinfo
->scratch_cursor_gc
)
7536 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7538 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7539 GCForeground
, &xgcv
);
7540 gc
= dpyinfo
->scratch_cursor_gc
;
7542 /* Set clipping, draw the rectangle, and reset clipping again. */
7543 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7544 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7545 XSetClipMask (dpy
, gc
, None
);
7549 /* Draw a bar cursor on window W in glyph row ROW.
7551 Implementation note: One would like to draw a bar cursor with an
7552 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7553 Unfortunately, I didn't find a font yet that has this property set.
7557 x_draw_bar_cursor (w
, row
, width
, kind
)
7559 struct glyph_row
*row
;
7561 enum text_cursor_kinds kind
;
7563 struct frame
*f
= XFRAME (w
->frame
);
7564 struct glyph
*cursor_glyph
;
7566 /* If cursor is out of bounds, don't draw garbage. This can happen
7567 in mini-buffer windows when switching between echo area glyphs
7569 cursor_glyph
= get_phys_cursor_glyph (w
);
7570 if (cursor_glyph
== NULL
)
7573 /* If on an image, draw like a normal cursor. That's usually better
7574 visible than drawing a bar, esp. if the image is large so that
7575 the bar might not be in the window. */
7576 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7578 struct glyph_row
*row
;
7579 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7580 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7584 Display
*dpy
= FRAME_X_DISPLAY (f
);
7585 Window window
= FRAME_X_WINDOW (f
);
7586 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7587 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7588 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7591 /* If the glyph's background equals the color we normally draw
7592 the bar cursor in, the bar cursor in its normal color is
7593 invisible. Use the glyph's foreground color instead in this
7594 case, on the assumption that the glyph's colors are chosen so
7595 that the glyph is legible. */
7596 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7597 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7599 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7600 xgcv
.graphics_exposures
= 0;
7603 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7606 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7607 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7611 width
= FRAME_CURSOR_WIDTH (f
);
7612 width
= min (cursor_glyph
->pixel_width
, width
);
7614 w
->phys_cursor_width
= width
;
7615 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7617 if (kind
== BAR_CURSOR
)
7618 XFillRectangle (dpy
, window
, gc
,
7619 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7620 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7621 width
, row
->height
);
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 row
->height
- width
),
7627 cursor_glyph
->pixel_width
,
7630 XSetClipMask (dpy
, gc
, None
);
7635 /* RIF: Define cursor CURSOR on frame F. */
7638 x_define_frame_cursor (f
, cursor
)
7642 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7646 /* RIF: Clear area on frame F. */
7649 x_clear_frame_area (f
, x
, y
, width
, height
)
7651 int x
, y
, width
, height
;
7653 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7654 x
, y
, width
, height
, False
);
7658 /* RIF: Draw cursor on window W. */
7661 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7663 struct glyph_row
*glyph_row
;
7665 int cursor_type
, cursor_width
;
7668 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7672 w
->phys_cursor_type
= cursor_type
;
7673 w
->phys_cursor_on_p
= 1;
7675 if (glyph_row
->exact_window_width_line_p
7676 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7678 glyph_row
->cursor_in_fringe_p
= 1;
7679 draw_fringe_bitmap (w
, glyph_row
, 0);
7682 switch (cursor_type
)
7684 case HOLLOW_BOX_CURSOR
:
7685 x_draw_hollow_cursor (w
, glyph_row
);
7688 case FILLED_BOX_CURSOR
:
7689 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7693 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7697 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7701 w
->phys_cursor_width
= 0;
7709 if (w
== XWINDOW (f
->selected_window
))
7710 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7711 xic_set_preeditarea (w
, x
, y
);
7716 XFlush (FRAME_X_DISPLAY (f
));
7723 /* Make the x-window of frame F use the gnu icon bitmap. */
7726 x_bitmap_icon (f
, file
)
7732 if (FRAME_X_WINDOW (f
) == 0)
7735 /* Free up our existing icon bitmap and mask if any. */
7736 if (f
->output_data
.x
->icon_bitmap
> 0)
7737 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7738 f
->output_data
.x
->icon_bitmap
= 0;
7743 /* Use gtk_window_set_icon_from_file () if available,
7744 It's not restricted to bitmaps */
7745 if (xg_set_icon (f
, file
))
7747 #endif /* USE_GTK */
7748 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7749 x_create_bitmap_mask (f
, bitmap_id
);
7753 /* Create the GNU bitmap and mask if necessary. */
7754 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7758 #if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7760 if (xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7763 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7765 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7766 #endif /* USE_GTK */
7767 #endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
7769 /* If all else fails, use the (black and white) xbm image. */
7772 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7773 gnu_xbm_width
, gnu_xbm_height
);
7777 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7778 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7782 /* The first time we create the GNU bitmap and mask,
7783 this increments the ref-count one extra time.
7784 As a result, the GNU bitmap and mask are never freed.
7785 That way, we don't have to worry about allocating it again. */
7786 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7788 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7791 x_wm_set_icon_pixmap (f
, bitmap_id
);
7792 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7798 /* Make the x-window of frame F use a rectangle with text.
7799 Use ICON_NAME as the text. */
7802 x_text_icon (f
, icon_name
)
7806 if (FRAME_X_WINDOW (f
) == 0)
7812 text
.value
= (unsigned char *) icon_name
;
7813 text
.encoding
= XA_STRING
;
7815 text
.nitems
= strlen (icon_name
);
7816 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7818 #else /* not HAVE_X11R4 */
7819 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), icon_name
);
7820 #endif /* not HAVE_X11R4 */
7822 if (f
->output_data
.x
->icon_bitmap
> 0)
7823 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7824 f
->output_data
.x
->icon_bitmap
= 0;
7825 x_wm_set_icon_pixmap (f
, 0);
7830 #define X_ERROR_MESSAGE_SIZE 200
7832 /* If non-nil, this should be a string.
7833 It means catch X errors and store the error message in this string.
7835 The reason we use a stack is that x_catch_error/x_uncatch_error can
7836 be called from a signal handler.
7839 struct x_error_message_stack
{
7840 char string
[X_ERROR_MESSAGE_SIZE
];
7842 struct x_error_message_stack
*prev
;
7844 static struct x_error_message_stack
*x_error_message
;
7846 /* An X error handler which stores the error message in
7847 *x_error_message. This is called from x_error_handler if
7848 x_catch_errors is in effect. */
7851 x_error_catcher (display
, error
)
7855 XGetErrorText (display
, error
->error_code
,
7856 x_error_message
->string
,
7857 X_ERROR_MESSAGE_SIZE
);
7860 /* Begin trapping X errors for display DPY. Actually we trap X errors
7861 for all displays, but DPY should be the display you are actually
7864 After calling this function, X protocol errors no longer cause
7865 Emacs to exit; instead, they are recorded in the string
7866 stored in *x_error_message.
7868 Calling x_check_errors signals an Emacs error if an X error has
7869 occurred since the last call to x_catch_errors or x_check_errors.
7871 Calling x_uncatch_errors resumes the normal error handling. */
7873 void x_check_errors ();
7876 x_catch_errors (dpy
)
7879 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7881 /* Make sure any errors from previous requests have been dealt with. */
7885 data
->string
[0] = 0;
7886 data
->prev
= x_error_message
;
7887 x_error_message
= data
;
7890 /* Undo the last x_catch_errors call.
7891 DPY should be the display that was passed to x_catch_errors. */
7896 struct x_error_message_stack
*tmp
;
7900 /* The display may have been closed before this function is called.
7901 Check if it is still open before calling XSync. */
7902 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7903 XSync (x_error_message
->dpy
, False
);
7905 tmp
= x_error_message
;
7906 x_error_message
= x_error_message
->prev
;
7911 /* If any X protocol errors have arrived since the last call to
7912 x_catch_errors or x_check_errors, signal an Emacs error using
7913 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7916 x_check_errors (dpy
, format
)
7920 /* Make sure to catch any errors incurred so far. */
7923 if (x_error_message
->string
[0])
7925 char string
[X_ERROR_MESSAGE_SIZE
];
7926 bcopy (x_error_message
->string
, string
, X_ERROR_MESSAGE_SIZE
);
7927 x_uncatch_errors ();
7928 error (format
, string
);
7932 /* Nonzero if we had any X protocol errors
7933 since we did x_catch_errors on DPY. */
7936 x_had_errors_p (dpy
)
7939 /* Make sure to catch any errors incurred so far. */
7942 return x_error_message
->string
[0] != 0;
7945 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7948 x_clear_errors (dpy
)
7951 x_error_message
->string
[0] = 0;
7954 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7955 * idea. --lorentey */
7956 /* Close off all unclosed x_catch_errors calls. */
7959 x_fully_uncatch_errors ()
7961 while (x_error_message
)
7962 x_uncatch_errors ();
7966 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7969 x_catching_errors ()
7971 return x_error_message
!= 0;
7975 static unsigned int x_wire_count
;
7978 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7983 /* Handle SIGPIPE, which can happen when the connection to a server
7984 simply goes away. SIGPIPE is handled by x_connection_signal.
7985 Don't need to do anything, because the write which caused the
7986 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7987 which will do the appropriate cleanup for us. */
7990 x_connection_signal (signalnum
) /* If we don't have an argument, */
7991 int signalnum
; /* some compilers complain in signal calls. */
7994 /* USG systems forget handlers when they are used;
7995 must reestablish each time */
7996 signal (signalnum
, x_connection_signal
);
8001 /************************************************************************
8003 ************************************************************************/
8005 /* Error message passed to x_connection_closed. */
8007 static char *error_msg
;
8009 /* Function installed as fatal_error_signal_hook in
8010 x_connection_closed. Print the X error message, and exit normally,
8011 instead of dumping core when XtCloseDisplay fails. */
8014 x_fatal_error_signal ()
8016 fprintf (stderr
, "%s\n", error_msg
);
8020 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
8021 the text of an error message that lead to the connection loss. */
8024 x_connection_closed (dpy
, error_message
)
8026 char *error_message
;
8028 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
8029 Lisp_Object frame
, tail
;
8030 int index
= SPECPDL_INDEX ();
8032 error_msg
= (char *) alloca (strlen (error_message
) + 1);
8033 strcpy (error_msg
, error_message
);
8034 handling_signal
= 0;
8036 /* Prevent being called recursively because of an error condition
8037 below. Otherwise, we might end up with printing ``can't find per
8038 display information'' in the recursive call instead of printing
8039 the original message here. */
8040 x_catch_errors (dpy
);
8042 /* Inhibit redisplay while frames are being deleted. */
8043 specbind (Qinhibit_redisplay
, Qt
);
8047 /* Protect display from being closed when we delete the last
8049 dpyinfo
->reference_count
++;
8050 dpyinfo
->terminal
->reference_count
++;
8053 /* First delete frames whose mini-buffers are on frames
8054 that are on the dead display. */
8055 FOR_EACH_FRAME (tail
, frame
)
8057 Lisp_Object minibuf_frame
;
8059 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
8060 if (FRAME_X_P (XFRAME (frame
))
8061 && FRAME_X_P (XFRAME (minibuf_frame
))
8062 && ! EQ (frame
, minibuf_frame
)
8063 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
8064 Fdelete_frame (frame
, Qt
);
8067 /* Now delete all remaining frames on the dead display.
8068 We are now sure none of these is used as the mini-buffer
8069 for another frame that we need to delete. */
8070 FOR_EACH_FRAME (tail
, frame
)
8071 if (FRAME_X_P (XFRAME (frame
))
8072 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
8074 /* Set this to t so that Fdelete_frame won't get confused
8075 trying to find a replacement. */
8076 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
8077 Fdelete_frame (frame
, Qt
);
8080 /* We have to close the display to inform Xt that it doesn't
8081 exist anymore. If we don't, Xt will continue to wait for
8082 events from the display. As a consequence, a sequence of
8084 M-x make-frame-on-display RET :1 RET
8085 ...kill the new frame, so that we get an IO error...
8086 M-x make-frame-on-display RET :1 RET
8088 will indefinitely wait in Xt for events for display `:1', opened
8089 in the first class to make-frame-on-display.
8091 Closing the display is reported to lead to a bus error on
8092 OpenWindows in certain situations. I suspect that is a bug
8093 in OpenWindows. I don't know how to cicumvent it here. */
8095 #ifdef USE_X_TOOLKIT
8096 /* If DPYINFO is null, this means we didn't open the display
8097 in the first place, so don't try to close it. */
8100 extern void (*fatal_error_signal_hook
) P_ ((void));
8101 fatal_error_signal_hook
= x_fatal_error_signal
;
8102 XtCloseDisplay (dpy
);
8103 fatal_error_signal_hook
= NULL
;
8109 xg_display_close (dpyinfo
->display
);
8114 /* Indicate that this display is dead. */
8115 dpyinfo
->display
= 0;
8117 dpyinfo
->reference_count
--;
8118 dpyinfo
->terminal
->reference_count
--;
8119 if (dpyinfo
->reference_count
!= 0)
8120 /* We have just closed all frames on this display. */
8123 x_delete_display (dpyinfo
);
8126 x_uncatch_errors ();
8128 if (terminal_list
== 0)
8130 fprintf (stderr
, "%s\n", error_msg
);
8131 shut_down_emacs (0, 0, Qnil
);
8135 /* Ordinary stack unwind doesn't deal with these. */
8137 sigunblock (sigmask (SIGIO
));
8139 sigunblock (sigmask (SIGALRM
));
8140 TOTALLY_UNBLOCK_INPUT
;
8142 unbind_to (index
, Qnil
);
8143 clear_waiting_for_input ();
8144 error ("%s", error_msg
);
8147 /* We specifically use it before defining it, so that gcc doesn't inline it,
8148 otherwise gdb doesn't know how to properly put a breakpoint on it. */
8149 static void x_error_quitter
P_ ((Display
*, XErrorEvent
*));
8151 /* This is the first-level handler for X protocol errors.
8152 It calls x_error_quitter or x_error_catcher. */
8155 x_error_handler (display
, error
)
8159 if (x_error_message
)
8160 x_error_catcher (display
, error
);
8162 x_error_quitter (display
, error
);
8166 /* This is the usual handler for X protocol errors.
8167 It kills all frames on the display that we got the error for.
8168 If that was the only one, it prints an error message and kills Emacs. */
8170 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
8172 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
8173 #define NO_INLINE __attribute__((noinline))
8178 /* Some versions of GNU/Linux define noinline in their headers. */
8184 /* On older GCC versions, just putting x_error_quitter
8185 after x_error_handler prevents inlining into the former. */
8187 static void NO_INLINE
8188 x_error_quitter (display
, error
)
8192 char buf
[256], buf1
[356];
8194 /* Ignore BadName errors. They can happen because of fonts
8195 or colors that are not defined. */
8197 if (error
->error_code
== BadName
)
8200 /* Note that there is no real way portable across R3/R4 to get the
8201 original error handler. */
8203 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
8204 sprintf (buf1
, "X protocol error: %s on protocol request %d",
8205 buf
, error
->request_code
);
8206 x_connection_closed (display
, buf1
);
8210 /* This is the handler for X IO errors, always.
8211 It kills all frames on the display that we lost touch with.
8212 If that was the only one, it prints an error message and kills Emacs. */
8215 x_io_error_quitter (display
)
8220 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
8221 x_connection_closed (display
, buf
);
8225 /* Changing the font of the frame. */
8227 /* Give frame F the font named FONTNAME as its default font, and
8228 return the full name of that font. FONTNAME may be a wildcard
8229 pattern; in that case, we choose some font that fits the pattern.
8230 The return value shows which font we chose. */
8233 x_new_font (f
, fontname
)
8235 register char *fontname
;
8237 struct font_info
*fontp
8238 = FS_LOAD_FONT (f
, fontname
);
8243 if (FRAME_FONT (f
) == (XFontStruct
*) (fontp
->font
))
8244 /* This font is already set in frame F. There's nothing more to
8246 return build_string (fontp
->full_name
);
8248 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
8249 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
8250 FRAME_FONTSET (f
) = -1;
8252 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
8253 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
8254 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
8256 compute_fringe_widths (f
, 1);
8258 /* Compute the scroll bar width in character columns. */
8259 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8261 int wid
= FRAME_COLUMN_WIDTH (f
);
8262 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8263 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
8267 int wid
= FRAME_COLUMN_WIDTH (f
);
8268 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8271 /* Now make the frame display the given font. */
8272 if (FRAME_X_WINDOW (f
) != 0)
8274 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
8275 FRAME_FONT (f
)->fid
);
8276 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
8277 FRAME_FONT (f
)->fid
);
8278 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
8279 FRAME_FONT (f
)->fid
);
8281 /* Don't change the size of a tip frame; there's no point in
8282 doing it because it's done in Fx_show_tip, and it leads to
8283 problems because the tip frame has no widget. */
8284 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8285 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8288 return build_string (fontp
->full_name
);
8291 /* Give frame F the fontset named FONTSETNAME as its default fontset,
8292 and return the full name of that fontset. FONTSETNAME may be a
8293 wildcard pattern; in that case, we choose some fontset that fits
8294 the pattern. FONTSETNAME may be a font name for ASCII characters;
8295 in that case, we create a fontset from that font name.
8297 The return value shows which fontset we chose.
8298 If FONTSETNAME specifies the default fontset, return Qt.
8299 If an ASCII font in the specified fontset can't be loaded, return
8303 x_new_fontset (f
, fontsetname
)
8305 Lisp_Object fontsetname
;
8307 int fontset
= fs_query_fontset (fontsetname
, 0);
8310 if (fontset
> 0 && f
->output_data
.x
->fontset
== fontset
)
8311 /* This fontset is already set in frame F. There's nothing more
8313 return fontset_name (fontset
);
8314 else if (fontset
== 0)
8315 /* The default fontset can't be the default font. */
8319 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
8321 result
= x_new_font (f
, SDATA (fontsetname
));
8323 if (!STRINGP (result
))
8324 /* Can't load ASCII font. */
8328 fontset
= new_fontset_from_font_name (result
);
8330 /* Since x_new_font doesn't update any fontset information, do it now. */
8331 FRAME_FONTSET (f
) = fontset
;
8335 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8336 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8339 return fontset_name (fontset
);
8342 #ifdef USE_FONT_BACKEND
8344 x_new_fontset2 (f
, fontset
, font_object
)
8347 Lisp_Object font_object
;
8349 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
8351 if (FRAME_FONT_OBJECT (f
) == font
)
8352 /* This font is already set in frame F. There's nothing more to
8354 return fontset_name (fontset
);
8358 FRAME_FONT_OBJECT (f
) = font
;
8359 FRAME_FONT (f
) = font
->font
.font
;
8360 FRAME_BASELINE_OFFSET (f
) = font
->font
.baseline_offset
;
8361 FRAME_FONTSET (f
) = fontset
;
8363 FRAME_COLUMN_WIDTH (f
) = font
->font
.average_width
;
8364 FRAME_SPACE_WIDTH (f
) = font
->font
.space_width
;
8365 FRAME_LINE_HEIGHT (f
) = font
->font
.height
;
8367 compute_fringe_widths (f
, 1);
8369 /* Compute the scroll bar width in character columns. */
8370 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8372 int wid
= FRAME_COLUMN_WIDTH (f
);
8373 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8374 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
- 1) / wid
;
8378 int wid
= FRAME_COLUMN_WIDTH (f
);
8379 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8382 /* Now make the frame display the given font. */
8383 if (FRAME_X_WINDOW (f
) != 0)
8385 /* Don't change the size of a tip frame; there's no point in
8386 doing it because it's done in Fx_show_tip, and it leads to
8387 problems because the tip frame has no widget. */
8388 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8389 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8394 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8395 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8400 return fontset_name (fontset
);
8402 #endif /* USE_FONT_BACKEND */
8405 /***********************************************************************
8407 ***********************************************************************/
8413 /* XIM destroy callback function, which is called whenever the
8414 connection to input method XIM dies. CLIENT_DATA contains a
8415 pointer to the x_display_info structure corresponding to XIM. */
8418 xim_destroy_callback (xim
, client_data
, call_data
)
8420 XPointer client_data
;
8423 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8424 Lisp_Object frame
, tail
;
8428 /* No need to call XDestroyIC.. */
8429 FOR_EACH_FRAME (tail
, frame
)
8431 struct frame
*f
= XFRAME (frame
);
8432 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8434 FRAME_XIC (f
) = NULL
;
8435 xic_free_xfontset (f
);
8439 /* No need to call XCloseIM. */
8440 dpyinfo
->xim
= NULL
;
8441 XFree (dpyinfo
->xim_styles
);
8445 #endif /* HAVE_X11R6 */
8448 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8449 extern char *XSetIMValues
P_ ((XIM
, ...));
8452 /* Open the connection to the XIM server on display DPYINFO.
8453 RESOURCE_NAME is the resource name Emacs uses. */
8456 xim_open_dpy (dpyinfo
, resource_name
)
8457 struct x_display_info
*dpyinfo
;
8458 char *resource_name
;
8465 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8472 XIMCallback destroy
;
8475 /* Get supported styles and XIM values. */
8476 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8479 destroy
.callback
= xim_destroy_callback
;
8480 destroy
.client_data
= (XPointer
)dpyinfo
;
8481 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8487 #endif /* HAVE_XIM */
8488 dpyinfo
->xim
= NULL
;
8492 #ifdef HAVE_X11R6_XIM
8496 struct x_display_info
*dpyinfo
;
8497 char *resource_name
;
8500 /* XIM instantiate callback function, which is called whenever an XIM
8501 server is available. DISPLAY is the display of the XIM.
8502 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8503 when the callback was registered. */
8506 xim_instantiate_callback (display
, client_data
, call_data
)
8508 XPointer client_data
;
8511 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8512 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8514 /* We don't support multiple XIM connections. */
8518 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8520 /* Create XIC for the existing frames on the same display, as long
8521 as they have no XIC. */
8522 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8524 Lisp_Object tail
, frame
;
8527 FOR_EACH_FRAME (tail
, frame
)
8529 struct frame
*f
= XFRAME (frame
);
8532 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8533 if (FRAME_XIC (f
) == NULL
)
8535 create_frame_xic (f
);
8536 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8537 xic_set_statusarea (f
);
8538 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8540 struct window
*w
= XWINDOW (f
->selected_window
);
8541 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8550 #endif /* HAVE_X11R6_XIM */
8553 /* Open a connection to the XIM server on display DPYINFO.
8554 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8555 connection only at the first time. On X11R6, open the connection
8556 in the XIM instantiate callback function. */
8559 xim_initialize (dpyinfo
, resource_name
)
8560 struct x_display_info
*dpyinfo
;
8561 char *resource_name
;
8566 #ifdef HAVE_X11R6_XIM
8567 struct xim_inst_t
*xim_inst
;
8570 dpyinfo
->xim
= NULL
;
8571 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8572 xim_inst
->dpyinfo
= dpyinfo
;
8573 len
= strlen (resource_name
);
8574 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8575 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8576 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8577 resource_name
, EMACS_CLASS
,
8578 xim_instantiate_callback
,
8579 /* This is XPointer in XFree86
8580 but (XPointer *) on Tru64, at
8581 least, hence the configure test. */
8582 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8583 #else /* not HAVE_X11R6_XIM */
8584 dpyinfo
->xim
= NULL
;
8585 xim_open_dpy (dpyinfo
, resource_name
);
8586 #endif /* not HAVE_X11R6_XIM */
8590 #endif /* HAVE_XIM */
8591 dpyinfo
->xim
= NULL
;
8595 /* Close the connection to the XIM server on display DPYINFO. */
8598 xim_close_dpy (dpyinfo
)
8599 struct x_display_info
*dpyinfo
;
8604 #ifdef HAVE_X11R6_XIM
8605 if (dpyinfo
->display
)
8606 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8608 xim_instantiate_callback
, NULL
);
8609 #endif /* not HAVE_X11R6_XIM */
8610 if (dpyinfo
->display
)
8611 XCloseIM (dpyinfo
->xim
);
8612 dpyinfo
->xim
= NULL
;
8613 XFree (dpyinfo
->xim_styles
);
8615 #endif /* HAVE_XIM */
8618 #endif /* not HAVE_X11R6_XIM */
8622 /* Calculate the absolute position in frame F
8623 from its current recorded position values and gravity. */
8626 x_calc_absolute_position (f
)
8629 int flags
= f
->size_hint_flags
;
8631 /* We have nothing to do if the current position
8632 is already for the top-left corner. */
8633 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8636 /* Treat negative positions as relative to the leftmost bottommost
8637 position that fits on the screen. */
8638 if (flags
& XNegative
)
8639 f
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
8640 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
);
8643 int height
= FRAME_PIXEL_HEIGHT (f
);
8645 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8646 /* Something is fishy here. When using Motif, starting Emacs with
8647 `-g -0-0', the frame appears too low by a few pixels.
8649 This seems to be so because initially, while Emacs is starting,
8650 the column widget's height and the frame's pixel height are
8651 different. The column widget's height is the right one. In
8652 later invocations, when Emacs is up, the frame's pixel height
8655 It's not obvious where the initial small difference comes from.
8656 2000-12-01, gerd. */
8658 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8661 if (flags
& YNegative
)
8662 f
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
- height
+ f
->top_pos
);
8665 /* The left_pos and top_pos
8666 are now relative to the top and left screen edges,
8667 so the flags should correspond. */
8668 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8671 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8672 to really change the position, and 0 when calling from
8673 x_make_frame_visible (in that case, XOFF and YOFF are the current
8674 position values). It is -1 when calling from x_set_frame_parameters,
8675 which means, do adjust for borders but don't change the gravity. */
8678 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8680 register int xoff
, yoff
;
8683 int modified_top
, modified_left
;
8685 if (change_gravity
!= 0)
8687 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8688 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8692 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8694 f
->size_hint_flags
|= XNegative
;
8696 f
->size_hint_flags
|= YNegative
;
8697 f
->win_gravity
= NorthWestGravity
;
8699 x_calc_absolute_position (f
);
8702 x_wm_set_size_hint (f
, (long) 0, 0);
8704 modified_left
= f
->left_pos
;
8705 modified_top
= f
->top_pos
;
8707 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8709 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8710 than the WM decorations. So we use the calculated offset instead
8711 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8712 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8713 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8716 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8717 modified_left
, modified_top
);
8719 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8720 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8723 /* change_gravity is non-zero when this function is called from Lisp to
8724 programmatically move a frame. In that case, we call
8725 x_check_expected_move to discover if we have a "Type A" or "Type B"
8726 window manager, and, for a "Type A" window manager, adjust the position
8729 We call x_check_expected_move if a programmatic move occurred, and
8730 either the window manager type (A/B) is unknown or it is Type A but we
8731 need to compute the top/left offset adjustment for this frame. */
8733 if (change_gravity
!= 0 &&
8734 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8735 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8736 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8737 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8738 x_check_expected_move (f
, modified_left
, modified_top
);
8743 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8744 on the root window for frame F contains ATOMNAME.
8745 This is how a WM check shall be done according to the Window Manager
8746 Specification/Extended Window Manager Hints at
8747 http://freedesktop.org/wiki/Standards_2fwm_2dspec. */
8750 wm_supports (f
, atomname
)
8752 const char *atomname
;
8755 unsigned long actual_size
, bytes_remaining
;
8756 int i
, rc
, actual_format
;
8758 Window wmcheck_window
;
8759 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8760 Window target_window
= dpyinfo
->root_window
;
8761 long max_len
= 65536;
8762 Display
*dpy
= FRAME_X_DISPLAY (f
);
8763 unsigned char *tmp_data
= NULL
;
8764 Atom target_type
= XA_WINDOW
;
8769 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8771 x_catch_errors (dpy
);
8772 rc
= XGetWindowProperty (dpy
, target_window
,
8773 prop_atom
, 0, max_len
, False
, target_type
,
8774 &actual_type
, &actual_format
, &actual_size
,
8775 &bytes_remaining
, &tmp_data
);
8777 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8779 if (tmp_data
) XFree (tmp_data
);
8780 x_uncatch_errors ();
8785 wmcheck_window
= *(Window
*) tmp_data
;
8788 /* Check if window exists. */
8789 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8791 if (x_had_errors_p (dpy
))
8793 x_uncatch_errors ();
8798 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8800 /* Window changed, reload atoms */
8801 if (dpyinfo
->net_supported_atoms
!= NULL
)
8802 XFree (dpyinfo
->net_supported_atoms
);
8803 dpyinfo
->net_supported_atoms
= NULL
;
8804 dpyinfo
->nr_net_supported_atoms
= 0;
8805 dpyinfo
->net_supported_window
= 0;
8807 target_type
= XA_ATOM
;
8808 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8810 rc
= XGetWindowProperty (dpy
, target_window
,
8811 prop_atom
, 0, max_len
, False
, target_type
,
8812 &actual_type
, &actual_format
, &actual_size
,
8813 &bytes_remaining
, &tmp_data
);
8815 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8817 if (tmp_data
) XFree (tmp_data
);
8818 x_uncatch_errors ();
8823 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8824 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8825 dpyinfo
->net_supported_window
= wmcheck_window
;
8829 want_atom
= XInternAtom (dpy
, atomname
, False
);
8831 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8832 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8834 x_uncatch_errors ();
8840 /* Do fullscreen as specified in extended window manager hints */
8843 do_ewmh_fullscreen (f
)
8846 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8848 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8849 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8851 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8856 const char *atom
= "_NET_WM_STATE";
8857 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8858 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8859 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8860 const char *what
= NULL
;
8862 XSETFRAME (frame
, f
);
8864 /* If there are _NET_ atoms we assume we have extended window manager
8866 switch (f
->want_fullscreen
)
8868 case FULLSCREEN_BOTH
:
8871 case FULLSCREEN_WIDTH
:
8874 case FULLSCREEN_HEIGHT
:
8879 if (what
!= NULL
&& !wm_supports (f
, what
)) return 0;
8882 Fx_send_client_event (frame
, make_number (0), frame
,
8883 make_unibyte_string (atom
, strlen (atom
)),
8885 Fcons (make_number (0), /* Remove */
8887 (make_unibyte_string (fs
,
8890 Fx_send_client_event (frame
, make_number (0), frame
,
8891 make_unibyte_string (atom
, strlen (atom
)),
8893 Fcons (make_number (0), /* Remove */
8895 (make_unibyte_string (fh
,
8898 Fx_send_client_event (frame
, make_number (0), frame
,
8899 make_unibyte_string (atom
, strlen (atom
)),
8901 Fcons (make_number (0), /* Remove */
8903 (make_unibyte_string (fw
,
8906 f
->want_fullscreen
= FULLSCREEN_NONE
;
8908 Fx_send_client_event (frame
, make_number (0), frame
,
8909 make_unibyte_string (atom
, strlen (atom
)),
8911 Fcons (make_number (1), /* Add */
8913 (make_unibyte_string (what
,
8918 return have_net_atom
;
8922 XTfullscreen_hook (f
)
8925 if (f
->async_visible
)
8928 do_ewmh_fullscreen (f
);
8935 /* Check if we need to resize the frame due to a fullscreen request.
8936 If so needed, resize the frame. */
8938 x_check_fullscreen (f
)
8941 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
8943 int width
, height
, ign
;
8945 if (do_ewmh_fullscreen (f
))
8948 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8950 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8952 /* We do not need to move the window, it shall be taken care of
8953 when setting WM manager hints.
8954 If the frame is visible already, the position is checked by
8955 x_check_expected_move. */
8956 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8958 change_frame_size (f
, height
, width
, 0, 1, 0);
8959 SET_FRAME_GARBAGED (f
);
8960 cancel_mouse_face (f
);
8962 /* Wait for the change of frame size to occur */
8963 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
8968 /* This function is called by x_set_offset to determine whether the window
8969 manager interfered with the positioning of the frame. Type A window
8970 managers position the surrounding window manager decorations a small
8971 amount above and left of the user-supplied position. Type B window
8972 managers position the surrounding window manager decorations at the
8973 user-specified position. If we detect a Type A window manager, we
8974 compensate by moving the window right and down by the proper amount. */
8977 x_check_expected_move (f
, expected_left
, expected_top
)
8982 int current_left
= 0, current_top
= 0;
8984 /* x_real_positions returns the left and top offsets of the outermost
8985 window manager window around the frame. */
8987 x_real_positions (f
, ¤t_left
, ¤t_top
);
8989 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8991 /* It's a "Type A" window manager. */
8996 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8997 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8998 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
9000 /* Now fix the mispositioned frame's location. */
9002 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
9003 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
9005 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9006 adjusted_left
, adjusted_top
);
9008 x_sync_with_move (f
, expected_left
, expected_top
, 0);
9011 /* It's a "Type B" window manager. We don't have to adjust the
9012 frame's position. */
9014 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
9018 /* Wait for XGetGeometry to return up-to-date position information for a
9019 recently-moved frame. Call this immediately after calling XMoveWindow.
9020 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
9021 frame has been moved to, so we use a fuzzy position comparison instead
9022 of an exact comparison. */
9025 x_sync_with_move (f
, left
, top
, fuzzy
)
9027 int left
, top
, fuzzy
;
9031 while (count
++ < 50)
9033 int current_left
= 0, current_top
= 0;
9035 /* In theory, this call to XSync only needs to happen once, but in
9036 practice, it doesn't seem to work, hence the need for the surrounding
9039 XSync (FRAME_X_DISPLAY (f
), False
);
9040 x_real_positions (f
, ¤t_left
, ¤t_top
);
9044 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
9047 if (eabs (current_left
- left
) <= 10
9048 && eabs (current_top
- top
) <= 40)
9051 else if (current_left
== left
&& current_top
== top
)
9055 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
9056 will then return up-to-date position info. */
9058 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
9062 /* Change the size of frame F's X window to COLS/ROWS in the case F
9063 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
9064 top-left-corner window gravity for this size change and subsequent
9065 size changes. Otherwise we leave the window gravity unchanged. */
9068 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
9073 int pixelwidth
, pixelheight
;
9075 check_frame_size (f
, &rows
, &cols
);
9076 f
->scroll_bar_actual_width
9077 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
9079 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
9080 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
9081 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
9083 compute_fringe_widths (f
, 0);
9085 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
9086 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
9088 f
->win_gravity
= NorthWestGravity
;
9089 x_wm_set_size_hint (f
, (long) 0, 0);
9091 XSync (FRAME_X_DISPLAY (f
), False
);
9092 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9093 pixelwidth
, pixelheight
);
9095 /* Now, strictly speaking, we can't be sure that this is accurate,
9096 but the window manager will get around to dealing with the size
9097 change request eventually, and we'll hear how it went when the
9098 ConfigureNotify event gets here.
9100 We could just not bother storing any of this information here,
9101 and let the ConfigureNotify event set everything up, but that
9102 might be kind of confusing to the Lisp code, since size changes
9103 wouldn't be reported in the frame parameters until some random
9104 point in the future when the ConfigureNotify event arrives.
9106 We pass 1 for DELAY since we can't run Lisp code inside of
9108 change_frame_size (f
, rows
, cols
, 0, 1, 0);
9109 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
9110 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
9112 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9113 receive in the ConfigureNotify event; if we get what we asked
9114 for, then the event won't cause the screen to become garbaged, so
9115 we have to make sure to do it here. */
9116 SET_FRAME_GARBAGED (f
);
9118 XFlush (FRAME_X_DISPLAY (f
));
9122 /* Call this to change the size of frame F's x-window.
9123 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
9124 for this size change and subsequent size changes.
9125 Otherwise we leave the window gravity unchanged. */
9128 x_set_window_size (f
, change_gravity
, cols
, rows
)
9136 if (FRAME_GTK_WIDGET (f
))
9137 xg_frame_set_char_size (f
, cols
, rows
);
9139 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9142 if (f
->output_data
.x
->widget
!= NULL
)
9144 /* The x and y position of the widget is clobbered by the
9145 call to XtSetValues within EmacsFrameSetCharSize.
9146 This is a real kludge, but I don't understand Xt so I can't
9147 figure out a correct fix. Can anyone else tell me? -- rms. */
9148 int xpos
= f
->output_data
.x
->widget
->core
.x
;
9149 int ypos
= f
->output_data
.x
->widget
->core
.y
;
9150 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
9151 f
->output_data
.x
->widget
->core
.x
= xpos
;
9152 f
->output_data
.x
->widget
->core
.y
= ypos
;
9155 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9157 #else /* not USE_X_TOOLKIT */
9159 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9161 #endif /* not USE_X_TOOLKIT */
9163 /* If cursor was outside the new size, mark it as off. */
9164 mark_window_cursors_off (XWINDOW (f
->root_window
));
9166 /* Clear out any recollection of where the mouse highlighting was,
9167 since it might be in a place that's outside the new frame size.
9168 Actually checking whether it is outside is a pain in the neck,
9169 so don't try--just let the highlighting be done afresh with new size. */
9170 cancel_mouse_face (f
);
9175 /* Mouse warping. */
9178 x_set_mouse_position (f
, x
, y
)
9184 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
9185 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
9187 if (pix_x
< 0) pix_x
= 0;
9188 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
9190 if (pix_y
< 0) pix_y
= 0;
9191 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
9195 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9196 0, 0, 0, 0, pix_x
, pix_y
);
9200 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
9203 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9209 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9210 0, 0, 0, 0, pix_x
, pix_y
);
9214 /* focus shifting, raising and lowering. */
9217 x_focus_on_frame (f
)
9220 #if 0 /* This proves to be unpleasant. */
9224 /* I don't think that the ICCCM allows programs to do things like this
9225 without the interaction of the window manager. Whatever you end up
9226 doing with this code, do it to x_unfocus_frame too. */
9227 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9228 RevertToPointerRoot
, CurrentTime
);
9237 /* Look at the remarks in x_focus_on_frame. */
9238 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
9239 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
9240 RevertToPointerRoot
, CurrentTime
);
9244 /* Raise frame F. */
9251 if (f
->async_visible
)
9252 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9254 XFlush (FRAME_X_DISPLAY (f
));
9258 /* Lower frame F. */
9264 if (f
->async_visible
)
9267 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9268 XFlush (FRAME_X_DISPLAY (f
));
9273 /* Activate frame with Extended Window Manager Hints */
9276 x_ewmh_activate_frame (f
)
9279 /* See Window Manager Specification/Extended Window Manager Hints at
9280 http://freedesktop.org/wiki/Standards_2fwm_2dspec */
9282 const char *atom
= "_NET_ACTIVE_WINDOW";
9283 if (f
->async_visible
&& wm_supports (f
, atom
))
9286 XSETFRAME (frame
, f
);
9287 Fx_send_client_event (frame
, make_number (0), frame
,
9288 make_unibyte_string (atom
, strlen (atom
)),
9290 Fcons (make_number (1),
9291 Fcons (make_number (last_user_time
),
9297 XTframe_raise_lower (f
, raise_flag
)
9307 /* Change of visibility. */
9309 /* This tries to wait until the frame is really visible.
9310 However, if the window manager asks the user where to position
9311 the frame, this will return before the user finishes doing that.
9312 The frame will not actually be visible at that time,
9313 but it will become visible later when the window manager
9314 finishes with it. */
9317 x_make_frame_visible (f
)
9321 int original_top
, original_left
;
9322 int retry_count
= 2;
9328 type
= x_icon_type (f
);
9330 x_bitmap_icon (f
, type
);
9332 if (! FRAME_VISIBLE_P (f
))
9334 /* We test FRAME_GARBAGED_P here to make sure we don't
9335 call x_set_offset a second time
9336 if we get to x_make_frame_visible a second time
9337 before the window gets really visible. */
9338 if (! FRAME_ICONIFIED_P (f
)
9339 && ! f
->output_data
.x
->asked_for_visible
)
9340 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9342 f
->output_data
.x
->asked_for_visible
= 1;
9344 if (! EQ (Vx_no_window_manager
, Qt
))
9345 x_wm_set_window_state (f
, NormalState
);
9346 #ifdef USE_X_TOOLKIT
9347 /* This was XtPopup, but that did nothing for an iconified frame. */
9348 XtMapWidget (f
->output_data
.x
->widget
);
9349 #else /* not USE_X_TOOLKIT */
9351 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9352 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9354 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9355 #endif /* not USE_GTK */
9356 #endif /* not USE_X_TOOLKIT */
9357 #if 0 /* This seems to bring back scroll bars in the wrong places
9358 if the window configuration has changed. They seem
9359 to come back ok without this. */
9360 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9361 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9365 XFlush (FRAME_X_DISPLAY (f
));
9367 /* Synchronize to ensure Emacs knows the frame is visible
9368 before we do anything else. We do this loop with input not blocked
9369 so that incoming events are handled. */
9373 /* This must be before UNBLOCK_INPUT
9374 since events that arrive in response to the actions above
9375 will set it when they are handled. */
9376 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9378 original_left
= f
->left_pos
;
9379 original_top
= f
->top_pos
;
9381 /* This must come after we set COUNT. */
9384 /* We unblock here so that arriving X events are processed. */
9386 /* Now move the window back to where it was "supposed to be".
9387 But don't do it if the gravity is negative.
9388 When the gravity is negative, this uses a position
9389 that is 3 pixels too low. Perhaps that's really the border width.
9391 Don't do this if the window has never been visible before,
9392 because the window manager may choose the position
9393 and we don't want to override it. */
9395 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
9396 && f
->win_gravity
== NorthWestGravity
9397 && previously_visible
)
9401 unsigned int width
, height
, border
, depth
;
9405 /* On some window managers (such as FVWM) moving an existing
9406 window, even to the same place, causes the window manager
9407 to introduce an offset. This can cause the window to move
9408 to an unexpected location. Check the geometry (a little
9409 slow here) and then verify that the window is in the right
9410 place. If the window is not in the right place, move it
9411 there, and take the potential window manager hit. */
9412 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9413 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9415 if (original_left
!= x
|| original_top
!= y
)
9416 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9417 original_left
, original_top
);
9422 XSETFRAME (frame
, f
);
9424 /* Wait until the frame is visible. Process X events until a
9425 MapNotify event has been seen, or until we think we won't get a
9426 MapNotify at all.. */
9427 for (count
= input_signal_count
+ 10;
9428 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9430 /* Force processing of queued events. */
9433 /* Machines that do polling rather than SIGIO have been
9434 observed to go into a busy-wait here. So we'll fake an
9435 alarm signal to let the handler know that there's something
9436 to be read. We used to raise a real alarm, but it seems
9437 that the handler isn't always enabled here. This is
9439 if (input_polling_used ())
9441 /* It could be confusing if a real alarm arrives while
9442 processing the fake one. Turn it off and let the
9443 handler reset it. */
9444 extern void poll_for_input_1
P_ ((void));
9445 int old_poll_suppress_count
= poll_suppress_count
;
9446 poll_suppress_count
= 1;
9447 poll_for_input_1 ();
9448 poll_suppress_count
= old_poll_suppress_count
;
9451 /* See if a MapNotify event has been processed. */
9452 FRAME_SAMPLE_VISIBILITY (f
);
9457 (let ((f (selected-frame)))
9461 the frame is not raised with various window managers on
9462 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9463 unknown reason, the call to XtMapWidget is completely ignored.
9464 Mapping the widget a second time works. */
9466 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9471 /* Change from mapped state to withdrawn state. */
9473 /* Make the frame visible (mapped and not iconified). */
9476 x_make_frame_invisible (f
)
9481 /* Use the frame's outermost window, not the one we normally draw on. */
9482 window
= FRAME_OUTER_WINDOW (f
);
9484 /* Don't keep the highlight on an invisible frame. */
9485 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9486 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9488 #if 0/* This might add unreliability; I don't trust it -- rms. */
9489 if (! f
->async_visible
&& ! f
->async_iconified
)
9495 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9496 that the current position of the window is user-specified, rather than
9497 program-specified, so that when the window is mapped again, it will be
9498 placed at the same location, without forcing the user to position it
9499 by hand again (they have already done that once for this window.) */
9500 x_wm_set_size_hint (f
, (long) 0, 1);
9503 if (FRAME_GTK_OUTER_WIDGET (f
))
9504 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9510 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9511 DefaultScreen (FRAME_X_DISPLAY (f
))))
9513 UNBLOCK_INPUT_RESIGNAL
;
9514 error ("Can't notify window manager of window withdrawal");
9516 #else /* ! defined (HAVE_X11R4) */
9518 /* Tell the window manager what we're going to do. */
9519 if (! EQ (Vx_no_window_manager
, Qt
))
9523 unmap
.xunmap
.type
= UnmapNotify
;
9524 unmap
.xunmap
.window
= window
;
9525 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
9526 unmap
.xunmap
.from_configure
= False
;
9527 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9528 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9530 SubstructureRedirectMaskSubstructureNotifyMask
,
9533 UNBLOCK_INPUT_RESIGNAL
;
9534 error ("Can't notify window manager of withdrawal");
9538 /* Unmap the window ourselves. Cheeky! */
9539 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
9540 #endif /* ! defined (HAVE_X11R4) */
9543 /* We can't distinguish this from iconification
9544 just by the event that we get from the server.
9545 So we can't win using the usual strategy of letting
9546 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9547 and synchronize with the server to make sure we agree. */
9549 FRAME_ICONIFIED_P (f
) = 0;
9550 f
->async_visible
= 0;
9551 f
->async_iconified
= 0;
9558 /* Change window state from mapped to iconified. */
9567 /* Don't keep the highlight on an invisible frame. */
9568 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9569 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9571 if (f
->async_iconified
)
9576 FRAME_SAMPLE_VISIBILITY (f
);
9578 type
= x_icon_type (f
);
9580 x_bitmap_icon (f
, type
);
9583 if (FRAME_GTK_OUTER_WIDGET (f
))
9585 if (! FRAME_VISIBLE_P (f
))
9586 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9588 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9591 f
->async_iconified
= 1;
9592 f
->async_visible
= 0;
9598 #ifdef USE_X_TOOLKIT
9600 if (! FRAME_VISIBLE_P (f
))
9602 if (! EQ (Vx_no_window_manager
, Qt
))
9603 x_wm_set_window_state (f
, IconicState
);
9604 /* This was XtPopup, but that did nothing for an iconified frame. */
9605 XtMapWidget (f
->output_data
.x
->widget
);
9606 /* The server won't give us any event to indicate
9607 that an invisible frame was changed to an icon,
9608 so we have to record it here. */
9611 f
->async_iconified
= 1;
9612 f
->async_visible
= 0;
9617 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9618 XtWindow (f
->output_data
.x
->widget
),
9619 DefaultScreen (FRAME_X_DISPLAY (f
)));
9623 error ("Can't notify window manager of iconification");
9625 f
->async_iconified
= 1;
9626 f
->async_visible
= 0;
9630 XFlush (FRAME_X_DISPLAY (f
));
9632 #else /* not USE_X_TOOLKIT */
9634 /* Make sure the X server knows where the window should be positioned,
9635 in case the user deiconifies with the window manager. */
9636 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
9637 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9639 /* Since we don't know which revision of X we're running, we'll use both
9640 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9642 /* X11R4: send a ClientMessage to the window manager using the
9643 WM_CHANGE_STATE type. */
9647 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9648 message
.xclient
.type
= ClientMessage
;
9649 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9650 message
.xclient
.format
= 32;
9651 message
.xclient
.data
.l
[0] = IconicState
;
9653 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9654 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9656 SubstructureRedirectMask
| SubstructureNotifyMask
,
9659 UNBLOCK_INPUT_RESIGNAL
;
9660 error ("Can't notify window manager of iconification");
9664 /* X11R3: set the initial_state field of the window manager hints to
9666 x_wm_set_window_state (f
, IconicState
);
9668 if (!FRAME_VISIBLE_P (f
))
9670 /* If the frame was withdrawn, before, we must map it. */
9671 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9674 f
->async_iconified
= 1;
9675 f
->async_visible
= 0;
9677 XFlush (FRAME_X_DISPLAY (f
));
9679 #endif /* not USE_X_TOOLKIT */
9683 /* Free X resources of frame F. */
9686 x_free_frame_resources (f
)
9689 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9691 struct scroll_bar
*b
;
9695 /* If a display connection is dead, don't try sending more
9696 commands to the X server. */
9697 if (dpyinfo
->display
)
9699 #ifdef USE_FONT_BACKEND
9700 /* We must free faces before destroying windows because some
9701 font-driver (e.g. xft) access a window while finishing a
9703 if (enable_font_backend
9704 && FRAME_FACE_CACHE (f
))
9705 free_frame_faces (f
);
9706 #endif /* USE_FONT_BACKEND */
9708 if (f
->output_data
.x
->icon_desc
)
9709 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9711 #ifdef USE_X_TOOLKIT
9712 /* Explicitly destroy the scroll bars of the frame. Without
9713 this, we get "BadDrawable" errors from the toolkit later on,
9714 presumably from expose events generated for the disappearing
9715 toolkit scroll bars. */
9716 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9718 b
= XSCROLL_BAR (bar
);
9719 x_scroll_bar_remove (b
);
9728 #ifdef USE_X_TOOLKIT
9729 if (f
->output_data
.x
->widget
)
9731 XtDestroyWidget (f
->output_data
.x
->widget
);
9732 f
->output_data
.x
->widget
= NULL
;
9734 /* Tooltips don't have widgets, only a simple X window, even if
9735 we are using a toolkit. */
9736 else if (FRAME_X_WINDOW (f
))
9737 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9739 free_frame_menubar (f
);
9740 #else /* !USE_X_TOOLKIT */
9743 /* In the GTK version, tooltips are normal X
9744 frames. We must check and free both types. */
9745 if (FRAME_GTK_OUTER_WIDGET (f
))
9747 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9748 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9749 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9751 #endif /* USE_GTK */
9753 if (FRAME_X_WINDOW (f
))
9754 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9755 #endif /* !USE_X_TOOLKIT */
9757 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9758 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9759 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9760 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9761 unload_color (f
, f
->output_data
.x
->border_pixel
);
9762 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9764 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9765 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9766 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9767 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9768 #ifdef USE_TOOLKIT_SCROLL_BARS
9769 /* Scrollbar shadow colors. */
9770 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9771 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9772 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9773 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9774 #endif /* USE_TOOLKIT_SCROLL_BARS */
9775 if (f
->output_data
.x
->white_relief
.allocated_p
)
9776 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9777 if (f
->output_data
.x
->black_relief
.allocated_p
)
9778 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9780 if (FRAME_FACE_CACHE (f
))
9781 free_frame_faces (f
);
9784 XFlush (FRAME_X_DISPLAY (f
));
9787 if (f
->output_data
.x
->saved_menu_event
)
9788 xfree (f
->output_data
.x
->saved_menu_event
);
9790 xfree (f
->output_data
.x
);
9791 f
->output_data
.x
= NULL
;
9793 if (f
== dpyinfo
->x_focus_frame
)
9794 dpyinfo
->x_focus_frame
= 0;
9795 if (f
== dpyinfo
->x_focus_event_frame
)
9796 dpyinfo
->x_focus_event_frame
= 0;
9797 if (f
== dpyinfo
->x_highlight_frame
)
9798 dpyinfo
->x_highlight_frame
= 0;
9800 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9802 dpyinfo
->mouse_face_beg_row
9803 = dpyinfo
->mouse_face_beg_col
= -1;
9804 dpyinfo
->mouse_face_end_row
9805 = dpyinfo
->mouse_face_end_col
= -1;
9806 dpyinfo
->mouse_face_window
= Qnil
;
9807 dpyinfo
->mouse_face_deferred_gc
= 0;
9808 dpyinfo
->mouse_face_mouse_frame
= 0;
9815 /* Destroy the X window of frame F. */
9818 x_destroy_window (f
)
9821 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9823 /* If a display connection is dead, don't try sending more
9824 commands to the X server. */
9825 if (dpyinfo
->display
!= 0)
9826 x_free_frame_resources (f
);
9828 dpyinfo
->reference_count
--;
9832 /* Setting window manager hints. */
9834 /* Set the normal size hints for the window manager, for frame F.
9835 FLAGS is the flags word to use--or 0 meaning preserve the flags
9836 that the window now has.
9837 If USER_POSITION is nonzero, we set the USPosition
9838 flag (this is useful when FLAGS is 0).
9839 The GTK version is in gtkutils.c */
9843 x_wm_set_size_hint (f
, flags
, user_position
)
9848 XSizeHints size_hints
;
9850 #ifdef USE_X_TOOLKIT
9853 Dimension widget_width
, widget_height
;
9856 Window window
= FRAME_OUTER_WINDOW (f
);
9858 /* Setting PMaxSize caused various problems. */
9859 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9861 size_hints
.x
= f
->left_pos
;
9862 size_hints
.y
= f
->top_pos
;
9864 #ifdef USE_X_TOOLKIT
9865 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9866 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9867 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9868 size_hints
.height
= widget_height
;
9869 size_hints
.width
= widget_width
;
9870 #else /* not USE_X_TOOLKIT */
9871 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9872 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9873 #endif /* not USE_X_TOOLKIT */
9875 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9876 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9877 size_hints
.max_width
9878 = FRAME_X_DISPLAY_INFO (f
)->width
- FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9879 size_hints
.max_height
9880 = FRAME_X_DISPLAY_INFO (f
)->height
- FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9882 /* Calculate the base and minimum sizes.
9884 (When we use the X toolkit, we don't do it here.
9885 Instead we copy the values that the widgets are using, below.) */
9886 #ifndef USE_X_TOOLKIT
9888 int base_width
, base_height
;
9889 int min_rows
= 0, min_cols
= 0;
9891 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9892 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9894 check_frame_size (f
, &min_rows
, &min_cols
);
9896 /* The window manager uses the base width hints to calculate the
9897 current number of rows and columns in the frame while
9898 resizing; min_width and min_height aren't useful for this
9899 purpose, since they might not give the dimensions for a
9900 zero-row, zero-column frame.
9902 We use the base_width and base_height members if we have
9903 them; otherwise, we set the min_width and min_height members
9904 to the size for a zero x zero frame. */
9907 size_hints
.flags
|= PBaseSize
;
9908 size_hints
.base_width
= base_width
;
9909 size_hints
.base_height
= base_height
;
9910 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9911 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9913 size_hints
.min_width
= base_width
;
9914 size_hints
.min_height
= base_height
;
9918 /* If we don't need the old flags, we don't need the old hint at all. */
9921 size_hints
.flags
|= flags
;
9924 #endif /* not USE_X_TOOLKIT */
9927 XSizeHints hints
; /* Sometimes I hate X Windows... */
9928 long supplied_return
;
9932 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9935 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
9938 #ifdef USE_X_TOOLKIT
9939 size_hints
.base_height
= hints
.base_height
;
9940 size_hints
.base_width
= hints
.base_width
;
9941 size_hints
.min_height
= hints
.min_height
;
9942 size_hints
.min_width
= hints
.min_width
;
9946 size_hints
.flags
|= flags
;
9951 if (hints
.flags
& PSize
)
9952 size_hints
.flags
|= PSize
;
9953 if (hints
.flags
& PPosition
)
9954 size_hints
.flags
|= PPosition
;
9955 if (hints
.flags
& USPosition
)
9956 size_hints
.flags
|= USPosition
;
9957 if (hints
.flags
& USSize
)
9958 size_hints
.flags
|= USSize
;
9962 #ifndef USE_X_TOOLKIT
9967 size_hints
.win_gravity
= f
->win_gravity
;
9968 size_hints
.flags
|= PWinGravity
;
9972 size_hints
.flags
&= ~ PPosition
;
9973 size_hints
.flags
|= USPosition
;
9975 #endif /* PWinGravity */
9978 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9980 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9983 #endif /* not USE_GTK */
9985 /* Used for IconicState or NormalState */
9988 x_wm_set_window_state (f
, state
)
9992 #ifdef USE_X_TOOLKIT
9995 XtSetArg (al
[0], XtNinitialState
, state
);
9996 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9997 #else /* not USE_X_TOOLKIT */
9998 Window window
= FRAME_X_WINDOW (f
);
10000 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
10001 f
->output_data
.x
->wm_hints
.initial_state
= state
;
10003 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10004 #endif /* not USE_X_TOOLKIT */
10008 x_wm_set_icon_pixmap (f
, pixmap_id
)
10012 Pixmap icon_pixmap
, icon_mask
;
10014 #ifndef USE_X_TOOLKIT
10015 Window window
= FRAME_OUTER_WINDOW (f
);
10020 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
10021 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
10022 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
10023 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
10027 /* It seems there is no way to turn off use of an icon pixmap.
10028 The following line does it, only if no icon has yet been created,
10029 for some window managers. But with mwm it crashes.
10030 Some people say it should clear the IconPixmapHint bit in this case,
10031 but that doesn't work, and the X consortium said it isn't the
10032 right thing at all. Since there is no way to win,
10033 best to explicitly give up. */
10035 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
10036 f
->output_data
.x
->wm_hints
.icon_mask
= None
;
10045 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
10049 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
10053 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
10054 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10055 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
10056 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10059 #else /* not USE_X_TOOLKIT && not USE_GTK */
10061 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
10062 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10064 #endif /* not USE_X_TOOLKIT && not USE_GTK */
10068 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10070 int icon_x
, icon_y
;
10072 Window window
= FRAME_OUTER_WINDOW (f
);
10074 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
10075 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
10076 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
10078 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10082 /***********************************************************************
10084 ***********************************************************************/
10086 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
10089 x_get_font_info (f
, font_idx
)
10093 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
10097 /* Return a list of names of available fonts matching PATTERN on frame F.
10099 If SIZE is > 0, it is the size (maximum bounds width) of fonts
10102 SIZE < 0 means include auto scaled fonts.
10104 Frame F null means we have not yet created any frame on X, and
10105 consult the first display in x_display_list. MAXNAMES sets a limit
10106 on how many fonts to match. */
10109 x_list_fonts (f
, pattern
, size
, maxnames
)
10111 Lisp_Object pattern
;
10115 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
10116 Lisp_Object tem
, second_best
;
10117 struct x_display_info
*dpyinfo
10118 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
10119 Display
*dpy
= dpyinfo
->display
;
10120 int try_XLoadQueryFont
= 0;
10121 int allow_auto_scaled_font
= 0;
10125 allow_auto_scaled_font
= 1;
10129 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
10130 if (NILP (patterns
))
10131 patterns
= Fcons (pattern
, Qnil
);
10133 if (maxnames
== 1 && !size
)
10134 /* We can return any single font matching PATTERN. */
10135 try_XLoadQueryFont
= 1;
10137 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
10140 char **names
= NULL
;
10142 pattern
= XCAR (patterns
);
10143 /* See if we cached the result for this particular query.
10144 The cache is an alist of the form:
10145 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
10146 tem
= XCDR (dpyinfo
->name_list_element
);
10147 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
10148 allow_auto_scaled_font
? Qt
: Qnil
);
10149 list
= Fassoc (key
, tem
);
10152 list
= Fcdr_safe (list
);
10153 /* We have a cashed list. Don't have to get the list again. */
10157 /* At first, put PATTERN in the cache. */
10160 x_catch_errors (dpy
);
10162 if (try_XLoadQueryFont
)
10165 unsigned long value
;
10167 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
10168 if (x_had_errors_p (dpy
))
10170 /* This error is perhaps due to insufficient memory on X
10171 server. Let's just ignore it. */
10173 x_clear_errors (dpy
);
10177 && XGetFontProperty (font
, XA_FONT
, &value
))
10179 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
10180 int len
= strlen (name
);
10183 /* If DXPC (a Differential X Protocol Compressor)
10184 Ver.3.7 is running, XGetAtomName will return null
10185 string. We must avoid such a name. */
10187 try_XLoadQueryFont
= 0;
10191 names
= (char **) alloca (sizeof (char *));
10192 /* Some systems only allow alloca assigned to a
10194 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
10195 bcopy (name
, names
[0], len
+ 1);
10200 try_XLoadQueryFont
= 0;
10203 XFreeFont (dpy
, font
);
10206 if (!try_XLoadQueryFont
)
10208 /* We try at least 10 fonts because XListFonts will return
10209 auto-scaled fonts at the head. */
10214 for (limit
= 500;;)
10216 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
10217 if (num_fonts
== limit
)
10220 XFreeFontNames (names
);
10229 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
10232 if (x_had_errors_p (dpy
))
10234 /* This error is perhaps due to insufficient memory on X
10235 server. Let's just ignore it. */
10237 x_clear_errors (dpy
);
10241 x_uncatch_errors ();
10248 /* Make a list of all the fonts we got back.
10249 Store that in the font cache for the display. */
10250 for (i
= 0; i
< num_fonts
; i
++)
10253 char *p
= names
[i
];
10254 int average_width
= -1, resx
= 0, dashes
= 0;
10256 /* Count the number of dashes in NAMES[I]. If there are
10257 14 dashes, the field value following 9th dash
10258 (RESOLUTION_X) is nonzero, and the field value
10259 following 12th dash (AVERAGE_WIDTH) is 0, this is a
10260 auto-scaled font which is usually too ugly to be used
10261 for editing. Let's ignore it. */
10266 if (dashes
== 7) /* PIXEL_SIZE field */
10268 else if (dashes
== 9)
10270 else if (dashes
== 12) /* AVERAGE_WIDTH field */
10271 average_width
= atoi (p
);
10274 if (allow_auto_scaled_font
10275 || dashes
< 14 || average_width
!= 0 || resx
== 0)
10277 tem
= build_string (names
[i
]);
10278 if (NILP (Fassoc (tem
, list
)))
10280 if (STRINGP (Vx_pixel_size_width_font_regexp
)
10281 && ((fast_c_string_match_ignore_case
10282 (Vx_pixel_size_width_font_regexp
, names
[i
]))
10284 /* We can set the value of PIXEL_SIZE to the
10285 width of this font. */
10286 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
10288 /* For the moment, width is not known. */
10289 list
= Fcons (Fcons (tem
, Qnil
), list
);
10294 if (!try_XLoadQueryFont
)
10297 XFreeFontNames (names
);
10302 /* Now store the result in the cache. */
10303 XSETCDR (dpyinfo
->name_list_element
,
10304 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
10307 if (NILP (list
)) continue; /* Try the remaining alternatives. */
10309 newlist
= second_best
= Qnil
;
10310 /* Make a list of the fonts that have the right width. */
10311 for (; CONSP (list
); list
= XCDR (list
))
10317 if (!CONSP (tem
) || NILP (XCAR (tem
)))
10321 newlist
= Fcons (XCAR (tem
), newlist
);
10325 if (!INTEGERP (XCDR (tem
)))
10327 /* Since we have not yet known the size of this font, we
10328 must try slow function call XLoadQueryFont. */
10329 XFontStruct
*thisinfo
;
10332 x_catch_errors (dpy
);
10333 thisinfo
= XLoadQueryFont (dpy
,
10334 SDATA (XCAR (tem
)));
10335 if (x_had_errors_p (dpy
))
10337 /* This error is perhaps due to insufficient memory on X
10338 server. Let's just ignore it. */
10340 x_clear_errors (dpy
);
10342 x_uncatch_errors ();
10348 (thisinfo
->min_bounds
.width
== 0
10350 : make_number (thisinfo
->max_bounds
.width
)));
10352 XFreeFont (dpy
, thisinfo
);
10356 /* For unknown reason, the previous call of XListFont had
10357 returned a font which can't be opened. Record the size
10358 as 0 not to try to open it again. */
10359 XSETCDR (tem
, make_number (0));
10362 found_size
= XINT (XCDR (tem
));
10363 if (found_size
== size
)
10364 newlist
= Fcons (XCAR (tem
), newlist
);
10365 else if (found_size
> 0)
10367 if (NILP (second_best
))
10369 else if (found_size
< size
)
10371 if (XINT (XCDR (second_best
)) > size
10372 || XINT (XCDR (second_best
)) < found_size
)
10377 if (XINT (XCDR (second_best
)) > size
10378 && XINT (XCDR (second_best
)) > found_size
)
10383 if (!NILP (newlist
))
10385 else if (!NILP (second_best
))
10387 newlist
= Fcons (XCAR (second_best
), Qnil
);
10398 /* Check that FONT is valid on frame F. It is if it can be found in F's
10402 x_check_font (f
, font
)
10407 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10409 xassert (font
!= NULL
);
10411 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10412 if (dpyinfo
->font_table
[i
].name
10413 && font
== dpyinfo
->font_table
[i
].font
)
10416 xassert (i
< dpyinfo
->n_fonts
);
10419 #endif /* GLYPH_DEBUG != 0 */
10421 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10422 Note: There are (broken) X fonts out there with invalid XFontStruct
10423 min_bounds contents. For example, handa@etl.go.jp reports that
10424 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10425 have font->min_bounds.width == 0. */
10428 x_font_min_bounds (font
, w
, h
)
10432 *h
= FONT_HEIGHT (font
);
10433 *w
= font
->min_bounds
.width
;
10435 /* Try to handle the case where FONT->min_bounds has invalid
10436 contents. Since the only font known to have invalid min_bounds
10437 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
10439 *w
= font
->max_bounds
.width
;
10443 /* Compute the smallest character width and smallest font height over
10444 all fonts available on frame F. Set the members smallest_char_width
10445 and smallest_font_height in F's x_display_info structure to
10446 the values computed. Value is non-zero if smallest_font_height or
10447 smallest_char_width become smaller than they were before. */
10450 x_compute_min_glyph_bounds (f
)
10454 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10456 int old_width
= dpyinfo
->smallest_char_width
;
10457 int old_height
= dpyinfo
->smallest_font_height
;
10459 dpyinfo
->smallest_font_height
= 100000;
10460 dpyinfo
->smallest_char_width
= 100000;
10462 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10463 if (dpyinfo
->font_table
[i
].name
)
10465 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10468 font
= (XFontStruct
*) fontp
->font
;
10469 xassert (font
!= (XFontStruct
*) ~0);
10470 x_font_min_bounds (font
, &w
, &h
);
10472 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10473 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10476 xassert (dpyinfo
->smallest_char_width
> 0
10477 && dpyinfo
->smallest_font_height
> 0);
10479 return (dpyinfo
->n_fonts
== 1
10480 || dpyinfo
->smallest_char_width
< old_width
10481 || dpyinfo
->smallest_font_height
< old_height
);
10485 /* Load font named FONTNAME of the size SIZE for frame F, and return a
10486 pointer to the structure font_info while allocating it dynamically.
10487 If SIZE is 0, load any size of font.
10488 If loading is failed, return NULL. */
10491 x_load_font (f
, fontname
, size
)
10493 register char *fontname
;
10496 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10497 Lisp_Object font_names
;
10499 /* Get a list of all the fonts that match this name. Once we
10500 have a list of matching fonts, we compare them against the fonts
10501 we already have by comparing names. */
10502 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
10504 if (!NILP (font_names
))
10509 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10510 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
10511 if (dpyinfo
->font_table
[i
].name
10512 && (!strcmp (dpyinfo
->font_table
[i
].name
,
10513 SDATA (XCAR (tail
)))
10514 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
10515 SDATA (XCAR (tail
)))))
10516 return (dpyinfo
->font_table
+ i
);
10519 /* Load the font and add it to the table. */
10523 struct font_info
*fontp
;
10524 unsigned long value
;
10527 /* If we have found fonts by x_list_font, load one of them. If
10528 not, we still try to load a font by the name given as FONTNAME
10529 because XListFonts (called in x_list_font) of some X server has
10530 a bug of not finding a font even if the font surely exists and
10531 is loadable by XLoadQueryFont. */
10532 if (size
> 0 && !NILP (font_names
))
10533 fontname
= (char *) SDATA (XCAR (font_names
));
10536 x_catch_errors (FRAME_X_DISPLAY (f
));
10537 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
10538 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
10540 /* This error is perhaps due to insufficient memory on X
10541 server. Let's just ignore it. */
10543 x_clear_errors (FRAME_X_DISPLAY (f
));
10545 x_uncatch_errors ();
10550 /* Find a free slot in the font table. */
10551 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10552 if (dpyinfo
->font_table
[i
].name
== NULL
)
10555 /* If no free slot found, maybe enlarge the font table. */
10556 if (i
== dpyinfo
->n_fonts
10557 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
10560 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
10561 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
10562 dpyinfo
->font_table
10563 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
10566 fontp
= dpyinfo
->font_table
+ i
;
10567 if (i
== dpyinfo
->n_fonts
)
10568 ++dpyinfo
->n_fonts
;
10570 /* Now fill in the slots of *FONTP. */
10572 bzero (fontp
, sizeof (*fontp
));
10573 fontp
->font
= font
;
10574 fontp
->font_idx
= i
;
10575 fontp
->charset
= -1; /* fs_load_font sets it. */
10576 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
10577 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
10579 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
10581 /* Fixed width font. */
10582 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
10589 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
10590 pcm
= x_per_char_metric (font
, &char2b
, 0);
10592 fontp
->space_width
= pcm
->width
;
10594 fontp
->space_width
= FONT_WIDTH (font
);
10596 fontp
->average_width
10597 = (XGetFontProperty (font
, dpyinfo
->Xatom_AVERAGE_WIDTH
, &value
)
10598 ? (long) value
/ 10 : 0);
10599 if (fontp
->average_width
< 0)
10600 fontp
->average_width
= - fontp
->average_width
;
10601 if (fontp
->average_width
== 0)
10605 int width
= pcm
->width
;
10606 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
10607 if ((pcm
= x_per_char_metric (font
, &char2b
, 0)) != NULL
)
10608 width
+= pcm
->width
;
10609 fontp
->average_width
= width
/ 95;
10612 fontp
->average_width
= FONT_WIDTH (font
);
10616 /* Try to get the full name of FONT. Put it in FULL_NAME. */
10618 if (XGetFontProperty (font
, XA_FONT
, &value
))
10620 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
10624 /* Count the number of dashes in the "full name".
10625 If it is too few, this isn't really the font's full name,
10627 In X11R4, the fonts did not come with their canonical names
10638 full_name
= (char *) xmalloc (p
- name
+ 1);
10639 bcopy (name
, full_name
, p
- name
+ 1);
10645 if (full_name
!= 0)
10646 fontp
->full_name
= full_name
;
10648 fontp
->full_name
= fontp
->name
;
10650 fontp
->size
= font
->max_bounds
.width
;
10651 fontp
->height
= FONT_HEIGHT (font
);
10653 if (NILP (font_names
))
10655 /* We come here because of a bug of XListFonts mentioned at
10656 the head of this block. Let's store this information in
10657 the cache for x_list_fonts. */
10658 Lisp_Object lispy_name
= build_string (fontname
);
10659 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
10660 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
10663 XSETCDR (dpyinfo
->name_list_element
,
10665 Fcons (Fcons (lispy_full_name
,
10666 make_number (fontp
->size
)),
10668 XCDR (dpyinfo
->name_list_element
)));
10671 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
10673 XSETCDR (dpyinfo
->name_list_element
,
10675 Fcons (Fcons (lispy_full_name
,
10676 make_number (fontp
->size
)),
10678 XCDR (dpyinfo
->name_list_element
)));
10682 /* The slot `encoding' specifies how to map a character
10683 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
10684 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
10685 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
10686 2:0xA020..0xFF7F). For the moment, we don't know which charset
10687 uses this font. So, we set information in fontp->encoding_type
10688 which is never used by any charset. If mapping can't be
10689 decided, set FONT_ENCODING_NOT_DECIDED. */
10690 fontp
->encoding_type
10691 = (font
->max_byte1
== 0
10693 ? (font
->min_char_or_byte2
< 0x80
10694 ? (font
->max_char_or_byte2
< 0x80
10695 ? 0 /* 0x20..0x7F */
10696 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
10697 : 1) /* 0xA0..0xFF */
10699 : (font
->min_byte1
< 0x80
10700 ? (font
->max_byte1
< 0x80
10701 ? (font
->min_char_or_byte2
< 0x80
10702 ? (font
->max_char_or_byte2
< 0x80
10703 ? 0 /* 0x2020..0x7F7F */
10704 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
10705 : 3) /* 0x20A0..0x7FFF */
10706 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
10707 : (font
->min_char_or_byte2
< 0x80
10708 ? (font
->max_char_or_byte2
< 0x80
10709 ? 2 /* 0xA020..0xFF7F */
10710 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
10711 : 1))); /* 0xA0A0..0xFFFF */
10713 fontp
->baseline_offset
10714 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
10715 ? (long) value
: 0);
10716 fontp
->relative_compose
10717 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
10718 ? (long) value
: 0);
10719 fontp
->default_ascent
10720 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
10721 ? (long) value
: 0);
10723 /* Set global flag fonts_changed_p to non-zero if the font loaded
10724 has a character with a smaller width than any other character
10725 before, or if the font loaded has a smaller height than any
10726 other font loaded before. If this happens, it will make a
10727 glyph matrix reallocation necessary. */
10728 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
10735 /* Return a pointer to struct font_info of a font named FONTNAME for
10736 frame F. If no such font is loaded, return NULL. */
10739 x_query_font (f
, fontname
)
10741 register char *fontname
;
10743 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10746 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10747 if (dpyinfo
->font_table
[i
].name
10748 && (!xstricmp (dpyinfo
->font_table
[i
].name
, fontname
)
10749 || !xstricmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
10750 return (dpyinfo
->font_table
+ i
);
10755 /* Find a CCL program for a font specified by FONTP, and set the member
10756 `encoder' of the structure. */
10759 x_find_ccl_program (fontp
)
10760 struct font_info
*fontp
;
10762 Lisp_Object list
, elt
;
10765 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
10769 && STRINGP (XCAR (elt
))
10770 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
10772 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
10779 struct ccl_program
*ccl
10780 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
10782 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
10785 fontp
->font_encoder
= ccl
;
10790 /* Return a char-table whose elements are t if the font FONT_INFO
10791 contains a glyph for the corresponding character, and nil if
10795 x_get_font_repertory (f
, font_info
)
10797 struct font_info
*font_info
;
10799 XFontStruct
*font
= (XFontStruct
*) font_info
->font
;
10801 int min_byte1
, max_byte1
, min_byte2
, max_byte2
;
10803 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
10804 int offset
= CHARSET_OFFSET (charset
);
10806 table
= Fmake_char_table (Qnil
, Qnil
);
10808 min_byte1
= font
->min_byte1
;
10809 max_byte1
= font
->max_byte1
;
10810 min_byte2
= font
->min_char_or_byte2
;
10811 max_byte2
= font
->max_char_or_byte2
;
10812 if (min_byte1
== 0 && max_byte1
== 0)
10814 if (! font
->per_char
|| font
->all_chars_exist
== True
)
10817 char_table_set_range (table
, offset
+ min_byte2
,
10818 offset
+ max_byte2
, Qt
);
10820 for (; min_byte2
<= max_byte2
; min_byte2
++)
10822 c
= DECODE_CHAR (charset
, min_byte2
);
10823 CHAR_TABLE_SET (table
, c
, Qt
);
10828 XCharStruct
*pcm
= font
->per_char
;
10832 for (i
= min_byte2
; i
<= max_byte2
; i
++, pcm
++)
10834 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
10839 char_table_set_range (table
, offset
+ from
,
10840 offset
+ i
- 1, Qt
);
10842 for (; from
< i
; from
++)
10844 c
= DECODE_CHAR (charset
, from
);
10845 CHAR_TABLE_SET (table
, c
, Qt
);
10856 char_table_set_range (table
, offset
+ from
, offset
+ i
- 1,
10859 for (; from
< i
; from
++)
10861 c
= DECODE_CHAR (charset
, from
);
10862 CHAR_TABLE_SET (table
, c
, Qt
);
10869 if (! font
->per_char
|| font
->all_chars_exist
== True
)
10874 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10875 char_table_set_range
10876 (table
, offset
+ ((i
<< 8) | min_byte2
),
10877 offset
+ ((i
<< 8) | max_byte2
), Qt
);
10879 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10880 for (j
= min_byte2
; j
<= max_byte2
; j
++)
10882 unsigned code
= (i
<< 8) | j
;
10883 c
= DECODE_CHAR (charset
, code
);
10884 CHAR_TABLE_SET (table
, c
, Qt
);
10889 XCharStruct
*pcm
= font
->per_char
;
10892 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10897 for (j
= min_byte2
; j
<= max_byte2
; j
++, pcm
++)
10899 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
10904 char_table_set_range
10905 (table
, offset
+ ((i
<< 8) | from
),
10906 offset
+ ((i
<< 8) | (j
- 1)), Qt
);
10909 for (; from
< j
; from
++)
10911 unsigned code
= (i
<< 8) | from
;
10912 c
= ENCODE_CHAR (charset
, code
);
10913 CHAR_TABLE_SET (table
, c
, Qt
);
10925 char_table_set_range
10926 (table
, offset
+ ((i
<< 8) | from
),
10927 offset
+ ((i
<< 8) | (j
- 1)), Qt
);
10930 for (; from
< j
; from
++)
10932 unsigned code
= (i
<< 8) | from
;
10933 c
= DECODE_CHAR (charset
, code
);
10934 CHAR_TABLE_SET (table
, c
, Qt
);
10945 /***********************************************************************
10947 ***********************************************************************/
10949 #ifdef USE_X_TOOLKIT
10950 static XrmOptionDescRec emacs_options
[] = {
10951 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
10952 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
10954 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
10955 XrmoptionSepArg
, NULL
},
10956 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
10958 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10959 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10960 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10961 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10962 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10963 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
10964 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
10967 /* Whether atimer for Xt timeouts is activated or not. */
10969 static int x_timeout_atimer_activated_flag
;
10971 #endif /* USE_X_TOOLKIT */
10973 static int x_initialized
;
10976 static int x_session_initialized
;
10979 #ifdef MULTI_KBOARD
10980 /* Test whether two display-name strings agree up to the dot that separates
10981 the screen number from the server number. */
10983 same_x_server (name1
, name2
)
10984 const char *name1
, *name2
;
10986 int seen_colon
= 0;
10987 const unsigned char *system_name
= SDATA (Vsystem_name
);
10988 int system_name_length
= strlen (system_name
);
10989 int length_until_period
= 0;
10991 while (system_name
[length_until_period
] != 0
10992 && system_name
[length_until_period
] != '.')
10993 length_until_period
++;
10995 /* Treat `unix' like an empty host name. */
10996 if (! strncmp (name1
, "unix:", 5))
10998 if (! strncmp (name2
, "unix:", 5))
11000 /* Treat this host's name like an empty host name. */
11001 if (! strncmp (name1
, system_name
, system_name_length
)
11002 && name1
[system_name_length
] == ':')
11003 name1
+= system_name_length
;
11004 if (! strncmp (name2
, system_name
, system_name_length
)
11005 && name2
[system_name_length
] == ':')
11006 name2
+= system_name_length
;
11007 /* Treat this host's domainless name like an empty host name. */
11008 if (! strncmp (name1
, system_name
, length_until_period
)
11009 && name1
[length_until_period
] == ':')
11010 name1
+= length_until_period
;
11011 if (! strncmp (name2
, system_name
, length_until_period
)
11012 && name2
[length_until_period
] == ':')
11013 name2
+= length_until_period
;
11015 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
11019 if (seen_colon
&& *name1
== '.')
11023 && (*name1
== '.' || *name1
== '\0')
11024 && (*name2
== '.' || *name2
== '\0'));
11028 /* Count number of set bits in mask and number of bits to shift to
11029 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
11032 get_bits_and_offset (mask
, bits
, offset
)
11033 unsigned long mask
;
11040 while (!(mask
& 1))
11056 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
11057 But don't permanently open it, just test its availability. */
11060 x_display_ok (display
)
11061 const char *display
;
11066 dpy
= XOpenDisplay (display
);
11068 XCloseDisplay (dpy
);
11074 /* Open a connection to X display DISPLAY_NAME, and return
11075 the structure that describes the open display.
11076 If we cannot contact the display, return null. */
11078 struct x_display_info
*
11079 x_term_init (display_name
, xrm_option
, resource_name
)
11080 Lisp_Object display_name
;
11082 char *resource_name
;
11086 struct terminal
*terminal
;
11087 struct x_display_info
*dpyinfo
;
11092 if (!x_initialized
)
11098 if (! x_display_ok (SDATA (display_name
)))
11099 error ("Display %s can't be opened", SDATA (display_name
));
11103 #define NUM_ARGV 10
11105 char *argv
[NUM_ARGV
];
11106 char **argv2
= argv
;
11109 #ifndef HAVE_GTK_MULTIDISPLAY
11110 if (!EQ (Vinitial_window_system
, intern ("x")))
11111 error ("Sorry, you cannot connect to X servers with the GTK toolkit");
11114 if (x_initialized
++ > 1)
11116 #ifdef HAVE_GTK_MULTIDISPLAY
11117 /* Opening another display. If xg_display_open returns less
11118 than zero, we are probably on GTK 2.0, which can only handle
11119 one display. GTK 2.2 or later can handle more than one. */
11120 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
11122 error ("Sorry, this version of GTK can only handle one display");
11126 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
11130 argv
[argc
++] = initial_argv
[0];
11132 if (! NILP (display_name
))
11134 argv
[argc
++] = "--display";
11135 argv
[argc
++] = SDATA (display_name
);
11138 argv
[argc
++] = "--name";
11139 argv
[argc
++] = resource_name
;
11142 XSetLocaleModifiers ("");
11145 gtk_init (&argc
, &argv2
);
11147 /* gtk_init does set_locale. We must fix locale after calling it. */
11151 dpy
= GDK_DISPLAY ();
11153 /* NULL window -> events for all windows go to our function */
11154 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
11156 /* Load our own gtkrc if it exists. */
11158 char *file
= "~/.emacs.d/gtkrc";
11159 Lisp_Object s
, abs_file
;
11161 s
= make_string (file
, strlen (file
));
11162 abs_file
= Fexpand_file_name (s
, Qnil
);
11164 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
11165 gtk_rc_parse (SDATA (abs_file
));
11168 XSetErrorHandler (x_error_handler
);
11169 XSetIOErrorHandler (x_io_error_quitter
);
11172 #else /* not USE_GTK */
11173 #ifdef USE_X_TOOLKIT
11174 /* weiner@footloose.sps.mot.com reports that this causes
11176 X protocol error: BadAtom (invalid Atom parameter)
11177 on protocol request 18skiloaf.
11178 So let's not use it until R6. */
11179 #ifdef HAVE_X11XTR6
11180 XtSetLanguageProc (NULL
, NULL
, NULL
);
11191 argv
[argc
++] = "-xrm";
11192 argv
[argc
++] = xrm_option
;
11194 turn_on_atimers (0);
11195 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
11196 resource_name
, EMACS_CLASS
,
11197 emacs_options
, XtNumber (emacs_options
),
11199 turn_on_atimers (1);
11201 #ifdef HAVE_X11XTR6
11202 /* I think this is to compensate for XtSetLanguageProc. */
11207 #else /* not USE_X_TOOLKIT */
11209 XSetLocaleModifiers ("");
11211 dpy
= XOpenDisplay (SDATA (display_name
));
11212 #endif /* not USE_X_TOOLKIT */
11213 #endif /* not USE_GTK*/
11215 /* Detect failure. */
11222 /* We have definitely succeeded. Record the new connection. */
11224 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
11225 bzero (dpyinfo
, sizeof *dpyinfo
);
11227 terminal
= x_create_terminal (dpyinfo
);
11229 #ifdef MULTI_KBOARD
11231 struct x_display_info
*share
;
11234 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
11235 share
= share
->next
, tail
= XCDR (tail
))
11236 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
11237 SDATA (display_name
)))
11240 terminal
->kboard
= share
->terminal
->kboard
;
11243 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
11244 init_kboard (terminal
->kboard
);
11245 terminal
->kboard
->Vwindow_system
= intern ("x");
11246 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
11248 char *vendor
= ServerVendor (dpy
);
11250 terminal
->kboard
->Vsystem_key_alist
11251 = call1 (Qvendor_specific_keysyms
,
11252 vendor
? build_string (vendor
) : empty_unibyte_string
);
11256 terminal
->kboard
->next_kboard
= all_kboards
;
11257 all_kboards
= terminal
->kboard
;
11258 /* Don't let the initial kboard remain current longer than necessary.
11259 That would cause problems if a file loaded on startup tries to
11260 prompt in the mini-buffer. */
11261 if (current_kboard
== initial_kboard
)
11262 current_kboard
= terminal
->kboard
;
11264 terminal
->kboard
->reference_count
++;
11268 /* Put this display on the chain. */
11269 dpyinfo
->next
= x_display_list
;
11270 x_display_list
= dpyinfo
;
11272 /* Put it on x_display_name_list as well, to keep them parallel. */
11273 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
11274 x_display_name_list
);
11275 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
11277 dpyinfo
->display
= dpy
;
11279 /* Set the name of the terminal. */
11280 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
11281 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
11282 terminal
->name
[SBYTES (display_name
)] = 0;
11285 XSetAfterFunction (x_current_display
, x_trace_wire
);
11289 = (char *) xmalloc (SBYTES (Vinvocation_name
)
11290 + SBYTES (Vsystem_name
)
11292 sprintf (dpyinfo
->x_id_name
, "%s@%s",
11293 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
11295 /* Figure out which modifier bits mean what. */
11296 x_find_modifier_meanings (dpyinfo
);
11298 /* Get the scroll bar cursor. */
11300 /* We must create a GTK cursor, it is required for GTK widgets. */
11301 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
11302 #endif /* USE_GTK */
11304 dpyinfo
->vertical_scroll_bar_cursor
11305 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
11307 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
11308 resource_name
, EMACS_CLASS
);
11309 #ifdef HAVE_XRMSETDATABASE
11310 XrmSetDatabase (dpyinfo
->display
, xrdb
);
11312 dpyinfo
->display
->db
= xrdb
;
11314 /* Put the rdb where we can find it in a way that works on
11316 dpyinfo
->xrdb
= xrdb
;
11318 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
11319 DefaultScreen (dpyinfo
->display
));
11320 select_visual (dpyinfo
);
11321 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
11322 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
11323 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
11324 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
11325 dpyinfo
->client_leader_window
= 0;
11326 dpyinfo
->grabbed
= 0;
11327 dpyinfo
->reference_count
= 0;
11328 dpyinfo
->icon_bitmap_id
= -1;
11329 dpyinfo
->font_table
= NULL
;
11330 dpyinfo
->n_fonts
= 0;
11331 dpyinfo
->font_table_size
= 0;
11332 dpyinfo
->bitmaps
= 0;
11333 dpyinfo
->bitmaps_size
= 0;
11334 dpyinfo
->bitmaps_last
= 0;
11335 dpyinfo
->scratch_cursor_gc
= 0;
11336 dpyinfo
->mouse_face_mouse_frame
= 0;
11337 dpyinfo
->mouse_face_deferred_gc
= 0;
11338 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
11339 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
11340 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
11341 dpyinfo
->mouse_face_window
= Qnil
;
11342 dpyinfo
->mouse_face_overlay
= Qnil
;
11343 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
11344 dpyinfo
->mouse_face_defer
= 0;
11345 dpyinfo
->mouse_face_hidden
= 0;
11346 dpyinfo
->x_focus_frame
= 0;
11347 dpyinfo
->x_focus_event_frame
= 0;
11348 dpyinfo
->x_highlight_frame
= 0;
11349 dpyinfo
->image_cache
= make_image_cache ();
11350 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
11352 /* See if we can construct pixel values from RGB values. */
11353 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
11354 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
11356 if (dpyinfo
->visual
->class == TrueColor
)
11358 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
11359 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
11360 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
11361 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
11362 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
11363 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
11366 /* See if a private colormap is requested. */
11367 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
11369 if (dpyinfo
->visual
->class == PseudoColor
)
11372 value
= display_x_get_resource (dpyinfo
,
11373 build_string ("privateColormap"),
11374 build_string ("PrivateColormap"),
11376 if (STRINGP (value
)
11377 && (!strcmp (SDATA (value
), "true")
11378 || !strcmp (SDATA (value
), "on")))
11379 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
11383 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
11384 dpyinfo
->visual
, AllocNone
);
11387 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
11388 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
11389 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
11390 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
11391 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
11392 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
11393 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
11394 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
11395 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
11398 dpyinfo
->Xatom_wm_protocols
11399 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
11400 dpyinfo
->Xatom_wm_take_focus
11401 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
11402 dpyinfo
->Xatom_wm_save_yourself
11403 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
11404 dpyinfo
->Xatom_wm_delete_window
11405 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
11406 dpyinfo
->Xatom_wm_change_state
11407 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
11408 dpyinfo
->Xatom_wm_configure_denied
11409 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
11410 dpyinfo
->Xatom_wm_window_moved
11411 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
11412 dpyinfo
->Xatom_wm_client_leader
11413 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
11414 dpyinfo
->Xatom_editres
11415 = XInternAtom (dpyinfo
->display
, "Editres", False
);
11416 dpyinfo
->Xatom_CLIPBOARD
11417 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
11418 dpyinfo
->Xatom_TIMESTAMP
11419 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
11420 dpyinfo
->Xatom_TEXT
11421 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
11422 dpyinfo
->Xatom_COMPOUND_TEXT
11423 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
11424 dpyinfo
->Xatom_UTF8_STRING
11425 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
11426 dpyinfo
->Xatom_DELETE
11427 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
11428 dpyinfo
->Xatom_MULTIPLE
11429 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
11430 dpyinfo
->Xatom_INCR
11431 = XInternAtom (dpyinfo
->display
, "INCR", False
);
11432 dpyinfo
->Xatom_EMACS_TMP
11433 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
11434 dpyinfo
->Xatom_TARGETS
11435 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
11436 dpyinfo
->Xatom_NULL
11437 = XInternAtom (dpyinfo
->display
, "NULL", False
);
11438 dpyinfo
->Xatom_ATOM_PAIR
11439 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
11440 /* For properties of font. */
11441 dpyinfo
->Xatom_PIXEL_SIZE
11442 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
11443 dpyinfo
->Xatom_AVERAGE_WIDTH
11444 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
11445 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
11446 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
11447 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
11448 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
11449 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
11450 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
11452 /* Ghostscript support. */
11453 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
11454 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
11456 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
11459 dpyinfo
->cut_buffers_initialized
= 0;
11461 dpyinfo
->x_dnd_atoms_size
= 8;
11462 dpyinfo
->x_dnd_atoms_length
= 0;
11463 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
11464 * dpyinfo
->x_dnd_atoms_size
);
11466 dpyinfo
->net_supported_atoms
= NULL
;
11467 dpyinfo
->nr_net_supported_atoms
= 0;
11468 dpyinfo
->net_supported_window
= 0;
11470 connection
= ConnectionNumber (dpyinfo
->display
);
11471 dpyinfo
->connection
= connection
;
11476 null_bits
[0] = 0x00;
11478 dpyinfo
->null_pixel
11479 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
11480 null_bits
, 1, 1, (long) 0, (long) 0,
11485 extern int gray_bitmap_width
, gray_bitmap_height
;
11486 extern char *gray_bitmap_bits
;
11488 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
11490 gray_bitmap_width
, gray_bitmap_height
,
11491 (unsigned long) 1, (unsigned long) 0, 1);
11495 xim_initialize (dpyinfo
, resource_name
);
11498 #ifdef subprocesses
11499 /* This is only needed for distinguishing keyboard and process input. */
11500 if (connection
!= 0)
11501 add_keyboard_wait_descriptor (connection
);
11504 #ifndef F_SETOWN_BUG
11506 #ifdef F_SETOWN_SOCK_NEG
11507 /* stdin is a socket here */
11508 fcntl (connection
, F_SETOWN
, -getpid ());
11509 #else /* ! defined (F_SETOWN_SOCK_NEG) */
11510 fcntl (connection
, F_SETOWN
, getpid ());
11511 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
11512 #endif /* ! defined (F_SETOWN) */
11513 #endif /* F_SETOWN_BUG */
11516 if (interrupt_input
)
11517 init_sigio (connection
);
11518 #endif /* ! defined (SIGIO) */
11521 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
11522 /* Make sure that we have a valid font for dialog boxes
11523 so that Xt does not crash. */
11525 Display
*dpy
= dpyinfo
->display
;
11526 XrmValue d
, fr
, to
;
11529 d
.addr
= (XPointer
)&dpy
;
11530 d
.size
= sizeof (Display
*);
11531 fr
.addr
= XtDefaultFont
;
11532 fr
.size
= sizeof (XtDefaultFont
);
11533 to
.size
= sizeof (Font
*);
11534 to
.addr
= (XPointer
)&font
;
11535 x_catch_errors (dpy
);
11536 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
11538 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
11539 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
11540 x_uncatch_errors ();
11545 /* See if we should run in synchronous mode. This is useful
11546 for debugging X code. */
11549 value
= display_x_get_resource (dpyinfo
,
11550 build_string ("synchronous"),
11551 build_string ("Synchronous"),
11553 if (STRINGP (value
)
11554 && (!strcmp (SDATA (value
), "true")
11555 || !strcmp (SDATA (value
), "on")))
11556 XSynchronize (dpyinfo
->display
, True
);
11561 value
= display_x_get_resource (dpyinfo
,
11562 build_string ("useXIM"),
11563 build_string ("UseXIM"),
11566 if (STRINGP (value
)
11567 && (!strcmp (XSTRING (value
)->data
, "false")
11568 || !strcmp (XSTRING (value
)->data
, "off")))
11571 if (STRINGP (value
)
11572 && (!strcmp (XSTRING (value
)->data
, "true")
11573 || !strcmp (XSTRING (value
)->data
, "on")))
11579 /* Only do this for the very first display in the Emacs session.
11580 Ignore X session management when Emacs was first started on a
11582 if (terminal
->id
== 1)
11583 x_session_initialize (dpyinfo
);
11591 /* Get rid of display DPYINFO, deleting all frames on it,
11592 and without sending any more commands to the X server. */
11595 x_delete_display (dpyinfo
)
11596 struct x_display_info
*dpyinfo
;
11599 struct terminal
*t
;
11601 /* Close all frames and delete the generic struct terminal for this
11603 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
11604 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
11607 /* Close X session management when we close its display. */
11608 if (t
->id
== 1 && x_session_have_connection ())
11611 delete_terminal (t
);
11615 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
11617 /* Discard this display from x_display_name_list and x_display_list.
11618 We can't use Fdelq because that can quit. */
11619 if (! NILP (x_display_name_list
)
11620 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
11621 x_display_name_list
= XCDR (x_display_name_list
);
11626 tail
= x_display_name_list
;
11627 while (CONSP (tail
) && CONSP (XCDR (tail
)))
11629 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
11631 XSETCDR (tail
, XCDR (XCDR (tail
)));
11634 tail
= XCDR (tail
);
11638 if (next_noop_dpyinfo
== dpyinfo
)
11639 next_noop_dpyinfo
= dpyinfo
->next
;
11641 if (x_display_list
== dpyinfo
)
11642 x_display_list
= dpyinfo
->next
;
11645 struct x_display_info
*tail
;
11647 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
11648 if (tail
->next
== dpyinfo
)
11649 tail
->next
= tail
->next
->next
;
11652 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
11653 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
11654 XrmDestroyDatabase (dpyinfo
->xrdb
);
11659 xim_close_dpy (dpyinfo
);
11662 /* Free the font names in the font table. */
11663 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11664 if (dpyinfo
->font_table
[i
].name
)
11666 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
11667 xfree (dpyinfo
->font_table
[i
].full_name
);
11668 xfree (dpyinfo
->font_table
[i
].name
);
11671 if (dpyinfo
->font_table
)
11673 if (dpyinfo
->font_table
->font_encoder
)
11674 xfree (dpyinfo
->font_table
->font_encoder
);
11675 xfree (dpyinfo
->font_table
);
11677 if (dpyinfo
->x_id_name
)
11678 xfree (dpyinfo
->x_id_name
);
11679 if (dpyinfo
->color_cells
)
11680 xfree (dpyinfo
->color_cells
);
11684 #ifdef USE_X_TOOLKIT
11686 /* Atimer callback function for TIMER. Called every 0.1s to process
11687 Xt timeouts, if needed. We must avoid calling XtAppPending as
11688 much as possible because that function does an implicit XFlush
11689 that slows us down. */
11692 x_process_timeouts (timer
)
11693 struct atimer
*timer
;
11696 x_timeout_atimer_activated_flag
= 0;
11697 if (toolkit_scroll_bar_interaction
|| popup_activated ())
11699 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
11700 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
11701 /* Reactivate the atimer for next time. */
11702 x_activate_timeout_atimer ();
11707 /* Install an asynchronous timer that processes Xt timeout events
11708 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
11709 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
11710 function whenever these variables are set. This is necessary
11711 because some widget sets use timeouts internally, for example the
11712 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
11713 processed, these widgets don't behave normally. */
11716 x_activate_timeout_atimer ()
11719 if (!x_timeout_atimer_activated_flag
)
11721 EMACS_TIME interval
;
11723 EMACS_SET_SECS_USECS (interval
, 0, 100000);
11724 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
11725 x_timeout_atimer_activated_flag
= 1;
11730 #endif /* USE_X_TOOLKIT */
11733 /* Set up use of X before we make the first connection. */
11735 extern frame_parm_handler x_frame_parm_handlers
[];
11737 static struct redisplay_interface x_redisplay_interface
=
11739 x_frame_parm_handlers
,
11743 x_clear_end_of_line
,
11745 x_after_update_window_line
,
11746 x_update_window_begin
,
11747 x_update_window_end
,
11753 0, /* flush_display_optional */
11755 x_clear_window_mouse_face
,
11756 x_get_glyph_overhangs
,
11757 x_fix_overlapping_area
,
11758 x_draw_fringe_bitmap
,
11759 0, /* define_fringe_bitmap */
11760 0, /* destroy_fringe_bitmap */
11763 x_compute_glyph_string_overhangs
,
11764 x_draw_glyph_string
,
11765 x_define_frame_cursor
,
11766 x_clear_frame_area
,
11767 x_draw_window_cursor
,
11768 x_draw_vertical_window_border
,
11769 x_shift_glyphs_for_insert
11773 /* This function is called when the last frame on a display is deleted. */
11775 x_delete_terminal (struct terminal
*terminal
)
11777 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
11780 /* Protect against recursive calls. Fdelete_frame in
11781 delete_terminal calls us back when it deletes our last frame. */
11782 if (!terminal
->name
)
11786 /* Free the fonts in the font table. */
11787 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11788 if (dpyinfo
->font_table
[i
].name
)
11790 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
11793 x_destroy_all_bitmaps (dpyinfo
);
11794 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
11797 xg_display_close (dpyinfo
->display
);
11799 #ifdef USE_X_TOOLKIT
11800 XtCloseDisplay (dpyinfo
->display
);
11802 XCloseDisplay (dpyinfo
->display
);
11804 #endif /* ! USE_GTK */
11806 x_delete_display (dpyinfo
);
11810 /* Create a struct terminal, initialize it with the X11 specific
11811 functions and make DISPLAY->TERMINAL point to it. */
11813 static struct terminal
*
11814 x_create_terminal (struct x_display_info
*dpyinfo
)
11816 struct terminal
*terminal
;
11818 terminal
= create_terminal ();
11820 terminal
->type
= output_x_window
;
11821 terminal
->display_info
.x
= dpyinfo
;
11822 dpyinfo
->terminal
= terminal
;
11824 /* kboard is initialized in x_term_init. */
11826 terminal
->clear_frame_hook
= x_clear_frame
;
11827 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
11828 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
11829 terminal
->ring_bell_hook
= XTring_bell
;
11830 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
11831 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
11832 terminal
->update_begin_hook
= x_update_begin
;
11833 terminal
->update_end_hook
= x_update_end
;
11834 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
11835 terminal
->read_socket_hook
= XTread_socket
;
11836 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
11837 terminal
->mouse_position_hook
= XTmouse_position
;
11838 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
11839 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
11840 terminal
->fullscreen_hook
= XTfullscreen_hook
;
11841 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
11842 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
11843 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
11844 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
11846 terminal
->delete_frame_hook
= x_destroy_window
;
11847 terminal
->delete_terminal_hook
= x_delete_terminal
;
11849 terminal
->rif
= &x_redisplay_interface
;
11850 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
11851 terminal
->char_ins_del_ok
= 1;
11852 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
11853 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
11854 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
11866 last_tool_bar_item
= -1;
11867 any_help_event_p
= 0;
11868 ignore_next_mouse_click_timeout
= 0;
11870 x_session_initialized
= 0;
11874 current_count
= -1;
11877 /* Try to use interrupt input; if we can't, then start polling. */
11878 Fset_input_interrupt_mode (Qt
);
11880 #ifdef USE_X_TOOLKIT
11881 XtToolkitInitialize ();
11883 Xt_app_con
= XtCreateApplicationContext ();
11885 /* Register a converter from strings to pixels, which uses
11886 Emacs' color allocation infrastructure. */
11887 XtAppSetTypeConverter (Xt_app_con
,
11888 XtRString
, XtRPixel
, cvt_string_to_pixel
,
11889 cvt_string_to_pixel_args
,
11890 XtNumber (cvt_string_to_pixel_args
),
11891 XtCacheByDisplay
, cvt_pixel_dtor
);
11893 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
11896 #ifdef USE_TOOLKIT_SCROLL_BARS
11898 xaw3d_arrow_scroll
= False
;
11899 xaw3d_pick_top
= True
;
11903 /* Note that there is no real way portable across R3/R4 to get the
11904 original error handler. */
11905 XSetErrorHandler (x_error_handler
);
11906 XSetIOErrorHandler (x_io_error_quitter
);
11908 /* Disable Window Change signals; they are handled by X events. */
11909 #if 0 /* Don't. We may want to open tty frames later. */
11911 signal (SIGWINCH
, SIG_DFL
);
11912 #endif /* SIGWINCH */
11915 signal (SIGPIPE
, x_connection_signal
);
11922 x_error_message
= NULL
;
11924 staticpro (&x_display_name_list
);
11925 x_display_name_list
= Qnil
;
11927 staticpro (&last_mouse_scroll_bar
);
11928 last_mouse_scroll_bar
= Qnil
;
11930 staticpro (&Qvendor_specific_keysyms
);
11931 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
11933 staticpro (&Qlatin_1
);
11934 Qlatin_1
= intern ("latin-1");
11936 staticpro (&last_mouse_press_frame
);
11937 last_mouse_press_frame
= Qnil
;
11939 DEFVAR_BOOL ("x-use-underline-position-properties",
11940 &x_use_underline_position_properties
,
11941 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11942 A value of nil means ignore them. If you encounter fonts with bogus
11943 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11944 to 4.1, set this to nil. */);
11945 x_use_underline_position_properties
= 1;
11947 DEFVAR_BOOL ("x-underline-at-descent-line",
11948 &x_underline_at_descent_line
,
11949 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
11950 A value of nil means to draw the underline according to the value of the
11951 variable `x-use-underline-position-properties', which is usually at the
11952 baseline level. The default value is nil. */);
11953 x_underline_at_descent_line
= 0;
11955 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
11956 &x_mouse_click_focus_ignore_position
,
11957 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
11958 This variable is only used when the window manager requires that you
11959 click on a frame to select it (give it focus). In that case, a value
11960 of nil, means that the selected window and cursor position changes to
11961 reflect the mouse click position, while a non-nil value means that the
11962 selected window or cursor position is preserved. */);
11963 x_mouse_click_focus_ignore_position
= 0;
11965 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11966 doc
: /* What X toolkit scroll bars Emacs uses.
11967 A value of nil means Emacs doesn't use X toolkit scroll bars.
11968 Otherwise, value is a symbol describing the X toolkit. */);
11969 #ifdef USE_TOOLKIT_SCROLL_BARS
11971 Vx_toolkit_scroll_bars
= intern ("motif");
11972 #elif defined HAVE_XAW3D
11973 Vx_toolkit_scroll_bars
= intern ("xaw3d");
11975 Vx_toolkit_scroll_bars
= intern ("gtk");
11977 Vx_toolkit_scroll_bars
= intern ("xaw");
11980 Vx_toolkit_scroll_bars
= Qnil
;
11983 staticpro (&last_mouse_motion_frame
);
11984 last_mouse_motion_frame
= Qnil
;
11986 Qmodifier_value
= intern ("modifier-value");
11987 Qalt
= intern ("alt");
11988 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
11989 Qhyper
= intern ("hyper");
11990 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
11991 Qmeta
= intern ("meta");
11992 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
11993 Qsuper
= intern ("super");
11994 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
11996 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
11997 doc
: /* Which keys Emacs uses for the alt modifier.
11998 This should be one of the symbols `alt', `hyper', `meta', `super'.
11999 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
12000 is nil, which is the same as `alt'. */);
12001 Vx_alt_keysym
= Qnil
;
12003 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
12004 doc
: /* Which keys Emacs uses for the hyper modifier.
12005 This should be one of the symbols `alt', `hyper', `meta', `super'.
12006 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
12007 default is nil, which is the same as `hyper'. */);
12008 Vx_hyper_keysym
= Qnil
;
12010 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
12011 doc
: /* Which keys Emacs uses for the meta modifier.
12012 This should be one of the symbols `alt', `hyper', `meta', `super'.
12013 For example, `meta' means use the Meta_L and Meta_R keysyms. The
12014 default is nil, which is the same as `meta'. */);
12015 Vx_meta_keysym
= Qnil
;
12017 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
12018 doc
: /* Which keys Emacs uses for the super modifier.
12019 This should be one of the symbols `alt', `hyper', `meta', `super'.
12020 For example, `super' means use the Super_L and Super_R keysyms. The
12021 default is nil, which is the same as `super'. */);
12022 Vx_super_keysym
= Qnil
;
12024 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
12025 doc
: /* Hash table of character codes indexed by X keysym codes. */);
12026 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
12027 make_float (DEFAULT_REHASH_SIZE
),
12028 make_float (DEFAULT_REHASH_THRESHOLD
),
12032 #endif /* HAVE_X_WINDOWS */
12034 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
12035 (do not change this comment) */