1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
24 /* Xt features made by Fred Pierresteguy. */
28 /* On 4.3 these lose if they come after xterm.h. */
29 /* Putting these at the beginning seems to be standard for other .c files. */
37 #include "blockinput.h"
39 /* Need syssignal.h for various externs and definitions that may be required
40 by some configurations for calls to signal later in this source file. */
41 #include "syssignal.h"
43 /* This may include sys/types.h, and that somehow loses
44 if this is not done before the other system files. */
46 #include <X11/cursorfont.h>
48 /* Load sys/types.h if not already loaded.
49 In some systems loading it twice is suicidal. */
51 #include <sys/types.h>
55 #include <sys/ioctl.h>
56 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
71 #include "character.h"
75 #include "dispextern.h"
77 #include "termhooks.h"
85 #include "intervals.h"
91 #include <X11/Shell.h>
94 #ifdef HAVE_SYS_TIME_H
105 #ifdef USE_FONT_BACKEND
107 #endif /* USE_FONT_BACKEND */
110 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
111 extern void xlwmenu_redisplay
P_ ((Widget
));
114 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
116 extern void free_frame_menubar
P_ ((struct frame
*));
117 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
122 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
124 extern void _XEditResCheckMessages ();
125 #endif /* not NO_EDITRES */
127 /* Include toolkit specific headers for the scroll bar widget. */
129 #ifdef USE_TOOLKIT_SCROLL_BARS
130 #if defined USE_MOTIF
131 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
132 #include <Xm/ScrollBar.h>
133 #else /* !USE_MOTIF i.e. use Xaw */
136 #include <X11/Xaw3d/Simple.h>
137 #include <X11/Xaw3d/Scrollbar.h>
138 #include <X11/Xaw3d/ThreeD.h>
139 #else /* !HAVE_XAW3D */
140 #include <X11/Xaw/Simple.h>
141 #include <X11/Xaw/Scrollbar.h>
142 #endif /* !HAVE_XAW3D */
144 #define XtNpickTop "pickTop"
145 #endif /* !XtNpickTop */
146 #endif /* !USE_MOTIF */
147 #endif /* USE_TOOLKIT_SCROLL_BARS */
149 #endif /* USE_X_TOOLKIT */
151 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
152 #define x_any_window_to_frame x_window_to_frame
153 #define x_top_window_to_frame x_window_to_frame
158 #ifndef XtNinitialState
159 #define XtNinitialState "initialState"
163 /* Default to using XIM if available. */
167 int use_xim
= 0; /* configure --without-xim */
172 /* Non-nil means Emacs uses toolkit scroll bars. */
174 Lisp_Object Vx_toolkit_scroll_bars
;
176 /* Non-zero means that a HELP_EVENT has been generated since Emacs
179 static int any_help_event_p
;
181 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
182 static Lisp_Object last_window
;
184 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
186 int x_use_underline_position_properties
;
188 /* Non-zero means to draw the underline at the same place as the descent line. */
190 int x_underline_at_descent_line
;
192 /* This is a chain of structures for all the X displays currently in
195 struct x_display_info
*x_display_list
;
197 /* This is a list of cons cells, each of the form (NAME
198 . FONT-LIST-CACHE), one for each element of x_display_list and in
199 the same order. NAME is the name of the frame. FONT-LIST-CACHE
200 records previous values returned by x-list-fonts. */
202 Lisp_Object x_display_name_list
;
204 /* Frame being updated by update_frame. This is declared in term.c.
205 This is set by update_begin and looked at by all the XT functions.
206 It is zero while not inside an update. In that case, the XT
207 functions assume that `selected_frame' is the frame to apply to. */
209 extern struct frame
*updating_frame
;
211 /* This is a frame waiting to be auto-raised, within XTread_socket. */
213 struct frame
*pending_autoraise_frame
;
216 /* The application context for Xt use. */
217 XtAppContext Xt_app_con
;
218 static String Xt_default_resources
[] = {0};
219 #endif /* USE_X_TOOLKIT */
221 /* Non-zero means user is interacting with a toolkit scroll bar. */
223 static int toolkit_scroll_bar_interaction
;
225 /* Non-zero means to not move point as a result of clicking on a
226 frame to focus it (when focus-follows-mouse is nil). */
228 int x_mouse_click_focus_ignore_position
;
230 /* Non-zero timeout value means ignore next mouse click if it arrives
231 before that timeout elapses (i.e. as part of the same sequence of
232 events resulting from clicking on a frame to select it). */
234 static unsigned long ignore_next_mouse_click_timeout
;
238 Formerly, we used PointerMotionHintMask (in standard_event_mask)
239 so that we would have to call XQueryPointer after each MotionNotify
240 event to ask for another such event. However, this made mouse tracking
241 slow, and there was a bug that made it eventually stop.
243 Simply asking for MotionNotify all the time seems to work better.
245 In order to avoid asking for motion events and then throwing most
246 of them away or busy-polling the server for mouse positions, we ask
247 the server for pointer motion hints. This means that we get only
248 one event per group of mouse movements. "Groups" are delimited by
249 other kinds of events (focus changes and button clicks, for
250 example), or by XQueryPointer calls; when one of these happens, we
251 get another MotionNotify event the next time the mouse moves. This
252 is at least as efficient as getting motion events when mouse
253 tracking is on, and I suspect only negligibly worse when tracking
256 /* Where the mouse was last time we reported a mouse event. */
258 static XRectangle last_mouse_glyph
;
259 static FRAME_PTR last_mouse_glyph_frame
;
260 static Lisp_Object last_mouse_press_frame
;
262 /* The scroll bar in which the last X motion event occurred.
264 If the last X motion event occurred in a scroll bar, we set this so
265 XTmouse_position can know whether to report a scroll bar motion or
268 If the last X motion event didn't occur in a scroll bar, we set
269 this to Qnil, to tell XTmouse_position to return an ordinary motion
272 static Lisp_Object last_mouse_scroll_bar
;
274 /* This is a hack. We would really prefer that XTmouse_position would
275 return the time associated with the position it returns, but there
276 doesn't seem to be any way to wrest the time-stamp from the server
277 along with the position query. So, we just keep track of the time
278 of the last movement we received, and return that in hopes that
279 it's somewhat accurate. */
281 static Time last_mouse_movement_time
;
283 /* Time for last user interaction as returned in X events. */
285 static Time last_user_time
;
287 /* Incremented by XTread_socket whenever it really tries to read
291 static int volatile input_signal_count
;
293 static int input_signal_count
;
296 /* Used locally within XTread_socket. */
298 static int x_noop_count
;
300 /* Initial values of argv and argc. */
302 extern char **initial_argv
;
303 extern int initial_argc
;
305 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
307 /* Tells if a window manager is present or not. */
309 extern Lisp_Object Vx_no_window_manager
;
311 extern Lisp_Object Qeql
;
315 /* A mask of extra modifier bits to put into every keyboard char. */
317 extern EMACS_INT extra_keyboard_modifiers
;
319 /* The keysyms to use for the various modifiers. */
321 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
322 Lisp_Object Vx_keysym_table
;
323 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
325 static Lisp_Object Qvendor_specific_keysyms
;
326 static Lisp_Object Qlatin_1
;
328 /* Used in x_flush. */
330 extern Lisp_Object Vinhibit_redisplay
;
332 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
333 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
335 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
336 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
337 static const XColor
*x_color_cells
P_ ((Display
*, int *));
338 static void x_update_window_end
P_ ((struct window
*, int, int));
340 static int x_io_error_quitter
P_ ((Display
*));
341 static struct terminal
*x_create_terminal
P_ ((struct x_display_info
*));
342 void x_delete_terminal
P_ ((struct terminal
*));
343 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
344 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
345 static void x_update_end
P_ ((struct frame
*));
346 static void XTframe_up_to_date
P_ ((struct frame
*));
347 static void XTset_terminal_modes
P_ ((struct terminal
*));
348 static void XTreset_terminal_modes
P_ ((struct terminal
*));
349 static void x_clear_frame
P_ ((struct frame
*));
350 static void frame_highlight
P_ ((struct frame
*));
351 static void frame_unhighlight
P_ ((struct frame
*));
352 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
353 static void x_focus_changed
P_ ((int, int, struct x_display_info
*,
354 struct frame
*, struct input_event
*));
355 static void x_detect_focus_change
P_ ((struct x_display_info
*,
356 XEvent
*, struct input_event
*));
357 static void XTframe_rehighlight
P_ ((struct frame
*));
358 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
359 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
360 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
361 enum text_cursor_kinds
));
363 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
364 static void x_flush
P_ ((struct frame
*f
));
365 static void x_update_begin
P_ ((struct frame
*));
366 static void x_update_window_begin
P_ ((struct window
*));
367 static void x_after_update_window_line
P_ ((struct glyph_row
*));
368 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Display
*, Window
));
369 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
370 enum scroll_bar_part
*,
371 Lisp_Object
*, Lisp_Object
*,
373 static void x_check_fullscreen
P_ ((struct frame
*));
374 static void x_check_expected_move
P_ ((struct frame
*, int, int));
375 static void x_sync_with_move
P_ ((struct frame
*, int, int, int));
376 static int handle_one_xevent
P_ ((struct x_display_info
*, XEvent
*,
377 int *, struct input_event
*));
378 /* Don't declare this NO_RETURN because we want no
379 interference with debugging failing X calls. */
380 static SIGTYPE x_connection_closed
P_ ((Display
*, char *));
383 /* Flush display of frame F, or of all frames if F is null. */
389 /* Don't call XFlush when it is not safe to redisplay; the X
390 connection may be broken. */
391 if (!NILP (Vinhibit_redisplay
))
397 Lisp_Object rest
, frame
;
398 FOR_EACH_FRAME (rest
, frame
)
399 if (FRAME_X_P (XFRAME (frame
)))
400 x_flush (XFRAME (frame
));
402 else if (FRAME_X_P (f
))
403 XFlush (FRAME_X_DISPLAY (f
));
408 /* Remove calls to XFlush by defining XFlush to an empty replacement.
409 Calls to XFlush should be unnecessary because the X output buffer
410 is flushed automatically as needed by calls to XPending,
411 XNextEvent, or XWindowEvent according to the XFlush man page.
412 XTread_socket calls XPending. Removing XFlush improves
415 #define XFlush(DISPLAY) (void) 0
418 /***********************************************************************
420 ***********************************************************************/
424 /* This is a function useful for recording debugging information about
425 the sequence of occurrences in this file. */
433 struct record event_record
[100];
435 int event_record_index
;
437 record_event (locus
, type
)
441 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
442 event_record_index
= 0;
444 event_record
[event_record_index
].locus
= locus
;
445 event_record
[event_record_index
].type
= type
;
446 event_record_index
++;
453 /* Return the struct x_display_info corresponding to DPY. */
455 struct x_display_info
*
456 x_display_info_for_display (dpy
)
459 struct x_display_info
*dpyinfo
;
461 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
462 if (dpyinfo
->display
== dpy
)
470 /***********************************************************************
471 Starting and ending an update
472 ***********************************************************************/
474 /* Start an update of frame F. This function is installed as a hook
475 for update_begin, i.e. it is called when update_begin is called.
476 This function is called prior to calls to x_update_window_begin for
477 each window being updated. Currently, there is nothing to do here
478 because all interesting stuff is done on a window basis. */
488 /* Start update of window W. Set the global variable updated_window
489 to the window being updated and set output_cursor to the cursor
493 x_update_window_begin (w
)
496 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
497 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
500 set_output_cursor (&w
->cursor
);
504 if (f
== display_info
->mouse_face_mouse_frame
)
506 /* Don't do highlighting for mouse motion during the update. */
507 display_info
->mouse_face_defer
= 1;
509 /* If F needs to be redrawn, simply forget about any prior mouse
511 if (FRAME_GARBAGED_P (f
))
512 display_info
->mouse_face_window
= Qnil
;
514 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
515 their mouse_face_p flag set, which means that they are always
516 unequal to rows in a desired matrix which never have that
517 flag set. So, rows containing mouse-face glyphs are never
518 scrolled, and we don't have to switch the mouse highlight off
519 here to prevent it from being scrolled. */
521 /* Can we tell that this update does not affect the window
522 where the mouse highlight is? If so, no need to turn off.
523 Likewise, don't do anything if the frame is garbaged;
524 in that case, the frame's current matrix that we would use
525 is all wrong, and we will redisplay that line anyway. */
526 if (!NILP (display_info
->mouse_face_window
)
527 && w
== XWINDOW (display_info
->mouse_face_window
))
531 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
532 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
535 if (i
< w
->desired_matrix
->nrows
)
536 clear_mouse_face (display_info
);
545 /* Draw a vertical window border from (x,y0) to (x,y1) */
548 x_draw_vertical_window_border (w
, x
, y0
, y1
)
552 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
555 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
557 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
560 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
561 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
564 /* End update of window W (which is equal to updated_window).
566 Draw vertical borders between horizontally adjacent windows, and
567 display W's cursor if CURSOR_ON_P is non-zero.
569 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
570 glyphs in mouse-face were overwritten. In that case we have to
571 make sure that the mouse-highlight is properly redrawn.
573 W may be a menu bar pseudo-window in case we don't have X toolkit
574 support. Such windows don't have a cursor, so don't display it
578 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
580 int cursor_on_p
, mouse_face_overwritten_p
;
582 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
584 if (!w
->pseudo_window_p
)
589 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
591 output_cursor
.x
, output_cursor
.y
);
593 if (draw_window_fringes (w
, 1))
594 x_draw_vertical_border (w
);
599 /* If a row with mouse-face was overwritten, arrange for
600 XTframe_up_to_date to redisplay the mouse highlight. */
601 if (mouse_face_overwritten_p
)
603 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
604 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
605 dpyinfo
->mouse_face_window
= Qnil
;
608 updated_window
= NULL
;
612 /* End update of frame F. This function is installed as a hook in
619 /* Mouse highlight may be displayed again. */
620 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
624 XFlush (FRAME_X_DISPLAY (f
));
630 /* This function is called from various places in xdisp.c whenever a
631 complete update has been performed. The global variable
632 updated_window is not available here. */
635 XTframe_up_to_date (f
)
640 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
642 if (dpyinfo
->mouse_face_deferred_gc
643 || f
== dpyinfo
->mouse_face_mouse_frame
)
646 if (dpyinfo
->mouse_face_mouse_frame
)
647 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
648 dpyinfo
->mouse_face_mouse_x
,
649 dpyinfo
->mouse_face_mouse_y
);
650 dpyinfo
->mouse_face_deferred_gc
= 0;
657 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
658 arrow bitmaps, or clear the fringes if no bitmaps are required
659 before DESIRED_ROW is made current. The window being updated is
660 found in updated_window. This function It is called from
661 update_window_line only if it is known that there are differences
662 between bitmaps to be drawn between current row and DESIRED_ROW. */
665 x_after_update_window_line (desired_row
)
666 struct glyph_row
*desired_row
;
668 struct window
*w
= updated_window
;
674 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
675 desired_row
->redraw_fringe_bitmaps_p
= 1;
677 /* When a window has disappeared, make sure that no rest of
678 full-width rows stays visible in the internal border. Could
679 check here if updated_window is the leftmost/rightmost window,
680 but I guess it's not worth doing since vertically split windows
681 are almost never used, internal border is rarely set, and the
682 overhead is very small. */
683 if (windows_or_buffers_changed
684 && desired_row
->full_width_p
685 && (f
= XFRAME (w
->frame
),
686 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
688 && (height
= desired_row
->visible_height
,
691 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
693 /* Internal border is drawn below the tool bar. */
694 if (WINDOWP (f
->tool_bar_window
)
695 && w
== XWINDOW (f
->tool_bar_window
))
699 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
700 0, y
, width
, height
, False
);
701 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
702 FRAME_PIXEL_WIDTH (f
) - width
,
703 y
, width
, height
, False
);
709 x_draw_fringe_bitmap (w
, row
, p
)
711 struct glyph_row
*row
;
712 struct draw_fringe_bitmap_params
*p
;
714 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
715 Display
*display
= FRAME_X_DISPLAY (f
);
716 Window window
= FRAME_X_WINDOW (f
);
717 GC gc
= f
->output_data
.x
->normal_gc
;
718 struct face
*face
= p
->face
;
721 /* Must clip because of partially visible lines. */
722 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
725 /* Adjust position of "bottom aligned" bitmap on partially
728 int oldVH
= row
->visible_height
;
729 row
->visible_height
= p
->h
;
730 row
->y
-= rowY
- p
->y
;
731 x_clip_to_row (w
, row
, -1, gc
);
733 row
->visible_height
= oldVH
;
736 x_clip_to_row (w
, row
, -1, gc
);
740 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
742 /* In case the same realized face is used for fringes and
743 for something displayed in the text (e.g. face `region' on
744 mono-displays, the fill style may have been changed to
745 FillSolid in x_draw_glyph_string_background. */
747 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
749 XSetForeground (display
, face
->gc
, face
->background
);
751 #ifdef USE_TOOLKIT_SCROLL_BARS
752 /* If the fringe is adjacent to the left (right) scroll bar of a
753 leftmost (rightmost, respectively) window, then extend its
754 background to the gap between the fringe and the bar. */
755 if ((WINDOW_LEFTMOST_P (w
)
756 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
757 || (WINDOW_RIGHTMOST_P (w
)
758 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
760 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
764 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
765 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
766 * FRAME_COLUMN_WIDTH (f
));
770 /* Bitmap fills the fringe. */
771 if (left
+ width
== p
->x
)
772 bx
= left
+ sb_width
;
773 else if (p
->x
+ p
->wd
== left
)
777 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
779 nx
= width
- sb_width
;
780 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
782 ny
= row
->visible_height
;
787 if (left
+ width
== bx
)
789 bx
= left
+ sb_width
;
790 nx
+= width
- sb_width
;
792 else if (bx
+ nx
== left
)
793 nx
+= width
- sb_width
;
798 if (bx
>= 0 && nx
> 0)
799 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
802 XSetForeground (display
, face
->gc
, face
->foreground
);
808 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
809 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
813 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
815 bits
= (unsigned char *)p
->bits
+ p
->dh
;
817 /* Draw the bitmap. I believe these small pixmaps can be cached
819 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
821 ? (p
->overlay_p
? face
->background
822 : f
->output_data
.x
->cursor_pixel
)
824 face
->background
, depth
);
828 clipmask
= XCreatePixmapFromBitmapData (display
,
829 FRAME_X_DISPLAY_INFO (f
)->root_window
,
832 gcv
.clip_mask
= clipmask
;
833 gcv
.clip_x_origin
= p
->x
;
834 gcv
.clip_y_origin
= p
->y
;
835 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
838 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
839 p
->wd
, p
->h
, p
->x
, p
->y
);
840 XFreePixmap (display
, pixmap
);
844 gcv
.clip_mask
= (Pixmap
) 0;
845 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
846 XFreePixmap (display
, clipmask
);
850 XSetClipMask (display
, gc
, None
);
855 /* This is called when starting Emacs and when restarting after
856 suspend. When starting Emacs, no X window is mapped. And nothing
857 must be done to Emacs's own window if it is suspended (though that
861 XTset_terminal_modes (struct terminal
*terminal
)
865 /* This is called when exiting or suspending Emacs. Exiting will make
866 the X-windows go away, and suspending requires no action. */
869 XTreset_terminal_modes (struct terminal
*terminal
)
875 /***********************************************************************
877 ***********************************************************************/
879 /* Function prototypes of this page. */
881 static int x_encode_char
P_ ((int, XChar2b
*, struct font_info
*,
882 struct charset
*, int *));
885 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
886 is not contained in the font. */
889 x_per_char_metric (font
, char2b
, font_type
)
892 int font_type
; /* unused on X */
894 /* The result metric information. */
895 XCharStruct
*pcm
= NULL
;
897 xassert (font
&& char2b
);
899 if (font
->per_char
!= NULL
)
901 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
903 /* min_char_or_byte2 specifies the linear character index
904 corresponding to the first element of the per_char array,
905 max_char_or_byte2 is the index of the last character. A
906 character with non-zero CHAR2B->byte1 is not in the font.
907 A character with byte2 less than min_char_or_byte2 or
908 greater max_char_or_byte2 is not in the font. */
909 if (char2b
->byte1
== 0
910 && char2b
->byte2
>= font
->min_char_or_byte2
911 && char2b
->byte2
<= font
->max_char_or_byte2
)
912 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
916 /* If either min_byte1 or max_byte1 are nonzero, both
917 min_char_or_byte2 and max_char_or_byte2 are less than
918 256, and the 2-byte character index values corresponding
919 to the per_char array element N (counting from 0) are:
921 byte1 = N/D + min_byte1
922 byte2 = N\D + min_char_or_byte2
926 D = max_char_or_byte2 - min_char_or_byte2 + 1
928 \ = integer modulus */
929 if (char2b
->byte1
>= font
->min_byte1
930 && char2b
->byte1
<= font
->max_byte1
931 && char2b
->byte2
>= font
->min_char_or_byte2
932 && char2b
->byte2
<= font
->max_char_or_byte2
)
934 pcm
= (font
->per_char
935 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
936 * (char2b
->byte1
- font
->min_byte1
))
937 + (char2b
->byte2
- font
->min_char_or_byte2
));
943 /* If the per_char pointer is null, all glyphs between the first
944 and last character indexes inclusive have the same
945 information, as given by both min_bounds and max_bounds. */
946 if (char2b
->byte2
>= font
->min_char_or_byte2
947 && char2b
->byte2
<= font
->max_char_or_byte2
)
948 pcm
= &font
->max_bounds
;
952 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
957 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
958 the two-byte form of C. Encoding is returned in *CHAR2B. */
961 x_encode_char (c
, char2b
, font_info
, charset
, two_byte_p
)
964 struct font_info
*font_info
;
965 struct charset
*charset
;
968 XFontStruct
*font
= font_info
->font
;
970 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
971 This may be either a program in a special encoder language or a
973 if (font_info
->font_encoder
)
975 /* It's a program. */
976 struct ccl_program
*ccl
= font_info
->font_encoder
;
978 check_ccl_update (ccl
);
979 if (CHARSET_DIMENSION (charset
) == 1)
981 ccl
->reg
[0] = CHARSET_ID (charset
);
982 ccl
->reg
[1] = char2b
->byte2
;
987 ccl
->reg
[0] = CHARSET_ID (charset
);
988 ccl
->reg
[1] = char2b
->byte1
;
989 ccl
->reg
[2] = char2b
->byte2
;
992 ccl_driver (ccl
, NULL
, NULL
, 0, 0, Qnil
);
994 /* We assume that MSBs are appropriately set/reset by CCL
996 if (font
->max_byte1
== 0) /* 1-byte font */
997 STORE_XCHAR2B (char2b
, 0, ccl
->reg
[1]);
999 STORE_XCHAR2B (char2b
, ccl
->reg
[1], ccl
->reg
[2]);
1001 else if (font_info
->encoding_type
)
1003 /* Fixed encoding scheme. See fontset.h for the meaning of the
1004 encoding numbers. */
1005 unsigned char enc
= font_info
->encoding_type
;
1007 if ((enc
== 1 || enc
== 2)
1008 && CHARSET_DIMENSION (charset
) == 2)
1009 char2b
->byte1
|= 0x80;
1011 if (enc
== 1 || enc
== 3)
1012 char2b
->byte2
|= 0x80;
1016 *two_byte_p
= ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1018 return FONT_TYPE_UNKNOWN
;
1023 /***********************************************************************
1025 ***********************************************************************/
1029 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
1030 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
1031 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
1033 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
1034 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
1035 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
1036 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
1037 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
1038 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
1039 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
1040 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
1041 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
1042 unsigned long *, double, int));
1043 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
1044 double, int, unsigned long));
1045 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
1046 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
1047 static void x_draw_image_relief
P_ ((struct glyph_string
*));
1048 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
1049 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
1050 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
1052 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
1053 int, int, int, int, int, int,
1055 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
1056 int, int, int, XRectangle
*));
1059 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
1063 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1068 struct glyph_string
*s
;
1070 if (s
->font
== FRAME_FONT (s
->f
)
1071 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1072 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1074 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1077 /* Cursor on non-default face: must merge. */
1081 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1082 xgcv
.foreground
= s
->face
->background
;
1084 /* If the glyph would be invisible, try a different foreground. */
1085 if (xgcv
.foreground
== xgcv
.background
)
1086 xgcv
.foreground
= s
->face
->foreground
;
1087 if (xgcv
.foreground
== xgcv
.background
)
1088 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1089 if (xgcv
.foreground
== xgcv
.background
)
1090 xgcv
.foreground
= s
->face
->foreground
;
1092 /* Make sure the cursor is distinct from text in this face. */
1093 if (xgcv
.background
== s
->face
->background
1094 && xgcv
.foreground
== s
->face
->foreground
)
1096 xgcv
.background
= s
->face
->foreground
;
1097 xgcv
.foreground
= s
->face
->background
;
1100 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1101 xgcv
.font
= s
->font
->fid
;
1102 xgcv
.graphics_exposures
= False
;
1103 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1105 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1106 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1109 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1110 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1112 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1117 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1120 x_set_mouse_face_gc (s
)
1121 struct glyph_string
*s
;
1126 /* What face has to be used last for the mouse face? */
1127 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1128 face
= FACE_FROM_ID (s
->f
, face_id
);
1130 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1132 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1133 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1135 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1136 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1137 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1139 /* If font in this face is same as S->font, use it. */
1140 if (s
->font
== s
->face
->font
)
1141 s
->gc
= s
->face
->gc
;
1142 #ifdef USE_FONT_BACKEND
1143 else if (enable_font_backend
)
1144 /* No need of setting a font for s->gc. */
1145 s
->gc
= s
->face
->gc
;
1146 #endif /* USE_FONT_BACKEND */
1149 /* Otherwise construct scratch_cursor_gc with values from FACE
1154 xgcv
.background
= s
->face
->background
;
1155 xgcv
.foreground
= s
->face
->foreground
;
1156 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1157 xgcv
.font
= s
->font
->fid
;
1158 xgcv
.graphics_exposures
= False
;
1159 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
1161 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1162 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1165 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1166 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1168 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1171 xassert (s
->gc
!= 0);
1175 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1176 Faces to use in the mode line have already been computed when the
1177 matrix was built, so there isn't much to do, here. */
1180 x_set_mode_line_face_gc (s
)
1181 struct glyph_string
*s
;
1183 s
->gc
= s
->face
->gc
;
1187 /* Set S->gc of glyph string S for drawing that glyph string. Set
1188 S->stippled_p to a non-zero value if the face of S has a stipple
1192 x_set_glyph_string_gc (s
)
1193 struct glyph_string
*s
;
1195 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1197 if (s
->hl
== DRAW_NORMAL_TEXT
)
1199 s
->gc
= s
->face
->gc
;
1200 s
->stippled_p
= s
->face
->stipple
!= 0;
1202 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1204 x_set_mode_line_face_gc (s
);
1205 s
->stippled_p
= s
->face
->stipple
!= 0;
1207 else if (s
->hl
== DRAW_CURSOR
)
1209 x_set_cursor_gc (s
);
1212 else if (s
->hl
== DRAW_MOUSE_FACE
)
1214 x_set_mouse_face_gc (s
);
1215 s
->stippled_p
= s
->face
->stipple
!= 0;
1217 else if (s
->hl
== DRAW_IMAGE_RAISED
1218 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1220 s
->gc
= s
->face
->gc
;
1221 s
->stippled_p
= s
->face
->stipple
!= 0;
1225 s
->gc
= s
->face
->gc
;
1226 s
->stippled_p
= s
->face
->stipple
!= 0;
1229 /* GC must have been set. */
1230 xassert (s
->gc
!= 0);
1234 /* Set clipping for output of glyph string S. S may be part of a mode
1235 line or menu if we don't have X toolkit support. */
1238 x_set_glyph_string_clipping (s
)
1239 struct glyph_string
*s
;
1241 #ifdef USE_FONT_BACKEND
1242 XRectangle
*r
= s
->clip
;
1246 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1249 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1250 #ifdef USE_FONT_BACKEND
1256 /* Set SRC's clipping for output of glyph string DST. This is called
1257 when we are drawing DST's left_overhang or right_overhang only in
1261 x_set_glyph_string_clipping_exactly (src
, dst
)
1262 struct glyph_string
*src
, *dst
;
1266 #ifdef USE_FONT_BACKEND
1267 if (enable_font_backend
)
1270 r
.width
= src
->width
;
1272 r
.height
= src
->height
;
1278 #endif /* USE_FONT_BACKEND */
1279 struct glyph_string
*clip_head
= src
->clip_head
;
1280 struct glyph_string
*clip_tail
= src
->clip_tail
;
1282 /* This foces clipping just this glyph string. */
1283 src
->clip_head
= src
->clip_tail
= src
;
1284 get_glyph_string_clip_rect (src
, &r
);
1285 src
->clip_head
= clip_head
, src
->clip_tail
= clip_tail
;
1286 #ifdef USE_FONT_BACKEND
1288 #endif /* USE_FONT_BACKEND */
1289 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1294 Compute left and right overhang of glyph string S. */
1297 x_compute_glyph_string_overhangs (s
)
1298 struct glyph_string
*s
;
1301 && s
->first_glyph
->type
== CHAR_GLYPH
)
1304 int direction
, font_ascent
, font_descent
;
1306 #ifdef USE_FONT_BACKEND
1307 if (enable_font_backend
)
1309 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1310 struct font
*font
= (struct font
*) s
->font_info
;
1311 struct font_metrics metrics
;
1314 for (i
= 0; i
< s
->nchars
; i
++)
1315 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1316 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1317 cs
.rbearing
= metrics
.rbearing
;
1318 cs
.lbearing
= metrics
.lbearing
;
1319 cs
.width
= metrics
.width
;
1322 #endif /* USE_FONT_BACKEND */
1323 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
1324 &font_ascent
, &font_descent
, &cs
);
1325 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
1326 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
1330 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1331 s
->left_overhang
= - s
->cmp
->lbearing
;
1336 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1339 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1340 struct glyph_string
*s
;
1344 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1345 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1346 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1347 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1351 /* Draw the background of glyph_string S. If S->background_filled_p
1352 is non-zero don't draw it. FORCE_P non-zero means draw the
1353 background even if it wouldn't be drawn normally. This is used
1354 when a string preceding S draws into the background of S, or S
1355 contains the first component of a composition. */
1358 x_draw_glyph_string_background (s
, force_p
)
1359 struct glyph_string
*s
;
1362 /* Nothing to do if background has already been drawn or if it
1363 shouldn't be drawn in the first place. */
1364 if (!s
->background_filled_p
)
1366 int box_line_width
= max (s
->face
->box_line_width
, 0);
1370 /* Fill background with a stipple pattern. */
1371 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1372 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1373 s
->y
+ box_line_width
,
1374 s
->background_width
,
1375 s
->height
- 2 * box_line_width
);
1376 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1377 s
->background_filled_p
= 1;
1379 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1380 || s
->font_not_found_p
1381 || s
->extends_to_end_of_line_p
1384 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1385 s
->background_width
,
1386 s
->height
- 2 * box_line_width
);
1387 s
->background_filled_p
= 1;
1393 /* Draw the foreground of glyph string S. */
1396 x_draw_glyph_string_foreground (s
)
1397 struct glyph_string
*s
;
1401 /* If first glyph of S has a left box line, start drawing the text
1402 of S to the right of that box line. */
1403 if (s
->face
->box
!= FACE_NO_BOX
1404 && s
->first_glyph
->left_box_line_p
)
1405 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1409 /* Draw characters of S as rectangles if S's font could not be
1411 if (s
->font_not_found_p
)
1413 for (i
= 0; i
< s
->nchars
; ++i
)
1415 struct glyph
*g
= s
->first_glyph
+ i
;
1416 XDrawRectangle (s
->display
, s
->window
,
1417 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1419 x
+= g
->pixel_width
;
1422 #ifdef USE_FONT_BACKEND
1423 else if (enable_font_backend
)
1425 int boff
= s
->font_info
->baseline_offset
;
1426 struct font
*font
= (struct font
*) s
->font_info
;
1429 if (s
->font_info
->vertical_centering
)
1430 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1432 y
= s
->ybase
- boff
;
1434 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1435 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1437 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1438 if (s
->face
->overstrike
)
1439 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1441 #endif /* USE_FONT_BACKEND */
1444 char *char1b
= (char *) s
->char2b
;
1445 int boff
= s
->font_info
->baseline_offset
;
1447 if (s
->font_info
->vertical_centering
)
1448 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
1450 /* If we can use 8-bit functions, condense S->char2b. */
1452 for (i
= 0; i
< s
->nchars
; ++i
)
1453 char1b
[i
] = s
->char2b
[i
].byte2
;
1455 /* Draw text with XDrawString if background has already been
1456 filled. Otherwise, use XDrawImageString. (Note that
1457 XDrawImageString is usually faster than XDrawString.) Always
1458 use XDrawImageString when drawing the cursor so that there is
1459 no chance that characters under a box cursor are invisible. */
1461 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1463 /* Draw characters with 16-bit or 8-bit functions. */
1465 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
1466 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1468 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
1469 s
->ybase
- boff
, char1b
, s
->nchars
);
1474 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
1475 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1477 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
1478 s
->ybase
- boff
, char1b
, s
->nchars
);
1481 if (s
->face
->overstrike
)
1483 /* For overstriking (to simulate bold-face), draw the
1484 characters again shifted to the right by one pixel. */
1486 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
+ 1,
1487 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
1489 XDrawString (s
->display
, s
->window
, s
->gc
, x
+ 1,
1490 s
->ybase
- boff
, char1b
, s
->nchars
);
1495 /* Draw the foreground of composite glyph string S. */
1498 x_draw_composite_glyph_string_foreground (s
)
1499 struct glyph_string
*s
;
1503 /* If first glyph of S has a left box line, start drawing the text
1504 of S to the right of that box line. */
1505 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1506 && s
->first_glyph
->left_box_line_p
)
1507 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1511 /* S is a glyph string for a composition. S->gidx is the index of
1512 the first character drawn for glyphs of this composition.
1513 S->gidx == 0 means we are drawing the very first character of
1514 this composition. */
1516 /* Draw a rectangle for the composition if the font for the very
1517 first character of the composition could not be loaded. */
1518 if (s
->font_not_found_p
)
1521 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1522 s
->width
- 1, s
->height
- 1);
1524 #ifdef USE_FONT_BACKEND
1525 else if (enable_font_backend
)
1527 struct font
*font
= (struct font
*) s
->font_info
;
1531 if (s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
1533 Lisp_Object gstring
= AREF (XHASH_TABLE (composition_hash_table
)
1535 s
->cmp
->hash_index
* 2);
1538 for (i
= from
= 0; i
< s
->nchars
; i
++)
1540 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
1541 Lisp_Object adjustment
= LGLYPH_ADJUSTMENT (g
);
1542 int xoff
, yoff
, wadjust
;
1544 if (! VECTORP (adjustment
))
1546 width
+= LGLYPH_WIDTH (g
);
1551 font
->driver
->draw (s
, from
, i
, x
, y
, 0);
1554 xoff
= XINT (AREF (adjustment
, 0));
1555 yoff
= XINT (AREF (adjustment
, 1));
1556 wadjust
= XINT (AREF (adjustment
, 2));
1558 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1564 font
->driver
->draw (s
, from
, i
, x
, y
, 0);
1568 for (i
= 0, j
= s
->gidx
; i
< s
->nchars
; i
++, j
++)
1569 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1571 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1572 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1574 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1575 if (s
->face
->overstrike
)
1576 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1580 #endif /* USE_FONT_BACKEND */
1583 for (i
= 0, j
= s
->gidx
; i
< s
->nchars
; i
++, j
++)
1586 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1587 x
+ s
->cmp
->offsets
[j
* 2],
1588 s
->ybase
- s
->cmp
->offsets
[j
* 2 + 1],
1590 if (s
->face
->overstrike
)
1591 XDrawString16 (s
->display
, s
->window
, s
->gc
,
1592 x
+ s
->cmp
->offsets
[j
* 2] + 1,
1593 s
->ybase
- s
->cmp
->offsets
[j
* 2 + 1],
1600 #ifdef USE_X_TOOLKIT
1602 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1603 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1604 XrmValue
*, XrmValue
*, XtPointer
*));
1605 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1606 XrmValue
*, Cardinal
*));
1609 /* Return the frame on which widget WIDGET is used.. Abort if frame
1610 cannot be determined. */
1612 static struct frame
*
1613 x_frame_of_widget (widget
)
1616 struct x_display_info
*dpyinfo
;
1620 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1622 /* Find the top-level shell of the widget. Note that this function
1623 can be called when the widget is not yet realized, so XtWindow
1624 (widget) == 0. That's the reason we can't simply use
1625 x_any_window_to_frame. */
1626 while (!XtIsTopLevelShell (widget
))
1627 widget
= XtParent (widget
);
1629 /* Look for a frame with that top-level widget. Allocate the color
1630 on that frame to get the right gamma correction value. */
1631 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1632 if (FRAMEP (XCAR (tail
))
1633 && (f
= XFRAME (XCAR (tail
)),
1635 && f
->output_data
.nothing
!= 1
1636 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1637 && f
->output_data
.x
->widget
== widget
)
1644 /* Allocate the color COLOR->pixel on the screen and display of
1645 widget WIDGET in colormap CMAP. If an exact match cannot be
1646 allocated, try the nearest color available. Value is non-zero
1647 if successful. This is called from lwlib. */
1650 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1655 struct frame
*f
= x_frame_of_widget (widget
);
1656 return x_alloc_nearest_color (f
, cmap
, color
);
1660 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1661 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1662 If this produces the same color as PIXEL, try a color where all RGB
1663 values have DELTA added. Return the allocated color in *PIXEL.
1664 DISPLAY is the X display, CMAP is the colormap to operate on.
1665 Value is non-zero if successful. */
1668 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1672 unsigned long *pixel
;
1676 struct frame
*f
= x_frame_of_widget (widget
);
1677 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1681 /* Structure specifying which arguments should be passed by Xt to
1682 cvt_string_to_pixel. We want the widget's screen and colormap. */
1684 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1686 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1688 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1693 /* The address of this variable is returned by
1694 cvt_string_to_pixel. */
1696 static Pixel cvt_string_to_pixel_value
;
1699 /* Convert a color name to a pixel color.
1701 DPY is the display we are working on.
1703 ARGS is an array of *NARGS XrmValue structures holding additional
1704 information about the widget for which the conversion takes place.
1705 The contents of this array are determined by the specification
1706 in cvt_string_to_pixel_args.
1708 FROM is a pointer to an XrmValue which points to the color name to
1709 convert. TO is an XrmValue in which to return the pixel color.
1711 CLOSURE_RET is a pointer to user-data, in which we record if
1712 we allocated the color or not.
1714 Value is True if successful, False otherwise. */
1717 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1721 XrmValue
*from
, *to
;
1722 XtPointer
*closure_ret
;
1732 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1733 "wrongParameters", "cvt_string_to_pixel",
1735 "Screen and colormap args required", NULL
, NULL
);
1739 screen
= *(Screen
**) args
[0].addr
;
1740 cmap
= *(Colormap
*) args
[1].addr
;
1741 color_name
= (String
) from
->addr
;
1743 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1745 *closure_ret
= (XtPointer
) False
;
1746 pixel
= WhitePixelOfScreen (screen
);
1748 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1750 *closure_ret
= (XtPointer
) False
;
1751 pixel
= BlackPixelOfScreen (screen
);
1753 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1754 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1756 pixel
= color
.pixel
;
1757 *closure_ret
= (XtPointer
) True
;
1762 Cardinal nparams
= 1;
1764 params
[0] = color_name
;
1765 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1766 "badValue", "cvt_string_to_pixel",
1767 "XtToolkitError", "Invalid color `%s'",
1772 if (to
->addr
!= NULL
)
1774 if (to
->size
< sizeof (Pixel
))
1776 to
->size
= sizeof (Pixel
);
1780 *(Pixel
*) to
->addr
= pixel
;
1784 cvt_string_to_pixel_value
= pixel
;
1785 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1788 to
->size
= sizeof (Pixel
);
1793 /* Free a pixel color which was previously allocated via
1794 cvt_string_to_pixel. This is registered as the destructor
1795 for this type of resource via XtSetTypeConverter.
1797 APP is the application context in which we work.
1799 TO is a pointer to an XrmValue holding the color to free.
1800 CLOSURE is the value we stored in CLOSURE_RET for this color
1801 in cvt_string_to_pixel.
1803 ARGS and NARGS are like for cvt_string_to_pixel. */
1806 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1815 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1817 "Screen and colormap arguments required",
1820 else if (closure
!= NULL
)
1822 /* We did allocate the pixel, so free it. */
1823 Screen
*screen
= *(Screen
**) args
[0].addr
;
1824 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1825 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1826 (Pixel
*) to
->addr
, 1);
1831 #endif /* USE_X_TOOLKIT */
1834 /* Value is an array of XColor structures for the contents of the
1835 color map of display DPY. Set *NCELLS to the size of the array.
1836 Note that this probably shouldn't be called for large color maps,
1837 say a 24-bit TrueColor map. */
1839 static const XColor
*
1840 x_color_cells (dpy
, ncells
)
1844 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1846 if (dpyinfo
->color_cells
== NULL
)
1848 Screen
*screen
= dpyinfo
->screen
;
1851 dpyinfo
->ncolor_cells
1852 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1853 dpyinfo
->color_cells
1854 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1855 * sizeof *dpyinfo
->color_cells
);
1857 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1858 dpyinfo
->color_cells
[i
].pixel
= i
;
1860 XQueryColors (dpy
, dpyinfo
->cmap
,
1861 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1864 *ncells
= dpyinfo
->ncolor_cells
;
1865 return dpyinfo
->color_cells
;
1869 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1870 colors in COLORS. Use cached information, if available. */
1873 x_query_colors (f
, colors
, ncolors
)
1878 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1880 if (dpyinfo
->color_cells
)
1883 for (i
= 0; i
< ncolors
; ++i
)
1885 unsigned long pixel
= colors
[i
].pixel
;
1886 xassert (pixel
< dpyinfo
->ncolor_cells
);
1887 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1888 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1892 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1896 /* On frame F, translate pixel color to RGB values for the color in
1897 COLOR. Use cached information, if available. */
1900 x_query_color (f
, color
)
1904 x_query_colors (f
, color
, 1);
1908 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1909 exact match can't be allocated, try the nearest color available.
1910 Value is non-zero if successful. Set *COLOR to the color
1914 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1921 rc
= XAllocColor (dpy
, cmap
, color
);
1924 /* If we got to this point, the colormap is full, so we're going
1925 to try to get the next closest color. The algorithm used is
1926 a least-squares matching, which is what X uses for closest
1927 color matching with StaticColor visuals. */
1929 unsigned long nearest_delta
= ~0;
1931 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1933 for (nearest
= i
= 0; i
< ncells
; ++i
)
1935 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1936 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1937 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1938 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1940 if (delta
< nearest_delta
)
1943 nearest_delta
= delta
;
1947 color
->red
= cells
[nearest
].red
;
1948 color
->green
= cells
[nearest
].green
;
1949 color
->blue
= cells
[nearest
].blue
;
1950 rc
= XAllocColor (dpy
, cmap
, color
);
1954 /* If allocation succeeded, and the allocated pixel color is not
1955 equal to a cached pixel color recorded earlier, there was a
1956 change in the colormap, so clear the color cache. */
1957 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1958 XColor
*cached_color
;
1960 if (dpyinfo
->color_cells
1961 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1962 (cached_color
->red
!= color
->red
1963 || cached_color
->blue
!= color
->blue
1964 || cached_color
->green
!= color
->green
)))
1966 xfree (dpyinfo
->color_cells
);
1967 dpyinfo
->color_cells
= NULL
;
1968 dpyinfo
->ncolor_cells
= 0;
1972 #ifdef DEBUG_X_COLORS
1974 register_color (color
->pixel
);
1975 #endif /* DEBUG_X_COLORS */
1981 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1982 exact match can't be allocated, try the nearest color available.
1983 Value is non-zero if successful. Set *COLOR to the color
1987 x_alloc_nearest_color (f
, cmap
, color
)
1992 gamma_correct (f
, color
);
1993 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1997 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1998 It's necessary to do this instead of just using PIXEL directly to
1999 get color reference counts right. */
2002 x_copy_color (f
, pixel
)
2004 unsigned long pixel
;
2008 color
.pixel
= pixel
;
2010 x_query_color (f
, &color
);
2011 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2013 #ifdef DEBUG_X_COLORS
2014 register_color (pixel
);
2020 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
2021 It's necessary to do this instead of just using PIXEL directly to
2022 get color reference counts right. */
2025 x_copy_dpy_color (dpy
, cmap
, pixel
)
2028 unsigned long pixel
;
2032 color
.pixel
= pixel
;
2034 XQueryColor (dpy
, cmap
, &color
);
2035 XAllocColor (dpy
, cmap
, &color
);
2037 #ifdef DEBUG_X_COLORS
2038 register_color (pixel
);
2044 /* Brightness beyond which a color won't have its highlight brightness
2047 Nominally, highlight colors for `3d' faces are calculated by
2048 brightening an object's color by a constant scale factor, but this
2049 doesn't yield good results for dark colors, so for colors who's
2050 brightness is less than this value (on a scale of 0-65535) have an
2051 use an additional additive factor.
2053 The value here is set so that the default menu-bar/mode-line color
2054 (grey75) will not have its highlights changed at all. */
2055 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
2058 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
2059 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2060 If this produces the same color as PIXEL, try a color where all RGB
2061 values have DELTA added. Return the allocated color in *PIXEL.
2062 DISPLAY is the X display, CMAP is the colormap to operate on.
2063 Value is non-zero if successful. */
2066 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
2070 unsigned long *pixel
;
2078 /* Get RGB color values. */
2079 color
.pixel
= *pixel
;
2080 x_query_color (f
, &color
);
2082 /* Change RGB values by specified FACTOR. Avoid overflow! */
2083 xassert (factor
>= 0);
2084 new.red
= min (0xffff, factor
* color
.red
);
2085 new.green
= min (0xffff, factor
* color
.green
);
2086 new.blue
= min (0xffff, factor
* color
.blue
);
2088 /* Calculate brightness of COLOR. */
2089 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
2091 /* We only boost colors that are darker than
2092 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2093 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2094 /* Make an additive adjustment to NEW, because it's dark enough so
2095 that scaling by FACTOR alone isn't enough. */
2097 /* How far below the limit this color is (0 - 1, 1 being darker). */
2098 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2099 /* The additive adjustment. */
2100 int min_delta
= delta
* dimness
* factor
/ 2;
2104 new.red
= max (0, new.red
- min_delta
);
2105 new.green
= max (0, new.green
- min_delta
);
2106 new.blue
= max (0, new.blue
- min_delta
);
2110 new.red
= min (0xffff, min_delta
+ new.red
);
2111 new.green
= min (0xffff, min_delta
+ new.green
);
2112 new.blue
= min (0xffff, min_delta
+ new.blue
);
2116 /* Try to allocate the color. */
2117 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2120 if (new.pixel
== *pixel
)
2122 /* If we end up with the same color as before, try adding
2123 delta to the RGB values. */
2124 x_free_colors (f
, &new.pixel
, 1);
2126 new.red
= min (0xffff, delta
+ color
.red
);
2127 new.green
= min (0xffff, delta
+ color
.green
);
2128 new.blue
= min (0xffff, delta
+ color
.blue
);
2129 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2140 /* Set up the foreground color for drawing relief lines of glyph
2141 string S. RELIEF is a pointer to a struct relief containing the GC
2142 with which lines will be drawn. Use a color that is FACTOR or
2143 DELTA lighter or darker than the relief's background which is found
2144 in S->f->output_data.x->relief_background. If such a color cannot
2145 be allocated, use DEFAULT_PIXEL, instead. */
2148 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
2150 struct relief
*relief
;
2153 unsigned long default_pixel
;
2156 struct x_output
*di
= f
->output_data
.x
;
2157 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
2158 unsigned long pixel
;
2159 unsigned long background
= di
->relief_background
;
2160 Colormap cmap
= FRAME_X_COLORMAP (f
);
2161 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2162 Display
*dpy
= FRAME_X_DISPLAY (f
);
2164 xgcv
.graphics_exposures
= False
;
2165 xgcv
.line_width
= 1;
2167 /* Free previously allocated color. The color cell will be reused
2168 when it has been freed as many times as it was allocated, so this
2169 doesn't affect faces using the same colors. */
2171 && relief
->allocated_p
)
2173 x_free_colors (f
, &relief
->pixel
, 1);
2174 relief
->allocated_p
= 0;
2177 /* Allocate new color. */
2178 xgcv
.foreground
= default_pixel
;
2180 if (dpyinfo
->n_planes
!= 1
2181 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
2183 relief
->allocated_p
= 1;
2184 xgcv
.foreground
= relief
->pixel
= pixel
;
2187 if (relief
->gc
== 0)
2189 xgcv
.stipple
= dpyinfo
->gray
;
2191 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
2194 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
2198 /* Set up colors for the relief lines around glyph string S. */
2201 x_setup_relief_colors (s
)
2202 struct glyph_string
*s
;
2204 struct x_output
*di
= s
->f
->output_data
.x
;
2205 unsigned long color
;
2207 if (s
->face
->use_box_color_for_shadows_p
)
2208 color
= s
->face
->box_color
;
2209 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2211 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2212 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2217 /* Get the background color of the face. */
2218 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2219 color
= xgcv
.background
;
2222 if (di
->white_relief
.gc
== 0
2223 || color
!= di
->relief_background
)
2225 di
->relief_background
= color
;
2226 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2227 WHITE_PIX_DEFAULT (s
->f
));
2228 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2229 BLACK_PIX_DEFAULT (s
->f
));
2234 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2235 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2236 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2237 relief. LEFT_P non-zero means draw a relief on the left side of
2238 the rectangle. RIGHT_P non-zero means draw a relief on the right
2239 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2243 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2244 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2246 int left_x
, top_y
, right_x
, bottom_y
, width
;
2247 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2248 XRectangle
*clip_rect
;
2250 Display
*dpy
= FRAME_X_DISPLAY (f
);
2251 Window window
= FRAME_X_WINDOW (f
);
2256 gc
= f
->output_data
.x
->white_relief
.gc
;
2258 gc
= f
->output_data
.x
->black_relief
.gc
;
2259 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2263 for (i
= 0; i
< width
; ++i
)
2264 XDrawLine (dpy
, window
, gc
,
2265 left_x
+ i
* left_p
, top_y
+ i
,
2266 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2270 for (i
= 0; i
< width
; ++i
)
2271 XDrawLine (dpy
, window
, gc
,
2272 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2274 XSetClipMask (dpy
, gc
, None
);
2276 gc
= f
->output_data
.x
->black_relief
.gc
;
2278 gc
= f
->output_data
.x
->white_relief
.gc
;
2279 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2283 for (i
= 0; i
< width
; ++i
)
2284 XDrawLine (dpy
, window
, gc
,
2285 left_x
+ i
* left_p
, bottom_y
- i
,
2286 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2290 for (i
= 0; i
< width
; ++i
)
2291 XDrawLine (dpy
, window
, gc
,
2292 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2294 XSetClipMask (dpy
, gc
, None
);
2298 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2299 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2300 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2301 left side of the rectangle. RIGHT_P non-zero means draw a line
2302 on the right side of the rectangle. CLIP_RECT is the clipping
2303 rectangle to use when drawing. */
2306 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2307 left_p
, right_p
, clip_rect
)
2308 struct glyph_string
*s
;
2309 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2310 XRectangle
*clip_rect
;
2314 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2315 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2316 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2319 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2320 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2324 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2325 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2328 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2329 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2333 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2334 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2336 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2337 XSetClipMask (s
->display
, s
->gc
, None
);
2341 /* Draw a box around glyph string S. */
2344 x_draw_glyph_string_box (s
)
2345 struct glyph_string
*s
;
2347 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2348 int left_p
, right_p
;
2349 struct glyph
*last_glyph
;
2350 XRectangle clip_rect
;
2352 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2353 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2354 : window_box_right (s
->w
, s
->area
));
2356 /* The glyph that may have a right box line. */
2357 last_glyph
= (s
->cmp
|| s
->img
2359 : s
->first_glyph
+ s
->nchars
- 1);
2361 width
= eabs (s
->face
->box_line_width
);
2362 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2364 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2366 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2368 bottom_y
= top_y
+ s
->height
- 1;
2370 left_p
= (s
->first_glyph
->left_box_line_p
2371 || (s
->hl
== DRAW_MOUSE_FACE
2373 || s
->prev
->hl
!= s
->hl
)));
2374 right_p
= (last_glyph
->right_box_line_p
2375 || (s
->hl
== DRAW_MOUSE_FACE
2377 || s
->next
->hl
!= s
->hl
)));
2379 get_glyph_string_clip_rect (s
, &clip_rect
);
2381 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2382 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2383 left_p
, right_p
, &clip_rect
);
2386 x_setup_relief_colors (s
);
2387 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2388 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2393 /* Draw foreground of image glyph string S. */
2396 x_draw_image_foreground (s
)
2397 struct glyph_string
*s
;
2400 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2402 /* If first glyph of S has a left box line, start drawing it to the
2403 right of that line. */
2404 if (s
->face
->box
!= FACE_NO_BOX
2405 && s
->first_glyph
->left_box_line_p
2407 x
+= eabs (s
->face
->box_line_width
);
2409 /* If there is a margin around the image, adjust x- and y-position
2411 if (s
->slice
.x
== 0)
2412 x
+= s
->img
->hmargin
;
2413 if (s
->slice
.y
== 0)
2414 y
+= s
->img
->vmargin
;
2420 /* We can't set both a clip mask and use XSetClipRectangles
2421 because the latter also sets a clip mask. We also can't
2422 trust on the shape extension to be available
2423 (XShapeCombineRegion). So, compute the rectangle to draw
2425 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2428 XRectangle clip_rect
, image_rect
, r
;
2430 xgcv
.clip_mask
= s
->img
->mask
;
2431 xgcv
.clip_x_origin
= x
;
2432 xgcv
.clip_y_origin
= y
;
2433 xgcv
.function
= GXcopy
;
2434 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2436 get_glyph_string_clip_rect (s
, &clip_rect
);
2439 image_rect
.width
= s
->slice
.width
;
2440 image_rect
.height
= s
->slice
.height
;
2441 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2442 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2443 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2444 r
.width
, r
.height
, r
.x
, r
.y
);
2448 XRectangle clip_rect
, image_rect
, r
;
2450 get_glyph_string_clip_rect (s
, &clip_rect
);
2453 image_rect
.width
= s
->slice
.width
;
2454 image_rect
.height
= s
->slice
.height
;
2455 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2456 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2457 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2458 r
.width
, r
.height
, r
.x
, r
.y
);
2460 /* When the image has a mask, we can expect that at
2461 least part of a mouse highlight or a block cursor will
2462 be visible. If the image doesn't have a mask, make
2463 a block cursor visible by drawing a rectangle around
2464 the image. I believe it's looking better if we do
2465 nothing here for mouse-face. */
2466 if (s
->hl
== DRAW_CURSOR
)
2468 int r
= s
->img
->relief
;
2470 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2472 s
->slice
.width
+ r
*2 - 1,
2473 s
->slice
.height
+ r
*2 - 1);
2478 /* Draw a rectangle if image could not be loaded. */
2479 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2480 s
->slice
.width
- 1, s
->slice
.height
- 1);
2484 /* Draw a relief around the image glyph string S. */
2487 x_draw_image_relief (s
)
2488 struct glyph_string
*s
;
2490 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2493 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2495 /* If first glyph of S has a left box line, start drawing it to the
2496 right of that line. */
2497 if (s
->face
->box
!= FACE_NO_BOX
2498 && s
->first_glyph
->left_box_line_p
2500 x
+= eabs (s
->face
->box_line_width
);
2502 /* If there is a margin around the image, adjust x- and y-position
2504 if (s
->slice
.x
== 0)
2505 x
+= s
->img
->hmargin
;
2506 if (s
->slice
.y
== 0)
2507 y
+= s
->img
->vmargin
;
2509 if (s
->hl
== DRAW_IMAGE_SUNKEN
2510 || s
->hl
== DRAW_IMAGE_RAISED
)
2512 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2513 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2517 thick
= eabs (s
->img
->relief
);
2518 raised_p
= s
->img
->relief
> 0;
2523 x1
= x
+ s
->slice
.width
+ thick
- 1;
2524 y1
= y
+ s
->slice
.height
+ thick
- 1;
2526 x_setup_relief_colors (s
);
2527 get_glyph_string_clip_rect (s
, &r
);
2528 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2530 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2532 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2537 /* Draw the foreground of image glyph string S to PIXMAP. */
2540 x_draw_image_foreground_1 (s
, pixmap
)
2541 struct glyph_string
*s
;
2545 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2547 /* If first glyph of S has a left box line, start drawing it to the
2548 right of that line. */
2549 if (s
->face
->box
!= FACE_NO_BOX
2550 && s
->first_glyph
->left_box_line_p
2552 x
+= eabs (s
->face
->box_line_width
);
2554 /* If there is a margin around the image, adjust x- and y-position
2556 if (s
->slice
.x
== 0)
2557 x
+= s
->img
->hmargin
;
2558 if (s
->slice
.y
== 0)
2559 y
+= s
->img
->vmargin
;
2565 /* We can't set both a clip mask and use XSetClipRectangles
2566 because the latter also sets a clip mask. We also can't
2567 trust on the shape extension to be available
2568 (XShapeCombineRegion). So, compute the rectangle to draw
2570 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2574 xgcv
.clip_mask
= s
->img
->mask
;
2575 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2576 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2577 xgcv
.function
= GXcopy
;
2578 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2580 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2581 s
->slice
.x
, s
->slice
.y
,
2582 s
->slice
.width
, s
->slice
.height
, x
, y
);
2583 XSetClipMask (s
->display
, s
->gc
, None
);
2587 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2588 s
->slice
.x
, s
->slice
.y
,
2589 s
->slice
.width
, s
->slice
.height
, x
, y
);
2591 /* When the image has a mask, we can expect that at
2592 least part of a mouse highlight or a block cursor will
2593 be visible. If the image doesn't have a mask, make
2594 a block cursor visible by drawing a rectangle around
2595 the image. I believe it's looking better if we do
2596 nothing here for mouse-face. */
2597 if (s
->hl
== DRAW_CURSOR
)
2599 int r
= s
->img
->relief
;
2601 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2602 s
->slice
.width
+ r
*2 - 1,
2603 s
->slice
.height
+ r
*2 - 1);
2608 /* Draw a rectangle if image could not be loaded. */
2609 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2610 s
->slice
.width
- 1, s
->slice
.height
- 1);
2614 /* Draw part of the background of glyph string S. X, Y, W, and H
2615 give the rectangle to draw. */
2618 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2619 struct glyph_string
*s
;
2624 /* Fill background with a stipple pattern. */
2625 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2626 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2627 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2630 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2634 /* Draw image glyph string S.
2637 s->x +-------------------------
2640 | +-------------------------
2643 | | +-------------------
2649 x_draw_image_glyph_string (s
)
2650 struct glyph_string
*s
;
2652 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2653 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2655 Pixmap pixmap
= None
;
2658 if (s
->slice
.y
== 0)
2659 height
-= box_line_vwidth
;
2660 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2661 height
-= box_line_vwidth
;
2663 /* Fill background with face under the image. Do it only if row is
2664 taller than image or if image has a clip mask to reduce
2666 s
->stippled_p
= s
->face
->stipple
!= 0;
2667 if (height
> s
->slice
.height
2671 || s
->img
->pixmap
== 0
2672 || s
->width
!= s
->background_width
)
2676 /* Create a pixmap as large as the glyph string. Fill it
2677 with the background color. Copy the image to it, using
2678 its mask. Copy the temporary pixmap to the display. */
2679 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2680 int depth
= DefaultDepthOfScreen (screen
);
2682 /* Create a pixmap as large as the glyph string. */
2683 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2684 s
->background_width
,
2687 /* Don't clip in the following because we're working on the
2689 XSetClipMask (s
->display
, s
->gc
, None
);
2691 /* Fill the pixmap with the background color/stipple. */
2694 /* Fill background with a stipple pattern. */
2695 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2696 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2697 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2698 0, 0, s
->background_width
, s
->height
);
2699 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2700 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2705 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2707 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2708 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2709 0, 0, s
->background_width
, s
->height
);
2710 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2718 if (s
->first_glyph
->left_box_line_p
2720 x
+= box_line_hwidth
;
2722 if (s
->slice
.y
== 0)
2723 y
+= box_line_vwidth
;
2725 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2728 s
->background_filled_p
= 1;
2731 /* Draw the foreground. */
2734 x_draw_image_foreground_1 (s
, pixmap
);
2735 x_set_glyph_string_clipping (s
);
2736 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2737 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2738 XFreePixmap (s
->display
, pixmap
);
2741 x_draw_image_foreground (s
);
2743 /* If we must draw a relief around the image, do it. */
2745 || s
->hl
== DRAW_IMAGE_RAISED
2746 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2747 x_draw_image_relief (s
);
2751 /* Draw stretch glyph string S. */
2754 x_draw_stretch_glyph_string (s
)
2755 struct glyph_string
*s
;
2757 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2759 if (s
->hl
== DRAW_CURSOR
2760 && !x_stretch_cursor_p
)
2762 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2763 as wide as the stretch glyph. */
2764 int width
, background_width
= s
->background_width
;
2765 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2769 background_width
-= left_x
- x
;
2772 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2775 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2777 /* Clear rest using the GC of the original non-cursor face. */
2778 if (width
< background_width
)
2781 int w
= background_width
- width
, h
= s
->height
;
2786 if (s
->row
->mouse_face_p
2787 && cursor_in_mouse_face_p (s
->w
))
2789 x_set_mouse_face_gc (s
);
2795 get_glyph_string_clip_rect (s
, &r
);
2796 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2798 if (s
->face
->stipple
)
2800 /* Fill background with a stipple pattern. */
2801 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2802 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2803 XSetFillStyle (s
->display
, gc
, FillSolid
);
2808 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2809 XSetForeground (s
->display
, gc
, xgcv
.background
);
2810 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2811 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2815 else if (!s
->background_filled_p
)
2817 int background_width
= s
->background_width
;
2818 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2820 /* Don't draw into left margin, fringe or scrollbar area
2821 except for header line and mode line. */
2822 if (x
< left_x
&& !s
->row
->mode_line_p
)
2824 background_width
-= left_x
- x
;
2827 if (background_width
> 0)
2828 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2831 s
->background_filled_p
= 1;
2835 /* Draw glyph string S. */
2838 x_draw_glyph_string (s
)
2839 struct glyph_string
*s
;
2841 int relief_drawn_p
= 0;
2843 /* If S draws into the background of its successors, draw the
2844 background of the successors first so that S can draw into it.
2845 This makes S->next use XDrawString instead of XDrawImageString. */
2846 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2849 struct glyph_string
*next
;
2851 for (width
= 0, next
= s
->next
; next
;
2852 width
+= next
->width
, next
= next
->next
)
2853 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2855 x_set_glyph_string_gc (next
);
2856 x_set_glyph_string_clipping (next
);
2857 x_draw_glyph_string_background (next
, 1);
2858 #ifdef USE_FONT_BACKEND
2859 next
->num_clips
= 0;
2860 #endif /* USE_FONT_BACKEND */
2864 /* Set up S->gc, set clipping and draw S. */
2865 x_set_glyph_string_gc (s
);
2867 /* Draw relief (if any) in advance for char/composition so that the
2868 glyph string can be drawn over it. */
2869 if (!s
->for_overlaps
2870 && s
->face
->box
!= FACE_NO_BOX
2871 && (s
->first_glyph
->type
== CHAR_GLYPH
2872 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2875 x_set_glyph_string_clipping (s
);
2876 x_draw_glyph_string_background (s
, 1);
2877 x_draw_glyph_string_box (s
);
2878 x_set_glyph_string_clipping (s
);
2881 else if ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2882 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
))
2883 /* We must clip just this glyph. left_overhang part has already
2884 drawn when s->prev was drawn, and right_overhang part will be
2885 drawn later when s->next is drawn. */
2886 x_set_glyph_string_clipping_exactly (s
, s
);
2888 x_set_glyph_string_clipping (s
);
2890 switch (s
->first_glyph
->type
)
2893 x_draw_image_glyph_string (s
);
2897 x_draw_stretch_glyph_string (s
);
2901 if (s
->for_overlaps
)
2902 s
->background_filled_p
= 1;
2904 x_draw_glyph_string_background (s
, 0);
2905 x_draw_glyph_string_foreground (s
);
2908 case COMPOSITE_GLYPH
:
2909 if (s
->for_overlaps
|| s
->gidx
> 0)
2910 s
->background_filled_p
= 1;
2912 x_draw_glyph_string_background (s
, 1);
2913 x_draw_composite_glyph_string_foreground (s
);
2920 if (!s
->for_overlaps
)
2922 /* Draw underline. */
2923 if (s
->face
->underline_p
)
2925 unsigned long tem
, h
;
2928 /* Get the underline thickness. Default is 1 pixel. */
2929 #ifdef USE_FONT_BACKEND
2930 if (enable_font_backend
)
2931 /* In the future, we must use information of font. */
2934 #endif /* USE_FONT_BACKEND */
2935 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
2938 #ifdef USE_FONT_BACKEND
2939 if (enable_font_backend
)
2942 /* In the future, we must use information of font. */
2943 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2945 y
= s
->y
+ s
->height
- h
;
2950 y
= s
->y
+ s
->height
- h
;
2951 if (!x_underline_at_descent_line
)
2953 /* Get the underline position. This is the recommended
2954 vertical offset in pixels from the baseline to the top of
2955 the underline. This is a signed value according to the
2956 specs, and its default is
2958 ROUND ((maximum descent) / 2), with
2959 ROUND(x) = floor (x + 0.5) */
2961 if (x_use_underline_position_properties
2962 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
2963 y
= s
->ybase
+ (long) tem
;
2964 else if (s
->face
->font
)
2965 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
2969 if (s
->face
->underline_defaulted_p
)
2970 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2971 s
->x
, y
, s
->background_width
, h
);
2975 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2976 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2977 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2978 s
->x
, y
, s
->background_width
, h
);
2979 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2983 /* Draw overline. */
2984 if (s
->face
->overline_p
)
2986 unsigned long dy
= 0, h
= 1;
2988 if (s
->face
->overline_color_defaulted_p
)
2989 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2990 s
->background_width
, h
);
2994 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2995 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2996 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2997 s
->background_width
, h
);
2998 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3002 /* Draw strike-through. */
3003 if (s
->face
->strike_through_p
)
3005 unsigned long h
= 1;
3006 unsigned long dy
= (s
->height
- h
) / 2;
3008 if (s
->face
->strike_through_color_defaulted_p
)
3009 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3014 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3015 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3016 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
3018 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3022 /* Draw relief if not yet drawn. */
3023 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3024 x_draw_glyph_string_box (s
);
3028 struct glyph_string
*prev
;
3030 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
3031 if (prev
->hl
!= s
->hl
3032 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
3034 /* As prev was drawn while clipped to its own area, we
3035 must draw the right_overhang part using s->hl now. */
3036 enum draw_glyphs_face save
= prev
->hl
;
3039 x_set_glyph_string_gc (prev
);
3040 x_set_glyph_string_clipping_exactly (s
, prev
);
3041 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
3042 x_draw_glyph_string_foreground (prev
);
3044 x_draw_composite_glyph_string_foreground (prev
);
3045 XSetClipMask (prev
->display
, prev
->gc
, None
);
3047 #ifdef USE_FONT_BACKEND
3048 prev
->num_clips
= 0;
3049 #endif /* USE_FONT_BACKEND */
3055 struct glyph_string
*next
;
3057 for (next
= s
->next
; next
; next
= next
->next
)
3058 if (next
->hl
!= s
->hl
3059 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
3061 /* As next will be drawn while clipped to its own area,
3062 we must draw the left_overhang part using s->hl now. */
3063 enum draw_glyphs_face save
= next
->hl
;
3066 x_set_glyph_string_gc (next
);
3067 x_set_glyph_string_clipping_exactly (s
, next
);
3068 if (next
->first_glyph
->type
== CHAR_GLYPH
)
3069 x_draw_glyph_string_foreground (next
);
3071 x_draw_composite_glyph_string_foreground (next
);
3072 XSetClipMask (next
->display
, next
->gc
, None
);
3074 #ifdef USE_FONT_BACKEND
3075 next
->num_clips
= 0;
3076 #endif /* USE_FONT_BACKEND */
3081 /* Reset clipping. */
3082 XSetClipMask (s
->display
, s
->gc
, None
);
3083 #ifdef USE_FONT_BACKEND
3085 #endif /* USE_FONT_BACKEND */
3088 /* Shift display to make room for inserted glyphs. */
3091 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
3093 int x
, y
, width
, height
, shift_by
;
3095 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3096 f
->output_data
.x
->normal_gc
,
3097 x
, y
, width
, height
,
3101 /* Delete N glyphs at the nominal cursor position. Not implemented
3105 x_delete_glyphs (f
, n
)
3113 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
3114 If they are <= 0, this is probably an error. */
3117 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
3124 xassert (width
> 0 && height
> 0);
3125 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
3129 /* Clear an entire frame. */
3132 x_clear_frame (struct frame
*f
)
3134 /* Clearing the frame will erase any cursor, so mark them all as no
3136 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3137 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3138 output_cursor
.x
= -1;
3140 /* We don't set the output cursor here because there will always
3141 follow an explicit cursor_to. */
3143 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
3145 /* We have to clear the scroll bars, too. If we have changed
3146 colors or something like that, then they should be notified. */
3147 x_scroll_bar_clear (f
);
3149 XFlush (FRAME_X_DISPLAY (f
));
3156 /* Invert the middle quarter of the frame for .15 sec. */
3158 /* We use the select system call to do the waiting, so we have to make
3159 sure it's available. If it isn't, we just won't do visual bells. */
3161 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3164 /* Subtract the `struct timeval' values X and Y, storing the result in
3165 *RESULT. Return 1 if the difference is negative, otherwise 0. */
3168 timeval_subtract (result
, x
, y
)
3169 struct timeval
*result
, x
, y
;
3171 /* Perform the carry for the later subtraction by updating y. This
3172 is safer because on some systems the tv_sec member is unsigned. */
3173 if (x
.tv_usec
< y
.tv_usec
)
3175 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
3176 y
.tv_usec
-= 1000000 * nsec
;
3180 if (x
.tv_usec
- y
.tv_usec
> 1000000)
3182 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
3183 y
.tv_usec
+= 1000000 * nsec
;
3187 /* Compute the time remaining to wait. tv_usec is certainly
3189 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
3190 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3192 /* Return indication of whether the result should be considered
3194 return x
.tv_sec
< y
.tv_sec
;
3206 /* Create a GC that will use the GXxor function to flip foreground
3207 pixels into background pixels. */
3211 values
.function
= GXxor
;
3212 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3213 ^ FRAME_BACKGROUND_PIXEL (f
));
3215 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3216 GCFunction
| GCForeground
, &values
);
3220 /* Get the height not including a menu bar widget. */
3221 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3222 /* Height of each line to flash. */
3223 int flash_height
= FRAME_LINE_HEIGHT (f
);
3224 /* These will be the left and right margins of the rectangles. */
3225 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3226 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3230 /* Don't flash the area between a scroll bar and the frame
3231 edge it is next to. */
3232 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3234 case vertical_scroll_bar_left
:
3235 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3238 case vertical_scroll_bar_right
:
3239 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3246 width
= flash_right
- flash_left
;
3248 /* If window is tall, flash top and bottom line. */
3249 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3251 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3253 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3254 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3255 width
, flash_height
);
3256 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3258 (height
- flash_height
3259 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3260 width
, flash_height
);
3263 /* If it is short, flash it all. */
3264 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3265 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3266 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3271 struct timeval wakeup
;
3273 EMACS_GET_TIME (wakeup
);
3275 /* Compute time to wait until, propagating carry from usecs. */
3276 wakeup
.tv_usec
+= 150000;
3277 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3278 wakeup
.tv_usec
%= 1000000;
3280 /* Keep waiting until past the time wakeup or any input gets
3282 while (! detect_input_pending ())
3284 struct timeval current
;
3285 struct timeval timeout
;
3287 EMACS_GET_TIME (current
);
3289 /* Break if result would be negative. */
3290 if (timeval_subtract (¤t
, wakeup
, current
))
3293 /* How long `select' should wait. */
3295 timeout
.tv_usec
= 10000;
3297 /* Try to wait that long--but we might wake up sooner. */
3298 select (0, NULL
, NULL
, NULL
, &timeout
);
3302 /* If window is tall, flash top and bottom line. */
3303 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3305 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3307 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3308 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3309 width
, flash_height
);
3310 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3312 (height
- flash_height
3313 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3314 width
, flash_height
);
3317 /* If it is short, flash it all. */
3318 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3319 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3320 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3322 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3330 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3333 /* Make audible bell. */
3338 struct frame
*f
= SELECTED_FRAME ();
3340 if (FRAME_X_DISPLAY (f
))
3342 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3349 XBell (FRAME_X_DISPLAY (f
), 0);
3350 XFlush (FRAME_X_DISPLAY (f
));
3357 /* Specify how many text lines, from the top of the window,
3358 should be affected by insert-lines and delete-lines operations.
3359 This, and those operations, are used only within an update
3360 that is bounded by calls to x_update_begin and x_update_end. */
3363 XTset_terminal_window (n
)
3366 /* This function intentionally left blank. */
3371 /***********************************************************************
3373 ***********************************************************************/
3375 /* Perform an insert-lines or delete-lines operation, inserting N
3376 lines or deleting -N lines at vertical position VPOS. */
3379 x_ins_del_lines (f
, vpos
, n
)
3387 /* Scroll part of the display as described by RUN. */
3390 x_scroll_run (w
, run
)
3394 struct frame
*f
= XFRAME (w
->frame
);
3395 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3397 /* Get frame-relative bounding box of the text display area of W,
3398 without mode lines. Include in this box the left and right
3400 window_box (w
, -1, &x
, &y
, &width
, &height
);
3402 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3403 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3404 bottom_y
= y
+ height
;
3408 /* Scrolling up. Make sure we don't copy part of the mode
3409 line at the bottom. */
3410 if (from_y
+ run
->height
> bottom_y
)
3411 height
= bottom_y
- from_y
;
3413 height
= run
->height
;
3417 /* Scolling down. Make sure we don't copy over the mode line.
3419 if (to_y
+ run
->height
> bottom_y
)
3420 height
= bottom_y
- to_y
;
3422 height
= run
->height
;
3427 /* Cursor off. Will be switched on again in x_update_window_end. */
3431 XCopyArea (FRAME_X_DISPLAY (f
),
3432 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3433 f
->output_data
.x
->normal_gc
,
3443 /***********************************************************************
3445 ***********************************************************************/
3452 /* We used to only do this if Vx_no_window_manager was non-nil, but
3453 the ICCCM (section 4.1.6) says that the window's border pixmap
3454 and border pixel are window attributes which are "private to the
3455 client", so we can always change it to whatever we want. */
3457 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3458 f
->output_data
.x
->border_pixel
);
3460 x_update_cursor (f
, 1);
3464 frame_unhighlight (f
)
3467 /* We used to only do this if Vx_no_window_manager was non-nil, but
3468 the ICCCM (section 4.1.6) says that the window's border pixmap
3469 and border pixel are window attributes which are "private to the
3470 client", so we can always change it to whatever we want. */
3472 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3473 f
->output_data
.x
->border_tile
);
3475 x_update_cursor (f
, 1);
3478 /* The focus has changed. Update the frames as necessary to reflect
3479 the new situation. Note that we can't change the selected frame
3480 here, because the Lisp code we are interrupting might become confused.
3481 Each event gets marked with the frame in which it occurred, so the
3482 Lisp code can tell when the switch took place by examining the events. */
3485 x_new_focus_frame (dpyinfo
, frame
)
3486 struct x_display_info
*dpyinfo
;
3487 struct frame
*frame
;
3489 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3491 if (frame
!= dpyinfo
->x_focus_frame
)
3493 /* Set this before calling other routines, so that they see
3494 the correct value of x_focus_frame. */
3495 dpyinfo
->x_focus_frame
= frame
;
3497 if (old_focus
&& old_focus
->auto_lower
)
3498 x_lower_frame (old_focus
);
3501 selected_frame
= frame
;
3502 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3504 Fselect_window (selected_frame
->selected_window
, Qnil
);
3505 choose_minibuf_frame ();
3508 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3509 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3511 pending_autoraise_frame
= 0;
3514 x_frame_rehighlight (dpyinfo
);
3517 /* Handle FocusIn and FocusOut state changes for FRAME.
3518 If FRAME has focus and there exists more than one frame, puts
3519 a FOCUS_IN_EVENT into *BUFP. */
3522 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
)
3525 struct x_display_info
*dpyinfo
;
3526 struct frame
*frame
;
3527 struct input_event
*bufp
;
3529 if (type
== FocusIn
)
3531 if (dpyinfo
->x_focus_event_frame
!= frame
)
3533 x_new_focus_frame (dpyinfo
, frame
);
3534 dpyinfo
->x_focus_event_frame
= frame
;
3536 /* Don't stop displaying the initial startup message
3537 for a switch-frame event we don't need. */
3538 if (NILP (Vterminal_frame
)
3539 && CONSP (Vframe_list
)
3540 && !NILP (XCDR (Vframe_list
)))
3542 bufp
->kind
= FOCUS_IN_EVENT
;
3543 XSETFRAME (bufp
->frame_or_window
, frame
);
3547 frame
->output_data
.x
->focus_state
|= state
;
3550 if (FRAME_XIC (frame
))
3551 XSetICFocus (FRAME_XIC (frame
));
3554 else if (type
== FocusOut
)
3556 frame
->output_data
.x
->focus_state
&= ~state
;
3558 if (dpyinfo
->x_focus_event_frame
== frame
)
3560 dpyinfo
->x_focus_event_frame
= 0;
3561 x_new_focus_frame (dpyinfo
, 0);
3565 if (FRAME_XIC (frame
))
3566 XUnsetICFocus (FRAME_XIC (frame
));
3571 /* The focus may have changed. Figure out if it is a real focus change,
3572 by checking both FocusIn/Out and Enter/LeaveNotify events.
3574 Returns FOCUS_IN_EVENT event in *BUFP. */
3577 x_detect_focus_change (dpyinfo
, event
, bufp
)
3578 struct x_display_info
*dpyinfo
;
3580 struct input_event
*bufp
;
3582 struct frame
*frame
;
3584 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3588 switch (event
->type
)
3593 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3595 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3597 if (event
->xcrossing
.detail
!= NotifyInferior
3598 && event
->xcrossing
.focus
3599 && ! (focus_state
& FOCUS_EXPLICIT
))
3600 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3602 dpyinfo
, frame
, bufp
);
3608 x_focus_changed (event
->type
,
3609 (event
->xfocus
.detail
== NotifyPointer
?
3610 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3611 dpyinfo
, frame
, bufp
);
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;
3691 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3693 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3694 min_code
, max_code
- min_code
+ 1,
3696 mods
= XGetModifierMapping (dpyinfo
->display
);
3698 /* Scan the modifier table to see which modifier bits the Meta and
3699 Alt keysyms are on. */
3701 int row
, col
; /* The row and column in the modifier table. */
3702 int found_alt_or_meta
;
3704 for (row
= 3; row
< 8; row
++)
3706 found_alt_or_meta
= 0;
3707 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3709 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3711 /* Zeroes are used for filler. Skip them. */
3715 /* Are any of this keycode's keysyms a meta key? */
3719 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3721 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3727 found_alt_or_meta
= 1;
3728 dpyinfo
->meta_mod_mask
|= (1 << row
);
3733 found_alt_or_meta
= 1;
3734 dpyinfo
->alt_mod_mask
|= (1 << row
);
3739 if (!found_alt_or_meta
)
3740 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3741 code_col
= syms_per_code
;
3742 col
= mods
->max_keypermod
;
3747 if (!found_alt_or_meta
)
3748 dpyinfo
->super_mod_mask
|= (1 << row
);
3749 code_col
= syms_per_code
;
3750 col
= mods
->max_keypermod
;
3754 /* Ignore this if it's not on the lock modifier. */
3755 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3756 dpyinfo
->shift_lock_mask
= LockMask
;
3757 code_col
= syms_per_code
;
3758 col
= mods
->max_keypermod
;
3767 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3768 if (! dpyinfo
->meta_mod_mask
)
3770 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3771 dpyinfo
->alt_mod_mask
= 0;
3774 /* If some keys are both alt and meta,
3775 make them just meta, not alt. */
3776 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3778 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3781 XFree ((char *) syms
);
3782 XFreeModifiermap (mods
);
3785 /* Convert between the modifier bits X uses and the modifier bits
3789 x_x_to_emacs_modifiers (dpyinfo
, state
)
3790 struct x_display_info
*dpyinfo
;
3793 EMACS_UINT mod_meta
= meta_modifier
;
3794 EMACS_UINT mod_alt
= alt_modifier
;
3795 EMACS_UINT mod_hyper
= hyper_modifier
;
3796 EMACS_UINT mod_super
= super_modifier
;
3799 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3800 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3801 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3802 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3803 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3804 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3805 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3806 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3809 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3810 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3811 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3812 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3813 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3814 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3818 x_emacs_to_x_modifiers (dpyinfo
, state
)
3819 struct x_display_info
*dpyinfo
;
3822 EMACS_UINT mod_meta
= meta_modifier
;
3823 EMACS_UINT mod_alt
= alt_modifier
;
3824 EMACS_UINT mod_hyper
= hyper_modifier
;
3825 EMACS_UINT mod_super
= super_modifier
;
3829 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3830 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3831 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3832 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3833 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3834 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3835 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3836 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3839 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3840 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3841 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3842 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3843 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3844 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3847 /* Convert a keysym to its name. */
3850 x_get_keysym_name (keysym
)
3856 value
= XKeysymToString (keysym
);
3864 /* Mouse clicks and mouse movement. Rah. */
3866 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3868 If the event is a button press, then note that we have grabbed
3872 construct_mouse_click (result
, event
, f
)
3873 struct input_event
*result
;
3874 XButtonEvent
*event
;
3877 /* Make the event type NO_EVENT; we'll change that when we decide
3879 result
->kind
= MOUSE_CLICK_EVENT
;
3880 result
->code
= event
->button
- Button1
;
3881 result
->timestamp
= event
->time
;
3882 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3884 | (event
->type
== ButtonRelease
3888 XSETINT (result
->x
, event
->x
);
3889 XSETINT (result
->y
, event
->y
);
3890 XSETFRAME (result
->frame_or_window
, f
);
3896 /* Function to report a mouse movement to the mainstream Emacs code.
3897 The input handler calls this.
3899 We have received a mouse movement event, which is given in *event.
3900 If the mouse is over a different glyph than it was last time, tell
3901 the mainstream emacs code by setting mouse_moved. If not, ask for
3902 another motion event, so we can check again the next time it moves. */
3904 static XMotionEvent last_mouse_motion_event
;
3905 static Lisp_Object last_mouse_motion_frame
;
3908 note_mouse_movement (frame
, event
)
3910 XMotionEvent
*event
;
3912 last_mouse_movement_time
= event
->time
;
3913 last_mouse_motion_event
= *event
;
3914 XSETFRAME (last_mouse_motion_frame
, frame
);
3916 if (!FRAME_X_OUTPUT (frame
))
3919 if (event
->window
!= FRAME_X_WINDOW (frame
))
3921 frame
->mouse_moved
= 1;
3922 last_mouse_scroll_bar
= Qnil
;
3923 note_mouse_highlight (frame
, -1, -1);
3924 last_mouse_glyph_frame
= 0;
3929 /* Has the mouse moved off the glyph it was on at the last sighting? */
3930 if (frame
!= last_mouse_glyph_frame
3931 || event
->x
< last_mouse_glyph
.x
3932 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3933 || event
->y
< last_mouse_glyph
.y
3934 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3936 frame
->mouse_moved
= 1;
3937 last_mouse_scroll_bar
= Qnil
;
3938 note_mouse_highlight (frame
, event
->x
, event
->y
);
3939 /* Remember which glyph we're now on. */
3940 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3941 last_mouse_glyph_frame
= frame
;
3949 /************************************************************************
3951 ************************************************************************/
3954 redo_mouse_highlight ()
3956 if (!NILP (last_mouse_motion_frame
)
3957 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3958 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3959 last_mouse_motion_event
.x
,
3960 last_mouse_motion_event
.y
);
3965 /* Return the current position of the mouse.
3966 *FP should be a frame which indicates which display to ask about.
3968 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3969 and *PART to the frame, window, and scroll bar part that the mouse
3970 is over. Set *X and *Y to the portion and whole of the mouse's
3971 position on the scroll bar.
3973 If the mouse movement started elsewhere, set *FP to the frame the
3974 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3977 Set *TIME to the server time-stamp for the time at which the mouse
3978 was at this position.
3980 Don't store anything if we don't have a valid set of values to report.
3982 This clears the mouse_moved flag, so we can wait for the next mouse
3986 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3989 Lisp_Object
*bar_window
;
3990 enum scroll_bar_part
*part
;
3992 unsigned long *time
;
3998 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3999 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
4005 Window dummy_window
;
4008 Lisp_Object frame
, tail
;
4010 /* Clear the mouse-moved flag for every frame on this display. */
4011 FOR_EACH_FRAME (tail
, frame
)
4012 if (FRAME_X_P (XFRAME (frame
))
4013 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
4014 XFRAME (frame
)->mouse_moved
= 0;
4016 last_mouse_scroll_bar
= Qnil
;
4018 /* Figure out which root window we're on. */
4019 XQueryPointer (FRAME_X_DISPLAY (*fp
),
4020 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
4022 /* The root window which contains the pointer. */
4025 /* Trash which we can't trust if the pointer is on
4026 a different screen. */
4029 /* The position on that root window. */
4032 /* More trash we can't trust. */
4035 /* Modifier keys and pointer buttons, about which
4037 (unsigned int *) &dummy
);
4039 /* Now we have a position on the root; find the innermost window
4040 containing the pointer. */
4044 int parent_x
= 0, parent_y
= 0;
4048 /* XTranslateCoordinates can get errors if the window
4049 structure is changing at the same time this function
4050 is running. So at least we must not crash from them. */
4052 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4054 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4055 && FRAME_LIVE_P (last_mouse_frame
))
4057 /* If mouse was grabbed on a frame, give coords for that frame
4058 even if the mouse is now outside it. */
4059 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4061 /* From-window, to-window. */
4062 root
, FRAME_X_WINDOW (last_mouse_frame
),
4064 /* From-position, to-position. */
4065 root_x
, root_y
, &win_x
, &win_y
,
4069 f1
= last_mouse_frame
;
4075 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4077 /* From-window, to-window. */
4080 /* From-position, to-position. */
4081 root_x
, root_y
, &win_x
, &win_y
,
4086 if (child
== None
|| child
== win
)
4094 /* Now we know that:
4095 win is the innermost window containing the pointer
4096 (XTC says it has no child containing the pointer),
4097 win_x and win_y are the pointer's position in it
4098 (XTC did this the last time through), and
4099 parent_x and parent_y are the pointer's position in win's parent.
4100 (They are what win_x and win_y were when win was child.
4101 If win is the root window, it has no parent, and
4102 parent_{x,y} are invalid, but that's okay, because we'll
4103 never use them in that case.) */
4105 /* Is win one of our frames? */
4106 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
4108 #ifdef USE_X_TOOLKIT
4109 /* If we end up with the menu bar window, say it's not
4112 && f1
->output_data
.x
->menubar_widget
4113 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4115 #endif /* USE_X_TOOLKIT */
4118 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4121 x_uncatch_errors ();
4123 /* If not, is it one of our scroll bars? */
4126 struct scroll_bar
*bar
;
4128 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
4132 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4138 if (f1
== 0 && insist
> 0)
4139 f1
= SELECTED_FRAME ();
4143 /* Ok, we found a frame. Store all the values.
4144 last_mouse_glyph is a rectangle used to reduce the
4145 generation of mouse events. To not miss any motion
4146 events, we must divide the frame into rectangles of the
4147 size of the smallest character that could be displayed
4148 on it, i.e. into the same rectangles that matrices on
4149 the frame are divided into. */
4151 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
4152 last_mouse_glyph_frame
= f1
;
4157 XSETINT (*x
, win_x
);
4158 XSETINT (*y
, win_y
);
4159 *time
= last_mouse_movement_time
;
4169 /***********************************************************************
4171 ***********************************************************************/
4173 /* Scroll bar support. */
4175 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4177 This can be called in GC, so we have to make sure to strip off mark
4180 static struct scroll_bar
*
4181 x_window_to_scroll_bar (display
, window_id
)
4187 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4188 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4189 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4191 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4193 Lisp_Object frame
, bar
, condemned
;
4195 frame
= XCAR (tail
);
4196 /* All elements of Vframe_list should be frames. */
4197 if (! FRAMEP (frame
))
4200 if (! FRAME_X_P (XFRAME (frame
)))
4203 /* Scan this frame's scroll bar list for a scroll bar with the
4205 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4206 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4207 /* This trick allows us to search both the ordinary and
4208 condemned scroll bar lists with one loop. */
4209 ! NILP (bar
) || (bar
= condemned
,
4212 bar
= XSCROLL_BAR (bar
)->next
)
4213 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4214 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4215 return XSCROLL_BAR (bar
);
4222 #if defined USE_LUCID
4224 /* Return the Lucid menu bar WINDOW is part of. Return null
4225 if WINDOW is not part of a menu bar. */
4228 x_window_to_menu_bar (window
)
4233 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4235 if (FRAME_X_P (XFRAME (XCAR (tail
))))
4237 Lisp_Object frame
= XCAR (tail
);
4238 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4240 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4248 #endif /* USE_LUCID */
4251 /************************************************************************
4253 ************************************************************************/
4255 #ifdef USE_TOOLKIT_SCROLL_BARS
4257 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
4258 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
4259 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
4260 struct scroll_bar
*));
4261 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4265 /* Lisp window being scrolled. Set when starting to interact with
4266 a toolkit scroll bar, reset to nil when ending the interaction. */
4268 static Lisp_Object window_being_scrolled
;
4270 /* Last scroll bar part sent in xm_scroll_callback. */
4272 static int last_scroll_bar_part
;
4274 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4275 that movements of 1/20 of the screen size are mapped to up/down. */
4278 /* Id of action hook installed for scroll bars. */
4280 static XtActionHookId action_hook_id
;
4282 static Boolean xaw3d_arrow_scroll
;
4284 /* Whether the drag scrolling maintains the mouse at the top of the
4285 thumb. If not, resizing the thumb needs to be done more carefully
4286 to avoid jerkyness. */
4288 static Boolean xaw3d_pick_top
;
4290 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4291 bars are used.. The hook is responsible for detecting when
4292 the user ends an interaction with the scroll bar, and generates
4293 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4296 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
4299 XtPointer client_data
;
4303 Cardinal
*num_params
;
4309 scroll_bar_p
= XmIsScrollBar (widget
);
4310 end_action
= "Release";
4311 #else /* !USE_MOTIF i.e. use Xaw */
4312 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4313 end_action
= "EndScroll";
4314 #endif /* USE_MOTIF */
4317 && strcmp (action_name
, end_action
) == 0
4318 && WINDOWP (window_being_scrolled
))
4322 x_send_scroll_bar_event (window_being_scrolled
,
4323 scroll_bar_end_scroll
, 0, 0);
4324 w
= XWINDOW (window_being_scrolled
);
4326 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4328 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4329 /* The thumb size is incorrect while dragging: fix it. */
4330 set_vertical_scroll_bar (w
);
4332 window_being_scrolled
= Qnil
;
4333 last_scroll_bar_part
= -1;
4335 /* Xt timeouts no longer needed. */
4336 toolkit_scroll_bar_interaction
= 0;
4339 #endif /* not USE_GTK */
4341 /* A vector of windows used for communication between
4342 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4344 static struct window
**scroll_bar_windows
;
4345 static int scroll_bar_windows_size
;
4348 /* Send a client message with message type Xatom_Scrollbar for a
4349 scroll action to the frame of WINDOW. PART is a value identifying
4350 the part of the scroll bar that was clicked on. PORTION is the
4351 amount to scroll of a whole of WHOLE. */
4354 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4356 int part
, portion
, whole
;
4359 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4360 struct window
*w
= XWINDOW (window
);
4361 struct frame
*f
= XFRAME (w
->frame
);
4366 /* Construct a ClientMessage event to send to the frame. */
4367 ev
->type
= ClientMessage
;
4368 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4369 ev
->display
= FRAME_X_DISPLAY (f
);
4370 ev
->window
= FRAME_X_WINDOW (f
);
4373 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4374 not enough to store a pointer or Lisp_Object on a 64 bit system.
4375 So, store the window in scroll_bar_windows and pass the index
4376 into that array in the event. */
4377 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4378 if (scroll_bar_windows
[i
] == NULL
)
4381 if (i
== scroll_bar_windows_size
)
4383 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4384 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4385 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4387 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4389 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4390 scroll_bar_windows_size
= new_size
;
4393 scroll_bar_windows
[i
] = w
;
4394 ev
->data
.l
[0] = (long) i
;
4395 ev
->data
.l
[1] = (long) part
;
4396 ev
->data
.l
[2] = (long) 0;
4397 ev
->data
.l
[3] = (long) portion
;
4398 ev
->data
.l
[4] = (long) whole
;
4400 /* Make Xt timeouts work while the scroll bar is active. */
4401 toolkit_scroll_bar_interaction
= 1;
4402 #ifdef USE_X_TOOLKIT
4403 x_activate_timeout_atimer ();
4406 /* Setting the event mask to zero means that the message will
4407 be sent to the client that created the window, and if that
4408 window no longer exists, no event will be sent. */
4409 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4414 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4418 x_scroll_bar_to_input_event (event
, ievent
)
4420 struct input_event
*ievent
;
4422 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4427 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4428 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4430 XSETWINDOW (window
, w
);
4431 f
= XFRAME (w
->frame
);
4433 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4434 ievent
->frame_or_window
= window
;
4437 ievent
->timestamp
= CurrentTime
;
4439 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4441 ievent
->part
= ev
->data
.l
[1];
4442 ievent
->code
= ev
->data
.l
[2];
4443 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4444 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4445 ievent
->modifiers
= 0;
4451 /* Minimum and maximum values used for Motif scroll bars. */
4453 #define XM_SB_MAX 10000000
4456 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4457 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4458 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4461 xm_scroll_callback (widget
, client_data
, call_data
)
4463 XtPointer client_data
, call_data
;
4465 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4466 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4467 int part
= -1, whole
= 0, portion
= 0;
4471 case XmCR_DECREMENT
:
4472 bar
->dragging
= Qnil
;
4473 part
= scroll_bar_up_arrow
;
4476 case XmCR_INCREMENT
:
4477 bar
->dragging
= Qnil
;
4478 part
= scroll_bar_down_arrow
;
4481 case XmCR_PAGE_DECREMENT
:
4482 bar
->dragging
= Qnil
;
4483 part
= scroll_bar_above_handle
;
4486 case XmCR_PAGE_INCREMENT
:
4487 bar
->dragging
= Qnil
;
4488 part
= scroll_bar_below_handle
;
4492 bar
->dragging
= Qnil
;
4493 part
= scroll_bar_to_top
;
4496 case XmCR_TO_BOTTOM
:
4497 bar
->dragging
= Qnil
;
4498 part
= scroll_bar_to_bottom
;
4505 /* Get the slider size. */
4507 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4510 whole
= XM_SB_MAX
- slider_size
;
4511 portion
= min (cs
->value
, whole
);
4512 part
= scroll_bar_handle
;
4513 bar
->dragging
= make_number (cs
->value
);
4517 case XmCR_VALUE_CHANGED
:
4523 window_being_scrolled
= bar
->window
;
4524 last_scroll_bar_part
= part
;
4525 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4529 #elif defined USE_GTK
4531 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4532 bar widget. DATA is a pointer to the scroll_bar structure. */
4535 xg_scroll_callback (widget
, data
)
4539 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4545 int part
= -1, whole
= 0, portion
= 0;
4546 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4548 position
= gtk_adjustment_get_value (adj
);
4550 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4553 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4555 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4561 if (xg_ignore_gtk_scrollbar
) return;
4563 diff
= (int) (position
- previous
);
4565 if (diff
== (int) adj
->step_increment
)
4567 part
= scroll_bar_down_arrow
;
4568 bar
->dragging
= Qnil
;
4570 else if (-diff
== (int) adj
->step_increment
)
4572 part
= scroll_bar_up_arrow
;
4573 bar
->dragging
= Qnil
;
4575 else if (diff
== (int) adj
->page_increment
)
4577 part
= scroll_bar_below_handle
;
4578 bar
->dragging
= Qnil
;
4580 else if (-diff
== (int) adj
->page_increment
)
4582 part
= scroll_bar_above_handle
;
4583 bar
->dragging
= Qnil
;
4587 part
= scroll_bar_handle
;
4588 whole
= adj
->upper
- adj
->page_size
;
4589 portion
= min ((int)position
, whole
);
4590 bar
->dragging
= make_number ((int)portion
);
4595 window_being_scrolled
= bar
->window
;
4596 last_scroll_bar_part
= part
;
4597 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4601 #else /* not USE_GTK and not USE_MOTIF */
4603 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4604 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4605 scroll bar struct. CALL_DATA is a pointer to a float saying where
4609 xaw_jump_callback (widget
, client_data
, call_data
)
4611 XtPointer client_data
, call_data
;
4613 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4614 float top
= *(float *) call_data
;
4616 int whole
, portion
, height
;
4619 /* Get the size of the thumb, a value between 0 and 1. */
4621 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4625 portion
= shown
< 1 ? top
* whole
: 0;
4627 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4628 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4629 the bottom, so we force the scrolling whenever we see that we're
4630 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4631 we try to ensure that we always stay two pixels away from the
4633 part
= scroll_bar_down_arrow
;
4635 part
= scroll_bar_handle
;
4637 window_being_scrolled
= bar
->window
;
4638 bar
->dragging
= make_number (portion
);
4639 last_scroll_bar_part
= part
;
4640 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4644 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4645 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4646 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4647 the scroll bar. CALL_DATA is an integer specifying the action that
4648 has taken place. Its magnitude is in the range 0..height of the
4649 scroll bar. Negative values mean scroll towards buffer start.
4650 Values < height of scroll bar mean line-wise movement. */
4653 xaw_scroll_callback (widget
, client_data
, call_data
)
4655 XtPointer client_data
, call_data
;
4657 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4658 /* The position really is stored cast to a pointer. */
4659 int position
= (long) call_data
;
4663 /* Get the height of the scroll bar. */
4665 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4668 if (eabs (position
) >= height
)
4669 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4671 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4672 it maps line-movement to call_data = max(5, height/20). */
4673 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4674 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4676 part
= scroll_bar_move_ratio
;
4678 window_being_scrolled
= bar
->window
;
4679 bar
->dragging
= Qnil
;
4680 last_scroll_bar_part
= part
;
4681 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4684 #endif /* not USE_GTK and not USE_MOTIF */
4686 #define SCROLL_BAR_NAME "verticalScrollBar"
4688 /* Create the widget for scroll bar BAR on frame F. Record the widget
4689 and X window of the scroll bar in BAR. */
4693 x_create_toolkit_scroll_bar (f
, bar
)
4695 struct scroll_bar
*bar
;
4697 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4700 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4705 #else /* not USE_GTK */
4708 x_create_toolkit_scroll_bar (f
, bar
)
4710 struct scroll_bar
*bar
;
4716 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4717 unsigned long pixel
;
4722 /* Set resources. Create the widget. */
4723 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4724 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4725 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4726 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4727 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4728 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4729 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4731 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4734 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4738 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4741 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4745 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4746 scroll_bar_name
, av
, ac
);
4748 /* Add one callback for everything that can happen. */
4749 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4751 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4753 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4755 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4757 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4759 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4761 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4764 /* Realize the widget. Only after that is the X window created. */
4765 XtRealizeWidget (widget
);
4767 /* Set the cursor to an arrow. I didn't find a resource to do that.
4768 And I'm wondering why it hasn't an arrow cursor by default. */
4769 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4770 f
->output_data
.x
->nontext_cursor
);
4772 #else /* !USE_MOTIF i.e. use Xaw */
4774 /* Set resources. Create the widget. The background of the
4775 Xaw3d scroll bar widget is a little bit light for my taste.
4776 We don't alter it here to let users change it according
4777 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4778 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4779 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4780 /* For smoother scrolling with Xaw3d -sm */
4781 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4783 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4786 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4790 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4793 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4797 /* Top/bottom shadow colors. */
4799 /* Allocate them, if necessary. */
4800 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4802 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4803 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4804 &pixel
, 1.2, 0x8000))
4806 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4808 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4810 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4811 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4812 &pixel
, 0.6, 0x4000))
4814 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4817 #ifdef XtNbeNiceToColormap
4818 /* Tell the toolkit about them. */
4819 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4820 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4821 /* We tried to allocate a color for the top/bottom shadow, and
4822 failed, so tell Xaw3d to use dithering instead. */
4824 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4828 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4829 be more consistent with other emacs 3d colors, and since Xaw3d is
4830 not good at dealing with allocation failure. */
4832 /* This tells Xaw3d to use real colors instead of dithering for
4834 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4837 /* Specify the colors. */
4838 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4841 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4844 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4847 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4853 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4854 f
->output_data
.x
->edit_widget
, av
, ac
);
4858 char *val
= initial
;
4859 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4860 #ifdef XtNarrowScrollbars
4861 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4863 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4864 if (xaw3d_arrow_scroll
|| val
== initial
)
4865 { /* ARROW_SCROLL */
4866 xaw3d_arrow_scroll
= True
;
4867 /* Isn't that just a personal preference ? --Stef */
4868 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4872 /* Define callbacks. */
4873 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4874 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4877 /* Realize the widget. Only after that is the X window created. */
4878 XtRealizeWidget (widget
);
4880 #endif /* !USE_MOTIF */
4882 /* Install an action hook that lets us detect when the user
4883 finishes interacting with a scroll bar. */
4884 if (action_hook_id
== 0)
4885 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4887 /* Remember X window and widget in the scroll bar vector. */
4888 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4889 xwindow
= XtWindow (widget
);
4890 bar
->x_window
= xwindow
;
4894 #endif /* not USE_GTK */
4897 /* Set the thumb size and position of scroll bar BAR. We are currently
4898 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4902 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4903 struct scroll_bar
*bar
;
4904 int portion
, position
, whole
;
4906 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4909 #else /* not USE_GTK */
4911 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4912 struct scroll_bar
*bar
;
4913 int portion
, position
, whole
;
4915 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4916 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4923 /* We use an estimate of 30 chars per line rather than the real
4924 `portion' value. This has the disadvantage that the thumb size
4925 is not very representative, but it makes our life a lot easier.
4926 Otherwise, we have to constantly adjust the thumb size, which
4927 we can't always do quickly enough: while dragging, the size of
4928 the thumb might prevent the user from dragging the thumb all the
4929 way to the end. but Motif and some versions of Xaw3d don't allow
4930 updating the thumb size while dragging. Also, even if we can update
4931 its size, the update will often happen too late.
4932 If you don't believe it, check out revision 1.650 of xterm.c to see
4933 what hoops we were going through and the still poor behavior we got. */
4934 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4935 /* When the thumb is at the bottom, position == whole.
4936 So we need to increase `whole' to make space for the thumb. */
4943 top
= (float) position
/ whole
;
4944 shown
= (float) portion
/ whole
;
4947 if (NILP (bar
->dragging
))
4951 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4952 is the scroll bar's maximum and MIN is the scroll bar's minimum
4954 size
= shown
* XM_SB_MAX
;
4955 size
= min (size
, XM_SB_MAX
);
4956 size
= max (size
, 1);
4958 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4959 value
= top
* XM_SB_MAX
;
4960 value
= min (value
, XM_SB_MAX
- size
);
4962 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4964 #else /* !USE_MOTIF i.e. use Xaw */
4970 top
= (float) position
/ whole
;
4971 shown
= (float) portion
/ whole
;
4975 float old_top
, old_shown
;
4977 XtVaGetValues (widget
,
4978 XtNtopOfThumb
, &old_top
,
4979 XtNshown
, &old_shown
,
4983 /* Massage the top+shown values. */
4984 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4985 top
= max (0, min (1, top
));
4988 /* Keep two pixels available for moving the thumb down. */
4989 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4991 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4992 check that your system's configuration file contains a define
4993 for `NARROWPROTO'. See s/freebsd.h for an example. */
4994 if (top
!= old_top
|| shown
!= old_shown
)
4996 if (NILP (bar
->dragging
))
4997 XawScrollbarSetThumb (widget
, top
, shown
);
5000 /* Try to make the scrolling a tad smoother. */
5001 if (!xaw3d_pick_top
)
5002 shown
= min (shown
, old_shown
);
5004 XawScrollbarSetThumb (widget
, top
, shown
);
5008 #endif /* !USE_MOTIF */
5012 #endif /* not USE_GTK */
5014 #endif /* USE_TOOLKIT_SCROLL_BARS */
5018 /************************************************************************
5019 Scroll bars, general
5020 ************************************************************************/
5022 /* Create a scroll bar and return the scroll bar vector for it. W is
5023 the Emacs window on which to create the scroll bar. TOP, LEFT,
5024 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
5027 static struct scroll_bar
*
5028 x_scroll_bar_create (w
, top
, left
, width
, height
)
5030 int top
, left
, width
, height
;
5032 struct frame
*f
= XFRAME (w
->frame
);
5033 struct scroll_bar
*bar
5034 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
5038 #ifdef USE_TOOLKIT_SCROLL_BARS
5039 x_create_toolkit_scroll_bar (f
, bar
);
5040 #else /* not USE_TOOLKIT_SCROLL_BARS */
5042 XSetWindowAttributes a
;
5046 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5047 if (a
.background_pixel
== -1)
5048 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5050 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
5051 | ButtonMotionMask
| PointerMotionHintMask
5053 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
5055 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
5057 /* Clear the area of W that will serve as a scroll bar. This is
5058 for the case that a window has been split horizontally. In
5059 this case, no clear_frame is generated to reduce flickering. */
5060 if (width
> 0 && height
> 0)
5061 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5063 window_box_height (w
), False
);
5065 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5066 /* Position and size of scroll bar. */
5067 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5069 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5071 /* Border width, depth, class, and visual. */
5078 bar
->x_window
= window
;
5080 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5082 XSETWINDOW (bar
->window
, w
);
5086 bar
->height
= height
;
5089 bar
->dragging
= Qnil
;
5090 bar
->fringe_extended_p
= 0;
5092 /* Add bar to its frame's list of scroll bars. */
5093 bar
->next
= FRAME_SCROLL_BARS (f
);
5095 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5096 if (!NILP (bar
->next
))
5097 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5099 /* Map the window/widget. */
5100 #ifdef USE_TOOLKIT_SCROLL_BARS
5103 xg_update_scrollbar_pos (f
,
5106 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5107 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5109 xg_show_scroll_bar (bar
->x_window
);
5110 #else /* not USE_GTK */
5111 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5112 XtConfigureWidget (scroll_bar
,
5113 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5115 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5116 max (height
, 1), 0);
5117 XtMapWidget (scroll_bar
);
5118 #endif /* not USE_GTK */
5120 #else /* not USE_TOOLKIT_SCROLL_BARS */
5121 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
5122 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5129 #ifndef USE_TOOLKIT_SCROLL_BARS
5131 /* Draw BAR's handle in the proper position.
5133 If the handle is already drawn from START to END, don't bother
5134 redrawing it, unless REBUILD is non-zero; in that case, always
5135 redraw it. (REBUILD is handy for drawing the handle after expose
5138 Normally, we want to constrain the start and end of the handle to
5139 fit inside its rectangle, but if the user is dragging the scroll
5140 bar handle, we want to let them drag it down all the way, so that
5141 the bar's top is as far down as it goes; otherwise, there's no way
5142 to move to the very end of the buffer. */
5145 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
5146 struct scroll_bar
*bar
;
5150 int dragging
= ! NILP (bar
->dragging
);
5151 Window w
= bar
->x_window
;
5152 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5153 GC gc
= f
->output_data
.x
->normal_gc
;
5155 /* If the display is already accurate, do nothing. */
5157 && start
== bar
->start
5164 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5165 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5166 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5168 /* Make sure the values are reasonable, and try to preserve
5169 the distance between start and end. */
5171 int length
= end
- start
;
5175 else if (start
> top_range
)
5177 end
= start
+ length
;
5181 else if (end
> top_range
&& ! dragging
)
5185 /* Store the adjusted setting in the scroll bar. */
5189 /* Clip the end position, just for display. */
5190 if (end
> top_range
)
5193 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5194 below top positions, to make sure the handle is always at least
5195 that many pixels tall. */
5196 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5198 /* Draw the empty space above the handle. Note that we can't clear
5199 zero-height areas; that means "clear to end of window." */
5201 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5202 /* x, y, width, height, and exposures. */
5203 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5204 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5205 inside_width
, start
,
5208 /* Change to proper foreground color if one is specified. */
5209 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5210 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5211 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5213 /* Draw the handle itself. */
5214 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5215 /* x, y, width, height */
5216 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5217 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5218 inside_width
, end
- start
);
5220 /* Restore the foreground color of the GC if we changed it above. */
5221 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5222 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5223 FRAME_FOREGROUND_PIXEL (f
));
5225 /* Draw the empty space below the handle. Note that we can't
5226 clear zero-height areas; that means "clear to end of window." */
5227 if (end
< inside_height
)
5228 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5229 /* x, y, width, height, and exposures. */
5230 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5231 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5232 inside_width
, inside_height
- end
,
5240 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5242 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5246 x_scroll_bar_remove (bar
)
5247 struct scroll_bar
*bar
;
5249 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5252 #ifdef USE_TOOLKIT_SCROLL_BARS
5254 xg_remove_scroll_bar (f
, bar
->x_window
);
5255 #else /* not USE_GTK */
5256 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5257 #endif /* not USE_GTK */
5259 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5262 /* Disassociate this scroll bar from its window. */
5263 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
5269 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5270 that we are displaying PORTION characters out of a total of WHOLE
5271 characters, starting at POSITION. If WINDOW has no scroll bar,
5275 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
5277 int portion
, whole
, position
;
5279 struct frame
*f
= XFRAME (w
->frame
);
5280 struct scroll_bar
*bar
;
5281 int top
, height
, left
, sb_left
, width
, sb_width
;
5282 int window_y
, window_height
;
5283 #ifdef USE_TOOLKIT_SCROLL_BARS
5284 int fringe_extended_p
;
5287 /* Get window dimensions. */
5288 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
5290 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5291 height
= window_height
;
5293 /* Compute the left edge of the scroll bar area. */
5294 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5296 /* Compute the width of the scroll bar which might be less than
5297 the width of the area reserved for the scroll bar. */
5298 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5299 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5303 /* Compute the left edge of the scroll bar. */
5304 #ifdef USE_TOOLKIT_SCROLL_BARS
5305 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5306 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5308 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5310 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5311 sb_left
= left
+ width
- sb_width
;
5316 #ifdef USE_TOOLKIT_SCROLL_BARS
5317 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5318 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5319 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5320 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5321 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5323 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5324 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5325 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5326 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5329 /* Does the scroll bar exist yet? */
5330 if (NILP (w
->vertical_scroll_bar
))
5332 if (width
> 0 && height
> 0)
5335 #ifdef USE_TOOLKIT_SCROLL_BARS
5336 if (fringe_extended_p
)
5337 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5338 sb_left
, top
, sb_width
, height
, False
);
5341 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5342 left
, top
, width
, height
, False
);
5346 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5350 /* It may just need to be moved and resized. */
5351 unsigned int mask
= 0;
5353 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5357 if (sb_left
!= bar
->left
)
5359 if (top
!= bar
->top
)
5361 if (sb_width
!= bar
->width
)
5363 if (height
!= bar
->height
)
5366 #ifdef USE_TOOLKIT_SCROLL_BARS
5368 /* Move/size the scroll bar widget. */
5369 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5371 /* Since toolkit scroll bars are smaller than the space reserved
5372 for them on the frame, we have to clear "under" them. */
5373 if (width
> 0 && height
> 0)
5375 if (fringe_extended_p
)
5376 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5377 sb_left
, top
, sb_width
, height
, False
);
5379 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5380 left
, top
, width
, height
, False
);
5383 xg_update_scrollbar_pos (f
,
5386 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5387 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5389 #else /* not USE_GTK */
5390 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5391 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5393 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5394 max (height
, 1), 0);
5395 #endif /* not USE_GTK */
5397 #else /* not USE_TOOLKIT_SCROLL_BARS */
5399 /* Clear areas not covered by the scroll bar because of
5400 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5401 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5403 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5404 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5406 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5407 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5408 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5412 /* Clear areas not covered by the scroll bar because it's not as
5413 wide as the area reserved for it. This makes sure a
5414 previous mode line display is cleared after C-x 2 C-x 1, for
5417 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5418 int rest
= area_width
- sb_width
;
5419 if (rest
> 0 && height
> 0)
5421 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5422 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5423 left
+ area_width
- rest
, top
,
5424 rest
, height
, False
);
5426 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5427 left
, top
, rest
, height
, False
);
5431 /* Move/size the scroll bar window. */
5436 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5438 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5440 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5444 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5446 /* Remember new settings. */
5447 bar
->left
= sb_left
;
5449 bar
->width
= sb_width
;
5450 bar
->height
= height
;
5455 #ifdef USE_TOOLKIT_SCROLL_BARS
5456 bar
->fringe_extended_p
= fringe_extended_p
;
5458 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5459 #else /* not USE_TOOLKIT_SCROLL_BARS */
5460 /* Set the scroll bar's current state, unless we're currently being
5462 if (NILP (bar
->dragging
))
5464 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5467 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5470 int start
= ((double) position
* top_range
) / whole
;
5471 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5472 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5475 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5477 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5481 /* The following three hooks are used when we're doing a thorough
5482 redisplay of the frame. We don't explicitly know which scroll bars
5483 are going to be deleted, because keeping track of when windows go
5484 away is a real pain - "Can you say set-window-configuration, boys
5485 and girls?" Instead, we just assert at the beginning of redisplay
5486 that *all* scroll bars are to be removed, and then save a scroll bar
5487 from the fiery pit when we actually redisplay its window. */
5489 /* Arrange for all scroll bars on FRAME to be removed at the next call
5490 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5491 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5494 XTcondemn_scroll_bars (frame
)
5497 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5498 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5501 bar
= FRAME_SCROLL_BARS (frame
);
5502 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5503 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5504 XSCROLL_BAR (bar
)->prev
= Qnil
;
5505 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5506 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5507 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5512 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5513 Note that WINDOW isn't necessarily condemned at all. */
5516 XTredeem_scroll_bar (window
)
5517 struct window
*window
;
5519 struct scroll_bar
*bar
;
5522 /* We can't redeem this window's scroll bar if it doesn't have one. */
5523 if (NILP (window
->vertical_scroll_bar
))
5526 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5528 /* Unlink it from the condemned list. */
5529 f
= XFRAME (WINDOW_FRAME (window
));
5530 if (NILP (bar
->prev
))
5532 /* If the prev pointer is nil, it must be the first in one of
5534 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5535 /* It's not condemned. Everything's fine. */
5537 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5538 window
->vertical_scroll_bar
))
5539 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5541 /* If its prev pointer is nil, it must be at the front of
5542 one or the other! */
5546 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5548 if (! NILP (bar
->next
))
5549 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5551 bar
->next
= FRAME_SCROLL_BARS (f
);
5553 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5554 if (! NILP (bar
->next
))
5555 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5558 /* Remove all scroll bars on FRAME that haven't been saved since the
5559 last call to `*condemn_scroll_bars_hook'. */
5562 XTjudge_scroll_bars (f
)
5565 Lisp_Object bar
, next
;
5567 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5569 /* Clear out the condemned list now so we won't try to process any
5570 more events on the hapless scroll bars. */
5571 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5573 for (; ! NILP (bar
); bar
= next
)
5575 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5577 x_scroll_bar_remove (b
);
5580 b
->next
= b
->prev
= Qnil
;
5583 /* Now there should be no references to the condemned scroll bars,
5584 and they should get garbage-collected. */
5588 #ifndef USE_TOOLKIT_SCROLL_BARS
5589 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5590 is a no-op when using toolkit scroll bars.
5592 This may be called from a signal handler, so we have to ignore GC
5596 x_scroll_bar_expose (bar
, event
)
5597 struct scroll_bar
*bar
;
5600 Window w
= bar
->x_window
;
5601 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5602 GC gc
= f
->output_data
.x
->normal_gc
;
5603 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5607 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5609 /* Switch to scroll bar foreground color. */
5610 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5611 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5612 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5614 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5615 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5617 /* x, y, width, height */
5619 bar
->width
- 1 - width_trim
- width_trim
,
5622 /* Restore the foreground color of the GC if we changed it above. */
5623 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5624 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5625 FRAME_FOREGROUND_PIXEL (f
));
5630 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5632 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5633 is set to something other than NO_EVENT, it is enqueued.
5635 This may be called from a signal handler, so we have to ignore GC
5640 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5641 struct scroll_bar
*bar
;
5643 struct input_event
*emacs_event
;
5645 if (! WINDOWP (bar
->window
))
5648 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5649 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5650 emacs_event
->modifiers
5651 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5652 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5653 event
->xbutton
.state
)
5654 | (event
->type
== ButtonRelease
5657 emacs_event
->frame_or_window
= bar
->window
;
5658 emacs_event
->arg
= Qnil
;
5659 emacs_event
->timestamp
= event
->xbutton
.time
;
5662 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5664 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5667 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5668 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5671 if (y
> top_range
) y
= top_range
;
5674 emacs_event
->part
= scroll_bar_above_handle
;
5675 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5676 emacs_event
->part
= scroll_bar_handle
;
5678 emacs_event
->part
= scroll_bar_below_handle
;
5680 /* Just because the user has clicked on the handle doesn't mean
5681 they want to drag it. Lisp code needs to be able to decide
5682 whether or not we're dragging. */
5684 /* If the user has just clicked on the handle, record where they're
5686 if (event
->type
== ButtonPress
5687 && emacs_event
->part
== scroll_bar_handle
)
5688 XSETINT (bar
->dragging
, y
- bar
->start
);
5691 #ifndef USE_TOOLKIT_SCROLL_BARS
5692 /* If the user has released the handle, set it to its final position. */
5693 if (event
->type
== ButtonRelease
5694 && ! NILP (bar
->dragging
))
5696 int new_start
= y
- XINT (bar
->dragging
);
5697 int new_end
= new_start
+ bar
->end
- bar
->start
;
5699 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5700 bar
->dragging
= Qnil
;
5704 /* Same deal here as the other #if 0. */
5706 /* Clicks on the handle are always reported as occurring at the top of
5708 if (emacs_event
->part
== scroll_bar_handle
)
5709 emacs_event
->x
= bar
->start
;
5711 XSETINT (emacs_event
->x
, y
);
5713 XSETINT (emacs_event
->x
, y
);
5716 XSETINT (emacs_event
->y
, top_range
);
5720 #ifndef USE_TOOLKIT_SCROLL_BARS
5722 /* Handle some mouse motion while someone is dragging the scroll bar.
5724 This may be called from a signal handler, so we have to ignore GC
5728 x_scroll_bar_note_movement (bar
, event
)
5729 struct scroll_bar
*bar
;
5732 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5734 last_mouse_movement_time
= event
->xmotion
.time
;
5737 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5739 /* If we're dragging the bar, display it. */
5740 if (! NILP (bar
->dragging
))
5742 /* Where should the handle be now? */
5743 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5745 if (new_start
!= bar
->start
)
5747 int new_end
= new_start
+ bar
->end
- bar
->start
;
5749 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5754 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5756 /* Return information to the user about the current position of the mouse
5757 on the scroll bar. */
5760 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5762 Lisp_Object
*bar_window
;
5763 enum scroll_bar_part
*part
;
5765 unsigned long *time
;
5767 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5768 Window w
= bar
->x_window
;
5769 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5771 Window dummy_window
;
5773 unsigned int dummy_mask
;
5777 /* Get the mouse's position relative to the scroll bar window, and
5779 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5781 /* Root, child, root x and root y. */
5782 &dummy_window
, &dummy_window
,
5783 &dummy_coord
, &dummy_coord
,
5785 /* Position relative to scroll bar. */
5788 /* Mouse buttons and modifier keys. */
5795 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5798 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5800 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5802 if (! NILP (bar
->dragging
))
5803 win_y
-= XINT (bar
->dragging
);
5807 if (win_y
> top_range
)
5811 *bar_window
= bar
->window
;
5813 if (! NILP (bar
->dragging
))
5814 *part
= scroll_bar_handle
;
5815 else if (win_y
< bar
->start
)
5816 *part
= scroll_bar_above_handle
;
5817 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5818 *part
= scroll_bar_handle
;
5820 *part
= scroll_bar_below_handle
;
5822 XSETINT (*x
, win_y
);
5823 XSETINT (*y
, top_range
);
5826 last_mouse_scroll_bar
= Qnil
;
5829 *time
= last_mouse_movement_time
;
5835 /* The screen has been cleared so we may have changed foreground or
5836 background colors, and the scroll bars may need to be redrawn.
5837 Clear out the scroll bars, and ask for expose events, so we can
5841 x_scroll_bar_clear (f
)
5844 #ifndef USE_TOOLKIT_SCROLL_BARS
5847 /* We can have scroll bars even if this is 0,
5848 if we just turned off scroll bar mode.
5849 But in that case we should not clear them. */
5850 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5851 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5852 bar
= XSCROLL_BAR (bar
)->next
)
5853 XClearArea (FRAME_X_DISPLAY (f
),
5854 XSCROLL_BAR (bar
)->x_window
,
5856 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5860 /* The main X event-reading loop - XTread_socket. */
5863 /* Time stamp of enter window event. This is only used by XTread_socket,
5864 but we have to put it out here, since static variables within functions
5865 sometimes don't work. */
5867 static Time enter_timestamp
;
5870 /* This holds the state XLookupString needs to implement dead keys
5871 and other tricks known as "compose processing". _X Window System_
5872 says that a portable program can't use this, but Stephen Gildea assures
5873 me that letting the compiler initialize it to zeros will work okay.
5875 This must be defined outside of XTread_socket, for the same reasons
5876 given for enter_timestamp, above. */
5878 static XComposeStatus compose_status
;
5880 /* Record the last 100 characters stored
5881 to help debug the loss-of-chars-during-GC problem. */
5883 static int temp_index
;
5884 static short temp_buffer
[100];
5886 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5887 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5889 temp_buffer[temp_index++] = (keysym)
5891 /* Set this to nonzero to fake an "X I/O error"
5892 on a particular display. */
5894 struct x_display_info
*XTread_socket_fake_io_error
;
5896 /* When we find no input here, we occasionally do a no-op command
5897 to verify that the X server is still running and we can still talk with it.
5898 We try all the open displays, one by one.
5899 This variable is used for cycling thru the displays. */
5901 static struct x_display_info
*next_noop_dpyinfo
;
5903 #define SET_SAVED_MENU_EVENT(size) \
5906 if (f->output_data.x->saved_menu_event == 0) \
5907 f->output_data.x->saved_menu_event \
5908 = (XEvent *) xmalloc (sizeof (XEvent)); \
5909 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5910 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5911 XSETFRAME (inev.ie.frame_or_window, f); \
5915 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5916 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5926 /* Filter events for the current X input method.
5927 DPYINFO is the display this event is for.
5928 EVENT is the X event to filter.
5930 Returns non-zero if the event was filtered, caller shall not process
5932 Returns zero if event is wasn't filtered. */
5936 x_filter_event (dpyinfo
, event
)
5937 struct x_display_info
*dpyinfo
;
5940 /* XFilterEvent returns non-zero if the input method has
5941 consumed the event. We pass the frame's X window to
5942 XFilterEvent because that's the one for which the IC
5945 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5946 event
->xclient
.window
);
5948 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5953 static int current_count
;
5954 static int current_finish
;
5955 static struct input_event
*current_hold_quit
;
5957 /* This is the filter function invoked by the GTK event loop.
5958 It is invoked before the XEvent is translated to a GdkEvent,
5959 so we have a chance to act on the event before GTK. */
5960 static GdkFilterReturn
5961 event_handler_gdk (gxev
, ev
, data
)
5966 XEvent
*xev
= (XEvent
*) gxev
;
5968 if (current_count
>= 0)
5970 struct x_display_info
*dpyinfo
;
5972 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5975 /* Filter events for the current X input method.
5976 GTK calls XFilterEvent but not for key press and release,
5977 so we do it here. */
5978 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5979 if (dpyinfo
&& x_filter_event (dpyinfo
, xev
))
5980 return GDK_FILTER_REMOVE
;
5984 current_finish
= X_EVENT_NORMAL
;
5988 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5993 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5995 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5996 return GDK_FILTER_REMOVE
;
5998 return GDK_FILTER_CONTINUE
;
6000 #endif /* USE_GTK */
6003 /* Handles the XEvent EVENT on display DPYINFO.
6005 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
6006 *FINISH is zero if caller should continue reading events.
6007 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
6009 We return the number of characters stored into the buffer. */
6012 handle_one_xevent (dpyinfo
, eventp
, finish
, hold_quit
)
6013 struct x_display_info
*dpyinfo
;
6016 struct input_event
*hold_quit
;
6019 struct input_event ie
;
6020 struct selection_input_event sie
;
6025 struct frame
*f
= NULL
;
6026 struct coding_system coding
;
6027 XEvent event
= *eventp
;
6029 *finish
= X_EVENT_NORMAL
;
6031 EVENT_INIT (inev
.ie
);
6032 inev
.ie
.kind
= NO_EVENT
;
6039 if (event
.xclient
.message_type
6040 == dpyinfo
->Xatom_wm_protocols
6041 && event
.xclient
.format
== 32)
6043 if (event
.xclient
.data
.l
[0]
6044 == dpyinfo
->Xatom_wm_take_focus
)
6046 /* Use x_any_window_to_frame because this
6047 could be the shell widget window
6048 if the frame has no title bar. */
6049 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6051 /* Not quite sure this is needed -pd */
6052 if (f
&& FRAME_XIC (f
))
6053 XSetICFocus (FRAME_XIC (f
));
6055 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
6056 instructs the WM to set the input focus automatically for
6057 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
6058 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
6059 it has set the focus. So, XSetInputFocus below is not
6062 The call to XSetInputFocus below has also caused trouble. In
6063 cases where the XSetInputFocus done by the WM and the one
6064 below are temporally close (on a fast machine), the call
6065 below can generate additional FocusIn events which confuse
6068 /* Since we set WM_TAKE_FOCUS, we must call
6069 XSetInputFocus explicitly. But not if f is null,
6070 since that might be an event for a deleted frame. */
6073 Display
*d
= event
.xclient
.display
;
6074 /* Catch and ignore errors, in case window has been
6075 iconified by a window manager such as GWM. */
6077 XSetInputFocus (d
, event
.xclient
.window
,
6078 /* The ICCCM says this is
6079 the only valid choice. */
6081 event
.xclient
.data
.l
[1]);
6082 /* This is needed to detect the error
6083 if there is an error. */
6085 x_uncatch_errors ();
6087 /* Not certain about handling scroll bars here */
6092 if (event
.xclient
.data
.l
[0]
6093 == dpyinfo
->Xatom_wm_save_yourself
)
6095 /* Save state modify the WM_COMMAND property to
6096 something which can reinstate us. This notifies
6097 the session manager, who's looking for such a
6098 PropertyNotify. Can restart processing when
6099 a keyboard or mouse event arrives. */
6100 /* If we have a session manager, don't set this.
6101 KDE will then start two Emacsen, one for the
6102 session manager and one for this. */
6104 if (! x_session_have_connection ())
6107 f
= x_top_window_to_frame (dpyinfo
,
6108 event
.xclient
.window
);
6109 /* This is just so we only give real data once
6110 for a single Emacs process. */
6111 if (f
== SELECTED_FRAME ())
6112 XSetCommand (FRAME_X_DISPLAY (f
),
6113 event
.xclient
.window
,
6114 initial_argv
, initial_argc
);
6116 XSetCommand (FRAME_X_DISPLAY (f
),
6117 event
.xclient
.window
,
6123 if (event
.xclient
.data
.l
[0]
6124 == dpyinfo
->Xatom_wm_delete_window
)
6126 f
= x_any_window_to_frame (dpyinfo
,
6127 event
.xclient
.window
);
6129 goto OTHER
; /* May be a dialog that is to be removed */
6131 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
6132 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6139 if (event
.xclient
.message_type
6140 == dpyinfo
->Xatom_wm_configure_denied
)
6145 if (event
.xclient
.message_type
6146 == dpyinfo
->Xatom_wm_window_moved
)
6149 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6151 new_x
= event
.xclient
.data
.s
[0];
6152 new_y
= event
.xclient
.data
.s
[1];
6156 f
->left_pos
= new_x
;
6163 if (event
.xclient
.message_type
6164 == dpyinfo
->Xatom_editres
)
6166 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6168 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
6172 #endif /* HACK_EDITRES */
6174 if ((event
.xclient
.message_type
6175 == dpyinfo
->Xatom_DONE
)
6176 || (event
.xclient
.message_type
6177 == dpyinfo
->Xatom_PAGE
))
6179 /* Ghostview job completed. Kill it. We could
6180 reply with "Next" if we received "Page", but we
6181 currently never do because we are interested in
6182 images, only, which should have 1 page. */
6183 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
6184 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6187 x_kill_gs_process (pixmap
, f
);
6188 expose_frame (f
, 0, 0, 0, 0);
6192 #ifdef USE_TOOLKIT_SCROLL_BARS
6193 /* Scroll bar callbacks send a ClientMessage from which
6194 we construct an input_event. */
6195 if (event
.xclient
.message_type
6196 == dpyinfo
->Xatom_Scrollbar
)
6198 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
6199 *finish
= X_EVENT_GOTO_OUT
;
6202 #endif /* USE_TOOLKIT_SCROLL_BARS */
6204 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6207 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6208 *finish
= X_EVENT_DROP
;
6212 case SelectionNotify
:
6213 last_user_time
= event
.xselection
.time
;
6214 #ifdef USE_X_TOOLKIT
6215 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6217 #endif /* not USE_X_TOOLKIT */
6218 x_handle_selection_notify (&event
.xselection
);
6221 case SelectionClear
: /* Someone has grabbed ownership. */
6222 last_user_time
= event
.xselectionclear
.time
;
6223 #ifdef USE_X_TOOLKIT
6224 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6226 #endif /* USE_X_TOOLKIT */
6228 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
6230 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6231 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6232 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6233 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6234 inev
.ie
.frame_or_window
= Qnil
;
6238 case SelectionRequest
: /* Someone wants our selection. */
6239 last_user_time
= event
.xselectionrequest
.time
;
6240 #ifdef USE_X_TOOLKIT
6241 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6243 #endif /* USE_X_TOOLKIT */
6245 XSelectionRequestEvent
*eventp
6246 = (XSelectionRequestEvent
*) &event
;
6248 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6249 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6250 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6251 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6252 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6253 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6254 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6255 inev
.ie
.frame_or_window
= Qnil
;
6259 case PropertyNotify
:
6260 last_user_time
= event
.xproperty
.time
;
6261 #if 0 /* This is plain wrong. In the case that we are waiting for a
6262 PropertyNotify used as an ACK in incremental selection
6263 transfer, the property will be on the receiver's window. */
6264 #if defined USE_X_TOOLKIT
6265 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
6269 x_handle_property_notify (&event
.xproperty
);
6272 case ReparentNotify
:
6273 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6277 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6278 x_real_positions (f
, &x
, &y
);
6282 /* Perhaps reparented due to a WM restart. Reset this. */
6283 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6284 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
6289 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6292 x_check_fullscreen (f
);
6295 /* This seems to be needed for GTK 2.6. */
6296 x_clear_area (event
.xexpose
.display
,
6297 event
.xexpose
.window
,
6298 event
.xexpose
.x
, event
.xexpose
.y
,
6299 event
.xexpose
.width
, event
.xexpose
.height
,
6302 if (f
->async_visible
== 0)
6304 f
->async_visible
= 1;
6305 f
->async_iconified
= 0;
6306 f
->output_data
.x
->has_been_visible
= 1;
6307 SET_FRAME_GARBAGED (f
);
6311 event
.xexpose
.x
, event
.xexpose
.y
,
6312 event
.xexpose
.width
, event
.xexpose
.height
);
6316 #ifndef USE_TOOLKIT_SCROLL_BARS
6317 struct scroll_bar
*bar
;
6319 #if defined USE_LUCID
6320 /* Submenus of the Lucid menu bar aren't widgets
6321 themselves, so there's no way to dispatch events
6322 to them. Recognize this case separately. */
6325 = x_window_to_menu_bar (event
.xexpose
.window
);
6327 xlwmenu_redisplay (widget
);
6329 #endif /* USE_LUCID */
6331 #ifdef USE_TOOLKIT_SCROLL_BARS
6332 /* Dispatch event to the widget. */
6334 #else /* not USE_TOOLKIT_SCROLL_BARS */
6335 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6336 event
.xexpose
.window
);
6339 x_scroll_bar_expose (bar
, &event
);
6340 #ifdef USE_X_TOOLKIT
6343 #endif /* USE_X_TOOLKIT */
6344 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6348 case GraphicsExpose
: /* This occurs when an XCopyArea's
6349 source area was obscured or not
6351 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6355 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6356 event
.xgraphicsexpose
.width
,
6357 event
.xgraphicsexpose
.height
);
6359 #ifdef USE_X_TOOLKIT
6362 #endif /* USE_X_TOOLKIT */
6365 case NoExpose
: /* This occurs when an XCopyArea's
6366 source area was completely
6371 /* Redo the mouse-highlight after the tooltip has gone. */
6372 if (event
.xmap
.window
== tip_window
)
6375 redo_mouse_highlight ();
6378 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6379 if (f
) /* F may no longer exist if
6380 the frame was deleted. */
6382 /* While a frame is unmapped, display generation is
6383 disabled; you don't want to spend time updating a
6384 display that won't ever be seen. */
6385 f
->async_visible
= 0;
6386 /* We can't distinguish, from the event, whether the window
6387 has become iconified or invisible. So assume, if it
6388 was previously visible, than now it is iconified.
6389 But x_make_frame_invisible clears both
6390 the visible flag and the iconified flag;
6391 and that way, we know the window is not iconified now. */
6392 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6394 f
->async_iconified
= 1;
6396 inev
.ie
.kind
= ICONIFY_EVENT
;
6397 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6403 if (event
.xmap
.window
== tip_window
)
6404 /* The tooltip has been drawn already. Avoid
6405 the SET_FRAME_GARBAGED below. */
6408 /* We use x_top_window_to_frame because map events can
6409 come for sub-windows and they don't mean that the
6410 frame is visible. */
6411 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6414 /* wait_reading_process_output will notice this and update
6415 the frame's display structures.
6416 If we where iconified, we should not set garbaged,
6417 because that stops redrawing on Expose events. This looks
6418 bad if we are called from a recursive event loop
6419 (x_dispatch_event), for example when a dialog is up. */
6420 if (! f
->async_iconified
)
6421 SET_FRAME_GARBAGED (f
);
6423 f
->async_visible
= 1;
6424 f
->async_iconified
= 0;
6425 f
->output_data
.x
->has_been_visible
= 1;
6429 inev
.ie
.kind
= DEICONIFY_EVENT
;
6430 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6432 else if (! NILP (Vframe_list
)
6433 && ! NILP (XCDR (Vframe_list
)))
6434 /* Force a redisplay sooner or later
6435 to update the frame titles
6436 in case this is the second frame. */
6437 record_asynch_buffer_change ();
6443 last_user_time
= event
.xkey
.time
;
6444 ignore_next_mouse_click_timeout
= 0;
6446 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6447 /* Dispatch KeyPress events when in menu. */
6448 if (popup_activated ())
6452 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6454 /* If mouse-highlight is an integer, input clears out
6455 mouse highlighting. */
6456 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6458 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6460 clear_mouse_face (dpyinfo
);
6461 dpyinfo
->mouse_face_hidden
= 1;
6464 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6467 /* Scroll bars consume key events, but we want
6468 the keys to go to the scroll bar's frame. */
6469 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6471 if (widget
&& XmIsScrollBar (widget
))
6473 widget
= XtParent (widget
);
6474 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6477 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6481 KeySym keysym
, orig_keysym
;
6482 /* al%imercury@uunet.uu.net says that making this 81
6483 instead of 80 fixed a bug whereby meta chars made
6486 It seems that some version of XmbLookupString has
6487 a bug of not returning XBufferOverflow in
6488 status_return even if the input is too long to
6489 fit in 81 bytes. So, we must prepare sufficient
6490 bytes for copy_buffer. 513 bytes (256 chars for
6491 two-byte character set) seems to be a fairly good
6492 approximation. -- 2000.8.10 handa@etl.go.jp */
6493 unsigned char copy_buffer
[513];
6494 unsigned char *copy_bufptr
= copy_buffer
;
6495 int copy_bufsiz
= sizeof (copy_buffer
);
6497 Lisp_Object coding_system
= Qlatin_1
;
6501 /* Don't pass keys to GTK. A Tab will shift focus to the
6502 tool bar in GTK 2.4. Keys will still go to menus and
6503 dialogs because in that case popup_activated is TRUE
6505 *finish
= X_EVENT_DROP
;
6509 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6510 extra_keyboard_modifiers
);
6511 modifiers
= event
.xkey
.state
;
6513 /* This will have to go some day... */
6515 /* make_lispy_event turns chars into control chars.
6516 Don't do it here because XLookupString is too eager. */
6517 event
.xkey
.state
&= ~ControlMask
;
6518 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6519 | dpyinfo
->super_mod_mask
6520 | dpyinfo
->hyper_mod_mask
6521 | dpyinfo
->alt_mod_mask
);
6523 /* In case Meta is ComposeCharacter,
6524 clear its status. According to Markus Ehrnsperger
6525 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6526 this enables ComposeCharacter to work whether or
6527 not it is combined with Meta. */
6528 if (modifiers
& dpyinfo
->meta_mod_mask
)
6529 bzero (&compose_status
, sizeof (compose_status
));
6534 Status status_return
;
6536 coding_system
= Vlocale_coding_system
;
6537 nbytes
= XmbLookupString (FRAME_XIC (f
),
6538 &event
.xkey
, copy_bufptr
,
6539 copy_bufsiz
, &keysym
,
6541 if (status_return
== XBufferOverflow
)
6543 copy_bufsiz
= nbytes
+ 1;
6544 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6545 nbytes
= XmbLookupString (FRAME_XIC (f
),
6546 &event
.xkey
, copy_bufptr
,
6547 copy_bufsiz
, &keysym
,
6550 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6551 #if 0 && defined X_HAVE_UTF8_STRING
6552 else if (status_return
== XLookupKeySym
)
6553 { /* Try again but with utf-8. */
6554 coding_system
= Qutf_8
;
6555 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6556 &event
.xkey
, copy_bufptr
,
6557 copy_bufsiz
, &keysym
,
6559 if (status_return
== XBufferOverflow
)
6561 copy_bufsiz
= nbytes
+ 1;
6562 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6563 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6566 copy_bufsiz
, &keysym
,
6572 if (status_return
== XLookupNone
)
6574 else if (status_return
== XLookupChars
)
6579 else if (status_return
!= XLookupKeySym
6580 && status_return
!= XLookupBoth
)
6584 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6585 copy_bufsiz
, &keysym
,
6588 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6589 copy_bufsiz
, &keysym
,
6593 /* If not using XIM/XIC, and a compose sequence is in progress,
6594 we break here. Otherwise, chars_matched is always 0. */
6595 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6598 bzero (&compose_status
, sizeof (compose_status
));
6599 orig_keysym
= keysym
;
6601 /* Common for all keysym input events. */
6602 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6604 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6605 inev
.ie
.timestamp
= event
.xkey
.time
;
6607 /* First deal with keysyms which have defined
6608 translations to characters. */
6609 if (keysym
>= 32 && keysym
< 128)
6610 /* Avoid explicitly decoding each ASCII character. */
6612 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6613 inev
.ie
.code
= keysym
;
6617 /* Keysyms directly mapped to Unicode characters. */
6618 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6620 if (keysym
< 0x01000080)
6621 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6623 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6624 inev
.ie
.code
= keysym
& 0xFFFFFF;
6628 /* Now non-ASCII. */
6629 if (HASH_TABLE_P (Vx_keysym_table
)
6630 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6634 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6635 ? ASCII_KEYSTROKE_EVENT
6636 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6637 inev
.ie
.code
= XFASTINT (c
);
6641 /* Random non-modifier sorts of keysyms. */
6642 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6643 || keysym
== XK_Delete
6644 #ifdef XK_ISO_Left_Tab
6645 || (keysym
>= XK_ISO_Left_Tab
6646 && keysym
<= XK_ISO_Enter
)
6648 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6649 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6651 /* This recognizes the "extended function
6652 keys". It seems there's no cleaner way.
6653 Test IsModifierKey to avoid handling
6654 mode_switch incorrectly. */
6655 || ((unsigned) (keysym
) >= XK_Select
6656 && (unsigned)(keysym
) < XK_KP_Space
)
6658 #ifdef XK_dead_circumflex
6659 || orig_keysym
== XK_dead_circumflex
6661 #ifdef XK_dead_grave
6662 || orig_keysym
== XK_dead_grave
6664 #ifdef XK_dead_tilde
6665 || orig_keysym
== XK_dead_tilde
6667 #ifdef XK_dead_diaeresis
6668 || orig_keysym
== XK_dead_diaeresis
6670 #ifdef XK_dead_macron
6671 || orig_keysym
== XK_dead_macron
6673 #ifdef XK_dead_degree
6674 || orig_keysym
== XK_dead_degree
6676 #ifdef XK_dead_acute
6677 || orig_keysym
== XK_dead_acute
6679 #ifdef XK_dead_cedilla
6680 || orig_keysym
== XK_dead_cedilla
6682 #ifdef XK_dead_breve
6683 || orig_keysym
== XK_dead_breve
6685 #ifdef XK_dead_ogonek
6686 || orig_keysym
== XK_dead_ogonek
6688 #ifdef XK_dead_caron
6689 || orig_keysym
== XK_dead_caron
6691 #ifdef XK_dead_doubleacute
6692 || orig_keysym
== XK_dead_doubleacute
6694 #ifdef XK_dead_abovedot
6695 || orig_keysym
== XK_dead_abovedot
6697 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6698 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6699 /* Any "vendor-specific" key is ok. */
6700 || (orig_keysym
& (1 << 28))
6701 || (keysym
!= NoSymbol
&& nbytes
== 0))
6702 && ! (IsModifierKey (orig_keysym
)
6703 /* The symbols from XK_ISO_Lock
6704 to XK_ISO_Last_Group_Lock
6705 don't have real modifiers but
6706 should be treated similarly to
6707 Mode_switch by Emacs. */
6708 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6709 || ((unsigned)(orig_keysym
)
6711 && (unsigned)(orig_keysym
)
6712 <= XK_ISO_Last_Group_Lock
)
6716 STORE_KEYSYM_FOR_DEBUG (keysym
);
6717 /* make_lispy_event will convert this to a symbolic
6719 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6720 inev
.ie
.code
= keysym
;
6724 { /* Raw bytes, not keysym. */
6729 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6731 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6733 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6736 if (nchars
< nbytes
)
6738 /* Decode the input data. */
6742 /* The input should be decoded with `coding_system'
6743 which depends on which X*LookupString function
6744 we used just above and the locale. */
6745 setup_coding_system (coding_system
, &coding
);
6746 coding
.src_multibyte
= 0;
6747 coding
.dst_multibyte
= 1;
6748 /* The input is converted to events, thus we can't
6749 handle composition. Anyway, there's no XIM that
6750 gives us composition information. */
6751 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6753 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6754 coding
.destination
= alloca (require
);
6755 coding
.dst_bytes
= require
;
6756 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6757 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6758 nbytes
= coding
.produced
;
6759 nchars
= coding
.produced_char
;
6760 copy_bufptr
= coding
.destination
;
6763 /* Convert the input data to a sequence of
6764 character events. */
6765 for (i
= 0; i
< nbytes
; i
+= len
)
6767 if (nchars
== nbytes
)
6768 c
= copy_bufptr
[i
], len
= 1;
6770 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6772 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6773 ? ASCII_KEYSTROKE_EVENT
6774 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6776 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6781 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6783 if (keysym
== NoSymbol
)
6789 /* Don't dispatch this event since XtDispatchEvent calls
6790 XFilterEvent, and two calls in a row may freeze the
6798 last_user_time
= event
.xkey
.time
;
6800 /* Don't dispatch this event since XtDispatchEvent calls
6801 XFilterEvent, and two calls in a row may freeze the
6809 last_user_time
= event
.xcrossing
.time
;
6810 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6812 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6814 if (f
&& x_mouse_click_focus_ignore_position
)
6815 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6818 if (event
.xcrossing
.focus
)
6820 /* Avoid nasty pop/raise loops. */
6821 if (f
&& (!(f
->auto_raise
)
6823 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6825 x_new_focus_frame (dpyinfo
, f
);
6826 enter_timestamp
= event
.xcrossing
.time
;
6829 else if (f
== dpyinfo
->x_focus_frame
)
6830 x_new_focus_frame (dpyinfo
, 0);
6833 /* EnterNotify counts as mouse movement,
6834 so update things that depend on mouse position. */
6835 if (f
&& !f
->output_data
.x
->hourglass_p
)
6836 note_mouse_movement (f
, &event
.xmotion
);
6838 /* We may get an EnterNotify on the buttons in the toolbar. In that
6839 case we moved out of any highlighted area and need to note this. */
6840 if (!f
&& last_mouse_glyph_frame
)
6841 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6846 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6850 last_user_time
= event
.xcrossing
.time
;
6851 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6853 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6856 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6858 /* If we move outside the frame, then we're
6859 certainly no longer on any text in the frame. */
6860 clear_mouse_face (dpyinfo
);
6861 dpyinfo
->mouse_face_mouse_frame
= 0;
6864 /* Generate a nil HELP_EVENT to cancel a help-echo.
6865 Do it only if there's something to cancel.
6866 Otherwise, the startup message is cleared when
6867 the mouse leaves the frame. */
6868 if (any_help_event_p
)
6872 /* See comment in EnterNotify above */
6873 else if (last_mouse_glyph_frame
)
6874 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6879 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6884 last_user_time
= event
.xmotion
.time
;
6885 previous_help_echo_string
= help_echo_string
;
6886 help_echo_string
= Qnil
;
6888 if (dpyinfo
->grabbed
&& last_mouse_frame
6889 && FRAME_LIVE_P (last_mouse_frame
))
6890 f
= last_mouse_frame
;
6892 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6894 if (dpyinfo
->mouse_face_hidden
)
6896 dpyinfo
->mouse_face_hidden
= 0;
6897 clear_mouse_face (dpyinfo
);
6903 /* Generate SELECT_WINDOW_EVENTs when needed. */
6904 if (!NILP (Vmouse_autoselect_window
))
6908 window
= window_from_coordinates (f
,
6909 event
.xmotion
.x
, event
.xmotion
.y
,
6912 /* Window will be selected only when it is not selected now and
6913 last mouse movement event was not in it. Minibuffer window
6914 will be selected only when it is active. */
6915 if (WINDOWP (window
)
6916 && !EQ (window
, last_window
)
6917 && !EQ (window
, selected_window
)
6918 /* For click-to-focus window managers
6919 create event iff we don't leave the
6921 && (focus_follows_mouse
6922 || (EQ (XWINDOW (window
)->frame
,
6923 XWINDOW (selected_window
)->frame
))))
6925 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6926 inev
.ie
.frame_or_window
= window
;
6931 if (!note_mouse_movement (f
, &event
.xmotion
))
6932 help_echo_string
= previous_help_echo_string
;
6936 #ifndef USE_TOOLKIT_SCROLL_BARS
6937 struct scroll_bar
*bar
6938 = x_window_to_scroll_bar (event
.xmotion
.display
,
6939 event
.xmotion
.window
);
6942 x_scroll_bar_note_movement (bar
, &event
);
6943 #endif /* USE_TOOLKIT_SCROLL_BARS */
6945 /* If we move outside the frame, then we're
6946 certainly no longer on any text in the frame. */
6947 clear_mouse_face (dpyinfo
);
6950 /* If the contents of the global variable help_echo_string
6951 has changed, generate a HELP_EVENT. */
6952 if (!NILP (help_echo_string
)
6953 || !NILP (previous_help_echo_string
))
6958 case ConfigureNotify
:
6959 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6962 #ifndef USE_X_TOOLKIT
6964 xg_resize_widgets (f
, event
.xconfigure
.width
,
6965 event
.xconfigure
.height
);
6966 #else /* not USE_GTK */
6967 /* If there is a pending resize for fullscreen, don't
6968 do this one, the right one will come later.
6969 The toolkit version doesn't seem to need this, but we
6970 need to reset it below. */
6972 = ((f
->want_fullscreen
& FULLSCREEN_WAIT
)
6973 && f
->new_text_cols
!= 0);
6974 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6975 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6980 /* In the toolkit version, change_frame_size
6981 is called by the code that handles resizing
6982 of the EmacsFrame widget. */
6984 /* Even if the number of character rows and columns has
6985 not changed, the font size may have changed, so we need
6986 to check the pixel dimensions as well. */
6987 if (columns
!= FRAME_COLS (f
)
6988 || rows
!= FRAME_LINES (f
)
6989 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6990 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6992 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6993 SET_FRAME_GARBAGED (f
);
6994 cancel_mouse_face (f
);
6996 #endif /* not USE_GTK */
6999 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
7000 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
7003 /* GTK creates windows but doesn't map them.
7004 Only get real positions and check fullscreen when mapped. */
7005 if (FRAME_GTK_OUTER_WIDGET (f
)
7006 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
7009 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
7011 if (f
->want_fullscreen
& FULLSCREEN_WAIT
)
7012 f
->want_fullscreen
&= ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
7016 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
7017 xic_set_statusarea (f
);
7020 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
7022 /* Since the WM decorations come below top_pos now,
7023 we must put them below top_pos in the future. */
7024 f
->win_gravity
= NorthWestGravity
;
7025 x_wm_set_size_hint (f
, (long) 0, 0);
7033 /* If we decide we want to generate an event to be seen
7034 by the rest of Emacs, we put it here. */
7037 bzero (&compose_status
, sizeof (compose_status
));
7038 last_mouse_glyph_frame
= 0;
7039 last_user_time
= event
.xbutton
.time
;
7041 if (dpyinfo
->grabbed
7043 && FRAME_LIVE_P (last_mouse_frame
))
7044 f
= last_mouse_frame
;
7046 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
7050 /* Is this in the tool-bar? */
7051 if (WINDOWP (f
->tool_bar_window
)
7052 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
7055 int x
= event
.xbutton
.x
;
7056 int y
= event
.xbutton
.y
;
7058 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
7059 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
7061 if (tool_bar_p
&& event
.xbutton
.button
< 4)
7063 handle_tool_bar_click (f
, x
, y
,
7064 event
.xbutton
.type
== ButtonPress
,
7065 x_x_to_emacs_modifiers (dpyinfo
,
7066 event
.xbutton
.state
));
7071 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7072 if (! popup_activated ())
7075 if (ignore_next_mouse_click_timeout
)
7077 if (event
.type
== ButtonPress
7078 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
7080 ignore_next_mouse_click_timeout
= 0;
7081 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
7083 if (event
.type
== ButtonRelease
)
7084 ignore_next_mouse_click_timeout
= 0;
7087 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
7092 struct scroll_bar
*bar
7093 = x_window_to_scroll_bar (event
.xbutton
.display
,
7094 event
.xbutton
.window
);
7096 #ifdef USE_TOOLKIT_SCROLL_BARS
7097 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
7099 if (bar
&& event
.xbutton
.state
& ControlMask
)
7101 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
7102 *finish
= X_EVENT_DROP
;
7104 #else /* not USE_TOOLKIT_SCROLL_BARS */
7106 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
7107 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7110 if (event
.type
== ButtonPress
)
7112 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
7113 last_mouse_frame
= f
;
7116 last_tool_bar_item
= -1;
7119 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
7121 /* Ignore any mouse motion that happened before this event;
7122 any subsequent mouse-movement Emacs events should reflect
7123 only motion after the ButtonPress/Release. */
7127 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7128 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
7129 /* For a down-event in the menu bar,
7130 don't pass it to Xt right now.
7131 Instead, save it away
7132 and we will pass it to Xt from kbd_buffer_get_event.
7133 That way, we can run some Lisp code first. */
7136 ! popup_activated ()
7139 f
&& event
.type
== ButtonPress
7140 /* Verify the event is really within the menu bar
7141 and not just sent to it due to grabbing. */
7142 && event
.xbutton
.x
>= 0
7143 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
7144 && event
.xbutton
.y
>= 0
7145 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
7146 && event
.xbutton
.same_screen
)
7148 SET_SAVED_BUTTON_EVENT
;
7149 XSETFRAME (last_mouse_press_frame
, f
);
7151 *finish
= X_EVENT_DROP
;
7154 else if (event
.type
== ButtonPress
)
7156 last_mouse_press_frame
= Qnil
;
7160 #ifdef USE_MOTIF /* This should do not harm for Lucid,
7161 but I am trying to be cautious. */
7162 else if (event
.type
== ButtonRelease
)
7164 if (!NILP (last_mouse_press_frame
))
7166 f
= XFRAME (last_mouse_press_frame
);
7167 if (f
->output_data
.x
)
7168 SET_SAVED_BUTTON_EVENT
;
7173 #endif /* USE_MOTIF */
7176 #endif /* USE_X_TOOLKIT || USE_GTK */
7180 case CirculateNotify
:
7183 case CirculateRequest
:
7186 case VisibilityNotify
:
7190 /* Someone has changed the keyboard mapping - update the
7192 switch (event
.xmapping
.request
)
7194 case MappingModifier
:
7195 x_find_modifier_meanings (dpyinfo
);
7196 /* This is meant to fall through. */
7197 case MappingKeyboard
:
7198 XRefreshKeyboardMapping (&event
.xmapping
);
7204 #ifdef USE_X_TOOLKIT
7206 if (*finish
!= X_EVENT_DROP
)
7207 XtDispatchEvent (&event
);
7209 #endif /* USE_X_TOOLKIT */
7214 if (inev
.ie
.kind
!= NO_EVENT
)
7216 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7221 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7226 XSETFRAME (frame
, f
);
7232 any_help_event_p
= 1;
7233 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7234 help_echo_object
, help_echo_pos
);
7238 help_echo_string
= Qnil
;
7239 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7249 /* Handles the XEvent EVENT on display DISPLAY.
7250 This is used for event loops outside the normal event handling,
7251 i.e. looping while a popup menu or a dialog is posted.
7253 Returns the value handle_one_xevent sets in the finish argument. */
7255 x_dispatch_event (event
, display
)
7259 struct x_display_info
*dpyinfo
;
7260 int finish
= X_EVENT_NORMAL
;
7262 dpyinfo
= x_display_info_for_display (display
);
7265 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7271 /* Read events coming from the X server.
7272 This routine is called by the SIGIO handler.
7273 We return as soon as there are no more events to be read.
7275 We return the number of characters stored into the buffer,
7276 thus pretending to be `read' (except the characters we store
7277 in the keyboard buffer can be multibyte, so are not necessarily
7280 EXPECTED is nonzero if the caller knows input is available. */
7283 XTread_socket (terminal
, expected
, hold_quit
)
7284 struct terminal
*terminal
;
7286 struct input_event
*hold_quit
;
7290 int event_found
= 0;
7291 struct x_display_info
*dpyinfo
;
7293 if (interrupt_input_blocked
)
7295 interrupt_input_pending
= 1;
7299 interrupt_input_pending
= 0;
7302 /* So people can tell when we have read the available input. */
7303 input_signal_count
++;
7308 /* Only check session manager input for the primary display. */
7309 if (terminal
->id
== 1 && x_session_have_connection ())
7311 struct input_event inev
;
7313 /* We don't need to EVENT_INIT (inev) here, as
7314 x_session_check_input copies an entire input_event. */
7315 if (x_session_check_input (&inev
))
7317 kbd_buffer_store_event_hold (&inev
, hold_quit
);
7324 /* For debugging, this gives a way to fake an I/O error. */
7325 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7327 XTread_socket_fake_io_error
= 0;
7328 x_io_error_quitter (dpyinfo
->display
);
7331 #if 0 /* This loop is a noop now. */
7332 /* Find the display we are supposed to read input for.
7333 It's the one communicating on descriptor SD. */
7334 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7336 #if 0 /* This ought to be unnecessary; let's verify it. */
7338 /* If available, Xlib uses FIOSNBIO to make the socket
7339 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
7340 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
7341 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
7342 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
7343 #endif /* ! defined (FIOSNBIO) */
7346 #if 0 /* This code can't be made to work, with multiple displays,
7347 and appears not to be used on any system any more.
7348 Also keyboard.c doesn't turn O_NDELAY on and off
7349 for X connections. */
7352 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7354 extern int read_alarm_should_throw
;
7355 read_alarm_should_throw
= 1;
7356 XPeekEvent (dpyinfo
->display
, &event
);
7357 read_alarm_should_throw
= 0;
7359 #endif /* HAVE_SELECT */
7366 while (XPending (terminal
->display_info
.x
->display
))
7370 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7373 /* Filter events for the current X input method. */
7374 if (x_filter_event (terminal
->display_info
.x
, &event
))
7379 count
+= handle_one_xevent (terminal
->display_info
.x
,
7380 &event
, &finish
, hold_quit
);
7382 if (finish
== X_EVENT_GOTO_OUT
)
7388 /* For GTK we must use the GTK event loop. But XEvents gets passed
7389 to our filter function above, and then to the big event switch.
7390 We use a bunch of globals to communicate with our filter function,
7391 that is kind of ugly, but it works.
7393 There is no way to do one display at the time, GTK just does events
7394 from all displays. */
7396 while (gtk_events_pending ())
7398 current_count
= count
;
7399 current_hold_quit
= hold_quit
;
7401 gtk_main_iteration ();
7403 count
= current_count
;
7405 current_hold_quit
= 0;
7407 if (current_finish
== X_EVENT_GOTO_OUT
)
7410 #endif /* USE_GTK */
7414 /* On some systems, an X bug causes Emacs to get no more events
7415 when the window is destroyed. Detect that. (1994.) */
7418 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7419 One XNOOP in 100 loops will make Emacs terminate.
7420 B. Bretthauer, 1994 */
7422 if (x_noop_count
>= 100)
7426 if (next_noop_dpyinfo
== 0)
7427 next_noop_dpyinfo
= x_display_list
;
7429 XNoOp (next_noop_dpyinfo
->display
);
7431 /* Each time we get here, cycle through the displays now open. */
7432 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7436 /* If the focus was just given to an auto-raising frame,
7438 /* ??? This ought to be able to handle more than one such frame. */
7439 if (pending_autoraise_frame
)
7441 x_raise_frame (pending_autoraise_frame
);
7442 pending_autoraise_frame
= 0;
7454 /***********************************************************************
7456 ***********************************************************************/
7458 /* Set clipping for output in glyph row ROW. W is the window in which
7459 we operate. GC is the graphics context to set clipping in.
7461 ROW may be a text row or, e.g., a mode line. Text rows must be
7462 clipped to the interior of the window dedicated to text display,
7463 mode lines must be clipped to the whole window. */
7466 x_clip_to_row (w
, row
, area
, gc
)
7468 struct glyph_row
*row
;
7472 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7473 XRectangle clip_rect
;
7474 int window_x
, window_y
, window_width
;
7476 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7478 clip_rect
.x
= window_x
;
7479 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7480 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7481 clip_rect
.width
= window_width
;
7482 clip_rect
.height
= row
->visible_height
;
7484 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7488 /* Draw a hollow box cursor on window W in glyph row ROW. */
7491 x_draw_hollow_cursor (w
, row
)
7493 struct glyph_row
*row
;
7495 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7496 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7497 Display
*dpy
= FRAME_X_DISPLAY (f
);
7500 struct glyph
*cursor_glyph
;
7503 /* Get the glyph the cursor is on. If we can't tell because
7504 the current matrix is invalid or such, give up. */
7505 cursor_glyph
= get_phys_cursor_glyph (w
);
7506 if (cursor_glyph
== NULL
)
7509 /* Compute frame-relative coordinates for phys cursor. */
7510 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7511 wd
= w
->phys_cursor_width
;
7513 /* The foreground of cursor_gc is typically the same as the normal
7514 background color, which can cause the cursor box to be invisible. */
7515 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7516 if (dpyinfo
->scratch_cursor_gc
)
7517 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7519 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7520 GCForeground
, &xgcv
);
7521 gc
= dpyinfo
->scratch_cursor_gc
;
7523 /* Set clipping, draw the rectangle, and reset clipping again. */
7524 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7525 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7526 XSetClipMask (dpy
, gc
, None
);
7530 /* Draw a bar cursor on window W in glyph row ROW.
7532 Implementation note: One would like to draw a bar cursor with an
7533 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7534 Unfortunately, I didn't find a font yet that has this property set.
7538 x_draw_bar_cursor (w
, row
, width
, kind
)
7540 struct glyph_row
*row
;
7542 enum text_cursor_kinds kind
;
7544 struct frame
*f
= XFRAME (w
->frame
);
7545 struct glyph
*cursor_glyph
;
7547 /* If cursor is out of bounds, don't draw garbage. This can happen
7548 in mini-buffer windows when switching between echo area glyphs
7550 cursor_glyph
= get_phys_cursor_glyph (w
);
7551 if (cursor_glyph
== NULL
)
7554 /* If on an image, draw like a normal cursor. That's usually better
7555 visible than drawing a bar, esp. if the image is large so that
7556 the bar might not be in the window. */
7557 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7559 struct glyph_row
*row
;
7560 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7561 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7565 Display
*dpy
= FRAME_X_DISPLAY (f
);
7566 Window window
= FRAME_X_WINDOW (f
);
7567 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7568 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7569 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7572 /* If the glyph's background equals the color we normally draw
7573 the bar cursor in, the bar cursor in its normal color is
7574 invisible. Use the glyph's foreground color instead in this
7575 case, on the assumption that the glyph's colors are chosen so
7576 that the glyph is legible. */
7577 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7578 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7580 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7581 xgcv
.graphics_exposures
= 0;
7584 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7587 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7588 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7592 width
= FRAME_CURSOR_WIDTH (f
);
7593 width
= min (cursor_glyph
->pixel_width
, width
);
7595 w
->phys_cursor_width
= width
;
7596 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7598 if (kind
== BAR_CURSOR
)
7599 XFillRectangle (dpy
, window
, gc
,
7600 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7601 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7602 width
, row
->height
);
7604 XFillRectangle (dpy
, window
, gc
,
7605 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7606 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7607 row
->height
- width
),
7608 cursor_glyph
->pixel_width
,
7611 XSetClipMask (dpy
, gc
, None
);
7616 /* RIF: Define cursor CURSOR on frame F. */
7619 x_define_frame_cursor (f
, cursor
)
7623 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7627 /* RIF: Clear area on frame F. */
7630 x_clear_frame_area (f
, x
, y
, width
, height
)
7632 int x
, y
, width
, height
;
7634 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7635 x
, y
, width
, height
, False
);
7639 /* RIF: Draw cursor on window W. */
7642 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7644 struct glyph_row
*glyph_row
;
7646 int cursor_type
, cursor_width
;
7649 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7653 w
->phys_cursor_type
= cursor_type
;
7654 w
->phys_cursor_on_p
= 1;
7656 if (glyph_row
->exact_window_width_line_p
7657 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7659 glyph_row
->cursor_in_fringe_p
= 1;
7660 draw_fringe_bitmap (w
, glyph_row
, 0);
7663 switch (cursor_type
)
7665 case HOLLOW_BOX_CURSOR
:
7666 x_draw_hollow_cursor (w
, glyph_row
);
7669 case FILLED_BOX_CURSOR
:
7670 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7674 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7678 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7682 w
->phys_cursor_width
= 0;
7690 if (w
== XWINDOW (f
->selected_window
))
7691 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7692 xic_set_preeditarea (w
, x
, y
);
7697 XFlush (FRAME_X_DISPLAY (f
));
7704 /* Make the x-window of frame F use the gnu icon bitmap. */
7707 x_bitmap_icon (f
, file
)
7713 if (FRAME_X_WINDOW (f
) == 0)
7716 /* Free up our existing icon bitmap and mask if any. */
7717 if (f
->output_data
.x
->icon_bitmap
> 0)
7718 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7719 f
->output_data
.x
->icon_bitmap
= 0;
7724 /* Use gtk_window_set_icon_from_file () if available,
7725 It's not restricted to bitmaps */
7726 if (xg_set_icon (f
, file
))
7728 #endif /* USE_GTK */
7729 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7730 x_create_bitmap_mask (f
, bitmap_id
);
7734 /* Create the GNU bitmap and mask if necessary. */
7735 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7739 #if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7741 if (xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7744 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7746 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7747 #endif /* USE_GTK */
7748 #endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
7750 /* If all else fails, use the (black and white) xbm image. */
7753 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7754 gnu_xbm_width
, gnu_xbm_height
);
7758 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7759 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7763 /* The first time we create the GNU bitmap and mask,
7764 this increments the ref-count one extra time.
7765 As a result, the GNU bitmap and mask are never freed.
7766 That way, we don't have to worry about allocating it again. */
7767 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7769 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7772 x_wm_set_icon_pixmap (f
, bitmap_id
);
7773 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7779 /* Make the x-window of frame F use a rectangle with text.
7780 Use ICON_NAME as the text. */
7783 x_text_icon (f
, icon_name
)
7787 if (FRAME_X_WINDOW (f
) == 0)
7792 text
.value
= (unsigned char *) icon_name
;
7793 text
.encoding
= XA_STRING
;
7795 text
.nitems
= strlen (icon_name
);
7796 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7799 if (f
->output_data
.x
->icon_bitmap
> 0)
7800 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7801 f
->output_data
.x
->icon_bitmap
= 0;
7802 x_wm_set_icon_pixmap (f
, 0);
7807 #define X_ERROR_MESSAGE_SIZE 200
7809 /* If non-nil, this should be a string.
7810 It means catch X errors and store the error message in this string.
7812 The reason we use a stack is that x_catch_error/x_uncatch_error can
7813 be called from a signal handler.
7816 struct x_error_message_stack
{
7817 char string
[X_ERROR_MESSAGE_SIZE
];
7819 struct x_error_message_stack
*prev
;
7821 static struct x_error_message_stack
*x_error_message
;
7823 /* An X error handler which stores the error message in
7824 *x_error_message. This is called from x_error_handler if
7825 x_catch_errors is in effect. */
7828 x_error_catcher (display
, error
)
7832 XGetErrorText (display
, error
->error_code
,
7833 x_error_message
->string
,
7834 X_ERROR_MESSAGE_SIZE
);
7837 /* Begin trapping X errors for display DPY. Actually we trap X errors
7838 for all displays, but DPY should be the display you are actually
7841 After calling this function, X protocol errors no longer cause
7842 Emacs to exit; instead, they are recorded in the string
7843 stored in *x_error_message.
7845 Calling x_check_errors signals an Emacs error if an X error has
7846 occurred since the last call to x_catch_errors or x_check_errors.
7848 Calling x_uncatch_errors resumes the normal error handling. */
7850 void x_check_errors ();
7853 x_catch_errors (dpy
)
7856 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7858 /* Make sure any errors from previous requests have been dealt with. */
7862 data
->string
[0] = 0;
7863 data
->prev
= x_error_message
;
7864 x_error_message
= data
;
7867 /* Undo the last x_catch_errors call.
7868 DPY should be the display that was passed to x_catch_errors. */
7873 struct x_error_message_stack
*tmp
;
7877 /* The display may have been closed before this function is called.
7878 Check if it is still open before calling XSync. */
7879 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7880 XSync (x_error_message
->dpy
, False
);
7882 tmp
= x_error_message
;
7883 x_error_message
= x_error_message
->prev
;
7888 /* If any X protocol errors have arrived since the last call to
7889 x_catch_errors or x_check_errors, signal an Emacs error using
7890 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7893 x_check_errors (dpy
, format
)
7897 /* Make sure to catch any errors incurred so far. */
7900 if (x_error_message
->string
[0])
7902 char string
[X_ERROR_MESSAGE_SIZE
];
7903 bcopy (x_error_message
->string
, string
, X_ERROR_MESSAGE_SIZE
);
7904 x_uncatch_errors ();
7905 error (format
, string
);
7909 /* Nonzero if we had any X protocol errors
7910 since we did x_catch_errors on DPY. */
7913 x_had_errors_p (dpy
)
7916 /* Make sure to catch any errors incurred so far. */
7919 return x_error_message
->string
[0] != 0;
7922 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7925 x_clear_errors (dpy
)
7928 x_error_message
->string
[0] = 0;
7931 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7932 * idea. --lorentey */
7933 /* Close off all unclosed x_catch_errors calls. */
7936 x_fully_uncatch_errors ()
7938 while (x_error_message
)
7939 x_uncatch_errors ();
7943 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7946 x_catching_errors ()
7948 return x_error_message
!= 0;
7952 static unsigned int x_wire_count
;
7955 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7960 /* Handle SIGPIPE, which can happen when the connection to a server
7961 simply goes away. SIGPIPE is handled by x_connection_signal.
7962 Don't need to do anything, because the write which caused the
7963 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7964 which will do the appropriate cleanup for us. */
7967 x_connection_signal (signalnum
) /* If we don't have an argument, */
7968 int signalnum
; /* some compilers complain in signal calls. */
7971 /* USG systems forget handlers when they are used;
7972 must reestablish each time */
7973 signal (signalnum
, x_connection_signal
);
7978 /************************************************************************
7980 ************************************************************************/
7982 /* Error message passed to x_connection_closed. */
7984 static char *error_msg
;
7986 /* Function installed as fatal_error_signal_hook in
7987 x_connection_closed. Print the X error message, and exit normally,
7988 instead of dumping core when XtCloseDisplay fails. */
7991 x_fatal_error_signal ()
7993 fprintf (stderr
, "%s\n", error_msg
);
7997 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7998 the text of an error message that lead to the connection loss. */
8001 x_connection_closed (dpy
, error_message
)
8003 char *error_message
;
8005 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
8006 Lisp_Object frame
, tail
;
8007 int index
= SPECPDL_INDEX ();
8009 error_msg
= (char *) alloca (strlen (error_message
) + 1);
8010 strcpy (error_msg
, error_message
);
8011 handling_signal
= 0;
8013 /* Prevent being called recursively because of an error condition
8014 below. Otherwise, we might end up with printing ``can't find per
8015 display information'' in the recursive call instead of printing
8016 the original message here. */
8017 x_catch_errors (dpy
);
8019 /* Inhibit redisplay while frames are being deleted. */
8020 specbind (Qinhibit_redisplay
, Qt
);
8024 /* Protect display from being closed when we delete the last
8026 dpyinfo
->reference_count
++;
8027 dpyinfo
->terminal
->reference_count
++;
8030 /* First delete frames whose mini-buffers are on frames
8031 that are on the dead display. */
8032 FOR_EACH_FRAME (tail
, frame
)
8034 Lisp_Object minibuf_frame
;
8036 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
8037 if (FRAME_X_P (XFRAME (frame
))
8038 && FRAME_X_P (XFRAME (minibuf_frame
))
8039 && ! EQ (frame
, minibuf_frame
)
8040 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
8041 Fdelete_frame (frame
, Qt
);
8044 /* Now delete all remaining frames on the dead display.
8045 We are now sure none of these is used as the mini-buffer
8046 for another frame that we need to delete. */
8047 FOR_EACH_FRAME (tail
, frame
)
8048 if (FRAME_X_P (XFRAME (frame
))
8049 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
8051 /* Set this to t so that Fdelete_frame won't get confused
8052 trying to find a replacement. */
8053 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
8054 Fdelete_frame (frame
, Qt
);
8057 /* We have to close the display to inform Xt that it doesn't
8058 exist anymore. If we don't, Xt will continue to wait for
8059 events from the display. As a consequence, a sequence of
8061 M-x make-frame-on-display RET :1 RET
8062 ...kill the new frame, so that we get an IO error...
8063 M-x make-frame-on-display RET :1 RET
8065 will indefinitely wait in Xt for events for display `:1', opened
8066 in the first class to make-frame-on-display.
8068 Closing the display is reported to lead to a bus error on
8069 OpenWindows in certain situations. I suspect that is a bug
8070 in OpenWindows. I don't know how to circumvent it here. */
8072 #ifdef USE_X_TOOLKIT
8073 /* If DPYINFO is null, this means we didn't open the display
8074 in the first place, so don't try to close it. */
8077 extern void (*fatal_error_signal_hook
) P_ ((void));
8078 fatal_error_signal_hook
= x_fatal_error_signal
;
8079 XtCloseDisplay (dpy
);
8080 fatal_error_signal_hook
= NULL
;
8086 xg_display_close (dpyinfo
->display
);
8091 /* Indicate that this display is dead. */
8092 dpyinfo
->display
= 0;
8094 dpyinfo
->reference_count
--;
8095 dpyinfo
->terminal
->reference_count
--;
8096 if (dpyinfo
->reference_count
!= 0)
8097 /* We have just closed all frames on this display. */
8100 x_delete_display (dpyinfo
);
8103 x_uncatch_errors ();
8105 if (terminal_list
== 0)
8107 fprintf (stderr
, "%s\n", error_msg
);
8108 shut_down_emacs (0, 0, Qnil
);
8112 /* Ordinary stack unwind doesn't deal with these. */
8114 sigunblock (sigmask (SIGIO
));
8116 sigunblock (sigmask (SIGALRM
));
8117 TOTALLY_UNBLOCK_INPUT
;
8119 unbind_to (index
, Qnil
);
8120 clear_waiting_for_input ();
8121 /* FIXME: This is an asynchronous interrupt w.r.t elisp, so signalling an
8122 error might not be the best thing to do. I'd vote for creating an
8123 elisp event and stuffing it in the queue so people can bind to it via
8124 the global map. --Stef */
8125 error ("%s", error_msg
);
8128 /* We specifically use it before defining it, so that gcc doesn't inline it,
8129 otherwise gdb doesn't know how to properly put a breakpoint on it. */
8130 static void x_error_quitter
P_ ((Display
*, XErrorEvent
*));
8132 /* This is the first-level handler for X protocol errors.
8133 It calls x_error_quitter or x_error_catcher. */
8136 x_error_handler (display
, error
)
8140 if (x_error_message
)
8141 x_error_catcher (display
, error
);
8143 x_error_quitter (display
, error
);
8147 /* This is the usual handler for X protocol errors.
8148 It kills all frames on the display that we got the error for.
8149 If that was the only one, it prints an error message and kills Emacs. */
8151 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
8153 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
8154 #define NO_INLINE __attribute__((noinline))
8159 /* Some versions of GNU/Linux define noinline in their headers. */
8165 /* On older GCC versions, just putting x_error_quitter
8166 after x_error_handler prevents inlining into the former. */
8168 static void NO_INLINE
8169 x_error_quitter (display
, error
)
8173 char buf
[256], buf1
[356];
8175 /* Ignore BadName errors. They can happen because of fonts
8176 or colors that are not defined. */
8178 if (error
->error_code
== BadName
)
8181 /* Note that there is no real way portable across R3/R4 to get the
8182 original error handler. */
8184 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
8185 sprintf (buf1
, "X protocol error: %s on protocol request %d",
8186 buf
, error
->request_code
);
8187 x_connection_closed (display
, buf1
);
8191 /* This is the handler for X IO errors, always.
8192 It kills all frames on the display that we lost touch with.
8193 If that was the only one, it prints an error message and kills Emacs. */
8196 x_io_error_quitter (display
)
8201 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
8202 x_connection_closed (display
, buf
);
8206 /* Changing the font of the frame. */
8208 /* Give frame F the font named FONTNAME as its default font, and
8209 return the full name of that font. FONTNAME may be a wildcard
8210 pattern; in that case, we choose some font that fits the pattern.
8211 The return value shows which font we chose. */
8214 x_new_font (f
, fontname
)
8216 register char *fontname
;
8218 struct font_info
*fontp
8219 = FS_LOAD_FONT (f
, fontname
);
8224 if (FRAME_FONT (f
) == (XFontStruct
*) (fontp
->font
))
8225 /* This font is already set in frame F. There's nothing more to
8227 return build_string (fontp
->full_name
);
8229 FRAME_FONT (f
) = (XFontStruct
*) (fontp
->font
);
8230 FRAME_BASELINE_OFFSET (f
) = fontp
->baseline_offset
;
8231 FRAME_FONTSET (f
) = -1;
8233 FRAME_COLUMN_WIDTH (f
) = fontp
->average_width
;
8234 FRAME_SPACE_WIDTH (f
) = fontp
->space_width
;
8235 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (FRAME_FONT (f
));
8237 compute_fringe_widths (f
, 1);
8239 /* Compute the scroll bar width in character columns. */
8240 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8242 int wid
= FRAME_COLUMN_WIDTH (f
);
8243 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8244 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
8248 int wid
= FRAME_COLUMN_WIDTH (f
);
8249 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8252 /* Now make the frame display the given font. */
8253 if (FRAME_X_WINDOW (f
) != 0)
8255 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
8256 FRAME_FONT (f
)->fid
);
8257 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
8258 FRAME_FONT (f
)->fid
);
8259 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
8260 FRAME_FONT (f
)->fid
);
8262 /* Don't change the size of a tip frame; there's no point in
8263 doing it because it's done in Fx_show_tip, and it leads to
8264 problems because the tip frame has no widget. */
8265 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8266 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8269 return build_string (fontp
->full_name
);
8272 /* Give frame F the fontset named FONTSETNAME as its default fontset,
8273 and return the full name of that fontset. FONTSETNAME may be a
8274 wildcard pattern; in that case, we choose some fontset that fits
8275 the pattern. FONTSETNAME may be a font name for ASCII characters;
8276 in that case, we create a fontset from that font name.
8278 The return value shows which fontset we chose.
8279 If FONTSETNAME specifies the default fontset, return Qt.
8280 If an ASCII font in the specified fontset can't be loaded, return
8284 x_new_fontset (f
, fontsetname
)
8286 Lisp_Object fontsetname
;
8288 int fontset
= fs_query_fontset (fontsetname
, 0);
8291 if (fontset
> 0 && f
->output_data
.x
->fontset
== fontset
)
8292 /* This fontset is already set in frame F. There's nothing more
8294 return fontset_name (fontset
);
8295 else if (fontset
== 0)
8296 /* The default fontset can't be the default font. */
8300 result
= x_new_font (f
, (SDATA (fontset_ascii (fontset
))));
8302 result
= x_new_font (f
, SDATA (fontsetname
));
8304 if (!STRINGP (result
))
8305 /* Can't load ASCII font. */
8309 fontset
= new_fontset_from_font_name (result
);
8311 /* Since x_new_font doesn't update any fontset information, do it now. */
8312 FRAME_FONTSET (f
) = fontset
;
8316 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8317 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8320 return fontset_name (fontset
);
8323 #ifdef USE_FONT_BACKEND
8325 x_new_fontset2 (f
, fontset
, font_object
)
8328 Lisp_Object font_object
;
8330 struct font
*font
= XSAVE_VALUE (font_object
)->pointer
;
8332 if (FRAME_FONT_OBJECT (f
) == font
)
8333 /* This font is already set in frame F. There's nothing more to
8335 return fontset_name (fontset
);
8339 FRAME_FONT_OBJECT (f
) = font
;
8340 FRAME_FONT (f
) = font
->font
.font
;
8341 FRAME_BASELINE_OFFSET (f
) = font
->font
.baseline_offset
;
8342 FRAME_FONTSET (f
) = fontset
;
8344 FRAME_COLUMN_WIDTH (f
) = font
->font
.average_width
;
8345 FRAME_SPACE_WIDTH (f
) = font
->font
.space_width
;
8346 FRAME_LINE_HEIGHT (f
) = font
->font
.height
;
8348 compute_fringe_widths (f
, 1);
8350 /* Compute the scroll bar width in character columns. */
8351 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8353 int wid
= FRAME_COLUMN_WIDTH (f
);
8354 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8355 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
- 1) / wid
;
8359 int wid
= FRAME_COLUMN_WIDTH (f
);
8360 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8363 /* Now make the frame display the given font. */
8364 if (FRAME_X_WINDOW (f
) != 0)
8366 /* Don't change the size of a tip frame; there's no point in
8367 doing it because it's done in Fx_show_tip, and it leads to
8368 problems because the tip frame has no widget. */
8369 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8370 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8375 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8376 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8381 return fontset_name (fontset
);
8383 #endif /* USE_FONT_BACKEND */
8386 /***********************************************************************
8388 ***********************************************************************/
8394 /* XIM destroy callback function, which is called whenever the
8395 connection to input method XIM dies. CLIENT_DATA contains a
8396 pointer to the x_display_info structure corresponding to XIM. */
8399 xim_destroy_callback (xim
, client_data
, call_data
)
8401 XPointer client_data
;
8404 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8405 Lisp_Object frame
, tail
;
8409 /* No need to call XDestroyIC.. */
8410 FOR_EACH_FRAME (tail
, frame
)
8412 struct frame
*f
= XFRAME (frame
);
8413 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8415 FRAME_XIC (f
) = NULL
;
8416 xic_free_xfontset (f
);
8420 /* No need to call XCloseIM. */
8421 dpyinfo
->xim
= NULL
;
8422 XFree (dpyinfo
->xim_styles
);
8426 #endif /* HAVE_X11R6 */
8429 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8430 extern char *XSetIMValues
P_ ((XIM
, ...));
8433 /* Open the connection to the XIM server on display DPYINFO.
8434 RESOURCE_NAME is the resource name Emacs uses. */
8437 xim_open_dpy (dpyinfo
, resource_name
)
8438 struct x_display_info
*dpyinfo
;
8439 char *resource_name
;
8446 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8453 XIMCallback destroy
;
8456 /* Get supported styles and XIM values. */
8457 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8460 destroy
.callback
= xim_destroy_callback
;
8461 destroy
.client_data
= (XPointer
)dpyinfo
;
8462 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8468 #endif /* HAVE_XIM */
8469 dpyinfo
->xim
= NULL
;
8473 #ifdef HAVE_X11R6_XIM
8477 struct x_display_info
*dpyinfo
;
8478 char *resource_name
;
8481 /* XIM instantiate callback function, which is called whenever an XIM
8482 server is available. DISPLAY is the display of the XIM.
8483 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8484 when the callback was registered. */
8487 xim_instantiate_callback (display
, client_data
, call_data
)
8489 XPointer client_data
;
8492 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8493 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8495 /* We don't support multiple XIM connections. */
8499 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8501 /* Create XIC for the existing frames on the same display, as long
8502 as they have no XIC. */
8503 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8505 Lisp_Object tail
, frame
;
8508 FOR_EACH_FRAME (tail
, frame
)
8510 struct frame
*f
= XFRAME (frame
);
8513 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8514 if (FRAME_XIC (f
) == NULL
)
8516 create_frame_xic (f
);
8517 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8518 xic_set_statusarea (f
);
8519 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8521 struct window
*w
= XWINDOW (f
->selected_window
);
8522 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8531 #endif /* HAVE_X11R6_XIM */
8534 /* Open a connection to the XIM server on display DPYINFO.
8535 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8536 connection only at the first time. On X11R6, open the connection
8537 in the XIM instantiate callback function. */
8540 xim_initialize (dpyinfo
, resource_name
)
8541 struct x_display_info
*dpyinfo
;
8542 char *resource_name
;
8547 #ifdef HAVE_X11R6_XIM
8548 struct xim_inst_t
*xim_inst
;
8551 dpyinfo
->xim
= NULL
;
8552 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8553 xim_inst
->dpyinfo
= dpyinfo
;
8554 len
= strlen (resource_name
);
8555 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8556 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8557 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8558 resource_name
, EMACS_CLASS
,
8559 xim_instantiate_callback
,
8560 /* This is XPointer in XFree86
8561 but (XPointer *) on Tru64, at
8562 least, hence the configure test. */
8563 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8564 #else /* not HAVE_X11R6_XIM */
8565 dpyinfo
->xim
= NULL
;
8566 xim_open_dpy (dpyinfo
, resource_name
);
8567 #endif /* not HAVE_X11R6_XIM */
8571 #endif /* HAVE_XIM */
8572 dpyinfo
->xim
= NULL
;
8576 /* Close the connection to the XIM server on display DPYINFO. */
8579 xim_close_dpy (dpyinfo
)
8580 struct x_display_info
*dpyinfo
;
8585 #ifdef HAVE_X11R6_XIM
8586 if (dpyinfo
->display
)
8587 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8589 xim_instantiate_callback
, NULL
);
8590 #endif /* not HAVE_X11R6_XIM */
8591 if (dpyinfo
->display
)
8592 XCloseIM (dpyinfo
->xim
);
8593 dpyinfo
->xim
= NULL
;
8594 XFree (dpyinfo
->xim_styles
);
8596 #endif /* HAVE_XIM */
8599 #endif /* not HAVE_X11R6_XIM */
8603 /* Calculate the absolute position in frame F
8604 from its current recorded position values and gravity. */
8607 x_calc_absolute_position (f
)
8610 int flags
= f
->size_hint_flags
;
8612 /* We have nothing to do if the current position
8613 is already for the top-left corner. */
8614 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8617 /* Treat negative positions as relative to the leftmost bottommost
8618 position that fits on the screen. */
8619 if (flags
& XNegative
)
8620 f
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
8621 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
);
8624 int height
= FRAME_PIXEL_HEIGHT (f
);
8626 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8627 /* Something is fishy here. When using Motif, starting Emacs with
8628 `-g -0-0', the frame appears too low by a few pixels.
8630 This seems to be so because initially, while Emacs is starting,
8631 the column widget's height and the frame's pixel height are
8632 different. The column widget's height is the right one. In
8633 later invocations, when Emacs is up, the frame's pixel height
8636 It's not obvious where the initial small difference comes from.
8637 2000-12-01, gerd. */
8639 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8642 if (flags
& YNegative
)
8643 f
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
- height
+ f
->top_pos
);
8646 /* The left_pos and top_pos
8647 are now relative to the top and left screen edges,
8648 so the flags should correspond. */
8649 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8652 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8653 to really change the position, and 0 when calling from
8654 x_make_frame_visible (in that case, XOFF and YOFF are the current
8655 position values). It is -1 when calling from x_set_frame_parameters,
8656 which means, do adjust for borders but don't change the gravity. */
8659 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8661 register int xoff
, yoff
;
8664 int modified_top
, modified_left
;
8666 if (change_gravity
!= 0)
8668 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8669 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8673 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8675 f
->size_hint_flags
|= XNegative
;
8677 f
->size_hint_flags
|= YNegative
;
8678 f
->win_gravity
= NorthWestGravity
;
8680 x_calc_absolute_position (f
);
8683 x_wm_set_size_hint (f
, (long) 0, 0);
8685 modified_left
= f
->left_pos
;
8686 modified_top
= f
->top_pos
;
8688 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8690 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8691 than the WM decorations. So we use the calculated offset instead
8692 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8693 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8694 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8697 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8698 modified_left
, modified_top
);
8700 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8701 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8704 /* change_gravity is non-zero when this function is called from Lisp to
8705 programmatically move a frame. In that case, we call
8706 x_check_expected_move to discover if we have a "Type A" or "Type B"
8707 window manager, and, for a "Type A" window manager, adjust the position
8710 We call x_check_expected_move if a programmatic move occurred, and
8711 either the window manager type (A/B) is unknown or it is Type A but we
8712 need to compute the top/left offset adjustment for this frame. */
8714 if (change_gravity
!= 0 &&
8715 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8716 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8717 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8718 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8719 x_check_expected_move (f
, modified_left
, modified_top
);
8724 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8725 on the root window for frame F contains ATOMNAME.
8726 This is how a WM check shall be done according to the Window Manager
8727 Specification/Extended Window Manager Hints at
8728 http://freedesktop.org/wiki/Specifications/wm-spec. */
8731 wm_supports (f
, atomname
)
8733 const char *atomname
;
8736 unsigned long actual_size
, bytes_remaining
;
8737 int i
, rc
, actual_format
;
8739 Window wmcheck_window
;
8740 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8741 Window target_window
= dpyinfo
->root_window
;
8742 long max_len
= 65536;
8743 Display
*dpy
= FRAME_X_DISPLAY (f
);
8744 unsigned char *tmp_data
= NULL
;
8745 Atom target_type
= XA_WINDOW
;
8750 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8752 x_catch_errors (dpy
);
8753 rc
= XGetWindowProperty (dpy
, target_window
,
8754 prop_atom
, 0, max_len
, False
, target_type
,
8755 &actual_type
, &actual_format
, &actual_size
,
8756 &bytes_remaining
, &tmp_data
);
8758 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8760 if (tmp_data
) XFree (tmp_data
);
8761 x_uncatch_errors ();
8766 wmcheck_window
= *(Window
*) tmp_data
;
8769 /* Check if window exists. */
8770 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8772 if (x_had_errors_p (dpy
))
8774 x_uncatch_errors ();
8779 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8781 /* Window changed, reload atoms */
8782 if (dpyinfo
->net_supported_atoms
!= NULL
)
8783 XFree (dpyinfo
->net_supported_atoms
);
8784 dpyinfo
->net_supported_atoms
= NULL
;
8785 dpyinfo
->nr_net_supported_atoms
= 0;
8786 dpyinfo
->net_supported_window
= 0;
8788 target_type
= XA_ATOM
;
8789 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8791 rc
= XGetWindowProperty (dpy
, target_window
,
8792 prop_atom
, 0, max_len
, False
, target_type
,
8793 &actual_type
, &actual_format
, &actual_size
,
8794 &bytes_remaining
, &tmp_data
);
8796 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8798 if (tmp_data
) XFree (tmp_data
);
8799 x_uncatch_errors ();
8804 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8805 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8806 dpyinfo
->net_supported_window
= wmcheck_window
;
8810 want_atom
= XInternAtom (dpy
, atomname
, False
);
8812 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8813 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8815 x_uncatch_errors ();
8821 /* Do fullscreen as specified in extended window manager hints */
8824 do_ewmh_fullscreen (f
)
8827 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8829 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8830 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8832 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8837 const char *atom
= "_NET_WM_STATE";
8838 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8839 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8840 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8841 const char *what
= NULL
;
8843 XSETFRAME (frame
, f
);
8845 /* If there are _NET_ atoms we assume we have extended window manager
8847 switch (f
->want_fullscreen
)
8849 case FULLSCREEN_BOTH
:
8852 case FULLSCREEN_WIDTH
:
8855 case FULLSCREEN_HEIGHT
:
8860 if (what
!= NULL
&& !wm_supports (f
, what
)) return 0;
8863 Fx_send_client_event (frame
, make_number (0), frame
,
8864 make_unibyte_string (atom
, strlen (atom
)),
8866 Fcons (make_number (0), /* Remove */
8868 (make_unibyte_string (fs
,
8871 Fx_send_client_event (frame
, make_number (0), frame
,
8872 make_unibyte_string (atom
, strlen (atom
)),
8874 Fcons (make_number (0), /* Remove */
8876 (make_unibyte_string (fh
,
8879 Fx_send_client_event (frame
, make_number (0), frame
,
8880 make_unibyte_string (atom
, strlen (atom
)),
8882 Fcons (make_number (0), /* Remove */
8884 (make_unibyte_string (fw
,
8887 f
->want_fullscreen
= FULLSCREEN_NONE
;
8889 Fx_send_client_event (frame
, make_number (0), frame
,
8890 make_unibyte_string (atom
, strlen (atom
)),
8892 Fcons (make_number (1), /* Add */
8894 (make_unibyte_string (what
,
8899 return have_net_atom
;
8903 XTfullscreen_hook (f
)
8906 if (f
->async_visible
)
8909 do_ewmh_fullscreen (f
);
8916 /* Check if we need to resize the frame due to a fullscreen request.
8917 If so needed, resize the frame. */
8919 x_check_fullscreen (f
)
8922 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
8924 int width
, height
, ign
;
8926 if (do_ewmh_fullscreen (f
))
8929 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8931 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8933 /* We do not need to move the window, it shall be taken care of
8934 when setting WM manager hints.
8935 If the frame is visible already, the position is checked by
8936 x_check_expected_move. */
8937 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8939 change_frame_size (f
, height
, width
, 0, 1, 0);
8940 SET_FRAME_GARBAGED (f
);
8941 cancel_mouse_face (f
);
8943 /* Wait for the change of frame size to occur */
8944 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
8949 /* This function is called by x_set_offset to determine whether the window
8950 manager interfered with the positioning of the frame. Type A window
8951 managers position the surrounding window manager decorations a small
8952 amount above and left of the user-supplied position. Type B window
8953 managers position the surrounding window manager decorations at the
8954 user-specified position. If we detect a Type A window manager, we
8955 compensate by moving the window right and down by the proper amount. */
8958 x_check_expected_move (f
, expected_left
, expected_top
)
8963 int current_left
= 0, current_top
= 0;
8965 /* x_real_positions returns the left and top offsets of the outermost
8966 window manager window around the frame. */
8968 x_real_positions (f
, ¤t_left
, ¤t_top
);
8970 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8972 /* It's a "Type A" window manager. */
8977 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8978 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8979 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8981 /* Now fix the mispositioned frame's location. */
8983 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8984 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8986 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8987 adjusted_left
, adjusted_top
);
8989 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8992 /* It's a "Type B" window manager. We don't have to adjust the
8993 frame's position. */
8995 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8999 /* Wait for XGetGeometry to return up-to-date position information for a
9000 recently-moved frame. Call this immediately after calling XMoveWindow.
9001 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
9002 frame has been moved to, so we use a fuzzy position comparison instead
9003 of an exact comparison. */
9006 x_sync_with_move (f
, left
, top
, fuzzy
)
9008 int left
, top
, fuzzy
;
9012 while (count
++ < 50)
9014 int current_left
= 0, current_top
= 0;
9016 /* In theory, this call to XSync only needs to happen once, but in
9017 practice, it doesn't seem to work, hence the need for the surrounding
9020 XSync (FRAME_X_DISPLAY (f
), False
);
9021 x_real_positions (f
, ¤t_left
, ¤t_top
);
9025 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
9028 if (eabs (current_left
- left
) <= 10
9029 && eabs (current_top
- top
) <= 40)
9032 else if (current_left
== left
&& current_top
== top
)
9036 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
9037 will then return up-to-date position info. */
9039 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
9043 /* Change the size of frame F's X window to COLS/ROWS in the case F
9044 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
9045 top-left-corner window gravity for this size change and subsequent
9046 size changes. Otherwise we leave the window gravity unchanged. */
9049 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
9054 int pixelwidth
, pixelheight
;
9056 check_frame_size (f
, &rows
, &cols
);
9057 f
->scroll_bar_actual_width
9058 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
9060 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
9061 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
9062 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
9064 compute_fringe_widths (f
, 0);
9066 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
9067 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
9069 f
->win_gravity
= NorthWestGravity
;
9070 x_wm_set_size_hint (f
, (long) 0, 0);
9072 XSync (FRAME_X_DISPLAY (f
), False
);
9073 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9074 pixelwidth
, pixelheight
);
9076 /* Now, strictly speaking, we can't be sure that this is accurate,
9077 but the window manager will get around to dealing with the size
9078 change request eventually, and we'll hear how it went when the
9079 ConfigureNotify event gets here.
9081 We could just not bother storing any of this information here,
9082 and let the ConfigureNotify event set everything up, but that
9083 might be kind of confusing to the Lisp code, since size changes
9084 wouldn't be reported in the frame parameters until some random
9085 point in the future when the ConfigureNotify event arrives.
9087 We pass 1 for DELAY since we can't run Lisp code inside of
9089 change_frame_size (f
, rows
, cols
, 0, 1, 0);
9090 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
9091 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
9093 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9094 receive in the ConfigureNotify event; if we get what we asked
9095 for, then the event won't cause the screen to become garbaged, so
9096 we have to make sure to do it here. */
9097 SET_FRAME_GARBAGED (f
);
9099 XFlush (FRAME_X_DISPLAY (f
));
9103 /* Call this to change the size of frame F's x-window.
9104 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
9105 for this size change and subsequent size changes.
9106 Otherwise we leave the window gravity unchanged. */
9109 x_set_window_size (f
, change_gravity
, cols
, rows
)
9117 if (FRAME_GTK_WIDGET (f
))
9118 xg_frame_set_char_size (f
, cols
, rows
);
9120 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9123 if (f
->output_data
.x
->widget
!= NULL
)
9125 /* The x and y position of the widget is clobbered by the
9126 call to XtSetValues within EmacsFrameSetCharSize.
9127 This is a real kludge, but I don't understand Xt so I can't
9128 figure out a correct fix. Can anyone else tell me? -- rms. */
9129 int xpos
= f
->output_data
.x
->widget
->core
.x
;
9130 int ypos
= f
->output_data
.x
->widget
->core
.y
;
9131 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
9132 f
->output_data
.x
->widget
->core
.x
= xpos
;
9133 f
->output_data
.x
->widget
->core
.y
= ypos
;
9136 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9138 #else /* not USE_X_TOOLKIT */
9140 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
9142 #endif /* not USE_X_TOOLKIT */
9144 /* If cursor was outside the new size, mark it as off. */
9145 mark_window_cursors_off (XWINDOW (f
->root_window
));
9147 /* Clear out any recollection of where the mouse highlighting was,
9148 since it might be in a place that's outside the new frame size.
9149 Actually checking whether it is outside is a pain in the neck,
9150 so don't try--just let the highlighting be done afresh with new size. */
9151 cancel_mouse_face (f
);
9156 /* Mouse warping. */
9159 x_set_mouse_position (f
, x
, y
)
9165 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
9166 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
9168 if (pix_x
< 0) pix_x
= 0;
9169 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
9171 if (pix_y
< 0) pix_y
= 0;
9172 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
9176 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9177 0, 0, 0, 0, pix_x
, pix_y
);
9181 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
9184 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9190 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9191 0, 0, 0, 0, pix_x
, pix_y
);
9195 /* focus shifting, raising and lowering. */
9198 x_focus_on_frame (f
)
9201 #if 0 /* This proves to be unpleasant. */
9205 /* I don't think that the ICCCM allows programs to do things like this
9206 without the interaction of the window manager. Whatever you end up
9207 doing with this code, do it to x_unfocus_frame too. */
9208 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9209 RevertToPointerRoot
, CurrentTime
);
9218 /* Look at the remarks in x_focus_on_frame. */
9219 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
9220 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
9221 RevertToPointerRoot
, CurrentTime
);
9225 /* Raise frame F. */
9232 if (f
->async_visible
)
9233 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9235 XFlush (FRAME_X_DISPLAY (f
));
9239 /* Lower frame F. */
9245 if (f
->async_visible
)
9248 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9249 XFlush (FRAME_X_DISPLAY (f
));
9254 /* Activate frame with Extended Window Manager Hints */
9257 x_ewmh_activate_frame (f
)
9260 /* See Window Manager Specification/Extended Window Manager Hints at
9261 http://freedesktop.org/wiki/Specifications/wm-spec */
9263 const char *atom
= "_NET_ACTIVE_WINDOW";
9264 if (f
->async_visible
&& wm_supports (f
, atom
))
9267 XSETFRAME (frame
, f
);
9268 Fx_send_client_event (frame
, make_number (0), frame
,
9269 make_unibyte_string (atom
, strlen (atom
)),
9271 Fcons (make_number (1),
9272 Fcons (make_number (last_user_time
),
9278 XTframe_raise_lower (f
, raise_flag
)
9288 /* Change of visibility. */
9290 /* This tries to wait until the frame is really visible.
9291 However, if the window manager asks the user where to position
9292 the frame, this will return before the user finishes doing that.
9293 The frame will not actually be visible at that time,
9294 but it will become visible later when the window manager
9295 finishes with it. */
9298 x_make_frame_visible (f
)
9302 int original_top
, original_left
;
9303 int retry_count
= 2;
9309 type
= x_icon_type (f
);
9311 x_bitmap_icon (f
, type
);
9313 if (! FRAME_VISIBLE_P (f
))
9315 /* We test FRAME_GARBAGED_P here to make sure we don't
9316 call x_set_offset a second time
9317 if we get to x_make_frame_visible a second time
9318 before the window gets really visible. */
9319 if (! FRAME_ICONIFIED_P (f
)
9320 && ! f
->output_data
.x
->asked_for_visible
)
9321 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9323 f
->output_data
.x
->asked_for_visible
= 1;
9325 if (! EQ (Vx_no_window_manager
, Qt
))
9326 x_wm_set_window_state (f
, NormalState
);
9327 #ifdef USE_X_TOOLKIT
9328 /* This was XtPopup, but that did nothing for an iconified frame. */
9329 XtMapWidget (f
->output_data
.x
->widget
);
9330 #else /* not USE_X_TOOLKIT */
9332 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9333 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9335 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9336 #endif /* not USE_GTK */
9337 #endif /* not USE_X_TOOLKIT */
9338 #if 0 /* This seems to bring back scroll bars in the wrong places
9339 if the window configuration has changed. They seem
9340 to come back ok without this. */
9341 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9342 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9346 XFlush (FRAME_X_DISPLAY (f
));
9348 /* Synchronize to ensure Emacs knows the frame is visible
9349 before we do anything else. We do this loop with input not blocked
9350 so that incoming events are handled. */
9354 /* This must be before UNBLOCK_INPUT
9355 since events that arrive in response to the actions above
9356 will set it when they are handled. */
9357 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9359 original_left
= f
->left_pos
;
9360 original_top
= f
->top_pos
;
9362 /* This must come after we set COUNT. */
9365 /* We unblock here so that arriving X events are processed. */
9367 /* Now move the window back to where it was "supposed to be".
9368 But don't do it if the gravity is negative.
9369 When the gravity is negative, this uses a position
9370 that is 3 pixels too low. Perhaps that's really the border width.
9372 Don't do this if the window has never been visible before,
9373 because the window manager may choose the position
9374 and we don't want to override it. */
9376 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
9377 && f
->win_gravity
== NorthWestGravity
9378 && previously_visible
)
9382 unsigned int width
, height
, border
, depth
;
9386 /* On some window managers (such as FVWM) moving an existing
9387 window, even to the same place, causes the window manager
9388 to introduce an offset. This can cause the window to move
9389 to an unexpected location. Check the geometry (a little
9390 slow here) and then verify that the window is in the right
9391 place. If the window is not in the right place, move it
9392 there, and take the potential window manager hit. */
9393 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9394 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9396 if (original_left
!= x
|| original_top
!= y
)
9397 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9398 original_left
, original_top
);
9403 XSETFRAME (frame
, f
);
9405 /* Wait until the frame is visible. Process X events until a
9406 MapNotify event has been seen, or until we think we won't get a
9407 MapNotify at all.. */
9408 for (count
= input_signal_count
+ 10;
9409 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9411 /* Force processing of queued events. */
9414 /* Machines that do polling rather than SIGIO have been
9415 observed to go into a busy-wait here. So we'll fake an
9416 alarm signal to let the handler know that there's something
9417 to be read. We used to raise a real alarm, but it seems
9418 that the handler isn't always enabled here. This is
9420 if (input_polling_used ())
9422 /* It could be confusing if a real alarm arrives while
9423 processing the fake one. Turn it off and let the
9424 handler reset it. */
9425 extern void poll_for_input_1
P_ ((void));
9426 int old_poll_suppress_count
= poll_suppress_count
;
9427 poll_suppress_count
= 1;
9428 poll_for_input_1 ();
9429 poll_suppress_count
= old_poll_suppress_count
;
9432 /* See if a MapNotify event has been processed. */
9433 FRAME_SAMPLE_VISIBILITY (f
);
9438 (let ((f (selected-frame)))
9442 the frame is not raised with various window managers on
9443 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9444 unknown reason, the call to XtMapWidget is completely ignored.
9445 Mapping the widget a second time works. */
9447 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9452 /* Change from mapped state to withdrawn state. */
9454 /* Make the frame visible (mapped and not iconified). */
9457 x_make_frame_invisible (f
)
9462 /* Use the frame's outermost window, not the one we normally draw on. */
9463 window
= FRAME_OUTER_WINDOW (f
);
9465 /* Don't keep the highlight on an invisible frame. */
9466 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9467 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9469 #if 0/* This might add unreliability; I don't trust it -- rms. */
9470 if (! f
->async_visible
&& ! f
->async_iconified
)
9476 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9477 that the current position of the window is user-specified, rather than
9478 program-specified, so that when the window is mapped again, it will be
9479 placed at the same location, without forcing the user to position it
9480 by hand again (they have already done that once for this window.) */
9481 x_wm_set_size_hint (f
, (long) 0, 1);
9484 if (FRAME_GTK_OUTER_WIDGET (f
))
9485 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9490 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9491 DefaultScreen (FRAME_X_DISPLAY (f
))))
9493 UNBLOCK_INPUT_RESIGNAL
;
9494 error ("Can't notify window manager of window withdrawal");
9498 /* We can't distinguish this from iconification
9499 just by the event that we get from the server.
9500 So we can't win using the usual strategy of letting
9501 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9502 and synchronize with the server to make sure we agree. */
9504 FRAME_ICONIFIED_P (f
) = 0;
9505 f
->async_visible
= 0;
9506 f
->async_iconified
= 0;
9513 /* Change window state from mapped to iconified. */
9522 /* Don't keep the highlight on an invisible frame. */
9523 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9524 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9526 if (f
->async_iconified
)
9531 FRAME_SAMPLE_VISIBILITY (f
);
9533 type
= x_icon_type (f
);
9535 x_bitmap_icon (f
, type
);
9538 if (FRAME_GTK_OUTER_WIDGET (f
))
9540 if (! FRAME_VISIBLE_P (f
))
9541 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9543 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9546 f
->async_iconified
= 1;
9547 f
->async_visible
= 0;
9553 #ifdef USE_X_TOOLKIT
9555 if (! FRAME_VISIBLE_P (f
))
9557 if (! EQ (Vx_no_window_manager
, Qt
))
9558 x_wm_set_window_state (f
, IconicState
);
9559 /* This was XtPopup, but that did nothing for an iconified frame. */
9560 XtMapWidget (f
->output_data
.x
->widget
);
9561 /* The server won't give us any event to indicate
9562 that an invisible frame was changed to an icon,
9563 so we have to record it here. */
9566 f
->async_iconified
= 1;
9567 f
->async_visible
= 0;
9572 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9573 XtWindow (f
->output_data
.x
->widget
),
9574 DefaultScreen (FRAME_X_DISPLAY (f
)));
9578 error ("Can't notify window manager of iconification");
9580 f
->async_iconified
= 1;
9581 f
->async_visible
= 0;
9585 XFlush (FRAME_X_DISPLAY (f
));
9587 #else /* not USE_X_TOOLKIT */
9589 /* Make sure the X server knows where the window should be positioned,
9590 in case the user deiconifies with the window manager. */
9591 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
9592 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9594 /* Since we don't know which revision of X we're running, we'll use both
9595 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9597 /* X11R4: send a ClientMessage to the window manager using the
9598 WM_CHANGE_STATE type. */
9602 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9603 message
.xclient
.type
= ClientMessage
;
9604 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9605 message
.xclient
.format
= 32;
9606 message
.xclient
.data
.l
[0] = IconicState
;
9608 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9609 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9611 SubstructureRedirectMask
| SubstructureNotifyMask
,
9614 UNBLOCK_INPUT_RESIGNAL
;
9615 error ("Can't notify window manager of iconification");
9619 /* X11R3: set the initial_state field of the window manager hints to
9621 x_wm_set_window_state (f
, IconicState
);
9623 if (!FRAME_VISIBLE_P (f
))
9625 /* If the frame was withdrawn, before, we must map it. */
9626 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9629 f
->async_iconified
= 1;
9630 f
->async_visible
= 0;
9632 XFlush (FRAME_X_DISPLAY (f
));
9634 #endif /* not USE_X_TOOLKIT */
9638 /* Free X resources of frame F. */
9641 x_free_frame_resources (f
)
9644 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9646 struct scroll_bar
*b
;
9650 /* If a display connection is dead, don't try sending more
9651 commands to the X server. */
9652 if (dpyinfo
->display
)
9654 #ifdef USE_FONT_BACKEND
9655 /* We must free faces before destroying windows because some
9656 font-driver (e.g. xft) access a window while finishing a
9658 if (enable_font_backend
9659 && FRAME_FACE_CACHE (f
))
9660 free_frame_faces (f
);
9661 #endif /* USE_FONT_BACKEND */
9663 if (f
->output_data
.x
->icon_desc
)
9664 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9666 #ifdef USE_X_TOOLKIT
9667 /* Explicitly destroy the scroll bars of the frame. Without
9668 this, we get "BadDrawable" errors from the toolkit later on,
9669 presumably from expose events generated for the disappearing
9670 toolkit scroll bars. */
9671 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9673 b
= XSCROLL_BAR (bar
);
9674 x_scroll_bar_remove (b
);
9683 #ifdef USE_X_TOOLKIT
9684 if (f
->output_data
.x
->widget
)
9686 XtDestroyWidget (f
->output_data
.x
->widget
);
9687 f
->output_data
.x
->widget
= NULL
;
9689 /* Tooltips don't have widgets, only a simple X window, even if
9690 we are using a toolkit. */
9691 else if (FRAME_X_WINDOW (f
))
9692 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9694 free_frame_menubar (f
);
9695 #else /* !USE_X_TOOLKIT */
9698 /* In the GTK version, tooltips are normal X
9699 frames. We must check and free both types. */
9700 if (FRAME_GTK_OUTER_WIDGET (f
))
9702 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9703 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9704 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9706 #endif /* USE_GTK */
9708 if (FRAME_X_WINDOW (f
))
9709 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9710 #endif /* !USE_X_TOOLKIT */
9712 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9713 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9714 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9715 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9716 unload_color (f
, f
->output_data
.x
->border_pixel
);
9717 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9719 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9720 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9721 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9722 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9723 #ifdef USE_TOOLKIT_SCROLL_BARS
9724 /* Scrollbar shadow colors. */
9725 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9726 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9727 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9728 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9729 #endif /* USE_TOOLKIT_SCROLL_BARS */
9730 if (f
->output_data
.x
->white_relief
.allocated_p
)
9731 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9732 if (f
->output_data
.x
->black_relief
.allocated_p
)
9733 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9735 if (FRAME_FACE_CACHE (f
))
9736 free_frame_faces (f
);
9739 XFlush (FRAME_X_DISPLAY (f
));
9742 if (f
->output_data
.x
->saved_menu_event
)
9743 xfree (f
->output_data
.x
->saved_menu_event
);
9745 xfree (f
->output_data
.x
);
9746 f
->output_data
.x
= NULL
;
9748 if (f
== dpyinfo
->x_focus_frame
)
9749 dpyinfo
->x_focus_frame
= 0;
9750 if (f
== dpyinfo
->x_focus_event_frame
)
9751 dpyinfo
->x_focus_event_frame
= 0;
9752 if (f
== dpyinfo
->x_highlight_frame
)
9753 dpyinfo
->x_highlight_frame
= 0;
9755 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9757 dpyinfo
->mouse_face_beg_row
9758 = dpyinfo
->mouse_face_beg_col
= -1;
9759 dpyinfo
->mouse_face_end_row
9760 = dpyinfo
->mouse_face_end_col
= -1;
9761 dpyinfo
->mouse_face_window
= Qnil
;
9762 dpyinfo
->mouse_face_deferred_gc
= 0;
9763 dpyinfo
->mouse_face_mouse_frame
= 0;
9770 /* Destroy the X window of frame F. */
9773 x_destroy_window (f
)
9776 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9778 /* If a display connection is dead, don't try sending more
9779 commands to the X server. */
9780 if (dpyinfo
->display
!= 0)
9781 x_free_frame_resources (f
);
9783 dpyinfo
->reference_count
--;
9787 /* Setting window manager hints. */
9789 /* Set the normal size hints for the window manager, for frame F.
9790 FLAGS is the flags word to use--or 0 meaning preserve the flags
9791 that the window now has.
9792 If USER_POSITION is nonzero, we set the USPosition
9793 flag (this is useful when FLAGS is 0).
9794 The GTK version is in gtkutils.c */
9798 x_wm_set_size_hint (f
, flags
, user_position
)
9803 XSizeHints size_hints
;
9805 #ifdef USE_X_TOOLKIT
9808 Dimension widget_width
, widget_height
;
9811 Window window
= FRAME_OUTER_WINDOW (f
);
9813 /* Setting PMaxSize caused various problems. */
9814 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9816 size_hints
.x
= f
->left_pos
;
9817 size_hints
.y
= f
->top_pos
;
9819 #ifdef USE_X_TOOLKIT
9820 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9821 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9822 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9823 size_hints
.height
= widget_height
;
9824 size_hints
.width
= widget_width
;
9825 #else /* not USE_X_TOOLKIT */
9826 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9827 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9828 #endif /* not USE_X_TOOLKIT */
9830 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9831 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9832 size_hints
.max_width
9833 = FRAME_X_DISPLAY_INFO (f
)->width
- FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9834 size_hints
.max_height
9835 = FRAME_X_DISPLAY_INFO (f
)->height
- FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9837 /* Calculate the base and minimum sizes.
9839 (When we use the X toolkit, we don't do it here.
9840 Instead we copy the values that the widgets are using, below.) */
9841 #ifndef USE_X_TOOLKIT
9843 int base_width
, base_height
;
9844 int min_rows
= 0, min_cols
= 0;
9846 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9847 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9849 check_frame_size (f
, &min_rows
, &min_cols
);
9851 /* The window manager uses the base width hints to calculate the
9852 current number of rows and columns in the frame while
9853 resizing; min_width and min_height aren't useful for this
9854 purpose, since they might not give the dimensions for a
9855 zero-row, zero-column frame.
9857 We use the base_width and base_height members if we have
9858 them; otherwise, we set the min_width and min_height members
9859 to the size for a zero x zero frame. */
9861 size_hints
.flags
|= PBaseSize
;
9862 size_hints
.base_width
= base_width
;
9863 size_hints
.base_height
= base_height
;
9864 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9865 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9868 /* If we don't need the old flags, we don't need the old hint at all. */
9871 size_hints
.flags
|= flags
;
9874 #endif /* not USE_X_TOOLKIT */
9877 XSizeHints hints
; /* Sometimes I hate X Windows... */
9878 long supplied_return
;
9881 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9884 #ifdef USE_X_TOOLKIT
9885 size_hints
.base_height
= hints
.base_height
;
9886 size_hints
.base_width
= hints
.base_width
;
9887 size_hints
.min_height
= hints
.min_height
;
9888 size_hints
.min_width
= hints
.min_width
;
9892 size_hints
.flags
|= flags
;
9897 if (hints
.flags
& PSize
)
9898 size_hints
.flags
|= PSize
;
9899 if (hints
.flags
& PPosition
)
9900 size_hints
.flags
|= PPosition
;
9901 if (hints
.flags
& USPosition
)
9902 size_hints
.flags
|= USPosition
;
9903 if (hints
.flags
& USSize
)
9904 size_hints
.flags
|= USSize
;
9908 #ifndef USE_X_TOOLKIT
9913 size_hints
.win_gravity
= f
->win_gravity
;
9914 size_hints
.flags
|= PWinGravity
;
9918 size_hints
.flags
&= ~ PPosition
;
9919 size_hints
.flags
|= USPosition
;
9921 #endif /* PWinGravity */
9923 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9925 #endif /* not USE_GTK */
9927 /* Used for IconicState or NormalState */
9930 x_wm_set_window_state (f
, state
)
9934 #ifdef USE_X_TOOLKIT
9937 XtSetArg (al
[0], XtNinitialState
, state
);
9938 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9939 #else /* not USE_X_TOOLKIT */
9940 Window window
= FRAME_X_WINDOW (f
);
9942 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9943 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9945 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9946 #endif /* not USE_X_TOOLKIT */
9950 x_wm_set_icon_pixmap (f
, pixmap_id
)
9954 Pixmap icon_pixmap
, icon_mask
;
9956 #ifndef USE_X_TOOLKIT
9957 Window window
= FRAME_OUTER_WINDOW (f
);
9962 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9963 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9964 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9965 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9969 /* It seems there is no way to turn off use of an icon pixmap.
9970 The following line does it, only if no icon has yet been created,
9971 for some window managers. But with mwm it crashes.
9972 Some people say it should clear the IconPixmapHint bit in this case,
9973 but that doesn't work, and the X consortium said it isn't the
9974 right thing at all. Since there is no way to win,
9975 best to explicitly give up. */
9977 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
9978 f
->output_data
.x
->wm_hints
.icon_mask
= None
;
9987 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9991 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9995 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9996 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9997 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9998 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10001 #else /* not USE_X_TOOLKIT && not USE_GTK */
10003 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
10004 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10006 #endif /* not USE_X_TOOLKIT && not USE_GTK */
10010 x_wm_set_icon_position (f
, icon_x
, icon_y
)
10012 int icon_x
, icon_y
;
10014 Window window
= FRAME_OUTER_WINDOW (f
);
10016 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
10017 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
10018 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
10020 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10024 /***********************************************************************
10026 ***********************************************************************/
10028 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
10031 x_get_font_info (f
, font_idx
)
10035 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
10039 /* Return a list of names of available fonts matching PATTERN on frame F.
10041 If SIZE is > 0, it is the size (maximum bounds width) of fonts
10044 SIZE < 0 means include auto scaled fonts.
10046 Frame F null means we have not yet created any frame on X, and
10047 consult the first display in x_display_list. MAXNAMES sets a limit
10048 on how many fonts to match. */
10051 x_list_fonts (f
, pattern
, size
, maxnames
)
10053 Lisp_Object pattern
;
10057 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
10058 Lisp_Object tem
, second_best
;
10059 struct x_display_info
*dpyinfo
10060 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
10061 Display
*dpy
= dpyinfo
->display
;
10062 int try_XLoadQueryFont
= 0;
10063 int allow_auto_scaled_font
= 0;
10067 allow_auto_scaled_font
= 1;
10071 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
10072 if (NILP (patterns
))
10073 patterns
= Fcons (pattern
, Qnil
);
10075 if (maxnames
== 1 && !size
)
10076 /* We can return any single font matching PATTERN. */
10077 try_XLoadQueryFont
= 1;
10079 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
10082 char **names
= NULL
;
10084 pattern
= XCAR (patterns
);
10085 /* See if we cached the result for this particular query.
10086 The cache is an alist of the form:
10087 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
10088 tem
= XCDR (dpyinfo
->name_list_element
);
10089 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
10090 allow_auto_scaled_font
? Qt
: Qnil
);
10091 list
= Fassoc (key
, tem
);
10094 list
= Fcdr_safe (list
);
10095 /* We have a cashed list. Don't have to get the list again. */
10099 /* At first, put PATTERN in the cache. */
10102 x_catch_errors (dpy
);
10104 if (try_XLoadQueryFont
)
10107 unsigned long value
;
10109 font
= XLoadQueryFont (dpy
, SDATA (pattern
));
10110 if (x_had_errors_p (dpy
))
10112 /* This error is perhaps due to insufficient memory on X
10113 server. Let's just ignore it. */
10115 x_clear_errors (dpy
);
10119 && XGetFontProperty (font
, XA_FONT
, &value
))
10121 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
10122 int len
= strlen (name
);
10125 /* If DXPC (a Differential X Protocol Compressor)
10126 Ver.3.7 is running, XGetAtomName will return null
10127 string. We must avoid such a name. */
10129 try_XLoadQueryFont
= 0;
10133 names
= (char **) alloca (sizeof (char *));
10134 /* Some systems only allow alloca assigned to a
10136 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
10137 bcopy (name
, names
[0], len
+ 1);
10142 try_XLoadQueryFont
= 0;
10145 XFreeFont (dpy
, font
);
10148 if (!try_XLoadQueryFont
)
10150 /* We try at least 10 fonts because XListFonts will return
10151 auto-scaled fonts at the head. */
10156 for (limit
= 500;;)
10158 names
= XListFonts (dpy
, SDATA (pattern
), limit
, &num_fonts
);
10159 if (num_fonts
== limit
)
10162 XFreeFontNames (names
);
10171 names
= XListFonts (dpy
, SDATA (pattern
), max (maxnames
, 10),
10174 if (x_had_errors_p (dpy
))
10176 /* This error is perhaps due to insufficient memory on X
10177 server. Let's just ignore it. */
10179 x_clear_errors (dpy
);
10183 x_uncatch_errors ();
10190 /* Make a list of all the fonts we got back.
10191 Store that in the font cache for the display. */
10192 for (i
= 0; i
< num_fonts
; i
++)
10195 char *p
= names
[i
];
10196 int average_width
= -1, resx
= 0, dashes
= 0;
10198 /* Count the number of dashes in NAMES[I]. If there are
10199 14 dashes, the field value following 9th dash
10200 (RESOLUTION_X) is nonzero, and the field value
10201 following 12th dash (AVERAGE_WIDTH) is 0, this is a
10202 auto-scaled font which is usually too ugly to be used
10203 for editing. Let's ignore it. */
10208 if (dashes
== 7) /* PIXEL_SIZE field */
10210 else if (dashes
== 9)
10212 else if (dashes
== 12) /* AVERAGE_WIDTH field */
10213 average_width
= atoi (p
);
10216 if (allow_auto_scaled_font
10217 || dashes
< 14 || average_width
!= 0 || resx
== 0)
10219 tem
= build_string (names
[i
]);
10220 if (NILP (Fassoc (tem
, list
)))
10222 if (STRINGP (Vx_pixel_size_width_font_regexp
)
10223 && ((fast_c_string_match_ignore_case
10224 (Vx_pixel_size_width_font_regexp
, names
[i
]))
10226 /* We can set the value of PIXEL_SIZE to the
10227 width of this font. */
10228 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
10230 /* For the moment, width is not known. */
10231 list
= Fcons (Fcons (tem
, Qnil
), list
);
10236 if (!try_XLoadQueryFont
)
10239 XFreeFontNames (names
);
10244 /* Now store the result in the cache. */
10245 XSETCDR (dpyinfo
->name_list_element
,
10246 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
10249 if (NILP (list
)) continue; /* Try the remaining alternatives. */
10251 newlist
= second_best
= Qnil
;
10252 /* Make a list of the fonts that have the right width. */
10253 for (; CONSP (list
); list
= XCDR (list
))
10259 if (!CONSP (tem
) || NILP (XCAR (tem
)))
10263 newlist
= Fcons (XCAR (tem
), newlist
);
10267 if (!INTEGERP (XCDR (tem
)))
10269 /* Since we have not yet known the size of this font, we
10270 must try slow function call XLoadQueryFont. */
10271 XFontStruct
*thisinfo
;
10274 x_catch_errors (dpy
);
10275 thisinfo
= XLoadQueryFont (dpy
,
10276 SDATA (XCAR (tem
)));
10277 if (x_had_errors_p (dpy
))
10279 /* This error is perhaps due to insufficient memory on X
10280 server. Let's just ignore it. */
10282 x_clear_errors (dpy
);
10284 x_uncatch_errors ();
10290 (thisinfo
->min_bounds
.width
== 0
10292 : make_number (thisinfo
->max_bounds
.width
)));
10294 XFreeFont (dpy
, thisinfo
);
10298 /* For unknown reason, the previous call of XListFont had
10299 returned a font which can't be opened. Record the size
10300 as 0 not to try to open it again. */
10301 XSETCDR (tem
, make_number (0));
10304 found_size
= XINT (XCDR (tem
));
10305 if (found_size
== size
)
10306 newlist
= Fcons (XCAR (tem
), newlist
);
10307 else if (found_size
> 0)
10309 if (NILP (second_best
))
10311 else if (found_size
< size
)
10313 if (XINT (XCDR (second_best
)) > size
10314 || XINT (XCDR (second_best
)) < found_size
)
10319 if (XINT (XCDR (second_best
)) > size
10320 && XINT (XCDR (second_best
)) > found_size
)
10325 if (!NILP (newlist
))
10327 else if (!NILP (second_best
))
10329 newlist
= Fcons (XCAR (second_best
), Qnil
);
10340 /* Check that FONT is valid on frame F. It is if it can be found in F's
10344 x_check_font (f
, font
)
10349 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10351 xassert (font
!= NULL
);
10353 #ifdef USE_FONT_BACKEND
10354 if (enable_font_backend
)
10355 /* Fixme: Perhaps we should check all cached fonts. */
10358 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10359 if (dpyinfo
->font_table
[i
].name
10360 && font
== dpyinfo
->font_table
[i
].font
)
10363 xassert (i
< dpyinfo
->n_fonts
);
10366 #endif /* GLYPH_DEBUG != 0 */
10368 /* Set *W to the minimum width, *H to the minimum font height of FONT.
10369 Note: There are (broken) X fonts out there with invalid XFontStruct
10370 min_bounds contents. For example, handa@etl.go.jp reports that
10371 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
10372 have font->min_bounds.width == 0. */
10375 x_font_min_bounds (font
, w
, h
)
10379 *h
= FONT_HEIGHT (font
);
10380 *w
= font
->min_bounds
.width
;
10382 /* Try to handle the case where FONT->min_bounds has invalid
10383 contents. Since the only font known to have invalid min_bounds
10384 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
10386 *w
= font
->max_bounds
.width
;
10390 /* Compute the smallest character width and smallest font height over
10391 all fonts available on frame F. Set the members smallest_char_width
10392 and smallest_font_height in F's x_display_info structure to
10393 the values computed. Value is non-zero if smallest_font_height or
10394 smallest_char_width become smaller than they were before. */
10397 x_compute_min_glyph_bounds (f
)
10401 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10403 int old_width
= dpyinfo
->smallest_char_width
;
10404 int old_height
= dpyinfo
->smallest_font_height
;
10406 dpyinfo
->smallest_font_height
= 100000;
10407 dpyinfo
->smallest_char_width
= 100000;
10409 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10410 if (dpyinfo
->font_table
[i
].name
)
10412 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
10415 font
= (XFontStruct
*) fontp
->font
;
10416 xassert (font
!= (XFontStruct
*) ~0);
10417 x_font_min_bounds (font
, &w
, &h
);
10419 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
10420 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
10423 xassert (dpyinfo
->smallest_char_width
> 0
10424 && dpyinfo
->smallest_font_height
> 0);
10426 return (dpyinfo
->n_fonts
== 1
10427 || dpyinfo
->smallest_char_width
< old_width
10428 || dpyinfo
->smallest_font_height
< old_height
);
10432 /* Load font named FONTNAME of the size SIZE for frame F, and return a
10433 pointer to the structure font_info while allocating it dynamically.
10434 If SIZE is 0, load any size of font.
10435 If loading is failed, return NULL. */
10438 x_load_font (f
, fontname
, size
)
10440 register char *fontname
;
10443 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10444 Lisp_Object font_names
;
10446 /* Get a list of all the fonts that match this name. Once we
10447 have a list of matching fonts, we compare them against the fonts
10448 we already have by comparing names. */
10449 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
10451 if (!NILP (font_names
))
10456 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10457 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
10458 if (dpyinfo
->font_table
[i
].name
10459 && (!strcmp (dpyinfo
->font_table
[i
].name
,
10460 SDATA (XCAR (tail
)))
10461 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
10462 SDATA (XCAR (tail
)))))
10463 return (dpyinfo
->font_table
+ i
);
10466 /* Load the font and add it to the table. */
10470 struct font_info
*fontp
;
10471 unsigned long value
;
10474 /* If we have found fonts by x_list_font, load one of them. If
10475 not, we still try to load a font by the name given as FONTNAME
10476 because XListFonts (called in x_list_font) of some X server has
10477 a bug of not finding a font even if the font surely exists and
10478 is loadable by XLoadQueryFont. */
10479 if (size
> 0 && !NILP (font_names
))
10480 fontname
= (char *) SDATA (XCAR (font_names
));
10483 x_catch_errors (FRAME_X_DISPLAY (f
));
10484 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
10485 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
10487 /* This error is perhaps due to insufficient memory on X
10488 server. Let's just ignore it. */
10490 x_clear_errors (FRAME_X_DISPLAY (f
));
10492 x_uncatch_errors ();
10497 /* Find a free slot in the font table. */
10498 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
10499 if (dpyinfo
->font_table
[i
].name
== NULL
)
10502 /* If no free slot found, maybe enlarge the font table. */
10503 if (i
== dpyinfo
->n_fonts
10504 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
10507 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
10508 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
10509 dpyinfo
->font_table
10510 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
10513 fontp
= dpyinfo
->font_table
+ i
;
10514 if (i
== dpyinfo
->n_fonts
)
10515 ++dpyinfo
->n_fonts
;
10517 /* Now fill in the slots of *FONTP. */
10519 bzero (fontp
, sizeof (*fontp
));
10520 fontp
->font
= font
;
10521 fontp
->font_idx
= i
;
10522 fontp
->charset
= -1; /* fs_load_font sets it. */
10523 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
10524 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
10526 if (font
->min_bounds
.width
== font
->max_bounds
.width
)
10528 /* Fixed width font. */
10529 fontp
->average_width
= fontp
->space_width
= font
->min_bounds
.width
;
10536 char2b
.byte1
= 0x00, char2b
.byte2
= 0x20;
10537 pcm
= x_per_char_metric (font
, &char2b
, 0);
10539 fontp
->space_width
= pcm
->width
;
10541 fontp
->space_width
= FONT_WIDTH (font
);
10543 fontp
->average_width
10544 = (XGetFontProperty (font
, dpyinfo
->Xatom_AVERAGE_WIDTH
, &value
)
10545 ? (long) value
/ 10 : 0);
10546 if (fontp
->average_width
< 0)
10547 fontp
->average_width
= - fontp
->average_width
;
10548 if (fontp
->average_width
== 0)
10552 int width
= pcm
->width
;
10553 for (char2b
.byte2
= 33; char2b
.byte2
<= 126; char2b
.byte2
++)
10554 if ((pcm
= x_per_char_metric (font
, &char2b
, 0)) != NULL
)
10555 width
+= pcm
->width
;
10556 fontp
->average_width
= width
/ 95;
10559 fontp
->average_width
= FONT_WIDTH (font
);
10563 /* Try to get the full name of FONT. Put it in FULL_NAME. */
10565 if (XGetFontProperty (font
, XA_FONT
, &value
))
10567 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
10571 /* Count the number of dashes in the "full name".
10572 If it is too few, this isn't really the font's full name,
10574 In X11R4, the fonts did not come with their canonical names
10585 full_name
= (char *) xmalloc (p
- name
+ 1);
10586 bcopy (name
, full_name
, p
- name
+ 1);
10592 if (full_name
!= 0)
10593 fontp
->full_name
= full_name
;
10595 fontp
->full_name
= fontp
->name
;
10597 fontp
->size
= font
->max_bounds
.width
;
10598 fontp
->height
= FONT_HEIGHT (font
);
10600 if (NILP (font_names
))
10602 /* We come here because of a bug of XListFonts mentioned at
10603 the head of this block. Let's store this information in
10604 the cache for x_list_fonts. */
10605 Lisp_Object lispy_name
= build_string (fontname
);
10606 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
10607 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
10610 XSETCDR (dpyinfo
->name_list_element
,
10612 Fcons (Fcons (lispy_full_name
,
10613 make_number (fontp
->size
)),
10615 XCDR (dpyinfo
->name_list_element
)));
10618 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
10620 XSETCDR (dpyinfo
->name_list_element
,
10622 Fcons (Fcons (lispy_full_name
,
10623 make_number (fontp
->size
)),
10625 XCDR (dpyinfo
->name_list_element
)));
10629 /* The slot `encoding' specifies how to map a character
10630 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
10631 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
10632 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
10633 2:0xA020..0xFF7F). For the moment, we don't know which charset
10634 uses this font. So, we set information in fontp->encoding_type
10635 which is never used by any charset. If mapping can't be
10636 decided, set FONT_ENCODING_NOT_DECIDED. */
10637 fontp
->encoding_type
10638 = (font
->max_byte1
== 0
10640 ? (font
->min_char_or_byte2
< 0x80
10641 ? (font
->max_char_or_byte2
< 0x80
10642 ? 0 /* 0x20..0x7F */
10643 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
10644 : 1) /* 0xA0..0xFF */
10646 : (font
->min_byte1
< 0x80
10647 ? (font
->max_byte1
< 0x80
10648 ? (font
->min_char_or_byte2
< 0x80
10649 ? (font
->max_char_or_byte2
< 0x80
10650 ? 0 /* 0x2020..0x7F7F */
10651 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
10652 : 3) /* 0x20A0..0x7FFF */
10653 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
10654 : (font
->min_char_or_byte2
< 0x80
10655 ? (font
->max_char_or_byte2
< 0x80
10656 ? 2 /* 0xA020..0xFF7F */
10657 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
10658 : 1))); /* 0xA0A0..0xFFFF */
10660 fontp
->baseline_offset
10661 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
10662 ? (long) value
: 0);
10663 fontp
->relative_compose
10664 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
10665 ? (long) value
: 0);
10666 fontp
->default_ascent
10667 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
10668 ? (long) value
: 0);
10670 /* Set global flag fonts_changed_p to non-zero if the font loaded
10671 has a character with a smaller width than any other character
10672 before, or if the font loaded has a smaller height than any
10673 other font loaded before. If this happens, it will make a
10674 glyph matrix reallocation necessary. */
10675 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
10682 /* Return a pointer to struct font_info of a font named FONTNAME for
10683 frame F. If no such font is loaded, return NULL. */
10686 x_query_font (f
, fontname
)
10688 register char *fontname
;
10690 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10693 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
10694 if (dpyinfo
->font_table
[i
].name
10695 && (!xstricmp (dpyinfo
->font_table
[i
].name
, fontname
)
10696 || !xstricmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
10697 return (dpyinfo
->font_table
+ i
);
10702 /* Find a CCL program for a font specified by FONTP, and set the member
10703 `encoder' of the structure. */
10706 x_find_ccl_program (fontp
)
10707 struct font_info
*fontp
;
10709 Lisp_Object list
, elt
;
10712 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
10716 && STRINGP (XCAR (elt
))
10717 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
10719 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
10726 struct ccl_program
*ccl
10727 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
10729 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
10732 fontp
->font_encoder
= ccl
;
10737 /* Return a char-table whose elements are t if the font FONT_INFO
10738 contains a glyph for the corresponding character, and nil if
10742 x_get_font_repertory (f
, font_info
)
10744 struct font_info
*font_info
;
10746 XFontStruct
*font
= (XFontStruct
*) font_info
->font
;
10748 int min_byte1
, max_byte1
, min_byte2
, max_byte2
;
10750 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
10751 int offset
= CHARSET_OFFSET (charset
);
10753 table
= Fmake_char_table (Qnil
, Qnil
);
10755 min_byte1
= font
->min_byte1
;
10756 max_byte1
= font
->max_byte1
;
10757 min_byte2
= font
->min_char_or_byte2
;
10758 max_byte2
= font
->max_char_or_byte2
;
10759 if (min_byte1
== 0 && max_byte1
== 0)
10761 if (! font
->per_char
|| font
->all_chars_exist
== True
)
10764 char_table_set_range (table
, offset
+ min_byte2
,
10765 offset
+ max_byte2
, Qt
);
10767 for (; min_byte2
<= max_byte2
; min_byte2
++)
10769 c
= DECODE_CHAR (charset
, min_byte2
);
10770 CHAR_TABLE_SET (table
, c
, Qt
);
10775 XCharStruct
*pcm
= font
->per_char
;
10779 for (i
= min_byte2
; i
<= max_byte2
; i
++, pcm
++)
10781 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
10786 char_table_set_range (table
, offset
+ from
,
10787 offset
+ i
- 1, Qt
);
10789 for (; from
< i
; from
++)
10791 c
= DECODE_CHAR (charset
, from
);
10792 CHAR_TABLE_SET (table
, c
, Qt
);
10803 char_table_set_range (table
, offset
+ from
, offset
+ i
- 1,
10806 for (; from
< i
; from
++)
10808 c
= DECODE_CHAR (charset
, from
);
10809 CHAR_TABLE_SET (table
, c
, Qt
);
10816 if (! font
->per_char
|| font
->all_chars_exist
== True
)
10821 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10822 char_table_set_range
10823 (table
, offset
+ ((i
<< 8) | min_byte2
),
10824 offset
+ ((i
<< 8) | max_byte2
), Qt
);
10826 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10827 for (j
= min_byte2
; j
<= max_byte2
; j
++)
10829 unsigned code
= (i
<< 8) | j
;
10830 c
= DECODE_CHAR (charset
, code
);
10831 CHAR_TABLE_SET (table
, c
, Qt
);
10836 XCharStruct
*pcm
= font
->per_char
;
10839 for (i
= min_byte1
; i
<= max_byte1
; i
++)
10844 for (j
= min_byte2
; j
<= max_byte2
; j
++, pcm
++)
10846 if (pcm
->width
== 0 && pcm
->rbearing
== pcm
->lbearing
)
10851 char_table_set_range
10852 (table
, offset
+ ((i
<< 8) | from
),
10853 offset
+ ((i
<< 8) | (j
- 1)), Qt
);
10856 for (; from
< j
; from
++)
10858 unsigned code
= (i
<< 8) | from
;
10859 c
= ENCODE_CHAR (charset
, code
);
10860 CHAR_TABLE_SET (table
, c
, Qt
);
10872 char_table_set_range
10873 (table
, offset
+ ((i
<< 8) | from
),
10874 offset
+ ((i
<< 8) | (j
- 1)), Qt
);
10877 for (; from
< j
; from
++)
10879 unsigned code
= (i
<< 8) | from
;
10880 c
= DECODE_CHAR (charset
, code
);
10881 CHAR_TABLE_SET (table
, c
, Qt
);
10892 /***********************************************************************
10894 ***********************************************************************/
10896 #ifdef USE_X_TOOLKIT
10897 static XrmOptionDescRec emacs_options
[] = {
10898 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
10899 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
10901 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
10902 XrmoptionSepArg
, NULL
},
10903 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
10905 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10906 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10907 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10908 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10909 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10910 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
10911 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
10914 /* Whether atimer for Xt timeouts is activated or not. */
10916 static int x_timeout_atimer_activated_flag
;
10918 #endif /* USE_X_TOOLKIT */
10920 static int x_initialized
;
10923 static int x_session_initialized
;
10926 #ifdef MULTI_KBOARD
10927 /* Test whether two display-name strings agree up to the dot that separates
10928 the screen number from the server number. */
10930 same_x_server (name1
, name2
)
10931 const char *name1
, *name2
;
10933 int seen_colon
= 0;
10934 const unsigned char *system_name
= SDATA (Vsystem_name
);
10935 int system_name_length
= strlen (system_name
);
10936 int length_until_period
= 0;
10938 while (system_name
[length_until_period
] != 0
10939 && system_name
[length_until_period
] != '.')
10940 length_until_period
++;
10942 /* Treat `unix' like an empty host name. */
10943 if (! strncmp (name1
, "unix:", 5))
10945 if (! strncmp (name2
, "unix:", 5))
10947 /* Treat this host's name like an empty host name. */
10948 if (! strncmp (name1
, system_name
, system_name_length
)
10949 && name1
[system_name_length
] == ':')
10950 name1
+= system_name_length
;
10951 if (! strncmp (name2
, system_name
, system_name_length
)
10952 && name2
[system_name_length
] == ':')
10953 name2
+= system_name_length
;
10954 /* Treat this host's domainless name like an empty host name. */
10955 if (! strncmp (name1
, system_name
, length_until_period
)
10956 && name1
[length_until_period
] == ':')
10957 name1
+= length_until_period
;
10958 if (! strncmp (name2
, system_name
, length_until_period
)
10959 && name2
[length_until_period
] == ':')
10960 name2
+= length_until_period
;
10962 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
10966 if (seen_colon
&& *name1
== '.')
10970 && (*name1
== '.' || *name1
== '\0')
10971 && (*name2
== '.' || *name2
== '\0'));
10975 /* Count number of set bits in mask and number of bits to shift to
10976 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
10979 get_bits_and_offset (mask
, bits
, offset
)
10980 unsigned long mask
;
10987 while (!(mask
& 1))
11003 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
11004 But don't permanently open it, just test its availability. */
11007 x_display_ok (display
)
11008 const char *display
;
11013 dpy
= XOpenDisplay (display
);
11015 XCloseDisplay (dpy
);
11021 /* Open a connection to X display DISPLAY_NAME, and return
11022 the structure that describes the open display.
11023 If we cannot contact the display, return null. */
11025 struct x_display_info
*
11026 x_term_init (display_name
, xrm_option
, resource_name
)
11027 Lisp_Object display_name
;
11029 char *resource_name
;
11033 struct terminal
*terminal
;
11034 struct x_display_info
*dpyinfo
;
11039 if (!x_initialized
)
11045 if (! x_display_ok (SDATA (display_name
)))
11046 error ("Display %s can't be opened", SDATA (display_name
));
11050 #define NUM_ARGV 10
11052 char *argv
[NUM_ARGV
];
11053 char **argv2
= argv
;
11056 #ifndef HAVE_GTK_MULTIDISPLAY
11057 if (!EQ (Vinitial_window_system
, intern ("x")))
11058 error ("Sorry, you cannot connect to X servers with the GTK toolkit");
11061 if (x_initialized
++ > 1)
11063 #ifdef HAVE_GTK_MULTIDISPLAY
11064 /* Opening another display. If xg_display_open returns less
11065 than zero, we are probably on GTK 2.0, which can only handle
11066 one display. GTK 2.2 or later can handle more than one. */
11067 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
11069 error ("Sorry, this version of GTK can only handle one display");
11073 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
11077 argv
[argc
++] = initial_argv
[0];
11079 if (! NILP (display_name
))
11081 argv
[argc
++] = "--display";
11082 argv
[argc
++] = SDATA (display_name
);
11085 argv
[argc
++] = "--name";
11086 argv
[argc
++] = resource_name
;
11088 XSetLocaleModifiers ("");
11090 gtk_init (&argc
, &argv2
);
11092 /* gtk_init does set_locale. We must fix locale after calling it. */
11096 dpy
= GDK_DISPLAY ();
11098 /* NULL window -> events for all windows go to our function */
11099 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
11101 /* Load our own gtkrc if it exists. */
11103 char *file
= "~/.emacs.d/gtkrc";
11104 Lisp_Object s
, abs_file
;
11106 s
= make_string (file
, strlen (file
));
11107 abs_file
= Fexpand_file_name (s
, Qnil
);
11109 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
11110 gtk_rc_parse (SDATA (abs_file
));
11113 XSetErrorHandler (x_error_handler
);
11114 XSetIOErrorHandler (x_io_error_quitter
);
11117 #else /* not USE_GTK */
11118 #ifdef USE_X_TOOLKIT
11119 /* weiner@footloose.sps.mot.com reports that this causes
11121 X protocol error: BadAtom (invalid Atom parameter)
11122 on protocol request 18skiloaf.
11123 So let's not use it until R6. */
11124 #ifdef HAVE_X11XTR6
11125 XtSetLanguageProc (NULL
, NULL
, NULL
);
11136 argv
[argc
++] = "-xrm";
11137 argv
[argc
++] = xrm_option
;
11139 turn_on_atimers (0);
11140 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
11141 resource_name
, EMACS_CLASS
,
11142 emacs_options
, XtNumber (emacs_options
),
11144 turn_on_atimers (1);
11146 #ifdef HAVE_X11XTR6
11147 /* I think this is to compensate for XtSetLanguageProc. */
11152 #else /* not USE_X_TOOLKIT */
11153 XSetLocaleModifiers ("");
11154 dpy
= XOpenDisplay (SDATA (display_name
));
11155 #endif /* not USE_X_TOOLKIT */
11156 #endif /* not USE_GTK*/
11158 /* Detect failure. */
11165 /* We have definitely succeeded. Record the new connection. */
11167 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
11168 bzero (dpyinfo
, sizeof *dpyinfo
);
11170 terminal
= x_create_terminal (dpyinfo
);
11172 #ifdef MULTI_KBOARD
11174 struct x_display_info
*share
;
11177 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
11178 share
= share
->next
, tail
= XCDR (tail
))
11179 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
11180 SDATA (display_name
)))
11183 terminal
->kboard
= share
->terminal
->kboard
;
11186 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
11187 init_kboard (terminal
->kboard
);
11188 terminal
->kboard
->Vwindow_system
= intern ("x");
11189 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
11191 char *vendor
= ServerVendor (dpy
);
11193 terminal
->kboard
->Vsystem_key_alist
11194 = call1 (Qvendor_specific_keysyms
,
11195 vendor
? build_string (vendor
) : empty_unibyte_string
);
11199 terminal
->kboard
->next_kboard
= all_kboards
;
11200 all_kboards
= terminal
->kboard
;
11201 /* Don't let the initial kboard remain current longer than necessary.
11202 That would cause problems if a file loaded on startup tries to
11203 prompt in the mini-buffer. */
11204 if (current_kboard
== initial_kboard
)
11205 current_kboard
= terminal
->kboard
;
11207 terminal
->kboard
->reference_count
++;
11211 /* Put this display on the chain. */
11212 dpyinfo
->next
= x_display_list
;
11213 x_display_list
= dpyinfo
;
11215 /* Put it on x_display_name_list as well, to keep them parallel. */
11216 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
11217 x_display_name_list
);
11218 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
11220 dpyinfo
->display
= dpy
;
11222 /* Set the name of the terminal. */
11223 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
11224 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
11225 terminal
->name
[SBYTES (display_name
)] = 0;
11228 XSetAfterFunction (x_current_display
, x_trace_wire
);
11232 = (char *) xmalloc (SBYTES (Vinvocation_name
)
11233 + SBYTES (Vsystem_name
)
11235 sprintf (dpyinfo
->x_id_name
, "%s@%s",
11236 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
11238 /* Figure out which modifier bits mean what. */
11239 x_find_modifier_meanings (dpyinfo
);
11241 /* Get the scroll bar cursor. */
11243 /* We must create a GTK cursor, it is required for GTK widgets. */
11244 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
11245 #endif /* USE_GTK */
11247 dpyinfo
->vertical_scroll_bar_cursor
11248 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
11250 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
11251 resource_name
, EMACS_CLASS
);
11252 #ifdef HAVE_XRMSETDATABASE
11253 XrmSetDatabase (dpyinfo
->display
, xrdb
);
11255 dpyinfo
->display
->db
= xrdb
;
11257 /* Put the rdb where we can find it in a way that works on
11259 dpyinfo
->xrdb
= xrdb
;
11261 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
11262 DefaultScreen (dpyinfo
->display
));
11263 select_visual (dpyinfo
);
11264 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
11265 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
11266 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
11267 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
11268 dpyinfo
->client_leader_window
= 0;
11269 dpyinfo
->grabbed
= 0;
11270 dpyinfo
->reference_count
= 0;
11271 dpyinfo
->icon_bitmap_id
= -1;
11272 dpyinfo
->font_table
= NULL
;
11273 dpyinfo
->n_fonts
= 0;
11274 dpyinfo
->font_table_size
= 0;
11275 dpyinfo
->bitmaps
= 0;
11276 dpyinfo
->bitmaps_size
= 0;
11277 dpyinfo
->bitmaps_last
= 0;
11278 dpyinfo
->scratch_cursor_gc
= 0;
11279 dpyinfo
->mouse_face_mouse_frame
= 0;
11280 dpyinfo
->mouse_face_deferred_gc
= 0;
11281 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
11282 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
11283 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
11284 dpyinfo
->mouse_face_window
= Qnil
;
11285 dpyinfo
->mouse_face_overlay
= Qnil
;
11286 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
11287 dpyinfo
->mouse_face_defer
= 0;
11288 dpyinfo
->mouse_face_hidden
= 0;
11289 dpyinfo
->x_focus_frame
= 0;
11290 dpyinfo
->x_focus_event_frame
= 0;
11291 dpyinfo
->x_highlight_frame
= 0;
11292 dpyinfo
->image_cache
= make_image_cache ();
11293 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
11295 /* See if we can construct pixel values from RGB values. */
11296 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
11297 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
11299 if (dpyinfo
->visual
->class == TrueColor
)
11301 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
11302 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
11303 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
11304 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
11305 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
11306 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
11309 /* See if a private colormap is requested. */
11310 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
11312 if (dpyinfo
->visual
->class == PseudoColor
)
11315 value
= display_x_get_resource (dpyinfo
,
11316 build_string ("privateColormap"),
11317 build_string ("PrivateColormap"),
11319 if (STRINGP (value
)
11320 && (!strcmp (SDATA (value
), "true")
11321 || !strcmp (SDATA (value
), "on")))
11322 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
11326 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
11327 dpyinfo
->visual
, AllocNone
);
11330 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
11331 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
11332 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
11333 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
11334 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
11335 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
11336 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
11337 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
11338 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
11341 dpyinfo
->Xatom_wm_protocols
11342 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
11343 dpyinfo
->Xatom_wm_take_focus
11344 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
11345 dpyinfo
->Xatom_wm_save_yourself
11346 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
11347 dpyinfo
->Xatom_wm_delete_window
11348 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
11349 dpyinfo
->Xatom_wm_change_state
11350 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
11351 dpyinfo
->Xatom_wm_configure_denied
11352 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
11353 dpyinfo
->Xatom_wm_window_moved
11354 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
11355 dpyinfo
->Xatom_wm_client_leader
11356 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
11357 dpyinfo
->Xatom_editres
11358 = XInternAtom (dpyinfo
->display
, "Editres", False
);
11359 dpyinfo
->Xatom_CLIPBOARD
11360 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
11361 dpyinfo
->Xatom_TIMESTAMP
11362 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
11363 dpyinfo
->Xatom_TEXT
11364 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
11365 dpyinfo
->Xatom_COMPOUND_TEXT
11366 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
11367 dpyinfo
->Xatom_UTF8_STRING
11368 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
11369 dpyinfo
->Xatom_DELETE
11370 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
11371 dpyinfo
->Xatom_MULTIPLE
11372 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
11373 dpyinfo
->Xatom_INCR
11374 = XInternAtom (dpyinfo
->display
, "INCR", False
);
11375 dpyinfo
->Xatom_EMACS_TMP
11376 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
11377 dpyinfo
->Xatom_TARGETS
11378 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
11379 dpyinfo
->Xatom_NULL
11380 = XInternAtom (dpyinfo
->display
, "NULL", False
);
11381 dpyinfo
->Xatom_ATOM_PAIR
11382 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
11383 /* For properties of font. */
11384 dpyinfo
->Xatom_PIXEL_SIZE
11385 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
11386 dpyinfo
->Xatom_AVERAGE_WIDTH
11387 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
11388 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
11389 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
11390 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
11391 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
11392 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
11393 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
11395 /* Ghostscript support. */
11396 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
11397 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
11399 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
11402 dpyinfo
->cut_buffers_initialized
= 0;
11404 dpyinfo
->x_dnd_atoms_size
= 8;
11405 dpyinfo
->x_dnd_atoms_length
= 0;
11406 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
11407 * dpyinfo
->x_dnd_atoms_size
);
11409 dpyinfo
->net_supported_atoms
= NULL
;
11410 dpyinfo
->nr_net_supported_atoms
= 0;
11411 dpyinfo
->net_supported_window
= 0;
11413 connection
= ConnectionNumber (dpyinfo
->display
);
11414 dpyinfo
->connection
= connection
;
11419 null_bits
[0] = 0x00;
11421 dpyinfo
->null_pixel
11422 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
11423 null_bits
, 1, 1, (long) 0, (long) 0,
11428 extern int gray_bitmap_width
, gray_bitmap_height
;
11429 extern char *gray_bitmap_bits
;
11431 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
11433 gray_bitmap_width
, gray_bitmap_height
,
11434 (unsigned long) 1, (unsigned long) 0, 1);
11438 xim_initialize (dpyinfo
, resource_name
);
11441 #ifdef subprocesses
11442 /* This is only needed for distinguishing keyboard and process input. */
11443 if (connection
!= 0)
11444 add_keyboard_wait_descriptor (connection
);
11447 #ifndef F_SETOWN_BUG
11449 #ifdef F_SETOWN_SOCK_NEG
11450 /* stdin is a socket here */
11451 fcntl (connection
, F_SETOWN
, -getpid ());
11452 #else /* ! defined (F_SETOWN_SOCK_NEG) */
11453 fcntl (connection
, F_SETOWN
, getpid ());
11454 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
11455 #endif /* ! defined (F_SETOWN) */
11456 #endif /* F_SETOWN_BUG */
11459 if (interrupt_input
)
11460 init_sigio (connection
);
11461 #endif /* ! defined (SIGIO) */
11465 Display
*dpy
= dpyinfo
->display
;
11466 XrmValue d
, fr
, to
;
11469 d
.addr
= (XPointer
)&dpy
;
11470 d
.size
= sizeof (Display
*);
11471 fr
.addr
= XtDefaultFont
;
11472 fr
.size
= sizeof (XtDefaultFont
);
11473 to
.size
= sizeof (Font
*);
11474 to
.addr
= (XPointer
)&font
;
11475 x_catch_errors (dpy
);
11476 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
11478 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
11479 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
11480 x_uncatch_errors ();
11484 /* See if we should run in synchronous mode. This is useful
11485 for debugging X code. */
11488 value
= display_x_get_resource (dpyinfo
,
11489 build_string ("synchronous"),
11490 build_string ("Synchronous"),
11492 if (STRINGP (value
)
11493 && (!strcmp (SDATA (value
), "true")
11494 || !strcmp (SDATA (value
), "on")))
11495 XSynchronize (dpyinfo
->display
, True
);
11500 value
= display_x_get_resource (dpyinfo
,
11501 build_string ("useXIM"),
11502 build_string ("UseXIM"),
11505 if (STRINGP (value
)
11506 && (!strcmp (SDATA (value
), "false")
11507 || !strcmp (SDATA (value
), "off")))
11510 if (STRINGP (value
)
11511 && (!strcmp (SDATA (value
), "true")
11512 || !strcmp (SDATA (value
), "on")))
11518 /* Only do this for the very first display in the Emacs session.
11519 Ignore X session management when Emacs was first started on a
11521 if (terminal
->id
== 1)
11522 x_session_initialize (dpyinfo
);
11530 /* Get rid of display DPYINFO, deleting all frames on it,
11531 and without sending any more commands to the X server. */
11534 x_delete_display (dpyinfo
)
11535 struct x_display_info
*dpyinfo
;
11538 struct terminal
*t
;
11540 /* Close all frames and delete the generic struct terminal for this
11542 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
11543 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
11546 /* Close X session management when we close its display. */
11547 if (t
->id
== 1 && x_session_have_connection ())
11550 delete_terminal (t
);
11554 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
11556 /* Discard this display from x_display_name_list and x_display_list.
11557 We can't use Fdelq because that can quit. */
11558 if (! NILP (x_display_name_list
)
11559 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
11560 x_display_name_list
= XCDR (x_display_name_list
);
11565 tail
= x_display_name_list
;
11566 while (CONSP (tail
) && CONSP (XCDR (tail
)))
11568 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
11570 XSETCDR (tail
, XCDR (XCDR (tail
)));
11573 tail
= XCDR (tail
);
11577 if (next_noop_dpyinfo
== dpyinfo
)
11578 next_noop_dpyinfo
= dpyinfo
->next
;
11580 if (x_display_list
== dpyinfo
)
11581 x_display_list
= dpyinfo
->next
;
11584 struct x_display_info
*tail
;
11586 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
11587 if (tail
->next
== dpyinfo
)
11588 tail
->next
= tail
->next
->next
;
11591 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
11592 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
11593 XrmDestroyDatabase (dpyinfo
->xrdb
);
11598 xim_close_dpy (dpyinfo
);
11601 #ifdef USE_FONT_BACKEND
11602 if (! enable_font_backend
)
11605 /* Free the font names in the font table. */
11606 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11607 if (dpyinfo
->font_table
[i
].name
)
11609 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
11610 xfree (dpyinfo
->font_table
[i
].full_name
);
11611 xfree (dpyinfo
->font_table
[i
].name
);
11614 if (dpyinfo
->font_table
)
11616 if (dpyinfo
->font_table
->font_encoder
)
11617 xfree (dpyinfo
->font_table
->font_encoder
);
11618 xfree (dpyinfo
->font_table
);
11620 #ifdef USE_FONT_BACKEND
11624 if (dpyinfo
->x_id_name
)
11625 xfree (dpyinfo
->x_id_name
);
11626 if (dpyinfo
->color_cells
)
11627 xfree (dpyinfo
->color_cells
);
11631 #ifdef USE_X_TOOLKIT
11633 /* Atimer callback function for TIMER. Called every 0.1s to process
11634 Xt timeouts, if needed. We must avoid calling XtAppPending as
11635 much as possible because that function does an implicit XFlush
11636 that slows us down. */
11639 x_process_timeouts (timer
)
11640 struct atimer
*timer
;
11643 x_timeout_atimer_activated_flag
= 0;
11644 if (toolkit_scroll_bar_interaction
|| popup_activated ())
11646 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
11647 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
11648 /* Reactivate the atimer for next time. */
11649 x_activate_timeout_atimer ();
11654 /* Install an asynchronous timer that processes Xt timeout events
11655 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
11656 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
11657 function whenever these variables are set. This is necessary
11658 because some widget sets use timeouts internally, for example the
11659 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
11660 processed, these widgets don't behave normally. */
11663 x_activate_timeout_atimer ()
11666 if (!x_timeout_atimer_activated_flag
)
11668 EMACS_TIME interval
;
11670 EMACS_SET_SECS_USECS (interval
, 0, 100000);
11671 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
11672 x_timeout_atimer_activated_flag
= 1;
11677 #endif /* USE_X_TOOLKIT */
11680 /* Set up use of X before we make the first connection. */
11682 extern frame_parm_handler x_frame_parm_handlers
[];
11684 static struct redisplay_interface x_redisplay_interface
=
11686 x_frame_parm_handlers
,
11690 x_clear_end_of_line
,
11692 x_after_update_window_line
,
11693 x_update_window_begin
,
11694 x_update_window_end
,
11700 0, /* flush_display_optional */
11702 x_clear_window_mouse_face
,
11703 x_get_glyph_overhangs
,
11704 x_fix_overlapping_area
,
11705 x_draw_fringe_bitmap
,
11706 0, /* define_fringe_bitmap */
11707 0, /* destroy_fringe_bitmap */
11710 x_compute_glyph_string_overhangs
,
11711 x_draw_glyph_string
,
11712 x_define_frame_cursor
,
11713 x_clear_frame_area
,
11714 x_draw_window_cursor
,
11715 x_draw_vertical_window_border
,
11716 x_shift_glyphs_for_insert
11720 /* This function is called when the last frame on a display is deleted. */
11722 x_delete_terminal (struct terminal
*terminal
)
11724 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
11727 /* Protect against recursive calls. Fdelete_frame in
11728 delete_terminal calls us back when it deletes our last frame. */
11729 if (!terminal
->name
)
11733 #ifdef USE_FONT_BACKEND
11734 if (! enable_font_backend
)
11736 /* Free the fonts in the font table. */
11737 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
11738 if (dpyinfo
->font_table
[i
].name
)
11740 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
11743 x_destroy_all_bitmaps (dpyinfo
);
11744 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
11747 xg_display_close (dpyinfo
->display
);
11749 #ifdef USE_X_TOOLKIT
11750 XtCloseDisplay (dpyinfo
->display
);
11752 XCloseDisplay (dpyinfo
->display
);
11754 #endif /* ! USE_GTK */
11756 x_delete_display (dpyinfo
);
11760 /* Create a struct terminal, initialize it with the X11 specific
11761 functions and make DISPLAY->TERMINAL point to it. */
11763 static struct terminal
*
11764 x_create_terminal (struct x_display_info
*dpyinfo
)
11766 struct terminal
*terminal
;
11768 terminal
= create_terminal ();
11770 terminal
->type
= output_x_window
;
11771 terminal
->display_info
.x
= dpyinfo
;
11772 dpyinfo
->terminal
= terminal
;
11774 /* kboard is initialized in x_term_init. */
11776 terminal
->clear_frame_hook
= x_clear_frame
;
11777 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
11778 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
11779 terminal
->ring_bell_hook
= XTring_bell
;
11780 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
11781 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
11782 terminal
->update_begin_hook
= x_update_begin
;
11783 terminal
->update_end_hook
= x_update_end
;
11784 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
11785 terminal
->read_socket_hook
= XTread_socket
;
11786 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
11787 terminal
->mouse_position_hook
= XTmouse_position
;
11788 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
11789 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
11790 terminal
->fullscreen_hook
= XTfullscreen_hook
;
11791 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
11792 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
11793 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
11794 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
11796 terminal
->delete_frame_hook
= x_destroy_window
;
11797 terminal
->delete_terminal_hook
= x_delete_terminal
;
11799 terminal
->rif
= &x_redisplay_interface
;
11800 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
11801 terminal
->char_ins_del_ok
= 1;
11802 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
11803 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
11804 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
11816 last_tool_bar_item
= -1;
11817 any_help_event_p
= 0;
11818 ignore_next_mouse_click_timeout
= 0;
11820 x_session_initialized
= 0;
11824 current_count
= -1;
11827 /* Try to use interrupt input; if we can't, then start polling. */
11828 Fset_input_interrupt_mode (Qt
);
11830 #ifdef USE_X_TOOLKIT
11831 XtToolkitInitialize ();
11833 Xt_app_con
= XtCreateApplicationContext ();
11835 /* Register a converter from strings to pixels, which uses
11836 Emacs' color allocation infrastructure. */
11837 XtAppSetTypeConverter (Xt_app_con
,
11838 XtRString
, XtRPixel
, cvt_string_to_pixel
,
11839 cvt_string_to_pixel_args
,
11840 XtNumber (cvt_string_to_pixel_args
),
11841 XtCacheByDisplay
, cvt_pixel_dtor
);
11843 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
11846 #ifdef USE_TOOLKIT_SCROLL_BARS
11848 xaw3d_arrow_scroll
= False
;
11849 xaw3d_pick_top
= True
;
11853 /* Note that there is no real way portable across R3/R4 to get the
11854 original error handler. */
11855 XSetErrorHandler (x_error_handler
);
11856 XSetIOErrorHandler (x_io_error_quitter
);
11858 /* Disable Window Change signals; they are handled by X events. */
11859 #if 0 /* Don't. We may want to open tty frames later. */
11861 signal (SIGWINCH
, SIG_DFL
);
11862 #endif /* SIGWINCH */
11865 signal (SIGPIPE
, x_connection_signal
);
11872 x_error_message
= NULL
;
11874 staticpro (&x_display_name_list
);
11875 x_display_name_list
= Qnil
;
11877 staticpro (&last_mouse_scroll_bar
);
11878 last_mouse_scroll_bar
= Qnil
;
11880 staticpro (&Qvendor_specific_keysyms
);
11881 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
11883 staticpro (&Qlatin_1
);
11884 Qlatin_1
= intern ("latin-1");
11886 staticpro (&last_mouse_press_frame
);
11887 last_mouse_press_frame
= Qnil
;
11889 DEFVAR_BOOL ("x-use-underline-position-properties",
11890 &x_use_underline_position_properties
,
11891 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11892 A value of nil means ignore them. If you encounter fonts with bogus
11893 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11894 to 4.1, set this to nil. */);
11895 x_use_underline_position_properties
= 1;
11897 DEFVAR_BOOL ("x-underline-at-descent-line",
11898 &x_underline_at_descent_line
,
11899 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
11900 A value of nil means to draw the underline according to the value of the
11901 variable `x-use-underline-position-properties', which is usually at the
11902 baseline level. The default value is nil. */);
11903 x_underline_at_descent_line
= 0;
11905 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
11906 &x_mouse_click_focus_ignore_position
,
11907 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
11908 This variable is only used when the window manager requires that you
11909 click on a frame to select it (give it focus). In that case, a value
11910 of nil, means that the selected window and cursor position changes to
11911 reflect the mouse click position, while a non-nil value means that the
11912 selected window or cursor position is preserved. */);
11913 x_mouse_click_focus_ignore_position
= 0;
11915 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
11916 doc
: /* What X toolkit scroll bars Emacs uses.
11917 A value of nil means Emacs doesn't use X toolkit scroll bars.
11918 Otherwise, value is a symbol describing the X toolkit. */);
11919 #ifdef USE_TOOLKIT_SCROLL_BARS
11921 Vx_toolkit_scroll_bars
= intern ("motif");
11922 #elif defined HAVE_XAW3D
11923 Vx_toolkit_scroll_bars
= intern ("xaw3d");
11925 Vx_toolkit_scroll_bars
= intern ("gtk");
11927 Vx_toolkit_scroll_bars
= intern ("xaw");
11930 Vx_toolkit_scroll_bars
= Qnil
;
11933 staticpro (&last_mouse_motion_frame
);
11934 last_mouse_motion_frame
= Qnil
;
11936 Qmodifier_value
= intern ("modifier-value");
11937 Qalt
= intern ("alt");
11938 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
11939 Qhyper
= intern ("hyper");
11940 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
11941 Qmeta
= intern ("meta");
11942 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
11943 Qsuper
= intern ("super");
11944 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
11946 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
11947 doc
: /* Which keys Emacs uses for the alt modifier.
11948 This should be one of the symbols `alt', `hyper', `meta', `super'.
11949 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
11950 is nil, which is the same as `alt'. */);
11951 Vx_alt_keysym
= Qnil
;
11953 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
11954 doc
: /* Which keys Emacs uses for the hyper modifier.
11955 This should be one of the symbols `alt', `hyper', `meta', `super'.
11956 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
11957 default is nil, which is the same as `hyper'. */);
11958 Vx_hyper_keysym
= Qnil
;
11960 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
11961 doc
: /* Which keys Emacs uses for the meta modifier.
11962 This should be one of the symbols `alt', `hyper', `meta', `super'.
11963 For example, `meta' means use the Meta_L and Meta_R keysyms. The
11964 default is nil, which is the same as `meta'. */);
11965 Vx_meta_keysym
= Qnil
;
11967 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
11968 doc
: /* Which keys Emacs uses for the super modifier.
11969 This should be one of the symbols `alt', `hyper', `meta', `super'.
11970 For example, `super' means use the Super_L and Super_R keysyms. The
11971 default is nil, which is the same as `super'. */);
11972 Vx_super_keysym
= Qnil
;
11974 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
11975 doc
: /* Hash table of character codes indexed by X keysym codes. */);
11976 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
11977 make_float (DEFAULT_REHASH_SIZE
),
11978 make_float (DEFAULT_REHASH_THRESHOLD
),
11982 #endif /* HAVE_X_WINDOWS */
11984 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
11985 (do not change this comment) */