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"
104 /* So we can do setlocale. */
108 #define min(a,b) ((a)<(b) ? (a) : (b))
109 #define max(a,b) ((a)>(b) ? (a) : (b))
111 /* This is a chain of structures for all the X displays currently in use. */
112 struct x_display_info
*x_display_list
;
114 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
115 one for each element of x_display_list and in the same order.
116 NAME is the name of the frame.
117 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
118 Lisp_Object x_display_name_list
;
120 /* Frame being updated by update_frame. This is declared in term.c.
121 This is set by update_begin and looked at by all the
122 XT functions. It is zero while not inside an update.
123 In that case, the XT functions assume that `selected_frame'
124 is the frame to apply to. */
125 extern struct frame
*updating_frame
;
127 /* This is a frame waiting to be autoraised, within XTread_socket. */
128 struct frame
*pending_autoraise_frame
;
131 /* The application context for Xt use. */
132 XtAppContext Xt_app_con
;
134 static String Xt_default_resources
[] =
140 /* During an update, maximum vpos for ins/del line operations to affect. */
142 static int flexlines
;
144 /* During an update, nonzero if chars output now should be highlighted. */
146 static int highlight
;
148 /* Nominal cursor position -- where to draw output.
149 During an update, these are different from the cursor-box position. */
156 In order to avoid asking for motion events and then throwing most
157 of them away or busy-polling the server for mouse positions, we ask
158 the server for pointer motion hints. This means that we get only
159 one event per group of mouse movements. "Groups" are delimited by
160 other kinds of events (focus changes and button clicks, for
161 example), or by XQueryPointer calls; when one of these happens, we
162 get another MotionNotify event the next time the mouse moves. This
163 is at least as efficient as getting motion events when mouse
164 tracking is on, and I suspect only negligibly worse when tracking
167 The silly O'Reilly & Associates Nutshell guides barely document
168 pointer motion hints at all (I think you have to infer how they
169 work from an example), and the description of XQueryPointer doesn't
170 mention that calling it causes you to get another motion hint from
171 the server, which is very important. */
173 /* Where the mouse was last time we reported a mouse event. */
174 static FRAME_PTR last_mouse_frame
;
175 static XRectangle last_mouse_glyph
;
177 /* The scroll bar in which the last X motion event occurred.
179 If the last X motion event occurred in a scroll bar, we set this
180 so XTmouse_position can know whether to report a scroll bar motion or
183 If the last X motion event didn't occur in a scroll bar, we set this
184 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
185 static Lisp_Object last_mouse_scroll_bar
;
187 /* This is a hack. We would really prefer that XTmouse_position would
188 return the time associated with the position it returns, but there
189 doesn't seem to be any way to wrest the timestamp from the server
190 along with the position query. So, we just keep track of the time
191 of the last movement we received, and return that in hopes that
192 it's somewhat accurate. */
193 static Time last_mouse_movement_time
;
195 /* Incremented by XTread_socket whenever it really tries to read events. */
197 static int volatile input_signal_count
;
199 static int input_signal_count
;
202 /* Used locally within XTread_socket. */
203 static int x_noop_count
;
205 /* Initial values of argv and argc. */
206 extern char **initial_argv
;
207 extern int initial_argc
;
209 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
211 /* Tells if a window manager is present or not. */
213 extern Lisp_Object Vx_no_window_manager
;
215 /* Nonzero enables some debugging for the X interface code. */
218 extern Lisp_Object Qface
, Qmouse_face
;
222 /* A mask of extra modifier bits to put into every keyboard char. */
223 extern int extra_keyboard_modifiers
;
225 static Lisp_Object Qvendor_specific_keysyms
;
227 extern XrmDatabase
x_load_resources ();
229 extern Lisp_Object
x_icon_type ();
231 void x_delete_display ();
233 static void redraw_previous_char ();
234 static void redraw_following_char ();
235 static unsigned int x_x_to_emacs_modifiers ();
237 static int fast_find_position ();
238 static void note_mouse_highlight ();
239 static void clear_mouse_face ();
240 static void show_mouse_face ();
241 static void do_line_dance ();
243 static int XTcursor_to ();
244 static int XTclear_end_of_line ();
245 static int x_io_error_quitter ();
246 void x_catch_errors ();
247 void x_uncatch_errors ();
250 /* This is a function useful for recording debugging information
251 about the sequence of occurrences in this file. */
259 struct record event_record
[100];
261 int event_record_index
;
263 record_event (locus
, type
)
267 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
268 event_record_index
= 0;
270 event_record
[event_record_index
].locus
= locus
;
271 event_record
[event_record_index
].type
= type
;
272 event_record_index
++;
277 /* Return the struct x_display_info corresponding to DPY. */
279 struct x_display_info
*
280 x_display_info_for_display (dpy
)
283 struct x_display_info
*dpyinfo
;
285 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
286 if (dpyinfo
->display
== dpy
)
292 /* Starting and ending updates.
294 These hooks are called by update_frame at the beginning and end
295 of a frame update. We record in `updating_frame' the identity
296 of the frame being updated, so that the XT... functions do not
297 need to take a frame as argument. Most of the XT... functions
298 should never be called except during an update, the only exceptions
299 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
310 flexlines
= f
->height
;
315 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
317 /* Don't do highlighting for mouse motion during the update. */
318 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 1;
320 /* If the frame needs to be redrawn,
321 simply forget about any prior mouse highlighting. */
322 if (FRAME_GARBAGED_P (f
))
323 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= Qnil
;
325 if (!NILP (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
327 int firstline
, lastline
, i
;
328 struct window
*w
= XWINDOW (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
);
330 /* Find the first, and the last+1, lines affected by redisplay. */
331 for (firstline
= 0; firstline
< f
->height
; firstline
++)
332 if (FRAME_DESIRED_GLYPHS (f
)->enable
[firstline
])
335 lastline
= f
->height
;
336 for (i
= f
->height
- 1; i
>= 0; i
--)
338 if (FRAME_DESIRED_GLYPHS (f
)->enable
[i
])
344 /* Can we tell that this update does not affect the window
345 where the mouse highlight is? If so, no need to turn off.
346 Likewise, don't do anything if the frame is garbaged;
347 in that case, the FRAME_CURRENT_GLYPHS that we would use
348 are all wrong, and we will redisplay that line anyway. */
349 if (! (firstline
> (XFASTINT (w
->top
) + window_internal_height (w
))
350 || lastline
< XFASTINT (w
->top
)))
351 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
367 x_display_cursor (f
, 1);
369 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
370 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
372 /* This fails in the case of having updated only the echo area
373 if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS
374 has no relation to the current contents, and its charstarts
375 have no relation to the contents of the window-buffer.
376 I don't know a clean way to check
377 for that case. window_end_valid isn't set up yet. */
378 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
379 note_mouse_highlight (f
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
380 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
383 XFlush (FRAME_X_DISPLAY (f
));
387 /* This is called after a redisplay on frame F. */
390 XTframe_up_to_date (f
)
393 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
394 || f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
396 note_mouse_highlight (FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
,
397 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
398 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
399 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 0;
403 /* External interface to control of standout mode.
404 Call this when about to modify line at position VPOS
405 and not change whether it is highlighted. */
407 XTreassert_line_highlight (new, vpos
)
413 /* Call this when about to modify line at position VPOS
414 and change whether it is highlighted. */
417 XTchange_line_highlight (new_highlight
, vpos
, first_unused_hpos
)
418 int new_highlight
, vpos
, first_unused_hpos
;
420 highlight
= new_highlight
;
421 XTcursor_to (vpos
, 0);
422 XTclear_end_of_line (updating_frame
->width
);
425 /* This is used when starting Emacs and when restarting after suspend.
426 When starting Emacs, no X window is mapped. And nothing must be done
427 to Emacs's own window if it is suspended (though that rarely happens). */
430 XTset_terminal_modes ()
434 /* This is called when exiting or suspending Emacs.
435 Exiting will make the X-windows go away, and suspending
436 requires no action. */
439 XTreset_terminal_modes ()
441 /* XTclear_frame (); */
444 /* Set the nominal cursor position of the frame.
445 This is where display update commands will take effect.
446 This does not affect the place where the cursor-box is displayed. */
449 XTcursor_to (row
, col
)
450 register int row
, col
;
458 if (updating_frame
== 0)
461 x_display_cursor (selected_frame
, 1);
462 XFlush (FRAME_X_DISPLAY (selected_frame
));
467 /* Display a sequence of N glyphs found at GP.
468 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
469 HL is 1 if this text is highlighted, 2 if the cursor is on it,
470 3 if should appear in its mouse-face.
471 JUST_FOREGROUND if 1 means draw only the foreground;
472 don't alter the background.
474 FONT is the default font to use (for glyphs whose font-code is 0).
476 Since the display generation code is responsible for calling
477 compute_char_face and compute_glyph_face on everything it puts in
478 the display structure, we can assume that the face code on each
479 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
480 to which we can actually apply intern_face.
481 Call this function with input blocked. */
484 /* This is the multi-face code. */
487 dumpglyphs (f
, left
, top
, gp
, n
, hl
, just_foreground
)
490 register GLYPH
*gp
; /* Points to first GLYPH. */
491 register int n
; /* Number of glyphs to display. */
495 /* Holds characters to be displayed. */
496 char *buf
= (char *) alloca (f
->width
* sizeof (*buf
));
497 register char *cp
; /* Steps through buf[]. */
498 register int tlen
= GLYPH_TABLE_LENGTH
;
499 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
500 Window window
= FRAME_X_WINDOW (f
);
501 int orig_left
= left
;
505 /* Get the face-code of the next GLYPH. */
509 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
510 cf
= FAST_GLYPH_FACE (g
);
512 /* Find the run of consecutive glyphs with the same face-code.
513 Extract their character codes into BUF. */
518 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
519 if (FAST_GLYPH_FACE (g
) != cf
)
522 *cp
++ = FAST_GLYPH_CHAR (g
);
527 /* LEN gets the length of the run. */
530 /* Now output this run of chars, with the font and pixel values
531 determined by the face code CF. */
533 struct face
*face
= FRAME_DEFAULT_FACE (f
);
534 XFontStruct
*font
= FACE_FONT (face
);
535 GC gc
= FACE_GC (face
);
538 /* HL = 3 means use a mouse face previously chosen. */
540 cf
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
;
542 /* First look at the face of the text itself. */
545 /* It's possible for the display table to specify
546 a face code that is out of range. Use 0 in that case. */
547 if (cf
< 0 || cf
>= FRAME_N_COMPUTED_FACES (f
)
548 || FRAME_COMPUTED_FACES (f
) [cf
] == 0)
552 face
= FRAME_MODE_LINE_FACE (f
);
554 face
= intern_face (f
, FRAME_COMPUTED_FACES (f
) [cf
]);
555 font
= FACE_FONT (face
);
557 if (FACE_STIPPLE (face
))
561 /* Then comes the distinction between modeline and normal text. */
566 face
= FRAME_MODE_LINE_FACE (f
);
567 font
= FACE_FONT (face
);
569 if (FACE_STIPPLE (face
))
573 #define FACE_DEFAULT (~0)
575 /* Now override that if the cursor's on this character. */
578 /* The cursor overrides stippling. */
582 || face
->font
== (XFontStruct
*) FACE_DEFAULT
583 || face
->font
== f
->display
.x
->font
)
584 && face
->background
== f
->display
.x
->background_pixel
585 && face
->foreground
== f
->display
.x
->foreground_pixel
)
587 gc
= f
->display
.x
->cursor_gc
;
589 /* Cursor on non-default face: must merge. */
595 xgcv
.background
= f
->display
.x
->cursor_pixel
;
596 xgcv
.foreground
= face
->background
;
597 /* If the glyph would be invisible,
598 try a different foreground. */
599 if (xgcv
.foreground
== xgcv
.background
)
600 xgcv
.foreground
= face
->foreground
;
601 if (xgcv
.foreground
== xgcv
.background
)
602 xgcv
.foreground
= f
->display
.x
->cursor_foreground_pixel
;
603 if (xgcv
.foreground
== xgcv
.background
)
604 xgcv
.foreground
= face
->foreground
;
605 /* Make sure the cursor is distinct from text in this face. */
606 if (xgcv
.background
== face
->background
607 && xgcv
.foreground
== face
->foreground
)
609 xgcv
.background
= face
->foreground
;
610 xgcv
.foreground
= face
->background
;
612 xgcv
.font
= face
->font
->fid
;
613 xgcv
.graphics_exposures
= 0;
614 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
615 if (FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
)
616 XChangeGC (FRAME_X_DISPLAY (f
),
617 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
,
620 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
621 = XCreateGC (FRAME_X_DISPLAY (f
), window
, mask
, &xgcv
);
622 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
624 /* If this code is restored, it must also reset to the default stipple
626 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
627 XSetStipple (FRAME_X_DISPLAY (f
), gc
, face
->stipple
);
632 if (font
== (XFontStruct
*) FACE_DEFAULT
)
633 font
= f
->display
.x
->font
;
636 XDrawString (FRAME_X_DISPLAY (f
), window
, gc
,
637 left
, top
+ FONT_BASE (font
), buf
, len
);
642 /* Turn stipple on. */
643 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillOpaqueStippled
);
645 /* Draw stipple on background. */
646 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
648 FONT_WIDTH (font
) * len
,
651 /* Turn stipple off. */
652 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillSolid
);
654 /* Draw the text, solidly, onto the stipple pattern. */
655 XDrawString (FRAME_X_DISPLAY (f
), window
, gc
,
656 left
, top
+ FONT_BASE (font
), buf
, len
);
659 XDrawImageString (FRAME_X_DISPLAY (f
), window
, gc
,
660 left
, top
+ FONT_BASE (font
), buf
, len
);
662 /* Clear the rest of the line's height. */
663 if (f
->display
.x
->line_height
!= FONT_HEIGHT (font
))
664 XClearArea (FRAME_X_DISPLAY (f
), window
, left
,
665 top
+ FONT_HEIGHT (font
),
666 FONT_WIDTH (font
) * len
,
667 /* This is how many pixels of height
669 f
->display
.x
->line_height
- FONT_HEIGHT (font
),
673 #if 0 /* Doesn't work, because it uses FRAME_CURRENT_GLYPHS,
674 which often is not up to date yet. */
675 if (!just_foreground
)
677 if (left
== orig_left
)
678 redraw_previous_char (f
, PIXEL_TO_CHAR_COL (f
, left
),
679 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
681 redraw_following_char (f
, PIXEL_TO_CHAR_COL (f
, left
+ len
* FONT_WIDTH (font
)),
682 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
686 /* We should probably check for XA_UNDERLINE_POSITION and
687 XA_UNDERLINE_THICKNESS properties on the font, but let's
688 just get the thing working, and come back to that. */
690 int underline_position
= 1;
692 if (font
->descent
<= underline_position
)
693 underline_position
= font
->descent
- 1;
696 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
700 + underline_position
),
701 len
* FONT_WIDTH (font
), 1);
704 left
+= len
* FONT_WIDTH (font
);
711 /* This is the old single-face code. */
714 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
717 register GLYPH
*gp
; /* Points to first GLYPH. */
718 register int n
; /* Number of glyphs to display. */
723 Window window
= FRAME_X_WINDOW (f
);
724 GC drawing_gc
= (hl
== 2 ? f
->display
.x
->cursor_gc
725 : (hl
? f
->display
.x
->reverse_gc
726 : f
->display
.x
->normal_gc
));
728 if (sizeof (GLYPH
) == sizeof (XChar2b
))
729 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
730 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
731 else if (sizeof (GLYPH
) == sizeof (unsigned char))
732 XDrawImageString (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
733 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
735 /* What size of glyph ARE you using? And does X have a function to
741 /* Output some text at the nominal frame cursor position.
742 Advance the cursor over the text.
743 Output LEN glyphs at START.
745 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
746 controls the pixel values used for foreground and background. */
749 XTwrite_glyphs (start
, len
)
750 register GLYPH
*start
;
753 register int temp_length
;
764 /* If not within an update,
765 output at the frame's visible cursor. */
766 curs_x
= f
->cursor_x
;
767 curs_y
= f
->cursor_y
;
771 CHAR_TO_PIXEL_COL (f
, curs_x
),
772 CHAR_TO_PIXEL_ROW (f
, curs_y
),
773 start
, len
, highlight
, 0);
775 /* If we drew on top of the cursor, note that it is turned off. */
776 if (curs_y
== f
->phys_cursor_y
777 && curs_x
<= f
->phys_cursor_x
778 && curs_x
+ len
> f
->phys_cursor_x
)
779 f
->phys_cursor_x
= -1;
781 if (updating_frame
== 0)
784 x_display_cursor (f
, 1);
793 /* Clear to the end of the line.
794 Erase the current text line from the nominal cursor position (inclusive)
795 to column FIRST_UNUSED (exclusive). The idea is that everything
796 from FIRST_UNUSED onward is already erased. */
799 XTclear_end_of_line (first_unused
)
800 register int first_unused
;
802 struct frame
*f
= updating_frame
;
808 if (curs_y
< 0 || curs_y
>= f
->height
)
810 if (first_unused
<= 0)
813 if (first_unused
>= f
->width
)
814 first_unused
= f
->width
;
820 /* Notice if the cursor will be cleared by this operation. */
821 if (curs_y
== f
->phys_cursor_y
822 && curs_x
<= f
->phys_cursor_x
823 && f
->phys_cursor_x
< first_unused
)
824 f
->phys_cursor_x
= -1;
826 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
827 CHAR_TO_PIXEL_COL (f
, curs_x
),
828 CHAR_TO_PIXEL_ROW (f
, curs_y
),
829 FONT_WIDTH (f
->display
.x
->font
) * (first_unused
- curs_x
),
830 f
->display
.x
->line_height
, False
);
832 redraw_previous_char (f
, curs_x
, curs_y
, highlight
);
842 struct frame
*f
= updating_frame
;
847 f
->phys_cursor_x
= -1; /* Cursor not visible. */
848 curs_x
= 0; /* Nominal cursor position is top left. */
853 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
855 /* We have to clear the scroll bars, too. If we have changed
856 colors or something like that, then they should be notified. */
857 x_scroll_bar_clear (f
);
859 XFlush (FRAME_X_DISPLAY (f
));
864 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
865 always contain the right glyphs to use.
867 It also needs to be changed to look at the details of the font and
868 see whether there is really overlap, and do nothing when there is
869 not. This can use font_char_overlap_left and font_char_overlap_right,
870 but just how to use them is not clear. */
872 /* Erase the character (if any) at the position just before X, Y in frame F,
873 then redraw it and the character before it.
874 This is necessary when we erase starting at X,
875 in case the character after X overlaps into the one before X.
876 Call this function with input blocked. */
879 redraw_previous_char (f
, x
, y
, highlight_flag
)
884 /* Erase the character before the new ones, in case
885 what was here before overlaps it.
886 Reoutput that character, and the previous character
887 (in case the previous character overlaps it). */
893 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
894 CHAR_TO_PIXEL_COL (f
, x
- 1),
895 CHAR_TO_PIXEL_ROW (f
, y
),
896 FONT_WIDTH (f
->display
.x
->font
),
897 f
->display
.x
->line_height
, False
);
899 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
900 CHAR_TO_PIXEL_ROW (f
, y
),
901 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
902 x
- start_x
, highlight_flag
, 1);
906 /* Erase the character (if any) at the position X, Y in frame F,
907 then redraw it and the character after it.
908 This is necessary when we erase endng at X,
909 in case the character after X overlaps into the one before X.
910 Call this function with input blocked. */
913 redraw_following_char (f
, x
, y
, highlight_flag
)
918 int limit
= FRAME_CURRENT_GLYPHS (f
)->used
[y
];
919 /* Erase the character after the new ones, in case
920 what was here before overlaps it.
921 Reoutput that character, and the following character
922 (in case the following character overlaps it). */
924 && FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
] != SPACEGLYPH
)
929 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
930 CHAR_TO_PIXEL_COL (f
, x
),
931 CHAR_TO_PIXEL_ROW (f
, y
),
932 FONT_WIDTH (f
->display
.x
->font
),
933 f
->display
.x
->line_height
, False
);
935 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, x
),
936 CHAR_TO_PIXEL_ROW (f
, y
),
937 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
],
938 end_x
- x
, highlight_flag
, 1);
943 #if 0 /* Not in use yet */
945 /* Return 1 if character C in font F extends past its left edge. */
948 font_char_overlap_left (font
, c
)
954 /* Find the bounding-box info for C. */
955 if (font
->per_char
== 0)
956 s
= &font
->max_bounds
;
959 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
962 /* Decode char into row number (byte 1) and code within row (byte 2). */
965 if (!(within
>= font
->min_char_or_byte2
966 && within
<= font
->max_char_or_byte2
967 && row
>= font
->min_byte1
968 && row
<= font
->max_byte1
))
970 /* If char is out of range, try the font's default char instead. */
971 c
= font
->default_char
;
972 row
= c
>> (INTBITS
- 8);
975 if (!(within
>= font
->min_char_or_byte2
976 && within
<= font
->max_char_or_byte2
977 && row
>= font
->min_byte1
978 && row
<= font
->max_byte1
))
979 /* Still out of range means this char does not overlap. */
982 /* We found the info for this char. */
983 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
987 return (s
&& s
->lbearing
< 0);
990 /* Return 1 if character C in font F extends past its right edge. */
993 font_char_overlap_right (font
, c
)
999 /* Find the bounding-box info for C. */
1000 if (font
->per_char
== 0)
1001 s
= &font
->max_bounds
;
1004 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1007 /* Decode char into row number (byte 1) and code within row (byte 2). */
1010 if (!(within
>= font
->min_char_or_byte2
1011 && within
<= font
->max_char_or_byte2
1012 && row
>= font
->min_byte1
1013 && row
<= font
->max_byte1
))
1015 /* If char is out of range, try the font's default char instead. */
1016 c
= font
->default_char
;
1017 row
= c
>> (INTBITS
- 8);
1020 if (!(within
>= font
->min_char_or_byte2
1021 && within
<= font
->max_char_or_byte2
1022 && row
>= font
->min_byte1
1023 && row
<= font
->max_byte1
))
1024 /* Still out of range means this char does not overlap. */
1027 /* We found the info for this char. */
1028 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1032 return (s
&& s
->rbearing
>= s
->width
);
1036 /* Invert the middle quarter of the frame for .15 sec. */
1038 /* We use the select system call to do the waiting, so we have to make sure
1039 it's available. If it isn't, we just won't do visual bells. */
1040 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1042 /* Subtract the `struct timeval' values X and Y,
1043 storing the result in RESULT.
1044 Return 1 if the difference is negative, otherwise 0. */
1047 timeval_subtract (result
, x
, y
)
1048 struct timeval
*result
, x
, y
;
1050 /* Perform the carry for the later subtraction by updating y.
1051 This is safer because on some systems
1052 the tv_sec member is unsigned. */
1053 if (x
.tv_usec
< y
.tv_usec
)
1055 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
1056 y
.tv_usec
-= 1000000 * nsec
;
1059 if (x
.tv_usec
- y
.tv_usec
> 1000000)
1061 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
1062 y
.tv_usec
+= 1000000 * nsec
;
1066 /* Compute the time remaining to wait. tv_usec is certainly positive. */
1067 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
1068 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
1070 /* Return indication of whether the result should be considered negative. */
1071 return x
.tv_sec
< y
.tv_sec
;
1082 /* Create a GC that will use the GXxor function to flip foreground pixels
1083 into background pixels. */
1087 values
.function
= GXxor
;
1088 values
.foreground
= (f
->display
.x
->foreground_pixel
1089 ^ f
->display
.x
->background_pixel
);
1091 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1092 GCFunction
| GCForeground
, &values
);
1096 int width
= PIXEL_WIDTH (f
);
1097 int height
= PIXEL_HEIGHT (f
);
1099 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1100 width
/4, height
/4, width
/2, height
/2);
1101 XFlush (FRAME_X_DISPLAY (f
));
1104 struct timeval wakeup
, now
;
1106 EMACS_GET_TIME (wakeup
);
1108 /* Compute time to wait until, propagating carry from usecs. */
1109 wakeup
.tv_usec
+= 150000;
1110 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
1111 wakeup
.tv_usec
%= 1000000;
1113 /* Keep waiting until past the time wakeup. */
1116 struct timeval timeout
;
1118 EMACS_GET_TIME (timeout
);
1120 /* In effect, timeout = wakeup - timeout.
1121 Break if result would be negative. */
1122 if (timeval_subtract (&timeout
, wakeup
, timeout
))
1125 /* Try to wait that long--but we might wake up sooner. */
1126 select (0, NULL
, NULL
, NULL
, &timeout
);
1130 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1131 width
/4, height
/4, width
/2, height
/2);
1132 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
1133 XFlush (FRAME_X_DISPLAY (f
));
1143 /* Make audible bell. */
1145 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
1149 if (FRAME_X_DISPLAY (selected_frame
) == 0)
1152 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1154 XTflash (selected_frame
);
1160 XFlush (FRAME_X_DISPLAY (selected_frame
));
1165 /* Insert and delete character.
1166 These are not supposed to be used because we are supposed to turn
1167 off the feature of using them. */
1170 XTinsert_glyphs (start
, len
)
1171 register char *start
;
1184 /* Specify how many text lines, from the top of the window,
1185 should be affected by insert-lines and delete-lines operations.
1186 This, and those operations, are used only within an update
1187 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1190 XTset_terminal_window (n
)
1193 if (updating_frame
== 0)
1196 if ((n
<= 0) || (n
> updating_frame
->height
))
1197 flexlines
= updating_frame
->height
;
1202 /* These variables need not be per frame
1203 because redisplay is done on a frame-by-frame basis
1204 and the line dance for one frame is finished before
1205 anything is done for anoter frame. */
1207 /* Array of line numbers from cached insert/delete operations.
1208 line_dance[i] is the old position of the line that we want
1209 to move to line i, or -1 if we want a blank line there. */
1210 static int *line_dance
;
1212 /* Allocated length of that array. */
1213 static int line_dance_len
;
1215 /* Flag indicating whether we've done any work. */
1216 static int line_dance_in_progress
;
1218 /* Perform an insert-lines or delete-lines operation,
1219 inserting N lines or deleting -N lines at vertical position VPOS. */
1220 XTins_del_lines (vpos
, n
)
1223 register int fence
, i
;
1225 if (vpos
>= flexlines
)
1228 if (!line_dance_in_progress
)
1230 int ht
= updating_frame
->height
;
1231 if (ht
> line_dance_len
)
1233 line_dance
= (int *)xrealloc (line_dance
, ht
* sizeof (int));
1234 line_dance_len
= ht
;
1236 for (i
= 0; i
< ht
; ++i
) line_dance
[i
] = i
;
1237 line_dance_in_progress
= 1;
1241 if (n
> flexlines
- vpos
)
1242 n
= flexlines
- vpos
;
1244 for (i
= flexlines
; --i
>= fence
;)
1245 line_dance
[i
] = line_dance
[i
-n
];
1246 for (i
= fence
; --i
>= vpos
;)
1252 if (n
> flexlines
- vpos
)
1253 n
= flexlines
- vpos
;
1254 fence
= flexlines
- n
;
1255 for (i
= vpos
; i
< fence
; ++i
)
1256 line_dance
[i
] = line_dance
[i
+ n
];
1257 for (i
= fence
; i
< flexlines
; ++i
)
1262 /* Here's where we actually move the pixels around.
1263 Must be called with input blocked. */
1267 register int i
, j
, distance
;
1268 register struct frame
*f
;
1272 /* Must check this flag first. If it's not set, then not only is the
1273 array uninitialized, but we might not even have a frame. */
1274 if (!line_dance_in_progress
)
1282 intborder
= f
->display
.x
->internal_border_width
;
1284 x_display_cursor (updating_frame
, 0);
1286 for (i
= 0; i
< ht
; ++i
)
1287 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) > 0)
1289 for (j
= i
; (j
< ht
&& line_dance
[j
] != -1
1290 && line_dance
[j
]-j
== distance
); ++j
);
1291 /* Copy [i,j) upward from [i+distance,j+distance) */
1292 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1293 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1294 intborder
, CHAR_TO_PIXEL_ROW (f
, i
+distance
),
1295 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1296 (j
-i
) * f
->display
.x
->line_height
,
1297 intborder
, CHAR_TO_PIXEL_ROW (f
, i
));
1301 for (i
= ht
; --i
>=0; )
1302 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) < 0)
1304 for (j
= i
; (--j
>= 0 && line_dance
[j
] != -1
1305 && line_dance
[j
]-j
== distance
););
1306 /* Copy (j,i] downward from (j+distance, i+distance] */
1307 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1308 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1309 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1+distance
),
1310 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1311 (i
-j
) * f
->display
.x
->line_height
,
1312 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1));
1316 for (i
= 0; i
< ht
; ++i
)
1317 if (line_dance
[i
] == -1)
1319 for (j
= i
; j
< ht
&& line_dance
[j
] == -1; ++j
);
1321 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1322 intborder
, CHAR_TO_PIXEL_ROW (f
, i
),
1323 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1324 (j
-i
) * f
->display
.x
->line_height
, False
);
1327 line_dance_in_progress
= 0;
1330 /* Support routines for exposure events. */
1331 static void clear_cursor ();
1333 /* Output into a rectangle of an X-window (for frame F)
1334 the characters in f->phys_lines that overlap that rectangle.
1335 TOP and LEFT are the position of the upper left corner of the rectangle.
1336 ROWS and COLS are the size of the rectangle.
1337 Call this function with input blocked. */
1340 dumprectangle (f
, left
, top
, cols
, rows
)
1342 register int left
, top
, cols
, rows
;
1344 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1345 int cursor_cleared
= 0;
1349 if (FRAME_GARBAGED_P (f
))
1352 /* Express rectangle as four edges, instead of position-and-size. */
1353 bottom
= top
+ rows
;
1354 right
= left
+ cols
;
1356 /* Convert rectangle edges in pixels to edges in chars.
1357 Round down for left and top, up for right and bottom. */
1358 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1359 left
= PIXEL_TO_CHAR_COL (f
, left
);
1360 bottom
+= (f
->display
.x
->line_height
- 1);
1361 right
+= (FONT_WIDTH (f
->display
.x
->font
) - 1);
1362 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1363 right
= PIXEL_TO_CHAR_COL (f
, right
);
1365 /* Clip the rectangle to what can be visible. */
1370 if (right
> f
->width
)
1372 if (bottom
> f
->height
)
1375 /* Get size in chars of the rectangle. */
1376 cols
= right
- left
;
1377 rows
= bottom
- top
;
1379 /* If rectangle has zero area, return. */
1380 if (rows
<= 0) return;
1381 if (cols
<= 0) return;
1383 /* Turn off the cursor if it is in the rectangle.
1384 We will turn it back on afterward. */
1385 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1386 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1392 /* Display the text in the rectangle, one text line at a time. */
1394 for (y
= top
; y
< bottom
; y
++)
1396 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1398 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1402 CHAR_TO_PIXEL_COL (f
, left
),
1403 CHAR_TO_PIXEL_ROW (f
, y
),
1404 line
, min (cols
, active_frame
->used
[y
] - left
),
1405 active_frame
->highlight
[y
], 0);
1408 /* Turn the cursor on if we turned it off. */
1411 x_display_cursor (f
, 1);
1418 /* We used to only do this if Vx_no_window_manager was non-nil, but
1419 the ICCCM (section 4.1.6) says that the window's border pixmap
1420 and border pixel are window attributes which are "private to the
1421 client", so we can always change it to whatever we want. */
1423 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1424 f
->display
.x
->border_pixel
);
1426 x_update_cursor (f
, 1);
1430 frame_unhighlight (f
)
1433 /* We used to only do this if Vx_no_window_manager was non-nil, but
1434 the ICCCM (section 4.1.6) says that the window's border pixmap
1435 and border pixel are window attributes which are "private to the
1436 client", so we can always change it to whatever we want. */
1438 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1439 f
->display
.x
->border_tile
);
1441 x_update_cursor (f
, 1);
1444 static void XTframe_rehighlight ();
1445 static void x_frame_rehighlight ();
1447 /* The focus has changed. Update the frames as necessary to reflect
1448 the new situation. Note that we can't change the selected frame
1449 here, because the Lisp code we are interrupting might become confused.
1450 Each event gets marked with the frame in which it occurred, so the
1451 Lisp code can tell when the switch took place by examining the events. */
1454 x_new_focus_frame (dpyinfo
, frame
)
1455 struct x_display_info
*dpyinfo
;
1456 struct frame
*frame
;
1458 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
1459 int events_enqueued
= 0;
1461 if (frame
!= dpyinfo
->x_focus_frame
)
1463 /* Set this before calling other routines, so that they see
1464 the correct value of x_focus_frame. */
1465 dpyinfo
->x_focus_frame
= frame
;
1467 if (old_focus
&& old_focus
->auto_lower
)
1468 x_lower_frame (old_focus
);
1471 selected_frame
= frame
;
1472 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
1474 Fselect_window (selected_frame
->selected_window
);
1475 choose_minibuf_frame ();
1478 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
1479 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
1481 pending_autoraise_frame
= 0;
1484 x_frame_rehighlight (dpyinfo
);
1487 /* Handle an event saying the mouse has moved out of an Emacs frame. */
1490 x_mouse_leave (dpyinfo
)
1491 struct x_display_info
*dpyinfo
;
1493 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
1496 /* The focus has changed, or we have redirected a frame's focus to
1497 another frame (this happens when a frame uses a surrogate
1498 minibuffer frame). Shift the highlight as appropriate.
1500 The FRAME argument doesn't necessarily have anything to do with which
1501 frame is being highlighted or unhighlighted; we only use it to find
1502 the appropriate X display info. */
1504 XTframe_rehighlight (frame
)
1505 struct frame
*frame
;
1507 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
1511 x_frame_rehighlight (dpyinfo
)
1512 struct x_display_info
*dpyinfo
;
1514 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1516 if (dpyinfo
->x_focus_frame
)
1518 dpyinfo
->x_highlight_frame
1519 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
1520 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
1521 : dpyinfo
->x_focus_frame
);
1522 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
1524 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
1525 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1529 dpyinfo
->x_highlight_frame
= 0;
1531 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
1534 frame_unhighlight (old_highlight
);
1535 if (dpyinfo
->x_highlight_frame
)
1536 frame_highlight (dpyinfo
->x_highlight_frame
);
1540 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1542 /* Initialize mode_switch_bit and modifier_meaning. */
1544 x_find_modifier_meanings (dpyinfo
)
1545 struct x_display_info
*dpyinfo
;
1547 int min_code
, max_code
;
1550 XModifierKeymap
*mods
;
1552 dpyinfo
->meta_mod_mask
= 0;
1553 dpyinfo
->shift_lock_mask
= 0;
1554 dpyinfo
->alt_mod_mask
= 0;
1555 dpyinfo
->super_mod_mask
= 0;
1556 dpyinfo
->hyper_mod_mask
= 0;
1559 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
1561 min_code
= display
->min_keycode
;
1562 max_code
= display
->max_keycode
;
1565 syms
= XGetKeyboardMapping (dpyinfo
->display
,
1566 min_code
, max_code
- min_code
+ 1,
1568 mods
= XGetModifierMapping (dpyinfo
->display
);
1570 /* Scan the modifier table to see which modifier bits the Meta and
1571 Alt keysyms are on. */
1573 int row
, col
; /* The row and column in the modifier table. */
1575 for (row
= 3; row
< 8; row
++)
1576 for (col
= 0; col
< mods
->max_keypermod
; col
++)
1579 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
1581 /* Zeroes are used for filler. Skip them. */
1585 /* Are any of this keycode's keysyms a meta key? */
1589 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
1591 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
1597 dpyinfo
->meta_mod_mask
|= (1 << row
);
1602 dpyinfo
->alt_mod_mask
|= (1 << row
);
1607 dpyinfo
->hyper_mod_mask
|= (1 << row
);
1612 dpyinfo
->super_mod_mask
|= (1 << row
);
1616 /* Ignore this if it's not on the lock modifier. */
1617 if ((1 << row
) == LockMask
)
1618 dpyinfo
->shift_lock_mask
= LockMask
;
1626 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
1627 if (! dpyinfo
->meta_mod_mask
)
1629 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
1630 dpyinfo
->alt_mod_mask
= 0;
1633 /* If some keys are both alt and meta,
1634 make them just meta, not alt. */
1635 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
1637 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
1640 XFree ((char *) syms
);
1641 XFreeModifiermap (mods
);
1644 /* Convert between the modifier bits X uses and the modifier bits
1647 x_x_to_emacs_modifiers (dpyinfo
, state
)
1648 struct x_display_info
*dpyinfo
;
1651 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
1652 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
1653 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
1654 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
1655 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
1656 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
1660 x_emacs_to_x_modifiers (dpyinfo
, state
)
1661 struct x_display_info
*dpyinfo
;
1664 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
1665 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
1666 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
1667 | ((state
& shift_modifier
) ? ShiftMask
: 0)
1668 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
1669 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
1672 /* Convert a keysym to its name. */
1675 x_get_keysym_name (keysym
)
1681 value
= XKeysymToString (keysym
);
1687 /* Mouse clicks and mouse movement. Rah. */
1689 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
1690 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
1691 that the glyph at X, Y occupies, if BOUNDS != 0.
1692 If NOCLIP is nonzero, do not force the value into range. */
1695 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1697 register int pix_x
, pix_y
;
1698 register int *x
, *y
;
1702 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1703 even for negative values. */
1705 pix_x
-= FONT_WIDTH ((f
)->display
.x
->font
) - 1;
1707 pix_y
-= (f
)->display
.x
->line_height
- 1;
1709 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
1710 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
1714 bounds
->width
= FONT_WIDTH (f
->display
.x
->font
);
1715 bounds
->height
= f
->display
.x
->line_height
;
1716 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
1717 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
1724 else if (pix_x
> f
->width
)
1729 else if (pix_y
> f
->height
)
1738 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
1741 register int *pix_x
, *pix_y
;
1743 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
1744 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
1747 /* Prepare a mouse-event in *RESULT for placement in the input queue.
1749 If the event is a button press, then note that we have grabbed
1753 construct_mouse_click (result
, event
, f
)
1754 struct input_event
*result
;
1755 XButtonEvent
*event
;
1758 /* Make the event type no_event; we'll change that when we decide
1760 result
->kind
= mouse_click
;
1761 result
->code
= event
->button
- Button1
;
1762 result
->timestamp
= event
->time
;
1763 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
1765 | (event
->type
== ButtonRelease
1773 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
1774 XSETFASTINT (result
->x
, column
);
1775 XSETFASTINT (result
->y
, row
);
1777 XSETINT (result
->x
, event
->x
);
1778 XSETINT (result
->y
, event
->y
);
1779 XSETFRAME (result
->frame_or_window
, f
);
1783 /* Prepare a menu-event in *RESULT for placement in the input queue. */
1786 construct_menu_click (result
, event
, f
)
1787 struct input_event
*result
;
1788 XButtonEvent
*event
;
1791 /* Make the event type no_event; we'll change that when we decide
1793 result
->kind
= mouse_click
;
1794 XSETINT (result
->code
, event
->button
- Button1
);
1795 result
->timestamp
= event
->time
;
1796 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
1798 | (event
->type
== ButtonRelease
1802 XSETINT (result
->x
, event
->x
);
1803 XSETINT (result
->y
, -1);
1804 XSETFRAME (result
->frame_or_window
, f
);
1807 /* Function to report a mouse movement to the mainstream Emacs code.
1808 The input handler calls this.
1810 We have received a mouse movement event, which is given in *event.
1811 If the mouse is over a different glyph than it was last time, tell
1812 the mainstream emacs code by setting mouse_moved. If not, ask for
1813 another motion event, so we can check again the next time it moves. */
1816 note_mouse_movement (frame
, event
)
1818 XMotionEvent
*event
;
1820 last_mouse_movement_time
= event
->time
;
1822 if (event
->window
!= FRAME_X_WINDOW (frame
))
1824 frame
->mouse_moved
= 1;
1825 last_mouse_scroll_bar
= Qnil
;
1827 note_mouse_highlight (frame
, -1, -1);
1829 /* Ask for another mouse motion event. */
1832 Window dummy_window
;
1834 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1835 &dummy_window
, &dummy_window
,
1836 &dummy
, &dummy
, &dummy
, &dummy
,
1837 (unsigned int *) &dummy
);
1841 /* Has the mouse moved off the glyph it was on at the last sighting? */
1842 else if (event
->x
< last_mouse_glyph
.x
1843 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
1844 || event
->y
< last_mouse_glyph
.y
1845 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
1847 frame
->mouse_moved
= 1;
1848 last_mouse_scroll_bar
= Qnil
;
1850 note_mouse_highlight (frame
, event
->x
, event
->y
);
1852 /* Ask for another mouse motion event. */
1855 Window dummy_window
;
1857 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1858 &dummy_window
, &dummy_window
,
1859 &dummy
, &dummy
, &dummy
, &dummy
,
1860 (unsigned int *) &dummy
);
1865 /* It's on the same glyph. Call XQueryPointer so we'll get an
1866 event the next time the mouse moves and we can see if it's
1867 *still* on the same glyph. */
1869 Window dummy_window
;
1871 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1872 &dummy_window
, &dummy_window
,
1873 &dummy
, &dummy
, &dummy
, &dummy
,
1874 (unsigned int *) &dummy
);
1878 /* This is used for debugging, to turn off note_mouse_highlight. */
1879 static int disable_mouse_highlight
;
1881 /* Take proper action when the mouse has moved to position X, Y on frame F
1882 as regards highlighting characters that have mouse-face properties.
1883 Also dehighlighting chars where the mouse was before.
1884 X and Y can be negative or out of range. */
1887 note_mouse_highlight (f
, x
, y
)
1891 int row
, column
, portion
;
1892 XRectangle new_glyph
;
1896 if (disable_mouse_highlight
)
1899 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
= x
;
1900 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
= y
;
1901 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
= f
;
1903 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
)
1908 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 1;
1912 /* Find out which glyph the mouse is on. */
1913 pixel_to_glyph_coords (f
, x
, y
, &column
, &row
,
1914 &new_glyph
, FRAME_X_DISPLAY_INFO (f
)->grabbed
);
1916 /* Which window is that in? */
1917 window
= window_from_coordinates (f
, column
, row
, &portion
);
1918 w
= XWINDOW (window
);
1920 /* If we were displaying active text in another window, clear that. */
1921 if (! EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
1922 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
1924 /* Are we in a window whose display is up to date?
1925 And verify the buffer's text has not changed. */
1926 if (WINDOWP (window
) && portion
== 0 && row
>= 0 && column
>= 0
1927 && row
< FRAME_HEIGHT (f
) && column
< FRAME_WIDTH (f
)
1928 && EQ (w
->window_end_valid
, w
->buffer
)
1929 && w
->last_modified
== BUF_MODIFF (XBUFFER (w
->buffer
)))
1931 int *ptr
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[row
];
1934 /* Find which buffer position the mouse corresponds to. */
1935 for (i
= column
; i
>= 0; i
--)
1939 /* Is it outside the displayed active region (if any)? */
1941 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
1942 else if (! (EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
)
1943 && row
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
1944 && row
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
1945 && (row
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
1946 || column
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
)
1947 && (row
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
1948 || column
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
1949 || FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
)))
1951 Lisp_Object mouse_face
, overlay
, position
;
1952 Lisp_Object
*overlay_vec
;
1953 int len
, noverlays
, ignor1
;
1954 struct buffer
*obuf
;
1957 /* If we get an out-of-range value, return now; avoid an error. */
1958 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
1961 /* Make the window's buffer temporarily current for
1962 overlays_at and compute_char_face. */
1963 obuf
= current_buffer
;
1964 current_buffer
= XBUFFER (w
->buffer
);
1970 /* Yes. Clear the display of the old active region, if any. */
1971 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
1973 /* Is this char mouse-active? */
1974 XSETINT (position
, pos
);
1977 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
1979 /* Put all the overlays we want in a vector in overlay_vec.
1980 Store the length in len. */
1981 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
1983 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
1985 /* Find the highest priority overlay that has a mouse-face prop. */
1987 for (i
= 0; i
< noverlays
; i
++)
1989 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
1990 if (!NILP (mouse_face
))
1992 overlay
= overlay_vec
[i
];
1997 /* If no overlay applies, get a text property. */
1999 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
2001 /* Handle the overlay case. */
2002 if (! NILP (overlay
))
2004 /* Find the range of text around this char that
2005 should be active. */
2006 Lisp_Object before
, after
;
2009 before
= Foverlay_start (overlay
);
2010 after
= Foverlay_end (overlay
);
2011 /* Record this as the current active region. */
2012 fast_find_position (window
, before
,
2013 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2014 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2015 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2016 = !fast_find_position (window
, after
,
2017 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2018 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2019 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2020 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2021 = compute_char_face (f
, w
, pos
, 0, 0,
2022 &ignore
, pos
+ 1, 1);
2024 /* Display it as active. */
2025 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2027 /* Handle the text property case. */
2028 else if (! NILP (mouse_face
))
2030 /* Find the range of text around this char that
2031 should be active. */
2032 Lisp_Object before
, after
, beginning
, end
;
2035 beginning
= Fmarker_position (w
->start
);
2036 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
2037 - XFASTINT (w
->window_end_pos
)));
2039 = Fprevious_single_property_change (make_number (pos
+ 1),
2041 w
->buffer
, beginning
);
2043 = Fnext_single_property_change (position
, Qmouse_face
,
2045 /* Record this as the current active region. */
2046 fast_find_position (window
, before
,
2047 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2048 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2049 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2050 = !fast_find_position (window
, after
,
2051 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2052 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2053 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2054 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2055 = compute_char_face (f
, w
, pos
, 0, 0,
2056 &ignore
, pos
+ 1, 1);
2058 /* Display it as active. */
2059 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2063 current_buffer
= obuf
;
2068 /* Find the row and column of position POS in window WINDOW.
2069 Store them in *COLUMNP and *ROWP.
2070 This assumes display in WINDOW is up to date.
2071 If POS is above start of WINDOW, return coords
2072 of start of first screen line.
2073 If POS is after end of WINDOW, return coords of end of last screen line.
2075 Value is 1 if POS is in range, 0 if it was off screen. */
2078 fast_find_position (window
, pos
, columnp
, rowp
)
2081 int *columnp
, *rowp
;
2083 struct window
*w
= XWINDOW (window
);
2084 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2089 int height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
2090 int width
= window_internal_width (w
);
2093 int maybe_next_line
= 0;
2095 /* Find the right row. */
2100 int linestart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ i
][left
];
2101 if (linestart
> pos
)
2103 /* If the position sought is the end of the buffer,
2104 don't include the blank lines at the bottom of the window. */
2105 if (linestart
== pos
&& pos
== BUF_ZV (XBUFFER (w
->buffer
)))
2107 maybe_next_line
= 1;
2114 /* Find the right column with in it. */
2115 charstarts
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ row
];
2117 for (i
= 0; i
< width
; i
++)
2119 if (charstarts
[left
+ i
] == pos
)
2122 *columnp
= i
+ left
;
2125 else if (charstarts
[left
+ i
] > pos
)
2127 else if (charstarts
[left
+ i
] > 0)
2131 /* If we're looking for the end of the buffer,
2132 and we didn't find it in the line we scanned,
2133 use the start of the following line. */
2134 if (maybe_next_line
)
2145 /* Display the active region described by mouse_face_*
2146 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2149 show_mouse_face (dpyinfo
, hl
)
2150 struct x_display_info
*dpyinfo
;
2153 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
2154 int width
= window_internal_width (w
);
2155 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2158 int old_curs_x
= curs_x
;
2159 int old_curs_y
= curs_y
;
2161 /* Set these variables temporarily
2162 so that if we have to turn the cursor off and on again
2163 we will put it back at the same place. */
2164 curs_x
= f
->phys_cursor_x
;
2165 curs_y
= f
->phys_cursor_y
;
2167 for (i
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
;
2168 i
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
; i
++)
2170 int column
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2171 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
2173 int endcolumn
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2174 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2176 endcolumn
= min (endcolumn
, FRAME_CURRENT_GLYPHS (f
)->used
[i
]);
2178 /* If the cursor's in the text we are about to rewrite,
2179 turn the cursor off. */
2181 && curs_x
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
- 1
2182 && curs_x
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
)
2184 x_display_cursor (f
, 0);
2189 CHAR_TO_PIXEL_COL (f
, column
),
2190 CHAR_TO_PIXEL_ROW (f
, i
),
2191 FRAME_CURRENT_GLYPHS (f
)->glyphs
[i
] + column
,
2193 /* Highlight with mouse face if hl > 0. */
2197 /* If we turned the cursor off, turn it back on. */
2199 x_display_cursor (f
, 1);
2201 curs_x
= old_curs_x
;
2202 curs_y
= old_curs_y
;
2204 /* Change the mouse cursor according to the value of HL. */
2206 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2207 f
->display
.x
->cross_cursor
);
2209 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2210 f
->display
.x
->text_cursor
);
2213 /* Clear out the mouse-highlighted active region.
2214 Redraw it unhighlighted first. */
2217 clear_mouse_face (dpyinfo
)
2218 struct x_display_info
*dpyinfo
;
2220 if (! NILP (dpyinfo
->mouse_face_window
))
2221 show_mouse_face (dpyinfo
, 0);
2223 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2224 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2225 dpyinfo
->mouse_face_window
= Qnil
;
2228 static struct scroll_bar
*x_window_to_scroll_bar ();
2229 static void x_scroll_bar_report_motion ();
2231 /* Return the current position of the mouse.
2232 *fp should be a frame which indicates which display to ask about.
2234 If the mouse movement started in a scroll bar, set *fp, *bar_window,
2235 and *part to the frame, window, and scroll bar part that the mouse
2236 is over. Set *x and *y to the portion and whole of the mouse's
2237 position on the scroll bar.
2239 If the mouse movement started elsewhere, set *fp to the frame the
2240 mouse is on, *bar_window to nil, and *x and *y to the character cell
2243 Set *time to the server timestamp for the time at which the mouse
2244 was at this position.
2246 Don't store anything if we don't have a valid set of values to report.
2248 This clears the mouse_moved flag, so we can wait for the next mouse
2249 movement. This also calls XQueryPointer, which will cause the
2250 server to give us another MotionNotify when the mouse moves
2254 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
2257 Lisp_Object
*bar_window
;
2258 enum scroll_bar_part
*part
;
2260 unsigned long *time
;
2266 if (! NILP (last_mouse_scroll_bar
))
2267 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
2273 Window dummy_window
;
2276 Lisp_Object frame
, tail
;
2278 /* Clear the mouse-moved flag for every frame on this display. */
2279 FOR_EACH_FRAME (tail
, frame
)
2280 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
2281 XFRAME (frame
)->mouse_moved
= 0;
2283 last_mouse_scroll_bar
= Qnil
;
2285 /* Figure out which root window we're on. */
2286 XQueryPointer (FRAME_X_DISPLAY (*fp
),
2287 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
2289 /* The root window which contains the pointer. */
2292 /* Trash which we can't trust if the pointer is on
2293 a different screen. */
2296 /* The position on that root window. */
2299 /* More trash we can't trust. */
2302 /* Modifier keys and pointer buttons, about which
2304 (unsigned int *) &dummy
);
2306 /* Now we have a position on the root; find the innermost window
2307 containing the pointer. */
2311 int parent_x
, parent_y
;
2315 /* XTranslateCoordinates can get errors if the window
2316 structure is changing at the same time this function
2317 is running. So at least we must not crash from them. */
2319 x_catch_errors (FRAME_X_DISPLAY (*fp
));
2321 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
2322 && FRAME_LIVE_P (last_mouse_frame
))
2324 /* If mouse was grabbed on a frame, give coords for that frame
2325 even if the mouse is now outside it. */
2326 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2328 /* From-window, to-window. */
2329 root
, FRAME_X_WINDOW (last_mouse_frame
),
2331 /* From-position, to-position. */
2332 root_x
, root_y
, &win_x
, &win_y
,
2336 f1
= last_mouse_frame
;
2342 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2344 /* From-window, to-window. */
2347 /* From-position, to-position. */
2348 root_x
, root_y
, &win_x
, &win_y
,
2361 /* Now we know that:
2362 win is the innermost window containing the pointer
2363 (XTC says it has no child containing the pointer),
2364 win_x and win_y are the pointer's position in it
2365 (XTC did this the last time through), and
2366 parent_x and parent_y are the pointer's position in win's parent.
2367 (They are what win_x and win_y were when win was child.
2368 If win is the root window, it has no parent, and
2369 parent_{x,y} are invalid, but that's okay, because we'll
2370 never use them in that case.) */
2372 /* Is win one of our frames? */
2373 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
2376 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
2379 x_uncatch_errors (FRAME_X_DISPLAY (*fp
));
2381 /* If not, is it one of our scroll bars? */
2384 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
2388 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2394 if (f1
== 0 && insist
)
2395 f1
= selected_frame
;
2399 int ignore1
, ignore2
;
2401 /* Ok, we found a frame. Store all the values. */
2403 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
2405 FRAME_X_DISPLAY_INFO (f1
)->grabbed
2411 XSETINT (*x
, win_x
);
2412 XSETINT (*y
, win_y
);
2413 *time
= last_mouse_movement_time
;
2421 /* Scroll bar support. */
2423 /* Given an X window ID, find the struct scroll_bar which manages it.
2424 This can be called in GC, so we have to make sure to strip off mark
2426 static struct scroll_bar
*
2427 x_window_to_scroll_bar (window_id
)
2430 Lisp_Object tail
, frame
;
2432 for (tail
= Vframe_list
;
2433 XGCTYPE (tail
) == Lisp_Cons
;
2434 tail
= XCONS (tail
)->cdr
)
2436 Lisp_Object frame
, bar
, condemned
;
2438 frame
= XCONS (tail
)->car
;
2439 /* All elements of Vframe_list should be frames. */
2440 if (! GC_FRAMEP (frame
))
2443 /* Scan this frame's scroll bar list for a scroll bar with the
2445 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2446 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2447 /* This trick allows us to search both the ordinary and
2448 condemned scroll bar lists with one loop. */
2449 ! GC_NILP (bar
) || (bar
= condemned
,
2452 bar
= XSCROLL_BAR (bar
)->next
)
2453 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2454 return XSCROLL_BAR (bar
);
2460 /* Open a new X window to serve as a scroll bar, and return the
2461 scroll bar vector for it. */
2462 static struct scroll_bar
*
2463 x_scroll_bar_create (window
, top
, left
, width
, height
)
2464 struct window
*window
;
2465 int top
, left
, width
, height
;
2467 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2468 struct scroll_bar
*bar
2469 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2474 XSetWindowAttributes a
;
2476 a
.background_pixel
= f
->display
.x
->background_pixel
;
2477 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2478 | ButtonMotionMask
| PointerMotionHintMask
2480 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
2482 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2487 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2488 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2489 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
2490 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
2491 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2492 sb_widget
= XtCreateManagedWidget ("box",
2494 f
->display
.x
->edit_widget
, al
, ac
);
2495 SET_SCROLL_BAR_X_WINDOW
2496 (bar
, sb_widget
->core
.window
);
2498 SET_SCROLL_BAR_X_WINDOW
2500 XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2502 /* Position and size of scroll bar. */
2503 left
, top
, width
, height
,
2505 /* Border width, depth, class, and visual. */
2506 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
2512 XSETWINDOW (bar
->window
, window
);
2513 XSETINT (bar
->top
, top
);
2514 XSETINT (bar
->left
, left
);
2515 XSETINT (bar
->width
, width
);
2516 XSETINT (bar
->height
, height
);
2517 XSETINT (bar
->start
, 0);
2518 XSETINT (bar
->end
, 0);
2519 bar
->dragging
= Qnil
;
2521 /* Add bar to its frame's list of scroll bars. */
2522 bar
->next
= FRAME_SCROLL_BARS (f
);
2524 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2525 if (! NILP (bar
->next
))
2526 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2528 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
2535 /* Draw BAR's handle in the proper position.
2536 If the handle is already drawn from START to END, don't bother
2537 redrawing it, unless REBUILD is non-zero; in that case, always
2538 redraw it. (REBUILD is handy for drawing the handle after expose
2541 Normally, we want to constrain the start and end of the handle to
2542 fit inside its rectangle, but if the user is dragging the scroll bar
2543 handle, we want to let them drag it down all the way, so that the
2544 bar's top is as far down as it goes; otherwise, there's no way to
2545 move to the very end of the buffer. */
2547 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
2548 struct scroll_bar
*bar
;
2552 int dragging
= ! NILP (bar
->dragging
);
2553 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2554 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2555 GC gc
= f
->display
.x
->normal_gc
;
2557 /* If the display is already accurate, do nothing. */
2559 && start
== XINT (bar
->start
)
2560 && end
== XINT (bar
->end
))
2566 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (XINT (bar
->width
));
2567 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2568 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2570 /* Make sure the values are reasonable, and try to preserve
2571 the distance between start and end. */
2573 int length
= end
- start
;
2577 else if (start
> top_range
)
2579 end
= start
+ length
;
2583 else if (end
> top_range
&& ! dragging
)
2587 /* Store the adjusted setting in the scroll bar. */
2588 XSETINT (bar
->start
, start
);
2589 XSETINT (bar
->end
, end
);
2591 /* Clip the end position, just for display. */
2592 if (end
> top_range
)
2595 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
2596 below top positions, to make sure the handle is always at least
2597 that many pixels tall. */
2598 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
2600 /* Draw the empty space above the handle. Note that we can't clear
2601 zero-height areas; that means "clear to end of window." */
2603 XClearArea (FRAME_X_DISPLAY (f
), w
,
2605 /* x, y, width, height, and exposures. */
2606 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2607 VERTICAL_SCROLL_BAR_TOP_BORDER
,
2608 inside_width
, start
,
2611 /* Draw the handle itself. */
2612 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
2614 /* x, y, width, height */
2615 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2616 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
2617 inside_width
, end
- start
);
2620 /* Draw the empty space below the handle. Note that we can't
2621 clear zero-height areas; that means "clear to end of window." */
2622 if (end
< inside_height
)
2623 XClearArea (FRAME_X_DISPLAY (f
), w
,
2625 /* x, y, width, height, and exposures. */
2626 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2627 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
2628 inside_width
, inside_height
- end
,
2636 /* Move a scroll bar around on the screen, to accommodate changing
2637 window configurations. */
2639 x_scroll_bar_move (bar
, top
, left
, width
, height
)
2640 struct scroll_bar
*bar
;
2641 int top
, left
, width
, height
;
2643 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2644 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2650 unsigned int mask
= 0;
2657 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
2658 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
2659 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
2660 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
2663 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
2667 XSETINT (bar
->left
, left
);
2668 XSETINT (bar
->top
, top
);
2669 XSETINT (bar
->width
, width
);
2670 XSETINT (bar
->height
, height
);
2675 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
2678 x_scroll_bar_remove (bar
)
2679 struct scroll_bar
*bar
;
2681 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2685 /* Destroy the window. */
2686 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
2688 /* Disassociate this scroll bar from its window. */
2689 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
2694 /* Set the handle of the vertical scroll bar for WINDOW to indicate
2695 that we are displaying PORTION characters out of a total of WHOLE
2696 characters, starting at POSITION. If WINDOW has no scroll bar,
2699 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
2700 struct window
*window
;
2701 int portion
, whole
, position
;
2703 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2704 int top
= XINT (window
->top
);
2705 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
2706 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
2708 /* Where should this scroll bar be, pixelwise? */
2709 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
2710 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
2712 = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
2713 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2714 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->display
.x
->font
)));
2715 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
2717 struct scroll_bar
*bar
;
2719 /* Does the scroll bar exist yet? */
2720 if (NILP (window
->vertical_scroll_bar
))
2721 bar
= x_scroll_bar_create (window
,
2722 pixel_top
, pixel_left
,
2723 pixel_width
, pixel_height
);
2726 /* It may just need to be moved and resized. */
2727 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2728 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
2731 /* Set the scroll bar's current state, unless we're currently being
2733 if (NILP (bar
->dragging
))
2735 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (pixel_height
);
2738 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
2741 int start
= ((double) position
* top_range
) / whole
;
2742 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
2744 x_scroll_bar_set_handle (bar
, start
, end
, 0);
2748 XSETVECTOR (window
->vertical_scroll_bar
, bar
);
2752 /* The following three hooks are used when we're doing a thorough
2753 redisplay of the frame. We don't explicitly know which scroll bars
2754 are going to be deleted, because keeping track of when windows go
2755 away is a real pain - "Can you say set-window-configuration, boys
2756 and girls?" Instead, we just assert at the beginning of redisplay
2757 that *all* scroll bars are to be removed, and then save a scroll bar
2758 from the fiery pit when we actually redisplay its window. */
2760 /* Arrange for all scroll bars on FRAME to be removed at the next call
2761 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
2762 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
2764 XTcondemn_scroll_bars (frame
)
2767 /* The condemned list should be empty at this point; if it's not,
2768 then the rest of Emacs isn't using the condemn/redeem/judge
2769 protocol correctly. */
2770 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
2773 /* Move them all to the "condemned" list. */
2774 FRAME_CONDEMNED_SCROLL_BARS (frame
) = FRAME_SCROLL_BARS (frame
);
2775 FRAME_SCROLL_BARS (frame
) = Qnil
;
2778 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
2779 Note that WINDOW isn't necessarily condemned at all. */
2781 XTredeem_scroll_bar (window
)
2782 struct window
*window
;
2784 struct scroll_bar
*bar
;
2786 /* We can't redeem this window's scroll bar if it doesn't have one. */
2787 if (NILP (window
->vertical_scroll_bar
))
2790 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2792 /* Unlink it from the condemned list. */
2794 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2796 if (NILP (bar
->prev
))
2798 /* If the prev pointer is nil, it must be the first in one of
2800 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
2801 /* It's not condemned. Everything's fine. */
2803 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
2804 window
->vertical_scroll_bar
))
2805 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
2807 /* If its prev pointer is nil, it must be at the front of
2808 one or the other! */
2812 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
2814 if (! NILP (bar
->next
))
2815 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
2817 bar
->next
= FRAME_SCROLL_BARS (f
);
2819 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2820 if (! NILP (bar
->next
))
2821 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2825 /* Remove all scroll bars on FRAME that haven't been saved since the
2826 last call to `*condemn_scroll_bars_hook'. */
2828 XTjudge_scroll_bars (f
)
2831 Lisp_Object bar
, next
;
2833 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
2835 /* Clear out the condemned list now so we won't try to process any
2836 more events on the hapless scroll bars. */
2837 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
2839 for (; ! NILP (bar
); bar
= next
)
2841 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
2843 x_scroll_bar_remove (b
);
2846 b
->next
= b
->prev
= Qnil
;
2849 /* Now there should be no references to the condemned scroll bars,
2850 and they should get garbage-collected. */
2854 /* Handle an Expose or GraphicsExpose event on a scroll bar.
2856 This may be called from a signal handler, so we have to ignore GC
2859 x_scroll_bar_expose (bar
, event
)
2860 struct scroll_bar
*bar
;
2863 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2864 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2865 GC gc
= f
->display
.x
->normal_gc
;
2869 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
2871 /* Draw a one-pixel border just inside the edges of the scroll bar. */
2872 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
2874 /* x, y, width, height */
2875 0, 0, XINT (bar
->width
) - 1, XINT (bar
->height
) - 1);
2880 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
2881 is set to something other than no_event, it is enqueued.
2883 This may be called from a signal handler, so we have to ignore GC
2886 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
2887 struct scroll_bar
*bar
;
2889 struct input_event
*emacs_event
;
2891 if (! GC_WINDOWP (bar
->window
))
2894 emacs_event
->kind
= scroll_bar_click
;
2895 emacs_event
->code
= event
->xbutton
.button
- Button1
;
2896 emacs_event
->modifiers
2897 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
2898 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
2899 event
->xbutton
.state
)
2900 | (event
->type
== ButtonRelease
2903 emacs_event
->frame_or_window
= bar
->window
;
2904 emacs_event
->timestamp
= event
->xbutton
.time
;
2907 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2909 = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2910 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
2913 if (y
> top_range
) y
= top_range
;
2915 if (y
< XINT (bar
->start
))
2916 emacs_event
->part
= scroll_bar_above_handle
;
2917 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
2918 emacs_event
->part
= scroll_bar_handle
;
2920 emacs_event
->part
= scroll_bar_below_handle
;
2922 /* Just because the user has clicked on the handle doesn't mean
2923 they want to drag it. Lisp code needs to be able to decide
2924 whether or not we're dragging. */
2926 /* If the user has just clicked on the handle, record where they're
2928 if (event
->type
== ButtonPress
2929 && emacs_event
->part
== scroll_bar_handle
)
2930 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
2933 /* If the user has released the handle, set it to its final position. */
2934 if (event
->type
== ButtonRelease
2935 && ! NILP (bar
->dragging
))
2937 int new_start
= y
- XINT (bar
->dragging
);
2938 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2940 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2941 bar
->dragging
= Qnil
;
2944 /* Same deal here as the other #if 0. */
2946 /* Clicks on the handle are always reported as occurring at the top of
2948 if (emacs_event
->part
== scroll_bar_handle
)
2949 emacs_event
->x
= bar
->start
;
2951 XSETINT (emacs_event
->x
, y
);
2953 XSETINT (emacs_event
->x
, y
);
2956 XSETINT (emacs_event
->y
, top_range
);
2960 /* Handle some mouse motion while someone is dragging the scroll bar.
2962 This may be called from a signal handler, so we have to ignore GC
2965 x_scroll_bar_note_movement (bar
, event
)
2966 struct scroll_bar
*bar
;
2969 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
2971 last_mouse_movement_time
= event
->xmotion
.time
;
2974 XSETVECTOR (last_mouse_scroll_bar
, bar
);
2976 /* If we're dragging the bar, display it. */
2977 if (! GC_NILP (bar
->dragging
))
2979 /* Where should the handle be now? */
2980 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
2982 if (new_start
!= XINT (bar
->start
))
2984 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2986 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2990 /* Call XQueryPointer so we'll get an event the next time the mouse
2991 moves and we can see *still* on the same position. */
2994 Window dummy_window
;
2996 XQueryPointer (event
->xmotion
.display
, event
->xmotion
.window
,
2997 &dummy_window
, &dummy_window
,
2998 &dummy
, &dummy
, &dummy
, &dummy
,
2999 (unsigned int *) &dummy
);
3003 /* Return information to the user about the current position of the mouse
3004 on the scroll bar. */
3006 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
3008 Lisp_Object
*bar_window
;
3009 enum scroll_bar_part
*part
;
3011 unsigned long *time
;
3013 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
3014 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3015 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3017 Window dummy_window
;
3019 unsigned int dummy_mask
;
3023 /* Get the mouse's position relative to the scroll bar window, and
3025 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
3027 /* Root, child, root x and root y. */
3028 &dummy_window
, &dummy_window
,
3029 &dummy_coord
, &dummy_coord
,
3031 /* Position relative to scroll bar. */
3034 /* Mouse buttons and modifier keys. */
3040 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
3042 = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
3044 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
3046 if (! NILP (bar
->dragging
))
3047 win_y
-= XINT (bar
->dragging
);
3051 if (win_y
> top_range
)
3055 *bar_window
= bar
->window
;
3057 if (! NILP (bar
->dragging
))
3058 *part
= scroll_bar_handle
;
3059 else if (win_y
< XINT (bar
->start
))
3060 *part
= scroll_bar_above_handle
;
3061 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3062 *part
= scroll_bar_handle
;
3064 *part
= scroll_bar_below_handle
;
3066 XSETINT (*x
, win_y
);
3067 XSETINT (*y
, top_range
);
3070 last_mouse_scroll_bar
= Qnil
;
3073 *time
= last_mouse_movement_time
;
3079 /* The screen has been cleared so we may have changed foreground or
3080 background colors, and the scroll bars may need to be redrawn.
3081 Clear out the scroll bars, and ask for expose events, so we can
3084 x_scroll_bar_clear (f
)
3089 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
3090 bar
= XSCROLL_BAR (bar
)->next
)
3091 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
3095 /* This processes Expose events from the menubar specific X event
3096 loop in xmenu.c. This allows to redisplay the frame if necessary
3097 when handling menubar or popup items. */
3100 process_expose_from_menu (event
)
3104 struct x_display_info
*dpyinfo
;
3108 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
3109 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3112 if (f
->async_visible
== 0)
3114 f
->async_visible
= 1;
3115 f
->async_iconified
= 0;
3116 SET_FRAME_GARBAGED (f
);
3120 dumprectangle (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
3121 event
.xexpose
.x
, event
.xexpose
.y
,
3122 event
.xexpose
.width
, event
.xexpose
.height
);
3127 struct scroll_bar
*bar
3128 = x_window_to_scroll_bar (event
.xexpose
.window
);
3131 x_scroll_bar_expose (bar
, &event
);
3137 /* Define a queue to save up SelectionRequest events for later handling. */
3139 struct selection_event_queue
3142 struct selection_event_queue
*next
;
3145 static struct selection_event_queue
*queue
;
3147 /* Nonzero means queue up certain events--don't process them yet. */
3148 static int x_queue_selection_requests
;
3150 /* Queue up an X event *EVENT, to be processed later. */
3153 x_queue_event (f
, event
)
3157 struct selection_event_queue
*queue_tmp
3158 = (struct selection_event_queue
*) malloc (sizeof (struct selection_event_queue
));
3160 if (queue_tmp
!= NULL
)
3162 queue_tmp
->event
= *event
;
3163 queue_tmp
->next
= queue
;
3168 /* Take all the queued events and put them back
3169 so that they get processed afresh. */
3172 x_unqueue_events (display
)
3175 while (queue
!= NULL
)
3177 struct selection_event_queue
*queue_tmp
= queue
;
3178 XPutBackEvent (display
, &queue_tmp
->event
);
3179 queue
= queue_tmp
->next
;
3180 free ((char *)queue_tmp
);
3184 /* Start queuing SelectionRequest events. */
3187 x_start_queuing_selection_requests (display
)
3190 x_queue_selection_requests
++;
3193 /* Stop queuing SelectionRequest events. */
3196 x_stop_queuing_selection_requests (display
)
3199 x_queue_selection_requests
--;
3200 x_unqueue_events (display
);
3203 /* The main X event-reading loop - XTread_socket. */
3205 /* Timestamp of enter window event. This is only used by XTread_socket,
3206 but we have to put it out here, since static variables within functions
3207 sometimes don't work. */
3208 static Time enter_timestamp
;
3210 /* This holds the state XLookupString needs to implement dead keys
3211 and other tricks known as "compose processing". _X Window System_
3212 says that a portable program can't use this, but Stephen Gildea assures
3213 me that letting the compiler initialize it to zeros will work okay.
3215 This must be defined outside of XTread_socket, for the same reasons
3216 given for enter_timestamp, above. */
3217 static XComposeStatus compose_status
;
3219 /* Record the last 100 characters stored
3220 to help debug the loss-of-chars-during-GC problem. */
3222 short temp_buffer
[100];
3224 /* Set this to nonzero to fake an "X I/O error"
3225 on a particular display. */
3226 struct x_display_info
*XTread_socket_fake_io_error
;
3228 /* Read events coming from the X server.
3229 This routine is called by the SIGIO handler.
3230 We return as soon as there are no more events to be read.
3232 Events representing keys are stored in buffer BUFP,
3233 which can hold up to NUMCHARS characters.
3234 We return the number of characters stored into the buffer,
3235 thus pretending to be `read'.
3237 WAITP is nonzero if we should block until input arrives.
3238 EXPECTED is nonzero if the caller knows input is available. */
3241 XTread_socket (sd
, bufp
, numchars
, waitp
, expected
)
3243 register struct input_event
*bufp
;
3244 register int numchars
;
3251 int items_pending
; /* How many items are in the X queue. */
3254 int event_found
= 0;
3257 struct x_display_info
*dpyinfo
;
3259 if (interrupt_input_blocked
)
3261 interrupt_input_pending
= 1;
3265 interrupt_input_pending
= 0;
3268 /* So people can tell when we have read the available input. */
3269 input_signal_count
++;
3272 abort (); /* Don't think this happens. */
3274 /* Find the display we are supposed to read input for.
3275 It's the one communicating on descriptor SD. */
3276 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
3278 #if 0 /* This ought to be unnecessary; let's verify it. */
3280 /* If available, Xlib uses FIOSNBIO to make the socket
3281 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3282 FIOSNBIO is ignored, and instead of signalling EWOULDBLOCK,
3283 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3284 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
3285 #endif /* ! defined (FIOSNBIO) */
3288 #if 0 /* This code can't be made to work, with multiple displays,
3289 and appears not to be used on any system any more.
3290 Also keyboard.c doesn't turn O_NDELAY on and off
3291 for X connections. */
3294 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
3296 extern int read_alarm_should_throw
;
3297 read_alarm_should_throw
= 1;
3298 XPeekEvent (dpyinfo
->display
, &event
);
3299 read_alarm_should_throw
= 0;
3301 #endif /* HAVE_SELECT */
3305 /* For debugging, this gives a way to fake an I/O error. */
3306 if (dpyinfo
== XTread_socket_fake_io_error
)
3308 XTread_socket_fake_io_error
= 0;
3309 x_io_error_quitter (dpyinfo
->display
);
3312 while (XPending (dpyinfo
->display
) != 0)
3314 XNextEvent (dpyinfo
->display
, &event
);
3321 if (event
.xclient
.message_type
3322 == dpyinfo
->Xatom_wm_protocols
3323 && event
.xclient
.format
== 32)
3325 if (event
.xclient
.data
.l
[0]
3326 == dpyinfo
->Xatom_wm_take_focus
)
3328 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3329 /* Since we set WM_TAKE_FOCUS, we must call
3330 XSetInputFocus explicitly. But not if f is null,
3331 since that might be an event for a deleted frame. */
3333 XSetInputFocus (event
.xclient
.display
,
3334 event
.xclient
.window
,
3335 RevertToPointerRoot
,
3336 event
.xclient
.data
.l
[1]);
3337 /* Not certain about handling scroll bars here */
3339 else if (event
.xclient
.data
.l
[0]
3340 == dpyinfo
->Xatom_wm_save_yourself
)
3342 /* Save state modify the WM_COMMAND property to
3343 something which can reinstate us. This notifies
3344 the session manager, who's looking for such a
3345 PropertyNotify. Can restart processing when
3346 a keyboard or mouse event arrives. */
3349 f
= x_top_window_to_frame (dpyinfo
,
3350 event
.xclient
.window
);
3352 /* This is just so we only give real data once
3353 for a single Emacs process. */
3354 if (f
== selected_frame
)
3355 XSetCommand (FRAME_X_DISPLAY (f
),
3356 event
.xclient
.window
,
3357 initial_argv
, initial_argc
);
3359 XSetCommand (FRAME_X_DISPLAY (f
),
3360 event
.xclient
.window
,
3364 else if (event
.xclient
.data
.l
[0]
3365 == dpyinfo
->Xatom_wm_delete_window
)
3368 = x_any_window_to_frame (dpyinfo
,
3369 event
.xclient
.window
);
3376 bufp
->kind
= delete_window_event
;
3377 XSETFRAME (bufp
->frame_or_window
, f
);
3385 else if (event
.xclient
.message_type
3386 == dpyinfo
->Xatom_wm_configure_denied
)
3389 else if (event
.xclient
.message_type
3390 == dpyinfo
->Xatom_wm_window_moved
)
3394 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3396 new_x
= event
.xclient
.data
.s
[0];
3397 new_y
= event
.xclient
.data
.s
[1];
3401 f
->display
.x
->left_pos
= new_x
;
3402 f
->display
.x
->top_pos
= new_y
;
3405 #if defined (USE_X_TOOLKIT) && defined (HAVE_X11R5)
3406 else if (event
.xclient
.message_type
3407 == dpyinfo
->Xatom_editres
)
3410 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
3411 _XEditResCheckMessages (f
->display
.x
->widget
, NULL
,
3414 #endif /* USE_X_TOOLKIT and HAVE_X11R5 */
3418 case SelectionNotify
:
3419 #ifdef USE_X_TOOLKIT
3420 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
3422 #endif /* not USE_X_TOOLKIT */
3423 x_handle_selection_notify (&event
);
3426 case SelectionClear
: /* Someone has grabbed ownership. */
3427 #ifdef USE_X_TOOLKIT
3428 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
3430 #endif /* USE_X_TOOLKIT */
3432 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
3437 bufp
->kind
= selection_clear_event
;
3438 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3439 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3440 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3448 case SelectionRequest
: /* Someone wants our selection. */
3449 #ifdef USE_X_TOOLKIT
3450 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
3452 #endif /* USE_X_TOOLKIT */
3453 if (x_queue_selection_requests
)
3454 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
3458 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
3463 bufp
->kind
= selection_request_event
;
3464 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3465 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
3466 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3467 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
3468 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
3469 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3477 case PropertyNotify
:
3478 #ifdef USE_X_TOOLKIT
3479 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
3481 #endif /* not USE_X_TOOLKIT */
3482 x_handle_property_notify (&event
);
3485 case ReparentNotify
:
3486 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
3490 f
->display
.x
->parent_desc
= event
.xreparent
.parent
;
3491 x_real_positions (f
, &x
, &y
);
3492 f
->display
.x
->left_pos
= x
;
3493 f
->display
.x
->top_pos
= y
;
3498 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3501 if (f
->async_visible
== 0)
3503 f
->async_visible
= 1;
3504 f
->async_iconified
= 0;
3505 SET_FRAME_GARBAGED (f
);
3508 dumprectangle (x_window_to_frame (dpyinfo
,
3509 event
.xexpose
.window
),
3510 event
.xexpose
.x
, event
.xexpose
.y
,
3511 event
.xexpose
.width
, event
.xexpose
.height
);
3515 struct scroll_bar
*bar
3516 = x_window_to_scroll_bar (event
.xexpose
.window
);
3519 x_scroll_bar_expose (bar
, &event
);
3520 #ifdef USE_X_TOOLKIT
3523 #endif /* USE_X_TOOLKIT */
3527 case GraphicsExpose
: /* This occurs when an XCopyArea's
3528 source area was obscured or not
3530 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
3534 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
3535 event
.xgraphicsexpose
.width
,
3536 event
.xgraphicsexpose
.height
);
3538 #ifdef USE_X_TOOLKIT
3541 #endif /* USE_X_TOOLKIT */
3544 case NoExpose
: /* This occurs when an XCopyArea's
3545 source area was completely
3550 f
= x_any_window_to_frame (dpyinfo
, event
.xunmap
.window
);
3551 if (f
) /* F may no longer exist if
3552 the frame was deleted. */
3554 /* While a frame is unmapped, display generation is
3555 disabled; you don't want to spend time updating a
3556 display that won't ever be seen. */
3557 f
->async_visible
= 0;
3558 /* We can't distinguish, from the event, whether the window
3559 has become iconified or invisible. So assume, if it
3560 was previously visible, than now it is iconified.
3561 We depend on x_make_frame_invisible to mark it iconified. */
3562 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
3563 f
->async_iconified
= 1;
3565 bufp
->kind
= iconify_event
;
3566 XSETFRAME (bufp
->frame_or_window
, f
);
3571 #ifdef USE_X_TOOLKIT
3573 #endif /* USE_X_TOOLKIT */
3577 /* We use x_top_window_to_frame because map events can come
3578 for subwindows and they don't mean that the frame is visible. */
3579 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
3582 f
->async_visible
= 1;
3583 f
->async_iconified
= 0;
3585 /* wait_reading_process_input will notice this and update
3586 the frame's display structures. */
3587 SET_FRAME_GARBAGED (f
);
3591 bufp
->kind
= deiconify_event
;
3592 XSETFRAME (bufp
->frame_or_window
, f
);
3598 /* Force a redisplay sooner or later
3599 to update the frame titles
3600 in case this is the second frame. */
3601 record_asynch_buffer_change ();
3603 #ifdef USE_X_TOOLKIT
3605 #endif /* USE_X_TOOLKIT */
3608 /* Turn off processing if we become fully obscured. */
3609 case VisibilityNotify
:
3613 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
3617 KeySym keysym
, orig_keysym
;
3618 /* al%imercury@uunet.uu.net says that making this 81 instead of
3619 80 fixed a bug whereby meta chars made his Emacs hang. */
3620 unsigned char copy_buffer
[81];
3624 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
3625 extra_keyboard_modifiers
);
3626 modifiers
= event
.xkey
.state
;
3628 /* This will have to go some day... */
3630 /* make_lispy_event turns chars into control chars.
3631 Don't do it here because XLookupString is too eager. */
3632 event
.xkey
.state
&= ~ControlMask
;
3633 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
3634 | dpyinfo
->super_mod_mask
3635 | dpyinfo
->hyper_mod_mask
3636 | dpyinfo
->alt_mod_mask
);
3638 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
3639 80, &keysym
, &compose_status
);
3641 orig_keysym
= keysym
;
3645 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
3646 || keysym
== XK_Delete
3647 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
3648 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
3650 /* This recognizes the "extended function keys".
3651 It seems there's no cleaner way.
3652 Test IsModifierKey to avoid handling mode_switch
3654 || ((unsigned) (keysym
) >= XK_Select
3655 && (unsigned)(keysym
) < XK_KP_Space
)
3657 #ifdef XK_dead_circumflex
3658 || orig_keysym
== XK_dead_circumflex
3660 #ifdef XK_dead_grave
3661 || orig_keysym
== XK_dead_grave
3663 #ifdef XK_dead_tilde
3664 || orig_keysym
== XK_dead_tilde
3666 #ifdef XK_dead_diaeresis
3667 || orig_keysym
== XK_dead_diaeresis
3669 #ifdef XK_dead_macron
3670 || orig_keysym
== XK_dead_macron
3672 #ifdef XK_dead_degree
3673 || orig_keysym
== XK_dead_degree
3675 #ifdef XK_dead_acute
3676 || orig_keysym
== XK_dead_acute
3678 #ifdef XK_dead_cedilla
3679 || orig_keysym
== XK_dead_cedilla
3681 #ifdef XK_dead_breve
3682 || orig_keysym
== XK_dead_breve
3684 #ifdef XK_dead_ogonek
3685 || orig_keysym
== XK_dead_ogonek
3687 #ifdef XK_dead_caron
3688 || orig_keysym
== XK_dead_caron
3690 #ifdef XK_dead_doubleacute
3691 || orig_keysym
== XK_dead_doubleacute
3693 #ifdef XK_dead_abovedot
3694 || orig_keysym
== XK_dead_abovedot
3696 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
3697 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
3698 /* Any "vendor-specific" key is ok. */
3699 || (orig_keysym
& (1 << 28)))
3700 && ! (IsModifierKey (orig_keysym
)
3702 #ifdef XK_Mode_switch
3703 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
3706 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
3708 #endif /* not HAVE_X11R5 */
3711 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3713 temp_buffer
[temp_index
++] = keysym
;
3714 bufp
->kind
= non_ascii_keystroke
;
3715 bufp
->code
= keysym
;
3716 XSETFRAME (bufp
->frame_or_window
, f
);
3718 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3720 bufp
->timestamp
= event
.xkey
.time
;
3725 else if (numchars
> nbytes
)
3729 for (i
= 0; i
< nbytes
; i
++)
3731 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3733 temp_buffer
[temp_index
++] = copy_buffer
[i
];
3734 bufp
->kind
= ascii_keystroke
;
3735 bufp
->code
= copy_buffer
[i
];
3736 XSETFRAME (bufp
->frame_or_window
, f
);
3738 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3740 bufp
->timestamp
= event
.xkey
.time
;
3755 /* Here's a possible interpretation of the whole
3756 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
3757 FocusIn event, you have to get a FocusOut event before you
3758 relinquish the focus. If you haven't received a FocusIn event,
3759 then a mere LeaveNotify is enough to free you. */
3762 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
3764 if (event
.xcrossing
.focus
) /* Entered Window */
3766 /* Avoid nasty pop/raise loops. */
3767 if (f
&& (!(f
->auto_raise
)
3769 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
3771 x_new_focus_frame (dpyinfo
, f
);
3772 enter_timestamp
= event
.xcrossing
.time
;
3775 else if (f
== dpyinfo
->x_focus_frame
)
3776 x_new_focus_frame (dpyinfo
, 0);
3777 /* EnterNotify counts as mouse movement,
3778 so update things that depend on mouse position. */
3780 note_mouse_movement (f
, &event
.xmotion
);
3781 #ifdef USE_X_TOOLKIT
3783 #endif /* USE_X_TOOLKIT */
3787 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
3788 if (event
.xfocus
.detail
!= NotifyPointer
)
3789 dpyinfo
->x_focus_event_frame
= f
;
3791 x_new_focus_frame (dpyinfo
, f
);
3792 #ifdef USE_X_TOOLKIT
3794 #endif /* USE_X_TOOLKIT */
3799 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
3802 if (f
== dpyinfo
->mouse_face_mouse_frame
)
3803 /* If we move outside the frame,
3804 then we're certainly no longer on any text in the frame. */
3805 clear_mouse_face (dpyinfo
);
3807 if (event
.xcrossing
.focus
)
3808 x_mouse_leave (dpyinfo
);
3811 if (f
== dpyinfo
->x_focus_event_frame
)
3812 dpyinfo
->x_focus_event_frame
= 0;
3813 if (f
== dpyinfo
->x_focus_frame
)
3814 x_new_focus_frame (dpyinfo
, 0);
3817 #ifdef USE_X_TOOLKIT
3819 #endif /* USE_X_TOOLKIT */
3823 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
3824 if (event
.xfocus
.detail
!= NotifyPointer
3825 && f
== dpyinfo
->x_focus_event_frame
)
3826 dpyinfo
->x_focus_event_frame
= 0;
3827 if (f
&& f
== dpyinfo
->x_focus_frame
)
3828 x_new_focus_frame (dpyinfo
, 0);
3829 #ifdef USE_X_TOOLKIT
3831 #endif /* USE_X_TOOLKIT */
3836 if (dpyinfo
->grabbed
&& last_mouse_frame
3837 && FRAME_LIVE_P (last_mouse_frame
))
3838 f
= last_mouse_frame
;
3840 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
3842 note_mouse_movement (f
, &event
.xmotion
);
3845 struct scroll_bar
*bar
3846 = x_window_to_scroll_bar (event
.xmotion
.window
);
3849 x_scroll_bar_note_movement (bar
, &event
);
3851 /* If we move outside the frame,
3852 then we're certainly no longer on any text in the frame. */
3853 clear_mouse_face (dpyinfo
);
3856 #ifdef USE_X_TOOLKIT
3858 #endif /* USE_X_TOOLKIT */
3861 case ConfigureNotify
:
3862 f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
3864 #ifdef USE_X_TOOLKIT
3865 && (event
.xconfigure
.window
== XtWindow (f
->display
.x
->widget
))
3869 #ifndef USE_X_TOOLKIT
3870 /* In the toolkit version, change_frame_size
3871 is called by the code that handles resizing
3872 of the EmacsFrame widget. */
3874 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
3875 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
3877 /* Even if the number of character rows and columns has
3878 not changed, the font size may have changed, so we need
3879 to check the pixel dimensions as well. */
3880 if (columns
!= f
->width
3881 || rows
!= f
->height
3882 || event
.xconfigure
.width
!= f
->display
.x
->pixel_width
3883 || event
.xconfigure
.height
!= f
->display
.x
->pixel_height
)
3885 change_frame_size (f
, rows
, columns
, 0, 1);
3886 SET_FRAME_GARBAGED (f
);
3890 /* Formerly, in the USE_X_TOOLKIT version,
3891 we did not test send_event here. */
3893 #ifndef USE_X_TOOLKIT
3894 && ! event
.xconfigure
.send_event
3901 /* Find the position of the outside upper-left corner of
3902 the window, in the root coordinate system. Don't
3903 refer to the parent window here; we may be processing
3904 this event after the window manager has changed our
3905 parent, but before we have reached the ReparentNotify. */
3906 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
3908 /* From-window, to-window. */
3909 event
.xconfigure
.window
,
3910 FRAME_X_DISPLAY_INFO (f
)->root_window
,
3912 /* From-position, to-position. */
3913 -event
.xconfigure
.border_width
,
3914 -event
.xconfigure
.border_width
,
3919 event
.xconfigure
.x
= win_x
;
3920 event
.xconfigure
.y
= win_y
;
3923 f
->display
.x
->pixel_width
= event
.xconfigure
.width
;
3924 f
->display
.x
->pixel_height
= event
.xconfigure
.height
;
3925 f
->display
.x
->left_pos
= event
.xconfigure
.x
;
3926 f
->display
.x
->top_pos
= event
.xconfigure
.y
;
3928 /* What we have now is the position of Emacs's own window.
3929 Convert that to the position of the window manager window. */
3932 x_real_positions (f
, &x
, &y
);
3933 f
->display
.x
->left_pos
= x
;
3934 f
->display
.x
->top_pos
= y
;
3935 /* Formerly we did not do this in the USE_X_TOOLKIT
3936 version. Let's try making them the same. */
3937 /* #ifndef USE_X_TOOLKIT */
3938 if (y
!= event
.xconfigure
.y
)
3940 /* Since the WM decorations come below top_pos now,
3941 we must put them below top_pos in the future. */
3942 f
->display
.x
->win_gravity
= NorthWestGravity
;
3943 x_wm_set_size_hint (f
, (long) 0, 0);
3948 #ifdef USE_X_TOOLKIT
3957 /* If we decide we want to generate an event to be seen
3958 by the rest of Emacs, we put it here. */
3959 struct input_event emacs_event
;
3960 emacs_event
.kind
= no_event
;
3962 bzero (&compose_status
, sizeof (compose_status
));
3964 if (dpyinfo
->grabbed
&& last_mouse_frame
3965 && FRAME_LIVE_P (last_mouse_frame
))
3966 f
= last_mouse_frame
;
3968 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
3972 if (!dpyinfo
->x_focus_frame
|| f
== dpyinfo
->x_focus_frame
)
3973 construct_mouse_click (&emacs_event
, &event
, f
);
3977 struct scroll_bar
*bar
3978 = x_window_to_scroll_bar (event
.xbutton
.window
);
3981 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
3982 #if 0 /* It doesn't make sense to do this.
3983 Menu bar clicks are handled within the toolkit itself. */
3984 #ifdef USE_X_TOOLKIT
3987 /* Assume we have a menubar button press. A bad
3988 assumption should behave benignly. */
3989 popup_get_selection (&event
, dpyinfo
);
3992 #endif /* USE_X_TOOLKIT */
3996 if (event
.type
== ButtonPress
)
3998 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
3999 last_mouse_frame
= f
;
4003 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
4006 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
4008 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
4014 #ifdef USE_X_TOOLKIT
4016 #endif /* USE_X_TOOLKIT */
4020 case CirculateNotify
:
4022 case CirculateRequest
:
4026 /* Someone has changed the keyboard mapping - update the
4028 switch (event
.xmapping
.request
)
4030 case MappingModifier
:
4031 x_find_modifier_meanings (dpyinfo
);
4032 /* This is meant to fall through. */
4033 case MappingKeyboard
:
4034 XRefreshKeyboardMapping (&event
.xmapping
);
4036 #ifdef USE_X_TOOLKIT
4038 #endif /* USE_X_TOOLKIT */
4042 #ifdef USE_X_TOOLKIT
4045 XtDispatchEvent (&event
);
4047 #endif /* USE_X_TOOLKIT */
4053 /* On some systems, an X bug causes Emacs to get no more events
4054 when the window is destroyed. Detect that. (1994.) */
4057 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
4058 One XNOOP in 100 loops will make Emacs terminate.
4059 B. Bretthauer, 1994 */
4061 if (x_noop_count
>= 100)
4064 /* Use the first display in the list. Why not? */
4065 XNoOp (x_display_list
->display
);
4069 /* If the focus was just given to an autoraising frame,
4071 /* ??? This ought to be able to handle more than one such frame. */
4072 if (pending_autoraise_frame
)
4074 x_raise_frame (pending_autoraise_frame
);
4075 pending_autoraise_frame
= 0;
4082 /* Drawing the cursor. */
4085 /* Draw a hollow box cursor on frame F at X, Y.
4086 Don't change the inside of the box. */
4089 x_draw_box (f
, x
, y
)
4093 int left
= CHAR_TO_PIXEL_COL (f
, x
);
4094 int top
= CHAR_TO_PIXEL_ROW (f
, y
);
4095 int width
= FONT_WIDTH (f
->display
.x
->font
);
4096 int height
= f
->display
.x
->line_height
;
4098 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4099 f
->display
.x
->cursor_gc
,
4100 left
, top
, width
- 1, height
- 1);
4103 /* Clear the cursor of frame F to background color,
4104 and mark the cursor as not shown.
4105 This is used when the text where the cursor is
4106 is about to be rewritten. */
4114 if (! FRAME_VISIBLE_P (f
)
4115 || f
->phys_cursor_x
< 0)
4118 x_display_cursor (f
, 0);
4119 f
->phys_cursor_x
= -1;
4122 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4123 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4127 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
4134 CHAR_TO_PIXEL_COL (f
, column
),
4135 CHAR_TO_PIXEL_ROW (f
, row
),
4136 &glyph
, 1, highlight
, 0);
4140 x_display_bar_cursor (f
, on
, x
, y
)
4145 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4147 /* This is pointless on invisible frames, and dangerous on garbaged
4148 frames; in the latter case, the frame may be in the midst of
4149 changing its size, and x and y may be off the frame. */
4150 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4153 if (! on
&& f
->phys_cursor_x
< 0)
4156 /* If there is anything wrong with the current cursor state, remove it. */
4157 if (f
->phys_cursor_x
>= 0
4159 || f
->phys_cursor_x
!= x
4160 || f
->phys_cursor_y
!= y
4161 || f
->display
.x
->current_cursor
!= bar_cursor
))
4163 /* Erase the cursor by redrawing the character underneath it. */
4164 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4165 f
->phys_cursor_glyph
,
4166 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4167 f
->phys_cursor_x
= -1;
4170 /* If we now need a cursor in the new place or in the new form, do it so. */
4172 && (f
->phys_cursor_x
< 0
4173 || (f
->display
.x
->current_cursor
!= bar_cursor
)))
4175 f
->phys_cursor_glyph
4176 = ((current_glyphs
->enable
[y
]
4177 && x
< current_glyphs
->used
[y
])
4178 ? current_glyphs
->glyphs
[y
][x
]
4180 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4181 f
->display
.x
->cursor_gc
,
4182 CHAR_TO_PIXEL_COL (f
, x
),
4183 CHAR_TO_PIXEL_ROW (f
, y
),
4184 max (f
->display
.x
->cursor_width
, 1),
4185 f
->display
.x
->line_height
);
4187 f
->phys_cursor_x
= x
;
4188 f
->phys_cursor_y
= y
;
4190 f
->display
.x
->current_cursor
= bar_cursor
;
4193 if (updating_frame
!= f
)
4194 XFlush (FRAME_X_DISPLAY (f
));
4198 /* Turn the displayed cursor of frame F on or off according to ON.
4199 If ON is nonzero, where to put the cursor is specified by X and Y. */
4202 x_display_box_cursor (f
, on
, x
, y
)
4207 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4209 /* This is pointless on invisible frames, and dangerous on garbaged
4210 frames; in the latter case, the frame may be in the midst of
4211 changing its size, and x and y may be off the frame. */
4212 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4215 /* If cursor is off and we want it off, return quickly. */
4216 if (!on
&& f
->phys_cursor_x
< 0)
4219 /* If cursor is currently being shown and we don't want it to be
4220 or it is in the wrong place,
4221 or we want a hollow box and it's not so, (pout!)
4223 if (f
->phys_cursor_x
>= 0
4225 || f
->phys_cursor_x
!= x
4226 || f
->phys_cursor_y
!= y
4227 || (f
->display
.x
->current_cursor
!= hollow_box_cursor
4228 && (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
))))
4230 int mouse_face_here
= 0;
4231 struct frame_glyphs
*active_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4233 /* If the cursor is in the mouse face area, redisplay that when
4234 we clear the cursor. */
4235 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
4237 (f
->phys_cursor_y
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4238 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4239 && f
->phys_cursor_x
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
))
4241 (f
->phys_cursor_y
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4242 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4243 && f
->phys_cursor_x
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
))
4244 /* Don't redraw the cursor's spot in mouse face
4245 if it is at the end of a line (on a newline).
4246 The cursor appears there, but mouse highlighting does not. */
4247 && active_glyphs
->used
[f
->phys_cursor_y
] > f
->phys_cursor_x
)
4248 mouse_face_here
= 1;
4250 /* If the font is not as tall as a whole line,
4251 we must explicitly clear the line's whole height. */
4252 if (FONT_HEIGHT (f
->display
.x
->font
) != f
->display
.x
->line_height
)
4253 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4254 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
4255 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
4256 FONT_WIDTH (f
->display
.x
->font
),
4257 f
->display
.x
->line_height
, False
);
4258 /* Erase the cursor by redrawing the character underneath it. */
4259 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4260 f
->phys_cursor_glyph
,
4263 : current_glyphs
->highlight
[f
->phys_cursor_y
]));
4264 f
->phys_cursor_x
= -1;
4267 /* If we want to show a cursor,
4268 or we want a box cursor and it's not so,
4269 write it in the right place. */
4271 && (f
->phys_cursor_x
< 0
4272 || (f
->display
.x
->current_cursor
!= filled_box_cursor
4273 && f
== FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)))
4275 f
->phys_cursor_glyph
4276 = ((current_glyphs
->enable
[y
]
4277 && x
< current_glyphs
->used
[y
])
4278 ? current_glyphs
->glyphs
[y
][x
]
4280 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
4282 x_draw_box (f
, x
, y
);
4283 f
->display
.x
->current_cursor
= hollow_box_cursor
;
4287 x_draw_single_glyph (f
, y
, x
,
4288 f
->phys_cursor_glyph
, 2);
4289 f
->display
.x
->current_cursor
= filled_box_cursor
;
4292 f
->phys_cursor_x
= x
;
4293 f
->phys_cursor_y
= y
;
4296 if (updating_frame
!= f
)
4297 XFlush (FRAME_X_DISPLAY (f
));
4300 /* Display the cursor on frame F, or clear it, according to ON.
4301 Use the position specified by curs_x and curs_y
4302 if we are doing an update of frame F now.
4303 Otherwise use the position in the FRAME_CURSOR_X and FRAME_CURSOR_Y fields
4306 x_display_cursor (f
, on
)
4312 /* If we're not updating, then don't change the physical cursor
4313 position. Just change (if appropriate) the style of display. */
4314 if (f
!= updating_frame
)
4316 curs_x
= FRAME_CURSOR_X (f
);
4317 curs_y
= FRAME_CURSOR_Y (f
);
4320 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4321 x_display_box_cursor (f
, on
, curs_x
, curs_y
);
4322 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4323 x_display_bar_cursor (f
, on
, curs_x
, curs_y
);
4325 /* Those are the only two we have implemented! */
4331 /* Display the cursor on frame F, or clear it, according to ON.
4332 Don't change the cursor's position. */
4334 x_update_cursor (f
, on
)
4340 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4341 x_display_box_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4342 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4343 x_display_bar_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4345 /* Those are the only two we have implemented! */
4353 /* Refresh bitmap kitchen sink icon for frame F
4354 when we get an expose event for it. */
4359 /* Normally, the window manager handles this function. */
4362 /* Make the x-window of frame F use the gnu icon bitmap. */
4365 x_bitmap_icon (f
, file
)
4369 int mask
, bitmap_id
;
4372 if (FRAME_X_WINDOW (f
) == 0)
4375 /* Free up our existing icon bitmap if any. */
4376 if (f
->display
.x
->icon_bitmap
> 0)
4377 x_destroy_bitmap (f
, f
->display
.x
->icon_bitmap
);
4378 f
->display
.x
->icon_bitmap
= 0;
4381 bitmap_id
= x_create_bitmap_from_file (f
, file
);
4384 /* Create the GNU bitmap if necessary. */
4385 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
4386 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
4387 = x_create_bitmap_from_data (f
, gnu_bits
,
4388 gnu_width
, gnu_height
);
4390 /* The first time we create the GNU bitmap,
4391 this increments the refcount one extra time.
4392 As a result, the GNU bitmap is never freed.
4393 That way, we don't have to worry about allocating it again. */
4394 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
4396 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
4399 x_wm_set_icon_pixmap (f
, bitmap_id
);
4400 f
->display
.x
->icon_bitmap
= bitmap_id
;
4406 /* Make the x-window of frame F use a rectangle with text.
4407 Use ICON_NAME as the text. */
4410 x_text_icon (f
, icon_name
)
4414 if (FRAME_X_WINDOW (f
) == 0)
4420 text
.value
= (unsigned char *) icon_name
;
4421 text
.encoding
= XA_STRING
;
4423 text
.nitems
= strlen (icon_name
);
4424 #ifdef USE_X_TOOLKIT
4425 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
),
4427 #else /* not USE_X_TOOLKIT */
4428 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
4429 #endif /* not USE_X_TOOLKIT */
4431 #else /* not HAVE_X11R4 */
4432 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
4433 #endif /* not HAVE_X11R4 */
4435 if (f
->display
.x
->icon_bitmap
> 0)
4436 x_destroy_bitmap (f
, f
->display
.x
->icon_bitmap
);
4437 f
->display
.x
->icon_bitmap
= 0;
4438 x_wm_set_icon_pixmap (f
, 0);
4443 /* Handling X errors. */
4445 /* Handle the loss of connection to display DISPLAY. */
4448 x_connection_closed (display
, error_message
)
4450 char *error_message
;
4452 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
4453 Lisp_Object frame
, tail
;
4455 /* Whatever we were in the middle of, we are going to throw out of it,
4456 so reassure various things that have error checks about being
4457 called with input blocked. */
4458 TOTALLY_UNBLOCK_INPUT
;
4463 /* First delete frames whose minibuffers are on frames
4464 that are on the dead display. */
4465 FOR_EACH_FRAME (tail
, frame
)
4467 Lisp_Object minibuf_frame
;
4469 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
4470 if (FRAME_X_P (XFRAME (frame
))
4471 && FRAME_X_P (XFRAME (minibuf_frame
))
4472 && ! EQ (frame
, minibuf_frame
)
4473 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
4474 Fdelete_frame (frame
, Qt
);
4477 /* Now delete all remaining frames on the dead display.
4478 We are now sure none of these is used as the minibuffer
4479 for another frame that we need to delete. */
4480 FOR_EACH_FRAME (tail
, frame
)
4481 if (FRAME_X_P (XFRAME (frame
))
4482 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
4484 /* Set this to t so that Fdelete_frame won't get confused
4485 trying to find a replacement. */
4486 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
4487 Fdelete_frame (frame
, Qt
);
4490 x_delete_display (dpyinfo
);
4492 if (x_display_list
== 0)
4494 fprintf (stderr
, "%s", error_message
);
4495 shut_down_emacs (0, 0, Qnil
);
4499 /* Ordinary stack unwind doesn't deal with these. */
4501 sigunblock (sigmask (SIGIO
));
4503 sigunblock (sigmask (SIGALRM
));
4504 TOTALLY_UNBLOCK_INPUT
;
4506 error ("%s", error_message
);
4510 x_connection_signal (signalnum
) /* If we don't have an argument, */
4511 int signalnum
; /* some compilers complain in signal calls. */
4513 /* We really ought to close the connection to the display
4514 that actually failed.
4515 But do we actually get this signal ever with X11? */
4516 fprintf (stderr
, "X connection closed");
4517 shut_down_emacs (0, 0, Qnil
);
4521 /* This is the usual handler for X protocol errors.
4522 It kills all frames on the display that we got the error for.
4523 If that was the only one, it prints an error message and kills Emacs. */
4526 x_error_quitter (display
, error
)
4530 char buf
[256], buf1
[356];
4532 /* Note that there is no real way portable across R3/R4 to get the
4533 original error handler. */
4535 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
4536 sprintf (buf1
, "X protocol error: %s on protocol request %d",
4537 buf
, error
->request_code
);
4538 x_connection_closed (display
, buf1
);
4541 /* This is the handler for X IO errors, always.
4542 It kills all frames on the display that we lost touch with.
4543 If that was the only one, it prints an error message and kills Emacs. */
4546 x_io_error_quitter (display
)
4551 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
4552 x_connection_closed (display
, buf
);
4555 /* A buffer for storing X error messages. */
4556 static char *x_caught_error_message
;
4557 #define X_CAUGHT_ERROR_MESSAGE_SIZE 200
4559 /* An X error handler which stores the error message in
4560 x_caught_error_message. This is what's installed when
4561 x_catch_errors is in effect. */
4564 x_error_catcher (display
, error
)
4568 XGetErrorText (display
, error
->error_code
,
4569 x_caught_error_message
, X_CAUGHT_ERROR_MESSAGE_SIZE
);
4573 /* Begin trapping X errors for display DPY. Actually we trap X errors
4574 for all displays, but DPY should be the display you are actually
4577 After calling this function, X protocol errors no longer cause
4578 Emacs to exit; instead, they are recorded in x_cfc_error_message.
4580 Calling x_check_errors signals an Emacs error if an X error has
4581 occurred since the last call to x_catch_errors or x_check_errors.
4583 Calling x_uncatch_errors resumes the normal error handling. */
4585 void x_catch_errors (), x_check_errors (), x_uncatch_errors ();
4588 x_catch_errors (dpy
)
4591 /* Make sure any errors from previous requests have been dealt with. */
4594 /* Set up the error buffer. */
4595 x_caught_error_message
4596 = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE
);
4597 x_caught_error_message
[0] = '\0';
4599 /* Install our little error handler. */
4600 XSetErrorHandler (x_error_catcher
);
4603 /* If any X protocol errors have arrived since the last call to
4604 x_catch_errors or x_check_errors, signal an Emacs error using
4605 sprintf (a buffer, FORMAT, the x error message text) as the text. */
4608 x_check_errors (dpy
, format
)
4612 /* Make sure to catch any errors incurred so far. */
4615 if (x_caught_error_message
[0])
4617 char buf
[X_CAUGHT_ERROR_MESSAGE_SIZE
+ 56];
4619 sprintf (buf
, format
, x_caught_error_message
);
4620 x_uncatch_errors (dpy
);
4625 /* Nonzero if we had any X protocol errors since we did x_catch_errors. */
4628 x_had_errors_p (dpy
)
4631 /* Make sure to catch any errors incurred so far. */
4634 return x_caught_error_message
[0] != 0;
4637 /* Stop catching X protocol errors and let them make Emacs die. */
4640 x_uncatch_errors (dpy
)
4643 xfree (x_caught_error_message
);
4644 x_caught_error_message
= 0;
4645 XSetErrorHandler (x_error_quitter
);
4649 static unsigned int x_wire_count
;
4652 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
4657 /* Changing the font of the frame. */
4659 /* Give frame F the font named FONTNAME as its default font, and
4660 return the full name of that font. FONTNAME may be a wildcard
4661 pattern; in that case, we choose some font that fits the pattern.
4662 The return value shows which font we chose. */
4665 x_new_font (f
, fontname
)
4667 register char *fontname
;
4670 int n_matching_fonts
;
4671 XFontStruct
*font_info
;
4674 /* Get a list of all the fonts that match this name. Once we
4675 have a list of matching fonts, we compare them against the fonts
4676 we already have by comparing font ids. */
4677 font_names
= (char **) XListFonts (FRAME_X_DISPLAY (f
), fontname
,
4678 1024, &n_matching_fonts
);
4679 /* Apparently it doesn't set n_matching_fonts to zero when it can't
4680 find any matches; font_names == 0 is the only clue. */
4682 n_matching_fonts
= 0;
4684 /* Don't just give up if n_matching_fonts is 0.
4685 Apparently there's a bug on Suns: XListFontsWithInfo can
4686 fail to find a font, but XLoadQueryFont may still find it. */
4688 /* See if we've already loaded a matching font. */
4689 already_loaded
= -1;
4690 if (n_matching_fonts
!= 0)
4694 for (i
= 0; i
< FRAME_X_DISPLAY_INFO (f
)->n_fonts
; i
++)
4695 for (j
= 0; j
< n_matching_fonts
; j
++)
4696 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].name
, font_names
[j
])
4697 || !strcmp (FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].full_name
, font_names
[j
]))
4700 fontname
= FRAME_X_DISPLAY_INFO (f
)->font_table
[i
].full_name
;
4706 /* If we have, just return it from the table. */
4707 if (already_loaded
>= 0)
4708 f
->display
.x
->font
= FRAME_X_DISPLAY_INFO (f
)->font_table
[already_loaded
].font
;
4709 /* Otherwise, load the font and add it to the table. */
4717 /* Try to find a character-cell font in the list. */
4719 /* A laudable goal, but this isn't how to do it. */
4720 for (i
= 0; i
< n_matching_fonts
; i
++)
4721 if (! font_info
[i
].per_char
)
4727 /* See comment above. */
4728 if (n_matching_fonts
!= 0)
4729 fontname
= font_names
[i
];
4731 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
4734 /* Free the information from XListFonts. */
4735 if (n_matching_fonts
)
4736 XFreeFontNames (font_names
);
4740 /* Do we need to create the table? */
4741 if (FRAME_X_DISPLAY_INFO (f
)->font_table_size
== 0)
4743 FRAME_X_DISPLAY_INFO (f
)->font_table_size
= 16;
4744 FRAME_X_DISPLAY_INFO (f
)->font_table
4745 = (struct font_info
*) xmalloc (FRAME_X_DISPLAY_INFO (f
)->font_table_size
4746 * sizeof (struct font_info
));
4748 /* Do we need to grow the table? */
4749 else if (FRAME_X_DISPLAY_INFO (f
)->n_fonts
4750 >= FRAME_X_DISPLAY_INFO (f
)->font_table_size
)
4752 FRAME_X_DISPLAY_INFO (f
)->font_table_size
*= 2;
4753 FRAME_X_DISPLAY_INFO (f
)->font_table
4754 = (struct font_info
*) xrealloc (FRAME_X_DISPLAY_INFO (f
)->font_table
,
4755 (FRAME_X_DISPLAY_INFO (f
)->font_table_size
4756 * sizeof (struct font_info
)));
4759 /* Try to get the full name of FONT. Put it in full_name. */
4761 for (i
= 0; i
< font
->n_properties
; i
++)
4764 = XGetAtomName (FRAME_X_DISPLAY (f
), font
->properties
[i
].name
);
4765 if (!strcmp (atom
, "FONT"))
4767 char *name
= XGetAtomName (FRAME_X_DISPLAY (f
),
4768 (Atom
) (font
->properties
[i
].card32
));
4772 /* Count the number of dashes in the "full name".
4773 If it is too few, this isn't really the font's full name,
4775 In X11R4, the fonts did not come with their canonical names
4793 n_fonts
= FRAME_X_DISPLAY_INFO (f
)->n_fonts
;
4794 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
= (char *) xmalloc (strlen (fontname
) + 1);
4795 bcopy (fontname
, FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
, strlen (fontname
) + 1);
4797 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].full_name
= full_name
;
4799 FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].full_name
= FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].name
;
4800 f
->display
.x
->font
= FRAME_X_DISPLAY_INFO (f
)->font_table
[n_fonts
].font
= font
;
4801 FRAME_X_DISPLAY_INFO (f
)->n_fonts
++;
4804 fontname
= full_name
;
4807 /* Compute the scroll bar width in character columns. */
4808 if (f
->scroll_bar_pixel_width
> 0)
4810 int wid
= FONT_WIDTH (f
->display
.x
->font
);
4811 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
4814 f
->scroll_bar_cols
= 2;
4816 /* Now make the frame display the given font. */
4817 if (FRAME_X_WINDOW (f
) != 0)
4819 XSetFont (FRAME_X_DISPLAY (f
), f
->display
.x
->normal_gc
,
4820 f
->display
.x
->font
->fid
);
4821 XSetFont (FRAME_X_DISPLAY (f
), f
->display
.x
->reverse_gc
,
4822 f
->display
.x
->font
->fid
);
4823 XSetFont (FRAME_X_DISPLAY (f
), f
->display
.x
->cursor_gc
,
4824 f
->display
.x
->font
->fid
);
4826 frame_update_line_height (f
);
4827 x_set_window_size (f
, 0, f
->width
, f
->height
);
4830 /* If we are setting a new frame's font for the first time,
4831 there are no faces yet, so this font's height is the line height. */
4832 f
->display
.x
->line_height
= FONT_HEIGHT (f
->display
.x
->font
);
4835 Lisp_Object lispy_name
;
4837 lispy_name
= build_string (fontname
);
4839 /* Free the information from XListFonts. The data
4840 we actually retain comes from XLoadQueryFont. */
4841 XFreeFontNames (font_names
);
4847 x_calc_absolute_position (f
)
4851 int win_x
= 0, win_y
= 0;
4852 int flags
= f
->display
.x
->size_hint_flags
;
4855 #ifdef USE_X_TOOLKIT
4856 this_window
= XtWindow (f
->display
.x
->widget
);
4858 this_window
= FRAME_X_WINDOW (f
);
4861 /* Find the position of the outside upper-left corner of
4862 the inner window, with respect to the outer window. */
4863 if (f
->display
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
4866 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
4868 /* From-window, to-window. */
4870 f
->display
.x
->parent_desc
,
4872 /* From-position, to-position. */
4873 0, 0, &win_x
, &win_y
,
4880 /* Treat negative positions as relative to the leftmost bottommost
4881 position that fits on the screen. */
4882 if (flags
& XNegative
)
4883 f
->display
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
4884 - 2 * f
->display
.x
->border_width
- win_x
4886 + f
->display
.x
->left_pos
);
4888 if (flags
& YNegative
)
4889 f
->display
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
4890 - 2 * f
->display
.x
->border_width
- win_y
4892 - (FRAME_EXTERNAL_MENU_BAR (f
)
4893 ? f
->display
.x
->menubar_height
: 0)
4894 + f
->display
.x
->top_pos
);
4895 /* The left_pos and top_pos
4896 are now relative to the top and left screen edges,
4897 so the flags should correspond. */
4898 f
->display
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
4901 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
4902 to really change the position, and 0 when calling from
4903 x_make_frame_visible (in that case, XOFF and YOFF are the current
4904 position values). It is -1 when calling from x_set_frame_parameters,
4905 which means, do adjust for borders but don't change the gravity. */
4907 x_set_offset (f
, xoff
, yoff
, change_gravity
)
4909 register int xoff
, yoff
;
4912 int modified_top
, modified_left
;
4914 if (change_gravity
> 0)
4916 f
->display
.x
->top_pos
= yoff
;
4917 f
->display
.x
->left_pos
= xoff
;
4918 f
->display
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
4920 f
->display
.x
->size_hint_flags
|= XNegative
;
4922 f
->display
.x
->size_hint_flags
|= YNegative
;
4923 f
->display
.x
->win_gravity
= NorthWestGravity
;
4925 x_calc_absolute_position (f
);
4928 x_wm_set_size_hint (f
, (long) 0, 0);
4930 /* It is a mystery why we need to add the border_width here
4931 when the frame is already visible, but experiment says we do. */
4932 modified_left
= f
->display
.x
->left_pos
;
4933 modified_top
= f
->display
.x
->top_pos
;
4934 if (change_gravity
!= 0)
4936 modified_left
+= f
->display
.x
->border_width
;
4937 modified_top
+= f
->display
.x
->border_width
;
4940 #ifdef USE_X_TOOLKIT
4941 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
),
4942 modified_left
, modified_top
);
4943 #else /* not USE_X_TOOLKIT */
4944 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4945 modified_left
, modified_top
);
4946 #endif /* not USE_X_TOOLKIT */
4950 /* Call this to change the size of frame F's x-window.
4951 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
4952 for this size change and subsequent size changes.
4953 Otherwise we leave the window gravity unchanged. */
4955 x_set_window_size (f
, change_gravity
, cols
, rows
)
4960 int pixelwidth
, pixelheight
;
4963 #ifdef USE_X_TOOLKIT
4966 /* The x and y position of the widget is clobbered by the
4967 call to XtSetValues within EmacsFrameSetCharSize.
4968 This is a real kludge, but I don't understand Xt so I can't
4969 figure out a correct fix. Can anyone else tell me? -- rms. */
4970 int xpos
= f
->display
.x
->widget
->core
.x
;
4971 int ypos
= f
->display
.x
->widget
->core
.y
;
4972 EmacsFrameSetCharSize (f
->display
.x
->edit_widget
, cols
, rows
);
4973 f
->display
.x
->widget
->core
.x
= xpos
;
4974 f
->display
.x
->widget
->core
.y
= ypos
;
4978 #else /* not USE_X_TOOLKIT */
4982 check_frame_size (f
, &rows
, &cols
);
4983 f
->display
.x
->vertical_scroll_bar_extra
4984 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4986 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
4987 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
4988 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->display
.x
->font
)));
4989 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
4990 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
4992 f
->display
.x
->win_gravity
= NorthWestGravity
;
4993 x_wm_set_size_hint (f
, (long) 0, 0);
4995 XSync (FRAME_X_DISPLAY (f
), False
);
4996 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4997 pixelwidth
, pixelheight
);
4999 /* Now, strictly speaking, we can't be sure that this is accurate,
5000 but the window manager will get around to dealing with the size
5001 change request eventually, and we'll hear how it went when the
5002 ConfigureNotify event gets here.
5004 We could just not bother storing any of this information here,
5005 and let the ConfigureNotify event set everything up, but that
5006 might be kind of confusing to the lisp code, since size changes
5007 wouldn't be reported in the frame parameters until some random
5008 point in the future when the ConfigureNotify event arrives. */
5009 change_frame_size (f
, rows
, cols
, 0, 0);
5010 PIXEL_WIDTH (f
) = pixelwidth
;
5011 PIXEL_HEIGHT (f
) = pixelheight
;
5013 /* If cursor was outside the new size, mark it as off. */
5014 if (f
->phys_cursor_y
>= rows
5015 || f
->phys_cursor_x
>= cols
)
5017 f
->phys_cursor_x
= -1;
5018 f
->phys_cursor_y
= -1;
5021 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5022 receive in the ConfigureNotify event; if we get what we asked
5023 for, then the event won't cause the screen to become garbaged, so
5024 we have to make sure to do it here. */
5025 SET_FRAME_GARBAGED (f
);
5027 XFlush (FRAME_X_DISPLAY (f
));
5029 #endif /* not USE_X_TOOLKIT */
5032 /* Mouse warping. */
5035 x_set_mouse_position (f
, x
, y
)
5041 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->display
.x
->font
) / 2;
5042 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->display
.x
->line_height
/ 2;
5044 if (pix_x
< 0) pix_x
= 0;
5045 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
5047 if (pix_y
< 0) pix_y
= 0;
5048 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
5052 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5053 0, 0, 0, 0, pix_x
, pix_y
);
5057 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
5060 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5066 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5067 0, 0, 0, 0, pix_x
, pix_y
);
5071 /* focus shifting, raising and lowering. */
5073 x_focus_on_frame (f
)
5076 #if 0 /* This proves to be unpleasant. */
5080 /* I don't think that the ICCCM allows programs to do things like this
5081 without the interaction of the window manager. Whatever you end up
5082 doing with this code, do it to x_unfocus_frame too. */
5083 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5084 RevertToPointerRoot
, CurrentTime
);
5092 /* Look at the remarks in x_focus_on_frame. */
5093 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
5094 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
5095 RevertToPointerRoot
, CurrentTime
);
5099 /* Raise frame F. */
5104 if (f
->async_visible
)
5107 #ifdef USE_X_TOOLKIT
5108 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
));
5109 #else /* not USE_X_TOOLKIT */
5110 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5111 #endif /* not USE_X_TOOLKIT */
5112 XFlush (FRAME_X_DISPLAY (f
));
5117 /* Lower frame F. */
5122 if (f
->async_visible
)
5125 #ifdef USE_X_TOOLKIT
5126 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
));
5127 #else /* not USE_X_TOOLKIT */
5128 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5129 #endif /* not USE_X_TOOLKIT */
5130 XFlush (FRAME_X_DISPLAY (f
));
5136 XTframe_raise_lower (f
, raise
)
5146 /* Change of visibility. */
5148 /* This tries to wait until the frame is really visible.
5149 However, if the window manager asks the user where to position
5150 the frame, this will return before the user finishes doing that.
5151 The frame will not actually be visible at that time,
5152 but it will become visible later when the window manager
5153 finishes with it. */
5155 x_make_frame_visible (f
)
5163 type
= x_icon_type (f
);
5165 x_bitmap_icon (f
, type
);
5167 if (! FRAME_VISIBLE_P (f
))
5169 /* We test FRAME_GARBAGED_P here to make sure we don't
5170 call x_set_offset a second time
5171 if we get to x_make_frame_visible a second time
5172 before the window gets really visible. */
5173 if (! FRAME_ICONIFIED_P (f
)
5174 && ! f
->display
.x
->asked_for_visible
)
5175 x_set_offset (f
, f
->display
.x
->left_pos
, f
->display
.x
->top_pos
, 0);
5177 f
->display
.x
->asked_for_visible
= 1;
5179 if (! EQ (Vx_no_window_manager
, Qt
))
5180 x_wm_set_window_state (f
, NormalState
);
5181 #ifdef USE_X_TOOLKIT
5182 /* This was XtPopup, but that did nothing for an iconified frame. */
5183 XtMapWidget (f
->display
.x
->widget
);
5184 #else /* not USE_X_TOOLKIT */
5185 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5186 #endif /* not USE_X_TOOLKIT */
5187 #if 0 /* This seems to bring back scroll bars in the wrong places
5188 if the window configuration has changed. They seem
5189 to come back ok without this. */
5190 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5191 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5195 XFlush (FRAME_X_DISPLAY (f
));
5197 /* Synchronize to ensure Emacs knows the frame is visible
5198 before we do anything else. We do this loop with input not blocked
5199 so that incoming events are handled. */
5202 int count
= input_signal_count
;
5204 /* This must come after we set COUNT. */
5207 XSETFRAME (frame
, f
);
5212 /* Once we have handled input events,
5213 we should have received the MapNotify if one is coming.
5214 So if we have not got it yet, stop looping.
5215 Some window managers make their own decisions
5216 about visibility. */
5217 if (input_signal_count
!= count
)
5219 /* Machines that do polling rather than SIGIO have been observed
5220 to go into a busy-wait here. So we'll fake an alarm signal
5221 to let the handler know that there's something to be read.
5222 We used to raise a real alarm, but it seems that the handler
5223 isn't always enabled here. This is probably a bug. */
5224 if (input_polling_used ())
5226 /* It could be confusing if a real alarm arrives while processing
5227 the fake one. Turn it off and let the handler reset it. */
5229 input_poll_signal ();
5231 /* Once we have handled input events,
5232 we should have received the MapNotify if one is coming.
5233 So if we have not got it yet, stop looping.
5234 Some window managers make their own decisions
5235 about visibility. */
5236 if (input_signal_count
!= count
)
5239 FRAME_SAMPLE_VISIBILITY (f
);
5243 /* Change from mapped state to withdrawn state. */
5245 /* Make the frame visible (mapped and not iconified). */
5247 x_make_frame_invisible (f
)
5253 #ifdef USE_X_TOOLKIT
5254 /* Use the frame's outermost window, not the one we normally draw on. */
5255 window
= XtWindow (f
->display
.x
->widget
);
5256 #else /* not USE_X_TOOLKIT */
5257 window
= FRAME_X_WINDOW (f
);
5258 #endif /* not USE_X_TOOLKIT */
5260 /* Don't keep the highlight on an invisible frame. */
5261 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5262 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5264 #if 0/* This might add unreliability; I don't trust it -- rms. */
5265 if (! f
->async_visible
&& ! f
->async_iconified
)
5271 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5272 that the current position of the window is user-specified, rather than
5273 program-specified, so that when the window is mapped again, it will be
5274 placed at the same location, without forcing the user to position it
5275 by hand again (they have already done that once for this window.) */
5276 x_wm_set_size_hint (f
, (long) 0, 1);
5280 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
5281 DefaultScreen (FRAME_X_DISPLAY (f
))))
5283 UNBLOCK_INPUT_RESIGNAL
;
5284 error ("Can't notify window manager of window withdrawal");
5286 #else /* ! defined (HAVE_X11R4) */
5288 /* Tell the window manager what we're going to do. */
5289 if (! EQ (Vx_no_window_manager
, Qt
))
5293 unmap
.xunmap
.type
= UnmapNotify
;
5294 unmap
.xunmap
.window
= window
;
5295 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
5296 unmap
.xunmap
.from_configure
= False
;
5297 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5298 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5300 SubstructureRedirectMask
|SubstructureNotifyMask
,
5303 UNBLOCK_INPUT_RESIGNAL
;
5304 error ("Can't notify window manager of withdrawal");
5308 /* Unmap the window ourselves. Cheeky! */
5309 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
5310 #endif /* ! defined (HAVE_X11R4) */
5312 /* We can't distinguish this from iconification
5313 just by the event that we get from the server.
5314 So we can't win using the usual strategy of letting
5315 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5316 and synchronize with the server to make sure we agree. */
5318 FRAME_ICONIFIED_P (f
) = 0;
5319 f
->async_visible
= 0;
5320 f
->async_iconified
= 0;
5327 /* Change window state from mapped to iconified. */
5336 /* Don't keep the highlight on an invisible frame. */
5337 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5338 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5340 if (f
->async_iconified
)
5345 type
= x_icon_type (f
);
5347 x_bitmap_icon (f
, type
);
5349 #ifdef USE_X_TOOLKIT
5351 if (! FRAME_VISIBLE_P (f
))
5353 if (! EQ (Vx_no_window_manager
, Qt
))
5354 x_wm_set_window_state (f
, IconicState
);
5355 /* This was XtPopup, but that did nothing for an iconified frame. */
5356 XtMapWidget (f
->display
.x
->widget
);
5361 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
5362 XtWindow (f
->display
.x
->widget
),
5363 DefaultScreen (FRAME_X_DISPLAY (f
)));
5367 error ("Can't notify window manager of iconification");
5369 f
->async_iconified
= 1;
5372 XFlush (FRAME_X_DISPLAY (f
));
5374 #else /* not USE_X_TOOLKIT */
5376 /* Make sure the X server knows where the window should be positioned,
5377 in case the user deiconifies with the window manager. */
5378 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
5379 x_set_offset (f
, f
->display
.x
->left_pos
, f
->display
.x
->top_pos
, 0);
5381 /* Since we don't know which revision of X we're running, we'll use both
5382 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
5384 /* X11R4: send a ClientMessage to the window manager using the
5385 WM_CHANGE_STATE type. */
5389 message
.xclient
.window
= FRAME_X_WINDOW (f
);
5390 message
.xclient
.type
= ClientMessage
;
5391 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
5392 message
.xclient
.format
= 32;
5393 message
.xclient
.data
.l
[0] = IconicState
;
5395 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5396 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5398 SubstructureRedirectMask
| SubstructureNotifyMask
,
5401 UNBLOCK_INPUT_RESIGNAL
;
5402 error ("Can't notify window manager of iconification");
5406 /* X11R3: set the initial_state field of the window manager hints to
5408 x_wm_set_window_state (f
, IconicState
);
5410 if (!FRAME_VISIBLE_P (f
))
5412 /* If the frame was withdrawn, before, we must map it. */
5413 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5416 f
->async_iconified
= 1;
5418 XFlush (FRAME_X_DISPLAY (f
));
5420 #endif /* not USE_X_TOOLKIT */
5423 /* Destroy the X window of frame F. */
5425 x_destroy_window (f
)
5428 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5432 if (f
->display
.x
->icon_desc
!= 0)
5433 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->display
.x
->icon_desc
);
5434 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->display
.x
->window_desc
);
5435 #ifdef USE_X_TOOLKIT
5436 XtDestroyWidget (f
->display
.x
->widget
);
5437 free_frame_menubar (f
);
5438 #endif /* USE_X_TOOLKIT */
5440 free_frame_faces (f
);
5441 XFlush (FRAME_X_DISPLAY (f
));
5443 xfree (f
->display
.x
);
5445 if (f
== dpyinfo
->x_focus_frame
)
5446 dpyinfo
->x_focus_frame
= 0;
5447 if (f
== dpyinfo
->x_focus_event_frame
)
5448 dpyinfo
->x_focus_event_frame
= 0;
5449 if (f
== dpyinfo
->x_highlight_frame
)
5450 dpyinfo
->x_highlight_frame
= 0;
5452 dpyinfo
->reference_count
--;
5454 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5456 dpyinfo
->mouse_face_beg_row
5457 = dpyinfo
->mouse_face_beg_col
= -1;
5458 dpyinfo
->mouse_face_end_row
5459 = dpyinfo
->mouse_face_end_col
= -1;
5460 dpyinfo
->mouse_face_window
= Qnil
;
5466 /* Setting window manager hints. */
5468 /* Set the normal size hints for the window manager, for frame F.
5469 FLAGS is the flags word to use--or 0 meaning preserve the flags
5470 that the window now has.
5471 If USER_POSITION is nonzero, we set the USPosition
5472 flag (this is useful when FLAGS is 0). */
5474 x_wm_set_size_hint (f
, flags
, user_position
)
5479 XSizeHints size_hints
;
5481 #ifdef USE_X_TOOLKIT
5484 Dimension widget_width
, widget_height
;
5485 Window window
= XtWindow (f
->display
.x
->widget
);
5486 #else /* not USE_X_TOOLKIT */
5487 Window window
= FRAME_X_WINDOW (f
);
5488 #endif /* not USE_X_TOOLKIT */
5490 /* Setting PMaxSize caused various problems. */
5491 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
5493 flexlines
= f
->height
;
5495 size_hints
.x
= f
->display
.x
->left_pos
;
5496 size_hints
.y
= f
->display
.x
->top_pos
;
5498 #ifdef USE_X_TOOLKIT
5499 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
5500 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
5501 XtGetValues (f
->display
.x
->widget
, al
, ac
);
5502 size_hints
.height
= widget_height
;
5503 size_hints
.width
= widget_width
;
5504 #else /* not USE_X_TOOLKIT */
5505 size_hints
.height
= PIXEL_HEIGHT (f
);
5506 size_hints
.width
= PIXEL_WIDTH (f
);
5507 #endif /* not USE_X_TOOLKIT */
5509 size_hints
.width_inc
= FONT_WIDTH (f
->display
.x
->font
);
5510 size_hints
.height_inc
= f
->display
.x
->line_height
;
5511 size_hints
.max_width
5512 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
5513 size_hints
.max_height
5514 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
5516 /* Calculate the base and minimum sizes.
5518 (When we use the X toolkit, we don't do it here.
5519 Instead we copy the values that the widgets are using, below.) */
5520 #ifndef USE_X_TOOLKIT
5522 int base_width
, base_height
;
5523 int min_rows
= 0, min_cols
= 0;
5525 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
5526 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
5528 check_frame_size (f
, &min_rows
, &min_cols
);
5530 /* The window manager uses the base width hints to calculate the
5531 current number of rows and columns in the frame while
5532 resizing; min_width and min_height aren't useful for this
5533 purpose, since they might not give the dimensions for a
5534 zero-row, zero-column frame.
5536 We use the base_width and base_height members if we have
5537 them; otherwise, we set the min_width and min_height members
5538 to the size for a zero x zero frame. */
5541 size_hints
.flags
|= PBaseSize
;
5542 size_hints
.base_width
= base_width
;
5543 size_hints
.base_height
= base_height
;
5544 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
5545 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
5547 size_hints
.min_width
= base_width
;
5548 size_hints
.min_height
= base_height
;
5552 /* If we don't need the old flags, we don't need the old hint at all. */
5555 size_hints
.flags
|= flags
;
5558 #endif /* not USE_X_TOOLKIT */
5561 XSizeHints hints
; /* Sometimes I hate X Windows... */
5562 long supplied_return
;
5566 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
5569 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
5572 #ifdef USE_X_TOOLKIT
5573 size_hints
.base_height
= hints
.base_height
;
5574 size_hints
.base_width
= hints
.base_width
;
5575 size_hints
.min_height
= hints
.min_height
;
5576 size_hints
.min_width
= hints
.min_width
;
5580 size_hints
.flags
|= flags
;
5585 if (hints
.flags
& PSize
)
5586 size_hints
.flags
|= PSize
;
5587 if (hints
.flags
& PPosition
)
5588 size_hints
.flags
|= PPosition
;
5589 if (hints
.flags
& USPosition
)
5590 size_hints
.flags
|= USPosition
;
5591 if (hints
.flags
& USSize
)
5592 size_hints
.flags
|= USSize
;
5599 size_hints
.win_gravity
= f
->display
.x
->win_gravity
;
5600 size_hints
.flags
|= PWinGravity
;
5604 size_hints
.flags
&= ~ PPosition
;
5605 size_hints
.flags
|= USPosition
;
5607 #endif /* PWinGravity */
5610 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
5612 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
5616 /* Used for IconicState or NormalState */
5617 x_wm_set_window_state (f
, state
)
5621 #ifdef USE_X_TOOLKIT
5624 XtSetArg (al
[0], XtNinitialState
, state
);
5625 XtSetValues (f
->display
.x
->widget
, al
, 1);
5626 #else /* not USE_X_TOOLKIT */
5627 Window window
= FRAME_X_WINDOW (f
);
5629 f
->display
.x
->wm_hints
.flags
|= StateHint
;
5630 f
->display
.x
->wm_hints
.initial_state
= state
;
5632 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
5633 #endif /* not USE_X_TOOLKIT */
5636 x_wm_set_icon_pixmap (f
, pixmap_id
)
5640 #ifdef USE_X_TOOLKIT
5641 Window window
= XtWindow (f
->display
.x
->widget
);
5643 Window window
= FRAME_X_WINDOW (f
);
5648 Pixmap icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
5649 f
->display
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
5652 f
->display
.x
->wm_hints
.icon_pixmap
= None
;
5654 f
->display
.x
->wm_hints
.flags
|= IconPixmapHint
;
5655 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
5658 x_wm_set_icon_position (f
, icon_x
, icon_y
)
5662 #ifdef USE_X_TOOLKIT
5663 Window window
= XtWindow (f
->display
.x
->widget
);
5665 Window window
= FRAME_X_WINDOW (f
);
5668 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
5669 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
5670 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
5672 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->display
.x
->wm_hints
);
5676 /* Initialization. */
5678 #ifdef USE_X_TOOLKIT
5679 static XrmOptionDescRec emacs_options
[] = {
5680 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
5681 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
5683 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
5684 XrmoptionSepArg
, NULL
},
5685 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
5687 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5688 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5689 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5690 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5691 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5692 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
5693 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
5695 #endif /* USE_X_TOOLKIT */
5697 static int x_initialized
;
5700 /* Test whether two display-name strings agree up to the dot that separates
5701 the screen number from the server number. */
5703 same_x_server (name1
, name2
)
5704 char *name1
, *name2
;
5707 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
5711 if (seen_colon
&& *name1
== '.')
5715 && (*name1
== '.' || *name1
== '\0')
5716 && (*name2
== '.' || *name2
== '\0'));
5720 struct x_display_info
*
5721 x_term_init (display_name
, xrm_option
, resource_name
)
5722 Lisp_Object display_name
;
5724 char *resource_name
;
5730 struct x_display_info
*dpyinfo
;
5741 #ifdef USE_X_TOOLKIT
5742 /* weiner@footloose.sps.mot.com reports that this causes
5744 X protocol error: BadAtom (invalid Atom parameter)
5745 on protocol request 18skiloaf.
5746 So let's not use it until R6. */
5748 XtSetLanguageProc (NULL
, NULL
, NULL
);
5759 argv
[argc
++] = "-xrm";
5760 argv
[argc
++] = xrm_option
;
5762 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
5763 resource_name
, EMACS_CLASS
,
5764 emacs_options
, XtNumber (emacs_options
),
5768 setlocale (LC_NUMERIC
, "C");
5769 setlocale (LC_TIME
, "C");
5773 #else /* not USE_X_TOOLKIT */
5775 XSetLocaleModifiers ("");
5777 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
5778 #endif /* not USE_X_TOOLKIT */
5780 /* Detect failure. */
5787 /* We have definitely succeeded. Record the new connection. */
5789 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
5793 struct x_display_info
*share
;
5796 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
5797 share
= share
->next
, tail
= XCONS (tail
)->cdr
)
5798 if (same_x_server (XSTRING (XCONS (XCONS (tail
)->car
)->car
)->data
,
5799 XSTRING (display_name
)->data
))
5802 dpyinfo
->kboard
= share
->kboard
;
5805 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
5806 init_kboard (dpyinfo
->kboard
);
5807 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
5809 char *vendor
= ServerVendor (dpy
);
5810 dpyinfo
->kboard
->Vsystem_key_alist
5811 = call1 (Qvendor_specific_keysyms
,
5812 build_string (vendor
? vendor
: ""));
5815 dpyinfo
->kboard
->next_kboard
= all_kboards
;
5816 all_kboards
= dpyinfo
->kboard
;
5817 /* Don't let the initial kboard remain current longer than necessary.
5818 That would cause problems if a file loaded on startup tries to
5819 prompt in the minibuffer. */
5820 if (current_kboard
== initial_kboard
)
5821 current_kboard
= dpyinfo
->kboard
;
5823 dpyinfo
->kboard
->reference_count
++;
5827 /* Put this display on the chain. */
5828 dpyinfo
->next
= x_display_list
;
5829 x_display_list
= dpyinfo
;
5831 /* Put it on x_display_name_list as well, to keep them parallel. */
5832 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
5833 x_display_name_list
);
5834 dpyinfo
->name_list_element
= XCONS (x_display_name_list
)->car
;
5836 dpyinfo
->display
= dpy
;
5839 XSetAfterFunction (x_current_display
, x_trace_wire
);
5843 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
5844 + XSTRING (Vsystem_name
)->size
5846 sprintf (dpyinfo
->x_id_name
, "%s@%s",
5847 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
5849 /* Figure out which modifier bits mean what. */
5850 x_find_modifier_meanings (dpyinfo
);
5852 /* Get the scroll bar cursor. */
5853 dpyinfo
->vertical_scroll_bar_cursor
5854 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
5856 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
5857 resource_name
, EMACS_CLASS
);
5858 #ifdef HAVE_XRMSETDATABASE
5859 XrmSetDatabase (dpyinfo
->display
, xrdb
);
5861 dpyinfo
->display
->db
= xrdb
;
5863 /* Put the rdb where we can find it in a way that works on
5865 dpyinfo
->xrdb
= xrdb
;
5867 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
5868 DefaultScreen (dpyinfo
->display
));
5869 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
5870 &dpyinfo
->n_planes
);
5871 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
5872 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
5873 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
5874 dpyinfo
->grabbed
= 0;
5875 dpyinfo
->reference_count
= 0;
5876 dpyinfo
->icon_bitmap_id
= -1;
5877 dpyinfo
->n_fonts
= 0;
5878 dpyinfo
->font_table_size
= 0;
5879 dpyinfo
->bitmaps
= 0;
5880 dpyinfo
->bitmaps_size
= 0;
5881 dpyinfo
->bitmaps_last
= 0;
5882 dpyinfo
->scratch_cursor_gc
= 0;
5883 dpyinfo
->mouse_face_mouse_frame
= 0;
5884 dpyinfo
->mouse_face_deferred_gc
= 0;
5885 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
5886 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
5887 dpyinfo
->mouse_face_face_id
= 0;
5888 dpyinfo
->mouse_face_window
= Qnil
;
5889 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
5890 dpyinfo
->mouse_face_defer
= 0;
5891 dpyinfo
->x_focus_frame
= 0;
5892 dpyinfo
->x_focus_event_frame
= 0;
5893 dpyinfo
->x_highlight_frame
= 0;
5895 dpyinfo
->Xatom_wm_protocols
5896 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
5897 dpyinfo
->Xatom_wm_take_focus
5898 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
5899 dpyinfo
->Xatom_wm_save_yourself
5900 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
5901 dpyinfo
->Xatom_wm_delete_window
5902 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
5903 dpyinfo
->Xatom_wm_change_state
5904 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
5905 dpyinfo
->Xatom_wm_configure_denied
5906 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
5907 dpyinfo
->Xatom_wm_window_moved
5908 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
5909 dpyinfo
->Xatom_editres
5910 = XInternAtom (dpyinfo
->display
, "Editres", False
);
5911 dpyinfo
->Xatom_CLIPBOARD
5912 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
5913 dpyinfo
->Xatom_TIMESTAMP
5914 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
5916 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
5917 dpyinfo
->Xatom_DELETE
5918 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
5919 dpyinfo
->Xatom_MULTIPLE
5920 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
5922 = XInternAtom (dpyinfo
->display
, "INCR", False
);
5923 dpyinfo
->Xatom_EMACS_TMP
5924 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
5925 dpyinfo
->Xatom_TARGETS
5926 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
5928 = XInternAtom (dpyinfo
->display
, "NULL", False
);
5929 dpyinfo
->Xatom_ATOM_PAIR
5930 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
5932 dpyinfo
->cut_buffers_initialized
= 0;
5934 connection
= ConnectionNumber (dpyinfo
->display
);
5935 dpyinfo
->connection
= connection
;
5938 /* This is only needed for distinguishing keyboard and process input. */
5939 if (connection
!= 0)
5940 add_keyboard_wait_descriptor (connection
);
5943 #ifndef F_SETOWN_BUG
5945 #ifdef F_SETOWN_SOCK_NEG
5946 /* stdin is a socket here */
5947 fcntl (connection
, F_SETOWN
, -getpid ());
5948 #else /* ! defined (F_SETOWN_SOCK_NEG) */
5949 fcntl (connection
, F_SETOWN
, getpid ());
5950 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
5951 #endif /* ! defined (F_SETOWN) */
5952 #endif /* F_SETOWN_BUG */
5955 if (interrupt_input
)
5956 init_sigio (connection
);
5957 #endif /* ! defined (SIGIO) */
5964 /* Get rid of display DPYINFO, assuming all frames are already gone,
5965 and without sending any more commands to the X server. */
5968 x_delete_display (dpyinfo
)
5969 struct x_display_info
*dpyinfo
;
5971 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
5973 /* Discard this display from x_display_name_list and x_display_list.
5974 We can't use Fdelq because that can quit. */
5975 if (! NILP (x_display_name_list
)
5976 && EQ (XCONS (x_display_name_list
)->car
, dpyinfo
->name_list_element
))
5977 x_display_name_list
= XCONS (x_display_name_list
)->cdr
;
5982 tail
= x_display_name_list
;
5983 while (CONSP (tail
) && CONSP (XCONS (tail
)->cdr
))
5985 if (EQ (XCONS (XCONS (tail
)->cdr
)->car
,
5986 dpyinfo
->name_list_element
))
5988 XCONS (tail
)->cdr
= XCONS (XCONS (tail
)->cdr
)->cdr
;
5991 tail
= XCONS (tail
)->cdr
;
5995 if (x_display_list
== dpyinfo
)
5996 x_display_list
= dpyinfo
->next
;
5999 struct x_display_info
*tail
;
6001 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
6002 if (tail
->next
== dpyinfo
)
6003 tail
->next
= tail
->next
->next
;
6006 #ifndef USE_X_TOOLKIT
6007 /* I'm told Xt does this itself. */
6008 XrmDestroyDatabase (dpyinfo
->xrdb
);
6011 if (--dpyinfo
->kboard
->reference_count
== 0)
6012 delete_kboard (dpyinfo
->kboard
);
6014 xfree (dpyinfo
->font_table
);
6015 xfree (dpyinfo
->x_id_name
);
6019 /* Set up use of X before we make the first connection. */
6023 clear_frame_hook
= XTclear_frame
;
6024 clear_end_of_line_hook
= XTclear_end_of_line
;
6025 ins_del_lines_hook
= XTins_del_lines
;
6026 change_line_highlight_hook
= XTchange_line_highlight
;
6027 insert_glyphs_hook
= XTinsert_glyphs
;
6028 write_glyphs_hook
= XTwrite_glyphs
;
6029 delete_glyphs_hook
= XTdelete_glyphs
;
6030 ring_bell_hook
= XTring_bell
;
6031 reset_terminal_modes_hook
= XTreset_terminal_modes
;
6032 set_terminal_modes_hook
= XTset_terminal_modes
;
6033 update_begin_hook
= XTupdate_begin
;
6034 update_end_hook
= XTupdate_end
;
6035 set_terminal_window_hook
= XTset_terminal_window
;
6036 read_socket_hook
= XTread_socket
;
6037 frame_up_to_date_hook
= XTframe_up_to_date
;
6038 cursor_to_hook
= XTcursor_to
;
6039 reassert_line_highlight_hook
= XTreassert_line_highlight
;
6040 mouse_position_hook
= XTmouse_position
;
6041 frame_rehighlight_hook
= XTframe_rehighlight
;
6042 frame_raise_lower_hook
= XTframe_raise_lower
;
6043 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
6044 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
6045 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
6046 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
6048 scroll_region_ok
= 1; /* we'll scroll partial frames */
6049 char_ins_del_ok
= 0; /* just as fast to write the line */
6050 line_ins_del_ok
= 1; /* we'll just blt 'em */
6051 fast_clear_end_of_line
= 1; /* X does this well */
6052 memory_below_frame
= 0; /* we don't remember what scrolls
6058 /* Try to use interrupt input; if we can't, then start polling. */
6059 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
6061 #ifdef USE_X_TOOLKIT
6062 XtToolkitInitialize ();
6063 Xt_app_con
= XtCreateApplicationContext ();
6064 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
6067 /* Note that there is no real way portable across R3/R4 to get the
6068 original error handler. */
6069 XSetErrorHandler (x_error_quitter
);
6070 XSetIOErrorHandler (x_io_error_quitter
);
6072 /* Disable Window Change signals; they are handled by X events. */
6074 signal (SIGWINCH
, SIG_DFL
);
6075 #endif /* ! defined (SIGWINCH) */
6077 signal (SIGPIPE
, x_connection_signal
);
6083 staticpro (&x_display_name_list
);
6084 x_display_name_list
= Qnil
;
6086 staticpro (&last_mouse_scroll_bar
);
6087 last_mouse_scroll_bar
= Qnil
;
6089 staticpro (&Qvendor_specific_keysyms
);
6090 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
6092 #endif /* ! defined (HAVE_X_WINDOWS) */