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 #define NEW_SELECTIONS
24 /* On 4.3 these lose if they come after xterm.h. */
25 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
26 /* Putting these at the beginning seems to be standard for other .c files. */
32 /* Need syssignal.h for various externs and definitions that may be required
33 by some configurations for calls to signal later in this source file. */
34 #include "syssignal.h"
39 #include "blockinput.h"
41 /* This may include sys/types.h, and that somehow loses
42 if this is not done before the other system files. */
44 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
55 #include <sys/ioctl.h>
57 #else /* ! defined (BSD) */
61 #endif /* ! defined (BSD) */
66 #ifndef INCLUDED_FCNTL
73 #include <sys/param.h>
75 #include "dispextern.h"
76 #include "termhooks.h"
90 extern XtAppContext Xt_app_con
;
91 extern Widget Xt_app_shell
;
92 extern void free_frame_menubar ();
93 #endif /* USE_X_TOOLKIT */
96 #define x_any_window_to_frame x_window_to_frame
100 #define XMapWindow XMapRaised /* Raise them when mapping. */
101 #else /* ! defined (HAVE_X11) */
102 #include <X/Xkeyboard.h>
103 /*#include <X/Xproto.h> */
104 #endif /* ! defined (HAVE_X11) */
107 /* We could get this from param.h, but better not to depend on finding that.
108 And better not to risk that it might define other symbols used in this
111 #define MAXDESC FD_SETSIZE
115 #define SELECT_TYPE fd_set
116 #else /* no FD_SET */
118 #define SELECT_TYPE int
120 /* Define the macros to access a single-int bitmap of descriptors. */
121 #define FD_SET(n, p) (*(p) |= (1 << (n)))
122 #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
123 #define FD_ISSET(n, p) (*(p) & (1 << (n)))
124 #define FD_ZERO(p) (*(p) = 0)
125 #endif /* no FD_SET */
127 /* For sending Meta-characters. Do we need this? */
130 #define min(a,b) ((a)<(b) ? (a) : (b))
131 #define max(a,b) ((a)>(b) ? (a) : (b))
133 /* Nonzero means we must reprint all windows
134 because 1) we received an ExposeWindow event
135 or 2) we received too many ExposeRegion events to record.
137 This is never needed under X11. */
138 static int expose_all_windows
;
140 /* Nonzero means we must reprint all icon windows. */
142 static int expose_all_icons
;
145 /* ExposeRegion events, when received, are copied into this queue
146 for later processing. */
148 static struct event_queue x_expose_queue
;
150 /* ButtonPress and ButtonReleased events, when received,
151 are copied into this queue for later processing. */
153 struct event_queue x_mouse_queue
;
154 #endif /* HAVE_X11 */
156 #if defined (SIGIO) && defined (FIONREAD)
157 int BLOCK_INPUT_mask
;
158 #endif /* ! defined (SIGIO) && defined (FIONREAD) */
160 /* The id of a bitmap used for icon windows.
161 One such map is shared by all Emacs icon windows.
162 This is zero if we have not yet had a need to create the bitmap. */
164 static Bitmap icon_bitmap
;
166 /* Font used for text icons. */
168 static FONT_TYPE
*icon_font_info
;
170 /* Stuff for dealing with the main icon title. */
172 extern Lisp_Object Vcommand_line_args
;
173 char *hostname
, *x_id_name
;
175 /* This is the X connection that we are using. */
177 Display
*x_current_display
;
179 /* The cursor to use for vertical scroll bars on x_current_display. */
180 static Cursor x_vertical_scroll_bar_cursor
;
182 /* Frame being updated by update_frame. This is declared in term.c.
183 This is set by update_begin and looked at by all the
184 XT functions. It is zero while not inside an update.
185 In that case, the XT functions assume that `selected_frame'
186 is the frame to apply to. */
187 extern struct frame
*updating_frame
;
189 /* The frame (if any) which has the X window that has keyboard focus.
190 Zero if none. This is examined by Ffocus_frame in frame.c. Note
191 that a mere EnterNotify event can set this; if you need to know the
192 last frame specified in a FocusIn or FocusOut event, use
193 x_focus_event_frame. */
194 struct frame
*x_focus_frame
;
196 /* The last frame mentioned in a FocusIn or FocusOut event. This is
197 separate from x_focus_frame, because whether or not LeaveNotify
198 events cause us to lose focus depends on whether or not we have
199 received a FocusIn event for it. */
200 struct frame
*x_focus_event_frame
;
202 /* The frame which currently has the visual highlight, and should get
203 keyboard input (other sorts of input have the frame encoded in the
204 event). It points to the X focus frame's selected window's
205 frame. It differs from x_focus_frame when we're using a global
207 static struct frame
*x_highlight_frame
;
209 /* From .Xdefaults, the value of "emacs.WarpMouse". If non-zero,
210 mouse is moved to inside of frame when frame is de-iconified. */
212 static int warp_mouse_on_deiconify
;
214 /* During an update, maximum vpos for ins/del line operations to affect. */
216 static int flexlines
;
218 /* During an update, nonzero if chars output now should be highlighted. */
220 static int highlight
;
222 /* Nominal cursor position -- where to draw output.
223 During an update, these are different from the cursor-box position. */
230 In order to avoid asking for motion events and then throwing most
231 of them away or busy-polling the server for mouse positions, we ask
232 the server for pointer motion hints. This means that we get only
233 one event per group of mouse movements. "Groups" are delimited by
234 other kinds of events (focus changes and button clicks, for
235 example), or by XQueryPointer calls; when one of these happens, we
236 get another MotionNotify event the next time the mouse moves. This
237 is at least as efficient as getting motion events when mouse
238 tracking is on, and I suspect only negligibly worse when tracking
241 The silly O'Reilly & Associates Nutshell guides barely document
242 pointer motion hints at all (I think you have to infer how they
243 work from an example), and the description of XQueryPointer doesn't
244 mention that calling it causes you to get another motion hint from
245 the server, which is very important. */
247 /* Where the mouse was last time we reported a mouse event. */
248 static FRAME_PTR last_mouse_frame
;
249 static XRectangle last_mouse_glyph
;
251 /* The scroll bar in which the last X motion event occurred.
253 If the last X motion event occurred in a scroll bar, we set this
254 so XTmouse_position can know whether to report a scroll bar motion or
257 If the last X motion event didn't occur in a scroll bar, we set this
258 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
259 static Lisp_Object last_mouse_scroll_bar
;
261 /* Record which buttons are currently pressed. */
262 unsigned int x_mouse_grabbed
;
264 /* This is a hack. We would really prefer that XTmouse_position would
265 return the time associated with the position it returns, but there
266 doesn't seem to be any way to wrest the timestamp from the server
267 along with the position query. So, we just keep track of the time
268 of the last movement we received, and return that in hopes that
269 it's somewhat accurate. */
270 static Time last_mouse_movement_time
;
272 /* These variables describe the range of text currently shown
273 in its mouse-face, together with the window they apply to.
274 As long as the mouse stays within this range, we need not
275 redraw anything on its account. */
276 static int mouse_face_beg
, mouse_face_end
;
277 static Lisp_Object mouse_face_window
;
278 static int mouse_face_face_id
;
280 /* 1 if a mouse motion event came and we didn't handle it right away because
281 gc was in progress. */
282 static int mouse_face_deferred_gc
;
284 /* FRAME and X, Y position of mouse when last checked for highlighting. */
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
;
292 /* `t' if a mouse button is depressed. */
294 extern Lisp_Object Vmouse_depressed
;
296 /* Tells if a window manager is present or not. */
298 extern Lisp_Object Vx_no_window_manager
;
300 /* Timestamp that we requested selection data was made. */
301 extern Time requestor_time
;
303 /* ID of the window requesting selection data. */
304 extern Window requestor_window
;
306 /* Nonzero enables some debugging for the X interface code. */
309 extern Qface
, Qmouse_face
;
311 #else /* ! defined (HAVE_X11) */
313 /* Bit patterns for the mouse cursor. */
315 short MouseCursor
[] = {
316 0x0000, 0x0008, 0x0018, 0x0038,
317 0x0078, 0x00f8, 0x01f8, 0x03f8,
318 0x07f8, 0x00f8, 0x00d8, 0x0188,
319 0x0180, 0x0300, 0x0300, 0x0000};
321 short MouseMask
[] = {
322 0x000c, 0x001c, 0x003c, 0x007c,
323 0x00fc, 0x01fc, 0x03fc, 0x07fc,
324 0x0ffc, 0x0ffc, 0x01fc, 0x03dc,
325 0x03cc, 0x0780, 0x0780, 0x0300};
327 static short grey_bits
[] = {
328 0x0005, 0x000a, 0x0005, 0x000a};
330 static Pixmap GreyPixmap
= 0;
331 #endif /* ! defined (HAVE_X11) */
333 /* From time to time we get info on an Emacs window, here. */
335 static WINDOWINFO_TYPE windowinfo
;
339 /* A mask of extra modifier bits to put into every keyboard char. */
340 extern int extra_keyboard_modifiers
;
342 extern Display
*XOpenDisplay ();
343 extern Window
XCreateWindow ();
345 extern Cursor
XCreateCursor ();
346 extern FONT_TYPE
*XOpenFont ();
348 static void flashback ();
349 static void redraw_previous_char ();
350 static unsigned int x_x_to_emacs_modifiers ();
352 static void note_mouse_highlight ();
353 static void clear_mouse_face ();
354 static void show_mouse_face ();
357 static void dumpqueue ();
358 #endif /* HAVE_X11 */
361 static int XTcursor_to ();
362 static int XTclear_end_of_line ();
365 /* Starting and ending updates.
367 These hooks are called by update_frame at the beginning and end
368 of a frame update. We record in `updating_frame' the identity
369 of the frame being updated, so that the XT... functions do not
370 need to take a frame as argument. Most of the XT... functions
371 should never be called except during an update, the only exceptions
372 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
374 extern int mouse_track_top
, mouse_track_left
, mouse_track_width
;
385 flexlines
= f
->height
;
390 if (f
== mouse_face_mouse_frame
)
392 /* Don't do highlighting for mouse motion during the update. */
393 mouse_face_defer
= 1;
394 if (!NILP (mouse_face_window
))
396 int firstline
, lastline
, i
;
397 struct window
*w
= XWINDOW (mouse_face_window
);
399 /* Find the first, and the last+1, lines affected by redisplay. */
400 for (firstline
= 0; firstline
< f
->height
; firstline
++)
401 if (FRAME_DESIRED_GLYPHS (f
)->enable
[firstline
])
404 lastline
= f
->height
;
405 for (i
= f
->height
- 1; i
>= 0; i
--)
407 if (FRAME_DESIRED_GLYPHS (f
)->enable
[i
])
413 /* Can we tell that this update does not affect the window
414 where the mouse highlight is? If so, no need to turn off. */
415 if (! (firstline
> (XFASTINT (w
->top
) + window_internal_height (w
))
416 || lastline
< XFASTINT (w
->top
)))
417 /* Otherwise turn off the mouse highlight now. */
423 #endif /* HAVE_X11 */
428 static void x_do_pending_expose ();
440 x_do_pending_expose ();
441 #endif /* HAVE_X11 */
443 x_display_cursor (f
, 1);
445 if (f
== mouse_face_mouse_frame
)
446 mouse_face_defer
= 0;
448 /* This fails in the case of having updated only the echo area
449 if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS
450 has no relation to the current contents, and its charstarts
451 have no relation to the contents of the window-buffer.
452 I don't know a clean way to check
453 for that case. window_end_valid isn't set up yet. */
454 if (f
== mouse_face_mouse_frame
)
455 note_mouse_highlight (f
, mouse_face_mouse_x
, mouse_face_mouse_y
);
462 /* This is called after a redisplay on frame F. */
465 XTframe_up_to_date (f
)
468 if (mouse_face_deferred_gc
|| f
== mouse_face_mouse_frame
)
470 note_mouse_highlight (mouse_face_mouse_frame
,
471 mouse_face_mouse_x
, mouse_face_mouse_y
);
472 mouse_face_deferred_gc
= 0;
476 /* External interface to control of standout mode.
477 Call this when about to modify line at position VPOS
478 and not change whether it is highlighted. */
480 XTreassert_line_highlight (new, vpos
)
486 /* Call this when about to modify line at position VPOS
487 and change whether it is highlighted. */
490 XTchange_line_highlight (new_highlight
, vpos
, first_unused_hpos
)
491 int new_highlight
, vpos
, first_unused_hpos
;
493 highlight
= new_highlight
;
494 XTcursor_to (vpos
, 0);
495 XTclear_end_of_line (updating_frame
->width
);
498 /* This is used when starting Emacs and when restarting after suspend.
499 When starting Emacs, no X window is mapped. And nothing must be done
500 to Emacs's own window if it is suspended (though that rarely happens). */
503 XTset_terminal_modes ()
507 /* This is called when exiting or suspending Emacs.
508 Exiting will make the X-windows go away, and suspending
509 requires no action. */
512 XTreset_terminal_modes ()
514 /* XTclear_frame (); */
517 /* Set the nominal cursor position of the frame.
518 This is where display update commands will take effect.
519 This does not affect the place where the cursor-box is displayed. */
522 XTcursor_to (row
, col
)
523 register int row
, col
;
531 if (updating_frame
== 0)
534 x_display_cursor (selected_frame
, 1);
540 /* Display a sequence of N glyphs found at GP.
541 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
542 HL is 1 if this text is highlighted, 2 if the cursor is on it,
543 3 if should appear in its mouse-face.
545 FONT is the default font to use (for glyphs whose font-code is 0).
547 Since the display generation code is responsible for calling
548 compute_char_face and compute_glyph_face on everything it puts in
549 the display structure, we can assume that the face code on each
550 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
551 to which we can actually apply intern_face.
552 Call this function with input blocked. */
555 /* This is the multi-face code. */
558 dumpglyphs (f
, left
, top
, gp
, n
, hl
)
561 register GLYPH
*gp
; /* Points to first GLYPH. */
562 register int n
; /* Number of glyphs to display. */
565 /* Holds characters to be displayed. */
566 char *buf
= (char *) alloca (f
->width
* sizeof (*buf
));
567 register char *cp
; /* Steps through buf[]. */
568 register int tlen
= GLYPH_TABLE_LENGTH
;
569 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
570 Window window
= FRAME_X_WINDOW (f
);
574 /* Get the face-code of the next GLYPH. */
578 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
579 cf
= FAST_GLYPH_FACE (g
);
581 /* Find the run of consecutive glyphs with the same face-code.
582 Extract their character codes into BUF. */
587 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
588 if (FAST_GLYPH_FACE (g
) != cf
)
591 *cp
++ = FAST_GLYPH_CHAR (g
);
596 /* LEN gets the length of the run. */
599 /* Now output this run of chars, with the font and pixel values
600 determined by the face code CF. */
602 struct face
*face
= FRAME_DEFAULT_FACE (f
);
603 FONT_TYPE
*font
= FACE_FONT (face
);
604 GC gc
= FACE_GC (face
);
606 int gc_temporary
= 0;
608 /* HL = 3 means use a mouse face previously chosen. */
610 cf
= mouse_face_face_id
;
612 /* First look at the face of the text itself. */
615 /* It's possible for the display table to specify
616 a face code that is out of range. Use 0 in that case. */
617 if (cf
< 0 || cf
>= FRAME_N_COMPUTED_FACES (f
)
618 || FRAME_COMPUTED_FACES (f
) [cf
] == 0)
622 face
= FRAME_MODE_LINE_FACE (f
);
624 face
= intern_face (f
, FRAME_COMPUTED_FACES (f
) [cf
]);
625 font
= FACE_FONT (face
);
630 /* Then comes the distinction between modeline and normal text. */
635 face
= FRAME_MODE_LINE_FACE (f
);
636 font
= FACE_FONT (face
);
641 #define FACE_DEFAULT (~0)
643 /* Now override that if the cursor's on this character. */
648 || (int) face
->font
== FACE_DEFAULT
)
650 gc
= f
->display
.x
->cursor_gc
;
652 /* Cursor on non-default face: must merge. */
658 xgcv
.background
= f
->display
.x
->cursor_pixel
;
659 if (face
== FRAME_DEFAULT_FACE (f
))
660 xgcv
.foreground
= f
->display
.x
->cursor_foreground_pixel
;
662 xgcv
.foreground
= face
->foreground
;
663 /* If the glyph would be invisible,
664 try a different foreground. */
665 if (xgcv
.foreground
== xgcv
.background
)
666 xgcv
.foreground
= face
->background
;
667 if (xgcv
.foreground
== xgcv
.background
)
668 xgcv
.foreground
= f
->display
.x
->cursor_foreground_pixel
;
669 if (xgcv
.foreground
== xgcv
.background
)
670 xgcv
.foreground
= face
->foreground
;
671 /* Make sure the cursor is distinct from text in this face. */
672 if (xgcv
.background
== face
->background
673 && xgcv
.foreground
== face
->foreground
)
675 xgcv
.background
= face
->foreground
;
676 xgcv
.foreground
= face
->background
;
678 xgcv
.font
= face
->font
->fid
;
679 xgcv
.graphics_exposures
= 0;
680 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
681 gc
= XCreateGC (x_current_display
, FRAME_X_WINDOW (f
),
684 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
685 XSetStipple (x_current_display
, gc
, face
->stipple
);
691 if ((int) font
== FACE_DEFAULT
)
692 font
= f
->display
.x
->font
;
694 XDrawImageString (x_current_display
, window
, gc
,
695 left
, top
+ FONT_BASE (font
), buf
, len
);
698 XFreeGC (x_current_display
, gc
);
700 /* We should probably check for XA_UNDERLINE_POSITION and
701 XA_UNDERLINE_THICKNESS properties on the font, but let's
702 just get the thing working, and come back to that. */
704 int underline_position
= 1;
706 if (font
->descent
<= underline_position
)
707 underline_position
= font
->descent
- 1;
710 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
),
714 + underline_position
),
715 len
* FONT_WIDTH (font
), 1);
718 left
+= len
* FONT_WIDTH (font
);
725 /* This is the old single-face code. */
728 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
731 register GLYPH
*gp
; /* Points to first GLYPH. */
732 register int n
; /* Number of glyphs to display. */
737 Window window
= FRAME_X_WINDOW (f
);
738 GC drawing_gc
= (hl
== 2 ? f
->display
.x
->cursor_gc
739 : (hl
? f
->display
.x
->reverse_gc
740 : f
->display
.x
->normal_gc
));
742 if (sizeof (GLYPH
) == sizeof (XChar2b
))
743 XDrawImageString16 (x_current_display
, window
, drawing_gc
,
744 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
745 else if (sizeof (GLYPH
) == sizeof (unsigned char))
746 XDrawImageString (x_current_display
, window
, drawing_gc
,
747 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
749 /* What size of glyph ARE you using? And does X have a function to
755 /* Output some text at the nominal frame cursor position.
756 Advance the cursor over the text.
757 Output LEN glyphs at START.
759 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
760 controls the pixel values used for foreground and background. */
763 XTwrite_glyphs (start
, len
)
764 register GLYPH
*start
;
767 register int temp_length
;
777 /* If not within an update,
778 output at the frame's visible cursor. */
779 curs_x
= f
->cursor_x
;
780 curs_y
= f
->cursor_y
;
784 CHAR_TO_PIXEL_COL (f
, curs_x
),
785 CHAR_TO_PIXEL_ROW (f
, curs_y
),
786 start
, len
, highlight
);
788 /* If we drew on top of the cursor, note that it is turned off. */
789 if (curs_y
== f
->phys_cursor_y
790 && curs_x
<= f
->phys_cursor_x
791 && curs_x
+ len
> f
->phys_cursor_x
)
792 f
->phys_cursor_x
= -1;
794 if (updating_frame
== 0)
797 x_display_cursor (f
, 1);
806 /* Clear to the end of the line.
807 Erase the current text line from the nominal cursor position (inclusive)
808 to column FIRST_UNUSED (exclusive). The idea is that everything
809 from FIRST_UNUSED onward is already erased. */
812 XTclear_end_of_line (first_unused
)
813 register int first_unused
;
815 struct frame
*f
= updating_frame
;
821 if (curs_y
< 0 || curs_y
>= f
->height
)
823 if (first_unused
<= 0)
826 if (first_unused
>= f
->width
)
827 first_unused
= f
->width
;
831 /* Notice if the cursor will be cleared by this operation. */
832 if (curs_y
== f
->phys_cursor_y
833 && curs_x
<= f
->phys_cursor_x
834 && f
->phys_cursor_x
< first_unused
)
835 f
->phys_cursor_x
= -1;
838 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
839 CHAR_TO_PIXEL_COL (f
, curs_x
),
840 CHAR_TO_PIXEL_ROW (f
, curs_y
),
841 FONT_WIDTH (f
->display
.x
->font
) * (first_unused
- curs_x
),
842 f
->display
.x
->line_height
, False
);
844 redraw_previous_char (f
, curs_x
, curs_y
);
846 #else /* ! defined (HAVE_X11) */
847 XPixSet (FRAME_X_WINDOW (f
),
848 CHAR_TO_PIXEL_COL (f
, curs_x
),
849 CHAR_TO_PIXEL_ROW (f
, curs_y
),
850 FONT_WIDTH (f
->display
.x
->font
) * (first_unused
- curs_x
),
851 f
->display
.x
->line_height
,
852 f
->display
.x
->background_pixel
);
853 #endif /* ! defined (HAVE_X11) */
858 /* Erase the character (if any) at the position just before X, Y in frame F,
859 then redraw it and the character before it.
860 This is necessary when we erase starting at X,
861 in case the character after X overlaps into the one before X.
862 Call this function with input blocked. */
865 redraw_previous_char (f
, x
, y
)
869 /* Erase the character before the new ones, in case
870 what was here before overlaps it.
871 Reoutput that character, and the previous character
872 (in case the previous character overlaps it). */
878 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
879 CHAR_TO_PIXEL_COL (f
, x
- 1),
880 CHAR_TO_PIXEL_ROW (f
, y
),
881 FONT_WIDTH (f
->display
.x
->font
),
882 f
->display
.x
->line_height
, False
);
884 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
885 CHAR_TO_PIXEL_ROW (f
, y
),
886 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
887 x
- start_x
, highlight
);
895 struct frame
*f
= updating_frame
;
900 f
->phys_cursor_x
= -1; /* Cursor not visible. */
901 curs_x
= 0; /* Nominal cursor position is top left. */
906 XClear (FRAME_X_WINDOW (f
));
908 /* We have to clear the scroll bars, too. If we have changed
909 colors or something like that, then they should be notified. */
910 x_scroll_bar_clear (f
);
914 #endif /* HAVE_X11 */
920 /* Invert the middle quarter of the frame for .15 sec. */
922 /* We use the select system call to do the waiting, so we have to make sure
923 it's available. If it isn't, we just won't do visual bells. */
924 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
926 /* Subtract the `struct timeval' values X and Y,
927 storing the result in RESULT.
928 Return 1 if the difference is negative, otherwise 0. */
931 timeval_subtract (result
, x
, y
)
932 struct timeval
*result
, x
, y
;
934 /* Perform the carry for the later subtraction by updating y.
935 This is safer because on some systems
936 the tv_sec member is unsigned. */
937 if (x
.tv_usec
< y
.tv_usec
)
939 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
940 y
.tv_usec
-= 1000000 * nsec
;
943 if (x
.tv_usec
- y
.tv_usec
> 1000000)
945 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
946 y
.tv_usec
+= 1000000 * nsec
;
950 /* Compute the time remaining to wait. tv_usec is certainly positive. */
951 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
952 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
954 /* Return indication of whether the result should be considered negative. */
955 return x
.tv_sec
< y
.tv_sec
;
966 /* Create a GC that will use the GXxor function to flip foreground pixels
967 into background pixels. */
971 values
.function
= GXxor
;
972 values
.foreground
= (f
->display
.x
->foreground_pixel
973 ^ f
->display
.x
->background_pixel
);
975 gc
= XCreateGC (x_current_display
, FRAME_X_WINDOW (f
),
976 GCFunction
| GCForeground
, &values
);
980 int width
= PIXEL_WIDTH (f
);
981 int height
= PIXEL_HEIGHT (f
);
983 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
), gc
,
984 width
/4, height
/4, width
/2, height
/2);
985 XFlush (x_current_display
);
988 struct timeval wakeup
, now
;
990 EMACS_GET_TIME (wakeup
);
992 /* Compute time to wait until, propagating carry from usecs. */
993 wakeup
.tv_usec
+= 150000;
994 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
995 wakeup
.tv_usec
%= 1000000;
997 /* Keep waiting until past the time wakeup. */
1000 struct timeval timeout
;
1002 EMACS_GET_TIME (timeout
);
1004 /* In effect, timeout = wakeup - timeout.
1005 Break if result would be negative. */
1006 if (timeval_subtract (&timeout
, wakeup
, timeout
))
1009 /* Try to wait that long--but we might wake up sooner. */
1010 select (0, 0, 0, 0, &timeout
);
1014 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
), gc
,
1015 width
/4, height
/4, width
/2, height
/2);
1016 XFreeGC (x_current_display
, gc
);
1017 XFlush (x_current_display
);
1027 /* Make audible bell. */
1030 #define XRINGBELL XBell (x_current_display, 0)
1031 #else /* ! defined (HAVE_X11) */
1032 #define XRINGBELL XFeep (0);
1033 #endif /* ! defined (HAVE_X11) */
1037 if (x_current_display
== 0)
1040 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
1042 XTflash (selected_frame
);
1053 /* Insert and delete character.
1054 These are not supposed to be used because we are supposed to turn
1055 off the feature of using them. */
1058 XTinsert_glyphs (start
, len
)
1059 register char *start
;
1072 /* Specify how many text lines, from the top of the window,
1073 should be affected by insert-lines and delete-lines operations.
1074 This, and those operations, are used only within an update
1075 that is bounded by calls to XTupdate_begin and XTupdate_end. */
1078 XTset_terminal_window (n
)
1081 if (updating_frame
== 0)
1084 if ((n
<= 0) || (n
> updating_frame
->height
))
1085 flexlines
= updating_frame
->height
;
1090 /* Perform an insert-lines operation.
1091 Insert N lines at a vertical position curs_y. */
1097 register int topregion
, bottomregion
;
1098 register int length
, newtop
, mask
;
1099 register struct frame
*f
= updating_frame
;
1100 int intborder
= f
->display
.x
->internal_border_width
;
1102 if (curs_y
>= flexlines
)
1106 bottomregion
= flexlines
- (n
+ 1);
1107 newtop
= topregion
+ n
;
1108 length
= (bottomregion
- topregion
) + 1;
1112 #endif /* HAVE_X11 */
1114 if ((length
> 0) && (newtop
<= flexlines
))
1117 XCopyArea (x_current_display
, FRAME_X_WINDOW (f
),
1118 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1119 intborder
, CHAR_TO_PIXEL_ROW (f
, topregion
),
1120 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1121 length
* f
->display
.x
->line_height
, intborder
,
1122 CHAR_TO_PIXEL_ROW (f
, newtop
));
1123 #else /* ! defined (HAVE_X11) */
1124 XMoveArea (FRAME_X_WINDOW (f
),
1125 intborder
, CHAR_TO_PIXEL_ROW (f
, topregion
),
1126 intborder
, CHAR_TO_PIXEL_ROW (f
, newtop
),
1127 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1128 length
* f
->display
.x
->line_height
);
1129 /* Now we must process any ExposeRegion events that occur
1130 if the area being copied from is obscured.
1131 We can't let it wait because further i/d operations
1132 may want to copy this area to another area. */
1134 #endif /* ! defined (HAVE_X11) */
1137 newtop
= min (newtop
, (flexlines
- 1));
1138 length
= newtop
- topregion
;
1142 XClearArea (x_current_display
, FRAME_X_WINDOW (f
), intborder
,
1143 CHAR_TO_PIXEL_ROW (f
, topregion
),
1144 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1145 n
* f
->display
.x
->line_height
, False
);
1146 #else /* ! defined (HAVE_X11) */
1147 XPixSet (FRAME_X_WINDOW (f
),
1149 CHAR_TO_PIXEL_ROW (f
, topregion
),
1150 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1151 n
* f
->display
.x
->line_height
,
1152 f
->display
.x
->background_pixel
);
1153 #endif /* ! defined (HAVE_X11) */
1157 /* Perform a delete-lines operation, deleting N lines
1158 at a vertical position curs_y. */
1165 register struct frame
*f
= updating_frame
;
1166 int intborder
= f
->display
.x
->internal_border_width
;
1168 if (curs_y
>= flexlines
)
1173 #endif /* HAVE_X11 */
1175 if ((curs_y
+ n
) >= flexlines
)
1177 if (flexlines
>= (curs_y
+ 1))
1180 XClearArea (x_current_display
, FRAME_X_WINDOW (f
), intborder
,
1181 CHAR_TO_PIXEL_ROW (f
, curs_y
),
1182 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1183 (flexlines
- curs_y
) * f
->display
.x
->line_height
, False
);
1184 #else /* ! defined (HAVE_X11) */
1185 XPixSet (FRAME_X_WINDOW (f
),
1186 intborder
, CHAR_TO_PIXEL_ROW (f
, curs_y
),
1187 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1188 (flexlines
- curs_y
) * f
->display
.x
->line_height
,
1189 f
->display
.x
->background_pixel
);
1190 #endif /* ! defined (HAVE_X11) */
1196 XCopyArea (x_current_display
, FRAME_X_WINDOW (f
),
1197 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1199 CHAR_TO_PIXEL_ROW (f
, curs_y
+ n
),
1200 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1201 (flexlines
- (curs_y
+ n
)) * f
->display
.x
->line_height
,
1202 intborder
, CHAR_TO_PIXEL_ROW (f
, curs_y
));
1203 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
1205 CHAR_TO_PIXEL_ROW (f
, flexlines
- n
),
1206 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1207 n
* f
->display
.x
->line_height
, False
);
1208 #else /* ! defined (HAVE_X11) */
1209 XMoveArea (FRAME_X_WINDOW (f
),
1211 CHAR_TO_PIXEL_ROW (f
, curs_y
+ n
),
1212 intborder
, CHAR_TO_PIXEL_ROW (f
, curs_y
),
1213 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1214 (flexlines
- (curs_y
+ n
)) * f
->display
.x
->line_height
);
1215 /* Now we must process any ExposeRegion events that occur
1216 if the area being copied from is obscured.
1217 We can't let it wait because further i/d operations
1218 may want to copy this area to another area. */
1220 XPixSet (FRAME_X_WINDOW (f
), intborder
,
1221 CHAR_TO_PIXEL_ROW (f
, flexlines
- n
),
1222 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1223 n
* f
->display
.x
->line_height
, f
->display
.x
->background_pixel
);
1224 #endif /* ! defined (HAVE_X11) */
1228 /* Perform an insert-lines or delete-lines operation,
1229 inserting N lines or deleting -N lines at vertical position VPOS. */
1231 XTins_del_lines (vpos
, n
)
1234 if (updating_frame
== 0)
1237 /* Hide the cursor. */
1238 x_display_cursor (updating_frame
, 0);
1240 XTcursor_to (vpos
, 0);
1251 /* Support routines for exposure events. */
1252 static void clear_cursor ();
1254 /* Output into a rectangle of an X-window (for frame F)
1255 the characters in f->phys_lines that overlap that rectangle.
1256 TOP and LEFT are the position of the upper left corner of the rectangle.
1257 ROWS and COLS are the size of the rectangle.
1258 Call this function with input blocked. */
1261 dumprectangle (f
, left
, top
, cols
, rows
)
1263 register int left
, top
, cols
, rows
;
1265 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1266 int cursor_cleared
= 0;
1270 if (FRAME_GARBAGED_P (f
))
1273 /* Express rectangle as four edges, instead of position-and-size. */
1274 bottom
= top
+ rows
;
1275 right
= left
+ cols
;
1277 #ifndef HAVE_X11 /* Window manger does this for X11. */
1279 int intborder
= f
->display
.x
->internal_border_width
;
1281 /* If the rectangle includes any of the internal border area,
1282 redisplay the border emphasis. */
1283 if (top
< intborder
|| left
< intborder
1284 || bottom
> intborder
+ f
->height
* f
->display
.x
->line_height
1285 || right
> intborder
+ f
->width
* f
->display
.x
->line_height
)
1288 #endif /* not HAVE_X11 Window manger does this for X11. */
1290 /* Convert rectangle edges in pixels to edges in chars.
1291 Round down for left and top, up for right and bottom. */
1292 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1293 left
= PIXEL_TO_CHAR_COL (f
, left
);
1294 bottom
+= (f
->display
.x
->line_height
- 1);
1295 right
+= (FONT_WIDTH (f
->display
.x
->font
) - 1);
1296 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1297 right
= PIXEL_TO_CHAR_COL (f
, right
);
1299 /* Clip the rectangle to what can be visible. */
1304 if (right
> f
->width
)
1306 if (bottom
> f
->height
)
1309 /* Get size in chars of the rectangle. */
1310 cols
= right
- left
;
1311 rows
= bottom
- top
;
1313 /* If rectangle has zero area, return. */
1314 if (rows
<= 0) return;
1315 if (cols
<= 0) return;
1317 /* Turn off the cursor if it is in the rectangle.
1318 We will turn it back on afterward. */
1319 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1320 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1326 /* Display the text in the rectangle, one text line at a time. */
1328 for (y
= top
; y
< bottom
; y
++)
1330 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1332 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1336 CHAR_TO_PIXEL_COL (f
, left
),
1337 CHAR_TO_PIXEL_ROW (f
, y
),
1338 line
, min (cols
, active_frame
->used
[y
] - left
),
1339 active_frame
->highlight
[y
]);
1342 /* Turn the cursor on if we turned it off. */
1345 x_display_cursor (f
, 1);
1349 /* Process all queued ExposeRegion events. */
1355 XExposeRegionEvent r
;
1357 while (dequeue_event (&r
, &x_expose_queue
))
1359 struct frame
*f
= x_window_to_frame (r
.window
);
1360 if (f
->display
.x
->icon_desc
== r
.window
)
1363 dumprectangle (f
, r
.x
, r
.y
, r
.width
, r
.height
);
1367 #endif /* HAVE_X11 */
1369 /* Process all expose events that are pending, for X10.
1370 Redraws the cursor if necessary on any frame that
1371 is not in the process of being updated with update_frame. */
1375 x_do_pending_expose ()
1379 Lisp_Object tail
, frame
;
1381 if (expose_all_windows
)
1383 expose_all_windows
= 0;
1384 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1386 register int temp_width
, temp_height
;
1389 frame
= XCONS (tail
)->car
;
1390 if (XGCTYPE (frame
) != Lisp_Frame
)
1393 if (! FRAME_X_P (f
))
1395 if (!f
->async_visible
)
1397 if (!f
->display
.x
->needs_exposure
)
1400 intborder
= f
->display
.x
->internal_border_width
;
1403 XGetWindowInfo (FRAME_X_WINDOW (f
), &windowinfo
);
1404 temp_width
= ((windowinfo
.width
- 2 * intborder
1405 - f
->display
.x
->v_scroll_bar_width
)
1406 / FONT_WIDTH (f
->display
.x
->font
));
1407 temp_height
= ((windowinfo
.height
- 2 * intborder
1408 - f
->display
.x
->h_scroll_bar_height
)
1409 / f
->display
.x
->line_height
);
1410 if (temp_width
!= f
->width
|| temp_height
!= f
->height
)
1412 change_frame_size (f
, max (1, temp_height
),
1413 max (1, temp_width
), 0, 1);
1414 x_resize_scroll_bars (f
);
1416 f
->display
.x
->left_pos
= windowinfo
.x
;
1417 f
->display
.x
->top_pos
= windowinfo
.y
;
1418 dumprectangle (f
, 0, 0, PIXEL_WIDTH (f
), PIXEL_HEIGHT (f
));
1422 f
->display
.x
->needs_exposure
= 0;
1423 if (updating_frame
!= f
)
1424 x_display_cursor (f
, 1);
1429 /* Handle any individual-rectangle expose events queued
1430 for various windows. */
1433 #else /* ! defined (HAVE_X11) */
1435 #endif /* ! defined (HAVE_X11) */
1441 frame_highlight (frame
)
1442 struct frame
*frame
;
1444 /* We used to only do this if Vx_no_window_manager was non-nil, but
1445 the ICCCM (section 4.1.6) says that the window's border pixmap
1446 and border pixel are window attributes which are "private to the
1447 client", so we can always change it to whatever we want. */
1449 XSetWindowBorder (x_current_display
, FRAME_X_WINDOW (frame
),
1450 frame
->display
.x
->border_pixel
);
1452 x_display_cursor (frame
, 1);
1456 frame_unhighlight (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 XSetWindowBorderPixmap (x_current_display
, FRAME_X_WINDOW (frame
),
1465 frame
->display
.x
->border_tile
);
1467 x_display_cursor (frame
, 1);
1469 #else /* ! defined (HAVE_X11) */
1470 /* Dump the border-emphasis of frame F.
1471 If F is selected, this is a lining of the same color as the border,
1472 just within the border, occupying a portion of the internal border.
1473 If F is not selected, it is background in the same place.
1474 If ALWAYS is 0, don't bother explicitly drawing if it's background.
1476 ALWAYS = 1 is used when a frame becomes selected or deselected.
1477 In that case, we also turn the cursor off and on again
1478 so it will appear in the proper shape (solid if selected; else hollow.) */
1481 dumpborder (f
, always
)
1485 int thickness
= f
->display
.x
->internal_border_width
/ 2;
1486 int width
= PIXEL_WIDTH (f
);
1487 int height
= PIXEL_HEIGHT (f
);
1490 if (f
!= selected_frame
)
1495 pixel
= f
->display
.x
->background_pixel
;
1499 pixel
= f
->display
.x
->border_pixel
;
1502 XPixSet (FRAME_X_WINDOW (f
), 0, 0, width
, thickness
, pixel
);
1503 XPixSet (FRAME_X_WINDOW (f
), 0, 0, thickness
, height
, pixel
);
1504 XPixSet (FRAME_X_WINDOW (f
), 0, height
- thickness
, width
,
1506 XPixSet (FRAME_X_WINDOW (f
), width
- thickness
, 0, thickness
,
1510 x_display_cursor (f
, 1);
1512 #endif /* ! defined (HAVE_X11) */
1514 static void XTframe_rehighlight ();
1516 /* The focus has changed. Update the frames as necessary to reflect
1517 the new situation. Note that we can't change the selected frame
1518 here, because the lisp code we are interrupting might become confused.
1519 Each event gets marked with the frame in which it occurred, so the
1520 lisp code can tell when the switch took place by examining the events. */
1523 x_new_focus_frame (frame
)
1524 struct frame
*frame
;
1526 struct frame
*old_focus
= x_focus_frame
;
1527 int events_enqueued
= 0;
1529 if (frame
!= x_focus_frame
)
1531 /* Set this before calling other routines, so that they see
1532 the correct value of x_focus_frame. */
1533 x_focus_frame
= frame
;
1535 if (old_focus
&& old_focus
->auto_lower
)
1536 x_lower_frame (old_focus
);
1539 selected_frame
= frame
;
1540 XSET (XWINDOW (selected_frame
->selected_window
)->frame
,
1541 Lisp_Frame
, selected_frame
);
1542 Fselect_window (selected_frame
->selected_window
);
1543 choose_minibuf_frame ();
1546 if (x_focus_frame
&& x_focus_frame
->auto_raise
)
1547 x_raise_frame (x_focus_frame
);
1550 XTframe_rehighlight ();
1554 /* The focus has changed, or we have redirected a frame's focus to
1555 another frame (this happens when a frame uses a surrogate
1556 minibuffer frame). Shift the highlight as appropriate. */
1558 XTframe_rehighlight ()
1560 struct frame
*old_highlight
= x_highlight_frame
;
1565 ((XGCTYPE (FRAME_FOCUS_FRAME (x_focus_frame
)) == Lisp_Frame
)
1566 ? XFRAME (FRAME_FOCUS_FRAME (x_focus_frame
))
1568 if (! FRAME_LIVE_P (x_highlight_frame
))
1570 FRAME_FOCUS_FRAME (x_focus_frame
) = Qnil
;
1571 x_highlight_frame
= x_focus_frame
;
1575 x_highlight_frame
= 0;
1577 if (x_highlight_frame
!= old_highlight
)
1580 frame_unhighlight (old_highlight
);
1581 if (x_highlight_frame
)
1582 frame_highlight (x_highlight_frame
);
1586 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1588 /* Which modifier keys are on which modifier bits?
1590 With each keystroke, X returns eight bits indicating which modifier
1591 keys were held down when the key was pressed. The interpretation
1592 of the top five modifier bits depends on what keys are attached
1593 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
1596 x_meta_mod_mask is a mask containing the bits used for the meta key.
1597 It may have more than one bit set, if more than one modifier bit
1598 has meta keys on it. Basically, if EVENT is a KeyPress event,
1599 the meta key is pressed if (EVENT.state & x_meta_mod_mask) != 0.
1601 x_shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
1602 lock modifier bit, or zero otherwise. Non-alphabetic keys should
1603 only be affected by the lock modifier bit if XK_Shift_Lock is in
1604 use; XK_Caps_Lock should only affect alphabetic keys. With this
1605 arrangement, the lock modifier should shift the character if
1606 (EVENT.state & x_shift_lock_mask) != 0. */
1607 static int x_meta_mod_mask
, x_shift_lock_mask
;
1609 /* These are like x_meta_mod_mask, but for different modifiers. */
1610 static int x_alt_mod_mask
, x_super_mod_mask
, x_hyper_mod_mask
;
1612 /* Initialize mode_switch_bit and modifier_meaning. */
1614 x_find_modifier_meanings ()
1616 int min_code
, max_code
;
1619 XModifierKeymap
*mods
;
1621 x_meta_mod_mask
= 0;
1622 x_shift_lock_mask
= 0;
1624 x_super_mod_mask
= 0;
1625 x_hyper_mod_mask
= 0;
1628 XDisplayKeycodes (x_current_display
, &min_code
, &max_code
);
1630 min_code
= x_current_display
->min_keycode
;
1631 max_code
= x_current_display
->max_keycode
;
1634 syms
= XGetKeyboardMapping (x_current_display
,
1635 min_code
, max_code
- min_code
+ 1,
1637 mods
= XGetModifierMapping (x_current_display
);
1639 /* Scan the modifier table to see which modifier bits the Meta and
1640 Alt keysyms are on. */
1642 int row
, col
; /* The row and column in the modifier table. */
1644 for (row
= 3; row
< 8; row
++)
1645 for (col
= 0; col
< mods
->max_keypermod
; col
++)
1648 mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
1650 /* Zeroes are used for filler. Skip them. */
1654 /* Are any of this keycode's keysyms a meta key? */
1658 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
1660 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
1666 x_meta_mod_mask
|= (1 << row
);
1671 x_alt_mod_mask
|= (1 << row
);
1676 x_hyper_mod_mask
|= (1 << row
);
1681 x_super_mod_mask
|= (1 << row
);
1685 /* Ignore this if it's not on the lock modifier. */
1686 if ((1 << row
) == LockMask
)
1687 x_shift_lock_mask
= LockMask
;
1695 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
1696 if (! x_meta_mod_mask
)
1698 x_meta_mod_mask
= x_alt_mod_mask
;
1702 /* If some keys are both alt and meta,
1703 make them just meta, not alt. */
1704 if (x_alt_mod_mask
& x_meta_mod_mask
)
1706 x_alt_mod_mask
&= ~x_meta_mod_mask
;
1709 XFree ((char *) syms
);
1710 XFreeModifiermap (mods
);
1713 /* Convert between the modifier bits X uses and the modifier bits
1716 x_x_to_emacs_modifiers (state
)
1719 return ( ((state
& (ShiftMask
| x_shift_lock_mask
)) ? shift_modifier
: 0)
1720 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
1721 | ((state
& x_meta_mod_mask
) ? meta_modifier
: 0)
1722 | ((state
& x_alt_mod_mask
) ? alt_modifier
: 0)
1723 | ((state
& x_super_mod_mask
) ? super_modifier
: 0)
1724 | ((state
& x_hyper_mod_mask
) ? hyper_modifier
: 0));
1728 x_emacs_to_x_modifiers (state
)
1731 return ( ((state
& alt_modifier
) ? x_alt_mod_mask
: 0)
1732 | ((state
& super_modifier
) ? x_super_mod_mask
: 0)
1733 | ((state
& hyper_modifier
) ? x_hyper_mod_mask
: 0)
1734 | ((state
& shift_modifier
) ? ShiftMask
: 0)
1735 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
1736 | ((state
& meta_modifier
) ? x_meta_mod_mask
: 0));
1739 /* Return true iff KEYSYM is a vendor-specific keysym that we should
1740 return as a function key. If you add a keysym to this, you should
1741 make sure that the tables make_lispy_event uses contain a suitable
1744 x_is_vendor_fkey (sym
)
1749 || (sym
== DXK_Remove
)
1755 /* Mouse clicks and mouse movement. Rah. */
1758 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
1759 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
1760 that the glyph at X, Y occupies, if BOUNDS != 0.
1761 If NOCLIP is nonzero, do not force the value into range. */
1764 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1766 register int pix_x
, pix_y
;
1767 register int *x
, *y
;
1771 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1772 even for negative values. */
1774 pix_x
-= FONT_WIDTH ((f
)->display
.x
->font
) - 1;
1776 pix_y
-= (f
)->display
.x
->line_height
- 1;
1778 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
1779 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
1783 bounds
->width
= FONT_WIDTH (f
->display
.x
->font
);
1784 bounds
->height
= f
->display
.x
->line_height
;
1785 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
1786 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
1793 else if (pix_x
> f
->width
)
1798 else if (pix_y
> f
->height
)
1807 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
1810 register int *pix_x
, *pix_y
;
1812 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
1813 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
1816 /* Prepare a mouse-event in *RESULT for placement in the input queue.
1818 If the event is a button press, then note that we have grabbed
1822 construct_mouse_click (result
, event
, f
)
1823 struct input_event
*result
;
1824 XButtonEvent
*event
;
1827 /* Make the event type no_event; we'll change that when we decide
1829 result
->kind
= mouse_click
;
1830 result
->code
= event
->button
- Button1
;
1831 result
->timestamp
= event
->time
;
1832 result
->modifiers
= (x_x_to_emacs_modifiers (event
->state
)
1833 | (event
->type
== ButtonRelease
1837 /* Notice if the mouse is still grabbed. */
1838 if (event
->type
== ButtonPress
)
1840 if (! x_mouse_grabbed
)
1841 Vmouse_depressed
= Qt
;
1842 x_mouse_grabbed
|= (1 << event
->button
);
1843 last_mouse_frame
= f
;
1845 else if (event
->type
== ButtonRelease
)
1847 x_mouse_grabbed
&= ~(1 << event
->button
);
1848 if (!x_mouse_grabbed
)
1849 Vmouse_depressed
= Qnil
;
1856 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
1857 XFASTINT (result
->x
) = column
;
1858 XFASTINT (result
->y
) = row
;
1860 XSET (result
->x
, Lisp_Int
, event
->x
);
1861 XSET (result
->y
, Lisp_Int
, event
->y
);
1862 XSET (result
->frame_or_window
, Lisp_Frame
, f
);
1866 /* Prepare a menu-event in *RESULT for placement in the input queue. */
1869 construct_menu_click (result
, event
, f
)
1870 struct input_event
*result
;
1871 XButtonEvent
*event
;
1874 /* Make the event type no_event; we'll change that when we decide
1876 result
->kind
= mouse_click
;
1877 XSET (result
->code
, Lisp_Int
, event
->button
- Button1
);
1878 result
->timestamp
= event
->time
;
1879 result
->modifiers
= (x_x_to_emacs_modifiers (event
->state
)
1880 | (event
->type
== ButtonRelease
1884 XSET (result
->x
, Lisp_Int
, event
->x
);
1885 XSET (result
->y
, Lisp_Int
, -1);
1886 XSET (result
->frame_or_window
, Lisp_Frame
, f
);
1889 /* Function to report a mouse movement to the mainstream Emacs code.
1890 The input handler calls this.
1892 We have received a mouse movement event, which is given in *event.
1893 If the mouse is over a different glyph than it was last time, tell
1894 the mainstream emacs code by setting mouse_moved. If not, ask for
1895 another motion event, so we can check again the next time it moves. */
1898 note_mouse_movement (frame
, event
)
1900 XMotionEvent
*event
;
1903 last_mouse_movement_time
= event
->time
;
1905 /* Has the mouse moved off the glyph it was on at the last sighting? */
1906 if (event
->x
< last_mouse_glyph
.x
1907 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
1908 || event
->y
< last_mouse_glyph
.y
1909 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
1912 last_mouse_scroll_bar
= Qnil
;
1914 note_mouse_highlight (frame
, event
->x
, event
->y
);
1916 /* Ask for another mouse motion event. */
1920 XQueryPointer (event
->display
, event
->window
,
1921 (Window
*) &dummy
, (Window
*) &dummy
,
1922 &dummy
, &dummy
, &dummy
, &dummy
,
1923 (unsigned int *) &dummy
);
1928 /* It's on the same glyph. Call XQueryPointer so we'll get an
1929 event the next time the mouse moves and we can see if it's
1930 *still* on the same glyph. */
1933 XQueryPointer (event
->display
, event
->window
,
1934 (Window
*) &dummy
, (Window
*) &dummy
,
1935 &dummy
, &dummy
, &dummy
, &dummy
,
1936 (unsigned int *) &dummy
);
1940 /* This is used for debugging, to turn off note_mouse_highlight. */
1941 static int disable_mouse_highlight
;
1943 /* Take proper action when the mouse has moved to position X, Y on frame F
1944 as regards highlighting characters that have mouse-face properties.
1945 Also dehighlighting chars where the mouse was before. */
1948 note_mouse_highlight (f
, x
, y
)
1951 int row
, column
, portion
;
1952 XRectangle new_glyph
;
1956 if (disable_mouse_highlight
)
1959 mouse_face_mouse_x
= x
;
1960 mouse_face_mouse_y
= y
;
1961 mouse_face_mouse_frame
= f
;
1963 if (mouse_face_defer
)
1968 mouse_face_deferred_gc
= 1;
1972 /* Find out which glyph the mouse is on. */
1973 pixel_to_glyph_coords (f
, x
, y
, &column
, &row
,
1974 &new_glyph
, x_mouse_grabbed
);
1976 /* Which window is that in? */
1977 window
= window_from_coordinates (f
, column
, row
, &portion
);
1978 w
= XWINDOW (window
);
1980 /* If we were displaying active text in another window, clear that. */
1981 if (! EQ (window
, mouse_face_window
))
1982 clear_mouse_face ();
1984 /* Are we in a window whose display is up to date? */
1985 if (WINDOWP (window
) && portion
== 0
1986 && EQ (w
->window_end_valid
, w
->buffer
))
1988 int *ptr
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[row
];
1991 /* Find which buffer position the mouse corresponds to. */
1992 for (i
= column
; i
>= 0; i
--)
1996 /* Is it outside the displayed active region (if any)? */
1998 && ! (EQ (window
, mouse_face_window
)
1999 && pos
>= mouse_face_beg
&& pos
< mouse_face_end
))
2001 Lisp_Object mouse_face
, overlay
, position
;
2002 Lisp_Object
*overlay_vec
;
2003 int len
, noverlays
, ignor1
;
2004 struct buffer
*obuf
;
2007 /* If we get an out-of-range value, return now; avoid an error. */
2008 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
2011 /* Make the window's buffer temporarily current for
2012 overlays_at and compute_char_face. */
2013 obuf
= current_buffer
;
2014 current_buffer
= XBUFFER (w
->buffer
);
2020 /* Yes. Clear the display of the old active region, if any. */
2021 clear_mouse_face ();
2023 /* Is this char mouse-active? */
2024 XSET (position
, Lisp_Int
, pos
);
2027 overlay_vec
= (Lisp_Object
*) xmalloc (len
* sizeof (Lisp_Object
));
2029 /* Put all the overlays we want in a vector in overlay_vec.
2030 Store the length in len. */
2031 noverlays
= overlays_at (XINT (pos
), 1, &overlay_vec
, &len
, &ignor1
);
2032 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
2034 /* Find the highest priority overlay that has a mouse-face prop. */
2036 for (i
= 0; i
< noverlays
; i
++)
2038 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
2039 if (!NILP (mouse_face
))
2041 overlay
= overlay_vec
[i
];
2046 /* If no overlay applies, get a text property. */
2048 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
2050 /* Handle the overlay case. */
2051 if (! NILP (overlay
))
2053 /* Find the range of text around this char that
2054 should be active. */
2055 Lisp_Object before
, after
;
2058 before
= Foverlay_start (overlay
);
2059 after
= Foverlay_end (overlay
);
2060 /* Record this as the current active region. */
2061 mouse_face_beg
= XFASTINT (before
);
2062 mouse_face_end
= XFASTINT (after
);
2063 mouse_face_window
= window
;
2064 mouse_face_face_id
= compute_char_face (f
, w
, pos
, 0, 0,
2065 &ignore
, pos
+ 1, 1);
2067 /* Display it as active. */
2068 show_mouse_face (1);
2070 /* Handle the text property case. */
2071 else if (! NILP (mouse_face
))
2073 /* Find the range of text around this char that
2074 should be active. */
2075 Lisp_Object before
, after
, beginning
, end
;
2078 beginning
= Fmarker_position (w
->start
);
2079 XSET (end
, Lisp_Int
,
2080 (BUF_Z (XBUFFER (w
->buffer
))
2081 - XFASTINT (w
->window_end_pos
)));
2083 = Fprevious_single_property_change (make_number (pos
+ 1),
2085 w
->buffer
, beginning
);
2087 = Fnext_single_property_change (position
, Qmouse_face
,
2089 /* Record this as the current active region. */
2090 mouse_face_beg
= XFASTINT (before
);
2091 mouse_face_end
= XFASTINT (after
);
2092 mouse_face_window
= window
;
2094 = compute_char_face (f
, w
, pos
, 0, 0,
2095 &ignore
, pos
+ 1, 1);
2097 /* Display it as active. */
2098 show_mouse_face (1);
2102 current_buffer
= obuf
;
2105 clear_mouse_face ();
2109 /* Find the row and column of position POS in window WINDOW.
2110 Store them in *COLUMNP and *ROWP.
2111 This assumes display in WINDOW is up to date.
2112 If POS is above start of WINDOW, return coords
2113 of start of first screen line.
2114 If POS is after end of WINDOW, return coords of end of last screen line. */
2117 fast_find_position (window
, pos
, columnp
, rowp
)
2120 int *columnp
, *rowp
;
2122 struct window
*w
= XWINDOW (window
);
2123 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2128 int height
= XFASTINT (w
->height
) - ! MINI_WINDOW_P (w
);
2129 int width
= window_internal_width (w
);
2137 int linestart
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ i
][left
];
2138 if (linestart
> pos
)
2144 charstarts
= FRAME_CURRENT_GLYPHS (f
)->charstarts
[top
+ row
];
2146 for (i
= 0; i
< width
; i
++)
2148 if (charstarts
[left
+ i
] == pos
)
2151 *columnp
= i
+ left
;
2154 else if (charstarts
[left
+ i
] > pos
)
2163 /* Display the active region described by mouse_face_*
2164 in its mouse-face if HL > 0, in its normal face if HL = 0. */
2167 show_mouse_face (hl
)
2170 int begcol
, begrow
, endcol
, endrow
;
2171 struct window
*w
= XWINDOW (mouse_face_window
);
2172 int width
= window_internal_width (w
);
2173 FRAME_PTR f
= XFRAME (WINDOW_FRAME (w
));
2175 int curs_x
= f
->phys_cursor_x
;
2176 int curs_y
= f
->phys_cursor_y
;
2179 fast_find_position (mouse_face_window
, mouse_face_beg
,
2181 fast_find_position (mouse_face_window
, mouse_face_end
,
2184 for (i
= begrow
; i
<= endrow
; i
++)
2186 int column
= (i
== begrow
? begcol
: w
->left
);
2187 int endcolumn
= (i
== endrow
? endcol
: w
->left
+ width
);
2188 endcolumn
= min (endcolumn
, FRAME_CURRENT_GLYPHS (f
)->used
[i
] - w
->left
);
2190 /* If the cursor's in the text we are about to rewrite,
2191 turn the cursor off. */
2193 && (curs_x
>= begrow
- 1 || curs_x
<= endrow
))
2195 x_display_cursor (f
, 0);
2200 CHAR_TO_PIXEL_COL (f
, column
),
2201 CHAR_TO_PIXEL_ROW (f
, i
),
2202 FRAME_CURRENT_GLYPHS (f
)->glyphs
[i
] + column
,
2204 /* Highlight with mouse face if hl > 0. */
2208 /* If we turned the cursor off, turn it back on. */
2210 x_display_cursor (f
, 1);
2212 /* Change the mouse cursor according to the value of HL. */
2214 XDefineCursor (XDISPLAY
FRAME_X_WINDOW (f
), f
->display
.x
->cross_cursor
);
2216 XDefineCursor (XDISPLAY
FRAME_X_WINDOW (f
), f
->display
.x
->text_cursor
);
2219 /* Clear out the mouse-highlighted active region.
2220 Redraw it unhighlighted first. */
2225 if (! NILP (mouse_face_window
))
2226 show_mouse_face (0);
2228 mouse_face_beg
= -1;
2229 mouse_face_end
= -1;
2230 mouse_face_window
= Qnil
;
2233 static struct scroll_bar
*x_window_to_scroll_bar ();
2234 static void x_scroll_bar_report_motion ();
2236 /* Return the current position of the mouse.
2238 If the mouse movement started in a scroll bar, set *f, *bar_window,
2239 and *part to the frame, window, and scroll bar part that the mouse
2240 is over. Set *x and *y to the portion and whole of the mouse's
2241 position on the scroll bar.
2243 If the mouse movement started elsewhere, set *f to the frame the
2244 mouse is on, *bar_window to nil, and *x and *y to the character cell
2247 Set *time to the server timestamp for the time at which the mouse
2248 was at this position.
2250 Don't store anything if we don't have a valid set of values to report.
2252 This clears the mouse_moved flag, so we can wait for the next mouse
2253 movement. This also calls XQueryPointer, which will cause the
2254 server to give us another MotionNotify when the mouse moves
2258 XTmouse_position (f
, bar_window
, part
, x
, y
, time
)
2260 Lisp_Object
*bar_window
;
2261 enum scroll_bar_part
*part
;
2263 unsigned long *time
;
2269 if (! NILP (last_mouse_scroll_bar
))
2270 x_scroll_bar_report_motion (f
, bar_window
, part
, x
, y
, time
);
2276 Window dummy_window
;
2280 last_mouse_scroll_bar
= Qnil
;
2282 /* Figure out which root window we're on. */
2283 XQueryPointer (x_current_display
,
2284 DefaultRootWindow (x_current_display
),
2286 /* The root window which contains the pointer. */
2289 /* Trash which we can't trust if the pointer is on
2290 a different screen. */
2293 /* The position on that root window. */
2296 /* More trash we can't trust. */
2299 /* Modifier keys and pointer buttons, about which
2301 (unsigned int *) &dummy
);
2303 /* Now we have a position on the root; find the innermost window
2304 containing the pointer. */
2308 int parent_x
, parent_y
;
2312 if (x_mouse_grabbed
)
2314 /* If mouse was grabbed on a frame, give coords for that frame
2315 even if the mouse is now outside it. */
2316 XTranslateCoordinates (x_current_display
,
2318 /* From-window, to-window. */
2319 root
, FRAME_X_WINDOW (last_mouse_frame
),
2321 /* From-position, to-position. */
2322 root_x
, root_y
, &win_x
, &win_y
,
2326 f1
= last_mouse_frame
;
2332 XTranslateCoordinates (x_current_display
,
2334 /* From-window, to-window. */
2337 /* From-position, to-position. */
2338 root_x
, root_y
, &win_x
, &win_y
,
2351 /* Now we know that:
2352 win is the innermost window containing the pointer
2353 (XTC says it has no child containing the pointer),
2354 win_x and win_y are the pointer's position in it
2355 (XTC did this the last time through), and
2356 parent_x and parent_y are the pointer's position in win's parent.
2357 (They are what win_x and win_y were when win was child.
2358 If win is the root window, it has no parent, and
2359 parent_{x,y} are invalid, but that's okay, because we'll
2360 never use them in that case.) */
2362 /* Is win one of our frames? */
2363 f1
= x_any_window_to_frame (win
);
2366 /* If not, is it one of our scroll bars? */
2369 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
2373 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2381 int ignore1
, ignore2
;
2383 /* Ok, we found a frame. Store all the values. */
2385 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
2386 &last_mouse_glyph
, x_mouse_grabbed
);
2391 XSET (*x
, Lisp_Int
, win_x
);
2392 XSET (*y
, Lisp_Int
, win_y
);
2393 *time
= last_mouse_movement_time
;
2401 #else /* ! defined (HAVE_X11) */
2402 #define XEvent XKeyPressedEvent
2403 #endif /* ! defined (HAVE_X11) */
2405 /* Scroll bar support. */
2407 /* Given an X window ID, find the struct scroll_bar which manages it.
2408 This can be called in GC, so we have to make sure to strip off mark
2410 static struct scroll_bar
*
2411 x_window_to_scroll_bar (window_id
)
2414 Lisp_Object tail
, frame
;
2416 for (tail
= Vframe_list
;
2417 XGCTYPE (tail
) == Lisp_Cons
;
2418 tail
= XCONS (tail
)->cdr
)
2420 Lisp_Object frame
, bar
, condemned
;
2422 frame
= XCONS (tail
)->car
;
2423 /* All elements of Vframe_list should be frames. */
2424 if (XGCTYPE (frame
) != Lisp_Frame
)
2427 /* Scan this frame's scroll bar list for a scroll bar with the
2429 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2430 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2431 /* This trick allows us to search both the ordinary and
2432 condemned scroll bar lists with one loop. */
2433 ! GC_NILP (bar
) || (bar
= condemned
,
2436 bar
= XSCROLL_BAR (bar
)->next
)
2437 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2438 return XSCROLL_BAR (bar
);
2444 /* Open a new X window to serve as a scroll bar, and return the
2445 scroll bar vector for it. */
2446 static struct scroll_bar
*
2447 x_scroll_bar_create (window
, top
, left
, width
, height
)
2448 struct window
*window
;
2449 int top
, left
, width
, height
;
2451 FRAME_PTR frame
= XFRAME (WINDOW_FRAME (window
));
2452 struct scroll_bar
*bar
=
2453 XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2458 XSetWindowAttributes a
;
2460 a
.background_pixel
= frame
->display
.x
->background_pixel
;
2461 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2462 | ButtonMotionMask
| PointerMotionHintMask
2464 a
.cursor
= x_vertical_scroll_bar_cursor
;
2466 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2471 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2472 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2473 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
2474 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
2475 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2476 sb_widget
= XtCreateManagedWidget ("box",
2478 frame
->display
.x
->edit_widget
, al
, ac
);
2479 SET_SCROLL_BAR_X_WINDOW
2480 (bar
, sb_widget
->core
.window
);
2482 SET_SCROLL_BAR_X_WINDOW
2484 XCreateWindow (x_current_display
, FRAME_X_WINDOW (frame
),
2486 /* Position and size of scroll bar. */
2487 left
, top
, width
, height
,
2489 /* Border width, depth, class, and visual. */
2490 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
2496 XSET (bar
->window
, Lisp_Window
, window
);
2497 XSET (bar
->top
, Lisp_Int
, top
);
2498 XSET (bar
->left
, Lisp_Int
, left
);
2499 XSET (bar
->width
, Lisp_Int
, width
);
2500 XSET (bar
->height
, Lisp_Int
, height
);
2501 XSET (bar
->start
, Lisp_Int
, 0);
2502 XSET (bar
->end
, Lisp_Int
, 0);
2503 bar
->dragging
= Qnil
;
2505 /* Add bar to its frame's list of scroll bars. */
2506 bar
->next
= FRAME_SCROLL_BARS (frame
);
2508 XSET (FRAME_SCROLL_BARS (frame
), Lisp_Vector
, bar
);
2509 if (! NILP (bar
->next
))
2510 XSET (XSCROLL_BAR (bar
->next
)->prev
, Lisp_Vector
, bar
);
2512 XMapWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
));
2519 /* Draw BAR's handle in the proper position.
2520 If the handle is already drawn from START to END, don't bother
2521 redrawing it, unless REBUILD is non-zero; in that case, always
2522 redraw it. (REBUILD is handy for drawing the handle after expose
2525 Normally, we want to constrain the start and end of the handle to
2526 fit inside its rectangle, but if the user is dragging the scroll bar
2527 handle, we want to let them drag it down all the way, so that the
2528 bar's top is as far down as it goes; otherwise, there's no way to
2529 move to the very end of the buffer. */
2531 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
2532 struct scroll_bar
*bar
;
2536 int dragging
= ! NILP (bar
->dragging
);
2537 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2538 GC gc
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))->display
.x
->normal_gc
;
2540 /* If the display is already accurate, do nothing. */
2542 && start
== XINT (bar
->start
)
2543 && end
== XINT (bar
->end
))
2549 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (XINT (bar
->width
));
2550 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2551 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2553 /* Make sure the values are reasonable, and try to preserve
2554 the distance between start and end. */
2556 int length
= end
- start
;
2560 else if (start
> top_range
)
2562 end
= start
+ length
;
2566 else if (end
> top_range
&& ! dragging
)
2570 /* Store the adjusted setting in the scroll bar. */
2571 XSET (bar
->start
, Lisp_Int
, start
);
2572 XSET (bar
->end
, Lisp_Int
, end
);
2574 /* Clip the end position, just for display. */
2575 if (end
> top_range
)
2578 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
2579 below top positions, to make sure the handle is always at least
2580 that many pixels tall. */
2581 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
2583 /* Draw the empty space above the handle. Note that we can't clear
2584 zero-height areas; that means "clear to end of window." */
2586 XClearArea (x_current_display
, w
,
2588 /* x, y, width, height, and exposures. */
2589 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2590 VERTICAL_SCROLL_BAR_TOP_BORDER
,
2591 inside_width
, start
,
2594 /* Draw the handle itself. */
2595 XFillRectangle (x_current_display
, w
, gc
,
2597 /* x, y, width, height */
2598 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2599 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
2600 inside_width
, end
- start
);
2603 /* Draw the empty space below the handle. Note that we can't
2604 clear zero-height areas; that means "clear to end of window." */
2605 if (end
< inside_height
)
2606 XClearArea (x_current_display
, w
,
2608 /* x, y, width, height, and exposures. */
2609 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2610 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
2611 inside_width
, inside_height
- end
,
2619 /* Move a scroll bar around on the screen, to accommodate changing
2620 window configurations. */
2622 x_scroll_bar_move (bar
, top
, left
, width
, height
)
2623 struct scroll_bar
*bar
;
2624 int top
, left
, width
, height
;
2630 unsigned int mask
= 0;
2637 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
2638 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
2639 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
2640 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
2643 XConfigureWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
),
2647 XSET (bar
->left
, Lisp_Int
, left
);
2648 XSET (bar
->top
, Lisp_Int
, top
);
2649 XSET (bar
->width
, Lisp_Int
, width
);
2650 XSET (bar
->height
, Lisp_Int
, height
);
2655 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
2658 x_scroll_bar_remove (bar
)
2659 struct scroll_bar
*bar
;
2661 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2665 /* Destroy the window. */
2666 XDestroyWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
));
2668 /* Disassociate this scroll bar from its window. */
2669 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
2674 /* Set the handle of the vertical scroll bar for WINDOW to indicate
2675 that we are displaying PORTION characters out of a total of WHOLE
2676 characters, starting at POSITION. If WINDOW has no scroll bar,
2679 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
2680 struct window
*window
;
2681 int portion
, whole
, position
;
2683 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2684 int top
= XINT (window
->top
);
2685 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
2686 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
2688 /* Where should this scroll bar be, pixelwise? */
2689 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
2690 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
2691 int pixel_width
= VERTICAL_SCROLL_BAR_PIXEL_WIDTH (f
);
2692 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
2694 struct scroll_bar
*bar
;
2696 /* Does the scroll bar exist yet? */
2697 if (NILP (window
->vertical_scroll_bar
))
2698 bar
= x_scroll_bar_create (window
,
2699 pixel_top
, pixel_left
,
2700 pixel_width
, pixel_height
);
2703 /* It may just need to be moved and resized. */
2704 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2705 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
2708 /* Set the scroll bar's current state, unless we're currently being
2710 if (NILP (bar
->dragging
))
2713 VERTICAL_SCROLL_BAR_TOP_RANGE (pixel_height
);
2716 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
2719 int start
= ((double) position
* top_range
) / whole
;
2720 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
2722 x_scroll_bar_set_handle (bar
, start
, end
, 0);
2726 XSET (window
->vertical_scroll_bar
, Lisp_Vector
, bar
);
2730 /* The following three hooks are used when we're doing a thorough
2731 redisplay of the frame. We don't explicitly know which scroll bars
2732 are going to be deleted, because keeping track of when windows go
2733 away is a real pain - "Can you say set-window-configuration, boys
2734 and girls?" Instead, we just assert at the beginning of redisplay
2735 that *all* scroll bars are to be removed, and then save a scroll bar
2736 from the fiery pit when we actually redisplay its window. */
2738 /* Arrange for all scroll bars on FRAME to be removed at the next call
2739 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
2740 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
2742 XTcondemn_scroll_bars (frame
)
2745 /* The condemned list should be empty at this point; if it's not,
2746 then the rest of Emacs isn't using the condemn/redeem/judge
2747 protocol correctly. */
2748 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
2751 /* Move them all to the "condemned" list. */
2752 FRAME_CONDEMNED_SCROLL_BARS (frame
) = FRAME_SCROLL_BARS (frame
);
2753 FRAME_SCROLL_BARS (frame
) = Qnil
;
2756 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
2757 Note that WINDOW isn't necessarily condemned at all. */
2759 XTredeem_scroll_bar (window
)
2760 struct window
*window
;
2762 struct scroll_bar
*bar
;
2764 /* We can't redeem this window's scroll bar if it doesn't have one. */
2765 if (NILP (window
->vertical_scroll_bar
))
2768 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2770 /* Unlink it from the condemned list. */
2772 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2774 if (NILP (bar
->prev
))
2776 /* If the prev pointer is nil, it must be the first in one of
2778 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
2779 /* It's not condemned. Everything's fine. */
2781 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
2782 window
->vertical_scroll_bar
))
2783 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
2785 /* If its prev pointer is nil, it must be at the front of
2786 one or the other! */
2790 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
2792 if (! NILP (bar
->next
))
2793 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
2795 bar
->next
= FRAME_SCROLL_BARS (f
);
2797 XSET (FRAME_SCROLL_BARS (f
), Lisp_Vector
, bar
);
2798 if (! NILP (bar
->next
))
2799 XSET (XSCROLL_BAR (bar
->next
)->prev
, Lisp_Vector
, bar
);
2803 /* Remove all scroll bars on FRAME that haven't been saved since the
2804 last call to `*condemn_scroll_bars_hook'. */
2806 XTjudge_scroll_bars (f
)
2809 Lisp_Object bar
, next
;
2811 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
2813 /* Clear out the condemned list now so we won't try to process any
2814 more events on the hapless scroll bars. */
2815 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
2817 for (; ! NILP (bar
); bar
= next
)
2819 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
2821 x_scroll_bar_remove (b
);
2824 b
->next
= b
->prev
= Qnil
;
2827 /* Now there should be no references to the condemned scroll bars,
2828 and they should get garbage-collected. */
2832 /* Handle an Expose or GraphicsExpose event on a scroll bar.
2834 This may be called from a signal handler, so we have to ignore GC
2837 x_scroll_bar_expose (bar
, event
)
2838 struct scroll_bar
*bar
;
2841 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2842 GC gc
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))->display
.x
->normal_gc
;
2846 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
2848 /* Draw a one-pixel border just inside the edges of the scroll bar. */
2849 XDrawRectangle (x_current_display
, w
, gc
,
2851 /* x, y, width, height */
2852 0, 0, XINT (bar
->width
) - 1, XINT (bar
->height
) - 1);
2857 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
2858 is set to something other than no_event, it is enqueued.
2860 This may be called from a signal handler, so we have to ignore GC
2863 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
2864 struct scroll_bar
*bar
;
2866 struct input_event
*emacs_event
;
2868 if (XGCTYPE (bar
->window
) != Lisp_Window
)
2871 emacs_event
->kind
= scroll_bar_click
;
2872 emacs_event
->code
= event
->xbutton
.button
- Button1
;
2873 emacs_event
->modifiers
=
2874 (x_x_to_emacs_modifiers (event
->xbutton
.state
)
2875 | (event
->type
== ButtonRelease
2878 emacs_event
->frame_or_window
= bar
->window
;
2879 emacs_event
->timestamp
= event
->xbutton
.time
;
2881 int internal_height
=
2882 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2884 VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2885 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
2888 if (y
> top_range
) y
= top_range
;
2890 if (y
< XINT (bar
->start
))
2891 emacs_event
->part
= scroll_bar_above_handle
;
2892 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
2893 emacs_event
->part
= scroll_bar_handle
;
2895 emacs_event
->part
= scroll_bar_below_handle
;
2897 /* Just because the user has clicked on the handle doesn't mean
2898 they want to drag it. Lisp code needs to be able to decide
2899 whether or not we're dragging. */
2901 /* If the user has just clicked on the handle, record where they're
2903 if (event
->type
== ButtonPress
2904 && emacs_event
->part
== scroll_bar_handle
)
2905 XSET (bar
->dragging
, Lisp_Int
, y
- XINT (bar
->start
));
2908 /* If the user has released the handle, set it to its final position. */
2909 if (event
->type
== ButtonRelease
2910 && ! NILP (bar
->dragging
))
2912 int new_start
= y
- XINT (bar
->dragging
);
2913 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2915 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2916 bar
->dragging
= Qnil
;
2919 /* Same deal here as the other #if 0. */
2921 /* Clicks on the handle are always reported as occurring at the top of
2923 if (emacs_event
->part
== scroll_bar_handle
)
2924 emacs_event
->x
= bar
->start
;
2926 XSET (emacs_event
->x
, Lisp_Int
, y
);
2928 XSET (emacs_event
->x
, Lisp_Int
, y
);
2931 XSET (emacs_event
->y
, Lisp_Int
, top_range
);
2935 /* Handle some mouse motion while someone is dragging the scroll bar.
2937 This may be called from a signal handler, so we have to ignore GC
2940 x_scroll_bar_note_movement (bar
, event
)
2941 struct scroll_bar
*bar
;
2944 last_mouse_movement_time
= event
->xmotion
.time
;
2947 XSET (last_mouse_scroll_bar
, Lisp_Vector
, bar
);
2949 /* If we're dragging the bar, display it. */
2950 if (! GC_NILP (bar
->dragging
))
2952 /* Where should the handle be now? */
2953 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
2955 if (new_start
!= XINT (bar
->start
))
2957 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2959 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2963 /* Call XQueryPointer so we'll get an event the next time the mouse
2964 moves and we can see *still* on the same position. */
2968 XQueryPointer (event
->xmotion
.display
, event
->xmotion
.window
,
2969 (Window
*) &dummy
, (Window
*) &dummy
,
2970 &dummy
, &dummy
, &dummy
, &dummy
,
2971 (unsigned int *) &dummy
);
2975 /* Return information to the user about the current position of the mouse
2976 on the scroll bar. */
2978 x_scroll_bar_report_motion (f
, bar_window
, part
, x
, y
, time
)
2980 Lisp_Object
*bar_window
;
2981 enum scroll_bar_part
*part
;
2983 unsigned long *time
;
2985 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
2987 Window dummy_window
;
2989 unsigned int dummy_mask
;
2993 /* Get the mouse's position relative to the scroll bar window, and
2995 if (! XQueryPointer (x_current_display
,
2996 SCROLL_BAR_X_WINDOW (bar
),
2998 /* Root, child, root x and root y. */
2999 &dummy_window
, &dummy_window
,
3000 &dummy_coord
, &dummy_coord
,
3002 /* Position relative to scroll bar. */
3005 /* Mouse buttons and modifier keys. */
3011 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
3013 = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
3015 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
3017 if (! NILP (bar
->dragging
))
3018 win_y
-= XINT (bar
->dragging
);
3022 if (win_y
> top_range
)
3025 *f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3026 *bar_window
= bar
->window
;
3028 if (! NILP (bar
->dragging
))
3029 *part
= scroll_bar_handle
;
3030 else if (win_y
< XINT (bar
->start
))
3031 *part
= scroll_bar_above_handle
;
3032 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
3033 *part
= scroll_bar_handle
;
3035 *part
= scroll_bar_below_handle
;
3037 XSET (*x
, Lisp_Int
, win_y
);
3038 XSET (*y
, Lisp_Int
, top_range
);
3041 last_mouse_scroll_bar
= Qnil
;
3044 *time
= last_mouse_movement_time
;
3050 /* The screen has been cleared so we may have changed foreground or
3051 background colors, and the scroll bars may need to be redrawn.
3052 Clear out the scroll bars, and ask for expose events, so we can
3055 x_scroll_bar_clear (f
)
3060 for (bar
= FRAME_SCROLL_BARS (f
);
3061 XTYPE (bar
) == Lisp_Vector
;
3062 bar
= XSCROLL_BAR (bar
)->next
)
3063 XClearArea (x_current_display
, SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
3067 /* This processes Expose events from the menubar specific X event
3068 loop in menubar.c. This allows to redisplay the frame if necessary
3069 when handling menubar or popup items. */
3072 process_expose_from_menu (event
)
3079 f
= x_window_to_frame (event
.xexpose
.window
);
3082 if (f
->async_visible
== 0)
3084 f
->async_visible
= 1;
3085 f
->async_iconified
= 0;
3086 SET_FRAME_GARBAGED (f
);
3090 dumprectangle (x_window_to_frame (event
.xexpose
.window
),
3091 event
.xexpose
.x
, event
.xexpose
.y
,
3092 event
.xexpose
.width
, event
.xexpose
.height
);
3097 struct scroll_bar
*bar
3098 = x_window_to_scroll_bar (event
.xexpose
.window
);
3101 x_scroll_bar_expose (bar
, &event
);
3108 /* The main X event-reading loop - XTread_socket. */
3110 /* Timestamp of enter window event. This is only used by XTread_socket,
3111 but we have to put it out here, since static variables within functions
3112 sometimes don't work. */
3113 static Time enter_timestamp
;
3115 /* This holds the state XLookupString needs to implement dead keys
3116 and other tricks known as "compose processing". _X Window System_
3117 says that a portable program can't use this, but Stephen Gildea assures
3118 me that letting the compiler initialize it to zeros will work okay.
3120 This must be defined outside of XTread_socket, for the same reasons
3121 given for enter_timestamp, above. */
3122 static XComposeStatus compose_status
;
3124 /* Communication with window managers. */
3125 Atom Xatom_wm_protocols
;
3127 /* Kinds of protocol things we may receive. */
3128 Atom Xatom_wm_take_focus
;
3129 Atom Xatom_wm_save_yourself
;
3130 Atom Xatom_wm_delete_window
;
3132 /* Other WM communication */
3133 Atom Xatom_wm_configure_denied
; /* When our config request is denied */
3134 Atom Xatom_wm_window_moved
; /* When the WM moves us. */
3136 /* Window manager communication. */
3137 Atom Xatom_wm_change_state
;
3139 /* Record the last 100 characters stored
3140 to help debug the loss-of-chars-during-GC problem. */
3142 short temp_buffer
[100];
3144 /* Read events coming from the X server.
3145 This routine is called by the SIGIO handler.
3146 We return as soon as there are no more events to be read.
3148 Events representing keys are stored in buffer BUFP,
3149 which can hold up to NUMCHARS characters.
3150 We return the number of characters stored into the buffer,
3151 thus pretending to be `read'.
3153 WAITP is nonzero if we should block until input arrives.
3154 EXPECTED is nonzero if the caller knows input is available. */
3157 XTread_socket (sd
, bufp
, numchars
, waitp
, expected
)
3159 register struct input_event
*bufp
;
3160 register int numchars
;
3167 int items_pending
; /* How many items are in the X queue. */
3170 int event_found
= 0;
3174 if (interrupt_input_blocked
)
3176 interrupt_input_pending
= 1;
3180 interrupt_input_pending
= 0;
3184 abort (); /* Don't think this happens. */
3187 /* If available, Xlib uses FIOSNBIO to make the socket
3188 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
3189 FIOSNBIO is ignored, and instead of signalling EWOULDBLOCK,
3190 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
3191 fcntl (fileno (stdin
), F_SETFL
, 0);
3192 #endif /* ! defined (FIOSNBIO) */
3196 if (! (fcntl (fileno (stdin
), F_GETFL
, 0) & O_NDELAY
))
3198 extern int read_alarm_should_throw
;
3199 read_alarm_should_throw
= 1;
3200 XPeekEvent (XDISPLAY
&event
);
3201 read_alarm_should_throw
= 0;
3203 #endif /* HAVE_SELECT */
3206 while (XStuffPending () != 0)
3208 XNextEvent (XDISPLAY
&event
);
3216 if (event
.xclient
.message_type
== Xatom_wm_protocols
3217 && event
.xclient
.format
== 32)
3219 if (event
.xclient
.data
.l
[0] == Xatom_wm_take_focus
)
3221 #ifdef USE_X_TOOLKIT
3222 /* f = x_any_window_to_frame (event.xclient.window); */
3223 f
= x_window_to_frame (event
.xclient
.window
);
3225 f
= x_window_to_frame (event
.xclient
.window
);
3228 x_focus_on_frame (f
);
3229 /* Not certain about handling scroll bars here */
3231 else if (event
.xclient
.data
.l
[0] == Xatom_wm_save_yourself
)
3233 /* Save state modify the WM_COMMAND property to
3234 something which can reinstate us. This notifies
3235 the session manager, who's looking for such a
3236 PropertyNotify. Can restart processing when
3237 a keyboard or mouse event arrives. */
3242 else if (event
.xclient
.data
.l
[0] == Xatom_wm_delete_window
)
3244 struct frame
*f
= x_any_window_to_frame (event
.xclient
.window
);
3251 bufp
->kind
= delete_window_event
;
3252 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3260 else if (event
.xclient
.message_type
== Xatom_wm_configure_denied
)
3263 else if (event
.xclient
.message_type
== Xatom_wm_window_moved
)
3266 struct frame
*f
= x_window_to_frame (event
.xclient
.window
);
3268 new_x
= event
.xclient
.data
.s
[0];
3269 new_y
= event
.xclient
.data
.s
[1];
3273 f
->display
.x
->left_pos
= new_x
;
3274 f
->display
.x
->top_pos
= new_y
;
3280 #ifdef NEW_SELECTIONS
3281 case SelectionNotify
:
3282 #ifdef USE_X_TOOLKIT
3283 if (x_window_to_frame (event
.xselection
.requestor
))
3284 x_handle_selection_notify (&event
);
3287 #else /* not USE_X_TOOLKIT */
3288 x_handle_selection_notify (&event
);
3289 #endif /* not USE_X_TOOLKIT */
3291 #endif /* NEW_SELECTIONS */
3293 case SelectionClear
: /* Someone has grabbed ownership. */
3294 #ifdef NEW_SELECTIONS
3296 #ifdef USE_X_TOOLKIT
3297 if (x_window_to_frame (event
.xselectionclear
.window
))
3299 #endif /* USE_X_TOOLKIT */
3300 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
3305 bufp
->kind
= selection_clear_event
;
3306 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3307 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3308 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3313 #ifdef USE_X_TOOLKIT
3317 #endif /* USE_X_TOOLKIT */
3319 #else /* not NEW_SELECTIONS */
3320 x_disown_selection (event
.xselectionclear
.window
,
3321 event
.xselectionclear
.selection
,
3322 event
.xselectionclear
.time
);
3323 #endif /* not NEW_SELECTIONS */
3326 case SelectionRequest
: /* Someone wants our selection. */
3327 #ifdef NEW_SELECTIONS
3329 #ifdef USE_X_TOOLKIT
3330 if (x_window_to_frame (event
.xselectionrequest
.owner
))
3332 #endif /* USE_X_TOOLKIT */
3333 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
3338 bufp
->kind
= selection_request_event
;
3339 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
3340 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
3341 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
3342 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
3343 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
3344 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
3349 #ifdef USE_X_TOOLKIT
3353 #endif /* USE_X_TOOLKIT */
3355 #else /* not NEW_SELECTIONS */
3356 x_answer_selection_request (event
);
3357 #endif /* not NEW_SELECTIONS */
3360 case PropertyNotify
:
3361 #ifdef NEW_SELECTIONS
3362 #ifdef USE_X_TOOLKIT
3363 if (x_any_window_to_frame (event
.xproperty
.window
))
3364 x_handle_property_notify (&event
);
3367 #else /* not USE_X_TOOLKIT */
3368 x_handle_property_notify (&event
);
3369 #endif /* not USE_X_TOOLKIT */
3370 #else /* not NEW_SELECTIONS */
3371 /* If we're being told about a root window property, then it's
3372 a cut buffer change. */
3373 if (event
.xproperty
.window
== ROOT_WINDOW
)
3374 x_invalidate_cut_buffer_cache (&event
.xproperty
);
3376 /* Otherwise, we're probably handling an incremental
3377 selection transmission. */
3380 /* If we were to do this synchronously, there'd be no worry
3381 about re-selecting. */
3382 x_send_incremental (event
);
3384 #endif /* not NEW_SELECTIONS */
3387 case ReparentNotify
:
3388 f
= x_window_to_frame (event
.xreparent
.window
);
3390 f
->display
.x
->parent_desc
= event
.xreparent
.parent
;
3394 f
= x_window_to_frame (event
.xexpose
.window
);
3397 if (f
->async_visible
== 0)
3399 f
->async_visible
= 1;
3400 f
->async_iconified
= 0;
3401 SET_FRAME_GARBAGED (f
);
3405 dumprectangle (x_window_to_frame (event
.xexpose
.window
),
3406 event
.xexpose
.x
, event
.xexpose
.y
,
3407 event
.xexpose
.width
, event
.xexpose
.height
);
3412 struct scroll_bar
*bar
3413 = x_window_to_scroll_bar (event
.xexpose
.window
);
3416 x_scroll_bar_expose (bar
, &event
);
3417 #ifdef USE_X_TOOLKIT
3420 #endif /* USE_X_TOOLKIT */
3424 case GraphicsExpose
: /* This occurs when an XCopyArea's
3425 source area was obscured or not
3427 f
= x_window_to_frame (event
.xgraphicsexpose
.drawable
);
3431 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
3432 event
.xgraphicsexpose
.width
,
3433 event
.xgraphicsexpose
.height
);
3435 #ifdef USE_X_TOOLKIT
3438 #endif /* USE_X_TOOLKIT */
3441 case NoExpose
: /* This occurs when an XCopyArea's
3442 source area was completely
3445 #else /* ! defined (HAVE_X11) */
3447 if (event
.subwindow
!= 0)
3448 break; /* duplicate event */
3449 f
= x_window_to_frame (event
.window
);
3450 if (event
.window
== f
->display
.x
->icon_desc
)
3453 f
->async_iconified
= 1;
3455 if (event
.window
== FRAME_X_WINDOW (f
))
3457 /* Say must check all windows' needs_exposure flags. */
3458 expose_all_windows
= 1;
3459 f
->display
.x
->needs_exposure
= 1;
3460 f
->async_visible
= 1;
3465 if (event
.subwindow
!= 0)
3466 break; /* duplicate event */
3467 f
= x_window_to_frame (event
.window
);
3468 if (event
.window
== f
->display
.x
->icon_desc
)
3473 /* If window already needs full redraw, ignore this rectangle. */
3474 if (expose_all_windows
&& f
->display
.x
->needs_exposure
)
3476 /* Put the event on the queue of rectangles to redraw. */
3477 if (enqueue_event (&event
, &x_expose_queue
))
3478 /* If it is full, we can't record the rectangle,
3479 so redraw this entire window. */
3481 /* Say must check all windows' needs_exposure flags. */
3482 expose_all_windows
= 1;
3483 f
->display
.x
->needs_exposure
= 1;
3488 /* This should happen only when we are expecting it,
3489 in x_read_exposes. */
3491 #endif /* ! defined (HAVE_X11) */
3495 f
= x_window_to_frame (event
.xunmap
.window
);
3496 if (f
) /* F may no longer exist if
3497 the frame was deleted. */
3499 /* While a frame is unmapped, display generation is
3500 disabled; you don't want to spend time updating a
3501 display that won't ever be seen. */
3502 f
->async_visible
= 0;
3503 /* The window manager never makes a window invisible
3504 ("withdrawn"); all it does is switch between visible
3505 and iconified. Frames get into the invisible state
3506 only through x_make_frame_invisible. */
3507 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
3508 f
->async_iconified
= 1;
3510 #ifdef USE_X_TOOLKIT
3512 #endif /* USE_X_TOOLKIT */
3516 #ifdef USE_X_TOOLKIT
3517 f
= x_any_window_to_frame (event
.xmap
.window
);
3518 #else /* not USE_X_TOOLKIT */
3519 f
= x_window_to_frame (event
.xmap
.window
);
3520 #endif /* not USE_X_TOOLKIT */
3523 f
->async_visible
= 1;
3524 f
->async_iconified
= 0;
3526 /* wait_reading_process_input will notice this and update
3527 the frame's display structures. */
3528 SET_FRAME_GARBAGED (f
);
3530 #ifdef USE_X_TOOLKIT
3532 #endif /* USE_X_TOOLKIT */
3535 /* Turn off processing if we become fully obscured. */
3536 case VisibilityNotify
:
3539 #else /* ! defined (HAVE_X11) */
3541 f
= x_window_to_frame (event
.window
);
3542 if (event
.window
== f
->display
.x
->icon_desc
)
3543 f
->async_iconified
= 0;
3544 if (event
.window
== FRAME_X_WINDOW (f
))
3545 f
->async_visible
= 0;
3547 #endif /* ! defined (HAVE_X11) */
3551 f
= x_any_window_to_frame (event
.xkey
.window
);
3555 KeySym keysym
, orig_keysym
;
3556 /* al%imercury@uunet.uu.net says that making this 81 instead of
3557 80 fixed a bug whereby meta chars made his Emacs hang. */
3558 unsigned char copy_buffer
[81];
3562 |= x_emacs_to_x_modifiers (extra_keyboard_modifiers
);
3563 modifiers
= event
.xkey
.state
;
3565 /* This will have to go some day... */
3567 /* make_lispy_event turns chars into control chars.
3568 Don't do it here because XLookupString is too eager. */
3569 event
.xkey
.state
&= ~ControlMask
;
3571 XLookupString (&event
.xkey
, copy_buffer
, 80, &keysym
,
3574 /* Strip off the vendor-specific keysym bit, and take a shot
3575 at recognizing the codes. HP servers have extra keysyms
3576 that fit into the MiscFunctionKey category. */
3577 orig_keysym
= keysym
;
3582 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
3583 || keysym
== XK_Delete
3584 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
3585 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
3587 /* This recognizes the "extended function keys".
3588 It seems there's no cleaner way.
3589 Test IsModifierKey to avoid handling mode_switch
3591 || ((unsigned) (keysym
) >= XK_Select
3592 && (unsigned)(keysym
) < XK_KP_Space
)
3594 #ifdef XK_dead_circumflex
3595 || orig_keysym
== XK_dead_circumflex
3597 #ifdef XK_dead_grave
3598 || orig_keysym
== XK_dead_grave
3600 #ifdef XK_dead_tilde
3601 || orig_keysym
== XK_dead_tilde
3603 #ifdef XK_dead_diaeresis
3604 || orig_keysym
== XK_dead_diaeresis
3606 #ifdef XK_dead_macron
3607 || orig_keysym
== XK_dead_macron
3609 #ifdef XK_dead_degree
3610 || orig_keysym
== XK_dead_degree
3612 #ifdef XK_dead_acute
3613 || orig_keysym
== XK_dead_acute
3615 #ifdef XK_dead_cedilla
3616 || orig_keysym
== XK_dead_cedilla
3618 #ifdef XK_dead_breve
3619 || orig_keysym
== XK_dead_breve
3621 #ifdef XK_dead_ogonek
3622 || orig_keysym
== XK_dead_ogonek
3624 #ifdef XK_dead_caron
3625 || orig_keysym
== XK_dead_caron
3627 #ifdef XK_dead_doubleacute
3628 || orig_keysym
== XK_dead_doubleacute
3630 #ifdef XK_dead_abovedot
3631 || orig_keysym
== XK_dead_abovedot
3633 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
3634 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
3635 || x_is_vendor_fkey (orig_keysym
))
3636 && ! (IsModifierKey (orig_keysym
)
3638 #ifdef XK_Mode_switch
3639 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
3642 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
3644 #endif /* not HAVE_X11R5 */
3647 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3649 temp_buffer
[temp_index
++] = keysym
;
3650 bufp
->kind
= non_ascii_keystroke
;
3651 bufp
->code
= keysym
;
3652 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3653 bufp
->modifiers
= x_x_to_emacs_modifiers (modifiers
);
3654 bufp
->timestamp
= event
.xkey
.time
;
3659 else if (numchars
> nbytes
)
3663 for (i
= 0; i
< nbytes
; i
++)
3665 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3667 temp_buffer
[temp_index
++] = copy_buffer
[i
];
3668 bufp
->kind
= ascii_keystroke
;
3669 bufp
->code
= copy_buffer
[i
];
3670 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3671 bufp
->modifiers
= x_x_to_emacs_modifiers (modifiers
);
3672 bufp
->timestamp
= event
.xkey
.time
;
3686 #else /* ! defined (HAVE_X11) */
3689 register char *where_mapping
;
3691 f
= x_window_to_frame (event
.window
);
3692 /* Ignore keys typed on icon windows. */
3693 if (f
!= 0 && event
.window
== f
->display
.x
->icon_desc
)
3695 where_mapping
= XLookupMapping (&event
, &nbytes
);
3696 /* Nasty fix for arrow keys */
3697 if (!nbytes
&& IsCursorKey (event
.detail
& 0xff))
3699 switch (event
.detail
& 0xff)
3701 case KC_CURSOR_LEFT
:
3702 where_mapping
= "\002";
3704 case KC_CURSOR_RIGHT
:
3705 where_mapping
= "\006";
3708 where_mapping
= "\020";
3710 case KC_CURSOR_DOWN
:
3711 where_mapping
= "\016";
3716 if (numchars
- nbytes
> 0)
3720 for (i
= 0; i
< nbytes
; i
++)
3722 bufp
->kind
= ascii_keystroke
;
3723 bufp
->code
= where_mapping
[i
];
3724 XSET (bufp
->time
, Lisp_Int
, event
.xkey
.time
);
3725 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3733 #endif /* ! defined (HAVE_X11) */
3737 /* Here's a possible interpretation of the whole
3738 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
3739 FocusIn event, you have to get a FocusOut event before you
3740 relinquish the focus. If you haven't received a FocusIn event,
3741 then a mere LeaveNotify is enough to free you. */
3744 f
= x_any_window_to_frame (event
.xcrossing
.window
);
3746 if (event
.xcrossing
.focus
) /* Entered Window */
3748 /* Avoid nasty pop/raise loops. */
3749 if (f
&& (!(f
->auto_raise
)
3751 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
3753 x_new_focus_frame (f
);
3754 enter_timestamp
= event
.xcrossing
.time
;
3757 else if (f
== x_focus_frame
)
3758 x_new_focus_frame (0);
3759 #ifdef USE_X_TOOLKIT
3761 #endif /* USE_X_TOOLKIT */
3765 f
= x_any_window_to_frame (event
.xfocus
.window
);
3766 if (event
.xfocus
.detail
!= NotifyPointer
)
3767 x_focus_event_frame
= f
;
3769 x_new_focus_frame (f
);
3770 #ifdef USE_X_TOOLKIT
3772 #endif /* USE_X_TOOLKIT */
3777 f
= x_any_window_to_frame (event
.xcrossing
.window
);
3779 if (f
== mouse_face_mouse_frame
)
3780 /* If we move outside the frame,
3781 then we're certainly no longer on any text in the frame. */
3782 clear_mouse_face ();
3784 if (event
.xcrossing
.focus
)
3786 if (! x_focus_event_frame
)
3787 x_new_focus_frame (0);
3789 x_new_focus_frame (f
);
3793 if (f
== x_focus_event_frame
)
3794 x_focus_event_frame
= 0;
3795 if (f
== x_focus_frame
)
3796 x_new_focus_frame (0);
3798 #ifdef USE_X_TOOLKIT
3800 #endif /* USE_X_TOOLKIT */
3804 f
= x_any_window_to_frame (event
.xfocus
.window
);
3805 if (event
.xfocus
.detail
!= NotifyPointer
3806 && f
== x_focus_event_frame
)
3807 x_focus_event_frame
= 0;
3808 if (f
&& f
== x_focus_frame
)
3809 x_new_focus_frame (0);
3810 #ifdef USE_X_TOOLKIT
3812 #endif /* USE_X_TOOLKIT */
3815 #else /* ! defined (HAVE_X11) */
3818 if ((event
.detail
& 0xFF) == 1)
3819 break; /* Coming from our own subwindow */
3820 if (event
.subwindow
!= 0)
3821 break; /* Entering our own subwindow. */
3824 f
= x_window_to_frame (event
.window
);
3827 x_new_focus_frame (f
);
3832 if ((event
.detail
& 0xFF) == 1)
3833 break; /* Entering our own subwindow */
3834 if (event
.subwindow
!= 0)
3835 break; /* Leaving our own subwindow. */
3838 if (x_focus_frame
== 0
3839 && x_input_frame
!= 0
3840 && x_input_frame
== x_window_to_frame (event
.window
)
3841 && event
.window
== FRAME_X_WINDOW (x_input_frame
))
3846 frame_unhighlight (f
);
3849 #endif /* ! defined (HAVE_X11) */
3854 if (x_mouse_grabbed
)
3855 f
= last_mouse_frame
;
3857 f
= x_window_to_frame (event
.xmotion
.window
);
3859 note_mouse_movement (f
, &event
.xmotion
);
3862 struct scroll_bar
*bar
3863 = x_window_to_scroll_bar (event
.xmotion
.window
);
3866 x_scroll_bar_note_movement (bar
, &event
);
3868 /* If we move outside the frame,
3869 then we're certainly no longer on any text in the frame. */
3870 clear_mouse_face ();
3873 #ifdef USE_X_TOOLKIT
3875 #endif /* USE_X_TOOLKIT */
3878 case ConfigureNotify
:
3879 f
= x_any_window_to_frame (event
.xconfigure
.window
);
3880 #ifdef USE_X_TOOLKIT
3882 && ! event
.xconfigure
.send_event
3883 && (event
.xconfigure
.window
== XtWindow (f
->display
.x
->widget
)))
3888 /* Find the position of the outside upper-left corner of
3889 the window, in the root coordinate system. Don't
3890 refer to the parent window here; we may be processing
3891 this event after the window manager has changed our
3892 parent, but before we have reached the ReparentNotify. */
3893 XTranslateCoordinates (x_current_display
,
3895 /* From-window, to-window. */
3896 XtWindow (f
->display
.x
->widget
),
3899 /* From-position, to-position. */
3900 -event
.xconfigure
.border_width
,
3901 -event
.xconfigure
.border_width
,
3906 event
.xconfigure
.x
= win_x
;
3907 event
.xconfigure
.y
= win_y
;
3909 f
->display
.x
->pixel_width
= event
.xconfigure
.width
;
3910 f
->display
.x
->pixel_height
= event
.xconfigure
.height
;
3911 f
->display
.x
->left_pos
= event
.xconfigure
.x
;
3912 f
->display
.x
->top_pos
= event
.xconfigure
.y
;
3915 #else /* not USE_X_TOOLKIT */
3918 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
3919 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
3921 /* Even if the number of character rows and columns has
3922 not changed, the font size may have changed, so we need
3923 to check the pixel dimensions as well. */
3924 if (columns
!= f
->width
3925 || rows
!= f
->height
3926 || event
.xconfigure
.width
!= f
->display
.x
->pixel_width
3927 || event
.xconfigure
.height
!= f
->display
.x
->pixel_height
)
3929 change_frame_size (f
, rows
, columns
, 0, 1);
3930 SET_FRAME_GARBAGED (f
);
3933 if (! event
.xconfigure
.send_event
)
3938 /* Find the position of the outside upper-left corner of
3939 the window, in the root coordinate system. Don't
3940 refer to the parent window here; we may be processing
3941 this event after the window manager has changed our
3942 parent, but before we have reached the ReparentNotify. */
3943 XTranslateCoordinates (x_current_display
,
3945 /* From-window, to-window. */
3946 f
->display
.x
->window_desc
,
3949 /* From-position, to-position. */
3950 -event
.xconfigure
.border_width
,
3951 -event
.xconfigure
.border_width
,
3956 event
.xconfigure
.x
= win_x
;
3957 event
.xconfigure
.y
= win_y
;
3960 f
->display
.x
->pixel_width
= event
.xconfigure
.width
;
3961 f
->display
.x
->pixel_height
= event
.xconfigure
.height
;
3962 f
->display
.x
->left_pos
= event
.xconfigure
.x
;
3963 f
->display
.x
->top_pos
= event
.xconfigure
.y
;
3965 #endif /* not USE_X_TOOLKIT */
3971 /* If we decide we want to generate an event to be seen
3972 by the rest of Emacs, we put it here. */
3973 struct input_event emacs_event
;
3974 emacs_event
.kind
= no_event
;
3976 f
= x_window_to_frame (event
.xbutton
.window
);
3979 if (!x_focus_frame
|| (f
== x_focus_frame
))
3980 construct_mouse_click (&emacs_event
, &event
, f
);
3984 struct scroll_bar
*bar
=
3985 x_window_to_scroll_bar (event
.xbutton
.window
);
3988 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
3989 #ifdef USE_X_TOOLKIT
3992 f
= x_any_window_to_frame (event
.xbutton
.window
);
3993 if (f
&& event
.type
== ButtonPress
)
3994 construct_menu_click (&emacs_event
,
3997 #endif /* USE_X_TOOLKIT */
4000 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
4002 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
4008 #ifdef USE_X_TOOLKIT
4010 #endif /* USE_X_TOOLKIT */
4014 #else /* ! defined (HAVE_X11) */
4016 case ButtonReleased
:
4017 f
= x_window_to_frame (event
.window
);
4020 if (event
.window
== f
->display
.x
->icon_desc
)
4022 x_make_frame_visible (f
);
4024 if (warp_mouse_on_deiconify
)
4025 XWarpMouse (FRAME_X_WINDOW (f
), 10, 10);
4028 if (event
.window
== FRAME_X_WINDOW (f
))
4034 enqueue_event (&event
, &x_mouse_queue
);
4037 bufp
->kind
= ascii_keystroke
;
4038 bufp
->code
= 'X' & 037; /* C-x */
4039 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
4040 XSET (bufp
->time
, Lisp_Int
, event
.xkey
.time
);
4043 bufp
->kind
= ascii_keystroke
;
4044 bufp
->code
= 0; /* C-@ */
4045 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
4046 XSET (bufp
->time
, Lisp_Int
, event
.xkey
.time
);
4053 #endif /* ! defined (HAVE_X11) */
4057 case CirculateNotify
:
4059 case CirculateRequest
:
4062 #endif /* ! defined (HAVE_X11) */
4065 /* Someone has changed the keyboard mapping - update the
4067 switch (event
.xmapping
.request
)
4069 case MappingModifier
:
4070 x_find_modifier_meanings ();
4071 /* This is meant to fall through. */
4072 case MappingKeyboard
:
4073 XRefreshKeyboardMapping (&event
.xmapping
);
4075 #ifdef USE_X_TOOLKIT
4077 #endif /* USE_X_TOOLKIT */
4081 #ifdef USE_X_TOOLKIT
4084 XtDispatchEvent (&event
);
4086 #endif /* USE_X_TOOLKIT */
4093 /* On some systems, an X bug causes Emacs to get no more events
4094 when the window is destroyed. Detect that. (1994.) */
4095 XNoOp (x_current_display
);
4096 #endif /* X_IO_BUG */
4098 #if 0 /* This fails for serial-line connections to the X server,
4099 because the characters arrive one by one, and a partial
4100 command makes select return but gives nothing to read.
4101 We'll have to hope that the bug that this tried to fix
4102 in 1988 has been fixed in Xlib or the X server. */
4104 if (expected
&& ! event_found
)
4106 /* AOJ 880406: if select returns true but XPending doesn't, it means that
4107 there is an EOF condition; in other words, that X has died.
4108 Act as if there had been a hangup. */
4109 int fd
= ConnectionNumber (x_current_display
);
4110 SELECT_TYPE mask
, junk1
, junk2
;
4115 EMACS_SET_SECS_USECS (timeout
, 0, 0);
4118 if (0 != select (fd
+ 1, &mask
, &junk1
, &junk2
, &timeout
)
4119 && !XStuffPending ())
4120 kill (getpid (), SIGHUP
);
4122 #endif /* HAVE_SELECT */
4126 if (updating_frame
== 0)
4127 x_do_pending_expose ();
4135 /* Read and process only Expose events
4136 until we get an ExposeCopy event; then return.
4137 This is used in insert/delete line.
4138 We assume input is already blocked. */
4144 XKeyPressedEvent event
;
4148 /* while there are more events*/
4149 XMaskEvent (ExposeWindow
| ExposeRegion
| ExposeCopy
, &event
);
4153 if (event
.subwindow
!= 0)
4154 break; /* duplicate event */
4155 f
= x_window_to_frame (event
.window
);
4156 if (event
.window
== f
->display
.x
->icon_desc
)
4161 if (event
.window
== FRAME_X_WINDOW (f
))
4163 expose_all_windows
= 1;
4164 f
->display
.x
->needs_exposure
= 1;
4170 if (event
.subwindow
!= 0)
4171 break; /* duplicate event */
4172 f
= x_window_to_frame (event
.window
);
4173 if (event
.window
== f
->display
.x
->icon_desc
)
4178 /* If window already needs full redraw, ignore this rectangle. */
4179 if (expose_all_windows
&& f
->display
.x
->needs_exposure
)
4181 /* Put the event on the queue of rectangles to redraw. */
4182 if (enqueue_event (&event
, &x_expose_queue
))
4183 /* If it is full, we can't record the rectangle,
4184 so redraw this entire window. */
4186 /* Say must check all windows' needs_exposure flags. */
4187 expose_all_windows
= 1;
4188 f
->display
.x
->needs_exposure
= 1;
4197 #endif /* HAVE_X11 */
4200 /* Drawing the cursor. */
4203 /* Draw a hollow box cursor. Don't change the inside of the box. */
4209 int left
= CHAR_TO_PIXEL_COL (f
, f
->cursor_x
);
4210 int top
= CHAR_TO_PIXEL_ROW (f
, f
->cursor_y
);
4211 int width
= FONT_WIDTH (f
->display
.x
->font
);
4212 int height
= f
->display
.x
->line_height
;
4215 XDrawRectangle (x_current_display
, FRAME_X_WINDOW (f
),
4216 f
->display
.x
->cursor_gc
,
4217 left
, top
, width
- 1, height
- 1);
4218 #else /* ! defined (HAVE_X11) */
4219 XPixSet (FRAME_X_WINDOW (f
),
4220 left
, top
, width
, 1,
4221 f
->display
.x
->cursor_pixel
);
4223 XPixSet (FRAME_X_WINDOW (f
),
4224 left
, top
, 1, height
,
4225 f
->display
.x
->cursor_pixel
);
4227 XPixSet (FRAME_X_WINDOW (f
),
4228 left
+width
-1, top
, 1, height
,
4229 f
->display
.x
->cursor_pixel
);
4231 XPixSet (FRAME_X_WINDOW (f
),
4232 left
, top
+height
-1, width
, 1,
4233 f
->display
.x
->cursor_pixel
);
4234 #endif /* ! defined (HAVE_X11) */
4237 /* Clear the cursor of frame F to background color,
4238 and mark the cursor as not shown.
4239 This is used when the text where the cursor is
4240 is about to be rewritten. */
4248 if (! FRAME_VISIBLE_P (f
)
4249 || f
->phys_cursor_x
< 0)
4253 x_display_cursor (f
, 0);
4254 #else /* ! defined (HAVE_X11) */
4255 XPixSet (FRAME_X_WINDOW (f
),
4256 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
4257 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
4258 FONT_WIDTH (f
->display
.x
->font
), f
->display
.x
->line_height
,
4259 f
->display
.x
->background_pixel
);
4260 #endif /* ! defined (HAVE_X11) */
4261 f
->phys_cursor_x
= -1;
4264 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
4265 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
4269 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
4276 CHAR_TO_PIXEL_COL (f
, column
),
4277 CHAR_TO_PIXEL_ROW (f
, row
),
4278 &glyph
, 1, highlight
);
4282 x_display_bar_cursor (f
, on
)
4286 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4288 /* This is pointless on invisible frames, and dangerous on garbaged
4289 frames; in the latter case, the frame may be in the midst of
4290 changing its size, and curs_x and curs_y may be off the frame. */
4291 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4294 if (! on
&& f
->phys_cursor_x
< 0)
4297 /* If we're not updating, then we want to use the current frame's
4298 cursor position, not our local idea of where the cursor ought to be. */
4299 if (f
!= updating_frame
)
4301 curs_x
= FRAME_CURSOR_X (f
);
4302 curs_y
= FRAME_CURSOR_Y (f
);
4305 /* If there is anything wrong with the current cursor state, remove it. */
4306 if (f
->phys_cursor_x
>= 0
4308 || f
->phys_cursor_x
!= curs_x
4309 || f
->phys_cursor_y
!= curs_y
4310 || f
->display
.x
->current_cursor
!= bar_cursor
))
4312 /* Erase the cursor by redrawing the character underneath it. */
4313 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4314 f
->phys_cursor_glyph
,
4315 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4316 f
->phys_cursor_x
= -1;
4319 /* If we now need a cursor in the new place or in the new form, do it so. */
4321 && (f
->phys_cursor_x
< 0
4322 || (f
->display
.x
->current_cursor
!= bar_cursor
)))
4324 f
->phys_cursor_glyph
4325 = ((current_glyphs
->enable
[curs_y
]
4326 && curs_x
< current_glyphs
->used
[curs_y
])
4327 ? current_glyphs
->glyphs
[curs_y
][curs_x
]
4329 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
),
4330 f
->display
.x
->cursor_gc
,
4331 CHAR_TO_PIXEL_COL (f
, curs_x
),
4332 CHAR_TO_PIXEL_ROW (f
, curs_y
),
4333 1, f
->display
.x
->line_height
);
4335 f
->phys_cursor_x
= curs_x
;
4336 f
->phys_cursor_y
= curs_y
;
4338 f
->display
.x
->current_cursor
= bar_cursor
;
4341 if (updating_frame
!= f
)
4346 /* Turn the displayed cursor of frame F on or off according to ON.
4347 If ON is nonzero, where to put the cursor is specified
4348 by F->cursor_x and F->cursor_y. */
4351 x_display_box_cursor (f
, on
)
4355 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
4357 /* This is pointless on invisible frames, and dangerous on garbaged
4358 frames; in the latter case, the frame may be in the midst of
4359 changing its size, and curs_x and curs_y may be off the frame. */
4360 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
4363 /* If cursor is off and we want it off, return quickly. */
4364 if (!on
&& f
->phys_cursor_x
< 0)
4367 /* If we're not updating, then we want to use the current frame's
4368 cursor position, not our local idea of where the cursor ought to be. */
4369 if (f
!= updating_frame
)
4371 curs_x
= FRAME_CURSOR_X (f
);
4372 curs_y
= FRAME_CURSOR_Y (f
);
4375 /* If cursor is currently being shown and we don't want it to be
4376 or it is in the wrong place,
4377 or we want a hollow box and it's not so, (pout!)
4379 if (f
->phys_cursor_x
>= 0
4381 || f
->phys_cursor_x
!= curs_x
4382 || f
->phys_cursor_y
!= curs_y
4383 || (f
->display
.x
->current_cursor
!= hollow_box_cursor
4384 && (f
!= x_highlight_frame
))))
4386 /* Erase the cursor by redrawing the character underneath it. */
4387 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
4388 f
->phys_cursor_glyph
,
4389 current_glyphs
->highlight
[f
->phys_cursor_y
]);
4390 f
->phys_cursor_x
= -1;
4393 /* If we want to show a cursor,
4394 or we want a box cursor and it's not so,
4395 write it in the right place. */
4397 && (f
->phys_cursor_x
< 0
4398 || (f
->display
.x
->current_cursor
!= filled_box_cursor
4399 && f
== x_highlight_frame
)))
4401 f
->phys_cursor_glyph
4402 = ((current_glyphs
->enable
[curs_y
]
4403 && curs_x
< current_glyphs
->used
[curs_y
])
4404 ? current_glyphs
->glyphs
[curs_y
][curs_x
]
4406 if (f
!= x_highlight_frame
)
4409 f
->display
.x
->current_cursor
= hollow_box_cursor
;
4413 x_draw_single_glyph (f
, curs_y
, curs_x
,
4414 f
->phys_cursor_glyph
, 2);
4415 f
->display
.x
->current_cursor
= filled_box_cursor
;
4418 f
->phys_cursor_x
= curs_x
;
4419 f
->phys_cursor_y
= curs_y
;
4422 if (updating_frame
!= f
)
4426 x_display_cursor (f
, on
)
4432 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4433 x_display_box_cursor (f
, on
);
4434 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4435 x_display_bar_cursor (f
, on
);
4437 /* Those are the only two we have implemented! */
4445 /* Refresh bitmap kitchen sink icon for frame F
4446 when we get an expose event for it. */
4452 /* Normally, the window manager handles this function. */
4453 #else /* ! defined (HAVE_X11) */
4456 if (f
->display
.x
->icon_bitmap_flag
)
4457 XBitmapBitsPut (f
->display
.x
->icon_desc
, 0, 0, sink_width
, sink_height
,
4458 sink_bits
, BlackPixel
, WHITE_PIX_DEFAULT
,
4459 icon_bitmap
, GXcopy
, AllPlanes
);
4462 extern struct frame
*selected_frame
;
4463 struct Lisp_String
*str
;
4464 unsigned char *string
;
4467 = XSTRING (XBUFFER (XWINDOW (f
->selected_window
)->buffer
)->name
)->data
;
4469 if (f
->display
.x
->icon_label
!= string
)
4471 f
->display
.x
->icon_label
= string
;
4472 XChangeWindow (f
->display
.x
->icon_desc
,
4473 XQueryWidth (string
, icon_font_info
->id
) + 10,
4474 icon_font_info
->height
+ 10);
4477 XText (f
->display
.x
->icon_desc
, 5, 5, string
,
4478 str
->size
, icon_font_info
->id
,
4479 BLACK_PIX_DEFAULT
, WHITE_PIX_DEFAULT
);
4482 #endif /* ! defined (HAVE_X11) */
4485 /* Make the x-window of frame F use the gnu icon bitmap. */
4494 if (FRAME_X_WINDOW (f
) == 0)
4500 XCreateBitmapFromData (x_current_display
, FRAME_X_WINDOW (f
),
4501 gnu_bits
, gnu_width
, gnu_height
);
4502 x_wm_set_icon_pixmap (f
, icon_bitmap
);
4503 f
->display
.x
->icon_bitmap_flag
= 1;
4504 #else /* ! defined (HAVE_X11) */
4505 if (f
->display
.x
->icon_desc
)
4507 XClearIconWindow (FRAME_X_WINDOW (f
));
4508 XDestroyWindow (f
->display
.x
->icon_desc
);
4511 icon_window
= XCreateWindow (f
->display
.x
->parent_desc
,
4512 0, 0, sink_width
, sink_height
,
4513 2, WhitePixmap
, (Pixmap
) NULL
);
4515 if (icon_window
== 0)
4518 XSetIconWindow (FRAME_X_WINDOW (f
), icon_window
);
4519 XSelectInput (icon_window
, ExposeWindow
| UnmapWindow
);
4521 f
->display
.x
->icon_desc
= icon_window
;
4522 f
->display
.x
->icon_bitmap_flag
= 1;
4524 if (icon_bitmap
== 0)
4526 = XStoreBitmap (sink_mask_width
, sink_mask_height
, sink_mask_bits
);
4527 #endif /* ! defined (HAVE_X11) */
4533 /* Make the x-window of frame F use a rectangle with text. */
4536 x_text_icon (f
, icon_name
)
4544 char *X_DefaultValue
;
4548 #define WhitePixel 1
4549 #endif /* WhitePixel */
4552 #define BlackPixel 0
4553 #endif /* BlackPixel */
4554 #endif /* HAVE_X11 */
4556 if (FRAME_X_WINDOW (f
) == 0)
4561 f
->display
.x
->icon_label
= icon_name
;
4563 if (! f
->display
.x
->icon_label
)
4564 f
->display
.x
->icon_label
= " *emacs* ";
4567 XSetIconName (x_current_display
, FRAME_X_WINDOW (f
),
4568 (char *) f
->display
.x
->icon_label
);
4571 f
->display
.x
->icon_bitmap_flag
= 0;
4572 x_wm_set_icon_pixmap (f
, 0);
4573 #else /* ! defined (HAVE_X11) */
4574 if (icon_font_info
== 0)
4576 = XGetFont (XGetDefault (XDISPLAY
4577 (char *) XSTRING (Vinvocation_name
)->data
,
4580 if (f
->display
.x
->icon_desc
)
4582 XClearIconWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4583 XDestroyWindow (XDISPLAY f
->display
.x
->icon_desc
);
4587 f
->display
.x
->icon_label
= (unsigned char *) icon_name
;
4589 if (! f
->display
.x
->icon_label
)
4590 f
->display
.x
->icon_label
= XSTRING (f
->name
)->data
;
4592 width
= XStringWidth (f
->display
.x
->icon_label
, icon_font_info
, 0, 0);
4593 icon_window
= XCreateWindow (f
->display
.x
->parent_desc
,
4594 f
->display
.x
->left_pos
,
4595 f
->display
.x
->top_pos
,
4596 width
+ 10, icon_font_info
->height
+ 10,
4597 2, BlackPixmap
, WhitePixmap
);
4599 if (icon_window
== 0)
4602 XSetIconWindow (FRAME_X_WINDOW (f
), icon_window
);
4603 XSelectInput (icon_window
, ExposeWindow
| ExposeRegion
| UnmapWindow
| ButtonPressed
);
4605 f
->display
.x
->icon_desc
= icon_window
;
4606 f
->display
.x
->icon_bitmap_flag
= 0;
4607 f
->display
.x
->icon_label
= 0;
4608 #endif /* ! defined (HAVE_X11) */
4613 /* Handling X errors. */
4615 /* Shut down Emacs in an orderly fashion, because of a SIGPIPE on the
4616 X server's connection, or an error reported via the X protocol. */
4619 x_connection_closed ()
4624 shut_down_emacs (0, 1, Qnil
);
4629 /* An X error handler which prints an error message and then kills
4630 Emacs. This is what's normally installed as Xlib's handler for
4633 x_error_quitter (display
, error
)
4639 /* Note that there is no real way portable across R3/R4 to get the
4640 original error handler. */
4642 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
4643 fprintf (stderr
, "X protocol error: %s on protocol request %d\n",
4644 buf
, error
->request_code
);
4647 /* While we're testing Emacs 19, we'll just dump core whenever we
4648 get an X error, so we can figure out why it happened. */
4652 x_connection_closed ();
4655 /* A handler for X IO errors which prints an error message and then
4656 kills Emacs. This is what is always installed as Xlib's handler
4659 x_io_error_quitter (display
)
4662 fprintf (stderr
, "Connection to X server %s lost.\n",
4663 XDisplayName (DisplayString (display
)));
4666 /* While we're testing Emacs 19, we'll just dump core whenever we
4667 get an X error, so we can figure out why it happened. */
4671 x_connection_closed ();
4674 /* A buffer for storing X error messages. */
4675 static char *x_caught_error_message
;
4676 #define X_CAUGHT_ERROR_MESSAGE_SIZE 200
4678 /* An X error handler which stores the error message in
4679 x_caught_error_message. This is what's installed when
4680 x_catch_errors is in effect. */
4682 x_error_catcher (display
, error
)
4686 XGetErrorText (display
, error
->error_code
,
4687 x_caught_error_message
, X_CAUGHT_ERROR_MESSAGE_SIZE
);
4691 /* Begin trapping X errors.
4693 After calling this function, X protocol errors no longer cause
4694 Emacs to exit; instead, they are recorded in x_cfc_error_message.
4696 Calling x_check_errors signals an Emacs error if an X error has
4697 occurred since the last call to x_catch_errors or x_check_errors.
4699 Calling x_uncatch_errors resumes the normal error handling. */
4701 void x_catch_errors (), x_check_errors (), x_uncatch_errors ();
4706 /* Make sure any errors from previous requests have been dealt with. */
4707 XSync (x_current_display
, False
);
4709 /* Set up the error buffer. */
4710 x_caught_error_message
4711 = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE
);
4712 x_caught_error_message
[0] = '\0';
4714 /* Install our little error handler. */
4715 XHandleError (x_error_catcher
);
4718 /* If any X protocol errors have arrived since the last call to
4719 x_catch_errors or x_check_errors, signal an Emacs error using
4720 sprintf (a buffer, FORMAT, the x error message text) as the text. */
4723 x_check_errors (format
)
4726 /* Make sure to catch any errors incurred so far. */
4727 XSync (x_current_display
, False
);
4729 if (x_caught_error_message
[0])
4731 char buf
[X_CAUGHT_ERROR_MESSAGE_SIZE
+ 56];
4733 sprintf (buf
, format
, x_caught_error_message
);
4734 x_uncatch_errors ();
4739 /* Nonzero if we had any X protocol errors since we did x_catch_errors. */
4744 /* Make sure to catch any errors incurred so far. */
4745 XSync (x_current_display
, False
);
4747 return x_caught_error_message
[0] != 0;
4750 /* Stop catching X protocol errors and let them make Emacs die. */
4755 xfree (x_caught_error_message
);
4756 x_caught_error_message
= 0;
4757 XHandleError (x_error_quitter
);
4761 static unsigned int x_wire_count
;
4764 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
4769 /* Changing the font of the frame. */
4771 /* Set the font of the x-window specified by frame F
4772 to the font named NEWNAME. This is safe to use
4773 even before F has an actual x-window. */
4783 /* A table of all the fonts we have already loaded. */
4784 static struct font_info
*x_font_table
;
4786 /* The current capacity of x_font_table. */
4787 static int x_font_table_size
;
4789 /* The number of fonts actually stored in x_font_table.
4790 x_font_table[n] is used and valid iff 0 <= n < n_fonts.
4791 0 <= n_fonts <= x_font_table_size. */
4795 x_new_font (f
, fontname
)
4797 register char *fontname
;
4800 int n_matching_fonts
;
4801 XFontStruct
*font_info
;
4804 /* Get a list of all the fonts that match this name. Once we
4805 have a list of matching fonts, we compare them against the fonts
4806 we already have by comparing font ids. */
4807 font_names
= (char **) XListFonts (x_current_display
, fontname
,
4808 1024, &n_matching_fonts
);
4809 /* Apparently it doesn't set n_matching_fonts to zero when it can't
4810 find any matches; font_names == 0 is the only clue. */
4812 n_matching_fonts
= 0;
4814 /* Don't just give up if n_matching_fonts is 0.
4815 Apparently there's a bug on Suns: XListFontsWithInfo can
4816 fail to find a font, but XLoadQueryFont may still find it. */
4818 /* See if we've already loaded a matching font. */
4819 already_loaded
= -1;
4820 if (n_matching_fonts
!= 0)
4824 for (i
= 0; i
< n_fonts
; i
++)
4825 for (j
= 0; j
< n_matching_fonts
; j
++)
4826 if (!strcmp (x_font_table
[i
].name
, font_names
[j
]))
4829 fontname
= font_names
[j
];
4835 /* If we have, just return it from the table. */
4836 if (already_loaded
>= 0)
4837 f
->display
.x
->font
= x_font_table
[already_loaded
].font
;
4839 /* Otherwise, load the font and add it to the table. */
4845 /* Try to find a character-cell font in the list. */
4847 /* A laudable goal, but this isn't how to do it. */
4848 for (i
= 0; i
< n_matching_fonts
; i
++)
4849 if (! font_info
[i
].per_char
)
4855 /* See comment above. */
4856 if (n_matching_fonts
!= 0)
4857 fontname
= font_names
[i
];
4859 font
= (XFontStruct
*) XLoadQueryFont (x_current_display
, fontname
);
4862 /* Free the information from XListFonts. */
4863 if (n_matching_fonts
)
4864 XFreeFontNames (font_names
);
4868 /* Do we need to create the table? */
4869 if (x_font_table_size
== 0)
4871 x_font_table_size
= 16;
4873 = (struct font_info
*) xmalloc (x_font_table_size
4874 * sizeof (x_font_table
[0]));
4876 /* Do we need to grow the table? */
4877 else if (n_fonts
>= x_font_table_size
)
4879 x_font_table_size
*= 2;
4881 = (struct font_info
*) xrealloc (x_font_table
,
4883 * sizeof (x_font_table
[0])));
4886 x_font_table
[n_fonts
].name
= (char *) xmalloc (strlen (fontname
) + 1);
4887 bcopy (fontname
, x_font_table
[n_fonts
].name
, strlen (fontname
) + 1);
4888 f
->display
.x
->font
= x_font_table
[n_fonts
++].font
= font
;
4891 /* Now make the frame display the given font. */
4892 if (FRAME_X_WINDOW (f
) != 0)
4894 XSetFont (x_current_display
, f
->display
.x
->normal_gc
,
4895 f
->display
.x
->font
->fid
);
4896 XSetFont (x_current_display
, f
->display
.x
->reverse_gc
,
4897 f
->display
.x
->font
->fid
);
4898 XSetFont (x_current_display
, f
->display
.x
->cursor_gc
,
4899 f
->display
.x
->font
->fid
);
4901 frame_update_line_height (f
);
4904 /* If we are setting a new frame's font for the first time,
4905 there are no faces yet, so this font's height is the line height. */
4906 f
->display
.x
->line_height
= FONT_HEIGHT (f
);
4909 Lisp_Object lispy_name
;
4911 lispy_name
= build_string (fontname
);
4913 /* Free the information from XListFonts. The data
4914 we actually retain comes from XLoadQueryFont. */
4915 XFreeFontNames (font_names
);
4920 #else /* ! defined (HAVE_X11) */
4921 x_new_font (f
, newname
)
4923 register char *newname
;
4928 temp
= XGetFont (newname
);
4929 if (temp
== (FONT_TYPE
*) 0)
4932 if (f
->display
.x
->font
)
4933 XLoseFont (f
->display
.x
->font
);
4935 f
->display
.x
->font
= temp
;
4937 if (FRAME_X_WINDOW (f
) != 0)
4938 x_set_window_size (f
, 0, f
->width
, f
->height
);
4942 #endif /* ! defined (HAVE_X11) */
4944 x_calc_absolute_position (f
)
4949 int win_x
= 0, win_y
= 0;
4951 /* Find the position of the outside upper-left corner of
4952 the inner window, with respect to the outer window. */
4953 if (f
->display
.x
->parent_desc
!= ROOT_WINDOW
)
4956 XTranslateCoordinates (x_current_display
,
4958 /* From-window, to-window. */
4959 f
->display
.x
->window_desc
,
4960 f
->display
.x
->parent_desc
,
4962 /* From-position, to-position. */
4963 0, 0, &win_x
, &win_y
,
4970 /* Treat negative positions as relative to the leftmost bottommost
4971 position that fits on the screen. */
4972 if (f
->display
.x
->left_pos
< 0)
4973 f
->display
.x
->left_pos
= (x_screen_width
4974 - 2 * f
->display
.x
->border_width
- win_x
4976 + f
->display
.x
->left_pos
);
4978 if (f
->display
.x
->top_pos
< 0)
4979 f
->display
.x
->top_pos
= (x_screen_height
4980 - 2 * f
->display
.x
->border_width
- win_y
4982 + f
->display
.x
->top_pos
);
4984 #else /* ! defined (HAVE_X11) */
4985 WINDOWINFO_TYPE parentinfo
;
4987 XGetWindowInfo (FRAME_X_WINDOW (f
), &parentinfo
);
4989 if (f
->display
.x
->left_pos
< 0)
4990 f
->display
.x
->left_pos
= parentinfo
.width
+ (f
->display
.x
->left_pos
+ 1)
4991 - PIXEL_WIDTH (f
) - 2 * f
->display
.x
->internal_border_width
;
4993 if (f
->display
.x
->top_pos
< 0)
4994 f
->display
.x
->top_pos
= parentinfo
.height
+ (f
->display
.x
->top_pos
+ 1)
4995 - PIXEL_HEIGHT (f
) - 2 * f
->display
.x
->internal_border_width
;
4996 #endif /* ! defined (HAVE_X11) */
4999 x_set_offset (f
, xoff
, yoff
)
5001 register int xoff
, yoff
;
5003 f
->display
.x
->top_pos
= yoff
;
5004 f
->display
.x
->left_pos
= xoff
;
5005 x_calc_absolute_position (f
);
5008 #ifdef USE_X_TOOLKIT
5009 XMoveWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
),
5010 f
->display
.x
->left_pos
, f
->display
.x
->top_pos
);
5011 #else /* not USE_X_TOOLKIT */
5012 XMoveWindow (XDISPLAY
FRAME_X_WINDOW (f
),
5013 f
->display
.x
->left_pos
, f
->display
.x
->top_pos
);
5014 #endif /* not USE_X_TOOLKIT */
5016 x_wm_set_size_hint (f
, 0, 1, xoff
, yoff
);
5017 #endif /* ! defined (HAVE_X11) */
5021 /* Call this to change the size of frame F's x-window.
5022 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
5023 for this size change and subsequent size changes.
5024 Otherwise we leave the window gravity unchanged. */
5026 x_set_window_size (f
, change_gravity
, cols
, rows
)
5031 int pixelwidth
, pixelheight
;
5034 #ifdef USE_X_TOOLKIT
5036 EmacsFrameSetCharSize (f
->display
.x
->edit_widget
, cols
, rows
);
5039 #else /* not USE_X_TOOLKIT */
5043 check_frame_size (f
, &rows
, &cols
);
5044 f
->display
.x
->vertical_scroll_bar_extra
5045 = (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5046 ? VERTICAL_SCROLL_BAR_PIXEL_WIDTH (f
)
5048 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
5049 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
5052 x_wm_set_size_hint (f
, 0, change_gravity
, 0, 0);
5053 #endif /* ! defined (HAVE_X11) */
5054 XChangeWindowSize (FRAME_X_WINDOW (f
), pixelwidth
, pixelheight
);
5056 /* Now, strictly speaking, we can't be sure that this is accurate,
5057 but the window manager will get around to dealing with the size
5058 change request eventually, and we'll hear how it went when the
5059 ConfigureNotify event gets here.
5061 We could just not bother storing any of this information here,
5062 and let the ConfigureNotify event set everything up, but that
5063 might be kind of confusing to the lisp code, since size changes
5064 wouldn't be reported in the frame parameters until some random
5065 point in the future when the ConfigureNotify event arrives. */
5066 change_frame_size (f
, rows
, cols
, 0, 0);
5067 PIXEL_WIDTH (f
) = pixelwidth
;
5068 PIXEL_HEIGHT (f
) = pixelheight
;
5070 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
5071 receive in the ConfigureNotify event; if we get what we asked
5072 for, then the event won't cause the screen to become garbaged, so
5073 we have to make sure to do it here. */
5074 SET_FRAME_GARBAGED (f
);
5078 #endif /* not USE_X_TOOLKIT */
5082 x_set_resize_hint (f
)
5085 XSetResizeHint (FRAME_X_WINDOW (f
),
5086 2 * f
->display
.x
->internal_border_width
,
5087 2 * f
->display
.x
->internal_border_width
,
5088 FONT_WIDTH (f
->display
.x
->font
),
5089 f
->display
.x
->line_height
);
5091 #endif /* HAVE_X11 */
5093 /* Mouse warping, focus shifting, raising and lowering. */
5095 x_set_mouse_position (f
, x
, y
)
5101 #if 0 /* Let the user ask for this if he wants it. */
5105 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->display
.x
->font
) / 2;
5106 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->display
.x
->line_height
/ 2;
5108 if (pix_x
< 0) pix_x
= 0;
5109 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
5111 if (pix_y
< 0) pix_y
= 0;
5112 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
5116 XWarpMousePointer (FRAME_X_WINDOW (f
), pix_x
, pix_y
);
5121 x_focus_on_frame (f
)
5124 #if 0 /* This proves to be unpleasant. */
5128 /* I don't think that the ICCCM allows programs to do things like this
5129 without the interaction of the window manager. Whatever you end up
5130 doing with this code, do it to x_unfocus_frame too. */
5131 XSetInputFocus (x_current_display
, FRAME_X_WINDOW (f
),
5132 RevertToPointerRoot
, CurrentTime
);
5140 /* Look at the remarks in x_focus_on_frame. */
5141 if (x_focus_frame
== f
)
5142 XSetInputFocus (x_current_display
, PointerRoot
,
5143 RevertToPointerRoot
, CurrentTime
);
5147 #endif /* ! defined (HAVE_X11) */
5149 /* Raise frame F. */
5154 if (f
->async_visible
)
5157 #ifdef USE_X_TOOLKIT
5158 XRaiseWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
));
5159 #else /* not USE_X_TOOLKIT */
5160 XRaiseWindow (XDISPLAY
FRAME_X_WINDOW (f
));
5161 #endif /* not USE_X_TOOLKIT */
5167 /* Lower frame F. */
5172 if (f
->async_visible
)
5175 #ifdef USE_X_TOOLKIT
5176 XLowerWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
));
5177 #else /* not USE_X_TOOLKIT */
5178 XLowerWindow (XDISPLAY
FRAME_X_WINDOW (f
));
5179 #endif /* not USE_X_TOOLKIT */
5186 XTframe_raise_lower (f
, raise
)
5197 /* Change from withdrawn state to mapped state. */
5199 x_make_frame_visible (f
)
5206 if (! FRAME_VISIBLE_P (f
))
5209 if (! EQ (Vx_no_window_manager
, Qt
))
5210 x_wm_set_window_state (f
, NormalState
);
5211 #ifdef USE_X_TOOLKIT
5212 XtPopup (f
->display
.x
->widget
, XtGrabNone
);
5213 #else /* not USE_X_TOOLKIT */
5214 XMapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
5215 #endif /* not USE_X_TOOLKIT */
5216 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5217 XMapSubwindows (x_current_display
, FRAME_X_WINDOW (f
));
5218 #else /* ! defined (HAVE_X11) */
5219 XMapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
5220 if (f
->display
.x
->icon_desc
!= 0)
5221 XUnmapWindow (f
->display
.x
->icon_desc
);
5223 /* Handled by the MapNotify event for X11 */
5224 f
->async_visible
= 1;
5225 f
->async_iconified
= 0;
5227 /* NOTE: this may cause problems for the first frame. */
5229 #endif /* ! defined (HAVE_X11) */
5237 /* Change from mapped state to withdrawn state. */
5239 x_make_frame_invisible (f
)
5244 /* Don't keep the highlight on an invisible frame. */
5245 if (x_highlight_frame
== f
)
5246 x_highlight_frame
= 0;
5248 if (! f
->async_visible
&& ! f
->async_iconified
)
5255 #ifdef USE_X_TOOLKIT
5256 if (! XWithdrawWindow (x_current_display
, XtWindow (f
->display
.x
->widget
),
5257 DefaultScreen (x_current_display
)))
5258 #else /* not USE_X_TOOLKIT */
5259 if (! XWithdrawWindow (x_current_display
, FRAME_X_WINDOW (f
),
5260 DefaultScreen (x_current_display
)))
5261 #endif /* not USE_X_TOOLKIT */
5263 UNBLOCK_INPUT_RESIGNAL
;
5264 error ("can't notify window manager of window withdrawal");
5267 #else /* ! defined (HAVE_X11R4) */
5270 /* Tell the window manager what we're going to do. */
5271 if (! EQ (Vx_no_window_manager
, Qt
))
5275 unmap
.xunmap
.type
= UnmapNotify
;
5276 #ifdef USE_X_TOOLKIT
5277 unmap
.xunmap
.window
= XtWindow (f
->display
.x
->widget
);
5278 #else /* not USE_X_TOOLKIT */
5279 unmap
.xunmap
.window
= FRAME_X_WINDOW (f
);
5280 #endif /* not USE_X_TOOLKIT */
5281 unmap
.xunmap
.event
= DefaultRootWindow (x_current_display
);
5282 unmap
.xunmap
.from_configure
= False
;
5283 if (! XSendEvent (x_current_display
,
5284 DefaultRootWindow (x_current_display
),
5286 SubstructureRedirectMask
|SubstructureNotifyMask
,
5289 UNBLOCK_INPUT_RESIGNAL
;
5290 error ("can't notify window manager of withdrawal");
5294 /* Unmap the window ourselves. Cheeky! */
5295 #ifdef USE_X_TOOLKIT
5296 XUnmapWindow (x_current_display
, XtWindow (f
->display
.x
->widget
));
5297 #else /* not USE_X_TOOLKIT */
5298 XUnmapWindow (x_current_display
, FRAME_X_WINDOW (f
));
5299 #endif /* not USE_X_TOOLKIT */
5300 #else /* ! defined (HAVE_X11) */
5302 XUnmapWindow (FRAME_X_WINDOW (f
));
5303 f
->async_visible
= 0; /* Handled by the UnMap event for X11 */
5304 if (f
->display
.x
->icon_desc
!= 0)
5305 XUnmapWindow (f
->display
.x
->icon_desc
);
5307 #endif /* ! defined (HAVE_X11) */
5308 #endif /* ! defined (HAVE_X11R4) */
5314 /* Change window state from mapped to iconified. */
5322 /* Don't keep the highlight on an invisible frame. */
5323 if (x_highlight_frame
== f
)
5324 x_highlight_frame
= 0;
5326 if (f
->async_iconified
)
5329 #ifdef USE_X_TOOLKIT
5331 result
= XIconifyWindow (x_current_display
,
5332 XtWindow (f
->display
.x
->widget
),
5333 DefaultScreen (x_current_display
));
5337 error ("Can't notify window manager of iconification.");
5339 f
->async_iconified
= 1;
5344 #else /* not USE_X_TOOLKIT */
5349 /* Since we don't know which revision of X we're running, we'll use both
5350 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
5352 /* X11R4: send a ClientMessage to the window manager using the
5353 WM_CHANGE_STATE type. */
5357 message
.xclient
.window
= FRAME_X_WINDOW (f
);
5358 message
.xclient
.type
= ClientMessage
;
5359 message
.xclient
.message_type
= Xatom_wm_change_state
;
5360 message
.xclient
.format
= 32;
5361 message
.xclient
.data
.l
[0] = IconicState
;
5363 if (! XSendEvent (x_current_display
,
5364 DefaultRootWindow (x_current_display
),
5366 SubstructureRedirectMask
| SubstructureNotifyMask
,
5369 UNBLOCK_INPUT_RESIGNAL
;
5370 error ("Can't notify window manager of iconification.");
5374 /* X11R3: set the initial_state field of the window manager hints to
5376 x_wm_set_window_state (f
, IconicState
);
5378 if (!FRAME_VISIBLE_P (f
))
5380 /* If the frame was withdrawn, before, we must map it. */
5381 XMapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
5382 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5383 XMapSubwindows (x_current_display
, FRAME_X_WINDOW (f
));
5386 f
->async_iconified
= 1;
5387 #else /* ! defined (HAVE_X11) */
5388 XUnmapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
5390 f
->async_visible
= 0; /* Handled in the UnMap event for X11. */
5391 if (f
->display
.x
->icon_desc
!= 0)
5393 XMapWindow (XDISPLAY f
->display
.x
->icon_desc
);
5396 #endif /* ! defined (HAVE_X11) */
5400 #endif /* not USE_X_TOOLKIT */
5403 /* Destroy the X window of frame F. */
5405 x_destroy_window (f
)
5410 if (f
->display
.x
->icon_desc
!= 0)
5411 XDestroyWindow (XDISPLAY f
->display
.x
->icon_desc
);
5412 XDestroyWindow (XDISPLAY f
->display
.x
->window_desc
);
5413 #ifdef USE_X_TOOLKIT
5414 XtDestroyWidget (f
->display
.x
->widget
);
5415 free_frame_menubar (f
);
5416 #endif /* USE_X_TOOLKIT */
5418 free_frame_faces (f
);
5421 xfree (f
->display
.x
);
5423 if (f
== x_focus_frame
)
5425 if (f
== x_highlight_frame
)
5426 x_highlight_frame
= 0;
5431 /* Manage event queues for X10. */
5435 /* Manage event queues.
5437 This code is only used by the X10 support.
5439 We cannot leave events in the X queue and get them when we are ready
5440 because X does not provide a subroutine to get only a certain kind
5441 of event but not block if there are no queued events of that kind.
5443 Therefore, we must examine events as they come in and copy events
5444 of certain kinds into our private queues.
5446 All ExposeRegion events are put in x_expose_queue.
5447 All ButtonPress and ButtonRelease events are put in x_mouse_queue. */
5450 /* Write the event *P_XREP into the event queue *QUEUE.
5451 If the queue is full, do nothing, but return nonzero. */
5454 enqueue_event (p_xrep
, queue
)
5455 register XEvent
*p_xrep
;
5456 register struct event_queue
*queue
;
5458 int newindex
= queue
->windex
+ 1;
5459 if (newindex
== EVENT_BUFFER_SIZE
)
5461 if (newindex
== queue
->rindex
)
5463 queue
->xrep
[queue
->windex
] = *p_xrep
;
5464 queue
->windex
= newindex
;
5468 /* Fetch the next event from queue *QUEUE and store it in *P_XREP.
5469 If *QUEUE is empty, do nothing and return 0. */
5472 dequeue_event (p_xrep
, queue
)
5473 register XEvent
*p_xrep
;
5474 register struct event_queue
*queue
;
5476 if (queue
->windex
== queue
->rindex
)
5478 *p_xrep
= queue
->xrep
[queue
->rindex
++];
5479 if (queue
->rindex
== EVENT_BUFFER_SIZE
)
5484 /* Return the number of events buffered in *QUEUE. */
5487 queue_event_count (queue
)
5488 register struct event_queue
*queue
;
5490 int tem
= queue
->windex
- queue
->rindex
;
5493 return EVENT_BUFFER_SIZE
+ tem
;
5496 /* Return nonzero if mouse input is pending. */
5499 mouse_event_pending_p ()
5501 return queue_event_count (&x_mouse_queue
);
5503 #endif /* HAVE_X11 */
5505 /* Setting window manager hints. */
5509 /* Record the gravity used previously, in case CHANGE_GRAVITY is 0. */
5510 static int previous_gravity
;
5512 /* SPEC_X and SPEC_Y are the specified positions.
5513 We look only at their sign, to decide the gravity.
5514 If CHANGE_GRAVITY is 0, we ignore SPEC_X and SPEC_Y
5515 and leave the gravity unchanged. */
5517 x_wm_set_size_hint (f
, prompting
, change_gravity
, spec_x
, spec_y
)
5523 XSizeHints size_hints
;
5525 #ifdef USE_X_TOOLKIT
5528 Dimension widget_width
, widget_height
;
5529 Window window
= XtWindow (f
->display
.x
->widget
);
5530 #else /* not USE_X_TOOLKIT */
5531 Window window
= FRAME_X_WINDOW (f
);
5532 #endif /* not USE_X_TOOLKIT */
5534 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
5536 flexlines
= f
->height
;
5538 size_hints
.x
= f
->display
.x
->left_pos
;
5539 size_hints
.y
= f
->display
.x
->top_pos
;
5540 #ifdef USE_X_TOOLKIT
5541 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
5542 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
5543 XtGetValues (f
->display
.x
->column_widget
, al
, ac
);
5544 size_hints
.height
= widget_height
;
5545 size_hints
.width
= widget_width
;
5546 #else /* not USE_X_TOOLKIT */
5547 size_hints
.height
= PIXEL_HEIGHT (f
);
5548 size_hints
.width
= PIXEL_WIDTH (f
);
5549 #endif /* not USE_X_TOOLKIT */
5550 size_hints
.width_inc
= FONT_WIDTH (f
->display
.x
->font
);
5551 size_hints
.height_inc
= f
->display
.x
->line_height
;
5553 size_hints
.max_width
= x_screen_width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
5554 size_hints
.max_height
= x_screen_height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
5557 int base_width
, base_height
;
5559 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
5560 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
5563 int min_rows
= 0, min_cols
= 0;
5564 check_frame_size (f
, &min_rows
, &min_cols
);
5566 /* The window manager uses the base width hints to calculate the
5567 current number of rows and columns in the frame while
5568 resizing; min_width and min_height aren't useful for this
5569 purpose, since they might not give the dimensions for a
5570 zero-row, zero-column frame.
5572 We use the base_width and base_height members if we have
5573 them; otherwise, we set the min_width and min_height members
5574 to the size for a zero x zero frame. */
5577 size_hints
.flags
|= PBaseSize
;
5578 size_hints
.base_width
= base_width
;
5579 size_hints
.base_height
= base_height
;
5580 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
5581 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
5583 size_hints
.min_width
= base_width
;
5584 size_hints
.min_height
= base_height
;
5591 size_hints
.flags
|= prompting
;
5594 XSizeHints hints
; /* Sometimes I hate X Windows... */
5596 if (XGetNormalHints (x_current_display
, window
, &hints
) == 0)
5598 if (hints
.flags
& PSize
)
5599 size_hints
.flags
|= PSize
;
5600 if (hints
.flags
& PPosition
)
5601 size_hints
.flags
|= PPosition
;
5602 if (hints
.flags
& USPosition
)
5603 size_hints
.flags
|= USPosition
;
5604 if (hints
.flags
& USSize
)
5605 size_hints
.flags
|= USSize
;
5607 #if defined (PWinGravity)
5610 switch (((spec_x
< 0) << 1) + (spec_y
< 0))
5613 size_hints
.win_gravity
= NorthWestGravity
;
5616 size_hints
.win_gravity
= NorthEastGravity
;
5619 size_hints
.win_gravity
= SouthWestGravity
;
5622 size_hints
.win_gravity
= SouthEastGravity
;
5625 previous_gravity
= size_hints
.win_gravity
;
5628 size_hints
.win_gravity
= previous_gravity
;
5630 size_hints
.flags
|= PWinGravity
;
5631 #endif /* PWinGravity */
5634 XSetWMNormalHints (x_current_display
, window
, &size_hints
);
5636 XSetNormalHints (x_current_display
, window
, &size_hints
);
5640 /* Used for IconicState or NormalState */
5641 x_wm_set_window_state (f
, state
)
5645 #ifdef USE_X_TOOLKIT
5646 Window window
= XtWindow (f
->display
.x
->widget
);
5647 #else /* not USE_X_TOOLKIT */
5648 Window window
= FRAME_X_WINDOW (f
);
5649 #endif /* not USE_X_TOOLKIT */
5651 f
->display
.x
->wm_hints
.flags
|= StateHint
;
5652 f
->display
.x
->wm_hints
.initial_state
= state
;
5654 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5657 x_wm_set_icon_pixmap (f
, icon_pixmap
)
5661 Window window
= FRAME_X_WINDOW (f
);
5665 f
->display
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
5666 f
->display
.x
->wm_hints
.flags
|= IconPixmapHint
;
5669 f
->display
.x
->wm_hints
.flags
&= ~IconPixmapHint
;
5671 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5674 x_wm_set_icon_position (f
, icon_x
, icon_y
)
5678 Window window
= FRAME_X_WINDOW (f
);
5680 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
5681 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
5682 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
5684 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5688 /* Initialization. */
5690 #ifdef USE_X_TOOLKIT
5691 static XrmOptionDescRec emacs_options
[] = {
5692 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
5693 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
5695 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
5696 XrmoptionSepArg
, NULL
},
5697 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
5699 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5700 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5701 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5702 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5703 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5704 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
5705 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
5707 #endif /* USE_X_TOOLKIT */
5710 x_term_init (display_name
)
5717 #ifndef F_SETOWN_BUG
5719 extern int old_fcntl_owner
;
5720 #endif /* ! defined (F_SETOWN) */
5721 #endif /* F_SETOWN_BUG */
5723 x_focus_frame
= x_highlight_frame
= 0;
5725 #ifdef USE_X_TOOLKIT
5726 argv
= (char **) XtMalloc (3 * sizeof (char *));
5728 argv
[1] = "-display";
5729 argv
[2] = display_name
;
5731 Xt_app_shell
= XtAppInitialize (&Xt_app_con
, "Emacs",
5732 emacs_options
, XtNumber (emacs_options
),
5736 x_current_display
= XtDisplay (Xt_app_shell
);
5738 #else /* not USE_X_TOOLKIT */
5739 x_current_display
= XOpenDisplay (display_name
);
5740 #endif /* not USE_X_TOOLKIT */
5741 if (x_current_display
== 0)
5742 fatal ("X server %s not responding.\n\
5743 Check the DISPLAY environment variable or use \"-d\"\n",
5749 XSetAfterFunction (x_current_display
, x_trace_wire
);
5751 hostname
= get_system_name ();
5752 x_id_name
= (char *) xmalloc (XSTRING (Vinvocation_name
)->size
5755 sprintf (x_id_name
, "%s@%s", XSTRING (Vinvocation_name
)->data
, hostname
);
5758 /* Figure out which modifier bits mean what. */
5759 x_find_modifier_meanings ();
5761 /* Get the scroll bar cursor. */
5762 x_vertical_scroll_bar_cursor
5763 = XCreateFontCursor (x_current_display
, XC_sb_v_double_arrow
);
5766 /* Watch for PropertyNotify events on the root window; we use them
5767 to figure out when to invalidate our cache of the cut buffers. */
5768 x_watch_cut_buffer_cache ();
5771 if (ConnectionNumber (x_current_display
) != 0)
5772 change_keyboard_wait_descriptor (ConnectionNumber (x_current_display
));
5773 change_input_fd (ConnectionNumber (x_current_display
));
5775 #endif /* ! defined (HAVE_X11) */
5777 #ifndef F_SETOWN_BUG
5779 old_fcntl_owner
= fcntl (ConnectionNumber (x_current_display
), F_GETOWN
, 0);
5780 #ifdef F_SETOWN_SOCK_NEG
5781 /* stdin is a socket here */
5782 fcntl (ConnectionNumber (x_current_display
), F_SETOWN
, -getpid ());
5783 #else /* ! defined (F_SETOWN_SOCK_NEG) */
5784 fcntl (ConnectionNumber (x_current_display
), F_SETOWN
, getpid ());
5785 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
5786 #endif /* ! defined (F_SETOWN) */
5787 #endif /* F_SETOWN_BUG */
5791 #endif /* ! defined (SIGIO) */
5793 expose_all_windows
= 0;
5795 clear_frame_hook
= XTclear_frame
;
5796 clear_end_of_line_hook
= XTclear_end_of_line
;
5797 ins_del_lines_hook
= XTins_del_lines
;
5798 change_line_highlight_hook
= XTchange_line_highlight
;
5799 insert_glyphs_hook
= XTinsert_glyphs
;
5800 write_glyphs_hook
= XTwrite_glyphs
;
5801 delete_glyphs_hook
= XTdelete_glyphs
;
5802 ring_bell_hook
= XTring_bell
;
5803 reset_terminal_modes_hook
= XTreset_terminal_modes
;
5804 set_terminal_modes_hook
= XTset_terminal_modes
;
5805 update_begin_hook
= XTupdate_begin
;
5806 update_end_hook
= XTupdate_end
;
5807 set_terminal_window_hook
= XTset_terminal_window
;
5808 read_socket_hook
= XTread_socket
;
5809 frame_up_to_date_hook
= XTframe_up_to_date
;
5810 cursor_to_hook
= XTcursor_to
;
5811 reassert_line_highlight_hook
= XTreassert_line_highlight
;
5812 mouse_position_hook
= XTmouse_position
;
5813 frame_rehighlight_hook
= XTframe_rehighlight
;
5814 frame_raise_lower_hook
= XTframe_raise_lower
;
5815 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
5816 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
5817 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
5818 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
5820 scroll_region_ok
= 1; /* we'll scroll partial frames */
5821 char_ins_del_ok
= 0; /* just as fast to write the line */
5822 line_ins_del_ok
= 1; /* we'll just blt 'em */
5823 fast_clear_end_of_line
= 1; /* X does this well */
5824 memory_below_frame
= 0; /* we don't remember what scrolls
5828 /* Try to use interrupt input; if we can't, then start polling. */
5829 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
5831 /* Note that there is no real way portable across R3/R4 to get the
5832 original error handler. */
5833 XHandleError (x_error_quitter
);
5834 XHandleIOError (x_io_error_quitter
);
5836 /* Disable Window Change signals; they are handled by X events. */
5838 signal (SIGWINCH
, SIG_DFL
);
5839 #endif /* ! defined (SIGWINCH) */
5841 signal (SIGPIPE
, x_connection_closed
);
5847 staticpro (&last_mouse_scroll_bar
);
5848 last_mouse_scroll_bar
= Qnil
;
5849 staticpro (&mouse_face_window
);
5850 mouse_face_window
= Qnil
;
5852 #endif /* ! defined (HAVE_X11) */
5853 #endif /* ! defined (HAVE_X_WINDOWS) */