1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 1993, 1994, 1995 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Xt features made by Fred Pierresteguy. */
22 /* On 4.3 these lose if they come after xterm.h. */
23 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
24 /* Putting these at the beginning seems to be standard for other .c files. */
31 /* Need syssignal.h for various externs and definitions that may be required
32 by some configurations for calls to signal later in this source file. */
33 #include "syssignal.h"
38 #include "blockinput.h"
40 /* This may include sys/types.h, and that somehow loses
41 if this is not done before the other system files. */
43 #include <X11/cursorfont.h>
46 /* Load sys/types.h if not already loaded.
47 In some systems loading it twice is suicidal. */
49 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
71 #include "dispextern.h"
72 #include "termhooks.h"
84 #include "intervals.h"
87 extern void free_frame_menubar ();
88 extern void _XEditResCheckMessages ();
89 #endif /* USE_X_TOOLKIT */
92 #define x_any_window_to_frame x_window_to_frame
93 #define x_top_window_to_frame x_window_to_frame
98 #ifndef XtNinitialState
99 #define XtNinitialState "initialState"
103 #define min(a,b) ((a)<(b) ? (a) : (b))
104 #define max(a,b) ((a)>(b) ? (a) : (b))
106 /* This is a chain of structures for all the X displays currently in use. */
107 struct x_display_info
*x_display_list
;
109 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
110 one for each element of x_display_list and in the same order.
111 NAME is the name of the frame.
112 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
113 Lisp_Object x_display_name_list
;
115 /* Frame being updated by update_frame. This is declared in term.c.
116 This is set by update_begin and looked at by all the
117 XT functions. It is zero while not inside an update.
118 In that case, the XT functions assume that `selected_frame'
119 is the frame to apply to. */
120 extern struct frame
*updating_frame
;
122 /* This is a frame waiting to be autoraised, within XTread_socket. */
123 struct frame
*pending_autoraise_frame
;
126 /* The application context for Xt use. */
127 XtAppContext Xt_app_con
;
130 /* During an update, maximum vpos for ins/del line operations to affect. */
132 static int flexlines
;
134 /* During an update, nonzero if chars output now should be highlighted. */
136 static int highlight
;
138 /* Nominal cursor position -- where to draw output.
139 During an update, these are different from the cursor-box position. */
146 In order to avoid asking for motion events and then throwing most
147 of them away or busy-polling the server for mouse positions, we ask
148 the server for pointer motion hints. This means that we get only
149 one event per group of mouse movements. "Groups" are delimited by
150 other kinds of events (focus changes and button clicks, for
151 example), or by XQueryPointer calls; when one of these happens, we
152 get another MotionNotify event the next time the mouse moves. This
153 is at least as efficient as getting motion events when mouse
154 tracking is on, and I suspect only negligibly worse when tracking
157 The silly O'Reilly & Associates Nutshell guides barely document
158 pointer motion hints at all (I think you have to infer how they
159 work from an example), and the description of XQueryPointer doesn't
160 mention that calling it causes you to get another motion hint from
161 the server, which is very important. */
163 /* Where the mouse was last time we reported a mouse event. */
164 static FRAME_PTR last_mouse_frame
;
165 static XRectangle last_mouse_glyph
;
167 /* The scroll bar in which the last X motion event occurred.
169 If the last X motion event occurred in a scroll bar, we set this
170 so XTmouse_position can know whether to report a scroll bar motion or
173 If the last X motion event didn't occur in a scroll bar, we set this
174 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
175 static Lisp_Object last_mouse_scroll_bar
;
177 /* This is a hack. We would really prefer that XTmouse_position would
178 return the time associated with the position it returns, but there
179 doesn't seem to be any way to wrest the timestamp from the server
180 along with the position query. So, we just keep track of the time
181 of the last movement we received, and return that in hopes that
182 it's somewhat accurate. */
183 static Time last_mouse_movement_time
;
185 /* Incremented by XTread_socket whenever it really tries to read events. */
187 static int volatile input_signal_count
;
189 static int input_signal_count
;
192 /* Used locally within XTread_socket. */
193 static int x_noop_count
;
195 /* Initial values of argv and argc. */
196 extern char **initial_argv
;
197 extern int initial_argc
;
199 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
201 /* Tells if a window manager is present or not. */
203 extern Lisp_Object Vx_no_window_manager
;
205 /* Nonzero enables some debugging for the X interface code. */
208 extern Lisp_Object Qface
, Qmouse_face
;
212 /* A mask of extra modifier bits to put into every keyboard char. */
213 extern int extra_keyboard_modifiers
;
215 static Lisp_Object Qvendor_specific_keysyms
;
217 extern XrmDatabase
x_load_resources ();
219 extern Lisp_Object
x_icon_type ();
221 void x_delete_display ();
223 static void redraw_previous_char ();
224 static void redraw_following_char ();
225 static unsigned int x_x_to_emacs_modifiers ();
227 static int fast_find_position ();
228 static void note_mouse_highlight ();
229 static void clear_mouse_face ();
230 static void show_mouse_face ();
231 static void do_line_dance ();
233 static int XTcursor_to ();
234 static int XTclear_end_of_line ();
235 static int x_io_error_quitter ();
236 void x_catch_errors ();
237 void x_uncatch_errors ();
239 /* Return the struct x_display_info corresponding to DPY. */
241 struct x_display_info
*
242 x_display_info_for_display (dpy
)
245 struct x_display_info
*dpyinfo
;
247 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
248 if (dpyinfo
->display
== dpy
)
254 /* Starting and ending updates.
256 These hooks are called by update_frame at the beginning and end
257 of a frame update. We record in `updating_frame' the identity
258 of the frame being updated, so that the XT... functions do not
259 need to take a frame as argument. Most of the XT... functions
260 should never be called except during an update, the only exceptions
261 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
272 flexlines
= f
->height
;
277 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
279 /* Don't do highlighting for mouse motion during the update. */
280 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 1;
282 /* If the frame needs to be redrawn,
283 simply forget about any prior mouse highlighting. */
284 if (FRAME_GARBAGED_P (f
))
285 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= Qnil
;
287 if (!NILP (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
289 int firstline
, lastline
, i
;
290 struct window
*w
= XWINDOW (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
);
292 /* Find the first, and the last+1, lines affected by redisplay. */
293 for (firstline
= 0; firstline
< f
->height
; firstline
++)
294 if (FRAME_DESIRED_GLYPHS (f
)->enable
[firstline
])
297 lastline
= f
->height
;
298 for (i
= f
->height
- 1; i
>= 0; i
--)
300 if (FRAME_DESIRED_GLYPHS (f
)->enable
[i
])
306 /* Can we tell that this update does not affect the window
307 where the mouse highlight is? If so, no need to turn off.
308 Likewise, don't do anything if the frame is garbaged;
309 in that case, the FRAME_CURRENT_GLYPHS that we would use
310 are all wrong, and we will redisplay that line anyway. */
311 if (! (firstline
> (XFASTINT (w
->top
) + window_internal_height (w
))
312 || lastline
< XFASTINT (w
->top
)))
313 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
329 x_display_cursor (f
, 1);
331 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
332 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
334 /* This fails in the case of having updated only the echo area
335 if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS
336 has no relation to the current contents, and its charstarts
337 have no relation to the contents of the window-buffer.
338 I don't know a clean way to check
339 for that case. window_end_valid isn't set up yet. */
340 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
341 note_mouse_highlight (f
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
342 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
345 XFlush (FRAME_X_DISPLAY (f
));
349 /* This is called after a redisplay on frame F. */
352 XTframe_up_to_date (f
)
355 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
356 || f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
358 note_mouse_highlight (FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
,
359 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
360 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
361 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 0;
365 /* External interface to control of standout mode.
366 Call this when about to modify line at position VPOS
367 and not change whether it is highlighted. */
369 XTreassert_line_highlight (new, vpos
)
375 /* Call this when about to modify line at position VPOS
376 and change whether it is highlighted. */
379 XTchange_line_highlight (new_highlight
, vpos
, first_unused_hpos
)
380 int new_highlight
, vpos
, first_unused_hpos
;
382 highlight
= new_highlight
;
383 XTcursor_to (vpos
, 0);
384 XTclear_end_of_line (updating_frame
->width
);
387 /* This is used when starting Emacs and when restarting after suspend.
388 When starting Emacs, no X window is mapped. And nothing must be done
389 to Emacs's own window if it is suspended (though that rarely happens). */
392 XTset_terminal_modes ()
396 /* This is called when exiting or suspending Emacs.
397 Exiting will make the X-windows go away, and suspending
398 requires no action. */
401 XTreset_terminal_modes ()
403 /* XTclear_frame (); */
406 /* Set the nominal cursor position of the frame.
407 This is where display update commands will take effect.
408 This does not affect the place where the cursor-box is displayed. */
411 XTcursor_to (row
, col
)
412 register int row
, col
;
420 if (updating_frame
== 0)
423 x_display_cursor (selected_frame
, 1);
424 XFlush (FRAME_X_DISPLAY (selected_frame
));
429 /* Display a sequence of N glyphs found at GP.
430 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
431 HL is 1 if this text is highlighted, 2 if the cursor is on it,
432 3 if should appear in its mouse-face.
433 JUST_FOREGROUND if 1 means draw only the foreground;
434 don't alter the background.
436 FONT is the default font to use (for glyphs whose font-code is 0).
438 Since the display generation code is responsible for calling
439 compute_char_face and compute_glyph_face on everything it puts in
440 the display structure, we can assume that the face code on each
441 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
442 to which we can actually apply intern_face.
443 Call this function with input blocked. */
446 /* This is the multi-face code. */
449 dumpglyphs (f
, left
, top
, gp
, n
, hl
, just_foreground
)
452 register GLYPH
*gp
; /* Points to first GLYPH. */
453 register int n
; /* Number of glyphs to display. */
457 /* Holds characters to be displayed. */
458 char *buf
= (char *) alloca (f
->width
* sizeof (*buf
));
459 register char *cp
; /* Steps through buf[]. */
460 register int tlen
= GLYPH_TABLE_LENGTH
;
461 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
462 Window window
= FRAME_X_WINDOW (f
);
463 int orig_left
= left
;
467 /* Get the face-code of the next GLYPH. */
471 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
472 cf
= FAST_GLYPH_FACE (g
);
474 /* Find the run of consecutive glyphs with the same face-code.
475 Extract their character codes into BUF. */
480 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
481 if (FAST_GLYPH_FACE (g
) != cf
)
484 *cp
++ = FAST_GLYPH_CHAR (g
);
489 /* LEN gets the length of the run. */
492 /* Now output this run of chars, with the font and pixel values
493 determined by the face code CF. */
495 struct face
*face
= FRAME_DEFAULT_FACE (f
);
496 XFontStruct
*font
= FACE_FONT (face
);
497 GC gc
= FACE_GC (face
);
500 /* HL = 3 means use a mouse face previously chosen. */
502 cf
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
;
504 /* First look at the face of the text itself. */
507 /* It's possible for the display table to specify
508 a face code that is out of range. Use 0 in that case. */
509 if (cf
< 0 || cf
>= FRAME_N_COMPUTED_FACES (f
)
510 || FRAME_COMPUTED_FACES (f
) [cf
] == 0)
514 face
= FRAME_MODE_LINE_FACE (f
);
516 face
= intern_face (f
, FRAME_COMPUTED_FACES (f
) [cf
]);
517 font
= FACE_FONT (face
);
519 if (FACE_STIPPLE (face
))
523 /* Then comes the distinction between modeline and normal text. */
528 face
= FRAME_MODE_LINE_FACE (f
);
529 font
= FACE_FONT (face
);
531 if (FACE_STIPPLE (face
))
535 #define FACE_DEFAULT (~0)
537 /* Now override that if the cursor's on this character. */
540 /* The cursor overrides stippling. */
544 || face
->font
== (XFontStruct
*) FACE_DEFAULT
545 || face
->font
== f
->display
.x
->font
)
546 && face
->background
== f
->display
.x
->background_pixel
547 && face
->foreground
== f
->display
.x
->foreground_pixel
)
549 gc
= f
->display
.x
->cursor_gc
;
551 /* Cursor on non-default face: must merge. */
557 xgcv
.background
= f
->display
.x
->cursor_pixel
;
558 xgcv
.foreground
= face
->background
;
559 /* If the glyph would be invisible,
560 try a different foreground. */
561 if (xgcv
.foreground
== xgcv
.background
)
562 xgcv
.foreground
= face
->foreground
;
563 if (xgcv
.foreground
== xgcv
.background
)
564 xgcv
.foreground
= f
->display
.x
->cursor_foreground_pixel
;
565 if (xgcv
.foreground
== xgcv
.background
)
566 xgcv
.foreground
= face
->foreground
;
567 /* Make sure the cursor is distinct from text in this face. */
568 if (xgcv
.background
== face
->background
569 && xgcv
.foreground
== face
->foreground
)
571 xgcv
.background
= face
->foreground
;
572 xgcv
.foreground
= face
->background
;
574 xgcv
.font
= face
->font
->fid
;
575 xgcv
.graphics_exposures
= 0;
576 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
577 if (FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
)
578 XChangeGC (FRAME_X_DISPLAY (f
),
579 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
,
582 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
583 = XCreateGC (FRAME_X_DISPLAY (f
), window
, mask
, &xgcv
);
584 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
586 /* If this code is restored, it must also reset to the default stipple
588 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
589 XSetStipple (FRAME_X_DISPLAY (f
), gc
, face
->stipple
);
594 if (font
== (XFontStruct
*) FACE_DEFAULT
)
595 font
= f
->display
.x
->font
;
598 XDrawString (FRAME_X_DISPLAY (f
), window
, gc
,
599 left
, top
+ FONT_BASE (font
), buf
, len
);
604 /* Turn stipple on. */
605 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillOpaqueStippled
);
607 /* Draw stipple on background. */
608 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
610 FONT_WIDTH (font
) * len
,
613 /* Turn stipple off. */
614 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillSolid
);
616 /* Draw the text, solidly, onto the stipple pattern. */
617 XDrawString (FRAME_X_DISPLAY (f
), window
, gc
,
618 left
, top
+ FONT_BASE (font
), buf
, len
);
621 XDrawImageString (FRAME_X_DISPLAY (f
), window
, gc
,
622 left
, top
+ FONT_BASE (font
), buf
, len
);
624 /* Clear the rest of the line's height. */
625 if (f
->display
.x
->line_height
!= FONT_HEIGHT (font
))
626 XClearArea (FRAME_X_DISPLAY (f
), window
, left
,
627 top
+ FONT_HEIGHT (font
),
628 FONT_WIDTH (font
) * len
,
629 /* This is how many pixels of height
631 f
->display
.x
->line_height
- FONT_HEIGHT (font
),
635 #if 0 /* Doesn't work, because it uses FRAME_CURRENT_GLYPHS,
636 which often is not up to date yet. */
637 if (!just_foreground
)
639 if (left
== orig_left
)
640 redraw_previous_char (f
, PIXEL_TO_CHAR_COL (f
, left
),
641 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
643 redraw_following_char (f
, PIXEL_TO_CHAR_COL (f
, left
+ len
* FONT_WIDTH (font
)),
644 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
648 /* We should probably check for XA_UNDERLINE_POSITION and
649 XA_UNDERLINE_THICKNESS properties on the font, but let's
650 just get the thing working, and come back to that. */
652 int underline_position
= 1;
654 if (font
->descent
<= underline_position
)
655 underline_position
= font
->descent
- 1;
658 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
662 + underline_position
),
663 len
* FONT_WIDTH (font
), 1);
666 left
+= len
* FONT_WIDTH (font
);
673 /* This is the old single-face code. */
676 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
679 register GLYPH
*gp
; /* Points to first GLYPH. */
680 register int n
; /* Number of glyphs to display. */
685 Window window
= FRAME_X_WINDOW (f
);
686 GC drawing_gc
= (hl
== 2 ? f
->display
.x
->cursor_gc
687 : (hl
? f
->display
.x
->reverse_gc
688 : f
->display
.x
->normal_gc
));
690 if (sizeof (GLYPH
) == sizeof (XChar2b
))
691 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
692 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
693 else if (sizeof (GLYPH
) == sizeof (unsigned char))
694 XDrawImageString (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
695 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
697 /* What size of glyph ARE you using? And does X have a function to
703 /* Output some text at the nominal frame cursor position.
704 Advance the cursor over the text.
705 Output LEN glyphs at START.
707 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
708 controls the pixel values used for foreground and background. */
711 XTwrite_glyphs (start
, len
)
712 register GLYPH
*start
;
715 register int temp_length
;
726 /* If not within an update,
727 output at the frame's visible cursor. */
728 curs_x
= f
->cursor_x
;
729 curs_y
= f
->cursor_y
;
733 CHAR_TO_PIXEL_COL (f
, curs_x
),
734 CHAR_TO_PIXEL_ROW (f
, curs_y
),
735 start
, len
, highlight
, 0);
737 /* If we drew on top of the cursor, note that it is turned off. */
738 if (curs_y
== f
->phys_cursor_y
739 && curs_x
<= f
->phys_cursor_x
740 && curs_x
+ len
> f
->phys_cursor_x
)
741 f
->phys_cursor_x
= -1;
743 if (updating_frame
== 0)
746 x_display_cursor (f
, 1);
755 /* Clear to the end of the line.
756 Erase the current text line from the nominal cursor position (inclusive)
757 to column FIRST_UNUSED (exclusive). The idea is that everything
758 from FIRST_UNUSED onward is already erased. */
761 XTclear_end_of_line (first_unused
)
762 register int first_unused
;
764 struct frame
*f
= updating_frame
;
770 if (curs_y
< 0 || curs_y
>= f
->height
)
772 if (first_unused
<= 0)
775 if (first_unused
>= f
->width
)
776 first_unused
= f
->width
;
782 /* Notice if the cursor will be cleared by this operation. */
783 if (curs_y
== f
->phys_cursor_y
784 && curs_x
<= f
->phys_cursor_x
785 && f
->phys_cursor_x
< first_unused
)
786 f
->phys_cursor_x
= -1;
788 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
789 CHAR_TO_PIXEL_COL (f
, curs_x
),
790 CHAR_TO_PIXEL_ROW (f
, curs_y
),
791 FONT_WIDTH (f
->display
.x
->font
) * (first_unused
- curs_x
),
792 f
->display
.x
->line_height
, False
);
794 redraw_previous_char (f
, curs_x
, curs_y
, highlight
);
804 struct frame
*f
= updating_frame
;
809 f
->phys_cursor_x
= -1; /* Cursor not visible. */
810 curs_x
= 0; /* Nominal cursor position is top left. */
815 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
817 /* We have to clear the scroll bars, too. If we have changed
818 colors or something like that, then they should be notified. */
819 x_scroll_bar_clear (f
);
821 XFlush (FRAME_X_DISPLAY (f
));
826 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
827 always contain the right glyphs to use.
829 It also needs to be changed to look at the details of the font and
830 see whether there is really overlap, and do nothing when there is
831 not. This can use font_char_overlap_left and font_char_overlap_right,
832 but just how to use them is not clear. */
834 /* Erase the character (if any) at the position just before X, Y in frame F,
835 then redraw it and the character before it.
836 This is necessary when we erase starting at X,
837 in case the character after X overlaps into the one before X.
838 Call this function with input blocked. */
841 redraw_previous_char (f
, x
, y
, highlight_flag
)
846 /* Erase the character before the new ones, in case
847 what was here before overlaps it.
848 Reoutput that character, and the previous character
849 (in case the previous character overlaps it). */
855 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
856 CHAR_TO_PIXEL_COL (f
, x
- 1),
857 CHAR_TO_PIXEL_ROW (f
, y
),
858 FONT_WIDTH (f
->display
.x
->font
),
859 f
->display
.x
->line_height
, False
);
861 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
862 CHAR_TO_PIXEL_ROW (f
, y
),
863 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
864 x
- start_x
, highlight_flag
, 1);
868 /* Erase the character (if any) at the position X, Y in frame F,
869 then redraw it and the character after it.
870 This is necessary when we erase endng at X,
871 in case the character after X overlaps into the one before X.
872 Call this function with input blocked. */
875 redraw_following_char (f
, x
, y
, highlight_flag
)
880 int limit
= FRAME_CURRENT_GLYPHS (f
)->used
[y
];
881 /* Erase the character after the new ones, in case
882 what was here before overlaps it.
883 Reoutput that character, and the following character
884 (in case the following character overlaps it). */
886 && FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
] != SPACEGLYPH
)
891 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
892 CHAR_TO_PIXEL_COL (f
, x
),
893 CHAR_TO_PIXEL_ROW (f
, y
),
894 FONT_WIDTH (f
->display
.x
->font
),
895 f
->display
.x
->line_height
, False
);
897 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, x
),
898 CHAR_TO_PIXEL_ROW (f
, y
),
899 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
],
900 end_x
- x
, highlight_flag
, 1);
905 #if 0 /* Not in use yet */
907 /* Return 1 if character C in font F extends past its left edge. */
910 font_char_overlap_left (font
, c
)
916 /* Find the bounding-box info for C. */
917 if (font
->per_char
== 0)
918 s
= &font
->max_bounds
;
921 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
924 /* Decode char into row number (byte 1) and code within row (byte 2). */
927 if (!(within
>= font
->min_char_or_byte2
928 && within
<= font
->max_char_or_byte2
929 && row
>= font
->min_byte1
930 && row
<= font
->max_byte1
))
932 /* If char is out of range, try the font's default char instead. */
933 c
= font
->default_char
;
934 row
= c
>> (INTBITS
- 8);
937 if (!(within
>= font
->min_char_or_byte2
938 && within
<= font
->max_char_or_byte2
939 && row
>= font
->min_byte1
940 && row
<= font
->max_byte1
))
941 /* Still out of range means this char does not overlap. */
944 /* We found the info for this char. */
945 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
949 return (s
&& s
->lbearing
< 0);
952 /* Return 1 if character C in font F extends past its right edge. */
955 font_char_overlap_right (font
, c
)
961 /* Find the bounding-box info for C. */
962 if (font
->per_char
== 0)
963 s
= &font
->max_bounds
;
966 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
969 /* Decode char into row number (byte 1) and code within row (byte 2). */
972 if (!(within
>= font
->min_char_or_byte2
973 && within
<= font
->max_char_or_byte2
974 && row
>= font
->min_byte1
975 && row
<= font
->max_byte1
))
977 /* If char is out of range, try the font's default char instead. */
978 c
= font
->default_char
;
979 row
= c
>> (INTBITS
- 8);
982 if (!(within
>= font
->min_char_or_byte2
983 && within
<= font
->max_char_or_byte2
984 && row
>= font
->min_byte1
985 && row
<= font
->max_byte1
))
986 /* Still out of range means this char does not overlap. */
989 /* We found the info for this char. */
990 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
994 return (s
&& s
->rbearing
>= s
->width
);
998 /* Invert the middle quarter of the frame for .15 sec. */
1000 /* We use the select system call to do the waiting, so we have to make sure
1001 it's available. If it isn't, we just won't do visual bells. */
1002 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1004 /* Subtract the `struct timeval' values X and Y,
1005 storing the result in RESULT.
1006 Return 1 if the difference is negative, otherwise 0. */
1009 timeval_subtract (result
, x
, y
)
1010 struct timeval
*result
, x
, y
;
1012 /* Perform the carry for the later subtraction by updating y.
1013 This is safer because on some systems
1014 the tv_sec member is unsigned. */
1015 if (x
.tv_usec
< y
.tv_usec
)
1017 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
1018 y
.tv_usec
-= 1000000 * nsec
;
1021 if (x
.tv_usec
- y
.tv_usec
> 1000000)
1023 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
1024 y
.tv_usec
+= 1000000 * nsec
;
1028 /* Compute the time remaining to wait. tv_usec is certainly positive. */
1029 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
1030 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
1032 /* Return indication of whether the result should be considered negative. */
1033 return x
.tv_sec
< y
.tv_sec
;
1044 /* Create a GC that will use the GXxor function to flip foreground pixels
1045 into background pixels. */
1049 values
.function
= GXxor
;
1050 values
.foreground
= (f
->display
.x
->foreground_pixel
1051 ^ f
->display
.x
->background_pixel
);
1053 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1054 GCFunction
| GCForeground
, &values
);
1058 int width
= PIXEL_WIDTH (f
);
1059 int height
= PIXEL_HEIGHT (f
);
1061 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1062 width
/4, height
/4, width
/2, height
/2);
1063 XFlush (FRAME_X_DISPLAY (f
));
1066 struct timeval wakeup
, now
;
1068 EMACS_GET_TIME (wakeup
);
1070 /* Compute time to wait until, propagating carry from usecs. */
1071 wakeup
.tv_usec
+= 150000;
1072 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
1073 wakeup
.tv_usec
%= 1000000;
1075 /* Keep waiting until past the time wakeup. */
1078 struct timeval timeout
;
1080 EMACS_GET_TIME (timeout
);
1082 /* In effect, timeout = wakeup - timeout.
1083 Break if result would be negative. */
1084 if (timeval_subtract (&timeout
, wakeup
, timeout
))
1087 /* Try to wait that long--but we might wake up sooner. */
1088 select (0, NULL
, NULL
, NULL
, &timeout
);
1092 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1093 width
/4, height
/4, width
/2, height
/2);
1094 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
1095 XFlush (FRAME_X_DISPLAY (f
));
1105 /* Make audible bell. */
1107 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
1111 if (FRAME_X_DISPLAY (selected_frame
) == 0)
1114 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1116 XTflash (selected_frame
);
1122 XFlush (FRAME_X_DISPLAY (selected_frame
));
1127 /* Insert and delete character.
1128 These are not supposed to be used because we are supposed to turn
1129 off the feature of using them. */
1132 XTinsert_glyphs (start
, len
)
1133 register char *start
;
1146 /* Specify how many text lines, from the top of the window,
1147 should be affected by insert-lines and delete-lines operations.
1148 This, and those operations, are used only within an update
1149 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1152 XTset_terminal_window (n
)
1155 if (updating_frame
== 0)
1158 if ((n
<= 0) || (n
> updating_frame
->height
))
1159 flexlines
= updating_frame
->height
;
1164 /* These variables need not be per frame
1165 because redisplay is done on a frame-by-frame basis
1166 and the line dance for one frame is finished before
1167 anything is done for anoter frame. */
1169 /* Array of line numbers from cached insert/delete operations.
1170 line_dance[i] is the old position of the line that we want
1171 to move to line i, or -1 if we want a blank line there. */
1172 static int *line_dance
;
1174 /* Allocated length of that array. */
1175 static int line_dance_len
;
1177 /* Flag indicating whether we've done any work. */
1178 static int line_dance_in_progress
;
1180 /* Perform an insert-lines or delete-lines operation,
1181 inserting N lines or deleting -N lines at vertical position VPOS. */
1182 XTins_del_lines (vpos
, n
)
1185 register int fence
, i
;
1187 if (vpos
>= flexlines
)
1190 if (!line_dance_in_progress
)
1192 int ht
= updating_frame
->height
;
1193 if (ht
> line_dance_len
)
1195 line_dance
= (int *)xrealloc (line_dance
, ht
* sizeof (int));
1196 line_dance_len
= ht
;
1198 for (i
= 0; i
< ht
; ++i
) line_dance
[i
] = i
;
1199 line_dance_in_progress
= 1;
1203 if (n
> flexlines
- vpos
)
1204 n
= flexlines
- vpos
;
1206 for (i
= flexlines
; --i
>= fence
;)
1207 line_dance
[i
] = line_dance
[i
-n
];
1208 for (i
= fence
; --i
>= vpos
;)
1214 if (n
> flexlines
- vpos
)
1215 n
= flexlines
- vpos
;
1216 fence
= flexlines
- n
;
1217 for (i
= vpos
; i
< fence
; ++i
)
1218 line_dance
[i
] = line_dance
[i
+ n
];
1219 for (i
= fence
; i
< flexlines
; ++i
)
1224 /* Here's where we actually move the pixels around.
1225 Must be called with input blocked. */
1229 register int i
, j
, distance
;
1230 register struct frame
*f
;
1234 /* Must check this flag first. If it's not set, then not only is the
1235 array uninitialized, but we might not even have a frame. */
1236 if (!line_dance_in_progress
)
1244 intborder
= f
->display
.x
->internal_border_width
;
1246 x_display_cursor (updating_frame
, 0);
1248 for (i
= 0; i
< ht
; ++i
)
1249 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) > 0)
1251 for (j
= i
; (j
< ht
&& line_dance
[j
] != -1
1252 && line_dance
[j
]-j
== distance
); ++j
);
1253 /* Copy [i,j) upward from [i+distance,j+distance) */
1254 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1255 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1256 intborder
, CHAR_TO_PIXEL_ROW (f
, i
+distance
),
1257 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1258 (j
-i
) * f
->display
.x
->line_height
,
1259 intborder
, CHAR_TO_PIXEL_ROW (f
, i
));
1263 for (i
= ht
; --i
>=0; )
1264 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) < 0)
1266 for (j
= i
; (--j
>= 0 && line_dance
[j
] != -1
1267 && line_dance
[j
]-j
== distance
););
1268 /* Copy (j,i] downward from (j+distance, i+distance] */
1269 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1270 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1271 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1+distance
),
1272 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1273 (i
-j
) * f
->display
.x
->line_height
,
1274 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1));
1278 for (i
= 0; i
< ht
; ++i
)
1279 if (line_dance
[i
] == -1)
1281 for (j
= i
; j
< ht
&& line_dance
[j
] == -1; ++j
);
1283 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1284 intborder
, CHAR_TO_PIXEL_ROW (f
, i
),
1285 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1286 (j
-i
) * f
->display
.x
->line_height
, False
);
1289 line_dance_in_progress
= 0;
1292 /* Support routines for exposure events. */
1293 static void clear_cursor ();
1295 /* Output into a rectangle of an X-window (for frame F)
1296 the characters in f->phys_lines that overlap that rectangle.
1297 TOP and LEFT are the position of the upper left corner of the rectangle.
1298 ROWS and COLS are the size of the rectangle.
1299 Call this function with input blocked. */
1302 dumprectangle (f
, left
, top
, cols
, rows
)
1304 register int left
, top
, cols
, rows
;
1306 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1307 int cursor_cleared
= 0;
1311 if (FRAME_GARBAGED_P (f
))
1314 /* Express rectangle as four edges, instead of position-and-size. */
1315 bottom
= top
+ rows
;
1316 right
= left
+ cols
;
1318 /* Convert rectangle edges in pixels to edges in chars.
1319 Round down for left and top, up for right and bottom. */
1320 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1321 left
= PIXEL_TO_CHAR_COL (f
, left
);
1322 bottom
+= (f
->display
.x
->line_height
- 1);
1323 right
+= (FONT_WIDTH (f
->display
.x
->font
) - 1);
1324 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1325 right
= PIXEL_TO_CHAR_COL (f
, right
);
1327 /* Clip the rectangle to what can be visible. */
1332 if (right
> f
->width
)
1334 if (bottom
> f
->height
)
1337 /* Get size in chars of the rectangle. */
1338 cols
= right
- left
;
1339 rows
= bottom
- top
;
1341 /* If rectangle has zero area, return. */
1342 if (rows
<= 0) return;
1343 if (cols
<= 0) return;
1345 /* Turn off the cursor if it is in the rectangle.
1346 We will turn it back on afterward. */
1347 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1348 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1354 /* Display the text in the rectangle, one text line at a time. */
1356 for (y
= top
; y
< bottom
; y
++)
1358 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1360 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1364 CHAR_TO_PIXEL_COL (f
, left
),
1365 CHAR_TO_PIXEL_ROW (f
, y
),
1366 line
, min (cols
, active_frame
->used
[y
] - left
),
1367 active_frame
->highlight
[y
], 0);
1370 /* Turn the cursor on if we turned it off. */
1373 x_display_cursor (f
, 1);
1380 /* We used to only do this if Vx_no_window_manager was non-nil, but
1381 the ICCCM (section 4.1.6) says that the window's border pixmap
1382 and border pixel are window attributes which are "private to the
1383 client", so we can always change it to whatever we want. */
1385 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1386 f
->display
.x
->border_pixel
);
1388 x_display_cursor (f
, 1);
1392 frame_unhighlight (f
)
1395 /* We used to only do this if Vx_no_window_manager was non-nil, but
1396 the ICCCM (section 4.1.6) says that the window's border pixmap
1397 and border pixel are window attributes which are "private to the
1398 client", so we can always change it to whatever we want. */
1400 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1401 f
->display
.x
->border_tile
);
1403 x_display_cursor (f
, 1);
1406 static void XTframe_rehighlight ();
1407 static void x_frame_rehighlight ();
1409 /* The focus has changed. Update the frames as necessary to reflect
1410 the new situation. Note that we can't change the selected frame
1411 here, because the Lisp code we are interrupting might become confused.
1412 Each event gets marked with the frame in which it occurred, so the
1413 Lisp code can tell when the switch took place by examining the events. */
1416 x_new_focus_frame (dpyinfo
, frame
)
1417 struct x_display_info
*dpyinfo
;
1418 struct frame
*frame
;
1420 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
1421 int events_enqueued
= 0;
1423 if (frame
!= dpyinfo
->x_focus_frame
)
1425 /* Set this before calling other routines, so that they see
1426 the correct value of x_focus_frame. */
1427 dpyinfo
->x_focus_frame
= frame
;
1429 if (old_focus
&& old_focus
->auto_lower
)
1430 x_lower_frame (old_focus
);
1433 selected_frame
= frame
;
1434 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
1436 Fselect_window (selected_frame
->selected_window
);
1437 choose_minibuf_frame ();
1440 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
1441 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
1443 pending_autoraise_frame
= 0;
1446 x_frame_rehighlight (dpyinfo
);
1449 /* Handle an event saying the mouse has moved out of an Emacs frame. */
1452 x_mouse_leave (dpyinfo
)
1453 struct x_display_info
*dpyinfo
;
1455 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
1458 /* The focus has changed, or we have redirected a frame's focus to
1459 another frame (this happens when a frame uses a surrogate
1460 minibuffer frame). Shift the highlight as appropriate.
1462 The FRAME argument doesn't necessarily have anything to do with which
1463 frame is being highlighted or unhighlighted; we only use it to find
1464 the appropriate X display info. */
1466 XTframe_rehighlight (frame
)
1467 struct frame
*frame
;
1469 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
1473 x_frame_rehighlight (dpyinfo
)
1474 struct x_display_info
*dpyinfo
;
1476 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1478 if (dpyinfo
->x_focus_frame
)
1480 dpyinfo
->x_highlight_frame
1481 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
1482 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
1483 : dpyinfo
->x_focus_frame
);
1484 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
1486 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
1487 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1491 dpyinfo
->x_highlight_frame
= 0;
1493 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
1496 frame_unhighlight (old_highlight
);
1497 if (dpyinfo
->x_highlight_frame
)
1498 frame_highlight (dpyinfo
->x_highlight_frame
);
1502 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1504 /* Initialize mode_switch_bit and modifier_meaning. */
1506 x_find_modifier_meanings (dpyinfo
)
1507 struct x_display_info
*dpyinfo
;
1509 int min_code
, max_code
;
1512 XModifierKeymap
*mods
;
1514 dpyinfo
->meta_mod_mask
= 0;
1515 dpyinfo
->shift_lock_mask
= 0;
1516 dpyinfo
->alt_mod_mask
= 0;
1517 dpyinfo
->super_mod_mask
= 0;
1518 dpyinfo
->hyper_mod_mask
= 0;
1521 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
1523 min_code
= display
->min_keycode
;
1524 max_code
= display
->max_keycode
;
1527 syms
= XGetKeyboardMapping (dpyinfo
->display
,
1528 min_code
, max_code
- min_code
+ 1,
1530 mods
= XGetModifierMapping (dpyinfo
->display
);
1532 /* Scan the modifier table to see which modifier bits the Meta and
1533 Alt keysyms are on. */
1535 int row
, col
; /* The row and column in the modifier table. */
1537 for (row
= 3; row
< 8; row
++)
1538 for (col
= 0; col
< mods
->max_keypermod
; col
++)
1541 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
1543 /* Zeroes are used for filler. Skip them. */
1547 /* Are any of this keycode's keysyms a meta key? */
1551 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
1553 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
1559 dpyinfo
->meta_mod_mask
|= (1 << row
);
1564 dpyinfo
->alt_mod_mask
|= (1 << row
);
1569 dpyinfo
->hyper_mod_mask
|= (1 << row
);
1574 dpyinfo
->super_mod_mask
|= (1 << row
);
1578 /* Ignore this if it's not on the lock modifier. */
1579 if ((1 << row
) == LockMask
)
1580 dpyinfo
->shift_lock_mask
= LockMask
;
1588 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
1589 if (! dpyinfo
->meta_mod_mask
)
1591 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
1592 dpyinfo
->alt_mod_mask
= 0;
1595 /* If some keys are both alt and meta,
1596 make them just meta, not alt. */
1597 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
1599 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
1602 XFree ((char *) syms
);
1603 XFreeModifiermap (mods
);
1606 /* Convert between the modifier bits X uses and the modifier bits
1609 x_x_to_emacs_modifiers (dpyinfo
, state
)
1610 struct x_display_info
*dpyinfo
;
1613 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
1614 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
1615 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
1616 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
1617 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
1618 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
1622 x_emacs_to_x_modifiers (dpyinfo
, state
)
1623 struct x_display_info
*dpyinfo
;
1626 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
1627 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
1628 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
1629 | ((state
& shift_modifier
) ? ShiftMask
: 0)
1630 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
1631 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
1634 /* Convert a keysym to its name. */
1637 x_get_keysym_name (keysym
)
1643 value
= XKeysymToString (keysym
);
1649 /* Mouse clicks and mouse movement. Rah. */
1651 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
1652 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
1653 that the glyph at X, Y occupies, if BOUNDS != 0.
1654 If NOCLIP is nonzero, do not force the value into range. */
1657 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1659 register int pix_x
, pix_y
;
1660 register int *x
, *y
;
1664 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1665 even for negative values. */
1667 pix_x
-= FONT_WIDTH ((f
)->display
.x
->font
) - 1;
1669 pix_y
-= (f
)->display
.x
->line_height
- 1;
1671 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
1672 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
1676 bounds
->width
= FONT_WIDTH (f
->display
.x
->font
);
1677 bounds
->height
= f
->display
.x
->line_height
;
1678 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
1679 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
1686 else if (pix_x
> f
->width
)
1691 else if (pix_y
> f
->height
)
1700 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
1703 register int *pix_x
, *pix_y
;
1705 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
1706 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
1709 /* Prepare a mouse-event in *RESULT for placement in the input queue.
1711 If the event is a button press, then note that we have grabbed
1715 construct_mouse_click (result
, event
, f
)
1716 struct input_event
*result
;
1717 XButtonEvent
*event
;
1720 /* Make the event type no_event; we'll change that when we decide
1722 result
->kind
= mouse_click
;
1723 result
->code
= event
->button
- Button1
;
1724 result
->timestamp
= event
->time
;
1725 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
1727 | (event
->type
== ButtonRelease
1735 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
1736 XSETFASTINT (result
->x
, column
);
1737 XSETFASTINT (result
->y
, row
);
1739 XSETINT (result
->x
, event
->x
);
1740 XSETINT (result
->y
, event
->y
);
1741 XSETFRAME (result
->frame_or_window
, f
);
1745 /* Prepare a menu-event in *RESULT for placement in the input queue. */
1748 construct_menu_click (result
, event
, f
)
1749 struct input_event
*result
;
1750 XButtonEvent
*event
;
1753 /* Make the event type no_event; we'll change that when we decide
1755 result
->kind
= mouse_click
;
1756 XSETINT (result
->code
, event
->button
- Button1
);
1757 result
->timestamp
= event
->time
;
1758 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
1760 | (event
->type
== ButtonRelease
1764 XSETINT (result
->x
, event
->x
);
1765 XSETINT (result
->y
, -1);
1766 XSETFRAME (result
->frame_or_window
, f
);
1769 /* Function to report a mouse movement to the mainstream Emacs code.
1770 The input handler calls this.
1772 We have received a mouse movement event, which is given in *event.
1773 If the mouse is over a different glyph than it was last time, tell
1774 the mainstream emacs code by setting mouse_moved. If not, ask for
1775 another motion event, so we can check again the next time it moves. */
1778 note_mouse_movement (frame
, event
)
1780 XMotionEvent
*event
;
1782 last_mouse_movement_time
= event
->time
;
1784 if (event
->window
!= FRAME_X_WINDOW (frame
))
1787 last_mouse_scroll_bar
= Qnil
;
1789 note_mouse_highlight (frame
, -1, -1);
1791 /* Ask for another mouse motion event. */
1794 Window dummy_window
;
1796 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1797 &dummy_window
, &dummy_window
,
1798 &dummy
, &dummy
, &dummy
, &dummy
,
1799 (unsigned int *) &dummy
);
1803 /* Has the mouse moved off the glyph it was on at the last sighting? */
1804 else if (event
->x
< last_mouse_glyph
.x
1805 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
1806 || event
->y
< last_mouse_glyph
.y
1807 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
1810 last_mouse_scroll_bar
= Qnil
;
1812 note_mouse_highlight (frame
, event
->x
, event
->y
);
1814 /* Ask for another mouse motion event. */
1817 Window dummy_window
;
1819 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1820 &dummy_window
, &dummy_window
,
1821 &dummy
, &dummy
, &dummy
, &dummy
,
1822 (unsigned int *) &dummy
);
1827 /* It's on the same glyph. Call XQueryPointer so we'll get an
1828 event the next time the mouse moves and we can see if it's
1829 *still* on the same glyph. */
1831 Window dummy_window
;
1833 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1834 &dummy_window
, &dummy_window
,
1835 &dummy
, &dummy
, &dummy
, &dummy
,
1836 (unsigned int *) &dummy
);
1840 /* This is used for debugging, to turn off note_mouse_highlight. */
1841 static int disable_mouse_highlight
;
1843 /* Take proper action when the mouse has moved to position X, Y on frame F
1844 as regards highlighting characters that have mouse-face properties.
1845 Also dehighlighting chars where the mouse was before.
1846 X and Y can be negative or out of range. */
1849 note_mouse_highlight (f
, x
, y
)
1853 int row
, column
, portion
;
1854 XRectangle new_glyph
;
1858 if (disable_mouse_highlight
)
1861 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
= x
;
1862 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
= y
;
1863 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
= f
;
1865 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
)
1870 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 1;
1874 /* Find out which glyph the mouse is on. */
1875 pixel_to_glyph_coords (f
, x
, y
, &column
, &row
,
1876 &new_glyph
, FRAME_X_DISPLAY_INFO (f
)->grabbed
);
1878 /* Which window is that in? */
1879 window
= window_from_coordinates (f
, column
, row
, &portion
);
1880 w
= XWINDOW (window
);
1882 /* If we were displaying active text in another window, clear that. */
1883 if (! EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
1884 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
1886 /* Are we in a window whose display is up to date?
1887 And verify the buffer's text has not changed. */
1888 if (WINDOWP (window
) && portion
== 0 && row
>= 0 && column
>= 0
1889 && row
< FRAME_HEIGHT (f
) && column
< FRAME_WIDTH (f
)
1890 && EQ (w
->window_end_valid
, w
->buffer
)
1891 && w
->last_modified
== BUF_MODIFF (XBUFFER (w
->buffer
)))
1893 int *ptr
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[row
];
1896 /* Find which buffer position the mouse corresponds to. */
1897 for (i
= column
; i
>= 0; i
--)
1901 /* Is it outside the displayed active region (if any)? */
1903 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
1904 else if (! (EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
)
1905 && row
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
1906 && row
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
1907 && (row
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
1908 || column
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
)
1909 && (row
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
1910 || column
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
1911 || FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
)))
1913 Lisp_Object mouse_face
, overlay
, position
;
1914 Lisp_Object
*overlay_vec
;
1915 int len
, noverlays
, ignor1
;
1916 struct buffer
*obuf
;
1919 /* If we get an out-of-range value, return now; avoid an error. */
1920 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
1923 /* Make the window's buffer temporarily current for
1924 overlays_at and compute_char_face. */
1925 obuf
= current_buffer
;
1926 current_buffer
= XBUFFER (w
->buffer
);
1932 /* Yes. Clear the display of the old active region, if any. */
1933 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
1935 /* Is this char mouse-active? */
1936 XSETINT (position
, pos
);
1939 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
1941 /* Put all the overlays we want in a vector in overlay_vec.
1942 Store the length in len. */
1943 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
1945 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
1947 /* Find the highest priority overlay that has a mouse-face prop. */
1949 for (i
= 0; i
< noverlays
; i
++)
1951 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
1952 if (!NILP (mouse_face
))
1954 overlay
= overlay_vec
[i
];
1959 /* If no overlay applies, get a text property. */
1961 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
1963 /* Handle the overlay case. */
1964 if (! NILP (overlay
))
1966 /* Find the range of text around this char that
1967 should be active. */
1968 Lisp_Object before
, after
;
1971 before
= Foverlay_start (overlay
);
1972 after
= Foverlay_end (overlay
);
1973 /* Record this as the current active region. */
1974 fast_find_position (window
, before
,
1975 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
1976 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
1977 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
1978 = !fast_find_position (window
, after
,
1979 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
1980 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
1981 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
1982 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
1983 = compute_char_face (f
, w
, pos
, 0, 0,
1984 &ignore
, pos
+ 1, 1);
1986 /* Display it as active. */
1987 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
1989 /* Handle the text property case. */
1990 else if (! NILP (mouse_face
))
1992 /* Find the range of text around this char that
1993 should be active. */
1994 Lisp_Object before
, after
, beginning
, end
;
1997 beginning
= Fmarker_position (w
->start
);
1998 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
1999 - XFASTINT (w
->window_end_pos
)));
2001 = Fprevious_single_property_change (make_number (pos
+ 1),
2003 w
->buffer
, beginning
);
2005 = Fnext_single_property_change (position
, Qmouse_face
,
2007 /* Record this as the current active region. */
2008 fast_find_position (window
, before
,
2009 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2010 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2011 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2012 = !fast_find_position (window
, after
,
2013 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2014 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2015 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2016 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2017 = compute_char_face (f
, w
, pos
, 0, 0,
2018 &ignore
, pos
+ 1, 1);
2020 /* Display it as active. */
2021 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2025 current_buffer
= obuf
;
2030 /* Find the row and column of position POS in window WINDOW.
2031 Store them in *COLUMNP and *ROWP.
2032 This assumes display in WINDOW is up to date.
2033 If POS is above start of WINDOW, return coords
2034 of start of first screen line.
2035 If POS is after end of WINDOW, return coords of end of last screen line.
2037 Value is 1 if POS is in range, 0 if it was off screen. */
2040 fast_find_position (window
, pos
, columnp
, rowp
)
2043 int *columnp
, *rowp
;
2045 struct window
*w
= XWINDOW (window
);
2046 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2051 int height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
2052 int width
= window_internal_width (w
);
2055 int maybe_next_line
= 0;
2057 /* Find the right row. */
2062 int linestart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ i
][left
];
2063 if (linestart
> pos
)
2065 /* If the position sought is the end of the buffer,
2066 don't include the blank lines at the bottom of the window. */
2067 if (linestart
== pos
&& pos
== BUF_ZV (XBUFFER (w
->buffer
)))
2069 maybe_next_line
= 1;
2076 /* Find the right column with in it. */
2077 charstarts
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ row
];
2079 for (i
= 0; i
< width
; i
++)
2081 if (charstarts
[left
+ i
] == pos
)
2084 *columnp
= i
+ left
;
2087 else if (charstarts
[left
+ i
] > pos
)
2089 else if (charstarts
[left
+ i
] > 0)
2093 /* If we're looking for the end of the buffer,
2094 and we didn't find it in the line we scanned,
2095 use the start of the following line. */
2096 if (maybe_next_line
)
2107 /* Display the active region described by mouse_face_*
2108 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2111 show_mouse_face (dpyinfo
, hl
)
2112 struct x_display_info
*dpyinfo
;
2115 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
2116 int width
= window_internal_width (w
);
2117 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2120 int old_curs_x
= curs_x
;
2121 int old_curs_y
= curs_y
;
2123 /* Set these variables temporarily
2124 so that if we have to turn the cursor off and on again
2125 we will put it back at the same place. */
2126 curs_x
= f
->phys_cursor_x
;
2127 curs_y
= f
->phys_cursor_y
;
2129 for (i
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
;
2130 i
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
; i
++)
2132 int column
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2133 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
2135 int endcolumn
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2136 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2138 endcolumn
= min (endcolumn
, FRAME_CURRENT_GLYPHS (f
)->used
[i
]);
2140 /* If the cursor's in the text we are about to rewrite,
2141 turn the cursor off. */
2143 && curs_x
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
- 1
2144 && curs_x
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
)
2146 x_display_cursor (f
, 0);
2151 CHAR_TO_PIXEL_COL (f
, column
),
2152 CHAR_TO_PIXEL_ROW (f
, i
),
2153 FRAME_CURRENT_GLYPHS (f
)->glyphs
[i
] + column
,
2155 /* Highlight with mouse face if hl > 0. */
2159 /* If we turned the cursor off, turn it back on. */
2161 x_display_cursor (f
, 1);
2163 curs_x
= old_curs_x
;
2164 curs_y
= old_curs_y
;
2166 /* Change the mouse cursor according to the value of HL. */
2168 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2169 f
->display
.x
->cross_cursor
);
2171 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2172 f
->display
.x
->text_cursor
);
2175 /* Clear out the mouse-highlighted active region.
2176 Redraw it unhighlighted first. */
2179 clear_mouse_face (dpyinfo
)
2180 struct x_display_info
*dpyinfo
;
2182 if (! NILP (dpyinfo
->mouse_face_window
))
2183 show_mouse_face (dpyinfo
, 0);
2185 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2186 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2187 dpyinfo
->mouse_face_window
= Qnil
;
2190 static struct scroll_bar
*x_window_to_scroll_bar ();
2191 static void x_scroll_bar_report_motion ();
2193 /* Return the current position of the mouse.
2194 *fp should be a frame which indicates which display to ask about.
2196 If the mouse movement started in a scroll bar, set *fp, *bar_window,
2197 and *part to the frame, window, and scroll bar part that the mouse
2198 is over. Set *x and *y to the portion and whole of the mouse's
2199 position on the scroll bar.
2201 If the mouse movement started elsewhere, set *fp to the frame the
2202 mouse is on, *bar_window to nil, and *x and *y to the character cell
2205 Set *time to the server timestamp for the time at which the mouse
2206 was at this position.
2208 Don't store anything if we don't have a valid set of values to report.
2210 This clears the mouse_moved flag, so we can wait for the next mouse
2211 movement. This also calls XQueryPointer, which will cause the
2212 server to give us another MotionNotify when the mouse moves
2216 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
2219 Lisp_Object
*bar_window
;
2220 enum scroll_bar_part
*part
;
2222 unsigned long *time
;
2228 if (! NILP (last_mouse_scroll_bar
))
2229 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
2235 Window dummy_window
;
2239 last_mouse_scroll_bar
= Qnil
;
2241 /* Figure out which root window we're on. */
2242 XQueryPointer (FRAME_X_DISPLAY (*fp
),
2243 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
2245 /* The root window which contains the pointer. */
2248 /* Trash which we can't trust if the pointer is on
2249 a different screen. */
2252 /* The position on that root window. */
2255 /* More trash we can't trust. */
2258 /* Modifier keys and pointer buttons, about which
2260 (unsigned int *) &dummy
);
2262 /* Now we have a position on the root; find the innermost window
2263 containing the pointer. */
2267 int parent_x
, parent_y
;
2271 /* XTranslateCoordinates can get errors if the window
2272 structure is changing at the same time this function
2273 is running. So at least we must not crash from them. */
2275 x_catch_errors (FRAME_X_DISPLAY (*fp
));
2277 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
2278 && FRAME_LIVE_P (last_mouse_frame
))
2280 /* If mouse was grabbed on a frame, give coords for that frame
2281 even if the mouse is now outside it. */
2282 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2284 /* From-window, to-window. */
2285 root
, FRAME_X_WINDOW (last_mouse_frame
),
2287 /* From-position, to-position. */
2288 root_x
, root_y
, &win_x
, &win_y
,
2292 f1
= last_mouse_frame
;
2298 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2300 /* From-window, to-window. */
2303 /* From-position, to-position. */
2304 root_x
, root_y
, &win_x
, &win_y
,
2317 /* Now we know that:
2318 win is the innermost window containing the pointer
2319 (XTC says it has no child containing the pointer),
2320 win_x and win_y are the pointer's position in it
2321 (XTC did this the last time through), and
2322 parent_x and parent_y are the pointer's position in win's parent.
2323 (They are what win_x and win_y were when win was child.
2324 If win is the root window, it has no parent, and
2325 parent_{x,y} are invalid, but that's okay, because we'll
2326 never use them in that case.) */
2328 /* Is win one of our frames? */
2329 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
2332 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
2335 x_uncatch_errors (FRAME_X_DISPLAY (*fp
));
2337 /* If not, is it one of our scroll bars? */
2340 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
2344 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2350 if (f1
== 0 && insist
)
2351 f1
= selected_frame
;
2355 int ignore1
, ignore2
;
2357 /* Ok, we found a frame. Store all the values. */
2359 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
2361 FRAME_X_DISPLAY_INFO (f1
)->grabbed
2367 XSETINT (*x
, win_x
);
2368 XSETINT (*y
, win_y
);
2369 *time
= last_mouse_movement_time
;
2377 /* Scroll bar support. */
2379 /* Given an X window ID, find the struct scroll_bar which manages it.
2380 This can be called in GC, so we have to make sure to strip off mark
2382 static struct scroll_bar
*
2383 x_window_to_scroll_bar (window_id
)
2386 Lisp_Object tail
, frame
;
2388 for (tail
= Vframe_list
;
2389 XGCTYPE (tail
) == Lisp_Cons
;
2390 tail
= XCONS (tail
)->cdr
)
2392 Lisp_Object frame
, bar
, condemned
;
2394 frame
= XCONS (tail
)->car
;
2395 /* All elements of Vframe_list should be frames. */
2396 if (! GC_FRAMEP (frame
))
2399 /* Scan this frame's scroll bar list for a scroll bar with the
2401 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2402 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2403 /* This trick allows us to search both the ordinary and
2404 condemned scroll bar lists with one loop. */
2405 ! GC_NILP (bar
) || (bar
= condemned
,
2408 bar
= XSCROLL_BAR (bar
)->next
)
2409 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2410 return XSCROLL_BAR (bar
);
2416 /* Open a new X window to serve as a scroll bar, and return the
2417 scroll bar vector for it. */
2418 static struct scroll_bar
*
2419 x_scroll_bar_create (window
, top
, left
, width
, height
)
2420 struct window
*window
;
2421 int top
, left
, width
, height
;
2423 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2424 struct scroll_bar
*bar
2425 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2430 XSetWindowAttributes a
;
2432 a
.background_pixel
= f
->display
.x
->background_pixel
;
2433 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2434 | ButtonMotionMask
| PointerMotionHintMask
2436 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
2438 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2443 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2444 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2445 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
2446 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
2447 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2448 sb_widget
= XtCreateManagedWidget ("box",
2450 f
->display
.x
->edit_widget
, al
, ac
);
2451 SET_SCROLL_BAR_X_WINDOW
2452 (bar
, sb_widget
->core
.window
);
2454 SET_SCROLL_BAR_X_WINDOW
2456 XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2458 /* Position and size of scroll bar. */
2459 left
, top
, width
, height
,
2461 /* Border width, depth, class, and visual. */
2462 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
2468 XSETWINDOW (bar
->window
, window
);
2469 XSETINT (bar
->top
, top
);
2470 XSETINT (bar
->left
, left
);
2471 XSETINT (bar
->width
, width
);
2472 XSETINT (bar
->height
, height
);
2473 XSETINT (bar
->start
, 0);
2474 XSETINT (bar
->end
, 0);
2475 bar
->dragging
= Qnil
;
2477 /* Add bar to its frame's list of scroll bars. */
2478 bar
->next
= FRAME_SCROLL_BARS (f
);
2480 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2481 if (! NILP (bar
->next
))
2482 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2484 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
2491 /* Draw BAR's handle in the proper position.
2492 If the handle is already drawn from START to END, don't bother
2493 redrawing it, unless REBUILD is non-zero; in that case, always
2494 redraw it. (REBUILD is handy for drawing the handle after expose
2497 Normally, we want to constrain the start and end of the handle to
2498 fit inside its rectangle, but if the user is dragging the scroll bar
2499 handle, we want to let them drag it down all the way, so that the
2500 bar's top is as far down as it goes; otherwise, there's no way to
2501 move to the very end of the buffer. */
2503 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
2504 struct scroll_bar
*bar
;
2508 int dragging
= ! NILP (bar
->dragging
);
2509 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2510 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2511 GC gc
= f
->display
.x
->normal_gc
;
2513 /* If the display is already accurate, do nothing. */
2515 && start
== XINT (bar
->start
)
2516 && end
== XINT (bar
->end
))
2522 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (XINT (bar
->width
));
2523 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2524 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2526 /* Make sure the values are reasonable, and try to preserve
2527 the distance between start and end. */
2529 int length
= end
- start
;
2533 else if (start
> top_range
)
2535 end
= start
+ length
;
2539 else if (end
> top_range
&& ! dragging
)
2543 /* Store the adjusted setting in the scroll bar. */
2544 XSETINT (bar
->start
, start
);
2545 XSETINT (bar
->end
, end
);
2547 /* Clip the end position, just for display. */
2548 if (end
> top_range
)
2551 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
2552 below top positions, to make sure the handle is always at least
2553 that many pixels tall. */
2554 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
2556 /* Draw the empty space above the handle. Note that we can't clear
2557 zero-height areas; that means "clear to end of window." */
2559 XClearArea (FRAME_X_DISPLAY (f
), w
,
2561 /* x, y, width, height, and exposures. */
2562 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2563 VERTICAL_SCROLL_BAR_TOP_BORDER
,
2564 inside_width
, start
,
2567 /* Draw the handle itself. */
2568 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
2570 /* x, y, width, height */
2571 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2572 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
2573 inside_width
, end
- start
);
2576 /* Draw the empty space below the handle. Note that we can't
2577 clear zero-height areas; that means "clear to end of window." */
2578 if (end
< inside_height
)
2579 XClearArea (FRAME_X_DISPLAY (f
), w
,
2581 /* x, y, width, height, and exposures. */
2582 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2583 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
2584 inside_width
, inside_height
- end
,
2592 /* Move a scroll bar around on the screen, to accommodate changing
2593 window configurations. */
2595 x_scroll_bar_move (bar
, top
, left
, width
, height
)
2596 struct scroll_bar
*bar
;
2597 int top
, left
, width
, height
;
2599 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2600 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2606 unsigned int mask
= 0;
2613 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
2614 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
2615 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
2616 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
2619 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
2623 XSETINT (bar
->left
, left
);
2624 XSETINT (bar
->top
, top
);
2625 XSETINT (bar
->width
, width
);
2626 XSETINT (bar
->height
, height
);
2631 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
2634 x_scroll_bar_remove (bar
)
2635 struct scroll_bar
*bar
;
2637 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2641 /* Destroy the window. */
2642 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
2644 /* Disassociate this scroll bar from its window. */
2645 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
2650 /* Set the handle of the vertical scroll bar for WINDOW to indicate
2651 that we are displaying PORTION characters out of a total of WHOLE
2652 characters, starting at POSITION. If WINDOW has no scroll bar,
2655 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
2656 struct window
*window
;
2657 int portion
, whole
, position
;
2659 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2660 int top
= XINT (window
->top
);
2661 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
2662 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
2664 /* Where should this scroll bar be, pixelwise? */
2665 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
2666 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
2668 = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
2669 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2670 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->display
.x
->font
)));
2671 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
2673 struct scroll_bar
*bar
;
2675 /* Does the scroll bar exist yet? */
2676 if (NILP (window
->vertical_scroll_bar
))
2677 bar
= x_scroll_bar_create (window
,
2678 pixel_top
, pixel_left
,
2679 pixel_width
, pixel_height
);
2682 /* It may just need to be moved and resized. */
2683 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2684 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
2687 /* Set the scroll bar's current state, unless we're currently being
2689 if (NILP (bar
->dragging
))
2691 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (pixel_height
);
2694 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
2697 int start
= ((double) position
* top_range
) / whole
;
2698 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
2700 x_scroll_bar_set_handle (bar
, start
, end
, 0);
2704 XSETVECTOR (window
->vertical_scroll_bar
, bar
);
2708 /* The following three hooks are used when we're doing a thorough
2709 redisplay of the frame. We don't explicitly know which scroll bars
2710 are going to be deleted, because keeping track of when windows go
2711 away is a real pain - "Can you say set-window-configuration, boys
2712 and girls?" Instead, we just assert at the beginning of redisplay
2713 that *all* scroll bars are to be removed, and then save a scroll bar
2714 from the fiery pit when we actually redisplay its window. */
2716 /* Arrange for all scroll bars on FRAME to be removed at the next call
2717 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
2718 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
2720 XTcondemn_scroll_bars (frame
)
2723 /* The condemned list should be empty at this point; if it's not,
2724 then the rest of Emacs isn't using the condemn/redeem/judge
2725 protocol correctly. */
2726 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
2729 /* Move them all to the "condemned" list. */
2730 FRAME_CONDEMNED_SCROLL_BARS (frame
) = FRAME_SCROLL_BARS (frame
);
2731 FRAME_SCROLL_BARS (frame
) = Qnil
;
2734 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
2735 Note that WINDOW isn't necessarily condemned at all. */
2737 XTredeem_scroll_bar (window
)
2738 struct window
*window
;
2740 struct scroll_bar
*bar
;
2742 /* We can't redeem this window's scroll bar if it doesn't have one. */
2743 if (NILP (window
->vertical_scroll_bar
))
2746 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2748 /* Unlink it from the condemned list. */
2750 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2752 if (NILP (bar
->prev
))
2754 /* If the prev pointer is nil, it must be the first in one of
2756 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
2757 /* It's not condemned. Everything's fine. */
2759 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
2760 window
->vertical_scroll_bar
))
2761 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
2763 /* If its prev pointer is nil, it must be at the front of
2764 one or the other! */
2768 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
2770 if (! NILP (bar
->next
))
2771 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
2773 bar
->next
= FRAME_SCROLL_BARS (f
);
2775 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2776 if (! NILP (bar
->next
))
2777 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2781 /* Remove all scroll bars on FRAME that haven't been saved since the
2782 last call to `*condemn_scroll_bars_hook'. */
2784 XTjudge_scroll_bars (f
)
2787 Lisp_Object bar
, next
;
2789 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
2791 /* Clear out the condemned list now so we won't try to process any
2792 more events on the hapless scroll bars. */
2793 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
2795 for (; ! NILP (bar
); bar
= next
)
2797 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
2799 x_scroll_bar_remove (b
);
2802 b
->next
= b
->prev
= Qnil
;
2805 /* Now there should be no references to the condemned scroll bars,
2806 and they should get garbage-collected. */
2810 /* Handle an Expose or GraphicsExpose event on a scroll bar.
2812 This may be called from a signal handler, so we have to ignore GC
2815 x_scroll_bar_expose (bar
, event
)
2816 struct scroll_bar
*bar
;
2819 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2820 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2821 GC gc
= f
->display
.x
->normal_gc
;
2825 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
2827 /* Draw a one-pixel border just inside the edges of the scroll bar. */
2828 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
2830 /* x, y, width, height */
2831 0, 0, XINT (bar
->width
) - 1, XINT (bar
->height
) - 1);
2836 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
2837 is set to something other than no_event, it is enqueued.
2839 This may be called from a signal handler, so we have to ignore GC
2842 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
2843 struct scroll_bar
*bar
;
2845 struct input_event
*emacs_event
;
2847 if (! GC_WINDOWP (bar
->window
))
2850 emacs_event
->kind
= scroll_bar_click
;
2851 emacs_event
->code
= event
->xbutton
.button
- Button1
;
2852 emacs_event
->modifiers
2853 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
2854 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
2855 event
->xbutton
.state
)
2856 | (event
->type
== ButtonRelease
2859 emacs_event
->frame_or_window
= bar
->window
;
2860 emacs_event
->timestamp
= event
->xbutton
.time
;
2863 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2865 = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2866 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
2869 if (y
> top_range
) y
= top_range
;
2871 if (y
< XINT (bar
->start
))
2872 emacs_event
->part
= scroll_bar_above_handle
;
2873 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
2874 emacs_event
->part
= scroll_bar_handle
;
2876 emacs_event
->part
= scroll_bar_below_handle
;
2878 /* Just because the user has clicked on the handle doesn't mean
2879 they want to drag it. Lisp code needs to be able to decide
2880 whether or not we're dragging. */
2882 /* If the user has just clicked on the handle, record where they're
2884 if (event
->type
== ButtonPress
2885 && emacs_event
->part
== scroll_bar_handle
)
2886 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
2889 /* If the user has released the handle, set it to its final position. */
2890 if (event
->type
== ButtonRelease
2891 && ! NILP (bar
->dragging
))
2893 int new_start
= y
- XINT (bar
->dragging
);
2894 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2896 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2897 bar
->dragging
= Qnil
;
2900 /* Same deal here as the other #if 0. */
2902 /* Clicks on the handle are always reported as occurring at the top of
2904 if (emacs_event
->part
== scroll_bar_handle
)
2905 emacs_event
->x
= bar
->start
;
2907 XSETINT (emacs_event
->x
, y
);
2909 XSETINT (emacs_event
->x
, y
);
2912 XSETINT (emacs_event
->y
, top_range
);
2916 /* Handle some mouse motion while someone is dragging the scroll bar.
2918 This may be called from a signal handler, so we have to ignore GC
2921 x_scroll_bar_note_movement (bar
, event
)
2922 struct scroll_bar
*bar
;
2925 last_mouse_movement_time
= event
->xmotion
.time
;
2928 XSETVECTOR (last_mouse_scroll_bar
, bar
);
2930 /* If we're dragging the bar, display it. */
2931 if (! GC_NILP (bar
->dragging
))
2933 /* Where should the handle be now? */
2934 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
2936 if (new_start
!= XINT (bar
->start
))
2938 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2940 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2944 /* Call XQueryPointer so we'll get an event the next time the mouse
2945 moves and we can see *still* on the same position. */
2948 Window dummy_window
;
2950 XQueryPointer (event
->xmotion
.display
, event
->xmotion
.window
,
2951 &dummy_window
, &dummy_window
,
2952 &dummy
, &dummy
, &dummy
, &dummy
,
2953 (unsigned int *) &dummy
);
2957 /* Return information to the user about the current position of the mouse
2958 on the scroll bar. */
2960 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
2962 Lisp_Object
*bar_window
;
2963 enum scroll_bar_part
*part
;
2965 unsigned long *time
;
2967 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
2968 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2969 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2971 Window dummy_window
;
2973 unsigned int dummy_mask
;
2977 /* Get the mouse's position relative to the scroll bar window, and
2979 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
2981 /* Root, child, root x and root y. */
2982 &dummy_window
, &dummy_window
,
2983 &dummy_coord
, &dummy_coord
,
2985 /* Position relative to scroll bar. */
2988 /* Mouse buttons and modifier keys. */
2994 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2996 = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2998 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
3000 if (! NILP (bar
->dragging
))
3001 win_y
-= XINT (bar
->dragging
);
3005 if (win_y
> top_range
)
3009 *bar_window
= bar
->window
;
3011 if (! NILP (bar
->dragging
))
3012 *part
= scroll_bar_handle
;
3013 else if (win_y
< XINT (bar
->start
))
3014 *part
= scroll_bar_above_handle
;
3015 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3016 *part
= scroll_bar_handle
;
3018 *part
= scroll_bar_below_handle
;
3020 XSETINT (*x
, win_y
);
3021 XSETINT (*y
, top_range
);
3024 last_mouse_scroll_bar
= Qnil
;
3027 *time
= last_mouse_movement_time
;
3033 /* The screen has been cleared so we may have changed foreground or
3034 background colors, and the scroll bars may need to be redrawn.
3035 Clear out the scroll bars, and ask for expose events, so we can
3038 x_scroll_bar_clear (f
)
3043 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
3044 bar
= XSCROLL_BAR (bar
)->next
)
3045 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
3049 /* This processes Expose events from the menubar specific X event
3050 loop in xmenu.c. This allows to redisplay the frame if necessary
3051 when handling menubar or popup items. */
3054 process_expose_from_menu (event
)
3058 struct x_display_info
*dpyinfo
;
3062 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
3063 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3066 if (f
->async_visible
== 0)
3068 f
->async_visible
= 1;
3069 f
->async_iconified
= 0;
3070 SET_FRAME_GARBAGED (f
);
3074 dumprectangle (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
3075 event
.xexpose
.x
, event
.xexpose
.y
,
3076 event
.xexpose
.width
, event
.xexpose
.height
);
3081 struct scroll_bar
*bar
3082 = x_window_to_scroll_bar (event
.xexpose
.window
);
3085 x_scroll_bar_expose (bar
, &event
);
3091 /* Define a queue to save up SelectionRequest events for later handling. */
3093 struct selection_event_queue
3096 struct selection_event_queue
*next
;
3099 static struct selection_event_queue
*queue
;
3101 /* Nonzero means queue up certain events--don't process them yet. */
3102 static int x_queue_selection_requests
;
3104 /* Queue up an X event *EVENT, to be processed later. */
3107 x_queue_event (f
, event
)
3111 struct selection_event_queue
*queue_tmp
3112 = (struct selection_event_queue
*) malloc (sizeof (struct selection_event_queue
));
3114 if (queue_tmp
!= NULL
)
3116 queue_tmp
->event
= *event
;
3117 queue_tmp
->next
= queue
;
3122 /* Take all the queued events and put them back
3123 so that they get processed afresh. */
3126 x_unqueue_events (display
)
3129 while (queue
!= NULL
)
3131 struct selection_event_queue
*queue_tmp
= queue
;
3132 XPutBackEvent (display
, &queue_tmp
->event
);
3133 queue
= queue_tmp
->next
;
3134 free ((char *)queue_tmp
);
3138 /* Start queuing SelectionRequest events. */
3141 x_start_queuing_selection_requests (display
)
3144 x_queue_selection_requests
++;
3147 /* Stop queuing SelectionRequest events. */
3150 x_stop_queuing_selection_requests (display
)
3153 x_queue_selection_requests
--;
3154 x_unqueue_events (display
);
3157 /* The main X event-reading loop - XTread_socket. */
3159 /* Timestamp of enter window event. This is only used by XTread_socket,
3160 but we have to put it out here, since static variables within functions
3161 sometimes don't work. */
3162 static Time enter_timestamp
;
3164 /* This holds the state XLookupString needs to implement dead keys
3165 and other tricks known as "compose processing". _X Window System_
3166 says that a portable program can't use this, but Stephen Gildea assures
3167 me that letting the compiler initialize it to zeros will work okay.
3169 This must be defined outside of XTread_socket, for the same reasons
3170 given for enter_timestamp, above. */
3171 static XComposeStatus compose_status
;
3173 /* Record the last 100 characters stored
3174 to help debug the loss-of-chars-during-GC problem. */
3176 short temp_buffer
[100];
3178 /* Set this to nonzero to fake an "X I/O error"
3179 on a particular display. */
3180 struct x_display_info
*XTread_socket_fake_io_error
;
3182 /* Read events coming from the X server.
3183 This routine is called by the SIGIO handler.
3184 We return as soon as there are no more events to be read.
3186 Events representing keys are stored in buffer BUFP,
3187 which can hold up to NUMCHARS characters.
3188 We return the number of characters stored into the buffer,
3189 thus pretending to be `read'.
3191 WAITP is nonzero if we should block until input arrives.
3192 EXPECTED is nonzero if the caller knows input is available. */
3195 XTread_socket (sd
, bufp
, numchars
, waitp
, expected
)
3197 register struct input_event
*bufp
;
3198 register int numchars
;
3205 int items_pending
; /* How many items are in the X queue. */
3208 int event_found
= 0;
3211 struct x_display_info
*dpyinfo
;
3213 if (interrupt_input_blocked
)
3215 interrupt_input_pending
= 1;
3219 interrupt_input_pending
= 0;
3222 /* So people can tell when we have read the available input. */
3223 input_signal_count
++;
3226 abort (); /* Don't think this happens. */
3228 /* Find the display we are supposed to read input for.
3229 It's the one communicating on descriptor SD. */
3230 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
3232 #if 0 /* This ought to be unnecessary; let's verify it. */
3234 /* If available, Xlib uses FIOSNBIO to make the socket
3235 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3236 FIOSNBIO is ignored, and instead of signalling EWOULDBLOCK,
3237 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3238 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
3239 #endif /* ! defined (FIOSNBIO) */
3242 #if 0 /* This code can't be made to work, with multiple displays,
3243 and appears not to be used on any system any more.
3244 Also keyboard.c doesn't turn O_NDELAY on and off
3245 for X connections. */
3248 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
3250 extern int read_alarm_should_throw
;
3251 read_alarm_should_throw
= 1;
3252 XPeekEvent (dpyinfo
->display
, &event
);
3253 read_alarm_should_throw
= 0;
3255 #endif /* HAVE_SELECT */
3259 /* For debugging, this gives a way to fake an I/O error. */
3260 if (dpyinfo
== XTread_socket_fake_io_error
)
3262 XTread_socket_fake_io_error
= 0;
3263 x_io_error_quitter (dpyinfo
->display
);
3266 while (XPending (dpyinfo
->display
) != 0)
3268 XNextEvent (dpyinfo
->display
, &event
);
3275 if (event
.xclient
.message_type
3276 == dpyinfo
->Xatom_wm_protocols
3277 && event
.xclient
.format
== 32)
3279 if (event
.xclient
.data
.l
[0]
3280 == dpyinfo
->Xatom_wm_take_focus
)
3282 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3283 /* Since we set WM_TAKE_FOCUS, we must call
3284 XSetInputFocus explicitly. But not if f is null,
3285 since that might be an event for a deleted frame. */
3287 XSetInputFocus (event
.xclient
.display
,
3288 event
.xclient
.window
,
3289 RevertToPointerRoot
,
3290 event
.xclient
.data
.l
[1]);
3291 /* Not certain about handling scroll bars here */
3293 else if (event
.xclient
.data
.l
[0]
3294 == dpyinfo
->Xatom_wm_save_yourself
)
3296 /* Save state modify the WM_COMMAND property to
3297 something which can reinstate us. This notifies
3298 the session manager, who's looking for such a
3299 PropertyNotify. Can restart processing when
3300 a keyboard or mouse event arrives. */
3303 f
= x_top_window_to_frame (dpyinfo
,
3304 event
.xclient
.window
);
3306 /* This is just so we only give real data once
3307 for a single Emacs process. */
3308 if (f
== selected_frame
)
3309 XSetCommand (FRAME_X_DISPLAY (f
),
3310 event
.xclient
.window
,
3311 initial_argv
, initial_argc
);
3313 XSetCommand (FRAME_X_DISPLAY (f
),
3314 event
.xclient
.window
,
3318 else if (event
.xclient
.data
.l
[0]
3319 == dpyinfo
->Xatom_wm_delete_window
)
3322 = x_any_window_to_frame (dpyinfo
,
3323 event
.xclient
.window
);
3330 bufp
->kind
= delete_window_event
;
3331 XSETFRAME (bufp
->frame_or_window
, f
);
3339 else if (event
.xclient
.message_type
3340 == dpyinfo
->Xatom_wm_configure_denied
)
3343 else if (event
.xclient
.message_type
3344 == dpyinfo
->Xatom_wm_window_moved
)
3348 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3350 new_x
= event
.xclient
.data
.s
[0];
3351 new_y
= event
.xclient
.data
.s
[1];
3355 f
->display
.x
->left_pos
= new_x
;
3356 f
->display
.x
->top_pos
= new_y
;
3359 #if defined (USE_X_TOOLKIT) && defined (HAVE_X11R5)
3360 else if (event
.xclient
.message_type
3361 == dpyinfo
->Xatom_editres
)
3364 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
3365 _XEditResCheckMessages (f
->display
.x
->widget
, NULL
,
3368 #endif /* USE_X_TOOLKIT and HAVE_X11R5 */
3372 case SelectionNotify
:
3373 #ifdef USE_X_TOOLKIT
3374 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
3376 #endif /* not USE_X_TOOLKIT */
3377 x_handle_selection_notify (&event
);
3380 case SelectionClear
: /* Someone has grabbed ownership. */
3381 #ifdef USE_X_TOOLKIT
3382 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
3384 #endif /* USE_X_TOOLKIT */
3386 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
3391 bufp
->kind
= selection_clear_event
;
3392 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3393 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3394 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3402 case SelectionRequest
: /* Someone wants our selection. */
3403 #ifdef USE_X_TOOLKIT
3404 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
3406 #endif /* USE_X_TOOLKIT */
3407 if (x_queue_selection_requests
)
3408 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
3412 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
3417 bufp
->kind
= selection_request_event
;
3418 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3419 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
3420 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3421 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
3422 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
3423 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3431 case PropertyNotify
:
3432 #ifdef USE_X_TOOLKIT
3433 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
3435 #endif /* not USE_X_TOOLKIT */
3436 x_handle_property_notify (&event
);
3439 case ReparentNotify
:
3440 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
3444 f
->display
.x
->parent_desc
= event
.xreparent
.parent
;
3445 x_real_positions (f
, &x
, &y
);
3446 f
->display
.x
->left_pos
= x
;
3447 f
->display
.x
->top_pos
= y
;
3452 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3455 if (f
->async_visible
== 0)
3457 f
->async_visible
= 1;
3458 f
->async_iconified
= 0;
3459 SET_FRAME_GARBAGED (f
);
3462 dumprectangle (x_window_to_frame (dpyinfo
,
3463 event
.xexpose
.window
),
3464 event
.xexpose
.x
, event
.xexpose
.y
,
3465 event
.xexpose
.width
, event
.xexpose
.height
);
3469 struct scroll_bar
*bar
3470 = x_window_to_scroll_bar (event
.xexpose
.window
);
3473 x_scroll_bar_expose (bar
, &event
);
3474 #ifdef USE_X_TOOLKIT
3477 #endif /* USE_X_TOOLKIT */
3481 case GraphicsExpose
: /* This occurs when an XCopyArea's
3482 source area was obscured or not
3484 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
3488 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
3489 event
.xgraphicsexpose
.width
,
3490 event
.xgraphicsexpose
.height
);
3492 #ifdef USE_X_TOOLKIT
3495 #endif /* USE_X_TOOLKIT */
3498 case NoExpose
: /* This occurs when an XCopyArea's
3499 source area was completely
3504 f
= x_any_window_to_frame (dpyinfo
, event
.xunmap
.window
);
3505 if (f
) /* F may no longer exist if
3506 the frame was deleted. */
3508 /* While a frame is unmapped, display generation is
3509 disabled; you don't want to spend time updating a
3510 display that won't ever be seen. */
3511 f
->async_visible
= 0;
3512 /* We can't distinguish, from the event, whether the window
3513 has become iconified or invisible. So assume, if it
3514 was previously visible, than now it is iconified.
3515 We depend on x_make_frame_invisible to mark it iconified. */
3516 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
3517 f
->async_iconified
= 1;
3519 bufp
->kind
= iconify_event
;
3520 XSETFRAME (bufp
->frame_or_window
, f
);
3525 #ifdef USE_X_TOOLKIT
3527 #endif /* USE_X_TOOLKIT */
3531 /* We use x_top_window_to_frame because map events can come
3532 for subwindows and they don't mean that the frame is visible. */
3533 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
3536 f
->async_visible
= 1;
3537 f
->async_iconified
= 0;
3539 /* wait_reading_process_input will notice this and update
3540 the frame's display structures. */
3541 SET_FRAME_GARBAGED (f
);
3545 bufp
->kind
= deiconify_event
;
3546 XSETFRAME (bufp
->frame_or_window
, f
);
3552 /* Force a redisplay sooner or later
3553 to update the frame titles
3554 in case this is the second frame. */
3555 record_asynch_buffer_change ();
3557 #ifdef USE_X_TOOLKIT
3559 #endif /* USE_X_TOOLKIT */
3562 /* Turn off processing if we become fully obscured. */
3563 case VisibilityNotify
:
3567 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
3571 KeySym keysym
, orig_keysym
;
3572 /* al%imercury@uunet.uu.net says that making this 81 instead of
3573 80 fixed a bug whereby meta chars made his Emacs hang. */
3574 unsigned char copy_buffer
[81];
3578 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
3579 extra_keyboard_modifiers
);
3580 modifiers
= event
.xkey
.state
;
3582 /* This will have to go some day... */
3584 /* make_lispy_event turns chars into control chars.
3585 Don't do it here because XLookupString is too eager. */
3586 event
.xkey
.state
&= ~ControlMask
;
3587 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
3588 80, &keysym
, &compose_status
);
3590 orig_keysym
= keysym
;
3594 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
3595 || keysym
== XK_Delete
3596 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
3597 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
3599 /* This recognizes the "extended function keys".
3600 It seems there's no cleaner way.
3601 Test IsModifierKey to avoid handling mode_switch
3603 || ((unsigned) (keysym
) >= XK_Select
3604 && (unsigned)(keysym
) < XK_KP_Space
)
3606 #ifdef XK_dead_circumflex
3607 || orig_keysym
== XK_dead_circumflex
3609 #ifdef XK_dead_grave
3610 || orig_keysym
== XK_dead_grave
3612 #ifdef XK_dead_tilde
3613 || orig_keysym
== XK_dead_tilde
3615 #ifdef XK_dead_diaeresis
3616 || orig_keysym
== XK_dead_diaeresis
3618 #ifdef XK_dead_macron
3619 || orig_keysym
== XK_dead_macron
3621 #ifdef XK_dead_degree
3622 || orig_keysym
== XK_dead_degree
3624 #ifdef XK_dead_acute
3625 || orig_keysym
== XK_dead_acute
3627 #ifdef XK_dead_cedilla
3628 || orig_keysym
== XK_dead_cedilla
3630 #ifdef XK_dead_breve
3631 || orig_keysym
== XK_dead_breve
3633 #ifdef XK_dead_ogonek
3634 || orig_keysym
== XK_dead_ogonek
3636 #ifdef XK_dead_caron
3637 || orig_keysym
== XK_dead_caron
3639 #ifdef XK_dead_doubleacute
3640 || orig_keysym
== XK_dead_doubleacute
3642 #ifdef XK_dead_abovedot
3643 || orig_keysym
== XK_dead_abovedot
3645 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
3646 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
3647 /* Any "vendor-specific" key is ok. */
3648 || (orig_keysym
& (1 << 28)))
3649 && ! (IsModifierKey (orig_keysym
)
3651 #ifdef XK_Mode_switch
3652 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
3655 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
3657 #endif /* not HAVE_X11R5 */
3660 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3662 temp_buffer
[temp_index
++] = keysym
;
3663 bufp
->kind
= non_ascii_keystroke
;
3664 bufp
->code
= keysym
;
3665 XSETFRAME (bufp
->frame_or_window
, f
);
3667 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3669 bufp
->timestamp
= event
.xkey
.time
;
3674 else if (numchars
> nbytes
)
3678 for (i
= 0; i
< nbytes
; i
++)
3680 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3682 temp_buffer
[temp_index
++] = copy_buffer
[i
];
3683 bufp
->kind
= ascii_keystroke
;
3684 bufp
->code
= copy_buffer
[i
];
3685 XSETFRAME (bufp
->frame_or_window
, f
);
3687 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3689 bufp
->timestamp
= event
.xkey
.time
;
3704 /* Here's a possible interpretation of the whole
3705 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
3706 FocusIn event, you have to get a FocusOut event before you
3707 relinquish the focus. If you haven't received a FocusIn event,
3708 then a mere LeaveNotify is enough to free you. */
3711 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
3713 if (event
.xcrossing
.focus
) /* Entered Window */
3715 /* Avoid nasty pop/raise loops. */
3716 if (f
&& (!(f
->auto_raise
)
3718 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
3720 x_new_focus_frame (dpyinfo
, f
);
3721 enter_timestamp
= event
.xcrossing
.time
;
3724 else if (f
== dpyinfo
->x_focus_frame
)
3725 x_new_focus_frame (dpyinfo
, 0);
3726 /* EnterNotify counts as mouse movement,
3727 so update things that depend on mouse position. */
3729 note_mouse_movement (f
, &event
.xmotion
);
3730 #ifdef USE_X_TOOLKIT
3732 #endif /* USE_X_TOOLKIT */
3736 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
3737 if (event
.xfocus
.detail
!= NotifyPointer
)
3738 dpyinfo
->x_focus_event_frame
= f
;
3740 x_new_focus_frame (dpyinfo
, f
);
3741 #ifdef USE_X_TOOLKIT
3743 #endif /* USE_X_TOOLKIT */
3748 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
3751 if (f
== dpyinfo
->mouse_face_mouse_frame
)
3752 /* If we move outside the frame,
3753 then we're certainly no longer on any text in the frame. */
3754 clear_mouse_face (dpyinfo
);
3756 if (event
.xcrossing
.focus
)
3757 x_mouse_leave (dpyinfo
);
3760 if (f
== dpyinfo
->x_focus_event_frame
)
3761 dpyinfo
->x_focus_event_frame
= 0;
3762 if (f
== dpyinfo
->x_focus_frame
)
3763 x_new_focus_frame (dpyinfo
, 0);
3766 #ifdef USE_X_TOOLKIT
3768 #endif /* USE_X_TOOLKIT */
3772 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
3773 if (event
.xfocus
.detail
!= NotifyPointer
3774 && f
== dpyinfo
->x_focus_event_frame
)
3775 dpyinfo
->x_focus_event_frame
= 0;
3776 if (f
&& f
== dpyinfo
->x_focus_frame
)
3777 x_new_focus_frame (dpyinfo
, 0);
3778 #ifdef USE_X_TOOLKIT
3780 #endif /* USE_X_TOOLKIT */
3785 if (dpyinfo
->grabbed
&& last_mouse_frame
3786 && FRAME_LIVE_P (last_mouse_frame
))
3787 f
= last_mouse_frame
;
3789 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
3791 note_mouse_movement (f
, &event
.xmotion
);
3794 struct scroll_bar
*bar
3795 = x_window_to_scroll_bar (event
.xmotion
.window
);
3798 x_scroll_bar_note_movement (bar
, &event
);
3800 /* If we move outside the frame,
3801 then we're certainly no longer on any text in the frame. */
3802 clear_mouse_face (dpyinfo
);
3805 #ifdef USE_X_TOOLKIT
3807 #endif /* USE_X_TOOLKIT */
3810 case ConfigureNotify
:
3811 f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
3813 #ifdef USE_X_TOOLKIT
3814 && (event
.xconfigure
.window
== XtWindow (f
->display
.x
->widget
))
3818 #ifndef USE_X_TOOLKIT
3819 /* In the toolkit version, change_frame_size
3820 is called by the code that handles resizing
3821 of the EmacsFrame widget. */
3823 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
3824 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
3826 /* Even if the number of character rows and columns has
3827 not changed, the font size may have changed, so we need
3828 to check the pixel dimensions as well. */
3829 if (columns
!= f
->width
3830 || rows
!= f
->height
3831 || event
.xconfigure
.width
!= f
->display
.x
->pixel_width
3832 || event
.xconfigure
.height
!= f
->display
.x
->pixel_height
)
3834 change_frame_size (f
, rows
, columns
, 0, 1);
3835 SET_FRAME_GARBAGED (f
);
3839 /* Formerly, in the USE_X_TOOLKIT version,
3840 we did not test send_event here. */
3842 #ifndef USE_X_TOOLKIT
3843 && ! event
.xconfigure
.send_event
3850 /* Find the position of the outside upper-left corner of
3851 the window, in the root coordinate system. Don't
3852 refer to the parent window here; we may be processing
3853 this event after the window manager has changed our
3854 parent, but before we have reached the ReparentNotify. */
3855 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
3857 /* From-window, to-window. */
3858 event
.xconfigure
.window
,
3859 FRAME_X_DISPLAY_INFO (f
)->root_window
,
3861 /* From-position, to-position. */
3862 -event
.xconfigure
.border_width
,
3863 -event
.xconfigure
.border_width
,
3868 event
.xconfigure
.x
= win_x
;
3869 event
.xconfigure
.y
= win_y
;
3872 f
->display
.x
->pixel_width
= event
.xconfigure
.width
;
3873 f
->display
.x
->pixel_height
= event
.xconfigure
.height
;
3874 f
->display
.x
->left_pos
= event
.xconfigure
.x
;
3875 f
->display
.x
->top_pos
= event
.xconfigure
.y
;
3877 /* What we have now is the position of Emacs's own window.
3878 Convert that to the position of the window manager window. */
3881 x_real_positions (f
, &x
, &y
);
3882 f
->display
.x
->left_pos
= x
;
3883 f
->display
.x
->top_pos
= y
;
3884 /* Formerly we did not do this in the USE_X_TOOLKIT
3885 version. Let's try making them the same. */
3886 /* #ifndef USE_X_TOOLKIT */
3887 if (y
!= event
.xconfigure
.y
)
3889 /* Since the WM decorations come below top_pos now,
3890 we must put them below top_pos in the future. */
3891 f
->display
.x
->win_gravity
= NorthWestGravity
;
3892 x_wm_set_size_hint (f
, (long) 0, 0);
3897 #ifdef USE_X_TOOLKIT
3906 /* If we decide we want to generate an event to be seen
3907 by the rest of Emacs, we put it here. */
3908 struct input_event emacs_event
;
3909 emacs_event
.kind
= no_event
;
3911 bzero (&compose_status
, sizeof (compose_status
));
3913 if (dpyinfo
->grabbed
&& last_mouse_frame
3914 && FRAME_LIVE_P (last_mouse_frame
))
3915 f
= last_mouse_frame
;
3917 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
3921 if (!dpyinfo
->x_focus_frame
|| f
== dpyinfo
->x_focus_frame
)
3922 construct_mouse_click (&emacs_event
, &event
, f
);
3926 struct scroll_bar
*bar
3927 = x_window_to_scroll_bar (event
.xbutton
.window
);
3930 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
3931 #if 0 /* It doesn't make sense to do this.
3932 Menu bar clicks are handled within the toolkit itself. */
3933 #ifdef USE_X_TOOLKIT
3936 /* Assume we have a menubar button press. A bad
3937 assumption should behave benignly. */
3938 popup_get_selection (&event
, dpyinfo
);
3941 #endif /* USE_X_TOOLKIT */
3945 if (event
.type
== ButtonPress
)
3947 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
3948 last_mouse_frame
= f
;
3952 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
3955 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
3957 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
3963 #ifdef USE_X_TOOLKIT
3965 #endif /* USE_X_TOOLKIT */
3969 case CirculateNotify
:
3971 case CirculateRequest
:
3975 /* Someone has changed the keyboard mapping - update the
3977 switch (event
.xmapping
.request
)
3979 case MappingModifier
:
3980 x_find_modifier_meanings (dpyinfo
);
3981 /* This is meant to fall through. */
3982 case MappingKeyboard
:
3983 XRefreshKeyboardMapping (&event
.xmapping
);
3985 #ifdef USE_X_TOOLKIT
3987 #endif /* USE_X_TOOLKIT */
3991 #ifdef USE_X_TOOLKIT
3994 XtDispatchEvent (&event
);
3996 #endif /* USE_X_TOOLKIT */
4002 /* On some systems, an X bug causes Emacs to get no more events
4003 when the window is destroyed. Detect that. (1994.) */
4006 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
4007 One XNOOP in 100 loops will make Emacs terminate.
4008 B. Bretthauer, 1994 */
4010 if (x_noop_count
>= 100)
4013 /* Use the first display in the list. Why not? */
4014 XNoOp (x_display_list
->display
);
4018 /* If the focus was just given to an autoraising frame,
4020 /* ??? This ought to be able to handle more than one such frame. */
4021 if (pending_autoraise_frame
)
4023 x_raise_frame (pending_autoraise_frame
);
4024 pending_autoraise_frame
= 0;
4031 /* Drawing the cursor. */
4034 /* Draw a hollow box cursor. Don't change the inside of the box. */
4040 int left
= CHAR_TO_PIXEL_COL (f
, curs_x
);
4041 int top
= CHAR_TO_PIXEL_ROW (f
, curs_y
);
4042 int width
= FONT_WIDTH (f
->display
.x
->font
);
4043 int height
= f
->display
.x
->line_height
;
4045 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4046 f
->display
.x
->cursor_gc
,
4047 left
, top
, width
- 1, height
- 1);
4050 /* Clear the cursor of frame F to background color,
4051 and mark the cursor as not shown.
4052 This is used when the text where the cursor is
4053 is about to be rewritten. */
4061 if (! FRAME_VISIBLE_P (f
)
4062 || f
->phys_cursor_x
< 0)
4065 x_display_cursor (f
, 0);
4066 f
->phys_cursor_x
= -1;
4069 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4070 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4074 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
4081 CHAR_TO_PIXEL_COL (f
, column
),
4082 CHAR_TO_PIXEL_ROW (f
, row
),
4083 &glyph
, 1, highlight
, 0);
4087 x_display_bar_cursor (f
, on
)
4091 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4093 /* This is pointless on invisible frames, and dangerous on garbaged
4094 frames; in the latter case, the frame may be in the midst of
4095 changing its size, and curs_x and curs_y may be off the frame. */
4096 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4099 if (! on
&& f
->phys_cursor_x
< 0)
4102 /* If we're not updating, then we want to use the current frame's
4103 cursor position, not our local idea of where the cursor ought to be. */
4104 if (f
!= updating_frame
)
4106 curs_x
= FRAME_CURSOR_X (f
);
4107 curs_y
= FRAME_CURSOR_Y (f
);
4110 /* If there is anything wrong with the current cursor state, remove it. */
4111 if (f
->phys_cursor_x
>= 0
4113 || f
->phys_cursor_x
!= curs_x
4114 || f
->phys_cursor_y
!= curs_y
4115 || f
->display
.x
->current_cursor
!= bar_cursor
))
4117 /* Erase the cursor by redrawing the character underneath it. */
4118 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4119 f
->phys_cursor_glyph
,
4120 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4121 f
->phys_cursor_x
= -1;
4124 /* If we now need a cursor in the new place or in the new form, do it so. */
4126 && (f
->phys_cursor_x
< 0
4127 || (f
->display
.x
->current_cursor
!= bar_cursor
)))
4129 f
->phys_cursor_glyph
4130 = ((current_glyphs
->enable
[curs_y
]
4131 && curs_x
< current_glyphs
->used
[curs_y
])
4132 ? current_glyphs
->glyphs
[curs_y
][curs_x
]
4134 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4135 f
->display
.x
->cursor_gc
,
4136 CHAR_TO_PIXEL_COL (f
, curs_x
),
4137 CHAR_TO_PIXEL_ROW (f
, curs_y
),
4138 max (f
->display
.x
->cursor_width
, 1),
4139 f
->display
.x
->line_height
);
4141 f
->phys_cursor_x
= curs_x
;
4142 f
->phys_cursor_y
= curs_y
;
4144 f
->display
.x
->current_cursor
= bar_cursor
;
4147 if (updating_frame
!= f
)
4148 XFlush (FRAME_X_DISPLAY (f
));
4152 /* Turn the displayed cursor of frame F on or off according to ON.
4153 If ON is nonzero, where to put the cursor is specified
4154 by F->cursor_x and F->cursor_y. */
4157 x_display_box_cursor (f
, on
)
4161 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4163 /* This is pointless on invisible frames, and dangerous on garbaged
4164 frames; in the latter case, the frame may be in the midst of
4165 changing its size, and curs_x and curs_y may be off the frame. */
4166 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4169 /* If cursor is off and we want it off, return quickly. */
4170 if (!on
&& f
->phys_cursor_x
< 0)
4173 /* If we're not updating, then we want to use the current frame's
4174 cursor position, not our local idea of where the cursor ought to be. */
4175 if (f
!= updating_frame
)
4177 curs_x
= FRAME_CURSOR_X (f
);
4178 curs_y
= FRAME_CURSOR_Y (f
);
4181 /* If cursor is currently being shown and we don't want it to be
4182 or it is in the wrong place,
4183 or we want a hollow box and it's not so, (pout!)
4185 if (f
->phys_cursor_x
>= 0
4187 || f
->phys_cursor_x
!= curs_x
4188 || f
->phys_cursor_y
!= curs_y
4189 || (f
->display
.x
->current_cursor
!= hollow_box_cursor
4190 && (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
))))
4192 int mouse_face_here
= 0;
4193 struct frame_glyphs
*active_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4195 /* If the cursor is in the mouse face area, redisplay that when
4196 we clear the cursor. */
4197 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
4199 (f
->phys_cursor_y
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4200 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4201 && f
->phys_cursor_x
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
))
4203 (f
->phys_cursor_y
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4204 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4205 && f
->phys_cursor_x
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
))
4206 /* Don't redraw the cursor's spot in mouse face
4207 if it is at the end of a line (on a newline).
4208 The cursor appears there, but mouse highlighting does not. */
4209 && active_glyphs
->used
[f
->phys_cursor_y
] > f
->phys_cursor_x
)
4210 mouse_face_here
= 1;
4212 /* If the font is not as tall as a whole line,
4213 we must explicitly clear the line's whole height. */
4214 if (FONT_HEIGHT (f
->display
.x
->font
) != f
->display
.x
->line_height
)
4215 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4216 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
4217 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
4218 FONT_WIDTH (f
->display
.x
->font
),
4219 f
->display
.x
->line_height
, False
);
4220 /* Erase the cursor by redrawing the character underneath it. */
4221 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4222 f
->phys_cursor_glyph
,
4225 : current_glyphs
->highlight
[f
->phys_cursor_y
]));
4226 f
->phys_cursor_x
= -1;
4229 /* If we want to show a cursor,
4230 or we want a box cursor and it's not so,
4231 write it in the right place. */
4233 && (f
->phys_cursor_x
< 0
4234 || (f
->display
.x
->current_cursor
!= filled_box_cursor
4235 && f
== FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)))
4237 f
->phys_cursor_glyph
4238 = ((current_glyphs
->enable
[curs_y
]
4239 && curs_x
< current_glyphs
->used
[curs_y
])
4240 ? current_glyphs
->glyphs
[curs_y
][curs_x
]
4242 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
4245 f
->display
.x
->current_cursor
= hollow_box_cursor
;
4249 x_draw_single_glyph (f
, curs_y
, curs_x
,
4250 f
->phys_cursor_glyph
, 2);
4251 f
->display
.x
->current_cursor
= filled_box_cursor
;
4254 f
->phys_cursor_x
= curs_x
;
4255 f
->phys_cursor_y
= curs_y
;
4258 if (updating_frame
!= f
)
4259 XFlush (FRAME_X_DISPLAY (f
));
4262 x_display_cursor (f
, on
)
4268 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4269 x_display_box_cursor (f
, on
);
4270 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4271 x_display_bar_cursor (f
, on
);
4273 /* Those are the only two we have implemented! */
4281 /* Refresh bitmap kitchen sink icon for frame F
4282 when we get an expose event for it. */
4287 /* Normally, the window manager handles this function. */
4290 /* Make the x-window of frame F use the gnu icon bitmap. */
4293 x_bitmap_icon (f
, file
)
4297 int mask
, bitmap_id
;
4300 if (FRAME_X_WINDOW (f
) == 0)
4303 /* Free up our existing icon bitmap if any. */
4304 if (f
->display
.x
->icon_bitmap
> 0)
4305 x_destroy_bitmap (f
, f
->display
.x
->icon_bitmap
);
4306 f
->display
.x
->icon_bitmap
= 0;
4309 bitmap_id
= x_create_bitmap_from_file (f
, file
);
4312 /* Create the GNU bitmap if necessary. */
4313 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
4314 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
4315 = x_create_bitmap_from_data (f
, gnu_bits
,
4316 gnu_width
, gnu_height
);
4318 /* The first time we create the GNU bitmap,
4319 this increments the refcount one extra time.
4320 As a result, the GNU bitmap is never freed.
4321 That way, we don't have to worry about allocating it again. */
4322 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
4324 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
4327 x_wm_set_icon_pixmap (f
, bitmap_id
);
4328 f
->display
.x
->icon_bitmap
= bitmap_id
;
4334 /* Make the x-window of frame F use a rectangle with text.
4335 Use ICON_NAME as the text. */
4338 x_text_icon (f
, icon_name
)
4342 if (FRAME_X_WINDOW (f
) == 0)
4348 text
.value
= (unsigned char *) icon_name
;
4349 text
.encoding
= XA_STRING
;
4351 text
.nitems
= strlen (icon_name
);
4352 #ifdef USE_X_TOOLKIT
4353 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
),
4355 #else /* not USE_X_TOOLKIT */
4356 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
4357 #endif /* not USE_X_TOOLKIT */
4359 #else /* not HAVE_X11R4 */
4360 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
4361 #endif /* not HAVE_X11R4 */
4363 if (f
->display
.x
->icon_bitmap
> 0)
4364 x_destroy_bitmap (f
, f
->display
.x
->icon_bitmap
);
4365 f
->display
.x
->icon_bitmap
= 0;
4366 x_wm_set_icon_pixmap (f
, 0);
4371 /* Handling X errors. */
4373 /* Handle the loss of connection to display DISPLAY. */
4376 x_connection_closed (display
, error_message
)
4378 char *error_message
;
4380 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
4381 Lisp_Object frame
, tail
;
4383 /* Whatever we were in the middle of, we are going to throw out of it,
4384 so reassure various things that have error checks about being
4385 called with input blocked. */
4386 TOTALLY_UNBLOCK_INPUT
;
4391 /* First delete frames whose minibuffers are on frames
4392 that are on the dead display. */
4393 FOR_EACH_FRAME (tail
, frame
)
4395 Lisp_Object minibuf_frame
;
4397 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
4398 if (FRAME_X_P (XFRAME (frame
))
4399 && FRAME_X_P (XFRAME (minibuf_frame
))
4400 && ! EQ (frame
, minibuf_frame
)
4401 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
4402 Fdelete_frame (frame
, Qt
);
4405 /* Now delete all remaining frames on the dead display.
4406 We are now sure none of these is used as the minibuffer
4407 for another frame that we need to delete. */
4408 FOR_EACH_FRAME (tail
, frame
)
4409 if (FRAME_X_P (XFRAME (frame
))
4410 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
4412 /* Set this to t so that Fdelete_frame won't get confused
4413 trying to find a replacement. */
4414 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
4415 Fdelete_frame (frame
, Qt
);
4418 x_delete_display (dpyinfo
);
4420 if (x_display_list
== 0)
4422 fprintf (stderr
, "%s", error_message
);
4423 shut_down_emacs (0, 0, Qnil
);
4427 /* Ordinary stack unwind doesn't deal with these. */
4429 sigunblock (sigmask (SIGIO
));
4431 sigunblock (sigmask (SIGALRM
));
4432 TOTALLY_UNBLOCK_INPUT
;
4434 error ("%s", error_message
);
4438 x_connection_signal (signalnum
) /* If we don't have an argument, */
4439 int signalnum
; /* some compilers complain in signal calls. */
4441 /* We really ought to close the connection to the display
4442 that actually failed.
4443 But do we actually get this signal ever with X11? */
4444 fprintf (stderr
, "X connection closed");
4445 shut_down_emacs (0, 0, Qnil
);
4449 /* This is the usual handler for X protocol errors.
4450 It kills all frames on the display that we got the error for.
4451 If that was the only one, it prints an error message and kills Emacs. */
4454 x_error_quitter (display
, error
)
4458 char buf
[256], buf1
[356];
4460 /* Note that there is no real way portable across R3/R4 to get the
4461 original error handler. */
4463 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
4464 sprintf (buf1
, "X protocol error: %s on protocol request %d",
4465 buf
, error
->request_code
);
4466 x_connection_closed (display
, buf1
);
4469 /* This is the handler for X IO errors, always.
4470 It kills all frames on the display that we lost touch with.
4471 If that was the only one, it prints an error message and kills Emacs. */
4474 x_io_error_quitter (display
)
4479 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
4480 x_connection_closed (display
, buf
);
4483 /* A buffer for storing X error messages. */
4484 static char *x_caught_error_message
;
4485 #define X_CAUGHT_ERROR_MESSAGE_SIZE 200
4487 /* An X error handler which stores the error message in
4488 x_caught_error_message. This is what's installed when
4489 x_catch_errors is in effect. */
4492 x_error_catcher (display
, error
)
4496 XGetErrorText (display
, error
->error_code
,
4497 x_caught_error_message
, X_CAUGHT_ERROR_MESSAGE_SIZE
);
4501 /* Begin trapping X errors for display DPY. Actually we trap X errors
4502 for all displays, but DPY should be the display you are actually
4505 After calling this function, X protocol errors no longer cause
4506 Emacs to exit; instead, they are recorded in x_cfc_error_message.
4508 Calling x_check_errors signals an Emacs error if an X error has
4509 occurred since the last call to x_catch_errors or x_check_errors.
4511 Calling x_uncatch_errors resumes the normal error handling. */
4513 void x_catch_errors (), x_check_errors (), x_uncatch_errors ();
4516 x_catch_errors (dpy
)
4519 /* Make sure any errors from previous requests have been dealt with. */
4522 /* Set up the error buffer. */
4523 x_caught_error_message
4524 = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE
);
4525 x_caught_error_message
[0] = '\0';
4527 /* Install our little error handler. */
4528 XSetErrorHandler (x_error_catcher
);
4531 /* If any X protocol errors have arrived since the last call to
4532 x_catch_errors or x_check_errors, signal an Emacs error using
4533 sprintf (a buffer, FORMAT, the x error message text) as the text. */
4536 x_check_errors (dpy
, format
)
4540 /* Make sure to catch any errors incurred so far. */
4543 if (x_caught_error_message
[0])
4545 char buf
[X_CAUGHT_ERROR_MESSAGE_SIZE
+ 56];
4547 sprintf (buf
, format
, x_caught_error_message
);
4548 x_uncatch_errors (dpy
);
4553 /* Nonzero if we had any X protocol errors since we did x_catch_errors. */
4556 x_had_errors_p (dpy
)
4559 /* Make sure to catch any errors incurred so far. */
4562 return x_caught_error_message
[0] != 0;
4565 /* Stop catching X protocol errors and let them make Emacs die. */
4568 x_uncatch_errors (dpy
)
4571 xfree (x_caught_error_message
);
4572 x_caught_error_message
= 0;
4573 XSetErrorHandler (x_error_quitter
);
4577 static unsigned int x_wire_count
;
4580 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
4585 /* Changing the font of the frame. */
4587 /* Give frame F the font named FONTNAME as its default font, and
4588 return the full name of that font. FONTNAME may be a wildcard
4589 pattern; in that case, we choose some font that fits the pattern.
4590 The return value shows which font we chose. */
4593 x_new_font (f
, fontname
)
4595 register char *fontname
;
4598 int n_matching_fonts
;
4599 XFontStruct
*font_info
;
4602 /* Get a list of all the fonts that match this name. Once we
4603 have a list of matching fonts, we compare them against the fonts
4604 we already have by comparing font ids. */
4605 font_names
= (char **) XListFonts (FRAME_X_DISPLAY (f
), fontname
,
4606 1024, &n_matching_fonts
);
4607 /* Apparently it doesn't set n_matching_fonts to zero when it can't
4608 find any matches; font_names == 0 is the only clue. */
4610 n_matching_fonts
= 0;
4612 /* Don't just give up if n_matching_fonts is 0.
4613 Apparently there's a bug on Suns: XListFontsWithInfo can
4614 fail to find a font, but XLoadQueryFont may still find it. */
4616 /* See if we've already loaded a matching font. */
4617 already_loaded
= -1;
4618 if (n_matching_fonts
!= 0)
4622 for (i
= 0; i
< FRAME_X_DISPLAY_INFO (f
)->n_fonts
; i
++)
4623 for (j
= 0; j
< n_matching_fonts
; j
++)
4624 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].name
, font_names
[j
])
4625 || !strcmp (FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].full_name
, font_names
[j
]))
4628 fontname
= FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].full_name
;
4634 /* If we have, just return it from the table. */
4635 if (already_loaded
>= 0)
4636 f
->display
.x
->font
= FRAME_X_DISPLAY_INFO (f
)->font_table
[already_loaded
].font
;
4637 /* Otherwise, load the font and add it to the table. */
4645 /* Try to find a character-cell font in the list. */
4647 /* A laudable goal, but this isn't how to do it. */
4648 for (i
= 0; i
< n_matching_fonts
; i
++)
4649 if (! font_info
[i
].per_char
)
4655 /* See comment above. */
4656 if (n_matching_fonts
!= 0)
4657 fontname
= font_names
[i
];
4659 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
4662 /* Free the information from XListFonts. */
4663 if (n_matching_fonts
)
4664 XFreeFontNames (font_names
);
4668 /* Do we need to create the table? */
4669 if (FRAME_X_DISPLAY_INFO (f
)->font_table_size
== 0)
4671 FRAME_X_DISPLAY_INFO (f
)->font_table_size
= 16;
4672 FRAME_X_DISPLAY_INFO (f
)->font_table
4673 = (struct font_info
*) xmalloc (FRAME_X_DISPLAY_INFO (f
)->font_table_size
4674 * sizeof (struct font_info
));
4676 /* Do we need to grow the table? */
4677 else if (FRAME_X_DISPLAY_INFO (f
)->n_fonts
4678 >= FRAME_X_DISPLAY_INFO (f
)->font_table_size
)
4680 FRAME_X_DISPLAY_INFO (f
)->font_table_size
*= 2;
4681 FRAME_X_DISPLAY_INFO (f
)->font_table
4682 = (struct font_info
*) xrealloc (FRAME_X_DISPLAY_INFO (f
)->font_table
,
4683 (FRAME_X_DISPLAY_INFO (f
)->font_table_size
4684 * sizeof (struct font_info
)));
4687 /* Try to get the full name of FONT. Put it in full_name. */
4689 for (i
= 0; i
< font
->n_properties
; i
++)
4692 = XGetAtomName (FRAME_X_DISPLAY (f
), font
->properties
[i
].name
);
4693 if (!strcmp (atom
, "FONT"))
4695 char *name
= XGetAtomName (FRAME_X_DISPLAY (f
),
4696 (Atom
) (font
->properties
[i
].card32
));
4700 /* Count the number of dashes in the "full name".
4701 If it is too few, this isn't really the font's full name,
4703 In X11R4, the fonts did not come with their canonical names
4721 n_fonts
= FRAME_X_DISPLAY_INFO (f
)->n_fonts
;
4722 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
= (char *) xmalloc (strlen (fontname
) + 1);
4723 bcopy (fontname
, FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
, strlen (fontname
) + 1);
4725 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].full_name
= full_name
;
4727 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].full_name
= FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
;
4728 f
->display
.x
->font
= FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].font
= font
;
4729 FRAME_X_DISPLAY_INFO (f
)->n_fonts
++;
4732 fontname
= full_name
;
4735 /* Compute the scroll bar width in character columns. */
4736 if (f
->scroll_bar_pixel_width
> 0)
4738 int wid
= FONT_WIDTH (f
->display
.x
->font
);
4739 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
4742 f
->scroll_bar_cols
= 2;
4744 /* Now make the frame display the given font. */
4745 if (FRAME_X_WINDOW (f
) != 0)
4747 XSetFont (FRAME_X_DISPLAY (f
), f
->display
.x
->normal_gc
,
4748 f
->display
.x
->font
->fid
);
4749 XSetFont (FRAME_X_DISPLAY (f
), f
->display
.x
->reverse_gc
,
4750 f
->display
.x
->font
->fid
);
4751 XSetFont (FRAME_X_DISPLAY (f
), f
->display
.x
->cursor_gc
,
4752 f
->display
.x
->font
->fid
);
4754 frame_update_line_height (f
);
4755 x_set_window_size (f
, 0, f
->width
, f
->height
);
4758 /* If we are setting a new frame's font for the first time,
4759 there are no faces yet, so this font's height is the line height. */
4760 f
->display
.x
->line_height
= FONT_HEIGHT (f
->display
.x
->font
);
4763 Lisp_Object lispy_name
;
4765 lispy_name
= build_string (fontname
);
4767 /* Free the information from XListFonts. The data
4768 we actually retain comes from XLoadQueryFont. */
4769 XFreeFontNames (font_names
);
4775 x_calc_absolute_position (f
)
4779 int win_x
= 0, win_y
= 0;
4780 int flags
= f
->display
.x
->size_hint_flags
;
4783 #ifdef USE_X_TOOLKIT
4784 this_window
= XtWindow (f
->display
.x
->widget
);
4786 this_window
= FRAME_X_WINDOW (f
);
4789 /* Find the position of the outside upper-left corner of
4790 the inner window, with respect to the outer window. */
4791 if (f
->display
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
4794 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
4796 /* From-window, to-window. */
4798 f
->display
.x
->parent_desc
,
4800 /* From-position, to-position. */
4801 0, 0, &win_x
, &win_y
,
4808 /* Treat negative positions as relative to the leftmost bottommost
4809 position that fits on the screen. */
4810 if (flags
& XNegative
)
4811 f
->display
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
4812 - 2 * f
->display
.x
->border_width
- win_x
4814 + f
->display
.x
->left_pos
);
4816 if (flags
& YNegative
)
4817 f
->display
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
4818 - 2 * f
->display
.x
->border_width
- win_y
4820 - (FRAME_EXTERNAL_MENU_BAR (f
)
4821 ? f
->display
.x
->menubar_height
: 0)
4822 + f
->display
.x
->top_pos
);
4823 /* The left_pos and top_pos
4824 are now relative to the top and left screen edges,
4825 so the flags should correspond. */
4826 f
->display
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
4829 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
4830 to really change the position, and 0 when calling from
4831 x_make_frame_visible (in that case, XOFF and YOFF are the current
4832 position values). It is -1 when calling from x_set_frame_parameters,
4833 which means, do adjust for borders but don't change the gravity. */
4835 x_set_offset (f
, xoff
, yoff
, change_gravity
)
4837 register int xoff
, yoff
;
4840 int modified_top
, modified_left
;
4842 if (change_gravity
> 0)
4844 f
->display
.x
->top_pos
= yoff
;
4845 f
->display
.x
->left_pos
= xoff
;
4846 f
->display
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
4848 f
->display
.x
->size_hint_flags
|= XNegative
;
4850 f
->display
.x
->size_hint_flags
|= YNegative
;
4851 f
->display
.x
->win_gravity
= NorthWestGravity
;
4853 x_calc_absolute_position (f
);
4856 x_wm_set_size_hint (f
, (long) 0, 0);
4858 /* It is a mystery why we need to add the border_width here
4859 when the frame is already visible, but experiment says we do. */
4860 modified_left
= f
->display
.x
->left_pos
;
4861 modified_top
= f
->display
.x
->top_pos
;
4862 if (change_gravity
!= 0)
4864 modified_left
+= f
->display
.x
->border_width
;
4865 modified_top
+= f
->display
.x
->border_width
;
4868 #ifdef USE_X_TOOLKIT
4869 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
),
4870 modified_left
, modified_top
);
4871 #else /* not USE_X_TOOLKIT */
4872 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4873 modified_left
, modified_top
);
4874 #endif /* not USE_X_TOOLKIT */
4878 /* Call this to change the size of frame F's x-window.
4879 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
4880 for this size change and subsequent size changes.
4881 Otherwise we leave the window gravity unchanged. */
4883 x_set_window_size (f
, change_gravity
, cols
, rows
)
4888 int pixelwidth
, pixelheight
;
4891 #ifdef USE_X_TOOLKIT
4894 /* The x and y position of the widget is clobbered by the
4895 call to XtSetValues within EmacsFrameSetCharSize.
4896 This is a real kludge, but I don't understand Xt so I can't
4897 figure out a correct fix. Can anyone else tell me? -- rms. */
4898 int xpos
= f
->display
.x
->widget
->core
.x
;
4899 int ypos
= f
->display
.x
->widget
->core
.y
;
4900 EmacsFrameSetCharSize (f
->display
.x
->edit_widget
, cols
, rows
);
4901 f
->display
.x
->widget
->core
.x
= xpos
;
4902 f
->display
.x
->widget
->core
.y
= ypos
;
4906 #else /* not USE_X_TOOLKIT */
4910 check_frame_size (f
, &rows
, &cols
);
4911 f
->display
.x
->vertical_scroll_bar_extra
4912 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4914 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
4915 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
4916 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->display
.x
->font
)));
4917 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
4918 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
4920 f
->display
.x
->win_gravity
= NorthWestGravity
;
4921 x_wm_set_size_hint (f
, (long) 0, 0);
4923 XSync (FRAME_X_DISPLAY (f
), False
);
4924 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4925 pixelwidth
, pixelheight
);
4927 /* Now, strictly speaking, we can't be sure that this is accurate,
4928 but the window manager will get around to dealing with the size
4929 change request eventually, and we'll hear how it went when the
4930 ConfigureNotify event gets here.
4932 We could just not bother storing any of this information here,
4933 and let the ConfigureNotify event set everything up, but that
4934 might be kind of confusing to the lisp code, since size changes
4935 wouldn't be reported in the frame parameters until some random
4936 point in the future when the ConfigureNotify event arrives. */
4937 change_frame_size (f
, rows
, cols
, 0, 0);
4938 PIXEL_WIDTH (f
) = pixelwidth
;
4939 PIXEL_HEIGHT (f
) = pixelheight
;
4941 /* If cursor was outside the new size, mark it as off. */
4942 if (f
->phys_cursor_y
>= rows
4943 || f
->phys_cursor_x
>= cols
)
4945 f
->phys_cursor_x
= -1;
4946 f
->phys_cursor_y
= -1;
4949 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
4950 receive in the ConfigureNotify event; if we get what we asked
4951 for, then the event won't cause the screen to become garbaged, so
4952 we have to make sure to do it here. */
4953 SET_FRAME_GARBAGED (f
);
4955 XFlush (FRAME_X_DISPLAY (f
));
4957 #endif /* not USE_X_TOOLKIT */
4960 /* Mouse warping. */
4963 x_set_mouse_position (f
, x
, y
)
4969 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->display
.x
->font
) / 2;
4970 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->display
.x
->line_height
/ 2;
4972 if (pix_x
< 0) pix_x
= 0;
4973 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
4975 if (pix_y
< 0) pix_y
= 0;
4976 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
4980 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
4981 0, 0, 0, 0, pix_x
, pix_y
);
4985 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
4988 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
4994 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
4995 0, 0, 0, 0, pix_x
, pix_y
);
4999 /* focus shifting, raising and lowering. */
5001 x_focus_on_frame (f
)
5004 #if 0 /* This proves to be unpleasant. */
5008 /* I don't think that the ICCCM allows programs to do things like this
5009 without the interaction of the window manager. Whatever you end up
5010 doing with this code, do it to x_unfocus_frame too. */
5011 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5012 RevertToPointerRoot
, CurrentTime
);
5020 /* Look at the remarks in x_focus_on_frame. */
5021 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
5022 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
5023 RevertToPointerRoot
, CurrentTime
);
5027 /* Raise frame F. */
5032 if (f
->async_visible
)
5035 #ifdef USE_X_TOOLKIT
5036 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
));
5037 #else /* not USE_X_TOOLKIT */
5038 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5039 #endif /* not USE_X_TOOLKIT */
5040 XFlush (FRAME_X_DISPLAY (f
));
5045 /* Lower frame F. */
5050 if (f
->async_visible
)
5053 #ifdef USE_X_TOOLKIT
5054 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
));
5055 #else /* not USE_X_TOOLKIT */
5056 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5057 #endif /* not USE_X_TOOLKIT */
5058 XFlush (FRAME_X_DISPLAY (f
));
5064 XTframe_raise_lower (f
, raise
)
5074 /* Change of visibility. */
5076 x_make_frame_visible (f
)
5084 type
= x_icon_type (f
);
5086 x_bitmap_icon (f
, type
);
5088 if (! FRAME_VISIBLE_P (f
))
5090 if (! FRAME_ICONIFIED_P (f
))
5091 x_set_offset (f
, f
->display
.x
->left_pos
, f
->display
.x
->top_pos
, 0);
5093 if (! EQ (Vx_no_window_manager
, Qt
))
5094 x_wm_set_window_state (f
, NormalState
);
5095 #ifdef USE_X_TOOLKIT
5096 /* This was XtPopup, but that did nothing for an iconified frame. */
5097 XtMapWidget (f
->display
.x
->widget
);
5098 #else /* not USE_X_TOOLKIT */
5099 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5100 #endif /* not USE_X_TOOLKIT */
5101 #if 0 /* This seems to bring back scroll bars in the wrong places
5102 if the window configuration has changed. They seem
5103 to come back ok without this. */
5104 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5105 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5109 XFlush (FRAME_X_DISPLAY (f
));
5111 /* Synchronize to ensure Emacs knows the frame is visible
5112 before we do anything else. We do this loop with input not blocked
5113 so that incoming events are handled. */
5116 int count
= input_signal_count
;
5118 /* This must come after we set COUNT. */
5121 XSETFRAME (frame
, f
);
5126 /* Once we have handled input events,
5127 we should have received the MapNotify if one is coming.
5128 So if we have not got it yet, stop looping.
5129 Some window managers make their own decisions
5130 about visibility. */
5131 if (input_signal_count
!= count
)
5133 /* Machines that do polling rather than SIGIO have been observed
5134 to go into a busy-wait here. So we'll fake an alarm signal
5135 to let the handler know that there's something to be read.
5136 We used to raise a real alarm, but it seems that the handler
5137 isn't always enabled here. This is probably a bug. */
5138 if (input_polling_used ())
5140 /* It could be confusing if a real alarm arrives while processing
5141 the fake one. Turn it off and let the handler reset it. */
5143 input_poll_signal ();
5145 /* Once we have handled input events,
5146 we should have received the MapNotify if one is coming.
5147 So if we have not got it yet, stop looping.
5148 Some window managers make their own decisions
5149 about visibility. */
5150 if (input_signal_count
!= count
)
5153 FRAME_SAMPLE_VISIBILITY (f
);
5157 /* Change from mapped state to withdrawn state. */
5159 /* Make the frame visible (mapped and not iconified). */
5161 x_make_frame_invisible (f
)
5167 #ifdef USE_X_TOOLKIT
5168 /* Use the frame's outermost window, not the one we normally draw on. */
5169 window
= XtWindow (f
->display
.x
->widget
);
5170 #else /* not USE_X_TOOLKIT */
5171 window
= FRAME_X_WINDOW (f
);
5172 #endif /* not USE_X_TOOLKIT */
5174 /* Don't keep the highlight on an invisible frame. */
5175 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5176 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5178 #if 0/* This might add unreliability; I don't trust it -- rms. */
5179 if (! f
->async_visible
&& ! f
->async_iconified
)
5185 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5186 that the current position of the window is user-specified, rather than
5187 program-specified, so that when the window is mapped again, it will be
5188 placed at the same location, without forcing the user to position it
5189 by hand again (they have already done that once for this window.) */
5190 x_wm_set_size_hint (f
, (long) 0, 1);
5194 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
5195 DefaultScreen (FRAME_X_DISPLAY (f
))))
5197 UNBLOCK_INPUT_RESIGNAL
;
5198 error ("Can't notify window manager of window withdrawal");
5200 #else /* ! defined (HAVE_X11R4) */
5202 /* Tell the window manager what we're going to do. */
5203 if (! EQ (Vx_no_window_manager
, Qt
))
5207 unmap
.xunmap
.type
= UnmapNotify
;
5208 unmap
.xunmap
.window
= window
;
5209 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
5210 unmap
.xunmap
.from_configure
= False
;
5211 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5212 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5214 SubstructureRedirectMask
|SubstructureNotifyMask
,
5217 UNBLOCK_INPUT_RESIGNAL
;
5218 error ("Can't notify window manager of withdrawal");
5222 /* Unmap the window ourselves. Cheeky! */
5223 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
5224 #endif /* ! defined (HAVE_X11R4) */
5226 /* We can't distinguish this from iconification
5227 just by the event that we get from the server.
5228 So we can't win using the usual strategy of letting
5229 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5230 and synchronize with the server to make sure we agree. */
5232 FRAME_ICONIFIED_P (f
) = 0;
5233 f
->async_visible
= 0;
5234 f
->async_iconified
= 0;
5241 /* Change window state from mapped to iconified. */
5250 /* Don't keep the highlight on an invisible frame. */
5251 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5252 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5254 if (f
->async_iconified
)
5259 type
= x_icon_type (f
);
5261 x_bitmap_icon (f
, type
);
5263 #ifdef USE_X_TOOLKIT
5265 if (! FRAME_VISIBLE_P (f
))
5267 if (! EQ (Vx_no_window_manager
, Qt
))
5268 x_wm_set_window_state (f
, IconicState
);
5269 /* This was XtPopup, but that did nothing for an iconified frame. */
5270 XtMapWidget (f
->display
.x
->widget
);
5275 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
5276 XtWindow (f
->display
.x
->widget
),
5277 DefaultScreen (FRAME_X_DISPLAY (f
)));
5281 error ("Can't notify window manager of iconification");
5283 f
->async_iconified
= 1;
5286 XFlush (FRAME_X_DISPLAY (f
));
5288 #else /* not USE_X_TOOLKIT */
5290 /* Make sure the X server knows where the window should be positioned,
5291 in case the user deiconifies with the window manager. */
5292 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
5293 x_set_offset (f
, f
->display
.x
->left_pos
, f
->display
.x
->top_pos
, 0);
5295 /* Since we don't know which revision of X we're running, we'll use both
5296 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
5298 /* X11R4: send a ClientMessage to the window manager using the
5299 WM_CHANGE_STATE type. */
5303 message
.xclient
.window
= FRAME_X_WINDOW (f
);
5304 message
.xclient
.type
= ClientMessage
;
5305 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
5306 message
.xclient
.format
= 32;
5307 message
.xclient
.data
.l
[0] = IconicState
;
5309 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5310 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5312 SubstructureRedirectMask
| SubstructureNotifyMask
,
5315 UNBLOCK_INPUT_RESIGNAL
;
5316 error ("Can't notify window manager of iconification");
5320 /* X11R3: set the initial_state field of the window manager hints to
5322 x_wm_set_window_state (f
, IconicState
);
5324 if (!FRAME_VISIBLE_P (f
))
5326 /* If the frame was withdrawn, before, we must map it. */
5327 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5330 f
->async_iconified
= 1;
5332 XFlush (FRAME_X_DISPLAY (f
));
5334 #endif /* not USE_X_TOOLKIT */
5337 /* Destroy the X window of frame F. */
5339 x_destroy_window (f
)
5342 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5346 if (f
->display
.x
->icon_desc
!= 0)
5347 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->display
.x
->icon_desc
);
5348 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->display
.x
->window_desc
);
5349 #ifdef USE_X_TOOLKIT
5350 XtDestroyWidget (f
->display
.x
->widget
);
5351 free_frame_menubar (f
);
5352 #endif /* USE_X_TOOLKIT */
5354 free_frame_faces (f
);
5355 XFlush (FRAME_X_DISPLAY (f
));
5357 xfree (f
->display
.x
);
5359 if (f
== dpyinfo
->x_focus_frame
)
5360 dpyinfo
->x_focus_frame
= 0;
5361 if (f
== dpyinfo
->x_focus_event_frame
)
5362 dpyinfo
->x_focus_event_frame
= 0;
5363 if (f
== dpyinfo
->x_highlight_frame
)
5364 dpyinfo
->x_highlight_frame
= 0;
5366 dpyinfo
->reference_count
--;
5368 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5370 dpyinfo
->mouse_face_beg_row
5371 = dpyinfo
->mouse_face_beg_col
= -1;
5372 dpyinfo
->mouse_face_end_row
5373 = dpyinfo
->mouse_face_end_col
= -1;
5374 dpyinfo
->mouse_face_window
= Qnil
;
5380 /* Setting window manager hints. */
5382 /* Set the normal size hints for the window manager, for frame F.
5383 FLAGS is the flags word to use--or 0 meaning preserve the flags
5384 that the window now has.
5385 If USER_POSITION is nonzero, we set the USPosition
5386 flag (this is useful when FLAGS is 0). */
5388 x_wm_set_size_hint (f
, flags
, user_position
)
5393 XSizeHints size_hints
;
5395 #ifdef USE_X_TOOLKIT
5398 Dimension widget_width
, widget_height
;
5399 Window window
= XtWindow (f
->display
.x
->widget
);
5400 #else /* not USE_X_TOOLKIT */
5401 Window window
= FRAME_X_WINDOW (f
);
5402 #endif /* not USE_X_TOOLKIT */
5404 /* Setting PMaxSize caused various problems. */
5405 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
5407 flexlines
= f
->height
;
5409 size_hints
.x
= f
->display
.x
->left_pos
;
5410 size_hints
.y
= f
->display
.x
->top_pos
;
5412 #ifdef USE_X_TOOLKIT
5413 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
5414 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
5415 XtGetValues (f
->display
.x
->widget
, al
, ac
);
5416 size_hints
.height
= widget_height
;
5417 size_hints
.width
= widget_width
;
5418 #else /* not USE_X_TOOLKIT */
5419 size_hints
.height
= PIXEL_HEIGHT (f
);
5420 size_hints
.width
= PIXEL_WIDTH (f
);
5421 #endif /* not USE_X_TOOLKIT */
5423 size_hints
.width_inc
= FONT_WIDTH (f
->display
.x
->font
);
5424 size_hints
.height_inc
= f
->display
.x
->line_height
;
5425 size_hints
.max_width
5426 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
5427 size_hints
.max_height
5428 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
5430 /* Calculate the base and minimum sizes.
5432 (When we use the X toolkit, we don't do it here.
5433 Instead we copy the values that the widgets are using, below.) */
5434 #ifndef USE_X_TOOLKIT
5436 int base_width
, base_height
;
5437 int min_rows
= 0, min_cols
= 0;
5439 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
5440 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
5442 check_frame_size (f
, &min_rows
, &min_cols
);
5444 /* The window manager uses the base width hints to calculate the
5445 current number of rows and columns in the frame while
5446 resizing; min_width and min_height aren't useful for this
5447 purpose, since they might not give the dimensions for a
5448 zero-row, zero-column frame.
5450 We use the base_width and base_height members if we have
5451 them; otherwise, we set the min_width and min_height members
5452 to the size for a zero x zero frame. */
5455 size_hints
.flags
|= PBaseSize
;
5456 size_hints
.base_width
= base_width
;
5457 size_hints
.base_height
= base_height
;
5458 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
5459 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
5461 size_hints
.min_width
= base_width
;
5462 size_hints
.min_height
= base_height
;
5466 /* If we don't need the old flags, we don't need the old hint at all. */
5469 size_hints
.flags
|= flags
;
5472 #endif /* not USE_X_TOOLKIT */
5475 XSizeHints hints
; /* Sometimes I hate X Windows... */
5476 long supplied_return
;
5480 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
5483 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
5486 #ifdef USE_X_TOOLKIT
5487 size_hints
.base_height
= hints
.base_height
;
5488 size_hints
.base_width
= hints
.base_width
;
5489 size_hints
.min_height
= hints
.min_height
;
5490 size_hints
.min_width
= hints
.min_width
;
5494 size_hints
.flags
|= flags
;
5499 if (hints
.flags
& PSize
)
5500 size_hints
.flags
|= PSize
;
5501 if (hints
.flags
& PPosition
)
5502 size_hints
.flags
|= PPosition
;
5503 if (hints
.flags
& USPosition
)
5504 size_hints
.flags
|= USPosition
;
5505 if (hints
.flags
& USSize
)
5506 size_hints
.flags
|= USSize
;
5513 size_hints
.win_gravity
= f
->display
.x
->win_gravity
;
5514 size_hints
.flags
|= PWinGravity
;
5518 size_hints
.flags
&= ~ PPosition
;
5519 size_hints
.flags
|= USPosition
;
5521 #endif /* PWinGravity */
5524 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
5526 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
5530 /* Used for IconicState or NormalState */
5531 x_wm_set_window_state (f
, state
)
5535 #ifdef USE_X_TOOLKIT
5538 XtSetArg (al
[0], XtNinitialState
, state
);
5539 XtSetValues (f
->display
.x
->widget
, al
, 1);
5540 #else /* not USE_X_TOOLKIT */
5541 Window window
= FRAME_X_WINDOW (f
);
5543 f
->display
.x
->wm_hints
.flags
|= StateHint
;
5544 f
->display
.x
->wm_hints
.initial_state
= state
;
5546 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
5547 #endif /* not USE_X_TOOLKIT */
5550 x_wm_set_icon_pixmap (f
, pixmap_id
)
5554 #ifdef USE_X_TOOLKIT
5555 Window window
= XtWindow (f
->display
.x
->widget
);
5557 Window window
= FRAME_X_WINDOW (f
);
5562 Pixmap icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
5563 f
->display
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
5566 f
->display
.x
->wm_hints
.icon_pixmap
= None
;
5568 f
->display
.x
->wm_hints
.flags
|= IconPixmapHint
;
5569 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
5572 x_wm_set_icon_position (f
, icon_x
, icon_y
)
5576 #ifdef USE_X_TOOLKIT
5577 Window window
= XtWindow (f
->display
.x
->widget
);
5579 Window window
= FRAME_X_WINDOW (f
);
5582 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
5583 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
5584 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
5586 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
5590 /* Initialization. */
5592 #ifdef USE_X_TOOLKIT
5593 static XrmOptionDescRec emacs_options
[] = {
5594 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
5595 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
5597 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
5598 XrmoptionSepArg
, NULL
},
5599 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
5601 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5602 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5603 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5604 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5605 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5606 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
5607 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
5609 #endif /* USE_X_TOOLKIT */
5611 static int x_initialized
;
5614 /* Test whether two display-name strings agree up to the dot that separates
5615 the screen number from the server number. */
5617 same_x_server (name1
, name2
)
5618 char *name1
, *name2
;
5621 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
5625 if (seen_colon
&& *name1
== '.')
5629 && (*name1
== '.' || *name1
== '\0')
5630 && (*name2
== '.' || *name2
== '\0'));
5634 struct x_display_info
*
5635 x_term_init (display_name
, xrm_option
, resource_name
)
5636 Lisp_Object display_name
;
5638 char *resource_name
;
5644 struct x_display_info
*dpyinfo
;
5655 #ifdef USE_X_TOOLKIT
5656 /* weiner@footloose.sps.mot.com reports that this causes
5658 X protocol error: BadAtom (invalid Atom parameter)
5659 on protocol request 18skiloaf.
5660 So let's not use it until R6. */
5662 XtSetLanguageProc (NULL
, NULL
, NULL
);
5673 argv
[argc
++] = "-xrm";
5674 argv
[argc
++] = xrm_option
;
5676 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
5677 resource_name
, EMACS_CLASS
,
5678 emacs_options
, XtNumber (emacs_options
),
5682 #else /* not USE_X_TOOLKIT */
5684 XSetLocaleModifiers ("");
5686 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
5687 #endif /* not USE_X_TOOLKIT */
5689 /* Detect failure. */
5696 /* We have definitely succeeded. Record the new connection. */
5698 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
5702 struct x_display_info
*share
;
5705 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
5706 share
= share
->next
, tail
= XCONS (tail
)->cdr
)
5707 if (same_x_server (XSTRING (XCONS (XCONS (tail
)->car
)->car
)->data
,
5708 XSTRING (display_name
)->data
))
5711 dpyinfo
->kboard
= share
->kboard
;
5714 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
5715 init_kboard (dpyinfo
->kboard
);
5716 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
5718 char *vendor
= ServerVendor (dpy
);
5719 dpyinfo
->kboard
->Vsystem_key_alist
5720 = call1 (Qvendor_specific_keysyms
,
5721 build_string (vendor
? vendor
: ""));
5724 dpyinfo
->kboard
->next_kboard
= all_kboards
;
5725 all_kboards
= dpyinfo
->kboard
;
5726 /* Don't let the initial kboard remain current longer than necessary.
5727 That would cause problems if a file loaded on startup tries to
5728 prompt in the minibuffer. */
5729 if (current_kboard
== initial_kboard
)
5730 current_kboard
= dpyinfo
->kboard
;
5732 dpyinfo
->kboard
->reference_count
++;
5736 /* Put this display on the chain. */
5737 dpyinfo
->next
= x_display_list
;
5738 x_display_list
= dpyinfo
;
5740 /* Put it on x_display_name_list as well, to keep them parallel. */
5741 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
5742 x_display_name_list
);
5743 dpyinfo
->name_list_element
= XCONS (x_display_name_list
)->car
;
5745 dpyinfo
->display
= dpy
;
5748 XSetAfterFunction (x_current_display
, x_trace_wire
);
5752 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
5753 + XSTRING (Vsystem_name
)->size
5755 sprintf (dpyinfo
->x_id_name
, "%s@%s",
5756 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
5758 /* Figure out which modifier bits mean what. */
5759 x_find_modifier_meanings (dpyinfo
);
5761 /* Get the scroll bar cursor. */
5762 dpyinfo
->vertical_scroll_bar_cursor
5763 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
5765 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
5766 resource_name
, EMACS_CLASS
);
5767 #ifdef HAVE_XRMSETDATABASE
5768 XrmSetDatabase (dpyinfo
->display
, xrdb
);
5770 dpyinfo
->display
->db
= xrdb
;
5772 /* Put the rdb where we can find it in a way that works on
5774 dpyinfo
->xrdb
= xrdb
;
5776 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
5777 DefaultScreen (dpyinfo
->display
));
5778 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
5779 &dpyinfo
->n_planes
);
5780 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
5781 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
5782 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
5783 dpyinfo
->grabbed
= 0;
5784 dpyinfo
->reference_count
= 0;
5785 dpyinfo
->icon_bitmap_id
= -1;
5786 dpyinfo
->n_fonts
= 0;
5787 dpyinfo
->font_table_size
= 0;
5788 dpyinfo
->bitmaps
= 0;
5789 dpyinfo
->bitmaps_size
= 0;
5790 dpyinfo
->bitmaps_last
= 0;
5791 dpyinfo
->scratch_cursor_gc
= 0;
5792 dpyinfo
->mouse_face_mouse_frame
= 0;
5793 dpyinfo
->mouse_face_deferred_gc
= 0;
5794 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
5795 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
5796 dpyinfo
->mouse_face_face_id
= 0;
5797 dpyinfo
->mouse_face_window
= Qnil
;
5798 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
5799 dpyinfo
->mouse_face_defer
= 0;
5800 dpyinfo
->x_focus_frame
= 0;
5801 dpyinfo
->x_focus_event_frame
= 0;
5802 dpyinfo
->x_highlight_frame
= 0;
5804 dpyinfo
->Xatom_wm_protocols
5805 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
5806 dpyinfo
->Xatom_wm_take_focus
5807 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
5808 dpyinfo
->Xatom_wm_save_yourself
5809 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
5810 dpyinfo
->Xatom_wm_delete_window
5811 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
5812 dpyinfo
->Xatom_wm_change_state
5813 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
5814 dpyinfo
->Xatom_wm_configure_denied
5815 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
5816 dpyinfo
->Xatom_wm_window_moved
5817 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
5818 dpyinfo
->Xatom_editres
5819 = XInternAtom (dpyinfo
->display
, "Editres", False
);
5820 dpyinfo
->Xatom_CLIPBOARD
5821 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
5822 dpyinfo
->Xatom_TIMESTAMP
5823 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
5825 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
5826 dpyinfo
->Xatom_DELETE
5827 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
5828 dpyinfo
->Xatom_MULTIPLE
5829 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
5831 = XInternAtom (dpyinfo
->display
, "INCR", False
);
5832 dpyinfo
->Xatom_EMACS_TMP
5833 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
5834 dpyinfo
->Xatom_TARGETS
5835 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
5837 = XInternAtom (dpyinfo
->display
, "NULL", False
);
5838 dpyinfo
->Xatom_ATOM_PAIR
5839 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
5841 dpyinfo
->cut_buffers_initialized
= 0;
5843 connection
= ConnectionNumber (dpyinfo
->display
);
5844 dpyinfo
->connection
= connection
;
5847 /* This is only needed for distinguishing keyboard and process input. */
5848 if (connection
!= 0)
5849 add_keyboard_wait_descriptor (connection
);
5852 #ifndef F_SETOWN_BUG
5854 #ifdef F_SETOWN_SOCK_NEG
5855 /* stdin is a socket here */
5856 fcntl (connection
, F_SETOWN
, -getpid ());
5857 #else /* ! defined (F_SETOWN_SOCK_NEG) */
5858 fcntl (connection
, F_SETOWN
, getpid ());
5859 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
5860 #endif /* ! defined (F_SETOWN) */
5861 #endif /* F_SETOWN_BUG */
5864 if (interrupt_input
)
5865 init_sigio (connection
);
5866 #endif /* ! defined (SIGIO) */
5873 /* Get rid of display DPYINFO, assuming all frames are already gone,
5874 and without sending any more commands to the X server. */
5877 x_delete_display (dpyinfo
)
5878 struct x_display_info
*dpyinfo
;
5880 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
5882 /* Discard this display from x_display_name_list and x_display_list.
5883 We can't use Fdelq because that can quit. */
5884 if (! NILP (x_display_name_list
)
5885 && EQ (XCONS (x_display_name_list
)->car
, dpyinfo
->name_list_element
))
5886 x_display_name_list
= XCONS (x_display_name_list
)->cdr
;
5891 tail
= x_display_name_list
;
5892 while (CONSP (tail
) && CONSP (XCONS (tail
)->cdr
))
5894 if (EQ (XCONS (XCONS (tail
)->cdr
)->car
,
5895 dpyinfo
->name_list_element
))
5897 XCONS (tail
)->cdr
= XCONS (XCONS (tail
)->cdr
)->cdr
;
5900 tail
= XCONS (tail
)->cdr
;
5904 if (x_display_list
== dpyinfo
)
5905 x_display_list
= dpyinfo
->next
;
5908 struct x_display_info
*tail
;
5910 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
5911 if (tail
->next
== dpyinfo
)
5912 tail
->next
= tail
->next
->next
;
5915 #ifndef USE_X_TOOLKIT
5916 /* I'm told Xt does this itself. */
5917 XrmDestroyDatabase (dpyinfo
->xrdb
);
5920 if (--dpyinfo
->kboard
->reference_count
== 0)
5921 delete_kboard (dpyinfo
->kboard
);
5923 xfree (dpyinfo
->font_table
);
5924 xfree (dpyinfo
->x_id_name
);
5928 /* Set up use of X before we make the first connection. */
5932 clear_frame_hook
= XTclear_frame
;
5933 clear_end_of_line_hook
= XTclear_end_of_line
;
5934 ins_del_lines_hook
= XTins_del_lines
;
5935 change_line_highlight_hook
= XTchange_line_highlight
;
5936 insert_glyphs_hook
= XTinsert_glyphs
;
5937 write_glyphs_hook
= XTwrite_glyphs
;
5938 delete_glyphs_hook
= XTdelete_glyphs
;
5939 ring_bell_hook
= XTring_bell
;
5940 reset_terminal_modes_hook
= XTreset_terminal_modes
;
5941 set_terminal_modes_hook
= XTset_terminal_modes
;
5942 update_begin_hook
= XTupdate_begin
;
5943 update_end_hook
= XTupdate_end
;
5944 set_terminal_window_hook
= XTset_terminal_window
;
5945 read_socket_hook
= XTread_socket
;
5946 frame_up_to_date_hook
= XTframe_up_to_date
;
5947 cursor_to_hook
= XTcursor_to
;
5948 reassert_line_highlight_hook
= XTreassert_line_highlight
;
5949 mouse_position_hook
= XTmouse_position
;
5950 frame_rehighlight_hook
= XTframe_rehighlight
;
5951 frame_raise_lower_hook
= XTframe_raise_lower
;
5952 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
5953 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
5954 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
5955 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
5957 scroll_region_ok
= 1; /* we'll scroll partial frames */
5958 char_ins_del_ok
= 0; /* just as fast to write the line */
5959 line_ins_del_ok
= 1; /* we'll just blt 'em */
5960 fast_clear_end_of_line
= 1; /* X does this well */
5961 memory_below_frame
= 0; /* we don't remember what scrolls
5967 /* Try to use interrupt input; if we can't, then start polling. */
5968 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
5970 #ifdef USE_X_TOOLKIT
5971 XtToolkitInitialize ();
5972 Xt_app_con
= XtCreateApplicationContext ();
5975 /* Note that there is no real way portable across R3/R4 to get the
5976 original error handler. */
5977 XSetErrorHandler (x_error_quitter
);
5978 XSetIOErrorHandler (x_io_error_quitter
);
5980 /* Disable Window Change signals; they are handled by X events. */
5982 signal (SIGWINCH
, SIG_DFL
);
5983 #endif /* ! defined (SIGWINCH) */
5985 signal (SIGPIPE
, x_connection_signal
);
5991 staticpro (&x_display_name_list
);
5992 x_display_name_list
= Qnil
;
5994 staticpro (&last_mouse_scroll_bar
);
5995 last_mouse_scroll_bar
= Qnil
;
5997 staticpro (&Qvendor_specific_keysyms
);
5998 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
6000 #endif /* ! defined (HAVE_X_WINDOWS) */