1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Xt features made by Fred Pierresteguy. */
23 /* On 4.3 these lose if they come after xterm.h. */
24 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
25 /* Putting these at the beginning seems to be standard for other .c files. */
35 #include "blockinput.h"
37 /* Need syssignal.h for various externs and definitions that may be required
38 by some configurations for calls to signal later in this source file. */
39 #include "syssignal.h"
41 /* This may include sys/types.h, and that somehow loses
42 if this is not done before the other system files. */
44 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
55 #include <sys/ioctl.h>
56 #endif /* ! defined (BSD_SYSTEM) */
61 #ifndef INCLUDED_FCNTL
68 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
69 /* #include <sys/param.h> */
75 #include "dispextern.h"
76 #include "termhooks.h"
88 #include "intervals.h"
92 #include <X11/Shell.h>
96 extern void free_frame_menubar ();
97 extern FRAME_PTR
x_menubar_window_to_frame ();
98 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
100 extern void _XEditResCheckMessages ();
101 #endif /* not NO_EDITRES */
102 #endif /* USE_X_TOOLKIT */
104 #ifndef USE_X_TOOLKIT
105 #define x_any_window_to_frame x_window_to_frame
106 #define x_top_window_to_frame x_window_to_frame
111 #ifndef XtNinitialState
112 #define XtNinitialState "initialState"
116 #ifdef HAVE_SETLOCALE
117 /* So we can do setlocale. */
122 /* memmove will be defined as a macro in Xfuncs.h unless
123 <string.h> is included beforehand. The declaration for memmove in
124 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
129 #define min(a,b) ((a)<(b) ? (a) : (b))
132 #define max(a,b) ((a)>(b) ? (a) : (b))
135 /* This is a chain of structures for all the X displays currently in use. */
136 struct x_display_info
*x_display_list
;
138 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
139 one for each element of x_display_list and in the same order.
140 NAME is the name of the frame.
141 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
142 Lisp_Object x_display_name_list
;
144 /* Frame being updated by update_frame. This is declared in term.c.
145 This is set by update_begin and looked at by all the
146 XT functions. It is zero while not inside an update.
147 In that case, the XT functions assume that `selected_frame'
148 is the frame to apply to. */
149 extern struct frame
*updating_frame
;
151 extern int waiting_for_input
;
153 /* This is a frame waiting to be autoraised, within XTread_socket. */
154 struct frame
*pending_autoraise_frame
;
157 /* The application context for Xt use. */
158 XtAppContext Xt_app_con
;
160 static String Xt_default_resources
[] =
166 /* During an update, maximum vpos for ins/del line operations to affect. */
168 static int flexlines
;
170 /* During an update, nonzero if chars output now should be highlighted. */
172 static int highlight
;
174 /* Nominal cursor position -- where to draw output.
175 During an update, these are different from the cursor-box position. */
182 Formerly, we used PointerMotionHintMask (in STANDARD_EVENT_MASK)
183 so that we would have to call XQueryPointer after each MotionNotify
184 event to ask for another such event. However, this made mouse tracking
185 slow, and there was a bug that made it eventually stop.
187 Simply asking for MotionNotify all the time seems to work better.
189 In order to avoid asking for motion events and then throwing most
190 of them away or busy-polling the server for mouse positions, we ask
191 the server for pointer motion hints. This means that we get only
192 one event per group of mouse movements. "Groups" are delimited by
193 other kinds of events (focus changes and button clicks, for
194 example), or by XQueryPointer calls; when one of these happens, we
195 get another MotionNotify event the next time the mouse moves. This
196 is at least as efficient as getting motion events when mouse
197 tracking is on, and I suspect only negligibly worse when tracking
200 /* Where the mouse was last time we reported a mouse event. */
201 static FRAME_PTR last_mouse_frame
;
202 static XRectangle last_mouse_glyph
;
204 static Lisp_Object last_mouse_press_frame
;
206 /* The scroll bar in which the last X motion event occurred.
208 If the last X motion event occurred in a scroll bar, we set this
209 so XTmouse_position can know whether to report a scroll bar motion or
212 If the last X motion event didn't occur in a scroll bar, we set this
213 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
214 static Lisp_Object last_mouse_scroll_bar
;
216 /* This is a hack. We would really prefer that XTmouse_position would
217 return the time associated with the position it returns, but there
218 doesn't seem to be any way to wrest the timestamp from the server
219 along with the position query. So, we just keep track of the time
220 of the last movement we received, and return that in hopes that
221 it's somewhat accurate. */
222 static Time last_mouse_movement_time
;
224 /* Incremented by XTread_socket whenever it really tries to read events. */
226 static int volatile input_signal_count
;
228 static int input_signal_count
;
231 /* Used locally within XTread_socket. */
232 static int x_noop_count
;
234 /* Initial values of argv and argc. */
235 extern char **initial_argv
;
236 extern int initial_argc
;
238 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
240 /* Tells if a window manager is present or not. */
242 extern Lisp_Object Vx_no_window_manager
;
244 extern Lisp_Object Qface
, Qmouse_face
;
248 /* A mask of extra modifier bits to put into every keyboard char. */
249 extern int extra_keyboard_modifiers
;
251 static Lisp_Object Qvendor_specific_keysyms
;
253 extern XrmDatabase
x_load_resources ();
255 extern Lisp_Object
x_icon_type ();
257 void x_delete_display ();
259 static void redraw_previous_char ();
260 static void redraw_following_char ();
261 static unsigned int x_x_to_emacs_modifiers ();
263 static int fast_find_position ();
264 static void note_mouse_highlight ();
265 static void clear_mouse_face ();
266 static void show_mouse_face ();
267 static void do_line_dance ();
269 static void XTcursor_to ();
270 static void XTclear_end_of_line ();
271 static int x_io_error_quitter ();
272 int x_catch_errors ();
273 void x_uncatch_errors ();
276 /* This is a function useful for recording debugging information
277 about the sequence of occurrences in this file. */
285 struct record event_record
[100];
287 int event_record_index
;
289 record_event (locus
, type
)
293 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
294 event_record_index
= 0;
296 event_record
[event_record_index
].locus
= locus
;
297 event_record
[event_record_index
].type
= type
;
298 event_record_index
++;
303 /* Return the struct x_display_info corresponding to DPY. */
305 struct x_display_info
*
306 x_display_info_for_display (dpy
)
309 struct x_display_info
*dpyinfo
;
311 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
312 if (dpyinfo
->display
== dpy
)
318 /* Starting and ending updates.
320 These hooks are called by update_frame at the beginning and end
321 of a frame update. We record in `updating_frame' the identity
322 of the frame being updated, so that the XT... functions do not
323 need to take a frame as argument. Most of the XT... functions
324 should never be called except during an update, the only exceptions
325 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
336 flexlines
= f
->height
;
341 curs_x
= FRAME_CURSOR_X (f
);
342 curs_y
= FRAME_CURSOR_Y (f
);
344 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
346 /* Don't do highlighting for mouse motion during the update. */
347 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 1;
349 /* If the frame needs to be redrawn,
350 simply forget about any prior mouse highlighting. */
351 if (FRAME_GARBAGED_P (f
))
352 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= Qnil
;
354 if (!NILP (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
356 int firstline
, lastline
, i
;
357 struct window
*w
= XWINDOW (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
);
359 /* Find the first, and the last+1, lines affected by redisplay. */
360 for (firstline
= 0; firstline
< f
->height
; firstline
++)
361 if (FRAME_DESIRED_GLYPHS (f
)->enable
[firstline
])
364 lastline
= f
->height
;
365 for (i
= f
->height
- 1; i
>= 0; i
--)
367 if (FRAME_DESIRED_GLYPHS (f
)->enable
[i
])
373 /* Can we tell that this update does not affect the window
374 where the mouse highlight is? If so, no need to turn off.
375 Likewise, don't do anything if the frame is garbaged;
376 in that case, the FRAME_CURRENT_GLYPHS that we would use
377 are all wrong, and we will redisplay that line anyway. */
378 if (! (firstline
> (XFASTINT (w
->top
) + window_internal_height (w
))
379 || lastline
< XFASTINT (w
->top
)))
380 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
396 x_display_cursor (f
, 1, curs_x
, curs_y
);
398 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
400 /* This fails in the case of having updated only the echo area
401 if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS
402 has no relation to the current contents, and its charstarts
403 have no relation to the contents of the window-buffer.
404 I don't know a clean way to check
405 for that case. window_end_valid isn't set up yet. */
406 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
407 note_mouse_highlight (f
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
408 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
411 XFlush (FRAME_X_DISPLAY (f
));
415 /* This is called after a redisplay on frame F. */
418 XTframe_up_to_date (f
)
422 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
423 || f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
425 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
426 note_mouse_highlight (FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
,
427 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
428 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
429 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 0;
434 /* External interface to control of standout mode.
435 Call this when about to modify line at position VPOS
436 and not change whether it is highlighted. */
439 XTreassert_line_highlight (new, vpos
)
445 /* Call this when about to modify line at position VPOS
446 and change whether it is highlighted. */
449 XTchange_line_highlight (new_highlight
, vpos
, first_unused_hpos
)
450 int new_highlight
, vpos
, first_unused_hpos
;
452 highlight
= new_highlight
;
453 XTcursor_to (vpos
, 0);
454 XTclear_end_of_line (FRAME_WINDOW_WIDTH (updating_frame
));
457 /* This is used when starting Emacs and when restarting after suspend.
458 When starting Emacs, no X window is mapped. And nothing must be done
459 to Emacs's own window if it is suspended (though that rarely happens). */
462 XTset_terminal_modes ()
466 /* This is called when exiting or suspending Emacs.
467 Exiting will make the X-windows go away, and suspending
468 requires no action. */
471 XTreset_terminal_modes ()
473 /* XTclear_frame (); */
476 /* Set the nominal cursor position of the frame.
477 This is where display update commands will take effect.
478 This does not affect the place where the cursor-box is displayed. */
481 XTcursor_to (row
, col
)
482 register int row
, col
;
493 if (curs_x
>= FRAME_CURSOR_X_LIMIT (f
))
494 curs_x
= FRAME_CURSOR_X_LIMIT (f
) - 1;
498 if (updating_frame
== 0)
501 x_display_cursor (selected_frame
, 1, curs_x
, curs_y
);
502 XFlush (FRAME_X_DISPLAY (selected_frame
));
508 /* Return a pointer to per char metric information in FONT of a
509 character pointed by B (*XChar2b). */
511 #define PER_CHAR_METRIC(font, b) \
513 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
514 + (((font)->min_byte1 || (font)->max_byte1) \
515 ? (((b)->byte1 - (font)->min_byte1) \
516 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
518 : &((font)->max_bounds))
520 /* Display a sequence of N glyphs found at GP.
521 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
522 HL is 1 if this text is highlighted, 2 if the cursor is on it,
523 3 if should appear in its mouse-face.
524 JUST_FOREGROUND if 1 means draw only the foreground;
525 don't alter the background.
527 CMPCHARP if non NULL is a pointer to the struct cmpchar_info, which
528 means drawing glyphs on the same column. This is set to non NULL
529 only when recursively called within dumpglyphs to draw a composite
530 character specified by CMPCHAR.
532 FONT is the default font to use (for glyphs whose font-code is 0).
534 Since the display generation code is responsible for calling
535 compute_char_face and compute_glyph_face on everything it puts in
536 the display structure, we can assume that the face code on each
537 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
538 to which we can actually apply intern_face.
539 Call this function with input blocked.
541 Return overall pixel width of the drawn glyphs. */
544 /* This is the multi-face code. */
547 dumpglyphs (f
, left
, top
, gp
, n
, hl
, just_foreground
, cmpcharp
)
550 register GLYPH
*gp
; /* Points to first GLYPH. */
551 register int n
; /* Number of glyphs to display. */
554 struct cmpchar_info
*cmpcharp
;
556 /* Holds characters to be displayed. */
557 XChar2b
*x_2byte_buffer
558 = (XChar2b
*) alloca (FRAME_WINDOW_WIDTH (f
) * sizeof (*x_2byte_buffer
));
559 register XChar2b
*cp
; /* Steps through x_2byte_buffer[]. */
561 = (char *) alloca (FRAME_WINDOW_WIDTH (f
) * sizeof (*x_1byte_buffer
));
562 register int tlen
= GLYPH_TABLE_LENGTH
;
563 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
564 Window window
= FRAME_X_WINDOW (f
);
565 int orig_left
= left
;
571 /* Get the face-code of the next GLYPH. */
575 Lisp_Object first_ch
;
576 /* HIGHEST and LOWEST are used while drawing a composite
577 character. The meanings are described later. */
580 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
581 cf
= (cmpcharp
? cmpcharp
->face_work
: FAST_GLYPH_FACE (g
));
582 ch
= FAST_GLYPH_CHAR (g
);
583 if (unibyte_display_via_language_environment
584 && SINGLE_BYTE_CHAR_P (ch
)
586 || (ch
>= 0200 && !NILP (Vnonascii_translation_table
))))
587 ch
= unibyte_char_to_multibyte (ch
);
588 if (gidx
== 0) XSETFASTINT (first_ch
, ch
);
589 charset
= CHAR_CHARSET (ch
);
590 if (charset
== CHARSET_COMPOSITION
)
592 /* We must draw components of the composite character on the
594 cmpcharp
= cmpchar_table
[COMPOSITE_CHAR_ID (ch
)];
596 /* Set the face in the slot for work. */
597 cmpcharp
->face_work
= cf
;
599 /* We don't need the return value ... */
600 dumpglyphs (f
, left
, top
, cmpcharp
->glyph
, cmpcharp
->glyph_len
,
601 hl
, just_foreground
, cmpcharp
);
602 /* ... because the width of just drawn text can be
603 calculated as follows. */
604 left
+= FONT_WIDTH (f
->output_data
.x
->font
) * cmpcharp
->width
;
607 while (gp
&& (*gp
& GLYPH_MASK_PADDING
)) ++gp
, --n
;
612 /* Find the run of consecutive glyphs which can be drawn with
613 the same GC (i.e. the same charset and the same face-code).
614 Extract their character codes into X_2BYTE_BUFFER.
615 If CMPCHARP is not NULL, face-code is not checked because we
616 use only the face specified in `cmpcharp->face_work'. */
620 int this_charset
, c1
, c2
;
623 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
624 ch
= FAST_GLYPH_CHAR (g
);
625 if (unibyte_display_via_language_environment
626 && SINGLE_BYTE_CHAR_P (ch
)
628 || (ch
>= 0200 && !NILP (Vnonascii_translation_table
))))
629 ch
= unibyte_char_to_multibyte (ch
);
630 SPLIT_CHAR (ch
, this_charset
, c1
, c2
);
631 if (this_charset
!= charset
632 || (cmpcharp
== NULL
&& FAST_GLYPH_FACE (g
) != cf
))
636 cp
->byte1
= c1
, cp
->byte2
= c2
;
638 cp
->byte1
= 0, cp
->byte2
= c1
;
641 while (gp
&& (*gp
& GLYPH_MASK_PADDING
))
645 /* LEN gets the length of the run. */
646 len
= cp
- x_2byte_buffer
;
647 /* Now output this run of chars, with the font and pixel values
648 determined by the face code CF. */
650 struct face
*face
= FRAME_DEFAULT_FACE (f
);
651 XFontStruct
*font
= NULL
;
654 int line_height
= f
->output_data
.x
->line_height
;
655 /* Pixel width of each glyph in this run. */
657 = (FONT_WIDTH (f
->output_data
.x
->font
)
658 * (cmpcharp
? cmpcharp
->width
: CHARSET_WIDTH (charset
)));
659 /* Overall pixel width of this run. */
661 = (FONT_WIDTH (f
->output_data
.x
->font
)
662 * (cmpcharp
? cmpcharp
->width
: len
* CHARSET_WIDTH (charset
)));
663 /* A flag to tell if we have already filled background. We
664 fill background in advance in the following cases:
665 1) A face has stipple.
666 2) A height of font is shorter than LINE_HEIGHT.
667 3) Drawing a composite character.
668 4) Font has non-zero _MULE_BASELINE_OFFSET property.
669 After filling background, we draw glyphs by XDrawString16. */
670 int background_filled
;
671 /* Baseline position of a character, offset from TOP. */
673 /* The property value of `_MULE_RELATIVE_COMPOSE' and
674 `_MULE_DEFAULT_ASCENT'. */
675 int relative_compose
= 0, default_ascent
= 0;
676 /* 1 if we find no font or a font of inappropriate size. */
677 int require_clipping
;
679 /* HL = 3 means use a mouse face previously chosen. */
681 cf
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
;
683 /* First look at the face of the text itself. */
686 /* It's possible for the display table to specify
687 a face code that is out of range. Use 0 in that case. */
688 if (cf
< 0 || cf
>= FRAME_N_COMPUTED_FACES (f
)
689 || FRAME_COMPUTED_FACES (f
) [cf
] == 0)
693 face
= FRAME_MODE_LINE_FACE (f
);
695 face
= intern_face (f
, FRAME_COMPUTED_FACES (f
) [cf
]);
696 if (FACE_STIPPLE (face
))
700 /* Then comes the distinction between modeline and normal text. */
705 face
= FRAME_MODE_LINE_FACE (f
);
706 if (FACE_STIPPLE (face
))
710 #define FACE_DEFAULT (~0)
712 /* Setting appropriate font and gc for this charset. */
713 if (charset
!= CHARSET_ASCII
)
716 int fontset
= FACE_FONTSET (face
);
717 struct font_info
*fontp
;
719 if ((fontset
< 0 && (fontset
= FRAME_FONTSET (f
)) < 0)
720 || !(fontp
= FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
),
721 charset
, NULL
, fontset
)))
724 font
= (XFontStruct
*) (fontp
->font
);
725 gc
= FACE_NON_ASCII_GC (face
);
726 XSetFont (FRAME_X_DISPLAY (f
), gc
, font
->fid
);
728 = (font
->max_byte1
!= 0
729 ? (line_height
+ font
->ascent
- font
->descent
) / 2
730 : f
->output_data
.x
->font_baseline
- fontp
->baseline_offset
);
731 if (FONT_HEIGHT (font
) <= line_height
732 && (font
->ascent
> baseline
733 || font
->descent
> line_height
- baseline
))
734 /* Adjust baseline for this font to show the whole
736 baseline
= line_height
- font
->descent
;
738 if (cmpcharp
&& cmpcharp
->cmp_rule
== NULL
)
740 relative_compose
= fontp
->relative_compose
;
741 default_ascent
= fontp
->default_ascent
;
744 /* We have to change code points in the following cases. */
745 if (fontp
->font_encoder
)
747 /* This font requires CCL program to calculate code
748 point of characters. */
749 struct ccl_program
*ccl
= fontp
->font_encoder
;
751 if (CHARSET_DIMENSION (charset
) == 1)
752 for (cp
= x_2byte_buffer
; cp
< x_2byte_buffer
+ len
; cp
++)
754 ccl
->reg
[0] = charset
;
755 ccl
->reg
[1] = cp
->byte2
;
756 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
757 /* We assume that MSBs are appropriately
758 set/reset by CCL program. */
759 if (font
->max_byte1
== 0) /* 1-byte font */
760 cp
->byte1
= 0, cp
->byte2
= ccl
->reg
[1];
762 cp
->byte1
= ccl
->reg
[1], cp
->byte2
= ccl
->reg
[2];
765 for (cp
= x_2byte_buffer
; cp
< x_2byte_buffer
+ len
; cp
++)
767 ccl
->reg
[0] = charset
;
768 ccl
->reg
[1] = cp
->byte1
, ccl
->reg
[2] = cp
->byte2
;
769 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
770 /* We assume that MSBs are appropriately
771 set/reset by CCL program. */
772 if (font
->max_byte1
== 0) /* 1-byte font */
773 cp
->byte1
= 0, cp
->byte2
= ccl
->reg
[1];
775 cp
->byte1
= ccl
->reg
[1], cp
->byte2
= ccl
->reg
[2];
778 else if (fontp
->encoding
[charset
])
780 int enc
= fontp
->encoding
[charset
];
782 if ((enc
== 1 || enc
== 2) && CHARSET_DIMENSION (charset
) == 2)
783 for (cp
= x_2byte_buffer
; cp
< x_2byte_buffer
+ len
; cp
++)
785 if (enc
== 1 || enc
== 3)
786 for (cp
= x_2byte_buffer
; cp
< x_2byte_buffer
+ len
; cp
++)
793 if (charset
== CHARSET_ASCII
|| charset
== charset_latin_iso8859_1
)
795 font
= FACE_FONT (face
);
796 if (!font
|| font
== (XFontStruct
*) FACE_DEFAULT
)
797 font
= f
->output_data
.x
->font
;
798 baseline
= FONT_BASE (f
->output_data
.x
->font
);
799 if (charset
== charset_latin_iso8859_1
)
801 if (font
->max_char_or_byte2
< 0x80)
802 /* This font can't display Latin1 characters. */
806 for (cp
= x_2byte_buffer
; cp
< x_2byte_buffer
+ len
; cp
++)
814 /* Now override that if the cursor's on this character. */
817 /* The cursor overrides stippling. */
820 if (font
== f
->output_data
.x
->font
821 && face
->background
== f
->output_data
.x
->background_pixel
822 && face
->foreground
== f
->output_data
.x
->foreground_pixel
825 gc
= f
->output_data
.x
->cursor_gc
;
827 /* Cursor on non-default face: must merge. */
833 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
834 xgcv
.foreground
= face
->background
;
835 /* If the glyph would be invisible,
836 try a different foreground. */
837 if (xgcv
.foreground
== xgcv
.background
)
838 xgcv
.foreground
= face
->foreground
;
839 if (xgcv
.foreground
== xgcv
.background
)
840 xgcv
.foreground
= f
->output_data
.x
->cursor_foreground_pixel
;
841 if (xgcv
.foreground
== xgcv
.background
)
842 xgcv
.foreground
= face
->foreground
;
843 /* Make sure the cursor is distinct from text in this face. */
844 if (xgcv
.background
== face
->background
845 && xgcv
.foreground
== face
->foreground
)
847 xgcv
.background
= face
->foreground
;
848 xgcv
.foreground
= face
->background
;
850 xgcv
.graphics_exposures
= 0;
851 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
854 xgcv
.font
= font
->fid
;
858 if (FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
)
859 XChangeGC (FRAME_X_DISPLAY (f
),
860 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
,
863 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
864 = XCreateGC (FRAME_X_DISPLAY (f
), window
, mask
, &xgcv
);
865 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
867 /* If this code is restored, it must also reset to the default stipple
869 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
870 XSetStipple (FRAME_X_DISPLAY (f
), gc
, face
->stipple
);
876 require_clipping
= (!NILP (Vclip_large_size_font
)
877 && (font
->ascent
> baseline
878 || font
->descent
> line_height
- baseline
880 && FONT_WIDTH (font
) > glyph_width
)));
882 if (font
&& (just_foreground
|| (cmpcharp
&& gidx
> 0)))
883 background_filled
= 1;
886 /* Turn stipple on. */
887 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillOpaqueStippled
);
889 /* Draw stipple or background color on background. */
890 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
891 left
, top
, run_width
, line_height
);
893 /* Turn stipple off. */
894 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillSolid
);
896 background_filled
= 1;
899 || FONT_HEIGHT (font
) < line_height
900 || FONT_WIDTH (font
) < glyph_width
903 /* Fill a area for the current run in background pixle of GC. */
905 unsigned long mask
= GCForeground
| GCBackground
| GCFillStyle
;
907 /* The current code at first set foreground to background,
908 fill the area, then recover the original foreground.
909 Aren't there any smarter ways? */
911 XGetGCValues (FRAME_X_DISPLAY (f
), gc
, mask
, &xgcv
);
912 XSetForeground (FRAME_X_DISPLAY (f
), gc
, xgcv
.background
);
913 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillSolid
);
914 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
915 left
, top
, run_width
, line_height
);
916 XSetForeground (FRAME_X_DISPLAY (f
), gc
, xgcv
.foreground
);
918 background_filled
= 1;
920 /* To assure not to fill background while drawing
921 remaining components. */
925 background_filled
= 0;
929 if (require_clipping
)
931 Region region
; /* Region used for setting clip mask to GC. */
932 XPoint x
[4]; /* Data used for creating REGION. */
934 x
[0].x
= x
[3].x
= left
, x
[1].x
= x
[2].x
= left
+ glyph_width
;
935 x
[0].y
= x
[1].y
= top
, x
[2].y
= x
[3].y
= top
+ line_height
;
936 region
= XPolygonRegion (x
, 4, EvenOddRule
);
937 XSetRegion (FRAME_X_DISPLAY (f
), gc
, region
);
938 XDestroyRegion (region
);
943 if (require_clipping
|| FONT_WIDTH (font
) != glyph_width
)
944 for (i
= 0; i
< len
; i
++)
946 if (require_clipping
&& i
> 0)
947 XSetClipOrigin (FRAME_X_DISPLAY (f
), gc
,
949 if (background_filled
)
950 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
951 left
+ glyph_width
* i
,
952 top
+ baseline
, x_2byte_buffer
+ i
, 1);
954 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, gc
,
955 left
+ glyph_width
* i
,
956 top
+ baseline
, x_2byte_buffer
+ i
, 1);
960 /* See if this whole buffer can be output as 8-bit chars.
961 If so, copy x_2byte_buffer to x_1byte_buffer
962 and do it as 8-bit chars. */
963 for (i
= 0; i
< len
; i
++)
965 if (x_2byte_buffer
[i
].byte1
!= 0)
967 x_1byte_buffer
[i
] = x_2byte_buffer
[i
].byte2
;
972 if (background_filled
)
973 XDrawString (FRAME_X_DISPLAY (f
), window
, gc
,
974 left
, top
+ baseline
, x_1byte_buffer
, len
);
976 XDrawImageString (FRAME_X_DISPLAY (f
), window
, gc
,
977 left
, top
+ baseline
, x_1byte_buffer
, len
);
981 /* We can't output them as 8-bit chars,
982 so do it as 16-bit chars. */
984 if (background_filled
)
985 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
986 left
, top
+ baseline
, x_2byte_buffer
, len
);
988 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, gc
,
989 left
, top
+ baseline
, x_2byte_buffer
, len
);
995 /* Handle composite characters. */
996 XCharStruct
*pcm
; /* Pointer to per char metric info. */
998 if ((cmpcharp
->cmp_rule
|| relative_compose
)
1001 /* This is the first character. Initialize variables.
1002 HIGHEST is the highest position of glyphs ever
1003 written, LOWEST the lowest position. */
1007 && CHAR_TABLE_P (Vuse_default_ascent
)
1008 && !NILP (Faref (Vuse_default_ascent
, first_ch
)))
1010 highest
= default_ascent
;
1015 pcm
= PER_CHAR_METRIC (font
, x_2byte_buffer
);
1016 highest
= pcm
->ascent
+ 1;
1017 lowest
= - pcm
->descent
;
1020 if (cmpcharp
->cmp_rule
)
1021 x_offset
= (cmpcharp
->col_offset
[0]
1022 * FONT_WIDTH (f
->output_data
.x
->font
));
1023 /* Draw the first character at the normal position. */
1024 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
1025 left
+ x_offset
, top
+ baseline
, x_2byte_buffer
, 1);
1032 for (; i
< len
; i
++, gidx
++)
1034 int x_offset
= 0, y_offset
= 0;
1036 if (relative_compose
)
1038 pcm
= PER_CHAR_METRIC (font
, x_2byte_buffer
+ i
);
1039 if (NILP (Vignore_relative_composition
)
1040 || NILP (Faref (Vignore_relative_composition
,
1041 make_number (cmpcharp
->glyph
[gidx
]))))
1043 if (- pcm
->descent
>= relative_compose
)
1045 /* Draw above the current glyphs. */
1046 y_offset
= highest
+ pcm
->descent
;
1047 highest
+= pcm
->ascent
+ pcm
->descent
;
1049 else if (pcm
->ascent
<= 0)
1051 /* Draw beneath the current glyphs. */
1052 y_offset
= lowest
- pcm
->ascent
;
1053 lowest
-= pcm
->ascent
+ pcm
->descent
;
1058 /* Draw the glyph at normal position. If
1059 it sticks out of HIGHEST or LOWEST,
1060 update them appropriately. */
1061 if (pcm
->ascent
> highest
)
1062 highest
= pcm
->ascent
;
1063 else if (- pcm
->descent
< lowest
)
1064 lowest
= - pcm
->descent
;
1067 else if (cmpcharp
->cmp_rule
)
1069 int gref
= (cmpcharp
->cmp_rule
[gidx
] - 0xA0) / 9;
1070 int nref
= (cmpcharp
->cmp_rule
[gidx
] - 0xA0) % 9;
1073 /* Re-encode GREF and NREF so that they specify
1074 only Y-axis information:
1075 0:top, 1:base, 2:bottom, 3:center */
1076 gref
= gref
/ 3 + (gref
== 4) * 2;
1077 nref
= nref
/ 3 + (nref
== 4) * 2;
1079 pcm
= PER_CHAR_METRIC (font
, x_2byte_buffer
+ i
);
1080 bottom
= ((gref
== 0 ? highest
: gref
== 1 ? 0
1081 : gref
== 2 ? lowest
1082 : (highest
+ lowest
) / 2)
1083 - (nref
== 0 ? pcm
->ascent
+ pcm
->descent
1084 : nref
== 1 ? pcm
->descent
: nref
== 2 ? 0
1085 : (pcm
->ascent
+ pcm
->descent
) / 2));
1086 top
= bottom
+ (pcm
->ascent
+ pcm
->descent
);
1089 if (bottom
< lowest
)
1091 y_offset
= bottom
+ pcm
->descent
;
1092 x_offset
= (cmpcharp
->col_offset
[gidx
]
1093 * FONT_WIDTH (f
->output_data
.x
->font
));
1095 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
1096 left
+ x_offset
, top
+ baseline
- y_offset
,
1097 x_2byte_buffer
+ i
, 1);
1100 if (require_clipping
)
1101 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
1103 #if 0 /* Doesn't work, because it uses FRAME_CURRENT_GLYPHS,
1104 which often is not up to date yet. */
1105 if (!just_foreground
)
1107 if (left
== orig_left
)
1108 redraw_previous_char (f
, PIXEL_TO_CHAR_COL (f
, left
),
1109 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
1111 redraw_following_char (f
, PIXEL_TO_CHAR_COL (f
, left
+ len
* FONT_WIDTH (font
)),
1112 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
1118 /* Show rectangles to indicate that we found no font. */
1119 int limit
= cmpcharp
? 1 : len
;
1121 for (i
= 0; i
< limit
; i
++)
1122 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1123 left
+ glyph_width
* i
, top
,
1124 glyph_width
- 1, line_height
- 1);
1126 else if (require_clipping
&& !NILP (Vhighlight_wrong_size_font
))
1128 /* Show ??? to indicate that we found a font of
1129 inappropriate size. */
1130 int limit
= cmpcharp
? 1 : len
;
1132 for (i
= 0; i
< limit
; i
++)
1134 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1135 left
+ glyph_width
* i
, top
+ line_height
- 1,
1136 left
+ glyph_width
* i
+ 1, top
+ line_height
- 1);
1137 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1138 left
+ glyph_width
* i
, top
+ line_height
- 3,
1139 left
+ glyph_width
* i
, top
+ line_height
- 1);
1143 /* We should probably check for XA_UNDERLINE_POSITION and
1144 XA_UNDERLINE_THICKNESS properties on the font, but let's
1145 just get the thing working, and come back to that. */
1147 /* Setting underline position based on the metric of the
1148 current font results in shaky underline if it strides
1149 over different fonts. So, we set the position based only
1150 on the default font of this frame. */
1151 int underline_position
= f
->output_data
.x
->font_baseline
+ 1;
1153 if (underline_position
>= line_height
)
1154 underline_position
= line_height
- 1;
1156 if (face
->underline
)
1157 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1159 left
, top
+ underline_position
, run_width
, 1);
1167 return (left
- orig_left
);
1172 /* This is the old single-face code. */
1175 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
1178 register GLYPH
*gp
; /* Points to first GLYPH. */
1179 register int n
; /* Number of glyphs to display. */
1184 Window window
= FRAME_X_WINDOW (f
);
1185 GC drawing_gc
= (hl
== 2 ? f
->output_data
.x
->cursor_gc
1186 : (hl
? f
->output_data
.x
->reverse_gc
1187 : f
->output_data
.x
->normal_gc
));
1189 if (sizeof (GLYPH
) == sizeof (XChar2b
))
1190 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
1191 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
1192 else if (sizeof (GLYPH
) == sizeof (unsigned char))
1193 XDrawImageString (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
1194 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
1196 /* What size of glyph ARE you using? And does X have a function to
1202 /* Output some text at the nominal frame cursor position.
1203 Advance the cursor over the text.
1204 Output LEN glyphs at START.
1206 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
1207 controls the pixel values used for foreground and background. */
1210 XTwrite_glyphs (start
, len
)
1211 register GLYPH
*start
;
1214 register int temp_length
;
1225 /* If not within an update,
1226 output at the frame's visible cursor. */
1227 curs_x
= FRAME_CURSOR_X (f
);
1228 curs_y
= FRAME_CURSOR_Y (f
);
1232 CHAR_TO_PIXEL_COL (f
, curs_x
),
1233 CHAR_TO_PIXEL_ROW (f
, curs_y
),
1234 start
, len
, highlight
, 0, NULL
);
1236 /* If we drew on top of the cursor, note that it is turned off. */
1237 if (curs_y
== f
->phys_cursor_y
1238 && curs_x
<= f
->phys_cursor_x
1239 && curs_x
+ len
> f
->phys_cursor_x
)
1240 f
->phys_cursor_on
= 0;
1243 if (curs_x
>= FRAME_CURSOR_X_LIMIT (f
))
1244 curs_x
= FRAME_CURSOR_X_LIMIT (f
) - 1;
1246 if (updating_frame
== 0)
1247 x_display_cursor (f
, 1, curs_x
, FRAME_CURSOR_Y (f
));
1253 /* Clear to the end of the line.
1254 Erase the current text line from the nominal cursor position (inclusive)
1255 to column FIRST_UNUSED (exclusive). The idea is that everything
1256 from FIRST_UNUSED onward is already erased. */
1259 XTclear_end_of_line (first_unused
)
1260 register int first_unused
;
1262 struct frame
*f
= updating_frame
;
1268 if (curs_y
< 0 || curs_y
>= f
->height
)
1270 if (first_unused
<= 0)
1273 if (first_unused
>= FRAME_WINDOW_WIDTH (f
))
1274 first_unused
= FRAME_WINDOW_WIDTH (f
);
1276 first_unused
+= FRAME_LEFT_SCROLL_BAR_WIDTH (f
);
1282 /* Notice if the cursor will be cleared by this operation. */
1283 if (curs_y
== f
->phys_cursor_y
1284 && curs_x
<= f
->phys_cursor_x
1285 && f
->phys_cursor_x
< first_unused
)
1286 f
->phys_cursor_on
= 0;
1288 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1289 CHAR_TO_PIXEL_COL (f
, curs_x
),
1290 CHAR_TO_PIXEL_ROW (f
, curs_y
),
1291 FONT_WIDTH (f
->output_data
.x
->font
) * (first_unused
- curs_x
),
1292 f
->output_data
.x
->line_height
, False
);
1294 redraw_previous_char (f
, curs_x
, curs_y
, highlight
);
1304 struct frame
*f
= updating_frame
;
1309 f
->phys_cursor_on
= 0; /* Cursor not visible. */
1310 curs_x
= 0; /* Nominal cursor position is top left. */
1315 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
1317 /* We have to clear the scroll bars, too. If we have changed
1318 colors or something like that, then they should be notified. */
1319 x_scroll_bar_clear (f
);
1321 XFlush (FRAME_X_DISPLAY (f
));
1326 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
1327 always contain the right glyphs to use.
1329 It also needs to be changed to look at the details of the font and
1330 see whether there is really overlap, and do nothing when there is
1331 not. This can use font_char_overlap_left and font_char_overlap_right,
1332 but just how to use them is not clear. */
1334 /* Erase the character (if any) at the position just before X, Y in frame F,
1335 then redraw it and the character before it.
1336 This is necessary when we erase starting at X,
1337 in case the character after X overlaps into the one before X.
1338 Call this function with input blocked. */
1341 redraw_previous_char (f
, x
, y
, highlight_flag
)
1346 /* Erase the character before the new ones, in case
1347 what was here before overlaps it.
1348 Reoutput that character, and the previous character
1349 (in case the previous character overlaps it). */
1352 int start_x
= x
- 2;
1355 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1356 CHAR_TO_PIXEL_COL (f
, x
- 1),
1357 CHAR_TO_PIXEL_ROW (f
, y
),
1358 FONT_WIDTH (f
->output_data
.x
->font
),
1359 f
->output_data
.x
->line_height
, False
);
1361 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
1362 CHAR_TO_PIXEL_ROW (f
, y
),
1363 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
1364 x
- start_x
, highlight_flag
, 1, NULL
);
1368 /* Erase the character (if any) at the position X, Y in frame F,
1369 then redraw it and the character after it.
1370 This is necessary when we erase endng at X,
1371 in case the character after X overlaps into the one before X.
1372 Call this function with input blocked. */
1375 redraw_following_char (f
, x
, y
, highlight_flag
)
1380 int limit
= FRAME_CURRENT_GLYPHS (f
)->used
[y
];
1381 /* Erase the character after the new ones, in case
1382 what was here before overlaps it.
1383 Reoutput that character, and the following character
1384 (in case the following character overlaps it). */
1386 && FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
] != SPACEGLYPH
)
1391 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1392 CHAR_TO_PIXEL_COL (f
, x
),
1393 CHAR_TO_PIXEL_ROW (f
, y
),
1394 FONT_WIDTH (f
->output_data
.x
->font
),
1395 f
->output_data
.x
->line_height
, False
);
1397 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, x
),
1398 CHAR_TO_PIXEL_ROW (f
, y
),
1399 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
],
1400 end_x
- x
, highlight_flag
, 1, NULL
);
1405 #if 0 /* Not in use yet */
1407 /* Return 1 if character C in font F extends past its left edge. */
1410 font_char_overlap_left (font
, c
)
1416 /* Find the bounding-box info for C. */
1417 if (font
->per_char
== 0)
1418 s
= &font
->max_bounds
;
1421 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1424 /* Decode char into row number (byte 1) and code within row (byte 2). */
1427 if (!(within
>= font
->min_char_or_byte2
1428 && within
<= font
->max_char_or_byte2
1429 && row
>= font
->min_byte1
1430 && row
<= font
->max_byte1
))
1432 /* If char is out of range, try the font's default char instead. */
1433 c
= font
->default_char
;
1434 row
= c
>> (BITS_PER_INT
- 8);
1437 if (!(within
>= font
->min_char_or_byte2
1438 && within
<= font
->max_char_or_byte2
1439 && row
>= font
->min_byte1
1440 && row
<= font
->max_byte1
))
1441 /* Still out of range means this char does not overlap. */
1444 /* We found the info for this char. */
1445 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1449 return (s
&& s
->lbearing
< 0);
1452 /* Return 1 if character C in font F extends past its right edge. */
1455 font_char_overlap_right (font
, c
)
1461 /* Find the bounding-box info for C. */
1462 if (font
->per_char
== 0)
1463 s
= &font
->max_bounds
;
1466 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1469 /* Decode char into row number (byte 1) and code within row (byte 2). */
1472 if (!(within
>= font
->min_char_or_byte2
1473 && within
<= font
->max_char_or_byte2
1474 && row
>= font
->min_byte1
1475 && row
<= font
->max_byte1
))
1477 /* If char is out of range, try the font's default char instead. */
1478 c
= font
->default_char
;
1479 row
= c
>> (BITS_PER_INT
- 8);
1482 if (!(within
>= font
->min_char_or_byte2
1483 && within
<= font
->max_char_or_byte2
1484 && row
>= font
->min_byte1
1485 && row
<= font
->max_byte1
))
1486 /* Still out of range means this char does not overlap. */
1489 /* We found the info for this char. */
1490 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1494 return (s
&& s
->rbearing
>= s
->width
);
1498 /* Invert the middle quarter of the frame for .15 sec. */
1500 /* We use the select system call to do the waiting, so we have to make sure
1501 it's available. If it isn't, we just won't do visual bells. */
1502 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1504 /* Subtract the `struct timeval' values X and Y,
1505 storing the result in RESULT.
1506 Return 1 if the difference is negative, otherwise 0. */
1509 timeval_subtract (result
, x
, y
)
1510 struct timeval
*result
, x
, y
;
1512 /* Perform the carry for the later subtraction by updating y.
1513 This is safer because on some systems
1514 the tv_sec member is unsigned. */
1515 if (x
.tv_usec
< y
.tv_usec
)
1517 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
1518 y
.tv_usec
-= 1000000 * nsec
;
1521 if (x
.tv_usec
- y
.tv_usec
> 1000000)
1523 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
1524 y
.tv_usec
+= 1000000 * nsec
;
1528 /* Compute the time remaining to wait. tv_usec is certainly positive. */
1529 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
1530 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
1532 /* Return indication of whether the result should be considered negative. */
1533 return x
.tv_sec
< y
.tv_sec
;
1545 /* Create a GC that will use the GXxor function to flip foreground pixels
1546 into background pixels. */
1550 values
.function
= GXxor
;
1551 values
.foreground
= (f
->output_data
.x
->foreground_pixel
1552 ^ f
->output_data
.x
->background_pixel
);
1554 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1555 GCFunction
| GCForeground
, &values
);
1559 /* Get the height not including a menu bar widget. */
1560 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
1561 /* Height of each line to flash. */
1562 int flash_height
= FRAME_LINE_HEIGHT (f
);
1563 /* These will be the left and right margins of the rectangles. */
1564 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1565 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
1569 /* Don't flash the area between a scroll bar and the frame
1570 edge it is next to. */
1571 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
1573 case vertical_scroll_bar_left
:
1574 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1577 case vertical_scroll_bar_right
:
1578 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1582 width
= flash_right
- flash_left
;
1584 /* If window is tall, flash top and bottom line. */
1585 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
1587 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1588 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1589 width
, flash_height
);
1590 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1592 (height
- flash_height
1593 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
1594 width
, flash_height
);
1597 /* If it is short, flash it all. */
1598 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1599 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1600 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
1602 XFlush (FRAME_X_DISPLAY (f
));
1605 struct timeval wakeup
, now
;
1607 EMACS_GET_TIME (wakeup
);
1609 /* Compute time to wait until, propagating carry from usecs. */
1610 wakeup
.tv_usec
+= 150000;
1611 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
1612 wakeup
.tv_usec
%= 1000000;
1614 /* Keep waiting until past the time wakeup. */
1617 struct timeval timeout
;
1619 EMACS_GET_TIME (timeout
);
1621 /* In effect, timeout = wakeup - timeout.
1622 Break if result would be negative. */
1623 if (timeval_subtract (&timeout
, wakeup
, timeout
))
1626 /* Try to wait that long--but we might wake up sooner. */
1627 select (0, NULL
, NULL
, NULL
, &timeout
);
1631 /* If window is tall, flash top and bottom line. */
1632 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
1634 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1635 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1636 width
, flash_height
);
1637 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1639 (height
- flash_height
1640 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
1641 width
, flash_height
);
1644 /* If it is short, flash it all. */
1645 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1646 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1647 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
1649 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
1650 XFlush (FRAME_X_DISPLAY (f
));
1660 /* Make audible bell. */
1662 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
1667 if (FRAME_X_DISPLAY (selected_frame
) == 0)
1670 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1672 XTflash (selected_frame
);
1678 XFlush (FRAME_X_DISPLAY (selected_frame
));
1683 /* Insert and delete character.
1684 These are not supposed to be used because we are supposed to turn
1685 off the feature of using them. */
1688 XTinsert_glyphs (start
, len
)
1689 register char *start
;
1702 /* Specify how many text lines, from the top of the window,
1703 should be affected by insert-lines and delete-lines operations.
1704 This, and those operations, are used only within an update
1705 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1708 XTset_terminal_window (n
)
1711 if (updating_frame
== 0)
1714 if ((n
<= 0) || (n
> updating_frame
->height
))
1715 flexlines
= updating_frame
->height
;
1720 /* These variables need not be per frame
1721 because redisplay is done on a frame-by-frame basis
1722 and the line dance for one frame is finished before
1723 anything is done for anoter frame. */
1725 /* Array of line numbers from cached insert/delete operations.
1726 line_dance[i] is the old position of the line that we want
1727 to move to line i, or -1 if we want a blank line there. */
1728 static int *line_dance
;
1730 /* Allocated length of that array. */
1731 static int line_dance_len
;
1733 /* Flag indicating whether we've done any work. */
1734 static int line_dance_in_progress
;
1736 /* Perform an insert-lines or delete-lines operation,
1737 inserting N lines or deleting -N lines at vertical position VPOS. */
1739 XTins_del_lines (vpos
, n
)
1742 register int fence
, i
;
1744 if (vpos
>= flexlines
)
1747 if (!line_dance_in_progress
)
1749 int ht
= updating_frame
->height
;
1750 if (ht
> line_dance_len
)
1752 line_dance
= (int *)xrealloc (line_dance
, ht
* sizeof (int));
1753 line_dance_len
= ht
;
1755 for (i
= 0; i
< ht
; ++i
) line_dance
[i
] = i
;
1756 line_dance_in_progress
= 1;
1760 if (n
> flexlines
- vpos
)
1761 n
= flexlines
- vpos
;
1763 for (i
= flexlines
; --i
>= fence
;)
1764 line_dance
[i
] = line_dance
[i
-n
];
1765 for (i
= fence
; --i
>= vpos
;)
1771 if (n
> flexlines
- vpos
)
1772 n
= flexlines
- vpos
;
1773 fence
= flexlines
- n
;
1774 for (i
= vpos
; i
< fence
; ++i
)
1775 line_dance
[i
] = line_dance
[i
+ n
];
1776 for (i
= fence
; i
< flexlines
; ++i
)
1781 /* Here's where we actually move the pixels around.
1782 Must be called with input blocked. */
1786 register int i
, j
, distance
;
1787 register struct frame
*f
;
1791 /* Must check this flag first. If it's not set, then not only is the
1792 array uninitialized, but we might not even have a frame. */
1793 if (!line_dance_in_progress
)
1801 intborder
= CHAR_TO_PIXEL_COL (f
, FRAME_LEFT_SCROLL_BAR_WIDTH (f
));
1803 x_update_cursor (updating_frame
, 0);
1805 for (i
= 0; i
< ht
; ++i
)
1806 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) > 0)
1808 for (j
= i
; (j
< ht
&& line_dance
[j
] != -1
1809 && line_dance
[j
]-j
== distance
); ++j
);
1810 /* Copy [i,j) upward from [i+distance,j+distance) */
1811 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1812 FRAME_X_WINDOW (f
), f
->output_data
.x
->normal_gc
,
1813 intborder
, CHAR_TO_PIXEL_ROW (f
, i
+distance
),
1814 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1815 (j
-i
) * f
->output_data
.x
->line_height
,
1816 intborder
, CHAR_TO_PIXEL_ROW (f
, i
));
1820 for (i
= ht
; --i
>=0; )
1821 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) < 0)
1823 for (j
= i
; (--j
>= 0 && line_dance
[j
] != -1
1824 && line_dance
[j
]-j
== distance
););
1825 /* Copy (j,i] downward from (j+distance, i+distance] */
1826 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1827 FRAME_X_WINDOW (f
), f
->output_data
.x
->normal_gc
,
1828 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1+distance
),
1829 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1830 (i
-j
) * f
->output_data
.x
->line_height
,
1831 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1));
1835 for (i
= 0; i
< ht
; ++i
)
1836 if (line_dance
[i
] == -1)
1838 for (j
= i
; j
< ht
&& line_dance
[j
] == -1; ++j
);
1840 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1841 intborder
, CHAR_TO_PIXEL_ROW (f
, i
),
1842 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1843 (j
-i
) * f
->output_data
.x
->line_height
, False
);
1846 line_dance_in_progress
= 0;
1849 /* Support routines for exposure events. */
1850 static void clear_cursor ();
1852 /* Output into a rectangle of an X-window (for frame F)
1853 the characters in f->phys_lines that overlap that rectangle.
1854 TOP and LEFT are the position of the upper left corner of the rectangle.
1855 ROWS and COLS are the size of the rectangle.
1856 Call this function with input blocked. */
1859 dumprectangle (f
, left
, top
, cols
, rows
)
1861 register int left
, top
, cols
, rows
;
1863 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1864 int cursor_cleared
= 0;
1868 if (FRAME_GARBAGED_P (f
))
1871 /* Express rectangle as four edges, instead of position-and-size. */
1872 bottom
= top
+ rows
;
1873 right
= left
+ cols
;
1875 /* Convert rectangle edges in pixels to edges in chars.
1876 Round down for left and top, up for right and bottom. */
1877 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1878 left
= PIXEL_TO_CHAR_COL (f
, left
);
1879 bottom
+= (f
->output_data
.x
->line_height
- 1);
1880 right
+= (FONT_WIDTH (f
->output_data
.x
->font
) - 1);
1881 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1882 right
= PIXEL_TO_CHAR_COL (f
, right
);
1884 /* Clip the rectangle to what can be visible. */
1889 if (right
> FRAME_WINDOW_WIDTH (f
))
1890 right
= FRAME_WINDOW_WIDTH (f
);
1891 if (bottom
> f
->height
)
1894 /* Get size in chars of the rectangle. */
1895 cols
= right
- left
;
1896 rows
= bottom
- top
;
1898 /* If rectangle has zero area, return. */
1899 if (rows
<= 0) return;
1900 if (cols
<= 0) return;
1902 /* Turn off the cursor if it is in the rectangle.
1903 We will turn it back on afterward. */
1904 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1905 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1911 /* Display the text in the rectangle, one text line at a time. */
1913 for (y
= top
; y
< bottom
; y
++)
1915 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1917 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1920 while (*line
& GLYPH_MASK_PADDING
)
1922 /* We must display the whole glyph of a wide-column
1929 CHAR_TO_PIXEL_COL (f
, left
),
1930 CHAR_TO_PIXEL_ROW (f
, y
),
1931 line
, min (cols
, active_frame
->used
[y
] - left
),
1932 active_frame
->highlight
[y
], 0, NULL
);
1935 /* Turn the cursor on if we turned it off. */
1938 x_update_cursor (f
, 1);
1945 /* We used to only do this if Vx_no_window_manager was non-nil, but
1946 the ICCCM (section 4.1.6) says that the window's border pixmap
1947 and border pixel are window attributes which are "private to the
1948 client", so we can always change it to whatever we want. */
1950 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1951 f
->output_data
.x
->border_pixel
);
1953 x_update_cursor (f
, 1);
1957 frame_unhighlight (f
)
1960 /* We used to only do this if Vx_no_window_manager was non-nil, but
1961 the ICCCM (section 4.1.6) says that the window's border pixmap
1962 and border pixel are window attributes which are "private to the
1963 client", so we can always change it to whatever we want. */
1965 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1966 f
->output_data
.x
->border_tile
);
1968 x_update_cursor (f
, 1);
1971 static void XTframe_rehighlight ();
1972 static void x_frame_rehighlight ();
1974 /* The focus has changed. Update the frames as necessary to reflect
1975 the new situation. Note that we can't change the selected frame
1976 here, because the Lisp code we are interrupting might become confused.
1977 Each event gets marked with the frame in which it occurred, so the
1978 Lisp code can tell when the switch took place by examining the events. */
1981 x_new_focus_frame (dpyinfo
, frame
)
1982 struct x_display_info
*dpyinfo
;
1983 struct frame
*frame
;
1985 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
1986 int events_enqueued
= 0;
1988 if (frame
!= dpyinfo
->x_focus_frame
)
1990 /* Set this before calling other routines, so that they see
1991 the correct value of x_focus_frame. */
1992 dpyinfo
->x_focus_frame
= frame
;
1994 if (old_focus
&& old_focus
->auto_lower
)
1995 x_lower_frame (old_focus
);
1998 selected_frame
= frame
;
1999 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
2001 Fselect_window (selected_frame
->selected_window
);
2002 choose_minibuf_frame ();
2005 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
2006 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
2008 pending_autoraise_frame
= 0;
2011 x_frame_rehighlight (dpyinfo
);
2014 /* Handle an event saying the mouse has moved out of an Emacs frame. */
2017 x_mouse_leave (dpyinfo
)
2018 struct x_display_info
*dpyinfo
;
2020 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
2023 /* The focus has changed, or we have redirected a frame's focus to
2024 another frame (this happens when a frame uses a surrogate
2025 minibuffer frame). Shift the highlight as appropriate.
2027 The FRAME argument doesn't necessarily have anything to do with which
2028 frame is being highlighted or unhighlighted; we only use it to find
2029 the appropriate X display info. */
2031 XTframe_rehighlight (frame
)
2032 struct frame
*frame
;
2034 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
2038 x_frame_rehighlight (dpyinfo
)
2039 struct x_display_info
*dpyinfo
;
2041 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
2043 if (dpyinfo
->x_focus_frame
)
2045 dpyinfo
->x_highlight_frame
2046 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
2047 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
2048 : dpyinfo
->x_focus_frame
);
2049 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
2051 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
2052 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
2056 dpyinfo
->x_highlight_frame
= 0;
2058 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
2061 frame_unhighlight (old_highlight
);
2062 if (dpyinfo
->x_highlight_frame
)
2063 frame_highlight (dpyinfo
->x_highlight_frame
);
2067 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
2069 /* Initialize mode_switch_bit and modifier_meaning. */
2071 x_find_modifier_meanings (dpyinfo
)
2072 struct x_display_info
*dpyinfo
;
2074 int min_code
, max_code
;
2077 XModifierKeymap
*mods
;
2079 dpyinfo
->meta_mod_mask
= 0;
2080 dpyinfo
->shift_lock_mask
= 0;
2081 dpyinfo
->alt_mod_mask
= 0;
2082 dpyinfo
->super_mod_mask
= 0;
2083 dpyinfo
->hyper_mod_mask
= 0;
2086 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
2088 min_code
= dpyinfo
->display
->min_keycode
;
2089 max_code
= dpyinfo
->display
->max_keycode
;
2092 syms
= XGetKeyboardMapping (dpyinfo
->display
,
2093 min_code
, max_code
- min_code
+ 1,
2095 mods
= XGetModifierMapping (dpyinfo
->display
);
2097 /* Scan the modifier table to see which modifier bits the Meta and
2098 Alt keysyms are on. */
2100 int row
, col
; /* The row and column in the modifier table. */
2102 for (row
= 3; row
< 8; row
++)
2103 for (col
= 0; col
< mods
->max_keypermod
; col
++)
2106 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
2108 /* Zeroes are used for filler. Skip them. */
2112 /* Are any of this keycode's keysyms a meta key? */
2116 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
2118 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
2124 dpyinfo
->meta_mod_mask
|= (1 << row
);
2129 dpyinfo
->alt_mod_mask
|= (1 << row
);
2134 dpyinfo
->hyper_mod_mask
|= (1 << row
);
2139 dpyinfo
->super_mod_mask
|= (1 << row
);
2143 /* Ignore this if it's not on the lock modifier. */
2144 if ((1 << row
) == LockMask
)
2145 dpyinfo
->shift_lock_mask
= LockMask
;
2153 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
2154 if (! dpyinfo
->meta_mod_mask
)
2156 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
2157 dpyinfo
->alt_mod_mask
= 0;
2160 /* If some keys are both alt and meta,
2161 make them just meta, not alt. */
2162 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
2164 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
2167 XFree ((char *) syms
);
2168 XFreeModifiermap (mods
);
2171 /* Convert between the modifier bits X uses and the modifier bits
2174 x_x_to_emacs_modifiers (dpyinfo
, state
)
2175 struct x_display_info
*dpyinfo
;
2178 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
2179 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
2180 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
2181 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
2182 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
2183 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
2187 x_emacs_to_x_modifiers (dpyinfo
, state
)
2188 struct x_display_info
*dpyinfo
;
2191 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
2192 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
2193 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
2194 | ((state
& shift_modifier
) ? ShiftMask
: 0)
2195 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
2196 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
2199 /* Convert a keysym to its name. */
2202 x_get_keysym_name (keysym
)
2208 value
= XKeysymToString (keysym
);
2214 /* Mouse clicks and mouse movement. Rah. */
2216 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
2217 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
2218 that the glyph at X, Y occupies, if BOUNDS != 0.
2219 If NOCLIP is nonzero, do not force the value into range. */
2222 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
2224 register int pix_x
, pix_y
;
2225 register int *x
, *y
;
2229 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
2230 even for negative values. */
2232 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
2234 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
2236 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
2237 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
2241 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
2242 bounds
->height
= f
->output_data
.x
->line_height
;
2243 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
2244 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
2251 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
2252 pix_x
= FRAME_WINDOW_WIDTH (f
);
2256 else if (pix_y
> f
->height
)
2265 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
2268 register int *pix_x
, *pix_y
;
2270 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
2271 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
2274 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2276 If the event is a button press, then note that we have grabbed
2280 construct_mouse_click (result
, event
, f
)
2281 struct input_event
*result
;
2282 XButtonEvent
*event
;
2285 /* Make the event type no_event; we'll change that when we decide
2287 result
->kind
= mouse_click
;
2288 result
->code
= event
->button
- Button1
;
2289 result
->timestamp
= event
->time
;
2290 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
2292 | (event
->type
== ButtonRelease
2300 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
2301 XSETFASTINT (result
->x
, column
);
2302 XSETFASTINT (result
->y
, row
);
2304 XSETINT (result
->x
, event
->x
);
2305 XSETINT (result
->y
, event
->y
);
2306 XSETFRAME (result
->frame_or_window
, f
);
2310 /* Prepare a menu-event in *RESULT for placement in the input queue. */
2313 construct_menu_click (result
, event
, f
)
2314 struct input_event
*result
;
2315 XButtonEvent
*event
;
2318 /* Make the event type no_event; we'll change that when we decide
2320 result
->kind
= mouse_click
;
2321 result
->code
= event
->button
- Button1
;
2322 result
->timestamp
= event
->time
;
2323 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
2325 | (event
->type
== ButtonRelease
2329 XSETINT (result
->x
, event
->x
);
2330 XSETINT (result
->y
, -1);
2331 XSETFRAME (result
->frame_or_window
, f
);
2334 /* Function to report a mouse movement to the mainstream Emacs code.
2335 The input handler calls this.
2337 We have received a mouse movement event, which is given in *event.
2338 If the mouse is over a different glyph than it was last time, tell
2339 the mainstream emacs code by setting mouse_moved. If not, ask for
2340 another motion event, so we can check again the next time it moves. */
2343 note_mouse_movement (frame
, event
)
2345 XMotionEvent
*event
;
2347 last_mouse_movement_time
= event
->time
;
2349 if (event
->window
!= FRAME_X_WINDOW (frame
))
2351 frame
->mouse_moved
= 1;
2352 last_mouse_scroll_bar
= Qnil
;
2354 note_mouse_highlight (frame
, -1, -1);
2357 /* Has the mouse moved off the glyph it was on at the last sighting? */
2358 else if (event
->x
< last_mouse_glyph
.x
2359 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
2360 || event
->y
< last_mouse_glyph
.y
2361 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
2363 frame
->mouse_moved
= 1;
2364 last_mouse_scroll_bar
= Qnil
;
2366 note_mouse_highlight (frame
, event
->x
, event
->y
);
2370 /* This is used for debugging, to turn off note_mouse_highlight. */
2371 static int disable_mouse_highlight
;
2373 /* Take proper action when the mouse has moved to position X, Y on frame F
2374 as regards highlighting characters that have mouse-face properties.
2375 Also dehighlighting chars where the mouse was before.
2376 X and Y can be negative or out of range. */
2379 note_mouse_highlight (f
, x
, y
)
2383 int row
, column
, portion
;
2384 XRectangle new_glyph
;
2388 if (disable_mouse_highlight
)
2391 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
= x
;
2392 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
= y
;
2393 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
= f
;
2395 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
)
2400 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 1;
2404 /* Find out which glyph the mouse is on. */
2405 pixel_to_glyph_coords (f
, x
, y
, &column
, &row
,
2406 &new_glyph
, FRAME_X_DISPLAY_INFO (f
)->grabbed
);
2408 /* Which window is that in? */
2409 window
= window_from_coordinates (f
, column
, row
, &portion
);
2410 w
= XWINDOW (window
);
2412 /* If we were displaying active text in another window, clear that. */
2413 if (! EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
2414 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2416 /* Are we in a window whose display is up to date?
2417 And verify the buffer's text has not changed. */
2418 if (WINDOWP (window
) && portion
== 0 && row
>= 0 && column
>= 0
2419 && row
< FRAME_HEIGHT (f
) && column
< FRAME_WIDTH (f
)
2420 && EQ (w
->window_end_valid
, w
->buffer
)
2421 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
2422 && (XFASTINT (w
->last_overlay_modified
)
2423 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
2425 int *ptr
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[row
];
2428 /* Find which buffer position the mouse corresponds to. */
2429 for (i
= column
; i
>= 0; i
--)
2433 /* Is it outside the displayed active region (if any)? */
2435 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2436 else if (! (EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
)
2437 && row
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2438 && row
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2439 && (row
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2440 || column
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
)
2441 && (row
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2442 || column
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2443 || FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
)))
2445 Lisp_Object mouse_face
, overlay
, position
;
2446 Lisp_Object
*overlay_vec
;
2447 int len
, noverlays
, ignor1
;
2448 struct buffer
*obuf
;
2451 /* If we get an out-of-range value, return now; avoid an error. */
2452 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
2455 /* Make the window's buffer temporarily current for
2456 overlays_at and compute_char_face. */
2457 obuf
= current_buffer
;
2458 current_buffer
= XBUFFER (w
->buffer
);
2464 /* Yes. Clear the display of the old active region, if any. */
2465 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2467 /* Is this char mouse-active? */
2468 XSETINT (position
, pos
);
2471 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2473 /* Put all the overlays we want in a vector in overlay_vec.
2474 Store the length in len. */
2475 noverlays
= overlays_at (pos
, 1, &overlay_vec
, &len
,
2477 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
2479 /* Find the highest priority overlay that has a mouse-face prop. */
2481 for (i
= 0; i
< noverlays
; i
++)
2483 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
2484 if (!NILP (mouse_face
))
2486 overlay
= overlay_vec
[i
];
2491 /* If no overlay applies, get a text property. */
2493 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
2495 /* Handle the overlay case. */
2496 if (! NILP (overlay
))
2498 /* Find the range of text around this char that
2499 should be active. */
2500 Lisp_Object before
, after
;
2503 before
= Foverlay_start (overlay
);
2504 after
= Foverlay_end (overlay
);
2505 /* Record this as the current active region. */
2506 fast_find_position (window
, XFASTINT (before
),
2507 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2508 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2509 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2510 = !fast_find_position (window
, XFASTINT (after
),
2511 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2512 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2513 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2514 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2515 = compute_char_face (f
, w
, pos
, 0, 0,
2516 &ignore
, pos
+ 1, 1);
2518 /* Display it as active. */
2519 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2521 /* Handle the text property case. */
2522 else if (! NILP (mouse_face
))
2524 /* Find the range of text around this char that
2525 should be active. */
2526 Lisp_Object before
, after
, beginning
, end
;
2529 beginning
= Fmarker_position (w
->start
);
2530 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
2531 - XFASTINT (w
->window_end_pos
)));
2533 = Fprevious_single_property_change (make_number (pos
+ 1),
2535 w
->buffer
, beginning
);
2537 = Fnext_single_property_change (position
, Qmouse_face
,
2539 /* Record this as the current active region. */
2540 fast_find_position (window
, XFASTINT (before
),
2541 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2542 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2543 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2544 = !fast_find_position (window
, XFASTINT (after
),
2545 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2546 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2547 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2548 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2549 = compute_char_face (f
, w
, pos
, 0, 0,
2550 &ignore
, pos
+ 1, 1);
2552 /* Display it as active. */
2553 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2557 current_buffer
= obuf
;
2562 /* Find the row and column of position POS in window WINDOW.
2563 Store them in *COLUMNP and *ROWP.
2564 This assumes display in WINDOW is up to date.
2565 If POS is above start of WINDOW, return coords
2566 of start of first screen line.
2567 If POS is after end of WINDOW, return coords of end of last screen line.
2569 Value is 1 if POS is in range, 0 if it was off screen. */
2572 fast_find_position (window
, pos
, columnp
, rowp
)
2575 int *columnp
, *rowp
;
2577 struct window
*w
= XWINDOW (window
);
2578 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2581 int left
= WINDOW_LEFT_MARGIN (w
);
2582 int top
= XFASTINT (w
->top
);
2583 int height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
2584 int width
= window_internal_width (w
);
2587 int maybe_next_line
= 0;
2589 /* Find the right row. */
2594 int linestart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ i
][left
];
2595 if (linestart
> pos
)
2597 /* If the position sought is the end of the buffer,
2598 don't include the blank lines at the bottom of the window. */
2599 if (linestart
== pos
&& pos
== BUF_ZV (XBUFFER (w
->buffer
)))
2601 maybe_next_line
= 1;
2608 /* Find the right column with in it. */
2609 charstarts
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ row
];
2611 for (i
= 0; i
< width
; i
++)
2613 if (charstarts
[left
+ i
] == pos
)
2616 *columnp
= i
+ left
;
2619 else if (charstarts
[left
+ i
] > pos
)
2621 else if (charstarts
[left
+ i
] > 0)
2622 lastcol
= left
+ i
+ 1;
2625 /* If we're looking for the end of the buffer,
2626 and we didn't find it in the line we scanned,
2627 use the start of the following line. */
2628 if (maybe_next_line
)
2639 /* Display the active region described by mouse_face_*
2640 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2643 show_mouse_face (dpyinfo
, hl
)
2644 struct x_display_info
*dpyinfo
;
2647 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
2648 int width
= window_internal_width (w
);
2649 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2652 int old_curs_x
= curs_x
;
2653 int old_curs_y
= curs_y
;
2655 /* Set these variables temporarily
2656 so that if we have to turn the cursor off and on again
2657 we will put it back at the same place. */
2658 curs_x
= f
->phys_cursor_x
;
2659 curs_y
= f
->phys_cursor_y
;
2660 for (i
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
;
2661 i
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
; i
++)
2663 int column
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2664 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
2665 : WINDOW_LEFT_MARGIN (w
));
2666 int endcolumn
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2667 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2668 : WINDOW_LEFT_MARGIN (w
) + width
);
2669 endcolumn
= min (endcolumn
, FRAME_CURRENT_GLYPHS (f
)->used
[i
]);
2671 /* If the cursor's in the text we are about to rewrite,
2672 turn the cursor off. */
2674 && curs_x
>= column
- 1
2675 && curs_x
<= endcolumn
)
2677 x_update_cursor (f
, 0);
2682 CHAR_TO_PIXEL_COL (f
, column
),
2683 CHAR_TO_PIXEL_ROW (f
, i
),
2684 FRAME_CURRENT_GLYPHS (f
)->glyphs
[i
] + column
,
2686 /* Highlight with mouse face if hl > 0. */
2687 hl
> 0 ? 3 : 0, 0, NULL
);
2690 /* If we turned the cursor off, turn it back on. */
2692 x_display_cursor (f
, 1, curs_x
, curs_y
);
2694 curs_x
= old_curs_x
;
2695 curs_y
= old_curs_y
;
2697 /* Change the mouse cursor according to the value of HL. */
2699 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2700 f
->output_data
.x
->cross_cursor
);
2702 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2703 f
->output_data
.x
->text_cursor
);
2706 /* Clear out the mouse-highlighted active region.
2707 Redraw it unhighlighted first. */
2710 clear_mouse_face (dpyinfo
)
2711 struct x_display_info
*dpyinfo
;
2713 if (! NILP (dpyinfo
->mouse_face_window
))
2714 show_mouse_face (dpyinfo
, 0);
2716 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2717 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2718 dpyinfo
->mouse_face_window
= Qnil
;
2721 /* Just discard the mouse face information for frame F, if any.
2722 This is used when the size of F is changed. */
2725 cancel_mouse_face (f
)
2729 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2731 window
= dpyinfo
->mouse_face_window
;
2732 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
2734 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2735 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2736 dpyinfo
->mouse_face_window
= Qnil
;
2740 static struct scroll_bar
*x_window_to_scroll_bar ();
2741 static void x_scroll_bar_report_motion ();
2743 /* Return the current position of the mouse.
2744 *fp should be a frame which indicates which display to ask about.
2746 If the mouse movement started in a scroll bar, set *fp, *bar_window,
2747 and *part to the frame, window, and scroll bar part that the mouse
2748 is over. Set *x and *y to the portion and whole of the mouse's
2749 position on the scroll bar.
2751 If the mouse movement started elsewhere, set *fp to the frame the
2752 mouse is on, *bar_window to nil, and *x and *y to the character cell
2755 Set *time to the server timestamp for the time at which the mouse
2756 was at this position.
2758 Don't store anything if we don't have a valid set of values to report.
2760 This clears the mouse_moved flag, so we can wait for the next mouse
2764 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
2767 Lisp_Object
*bar_window
;
2768 enum scroll_bar_part
*part
;
2770 unsigned long *time
;
2776 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
2777 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
2783 Window dummy_window
;
2786 Lisp_Object frame
, tail
;
2788 /* Clear the mouse-moved flag for every frame on this display. */
2789 FOR_EACH_FRAME (tail
, frame
)
2790 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
2791 XFRAME (frame
)->mouse_moved
= 0;
2793 last_mouse_scroll_bar
= Qnil
;
2795 /* Figure out which root window we're on. */
2796 XQueryPointer (FRAME_X_DISPLAY (*fp
),
2797 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
2799 /* The root window which contains the pointer. */
2802 /* Trash which we can't trust if the pointer is on
2803 a different screen. */
2806 /* The position on that root window. */
2809 /* More trash we can't trust. */
2812 /* Modifier keys and pointer buttons, about which
2814 (unsigned int *) &dummy
);
2816 /* Now we have a position on the root; find the innermost window
2817 containing the pointer. */
2821 int parent_x
, parent_y
;
2826 /* XTranslateCoordinates can get errors if the window
2827 structure is changing at the same time this function
2828 is running. So at least we must not crash from them. */
2830 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
2832 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
2833 && FRAME_LIVE_P (last_mouse_frame
))
2835 /* If mouse was grabbed on a frame, give coords for that frame
2836 even if the mouse is now outside it. */
2837 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2839 /* From-window, to-window. */
2840 root
, FRAME_X_WINDOW (last_mouse_frame
),
2842 /* From-position, to-position. */
2843 root_x
, root_y
, &win_x
, &win_y
,
2847 f1
= last_mouse_frame
;
2853 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2855 /* From-window, to-window. */
2858 /* From-position, to-position. */
2859 root_x
, root_y
, &win_x
, &win_y
,
2864 if (child
== None
|| child
== win
)
2872 /* Now we know that:
2873 win is the innermost window containing the pointer
2874 (XTC says it has no child containing the pointer),
2875 win_x and win_y are the pointer's position in it
2876 (XTC did this the last time through), and
2877 parent_x and parent_y are the pointer's position in win's parent.
2878 (They are what win_x and win_y were when win was child.
2879 If win is the root window, it has no parent, and
2880 parent_{x,y} are invalid, but that's okay, because we'll
2881 never use them in that case.) */
2883 /* Is win one of our frames? */
2884 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
2887 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
2890 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
2892 /* If not, is it one of our scroll bars? */
2895 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
2899 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2905 if (f1
== 0 && insist
> 0)
2906 f1
= selected_frame
;
2910 int ignore1
, ignore2
;
2912 /* Ok, we found a frame. Store all the values. */
2914 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
2916 FRAME_X_DISPLAY_INFO (f1
)->grabbed
2922 XSETINT (*x
, win_x
);
2923 XSETINT (*y
, win_y
);
2924 *time
= last_mouse_movement_time
;
2932 /* Scroll bar support. */
2934 /* Given an X window ID, find the struct scroll_bar which manages it.
2935 This can be called in GC, so we have to make sure to strip off mark
2937 static struct scroll_bar
*
2938 x_window_to_scroll_bar (window_id
)
2941 Lisp_Object tail
, frame
;
2943 for (tail
= Vframe_list
;
2944 XGCTYPE (tail
) == Lisp_Cons
;
2945 tail
= XCONS (tail
)->cdr
)
2947 Lisp_Object frame
, bar
, condemned
;
2949 frame
= XCONS (tail
)->car
;
2950 /* All elements of Vframe_list should be frames. */
2951 if (! GC_FRAMEP (frame
))
2954 /* Scan this frame's scroll bar list for a scroll bar with the
2956 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2957 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2958 /* This trick allows us to search both the ordinary and
2959 condemned scroll bar lists with one loop. */
2960 ! GC_NILP (bar
) || (bar
= condemned
,
2963 bar
= XSCROLL_BAR (bar
)->next
)
2964 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2965 return XSCROLL_BAR (bar
);
2971 /* Open a new X window to serve as a scroll bar, and return the
2972 scroll bar vector for it. */
2973 static struct scroll_bar
*
2974 x_scroll_bar_create (window
, top
, left
, width
, height
)
2975 struct window
*window
;
2976 int top
, left
, width
, height
;
2978 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2979 struct scroll_bar
*bar
2980 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2985 XSetWindowAttributes a
;
2987 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
2988 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2989 | ButtonMotionMask
| PointerMotionHintMask
2991 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
2993 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2998 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2999 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
3000 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
3001 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
3002 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
3003 sb_widget
= XtCreateManagedWidget ("box",
3005 f
->output_data
.x
->edit_widget
, al
, ac
);
3006 SET_SCROLL_BAR_X_WINDOW
3007 (bar
, sb_widget
->core
.window
);
3009 SET_SCROLL_BAR_X_WINDOW
3011 XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3013 /* Position and size of scroll bar. */
3014 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, top
,
3015 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2, height
,
3017 /* Border width, depth, class, and visual. */
3018 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
3024 XSETWINDOW (bar
->window
, window
);
3025 XSETINT (bar
->top
, top
);
3026 XSETINT (bar
->left
, left
);
3027 XSETINT (bar
->width
, width
);
3028 XSETINT (bar
->height
, height
);
3029 XSETINT (bar
->start
, 0);
3030 XSETINT (bar
->end
, 0);
3031 bar
->dragging
= Qnil
;
3033 /* Add bar to its frame's list of scroll bars. */
3034 bar
->next
= FRAME_SCROLL_BARS (f
);
3036 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
3037 if (! NILP (bar
->next
))
3038 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3040 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
3047 /* Draw BAR's handle in the proper position.
3048 If the handle is already drawn from START to END, don't bother
3049 redrawing it, unless REBUILD is non-zero; in that case, always
3050 redraw it. (REBUILD is handy for drawing the handle after expose
3053 Normally, we want to constrain the start and end of the handle to
3054 fit inside its rectangle, but if the user is dragging the scroll bar
3055 handle, we want to let them drag it down all the way, so that the
3056 bar's top is as far down as it goes; otherwise, there's no way to
3057 move to the very end of the buffer. */
3059 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
3060 struct scroll_bar
*bar
;
3064 int dragging
= ! NILP (bar
->dragging
);
3065 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3066 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3067 GC gc
= f
->output_data
.x
->normal_gc
;
3069 /* If the display is already accurate, do nothing. */
3071 && start
== XINT (bar
->start
)
3072 && end
== XINT (bar
->end
))
3078 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
3079 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
3080 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3082 /* Make sure the values are reasonable, and try to preserve
3083 the distance between start and end. */
3085 int length
= end
- start
;
3089 else if (start
> top_range
)
3091 end
= start
+ length
;
3095 else if (end
> top_range
&& ! dragging
)
3099 /* Store the adjusted setting in the scroll bar. */
3100 XSETINT (bar
->start
, start
);
3101 XSETINT (bar
->end
, end
);
3103 /* Clip the end position, just for display. */
3104 if (end
> top_range
)
3107 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
3108 below top positions, to make sure the handle is always at least
3109 that many pixels tall. */
3110 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3112 /* Draw the empty space above the handle. Note that we can't clear
3113 zero-height areas; that means "clear to end of window." */
3115 XClearArea (FRAME_X_DISPLAY (f
), w
,
3117 /* x, y, width, height, and exposures. */
3118 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3119 VERTICAL_SCROLL_BAR_TOP_BORDER
,
3120 inside_width
, start
,
3123 /* Draw the handle itself. */
3124 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
3126 /* x, y, width, height */
3127 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3128 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
3129 inside_width
, end
- start
);
3132 /* Draw the empty space below the handle. Note that we can't
3133 clear zero-height areas; that means "clear to end of window." */
3134 if (end
< inside_height
)
3135 XClearArea (FRAME_X_DISPLAY (f
), w
,
3137 /* x, y, width, height, and exposures. */
3138 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3139 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
3140 inside_width
, inside_height
- end
,
3148 /* Move a scroll bar around on the screen, to accommodate changing
3149 window configurations. */
3151 x_scroll_bar_move (bar
, top
, left
, width
, height
)
3152 struct scroll_bar
*bar
;
3153 int top
, left
, width
, height
;
3155 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3156 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3162 unsigned int mask
= 0;
3164 wc
.x
= left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3167 wc
.width
= width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
3170 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
3171 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
3172 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
3173 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
3176 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
3180 XSETINT (bar
->left
, left
);
3181 XSETINT (bar
->top
, top
);
3182 XSETINT (bar
->width
, width
);
3183 XSETINT (bar
->height
, height
);
3188 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
3191 x_scroll_bar_remove (bar
)
3192 struct scroll_bar
*bar
;
3194 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3198 /* Destroy the window. */
3199 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
3201 /* Disassociate this scroll bar from its window. */
3202 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
3207 /* Set the handle of the vertical scroll bar for WINDOW to indicate
3208 that we are displaying PORTION characters out of a total of WHOLE
3209 characters, starting at POSITION. If WINDOW has no scroll bar,
3212 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
3213 struct window
*window
;
3214 int portion
, whole
, position
;
3216 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
3217 int top
= XINT (window
->top
);
3218 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
3219 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
3221 /* Where should this scroll bar be, pixelwise? */
3222 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
3223 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
3225 = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3226 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3227 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
3228 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
3230 struct scroll_bar
*bar
;
3232 /* Does the scroll bar exist yet? */
3233 if (NILP (window
->vertical_scroll_bar
))
3234 bar
= x_scroll_bar_create (window
,
3235 pixel_top
, pixel_left
,
3236 pixel_width
, pixel_height
);
3239 /* It may just need to be moved and resized. */
3240 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
3241 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
3244 /* Set the scroll bar's current state, unless we're currently being
3246 if (NILP (bar
->dragging
))
3248 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, pixel_height
);
3251 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
3254 int start
= ((double) position
* top_range
) / whole
;
3255 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
3257 x_scroll_bar_set_handle (bar
, start
, end
, 0);
3261 XSETVECTOR (window
->vertical_scroll_bar
, bar
);
3265 /* The following three hooks are used when we're doing a thorough
3266 redisplay of the frame. We don't explicitly know which scroll bars
3267 are going to be deleted, because keeping track of when windows go
3268 away is a real pain - "Can you say set-window-configuration, boys
3269 and girls?" Instead, we just assert at the beginning of redisplay
3270 that *all* scroll bars are to be removed, and then save a scroll bar
3271 from the fiery pit when we actually redisplay its window. */
3273 /* Arrange for all scroll bars on FRAME to be removed at the next call
3274 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
3275 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
3277 XTcondemn_scroll_bars (frame
)
3280 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
3281 while (! NILP (FRAME_SCROLL_BARS (frame
)))
3284 bar
= FRAME_SCROLL_BARS (frame
);
3285 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
3286 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
3287 XSCROLL_BAR (bar
)->prev
= Qnil
;
3288 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
3289 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
3290 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
3294 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
3295 Note that WINDOW isn't necessarily condemned at all. */
3297 XTredeem_scroll_bar (window
)
3298 struct window
*window
;
3300 struct scroll_bar
*bar
;
3302 /* We can't redeem this window's scroll bar if it doesn't have one. */
3303 if (NILP (window
->vertical_scroll_bar
))
3306 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
3308 /* Unlink it from the condemned list. */
3310 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
3312 if (NILP (bar
->prev
))
3314 /* If the prev pointer is nil, it must be the first in one of
3316 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
3317 /* It's not condemned. Everything's fine. */
3319 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
3320 window
->vertical_scroll_bar
))
3321 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
3323 /* If its prev pointer is nil, it must be at the front of
3324 one or the other! */
3328 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
3330 if (! NILP (bar
->next
))
3331 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
3333 bar
->next
= FRAME_SCROLL_BARS (f
);
3335 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
3336 if (! NILP (bar
->next
))
3337 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3341 /* Remove all scroll bars on FRAME that haven't been saved since the
3342 last call to `*condemn_scroll_bars_hook'. */
3344 XTjudge_scroll_bars (f
)
3347 Lisp_Object bar
, next
;
3349 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
3351 /* Clear out the condemned list now so we won't try to process any
3352 more events on the hapless scroll bars. */
3353 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
3355 for (; ! NILP (bar
); bar
= next
)
3357 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
3359 x_scroll_bar_remove (b
);
3362 b
->next
= b
->prev
= Qnil
;
3365 /* Now there should be no references to the condemned scroll bars,
3366 and they should get garbage-collected. */
3370 /* Handle an Expose or GraphicsExpose event on a scroll bar.
3372 This may be called from a signal handler, so we have to ignore GC
3375 x_scroll_bar_expose (bar
, event
)
3376 struct scroll_bar
*bar
;
3379 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3380 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3381 GC gc
= f
->output_data
.x
->normal_gc
;
3382 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3386 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
3388 /* Draw a one-pixel border just inside the edges of the scroll bar. */
3389 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
3391 /* x, y, width, height */
3393 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
3394 XINT (bar
->height
) - 1);
3399 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
3400 is set to something other than no_event, it is enqueued.
3402 This may be called from a signal handler, so we have to ignore GC
3405 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
3406 struct scroll_bar
*bar
;
3408 struct input_event
*emacs_event
;
3410 if (! GC_WINDOWP (bar
->window
))
3413 emacs_event
->kind
= scroll_bar_click
;
3414 emacs_event
->code
= event
->xbutton
.button
- Button1
;
3415 emacs_event
->modifiers
3416 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
3417 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
3418 event
->xbutton
.state
)
3419 | (event
->type
== ButtonRelease
3422 emacs_event
->frame_or_window
= bar
->window
;
3423 emacs_event
->timestamp
= event
->xbutton
.time
;
3425 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3427 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
3429 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3430 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
3433 if (y
> top_range
) y
= top_range
;
3435 if (y
< XINT (bar
->start
))
3436 emacs_event
->part
= scroll_bar_above_handle
;
3437 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3438 emacs_event
->part
= scroll_bar_handle
;
3440 emacs_event
->part
= scroll_bar_below_handle
;
3442 /* Just because the user has clicked on the handle doesn't mean
3443 they want to drag it. Lisp code needs to be able to decide
3444 whether or not we're dragging. */
3446 /* If the user has just clicked on the handle, record where they're
3448 if (event
->type
== ButtonPress
3449 && emacs_event
->part
== scroll_bar_handle
)
3450 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
3453 /* If the user has released the handle, set it to its final position. */
3454 if (event
->type
== ButtonRelease
3455 && ! NILP (bar
->dragging
))
3457 int new_start
= y
- XINT (bar
->dragging
);
3458 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
3460 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
3461 bar
->dragging
= Qnil
;
3464 /* Same deal here as the other #if 0. */
3466 /* Clicks on the handle are always reported as occurring at the top of
3468 if (emacs_event
->part
== scroll_bar_handle
)
3469 emacs_event
->x
= bar
->start
;
3471 XSETINT (emacs_event
->x
, y
);
3473 XSETINT (emacs_event
->x
, y
);
3476 XSETINT (emacs_event
->y
, top_range
);
3480 /* Handle some mouse motion while someone is dragging the scroll bar.
3482 This may be called from a signal handler, so we have to ignore GC
3485 x_scroll_bar_note_movement (bar
, event
)
3486 struct scroll_bar
*bar
;
3489 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
3491 last_mouse_movement_time
= event
->xmotion
.time
;
3494 XSETVECTOR (last_mouse_scroll_bar
, bar
);
3496 /* If we're dragging the bar, display it. */
3497 if (! GC_NILP (bar
->dragging
))
3499 /* Where should the handle be now? */
3500 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
3502 if (new_start
!= XINT (bar
->start
))
3504 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
3506 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
3511 /* Return information to the user about the current position of the mouse
3512 on the scroll bar. */
3514 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
3516 Lisp_Object
*bar_window
;
3517 enum scroll_bar_part
*part
;
3519 unsigned long *time
;
3521 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
3522 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3523 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3525 Window dummy_window
;
3527 unsigned int dummy_mask
;
3531 /* Get the mouse's position relative to the scroll bar window, and
3533 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
3535 /* Root, child, root x and root y. */
3536 &dummy_window
, &dummy_window
,
3537 &dummy_coord
, &dummy_coord
,
3539 /* Position relative to scroll bar. */
3542 /* Mouse buttons and modifier keys. */
3548 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
3550 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3552 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
3554 if (! NILP (bar
->dragging
))
3555 win_y
-= XINT (bar
->dragging
);
3559 if (win_y
> top_range
)
3563 *bar_window
= bar
->window
;
3565 if (! NILP (bar
->dragging
))
3566 *part
= scroll_bar_handle
;
3567 else if (win_y
< XINT (bar
->start
))
3568 *part
= scroll_bar_above_handle
;
3569 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3570 *part
= scroll_bar_handle
;
3572 *part
= scroll_bar_below_handle
;
3574 XSETINT (*x
, win_y
);
3575 XSETINT (*y
, top_range
);
3578 last_mouse_scroll_bar
= Qnil
;
3581 *time
= last_mouse_movement_time
;
3587 /* The screen has been cleared so we may have changed foreground or
3588 background colors, and the scroll bars may need to be redrawn.
3589 Clear out the scroll bars, and ask for expose events, so we can
3593 x_scroll_bar_clear (f
)
3598 /* We can have scroll bars even if this is 0,
3599 if we just turned off scroll bar mode.
3600 But in that case we should not clear them. */
3601 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3602 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
3603 bar
= XSCROLL_BAR (bar
)->next
)
3604 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
3608 /* This processes Expose events from the menubar specific X event
3609 loop in xmenu.c. This allows to redisplay the frame if necessary
3610 when handling menubar or popup items. */
3613 process_expose_from_menu (event
)
3617 struct x_display_info
*dpyinfo
;
3621 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
3622 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3625 if (f
->async_visible
== 0)
3627 f
->async_visible
= 1;
3628 f
->async_iconified
= 0;
3629 f
->output_data
.x
->has_been_visible
= 1;
3630 SET_FRAME_GARBAGED (f
);
3634 dumprectangle (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
3635 event
.xexpose
.x
, event
.xexpose
.y
,
3636 event
.xexpose
.width
, event
.xexpose
.height
);
3641 struct scroll_bar
*bar
3642 = x_window_to_scroll_bar (event
.xexpose
.window
);
3645 x_scroll_bar_expose (bar
, &event
);
3651 /* Define a queue to save up SelectionRequest events for later handling. */
3653 struct selection_event_queue
3656 struct selection_event_queue
*next
;
3659 static struct selection_event_queue
*queue
;
3661 /* Nonzero means queue up certain events--don't process them yet. */
3662 static int x_queue_selection_requests
;
3664 /* Queue up an X event *EVENT, to be processed later. */
3667 x_queue_event (f
, event
)
3671 struct selection_event_queue
*queue_tmp
3672 = (struct selection_event_queue
*) malloc (sizeof (struct selection_event_queue
));
3674 if (queue_tmp
!= NULL
)
3676 queue_tmp
->event
= *event
;
3677 queue_tmp
->next
= queue
;
3682 /* Take all the queued events and put them back
3683 so that they get processed afresh. */
3686 x_unqueue_events (display
)
3689 while (queue
!= NULL
)
3691 struct selection_event_queue
*queue_tmp
= queue
;
3692 XPutBackEvent (display
, &queue_tmp
->event
);
3693 queue
= queue_tmp
->next
;
3694 free ((char *)queue_tmp
);
3698 /* Start queuing SelectionRequest events. */
3701 x_start_queuing_selection_requests (display
)
3704 x_queue_selection_requests
++;
3707 /* Stop queuing SelectionRequest events. */
3710 x_stop_queuing_selection_requests (display
)
3713 x_queue_selection_requests
--;
3714 x_unqueue_events (display
);
3717 /* The main X event-reading loop - XTread_socket. */
3719 /* Timestamp of enter window event. This is only used by XTread_socket,
3720 but we have to put it out here, since static variables within functions
3721 sometimes don't work. */
3722 static Time enter_timestamp
;
3724 /* This holds the state XLookupString needs to implement dead keys
3725 and other tricks known as "compose processing". _X Window System_
3726 says that a portable program can't use this, but Stephen Gildea assures
3727 me that letting the compiler initialize it to zeros will work okay.
3729 This must be defined outside of XTread_socket, for the same reasons
3730 given for enter_timestamp, above. */
3731 static XComposeStatus compose_status
;
3733 /* Record the last 100 characters stored
3734 to help debug the loss-of-chars-during-GC problem. */
3735 static int temp_index
;
3736 static short temp_buffer
[100];
3738 /* Set this to nonzero to fake an "X I/O error"
3739 on a particular display. */
3740 struct x_display_info
*XTread_socket_fake_io_error
;
3742 /* When we find no input here, we occasionally do a no-op command
3743 to verify that the X server is still running and we can still talk with it.
3744 We try all the open displays, one by one.
3745 This variable is used for cycling thru the displays. */
3746 static struct x_display_info
*next_noop_dpyinfo
;
3748 #define SET_SAVED_MENU_EVENT(size) { \
3749 if (f->output_data.x->saved_menu_event == 0) \
3750 f->output_data.x->saved_menu_event = (XEvent*)xmalloc (sizeof (XEvent)); \
3751 bcopy (&event, f->output_data.x->saved_menu_event, size); \
3752 if (numchars >= 1) \
3754 bufp->kind = menu_bar_activate_event; \
3755 XSETFRAME (bufp->frame_or_window, f); \
3761 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
3762 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
3764 /* Read events coming from the X server.
3765 This routine is called by the SIGIO handler.
3766 We return as soon as there are no more events to be read.
3768 Events representing keys are stored in buffer BUFP,
3769 which can hold up to NUMCHARS characters.
3770 We return the number of characters stored into the buffer,
3771 thus pretending to be `read'.
3773 EXPECTED is nonzero if the caller knows input is available. */
3776 XTread_socket (sd
, bufp
, numchars
, expected
)
3778 /* register */ struct input_event
*bufp
;
3779 /* register */ int numchars
;
3785 int items_pending
; /* How many items are in the X queue. */
3788 int event_found
= 0;
3791 struct x_display_info
*dpyinfo
;
3793 Status status_return
;
3796 if (interrupt_input_blocked
)
3798 interrupt_input_pending
= 1;
3802 interrupt_input_pending
= 0;
3805 /* So people can tell when we have read the available input. */
3806 input_signal_count
++;
3809 abort (); /* Don't think this happens. */
3811 /* Find the display we are supposed to read input for.
3812 It's the one communicating on descriptor SD. */
3813 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
3815 #if 0 /* This ought to be unnecessary; let's verify it. */
3817 /* If available, Xlib uses FIOSNBIO to make the socket
3818 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3819 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
3820 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3821 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
3822 #endif /* ! defined (FIOSNBIO) */
3825 #if 0 /* This code can't be made to work, with multiple displays,
3826 and appears not to be used on any system any more.
3827 Also keyboard.c doesn't turn O_NDELAY on and off
3828 for X connections. */
3831 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
3833 extern int read_alarm_should_throw
;
3834 read_alarm_should_throw
= 1;
3835 XPeekEvent (dpyinfo
->display
, &event
);
3836 read_alarm_should_throw
= 0;
3838 #endif /* HAVE_SELECT */
3842 /* For debugging, this gives a way to fake an I/O error. */
3843 if (dpyinfo
== XTread_socket_fake_io_error
)
3845 XTread_socket_fake_io_error
= 0;
3846 x_io_error_quitter (dpyinfo
->display
);
3849 while (XPending (dpyinfo
->display
) != 0)
3851 #ifdef USE_X_TOOLKIT
3852 /* needed to raise Motif submenus */
3853 XtAppNextEvent (Xt_app_con
, &event
);
3855 XNextEvent (dpyinfo
->display
, &event
);
3859 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
3860 event
.xclient
.window
);
3861 /* The necessity of the following line took me
3862 a full work-day to decipher from the docs!! */
3863 if (f1
!= 0 && FRAME_XIC (f1
) && XFilterEvent (&event
, None
))
3873 if (event
.xclient
.message_type
3874 == dpyinfo
->Xatom_wm_protocols
3875 && event
.xclient
.format
== 32)
3877 if (event
.xclient
.data
.l
[0]
3878 == dpyinfo
->Xatom_wm_take_focus
)
3880 /* Use x_any_window_to_frame because this
3881 could be the shell widget window
3882 if the frame has no title bar. */
3883 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
3885 /* Not quite sure this is needed -pd */
3886 if (f
&& FRAME_XIC (f
))
3887 XSetICFocus (FRAME_XIC (f
));
3889 /* Since we set WM_TAKE_FOCUS, we must call
3890 XSetInputFocus explicitly. But not if f is null,
3891 since that might be an event for a deleted frame. */
3894 Display
*d
= event
.xclient
.display
;
3895 /* Catch and ignore errors, in case window has been
3896 iconified by a window manager such as GWM. */
3897 int count
= x_catch_errors (d
);
3898 XSetInputFocus (d
, event
.xclient
.window
,
3899 RevertToPointerRoot
,
3900 event
.xclient
.data
.l
[1]);
3901 /* This is needed to detect the error
3902 if there is an error. */
3904 x_uncatch_errors (d
, count
);
3906 /* Not certain about handling scroll bars here */
3908 else if (event
.xclient
.data
.l
[0]
3909 == dpyinfo
->Xatom_wm_save_yourself
)
3911 /* Save state modify the WM_COMMAND property to
3912 something which can reinstate us. This notifies
3913 the session manager, who's looking for such a
3914 PropertyNotify. Can restart processing when
3915 a keyboard or mouse event arrives. */
3918 f
= x_top_window_to_frame (dpyinfo
,
3919 event
.xclient
.window
);
3921 /* This is just so we only give real data once
3922 for a single Emacs process. */
3923 if (f
== selected_frame
)
3924 XSetCommand (FRAME_X_DISPLAY (f
),
3925 event
.xclient
.window
,
3926 initial_argv
, initial_argc
);
3928 XSetCommand (FRAME_X_DISPLAY (f
),
3929 event
.xclient
.window
,
3933 else if (event
.xclient
.data
.l
[0]
3934 == dpyinfo
->Xatom_wm_delete_window
)
3937 = x_any_window_to_frame (dpyinfo
,
3938 event
.xclient
.window
);
3945 bufp
->kind
= delete_window_event
;
3946 XSETFRAME (bufp
->frame_or_window
, f
);
3954 else if (event
.xclient
.message_type
3955 == dpyinfo
->Xatom_wm_configure_denied
)
3958 else if (event
.xclient
.message_type
3959 == dpyinfo
->Xatom_wm_window_moved
)
3963 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3965 new_x
= event
.xclient
.data
.s
[0];
3966 new_y
= event
.xclient
.data
.s
[1];
3970 f
->output_data
.x
->left_pos
= new_x
;
3971 f
->output_data
.x
->top_pos
= new_y
;
3975 else if (event
.xclient
.message_type
3976 == dpyinfo
->Xatom_editres
)
3979 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
3980 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
3983 #endif /* HACK_EDITRES */
3987 case SelectionNotify
:
3988 #ifdef USE_X_TOOLKIT
3989 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
3991 #endif /* not USE_X_TOOLKIT */
3992 x_handle_selection_notify (&event
.xselection
);
3995 case SelectionClear
: /* Someone has grabbed ownership. */
3996 #ifdef USE_X_TOOLKIT
3997 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
3999 #endif /* USE_X_TOOLKIT */
4001 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
4006 bufp
->kind
= selection_clear_event
;
4007 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
4008 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
4009 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
4010 bufp
->frame_or_window
= Qnil
;
4018 case SelectionRequest
: /* Someone wants our selection. */
4019 #ifdef USE_X_TOOLKIT
4020 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
4022 #endif /* USE_X_TOOLKIT */
4023 if (x_queue_selection_requests
)
4024 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
4028 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
4033 bufp
->kind
= selection_request_event
;
4034 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
4035 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
4036 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
4037 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
4038 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
4039 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
4040 bufp
->frame_or_window
= Qnil
;
4048 case PropertyNotify
:
4049 #ifdef USE_X_TOOLKIT
4050 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
4052 #endif /* not USE_X_TOOLKIT */
4053 x_handle_property_notify (&event
.xproperty
);
4056 case ReparentNotify
:
4057 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
4061 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
4062 x_real_positions (f
, &x
, &y
);
4063 f
->output_data
.x
->left_pos
= x
;
4064 f
->output_data
.x
->top_pos
= y
;
4069 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
4072 if (f
->async_visible
== 0)
4074 f
->async_visible
= 1;
4075 f
->async_iconified
= 0;
4076 f
->output_data
.x
->has_been_visible
= 1;
4077 SET_FRAME_GARBAGED (f
);
4080 dumprectangle (x_window_to_frame (dpyinfo
,
4081 event
.xexpose
.window
),
4082 event
.xexpose
.x
, event
.xexpose
.y
,
4083 event
.xexpose
.width
, event
.xexpose
.height
);
4087 struct scroll_bar
*bar
4088 = x_window_to_scroll_bar (event
.xexpose
.window
);
4091 x_scroll_bar_expose (bar
, &event
);
4092 #ifdef USE_X_TOOLKIT
4095 #endif /* USE_X_TOOLKIT */
4099 case GraphicsExpose
: /* This occurs when an XCopyArea's
4100 source area was obscured or not
4102 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
4106 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
4107 event
.xgraphicsexpose
.width
,
4108 event
.xgraphicsexpose
.height
);
4110 #ifdef USE_X_TOOLKIT
4113 #endif /* USE_X_TOOLKIT */
4116 case NoExpose
: /* This occurs when an XCopyArea's
4117 source area was completely
4122 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
4123 if (f
) /* F may no longer exist if
4124 the frame was deleted. */
4126 /* While a frame is unmapped, display generation is
4127 disabled; you don't want to spend time updating a
4128 display that won't ever be seen. */
4129 f
->async_visible
= 0;
4130 /* We can't distinguish, from the event, whether the window
4131 has become iconified or invisible. So assume, if it
4132 was previously visible, than now it is iconified.
4133 But x_make_frame_invisible clears both
4134 the visible flag and the iconified flag;
4135 and that way, we know the window is not iconified now. */
4136 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
4138 f
->async_iconified
= 1;
4140 bufp
->kind
= iconify_event
;
4141 XSETFRAME (bufp
->frame_or_window
, f
);
4150 /* We use x_top_window_to_frame because map events can come
4151 for subwindows and they don't mean that the frame is visible. */
4152 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
4155 f
->async_visible
= 1;
4156 f
->async_iconified
= 0;
4157 f
->output_data
.x
->has_been_visible
= 1;
4159 /* wait_reading_process_input will notice this and update
4160 the frame's display structures. */
4161 SET_FRAME_GARBAGED (f
);
4165 bufp
->kind
= deiconify_event
;
4166 XSETFRAME (bufp
->frame_or_window
, f
);
4171 else if (! NILP (Vframe_list
)
4172 && ! NILP (XCONS (Vframe_list
)->cdr
))
4173 /* Force a redisplay sooner or later
4174 to update the frame titles
4175 in case this is the second frame. */
4176 record_asynch_buffer_change ();
4180 /* Turn off processing if we become fully obscured. */
4181 case VisibilityNotify
:
4185 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
4189 KeySym keysym
, orig_keysym
;
4190 /* al%imercury@uunet.uu.net says that making this 81 instead of
4191 80 fixed a bug whereby meta chars made his Emacs hang. */
4192 unsigned char copy_buffer
[81];
4195 #if 0 /* This was how we made f10 work in Motif.
4196 The drawback is, you can't type at Emacs when the
4197 the mouse is in the menu bar. So it is better to
4198 turn off f10 in Motif and let Emacs handle it. */
4200 if (lw_window_is_in_menubar (event
.xkey
.window
,
4201 f
->output_data
.x
->menubar_widget
4204 SET_SAVED_KEY_EVENT
;
4207 #endif /* USE_MOTIF */
4211 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
4212 extra_keyboard_modifiers
);
4213 modifiers
= event
.xkey
.state
;
4215 /* This will have to go some day... */
4217 /* make_lispy_event turns chars into control chars.
4218 Don't do it here because XLookupString is too eager. */
4219 event
.xkey
.state
&= ~ControlMask
;
4220 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
4221 | dpyinfo
->super_mod_mask
4222 | dpyinfo
->hyper_mod_mask
4223 | dpyinfo
->alt_mod_mask
);
4225 /* In case Meta is ComposeCharacter,
4226 clear its status. According to Markus Ehrnsperger
4227 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
4228 this enables ComposeCharacter to work whether or
4229 not it is combined with Meta. */
4230 if (modifiers
& dpyinfo
->meta_mod_mask
)
4231 bzero (&compose_status
, sizeof (compose_status
));
4236 /* The necessity of the following line took me
4237 a full work-day to decipher from the docs!! */
4238 if (XFilterEvent (&event
, None
))
4240 nbytes
= XmbLookupString (FRAME_XIC (f
),
4241 &event
.xkey
, copy_buffer
,
4244 if (status_return
== XLookupNone
)
4246 else if (status_return
== XLookupChars
)
4248 else if (status_return
!= XLookupKeySym
4249 && status_return
!= XLookupBoth
)
4253 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
4254 80, &keysym
, &compose_status
);
4256 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
4257 80, &keysym
, &compose_status
);
4260 orig_keysym
= keysym
;
4264 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
4265 || keysym
== XK_Delete
4266 #ifdef XK_ISO_Left_Tab
4267 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
4269 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
4270 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
4271 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
4273 /* This recognizes the "extended function keys".
4274 It seems there's no cleaner way.
4275 Test IsModifierKey to avoid handling mode_switch
4277 || ((unsigned) (keysym
) >= XK_Select
4278 && (unsigned)(keysym
) < XK_KP_Space
)
4280 #ifdef XK_dead_circumflex
4281 || orig_keysym
== XK_dead_circumflex
4283 #ifdef XK_dead_grave
4284 || orig_keysym
== XK_dead_grave
4286 #ifdef XK_dead_tilde
4287 || orig_keysym
== XK_dead_tilde
4289 #ifdef XK_dead_diaeresis
4290 || orig_keysym
== XK_dead_diaeresis
4292 #ifdef XK_dead_macron
4293 || orig_keysym
== XK_dead_macron
4295 #ifdef XK_dead_degree
4296 || orig_keysym
== XK_dead_degree
4298 #ifdef XK_dead_acute
4299 || orig_keysym
== XK_dead_acute
4301 #ifdef XK_dead_cedilla
4302 || orig_keysym
== XK_dead_cedilla
4304 #ifdef XK_dead_breve
4305 || orig_keysym
== XK_dead_breve
4307 #ifdef XK_dead_ogonek
4308 || orig_keysym
== XK_dead_ogonek
4310 #ifdef XK_dead_caron
4311 || orig_keysym
== XK_dead_caron
4313 #ifdef XK_dead_doubleacute
4314 || orig_keysym
== XK_dead_doubleacute
4316 #ifdef XK_dead_abovedot
4317 || orig_keysym
== XK_dead_abovedot
4319 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
4320 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
4321 /* Any "vendor-specific" key is ok. */
4322 || (orig_keysym
& (1 << 28)))
4323 && ! (IsModifierKey (orig_keysym
)
4325 #ifdef XK_Mode_switch
4326 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
4329 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
4331 #endif /* not HAVE_X11R5 */
4334 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4336 temp_buffer
[temp_index
++] = keysym
;
4337 bufp
->kind
= non_ascii_keystroke
;
4338 bufp
->code
= keysym
;
4339 XSETFRAME (bufp
->frame_or_window
, f
);
4341 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
4343 bufp
->timestamp
= event
.xkey
.time
;
4348 else if (numchars
> nbytes
)
4352 for (i
= 0; i
< nbytes
; i
++)
4354 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4356 temp_buffer
[temp_index
++] = copy_buffer
[i
];
4357 bufp
->kind
= ascii_keystroke
;
4358 bufp
->code
= copy_buffer
[i
];
4359 XSETFRAME (bufp
->frame_or_window
, f
);
4361 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
4363 bufp
->timestamp
= event
.xkey
.time
;
4370 if (keysym
== NoSymbol
)
4381 /* Here's a possible interpretation of the whole
4382 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
4383 FocusIn event, you have to get a FocusOut event before you
4384 relinquish the focus. If you haven't received a FocusIn event,
4385 then a mere LeaveNotify is enough to free you. */
4388 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
4390 if (event
.xcrossing
.focus
) /* Entered Window */
4392 /* Avoid nasty pop/raise loops. */
4393 if (f
&& (!(f
->auto_raise
)
4395 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
4397 x_new_focus_frame (dpyinfo
, f
);
4398 enter_timestamp
= event
.xcrossing
.time
;
4401 else if (f
== dpyinfo
->x_focus_frame
)
4402 x_new_focus_frame (dpyinfo
, 0);
4403 /* EnterNotify counts as mouse movement,
4404 so update things that depend on mouse position. */
4406 note_mouse_movement (f
, &event
.xmotion
);
4410 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
4411 if (event
.xfocus
.detail
!= NotifyPointer
)
4412 dpyinfo
->x_focus_event_frame
= f
;
4414 x_new_focus_frame (dpyinfo
, f
);
4417 if (f
&& FRAME_XIC (f
))
4418 XSetICFocus (FRAME_XIC (f
));
4424 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
4427 if (f
== dpyinfo
->mouse_face_mouse_frame
)
4428 /* If we move outside the frame,
4429 then we're certainly no longer on any text in the frame. */
4430 clear_mouse_face (dpyinfo
);
4432 if (event
.xcrossing
.focus
)
4433 x_mouse_leave (dpyinfo
);
4436 if (f
== dpyinfo
->x_focus_event_frame
)
4437 dpyinfo
->x_focus_event_frame
= 0;
4438 if (f
== dpyinfo
->x_focus_frame
)
4439 x_new_focus_frame (dpyinfo
, 0);
4445 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
4446 if (event
.xfocus
.detail
!= NotifyPointer
4447 && f
== dpyinfo
->x_focus_event_frame
)
4448 dpyinfo
->x_focus_event_frame
= 0;
4449 if (f
&& f
== dpyinfo
->x_focus_frame
)
4450 x_new_focus_frame (dpyinfo
, 0);
4453 if (f
&& FRAME_XIC (f
))
4454 XUnsetICFocus (FRAME_XIC (f
));
4461 if (dpyinfo
->grabbed
&& last_mouse_frame
4462 && FRAME_LIVE_P (last_mouse_frame
))
4463 f
= last_mouse_frame
;
4465 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
4467 note_mouse_movement (f
, &event
.xmotion
);
4470 struct scroll_bar
*bar
4471 = x_window_to_scroll_bar (event
.xmotion
.window
);
4474 x_scroll_bar_note_movement (bar
, &event
);
4476 /* If we move outside the frame,
4477 then we're certainly no longer on any text in the frame. */
4478 clear_mouse_face (dpyinfo
);
4483 case ConfigureNotify
:
4484 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
4487 #ifndef USE_X_TOOLKIT
4488 /* In the toolkit version, change_frame_size
4489 is called by the code that handles resizing
4490 of the EmacsFrame widget. */
4492 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
4493 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
4495 /* Even if the number of character rows and columns has
4496 not changed, the font size may have changed, so we need
4497 to check the pixel dimensions as well. */
4498 if (columns
!= f
->width
4499 || rows
!= f
->height
4500 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
4501 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
4503 change_frame_size (f
, rows
, columns
, 0, 1);
4504 SET_FRAME_GARBAGED (f
);
4505 cancel_mouse_face (f
);
4509 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
4510 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
4512 /* What we have now is the position of Emacs's own window.
4513 Convert that to the position of the window manager window. */
4514 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
4515 &f
->output_data
.x
->top_pos
);
4517 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
4519 /* Since the WM decorations come below top_pos now,
4520 we must put them below top_pos in the future. */
4521 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
4522 x_wm_set_size_hint (f
, (long) 0, 0);
4525 /* Some window managers pass (0,0) as the location of
4526 the window, and the Motif event handler stores it
4527 in the emacs widget, which messes up Motif menus. */
4528 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
4530 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
4531 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
4540 /* If we decide we want to generate an event to be seen
4541 by the rest of Emacs, we put it here. */
4542 struct input_event emacs_event
;
4543 emacs_event
.kind
= no_event
;
4545 bzero (&compose_status
, sizeof (compose_status
));
4547 if (dpyinfo
->grabbed
&& last_mouse_frame
4548 && FRAME_LIVE_P (last_mouse_frame
))
4549 f
= last_mouse_frame
;
4551 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
4555 if (!dpyinfo
->x_focus_frame
|| f
== dpyinfo
->x_focus_frame
)
4556 construct_mouse_click (&emacs_event
, &event
, f
);
4560 struct scroll_bar
*bar
4561 = x_window_to_scroll_bar (event
.xbutton
.window
);
4564 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
4567 if (event
.type
== ButtonPress
)
4569 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
4570 last_mouse_frame
= f
;
4571 /* Ignore any mouse motion that happened
4572 before this event; any subsequent mouse-movement
4573 Emacs events should reflect only motion after
4580 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
4583 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
4585 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
4591 #ifdef USE_X_TOOLKIT
4592 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
4593 /* For a down-event in the menu bar,
4594 don't pass it to Xt right now.
4595 Instead, save it away
4596 and we will pass it to Xt from kbd_buffer_get_event.
4597 That way, we can run some Lisp code first. */
4598 if (f
&& event
.type
== ButtonPress
4599 /* Verify the event is really within the menu bar
4600 and not just sent to it due to grabbing. */
4601 && event
.xbutton
.x
>= 0
4602 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
4603 && event
.xbutton
.y
>= 0
4604 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
4605 && event
.xbutton
.same_screen
)
4607 SET_SAVED_BUTTON_EVENT
;
4608 XSETFRAME (last_mouse_press_frame
, f
);
4610 else if (event
.type
== ButtonPress
)
4612 last_mouse_press_frame
= Qnil
;
4615 #ifdef USE_MOTIF /* This should do not harm for Lucid,
4616 but I am trying to be cautious. */
4617 else if (event
.type
== ButtonRelease
)
4619 if (!NILP (last_mouse_press_frame
))
4621 f
= XFRAME (last_mouse_press_frame
);
4622 if (f
->output_data
.x
)
4624 SET_SAVED_BUTTON_EVENT
;
4630 #endif /* USE_MOTIF */
4633 #endif /* USE_X_TOOLKIT */
4637 case CirculateNotify
:
4639 case CirculateRequest
:
4643 /* Someone has changed the keyboard mapping - update the
4645 switch (event
.xmapping
.request
)
4647 case MappingModifier
:
4648 x_find_modifier_meanings (dpyinfo
);
4649 /* This is meant to fall through. */
4650 case MappingKeyboard
:
4651 XRefreshKeyboardMapping (&event
.xmapping
);
4657 #ifdef USE_X_TOOLKIT
4659 XtDispatchEvent (&event
);
4661 #endif /* USE_X_TOOLKIT */
4667 /* On some systems, an X bug causes Emacs to get no more events
4668 when the window is destroyed. Detect that. (1994.) */
4671 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
4672 One XNOOP in 100 loops will make Emacs terminate.
4673 B. Bretthauer, 1994 */
4675 if (x_noop_count
>= 100)
4679 if (next_noop_dpyinfo
== 0)
4680 next_noop_dpyinfo
= x_display_list
;
4682 XNoOp (next_noop_dpyinfo
->display
);
4684 /* Each time we get here, cycle through the displays now open. */
4685 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
4689 /* If the focus was just given to an autoraising frame,
4691 /* ??? This ought to be able to handle more than one such frame. */
4692 if (pending_autoraise_frame
)
4694 x_raise_frame (pending_autoraise_frame
);
4695 pending_autoraise_frame
= 0;
4702 /* Drawing the cursor. */
4705 /* Draw a hollow box cursor on frame F at X, Y.
4706 Don't change the inside of the box. */
4709 x_draw_box (f
, x
, y
)
4713 int left
= CHAR_TO_PIXEL_COL (f
, x
);
4714 int top
= CHAR_TO_PIXEL_ROW (f
, y
);
4715 int width
= FONT_WIDTH (f
->output_data
.x
->font
);
4716 int height
= f
->output_data
.x
->line_height
;
4717 int c
= FAST_GLYPH_CHAR (f
->phys_cursor_glyph
);
4718 int charset
= CHAR_CHARSET (c
);
4721 unsigned long mask
= GCForeground
;
4723 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
4725 /* cursor_gc's foreground color is typically the same as the normal
4726 background color, which can cause the cursor box to be invisible. */
4727 if (FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
)
4728 XChangeGC (FRAME_X_DISPLAY (f
),
4729 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
,
4732 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
4733 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), mask
, &xgcv
);
4735 /* If cursor is on a multi-column character, multiply WIDTH by columns. */
4736 width
*= (charset
== CHARSET_COMPOSITION
4737 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
4738 : CHARSET_WIDTH (charset
));
4739 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4740 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
,
4741 left
, top
, width
- 1, height
- 1);
4744 /* Clear the cursor of frame F to background color,
4745 and mark the cursor as not shown.
4746 This is used when the text where the cursor is
4747 is about to be rewritten. */
4755 if (! FRAME_VISIBLE_P (f
)
4756 || ! f
->phys_cursor_on
)
4759 x_update_cursor (f
, 0);
4760 f
->phys_cursor_on
= 0;
4763 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4764 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4768 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
4775 CHAR_TO_PIXEL_COL (f
, column
),
4776 CHAR_TO_PIXEL_ROW (f
, row
),
4777 &glyph
, 1, highlight
, 0, NULL
);
4781 x_display_bar_cursor (f
, on
, x
, y
)
4786 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4788 /* This is pointless on invisible frames, and dangerous on garbaged
4789 frames; in the latter case, the frame may be in the midst of
4790 changing its size, and x and y may be off the frame. */
4791 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4794 if (! on
&& ! f
->phys_cursor_on
)
4797 /* If there is anything wrong with the current cursor state, remove it. */
4798 if (f
->phys_cursor_on
4800 || f
->phys_cursor_x
!= x
4801 || f
->phys_cursor_y
!= y
4802 || f
->output_data
.x
->current_cursor
!= bar_cursor
))
4804 /* Erase the cursor by redrawing the character underneath it. */
4805 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4806 f
->phys_cursor_glyph
,
4807 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4808 f
->phys_cursor_on
= 0;
4811 /* If we now need a cursor in the new place or in the new form, do it so. */
4813 && (! f
->phys_cursor_on
4814 || (f
->output_data
.x
->current_cursor
!= bar_cursor
)))
4816 f
->phys_cursor_glyph
4817 = ((current_glyphs
->enable
[y
]
4818 && x
< current_glyphs
->used
[y
])
4819 ? current_glyphs
->glyphs
[y
][x
]
4821 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4822 f
->output_data
.x
->cursor_gc
,
4823 CHAR_TO_PIXEL_COL (f
, x
),
4824 CHAR_TO_PIXEL_ROW (f
, y
),
4825 max (f
->output_data
.x
->cursor_width
, 1),
4826 f
->output_data
.x
->line_height
);
4828 f
->phys_cursor_x
= x
;
4829 f
->phys_cursor_y
= y
;
4830 f
->phys_cursor_on
= 1;
4832 f
->output_data
.x
->current_cursor
= bar_cursor
;
4835 if (updating_frame
!= f
)
4836 XFlush (FRAME_X_DISPLAY (f
));
4840 /* Turn the displayed cursor of frame F on or off according to ON.
4841 If ON is nonzero, where to put the cursor is specified by X and Y. */
4844 x_display_box_cursor (f
, on
, x
, y
)
4849 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4851 /* This is pointless on invisible frames, and dangerous on garbaged
4852 frames; in the latter case, the frame may be in the midst of
4853 changing its size, and x and y may be off the frame. */
4854 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4857 /* If cursor is off and we want it off, return quickly. */
4858 if (!on
&& ! f
->phys_cursor_on
)
4861 /* If cursor is currently being shown and we don't want it to be
4862 or it is in the wrong place,
4863 or we want a hollow box and it's not so, (pout!)
4865 if (f
->phys_cursor_on
4867 || f
->phys_cursor_x
!= x
4868 || f
->phys_cursor_y
!= y
4869 || (f
->output_data
.x
->current_cursor
!= hollow_box_cursor
4870 && (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
))))
4872 int mouse_face_here
= 0;
4873 struct frame_glyphs
*active_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4875 /* If the cursor is in the mouse face area, redisplay that when
4876 we clear the cursor. */
4877 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
4879 (f
->phys_cursor_y
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4880 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4881 && f
->phys_cursor_x
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
))
4883 (f
->phys_cursor_y
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4884 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4885 && f
->phys_cursor_x
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
))
4886 /* Don't redraw the cursor's spot in mouse face
4887 if it is at the end of a line (on a newline).
4888 The cursor appears there, but mouse highlighting does not. */
4889 && active_glyphs
->used
[f
->phys_cursor_y
] > f
->phys_cursor_x
)
4890 mouse_face_here
= 1;
4892 /* If the font is not as tall as a whole line,
4893 we must explicitly clear the line's whole height. */
4894 if (FONT_HEIGHT (f
->output_data
.x
->font
) != f
->output_data
.x
->line_height
)
4895 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4896 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
4897 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
4898 FONT_WIDTH (f
->output_data
.x
->font
),
4899 f
->output_data
.x
->line_height
, False
);
4900 /* Erase the cursor by redrawing the character underneath it. */
4901 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4902 f
->phys_cursor_glyph
,
4905 : current_glyphs
->highlight
[f
->phys_cursor_y
]));
4906 f
->phys_cursor_on
= 0;
4909 /* If we want to show a cursor,
4910 or we want a box cursor and it's not so,
4911 write it in the right place. */
4913 && (! f
->phys_cursor_on
4914 || (f
->output_data
.x
->current_cursor
!= filled_box_cursor
4915 && f
== FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)))
4917 f
->phys_cursor_glyph
4918 = ((current_glyphs
->enable
[y
]
4919 && x
< current_glyphs
->used
[y
])
4920 ? current_glyphs
->glyphs
[y
][x
]
4922 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
4924 x_draw_box (f
, x
, y
);
4925 f
->output_data
.x
->current_cursor
= hollow_box_cursor
;
4929 x_draw_single_glyph (f
, y
, x
,
4930 f
->phys_cursor_glyph
, 2);
4931 f
->output_data
.x
->current_cursor
= filled_box_cursor
;
4934 f
->phys_cursor_x
= x
;
4935 f
->phys_cursor_y
= y
;
4936 f
->phys_cursor_on
= 1;
4939 if (updating_frame
!= f
)
4940 XFlush (FRAME_X_DISPLAY (f
));
4943 /* Display the cursor on frame F, or clear it, according to ON.
4944 Also set the frame's cursor position to X and Y. */
4947 x_display_cursor (f
, on
, x
, y
)
4954 if ((unsigned) x
>= FRAME_CURSOR_X_LIMIT (f
)
4955 || (unsigned) y
>= FRAME_HEIGHT (f
))
4958 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4959 x_display_box_cursor (f
, on
, x
, y
);
4960 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4961 x_display_bar_cursor (f
, on
, x
, y
);
4963 /* Those are the only two we have implemented! */
4969 /* Display the cursor on frame F, or clear it, according to ON.
4970 Don't change the cursor's position. */
4973 x_update_cursor (f
, on
)
4979 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4980 x_display_box_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4981 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4982 x_display_bar_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4984 /* Those are the only two we have implemented! */
4992 /* Refresh bitmap kitchen sink icon for frame F
4993 when we get an expose event for it. */
4999 /* Normally, the window manager handles this function. */
5002 /* Make the x-window of frame F use the gnu icon bitmap. */
5005 x_bitmap_icon (f
, file
)
5009 int mask
, bitmap_id
;
5012 if (FRAME_X_WINDOW (f
) == 0)
5015 /* Free up our existing icon bitmap if any. */
5016 if (f
->output_data
.x
->icon_bitmap
> 0)
5017 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
5018 f
->output_data
.x
->icon_bitmap
= 0;
5021 bitmap_id
= x_create_bitmap_from_file (f
, file
);
5024 /* Create the GNU bitmap if necessary. */
5025 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
5026 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
5027 = x_create_bitmap_from_data (f
, gnu_bits
,
5028 gnu_width
, gnu_height
);
5030 /* The first time we create the GNU bitmap,
5031 this increments the refcount one extra time.
5032 As a result, the GNU bitmap is never freed.
5033 That way, we don't have to worry about allocating it again. */
5034 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
5036 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
5039 x_wm_set_icon_pixmap (f
, bitmap_id
);
5040 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
5046 /* Make the x-window of frame F use a rectangle with text.
5047 Use ICON_NAME as the text. */
5050 x_text_icon (f
, icon_name
)
5054 if (FRAME_X_WINDOW (f
) == 0)
5060 text
.value
= (unsigned char *) icon_name
;
5061 text
.encoding
= XA_STRING
;
5063 text
.nitems
= strlen (icon_name
);
5064 #ifdef USE_X_TOOLKIT
5065 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
5067 #else /* not USE_X_TOOLKIT */
5068 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
5069 #endif /* not USE_X_TOOLKIT */
5071 #else /* not HAVE_X11R4 */
5072 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
5073 #endif /* not HAVE_X11R4 */
5075 if (f
->output_data
.x
->icon_bitmap
> 0)
5076 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
5077 f
->output_data
.x
->icon_bitmap
= 0;
5078 x_wm_set_icon_pixmap (f
, 0);
5083 #define X_ERROR_MESSAGE_SIZE 200
5085 /* If non-nil, this should be a string.
5086 It means catch X errors and store the error message in this string. */
5088 static Lisp_Object x_error_message_string
;
5090 /* An X error handler which stores the error message in
5091 x_error_message_string. This is called from x_error_handler if
5092 x_catch_errors is in effect. */
5095 x_error_catcher (display
, error
)
5099 XGetErrorText (display
, error
->error_code
,
5100 XSTRING (x_error_message_string
)->data
,
5101 X_ERROR_MESSAGE_SIZE
);
5104 /* Begin trapping X errors for display DPY. Actually we trap X errors
5105 for all displays, but DPY should be the display you are actually
5108 After calling this function, X protocol errors no longer cause
5109 Emacs to exit; instead, they are recorded in the string
5110 stored in x_error_message_string.
5112 Calling x_check_errors signals an Emacs error if an X error has
5113 occurred since the last call to x_catch_errors or x_check_errors.
5115 Calling x_uncatch_errors resumes the normal error handling. */
5117 void x_check_errors ();
5118 static Lisp_Object
x_catch_errors_unwind ();
5121 x_catch_errors (dpy
)
5124 int count
= specpdl_ptr
- specpdl
;
5126 /* Make sure any errors from previous requests have been dealt with. */
5129 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
5131 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
5132 XSTRING (x_error_message_string
)->data
[0] = 0;
5137 /* Unbind the binding that we made to check for X errors. */
5140 x_catch_errors_unwind (old_val
)
5141 Lisp_Object old_val
;
5143 x_error_message_string
= old_val
;
5147 /* If any X protocol errors have arrived since the last call to
5148 x_catch_errors or x_check_errors, signal an Emacs error using
5149 sprintf (a buffer, FORMAT, the x error message text) as the text. */
5152 x_check_errors (dpy
, format
)
5156 /* Make sure to catch any errors incurred so far. */
5159 if (XSTRING (x_error_message_string
)->data
[0])
5160 error (format
, XSTRING (x_error_message_string
)->data
);
5163 /* Nonzero if we had any X protocol errors
5164 since we did x_catch_errors on DPY. */
5167 x_had_errors_p (dpy
)
5170 /* Make sure to catch any errors incurred so far. */
5173 return XSTRING (x_error_message_string
)->data
[0] != 0;
5176 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
5179 x_clear_errors (dpy
)
5182 XSTRING (x_error_message_string
)->data
[0] = 0;
5185 /* Stop catching X protocol errors and let them make Emacs die.
5186 DPY should be the display that was passed to x_catch_errors.
5187 COUNT should be the value that was returned by
5188 the corresponding call to x_catch_errors. */
5191 x_uncatch_errors (dpy
, count
)
5195 unbind_to (count
, Qnil
);
5199 static unsigned int x_wire_count
;
5202 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
5207 /* Handle SIGPIPE, which can happen when the connection to a server
5208 simply goes away. SIGPIPE is handled by x_connection_signal.
5209 Don't need to do anything, because the write which caused the
5210 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
5211 which will do the appropriate cleanup for us. */
5214 x_connection_signal (signalnum
) /* If we don't have an argument, */
5215 int signalnum
; /* some compilers complain in signal calls. */
5218 /* USG systems forget handlers when they are used;
5219 must reestablish each time */
5220 signal (signalnum
, x_connection_signal
);
5224 /* Handling X errors. */
5226 /* Handle the loss of connection to display DISPLAY. */
5229 x_connection_closed (display
, error_message
)
5231 char *error_message
;
5233 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
5234 Lisp_Object frame
, tail
;
5236 /* Indicate that this display is dead. */
5238 #ifdef USE_X_TOOLKIT
5239 XtCloseDisplay (display
);
5242 dpyinfo
->display
= 0;
5244 /* First delete frames whose minibuffers are on frames
5245 that are on the dead display. */
5246 FOR_EACH_FRAME (tail
, frame
)
5248 Lisp_Object minibuf_frame
;
5250 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
5251 if (FRAME_X_P (XFRAME (frame
))
5252 && FRAME_X_P (XFRAME (minibuf_frame
))
5253 && ! EQ (frame
, minibuf_frame
)
5254 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
5255 Fdelete_frame (frame
, Qt
);
5258 /* Now delete all remaining frames on the dead display.
5259 We are now sure none of these is used as the minibuffer
5260 for another frame that we need to delete. */
5261 FOR_EACH_FRAME (tail
, frame
)
5262 if (FRAME_X_P (XFRAME (frame
))
5263 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
5265 /* Set this to t so that Fdelete_frame won't get confused
5266 trying to find a replacement. */
5267 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
5268 Fdelete_frame (frame
, Qt
);
5272 x_delete_display (dpyinfo
);
5274 if (x_display_list
== 0)
5276 fprintf (stderr
, "%s\n", error_message
);
5277 shut_down_emacs (0, 0, Qnil
);
5281 /* Ordinary stack unwind doesn't deal with these. */
5283 sigunblock (sigmask (SIGIO
));
5285 sigunblock (sigmask (SIGALRM
));
5286 TOTALLY_UNBLOCK_INPUT
;
5288 clear_waiting_for_input ();
5289 error ("%s", error_message
);
5292 /* This is the usual handler for X protocol errors.
5293 It kills all frames on the display that we got the error for.
5294 If that was the only one, it prints an error message and kills Emacs. */
5297 x_error_quitter (display
, error
)
5301 char buf
[256], buf1
[356];
5303 /* Note that there is no real way portable across R3/R4 to get the
5304 original error handler. */
5306 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
5307 sprintf (buf1
, "X protocol error: %s on protocol request %d",
5308 buf
, error
->request_code
);
5309 x_connection_closed (display
, buf1
);
5312 /* This is the first-level handler for X protocol errors.
5313 It calls x_error_quitter or x_error_catcher. */
5316 x_error_handler (display
, error
)
5320 char buf
[256], buf1
[356];
5322 if (! NILP (x_error_message_string
))
5323 x_error_catcher (display
, error
);
5325 x_error_quitter (display
, error
);
5328 /* This is the handler for X IO errors, always.
5329 It kills all frames on the display that we lost touch with.
5330 If that was the only one, it prints an error message and kills Emacs. */
5333 x_io_error_quitter (display
)
5338 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
5339 x_connection_closed (display
, buf
);
5342 /* Changing the font of the frame. */
5344 /* Give frame F the font named FONTNAME as its default font, and
5345 return the full name of that font. FONTNAME may be a wildcard
5346 pattern; in that case, we choose some font that fits the pattern.
5347 The return value shows which font we chose. */
5350 x_new_font (f
, fontname
)
5352 register char *fontname
;
5354 struct font_info
*fontp
5355 = fs_load_font (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
, fontname
, -1);
5360 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
5361 f
->output_data
.x
->font_baseline
5362 = (f
->output_data
.x
->font
->ascent
+ fontp
->baseline_offset
);
5363 f
->output_data
.x
->fontset
= -1;
5365 /* Compute the scroll bar width in character columns. */
5366 if (f
->scroll_bar_pixel_width
> 0)
5368 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
5369 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
5373 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
5374 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
5377 /* Now make the frame display the given font. */
5378 if (FRAME_X_WINDOW (f
) != 0)
5380 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
5381 f
->output_data
.x
->font
->fid
);
5382 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
5383 f
->output_data
.x
->font
->fid
);
5384 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
5385 f
->output_data
.x
->font
->fid
);
5387 frame_update_line_height (f
);
5388 x_set_window_size (f
, 0, f
->width
, f
->height
);
5391 /* If we are setting a new frame's font for the first time,
5392 there are no faces yet, so this font's height is the line height. */
5393 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
5395 return build_string (fontp
->full_name
);
5398 /* Give frame F the fontset named FONTSETNAME as its default font, and
5399 return the full name of that fontset. FONTSETNAME may be a wildcard
5400 pattern; in that case, we choose some fontset that fits the pattern.
5401 The return value shows which fontset we chose. */
5404 x_new_fontset (f
, fontsetname
)
5408 int fontset
= fs_query_fontset (f
, fontsetname
);
5409 struct fontset_info
*fontsetp
;
5415 if (f
->output_data
.x
->fontset
== fontset
)
5416 /* This fontset is already set in frame F. There's nothing more
5418 return build_string (fontsetname
);
5420 fontsetp
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
5422 if (!fontsetp
->fontname
[CHARSET_ASCII
])
5423 /* This fontset doesn't contain ASCII font. */
5426 result
= x_new_font (f
, fontsetp
->fontname
[CHARSET_ASCII
]);
5428 if (!STRINGP (result
))
5429 /* Can't load ASCII font. */
5432 /* Since x_new_font doesn't update any fontset information, do it now. */
5433 f
->output_data
.x
->fontset
= fontset
;
5434 FS_LOAD_FONT (f
, FRAME_X_FONT_TABLE (f
),
5435 CHARSET_ASCII
, XSTRING (result
)->data
, fontset
);
5437 return build_string (fontsetname
);
5440 /* Calculate the absolute position in frame F
5441 from its current recorded position values and gravity. */
5444 x_calc_absolute_position (f
)
5448 int win_x
= 0, win_y
= 0;
5449 int flags
= f
->output_data
.x
->size_hint_flags
;
5452 /* We have nothing to do if the current position
5453 is already for the top-left corner. */
5454 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
5457 #ifdef USE_X_TOOLKIT
5458 this_window
= XtWindow (f
->output_data
.x
->widget
);
5460 this_window
= FRAME_X_WINDOW (f
);
5463 /* Find the position of the outside upper-left corner of
5464 the inner window, with respect to the outer window.
5465 But do this only if we will need the results. */
5466 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
5471 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
5474 x_clear_errors (FRAME_X_DISPLAY (f
));
5475 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
5477 /* From-window, to-window. */
5479 f
->output_data
.x
->parent_desc
,
5481 /* From-position, to-position. */
5482 0, 0, &win_x
, &win_y
,
5486 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
5488 Window newroot
, newparent
= 0xdeadbeef;
5489 Window
*newchildren
;
5492 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
5493 &newparent
, &newchildren
, &nchildren
))
5496 XFree ((char *) newchildren
);
5498 f
->output_data
.x
->parent_desc
= newparent
;
5504 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
5508 /* Treat negative positions as relative to the leftmost bottommost
5509 position that fits on the screen. */
5510 if (flags
& XNegative
)
5511 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
5512 - 2 * f
->output_data
.x
->border_width
- win_x
5514 + f
->output_data
.x
->left_pos
);
5516 if (flags
& YNegative
)
5517 /* We used to subtract f->output_data.x->menubar_height here
5518 in the toolkit case, but PIXEL_HEIGHT already includes that. */
5519 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
5520 - 2 * f
->output_data
.x
->border_width
- win_y
5522 + f
->output_data
.x
->top_pos
);
5524 /* The left_pos and top_pos
5525 are now relative to the top and left screen edges,
5526 so the flags should correspond. */
5527 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5530 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5531 to really change the position, and 0 when calling from
5532 x_make_frame_visible (in that case, XOFF and YOFF are the current
5533 position values). It is -1 when calling from x_set_frame_parameters,
5534 which means, do adjust for borders but don't change the gravity. */
5537 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5539 register int xoff
, yoff
;
5542 int modified_top
, modified_left
;
5544 if (change_gravity
> 0)
5546 f
->output_data
.x
->top_pos
= yoff
;
5547 f
->output_data
.x
->left_pos
= xoff
;
5548 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5550 f
->output_data
.x
->size_hint_flags
|= XNegative
;
5552 f
->output_data
.x
->size_hint_flags
|= YNegative
;
5553 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
5555 x_calc_absolute_position (f
);
5558 x_wm_set_size_hint (f
, (long) 0, 0);
5560 modified_left
= f
->output_data
.x
->left_pos
;
5561 modified_top
= f
->output_data
.x
->top_pos
;
5562 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
5563 this seems to be unnecessary and incorrect. rms, 4/17/97. */
5564 /* It is a mystery why we need to add the border_width here
5565 when the frame is already visible, but experiment says we do. */
5566 if (change_gravity
!= 0)
5568 modified_left
+= f
->output_data
.x
->border_width
;
5569 modified_top
+= f
->output_data
.x
->border_width
;
5573 #ifdef USE_X_TOOLKIT
5574 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
5575 modified_left
, modified_top
);
5576 #else /* not USE_X_TOOLKIT */
5577 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5578 modified_left
, modified_top
);
5579 #endif /* not USE_X_TOOLKIT */
5583 /* Call this to change the size of frame F's x-window.
5584 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5585 for this size change and subsequent size changes.
5586 Otherwise we leave the window gravity unchanged. */
5589 x_set_window_size (f
, change_gravity
, cols
, rows
)
5594 int pixelwidth
, pixelheight
;
5596 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5600 #ifdef USE_X_TOOLKIT
5602 /* The x and y position of the widget is clobbered by the
5603 call to XtSetValues within EmacsFrameSetCharSize.
5604 This is a real kludge, but I don't understand Xt so I can't
5605 figure out a correct fix. Can anyone else tell me? -- rms. */
5606 int xpos
= f
->output_data
.x
->widget
->core
.x
;
5607 int ypos
= f
->output_data
.x
->widget
->core
.y
;
5608 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
5609 f
->output_data
.x
->widget
->core
.x
= xpos
;
5610 f
->output_data
.x
->widget
->core
.y
= ypos
;
5613 #else /* not USE_X_TOOLKIT */
5615 check_frame_size (f
, &rows
, &cols
);
5616 f
->output_data
.x
->vertical_scroll_bar_extra
5617 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5619 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
5620 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
5621 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
5622 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
5623 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
5625 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
5626 x_wm_set_size_hint (f
, (long) 0, 0);
5628 XSync (FRAME_X_DISPLAY (f
), False
);
5629 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5630 pixelwidth
, pixelheight
);
5632 /* Now, strictly speaking, we can't be sure that this is accurate,
5633 but the window manager will get around to dealing with the size
5634 change request eventually, and we'll hear how it went when the
5635 ConfigureNotify event gets here.
5637 We could just not bother storing any of this information here,
5638 and let the ConfigureNotify event set everything up, but that
5639 might be kind of confusing to the lisp code, since size changes
5640 wouldn't be reported in the frame parameters until some random
5641 point in the future when the ConfigureNotify event arrives. */
5642 change_frame_size (f
, rows
, cols
, 0, 0);
5643 PIXEL_WIDTH (f
) = pixelwidth
;
5644 PIXEL_HEIGHT (f
) = pixelheight
;
5646 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5647 receive in the ConfigureNotify event; if we get what we asked
5648 for, then the event won't cause the screen to become garbaged, so
5649 we have to make sure to do it here. */
5650 SET_FRAME_GARBAGED (f
);
5652 XFlush (FRAME_X_DISPLAY (f
));
5654 #endif /* not USE_X_TOOLKIT */
5656 /* If cursor was outside the new size, mark it as off. */
5657 if (f
->phys_cursor_y
>= rows
5658 || f
->phys_cursor_x
>= cols
)
5660 f
->phys_cursor_x
= 0;
5661 f
->phys_cursor_y
= 0;
5662 f
->phys_cursor_on
= 0;
5665 /* Clear out any recollection of where the mouse highlighting was,
5666 since it might be in a place that's outside the new frame size.
5667 Actually checking whether it is outside is a pain in the neck,
5668 so don't try--just let the highlighting be done afresh with new size. */
5669 cancel_mouse_face (f
);
5674 /* Mouse warping. */
5677 x_set_mouse_position (f
, x
, y
)
5683 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
5684 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
5686 if (pix_x
< 0) pix_x
= 0;
5687 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
5689 if (pix_y
< 0) pix_y
= 0;
5690 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
5694 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5695 0, 0, 0, 0, pix_x
, pix_y
);
5699 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
5702 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5708 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5709 0, 0, 0, 0, pix_x
, pix_y
);
5713 /* focus shifting, raising and lowering. */
5716 x_focus_on_frame (f
)
5719 #if 0 /* This proves to be unpleasant. */
5723 /* I don't think that the ICCCM allows programs to do things like this
5724 without the interaction of the window manager. Whatever you end up
5725 doing with this code, do it to x_unfocus_frame too. */
5726 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5727 RevertToPointerRoot
, CurrentTime
);
5736 /* Look at the remarks in x_focus_on_frame. */
5737 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
5738 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
5739 RevertToPointerRoot
, CurrentTime
);
5743 /* Raise frame F. */
5749 if (f
->async_visible
)
5752 #ifdef USE_X_TOOLKIT
5753 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
5754 #else /* not USE_X_TOOLKIT */
5755 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5756 #endif /* not USE_X_TOOLKIT */
5757 XFlush (FRAME_X_DISPLAY (f
));
5762 /* Lower frame F. */
5768 if (f
->async_visible
)
5771 #ifdef USE_X_TOOLKIT
5772 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
5773 #else /* not USE_X_TOOLKIT */
5774 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5775 #endif /* not USE_X_TOOLKIT */
5776 XFlush (FRAME_X_DISPLAY (f
));
5782 XTframe_raise_lower (f
, raise_flag
)
5792 /* Change of visibility. */
5794 /* This tries to wait until the frame is really visible.
5795 However, if the window manager asks the user where to position
5796 the frame, this will return before the user finishes doing that.
5797 The frame will not actually be visible at that time,
5798 but it will become visible later when the window manager
5799 finishes with it. */
5802 x_make_frame_visible (f
)
5807 int starting_flags
= f
->output_data
.x
->size_hint_flags
;
5808 int original_top
, original_left
;
5812 type
= x_icon_type (f
);
5814 x_bitmap_icon (f
, type
);
5816 if (! FRAME_VISIBLE_P (f
))
5818 /* We test FRAME_GARBAGED_P here to make sure we don't
5819 call x_set_offset a second time
5820 if we get to x_make_frame_visible a second time
5821 before the window gets really visible. */
5822 if (! FRAME_ICONIFIED_P (f
)
5823 && ! f
->output_data
.x
->asked_for_visible
)
5824 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
5826 f
->output_data
.x
->asked_for_visible
= 1;
5828 if (! EQ (Vx_no_window_manager
, Qt
))
5829 x_wm_set_window_state (f
, NormalState
);
5830 #ifdef USE_X_TOOLKIT
5831 /* This was XtPopup, but that did nothing for an iconified frame. */
5832 XtMapWidget (f
->output_data
.x
->widget
);
5833 #else /* not USE_X_TOOLKIT */
5834 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5835 #endif /* not USE_X_TOOLKIT */
5836 #if 0 /* This seems to bring back scroll bars in the wrong places
5837 if the window configuration has changed. They seem
5838 to come back ok without this. */
5839 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5840 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5844 XFlush (FRAME_X_DISPLAY (f
));
5846 /* Synchronize to ensure Emacs knows the frame is visible
5847 before we do anything else. We do this loop with input not blocked
5848 so that incoming events are handled. */
5851 int count
= input_signal_count
;
5852 /* This must be before UNBLOCK_INPUT
5853 since events that arrive in response to the actions above
5854 will set it when they are handled. */
5855 int previously_visible
= f
->output_data
.x
->has_been_visible
;
5857 original_left
= f
->output_data
.x
->left_pos
;
5858 original_top
= f
->output_data
.x
->top_pos
;
5860 /* This must come after we set COUNT. */
5863 /* We unblock here so that arriving X events are processed. */
5865 /* Now move the window back to where it was "supposed to be".
5866 But don't do it if the gravity is negative.
5867 When the gravity is negative, this uses a position
5868 that is 3 pixels too low. Perhaps that's really the border width.
5870 Don't do this if the window has never been visible before,
5871 because the window manager may choose the position
5872 and we don't want to override it. */
5874 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
5875 && f
->output_data
.x
->win_gravity
== NorthWestGravity
5876 && previously_visible
)
5880 unsigned int width
, height
, border
, depth
;
5884 /* On some window managers (Such as FVWM) moving an existing window,
5885 even to the same place, causes the window manager to introduce
5886 an offset. This can cause the window to move to an unexpected
5887 location. Check the geometry (A little slow here) and then verify
5888 that the window is in the right place. If the window is not in
5889 the right place, move it there, and take the potential window
5892 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
5893 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
5895 if (original_left
!= x
|| original_top
!= y
)
5896 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
5897 original_left
, original_top
);
5902 XSETFRAME (frame
, f
);
5907 /* Once we have handled input events,
5908 we should have received the MapNotify if one is coming.
5909 So if we have not got it yet, stop looping.
5910 Some window managers make their own decisions
5911 about visibility. */
5912 if (input_signal_count
!= count
)
5914 /* Machines that do polling rather than SIGIO have been observed
5915 to go into a busy-wait here. So we'll fake an alarm signal
5916 to let the handler know that there's something to be read.
5917 We used to raise a real alarm, but it seems that the handler
5918 isn't always enabled here. This is probably a bug. */
5919 if (input_polling_used ())
5921 /* It could be confusing if a real alarm arrives while processing
5922 the fake one. Turn it off and let the handler reset it. */
5924 input_poll_signal (0);
5926 /* Once we have handled input events,
5927 we should have received the MapNotify if one is coming.
5928 So if we have not got it yet, stop looping.
5929 Some window managers make their own decisions
5930 about visibility. */
5931 if (input_signal_count
!= count
)
5934 FRAME_SAMPLE_VISIBILITY (f
);
5938 /* Change from mapped state to withdrawn state. */
5940 /* Make the frame visible (mapped and not iconified). */
5943 x_make_frame_invisible (f
)
5949 #ifdef USE_X_TOOLKIT
5950 /* Use the frame's outermost window, not the one we normally draw on. */
5951 window
= XtWindow (f
->output_data
.x
->widget
);
5952 #else /* not USE_X_TOOLKIT */
5953 window
= FRAME_X_WINDOW (f
);
5954 #endif /* not USE_X_TOOLKIT */
5956 /* Don't keep the highlight on an invisible frame. */
5957 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5958 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5960 #if 0/* This might add unreliability; I don't trust it -- rms. */
5961 if (! f
->async_visible
&& ! f
->async_iconified
)
5967 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5968 that the current position of the window is user-specified, rather than
5969 program-specified, so that when the window is mapped again, it will be
5970 placed at the same location, without forcing the user to position it
5971 by hand again (they have already done that once for this window.) */
5972 x_wm_set_size_hint (f
, (long) 0, 1);
5976 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
5977 DefaultScreen (FRAME_X_DISPLAY (f
))))
5979 UNBLOCK_INPUT_RESIGNAL
;
5980 error ("Can't notify window manager of window withdrawal");
5982 #else /* ! defined (HAVE_X11R4) */
5984 /* Tell the window manager what we're going to do. */
5985 if (! EQ (Vx_no_window_manager
, Qt
))
5989 unmap
.xunmap
.type
= UnmapNotify
;
5990 unmap
.xunmap
.window
= window
;
5991 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
5992 unmap
.xunmap
.from_configure
= False
;
5993 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5994 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5996 SubstructureRedirectMask
|SubstructureNotifyMask
,
5999 UNBLOCK_INPUT_RESIGNAL
;
6000 error ("Can't notify window manager of withdrawal");
6004 /* Unmap the window ourselves. Cheeky! */
6005 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
6006 #endif /* ! defined (HAVE_X11R4) */
6008 /* We can't distinguish this from iconification
6009 just by the event that we get from the server.
6010 So we can't win using the usual strategy of letting
6011 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
6012 and synchronize with the server to make sure we agree. */
6014 FRAME_ICONIFIED_P (f
) = 0;
6015 f
->async_visible
= 0;
6016 f
->async_iconified
= 0;
6023 /* Change window state from mapped to iconified. */
6033 /* Don't keep the highlight on an invisible frame. */
6034 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
6035 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
6037 if (f
->async_iconified
)
6042 FRAME_SAMPLE_VISIBILITY (f
);
6044 type
= x_icon_type (f
);
6046 x_bitmap_icon (f
, type
);
6048 #ifdef USE_X_TOOLKIT
6050 if (! FRAME_VISIBLE_P (f
))
6052 if (! EQ (Vx_no_window_manager
, Qt
))
6053 x_wm_set_window_state (f
, IconicState
);
6054 /* This was XtPopup, but that did nothing for an iconified frame. */
6055 XtMapWidget (f
->output_data
.x
->widget
);
6056 /* The server won't give us any event to indicate
6057 that an invisible frame was changed to an icon,
6058 so we have to record it here. */
6061 f
->async_iconified
= 1;
6062 f
->async_visible
= 0;
6067 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
6068 XtWindow (f
->output_data
.x
->widget
),
6069 DefaultScreen (FRAME_X_DISPLAY (f
)));
6073 error ("Can't notify window manager of iconification");
6075 f
->async_iconified
= 1;
6076 f
->async_visible
= 0;
6080 XFlush (FRAME_X_DISPLAY (f
));
6082 #else /* not USE_X_TOOLKIT */
6084 /* Make sure the X server knows where the window should be positioned,
6085 in case the user deiconifies with the window manager. */
6086 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
6087 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
6089 /* Since we don't know which revision of X we're running, we'll use both
6090 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
6092 /* X11R4: send a ClientMessage to the window manager using the
6093 WM_CHANGE_STATE type. */
6097 message
.xclient
.window
= FRAME_X_WINDOW (f
);
6098 message
.xclient
.type
= ClientMessage
;
6099 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
6100 message
.xclient
.format
= 32;
6101 message
.xclient
.data
.l
[0] = IconicState
;
6103 if (! XSendEvent (FRAME_X_DISPLAY (f
),
6104 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
6106 SubstructureRedirectMask
| SubstructureNotifyMask
,
6109 UNBLOCK_INPUT_RESIGNAL
;
6110 error ("Can't notify window manager of iconification");
6114 /* X11R3: set the initial_state field of the window manager hints to
6116 x_wm_set_window_state (f
, IconicState
);
6118 if (!FRAME_VISIBLE_P (f
))
6120 /* If the frame was withdrawn, before, we must map it. */
6121 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
6124 f
->async_iconified
= 1;
6125 f
->async_visible
= 0;
6127 XFlush (FRAME_X_DISPLAY (f
));
6129 #endif /* not USE_X_TOOLKIT */
6132 /* Destroy the X window of frame F. */
6135 x_destroy_window (f
)
6138 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6142 /* If a display connection is dead, don't try sending more
6143 commands to the X server. */
6144 if (dpyinfo
->display
!= 0)
6146 if (f
->output_data
.x
->icon_desc
!= 0)
6147 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
6151 XDestroyIC (FRAME_XIC (f
));
6152 #if ! defined (SOLARIS2) || defined (HAVE_X11R6)
6153 /* This line causes crashes on Solaris with Openwin,
6154 due to an apparent bug in XCloseIM.
6155 X11R6 seems not to have the bug. */
6156 XCloseIM (FRAME_XIM (f
));
6160 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
6161 #ifdef USE_X_TOOLKIT
6162 XtDestroyWidget (f
->output_data
.x
->widget
);
6163 free_frame_menubar (f
);
6164 #endif /* USE_X_TOOLKIT */
6166 free_frame_faces (f
);
6167 XFlush (FRAME_X_DISPLAY (f
));
6170 if (f
->output_data
.x
->saved_menu_event
)
6171 free (f
->output_data
.x
->saved_menu_event
);
6173 xfree (f
->output_data
.x
);
6174 f
->output_data
.x
= 0;
6175 if (f
== dpyinfo
->x_focus_frame
)
6176 dpyinfo
->x_focus_frame
= 0;
6177 if (f
== dpyinfo
->x_focus_event_frame
)
6178 dpyinfo
->x_focus_event_frame
= 0;
6179 if (f
== dpyinfo
->x_highlight_frame
)
6180 dpyinfo
->x_highlight_frame
= 0;
6182 dpyinfo
->reference_count
--;
6184 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6186 dpyinfo
->mouse_face_beg_row
6187 = dpyinfo
->mouse_face_beg_col
= -1;
6188 dpyinfo
->mouse_face_end_row
6189 = dpyinfo
->mouse_face_end_col
= -1;
6190 dpyinfo
->mouse_face_window
= Qnil
;
6191 dpyinfo
->mouse_face_deferred_gc
= 0;
6192 dpyinfo
->mouse_face_mouse_frame
= 0;
6198 /* Setting window manager hints. */
6200 /* Set the normal size hints for the window manager, for frame F.
6201 FLAGS is the flags word to use--or 0 meaning preserve the flags
6202 that the window now has.
6203 If USER_POSITION is nonzero, we set the USPosition
6204 flag (this is useful when FLAGS is 0). */
6207 x_wm_set_size_hint (f
, flags
, user_position
)
6212 XSizeHints size_hints
;
6214 #ifdef USE_X_TOOLKIT
6217 Dimension widget_width
, widget_height
;
6218 Window window
= XtWindow (f
->output_data
.x
->widget
);
6219 #else /* not USE_X_TOOLKIT */
6220 Window window
= FRAME_X_WINDOW (f
);
6221 #endif /* not USE_X_TOOLKIT */
6223 /* Setting PMaxSize caused various problems. */
6224 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
6226 flexlines
= f
->height
;
6228 size_hints
.x
= f
->output_data
.x
->left_pos
;
6229 size_hints
.y
= f
->output_data
.x
->top_pos
;
6231 #ifdef USE_X_TOOLKIT
6232 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
6233 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
6234 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
6235 size_hints
.height
= widget_height
;
6236 size_hints
.width
= widget_width
;
6237 #else /* not USE_X_TOOLKIT */
6238 size_hints
.height
= PIXEL_HEIGHT (f
);
6239 size_hints
.width
= PIXEL_WIDTH (f
);
6240 #endif /* not USE_X_TOOLKIT */
6242 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
6243 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
6244 size_hints
.max_width
6245 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
6246 size_hints
.max_height
6247 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
6249 /* Calculate the base and minimum sizes.
6251 (When we use the X toolkit, we don't do it here.
6252 Instead we copy the values that the widgets are using, below.) */
6253 #ifndef USE_X_TOOLKIT
6255 int base_width
, base_height
;
6256 int min_rows
= 0, min_cols
= 0;
6258 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
6259 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
6261 check_frame_size (f
, &min_rows
, &min_cols
);
6263 /* The window manager uses the base width hints to calculate the
6264 current number of rows and columns in the frame while
6265 resizing; min_width and min_height aren't useful for this
6266 purpose, since they might not give the dimensions for a
6267 zero-row, zero-column frame.
6269 We use the base_width and base_height members if we have
6270 them; otherwise, we set the min_width and min_height members
6271 to the size for a zero x zero frame. */
6274 size_hints
.flags
|= PBaseSize
;
6275 size_hints
.base_width
= base_width
;
6276 size_hints
.base_height
= base_height
;
6277 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
6278 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
6280 size_hints
.min_width
= base_width
;
6281 size_hints
.min_height
= base_height
;
6285 /* If we don't need the old flags, we don't need the old hint at all. */
6288 size_hints
.flags
|= flags
;
6291 #endif /* not USE_X_TOOLKIT */
6294 XSizeHints hints
; /* Sometimes I hate X Windows... */
6295 long supplied_return
;
6299 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
6302 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
6305 #ifdef USE_X_TOOLKIT
6306 size_hints
.base_height
= hints
.base_height
;
6307 size_hints
.base_width
= hints
.base_width
;
6308 size_hints
.min_height
= hints
.min_height
;
6309 size_hints
.min_width
= hints
.min_width
;
6313 size_hints
.flags
|= flags
;
6318 if (hints
.flags
& PSize
)
6319 size_hints
.flags
|= PSize
;
6320 if (hints
.flags
& PPosition
)
6321 size_hints
.flags
|= PPosition
;
6322 if (hints
.flags
& USPosition
)
6323 size_hints
.flags
|= USPosition
;
6324 if (hints
.flags
& USSize
)
6325 size_hints
.flags
|= USSize
;
6332 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
6333 size_hints
.flags
|= PWinGravity
;
6337 size_hints
.flags
&= ~ PPosition
;
6338 size_hints
.flags
|= USPosition
;
6340 #endif /* PWinGravity */
6343 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
6345 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
6349 /* Used for IconicState or NormalState */
6351 x_wm_set_window_state (f
, state
)
6355 #ifdef USE_X_TOOLKIT
6358 XtSetArg (al
[0], XtNinitialState
, state
);
6359 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6360 #else /* not USE_X_TOOLKIT */
6361 Window window
= FRAME_X_WINDOW (f
);
6363 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
6364 f
->output_data
.x
->wm_hints
.initial_state
= state
;
6366 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6367 #endif /* not USE_X_TOOLKIT */
6371 x_wm_set_icon_pixmap (f
, pixmap_id
)
6377 #ifdef USE_X_TOOLKIT
6378 Window window
= XtWindow (f
->output_data
.x
->widget
);
6380 Window window
= FRAME_X_WINDOW (f
);
6385 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
6386 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
6390 /* It seems there is no way to turn off use of an icon pixmap.
6391 The following line does it, only if no icon has yet been created,
6392 for some window managers. But with mwm it crashes.
6393 Some people say it should clear the IconPixmapHint bit in this case,
6394 but that doesn't work, and the X consortium said it isn't the
6395 right thing at all. Since there is no way to win,
6396 best to explicitly give up. */
6398 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
6404 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
6408 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
6409 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6412 #else /* not USE_X_TOOLKIT */
6414 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
6415 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6417 #endif /* not USE_X_TOOLKIT */
6421 x_wm_set_icon_position (f
, icon_x
, icon_y
)
6425 #ifdef USE_X_TOOLKIT
6426 Window window
= XtWindow (f
->output_data
.x
->widget
);
6428 Window window
= FRAME_X_WINDOW (f
);
6431 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
6432 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
6433 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
6435 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6439 /* Interface to fontset handler. */
6441 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6443 x_get_font_info (f
, font_idx
)
6447 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
6451 /* Return a list of names of available fonts matching PATTERN on frame
6452 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6453 to be listed. Frame F NULL means we have not yet created any
6454 frame on X, and consult the first display in x_display_list.
6455 MAXNAMES sets a limit on how many fonts to match. */
6458 x_list_fonts (f
, pattern
, size
, maxnames
)
6460 Lisp_Object pattern
;
6464 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
, tem
, second_best
;
6465 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
6466 int try_XLoadQueryFont
= 0;
6468 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
6469 if (NILP (patterns
))
6470 patterns
= Fcons (pattern
, Qnil
);
6472 if (maxnames
== 1 && !size
)
6473 /* We can return any single font matching PATTERN. */
6474 try_XLoadQueryFont
= 1;
6476 for (; CONSP (patterns
); patterns
= XCONS (patterns
)->cdr
)
6481 pattern
= XCONS (patterns
)->car
;
6482 /* See if we cached the result for this particular query.
6483 The cache is an alist of the form:
6484 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
6486 if (f
&& (tem
= XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
,
6487 key
= Fcons (pattern
, make_number (maxnames
)),
6488 !NILP (list
= Fassoc (key
, tem
))))
6490 list
= Fcdr_safe (list
);
6491 /* We have a cashed list. Don't have to get the list again. */
6495 /* At first, put PATTERN in the cache. */
6498 if (try_XLoadQueryFont
)
6501 unsigned long value
;
6503 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
6505 && XGetFontProperty (font
, XA_FONT
, &value
))
6507 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
6508 int len
= strlen (name
);
6511 /* If DXPC (a Differential X Protocol Compressor)
6512 Ver.3.7 is running, XGetAtomName will return null
6513 string. We must avoid such a name. */
6515 try_XLoadQueryFont
= 0;
6519 names
= (char **) alloca (sizeof (char *));
6520 /* Some systems only allow alloca assigned to a
6522 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
6523 bcopy (name
, names
[0], len
+ 1);
6528 try_XLoadQueryFont
= 0;
6531 XFreeFont (dpy
, font
);
6534 if (!try_XLoadQueryFont
)
6535 /* We try at least 10 fonts because XListFonts will return
6536 auto-scaled fonts at the head. */
6537 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
6545 /* Make a list of all the fonts we got back.
6546 Store that in the font cache for the display. */
6547 for (i
= 0; i
< num_fonts
; i
++)
6550 int average_width
= -1, dashes
= 0, width
= 0;
6552 /* Count the number of dashes in NAMES[I]. If there are
6553 14 dashes, and the field value following 12th dash
6554 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
6555 is usually too ugly to be used for editing. Let's
6561 if (dashes
== 7) /* PIXEL_SIZE field */
6563 else if (dashes
== 12) /* AVERAGE_WIDTH field */
6564 average_width
= atoi (p
);
6566 if (dashes
< 14 || average_width
!= 0)
6568 tem
= build_string (names
[i
]);
6569 if (NILP (Fassoc (tem
, list
)))
6571 if (STRINGP (Vx_pixel_size_width_font_regexp
)
6572 && ((fast_c_string_match_ignore_case
6573 (Vx_pixel_size_width_font_regexp
, names
[i
]))
6575 /* We can set the value of PIXEL_SIZE to the
6576 width of this font. */
6577 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
6579 /* For the moment, width is not known. */
6580 list
= Fcons (Fcons (tem
, Qnil
), list
);
6584 if (!try_XLoadQueryFont
)
6585 XFreeFontNames (names
);
6588 /* Now store the result in the cache. */
6590 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
6591 = Fcons (Fcons (key
, list
),
6592 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
);
6595 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6597 newlist
= second_best
= Qnil
;
6598 /* Make a list of the fonts that have the right width. */
6599 for (; CONSP (list
); list
= XCONS (list
)->cdr
)
6603 tem
= XCONS (list
)->car
;
6605 if (!CONSP (tem
) || NILP (XCONS (tem
)->car
))
6609 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
6613 if (!INTEGERP (XCONS (tem
)->cdr
))
6615 /* Since we have not yet known the size of this font, we
6616 must try slow function call XLoadQueryFont. */
6617 XFontStruct
*thisinfo
;
6620 thisinfo
= XLoadQueryFont (dpy
,
6621 XSTRING (XCONS (tem
)->car
)->data
);
6627 = (thisinfo
->min_bounds
.width
== 0
6629 : make_number (thisinfo
->max_bounds
.width
));
6630 XFreeFont (dpy
, thisinfo
);
6633 /* For unknown reason, the previous call of XListFont had
6634 retruned a font which can't be opened. Record the size
6635 as 0 not to try to open it again. */
6636 XCONS (tem
)->cdr
= make_number (0);
6639 found_size
= XINT (XCONS (tem
)->cdr
);
6640 if (found_size
== size
)
6641 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
6642 else if (found_size
> 0)
6644 if (NILP (second_best
))
6646 else if (found_size
< size
)
6648 if (XINT (XCONS (second_best
)->cdr
) > size
6649 || XINT (XCONS (second_best
)->cdr
) < found_size
)
6654 if (XINT (XCONS (second_best
)->cdr
) > size
6655 && XINT (XCONS (second_best
)->cdr
) > found_size
)
6660 if (!NILP (newlist
))
6662 else if (!NILP (second_best
))
6664 newlist
= Fcons (XCONS (second_best
)->car
, Qnil
);
6672 /* Load font named FONTNAME of the size SIZE for frame F, and return a
6673 pointer to the structure font_info while allocating it dynamically.
6674 If SIZE is 0, load any size of font.
6675 If loading is failed, return NULL. */
6678 x_load_font (f
, fontname
, size
)
6680 register char *fontname
;
6683 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6684 Lisp_Object font_names
;
6686 /* Get a list of all the fonts that match this name. Once we
6687 have a list of matching fonts, we compare them against the fonts
6688 we already have by comparing names. */
6689 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
6691 if (!NILP (font_names
))
6696 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6697 for (tail
= font_names
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
6698 if (!strcmp (dpyinfo
->font_table
[i
].name
,
6699 XSTRING (XCONS (tail
)->car
)->data
)
6700 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
6701 XSTRING (XCONS (tail
)->car
)->data
))
6702 return (dpyinfo
->font_table
+ i
);
6705 /* Load the font and add it to the table. */
6709 struct font_info
*fontp
;
6710 unsigned long value
;
6712 /* If we have found fonts by x_list_font, load one of them. If
6713 not, we still try to load a font by the name given as FONTNAME
6714 because XListFonts (called in x_list_font) of some X server has
6715 a bug of not finding a font even if the font surely exists and
6716 is loadable by XLoadQueryFont. */
6717 if (size
> 0 && !NILP (font_names
))
6718 fontname
= (char *) XSTRING (XCONS (font_names
)->car
)->data
;
6721 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
6726 /* Do we need to create the table? */
6727 if (dpyinfo
->font_table_size
== 0)
6729 dpyinfo
->font_table_size
= 16;
6731 = (struct font_info
*) xmalloc (dpyinfo
->font_table_size
6732 * sizeof (struct font_info
));
6734 /* Do we need to grow the table? */
6735 else if (dpyinfo
->n_fonts
6736 >= dpyinfo
->font_table_size
)
6738 dpyinfo
->font_table_size
*= 2;
6740 = (struct font_info
*) xrealloc (dpyinfo
->font_table
,
6741 (dpyinfo
->font_table_size
6742 * sizeof (struct font_info
)));
6745 fontp
= dpyinfo
->font_table
+ dpyinfo
->n_fonts
;
6747 /* Now fill in the slots of *FONTP. */
6750 fontp
->font_idx
= dpyinfo
->n_fonts
;
6751 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
6752 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
6754 /* Try to get the full name of FONT. Put it in FULL_NAME. */
6756 if (XGetFontProperty (font
, XA_FONT
, &value
))
6758 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
6762 /* Count the number of dashes in the "full name".
6763 If it is too few, this isn't really the font's full name,
6765 In X11R4, the fonts did not come with their canonical names
6776 full_name
= (char *) xmalloc (p
- name
+ 1);
6777 bcopy (name
, full_name
, p
- name
+ 1);
6784 fontp
->full_name
= full_name
;
6786 fontp
->full_name
= fontp
->name
;
6788 fontp
->size
= font
->max_bounds
.width
;
6789 fontp
->height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
6791 if (NILP (font_names
))
6793 /* We come here because of a bug of XListFonts mentioned at
6794 the head of this block. Let's store this information in
6795 the cache for x_list_fonts. */
6796 Lisp_Object lispy_name
= build_string (fontname
);
6797 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
6799 XCONS (dpyinfo
->name_list_element
)->cdr
6800 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
6801 Fcons (Fcons (lispy_full_name
,
6802 make_number (fontp
->size
)),
6804 XCONS (dpyinfo
->name_list_element
)->cdr
);
6806 XCONS (dpyinfo
->name_list_element
)->cdr
6807 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
6808 Fcons (Fcons (lispy_full_name
,
6809 make_number (fontp
->size
)),
6811 XCONS (dpyinfo
->name_list_element
)->cdr
);
6814 /* The slot `encoding' specifies how to map a character
6815 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
6816 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
6817 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
6818 0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
6819 2:0xA020..0xFF7F). For the moment, we don't know which charset
6820 uses this font. So, we set informatoin in fontp->encoding[1]
6821 which is never used by any charset. If mapping can't be
6822 decided, set FONT_ENCODING_NOT_DECIDED. */
6824 = (font
->max_byte1
== 0
6826 ? (font
->min_char_or_byte2
< 0x80
6827 ? (font
->max_char_or_byte2
< 0x80
6828 ? 0 /* 0x20..0x7F */
6829 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
6830 : 1) /* 0xA0..0xFF */
6832 : (font
->min_byte1
< 0x80
6833 ? (font
->max_byte1
< 0x80
6834 ? (font
->min_char_or_byte2
< 0x80
6835 ? (font
->max_char_or_byte2
< 0x80
6836 ? 0 /* 0x2020..0x7F7F */
6837 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
6838 : 3) /* 0x20A0..0x7FFF */
6839 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
6840 : (font
->min_char_or_byte2
< 0x80
6841 ? (font
->max_char_or_byte2
< 0x80
6842 ? 2 /* 0xA020..0xFF7F */
6843 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
6844 : 1))); /* 0xA0A0..0xFFFF */
6846 fontp
->baseline_offset
6847 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
6848 ? (long) value
: 0);
6849 fontp
->relative_compose
6850 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
6851 ? (long) value
: 0);
6852 fontp
->default_ascent
6853 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
6854 ? (long) value
: 0);
6863 /* Return a pointer to struct font_info of a font named FONTNAME for frame F.
6864 If no such font is loaded, return NULL. */
6866 x_query_font (f
, fontname
)
6868 register char *fontname
;
6870 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6873 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6874 if (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
6875 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
))
6876 return (dpyinfo
->font_table
+ i
);
6880 /* Find a CCL program for a font specified by FONTP, and set the memer
6881 `encoder' of the structure. */
6884 x_find_ccl_program (fontp
)
6885 struct font_info
*fontp
;
6887 extern Lisp_Object Vfont_ccl_encoder_alist
, Vccl_program_table
;
6888 extern Lisp_Object Qccl_program_idx
;
6889 extern Lisp_Object
resolve_symbol_ccl_program ();
6890 Lisp_Object list
, elt
, ccl_prog
, ccl_id
;
6892 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCONS (list
)->cdr
)
6894 elt
= XCONS (list
)->car
;
6896 && STRINGP (XCONS (elt
)->car
)
6897 && (fast_c_string_match_ignore_case (XCONS (elt
)->car
, fontp
->name
)
6900 if (SYMBOLP (XCONS (elt
)->cdr
) &&
6901 (!NILP (ccl_id
= Fget (XCONS (elt
)->cdr
, Qccl_program_idx
))))
6903 ccl_prog
= XVECTOR (Vccl_program_table
)->contents
[XUINT (ccl_id
)];
6904 if (!CONSP (ccl_prog
)) continue;
6905 ccl_prog
= XCONS (ccl_prog
)->cdr
;
6909 ccl_prog
= XCONS (elt
)->cdr
;
6910 if (!VECTORP (ccl_prog
)) continue;
6914 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
6915 setup_ccl_program (fontp
->font_encoder
,
6916 resolve_symbol_ccl_program (ccl_prog
));
6923 /* Initialization. */
6925 #ifdef USE_X_TOOLKIT
6926 static XrmOptionDescRec emacs_options
[] = {
6927 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
6928 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
6930 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
6931 XrmoptionSepArg
, NULL
},
6932 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
6934 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6935 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6936 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6937 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
6938 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
6939 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
6940 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
6942 #endif /* USE_X_TOOLKIT */
6944 static int x_initialized
;
6947 /* Test whether two display-name strings agree up to the dot that separates
6948 the screen number from the server number. */
6950 same_x_server (name1
, name2
)
6951 char *name1
, *name2
;
6954 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
6958 if (seen_colon
&& *name1
== '.')
6962 && (*name1
== '.' || *name1
== '\0')
6963 && (*name2
== '.' || *name2
== '\0'));
6967 #if defined (HAVE_X_I18N) || (defined (USE_X_TOOLKIT) && defined (HAVE_X11XTR6))
6968 /* Recover from setlocale (LC_ALL, ""). */
6972 /* Currently we require strerror to use the "C" locale,
6973 since we don't yet support decoding its string result. */
6975 setlocale (LC_MESSAGES
, "C");
6978 /* The Emacs Lisp reader needs LC_NUMERIC to be "C",
6979 so that numbers are read and printed properly for Emacs Lisp. */
6980 setlocale (LC_NUMERIC
, "C");
6982 /* Currently we require strftime to use the "C" locale,
6983 since we don't yet support encoding its format argument,
6984 or decoding its string result. */
6985 setlocale (LC_TIME
, "C");
6989 struct x_display_info
*
6990 x_term_init (display_name
, xrm_option
, resource_name
)
6991 Lisp_Object display_name
;
6993 char *resource_name
;
6999 struct x_display_info
*dpyinfo
;
7011 setlocale (LC_ALL
, "");
7015 #ifdef USE_X_TOOLKIT
7016 /* weiner@footloose.sps.mot.com reports that this causes
7018 X protocol error: BadAtom (invalid Atom parameter)
7019 on protocol request 18skiloaf.
7020 So let's not use it until R6. */
7022 XtSetLanguageProc (NULL
, NULL
, NULL
);
7033 argv
[argc
++] = "-xrm";
7034 argv
[argc
++] = xrm_option
;
7036 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
7037 resource_name
, EMACS_CLASS
,
7038 emacs_options
, XtNumber (emacs_options
),
7042 /* I think this is to compensate for XtSetLanguageProc. */
7047 #else /* not USE_X_TOOLKIT */
7049 XSetLocaleModifiers ("");
7051 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
7052 #endif /* not USE_X_TOOLKIT */
7054 /* Detect failure. */
7061 /* We have definitely succeeded. Record the new connection. */
7063 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
7067 struct x_display_info
*share
;
7070 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
7071 share
= share
->next
, tail
= XCONS (tail
)->cdr
)
7072 if (same_x_server (XSTRING (XCONS (XCONS (tail
)->car
)->car
)->data
,
7073 XSTRING (display_name
)->data
))
7076 dpyinfo
->kboard
= share
->kboard
;
7079 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
7080 init_kboard (dpyinfo
->kboard
);
7081 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
7083 char *vendor
= ServerVendor (dpy
);
7084 dpyinfo
->kboard
->Vsystem_key_alist
7085 = call1 (Qvendor_specific_keysyms
,
7086 build_string (vendor
? vendor
: ""));
7089 dpyinfo
->kboard
->next_kboard
= all_kboards
;
7090 all_kboards
= dpyinfo
->kboard
;
7091 /* Don't let the initial kboard remain current longer than necessary.
7092 That would cause problems if a file loaded on startup tries to
7093 prompt in the minibuffer. */
7094 if (current_kboard
== initial_kboard
)
7095 current_kboard
= dpyinfo
->kboard
;
7097 dpyinfo
->kboard
->reference_count
++;
7101 /* Put this display on the chain. */
7102 dpyinfo
->next
= x_display_list
;
7103 x_display_list
= dpyinfo
;
7105 /* Put it on x_display_name_list as well, to keep them parallel. */
7106 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
7107 x_display_name_list
);
7108 dpyinfo
->name_list_element
= XCONS (x_display_name_list
)->car
;
7110 dpyinfo
->display
= dpy
;
7113 XSetAfterFunction (x_current_display
, x_trace_wire
);
7117 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
7118 + STRING_BYTES (XSTRING (Vsystem_name
))
7120 sprintf (dpyinfo
->x_id_name
, "%s@%s",
7121 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
7123 /* Figure out which modifier bits mean what. */
7124 x_find_modifier_meanings (dpyinfo
);
7126 /* Get the scroll bar cursor. */
7127 dpyinfo
->vertical_scroll_bar_cursor
7128 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
7130 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
7131 resource_name
, EMACS_CLASS
);
7132 #ifdef HAVE_XRMSETDATABASE
7133 XrmSetDatabase (dpyinfo
->display
, xrdb
);
7135 dpyinfo
->display
->db
= xrdb
;
7137 /* Put the rdb where we can find it in a way that works on
7139 dpyinfo
->xrdb
= xrdb
;
7141 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
7142 DefaultScreen (dpyinfo
->display
));
7143 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
7144 &dpyinfo
->n_planes
);
7145 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
7146 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
7147 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
7148 dpyinfo
->grabbed
= 0;
7149 dpyinfo
->reference_count
= 0;
7150 dpyinfo
->icon_bitmap_id
= -1;
7151 dpyinfo
->n_fonts
= 0;
7152 dpyinfo
->font_table_size
= 0;
7153 dpyinfo
->bitmaps
= 0;
7154 dpyinfo
->bitmaps_size
= 0;
7155 dpyinfo
->bitmaps_last
= 0;
7156 dpyinfo
->scratch_cursor_gc
= 0;
7157 dpyinfo
->mouse_face_mouse_frame
= 0;
7158 dpyinfo
->mouse_face_deferred_gc
= 0;
7159 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7160 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7161 dpyinfo
->mouse_face_face_id
= 0;
7162 dpyinfo
->mouse_face_window
= Qnil
;
7163 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
7164 dpyinfo
->mouse_face_defer
= 0;
7165 dpyinfo
->x_focus_frame
= 0;
7166 dpyinfo
->x_focus_event_frame
= 0;
7167 dpyinfo
->x_highlight_frame
= 0;
7169 dpyinfo
->Xatom_wm_protocols
7170 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
7171 dpyinfo
->Xatom_wm_take_focus
7172 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
7173 dpyinfo
->Xatom_wm_save_yourself
7174 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
7175 dpyinfo
->Xatom_wm_delete_window
7176 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
7177 dpyinfo
->Xatom_wm_change_state
7178 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
7179 dpyinfo
->Xatom_wm_configure_denied
7180 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
7181 dpyinfo
->Xatom_wm_window_moved
7182 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
7183 dpyinfo
->Xatom_editres
7184 = XInternAtom (dpyinfo
->display
, "Editres", False
);
7185 dpyinfo
->Xatom_CLIPBOARD
7186 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
7187 dpyinfo
->Xatom_TIMESTAMP
7188 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
7190 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
7191 dpyinfo
->Xatom_COMPOUND_TEXT
7192 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
7193 dpyinfo
->Xatom_DELETE
7194 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
7195 dpyinfo
->Xatom_MULTIPLE
7196 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
7198 = XInternAtom (dpyinfo
->display
, "INCR", False
);
7199 dpyinfo
->Xatom_EMACS_TMP
7200 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
7201 dpyinfo
->Xatom_TARGETS
7202 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
7204 = XInternAtom (dpyinfo
->display
, "NULL", False
);
7205 dpyinfo
->Xatom_ATOM_PAIR
7206 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
7207 /* For properties of font. */
7208 dpyinfo
->Xatom_PIXEL_SIZE
7209 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
7210 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
7211 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
7212 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
7213 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
7214 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
7215 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
7217 dpyinfo
->cut_buffers_initialized
= 0;
7219 connection
= ConnectionNumber (dpyinfo
->display
);
7220 dpyinfo
->connection
= connection
;
7225 null_bits
[0] = 0x00;
7228 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
7229 null_bits
, 1, 1, (long) 0, (long) 0,
7234 /* This is only needed for distinguishing keyboard and process input. */
7235 if (connection
!= 0)
7236 add_keyboard_wait_descriptor (connection
);
7239 #ifndef F_SETOWN_BUG
7241 #ifdef F_SETOWN_SOCK_NEG
7242 /* stdin is a socket here */
7243 fcntl (connection
, F_SETOWN
, -getpid ());
7244 #else /* ! defined (F_SETOWN_SOCK_NEG) */
7245 fcntl (connection
, F_SETOWN
, getpid ());
7246 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
7247 #endif /* ! defined (F_SETOWN) */
7248 #endif /* F_SETOWN_BUG */
7251 if (interrupt_input
)
7252 init_sigio (connection
);
7253 #endif /* ! defined (SIGIO) */
7256 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
7257 /* Make sure that we have a valid font for dialog boxes
7258 so that Xt does not crash. */
7260 Display
*dpy
= dpyinfo
->display
;
7265 d
.addr
= (XPointer
)&dpy
;
7266 d
.size
= sizeof (Display
*);
7267 fr
.addr
= XtDefaultFont
;
7268 fr
.size
= sizeof (XtDefaultFont
);
7269 to
.size
= sizeof (Font
*);
7270 to
.addr
= (XPointer
)&font
;
7271 count
= x_catch_errors (dpy
);
7272 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
7274 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
7275 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
7276 x_uncatch_errors (dpy
, count
);
7287 /* Get rid of display DPYINFO, assuming all frames are already gone,
7288 and without sending any more commands to the X server. */
7291 x_delete_display (dpyinfo
)
7292 struct x_display_info
*dpyinfo
;
7294 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
7296 /* Discard this display from x_display_name_list and x_display_list.
7297 We can't use Fdelq because that can quit. */
7298 if (! NILP (x_display_name_list
)
7299 && EQ (XCONS (x_display_name_list
)->car
, dpyinfo
->name_list_element
))
7300 x_display_name_list
= XCONS (x_display_name_list
)->cdr
;
7305 tail
= x_display_name_list
;
7306 while (CONSP (tail
) && CONSP (XCONS (tail
)->cdr
))
7308 if (EQ (XCONS (XCONS (tail
)->cdr
)->car
,
7309 dpyinfo
->name_list_element
))
7311 XCONS (tail
)->cdr
= XCONS (XCONS (tail
)->cdr
)->cdr
;
7314 tail
= XCONS (tail
)->cdr
;
7318 if (x_display_list
== dpyinfo
)
7319 x_display_list
= dpyinfo
->next
;
7322 struct x_display_info
*tail
;
7324 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
7325 if (tail
->next
== dpyinfo
)
7326 tail
->next
= tail
->next
->next
;
7329 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
7330 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
7331 XrmDestroyDatabase (dpyinfo
->xrdb
);
7335 if (--dpyinfo
->kboard
->reference_count
== 0)
7336 delete_kboard (dpyinfo
->kboard
);
7338 xfree (dpyinfo
->font_table
);
7339 xfree (dpyinfo
->x_id_name
);
7343 /* Set up use of X before we make the first connection. */
7348 clear_frame_hook
= XTclear_frame
;
7349 clear_end_of_line_hook
= XTclear_end_of_line
;
7350 ins_del_lines_hook
= XTins_del_lines
;
7351 change_line_highlight_hook
= XTchange_line_highlight
;
7352 insert_glyphs_hook
= XTinsert_glyphs
;
7353 write_glyphs_hook
= XTwrite_glyphs
;
7354 delete_glyphs_hook
= XTdelete_glyphs
;
7355 ring_bell_hook
= XTring_bell
;
7356 reset_terminal_modes_hook
= XTreset_terminal_modes
;
7357 set_terminal_modes_hook
= XTset_terminal_modes
;
7358 update_begin_hook
= XTupdate_begin
;
7359 update_end_hook
= XTupdate_end
;
7360 set_terminal_window_hook
= XTset_terminal_window
;
7361 read_socket_hook
= XTread_socket
;
7362 frame_up_to_date_hook
= XTframe_up_to_date
;
7363 cursor_to_hook
= XTcursor_to
;
7364 reassert_line_highlight_hook
= XTreassert_line_highlight
;
7365 mouse_position_hook
= XTmouse_position
;
7366 frame_rehighlight_hook
= XTframe_rehighlight
;
7367 frame_raise_lower_hook
= XTframe_raise_lower
;
7368 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
7369 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
7370 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
7371 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
7373 scroll_region_ok
= 1; /* we'll scroll partial frames */
7374 char_ins_del_ok
= 0; /* just as fast to write the line */
7375 line_ins_del_ok
= 1; /* we'll just blt 'em */
7376 fast_clear_end_of_line
= 1; /* X does this well */
7377 memory_below_frame
= 0; /* we don't remember what scrolls
7383 /* Try to use interrupt input; if we can't, then start polling. */
7384 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
7386 #ifdef USE_X_TOOLKIT
7387 XtToolkitInitialize ();
7388 Xt_app_con
= XtCreateApplicationContext ();
7389 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
7392 /* Note that there is no real way portable across R3/R4 to get the
7393 original error handler. */
7394 XSetErrorHandler (x_error_handler
);
7395 XSetIOErrorHandler (x_io_error_quitter
);
7397 /* Disable Window Change signals; they are handled by X events. */
7399 signal (SIGWINCH
, SIG_DFL
);
7400 #endif /* ! defined (SIGWINCH) */
7402 signal (SIGPIPE
, x_connection_signal
);
7408 staticpro (&x_error_message_string
);
7409 x_error_message_string
= Qnil
;
7411 staticpro (&x_display_name_list
);
7412 x_display_name_list
= Qnil
;
7414 staticpro (&last_mouse_scroll_bar
);
7415 last_mouse_scroll_bar
= Qnil
;
7417 staticpro (&Qvendor_specific_keysyms
);
7418 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
7420 staticpro (&last_mouse_press_frame
);
7421 last_mouse_press_frame
= Qnil
;
7424 #endif /* not HAVE_X_WINDOWS */