]> code.delx.au - gnu-emacs/blob - src/xterm.c
(x_load_font): Get value of fontp->height from
[gnu-emacs] / src / xterm.c
1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 1996 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
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)
9 any later version.
10
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.
15
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. */
20
21 /* Xt features made by Fred Pierresteguy. */
22
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. */
26 #include <signal.h>
27
28 #include <config.h>
29
30 #include <stdio.h>
31
32 /* Need syssignal.h for various externs and definitions that may be required
33 by some configurations for calls to signal later in this source file. */
34 #include "syssignal.h"
35
36 #ifdef HAVE_X_WINDOWS
37
38 #include "lisp.h"
39 #include "blockinput.h"
40
41 /* This may include sys/types.h, and that somehow loses
42 if this is not done before the other system files. */
43 #include "xterm.h"
44 #include <X11/cursorfont.h>
45
46 #ifndef USG
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
49 #ifndef makedev
50 #include <sys/types.h>
51 #endif /* makedev */
52 #endif /* USG */
53
54 #ifdef BSD_SYSTEM
55 #include <sys/ioctl.h>
56 #endif /* ! defined (BSD_SYSTEM) */
57
58 #include "systty.h"
59 #include "systime.h"
60
61 #ifndef INCLUDED_FCNTL
62 #include <fcntl.h>
63 #endif
64 #include <ctype.h>
65 #include <errno.h>
66 #include <setjmp.h>
67 #include <sys/stat.h>
68 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
69 /* #include <sys/param.h> */
70
71 #include "charset.h"
72 #include "ccl.h"
73 #include "fontset.h"
74 #include "frame.h"
75 #include "dispextern.h"
76 #include "termhooks.h"
77 #include "termopts.h"
78 #include "termchar.h"
79 #if 0
80 #include "sink.h"
81 #include "sinkmask.h"
82 #endif /* ! 0 */
83 #include "gnu.h"
84 #include "disptab.h"
85 #include "buffer.h"
86 #include "window.h"
87 #include "keyboard.h"
88 #include "intervals.h"
89
90 #ifdef USE_X_TOOLKIT
91 #include <X11/Shell.h>
92 #endif
93
94 #ifdef USE_X_TOOLKIT
95 extern void free_frame_menubar ();
96 extern FRAME_PTR x_menubar_window_to_frame ();
97 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
98 #define HACK_EDITRES
99 extern void _XEditResCheckMessages ();
100 #endif /* not NO_EDITRES */
101 #endif /* USE_X_TOOLKIT */
102
103 #ifndef USE_X_TOOLKIT
104 #define x_any_window_to_frame x_window_to_frame
105 #define x_top_window_to_frame x_window_to_frame
106 #endif
107
108 #ifdef USE_X_TOOLKIT
109 #include "widget.h"
110 #ifndef XtNinitialState
111 #define XtNinitialState "initialState"
112 #endif
113 #endif
114
115 #ifdef HAVE_SETLOCALE
116 /* So we can do setlocale. */
117 #include <locale.h>
118 #endif
119
120 #ifdef SOLARIS2
121 /* memmove will be defined as a macro in Xfuncs.h unless
122 <string.h> is included beforehand. The declaration for memmove in
123 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
124 #include <string.h>
125 #endif
126
127 #ifndef min
128 #define min(a,b) ((a)<(b) ? (a) : (b))
129 #endif
130 #ifndef max
131 #define max(a,b) ((a)>(b) ? (a) : (b))
132 #endif
133 \f
134 /* This is a chain of structures for all the X displays currently in use. */
135 struct x_display_info *x_display_list;
136
137 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
138 one for each element of x_display_list and in the same order.
139 NAME is the name of the frame.
140 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
141 Lisp_Object x_display_name_list;
142
143 /* Frame being updated by update_frame. This is declared in term.c.
144 This is set by update_begin and looked at by all the
145 XT functions. It is zero while not inside an update.
146 In that case, the XT functions assume that `selected_frame'
147 is the frame to apply to. */
148 extern struct frame *updating_frame;
149
150 extern waiting_for_input;
151
152 /* This is a frame waiting to be autoraised, within XTread_socket. */
153 struct frame *pending_autoraise_frame;
154
155 #ifdef USE_X_TOOLKIT
156 /* The application context for Xt use. */
157 XtAppContext Xt_app_con;
158
159 static String Xt_default_resources[] =
160 {
161 0
162 };
163 #endif
164
165 /* During an update, maximum vpos for ins/del line operations to affect. */
166
167 static int flexlines;
168
169 /* During an update, nonzero if chars output now should be highlighted. */
170
171 static int highlight;
172
173 /* Nominal cursor position -- where to draw output.
174 During an update, these are different from the cursor-box position. */
175
176 static int curs_x;
177 static int curs_y;
178
179 /* Mouse movement.
180
181 Formerly, we used PointerMotionHintMask (in STANDARD_EVENT_MASK)
182 so that we would have to call XQueryPointer after each MotionNotify
183 event to ask for another such event. However, this made mouse tracking
184 slow, and there was a bug that made it eventually stop.
185
186 Simply asking for MotionNotify all the time seems to work better.
187
188 In order to avoid asking for motion events and then throwing most
189 of them away or busy-polling the server for mouse positions, we ask
190 the server for pointer motion hints. This means that we get only
191 one event per group of mouse movements. "Groups" are delimited by
192 other kinds of events (focus changes and button clicks, for
193 example), or by XQueryPointer calls; when one of these happens, we
194 get another MotionNotify event the next time the mouse moves. This
195 is at least as efficient as getting motion events when mouse
196 tracking is on, and I suspect only negligibly worse when tracking
197 is off. */
198
199 /* Where the mouse was last time we reported a mouse event. */
200 static FRAME_PTR last_mouse_frame;
201 static XRectangle last_mouse_glyph;
202
203 static Lisp_Object last_mouse_press_frame;
204
205 /* The scroll bar in which the last X motion event occurred.
206
207 If the last X motion event occurred in a scroll bar, we set this
208 so XTmouse_position can know whether to report a scroll bar motion or
209 an ordinary motion.
210
211 If the last X motion event didn't occur in a scroll bar, we set this
212 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
213 static Lisp_Object last_mouse_scroll_bar;
214
215 /* This is a hack. We would really prefer that XTmouse_position would
216 return the time associated with the position it returns, but there
217 doesn't seem to be any way to wrest the timestamp from the server
218 along with the position query. So, we just keep track of the time
219 of the last movement we received, and return that in hopes that
220 it's somewhat accurate. */
221 static Time last_mouse_movement_time;
222
223 /* Incremented by XTread_socket whenever it really tries to read events. */
224 #ifdef __STDC__
225 static int volatile input_signal_count;
226 #else
227 static int input_signal_count;
228 #endif
229
230 /* Used locally within XTread_socket. */
231 static int x_noop_count;
232
233 /* Initial values of argv and argc. */
234 extern char **initial_argv;
235 extern int initial_argc;
236
237 extern Lisp_Object Vcommand_line_args, Vsystem_name;
238
239 /* Tells if a window manager is present or not. */
240
241 extern Lisp_Object Vx_no_window_manager;
242
243 extern Lisp_Object Qface, Qmouse_face;
244
245 extern int errno;
246
247 /* A mask of extra modifier bits to put into every keyboard char. */
248 extern int extra_keyboard_modifiers;
249
250 static Lisp_Object Qvendor_specific_keysyms;
251
252 extern XrmDatabase x_load_resources ();
253
254 extern Lisp_Object x_icon_type ();
255
256 void x_delete_display ();
257
258 static void redraw_previous_char ();
259 static void redraw_following_char ();
260 static unsigned int x_x_to_emacs_modifiers ();
261
262 static int fast_find_position ();
263 static void note_mouse_highlight ();
264 static void clear_mouse_face ();
265 static void show_mouse_face ();
266 static void do_line_dance ();
267
268 static int XTcursor_to ();
269 static int XTclear_end_of_line ();
270 static int x_io_error_quitter ();
271 int x_catch_errors ();
272 void x_uncatch_errors ();
273 \f
274 #if 0
275 /* This is a function useful for recording debugging information
276 about the sequence of occurrences in this file. */
277
278 struct record
279 {
280 char *locus;
281 int type;
282 };
283
284 struct record event_record[100];
285
286 int event_record_index;
287
288 record_event (locus, type)
289 char *locus;
290 int type;
291 {
292 if (event_record_index == sizeof (event_record) / sizeof (struct record))
293 event_record_index = 0;
294
295 event_record[event_record_index].locus = locus;
296 event_record[event_record_index].type = type;
297 event_record_index++;
298 }
299
300 #endif /* 0 */
301 \f
302 /* Return the struct x_display_info corresponding to DPY. */
303
304 struct x_display_info *
305 x_display_info_for_display (dpy)
306 Display *dpy;
307 {
308 struct x_display_info *dpyinfo;
309
310 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
311 if (dpyinfo->display == dpy)
312 return dpyinfo;
313
314 return 0;
315 }
316 \f
317 /* Starting and ending updates.
318
319 These hooks are called by update_frame at the beginning and end
320 of a frame update. We record in `updating_frame' the identity
321 of the frame being updated, so that the XT... functions do not
322 need to take a frame as argument. Most of the XT... functions
323 should never be called except during an update, the only exceptions
324 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
325
326 static
327 XTupdate_begin (f)
328 struct frame *f;
329 {
330 int mask;
331
332 if (f == 0)
333 abort ();
334
335 flexlines = f->height;
336 highlight = 0;
337
338 BLOCK_INPUT;
339
340 curs_x = FRAME_CURSOR_X (f);
341 curs_y = FRAME_CURSOR_Y (f);
342
343 if (f == FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_frame)
344 {
345 /* Don't do highlighting for mouse motion during the update. */
346 FRAME_X_DISPLAY_INFO (f)->mouse_face_defer = 1;
347
348 /* If the frame needs to be redrawn,
349 simply forget about any prior mouse highlighting. */
350 if (FRAME_GARBAGED_P (f))
351 FRAME_X_DISPLAY_INFO (f)->mouse_face_window = Qnil;
352
353 if (!NILP (FRAME_X_DISPLAY_INFO (f)->mouse_face_window))
354 {
355 int firstline, lastline, i;
356 struct window *w = XWINDOW (FRAME_X_DISPLAY_INFO (f)->mouse_face_window);
357
358 /* Find the first, and the last+1, lines affected by redisplay. */
359 for (firstline = 0; firstline < f->height; firstline++)
360 if (FRAME_DESIRED_GLYPHS (f)->enable[firstline])
361 break;
362
363 lastline = f->height;
364 for (i = f->height - 1; i >= 0; i--)
365 {
366 if (FRAME_DESIRED_GLYPHS (f)->enable[i])
367 break;
368 else
369 lastline = i;
370 }
371
372 /* Can we tell that this update does not affect the window
373 where the mouse highlight is? If so, no need to turn off.
374 Likewise, don't do anything if the frame is garbaged;
375 in that case, the FRAME_CURRENT_GLYPHS that we would use
376 are all wrong, and we will redisplay that line anyway. */
377 if (! (firstline > (XFASTINT (w->top) + window_internal_height (w))
378 || lastline < XFASTINT (w->top)))
379 clear_mouse_face (FRAME_X_DISPLAY_INFO (f));
380 }
381 }
382
383 UNBLOCK_INPUT;
384 }
385
386 static
387 XTupdate_end (f)
388 struct frame *f;
389 {
390 int mask;
391
392 BLOCK_INPUT;
393
394 do_line_dance ();
395 x_display_cursor (f, 1, curs_x, curs_y);
396
397 FRAME_X_DISPLAY_INFO (f)->mouse_face_defer = 0;
398 #if 0
399 /* This fails in the case of having updated only the echo area
400 if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS
401 has no relation to the current contents, and its charstarts
402 have no relation to the contents of the window-buffer.
403 I don't know a clean way to check
404 for that case. window_end_valid isn't set up yet. */
405 if (f == FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_frame)
406 note_mouse_highlight (f, FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_x,
407 FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_y);
408 #endif
409
410 XFlush (FRAME_X_DISPLAY (f));
411 UNBLOCK_INPUT;
412 }
413
414 /* This is called after a redisplay on frame F. */
415
416 static
417 XTframe_up_to_date (f)
418 FRAME_PTR f;
419 {
420 BLOCK_INPUT;
421 if (FRAME_X_DISPLAY_INFO (f)->mouse_face_deferred_gc
422 || f == FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_frame)
423 {
424 note_mouse_highlight (FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_frame,
425 FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_x,
426 FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_y);
427 FRAME_X_DISPLAY_INFO (f)->mouse_face_deferred_gc = 0;
428 }
429 UNBLOCK_INPUT;
430 }
431 \f
432 /* External interface to control of standout mode.
433 Call this when about to modify line at position VPOS
434 and not change whether it is highlighted. */
435
436 XTreassert_line_highlight (new, vpos)
437 int new, vpos;
438 {
439 highlight = new;
440 }
441
442 /* Call this when about to modify line at position VPOS
443 and change whether it is highlighted. */
444
445 static
446 XTchange_line_highlight (new_highlight, vpos, first_unused_hpos)
447 int new_highlight, vpos, first_unused_hpos;
448 {
449 highlight = new_highlight;
450 XTcursor_to (vpos, 0);
451 XTclear_end_of_line (FRAME_WINDOW_WIDTH (updating_frame));
452 }
453
454 /* This is used when starting Emacs and when restarting after suspend.
455 When starting Emacs, no X window is mapped. And nothing must be done
456 to Emacs's own window if it is suspended (though that rarely happens). */
457
458 static
459 XTset_terminal_modes ()
460 {
461 }
462
463 /* This is called when exiting or suspending Emacs.
464 Exiting will make the X-windows go away, and suspending
465 requires no action. */
466
467 static
468 XTreset_terminal_modes ()
469 {
470 /* XTclear_frame (); */
471 }
472 \f
473 /* Set the nominal cursor position of the frame.
474 This is where display update commands will take effect.
475 This does not affect the place where the cursor-box is displayed. */
476
477 static int
478 XTcursor_to (row, col)
479 register int row, col;
480 {
481 int mask;
482 int orow = row;
483
484 curs_x = col;
485 curs_y = row;
486
487 if (updating_frame == 0)
488 {
489 BLOCK_INPUT;
490 x_display_cursor (selected_frame, 1, curs_x, curs_y);
491 XFlush (FRAME_X_DISPLAY (selected_frame));
492 UNBLOCK_INPUT;
493 }
494 }
495 \f
496
497 /* Return a pointer to per char metric information in FONT of a
498 character pointed by B (*XChar2b). */
499
500 #define PER_CHAR_METRIC(font, b) \
501 ((font)->per_char \
502 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
503 + (((font)->min_byte1 || (font)->max_byte1) \
504 ? (((b)->byte1 - (font)->min_byte1) \
505 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
506 : 0)) \
507 : &((font)->max_bounds))
508
509 /* Display a sequence of N glyphs found at GP.
510 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
511 HL is 1 if this text is highlighted, 2 if the cursor is on it,
512 3 if should appear in its mouse-face.
513 JUST_FOREGROUND if 1 means draw only the foreground;
514 don't alter the background.
515
516 CMPCHARP if non NULL is a pointer to the struct cmpchar_info, which
517 means drawing glyphs on the same column. This is set to non NULL
518 only when recursively called within dumpglyphs to draw a composite
519 character specified by CMPCHAR.
520
521 FONT is the default font to use (for glyphs whose font-code is 0).
522
523 Since the display generation code is responsible for calling
524 compute_char_face and compute_glyph_face on everything it puts in
525 the display structure, we can assume that the face code on each
526 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
527 to which we can actually apply intern_face.
528 Call this function with input blocked.
529
530 Return overall pixel width of the drawn glyphs. */
531
532 #if 1
533 /* This is the multi-face code. */
534
535 static int
536 dumpglyphs (f, left, top, gp, n, hl, just_foreground, cmpcharp)
537 struct frame *f;
538 int left, top;
539 register GLYPH *gp; /* Points to first GLYPH. */
540 register int n; /* Number of glyphs to display. */
541 int hl;
542 int just_foreground;
543 struct cmpchar_info *cmpcharp;
544 {
545 /* Holds characters to be displayed. */
546 XChar2b *buf = (XChar2b *) alloca (FRAME_WINDOW_WIDTH (f) * sizeof (*buf));
547 register XChar2b *cp; /* Steps through buf[]. */
548 register int tlen = GLYPH_TABLE_LENGTH;
549 register Lisp_Object *tbase = GLYPH_TABLE_BASE;
550 Window window = FRAME_X_WINDOW (f);
551 int orig_left = left;
552 int gidx = 0;
553 int i;
554
555 while (n > 0)
556 {
557 /* Get the face-code of the next GLYPH. */
558 int cf, len;
559 GLYPH g = *gp;
560 int ch, first_ch, charset;
561 /* HIGHEST and LOWEST are used while drawing a composite
562 character. The meanings are described later. */
563 int highest, lowest;
564
565 GLYPH_FOLLOW_ALIASES (tbase, tlen, g);
566 cf = (cmpcharp ? cmpcharp->face_work : FAST_GLYPH_FACE (g));
567 ch = FAST_GLYPH_CHAR (g);
568 if (gidx == 0) first_ch = ch;
569 charset = CHAR_CHARSET (ch);
570 if (charset == CHARSET_COMPOSITION)
571 {
572 /* We must draw components of the composite character on the
573 same column. */
574 cmpcharp = cmpchar_table[COMPOSITE_CHAR_ID (ch)];
575
576 /* Set the face in the slot for work. */
577 cmpcharp->face_work = cf;
578
579 /* We don't need the return value ... */
580 dumpglyphs (f, left, top, cmpcharp->glyph, cmpcharp->glyph_len,
581 hl, just_foreground, cmpcharp);
582 /* ... because the width of just drawn text can be
583 calculated as follows. */
584 left += FONT_WIDTH (f->output_data.x->font) * cmpcharp->width;
585
586 ++gp, --n;
587 while (gp && (*gp & GLYPH_MASK_PADDING)) ++gp, --n;
588 cmpcharp = NULL;
589 continue;
590 }
591
592 /* Find the run of consecutive glyphs which can be drawn with
593 the same GC (i.e. the same charset and the same face-code).
594 Extract their character codes into BUF.
595 If CMPCHARP is not NULL, face-code is not checked because we
596 use only the face specified in `cmpcharp->face_work'. */
597 cp = buf;
598 while (n > 0)
599 {
600 int this_charset, c1, c2;
601
602 g = *gp;
603 GLYPH_FOLLOW_ALIASES (tbase, tlen, g);
604 ch = FAST_GLYPH_CHAR (g);
605 SPLIT_CHAR (ch, this_charset, c1, c2);
606 if (this_charset != charset
607 || (cmpcharp == NULL && FAST_GLYPH_FACE (g) != cf))
608 break;
609
610 if (c2 > 0)
611 cp->byte1 = c1, cp->byte2 = c2;
612 else
613 cp->byte1 = 0, cp->byte2 = c1;
614 ++cp;
615 ++gp, --n;
616 while (gp && (*gp & GLYPH_MASK_PADDING))
617 ++gp, --n;
618 }
619
620 /* LEN gets the length of the run. */
621 len = cp - buf;
622 /* Now output this run of chars, with the font and pixel values
623 determined by the face code CF. */
624 {
625 struct face *face = FRAME_DEFAULT_FACE (f);
626 XFontStruct *font = NULL;
627 GC gc;
628 int stippled = 0;
629 int line_height = f->output_data.x->line_height;
630 /* Pixel width of each glyph in this run. */
631 int glyph_width
632 = (FONT_WIDTH (f->output_data.x->font)
633 * (cmpcharp ? cmpcharp->width : CHARSET_WIDTH (charset)));
634 /* Overall pixel width of this run. */
635 int run_width
636 = (FONT_WIDTH (f->output_data.x->font)
637 * (cmpcharp ? cmpcharp->width : len * CHARSET_WIDTH (charset)));
638 /* A flag to tell if we have already filled background. We
639 fill background in advance in the following cases:
640 1) A face has stipple.
641 2) A height of font is shorter than LINE_HEIGHT.
642 3) Drawing a composite character.
643 4) Font has non-zero _MULE_BASELINE_OFFSET property.
644 After filling background, we draw glyphs by XDrawString16. */
645 int background_filled;
646 /* Baseline position of a character, offset from TOP. */
647 int baseline;
648 /* The property value of `_MULE_RELATIVE_COMPOSE' and
649 `_MULE_DEFAULT_ASCENT'. */
650 int relative_compose = 0, default_ascent = 0;
651 /* 1 if we find no font or a font of inappropriate size. */
652 int require_clipping;
653
654 /* HL = 3 means use a mouse face previously chosen. */
655 if (hl == 3)
656 cf = FRAME_X_DISPLAY_INFO (f)->mouse_face_face_id;
657
658 /* First look at the face of the text itself. */
659 if (cf != 0)
660 {
661 /* It's possible for the display table to specify
662 a face code that is out of range. Use 0 in that case. */
663 if (cf < 0 || cf >= FRAME_N_COMPUTED_FACES (f)
664 || FRAME_COMPUTED_FACES (f) [cf] == 0)
665 cf = 0;
666
667 if (cf == 1)
668 face = FRAME_MODE_LINE_FACE (f);
669 else
670 face = intern_face (f, FRAME_COMPUTED_FACES (f) [cf]);
671 if (FACE_STIPPLE (face))
672 stippled = 1;
673 }
674
675 /* Then comes the distinction between modeline and normal text. */
676 else if (hl == 0)
677 ;
678 else if (hl == 1)
679 {
680 face = FRAME_MODE_LINE_FACE (f);
681 if (FACE_STIPPLE (face))
682 stippled = 1;
683 }
684
685 #define FACE_DEFAULT (~0)
686
687 /* Setting appropriate font and gc for this charset. */
688 if (charset != CHARSET_ASCII)
689 {
690 int font_id;
691 int fontset = FACE_FONTSET (face);
692 struct font_info *fontp;
693
694 if ((fontset < 0 && (fontset = FRAME_FONTSET (f)) < 0)
695 || !(fontp = FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f),
696 charset, NULL, fontset)))
697 goto font_not_found;
698
699 font = (XFontStruct *) (fontp->font);
700 gc = FACE_NON_ASCII_GC (face);
701 XSetFont (FRAME_X_DISPLAY (f), gc, font->fid);
702 baseline
703 = (font->max_byte1 != 0
704 ? (line_height + font->ascent - font->descent) / 2
705 : f->output_data.x->font_baseline - fontp->baseline_offset);
706 if (FONT_HEIGHT (font) <= line_height
707 && (font->ascent > baseline
708 || font->descent > line_height - baseline))
709 /* Adjust baseline for this font to show the whole
710 glyphs in a line. */
711 baseline = line_height - font->descent;
712
713 if (cmpcharp && cmpcharp->cmp_rule == NULL)
714 {
715 relative_compose = fontp->relative_compose;
716 default_ascent = fontp->default_ascent;
717 }
718
719 /* We have to change code points in the following cases. */
720 if (fontp->font_encoder)
721 {
722 /* This font requires CCL program to calculate code
723 point of characters. */
724 struct ccl_program *ccl = fontp->font_encoder;
725
726 if (CHARSET_DIMENSION (charset) == 1)
727 for (cp = buf; cp < buf + len; cp++)
728 {
729 ccl->reg[0] = charset;
730 ccl->reg[1] = cp->byte2;
731 ccl_driver (ccl, NULL, NULL, 0, 0, NULL);
732 cp->byte2 = ccl->reg[1];
733 }
734 else
735 for (cp = buf; cp < buf + len; cp++)
736 {
737 ccl->reg[0] = charset;
738 ccl->reg[1] = cp->byte1, ccl->reg[2] = cp->byte2;
739 ccl_driver (ccl, NULL, NULL, 0, 0, NULL);
740 cp->byte1 = ccl->reg[1], cp->byte2 = ccl->reg[2];
741 }
742 }
743 else if (fontp->encoding[charset])
744 {
745 int enc = fontp->encoding[charset];
746
747 if ((enc == 1 || enc == 2) && CHARSET_DIMENSION (charset) == 2)
748 for (cp = buf; cp < buf + len; cp++)
749 cp->byte1 |= 0x80;
750 if (enc == 1 || enc == 3)
751 for (cp = buf; cp < buf + len; cp++)
752 cp->byte2 |= 0x80;
753 }
754 }
755 else
756 {
757 font_not_found:
758 if (charset == CHARSET_ASCII || charset == charset_latin_iso8859_1)
759 {
760 font = FACE_FONT (face);
761 if (font == (XFontStruct *) FACE_DEFAULT)
762 font = f->output_data.x->font;
763 baseline = FONT_BASE (f->output_data.x->font);
764 if (charset == charset_latin_iso8859_1)
765 {
766 if (font->max_char_or_byte2 < 0x80)
767 /* This font can't display Latin1 characters. */
768 font = NULL;
769 else
770 {
771 for (cp = buf; cp < buf + len; cp++)
772 cp->byte2 |= 0x80;
773 }
774 }
775 }
776 gc = FACE_GC (face);
777 }
778
779 /* Now override that if the cursor's on this character. */
780 if (hl == 2)
781 {
782 /* The cursor overrides stippling. */
783 stippled = 0;
784
785 if (font == f->output_data.x->font
786 && face->background == f->output_data.x->background_pixel
787 && face->foreground == f->output_data.x->foreground_pixel
788 && !cmpcharp)
789 {
790 gc = f->output_data.x->cursor_gc;
791 }
792 /* Cursor on non-default face: must merge. */
793 else
794 {
795 XGCValues xgcv;
796 unsigned long mask;
797
798 xgcv.background = f->output_data.x->cursor_pixel;
799 xgcv.foreground = face->background;
800 /* If the glyph would be invisible,
801 try a different foreground. */
802 if (xgcv.foreground == xgcv.background)
803 xgcv.foreground = face->foreground;
804 if (xgcv.foreground == xgcv.background)
805 xgcv.foreground = f->output_data.x->cursor_foreground_pixel;
806 if (xgcv.foreground == xgcv.background)
807 xgcv.foreground = face->foreground;
808 /* Make sure the cursor is distinct from text in this face. */
809 if (xgcv.background == face->background
810 && xgcv.foreground == face->foreground)
811 {
812 xgcv.background = face->foreground;
813 xgcv.foreground = face->background;
814 }
815 if (font)
816 xgcv.font = font->fid;
817 else
818 xgcv.font = FACE_FONT (face)->fid;
819 xgcv.graphics_exposures = 0;
820 mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures;
821 if (FRAME_X_DISPLAY_INFO (f)->scratch_cursor_gc)
822 XChangeGC (FRAME_X_DISPLAY (f),
823 FRAME_X_DISPLAY_INFO (f)->scratch_cursor_gc,
824 mask, &xgcv);
825 else
826 FRAME_X_DISPLAY_INFO (f)->scratch_cursor_gc
827 = XCreateGC (FRAME_X_DISPLAY (f), window, mask, &xgcv);
828 gc = FRAME_X_DISPLAY_INFO (f)->scratch_cursor_gc;
829 #if 0
830 /* If this code is restored, it must also reset to the default stipple
831 if necessary. */
832 if (face->stipple && face->stipple != FACE_DEFAULT)
833 XSetStipple (FRAME_X_DISPLAY (f), gc, face->stipple);
834 #endif
835 }
836 }
837
838 if (font)
839 require_clipping = (!NILP (Vclip_large_size_font)
840 && (font->ascent > baseline
841 || font->descent > line_height - baseline
842 || (!cmpcharp
843 && FONT_WIDTH (font) > glyph_width)));
844
845 if (font && (just_foreground || (cmpcharp && gidx > 0)))
846 background_filled = 1;
847 else if (stippled)
848 {
849 /* Turn stipple on. */
850 XSetFillStyle (FRAME_X_DISPLAY (f), gc, FillOpaqueStippled);
851
852 /* Draw stipple or background color on background. */
853 XFillRectangle (FRAME_X_DISPLAY (f), window, gc,
854 left, top, run_width, line_height);
855
856 /* Turn stipple off. */
857 XSetFillStyle (FRAME_X_DISPLAY (f), gc, FillSolid);
858
859 background_filled = 1;
860 }
861 else if (!font
862 || FONT_HEIGHT (font) < line_height
863 || FONT_WIDTH (font) < glyph_width
864 || cmpcharp)
865 {
866 /* Fill a area for the current run in background pixle of GC. */
867 XGCValues xgcv;
868 unsigned long mask = GCForeground | GCBackground | GCFillStyle;
869
870 /* The current code at first set foreground to background,
871 fill the area, then recover the original foreground.
872 Aren't there any smarter ways? */
873
874 XGetGCValues (FRAME_X_DISPLAY (f), gc, mask, &xgcv);
875 XSetForeground (FRAME_X_DISPLAY (f), gc, xgcv.background);
876 XSetFillStyle (FRAME_X_DISPLAY (f), gc, FillSolid);
877 XFillRectangle (FRAME_X_DISPLAY (f), window, gc,
878 left, top, run_width, line_height);
879 XSetForeground (FRAME_X_DISPLAY (f), gc, xgcv.foreground);
880
881 background_filled = 1;
882 if (cmpcharp)
883 /* To assure not to fill background while drawing
884 remaining components. */
885 just_foreground = 1;
886 }
887 else
888 background_filled = 0;
889
890 if (font)
891 {
892 if (require_clipping)
893 {
894 Region region; /* Region used for setting clip mask to GC. */
895 XPoint x[4]; /* Data used for creating REGION. */
896
897 x[0].x = x[3].x = left, x[1].x = x[2].x = left + glyph_width;
898 x[0].y = x[1].y = top, x[2].y = x[3].y = top + line_height;
899 region = XPolygonRegion (x, 4, EvenOddRule);
900 XSetRegion (FRAME_X_DISPLAY (f), gc, region);
901 XDestroyRegion (region);
902 }
903
904 if (!cmpcharp)
905 {
906 if (require_clipping || FONT_WIDTH (font) != glyph_width)
907 for (i = 0; i < len; i++)
908 {
909 if (require_clipping && i > 0)
910 XSetClipOrigin (FRAME_X_DISPLAY (f), gc,
911 glyph_width * i, 0);
912 if (background_filled)
913 XDrawString16 (FRAME_X_DISPLAY (f), window, gc,
914 left + glyph_width * i,
915 top + baseline, buf + i, 1);
916 else
917 XDrawImageString16 (FRAME_X_DISPLAY (f), window, gc,
918 left + glyph_width * i,
919 top + baseline, buf + i, 1);
920 }
921 else
922 {
923 if (background_filled)
924 XDrawString16 (FRAME_X_DISPLAY (f), window, gc,
925 left, top + baseline, buf, len);
926 else
927 XDrawImageString16 (FRAME_X_DISPLAY (f), window, gc,
928 left, top + baseline, buf, len);
929 }
930 }
931 else
932 {
933 XCharStruct *pcm; /* Pointer to per char metric info. */
934
935 if ((cmpcharp->cmp_rule || relative_compose)
936 && gidx == 0)
937 {
938 /* This is the first character. Initialize variables.
939 HIGHEST is the highest position of glyphs ever
940 written, LOWEST the lowest position. */
941 int x_offset = 0;
942
943 if (default_ascent
944 && CHAR_TABLE_P (Vuse_default_ascent)
945 && !NILP (Faref (Vuse_default_ascent, first_ch)))
946 {
947 highest = default_ascent;
948 lowest = 0;
949 }
950 else
951 {
952 pcm = PER_CHAR_METRIC (font, buf);
953 highest = pcm->ascent + 1;
954 lowest = - pcm->descent;
955 }
956
957 if (cmpcharp->cmp_rule)
958 x_offset = (cmpcharp->col_offset[0]
959 * FONT_WIDTH (f->output_data.x->font));
960 /* Draw the first character at the normal position. */
961 XDrawString16 (FRAME_X_DISPLAY (f), window, gc,
962 left + x_offset, top + baseline, buf, 1);
963 i = 1;
964 gidx++;
965 }
966 else
967 i = 0;
968
969 for (; i < len; i++, gidx++)
970 {
971 int x_offset = 0, y_offset = 0;
972
973 if (relative_compose)
974 {
975 pcm = PER_CHAR_METRIC (font, buf + i);
976 if (- pcm->descent >= relative_compose)
977 {
978 /* Draw above the current glyphs. */
979 y_offset = highest + pcm->descent;
980 highest += pcm->ascent + pcm->descent;
981 }
982 else if (pcm->ascent <= 0)
983 {
984 /* Draw beneath the current glyphs. */
985 y_offset = lowest - pcm->ascent;
986 lowest -= pcm->ascent + pcm->descent;
987 }
988 }
989 else if (cmpcharp->cmp_rule)
990 {
991 int gref = (cmpcharp->cmp_rule[gidx] - 0xA0) / 9;
992 int nref = (cmpcharp->cmp_rule[gidx] - 0xA0) % 9;
993 int bottom, top;
994
995 /* Re-encode GREF and NREF so that they specify
996 only Y-axis information:
997 0:top, 1:base, 2:bottom, 3:center */
998 gref = gref / 3 + (gref == 4) * 2;
999 nref = nref / 3 + (nref == 4) * 2;
1000
1001 pcm = PER_CHAR_METRIC (font, buf + i);
1002 bottom = ((gref == 0 ? highest : gref == 1 ? 0
1003 : gref == 2 ? lowest
1004 : (highest + lowest) / 2)
1005 - (nref == 0 ? pcm->ascent + pcm->descent
1006 : nref == 1 ? pcm->descent : nref == 2 ? 0
1007 : (pcm->ascent + pcm->descent) / 2));
1008 top = bottom + (pcm->ascent + pcm->descent);
1009 if (top > highest)
1010 highest = top;
1011 if (bottom < lowest)
1012 lowest = bottom;
1013 y_offset = bottom + pcm->descent;
1014 x_offset = (cmpcharp->col_offset[gidx]
1015 * FONT_WIDTH (f->output_data.x->font));
1016 }
1017 XDrawString16 (FRAME_X_DISPLAY (f), window, gc,
1018 left + x_offset, top + baseline - y_offset,
1019 buf + i, 1);
1020 }
1021 }
1022 if (require_clipping)
1023 XSetClipMask (FRAME_X_DISPLAY (f), gc, None);
1024
1025 #if 0 /* Doesn't work, because it uses FRAME_CURRENT_GLYPHS,
1026 which often is not up to date yet. */
1027 if (!just_foreground)
1028 {
1029 if (left == orig_left)
1030 redraw_previous_char (f, PIXEL_TO_CHAR_COL (f, left),
1031 PIXEL_TO_CHAR_ROW (f, top), hl == 1);
1032 if (n == 0)
1033 redraw_following_char (f, PIXEL_TO_CHAR_COL (f, left + len * FONT_WIDTH (font)),
1034 PIXEL_TO_CHAR_ROW (f, top), hl == 1);
1035 }
1036 #endif
1037 }
1038 if (!font)
1039 {
1040 /* Show rectangles to indicate that we found no font. */
1041 int limit = cmpcharp ? 1 : len;
1042
1043 for (i = 0; i < limit; i++)
1044 XDrawRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1045 left + glyph_width * i, top,
1046 glyph_width - 1, line_height - 1);
1047 }
1048 else if (require_clipping && !NILP (Vhighlight_wrong_size_font))
1049 {
1050 /* Show ??? to indicate that we found a font of
1051 inappropriate size. */
1052 int limit = cmpcharp ? 1 : len;
1053
1054 for (i = 0; i < limit; i++)
1055 {
1056 XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1057 left + glyph_width * i, top + line_height - 1,
1058 left + glyph_width * i + 1, top + line_height - 1);
1059 XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1060 left + glyph_width * i, top + line_height - 3,
1061 left + glyph_width * i, top + line_height - 1);
1062 }
1063 }
1064
1065 /* We should probably check for XA_UNDERLINE_POSITION and
1066 XA_UNDERLINE_THICKNESS properties on the font, but let's
1067 just get the thing working, and come back to that. */
1068 {
1069 /* Setting underline position based on the metric of the
1070 current font results in shaky underline if it strides
1071 over different fonts. So, we set the position based only
1072 on the default font of this frame. */
1073 int underline_position = f->output_data.x->font_baseline + 1;
1074
1075 if (underline_position >= line_height)
1076 underline_position = line_height - 1;
1077
1078 if (face->underline)
1079 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1080 FACE_GC (face),
1081 left, top + underline_position, run_width, 1);
1082 }
1083
1084 if (!cmpcharp)
1085 left += run_width;
1086 }
1087 }
1088
1089 return (left - orig_left);
1090 }
1091 #endif /* 1 */
1092
1093 #if 0
1094 /* This is the old single-face code. */
1095
1096 static void
1097 dumpglyphs (f, left, top, gp, n, hl, font)
1098 struct frame *f;
1099 int left, top;
1100 register GLYPH *gp; /* Points to first GLYPH. */
1101 register int n; /* Number of glyphs to display. */
1102 int hl;
1103 XFontStruct *font;
1104 {
1105 register int len;
1106 Window window = FRAME_X_WINDOW (f);
1107 GC drawing_gc = (hl == 2 ? f->output_data.x->cursor_gc
1108 : (hl ? f->output_data.x->reverse_gc
1109 : f->output_data.x->normal_gc));
1110
1111 if (sizeof (GLYPH) == sizeof (XChar2b))
1112 XDrawImageString16 (FRAME_X_DISPLAY (f), window, drawing_gc,
1113 left, top + FONT_BASE (font), (XChar2b *) gp, n);
1114 else if (sizeof (GLYPH) == sizeof (unsigned char))
1115 XDrawImageString (FRAME_X_DISPLAY (f), window, drawing_gc,
1116 left, top + FONT_BASE (font), (char *) gp, n);
1117 else
1118 /* What size of glyph ARE you using? And does X have a function to
1119 draw them? */
1120 abort ();
1121 }
1122 #endif
1123 \f
1124 /* Output some text at the nominal frame cursor position.
1125 Advance the cursor over the text.
1126 Output LEN glyphs at START.
1127
1128 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
1129 controls the pixel values used for foreground and background. */
1130
1131 static
1132 XTwrite_glyphs (start, len)
1133 register GLYPH *start;
1134 int len;
1135 {
1136 register int temp_length;
1137 int mask;
1138 struct frame *f;
1139
1140 BLOCK_INPUT;
1141
1142 do_line_dance ();
1143 f = updating_frame;
1144 if (f == 0)
1145 {
1146 f = selected_frame;
1147 /* If not within an update,
1148 output at the frame's visible cursor. */
1149 curs_x = f->cursor_x;
1150 curs_y = f->cursor_y;
1151 }
1152
1153 dumpglyphs (f,
1154 CHAR_TO_PIXEL_COL (f, curs_x),
1155 CHAR_TO_PIXEL_ROW (f, curs_y),
1156 start, len, highlight, 0, NULL);
1157
1158 /* If we drew on top of the cursor, note that it is turned off. */
1159 if (curs_y == f->phys_cursor_y
1160 && curs_x <= f->phys_cursor_x
1161 && curs_x + len > f->phys_cursor_x)
1162 f->phys_cursor_on = 0;
1163
1164 if (updating_frame == 0)
1165 x_display_cursor (f, 1, FRAME_CURSOR_X (f) + len, FRAME_CURSOR_Y (f));
1166 else
1167 curs_x += len;
1168
1169 UNBLOCK_INPUT;
1170 }
1171 \f
1172 /* Clear to the end of the line.
1173 Erase the current text line from the nominal cursor position (inclusive)
1174 to column FIRST_UNUSED (exclusive). The idea is that everything
1175 from FIRST_UNUSED onward is already erased. */
1176
1177 static
1178 XTclear_end_of_line (first_unused)
1179 register int first_unused;
1180 {
1181 struct frame *f = updating_frame;
1182 int mask;
1183
1184 if (f == 0)
1185 abort ();
1186
1187 if (curs_y < 0 || curs_y >= f->height)
1188 return;
1189 if (first_unused <= 0)
1190 return;
1191
1192 if (first_unused >= FRAME_WINDOW_WIDTH (f))
1193 first_unused = FRAME_WINDOW_WIDTH (f);
1194
1195 first_unused += FRAME_LEFT_SCROLL_BAR_WIDTH (f);
1196
1197 BLOCK_INPUT;
1198
1199 do_line_dance ();
1200
1201 /* Notice if the cursor will be cleared by this operation. */
1202 if (curs_y == f->phys_cursor_y
1203 && curs_x <= f->phys_cursor_x
1204 && f->phys_cursor_x < first_unused)
1205 f->phys_cursor_on = 0;
1206
1207 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1208 CHAR_TO_PIXEL_COL (f, curs_x),
1209 CHAR_TO_PIXEL_ROW (f, curs_y),
1210 FONT_WIDTH (f->output_data.x->font) * (first_unused - curs_x),
1211 f->output_data.x->line_height, False);
1212 #if 0
1213 redraw_previous_char (f, curs_x, curs_y, highlight);
1214 #endif
1215
1216 UNBLOCK_INPUT;
1217 }
1218
1219 static
1220 XTclear_frame ()
1221 {
1222 int mask;
1223 struct frame *f = updating_frame;
1224
1225 if (f == 0)
1226 f = selected_frame;
1227
1228 f->phys_cursor_on = 0; /* Cursor not visible. */
1229 curs_x = 0; /* Nominal cursor position is top left. */
1230 curs_y = 0;
1231
1232 BLOCK_INPUT;
1233
1234 XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
1235
1236 /* We have to clear the scroll bars, too. If we have changed
1237 colors or something like that, then they should be notified. */
1238 x_scroll_bar_clear (f);
1239
1240 XFlush (FRAME_X_DISPLAY (f));
1241 UNBLOCK_INPUT;
1242 }
1243 \f
1244 #if 0
1245 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
1246 always contain the right glyphs to use.
1247
1248 It also needs to be changed to look at the details of the font and
1249 see whether there is really overlap, and do nothing when there is
1250 not. This can use font_char_overlap_left and font_char_overlap_right,
1251 but just how to use them is not clear. */
1252
1253 /* Erase the character (if any) at the position just before X, Y in frame F,
1254 then redraw it and the character before it.
1255 This is necessary when we erase starting at X,
1256 in case the character after X overlaps into the one before X.
1257 Call this function with input blocked. */
1258
1259 static void
1260 redraw_previous_char (f, x, y, highlight_flag)
1261 FRAME_PTR f;
1262 int x, y;
1263 int highlight_flag;
1264 {
1265 /* Erase the character before the new ones, in case
1266 what was here before overlaps it.
1267 Reoutput that character, and the previous character
1268 (in case the previous character overlaps it). */
1269 if (x > 0)
1270 {
1271 int start_x = x - 2;
1272 if (start_x < 0)
1273 start_x = 0;
1274 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1275 CHAR_TO_PIXEL_COL (f, x - 1),
1276 CHAR_TO_PIXEL_ROW (f, y),
1277 FONT_WIDTH (f->output_data.x->font),
1278 f->output_data.x->line_height, False);
1279
1280 dumpglyphs (f, CHAR_TO_PIXEL_COL (f, start_x),
1281 CHAR_TO_PIXEL_ROW (f, y),
1282 &FRAME_CURRENT_GLYPHS (f)->glyphs[y][start_x],
1283 x - start_x, highlight_flag, 1, NULL);
1284 }
1285 }
1286
1287 /* Erase the character (if any) at the position X, Y in frame F,
1288 then redraw it and the character after it.
1289 This is necessary when we erase endng at X,
1290 in case the character after X overlaps into the one before X.
1291 Call this function with input blocked. */
1292
1293 static void
1294 redraw_following_char (f, x, y, highlight_flag)
1295 FRAME_PTR f;
1296 int x, y;
1297 int highlight_flag;
1298 {
1299 int limit = FRAME_CURRENT_GLYPHS (f)->used[y];
1300 /* Erase the character after the new ones, in case
1301 what was here before overlaps it.
1302 Reoutput that character, and the following character
1303 (in case the following character overlaps it). */
1304 if (x < limit
1305 && FRAME_CURRENT_GLYPHS (f)->glyphs[y][x] != SPACEGLYPH)
1306 {
1307 int end_x = x + 2;
1308 if (end_x > limit)
1309 end_x = limit;
1310 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1311 CHAR_TO_PIXEL_COL (f, x),
1312 CHAR_TO_PIXEL_ROW (f, y),
1313 FONT_WIDTH (f->output_data.x->font),
1314 f->output_data.x->line_height, False);
1315
1316 dumpglyphs (f, CHAR_TO_PIXEL_COL (f, x),
1317 CHAR_TO_PIXEL_ROW (f, y),
1318 &FRAME_CURRENT_GLYPHS (f)->glyphs[y][x],
1319 end_x - x, highlight_flag, 1, NULL);
1320 }
1321 }
1322 #endif /* 0 */
1323 \f
1324 #if 0 /* Not in use yet */
1325
1326 /* Return 1 if character C in font F extends past its left edge. */
1327
1328 static int
1329 font_char_overlap_left (font, c)
1330 XFontStruct *font;
1331 int c;
1332 {
1333 XCharStruct *s;
1334
1335 /* Find the bounding-box info for C. */
1336 if (font->per_char == 0)
1337 s = &font->max_bounds;
1338 else
1339 {
1340 int rowlen = font->max_char_or_byte2 - font->min_char_or_byte2 + 1;
1341 int row, within;
1342
1343 /* Decode char into row number (byte 1) and code within row (byte 2). */
1344 row = c >> 8;
1345 within = c & 0177;
1346 if (!(within >= font->min_char_or_byte2
1347 && within <= font->max_char_or_byte2
1348 && row >= font->min_byte1
1349 && row <= font->max_byte1))
1350 {
1351 /* If char is out of range, try the font's default char instead. */
1352 c = font->default_char;
1353 row = c >> (BITS_PER_INT - 8);
1354 within = c & 0177;
1355 }
1356 if (!(within >= font->min_char_or_byte2
1357 && within <= font->max_char_or_byte2
1358 && row >= font->min_byte1
1359 && row <= font->max_byte1))
1360 /* Still out of range means this char does not overlap. */
1361 return 0;
1362 else
1363 /* We found the info for this char. */
1364 s = (font->per_char + (within - font->min_char_or_byte2)
1365 + row * rowlen);
1366 }
1367
1368 return (s && s->lbearing < 0);
1369 }
1370
1371 /* Return 1 if character C in font F extends past its right edge. */
1372
1373 static int
1374 font_char_overlap_right (font, c)
1375 XFontStruct *font;
1376 int c;
1377 {
1378 XCharStruct *s;
1379
1380 /* Find the bounding-box info for C. */
1381 if (font->per_char == 0)
1382 s = &font->max_bounds;
1383 else
1384 {
1385 int rowlen = font->max_char_or_byte2 - font->min_char_or_byte2 + 1;
1386 int row, within;
1387
1388 /* Decode char into row number (byte 1) and code within row (byte 2). */
1389 row = c >> 8;
1390 within = c & 0177;
1391 if (!(within >= font->min_char_or_byte2
1392 && within <= font->max_char_or_byte2
1393 && row >= font->min_byte1
1394 && row <= font->max_byte1))
1395 {
1396 /* If char is out of range, try the font's default char instead. */
1397 c = font->default_char;
1398 row = c >> (BITS_PER_INT - 8);
1399 within = c & 0177;
1400 }
1401 if (!(within >= font->min_char_or_byte2
1402 && within <= font->max_char_or_byte2
1403 && row >= font->min_byte1
1404 && row <= font->max_byte1))
1405 /* Still out of range means this char does not overlap. */
1406 return 0;
1407 else
1408 /* We found the info for this char. */
1409 s = (font->per_char + (within - font->min_char_or_byte2)
1410 + row * rowlen);
1411 }
1412
1413 return (s && s->rbearing >= s->width);
1414 }
1415 #endif /* 0 */
1416 \f
1417 /* Invert the middle quarter of the frame for .15 sec. */
1418
1419 /* We use the select system call to do the waiting, so we have to make sure
1420 it's available. If it isn't, we just won't do visual bells. */
1421 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1422
1423 /* Subtract the `struct timeval' values X and Y,
1424 storing the result in RESULT.
1425 Return 1 if the difference is negative, otherwise 0. */
1426
1427 static int
1428 timeval_subtract (result, x, y)
1429 struct timeval *result, x, y;
1430 {
1431 /* Perform the carry for the later subtraction by updating y.
1432 This is safer because on some systems
1433 the tv_sec member is unsigned. */
1434 if (x.tv_usec < y.tv_usec)
1435 {
1436 int nsec = (y.tv_usec - x.tv_usec) / 1000000 + 1;
1437 y.tv_usec -= 1000000 * nsec;
1438 y.tv_sec += nsec;
1439 }
1440 if (x.tv_usec - y.tv_usec > 1000000)
1441 {
1442 int nsec = (y.tv_usec - x.tv_usec) / 1000000;
1443 y.tv_usec += 1000000 * nsec;
1444 y.tv_sec -= nsec;
1445 }
1446
1447 /* Compute the time remaining to wait. tv_usec is certainly positive. */
1448 result->tv_sec = x.tv_sec - y.tv_sec;
1449 result->tv_usec = x.tv_usec - y.tv_usec;
1450
1451 /* Return indication of whether the result should be considered negative. */
1452 return x.tv_sec < y.tv_sec;
1453 }
1454
1455 XTflash (f)
1456 struct frame *f;
1457 {
1458 BLOCK_INPUT;
1459
1460 {
1461 GC gc;
1462
1463 /* Create a GC that will use the GXxor function to flip foreground pixels
1464 into background pixels. */
1465 {
1466 XGCValues values;
1467
1468 values.function = GXxor;
1469 values.foreground = (f->output_data.x->foreground_pixel
1470 ^ f->output_data.x->background_pixel);
1471
1472 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1473 GCFunction | GCForeground, &values);
1474 }
1475
1476 {
1477 /* Get the height not including a menu bar widget. */
1478 int height = CHAR_TO_PIXEL_HEIGHT (f, FRAME_HEIGHT (f));
1479 /* Height of each line to flash. */
1480 int flash_height = FRAME_LINE_HEIGHT (f);
1481 /* These will be the left and right margins of the rectangles. */
1482 int flash_left = FRAME_INTERNAL_BORDER_WIDTH (f);
1483 int flash_right = PIXEL_WIDTH (f) - FRAME_INTERNAL_BORDER_WIDTH (f);
1484
1485 int width;
1486
1487 /* Don't flash the area between a scroll bar and the frame
1488 edge it is next to. */
1489 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f))
1490 {
1491 case vertical_scroll_bar_left:
1492 flash_left += VERTICAL_SCROLL_BAR_WIDTH_TRIM;
1493 break;
1494
1495 case vertical_scroll_bar_right:
1496 flash_right -= VERTICAL_SCROLL_BAR_WIDTH_TRIM;
1497 break;
1498 }
1499
1500 width = flash_right - flash_left;
1501
1502 /* If window is tall, flash top and bottom line. */
1503 if (height > 3 * FRAME_LINE_HEIGHT (f))
1504 {
1505 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1506 flash_left, FRAME_INTERNAL_BORDER_WIDTH (f),
1507 width, flash_height);
1508 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1509 flash_left,
1510 (height - flash_height
1511 - FRAME_INTERNAL_BORDER_WIDTH (f)),
1512 width, flash_height);
1513 }
1514 else
1515 /* If it is short, flash it all. */
1516 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1517 flash_left, FRAME_INTERNAL_BORDER_WIDTH (f),
1518 width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
1519
1520 XFlush (FRAME_X_DISPLAY (f));
1521
1522 {
1523 struct timeval wakeup, now;
1524
1525 EMACS_GET_TIME (wakeup);
1526
1527 /* Compute time to wait until, propagating carry from usecs. */
1528 wakeup.tv_usec += 150000;
1529 wakeup.tv_sec += (wakeup.tv_usec / 1000000);
1530 wakeup.tv_usec %= 1000000;
1531
1532 /* Keep waiting until past the time wakeup. */
1533 while (1)
1534 {
1535 struct timeval timeout;
1536
1537 EMACS_GET_TIME (timeout);
1538
1539 /* In effect, timeout = wakeup - timeout.
1540 Break if result would be negative. */
1541 if (timeval_subtract (&timeout, wakeup, timeout))
1542 break;
1543
1544 /* Try to wait that long--but we might wake up sooner. */
1545 select (0, NULL, NULL, NULL, &timeout);
1546 }
1547 }
1548
1549 /* If window is tall, flash top and bottom line. */
1550 if (height > 3 * FRAME_LINE_HEIGHT (f))
1551 {
1552 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1553 flash_left, FRAME_INTERNAL_BORDER_WIDTH (f),
1554 width, flash_height);
1555 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1556 flash_left,
1557 (height - flash_height
1558 - FRAME_INTERNAL_BORDER_WIDTH (f)),
1559 width, flash_height);
1560 }
1561 else
1562 /* If it is short, flash it all. */
1563 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
1564 flash_left, FRAME_INTERNAL_BORDER_WIDTH (f),
1565 width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
1566
1567 XFreeGC (FRAME_X_DISPLAY (f), gc);
1568 XFlush (FRAME_X_DISPLAY (f));
1569 }
1570 }
1571
1572 UNBLOCK_INPUT;
1573 }
1574
1575 #endif
1576
1577
1578 /* Make audible bell. */
1579
1580 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
1581
1582 XTring_bell ()
1583 {
1584 if (FRAME_X_DISPLAY (selected_frame) == 0)
1585 return;
1586
1587 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1588 if (visible_bell)
1589 XTflash (selected_frame);
1590 else
1591 #endif
1592 {
1593 BLOCK_INPUT;
1594 XRINGBELL;
1595 XFlush (FRAME_X_DISPLAY (selected_frame));
1596 UNBLOCK_INPUT;
1597 }
1598 }
1599 \f
1600 /* Insert and delete character.
1601 These are not supposed to be used because we are supposed to turn
1602 off the feature of using them. */
1603
1604 static
1605 XTinsert_glyphs (start, len)
1606 register char *start;
1607 register int len;
1608 {
1609 abort ();
1610 }
1611
1612 static
1613 XTdelete_glyphs (n)
1614 register int n;
1615 {
1616 abort ();
1617 }
1618 \f
1619 /* Specify how many text lines, from the top of the window,
1620 should be affected by insert-lines and delete-lines operations.
1621 This, and those operations, are used only within an update
1622 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1623
1624 static
1625 XTset_terminal_window (n)
1626 register int n;
1627 {
1628 if (updating_frame == 0)
1629 abort ();
1630
1631 if ((n <= 0) || (n > updating_frame->height))
1632 flexlines = updating_frame->height;
1633 else
1634 flexlines = n;
1635 }
1636 \f
1637 /* These variables need not be per frame
1638 because redisplay is done on a frame-by-frame basis
1639 and the line dance for one frame is finished before
1640 anything is done for anoter frame. */
1641
1642 /* Array of line numbers from cached insert/delete operations.
1643 line_dance[i] is the old position of the line that we want
1644 to move to line i, or -1 if we want a blank line there. */
1645 static int *line_dance;
1646
1647 /* Allocated length of that array. */
1648 static int line_dance_len;
1649
1650 /* Flag indicating whether we've done any work. */
1651 static int line_dance_in_progress;
1652
1653 /* Perform an insert-lines or delete-lines operation,
1654 inserting N lines or deleting -N lines at vertical position VPOS. */
1655 XTins_del_lines (vpos, n)
1656 int vpos, n;
1657 {
1658 register int fence, i;
1659
1660 if (vpos >= flexlines)
1661 return;
1662
1663 if (!line_dance_in_progress)
1664 {
1665 int ht = updating_frame->height;
1666 if (ht > line_dance_len)
1667 {
1668 line_dance = (int *)xrealloc (line_dance, ht * sizeof (int));
1669 line_dance_len = ht;
1670 }
1671 for (i = 0; i < ht; ++i) line_dance[i] = i;
1672 line_dance_in_progress = 1;
1673 }
1674 if (n >= 0)
1675 {
1676 if (n > flexlines - vpos)
1677 n = flexlines - vpos;
1678 fence = vpos + n;
1679 for (i = flexlines; --i >= fence;)
1680 line_dance[i] = line_dance[i-n];
1681 for (i = fence; --i >= vpos;)
1682 line_dance[i] = -1;
1683 }
1684 else
1685 {
1686 n = -n;
1687 if (n > flexlines - vpos)
1688 n = flexlines - vpos;
1689 fence = flexlines - n;
1690 for (i = vpos; i < fence; ++i)
1691 line_dance[i] = line_dance[i + n];
1692 for (i = fence; i < flexlines; ++i)
1693 line_dance[i] = -1;
1694 }
1695 }
1696
1697 /* Here's where we actually move the pixels around.
1698 Must be called with input blocked. */
1699 static void
1700 do_line_dance ()
1701 {
1702 register int i, j, distance;
1703 register struct frame *f;
1704 int ht;
1705 int intborder;
1706
1707 /* Must check this flag first. If it's not set, then not only is the
1708 array uninitialized, but we might not even have a frame. */
1709 if (!line_dance_in_progress)
1710 return;
1711
1712 f = updating_frame;
1713 if (f == 0)
1714 abort ();
1715
1716 ht = f->height;
1717 intborder = CHAR_TO_PIXEL_COL (f, FRAME_LEFT_SCROLL_BAR_WIDTH (f));
1718
1719 x_update_cursor (updating_frame, 0);
1720
1721 for (i = 0; i < ht; ++i)
1722 if (line_dance[i] != -1 && (distance = line_dance[i]-i) > 0)
1723 {
1724 for (j = i; (j < ht && line_dance[j] != -1
1725 && line_dance[j]-j == distance); ++j);
1726 /* Copy [i,j) upward from [i+distance,j+distance) */
1727 XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1728 FRAME_X_WINDOW (f), f->output_data.x->normal_gc,
1729 intborder, CHAR_TO_PIXEL_ROW (f, i+distance),
1730 FRAME_WINDOW_WIDTH (f) * FONT_WIDTH (f->output_data.x->font),
1731 (j-i) * f->output_data.x->line_height,
1732 intborder, CHAR_TO_PIXEL_ROW (f, i));
1733 i = j-1;
1734 }
1735
1736 for (i = ht; --i >=0; )
1737 if (line_dance[i] != -1 && (distance = line_dance[i]-i) < 0)
1738 {
1739 for (j = i; (--j >= 0 && line_dance[j] != -1
1740 && line_dance[j]-j == distance););
1741 /* Copy (j,i] downward from (j+distance, i+distance] */
1742 XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1743 FRAME_X_WINDOW (f), f->output_data.x->normal_gc,
1744 intborder, CHAR_TO_PIXEL_ROW (f, j+1+distance),
1745 FRAME_WINDOW_WIDTH (f) * FONT_WIDTH (f->output_data.x->font),
1746 (i-j) * f->output_data.x->line_height,
1747 intborder, CHAR_TO_PIXEL_ROW (f, j+1));
1748 i = j+1;
1749 }
1750
1751 for (i = 0; i < ht; ++i)
1752 if (line_dance[i] == -1)
1753 {
1754 for (j = i; j < ht && line_dance[j] == -1; ++j);
1755 /* Clear [i,j) */
1756 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1757 intborder, CHAR_TO_PIXEL_ROW (f, i),
1758 FRAME_WINDOW_WIDTH (f) * FONT_WIDTH (f->output_data.x->font),
1759 (j-i) * f->output_data.x->line_height, False);
1760 i = j-1;
1761 }
1762 line_dance_in_progress = 0;
1763 }
1764 \f
1765 /* Support routines for exposure events. */
1766 static void clear_cursor ();
1767
1768 /* Output into a rectangle of an X-window (for frame F)
1769 the characters in f->phys_lines that overlap that rectangle.
1770 TOP and LEFT are the position of the upper left corner of the rectangle.
1771 ROWS and COLS are the size of the rectangle.
1772 Call this function with input blocked. */
1773
1774 static void
1775 dumprectangle (f, left, top, cols, rows)
1776 struct frame *f;
1777 register int left, top, cols, rows;
1778 {
1779 register struct frame_glyphs *active_frame = FRAME_CURRENT_GLYPHS (f);
1780 int cursor_cleared = 0;
1781 int bottom, right;
1782 register int y;
1783
1784 if (FRAME_GARBAGED_P (f))
1785 return;
1786
1787 /* Express rectangle as four edges, instead of position-and-size. */
1788 bottom = top + rows;
1789 right = left + cols;
1790
1791 /* Convert rectangle edges in pixels to edges in chars.
1792 Round down for left and top, up for right and bottom. */
1793 top = PIXEL_TO_CHAR_ROW (f, top);
1794 left = PIXEL_TO_CHAR_COL (f, left);
1795 bottom += (f->output_data.x->line_height - 1);
1796 right += (FONT_WIDTH (f->output_data.x->font) - 1);
1797 bottom = PIXEL_TO_CHAR_ROW (f, bottom);
1798 right = PIXEL_TO_CHAR_COL (f, right);
1799
1800 /* Clip the rectangle to what can be visible. */
1801 if (left < 0)
1802 left = 0;
1803 if (top < 0)
1804 top = 0;
1805 if (right > FRAME_WINDOW_WIDTH (f))
1806 right = FRAME_WINDOW_WIDTH (f);
1807 if (bottom > f->height)
1808 bottom = f->height;
1809
1810 /* Get size in chars of the rectangle. */
1811 cols = right - left;
1812 rows = bottom - top;
1813
1814 /* If rectangle has zero area, return. */
1815 if (rows <= 0) return;
1816 if (cols <= 0) return;
1817
1818 /* Turn off the cursor if it is in the rectangle.
1819 We will turn it back on afterward. */
1820 if ((f->phys_cursor_x >= left) && (f->phys_cursor_x < right)
1821 && (f->phys_cursor_y >= top) && (f->phys_cursor_y < bottom))
1822 {
1823 clear_cursor (f);
1824 cursor_cleared = 1;
1825 }
1826
1827 /* Display the text in the rectangle, one text line at a time. */
1828
1829 for (y = top; y < bottom; y++)
1830 {
1831 GLYPH *line = &active_frame->glyphs[y][left];
1832
1833 if (! active_frame->enable[y] || left > active_frame->used[y])
1834 continue;
1835
1836 while (*line & GLYPH_MASK_PADDING)
1837 {
1838 /* We must display the whole glyph of a wide-column
1839 character. */
1840 left--;
1841 line--;
1842 cols++;
1843 }
1844 dumpglyphs (f,
1845 CHAR_TO_PIXEL_COL (f, left),
1846 CHAR_TO_PIXEL_ROW (f, y),
1847 line, min (cols, active_frame->used[y] - left),
1848 active_frame->highlight[y], 0, NULL);
1849 }
1850
1851 /* Turn the cursor on if we turned it off. */
1852
1853 if (cursor_cleared)
1854 x_update_cursor (f, 1);
1855 }
1856 \f
1857 static void
1858 frame_highlight (f)
1859 struct frame *f;
1860 {
1861 /* We used to only do this if Vx_no_window_manager was non-nil, but
1862 the ICCCM (section 4.1.6) says that the window's border pixmap
1863 and border pixel are window attributes which are "private to the
1864 client", so we can always change it to whatever we want. */
1865 BLOCK_INPUT;
1866 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1867 f->output_data.x->border_pixel);
1868 UNBLOCK_INPUT;
1869 x_update_cursor (f, 1);
1870 }
1871
1872 static void
1873 frame_unhighlight (f)
1874 struct frame *f;
1875 {
1876 /* We used to only do this if Vx_no_window_manager was non-nil, but
1877 the ICCCM (section 4.1.6) says that the window's border pixmap
1878 and border pixel are window attributes which are "private to the
1879 client", so we can always change it to whatever we want. */
1880 BLOCK_INPUT;
1881 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1882 f->output_data.x->border_tile);
1883 UNBLOCK_INPUT;
1884 x_update_cursor (f, 1);
1885 }
1886
1887 static void XTframe_rehighlight ();
1888 static void x_frame_rehighlight ();
1889
1890 /* The focus has changed. Update the frames as necessary to reflect
1891 the new situation. Note that we can't change the selected frame
1892 here, because the Lisp code we are interrupting might become confused.
1893 Each event gets marked with the frame in which it occurred, so the
1894 Lisp code can tell when the switch took place by examining the events. */
1895
1896 static void
1897 x_new_focus_frame (dpyinfo, frame)
1898 struct x_display_info *dpyinfo;
1899 struct frame *frame;
1900 {
1901 struct frame *old_focus = dpyinfo->x_focus_frame;
1902 int events_enqueued = 0;
1903
1904 if (frame != dpyinfo->x_focus_frame)
1905 {
1906 /* Set this before calling other routines, so that they see
1907 the correct value of x_focus_frame. */
1908 dpyinfo->x_focus_frame = frame;
1909
1910 if (old_focus && old_focus->auto_lower)
1911 x_lower_frame (old_focus);
1912
1913 #if 0
1914 selected_frame = frame;
1915 XSETFRAME (XWINDOW (selected_frame->selected_window)->frame,
1916 selected_frame);
1917 Fselect_window (selected_frame->selected_window);
1918 choose_minibuf_frame ();
1919 #endif /* ! 0 */
1920
1921 if (dpyinfo->x_focus_frame && dpyinfo->x_focus_frame->auto_raise)
1922 pending_autoraise_frame = dpyinfo->x_focus_frame;
1923 else
1924 pending_autoraise_frame = 0;
1925 }
1926
1927 x_frame_rehighlight (dpyinfo);
1928 }
1929
1930 /* Handle an event saying the mouse has moved out of an Emacs frame. */
1931
1932 void
1933 x_mouse_leave (dpyinfo)
1934 struct x_display_info *dpyinfo;
1935 {
1936 x_new_focus_frame (dpyinfo, dpyinfo->x_focus_event_frame);
1937 }
1938
1939 /* The focus has changed, or we have redirected a frame's focus to
1940 another frame (this happens when a frame uses a surrogate
1941 minibuffer frame). Shift the highlight as appropriate.
1942
1943 The FRAME argument doesn't necessarily have anything to do with which
1944 frame is being highlighted or unhighlighted; we only use it to find
1945 the appropriate X display info. */
1946 static void
1947 XTframe_rehighlight (frame)
1948 struct frame *frame;
1949 {
1950 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame));
1951 }
1952
1953 static void
1954 x_frame_rehighlight (dpyinfo)
1955 struct x_display_info *dpyinfo;
1956 {
1957 struct frame *old_highlight = dpyinfo->x_highlight_frame;
1958
1959 if (dpyinfo->x_focus_frame)
1960 {
1961 dpyinfo->x_highlight_frame
1962 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame)))
1963 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame))
1964 : dpyinfo->x_focus_frame);
1965 if (! FRAME_LIVE_P (dpyinfo->x_highlight_frame))
1966 {
1967 FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame) = Qnil;
1968 dpyinfo->x_highlight_frame = dpyinfo->x_focus_frame;
1969 }
1970 }
1971 else
1972 dpyinfo->x_highlight_frame = 0;
1973
1974 if (dpyinfo->x_highlight_frame != old_highlight)
1975 {
1976 if (old_highlight)
1977 frame_unhighlight (old_highlight);
1978 if (dpyinfo->x_highlight_frame)
1979 frame_highlight (dpyinfo->x_highlight_frame);
1980 }
1981 }
1982 \f
1983 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1984
1985 /* Initialize mode_switch_bit and modifier_meaning. */
1986 static void
1987 x_find_modifier_meanings (dpyinfo)
1988 struct x_display_info *dpyinfo;
1989 {
1990 int min_code, max_code;
1991 KeySym *syms;
1992 int syms_per_code;
1993 XModifierKeymap *mods;
1994
1995 dpyinfo->meta_mod_mask = 0;
1996 dpyinfo->shift_lock_mask = 0;
1997 dpyinfo->alt_mod_mask = 0;
1998 dpyinfo->super_mod_mask = 0;
1999 dpyinfo->hyper_mod_mask = 0;
2000
2001 #ifdef HAVE_X11R4
2002 XDisplayKeycodes (dpyinfo->display, &min_code, &max_code);
2003 #else
2004 min_code = dpyinfo->display->min_keycode;
2005 max_code = dpyinfo->display->max_keycode;
2006 #endif
2007
2008 syms = XGetKeyboardMapping (dpyinfo->display,
2009 min_code, max_code - min_code + 1,
2010 &syms_per_code);
2011 mods = XGetModifierMapping (dpyinfo->display);
2012
2013 /* Scan the modifier table to see which modifier bits the Meta and
2014 Alt keysyms are on. */
2015 {
2016 int row, col; /* The row and column in the modifier table. */
2017
2018 for (row = 3; row < 8; row++)
2019 for (col = 0; col < mods->max_keypermod; col++)
2020 {
2021 KeyCode code
2022 = mods->modifiermap[(row * mods->max_keypermod) + col];
2023
2024 /* Zeroes are used for filler. Skip them. */
2025 if (code == 0)
2026 continue;
2027
2028 /* Are any of this keycode's keysyms a meta key? */
2029 {
2030 int code_col;
2031
2032 for (code_col = 0; code_col < syms_per_code; code_col++)
2033 {
2034 int sym = syms[((code - min_code) * syms_per_code) + code_col];
2035
2036 switch (sym)
2037 {
2038 case XK_Meta_L:
2039 case XK_Meta_R:
2040 dpyinfo->meta_mod_mask |= (1 << row);
2041 break;
2042
2043 case XK_Alt_L:
2044 case XK_Alt_R:
2045 dpyinfo->alt_mod_mask |= (1 << row);
2046 break;
2047
2048 case XK_Hyper_L:
2049 case XK_Hyper_R:
2050 dpyinfo->hyper_mod_mask |= (1 << row);
2051 break;
2052
2053 case XK_Super_L:
2054 case XK_Super_R:
2055 dpyinfo->super_mod_mask |= (1 << row);
2056 break;
2057
2058 case XK_Shift_Lock:
2059 /* Ignore this if it's not on the lock modifier. */
2060 if ((1 << row) == LockMask)
2061 dpyinfo->shift_lock_mask = LockMask;
2062 break;
2063 }
2064 }
2065 }
2066 }
2067 }
2068
2069 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
2070 if (! dpyinfo->meta_mod_mask)
2071 {
2072 dpyinfo->meta_mod_mask = dpyinfo->alt_mod_mask;
2073 dpyinfo->alt_mod_mask = 0;
2074 }
2075
2076 /* If some keys are both alt and meta,
2077 make them just meta, not alt. */
2078 if (dpyinfo->alt_mod_mask & dpyinfo->meta_mod_mask)
2079 {
2080 dpyinfo->alt_mod_mask &= ~dpyinfo->meta_mod_mask;
2081 }
2082
2083 XFree ((char *) syms);
2084 XFreeModifiermap (mods);
2085 }
2086
2087 /* Convert between the modifier bits X uses and the modifier bits
2088 Emacs uses. */
2089 static unsigned int
2090 x_x_to_emacs_modifiers (dpyinfo, state)
2091 struct x_display_info *dpyinfo;
2092 unsigned int state;
2093 {
2094 return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0)
2095 | ((state & ControlMask) ? ctrl_modifier : 0)
2096 | ((state & dpyinfo->meta_mod_mask) ? meta_modifier : 0)
2097 | ((state & dpyinfo->alt_mod_mask) ? alt_modifier : 0)
2098 | ((state & dpyinfo->super_mod_mask) ? super_modifier : 0)
2099 | ((state & dpyinfo->hyper_mod_mask) ? hyper_modifier : 0));
2100 }
2101
2102 static unsigned int
2103 x_emacs_to_x_modifiers (dpyinfo, state)
2104 struct x_display_info *dpyinfo;
2105 unsigned int state;
2106 {
2107 return ( ((state & alt_modifier) ? dpyinfo->alt_mod_mask : 0)
2108 | ((state & super_modifier) ? dpyinfo->super_mod_mask : 0)
2109 | ((state & hyper_modifier) ? dpyinfo->hyper_mod_mask : 0)
2110 | ((state & shift_modifier) ? ShiftMask : 0)
2111 | ((state & ctrl_modifier) ? ControlMask : 0)
2112 | ((state & meta_modifier) ? dpyinfo->meta_mod_mask : 0));
2113 }
2114
2115 /* Convert a keysym to its name. */
2116
2117 char *
2118 x_get_keysym_name (keysym)
2119 KeySym keysym;
2120 {
2121 char *value;
2122
2123 BLOCK_INPUT;
2124 value = XKeysymToString (keysym);
2125 UNBLOCK_INPUT;
2126
2127 return value;
2128 }
2129 \f
2130 /* Mouse clicks and mouse movement. Rah. */
2131
2132 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
2133 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
2134 that the glyph at X, Y occupies, if BOUNDS != 0.
2135 If NOCLIP is nonzero, do not force the value into range. */
2136
2137 void
2138 pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip)
2139 FRAME_PTR f;
2140 register int pix_x, pix_y;
2141 register int *x, *y;
2142 XRectangle *bounds;
2143 int noclip;
2144 {
2145 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
2146 even for negative values. */
2147 if (pix_x < 0)
2148 pix_x -= FONT_WIDTH ((f)->output_data.x->font) - 1;
2149 if (pix_y < 0)
2150 pix_y -= (f)->output_data.x->line_height - 1;
2151
2152 pix_x = PIXEL_TO_CHAR_COL (f, pix_x);
2153 pix_y = PIXEL_TO_CHAR_ROW (f, pix_y);
2154
2155 if (bounds)
2156 {
2157 bounds->width = FONT_WIDTH (f->output_data.x->font);
2158 bounds->height = f->output_data.x->line_height;
2159 bounds->x = CHAR_TO_PIXEL_COL (f, pix_x);
2160 bounds->y = CHAR_TO_PIXEL_ROW (f, pix_y);
2161 }
2162
2163 if (!noclip)
2164 {
2165 if (pix_x < 0)
2166 pix_x = 0;
2167 else if (pix_x > FRAME_WINDOW_WIDTH (f))
2168 pix_x = FRAME_WINDOW_WIDTH (f);
2169
2170 if (pix_y < 0)
2171 pix_y = 0;
2172 else if (pix_y > f->height)
2173 pix_y = f->height;
2174 }
2175
2176 *x = pix_x;
2177 *y = pix_y;
2178 }
2179
2180 void
2181 glyph_to_pixel_coords (f, x, y, pix_x, pix_y)
2182 FRAME_PTR f;
2183 register int x, y;
2184 register int *pix_x, *pix_y;
2185 {
2186 *pix_x = CHAR_TO_PIXEL_COL (f, x);
2187 *pix_y = CHAR_TO_PIXEL_ROW (f, y);
2188 }
2189
2190 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2191
2192 If the event is a button press, then note that we have grabbed
2193 the mouse. */
2194
2195 static Lisp_Object
2196 construct_mouse_click (result, event, f)
2197 struct input_event *result;
2198 XButtonEvent *event;
2199 struct frame *f;
2200 {
2201 /* Make the event type no_event; we'll change that when we decide
2202 otherwise. */
2203 result->kind = mouse_click;
2204 result->code = event->button - Button1;
2205 result->timestamp = event->time;
2206 result->modifiers = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f),
2207 event->state)
2208 | (event->type == ButtonRelease
2209 ? up_modifier
2210 : down_modifier));
2211
2212 {
2213 int row, column;
2214
2215 #if 0
2216 pixel_to_glyph_coords (f, event->x, event->y, &column, &row, NULL, 0);
2217 XSETFASTINT (result->x, column);
2218 XSETFASTINT (result->y, row);
2219 #endif
2220 XSETINT (result->x, event->x);
2221 XSETINT (result->y, event->y);
2222 XSETFRAME (result->frame_or_window, f);
2223 }
2224 }
2225
2226 /* Prepare a menu-event in *RESULT for placement in the input queue. */
2227
2228 static Lisp_Object
2229 construct_menu_click (result, event, f)
2230 struct input_event *result;
2231 XButtonEvent *event;
2232 struct frame *f;
2233 {
2234 /* Make the event type no_event; we'll change that when we decide
2235 otherwise. */
2236 result->kind = mouse_click;
2237 result->code = event->button - Button1;
2238 result->timestamp = event->time;
2239 result->modifiers = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f),
2240 event->state)
2241 | (event->type == ButtonRelease
2242 ? up_modifier
2243 : down_modifier));
2244
2245 XSETINT (result->x, event->x);
2246 XSETINT (result->y, -1);
2247 XSETFRAME (result->frame_or_window, f);
2248 }
2249 \f
2250 /* Function to report a mouse movement to the mainstream Emacs code.
2251 The input handler calls this.
2252
2253 We have received a mouse movement event, which is given in *event.
2254 If the mouse is over a different glyph than it was last time, tell
2255 the mainstream emacs code by setting mouse_moved. If not, ask for
2256 another motion event, so we can check again the next time it moves. */
2257
2258 static void
2259 note_mouse_movement (frame, event)
2260 FRAME_PTR frame;
2261 XMotionEvent *event;
2262 {
2263 last_mouse_movement_time = event->time;
2264
2265 if (event->window != FRAME_X_WINDOW (frame))
2266 {
2267 frame->mouse_moved = 1;
2268 last_mouse_scroll_bar = Qnil;
2269
2270 note_mouse_highlight (frame, -1, -1);
2271 }
2272
2273 /* Has the mouse moved off the glyph it was on at the last sighting? */
2274 else if (event->x < last_mouse_glyph.x
2275 || event->x >= last_mouse_glyph.x + last_mouse_glyph.width
2276 || event->y < last_mouse_glyph.y
2277 || event->y >= last_mouse_glyph.y + last_mouse_glyph.height)
2278 {
2279 frame->mouse_moved = 1;
2280 last_mouse_scroll_bar = Qnil;
2281
2282 note_mouse_highlight (frame, event->x, event->y);
2283 }
2284 }
2285
2286 /* This is used for debugging, to turn off note_mouse_highlight. */
2287 static int disable_mouse_highlight;
2288
2289 /* Take proper action when the mouse has moved to position X, Y on frame F
2290 as regards highlighting characters that have mouse-face properties.
2291 Also dehighlighting chars where the mouse was before.
2292 X and Y can be negative or out of range. */
2293
2294 static void
2295 note_mouse_highlight (f, x, y)
2296 FRAME_PTR f;
2297 int x, y;
2298 {
2299 int row, column, portion;
2300 XRectangle new_glyph;
2301 Lisp_Object window;
2302 struct window *w;
2303
2304 if (disable_mouse_highlight)
2305 return;
2306
2307 FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_x = x;
2308 FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_y = y;
2309 FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_frame = f;
2310
2311 if (FRAME_X_DISPLAY_INFO (f)->mouse_face_defer)
2312 return;
2313
2314 if (gc_in_progress)
2315 {
2316 FRAME_X_DISPLAY_INFO (f)->mouse_face_deferred_gc = 1;
2317 return;
2318 }
2319
2320 /* Find out which glyph the mouse is on. */
2321 pixel_to_glyph_coords (f, x, y, &column, &row,
2322 &new_glyph, FRAME_X_DISPLAY_INFO (f)->grabbed);
2323
2324 /* Which window is that in? */
2325 window = window_from_coordinates (f, column, row, &portion);
2326 w = XWINDOW (window);
2327
2328 /* If we were displaying active text in another window, clear that. */
2329 if (! EQ (window, FRAME_X_DISPLAY_INFO (f)->mouse_face_window))
2330 clear_mouse_face (FRAME_X_DISPLAY_INFO (f));
2331
2332 /* Are we in a window whose display is up to date?
2333 And verify the buffer's text has not changed. */
2334 if (WINDOWP (window) && portion == 0 && row >= 0 && column >= 0
2335 && row < FRAME_HEIGHT (f) && column < FRAME_WIDTH (f)
2336 && EQ (w->window_end_valid, w->buffer)
2337 && XFASTINT (w->last_modified) == BUF_MODIFF (XBUFFER (w->buffer))
2338 && (XFASTINT (w->last_overlay_modified)
2339 == BUF_OVERLAY_MODIFF (XBUFFER (w->buffer))))
2340 {
2341 int *ptr = FRAME_CURRENT_GLYPHS (f)->charstarts[row];
2342 int i, pos;
2343
2344 /* Find which buffer position the mouse corresponds to. */
2345 for (i = column; i >= 0; i--)
2346 if (ptr[i] > 0)
2347 break;
2348 pos = ptr[i];
2349 /* Is it outside the displayed active region (if any)? */
2350 if (pos <= 0)
2351 clear_mouse_face (FRAME_X_DISPLAY_INFO (f));
2352 else if (! (EQ (window, FRAME_X_DISPLAY_INFO (f)->mouse_face_window)
2353 && row >= FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_row
2354 && row <= FRAME_X_DISPLAY_INFO (f)->mouse_face_end_row
2355 && (row > FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_row
2356 || column >= FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_col)
2357 && (row < FRAME_X_DISPLAY_INFO (f)->mouse_face_end_row
2358 || column < FRAME_X_DISPLAY_INFO (f)->mouse_face_end_col
2359 || FRAME_X_DISPLAY_INFO (f)->mouse_face_past_end)))
2360 {
2361 Lisp_Object mouse_face, overlay, position;
2362 Lisp_Object *overlay_vec;
2363 int len, noverlays, ignor1;
2364 struct buffer *obuf;
2365 int obegv, ozv;
2366
2367 /* If we get an out-of-range value, return now; avoid an error. */
2368 if (pos > BUF_Z (XBUFFER (w->buffer)))
2369 return;
2370
2371 /* Make the window's buffer temporarily current for
2372 overlays_at and compute_char_face. */
2373 obuf = current_buffer;
2374 current_buffer = XBUFFER (w->buffer);
2375 obegv = BEGV;
2376 ozv = ZV;
2377 BEGV = BEG;
2378 ZV = Z;
2379
2380 /* Yes. Clear the display of the old active region, if any. */
2381 clear_mouse_face (FRAME_X_DISPLAY_INFO (f));
2382
2383 /* Is this char mouse-active? */
2384 XSETINT (position, pos);
2385
2386 len = 10;
2387 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object));
2388
2389 /* Put all the overlays we want in a vector in overlay_vec.
2390 Store the length in len. */
2391 noverlays = overlays_at (pos, 1, &overlay_vec, &len,
2392 NULL, NULL);
2393 noverlays = sort_overlays (overlay_vec, noverlays, w);
2394
2395 /* Find the highest priority overlay that has a mouse-face prop. */
2396 overlay = Qnil;
2397 for (i = 0; i < noverlays; i++)
2398 {
2399 mouse_face = Foverlay_get (overlay_vec[i], Qmouse_face);
2400 if (!NILP (mouse_face))
2401 {
2402 overlay = overlay_vec[i];
2403 break;
2404 }
2405 }
2406 free (overlay_vec);
2407 /* If no overlay applies, get a text property. */
2408 if (NILP (overlay))
2409 mouse_face = Fget_text_property (position, Qmouse_face, w->buffer);
2410
2411 /* Handle the overlay case. */
2412 if (! NILP (overlay))
2413 {
2414 /* Find the range of text around this char that
2415 should be active. */
2416 Lisp_Object before, after;
2417 int ignore;
2418
2419 before = Foverlay_start (overlay);
2420 after = Foverlay_end (overlay);
2421 /* Record this as the current active region. */
2422 fast_find_position (window, XFASTINT (before),
2423 &FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_col,
2424 &FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_row);
2425 FRAME_X_DISPLAY_INFO (f)->mouse_face_past_end
2426 = !fast_find_position (window, XFASTINT (after),
2427 &FRAME_X_DISPLAY_INFO (f)->mouse_face_end_col,
2428 &FRAME_X_DISPLAY_INFO (f)->mouse_face_end_row);
2429 FRAME_X_DISPLAY_INFO (f)->mouse_face_window = window;
2430 FRAME_X_DISPLAY_INFO (f)->mouse_face_face_id
2431 = compute_char_face (f, w, pos, 0, 0,
2432 &ignore, pos + 1, 1);
2433
2434 /* Display it as active. */
2435 show_mouse_face (FRAME_X_DISPLAY_INFO (f), 1);
2436 }
2437 /* Handle the text property case. */
2438 else if (! NILP (mouse_face))
2439 {
2440 /* Find the range of text around this char that
2441 should be active. */
2442 Lisp_Object before, after, beginning, end;
2443 int ignore;
2444
2445 beginning = Fmarker_position (w->start);
2446 XSETINT (end, (BUF_Z (XBUFFER (w->buffer))
2447 - XFASTINT (w->window_end_pos)));
2448 before
2449 = Fprevious_single_property_change (make_number (pos + 1),
2450 Qmouse_face,
2451 w->buffer, beginning);
2452 after
2453 = Fnext_single_property_change (position, Qmouse_face,
2454 w->buffer, end);
2455 /* Record this as the current active region. */
2456 fast_find_position (window, XFASTINT (before),
2457 &FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_col,
2458 &FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_row);
2459 FRAME_X_DISPLAY_INFO (f)->mouse_face_past_end
2460 = !fast_find_position (window, XFASTINT (after),
2461 &FRAME_X_DISPLAY_INFO (f)->mouse_face_end_col,
2462 &FRAME_X_DISPLAY_INFO (f)->mouse_face_end_row);
2463 FRAME_X_DISPLAY_INFO (f)->mouse_face_window = window;
2464 FRAME_X_DISPLAY_INFO (f)->mouse_face_face_id
2465 = compute_char_face (f, w, pos, 0, 0,
2466 &ignore, pos + 1, 1);
2467
2468 /* Display it as active. */
2469 show_mouse_face (FRAME_X_DISPLAY_INFO (f), 1);
2470 }
2471 BEGV = obegv;
2472 ZV = ozv;
2473 current_buffer = obuf;
2474 }
2475 }
2476 }
2477 \f
2478 /* Find the row and column of position POS in window WINDOW.
2479 Store them in *COLUMNP and *ROWP.
2480 This assumes display in WINDOW is up to date.
2481 If POS is above start of WINDOW, return coords
2482 of start of first screen line.
2483 If POS is after end of WINDOW, return coords of end of last screen line.
2484
2485 Value is 1 if POS is in range, 0 if it was off screen. */
2486
2487 static int
2488 fast_find_position (window, pos, columnp, rowp)
2489 Lisp_Object window;
2490 int pos;
2491 int *columnp, *rowp;
2492 {
2493 struct window *w = XWINDOW (window);
2494 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2495 int i;
2496 int row = 0;
2497 int left = WINDOW_LEFT_MARGIN (w);
2498 int top = XFASTINT (w->top);
2499 int height = XFASTINT (w->height) - ! MINI_WINDOW_P (w);
2500 int width = window_internal_width (w);
2501 int *charstarts;
2502 int lastcol;
2503 int maybe_next_line = 0;
2504
2505 /* Find the right row. */
2506 for (i = 0;
2507 i < height;
2508 i++)
2509 {
2510 int linestart = FRAME_CURRENT_GLYPHS (f)->charstarts[top + i][left];
2511 if (linestart > pos)
2512 break;
2513 /* If the position sought is the end of the buffer,
2514 don't include the blank lines at the bottom of the window. */
2515 if (linestart == pos && pos == BUF_ZV (XBUFFER (w->buffer)))
2516 {
2517 maybe_next_line = 1;
2518 break;
2519 }
2520 if (linestart > 0)
2521 row = i;
2522 }
2523
2524 /* Find the right column with in it. */
2525 charstarts = FRAME_CURRENT_GLYPHS (f)->charstarts[top + row];
2526 lastcol = left;
2527 for (i = 0; i < width; i++)
2528 {
2529 if (charstarts[left + i] == pos)
2530 {
2531 *rowp = row + top;
2532 *columnp = i + left;
2533 return 1;
2534 }
2535 else if (charstarts[left + i] > pos)
2536 break;
2537 else if (charstarts[left + i] > 0)
2538 lastcol = left + i;
2539 }
2540
2541 /* If we're looking for the end of the buffer,
2542 and we didn't find it in the line we scanned,
2543 use the start of the following line. */
2544 if (maybe_next_line)
2545 {
2546 row++;
2547 lastcol = left;
2548 }
2549
2550 *rowp = row + top;
2551 *columnp = lastcol;
2552 return 0;
2553 }
2554
2555 /* Display the active region described by mouse_face_*
2556 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2557
2558 static void
2559 show_mouse_face (dpyinfo, hl)
2560 struct x_display_info *dpyinfo;
2561 int hl;
2562 {
2563 struct window *w = XWINDOW (dpyinfo->mouse_face_window);
2564 int width = window_internal_width (w);
2565 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2566 int i;
2567 int cursor_off = 0;
2568 int old_curs_x = curs_x;
2569 int old_curs_y = curs_y;
2570
2571 /* Set these variables temporarily
2572 so that if we have to turn the cursor off and on again
2573 we will put it back at the same place. */
2574 curs_x = f->phys_cursor_x;
2575 curs_y = f->phys_cursor_y;
2576 for (i = FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_row;
2577 i <= FRAME_X_DISPLAY_INFO (f)->mouse_face_end_row; i++)
2578 {
2579 int column = (i == FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_row
2580 ? FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_col
2581 : WINDOW_LEFT_MARGIN (w));
2582 int endcolumn = (i == FRAME_X_DISPLAY_INFO (f)->mouse_face_end_row
2583 ? FRAME_X_DISPLAY_INFO (f)->mouse_face_end_col
2584 : WINDOW_LEFT_MARGIN (w) + width);
2585 endcolumn = min (endcolumn, FRAME_CURRENT_GLYPHS (f)->used[i]);
2586
2587 /* If the cursor's in the text we are about to rewrite,
2588 turn the cursor off. */
2589 if (i == curs_y
2590 && curs_x >= column - 1
2591 && curs_x <= endcolumn)
2592 {
2593 x_update_cursor (f, 0);
2594 cursor_off = 1;
2595 }
2596
2597 dumpglyphs (f,
2598 CHAR_TO_PIXEL_COL (f, column),
2599 CHAR_TO_PIXEL_ROW (f, i),
2600 FRAME_CURRENT_GLYPHS (f)->glyphs[i] + column,
2601 endcolumn - column,
2602 /* Highlight with mouse face if hl > 0. */
2603 hl > 0 ? 3 : 0, 0, NULL);
2604 }
2605
2606 /* If we turned the cursor off, turn it back on. */
2607 if (cursor_off)
2608 x_display_cursor (f, 1, curs_x, curs_y);
2609
2610 curs_x = old_curs_x;
2611 curs_y = old_curs_y;
2612
2613 /* Change the mouse cursor according to the value of HL. */
2614 if (hl > 0)
2615 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2616 f->output_data.x->cross_cursor);
2617 else
2618 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2619 f->output_data.x->text_cursor);
2620 }
2621
2622 /* Clear out the mouse-highlighted active region.
2623 Redraw it unhighlighted first. */
2624
2625 static void
2626 clear_mouse_face (dpyinfo)
2627 struct x_display_info *dpyinfo;
2628 {
2629 if (! NILP (dpyinfo->mouse_face_window))
2630 show_mouse_face (dpyinfo, 0);
2631
2632 dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
2633 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
2634 dpyinfo->mouse_face_window = Qnil;
2635 }
2636
2637 /* Just discard the mouse face information for frame F, if any.
2638 This is used when the size of F is changed. */
2639
2640 cancel_mouse_face (f)
2641 FRAME_PTR f;
2642 {
2643 Lisp_Object window;
2644 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2645
2646 window = dpyinfo->mouse_face_window;
2647 if (! NILP (window) && XFRAME (XWINDOW (window)->frame) == f)
2648 {
2649 dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
2650 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
2651 dpyinfo->mouse_face_window = Qnil;
2652 }
2653 }
2654 \f
2655 static struct scroll_bar *x_window_to_scroll_bar ();
2656 static void x_scroll_bar_report_motion ();
2657
2658 /* Return the current position of the mouse.
2659 *fp should be a frame which indicates which display to ask about.
2660
2661 If the mouse movement started in a scroll bar, set *fp, *bar_window,
2662 and *part to the frame, window, and scroll bar part that the mouse
2663 is over. Set *x and *y to the portion and whole of the mouse's
2664 position on the scroll bar.
2665
2666 If the mouse movement started elsewhere, set *fp to the frame the
2667 mouse is on, *bar_window to nil, and *x and *y to the character cell
2668 the mouse is over.
2669
2670 Set *time to the server timestamp for the time at which the mouse
2671 was at this position.
2672
2673 Don't store anything if we don't have a valid set of values to report.
2674
2675 This clears the mouse_moved flag, so we can wait for the next mouse
2676 movement. */
2677
2678 static void
2679 XTmouse_position (fp, insist, bar_window, part, x, y, time)
2680 FRAME_PTR *fp;
2681 int insist;
2682 Lisp_Object *bar_window;
2683 enum scroll_bar_part *part;
2684 Lisp_Object *x, *y;
2685 unsigned long *time;
2686 {
2687 FRAME_PTR f1;
2688
2689 BLOCK_INPUT;
2690
2691 if (! NILP (last_mouse_scroll_bar))
2692 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
2693 else
2694 {
2695 Window root;
2696 int root_x, root_y;
2697
2698 Window dummy_window;
2699 int dummy;
2700
2701 Lisp_Object frame, tail;
2702
2703 /* Clear the mouse-moved flag for every frame on this display. */
2704 FOR_EACH_FRAME (tail, frame)
2705 if (FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp))
2706 XFRAME (frame)->mouse_moved = 0;
2707
2708 last_mouse_scroll_bar = Qnil;
2709
2710 /* Figure out which root window we're on. */
2711 XQueryPointer (FRAME_X_DISPLAY (*fp),
2712 DefaultRootWindow (FRAME_X_DISPLAY (*fp)),
2713
2714 /* The root window which contains the pointer. */
2715 &root,
2716
2717 /* Trash which we can't trust if the pointer is on
2718 a different screen. */
2719 &dummy_window,
2720
2721 /* The position on that root window. */
2722 &root_x, &root_y,
2723
2724 /* More trash we can't trust. */
2725 &dummy, &dummy,
2726
2727 /* Modifier keys and pointer buttons, about which
2728 we don't care. */
2729 (unsigned int *) &dummy);
2730
2731 /* Now we have a position on the root; find the innermost window
2732 containing the pointer. */
2733 {
2734 Window win, child;
2735 int win_x, win_y;
2736 int parent_x, parent_y;
2737 int count;
2738
2739 win = root;
2740
2741 /* XTranslateCoordinates can get errors if the window
2742 structure is changing at the same time this function
2743 is running. So at least we must not crash from them. */
2744
2745 count = x_catch_errors (FRAME_X_DISPLAY (*fp));
2746
2747 if (FRAME_X_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame
2748 && FRAME_LIVE_P (last_mouse_frame))
2749 {
2750 /* If mouse was grabbed on a frame, give coords for that frame
2751 even if the mouse is now outside it. */
2752 XTranslateCoordinates (FRAME_X_DISPLAY (*fp),
2753
2754 /* From-window, to-window. */
2755 root, FRAME_X_WINDOW (last_mouse_frame),
2756
2757 /* From-position, to-position. */
2758 root_x, root_y, &win_x, &win_y,
2759
2760 /* Child of win. */
2761 &child);
2762 f1 = last_mouse_frame;
2763 }
2764 else
2765 {
2766 while (1)
2767 {
2768 XTranslateCoordinates (FRAME_X_DISPLAY (*fp),
2769
2770 /* From-window, to-window. */
2771 root, win,
2772
2773 /* From-position, to-position. */
2774 root_x, root_y, &win_x, &win_y,
2775
2776 /* Child of win. */
2777 &child);
2778
2779 if (child == None || child == win)
2780 break;
2781
2782 win = child;
2783 parent_x = win_x;
2784 parent_y = win_y;
2785 }
2786
2787 /* Now we know that:
2788 win is the innermost window containing the pointer
2789 (XTC says it has no child containing the pointer),
2790 win_x and win_y are the pointer's position in it
2791 (XTC did this the last time through), and
2792 parent_x and parent_y are the pointer's position in win's parent.
2793 (They are what win_x and win_y were when win was child.
2794 If win is the root window, it has no parent, and
2795 parent_{x,y} are invalid, but that's okay, because we'll
2796 never use them in that case.) */
2797
2798 /* Is win one of our frames? */
2799 f1 = x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp), win);
2800 }
2801
2802 if (x_had_errors_p (FRAME_X_DISPLAY (*fp)))
2803 f1 = 0;
2804
2805 x_uncatch_errors (FRAME_X_DISPLAY (*fp), count);
2806
2807 /* If not, is it one of our scroll bars? */
2808 if (! f1)
2809 {
2810 struct scroll_bar *bar = x_window_to_scroll_bar (win);
2811
2812 if (bar)
2813 {
2814 f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
2815 win_x = parent_x;
2816 win_y = parent_y;
2817 }
2818 }
2819
2820 if (f1 == 0 && insist)
2821 f1 = selected_frame;
2822
2823 if (f1)
2824 {
2825 int ignore1, ignore2;
2826
2827 /* Ok, we found a frame. Store all the values. */
2828
2829 pixel_to_glyph_coords (f1, win_x, win_y, &ignore1, &ignore2,
2830 &last_mouse_glyph,
2831 FRAME_X_DISPLAY_INFO (f1)->grabbed
2832 || insist);
2833
2834 *bar_window = Qnil;
2835 *part = 0;
2836 *fp = f1;
2837 XSETINT (*x, win_x);
2838 XSETINT (*y, win_y);
2839 *time = last_mouse_movement_time;
2840 }
2841 }
2842 }
2843
2844 UNBLOCK_INPUT;
2845 }
2846 \f
2847 /* Scroll bar support. */
2848
2849 /* Given an X window ID, find the struct scroll_bar which manages it.
2850 This can be called in GC, so we have to make sure to strip off mark
2851 bits. */
2852 static struct scroll_bar *
2853 x_window_to_scroll_bar (window_id)
2854 Window window_id;
2855 {
2856 Lisp_Object tail, frame;
2857
2858 for (tail = Vframe_list;
2859 XGCTYPE (tail) == Lisp_Cons;
2860 tail = XCONS (tail)->cdr)
2861 {
2862 Lisp_Object frame, bar, condemned;
2863
2864 frame = XCONS (tail)->car;
2865 /* All elements of Vframe_list should be frames. */
2866 if (! GC_FRAMEP (frame))
2867 abort ();
2868
2869 /* Scan this frame's scroll bar list for a scroll bar with the
2870 right window ID. */
2871 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame));
2872 for (bar = FRAME_SCROLL_BARS (XFRAME (frame));
2873 /* This trick allows us to search both the ordinary and
2874 condemned scroll bar lists with one loop. */
2875 ! GC_NILP (bar) || (bar = condemned,
2876 condemned = Qnil,
2877 ! GC_NILP (bar));
2878 bar = XSCROLL_BAR (bar)->next)
2879 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)) == window_id)
2880 return XSCROLL_BAR (bar);
2881 }
2882
2883 return 0;
2884 }
2885
2886 /* Open a new X window to serve as a scroll bar, and return the
2887 scroll bar vector for it. */
2888 static struct scroll_bar *
2889 x_scroll_bar_create (window, top, left, width, height)
2890 struct window *window;
2891 int top, left, width, height;
2892 {
2893 FRAME_PTR f = XFRAME (WINDOW_FRAME (window));
2894 struct scroll_bar *bar
2895 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
2896
2897 BLOCK_INPUT;
2898
2899 {
2900 XSetWindowAttributes a;
2901 unsigned long mask;
2902 a.background_pixel = f->output_data.x->background_pixel;
2903 a.event_mask = (ButtonPressMask | ButtonReleaseMask
2904 | ButtonMotionMask | PointerMotionHintMask
2905 | ExposureMask);
2906 a.cursor = FRAME_X_DISPLAY_INFO (f)->vertical_scroll_bar_cursor;
2907
2908 mask = (CWBackPixel | CWEventMask | CWCursor);
2909
2910 #if 0
2911
2912 ac = 0;
2913 XtSetArg (al[ac], XtNx, left); ac++;
2914 XtSetArg (al[ac], XtNy, top); ac++;
2915 XtSetArg (al[ac], XtNwidth, width); ac++;
2916 XtSetArg (al[ac], XtNheight, height); ac++;
2917 XtSetArg (al[ac], XtNborderWidth, 0); ac++;
2918 sb_widget = XtCreateManagedWidget ("box",
2919 boxWidgetClass,
2920 f->output_data.x->edit_widget, al, ac);
2921 SET_SCROLL_BAR_X_WINDOW
2922 (bar, sb_widget->core.window);
2923 #endif
2924 SET_SCROLL_BAR_X_WINDOW
2925 (bar,
2926 XCreateWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2927
2928 /* Position and size of scroll bar. */
2929 left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, top,
2930 width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, height,
2931
2932 /* Border width, depth, class, and visual. */
2933 0, CopyFromParent, CopyFromParent, CopyFromParent,
2934
2935 /* Attributes. */
2936 mask, &a));
2937 }
2938
2939 XSETWINDOW (bar->window, window);
2940 XSETINT (bar->top, top);
2941 XSETINT (bar->left, left);
2942 XSETINT (bar->width, width);
2943 XSETINT (bar->height, height);
2944 XSETINT (bar->start, 0);
2945 XSETINT (bar->end, 0);
2946 bar->dragging = Qnil;
2947
2948 /* Add bar to its frame's list of scroll bars. */
2949 bar->next = FRAME_SCROLL_BARS (f);
2950 bar->prev = Qnil;
2951 XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
2952 if (! NILP (bar->next))
2953 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
2954
2955 XMapRaised (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar));
2956
2957 UNBLOCK_INPUT;
2958
2959 return bar;
2960 }
2961
2962 /* Draw BAR's handle in the proper position.
2963 If the handle is already drawn from START to END, don't bother
2964 redrawing it, unless REBUILD is non-zero; in that case, always
2965 redraw it. (REBUILD is handy for drawing the handle after expose
2966 events.)
2967
2968 Normally, we want to constrain the start and end of the handle to
2969 fit inside its rectangle, but if the user is dragging the scroll bar
2970 handle, we want to let them drag it down all the way, so that the
2971 bar's top is as far down as it goes; otherwise, there's no way to
2972 move to the very end of the buffer. */
2973 static void
2974 x_scroll_bar_set_handle (bar, start, end, rebuild)
2975 struct scroll_bar *bar;
2976 int start, end;
2977 int rebuild;
2978 {
2979 int dragging = ! NILP (bar->dragging);
2980 Window w = SCROLL_BAR_X_WINDOW (bar);
2981 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
2982 GC gc = f->output_data.x->normal_gc;
2983
2984 /* If the display is already accurate, do nothing. */
2985 if (! rebuild
2986 && start == XINT (bar->start)
2987 && end == XINT (bar->end))
2988 return;
2989
2990 BLOCK_INPUT;
2991
2992 {
2993 int inside_width = VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f, XINT (bar->width));
2994 int inside_height = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height));
2995 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
2996
2997 /* Make sure the values are reasonable, and try to preserve
2998 the distance between start and end. */
2999 {
3000 int length = end - start;
3001
3002 if (start < 0)
3003 start = 0;
3004 else if (start > top_range)
3005 start = top_range;
3006 end = start + length;
3007
3008 if (end < start)
3009 end = start;
3010 else if (end > top_range && ! dragging)
3011 end = top_range;
3012 }
3013
3014 /* Store the adjusted setting in the scroll bar. */
3015 XSETINT (bar->start, start);
3016 XSETINT (bar->end, end);
3017
3018 /* Clip the end position, just for display. */
3019 if (end > top_range)
3020 end = top_range;
3021
3022 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
3023 below top positions, to make sure the handle is always at least
3024 that many pixels tall. */
3025 end += VERTICAL_SCROLL_BAR_MIN_HANDLE;
3026
3027 /* Draw the empty space above the handle. Note that we can't clear
3028 zero-height areas; that means "clear to end of window." */
3029 if (0 < start)
3030 XClearArea (FRAME_X_DISPLAY (f), w,
3031
3032 /* x, y, width, height, and exposures. */
3033 VERTICAL_SCROLL_BAR_LEFT_BORDER,
3034 VERTICAL_SCROLL_BAR_TOP_BORDER,
3035 inside_width, start,
3036 False);
3037
3038 /* Draw the handle itself. */
3039 XFillRectangle (FRAME_X_DISPLAY (f), w, gc,
3040
3041 /* x, y, width, height */
3042 VERTICAL_SCROLL_BAR_LEFT_BORDER,
3043 VERTICAL_SCROLL_BAR_TOP_BORDER + start,
3044 inside_width, end - start);
3045
3046
3047 /* Draw the empty space below the handle. Note that we can't
3048 clear zero-height areas; that means "clear to end of window." */
3049 if (end < inside_height)
3050 XClearArea (FRAME_X_DISPLAY (f), w,
3051
3052 /* x, y, width, height, and exposures. */
3053 VERTICAL_SCROLL_BAR_LEFT_BORDER,
3054 VERTICAL_SCROLL_BAR_TOP_BORDER + end,
3055 inside_width, inside_height - end,
3056 False);
3057
3058 }
3059
3060 UNBLOCK_INPUT;
3061 }
3062
3063 /* Move a scroll bar around on the screen, to accommodate changing
3064 window configurations. */
3065 static void
3066 x_scroll_bar_move (bar, top, left, width, height)
3067 struct scroll_bar *bar;
3068 int top, left, width, height;
3069 {
3070 Window w = SCROLL_BAR_X_WINDOW (bar);
3071 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3072
3073 BLOCK_INPUT;
3074
3075 {
3076 XWindowChanges wc;
3077 unsigned int mask = 0;
3078
3079 wc.x = left + VERTICAL_SCROLL_BAR_WIDTH_TRIM;
3080 wc.y = top;
3081
3082 wc.width = width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2;
3083 wc.height = height;
3084
3085 if (left != XINT (bar->left)) mask |= CWX;
3086 if (top != XINT (bar->top)) mask |= CWY;
3087 if (width != XINT (bar->width)) mask |= CWWidth;
3088 if (height != XINT (bar->height)) mask |= CWHeight;
3089
3090 if (mask)
3091 XConfigureWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar),
3092 mask, &wc);
3093 }
3094
3095 XSETINT (bar->left, left);
3096 XSETINT (bar->top, top);
3097 XSETINT (bar->width, width);
3098 XSETINT (bar->height, height);
3099
3100 UNBLOCK_INPUT;
3101 }
3102
3103 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
3104 to nil. */
3105 static void
3106 x_scroll_bar_remove (bar)
3107 struct scroll_bar *bar;
3108 {
3109 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3110
3111 BLOCK_INPUT;
3112
3113 /* Destroy the window. */
3114 XDestroyWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar));
3115
3116 /* Disassociate this scroll bar from its window. */
3117 XWINDOW (bar->window)->vertical_scroll_bar = Qnil;
3118
3119 UNBLOCK_INPUT;
3120 }
3121
3122 /* Set the handle of the vertical scroll bar for WINDOW to indicate
3123 that we are displaying PORTION characters out of a total of WHOLE
3124 characters, starting at POSITION. If WINDOW has no scroll bar,
3125 create one. */
3126 static void
3127 XTset_vertical_scroll_bar (window, portion, whole, position)
3128 struct window *window;
3129 int portion, whole, position;
3130 {
3131 FRAME_PTR f = XFRAME (WINDOW_FRAME (window));
3132 int top = XINT (window->top);
3133 int left = WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window);
3134 int height = WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window);
3135
3136 /* Where should this scroll bar be, pixelwise? */
3137 int pixel_top = CHAR_TO_PIXEL_ROW (f, top);
3138 int pixel_left = CHAR_TO_PIXEL_COL (f, left);
3139 int pixel_width
3140 = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0
3141 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f)
3142 : (FRAME_SCROLL_BAR_COLS (f) * FONT_WIDTH (f->output_data.x->font)));
3143 int pixel_height = VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f, height);
3144
3145 struct scroll_bar *bar;
3146
3147 /* Does the scroll bar exist yet? */
3148 if (NILP (window->vertical_scroll_bar))
3149 bar = x_scroll_bar_create (window,
3150 pixel_top, pixel_left,
3151 pixel_width, pixel_height);
3152 else
3153 {
3154 /* It may just need to be moved and resized. */
3155 bar = XSCROLL_BAR (window->vertical_scroll_bar);
3156 x_scroll_bar_move (bar, pixel_top, pixel_left, pixel_width, pixel_height);
3157 }
3158
3159 /* Set the scroll bar's current state, unless we're currently being
3160 dragged. */
3161 if (NILP (bar->dragging))
3162 {
3163 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, pixel_height);
3164
3165 if (whole == 0)
3166 x_scroll_bar_set_handle (bar, 0, top_range, 0);
3167 else
3168 {
3169 int start = ((double) position * top_range) / whole;
3170 int end = ((double) (position + portion) * top_range) / whole;
3171
3172 x_scroll_bar_set_handle (bar, start, end, 0);
3173 }
3174 }
3175
3176 XSETVECTOR (window->vertical_scroll_bar, bar);
3177 }
3178
3179
3180 /* The following three hooks are used when we're doing a thorough
3181 redisplay of the frame. We don't explicitly know which scroll bars
3182 are going to be deleted, because keeping track of when windows go
3183 away is a real pain - "Can you say set-window-configuration, boys
3184 and girls?" Instead, we just assert at the beginning of redisplay
3185 that *all* scroll bars are to be removed, and then save a scroll bar
3186 from the fiery pit when we actually redisplay its window. */
3187
3188 /* Arrange for all scroll bars on FRAME to be removed at the next call
3189 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
3190 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
3191 static void
3192 XTcondemn_scroll_bars (frame)
3193 FRAME_PTR frame;
3194 {
3195 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
3196 while (! NILP (FRAME_SCROLL_BARS (frame)))
3197 {
3198 Lisp_Object bar;
3199 bar = FRAME_SCROLL_BARS (frame);
3200 FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next;
3201 XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame);
3202 XSCROLL_BAR (bar)->prev = Qnil;
3203 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame)))
3204 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar;
3205 FRAME_CONDEMNED_SCROLL_BARS (frame) = bar;
3206 }
3207 }
3208
3209 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
3210 Note that WINDOW isn't necessarily condemned at all. */
3211 static void
3212 XTredeem_scroll_bar (window)
3213 struct window *window;
3214 {
3215 struct scroll_bar *bar;
3216
3217 /* We can't redeem this window's scroll bar if it doesn't have one. */
3218 if (NILP (window->vertical_scroll_bar))
3219 abort ();
3220
3221 bar = XSCROLL_BAR (window->vertical_scroll_bar);
3222
3223 /* Unlink it from the condemned list. */
3224 {
3225 FRAME_PTR f = XFRAME (WINDOW_FRAME (window));
3226
3227 if (NILP (bar->prev))
3228 {
3229 /* If the prev pointer is nil, it must be the first in one of
3230 the lists. */
3231 if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar))
3232 /* It's not condemned. Everything's fine. */
3233 return;
3234 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f),
3235 window->vertical_scroll_bar))
3236 FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next;
3237 else
3238 /* If its prev pointer is nil, it must be at the front of
3239 one or the other! */
3240 abort ();
3241 }
3242 else
3243 XSCROLL_BAR (bar->prev)->next = bar->next;
3244
3245 if (! NILP (bar->next))
3246 XSCROLL_BAR (bar->next)->prev = bar->prev;
3247
3248 bar->next = FRAME_SCROLL_BARS (f);
3249 bar->prev = Qnil;
3250 XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
3251 if (! NILP (bar->next))
3252 XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
3253 }
3254 }
3255
3256 /* Remove all scroll bars on FRAME that haven't been saved since the
3257 last call to `*condemn_scroll_bars_hook'. */
3258 static void
3259 XTjudge_scroll_bars (f)
3260 FRAME_PTR f;
3261 {
3262 Lisp_Object bar, next;
3263
3264 bar = FRAME_CONDEMNED_SCROLL_BARS (f);
3265
3266 /* Clear out the condemned list now so we won't try to process any
3267 more events on the hapless scroll bars. */
3268 FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil;
3269
3270 for (; ! NILP (bar); bar = next)
3271 {
3272 struct scroll_bar *b = XSCROLL_BAR (bar);
3273
3274 x_scroll_bar_remove (b);
3275
3276 next = b->next;
3277 b->next = b->prev = Qnil;
3278 }
3279
3280 /* Now there should be no references to the condemned scroll bars,
3281 and they should get garbage-collected. */
3282 }
3283
3284
3285 /* Handle an Expose or GraphicsExpose event on a scroll bar.
3286
3287 This may be called from a signal handler, so we have to ignore GC
3288 mark bits. */
3289 static void
3290 x_scroll_bar_expose (bar, event)
3291 struct scroll_bar *bar;
3292 XEvent *event;
3293 {
3294 Window w = SCROLL_BAR_X_WINDOW (bar);
3295 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3296 GC gc = f->output_data.x->normal_gc;
3297 int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM;
3298
3299 BLOCK_INPUT;
3300
3301 x_scroll_bar_set_handle (bar, XINT (bar->start), XINT (bar->end), 1);
3302
3303 /* Draw a one-pixel border just inside the edges of the scroll bar. */
3304 XDrawRectangle (FRAME_X_DISPLAY (f), w, gc,
3305
3306 /* x, y, width, height */
3307 0, 0,
3308 XINT (bar->width) - 1 - width_trim - width_trim,
3309 XINT (bar->height) - 1);
3310
3311 UNBLOCK_INPUT;
3312 }
3313
3314 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
3315 is set to something other than no_event, it is enqueued.
3316
3317 This may be called from a signal handler, so we have to ignore GC
3318 mark bits. */
3319 static void
3320 x_scroll_bar_handle_click (bar, event, emacs_event)
3321 struct scroll_bar *bar;
3322 XEvent *event;
3323 struct input_event *emacs_event;
3324 {
3325 if (! GC_WINDOWP (bar->window))
3326 abort ();
3327
3328 emacs_event->kind = scroll_bar_click;
3329 emacs_event->code = event->xbutton.button - Button1;
3330 emacs_event->modifiers
3331 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
3332 (XFRAME (WINDOW_FRAME (XWINDOW (bar->window)))),
3333 event->xbutton.state)
3334 | (event->type == ButtonRelease
3335 ? up_modifier
3336 : down_modifier));
3337 emacs_event->frame_or_window = bar->window;
3338 emacs_event->timestamp = event->xbutton.time;
3339 {
3340 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3341 int internal_height
3342 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height));
3343 int top_range
3344 = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
3345 int y = event->xbutton.y - VERTICAL_SCROLL_BAR_TOP_BORDER;
3346
3347 if (y < 0) y = 0;
3348 if (y > top_range) y = top_range;
3349
3350 if (y < XINT (bar->start))
3351 emacs_event->part = scroll_bar_above_handle;
3352 else if (y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE)
3353 emacs_event->part = scroll_bar_handle;
3354 else
3355 emacs_event->part = scroll_bar_below_handle;
3356
3357 /* Just because the user has clicked on the handle doesn't mean
3358 they want to drag it. Lisp code needs to be able to decide
3359 whether or not we're dragging. */
3360 #if 0
3361 /* If the user has just clicked on the handle, record where they're
3362 holding it. */
3363 if (event->type == ButtonPress
3364 && emacs_event->part == scroll_bar_handle)
3365 XSETINT (bar->dragging, y - XINT (bar->start));
3366 #endif
3367
3368 /* If the user has released the handle, set it to its final position. */
3369 if (event->type == ButtonRelease
3370 && ! NILP (bar->dragging))
3371 {
3372 int new_start = y - XINT (bar->dragging);
3373 int new_end = new_start + (XINT (bar->end) - XINT (bar->start));
3374
3375 x_scroll_bar_set_handle (bar, new_start, new_end, 0);
3376 bar->dragging = Qnil;
3377 }
3378
3379 /* Same deal here as the other #if 0. */
3380 #if 0
3381 /* Clicks on the handle are always reported as occurring at the top of
3382 the handle. */
3383 if (emacs_event->part == scroll_bar_handle)
3384 emacs_event->x = bar->start;
3385 else
3386 XSETINT (emacs_event->x, y);
3387 #else
3388 XSETINT (emacs_event->x, y);
3389 #endif
3390
3391 XSETINT (emacs_event->y, top_range);
3392 }
3393 }
3394
3395 /* Handle some mouse motion while someone is dragging the scroll bar.
3396
3397 This may be called from a signal handler, so we have to ignore GC
3398 mark bits. */
3399 static void
3400 x_scroll_bar_note_movement (bar, event)
3401 struct scroll_bar *bar;
3402 XEvent *event;
3403 {
3404 FRAME_PTR f = XFRAME (XWINDOW (bar->window)->frame);
3405
3406 last_mouse_movement_time = event->xmotion.time;
3407
3408 f->mouse_moved = 1;
3409 XSETVECTOR (last_mouse_scroll_bar, bar);
3410
3411 /* If we're dragging the bar, display it. */
3412 if (! GC_NILP (bar->dragging))
3413 {
3414 /* Where should the handle be now? */
3415 int new_start = event->xmotion.y - XINT (bar->dragging);
3416
3417 if (new_start != XINT (bar->start))
3418 {
3419 int new_end = new_start + (XINT (bar->end) - XINT (bar->start));
3420
3421 x_scroll_bar_set_handle (bar, new_start, new_end, 0);
3422 }
3423 }
3424 }
3425
3426 /* Return information to the user about the current position of the mouse
3427 on the scroll bar. */
3428 static void
3429 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
3430 FRAME_PTR *fp;
3431 Lisp_Object *bar_window;
3432 enum scroll_bar_part *part;
3433 Lisp_Object *x, *y;
3434 unsigned long *time;
3435 {
3436 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
3437 Window w = SCROLL_BAR_X_WINDOW (bar);
3438 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3439 int win_x, win_y;
3440 Window dummy_window;
3441 int dummy_coord;
3442 unsigned int dummy_mask;
3443
3444 BLOCK_INPUT;
3445
3446 /* Get the mouse's position relative to the scroll bar window, and
3447 report that. */
3448 if (! XQueryPointer (FRAME_X_DISPLAY (f), w,
3449
3450 /* Root, child, root x and root y. */
3451 &dummy_window, &dummy_window,
3452 &dummy_coord, &dummy_coord,
3453
3454 /* Position relative to scroll bar. */
3455 &win_x, &win_y,
3456
3457 /* Mouse buttons and modifier keys. */
3458 &dummy_mask))
3459 ;
3460 else
3461 {
3462 int inside_height
3463 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height));
3464 int top_range
3465 = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
3466
3467 win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER;
3468
3469 if (! NILP (bar->dragging))
3470 win_y -= XINT (bar->dragging);
3471
3472 if (win_y < 0)
3473 win_y = 0;
3474 if (win_y > top_range)
3475 win_y = top_range;
3476
3477 *fp = f;
3478 *bar_window = bar->window;
3479
3480 if (! NILP (bar->dragging))
3481 *part = scroll_bar_handle;
3482 else if (win_y < XINT (bar->start))
3483 *part = scroll_bar_above_handle;
3484 else if (win_y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE)
3485 *part = scroll_bar_handle;
3486 else
3487 *part = scroll_bar_below_handle;
3488
3489 XSETINT (*x, win_y);
3490 XSETINT (*y, top_range);
3491
3492 f->mouse_moved = 0;
3493 last_mouse_scroll_bar = Qnil;
3494 }
3495
3496 *time = last_mouse_movement_time;
3497
3498 UNBLOCK_INPUT;
3499 }
3500
3501
3502 /* The screen has been cleared so we may have changed foreground or
3503 background colors, and the scroll bars may need to be redrawn.
3504 Clear out the scroll bars, and ask for expose events, so we can
3505 redraw them. */
3506
3507 x_scroll_bar_clear (f)
3508 FRAME_PTR f;
3509 {
3510 Lisp_Object bar;
3511
3512 /* We can have scroll bars even if this is 0,
3513 if we just turned off scroll bar mode.
3514 But in that case we should not clear them. */
3515 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3516 for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar);
3517 bar = XSCROLL_BAR (bar)->next)
3518 XClearArea (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)),
3519 0, 0, 0, 0, True);
3520 }
3521
3522 /* This processes Expose events from the menubar specific X event
3523 loop in xmenu.c. This allows to redisplay the frame if necessary
3524 when handling menubar or popup items. */
3525
3526 void
3527 process_expose_from_menu (event)
3528 XEvent event;
3529 {
3530 FRAME_PTR f;
3531 struct x_display_info *dpyinfo;
3532
3533 BLOCK_INPUT;
3534
3535 dpyinfo = x_display_info_for_display (event.xexpose.display);
3536 f = x_window_to_frame (dpyinfo, event.xexpose.window);
3537 if (f)
3538 {
3539 if (f->async_visible == 0)
3540 {
3541 f->async_visible = 1;
3542 f->async_iconified = 0;
3543 f->output_data.x->has_been_visible = 1;
3544 SET_FRAME_GARBAGED (f);
3545 }
3546 else
3547 {
3548 dumprectangle (x_window_to_frame (dpyinfo, event.xexpose.window),
3549 event.xexpose.x, event.xexpose.y,
3550 event.xexpose.width, event.xexpose.height);
3551 }
3552 }
3553 else
3554 {
3555 struct scroll_bar *bar
3556 = x_window_to_scroll_bar (event.xexpose.window);
3557
3558 if (bar)
3559 x_scroll_bar_expose (bar, &event);
3560 }
3561
3562 UNBLOCK_INPUT;
3563 }
3564 \f
3565 /* Define a queue to save up SelectionRequest events for later handling. */
3566
3567 struct selection_event_queue
3568 {
3569 XEvent event;
3570 struct selection_event_queue *next;
3571 };
3572
3573 static struct selection_event_queue *queue;
3574
3575 /* Nonzero means queue up certain events--don't process them yet. */
3576 static int x_queue_selection_requests;
3577
3578 /* Queue up an X event *EVENT, to be processed later. */
3579
3580 static void
3581 x_queue_event (f, event)
3582 FRAME_PTR f;
3583 XEvent *event;
3584 {
3585 struct selection_event_queue *queue_tmp
3586 = (struct selection_event_queue *) malloc (sizeof (struct selection_event_queue));
3587
3588 if (queue_tmp != NULL)
3589 {
3590 queue_tmp->event = *event;
3591 queue_tmp->next = queue;
3592 queue = queue_tmp;
3593 }
3594 }
3595
3596 /* Take all the queued events and put them back
3597 so that they get processed afresh. */
3598
3599 static void
3600 x_unqueue_events (display)
3601 Display *display;
3602 {
3603 while (queue != NULL)
3604 {
3605 struct selection_event_queue *queue_tmp = queue;
3606 XPutBackEvent (display, &queue_tmp->event);
3607 queue = queue_tmp->next;
3608 free ((char *)queue_tmp);
3609 }
3610 }
3611
3612 /* Start queuing SelectionRequest events. */
3613
3614 void
3615 x_start_queuing_selection_requests (display)
3616 Display *display;
3617 {
3618 x_queue_selection_requests++;
3619 }
3620
3621 /* Stop queuing SelectionRequest events. */
3622
3623 void
3624 x_stop_queuing_selection_requests (display)
3625 Display *display;
3626 {
3627 x_queue_selection_requests--;
3628 x_unqueue_events (display);
3629 }
3630 \f
3631 /* The main X event-reading loop - XTread_socket. */
3632
3633 /* Timestamp of enter window event. This is only used by XTread_socket,
3634 but we have to put it out here, since static variables within functions
3635 sometimes don't work. */
3636 static Time enter_timestamp;
3637
3638 /* This holds the state XLookupString needs to implement dead keys
3639 and other tricks known as "compose processing". _X Window System_
3640 says that a portable program can't use this, but Stephen Gildea assures
3641 me that letting the compiler initialize it to zeros will work okay.
3642
3643 This must be defined outside of XTread_socket, for the same reasons
3644 given for enter_timestamp, above. */
3645 static XComposeStatus compose_status;
3646
3647 /* Record the last 100 characters stored
3648 to help debug the loss-of-chars-during-GC problem. */
3649 static int temp_index;
3650 static short temp_buffer[100];
3651
3652 /* Set this to nonzero to fake an "X I/O error"
3653 on a particular display. */
3654 struct x_display_info *XTread_socket_fake_io_error;
3655
3656 /* When we find no input here, we occasionally do a no-op command
3657 to verify that the X server is still running and we can still talk with it.
3658 We try all the open displays, one by one.
3659 This variable is used for cycling thru the displays. */
3660 static struct x_display_info *next_noop_dpyinfo;
3661
3662 #define SET_SAVED_MENU_EVENT(size) { \
3663 if (f->output_data.x->saved_menu_event == 0) \
3664 f->output_data.x->saved_menu_event = (XEvent*)xmalloc (sizeof (XEvent)); \
3665 bcopy (&event, f->output_data.x->saved_menu_event, size); \
3666 if (numchars >= 1) \
3667 { \
3668 bufp->kind = menu_bar_activate_event; \
3669 XSETFRAME (bufp->frame_or_window, f); \
3670 bufp++; \
3671 count++; \
3672 numchars--; \
3673 } \
3674 }
3675 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
3676 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
3677
3678 /* Read events coming from the X server.
3679 This routine is called by the SIGIO handler.
3680 We return as soon as there are no more events to be read.
3681
3682 Events representing keys are stored in buffer BUFP,
3683 which can hold up to NUMCHARS characters.
3684 We return the number of characters stored into the buffer,
3685 thus pretending to be `read'.
3686
3687 EXPECTED is nonzero if the caller knows input is available. */
3688
3689 int
3690 XTread_socket (sd, bufp, numchars, expected)
3691 register int sd;
3692 /* register */ struct input_event *bufp;
3693 /* register */ int numchars;
3694 int expected;
3695 {
3696 int count = 0;
3697 int nbytes = 0;
3698 int mask;
3699 int items_pending; /* How many items are in the X queue. */
3700 XEvent event;
3701 struct frame *f;
3702 int event_found = 0;
3703 int prefix;
3704 Lisp_Object part;
3705 struct x_display_info *dpyinfo;
3706 #ifdef HAVE_X_I18N
3707 Status status_return;
3708 #endif
3709
3710 if (interrupt_input_blocked)
3711 {
3712 interrupt_input_pending = 1;
3713 return -1;
3714 }
3715
3716 interrupt_input_pending = 0;
3717 BLOCK_INPUT;
3718
3719 /* So people can tell when we have read the available input. */
3720 input_signal_count++;
3721
3722 if (numchars <= 0)
3723 abort (); /* Don't think this happens. */
3724
3725 /* Find the display we are supposed to read input for.
3726 It's the one communicating on descriptor SD. */
3727 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
3728 {
3729 #if 0 /* This ought to be unnecessary; let's verify it. */
3730 #ifdef FIOSNBIO
3731 /* If available, Xlib uses FIOSNBIO to make the socket
3732 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3733 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
3734 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3735 fcntl (dpyinfo->connection, F_SETFL, 0);
3736 #endif /* ! defined (FIOSNBIO) */
3737 #endif
3738
3739 #if 0 /* This code can't be made to work, with multiple displays,
3740 and appears not to be used on any system any more.
3741 Also keyboard.c doesn't turn O_NDELAY on and off
3742 for X connections. */
3743 #ifndef SIGIO
3744 #ifndef HAVE_SELECT
3745 if (! (fcntl (dpyinfo->connection, F_GETFL, 0) & O_NDELAY))
3746 {
3747 extern int read_alarm_should_throw;
3748 read_alarm_should_throw = 1;
3749 XPeekEvent (dpyinfo->display, &event);
3750 read_alarm_should_throw = 0;
3751 }
3752 #endif /* HAVE_SELECT */
3753 #endif /* SIGIO */
3754 #endif
3755
3756 /* For debugging, this gives a way to fake an I/O error. */
3757 if (dpyinfo == XTread_socket_fake_io_error)
3758 {
3759 XTread_socket_fake_io_error = 0;
3760 x_io_error_quitter (dpyinfo->display);
3761 }
3762
3763 while (XPending (dpyinfo->display) != 0)
3764 {
3765 #ifdef USE_X_TOOLKIT
3766 /* needed to raise Motif submenus */
3767 XtAppNextEvent (Xt_app_con, &event);
3768 #else
3769 XNextEvent (dpyinfo->display, &event);
3770 #endif
3771 #ifdef HAVE_X_I18N
3772 {
3773 struct frame *f1 = x_any_window_to_frame (dpyinfo,
3774 &event.xclient.window);
3775 /* The necessity of the following line took me
3776 a full work-day to decipher from the docs!! */
3777 if (f1 != 0 && FRAME_XIC (f1) && XFilterEvent (&event, None))
3778 break;
3779 }
3780 #endif
3781 event_found = 1;
3782
3783 switch (event.type)
3784 {
3785 case ClientMessage:
3786 {
3787 if (event.xclient.message_type
3788 == dpyinfo->Xatom_wm_protocols
3789 && event.xclient.format == 32)
3790 {
3791 if (event.xclient.data.l[0]
3792 == dpyinfo->Xatom_wm_take_focus)
3793 {
3794 f = x_window_to_frame (dpyinfo, event.xclient.window);
3795 /* Since we set WM_TAKE_FOCUS, we must call
3796 XSetInputFocus explicitly. But not if f is null,
3797 since that might be an event for a deleted frame. */
3798 #ifdef HAVE_X_I18N
3799 /* Not quite sure this is needed -pd */
3800 if (f)
3801 XSetICFocus (FRAME_XIC (f));
3802 #endif
3803 if (f)
3804 XSetInputFocus (event.xclient.display,
3805 event.xclient.window,
3806 RevertToPointerRoot,
3807 event.xclient.data.l[1]);
3808 /* Not certain about handling scroll bars here */
3809 }
3810 else if (event.xclient.data.l[0]
3811 == dpyinfo->Xatom_wm_save_yourself)
3812 {
3813 /* Save state modify the WM_COMMAND property to
3814 something which can reinstate us. This notifies
3815 the session manager, who's looking for such a
3816 PropertyNotify. Can restart processing when
3817 a keyboard or mouse event arrives. */
3818 if (numchars > 0)
3819 {
3820 f = x_top_window_to_frame (dpyinfo,
3821 event.xclient.window);
3822
3823 /* This is just so we only give real data once
3824 for a single Emacs process. */
3825 if (f == selected_frame)
3826 XSetCommand (FRAME_X_DISPLAY (f),
3827 event.xclient.window,
3828 initial_argv, initial_argc);
3829 else if (f)
3830 XSetCommand (FRAME_X_DISPLAY (f),
3831 event.xclient.window,
3832 0, 0);
3833 }
3834 }
3835 else if (event.xclient.data.l[0]
3836 == dpyinfo->Xatom_wm_delete_window)
3837 {
3838 struct frame *f
3839 = x_any_window_to_frame (dpyinfo,
3840 event.xclient.window);
3841
3842 if (f)
3843 {
3844 if (numchars == 0)
3845 abort ();
3846
3847 bufp->kind = delete_window_event;
3848 XSETFRAME (bufp->frame_or_window, f);
3849 bufp++;
3850
3851 count += 1;
3852 numchars -= 1;
3853 }
3854 }
3855 }
3856 else if (event.xclient.message_type
3857 == dpyinfo->Xatom_wm_configure_denied)
3858 {
3859 }
3860 else if (event.xclient.message_type
3861 == dpyinfo->Xatom_wm_window_moved)
3862 {
3863 int new_x, new_y;
3864 struct frame *f
3865 = x_window_to_frame (dpyinfo, event.xclient.window);
3866
3867 new_x = event.xclient.data.s[0];
3868 new_y = event.xclient.data.s[1];
3869
3870 if (f)
3871 {
3872 f->output_data.x->left_pos = new_x;
3873 f->output_data.x->top_pos = new_y;
3874 }
3875 }
3876 #ifdef HACK_EDITRES
3877 else if (event.xclient.message_type
3878 == dpyinfo->Xatom_editres)
3879 {
3880 struct frame *f
3881 = x_any_window_to_frame (dpyinfo, event.xclient.window);
3882 _XEditResCheckMessages (f->output_data.x->widget, NULL,
3883 &event, NULL);
3884 }
3885 #endif /* HACK_EDITRES */
3886 }
3887 break;
3888
3889 case SelectionNotify:
3890 #ifdef USE_X_TOOLKIT
3891 if (! x_window_to_frame (dpyinfo, event.xselection.requestor))
3892 goto OTHER;
3893 #endif /* not USE_X_TOOLKIT */
3894 x_handle_selection_notify (&event);
3895 break;
3896
3897 case SelectionClear: /* Someone has grabbed ownership. */
3898 #ifdef USE_X_TOOLKIT
3899 if (! x_window_to_frame (dpyinfo, event.xselectionclear.window))
3900 goto OTHER;
3901 #endif /* USE_X_TOOLKIT */
3902 {
3903 XSelectionClearEvent *eventp = (XSelectionClearEvent *) &event;
3904
3905 if (numchars == 0)
3906 abort ();
3907
3908 bufp->kind = selection_clear_event;
3909 SELECTION_EVENT_DISPLAY (bufp) = eventp->display;
3910 SELECTION_EVENT_SELECTION (bufp) = eventp->selection;
3911 SELECTION_EVENT_TIME (bufp) = eventp->time;
3912 bufp->frame_or_window = Qnil;
3913 bufp++;
3914
3915 count += 1;
3916 numchars -= 1;
3917 }
3918 break;
3919
3920 case SelectionRequest: /* Someone wants our selection. */
3921 #ifdef USE_X_TOOLKIT
3922 if (!x_window_to_frame (dpyinfo, event.xselectionrequest.owner))
3923 goto OTHER;
3924 #endif /* USE_X_TOOLKIT */
3925 if (x_queue_selection_requests)
3926 x_queue_event (x_window_to_frame (dpyinfo, event.xselectionrequest.owner),
3927 &event);
3928 else
3929 {
3930 XSelectionRequestEvent *eventp = (XSelectionRequestEvent *) &event;
3931
3932 if (numchars == 0)
3933 abort ();
3934
3935 bufp->kind = selection_request_event;
3936 SELECTION_EVENT_DISPLAY (bufp) = eventp->display;
3937 SELECTION_EVENT_REQUESTOR (bufp) = eventp->requestor;
3938 SELECTION_EVENT_SELECTION (bufp) = eventp->selection;
3939 SELECTION_EVENT_TARGET (bufp) = eventp->target;
3940 SELECTION_EVENT_PROPERTY (bufp) = eventp->property;
3941 SELECTION_EVENT_TIME (bufp) = eventp->time;
3942 bufp->frame_or_window = Qnil;
3943 bufp++;
3944
3945 count += 1;
3946 numchars -= 1;
3947 }
3948 break;
3949
3950 case PropertyNotify:
3951 #ifdef USE_X_TOOLKIT
3952 if (!x_any_window_to_frame (dpyinfo, event.xproperty.window))
3953 goto OTHER;
3954 #endif /* not USE_X_TOOLKIT */
3955 x_handle_property_notify (&event);
3956 break;
3957
3958 case ReparentNotify:
3959 f = x_top_window_to_frame (dpyinfo, event.xreparent.window);
3960 if (f)
3961 {
3962 int x, y;
3963 f->output_data.x->parent_desc = event.xreparent.parent;
3964 x_real_positions (f, &x, &y);
3965 f->output_data.x->left_pos = x;
3966 f->output_data.x->top_pos = y;
3967 }
3968 break;
3969
3970 case Expose:
3971 f = x_window_to_frame (dpyinfo, event.xexpose.window);
3972 if (f)
3973 {
3974 if (f->async_visible == 0)
3975 {
3976 f->async_visible = 1;
3977 f->async_iconified = 0;
3978 f->output_data.x->has_been_visible = 1;
3979 SET_FRAME_GARBAGED (f);
3980 }
3981 else
3982 dumprectangle (x_window_to_frame (dpyinfo,
3983 event.xexpose.window),
3984 event.xexpose.x, event.xexpose.y,
3985 event.xexpose.width, event.xexpose.height);
3986 }
3987 else
3988 {
3989 struct scroll_bar *bar
3990 = x_window_to_scroll_bar (event.xexpose.window);
3991
3992 if (bar)
3993 x_scroll_bar_expose (bar, &event);
3994 #ifdef USE_X_TOOLKIT
3995 else
3996 goto OTHER;
3997 #endif /* USE_X_TOOLKIT */
3998 }
3999 break;
4000
4001 case GraphicsExpose: /* This occurs when an XCopyArea's
4002 source area was obscured or not
4003 available.*/
4004 f = x_window_to_frame (dpyinfo, event.xgraphicsexpose.drawable);
4005 if (f)
4006 {
4007 dumprectangle (f,
4008 event.xgraphicsexpose.x, event.xgraphicsexpose.y,
4009 event.xgraphicsexpose.width,
4010 event.xgraphicsexpose.height);
4011 }
4012 #ifdef USE_X_TOOLKIT
4013 else
4014 goto OTHER;
4015 #endif /* USE_X_TOOLKIT */
4016 break;
4017
4018 case NoExpose: /* This occurs when an XCopyArea's
4019 source area was completely
4020 available */
4021 break;
4022
4023 case UnmapNotify:
4024 f = x_top_window_to_frame (dpyinfo, event.xunmap.window);
4025 if (f) /* F may no longer exist if
4026 the frame was deleted. */
4027 {
4028 /* While a frame is unmapped, display generation is
4029 disabled; you don't want to spend time updating a
4030 display that won't ever be seen. */
4031 f->async_visible = 0;
4032 /* We can't distinguish, from the event, whether the window
4033 has become iconified or invisible. So assume, if it
4034 was previously visible, than now it is iconified.
4035 But x_make_frame_invisible clears both
4036 the visible flag and the iconified flag;
4037 and that way, we know the window is not iconified now. */
4038 if (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f))
4039 {
4040 f->async_iconified = 1;
4041
4042 bufp->kind = iconify_event;
4043 XSETFRAME (bufp->frame_or_window, f);
4044 bufp++;
4045 count++;
4046 numchars--;
4047 }
4048 }
4049 goto OTHER;
4050
4051 case MapNotify:
4052 /* We use x_top_window_to_frame because map events can come
4053 for subwindows and they don't mean that the frame is visible. */
4054 f = x_top_window_to_frame (dpyinfo, event.xmap.window);
4055 if (f)
4056 {
4057 f->async_visible = 1;
4058 f->async_iconified = 0;
4059 f->output_data.x->has_been_visible = 1;
4060
4061 /* wait_reading_process_input will notice this and update
4062 the frame's display structures. */
4063 SET_FRAME_GARBAGED (f);
4064
4065 if (f->iconified)
4066 {
4067 bufp->kind = deiconify_event;
4068 XSETFRAME (bufp->frame_or_window, f);
4069 bufp++;
4070 count++;
4071 numchars--;
4072 }
4073 else if (! NILP (Vframe_list)
4074 && ! NILP (XCONS (Vframe_list)->cdr))
4075 /* Force a redisplay sooner or later
4076 to update the frame titles
4077 in case this is the second frame. */
4078 record_asynch_buffer_change ();
4079 }
4080 goto OTHER;
4081
4082 /* Turn off processing if we become fully obscured. */
4083 case VisibilityNotify:
4084 break;
4085
4086 case KeyPress:
4087 f = x_any_window_to_frame (dpyinfo, event.xkey.window);
4088
4089 if (f != 0)
4090 {
4091 KeySym keysym, orig_keysym;
4092 /* al%imercury@uunet.uu.net says that making this 81 instead of
4093 80 fixed a bug whereby meta chars made his Emacs hang. */
4094 unsigned char copy_buffer[81];
4095 int modifiers;
4096
4097 #if 0 /* This was how we made f10 work in Motif.
4098 The drawback is, you can't type at Emacs when the
4099 the mouse is in the menu bar. So it is better to
4100 turn off f10 in Motif and let Emacs handle it. */
4101 #ifdef USE_MOTIF
4102 if (lw_window_is_in_menubar (event.xkey.window,
4103 f->output_data.x->menubar_widget
4104 ))
4105 {
4106 SET_SAVED_KEY_EVENT;
4107 break;
4108 }
4109 #endif /* USE_MOTIF */
4110 #endif /* 0 */
4111
4112 event.xkey.state
4113 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f),
4114 extra_keyboard_modifiers);
4115 modifiers = event.xkey.state;
4116
4117 /* This will have to go some day... */
4118
4119 /* make_lispy_event turns chars into control chars.
4120 Don't do it here because XLookupString is too eager. */
4121 event.xkey.state &= ~ControlMask;
4122 event.xkey.state &= ~(dpyinfo->meta_mod_mask
4123 | dpyinfo->super_mod_mask
4124 | dpyinfo->hyper_mod_mask
4125 | dpyinfo->alt_mod_mask);
4126
4127 /* In case Meta is ComposeCharacter,
4128 clear its status. According to Markus Ehrnsperger
4129 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
4130 this enables ComposeCharacter to work whether or
4131 not it is combined with Meta. */
4132 if (modifiers & dpyinfo->meta_mod_mask)
4133 bzero (&compose_status, sizeof (compose_status));
4134
4135 #ifdef HAVE_X_I18N
4136 if (FRAME_XIC (f))
4137 {
4138 /* The necessity of the following line took me
4139 a full work-day to decipher from the docs!! */
4140 if (XFilterEvent (&event, None))
4141 break;
4142 nbytes = XmbLookupString (FRAME_XIC (f),
4143 &event.xkey, copy_buffer,
4144 80, &keysym,
4145 &status_return);
4146 }
4147 else
4148 nbytes = XLookupString (&event.xkey, copy_buffer,
4149 80, &keysym, &compose_status);
4150 #else
4151 nbytes = XLookupString (&event.xkey, copy_buffer,
4152 80, &keysym, &compose_status);
4153 #endif
4154
4155 orig_keysym = keysym;
4156
4157 if (numchars > 1)
4158 {
4159 if (((keysym >= XK_BackSpace && keysym <= XK_Escape)
4160 || keysym == XK_Delete
4161 #ifdef XK_ISO_Left_Tab
4162 || (keysym >= XK_ISO_Left_Tab && keysym <= XK_ISO_Enter)
4163 #endif
4164 || IsCursorKey (keysym) /* 0xff50 <= x < 0xff60 */
4165 || IsMiscFunctionKey (keysym) /* 0xff60 <= x < VARIES */
4166 #ifdef HPUX
4167 /* This recognizes the "extended function keys".
4168 It seems there's no cleaner way.
4169 Test IsModifierKey to avoid handling mode_switch
4170 incorrectly. */
4171 || ((unsigned) (keysym) >= XK_Select
4172 && (unsigned)(keysym) < XK_KP_Space)
4173 #endif
4174 #ifdef XK_dead_circumflex
4175 || orig_keysym == XK_dead_circumflex
4176 #endif
4177 #ifdef XK_dead_grave
4178 || orig_keysym == XK_dead_grave
4179 #endif
4180 #ifdef XK_dead_tilde
4181 || orig_keysym == XK_dead_tilde
4182 #endif
4183 #ifdef XK_dead_diaeresis
4184 || orig_keysym == XK_dead_diaeresis
4185 #endif
4186 #ifdef XK_dead_macron
4187 || orig_keysym == XK_dead_macron
4188 #endif
4189 #ifdef XK_dead_degree
4190 || orig_keysym == XK_dead_degree
4191 #endif
4192 #ifdef XK_dead_acute
4193 || orig_keysym == XK_dead_acute
4194 #endif
4195 #ifdef XK_dead_cedilla
4196 || orig_keysym == XK_dead_cedilla
4197 #endif
4198 #ifdef XK_dead_breve
4199 || orig_keysym == XK_dead_breve
4200 #endif
4201 #ifdef XK_dead_ogonek
4202 || orig_keysym == XK_dead_ogonek
4203 #endif
4204 #ifdef XK_dead_caron
4205 || orig_keysym == XK_dead_caron
4206 #endif
4207 #ifdef XK_dead_doubleacute
4208 || orig_keysym == XK_dead_doubleacute
4209 #endif
4210 #ifdef XK_dead_abovedot
4211 || orig_keysym == XK_dead_abovedot
4212 #endif
4213 || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */
4214 || IsFunctionKey (keysym) /* 0xffbe <= x < 0xffe1 */
4215 /* Any "vendor-specific" key is ok. */
4216 || (orig_keysym & (1 << 28)))
4217 && ! (IsModifierKey (orig_keysym)
4218 #ifndef HAVE_X11R5
4219 #ifdef XK_Mode_switch
4220 || ((unsigned)(orig_keysym) == XK_Mode_switch)
4221 #endif
4222 #ifdef XK_Num_Lock
4223 || ((unsigned)(orig_keysym) == XK_Num_Lock)
4224 #endif
4225 #endif /* not HAVE_X11R5 */
4226 ))
4227 {
4228 if (temp_index == sizeof temp_buffer / sizeof (short))
4229 temp_index = 0;
4230 temp_buffer[temp_index++] = keysym;
4231 bufp->kind = non_ascii_keystroke;
4232 bufp->code = keysym;
4233 XSETFRAME (bufp->frame_or_window, f);
4234 bufp->modifiers
4235 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f),
4236 modifiers);
4237 bufp->timestamp = event.xkey.time;
4238 bufp++;
4239 count++;
4240 numchars--;
4241 }
4242 else if (numchars > nbytes)
4243 {
4244 register int i;
4245
4246 for (i = 0; i < nbytes; i++)
4247 {
4248 if (temp_index == sizeof temp_buffer / sizeof (short))
4249 temp_index = 0;
4250 temp_buffer[temp_index++] = copy_buffer[i];
4251 bufp->kind = ascii_keystroke;
4252 bufp->code = copy_buffer[i];
4253 XSETFRAME (bufp->frame_or_window, f);
4254 bufp->modifiers
4255 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f),
4256 modifiers);
4257 bufp->timestamp = event.xkey.time;
4258 bufp++;
4259 }
4260
4261 count += nbytes;
4262 numchars -= nbytes;
4263 }
4264 else
4265 abort ();
4266 }
4267 else
4268 abort ();
4269 }
4270 goto OTHER;
4271
4272 /* Here's a possible interpretation of the whole
4273 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
4274 FocusIn event, you have to get a FocusOut event before you
4275 relinquish the focus. If you haven't received a FocusIn event,
4276 then a mere LeaveNotify is enough to free you. */
4277
4278 case EnterNotify:
4279 f = x_any_window_to_frame (dpyinfo, event.xcrossing.window);
4280
4281 if (event.xcrossing.focus) /* Entered Window */
4282 {
4283 /* Avoid nasty pop/raise loops. */
4284 if (f && (!(f->auto_raise)
4285 || !(f->auto_lower)
4286 || (event.xcrossing.time - enter_timestamp) > 500))
4287 {
4288 x_new_focus_frame (dpyinfo, f);
4289 enter_timestamp = event.xcrossing.time;
4290 }
4291 }
4292 else if (f == dpyinfo->x_focus_frame)
4293 x_new_focus_frame (dpyinfo, 0);
4294 /* EnterNotify counts as mouse movement,
4295 so update things that depend on mouse position. */
4296 if (f)
4297 note_mouse_movement (f, &event.xmotion);
4298 goto OTHER;
4299
4300 case FocusIn:
4301 f = x_any_window_to_frame (dpyinfo, event.xfocus.window);
4302 if (event.xfocus.detail != NotifyPointer)
4303 dpyinfo->x_focus_event_frame = f;
4304 if (f)
4305 x_new_focus_frame (dpyinfo, f);
4306
4307 #ifdef HAVE_X_I18N
4308 if (f && FRAME_XIC (f))
4309 XSetICFocus (FRAME_XIC (f));
4310 #endif
4311
4312 goto OTHER;
4313
4314 case LeaveNotify:
4315 f = x_top_window_to_frame (dpyinfo, event.xcrossing.window);
4316 if (f)
4317 {
4318 if (f == dpyinfo->mouse_face_mouse_frame)
4319 /* If we move outside the frame,
4320 then we're certainly no longer on any text in the frame. */
4321 clear_mouse_face (dpyinfo);
4322
4323 if (event.xcrossing.focus)
4324 x_mouse_leave (dpyinfo);
4325 else
4326 {
4327 if (f == dpyinfo->x_focus_event_frame)
4328 dpyinfo->x_focus_event_frame = 0;
4329 if (f == dpyinfo->x_focus_frame)
4330 x_new_focus_frame (dpyinfo, 0);
4331 }
4332 }
4333 goto OTHER;
4334
4335 case FocusOut:
4336 f = x_any_window_to_frame (dpyinfo, event.xfocus.window);
4337 if (event.xfocus.detail != NotifyPointer
4338 && f == dpyinfo->x_focus_event_frame)
4339 dpyinfo->x_focus_event_frame = 0;
4340 if (f && f == dpyinfo->x_focus_frame)
4341 x_new_focus_frame (dpyinfo, 0);
4342
4343 #ifdef HAVE_X_I18N
4344 if (f && FRAME_XIC (f))
4345 XUnsetICFocus (FRAME_XIC (f));
4346 #endif
4347
4348 goto OTHER;
4349
4350 case MotionNotify:
4351 {
4352 if (dpyinfo->grabbed && last_mouse_frame
4353 && FRAME_LIVE_P (last_mouse_frame))
4354 f = last_mouse_frame;
4355 else
4356 f = x_window_to_frame (dpyinfo, event.xmotion.window);
4357 if (f)
4358 note_mouse_movement (f, &event.xmotion);
4359 else
4360 {
4361 struct scroll_bar *bar
4362 = x_window_to_scroll_bar (event.xmotion.window);
4363
4364 if (bar)
4365 x_scroll_bar_note_movement (bar, &event);
4366
4367 /* If we move outside the frame,
4368 then we're certainly no longer on any text in the frame. */
4369 clear_mouse_face (dpyinfo);
4370 }
4371 }
4372 goto OTHER;
4373
4374 case ConfigureNotify:
4375 f = x_top_window_to_frame (dpyinfo, event.xconfigure.window);
4376 if (f)
4377 {
4378 #ifndef USE_X_TOOLKIT
4379 /* In the toolkit version, change_frame_size
4380 is called by the code that handles resizing
4381 of the EmacsFrame widget. */
4382
4383 int rows = PIXEL_TO_CHAR_HEIGHT (f, event.xconfigure.height);
4384 int columns = PIXEL_TO_CHAR_WIDTH (f, event.xconfigure.width);
4385
4386 /* Even if the number of character rows and columns has
4387 not changed, the font size may have changed, so we need
4388 to check the pixel dimensions as well. */
4389 if (columns != f->width
4390 || rows != f->height
4391 || event.xconfigure.width != f->output_data.x->pixel_width
4392 || event.xconfigure.height != f->output_data.x->pixel_height)
4393 {
4394 change_frame_size (f, rows, columns, 0, 1);
4395 SET_FRAME_GARBAGED (f);
4396 cancel_mouse_face (f);
4397 }
4398 #endif
4399
4400 f->output_data.x->pixel_width = event.xconfigure.width;
4401 f->output_data.x->pixel_height = event.xconfigure.height;
4402
4403 /* What we have now is the position of Emacs's own window.
4404 Convert that to the position of the window manager window. */
4405 x_real_positions (f, &f->output_data.x->left_pos,
4406 &f->output_data.x->top_pos);
4407
4408 if (f->output_data.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window)
4409 {
4410 /* Since the WM decorations come below top_pos now,
4411 we must put them below top_pos in the future. */
4412 f->output_data.x->win_gravity = NorthWestGravity;
4413 x_wm_set_size_hint (f, (long) 0, 0);
4414 }
4415 }
4416 goto OTHER;
4417
4418 case ButtonPress:
4419 case ButtonRelease:
4420 {
4421 /* If we decide we want to generate an event to be seen
4422 by the rest of Emacs, we put it here. */
4423 struct input_event emacs_event;
4424 emacs_event.kind = no_event;
4425
4426 bzero (&compose_status, sizeof (compose_status));
4427
4428 if (dpyinfo->grabbed && last_mouse_frame
4429 && FRAME_LIVE_P (last_mouse_frame))
4430 f = last_mouse_frame;
4431 else
4432 f = x_window_to_frame (dpyinfo, event.xbutton.window);
4433
4434 if (f)
4435 {
4436 if (!dpyinfo->x_focus_frame || f == dpyinfo->x_focus_frame)
4437 construct_mouse_click (&emacs_event, &event, f);
4438 }
4439 else
4440 {
4441 struct scroll_bar *bar
4442 = x_window_to_scroll_bar (event.xbutton.window);
4443
4444 if (bar)
4445 x_scroll_bar_handle_click (bar, &event, &emacs_event);
4446 }
4447
4448 if (event.type == ButtonPress)
4449 {
4450 dpyinfo->grabbed |= (1 << event.xbutton.button);
4451 last_mouse_frame = f;
4452 }
4453 else
4454 {
4455 dpyinfo->grabbed &= ~(1 << event.xbutton.button);
4456 }
4457
4458 if (numchars >= 1 && emacs_event.kind != no_event)
4459 {
4460 bcopy (&emacs_event, bufp, sizeof (struct input_event));
4461 bufp++;
4462 count++;
4463 numchars--;
4464 }
4465
4466 #ifdef USE_X_TOOLKIT
4467 f = x_menubar_window_to_frame (dpyinfo, event.xbutton.window);
4468 /* For a down-event in the menu bar,
4469 don't pass it to Xt right now.
4470 Instead, save it away
4471 and we will pass it to Xt from kbd_buffer_get_event.
4472 That way, we can run some Lisp code first. */
4473 if (f && event.type == ButtonPress
4474 /* Verify the event is really within the menu bar
4475 and not just sent to it due to grabbing. */
4476 && event.xbutton.x >= 0
4477 && event.xbutton.x < f->output_data.x->pixel_width
4478 && event.xbutton.y >= 0
4479 && event.xbutton.y < f->output_data.x->menubar_height
4480 && event.xbutton.same_screen)
4481 {
4482 SET_SAVED_BUTTON_EVENT;
4483 XSETFRAME (last_mouse_press_frame, f);
4484 }
4485 else if (event.type == ButtonPress)
4486 {
4487 last_mouse_press_frame = Qnil;
4488 goto OTHER;
4489 }
4490 #ifdef USE_MOTIF /* This should do not harm for Lucid,
4491 but I am trying to be cautious. */
4492 else if (event.type == ButtonRelease)
4493 {
4494 if (!NILP (last_mouse_press_frame))
4495 {
4496 f = XFRAME (last_mouse_press_frame);
4497 if (f->output_data.x)
4498 {
4499 SET_SAVED_BUTTON_EVENT;
4500 }
4501 }
4502 else
4503 goto OTHER;
4504 }
4505 #endif /* USE_MOTIF */
4506 else
4507 goto OTHER;
4508 #endif /* USE_X_TOOLKIT */
4509 }
4510 break;
4511
4512 case CirculateNotify:
4513 break;
4514 case CirculateRequest:
4515 break;
4516
4517 case MappingNotify:
4518 /* Someone has changed the keyboard mapping - update the
4519 local cache. */
4520 switch (event.xmapping.request)
4521 {
4522 case MappingModifier:
4523 x_find_modifier_meanings (dpyinfo);
4524 /* This is meant to fall through. */
4525 case MappingKeyboard:
4526 XRefreshKeyboardMapping (&event.xmapping);
4527 }
4528 goto OTHER;
4529
4530 default:
4531 OTHER:
4532 #ifdef USE_X_TOOLKIT
4533 BLOCK_INPUT;
4534 XtDispatchEvent (&event);
4535 UNBLOCK_INPUT;
4536 #endif /* USE_X_TOOLKIT */
4537 break;
4538 }
4539 }
4540 }
4541
4542 /* On some systems, an X bug causes Emacs to get no more events
4543 when the window is destroyed. Detect that. (1994.) */
4544 if (! event_found)
4545 {
4546 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
4547 One XNOOP in 100 loops will make Emacs terminate.
4548 B. Bretthauer, 1994 */
4549 x_noop_count++;
4550 if (x_noop_count >= 100)
4551 {
4552 x_noop_count=0;
4553
4554 if (next_noop_dpyinfo == 0)
4555 next_noop_dpyinfo = x_display_list;
4556
4557 XNoOp (next_noop_dpyinfo->display);
4558
4559 /* Each time we get here, cycle through the displays now open. */
4560 next_noop_dpyinfo = next_noop_dpyinfo->next;
4561 }
4562 }
4563
4564 /* If the focus was just given to an autoraising frame,
4565 raise it now. */
4566 /* ??? This ought to be able to handle more than one such frame. */
4567 if (pending_autoraise_frame)
4568 {
4569 x_raise_frame (pending_autoraise_frame);
4570 pending_autoraise_frame = 0;
4571 }
4572
4573 UNBLOCK_INPUT;
4574 return count;
4575 }
4576 \f
4577 /* Drawing the cursor. */
4578
4579
4580 /* Draw a hollow box cursor on frame F at X, Y.
4581 Don't change the inside of the box. */
4582
4583 static void
4584 x_draw_box (f, x, y)
4585 struct frame *f;
4586 int x, y;
4587 {
4588 int left = CHAR_TO_PIXEL_COL (f, x);
4589 int top = CHAR_TO_PIXEL_ROW (f, y);
4590 int width = FONT_WIDTH (f->output_data.x->font);
4591 int height = f->output_data.x->line_height;
4592 int c = FAST_GLYPH_CHAR (f->phys_cursor_glyph);
4593 int charset = CHAR_CHARSET (c);
4594
4595 /* If cursor is on a multi-column character, multiply WIDTH by columns. */
4596 width *= (charset == CHARSET_COMPOSITION
4597 ? cmpchar_table[COMPOSITE_CHAR_ID (c)]->width
4598 : CHARSET_WIDTH (charset));
4599 XDrawRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4600 f->output_data.x->cursor_gc,
4601 left, top, width - 1, height - 1);
4602 }
4603
4604 /* Clear the cursor of frame F to background color,
4605 and mark the cursor as not shown.
4606 This is used when the text where the cursor is
4607 is about to be rewritten. */
4608
4609 static void
4610 clear_cursor (f)
4611 struct frame *f;
4612 {
4613 int mask;
4614
4615 if (! FRAME_VISIBLE_P (f)
4616 || ! f->phys_cursor_on)
4617 return;
4618
4619 x_update_cursor (f, 0);
4620 f->phys_cursor_on = 0;
4621 }
4622
4623 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4624 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4625 glyph drawn. */
4626
4627 static void
4628 x_draw_single_glyph (f, row, column, glyph, highlight)
4629 struct frame *f;
4630 int row, column;
4631 GLYPH glyph;
4632 int highlight;
4633 {
4634 dumpglyphs (f,
4635 CHAR_TO_PIXEL_COL (f, column),
4636 CHAR_TO_PIXEL_ROW (f, row),
4637 &glyph, 1, highlight, 0, NULL);
4638 }
4639
4640 static void
4641 x_display_bar_cursor (f, on, x, y)
4642 struct frame *f;
4643 int on;
4644 int x, y;
4645 {
4646 struct frame_glyphs *current_glyphs = FRAME_CURRENT_GLYPHS (f);
4647
4648 /* This is pointless on invisible frames, and dangerous on garbaged
4649 frames; in the latter case, the frame may be in the midst of
4650 changing its size, and x and y may be off the frame. */
4651 if (! FRAME_VISIBLE_P (f) || FRAME_GARBAGED_P (f))
4652 return;
4653
4654 if (! on && ! f->phys_cursor_on)
4655 return;
4656
4657 /* If there is anything wrong with the current cursor state, remove it. */
4658 if (f->phys_cursor_on
4659 && (!on
4660 || f->phys_cursor_x != x
4661 || f->phys_cursor_y != y
4662 || f->output_data.x->current_cursor != bar_cursor))
4663 {
4664 /* Erase the cursor by redrawing the character underneath it. */
4665 x_draw_single_glyph (f, f->phys_cursor_y, f->phys_cursor_x,
4666 f->phys_cursor_glyph,
4667 current_glyphs->highlight[f->phys_cursor_y]);
4668 f->phys_cursor_on = 0;
4669 }
4670
4671 /* If we now need a cursor in the new place or in the new form, do it so. */
4672 if (on
4673 && (! f->phys_cursor_on
4674 || (f->output_data.x->current_cursor != bar_cursor)))
4675 {
4676 f->phys_cursor_glyph
4677 = ((current_glyphs->enable[y]
4678 && x < current_glyphs->used[y])
4679 ? current_glyphs->glyphs[y][x]
4680 : SPACEGLYPH);
4681 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4682 f->output_data.x->cursor_gc,
4683 CHAR_TO_PIXEL_COL (f, x),
4684 CHAR_TO_PIXEL_ROW (f, y),
4685 max (f->output_data.x->cursor_width, 1),
4686 f->output_data.x->line_height);
4687
4688 f->phys_cursor_x = x;
4689 f->phys_cursor_y = y;
4690 f->phys_cursor_on = 1;
4691
4692 f->output_data.x->current_cursor = bar_cursor;
4693 }
4694
4695 if (updating_frame != f)
4696 XFlush (FRAME_X_DISPLAY (f));
4697 }
4698
4699
4700 /* Turn the displayed cursor of frame F on or off according to ON.
4701 If ON is nonzero, where to put the cursor is specified by X and Y. */
4702
4703 static void
4704 x_display_box_cursor (f, on, x, y)
4705 struct frame *f;
4706 int on;
4707 int x, y;
4708 {
4709 struct frame_glyphs *current_glyphs = FRAME_CURRENT_GLYPHS (f);
4710
4711 /* This is pointless on invisible frames, and dangerous on garbaged
4712 frames; in the latter case, the frame may be in the midst of
4713 changing its size, and x and y may be off the frame. */
4714 if (! FRAME_VISIBLE_P (f) || FRAME_GARBAGED_P (f))
4715 return;
4716
4717 /* If cursor is off and we want it off, return quickly. */
4718 if (!on && ! f->phys_cursor_on)
4719 return;
4720
4721 /* If cursor is currently being shown and we don't want it to be
4722 or it is in the wrong place,
4723 or we want a hollow box and it's not so, (pout!)
4724 erase it. */
4725 if (f->phys_cursor_on
4726 && (!on
4727 || f->phys_cursor_x != x
4728 || f->phys_cursor_y != y
4729 || (f->output_data.x->current_cursor != hollow_box_cursor
4730 && (f != FRAME_X_DISPLAY_INFO (f)->x_highlight_frame))))
4731 {
4732 int mouse_face_here = 0;
4733 struct frame_glyphs *active_glyphs = FRAME_CURRENT_GLYPHS (f);
4734
4735 /* If the cursor is in the mouse face area, redisplay that when
4736 we clear the cursor. */
4737 if (f == FRAME_X_DISPLAY_INFO (f)->mouse_face_mouse_frame
4738 &&
4739 (f->phys_cursor_y > FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_row
4740 || (f->phys_cursor_y == FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_row
4741 && f->phys_cursor_x >= FRAME_X_DISPLAY_INFO (f)->mouse_face_beg_col))
4742 &&
4743 (f->phys_cursor_y < FRAME_X_DISPLAY_INFO (f)->mouse_face_end_row
4744 || (f->phys_cursor_y == FRAME_X_DISPLAY_INFO (f)->mouse_face_end_row
4745 && f->phys_cursor_x < FRAME_X_DISPLAY_INFO (f)->mouse_face_end_col))
4746 /* Don't redraw the cursor's spot in mouse face
4747 if it is at the end of a line (on a newline).
4748 The cursor appears there, but mouse highlighting does not. */
4749 && active_glyphs->used[f->phys_cursor_y] > f->phys_cursor_x)
4750 mouse_face_here = 1;
4751
4752 /* If the font is not as tall as a whole line,
4753 we must explicitly clear the line's whole height. */
4754 if (FONT_HEIGHT (f->output_data.x->font) != f->output_data.x->line_height)
4755 XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4756 CHAR_TO_PIXEL_COL (f, f->phys_cursor_x),
4757 CHAR_TO_PIXEL_ROW (f, f->phys_cursor_y),
4758 FONT_WIDTH (f->output_data.x->font),
4759 f->output_data.x->line_height, False);
4760 /* Erase the cursor by redrawing the character underneath it. */
4761 x_draw_single_glyph (f, f->phys_cursor_y, f->phys_cursor_x,
4762 f->phys_cursor_glyph,
4763 (mouse_face_here
4764 ? 3
4765 : current_glyphs->highlight[f->phys_cursor_y]));
4766 f->phys_cursor_on = 0;
4767 }
4768
4769 /* If we want to show a cursor,
4770 or we want a box cursor and it's not so,
4771 write it in the right place. */
4772 if (on
4773 && (! f->phys_cursor_on
4774 || (f->output_data.x->current_cursor != filled_box_cursor
4775 && f == FRAME_X_DISPLAY_INFO (f)->x_highlight_frame)))
4776 {
4777 f->phys_cursor_glyph
4778 = ((current_glyphs->enable[y]
4779 && x < current_glyphs->used[y])
4780 ? current_glyphs->glyphs[y][x]
4781 : SPACEGLYPH);
4782 if (f != FRAME_X_DISPLAY_INFO (f)->x_highlight_frame)
4783 {
4784 x_draw_box (f, x, y);
4785 f->output_data.x->current_cursor = hollow_box_cursor;
4786 }
4787 else
4788 {
4789 x_draw_single_glyph (f, y, x,
4790 f->phys_cursor_glyph, 2);
4791 f->output_data.x->current_cursor = filled_box_cursor;
4792 }
4793
4794 f->phys_cursor_x = x;
4795 f->phys_cursor_y = y;
4796 f->phys_cursor_on = 1;
4797 }
4798
4799 if (updating_frame != f)
4800 XFlush (FRAME_X_DISPLAY (f));
4801 }
4802
4803 /* Display the cursor on frame F, or clear it, according to ON.
4804 Also set the frame's cursor position to X and Y. */
4805
4806 x_display_cursor (f, on, x, y)
4807 struct frame *f;
4808 int on;
4809 int x, y;
4810 {
4811 BLOCK_INPUT;
4812
4813 if (FRAME_DESIRED_CURSOR (f) == filled_box_cursor)
4814 x_display_box_cursor (f, on, x, y);
4815 else if (FRAME_DESIRED_CURSOR (f) == bar_cursor)
4816 x_display_bar_cursor (f, on, x, y);
4817 else
4818 /* Those are the only two we have implemented! */
4819 abort ();
4820
4821 UNBLOCK_INPUT;
4822 }
4823
4824 /* Display the cursor on frame F, or clear it, according to ON.
4825 Don't change the cursor's position. */
4826
4827 x_update_cursor (f, on)
4828 struct frame *f;
4829 int on;
4830 {
4831 BLOCK_INPUT;
4832
4833 if (FRAME_DESIRED_CURSOR (f) == filled_box_cursor)
4834 x_display_box_cursor (f, on, f->phys_cursor_x, f->phys_cursor_y);
4835 else if (FRAME_DESIRED_CURSOR (f) == bar_cursor)
4836 x_display_bar_cursor (f, on, f->phys_cursor_x, f->phys_cursor_y);
4837 else
4838 /* Those are the only two we have implemented! */
4839 abort ();
4840
4841 UNBLOCK_INPUT;
4842 }
4843 \f
4844 /* Icons. */
4845
4846 /* Refresh bitmap kitchen sink icon for frame F
4847 when we get an expose event for it. */
4848
4849 refreshicon (f)
4850 struct frame *f;
4851 {
4852 /* Normally, the window manager handles this function. */
4853 }
4854
4855 /* Make the x-window of frame F use the gnu icon bitmap. */
4856
4857 int
4858 x_bitmap_icon (f, file)
4859 struct frame *f;
4860 Lisp_Object file;
4861 {
4862 int mask, bitmap_id;
4863 Window icon_window;
4864
4865 if (FRAME_X_WINDOW (f) == 0)
4866 return 1;
4867
4868 /* Free up our existing icon bitmap if any. */
4869 if (f->output_data.x->icon_bitmap > 0)
4870 x_destroy_bitmap (f, f->output_data.x->icon_bitmap);
4871 f->output_data.x->icon_bitmap = 0;
4872
4873 if (STRINGP (file))
4874 bitmap_id = x_create_bitmap_from_file (f, file);
4875 else
4876 {
4877 /* Create the GNU bitmap if necessary. */
4878 if (FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id < 0)
4879 FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id
4880 = x_create_bitmap_from_data (f, gnu_bits,
4881 gnu_width, gnu_height);
4882
4883 /* The first time we create the GNU bitmap,
4884 this increments the refcount one extra time.
4885 As a result, the GNU bitmap is never freed.
4886 That way, we don't have to worry about allocating it again. */
4887 x_reference_bitmap (f, FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id);
4888
4889 bitmap_id = FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id;
4890 }
4891
4892 x_wm_set_icon_pixmap (f, bitmap_id);
4893 f->output_data.x->icon_bitmap = bitmap_id;
4894
4895 return 0;
4896 }
4897
4898
4899 /* Make the x-window of frame F use a rectangle with text.
4900 Use ICON_NAME as the text. */
4901
4902 int
4903 x_text_icon (f, icon_name)
4904 struct frame *f;
4905 char *icon_name;
4906 {
4907 if (FRAME_X_WINDOW (f) == 0)
4908 return 1;
4909
4910 #ifdef HAVE_X11R4
4911 {
4912 XTextProperty text;
4913 text.value = (unsigned char *) icon_name;
4914 text.encoding = XA_STRING;
4915 text.format = 8;
4916 text.nitems = strlen (icon_name);
4917 #ifdef USE_X_TOOLKIT
4918 XSetWMIconName (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget),
4919 &text);
4920 #else /* not USE_X_TOOLKIT */
4921 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text);
4922 #endif /* not USE_X_TOOLKIT */
4923 }
4924 #else /* not HAVE_X11R4 */
4925 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), icon_name);
4926 #endif /* not HAVE_X11R4 */
4927
4928 if (f->output_data.x->icon_bitmap > 0)
4929 x_destroy_bitmap (f, f->output_data.x->icon_bitmap);
4930 f->output_data.x->icon_bitmap = 0;
4931 x_wm_set_icon_pixmap (f, 0);
4932
4933 return 0;
4934 }
4935 \f
4936 #define X_ERROR_MESSAGE_SIZE 200
4937
4938 /* If non-nil, this should be a string.
4939 It means catch X errors and store the error message in this string. */
4940
4941 static Lisp_Object x_error_message_string;
4942
4943 /* An X error handler which stores the error message in
4944 x_error_message_string. This is called from x_error_handler if
4945 x_catch_errors is in effect. */
4946
4947 static int
4948 x_error_catcher (display, error)
4949 Display *display;
4950 XErrorEvent *error;
4951 {
4952 XGetErrorText (display, error->error_code,
4953 XSTRING (x_error_message_string)->data,
4954 X_ERROR_MESSAGE_SIZE);
4955 }
4956
4957 /* Begin trapping X errors for display DPY. Actually we trap X errors
4958 for all displays, but DPY should be the display you are actually
4959 operating on.
4960
4961 After calling this function, X protocol errors no longer cause
4962 Emacs to exit; instead, they are recorded in the string
4963 stored in x_error_message_string.
4964
4965 Calling x_check_errors signals an Emacs error if an X error has
4966 occurred since the last call to x_catch_errors or x_check_errors.
4967
4968 Calling x_uncatch_errors resumes the normal error handling. */
4969
4970 void x_check_errors ();
4971 static Lisp_Object x_catch_errors_unwind ();
4972
4973 int
4974 x_catch_errors (dpy)
4975 Display *dpy;
4976 {
4977 int count = specpdl_ptr - specpdl;
4978
4979 /* Make sure any errors from previous requests have been dealt with. */
4980 XSync (dpy, False);
4981
4982 record_unwind_protect (x_catch_errors_unwind, x_error_message_string);
4983
4984 x_error_message_string = make_uninit_string (X_ERROR_MESSAGE_SIZE);
4985 XSTRING (x_error_message_string)->data[0] = 0;
4986
4987 return count;
4988 }
4989
4990 /* Unbind the binding that we made to check for X errors. */
4991
4992 static Lisp_Object
4993 x_catch_errors_unwind (old_val)
4994 Lisp_Object old_val;
4995 {
4996 x_error_message_string = old_val;
4997 return Qnil;
4998 }
4999
5000 /* If any X protocol errors have arrived since the last call to
5001 x_catch_errors or x_check_errors, signal an Emacs error using
5002 sprintf (a buffer, FORMAT, the x error message text) as the text. */
5003
5004 void
5005 x_check_errors (dpy, format)
5006 Display *dpy;
5007 char *format;
5008 {
5009 /* Make sure to catch any errors incurred so far. */
5010 XSync (dpy, False);
5011
5012 if (XSTRING (x_error_message_string)->data[0])
5013 error (format, XSTRING (x_error_message_string)->data);
5014 }
5015
5016 /* Nonzero if we had any X protocol errors
5017 since we did x_catch_errors on DPY. */
5018
5019 int
5020 x_had_errors_p (dpy)
5021 Display *dpy;
5022 {
5023 /* Make sure to catch any errors incurred so far. */
5024 XSync (dpy, False);
5025
5026 return XSTRING (x_error_message_string)->data[0] != 0;
5027 }
5028
5029 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
5030
5031 int
5032 x_clear_errors (dpy)
5033 Display *dpy;
5034 {
5035 XSTRING (x_error_message_string)->data[0] = 0;
5036 }
5037
5038 /* Stop catching X protocol errors and let them make Emacs die.
5039 DPY should be the display that was passed to x_catch_errors.
5040 COUNT should be the value that was returned by
5041 the corresponding call to x_catch_errors. */
5042
5043 void
5044 x_uncatch_errors (dpy, count)
5045 Display *dpy;
5046 int count;
5047 {
5048 unbind_to (count, Qnil);
5049 }
5050
5051 #if 0
5052 static unsigned int x_wire_count;
5053 x_trace_wire ()
5054 {
5055 fprintf (stderr, "Lib call: %d\n", ++x_wire_count);
5056 }
5057 #endif /* ! 0 */
5058
5059 \f
5060 /* Handle SIGPIPE, which can happen when the connection to a server
5061 simply goes away. SIGPIPE is handled by x_connection_signal.
5062 Don't need to do anything, because the write which caused the
5063 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
5064 which will do the appropriate cleanup for us. */
5065
5066 static SIGTYPE
5067 x_connection_signal (signalnum) /* If we don't have an argument, */
5068 int signalnum; /* some compilers complain in signal calls. */
5069 {
5070 #ifdef USG
5071 /* USG systems forget handlers when they are used;
5072 must reestablish each time */
5073 signal (signalnum, x_connection_signal);
5074 #endif /* USG */
5075 }
5076 \f
5077 /* Handling X errors. */
5078
5079 /* Handle the loss of connection to display DISPLAY. */
5080
5081 static SIGTYPE
5082 x_connection_closed (display, error_message)
5083 Display *display;
5084 char *error_message;
5085 {
5086 struct x_display_info *dpyinfo = x_display_info_for_display (display);
5087 Lisp_Object frame, tail;
5088
5089 /* Indicate that this display is dead. */
5090
5091 #ifdef USE_X_TOOLKIT
5092 XtCloseDisplay (display);
5093 #endif
5094
5095 dpyinfo->display = 0;
5096
5097 /* First delete frames whose minibuffers are on frames
5098 that are on the dead display. */
5099 FOR_EACH_FRAME (tail, frame)
5100 {
5101 Lisp_Object minibuf_frame;
5102 minibuf_frame
5103 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame))));
5104 if (FRAME_X_P (XFRAME (frame))
5105 && FRAME_X_P (XFRAME (minibuf_frame))
5106 && ! EQ (frame, minibuf_frame)
5107 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame)) == dpyinfo)
5108 Fdelete_frame (frame, Qt);
5109 }
5110
5111 /* Now delete all remaining frames on the dead display.
5112 We are now sure none of these is used as the minibuffer
5113 for another frame that we need to delete. */
5114 FOR_EACH_FRAME (tail, frame)
5115 if (FRAME_X_P (XFRAME (frame))
5116 && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
5117 {
5118 /* Set this to t so that Fdelete_frame won't get confused
5119 trying to find a replacement. */
5120 FRAME_KBOARD (XFRAME (frame))->Vdefault_minibuffer_frame = Qt;
5121 Fdelete_frame (frame, Qt);
5122 }
5123
5124 if (dpyinfo)
5125 x_delete_display (dpyinfo);
5126
5127 if (x_display_list == 0)
5128 {
5129 fprintf (stderr, "%s\n", error_message);
5130 shut_down_emacs (0, 0, Qnil);
5131 exit (70);
5132 }
5133
5134 /* Ordinary stack unwind doesn't deal with these. */
5135 #ifdef SIGIO
5136 sigunblock (sigmask (SIGIO));
5137 #endif
5138 sigunblock (sigmask (SIGALRM));
5139 TOTALLY_UNBLOCK_INPUT;
5140
5141 clear_waiting_for_input ();
5142 error ("%s", error_message);
5143 }
5144
5145 /* This is the usual handler for X protocol errors.
5146 It kills all frames on the display that we got the error for.
5147 If that was the only one, it prints an error message and kills Emacs. */
5148
5149 static int
5150 x_error_quitter (display, error)
5151 Display *display;
5152 XErrorEvent *error;
5153 {
5154 char buf[256], buf1[356];
5155
5156 /* Note that there is no real way portable across R3/R4 to get the
5157 original error handler. */
5158
5159 XGetErrorText (display, error->error_code, buf, sizeof (buf));
5160 sprintf (buf1, "X protocol error: %s on protocol request %d",
5161 buf, error->request_code);
5162 x_connection_closed (display, buf1);
5163 }
5164
5165 /* This is the first-level handler for X protocol errors.
5166 It calls x_error_quitter or x_error_catcher. */
5167
5168 static int
5169 x_error_handler (display, error)
5170 Display *display;
5171 XErrorEvent *error;
5172 {
5173 char buf[256], buf1[356];
5174
5175 if (! NILP (x_error_message_string))
5176 x_error_catcher (display, error);
5177 else
5178 x_error_quitter (display, error);
5179 }
5180
5181 /* This is the handler for X IO errors, always.
5182 It kills all frames on the display that we lost touch with.
5183 If that was the only one, it prints an error message and kills Emacs. */
5184
5185 static int
5186 x_io_error_quitter (display)
5187 Display *display;
5188 {
5189 char buf[256];
5190
5191 sprintf (buf, "Connection lost to X server `%s'", DisplayString (display));
5192 x_connection_closed (display, buf);
5193 }
5194 \f
5195 /* Changing the font of the frame. */
5196
5197 /* Give frame F the font named FONTNAME as its default font, and
5198 return the full name of that font. FONTNAME may be a wildcard
5199 pattern; in that case, we choose some font that fits the pattern.
5200 The return value shows which font we chose. */
5201
5202 Lisp_Object
5203 x_new_font (f, fontname)
5204 struct frame *f;
5205 register char *fontname;
5206 {
5207 struct font_info *fontp
5208 = fs_load_font (f, FRAME_X_FONT_TABLE (f), CHARSET_ASCII, fontname, -1);
5209
5210 if (!fontp)
5211 return Qnil;
5212
5213 f->output_data.x->font = (XFontStruct *) (fontp->font);
5214 f->output_data.x->font_baseline
5215 = (f->output_data.x->font->ascent + fontp->baseline_offset);
5216 f->output_data.x->fontset = -1;
5217
5218 /* Compute the scroll bar width in character columns. */
5219 if (f->scroll_bar_pixel_width > 0)
5220 {
5221 int wid = FONT_WIDTH (f->output_data.x->font);
5222 f->scroll_bar_cols = (f->scroll_bar_pixel_width + wid-1) / wid;
5223 }
5224 else
5225 f->scroll_bar_cols = 2;
5226
5227 /* Now make the frame display the given font. */
5228 if (FRAME_X_WINDOW (f) != 0)
5229 {
5230 XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->normal_gc,
5231 f->output_data.x->font->fid);
5232 XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->reverse_gc,
5233 f->output_data.x->font->fid);
5234 XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->cursor_gc,
5235 f->output_data.x->font->fid);
5236
5237 frame_update_line_height (f);
5238 x_set_window_size (f, 0, f->width, f->height);
5239 }
5240 else
5241 /* If we are setting a new frame's font for the first time,
5242 there are no faces yet, so this font's height is the line height. */
5243 f->output_data.x->line_height = FONT_HEIGHT (f->output_data.x->font);
5244
5245 return build_string (fontp->full_name);
5246 }
5247
5248 /* Give frame F the fontset named FONTSETNAME as its default font, and
5249 return the full name of that fontset. FONTSETNAME may be a wildcard
5250 pattern; in that case, we choose some fontset that fits the pattern.
5251 The return value shows which fontset we chose. */
5252
5253 Lisp_Object
5254 x_new_fontset (f, fontsetname)
5255 struct frame *f;
5256 char *fontsetname;
5257 {
5258 int fontset = fs_query_fontset (f, fontsetname);
5259 struct fontset_info *fontsetp;
5260 Lisp_Object result;
5261
5262 if (fontset < 0)
5263 return Qnil;
5264
5265 if (f->output_data.x->fontset == fontset)
5266 /* This fontset is already set in frame F. There's nothing more
5267 to do. */
5268 return build_string (fontsetname);
5269
5270 fontsetp = FRAME_FONTSET_DATA (f)->fontset_table[fontset];
5271
5272 if (!fontsetp->fontname[CHARSET_ASCII])
5273 /* This fontset doesn't contain ASCII font. */
5274 return Qnil;
5275
5276 result = x_new_font (f, fontsetp->fontname[CHARSET_ASCII]);
5277
5278 if (!STRINGP (result))
5279 /* Can't load ASCII font. */
5280 return Qnil;
5281
5282 /* Since x_new_font doesn't update any fontset information, do it now. */
5283 f->output_data.x->fontset = fontset;
5284 FS_LOAD_FONT (f, FRAME_X_FONT_TABLE (f),
5285 CHARSET_ASCII, XSTRING (result)->data, fontset);
5286
5287 return build_string (fontsetname);
5288 }
5289 \f
5290 /* Calculate the absolute position in frame F
5291 from its current recorded position values and gravity. */
5292
5293 x_calc_absolute_position (f)
5294 struct frame *f;
5295 {
5296 Window win, child;
5297 int win_x = 0, win_y = 0;
5298 int flags = f->output_data.x->size_hint_flags;
5299 int this_window;
5300
5301 /* We have nothing to do if the current position
5302 is already for the top-left corner. */
5303 if (! ((flags & XNegative) || (flags & YNegative)))
5304 return;
5305
5306 #ifdef USE_X_TOOLKIT
5307 this_window = XtWindow (f->output_data.x->widget);
5308 #else
5309 this_window = FRAME_X_WINDOW (f);
5310 #endif
5311
5312 /* Find the position of the outside upper-left corner of
5313 the inner window, with respect to the outer window.
5314 But do this only if we will need the results. */
5315 if (f->output_data.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window)
5316 {
5317 int count;
5318
5319 BLOCK_INPUT;
5320 count = x_catch_errors (FRAME_X_DISPLAY (f));
5321 while (1)
5322 {
5323 x_clear_errors (FRAME_X_DISPLAY (f));
5324 XTranslateCoordinates (FRAME_X_DISPLAY (f),
5325
5326 /* From-window, to-window. */
5327 this_window,
5328 f->output_data.x->parent_desc,
5329
5330 /* From-position, to-position. */
5331 0, 0, &win_x, &win_y,
5332
5333 /* Child of win. */
5334 &child);
5335 if (x_had_errors_p (FRAME_X_DISPLAY (f)))
5336 {
5337 Window newroot, newparent = 0xdeadbeef;
5338 Window *newchildren;
5339 int nchildren;
5340
5341 if (! XQueryTree (FRAME_X_DISPLAY (f), this_window, &newroot,
5342 &newparent, &newchildren, &nchildren))
5343 break;
5344
5345 XFree (newchildren);
5346
5347 f->output_data.x->parent_desc = newparent;
5348 }
5349 else
5350 break;
5351 }
5352
5353 x_uncatch_errors (FRAME_X_DISPLAY (f), count);
5354 UNBLOCK_INPUT;
5355 }
5356
5357 /* Treat negative positions as relative to the leftmost bottommost
5358 position that fits on the screen. */
5359 if (flags & XNegative)
5360 f->output_data.x->left_pos = (FRAME_X_DISPLAY_INFO (f)->width
5361 - 2 * f->output_data.x->border_width - win_x
5362 - PIXEL_WIDTH (f)
5363 + f->output_data.x->left_pos);
5364
5365 if (flags & YNegative)
5366 /* We used to subtract f->output_data.x->menubar_height here
5367 in the toolkit case, but PIXEL_HEIGHT already includes that. */
5368 f->output_data.x->top_pos = (FRAME_X_DISPLAY_INFO (f)->height
5369 - 2 * f->output_data.x->border_width - win_y
5370 - PIXEL_HEIGHT (f)
5371 + f->output_data.x->top_pos);
5372
5373 /* The left_pos and top_pos
5374 are now relative to the top and left screen edges,
5375 so the flags should correspond. */
5376 f->output_data.x->size_hint_flags &= ~ (XNegative | YNegative);
5377 }
5378
5379 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5380 to really change the position, and 0 when calling from
5381 x_make_frame_visible (in that case, XOFF and YOFF are the current
5382 position values). It is -1 when calling from x_set_frame_parameters,
5383 which means, do adjust for borders but don't change the gravity. */
5384
5385 x_set_offset (f, xoff, yoff, change_gravity)
5386 struct frame *f;
5387 register int xoff, yoff;
5388 int change_gravity;
5389 {
5390 int modified_top, modified_left;
5391
5392 if (change_gravity > 0)
5393 {
5394 f->output_data.x->top_pos = yoff;
5395 f->output_data.x->left_pos = xoff;
5396 f->output_data.x->size_hint_flags &= ~ (XNegative | YNegative);
5397 if (xoff < 0)
5398 f->output_data.x->size_hint_flags |= XNegative;
5399 if (yoff < 0)
5400 f->output_data.x->size_hint_flags |= YNegative;
5401 f->output_data.x->win_gravity = NorthWestGravity;
5402 }
5403 x_calc_absolute_position (f);
5404
5405 BLOCK_INPUT;
5406 x_wm_set_size_hint (f, (long) 0, 0);
5407
5408 modified_left = f->output_data.x->left_pos;
5409 modified_top = f->output_data.x->top_pos;
5410 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
5411 this seems to be unnecessary and incorrect. rms, 4/17/97. */
5412 /* It is a mystery why we need to add the border_width here
5413 when the frame is already visible, but experiment says we do. */
5414 if (change_gravity != 0)
5415 {
5416 modified_left += f->output_data.x->border_width;
5417 modified_top += f->output_data.x->border_width;
5418 }
5419 #endif
5420
5421 #ifdef USE_X_TOOLKIT
5422 XMoveWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget),
5423 modified_left, modified_top);
5424 #else /* not USE_X_TOOLKIT */
5425 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5426 modified_left, modified_top);
5427 #endif /* not USE_X_TOOLKIT */
5428 UNBLOCK_INPUT;
5429 }
5430
5431 /* Call this to change the size of frame F's x-window.
5432 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5433 for this size change and subsequent size changes.
5434 Otherwise we leave the window gravity unchanged. */
5435
5436 x_set_window_size (f, change_gravity, cols, rows)
5437 struct frame *f;
5438 int change_gravity;
5439 int cols, rows;
5440 {
5441 int pixelwidth, pixelheight;
5442 int mask;
5443 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
5444
5445 BLOCK_INPUT;
5446
5447 #ifdef USE_X_TOOLKIT
5448 {
5449 /* The x and y position of the widget is clobbered by the
5450 call to XtSetValues within EmacsFrameSetCharSize.
5451 This is a real kludge, but I don't understand Xt so I can't
5452 figure out a correct fix. Can anyone else tell me? -- rms. */
5453 int xpos = f->output_data.x->widget->core.x;
5454 int ypos = f->output_data.x->widget->core.y;
5455 EmacsFrameSetCharSize (f->output_data.x->edit_widget, cols, rows);
5456 f->output_data.x->widget->core.x = xpos;
5457 f->output_data.x->widget->core.y = ypos;
5458 }
5459
5460 #else /* not USE_X_TOOLKIT */
5461
5462 check_frame_size (f, &rows, &cols);
5463 f->output_data.x->vertical_scroll_bar_extra
5464 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f)
5465 ? 0
5466 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0
5467 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f)
5468 : (FRAME_SCROLL_BAR_COLS (f) * FONT_WIDTH (f->output_data.x->font)));
5469 pixelwidth = CHAR_TO_PIXEL_WIDTH (f, cols);
5470 pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows);
5471
5472 f->output_data.x->win_gravity = NorthWestGravity;
5473 x_wm_set_size_hint (f, (long) 0, 0);
5474
5475 XSync (FRAME_X_DISPLAY (f), False);
5476 XResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5477 pixelwidth, pixelheight);
5478
5479 /* Now, strictly speaking, we can't be sure that this is accurate,
5480 but the window manager will get around to dealing with the size
5481 change request eventually, and we'll hear how it went when the
5482 ConfigureNotify event gets here.
5483
5484 We could just not bother storing any of this information here,
5485 and let the ConfigureNotify event set everything up, but that
5486 might be kind of confusing to the lisp code, since size changes
5487 wouldn't be reported in the frame parameters until some random
5488 point in the future when the ConfigureNotify event arrives. */
5489 change_frame_size (f, rows, cols, 0, 0);
5490 PIXEL_WIDTH (f) = pixelwidth;
5491 PIXEL_HEIGHT (f) = pixelheight;
5492
5493 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5494 receive in the ConfigureNotify event; if we get what we asked
5495 for, then the event won't cause the screen to become garbaged, so
5496 we have to make sure to do it here. */
5497 SET_FRAME_GARBAGED (f);
5498
5499 XFlush (FRAME_X_DISPLAY (f));
5500
5501 #endif /* not USE_X_TOOLKIT */
5502
5503 /* If cursor was outside the new size, mark it as off. */
5504 if (f->phys_cursor_y >= rows
5505 || f->phys_cursor_x >= cols)
5506 {
5507 f->phys_cursor_x = 0;
5508 f->phys_cursor_y = 0;
5509 f->phys_cursor_on = 0;
5510 }
5511
5512 /* Clear out any recollection of where the mouse highlighting was,
5513 since it might be in a place that's outside the new frame size.
5514 Actually checking whether it is outside is a pain in the neck,
5515 so don't try--just let the highlighting be done afresh with new size. */
5516 cancel_mouse_face (f);
5517
5518 UNBLOCK_INPUT;
5519 }
5520 \f
5521 /* Mouse warping. */
5522
5523 void
5524 x_set_mouse_position (f, x, y)
5525 struct frame *f;
5526 int x, y;
5527 {
5528 int pix_x, pix_y;
5529
5530 pix_x = CHAR_TO_PIXEL_COL (f, x) + FONT_WIDTH (f->output_data.x->font) / 2;
5531 pix_y = CHAR_TO_PIXEL_ROW (f, y) + f->output_data.x->line_height / 2;
5532
5533 if (pix_x < 0) pix_x = 0;
5534 if (pix_x > PIXEL_WIDTH (f)) pix_x = PIXEL_WIDTH (f);
5535
5536 if (pix_y < 0) pix_y = 0;
5537 if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f);
5538
5539 BLOCK_INPUT;
5540
5541 XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f),
5542 0, 0, 0, 0, pix_x, pix_y);
5543 UNBLOCK_INPUT;
5544 }
5545
5546 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
5547
5548 void
5549 x_set_mouse_pixel_position (f, pix_x, pix_y)
5550 struct frame *f;
5551 int pix_x, pix_y;
5552 {
5553 BLOCK_INPUT;
5554
5555 XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f),
5556 0, 0, 0, 0, pix_x, pix_y);
5557 UNBLOCK_INPUT;
5558 }
5559 \f
5560 /* focus shifting, raising and lowering. */
5561
5562 x_focus_on_frame (f)
5563 struct frame *f;
5564 {
5565 #if 0 /* This proves to be unpleasant. */
5566 x_raise_frame (f);
5567 #endif
5568 #if 0
5569 /* I don't think that the ICCCM allows programs to do things like this
5570 without the interaction of the window manager. Whatever you end up
5571 doing with this code, do it to x_unfocus_frame too. */
5572 XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5573 RevertToPointerRoot, CurrentTime);
5574 #endif /* ! 0 */
5575 }
5576
5577 x_unfocus_frame (f)
5578 struct frame *f;
5579 {
5580 #if 0
5581 /* Look at the remarks in x_focus_on_frame. */
5582 if (FRAME_X_DISPLAY_INFO (f)->x_focus_frame == f)
5583 XSetInputFocus (FRAME_X_DISPLAY (f), PointerRoot,
5584 RevertToPointerRoot, CurrentTime);
5585 #endif /* ! 0 */
5586 }
5587
5588 /* Raise frame F. */
5589
5590 x_raise_frame (f)
5591 struct frame *f;
5592 {
5593 if (f->async_visible)
5594 {
5595 BLOCK_INPUT;
5596 #ifdef USE_X_TOOLKIT
5597 XRaiseWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget));
5598 #else /* not USE_X_TOOLKIT */
5599 XRaiseWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5600 #endif /* not USE_X_TOOLKIT */
5601 XFlush (FRAME_X_DISPLAY (f));
5602 UNBLOCK_INPUT;
5603 }
5604 }
5605
5606 /* Lower frame F. */
5607
5608 x_lower_frame (f)
5609 struct frame *f;
5610 {
5611 if (f->async_visible)
5612 {
5613 BLOCK_INPUT;
5614 #ifdef USE_X_TOOLKIT
5615 XLowerWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget));
5616 #else /* not USE_X_TOOLKIT */
5617 XLowerWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5618 #endif /* not USE_X_TOOLKIT */
5619 XFlush (FRAME_X_DISPLAY (f));
5620 UNBLOCK_INPUT;
5621 }
5622 }
5623
5624 static void
5625 XTframe_raise_lower (f, raise_flag)
5626 FRAME_PTR f;
5627 int raise_flag;
5628 {
5629 if (raise_flag)
5630 x_raise_frame (f);
5631 else
5632 x_lower_frame (f);
5633 }
5634 \f
5635 /* Change of visibility. */
5636
5637 /* This tries to wait until the frame is really visible.
5638 However, if the window manager asks the user where to position
5639 the frame, this will return before the user finishes doing that.
5640 The frame will not actually be visible at that time,
5641 but it will become visible later when the window manager
5642 finishes with it. */
5643
5644 x_make_frame_visible (f)
5645 struct frame *f;
5646 {
5647 int mask;
5648 Lisp_Object type;
5649 int starting_flags = f->output_data.x->size_hint_flags;
5650 int original_top, original_left;
5651
5652 BLOCK_INPUT;
5653
5654 type = x_icon_type (f);
5655 if (!NILP (type))
5656 x_bitmap_icon (f, type);
5657
5658 if (! FRAME_VISIBLE_P (f))
5659 {
5660 /* We test FRAME_GARBAGED_P here to make sure we don't
5661 call x_set_offset a second time
5662 if we get to x_make_frame_visible a second time
5663 before the window gets really visible. */
5664 if (! FRAME_ICONIFIED_P (f)
5665 && ! f->output_data.x->asked_for_visible)
5666 x_set_offset (f, f->output_data.x->left_pos, f->output_data.x->top_pos, 0);
5667
5668 f->output_data.x->asked_for_visible = 1;
5669
5670 if (! EQ (Vx_no_window_manager, Qt))
5671 x_wm_set_window_state (f, NormalState);
5672 #ifdef USE_X_TOOLKIT
5673 /* This was XtPopup, but that did nothing for an iconified frame. */
5674 XtMapWidget (f->output_data.x->widget);
5675 #else /* not USE_X_TOOLKIT */
5676 XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5677 #endif /* not USE_X_TOOLKIT */
5678 #if 0 /* This seems to bring back scroll bars in the wrong places
5679 if the window configuration has changed. They seem
5680 to come back ok without this. */
5681 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
5682 XMapSubwindows (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5683 #endif
5684 }
5685
5686 XFlush (FRAME_X_DISPLAY (f));
5687
5688 /* Synchronize to ensure Emacs knows the frame is visible
5689 before we do anything else. We do this loop with input not blocked
5690 so that incoming events are handled. */
5691 {
5692 Lisp_Object frame;
5693 int count = input_signal_count;
5694 /* This must be before UNBLOCK_INPUT
5695 since events that arrive in response to the actions above
5696 will set it when they are handled. */
5697 int previously_visible = f->output_data.x->has_been_visible;
5698
5699 original_left = f->output_data.x->left_pos;
5700 original_top = f->output_data.x->top_pos;
5701
5702 /* This must come after we set COUNT. */
5703 UNBLOCK_INPUT;
5704
5705 /* Arriving X events are processed here. */
5706
5707 /* Now move the window back to where it was "supposed to be".
5708 But don't do it if the gravity is negative.
5709 When the gravity is negative, this uses a position
5710 that is 3 pixels too low. Perhaps that's really the border width.
5711
5712 Don't do this if the window has never been visible before,
5713 because the window manager may choose the position
5714 and we don't want to override it. */
5715
5716 if (! FRAME_VISIBLE_P (f) && ! FRAME_ICONIFIED_P (f)
5717 && f->output_data.x->win_gravity == NorthWestGravity
5718 && previously_visible)
5719 {
5720 BLOCK_INPUT;
5721
5722 #ifdef USE_X_TOOLKIT
5723 XMoveWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget),
5724 original_left, original_top);
5725 #else /* not USE_X_TOOLKIT */
5726 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5727 original_left, original_top);
5728 #endif /* not USE_X_TOOLKIT */
5729 UNBLOCK_INPUT;
5730 }
5731
5732 XSETFRAME (frame, f);
5733
5734 while (1)
5735 {
5736 x_sync (f);
5737 /* Once we have handled input events,
5738 we should have received the MapNotify if one is coming.
5739 So if we have not got it yet, stop looping.
5740 Some window managers make their own decisions
5741 about visibility. */
5742 if (input_signal_count != count)
5743 break;
5744 /* Machines that do polling rather than SIGIO have been observed
5745 to go into a busy-wait here. So we'll fake an alarm signal
5746 to let the handler know that there's something to be read.
5747 We used to raise a real alarm, but it seems that the handler
5748 isn't always enabled here. This is probably a bug. */
5749 if (input_polling_used ())
5750 {
5751 /* It could be confusing if a real alarm arrives while processing
5752 the fake one. Turn it off and let the handler reset it. */
5753 alarm (0);
5754 input_poll_signal ();
5755 }
5756 /* Once we have handled input events,
5757 we should have received the MapNotify if one is coming.
5758 So if we have not got it yet, stop looping.
5759 Some window managers make their own decisions
5760 about visibility. */
5761 if (input_signal_count != count)
5762 break;
5763 }
5764 FRAME_SAMPLE_VISIBILITY (f);
5765 }
5766 }
5767
5768 /* Change from mapped state to withdrawn state. */
5769
5770 /* Make the frame visible (mapped and not iconified). */
5771
5772 x_make_frame_invisible (f)
5773 struct frame *f;
5774 {
5775 int mask;
5776 Window window;
5777
5778 #ifdef USE_X_TOOLKIT
5779 /* Use the frame's outermost window, not the one we normally draw on. */
5780 window = XtWindow (f->output_data.x->widget);
5781 #else /* not USE_X_TOOLKIT */
5782 window = FRAME_X_WINDOW (f);
5783 #endif /* not USE_X_TOOLKIT */
5784
5785 /* Don't keep the highlight on an invisible frame. */
5786 if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f)
5787 FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0;
5788
5789 #if 0/* This might add unreliability; I don't trust it -- rms. */
5790 if (! f->async_visible && ! f->async_iconified)
5791 return;
5792 #endif
5793
5794 BLOCK_INPUT;
5795
5796 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5797 that the current position of the window is user-specified, rather than
5798 program-specified, so that when the window is mapped again, it will be
5799 placed at the same location, without forcing the user to position it
5800 by hand again (they have already done that once for this window.) */
5801 x_wm_set_size_hint (f, (long) 0, 1);
5802
5803 #ifdef HAVE_X11R4
5804
5805 if (! XWithdrawWindow (FRAME_X_DISPLAY (f), window,
5806 DefaultScreen (FRAME_X_DISPLAY (f))))
5807 {
5808 UNBLOCK_INPUT_RESIGNAL;
5809 error ("Can't notify window manager of window withdrawal");
5810 }
5811 #else /* ! defined (HAVE_X11R4) */
5812
5813 /* Tell the window manager what we're going to do. */
5814 if (! EQ (Vx_no_window_manager, Qt))
5815 {
5816 XEvent unmap;
5817
5818 unmap.xunmap.type = UnmapNotify;
5819 unmap.xunmap.window = window;
5820 unmap.xunmap.event = DefaultRootWindow (FRAME_X_DISPLAY (f));
5821 unmap.xunmap.from_configure = False;
5822 if (! XSendEvent (FRAME_X_DISPLAY (f),
5823 DefaultRootWindow (FRAME_X_DISPLAY (f)),
5824 False,
5825 SubstructureRedirectMask|SubstructureNotifyMask,
5826 &unmap))
5827 {
5828 UNBLOCK_INPUT_RESIGNAL;
5829 error ("Can't notify window manager of withdrawal");
5830 }
5831 }
5832
5833 /* Unmap the window ourselves. Cheeky! */
5834 XUnmapWindow (FRAME_X_DISPLAY (f), window);
5835 #endif /* ! defined (HAVE_X11R4) */
5836
5837 /* We can't distinguish this from iconification
5838 just by the event that we get from the server.
5839 So we can't win using the usual strategy of letting
5840 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5841 and synchronize with the server to make sure we agree. */
5842 f->visible = 0;
5843 FRAME_ICONIFIED_P (f) = 0;
5844 f->async_visible = 0;
5845 f->async_iconified = 0;
5846
5847 x_sync (f);
5848
5849 UNBLOCK_INPUT;
5850 }
5851
5852 /* Change window state from mapped to iconified. */
5853
5854 x_iconify_frame (f)
5855 struct frame *f;
5856 {
5857 int mask;
5858 int result;
5859 Lisp_Object type;
5860
5861 /* Don't keep the highlight on an invisible frame. */
5862 if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f)
5863 FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0;
5864
5865 if (f->async_iconified)
5866 return;
5867
5868 BLOCK_INPUT;
5869
5870 FRAME_SAMPLE_VISIBILITY (f);
5871
5872 type = x_icon_type (f);
5873 if (!NILP (type))
5874 x_bitmap_icon (f, type);
5875
5876 #ifdef USE_X_TOOLKIT
5877
5878 if (! FRAME_VISIBLE_P (f))
5879 {
5880 if (! EQ (Vx_no_window_manager, Qt))
5881 x_wm_set_window_state (f, IconicState);
5882 /* This was XtPopup, but that did nothing for an iconified frame. */
5883 XtMapWidget (f->output_data.x->widget);
5884 /* The server won't give us any event to indicate
5885 that an invisible frame was changed to an icon,
5886 so we have to record it here. */
5887 f->iconified = 1;
5888 f->visible = 1;
5889 f->async_iconified = 1;
5890 f->async_visible = 0;
5891 UNBLOCK_INPUT;
5892 return;
5893 }
5894
5895 result = XIconifyWindow (FRAME_X_DISPLAY (f),
5896 XtWindow (f->output_data.x->widget),
5897 DefaultScreen (FRAME_X_DISPLAY (f)));
5898 UNBLOCK_INPUT;
5899
5900 if (!result)
5901 error ("Can't notify window manager of iconification");
5902
5903 f->async_iconified = 1;
5904 f->async_visible = 0;
5905
5906
5907 BLOCK_INPUT;
5908 XFlush (FRAME_X_DISPLAY (f));
5909 UNBLOCK_INPUT;
5910 #else /* not USE_X_TOOLKIT */
5911
5912 /* Make sure the X server knows where the window should be positioned,
5913 in case the user deiconifies with the window manager. */
5914 if (! FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f))
5915 x_set_offset (f, f->output_data.x->left_pos, f->output_data.x->top_pos, 0);
5916
5917 /* Since we don't know which revision of X we're running, we'll use both
5918 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
5919
5920 /* X11R4: send a ClientMessage to the window manager using the
5921 WM_CHANGE_STATE type. */
5922 {
5923 XEvent message;
5924
5925 message.xclient.window = FRAME_X_WINDOW (f);
5926 message.xclient.type = ClientMessage;
5927 message.xclient.message_type = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_change_state;
5928 message.xclient.format = 32;
5929 message.xclient.data.l[0] = IconicState;
5930
5931 if (! XSendEvent (FRAME_X_DISPLAY (f),
5932 DefaultRootWindow (FRAME_X_DISPLAY (f)),
5933 False,
5934 SubstructureRedirectMask | SubstructureNotifyMask,
5935 &message))
5936 {
5937 UNBLOCK_INPUT_RESIGNAL;
5938 error ("Can't notify window manager of iconification");
5939 }
5940 }
5941
5942 /* X11R3: set the initial_state field of the window manager hints to
5943 IconicState. */
5944 x_wm_set_window_state (f, IconicState);
5945
5946 if (!FRAME_VISIBLE_P (f))
5947 {
5948 /* If the frame was withdrawn, before, we must map it. */
5949 XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5950 }
5951
5952 f->async_iconified = 1;
5953 f->async_visible = 0;
5954
5955 XFlush (FRAME_X_DISPLAY (f));
5956 UNBLOCK_INPUT;
5957 #endif /* not USE_X_TOOLKIT */
5958 }
5959 \f
5960 /* Destroy the X window of frame F. */
5961
5962 x_destroy_window (f)
5963 struct frame *f;
5964 {
5965 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
5966
5967 BLOCK_INPUT;
5968
5969 /* If a display connection is dead, don't try sending more
5970 commands to the X server. */
5971 if (dpyinfo->display != 0)
5972 {
5973 if (f->output_data.x->icon_desc != 0)
5974 XDestroyWindow (FRAME_X_DISPLAY (f), f->output_data.x->icon_desc);
5975 #ifdef HAVE_X_I18N
5976 if (FRAME_XIM (f))
5977 {
5978 XDestroyIC (FRAME_XIC (f));
5979 #if ! defined (SOLARIS2) || defined (HAVE_X11R6)
5980 /* This line causes crashes on Solaris with Openwin,
5981 due to an apparent bug in XCloseIM.
5982 X11R6 seems not to have the bug. */
5983 XCloseIM (FRAME_XIM (f));
5984 #endif
5985 }
5986 #endif
5987 XDestroyWindow (FRAME_X_DISPLAY (f), f->output_data.x->window_desc);
5988 #ifdef USE_X_TOOLKIT
5989 XtDestroyWidget (f->output_data.x->widget);
5990 free_frame_menubar (f);
5991 #endif /* USE_X_TOOLKIT */
5992
5993 free_frame_faces (f);
5994 XFlush (FRAME_X_DISPLAY (f));
5995 }
5996
5997 if (f->output_data.x->saved_menu_event)
5998 free (f->output_data.x->saved_menu_event);
5999
6000 xfree (f->output_data.x);
6001 f->output_data.x = 0;
6002 if (f == dpyinfo->x_focus_frame)
6003 dpyinfo->x_focus_frame = 0;
6004 if (f == dpyinfo->x_focus_event_frame)
6005 dpyinfo->x_focus_event_frame = 0;
6006 if (f == dpyinfo->x_highlight_frame)
6007 dpyinfo->x_highlight_frame = 0;
6008
6009 dpyinfo->reference_count--;
6010
6011 if (f == dpyinfo->mouse_face_mouse_frame)
6012 {
6013 dpyinfo->mouse_face_beg_row
6014 = dpyinfo->mouse_face_beg_col = -1;
6015 dpyinfo->mouse_face_end_row
6016 = dpyinfo->mouse_face_end_col = -1;
6017 dpyinfo->mouse_face_window = Qnil;
6018 }
6019
6020 UNBLOCK_INPUT;
6021 }
6022 \f
6023 /* Setting window manager hints. */
6024
6025 /* Set the normal size hints for the window manager, for frame F.
6026 FLAGS is the flags word to use--or 0 meaning preserve the flags
6027 that the window now has.
6028 If USER_POSITION is nonzero, we set the USPosition
6029 flag (this is useful when FLAGS is 0). */
6030
6031 x_wm_set_size_hint (f, flags, user_position)
6032 struct frame *f;
6033 long flags;
6034 int user_position;
6035 {
6036 XSizeHints size_hints;
6037
6038 #ifdef USE_X_TOOLKIT
6039 Arg al[2];
6040 int ac = 0;
6041 Dimension widget_width, widget_height;
6042 Window window = XtWindow (f->output_data.x->widget);
6043 #else /* not USE_X_TOOLKIT */
6044 Window window = FRAME_X_WINDOW (f);
6045 #endif /* not USE_X_TOOLKIT */
6046
6047 /* Setting PMaxSize caused various problems. */
6048 size_hints.flags = PResizeInc | PMinSize /* | PMaxSize */;
6049
6050 flexlines = f->height;
6051
6052 size_hints.x = f->output_data.x->left_pos;
6053 size_hints.y = f->output_data.x->top_pos;
6054
6055 #ifdef USE_X_TOOLKIT
6056 XtSetArg (al[ac], XtNwidth, &widget_width); ac++;
6057 XtSetArg (al[ac], XtNheight, &widget_height); ac++;
6058 XtGetValues (f->output_data.x->widget, al, ac);
6059 size_hints.height = widget_height;
6060 size_hints.width = widget_width;
6061 #else /* not USE_X_TOOLKIT */
6062 size_hints.height = PIXEL_HEIGHT (f);
6063 size_hints.width = PIXEL_WIDTH (f);
6064 #endif /* not USE_X_TOOLKIT */
6065
6066 size_hints.width_inc = FONT_WIDTH (f->output_data.x->font);
6067 size_hints.height_inc = f->output_data.x->line_height;
6068 size_hints.max_width
6069 = FRAME_X_DISPLAY_INFO (f)->width - CHAR_TO_PIXEL_WIDTH (f, 0);
6070 size_hints.max_height
6071 = FRAME_X_DISPLAY_INFO (f)->height - CHAR_TO_PIXEL_HEIGHT (f, 0);
6072
6073 /* Calculate the base and minimum sizes.
6074
6075 (When we use the X toolkit, we don't do it here.
6076 Instead we copy the values that the widgets are using, below.) */
6077 #ifndef USE_X_TOOLKIT
6078 {
6079 int base_width, base_height;
6080 int min_rows = 0, min_cols = 0;
6081
6082 base_width = CHAR_TO_PIXEL_WIDTH (f, 0);
6083 base_height = CHAR_TO_PIXEL_HEIGHT (f, 0);
6084
6085 check_frame_size (f, &min_rows, &min_cols);
6086
6087 /* The window manager uses the base width hints to calculate the
6088 current number of rows and columns in the frame while
6089 resizing; min_width and min_height aren't useful for this
6090 purpose, since they might not give the dimensions for a
6091 zero-row, zero-column frame.
6092
6093 We use the base_width and base_height members if we have
6094 them; otherwise, we set the min_width and min_height members
6095 to the size for a zero x zero frame. */
6096
6097 #ifdef HAVE_X11R4
6098 size_hints.flags |= PBaseSize;
6099 size_hints.base_width = base_width;
6100 size_hints.base_height = base_height;
6101 size_hints.min_width = base_width + min_cols * size_hints.width_inc;
6102 size_hints.min_height = base_height + min_rows * size_hints.height_inc;
6103 #else
6104 size_hints.min_width = base_width;
6105 size_hints.min_height = base_height;
6106 #endif
6107 }
6108
6109 /* If we don't need the old flags, we don't need the old hint at all. */
6110 if (flags)
6111 {
6112 size_hints.flags |= flags;
6113 goto no_read;
6114 }
6115 #endif /* not USE_X_TOOLKIT */
6116
6117 {
6118 XSizeHints hints; /* Sometimes I hate X Windows... */
6119 long supplied_return;
6120 int value;
6121
6122 #ifdef HAVE_X11R4
6123 value = XGetWMNormalHints (FRAME_X_DISPLAY (f), window, &hints,
6124 &supplied_return);
6125 #else
6126 value = XGetNormalHints (FRAME_X_DISPLAY (f), window, &hints);
6127 #endif
6128
6129 #ifdef USE_X_TOOLKIT
6130 size_hints.base_height = hints.base_height;
6131 size_hints.base_width = hints.base_width;
6132 size_hints.min_height = hints.min_height;
6133 size_hints.min_width = hints.min_width;
6134 #endif
6135
6136 if (flags)
6137 size_hints.flags |= flags;
6138 else
6139 {
6140 if (value == 0)
6141 hints.flags = 0;
6142 if (hints.flags & PSize)
6143 size_hints.flags |= PSize;
6144 if (hints.flags & PPosition)
6145 size_hints.flags |= PPosition;
6146 if (hints.flags & USPosition)
6147 size_hints.flags |= USPosition;
6148 if (hints.flags & USSize)
6149 size_hints.flags |= USSize;
6150 }
6151 }
6152
6153 no_read:
6154
6155 #ifdef PWinGravity
6156 size_hints.win_gravity = f->output_data.x->win_gravity;
6157 size_hints.flags |= PWinGravity;
6158
6159 if (user_position)
6160 {
6161 size_hints.flags &= ~ PPosition;
6162 size_hints.flags |= USPosition;
6163 }
6164 #endif /* PWinGravity */
6165
6166 #ifdef HAVE_X11R4
6167 XSetWMNormalHints (FRAME_X_DISPLAY (f), window, &size_hints);
6168 #else
6169 XSetNormalHints (FRAME_X_DISPLAY (f), window, &size_hints);
6170 #endif
6171 }
6172
6173 /* Used for IconicState or NormalState */
6174 x_wm_set_window_state (f, state)
6175 struct frame *f;
6176 int state;
6177 {
6178 #ifdef USE_X_TOOLKIT
6179 Arg al[1];
6180
6181 XtSetArg (al[0], XtNinitialState, state);
6182 XtSetValues (f->output_data.x->widget, al, 1);
6183 #else /* not USE_X_TOOLKIT */
6184 Window window = FRAME_X_WINDOW (f);
6185
6186 f->output_data.x->wm_hints.flags |= StateHint;
6187 f->output_data.x->wm_hints.initial_state = state;
6188
6189 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints);
6190 #endif /* not USE_X_TOOLKIT */
6191 }
6192
6193 x_wm_set_icon_pixmap (f, pixmap_id)
6194 struct frame *f;
6195 int pixmap_id;
6196 {
6197 Pixmap icon_pixmap;
6198
6199 #ifdef USE_X_TOOLKIT
6200 Window window = XtWindow (f->output_data.x->widget);
6201 #else
6202 Window window = FRAME_X_WINDOW (f);
6203 #endif
6204
6205 if (pixmap_id > 0)
6206 {
6207 icon_pixmap = x_bitmap_pixmap (f, pixmap_id);
6208 f->output_data.x->wm_hints.icon_pixmap = icon_pixmap;
6209 }
6210 else
6211 {
6212 /* It seems there is no way to turn off use of an icon pixmap.
6213 The following line does it, only if no icon has yet been created,
6214 for some window managers. But with mwm it crashes.
6215 Some people say it should clear the IconPixmapHint bit in this case,
6216 but that doesn't work, and the X consortium said it isn't the
6217 right thing at all. Since there is no way to win,
6218 best to explicitly give up. */
6219 #if 0
6220 f->output_data.x->wm_hints.icon_pixmap = None;
6221 #else
6222 return;
6223 #endif
6224 }
6225
6226 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
6227
6228 {
6229 Arg al[1];
6230 XtSetArg (al[0], XtNiconPixmap, icon_pixmap);
6231 XtSetValues (f->output_data.x->widget, al, 1);
6232 }
6233
6234 #else /* not USE_X_TOOLKIT */
6235
6236 f->output_data.x->wm_hints.flags |= IconPixmapHint;
6237 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints);
6238
6239 #endif /* not USE_X_TOOLKIT */
6240 }
6241
6242 x_wm_set_icon_position (f, icon_x, icon_y)
6243 struct frame *f;
6244 int icon_x, icon_y;
6245 {
6246 #ifdef USE_X_TOOLKIT
6247 Window window = XtWindow (f->output_data.x->widget);
6248 #else
6249 Window window = FRAME_X_WINDOW (f);
6250 #endif
6251
6252 f->output_data.x->wm_hints.flags |= IconPositionHint;
6253 f->output_data.x->wm_hints.icon_x = icon_x;
6254 f->output_data.x->wm_hints.icon_y = icon_y;
6255
6256 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints);
6257 }
6258
6259 \f
6260 /* Interface to fontset handler. */
6261
6262 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6263 struct font_info *
6264 x_get_font_info (f, font_idx)
6265 FRAME_PTR f;
6266 int font_idx;
6267 {
6268 return (FRAME_X_FONT_TABLE (f) + font_idx);
6269 }
6270
6271
6272 /* Return a list of names of available fonts matching PATTERN on frame
6273 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6274 to be listed. Frame F NULL means we have not yet created any
6275 frame on X, and consult the first display in x_display_list.
6276 MAXNAMES sets a limit on how many fonts to match. */
6277
6278 Lisp_Object
6279 x_list_fonts (f, pattern, size, maxnames)
6280 FRAME_PTR f;
6281 Lisp_Object pattern;
6282 int size;
6283 int maxnames;
6284 {
6285 Lisp_Object list = Qnil, patterns, newlist = Qnil, key, tem, second_best;
6286 Display *dpy = f != NULL ? FRAME_X_DISPLAY (f) : x_display_list->display;
6287
6288 patterns = Fassoc (pattern, Valternative_fontname_alist);
6289 if (NILP (patterns))
6290 patterns = Fcons (pattern, Qnil);
6291
6292 for (; CONSP (patterns); patterns = XCONS (patterns)->cdr)
6293 {
6294 int num_fonts;
6295 char **names;
6296
6297 pattern = XCONS (patterns)->car;
6298 /* See if we cached the result for this particular query. */
6299 if (f && (tem = XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->cdr,
6300 key = Fcons (pattern, make_number (maxnames)),
6301 !NILP (list = Fassoc (key, tem))))
6302 {
6303 list = Fcdr_safe (list);
6304 /* We have a cashed list. Don't have to get the list again. */
6305 goto label_cached;
6306 }
6307
6308 /* At first, put PATTERN in the cache. */
6309 BLOCK_INPUT;
6310 names = XListFonts (dpy, XSTRING (pattern)->data, maxnames, &num_fonts);
6311 UNBLOCK_INPUT;
6312
6313 if (names)
6314 {
6315 int i;
6316
6317 /* Make a list of all the fonts we got back.
6318 Store that in the font cache for the display. */
6319 for (i = 0; i < num_fonts; i++)
6320 {
6321 char *p = names[i];
6322 int average_width = -1, dashes = 0, width = 0;
6323
6324 /* Count the number of dashes in NAMES[I]. If there are
6325 14 dashes, and the field value following 12th dash
6326 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
6327 is usually too ugly to be used for editing. Let's
6328 ignore it. */
6329 while (*p)
6330 if (*p++ == '-')
6331 {
6332 dashes++;
6333 if (dashes == 7) /* PIXEL_SIZE field */
6334 width = atoi (p);
6335 else if (dashes == 12) /* AVERAGE_WIDTH field */
6336 average_width = atoi (p);
6337 }
6338 if (dashes < 14 || average_width != 0)
6339 {
6340 tem = build_string (names[i]);
6341 if (NILP (Fassoc (tem, list)))
6342 {
6343 if (STRINGP (Vx_pixel_size_width_font_regexp)
6344 && ((fast_c_string_match_ignore_case
6345 (Vx_pixel_size_width_font_regexp, names[i]))
6346 >= 0))
6347 /* We can set the value of PIXEL_SIZE to the
6348 width of this font. */
6349 list = Fcons (Fcons (tem, make_number (width)), list);
6350 else
6351 /* For the moment, width is not known. */
6352 list = Fcons (Fcons (tem, Qnil), list);
6353 }
6354 }
6355 }
6356 XFreeFontNames (names);
6357 }
6358
6359 /* Now store the result in the cache. */
6360 if (f != NULL)
6361 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->cdr
6362 = Fcons (Fcons (key, list),
6363 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->cdr);
6364
6365 label_cached:
6366 if (NILP (list)) continue; /* Try the remaining alternatives. */
6367
6368 newlist = second_best = Qnil;
6369 /* Make a list of the fonts that have the right width. */
6370 for (; CONSP (list); list = XCONS (list)->cdr)
6371 {
6372 tem = XCONS (list)->car;
6373
6374 if (!CONSP (tem) || NILP (XCONS (tem)->car))
6375 continue;
6376 if (!size)
6377 {
6378 newlist = Fcons (XCONS (tem)->car, newlist);
6379 continue;
6380 }
6381
6382 if (!INTEGERP (XCONS (tem)->cdr))
6383 {
6384 /* Since we have not yet known the size of this font, we
6385 must try slow function call XLoadQueryFont. */
6386 XFontStruct *thisinfo;
6387
6388 BLOCK_INPUT;
6389 thisinfo = XLoadQueryFont (dpy,
6390 XSTRING (XCONS (tem)->car)->data);
6391 UNBLOCK_INPUT;
6392
6393 if (thisinfo)
6394 {
6395 XCONS (tem)->cdr = make_number (thisinfo->max_bounds.width);
6396 XFreeFont (dpy, thisinfo);
6397 }
6398 else
6399 /* For unknown reason, the previous call of XListFont had
6400 retruned a font which can't be opened. Record the size
6401 as 0 not to try to open it again. */
6402 XCONS (tem)->cdr = make_number (0);
6403 }
6404 if (XINT (XCONS (tem)->cdr) == size)
6405 newlist = Fcons (XCONS (tem)->car, newlist);
6406 else if (NILP (second_best))
6407 second_best = tem;
6408 else if (XINT (XCONS (tem)->cdr) < size)
6409 {
6410 if (XINT (XCONS (second_best)->cdr) > size
6411 || XINT (XCONS (second_best)->cdr) < XINT (XCONS (tem)->cdr))
6412 second_best = tem;
6413 }
6414 else
6415 {
6416 if (XINT (XCONS (second_best)->cdr) > size
6417 && XINT (XCONS (second_best)->cdr) > XINT (XCONS (tem)->cdr))
6418 second_best = tem;
6419 }
6420 }
6421 if (!NILP (newlist))
6422 break;
6423 else if (!NILP (second_best))
6424 {
6425 newlist = Fcons (XCONS (second_best)->car, Qnil);
6426 break;
6427 }
6428 }
6429
6430 return newlist;
6431 }
6432
6433 /* Load font named FONTNAME of the size SIZE for frame F, and return a
6434 pointer to the structure font_info while allocating it dynamically.
6435 If SIZE is 0, load any size of font.
6436 If loading is failed, return NULL. */
6437
6438 struct font_info *
6439 x_load_font (f, fontname, size)
6440 struct frame *f;
6441 register char *fontname;
6442 int size;
6443 {
6444 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
6445 Lisp_Object font_names;
6446
6447 /* Get a list of all the fonts that match this name. Once we
6448 have a list of matching fonts, we compare them against the fonts
6449 we already have by comparing names. */
6450 font_names = x_list_fonts (f, build_string (fontname), size, 256);
6451
6452 if (!NILP (font_names))
6453 {
6454 Lisp_Object tail;
6455 int i;
6456
6457 for (i = 0; i < dpyinfo->n_fonts; i++)
6458 for (tail = font_names; CONSP (tail); tail = XCONS (tail)->cdr)
6459 if (!strcmp (dpyinfo->font_table[i].name,
6460 XSTRING (XCONS (tail)->car)->data)
6461 || !strcmp (dpyinfo->font_table[i].full_name,
6462 XSTRING (XCONS (tail)->car)->data))
6463 return (dpyinfo->font_table + i);
6464 }
6465
6466 /* Load the font and add it to the table. */
6467 {
6468 char *full_name;
6469 XFontStruct *font;
6470 struct font_info *fontp;
6471 unsigned long value;
6472
6473 /* If we have found fonts by x_list_font, load one of them. If
6474 not, we still try to load a font by the name given as FONTNAME
6475 because XListFonts (called in x_list_font) of some X server has
6476 a bug of not finding a font even if the font surely exists and
6477 is loadable by XLoadQueryFont. */
6478 if (!NILP (font_names))
6479 fontname = (char *) XSTRING (XCONS (font_names)->car)->data;
6480
6481 BLOCK_INPUT;
6482 font = (XFontStruct *) XLoadQueryFont (FRAME_X_DISPLAY (f), fontname);
6483 UNBLOCK_INPUT;
6484 if (!font)
6485 return NULL;
6486
6487 /* Do we need to create the table? */
6488 if (dpyinfo->font_table_size == 0)
6489 {
6490 dpyinfo->font_table_size = 16;
6491 dpyinfo->font_table
6492 = (struct font_info *) xmalloc (dpyinfo->font_table_size
6493 * sizeof (struct font_info));
6494 }
6495 /* Do we need to grow the table? */
6496 else if (dpyinfo->n_fonts
6497 >= dpyinfo->font_table_size)
6498 {
6499 dpyinfo->font_table_size *= 2;
6500 dpyinfo->font_table
6501 = (struct font_info *) xrealloc (dpyinfo->font_table,
6502 (dpyinfo->font_table_size
6503 * sizeof (struct font_info)));
6504 }
6505
6506 fontp = dpyinfo->font_table + dpyinfo->n_fonts;
6507
6508 /* Now fill in the slots of *FONTP. */
6509 BLOCK_INPUT;
6510 fontp->font = font;
6511 fontp->font_idx = dpyinfo->n_fonts;
6512 fontp->name = (char *) xmalloc (strlen (fontname) + 1);
6513 bcopy (fontname, fontp->name, strlen (fontname) + 1);
6514
6515 /* Try to get the full name of FONT. Put it in FULL_NAME. */
6516 full_name = 0;
6517 if (XGetFontProperty (font, XA_FONT, &value))
6518 {
6519 char *name = (char *) XGetAtomName (FRAME_X_DISPLAY (f), (Atom) value);
6520 char *p = name;
6521 int dashes = 0;
6522
6523 /* Count the number of dashes in the "full name".
6524 If it is too few, this isn't really the font's full name,
6525 so don't use it.
6526 In X11R4, the fonts did not come with their canonical names
6527 stored in them. */
6528 while (*p)
6529 {
6530 if (*p == '-')
6531 dashes++;
6532 p++;
6533 }
6534
6535 if (dashes >= 13)
6536 {
6537 full_name = (char *) xmalloc (p - name + 1);
6538 bcopy (name, full_name, p - name + 1);
6539 }
6540
6541 XFree (name);
6542 }
6543
6544 if (full_name != 0)
6545 fontp->full_name = full_name;
6546 else
6547 fontp->full_name = fontp->name;
6548
6549 fontp->size = font->max_bounds.width;
6550 fontp->height = font->max_bounds.ascent + font->max_bounds.descent;
6551
6552 if (NILP (font_names))
6553 {
6554 /* We come here because of a bug of XListFonts mentioned at
6555 the head of this block. Let's store this information in
6556 the cache for x_list_fonts. */
6557 Lisp_Object lispy_name = build_string (fontname);
6558 Lisp_Object lispy_full_name = build_string (fontp->full_name);
6559
6560 XCONS (dpyinfo->name_list_element)->cdr
6561 = Fcons (Fcons (Fcons (lispy_name, make_number (256)),
6562 Fcons (Fcons (lispy_full_name,
6563 make_number (fontp->size)),
6564 Qnil)),
6565 XCONS (dpyinfo->name_list_element)->cdr);
6566 if (full_name)
6567 XCONS (dpyinfo->name_list_element)->cdr
6568 = Fcons (Fcons (Fcons (lispy_full_name, make_number (256)),
6569 Fcons (Fcons (lispy_full_name,
6570 make_number (fontp->size)),
6571 Qnil)),
6572 XCONS (dpyinfo->name_list_element)->cdr);
6573 }
6574
6575 /* The slot `encoding' specifies how to map a character
6576 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
6577 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
6578 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
6579 0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
6580 2:0xA020..0xFF7F). For the moment, we don't know which charset
6581 uses this font. So, we set informatoin in fontp->encoding[1]
6582 which is never used by any charset. If mapping can't be
6583 decided, set FONT_ENCODING_NOT_DECIDED. */
6584 fontp->encoding[1]
6585 = (font->max_byte1 == 0
6586 /* 1-byte font */
6587 ? (font->min_char_or_byte2 < 0x80
6588 ? (font->max_char_or_byte2 < 0x80
6589 ? 0 /* 0x20..0x7F */
6590 : FONT_ENCODING_NOT_DECIDED) /* 0x20..0xFF */
6591 : 1) /* 0xA0..0xFF */
6592 /* 2-byte font */
6593 : (font->min_byte1 < 0x80
6594 ? (font->max_byte1 < 0x80
6595 ? (font->min_char_or_byte2 < 0x80
6596 ? (font->max_char_or_byte2 < 0x80
6597 ? 0 /* 0x2020..0x7F7F */
6598 : FONT_ENCODING_NOT_DECIDED) /* 0x2020..0x7FFF */
6599 : 3) /* 0x20A0..0x7FFF */
6600 : FONT_ENCODING_NOT_DECIDED) /* 0x20??..0xA0?? */
6601 : (font->min_char_or_byte2 < 0x80
6602 ? (font->max_char_or_byte2 < 0x80
6603 ? 2 /* 0xA020..0xFF7F */
6604 : FONT_ENCODING_NOT_DECIDED) /* 0xA020..0xFFFF */
6605 : 1))); /* 0xA0A0..0xFFFF */
6606
6607 fontp->baseline_offset
6608 = (XGetFontProperty (font, dpyinfo->Xatom_MULE_BASELINE_OFFSET, &value)
6609 ? (long) value : 0);
6610 fontp->relative_compose
6611 = (XGetFontProperty (font, dpyinfo->Xatom_MULE_RELATIVE_COMPOSE, &value)
6612 ? (long) value : 0);
6613 fontp->default_ascent
6614 = (XGetFontProperty (font, dpyinfo->Xatom_MULE_DEFAULT_ASCENT, &value)
6615 ? (long) value : 0);
6616
6617 UNBLOCK_INPUT;
6618 dpyinfo->n_fonts++;
6619
6620 return fontp;
6621 }
6622 }
6623
6624 /* Return a pointer to struct font_info of a font named FONTNAME for frame F.
6625 If no such font is loaded, return NULL. */
6626 struct font_info *
6627 x_query_font (f, fontname)
6628 struct frame *f;
6629 register char *fontname;
6630 {
6631 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
6632 int i;
6633
6634 for (i = 0; i < dpyinfo->n_fonts; i++)
6635 if (!strcmp (dpyinfo->font_table[i].name, fontname)
6636 || !strcmp (dpyinfo->font_table[i].full_name, fontname))
6637 return (dpyinfo->font_table + i);
6638 return NULL;
6639 }
6640
6641 \f
6642 /* Initialization. */
6643
6644 #ifdef USE_X_TOOLKIT
6645 static XrmOptionDescRec emacs_options[] = {
6646 {"-geometry", ".geometry", XrmoptionSepArg, NULL},
6647 {"-iconic", ".iconic", XrmoptionNoArg, (XtPointer) "yes"},
6648
6649 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
6650 XrmoptionSepArg, NULL},
6651 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg, NULL},
6652
6653 {"-T", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL},
6654 {"-wn", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL},
6655 {"-title", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL},
6656 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg, (XtPointer) NULL},
6657 {"-in", "*EmacsShell.iconName", XrmoptionSepArg, (XtPointer) NULL},
6658 {"-mc", "*pointerColor", XrmoptionSepArg, (XtPointer) NULL},
6659 {"-cr", "*cursorColor", XrmoptionSepArg, (XtPointer) NULL}
6660 };
6661 #endif /* USE_X_TOOLKIT */
6662
6663 static int x_initialized;
6664
6665 #ifdef MULTI_KBOARD
6666 /* Test whether two display-name strings agree up to the dot that separates
6667 the screen number from the server number. */
6668 static int
6669 same_x_server (name1, name2)
6670 char *name1, *name2;
6671 {
6672 int seen_colon = 0;
6673 for (; *name1 != '\0' && *name1 == *name2; name1++, name2++)
6674 {
6675 if (*name1 == ':')
6676 seen_colon++;
6677 if (seen_colon && *name1 == '.')
6678 return 1;
6679 }
6680 return (seen_colon
6681 && (*name1 == '.' || *name1 == '\0')
6682 && (*name2 == '.' || *name2 == '\0'));
6683 }
6684 #endif
6685
6686 struct x_display_info *
6687 x_term_init (display_name, xrm_option, resource_name)
6688 Lisp_Object display_name;
6689 char *xrm_option;
6690 char *resource_name;
6691 {
6692 Lisp_Object frame;
6693 char *defaultvalue;
6694 int connection;
6695 Display *dpy;
6696 struct x_display_info *dpyinfo;
6697 XrmDatabase xrdb;
6698
6699 BLOCK_INPUT;
6700
6701 if (!x_initialized)
6702 {
6703 x_initialize ();
6704 x_initialized = 1;
6705 }
6706
6707 #ifdef HAVE_X_I18N
6708 setlocale (LC_ALL, "");
6709 /* In case we just overrode what init_lread did, redo it. */
6710 setlocale (LC_NUMERIC, "C");
6711 setlocale (LC_TIME, "C");
6712 #endif
6713
6714 #ifdef USE_X_TOOLKIT
6715 /* weiner@footloose.sps.mot.com reports that this causes
6716 errors with X11R5:
6717 X protocol error: BadAtom (invalid Atom parameter)
6718 on protocol request 18skiloaf.
6719 So let's not use it until R6. */
6720 #ifdef HAVE_X11XTR6
6721 XtSetLanguageProc (NULL, NULL, NULL);
6722 #endif
6723
6724 {
6725 int argc = 0;
6726 char *argv[3];
6727
6728 argv[0] = "";
6729 argc = 1;
6730 if (xrm_option)
6731 {
6732 argv[argc++] = "-xrm";
6733 argv[argc++] = xrm_option;
6734 }
6735 dpy = XtOpenDisplay (Xt_app_con, XSTRING (display_name)->data,
6736 resource_name, EMACS_CLASS,
6737 emacs_options, XtNumber (emacs_options),
6738 &argc, argv);
6739
6740 #ifdef HAVE_X11XTR6
6741 /* I think this is to compensate for XtSetLanguageProc. */
6742 setlocale (LC_NUMERIC, "C");
6743 setlocale (LC_TIME, "C");
6744 #endif
6745 }
6746
6747 #else /* not USE_X_TOOLKIT */
6748 #ifdef HAVE_X11R5
6749 XSetLocaleModifiers ("");
6750 #endif
6751 dpy = XOpenDisplay (XSTRING (display_name)->data);
6752 #endif /* not USE_X_TOOLKIT */
6753
6754 /* Detect failure. */
6755 if (dpy == 0)
6756 {
6757 UNBLOCK_INPUT;
6758 return 0;
6759 }
6760
6761 /* We have definitely succeeded. Record the new connection. */
6762
6763 dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info));
6764
6765 #ifdef MULTI_KBOARD
6766 {
6767 struct x_display_info *share;
6768 Lisp_Object tail;
6769
6770 for (share = x_display_list, tail = x_display_name_list; share;
6771 share = share->next, tail = XCONS (tail)->cdr)
6772 if (same_x_server (XSTRING (XCONS (XCONS (tail)->car)->car)->data,
6773 XSTRING (display_name)->data))
6774 break;
6775 if (share)
6776 dpyinfo->kboard = share->kboard;
6777 else
6778 {
6779 dpyinfo->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
6780 init_kboard (dpyinfo->kboard);
6781 if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound))
6782 {
6783 char *vendor = ServerVendor (dpy);
6784 dpyinfo->kboard->Vsystem_key_alist
6785 = call1 (Qvendor_specific_keysyms,
6786 build_string (vendor ? vendor : ""));
6787 }
6788
6789 dpyinfo->kboard->next_kboard = all_kboards;
6790 all_kboards = dpyinfo->kboard;
6791 /* Don't let the initial kboard remain current longer than necessary.
6792 That would cause problems if a file loaded on startup tries to
6793 prompt in the minibuffer. */
6794 if (current_kboard == initial_kboard)
6795 current_kboard = dpyinfo->kboard;
6796 }
6797 dpyinfo->kboard->reference_count++;
6798 }
6799 #endif
6800
6801 /* Put this display on the chain. */
6802 dpyinfo->next = x_display_list;
6803 x_display_list = dpyinfo;
6804
6805 /* Put it on x_display_name_list as well, to keep them parallel. */
6806 x_display_name_list = Fcons (Fcons (display_name, Qnil),
6807 x_display_name_list);
6808 dpyinfo->name_list_element = XCONS (x_display_name_list)->car;
6809
6810 dpyinfo->display = dpy;
6811
6812 #if 0
6813 XSetAfterFunction (x_current_display, x_trace_wire);
6814 #endif /* ! 0 */
6815
6816 dpyinfo->x_id_name
6817 = (char *) xmalloc (XSTRING (Vinvocation_name)->size
6818 + XSTRING (Vsystem_name)->size
6819 + 2);
6820 sprintf (dpyinfo->x_id_name, "%s@%s",
6821 XSTRING (Vinvocation_name)->data, XSTRING (Vsystem_name)->data);
6822
6823 /* Figure out which modifier bits mean what. */
6824 x_find_modifier_meanings (dpyinfo);
6825
6826 /* Get the scroll bar cursor. */
6827 dpyinfo->vertical_scroll_bar_cursor
6828 = XCreateFontCursor (dpyinfo->display, XC_sb_v_double_arrow);
6829
6830 xrdb = x_load_resources (dpyinfo->display, xrm_option,
6831 resource_name, EMACS_CLASS);
6832 #ifdef HAVE_XRMSETDATABASE
6833 XrmSetDatabase (dpyinfo->display, xrdb);
6834 #else
6835 dpyinfo->display->db = xrdb;
6836 #endif
6837 /* Put the rdb where we can find it in a way that works on
6838 all versions. */
6839 dpyinfo->xrdb = xrdb;
6840
6841 dpyinfo->screen = ScreenOfDisplay (dpyinfo->display,
6842 DefaultScreen (dpyinfo->display));
6843 dpyinfo->visual = select_visual (dpyinfo->display, dpyinfo->screen,
6844 &dpyinfo->n_planes);
6845 dpyinfo->height = HeightOfScreen (dpyinfo->screen);
6846 dpyinfo->width = WidthOfScreen (dpyinfo->screen);
6847 dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen);
6848 dpyinfo->grabbed = 0;
6849 dpyinfo->reference_count = 0;
6850 dpyinfo->icon_bitmap_id = -1;
6851 dpyinfo->n_fonts = 0;
6852 dpyinfo->font_table_size = 0;
6853 dpyinfo->bitmaps = 0;
6854 dpyinfo->bitmaps_size = 0;
6855 dpyinfo->bitmaps_last = 0;
6856 dpyinfo->scratch_cursor_gc = 0;
6857 dpyinfo->mouse_face_mouse_frame = 0;
6858 dpyinfo->mouse_face_deferred_gc = 0;
6859 dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
6860 dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
6861 dpyinfo->mouse_face_face_id = 0;
6862 dpyinfo->mouse_face_window = Qnil;
6863 dpyinfo->mouse_face_mouse_x = dpyinfo->mouse_face_mouse_y = 0;
6864 dpyinfo->mouse_face_defer = 0;
6865 dpyinfo->x_focus_frame = 0;
6866 dpyinfo->x_focus_event_frame = 0;
6867 dpyinfo->x_highlight_frame = 0;
6868
6869 dpyinfo->Xatom_wm_protocols
6870 = XInternAtom (dpyinfo->display, "WM_PROTOCOLS", False);
6871 dpyinfo->Xatom_wm_take_focus
6872 = XInternAtom (dpyinfo->display, "WM_TAKE_FOCUS", False);
6873 dpyinfo->Xatom_wm_save_yourself
6874 = XInternAtom (dpyinfo->display, "WM_SAVE_YOURSELF", False);
6875 dpyinfo->Xatom_wm_delete_window
6876 = XInternAtom (dpyinfo->display, "WM_DELETE_WINDOW", False);
6877 dpyinfo->Xatom_wm_change_state
6878 = XInternAtom (dpyinfo->display, "WM_CHANGE_STATE", False);
6879 dpyinfo->Xatom_wm_configure_denied
6880 = XInternAtom (dpyinfo->display, "WM_CONFIGURE_DENIED", False);
6881 dpyinfo->Xatom_wm_window_moved
6882 = XInternAtom (dpyinfo->display, "WM_MOVED", False);
6883 dpyinfo->Xatom_editres
6884 = XInternAtom (dpyinfo->display, "Editres", False);
6885 dpyinfo->Xatom_CLIPBOARD
6886 = XInternAtom (dpyinfo->display, "CLIPBOARD", False);
6887 dpyinfo->Xatom_TIMESTAMP
6888 = XInternAtom (dpyinfo->display, "TIMESTAMP", False);
6889 dpyinfo->Xatom_TEXT
6890 = XInternAtom (dpyinfo->display, "TEXT", False);
6891 dpyinfo->Xatom_COMPOUND_TEXT
6892 = XInternAtom (dpyinfo->display, "COMPOUND_TEXT", False);
6893 dpyinfo->Xatom_DELETE
6894 = XInternAtom (dpyinfo->display, "DELETE", False);
6895 dpyinfo->Xatom_MULTIPLE
6896 = XInternAtom (dpyinfo->display, "MULTIPLE", False);
6897 dpyinfo->Xatom_INCR
6898 = XInternAtom (dpyinfo->display, "INCR", False);
6899 dpyinfo->Xatom_EMACS_TMP
6900 = XInternAtom (dpyinfo->display, "_EMACS_TMP_", False);
6901 dpyinfo->Xatom_TARGETS
6902 = XInternAtom (dpyinfo->display, "TARGETS", False);
6903 dpyinfo->Xatom_NULL
6904 = XInternAtom (dpyinfo->display, "NULL", False);
6905 dpyinfo->Xatom_ATOM_PAIR
6906 = XInternAtom (dpyinfo->display, "ATOM_PAIR", False);
6907 /* For properties of font. */
6908 dpyinfo->Xatom_PIXEL_SIZE
6909 = XInternAtom (dpyinfo->display, "PIXEL_SIZE", False);
6910 dpyinfo->Xatom_MULE_BASELINE_OFFSET
6911 = XInternAtom (dpyinfo->display, "_MULE_BASELINE_OFFSET", False);
6912 dpyinfo->Xatom_MULE_RELATIVE_COMPOSE
6913 = XInternAtom (dpyinfo->display, "_MULE_RELATIVE_COMPOSE", False);
6914 dpyinfo->Xatom_MULE_DEFAULT_ASCENT
6915 = XInternAtom (dpyinfo->display, "_MULE_DEFAULT_ASCENT", False);
6916
6917 dpyinfo->cut_buffers_initialized = 0;
6918
6919 connection = ConnectionNumber (dpyinfo->display);
6920 dpyinfo->connection = connection;
6921
6922 {
6923 char null_bits[1];
6924
6925 null_bits[0] = 0x00;
6926
6927 dpyinfo->null_pixel
6928 = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window,
6929 null_bits, 1, 1, (long) 0, (long) 0,
6930 1);
6931 }
6932
6933 #ifdef subprocesses
6934 /* This is only needed for distinguishing keyboard and process input. */
6935 if (connection != 0)
6936 add_keyboard_wait_descriptor (connection);
6937 #endif
6938
6939 #ifndef F_SETOWN_BUG
6940 #ifdef F_SETOWN
6941 #ifdef F_SETOWN_SOCK_NEG
6942 /* stdin is a socket here */
6943 fcntl (connection, F_SETOWN, -getpid ());
6944 #else /* ! defined (F_SETOWN_SOCK_NEG) */
6945 fcntl (connection, F_SETOWN, getpid ());
6946 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
6947 #endif /* ! defined (F_SETOWN) */
6948 #endif /* F_SETOWN_BUG */
6949
6950 #ifdef SIGIO
6951 if (interrupt_input)
6952 init_sigio (connection);
6953 #endif /* ! defined (SIGIO) */
6954
6955 #ifdef USE_LUCID
6956 /* Make sure that we have a valid font for dialog boxes
6957 so that Xt does not crash. */
6958 {
6959 Display *dpy = dpyinfo->display;
6960 XrmValue d, fr, to;
6961 Font font;
6962 int count;
6963
6964 d.addr = (XPointer)&dpy;
6965 d.size = sizeof (Display *);
6966 fr.addr = XtDefaultFont;
6967 fr.size = sizeof (XtDefaultFont);
6968 to.size = sizeof (Font *);
6969 to.addr = (XPointer)&font;
6970 count = x_catch_errors (dpy);
6971 if (!XtCallConverter (dpy, XtCvtStringToFont, &d, 1, &fr, &to, NULL))
6972 abort ();
6973 if (x_had_errors_p (dpy) || !XQueryFont (dpy, font))
6974 XrmPutLineResource (&xrdb, "Emacs.dialog.*.font: 9x15");
6975 x_uncatch_errors (dpy, count);
6976 }
6977 #endif
6978
6979
6980 UNBLOCK_INPUT;
6981
6982 return dpyinfo;
6983 }
6984 \f
6985 /* Get rid of display DPYINFO, assuming all frames are already gone,
6986 and without sending any more commands to the X server. */
6987
6988 void
6989 x_delete_display (dpyinfo)
6990 struct x_display_info *dpyinfo;
6991 {
6992 delete_keyboard_wait_descriptor (dpyinfo->connection);
6993
6994 /* Discard this display from x_display_name_list and x_display_list.
6995 We can't use Fdelq because that can quit. */
6996 if (! NILP (x_display_name_list)
6997 && EQ (XCONS (x_display_name_list)->car, dpyinfo->name_list_element))
6998 x_display_name_list = XCONS (x_display_name_list)->cdr;
6999 else
7000 {
7001 Lisp_Object tail;
7002
7003 tail = x_display_name_list;
7004 while (CONSP (tail) && CONSP (XCONS (tail)->cdr))
7005 {
7006 if (EQ (XCONS (XCONS (tail)->cdr)->car,
7007 dpyinfo->name_list_element))
7008 {
7009 XCONS (tail)->cdr = XCONS (XCONS (tail)->cdr)->cdr;
7010 break;
7011 }
7012 tail = XCONS (tail)->cdr;
7013 }
7014 }
7015
7016 if (x_display_list == dpyinfo)
7017 x_display_list = dpyinfo->next;
7018 else
7019 {
7020 struct x_display_info *tail;
7021
7022 for (tail = x_display_list; tail; tail = tail->next)
7023 if (tail->next == dpyinfo)
7024 tail->next = tail->next->next;
7025 }
7026
7027 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
7028 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
7029 XrmDestroyDatabase (dpyinfo->xrdb);
7030 #endif
7031 #endif
7032 #ifdef MULTI_KBOARD
7033 if (--dpyinfo->kboard->reference_count == 0)
7034 delete_kboard (dpyinfo->kboard);
7035 #endif
7036 xfree (dpyinfo->font_table);
7037 xfree (dpyinfo->x_id_name);
7038 xfree (dpyinfo);
7039 }
7040 \f
7041 /* Set up use of X before we make the first connection. */
7042
7043 x_initialize ()
7044 {
7045 clear_frame_hook = XTclear_frame;
7046 clear_end_of_line_hook = XTclear_end_of_line;
7047 ins_del_lines_hook = XTins_del_lines;
7048 change_line_highlight_hook = XTchange_line_highlight;
7049 insert_glyphs_hook = XTinsert_glyphs;
7050 write_glyphs_hook = XTwrite_glyphs;
7051 delete_glyphs_hook = XTdelete_glyphs;
7052 ring_bell_hook = XTring_bell;
7053 reset_terminal_modes_hook = XTreset_terminal_modes;
7054 set_terminal_modes_hook = XTset_terminal_modes;
7055 update_begin_hook = XTupdate_begin;
7056 update_end_hook = XTupdate_end;
7057 set_terminal_window_hook = XTset_terminal_window;
7058 read_socket_hook = XTread_socket;
7059 frame_up_to_date_hook = XTframe_up_to_date;
7060 cursor_to_hook = XTcursor_to;
7061 reassert_line_highlight_hook = XTreassert_line_highlight;
7062 mouse_position_hook = XTmouse_position;
7063 frame_rehighlight_hook = XTframe_rehighlight;
7064 frame_raise_lower_hook = XTframe_raise_lower;
7065 set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
7066 condemn_scroll_bars_hook = XTcondemn_scroll_bars;
7067 redeem_scroll_bar_hook = XTredeem_scroll_bar;
7068 judge_scroll_bars_hook = XTjudge_scroll_bars;
7069
7070 scroll_region_ok = 1; /* we'll scroll partial frames */
7071 char_ins_del_ok = 0; /* just as fast to write the line */
7072 line_ins_del_ok = 1; /* we'll just blt 'em */
7073 fast_clear_end_of_line = 1; /* X does this well */
7074 memory_below_frame = 0; /* we don't remember what scrolls
7075 off the bottom */
7076 baud_rate = 19200;
7077
7078 x_noop_count = 0;
7079
7080 /* Try to use interrupt input; if we can't, then start polling. */
7081 Fset_input_mode (Qt, Qnil, Qt, Qnil);
7082
7083 #ifdef USE_X_TOOLKIT
7084 XtToolkitInitialize ();
7085 Xt_app_con = XtCreateApplicationContext ();
7086 XtAppSetFallbackResources (Xt_app_con, Xt_default_resources);
7087 #endif
7088
7089 /* Note that there is no real way portable across R3/R4 to get the
7090 original error handler. */
7091 XSetErrorHandler (x_error_handler);
7092 XSetIOErrorHandler (x_io_error_quitter);
7093
7094 /* Disable Window Change signals; they are handled by X events. */
7095 #ifdef SIGWINCH
7096 signal (SIGWINCH, SIG_DFL);
7097 #endif /* ! defined (SIGWINCH) */
7098
7099 signal (SIGPIPE, x_connection_signal);
7100 }
7101
7102 void
7103 syms_of_xterm ()
7104 {
7105 staticpro (&x_error_message_string);
7106 x_error_message_string = Qnil;
7107
7108 staticpro (&x_display_name_list);
7109 x_display_name_list = Qnil;
7110
7111 staticpro (&last_mouse_scroll_bar);
7112 last_mouse_scroll_bar = Qnil;
7113
7114 staticpro (&Qvendor_specific_keysyms);
7115 Qvendor_specific_keysyms = intern ("vendor-specific-keysyms");
7116
7117 staticpro (&last_mouse_press_frame);
7118 last_mouse_press_frame = Qnil;
7119 }
7120
7121 #endif /* not HAVE_X_WINDOWS */