1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 1996 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Xt features made by Fred Pierresteguy. */
23 /* On 4.3 these lose if they come after xterm.h. */
24 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
25 /* Putting these at the beginning seems to be standard for other .c files. */
32 /* Need syssignal.h for various externs and definitions that may be required
33 by some configurations for calls to signal later in this source file. */
34 #include "syssignal.h"
39 #include "blockinput.h"
41 /* This may include sys/types.h, and that somehow loses
42 if this is not done before the other system files. */
44 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
55 #include <sys/ioctl.h>
56 #endif /* ! defined (BSD_SYSTEM) */
61 #ifndef INCLUDED_FCNTL
68 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
69 /* #include <sys/param.h> */
75 #include "dispextern.h"
76 #include "termhooks.h"
88 #include "intervals.h"
91 #include <X11/Shell.h>
95 extern void free_frame_menubar ();
96 extern FRAME_PTR
x_menubar_window_to_frame ();
97 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
99 extern void _XEditResCheckMessages ();
100 #endif /* not NO_EDITRES */
101 #endif /* USE_X_TOOLKIT */
103 #ifndef USE_X_TOOLKIT
104 #define x_any_window_to_frame x_window_to_frame
105 #define x_top_window_to_frame x_window_to_frame
110 #ifndef XtNinitialState
111 #define XtNinitialState "initialState"
115 #ifdef HAVE_SETLOCALE
116 /* So we can do setlocale. */
121 /* memmove will be defined as a macro in Xfuncs.h unless
122 <string.h> is included beforehand. The declaration for memmove in
123 <string.h> will cause a syntax error when Xfuncs.h later includes it. */
128 #define min(a,b) ((a)<(b) ? (a) : (b))
131 #define max(a,b) ((a)>(b) ? (a) : (b))
134 /* This is a chain of structures for all the X displays currently in use. */
135 struct x_display_info
*x_display_list
;
137 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
138 one for each element of x_display_list and in the same order.
139 NAME is the name of the frame.
140 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
141 Lisp_Object x_display_name_list
;
143 /* Frame being updated by update_frame. This is declared in term.c.
144 This is set by update_begin and looked at by all the
145 XT functions. It is zero while not inside an update.
146 In that case, the XT functions assume that `selected_frame'
147 is the frame to apply to. */
148 extern struct frame
*updating_frame
;
150 extern waiting_for_input
;
152 /* This is a frame waiting to be autoraised, within XTread_socket. */
153 struct frame
*pending_autoraise_frame
;
156 /* The application context for Xt use. */
157 XtAppContext Xt_app_con
;
159 static String Xt_default_resources
[] =
165 /* During an update, maximum vpos for ins/del line operations to affect. */
167 static int flexlines
;
169 /* During an update, nonzero if chars output now should be highlighted. */
171 static int highlight
;
173 /* Nominal cursor position -- where to draw output.
174 During an update, these are different from the cursor-box position. */
181 Formerly, we used PointerMotionHintMask (in STANDARD_EVENT_MASK)
182 so that we would have to call XQueryPointer after each MotionNotify
183 event to ask for another such event. However, this made mouse tracking
184 slow, and there was a bug that made it eventually stop.
186 Simply asking for MotionNotify all the time seems to work better.
188 In order to avoid asking for motion events and then throwing most
189 of them away or busy-polling the server for mouse positions, we ask
190 the server for pointer motion hints. This means that we get only
191 one event per group of mouse movements. "Groups" are delimited by
192 other kinds of events (focus changes and button clicks, for
193 example), or by XQueryPointer calls; when one of these happens, we
194 get another MotionNotify event the next time the mouse moves. This
195 is at least as efficient as getting motion events when mouse
196 tracking is on, and I suspect only negligibly worse when tracking
199 /* Where the mouse was last time we reported a mouse event. */
200 static FRAME_PTR last_mouse_frame
;
201 static XRectangle last_mouse_glyph
;
203 static Lisp_Object last_mouse_press_frame
;
205 /* The scroll bar in which the last X motion event occurred.
207 If the last X motion event occurred in a scroll bar, we set this
208 so XTmouse_position can know whether to report a scroll bar motion or
211 If the last X motion event didn't occur in a scroll bar, we set this
212 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
213 static Lisp_Object last_mouse_scroll_bar
;
215 /* This is a hack. We would really prefer that XTmouse_position would
216 return the time associated with the position it returns, but there
217 doesn't seem to be any way to wrest the timestamp from the server
218 along with the position query. So, we just keep track of the time
219 of the last movement we received, and return that in hopes that
220 it's somewhat accurate. */
221 static Time last_mouse_movement_time
;
223 /* Incremented by XTread_socket whenever it really tries to read events. */
225 static int volatile input_signal_count
;
227 static int input_signal_count
;
230 /* Used locally within XTread_socket. */
231 static int x_noop_count
;
233 /* Initial values of argv and argc. */
234 extern char **initial_argv
;
235 extern int initial_argc
;
237 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
239 /* Tells if a window manager is present or not. */
241 extern Lisp_Object Vx_no_window_manager
;
243 extern Lisp_Object Qface
, Qmouse_face
;
247 /* A mask of extra modifier bits to put into every keyboard char. */
248 extern int extra_keyboard_modifiers
;
250 static Lisp_Object Qvendor_specific_keysyms
;
252 extern XrmDatabase
x_load_resources ();
254 extern Lisp_Object
x_icon_type ();
256 void x_delete_display ();
258 static void redraw_previous_char ();
259 static void redraw_following_char ();
260 static unsigned int x_x_to_emacs_modifiers ();
262 static int fast_find_position ();
263 static void note_mouse_highlight ();
264 static void clear_mouse_face ();
265 static void show_mouse_face ();
266 static void do_line_dance ();
268 static int XTcursor_to ();
269 static int XTclear_end_of_line ();
270 static int x_io_error_quitter ();
271 int x_catch_errors ();
272 void x_uncatch_errors ();
275 /* This is a function useful for recording debugging information
276 about the sequence of occurrences in this file. */
284 struct record event_record
[100];
286 int event_record_index
;
288 record_event (locus
, type
)
292 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
293 event_record_index
= 0;
295 event_record
[event_record_index
].locus
= locus
;
296 event_record
[event_record_index
].type
= type
;
297 event_record_index
++;
302 /* Return the struct x_display_info corresponding to DPY. */
304 struct x_display_info
*
305 x_display_info_for_display (dpy
)
308 struct x_display_info
*dpyinfo
;
310 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
311 if (dpyinfo
->display
== dpy
)
317 /* Starting and ending updates.
319 These hooks are called by update_frame at the beginning and end
320 of a frame update. We record in `updating_frame' the identity
321 of the frame being updated, so that the XT... functions do not
322 need to take a frame as argument. Most of the XT... functions
323 should never be called except during an update, the only exceptions
324 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
335 flexlines
= f
->height
;
340 curs_x
= FRAME_CURSOR_X (f
);
341 curs_y
= FRAME_CURSOR_Y (f
);
343 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
345 /* Don't do highlighting for mouse motion during the update. */
346 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 1;
348 /* If the frame needs to be redrawn,
349 simply forget about any prior mouse highlighting. */
350 if (FRAME_GARBAGED_P (f
))
351 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= Qnil
;
353 if (!NILP (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
355 int firstline
, lastline
, i
;
356 struct window
*w
= XWINDOW (FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
);
358 /* Find the first, and the last+1, lines affected by redisplay. */
359 for (firstline
= 0; firstline
< f
->height
; firstline
++)
360 if (FRAME_DESIRED_GLYPHS (f
)->enable
[firstline
])
363 lastline
= f
->height
;
364 for (i
= f
->height
- 1; i
>= 0; i
--)
366 if (FRAME_DESIRED_GLYPHS (f
)->enable
[i
])
372 /* Can we tell that this update does not affect the window
373 where the mouse highlight is? If so, no need to turn off.
374 Likewise, don't do anything if the frame is garbaged;
375 in that case, the FRAME_CURRENT_GLYPHS that we would use
376 are all wrong, and we will redisplay that line anyway. */
377 if (! (firstline
> (XFASTINT (w
->top
) + window_internal_height (w
))
378 || lastline
< XFASTINT (w
->top
)))
379 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
395 x_display_cursor (f
, 1, curs_x
, curs_y
);
397 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
399 /* This fails in the case of having updated only the echo area
400 if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS
401 has no relation to the current contents, and its charstarts
402 have no relation to the contents of the window-buffer.
403 I don't know a clean way to check
404 for that case. window_end_valid isn't set up yet. */
405 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
406 note_mouse_highlight (f
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
407 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
410 XFlush (FRAME_X_DISPLAY (f
));
414 /* This is called after a redisplay on frame F. */
417 XTframe_up_to_date (f
)
421 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
422 || f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
)
424 note_mouse_highlight (FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
,
425 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
,
426 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
);
427 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 0;
432 /* External interface to control of standout mode.
433 Call this when about to modify line at position VPOS
434 and not change whether it is highlighted. */
436 XTreassert_line_highlight (new, vpos
)
442 /* Call this when about to modify line at position VPOS
443 and change whether it is highlighted. */
446 XTchange_line_highlight (new_highlight
, vpos
, first_unused_hpos
)
447 int new_highlight
, vpos
, first_unused_hpos
;
449 highlight
= new_highlight
;
450 XTcursor_to (vpos
, 0);
451 XTclear_end_of_line (FRAME_WINDOW_WIDTH (updating_frame
));
454 /* This is used when starting Emacs and when restarting after suspend.
455 When starting Emacs, no X window is mapped. And nothing must be done
456 to Emacs's own window if it is suspended (though that rarely happens). */
459 XTset_terminal_modes ()
463 /* This is called when exiting or suspending Emacs.
464 Exiting will make the X-windows go away, and suspending
465 requires no action. */
468 XTreset_terminal_modes ()
470 /* XTclear_frame (); */
473 /* Set the nominal cursor position of the frame.
474 This is where display update commands will take effect.
475 This does not affect the place where the cursor-box is displayed. */
478 XTcursor_to (row
, col
)
479 register int row
, col
;
487 if (updating_frame
== 0)
490 x_display_cursor (selected_frame
, 1, curs_x
, curs_y
);
491 XFlush (FRAME_X_DISPLAY (selected_frame
));
497 /* Return a pointer to per char metric information in FONT of a
498 character pointed by B (*XChar2b). */
500 #define PER_CHAR_METRIC(font, b) \
502 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
503 + (((font)->min_byte1 || (font)->max_byte1) \
504 ? (((b)->byte1 - (font)->min_byte1) \
505 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
507 : &((font)->max_bounds))
509 /* Display a sequence of N glyphs found at GP.
510 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
511 HL is 1 if this text is highlighted, 2 if the cursor is on it,
512 3 if should appear in its mouse-face.
513 JUST_FOREGROUND if 1 means draw only the foreground;
514 don't alter the background.
516 CMPCHARP if non NULL is a pointer to the struct cmpchar_info, which
517 means drawing glyphs on the same column. This is set to non NULL
518 only when recursively called within dumpglyphs to draw a composite
519 character specified by CMPCHAR.
521 FONT is the default font to use (for glyphs whose font-code is 0).
523 Since the display generation code is responsible for calling
524 compute_char_face and compute_glyph_face on everything it puts in
525 the display structure, we can assume that the face code on each
526 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
527 to which we can actually apply intern_face.
528 Call this function with input blocked.
530 Return overall pixel width of the drawn glyphs. */
533 /* This is the multi-face code. */
536 dumpglyphs (f
, left
, top
, gp
, n
, hl
, just_foreground
, cmpcharp
)
539 register GLYPH
*gp
; /* Points to first GLYPH. */
540 register int n
; /* Number of glyphs to display. */
543 struct cmpchar_info
*cmpcharp
;
545 /* Holds characters to be displayed. */
546 XChar2b
*buf
= (XChar2b
*) alloca (FRAME_WINDOW_WIDTH (f
) * sizeof (*buf
));
547 register XChar2b
*cp
; /* Steps through buf[]. */
548 register int tlen
= GLYPH_TABLE_LENGTH
;
549 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
550 Window window
= FRAME_X_WINDOW (f
);
551 int orig_left
= left
;
557 /* Get the face-code of the next GLYPH. */
560 int ch
, first_ch
, charset
;
561 /* HIGHEST and LOWEST are used while drawing a composite
562 character. The meanings are described later. */
565 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
566 cf
= (cmpcharp
? cmpcharp
->face_work
: FAST_GLYPH_FACE (g
));
567 ch
= FAST_GLYPH_CHAR (g
);
568 if (gidx
== 0) first_ch
= ch
;
569 charset
= CHAR_CHARSET (ch
);
570 if (charset
== CHARSET_COMPOSITION
)
572 /* We must draw components of the composite character on the
574 cmpcharp
= cmpchar_table
[COMPOSITE_CHAR_ID (ch
)];
576 /* Set the face in the slot for work. */
577 cmpcharp
->face_work
= cf
;
579 /* We don't need the return value ... */
580 dumpglyphs (f
, left
, top
, cmpcharp
->glyph
, cmpcharp
->glyph_len
,
581 hl
, just_foreground
, cmpcharp
);
582 /* ... because the width of just drawn text can be
583 calculated as follows. */
584 left
+= FONT_WIDTH (f
->output_data
.x
->font
) * cmpcharp
->width
;
587 while (gp
&& (*gp
& GLYPH_MASK_PADDING
)) ++gp
, --n
;
592 /* Find the run of consecutive glyphs which can be drawn with
593 the same GC (i.e. the same charset and the same face-code).
594 Extract their character codes into BUF.
595 If CMPCHARP is not NULL, face-code is not checked because we
596 use only the face specified in `cmpcharp->face_work'. */
600 int this_charset
, c1
, c2
;
603 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
604 ch
= FAST_GLYPH_CHAR (g
);
605 SPLIT_CHAR (ch
, this_charset
, c1
, c2
);
606 if (this_charset
!= charset
607 || (cmpcharp
== NULL
&& FAST_GLYPH_FACE (g
) != cf
))
611 cp
->byte1
= c1
, cp
->byte2
= c2
;
613 cp
->byte1
= 0, cp
->byte2
= c1
;
616 while (gp
&& (*gp
& GLYPH_MASK_PADDING
))
620 /* LEN gets the length of the run. */
622 /* Now output this run of chars, with the font and pixel values
623 determined by the face code CF. */
625 struct face
*face
= FRAME_DEFAULT_FACE (f
);
626 XFontStruct
*font
= NULL
;
629 int line_height
= f
->output_data
.x
->line_height
;
630 /* Pixel width of each glyph in this run. */
632 = (FONT_WIDTH (f
->output_data
.x
->font
)
633 * (cmpcharp
? cmpcharp
->width
: CHARSET_WIDTH (charset
)));
634 /* Overall pixel width of this run. */
636 = (FONT_WIDTH (f
->output_data
.x
->font
)
637 * (cmpcharp
? cmpcharp
->width
: len
* CHARSET_WIDTH (charset
)));
638 /* A flag to tell if we have already filled background. We
639 fill background in advance in the following cases:
640 1) A face has stipple.
641 2) A height of font is shorter than LINE_HEIGHT.
642 3) Drawing a composite character.
643 4) Font has non-zero _MULE_BASELINE_OFFSET property.
644 After filling background, we draw glyphs by XDrawString16. */
645 int background_filled
;
646 /* Baseline position of a character, offset from TOP. */
648 /* The property value of `_MULE_RELATIVE_COMPOSE' and
649 `_MULE_DEFAULT_ASCENT'. */
650 int relative_compose
= 0, default_ascent
= 0;
651 /* 1 if we find no font or a font of inappropriate size. */
652 int require_clipping
;
654 /* HL = 3 means use a mouse face previously chosen. */
656 cf
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
;
658 /* First look at the face of the text itself. */
661 /* It's possible for the display table to specify
662 a face code that is out of range. Use 0 in that case. */
663 if (cf
< 0 || cf
>= FRAME_N_COMPUTED_FACES (f
)
664 || FRAME_COMPUTED_FACES (f
) [cf
] == 0)
668 face
= FRAME_MODE_LINE_FACE (f
);
670 face
= intern_face (f
, FRAME_COMPUTED_FACES (f
) [cf
]);
671 if (FACE_STIPPLE (face
))
675 /* Then comes the distinction between modeline and normal text. */
680 face
= FRAME_MODE_LINE_FACE (f
);
681 if (FACE_STIPPLE (face
))
685 #define FACE_DEFAULT (~0)
687 /* Setting appropriate font and gc for this charset. */
688 if (charset
!= CHARSET_ASCII
)
691 int fontset
= FACE_FONTSET (face
);
692 struct font_info
*fontp
;
694 if ((fontset
< 0 && (fontset
= FRAME_FONTSET (f
)) < 0)
695 || !(fontp
= fs_load_font (f
, FRAME_X_FONT_TABLE (f
),
696 charset
, NULL
, fontset
)))
699 font
= (XFontStruct
*) (fontp
->font
);
700 gc
= FACE_NON_ASCII_GC (face
);
701 XSetFont (FRAME_X_DISPLAY (f
), gc
, font
->fid
);
703 = (font
->max_byte1
!= 0
704 ? (line_height
+ font
->ascent
- font
->descent
) / 2
705 : f
->output_data
.x
->font_baseline
- fontp
->baseline_offset
);
706 if (cmpcharp
&& cmpcharp
->cmp_rule
== NULL
)
708 relative_compose
= fontp
->relative_compose
;
709 default_ascent
= fontp
->default_ascent
;
712 /* We have to change code points in the following cases. */
713 if (fontp
->font_encoder
)
715 /* This font requires CCL program to calculate code
716 point of characters. */
717 struct ccl_program
*ccl
= fontp
->font_encoder
;
719 if (CHARSET_DIMENSION (charset
) == 1)
720 for (cp
= buf
; cp
< buf
+ len
; cp
++)
722 ccl
->reg
[0] = charset
;
723 ccl
->reg
[1] = cp
->byte2
;
724 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
725 cp
->byte2
= ccl
->reg
[1];
728 for (cp
= buf
; cp
< buf
+ len
; cp
++)
730 ccl
->reg
[0] = charset
;
731 ccl
->reg
[1] = cp
->byte1
, ccl
->reg
[2] = cp
->byte2
;
732 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
733 cp
->byte1
= ccl
->reg
[1], cp
->byte2
= ccl
->reg
[2];
736 else if (fontp
->encoding
[charset
])
738 int enc
= fontp
->encoding
[charset
];
740 if ((enc
== 1 || enc
== 2) && CHARSET_DIMENSION (charset
) == 2)
741 for (cp
= buf
; cp
< buf
+ len
; cp
++)
743 if (enc
== 1 || enc
== 3)
744 for (cp
= buf
; cp
< buf
+ len
; cp
++)
750 font
= FACE_FONT (face
);
751 if (font
== (XFontStruct
*) FACE_DEFAULT
)
752 font
= f
->output_data
.x
->font
;
753 baseline
= FONT_BASE (font
);
758 /* Now override that if the cursor's on this character. */
761 /* The cursor overrides stippling. */
764 if (font
== f
->output_data
.x
->font
765 && face
->background
== f
->output_data
.x
->background_pixel
766 && face
->foreground
== f
->output_data
.x
->foreground_pixel
)
768 gc
= f
->output_data
.x
->cursor_gc
;
770 /* Cursor on non-default face: must merge. */
776 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
777 xgcv
.foreground
= face
->background
;
778 /* If the glyph would be invisible,
779 try a different foreground. */
780 if (xgcv
.foreground
== xgcv
.background
)
781 xgcv
.foreground
= face
->foreground
;
782 if (xgcv
.foreground
== xgcv
.background
)
783 xgcv
.foreground
= f
->output_data
.x
->cursor_foreground_pixel
;
784 if (xgcv
.foreground
== xgcv
.background
)
785 xgcv
.foreground
= face
->foreground
;
786 /* Make sure the cursor is distinct from text in this face. */
787 if (xgcv
.background
== face
->background
788 && xgcv
.foreground
== face
->foreground
)
790 xgcv
.background
= face
->foreground
;
791 xgcv
.foreground
= face
->background
;
794 xgcv
.font
= font
->fid
;
796 xgcv
.font
= FACE_FONT (face
)->fid
;
797 xgcv
.graphics_exposures
= 0;
798 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
799 if (FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
)
800 XChangeGC (FRAME_X_DISPLAY (f
),
801 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
,
804 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
805 = XCreateGC (FRAME_X_DISPLAY (f
), window
, mask
, &xgcv
);
806 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
808 /* If this code is restored, it must also reset to the default stipple
810 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
811 XSetStipple (FRAME_X_DISPLAY (f
), gc
, face
->stipple
);
817 require_clipping
= (!NILP (Vclip_large_size_font
)
818 && (font
->ascent
> baseline
819 || font
->descent
> line_height
- baseline
821 && FONT_WIDTH (font
) > glyph_width
)));
823 if (font
&& (just_foreground
|| (cmpcharp
&& gidx
> 0)))
824 background_filled
= 1;
827 /* Turn stipple on. */
828 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillOpaqueStippled
);
830 /* Draw stipple or background color on background. */
831 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
832 left
, top
, run_width
, line_height
);
834 /* Turn stipple off. */
835 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillSolid
);
837 background_filled
= 1;
840 || FONT_HEIGHT (font
) < line_height
841 || FONT_WIDTH (font
) < glyph_width
844 /* Fill a area for the current run in background pixle of GC. */
846 unsigned long mask
= GCForeground
| GCBackground
;
847 unsigned long fore
, back
;
849 /* The current code at first exchange foreground and
850 background of GC, fill the area, then recover the
851 original foreground and background of GC.
852 Aren't there any more smart ways? */
854 XGetGCValues (FRAME_X_DISPLAY (f
), gc
, mask
, &xgcv
);
855 fore
= xgcv
.foreground
, back
= xgcv
.background
;
856 xgcv
.foreground
= back
, xgcv
.background
= fore
;
857 XChangeGC (FRAME_X_DISPLAY (f
), gc
, mask
, &xgcv
);
858 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
859 left
, top
, run_width
, line_height
);
860 xgcv
.foreground
= fore
, xgcv
.background
= back
;
861 XChangeGC (FRAME_X_DISPLAY (f
), gc
, mask
, &xgcv
);
863 background_filled
= 1;
865 /* To assure not to fill background while drawing
866 remaining components. */
870 background_filled
= 0;
874 if (require_clipping
)
876 Region region
; /* Region used for setting clip mask to GC. */
877 XPoint x
[4]; /* Data used for creating REGION. */
879 x
[0].x
= x
[3].x
= left
, x
[1].x
= x
[2].x
= left
+ glyph_width
;
880 x
[0].y
= x
[1].y
= top
, x
[2].y
= x
[3].y
= top
+ line_height
;
881 region
= XPolygonRegion (x
, 4, EvenOddRule
);
882 XSetRegion (FRAME_X_DISPLAY (f
), gc
, region
);
883 XDestroyRegion (region
);
888 if (require_clipping
)
889 for (i
= 0; i
< len
; i
++)
892 XSetClipOrigin (FRAME_X_DISPLAY (f
), gc
,
894 if (background_filled
)
895 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
896 left
+ glyph_width
* i
,
897 top
+ baseline
, buf
+ i
, 1);
899 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, gc
,
900 left
+ glyph_width
* i
,
901 top
+ baseline
, buf
+ i
, 1);
905 if (background_filled
)
906 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
907 left
, top
+ baseline
, buf
, len
);
909 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, gc
,
910 left
, top
+ baseline
, buf
, len
);
915 XCharStruct
*pcm
; /* Pointer to per char metric info. */
917 if ((cmpcharp
->cmp_rule
|| relative_compose
)
920 /* This is the first character. Initialize variables.
921 HIGHEST is the highest position of glyphs ever
922 written, LOWEST the lowest position. */
926 && CHAR_TABLE_P (Vuse_default_ascent
)
927 && !NILP (Faref (Vuse_default_ascent
, first_ch
)))
929 highest
= default_ascent
;
934 pcm
= PER_CHAR_METRIC (font
, buf
);
935 highest
= pcm
->ascent
+ 1;
936 lowest
= - pcm
->descent
;
939 if (cmpcharp
->cmp_rule
)
940 x_offset
= (cmpcharp
->col_offset
[0]
941 * FONT_WIDTH (f
->output_data
.x
->font
));
942 /* Draw the first character at the normal position. */
943 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
944 left
+ x_offset
, top
+ baseline
, buf
, 1);
951 for (; i
< len
; i
++, gidx
++)
953 int x_offset
= 0, y_offset
= 0;
955 if (relative_compose
)
957 pcm
= PER_CHAR_METRIC (font
, buf
+ i
);
958 if (- pcm
->descent
>= relative_compose
)
960 /* Draw above the current glyphs. */
961 y_offset
= highest
+ pcm
->descent
;
962 highest
+= pcm
->ascent
+ pcm
->descent
;
964 else if (pcm
->ascent
<= 0)
966 /* Draw beneath the current glyphs. */
967 y_offset
= lowest
- pcm
->ascent
;
968 lowest
-= pcm
->ascent
+ pcm
->descent
;
971 else if (cmpcharp
->cmp_rule
)
973 int gref
= (cmpcharp
->cmp_rule
[gidx
] - 0xA0) / 9;
974 int nref
= (cmpcharp
->cmp_rule
[gidx
] - 0xA0) % 9;
977 /* Re-encode GREF and NREF so that they specify
978 only Y-axis information:
979 0:top, 1:base, 2:bottom, 3:center */
980 gref
= gref
/ 3 + (gref
== 4) * 2;
981 nref
= nref
/ 3 + (nref
== 4) * 2;
983 pcm
= PER_CHAR_METRIC (font
, buf
+ i
);
984 bottom
= ((gref
== 0 ? highest
: gref
== 1 ? 0
986 : (highest
+ lowest
) / 2)
987 - (nref
== 0 ? pcm
->ascent
+ pcm
->descent
988 : nref
== 1 ? pcm
->descent
: nref
== 2 ? 0
989 : (pcm
->ascent
+ pcm
->descent
) / 2));
990 top
= bottom
+ (pcm
->ascent
+ pcm
->descent
);
995 y_offset
= bottom
+ pcm
->descent
;
996 x_offset
= (cmpcharp
->col_offset
[gidx
]
997 * FONT_WIDTH (f
->output_data
.x
->font
));
999 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
1000 left
+ x_offset
, top
+ baseline
- y_offset
,
1004 if (require_clipping
)
1005 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
1007 #if 0 /* Doesn't work, because it uses FRAME_CURRENT_GLYPHS,
1008 which often is not up to date yet. */
1009 if (!just_foreground
)
1011 if (left
== orig_left
)
1012 redraw_previous_char (f
, PIXEL_TO_CHAR_COL (f
, left
),
1013 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
1015 redraw_following_char (f
, PIXEL_TO_CHAR_COL (f
, left
+ len
* FONT_WIDTH (font
)),
1016 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
1020 if (!font
|| require_clipping
&& !NILP (Vhighlight_wrong_size_font
))
1022 /* Show rectangles to show that we found no font or a font
1023 of inappropriate size. */
1027 (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1028 left
, top
, run_width
- 1, line_height
- 1);
1030 for (i
= 0; i
< len
; i
++)
1031 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1032 left
+ glyph_width
* i
, top
,
1033 glyph_width
-1, line_height
- 1);
1036 /* We should probably check for XA_UNDERLINE_POSITION and
1037 XA_UNDERLINE_THICKNESS properties on the font, but let's
1038 just get the thing working, and come back to that. */
1040 /* Setting underline position based on the metric of the
1041 current font results in shaky underline if it strides
1042 over different fonts. So, we set the position based only
1043 on the default font of this frame. */
1044 int underline_position
= f
->output_data
.x
->font_baseline
+ 1;
1046 if (underline_position
>= line_height
)
1047 underline_position
= line_height
- 1;
1049 if (face
->underline
)
1050 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1052 left
, top
+ underline_position
, run_width
, 1);
1060 return (left
- orig_left
);
1065 /* This is the old single-face code. */
1068 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
1071 register GLYPH
*gp
; /* Points to first GLYPH. */
1072 register int n
; /* Number of glyphs to display. */
1077 Window window
= FRAME_X_WINDOW (f
);
1078 GC drawing_gc
= (hl
== 2 ? f
->output_data
.x
->cursor_gc
1079 : (hl
? f
->output_data
.x
->reverse_gc
1080 : f
->output_data
.x
->normal_gc
));
1082 if (sizeof (GLYPH
) == sizeof (XChar2b
))
1083 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
1084 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
1085 else if (sizeof (GLYPH
) == sizeof (unsigned char))
1086 XDrawImageString (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
1087 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
1089 /* What size of glyph ARE you using? And does X have a function to
1095 /* Output some text at the nominal frame cursor position.
1096 Advance the cursor over the text.
1097 Output LEN glyphs at START.
1099 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
1100 controls the pixel values used for foreground and background. */
1103 XTwrite_glyphs (start
, len
)
1104 register GLYPH
*start
;
1107 register int temp_length
;
1118 /* If not within an update,
1119 output at the frame's visible cursor. */
1120 curs_x
= f
->cursor_x
;
1121 curs_y
= f
->cursor_y
;
1125 CHAR_TO_PIXEL_COL (f
, curs_x
),
1126 CHAR_TO_PIXEL_ROW (f
, curs_y
),
1127 start
, len
, highlight
, 0, NULL
);
1129 /* If we drew on top of the cursor, note that it is turned off. */
1130 if (curs_y
== f
->phys_cursor_y
1131 && curs_x
<= f
->phys_cursor_x
1132 && curs_x
+ len
> f
->phys_cursor_x
)
1133 f
->phys_cursor_on
= 0;
1135 if (updating_frame
== 0)
1136 x_display_cursor (f
, 1, FRAME_CURSOR_X (f
) + len
, FRAME_CURSOR_Y (f
));
1143 /* Clear to the end of the line.
1144 Erase the current text line from the nominal cursor position (inclusive)
1145 to column FIRST_UNUSED (exclusive). The idea is that everything
1146 from FIRST_UNUSED onward is already erased. */
1149 XTclear_end_of_line (first_unused
)
1150 register int first_unused
;
1152 struct frame
*f
= updating_frame
;
1158 if (curs_y
< 0 || curs_y
>= f
->height
)
1160 if (first_unused
<= 0)
1163 if (first_unused
>= FRAME_WINDOW_WIDTH (f
))
1164 first_unused
= FRAME_WINDOW_WIDTH (f
);
1166 first_unused
+= FRAME_LEFT_SCROLL_BAR_WIDTH (f
);
1172 /* Notice if the cursor will be cleared by this operation. */
1173 if (curs_y
== f
->phys_cursor_y
1174 && curs_x
<= f
->phys_cursor_x
1175 && f
->phys_cursor_x
< first_unused
)
1176 f
->phys_cursor_on
= 0;
1178 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1179 CHAR_TO_PIXEL_COL (f
, curs_x
),
1180 CHAR_TO_PIXEL_ROW (f
, curs_y
),
1181 FONT_WIDTH (f
->output_data
.x
->font
) * (first_unused
- curs_x
),
1182 f
->output_data
.x
->line_height
, False
);
1184 redraw_previous_char (f
, curs_x
, curs_y
, highlight
);
1194 struct frame
*f
= updating_frame
;
1199 f
->phys_cursor_on
= 0; /* Cursor not visible. */
1200 curs_x
= 0; /* Nominal cursor position is top left. */
1205 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
1207 /* We have to clear the scroll bars, too. If we have changed
1208 colors or something like that, then they should be notified. */
1209 x_scroll_bar_clear (f
);
1211 XFlush (FRAME_X_DISPLAY (f
));
1216 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
1217 always contain the right glyphs to use.
1219 It also needs to be changed to look at the details of the font and
1220 see whether there is really overlap, and do nothing when there is
1221 not. This can use font_char_overlap_left and font_char_overlap_right,
1222 but just how to use them is not clear. */
1224 /* Erase the character (if any) at the position just before X, Y in frame F,
1225 then redraw it and the character before it.
1226 This is necessary when we erase starting at X,
1227 in case the character after X overlaps into the one before X.
1228 Call this function with input blocked. */
1231 redraw_previous_char (f
, x
, y
, highlight_flag
)
1236 /* Erase the character before the new ones, in case
1237 what was here before overlaps it.
1238 Reoutput that character, and the previous character
1239 (in case the previous character overlaps it). */
1242 int start_x
= x
- 2;
1245 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1246 CHAR_TO_PIXEL_COL (f
, x
- 1),
1247 CHAR_TO_PIXEL_ROW (f
, y
),
1248 FONT_WIDTH (f
->output_data
.x
->font
),
1249 f
->output_data
.x
->line_height
, False
);
1251 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
1252 CHAR_TO_PIXEL_ROW (f
, y
),
1253 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
1254 x
- start_x
, highlight_flag
, 1, NULL
);
1258 /* Erase the character (if any) at the position X, Y in frame F,
1259 then redraw it and the character after it.
1260 This is necessary when we erase endng at X,
1261 in case the character after X overlaps into the one before X.
1262 Call this function with input blocked. */
1265 redraw_following_char (f
, x
, y
, highlight_flag
)
1270 int limit
= FRAME_CURRENT_GLYPHS (f
)->used
[y
];
1271 /* Erase the character after the new ones, in case
1272 what was here before overlaps it.
1273 Reoutput that character, and the following character
1274 (in case the following character overlaps it). */
1276 && FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
] != SPACEGLYPH
)
1281 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1282 CHAR_TO_PIXEL_COL (f
, x
),
1283 CHAR_TO_PIXEL_ROW (f
, y
),
1284 FONT_WIDTH (f
->output_data
.x
->font
),
1285 f
->output_data
.x
->line_height
, False
);
1287 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, x
),
1288 CHAR_TO_PIXEL_ROW (f
, y
),
1289 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
],
1290 end_x
- x
, highlight_flag
, 1, NULL
);
1295 #if 0 /* Not in use yet */
1297 /* Return 1 if character C in font F extends past its left edge. */
1300 font_char_overlap_left (font
, c
)
1306 /* Find the bounding-box info for C. */
1307 if (font
->per_char
== 0)
1308 s
= &font
->max_bounds
;
1311 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1314 /* Decode char into row number (byte 1) and code within row (byte 2). */
1317 if (!(within
>= font
->min_char_or_byte2
1318 && within
<= font
->max_char_or_byte2
1319 && row
>= font
->min_byte1
1320 && row
<= font
->max_byte1
))
1322 /* If char is out of range, try the font's default char instead. */
1323 c
= font
->default_char
;
1324 row
= c
>> (BITS_PER_INT
- 8);
1327 if (!(within
>= font
->min_char_or_byte2
1328 && within
<= font
->max_char_or_byte2
1329 && row
>= font
->min_byte1
1330 && row
<= font
->max_byte1
))
1331 /* Still out of range means this char does not overlap. */
1334 /* We found the info for this char. */
1335 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1339 return (s
&& s
->lbearing
< 0);
1342 /* Return 1 if character C in font F extends past its right edge. */
1345 font_char_overlap_right (font
, c
)
1351 /* Find the bounding-box info for C. */
1352 if (font
->per_char
== 0)
1353 s
= &font
->max_bounds
;
1356 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1359 /* Decode char into row number (byte 1) and code within row (byte 2). */
1362 if (!(within
>= font
->min_char_or_byte2
1363 && within
<= font
->max_char_or_byte2
1364 && row
>= font
->min_byte1
1365 && row
<= font
->max_byte1
))
1367 /* If char is out of range, try the font's default char instead. */
1368 c
= font
->default_char
;
1369 row
= c
>> (BITS_PER_INT
- 8);
1372 if (!(within
>= font
->min_char_or_byte2
1373 && within
<= font
->max_char_or_byte2
1374 && row
>= font
->min_byte1
1375 && row
<= font
->max_byte1
))
1376 /* Still out of range means this char does not overlap. */
1379 /* We found the info for this char. */
1380 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1384 return (s
&& s
->rbearing
>= s
->width
);
1388 /* Invert the middle quarter of the frame for .15 sec. */
1390 /* We use the select system call to do the waiting, so we have to make sure
1391 it's available. If it isn't, we just won't do visual bells. */
1392 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1394 /* Subtract the `struct timeval' values X and Y,
1395 storing the result in RESULT.
1396 Return 1 if the difference is negative, otherwise 0. */
1399 timeval_subtract (result
, x
, y
)
1400 struct timeval
*result
, x
, y
;
1402 /* Perform the carry for the later subtraction by updating y.
1403 This is safer because on some systems
1404 the tv_sec member is unsigned. */
1405 if (x
.tv_usec
< y
.tv_usec
)
1407 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
1408 y
.tv_usec
-= 1000000 * nsec
;
1411 if (x
.tv_usec
- y
.tv_usec
> 1000000)
1413 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
1414 y
.tv_usec
+= 1000000 * nsec
;
1418 /* Compute the time remaining to wait. tv_usec is certainly positive. */
1419 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
1420 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
1422 /* Return indication of whether the result should be considered negative. */
1423 return x
.tv_sec
< y
.tv_sec
;
1434 /* Create a GC that will use the GXxor function to flip foreground pixels
1435 into background pixels. */
1439 values
.function
= GXxor
;
1440 values
.foreground
= (f
->output_data
.x
->foreground_pixel
1441 ^ f
->output_data
.x
->background_pixel
);
1443 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1444 GCFunction
| GCForeground
, &values
);
1448 /* Get the height not including a menu bar widget. */
1449 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
1450 /* Height of each line to flash. */
1451 int flash_height
= FRAME_LINE_HEIGHT (f
);
1452 /* These will be the left and right margins of the rectangles. */
1453 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1454 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
1458 /* Don't flash the area between a scroll bar and the frame
1459 edge it is next to. */
1460 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
1462 case vertical_scroll_bar_left
:
1463 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1466 case vertical_scroll_bar_right
:
1467 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1471 width
= flash_right
- flash_left
;
1473 /* If window is tall, flash top and bottom line. */
1474 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
1476 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1477 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1478 width
, flash_height
);
1479 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1481 (height
- flash_height
1482 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
1483 width
, flash_height
);
1486 /* If it is short, flash it all. */
1487 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1488 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1489 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
1491 XFlush (FRAME_X_DISPLAY (f
));
1494 struct timeval wakeup
, now
;
1496 EMACS_GET_TIME (wakeup
);
1498 /* Compute time to wait until, propagating carry from usecs. */
1499 wakeup
.tv_usec
+= 150000;
1500 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
1501 wakeup
.tv_usec
%= 1000000;
1503 /* Keep waiting until past the time wakeup. */
1506 struct timeval timeout
;
1508 EMACS_GET_TIME (timeout
);
1510 /* In effect, timeout = wakeup - timeout.
1511 Break if result would be negative. */
1512 if (timeval_subtract (&timeout
, wakeup
, timeout
))
1515 /* Try to wait that long--but we might wake up sooner. */
1516 select (0, NULL
, NULL
, NULL
, &timeout
);
1520 /* If window is tall, flash top and bottom line. */
1521 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
1523 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1524 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1525 width
, flash_height
);
1526 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1528 (height
- flash_height
1529 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
1530 width
, flash_height
);
1533 /* If it is short, flash it all. */
1534 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1535 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1536 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
1538 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
1539 XFlush (FRAME_X_DISPLAY (f
));
1549 /* Make audible bell. */
1551 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
1555 if (FRAME_X_DISPLAY (selected_frame
) == 0)
1558 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1560 XTflash (selected_frame
);
1566 XFlush (FRAME_X_DISPLAY (selected_frame
));
1571 /* Insert and delete character.
1572 These are not supposed to be used because we are supposed to turn
1573 off the feature of using them. */
1576 XTinsert_glyphs (start
, len
)
1577 register char *start
;
1590 /* Specify how many text lines, from the top of the window,
1591 should be affected by insert-lines and delete-lines operations.
1592 This, and those operations, are used only within an update
1593 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1596 XTset_terminal_window (n
)
1599 if (updating_frame
== 0)
1602 if ((n
<= 0) || (n
> updating_frame
->height
))
1603 flexlines
= updating_frame
->height
;
1608 /* These variables need not be per frame
1609 because redisplay is done on a frame-by-frame basis
1610 and the line dance for one frame is finished before
1611 anything is done for anoter frame. */
1613 /* Array of line numbers from cached insert/delete operations.
1614 line_dance[i] is the old position of the line that we want
1615 to move to line i, or -1 if we want a blank line there. */
1616 static int *line_dance
;
1618 /* Allocated length of that array. */
1619 static int line_dance_len
;
1621 /* Flag indicating whether we've done any work. */
1622 static int line_dance_in_progress
;
1624 /* Perform an insert-lines or delete-lines operation,
1625 inserting N lines or deleting -N lines at vertical position VPOS. */
1626 XTins_del_lines (vpos
, n
)
1629 register int fence
, i
;
1631 if (vpos
>= flexlines
)
1634 if (!line_dance_in_progress
)
1636 int ht
= updating_frame
->height
;
1637 if (ht
> line_dance_len
)
1639 line_dance
= (int *)xrealloc (line_dance
, ht
* sizeof (int));
1640 line_dance_len
= ht
;
1642 for (i
= 0; i
< ht
; ++i
) line_dance
[i
] = i
;
1643 line_dance_in_progress
= 1;
1647 if (n
> flexlines
- vpos
)
1648 n
= flexlines
- vpos
;
1650 for (i
= flexlines
; --i
>= fence
;)
1651 line_dance
[i
] = line_dance
[i
-n
];
1652 for (i
= fence
; --i
>= vpos
;)
1658 if (n
> flexlines
- vpos
)
1659 n
= flexlines
- vpos
;
1660 fence
= flexlines
- n
;
1661 for (i
= vpos
; i
< fence
; ++i
)
1662 line_dance
[i
] = line_dance
[i
+ n
];
1663 for (i
= fence
; i
< flexlines
; ++i
)
1668 /* Here's where we actually move the pixels around.
1669 Must be called with input blocked. */
1673 register int i
, j
, distance
;
1674 register struct frame
*f
;
1678 /* Must check this flag first. If it's not set, then not only is the
1679 array uninitialized, but we might not even have a frame. */
1680 if (!line_dance_in_progress
)
1688 intborder
= CHAR_TO_PIXEL_COL (f
, FRAME_LEFT_SCROLL_BAR_WIDTH (f
));
1690 x_update_cursor (updating_frame
, 0);
1692 for (i
= 0; i
< ht
; ++i
)
1693 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) > 0)
1695 for (j
= i
; (j
< ht
&& line_dance
[j
] != -1
1696 && line_dance
[j
]-j
== distance
); ++j
);
1697 /* Copy [i,j) upward from [i+distance,j+distance) */
1698 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1699 FRAME_X_WINDOW (f
), f
->output_data
.x
->normal_gc
,
1700 intborder
, CHAR_TO_PIXEL_ROW (f
, i
+distance
),
1701 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1702 (j
-i
) * f
->output_data
.x
->line_height
,
1703 intborder
, CHAR_TO_PIXEL_ROW (f
, i
));
1707 for (i
= ht
; --i
>=0; )
1708 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) < 0)
1710 for (j
= i
; (--j
>= 0 && line_dance
[j
] != -1
1711 && line_dance
[j
]-j
== distance
););
1712 /* Copy (j,i] downward from (j+distance, i+distance] */
1713 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1714 FRAME_X_WINDOW (f
), f
->output_data
.x
->normal_gc
,
1715 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1+distance
),
1716 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1717 (i
-j
) * f
->output_data
.x
->line_height
,
1718 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1));
1722 for (i
= 0; i
< ht
; ++i
)
1723 if (line_dance
[i
] == -1)
1725 for (j
= i
; j
< ht
&& line_dance
[j
] == -1; ++j
);
1727 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1728 intborder
, CHAR_TO_PIXEL_ROW (f
, i
),
1729 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1730 (j
-i
) * f
->output_data
.x
->line_height
, False
);
1733 line_dance_in_progress
= 0;
1736 /* Support routines for exposure events. */
1737 static void clear_cursor ();
1739 /* Output into a rectangle of an X-window (for frame F)
1740 the characters in f->phys_lines that overlap that rectangle.
1741 TOP and LEFT are the position of the upper left corner of the rectangle.
1742 ROWS and COLS are the size of the rectangle.
1743 Call this function with input blocked. */
1746 dumprectangle (f
, left
, top
, cols
, rows
)
1748 register int left
, top
, cols
, rows
;
1750 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1751 int cursor_cleared
= 0;
1755 if (FRAME_GARBAGED_P (f
))
1758 /* Express rectangle as four edges, instead of position-and-size. */
1759 bottom
= top
+ rows
;
1760 right
= left
+ cols
;
1762 /* Convert rectangle edges in pixels to edges in chars.
1763 Round down for left and top, up for right and bottom. */
1764 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1765 left
= PIXEL_TO_CHAR_COL (f
, left
);
1766 bottom
+= (f
->output_data
.x
->line_height
- 1);
1767 right
+= (FONT_WIDTH (f
->output_data
.x
->font
) - 1);
1768 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1769 right
= PIXEL_TO_CHAR_COL (f
, right
);
1771 /* Clip the rectangle to what can be visible. */
1776 if (right
> FRAME_WINDOW_WIDTH (f
))
1777 right
= FRAME_WINDOW_WIDTH (f
);
1778 if (bottom
> f
->height
)
1781 /* Get size in chars of the rectangle. */
1782 cols
= right
- left
;
1783 rows
= bottom
- top
;
1785 /* If rectangle has zero area, return. */
1786 if (rows
<= 0) return;
1787 if (cols
<= 0) return;
1789 /* Turn off the cursor if it is in the rectangle.
1790 We will turn it back on afterward. */
1791 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1792 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1798 /* Display the text in the rectangle, one text line at a time. */
1800 for (y
= top
; y
< bottom
; y
++)
1802 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1804 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1807 while (*line
& GLYPH_MASK_PADDING
)
1809 /* We must display the whole glyph of a wide-column
1816 CHAR_TO_PIXEL_COL (f
, left
),
1817 CHAR_TO_PIXEL_ROW (f
, y
),
1818 line
, min (cols
, active_frame
->used
[y
] - left
),
1819 active_frame
->highlight
[y
], 0, NULL
);
1822 /* Turn the cursor on if we turned it off. */
1825 x_update_cursor (f
, 1);
1832 /* We used to only do this if Vx_no_window_manager was non-nil, but
1833 the ICCCM (section 4.1.6) says that the window's border pixmap
1834 and border pixel are window attributes which are "private to the
1835 client", so we can always change it to whatever we want. */
1837 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1838 f
->output_data
.x
->border_pixel
);
1840 x_update_cursor (f
, 1);
1844 frame_unhighlight (f
)
1847 /* We used to only do this if Vx_no_window_manager was non-nil, but
1848 the ICCCM (section 4.1.6) says that the window's border pixmap
1849 and border pixel are window attributes which are "private to the
1850 client", so we can always change it to whatever we want. */
1852 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1853 f
->output_data
.x
->border_tile
);
1855 x_update_cursor (f
, 1);
1858 static void XTframe_rehighlight ();
1859 static void x_frame_rehighlight ();
1861 /* The focus has changed. Update the frames as necessary to reflect
1862 the new situation. Note that we can't change the selected frame
1863 here, because the Lisp code we are interrupting might become confused.
1864 Each event gets marked with the frame in which it occurred, so the
1865 Lisp code can tell when the switch took place by examining the events. */
1868 x_new_focus_frame (dpyinfo
, frame
)
1869 struct x_display_info
*dpyinfo
;
1870 struct frame
*frame
;
1872 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
1873 int events_enqueued
= 0;
1875 if (frame
!= dpyinfo
->x_focus_frame
)
1877 /* Set this before calling other routines, so that they see
1878 the correct value of x_focus_frame. */
1879 dpyinfo
->x_focus_frame
= frame
;
1881 if (old_focus
&& old_focus
->auto_lower
)
1882 x_lower_frame (old_focus
);
1885 selected_frame
= frame
;
1886 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
1888 Fselect_window (selected_frame
->selected_window
);
1889 choose_minibuf_frame ();
1892 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
1893 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
1895 pending_autoraise_frame
= 0;
1898 x_frame_rehighlight (dpyinfo
);
1901 /* Handle an event saying the mouse has moved out of an Emacs frame. */
1904 x_mouse_leave (dpyinfo
)
1905 struct x_display_info
*dpyinfo
;
1907 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
1910 /* The focus has changed, or we have redirected a frame's focus to
1911 another frame (this happens when a frame uses a surrogate
1912 minibuffer frame). Shift the highlight as appropriate.
1914 The FRAME argument doesn't necessarily have anything to do with which
1915 frame is being highlighted or unhighlighted; we only use it to find
1916 the appropriate X display info. */
1918 XTframe_rehighlight (frame
)
1919 struct frame
*frame
;
1921 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
1925 x_frame_rehighlight (dpyinfo
)
1926 struct x_display_info
*dpyinfo
;
1928 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1930 if (dpyinfo
->x_focus_frame
)
1932 dpyinfo
->x_highlight_frame
1933 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
1934 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
1935 : dpyinfo
->x_focus_frame
);
1936 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
1938 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
1939 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1943 dpyinfo
->x_highlight_frame
= 0;
1945 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
1948 frame_unhighlight (old_highlight
);
1949 if (dpyinfo
->x_highlight_frame
)
1950 frame_highlight (dpyinfo
->x_highlight_frame
);
1954 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1956 /* Initialize mode_switch_bit and modifier_meaning. */
1958 x_find_modifier_meanings (dpyinfo
)
1959 struct x_display_info
*dpyinfo
;
1961 int min_code
, max_code
;
1964 XModifierKeymap
*mods
;
1966 dpyinfo
->meta_mod_mask
= 0;
1967 dpyinfo
->shift_lock_mask
= 0;
1968 dpyinfo
->alt_mod_mask
= 0;
1969 dpyinfo
->super_mod_mask
= 0;
1970 dpyinfo
->hyper_mod_mask
= 0;
1973 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
1975 min_code
= dpyinfo
->display
->min_keycode
;
1976 max_code
= dpyinfo
->display
->max_keycode
;
1979 syms
= XGetKeyboardMapping (dpyinfo
->display
,
1980 min_code
, max_code
- min_code
+ 1,
1982 mods
= XGetModifierMapping (dpyinfo
->display
);
1984 /* Scan the modifier table to see which modifier bits the Meta and
1985 Alt keysyms are on. */
1987 int row
, col
; /* The row and column in the modifier table. */
1989 for (row
= 3; row
< 8; row
++)
1990 for (col
= 0; col
< mods
->max_keypermod
; col
++)
1993 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
1995 /* Zeroes are used for filler. Skip them. */
1999 /* Are any of this keycode's keysyms a meta key? */
2003 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
2005 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
2011 dpyinfo
->meta_mod_mask
|= (1 << row
);
2016 dpyinfo
->alt_mod_mask
|= (1 << row
);
2021 dpyinfo
->hyper_mod_mask
|= (1 << row
);
2026 dpyinfo
->super_mod_mask
|= (1 << row
);
2030 /* Ignore this if it's not on the lock modifier. */
2031 if ((1 << row
) == LockMask
)
2032 dpyinfo
->shift_lock_mask
= LockMask
;
2040 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
2041 if (! dpyinfo
->meta_mod_mask
)
2043 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
2044 dpyinfo
->alt_mod_mask
= 0;
2047 /* If some keys are both alt and meta,
2048 make them just meta, not alt. */
2049 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
2051 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
2054 XFree ((char *) syms
);
2055 XFreeModifiermap (mods
);
2058 /* Convert between the modifier bits X uses and the modifier bits
2061 x_x_to_emacs_modifiers (dpyinfo
, state
)
2062 struct x_display_info
*dpyinfo
;
2065 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
2066 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
2067 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
2068 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
2069 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
2070 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
2074 x_emacs_to_x_modifiers (dpyinfo
, state
)
2075 struct x_display_info
*dpyinfo
;
2078 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
2079 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
2080 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
2081 | ((state
& shift_modifier
) ? ShiftMask
: 0)
2082 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
2083 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
2086 /* Convert a keysym to its name. */
2089 x_get_keysym_name (keysym
)
2095 value
= XKeysymToString (keysym
);
2101 /* Mouse clicks and mouse movement. Rah. */
2103 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
2104 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
2105 that the glyph at X, Y occupies, if BOUNDS != 0.
2106 If NOCLIP is nonzero, do not force the value into range. */
2109 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
2111 register int pix_x
, pix_y
;
2112 register int *x
, *y
;
2116 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
2117 even for negative values. */
2119 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
2121 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
2123 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
2124 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
2128 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
2129 bounds
->height
= f
->output_data
.x
->line_height
;
2130 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
2131 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
2138 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
2139 pix_x
= FRAME_WINDOW_WIDTH (f
);
2143 else if (pix_y
> f
->height
)
2152 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
2155 register int *pix_x
, *pix_y
;
2157 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
2158 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
2161 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2163 If the event is a button press, then note that we have grabbed
2167 construct_mouse_click (result
, event
, f
)
2168 struct input_event
*result
;
2169 XButtonEvent
*event
;
2172 /* Make the event type no_event; we'll change that when we decide
2174 result
->kind
= mouse_click
;
2175 result
->code
= event
->button
- Button1
;
2176 result
->timestamp
= event
->time
;
2177 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
2179 | (event
->type
== ButtonRelease
2187 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
2188 XSETFASTINT (result
->x
, column
);
2189 XSETFASTINT (result
->y
, row
);
2191 XSETINT (result
->x
, event
->x
);
2192 XSETINT (result
->y
, event
->y
);
2193 XSETFRAME (result
->frame_or_window
, f
);
2197 /* Prepare a menu-event in *RESULT for placement in the input queue. */
2200 construct_menu_click (result
, event
, f
)
2201 struct input_event
*result
;
2202 XButtonEvent
*event
;
2205 /* Make the event type no_event; we'll change that when we decide
2207 result
->kind
= mouse_click
;
2208 result
->code
= event
->button
- Button1
;
2209 result
->timestamp
= event
->time
;
2210 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
2212 | (event
->type
== ButtonRelease
2216 XSETINT (result
->x
, event
->x
);
2217 XSETINT (result
->y
, -1);
2218 XSETFRAME (result
->frame_or_window
, f
);
2221 /* Function to report a mouse movement to the mainstream Emacs code.
2222 The input handler calls this.
2224 We have received a mouse movement event, which is given in *event.
2225 If the mouse is over a different glyph than it was last time, tell
2226 the mainstream emacs code by setting mouse_moved. If not, ask for
2227 another motion event, so we can check again the next time it moves. */
2230 note_mouse_movement (frame
, event
)
2232 XMotionEvent
*event
;
2234 last_mouse_movement_time
= event
->time
;
2236 if (event
->window
!= FRAME_X_WINDOW (frame
))
2238 frame
->mouse_moved
= 1;
2239 last_mouse_scroll_bar
= Qnil
;
2241 note_mouse_highlight (frame
, -1, -1);
2244 /* Has the mouse moved off the glyph it was on at the last sighting? */
2245 else if (event
->x
< last_mouse_glyph
.x
2246 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
2247 || event
->y
< last_mouse_glyph
.y
2248 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
2250 frame
->mouse_moved
= 1;
2251 last_mouse_scroll_bar
= Qnil
;
2253 note_mouse_highlight (frame
, event
->x
, event
->y
);
2257 /* This is used for debugging, to turn off note_mouse_highlight. */
2258 static int disable_mouse_highlight
;
2260 /* Take proper action when the mouse has moved to position X, Y on frame F
2261 as regards highlighting characters that have mouse-face properties.
2262 Also dehighlighting chars where the mouse was before.
2263 X and Y can be negative or out of range. */
2266 note_mouse_highlight (f
, x
, y
)
2270 int row
, column
, portion
;
2271 XRectangle new_glyph
;
2275 if (disable_mouse_highlight
)
2278 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
= x
;
2279 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
= y
;
2280 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
= f
;
2282 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
)
2287 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 1;
2291 /* Find out which glyph the mouse is on. */
2292 pixel_to_glyph_coords (f
, x
, y
, &column
, &row
,
2293 &new_glyph
, FRAME_X_DISPLAY_INFO (f
)->grabbed
);
2295 /* Which window is that in? */
2296 window
= window_from_coordinates (f
, column
, row
, &portion
);
2297 w
= XWINDOW (window
);
2299 /* If we were displaying active text in another window, clear that. */
2300 if (! EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
2301 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2303 /* Are we in a window whose display is up to date?
2304 And verify the buffer's text has not changed. */
2305 if (WINDOWP (window
) && portion
== 0 && row
>= 0 && column
>= 0
2306 && row
< FRAME_HEIGHT (f
) && column
< FRAME_WIDTH (f
)
2307 && EQ (w
->window_end_valid
, w
->buffer
)
2308 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
2309 && (XFASTINT (w
->last_overlay_modified
)
2310 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
2312 int *ptr
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[row
];
2315 /* Find which buffer position the mouse corresponds to. */
2316 for (i
= column
; i
>= 0; i
--)
2320 /* Is it outside the displayed active region (if any)? */
2322 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2323 else if (! (EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
)
2324 && row
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2325 && row
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2326 && (row
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2327 || column
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
)
2328 && (row
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2329 || column
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2330 || FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
)))
2332 Lisp_Object mouse_face
, overlay
, position
;
2333 Lisp_Object
*overlay_vec
;
2334 int len
, noverlays
, ignor1
;
2335 struct buffer
*obuf
;
2338 /* If we get an out-of-range value, return now; avoid an error. */
2339 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
2342 /* Make the window's buffer temporarily current for
2343 overlays_at and compute_char_face. */
2344 obuf
= current_buffer
;
2345 current_buffer
= XBUFFER (w
->buffer
);
2351 /* Yes. Clear the display of the old active region, if any. */
2352 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2354 /* Is this char mouse-active? */
2355 XSETINT (position
, pos
);
2358 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2360 /* Put all the overlays we want in a vector in overlay_vec.
2361 Store the length in len. */
2362 noverlays
= overlays_at (pos
, 1, &overlay_vec
, &len
,
2364 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
2366 /* Find the highest priority overlay that has a mouse-face prop. */
2368 for (i
= 0; i
< noverlays
; i
++)
2370 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
2371 if (!NILP (mouse_face
))
2373 overlay
= overlay_vec
[i
];
2378 /* If no overlay applies, get a text property. */
2380 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
2382 /* Handle the overlay case. */
2383 if (! NILP (overlay
))
2385 /* Find the range of text around this char that
2386 should be active. */
2387 Lisp_Object before
, after
;
2390 before
= Foverlay_start (overlay
);
2391 after
= Foverlay_end (overlay
);
2392 /* Record this as the current active region. */
2393 fast_find_position (window
, XFASTINT (before
),
2394 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2395 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2396 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2397 = !fast_find_position (window
, XFASTINT (after
),
2398 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2399 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2400 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2401 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2402 = compute_char_face (f
, w
, pos
, 0, 0,
2403 &ignore
, pos
+ 1, 1);
2405 /* Display it as active. */
2406 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2408 /* Handle the text property case. */
2409 else if (! NILP (mouse_face
))
2411 /* Find the range of text around this char that
2412 should be active. */
2413 Lisp_Object before
, after
, beginning
, end
;
2416 beginning
= Fmarker_position (w
->start
);
2417 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
2418 - XFASTINT (w
->window_end_pos
)));
2420 = Fprevious_single_property_change (make_number (pos
+ 1),
2422 w
->buffer
, beginning
);
2424 = Fnext_single_property_change (position
, Qmouse_face
,
2426 /* Record this as the current active region. */
2427 fast_find_position (window
, XFASTINT (before
),
2428 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2429 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2430 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2431 = !fast_find_position (window
, XFASTINT (after
),
2432 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2433 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2434 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2435 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2436 = compute_char_face (f
, w
, pos
, 0, 0,
2437 &ignore
, pos
+ 1, 1);
2439 /* Display it as active. */
2440 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2444 current_buffer
= obuf
;
2449 /* Find the row and column of position POS in window WINDOW.
2450 Store them in *COLUMNP and *ROWP.
2451 This assumes display in WINDOW is up to date.
2452 If POS is above start of WINDOW, return coords
2453 of start of first screen line.
2454 If POS is after end of WINDOW, return coords of end of last screen line.
2456 Value is 1 if POS is in range, 0 if it was off screen. */
2459 fast_find_position (window
, pos
, columnp
, rowp
)
2462 int *columnp
, *rowp
;
2464 struct window
*w
= XWINDOW (window
);
2465 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2468 int left
= WINDOW_LEFT_MARGIN (w
);
2469 int top
= XFASTINT (w
->top
);
2470 int height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
2471 int width
= window_internal_width (w
);
2474 int maybe_next_line
= 0;
2476 /* Find the right row. */
2481 int linestart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ i
][left
];
2482 if (linestart
> pos
)
2484 /* If the position sought is the end of the buffer,
2485 don't include the blank lines at the bottom of the window. */
2486 if (linestart
== pos
&& pos
== BUF_ZV (XBUFFER (w
->buffer
)))
2488 maybe_next_line
= 1;
2495 /* Find the right column with in it. */
2496 charstarts
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ row
];
2498 for (i
= 0; i
< width
; i
++)
2500 if (charstarts
[left
+ i
] == pos
)
2503 *columnp
= i
+ left
;
2506 else if (charstarts
[left
+ i
] > pos
)
2508 else if (charstarts
[left
+ i
] > 0)
2512 /* If we're looking for the end of the buffer,
2513 and we didn't find it in the line we scanned,
2514 use the start of the following line. */
2515 if (maybe_next_line
)
2526 /* Display the active region described by mouse_face_*
2527 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2530 show_mouse_face (dpyinfo
, hl
)
2531 struct x_display_info
*dpyinfo
;
2534 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
2535 int width
= window_internal_width (w
);
2536 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2539 int old_curs_x
= curs_x
;
2540 int old_curs_y
= curs_y
;
2542 /* Set these variables temporarily
2543 so that if we have to turn the cursor off and on again
2544 we will put it back at the same place. */
2545 curs_x
= f
->phys_cursor_x
;
2546 curs_y
= f
->phys_cursor_y
;
2547 for (i
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
;
2548 i
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
; i
++)
2550 int column
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2551 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
2552 : WINDOW_LEFT_MARGIN (w
));
2553 int endcolumn
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2554 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2555 : WINDOW_LEFT_MARGIN (w
) + width
);
2556 endcolumn
= min (endcolumn
, FRAME_CURRENT_GLYPHS (f
)->used
[i
]);
2558 /* If the cursor's in the text we are about to rewrite,
2559 turn the cursor off. */
2561 && curs_x
>= column
- 1
2562 && curs_x
<= endcolumn
)
2564 x_update_cursor (f
, 0);
2569 CHAR_TO_PIXEL_COL (f
, column
),
2570 CHAR_TO_PIXEL_ROW (f
, i
),
2571 FRAME_CURRENT_GLYPHS (f
)->glyphs
[i
] + column
,
2573 /* Highlight with mouse face if hl > 0. */
2574 hl
> 0 ? 3 : 0, 0, NULL
);
2577 /* If we turned the cursor off, turn it back on. */
2579 x_display_cursor (f
, 1, curs_x
, curs_y
);
2581 curs_x
= old_curs_x
;
2582 curs_y
= old_curs_y
;
2584 /* Change the mouse cursor according to the value of HL. */
2586 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2587 f
->output_data
.x
->cross_cursor
);
2589 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2590 f
->output_data
.x
->text_cursor
);
2593 /* Clear out the mouse-highlighted active region.
2594 Redraw it unhighlighted first. */
2597 clear_mouse_face (dpyinfo
)
2598 struct x_display_info
*dpyinfo
;
2600 if (! NILP (dpyinfo
->mouse_face_window
))
2601 show_mouse_face (dpyinfo
, 0);
2603 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2604 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2605 dpyinfo
->mouse_face_window
= Qnil
;
2608 /* Just discard the mouse face information for frame F, if any.
2609 This is used when the size of F is changed. */
2611 cancel_mouse_face (f
)
2615 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2617 window
= dpyinfo
->mouse_face_window
;
2618 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
2620 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2621 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2622 dpyinfo
->mouse_face_window
= Qnil
;
2626 static struct scroll_bar
*x_window_to_scroll_bar ();
2627 static void x_scroll_bar_report_motion ();
2629 /* Return the current position of the mouse.
2630 *fp should be a frame which indicates which display to ask about.
2632 If the mouse movement started in a scroll bar, set *fp, *bar_window,
2633 and *part to the frame, window, and scroll bar part that the mouse
2634 is over. Set *x and *y to the portion and whole of the mouse's
2635 position on the scroll bar.
2637 If the mouse movement started elsewhere, set *fp to the frame the
2638 mouse is on, *bar_window to nil, and *x and *y to the character cell
2641 Set *time to the server timestamp for the time at which the mouse
2642 was at this position.
2644 Don't store anything if we don't have a valid set of values to report.
2646 This clears the mouse_moved flag, so we can wait for the next mouse
2650 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
2653 Lisp_Object
*bar_window
;
2654 enum scroll_bar_part
*part
;
2656 unsigned long *time
;
2662 if (! NILP (last_mouse_scroll_bar
))
2663 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
2669 Window dummy_window
;
2672 Lisp_Object frame
, tail
;
2674 /* Clear the mouse-moved flag for every frame on this display. */
2675 FOR_EACH_FRAME (tail
, frame
)
2676 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
2677 XFRAME (frame
)->mouse_moved
= 0;
2679 last_mouse_scroll_bar
= Qnil
;
2681 /* Figure out which root window we're on. */
2682 XQueryPointer (FRAME_X_DISPLAY (*fp
),
2683 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
2685 /* The root window which contains the pointer. */
2688 /* Trash which we can't trust if the pointer is on
2689 a different screen. */
2692 /* The position on that root window. */
2695 /* More trash we can't trust. */
2698 /* Modifier keys and pointer buttons, about which
2700 (unsigned int *) &dummy
);
2702 /* Now we have a position on the root; find the innermost window
2703 containing the pointer. */
2707 int parent_x
, parent_y
;
2712 /* XTranslateCoordinates can get errors if the window
2713 structure is changing at the same time this function
2714 is running. So at least we must not crash from them. */
2716 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
2718 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
2719 && FRAME_LIVE_P (last_mouse_frame
))
2721 /* If mouse was grabbed on a frame, give coords for that frame
2722 even if the mouse is now outside it. */
2723 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2725 /* From-window, to-window. */
2726 root
, FRAME_X_WINDOW (last_mouse_frame
),
2728 /* From-position, to-position. */
2729 root_x
, root_y
, &win_x
, &win_y
,
2733 f1
= last_mouse_frame
;
2739 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2741 /* From-window, to-window. */
2744 /* From-position, to-position. */
2745 root_x
, root_y
, &win_x
, &win_y
,
2750 if (child
== None
|| child
== win
)
2758 /* Now we know that:
2759 win is the innermost window containing the pointer
2760 (XTC says it has no child containing the pointer),
2761 win_x and win_y are the pointer's position in it
2762 (XTC did this the last time through), and
2763 parent_x and parent_y are the pointer's position in win's parent.
2764 (They are what win_x and win_y were when win was child.
2765 If win is the root window, it has no parent, and
2766 parent_{x,y} are invalid, but that's okay, because we'll
2767 never use them in that case.) */
2769 /* Is win one of our frames? */
2770 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
2773 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
2776 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
2778 /* If not, is it one of our scroll bars? */
2781 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
2785 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2791 if (f1
== 0 && insist
)
2792 f1
= selected_frame
;
2796 int ignore1
, ignore2
;
2798 /* Ok, we found a frame. Store all the values. */
2800 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
2802 FRAME_X_DISPLAY_INFO (f1
)->grabbed
2808 XSETINT (*x
, win_x
);
2809 XSETINT (*y
, win_y
);
2810 *time
= last_mouse_movement_time
;
2818 /* Scroll bar support. */
2820 /* Given an X window ID, find the struct scroll_bar which manages it.
2821 This can be called in GC, so we have to make sure to strip off mark
2823 static struct scroll_bar
*
2824 x_window_to_scroll_bar (window_id
)
2827 Lisp_Object tail
, frame
;
2829 for (tail
= Vframe_list
;
2830 XGCTYPE (tail
) == Lisp_Cons
;
2831 tail
= XCONS (tail
)->cdr
)
2833 Lisp_Object frame
, bar
, condemned
;
2835 frame
= XCONS (tail
)->car
;
2836 /* All elements of Vframe_list should be frames. */
2837 if (! GC_FRAMEP (frame
))
2840 /* Scan this frame's scroll bar list for a scroll bar with the
2842 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2843 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2844 /* This trick allows us to search both the ordinary and
2845 condemned scroll bar lists with one loop. */
2846 ! GC_NILP (bar
) || (bar
= condemned
,
2849 bar
= XSCROLL_BAR (bar
)->next
)
2850 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2851 return XSCROLL_BAR (bar
);
2857 /* Open a new X window to serve as a scroll bar, and return the
2858 scroll bar vector for it. */
2859 static struct scroll_bar
*
2860 x_scroll_bar_create (window
, top
, left
, width
, height
)
2861 struct window
*window
;
2862 int top
, left
, width
, height
;
2864 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2865 struct scroll_bar
*bar
2866 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2871 XSetWindowAttributes a
;
2873 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
2874 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2875 | ButtonMotionMask
| PointerMotionHintMask
2877 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
2879 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2884 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2885 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2886 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
2887 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
2888 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2889 sb_widget
= XtCreateManagedWidget ("box",
2891 f
->output_data
.x
->edit_widget
, al
, ac
);
2892 SET_SCROLL_BAR_X_WINDOW
2893 (bar
, sb_widget
->core
.window
);
2895 SET_SCROLL_BAR_X_WINDOW
2897 XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2899 /* Position and size of scroll bar. */
2900 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, top
,
2901 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2, height
,
2903 /* Border width, depth, class, and visual. */
2904 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
2910 XSETWINDOW (bar
->window
, window
);
2911 XSETINT (bar
->top
, top
);
2912 XSETINT (bar
->left
, left
);
2913 XSETINT (bar
->width
, width
);
2914 XSETINT (bar
->height
, height
);
2915 XSETINT (bar
->start
, 0);
2916 XSETINT (bar
->end
, 0);
2917 bar
->dragging
= Qnil
;
2919 /* Add bar to its frame's list of scroll bars. */
2920 bar
->next
= FRAME_SCROLL_BARS (f
);
2922 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2923 if (! NILP (bar
->next
))
2924 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2926 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
2933 /* Draw BAR's handle in the proper position.
2934 If the handle is already drawn from START to END, don't bother
2935 redrawing it, unless REBUILD is non-zero; in that case, always
2936 redraw it. (REBUILD is handy for drawing the handle after expose
2939 Normally, we want to constrain the start and end of the handle to
2940 fit inside its rectangle, but if the user is dragging the scroll bar
2941 handle, we want to let them drag it down all the way, so that the
2942 bar's top is as far down as it goes; otherwise, there's no way to
2943 move to the very end of the buffer. */
2945 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
2946 struct scroll_bar
*bar
;
2950 int dragging
= ! NILP (bar
->dragging
);
2951 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2952 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2953 GC gc
= f
->output_data
.x
->normal_gc
;
2955 /* If the display is already accurate, do nothing. */
2957 && start
== XINT (bar
->start
)
2958 && end
== XINT (bar
->end
))
2964 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
2965 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
2966 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
2968 /* Make sure the values are reasonable, and try to preserve
2969 the distance between start and end. */
2971 int length
= end
- start
;
2975 else if (start
> top_range
)
2977 end
= start
+ length
;
2981 else if (end
> top_range
&& ! dragging
)
2985 /* Store the adjusted setting in the scroll bar. */
2986 XSETINT (bar
->start
, start
);
2987 XSETINT (bar
->end
, end
);
2989 /* Clip the end position, just for display. */
2990 if (end
> top_range
)
2993 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
2994 below top positions, to make sure the handle is always at least
2995 that many pixels tall. */
2996 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
2998 /* Draw the empty space above the handle. Note that we can't clear
2999 zero-height areas; that means "clear to end of window." */
3001 XClearArea (FRAME_X_DISPLAY (f
), w
,
3003 /* x, y, width, height, and exposures. */
3004 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3005 VERTICAL_SCROLL_BAR_TOP_BORDER
,
3006 inside_width
, start
,
3009 /* Draw the handle itself. */
3010 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
3012 /* x, y, width, height */
3013 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3014 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
3015 inside_width
, end
- start
);
3018 /* Draw the empty space below the handle. Note that we can't
3019 clear zero-height areas; that means "clear to end of window." */
3020 if (end
< inside_height
)
3021 XClearArea (FRAME_X_DISPLAY (f
), w
,
3023 /* x, y, width, height, and exposures. */
3024 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3025 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
3026 inside_width
, inside_height
- end
,
3034 /* Move a scroll bar around on the screen, to accommodate changing
3035 window configurations. */
3037 x_scroll_bar_move (bar
, top
, left
, width
, height
)
3038 struct scroll_bar
*bar
;
3039 int top
, left
, width
, height
;
3041 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3042 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3048 unsigned int mask
= 0;
3050 wc
.x
= left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3053 wc
.width
= width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
3056 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
3057 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
3058 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
3059 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
3062 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
3066 XSETINT (bar
->left
, left
);
3067 XSETINT (bar
->top
, top
);
3068 XSETINT (bar
->width
, width
);
3069 XSETINT (bar
->height
, height
);
3074 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
3077 x_scroll_bar_remove (bar
)
3078 struct scroll_bar
*bar
;
3080 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3084 /* Destroy the window. */
3085 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
3087 /* Disassociate this scroll bar from its window. */
3088 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
3093 /* Set the handle of the vertical scroll bar for WINDOW to indicate
3094 that we are displaying PORTION characters out of a total of WHOLE
3095 characters, starting at POSITION. If WINDOW has no scroll bar,
3098 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
3099 struct window
*window
;
3100 int portion
, whole
, position
;
3102 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
3103 int top
= XINT (window
->top
);
3104 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
3105 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
3107 /* Where should this scroll bar be, pixelwise? */
3108 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
3109 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
3111 = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3112 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3113 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
3114 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
3116 struct scroll_bar
*bar
;
3118 /* Does the scroll bar exist yet? */
3119 if (NILP (window
->vertical_scroll_bar
))
3120 bar
= x_scroll_bar_create (window
,
3121 pixel_top
, pixel_left
,
3122 pixel_width
, pixel_height
);
3125 /* It may just need to be moved and resized. */
3126 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
3127 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
3130 /* Set the scroll bar's current state, unless we're currently being
3132 if (NILP (bar
->dragging
))
3134 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, pixel_height
);
3137 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
3140 int start
= ((double) position
* top_range
) / whole
;
3141 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
3143 x_scroll_bar_set_handle (bar
, start
, end
, 0);
3147 XSETVECTOR (window
->vertical_scroll_bar
, bar
);
3151 /* The following three hooks are used when we're doing a thorough
3152 redisplay of the frame. We don't explicitly know which scroll bars
3153 are going to be deleted, because keeping track of when windows go
3154 away is a real pain - "Can you say set-window-configuration, boys
3155 and girls?" Instead, we just assert at the beginning of redisplay
3156 that *all* scroll bars are to be removed, and then save a scroll bar
3157 from the fiery pit when we actually redisplay its window. */
3159 /* Arrange for all scroll bars on FRAME to be removed at the next call
3160 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
3161 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
3163 XTcondemn_scroll_bars (frame
)
3166 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
3167 while (! NILP (FRAME_SCROLL_BARS (frame
)))
3170 bar
= FRAME_SCROLL_BARS (frame
);
3171 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
3172 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
3173 XSCROLL_BAR (bar
)->prev
= Qnil
;
3174 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
3175 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
3176 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
3180 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
3181 Note that WINDOW isn't necessarily condemned at all. */
3183 XTredeem_scroll_bar (window
)
3184 struct window
*window
;
3186 struct scroll_bar
*bar
;
3188 /* We can't redeem this window's scroll bar if it doesn't have one. */
3189 if (NILP (window
->vertical_scroll_bar
))
3192 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
3194 /* Unlink it from the condemned list. */
3196 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
3198 if (NILP (bar
->prev
))
3200 /* If the prev pointer is nil, it must be the first in one of
3202 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
3203 /* It's not condemned. Everything's fine. */
3205 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
3206 window
->vertical_scroll_bar
))
3207 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
3209 /* If its prev pointer is nil, it must be at the front of
3210 one or the other! */
3214 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
3216 if (! NILP (bar
->next
))
3217 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
3219 bar
->next
= FRAME_SCROLL_BARS (f
);
3221 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
3222 if (! NILP (bar
->next
))
3223 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3227 /* Remove all scroll bars on FRAME that haven't been saved since the
3228 last call to `*condemn_scroll_bars_hook'. */
3230 XTjudge_scroll_bars (f
)
3233 Lisp_Object bar
, next
;
3235 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
3237 /* Clear out the condemned list now so we won't try to process any
3238 more events on the hapless scroll bars. */
3239 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
3241 for (; ! NILP (bar
); bar
= next
)
3243 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
3245 x_scroll_bar_remove (b
);
3248 b
->next
= b
->prev
= Qnil
;
3251 /* Now there should be no references to the condemned scroll bars,
3252 and they should get garbage-collected. */
3256 /* Handle an Expose or GraphicsExpose event on a scroll bar.
3258 This may be called from a signal handler, so we have to ignore GC
3261 x_scroll_bar_expose (bar
, event
)
3262 struct scroll_bar
*bar
;
3265 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3266 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3267 GC gc
= f
->output_data
.x
->normal_gc
;
3268 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3272 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
3274 /* Draw a one-pixel border just inside the edges of the scroll bar. */
3275 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
3277 /* x, y, width, height */
3279 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
3280 XINT (bar
->height
) - 1);
3285 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
3286 is set to something other than no_event, it is enqueued.
3288 This may be called from a signal handler, so we have to ignore GC
3291 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
3292 struct scroll_bar
*bar
;
3294 struct input_event
*emacs_event
;
3296 if (! GC_WINDOWP (bar
->window
))
3299 emacs_event
->kind
= scroll_bar_click
;
3300 emacs_event
->code
= event
->xbutton
.button
- Button1
;
3301 emacs_event
->modifiers
3302 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
3303 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
3304 event
->xbutton
.state
)
3305 | (event
->type
== ButtonRelease
3308 emacs_event
->frame_or_window
= bar
->window
;
3309 emacs_event
->timestamp
= event
->xbutton
.time
;
3311 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3313 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
3315 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3316 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
3319 if (y
> top_range
) y
= top_range
;
3321 if (y
< XINT (bar
->start
))
3322 emacs_event
->part
= scroll_bar_above_handle
;
3323 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3324 emacs_event
->part
= scroll_bar_handle
;
3326 emacs_event
->part
= scroll_bar_below_handle
;
3328 /* Just because the user has clicked on the handle doesn't mean
3329 they want to drag it. Lisp code needs to be able to decide
3330 whether or not we're dragging. */
3332 /* If the user has just clicked on the handle, record where they're
3334 if (event
->type
== ButtonPress
3335 && emacs_event
->part
== scroll_bar_handle
)
3336 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
3339 /* If the user has released the handle, set it to its final position. */
3340 if (event
->type
== ButtonRelease
3341 && ! NILP (bar
->dragging
))
3343 int new_start
= y
- XINT (bar
->dragging
);
3344 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
3346 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
3347 bar
->dragging
= Qnil
;
3350 /* Same deal here as the other #if 0. */
3352 /* Clicks on the handle are always reported as occurring at the top of
3354 if (emacs_event
->part
== scroll_bar_handle
)
3355 emacs_event
->x
= bar
->start
;
3357 XSETINT (emacs_event
->x
, y
);
3359 XSETINT (emacs_event
->x
, y
);
3362 XSETINT (emacs_event
->y
, top_range
);
3366 /* Handle some mouse motion while someone is dragging the scroll bar.
3368 This may be called from a signal handler, so we have to ignore GC
3371 x_scroll_bar_note_movement (bar
, event
)
3372 struct scroll_bar
*bar
;
3375 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
3377 last_mouse_movement_time
= event
->xmotion
.time
;
3380 XSETVECTOR (last_mouse_scroll_bar
, bar
);
3382 /* If we're dragging the bar, display it. */
3383 if (! GC_NILP (bar
->dragging
))
3385 /* Where should the handle be now? */
3386 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
3388 if (new_start
!= XINT (bar
->start
))
3390 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
3392 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
3397 /* Return information to the user about the current position of the mouse
3398 on the scroll bar. */
3400 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
3402 Lisp_Object
*bar_window
;
3403 enum scroll_bar_part
*part
;
3405 unsigned long *time
;
3407 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
3408 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3409 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3411 Window dummy_window
;
3413 unsigned int dummy_mask
;
3417 /* Get the mouse's position relative to the scroll bar window, and
3419 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
3421 /* Root, child, root x and root y. */
3422 &dummy_window
, &dummy_window
,
3423 &dummy_coord
, &dummy_coord
,
3425 /* Position relative to scroll bar. */
3428 /* Mouse buttons and modifier keys. */
3434 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
3436 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3438 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
3440 if (! NILP (bar
->dragging
))
3441 win_y
-= XINT (bar
->dragging
);
3445 if (win_y
> top_range
)
3449 *bar_window
= bar
->window
;
3451 if (! NILP (bar
->dragging
))
3452 *part
= scroll_bar_handle
;
3453 else if (win_y
< XINT (bar
->start
))
3454 *part
= scroll_bar_above_handle
;
3455 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3456 *part
= scroll_bar_handle
;
3458 *part
= scroll_bar_below_handle
;
3460 XSETINT (*x
, win_y
);
3461 XSETINT (*y
, top_range
);
3464 last_mouse_scroll_bar
= Qnil
;
3467 *time
= last_mouse_movement_time
;
3473 /* The screen has been cleared so we may have changed foreground or
3474 background colors, and the scroll bars may need to be redrawn.
3475 Clear out the scroll bars, and ask for expose events, so we can
3478 x_scroll_bar_clear (f
)
3483 /* We can have scroll bars even if this is 0,
3484 if we just turned off scroll bar mode.
3485 But in that case we should not clear them. */
3486 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3487 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
3488 bar
= XSCROLL_BAR (bar
)->next
)
3489 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
3493 /* This processes Expose events from the menubar specific X event
3494 loop in xmenu.c. This allows to redisplay the frame if necessary
3495 when handling menubar or popup items. */
3498 process_expose_from_menu (event
)
3502 struct x_display_info
*dpyinfo
;
3506 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
3507 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3510 if (f
->async_visible
== 0)
3512 f
->async_visible
= 1;
3513 f
->async_iconified
= 0;
3514 SET_FRAME_GARBAGED (f
);
3518 dumprectangle (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
3519 event
.xexpose
.x
, event
.xexpose
.y
,
3520 event
.xexpose
.width
, event
.xexpose
.height
);
3525 struct scroll_bar
*bar
3526 = x_window_to_scroll_bar (event
.xexpose
.window
);
3529 x_scroll_bar_expose (bar
, &event
);
3535 /* Define a queue to save up SelectionRequest events for later handling. */
3537 struct selection_event_queue
3540 struct selection_event_queue
*next
;
3543 static struct selection_event_queue
*queue
;
3545 /* Nonzero means queue up certain events--don't process them yet. */
3546 static int x_queue_selection_requests
;
3548 /* Queue up an X event *EVENT, to be processed later. */
3551 x_queue_event (f
, event
)
3555 struct selection_event_queue
*queue_tmp
3556 = (struct selection_event_queue
*) malloc (sizeof (struct selection_event_queue
));
3558 if (queue_tmp
!= NULL
)
3560 queue_tmp
->event
= *event
;
3561 queue_tmp
->next
= queue
;
3566 /* Take all the queued events and put them back
3567 so that they get processed afresh. */
3570 x_unqueue_events (display
)
3573 while (queue
!= NULL
)
3575 struct selection_event_queue
*queue_tmp
= queue
;
3576 XPutBackEvent (display
, &queue_tmp
->event
);
3577 queue
= queue_tmp
->next
;
3578 free ((char *)queue_tmp
);
3582 /* Start queuing SelectionRequest events. */
3585 x_start_queuing_selection_requests (display
)
3588 x_queue_selection_requests
++;
3591 /* Stop queuing SelectionRequest events. */
3594 x_stop_queuing_selection_requests (display
)
3597 x_queue_selection_requests
--;
3598 x_unqueue_events (display
);
3601 /* The main X event-reading loop - XTread_socket. */
3603 /* Timestamp of enter window event. This is only used by XTread_socket,
3604 but we have to put it out here, since static variables within functions
3605 sometimes don't work. */
3606 static Time enter_timestamp
;
3608 /* This holds the state XLookupString needs to implement dead keys
3609 and other tricks known as "compose processing". _X Window System_
3610 says that a portable program can't use this, but Stephen Gildea assures
3611 me that letting the compiler initialize it to zeros will work okay.
3613 This must be defined outside of XTread_socket, for the same reasons
3614 given for enter_timestamp, above. */
3615 static XComposeStatus compose_status
;
3617 /* Record the last 100 characters stored
3618 to help debug the loss-of-chars-during-GC problem. */
3619 static int temp_index
;
3620 static short temp_buffer
[100];
3622 /* Set this to nonzero to fake an "X I/O error"
3623 on a particular display. */
3624 struct x_display_info
*XTread_socket_fake_io_error
;
3626 /* When we find no input here, we occasionally do a no-op command
3627 to verify that the X server is still running and we can still talk with it.
3628 We try all the open displays, one by one.
3629 This variable is used for cycling thru the displays. */
3630 static struct x_display_info
*next_noop_dpyinfo
;
3632 #define SET_SAVED_MENU_EVENT(size) { \
3633 if (f->output_data.x->saved_menu_event == 0) \
3634 f->output_data.x->saved_menu_event = (XEvent*)xmalloc (sizeof (XEvent)); \
3635 bcopy (&event, f->output_data.x->saved_menu_event, size); \
3636 if (numchars >= 1) \
3638 bufp->kind = menu_bar_activate_event; \
3639 XSETFRAME (bufp->frame_or_window, f); \
3645 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
3646 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
3648 /* Read events coming from the X server.
3649 This routine is called by the SIGIO handler.
3650 We return as soon as there are no more events to be read.
3652 Events representing keys are stored in buffer BUFP,
3653 which can hold up to NUMCHARS characters.
3654 We return the number of characters stored into the buffer,
3655 thus pretending to be `read'.
3657 EXPECTED is nonzero if the caller knows input is available. */
3660 XTread_socket (sd
, bufp
, numchars
, expected
)
3662 /* register */ struct input_event
*bufp
;
3663 /* register */ int numchars
;
3669 int items_pending
; /* How many items are in the X queue. */
3672 int event_found
= 0;
3675 struct x_display_info
*dpyinfo
;
3677 Status status_return
;
3680 if (interrupt_input_blocked
)
3682 interrupt_input_pending
= 1;
3686 interrupt_input_pending
= 0;
3689 /* So people can tell when we have read the available input. */
3690 input_signal_count
++;
3693 abort (); /* Don't think this happens. */
3695 /* Find the display we are supposed to read input for.
3696 It's the one communicating on descriptor SD. */
3697 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
3699 #if 0 /* This ought to be unnecessary; let's verify it. */
3701 /* If available, Xlib uses FIOSNBIO to make the socket
3702 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3703 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
3704 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3705 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
3706 #endif /* ! defined (FIOSNBIO) */
3709 #if 0 /* This code can't be made to work, with multiple displays,
3710 and appears not to be used on any system any more.
3711 Also keyboard.c doesn't turn O_NDELAY on and off
3712 for X connections. */
3715 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
3717 extern int read_alarm_should_throw
;
3718 read_alarm_should_throw
= 1;
3719 XPeekEvent (dpyinfo
->display
, &event
);
3720 read_alarm_should_throw
= 0;
3722 #endif /* HAVE_SELECT */
3726 /* For debugging, this gives a way to fake an I/O error. */
3727 if (dpyinfo
== XTread_socket_fake_io_error
)
3729 XTread_socket_fake_io_error
= 0;
3730 x_io_error_quitter (dpyinfo
->display
);
3733 while (XPending (dpyinfo
->display
) != 0)
3735 #ifdef USE_X_TOOLKIT
3736 /* needed to raise Motif submenus */
3737 XtAppNextEvent (Xt_app_con
, &event
);
3739 XNextEvent (dpyinfo
->display
, &event
);
3743 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
3744 &event
.xclient
.window
);
3745 /* The necessity of the following line took me
3746 a full work-day to decipher from the docs!! */
3747 if (f1
!= 0 && FRAME_XIC (f1
) && XFilterEvent (&event
, None
))
3757 if (event
.xclient
.message_type
3758 == dpyinfo
->Xatom_wm_protocols
3759 && event
.xclient
.format
== 32)
3761 if (event
.xclient
.data
.l
[0]
3762 == dpyinfo
->Xatom_wm_take_focus
)
3764 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3765 /* Since we set WM_TAKE_FOCUS, we must call
3766 XSetInputFocus explicitly. But not if f is null,
3767 since that might be an event for a deleted frame. */
3769 /* Not quite sure this is needed -pd */
3771 XSetICFocus (FRAME_XIC (f
));
3774 XSetInputFocus (event
.xclient
.display
,
3775 event
.xclient
.window
,
3776 RevertToPointerRoot
,
3777 event
.xclient
.data
.l
[1]);
3778 /* Not certain about handling scroll bars here */
3780 else if (event
.xclient
.data
.l
[0]
3781 == dpyinfo
->Xatom_wm_save_yourself
)
3783 /* Save state modify the WM_COMMAND property to
3784 something which can reinstate us. This notifies
3785 the session manager, who's looking for such a
3786 PropertyNotify. Can restart processing when
3787 a keyboard or mouse event arrives. */
3790 f
= x_top_window_to_frame (dpyinfo
,
3791 event
.xclient
.window
);
3793 /* This is just so we only give real data once
3794 for a single Emacs process. */
3795 if (f
== selected_frame
)
3796 XSetCommand (FRAME_X_DISPLAY (f
),
3797 event
.xclient
.window
,
3798 initial_argv
, initial_argc
);
3800 XSetCommand (FRAME_X_DISPLAY (f
),
3801 event
.xclient
.window
,
3805 else if (event
.xclient
.data
.l
[0]
3806 == dpyinfo
->Xatom_wm_delete_window
)
3809 = x_any_window_to_frame (dpyinfo
,
3810 event
.xclient
.window
);
3817 bufp
->kind
= delete_window_event
;
3818 XSETFRAME (bufp
->frame_or_window
, f
);
3826 else if (event
.xclient
.message_type
3827 == dpyinfo
->Xatom_wm_configure_denied
)
3830 else if (event
.xclient
.message_type
3831 == dpyinfo
->Xatom_wm_window_moved
)
3835 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3837 new_x
= event
.xclient
.data
.s
[0];
3838 new_y
= event
.xclient
.data
.s
[1];
3842 f
->output_data
.x
->left_pos
= new_x
;
3843 f
->output_data
.x
->top_pos
= new_y
;
3847 else if (event
.xclient
.message_type
3848 == dpyinfo
->Xatom_editres
)
3851 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
3852 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
3855 #endif /* HACK_EDITRES */
3859 case SelectionNotify
:
3860 #ifdef USE_X_TOOLKIT
3861 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
3863 #endif /* not USE_X_TOOLKIT */
3864 x_handle_selection_notify (&event
);
3867 case SelectionClear
: /* Someone has grabbed ownership. */
3868 #ifdef USE_X_TOOLKIT
3869 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
3871 #endif /* USE_X_TOOLKIT */
3873 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
3878 bufp
->kind
= selection_clear_event
;
3879 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3880 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3881 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3882 bufp
->frame_or_window
= Qnil
;
3890 case SelectionRequest
: /* Someone wants our selection. */
3891 #ifdef USE_X_TOOLKIT
3892 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
3894 #endif /* USE_X_TOOLKIT */
3895 if (x_queue_selection_requests
)
3896 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
3900 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
3905 bufp
->kind
= selection_request_event
;
3906 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3907 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
3908 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3909 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
3910 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
3911 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3912 bufp
->frame_or_window
= Qnil
;
3920 case PropertyNotify
:
3921 #ifdef USE_X_TOOLKIT
3922 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
3924 #endif /* not USE_X_TOOLKIT */
3925 x_handle_property_notify (&event
);
3928 case ReparentNotify
:
3929 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
3933 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
3934 x_real_positions (f
, &x
, &y
);
3935 f
->output_data
.x
->left_pos
= x
;
3936 f
->output_data
.x
->top_pos
= y
;
3941 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3944 if (f
->async_visible
== 0)
3946 f
->async_visible
= 1;
3947 f
->async_iconified
= 0;
3948 SET_FRAME_GARBAGED (f
);
3951 dumprectangle (x_window_to_frame (dpyinfo
,
3952 event
.xexpose
.window
),
3953 event
.xexpose
.x
, event
.xexpose
.y
,
3954 event
.xexpose
.width
, event
.xexpose
.height
);
3958 struct scroll_bar
*bar
3959 = x_window_to_scroll_bar (event
.xexpose
.window
);
3962 x_scroll_bar_expose (bar
, &event
);
3963 #ifdef USE_X_TOOLKIT
3966 #endif /* USE_X_TOOLKIT */
3970 case GraphicsExpose
: /* This occurs when an XCopyArea's
3971 source area was obscured or not
3973 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
3977 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
3978 event
.xgraphicsexpose
.width
,
3979 event
.xgraphicsexpose
.height
);
3981 #ifdef USE_X_TOOLKIT
3984 #endif /* USE_X_TOOLKIT */
3987 case NoExpose
: /* This occurs when an XCopyArea's
3988 source area was completely
3993 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
3994 if (f
) /* F may no longer exist if
3995 the frame was deleted. */
3997 /* While a frame is unmapped, display generation is
3998 disabled; you don't want to spend time updating a
3999 display that won't ever be seen. */
4000 f
->async_visible
= 0;
4001 /* We can't distinguish, from the event, whether the window
4002 has become iconified or invisible. So assume, if it
4003 was previously visible, than now it is iconified.
4004 We depend on x_make_frame_invisible to mark it invisible. */
4005 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
4006 f
->async_iconified
= 1;
4008 bufp
->kind
= iconify_event
;
4009 XSETFRAME (bufp
->frame_or_window
, f
);
4017 /* We use x_top_window_to_frame because map events can come
4018 for subwindows and they don't mean that the frame is visible. */
4019 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
4022 f
->async_visible
= 1;
4023 f
->async_iconified
= 0;
4025 /* wait_reading_process_input will notice this and update
4026 the frame's display structures. */
4027 SET_FRAME_GARBAGED (f
);
4031 bufp
->kind
= deiconify_event
;
4032 XSETFRAME (bufp
->frame_or_window
, f
);
4037 else if (! NILP (Vframe_list
)
4038 && ! NILP (XCONS (Vframe_list
)->cdr
))
4039 /* Force a redisplay sooner or later
4040 to update the frame titles
4041 in case this is the second frame. */
4042 record_asynch_buffer_change ();
4046 /* Turn off processing if we become fully obscured. */
4047 case VisibilityNotify
:
4051 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
4055 KeySym keysym
, orig_keysym
;
4056 /* al%imercury@uunet.uu.net says that making this 81 instead of
4057 80 fixed a bug whereby meta chars made his Emacs hang. */
4058 unsigned char copy_buffer
[81];
4061 #if 0 /* This was how we made f10 work in Motif.
4062 The drawback is, you can't type at Emacs when the
4063 the mouse is in the menu bar. So it is better to
4064 turn off f10 in Motif and let Emacs handle it. */
4066 if (lw_window_is_in_menubar (event
.xkey
.window
,
4067 f
->output_data
.x
->menubar_widget
4070 SET_SAVED_KEY_EVENT
;
4073 #endif /* USE_MOTIF */
4077 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
4078 extra_keyboard_modifiers
);
4079 modifiers
= event
.xkey
.state
;
4081 /* This will have to go some day... */
4083 /* make_lispy_event turns chars into control chars.
4084 Don't do it here because XLookupString is too eager. */
4085 event
.xkey
.state
&= ~ControlMask
;
4086 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
4087 | dpyinfo
->super_mod_mask
4088 | dpyinfo
->hyper_mod_mask
4089 | dpyinfo
->alt_mod_mask
);
4091 /* In case Meta is ComposeCharacter,
4092 clear its status. According to Markus Ehrnsperger
4093 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
4094 this enables ComposeCharacter to work whether or
4095 not it is combined with Meta. */
4096 if (modifiers
& dpyinfo
->meta_mod_mask
)
4097 bzero (&compose_status
, sizeof (compose_status
));
4102 nbytes
= XmbLookupString (FRAME_XIC (f
),
4103 &event
.xkey
, copy_buffer
,
4108 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
4109 80, &keysym
, &compose_status
);
4111 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
4112 80, &keysym
, &compose_status
);
4115 orig_keysym
= keysym
;
4119 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
4120 || keysym
== XK_Delete
4121 #ifdef XK_ISO_Left_Tab
4122 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
4124 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
4125 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
4127 /* This recognizes the "extended function keys".
4128 It seems there's no cleaner way.
4129 Test IsModifierKey to avoid handling mode_switch
4131 || ((unsigned) (keysym
) >= XK_Select
4132 && (unsigned)(keysym
) < XK_KP_Space
)
4134 #ifdef XK_dead_circumflex
4135 || orig_keysym
== XK_dead_circumflex
4137 #ifdef XK_dead_grave
4138 || orig_keysym
== XK_dead_grave
4140 #ifdef XK_dead_tilde
4141 || orig_keysym
== XK_dead_tilde
4143 #ifdef XK_dead_diaeresis
4144 || orig_keysym
== XK_dead_diaeresis
4146 #ifdef XK_dead_macron
4147 || orig_keysym
== XK_dead_macron
4149 #ifdef XK_dead_degree
4150 || orig_keysym
== XK_dead_degree
4152 #ifdef XK_dead_acute
4153 || orig_keysym
== XK_dead_acute
4155 #ifdef XK_dead_cedilla
4156 || orig_keysym
== XK_dead_cedilla
4158 #ifdef XK_dead_breve
4159 || orig_keysym
== XK_dead_breve
4161 #ifdef XK_dead_ogonek
4162 || orig_keysym
== XK_dead_ogonek
4164 #ifdef XK_dead_caron
4165 || orig_keysym
== XK_dead_caron
4167 #ifdef XK_dead_doubleacute
4168 || orig_keysym
== XK_dead_doubleacute
4170 #ifdef XK_dead_abovedot
4171 || orig_keysym
== XK_dead_abovedot
4173 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
4174 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
4175 /* Any "vendor-specific" key is ok. */
4176 || (orig_keysym
& (1 << 28)))
4177 && ! (IsModifierKey (orig_keysym
)
4179 #ifdef XK_Mode_switch
4180 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
4183 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
4185 #endif /* not HAVE_X11R5 */
4188 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4190 temp_buffer
[temp_index
++] = keysym
;
4191 bufp
->kind
= non_ascii_keystroke
;
4192 bufp
->code
= keysym
;
4193 XSETFRAME (bufp
->frame_or_window
, f
);
4195 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
4197 bufp
->timestamp
= event
.xkey
.time
;
4202 else if (numchars
> nbytes
)
4206 for (i
= 0; i
< nbytes
; i
++)
4208 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4210 temp_buffer
[temp_index
++] = copy_buffer
[i
];
4211 bufp
->kind
= ascii_keystroke
;
4212 bufp
->code
= copy_buffer
[i
];
4213 XSETFRAME (bufp
->frame_or_window
, f
);
4215 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
4217 bufp
->timestamp
= event
.xkey
.time
;
4232 /* Here's a possible interpretation of the whole
4233 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
4234 FocusIn event, you have to get a FocusOut event before you
4235 relinquish the focus. If you haven't received a FocusIn event,
4236 then a mere LeaveNotify is enough to free you. */
4239 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
4241 if (event
.xcrossing
.focus
) /* Entered Window */
4243 /* Avoid nasty pop/raise loops. */
4244 if (f
&& (!(f
->auto_raise
)
4246 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
4248 x_new_focus_frame (dpyinfo
, f
);
4249 enter_timestamp
= event
.xcrossing
.time
;
4252 else if (f
== dpyinfo
->x_focus_frame
)
4253 x_new_focus_frame (dpyinfo
, 0);
4254 /* EnterNotify counts as mouse movement,
4255 so update things that depend on mouse position. */
4257 note_mouse_movement (f
, &event
.xmotion
);
4261 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
4262 if (event
.xfocus
.detail
!= NotifyPointer
)
4263 dpyinfo
->x_focus_event_frame
= f
;
4265 x_new_focus_frame (dpyinfo
, f
);
4268 if (f
&& FRAME_XIC (f
))
4269 XSetICFocus (FRAME_XIC (f
));
4275 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
4278 if (f
== dpyinfo
->mouse_face_mouse_frame
)
4279 /* If we move outside the frame,
4280 then we're certainly no longer on any text in the frame. */
4281 clear_mouse_face (dpyinfo
);
4283 if (event
.xcrossing
.focus
)
4284 x_mouse_leave (dpyinfo
);
4287 if (f
== dpyinfo
->x_focus_event_frame
)
4288 dpyinfo
->x_focus_event_frame
= 0;
4289 if (f
== dpyinfo
->x_focus_frame
)
4290 x_new_focus_frame (dpyinfo
, 0);
4296 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
4297 if (event
.xfocus
.detail
!= NotifyPointer
4298 && f
== dpyinfo
->x_focus_event_frame
)
4299 dpyinfo
->x_focus_event_frame
= 0;
4300 if (f
&& f
== dpyinfo
->x_focus_frame
)
4301 x_new_focus_frame (dpyinfo
, 0);
4304 if (f
&& FRAME_XIC (f
))
4305 XUnsetICFocus (FRAME_XIC (f
));
4312 if (dpyinfo
->grabbed
&& last_mouse_frame
4313 && FRAME_LIVE_P (last_mouse_frame
))
4314 f
= last_mouse_frame
;
4316 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
4318 note_mouse_movement (f
, &event
.xmotion
);
4321 struct scroll_bar
*bar
4322 = x_window_to_scroll_bar (event
.xmotion
.window
);
4325 x_scroll_bar_note_movement (bar
, &event
);
4327 /* If we move outside the frame,
4328 then we're certainly no longer on any text in the frame. */
4329 clear_mouse_face (dpyinfo
);
4334 case ConfigureNotify
:
4335 f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
4337 #ifdef USE_X_TOOLKIT
4338 && (event
.xconfigure
.window
== XtWindow (f
->output_data
.x
->widget
))
4342 #ifndef USE_X_TOOLKIT
4343 /* In the toolkit version, change_frame_size
4344 is called by the code that handles resizing
4345 of the EmacsFrame widget. */
4347 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
4348 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
4350 /* Even if the number of character rows and columns has
4351 not changed, the font size may have changed, so we need
4352 to check the pixel dimensions as well. */
4353 if (columns
!= f
->width
4354 || rows
!= f
->height
4355 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
4356 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
4358 change_frame_size (f
, rows
, columns
, 0, 1);
4359 SET_FRAME_GARBAGED (f
);
4360 cancel_mouse_face (f
);
4364 /* Formerly, in the USE_X_TOOLKIT version,
4365 we did not test send_event here. */
4367 #ifndef USE_X_TOOLKIT
4368 && ! event
.xconfigure
.send_event
4375 /* Find the position of the outside upper-left corner of
4376 the window, in the root coordinate system. Don't
4377 refer to the parent window here; we may be processing
4378 this event after the window manager has changed our
4379 parent, but before we have reached the ReparentNotify. */
4380 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
4382 /* From-window, to-window. */
4383 event
.xconfigure
.window
,
4384 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4386 /* From-position, to-position. */
4387 -event
.xconfigure
.border_width
,
4388 -event
.xconfigure
.border_width
,
4393 event
.xconfigure
.x
= win_x
;
4394 event
.xconfigure
.y
= win_y
;
4397 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
4398 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
4399 f
->output_data
.x
->left_pos
= event
.xconfigure
.x
;
4400 f
->output_data
.x
->top_pos
= event
.xconfigure
.y
;
4402 /* What we have now is the position of Emacs's own window.
4403 Convert that to the position of the window manager window. */
4406 x_real_positions (f
, &x
, &y
);
4407 f
->output_data
.x
->left_pos
= x
;
4408 f
->output_data
.x
->top_pos
= y
;
4409 /* Formerly we did not do this in the USE_X_TOOLKIT
4410 version. Let's try making them the same. */
4411 /* #ifndef USE_X_TOOLKIT */
4412 if (y
!= event
.xconfigure
.y
)
4414 /* Since the WM decorations come below top_pos now,
4415 we must put them below top_pos in the future. */
4416 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
4417 x_wm_set_size_hint (f
, (long) 0, 0);
4427 /* If we decide we want to generate an event to be seen
4428 by the rest of Emacs, we put it here. */
4429 struct input_event emacs_event
;
4430 emacs_event
.kind
= no_event
;
4432 bzero (&compose_status
, sizeof (compose_status
));
4434 if (dpyinfo
->grabbed
&& last_mouse_frame
4435 && FRAME_LIVE_P (last_mouse_frame
))
4436 f
= last_mouse_frame
;
4438 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
4442 if (!dpyinfo
->x_focus_frame
|| f
== dpyinfo
->x_focus_frame
)
4443 construct_mouse_click (&emacs_event
, &event
, f
);
4447 struct scroll_bar
*bar
4448 = x_window_to_scroll_bar (event
.xbutton
.window
);
4451 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
4454 if (event
.type
== ButtonPress
)
4456 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
4457 last_mouse_frame
= f
;
4461 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
4464 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
4466 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
4472 #ifdef USE_X_TOOLKIT
4473 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
4474 /* For a down-event in the menu bar,
4475 don't pass it to Xt right now.
4476 Instead, save it away
4477 and we will pass it to Xt from kbd_buffer_get_event.
4478 That way, we can run some Lisp code first. */
4479 if (f
&& event
.type
== ButtonPress
4480 /* Verify the event is really within the menu bar
4481 and not just sent to it due to grabbing. */
4482 && event
.xbutton
.x
>= 0
4483 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
4484 && event
.xbutton
.y
>= 0
4485 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
4486 && event
.xbutton
.same_screen
)
4488 SET_SAVED_BUTTON_EVENT
;
4489 XSETFRAME (last_mouse_press_frame
, f
);
4491 else if (event
.type
== ButtonPress
)
4493 last_mouse_press_frame
= Qnil
;
4496 #ifdef USE_MOTIF /* This should do not harm for Lucid,
4497 but I am trying to be cautious. */
4498 else if (event
.type
== ButtonRelease
)
4500 if (!NILP (last_mouse_press_frame
))
4502 f
= XFRAME (last_mouse_press_frame
);
4503 if (f
->output_data
.x
)
4505 SET_SAVED_BUTTON_EVENT
;
4511 #endif /* USE_MOTIF */
4514 #endif /* USE_X_TOOLKIT */
4518 case CirculateNotify
:
4520 case CirculateRequest
:
4524 /* Someone has changed the keyboard mapping - update the
4526 switch (event
.xmapping
.request
)
4528 case MappingModifier
:
4529 x_find_modifier_meanings (dpyinfo
);
4530 /* This is meant to fall through. */
4531 case MappingKeyboard
:
4532 XRefreshKeyboardMapping (&event
.xmapping
);
4538 #ifdef USE_X_TOOLKIT
4540 XtDispatchEvent (&event
);
4542 #endif /* USE_X_TOOLKIT */
4548 /* On some systems, an X bug causes Emacs to get no more events
4549 when the window is destroyed. Detect that. (1994.) */
4552 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
4553 One XNOOP in 100 loops will make Emacs terminate.
4554 B. Bretthauer, 1994 */
4556 if (x_noop_count
>= 100)
4560 if (next_noop_dpyinfo
== 0)
4561 next_noop_dpyinfo
= x_display_list
;
4563 XNoOp (next_noop_dpyinfo
->display
);
4565 /* Each time we get here, cycle through the displays now open. */
4566 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
4570 /* If the focus was just given to an autoraising frame,
4572 /* ??? This ought to be able to handle more than one such frame. */
4573 if (pending_autoraise_frame
)
4575 x_raise_frame (pending_autoraise_frame
);
4576 pending_autoraise_frame
= 0;
4583 /* Drawing the cursor. */
4586 /* Draw a hollow box cursor on frame F at X, Y.
4587 Don't change the inside of the box. */
4590 x_draw_box (f
, x
, y
)
4594 int left
= CHAR_TO_PIXEL_COL (f
, x
);
4595 int top
= CHAR_TO_PIXEL_ROW (f
, y
);
4596 int width
= FONT_WIDTH (f
->output_data
.x
->font
);
4597 int height
= f
->output_data
.x
->line_height
;
4598 int c
= FAST_GLYPH_CHAR (f
->phys_cursor_glyph
);
4599 int charset
= CHAR_CHARSET (c
);
4601 /* If cursor is on a multi-column character, multiply WIDTH by columns. */
4602 width
*= (charset
== CHARSET_COMPOSITION
4603 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
4604 : CHARSET_WIDTH (charset
));
4605 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4606 f
->output_data
.x
->cursor_gc
,
4607 left
, top
, width
- 1, height
- 1);
4610 /* Clear the cursor of frame F to background color,
4611 and mark the cursor as not shown.
4612 This is used when the text where the cursor is
4613 is about to be rewritten. */
4621 if (! FRAME_VISIBLE_P (f
)
4622 || ! f
->phys_cursor_on
)
4625 x_update_cursor (f
, 0);
4626 f
->phys_cursor_on
= 0;
4629 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4630 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4634 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
4641 CHAR_TO_PIXEL_COL (f
, column
),
4642 CHAR_TO_PIXEL_ROW (f
, row
),
4643 &glyph
, 1, highlight
, 0, NULL
);
4647 x_display_bar_cursor (f
, on
, x
, y
)
4652 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4654 /* This is pointless on invisible frames, and dangerous on garbaged
4655 frames; in the latter case, the frame may be in the midst of
4656 changing its size, and x and y may be off the frame. */
4657 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4660 if (! on
&& ! f
->phys_cursor_on
)
4663 /* If there is anything wrong with the current cursor state, remove it. */
4664 if (f
->phys_cursor_on
4666 || f
->phys_cursor_x
!= x
4667 || f
->phys_cursor_y
!= y
4668 || f
->output_data
.x
->current_cursor
!= bar_cursor
))
4670 /* Erase the cursor by redrawing the character underneath it. */
4671 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4672 f
->phys_cursor_glyph
,
4673 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4674 f
->phys_cursor_on
= 0;
4677 /* If we now need a cursor in the new place or in the new form, do it so. */
4679 && (! f
->phys_cursor_on
4680 || (f
->output_data
.x
->current_cursor
!= bar_cursor
)))
4682 f
->phys_cursor_glyph
4683 = ((current_glyphs
->enable
[y
]
4684 && x
< current_glyphs
->used
[y
])
4685 ? current_glyphs
->glyphs
[y
][x
]
4687 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4688 f
->output_data
.x
->cursor_gc
,
4689 CHAR_TO_PIXEL_COL (f
, x
),
4690 CHAR_TO_PIXEL_ROW (f
, y
),
4691 max (f
->output_data
.x
->cursor_width
, 1),
4692 f
->output_data
.x
->line_height
);
4694 f
->phys_cursor_x
= x
;
4695 f
->phys_cursor_y
= y
;
4696 f
->phys_cursor_on
= 1;
4698 f
->output_data
.x
->current_cursor
= bar_cursor
;
4701 if (updating_frame
!= f
)
4702 XFlush (FRAME_X_DISPLAY (f
));
4706 /* Turn the displayed cursor of frame F on or off according to ON.
4707 If ON is nonzero, where to put the cursor is specified by X and Y. */
4710 x_display_box_cursor (f
, on
, x
, y
)
4715 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4717 /* This is pointless on invisible frames, and dangerous on garbaged
4718 frames; in the latter case, the frame may be in the midst of
4719 changing its size, and x and y may be off the frame. */
4720 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4723 /* If cursor is off and we want it off, return quickly. */
4724 if (!on
&& ! f
->phys_cursor_on
)
4727 /* If cursor is currently being shown and we don't want it to be
4728 or it is in the wrong place,
4729 or we want a hollow box and it's not so, (pout!)
4731 if (f
->phys_cursor_on
4733 || f
->phys_cursor_x
!= x
4734 || f
->phys_cursor_y
!= y
4735 || (f
->output_data
.x
->current_cursor
!= hollow_box_cursor
4736 && (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
))))
4738 int mouse_face_here
= 0;
4739 struct frame_glyphs
*active_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4741 /* If the cursor is in the mouse face area, redisplay that when
4742 we clear the cursor. */
4743 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
4745 (f
->phys_cursor_y
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4746 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4747 && f
->phys_cursor_x
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
))
4749 (f
->phys_cursor_y
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4750 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4751 && f
->phys_cursor_x
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
))
4752 /* Don't redraw the cursor's spot in mouse face
4753 if it is at the end of a line (on a newline).
4754 The cursor appears there, but mouse highlighting does not. */
4755 && active_glyphs
->used
[f
->phys_cursor_y
] > f
->phys_cursor_x
)
4756 mouse_face_here
= 1;
4758 /* If the font is not as tall as a whole line,
4759 we must explicitly clear the line's whole height. */
4760 if (FONT_HEIGHT (f
->output_data
.x
->font
) != f
->output_data
.x
->line_height
)
4761 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4762 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
4763 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
4764 FONT_WIDTH (f
->output_data
.x
->font
),
4765 f
->output_data
.x
->line_height
, False
);
4766 /* Erase the cursor by redrawing the character underneath it. */
4767 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4768 f
->phys_cursor_glyph
,
4771 : current_glyphs
->highlight
[f
->phys_cursor_y
]));
4772 f
->phys_cursor_on
= 0;
4775 /* If we want to show a cursor,
4776 or we want a box cursor and it's not so,
4777 write it in the right place. */
4779 && (! f
->phys_cursor_on
4780 || (f
->output_data
.x
->current_cursor
!= filled_box_cursor
4781 && f
== FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)))
4783 f
->phys_cursor_glyph
4784 = ((current_glyphs
->enable
[y
]
4785 && x
< current_glyphs
->used
[y
])
4786 ? current_glyphs
->glyphs
[y
][x
]
4788 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
4790 x_draw_box (f
, x
, y
);
4791 f
->output_data
.x
->current_cursor
= hollow_box_cursor
;
4795 x_draw_single_glyph (f
, y
, x
,
4796 f
->phys_cursor_glyph
, 2);
4797 f
->output_data
.x
->current_cursor
= filled_box_cursor
;
4800 f
->phys_cursor_x
= x
;
4801 f
->phys_cursor_y
= y
;
4802 f
->phys_cursor_on
= 1;
4805 if (updating_frame
!= f
)
4806 XFlush (FRAME_X_DISPLAY (f
));
4809 /* Display the cursor on frame F, or clear it, according to ON.
4810 Also set the frame's cursor position to X and Y. */
4812 x_display_cursor (f
, on
, x
, y
)
4819 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4820 x_display_box_cursor (f
, on
, x
, y
);
4821 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4822 x_display_bar_cursor (f
, on
, x
, y
);
4824 /* Those are the only two we have implemented! */
4830 /* Display the cursor on frame F, or clear it, according to ON.
4831 Don't change the cursor's position. */
4833 x_update_cursor (f
, on
)
4839 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4840 x_display_box_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4841 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4842 x_display_bar_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4844 /* Those are the only two we have implemented! */
4852 /* Refresh bitmap kitchen sink icon for frame F
4853 when we get an expose event for it. */
4858 /* Normally, the window manager handles this function. */
4861 /* Make the x-window of frame F use the gnu icon bitmap. */
4864 x_bitmap_icon (f
, file
)
4868 int mask
, bitmap_id
;
4871 if (FRAME_X_WINDOW (f
) == 0)
4874 /* Free up our existing icon bitmap if any. */
4875 if (f
->output_data
.x
->icon_bitmap
> 0)
4876 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
4877 f
->output_data
.x
->icon_bitmap
= 0;
4880 bitmap_id
= x_create_bitmap_from_file (f
, file
);
4883 /* Create the GNU bitmap if necessary. */
4884 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
4885 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
4886 = x_create_bitmap_from_data (f
, gnu_bits
,
4887 gnu_width
, gnu_height
);
4889 /* The first time we create the GNU bitmap,
4890 this increments the refcount one extra time.
4891 As a result, the GNU bitmap is never freed.
4892 That way, we don't have to worry about allocating it again. */
4893 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
4895 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
4898 x_wm_set_icon_pixmap (f
, bitmap_id
);
4899 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
4905 /* Make the x-window of frame F use a rectangle with text.
4906 Use ICON_NAME as the text. */
4909 x_text_icon (f
, icon_name
)
4913 if (FRAME_X_WINDOW (f
) == 0)
4919 text
.value
= (unsigned char *) icon_name
;
4920 text
.encoding
= XA_STRING
;
4922 text
.nitems
= strlen (icon_name
);
4923 #ifdef USE_X_TOOLKIT
4924 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
4926 #else /* not USE_X_TOOLKIT */
4927 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
4928 #endif /* not USE_X_TOOLKIT */
4930 #else /* not HAVE_X11R4 */
4931 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
4932 #endif /* not HAVE_X11R4 */
4934 if (f
->output_data
.x
->icon_bitmap
> 0)
4935 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
4936 f
->output_data
.x
->icon_bitmap
= 0;
4937 x_wm_set_icon_pixmap (f
, 0);
4942 #define X_ERROR_MESSAGE_SIZE 200
4944 /* If non-nil, this should be a string.
4945 It means catch X errors and store the error message in this string. */
4947 static Lisp_Object x_error_message_string
;
4949 /* An X error handler which stores the error message in
4950 x_error_message_string. This is called from x_error_handler if
4951 x_catch_errors is in effect. */
4954 x_error_catcher (display
, error
)
4958 XGetErrorText (display
, error
->error_code
,
4959 XSTRING (x_error_message_string
)->data
,
4960 X_ERROR_MESSAGE_SIZE
);
4963 /* Begin trapping X errors for display DPY. Actually we trap X errors
4964 for all displays, but DPY should be the display you are actually
4967 After calling this function, X protocol errors no longer cause
4968 Emacs to exit; instead, they are recorded in the string
4969 stored in x_error_message_string.
4971 Calling x_check_errors signals an Emacs error if an X error has
4972 occurred since the last call to x_catch_errors or x_check_errors.
4974 Calling x_uncatch_errors resumes the normal error handling. */
4976 void x_check_errors ();
4977 static Lisp_Object
x_catch_errors_unwind ();
4980 x_catch_errors (dpy
)
4983 int count
= specpdl_ptr
- specpdl
;
4985 /* Make sure any errors from previous requests have been dealt with. */
4988 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
4990 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
4991 XSTRING (x_error_message_string
)->data
[0] = 0;
4996 /* Unbind the binding that we made to check for X errors. */
4999 x_catch_errors_unwind (old_val
)
5000 Lisp_Object old_val
;
5002 x_error_message_string
= old_val
;
5006 /* If any X protocol errors have arrived since the last call to
5007 x_catch_errors or x_check_errors, signal an Emacs error using
5008 sprintf (a buffer, FORMAT, the x error message text) as the text. */
5011 x_check_errors (dpy
, format
)
5015 /* Make sure to catch any errors incurred so far. */
5018 if (XSTRING (x_error_message_string
)->data
[0])
5019 error (format
, XSTRING (x_error_message_string
)->data
);
5022 /* Nonzero if we had any X protocol errors on DPY
5023 since we did x_catch_errors. */
5026 x_had_errors_p (dpy
)
5029 /* Make sure to catch any errors incurred so far. */
5032 return XSTRING (x_error_message_string
)->data
[0] != 0;
5035 /* Stop catching X protocol errors and let them make Emacs die.
5036 DPY should be the display that was passed to x_catch_errors.
5037 COUNT should be the value that was returned by
5038 the corresponding call to x_catch_errors. */
5041 x_uncatch_errors (dpy
, count
)
5045 unbind_to (count
, Qnil
);
5049 static unsigned int x_wire_count
;
5052 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
5057 /* Handle SIGPIPE, which can happen when the connection to a server
5058 simply goes away. SIGPIPE is handled by x_connection_signal.
5059 Don't need to do anything, because the write which caused the
5060 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
5061 which will do the appropriate cleanup for us. */
5064 x_connection_signal (signalnum
) /* If we don't have an argument, */
5065 int signalnum
; /* some compilers complain in signal calls. */
5068 /* USG systems forget handlers when they are used;
5069 must reestablish each time */
5070 signal (signalnum
, x_connection_signal
);
5074 /* Handling X errors. */
5076 /* Handle the loss of connection to display DISPLAY. */
5079 x_connection_closed (display
, error_message
)
5081 char *error_message
;
5083 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
5084 Lisp_Object frame
, tail
;
5086 /* Indicate that this display is dead. */
5088 #ifdef USE_X_TOOLKIT
5089 XtCloseDisplay (display
);
5092 dpyinfo
->display
= 0;
5094 /* First delete frames whose minibuffers are on frames
5095 that are on the dead display. */
5096 FOR_EACH_FRAME (tail
, frame
)
5098 Lisp_Object minibuf_frame
;
5100 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
5101 if (FRAME_X_P (XFRAME (frame
))
5102 && FRAME_X_P (XFRAME (minibuf_frame
))
5103 && ! EQ (frame
, minibuf_frame
)
5104 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
5105 Fdelete_frame (frame
, Qt
);
5108 /* Now delete all remaining frames on the dead display.
5109 We are now sure none of these is used as the minibuffer
5110 for another frame that we need to delete. */
5111 FOR_EACH_FRAME (tail
, frame
)
5112 if (FRAME_X_P (XFRAME (frame
))
5113 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
5115 /* Set this to t so that Fdelete_frame won't get confused
5116 trying to find a replacement. */
5117 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
5118 Fdelete_frame (frame
, Qt
);
5122 x_delete_display (dpyinfo
);
5124 if (x_display_list
== 0)
5126 fprintf (stderr
, "%s\n", error_message
);
5127 shut_down_emacs (0, 0, Qnil
);
5131 /* Ordinary stack unwind doesn't deal with these. */
5133 sigunblock (sigmask (SIGIO
));
5135 sigunblock (sigmask (SIGALRM
));
5136 TOTALLY_UNBLOCK_INPUT
;
5138 clear_waiting_for_input ();
5139 error ("%s", error_message
);
5142 /* This is the usual handler for X protocol errors.
5143 It kills all frames on the display that we got the error for.
5144 If that was the only one, it prints an error message and kills Emacs. */
5147 x_error_quitter (display
, error
)
5151 char buf
[256], buf1
[356];
5153 /* Note that there is no real way portable across R3/R4 to get the
5154 original error handler. */
5156 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
5157 sprintf (buf1
, "X protocol error: %s on protocol request %d",
5158 buf
, error
->request_code
);
5159 x_connection_closed (display
, buf1
);
5162 /* This is the first-level handler for X protocol errors.
5163 It calls x_error_quitter or x_error_catcher. */
5166 x_error_handler (display
, error
)
5170 char buf
[256], buf1
[356];
5172 if (! NILP (x_error_message_string
))
5173 x_error_catcher (display
, error
);
5175 x_error_quitter (display
, error
);
5178 /* This is the handler for X IO errors, always.
5179 It kills all frames on the display that we lost touch with.
5180 If that was the only one, it prints an error message and kills Emacs. */
5183 x_io_error_quitter (display
)
5188 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
5189 x_connection_closed (display
, buf
);
5192 /* Changing the font of the frame. */
5194 /* Give frame F the font named FONTNAME as its default font, and
5195 return the full name of that font. FONTNAME may be a wildcard
5196 pattern; in that case, we choose some font that fits the pattern.
5197 The return value shows which font we chose. */
5200 x_new_font (f
, fontname
)
5202 register char *fontname
;
5204 struct font_info
*fontp
5205 = fs_load_font (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
, fontname
, -1);
5210 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
5211 f
->output_data
.x
->font_baseline
5212 = (f
->output_data
.x
->font
->ascent
+ fontp
->baseline_offset
);
5213 f
->output_data
.x
->fontset
= -1;
5215 /* Compute the scroll bar width in character columns. */
5216 if (f
->scroll_bar_pixel_width
> 0)
5218 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
5219 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
5222 f
->scroll_bar_cols
= 2;
5224 /* Now make the frame display the given font. */
5225 if (FRAME_X_WINDOW (f
) != 0)
5227 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
5228 f
->output_data
.x
->font
->fid
);
5229 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
5230 f
->output_data
.x
->font
->fid
);
5231 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
5232 f
->output_data
.x
->font
->fid
);
5234 frame_update_line_height (f
);
5235 x_set_window_size (f
, 0, f
->width
, f
->height
);
5238 /* If we are setting a new frame's font for the first time,
5239 there are no faces yet, so this font's height is the line height. */
5240 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
5242 return build_string (fontp
->full_name
);
5245 /* Give frame F the fontset named FONTSETNAME as its default font, and
5246 return the full name of that fontset. FONTSETNAME may be a wildcard
5247 pattern; in that case, we choose some fontset that fits the pattern.
5248 The return value shows which fontset we chose. */
5251 x_new_fontset (f
, fontsetname
)
5255 int fontset
= fs_query_fontset (f
, fontsetname
);
5256 struct fontset_info
*fontsetp
;
5262 fontsetp
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
5264 if (!fontsetp
->fontname
[CHARSET_ASCII
])
5265 /* This fontset doesn't contain ASCII font. */
5268 result
= x_new_font (f
, fontsetp
->fontname
[CHARSET_ASCII
]);
5270 if (!STRINGP (result
))
5271 /* Can't load ASCII font. */
5274 /* Since x_new_font doesn't update any fontset information, do it now. */
5275 f
->output_data
.x
->fontset
= fontset
;
5276 fs_load_font (f
, FRAME_X_FONT_TABLE (f
),
5277 CHARSET_ASCII
, XSTRING (result
)->data
, fontset
);
5279 return build_string (fontsetname
);
5282 /* Calculate the absolute position in frame F
5283 from its current recorded position values and gravity. */
5285 x_calc_absolute_position (f
)
5289 int win_x
= 0, win_y
= 0;
5290 int flags
= f
->output_data
.x
->size_hint_flags
;
5293 #ifdef USE_X_TOOLKIT
5294 this_window
= XtWindow (f
->output_data
.x
->widget
);
5296 this_window
= FRAME_X_WINDOW (f
);
5299 /* Find the position of the outside upper-left corner of
5300 the inner window, with respect to the outer window. */
5301 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
5304 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
5306 /* From-window, to-window. */
5308 f
->output_data
.x
->parent_desc
,
5310 /* From-position, to-position. */
5311 0, 0, &win_x
, &win_y
,
5318 /* Treat negative positions as relative to the leftmost bottommost
5319 position that fits on the screen. */
5320 if (flags
& XNegative
)
5321 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
5322 - 2 * f
->output_data
.x
->border_width
- win_x
5324 + f
->output_data
.x
->left_pos
);
5326 if (flags
& YNegative
)
5327 /* We used to subtract f->output_data.x->menubar_height here
5328 in the toolkit case, but PIXEL_HEIGHT already includes that. */
5329 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
5330 - 2 * f
->output_data
.x
->border_width
- win_y
5332 + f
->output_data
.x
->top_pos
);
5334 /* The left_pos and top_pos
5335 are now relative to the top and left screen edges,
5336 so the flags should correspond. */
5337 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5340 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5341 to really change the position, and 0 when calling from
5342 x_make_frame_visible (in that case, XOFF and YOFF are the current
5343 position values). It is -1 when calling from x_set_frame_parameters,
5344 which means, do adjust for borders but don't change the gravity. */
5346 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5348 register int xoff
, yoff
;
5351 int modified_top
, modified_left
;
5353 if (change_gravity
> 0)
5355 f
->output_data
.x
->top_pos
= yoff
;
5356 f
->output_data
.x
->left_pos
= xoff
;
5357 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5359 f
->output_data
.x
->size_hint_flags
|= XNegative
;
5361 f
->output_data
.x
->size_hint_flags
|= YNegative
;
5362 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
5364 x_calc_absolute_position (f
);
5367 x_wm_set_size_hint (f
, (long) 0, 0);
5369 modified_left
= f
->output_data
.x
->left_pos
;
5370 modified_top
= f
->output_data
.x
->top_pos
;
5371 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
5372 this seems to be unnecessary and incorrect. rms, 4/17/97. */
5373 /* It is a mystery why we need to add the border_width here
5374 when the frame is already visible, but experiment says we do. */
5375 if (change_gravity
!= 0)
5377 modified_left
+= f
->output_data
.x
->border_width
;
5378 modified_top
+= f
->output_data
.x
->border_width
;
5382 #ifdef USE_X_TOOLKIT
5383 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
5384 modified_left
, modified_top
);
5385 #else /* not USE_X_TOOLKIT */
5386 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5387 modified_left
, modified_top
);
5388 #endif /* not USE_X_TOOLKIT */
5392 /* Call this to change the size of frame F's x-window.
5393 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5394 for this size change and subsequent size changes.
5395 Otherwise we leave the window gravity unchanged. */
5397 x_set_window_size (f
, change_gravity
, cols
, rows
)
5402 int pixelwidth
, pixelheight
;
5404 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5408 #ifdef USE_X_TOOLKIT
5410 /* The x and y position of the widget is clobbered by the
5411 call to XtSetValues within EmacsFrameSetCharSize.
5412 This is a real kludge, but I don't understand Xt so I can't
5413 figure out a correct fix. Can anyone else tell me? -- rms. */
5414 int xpos
= f
->output_data
.x
->widget
->core
.x
;
5415 int ypos
= f
->output_data
.x
->widget
->core
.y
;
5416 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
5417 f
->output_data
.x
->widget
->core
.x
= xpos
;
5418 f
->output_data
.x
->widget
->core
.y
= ypos
;
5421 #else /* not USE_X_TOOLKIT */
5423 check_frame_size (f
, &rows
, &cols
);
5424 f
->output_data
.x
->vertical_scroll_bar_extra
5425 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5427 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
5428 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
5429 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
5430 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
5431 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
5433 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
5434 x_wm_set_size_hint (f
, (long) 0, 0);
5436 XSync (FRAME_X_DISPLAY (f
), False
);
5437 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5438 pixelwidth
, pixelheight
);
5440 /* Now, strictly speaking, we can't be sure that this is accurate,
5441 but the window manager will get around to dealing with the size
5442 change request eventually, and we'll hear how it went when the
5443 ConfigureNotify event gets here.
5445 We could just not bother storing any of this information here,
5446 and let the ConfigureNotify event set everything up, but that
5447 might be kind of confusing to the lisp code, since size changes
5448 wouldn't be reported in the frame parameters until some random
5449 point in the future when the ConfigureNotify event arrives. */
5450 change_frame_size (f
, rows
, cols
, 0, 0);
5451 PIXEL_WIDTH (f
) = pixelwidth
;
5452 PIXEL_HEIGHT (f
) = pixelheight
;
5454 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5455 receive in the ConfigureNotify event; if we get what we asked
5456 for, then the event won't cause the screen to become garbaged, so
5457 we have to make sure to do it here. */
5458 SET_FRAME_GARBAGED (f
);
5460 XFlush (FRAME_X_DISPLAY (f
));
5462 #endif /* not USE_X_TOOLKIT */
5464 /* If cursor was outside the new size, mark it as off. */
5465 if (f
->phys_cursor_y
>= rows
5466 || f
->phys_cursor_x
>= cols
)
5468 f
->phys_cursor_x
= 0;
5469 f
->phys_cursor_y
= 0;
5470 f
->phys_cursor_on
= 0;
5473 /* Clear out any recollection of where the mouse highlighting was,
5474 since it might be in a place that's outside the new frame size.
5475 Actually checking whether it is outside is a pain in the neck,
5476 so don't try--just let the highlighting be done afresh with new size. */
5477 cancel_mouse_face (f
);
5482 /* Mouse warping. */
5485 x_set_mouse_position (f
, x
, y
)
5491 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
5492 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
5494 if (pix_x
< 0) pix_x
= 0;
5495 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
5497 if (pix_y
< 0) pix_y
= 0;
5498 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
5502 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5503 0, 0, 0, 0, pix_x
, pix_y
);
5507 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
5510 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5516 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5517 0, 0, 0, 0, pix_x
, pix_y
);
5521 /* focus shifting, raising and lowering. */
5523 x_focus_on_frame (f
)
5526 #if 0 /* This proves to be unpleasant. */
5530 /* I don't think that the ICCCM allows programs to do things like this
5531 without the interaction of the window manager. Whatever you end up
5532 doing with this code, do it to x_unfocus_frame too. */
5533 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5534 RevertToPointerRoot
, CurrentTime
);
5542 /* Look at the remarks in x_focus_on_frame. */
5543 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
5544 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
5545 RevertToPointerRoot
, CurrentTime
);
5549 /* Raise frame F. */
5554 if (f
->async_visible
)
5557 #ifdef USE_X_TOOLKIT
5558 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
5559 #else /* not USE_X_TOOLKIT */
5560 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5561 #endif /* not USE_X_TOOLKIT */
5562 XFlush (FRAME_X_DISPLAY (f
));
5567 /* Lower frame F. */
5572 if (f
->async_visible
)
5575 #ifdef USE_X_TOOLKIT
5576 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
5577 #else /* not USE_X_TOOLKIT */
5578 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5579 #endif /* not USE_X_TOOLKIT */
5580 XFlush (FRAME_X_DISPLAY (f
));
5586 XTframe_raise_lower (f
, raise_flag
)
5596 /* Change of visibility. */
5598 /* This tries to wait until the frame is really visible.
5599 However, if the window manager asks the user where to position
5600 the frame, this will return before the user finishes doing that.
5601 The frame will not actually be visible at that time,
5602 but it will become visible later when the window manager
5603 finishes with it. */
5605 x_make_frame_visible (f
)
5613 type
= x_icon_type (f
);
5615 x_bitmap_icon (f
, type
);
5617 if (! FRAME_VISIBLE_P (f
))
5619 /* We test FRAME_GARBAGED_P here to make sure we don't
5620 call x_set_offset a second time
5621 if we get to x_make_frame_visible a second time
5622 before the window gets really visible. */
5623 if (! FRAME_ICONIFIED_P (f
)
5624 && ! f
->output_data
.x
->asked_for_visible
)
5625 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
5627 f
->output_data
.x
->asked_for_visible
= 1;
5629 if (! EQ (Vx_no_window_manager
, Qt
))
5630 x_wm_set_window_state (f
, NormalState
);
5631 #ifdef USE_X_TOOLKIT
5632 /* This was XtPopup, but that did nothing for an iconified frame. */
5633 XtMapWidget (f
->output_data
.x
->widget
);
5634 #else /* not USE_X_TOOLKIT */
5635 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5636 #endif /* not USE_X_TOOLKIT */
5637 #if 0 /* This seems to bring back scroll bars in the wrong places
5638 if the window configuration has changed. They seem
5639 to come back ok without this. */
5640 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5641 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5645 XFlush (FRAME_X_DISPLAY (f
));
5647 /* Synchronize to ensure Emacs knows the frame is visible
5648 before we do anything else. We do this loop with input not blocked
5649 so that incoming events are handled. */
5652 int count
= input_signal_count
;
5654 /* This must come after we set COUNT. */
5657 XSETFRAME (frame
, f
);
5662 /* Once we have handled input events,
5663 we should have received the MapNotify if one is coming.
5664 So if we have not got it yet, stop looping.
5665 Some window managers make their own decisions
5666 about visibility. */
5667 if (input_signal_count
!= count
)
5669 /* Machines that do polling rather than SIGIO have been observed
5670 to go into a busy-wait here. So we'll fake an alarm signal
5671 to let the handler know that there's something to be read.
5672 We used to raise a real alarm, but it seems that the handler
5673 isn't always enabled here. This is probably a bug. */
5674 if (input_polling_used ())
5676 /* It could be confusing if a real alarm arrives while processing
5677 the fake one. Turn it off and let the handler reset it. */
5679 input_poll_signal ();
5681 /* Once we have handled input events,
5682 we should have received the MapNotify if one is coming.
5683 So if we have not got it yet, stop looping.
5684 Some window managers make their own decisions
5685 about visibility. */
5686 if (input_signal_count
!= count
)
5689 FRAME_SAMPLE_VISIBILITY (f
);
5693 /* Change from mapped state to withdrawn state. */
5695 /* Make the frame visible (mapped and not iconified). */
5697 x_make_frame_invisible (f
)
5703 #ifdef USE_X_TOOLKIT
5704 /* Use the frame's outermost window, not the one we normally draw on. */
5705 window
= XtWindow (f
->output_data
.x
->widget
);
5706 #else /* not USE_X_TOOLKIT */
5707 window
= FRAME_X_WINDOW (f
);
5708 #endif /* not USE_X_TOOLKIT */
5710 /* Don't keep the highlight on an invisible frame. */
5711 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5712 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5714 #if 0/* This might add unreliability; I don't trust it -- rms. */
5715 if (! f
->async_visible
&& ! f
->async_iconified
)
5721 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5722 that the current position of the window is user-specified, rather than
5723 program-specified, so that when the window is mapped again, it will be
5724 placed at the same location, without forcing the user to position it
5725 by hand again (they have already done that once for this window.) */
5726 x_wm_set_size_hint (f
, (long) 0, 1);
5730 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
5731 DefaultScreen (FRAME_X_DISPLAY (f
))))
5733 UNBLOCK_INPUT_RESIGNAL
;
5734 error ("Can't notify window manager of window withdrawal");
5736 #else /* ! defined (HAVE_X11R4) */
5738 /* Tell the window manager what we're going to do. */
5739 if (! EQ (Vx_no_window_manager
, Qt
))
5743 unmap
.xunmap
.type
= UnmapNotify
;
5744 unmap
.xunmap
.window
= window
;
5745 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
5746 unmap
.xunmap
.from_configure
= False
;
5747 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5748 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5750 SubstructureRedirectMask
|SubstructureNotifyMask
,
5753 UNBLOCK_INPUT_RESIGNAL
;
5754 error ("Can't notify window manager of withdrawal");
5758 /* Unmap the window ourselves. Cheeky! */
5759 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
5760 #endif /* ! defined (HAVE_X11R4) */
5762 /* We can't distinguish this from iconification
5763 just by the event that we get from the server.
5764 So we can't win using the usual strategy of letting
5765 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5766 and synchronize with the server to make sure we agree. */
5768 FRAME_ICONIFIED_P (f
) = 0;
5769 f
->async_visible
= 0;
5770 f
->async_iconified
= 0;
5777 /* Change window state from mapped to iconified. */
5786 /* Don't keep the highlight on an invisible frame. */
5787 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5788 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5790 if (f
->async_iconified
)
5795 FRAME_SAMPLE_VISIBILITY (f
);
5797 type
= x_icon_type (f
);
5799 x_bitmap_icon (f
, type
);
5801 #ifdef USE_X_TOOLKIT
5803 if (! FRAME_VISIBLE_P (f
))
5805 if (! EQ (Vx_no_window_manager
, Qt
))
5806 x_wm_set_window_state (f
, IconicState
);
5807 /* This was XtPopup, but that did nothing for an iconified frame. */
5808 XtMapWidget (f
->output_data
.x
->widget
);
5809 /* The server won't give us any event to indicate
5810 that an invisible frame was changed to an icon,
5811 so we have to record it here. */
5814 f
->async_iconified
= 1;
5815 f
->async_visible
= 0;
5820 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
5821 XtWindow (f
->output_data
.x
->widget
),
5822 DefaultScreen (FRAME_X_DISPLAY (f
)));
5826 error ("Can't notify window manager of iconification");
5828 f
->async_iconified
= 1;
5829 f
->async_visible
= 0;
5833 XFlush (FRAME_X_DISPLAY (f
));
5835 #else /* not USE_X_TOOLKIT */
5837 /* Make sure the X server knows where the window should be positioned,
5838 in case the user deiconifies with the window manager. */
5839 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
5840 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
5842 /* Since we don't know which revision of X we're running, we'll use both
5843 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
5845 /* X11R4: send a ClientMessage to the window manager using the
5846 WM_CHANGE_STATE type. */
5850 message
.xclient
.window
= FRAME_X_WINDOW (f
);
5851 message
.xclient
.type
= ClientMessage
;
5852 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
5853 message
.xclient
.format
= 32;
5854 message
.xclient
.data
.l
[0] = IconicState
;
5856 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5857 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5859 SubstructureRedirectMask
| SubstructureNotifyMask
,
5862 UNBLOCK_INPUT_RESIGNAL
;
5863 error ("Can't notify window manager of iconification");
5867 /* X11R3: set the initial_state field of the window manager hints to
5869 x_wm_set_window_state (f
, IconicState
);
5871 if (!FRAME_VISIBLE_P (f
))
5873 /* If the frame was withdrawn, before, we must map it. */
5874 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5877 f
->async_iconified
= 1;
5878 f
->async_visible
= 0;
5880 XFlush (FRAME_X_DISPLAY (f
));
5882 #endif /* not USE_X_TOOLKIT */
5885 /* Destroy the X window of frame F. */
5887 x_destroy_window (f
)
5890 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5894 /* If a display connection is dead, don't try sending more
5895 commands to the X server. */
5896 if (dpyinfo
->display
!= 0)
5898 if (f
->output_data
.x
->icon_desc
!= 0)
5899 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
5903 XDestroyIC (FRAME_XIC (f
));
5904 #if ! defined (SOLARIS2) || defined (HAVE_X11R6)
5905 /* This line causes crashes on Solaris with Openwin,
5906 due to an apparent bug in XCloseIM.
5907 X11R6 seems not to have the bug. */
5908 XCloseIM (FRAME_XIM (f
));
5912 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
5913 #ifdef USE_X_TOOLKIT
5914 XtDestroyWidget (f
->output_data
.x
->widget
);
5915 free_frame_menubar (f
);
5916 #endif /* USE_X_TOOLKIT */
5918 free_frame_faces (f
);
5919 XFlush (FRAME_X_DISPLAY (f
));
5922 if (f
->output_data
.x
->saved_menu_event
)
5923 free (f
->output_data
.x
->saved_menu_event
);
5925 xfree (f
->output_data
.x
);
5926 f
->output_data
.x
= 0;
5927 if (f
== dpyinfo
->x_focus_frame
)
5928 dpyinfo
->x_focus_frame
= 0;
5929 if (f
== dpyinfo
->x_focus_event_frame
)
5930 dpyinfo
->x_focus_event_frame
= 0;
5931 if (f
== dpyinfo
->x_highlight_frame
)
5932 dpyinfo
->x_highlight_frame
= 0;
5934 dpyinfo
->reference_count
--;
5936 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5938 dpyinfo
->mouse_face_beg_row
5939 = dpyinfo
->mouse_face_beg_col
= -1;
5940 dpyinfo
->mouse_face_end_row
5941 = dpyinfo
->mouse_face_end_col
= -1;
5942 dpyinfo
->mouse_face_window
= Qnil
;
5948 /* Setting window manager hints. */
5950 /* Set the normal size hints for the window manager, for frame F.
5951 FLAGS is the flags word to use--or 0 meaning preserve the flags
5952 that the window now has.
5953 If USER_POSITION is nonzero, we set the USPosition
5954 flag (this is useful when FLAGS is 0). */
5956 x_wm_set_size_hint (f
, flags
, user_position
)
5961 XSizeHints size_hints
;
5963 #ifdef USE_X_TOOLKIT
5966 Dimension widget_width
, widget_height
;
5967 Window window
= XtWindow (f
->output_data
.x
->widget
);
5968 #else /* not USE_X_TOOLKIT */
5969 Window window
= FRAME_X_WINDOW (f
);
5970 #endif /* not USE_X_TOOLKIT */
5972 /* Setting PMaxSize caused various problems. */
5973 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
5975 flexlines
= f
->height
;
5977 size_hints
.x
= f
->output_data
.x
->left_pos
;
5978 size_hints
.y
= f
->output_data
.x
->top_pos
;
5980 #ifdef USE_X_TOOLKIT
5981 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
5982 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
5983 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
5984 size_hints
.height
= widget_height
;
5985 size_hints
.width
= widget_width
;
5986 #else /* not USE_X_TOOLKIT */
5987 size_hints
.height
= PIXEL_HEIGHT (f
);
5988 size_hints
.width
= PIXEL_WIDTH (f
);
5989 #endif /* not USE_X_TOOLKIT */
5991 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
5992 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
5993 size_hints
.max_width
5994 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
5995 size_hints
.max_height
5996 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
5998 /* Calculate the base and minimum sizes.
6000 (When we use the X toolkit, we don't do it here.
6001 Instead we copy the values that the widgets are using, below.) */
6002 #ifndef USE_X_TOOLKIT
6004 int base_width
, base_height
;
6005 int min_rows
= 0, min_cols
= 0;
6007 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
6008 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
6010 check_frame_size (f
, &min_rows
, &min_cols
);
6012 /* The window manager uses the base width hints to calculate the
6013 current number of rows and columns in the frame while
6014 resizing; min_width and min_height aren't useful for this
6015 purpose, since they might not give the dimensions for a
6016 zero-row, zero-column frame.
6018 We use the base_width and base_height members if we have
6019 them; otherwise, we set the min_width and min_height members
6020 to the size for a zero x zero frame. */
6023 size_hints
.flags
|= PBaseSize
;
6024 size_hints
.base_width
= base_width
;
6025 size_hints
.base_height
= base_height
;
6026 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
6027 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
6029 size_hints
.min_width
= base_width
;
6030 size_hints
.min_height
= base_height
;
6034 /* If we don't need the old flags, we don't need the old hint at all. */
6037 size_hints
.flags
|= flags
;
6040 #endif /* not USE_X_TOOLKIT */
6043 XSizeHints hints
; /* Sometimes I hate X Windows... */
6044 long supplied_return
;
6048 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
6051 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
6054 #ifdef USE_X_TOOLKIT
6055 size_hints
.base_height
= hints
.base_height
;
6056 size_hints
.base_width
= hints
.base_width
;
6057 size_hints
.min_height
= hints
.min_height
;
6058 size_hints
.min_width
= hints
.min_width
;
6062 size_hints
.flags
|= flags
;
6067 if (hints
.flags
& PSize
)
6068 size_hints
.flags
|= PSize
;
6069 if (hints
.flags
& PPosition
)
6070 size_hints
.flags
|= PPosition
;
6071 if (hints
.flags
& USPosition
)
6072 size_hints
.flags
|= USPosition
;
6073 if (hints
.flags
& USSize
)
6074 size_hints
.flags
|= USSize
;
6081 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
6082 size_hints
.flags
|= PWinGravity
;
6086 size_hints
.flags
&= ~ PPosition
;
6087 size_hints
.flags
|= USPosition
;
6089 #endif /* PWinGravity */
6092 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
6094 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
6098 /* Used for IconicState or NormalState */
6099 x_wm_set_window_state (f
, state
)
6103 #ifdef USE_X_TOOLKIT
6106 XtSetArg (al
[0], XtNinitialState
, state
);
6107 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6108 #else /* not USE_X_TOOLKIT */
6109 Window window
= FRAME_X_WINDOW (f
);
6111 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
6112 f
->output_data
.x
->wm_hints
.initial_state
= state
;
6114 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6115 #endif /* not USE_X_TOOLKIT */
6118 x_wm_set_icon_pixmap (f
, pixmap_id
)
6124 #ifdef USE_X_TOOLKIT
6125 Window window
= XtWindow (f
->output_data
.x
->widget
);
6127 Window window
= FRAME_X_WINDOW (f
);
6132 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
6133 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
6137 /* It seems there is no way to turn off use of an icon pixmap.
6138 The following line does it, only if no icon has yet been created,
6139 for some window managers. But with mwm it crashes.
6140 Some people say it should clear the IconPixmapHint bit in this case,
6141 but that doesn't work, and the X consortium said it isn't the
6142 right thing at all. Since there is no way to win,
6143 best to explicitly give up. */
6145 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
6151 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
6155 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
6156 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6159 #else /* not USE_X_TOOLKIT */
6161 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
6162 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6164 #endif /* not USE_X_TOOLKIT */
6167 x_wm_set_icon_position (f
, icon_x
, icon_y
)
6171 #ifdef USE_X_TOOLKIT
6172 Window window
= XtWindow (f
->output_data
.x
->widget
);
6174 Window window
= FRAME_X_WINDOW (f
);
6177 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
6178 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
6179 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
6181 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6185 /* Interface to fontset handler. */
6187 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6189 x_get_font_info (f
, font_idx
)
6193 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
6197 /* Return a list of names of available fonts matching PATTERN on frame
6198 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6199 to be listed. Frame F NULL means we have not yet created any
6200 frame on X, and consult the first display in x_display_list.
6201 MAXNAMES sets a limit on how many fonts to match. */
6204 x_list_fonts (f
, pattern
, size
, maxnames
)
6206 Lisp_Object pattern
;
6210 Lisp_Object list
, patterns
= Qnil
, newlist
= Qnil
, key
, tem
, second_best
;
6211 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
6213 for (list
= Valternative_fontname_alist
; CONSP (list
);
6214 list
= XCONS (list
)->cdr
)
6216 tem
= XCONS (list
)->car
;
6218 && STRINGP (XCONS (tem
)->car
)
6219 && !NILP (Fstring_equal (XCONS (tem
)->car
, pattern
)))
6221 patterns
= XCONS (tem
)->cdr
;
6226 for (patterns
= Fcons (pattern
, patterns
); CONSP (patterns
);
6227 patterns
= XCONS (patterns
)->cdr
, pattern
= XCONS (patterns
)->car
)
6232 /* See if we cached the result for this particular query. */
6233 if (f
&& (tem
= XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
,
6234 key
= Fcons (pattern
, make_number (maxnames
)),
6235 !NILP (list
= Fassoc (key
, tem
))))
6237 list
= Fcdr_safe (list
);
6238 /* We have a cashed list. Don't have to get the list again. */
6242 /* At first, put PATTERN in the cache. */
6244 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, maxnames
, &num_fonts
);
6251 /* Make a list of all the fonts we got back.
6252 Store that in the font cache for the display. */
6253 for (i
= 0; i
< num_fonts
; i
++)
6256 int average_width
= -1, dashes
= 0, width
= 0;
6258 /* Count the number of dashes in NAMES[I]. If there are
6259 14 dashes, and the field value following 12th dash
6260 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
6261 is usually too ugly to be used for editing. Let's
6267 if (dashes
== 7) /* PIXEL_SIZE field */
6269 else if (dashes
== 12) /* AVERAGE_WIDTH field */
6270 average_width
= atoi (p
);
6272 if (dashes
< 14 || average_width
!= 0)
6274 tem
= build_string (names
[i
]);
6275 if (NILP (Fassoc (tem
, list
)))
6277 if (STRINGP (Vx_pixel_size_width_font_regexp
)
6278 && (fast_string_match_ignore_case
6279 (Vx_pixel_size_width_font_regexp
, names
[i
])
6281 /* We can set the value of PIXEL_SIZE to the
6282 width of this font. */
6283 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
6285 /* For the moment, width is not known. */
6286 list
= Fcons (Fcons (tem
, Qnil
), list
);
6290 XFreeFontNames (names
);
6293 /* Now store the result in the cache. */
6295 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
6296 = Fcons (Fcons (key
, list
),
6297 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
);
6300 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6302 newlist
= second_best
= Qnil
;
6303 /* Make a list of the fonts that have the right width. */
6304 for (; CONSP (list
); list
= XCONS (list
)->cdr
)
6306 tem
= XCONS (list
)->car
;
6308 if (!CONSP (tem
) || NILP (XCONS (tem
)->car
))
6312 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
6316 if (!INTEGERP (XCONS (tem
)->cdr
))
6318 /* Since we have not yet known the size of this font, we
6319 must try slow function call XLoadQueryFont. */
6320 XFontStruct
*thisinfo
;
6323 thisinfo
= XLoadQueryFont (dpy
,
6324 XSTRING (XCONS (tem
)->car
)->data
);
6329 XCONS (tem
)->cdr
= make_number (thisinfo
->max_bounds
.width
);
6330 XFreeFont (dpy
, thisinfo
);
6333 /* For unknown reason, the previous call of XListFont had
6334 retruned a font which can't be opened. Record the size
6335 as 0 not to try to open it again. */
6336 XCONS (tem
)->cdr
= make_number (0);
6338 if (XINT (XCONS (tem
)->cdr
) == size
)
6339 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
6340 else if (NILP (second_best
))
6342 else if (XINT (XCONS (tem
)->cdr
) < size
)
6344 if (XINT (XCONS (second_best
)->cdr
) > size
6345 || XINT (XCONS (second_best
)->cdr
) < XINT (XCONS (tem
)->cdr
))
6350 if (XINT (XCONS (second_best
)->cdr
) > size
6351 && XINT (XCONS (second_best
)->cdr
) > XINT (XCONS (tem
)->cdr
))
6355 if (!NILP (newlist
))
6357 else if (!NILP (second_best
))
6359 newlist
= Fcons (XCONS (second_best
)->car
, Qnil
);
6367 /* Load font named FONTNAME of the size SIZE for frame F, and return a
6368 pointer to the structure font_info while allocating it dynamically.
6369 If SIZE is 0, load any size of font.
6370 If loading is failed, return NULL. */
6373 x_load_font (f
, fontname
, size
)
6375 register char *fontname
;
6378 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6379 Lisp_Object font_names
;
6381 /* Get a list of all the fonts that match this name. Once we
6382 have a list of matching fonts, we compare them against the fonts
6383 we already have by comparing names. */
6384 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 256);
6386 if (!NILP (font_names
))
6391 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6392 for (tail
= font_names
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
6393 if (!strcmp (dpyinfo
->font_table
[i
].name
,
6394 XSTRING (XCONS (tail
)->car
)->data
)
6395 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
6396 XSTRING (XCONS (tail
)->car
)->data
))
6397 return (dpyinfo
->font_table
+ i
);
6400 /* Load the font and add it to the table. */
6404 struct font_info
*fontp
;
6405 unsigned long value
;
6407 if (!NILP (font_names
))
6408 fontname
= XSTRING (XCONS (font_names
)->car
)->data
;
6411 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
6416 /* Do we need to create the table? */
6417 if (dpyinfo
->font_table_size
== 0)
6419 dpyinfo
->font_table_size
= 16;
6421 = (struct font_info
*) xmalloc (dpyinfo
->font_table_size
6422 * sizeof (struct font_info
));
6424 /* Do we need to grow the table? */
6425 else if (dpyinfo
->n_fonts
6426 >= dpyinfo
->font_table_size
)
6428 dpyinfo
->font_table_size
*= 2;
6430 = (struct font_info
*) xrealloc (dpyinfo
->font_table
,
6431 (dpyinfo
->font_table_size
6432 * sizeof (struct font_info
)));
6435 fontp
= dpyinfo
->font_table
+ dpyinfo
->n_fonts
;
6437 /* Now fill in the slots of *FONTP. */
6440 fontp
->font_idx
= dpyinfo
->n_fonts
;
6441 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
6442 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
6444 /* Try to get the full name of FONT. Put it in FULL_NAME. */
6446 if (XGetFontProperty (font
, XA_FONT
, &value
))
6448 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
6452 /* Count the number of dashes in the "full name".
6453 If it is too few, this isn't really the font's full name,
6455 In X11R4, the fonts did not come with their canonical names
6466 full_name
= (char *) xmalloc (p
- name
+ 1);
6467 bcopy (name
, full_name
, p
- name
+ 1);
6474 fontp
->full_name
= full_name
;
6476 fontp
->full_name
= fontp
->name
;
6478 fontp
->size
= font
->max_bounds
.width
;
6479 fontp
->height
= font
->ascent
+ font
->descent
;
6481 /* The slot `encoding' specifies how to map a character
6482 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
6483 the font code-points (0x20..0x7F, 0xA0..0xFF, 0x2020..0x7F7F,
6484 0xA0A0..0xFFFF, 0x20A0..0x7FFF, or 0xA020..0xFF7F). For the
6485 moment, we don't know which charset uses this font. So, we set
6486 informatoin in fontp->encoding[1] which is never used by any
6487 charset. If mapping can't be decided, set -1. */
6489 = (font
->max_byte1
== 0
6491 ? (font
->min_char_or_byte2
< 0x80
6492 ? (font
->max_char_or_byte2
< 0x80
6493 ? 0 /* 0x20..0x7F */
6494 : -1) /* 0x20..0xFF (can't decide) */
6495 : 1) /* 0xA0..0xFF */
6497 : (font
->min_byte1
< 0x80
6498 ? (font
->max_byte1
< 0x80
6499 ? (font
->min_char_or_byte2
< 0x80
6500 ? (font
->max_char_or_byte2
< 0x80
6501 ? 0 /* 0x2020..0x7F7F */
6502 : -1) /* 0x2020..0x7FFF (can't decide) */
6503 : 3) /* 0x20A0..0x7FFF */
6504 : -1) /* 0x20??..0xA0?? (can't decide) */
6505 : (font
->min_char_or_byte2
< 0x80
6506 ? (font
->max_char_or_byte2
< 0x80
6507 ? 2 /* 0xA020..0xFF7F */
6508 : -1) /* 0xA020..0xFFFF (can't decide) */
6509 : 1))); /* 0xA0A0..0xFFFF */
6511 fontp
->baseline_offset
6512 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
6513 ? (long) value
: 0);
6514 fontp
->relative_compose
6515 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
6516 ? (long) value
: 0);
6517 fontp
->default_ascent
6518 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
6519 ? (long) value
: 0);
6528 /* Return a pointer to struct font_info of a font named FONTNAME for frame F.
6529 If no such font is loaded, return NULL. */
6531 x_query_font (f
, fontname
)
6533 register char *fontname
;
6535 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6538 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6539 if (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
6540 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
))
6541 return (dpyinfo
->font_table
+ i
);
6546 /* Initialization. */
6548 #ifdef USE_X_TOOLKIT
6549 static XrmOptionDescRec emacs_options
[] = {
6550 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
6551 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
6553 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
6554 XrmoptionSepArg
, NULL
},
6555 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
6557 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6558 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6559 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6560 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
6561 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
6562 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
6563 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
6565 #endif /* USE_X_TOOLKIT */
6567 static int x_initialized
;
6570 /* Test whether two display-name strings agree up to the dot that separates
6571 the screen number from the server number. */
6573 same_x_server (name1
, name2
)
6574 char *name1
, *name2
;
6577 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
6581 if (seen_colon
&& *name1
== '.')
6585 && (*name1
== '.' || *name1
== '\0')
6586 && (*name2
== '.' || *name2
== '\0'));
6590 struct x_display_info
*
6591 x_term_init (display_name
, xrm_option
, resource_name
)
6592 Lisp_Object display_name
;
6594 char *resource_name
;
6600 struct x_display_info
*dpyinfo
;
6612 setlocale (LC_ALL
, "");
6613 /* In case we just overrode what init_lread did, redo it. */
6614 setlocale (LC_NUMERIC
, "C");
6615 setlocale (LC_TIME
, "C");
6618 #ifdef USE_X_TOOLKIT
6619 /* weiner@footloose.sps.mot.com reports that this causes
6621 X protocol error: BadAtom (invalid Atom parameter)
6622 on protocol request 18skiloaf.
6623 So let's not use it until R6. */
6625 XtSetLanguageProc (NULL
, NULL
, NULL
);
6636 argv
[argc
++] = "-xrm";
6637 argv
[argc
++] = xrm_option
;
6639 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
6640 resource_name
, EMACS_CLASS
,
6641 emacs_options
, XtNumber (emacs_options
),
6645 /* I think this is to compensate for XtSetLanguageProc. */
6646 setlocale (LC_NUMERIC
, "C");
6647 setlocale (LC_TIME
, "C");
6651 #else /* not USE_X_TOOLKIT */
6653 XSetLocaleModifiers ("");
6655 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
6656 #endif /* not USE_X_TOOLKIT */
6658 /* Detect failure. */
6665 /* We have definitely succeeded. Record the new connection. */
6667 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
6671 struct x_display_info
*share
;
6674 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
6675 share
= share
->next
, tail
= XCONS (tail
)->cdr
)
6676 if (same_x_server (XSTRING (XCONS (XCONS (tail
)->car
)->car
)->data
,
6677 XSTRING (display_name
)->data
))
6680 dpyinfo
->kboard
= share
->kboard
;
6683 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
6684 init_kboard (dpyinfo
->kboard
);
6685 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
6687 char *vendor
= ServerVendor (dpy
);
6688 dpyinfo
->kboard
->Vsystem_key_alist
6689 = call1 (Qvendor_specific_keysyms
,
6690 build_string (vendor
? vendor
: ""));
6693 dpyinfo
->kboard
->next_kboard
= all_kboards
;
6694 all_kboards
= dpyinfo
->kboard
;
6695 /* Don't let the initial kboard remain current longer than necessary.
6696 That would cause problems if a file loaded on startup tries to
6697 prompt in the minibuffer. */
6698 if (current_kboard
== initial_kboard
)
6699 current_kboard
= dpyinfo
->kboard
;
6701 dpyinfo
->kboard
->reference_count
++;
6705 /* Put this display on the chain. */
6706 dpyinfo
->next
= x_display_list
;
6707 x_display_list
= dpyinfo
;
6709 /* Put it on x_display_name_list as well, to keep them parallel. */
6710 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
6711 x_display_name_list
);
6712 dpyinfo
->name_list_element
= XCONS (x_display_name_list
)->car
;
6714 dpyinfo
->display
= dpy
;
6717 XSetAfterFunction (x_current_display
, x_trace_wire
);
6721 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
6722 + XSTRING (Vsystem_name
)->size
6724 sprintf (dpyinfo
->x_id_name
, "%s@%s",
6725 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
6727 /* Figure out which modifier bits mean what. */
6728 x_find_modifier_meanings (dpyinfo
);
6730 /* Get the scroll bar cursor. */
6731 dpyinfo
->vertical_scroll_bar_cursor
6732 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
6734 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
6735 resource_name
, EMACS_CLASS
);
6736 #ifdef HAVE_XRMSETDATABASE
6737 XrmSetDatabase (dpyinfo
->display
, xrdb
);
6739 dpyinfo
->display
->db
= xrdb
;
6741 /* Put the rdb where we can find it in a way that works on
6743 dpyinfo
->xrdb
= xrdb
;
6745 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
6746 DefaultScreen (dpyinfo
->display
));
6747 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
6748 &dpyinfo
->n_planes
);
6749 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
6750 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
6751 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
6752 dpyinfo
->grabbed
= 0;
6753 dpyinfo
->reference_count
= 0;
6754 dpyinfo
->icon_bitmap_id
= -1;
6755 dpyinfo
->n_fonts
= 0;
6756 dpyinfo
->font_table_size
= 0;
6757 dpyinfo
->bitmaps
= 0;
6758 dpyinfo
->bitmaps_size
= 0;
6759 dpyinfo
->bitmaps_last
= 0;
6760 dpyinfo
->scratch_cursor_gc
= 0;
6761 dpyinfo
->mouse_face_mouse_frame
= 0;
6762 dpyinfo
->mouse_face_deferred_gc
= 0;
6763 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6764 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6765 dpyinfo
->mouse_face_face_id
= 0;
6766 dpyinfo
->mouse_face_window
= Qnil
;
6767 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
6768 dpyinfo
->mouse_face_defer
= 0;
6769 dpyinfo
->x_focus_frame
= 0;
6770 dpyinfo
->x_focus_event_frame
= 0;
6771 dpyinfo
->x_highlight_frame
= 0;
6773 dpyinfo
->Xatom_wm_protocols
6774 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
6775 dpyinfo
->Xatom_wm_take_focus
6776 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
6777 dpyinfo
->Xatom_wm_save_yourself
6778 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
6779 dpyinfo
->Xatom_wm_delete_window
6780 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
6781 dpyinfo
->Xatom_wm_change_state
6782 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
6783 dpyinfo
->Xatom_wm_configure_denied
6784 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
6785 dpyinfo
->Xatom_wm_window_moved
6786 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
6787 dpyinfo
->Xatom_editres
6788 = XInternAtom (dpyinfo
->display
, "Editres", False
);
6789 dpyinfo
->Xatom_CLIPBOARD
6790 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
6791 dpyinfo
->Xatom_TIMESTAMP
6792 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
6794 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
6795 dpyinfo
->Xatom_COMPOUND_TEXT
6796 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
6797 dpyinfo
->Xatom_DELETE
6798 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
6799 dpyinfo
->Xatom_MULTIPLE
6800 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
6802 = XInternAtom (dpyinfo
->display
, "INCR", False
);
6803 dpyinfo
->Xatom_EMACS_TMP
6804 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
6805 dpyinfo
->Xatom_TARGETS
6806 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
6808 = XInternAtom (dpyinfo
->display
, "NULL", False
);
6809 dpyinfo
->Xatom_ATOM_PAIR
6810 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
6811 /* For properties of font. */
6812 dpyinfo
->Xatom_PIXEL_SIZE
6813 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
6814 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
6815 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
6816 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
6817 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
6818 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
6819 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
6821 dpyinfo
->cut_buffers_initialized
= 0;
6823 connection
= ConnectionNumber (dpyinfo
->display
);
6824 dpyinfo
->connection
= connection
;
6827 char null_bits
[] = { 0x00 };
6830 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
6831 null_bits
, 1, 1, (long) 0, (long) 0,
6836 /* This is only needed for distinguishing keyboard and process input. */
6837 if (connection
!= 0)
6838 add_keyboard_wait_descriptor (connection
);
6841 #ifndef F_SETOWN_BUG
6843 #ifdef F_SETOWN_SOCK_NEG
6844 /* stdin is a socket here */
6845 fcntl (connection
, F_SETOWN
, -getpid ());
6846 #else /* ! defined (F_SETOWN_SOCK_NEG) */
6847 fcntl (connection
, F_SETOWN
, getpid ());
6848 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
6849 #endif /* ! defined (F_SETOWN) */
6850 #endif /* F_SETOWN_BUG */
6853 if (interrupt_input
)
6854 init_sigio (connection
);
6855 #endif /* ! defined (SIGIO) */
6858 /* Make sure that we have a valid font for dialog boxes
6859 so that Xt does not crash. */
6861 Display
*dpy
= dpyinfo
->display
;
6866 d
.addr
= (XPointer
)&dpy
;
6867 d
.size
= sizeof (Display
*);
6868 fr
.addr
= XtDefaultFont
;
6869 fr
.size
= sizeof (XtDefaultFont
);
6870 to
.size
= sizeof (Font
*);
6871 to
.addr
= (XPointer
)&font
;
6872 count
= x_catch_errors (dpy
);
6873 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
6875 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
6876 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
6877 x_uncatch_errors (dpy
, count
);
6887 /* Get rid of display DPYINFO, assuming all frames are already gone,
6888 and without sending any more commands to the X server. */
6891 x_delete_display (dpyinfo
)
6892 struct x_display_info
*dpyinfo
;
6894 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
6896 /* Discard this display from x_display_name_list and x_display_list.
6897 We can't use Fdelq because that can quit. */
6898 if (! NILP (x_display_name_list
)
6899 && EQ (XCONS (x_display_name_list
)->car
, dpyinfo
->name_list_element
))
6900 x_display_name_list
= XCONS (x_display_name_list
)->cdr
;
6905 tail
= x_display_name_list
;
6906 while (CONSP (tail
) && CONSP (XCONS (tail
)->cdr
))
6908 if (EQ (XCONS (XCONS (tail
)->cdr
)->car
,
6909 dpyinfo
->name_list_element
))
6911 XCONS (tail
)->cdr
= XCONS (XCONS (tail
)->cdr
)->cdr
;
6914 tail
= XCONS (tail
)->cdr
;
6918 if (x_display_list
== dpyinfo
)
6919 x_display_list
= dpyinfo
->next
;
6922 struct x_display_info
*tail
;
6924 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
6925 if (tail
->next
== dpyinfo
)
6926 tail
->next
= tail
->next
->next
;
6929 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
6930 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
6931 XrmDestroyDatabase (dpyinfo
->xrdb
);
6935 if (--dpyinfo
->kboard
->reference_count
== 0)
6936 delete_kboard (dpyinfo
->kboard
);
6938 xfree (dpyinfo
->font_table
);
6939 xfree (dpyinfo
->x_id_name
);
6943 /* Set up use of X before we make the first connection. */
6947 clear_frame_hook
= XTclear_frame
;
6948 clear_end_of_line_hook
= XTclear_end_of_line
;
6949 ins_del_lines_hook
= XTins_del_lines
;
6950 change_line_highlight_hook
= XTchange_line_highlight
;
6951 insert_glyphs_hook
= XTinsert_glyphs
;
6952 write_glyphs_hook
= XTwrite_glyphs
;
6953 delete_glyphs_hook
= XTdelete_glyphs
;
6954 ring_bell_hook
= XTring_bell
;
6955 reset_terminal_modes_hook
= XTreset_terminal_modes
;
6956 set_terminal_modes_hook
= XTset_terminal_modes
;
6957 update_begin_hook
= XTupdate_begin
;
6958 update_end_hook
= XTupdate_end
;
6959 set_terminal_window_hook
= XTset_terminal_window
;
6960 read_socket_hook
= XTread_socket
;
6961 frame_up_to_date_hook
= XTframe_up_to_date
;
6962 cursor_to_hook
= XTcursor_to
;
6963 reassert_line_highlight_hook
= XTreassert_line_highlight
;
6964 mouse_position_hook
= XTmouse_position
;
6965 frame_rehighlight_hook
= XTframe_rehighlight
;
6966 frame_raise_lower_hook
= XTframe_raise_lower
;
6967 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
6968 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
6969 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
6970 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
6972 scroll_region_ok
= 1; /* we'll scroll partial frames */
6973 char_ins_del_ok
= 0; /* just as fast to write the line */
6974 line_ins_del_ok
= 1; /* we'll just blt 'em */
6975 fast_clear_end_of_line
= 1; /* X does this well */
6976 memory_below_frame
= 0; /* we don't remember what scrolls
6982 /* Try to use interrupt input; if we can't, then start polling. */
6983 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
6985 #ifdef USE_X_TOOLKIT
6986 XtToolkitInitialize ();
6987 Xt_app_con
= XtCreateApplicationContext ();
6988 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
6991 /* Note that there is no real way portable across R3/R4 to get the
6992 original error handler. */
6993 XSetErrorHandler (x_error_handler
);
6994 XSetIOErrorHandler (x_io_error_quitter
);
6996 /* Disable Window Change signals; they are handled by X events. */
6998 signal (SIGWINCH
, SIG_DFL
);
6999 #endif /* ! defined (SIGWINCH) */
7001 signal (SIGPIPE
, x_connection_signal
);
7007 staticpro (&x_error_message_string
);
7008 x_error_message_string
= Qnil
;
7010 staticpro (&x_display_name_list
);
7011 x_display_name_list
= Qnil
;
7013 staticpro (&last_mouse_scroll_bar
);
7014 last_mouse_scroll_bar
= Qnil
;
7016 staticpro (&Qvendor_specific_keysyms
);
7017 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
7019 staticpro (&last_mouse_press_frame
);
7020 last_mouse_press_frame
= Qnil
;
7023 #endif /* not HAVE_X_WINDOWS */