1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Xt features made by Fred Pierresteguy. */
22 /* On 4.3 these lose if they come after xterm.h. */
23 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
24 /* Putting these at the beginning seems to be standard for other .c files. */
31 /* Need syssignal.h for various externs and definitions that may be required
32 by some configurations for calls to signal later in this source file. */
33 #include "syssignal.h"
38 #include "blockinput.h"
40 /* This may include sys/types.h, and that somehow loses
41 if this is not done before the other system files. */
43 #include <X11/cursorfont.h>
46 /* Load sys/types.h if not already loaded.
47 In some systems loading it twice is suicidal. */
49 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD) */
60 #ifndef INCLUDED_FCNTL
67 #include <sys/param.h>
69 #include "dispextern.h"
70 #include "termhooks.h"
83 #include "intervals.h"
86 extern XtAppContext Xt_app_con
;
87 extern Widget Xt_app_shell
;
88 extern void free_frame_menubar ();
89 extern void _XEditResCheckMessages ();
90 #endif /* USE_X_TOOLKIT */
93 #define x_any_window_to_frame x_window_to_frame
94 #define x_top_window_to_frame x_window_to_frame
98 #ifndef XtNinitialState
99 #define XtNinitialState "initialState"
103 #define XMapWindow XMapRaised /* Raise them when mapping. */
106 /* We could get this from param.h, but better not to depend on finding that.
107 And better not to risk that it might define other symbols used in this
110 #define MAXDESC FD_SETSIZE
114 #define SELECT_TYPE fd_set
115 #else /* no FD_SET */
117 #define SELECT_TYPE int
119 /* Define the macros to access a single-int bitmap of descriptors. */
120 #define FD_SET(n, p) (*(p) |= (1 << (n)))
121 #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
122 #define FD_ISSET(n, p) (*(p) & (1 << (n)))
123 #define FD_ZERO(p) (*(p) = 0)
124 #endif /* no FD_SET */
126 /* For sending Meta-characters. Do we need this? */
129 #define min(a,b) ((a)<(b) ? (a) : (b))
130 #define max(a,b) ((a)>(b) ? (a) : (b))
132 /* Nonzero means we must reprint all windows
133 because 1) we received an ExposeWindow event
134 or 2) we received too many ExposeRegion events to record.
136 This is never needed under X11. */
137 static int expose_all_windows
;
139 /* Nonzero means we must reprint all icon windows. */
141 static int expose_all_icons
;
143 #if defined (SIGIO) && defined (FIONREAD)
144 int BLOCK_INPUT_mask
;
145 #endif /* ! defined (SIGIO) && defined (FIONREAD) */
147 /* The id of a bitmap used for icon windows, in frames
148 for which no specific bitmap was specified.
149 This is 0 if we have not yet had a need to create the bitmap. */
151 static int icon_bitmap
;
153 /* Font used for text icons. */
155 static FONT_TYPE
*icon_font_info
;
157 /* Stuff for dealing with the main icon title. */
159 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
162 /* Initial values of argv and argc. */
163 extern char **initial_argv
;
164 extern int initial_argc
;
166 /* This is the X connection that we are using. */
168 Display
*x_current_display
;
170 /* The cursor to use for vertical scroll bars on x_current_display. */
171 static Cursor x_vertical_scroll_bar_cursor
;
173 /* Frame being updated by update_frame. This is declared in term.c.
174 This is set by update_begin and looked at by all the
175 XT functions. It is zero while not inside an update.
176 In that case, the XT functions assume that `selected_frame'
177 is the frame to apply to. */
178 extern struct frame
*updating_frame
;
180 /* The frame (if any) which has the X window that has keyboard focus.
181 Zero if none. This is examined by Ffocus_frame in frame.c. Note
182 that a mere EnterNotify event can set this; if you need to know the
183 last frame specified in a FocusIn or FocusOut event, use
184 x_focus_event_frame. */
185 struct frame
*x_focus_frame
;
187 /* This is a frame waiting to be autoraised, within XTread_socket. */
188 struct frame
*pending_autoraise_frame
;
190 /* The last frame mentioned in a FocusIn or FocusOut event. This is
191 separate from x_focus_frame, because whether or not LeaveNotify
192 events cause us to lose focus depends on whether or not we have
193 received a FocusIn event for it. */
194 struct frame
*x_focus_event_frame
;
196 /* The frame which currently has the visual highlight, and should get
197 keyboard input (other sorts of input have the frame encoded in the
198 event). It points to the X focus frame's selected window's
199 frame. It differs from x_focus_frame when we're using a global
201 static struct frame
*x_highlight_frame
;
203 /* From .Xdefaults, the value of "emacs.WarpMouse". If non-zero,
204 mouse is moved to inside of frame when frame is de-iconified. */
206 static int warp_mouse_on_deiconify
;
208 /* During an update, maximum vpos for ins/del line operations to affect. */
210 static int flexlines
;
212 /* During an update, nonzero if chars output now should be highlighted. */
214 static int highlight
;
216 /* Nominal cursor position -- where to draw output.
217 During an update, these are different from the cursor-box position. */
222 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
223 static GC scratch_cursor_gc
;
227 In order to avoid asking for motion events and then throwing most
228 of them away or busy-polling the server for mouse positions, we ask
229 the server for pointer motion hints. This means that we get only
230 one event per group of mouse movements. "Groups" are delimited by
231 other kinds of events (focus changes and button clicks, for
232 example), or by XQueryPointer calls; when one of these happens, we
233 get another MotionNotify event the next time the mouse moves. This
234 is at least as efficient as getting motion events when mouse
235 tracking is on, and I suspect only negligibly worse when tracking
238 The silly O'Reilly & Associates Nutshell guides barely document
239 pointer motion hints at all (I think you have to infer how they
240 work from an example), and the description of XQueryPointer doesn't
241 mention that calling it causes you to get another motion hint from
242 the server, which is very important. */
244 /* Where the mouse was last time we reported a mouse event. */
245 static FRAME_PTR last_mouse_frame
;
246 static XRectangle last_mouse_glyph
;
248 /* The scroll bar in which the last X motion event occurred.
250 If the last X motion event occurred in a scroll bar, we set this
251 so XTmouse_position can know whether to report a scroll bar motion or
254 If the last X motion event didn't occur in a scroll bar, we set this
255 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
256 static Lisp_Object last_mouse_scroll_bar
;
258 /* Record which buttons are currently pressed. */
259 unsigned int x_mouse_grabbed
;
261 /* This is a hack. We would really prefer that XTmouse_position would
262 return the time associated with the position it returns, but there
263 doesn't seem to be any way to wrest the timestamp from the server
264 along with the position query. So, we just keep track of the time
265 of the last movement we received, and return that in hopes that
266 it's somewhat accurate. */
267 static Time last_mouse_movement_time
;
269 /* These variables describe the range of text currently shown
270 in its mouse-face, together with the window they apply to.
271 As long as the mouse stays within this range, we need not
272 redraw anything on its account. */
273 static int mouse_face_beg_row
, mouse_face_beg_col
;
274 static int mouse_face_end_row
, mouse_face_end_col
;
275 static int mouse_face_past_end
;
276 static Lisp_Object mouse_face_window
;
277 static int mouse_face_face_id
;
279 /* 1 if a mouse motion event came and we didn't handle it right away because
280 gc was in progress. */
281 static int mouse_face_deferred_gc
;
283 /* FRAME and X, Y position of mouse when last checked for
284 highlighting. X and Y can be negative or out of range for the frame. */
285 static FRAME_PTR mouse_face_mouse_frame
;
286 static int mouse_face_mouse_x
, mouse_face_mouse_y
;
288 /* Nonzero means defer mouse-motion highlighting. */
289 static int mouse_face_defer
;
291 /* Incremented by XTread_socket whenever it really tries to read events. */
293 static int volatile input_signal_count
;
295 static int input_signal_count
;
298 /* `t' if a mouse button is depressed. */
300 extern Lisp_Object Vmouse_depressed
;
302 /* Tells if a window manager is present or not. */
304 extern Lisp_Object Vx_no_window_manager
;
306 /* Timestamp that we requested selection data was made. */
307 extern Time requestor_time
;
309 /* ID of the window requesting selection data. */
310 extern Window requestor_window
;
312 /* Nonzero enables some debugging for the X interface code. */
315 extern Lisp_Object Qface
, Qmouse_face
;
317 static int x_noop_count
;
320 /* From time to time we get info on an Emacs window, here. */
322 static WINDOWINFO_TYPE windowinfo
;
326 /* A mask of extra modifier bits to put into every keyboard char. */
327 extern int extra_keyboard_modifiers
;
329 extern Display
*XOpenDisplay ();
330 extern Window
XCreateWindow ();
332 extern Cursor
XCreateCursor ();
333 extern FONT_TYPE
*XOpenFont ();
335 static void flashback ();
336 static void redraw_previous_char ();
337 static void redraw_following_char ();
338 static unsigned int x_x_to_emacs_modifiers ();
340 static int fast_find_position ();
341 static void note_mouse_highlight ();
342 static void clear_mouse_face ();
343 static void show_mouse_face ();
344 static void do_line_dance ();
347 static int XTcursor_to ();
348 static int XTclear_end_of_line ();
351 /* Starting and ending updates.
353 These hooks are called by update_frame at the beginning and end
354 of a frame update. We record in `updating_frame' the identity
355 of the frame being updated, so that the XT... functions do not
356 need to take a frame as argument. Most of the XT... functions
357 should never be called except during an update, the only exceptions
358 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
360 extern int mouse_track_top
, mouse_track_left
, mouse_track_width
;
371 flexlines
= f
->height
;
376 if (f
== mouse_face_mouse_frame
)
378 /* Don't do highlighting for mouse motion during the update. */
379 mouse_face_defer
= 1;
380 if (!NILP (mouse_face_window
))
382 int firstline
, lastline
, i
;
383 struct window
*w
= XWINDOW (mouse_face_window
);
385 /* Find the first, and the last+1, lines affected by redisplay. */
386 for (firstline
= 0; firstline
< f
->height
; firstline
++)
387 if (FRAME_DESIRED_GLYPHS (f
)->enable
[firstline
])
390 lastline
= f
->height
;
391 for (i
= f
->height
- 1; i
>= 0; i
--)
393 if (FRAME_DESIRED_GLYPHS (f
)->enable
[i
])
399 /* Can we tell that this update does not affect the window
400 where the mouse highlight is? If so, no need to turn off. */
401 if (! (firstline
> (XFASTINT (w
->top
) + window_internal_height (w
))
402 || lastline
< XFASTINT (w
->top
)))
403 /* Otherwise turn off the mouse highlight now. */
420 x_display_cursor (f
, 1);
422 if (f
== mouse_face_mouse_frame
)
423 mouse_face_defer
= 0;
425 /* This fails in the case of having updated only the echo area
426 if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS
427 has no relation to the current contents, and its charstarts
428 have no relation to the contents of the window-buffer.
429 I don't know a clean way to check
430 for that case. window_end_valid isn't set up yet. */
431 if (f
== mouse_face_mouse_frame
)
432 note_mouse_highlight (f
, mouse_face_mouse_x
, mouse_face_mouse_y
);
439 /* This is called after a redisplay on frame F. */
442 XTframe_up_to_date (f
)
445 if (mouse_face_deferred_gc
|| f
== mouse_face_mouse_frame
)
447 note_mouse_highlight (mouse_face_mouse_frame
,
448 mouse_face_mouse_x
, mouse_face_mouse_y
);
449 mouse_face_deferred_gc
= 0;
453 /* External interface to control of standout mode.
454 Call this when about to modify line at position VPOS
455 and not change whether it is highlighted. */
457 XTreassert_line_highlight (new, vpos
)
463 /* Call this when about to modify line at position VPOS
464 and change whether it is highlighted. */
467 XTchange_line_highlight (new_highlight
, vpos
, first_unused_hpos
)
468 int new_highlight
, vpos
, first_unused_hpos
;
470 highlight
= new_highlight
;
471 XTcursor_to (vpos
, 0);
472 XTclear_end_of_line (updating_frame
->width
);
475 /* This is used when starting Emacs and when restarting after suspend.
476 When starting Emacs, no X window is mapped. And nothing must be done
477 to Emacs's own window if it is suspended (though that rarely happens). */
480 XTset_terminal_modes ()
484 /* This is called when exiting or suspending Emacs.
485 Exiting will make the X-windows go away, and suspending
486 requires no action. */
489 XTreset_terminal_modes ()
491 /* XTclear_frame (); */
494 /* Set the nominal cursor position of the frame.
495 This is where display update commands will take effect.
496 This does not affect the place where the cursor-box is displayed. */
499 XTcursor_to (row
, col
)
500 register int row
, col
;
508 if (updating_frame
== 0)
511 x_display_cursor (selected_frame
, 1);
517 /* Display a sequence of N glyphs found at GP.
518 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
519 HL is 1 if this text is highlighted, 2 if the cursor is on it,
520 3 if should appear in its mouse-face.
521 JUST_FOREGROUND if 1 means draw only the foreground;
522 don't alter the background.
524 FONT is the default font to use (for glyphs whose font-code is 0).
526 Since the display generation code is responsible for calling
527 compute_char_face and compute_glyph_face on everything it puts in
528 the display structure, we can assume that the face code on each
529 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
530 to which we can actually apply intern_face.
531 Call this function with input blocked. */
534 /* This is the multi-face code. */
537 dumpglyphs (f
, left
, top
, gp
, n
, hl
, just_foreground
)
540 register GLYPH
*gp
; /* Points to first GLYPH. */
541 register int n
; /* Number of glyphs to display. */
545 /* Holds characters to be displayed. */
546 char *buf
= (char *) alloca (f
->width
* sizeof (*buf
));
547 register char *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
;
555 /* Get the face-code of the next GLYPH. */
559 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
560 cf
= FAST_GLYPH_FACE (g
);
562 /* Find the run of consecutive glyphs with the same face-code.
563 Extract their character codes into BUF. */
568 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
569 if (FAST_GLYPH_FACE (g
) != cf
)
572 *cp
++ = FAST_GLYPH_CHAR (g
);
577 /* LEN gets the length of the run. */
580 /* Now output this run of chars, with the font and pixel values
581 determined by the face code CF. */
583 struct face
*face
= FRAME_DEFAULT_FACE (f
);
584 FONT_TYPE
*font
= FACE_FONT (face
);
585 GC gc
= FACE_GC (face
);
588 /* HL = 3 means use a mouse face previously chosen. */
590 cf
= mouse_face_face_id
;
592 /* First look at the face of the text itself. */
595 /* It's possible for the display table to specify
596 a face code that is out of range. Use 0 in that case. */
597 if (cf
< 0 || cf
>= FRAME_N_COMPUTED_FACES (f
)
598 || FRAME_COMPUTED_FACES (f
) [cf
] == 0)
602 face
= FRAME_MODE_LINE_FACE (f
);
604 face
= intern_face (f
, FRAME_COMPUTED_FACES (f
) [cf
]);
605 font
= FACE_FONT (face
);
607 if (FACE_STIPPLE (face
))
611 /* Then comes the distinction between modeline and normal text. */
616 face
= FRAME_MODE_LINE_FACE (f
);
617 font
= FACE_FONT (face
);
619 if (FACE_STIPPLE (face
))
623 #define FACE_DEFAULT (~0)
625 /* Now override that if the cursor's on this character. */
628 /* The cursor overrides stippling. */
632 || (int) face
->font
== FACE_DEFAULT
633 || face
->font
== f
->display
.x
->font
)
634 && face
->background
== f
->display
.x
->background_pixel
635 && face
->foreground
== f
->display
.x
->foreground_pixel
)
637 gc
= f
->display
.x
->cursor_gc
;
639 /* Cursor on non-default face: must merge. */
645 xgcv
.background
= f
->display
.x
->cursor_pixel
;
646 xgcv
.foreground
= face
->background
;
647 /* If the glyph would be invisible,
648 try a different foreground. */
649 if (xgcv
.foreground
== xgcv
.background
)
650 xgcv
.foreground
= face
->foreground
;
651 if (xgcv
.foreground
== xgcv
.background
)
652 xgcv
.foreground
= f
->display
.x
->cursor_foreground_pixel
;
653 if (xgcv
.foreground
== xgcv
.background
)
654 xgcv
.foreground
= face
->foreground
;
655 /* Make sure the cursor is distinct from text in this face. */
656 if (xgcv
.background
== face
->background
657 && xgcv
.foreground
== face
->foreground
)
659 xgcv
.background
= face
->foreground
;
660 xgcv
.foreground
= face
->background
;
662 xgcv
.font
= face
->font
->fid
;
663 xgcv
.graphics_exposures
= 0;
664 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
665 if (scratch_cursor_gc
)
666 XChangeGC (x_current_display
, scratch_cursor_gc
, mask
, &xgcv
);
669 = XCreateGC (x_current_display
, window
, mask
, &xgcv
);
670 gc
= scratch_cursor_gc
;
672 /* If this code is restored, it must also reset to the default stipple
674 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
675 XSetStipple (x_current_display
, gc
, face
->stipple
);
680 if ((int) font
== FACE_DEFAULT
)
681 font
= f
->display
.x
->font
;
684 XDrawString (x_current_display
, window
, gc
,
685 left
, top
+ FONT_BASE (font
), buf
, len
);
690 /* Turn stipple on. */
691 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillOpaqueStippled
);
693 /* Draw stipple on background. */
694 XFillRectangle (x_current_display
, window
, gc
,
696 FONT_WIDTH (font
) * len
,
699 /* Turn stipple off. */
700 XSetFillStyle (FRAME_X_DISPLAY (f
), gc
, FillSolid
);
702 /* Draw the text, solidly, onto the stipple pattern. */
703 XDrawString (x_current_display
, window
, gc
,
704 left
, top
+ FONT_BASE (font
), buf
, len
);
707 XDrawImageString (x_current_display
, window
, gc
,
708 left
, top
+ FONT_BASE (font
), buf
, len
);
710 /* Clear the rest of the line's height. */
711 if (f
->display
.x
->line_height
!= FONT_HEIGHT (font
))
712 XClearArea (x_current_display
, window
, left
,
713 top
+ FONT_HEIGHT (font
),
714 FONT_WIDTH (font
) * len
,
715 /* This is how many pixels of height
717 f
->display
.x
->line_height
- FONT_HEIGHT (font
),
721 #if 0 /* Doesn't work, because it uses FRAME_CURRENT_GLYPHS,
722 which often is not up to date yet. */
723 if (!just_foreground
)
725 if (left
== orig_left
)
726 redraw_previous_char (f
, PIXEL_TO_CHAR_COL (f
, left
),
727 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
729 redraw_following_char (f
, PIXEL_TO_CHAR_COL (f
, left
+ len
* FONT_WIDTH (font
)),
730 PIXEL_TO_CHAR_ROW (f
, top
), hl
== 1);
734 /* We should probably check for XA_UNDERLINE_POSITION and
735 XA_UNDERLINE_THICKNESS properties on the font, but let's
736 just get the thing working, and come back to that. */
738 int underline_position
= 1;
740 if (font
->descent
<= underline_position
)
741 underline_position
= font
->descent
- 1;
744 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
),
748 + underline_position
),
749 len
* FONT_WIDTH (font
), 1);
752 left
+= len
* FONT_WIDTH (font
);
759 /* This is the old single-face code. */
762 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
765 register GLYPH
*gp
; /* Points to first GLYPH. */
766 register int n
; /* Number of glyphs to display. */
771 Window window
= FRAME_X_WINDOW (f
);
772 GC drawing_gc
= (hl
== 2 ? f
->display
.x
->cursor_gc
773 : (hl
? f
->display
.x
->reverse_gc
774 : f
->display
.x
->normal_gc
));
776 if (sizeof (GLYPH
) == sizeof (XChar2b
))
777 XDrawImageString16 (x_current_display
, window
, drawing_gc
,
778 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
779 else if (sizeof (GLYPH
) == sizeof (unsigned char))
780 XDrawImageString (x_current_display
, window
, drawing_gc
,
781 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
783 /* What size of glyph ARE you using? And does X have a function to
789 /* Output some text at the nominal frame cursor position.
790 Advance the cursor over the text.
791 Output LEN glyphs at START.
793 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
794 controls the pixel values used for foreground and background. */
797 XTwrite_glyphs (start
, len
)
798 register GLYPH
*start
;
801 register int temp_length
;
812 /* If not within an update,
813 output at the frame's visible cursor. */
814 curs_x
= f
->cursor_x
;
815 curs_y
= f
->cursor_y
;
819 CHAR_TO_PIXEL_COL (f
, curs_x
),
820 CHAR_TO_PIXEL_ROW (f
, curs_y
),
821 start
, len
, highlight
, 0);
823 /* If we drew on top of the cursor, note that it is turned off. */
824 if (curs_y
== f
->phys_cursor_y
825 && curs_x
<= f
->phys_cursor_x
826 && curs_x
+ len
> f
->phys_cursor_x
)
827 f
->phys_cursor_x
= -1;
829 if (updating_frame
== 0)
832 x_display_cursor (f
, 1);
841 /* Clear to the end of the line.
842 Erase the current text line from the nominal cursor position (inclusive)
843 to column FIRST_UNUSED (exclusive). The idea is that everything
844 from FIRST_UNUSED onward is already erased. */
847 XTclear_end_of_line (first_unused
)
848 register int first_unused
;
850 struct frame
*f
= updating_frame
;
856 if (curs_y
< 0 || curs_y
>= f
->height
)
858 if (first_unused
<= 0)
861 if (first_unused
>= f
->width
)
862 first_unused
= f
->width
;
866 /* Notice if the cursor will be cleared by this operation. */
867 if (curs_y
== f
->phys_cursor_y
868 && curs_x
<= f
->phys_cursor_x
869 && f
->phys_cursor_x
< first_unused
)
870 f
->phys_cursor_x
= -1;
872 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
873 CHAR_TO_PIXEL_COL (f
, curs_x
),
874 CHAR_TO_PIXEL_ROW (f
, curs_y
),
875 FONT_WIDTH (f
->display
.x
->font
) * (first_unused
- curs_x
),
876 f
->display
.x
->line_height
, False
);
878 redraw_previous_char (f
, curs_x
, curs_y
, highlight
);
888 struct frame
*f
= updating_frame
;
893 f
->phys_cursor_x
= -1; /* Cursor not visible. */
894 curs_x
= 0; /* Nominal cursor position is top left. */
899 XClear (FRAME_X_WINDOW (f
));
901 /* We have to clear the scroll bars, too. If we have changed
902 colors or something like that, then they should be notified. */
903 x_scroll_bar_clear (f
);
910 /* This currently does not work because FRAME_CURRENT_GLYPHS doesn't
911 always contain the right glyphs to use.
913 It also needs to be changed to look at the details of the font and
914 see whether there is really overlap, and do nothing when there is
915 not. This can use font_char_overlap_left and font_char_overlap_right,
916 but just how to use them is not clear. */
918 /* Erase the character (if any) at the position just before X, Y in frame F,
919 then redraw it and the character before it.
920 This is necessary when we erase starting at X,
921 in case the character after X overlaps into the one before X.
922 Call this function with input blocked. */
925 redraw_previous_char (f
, x
, y
, highlight_flag
)
930 /* Erase the character before the new ones, in case
931 what was here before overlaps it.
932 Reoutput that character, and the previous character
933 (in case the previous character overlaps it). */
939 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
940 CHAR_TO_PIXEL_COL (f
, x
- 1),
941 CHAR_TO_PIXEL_ROW (f
, y
),
942 FONT_WIDTH (f
->display
.x
->font
),
943 f
->display
.x
->line_height
, False
);
945 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
946 CHAR_TO_PIXEL_ROW (f
, y
),
947 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
948 x
- start_x
, highlight_flag
, 1);
952 /* Erase the character (if any) at the position X, Y in frame F,
953 then redraw it and the character after it.
954 This is necessary when we erase endng at X,
955 in case the character after X overlaps into the one before X.
956 Call this function with input blocked. */
959 redraw_following_char (f
, x
, y
, highlight_flag
)
964 int limit
= FRAME_CURRENT_GLYPHS (f
)->used
[y
];
965 /* Erase the character after the new ones, in case
966 what was here before overlaps it.
967 Reoutput that character, and the following character
968 (in case the following character overlaps it). */
970 && FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
] != SPACEGLYPH
)
975 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
976 CHAR_TO_PIXEL_COL (f
, x
),
977 CHAR_TO_PIXEL_ROW (f
, y
),
978 FONT_WIDTH (f
->display
.x
->font
),
979 f
->display
.x
->line_height
, False
);
981 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, x
),
982 CHAR_TO_PIXEL_ROW (f
, y
),
983 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][x
],
984 end_x
- x
, highlight_flag
, 1);
989 #if 0 /* Not in use yet */
991 /* Return 1 if character C in font F extends past its left edge. */
994 font_char_overlap_left (font
, c
)
1000 /* Find the bounding-box info for C. */
1001 if (font
->per_char
== 0)
1002 s
= &font
->max_bounds
;
1005 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1008 /* Decode char into row number (byte 1) and code within row (byte 2). */
1011 if (!(within
>= font
->min_char_or_byte2
1012 && within
<= font
->max_char_or_byte2
1013 && row
>= font
->min_byte1
1014 && row
<= font
->max_byte1
))
1016 /* If char is out of range, try the font's default char instead. */
1017 c
= font
->default_char
;
1018 row
= c
>> (INTBITS
- 8);
1021 if (!(within
>= font
->min_char_or_byte2
1022 && within
<= font
->max_char_or_byte2
1023 && row
>= font
->min_byte1
1024 && row
<= font
->max_byte1
))
1025 /* Still out of range means this char does not overlap. */
1028 /* We found the info for this char. */
1029 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1033 return (s
&& s
->lbearing
< 0);
1036 /* Return 1 if character C in font F extends past its right edge. */
1039 font_char_overlap_right (font
, c
)
1045 /* Find the bounding-box info for C. */
1046 if (font
->per_char
== 0)
1047 s
= &font
->max_bounds
;
1050 int rowlen
= font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1;
1053 /* Decode char into row number (byte 1) and code within row (byte 2). */
1056 if (!(within
>= font
->min_char_or_byte2
1057 && within
<= font
->max_char_or_byte2
1058 && row
>= font
->min_byte1
1059 && row
<= font
->max_byte1
))
1061 /* If char is out of range, try the font's default char instead. */
1062 c
= font
->default_char
;
1063 row
= c
>> (INTBITS
- 8);
1066 if (!(within
>= font
->min_char_or_byte2
1067 && within
<= font
->max_char_or_byte2
1068 && row
>= font
->min_byte1
1069 && row
<= font
->max_byte1
))
1070 /* Still out of range means this char does not overlap. */
1073 /* We found the info for this char. */
1074 s
= (font
->per_char
+ (within
- font
->min_char_or_byte2
)
1078 return (s
&& s
->rbearing
>= s
->width
);
1082 /* Invert the middle quarter of the frame for .15 sec. */
1084 /* We use the select system call to do the waiting, so we have to make sure
1085 it's available. If it isn't, we just won't do visual bells. */
1086 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1088 /* Subtract the `struct timeval' values X and Y,
1089 storing the result in RESULT.
1090 Return 1 if the difference is negative, otherwise 0. */
1093 timeval_subtract (result
, x
, y
)
1094 struct timeval
*result
, x
, y
;
1096 /* Perform the carry for the later subtraction by updating y.
1097 This is safer because on some systems
1098 the tv_sec member is unsigned. */
1099 if (x
.tv_usec
< y
.tv_usec
)
1101 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
1102 y
.tv_usec
-= 1000000 * nsec
;
1105 if (x
.tv_usec
- y
.tv_usec
> 1000000)
1107 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
1108 y
.tv_usec
+= 1000000 * nsec
;
1112 /* Compute the time remaining to wait. tv_usec is certainly positive. */
1113 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
1114 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
1116 /* Return indication of whether the result should be considered negative. */
1117 return x
.tv_sec
< y
.tv_sec
;
1128 /* Create a GC that will use the GXxor function to flip foreground pixels
1129 into background pixels. */
1133 values
.function
= GXxor
;
1134 values
.foreground
= (f
->display
.x
->foreground_pixel
1135 ^ f
->display
.x
->background_pixel
);
1137 gc
= XCreateGC (x_current_display
, FRAME_X_WINDOW (f
),
1138 GCFunction
| GCForeground
, &values
);
1142 int width
= PIXEL_WIDTH (f
);
1143 int height
= PIXEL_HEIGHT (f
);
1145 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
), gc
,
1146 width
/4, height
/4, width
/2, height
/2);
1147 XFlush (x_current_display
);
1150 struct timeval wakeup
, now
;
1152 EMACS_GET_TIME (wakeup
);
1154 /* Compute time to wait until, propagating carry from usecs. */
1155 wakeup
.tv_usec
+= 150000;
1156 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
1157 wakeup
.tv_usec
%= 1000000;
1159 /* Keep waiting until past the time wakeup. */
1162 struct timeval timeout
;
1164 EMACS_GET_TIME (timeout
);
1166 /* In effect, timeout = wakeup - timeout.
1167 Break if result would be negative. */
1168 if (timeval_subtract (&timeout
, wakeup
, timeout
))
1171 /* Try to wait that long--but we might wake up sooner. */
1172 select (0, 0, 0, 0, &timeout
);
1176 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
), gc
,
1177 width
/4, height
/4, width
/2, height
/2);
1178 XFreeGC (x_current_display
, gc
);
1179 XFlush (x_current_display
);
1189 /* Make audible bell. */
1191 #define XRINGBELL XBell (x_current_display, 0)
1195 if (x_current_display
== 0)
1198 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1200 XTflash (selected_frame
);
1211 /* Insert and delete character.
1212 These are not supposed to be used because we are supposed to turn
1213 off the feature of using them. */
1216 XTinsert_glyphs (start
, len
)
1217 register char *start
;
1230 /* Specify how many text lines, from the top of the window,
1231 should be affected by insert-lines and delete-lines operations.
1232 This, and those operations, are used only within an update
1233 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1236 XTset_terminal_window (n
)
1239 if (updating_frame
== 0)
1242 if ((n
<= 0) || (n
> updating_frame
->height
))
1243 flexlines
= updating_frame
->height
;
1248 /* Array of line numbers from cached insert/delete operations.
1249 line_dance[i] is the old position of the line that we want
1250 to move to line i, or -1 if we want a blank line there. */
1251 static int *line_dance
;
1253 /* Allocated length of that array. */
1254 static int line_dance_len
;
1256 /* Flag indicating whether we've done any work. */
1257 static int line_dance_in_progress
;
1259 /* Perform an insert-lines or delete-lines operation,
1260 inserting N lines or deleting -N lines at vertical position VPOS. */
1261 XTins_del_lines (vpos
, n
)
1264 register int fence
, i
;
1266 if (vpos
>= flexlines
)
1269 if (!line_dance_in_progress
)
1271 int ht
= updating_frame
->height
;
1272 if (ht
> line_dance_len
)
1274 line_dance
= (int *)xrealloc (line_dance
, ht
* sizeof (int));
1275 line_dance_len
= ht
;
1277 for (i
= 0; i
< ht
; ++i
) line_dance
[i
] = i
;
1278 line_dance_in_progress
= 1;
1282 if (n
> flexlines
- vpos
)
1283 n
= flexlines
- vpos
;
1285 for (i
= flexlines
; --i
>= fence
;)
1286 line_dance
[i
] = line_dance
[i
-n
];
1287 for (i
= fence
; --i
>= vpos
;)
1293 if (n
> flexlines
- vpos
)
1294 n
= flexlines
- vpos
;
1295 fence
= flexlines
- n
;
1296 for (i
= vpos
; i
< fence
; ++i
)
1297 line_dance
[i
] = line_dance
[i
+ n
];
1298 for (i
= fence
; i
< flexlines
; ++i
)
1303 /* Here's where we actually move the pixels around.
1304 Must be called with input blocked. */
1308 register int i
, j
, distance
;
1309 register struct frame
*f
;
1313 /* Must check this flag first. If it's not set, then not only is the
1314 array uninitialized, but we might not even have a frame. */
1315 if (!line_dance_in_progress
)
1323 intborder
= f
->display
.x
->internal_border_width
;
1325 x_display_cursor (updating_frame
, 0);
1327 for (i
= 0; i
< ht
; ++i
)
1328 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) > 0)
1330 for (j
= i
; (j
< ht
&& line_dance
[j
] != -1
1331 && line_dance
[j
]-j
== distance
); ++j
);
1332 /* Copy [i,j) upward from [i+distance,j+distance) */
1333 XCopyArea (x_current_display
, FRAME_X_WINDOW (f
),
1334 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1335 intborder
, CHAR_TO_PIXEL_ROW (f
, i
+distance
),
1336 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1337 (j
-i
) * f
->display
.x
->line_height
,
1338 intborder
, CHAR_TO_PIXEL_ROW (f
, i
));
1342 for (i
= ht
; --i
>=0; )
1343 if (line_dance
[i
] != -1 && (distance
= line_dance
[i
]-i
) < 0)
1345 for (j
= i
; (--j
>= 0 && line_dance
[j
] != -1
1346 && line_dance
[j
]-j
== distance
); --j
);
1347 /* Copy (j,i] downward from (j+distance, i+distance] */
1348 XCopyArea (x_current_display
, FRAME_X_WINDOW (f
),
1349 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1350 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1+distance
),
1351 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1352 (i
-j
) * f
->display
.x
->line_height
,
1353 intborder
, CHAR_TO_PIXEL_ROW (f
, j
+1));
1357 for (i
= 0; i
< ht
; ++i
)
1358 if (line_dance
[i
] == -1)
1360 for (j
= i
; j
< ht
&& line_dance
[j
] == -1; ++j
);
1362 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
1363 intborder
, CHAR_TO_PIXEL_ROW (f
, i
),
1364 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1365 (j
-i
) * f
->display
.x
->line_height
, False
);
1368 line_dance_in_progress
= 0;
1371 /* Support routines for exposure events. */
1372 static void clear_cursor ();
1374 /* Output into a rectangle of an X-window (for frame F)
1375 the characters in f->phys_lines that overlap that rectangle.
1376 TOP and LEFT are the position of the upper left corner of the rectangle.
1377 ROWS and COLS are the size of the rectangle.
1378 Call this function with input blocked. */
1381 dumprectangle (f
, left
, top
, cols
, rows
)
1383 register int left
, top
, cols
, rows
;
1385 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1386 int cursor_cleared
= 0;
1390 if (FRAME_GARBAGED_P (f
))
1393 /* Express rectangle as four edges, instead of position-and-size. */
1394 bottom
= top
+ rows
;
1395 right
= left
+ cols
;
1397 /* Convert rectangle edges in pixels to edges in chars.
1398 Round down for left and top, up for right and bottom. */
1399 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1400 left
= PIXEL_TO_CHAR_COL (f
, left
);
1401 bottom
+= (f
->display
.x
->line_height
- 1);
1402 right
+= (FONT_WIDTH (f
->display
.x
->font
) - 1);
1403 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1404 right
= PIXEL_TO_CHAR_COL (f
, right
);
1406 /* Clip the rectangle to what can be visible. */
1411 if (right
> f
->width
)
1413 if (bottom
> f
->height
)
1416 /* Get size in chars of the rectangle. */
1417 cols
= right
- left
;
1418 rows
= bottom
- top
;
1420 /* If rectangle has zero area, return. */
1421 if (rows
<= 0) return;
1422 if (cols
<= 0) return;
1424 /* Turn off the cursor if it is in the rectangle.
1425 We will turn it back on afterward. */
1426 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1427 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1433 /* Display the text in the rectangle, one text line at a time. */
1435 for (y
= top
; y
< bottom
; y
++)
1437 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1439 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1443 CHAR_TO_PIXEL_COL (f
, left
),
1444 CHAR_TO_PIXEL_ROW (f
, y
),
1445 line
, min (cols
, active_frame
->used
[y
] - left
),
1446 active_frame
->highlight
[y
], 0);
1449 /* Turn the cursor on if we turned it off. */
1452 x_display_cursor (f
, 1);
1456 frame_highlight (frame
)
1457 struct frame
*frame
;
1459 /* We used to only do this if Vx_no_window_manager was non-nil, but
1460 the ICCCM (section 4.1.6) says that the window's border pixmap
1461 and border pixel are window attributes which are "private to the
1462 client", so we can always change it to whatever we want. */
1464 XSetWindowBorder (x_current_display
, FRAME_X_WINDOW (frame
),
1465 frame
->display
.x
->border_pixel
);
1467 x_display_cursor (frame
, 1);
1471 frame_unhighlight (frame
)
1472 struct frame
*frame
;
1474 /* We used to only do this if Vx_no_window_manager was non-nil, but
1475 the ICCCM (section 4.1.6) says that the window's border pixmap
1476 and border pixel are window attributes which are "private to the
1477 client", so we can always change it to whatever we want. */
1479 XSetWindowBorderPixmap (x_current_display
, FRAME_X_WINDOW (frame
),
1480 frame
->display
.x
->border_tile
);
1482 x_display_cursor (frame
, 1);
1485 static void XTframe_rehighlight ();
1487 /* The focus has changed. Update the frames as necessary to reflect
1488 the new situation. Note that we can't change the selected frame
1489 here, because the lisp code we are interrupting might become confused.
1490 Each event gets marked with the frame in which it occurred, so the
1491 lisp code can tell when the switch took place by examining the events. */
1494 x_new_focus_frame (frame
)
1495 struct frame
*frame
;
1497 struct frame
*old_focus
= x_focus_frame
;
1498 int events_enqueued
= 0;
1500 if (frame
!= x_focus_frame
)
1502 /* Set this before calling other routines, so that they see
1503 the correct value of x_focus_frame. */
1504 x_focus_frame
= frame
;
1506 if (old_focus
&& old_focus
->auto_lower
)
1507 x_lower_frame (old_focus
);
1510 selected_frame
= frame
;
1511 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
1513 Fselect_window (selected_frame
->selected_window
);
1514 choose_minibuf_frame ();
1517 if (x_focus_frame
&& x_focus_frame
->auto_raise
)
1518 pending_autoraise_frame
= x_focus_frame
;
1520 pending_autoraise_frame
= 0;
1523 XTframe_rehighlight ();
1527 /* The focus has changed, or we have redirected a frame's focus to
1528 another frame (this happens when a frame uses a surrogate
1529 minibuffer frame). Shift the highlight as appropriate. */
1531 XTframe_rehighlight ()
1533 struct frame
*old_highlight
= x_highlight_frame
;
1538 ((XGCTYPE (FRAME_FOCUS_FRAME (x_focus_frame
)) == Lisp_Frame
)
1539 ? XFRAME (FRAME_FOCUS_FRAME (x_focus_frame
))
1541 if (! FRAME_LIVE_P (x_highlight_frame
))
1543 FRAME_FOCUS_FRAME (x_focus_frame
) = Qnil
;
1544 x_highlight_frame
= x_focus_frame
;
1548 x_highlight_frame
= 0;
1550 if (x_highlight_frame
!= old_highlight
)
1553 frame_unhighlight (old_highlight
);
1554 if (x_highlight_frame
)
1555 frame_highlight (x_highlight_frame
);
1559 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1561 /* Which modifier keys are on which modifier bits?
1563 With each keystroke, X returns eight bits indicating which modifier
1564 keys were held down when the key was pressed. The interpretation
1565 of the top five modifier bits depends on what keys are attached
1566 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
1569 x_meta_mod_mask is a mask containing the bits used for the meta key.
1570 It may have more than one bit set, if more than one modifier bit
1571 has meta keys on it. Basically, if EVENT is a KeyPress event,
1572 the meta key is pressed if (EVENT.state & x_meta_mod_mask) != 0.
1574 x_shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
1575 lock modifier bit, or zero otherwise. Non-alphabetic keys should
1576 only be affected by the lock modifier bit if XK_Shift_Lock is in
1577 use; XK_Caps_Lock should only affect alphabetic keys. With this
1578 arrangement, the lock modifier should shift the character if
1579 (EVENT.state & x_shift_lock_mask) != 0. */
1580 static int x_meta_mod_mask
, x_shift_lock_mask
;
1582 /* These are like x_meta_mod_mask, but for different modifiers. */
1583 static int x_alt_mod_mask
, x_super_mod_mask
, x_hyper_mod_mask
;
1585 /* Initialize mode_switch_bit and modifier_meaning. */
1587 x_find_modifier_meanings ()
1589 int min_code
, max_code
;
1592 XModifierKeymap
*mods
;
1594 x_meta_mod_mask
= 0;
1595 x_shift_lock_mask
= 0;
1597 x_super_mod_mask
= 0;
1598 x_hyper_mod_mask
= 0;
1601 XDisplayKeycodes (x_current_display
, &min_code
, &max_code
);
1603 min_code
= x_current_display
->min_keycode
;
1604 max_code
= x_current_display
->max_keycode
;
1607 syms
= XGetKeyboardMapping (x_current_display
,
1608 min_code
, max_code
- min_code
+ 1,
1610 mods
= XGetModifierMapping (x_current_display
);
1612 /* Scan the modifier table to see which modifier bits the Meta and
1613 Alt keysyms are on. */
1615 int row
, col
; /* The row and column in the modifier table. */
1617 for (row
= 3; row
< 8; row
++)
1618 for (col
= 0; col
< mods
->max_keypermod
; col
++)
1621 mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
1623 /* Zeroes are used for filler. Skip them. */
1627 /* Are any of this keycode's keysyms a meta key? */
1631 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
1633 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
1639 x_meta_mod_mask
|= (1 << row
);
1644 x_alt_mod_mask
|= (1 << row
);
1649 x_hyper_mod_mask
|= (1 << row
);
1654 x_super_mod_mask
|= (1 << row
);
1658 /* Ignore this if it's not on the lock modifier. */
1659 if ((1 << row
) == LockMask
)
1660 x_shift_lock_mask
= LockMask
;
1668 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
1669 if (! x_meta_mod_mask
)
1671 x_meta_mod_mask
= x_alt_mod_mask
;
1675 /* If some keys are both alt and meta,
1676 make them just meta, not alt. */
1677 if (x_alt_mod_mask
& x_meta_mod_mask
)
1679 x_alt_mod_mask
&= ~x_meta_mod_mask
;
1682 XFree ((char *) syms
);
1683 XFreeModifiermap (mods
);
1686 /* Convert between the modifier bits X uses and the modifier bits
1689 x_x_to_emacs_modifiers (state
)
1692 return ( ((state
& (ShiftMask
| x_shift_lock_mask
)) ? shift_modifier
: 0)
1693 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
1694 | ((state
& x_meta_mod_mask
) ? meta_modifier
: 0)
1695 | ((state
& x_alt_mod_mask
) ? alt_modifier
: 0)
1696 | ((state
& x_super_mod_mask
) ? super_modifier
: 0)
1697 | ((state
& x_hyper_mod_mask
) ? hyper_modifier
: 0));
1701 x_emacs_to_x_modifiers (state
)
1704 return ( ((state
& alt_modifier
) ? x_alt_mod_mask
: 0)
1705 | ((state
& super_modifier
) ? x_super_mod_mask
: 0)
1706 | ((state
& hyper_modifier
) ? x_hyper_mod_mask
: 0)
1707 | ((state
& shift_modifier
) ? ShiftMask
: 0)
1708 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
1709 | ((state
& meta_modifier
) ? x_meta_mod_mask
: 0));
1712 /* Mouse clicks and mouse movement. Rah. */
1714 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
1715 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
1716 that the glyph at X, Y occupies, if BOUNDS != 0.
1717 If NOCLIP is nonzero, do not force the value into range. */
1720 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1722 register int pix_x
, pix_y
;
1723 register int *x
, *y
;
1727 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1728 even for negative values. */
1730 pix_x
-= FONT_WIDTH ((f
)->display
.x
->font
) - 1;
1732 pix_y
-= (f
)->display
.x
->line_height
- 1;
1734 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
1735 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
1739 bounds
->width
= FONT_WIDTH (f
->display
.x
->font
);
1740 bounds
->height
= f
->display
.x
->line_height
;
1741 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
1742 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
1749 else if (pix_x
> f
->width
)
1754 else if (pix_y
> f
->height
)
1763 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
1766 register int *pix_x
, *pix_y
;
1768 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
1769 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
1772 /* Prepare a mouse-event in *RESULT for placement in the input queue.
1774 If the event is a button press, then note that we have grabbed
1778 construct_mouse_click (result
, event
, f
)
1779 struct input_event
*result
;
1780 XButtonEvent
*event
;
1783 /* Make the event type no_event; we'll change that when we decide
1785 result
->kind
= mouse_click
;
1786 result
->code
= event
->button
- Button1
;
1787 result
->timestamp
= event
->time
;
1788 result
->modifiers
= (x_x_to_emacs_modifiers (event
->state
)
1789 | (event
->type
== ButtonRelease
1797 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
1798 XSETFASTINT (result
->x
, column
);
1799 XSETFASTINT (result
->y
, row
);
1801 XSETINT (result
->x
, event
->x
);
1802 XSETINT (result
->y
, event
->y
);
1803 XSETFRAME (result
->frame_or_window
, f
);
1807 /* Prepare a menu-event in *RESULT for placement in the input queue. */
1810 construct_menu_click (result
, event
, f
)
1811 struct input_event
*result
;
1812 XButtonEvent
*event
;
1815 /* Make the event type no_event; we'll change that when we decide
1817 result
->kind
= mouse_click
;
1818 XSETINT (result
->code
, event
->button
- Button1
);
1819 result
->timestamp
= event
->time
;
1820 result
->modifiers
= (x_x_to_emacs_modifiers (event
->state
)
1821 | (event
->type
== ButtonRelease
1825 XSETINT (result
->x
, event
->x
);
1826 XSETINT (result
->y
, -1);
1827 XSETFRAME (result
->frame_or_window
, f
);
1830 /* Function to report a mouse movement to the mainstream Emacs code.
1831 The input handler calls this.
1833 We have received a mouse movement event, which is given in *event.
1834 If the mouse is over a different glyph than it was last time, tell
1835 the mainstream emacs code by setting mouse_moved. If not, ask for
1836 another motion event, so we can check again the next time it moves. */
1839 note_mouse_movement (frame
, event
)
1841 XMotionEvent
*event
;
1844 last_mouse_movement_time
= event
->time
;
1846 if (event
->window
!= FRAME_X_WINDOW (frame
))
1849 last_mouse_scroll_bar
= Qnil
;
1851 note_mouse_highlight (frame
, -1, -1);
1853 /* Ask for another mouse motion event. */
1856 Window dummy_window
;
1858 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1859 &dummy_window
, &dummy_window
,
1860 &dummy
, &dummy
, &dummy
, &dummy
,
1861 (unsigned int *) &dummy
);
1865 /* Has the mouse moved off the glyph it was on at the last sighting? */
1866 else if (event
->x
< last_mouse_glyph
.x
1867 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
1868 || event
->y
< last_mouse_glyph
.y
1869 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
1872 last_mouse_scroll_bar
= Qnil
;
1874 note_mouse_highlight (frame
, event
->x
, event
->y
);
1876 /* Ask for another mouse motion event. */
1879 Window dummy_window
;
1881 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1882 &dummy_window
, &dummy_window
,
1883 &dummy
, &dummy
, &dummy
, &dummy
,
1884 (unsigned int *) &dummy
);
1889 /* It's on the same glyph. Call XQueryPointer so we'll get an
1890 event the next time the mouse moves and we can see if it's
1891 *still* on the same glyph. */
1893 Window dummy_window
;
1895 XQueryPointer (event
->display
, FRAME_X_WINDOW (frame
),
1896 &dummy_window
, &dummy_window
,
1897 &dummy
, &dummy
, &dummy
, &dummy
,
1898 (unsigned int *) &dummy
);
1902 /* This is used for debugging, to turn off note_mouse_highlight. */
1903 static int disable_mouse_highlight
;
1905 /* Take proper action when the mouse has moved to position X, Y on frame F
1906 as regards highlighting characters that have mouse-face properties.
1907 Also dehighlighting chars where the mouse was before.
1908 X and Y can be negative or out of range. */
1911 note_mouse_highlight (f
, x
, y
)
1914 int row
, column
, portion
;
1915 XRectangle new_glyph
;
1919 if (disable_mouse_highlight
)
1922 mouse_face_mouse_x
= x
;
1923 mouse_face_mouse_y
= y
;
1924 mouse_face_mouse_frame
= f
;
1926 if (mouse_face_defer
)
1931 mouse_face_deferred_gc
= 1;
1935 /* Find out which glyph the mouse is on. */
1936 pixel_to_glyph_coords (f
, x
, y
, &column
, &row
,
1937 &new_glyph
, x_mouse_grabbed
);
1939 /* Which window is that in? */
1940 window
= window_from_coordinates (f
, column
, row
, &portion
);
1941 w
= XWINDOW (window
);
1943 /* If we were displaying active text in another window, clear that. */
1944 if (! EQ (window
, mouse_face_window
))
1945 clear_mouse_face ();
1947 /* Are we in a window whose display is up to date?
1948 And verify the buffer's text has not changed. */
1949 if (WINDOWP (window
) && portion
== 0 && row
>= 0 && column
>= 0
1950 && row
< FRAME_HEIGHT (f
) && column
< FRAME_WIDTH (f
)
1951 && EQ (w
->window_end_valid
, w
->buffer
)
1952 && w
->last_modified
== BUF_MODIFF (XBUFFER (w
->buffer
)))
1954 int *ptr
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[row
];
1957 /* Find which buffer position the mouse corresponds to. */
1958 for (i
= column
; i
>= 0; i
--)
1962 /* Is it outside the displayed active region (if any)? */
1964 clear_mouse_face ();
1965 else if (! (EQ (window
, mouse_face_window
)
1966 && row
>= mouse_face_beg_row
1967 && row
<= mouse_face_end_row
1968 && (row
> mouse_face_beg_row
|| column
>= mouse_face_beg_col
)
1969 && (row
< mouse_face_end_row
|| column
< mouse_face_end_col
1970 || mouse_face_past_end
)))
1972 Lisp_Object mouse_face
, overlay
, position
;
1973 Lisp_Object
*overlay_vec
;
1974 int len
, noverlays
, ignor1
;
1975 struct buffer
*obuf
;
1978 /* If we get an out-of-range value, return now; avoid an error. */
1979 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
1982 /* Make the window's buffer temporarily current for
1983 overlays_at and compute_char_face. */
1984 obuf
= current_buffer
;
1985 current_buffer
= XBUFFER (w
->buffer
);
1991 /* Yes. Clear the display of the old active region, if any. */
1992 clear_mouse_face ();
1994 /* Is this char mouse-active? */
1995 XSETINT (position
, pos
);
1998 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2000 /* Put all the overlays we want in a vector in overlay_vec.
2001 Store the length in len. */
2002 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
,
2004 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
2006 /* Find the highest priority overlay that has a mouse-face prop. */
2008 for (i
= 0; i
< noverlays
; i
++)
2010 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
2011 if (!NILP (mouse_face
))
2013 overlay
= overlay_vec
[i
];
2018 /* If no overlay applies, get a text property. */
2020 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
2022 /* Handle the overlay case. */
2023 if (! NILP (overlay
))
2025 /* Find the range of text around this char that
2026 should be active. */
2027 Lisp_Object before
, after
;
2030 before
= Foverlay_start (overlay
);
2031 after
= Foverlay_end (overlay
);
2032 /* Record this as the current active region. */
2033 fast_find_position (window
, before
, &mouse_face_beg_col
,
2034 &mouse_face_beg_row
);
2036 = !fast_find_position (window
, after
, &mouse_face_end_col
,
2037 &mouse_face_end_row
);
2038 mouse_face_window
= window
;
2039 mouse_face_face_id
= compute_char_face (f
, w
, pos
, 0, 0,
2040 &ignore
, pos
+ 1, 1);
2042 /* Display it as active. */
2043 show_mouse_face (1);
2045 /* Handle the text property case. */
2046 else if (! NILP (mouse_face
))
2048 /* Find the range of text around this char that
2049 should be active. */
2050 Lisp_Object before
, after
, beginning
, end
;
2053 beginning
= Fmarker_position (w
->start
);
2054 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
2055 - XFASTINT (w
->window_end_pos
)));
2057 = Fprevious_single_property_change (make_number (pos
+ 1),
2059 w
->buffer
, beginning
);
2061 = Fnext_single_property_change (position
, Qmouse_face
,
2063 /* Record this as the current active region. */
2064 fast_find_position (window
, before
, &mouse_face_beg_col
,
2065 &mouse_face_beg_row
);
2067 = !fast_find_position (window
, after
, &mouse_face_end_col
,
2068 &mouse_face_end_row
);
2069 mouse_face_window
= window
;
2071 = compute_char_face (f
, w
, pos
, 0, 0,
2072 &ignore
, pos
+ 1, 1);
2074 /* Display it as active. */
2075 show_mouse_face (1);
2079 current_buffer
= obuf
;
2084 /* Find the row and column of position POS in window WINDOW.
2085 Store them in *COLUMNP and *ROWP.
2086 This assumes display in WINDOW is up to date.
2087 If POS is above start of WINDOW, return coords
2088 of start of first screen line.
2089 If POS is after end of WINDOW, return coords of end of last screen line.
2091 Value is 1 if POS is in range, 0 if it was off screen. */
2094 fast_find_position (window
, pos
, columnp
, rowp
)
2097 int *columnp
, *rowp
;
2099 struct window
*w
= XWINDOW (window
);
2100 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2105 int height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
2106 int width
= window_internal_width (w
);
2110 /* Find the right row. */
2115 int linestart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ i
][left
];
2116 if (linestart
> pos
)
2122 /* Find the right column with in it. */
2123 charstarts
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ row
];
2125 for (i
= 0; i
< width
; i
++)
2127 if (charstarts
[left
+ i
] == pos
)
2130 *columnp
= i
+ left
;
2133 else if (charstarts
[left
+ i
] > pos
)
2135 else if (charstarts
[left
+ i
] > 0)
2144 /* Display the active region described by mouse_face_*
2145 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2148 show_mouse_face (hl
)
2151 struct window
*w
= XWINDOW (mouse_face_window
);
2152 int width
= window_internal_width (w
);
2153 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2156 int old_curs_x
= curs_x
;
2157 int old_curs_y
= curs_y
;
2159 /* Set these variables temporarily
2160 so that if we have to turn the cursor off and on again
2161 we will put it back at the same place. */
2162 curs_x
= f
->phys_cursor_x
;
2163 curs_y
= f
->phys_cursor_y
;
2165 for (i
= mouse_face_beg_row
; i
<= mouse_face_end_row
; i
++)
2167 int column
= (i
== mouse_face_beg_row
? mouse_face_beg_col
: w
->left
);
2168 int endcolumn
= (i
== mouse_face_end_row
? mouse_face_end_col
: w
->left
+ width
);
2169 endcolumn
= min (endcolumn
, FRAME_CURRENT_GLYPHS (f
)->used
[i
]);
2171 /* If the cursor's in the text we are about to rewrite,
2172 turn the cursor off. */
2174 && curs_x
>= mouse_face_beg_col
- 1 && curs_x
<= mouse_face_end_col
)
2176 x_display_cursor (f
, 0);
2181 CHAR_TO_PIXEL_COL (f
, column
),
2182 CHAR_TO_PIXEL_ROW (f
, i
),
2183 FRAME_CURRENT_GLYPHS (f
)->glyphs
[i
] + column
,
2185 /* Highlight with mouse face if hl > 0. */
2189 /* If we turned the cursor off, turn it back on. */
2191 x_display_cursor (f
, 1);
2193 curs_x
= old_curs_x
;
2194 curs_y
= old_curs_y
;
2196 /* Change the mouse cursor according to the value of HL. */
2198 XDefineCursor (XDISPLAY
FRAME_X_WINDOW (f
), f
->display
.x
->cross_cursor
);
2200 XDefineCursor (XDISPLAY
FRAME_X_WINDOW (f
), f
->display
.x
->text_cursor
);
2203 /* Clear out the mouse-highlighted active region.
2204 Redraw it unhighlighted first. */
2209 if (! NILP (mouse_face_window
))
2210 show_mouse_face (0);
2212 mouse_face_beg_row
= mouse_face_beg_col
= -1;
2213 mouse_face_end_row
= mouse_face_end_col
= -1;
2214 mouse_face_window
= Qnil
;
2217 static struct scroll_bar
*x_window_to_scroll_bar ();
2218 static void x_scroll_bar_report_motion ();
2220 /* Return the current position of the mouse.
2222 If the mouse movement started in a scroll bar, set *f, *bar_window,
2223 and *part to the frame, window, and scroll bar part that the mouse
2224 is over. Set *x and *y to the portion and whole of the mouse's
2225 position on the scroll bar.
2227 If the mouse movement started elsewhere, set *f to the frame the
2228 mouse is on, *bar_window to nil, and *x and *y to the character cell
2231 Set *time to the server timestamp for the time at which the mouse
2232 was at this position.
2234 Don't store anything if we don't have a valid set of values to report.
2236 This clears the mouse_moved flag, so we can wait for the next mouse
2237 movement. This also calls XQueryPointer, which will cause the
2238 server to give us another MotionNotify when the mouse moves
2242 XTmouse_position (f
, bar_window
, part
, x
, y
, time
)
2244 Lisp_Object
*bar_window
;
2245 enum scroll_bar_part
*part
;
2247 unsigned long *time
;
2253 if (! NILP (last_mouse_scroll_bar
))
2254 x_scroll_bar_report_motion (f
, bar_window
, part
, x
, y
, time
);
2260 Window dummy_window
;
2264 last_mouse_scroll_bar
= Qnil
;
2266 /* Figure out which root window we're on. */
2267 XQueryPointer (x_current_display
,
2268 DefaultRootWindow (x_current_display
),
2270 /* The root window which contains the pointer. */
2273 /* Trash which we can't trust if the pointer is on
2274 a different screen. */
2277 /* The position on that root window. */
2280 /* More trash we can't trust. */
2283 /* Modifier keys and pointer buttons, about which
2285 (unsigned int *) &dummy
);
2287 /* Now we have a position on the root; find the innermost window
2288 containing the pointer. */
2292 int parent_x
, parent_y
;
2296 if (x_mouse_grabbed
&& last_mouse_frame
2297 && FRAME_LIVE_P (last_mouse_frame
))
2299 /* If mouse was grabbed on a frame, give coords for that frame
2300 even if the mouse is now outside it. */
2301 XTranslateCoordinates (x_current_display
,
2303 /* From-window, to-window. */
2304 root
, FRAME_X_WINDOW (last_mouse_frame
),
2306 /* From-position, to-position. */
2307 root_x
, root_y
, &win_x
, &win_y
,
2311 f1
= last_mouse_frame
;
2317 XTranslateCoordinates (x_current_display
,
2319 /* From-window, to-window. */
2322 /* From-position, to-position. */
2323 root_x
, root_y
, &win_x
, &win_y
,
2336 /* Now we know that:
2337 win is the innermost window containing the pointer
2338 (XTC says it has no child containing the pointer),
2339 win_x and win_y are the pointer's position in it
2340 (XTC did this the last time through), and
2341 parent_x and parent_y are the pointer's position in win's parent.
2342 (They are what win_x and win_y were when win was child.
2343 If win is the root window, it has no parent, and
2344 parent_{x,y} are invalid, but that's okay, because we'll
2345 never use them in that case.) */
2347 /* Is win one of our frames? */
2348 f1
= x_any_window_to_frame (win
);
2351 /* If not, is it one of our scroll bars? */
2354 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
2358 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2366 int ignore1
, ignore2
;
2368 /* Ok, we found a frame. Store all the values. */
2370 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
2371 &last_mouse_glyph
, x_mouse_grabbed
);
2376 XSETINT (*x
, win_x
);
2377 XSETINT (*y
, win_y
);
2378 *time
= last_mouse_movement_time
;
2386 /* Scroll bar support. */
2388 /* Given an X window ID, find the struct scroll_bar which manages it.
2389 This can be called in GC, so we have to make sure to strip off mark
2391 static struct scroll_bar
*
2392 x_window_to_scroll_bar (window_id
)
2395 Lisp_Object tail
, frame
;
2397 for (tail
= Vframe_list
;
2398 XGCTYPE (tail
) == Lisp_Cons
;
2399 tail
= XCONS (tail
)->cdr
)
2401 Lisp_Object frame
, bar
, condemned
;
2403 frame
= XCONS (tail
)->car
;
2404 /* All elements of Vframe_list should be frames. */
2405 if (XGCTYPE (frame
) != Lisp_Frame
)
2408 /* Scan this frame's scroll bar list for a scroll bar with the
2410 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2411 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2412 /* This trick allows us to search both the ordinary and
2413 condemned scroll bar lists with one loop. */
2414 ! GC_NILP (bar
) || (bar
= condemned
,
2417 bar
= XSCROLL_BAR (bar
)->next
)
2418 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2419 return XSCROLL_BAR (bar
);
2425 /* Open a new X window to serve as a scroll bar, and return the
2426 scroll bar vector for it. */
2427 static struct scroll_bar
*
2428 x_scroll_bar_create (window
, top
, left
, width
, height
)
2429 struct window
*window
;
2430 int top
, left
, width
, height
;
2432 FRAME_PTR frame
= XFRAME (WINDOW_FRAME (window
));
2433 struct scroll_bar
*bar
=
2434 XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2439 XSetWindowAttributes a
;
2441 a
.background_pixel
= frame
->display
.x
->background_pixel
;
2442 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2443 | ButtonMotionMask
| PointerMotionHintMask
2445 a
.cursor
= x_vertical_scroll_bar_cursor
;
2447 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2452 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2453 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2454 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
2455 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
2456 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2457 sb_widget
= XtCreateManagedWidget ("box",
2459 frame
->display
.x
->edit_widget
, al
, ac
);
2460 SET_SCROLL_BAR_X_WINDOW
2461 (bar
, sb_widget
->core
.window
);
2463 SET_SCROLL_BAR_X_WINDOW
2465 XCreateWindow (x_current_display
, FRAME_X_WINDOW (frame
),
2467 /* Position and size of scroll bar. */
2468 left
, top
, width
, height
,
2470 /* Border width, depth, class, and visual. */
2471 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
2477 XSETWINDOW (bar
->window
, window
);
2478 XSETINT (bar
->top
, top
);
2479 XSETINT (bar
->left
, left
);
2480 XSETINT (bar
->width
, width
);
2481 XSETINT (bar
->height
, height
);
2482 XSETINT (bar
->start
, 0);
2483 XSETINT (bar
->end
, 0);
2484 bar
->dragging
= Qnil
;
2486 /* Add bar to its frame's list of scroll bars. */
2487 bar
->next
= FRAME_SCROLL_BARS (frame
);
2489 XSETVECTOR (FRAME_SCROLL_BARS (frame
), bar
);
2490 if (! NILP (bar
->next
))
2491 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2493 XMapWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
));
2500 /* Draw BAR's handle in the proper position.
2501 If the handle is already drawn from START to END, don't bother
2502 redrawing it, unless REBUILD is non-zero; in that case, always
2503 redraw it. (REBUILD is handy for drawing the handle after expose
2506 Normally, we want to constrain the start and end of the handle to
2507 fit inside its rectangle, but if the user is dragging the scroll bar
2508 handle, we want to let them drag it down all the way, so that the
2509 bar's top is as far down as it goes; otherwise, there's no way to
2510 move to the very end of the buffer. */
2512 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
2513 struct scroll_bar
*bar
;
2517 int dragging
= ! NILP (bar
->dragging
);
2518 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2519 GC gc
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))->display
.x
->normal_gc
;
2521 /* If the display is already accurate, do nothing. */
2523 && start
== XINT (bar
->start
)
2524 && end
== XINT (bar
->end
))
2530 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (XINT (bar
->width
));
2531 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2532 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2534 /* Make sure the values are reasonable, and try to preserve
2535 the distance between start and end. */
2537 int length
= end
- start
;
2541 else if (start
> top_range
)
2543 end
= start
+ length
;
2547 else if (end
> top_range
&& ! dragging
)
2551 /* Store the adjusted setting in the scroll bar. */
2552 XSETINT (bar
->start
, start
);
2553 XSETINT (bar
->end
, end
);
2555 /* Clip the end position, just for display. */
2556 if (end
> top_range
)
2559 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
2560 below top positions, to make sure the handle is always at least
2561 that many pixels tall. */
2562 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
2564 /* Draw the empty space above the handle. Note that we can't clear
2565 zero-height areas; that means "clear to end of window." */
2567 XClearArea (x_current_display
, w
,
2569 /* x, y, width, height, and exposures. */
2570 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2571 VERTICAL_SCROLL_BAR_TOP_BORDER
,
2572 inside_width
, start
,
2575 /* Draw the handle itself. */
2576 XFillRectangle (x_current_display
, w
, gc
,
2578 /* x, y, width, height */
2579 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2580 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
2581 inside_width
, end
- start
);
2584 /* Draw the empty space below the handle. Note that we can't
2585 clear zero-height areas; that means "clear to end of window." */
2586 if (end
< inside_height
)
2587 XClearArea (x_current_display
, w
,
2589 /* x, y, width, height, and exposures. */
2590 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2591 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
2592 inside_width
, inside_height
- end
,
2600 /* Move a scroll bar around on the screen, to accommodate changing
2601 window configurations. */
2603 x_scroll_bar_move (bar
, top
, left
, width
, height
)
2604 struct scroll_bar
*bar
;
2605 int top
, left
, width
, height
;
2611 unsigned int mask
= 0;
2618 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
2619 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
2620 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
2621 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
2624 XConfigureWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
),
2628 XSETINT (bar
->left
, left
);
2629 XSETINT (bar
->top
, top
);
2630 XSETINT (bar
->width
, width
);
2631 XSETINT (bar
->height
, height
);
2636 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
2639 x_scroll_bar_remove (bar
)
2640 struct scroll_bar
*bar
;
2642 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2646 /* Destroy the window. */
2647 XDestroyWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
));
2649 /* Disassociate this scroll bar from its window. */
2650 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
2655 /* Set the handle of the vertical scroll bar for WINDOW to indicate
2656 that we are displaying PORTION characters out of a total of WHOLE
2657 characters, starting at POSITION. If WINDOW has no scroll bar,
2660 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
2661 struct window
*window
;
2662 int portion
, whole
, position
;
2664 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2665 int top
= XINT (window
->top
);
2666 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
2667 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
2669 /* Where should this scroll bar be, pixelwise? */
2670 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
2671 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
2673 = (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
2674 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2675 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->display
.x
->font
)));
2676 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
2678 struct scroll_bar
*bar
;
2680 /* Does the scroll bar exist yet? */
2681 if (NILP (window
->vertical_scroll_bar
))
2682 bar
= x_scroll_bar_create (window
,
2683 pixel_top
, pixel_left
,
2684 pixel_width
, pixel_height
);
2687 /* It may just need to be moved and resized. */
2688 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2689 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
2692 /* Set the scroll bar's current state, unless we're currently being
2694 if (NILP (bar
->dragging
))
2697 VERTICAL_SCROLL_BAR_TOP_RANGE (pixel_height
);
2700 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
2703 int start
= ((double) position
* top_range
) / whole
;
2704 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
2706 x_scroll_bar_set_handle (bar
, start
, end
, 0);
2710 XSETVECTOR (window
->vertical_scroll_bar
, bar
);
2714 /* The following three hooks are used when we're doing a thorough
2715 redisplay of the frame. We don't explicitly know which scroll bars
2716 are going to be deleted, because keeping track of when windows go
2717 away is a real pain - "Can you say set-window-configuration, boys
2718 and girls?" Instead, we just assert at the beginning of redisplay
2719 that *all* scroll bars are to be removed, and then save a scroll bar
2720 from the fiery pit when we actually redisplay its window. */
2722 /* Arrange for all scroll bars on FRAME to be removed at the next call
2723 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
2724 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
2726 XTcondemn_scroll_bars (frame
)
2729 /* The condemned list should be empty at this point; if it's not,
2730 then the rest of Emacs isn't using the condemn/redeem/judge
2731 protocol correctly. */
2732 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
2735 /* Move them all to the "condemned" list. */
2736 FRAME_CONDEMNED_SCROLL_BARS (frame
) = FRAME_SCROLL_BARS (frame
);
2737 FRAME_SCROLL_BARS (frame
) = Qnil
;
2740 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
2741 Note that WINDOW isn't necessarily condemned at all. */
2743 XTredeem_scroll_bar (window
)
2744 struct window
*window
;
2746 struct scroll_bar
*bar
;
2748 /* We can't redeem this window's scroll bar if it doesn't have one. */
2749 if (NILP (window
->vertical_scroll_bar
))
2752 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2754 /* Unlink it from the condemned list. */
2756 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2758 if (NILP (bar
->prev
))
2760 /* If the prev pointer is nil, it must be the first in one of
2762 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
2763 /* It's not condemned. Everything's fine. */
2765 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
2766 window
->vertical_scroll_bar
))
2767 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
2769 /* If its prev pointer is nil, it must be at the front of
2770 one or the other! */
2774 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
2776 if (! NILP (bar
->next
))
2777 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
2779 bar
->next
= FRAME_SCROLL_BARS (f
);
2781 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
2782 if (! NILP (bar
->next
))
2783 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
2787 /* Remove all scroll bars on FRAME that haven't been saved since the
2788 last call to `*condemn_scroll_bars_hook'. */
2790 XTjudge_scroll_bars (f
)
2793 Lisp_Object bar
, next
;
2795 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
2797 /* Clear out the condemned list now so we won't try to process any
2798 more events on the hapless scroll bars. */
2799 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
2801 for (; ! NILP (bar
); bar
= next
)
2803 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
2805 x_scroll_bar_remove (b
);
2808 b
->next
= b
->prev
= Qnil
;
2811 /* Now there should be no references to the condemned scroll bars,
2812 and they should get garbage-collected. */
2816 /* Handle an Expose or GraphicsExpose event on a scroll bar.
2818 This may be called from a signal handler, so we have to ignore GC
2821 x_scroll_bar_expose (bar
, event
)
2822 struct scroll_bar
*bar
;
2825 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2826 GC gc
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))->display
.x
->normal_gc
;
2830 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
2832 /* Draw a one-pixel border just inside the edges of the scroll bar. */
2833 XDrawRectangle (x_current_display
, w
, gc
,
2835 /* x, y, width, height */
2836 0, 0, XINT (bar
->width
) - 1, XINT (bar
->height
) - 1);
2841 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
2842 is set to something other than no_event, it is enqueued.
2844 This may be called from a signal handler, so we have to ignore GC
2847 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
2848 struct scroll_bar
*bar
;
2850 struct input_event
*emacs_event
;
2852 if (XGCTYPE (bar
->window
) != Lisp_Window
)
2855 emacs_event
->kind
= scroll_bar_click
;
2856 emacs_event
->code
= event
->xbutton
.button
- Button1
;
2857 emacs_event
->modifiers
=
2858 (x_x_to_emacs_modifiers (event
->xbutton
.state
)
2859 | (event
->type
== ButtonRelease
2862 emacs_event
->frame_or_window
= bar
->window
;
2863 emacs_event
->timestamp
= event
->xbutton
.time
;
2865 int internal_height
=
2866 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2868 VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2869 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
2872 if (y
> top_range
) y
= top_range
;
2874 if (y
< XINT (bar
->start
))
2875 emacs_event
->part
= scroll_bar_above_handle
;
2876 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
2877 emacs_event
->part
= scroll_bar_handle
;
2879 emacs_event
->part
= scroll_bar_below_handle
;
2881 /* Just because the user has clicked on the handle doesn't mean
2882 they want to drag it. Lisp code needs to be able to decide
2883 whether or not we're dragging. */
2885 /* If the user has just clicked on the handle, record where they're
2887 if (event
->type
== ButtonPress
2888 && emacs_event
->part
== scroll_bar_handle
)
2889 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
2892 /* If the user has released the handle, set it to its final position. */
2893 if (event
->type
== ButtonRelease
2894 && ! NILP (bar
->dragging
))
2896 int new_start
= y
- XINT (bar
->dragging
);
2897 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2899 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2900 bar
->dragging
= Qnil
;
2903 /* Same deal here as the other #if 0. */
2905 /* Clicks on the handle are always reported as occurring at the top of
2907 if (emacs_event
->part
== scroll_bar_handle
)
2908 emacs_event
->x
= bar
->start
;
2910 XSETINT (emacs_event
->x
, y
);
2912 XSETINT (emacs_event
->x
, y
);
2915 XSETINT (emacs_event
->y
, top_range
);
2919 /* Handle some mouse motion while someone is dragging the scroll bar.
2921 This may be called from a signal handler, so we have to ignore GC
2924 x_scroll_bar_note_movement (bar
, event
)
2925 struct scroll_bar
*bar
;
2928 last_mouse_movement_time
= event
->xmotion
.time
;
2931 XSETVECTOR (last_mouse_scroll_bar
, bar
);
2933 /* If we're dragging the bar, display it. */
2934 if (! GC_NILP (bar
->dragging
))
2936 /* Where should the handle be now? */
2937 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
2939 if (new_start
!= XINT (bar
->start
))
2941 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2943 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2947 /* Call XQueryPointer so we'll get an event the next time the mouse
2948 moves and we can see *still* on the same position. */
2951 Window dummy_window
;
2953 XQueryPointer (event
->xmotion
.display
, event
->xmotion
.window
,
2954 &dummy_window
, &dummy_window
,
2955 &dummy
, &dummy
, &dummy
, &dummy
,
2956 (unsigned int *) &dummy
);
2960 /* Return information to the user about the current position of the mouse
2961 on the scroll bar. */
2963 x_scroll_bar_report_motion (f
, bar_window
, part
, x
, y
, time
)
2965 Lisp_Object
*bar_window
;
2966 enum scroll_bar_part
*part
;
2968 unsigned long *time
;
2970 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
2972 Window dummy_window
;
2974 unsigned int dummy_mask
;
2978 /* Get the mouse's position relative to the scroll bar window, and
2980 if (! XQueryPointer (x_current_display
,
2981 SCROLL_BAR_X_WINDOW (bar
),
2983 /* Root, child, root x and root y. */
2984 &dummy_window
, &dummy_window
,
2985 &dummy_coord
, &dummy_coord
,
2987 /* Position relative to scroll bar. */
2990 /* Mouse buttons and modifier keys. */
2996 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2998 = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
3000 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
3002 if (! NILP (bar
->dragging
))
3003 win_y
-= XINT (bar
->dragging
);
3007 if (win_y
> top_range
)
3010 *f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3011 *bar_window
= bar
->window
;
3013 if (! NILP (bar
->dragging
))
3014 *part
= scroll_bar_handle
;
3015 else if (win_y
< XINT (bar
->start
))
3016 *part
= scroll_bar_above_handle
;
3017 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3018 *part
= scroll_bar_handle
;
3020 *part
= scroll_bar_below_handle
;
3022 XSETINT (*x
, win_y
);
3023 XSETINT (*y
, top_range
);
3026 last_mouse_scroll_bar
= Qnil
;
3029 *time
= last_mouse_movement_time
;
3035 /* The screen has been cleared so we may have changed foreground or
3036 background colors, and the scroll bars may need to be redrawn.
3037 Clear out the scroll bars, and ask for expose events, so we can
3040 x_scroll_bar_clear (f
)
3045 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
3046 bar
= XSCROLL_BAR (bar
)->next
)
3047 XClearArea (x_current_display
, SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
3051 /* This processes Expose events from the menubar specific X event
3052 loop in menubar.c. This allows to redisplay the frame if necessary
3053 when handling menubar or popup items. */
3056 process_expose_from_menu (event
)
3063 f
= x_window_to_frame (event
.xexpose
.window
);
3066 if (f
->async_visible
== 0)
3068 f
->async_visible
= 1;
3069 f
->async_iconified
= 0;
3070 SET_FRAME_GARBAGED (f
);
3074 dumprectangle (x_window_to_frame (event
.xexpose
.window
),
3075 event
.xexpose
.x
, event
.xexpose
.y
,
3076 event
.xexpose
.width
, event
.xexpose
.height
);
3081 struct scroll_bar
*bar
3082 = x_window_to_scroll_bar (event
.xexpose
.window
);
3085 x_scroll_bar_expose (bar
, &event
);
3091 /* Define a queue to save up SelectionRequest events for later handling. */
3093 struct selection_event_queue
3096 struct selection_event_queue
*next
;
3099 static struct selection_event_queue
*queue
;
3101 /* Nonzero means queue up certain events--don't process them yet. */
3102 static int x_queue_selection_requests
;
3104 /* Queue up an X event *EVENT, to be processed later. */
3107 x_queue_event (event
)
3110 struct selection_event_queue
*queue_tmp
3111 = (struct selection_event_queue
*) malloc (sizeof (struct selection_event_queue
));
3113 if (queue_tmp
!= NULL
)
3115 queue_tmp
->event
= *event
;
3116 queue_tmp
->next
= queue
;
3121 /* Take all the queued events and put them back
3122 so that they get processed afresh. */
3127 while (queue
!= NULL
)
3129 struct selection_event_queue
*queue_tmp
= queue
;
3130 XPutBackEvent (XDISPLAY
&queue_tmp
->event
);
3131 queue
= queue_tmp
->next
;
3132 free ((char *)queue_tmp
);
3136 /* Start queuing SelectionRequest events. */
3139 x_start_queuing_selection_requests ()
3141 x_queue_selection_requests
++;
3144 /* Stop queuing SelectionRequest events. */
3147 x_stop_queuing_selection_requests ()
3149 x_queue_selection_requests
--;
3150 x_unqueue_events ();
3153 /* The main X event-reading loop - XTread_socket. */
3155 /* Timestamp of enter window event. This is only used by XTread_socket,
3156 but we have to put it out here, since static variables within functions
3157 sometimes don't work. */
3158 static Time enter_timestamp
;
3160 /* This holds the state XLookupString needs to implement dead keys
3161 and other tricks known as "compose processing". _X Window System_
3162 says that a portable program can't use this, but Stephen Gildea assures
3163 me that letting the compiler initialize it to zeros will work okay.
3165 This must be defined outside of XTread_socket, for the same reasons
3166 given for enter_timestamp, above. */
3167 static XComposeStatus compose_status
;
3169 /* Communication with window managers. */
3170 Atom Xatom_wm_protocols
;
3172 /* Kinds of protocol things we may receive. */
3173 Atom Xatom_wm_take_focus
;
3174 Atom Xatom_wm_save_yourself
;
3175 Atom Xatom_wm_delete_window
;
3177 /* Other WM communication */
3178 Atom Xatom_wm_configure_denied
; /* When our config request is denied */
3179 Atom Xatom_wm_window_moved
; /* When the WM moves us. */
3181 /* Window manager communication. */
3182 Atom Xatom_wm_change_state
;
3184 /* EditRes protocol */
3185 Atom Xatom_editres_name
;
3187 /* Record the last 100 characters stored
3188 to help debug the loss-of-chars-during-GC problem. */
3190 short temp_buffer
[100];
3192 /* Read events coming from the X server.
3193 This routine is called by the SIGIO handler.
3194 We return as soon as there are no more events to be read.
3196 Events representing keys are stored in buffer BUFP,
3197 which can hold up to NUMCHARS characters.
3198 We return the number of characters stored into the buffer,
3199 thus pretending to be `read'.
3201 WAITP is nonzero if we should block until input arrives.
3202 EXPECTED is nonzero if the caller knows input is available. */
3205 XTread_socket (sd
, bufp
, numchars
, waitp
, expected
)
3207 register struct input_event
*bufp
;
3208 register int numchars
;
3215 int items_pending
; /* How many items are in the X queue. */
3218 int event_found
= 0;
3222 if (interrupt_input_blocked
)
3224 interrupt_input_pending
= 1;
3228 interrupt_input_pending
= 0;
3231 /* So people can tell when we have read the available input. */
3232 input_signal_count
++;
3235 abort (); /* Don't think this happens. */
3238 /* If available, Xlib uses FIOSNBIO to make the socket
3239 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3240 FIOSNBIO is ignored, and instead of signalling EWOULDBLOCK,
3241 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3242 fcntl (fileno (stdin
), F_SETFL
, 0);
3243 #endif /* ! defined (FIOSNBIO) */
3247 if (! (fcntl (fileno (stdin
), F_GETFL
, 0) & O_NDELAY
))
3249 extern int read_alarm_should_throw
;
3250 read_alarm_should_throw
= 1;
3251 XPeekEvent (XDISPLAY
&event
);
3252 read_alarm_should_throw
= 0;
3254 #endif /* HAVE_SELECT */
3257 while (XStuffPending () != 0)
3259 XNextEvent (XDISPLAY
&event
);
3266 if (event
.xclient
.message_type
== Xatom_wm_protocols
3267 && event
.xclient
.format
== 32)
3269 if (event
.xclient
.data
.l
[0] == Xatom_wm_take_focus
)
3271 f
= x_window_to_frame (event
.xclient
.window
);
3272 /* Since we set WM_TAKE_FOCUS, we must call
3273 XSetInputFocus explicitly. But not if f is null,
3274 since that might be an event for a deleted frame. */
3276 XSetInputFocus (event
.xclient
.display
,
3277 event
.xclient
.window
,
3278 RevertToPointerRoot
,
3279 event
.xclient
.data
.l
[1]);
3280 /* Not certain about handling scroll bars here */
3282 else if (event
.xclient
.data
.l
[0] == Xatom_wm_save_yourself
)
3284 /* Save state modify the WM_COMMAND property to
3285 something which can reinstate us. This notifies
3286 the session manager, who's looking for such a
3287 PropertyNotify. Can restart processing when
3288 a keyboard or mouse event arrives. */
3291 /* This is just so we only give real data once
3292 for a single Emacs process. */
3293 if (x_top_window_to_frame (event
.xclient
.window
)
3295 XSetCommand (x_current_display
,
3296 event
.xclient
.window
,
3297 initial_argv
, initial_argc
);
3299 XSetCommand (x_current_display
,
3300 event
.xclient
.window
,
3304 else if (event
.xclient
.data
.l
[0] == Xatom_wm_delete_window
)
3306 struct frame
*f
= x_any_window_to_frame (event
.xclient
.window
);
3313 bufp
->kind
= delete_window_event
;
3314 XSETFRAME (bufp
->frame_or_window
, f
);
3322 else if (event
.xclient
.message_type
== Xatom_wm_configure_denied
)
3325 else if (event
.xclient
.message_type
== Xatom_wm_window_moved
)
3328 struct frame
*f
= x_window_to_frame (event
.xclient
.window
);
3330 new_x
= event
.xclient
.data
.s
[0];
3331 new_y
= event
.xclient
.data
.s
[1];
3335 f
->display
.x
->left_pos
= new_x
;
3336 f
->display
.x
->top_pos
= new_y
;
3339 #if defined (USE_X_TOOLKIT) && defined (HAVE_X11R5)
3340 else if (event
.xclient
.message_type
== Xatom_editres_name
)
3342 struct frame
*f
= x_any_window_to_frame (event
.xclient
.window
);
3343 _XEditResCheckMessages (f
->display
.x
->widget
, NULL
, &event
, NULL
);
3345 #endif /* USE_X_TOOLKIT and HAVE_X11R5 */
3349 case SelectionNotify
:
3350 #ifdef USE_X_TOOLKIT
3351 if (! x_window_to_frame (event
.xselection
.requestor
))
3353 #endif /* not USE_X_TOOLKIT */
3354 x_handle_selection_notify (&event
);
3357 case SelectionClear
: /* Someone has grabbed ownership. */
3358 #ifdef USE_X_TOOLKIT
3359 if (! x_window_to_frame (event
.xselectionclear
.window
))
3361 #endif /* USE_X_TOOLKIT */
3363 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
3368 bufp
->kind
= selection_clear_event
;
3369 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3370 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3371 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3379 case SelectionRequest
: /* Someone wants our selection. */
3380 #ifdef USE_X_TOOLKIT
3381 if (!x_window_to_frame (event
.xselectionrequest
.owner
))
3383 #endif /* USE_X_TOOLKIT */
3384 if (x_queue_selection_requests
)
3385 x_queue_event (&event
);
3388 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
3393 bufp
->kind
= selection_request_event
;
3394 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3395 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
3396 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3397 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
3398 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
3399 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3407 case PropertyNotify
:
3408 #ifdef USE_X_TOOLKIT
3409 if (!x_any_window_to_frame (event
.xproperty
.window
))
3411 #endif /* not USE_X_TOOLKIT */
3412 x_handle_property_notify (&event
);
3415 case ReparentNotify
:
3416 f
= x_top_window_to_frame (event
.xreparent
.window
);
3420 f
->display
.x
->parent_desc
= event
.xreparent
.parent
;
3421 x_real_positions (f
, &x
, &y
);
3422 f
->display
.x
->left_pos
= x
;
3423 f
->display
.x
->top_pos
= y
;
3428 f
= x_window_to_frame (event
.xexpose
.window
);
3431 if (f
->async_visible
== 0)
3433 f
->async_visible
= 1;
3434 f
->async_iconified
= 0;
3435 SET_FRAME_GARBAGED (f
);
3438 dumprectangle (x_window_to_frame (event
.xexpose
.window
),
3439 event
.xexpose
.x
, event
.xexpose
.y
,
3440 event
.xexpose
.width
, event
.xexpose
.height
);
3444 struct scroll_bar
*bar
3445 = x_window_to_scroll_bar (event
.xexpose
.window
);
3448 x_scroll_bar_expose (bar
, &event
);
3449 #ifdef USE_X_TOOLKIT
3452 #endif /* USE_X_TOOLKIT */
3456 case GraphicsExpose
: /* This occurs when an XCopyArea's
3457 source area was obscured or not
3459 f
= x_window_to_frame (event
.xgraphicsexpose
.drawable
);
3463 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
3464 event
.xgraphicsexpose
.width
,
3465 event
.xgraphicsexpose
.height
);
3467 #ifdef USE_X_TOOLKIT
3470 #endif /* USE_X_TOOLKIT */
3473 case NoExpose
: /* This occurs when an XCopyArea's
3474 source area was completely
3479 f
= x_any_window_to_frame (event
.xunmap
.window
);
3480 if (f
) /* F may no longer exist if
3481 the frame was deleted. */
3483 /* While a frame is unmapped, display generation is
3484 disabled; you don't want to spend time updating a
3485 display that won't ever be seen. */
3486 f
->async_visible
= 0;
3487 /* We can't distinguish, from the event, whether the window
3488 has become iconified or invisible. So assume, if it
3489 was previously visible, than now it is iconified.
3490 We depend on x_make_frame_invisible to mark it iconified. */
3491 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
3492 f
->async_iconified
= 1;
3494 #ifdef USE_X_TOOLKIT
3496 #endif /* USE_X_TOOLKIT */
3500 /* We use x_top_window_to_frame because map events can come
3501 for subwindows and they don't mean that the frame is visible. */
3502 f
= x_top_window_to_frame (event
.xmap
.window
);
3505 f
->async_visible
= 1;
3506 f
->async_iconified
= 0;
3508 /* wait_reading_process_input will notice this and update
3509 the frame's display structures. */
3510 SET_FRAME_GARBAGED (f
);
3512 #ifdef USE_X_TOOLKIT
3514 #endif /* USE_X_TOOLKIT */
3517 /* Turn off processing if we become fully obscured. */
3518 case VisibilityNotify
:
3522 f
= x_any_window_to_frame (event
.xkey
.window
);
3526 KeySym keysym
, orig_keysym
;
3527 /* al%imercury@uunet.uu.net says that making this 81 instead of
3528 80 fixed a bug whereby meta chars made his Emacs hang. */
3529 unsigned char copy_buffer
[81];
3533 |= x_emacs_to_x_modifiers (extra_keyboard_modifiers
);
3534 modifiers
= event
.xkey
.state
;
3536 /* This will have to go some day... */
3538 /* make_lispy_event turns chars into control chars.
3539 Don't do it here because XLookupString is too eager. */
3540 event
.xkey
.state
&= ~ControlMask
;
3542 XLookupString (&event
.xkey
, copy_buffer
, 80, &keysym
,
3545 orig_keysym
= keysym
;
3549 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
3550 || keysym
== XK_Delete
3551 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
3552 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
3554 /* This recognizes the "extended function keys".
3555 It seems there's no cleaner way.
3556 Test IsModifierKey to avoid handling mode_switch
3558 || ((unsigned) (keysym
) >= XK_Select
3559 && (unsigned)(keysym
) < XK_KP_Space
)
3561 #ifdef XK_dead_circumflex
3562 || orig_keysym
== XK_dead_circumflex
3564 #ifdef XK_dead_grave
3565 || orig_keysym
== XK_dead_grave
3567 #ifdef XK_dead_tilde
3568 || orig_keysym
== XK_dead_tilde
3570 #ifdef XK_dead_diaeresis
3571 || orig_keysym
== XK_dead_diaeresis
3573 #ifdef XK_dead_macron
3574 || orig_keysym
== XK_dead_macron
3576 #ifdef XK_dead_degree
3577 || orig_keysym
== XK_dead_degree
3579 #ifdef XK_dead_acute
3580 || orig_keysym
== XK_dead_acute
3582 #ifdef XK_dead_cedilla
3583 || orig_keysym
== XK_dead_cedilla
3585 #ifdef XK_dead_breve
3586 || orig_keysym
== XK_dead_breve
3588 #ifdef XK_dead_ogonek
3589 || orig_keysym
== XK_dead_ogonek
3591 #ifdef XK_dead_caron
3592 || orig_keysym
== XK_dead_caron
3594 #ifdef XK_dead_doubleacute
3595 || orig_keysym
== XK_dead_doubleacute
3597 #ifdef XK_dead_abovedot
3598 || orig_keysym
== XK_dead_abovedot
3600 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
3601 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
3602 /* Any "vendor-specific" key is ok. */
3603 || (orig_keysym
& (1 << 28)))
3604 && ! (IsModifierKey (orig_keysym
)
3606 #ifdef XK_Mode_switch
3607 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
3610 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
3612 #endif /* not HAVE_X11R5 */
3615 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3617 temp_buffer
[temp_index
++] = keysym
;
3618 bufp
->kind
= non_ascii_keystroke
;
3619 bufp
->code
= keysym
;
3620 XSETFRAME (bufp
->frame_or_window
, f
);
3621 bufp
->modifiers
= x_x_to_emacs_modifiers (modifiers
);
3622 bufp
->timestamp
= event
.xkey
.time
;
3627 else if (numchars
> nbytes
)
3631 for (i
= 0; i
< nbytes
; i
++)
3633 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3635 temp_buffer
[temp_index
++] = copy_buffer
[i
];
3636 bufp
->kind
= ascii_keystroke
;
3637 bufp
->code
= copy_buffer
[i
];
3638 XSETFRAME (bufp
->frame_or_window
, f
);
3639 bufp
->modifiers
= x_x_to_emacs_modifiers (modifiers
);
3640 bufp
->timestamp
= event
.xkey
.time
;
3655 /* Here's a possible interpretation of the whole
3656 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
3657 FocusIn event, you have to get a FocusOut event before you
3658 relinquish the focus. If you haven't received a FocusIn event,
3659 then a mere LeaveNotify is enough to free you. */
3662 f
= x_any_window_to_frame (event
.xcrossing
.window
);
3664 if (event
.xcrossing
.focus
) /* Entered Window */
3666 /* Avoid nasty pop/raise loops. */
3667 if (f
&& (!(f
->auto_raise
)
3669 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
3671 x_new_focus_frame (f
);
3672 enter_timestamp
= event
.xcrossing
.time
;
3675 else if (f
== x_focus_frame
)
3676 x_new_focus_frame (0);
3677 /* EnterNotify counts as mouse movement,
3678 so update things that depend on mouse position. */
3680 note_mouse_movement (f
, &event
.xmotion
);
3681 #ifdef USE_X_TOOLKIT
3683 #endif /* USE_X_TOOLKIT */
3687 f
= x_any_window_to_frame (event
.xfocus
.window
);
3688 if (event
.xfocus
.detail
!= NotifyPointer
)
3689 x_focus_event_frame
= f
;
3691 x_new_focus_frame (f
);
3692 #ifdef USE_X_TOOLKIT
3694 #endif /* USE_X_TOOLKIT */
3699 f
= x_top_window_to_frame (event
.xcrossing
.window
);
3702 if (f
== mouse_face_mouse_frame
)
3703 /* If we move outside the frame,
3704 then we're certainly no longer on any text in the frame. */
3705 clear_mouse_face ();
3707 if (event
.xcrossing
.focus
)
3709 if (! x_focus_event_frame
)
3710 x_new_focus_frame (0);
3712 x_new_focus_frame (f
);
3716 if (f
== x_focus_event_frame
)
3717 x_focus_event_frame
= 0;
3718 if (f
== x_focus_frame
)
3719 x_new_focus_frame (0);
3722 #ifdef USE_X_TOOLKIT
3724 #endif /* USE_X_TOOLKIT */
3728 f
= x_any_window_to_frame (event
.xfocus
.window
);
3729 if (event
.xfocus
.detail
!= NotifyPointer
3730 && f
== x_focus_event_frame
)
3731 x_focus_event_frame
= 0;
3732 if (f
&& f
== x_focus_frame
)
3733 x_new_focus_frame (0);
3734 #ifdef USE_X_TOOLKIT
3736 #endif /* USE_X_TOOLKIT */
3741 if (x_mouse_grabbed
&& last_mouse_frame
3742 && FRAME_LIVE_P (last_mouse_frame
))
3743 f
= last_mouse_frame
;
3745 f
= x_window_to_frame (event
.xmotion
.window
);
3747 note_mouse_movement (f
, &event
.xmotion
);
3750 struct scroll_bar
*bar
3751 = x_window_to_scroll_bar (event
.xmotion
.window
);
3754 x_scroll_bar_note_movement (bar
, &event
);
3756 /* If we move outside the frame,
3757 then we're certainly no longer on any text in the frame. */
3758 clear_mouse_face ();
3761 #if 0 /* This should be unnecessary, since the toolkit has no use
3762 for motion events that happen outside of the menu event loop,
3763 and it seems to cause the bug that mouse events stop coming
3765 #ifdef USE_X_TOOLKIT
3767 #endif /* USE_X_TOOLKIT */
3771 case ConfigureNotify
:
3772 f
= x_any_window_to_frame (event
.xconfigure
.window
);
3773 #ifdef USE_X_TOOLKIT
3776 && ! event
.xconfigure
.send_event
3778 && (event
.xconfigure
.window
== XtWindow (f
->display
.x
->widget
)))
3783 /* Find the position of the outside upper-left corner of
3784 the window, in the root coordinate system. Don't
3785 refer to the parent window here; we may be processing
3786 this event after the window manager has changed our
3787 parent, but before we have reached the ReparentNotify. */
3788 XTranslateCoordinates (x_current_display
,
3790 /* From-window, to-window. */
3791 XtWindow (f
->display
.x
->widget
),
3794 /* From-position, to-position. */
3795 -event
.xconfigure
.border_width
,
3796 -event
.xconfigure
.border_width
,
3801 event
.xconfigure
.x
= win_x
;
3802 event
.xconfigure
.y
= win_y
;
3804 f
->display
.x
->pixel_width
= event
.xconfigure
.width
;
3805 f
->display
.x
->pixel_height
= event
.xconfigure
.height
;
3806 f
->display
.x
->left_pos
= event
.xconfigure
.x
;
3807 f
->display
.x
->top_pos
= event
.xconfigure
.y
;
3809 /* What we have now is the position of Emacs's own window.
3810 Convert that to the position of the window manager window. */
3813 x_real_positions (f
, &x
, &y
);
3814 f
->display
.x
->left_pos
= x
;
3815 f
->display
.x
->top_pos
= y
;
3819 #else /* not USE_X_TOOLKIT */
3822 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
3823 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
3825 /* Even if the number of character rows and columns has
3826 not changed, the font size may have changed, so we need
3827 to check the pixel dimensions as well. */
3828 if (columns
!= f
->width
3829 || rows
!= f
->height
3830 || event
.xconfigure
.width
!= f
->display
.x
->pixel_width
3831 || event
.xconfigure
.height
!= f
->display
.x
->pixel_height
)
3833 change_frame_size (f
, rows
, columns
, 0, 1);
3834 SET_FRAME_GARBAGED (f
);
3837 if (! event
.xconfigure
.send_event
)
3842 /* Find the position of the outside upper-left corner of
3843 the window, in the root coordinate system. Don't
3844 refer to the parent window here; we may be processing
3845 this event after the window manager has changed our
3846 parent, but before we have reached the ReparentNotify. */
3847 XTranslateCoordinates (x_current_display
,
3849 /* From-window, to-window. */
3850 f
->display
.x
->window_desc
,
3853 /* From-position, to-position. */
3854 -event
.xconfigure
.border_width
,
3855 -event
.xconfigure
.border_width
,
3860 event
.xconfigure
.x
= win_x
;
3861 event
.xconfigure
.y
= win_y
;
3864 f
->display
.x
->pixel_width
= event
.xconfigure
.width
;
3865 f
->display
.x
->pixel_height
= event
.xconfigure
.height
;
3866 f
->display
.x
->left_pos
= event
.xconfigure
.x
;
3867 f
->display
.x
->top_pos
= event
.xconfigure
.y
;
3869 /* What we have now is the position of Emacs's own window.
3870 Convert that to the position of the window manager window. */
3873 x_real_positions (f
, &x
, &y
);
3874 f
->display
.x
->left_pos
= x
;
3875 f
->display
.x
->top_pos
= y
;
3876 if (y
!= event
.xconfigure
.y
)
3878 /* Since the WM decorations come below top_pos now,
3879 we must put them below top_pos in the future. */
3880 f
->display
.x
->win_gravity
= NorthWestGravity
;
3881 x_wm_set_size_hint (f
, 0, 0);
3885 #endif /* not USE_X_TOOLKIT */
3891 /* If we decide we want to generate an event to be seen
3892 by the rest of Emacs, we put it here. */
3893 struct input_event emacs_event
;
3894 emacs_event
.kind
= no_event
;
3896 bzero (&compose_status
, sizeof (compose_status
));
3898 f
= x_window_to_frame (event
.xbutton
.window
);
3901 if (!x_focus_frame
|| (f
== x_focus_frame
))
3902 construct_mouse_click (&emacs_event
, &event
, f
);
3906 struct scroll_bar
*bar
3907 = x_window_to_scroll_bar (event
.xbutton
.window
);
3910 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
3911 #ifdef USE_X_TOOLKIT
3914 /* Assume we have a menubar button press. A bad
3915 assumption should behave benignly. */
3916 popup_get_selection (&event
);
3919 #endif /* USE_X_TOOLKIT */
3922 if (event
.type
== ButtonPress
)
3924 x_mouse_grabbed
|= (1 << event
.xbutton
.button
);
3925 Vmouse_depressed
= Qt
;
3926 last_mouse_frame
= f
;
3930 x_mouse_grabbed
&= ~(1 << event
.xbutton
.button
);
3931 if (!x_mouse_grabbed
)
3932 Vmouse_depressed
= Qnil
;
3935 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
3937 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
3943 #ifdef USE_X_TOOLKIT
3945 #endif /* USE_X_TOOLKIT */
3949 case CirculateNotify
:
3951 case CirculateRequest
:
3955 /* Someone has changed the keyboard mapping - update the
3957 switch (event
.xmapping
.request
)
3959 case MappingModifier
:
3960 x_find_modifier_meanings ();
3961 /* This is meant to fall through. */
3962 case MappingKeyboard
:
3963 XRefreshKeyboardMapping (&event
.xmapping
);
3965 #ifdef USE_X_TOOLKIT
3967 #endif /* USE_X_TOOLKIT */
3971 #ifdef USE_X_TOOLKIT
3974 XtDispatchEvent (&event
);
3976 #endif /* USE_X_TOOLKIT */
3981 /* On some systems, an X bug causes Emacs to get no more events
3982 when the window is destroyed. Detect that. (1994.) */
3985 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
3986 One XNOOP in 100 loops will make Emacs terminate.
3987 B. Bretthauer, 1994 */
3989 if (x_noop_count
>= 100)
3992 XNoOp (x_current_display
);
3996 #if 0 /* This fails for serial-line connections to the X server,
3997 because the characters arrive one by one, and a partial
3998 command makes select return but gives nothing to read.
3999 We'll have to hope that the bug that this tried to fix
4000 in 1988 has been fixed in Xlib or the X server. */
4002 if (expected
&& ! event_found
)
4004 /* AOJ 880406: if select returns true but XPending doesn't, it means that
4005 there is an EOF condition; in other words, that X has died.
4006 Act as if there had been a hangup. */
4007 int fd
= ConnectionNumber (x_current_display
);
4008 SELECT_TYPE mask
, junk1
, junk2
;
4013 EMACS_SET_SECS_USECS (timeout
, 0, 0);
4016 if (0 != select (fd
+ 1, &mask
, &junk1
, &junk2
, &timeout
)
4017 && !XStuffPending ())
4018 kill (getpid (), SIGHUP
);
4020 #endif /* HAVE_SELECT */
4023 /* If the focus was just given to an autoraising frame,
4025 if (pending_autoraise_frame
)
4027 x_raise_frame (pending_autoraise_frame
);
4028 pending_autoraise_frame
= 0;
4035 /* Drawing the cursor. */
4038 /* Draw a hollow box cursor. Don't change the inside of the box. */
4044 int left
= CHAR_TO_PIXEL_COL (f
, curs_x
);
4045 int top
= CHAR_TO_PIXEL_ROW (f
, curs_y
);
4046 int width
= FONT_WIDTH (f
->display
.x
->font
);
4047 int height
= f
->display
.x
->line_height
;
4049 XDrawRectangle (x_current_display
, FRAME_X_WINDOW (f
),
4050 f
->display
.x
->cursor_gc
,
4051 left
, top
, width
- 1, height
- 1);
4054 /* Clear the cursor of frame F to background color,
4055 and mark the cursor as not shown.
4056 This is used when the text where the cursor is
4057 is about to be rewritten. */
4065 if (! FRAME_VISIBLE_P (f
)
4066 || f
->phys_cursor_x
< 0)
4069 x_display_cursor (f
, 0);
4070 f
->phys_cursor_x
= -1;
4073 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4074 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4078 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
4085 CHAR_TO_PIXEL_COL (f
, column
),
4086 CHAR_TO_PIXEL_ROW (f
, row
),
4087 &glyph
, 1, highlight
, 0);
4091 x_display_bar_cursor (f
, on
)
4095 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4097 /* This is pointless on invisible frames, and dangerous on garbaged
4098 frames; in the latter case, the frame may be in the midst of
4099 changing its size, and curs_x and curs_y may be off the frame. */
4100 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4103 if (! on
&& f
->phys_cursor_x
< 0)
4106 /* If we're not updating, then we want to use the current frame's
4107 cursor position, not our local idea of where the cursor ought to be. */
4108 if (f
!= updating_frame
)
4110 curs_x
= FRAME_CURSOR_X (f
);
4111 curs_y
= FRAME_CURSOR_Y (f
);
4114 /* If there is anything wrong with the current cursor state, remove it. */
4115 if (f
->phys_cursor_x
>= 0
4117 || f
->phys_cursor_x
!= curs_x
4118 || f
->phys_cursor_y
!= curs_y
4119 || f
->display
.x
->current_cursor
!= bar_cursor
))
4121 /* Erase the cursor by redrawing the character underneath it. */
4122 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4123 f
->phys_cursor_glyph
,
4124 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4125 f
->phys_cursor_x
= -1;
4128 /* If we now need a cursor in the new place or in the new form, do it so. */
4130 && (f
->phys_cursor_x
< 0
4131 || (f
->display
.x
->current_cursor
!= bar_cursor
)))
4133 f
->phys_cursor_glyph
4134 = ((current_glyphs
->enable
[curs_y
]
4135 && curs_x
< current_glyphs
->used
[curs_y
])
4136 ? current_glyphs
->glyphs
[curs_y
][curs_x
]
4138 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
),
4139 f
->display
.x
->cursor_gc
,
4140 CHAR_TO_PIXEL_COL (f
, curs_x
),
4141 CHAR_TO_PIXEL_ROW (f
, curs_y
),
4142 1, f
->display
.x
->line_height
);
4144 f
->phys_cursor_x
= curs_x
;
4145 f
->phys_cursor_y
= curs_y
;
4147 f
->display
.x
->current_cursor
= bar_cursor
;
4150 if (updating_frame
!= f
)
4155 /* Turn the displayed cursor of frame F on or off according to ON.
4156 If ON is nonzero, where to put the cursor is specified
4157 by F->cursor_x and F->cursor_y. */
4160 x_display_box_cursor (f
, on
)
4164 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4166 /* This is pointless on invisible frames, and dangerous on garbaged
4167 frames; in the latter case, the frame may be in the midst of
4168 changing its size, and curs_x and curs_y may be off the frame. */
4169 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4172 /* If cursor is off and we want it off, return quickly. */
4173 if (!on
&& f
->phys_cursor_x
< 0)
4176 /* If we're not updating, then we want to use the current frame's
4177 cursor position, not our local idea of where the cursor ought to be. */
4178 if (f
!= updating_frame
)
4180 curs_x
= FRAME_CURSOR_X (f
);
4181 curs_y
= FRAME_CURSOR_Y (f
);
4184 /* If cursor is currently being shown and we don't want it to be
4185 or it is in the wrong place,
4186 or we want a hollow box and it's not so, (pout!)
4188 if (f
->phys_cursor_x
>= 0
4190 || f
->phys_cursor_x
!= curs_x
4191 || f
->phys_cursor_y
!= curs_y
4192 || (f
->display
.x
->current_cursor
!= hollow_box_cursor
4193 && (f
!= x_highlight_frame
))))
4195 int mouse_face_here
= 0;
4197 /* If the cursor is in the mouse face area, redisplay that when
4198 we clear the cursor. */
4199 if (f
== mouse_face_mouse_frame
4201 (f
->phys_cursor_y
> mouse_face_beg_row
4202 || (f
->phys_cursor_y
== mouse_face_beg_row
4203 && f
->phys_cursor_x
>= mouse_face_beg_col
))
4205 (f
->phys_cursor_y
< mouse_face_end_row
4206 || (f
->phys_cursor_y
== mouse_face_end_row
4207 && f
->phys_cursor_x
< mouse_face_end_col
)))
4208 mouse_face_here
= 1;
4210 /* If the font is not as tall as a whole line,
4211 we must explicitly clear the line's whole height. */
4212 if (FONT_HEIGHT (f
->display
.x
->font
) != f
->display
.x
->line_height
)
4213 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
4214 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
4215 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
4216 FONT_WIDTH (f
->display
.x
->font
),
4217 f
->display
.x
->line_height
, False
);
4218 /* Erase the cursor by redrawing the character underneath it. */
4219 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4220 f
->phys_cursor_glyph
,
4223 : current_glyphs
->highlight
[f
->phys_cursor_y
]));
4224 f
->phys_cursor_x
= -1;
4227 /* If we want to show a cursor,
4228 or we want a box cursor and it's not so,
4229 write it in the right place. */
4231 && (f
->phys_cursor_x
< 0
4232 || (f
->display
.x
->current_cursor
!= filled_box_cursor
4233 && f
== x_highlight_frame
)))
4235 f
->phys_cursor_glyph
4236 = ((current_glyphs
->enable
[curs_y
]
4237 && curs_x
< current_glyphs
->used
[curs_y
])
4238 ? current_glyphs
->glyphs
[curs_y
][curs_x
]
4240 if (f
!= x_highlight_frame
)
4243 f
->display
.x
->current_cursor
= hollow_box_cursor
;
4247 x_draw_single_glyph (f
, curs_y
, curs_x
,
4248 f
->phys_cursor_glyph
, 2);
4249 f
->display
.x
->current_cursor
= filled_box_cursor
;
4252 f
->phys_cursor_x
= curs_x
;
4253 f
->phys_cursor_y
= curs_y
;
4256 if (updating_frame
!= f
)
4260 x_display_cursor (f
, on
)
4266 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4267 x_display_box_cursor (f
, on
);
4268 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4269 x_display_bar_cursor (f
, on
);
4271 /* Those are the only two we have implemented! */
4279 /* Refresh bitmap kitchen sink icon for frame F
4280 when we get an expose event for it. */
4285 /* Normally, the window manager handles this function. */
4288 /* Make the x-window of frame F use the gnu icon bitmap. */
4291 x_bitmap_icon (f
, file
)
4295 int mask
, bitmap_id
;
4298 if (FRAME_X_WINDOW (f
) == 0)
4301 /* Free up our existing icon bitmap if any. */
4302 if (f
->display
.x
->icon_bitmap
> 0)
4303 x_destroy_bitmap (f
, f
->display
.x
->icon_bitmap
);
4304 f
->display
.x
->icon_bitmap
= 0;
4307 bitmap_id
= x_create_bitmap_from_file (f
, file
);
4310 /* Create the GNU bitmap if necessary. */
4312 icon_bitmap
= x_create_bitmap_from_data (f
, gnu_bits
,
4313 gnu_width
, gnu_height
);
4315 /* The first time we create the GNU bitmap,
4316 this increments the refcount one extra time.
4317 As a result, the GNU bitmap is never freed.
4318 That way, we don't have to worry about allocating it again. */
4319 x_reference_bitmap (f
, icon_bitmap
);
4321 bitmap_id
= icon_bitmap
;
4324 x_wm_set_icon_pixmap (f
, bitmap_id
);
4325 f
->display
.x
->icon_bitmap
= bitmap_id
;
4331 /* Make the x-window of frame F use a rectangle with text. */
4334 x_text_icon (f
, icon_name
)
4338 if (FRAME_X_WINDOW (f
) == 0)
4342 f
->display
.x
->icon_label
= icon_name
;
4344 if (! f
->display
.x
->icon_label
)
4345 f
->display
.x
->icon_label
= " *emacs* ";
4348 XSetIconName (x_current_display
, FRAME_X_WINDOW (f
),
4349 (char *) f
->display
.x
->icon_label
);
4352 if (f
->display
.x
->icon_bitmap
> 0)
4353 x_destroy_bitmap (f
, f
->display
.x
->icon_bitmap
);
4354 f
->display
.x
->icon_bitmap
= 0;
4355 x_wm_set_icon_pixmap (f
, 0);
4360 /* Handling X errors. */
4362 /* Shut down Emacs in an orderly fashion, because of a SIGPIPE on the
4363 X server's connection, or an error reported via the X protocol. */
4366 x_connection_closed ()
4371 shut_down_emacs (0, 1, Qnil
);
4376 /* An X error handler which prints an error message and then kills
4377 Emacs. This is what's normally installed as Xlib's handler for
4380 x_error_quitter (display
, error
)
4386 /* Note that there is no real way portable across R3/R4 to get the
4387 original error handler. */
4389 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
4390 fprintf (stderr
, "X protocol error: %s on protocol request %d\n",
4391 buf
, error
->request_code
);
4394 /* While we're testing Emacs 19, we'll just dump core whenever we
4395 get an X error, so we can figure out why it happened. */
4399 x_connection_closed ();
4402 /* A handler for X IO errors which prints an error message and then
4403 kills Emacs. This is what is always installed as Xlib's handler
4406 x_io_error_quitter (display
)
4409 fprintf (stderr
, "Connection to X server %s lost.\n",
4410 XDisplayName (DisplayString (display
)));
4413 /* While we're testing Emacs 19, we'll just dump core whenever we
4414 get an X error, so we can figure out why it happened. */
4418 x_connection_closed ();
4421 /* A buffer for storing X error messages. */
4422 static char *x_caught_error_message
;
4423 #define X_CAUGHT_ERROR_MESSAGE_SIZE 200
4425 /* An X error handler which stores the error message in
4426 x_caught_error_message. This is what's installed when
4427 x_catch_errors is in effect. */
4429 x_error_catcher (display
, error
)
4433 XGetErrorText (display
, error
->error_code
,
4434 x_caught_error_message
, X_CAUGHT_ERROR_MESSAGE_SIZE
);
4438 /* Begin trapping X errors.
4440 After calling this function, X protocol errors no longer cause
4441 Emacs to exit; instead, they are recorded in x_cfc_error_message.
4443 Calling x_check_errors signals an Emacs error if an X error has
4444 occurred since the last call to x_catch_errors or x_check_errors.
4446 Calling x_uncatch_errors resumes the normal error handling. */
4448 void x_catch_errors (), x_check_errors (), x_uncatch_errors ();
4453 /* Make sure any errors from previous requests have been dealt with. */
4454 XSync (x_current_display
, False
);
4456 /* Set up the error buffer. */
4457 x_caught_error_message
4458 = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE
);
4459 x_caught_error_message
[0] = '\0';
4461 /* Install our little error handler. */
4462 XHandleError (x_error_catcher
);
4465 /* If any X protocol errors have arrived since the last call to
4466 x_catch_errors or x_check_errors, signal an Emacs error using
4467 sprintf (a buffer, FORMAT, the x error message text) as the text. */
4470 x_check_errors (format
)
4473 /* Make sure to catch any errors incurred so far. */
4474 XSync (x_current_display
, False
);
4476 if (x_caught_error_message
[0])
4478 char buf
[X_CAUGHT_ERROR_MESSAGE_SIZE
+ 56];
4480 sprintf (buf
, format
, x_caught_error_message
);
4481 x_uncatch_errors ();
4486 /* Nonzero if we had any X protocol errors since we did x_catch_errors. */
4491 /* Make sure to catch any errors incurred so far. */
4492 XSync (x_current_display
, False
);
4494 return x_caught_error_message
[0] != 0;
4497 /* Stop catching X protocol errors and let them make Emacs die. */
4502 xfree (x_caught_error_message
);
4503 x_caught_error_message
= 0;
4504 XHandleError (x_error_quitter
);
4508 static unsigned int x_wire_count
;
4511 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
4516 /* Changing the font of the frame. */
4518 /* Set the font of the x-window specified by frame F
4519 to the font named NEWNAME. This is safe to use
4520 even before F has an actual x-window. */
4529 /* A table of all the fonts we have already loaded. */
4530 static struct font_info
*x_font_table
;
4532 /* The current capacity of x_font_table. */
4533 static int x_font_table_size
;
4535 /* The number of fonts actually stored in x_font_table.
4536 x_font_table[n] is used and valid iff 0 <= n < n_fonts.
4537 0 <= n_fonts <= x_font_table_size. */
4540 /* Give frame F the font named FONTNAME as its default font, and
4541 return the full name of that font. FONTNAME may be a wildcard
4542 pattern; in that case, we choose some font that fits the pattern.
4543 The return value shows which font we chose. */
4546 x_new_font (f
, fontname
)
4548 register char *fontname
;
4551 int n_matching_fonts
;
4552 XFontStruct
*font_info
;
4555 /* Get a list of all the fonts that match this name. Once we
4556 have a list of matching fonts, we compare them against the fonts
4557 we already have by comparing font ids. */
4558 font_names
= (char **) XListFonts (x_current_display
, fontname
,
4559 1024, &n_matching_fonts
);
4560 /* Apparently it doesn't set n_matching_fonts to zero when it can't
4561 find any matches; font_names == 0 is the only clue. */
4563 n_matching_fonts
= 0;
4565 /* Don't just give up if n_matching_fonts is 0.
4566 Apparently there's a bug on Suns: XListFontsWithInfo can
4567 fail to find a font, but XLoadQueryFont may still find it. */
4569 /* See if we've already loaded a matching font. */
4570 already_loaded
= -1;
4571 if (n_matching_fonts
!= 0)
4575 for (i
= 0; i
< n_fonts
; i
++)
4576 for (j
= 0; j
< n_matching_fonts
; j
++)
4577 if (!strcmp (x_font_table
[i
].name
, font_names
[j
])
4578 || !strcmp (x_font_table
[i
].full_name
, font_names
[j
]))
4581 fontname
= x_font_table
[i
].full_name
;
4587 /* If we have, just return it from the table. */
4588 if (already_loaded
>= 0)
4589 f
->display
.x
->font
= x_font_table
[already_loaded
].font
;
4590 /* Otherwise, load the font and add it to the table. */
4597 /* Try to find a character-cell font in the list. */
4599 /* A laudable goal, but this isn't how to do it. */
4600 for (i
= 0; i
< n_matching_fonts
; i
++)
4601 if (! font_info
[i
].per_char
)
4607 /* See comment above. */
4608 if (n_matching_fonts
!= 0)
4609 fontname
= font_names
[i
];
4611 font
= (XFontStruct
*) XLoadQueryFont (x_current_display
, fontname
);
4614 /* Free the information from XListFonts. */
4615 if (n_matching_fonts
)
4616 XFreeFontNames (font_names
);
4620 /* Do we need to create the table? */
4621 if (x_font_table_size
== 0)
4623 x_font_table_size
= 16;
4625 = (struct font_info
*) xmalloc (x_font_table_size
4626 * sizeof (x_font_table
[0]));
4628 /* Do we need to grow the table? */
4629 else if (n_fonts
>= x_font_table_size
)
4631 x_font_table_size
*= 2;
4633 = (struct font_info
*) xrealloc (x_font_table
,
4635 * sizeof (x_font_table
[0])));
4638 /* Try to get the full name of FONT. Put it in full_name. */
4640 for (i
= 0; i
< font
->n_properties
; i
++)
4643 = XGetAtomName (x_current_display
, font
->properties
[i
].name
);
4644 if (!strcmp (atom
, "FONT"))
4646 char *name
= XGetAtomName (x_current_display
,
4647 (Atom
) (font
->properties
[i
].card32
));
4651 /* Count the number of dashes in the "full name".
4652 If it is too few, this isn't really the font's full name,
4654 In X11R4, the fonts did not come with their canonical names
4672 x_font_table
[n_fonts
].name
= (char *) xmalloc (strlen (fontname
) + 1);
4673 bcopy (fontname
, x_font_table
[n_fonts
].name
, strlen (fontname
) + 1);
4675 x_font_table
[n_fonts
].full_name
= full_name
;
4677 x_font_table
[n_fonts
].full_name
= x_font_table
[n_fonts
].name
;
4678 f
->display
.x
->font
= x_font_table
[n_fonts
++].font
= font
;
4681 fontname
= full_name
;
4684 /* Compute the scroll bar width in character columns. */
4685 if (f
->scroll_bar_pixel_width
> 0)
4687 int wid
= FONT_WIDTH (f
->display
.x
->font
);
4688 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
4691 f
->scroll_bar_cols
= 2;
4693 /* Now make the frame display the given font. */
4694 if (FRAME_X_WINDOW (f
) != 0)
4696 XSetFont (x_current_display
, f
->display
.x
->normal_gc
,
4697 f
->display
.x
->font
->fid
);
4698 XSetFont (x_current_display
, f
->display
.x
->reverse_gc
,
4699 f
->display
.x
->font
->fid
);
4700 XSetFont (x_current_display
, f
->display
.x
->cursor_gc
,
4701 f
->display
.x
->font
->fid
);
4703 frame_update_line_height (f
);
4704 x_set_window_size (f
, 0, f
->width
, f
->height
);
4707 /* If we are setting a new frame's font for the first time,
4708 there are no faces yet, so this font's height is the line height. */
4709 f
->display
.x
->line_height
= FONT_HEIGHT (f
->display
.x
->font
);
4712 Lisp_Object lispy_name
;
4714 lispy_name
= build_string (fontname
);
4716 /* Free the information from XListFonts. The data
4717 we actually retain comes from XLoadQueryFont. */
4718 XFreeFontNames (font_names
);
4724 x_calc_absolute_position (f
)
4728 int win_x
= 0, win_y
= 0;
4729 int flags
= f
->display
.x
->size_hint_flags
;
4731 /* Find the position of the outside upper-left corner of
4732 the inner window, with respect to the outer window. */
4733 if (f
->display
.x
->parent_desc
!= ROOT_WINDOW
)
4736 XTranslateCoordinates (x_current_display
,
4738 /* From-window, to-window. */
4739 f
->display
.x
->window_desc
,
4740 f
->display
.x
->parent_desc
,
4742 /* From-position, to-position. */
4743 0, 0, &win_x
, &win_y
,
4750 /* Treat negative positions as relative to the leftmost bottommost
4751 position that fits on the screen. */
4752 if (flags
& XNegative
)
4753 f
->display
.x
->left_pos
= (x_screen_width
4754 - 2 * f
->display
.x
->border_width
- win_x
4756 + f
->display
.x
->left_pos
);
4758 if (flags
& YNegative
)
4759 f
->display
.x
->top_pos
= (x_screen_height
4760 - 2 * f
->display
.x
->border_width
- win_y
4762 + f
->display
.x
->top_pos
);
4763 /* The left_pos and top_pos
4764 are now relative to the top and left screen edges,
4765 so the flags should correspond. */
4766 f
->display
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
4769 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
4770 to really change the position, and 0 when calling from
4771 x_make_frame_visible (in that case, XOFF and YOFF are the current
4772 position values). */
4774 x_set_offset (f
, xoff
, yoff
, change_gravity
)
4776 register int xoff
, yoff
;
4781 f
->display
.x
->top_pos
= yoff
;
4782 f
->display
.x
->left_pos
= xoff
;
4783 f
->display
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
4785 f
->display
.x
->size_hint_flags
|= XNegative
;
4787 f
->display
.x
->size_hint_flags
|= YNegative
;
4788 f
->display
.x
->win_gravity
= NorthWestGravity
;
4790 x_calc_absolute_position (f
);
4793 x_wm_set_size_hint (f
, 0, 0);
4795 #ifdef USE_X_TOOLKIT
4796 XMoveWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
),
4797 f
->display
.x
->left_pos
, f
->display
.x
->top_pos
);
4798 #else /* not USE_X_TOOLKIT */
4799 XMoveWindow (XDISPLAY
FRAME_X_WINDOW (f
),
4800 f
->display
.x
->left_pos
, f
->display
.x
->top_pos
);
4801 #endif /* not USE_X_TOOLKIT */
4805 /* Call this to change the size of frame F's x-window.
4806 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
4807 for this size change and subsequent size changes.
4808 Otherwise we leave the window gravity unchanged. */
4810 x_set_window_size (f
, change_gravity
, cols
, rows
)
4815 int pixelwidth
, pixelheight
;
4818 #ifdef USE_X_TOOLKIT
4821 /* The x and y position of the widget is clobbered by the
4822 call to XtSetValues within EmacsFrameSetCharSize.
4823 This is a real kludge, but I don't understand Xt so I can't
4824 figure out a correct fix. Can anyone else tell me? -- rms. */
4825 int xpos
= f
->display
.x
->widget
->core
.x
;
4826 int ypos
= f
->display
.x
->widget
->core
.y
;
4827 EmacsFrameSetCharSize (f
->display
.x
->edit_widget
, cols
, rows
);
4828 f
->display
.x
->widget
->core
.x
= xpos
;
4829 f
->display
.x
->widget
->core
.y
= ypos
;
4833 #else /* not USE_X_TOOLKIT */
4837 check_frame_size (f
, &rows
, &cols
);
4838 f
->display
.x
->vertical_scroll_bar_extra
4839 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4841 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
4842 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
4843 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->display
.x
->font
)));
4844 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
4845 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
4847 f
->display
.x
->win_gravity
= NorthWestGravity
;
4848 x_wm_set_size_hint (f
, 0, 0);
4850 XSync (x_current_display
, False
);
4851 XChangeWindowSize (FRAME_X_WINDOW (f
), pixelwidth
, pixelheight
);
4853 /* Now, strictly speaking, we can't be sure that this is accurate,
4854 but the window manager will get around to dealing with the size
4855 change request eventually, and we'll hear how it went when the
4856 ConfigureNotify event gets here.
4858 We could just not bother storing any of this information here,
4859 and let the ConfigureNotify event set everything up, but that
4860 might be kind of confusing to the lisp code, since size changes
4861 wouldn't be reported in the frame parameters until some random
4862 point in the future when the ConfigureNotify event arrives. */
4863 change_frame_size (f
, rows
, cols
, 0, 0);
4864 PIXEL_WIDTH (f
) = pixelwidth
;
4865 PIXEL_HEIGHT (f
) = pixelheight
;
4867 /* If cursor was outside the new size, mark it as off. */
4868 if (f
->phys_cursor_y
>= rows
4869 || f
->phys_cursor_x
>= cols
)
4871 f
->phys_cursor_x
= -1;
4872 f
->phys_cursor_y
= -1;
4875 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
4876 receive in the ConfigureNotify event; if we get what we asked
4877 for, then the event won't cause the screen to become garbaged, so
4878 we have to make sure to do it here. */
4879 SET_FRAME_GARBAGED (f
);
4883 #endif /* not USE_X_TOOLKIT */
4886 /* Mouse warping, focus shifting, raising and lowering. */
4889 x_set_mouse_position (f
, x
, y
)
4895 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->display
.x
->font
) / 2;
4896 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->display
.x
->line_height
/ 2;
4898 if (pix_x
< 0) pix_x
= 0;
4899 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
4901 if (pix_y
< 0) pix_y
= 0;
4902 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
4906 XWarpMousePointer (FRAME_X_WINDOW (f
), pix_x
, pix_y
);
4910 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
4913 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
4919 XWarpMousePointer (FRAME_X_WINDOW (f
), pix_x
, pix_y
);
4923 x_focus_on_frame (f
)
4926 #if 0 /* This proves to be unpleasant. */
4930 /* I don't think that the ICCCM allows programs to do things like this
4931 without the interaction of the window manager. Whatever you end up
4932 doing with this code, do it to x_unfocus_frame too. */
4933 XSetInputFocus (x_current_display
, FRAME_X_WINDOW (f
),
4934 RevertToPointerRoot
, CurrentTime
);
4942 /* Look at the remarks in x_focus_on_frame. */
4943 if (x_focus_frame
== f
)
4944 XSetInputFocus (x_current_display
, PointerRoot
,
4945 RevertToPointerRoot
, CurrentTime
);
4949 /* Raise frame F. */
4954 if (f
->async_visible
)
4957 #ifdef USE_X_TOOLKIT
4958 XRaiseWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
));
4959 #else /* not USE_X_TOOLKIT */
4960 XRaiseWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4961 #endif /* not USE_X_TOOLKIT */
4967 /* Lower frame F. */
4972 if (f
->async_visible
)
4975 #ifdef USE_X_TOOLKIT
4976 XLowerWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
));
4977 #else /* not USE_X_TOOLKIT */
4978 XLowerWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4979 #endif /* not USE_X_TOOLKIT */
4986 XTframe_raise_lower (f
, raise
)
4996 /* Change from withdrawn state to mapped state,
4999 x_make_frame_visible (f
)
5007 type
= x_icon_type (f
);
5009 x_bitmap_icon (f
, type
);
5011 if (! FRAME_VISIBLE_P (f
))
5013 #ifndef USE_X_TOOLKIT
5014 if (! FRAME_ICONIFIED_P (f
))
5015 x_set_offset (f
, f
->display
.x
->left_pos
, f
->display
.x
->top_pos
, 0);
5018 if (! EQ (Vx_no_window_manager
, Qt
))
5019 x_wm_set_window_state (f
, NormalState
);
5020 #ifdef USE_X_TOOLKIT
5021 /* This was XtPopup, but that did nothing for an iconified frame. */
5022 XtMapWidget (f
->display
.x
->widget
);
5023 #else /* not USE_X_TOOLKIT */
5024 XMapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
5025 #endif /* not USE_X_TOOLKIT */
5026 #if 0 /* This seems to bring back scroll bars in the wrong places
5027 if the window configuration has changed. They seem
5028 to come back ok without this. */
5029 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5030 XMapSubwindows (x_current_display
, FRAME_X_WINDOW (f
));
5036 /* Synchronize to ensure Emacs knows the frame is visible
5037 before we do anything else. We do this loop with input not blocked
5038 so that incoming events are handled. */
5041 int count
= input_signal_count
;
5043 /* This must come after we set COUNT. */
5046 XSETFRAME (frame
, f
);
5051 /* Once we have handled input events,
5052 we should have received the MapNotify if one is coming.
5053 So if we have not got it yet, stop looping.
5054 Some window managers make their own decisions
5055 about visibility. */
5056 if (input_signal_count
!= count
)
5058 /* Machines that do polling rather than SIGIO have been observed
5059 to go into a busy-wait here. So we'll fake an alarm signal
5060 to let the handler know that there's something to be read.
5061 We used to raise a real alarm, but it seems that the handler
5062 isn't always enabled here. This is probably a bug. */
5063 if (input_polling_used ())
5065 /* It could be confusing if a real alarm arrives while processing
5066 the fake one. Turn it off and let the handler reset it. */
5068 input_poll_signal ();
5070 /* Once we have handled input events,
5071 we should have received the MapNotify if one is coming.
5072 So if we have not got it yet, stop looping.
5073 Some window managers make their own decisions
5074 about visibility. */
5075 if (input_signal_count
!= count
)
5078 FRAME_SAMPLE_VISIBILITY (f
);
5082 /* Change from mapped state to withdrawn state. */
5084 x_make_frame_invisible (f
)
5090 #ifdef USE_X_TOOLKIT
5091 /* Use the frame's outermost window, not the one we normally draw on. */
5092 window
= XtWindow (f
->display
.x
->widget
);
5093 #else /* not USE_X_TOOLKIT */
5094 window
= FRAME_X_WINDOW (f
);
5095 #endif /* not USE_X_TOOLKIT */
5097 /* Don't keep the highlight on an invisible frame. */
5098 if (x_highlight_frame
== f
)
5099 x_highlight_frame
= 0;
5101 #if 0/* This might add unreliability; I don't trust it -- rms. */
5102 if (! f
->async_visible
&& ! f
->async_iconified
)
5108 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
5109 that the current position of the window is user-specified, rather than
5110 program-specified, so that when the window is mapped again, it will be
5111 placed at the same location, without forcing the user to position it
5112 by hand again (they have already done that once for this window.) */
5113 x_wm_set_size_hint (f
, 0, 1);
5117 if (! XWithdrawWindow (x_current_display
, window
,
5118 DefaultScreen (x_current_display
)))
5120 UNBLOCK_INPUT_RESIGNAL
;
5121 error ("Can't notify window manager of window withdrawal");
5123 #else /* ! defined (HAVE_X11R4) */
5125 /* Tell the window manager what we're going to do. */
5126 if (! EQ (Vx_no_window_manager
, Qt
))
5130 unmap
.xunmap
.type
= UnmapNotify
;
5131 unmap
.xunmap
.window
= window
;
5132 unmap
.xunmap
.event
= DefaultRootWindow (x_current_display
);
5133 unmap
.xunmap
.from_configure
= False
;
5134 if (! XSendEvent (x_current_display
,
5135 DefaultRootWindow (x_current_display
),
5137 SubstructureRedirectMask
|SubstructureNotifyMask
,
5140 UNBLOCK_INPUT_RESIGNAL
;
5141 error ("Can't notify window manager of withdrawal");
5145 /* Unmap the window ourselves. Cheeky! */
5146 XUnmapWindow (x_current_display
, window
);
5147 #endif /* ! defined (HAVE_X11R4) */
5149 /* We can't distinguish this from iconification
5150 just by the event that we get from the server.
5151 So we can't win using the usual strategy of letting
5152 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
5153 and synchronize with the server to make sure we agree. */
5155 FRAME_ICONIFIED_P (f
) = 0;
5156 f
->async_visible
= 0;
5157 f
->async_iconified
= 0;
5164 /* Change window state from mapped to iconified. */
5173 /* Don't keep the highlight on an invisible frame. */
5174 if (x_highlight_frame
== f
)
5175 x_highlight_frame
= 0;
5177 if (f
->async_iconified
)
5182 type
= x_icon_type (f
);
5184 x_bitmap_icon (f
, type
);
5186 #ifdef USE_X_TOOLKIT
5188 if (! FRAME_VISIBLE_P (f
))
5190 if (! EQ (Vx_no_window_manager
, Qt
))
5191 x_wm_set_window_state (f
, IconicState
);
5192 /* This was XtPopup, but that did nothing for an iconified frame. */
5193 XtMapWidget (f
->display
.x
->widget
);
5198 result
= XIconifyWindow (x_current_display
,
5199 XtWindow (f
->display
.x
->widget
),
5200 DefaultScreen (x_current_display
));
5204 error ("Can't notify window manager of iconification");
5206 f
->async_iconified
= 1;
5211 #else /* not USE_X_TOOLKIT */
5213 /* Make sure the X server knows where the window should be positioned,
5214 in case the user deiconifies with the window manager. */
5215 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
5216 x_set_offset (f
, f
->display
.x
->left_pos
, f
->display
.x
->top_pos
, 0);
5218 /* Since we don't know which revision of X we're running, we'll use both
5219 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
5221 /* X11R4: send a ClientMessage to the window manager using the
5222 WM_CHANGE_STATE type. */
5226 message
.xclient
.window
= FRAME_X_WINDOW (f
);
5227 message
.xclient
.type
= ClientMessage
;
5228 message
.xclient
.message_type
= Xatom_wm_change_state
;
5229 message
.xclient
.format
= 32;
5230 message
.xclient
.data
.l
[0] = IconicState
;
5232 if (! XSendEvent (x_current_display
,
5233 DefaultRootWindow (x_current_display
),
5235 SubstructureRedirectMask
| SubstructureNotifyMask
,
5238 UNBLOCK_INPUT_RESIGNAL
;
5239 error ("Can't notify window manager of iconification");
5243 /* X11R3: set the initial_state field of the window manager hints to
5245 x_wm_set_window_state (f
, IconicState
);
5247 if (!FRAME_VISIBLE_P (f
))
5249 /* If the frame was withdrawn, before, we must map it. */
5250 XMapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
5251 #if 0 /* We don't have subwindows in the icon. */
5252 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5253 XMapSubwindows (x_current_display
, FRAME_X_WINDOW (f
));
5257 f
->async_iconified
= 1;
5261 #endif /* not USE_X_TOOLKIT */
5264 /* Destroy the X window of frame F. */
5266 x_destroy_window (f
)
5271 if (f
->display
.x
->icon_desc
!= 0)
5272 XDestroyWindow (XDISPLAY f
->display
.x
->icon_desc
);
5273 XDestroyWindow (XDISPLAY f
->display
.x
->window_desc
);
5274 #ifdef USE_X_TOOLKIT
5275 XtDestroyWidget (f
->display
.x
->widget
);
5276 free_frame_menubar (f
);
5277 #endif /* USE_X_TOOLKIT */
5279 free_frame_faces (f
);
5282 FRAME_X_SCREEN (f
)->reference_count
--;
5284 if (FRAME_X_SCREEN (f
)->reference_count
== 0)
5285 free (FRAME_X_SCREEN (f
));
5288 xfree (f
->display
.x
);
5290 if (f
== x_focus_frame
)
5292 if (f
== x_highlight_frame
)
5293 x_highlight_frame
= 0;
5295 if (f
== mouse_face_mouse_frame
)
5297 mouse_face_beg_row
= mouse_face_beg_col
= -1;
5298 mouse_face_end_row
= mouse_face_end_col
= -1;
5299 mouse_face_window
= Qnil
;
5305 /* Setting window manager hints. */
5307 /* Set the normal size hints for the window manager, for frame F.
5308 FLAGS is the flags word to use--or 0 meaning preserve the flags
5309 that the window now has.
5310 If USER_POSITION is nonzero, we set the USPosition
5311 flag (this is useful when FLAGS is 0). */
5313 x_wm_set_size_hint (f
, flags
, user_position
)
5318 XSizeHints size_hints
;
5320 #ifdef USE_X_TOOLKIT
5323 Dimension widget_width
, widget_height
;
5324 Window window
= XtWindow (f
->display
.x
->widget
);
5325 #else /* not USE_X_TOOLKIT */
5326 Window window
= FRAME_X_WINDOW (f
);
5327 #endif /* not USE_X_TOOLKIT */
5329 /* Setting PMaxSize caused various problems. */
5330 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
5332 flexlines
= f
->height
;
5334 size_hints
.x
= f
->display
.x
->left_pos
;
5335 size_hints
.y
= f
->display
.x
->top_pos
;
5337 #ifdef USE_X_TOOLKIT
5338 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
5339 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
5340 XtGetValues (f
->display
.x
->column_widget
, al
, ac
);
5341 size_hints
.height
= widget_height
;
5342 size_hints
.width
= widget_width
;
5343 #else /* not USE_X_TOOLKIT */
5344 size_hints
.height
= PIXEL_HEIGHT (f
);
5345 size_hints
.width
= PIXEL_WIDTH (f
);
5346 #endif /* not USE_X_TOOLKIT */
5348 size_hints
.width_inc
= FONT_WIDTH (f
->display
.x
->font
);
5349 size_hints
.height_inc
= f
->display
.x
->line_height
;
5350 size_hints
.max_width
= x_screen_width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
5351 size_hints
.max_height
= x_screen_height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
5354 int base_width
, base_height
;
5355 int min_rows
= 0, min_cols
= 0;
5357 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
5358 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
5360 check_frame_size (f
, &min_rows
, &min_cols
);
5362 /* The window manager uses the base width hints to calculate the
5363 current number of rows and columns in the frame while
5364 resizing; min_width and min_height aren't useful for this
5365 purpose, since they might not give the dimensions for a
5366 zero-row, zero-column frame.
5368 We use the base_width and base_height members if we have
5369 them; otherwise, we set the min_width and min_height members
5370 to the size for a zero x zero frame. */
5373 size_hints
.flags
|= PBaseSize
;
5374 size_hints
.base_width
= base_width
;
5375 size_hints
.base_height
= base_height
;
5376 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
5377 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
5379 size_hints
.min_width
= base_width
;
5380 size_hints
.min_height
= base_height
;
5385 size_hints
.flags
|= flags
;
5388 XSizeHints hints
; /* Sometimes I hate X Windows... */
5389 long supplied_return
;
5393 value
= XGetWMNormalHints (x_current_display
, window
, &hints
,
5396 value
= XGetNormalHints (x_current_display
, window
, &hints
);
5401 if (hints
.flags
& PSize
)
5402 size_hints
.flags
|= PSize
;
5403 if (hints
.flags
& PPosition
)
5404 size_hints
.flags
|= PPosition
;
5405 if (hints
.flags
& USPosition
)
5406 size_hints
.flags
|= USPosition
;
5407 if (hints
.flags
& USSize
)
5408 size_hints
.flags
|= USSize
;
5412 size_hints
.win_gravity
= f
->display
.x
->win_gravity
;
5413 size_hints
.flags
|= PWinGravity
;
5417 size_hints
.flags
&= ~ PPosition
;
5418 size_hints
.flags
|= USPosition
;
5420 #endif /* PWinGravity */
5423 XSetWMNormalHints (x_current_display
, window
, &size_hints
);
5425 XSetNormalHints (x_current_display
, window
, &size_hints
);
5429 /* Used for IconicState or NormalState */
5430 x_wm_set_window_state (f
, state
)
5434 #ifdef USE_X_TOOLKIT
5437 XtSetArg (al
[0], XtNinitialState
, state
);
5438 XtSetValues (f
->display
.x
->widget
, al
, 1);
5439 #else /* not USE_X_TOOLKIT */
5440 Window window
= FRAME_X_WINDOW (f
);
5442 f
->display
.x
->wm_hints
.flags
|= StateHint
;
5443 f
->display
.x
->wm_hints
.initial_state
= state
;
5445 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5446 #endif /* not USE_X_TOOLKIT */
5449 x_wm_set_icon_pixmap (f
, pixmap_id
)
5453 #ifdef USE_X_TOOLKIT
5454 Window window
= XtWindow (f
->display
.x
->widget
);
5456 Window window
= FRAME_X_WINDOW (f
);
5461 Pixmap icon_pixmap
= x_lookup_pixmap (pixmap_id
);
5462 f
->display
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
5463 f
->display
.x
->wm_hints
.flags
|= IconPixmapHint
;
5467 f
->display
.x
->wm_hints
.icon_pixmap
= None
;
5468 f
->display
.x
->wm_hints
.flags
&= ~IconPixmapHint
;
5471 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5474 x_wm_set_icon_position (f
, icon_x
, icon_y
)
5478 #ifdef USE_X_TOOLKIT
5479 Window window
= XtWindow (f
->display
.x
->widget
);
5481 Window window
= FRAME_X_WINDOW (f
);
5484 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
5485 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
5486 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
5488 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5492 /* Initialization. */
5494 #ifdef USE_X_TOOLKIT
5495 static XrmOptionDescRec emacs_options
[] = {
5496 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
5497 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
5499 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
5500 XrmoptionSepArg
, NULL
},
5501 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
5503 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5504 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5505 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5506 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5507 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5508 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
5509 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
5511 #endif /* USE_X_TOOLKIT */
5514 x_term_init (display_name
, xrm_option
, resource_name
)
5517 char *resource_name
;
5523 #ifndef F_SETOWN_BUG
5525 extern int old_fcntl_owner
;
5526 #endif /* ! defined (F_SETOWN) */
5527 #endif /* F_SETOWN_BUG */
5531 x_focus_frame
= x_highlight_frame
= 0;
5533 #ifdef USE_X_TOOLKIT
5535 XtSetLanguageProc (NULL
, NULL
, NULL
);
5538 argv
= (char **) XtMalloc (7 * sizeof (char *));
5540 argv
[1] = "-display";
5541 argv
[2] = display_name
;
5543 /* Usually `emacs', but not always. */
5544 argv
[4] = resource_name
;
5548 argv
[argc
++] = "-xrm";
5549 argv
[argc
++] = xrm_option
;
5551 Xt_app_shell
= XtAppInitialize (&Xt_app_con
, "Emacs",
5552 emacs_options
, XtNumber (emacs_options
),
5555 XtFree ((char *)argv
);
5556 x_current_display
= XtDisplay (Xt_app_shell
);
5558 #else /* not USE_X_TOOLKIT */
5560 XSetLocaleModifiers ("");
5562 x_current_display
= XOpenDisplay (display_name
);
5563 #endif /* not USE_X_TOOLKIT */
5564 if (x_current_display
== 0)
5565 fatal ("X server %s not responding.\n\
5566 Check the DISPLAY environment variable or use \"-d\"\n",
5571 XSetAfterFunction (x_current_display
, x_trace_wire
);
5573 x_id_name
= (char *) xmalloc (XSTRING (Vinvocation_name
)->size
5574 + XSTRING (Vsystem_name
)->size
5576 sprintf (x_id_name
, "%s@%s",
5577 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
5580 /* Figure out which modifier bits mean what. */
5581 x_find_modifier_meanings ();
5583 /* Get the scroll bar cursor. */
5584 x_vertical_scroll_bar_cursor
5585 = XCreateFontCursor (x_current_display
, XC_sb_v_double_arrow
);
5588 /* Watch for PropertyNotify events on the root window; we use them
5589 to figure out when to invalidate our cache of the cut buffers. */
5590 x_watch_cut_buffer_cache ();
5594 /* This is only needed for distinguishing keyboard and process input. */
5595 if (ConnectionNumber (x_current_display
) != 0)
5596 change_keyboard_wait_descriptor (ConnectionNumber (x_current_display
));
5598 change_input_fd (ConnectionNumber (x_current_display
));
5600 #ifndef F_SETOWN_BUG
5602 old_fcntl_owner
= fcntl (ConnectionNumber (x_current_display
), F_GETOWN
, 0);
5603 #ifdef F_SETOWN_SOCK_NEG
5604 /* stdin is a socket here */
5605 fcntl (ConnectionNumber (x_current_display
), F_SETOWN
, -getpid ());
5606 #else /* ! defined (F_SETOWN_SOCK_NEG) */
5607 fcntl (ConnectionNumber (x_current_display
), F_SETOWN
, getpid ());
5608 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
5609 #endif /* ! defined (F_SETOWN) */
5610 #endif /* F_SETOWN_BUG */
5614 #endif /* ! defined (SIGIO) */
5616 expose_all_windows
= 0;
5618 clear_frame_hook
= XTclear_frame
;
5619 clear_end_of_line_hook
= XTclear_end_of_line
;
5620 ins_del_lines_hook
= XTins_del_lines
;
5621 change_line_highlight_hook
= XTchange_line_highlight
;
5622 insert_glyphs_hook
= XTinsert_glyphs
;
5623 write_glyphs_hook
= XTwrite_glyphs
;
5624 delete_glyphs_hook
= XTdelete_glyphs
;
5625 ring_bell_hook
= XTring_bell
;
5626 reset_terminal_modes_hook
= XTreset_terminal_modes
;
5627 set_terminal_modes_hook
= XTset_terminal_modes
;
5628 update_begin_hook
= XTupdate_begin
;
5629 update_end_hook
= XTupdate_end
;
5630 set_terminal_window_hook
= XTset_terminal_window
;
5631 read_socket_hook
= XTread_socket
;
5632 frame_up_to_date_hook
= XTframe_up_to_date
;
5633 cursor_to_hook
= XTcursor_to
;
5634 reassert_line_highlight_hook
= XTreassert_line_highlight
;
5635 mouse_position_hook
= XTmouse_position
;
5636 frame_rehighlight_hook
= XTframe_rehighlight
;
5637 frame_raise_lower_hook
= XTframe_raise_lower
;
5638 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
5639 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
5640 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
5641 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
5643 scroll_region_ok
= 1; /* we'll scroll partial frames */
5644 char_ins_del_ok
= 0; /* just as fast to write the line */
5645 line_ins_del_ok
= 1; /* we'll just blt 'em */
5646 fast_clear_end_of_line
= 1; /* X does this well */
5647 memory_below_frame
= 0; /* we don't remember what scrolls
5651 /* Try to use interrupt input; if we can't, then start polling. */
5652 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
5654 /* Note that there is no real way portable across R3/R4 to get the
5655 original error handler. */
5656 XHandleError (x_error_quitter
);
5657 XHandleIOError (x_io_error_quitter
);
5659 /* Disable Window Change signals; they are handled by X events. */
5661 signal (SIGWINCH
, SIG_DFL
);
5662 #endif /* ! defined (SIGWINCH) */
5664 signal (SIGPIPE
, x_connection_closed
);
5670 staticpro (&last_mouse_scroll_bar
);
5671 last_mouse_scroll_bar
= Qnil
;
5672 staticpro (&mouse_face_window
);
5673 mouse_face_window
= Qnil
;
5675 #endif /* ! defined (HAVE_X_WINDOWS) */