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
++)
751 if (charset
== CHARSET_ASCII
|| charset
== charset_latin_iso8859_1
)
753 font
= FACE_FONT (face
);
754 if (font
== (XFontStruct
*) FACE_DEFAULT
)
755 font
= f
->output_data
.x
->font
;
756 baseline
= FONT_BASE (font
);
757 if (charset
== charset_latin_iso8859_1
)
759 if (font
->max_char_or_byte2
< 0x80)
760 /* This font can't display Latin1 characters. */
764 for (cp
= buf
; cp
< buf
+ len
; cp
++)
772 /* Now override that if the cursor's on this character. */
775 /* The cursor overrides stippling. */
778 if (font
== f
->output_data
.x
->font
779 && face
->background
== f
->output_data
.x
->background_pixel
780 && face
->foreground
== f
->output_data
.x
->foreground_pixel
783 gc
= f
->output_data
.x
->cursor_gc
;
785 /* Cursor on non-default face: must merge. */
791 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
792 xgcv
.foreground
= face
->background
;
793 /* If the glyph would be invisible,
794 try a different foreground. */
795 if (xgcv
.foreground
== xgcv
.background
)
796 xgcv
.foreground
= face
->foreground
;
797 if (xgcv
.foreground
== xgcv
.background
)
798 xgcv
.foreground
= f
->output_data
.x
->cursor_foreground_pixel
;
799 if (xgcv
.foreground
== xgcv
.background
)
800 xgcv
.foreground
= face
->foreground
;
801 /* Make sure the cursor is distinct from text in this face. */
802 if (xgcv
.background
== face
->background
803 && xgcv
.foreground
== face
->foreground
)
805 xgcv
.background
= face
->foreground
;
806 xgcv
.foreground
= face
->background
;
809 xgcv
.font
= font
->fid
;
811 xgcv
.font
= FACE_FONT (face
)->fid
;
812 xgcv
.graphics_exposures
= 0;
813 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
814 if (FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
)
815 XChangeGC (FRAME_X_DISPLAY (f
),
816 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
,
819 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
820 = XCreateGC (FRAME_X_DISPLAY (f
), window
, mask
, &xgcv
);
821 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
823 /* If this code is restored, it must also reset to the default stipple
825 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
826 XSetStipple (FRAME_X_DISPLAY (f
), gc
, face
->stipple
);
832 require_clipping
= (!NILP (Vclip_large_size_font
)
833 && (font
->ascent
> baseline
834 || font
->descent
> line_height
- baseline
836 && FONT_WIDTH (font
) > glyph_width
)));
838 if (font
&& (just_foreground
|| (cmpcharp
&& gidx
> 0)))
839 background_filled
= 1;
842 /* Turn stipple on. */
843 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillOpaqueStippled
);
845 /* Draw stipple or background color on background. */
846 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
847 left
, top
, run_width
, line_height
);
849 /* Turn stipple off. */
850 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillSolid
);
852 background_filled
= 1;
855 || FONT_HEIGHT (font
) < line_height
856 || FONT_WIDTH (font
) < glyph_width
859 /* Fill a area for the current run in background pixle of GC. */
861 unsigned long mask
= GCForeground
| GCBackground
;
862 unsigned long fore
, back
;
864 /* The current code at first set foreground to background,
865 fill the area, then recover the original foreground.
866 Aren't there any more smart ways? */
868 XGetGCValues (FRAME_X_DISPLAY (f
), gc
, mask
, &xgcv
);
869 XSetForeground (FRAME_X_DISPLAY (f
), gc
, xgcv
.background
);
870 XFillRectangle (FRAME_X_DISPLAY (f
), window
, gc
,
871 left
, top
, run_width
, line_height
);
872 XSetForeground (FRAME_X_DISPLAY (f
), gc
, xgcv
.foreground
);
874 background_filled
= 1;
876 /* To assure not to fill background while drawing
877 remaining components. */
881 background_filled
= 0;
885 if (require_clipping
)
887 Region region
; /* Region used for setting clip mask to GC. */
888 XPoint x
[4]; /* Data used for creating REGION. */
890 x
[0].x
= x
[3].x
= left
, x
[1].x
= x
[2].x
= left
+ glyph_width
;
891 x
[0].y
= x
[1].y
= top
, x
[2].y
= x
[3].y
= top
+ line_height
;
892 region
= XPolygonRegion (x
, 4, EvenOddRule
);
893 XSetRegion (FRAME_X_DISPLAY (f
), gc
, region
);
894 XDestroyRegion (region
);
899 if (require_clipping
|| FONT_WIDTH (font
) != glyph_width
)
900 for (i
= 0; i
< len
; i
++)
902 if (require_clipping
&& i
> 0)
903 XSetClipOrigin (FRAME_X_DISPLAY (f
), gc
,
905 if (background_filled
)
906 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
907 left
+ glyph_width
* i
,
908 top
+ baseline
, buf
+ i
, 1);
910 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, gc
,
911 left
+ glyph_width
* i
,
912 top
+ baseline
, buf
+ i
, 1);
916 if (background_filled
)
917 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
918 left
, top
+ baseline
, buf
, len
);
920 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, gc
,
921 left
, top
+ baseline
, buf
, len
);
926 XCharStruct
*pcm
; /* Pointer to per char metric info. */
928 if ((cmpcharp
->cmp_rule
|| relative_compose
)
931 /* This is the first character. Initialize variables.
932 HIGHEST is the highest position of glyphs ever
933 written, LOWEST the lowest position. */
937 && CHAR_TABLE_P (Vuse_default_ascent
)
938 && !NILP (Faref (Vuse_default_ascent
, first_ch
)))
940 highest
= default_ascent
;
945 pcm
= PER_CHAR_METRIC (font
, buf
);
946 highest
= pcm
->ascent
+ 1;
947 lowest
= - pcm
->descent
;
950 if (cmpcharp
->cmp_rule
)
951 x_offset
= (cmpcharp
->col_offset
[0]
952 * FONT_WIDTH (f
->output_data
.x
->font
));
953 /* Draw the first character at the normal position. */
954 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
955 left
+ x_offset
, top
+ baseline
, buf
, 1);
962 for (; i
< len
; i
++, gidx
++)
964 int x_offset
= 0, y_offset
= 0;
966 if (relative_compose
)
968 pcm
= PER_CHAR_METRIC (font
, buf
+ i
);
969 if (- pcm
->descent
>= relative_compose
)
971 /* Draw above the current glyphs. */
972 y_offset
= highest
+ pcm
->descent
;
973 highest
+= pcm
->ascent
+ pcm
->descent
;
975 else if (pcm
->ascent
<= 0)
977 /* Draw beneath the current glyphs. */
978 y_offset
= lowest
- pcm
->ascent
;
979 lowest
-= pcm
->ascent
+ pcm
->descent
;
982 else if (cmpcharp
->cmp_rule
)
984 int gref
= (cmpcharp
->cmp_rule
[gidx
] - 0xA0) / 9;
985 int nref
= (cmpcharp
->cmp_rule
[gidx
] - 0xA0) % 9;
988 /* Re-encode GREF and NREF so that they specify
989 only Y-axis information:
990 0:top, 1:base, 2:bottom, 3:center */
991 gref
= gref
/ 3 + (gref
== 4) * 2;
992 nref
= nref
/ 3 + (nref
== 4) * 2;
994 pcm
= PER_CHAR_METRIC (font
, buf
+ i
);
995 bottom
= ((gref
== 0 ? highest
: gref
== 1 ? 0
997 : (highest
+ lowest
) / 2)
998 - (nref
== 0 ? pcm
->ascent
+ pcm
->descent
999 : nref
== 1 ? pcm
->descent
: nref
== 2 ? 0
1000 : (pcm
->ascent
+ pcm
->descent
) / 2));
1001 top
= bottom
+ (pcm
->ascent
+ pcm
->descent
);
1004 if (bottom
< lowest
)
1006 y_offset
= bottom
+ pcm
->descent
;
1007 x_offset
= (cmpcharp
->col_offset
[gidx
]
1008 * FONT_WIDTH (f
->output_data
.x
->font
));
1010 XDrawString16 (FRAME_X_DISPLAY (f
), window
, gc
,
1011 left
+ x_offset
, top
+ baseline
- y_offset
,
1015 if (require_clipping
)
1016 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
1018 #if 0 /* Doesn't work, because it uses FRAME_CURRENT_GLYPHS,
1019 which often is not up to date yet. */
1020 if (!just_foreground
)
1022 if (left
== orig_left
)
1023 redraw_previous_char (f
, PIXEL_TO_CHAR_COL (f
, left
),
1024 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
1026 redraw_following_char (f
, PIXEL_TO_CHAR_COL (f
, left
+ len
* FONT_WIDTH (font
)),
1027 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
1031 if (!font
|| require_clipping
&& !NILP (Vhighlight_wrong_size_font
))
1033 /* Show rectangles to show that we found no font or a font
1034 of inappropriate size. */
1038 (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1039 left
, top
, run_width
- 1, line_height
- 1);
1041 for (i
= 0; i
< len
; i
++)
1042 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1043 left
+ glyph_width
* i
, top
,
1044 glyph_width
-1, line_height
- 1);
1047 /* We should probably check for XA_UNDERLINE_POSITION and
1048 XA_UNDERLINE_THICKNESS properties on the font, but let's
1049 just get the thing working, and come back to that. */
1051 /* Setting underline position based on the metric of the
1052 current font results in shaky underline if it strides
1053 over different fonts. So, we set the position based only
1054 on the default font of this frame. */
1055 int underline_position
= f
->output_data
.x
->font_baseline
+ 1;
1057 if (underline_position
>= line_height
)
1058 underline_position
= line_height
- 1;
1060 if (face
->underline
)
1061 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1063 left
, top
+ underline_position
, run_width
, 1);
1071 return (left
- orig_left
);
1076 /* This is the old single-face code. */
1079 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
1082 register GLYPH
*gp
; /* Points to first GLYPH. */
1083 register int n
; /* Number of glyphs to display. */
1088 Window window
= FRAME_X_WINDOW (f
);
1089 GC drawing_gc
= (hl
== 2 ? f
->output_data
.x
->cursor_gc
1090 : (hl
? f
->output_data
.x
->reverse_gc
1091 : f
->output_data
.x
->normal_gc
));
1093 if (sizeof (GLYPH
) == sizeof (XChar2b
))
1094 XDrawImageString16 (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
1095 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
1096 else if (sizeof (GLYPH
) == sizeof (unsigned char))
1097 XDrawImageString (FRAME_X_DISPLAY (f
), window
, drawing_gc
,
1098 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
1100 /* What size of glyph ARE you using? And does X have a function to
1106 /* Output some text at the nominal frame cursor position.
1107 Advance the cursor over the text.
1108 Output LEN glyphs at START.
1110 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
1111 controls the pixel values used for foreground and background. */
1114 XTwrite_glyphs (start
, len
)
1115 register GLYPH
*start
;
1118 register int temp_length
;
1129 /* If not within an update,
1130 output at the frame's visible cursor. */
1131 curs_x
= f
->cursor_x
;
1132 curs_y
= f
->cursor_y
;
1136 CHAR_TO_PIXEL_COL (f
, curs_x
),
1137 CHAR_TO_PIXEL_ROW (f
, curs_y
),
1138 start
, len
, highlight
, 0, NULL
);
1140 /* If we drew on top of the cursor, note that it is turned off. */
1141 if (curs_y
== f
->phys_cursor_y
1142 && curs_x
<= f
->phys_cursor_x
1143 && curs_x
+ len
> f
->phys_cursor_x
)
1144 f
->phys_cursor_on
= 0;
1146 if (updating_frame
== 0)
1147 x_display_cursor (f
, 1, FRAME_CURSOR_X (f
) + len
, FRAME_CURSOR_Y (f
));
1154 /* Clear to the end of the line.
1155 Erase the current text line from the nominal cursor position (inclusive)
1156 to column FIRST_UNUSED (exclusive). The idea is that everything
1157 from FIRST_UNUSED onward is already erased. */
1160 XTclear_end_of_line (first_unused
)
1161 register int first_unused
;
1163 struct frame
*f
= updating_frame
;
1169 if (curs_y
< 0 || curs_y
>= f
->height
)
1171 if (first_unused
<= 0)
1174 if (first_unused
>= FRAME_WINDOW_WIDTH (f
))
1175 first_unused
= FRAME_WINDOW_WIDTH (f
);
1177 first_unused
+= FRAME_LEFT_SCROLL_BAR_WIDTH (f
);
1183 /* Notice if the cursor will be cleared by this operation. */
1184 if (curs_y
== f
->phys_cursor_y
1185 && curs_x
<= f
->phys_cursor_x
1186 && f
->phys_cursor_x
< first_unused
)
1187 f
->phys_cursor_on
= 0;
1189 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1190 CHAR_TO_PIXEL_COL (f
, curs_x
),
1191 CHAR_TO_PIXEL_ROW (f
, curs_y
),
1192 FONT_WIDTH (f
->output_data
.x
->font
) * (first_unused
- curs_x
),
1193 f
->output_data
.x
->line_height
, False
);
1195 redraw_previous_char (f
, curs_x
, curs_y
, highlight
);
1205 struct frame
*f
= updating_frame
;
1210 f
->phys_cursor_on
= 0; /* Cursor not visible. */
1211 curs_x
= 0; /* Nominal cursor position is top left. */
1216 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
1218 /* We have to clear the scroll bars, too. If we have changed
1219 colors or something like that, then they should be notified. */
1220 x_scroll_bar_clear (f
);
1222 XFlush (FRAME_X_DISPLAY (f
));
1227 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
1228 always contain the right glyphs to use.
1230 It also needs to be changed to look at the details of the font and
1231 see whether there is really overlap, and do nothing when there is
1232 not. This can use font_char_overlap_left and font_char_overlap_right,
1233 but just how to use them is not clear. */
1235 /* Erase the character (if any) at the position just before X, Y in frame F,
1236 then redraw it and the character before it.
1237 This is necessary when we erase starting at X,
1238 in case the character after X overlaps into the one before X.
1239 Call this function with input blocked. */
1242 redraw_previous_char (f
, x
, y
, highlight_flag
)
1247 /* Erase the character before the new ones, in case
1248 what was here before overlaps it.
1249 Reoutput that character, and the previous character
1250 (in case the previous character overlaps it). */
1253 int start_x
= x
- 2;
1256 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1257 CHAR_TO_PIXEL_COL (f
, x
- 1),
1258 CHAR_TO_PIXEL_ROW (f
, y
),
1259 FONT_WIDTH (f
->output_data
.x
->font
),
1260 f
->output_data
.x
->line_height
, False
);
1262 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
1263 CHAR_TO_PIXEL_ROW (f
, y
),
1264 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
1265 x
- start_x
, highlight_flag
, 1, NULL
);
1269 /* Erase the character (if any) at the position X, Y in frame F,
1270 then redraw it and the character after it.
1271 This is necessary when we erase endng at X,
1272 in case the character after X overlaps into the one before X.
1273 Call this function with input blocked. */
1276 redraw_following_char (f
, x
, y
, highlight_flag
)
1281 int limit
= FRAME_CURRENT_GLYPHS (f
)->used
[y
];
1282 /* Erase the character after the new ones, in case
1283 what was here before overlaps it.
1284 Reoutput that character, and the following character
1285 (in case the following character overlaps it). */
1287 && FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
] != SPACEGLYPH
)
1292 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1293 CHAR_TO_PIXEL_COL (f
, x
),
1294 CHAR_TO_PIXEL_ROW (f
, y
),
1295 FONT_WIDTH (f
->output_data
.x
->font
),
1296 f
->output_data
.x
->line_height
, False
);
1298 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, x
),
1299 CHAR_TO_PIXEL_ROW (f
, y
),
1300 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
],
1301 end_x
- x
, highlight_flag
, 1, NULL
);
1306 #if 0 /* Not in use yet */
1308 /* Return 1 if character C in font F extends past its left edge. */
1311 font_char_overlap_left (font
, c
)
1317 /* Find the bounding-box info for C. */
1318 if (font
->per_char
== 0)
1319 s
= &font
->max_bounds
;
1322 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1325 /* Decode char into row number (byte 1) and code within row (byte 2). */
1328 if (!(within
>= font
->min_char_or_byte2
1329 && within
<= font
->max_char_or_byte2
1330 && row
>= font
->min_byte1
1331 && row
<= font
->max_byte1
))
1333 /* If char is out of range, try the font's default char instead. */
1334 c
= font
->default_char
;
1335 row
= c
>> (BITS_PER_INT
- 8);
1338 if (!(within
>= font
->min_char_or_byte2
1339 && within
<= font
->max_char_or_byte2
1340 && row
>= font
->min_byte1
1341 && row
<= font
->max_byte1
))
1342 /* Still out of range means this char does not overlap. */
1345 /* We found the info for this char. */
1346 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1350 return (s
&& s
->lbearing
< 0);
1353 /* Return 1 if character C in font F extends past its right edge. */
1356 font_char_overlap_right (font
, c
)
1362 /* Find the bounding-box info for C. */
1363 if (font
->per_char
== 0)
1364 s
= &font
->max_bounds
;
1367 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1370 /* Decode char into row number (byte 1) and code within row (byte 2). */
1373 if (!(within
>= font
->min_char_or_byte2
1374 && within
<= font
->max_char_or_byte2
1375 && row
>= font
->min_byte1
1376 && row
<= font
->max_byte1
))
1378 /* If char is out of range, try the font's default char instead. */
1379 c
= font
->default_char
;
1380 row
= c
>> (BITS_PER_INT
- 8);
1383 if (!(within
>= font
->min_char_or_byte2
1384 && within
<= font
->max_char_or_byte2
1385 && row
>= font
->min_byte1
1386 && row
<= font
->max_byte1
))
1387 /* Still out of range means this char does not overlap. */
1390 /* We found the info for this char. */
1391 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1395 return (s
&& s
->rbearing
>= s
->width
);
1399 /* Invert the middle quarter of the frame for .15 sec. */
1401 /* We use the select system call to do the waiting, so we have to make sure
1402 it's available. If it isn't, we just won't do visual bells. */
1403 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1405 /* Subtract the `struct timeval' values X and Y,
1406 storing the result in RESULT.
1407 Return 1 if the difference is negative, otherwise 0. */
1410 timeval_subtract (result
, x
, y
)
1411 struct timeval
*result
, x
, y
;
1413 /* Perform the carry for the later subtraction by updating y.
1414 This is safer because on some systems
1415 the tv_sec member is unsigned. */
1416 if (x
.tv_usec
< y
.tv_usec
)
1418 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
1419 y
.tv_usec
-= 1000000 * nsec
;
1422 if (x
.tv_usec
- y
.tv_usec
> 1000000)
1424 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
1425 y
.tv_usec
+= 1000000 * nsec
;
1429 /* Compute the time remaining to wait. tv_usec is certainly positive. */
1430 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
1431 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
1433 /* Return indication of whether the result should be considered negative. */
1434 return x
.tv_sec
< y
.tv_sec
;
1445 /* Create a GC that will use the GXxor function to flip foreground pixels
1446 into background pixels. */
1450 values
.function
= GXxor
;
1451 values
.foreground
= (f
->output_data
.x
->foreground_pixel
1452 ^ f
->output_data
.x
->background_pixel
);
1454 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1455 GCFunction
| GCForeground
, &values
);
1459 /* Get the height not including a menu bar widget. */
1460 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
1461 /* Height of each line to flash. */
1462 int flash_height
= FRAME_LINE_HEIGHT (f
);
1463 /* These will be the left and right margins of the rectangles. */
1464 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1465 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
1469 /* Don't flash the area between a scroll bar and the frame
1470 edge it is next to. */
1471 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
1473 case vertical_scroll_bar_left
:
1474 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1477 case vertical_scroll_bar_right
:
1478 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1482 width
= flash_right
- flash_left
;
1484 /* If window is tall, flash top and bottom line. */
1485 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
1487 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1488 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1489 width
, flash_height
);
1490 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1492 (height
- flash_height
1493 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
1494 width
, flash_height
);
1497 /* If it is short, flash it all. */
1498 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1499 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1500 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
1502 XFlush (FRAME_X_DISPLAY (f
));
1505 struct timeval wakeup
, now
;
1507 EMACS_GET_TIME (wakeup
);
1509 /* Compute time to wait until, propagating carry from usecs. */
1510 wakeup
.tv_usec
+= 150000;
1511 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
1512 wakeup
.tv_usec
%= 1000000;
1514 /* Keep waiting until past the time wakeup. */
1517 struct timeval timeout
;
1519 EMACS_GET_TIME (timeout
);
1521 /* In effect, timeout = wakeup - timeout.
1522 Break if result would be negative. */
1523 if (timeval_subtract (&timeout
, wakeup
, timeout
))
1526 /* Try to wait that long--but we might wake up sooner. */
1527 select (0, NULL
, NULL
, NULL
, &timeout
);
1531 /* If window is tall, flash top and bottom line. */
1532 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
1534 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1535 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1536 width
, flash_height
);
1537 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1539 (height
- flash_height
1540 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
1541 width
, flash_height
);
1544 /* If it is short, flash it all. */
1545 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
1546 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
1547 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
1549 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
1550 XFlush (FRAME_X_DISPLAY (f
));
1560 /* Make audible bell. */
1562 #define XRINGBELL XBell (FRAME_X_DISPLAY (selected_frame), 0)
1566 if (FRAME_X_DISPLAY (selected_frame
) == 0)
1569 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1571 XTflash (selected_frame
);
1577 XFlush (FRAME_X_DISPLAY (selected_frame
));
1582 /* Insert and delete character.
1583 These are not supposed to be used because we are supposed to turn
1584 off the feature of using them. */
1587 XTinsert_glyphs (start
, len
)
1588 register char *start
;
1601 /* Specify how many text lines, from the top of the window,
1602 should be affected by insert-lines and delete-lines operations.
1603 This, and those operations, are used only within an update
1604 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1607 XTset_terminal_window (n
)
1610 if (updating_frame
== 0)
1613 if ((n
<= 0) || (n
> updating_frame
->height
))
1614 flexlines
= updating_frame
->height
;
1619 /* These variables need not be per frame
1620 because redisplay is done on a frame-by-frame basis
1621 and the line dance for one frame is finished before
1622 anything is done for anoter frame. */
1624 /* Array of line numbers from cached insert/delete operations.
1625 line_dance[i] is the old position of the line that we want
1626 to move to line i, or -1 if we want a blank line there. */
1627 static int *line_dance
;
1629 /* Allocated length of that array. */
1630 static int line_dance_len
;
1632 /* Flag indicating whether we've done any work. */
1633 static int line_dance_in_progress
;
1635 /* Perform an insert-lines or delete-lines operation,
1636 inserting N lines or deleting -N lines at vertical position VPOS. */
1637 XTins_del_lines (vpos
, n
)
1640 register int fence
, i
;
1642 if (vpos
>= flexlines
)
1645 if (!line_dance_in_progress
)
1647 int ht
= updating_frame
->height
;
1648 if (ht
> line_dance_len
)
1650 line_dance
= (int *)xrealloc (line_dance
, ht
* sizeof (int));
1651 line_dance_len
= ht
;
1653 for (i
= 0; i
< ht
; ++i
) line_dance
[i
] = i
;
1654 line_dance_in_progress
= 1;
1658 if (n
> flexlines
- vpos
)
1659 n
= flexlines
- vpos
;
1661 for (i
= flexlines
; --i
>= fence
;)
1662 line_dance
[i
] = line_dance
[i
-n
];
1663 for (i
= fence
; --i
>= vpos
;)
1669 if (n
> flexlines
- vpos
)
1670 n
= flexlines
- vpos
;
1671 fence
= flexlines
- n
;
1672 for (i
= vpos
; i
< fence
; ++i
)
1673 line_dance
[i
] = line_dance
[i
+ n
];
1674 for (i
= fence
; i
< flexlines
; ++i
)
1679 /* Here's where we actually move the pixels around.
1680 Must be called with input blocked. */
1684 register int i
, j
, distance
;
1685 register struct frame
*f
;
1689 /* Must check this flag first. If it's not set, then not only is the
1690 array uninitialized, but we might not even have a frame. */
1691 if (!line_dance_in_progress
)
1699 intborder
= CHAR_TO_PIXEL_COL (f
, FRAME_LEFT_SCROLL_BAR_WIDTH (f
));
1701 x_update_cursor (updating_frame
, 0);
1703 for (i
= 0; i
< ht
; ++i
)
1704 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) > 0)
1706 for (j
= i
; (j
< ht
&& line_dance
[j
] != -1
1707 && line_dance
[j
]-j
== distance
); ++j
);
1708 /* Copy [i,j) upward from [i+distance,j+distance) */
1709 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1710 FRAME_X_WINDOW (f
), f
->output_data
.x
->normal_gc
,
1711 intborder
, CHAR_TO_PIXEL_ROW (f
, i
+distance
),
1712 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1713 (j
-i
) * f
->output_data
.x
->line_height
,
1714 intborder
, CHAR_TO_PIXEL_ROW (f
, i
));
1718 for (i
= ht
; --i
>=0; )
1719 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) < 0)
1721 for (j
= i
; (--j
>= 0 && line_dance
[j
] != -1
1722 && line_dance
[j
]-j
== distance
););
1723 /* Copy (j,i] downward from (j+distance, i+distance] */
1724 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1725 FRAME_X_WINDOW (f
), f
->output_data
.x
->normal_gc
,
1726 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1+distance
),
1727 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1728 (i
-j
) * f
->output_data
.x
->line_height
,
1729 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1));
1733 for (i
= 0; i
< ht
; ++i
)
1734 if (line_dance
[i
] == -1)
1736 for (j
= i
; j
< ht
&& line_dance
[j
] == -1; ++j
);
1738 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1739 intborder
, CHAR_TO_PIXEL_ROW (f
, i
),
1740 FRAME_WINDOW_WIDTH (f
) * FONT_WIDTH (f
->output_data
.x
->font
),
1741 (j
-i
) * f
->output_data
.x
->line_height
, False
);
1744 line_dance_in_progress
= 0;
1747 /* Support routines for exposure events. */
1748 static void clear_cursor ();
1750 /* Output into a rectangle of an X-window (for frame F)
1751 the characters in f->phys_lines that overlap that rectangle.
1752 TOP and LEFT are the position of the upper left corner of the rectangle.
1753 ROWS and COLS are the size of the rectangle.
1754 Call this function with input blocked. */
1757 dumprectangle (f
, left
, top
, cols
, rows
)
1759 register int left
, top
, cols
, rows
;
1761 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1762 int cursor_cleared
= 0;
1766 if (FRAME_GARBAGED_P (f
))
1769 /* Express rectangle as four edges, instead of position-and-size. */
1770 bottom
= top
+ rows
;
1771 right
= left
+ cols
;
1773 /* Convert rectangle edges in pixels to edges in chars.
1774 Round down for left and top, up for right and bottom. */
1775 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1776 left
= PIXEL_TO_CHAR_COL (f
, left
);
1777 bottom
+= (f
->output_data
.x
->line_height
- 1);
1778 right
+= (FONT_WIDTH (f
->output_data
.x
->font
) - 1);
1779 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1780 right
= PIXEL_TO_CHAR_COL (f
, right
);
1782 /* Clip the rectangle to what can be visible. */
1787 if (right
> FRAME_WINDOW_WIDTH (f
))
1788 right
= FRAME_WINDOW_WIDTH (f
);
1789 if (bottom
> f
->height
)
1792 /* Get size in chars of the rectangle. */
1793 cols
= right
- left
;
1794 rows
= bottom
- top
;
1796 /* If rectangle has zero area, return. */
1797 if (rows
<= 0) return;
1798 if (cols
<= 0) return;
1800 /* Turn off the cursor if it is in the rectangle.
1801 We will turn it back on afterward. */
1802 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1803 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1809 /* Display the text in the rectangle, one text line at a time. */
1811 for (y
= top
; y
< bottom
; y
++)
1813 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1815 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1818 while (*line
& GLYPH_MASK_PADDING
)
1820 /* We must display the whole glyph of a wide-column
1827 CHAR_TO_PIXEL_COL (f
, left
),
1828 CHAR_TO_PIXEL_ROW (f
, y
),
1829 line
, min (cols
, active_frame
->used
[y
] - left
),
1830 active_frame
->highlight
[y
], 0, NULL
);
1833 /* Turn the cursor on if we turned it off. */
1836 x_update_cursor (f
, 1);
1843 /* We used to only do this if Vx_no_window_manager was non-nil, but
1844 the ICCCM (section 4.1.6) says that the window's border pixmap
1845 and border pixel are window attributes which are "private to the
1846 client", so we can always change it to whatever we want. */
1848 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1849 f
->output_data
.x
->border_pixel
);
1851 x_update_cursor (f
, 1);
1855 frame_unhighlight (f
)
1858 /* We used to only do this if Vx_no_window_manager was non-nil, but
1859 the ICCCM (section 4.1.6) says that the window's border pixmap
1860 and border pixel are window attributes which are "private to the
1861 client", so we can always change it to whatever we want. */
1863 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1864 f
->output_data
.x
->border_tile
);
1866 x_update_cursor (f
, 1);
1869 static void XTframe_rehighlight ();
1870 static void x_frame_rehighlight ();
1872 /* The focus has changed. Update the frames as necessary to reflect
1873 the new situation. Note that we can't change the selected frame
1874 here, because the Lisp code we are interrupting might become confused.
1875 Each event gets marked with the frame in which it occurred, so the
1876 Lisp code can tell when the switch took place by examining the events. */
1879 x_new_focus_frame (dpyinfo
, frame
)
1880 struct x_display_info
*dpyinfo
;
1881 struct frame
*frame
;
1883 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
1884 int events_enqueued
= 0;
1886 if (frame
!= dpyinfo
->x_focus_frame
)
1888 /* Set this before calling other routines, so that they see
1889 the correct value of x_focus_frame. */
1890 dpyinfo
->x_focus_frame
= frame
;
1892 if (old_focus
&& old_focus
->auto_lower
)
1893 x_lower_frame (old_focus
);
1896 selected_frame
= frame
;
1897 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
1899 Fselect_window (selected_frame
->selected_window
);
1900 choose_minibuf_frame ();
1903 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
1904 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
1906 pending_autoraise_frame
= 0;
1909 x_frame_rehighlight (dpyinfo
);
1912 /* Handle an event saying the mouse has moved out of an Emacs frame. */
1915 x_mouse_leave (dpyinfo
)
1916 struct x_display_info
*dpyinfo
;
1918 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
1921 /* The focus has changed, or we have redirected a frame's focus to
1922 another frame (this happens when a frame uses a surrogate
1923 minibuffer frame). Shift the highlight as appropriate.
1925 The FRAME argument doesn't necessarily have anything to do with which
1926 frame is being highlighted or unhighlighted; we only use it to find
1927 the appropriate X display info. */
1929 XTframe_rehighlight (frame
)
1930 struct frame
*frame
;
1932 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
1936 x_frame_rehighlight (dpyinfo
)
1937 struct x_display_info
*dpyinfo
;
1939 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1941 if (dpyinfo
->x_focus_frame
)
1943 dpyinfo
->x_highlight_frame
1944 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
1945 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
1946 : dpyinfo
->x_focus_frame
);
1947 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
1949 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
1950 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1954 dpyinfo
->x_highlight_frame
= 0;
1956 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
1959 frame_unhighlight (old_highlight
);
1960 if (dpyinfo
->x_highlight_frame
)
1961 frame_highlight (dpyinfo
->x_highlight_frame
);
1965 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1967 /* Initialize mode_switch_bit and modifier_meaning. */
1969 x_find_modifier_meanings (dpyinfo
)
1970 struct x_display_info
*dpyinfo
;
1972 int min_code
, max_code
;
1975 XModifierKeymap
*mods
;
1977 dpyinfo
->meta_mod_mask
= 0;
1978 dpyinfo
->shift_lock_mask
= 0;
1979 dpyinfo
->alt_mod_mask
= 0;
1980 dpyinfo
->super_mod_mask
= 0;
1981 dpyinfo
->hyper_mod_mask
= 0;
1984 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
1986 min_code
= dpyinfo
->display
->min_keycode
;
1987 max_code
= dpyinfo
->display
->max_keycode
;
1990 syms
= XGetKeyboardMapping (dpyinfo
->display
,
1991 min_code
, max_code
- min_code
+ 1,
1993 mods
= XGetModifierMapping (dpyinfo
->display
);
1995 /* Scan the modifier table to see which modifier bits the Meta and
1996 Alt keysyms are on. */
1998 int row
, col
; /* The row and column in the modifier table. */
2000 for (row
= 3; row
< 8; row
++)
2001 for (col
= 0; col
< mods
->max_keypermod
; col
++)
2004 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
2006 /* Zeroes are used for filler. Skip them. */
2010 /* Are any of this keycode's keysyms a meta key? */
2014 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
2016 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
2022 dpyinfo
->meta_mod_mask
|= (1 << row
);
2027 dpyinfo
->alt_mod_mask
|= (1 << row
);
2032 dpyinfo
->hyper_mod_mask
|= (1 << row
);
2037 dpyinfo
->super_mod_mask
|= (1 << row
);
2041 /* Ignore this if it's not on the lock modifier. */
2042 if ((1 << row
) == LockMask
)
2043 dpyinfo
->shift_lock_mask
= LockMask
;
2051 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
2052 if (! dpyinfo
->meta_mod_mask
)
2054 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
2055 dpyinfo
->alt_mod_mask
= 0;
2058 /* If some keys are both alt and meta,
2059 make them just meta, not alt. */
2060 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
2062 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
2065 XFree ((char *) syms
);
2066 XFreeModifiermap (mods
);
2069 /* Convert between the modifier bits X uses and the modifier bits
2072 x_x_to_emacs_modifiers (dpyinfo
, state
)
2073 struct x_display_info
*dpyinfo
;
2076 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
2077 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
2078 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
2079 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
2080 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
2081 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
2085 x_emacs_to_x_modifiers (dpyinfo
, state
)
2086 struct x_display_info
*dpyinfo
;
2089 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
2090 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
2091 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
2092 | ((state
& shift_modifier
) ? ShiftMask
: 0)
2093 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
2094 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
2097 /* Convert a keysym to its name. */
2100 x_get_keysym_name (keysym
)
2106 value
= XKeysymToString (keysym
);
2112 /* Mouse clicks and mouse movement. Rah. */
2114 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
2115 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
2116 that the glyph at X, Y occupies, if BOUNDS != 0.
2117 If NOCLIP is nonzero, do not force the value into range. */
2120 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
2122 register int pix_x
, pix_y
;
2123 register int *x
, *y
;
2127 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
2128 even for negative values. */
2130 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
2132 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
2134 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
2135 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
2139 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
2140 bounds
->height
= f
->output_data
.x
->line_height
;
2141 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
2142 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
2149 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
2150 pix_x
= FRAME_WINDOW_WIDTH (f
);
2154 else if (pix_y
> f
->height
)
2163 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
2166 register int *pix_x
, *pix_y
;
2168 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
2169 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
2172 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2174 If the event is a button press, then note that we have grabbed
2178 construct_mouse_click (result
, event
, f
)
2179 struct input_event
*result
;
2180 XButtonEvent
*event
;
2183 /* Make the event type no_event; we'll change that when we decide
2185 result
->kind
= mouse_click
;
2186 result
->code
= event
->button
- Button1
;
2187 result
->timestamp
= event
->time
;
2188 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
2190 | (event
->type
== ButtonRelease
2198 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
2199 XSETFASTINT (result
->x
, column
);
2200 XSETFASTINT (result
->y
, row
);
2202 XSETINT (result
->x
, event
->x
);
2203 XSETINT (result
->y
, event
->y
);
2204 XSETFRAME (result
->frame_or_window
, f
);
2208 /* Prepare a menu-event in *RESULT for placement in the input queue. */
2211 construct_menu_click (result
, event
, f
)
2212 struct input_event
*result
;
2213 XButtonEvent
*event
;
2216 /* Make the event type no_event; we'll change that when we decide
2218 result
->kind
= mouse_click
;
2219 result
->code
= event
->button
- Button1
;
2220 result
->timestamp
= event
->time
;
2221 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
2223 | (event
->type
== ButtonRelease
2227 XSETINT (result
->x
, event
->x
);
2228 XSETINT (result
->y
, -1);
2229 XSETFRAME (result
->frame_or_window
, f
);
2232 /* Function to report a mouse movement to the mainstream Emacs code.
2233 The input handler calls this.
2235 We have received a mouse movement event, which is given in *event.
2236 If the mouse is over a different glyph than it was last time, tell
2237 the mainstream emacs code by setting mouse_moved. If not, ask for
2238 another motion event, so we can check again the next time it moves. */
2241 note_mouse_movement (frame
, event
)
2243 XMotionEvent
*event
;
2245 last_mouse_movement_time
= event
->time
;
2247 if (event
->window
!= FRAME_X_WINDOW (frame
))
2249 frame
->mouse_moved
= 1;
2250 last_mouse_scroll_bar
= Qnil
;
2252 note_mouse_highlight (frame
, -1, -1);
2255 /* Has the mouse moved off the glyph it was on at the last sighting? */
2256 else if (event
->x
< last_mouse_glyph
.x
2257 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
2258 || event
->y
< last_mouse_glyph
.y
2259 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
2261 frame
->mouse_moved
= 1;
2262 last_mouse_scroll_bar
= Qnil
;
2264 note_mouse_highlight (frame
, event
->x
, event
->y
);
2268 /* This is used for debugging, to turn off note_mouse_highlight. */
2269 static int disable_mouse_highlight
;
2271 /* Take proper action when the mouse has moved to position X, Y on frame F
2272 as regards highlighting characters that have mouse-face properties.
2273 Also dehighlighting chars where the mouse was before.
2274 X and Y can be negative or out of range. */
2277 note_mouse_highlight (f
, x
, y
)
2281 int row
, column
, portion
;
2282 XRectangle new_glyph
;
2286 if (disable_mouse_highlight
)
2289 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_x
= x
;
2290 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_y
= y
;
2291 FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
= f
;
2293 if (FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
)
2298 FRAME_X_DISPLAY_INFO (f
)->mouse_face_deferred_gc
= 1;
2302 /* Find out which glyph the mouse is on. */
2303 pixel_to_glyph_coords (f
, x
, y
, &column
, &row
,
2304 &new_glyph
, FRAME_X_DISPLAY_INFO (f
)->grabbed
);
2306 /* Which window is that in? */
2307 window
= window_from_coordinates (f
, column
, row
, &portion
);
2308 w
= XWINDOW (window
);
2310 /* If we were displaying active text in another window, clear that. */
2311 if (! EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
))
2312 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2314 /* Are we in a window whose display is up to date?
2315 And verify the buffer's text has not changed. */
2316 if (WINDOWP (window
) && portion
== 0 && row
>= 0 && column
>= 0
2317 && row
< FRAME_HEIGHT (f
) && column
< FRAME_WIDTH (f
)
2318 && EQ (w
->window_end_valid
, w
->buffer
)
2319 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
2320 && (XFASTINT (w
->last_overlay_modified
)
2321 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
2323 int *ptr
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[row
];
2326 /* Find which buffer position the mouse corresponds to. */
2327 for (i
= column
; i
>= 0; i
--)
2331 /* Is it outside the displayed active region (if any)? */
2333 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2334 else if (! (EQ (window
, FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
)
2335 && row
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2336 && row
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2337 && (row
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2338 || column
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
)
2339 && (row
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2340 || column
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2341 || FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
)))
2343 Lisp_Object mouse_face
, overlay
, position
;
2344 Lisp_Object
*overlay_vec
;
2345 int len
, noverlays
, ignor1
;
2346 struct buffer
*obuf
;
2349 /* If we get an out-of-range value, return now; avoid an error. */
2350 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
2353 /* Make the window's buffer temporarily current for
2354 overlays_at and compute_char_face. */
2355 obuf
= current_buffer
;
2356 current_buffer
= XBUFFER (w
->buffer
);
2362 /* Yes. Clear the display of the old active region, if any. */
2363 clear_mouse_face (FRAME_X_DISPLAY_INFO (f
));
2365 /* Is this char mouse-active? */
2366 XSETINT (position
, pos
);
2369 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2371 /* Put all the overlays we want in a vector in overlay_vec.
2372 Store the length in len. */
2373 noverlays
= overlays_at (pos
, 1, &overlay_vec
, &len
,
2375 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
2377 /* Find the highest priority overlay that has a mouse-face prop. */
2379 for (i
= 0; i
< noverlays
; i
++)
2381 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
2382 if (!NILP (mouse_face
))
2384 overlay
= overlay_vec
[i
];
2389 /* If no overlay applies, get a text property. */
2391 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
2393 /* Handle the overlay case. */
2394 if (! NILP (overlay
))
2396 /* Find the range of text around this char that
2397 should be active. */
2398 Lisp_Object before
, after
;
2401 before
= Foverlay_start (overlay
);
2402 after
= Foverlay_end (overlay
);
2403 /* Record this as the current active region. */
2404 fast_find_position (window
, XFASTINT (before
),
2405 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2406 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2407 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2408 = !fast_find_position (window
, XFASTINT (after
),
2409 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2410 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2411 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2412 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2413 = compute_char_face (f
, w
, pos
, 0, 0,
2414 &ignore
, pos
+ 1, 1);
2416 /* Display it as active. */
2417 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2419 /* Handle the text property case. */
2420 else if (! NILP (mouse_face
))
2422 /* Find the range of text around this char that
2423 should be active. */
2424 Lisp_Object before
, after
, beginning
, end
;
2427 beginning
= Fmarker_position (w
->start
);
2428 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
2429 - XFASTINT (w
->window_end_pos
)));
2431 = Fprevious_single_property_change (make_number (pos
+ 1),
2433 w
->buffer
, beginning
);
2435 = Fnext_single_property_change (position
, Qmouse_face
,
2437 /* Record this as the current active region. */
2438 fast_find_position (window
, XFASTINT (before
),
2439 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
,
2440 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
);
2441 FRAME_X_DISPLAY_INFO (f
)->mouse_face_past_end
2442 = !fast_find_position (window
, XFASTINT (after
),
2443 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
,
2444 &FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
);
2445 FRAME_X_DISPLAY_INFO (f
)->mouse_face_window
= window
;
2446 FRAME_X_DISPLAY_INFO (f
)->mouse_face_face_id
2447 = compute_char_face (f
, w
, pos
, 0, 0,
2448 &ignore
, pos
+ 1, 1);
2450 /* Display it as active. */
2451 show_mouse_face (FRAME_X_DISPLAY_INFO (f
), 1);
2455 current_buffer
= obuf
;
2460 /* Find the row and column of position POS in window WINDOW.
2461 Store them in *COLUMNP and *ROWP.
2462 This assumes display in WINDOW is up to date.
2463 If POS is above start of WINDOW, return coords
2464 of start of first screen line.
2465 If POS is after end of WINDOW, return coords of end of last screen line.
2467 Value is 1 if POS is in range, 0 if it was off screen. */
2470 fast_find_position (window
, pos
, columnp
, rowp
)
2473 int *columnp
, *rowp
;
2475 struct window
*w
= XWINDOW (window
);
2476 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2479 int left
= WINDOW_LEFT_MARGIN (w
);
2480 int top
= XFASTINT (w
->top
);
2481 int height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
2482 int width
= window_internal_width (w
);
2485 int maybe_next_line
= 0;
2487 /* Find the right row. */
2492 int linestart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ i
][left
];
2493 if (linestart
> pos
)
2495 /* If the position sought is the end of the buffer,
2496 don't include the blank lines at the bottom of the window. */
2497 if (linestart
== pos
&& pos
== BUF_ZV (XBUFFER (w
->buffer
)))
2499 maybe_next_line
= 1;
2506 /* Find the right column with in it. */
2507 charstarts
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ row
];
2509 for (i
= 0; i
< width
; i
++)
2511 if (charstarts
[left
+ i
] == pos
)
2514 *columnp
= i
+ left
;
2517 else if (charstarts
[left
+ i
] > pos
)
2519 else if (charstarts
[left
+ i
] > 0)
2523 /* If we're looking for the end of the buffer,
2524 and we didn't find it in the line we scanned,
2525 use the start of the following line. */
2526 if (maybe_next_line
)
2537 /* Display the active region described by mouse_face_*
2538 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2541 show_mouse_face (dpyinfo
, hl
)
2542 struct x_display_info
*dpyinfo
;
2545 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
2546 int width
= window_internal_width (w
);
2547 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2550 int old_curs_x
= curs_x
;
2551 int old_curs_y
= curs_y
;
2553 /* Set these variables temporarily
2554 so that if we have to turn the cursor off and on again
2555 we will put it back at the same place. */
2556 curs_x
= f
->phys_cursor_x
;
2557 curs_y
= f
->phys_cursor_y
;
2558 for (i
= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
;
2559 i
<= FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
; i
++)
2561 int column
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
2562 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
2563 : WINDOW_LEFT_MARGIN (w
));
2564 int endcolumn
= (i
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
2565 ? FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
2566 : WINDOW_LEFT_MARGIN (w
) + width
);
2567 endcolumn
= min (endcolumn
, FRAME_CURRENT_GLYPHS (f
)->used
[i
]);
2569 /* If the cursor's in the text we are about to rewrite,
2570 turn the cursor off. */
2572 && curs_x
>= column
- 1
2573 && curs_x
<= endcolumn
)
2575 x_update_cursor (f
, 0);
2580 CHAR_TO_PIXEL_COL (f
, column
),
2581 CHAR_TO_PIXEL_ROW (f
, i
),
2582 FRAME_CURRENT_GLYPHS (f
)->glyphs
[i
] + column
,
2584 /* Highlight with mouse face if hl > 0. */
2585 hl
> 0 ? 3 : 0, 0, NULL
);
2588 /* If we turned the cursor off, turn it back on. */
2590 x_display_cursor (f
, 1, curs_x
, curs_y
);
2592 curs_x
= old_curs_x
;
2593 curs_y
= old_curs_y
;
2595 /* Change the mouse cursor according to the value of HL. */
2597 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2598 f
->output_data
.x
->cross_cursor
);
2600 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2601 f
->output_data
.x
->text_cursor
);
2604 /* Clear out the mouse-highlighted active region.
2605 Redraw it unhighlighted first. */
2608 clear_mouse_face (dpyinfo
)
2609 struct x_display_info
*dpyinfo
;
2611 if (! NILP (dpyinfo
->mouse_face_window
))
2612 show_mouse_face (dpyinfo
, 0);
2614 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2615 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2616 dpyinfo
->mouse_face_window
= Qnil
;
2619 /* Just discard the mouse face information for frame F, if any.
2620 This is used when the size of F is changed. */
2622 cancel_mouse_face (f
)
2626 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2628 window
= dpyinfo
->mouse_face_window
;
2629 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
2631 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
2632 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
2633 dpyinfo
->mouse_face_window
= Qnil
;
2637 static struct scroll_bar
*x_window_to_scroll_bar ();
2638 static void x_scroll_bar_report_motion ();
2640 /* Return the current position of the mouse.
2641 *fp should be a frame which indicates which display to ask about.
2643 If the mouse movement started in a scroll bar, set *fp, *bar_window,
2644 and *part to the frame, window, and scroll bar part that the mouse
2645 is over. Set *x and *y to the portion and whole of the mouse's
2646 position on the scroll bar.
2648 If the mouse movement started elsewhere, set *fp to the frame the
2649 mouse is on, *bar_window to nil, and *x and *y to the character cell
2652 Set *time to the server timestamp for the time at which the mouse
2653 was at this position.
2655 Don't store anything if we don't have a valid set of values to report.
2657 This clears the mouse_moved flag, so we can wait for the next mouse
2661 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
2664 Lisp_Object
*bar_window
;
2665 enum scroll_bar_part
*part
;
2667 unsigned long *time
;
2673 if (! NILP (last_mouse_scroll_bar
))
2674 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
2680 Window dummy_window
;
2683 Lisp_Object frame
, tail
;
2685 /* Clear the mouse-moved flag for every frame on this display. */
2686 FOR_EACH_FRAME (tail
, frame
)
2687 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
2688 XFRAME (frame
)->mouse_moved
= 0;
2690 last_mouse_scroll_bar
= Qnil
;
2692 /* Figure out which root window we're on. */
2693 XQueryPointer (FRAME_X_DISPLAY (*fp
),
2694 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
2696 /* The root window which contains the pointer. */
2699 /* Trash which we can't trust if the pointer is on
2700 a different screen. */
2703 /* The position on that root window. */
2706 /* More trash we can't trust. */
2709 /* Modifier keys and pointer buttons, about which
2711 (unsigned int *) &dummy
);
2713 /* Now we have a position on the root; find the innermost window
2714 containing the pointer. */
2718 int parent_x
, parent_y
;
2723 /* XTranslateCoordinates can get errors if the window
2724 structure is changing at the same time this function
2725 is running. So at least we must not crash from them. */
2727 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
2729 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
2730 && FRAME_LIVE_P (last_mouse_frame
))
2732 /* If mouse was grabbed on a frame, give coords for that frame
2733 even if the mouse is now outside it. */
2734 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2736 /* From-window, to-window. */
2737 root
, FRAME_X_WINDOW (last_mouse_frame
),
2739 /* From-position, to-position. */
2740 root_x
, root_y
, &win_x
, &win_y
,
2744 f1
= last_mouse_frame
;
2750 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
2752 /* From-window, to-window. */
2755 /* From-position, to-position. */
2756 root_x
, root_y
, &win_x
, &win_y
,
2761 if (child
== None
|| child
== win
)
2769 /* Now we know that:
2770 win is the innermost window containing the pointer
2771 (XTC says it has no child containing the pointer),
2772 win_x and win_y are the pointer's position in it
2773 (XTC did this the last time through), and
2774 parent_x and parent_y are the pointer's position in win's parent.
2775 (They are what win_x and win_y were when win was child.
2776 If win is the root window, it has no parent, and
2777 parent_{x,y} are invalid, but that's okay, because we'll
2778 never use them in that case.) */
2780 /* Is win one of our frames? */
2781 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
2784 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
2787 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
2789 /* If not, is it one of our scroll bars? */
2792 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
2796 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2802 if (f1
== 0 && insist
)
2803 f1
= selected_frame
;
2807 int ignore1
, ignore2
;
2809 /* Ok, we found a frame. Store all the values. */
2811 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
2813 FRAME_X_DISPLAY_INFO (f1
)->grabbed
2819 XSETINT (*x
, win_x
);
2820 XSETINT (*y
, win_y
);
2821 *time
= last_mouse_movement_time
;
2829 /* Scroll bar support. */
2831 /* Given an X window ID, find the struct scroll_bar which manages it.
2832 This can be called in GC, so we have to make sure to strip off mark
2834 static struct scroll_bar
*
2835 x_window_to_scroll_bar (window_id
)
2838 Lisp_Object tail
, frame
;
2840 for (tail
= Vframe_list
;
2841 XGCTYPE (tail
) == Lisp_Cons
;
2842 tail
= XCONS (tail
)->cdr
)
2844 Lisp_Object frame
, bar
, condemned
;
2846 frame
= XCONS (tail
)->car
;
2847 /* All elements of Vframe_list should be frames. */
2848 if (! GC_FRAMEP (frame
))
2851 /* Scan this frame's scroll bar list for a scroll bar with the
2853 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2854 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2855 /* This trick allows us to search both the ordinary and
2856 condemned scroll bar lists with one loop. */
2857 ! GC_NILP (bar
) || (bar
= condemned
,
2860 bar
= XSCROLL_BAR (bar
)->next
)
2861 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2862 return XSCROLL_BAR (bar
);
2868 /* Open a new X window to serve as a scroll bar, and return the
2869 scroll bar vector for it. */
2870 static struct scroll_bar
*
2871 x_scroll_bar_create (window
, top
, left
, width
, height
)
2872 struct window
*window
;
2873 int top
, left
, width
, height
;
2875 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2876 struct scroll_bar
*bar
2877 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2882 XSetWindowAttributes a
;
2884 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
2885 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2886 | ButtonMotionMask
| PointerMotionHintMask
2888 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
2890 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2895 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2896 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2897 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
2898 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
2899 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2900 sb_widget
= XtCreateManagedWidget ("box",
2902 f
->output_data
.x
->edit_widget
, al
, ac
);
2903 SET_SCROLL_BAR_X_WINDOW
2904 (bar
, sb_widget
->core
.window
);
2906 SET_SCROLL_BAR_X_WINDOW
2908 XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2910 /* Position and size of scroll bar. */
2911 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
, top
,
2912 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2, height
,
2914 /* Border width, depth, class, and visual. */
2915 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
2921 XSETWINDOW (bar
->window
, window
);
2922 XSETINT (bar
->top
, top
);
2923 XSETINT (bar
->left
, left
);
2924 XSETINT (bar
->width
, width
);
2925 XSETINT (bar
->height
, height
);
2926 XSETINT (bar
->start
, 0);
2927 XSETINT (bar
->end
, 0);
2928 bar
->dragging
= Qnil
;
2930 /* Add bar to its frame's list of scroll bars. */
2931 bar
->next
= FRAME_SCROLL_BARS (f
);
2933 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2934 if (! NILP (bar
->next
))
2935 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2937 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
2944 /* Draw BAR's handle in the proper position.
2945 If the handle is already drawn from START to END, don't bother
2946 redrawing it, unless REBUILD is non-zero; in that case, always
2947 redraw it. (REBUILD is handy for drawing the handle after expose
2950 Normally, we want to constrain the start and end of the handle to
2951 fit inside its rectangle, but if the user is dragging the scroll bar
2952 handle, we want to let them drag it down all the way, so that the
2953 bar's top is as far down as it goes; otherwise, there's no way to
2954 move to the very end of the buffer. */
2956 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
2957 struct scroll_bar
*bar
;
2961 int dragging
= ! NILP (bar
->dragging
);
2962 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2963 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2964 GC gc
= f
->output_data
.x
->normal_gc
;
2966 /* If the display is already accurate, do nothing. */
2968 && start
== XINT (bar
->start
)
2969 && end
== XINT (bar
->end
))
2975 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
2976 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
2977 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
2979 /* Make sure the values are reasonable, and try to preserve
2980 the distance between start and end. */
2982 int length
= end
- start
;
2986 else if (start
> top_range
)
2988 end
= start
+ length
;
2992 else if (end
> top_range
&& ! dragging
)
2996 /* Store the adjusted setting in the scroll bar. */
2997 XSETINT (bar
->start
, start
);
2998 XSETINT (bar
->end
, end
);
3000 /* Clip the end position, just for display. */
3001 if (end
> top_range
)
3004 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
3005 below top positions, to make sure the handle is always at least
3006 that many pixels tall. */
3007 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
3009 /* Draw the empty space above the handle. Note that we can't clear
3010 zero-height areas; that means "clear to end of window." */
3012 XClearArea (FRAME_X_DISPLAY (f
), w
,
3014 /* x, y, width, height, and exposures. */
3015 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3016 VERTICAL_SCROLL_BAR_TOP_BORDER
,
3017 inside_width
, start
,
3020 /* Draw the handle itself. */
3021 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
3023 /* x, y, width, height */
3024 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3025 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
3026 inside_width
, end
- start
);
3029 /* Draw the empty space below the handle. Note that we can't
3030 clear zero-height areas; that means "clear to end of window." */
3031 if (end
< inside_height
)
3032 XClearArea (FRAME_X_DISPLAY (f
), w
,
3034 /* x, y, width, height, and exposures. */
3035 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
3036 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
3037 inside_width
, inside_height
- end
,
3045 /* Move a scroll bar around on the screen, to accommodate changing
3046 window configurations. */
3048 x_scroll_bar_move (bar
, top
, left
, width
, height
)
3049 struct scroll_bar
*bar
;
3050 int top
, left
, width
, height
;
3052 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3053 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3059 unsigned int mask
= 0;
3061 wc
.x
= left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3064 wc
.width
= width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
3067 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
3068 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
3069 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
3070 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
3073 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
3077 XSETINT (bar
->left
, left
);
3078 XSETINT (bar
->top
, top
);
3079 XSETINT (bar
->width
, width
);
3080 XSETINT (bar
->height
, height
);
3085 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
3088 x_scroll_bar_remove (bar
)
3089 struct scroll_bar
*bar
;
3091 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3095 /* Destroy the window. */
3096 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
3098 /* Disassociate this scroll bar from its window. */
3099 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
3104 /* Set the handle of the vertical scroll bar for WINDOW to indicate
3105 that we are displaying PORTION characters out of a total of WHOLE
3106 characters, starting at POSITION. If WINDOW has no scroll bar,
3109 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
3110 struct window
*window
;
3111 int portion
, whole
, position
;
3113 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
3114 int top
= XINT (window
->top
);
3115 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
3116 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
3118 /* Where should this scroll bar be, pixelwise? */
3119 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
3120 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
3122 = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
3123 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
3124 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
3125 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
3127 struct scroll_bar
*bar
;
3129 /* Does the scroll bar exist yet? */
3130 if (NILP (window
->vertical_scroll_bar
))
3131 bar
= x_scroll_bar_create (window
,
3132 pixel_top
, pixel_left
,
3133 pixel_width
, pixel_height
);
3136 /* It may just need to be moved and resized. */
3137 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
3138 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
3141 /* Set the scroll bar's current state, unless we're currently being
3143 if (NILP (bar
->dragging
))
3145 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, pixel_height
);
3148 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
3151 int start
= ((double) position
* top_range
) / whole
;
3152 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
3154 x_scroll_bar_set_handle (bar
, start
, end
, 0);
3158 XSETVECTOR (window
->vertical_scroll_bar
, bar
);
3162 /* The following three hooks are used when we're doing a thorough
3163 redisplay of the frame. We don't explicitly know which scroll bars
3164 are going to be deleted, because keeping track of when windows go
3165 away is a real pain - "Can you say set-window-configuration, boys
3166 and girls?" Instead, we just assert at the beginning of redisplay
3167 that *all* scroll bars are to be removed, and then save a scroll bar
3168 from the fiery pit when we actually redisplay its window. */
3170 /* Arrange for all scroll bars on FRAME to be removed at the next call
3171 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
3172 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
3174 XTcondemn_scroll_bars (frame
)
3177 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
3178 while (! NILP (FRAME_SCROLL_BARS (frame
)))
3181 bar
= FRAME_SCROLL_BARS (frame
);
3182 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
3183 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
3184 XSCROLL_BAR (bar
)->prev
= Qnil
;
3185 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
3186 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
3187 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
3191 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
3192 Note that WINDOW isn't necessarily condemned at all. */
3194 XTredeem_scroll_bar (window
)
3195 struct window
*window
;
3197 struct scroll_bar
*bar
;
3199 /* We can't redeem this window's scroll bar if it doesn't have one. */
3200 if (NILP (window
->vertical_scroll_bar
))
3203 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
3205 /* Unlink it from the condemned list. */
3207 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
3209 if (NILP (bar
->prev
))
3211 /* If the prev pointer is nil, it must be the first in one of
3213 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
3214 /* It's not condemned. Everything's fine. */
3216 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
3217 window
->vertical_scroll_bar
))
3218 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
3220 /* If its prev pointer is nil, it must be at the front of
3221 one or the other! */
3225 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
3227 if (! NILP (bar
->next
))
3228 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
3230 bar
->next
= FRAME_SCROLL_BARS (f
);
3232 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
3233 if (! NILP (bar
->next
))
3234 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
3238 /* Remove all scroll bars on FRAME that haven't been saved since the
3239 last call to `*condemn_scroll_bars_hook'. */
3241 XTjudge_scroll_bars (f
)
3244 Lisp_Object bar
, next
;
3246 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
3248 /* Clear out the condemned list now so we won't try to process any
3249 more events on the hapless scroll bars. */
3250 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
3252 for (; ! NILP (bar
); bar
= next
)
3254 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
3256 x_scroll_bar_remove (b
);
3259 b
->next
= b
->prev
= Qnil
;
3262 /* Now there should be no references to the condemned scroll bars,
3263 and they should get garbage-collected. */
3267 /* Handle an Expose or GraphicsExpose event on a scroll bar.
3269 This may be called from a signal handler, so we have to ignore GC
3272 x_scroll_bar_expose (bar
, event
)
3273 struct scroll_bar
*bar
;
3276 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3277 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3278 GC gc
= f
->output_data
.x
->normal_gc
;
3279 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3283 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
3285 /* Draw a one-pixel border just inside the edges of the scroll bar. */
3286 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
3288 /* x, y, width, height */
3290 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
3291 XINT (bar
->height
) - 1);
3296 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
3297 is set to something other than no_event, it is enqueued.
3299 This may be called from a signal handler, so we have to ignore GC
3302 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
3303 struct scroll_bar
*bar
;
3305 struct input_event
*emacs_event
;
3307 if (! GC_WINDOWP (bar
->window
))
3310 emacs_event
->kind
= scroll_bar_click
;
3311 emacs_event
->code
= event
->xbutton
.button
- Button1
;
3312 emacs_event
->modifiers
3313 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
3314 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
3315 event
->xbutton
.state
)
3316 | (event
->type
== ButtonRelease
3319 emacs_event
->frame_or_window
= bar
->window
;
3320 emacs_event
->timestamp
= event
->xbutton
.time
;
3322 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3324 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
3326 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3327 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
3330 if (y
> top_range
) y
= top_range
;
3332 if (y
< XINT (bar
->start
))
3333 emacs_event
->part
= scroll_bar_above_handle
;
3334 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3335 emacs_event
->part
= scroll_bar_handle
;
3337 emacs_event
->part
= scroll_bar_below_handle
;
3339 /* Just because the user has clicked on the handle doesn't mean
3340 they want to drag it. Lisp code needs to be able to decide
3341 whether or not we're dragging. */
3343 /* If the user has just clicked on the handle, record where they're
3345 if (event
->type
== ButtonPress
3346 && emacs_event
->part
== scroll_bar_handle
)
3347 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
3350 /* If the user has released the handle, set it to its final position. */
3351 if (event
->type
== ButtonRelease
3352 && ! NILP (bar
->dragging
))
3354 int new_start
= y
- XINT (bar
->dragging
);
3355 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
3357 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
3358 bar
->dragging
= Qnil
;
3361 /* Same deal here as the other #if 0. */
3363 /* Clicks on the handle are always reported as occurring at the top of
3365 if (emacs_event
->part
== scroll_bar_handle
)
3366 emacs_event
->x
= bar
->start
;
3368 XSETINT (emacs_event
->x
, y
);
3370 XSETINT (emacs_event
->x
, y
);
3373 XSETINT (emacs_event
->y
, top_range
);
3377 /* Handle some mouse motion while someone is dragging the scroll bar.
3379 This may be called from a signal handler, so we have to ignore GC
3382 x_scroll_bar_note_movement (bar
, event
)
3383 struct scroll_bar
*bar
;
3386 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
3388 last_mouse_movement_time
= event
->xmotion
.time
;
3391 XSETVECTOR (last_mouse_scroll_bar
, bar
);
3393 /* If we're dragging the bar, display it. */
3394 if (! GC_NILP (bar
->dragging
))
3396 /* Where should the handle be now? */
3397 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
3399 if (new_start
!= XINT (bar
->start
))
3401 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
3403 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
3408 /* Return information to the user about the current position of the mouse
3409 on the scroll bar. */
3411 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
3413 Lisp_Object
*bar_window
;
3414 enum scroll_bar_part
*part
;
3416 unsigned long *time
;
3418 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
3419 Window w
= SCROLL_BAR_X_WINDOW (bar
);
3420 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3422 Window dummy_window
;
3424 unsigned int dummy_mask
;
3428 /* Get the mouse's position relative to the scroll bar window, and
3430 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
3432 /* Root, child, root x and root y. */
3433 &dummy_window
, &dummy_window
,
3434 &dummy_coord
, &dummy_coord
,
3436 /* Position relative to scroll bar. */
3439 /* Mouse buttons and modifier keys. */
3445 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
3447 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
3449 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
3451 if (! NILP (bar
->dragging
))
3452 win_y
-= XINT (bar
->dragging
);
3456 if (win_y
> top_range
)
3460 *bar_window
= bar
->window
;
3462 if (! NILP (bar
->dragging
))
3463 *part
= scroll_bar_handle
;
3464 else if (win_y
< XINT (bar
->start
))
3465 *part
= scroll_bar_above_handle
;
3466 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3467 *part
= scroll_bar_handle
;
3469 *part
= scroll_bar_below_handle
;
3471 XSETINT (*x
, win_y
);
3472 XSETINT (*y
, top_range
);
3475 last_mouse_scroll_bar
= Qnil
;
3478 *time
= last_mouse_movement_time
;
3484 /* The screen has been cleared so we may have changed foreground or
3485 background colors, and the scroll bars may need to be redrawn.
3486 Clear out the scroll bars, and ask for expose events, so we can
3489 x_scroll_bar_clear (f
)
3494 /* We can have scroll bars even if this is 0,
3495 if we just turned off scroll bar mode.
3496 But in that case we should not clear them. */
3497 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3498 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
3499 bar
= XSCROLL_BAR (bar
)->next
)
3500 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
3504 /* This processes Expose events from the menubar specific X event
3505 loop in xmenu.c. This allows to redisplay the frame if necessary
3506 when handling menubar or popup items. */
3509 process_expose_from_menu (event
)
3513 struct x_display_info
*dpyinfo
;
3517 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
3518 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3521 if (f
->async_visible
== 0)
3523 f
->async_visible
= 1;
3524 f
->async_iconified
= 0;
3525 f
->output_data
.x
->has_been_visible
= 1;
3526 SET_FRAME_GARBAGED (f
);
3530 dumprectangle (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
3531 event
.xexpose
.x
, event
.xexpose
.y
,
3532 event
.xexpose
.width
, event
.xexpose
.height
);
3537 struct scroll_bar
*bar
3538 = x_window_to_scroll_bar (event
.xexpose
.window
);
3541 x_scroll_bar_expose (bar
, &event
);
3547 /* Define a queue to save up SelectionRequest events for later handling. */
3549 struct selection_event_queue
3552 struct selection_event_queue
*next
;
3555 static struct selection_event_queue
*queue
;
3557 /* Nonzero means queue up certain events--don't process them yet. */
3558 static int x_queue_selection_requests
;
3560 /* Queue up an X event *EVENT, to be processed later. */
3563 x_queue_event (f
, event
)
3567 struct selection_event_queue
*queue_tmp
3568 = (struct selection_event_queue
*) malloc (sizeof (struct selection_event_queue
));
3570 if (queue_tmp
!= NULL
)
3572 queue_tmp
->event
= *event
;
3573 queue_tmp
->next
= queue
;
3578 /* Take all the queued events and put them back
3579 so that they get processed afresh. */
3582 x_unqueue_events (display
)
3585 while (queue
!= NULL
)
3587 struct selection_event_queue
*queue_tmp
= queue
;
3588 XPutBackEvent (display
, &queue_tmp
->event
);
3589 queue
= queue_tmp
->next
;
3590 free ((char *)queue_tmp
);
3594 /* Start queuing SelectionRequest events. */
3597 x_start_queuing_selection_requests (display
)
3600 x_queue_selection_requests
++;
3603 /* Stop queuing SelectionRequest events. */
3606 x_stop_queuing_selection_requests (display
)
3609 x_queue_selection_requests
--;
3610 x_unqueue_events (display
);
3613 /* The main X event-reading loop - XTread_socket. */
3615 /* Timestamp of enter window event. This is only used by XTread_socket,
3616 but we have to put it out here, since static variables within functions
3617 sometimes don't work. */
3618 static Time enter_timestamp
;
3620 /* This holds the state XLookupString needs to implement dead keys
3621 and other tricks known as "compose processing". _X Window System_
3622 says that a portable program can't use this, but Stephen Gildea assures
3623 me that letting the compiler initialize it to zeros will work okay.
3625 This must be defined outside of XTread_socket, for the same reasons
3626 given for enter_timestamp, above. */
3627 static XComposeStatus compose_status
;
3629 /* Record the last 100 characters stored
3630 to help debug the loss-of-chars-during-GC problem. */
3631 static int temp_index
;
3632 static short temp_buffer
[100];
3634 /* Set this to nonzero to fake an "X I/O error"
3635 on a particular display. */
3636 struct x_display_info
*XTread_socket_fake_io_error
;
3638 /* When we find no input here, we occasionally do a no-op command
3639 to verify that the X server is still running and we can still talk with it.
3640 We try all the open displays, one by one.
3641 This variable is used for cycling thru the displays. */
3642 static struct x_display_info
*next_noop_dpyinfo
;
3644 #define SET_SAVED_MENU_EVENT(size) { \
3645 if (f->output_data.x->saved_menu_event == 0) \
3646 f->output_data.x->saved_menu_event = (XEvent*)xmalloc (sizeof (XEvent)); \
3647 bcopy (&event, f->output_data.x->saved_menu_event, size); \
3648 if (numchars >= 1) \
3650 bufp->kind = menu_bar_activate_event; \
3651 XSETFRAME (bufp->frame_or_window, f); \
3657 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
3658 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
3660 /* Read events coming from the X server.
3661 This routine is called by the SIGIO handler.
3662 We return as soon as there are no more events to be read.
3664 Events representing keys are stored in buffer BUFP,
3665 which can hold up to NUMCHARS characters.
3666 We return the number of characters stored into the buffer,
3667 thus pretending to be `read'.
3669 EXPECTED is nonzero if the caller knows input is available. */
3672 XTread_socket (sd
, bufp
, numchars
, expected
)
3674 /* register */ struct input_event
*bufp
;
3675 /* register */ int numchars
;
3681 int items_pending
; /* How many items are in the X queue. */
3684 int event_found
= 0;
3687 struct x_display_info
*dpyinfo
;
3689 Status status_return
;
3692 if (interrupt_input_blocked
)
3694 interrupt_input_pending
= 1;
3698 interrupt_input_pending
= 0;
3701 /* So people can tell when we have read the available input. */
3702 input_signal_count
++;
3705 abort (); /* Don't think this happens. */
3707 /* Find the display we are supposed to read input for.
3708 It's the one communicating on descriptor SD. */
3709 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
3711 #if 0 /* This ought to be unnecessary; let's verify it. */
3713 /* If available, Xlib uses FIOSNBIO to make the socket
3714 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3715 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
3716 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3717 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
3718 #endif /* ! defined (FIOSNBIO) */
3721 #if 0 /* This code can't be made to work, with multiple displays,
3722 and appears not to be used on any system any more.
3723 Also keyboard.c doesn't turn O_NDELAY on and off
3724 for X connections. */
3727 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
3729 extern int read_alarm_should_throw
;
3730 read_alarm_should_throw
= 1;
3731 XPeekEvent (dpyinfo
->display
, &event
);
3732 read_alarm_should_throw
= 0;
3734 #endif /* HAVE_SELECT */
3738 /* For debugging, this gives a way to fake an I/O error. */
3739 if (dpyinfo
== XTread_socket_fake_io_error
)
3741 XTread_socket_fake_io_error
= 0;
3742 x_io_error_quitter (dpyinfo
->display
);
3745 while (XPending (dpyinfo
->display
) != 0)
3747 #ifdef USE_X_TOOLKIT
3748 /* needed to raise Motif submenus */
3749 XtAppNextEvent (Xt_app_con
, &event
);
3751 XNextEvent (dpyinfo
->display
, &event
);
3755 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
3756 &event
.xclient
.window
);
3757 /* The necessity of the following line took me
3758 a full work-day to decipher from the docs!! */
3759 if (f1
!= 0 && FRAME_XIC (f1
) && XFilterEvent (&event
, None
))
3769 if (event
.xclient
.message_type
3770 == dpyinfo
->Xatom_wm_protocols
3771 && event
.xclient
.format
== 32)
3773 if (event
.xclient
.data
.l
[0]
3774 == dpyinfo
->Xatom_wm_take_focus
)
3776 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3777 /* Since we set WM_TAKE_FOCUS, we must call
3778 XSetInputFocus explicitly. But not if f is null,
3779 since that might be an event for a deleted frame. */
3781 /* Not quite sure this is needed -pd */
3783 XSetICFocus (FRAME_XIC (f
));
3786 XSetInputFocus (event
.xclient
.display
,
3787 event
.xclient
.window
,
3788 RevertToPointerRoot
,
3789 event
.xclient
.data
.l
[1]);
3790 /* Not certain about handling scroll bars here */
3792 else if (event
.xclient
.data
.l
[0]
3793 == dpyinfo
->Xatom_wm_save_yourself
)
3795 /* Save state modify the WM_COMMAND property to
3796 something which can reinstate us. This notifies
3797 the session manager, who's looking for such a
3798 PropertyNotify. Can restart processing when
3799 a keyboard or mouse event arrives. */
3802 f
= x_top_window_to_frame (dpyinfo
,
3803 event
.xclient
.window
);
3805 /* This is just so we only give real data once
3806 for a single Emacs process. */
3807 if (f
== selected_frame
)
3808 XSetCommand (FRAME_X_DISPLAY (f
),
3809 event
.xclient
.window
,
3810 initial_argv
, initial_argc
);
3812 XSetCommand (FRAME_X_DISPLAY (f
),
3813 event
.xclient
.window
,
3817 else if (event
.xclient
.data
.l
[0]
3818 == dpyinfo
->Xatom_wm_delete_window
)
3821 = x_any_window_to_frame (dpyinfo
,
3822 event
.xclient
.window
);
3829 bufp
->kind
= delete_window_event
;
3830 XSETFRAME (bufp
->frame_or_window
, f
);
3838 else if (event
.xclient
.message_type
3839 == dpyinfo
->Xatom_wm_configure_denied
)
3842 else if (event
.xclient
.message_type
3843 == dpyinfo
->Xatom_wm_window_moved
)
3847 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
3849 new_x
= event
.xclient
.data
.s
[0];
3850 new_y
= event
.xclient
.data
.s
[1];
3854 f
->output_data
.x
->left_pos
= new_x
;
3855 f
->output_data
.x
->top_pos
= new_y
;
3859 else if (event
.xclient
.message_type
3860 == dpyinfo
->Xatom_editres
)
3863 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
3864 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
3867 #endif /* HACK_EDITRES */
3871 case SelectionNotify
:
3872 #ifdef USE_X_TOOLKIT
3873 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
3875 #endif /* not USE_X_TOOLKIT */
3876 x_handle_selection_notify (&event
);
3879 case SelectionClear
: /* Someone has grabbed ownership. */
3880 #ifdef USE_X_TOOLKIT
3881 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
3883 #endif /* USE_X_TOOLKIT */
3885 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
3890 bufp
->kind
= selection_clear_event
;
3891 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3892 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3893 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3894 bufp
->frame_or_window
= Qnil
;
3902 case SelectionRequest
: /* Someone wants our selection. */
3903 #ifdef USE_X_TOOLKIT
3904 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
3906 #endif /* USE_X_TOOLKIT */
3907 if (x_queue_selection_requests
)
3908 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
3912 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
3917 bufp
->kind
= selection_request_event
;
3918 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3919 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
3920 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3921 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
3922 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
3923 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3924 bufp
->frame_or_window
= Qnil
;
3932 case PropertyNotify
:
3933 #ifdef USE_X_TOOLKIT
3934 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
3936 #endif /* not USE_X_TOOLKIT */
3937 x_handle_property_notify (&event
);
3940 case ReparentNotify
:
3941 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
3945 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
3946 x_real_positions (f
, &x
, &y
);
3947 f
->output_data
.x
->left_pos
= x
;
3948 f
->output_data
.x
->top_pos
= y
;
3953 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
3956 if (f
->async_visible
== 0)
3958 f
->async_visible
= 1;
3959 f
->async_iconified
= 0;
3960 f
->output_data
.x
->has_been_visible
= 1;
3961 SET_FRAME_GARBAGED (f
);
3964 dumprectangle (x_window_to_frame (dpyinfo
,
3965 event
.xexpose
.window
),
3966 event
.xexpose
.x
, event
.xexpose
.y
,
3967 event
.xexpose
.width
, event
.xexpose
.height
);
3971 struct scroll_bar
*bar
3972 = x_window_to_scroll_bar (event
.xexpose
.window
);
3975 x_scroll_bar_expose (bar
, &event
);
3976 #ifdef USE_X_TOOLKIT
3979 #endif /* USE_X_TOOLKIT */
3983 case GraphicsExpose
: /* This occurs when an XCopyArea's
3984 source area was obscured or not
3986 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
3990 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
3991 event
.xgraphicsexpose
.width
,
3992 event
.xgraphicsexpose
.height
);
3994 #ifdef USE_X_TOOLKIT
3997 #endif /* USE_X_TOOLKIT */
4000 case NoExpose
: /* This occurs when an XCopyArea's
4001 source area was completely
4006 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
4007 if (f
) /* F may no longer exist if
4008 the frame was deleted. */
4010 /* While a frame is unmapped, display generation is
4011 disabled; you don't want to spend time updating a
4012 display that won't ever be seen. */
4013 f
->async_visible
= 0;
4014 /* We can't distinguish, from the event, whether the window
4015 has become iconified or invisible. So assume, if it
4016 was previously visible, than now it is iconified.
4017 But x_make_frame_invisible clears both
4018 the visible flag and the iconified flag;
4019 and that way, we know the window is not iconified now. */
4020 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
4022 f
->async_iconified
= 1;
4024 bufp
->kind
= iconify_event
;
4025 XSETFRAME (bufp
->frame_or_window
, f
);
4034 /* We use x_top_window_to_frame because map events can come
4035 for subwindows and they don't mean that the frame is visible. */
4036 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
4039 f
->async_visible
= 1;
4040 f
->async_iconified
= 0;
4041 f
->output_data
.x
->has_been_visible
= 1;
4043 /* wait_reading_process_input will notice this and update
4044 the frame's display structures. */
4045 SET_FRAME_GARBAGED (f
);
4049 bufp
->kind
= deiconify_event
;
4050 XSETFRAME (bufp
->frame_or_window
, f
);
4055 else if (! NILP (Vframe_list
)
4056 && ! NILP (XCONS (Vframe_list
)->cdr
))
4057 /* Force a redisplay sooner or later
4058 to update the frame titles
4059 in case this is the second frame. */
4060 record_asynch_buffer_change ();
4064 /* Turn off processing if we become fully obscured. */
4065 case VisibilityNotify
:
4069 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
4073 KeySym keysym
, orig_keysym
;
4074 /* al%imercury@uunet.uu.net says that making this 81 instead of
4075 80 fixed a bug whereby meta chars made his Emacs hang. */
4076 unsigned char copy_buffer
[81];
4079 #if 0 /* This was how we made f10 work in Motif.
4080 The drawback is, you can't type at Emacs when the
4081 the mouse is in the menu bar. So it is better to
4082 turn off f10 in Motif and let Emacs handle it. */
4084 if (lw_window_is_in_menubar (event
.xkey
.window
,
4085 f
->output_data
.x
->menubar_widget
4088 SET_SAVED_KEY_EVENT
;
4091 #endif /* USE_MOTIF */
4095 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
4096 extra_keyboard_modifiers
);
4097 modifiers
= event
.xkey
.state
;
4099 /* This will have to go some day... */
4101 /* make_lispy_event turns chars into control chars.
4102 Don't do it here because XLookupString is too eager. */
4103 event
.xkey
.state
&= ~ControlMask
;
4104 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
4105 | dpyinfo
->super_mod_mask
4106 | dpyinfo
->hyper_mod_mask
4107 | dpyinfo
->alt_mod_mask
);
4109 /* In case Meta is ComposeCharacter,
4110 clear its status. According to Markus Ehrnsperger
4111 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
4112 this enables ComposeCharacter to work whether or
4113 not it is combined with Meta. */
4114 if (modifiers
& dpyinfo
->meta_mod_mask
)
4115 bzero (&compose_status
, sizeof (compose_status
));
4120 nbytes
= XmbLookupString (FRAME_XIC (f
),
4121 &event
.xkey
, copy_buffer
,
4126 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
4127 80, &keysym
, &compose_status
);
4129 nbytes
= XLookupString (&event
.xkey
, copy_buffer
,
4130 80, &keysym
, &compose_status
);
4133 orig_keysym
= keysym
;
4137 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
4138 || keysym
== XK_Delete
4139 #ifdef XK_ISO_Left_Tab
4140 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
4142 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
4143 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
4145 /* This recognizes the "extended function keys".
4146 It seems there's no cleaner way.
4147 Test IsModifierKey to avoid handling mode_switch
4149 || ((unsigned) (keysym
) >= XK_Select
4150 && (unsigned)(keysym
) < XK_KP_Space
)
4152 #ifdef XK_dead_circumflex
4153 || orig_keysym
== XK_dead_circumflex
4155 #ifdef XK_dead_grave
4156 || orig_keysym
== XK_dead_grave
4158 #ifdef XK_dead_tilde
4159 || orig_keysym
== XK_dead_tilde
4161 #ifdef XK_dead_diaeresis
4162 || orig_keysym
== XK_dead_diaeresis
4164 #ifdef XK_dead_macron
4165 || orig_keysym
== XK_dead_macron
4167 #ifdef XK_dead_degree
4168 || orig_keysym
== XK_dead_degree
4170 #ifdef XK_dead_acute
4171 || orig_keysym
== XK_dead_acute
4173 #ifdef XK_dead_cedilla
4174 || orig_keysym
== XK_dead_cedilla
4176 #ifdef XK_dead_breve
4177 || orig_keysym
== XK_dead_breve
4179 #ifdef XK_dead_ogonek
4180 || orig_keysym
== XK_dead_ogonek
4182 #ifdef XK_dead_caron
4183 || orig_keysym
== XK_dead_caron
4185 #ifdef XK_dead_doubleacute
4186 || orig_keysym
== XK_dead_doubleacute
4188 #ifdef XK_dead_abovedot
4189 || orig_keysym
== XK_dead_abovedot
4191 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
4192 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
4193 /* Any "vendor-specific" key is ok. */
4194 || (orig_keysym
& (1 << 28)))
4195 && ! (IsModifierKey (orig_keysym
)
4197 #ifdef XK_Mode_switch
4198 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
4201 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
4203 #endif /* not HAVE_X11R5 */
4206 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4208 temp_buffer
[temp_index
++] = keysym
;
4209 bufp
->kind
= non_ascii_keystroke
;
4210 bufp
->code
= keysym
;
4211 XSETFRAME (bufp
->frame_or_window
, f
);
4213 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
4215 bufp
->timestamp
= event
.xkey
.time
;
4220 else if (numchars
> nbytes
)
4224 for (i
= 0; i
< nbytes
; i
++)
4226 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
4228 temp_buffer
[temp_index
++] = copy_buffer
[i
];
4229 bufp
->kind
= ascii_keystroke
;
4230 bufp
->code
= copy_buffer
[i
];
4231 XSETFRAME (bufp
->frame_or_window
, f
);
4233 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
4235 bufp
->timestamp
= event
.xkey
.time
;
4250 /* Here's a possible interpretation of the whole
4251 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
4252 FocusIn event, you have to get a FocusOut event before you
4253 relinquish the focus. If you haven't received a FocusIn event,
4254 then a mere LeaveNotify is enough to free you. */
4257 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
4259 if (event
.xcrossing
.focus
) /* Entered Window */
4261 /* Avoid nasty pop/raise loops. */
4262 if (f
&& (!(f
->auto_raise
)
4264 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
4266 x_new_focus_frame (dpyinfo
, f
);
4267 enter_timestamp
= event
.xcrossing
.time
;
4270 else if (f
== dpyinfo
->x_focus_frame
)
4271 x_new_focus_frame (dpyinfo
, 0);
4272 /* EnterNotify counts as mouse movement,
4273 so update things that depend on mouse position. */
4275 note_mouse_movement (f
, &event
.xmotion
);
4279 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
4280 if (event
.xfocus
.detail
!= NotifyPointer
)
4281 dpyinfo
->x_focus_event_frame
= f
;
4283 x_new_focus_frame (dpyinfo
, f
);
4286 if (f
&& FRAME_XIC (f
))
4287 XSetICFocus (FRAME_XIC (f
));
4293 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
4296 if (f
== dpyinfo
->mouse_face_mouse_frame
)
4297 /* If we move outside the frame,
4298 then we're certainly no longer on any text in the frame. */
4299 clear_mouse_face (dpyinfo
);
4301 if (event
.xcrossing
.focus
)
4302 x_mouse_leave (dpyinfo
);
4305 if (f
== dpyinfo
->x_focus_event_frame
)
4306 dpyinfo
->x_focus_event_frame
= 0;
4307 if (f
== dpyinfo
->x_focus_frame
)
4308 x_new_focus_frame (dpyinfo
, 0);
4314 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
4315 if (event
.xfocus
.detail
!= NotifyPointer
4316 && f
== dpyinfo
->x_focus_event_frame
)
4317 dpyinfo
->x_focus_event_frame
= 0;
4318 if (f
&& f
== dpyinfo
->x_focus_frame
)
4319 x_new_focus_frame (dpyinfo
, 0);
4322 if (f
&& FRAME_XIC (f
))
4323 XUnsetICFocus (FRAME_XIC (f
));
4330 if (dpyinfo
->grabbed
&& last_mouse_frame
4331 && FRAME_LIVE_P (last_mouse_frame
))
4332 f
= last_mouse_frame
;
4334 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
4336 note_mouse_movement (f
, &event
.xmotion
);
4339 struct scroll_bar
*bar
4340 = x_window_to_scroll_bar (event
.xmotion
.window
);
4343 x_scroll_bar_note_movement (bar
, &event
);
4345 /* If we move outside the frame,
4346 then we're certainly no longer on any text in the frame. */
4347 clear_mouse_face (dpyinfo
);
4352 case ConfigureNotify
:
4353 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
4356 #ifndef USE_X_TOOLKIT
4357 /* In the toolkit version, change_frame_size
4358 is called by the code that handles resizing
4359 of the EmacsFrame widget. */
4361 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
4362 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
4364 /* Even if the number of character rows and columns has
4365 not changed, the font size may have changed, so we need
4366 to check the pixel dimensions as well. */
4367 if (columns
!= f
->width
4368 || rows
!= f
->height
4369 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
4370 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
4372 change_frame_size (f
, rows
, columns
, 0, 1);
4373 SET_FRAME_GARBAGED (f
);
4374 cancel_mouse_face (f
);
4378 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
4379 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
4381 /* What we have now is the position of Emacs's own window.
4382 Convert that to the position of the window manager window. */
4383 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
4384 &f
->output_data
.x
->top_pos
);
4386 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
4388 /* Since the WM decorations come below top_pos now,
4389 we must put them below top_pos in the future. */
4390 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
4391 x_wm_set_size_hint (f
, (long) 0, 0);
4399 /* If we decide we want to generate an event to be seen
4400 by the rest of Emacs, we put it here. */
4401 struct input_event emacs_event
;
4402 emacs_event
.kind
= no_event
;
4404 bzero (&compose_status
, sizeof (compose_status
));
4406 if (dpyinfo
->grabbed
&& last_mouse_frame
4407 && FRAME_LIVE_P (last_mouse_frame
))
4408 f
= last_mouse_frame
;
4410 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
4414 if (!dpyinfo
->x_focus_frame
|| f
== dpyinfo
->x_focus_frame
)
4415 construct_mouse_click (&emacs_event
, &event
, f
);
4419 struct scroll_bar
*bar
4420 = x_window_to_scroll_bar (event
.xbutton
.window
);
4423 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
4426 if (event
.type
== ButtonPress
)
4428 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
4429 last_mouse_frame
= f
;
4433 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
4436 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
4438 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
4444 #ifdef USE_X_TOOLKIT
4445 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
4446 /* For a down-event in the menu bar,
4447 don't pass it to Xt right now.
4448 Instead, save it away
4449 and we will pass it to Xt from kbd_buffer_get_event.
4450 That way, we can run some Lisp code first. */
4451 if (f
&& event
.type
== ButtonPress
4452 /* Verify the event is really within the menu bar
4453 and not just sent to it due to grabbing. */
4454 && event
.xbutton
.x
>= 0
4455 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
4456 && event
.xbutton
.y
>= 0
4457 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
4458 && event
.xbutton
.same_screen
)
4460 SET_SAVED_BUTTON_EVENT
;
4461 XSETFRAME (last_mouse_press_frame
, f
);
4463 else if (event
.type
== ButtonPress
)
4465 last_mouse_press_frame
= Qnil
;
4468 #ifdef USE_MOTIF /* This should do not harm for Lucid,
4469 but I am trying to be cautious. */
4470 else if (event
.type
== ButtonRelease
)
4472 if (!NILP (last_mouse_press_frame
))
4474 f
= XFRAME (last_mouse_press_frame
);
4475 if (f
->output_data
.x
)
4477 SET_SAVED_BUTTON_EVENT
;
4483 #endif /* USE_MOTIF */
4486 #endif /* USE_X_TOOLKIT */
4490 case CirculateNotify
:
4492 case CirculateRequest
:
4496 /* Someone has changed the keyboard mapping - update the
4498 switch (event
.xmapping
.request
)
4500 case MappingModifier
:
4501 x_find_modifier_meanings (dpyinfo
);
4502 /* This is meant to fall through. */
4503 case MappingKeyboard
:
4504 XRefreshKeyboardMapping (&event
.xmapping
);
4510 #ifdef USE_X_TOOLKIT
4512 XtDispatchEvent (&event
);
4514 #endif /* USE_X_TOOLKIT */
4520 /* On some systems, an X bug causes Emacs to get no more events
4521 when the window is destroyed. Detect that. (1994.) */
4524 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
4525 One XNOOP in 100 loops will make Emacs terminate.
4526 B. Bretthauer, 1994 */
4528 if (x_noop_count
>= 100)
4532 if (next_noop_dpyinfo
== 0)
4533 next_noop_dpyinfo
= x_display_list
;
4535 XNoOp (next_noop_dpyinfo
->display
);
4537 /* Each time we get here, cycle through the displays now open. */
4538 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
4542 /* If the focus was just given to an autoraising frame,
4544 /* ??? This ought to be able to handle more than one such frame. */
4545 if (pending_autoraise_frame
)
4547 x_raise_frame (pending_autoraise_frame
);
4548 pending_autoraise_frame
= 0;
4555 /* Drawing the cursor. */
4558 /* Draw a hollow box cursor on frame F at X, Y.
4559 Don't change the inside of the box. */
4562 x_draw_box (f
, x
, y
)
4566 int left
= CHAR_TO_PIXEL_COL (f
, x
);
4567 int top
= CHAR_TO_PIXEL_ROW (f
, y
);
4568 int width
= FONT_WIDTH (f
->output_data
.x
->font
);
4569 int height
= f
->output_data
.x
->line_height
;
4570 int c
= FAST_GLYPH_CHAR (f
->phys_cursor_glyph
);
4571 int charset
= CHAR_CHARSET (c
);
4573 /* If cursor is on a multi-column character, multiply WIDTH by columns. */
4574 width
*= (charset
== CHARSET_COMPOSITION
4575 ? cmpchar_table
[COMPOSITE_CHAR_ID (c
)]->width
4576 : CHARSET_WIDTH (charset
));
4577 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4578 f
->output_data
.x
->cursor_gc
,
4579 left
, top
, width
- 1, height
- 1);
4582 /* Clear the cursor of frame F to background color,
4583 and mark the cursor as not shown.
4584 This is used when the text where the cursor is
4585 is about to be rewritten. */
4593 if (! FRAME_VISIBLE_P (f
)
4594 || ! f
->phys_cursor_on
)
4597 x_update_cursor (f
, 0);
4598 f
->phys_cursor_on
= 0;
4601 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4602 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4606 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
4613 CHAR_TO_PIXEL_COL (f
, column
),
4614 CHAR_TO_PIXEL_ROW (f
, row
),
4615 &glyph
, 1, highlight
, 0, NULL
);
4619 x_display_bar_cursor (f
, on
, x
, y
)
4624 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4626 /* This is pointless on invisible frames, and dangerous on garbaged
4627 frames; in the latter case, the frame may be in the midst of
4628 changing its size, and x and y may be off the frame. */
4629 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4632 if (! on
&& ! f
->phys_cursor_on
)
4635 /* If there is anything wrong with the current cursor state, remove it. */
4636 if (f
->phys_cursor_on
4638 || f
->phys_cursor_x
!= x
4639 || f
->phys_cursor_y
!= y
4640 || f
->output_data
.x
->current_cursor
!= bar_cursor
))
4642 /* Erase the cursor by redrawing the character underneath it. */
4643 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4644 f
->phys_cursor_glyph
,
4645 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4646 f
->phys_cursor_on
= 0;
4649 /* If we now need a cursor in the new place or in the new form, do it so. */
4651 && (! f
->phys_cursor_on
4652 || (f
->output_data
.x
->current_cursor
!= bar_cursor
)))
4654 f
->phys_cursor_glyph
4655 = ((current_glyphs
->enable
[y
]
4656 && x
< current_glyphs
->used
[y
])
4657 ? current_glyphs
->glyphs
[y
][x
]
4659 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4660 f
->output_data
.x
->cursor_gc
,
4661 CHAR_TO_PIXEL_COL (f
, x
),
4662 CHAR_TO_PIXEL_ROW (f
, y
),
4663 max (f
->output_data
.x
->cursor_width
, 1),
4664 f
->output_data
.x
->line_height
);
4666 f
->phys_cursor_x
= x
;
4667 f
->phys_cursor_y
= y
;
4668 f
->phys_cursor_on
= 1;
4670 f
->output_data
.x
->current_cursor
= bar_cursor
;
4673 if (updating_frame
!= f
)
4674 XFlush (FRAME_X_DISPLAY (f
));
4678 /* Turn the displayed cursor of frame F on or off according to ON.
4679 If ON is nonzero, where to put the cursor is specified by X and Y. */
4682 x_display_box_cursor (f
, on
, x
, y
)
4687 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4689 /* This is pointless on invisible frames, and dangerous on garbaged
4690 frames; in the latter case, the frame may be in the midst of
4691 changing its size, and x and y may be off the frame. */
4692 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4695 /* If cursor is off and we want it off, return quickly. */
4696 if (!on
&& ! f
->phys_cursor_on
)
4699 /* If cursor is currently being shown and we don't want it to be
4700 or it is in the wrong place,
4701 or we want a hollow box and it's not so, (pout!)
4703 if (f
->phys_cursor_on
4705 || f
->phys_cursor_x
!= x
4706 || f
->phys_cursor_y
!= y
4707 || (f
->output_data
.x
->current_cursor
!= hollow_box_cursor
4708 && (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
))))
4710 int mouse_face_here
= 0;
4711 struct frame_glyphs
*active_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4713 /* If the cursor is in the mouse face area, redisplay that when
4714 we clear the cursor. */
4715 if (f
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_mouse_frame
4717 (f
->phys_cursor_y
> FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4718 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_row
4719 && f
->phys_cursor_x
>= FRAME_X_DISPLAY_INFO (f
)->mouse_face_beg_col
))
4721 (f
->phys_cursor_y
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4722 || (f
->phys_cursor_y
== FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_row
4723 && f
->phys_cursor_x
< FRAME_X_DISPLAY_INFO (f
)->mouse_face_end_col
))
4724 /* Don't redraw the cursor's spot in mouse face
4725 if it is at the end of a line (on a newline).
4726 The cursor appears there, but mouse highlighting does not. */
4727 && active_glyphs
->used
[f
->phys_cursor_y
] > f
->phys_cursor_x
)
4728 mouse_face_here
= 1;
4730 /* If the font is not as tall as a whole line,
4731 we must explicitly clear the line's whole height. */
4732 if (FONT_HEIGHT (f
->output_data
.x
->font
) != f
->output_data
.x
->line_height
)
4733 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4734 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
4735 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
4736 FONT_WIDTH (f
->output_data
.x
->font
),
4737 f
->output_data
.x
->line_height
, False
);
4738 /* Erase the cursor by redrawing the character underneath it. */
4739 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4740 f
->phys_cursor_glyph
,
4743 : current_glyphs
->highlight
[f
->phys_cursor_y
]));
4744 f
->phys_cursor_on
= 0;
4747 /* If we want to show a cursor,
4748 or we want a box cursor and it's not so,
4749 write it in the right place. */
4751 && (! f
->phys_cursor_on
4752 || (f
->output_data
.x
->current_cursor
!= filled_box_cursor
4753 && f
== FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)))
4755 f
->phys_cursor_glyph
4756 = ((current_glyphs
->enable
[y
]
4757 && x
< current_glyphs
->used
[y
])
4758 ? current_glyphs
->glyphs
[y
][x
]
4760 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
4762 x_draw_box (f
, x
, y
);
4763 f
->output_data
.x
->current_cursor
= hollow_box_cursor
;
4767 x_draw_single_glyph (f
, y
, x
,
4768 f
->phys_cursor_glyph
, 2);
4769 f
->output_data
.x
->current_cursor
= filled_box_cursor
;
4772 f
->phys_cursor_x
= x
;
4773 f
->phys_cursor_y
= y
;
4774 f
->phys_cursor_on
= 1;
4777 if (updating_frame
!= f
)
4778 XFlush (FRAME_X_DISPLAY (f
));
4781 /* Display the cursor on frame F, or clear it, according to ON.
4782 Also set the frame's cursor position to X and Y. */
4784 x_display_cursor (f
, on
, x
, y
)
4791 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4792 x_display_box_cursor (f
, on
, x
, y
);
4793 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4794 x_display_bar_cursor (f
, on
, x
, y
);
4796 /* Those are the only two we have implemented! */
4802 /* Display the cursor on frame F, or clear it, according to ON.
4803 Don't change the cursor's position. */
4805 x_update_cursor (f
, on
)
4811 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4812 x_display_box_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4813 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4814 x_display_bar_cursor (f
, on
, f
->phys_cursor_x
, f
->phys_cursor_y
);
4816 /* Those are the only two we have implemented! */
4824 /* Refresh bitmap kitchen sink icon for frame F
4825 when we get an expose event for it. */
4830 /* Normally, the window manager handles this function. */
4833 /* Make the x-window of frame F use the gnu icon bitmap. */
4836 x_bitmap_icon (f
, file
)
4840 int mask
, bitmap_id
;
4843 if (FRAME_X_WINDOW (f
) == 0)
4846 /* Free up our existing icon bitmap if any. */
4847 if (f
->output_data
.x
->icon_bitmap
> 0)
4848 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
4849 f
->output_data
.x
->icon_bitmap
= 0;
4852 bitmap_id
= x_create_bitmap_from_file (f
, file
);
4855 /* Create the GNU bitmap if necessary. */
4856 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
4857 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
4858 = x_create_bitmap_from_data (f
, gnu_bits
,
4859 gnu_width
, gnu_height
);
4861 /* The first time we create the GNU bitmap,
4862 this increments the refcount one extra time.
4863 As a result, the GNU bitmap is never freed.
4864 That way, we don't have to worry about allocating it again. */
4865 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
4867 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
4870 x_wm_set_icon_pixmap (f
, bitmap_id
);
4871 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
4877 /* Make the x-window of frame F use a rectangle with text.
4878 Use ICON_NAME as the text. */
4881 x_text_icon (f
, icon_name
)
4885 if (FRAME_X_WINDOW (f
) == 0)
4891 text
.value
= (unsigned char *) icon_name
;
4892 text
.encoding
= XA_STRING
;
4894 text
.nitems
= strlen (icon_name
);
4895 #ifdef USE_X_TOOLKIT
4896 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
4898 #else /* not USE_X_TOOLKIT */
4899 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
4900 #endif /* not USE_X_TOOLKIT */
4902 #else /* not HAVE_X11R4 */
4903 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
4904 #endif /* not HAVE_X11R4 */
4906 if (f
->output_data
.x
->icon_bitmap
> 0)
4907 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
4908 f
->output_data
.x
->icon_bitmap
= 0;
4909 x_wm_set_icon_pixmap (f
, 0);
4914 #define X_ERROR_MESSAGE_SIZE 200
4916 /* If non-nil, this should be a string.
4917 It means catch X errors and store the error message in this string. */
4919 static Lisp_Object x_error_message_string
;
4921 /* An X error handler which stores the error message in
4922 x_error_message_string. This is called from x_error_handler if
4923 x_catch_errors is in effect. */
4926 x_error_catcher (display
, error
)
4930 XGetErrorText (display
, error
->error_code
,
4931 XSTRING (x_error_message_string
)->data
,
4932 X_ERROR_MESSAGE_SIZE
);
4935 /* Begin trapping X errors for display DPY. Actually we trap X errors
4936 for all displays, but DPY should be the display you are actually
4939 After calling this function, X protocol errors no longer cause
4940 Emacs to exit; instead, they are recorded in the string
4941 stored in x_error_message_string.
4943 Calling x_check_errors signals an Emacs error if an X error has
4944 occurred since the last call to x_catch_errors or x_check_errors.
4946 Calling x_uncatch_errors resumes the normal error handling. */
4948 void x_check_errors ();
4949 static Lisp_Object
x_catch_errors_unwind ();
4952 x_catch_errors (dpy
)
4955 int count
= specpdl_ptr
- specpdl
;
4957 /* Make sure any errors from previous requests have been dealt with. */
4960 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
4962 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
4963 XSTRING (x_error_message_string
)->data
[0] = 0;
4968 /* Unbind the binding that we made to check for X errors. */
4971 x_catch_errors_unwind (old_val
)
4972 Lisp_Object old_val
;
4974 x_error_message_string
= old_val
;
4978 /* If any X protocol errors have arrived since the last call to
4979 x_catch_errors or x_check_errors, signal an Emacs error using
4980 sprintf (a buffer, FORMAT, the x error message text) as the text. */
4983 x_check_errors (dpy
, format
)
4987 /* Make sure to catch any errors incurred so far. */
4990 if (XSTRING (x_error_message_string
)->data
[0])
4991 error (format
, XSTRING (x_error_message_string
)->data
);
4994 /* Nonzero if we had any X protocol errors
4995 since we did x_catch_errors on DPY. */
4998 x_had_errors_p (dpy
)
5001 /* Make sure to catch any errors incurred so far. */
5004 return XSTRING (x_error_message_string
)->data
[0] != 0;
5007 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
5010 x_clear_errors (dpy
)
5013 XSTRING (x_error_message_string
)->data
[0] = 0;
5016 /* Stop catching X protocol errors and let them make Emacs die.
5017 DPY should be the display that was passed to x_catch_errors.
5018 COUNT should be the value that was returned by
5019 the corresponding call to x_catch_errors. */
5022 x_uncatch_errors (dpy
, count
)
5026 unbind_to (count
, Qnil
);
5030 static unsigned int x_wire_count
;
5033 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
5038 /* Handle SIGPIPE, which can happen when the connection to a server
5039 simply goes away. SIGPIPE is handled by x_connection_signal.
5040 Don't need to do anything, because the write which caused the
5041 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
5042 which will do the appropriate cleanup for us. */
5045 x_connection_signal (signalnum
) /* If we don't have an argument, */
5046 int signalnum
; /* some compilers complain in signal calls. */
5049 /* USG systems forget handlers when they are used;
5050 must reestablish each time */
5051 signal (signalnum
, x_connection_signal
);
5055 /* Handling X errors. */
5057 /* Handle the loss of connection to display DISPLAY. */
5060 x_connection_closed (display
, error_message
)
5062 char *error_message
;
5064 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
5065 Lisp_Object frame
, tail
;
5067 /* Indicate that this display is dead. */
5069 #ifdef USE_X_TOOLKIT
5070 XtCloseDisplay (display
);
5073 dpyinfo
->display
= 0;
5075 /* First delete frames whose minibuffers are on frames
5076 that are on the dead display. */
5077 FOR_EACH_FRAME (tail
, frame
)
5079 Lisp_Object minibuf_frame
;
5081 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
5082 if (FRAME_X_P (XFRAME (frame
))
5083 && FRAME_X_P (XFRAME (minibuf_frame
))
5084 && ! EQ (frame
, minibuf_frame
)
5085 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
5086 Fdelete_frame (frame
, Qt
);
5089 /* Now delete all remaining frames on the dead display.
5090 We are now sure none of these is used as the minibuffer
5091 for another frame that we need to delete. */
5092 FOR_EACH_FRAME (tail
, frame
)
5093 if (FRAME_X_P (XFRAME (frame
))
5094 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
5096 /* Set this to t so that Fdelete_frame won't get confused
5097 trying to find a replacement. */
5098 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
5099 Fdelete_frame (frame
, Qt
);
5103 x_delete_display (dpyinfo
);
5105 if (x_display_list
== 0)
5107 fprintf (stderr
, "%s\n", error_message
);
5108 shut_down_emacs (0, 0, Qnil
);
5112 /* Ordinary stack unwind doesn't deal with these. */
5114 sigunblock (sigmask (SIGIO
));
5116 sigunblock (sigmask (SIGALRM
));
5117 TOTALLY_UNBLOCK_INPUT
;
5119 clear_waiting_for_input ();
5120 error ("%s", error_message
);
5123 /* This is the usual handler for X protocol errors.
5124 It kills all frames on the display that we got the error for.
5125 If that was the only one, it prints an error message and kills Emacs. */
5128 x_error_quitter (display
, error
)
5132 char buf
[256], buf1
[356];
5134 /* Note that there is no real way portable across R3/R4 to get the
5135 original error handler. */
5137 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
5138 sprintf (buf1
, "X protocol error: %s on protocol request %d",
5139 buf
, error
->request_code
);
5140 x_connection_closed (display
, buf1
);
5143 /* This is the first-level handler for X protocol errors.
5144 It calls x_error_quitter or x_error_catcher. */
5147 x_error_handler (display
, error
)
5151 char buf
[256], buf1
[356];
5153 if (! NILP (x_error_message_string
))
5154 x_error_catcher (display
, error
);
5156 x_error_quitter (display
, error
);
5159 /* This is the handler for X IO errors, always.
5160 It kills all frames on the display that we lost touch with.
5161 If that was the only one, it prints an error message and kills Emacs. */
5164 x_io_error_quitter (display
)
5169 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
5170 x_connection_closed (display
, buf
);
5173 /* Changing the font of the frame. */
5175 /* Give frame F the font named FONTNAME as its default font, and
5176 return the full name of that font. FONTNAME may be a wildcard
5177 pattern; in that case, we choose some font that fits the pattern.
5178 The return value shows which font we chose. */
5181 x_new_font (f
, fontname
)
5183 register char *fontname
;
5185 struct font_info
*fontp
5186 = fs_load_font (f
, FRAME_X_FONT_TABLE (f
), CHARSET_ASCII
, fontname
, -1);
5191 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
5192 f
->output_data
.x
->font_baseline
5193 = (f
->output_data
.x
->font
->ascent
+ fontp
->baseline_offset
);
5194 f
->output_data
.x
->fontset
= -1;
5196 /* Compute the scroll bar width in character columns. */
5197 if (f
->scroll_bar_pixel_width
> 0)
5199 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
5200 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
5203 f
->scroll_bar_cols
= 2;
5205 /* Now make the frame display the given font. */
5206 if (FRAME_X_WINDOW (f
) != 0)
5208 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
5209 f
->output_data
.x
->font
->fid
);
5210 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
5211 f
->output_data
.x
->font
->fid
);
5212 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
5213 f
->output_data
.x
->font
->fid
);
5215 frame_update_line_height (f
);
5216 x_set_window_size (f
, 0, f
->width
, f
->height
);
5219 /* If we are setting a new frame's font for the first time,
5220 there are no faces yet, so this font's height is the line height. */
5221 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
5223 return build_string (fontp
->full_name
);
5226 /* Give frame F the fontset named FONTSETNAME as its default font, and
5227 return the full name of that fontset. FONTSETNAME may be a wildcard
5228 pattern; in that case, we choose some fontset that fits the pattern.
5229 The return value shows which fontset we chose. */
5232 x_new_fontset (f
, fontsetname
)
5236 int fontset
= fs_query_fontset (f
, fontsetname
);
5237 struct fontset_info
*fontsetp
;
5243 fontsetp
= FRAME_FONTSET_DATA (f
)->fontset_table
[fontset
];
5245 if (!fontsetp
->fontname
[CHARSET_ASCII
])
5246 /* This fontset doesn't contain ASCII font. */
5249 result
= x_new_font (f
, fontsetp
->fontname
[CHARSET_ASCII
]);
5251 if (!STRINGP (result
))
5252 /* Can't load ASCII font. */
5255 /* Since x_new_font doesn't update any fontset information, do it now. */
5256 f
->output_data
.x
->fontset
= fontset
;
5257 fs_load_font (f
, FRAME_X_FONT_TABLE (f
),
5258 CHARSET_ASCII
, XSTRING (result
)->data
, fontset
);
5260 return build_string (fontsetname
);
5263 /* Calculate the absolute position in frame F
5264 from its current recorded position values and gravity. */
5266 x_calc_absolute_position (f
)
5270 int win_x
= 0, win_y
= 0;
5271 int flags
= f
->output_data
.x
->size_hint_flags
;
5274 /* We have nothing to do if the current position
5275 is already for the top-left corner. */
5276 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
5279 #ifdef USE_X_TOOLKIT
5280 this_window
= XtWindow (f
->output_data
.x
->widget
);
5282 this_window
= FRAME_X_WINDOW (f
);
5285 /* Find the position of the outside upper-left corner of
5286 the inner window, with respect to the outer window.
5287 But do this only if we will need the results. */
5288 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
5293 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
5296 x_clear_errors (FRAME_X_DISPLAY (f
));
5297 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
5299 /* From-window, to-window. */
5301 f
->output_data
.x
->parent_desc
,
5303 /* From-position, to-position. */
5304 0, 0, &win_x
, &win_y
,
5308 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
5310 Window newroot
, newparent
= 0xdeadbeef;
5311 Window
*newchildren
;
5314 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
5315 &newparent
, &newchildren
, &nchildren
))
5318 XFree (newchildren
);
5320 f
->output_data
.x
->parent_desc
= newparent
;
5326 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
5330 /* Treat negative positions as relative to the leftmost bottommost
5331 position that fits on the screen. */
5332 if (flags
& XNegative
)
5333 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
5334 - 2 * f
->output_data
.x
->border_width
- win_x
5336 + f
->output_data
.x
->left_pos
);
5338 if (flags
& YNegative
)
5339 /* We used to subtract f->output_data.x->menubar_height here
5340 in the toolkit case, but PIXEL_HEIGHT already includes that. */
5341 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
5342 - 2 * f
->output_data
.x
->border_width
- win_y
5344 + f
->output_data
.x
->top_pos
);
5346 /* The left_pos and top_pos
5347 are now relative to the top and left screen edges,
5348 so the flags should correspond. */
5349 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5352 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
5353 to really change the position, and 0 when calling from
5354 x_make_frame_visible (in that case, XOFF and YOFF are the current
5355 position values). It is -1 when calling from x_set_frame_parameters,
5356 which means, do adjust for borders but don't change the gravity. */
5358 x_set_offset (f
, xoff
, yoff
, change_gravity
)
5360 register int xoff
, yoff
;
5363 int modified_top
, modified_left
;
5365 if (change_gravity
> 0)
5367 f
->output_data
.x
->top_pos
= yoff
;
5368 f
->output_data
.x
->left_pos
= xoff
;
5369 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
5371 f
->output_data
.x
->size_hint_flags
|= XNegative
;
5373 f
->output_data
.x
->size_hint_flags
|= YNegative
;
5374 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
5376 x_calc_absolute_position (f
);
5379 x_wm_set_size_hint (f
, (long) 0, 0);
5381 modified_left
= f
->output_data
.x
->left_pos
;
5382 modified_top
= f
->output_data
.x
->top_pos
;
5383 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
5384 this seems to be unnecessary and incorrect. rms, 4/17/97. */
5385 /* It is a mystery why we need to add the border_width here
5386 when the frame is already visible, but experiment says we do. */
5387 if (change_gravity
!= 0)
5389 modified_left
+= f
->output_data
.x
->border_width
;
5390 modified_top
+= f
->output_data
.x
->border_width
;
5394 #ifdef USE_X_TOOLKIT
5395 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
5396 modified_left
, modified_top
);
5397 #else /* not USE_X_TOOLKIT */
5398 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5399 modified_left
, modified_top
);
5400 #endif /* not USE_X_TOOLKIT */
5404 /* Call this to change the size of frame F's x-window.
5405 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5406 for this size change and subsequent size changes.
5407 Otherwise we leave the window gravity unchanged. */
5409 x_set_window_size (f
, change_gravity
, cols
, rows
)
5414 int pixelwidth
, pixelheight
;
5416 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5420 #ifdef USE_X_TOOLKIT
5422 /* The x and y position of the widget is clobbered by the
5423 call to XtSetValues within EmacsFrameSetCharSize.
5424 This is a real kludge, but I don't understand Xt so I can't
5425 figure out a correct fix. Can anyone else tell me? -- rms. */
5426 int xpos
= f
->output_data
.x
->widget
->core
.x
;
5427 int ypos
= f
->output_data
.x
->widget
->core
.y
;
5428 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
5429 f
->output_data
.x
->widget
->core
.x
= xpos
;
5430 f
->output_data
.x
->widget
->core
.y
= ypos
;
5433 #else /* not USE_X_TOOLKIT */
5435 check_frame_size (f
, &rows
, &cols
);
5436 f
->output_data
.x
->vertical_scroll_bar_extra
5437 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5439 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
5440 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
5441 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
5442 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
5443 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
5445 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
5446 x_wm_set_size_hint (f
, (long) 0, 0);
5448 XSync (FRAME_X_DISPLAY (f
), False
);
5449 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5450 pixelwidth
, pixelheight
);
5452 /* Now, strictly speaking, we can't be sure that this is accurate,
5453 but the window manager will get around to dealing with the size
5454 change request eventually, and we'll hear how it went when the
5455 ConfigureNotify event gets here.
5457 We could just not bother storing any of this information here,
5458 and let the ConfigureNotify event set everything up, but that
5459 might be kind of confusing to the lisp code, since size changes
5460 wouldn't be reported in the frame parameters until some random
5461 point in the future when the ConfigureNotify event arrives. */
5462 change_frame_size (f
, rows
, cols
, 0, 0);
5463 PIXEL_WIDTH (f
) = pixelwidth
;
5464 PIXEL_HEIGHT (f
) = pixelheight
;
5466 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5467 receive in the ConfigureNotify event; if we get what we asked
5468 for, then the event won't cause the screen to become garbaged, so
5469 we have to make sure to do it here. */
5470 SET_FRAME_GARBAGED (f
);
5472 XFlush (FRAME_X_DISPLAY (f
));
5474 #endif /* not USE_X_TOOLKIT */
5476 /* If cursor was outside the new size, mark it as off. */
5477 if (f
->phys_cursor_y
>= rows
5478 || f
->phys_cursor_x
>= cols
)
5480 f
->phys_cursor_x
= 0;
5481 f
->phys_cursor_y
= 0;
5482 f
->phys_cursor_on
= 0;
5485 /* Clear out any recollection of where the mouse highlighting was,
5486 since it might be in a place that's outside the new frame size.
5487 Actually checking whether it is outside is a pain in the neck,
5488 so don't try--just let the highlighting be done afresh with new size. */
5489 cancel_mouse_face (f
);
5494 /* Mouse warping. */
5497 x_set_mouse_position (f
, x
, y
)
5503 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
5504 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
5506 if (pix_x
< 0) pix_x
= 0;
5507 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
5509 if (pix_y
< 0) pix_y
= 0;
5510 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
5514 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5515 0, 0, 0, 0, pix_x
, pix_y
);
5519 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
5522 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
5528 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
5529 0, 0, 0, 0, pix_x
, pix_y
);
5533 /* focus shifting, raising and lowering. */
5535 x_focus_on_frame (f
)
5538 #if 0 /* This proves to be unpleasant. */
5542 /* I don't think that the ICCCM allows programs to do things like this
5543 without the interaction of the window manager. Whatever you end up
5544 doing with this code, do it to x_unfocus_frame too. */
5545 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5546 RevertToPointerRoot
, CurrentTime
);
5554 /* Look at the remarks in x_focus_on_frame. */
5555 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
5556 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
5557 RevertToPointerRoot
, CurrentTime
);
5561 /* Raise frame F. */
5566 if (f
->async_visible
)
5569 #ifdef USE_X_TOOLKIT
5570 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
5571 #else /* not USE_X_TOOLKIT */
5572 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5573 #endif /* not USE_X_TOOLKIT */
5574 XFlush (FRAME_X_DISPLAY (f
));
5579 /* Lower frame F. */
5584 if (f
->async_visible
)
5587 #ifdef USE_X_TOOLKIT
5588 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
5589 #else /* not USE_X_TOOLKIT */
5590 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5591 #endif /* not USE_X_TOOLKIT */
5592 XFlush (FRAME_X_DISPLAY (f
));
5598 XTframe_raise_lower (f
, raise_flag
)
5608 /* Change of visibility. */
5610 /* This tries to wait until the frame is really visible.
5611 However, if the window manager asks the user where to position
5612 the frame, this will return before the user finishes doing that.
5613 The frame will not actually be visible at that time,
5614 but it will become visible later when the window manager
5615 finishes with it. */
5617 x_make_frame_visible (f
)
5622 int starting_flags
= f
->output_data
.x
->size_hint_flags
;
5623 int original_top
, original_left
;
5627 type
= x_icon_type (f
);
5629 x_bitmap_icon (f
, type
);
5631 if (! FRAME_VISIBLE_P (f
))
5633 /* We test FRAME_GARBAGED_P here to make sure we don't
5634 call x_set_offset a second time
5635 if we get to x_make_frame_visible a second time
5636 before the window gets really visible. */
5637 if (! FRAME_ICONIFIED_P (f
)
5638 && ! f
->output_data
.x
->asked_for_visible
)
5639 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
5641 f
->output_data
.x
->asked_for_visible
= 1;
5643 if (! EQ (Vx_no_window_manager
, Qt
))
5644 x_wm_set_window_state (f
, NormalState
);
5645 #ifdef USE_X_TOOLKIT
5646 /* This was XtPopup, but that did nothing for an iconified frame. */
5647 XtMapWidget (f
->output_data
.x
->widget
);
5648 #else /* not USE_X_TOOLKIT */
5649 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5650 #endif /* not USE_X_TOOLKIT */
5651 #if 0 /* This seems to bring back scroll bars in the wrong places
5652 if the window configuration has changed. They seem
5653 to come back ok without this. */
5654 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5655 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5659 XFlush (FRAME_X_DISPLAY (f
));
5661 /* Synchronize to ensure Emacs knows the frame is visible
5662 before we do anything else. We do this loop with input not blocked
5663 so that incoming events are handled. */
5666 int count
= input_signal_count
;
5668 original_left
= f
->output_data
.x
->left_pos
;
5669 original_top
= f
->output_data
.x
->top_pos
;
5671 /* This must come after we set COUNT. */
5674 /* Arriving X events are processed here. */
5676 /* Now move the window back to where it was "supposed to be".
5677 But don't do it if the gravity is negative.
5678 When the gravity is negative, this uses a position
5679 that is 3 pixels too low. Perhaps that's really the border width. */
5681 if (! FRAME_VISIBLE_P (f
)
5682 && f
->output_data
.x
->win_gravity
== NorthWestGravity
5683 && f
->output_data
.x
->has_been_visible
)
5687 #ifdef USE_X_TOOLKIT
5688 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
5689 original_left
, original_top
);
5690 #else /* not USE_X_TOOLKIT */
5691 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5692 original_left
, original_top
);
5693 #endif /* not USE_X_TOOLKIT */
5697 XSETFRAME (frame
, f
);
5702 /* Once we have handled input events,
5703 we should have received the MapNotify if one is coming.
5704 So if we have not got it yet, stop looping.
5705 Some window managers make their own decisions
5706 about visibility. */
5707 if (input_signal_count
!= count
)
5709 /* Machines that do polling rather than SIGIO have been observed
5710 to go into a busy-wait here. So we'll fake an alarm signal
5711 to let the handler know that there's something to be read.
5712 We used to raise a real alarm, but it seems that the handler
5713 isn't always enabled here. This is probably a bug. */
5714 if (input_polling_used ())
5716 /* It could be confusing if a real alarm arrives while processing
5717 the fake one. Turn it off and let the handler reset it. */
5719 input_poll_signal ();
5721 /* Once we have handled input events,
5722 we should have received the MapNotify if one is coming.
5723 So if we have not got it yet, stop looping.
5724 Some window managers make their own decisions
5725 about visibility. */
5726 if (input_signal_count
!= count
)
5729 FRAME_SAMPLE_VISIBILITY (f
);
5733 /* Change from mapped state to withdrawn state. */
5735 /* Make the frame visible (mapped and not iconified). */
5737 x_make_frame_invisible (f
)
5743 #ifdef USE_X_TOOLKIT
5744 /* Use the frame's outermost window, not the one we normally draw on. */
5745 window
= XtWindow (f
->output_data
.x
->widget
);
5746 #else /* not USE_X_TOOLKIT */
5747 window
= FRAME_X_WINDOW (f
);
5748 #endif /* not USE_X_TOOLKIT */
5750 /* Don't keep the highlight on an invisible frame. */
5751 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5752 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5754 #if 0/* This might add unreliability; I don't trust it -- rms. */
5755 if (! f
->async_visible
&& ! f
->async_iconified
)
5761 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5762 that the current position of the window is user-specified, rather than
5763 program-specified, so that when the window is mapped again, it will be
5764 placed at the same location, without forcing the user to position it
5765 by hand again (they have already done that once for this window.) */
5766 x_wm_set_size_hint (f
, (long) 0, 1);
5770 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
5771 DefaultScreen (FRAME_X_DISPLAY (f
))))
5773 UNBLOCK_INPUT_RESIGNAL
;
5774 error ("Can't notify window manager of window withdrawal");
5776 #else /* ! defined (HAVE_X11R4) */
5778 /* Tell the window manager what we're going to do. */
5779 if (! EQ (Vx_no_window_manager
, Qt
))
5783 unmap
.xunmap
.type
= UnmapNotify
;
5784 unmap
.xunmap
.window
= window
;
5785 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
5786 unmap
.xunmap
.from_configure
= False
;
5787 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5788 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5790 SubstructureRedirectMask
|SubstructureNotifyMask
,
5793 UNBLOCK_INPUT_RESIGNAL
;
5794 error ("Can't notify window manager of withdrawal");
5798 /* Unmap the window ourselves. Cheeky! */
5799 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
5800 #endif /* ! defined (HAVE_X11R4) */
5802 /* We can't distinguish this from iconification
5803 just by the event that we get from the server.
5804 So we can't win using the usual strategy of letting
5805 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5806 and synchronize with the server to make sure we agree. */
5808 FRAME_ICONIFIED_P (f
) = 0;
5809 f
->async_visible
= 0;
5810 f
->async_iconified
= 0;
5817 /* Change window state from mapped to iconified. */
5826 /* Don't keep the highlight on an invisible frame. */
5827 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
5828 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
5830 if (f
->async_iconified
)
5835 FRAME_SAMPLE_VISIBILITY (f
);
5837 type
= x_icon_type (f
);
5839 x_bitmap_icon (f
, type
);
5841 #ifdef USE_X_TOOLKIT
5843 if (! FRAME_VISIBLE_P (f
))
5845 if (! EQ (Vx_no_window_manager
, Qt
))
5846 x_wm_set_window_state (f
, IconicState
);
5847 /* This was XtPopup, but that did nothing for an iconified frame. */
5848 XtMapWidget (f
->output_data
.x
->widget
);
5849 /* The server won't give us any event to indicate
5850 that an invisible frame was changed to an icon,
5851 so we have to record it here. */
5854 f
->async_iconified
= 1;
5855 f
->async_visible
= 0;
5860 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
5861 XtWindow (f
->output_data
.x
->widget
),
5862 DefaultScreen (FRAME_X_DISPLAY (f
)));
5866 error ("Can't notify window manager of iconification");
5868 f
->async_iconified
= 1;
5869 f
->async_visible
= 0;
5873 XFlush (FRAME_X_DISPLAY (f
));
5875 #else /* not USE_X_TOOLKIT */
5877 /* Make sure the X server knows where the window should be positioned,
5878 in case the user deiconifies with the window manager. */
5879 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
5880 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
5882 /* Since we don't know which revision of X we're running, we'll use both
5883 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
5885 /* X11R4: send a ClientMessage to the window manager using the
5886 WM_CHANGE_STATE type. */
5890 message
.xclient
.window
= FRAME_X_WINDOW (f
);
5891 message
.xclient
.type
= ClientMessage
;
5892 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
5893 message
.xclient
.format
= 32;
5894 message
.xclient
.data
.l
[0] = IconicState
;
5896 if (! XSendEvent (FRAME_X_DISPLAY (f
),
5897 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
5899 SubstructureRedirectMask
| SubstructureNotifyMask
,
5902 UNBLOCK_INPUT_RESIGNAL
;
5903 error ("Can't notify window manager of iconification");
5907 /* X11R3: set the initial_state field of the window manager hints to
5909 x_wm_set_window_state (f
, IconicState
);
5911 if (!FRAME_VISIBLE_P (f
))
5913 /* If the frame was withdrawn, before, we must map it. */
5914 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5917 f
->async_iconified
= 1;
5918 f
->async_visible
= 0;
5920 XFlush (FRAME_X_DISPLAY (f
));
5922 #endif /* not USE_X_TOOLKIT */
5925 /* Destroy the X window of frame F. */
5927 x_destroy_window (f
)
5930 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5934 /* If a display connection is dead, don't try sending more
5935 commands to the X server. */
5936 if (dpyinfo
->display
!= 0)
5938 if (f
->output_data
.x
->icon_desc
!= 0)
5939 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
5943 XDestroyIC (FRAME_XIC (f
));
5944 #if ! defined (SOLARIS2) || defined (HAVE_X11R6)
5945 /* This line causes crashes on Solaris with Openwin,
5946 due to an apparent bug in XCloseIM.
5947 X11R6 seems not to have the bug. */
5948 XCloseIM (FRAME_XIM (f
));
5952 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
5953 #ifdef USE_X_TOOLKIT
5954 XtDestroyWidget (f
->output_data
.x
->widget
);
5955 free_frame_menubar (f
);
5956 #endif /* USE_X_TOOLKIT */
5958 free_frame_faces (f
);
5959 XFlush (FRAME_X_DISPLAY (f
));
5962 if (f
->output_data
.x
->saved_menu_event
)
5963 free (f
->output_data
.x
->saved_menu_event
);
5965 xfree (f
->output_data
.x
);
5966 f
->output_data
.x
= 0;
5967 if (f
== dpyinfo
->x_focus_frame
)
5968 dpyinfo
->x_focus_frame
= 0;
5969 if (f
== dpyinfo
->x_focus_event_frame
)
5970 dpyinfo
->x_focus_event_frame
= 0;
5971 if (f
== dpyinfo
->x_highlight_frame
)
5972 dpyinfo
->x_highlight_frame
= 0;
5974 dpyinfo
->reference_count
--;
5976 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5978 dpyinfo
->mouse_face_beg_row
5979 = dpyinfo
->mouse_face_beg_col
= -1;
5980 dpyinfo
->mouse_face_end_row
5981 = dpyinfo
->mouse_face_end_col
= -1;
5982 dpyinfo
->mouse_face_window
= Qnil
;
5988 /* Setting window manager hints. */
5990 /* Set the normal size hints for the window manager, for frame F.
5991 FLAGS is the flags word to use--or 0 meaning preserve the flags
5992 that the window now has.
5993 If USER_POSITION is nonzero, we set the USPosition
5994 flag (this is useful when FLAGS is 0). */
5996 x_wm_set_size_hint (f
, flags
, user_position
)
6001 XSizeHints size_hints
;
6003 #ifdef USE_X_TOOLKIT
6006 Dimension widget_width
, widget_height
;
6007 Window window
= XtWindow (f
->output_data
.x
->widget
);
6008 #else /* not USE_X_TOOLKIT */
6009 Window window
= FRAME_X_WINDOW (f
);
6010 #endif /* not USE_X_TOOLKIT */
6012 /* Setting PMaxSize caused various problems. */
6013 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
6015 flexlines
= f
->height
;
6017 size_hints
.x
= f
->output_data
.x
->left_pos
;
6018 size_hints
.y
= f
->output_data
.x
->top_pos
;
6020 #ifdef USE_X_TOOLKIT
6021 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
6022 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
6023 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
6024 size_hints
.height
= widget_height
;
6025 size_hints
.width
= widget_width
;
6026 #else /* not USE_X_TOOLKIT */
6027 size_hints
.height
= PIXEL_HEIGHT (f
);
6028 size_hints
.width
= PIXEL_WIDTH (f
);
6029 #endif /* not USE_X_TOOLKIT */
6031 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
6032 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
6033 size_hints
.max_width
6034 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
6035 size_hints
.max_height
6036 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
6038 /* Calculate the base and minimum sizes.
6040 (When we use the X toolkit, we don't do it here.
6041 Instead we copy the values that the widgets are using, below.) */
6042 #ifndef USE_X_TOOLKIT
6044 int base_width
, base_height
;
6045 int min_rows
= 0, min_cols
= 0;
6047 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
6048 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
6050 check_frame_size (f
, &min_rows
, &min_cols
);
6052 /* The window manager uses the base width hints to calculate the
6053 current number of rows and columns in the frame while
6054 resizing; min_width and min_height aren't useful for this
6055 purpose, since they might not give the dimensions for a
6056 zero-row, zero-column frame.
6058 We use the base_width and base_height members if we have
6059 them; otherwise, we set the min_width and min_height members
6060 to the size for a zero x zero frame. */
6063 size_hints
.flags
|= PBaseSize
;
6064 size_hints
.base_width
= base_width
;
6065 size_hints
.base_height
= base_height
;
6066 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
6067 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
6069 size_hints
.min_width
= base_width
;
6070 size_hints
.min_height
= base_height
;
6074 /* If we don't need the old flags, we don't need the old hint at all. */
6077 size_hints
.flags
|= flags
;
6080 #endif /* not USE_X_TOOLKIT */
6083 XSizeHints hints
; /* Sometimes I hate X Windows... */
6084 long supplied_return
;
6088 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
6091 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
6094 #ifdef USE_X_TOOLKIT
6095 size_hints
.base_height
= hints
.base_height
;
6096 size_hints
.base_width
= hints
.base_width
;
6097 size_hints
.min_height
= hints
.min_height
;
6098 size_hints
.min_width
= hints
.min_width
;
6102 size_hints
.flags
|= flags
;
6107 if (hints
.flags
& PSize
)
6108 size_hints
.flags
|= PSize
;
6109 if (hints
.flags
& PPosition
)
6110 size_hints
.flags
|= PPosition
;
6111 if (hints
.flags
& USPosition
)
6112 size_hints
.flags
|= USPosition
;
6113 if (hints
.flags
& USSize
)
6114 size_hints
.flags
|= USSize
;
6121 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
6122 size_hints
.flags
|= PWinGravity
;
6126 size_hints
.flags
&= ~ PPosition
;
6127 size_hints
.flags
|= USPosition
;
6129 #endif /* PWinGravity */
6132 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
6134 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
6138 /* Used for IconicState or NormalState */
6139 x_wm_set_window_state (f
, state
)
6143 #ifdef USE_X_TOOLKIT
6146 XtSetArg (al
[0], XtNinitialState
, state
);
6147 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6148 #else /* not USE_X_TOOLKIT */
6149 Window window
= FRAME_X_WINDOW (f
);
6151 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
6152 f
->output_data
.x
->wm_hints
.initial_state
= state
;
6154 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6155 #endif /* not USE_X_TOOLKIT */
6158 x_wm_set_icon_pixmap (f
, pixmap_id
)
6164 #ifdef USE_X_TOOLKIT
6165 Window window
= XtWindow (f
->output_data
.x
->widget
);
6167 Window window
= FRAME_X_WINDOW (f
);
6172 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
6173 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
6177 /* It seems there is no way to turn off use of an icon pixmap.
6178 The following line does it, only if no icon has yet been created,
6179 for some window managers. But with mwm it crashes.
6180 Some people say it should clear the IconPixmapHint bit in this case,
6181 but that doesn't work, and the X consortium said it isn't the
6182 right thing at all. Since there is no way to win,
6183 best to explicitly give up. */
6185 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
6191 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
6195 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
6196 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
6199 #else /* not USE_X_TOOLKIT */
6201 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
6202 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6204 #endif /* not USE_X_TOOLKIT */
6207 x_wm_set_icon_position (f
, icon_x
, icon_y
)
6211 #ifdef USE_X_TOOLKIT
6212 Window window
= XtWindow (f
->output_data
.x
->widget
);
6214 Window window
= FRAME_X_WINDOW (f
);
6217 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
6218 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
6219 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
6221 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
6225 /* Interface to fontset handler. */
6227 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
6229 x_get_font_info (f
, font_idx
)
6233 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
6237 /* Return a list of names of available fonts matching PATTERN on frame
6238 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
6239 to be listed. Frame F NULL means we have not yet created any
6240 frame on X, and consult the first display in x_display_list.
6241 MAXNAMES sets a limit on how many fonts to match. */
6244 x_list_fonts (f
, pattern
, size
, maxnames
)
6246 Lisp_Object pattern
;
6250 Lisp_Object list
, patterns
= Qnil
, newlist
= Qnil
, key
, tem
, second_best
;
6251 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
6253 for (list
= Valternative_fontname_alist
; CONSP (list
);
6254 list
= XCONS (list
)->cdr
)
6256 tem
= XCONS (list
)->car
;
6258 && STRINGP (XCONS (tem
)->car
)
6259 && !NILP (Fstring_equal (XCONS (tem
)->car
, pattern
)))
6261 patterns
= XCONS (tem
)->cdr
;
6266 for (patterns
= Fcons (pattern
, patterns
); CONSP (patterns
);
6267 patterns
= XCONS (patterns
)->cdr
, pattern
= XCONS (patterns
)->car
)
6272 /* See if we cached the result for this particular query. */
6273 if (f
&& (tem
= XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
,
6274 key
= Fcons (pattern
, make_number (maxnames
)),
6275 !NILP (list
= Fassoc (key
, tem
))))
6277 list
= Fcdr_safe (list
);
6278 /* We have a cashed list. Don't have to get the list again. */
6282 /* At first, put PATTERN in the cache. */
6284 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, maxnames
, &num_fonts
);
6291 /* Make a list of all the fonts we got back.
6292 Store that in the font cache for the display. */
6293 for (i
= 0; i
< num_fonts
; i
++)
6296 int average_width
= -1, dashes
= 0, width
= 0;
6298 /* Count the number of dashes in NAMES[I]. If there are
6299 14 dashes, and the field value following 12th dash
6300 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
6301 is usually too ugly to be used for editing. Let's
6307 if (dashes
== 7) /* PIXEL_SIZE field */
6309 else if (dashes
== 12) /* AVERAGE_WIDTH field */
6310 average_width
= atoi (p
);
6312 if (dashes
< 14 || average_width
!= 0)
6314 tem
= build_string (names
[i
]);
6315 if (NILP (Fassoc (tem
, list
)))
6317 if (STRINGP (Vx_pixel_size_width_font_regexp
)
6318 && (fast_string_match_ignore_case
6319 (Vx_pixel_size_width_font_regexp
, names
[i
])
6321 /* We can set the value of PIXEL_SIZE to the
6322 width of this font. */
6323 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
6325 /* For the moment, width is not known. */
6326 list
= Fcons (Fcons (tem
, Qnil
), list
);
6330 XFreeFontNames (names
);
6333 /* Now store the result in the cache. */
6335 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
6336 = Fcons (Fcons (key
, list
),
6337 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
);
6340 if (NILP (list
)) continue; /* Try the remaining alternatives. */
6342 newlist
= second_best
= Qnil
;
6343 /* Make a list of the fonts that have the right width. */
6344 for (; CONSP (list
); list
= XCONS (list
)->cdr
)
6346 tem
= XCONS (list
)->car
;
6348 if (!CONSP (tem
) || NILP (XCONS (tem
)->car
))
6352 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
6356 if (!INTEGERP (XCONS (tem
)->cdr
))
6358 /* Since we have not yet known the size of this font, we
6359 must try slow function call XLoadQueryFont. */
6360 XFontStruct
*thisinfo
;
6363 thisinfo
= XLoadQueryFont (dpy
,
6364 XSTRING (XCONS (tem
)->car
)->data
);
6369 XCONS (tem
)->cdr
= make_number (thisinfo
->max_bounds
.width
);
6370 XFreeFont (dpy
, thisinfo
);
6373 /* For unknown reason, the previous call of XListFont had
6374 retruned a font which can't be opened. Record the size
6375 as 0 not to try to open it again. */
6376 XCONS (tem
)->cdr
= make_number (0);
6378 if (XINT (XCONS (tem
)->cdr
) == size
)
6379 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
6380 else if (NILP (second_best
))
6382 else if (XINT (XCONS (tem
)->cdr
) < size
)
6384 if (XINT (XCONS (second_best
)->cdr
) > size
6385 || XINT (XCONS (second_best
)->cdr
) < XINT (XCONS (tem
)->cdr
))
6390 if (XINT (XCONS (second_best
)->cdr
) > size
6391 && XINT (XCONS (second_best
)->cdr
) > XINT (XCONS (tem
)->cdr
))
6395 if (!NILP (newlist
))
6397 else if (!NILP (second_best
))
6399 newlist
= Fcons (XCONS (second_best
)->car
, Qnil
);
6407 /* Load font named FONTNAME of the size SIZE for frame F, and return a
6408 pointer to the structure font_info while allocating it dynamically.
6409 If SIZE is 0, load any size of font.
6410 If loading is failed, return NULL. */
6413 x_load_font (f
, fontname
, size
)
6415 register char *fontname
;
6418 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6419 Lisp_Object font_names
;
6421 /* Get a list of all the fonts that match this name. Once we
6422 have a list of matching fonts, we compare them against the fonts
6423 we already have by comparing names. */
6424 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 256);
6426 if (!NILP (font_names
))
6431 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6432 for (tail
= font_names
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
6433 if (!strcmp (dpyinfo
->font_table
[i
].name
,
6434 XSTRING (XCONS (tail
)->car
)->data
)
6435 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
6436 XSTRING (XCONS (tail
)->car
)->data
))
6437 return (dpyinfo
->font_table
+ i
);
6440 /* Load the font and add it to the table. */
6444 struct font_info
*fontp
;
6445 unsigned long value
;
6447 if (!NILP (font_names
))
6448 fontname
= (char *) XSTRING (XCONS (font_names
)->car
)->data
;
6451 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
6456 /* Do we need to create the table? */
6457 if (dpyinfo
->font_table_size
== 0)
6459 dpyinfo
->font_table_size
= 16;
6461 = (struct font_info
*) xmalloc (dpyinfo
->font_table_size
6462 * sizeof (struct font_info
));
6464 /* Do we need to grow the table? */
6465 else if (dpyinfo
->n_fonts
6466 >= dpyinfo
->font_table_size
)
6468 dpyinfo
->font_table_size
*= 2;
6470 = (struct font_info
*) xrealloc (dpyinfo
->font_table
,
6471 (dpyinfo
->font_table_size
6472 * sizeof (struct font_info
)));
6475 fontp
= dpyinfo
->font_table
+ dpyinfo
->n_fonts
;
6477 /* Now fill in the slots of *FONTP. */
6480 fontp
->font_idx
= dpyinfo
->n_fonts
;
6481 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
6482 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
6484 /* Try to get the full name of FONT. Put it in FULL_NAME. */
6486 if (XGetFontProperty (font
, XA_FONT
, &value
))
6488 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
6492 /* Count the number of dashes in the "full name".
6493 If it is too few, this isn't really the font's full name,
6495 In X11R4, the fonts did not come with their canonical names
6506 full_name
= (char *) xmalloc (p
- name
+ 1);
6507 bcopy (name
, full_name
, p
- name
+ 1);
6514 fontp
->full_name
= full_name
;
6516 fontp
->full_name
= fontp
->name
;
6518 fontp
->size
= font
->max_bounds
.width
;
6519 fontp
->height
= font
->ascent
+ font
->descent
;
6521 /* The slot `encoding' specifies how to map a character
6522 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
6523 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
6524 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
6525 0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
6526 2:0xA020..0xFF7F). For the moment, we don't know which charset
6527 uses this font. So, we set informatoin in fontp->encoding[1]
6528 which is never used by any charset. If mapping can't be
6529 decided, set FONT_ENCODING_NOT_DECIDED. */
6531 = (font
->max_byte1
== 0
6533 ? (font
->min_char_or_byte2
< 0x80
6534 ? (font
->max_char_or_byte2
< 0x80
6535 ? 0 /* 0x20..0x7F */
6536 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
6537 : 1) /* 0xA0..0xFF */
6539 : (font
->min_byte1
< 0x80
6540 ? (font
->max_byte1
< 0x80
6541 ? (font
->min_char_or_byte2
< 0x80
6542 ? (font
->max_char_or_byte2
< 0x80
6543 ? 0 /* 0x2020..0x7F7F */
6544 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
6545 : 3) /* 0x20A0..0x7FFF */
6546 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
6547 : (font
->min_char_or_byte2
< 0x80
6548 ? (font
->max_char_or_byte2
< 0x80
6549 ? 2 /* 0xA020..0xFF7F */
6550 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
6551 : 1))); /* 0xA0A0..0xFFFF */
6553 fontp
->baseline_offset
6554 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
6555 ? (long) value
: 0);
6556 fontp
->relative_compose
6557 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
6558 ? (long) value
: 0);
6559 fontp
->default_ascent
6560 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
6561 ? (long) value
: 0);
6570 /* Return a pointer to struct font_info of a font named FONTNAME for frame F.
6571 If no such font is loaded, return NULL. */
6573 x_query_font (f
, fontname
)
6575 register char *fontname
;
6577 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6580 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
6581 if (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
6582 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
))
6583 return (dpyinfo
->font_table
+ i
);
6588 /* Initialization. */
6590 #ifdef USE_X_TOOLKIT
6591 static XrmOptionDescRec emacs_options
[] = {
6592 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
6593 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
6595 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
6596 XrmoptionSepArg
, NULL
},
6597 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
6599 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6600 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6601 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
6602 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
6603 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
6604 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
6605 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
6607 #endif /* USE_X_TOOLKIT */
6609 static int x_initialized
;
6612 /* Test whether two display-name strings agree up to the dot that separates
6613 the screen number from the server number. */
6615 same_x_server (name1
, name2
)
6616 char *name1
, *name2
;
6619 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
6623 if (seen_colon
&& *name1
== '.')
6627 && (*name1
== '.' || *name1
== '\0')
6628 && (*name2
== '.' || *name2
== '\0'));
6632 struct x_display_info
*
6633 x_term_init (display_name
, xrm_option
, resource_name
)
6634 Lisp_Object display_name
;
6636 char *resource_name
;
6642 struct x_display_info
*dpyinfo
;
6654 setlocale (LC_ALL
, "");
6655 /* In case we just overrode what init_lread did, redo it. */
6656 setlocale (LC_NUMERIC
, "C");
6657 setlocale (LC_TIME
, "C");
6660 #ifdef USE_X_TOOLKIT
6661 /* weiner@footloose.sps.mot.com reports that this causes
6663 X protocol error: BadAtom (invalid Atom parameter)
6664 on protocol request 18skiloaf.
6665 So let's not use it until R6. */
6667 XtSetLanguageProc (NULL
, NULL
, NULL
);
6678 argv
[argc
++] = "-xrm";
6679 argv
[argc
++] = xrm_option
;
6681 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
6682 resource_name
, EMACS_CLASS
,
6683 emacs_options
, XtNumber (emacs_options
),
6687 /* I think this is to compensate for XtSetLanguageProc. */
6688 setlocale (LC_NUMERIC
, "C");
6689 setlocale (LC_TIME
, "C");
6693 #else /* not USE_X_TOOLKIT */
6695 XSetLocaleModifiers ("");
6697 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
6698 #endif /* not USE_X_TOOLKIT */
6700 /* Detect failure. */
6707 /* We have definitely succeeded. Record the new connection. */
6709 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
6713 struct x_display_info
*share
;
6716 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
6717 share
= share
->next
, tail
= XCONS (tail
)->cdr
)
6718 if (same_x_server (XSTRING (XCONS (XCONS (tail
)->car
)->car
)->data
,
6719 XSTRING (display_name
)->data
))
6722 dpyinfo
->kboard
= share
->kboard
;
6725 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
6726 init_kboard (dpyinfo
->kboard
);
6727 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
6729 char *vendor
= ServerVendor (dpy
);
6730 dpyinfo
->kboard
->Vsystem_key_alist
6731 = call1 (Qvendor_specific_keysyms
,
6732 build_string (vendor
? vendor
: ""));
6735 dpyinfo
->kboard
->next_kboard
= all_kboards
;
6736 all_kboards
= dpyinfo
->kboard
;
6737 /* Don't let the initial kboard remain current longer than necessary.
6738 That would cause problems if a file loaded on startup tries to
6739 prompt in the minibuffer. */
6740 if (current_kboard
== initial_kboard
)
6741 current_kboard
= dpyinfo
->kboard
;
6743 dpyinfo
->kboard
->reference_count
++;
6747 /* Put this display on the chain. */
6748 dpyinfo
->next
= x_display_list
;
6749 x_display_list
= dpyinfo
;
6751 /* Put it on x_display_name_list as well, to keep them parallel. */
6752 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
6753 x_display_name_list
);
6754 dpyinfo
->name_list_element
= XCONS (x_display_name_list
)->car
;
6756 dpyinfo
->display
= dpy
;
6759 XSetAfterFunction (x_current_display
, x_trace_wire
);
6763 = (char *) xmalloc (XSTRING (Vinvocation_name
)->size
6764 + XSTRING (Vsystem_name
)->size
6766 sprintf (dpyinfo
->x_id_name
, "%s@%s",
6767 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
6769 /* Figure out which modifier bits mean what. */
6770 x_find_modifier_meanings (dpyinfo
);
6772 /* Get the scroll bar cursor. */
6773 dpyinfo
->vertical_scroll_bar_cursor
6774 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
6776 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
6777 resource_name
, EMACS_CLASS
);
6778 #ifdef HAVE_XRMSETDATABASE
6779 XrmSetDatabase (dpyinfo
->display
, xrdb
);
6781 dpyinfo
->display
->db
= xrdb
;
6783 /* Put the rdb where we can find it in a way that works on
6785 dpyinfo
->xrdb
= xrdb
;
6787 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
6788 DefaultScreen (dpyinfo
->display
));
6789 dpyinfo
->visual
= select_visual (dpyinfo
->display
, dpyinfo
->screen
,
6790 &dpyinfo
->n_planes
);
6791 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
6792 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
6793 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
6794 dpyinfo
->grabbed
= 0;
6795 dpyinfo
->reference_count
= 0;
6796 dpyinfo
->icon_bitmap_id
= -1;
6797 dpyinfo
->n_fonts
= 0;
6798 dpyinfo
->font_table_size
= 0;
6799 dpyinfo
->bitmaps
= 0;
6800 dpyinfo
->bitmaps_size
= 0;
6801 dpyinfo
->bitmaps_last
= 0;
6802 dpyinfo
->scratch_cursor_gc
= 0;
6803 dpyinfo
->mouse_face_mouse_frame
= 0;
6804 dpyinfo
->mouse_face_deferred_gc
= 0;
6805 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
6806 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
6807 dpyinfo
->mouse_face_face_id
= 0;
6808 dpyinfo
->mouse_face_window
= Qnil
;
6809 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
6810 dpyinfo
->mouse_face_defer
= 0;
6811 dpyinfo
->x_focus_frame
= 0;
6812 dpyinfo
->x_focus_event_frame
= 0;
6813 dpyinfo
->x_highlight_frame
= 0;
6815 dpyinfo
->Xatom_wm_protocols
6816 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
6817 dpyinfo
->Xatom_wm_take_focus
6818 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
6819 dpyinfo
->Xatom_wm_save_yourself
6820 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
6821 dpyinfo
->Xatom_wm_delete_window
6822 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
6823 dpyinfo
->Xatom_wm_change_state
6824 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
6825 dpyinfo
->Xatom_wm_configure_denied
6826 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
6827 dpyinfo
->Xatom_wm_window_moved
6828 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
6829 dpyinfo
->Xatom_editres
6830 = XInternAtom (dpyinfo
->display
, "Editres", False
);
6831 dpyinfo
->Xatom_CLIPBOARD
6832 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
6833 dpyinfo
->Xatom_TIMESTAMP
6834 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
6836 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
6837 dpyinfo
->Xatom_COMPOUND_TEXT
6838 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
6839 dpyinfo
->Xatom_DELETE
6840 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
6841 dpyinfo
->Xatom_MULTIPLE
6842 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
6844 = XInternAtom (dpyinfo
->display
, "INCR", False
);
6845 dpyinfo
->Xatom_EMACS_TMP
6846 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
6847 dpyinfo
->Xatom_TARGETS
6848 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
6850 = XInternAtom (dpyinfo
->display
, "NULL", False
);
6851 dpyinfo
->Xatom_ATOM_PAIR
6852 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
6853 /* For properties of font. */
6854 dpyinfo
->Xatom_PIXEL_SIZE
6855 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
6856 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
6857 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
6858 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
6859 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
6860 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
6861 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
6863 dpyinfo
->cut_buffers_initialized
= 0;
6865 connection
= ConnectionNumber (dpyinfo
->display
);
6866 dpyinfo
->connection
= connection
;
6869 char null_bits
[] = { 0x00 };
6872 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
6873 null_bits
, 1, 1, (long) 0, (long) 0,
6878 /* This is only needed for distinguishing keyboard and process input. */
6879 if (connection
!= 0)
6880 add_keyboard_wait_descriptor (connection
);
6883 #ifndef F_SETOWN_BUG
6885 #ifdef F_SETOWN_SOCK_NEG
6886 /* stdin is a socket here */
6887 fcntl (connection
, F_SETOWN
, -getpid ());
6888 #else /* ! defined (F_SETOWN_SOCK_NEG) */
6889 fcntl (connection
, F_SETOWN
, getpid ());
6890 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
6891 #endif /* ! defined (F_SETOWN) */
6892 #endif /* F_SETOWN_BUG */
6895 if (interrupt_input
)
6896 init_sigio (connection
);
6897 #endif /* ! defined (SIGIO) */
6900 /* Make sure that we have a valid font for dialog boxes
6901 so that Xt does not crash. */
6903 Display
*dpy
= dpyinfo
->display
;
6908 d
.addr
= (XPointer
)&dpy
;
6909 d
.size
= sizeof (Display
*);
6910 fr
.addr
= XtDefaultFont
;
6911 fr
.size
= sizeof (XtDefaultFont
);
6912 to
.size
= sizeof (Font
*);
6913 to
.addr
= (XPointer
)&font
;
6914 count
= x_catch_errors (dpy
);
6915 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
6917 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
6918 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
6919 x_uncatch_errors (dpy
, count
);
6929 /* Get rid of display DPYINFO, assuming all frames are already gone,
6930 and without sending any more commands to the X server. */
6933 x_delete_display (dpyinfo
)
6934 struct x_display_info
*dpyinfo
;
6936 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
6938 /* Discard this display from x_display_name_list and x_display_list.
6939 We can't use Fdelq because that can quit. */
6940 if (! NILP (x_display_name_list
)
6941 && EQ (XCONS (x_display_name_list
)->car
, dpyinfo
->name_list_element
))
6942 x_display_name_list
= XCONS (x_display_name_list
)->cdr
;
6947 tail
= x_display_name_list
;
6948 while (CONSP (tail
) && CONSP (XCONS (tail
)->cdr
))
6950 if (EQ (XCONS (XCONS (tail
)->cdr
)->car
,
6951 dpyinfo
->name_list_element
))
6953 XCONS (tail
)->cdr
= XCONS (XCONS (tail
)->cdr
)->cdr
;
6956 tail
= XCONS (tail
)->cdr
;
6960 if (x_display_list
== dpyinfo
)
6961 x_display_list
= dpyinfo
->next
;
6964 struct x_display_info
*tail
;
6966 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
6967 if (tail
->next
== dpyinfo
)
6968 tail
->next
= tail
->next
->next
;
6971 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
6972 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
6973 XrmDestroyDatabase (dpyinfo
->xrdb
);
6977 if (--dpyinfo
->kboard
->reference_count
== 0)
6978 delete_kboard (dpyinfo
->kboard
);
6980 xfree (dpyinfo
->font_table
);
6981 xfree (dpyinfo
->x_id_name
);
6985 /* Set up use of X before we make the first connection. */
6989 clear_frame_hook
= XTclear_frame
;
6990 clear_end_of_line_hook
= XTclear_end_of_line
;
6991 ins_del_lines_hook
= XTins_del_lines
;
6992 change_line_highlight_hook
= XTchange_line_highlight
;
6993 insert_glyphs_hook
= XTinsert_glyphs
;
6994 write_glyphs_hook
= XTwrite_glyphs
;
6995 delete_glyphs_hook
= XTdelete_glyphs
;
6996 ring_bell_hook
= XTring_bell
;
6997 reset_terminal_modes_hook
= XTreset_terminal_modes
;
6998 set_terminal_modes_hook
= XTset_terminal_modes
;
6999 update_begin_hook
= XTupdate_begin
;
7000 update_end_hook
= XTupdate_end
;
7001 set_terminal_window_hook
= XTset_terminal_window
;
7002 read_socket_hook
= XTread_socket
;
7003 frame_up_to_date_hook
= XTframe_up_to_date
;
7004 cursor_to_hook
= XTcursor_to
;
7005 reassert_line_highlight_hook
= XTreassert_line_highlight
;
7006 mouse_position_hook
= XTmouse_position
;
7007 frame_rehighlight_hook
= XTframe_rehighlight
;
7008 frame_raise_lower_hook
= XTframe_raise_lower
;
7009 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
7010 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
7011 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
7012 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
7014 scroll_region_ok
= 1; /* we'll scroll partial frames */
7015 char_ins_del_ok
= 0; /* just as fast to write the line */
7016 line_ins_del_ok
= 1; /* we'll just blt 'em */
7017 fast_clear_end_of_line
= 1; /* X does this well */
7018 memory_below_frame
= 0; /* we don't remember what scrolls
7024 /* Try to use interrupt input; if we can't, then start polling. */
7025 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
7027 #ifdef USE_X_TOOLKIT
7028 XtToolkitInitialize ();
7029 Xt_app_con
= XtCreateApplicationContext ();
7030 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
7033 /* Note that there is no real way portable across R3/R4 to get the
7034 original error handler. */
7035 XSetErrorHandler (x_error_handler
);
7036 XSetIOErrorHandler (x_io_error_quitter
);
7038 /* Disable Window Change signals; they are handled by X events. */
7040 signal (SIGWINCH
, SIG_DFL
);
7041 #endif /* ! defined (SIGWINCH) */
7043 signal (SIGPIPE
, x_connection_signal
);
7049 staticpro (&x_error_message_string
);
7050 x_error_message_string
= Qnil
;
7052 staticpro (&x_display_name_list
);
7053 x_display_name_list
= Qnil
;
7055 staticpro (&last_mouse_scroll_bar
);
7056 last_mouse_scroll_bar
= Qnil
;
7058 staticpro (&Qvendor_specific_keysyms
);
7059 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
7061 staticpro (&last_mouse_press_frame
);
7062 last_mouse_press_frame
= Qnil
;
7065 #endif /* not HAVE_X_WINDOWS */