1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 1996 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Xt features made by Fred Pierresteguy. */
23 /* On 4.3 these lose if they come after xterm.h. */
24 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
25 /* Putting these at the beginning seems to be standard for other .c files. */
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"
39 #include "blockinput.h"
41 /* This may include sys/types.h, and that somehow loses
42 if this is not done before the other system files. */
44 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
55 #include <sys/ioctl.h>
56 #endif /* ! defined (BSD_SYSTEM) */
61 #ifndef INCLUDED_FCNTL
68 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
69 /* #include <sys/param.h> */
72 #include "dispextern.h"
73 #include "termhooks.h"
85 #include "intervals.h"
88 #include <X11/Shell.h>
92 extern void free_frame_menubar ();
93 extern FRAME_PTR
x_menubar_window_to_frame ();
94 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
96 extern void _XEditResCheckMessages ();
97 #endif /* not NO_EDITRES */
98 #endif /* USE_X_TOOLKIT */
100 #ifndef USE_X_TOOLKIT
101 #define x_any_window_to_frame x_window_to_frame
102 #define x_top_window_to_frame x_window_to_frame
107 #ifndef XtNinitialState
108 #define XtNinitialState "initialState"
112 #ifdef HAVE_SETLOCALE
113 /* So we can do setlocale. */
118 /* memmove will be defined as a macro in Xfuncs.h unless
119 <string.h> is included beforehand. The declaration for memmove in
120 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
125 #define min(a,b) ((a)<(b) ? (a) : (b))
128 #define max(a,b) ((a)>(b) ? (a) : (b))
131 /* This is a chain of structures for all the X displays currently in use. */
132 struct x_display_info
*x_display_list
;
134 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
135 one for each element of x_display_list and in the same order.
136 NAME is the name of the frame.
137 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
138 Lisp_Object x_display_name_list
;
140 /* Frame being updated by update_frame. This is declared in term.c.
141 This is set by update_begin and looked at by all the
142 XT functions. It is zero while not inside an update.
143 In that case, the XT functions assume that `selected_frame'
144 is the frame to apply to. */
145 extern struct frame
*updating_frame
;
147 extern waiting_for_input
;
149 /* This is a frame waiting to be autoraised, within XTread_socket. */
150 struct frame
*pending_autoraise_frame
;
153 /* The application context for Xt use. */
154 XtAppContext Xt_app_con
;
156 static String Xt_default_resources
[] =
162 /* During an update, maximum vpos for ins/del line operations to affect. */
164 static int flexlines
;
166 /* During an update, nonzero if chars output now should be highlighted. */
168 static int highlight
;
170 /* Nominal cursor position -- where to draw output.
171 During an update, these are different from the cursor-box position. */
178 Formerly, we used PointerMotionHintMask (in STANDARD_EVENT_MASK)
179 so that we would have to call XQueryPointer after each MotionNotify
180 event to ask for another such event. However, this made mouse tracking
181 slow, and there was a bug that made it eventually stop.
183 Simply asking for MotionNotify all the time seems to work better.
185 In order to avoid asking for motion events and then throwing most
186 of them away or busy-polling the server for mouse positions, we ask
187 the server for pointer motion hints. This means that we get only
188 one event per group of mouse movements. "Groups" are delimited by
189 other kinds of events (focus changes and button clicks, for
190 example), or by XQueryPointer calls; when one of these happens, we
191 get another MotionNotify event the next time the mouse moves. This
192 is at least as efficient as getting motion events when mouse
193 tracking is on, and I suspect only negligibly worse when tracking
196 /* Where the mouse was last time we reported a mouse event. */
197 static FRAME_PTR last_mouse_frame
;
198 static XRectangle last_mouse_glyph
;
200 static Lisp_Object last_mouse_press_frame
;
202 /* The scroll bar in which the last X motion event occurred.
204 If the last X motion event occurred in a scroll bar, we set this
205 so XTmouse_position can know whether to report a scroll bar motion or
208 If the last X motion event didn't occur in a scroll bar, we set this
209 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
210 static Lisp_Object last_mouse_scroll_bar
;
212 /* This is a hack. We would really prefer that XTmouse_position would
213 return the time associated with the position it returns, but there
214 doesn't seem to be any way to wrest the timestamp from the server
215 along with the position query. So, we just keep track of the time
216 of the last movement we received, and return that in hopes that
217 it's somewhat accurate. */
218 static Time last_mouse_movement_time
;
220 /* Incremented by XTread_socket whenever it really tries to read events. */
222 static int volatile input_signal_count
;
224 static int input_signal_count
;
227 /* Used locally within XTread_socket. */
228 static int x_noop_count
;
230 /* Initial values of argv and argc. */
231 extern char **initial_argv
;
232 extern int initial_argc
;
234 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
236 /* Tells if a window manager is present or not. */
238 extern Lisp_Object Vx_no_window_manager
;
240 extern Lisp_Object Qface
, Qmouse_face
;
244 /* A mask of extra modifier bits to put into every keyboard char. */
245 extern int extra_keyboard_modifiers
;
247 static Lisp_Object Qvendor_specific_keysyms
;
249 extern XrmDatabase
x_load_resources ();
251 extern Lisp_Object
x_icon_type ();
253 void x_delete_display ();
255 static void redraw_previous_char ();
256 static void redraw_following_char ();
257 static unsigned int x_x_to_emacs_modifiers ();
259 static int fast_find_position ();
260 static void note_mouse_highlight ();
261 static void clear_mouse_face ();
262 static void show_mouse_face ();
263 static void do_line_dance ();
265 static int XTcursor_to ();
266 static int XTclear_end_of_line ();
267 static int x_io_error_quitter ();
268 void x_catch_errors ();
269 void x_uncatch_errors ();
272 /* This is a function useful for recording debugging information
273 about the sequence of occurrences in this file. */
281 struct record event_record
[100];
283 int event_record_index
;
285 record_event (locus
, type
)
289 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
290 event_record_index
= 0;
292 event_record
[event_record_index
].locus
= locus
;
293 event_record
[event_record_index
].type
= type
;
294 event_record_index
++;
299 /* Return the struct x_display_info corresponding to DPY. */
301 struct x_display_info
*
302 x_display_info_for_display (dpy
)
305 struct x_display_info
*dpyinfo
;
307 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
308 if (dpyinfo
->display
== dpy
)
314 /* Starting and ending updates.
316 These hooks are called by update_frame at the beginning and end
317 of a frame update. We record in `updating_frame' the identity
318 of the frame being updated, so that the XT... functions do not
319 need to take a frame as argument. Most of the XT... functions
320 should never be called except during an update, the only exceptions
321 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
332 flexlines
= f
->height
;
337 curs_x
= FRAME_CURSOR_X (f
);
338 curs_y
= FRAME_CURSOR_Y (f
);
340 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
342 /* Don't do highlighting for mouse motion during the update. */
343 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 1;
345 /* If the frame needs to be redrawn,
346 simply forget about any prior mouse highlighting. */
347 if (FRAME_GARBAGED_P (f
))
348 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= Qnil
;
350 if (!NILP (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
352 int firstline
, lastline
, i
;
353 struct window
*w
= XWINDOW (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
);
355 /* Find the first, and the last+1, lines affected by redisplay. */
356 for (firstline
= 0; firstline
< f
->height
; firstline
++)
357 if (FRAME_DESIRED_GLYPHS (f
)->enable
[firstline
])
360 lastline
= f
->height
;
361 for (i
= f
->height
- 1; i
>= 0; i
--)
363 if (FRAME_DESIRED_GLYPHS (f
)->enable
[i
])
369 /* Can we tell that this update does not affect the window
370 where the mouse highlight is? If so, no need to turn off.
371 Likewise, don't do anything if the frame is garbaged;
372 in that case, the FRAME_CURRENT_GLYPHS that we would use
373 are all wrong, and we will redisplay that line anyway. */
374 if (! (firstline
> (XFASTINT (w
->top
) + window_internal_height (w
))
375 || lastline
< XFASTINT (w
->top
)))
376 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
392 x_display_cursor (f
, 1, curs_x
, curs_y
);
394 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
396 /* This fails in the case of having updated only the echo area
397 if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS
398 has no relation to the current contents, and its charstarts
399 have no relation to the contents of the window-buffer.
400 I don't know a clean way to check
401 for that case. window_end_valid isn't set up yet. */
402 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
403 note_mouse_highlight (f
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
404 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
407 XFlush (FRAME_X_DISPLAY (f
));
411 /* This is called after a redisplay on frame F. */
414 XTframe_up_to_date (f
)
418 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
419 || f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
421 note_mouse_highlight (FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
,
422 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
423 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
424 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 0;
429 /* External interface to control of standout mode.
430 Call this when about to modify line at position VPOS
431 and not change whether it is highlighted. */
433 XTreassert_line_highlight (new, vpos
)
439 /* Call this when about to modify line at position VPOS
440 and change whether it is highlighted. */
443 XTchange_line_highlight (new_highlight
, vpos
, first_unused_hpos
)
444 int new_highlight
, vpos
, first_unused_hpos
;
446 highlight
= new_highlight
;
447 XTcursor_to (vpos
, 0);
448 XTclear_end_of_line (FRAME_WINDOW_WIDTH (updating_frame
));
451 /* This is used when starting Emacs and when restarting after suspend.
452 When starting Emacs, no X window is mapped. And nothing must be done
453 to Emacs's own window if it is suspended (though that rarely happens). */
456 XTset_terminal_modes ()
460 /* This is called when exiting or suspending Emacs.
461 Exiting will make the X-windows go away, and suspending
462 requires no action. */
465 XTreset_terminal_modes ()
467 /* XTclear_frame (); */
470 /* Set the nominal cursor position of the frame.
471 This is where display update commands will take effect.
472 This does not affect the place where the cursor-box is displayed. */
475 XTcursor_to (row
, col
)
476 register int row
, col
;
484 if (updating_frame
== 0)
487 x_display_cursor (selected_frame
, 1, curs_x
, curs_y
);
488 XFlush (FRAME_X_DISPLAY (selected_frame
));
493 /* Display a sequence of N glyphs found at GP.
494 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
495 HL is 1 if this text is highlighted, 2 if the cursor is on it,
496 3 if should appear in its mouse-face.
497 JUST_FOREGROUND if 1 means draw only the foreground;
498 don't alter the background.
500 FONT is the default font to use (for glyphs whose font-code is 0).
502 Since the display generation code is responsible for calling
503 compute_char_face and compute_glyph_face on everything it puts in
504 the display structure, we can assume that the face code on each
505 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
506 to which we can actually apply intern_face.
507 Call this function with input blocked. */
510 /* This is the multi-face code. */
513 dumpglyphs (f
, left
, top
, gp
, n
, hl
, just_foreground
)
516 register GLYPH
*gp
; /* Points to first GLYPH. */
517 register int n
; /* Number of glyphs to display. */
521 /* Holds characters to be displayed. */
522 char *buf
= (char *) alloca (FRAME_WINDOW_WIDTH (f
) * sizeof (*buf
));
523 register char *cp
; /* Steps through buf[]. */
524 register int tlen
= GLYPH_TABLE_LENGTH
;
525 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
526 Window window
= FRAME_X_WINDOW (f
);
527 int orig_left
= left
;
531 /* Get the face-code of the next GLYPH. */
535 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
536 cf
= FAST_GLYPH_FACE (g
);
538 /* Find the run of consecutive glyphs with the same face-code.
539 Extract their character codes into BUF. */
544 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
545 if (FAST_GLYPH_FACE (g
) != cf
)
548 *cp
++ = FAST_GLYPH_CHAR (g
);
553 /* LEN gets the length of the run. */
556 /* Now output this run of chars, with the font and pixel values
557 determined by the face code CF. */
559 struct face
*face
= FRAME_DEFAULT_FACE (f
);
560 XFontStruct
*font
= FACE_FONT (face
);
561 GC gc
= FACE_GC (face
);
564 /* HL = 3 means use a mouse face previously chosen. */
566 cf
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
;
568 /* First look at the face of the text itself. */
571 /* It's possible for the display table to specify
572 a face code that is out of range. Use 0 in that case. */
573 if (cf
< 0 || cf
>= FRAME_N_COMPUTED_FACES (f
)
574 || FRAME_COMPUTED_FACES (f
) [cf
] == 0)
578 face
= FRAME_MODE_LINE_FACE (f
);
580 face
= intern_face (f
, FRAME_COMPUTED_FACES (f
) [cf
]);
581 font
= FACE_FONT (face
);
583 if (FACE_STIPPLE (face
))
587 /* Then comes the distinction between modeline and normal text. */
592 face
= FRAME_MODE_LINE_FACE (f
);
593 font
= FACE_FONT (face
);
595 if (FACE_STIPPLE (face
))
599 #define FACE_DEFAULT (~0)
601 /* Now override that if the cursor's on this character. */
604 /* The cursor overrides stippling. */
608 || face
->font
== (XFontStruct
*) FACE_DEFAULT
609 || face
->font
== f
->output_data
.x
->font
)
610 && face
->background
== f
->output_data
.x
->background_pixel
611 && face
->foreground
== f
->output_data
.x
->foreground_pixel
)
613 gc
= f
->output_data
.x
->cursor_gc
;
615 /* Cursor on non-default face: must merge. */
621 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
622 xgcv
.foreground
= face
->background
;
623 /* If the glyph would be invisible,
624 try a different foreground. */
625 if (xgcv
.foreground
== xgcv
.background
)
626 xgcv
.foreground
= face
->foreground
;
627 if (xgcv
.foreground
== xgcv
.background
)
628 xgcv
.foreground
= f
->output_data
.x
->cursor_foreground_pixel
;
629 if (xgcv
.foreground
== xgcv
.background
)
630 xgcv
.foreground
= face
->foreground
;
631 /* Make sure the cursor is distinct from text in this face. */
632 if (xgcv
.background
== face
->background
633 && xgcv
.foreground
== face
->foreground
)
635 xgcv
.background
= face
->foreground
;
636 xgcv
.foreground
= face
->background
;
638 xgcv
.font
= face
->font
->fid
;
639 xgcv
.graphics_exposures
= 0;
640 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
641 if (FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
)
642 XChangeGC (FRAME_X_DISPLAY (f
),
643 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
,
646 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
647 = XCreateGC (FRAME_X_DISPLAY (f
), window
, mask
, &xgcv
);
648 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
650 /* If this code is restored, it must also reset to the default stipple
652 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
653 XSetStipple (FRAME_X_DISPLAY (f
), gc
, face
->stipple
);
658 if (font
== (XFontStruct
*) FACE_DEFAULT
)
659 font
= f
->output_data
.x
->font
;
662 XDrawString (FRAME_X_DISPLAY (f
), window
, gc
,
663 left
, top
+ FONT_BASE (font
), buf
, len
);
668 /* Turn stipple on. */
669 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillOpaqueStippled
);
671 /* Draw stipple on background. */
672 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
674 FONT_WIDTH (font
) * len
,
677 /* Turn stipple off. */
678 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillSolid
);
680 /* Draw the text, solidly, onto the stipple pattern. */
681 XDrawString (FRAME_X_DISPLAY (f
), window
, gc
,
682 left
, top
+ FONT_BASE (font
), buf
, len
);
685 XDrawImageString (FRAME_X_DISPLAY (f
), window
, gc
,
686 left
, top
+ FONT_BASE (font
), buf
, len
);
688 /* Clear the rest of the line's height. */
689 if (f
->output_data
.x
->line_height
!= FONT_HEIGHT (font
))
690 XClearArea (FRAME_X_DISPLAY (f
), window
, left
,
691 top
+ FONT_HEIGHT (font
),
692 FONT_WIDTH (font
) * len
,
693 /* This is how many pixels of height
695 f
->output_data
.x
->line_height
- FONT_HEIGHT (font
),
699 #if 0 /* Doesn't work, because it uses FRAME_CURRENT_GLYPHS,
700 which often is not up to date yet. */
701 if (!just_foreground
)
703 if (left
== orig_left
)
704 redraw_previous_char (f
, PIXEL_TO_CHAR_COL (f
, left
),
705 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
707 redraw_following_char (f
, PIXEL_TO_CHAR_COL (f
, left
+ len
* FONT_WIDTH (font
)),
708 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
712 /* We should probably check for XA_UNDERLINE_POSITION and
713 XA_UNDERLINE_THICKNESS properties on the font, but let's
714 just get the thing working, and come back to that. */
716 int underline_position
= 1;
718 if (font
->descent
<= underline_position
)
719 underline_position
= font
->descent
- 1;
722 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
726 + underline_position
),
727 len
* FONT_WIDTH (font
), 1);
730 left
+= len
* FONT_WIDTH (font
);
737 /* This is the old single-face code. */
740 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
743 register GLYPH
*gp
; /* Points to first GLYPH. */
744 register int n
; /* Number of glyphs to display. */
749 Window window
= FRAME_X_WINDOW (f
);
750 GC drawing_gc
= (hl
== 2 ? f
->output_data
.x
->cursor_gc
751 : (hl
? f
->output_data
.x
->reverse_gc
752 : f
->output_data
.x
->normal_gc
));
754 if (sizeof (GLYPH
) == sizeof (XChar2b
))
755 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
756 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
757 else if (sizeof (GLYPH
) == sizeof (unsigned char))
758 XDrawImageString (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
759 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
761 /* What size of glyph ARE you using? And does X have a function to
767 /* Output some text at the nominal frame cursor position.
768 Advance the cursor over the text.
769 Output LEN glyphs at START.
771 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
772 controls the pixel values used for foreground and background. */
775 XTwrite_glyphs (start
, len
)
776 register GLYPH
*start
;
779 register int temp_length
;
790 /* If not within an update,
791 output at the frame's visible cursor. */
792 curs_x
= f
->cursor_x
;
793 curs_y
= f
->cursor_y
;
797 CHAR_TO_PIXEL_COL (f
, curs_x
),
798 CHAR_TO_PIXEL_ROW (f
, curs_y
),
799 start
, len
, highlight
, 0);
801 /* If we drew on top of the cursor, note that it is turned off. */
802 if (curs_y
== f
->phys_cursor_y
803 && curs_x
<= f
->phys_cursor_x
804 && curs_x
+ len
> f
->phys_cursor_x
)
805 f
->phys_cursor_on
= 0;
807 if (updating_frame
== 0)
808 x_display_cursor (f
, 1, FRAME_CURSOR_X (f
) + len
, FRAME_CURSOR_Y (f
));
815 /* Clear to the end of the line.
816 Erase the current text line from the nominal cursor position (inclusive)
817 to column FIRST_UNUSED (exclusive). The idea is that everything
818 from FIRST_UNUSED onward is already erased. */
821 XTclear_end_of_line (first_unused
)
822 register int first_unused
;
824 struct frame
*f
= updating_frame
;
830 if (curs_y
< 0 || curs_y
>= f
->height
)
832 if (first_unused
<= 0)
835 if (first_unused
>= FRAME_WINDOW_WIDTH (f
))
836 first_unused
= FRAME_WINDOW_WIDTH (f
);
838 first_unused
+= FRAME_LEFT_SCROLL_BAR_WIDTH (f
);
844 /* Notice if the cursor will be cleared by this operation. */
845 if (curs_y
== f
->phys_cursor_y
846 && curs_x
<= f
->phys_cursor_x
847 && f
->phys_cursor_x
< first_unused
)
848 f
->phys_cursor_on
= 0;
850 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
851 CHAR_TO_PIXEL_COL (f
, curs_x
),
852 CHAR_TO_PIXEL_ROW (f
, curs_y
),
853 FONT_WIDTH (f
->output_data
.x
->font
) * (first_unused
- curs_x
),
854 f
->output_data
.x
->line_height
, False
);
856 redraw_previous_char (f
, curs_x
, curs_y
, highlight
);
866 struct frame
*f
= updating_frame
;
871 f
->phys_cursor_on
= 0; /* Cursor not visible. */
872 curs_x
= 0; /* Nominal cursor position is top left. */
877 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
879 /* We have to clear the scroll bars, too. If we have changed
880 colors or something like that, then they should be notified. */
881 x_scroll_bar_clear (f
);
883 XFlush (FRAME_X_DISPLAY (f
));
888 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
889 always contain the right glyphs to use.
891 It also needs to be changed to look at the details of the font and
892 see whether there is really overlap, and do nothing when there is
893 not. This can use font_char_overlap_left and font_char_overlap_right,
894 but just how to use them is not clear. */
896 /* Erase the character (if any) at the position just before X, Y in frame F,
897 then redraw it and the character before it.
898 This is necessary when we erase starting at X,
899 in case the character after X overlaps into the one before X.
900 Call this function with input blocked. */
903 redraw_previous_char (f
, x
, y
, highlight_flag
)
908 /* Erase the character before the new ones, in case
909 what was here before overlaps it.
910 Reoutput that character, and the previous character
911 (in case the previous character overlaps it). */
917 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
918 CHAR_TO_PIXEL_COL (f
, x
- 1),
919 CHAR_TO_PIXEL_ROW (f
, y
),
920 FONT_WIDTH (f
->output_data
.x
->font
),
921 f
->output_data
.x
->line_height
, False
);
923 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
924 CHAR_TO_PIXEL_ROW (f
, y
),
925 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
926 x
- start_x
, highlight_flag
, 1);
930 /* Erase the character (if any) at the position X, Y in frame F,
931 then redraw it and the character after it.
932 This is necessary when we erase endng at X,
933 in case the character after X overlaps into the one before X.
934 Call this function with input blocked. */
937 redraw_following_char (f
, x
, y
, highlight_flag
)
942 int limit
= FRAME_CURRENT_GLYPHS (f
)->used
[y
];
943 /* Erase the character after the new ones, in case
944 what was here before overlaps it.
945 Reoutput that character, and the following character
946 (in case the following character overlaps it). */
948 && FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
] != SPACEGLYPH
)
953 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
954 CHAR_TO_PIXEL_COL (f
, x
),
955 CHAR_TO_PIXEL_ROW (f
, y
),
956 FONT_WIDTH (f
->output_data
.x
->font
),
957 f
->output_data
.x
->line_height
, False
);
959 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, x
),
960 CHAR_TO_PIXEL_ROW (f
, y
),
961 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
],
962 end_x
- x
, highlight_flag
, 1);
967 #if 0 /* Not in use yet */
969 /* Return 1 if character C in font F extends past its left edge. */
972 font_char_overlap_left (font
, c
)
978 /* Find the bounding-box info for C. */
979 if (font
->per_char
== 0)
980 s
= &font
->max_bounds
;
983 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
986 /* Decode char into row number (byte 1) and code within row (byte 2). */
989 if (!(within
>= font
->min_char_or_byte2
990 && within
<= font
->max_char_or_byte2
991 && row
>= font
->min_byte1
992 && row
<= font
->max_byte1
))
994 /* If char is out of range, try the font's default char instead. */
995 c
= font
->default_char
;
996 row
= c
>> (BITS_PER_INT
- 8);
999 if (!(within
>= font
->min_char_or_byte2
1000 && within
<= font
->max_char_or_byte2
1001 && row
>= font
->min_byte1
1002 && row
<= font
->max_byte1
))
1003 /* Still out of range means this char does not overlap. */
1006 /* We found the info for this char. */
1007 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1011 return (s
&& s
->lbearing
< 0);
1014 /* Return 1 if character C in font F extends past its right edge. */
1017 font_char_overlap_right (font
, c
)
1023 /* Find the bounding-box info for C. */
1024 if (font
->per_char
== 0)
1025 s
= &font
->max_bounds
;
1028 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1031 /* Decode char into row number (byte 1) and code within row (byte 2). */
1034 if (!(within
>= font
->min_char_or_byte2
1035 && within
<= font
->max_char_or_byte2
1036 && row
>= font
->min_byte1
1037 && row
<= font
->max_byte1
))
1039 /* If char is out of range, try the font's default char instead. */
1040 c
= font
->default_char
;
1041 row
= c
>> (BITS_PER_INT
- 8);
1044 if (!(within
>= font
->min_char_or_byte2
1045 && within
<= font
->max_char_or_byte2
1046 && row
>= font
->min_byte1
1047 && row
<= font
->max_byte1
))
1048 /* Still out of range means this char does not overlap. */
1051 /* We found the info for this char. */
1052 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1056 return (s
&& s
->rbearing
>= s
->width
);
1060 /* Invert the middle quarter of the frame for .15 sec. */
1062 /* We use the select system call to do the waiting, so we have to make sure
1063 it's available. If it isn't, we just won't do visual bells. */
1064 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1066 /* Subtract the `struct timeval' values X and Y,
1067 storing the result in RESULT.
1068 Return 1 if the difference is negative, otherwise 0. */
1071 timeval_subtract (result
, x
, y
)
1072 struct timeval
*result
, x
, y
;
1074 /* Perform the carry for the later subtraction by updating y.
1075 This is safer because on some systems
1076 the tv_sec member is unsigned. */
1077 if (x
.tv_usec
< y
.tv_usec
)
1079 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
1080 y
.tv_usec
-= 1000000 * nsec
;
1083 if (x
.tv_usec
- y
.tv_usec
> 1000000)
1085 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
1086 y
.tv_usec
+= 1000000 * nsec
;
1090 /* Compute the time remaining to wait. tv_usec is certainly positive. */
1091 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
1092 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
1094 /* Return indication of whether the result should be considered negative. */
1095 return x
.tv_sec
< y
.tv_sec
;
1106 /* Create a GC that will use the GXxor function to flip foreground pixels
1107 into background pixels. */
1111 values
.function
= GXxor
;
1112 values
.foreground
= (f
->output_data
.x
->foreground_pixel
1113 ^ f
->output_data
.x
->background_pixel
);
1115 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1116 GCFunction
| GCForeground
, &values
);
1120 /* Get the height not including a menu bar widget. */
1121 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
1122 /* Height of each line to flash. */
1123 int flash_height
= FRAME_LINE_HEIGHT (f
);
1124 /* These will be the left and right margins of the rectangles. */
1125 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1126 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
1130 /* Don't flash the area between a scroll bar and the frame
1131 edge it is next to. */
1132 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
1134 case vertical_scroll_bar_left
:
1135 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1138 case vertical_scroll_bar_right
:
1139 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1143 width
= flash_right
- flash_left
;
1145 /* If window is tall, flash top and bottom line. */
1146 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
1148 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1149 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1150 width
, flash_height
);
1151 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1153 (height
- flash_height
1154 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
1155 width
, flash_height
);
1158 /* If it is short, flash it all. */
1159 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1160 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1161 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
1163 XFlush (FRAME_X_DISPLAY (f
));
1166 struct timeval wakeup
, now
;
1168 EMACS_GET_TIME (wakeup
);
1170 /* Compute time to wait until, propagating carry from usecs. */
1171 wakeup
.tv_usec
+= 150000;
1172 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
1173 wakeup
.tv_usec
%= 1000000;
1175 /* Keep waiting until past the time wakeup. */
1178 struct timeval timeout
;
1180 EMACS_GET_TIME (timeout
);
1182 /* In effect, timeout = wakeup - timeout.
1183 Break if result would be negative. */
1184 if (timeval_subtract (&timeout
, wakeup
, timeout
))
1187 /* Try to wait that long--but we might wake up sooner. */
1188 select (0, NULL
, NULL
, NULL
, &timeout
);
1192 /* If window is tall, flash top and bottom line. */
1193 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
1195 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1196 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1197 width
, flash_height
);
1198 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1200 (height
- flash_height
1201 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
1202 width
, flash_height
);
1205 /* If it is short, flash it all. */
1206 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1207 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1208 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
1210 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
1211 XFlush (FRAME_X_DISPLAY (f
));
1221 /* Make audible bell. */
1223 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
1227 if (FRAME_X_DISPLAY (selected_frame
) == 0)
1230 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1232 XTflash (selected_frame
);
1238 XFlush (FRAME_X_DISPLAY (selected_frame
));
1243 /* Insert and delete character.
1244 These are not supposed to be used because we are supposed to turn
1245 off the feature of using them. */
1248 XTinsert_glyphs (start
, len
)
1249 register char *start
;
1262 /* Specify how many text lines, from the top of the window,
1263 should be affected by insert-lines and delete-lines operations.
1264 This, and those operations, are used only within an update
1265 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1268 XTset_terminal_window (n
)
1271 if (updating_frame
== 0)
1274 if ((n
<= 0) || (n
> updating_frame
->height
))
1275 flexlines
= updating_frame
->height
;
1280 /* These variables need not be per frame
1281 because redisplay is done on a frame-by-frame basis
1282 and the line dance for one frame is finished before
1283 anything is done for anoter frame. */
1285 /* Array of line numbers from cached insert/delete operations.
1286 line_dance[i] is the old position of the line that we want
1287 to move to line i, or -1 if we want a blank line there. */
1288 static int *line_dance
;
1290 /* Allocated length of that array. */
1291 static int line_dance_len
;
1293 /* Flag indicating whether we've done any work. */
1294 static int line_dance_in_progress
;
1296 /* Perform an insert-lines or delete-lines operation,
1297 inserting N lines or deleting -N lines at vertical position VPOS. */
1298 XTins_del_lines (vpos
, n
)
1301 register int fence
, i
;
1303 if (vpos
>= flexlines
)
1306 if (!line_dance_in_progress
)
1308 int ht
= updating_frame
->height
;
1309 if (ht
> line_dance_len
)
1311 line_dance
= (int *)xrealloc (line_dance
, ht
* sizeof (int));
1312 line_dance_len
= ht
;
1314 for (i
= 0; i
< ht
; ++i
) line_dance
[i
] = i
;
1315 line_dance_in_progress
= 1;
1319 if (n
> flexlines
- vpos
)
1320 n
= flexlines
- vpos
;
1322 for (i
= flexlines
; --i
>= fence
;)
1323 line_dance
[i
] = line_dance
[i
-n
];
1324 for (i
= fence
; --i
>= vpos
;)
1330 if (n
> flexlines
- vpos
)
1331 n
= flexlines
- vpos
;
1332 fence
= flexlines
- n
;
1333 for (i
= vpos
; i
< fence
; ++i
)
1334 line_dance
[i
] = line_dance
[i
+ n
];
1335 for (i
= fence
; i
< flexlines
; ++i
)
1340 /* Here's where we actually move the pixels around.
1341 Must be called with input blocked. */
1345 register int i
, j
, distance
;
1346 register struct frame
*f
;
1350 /* Must check this flag first. If it's not set, then not only is the
1351 array uninitialized, but we might not even have a frame. */
1352 if (!line_dance_in_progress
)
1360 intborder
= CHAR_TO_PIXEL_COL (f
, FRAME_LEFT_SCROLL_BAR_WIDTH (f
));
1362 x_update_cursor (updating_frame
, 0);
1364 for (i
= 0; i
< ht
; ++i
)
1365 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) > 0)
1367 for (j
= i
; (j
< ht
&& line_dance
[j
] != -1
1368 && line_dance
[j
]-j
== distance
); ++j
);
1369 /* Copy [i,j) upward from [i+distance,j+distance) */
1370 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1371 FRAME_X_WINDOW (f
), f
->output_data
.x
->normal_gc
,
1372 intborder
, CHAR_TO_PIXEL_ROW (f
, i
+distance
),
1373 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1374 (j
-i
) * f
->output_data
.x
->line_height
,
1375 intborder
, CHAR_TO_PIXEL_ROW (f
, i
));
1379 for (i
= ht
; --i
>=0; )
1380 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) < 0)
1382 for (j
= i
; (--j
>= 0 && line_dance
[j
] != -1
1383 && line_dance
[j
]-j
== distance
););
1384 /* Copy (j,i] downward from (j+distance, i+distance] */
1385 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1386 FRAME_X_WINDOW (f
), f
->output_data
.x
->normal_gc
,
1387 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1+distance
),
1388 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1389 (i
-j
) * f
->output_data
.x
->line_height
,
1390 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1));
1394 for (i
= 0; i
< ht
; ++i
)
1395 if (line_dance
[i
] == -1)
1397 for (j
= i
; j
< ht
&& line_dance
[j
] == -1; ++j
);
1399 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1400 intborder
, CHAR_TO_PIXEL_ROW (f
, i
),
1401 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1402 (j
-i
) * f
->output_data
.x
->line_height
, False
);
1405 line_dance_in_progress
= 0;
1408 /* Support routines for exposure events. */
1409 static void clear_cursor ();
1411 /* Output into a rectangle of an X-window (for frame F)
1412 the characters in f->phys_lines that overlap that rectangle.
1413 TOP and LEFT are the position of the upper left corner of the rectangle.
1414 ROWS and COLS are the size of the rectangle.
1415 Call this function with input blocked. */
1418 dumprectangle (f
, left
, top
, cols
, rows
)
1420 register int left
, top
, cols
, rows
;
1422 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1423 int cursor_cleared
= 0;
1427 if (FRAME_GARBAGED_P (f
))
1430 /* Express rectangle as four edges, instead of position-and-size. */
1431 bottom
= top
+ rows
;
1432 right
= left
+ cols
;
1434 /* Convert rectangle edges in pixels to edges in chars.
1435 Round down for left and top, up for right and bottom. */
1436 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1437 left
= PIXEL_TO_CHAR_COL (f
, left
);
1438 bottom
+= (f
->output_data
.x
->line_height
- 1);
1439 right
+= (FONT_WIDTH (f
->output_data
.x
->font
) - 1);
1440 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1441 right
= PIXEL_TO_CHAR_COL (f
, right
);
1443 /* Clip the rectangle to what can be visible. */
1448 if (right
> FRAME_WINDOW_WIDTH (f
))
1449 right
= FRAME_WINDOW_WIDTH (f
);
1450 if (bottom
> f
->height
)
1453 /* Get size in chars of the rectangle. */
1454 cols
= right
- left
;
1455 rows
= bottom
- top
;
1457 /* If rectangle has zero area, return. */
1458 if (rows
<= 0) return;
1459 if (cols
<= 0) return;
1461 /* Turn off the cursor if it is in the rectangle.
1462 We will turn it back on afterward. */
1463 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1464 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1470 /* Display the text in the rectangle, one text line at a time. */
1472 for (y
= top
; y
< bottom
; y
++)
1474 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1476 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1480 CHAR_TO_PIXEL_COL (f
, left
),
1481 CHAR_TO_PIXEL_ROW (f
, y
),
1482 line
, min (cols
, active_frame
->used
[y
] - left
),
1483 active_frame
->highlight
[y
], 0);
1486 /* Turn the cursor on if we turned it off. */
1489 x_update_cursor (f
, 1);
1496 /* We used to only do this if Vx_no_window_manager was non-nil, but
1497 the ICCCM (section 4.1.6) says that the window's border pixmap
1498 and border pixel are window attributes which are "private to the
1499 client", so we can always change it to whatever we want. */
1501 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1502 f
->output_data
.x
->border_pixel
);
1504 x_update_cursor (f
, 1);
1508 frame_unhighlight (f
)
1511 /* We used to only do this if Vx_no_window_manager was non-nil, but
1512 the ICCCM (section 4.1.6) says that the window's border pixmap
1513 and border pixel are window attributes which are "private to the
1514 client", so we can always change it to whatever we want. */
1516 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1517 f
->output_data
.x
->border_tile
);
1519 x_update_cursor (f
, 1);
1522 static void XTframe_rehighlight ();
1523 static void x_frame_rehighlight ();
1525 /* The focus has changed. Update the frames as necessary to reflect
1526 the new situation. Note that we can't change the selected frame
1527 here, because the Lisp code we are interrupting might become confused.
1528 Each event gets marked with the frame in which it occurred, so the
1529 Lisp code can tell when the switch took place by examining the events. */
1532 x_new_focus_frame (dpyinfo
, frame
)
1533 struct x_display_info
*dpyinfo
;
1534 struct frame
*frame
;
1536 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
1537 int events_enqueued
= 0;
1539 if (frame
!= dpyinfo
->x_focus_frame
)
1541 /* Set this before calling other routines, so that they see
1542 the correct value of x_focus_frame. */
1543 dpyinfo
->x_focus_frame
= frame
;
1545 if (old_focus
&& old_focus
->auto_lower
)
1546 x_lower_frame (old_focus
);
1549 selected_frame
= frame
;
1550 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
1552 Fselect_window (selected_frame
->selected_window
);
1553 choose_minibuf_frame ();
1556 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
1557 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
1559 pending_autoraise_frame
= 0;
1562 x_frame_rehighlight (dpyinfo
);
1565 /* Handle an event saying the mouse has moved out of an Emacs frame. */
1568 x_mouse_leave (dpyinfo
)
1569 struct x_display_info
*dpyinfo
;
1571 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
1574 /* The focus has changed, or we have redirected a frame's focus to
1575 another frame (this happens when a frame uses a surrogate
1576 minibuffer frame). Shift the highlight as appropriate.
1578 The FRAME argument doesn't necessarily have anything to do with which
1579 frame is being highlighted or unhighlighted; we only use it to find
1580 the appropriate X display info. */
1582 XTframe_rehighlight (frame
)
1583 struct frame
*frame
;
1585 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
1589 x_frame_rehighlight (dpyinfo
)
1590 struct x_display_info
*dpyinfo
;
1592 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1594 if (dpyinfo
->x_focus_frame
)
1596 dpyinfo
->x_highlight_frame
1597 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
1598 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
1599 : dpyinfo
->x_focus_frame
);
1600 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
1602 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
1603 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1607 dpyinfo
->x_highlight_frame
= 0;
1609 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
1612 frame_unhighlight (old_highlight
);
1613 if (dpyinfo
->x_highlight_frame
)
1614 frame_highlight (dpyinfo
->x_highlight_frame
);
1618 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1620 /* Initialize mode_switch_bit and modifier_meaning. */
1622 x_find_modifier_meanings (dpyinfo
)
1623 struct x_display_info
*dpyinfo
;
1625 int min_code
, max_code
;
1628 XModifierKeymap
*mods
;
1630 dpyinfo
->meta_mod_mask
= 0;
1631 dpyinfo
->shift_lock_mask
= 0;
1632 dpyinfo
->alt_mod_mask
= 0;
1633 dpyinfo
->super_mod_mask
= 0;
1634 dpyinfo
->hyper_mod_mask
= 0;
1637 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
1639 min_code
= dpyinfo
->display
->min_keycode
;
1640 max_code
= dpyinfo
->display
->max_keycode
;
1643 syms
= XGetKeyboardMapping (dpyinfo
->display
,
1644 min_code
, max_code
- min_code
+ 1,
1646 mods
= XGetModifierMapping (dpyinfo
->display
);
1648 /* Scan the modifier table to see which modifier bits the Meta and
1649 Alt keysyms are on. */
1651 int row
, col
; /* The row and column in the modifier table. */
1653 for (row
= 3; row
< 8; row
++)
1654 for (col
= 0; col
< mods
->max_keypermod
; col
++)
1657 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
1659 /* Zeroes are used for filler. Skip them. */
1663 /* Are any of this keycode's keysyms a meta key? */
1667 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
1669 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
1675 dpyinfo
->meta_mod_mask
|= (1 << row
);
1680 dpyinfo
->alt_mod_mask
|= (1 << row
);
1685 dpyinfo
->hyper_mod_mask
|= (1 << row
);
1690 dpyinfo
->super_mod_mask
|= (1 << row
);
1694 /* Ignore this if it's not on the lock modifier. */
1695 if ((1 << row
) == LockMask
)
1696 dpyinfo
->shift_lock_mask
= LockMask
;
1704 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
1705 if (! dpyinfo
->meta_mod_mask
)
1707 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
1708 dpyinfo
->alt_mod_mask
= 0;
1711 /* If some keys are both alt and meta,
1712 make them just meta, not alt. */
1713 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
1715 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
1718 XFree ((char *) syms
);
1719 XFreeModifiermap (mods
);
1722 /* Convert between the modifier bits X uses and the modifier bits
1725 x_x_to_emacs_modifiers (dpyinfo
, state
)
1726 struct x_display_info
*dpyinfo
;
1729 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
1730 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
1731 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
1732 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
1733 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
1734 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
1738 x_emacs_to_x_modifiers (dpyinfo
, state
)
1739 struct x_display_info
*dpyinfo
;
1742 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
1743 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
1744 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
1745 | ((state
& shift_modifier
) ? ShiftMask
: 0)
1746 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
1747 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
1750 /* Convert a keysym to its name. */
1753 x_get_keysym_name (keysym
)
1759 value
= XKeysymToString (keysym
);
1765 /* Mouse clicks and mouse movement. Rah. */
1767 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
1768 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
1769 that the glyph at X, Y occupies, if BOUNDS != 0.
1770 If NOCLIP is nonzero, do not force the value into range. */
1773 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1775 register int pix_x
, pix_y
;
1776 register int *x
, *y
;
1780 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1781 even for negative values. */
1783 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
1785 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
1787 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
1788 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
1792 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
1793 bounds
->height
= f
->output_data
.x
->line_height
;
1794 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
1795 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
1802 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
1803 pix_x
= FRAME_WINDOW_WIDTH (f
);
1807 else if (pix_y
> f
->height
)
1816 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
1819 register int *pix_x
, *pix_y
;
1821 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
1822 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
1825 /* Prepare a mouse-event in *RESULT for placement in the input queue.
1827 If the event is a button press, then note that we have grabbed
1831 construct_mouse_click (result
, event
, f
)
1832 struct input_event
*result
;
1833 XButtonEvent
*event
;
1836 /* Make the event type no_event; we'll change that when we decide
1838 result
->kind
= mouse_click
;
1839 result
->code
= event
->button
- Button1
;
1840 result
->timestamp
= event
->time
;
1841 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
1843 | (event
->type
== ButtonRelease
1851 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
1852 XSETFASTINT (result
->x
, column
);
1853 XSETFASTINT (result
->y
, row
);
1855 XSETINT (result
->x
, event
->x
);
1856 XSETINT (result
->y
, event
->y
);
1857 XSETFRAME (result
->frame_or_window
, f
);
1861 /* Prepare a menu-event in *RESULT for placement in the input queue. */
1864 construct_menu_click (result
, event
, f
)
1865 struct input_event
*result
;
1866 XButtonEvent
*event
;
1869 /* Make the event type no_event; we'll change that when we decide
1871 result
->kind
= mouse_click
;
1872 XSETINT (result
->code
, event
->button
- Button1
);
1873 result
->timestamp
= event
->time
;
1874 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
1876 | (event
->type
== ButtonRelease
1880 XSETINT (result
->x
, event
->x
);
1881 XSETINT (result
->y
, -1);
1882 XSETFRAME (result
->frame_or_window
, f
);
1885 /* Function to report a mouse movement to the mainstream Emacs code.
1886 The input handler calls this.
1888 We have received a mouse movement event, which is given in *event.
1889 If the mouse is over a different glyph than it was last time, tell
1890 the mainstream emacs code by setting mouse_moved. If not, ask for
1891 another motion event, so we can check again the next time it moves. */
1894 note_mouse_movement (frame
, event
)
1896 XMotionEvent
*event
;
1898 last_mouse_movement_time
= event
->time
;
1900 if (event
->window
!= FRAME_X_WINDOW (frame
))
1902 frame
->mouse_moved
= 1;
1903 last_mouse_scroll_bar
= Qnil
;
1905 note_mouse_highlight (frame
, -1, -1);
1908 /* Has the mouse moved off the glyph it was on at the last sighting? */
1909 else if (event
->x
< last_mouse_glyph
.x
1910 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
1911 || event
->y
< last_mouse_glyph
.y
1912 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
1914 frame
->mouse_moved
= 1;
1915 last_mouse_scroll_bar
= Qnil
;
1917 note_mouse_highlight (frame
, event
->x
, event
->y
);
1921 /* This is used for debugging, to turn off note_mouse_highlight. */
1922 static int disable_mouse_highlight
;
1924 /* Take proper action when the mouse has moved to position X, Y on frame F
1925 as regards highlighting characters that have mouse-face properties.
1926 Also dehighlighting chars where the mouse was before.
1927 X and Y can be negative or out of range. */
1930 note_mouse_highlight (f
, x
, y
)
1934 int row
, column
, portion
;
1935 XRectangle new_glyph
;
1939 if (disable_mouse_highlight
)
1942 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
= x
;
1943 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
= y
;
1944 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
= f
;
1946 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
)
1951 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 1;
1955 /* Find out which glyph the mouse is on. */
1956 pixel_to_glyph_coords (f
, x
, y
, &column
, &row
,
1957 &new_glyph
, FRAME_X_DISPLAY_INFO (f
)->grabbed
);
1959 /* Which window is that in? */
1960 window
= window_from_coordinates (f
, column
, row
, &portion
);
1961 w
= XWINDOW (window
);
1963 /* If we were displaying active text in another window, clear that. */
1964 if (! EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
1965 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
1967 /* Are we in a window whose display is up to date?
1968 And verify the buffer's text has not changed. */
1969 if (WINDOWP (window
) && portion
== 0 && row
>= 0 && column
>= 0
1970 && row
< FRAME_HEIGHT (f
) && column
< FRAME_WIDTH (f
)
1971 && EQ (w
->window_end_valid
, w
->buffer
)
1972 && w
->last_modified
== BUF_MODIFF (XBUFFER (w
->buffer
))
1973 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
)))
1975 int *ptr
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[row
];
1978 /* Find which buffer position the mouse corresponds to. */
1979 for (i
= column
; i
>= 0; i
--)
1983 /* Is it outside the displayed active region (if any)? */
1985 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
1986 else if (! (EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
)
1987 && row
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
1988 && row
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
1989 && (row
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
1990 || column
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
)
1991 && (row
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
1992 || column
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
1993 || FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
)))
1995 Lisp_Object mouse_face
, overlay
, position
;
1996 Lisp_Object
*overlay_vec
;
1997 int len
, noverlays
, ignor1
;
1998 struct buffer
*obuf
;
2001 /* If we get an out-of-range value, return now; avoid an error. */
2002 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
2005 /* Make the window's buffer temporarily current for
2006 overlays_at and compute_char_face. */
2007 obuf
= current_buffer
;
2008 current_buffer
= XBUFFER (w
->buffer
);
2014 /* Yes. Clear the display of the old active region, if any. */
2015 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2017 /* Is this char mouse-active? */
2018 XSETINT (position
, pos
);
2021 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2023 /* Put all the overlays we want in a vector in overlay_vec.
2024 Store the length in len. */
2025 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2027 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
2029 /* Find the highest priority overlay that has a mouse-face prop. */
2031 for (i
= 0; i
< noverlays
; i
++)
2033 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
2034 if (!NILP (mouse_face
))
2036 overlay
= overlay_vec
[i
];
2041 /* If no overlay applies, get a text property. */
2043 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
2045 /* Handle the overlay case. */
2046 if (! NILP (overlay
))
2048 /* Find the range of text around this char that
2049 should be active. */
2050 Lisp_Object before
, after
;
2053 before
= Foverlay_start (overlay
);
2054 after
= Foverlay_end (overlay
);
2055 /* Record this as the current active region. */
2056 fast_find_position (window
, XFASTINT (before
),
2057 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2058 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2059 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2060 = !fast_find_position (window
, XFASTINT (after
),
2061 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2062 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2063 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2064 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2065 = compute_char_face (f
, w
, pos
, 0, 0,
2066 &ignore
, pos
+ 1, 1);
2068 /* Display it as active. */
2069 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2071 /* Handle the text property case. */
2072 else if (! NILP (mouse_face
))
2074 /* Find the range of text around this char that
2075 should be active. */
2076 Lisp_Object before
, after
, beginning
, end
;
2079 beginning
= Fmarker_position (w
->start
);
2080 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
2081 - XFASTINT (w
->window_end_pos
)));
2083 = Fprevious_single_property_change (make_number (pos
+ 1),
2085 w
->buffer
, beginning
);
2087 = Fnext_single_property_change (position
, Qmouse_face
,
2089 /* Record this as the current active region. */
2090 fast_find_position (window
, XFASTINT (before
),
2091 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2092 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2093 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2094 = !fast_find_position (window
, XFASTINT (after
),
2095 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2096 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2097 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2098 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2099 = compute_char_face (f
, w
, pos
, 0, 0,
2100 &ignore
, pos
+ 1, 1);
2102 /* Display it as active. */
2103 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2107 current_buffer
= obuf
;
2112 /* Find the row and column of position POS in window WINDOW.
2113 Store them in *COLUMNP and *ROWP.
2114 This assumes display in WINDOW is up to date.
2115 If POS is above start of WINDOW, return coords
2116 of start of first screen line.
2117 If POS is after end of WINDOW, return coords of end of last screen line.
2119 Value is 1 if POS is in range, 0 if it was off screen. */
2122 fast_find_position (window
, pos
, columnp
, rowp
)
2125 int *columnp
, *rowp
;
2127 struct window
*w
= XWINDOW (window
);
2128 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2131 int left
= WINDOW_LEFT_MARGIN (w
);
2133 int height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
2134 int width
= window_internal_width (w
);
2137 int maybe_next_line
= 0;
2139 /* Find the right row. */
2144 int linestart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ i
][left
];
2145 if (linestart
> pos
)
2147 /* If the position sought is the end of the buffer,
2148 don't include the blank lines at the bottom of the window. */
2149 if (linestart
== pos
&& pos
== BUF_ZV (XBUFFER (w
->buffer
)))
2151 maybe_next_line
= 1;
2158 /* Find the right column with in it. */
2159 charstarts
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ row
];
2161 for (i
= 0; i
< width
; i
++)
2163 if (charstarts
[left
+ i
] == pos
)
2166 *columnp
= i
+ left
;
2169 else if (charstarts
[left
+ i
] > pos
)
2171 else if (charstarts
[left
+ i
] > 0)
2175 /* If we're looking for the end of the buffer,
2176 and we didn't find it in the line we scanned,
2177 use the start of the following line. */
2178 if (maybe_next_line
)
2189 /* Display the active region described by mouse_face_*
2190 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2193 show_mouse_face (dpyinfo
, hl
)
2194 struct x_display_info
*dpyinfo
;
2197 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
2198 int width
= window_internal_width (w
);
2199 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2202 int old_curs_x
= curs_x
;
2203 int old_curs_y
= curs_y
;
2205 /* Set these variables temporarily
2206 so that if we have to turn the cursor off and on again
2207 we will put it back at the same place. */
2208 curs_x
= f
->phys_cursor_x
;
2209 curs_y
= f
->phys_cursor_y
;
2210 for (i
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
;
2211 i
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
; i
++)
2213 int column
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2214 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
2215 : WINDOW_LEFT_MARGIN (w
));
2216 int endcolumn
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2217 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2218 : WINDOW_LEFT_MARGIN (w
) + width
);
2219 endcolumn
= min (endcolumn
, FRAME_CURRENT_GLYPHS (f
)->used
[i
]);
2221 /* If the cursor's in the text we are about to rewrite,
2222 turn the cursor off. */
2224 && curs_x
>= column
- 1
2225 && curs_x
<= endcolumn
)
2227 x_update_cursor (f
, 0);
2232 CHAR_TO_PIXEL_COL (f
, column
),
2233 CHAR_TO_PIXEL_ROW (f
, i
),
2234 FRAME_CURRENT_GLYPHS (f
)->glyphs
[i
] + column
,
2236 /* Highlight with mouse face if hl > 0. */
2240 /* If we turned the cursor off, turn it back on. */
2242 x_display_cursor (f
, 1, curs_x
, curs_y
);
2244 curs_x
= old_curs_x
;
2245 curs_y
= old_curs_y
;
2247 /* Change the mouse cursor according to the value of HL. */
2249 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2250 f
->output_data
.x
->cross_cursor
);
2252 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2253 f
->output_data
.x
->text_cursor
);
2256 /* Clear out the mouse-highlighted active region.
2257 Redraw it unhighlighted first. */
2260 clear_mouse_face (dpyinfo
)
2261 struct x_display_info
*dpyinfo
;
2263 if (! NILP (dpyinfo
->mouse_face_window
))
2264 show_mouse_face (dpyinfo
, 0);
2266 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2267 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2268 dpyinfo
->mouse_face_window
= Qnil
;
2271 /* Just discard the mouse face information for frame F, if any.
2272 This is used when the size of F is changed. */
2274 cancel_mouse_face (f
)
2278 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2280 window
= dpyinfo
->mouse_face_window
;
2281 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
2283 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2284 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2285 dpyinfo
->mouse_face_window
= Qnil
;
2289 static struct scroll_bar
*x_window_to_scroll_bar ();
2290 static void x_scroll_bar_report_motion ();
2292 /* Return the current position of the mouse.
2293 *fp should be a frame which indicates which display to ask about.
2295 If the mouse movement started in a scroll bar, set *fp, *bar_window,
2296 and *part to the frame, window, and scroll bar part that the mouse
2297 is over. Set *x and *y to the portion and whole of the mouse's
2298 position on the scroll bar.
2300 If the mouse movement started elsewhere, set *fp to the frame the
2301 mouse is on, *bar_window to nil, and *x and *y to the character cell
2304 Set *time to the server timestamp for the time at which the mouse
2305 was at this position.
2307 Don't store anything if we don't have a valid set of values to report.
2309 This clears the mouse_moved flag, so we can wait for the next mouse
2313 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
2316 Lisp_Object
*bar_window
;
2317 enum scroll_bar_part
*part
;
2319 unsigned long *time
;
2325 if (! NILP (last_mouse_scroll_bar
))
2326 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
2332 Window dummy_window
;
2335 Lisp_Object frame
, tail
;
2337 /* Clear the mouse-moved flag for every frame on this display. */
2338 FOR_EACH_FRAME (tail
, frame
)
2339 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
2340 XFRAME (frame
)->mouse_moved
= 0;
2342 last_mouse_scroll_bar
= Qnil
;
2344 /* Figure out which root window we're on. */
2345 XQueryPointer (FRAME_X_DISPLAY (*fp
),
2346 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
2348 /* The root window which contains the pointer. */
2351 /* Trash which we can't trust if the pointer is on
2352 a different screen. */
2355 /* The position on that root window. */
2358 /* More trash we can't trust. */
2361 /* Modifier keys and pointer buttons, about which
2363 (unsigned int *) &dummy
);
2365 /* Now we have a position on the root; find the innermost window
2366 containing the pointer. */
2370 int parent_x
, parent_y
;
2374 /* XTranslateCoordinates can get errors if the window
2375 structure is changing at the same time this function
2376 is running. So at least we must not crash from them. */
2378 x_catch_errors (FRAME_X_DISPLAY (*fp
));
2380 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
2381 && FRAME_LIVE_P (last_mouse_frame
))
2383 /* If mouse was grabbed on a frame, give coords for that frame
2384 even if the mouse is now outside it. */
2385 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2387 /* From-window, to-window. */
2388 root
, FRAME_X_WINDOW (last_mouse_frame
),
2390 /* From-position, to-position. */
2391 root_x
, root_y
, &win_x
, &win_y
,
2395 f1
= last_mouse_frame
;
2401 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2403 /* From-window, to-window. */
2406 /* From-position, to-position. */
2407 root_x
, root_y
, &win_x
, &win_y
,
2412 if (child
== None
|| child
== win
)
2420 /* Now we know that:
2421 win is the innermost window containing the pointer
2422 (XTC says it has no child containing the pointer),
2423 win_x and win_y are the pointer's position in it
2424 (XTC did this the last time through), and
2425 parent_x and parent_y are the pointer's position in win's parent.
2426 (They are what win_x and win_y were when win was child.
2427 If win is the root window, it has no parent, and
2428 parent_{x,y} are invalid, but that's okay, because we'll
2429 never use them in that case.) */
2431 /* Is win one of our frames? */
2432 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
2435 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
2438 x_uncatch_errors (FRAME_X_DISPLAY (*fp
));
2440 /* If not, is it one of our scroll bars? */
2443 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
2447 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2453 if (f1
== 0 && insist
)
2454 f1
= selected_frame
;
2458 int ignore1
, ignore2
;
2460 /* Ok, we found a frame. Store all the values. */
2462 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
2464 FRAME_X_DISPLAY_INFO (f1
)->grabbed
2470 XSETINT (*x
, win_x
);
2471 XSETINT (*y
, win_y
);
2472 *time
= last_mouse_movement_time
;
2480 /* Scroll bar support. */
2482 /* Given an X window ID, find the struct scroll_bar which manages it.
2483 This can be called in GC, so we have to make sure to strip off mark
2485 static struct scroll_bar
*
2486 x_window_to_scroll_bar (window_id
)
2489 Lisp_Object tail
, frame
;
2491 for (tail
= Vframe_list
;
2492 XGCTYPE (tail
) == Lisp_Cons
;
2493 tail
= XCONS (tail
)->cdr
)
2495 Lisp_Object frame
, bar
, condemned
;
2497 frame
= XCONS (tail
)->car
;
2498 /* All elements of Vframe_list should be frames. */
2499 if (! GC_FRAMEP (frame
))
2502 /* Scan this frame's scroll bar list for a scroll bar with the
2504 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2505 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2506 /* This trick allows us to search both the ordinary and
2507 condemned scroll bar lists with one loop. */
2508 ! GC_NILP (bar
) || (bar
= condemned
,
2511 bar
= XSCROLL_BAR (bar
)->next
)
2512 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2513 return XSCROLL_BAR (bar
);
2519 /* Open a new X window to serve as a scroll bar, and return the
2520 scroll bar vector for it. */
2521 static struct scroll_bar
*
2522 x_scroll_bar_create (window
, top
, left
, width
, height
)
2523 struct window
*window
;
2524 int top
, left
, width
, height
;
2526 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2527 struct scroll_bar
*bar
2528 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2533 XSetWindowAttributes a
;
2535 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
2536 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2537 | ButtonMotionMask
| PointerMotionHintMask
2539 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
2541 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2546 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2547 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2548 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
2549 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
2550 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2551 sb_widget
= XtCreateManagedWidget ("box",
2553 f
->output_data
.x
->edit_widget
, al
, ac
);
2554 SET_SCROLL_BAR_X_WINDOW
2555 (bar
, sb_widget
->core
.window
);
2557 SET_SCROLL_BAR_X_WINDOW
2559 XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2561 /* Position and size of scroll bar. */
2562 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, top
,
2563 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2, height
,
2565 /* Border width, depth, class, and visual. */
2566 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
2572 XSETWINDOW (bar
->window
, window
);
2573 XSETINT (bar
->top
, top
);
2574 XSETINT (bar
->left
, left
);
2575 XSETINT (bar
->width
, width
);
2576 XSETINT (bar
->height
, height
);
2577 XSETINT (bar
->start
, 0);
2578 XSETINT (bar
->end
, 0);
2579 bar
->dragging
= Qnil
;
2581 /* Add bar to its frame's list of scroll bars. */
2582 bar
->next
= FRAME_SCROLL_BARS (f
);
2584 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2585 if (! NILP (bar
->next
))
2586 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2588 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
2595 /* Draw BAR's handle in the proper position.
2596 If the handle is already drawn from START to END, don't bother
2597 redrawing it, unless REBUILD is non-zero; in that case, always
2598 redraw it. (REBUILD is handy for drawing the handle after expose
2601 Normally, we want to constrain the start and end of the handle to
2602 fit inside its rectangle, but if the user is dragging the scroll bar
2603 handle, we want to let them drag it down all the way, so that the
2604 bar's top is as far down as it goes; otherwise, there's no way to
2605 move to the very end of the buffer. */
2607 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
2608 struct scroll_bar
*bar
;
2612 int dragging
= ! NILP (bar
->dragging
);
2613 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2614 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2615 GC gc
= f
->output_data
.x
->normal_gc
;
2617 /* If the display is already accurate, do nothing. */
2619 && start
== XINT (bar
->start
)
2620 && end
== XINT (bar
->end
))
2626 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
2627 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
2628 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
2630 /* Make sure the values are reasonable, and try to preserve
2631 the distance between start and end. */
2633 int length
= end
- start
;
2637 else if (start
> top_range
)
2639 end
= start
+ length
;
2643 else if (end
> top_range
&& ! dragging
)
2647 /* Store the adjusted setting in the scroll bar. */
2648 XSETINT (bar
->start
, start
);
2649 XSETINT (bar
->end
, end
);
2651 /* Clip the end position, just for display. */
2652 if (end
> top_range
)
2655 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
2656 below top positions, to make sure the handle is always at least
2657 that many pixels tall. */
2658 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
2660 /* Draw the empty space above the handle. Note that we can't clear
2661 zero-height areas; that means "clear to end of window." */
2663 XClearArea (FRAME_X_DISPLAY (f
), w
,
2665 /* x, y, width, height, and exposures. */
2666 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2667 VERTICAL_SCROLL_BAR_TOP_BORDER
,
2668 inside_width
, start
,
2671 /* Draw the handle itself. */
2672 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
2674 /* x, y, width, height */
2675 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2676 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
2677 inside_width
, end
- start
);
2680 /* Draw the empty space below the handle. Note that we can't
2681 clear zero-height areas; that means "clear to end of window." */
2682 if (end
< inside_height
)
2683 XClearArea (FRAME_X_DISPLAY (f
), w
,
2685 /* x, y, width, height, and exposures. */
2686 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2687 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
2688 inside_width
, inside_height
- end
,
2696 /* Move a scroll bar around on the screen, to accommodate changing
2697 window configurations. */
2699 x_scroll_bar_move (bar
, top
, left
, width
, height
)
2700 struct scroll_bar
*bar
;
2701 int top
, left
, width
, height
;
2703 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2704 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2710 unsigned int mask
= 0;
2712 wc
.x
= left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2715 wc
.width
= width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
2718 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
2719 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
2720 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
2721 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
2724 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
2728 XSETINT (bar
->left
, left
);
2729 XSETINT (bar
->top
, top
);
2730 XSETINT (bar
->width
, width
);
2731 XSETINT (bar
->height
, height
);
2736 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
2739 x_scroll_bar_remove (bar
)
2740 struct scroll_bar
*bar
;
2742 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2746 /* Destroy the window. */
2747 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
2749 /* Disassociate this scroll bar from its window. */
2750 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
2755 /* Set the handle of the vertical scroll bar for WINDOW to indicate
2756 that we are displaying PORTION characters out of a total of WHOLE
2757 characters, starting at POSITION. If WINDOW has no scroll bar,
2760 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
2761 struct window
*window
;
2762 int portion
, whole
, position
;
2764 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2765 int top
= XINT (window
->top
);
2766 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
2767 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
2769 /* Where should this scroll bar be, pixelwise? */
2770 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
2771 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
2773 = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
2774 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2775 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
2776 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
2778 struct scroll_bar
*bar
;
2780 /* Does the scroll bar exist yet? */
2781 if (NILP (window
->vertical_scroll_bar
))
2782 bar
= x_scroll_bar_create (window
,
2783 pixel_top
, pixel_left
,
2784 pixel_width
, pixel_height
);
2787 /* It may just need to be moved and resized. */
2788 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2789 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
2792 /* Set the scroll bar's current state, unless we're currently being
2794 if (NILP (bar
->dragging
))
2796 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, pixel_height
);
2799 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
2802 int start
= ((double) position
* top_range
) / whole
;
2803 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
2805 x_scroll_bar_set_handle (bar
, start
, end
, 0);
2809 XSETVECTOR (window
->vertical_scroll_bar
, bar
);
2813 /* The following three hooks are used when we're doing a thorough
2814 redisplay of the frame. We don't explicitly know which scroll bars
2815 are going to be deleted, because keeping track of when windows go
2816 away is a real pain - "Can you say set-window-configuration, boys
2817 and girls?" Instead, we just assert at the beginning of redisplay
2818 that *all* scroll bars are to be removed, and then save a scroll bar
2819 from the fiery pit when we actually redisplay its window. */
2821 /* Arrange for all scroll bars on FRAME to be removed at the next call
2822 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
2823 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
2825 XTcondemn_scroll_bars (frame
)
2828 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
2829 while (! NILP (FRAME_SCROLL_BARS (frame
)))
2832 bar
= FRAME_SCROLL_BARS (frame
);
2833 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
2834 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
2835 XSCROLL_BAR (bar
)->prev
= Qnil
;
2836 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
2837 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
2838 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
2842 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
2843 Note that WINDOW isn't necessarily condemned at all. */
2845 XTredeem_scroll_bar (window
)
2846 struct window
*window
;
2848 struct scroll_bar
*bar
;
2850 /* We can't redeem this window's scroll bar if it doesn't have one. */
2851 if (NILP (window
->vertical_scroll_bar
))
2854 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2856 /* Unlink it from the condemned list. */
2858 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2860 if (NILP (bar
->prev
))
2862 /* If the prev pointer is nil, it must be the first in one of
2864 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
2865 /* It's not condemned. Everything's fine. */
2867 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
2868 window
->vertical_scroll_bar
))
2869 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
2871 /* If its prev pointer is nil, it must be at the front of
2872 one or the other! */
2876 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
2878 if (! NILP (bar
->next
))
2879 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
2881 bar
->next
= FRAME_SCROLL_BARS (f
);
2883 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2884 if (! NILP (bar
->next
))
2885 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2889 /* Remove all scroll bars on FRAME that haven't been saved since the
2890 last call to `*condemn_scroll_bars_hook'. */
2892 XTjudge_scroll_bars (f
)
2895 Lisp_Object bar
, next
;
2897 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
2899 /* Clear out the condemned list now so we won't try to process any
2900 more events on the hapless scroll bars. */
2901 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
2903 for (; ! NILP (bar
); bar
= next
)
2905 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
2907 x_scroll_bar_remove (b
);
2910 b
->next
= b
->prev
= Qnil
;
2913 /* Now there should be no references to the condemned scroll bars,
2914 and they should get garbage-collected. */
2918 /* Handle an Expose or GraphicsExpose event on a scroll bar.
2920 This may be called from a signal handler, so we have to ignore GC
2923 x_scroll_bar_expose (bar
, event
)
2924 struct scroll_bar
*bar
;
2927 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2928 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2929 GC gc
= f
->output_data
.x
->normal_gc
;
2930 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2934 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
2936 /* Draw a one-pixel border just inside the edges of the scroll bar. */
2937 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
2939 /* x, y, width, height */
2941 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
2942 XINT (bar
->height
) - 1);
2947 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
2948 is set to something other than no_event, it is enqueued.
2950 This may be called from a signal handler, so we have to ignore GC
2953 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
2954 struct scroll_bar
*bar
;
2956 struct input_event
*emacs_event
;
2958 if (! GC_WINDOWP (bar
->window
))
2961 emacs_event
->kind
= scroll_bar_click
;
2962 emacs_event
->code
= event
->xbutton
.button
- Button1
;
2963 emacs_event
->modifiers
2964 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
2965 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
2966 event
->xbutton
.state
)
2967 | (event
->type
== ButtonRelease
2970 emacs_event
->frame_or_window
= bar
->window
;
2971 emacs_event
->timestamp
= event
->xbutton
.time
;
2973 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2975 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
2977 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
2978 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
2981 if (y
> top_range
) y
= top_range
;
2983 if (y
< XINT (bar
->start
))
2984 emacs_event
->part
= scroll_bar_above_handle
;
2985 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
2986 emacs_event
->part
= scroll_bar_handle
;
2988 emacs_event
->part
= scroll_bar_below_handle
;
2990 /* Just because the user has clicked on the handle doesn't mean
2991 they want to drag it. Lisp code needs to be able to decide
2992 whether or not we're dragging. */
2994 /* If the user has just clicked on the handle, record where they're
2996 if (event
->type
== ButtonPress
2997 && emacs_event
->part
== scroll_bar_handle
)
2998 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
3001 /* If the user has released the handle, set it to its final position. */
3002 if (event
->type
== ButtonRelease
3003 && ! NILP (bar
->dragging
))
3005 int new_start
= y
- XINT (bar
->dragging
);
3006 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
3008 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
3009 bar
->dragging
= Qnil
;
3012 /* Same deal here as the other #if 0. */
3014 /* Clicks on the handle are always reported as occurring at the top of
3016 if (emacs_event
->part
== scroll_bar_handle
)
3017 emacs_event
->x
= bar
->start
;
3019 XSETINT (emacs_event
->x
, y
);
3021 XSETINT (emacs_event
->x
, y
);
3024 XSETINT (emacs_event
->y
, top_range
);
3028 /* Handle some mouse motion while someone is dragging the scroll bar.
3030 This may be called from a signal handler, so we have to ignore GC
3033 x_scroll_bar_note_movement (bar
, event
)
3034 struct scroll_bar
*bar
;
3037 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
3039 last_mouse_movement_time
= event
->xmotion
.time
;
3042 XSETVECTOR (last_mouse_scroll_bar
, bar
);
3044 /* If we're dragging the bar, display it. */
3045 if (! GC_NILP (bar
->dragging
))
3047 /* Where should the handle be now? */
3048 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
3050 if (new_start
!= XINT (bar
->start
))
3052 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
3054 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
3059 /* Return information to the user about the current position of the mouse
3060 on the scroll bar. */
3062 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
3064 Lisp_Object
*bar_window
;
3065 enum scroll_bar_part
*part
;
3067 unsigned long *time
;
3069 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
3070 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3071 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3073 Window dummy_window
;
3075 unsigned int dummy_mask
;
3079 /* Get the mouse's position relative to the scroll bar window, and
3081 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
3083 /* Root, child, root x and root y. */
3084 &dummy_window
, &dummy_window
,
3085 &dummy_coord
, &dummy_coord
,
3087 /* Position relative to scroll bar. */
3090 /* Mouse buttons and modifier keys. */
3096 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
3098 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3100 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
3102 if (! NILP (bar
->dragging
))
3103 win_y
-= XINT (bar
->dragging
);
3107 if (win_y
> top_range
)
3111 *bar_window
= bar
->window
;
3113 if (! NILP (bar
->dragging
))
3114 *part
= scroll_bar_handle
;
3115 else if (win_y
< XINT (bar
->start
))
3116 *part
= scroll_bar_above_handle
;
3117 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3118 *part
= scroll_bar_handle
;
3120 *part
= scroll_bar_below_handle
;
3122 XSETINT (*x
, win_y
);
3123 XSETINT (*y
, top_range
);
3126 last_mouse_scroll_bar
= Qnil
;
3129 *time
= last_mouse_movement_time
;
3135 /* The screen has been cleared so we may have changed foreground or
3136 background colors, and the scroll bars may need to be redrawn.
3137 Clear out the scroll bars, and ask for expose events, so we can
3140 x_scroll_bar_clear (f
)
3145 /* We can have scroll bars even if this is 0,
3146 if we just turned off scroll bar mode.
3147 But in that case we should not clear them. */
3148 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3149 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
3150 bar
= XSCROLL_BAR (bar
)->next
)
3151 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
3155 /* This processes Expose events from the menubar specific X event
3156 loop in xmenu.c. This allows to redisplay the frame if necessary
3157 when handling menubar or popup items. */
3160 process_expose_from_menu (event
)
3164 struct x_display_info
*dpyinfo
;
3168 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
3169 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3172 if (f
->async_visible
== 0)
3174 f
->async_visible
= 1;
3175 f
->async_iconified
= 0;
3176 SET_FRAME_GARBAGED (f
);
3180 dumprectangle (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
3181 event
.xexpose
.x
, event
.xexpose
.y
,
3182 event
.xexpose
.width
, event
.xexpose
.height
);
3187 struct scroll_bar
*bar
3188 = x_window_to_scroll_bar (event
.xexpose
.window
);
3191 x_scroll_bar_expose (bar
, &event
);
3197 /* Define a queue to save up SelectionRequest events for later handling. */
3199 struct selection_event_queue
3202 struct selection_event_queue
*next
;
3205 static struct selection_event_queue
*queue
;
3207 /* Nonzero means queue up certain events--don't process them yet. */
3208 static int x_queue_selection_requests
;
3210 /* Queue up an X event *EVENT, to be processed later. */
3213 x_queue_event (f
, event
)
3217 struct selection_event_queue
*queue_tmp
3218 = (struct selection_event_queue
*) malloc (sizeof (struct selection_event_queue
));
3220 if (queue_tmp
!= NULL
)
3222 queue_tmp
->event
= *event
;
3223 queue_tmp
->next
= queue
;
3228 /* Take all the queued events and put them back
3229 so that they get processed afresh. */
3232 x_unqueue_events (display
)
3235 while (queue
!= NULL
)
3237 struct selection_event_queue
*queue_tmp
= queue
;
3238 XPutBackEvent (display
, &queue_tmp
->event
);
3239 queue
= queue_tmp
->next
;
3240 free ((char *)queue_tmp
);
3244 /* Start queuing SelectionRequest events. */
3247 x_start_queuing_selection_requests (display
)
3250 x_queue_selection_requests
++;
3253 /* Stop queuing SelectionRequest events. */
3256 x_stop_queuing_selection_requests (display
)
3259 x_queue_selection_requests
--;
3260 x_unqueue_events (display
);
3263 /* The main X event-reading loop - XTread_socket. */
3265 /* Timestamp of enter window event. This is only used by XTread_socket,
3266 but we have to put it out here, since static variables within functions
3267 sometimes don't work. */
3268 static Time enter_timestamp
;
3270 /* This holds the state XLookupString needs to implement dead keys
3271 and other tricks known as "compose processing". _X Window System_
3272 says that a portable program can't use this, but Stephen Gildea assures
3273 me that letting the compiler initialize it to zeros will work okay.
3275 This must be defined outside of XTread_socket, for the same reasons
3276 given for enter_timestamp, above. */
3277 static XComposeStatus compose_status
;
3279 /* Record the last 100 characters stored
3280 to help debug the loss-of-chars-during-GC problem. */
3281 static int temp_index
;
3282 static short temp_buffer
[100];
3284 /* Set this to nonzero to fake an "X I/O error"
3285 on a particular display. */
3286 struct x_display_info
*XTread_socket_fake_io_error
;
3288 /* When we find no input here, we occasionally do a no-op command
3289 to verify that the X server is still running and we can still talk with it.
3290 We try all the open displays, one by one.
3291 This variable is used for cycling thru the displays. */
3292 static struct x_display_info
*next_noop_dpyinfo
;
3294 #define SET_SAVED_MENU_EVENT(size) { \
3295 if (f->output_data.x->saved_menu_event == 0) \
3296 f->output_data.x->saved_menu_event = (XEvent*)xmalloc (sizeof (XEvent)); \
3297 bcopy (&event, f->output_data.x->saved_menu_event, size); \
3298 if (numchars >= 1) \
3300 bufp->kind = menu_bar_activate_event; \
3301 XSETFRAME (bufp->frame_or_window, f); \
3307 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
3308 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
3310 /* Read events coming from the X server.
3311 This routine is called by the SIGIO handler.
3312 We return as soon as there are no more events to be read.
3314 Events representing keys are stored in buffer BUFP,
3315 which can hold up to NUMCHARS characters.
3316 We return the number of characters stored into the buffer,
3317 thus pretending to be `read'.
3319 EXPECTED is nonzero if the caller knows input is available. */
3322 XTread_socket (sd
, bufp
, numchars
, expected
)
3324 /* register */ struct input_event
*bufp
;
3325 /* register */ int numchars
;
3331 int items_pending
; /* How many items are in the X queue. */
3334 int event_found
= 0;
3337 struct x_display_info
*dpyinfo
;
3339 Status status_return
;
3342 if (interrupt_input_blocked
)
3344 interrupt_input_pending
= 1;
3348 interrupt_input_pending
= 0;
3351 /* So people can tell when we have read the available input. */
3352 input_signal_count
++;
3355 abort (); /* Don't think this happens. */
3357 /* Find the display we are supposed to read input for.
3358 It's the one communicating on descriptor SD. */
3359 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
3361 #if 0 /* This ought to be unnecessary; let's verify it. */
3363 /* If available, Xlib uses FIOSNBIO to make the socket
3364 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3365 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
3366 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3367 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
3368 #endif /* ! defined (FIOSNBIO) */
3371 #if 0 /* This code can't be made to work, with multiple displays,
3372 and appears not to be used on any system any more.
3373 Also keyboard.c doesn't turn O_NDELAY on and off
3374 for X connections. */
3377 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
3379 extern int read_alarm_should_throw
;
3380 read_alarm_should_throw
= 1;
3381 XPeekEvent (dpyinfo
->display
, &event
);
3382 read_alarm_should_throw
= 0;
3384 #endif /* HAVE_SELECT */
3388 /* For debugging, this gives a way to fake an I/O error. */
3389 if (dpyinfo
== XTread_socket_fake_io_error
)
3391 XTread_socket_fake_io_error
= 0;
3392 x_io_error_quitter (dpyinfo
->display
);
3395 while (XPending (dpyinfo
->display
) != 0)
3397 #ifdef USE_X_TOOLKIT
3398 /* needed to raise Motif submenus */
3399 XtAppNextEvent (Xt_app_con
, &event
);
3401 XNextEvent (dpyinfo
->display
, &event
);
3405 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
3406 &event
.xclient
.window
);
3407 /* The necessity of the following line took me
3408 a full work-day to decipher from the docs!! */
3409 if (f1
!= 0 && FRAME_XIC (f1
) && XFilterEvent (&event
, None
))
3419 if (event
.xclient
.message_type
3420 == dpyinfo
->Xatom_wm_protocols
3421 && event
.xclient
.format
== 32)
3423 if (event
.xclient
.data
.l
[0]
3424 == dpyinfo
->Xatom_wm_take_focus
)
3426 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3427 /* Since we set WM_TAKE_FOCUS, we must call
3428 XSetInputFocus explicitly. But not if f is null,
3429 since that might be an event for a deleted frame. */
3431 /* Not quite sure this is needed -pd */
3433 XSetICFocus (FRAME_XIC (f
));
3436 XSetInputFocus (event
.xclient
.display
,
3437 event
.xclient
.window
,
3438 RevertToPointerRoot
,
3439 event
.xclient
.data
.l
[1]);
3440 /* Not certain about handling scroll bars here */
3442 else if (event
.xclient
.data
.l
[0]
3443 == dpyinfo
->Xatom_wm_save_yourself
)
3445 /* Save state modify the WM_COMMAND property to
3446 something which can reinstate us. This notifies
3447 the session manager, who's looking for such a
3448 PropertyNotify. Can restart processing when
3449 a keyboard or mouse event arrives. */
3452 f
= x_top_window_to_frame (dpyinfo
,
3453 event
.xclient
.window
);
3455 /* This is just so we only give real data once
3456 for a single Emacs process. */
3457 if (f
== selected_frame
)
3458 XSetCommand (FRAME_X_DISPLAY (f
),
3459 event
.xclient
.window
,
3460 initial_argv
, initial_argc
);
3462 XSetCommand (FRAME_X_DISPLAY (f
),
3463 event
.xclient
.window
,
3467 else if (event
.xclient
.data
.l
[0]
3468 == dpyinfo
->Xatom_wm_delete_window
)
3471 = x_any_window_to_frame (dpyinfo
,
3472 event
.xclient
.window
);
3479 bufp
->kind
= delete_window_event
;
3480 XSETFRAME (bufp
->frame_or_window
, f
);
3488 else if (event
.xclient
.message_type
3489 == dpyinfo
->Xatom_wm_configure_denied
)
3492 else if (event
.xclient
.message_type
3493 == dpyinfo
->Xatom_wm_window_moved
)
3497 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3499 new_x
= event
.xclient
.data
.s
[0];
3500 new_y
= event
.xclient
.data
.s
[1];
3504 f
->output_data
.x
->left_pos
= new_x
;
3505 f
->output_data
.x
->top_pos
= new_y
;
3509 else if (event
.xclient
.message_type
3510 == dpyinfo
->Xatom_editres
)
3513 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
3514 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
3517 #endif /* HACK_EDITRES */
3521 case SelectionNotify
:
3522 #ifdef USE_X_TOOLKIT
3523 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
3525 #endif /* not USE_X_TOOLKIT */
3526 x_handle_selection_notify (&event
);
3529 case SelectionClear
: /* Someone has grabbed ownership. */
3530 #ifdef USE_X_TOOLKIT
3531 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
3533 #endif /* USE_X_TOOLKIT */
3535 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
3540 bufp
->kind
= selection_clear_event
;
3541 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3542 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3543 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3544 bufp
->frame_or_window
= Qnil
;
3552 case SelectionRequest
: /* Someone wants our selection. */
3553 #ifdef USE_X_TOOLKIT
3554 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
3556 #endif /* USE_X_TOOLKIT */
3557 if (x_queue_selection_requests
)
3558 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
3562 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
3567 bufp
->kind
= selection_request_event
;
3568 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3569 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
3570 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3571 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
3572 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
3573 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3574 bufp
->frame_or_window
= Qnil
;
3582 case PropertyNotify
:
3583 #ifdef USE_X_TOOLKIT
3584 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
3586 #endif /* not USE_X_TOOLKIT */
3587 x_handle_property_notify (&event
);
3590 case ReparentNotify
:
3591 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
3595 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
3596 x_real_positions (f
, &x
, &y
);
3597 f
->output_data
.x
->left_pos
= x
;
3598 f
->output_data
.x
->top_pos
= y
;
3603 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3606 if (f
->async_visible
== 0)
3608 f
->async_visible
= 1;
3609 f
->async_iconified
= 0;
3610 SET_FRAME_GARBAGED (f
);
3613 dumprectangle (x_window_to_frame (dpyinfo
,
3614 event
.xexpose
.window
),
3615 event
.xexpose
.x
, event
.xexpose
.y
,
3616 event
.xexpose
.width
, event
.xexpose
.height
);
3620 struct scroll_bar
*bar
3621 = x_window_to_scroll_bar (event
.xexpose
.window
);
3624 x_scroll_bar_expose (bar
, &event
);
3625 #ifdef USE_X_TOOLKIT
3628 #endif /* USE_X_TOOLKIT */
3632 case GraphicsExpose
: /* This occurs when an XCopyArea's
3633 source area was obscured or not
3635 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
3639 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
3640 event
.xgraphicsexpose
.width
,
3641 event
.xgraphicsexpose
.height
);
3643 #ifdef USE_X_TOOLKIT
3646 #endif /* USE_X_TOOLKIT */
3649 case NoExpose
: /* This occurs when an XCopyArea's
3650 source area was completely
3655 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
3656 if (f
) /* F may no longer exist if
3657 the frame was deleted. */
3659 /* While a frame is unmapped, display generation is
3660 disabled; you don't want to spend time updating a
3661 display that won't ever be seen. */
3662 f
->async_visible
= 0;
3663 /* We can't distinguish, from the event, whether the window
3664 has become iconified or invisible. So assume, if it
3665 was previously visible, than now it is iconified.
3666 We depend on x_make_frame_invisible to mark it invisible. */
3667 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
3668 f
->async_iconified
= 1;
3670 bufp
->kind
= iconify_event
;
3671 XSETFRAME (bufp
->frame_or_window
, f
);
3679 /* We use x_top_window_to_frame because map events can come
3680 for subwindows and they don't mean that the frame is visible. */
3681 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
3684 f
->async_visible
= 1;
3685 f
->async_iconified
= 0;
3687 /* wait_reading_process_input will notice this and update
3688 the frame's display structures. */
3689 SET_FRAME_GARBAGED (f
);
3693 bufp
->kind
= deiconify_event
;
3694 XSETFRAME (bufp
->frame_or_window
, f
);
3699 else if (! NILP(Vframe_list
)
3700 && ! NILP (XCONS (Vframe_list
)->cdr
))
3701 /* Force a redisplay sooner or later
3702 to update the frame titles
3703 in case this is the second frame. */
3704 record_asynch_buffer_change ();
3708 /* Turn off processing if we become fully obscured. */
3709 case VisibilityNotify
:
3713 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
3717 KeySym keysym
, orig_keysym
;
3718 /* al%imercury@uunet.uu.net says that making this 81 instead of
3719 80 fixed a bug whereby meta chars made his Emacs hang. */
3720 unsigned char copy_buffer
[81];
3723 #if 0 /* This was how we made f10 work in Motif.
3724 The drawback is, you can't type at Emacs when the
3725 the mouse is in the menu bar. So it is better to
3726 turn off f10 in Motif and let Emacs handle it. */
3728 if (lw_window_is_in_menubar (event
.xkey
.window
,
3729 f
->output_data
.x
->menubar_widget
3732 SET_SAVED_KEY_EVENT
;
3735 #endif /* USE_MOTIF */
3739 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
3740 extra_keyboard_modifiers
);
3741 modifiers
= event
.xkey
.state
;
3743 /* This will have to go some day... */
3745 /* make_lispy_event turns chars into control chars.
3746 Don't do it here because XLookupString is too eager. */
3747 event
.xkey
.state
&= ~ControlMask
;
3748 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
3749 | dpyinfo
->super_mod_mask
3750 | dpyinfo
->hyper_mod_mask
3751 | dpyinfo
->alt_mod_mask
);
3753 /* In case Meta is ComposeCharacter,
3754 clear its status. According to Markus Ehrnsperger
3755 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
3756 this enables ComposeCharacter to work whether or
3757 not it is combined with Meta. */
3758 if (modifiers
& dpyinfo
->meta_mod_mask
)
3759 bzero (&compose_status
, sizeof (compose_status
));
3764 nbytes
= XmbLookupString (FRAME_XIC (f
),
3765 &event
.xkey
, copy_buffer
,
3770 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
3771 80, &keysym
, &compose_status
);
3773 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
3774 80, &keysym
, &compose_status
);
3777 orig_keysym
= keysym
;
3781 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
3782 || keysym
== XK_Delete
3783 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
3784 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
3786 /* This recognizes the "extended function keys".
3787 It seems there's no cleaner way.
3788 Test IsModifierKey to avoid handling mode_switch
3790 || ((unsigned) (keysym
) >= XK_Select
3791 && (unsigned)(keysym
) < XK_KP_Space
)
3793 #ifdef XK_dead_circumflex
3794 || orig_keysym
== XK_dead_circumflex
3796 #ifdef XK_dead_grave
3797 || orig_keysym
== XK_dead_grave
3799 #ifdef XK_dead_tilde
3800 || orig_keysym
== XK_dead_tilde
3802 #ifdef XK_dead_diaeresis
3803 || orig_keysym
== XK_dead_diaeresis
3805 #ifdef XK_dead_macron
3806 || orig_keysym
== XK_dead_macron
3808 #ifdef XK_dead_degree
3809 || orig_keysym
== XK_dead_degree
3811 #ifdef XK_dead_acute
3812 || orig_keysym
== XK_dead_acute
3814 #ifdef XK_dead_cedilla
3815 || orig_keysym
== XK_dead_cedilla
3817 #ifdef XK_dead_breve
3818 || orig_keysym
== XK_dead_breve
3820 #ifdef XK_dead_ogonek
3821 || orig_keysym
== XK_dead_ogonek
3823 #ifdef XK_dead_caron
3824 || orig_keysym
== XK_dead_caron
3826 #ifdef XK_dead_doubleacute
3827 || orig_keysym
== XK_dead_doubleacute
3829 #ifdef XK_dead_abovedot
3830 || orig_keysym
== XK_dead_abovedot
3832 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
3833 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
3834 /* Any "vendor-specific" key is ok. */
3835 || (orig_keysym
& (1 << 28)))
3836 && ! (IsModifierKey (orig_keysym
)
3838 #ifdef XK_Mode_switch
3839 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
3842 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
3844 #endif /* not HAVE_X11R5 */
3847 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3849 temp_buffer
[temp_index
++] = keysym
;
3850 bufp
->kind
= non_ascii_keystroke
;
3851 bufp
->code
= keysym
;
3852 XSETFRAME (bufp
->frame_or_window
, f
);
3854 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3856 bufp
->timestamp
= event
.xkey
.time
;
3861 else if (numchars
> nbytes
)
3865 for (i
= 0; i
< nbytes
; i
++)
3867 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3869 temp_buffer
[temp_index
++] = copy_buffer
[i
];
3870 bufp
->kind
= ascii_keystroke
;
3871 bufp
->code
= copy_buffer
[i
];
3872 XSETFRAME (bufp
->frame_or_window
, f
);
3874 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3876 bufp
->timestamp
= event
.xkey
.time
;
3891 /* Here's a possible interpretation of the whole
3892 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
3893 FocusIn event, you have to get a FocusOut event before you
3894 relinquish the focus. If you haven't received a FocusIn event,
3895 then a mere LeaveNotify is enough to free you. */
3898 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
3900 if (event
.xcrossing
.focus
) /* Entered Window */
3902 /* Avoid nasty pop/raise loops. */
3903 if (f
&& (!(f
->auto_raise
)
3905 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
3907 x_new_focus_frame (dpyinfo
, f
);
3908 enter_timestamp
= event
.xcrossing
.time
;
3911 else if (f
== dpyinfo
->x_focus_frame
)
3912 x_new_focus_frame (dpyinfo
, 0);
3913 /* EnterNotify counts as mouse movement,
3914 so update things that depend on mouse position. */
3916 note_mouse_movement (f
, &event
.xmotion
);
3920 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
3921 if (event
.xfocus
.detail
!= NotifyPointer
)
3922 dpyinfo
->x_focus_event_frame
= f
;
3924 x_new_focus_frame (dpyinfo
, f
);
3927 if (f
&& FRAME_XIC (f
))
3928 XSetICFocus (FRAME_XIC (f
));
3934 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
3937 if (f
== dpyinfo
->mouse_face_mouse_frame
)
3938 /* If we move outside the frame,
3939 then we're certainly no longer on any text in the frame. */
3940 clear_mouse_face (dpyinfo
);
3942 if (event
.xcrossing
.focus
)
3943 x_mouse_leave (dpyinfo
);
3946 if (f
== dpyinfo
->x_focus_event_frame
)
3947 dpyinfo
->x_focus_event_frame
= 0;
3948 if (f
== dpyinfo
->x_focus_frame
)
3949 x_new_focus_frame (dpyinfo
, 0);
3955 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
3956 if (event
.xfocus
.detail
!= NotifyPointer
3957 && f
== dpyinfo
->x_focus_event_frame
)
3958 dpyinfo
->x_focus_event_frame
= 0;
3959 if (f
&& f
== dpyinfo
->x_focus_frame
)
3960 x_new_focus_frame (dpyinfo
, 0);
3963 if (f
&& FRAME_XIC (f
))
3964 XUnsetICFocus (FRAME_XIC (f
));
3971 if (dpyinfo
->grabbed
&& last_mouse_frame
3972 && FRAME_LIVE_P (last_mouse_frame
))
3973 f
= last_mouse_frame
;
3975 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
3977 note_mouse_movement (f
, &event
.xmotion
);
3980 struct scroll_bar
*bar
3981 = x_window_to_scroll_bar (event
.xmotion
.window
);
3984 x_scroll_bar_note_movement (bar
, &event
);
3986 /* If we move outside the frame,
3987 then we're certainly no longer on any text in the frame. */
3988 clear_mouse_face (dpyinfo
);
3993 case ConfigureNotify
:
3994 f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
3996 #ifdef USE_X_TOOLKIT
3997 && (event
.xconfigure
.window
== XtWindow (f
->output_data
.x
->widget
))
4001 #ifndef USE_X_TOOLKIT
4002 /* In the toolkit version, change_frame_size
4003 is called by the code that handles resizing
4004 of the EmacsFrame widget. */
4006 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
4007 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
4009 /* Even if the number of character rows and columns has
4010 not changed, the font size may have changed, so we need
4011 to check the pixel dimensions as well. */
4012 if (columns
!= f
->width
4013 || rows
!= f
->height
4014 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
4015 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
4017 change_frame_size (f
, rows
, columns
, 0, 1);
4018 SET_FRAME_GARBAGED (f
);
4019 cancel_mouse_face (f
);
4023 /* Formerly, in the USE_X_TOOLKIT version,
4024 we did not test send_event here. */
4026 #ifndef USE_X_TOOLKIT
4027 && ! event
.xconfigure
.send_event
4034 /* Find the position of the outside upper-left corner of
4035 the window, in the root coordinate system. Don't
4036 refer to the parent window here; we may be processing
4037 this event after the window manager has changed our
4038 parent, but before we have reached the ReparentNotify. */
4039 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
4041 /* From-window, to-window. */
4042 event
.xconfigure
.window
,
4043 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4045 /* From-position, to-position. */
4046 -event
.xconfigure
.border_width
,
4047 -event
.xconfigure
.border_width
,
4052 event
.xconfigure
.x
= win_x
;
4053 event
.xconfigure
.y
= win_y
;
4056 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
4057 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
4058 f
->output_data
.x
->left_pos
= event
.xconfigure
.x
;
4059 f
->output_data
.x
->top_pos
= event
.xconfigure
.y
;
4061 /* What we have now is the position of Emacs's own window.
4062 Convert that to the position of the window manager window. */
4065 x_real_positions (f
, &x
, &y
);
4066 f
->output_data
.x
->left_pos
= x
;
4067 f
->output_data
.x
->top_pos
= y
;
4068 /* Formerly we did not do this in the USE_X_TOOLKIT
4069 version. Let's try making them the same. */
4070 /* #ifndef USE_X_TOOLKIT */
4071 if (y
!= event
.xconfigure
.y
)
4073 /* Since the WM decorations come below top_pos now,
4074 we must put them below top_pos in the future. */
4075 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
4076 x_wm_set_size_hint (f
, (long) 0, 0);
4086 /* If we decide we want to generate an event to be seen
4087 by the rest of Emacs, we put it here. */
4088 struct input_event emacs_event
;
4089 emacs_event
.kind
= no_event
;
4091 bzero (&compose_status
, sizeof (compose_status
));
4093 if (dpyinfo
->grabbed
&& last_mouse_frame
4094 && FRAME_LIVE_P (last_mouse_frame
))
4095 f
= last_mouse_frame
;
4097 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
4101 if (!dpyinfo
->x_focus_frame
|| f
== dpyinfo
->x_focus_frame
)
4102 construct_mouse_click (&emacs_event
, &event
, f
);
4106 struct scroll_bar
*bar
4107 = x_window_to_scroll_bar (event
.xbutton
.window
);
4110 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
4113 if (event
.type
== ButtonPress
)
4115 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
4116 last_mouse_frame
= f
;
4120 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
4123 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
4125 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
4131 #ifdef USE_X_TOOLKIT
4132 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
4133 /* For a down-event in the menu bar,
4134 don't pass it to Xt right now.
4135 Instead, save it away
4136 and we will pass it to Xt from kbd_buffer_get_event.
4137 That way, we can run some Lisp code first. */
4138 if (f
&& event
.type
== ButtonPress
4139 /* Verify the event is really within the menu bar
4140 and not just sent to it due to grabbing. */
4141 && event
.xbutton
.x
>= 0
4142 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
4143 && event
.xbutton
.y
>= 0
4144 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
4145 && event
.xbutton
.same_screen
)
4147 SET_SAVED_BUTTON_EVENT
;
4148 XSETFRAME (last_mouse_press_frame
, f
);
4150 else if (event
.type
== ButtonPress
)
4152 last_mouse_press_frame
= Qnil
;
4155 #ifdef USE_MOTIF /* This should do not harm for Lucid,
4156 but I am trying to be cautious. */
4157 else if (event
.type
== ButtonRelease
)
4159 if (!NILP (last_mouse_press_frame
))
4161 f
= XFRAME (last_mouse_press_frame
);
4162 if (f
->output_data
.x
)
4164 SET_SAVED_BUTTON_EVENT
;
4170 #endif /* USE_MOTIF */
4173 #endif /* USE_X_TOOLKIT */
4177 case CirculateNotify
:
4179 case CirculateRequest
:
4183 /* Someone has changed the keyboard mapping - update the
4185 switch (event
.xmapping
.request
)
4187 case MappingModifier
:
4188 x_find_modifier_meanings (dpyinfo
);
4189 /* This is meant to fall through. */
4190 case MappingKeyboard
:
4191 XRefreshKeyboardMapping (&event
.xmapping
);
4197 #ifdef USE_X_TOOLKIT
4199 XtDispatchEvent (&event
);
4201 #endif /* USE_X_TOOLKIT */
4207 /* On some systems, an X bug causes Emacs to get no more events
4208 when the window is destroyed. Detect that. (1994.) */
4211 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
4212 One XNOOP in 100 loops will make Emacs terminate.
4213 B. Bretthauer, 1994 */
4215 if (x_noop_count
>= 100)
4219 if (next_noop_dpyinfo
== 0)
4220 next_noop_dpyinfo
= x_display_list
;
4222 XNoOp (next_noop_dpyinfo
->display
);
4224 /* Each time we get here, cycle through the displays now open. */
4225 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
4229 /* If the focus was just given to an autoraising frame,
4231 /* ??? This ought to be able to handle more than one such frame. */
4232 if (pending_autoraise_frame
)
4234 x_raise_frame (pending_autoraise_frame
);
4235 pending_autoraise_frame
= 0;
4242 /* Drawing the cursor. */
4245 /* Draw a hollow box cursor on frame F at X, Y.
4246 Don't change the inside of the box. */
4249 x_draw_box (f
, x
, y
)
4253 int left
= CHAR_TO_PIXEL_COL (f
, x
);
4254 int top
= CHAR_TO_PIXEL_ROW (f
, y
);
4255 int width
= FONT_WIDTH (f
->output_data
.x
->font
);
4256 int height
= f
->output_data
.x
->line_height
;
4258 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4259 f
->output_data
.x
->cursor_gc
,
4260 left
, top
, width
- 1, height
- 1);
4263 /* Clear the cursor of frame F to background color,
4264 and mark the cursor as not shown.
4265 This is used when the text where the cursor is
4266 is about to be rewritten. */
4274 if (! FRAME_VISIBLE_P (f
)
4275 || ! f
->phys_cursor_on
)
4278 x_update_cursor (f
, 0);
4279 f
->phys_cursor_on
= 0;
4282 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4283 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4287 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
4294 CHAR_TO_PIXEL_COL (f
, column
),
4295 CHAR_TO_PIXEL_ROW (f
, row
),
4296 &glyph
, 1, highlight
, 0);
4300 x_display_bar_cursor (f
, on
, x
, y
)
4305 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4307 /* This is pointless on invisible frames, and dangerous on garbaged
4308 frames; in the latter case, the frame may be in the midst of
4309 changing its size, and x and y may be off the frame. */
4310 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4313 if (! on
&& ! f
->phys_cursor_on
)
4316 /* If there is anything wrong with the current cursor state, remove it. */
4317 if (f
->phys_cursor_on
4319 || f
->phys_cursor_x
!= x
4320 || f
->phys_cursor_y
!= y
4321 || f
->output_data
.x
->current_cursor
!= bar_cursor
))
4323 /* Erase the cursor by redrawing the character underneath it. */
4324 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4325 f
->phys_cursor_glyph
,
4326 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4327 f
->phys_cursor_on
= 0;
4330 /* If we now need a cursor in the new place or in the new form, do it so. */
4332 && (! f
->phys_cursor_on
4333 || (f
->output_data
.x
->current_cursor
!= bar_cursor
)))
4335 f
->phys_cursor_glyph
4336 = ((current_glyphs
->enable
[y
]
4337 && x
< current_glyphs
->used
[y
])
4338 ? current_glyphs
->glyphs
[y
][x
]
4340 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4341 f
->output_data
.x
->cursor_gc
,
4342 CHAR_TO_PIXEL_COL (f
, x
),
4343 CHAR_TO_PIXEL_ROW (f
, y
),
4344 max (f
->output_data
.x
->cursor_width
, 1),
4345 f
->output_data
.x
->line_height
);
4347 f
->phys_cursor_x
= x
;
4348 f
->phys_cursor_y
= y
;
4349 f
->phys_cursor_on
= 1;
4351 f
->output_data
.x
->current_cursor
= bar_cursor
;
4354 if (updating_frame
!= f
)
4355 XFlush (FRAME_X_DISPLAY (f
));
4359 /* Turn the displayed cursor of frame F on or off according to ON.
4360 If ON is nonzero, where to put the cursor is specified by X and Y. */
4363 x_display_box_cursor (f
, on
, x
, y
)
4368 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4370 /* This is pointless on invisible frames, and dangerous on garbaged
4371 frames; in the latter case, the frame may be in the midst of
4372 changing its size, and x and y may be off the frame. */
4373 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4376 /* If cursor is off and we want it off, return quickly. */
4377 if (!on
&& ! f
->phys_cursor_on
)
4380 /* If cursor is currently being shown and we don't want it to be
4381 or it is in the wrong place,
4382 or we want a hollow box and it's not so, (pout!)
4384 if (f
->phys_cursor_on
4386 || f
->phys_cursor_x
!= x
4387 || f
->phys_cursor_y
!= y
4388 || (f
->output_data
.x
->current_cursor
!= hollow_box_cursor
4389 && (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
))))
4391 int mouse_face_here
= 0;
4392 struct frame_glyphs
*active_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4394 /* If the cursor is in the mouse face area, redisplay that when
4395 we clear the cursor. */
4396 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
4398 (f
->phys_cursor_y
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4399 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4400 && f
->phys_cursor_x
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
))
4402 (f
->phys_cursor_y
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4403 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4404 && f
->phys_cursor_x
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
))
4405 /* Don't redraw the cursor's spot in mouse face
4406 if it is at the end of a line (on a newline).
4407 The cursor appears there, but mouse highlighting does not. */
4408 && active_glyphs
->used
[f
->phys_cursor_y
] > f
->phys_cursor_x
)
4409 mouse_face_here
= 1;
4411 /* If the font is not as tall as a whole line,
4412 we must explicitly clear the line's whole height. */
4413 if (FONT_HEIGHT (f
->output_data
.x
->font
) != f
->output_data
.x
->line_height
)
4414 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4415 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
4416 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
4417 FONT_WIDTH (f
->output_data
.x
->font
),
4418 f
->output_data
.x
->line_height
, False
);
4419 /* Erase the cursor by redrawing the character underneath it. */
4420 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4421 f
->phys_cursor_glyph
,
4424 : current_glyphs
->highlight
[f
->phys_cursor_y
]));
4425 f
->phys_cursor_on
= 0;
4428 /* If we want to show a cursor,
4429 or we want a box cursor and it's not so,
4430 write it in the right place. */
4432 && (! f
->phys_cursor_on
4433 || (f
->output_data
.x
->current_cursor
!= filled_box_cursor
4434 && f
== FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)))
4436 f
->phys_cursor_glyph
4437 = ((current_glyphs
->enable
[y
]
4438 && x
< current_glyphs
->used
[y
])
4439 ? current_glyphs
->glyphs
[y
][x
]
4441 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
4443 x_draw_box (f
, x
, y
);
4444 f
->output_data
.x
->current_cursor
= hollow_box_cursor
;
4448 x_draw_single_glyph (f
, y
, x
,
4449 f
->phys_cursor_glyph
, 2);
4450 f
->output_data
.x
->current_cursor
= filled_box_cursor
;
4453 f
->phys_cursor_x
= x
;
4454 f
->phys_cursor_y
= y
;
4455 f
->phys_cursor_on
= 1;
4458 if (updating_frame
!= f
)
4459 XFlush (FRAME_X_DISPLAY (f
));
4462 /* Display the cursor on frame F, or clear it, according to ON.
4463 Also set the frame's cursor position to X and Y. */
4465 x_display_cursor (f
, on
, x
, y
)
4472 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4473 x_display_box_cursor (f
, on
, x
, y
);
4474 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4475 x_display_bar_cursor (f
, on
, x
, y
);
4477 /* Those are the only two we have implemented! */
4483 /* Display the cursor on frame F, or clear it, according to ON.
4484 Don't change the cursor's position. */
4486 x_update_cursor (f
, on
)
4492 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4493 x_display_box_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4494 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4495 x_display_bar_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4497 /* Those are the only two we have implemented! */
4505 /* Refresh bitmap kitchen sink icon for frame F
4506 when we get an expose event for it. */
4511 /* Normally, the window manager handles this function. */
4514 /* Make the x-window of frame F use the gnu icon bitmap. */
4517 x_bitmap_icon (f
, file
)
4521 int mask
, bitmap_id
;
4524 if (FRAME_X_WINDOW (f
) == 0)
4527 /* Free up our existing icon bitmap if any. */
4528 if (f
->output_data
.x
->icon_bitmap
> 0)
4529 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
4530 f
->output_data
.x
->icon_bitmap
= 0;
4533 bitmap_id
= x_create_bitmap_from_file (f
, file
);
4536 /* Create the GNU bitmap if necessary. */
4537 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
4538 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
4539 = x_create_bitmap_from_data (f
, gnu_bits
,
4540 gnu_width
, gnu_height
);
4542 /* The first time we create the GNU bitmap,
4543 this increments the refcount one extra time.
4544 As a result, the GNU bitmap is never freed.
4545 That way, we don't have to worry about allocating it again. */
4546 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
4548 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
4551 x_wm_set_icon_pixmap (f
, bitmap_id
);
4552 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
4558 /* Make the x-window of frame F use a rectangle with text.
4559 Use ICON_NAME as the text. */
4562 x_text_icon (f
, icon_name
)
4566 if (FRAME_X_WINDOW (f
) == 0)
4572 text
.value
= (unsigned char *) icon_name
;
4573 text
.encoding
= XA_STRING
;
4575 text
.nitems
= strlen (icon_name
);
4576 #ifdef USE_X_TOOLKIT
4577 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
4579 #else /* not USE_X_TOOLKIT */
4580 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
4581 #endif /* not USE_X_TOOLKIT */
4583 #else /* not HAVE_X11R4 */
4584 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
4585 #endif /* not HAVE_X11R4 */
4587 if (f
->output_data
.x
->icon_bitmap
> 0)
4588 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
4589 f
->output_data
.x
->icon_bitmap
= 0;
4590 x_wm_set_icon_pixmap (f
, 0);
4595 /* Handling X errors. */
4597 /* Handle the loss of connection to display DISPLAY. */
4600 x_connection_closed (display
, error_message
)
4602 char *error_message
;
4604 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
4605 Lisp_Object frame
, tail
;
4607 /* Indicate that this display is dead. */
4609 #ifdef USE_X_TOOLKIT
4610 XtCloseDisplay (display
);
4613 dpyinfo
->display
= 0;
4615 /* First delete frames whose minibuffers are on frames
4616 that are on the dead display. */
4617 FOR_EACH_FRAME (tail
, frame
)
4619 Lisp_Object minibuf_frame
;
4621 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
4622 if (FRAME_X_P (XFRAME (frame
))
4623 && FRAME_X_P (XFRAME (minibuf_frame
))
4624 && ! EQ (frame
, minibuf_frame
)
4625 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
4626 Fdelete_frame (frame
, Qt
);
4629 /* Now delete all remaining frames on the dead display.
4630 We are now sure none of these is used as the minibuffer
4631 for another frame that we need to delete. */
4632 FOR_EACH_FRAME (tail
, frame
)
4633 if (FRAME_X_P (XFRAME (frame
))
4634 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
4636 /* Set this to t so that Fdelete_frame won't get confused
4637 trying to find a replacement. */
4638 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
4639 Fdelete_frame (frame
, Qt
);
4643 x_delete_display (dpyinfo
);
4645 if (x_display_list
== 0)
4647 fprintf (stderr
, "%s\n", error_message
);
4648 shut_down_emacs (0, 0, Qnil
);
4652 /* Ordinary stack unwind doesn't deal with these. */
4654 sigunblock (sigmask (SIGIO
));
4656 sigunblock (sigmask (SIGALRM
));
4657 TOTALLY_UNBLOCK_INPUT
;
4659 clear_waiting_for_input ();
4660 error ("%s", error_message
);
4663 /* This is the usual handler for X protocol errors.
4664 It kills all frames on the display that we got the error for.
4665 If that was the only one, it prints an error message and kills Emacs. */
4668 x_error_quitter (display
, error
)
4672 char buf
[256], buf1
[356];
4674 /* Note that there is no real way portable across R3/R4 to get the
4675 original error handler. */
4677 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
4678 sprintf (buf1
, "X protocol error: %s on protocol request %d",
4679 buf
, error
->request_code
);
4680 x_connection_closed (display
, buf1
);
4683 /* This is the handler for X IO errors, always.
4684 It kills all frames on the display that we lost touch with.
4685 If that was the only one, it prints an error message and kills Emacs. */
4688 x_io_error_quitter (display
)
4693 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
4694 x_connection_closed (display
, buf
);
4697 /* Handle SIGPIPE, which can happen when the connection to a server
4698 simply goes away. SIGPIPE is handled by x_connection_signal.
4699 Don't need to do anything, because the write which caused the
4700 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
4701 which will do the appropriate cleanup for us. */
4704 x_connection_signal (signalnum
) /* If we don't have an argument, */
4705 int signalnum
; /* some compilers complain in signal calls. */
4708 /* USG systems forget handlers when they are used;
4709 must reestablish each time */
4710 signal (signalnum
, x_connection_signal
);
4714 /* A buffer for storing X error messages. */
4715 static char *x_caught_error_message
;
4716 #define X_CAUGHT_ERROR_MESSAGE_SIZE 200
4718 /* An X error handler which stores the error message in
4719 x_caught_error_message. This is what's installed when
4720 x_catch_errors is in effect. */
4723 x_error_catcher (display
, error
)
4727 XGetErrorText (display
, error
->error_code
,
4728 x_caught_error_message
, X_CAUGHT_ERROR_MESSAGE_SIZE
);
4732 /* Begin trapping X errors for display DPY. Actually we trap X errors
4733 for all displays, but DPY should be the display you are actually
4736 After calling this function, X protocol errors no longer cause
4737 Emacs to exit; instead, they are recorded in x_cfc_error_message.
4739 Calling x_check_errors signals an Emacs error if an X error has
4740 occurred since the last call to x_catch_errors or x_check_errors.
4742 Calling x_uncatch_errors resumes the normal error handling. */
4744 void x_catch_errors (), x_check_errors (), x_uncatch_errors ();
4747 x_catch_errors (dpy
)
4750 /* Make sure any errors from previous requests have been dealt with. */
4753 /* Set up the error buffer. */
4754 x_caught_error_message
4755 = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE
);
4756 x_caught_error_message
[0] = '\0';
4758 /* Install our little error handler. */
4759 XSetErrorHandler (x_error_catcher
);
4762 /* If any X protocol errors have arrived since the last call to
4763 x_catch_errors or x_check_errors, signal an Emacs error using
4764 sprintf (a buffer, FORMAT, the x error message text) as the text. */
4767 x_check_errors (dpy
, format
)
4771 /* Make sure to catch any errors incurred so far. */
4774 if (x_caught_error_message
[0])
4776 char buf
[X_CAUGHT_ERROR_MESSAGE_SIZE
+ 56];
4778 sprintf (buf
, format
, x_caught_error_message
);
4779 x_uncatch_errors (dpy
);
4784 /* Nonzero if we had any X protocol errors since we did x_catch_errors. */
4787 x_had_errors_p (dpy
)
4790 /* Make sure to catch any errors incurred so far. */
4793 return x_caught_error_message
[0] != 0;
4796 /* Stop catching X protocol errors and let them make Emacs die. */
4799 x_uncatch_errors (dpy
)
4802 xfree (x_caught_error_message
);
4803 x_caught_error_message
= 0;
4804 XSetErrorHandler (x_error_quitter
);
4808 static unsigned int x_wire_count
;
4811 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
4816 /* Changing the font of the frame. */
4818 /* Give frame F the font named FONTNAME as its default font, and
4819 return the full name of that font. FONTNAME may be a wildcard
4820 pattern; in that case, we choose some font that fits the pattern.
4821 The return value shows which font we chose. */
4824 x_new_font (f
, fontname
)
4826 register char *fontname
;
4829 int n_matching_fonts
;
4830 XFontStruct
*font_info
;
4833 /* Get a list of all the fonts that match this name. Once we
4834 have a list of matching fonts, we compare them against the fonts
4835 we already have by comparing font ids. */
4836 font_names
= (char **) XListFonts (FRAME_X_DISPLAY (f
), fontname
,
4837 1024, &n_matching_fonts
);
4838 /* Apparently it doesn't set n_matching_fonts to zero when it can't
4839 find any matches; font_names == 0 is the only clue. */
4841 n_matching_fonts
= 0;
4843 /* Don't just give up if n_matching_fonts is 0.
4844 Apparently there's a bug on Suns: XListFontsWithInfo can
4845 fail to find a font, but XLoadQueryFont may still find it. */
4847 /* See if we've already loaded a matching font. */
4848 already_loaded
= -1;
4849 if (n_matching_fonts
!= 0)
4853 for (i
= 0; i
< FRAME_X_DISPLAY_INFO (f
)->n_fonts
; i
++)
4854 for (j
= 0; j
< n_matching_fonts
; j
++)
4855 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].name
, font_names
[j
])
4856 || !strcmp (FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].full_name
, font_names
[j
]))
4859 fontname
= FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].full_name
;
4865 /* If we have, just return it from the table. */
4866 if (already_loaded
>= 0)
4867 f
->output_data
.x
->font
= FRAME_X_DISPLAY_INFO (f
)->font_table
[already_loaded
].font
;
4868 /* Otherwise, load the font and add it to the table. */
4876 /* Try to find a character-cell font in the list. */
4878 /* A laudable goal, but this isn't how to do it. */
4879 for (i
= 0; i
< n_matching_fonts
; i
++)
4880 if (! font_info
[i
].per_char
)
4886 /* See comment above. */
4887 if (n_matching_fonts
!= 0)
4888 fontname
= font_names
[i
];
4890 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
4893 /* Free the information from XListFonts. */
4894 if (n_matching_fonts
)
4895 XFreeFontNames (font_names
);
4899 /* Do we need to create the table? */
4900 if (FRAME_X_DISPLAY_INFO (f
)->font_table_size
== 0)
4902 FRAME_X_DISPLAY_INFO (f
)->font_table_size
= 16;
4903 FRAME_X_DISPLAY_INFO (f
)->font_table
4904 = (struct font_info
*) xmalloc (FRAME_X_DISPLAY_INFO (f
)->font_table_size
4905 * sizeof (struct font_info
));
4907 /* Do we need to grow the table? */
4908 else if (FRAME_X_DISPLAY_INFO (f
)->n_fonts
4909 >= FRAME_X_DISPLAY_INFO (f
)->font_table_size
)
4911 FRAME_X_DISPLAY_INFO (f
)->font_table_size
*= 2;
4912 FRAME_X_DISPLAY_INFO (f
)->font_table
4913 = (struct font_info
*) xrealloc (FRAME_X_DISPLAY_INFO (f
)->font_table
,
4914 (FRAME_X_DISPLAY_INFO (f
)->font_table_size
4915 * sizeof (struct font_info
)));
4918 /* Try to get the full name of FONT. Put it in full_name. */
4920 for (i
= 0; i
< font
->n_properties
; i
++)
4922 if (FRAME_X_DISPLAY_INFO (f
)->Xatom_FONT
== font
->properties
[i
].name
)
4924 char *name
= XGetAtomName (FRAME_X_DISPLAY (f
),
4925 (Atom
) (font
->properties
[i
].card32
));
4929 /* Count the number of dashes in the "full name".
4930 If it is too few, this isn't really the font's full name,
4932 In X11R4, the fonts did not come with their canonical names
4948 n_fonts
= FRAME_X_DISPLAY_INFO (f
)->n_fonts
;
4949 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
= (char *) xmalloc (strlen (fontname
) + 1);
4950 bcopy (fontname
, FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
, strlen (fontname
) + 1);
4952 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].full_name
= full_name
;
4954 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].full_name
= FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
;
4955 f
->output_data
.x
->font
= FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].font
= font
;
4956 FRAME_X_DISPLAY_INFO (f
)->n_fonts
++;
4959 fontname
= full_name
;
4962 /* Compute the scroll bar width in character columns. */
4963 if (f
->scroll_bar_pixel_width
> 0)
4965 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
4966 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
4969 f
->scroll_bar_cols
= 2;
4971 /* Now make the frame display the given font. */
4972 if (FRAME_X_WINDOW (f
) != 0)
4974 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
4975 f
->output_data
.x
->font
->fid
);
4976 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
4977 f
->output_data
.x
->font
->fid
);
4978 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
4979 f
->output_data
.x
->font
->fid
);
4981 frame_update_line_height (f
);
4982 x_set_window_size (f
, 0, f
->width
, f
->height
);
4985 /* If we are setting a new frame's font for the first time,
4986 there are no faces yet, so this font's height is the line height. */
4987 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
4990 Lisp_Object lispy_name
;
4992 lispy_name
= build_string (fontname
);
4994 /* Free the information from XListFonts. The data
4995 we actually retain comes from XLoadQueryFont. */
4996 XFreeFontNames (font_names
);
5002 /* Calculate the absolute position in frame F
5003 from its current recorded position values and gravity. */
5005 x_calc_absolute_position (f
)
5009 int win_x
= 0, win_y
= 0;
5010 int flags
= f
->output_data
.x
->size_hint_flags
;
5013 #ifdef USE_X_TOOLKIT
5014 this_window
= XtWindow (f
->output_data
.x
->widget
);
5016 this_window
= FRAME_X_WINDOW (f
);
5019 /* Find the position of the outside upper-left corner of
5020 the inner window, with respect to the outer window. */
5021 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
5024 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
5026 /* From-window, to-window. */
5028 f
->output_data
.x
->parent_desc
,
5030 /* From-position, to-position. */
5031 0, 0, &win_x
, &win_y
,
5038 /* Treat negative positions as relative to the leftmost bottommost
5039 position that fits on the screen. */
5040 if (flags
& XNegative
)
5041 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
5042 - 2 * f
->output_data
.x
->border_width
- win_x
5044 + f
->output_data
.x
->left_pos
);
5046 if (flags
& YNegative
)
5047 /* We used to subtract f->output_data.x->menubar_height here
5048 in the toolkit case, but PIXEL_HEIGHT already includes that. */
5049 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
5050 - 2 * f
->output_data
.x
->border_width
- win_y
5052 + f
->output_data
.x
->top_pos
);
5054 /* The left_pos and top_pos
5055 are now relative to the top and left screen edges,
5056 so the flags should correspond. */
5057 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5060 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5061 to really change the position, and 0 when calling from
5062 x_make_frame_visible (in that case, XOFF and YOFF are the current
5063 position values). It is -1 when calling from x_set_frame_parameters,
5064 which means, do adjust for borders but don't change the gravity. */
5066 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5068 register int xoff
, yoff
;
5071 int modified_top
, modified_left
;
5073 if (change_gravity
> 0)
5075 f
->output_data
.x
->top_pos
= yoff
;
5076 f
->output_data
.x
->left_pos
= xoff
;
5077 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5079 f
->output_data
.x
->size_hint_flags
|= XNegative
;
5081 f
->output_data
.x
->size_hint_flags
|= YNegative
;
5082 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
5084 x_calc_absolute_position (f
);
5087 x_wm_set_size_hint (f
, (long) 0, 0);
5089 /* It is a mystery why we need to add the border_width here
5090 when the frame is already visible, but experiment says we do. */
5091 modified_left
= f
->output_data
.x
->left_pos
;
5092 modified_top
= f
->output_data
.x
->top_pos
;
5093 if (change_gravity
!= 0)
5095 modified_left
+= f
->output_data
.x
->border_width
;
5096 modified_top
+= f
->output_data
.x
->border_width
;
5099 #ifdef USE_X_TOOLKIT
5100 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
5101 modified_left
, modified_top
);
5102 #else /* not USE_X_TOOLKIT */
5103 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5104 modified_left
, modified_top
);
5105 #endif /* not USE_X_TOOLKIT */
5109 /* Call this to change the size of frame F's x-window.
5110 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5111 for this size change and subsequent size changes.
5112 Otherwise we leave the window gravity unchanged. */
5114 x_set_window_size (f
, change_gravity
, cols
, rows
)
5119 int pixelwidth
, pixelheight
;
5121 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5125 #ifdef USE_X_TOOLKIT
5127 /* The x and y position of the widget is clobbered by the
5128 call to XtSetValues within EmacsFrameSetCharSize.
5129 This is a real kludge, but I don't understand Xt so I can't
5130 figure out a correct fix. Can anyone else tell me? -- rms. */
5131 int xpos
= f
->output_data
.x
->widget
->core
.x
;
5132 int ypos
= f
->output_data
.x
->widget
->core
.y
;
5133 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
5134 f
->output_data
.x
->widget
->core
.x
= xpos
;
5135 f
->output_data
.x
->widget
->core
.y
= ypos
;
5138 #else /* not USE_X_TOOLKIT */
5140 check_frame_size (f
, &rows
, &cols
);
5141 f
->output_data
.x
->vertical_scroll_bar_extra
5142 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5144 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
5145 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
5146 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
5147 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
5148 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
5150 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
5151 x_wm_set_size_hint (f
, (long) 0, 0);
5153 XSync (FRAME_X_DISPLAY (f
), False
);
5154 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5155 pixelwidth
, pixelheight
);
5157 /* Now, strictly speaking, we can't be sure that this is accurate,
5158 but the window manager will get around to dealing with the size
5159 change request eventually, and we'll hear how it went when the
5160 ConfigureNotify event gets here.
5162 We could just not bother storing any of this information here,
5163 and let the ConfigureNotify event set everything up, but that
5164 might be kind of confusing to the lisp code, since size changes
5165 wouldn't be reported in the frame parameters until some random
5166 point in the future when the ConfigureNotify event arrives. */
5167 change_frame_size (f
, rows
, cols
, 0, 0);
5168 PIXEL_WIDTH (f
) = pixelwidth
;
5169 PIXEL_HEIGHT (f
) = pixelheight
;
5171 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5172 receive in the ConfigureNotify event; if we get what we asked
5173 for, then the event won't cause the screen to become garbaged, so
5174 we have to make sure to do it here. */
5175 SET_FRAME_GARBAGED (f
);
5177 XFlush (FRAME_X_DISPLAY (f
));
5179 #endif /* not USE_X_TOOLKIT */
5181 /* If cursor was outside the new size, mark it as off. */
5182 if (f
->phys_cursor_y
>= rows
5183 || f
->phys_cursor_x
>= cols
)
5185 f
->phys_cursor_x
= 0;
5186 f
->phys_cursor_y
= 0;
5187 f
->phys_cursor_on
= 0;
5190 /* Clear out any recollection of where the mouse highlighting was,
5191 since it might be in a place that's outside the new frame size.
5192 Actually checking whether it is outside is a pain in the neck,
5193 so don't try--just let the highlighting be done afresh with new size. */
5194 cancel_mouse_face (f
);
5199 /* Mouse warping. */
5202 x_set_mouse_position (f
, x
, y
)
5208 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
5209 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
5211 if (pix_x
< 0) pix_x
= 0;
5212 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
5214 if (pix_y
< 0) pix_y
= 0;
5215 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
5219 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5220 0, 0, 0, 0, pix_x
, pix_y
);
5224 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
5227 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5233 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5234 0, 0, 0, 0, pix_x
, pix_y
);
5238 /* focus shifting, raising and lowering. */
5240 x_focus_on_frame (f
)
5243 #if 0 /* This proves to be unpleasant. */
5247 /* I don't think that the ICCCM allows programs to do things like this
5248 without the interaction of the window manager. Whatever you end up
5249 doing with this code, do it to x_unfocus_frame too. */
5250 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5251 RevertToPointerRoot
, CurrentTime
);
5259 /* Look at the remarks in x_focus_on_frame. */
5260 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
5261 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
5262 RevertToPointerRoot
, CurrentTime
);
5266 /* Raise frame F. */
5271 if (f
->async_visible
)
5274 #ifdef USE_X_TOOLKIT
5275 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
5276 #else /* not USE_X_TOOLKIT */
5277 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5278 #endif /* not USE_X_TOOLKIT */
5279 XFlush (FRAME_X_DISPLAY (f
));
5284 /* Lower frame F. */
5289 if (f
->async_visible
)
5292 #ifdef USE_X_TOOLKIT
5293 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
5294 #else /* not USE_X_TOOLKIT */
5295 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5296 #endif /* not USE_X_TOOLKIT */
5297 XFlush (FRAME_X_DISPLAY (f
));
5303 XTframe_raise_lower (f
, raise_flag
)
5313 /* Change of visibility. */
5315 /* This tries to wait until the frame is really visible.
5316 However, if the window manager asks the user where to position
5317 the frame, this will return before the user finishes doing that.
5318 The frame will not actually be visible at that time,
5319 but it will become visible later when the window manager
5320 finishes with it. */
5322 x_make_frame_visible (f
)
5330 type
= x_icon_type (f
);
5332 x_bitmap_icon (f
, type
);
5334 if (! FRAME_VISIBLE_P (f
))
5336 /* We test FRAME_GARBAGED_P here to make sure we don't
5337 call x_set_offset a second time
5338 if we get to x_make_frame_visible a second time
5339 before the window gets really visible. */
5340 if (! FRAME_ICONIFIED_P (f
)
5341 && ! f
->output_data
.x
->asked_for_visible
)
5342 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
5344 f
->output_data
.x
->asked_for_visible
= 1;
5346 if (! EQ (Vx_no_window_manager
, Qt
))
5347 x_wm_set_window_state (f
, NormalState
);
5348 #ifdef USE_X_TOOLKIT
5349 /* This was XtPopup, but that did nothing for an iconified frame. */
5350 XtMapWidget (f
->output_data
.x
->widget
);
5351 #else /* not USE_X_TOOLKIT */
5352 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5353 #endif /* not USE_X_TOOLKIT */
5354 #if 0 /* This seems to bring back scroll bars in the wrong places
5355 if the window configuration has changed. They seem
5356 to come back ok without this. */
5357 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5358 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5362 XFlush (FRAME_X_DISPLAY (f
));
5364 /* Synchronize to ensure Emacs knows the frame is visible
5365 before we do anything else. We do this loop with input not blocked
5366 so that incoming events are handled. */
5369 int count
= input_signal_count
;
5371 /* This must come after we set COUNT. */
5374 XSETFRAME (frame
, f
);
5379 /* Once we have handled input events,
5380 we should have received the MapNotify if one is coming.
5381 So if we have not got it yet, stop looping.
5382 Some window managers make their own decisions
5383 about visibility. */
5384 if (input_signal_count
!= count
)
5386 /* Machines that do polling rather than SIGIO have been observed
5387 to go into a busy-wait here. So we'll fake an alarm signal
5388 to let the handler know that there's something to be read.
5389 We used to raise a real alarm, but it seems that the handler
5390 isn't always enabled here. This is probably a bug. */
5391 if (input_polling_used ())
5393 /* It could be confusing if a real alarm arrives while processing
5394 the fake one. Turn it off and let the handler reset it. */
5396 input_poll_signal ();
5398 /* Once we have handled input events,
5399 we should have received the MapNotify if one is coming.
5400 So if we have not got it yet, stop looping.
5401 Some window managers make their own decisions
5402 about visibility. */
5403 if (input_signal_count
!= count
)
5406 FRAME_SAMPLE_VISIBILITY (f
);
5410 /* Change from mapped state to withdrawn state. */
5412 /* Make the frame visible (mapped and not iconified). */
5414 x_make_frame_invisible (f
)
5420 #ifdef USE_X_TOOLKIT
5421 /* Use the frame's outermost window, not the one we normally draw on. */
5422 window
= XtWindow (f
->output_data
.x
->widget
);
5423 #else /* not USE_X_TOOLKIT */
5424 window
= FRAME_X_WINDOW (f
);
5425 #endif /* not USE_X_TOOLKIT */
5427 /* Don't keep the highlight on an invisible frame. */
5428 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5429 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5431 #if 0/* This might add unreliability; I don't trust it -- rms. */
5432 if (! f
->async_visible
&& ! f
->async_iconified
)
5438 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5439 that the current position of the window is user-specified, rather than
5440 program-specified, so that when the window is mapped again, it will be
5441 placed at the same location, without forcing the user to position it
5442 by hand again (they have already done that once for this window.) */
5443 x_wm_set_size_hint (f
, (long) 0, 1);
5447 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
5448 DefaultScreen (FRAME_X_DISPLAY (f
))))
5450 UNBLOCK_INPUT_RESIGNAL
;
5451 error ("Can't notify window manager of window withdrawal");
5453 #else /* ! defined (HAVE_X11R4) */
5455 /* Tell the window manager what we're going to do. */
5456 if (! EQ (Vx_no_window_manager
, Qt
))
5460 unmap
.xunmap
.type
= UnmapNotify
;
5461 unmap
.xunmap
.window
= window
;
5462 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
5463 unmap
.xunmap
.from_configure
= False
;
5464 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5465 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5467 SubstructureRedirectMask
|SubstructureNotifyMask
,
5470 UNBLOCK_INPUT_RESIGNAL
;
5471 error ("Can't notify window manager of withdrawal");
5475 /* Unmap the window ourselves. Cheeky! */
5476 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
5477 #endif /* ! defined (HAVE_X11R4) */
5479 /* We can't distinguish this from iconification
5480 just by the event that we get from the server.
5481 So we can't win using the usual strategy of letting
5482 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5483 and synchronize with the server to make sure we agree. */
5485 FRAME_ICONIFIED_P (f
) = 0;
5486 f
->async_visible
= 0;
5487 f
->async_iconified
= 0;
5494 /* Change window state from mapped to iconified. */
5503 /* Don't keep the highlight on an invisible frame. */
5504 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5505 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5507 if (f
->async_iconified
)
5512 FRAME_SAMPLE_VISIBILITY (f
);
5514 type
= x_icon_type (f
);
5516 x_bitmap_icon (f
, type
);
5518 #ifdef USE_X_TOOLKIT
5520 if (! FRAME_VISIBLE_P (f
))
5522 if (! EQ (Vx_no_window_manager
, Qt
))
5523 x_wm_set_window_state (f
, IconicState
);
5524 /* This was XtPopup, but that did nothing for an iconified frame. */
5525 XtMapWidget (f
->output_data
.x
->widget
);
5526 /* The server won't give us any event to indicate
5527 that an invisible frame was changed to an icon,
5528 so we have to record it here. */
5531 f
->async_iconified
= 1;
5532 f
->async_visible
= 0;
5537 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
5538 XtWindow (f
->output_data
.x
->widget
),
5539 DefaultScreen (FRAME_X_DISPLAY (f
)));
5543 error ("Can't notify window manager of iconification");
5545 f
->async_iconified
= 1;
5546 f
->async_visible
= 0;
5550 XFlush (FRAME_X_DISPLAY (f
));
5552 #else /* not USE_X_TOOLKIT */
5554 /* Make sure the X server knows where the window should be positioned,
5555 in case the user deiconifies with the window manager. */
5556 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
5557 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
5559 /* Since we don't know which revision of X we're running, we'll use both
5560 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
5562 /* X11R4: send a ClientMessage to the window manager using the
5563 WM_CHANGE_STATE type. */
5567 message
.xclient
.window
= FRAME_X_WINDOW (f
);
5568 message
.xclient
.type
= ClientMessage
;
5569 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
5570 message
.xclient
.format
= 32;
5571 message
.xclient
.data
.l
[0] = IconicState
;
5573 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5574 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5576 SubstructureRedirectMask
| SubstructureNotifyMask
,
5579 UNBLOCK_INPUT_RESIGNAL
;
5580 error ("Can't notify window manager of iconification");
5584 /* X11R3: set the initial_state field of the window manager hints to
5586 x_wm_set_window_state (f
, IconicState
);
5588 if (!FRAME_VISIBLE_P (f
))
5590 /* If the frame was withdrawn, before, we must map it. */
5591 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5594 f
->async_iconified
= 1;
5595 f
->async_visible
= 0;
5597 XFlush (FRAME_X_DISPLAY (f
));
5599 #endif /* not USE_X_TOOLKIT */
5602 /* Destroy the X window of frame F. */
5604 x_destroy_window (f
)
5607 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5611 /* If a display connection is dead, don't try sending more
5612 commands to the X server. */
5613 if (dpyinfo
->display
!= 0)
5615 if (f
->output_data
.x
->icon_desc
!= 0)
5616 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
5620 XDestroyIC (FRAME_XIC (f
));
5621 #if ! defined (SOLARIS2) || defined (HAVE_X11R6)
5622 /* This line causes crashes on Solaris with Openwin,
5623 due to an apparent bug in XCloseIM.
5624 X11R6 seems not to have the bug. */
5625 XCloseIM (FRAME_XIM (f
));
5629 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
5630 #ifdef USE_X_TOOLKIT
5631 XtDestroyWidget (f
->output_data
.x
->widget
);
5632 free_frame_menubar (f
);
5633 #endif /* USE_X_TOOLKIT */
5635 free_frame_faces (f
);
5636 XFlush (FRAME_X_DISPLAY (f
));
5639 xfree (f
->output_data
.x
);
5640 f
->output_data
.x
= 0;
5641 if (f
== dpyinfo
->x_focus_frame
)
5642 dpyinfo
->x_focus_frame
= 0;
5643 if (f
== dpyinfo
->x_focus_event_frame
)
5644 dpyinfo
->x_focus_event_frame
= 0;
5645 if (f
== dpyinfo
->x_highlight_frame
)
5646 dpyinfo
->x_highlight_frame
= 0;
5648 dpyinfo
->reference_count
--;
5650 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5652 dpyinfo
->mouse_face_beg_row
5653 = dpyinfo
->mouse_face_beg_col
= -1;
5654 dpyinfo
->mouse_face_end_row
5655 = dpyinfo
->mouse_face_end_col
= -1;
5656 dpyinfo
->mouse_face_window
= Qnil
;
5662 /* Setting window manager hints. */
5664 /* Set the normal size hints for the window manager, for frame F.
5665 FLAGS is the flags word to use--or 0 meaning preserve the flags
5666 that the window now has.
5667 If USER_POSITION is nonzero, we set the USPosition
5668 flag (this is useful when FLAGS is 0). */
5670 x_wm_set_size_hint (f
, flags
, user_position
)
5675 XSizeHints size_hints
;
5677 #ifdef USE_X_TOOLKIT
5680 Dimension widget_width
, widget_height
;
5681 Window window
= XtWindow (f
->output_data
.x
->widget
);
5682 #else /* not USE_X_TOOLKIT */
5683 Window window
= FRAME_X_WINDOW (f
);
5684 #endif /* not USE_X_TOOLKIT */
5686 /* Setting PMaxSize caused various problems. */
5687 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
5689 flexlines
= f
->height
;
5691 size_hints
.x
= f
->output_data
.x
->left_pos
;
5692 size_hints
.y
= f
->output_data
.x
->top_pos
;
5694 #ifdef USE_X_TOOLKIT
5695 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
5696 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
5697 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
5698 size_hints
.height
= widget_height
;
5699 size_hints
.width
= widget_width
;
5700 #else /* not USE_X_TOOLKIT */
5701 size_hints
.height
= PIXEL_HEIGHT (f
);
5702 size_hints
.width
= PIXEL_WIDTH (f
);
5703 #endif /* not USE_X_TOOLKIT */
5705 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
5706 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
5707 size_hints
.max_width
5708 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
5709 size_hints
.max_height
5710 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
5712 /* Calculate the base and minimum sizes.
5714 (When we use the X toolkit, we don't do it here.
5715 Instead we copy the values that the widgets are using, below.) */
5716 #ifndef USE_X_TOOLKIT
5718 int base_width
, base_height
;
5719 int min_rows
= 0, min_cols
= 0;
5721 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
5722 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
5724 check_frame_size (f
, &min_rows
, &min_cols
);
5726 /* The window manager uses the base width hints to calculate the
5727 current number of rows and columns in the frame while
5728 resizing; min_width and min_height aren't useful for this
5729 purpose, since they might not give the dimensions for a
5730 zero-row, zero-column frame.
5732 We use the base_width and base_height members if we have
5733 them; otherwise, we set the min_width and min_height members
5734 to the size for a zero x zero frame. */
5737 size_hints
.flags
|= PBaseSize
;
5738 size_hints
.base_width
= base_width
;
5739 size_hints
.base_height
= base_height
;
5740 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
5741 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
5743 size_hints
.min_width
= base_width
;
5744 size_hints
.min_height
= base_height
;
5748 /* If we don't need the old flags, we don't need the old hint at all. */
5751 size_hints
.flags
|= flags
;
5754 #endif /* not USE_X_TOOLKIT */
5757 XSizeHints hints
; /* Sometimes I hate X Windows... */
5758 long supplied_return
;
5762 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
5765 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
5768 #ifdef USE_X_TOOLKIT
5769 size_hints
.base_height
= hints
.base_height
;
5770 size_hints
.base_width
= hints
.base_width
;
5771 size_hints
.min_height
= hints
.min_height
;
5772 size_hints
.min_width
= hints
.min_width
;
5776 size_hints
.flags
|= flags
;
5781 if (hints
.flags
& PSize
)
5782 size_hints
.flags
|= PSize
;
5783 if (hints
.flags
& PPosition
)
5784 size_hints
.flags
|= PPosition
;
5785 if (hints
.flags
& USPosition
)
5786 size_hints
.flags
|= USPosition
;
5787 if (hints
.flags
& USSize
)
5788 size_hints
.flags
|= USSize
;
5795 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
5796 size_hints
.flags
|= PWinGravity
;
5800 size_hints
.flags
&= ~ PPosition
;
5801 size_hints
.flags
|= USPosition
;
5803 #endif /* PWinGravity */
5806 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
5808 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
5812 /* Used for IconicState or NormalState */
5813 x_wm_set_window_state (f
, state
)
5817 #ifdef USE_X_TOOLKIT
5820 XtSetArg (al
[0], XtNinitialState
, state
);
5821 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
5822 #else /* not USE_X_TOOLKIT */
5823 Window window
= FRAME_X_WINDOW (f
);
5825 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
5826 f
->output_data
.x
->wm_hints
.initial_state
= state
;
5828 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
5829 #endif /* not USE_X_TOOLKIT */
5832 x_wm_set_icon_pixmap (f
, pixmap_id
)
5838 #ifdef USE_X_TOOLKIT
5839 Window window
= XtWindow (f
->output_data
.x
->widget
);
5841 Window window
= FRAME_X_WINDOW (f
);
5846 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
5847 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
5851 /* It seems there is no way to turn off use of an icon pixmap.
5852 The following line does it, only if no icon has yet been created,
5853 for some window managers. But with mwm it crashes.
5854 Some people say it should clear the IconPixmapHint bit in this case,
5855 but that doesn't work, and the X consortium said it isn't the
5856 right thing at all. Since there is no way to win,
5857 best to explicitly give up. */
5859 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
5865 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
5869 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
5870 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
5873 #else /* not USE_X_TOOLKIT */
5875 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
5876 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
5878 #endif /* not USE_X_TOOLKIT */
5881 x_wm_set_icon_position (f
, icon_x
, icon_y
)
5885 #ifdef USE_X_TOOLKIT
5886 Window window
= XtWindow (f
->output_data
.x
->widget
);
5888 Window window
= FRAME_X_WINDOW (f
);
5891 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
5892 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
5893 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
5895 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
5899 /* Initialization. */
5901 #ifdef USE_X_TOOLKIT
5902 static XrmOptionDescRec emacs_options
[] = {
5903 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
5904 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
5906 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
5907 XrmoptionSepArg
, NULL
},
5908 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
5910 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5911 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5912 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5913 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5914 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5915 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
5916 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
5918 #endif /* USE_X_TOOLKIT */
5920 static int x_initialized
;
5923 /* Test whether two display-name strings agree up to the dot that separates
5924 the screen number from the server number. */
5926 same_x_server (name1
, name2
)
5927 char *name1
, *name2
;
5930 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
5934 if (seen_colon
&& *name1
== '.')
5938 && (*name1
== '.' || *name1
== '\0')
5939 && (*name2
== '.' || *name2
== '\0'));
5943 struct x_display_info
*
5944 x_term_init (display_name
, xrm_option
, resource_name
)
5945 Lisp_Object display_name
;
5947 char *resource_name
;
5953 struct x_display_info
*dpyinfo
;
5965 setlocale (LC_ALL
, "");
5966 /* In case we just overrode what init_lread did, redo it. */
5967 setlocale (LC_NUMERIC
, "C");
5968 setlocale (LC_TIME
, "C");
5971 #ifdef USE_X_TOOLKIT
5972 /* weiner@footloose.sps.mot.com reports that this causes
5974 X protocol error: BadAtom (invalid Atom parameter)
5975 on protocol request 18skiloaf.
5976 So let's not use it until R6. */
5978 XtSetLanguageProc (NULL
, NULL
, NULL
);
5989 argv
[argc
++] = "-xrm";
5990 argv
[argc
++] = xrm_option
;
5992 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
5993 resource_name
, EMACS_CLASS
,
5994 emacs_options
, XtNumber (emacs_options
),
5998 /* I think this is to compensate for XtSetLanguageProc. */
5999 setlocale (LC_NUMERIC
, "C");
6000 setlocale (LC_TIME
, "C");
6004 #else /* not USE_X_TOOLKIT */
6006 XSetLocaleModifiers ("");
6008 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
6009 #endif /* not USE_X_TOOLKIT */
6011 /* Detect failure. */
6018 /* We have definitely succeeded. Record the new connection. */
6020 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
6024 struct x_display_info
*share
;
6027 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
6028 share
= share
->next
, tail
= XCONS (tail
)->cdr
)
6029 if (same_x_server (XSTRING (XCONS (XCONS (tail
)->car
)->car
)->data
,
6030 XSTRING (display_name
)->data
))
6033 dpyinfo
->kboard
= share
->kboard
;
6036 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
6037 init_kboard (dpyinfo
->kboard
);
6038 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
6040 char *vendor
= ServerVendor (dpy
);
6041 dpyinfo
->kboard
->Vsystem_key_alist
6042 = call1 (Qvendor_specific_keysyms
,
6043 build_string (vendor
? vendor
: ""));
6046 dpyinfo
->kboard
->next_kboard
= all_kboards
;
6047 all_kboards
= dpyinfo
->kboard
;
6048 /* Don't let the initial kboard remain current longer than necessary.
6049 That would cause problems if a file loaded on startup tries to
6050 prompt in the minibuffer. */
6051 if (current_kboard
== initial_kboard
)
6052 current_kboard
= dpyinfo
->kboard
;
6054 dpyinfo
->kboard
->reference_count
++;
6058 /* Put this display on the chain. */
6059 dpyinfo
->next
= x_display_list
;
6060 x_display_list
= dpyinfo
;
6062 /* Put it on x_display_name_list as well, to keep them parallel. */
6063 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
6064 x_display_name_list
);
6065 dpyinfo
->name_list_element
= XCONS (x_display_name_list
)->car
;
6067 dpyinfo
->display
= dpy
;
6070 XSetAfterFunction (x_current_display
, x_trace_wire
);
6074 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
6075 + XSTRING (Vsystem_name
)->size
6077 sprintf (dpyinfo
->x_id_name
, "%s@%s",
6078 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
6080 /* Figure out which modifier bits mean what. */
6081 x_find_modifier_meanings (dpyinfo
);
6083 /* Get the scroll bar cursor. */
6084 dpyinfo
->vertical_scroll_bar_cursor
6085 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
6087 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
6088 resource_name
, EMACS_CLASS
);
6089 #ifdef HAVE_XRMSETDATABASE
6090 XrmSetDatabase (dpyinfo
->display
, xrdb
);
6092 dpyinfo
->display
->db
= xrdb
;
6094 /* Put the rdb where we can find it in a way that works on
6096 dpyinfo
->xrdb
= xrdb
;
6098 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
6099 DefaultScreen (dpyinfo
->display
));
6100 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
6101 &dpyinfo
->n_planes
);
6102 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
6103 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
6104 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
6105 dpyinfo
->grabbed
= 0;
6106 dpyinfo
->reference_count
= 0;
6107 dpyinfo
->icon_bitmap_id
= -1;
6108 dpyinfo
->n_fonts
= 0;
6109 dpyinfo
->font_table_size
= 0;
6110 dpyinfo
->bitmaps
= 0;
6111 dpyinfo
->bitmaps_size
= 0;
6112 dpyinfo
->bitmaps_last
= 0;
6113 dpyinfo
->scratch_cursor_gc
= 0;
6114 dpyinfo
->mouse_face_mouse_frame
= 0;
6115 dpyinfo
->mouse_face_deferred_gc
= 0;
6116 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6117 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6118 dpyinfo
->mouse_face_face_id
= 0;
6119 dpyinfo
->mouse_face_window
= Qnil
;
6120 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
6121 dpyinfo
->mouse_face_defer
= 0;
6122 dpyinfo
->x_focus_frame
= 0;
6123 dpyinfo
->x_focus_event_frame
= 0;
6124 dpyinfo
->x_highlight_frame
= 0;
6126 dpyinfo
->Xatom_wm_protocols
6127 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
6128 dpyinfo
->Xatom_wm_take_focus
6129 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
6130 dpyinfo
->Xatom_wm_save_yourself
6131 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
6132 dpyinfo
->Xatom_wm_delete_window
6133 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
6134 dpyinfo
->Xatom_wm_change_state
6135 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
6136 dpyinfo
->Xatom_wm_configure_denied
6137 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
6138 dpyinfo
->Xatom_wm_window_moved
6139 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
6140 dpyinfo
->Xatom_editres
6141 = XInternAtom (dpyinfo
->display
, "Editres", False
);
6143 = XInternAtom (dpyinfo
->display
, "FONT", False
);
6144 dpyinfo
->Xatom_CLIPBOARD
6145 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
6146 dpyinfo
->Xatom_TIMESTAMP
6147 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
6149 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
6150 dpyinfo
->Xatom_DELETE
6151 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
6152 dpyinfo
->Xatom_MULTIPLE
6153 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
6155 = XInternAtom (dpyinfo
->display
, "INCR", False
);
6156 dpyinfo
->Xatom_EMACS_TMP
6157 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
6158 dpyinfo
->Xatom_TARGETS
6159 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
6161 = XInternAtom (dpyinfo
->display
, "NULL", False
);
6162 dpyinfo
->Xatom_ATOM_PAIR
6163 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
6165 dpyinfo
->cut_buffers_initialized
= 0;
6167 connection
= ConnectionNumber (dpyinfo
->display
);
6168 dpyinfo
->connection
= connection
;
6171 /* This is only needed for distinguishing keyboard and process input. */
6172 if (connection
!= 0)
6173 add_keyboard_wait_descriptor (connection
);
6176 #ifndef F_SETOWN_BUG
6178 #ifdef F_SETOWN_SOCK_NEG
6179 /* stdin is a socket here */
6180 fcntl (connection
, F_SETOWN
, -getpid ());
6181 #else /* ! defined (F_SETOWN_SOCK_NEG) */
6182 fcntl (connection
, F_SETOWN
, getpid ());
6183 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
6184 #endif /* ! defined (F_SETOWN) */
6185 #endif /* F_SETOWN_BUG */
6188 if (interrupt_input
)
6189 init_sigio (connection
);
6190 #endif /* ! defined (SIGIO) */
6193 /* Make sure that we have a valid font for dialog boxes
6194 so that Xt does not crash. */
6196 Display
*dpy
= dpyinfo
->display
;
6200 d
.addr
= (XPointer
)&dpy
;
6201 d
.size
= sizeof (Display
*);
6202 fr
.addr
= XtDefaultFont
;
6203 fr
.size
= sizeof (XtDefaultFont
);
6204 to
.size
= sizeof (Font
*);
6205 to
.addr
= (XPointer
)&font
;
6206 x_catch_errors (dpy
);
6207 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
6209 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
6210 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
6211 x_uncatch_errors (dpy
);
6221 /* Get rid of display DPYINFO, assuming all frames are already gone,
6222 and without sending any more commands to the X server. */
6225 x_delete_display (dpyinfo
)
6226 struct x_display_info
*dpyinfo
;
6228 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
6230 /* Discard this display from x_display_name_list and x_display_list.
6231 We can't use Fdelq because that can quit. */
6232 if (! NILP (x_display_name_list
)
6233 && EQ (XCONS (x_display_name_list
)->car
, dpyinfo
->name_list_element
))
6234 x_display_name_list
= XCONS (x_display_name_list
)->cdr
;
6239 tail
= x_display_name_list
;
6240 while (CONSP (tail
) && CONSP (XCONS (tail
)->cdr
))
6242 if (EQ (XCONS (XCONS (tail
)->cdr
)->car
,
6243 dpyinfo
->name_list_element
))
6245 XCONS (tail
)->cdr
= XCONS (XCONS (tail
)->cdr
)->cdr
;
6248 tail
= XCONS (tail
)->cdr
;
6252 if (x_display_list
== dpyinfo
)
6253 x_display_list
= dpyinfo
->next
;
6256 struct x_display_info
*tail
;
6258 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
6259 if (tail
->next
== dpyinfo
)
6260 tail
->next
= tail
->next
->next
;
6263 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
6264 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
6265 XrmDestroyDatabase (dpyinfo
->xrdb
);
6269 if (--dpyinfo
->kboard
->reference_count
== 0)
6270 delete_kboard (dpyinfo
->kboard
);
6272 xfree (dpyinfo
->font_table
);
6273 xfree (dpyinfo
->x_id_name
);
6277 /* Set up use of X before we make the first connection. */
6281 clear_frame_hook
= XTclear_frame
;
6282 clear_end_of_line_hook
= XTclear_end_of_line
;
6283 ins_del_lines_hook
= XTins_del_lines
;
6284 change_line_highlight_hook
= XTchange_line_highlight
;
6285 insert_glyphs_hook
= XTinsert_glyphs
;
6286 write_glyphs_hook
= XTwrite_glyphs
;
6287 delete_glyphs_hook
= XTdelete_glyphs
;
6288 ring_bell_hook
= XTring_bell
;
6289 reset_terminal_modes_hook
= XTreset_terminal_modes
;
6290 set_terminal_modes_hook
= XTset_terminal_modes
;
6291 update_begin_hook
= XTupdate_begin
;
6292 update_end_hook
= XTupdate_end
;
6293 set_terminal_window_hook
= XTset_terminal_window
;
6294 read_socket_hook
= XTread_socket
;
6295 frame_up_to_date_hook
= XTframe_up_to_date
;
6296 cursor_to_hook
= XTcursor_to
;
6297 reassert_line_highlight_hook
= XTreassert_line_highlight
;
6298 mouse_position_hook
= XTmouse_position
;
6299 frame_rehighlight_hook
= XTframe_rehighlight
;
6300 frame_raise_lower_hook
= XTframe_raise_lower
;
6301 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
6302 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
6303 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
6304 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
6306 scroll_region_ok
= 1; /* we'll scroll partial frames */
6307 char_ins_del_ok
= 0; /* just as fast to write the line */
6308 line_ins_del_ok
= 1; /* we'll just blt 'em */
6309 fast_clear_end_of_line
= 1; /* X does this well */
6310 memory_below_frame
= 0; /* we don't remember what scrolls
6316 /* Try to use interrupt input; if we can't, then start polling. */
6317 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
6319 #ifdef USE_X_TOOLKIT
6320 XtToolkitInitialize ();
6321 Xt_app_con
= XtCreateApplicationContext ();
6322 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
6325 /* Note that there is no real way portable across R3/R4 to get the
6326 original error handler. */
6327 XSetErrorHandler (x_error_quitter
);
6328 XSetIOErrorHandler (x_io_error_quitter
);
6330 /* Disable Window Change signals; they are handled by X events. */
6332 signal (SIGWINCH
, SIG_DFL
);
6333 #endif /* ! defined (SIGWINCH) */
6335 signal (SIGPIPE
, x_connection_signal
);
6341 staticpro (&x_display_name_list
);
6342 x_display_name_list
= Qnil
;
6344 staticpro (&last_mouse_scroll_bar
);
6345 last_mouse_scroll_bar
= Qnil
;
6347 staticpro (&Qvendor_specific_keysyms
);
6348 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
6350 staticpro (&last_mouse_press_frame
);
6351 last_mouse_press_frame
= Qnil
;
6354 #endif /* not HAVE_X_WINDOWS */