1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 1993 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. */
22 Kludge: dup2 is used to put the X-connection socket into desc # 0
23 so that wait_reading_process_input will wait for it in place of
24 actual terminal input.
28 /* Xt features made by Fred Pierresteguy. */
30 #define NEW_SELECTIONS
32 /* On 4.3 these lose if they come after xterm.h. */
33 /* On HP-UX 8.0 signal.h loses if it comes after config.h. */
34 /* Putting these at the beginning seems to be standard for other .c files. */
40 /* Need syssignal.h for various externs and definitions that may be required
41 by some configurations for calls to signal later in this source file. */
42 #include "syssignal.h"
47 #include "blockinput.h"
49 /* This may include sys/types.h, and that somehow loses
50 if this is not done before the other system files. */
52 #include <X11/cursorfont.h>
55 /* Load sys/types.h if not already loaded.
56 In some systems loading it twice is suicidal. */
58 #include <sys/types.h>
63 #include <sys/ioctl.h>
65 #else /* ! defined (BSD) */
69 #endif /* ! defined (BSD) */
79 #include <sys/param.h>
81 #include "dispextern.h"
82 #include "termhooks.h"
96 extern XtAppContext Xt_app_con
;
97 extern Widget Xt_app_shell
;
98 extern void free_frame_menubar ();
99 #endif /* USE_X_TOOLKIT */
101 #ifndef USE_X_TOOLKIT
102 #define x_any_window_to_frame x_window_to_frame
106 #define XMapWindow XMapRaised /* Raise them when mapping. */
107 #else /* ! defined (HAVE_X11) */
108 #include <X/Xkeyboard.h>
109 /*#include <X/Xproto.h> */
110 #endif /* ! defined (HAVE_X11) */
113 /* We could get this from param.h, but better not to depend on finding that.
114 And better not to risk that it might define other symbols used in this
117 #define MAXDESC FD_SETSIZE
121 #define SELECT_TYPE fd_set
122 #else /* no FD_SET */
124 #define SELECT_TYPE int
126 /* Define the macros to access a single-int bitmap of descriptors. */
127 #define FD_SET(n, p) (*(p) |= (1 << (n)))
128 #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
129 #define FD_ISSET(n, p) (*(p) & (1 << (n)))
130 #define FD_ZERO(p) (*(p) = 0)
131 #endif /* no FD_SET */
133 /* For sending Meta-characters. Do we need this? */
136 #define min(a,b) ((a)<(b) ? (a) : (b))
137 #define max(a,b) ((a)>(b) ? (a) : (b))
139 /* Nonzero means we must reprint all windows
140 because 1) we received an ExposeWindow event
141 or 2) we received too many ExposeRegion events to record.
143 This is never needed under X11. */
144 static int expose_all_windows
;
146 /* Nonzero means we must reprint all icon windows. */
148 static int expose_all_icons
;
151 /* ExposeRegion events, when received, are copied into this queue
152 for later processing. */
154 static struct event_queue x_expose_queue
;
156 /* ButtonPress and ButtonReleased events, when received,
157 are copied into this queue for later processing. */
159 struct event_queue x_mouse_queue
;
160 #endif /* HAVE_X11 */
162 #if defined (SIGIO) && defined (FIONREAD)
163 int BLOCK_INPUT_mask
;
164 #endif /* ! defined (SIGIO) && defined (FIONREAD) */
166 /* The id of a bitmap used for icon windows.
167 One such map is shared by all Emacs icon windows.
168 This is zero if we have not yet had a need to create the bitmap. */
170 static Bitmap icon_bitmap
;
172 /* Font used for text icons. */
174 static FONT_TYPE
*icon_font_info
;
176 /* Stuff for dealing with the main icon title. */
178 extern Lisp_Object Vcommand_line_args
;
179 char *hostname
, *x_id_name
;
181 /* This is the X connection that we are using. */
183 Display
*x_current_display
;
185 /* The cursor to use for vertical scroll bars on x_current_display. */
186 static Cursor x_vertical_scroll_bar_cursor
;
188 /* Frame being updated by update_frame. This is declared in term.c.
189 This is set by update_begin and looked at by all the
190 XT functions. It is zero while not inside an update.
191 In that case, the XT functions assume that `selected_frame'
192 is the frame to apply to. */
193 extern struct frame
*updating_frame
;
195 /* The frame (if any) which has the X window that has keyboard focus.
196 Zero if none. This is examined by Ffocus_frame in frame.c. Note
197 that a mere EnterNotify event can set this; if you need to know the
198 last frame specified in a FocusIn or FocusOut event, use
199 x_focus_event_frame. */
200 struct frame
*x_focus_frame
;
202 /* The last frame mentioned in a FocusIn or FocusOut event. This is
203 separate from x_focus_frame, because whether or not LeaveNotify
204 events cause us to lose focus depends on whether or not we have
205 received a FocusIn event for it. */
206 struct frame
*x_focus_event_frame
;
208 /* The frame which currently has the visual highlight, and should get
209 keyboard input (other sorts of input have the frame encoded in the
210 event). It points to the X focus frame's selected window's
211 frame. It differs from x_focus_frame when we're using a global
213 static struct frame
*x_highlight_frame
;
215 /* From .Xdefaults, the value of "emacs.WarpMouse". If non-zero,
216 mouse is moved to inside of frame when frame is de-iconified. */
218 static int warp_mouse_on_deiconify
;
220 /* During an update, maximum vpos for ins/del line operations to affect. */
222 static int flexlines
;
224 /* During an update, nonzero if chars output now should be highlighted. */
226 static int highlight
;
228 /* Nominal cursor position -- where to draw output.
229 During an update, these are different from the cursor-box position. */
236 In order to avoid asking for motion events and then throwing most
237 of them away or busy-polling the server for mouse positions, we ask
238 the server for pointer motion hints. This means that we get only
239 one event per group of mouse movements. "Groups" are delimited by
240 other kinds of events (focus changes and button clicks, for
241 example), or by XQueryPointer calls; when one of these happens, we
242 get another MotionNotify event the next time the mouse moves. This
243 is at least as efficient as getting motion events when mouse
244 tracking is on, and I suspect only negligibly worse when tracking
247 The silly O'Reilly & Associates Nutshell guides barely document
248 pointer motion hints at all (I think you have to infer how they
249 work from an example), and the description of XQueryPointer doesn't
250 mention that calling it causes you to get another motion hint from
251 the server, which is very important. */
253 /* Where the mouse was last time we reported a mouse event. */
254 static FRAME_PTR last_mouse_frame
;
255 static XRectangle last_mouse_glyph
;
257 /* The scroll bar in which the last X motion event occurred.
259 If the last X motion event occurred in a scroll bar, we set this
260 so XTmouse_position can know whether to report a scroll bar motion or
263 If the last X motion event didn't occur in a scroll bar, we set this
264 to Qnil, to tell XTmouse_position to return an ordinary motion event. */
265 static Lisp_Object last_mouse_scroll_bar
;
267 /* Record which buttons are currently pressed. */
268 unsigned int x_mouse_grabbed
;
270 /* This is a hack. We would really prefer that XTmouse_position would
271 return the time associated with the position it returns, but there
272 doesn't seem to be any way to wrest the timestamp from the server
273 along with the position query. So, we just keep track of the time
274 of the last movement we received, and return that in hopes that
275 it's somewhat accurate. */
276 static Time last_mouse_movement_time
;
279 /* `t' if a mouse button is depressed. */
281 extern Lisp_Object Vmouse_depressed
;
283 /* Tells if a window manager is present or not. */
285 extern Lisp_Object Vx_no_window_manager
;
287 /* Timestamp that we requested selection data was made. */
288 extern Time requestor_time
;
290 /* ID of the window requesting selection data. */
291 extern Window requestor_window
;
293 /* Nonzero enables some debugging for the X interface code. */
296 #else /* ! defined (HAVE_X11) */
298 /* Bit patterns for the mouse cursor. */
300 short MouseCursor
[] = {
301 0x0000, 0x0008, 0x0018, 0x0038,
302 0x0078, 0x00f8, 0x01f8, 0x03f8,
303 0x07f8, 0x00f8, 0x00d8, 0x0188,
304 0x0180, 0x0300, 0x0300, 0x0000};
306 short MouseMask
[] = {
307 0x000c, 0x001c, 0x003c, 0x007c,
308 0x00fc, 0x01fc, 0x03fc, 0x07fc,
309 0x0ffc, 0x0ffc, 0x01fc, 0x03dc,
310 0x03cc, 0x0780, 0x0780, 0x0300};
312 static short grey_bits
[] = {
313 0x0005, 0x000a, 0x0005, 0x000a};
315 static Pixmap GreyPixmap
= 0;
316 #endif /* ! defined (HAVE_X11) */
318 /* From time to time we get info on an Emacs window, here. */
320 static WINDOWINFO_TYPE windowinfo
;
324 /* A mask of extra modifier bits to put into every keyboard char. */
325 extern int extra_keyboard_modifiers
;
327 extern Display
*XOpenDisplay ();
328 extern Window
XCreateWindow ();
330 extern Cursor
XCreateCursor ();
331 extern FONT_TYPE
*XOpenFont ();
333 static void flashback ();
334 static void redraw_previous_char ();
335 static unsigned int x_x_to_emacs_modifiers ();
338 static void dumpqueue ();
339 #endif /* HAVE_X11 */
342 static int XTcursor_to ();
343 static int XTclear_end_of_line ();
346 /* Starting and ending updates.
348 These hooks are called by update_frame at the beginning and end
349 of a frame update. We record in `updating_frame' the identity
350 of the frame being updated, so that the XT... functions do not
351 need to take a frame as argument. Most of the XT... functions
352 should never be called except during an update, the only exceptions
353 being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */
355 extern int mouse_track_top
, mouse_track_left
, mouse_track_width
;
366 flexlines
= f
->height
;
372 #endif /* HAVE_X11 */
377 static void x_do_pending_expose ();
389 x_do_pending_expose ();
390 #endif /* HAVE_X11 */
392 x_display_cursor (f
, 1);
398 /* External interface to control of standout mode.
399 Call this when about to modify line at position VPOS
400 and not change whether it is highlighted. */
402 XTreassert_line_highlight (new, vpos
)
408 /* Call this when about to modify line at position VPOS
409 and change whether it is highlighted. */
412 XTchange_line_highlight (new_highlight
, vpos
, first_unused_hpos
)
413 int new_highlight
, vpos
, first_unused_hpos
;
415 highlight
= new_highlight
;
416 XTcursor_to (vpos
, 0);
417 XTclear_end_of_line (updating_frame
->width
);
420 /* This is used when starting Emacs and when restarting after suspend.
421 When starting Emacs, no X window is mapped. And nothing must be done
422 to Emacs's own window if it is suspended (though that rarely happens). */
425 XTset_terminal_modes ()
429 /* This is called when exiting or suspending Emacs.
430 Exiting will make the X-windows go away, and suspending
431 requires no action. */
434 XTreset_terminal_modes ()
436 /* XTclear_frame (); */
439 /* Set the nominal cursor position of the frame.
440 This is where display update commands will take effect.
441 This does not affect the place where the cursor-box is displayed. */
444 XTcursor_to (row
, col
)
445 register int row
, col
;
453 if (updating_frame
== 0)
456 x_display_cursor (selected_frame
, 1);
462 /* Display a sequence of N glyphs found at GP.
463 WINDOW is the x-window to output to. LEFT and TOP are starting coords.
464 HL is 1 if this text is highlighted, 2 if the cursor is on it.
466 FONT is the default font to use (for glyphs whose font-code is 0).
468 Since the display generation code is responsible for calling
469 compute_char_face and compute_glyph_face on everything it puts in
470 the display structure, we can assume that the face code on each
471 glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one
472 to which we can actually apply intern_face.
473 Call this function with input blocked. */
476 /* This is the multi-face code. */
479 dumpglyphs (f
, left
, top
, gp
, n
, hl
)
482 register GLYPH
*gp
; /* Points to first GLYPH. */
483 register int n
; /* Number of glyphs to display. */
486 /* Holds characters to be displayed. */
487 char *buf
= (char *) alloca (f
->width
* sizeof (*buf
));
488 register char *cp
; /* Steps through buf[]. */
489 register int tlen
= GLYPH_TABLE_LENGTH
;
490 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
491 Window window
= FRAME_X_WINDOW (f
);
495 /* Get the face-code of the next GLYPH. */
499 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
500 cf
= FAST_GLYPH_FACE (g
);
502 /* Find the run of consecutive glyphs with the same face-code.
503 Extract their character codes into BUF. */
508 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
509 if (FAST_GLYPH_FACE (g
) != cf
)
512 *cp
++ = FAST_GLYPH_CHAR (g
);
517 /* LEN gets the length of the run. */
520 /* Now output this run of chars, with the font and pixel values
521 determined by the face code CF. */
523 struct face
*face
= FRAME_DEFAULT_FACE (f
);
524 FONT_TYPE
*font
= FACE_FONT (face
);
525 GC gc
= FACE_GC (face
);
527 int gc_temporary
= 0;
529 /* First look at the face of the text itself. */
532 /* It's possible for the display table to specify
533 a face code that is out of range. Use 0 in that case. */
534 if (cf
< 0 || cf
>= FRAME_N_COMPUTED_FACES (f
)
535 || FRAME_COMPUTED_FACES (f
) [cf
] == 0)
539 face
= FRAME_MODE_LINE_FACE (f
);
541 face
= intern_face (f
, FRAME_COMPUTED_FACES (f
) [cf
]);
542 font
= FACE_FONT (face
);
547 /* Then comes the distinction between modeline and normal text. */
552 face
= FRAME_MODE_LINE_FACE (f
);
553 font
= FACE_FONT (face
);
558 #define FACE_DEFAULT (~0)
560 /* Now override that if the cursor's on this character. */
565 || (int) face
->font
== FACE_DEFAULT
)
567 gc
= f
->display
.x
->cursor_gc
;
569 /* Cursor on non-default face: must merge. */
575 xgcv
.background
= f
->display
.x
->cursor_pixel
;
576 if (face
== FRAME_DEFAULT_FACE (f
))
577 xgcv
.foreground
= f
->display
.x
->cursor_foreground_pixel
;
579 xgcv
.foreground
= face
->foreground
;
580 /* If the glyph would be invisible,
581 try a different foreground. */
582 if (xgcv
.foreground
== xgcv
.background
)
583 xgcv
.foreground
= face
->background
;
584 if (xgcv
.foreground
== xgcv
.background
)
585 xgcv
.foreground
= f
->display
.x
->cursor_foreground_pixel
;
586 if (xgcv
.foreground
== xgcv
.background
)
587 xgcv
.foreground
= face
->foreground
;
588 /* Make sure the cursor is distinct from text in this face. */
589 if (xgcv
.background
== face
->background
590 && xgcv
.foreground
== face
->foreground
)
592 xgcv
.background
= face
->foreground
;
593 xgcv
.foreground
= face
->background
;
595 xgcv
.font
= face
->font
->fid
;
596 xgcv
.graphics_exposures
= 0;
597 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
598 gc
= XCreateGC (x_current_display
, FRAME_X_WINDOW (f
),
601 if (face
->stipple
&& face
->stipple
!= FACE_DEFAULT
)
602 XSetStipple (x_current_display
, gc
, face
->stipple
);
608 if ((int) font
== FACE_DEFAULT
)
609 font
= f
->display
.x
->font
;
611 XDrawImageString (x_current_display
, window
, gc
,
612 left
, top
+ FONT_BASE (font
), buf
, len
);
615 XFreeGC (x_current_display
, gc
);
617 /* We should probably check for XA_UNDERLINE_POSITION and
618 XA_UNDERLINE_THICKNESS properties on the font, but let's
619 just get the thing working, and come back to that. */
621 int underline_position
= 1;
623 if (font
->descent
<= underline_position
)
624 underline_position
= font
->descent
- 1;
627 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
),
631 + underline_position
),
632 len
* FONT_WIDTH (font
), 1);
635 left
+= len
* FONT_WIDTH (font
);
642 /* This is the old single-face code. */
645 dumpglyphs (f
, left
, top
, gp
, n
, hl
, font
)
648 register GLYPH
*gp
; /* Points to first GLYPH. */
649 register int n
; /* Number of glyphs to display. */
654 Window window
= FRAME_X_WINDOW (f
);
655 GC drawing_gc
= (hl
== 2 ? f
->display
.x
->cursor_gc
656 : (hl
? f
->display
.x
->reverse_gc
657 : f
->display
.x
->normal_gc
));
659 if (sizeof (GLYPH
) == sizeof (XChar2b
))
660 XDrawImageString16 (x_current_display
, window
, drawing_gc
,
661 left
, top
+ FONT_BASE (font
), (XChar2b
*) gp
, n
);
662 else if (sizeof (GLYPH
) == sizeof (unsigned char))
663 XDrawImageString (x_current_display
, window
, drawing_gc
,
664 left
, top
+ FONT_BASE (font
), (char *) gp
, n
);
666 /* What size of glyph ARE you using? And does X have a function to
672 /* Output some text at the nominal frame cursor position.
673 Advance the cursor over the text.
674 Output LEN glyphs at START.
676 `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight,
677 controls the pixel values used for foreground and background. */
680 XTwrite_glyphs (start
, len
)
681 register GLYPH
*start
;
684 register int temp_length
;
694 /* If not within an update,
695 output at the frame's visible cursor. */
696 curs_x
= f
->cursor_x
;
697 curs_y
= f
->cursor_y
;
701 CHAR_TO_PIXEL_COL (f
, curs_x
),
702 CHAR_TO_PIXEL_ROW (f
, curs_y
),
703 start
, len
, highlight
);
705 /* If we drew on top of the cursor, note that it is turned off. */
706 if (curs_y
== f
->phys_cursor_y
707 && curs_x
<= f
->phys_cursor_x
708 && curs_x
+ len
> f
->phys_cursor_x
)
709 f
->phys_cursor_x
= -1;
711 if (updating_frame
== 0)
714 x_display_cursor (f
, 1);
723 /* Clear to the end of the line.
724 Erase the current text line from the nominal cursor position (inclusive)
725 to column FIRST_UNUSED (exclusive). The idea is that everything
726 from FIRST_UNUSED onward is already erased. */
729 XTclear_end_of_line (first_unused
)
730 register int first_unused
;
732 struct frame
*f
= updating_frame
;
738 if (curs_y
< 0 || curs_y
>= f
->height
)
740 if (first_unused
<= 0)
743 if (first_unused
>= f
->width
)
744 first_unused
= f
->width
;
748 /* Notice if the cursor will be cleared by this operation. */
749 if (curs_y
== f
->phys_cursor_y
750 && curs_x
<= f
->phys_cursor_x
751 && f
->phys_cursor_x
< first_unused
)
752 f
->phys_cursor_x
= -1;
755 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
756 CHAR_TO_PIXEL_COL (f
, curs_x
),
757 CHAR_TO_PIXEL_ROW (f
, curs_y
),
758 FONT_WIDTH (f
->display
.x
->font
) * (first_unused
- curs_x
),
759 FONT_HEIGHT (f
->display
.x
->font
), False
);
761 redraw_previous_char (f
, curs_x
, curs_y
);
763 #else /* ! defined (HAVE_X11) */
764 XPixSet (FRAME_X_WINDOW (f
),
765 CHAR_TO_PIXEL_COL (f
, curs_x
),
766 CHAR_TO_PIXEL_ROW (f
, curs_y
),
767 FONT_WIDTH (f
->display
.x
->font
) * (first_unused
- curs_x
),
768 FONT_HEIGHT (f
->display
.x
->font
),
769 f
->display
.x
->background_pixel
);
770 #endif /* ! defined (HAVE_X11) */
775 /* Erase the character (if any) at the position just before X, Y in frame F,
776 then redraw it and the character before it.
777 This is necessary when we erase starting at X,
778 in case the character after X overlaps into the one before X.
779 Call this function with input blocked. */
782 redraw_previous_char (f
, x
, y
)
786 /* Erase the character before the new ones, in case
787 what was here before overlaps it.
788 Reoutput that character, and the previous character
789 (in case the previous character overlaps it). */
795 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
796 CHAR_TO_PIXEL_COL (f
, x
- 1),
797 CHAR_TO_PIXEL_ROW (f
, y
),
798 FONT_WIDTH (f
->display
.x
->font
),
799 FONT_HEIGHT (f
->display
.x
->font
), False
);
801 dumpglyphs (f
, CHAR_TO_PIXEL_COL (f
, start_x
),
802 CHAR_TO_PIXEL_ROW (f
, y
),
803 &FRAME_CURRENT_GLYPHS (f
)->glyphs
[y
][start_x
],
804 x
- start_x
, highlight
);
812 struct frame
*f
= updating_frame
;
817 f
->phys_cursor_x
= -1; /* Cursor not visible. */
818 curs_x
= 0; /* Nominal cursor position is top left. */
823 XClear (FRAME_X_WINDOW (f
));
825 /* We have to clear the scroll bars, too. If we have changed
826 colors or something like that, then they should be notified. */
827 x_scroll_bar_clear (f
);
831 #endif /* HAVE_X11 */
837 /* Invert the middle quarter of the frame for .15 sec. */
839 /* We use the select system call to do the waiting, so we have to make sure
840 it's available. If it isn't, we just won't do visual bells. */
841 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
843 /* Subtract the `struct timeval' values X and Y,
844 storing the result in RESULT.
845 Return 1 if the difference is negative, otherwise 0. */
848 timeval_subtract (result
, x
, y
)
849 struct timeval
*result
, x
, y
;
851 /* Perform the carry for the later subtraction by updating y.
852 This is safer because on some systems
853 the tv_sec member is unsigned. */
854 if (x
.tv_usec
< y
.tv_usec
)
856 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
857 y
.tv_usec
-= 1000000 * nsec
;
860 if (x
.tv_usec
- y
.tv_usec
> 1000000)
862 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
863 y
.tv_usec
+= 1000000 * nsec
;
867 /* Compute the time remaining to wait. tv_usec is certainly positive. */
868 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
869 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
871 /* Return indication of whether the result should be considered negative. */
872 return x
.tv_sec
< y
.tv_sec
;
883 /* Create a GC that will use the GXxor function to flip foreground pixels
884 into background pixels. */
888 values
.function
= GXxor
;
889 values
.foreground
= (f
->display
.x
->foreground_pixel
890 ^ f
->display
.x
->background_pixel
);
892 gc
= XCreateGC (x_current_display
, FRAME_X_WINDOW (f
),
893 GCFunction
| GCForeground
, &values
);
897 int width
= PIXEL_WIDTH (f
);
898 int height
= PIXEL_HEIGHT (f
);
900 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
), gc
,
901 width
/4, height
/4, width
/2, height
/2);
902 XFlush (x_current_display
);
905 struct timeval wakeup
, now
;
907 EMACS_GET_TIME (wakeup
);
909 /* Compute time to wait until, propagating carry from usecs. */
910 wakeup
.tv_usec
+= 150000;
911 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
912 wakeup
.tv_usec
%= 1000000;
914 /* Keep waiting until past the time wakeup. */
917 struct timeval timeout
;
919 EMACS_GET_TIME (timeout
);
921 /* In effect, timeout = wakeup - timeout.
922 Break if result would be negative. */
923 if (timeval_subtract (&timeout
, wakeup
, timeout
))
926 /* Try to wait that long--but we might wake up sooner. */
927 select (0, 0, 0, 0, &timeout
);
931 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
), gc
,
932 width
/4, height
/4, width
/2, height
/2);
933 XFreeGC (x_current_display
, gc
);
934 XFlush (x_current_display
);
944 /* Make audible bell. */
947 #define XRINGBELL XBell (x_current_display, 0)
948 #else /* ! defined (HAVE_X11) */
949 #define XRINGBELL XFeep (0);
950 #endif /* ! defined (HAVE_X11) */
954 if (x_current_display
== 0)
957 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
959 XTflash (selected_frame
);
970 /* Insert and delete character.
971 These are not supposed to be used because we are supposed to turn
972 off the feature of using them. */
975 XTinsert_glyphs (start
, len
)
976 register char *start
;
989 /* Specify how many text lines, from the top of the window,
990 should be affected by insert-lines and delete-lines operations.
991 This, and those operations, are used only within an update
992 that is bounded by calls to XTupdate_begin and XTupdate_end. */
995 XTset_terminal_window (n
)
998 if (updating_frame
== 0)
1001 if ((n
<= 0) || (n
> updating_frame
->height
))
1002 flexlines
= updating_frame
->height
;
1007 /* Perform an insert-lines operation.
1008 Insert N lines at a vertical position curs_y. */
1014 register int topregion
, bottomregion
;
1015 register int length
, newtop
, mask
;
1016 register struct frame
*f
= updating_frame
;
1017 int intborder
= f
->display
.x
->internal_border_width
;
1019 if (curs_y
>= flexlines
)
1023 bottomregion
= flexlines
- (n
+ 1);
1024 newtop
= topregion
+ n
;
1025 length
= (bottomregion
- topregion
) + 1;
1029 #endif /* HAVE_X11 */
1031 if ((length
> 0) && (newtop
<= flexlines
))
1034 XCopyArea (x_current_display
, FRAME_X_WINDOW (f
),
1035 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1036 intborder
, CHAR_TO_PIXEL_ROW (f
, topregion
),
1037 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1038 length
* FONT_HEIGHT (f
->display
.x
->font
), intborder
,
1039 CHAR_TO_PIXEL_ROW (f
, newtop
));
1040 #else /* ! defined (HAVE_X11) */
1041 XMoveArea (FRAME_X_WINDOW (f
),
1042 intborder
, CHAR_TO_PIXEL_ROW (f
, topregion
),
1043 intborder
, CHAR_TO_PIXEL_ROW (f
, newtop
),
1044 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1045 length
* FONT_HEIGHT (f
->display
.x
->font
));
1046 /* Now we must process any ExposeRegion events that occur
1047 if the area being copied from is obscured.
1048 We can't let it wait because further i/d operations
1049 may want to copy this area to another area. */
1051 #endif /* ! defined (HAVE_X11) */
1054 newtop
= min (newtop
, (flexlines
- 1));
1055 length
= newtop
- topregion
;
1059 XClearArea (x_current_display
, FRAME_X_WINDOW (f
), intborder
,
1060 CHAR_TO_PIXEL_ROW (f
, topregion
),
1061 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1062 n
* FONT_HEIGHT (f
->display
.x
->font
), False
);
1063 #else /* ! defined (HAVE_X11) */
1064 XPixSet (FRAME_X_WINDOW (f
),
1066 CHAR_TO_PIXEL_ROW (f
, topregion
),
1067 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1068 n
* FONT_HEIGHT (f
->display
.x
->font
),
1069 f
->display
.x
->background_pixel
);
1070 #endif /* ! defined (HAVE_X11) */
1074 /* Perform a delete-lines operation, deleting N lines
1075 at a vertical position curs_y. */
1082 register struct frame
*f
= updating_frame
;
1083 int intborder
= f
->display
.x
->internal_border_width
;
1085 if (curs_y
>= flexlines
)
1090 #endif /* HAVE_X11 */
1092 if ((curs_y
+ n
) >= flexlines
)
1094 if (flexlines
>= (curs_y
+ 1))
1097 XClearArea (x_current_display
, FRAME_X_WINDOW (f
), intborder
,
1098 CHAR_TO_PIXEL_ROW (f
, curs_y
),
1099 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1100 (flexlines
- curs_y
) * FONT_HEIGHT (f
->display
.x
->font
), False
);
1101 #else /* ! defined (HAVE_X11) */
1102 XPixSet (FRAME_X_WINDOW (f
),
1103 intborder
, CHAR_TO_PIXEL_ROW (f
, curs_y
),
1104 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1105 (flexlines
- curs_y
) * FONT_HEIGHT (f
->display
.x
->font
),
1106 f
->display
.x
->background_pixel
);
1107 #endif /* ! defined (HAVE_X11) */
1113 XCopyArea (x_current_display
, FRAME_X_WINDOW (f
),
1114 FRAME_X_WINDOW (f
), f
->display
.x
->normal_gc
,
1116 CHAR_TO_PIXEL_ROW (f
, curs_y
+ n
),
1117 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1118 (flexlines
- (curs_y
+ n
)) * FONT_HEIGHT (f
->display
.x
->font
),
1119 intborder
, CHAR_TO_PIXEL_ROW (f
, curs_y
));
1120 XClearArea (x_current_display
, FRAME_X_WINDOW (f
),
1122 CHAR_TO_PIXEL_ROW (f
, flexlines
- n
),
1123 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1124 n
* FONT_HEIGHT (f
->display
.x
->font
), False
);
1125 #else /* ! defined (HAVE_X11) */
1126 XMoveArea (FRAME_X_WINDOW (f
),
1128 CHAR_TO_PIXEL_ROW (f
, curs_y
+ n
),
1129 intborder
, CHAR_TO_PIXEL_ROW (f
, curs_y
),
1130 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1131 (flexlines
- (curs_y
+ n
)) * FONT_HEIGHT (f
->display
.x
->font
));
1132 /* Now we must process any ExposeRegion events that occur
1133 if the area being copied from is obscured.
1134 We can't let it wait because further i/d operations
1135 may want to copy this area to another area. */
1137 XPixSet (FRAME_X_WINDOW (f
), intborder
,
1138 CHAR_TO_PIXEL_ROW (f
, flexlines
- n
),
1139 f
->width
* FONT_WIDTH (f
->display
.x
->font
),
1140 n
* FONT_HEIGHT (f
->display
.x
->font
), f
->display
.x
->background_pixel
);
1141 #endif /* ! defined (HAVE_X11) */
1145 /* Perform an insert-lines or delete-lines operation,
1146 inserting N lines or deleting -N lines at vertical position VPOS. */
1148 XTins_del_lines (vpos
, n
)
1151 if (updating_frame
== 0)
1154 /* Hide the cursor. */
1155 x_display_cursor (updating_frame
, 0);
1157 XTcursor_to (vpos
, 0);
1168 /* Support routines for exposure events. */
1169 static void clear_cursor ();
1171 /* Output into a rectangle of an X-window (for frame F)
1172 the characters in f->phys_lines that overlap that rectangle.
1173 TOP and LEFT are the position of the upper left corner of the rectangle.
1174 ROWS and COLS are the size of the rectangle.
1175 Call this function with input blocked. */
1178 dumprectangle (f
, left
, top
, cols
, rows
)
1180 register int left
, top
, cols
, rows
;
1182 register struct frame_glyphs
*active_frame
= FRAME_CURRENT_GLYPHS (f
);
1183 int cursor_cleared
= 0;
1187 if (FRAME_GARBAGED_P (f
))
1190 /* Express rectangle as four edges, instead of position-and-size. */
1191 bottom
= top
+ rows
;
1192 right
= left
+ cols
;
1194 #ifndef HAVE_X11 /* Window manger does this for X11. */
1196 int intborder
= f
->display
.x
->internal_border_width
;
1198 /* If the rectangle includes any of the internal border area,
1199 redisplay the border emphasis. */
1200 if (top
< intborder
|| left
< intborder
1201 || bottom
> intborder
+ f
->height
* FONT_HEIGHT (f
->display
.x
->font
)
1202 || right
> intborder
+ f
->width
* FONT_WIDTH (f
->display
.x
->font
))
1205 #endif /* HAVE_X11 Window manger does this for X11. */
1207 /* Convert rectangle edges in pixels to edges in chars.
1208 Round down for left and top, up for right and bottom. */
1209 top
= PIXEL_TO_CHAR_ROW (f
, top
);
1210 left
= PIXEL_TO_CHAR_COL (f
, left
);
1211 bottom
+= (FONT_HEIGHT (f
->display
.x
->font
) - 1);
1212 right
+= (FONT_WIDTH (f
->display
.x
->font
) - 1);
1213 bottom
= PIXEL_TO_CHAR_ROW (f
, bottom
);
1214 right
= PIXEL_TO_CHAR_COL (f
, right
);
1216 /* Clip the rectangle to what can be visible. */
1221 if (right
> f
->width
)
1223 if (bottom
> f
->height
)
1226 /* Get size in chars of the rectangle. */
1227 cols
= right
- left
;
1228 rows
= bottom
- top
;
1230 /* If rectangle has zero area, return. */
1231 if (rows
<= 0) return;
1232 if (cols
<= 0) return;
1234 /* Turn off the cursor if it is in the rectangle.
1235 We will turn it back on afterward. */
1236 if ((f
->phys_cursor_x
>= left
) && (f
->phys_cursor_x
< right
)
1237 && (f
->phys_cursor_y
>= top
) && (f
->phys_cursor_y
< bottom
))
1243 /* Display the text in the rectangle, one text line at a time. */
1245 for (y
= top
; y
< bottom
; y
++)
1247 GLYPH
*line
= &active_frame
->glyphs
[y
][left
];
1249 if (! active_frame
->enable
[y
] || left
> active_frame
->used
[y
])
1253 CHAR_TO_PIXEL_COL (f
, left
),
1254 CHAR_TO_PIXEL_ROW (f
, y
),
1255 line
, min (cols
, active_frame
->used
[y
] - left
),
1256 active_frame
->highlight
[y
]);
1259 /* Turn the cursor on if we turned it off. */
1262 x_display_cursor (f
, 1);
1266 /* Process all queued ExposeRegion events. */
1272 XExposeRegionEvent r
;
1274 while (dequeue_event (&r
, &x_expose_queue
))
1276 struct frame
*f
= x_window_to_frame (r
.window
);
1277 if (f
->display
.x
->icon_desc
== r
.window
)
1280 dumprectangle (f
, r
.x
, r
.y
, r
.width
, r
.height
);
1284 #endif /* HAVE_X11 */
1286 /* Process all expose events that are pending, for X10.
1287 Redraws the cursor if necessary on any frame that
1288 is not in the process of being updated with update_frame. */
1292 x_do_pending_expose ()
1296 Lisp_Object tail
, frame
;
1298 if (expose_all_windows
)
1300 expose_all_windows
= 0;
1301 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1303 register int temp_width
, temp_height
;
1306 frame
= XCONS (tail
)->car
;
1307 if (XGCTYPE (frame
) != Lisp_Frame
)
1310 if (! FRAME_X_P (f
))
1312 if (!f
->async_visible
)
1314 if (!f
->display
.x
->needs_exposure
)
1317 intborder
= f
->display
.x
->internal_border_width
;
1320 XGetWindowInfo (FRAME_X_WINDOW (f
), &windowinfo
);
1321 temp_width
= ((windowinfo
.width
- 2 * intborder
1322 - f
->display
.x
->v_scroll_bar_width
)
1323 / FONT_WIDTH (f
->display
.x
->font
));
1324 temp_height
= ((windowinfo
.height
- 2 * intborder
1325 - f
->display
.x
->h_scroll_bar_height
)
1326 / FONT_HEIGHT (f
->display
.x
->font
));
1327 if (temp_width
!= f
->width
|| temp_height
!= f
->height
)
1329 change_frame_size (f
, max (1, temp_height
),
1330 max (1, temp_width
), 0, 1);
1331 x_resize_scroll_bars (f
);
1333 f
->display
.x
->left_pos
= windowinfo
.x
;
1334 f
->display
.x
->top_pos
= windowinfo
.y
;
1335 dumprectangle (f
, 0, 0, PIXEL_WIDTH (f
), PIXEL_HEIGHT (f
));
1339 f
->display
.x
->needs_exposure
= 0;
1340 if (updating_frame
!= f
)
1341 x_display_cursor (f
, 1);
1346 /* Handle any individual-rectangle expose events queued
1347 for various windows. */
1350 #else /* ! defined (HAVE_X11) */
1352 #endif /* ! defined (HAVE_X11) */
1358 frame_highlight (frame
)
1359 struct frame
*frame
;
1361 /* We used to only do this if Vx_no_window_manager was non-nil, but
1362 the ICCCM (section 4.1.6) says that the window's border pixmap
1363 and border pixel are window attributes which are "private to the
1364 client", so we can always change it to whatever we want. */
1366 XSetWindowBorder (x_current_display
, FRAME_X_WINDOW (frame
),
1367 frame
->display
.x
->border_pixel
);
1369 x_display_cursor (frame
, 1);
1373 frame_unhighlight (frame
)
1374 struct frame
*frame
;
1376 /* We used to only do this if Vx_no_window_manager was non-nil, but
1377 the ICCCM (section 4.1.6) says that the window's border pixmap
1378 and border pixel are window attributes which are "private to the
1379 client", so we can always change it to whatever we want. */
1381 XSetWindowBorderPixmap (x_current_display
, FRAME_X_WINDOW (frame
),
1382 frame
->display
.x
->border_tile
);
1384 x_display_cursor (frame
, 1);
1386 #else /* ! defined (HAVE_X11) */
1387 /* Dump the border-emphasis of frame F.
1388 If F is selected, this is a lining of the same color as the border,
1389 just within the border, occupying a portion of the internal border.
1390 If F is not selected, it is background in the same place.
1391 If ALWAYS is 0, don't bother explicitly drawing if it's background.
1393 ALWAYS = 1 is used when a frame becomes selected or deselected.
1394 In that case, we also turn the cursor off and on again
1395 so it will appear in the proper shape (solid if selected; else hollow.) */
1398 dumpborder (f
, always
)
1402 int thickness
= f
->display
.x
->internal_border_width
/ 2;
1403 int width
= PIXEL_WIDTH (f
);
1404 int height
= PIXEL_HEIGHT (f
);
1407 if (f
!= selected_frame
)
1412 pixel
= f
->display
.x
->background_pixel
;
1416 pixel
= f
->display
.x
->border_pixel
;
1419 XPixSet (FRAME_X_WINDOW (f
), 0, 0, width
, thickness
, pixel
);
1420 XPixSet (FRAME_X_WINDOW (f
), 0, 0, thickness
, height
, pixel
);
1421 XPixSet (FRAME_X_WINDOW (f
), 0, height
- thickness
, width
,
1423 XPixSet (FRAME_X_WINDOW (f
), width
- thickness
, 0, thickness
,
1427 x_display_cursor (f
, 1);
1429 #endif /* ! defined (HAVE_X11) */
1431 static void XTframe_rehighlight ();
1433 /* The focus has changed. Update the frames as necessary to reflect
1434 the new situation. Note that we can't change the selected frame
1435 here, because the lisp code we are interrupting might become confused.
1436 Each event gets marked with the frame in which it occurred, so the
1437 lisp code can tell when the switch took place by examining the events. */
1440 x_new_focus_frame (frame
)
1441 struct frame
*frame
;
1443 struct frame
*old_focus
= x_focus_frame
;
1444 int events_enqueued
= 0;
1446 if (frame
!= x_focus_frame
)
1448 /* Set this before calling other routines, so that they see
1449 the correct value of x_focus_frame. */
1450 x_focus_frame
= frame
;
1452 if (old_focus
&& old_focus
->auto_lower
)
1453 x_lower_frame (old_focus
);
1456 selected_frame
= frame
;
1457 XSET (XWINDOW (selected_frame
->selected_window
)->frame
,
1458 Lisp_Frame
, selected_frame
);
1459 Fselect_window (selected_frame
->selected_window
);
1460 choose_minibuf_frame ();
1463 if (x_focus_frame
&& x_focus_frame
->auto_raise
)
1464 x_raise_frame (x_focus_frame
);
1467 XTframe_rehighlight ();
1471 /* The focus has changed, or we have redirected a frame's focus to
1472 another frame (this happens when a frame uses a surrogate
1473 minibuffer frame). Shift the highlight as appropriate. */
1475 XTframe_rehighlight ()
1477 struct frame
*old_highlight
= x_highlight_frame
;
1482 ((XGCTYPE (FRAME_FOCUS_FRAME (x_focus_frame
)) == Lisp_Frame
)
1483 ? XFRAME (FRAME_FOCUS_FRAME (x_focus_frame
))
1485 if (! FRAME_LIVE_P (x_highlight_frame
))
1487 FRAME_FOCUS_FRAME (x_focus_frame
) = Qnil
;
1488 x_highlight_frame
= x_focus_frame
;
1492 x_highlight_frame
= 0;
1494 if (x_highlight_frame
!= old_highlight
)
1497 frame_unhighlight (old_highlight
);
1498 if (x_highlight_frame
)
1499 frame_highlight (x_highlight_frame
);
1503 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
1505 /* Which modifier keys are on which modifier bits?
1507 With each keystroke, X returns eight bits indicating which modifier
1508 keys were held down when the key was pressed. The interpretation
1509 of the top five modifier bits depends on what keys are attached
1510 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
1513 x_meta_mod_mask is a mask containing the bits used for the meta key.
1514 It may have more than one bit set, if more than one modifier bit
1515 has meta keys on it. Basically, if EVENT is a KeyPress event,
1516 the meta key is pressed if (EVENT.state & x_meta_mod_mask) != 0.
1518 x_shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
1519 lock modifier bit, or zero otherwise. Non-alphabetic keys should
1520 only be affected by the lock modifier bit if XK_Shift_Lock is in
1521 use; XK_Caps_Lock should only affect alphabetic keys. With this
1522 arrangement, the lock modifier should shift the character if
1523 (EVENT.state & x_shift_lock_mask) != 0. */
1524 static int x_meta_mod_mask
, x_shift_lock_mask
;
1526 /* These are like x_meta_mod_mask, but for different modifiers. */
1527 static int x_alt_mod_mask
, x_super_mod_mask
, x_hyper_mod_mask
;
1529 /* Initialize mode_switch_bit and modifier_meaning. */
1531 x_find_modifier_meanings ()
1533 int min_code
, max_code
;
1536 XModifierKeymap
*mods
;
1538 x_meta_mod_mask
= 0;
1539 x_shift_lock_mask
= 0;
1541 x_super_mod_mask
= 0;
1542 x_hyper_mod_mask
= 0;
1545 XDisplayKeycodes (x_current_display
, &min_code
, &max_code
);
1547 min_code
= x_current_display
->min_keycode
;
1548 max_code
= x_current_display
->max_keycode
;
1551 syms
= XGetKeyboardMapping (x_current_display
,
1552 min_code
, max_code
- min_code
+ 1,
1554 mods
= XGetModifierMapping (x_current_display
);
1556 /* Scan the modifier table to see which modifier bits the Meta and
1557 Alt keysyms are on. */
1559 int row
, col
; /* The row and column in the modifier table. */
1561 for (row
= 3; row
< 8; row
++)
1562 for (col
= 0; col
< mods
->max_keypermod
; col
++)
1565 mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
1567 /* Zeroes are used for filler. Skip them. */
1571 /* Are any of this keycode's keysyms a meta key? */
1575 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
1577 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
1583 x_meta_mod_mask
|= (1 << row
);
1588 x_alt_mod_mask
|= (1 << row
);
1593 x_hyper_mod_mask
|= (1 << row
);
1598 x_super_mod_mask
|= (1 << row
);
1602 /* Ignore this if it's not on the lock modifier. */
1603 if ((1 << row
) == LockMask
)
1604 x_shift_lock_mask
= LockMask
;
1612 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
1613 if (! x_meta_mod_mask
)
1615 x_meta_mod_mask
= x_alt_mod_mask
;
1619 /* If some keys are both alt and meta,
1620 make them just meta, not alt. */
1621 if (x_alt_mod_mask
& x_meta_mod_mask
)
1623 x_alt_mod_mask
&= ~x_meta_mod_mask
;
1626 XFree ((char *) syms
);
1627 XFreeModifiermap (mods
);
1630 /* Convert between the modifier bits X uses and the modifier bits
1633 x_x_to_emacs_modifiers (state
)
1636 return ( ((state
& (ShiftMask
| x_shift_lock_mask
)) ? shift_modifier
: 0)
1637 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
1638 | ((state
& x_meta_mod_mask
) ? meta_modifier
: 0)
1639 | ((state
& x_alt_mod_mask
) ? alt_modifier
: 0)
1640 | ((state
& x_super_mod_mask
) ? super_modifier
: 0)
1641 | ((state
& x_hyper_mod_mask
) ? hyper_modifier
: 0));
1645 x_emacs_to_x_modifiers (state
)
1648 return ( ((state
& alt_modifier
) ? x_alt_mod_mask
: 0)
1649 | ((state
& super_modifier
) ? x_super_mod_mask
: 0)
1650 | ((state
& hyper_modifier
) ? x_hyper_mod_mask
: 0)
1651 | ((state
& shift_modifier
) ? ShiftMask
: 0)
1652 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
1653 | ((state
& meta_modifier
) ? x_meta_mod_mask
: 0));
1656 /* Return true iff KEYSYM is a vendor-specific keysym that we should
1657 return as a function key. If you add a keysym to this, you should
1658 make sure that the tables make_lispy_event uses contain a suitable
1661 x_is_vendor_fkey (sym
)
1666 || (sym
== DXK_Remove
)
1672 /* Mouse clicks and mouse movement. Rah. */
1675 /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
1676 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
1677 that the glyph at X, Y occupies, if BOUNDS != 0.
1678 If NOCLIP is nonzero, do not force the value into range. */
1681 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1683 register int pix_x
, pix_y
;
1684 register int *x
, *y
;
1688 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1689 even for negative values. */
1691 pix_x
-= FONT_WIDTH ((f
)->display
.x
->font
) - 1;
1693 pix_y
-= FONT_HEIGHT ((f
)->display
.x
->font
) - 1;
1695 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
1696 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
1700 bounds
->width
= FONT_WIDTH (f
->display
.x
->font
);
1701 bounds
->height
= FONT_HEIGHT (f
->display
.x
->font
);
1702 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
1703 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
1710 else if (pix_x
> f
->width
)
1715 else if (pix_y
> f
->height
)
1724 glyph_to_pixel_coords (f
, x
, y
, pix_x
, pix_y
)
1727 register int *pix_x
, *pix_y
;
1729 *pix_x
= CHAR_TO_PIXEL_COL (f
, x
);
1730 *pix_y
= CHAR_TO_PIXEL_ROW (f
, y
);
1733 /* Prepare a mouse-event in *RESULT for placement in the input queue.
1735 If the event is a button press, then note that we have grabbed
1739 construct_mouse_click (result
, event
, f
)
1740 struct input_event
*result
;
1741 XButtonEvent
*event
;
1744 /* Make the event type no_event; we'll change that when we decide
1746 result
->kind
= mouse_click
;
1747 result
->code
= event
->button
- Button1
;
1748 result
->timestamp
= event
->time
;
1749 result
->modifiers
= (x_x_to_emacs_modifiers (event
->state
)
1750 | (event
->type
== ButtonRelease
1754 /* Notice if the mouse is still grabbed. */
1755 if (event
->type
== ButtonPress
)
1757 if (! x_mouse_grabbed
)
1758 Vmouse_depressed
= Qt
;
1759 x_mouse_grabbed
|= (1 << event
->button
);
1760 last_mouse_frame
= f
;
1762 else if (event
->type
== ButtonRelease
)
1764 x_mouse_grabbed
&= ~(1 << event
->button
);
1765 if (!x_mouse_grabbed
)
1766 Vmouse_depressed
= Qnil
;
1773 pixel_to_glyph_coords (f
, event
->x
, event
->y
, &column
, &row
, NULL
, 0);
1774 XFASTINT (result
->x
) = column
;
1775 XFASTINT (result
->y
) = row
;
1777 XFASTINT (result
->x
) = event
->x
;
1778 XFASTINT (result
->y
) = event
->y
;
1779 XSET (result
->frame_or_window
, Lisp_Frame
, f
);
1783 /* Prepare a menu-event in *RESULT for placement in the input queue. */
1786 construct_menu_click (result
, event
, f
)
1787 struct input_event
*result
;
1788 XButtonEvent
*event
;
1791 /* Make the event type no_event; we'll change that when we decide
1793 result
->kind
= mouse_click
;
1794 XSET (result
->code
, Lisp_Int
, event
->button
- Button1
);
1795 result
->timestamp
= event
->time
;
1796 result
->modifiers
= (x_x_to_emacs_modifiers (event
->state
)
1797 | (event
->type
== ButtonRelease
1801 XFASTINT (result
->x
) = event
->x
;
1802 XSETINT (result
->y
, -1);
1803 XSET (result
->frame_or_window
, Lisp_Frame
, f
);
1806 /* Function to report a mouse movement to the mainstream Emacs code.
1807 The input handler calls this.
1809 We have received a mouse movement event, which is given in *event.
1810 If the mouse is over a different glyph than it was last time, tell
1811 the mainstream emacs code by setting mouse_moved. If not, ask for
1812 another motion event, so we can check again the next time it moves. */
1814 note_mouse_movement (frame
, event
)
1816 XMotionEvent
*event
;
1819 last_mouse_movement_time
= event
->time
;
1821 /* Has the mouse moved off the glyph it was on at the last sighting? */
1822 if (event
->x
< last_mouse_glyph
.x
1823 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
1824 || event
->y
< last_mouse_glyph
.y
1825 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
1828 last_mouse_scroll_bar
= Qnil
;
1832 /* It's on the same glyph. Call XQueryPointer so we'll get an
1833 event the next time the mouse moves and we can see if it's
1834 *still* on the same glyph. */
1837 XQueryPointer (event
->display
, event
->window
,
1838 (Window
*) &dummy
, (Window
*) &dummy
,
1839 &dummy
, &dummy
, &dummy
, &dummy
,
1840 (unsigned int *) &dummy
);
1844 static struct scroll_bar
*x_window_to_scroll_bar ();
1845 static void x_scroll_bar_report_motion ();
1847 /* Return the current position of the mouse.
1849 If the mouse movement started in a scroll bar, set *f, *bar_window,
1850 and *part to the frame, window, and scroll bar part that the mouse
1851 is over. Set *x and *y to the portion and whole of the mouse's
1852 position on the scroll bar.
1854 If the mouse movement started elsewhere, set *f to the frame the
1855 mouse is on, *bar_window to nil, and *x and *y to the character cell
1858 Set *time to the server timestamp for the time at which the mouse
1859 was at this position.
1861 Don't store anything if we don't have a valid set of values to report.
1863 This clears the mouse_moved flag, so we can wait for the next mouse
1864 movement. This also calls XQueryPointer, which will cause the
1865 server to give us another MotionNotify when the mouse moves
1869 XTmouse_position (f
, bar_window
, part
, x
, y
, time
)
1871 Lisp_Object
*bar_window
;
1872 enum scroll_bar_part
*part
;
1874 unsigned long *time
;
1880 if (! NILP (last_mouse_scroll_bar
))
1881 x_scroll_bar_report_motion (f
, bar_window
, part
, x
, y
, time
);
1887 Window dummy_window
;
1891 last_mouse_scroll_bar
= Qnil
;
1893 /* Figure out which root window we're on. */
1894 XQueryPointer (x_current_display
,
1895 DefaultRootWindow (x_current_display
),
1897 /* The root window which contains the pointer. */
1900 /* Trash which we can't trust if the pointer is on
1901 a different screen. */
1904 /* The position on that root window. */
1907 /* More trash we can't trust. */
1910 /* Modifier keys and pointer buttons, about which
1912 (unsigned int *) &dummy
);
1914 /* Now we have a position on the root; find the innermost window
1915 containing the pointer. */
1919 int parent_x
, parent_y
;
1923 if (x_mouse_grabbed
)
1925 /* If mouse was grabbed on a frame, give coords for that frame
1926 even if the mouse is now outside it. */
1927 XTranslateCoordinates (x_current_display
,
1929 /* From-window, to-window. */
1930 root
, FRAME_X_WINDOW (last_mouse_frame
),
1932 /* From-position, to-position. */
1933 root_x
, root_y
, &win_x
, &win_y
,
1937 f1
= last_mouse_frame
;
1943 XTranslateCoordinates (x_current_display
,
1945 /* From-window, to-window. */
1948 /* From-position, to-position. */
1949 root_x
, root_y
, &win_x
, &win_y
,
1962 /* Now we know that:
1963 win is the innermost window containing the pointer
1964 (XTC says it has no child containing the pointer),
1965 win_x and win_y are the pointer's position in it
1966 (XTC did this the last time through), and
1967 parent_x and parent_y are the pointer's position in win's parent.
1968 (They are what win_x and win_y were when win was child.
1969 If win is the root window, it has no parent, and
1970 parent_{x,y} are invalid, but that's okay, because we'll
1971 never use them in that case.) */
1973 /* Is win one of our frames? */
1974 f1
= x_any_window_to_frame (win
);
1977 /* If not, is it one of our scroll bars? */
1980 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
1984 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
1992 int ignore1
, ignore2
;
1994 /* Ok, we found a frame. Store all the values. */
1996 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
1997 &last_mouse_glyph
, x_mouse_grabbed
);
2002 XSET (*x
, Lisp_Int
, win_x
);
2003 XSET (*y
, Lisp_Int
, win_y
);
2004 *time
= last_mouse_movement_time
;
2012 #else /* ! defined (HAVE_X11) */
2013 #define XEvent XKeyPressedEvent
2014 #endif /* ! defined (HAVE_X11) */
2016 /* Scroll bar support. */
2018 /* Given an X window ID, find the struct scroll_bar which manages it.
2019 This can be called in GC, so we have to make sure to strip off mark
2021 static struct scroll_bar
*
2022 x_window_to_scroll_bar (window_id
)
2025 Lisp_Object tail
, frame
;
2027 for (tail
= Vframe_list
;
2028 XGCTYPE (tail
) == Lisp_Cons
;
2029 tail
= XCONS (tail
)->cdr
)
2031 Lisp_Object frame
, bar
, condemned
;
2033 frame
= XCONS (tail
)->car
;
2034 /* All elements of Vframe_list should be frames. */
2035 if (XGCTYPE (frame
) != Lisp_Frame
)
2038 /* Scan this frame's scroll bar list for a scroll bar with the
2040 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
2041 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
2042 /* This trick allows us to search both the ordinary and
2043 condemned scroll bar lists with one loop. */
2044 ! GC_NILP (bar
) || (bar
= condemned
,
2047 bar
= XSCROLL_BAR (bar
)->next
)
2048 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
2049 return XSCROLL_BAR (bar
);
2055 /* Open a new X window to serve as a scroll bar, and return the
2056 scroll bar vector for it. */
2057 static struct scroll_bar
*
2058 x_scroll_bar_create (window
, top
, left
, width
, height
)
2059 struct window
*window
;
2060 int top
, left
, width
, height
;
2062 FRAME_PTR frame
= XFRAME (WINDOW_FRAME (window
));
2063 struct scroll_bar
*bar
=
2064 XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
2069 XSetWindowAttributes a
;
2071 a
.background_pixel
= frame
->display
.x
->background_pixel
;
2072 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
2073 | ButtonMotionMask
| PointerMotionHintMask
2075 a
.cursor
= x_vertical_scroll_bar_cursor
;
2077 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
2082 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2083 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2084 XtSetArg (al
[ac
], XtNwidth
, width
); ac
++;
2085 XtSetArg (al
[ac
], XtNheight
, height
); ac
++;
2086 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2087 sb_widget
= XtCreateManagedWidget ("box",
2089 frame
->display
.x
->edit_widget
, al
, ac
);
2090 SET_SCROLL_BAR_X_WINDOW
2091 (bar
, sb_widget
->core
.window
);
2093 SET_SCROLL_BAR_X_WINDOW
2095 XCreateWindow (x_current_display
, FRAME_X_WINDOW (frame
),
2097 /* Position and size of scroll bar. */
2098 left
, top
, width
, height
,
2100 /* Border width, depth, class, and visual. */
2101 0, CopyFromParent
, CopyFromParent
, CopyFromParent
,
2107 XSET (bar
->window
, Lisp_Window
, window
);
2108 XSET (bar
->top
, Lisp_Int
, top
);
2109 XSET (bar
->left
, Lisp_Int
, left
);
2110 XSET (bar
->width
, Lisp_Int
, width
);
2111 XSET (bar
->height
, Lisp_Int
, height
);
2112 XSET (bar
->start
, Lisp_Int
, 0);
2113 XSET (bar
->end
, Lisp_Int
, 0);
2114 bar
->dragging
= Qnil
;
2116 /* Add bar to its frame's list of scroll bars. */
2117 bar
->next
= FRAME_SCROLL_BARS (frame
);
2119 XSET (FRAME_SCROLL_BARS (frame
), Lisp_Vector
, bar
);
2120 if (! NILP (bar
->next
))
2121 XSET (XSCROLL_BAR (bar
->next
)->prev
, Lisp_Vector
, bar
);
2123 XMapWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
));
2130 /* Draw BAR's handle in the proper position.
2131 If the handle is already drawn from START to END, don't bother
2132 redrawing it, unless REBUILD is non-zero; in that case, always
2133 redraw it. (REBUILD is handy for drawing the handle after expose
2136 Normally, we want to constrain the start and end of the handle to
2137 fit inside its rectangle, but if the user is dragging the scroll bar
2138 handle, we want to let them drag it down all the way, so that the
2139 bar's top is as far down as it goes; otherwise, there's no way to
2140 move to the very end of the buffer. */
2142 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
2143 struct scroll_bar
*bar
;
2147 int dragging
= ! NILP (bar
->dragging
);
2148 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2149 GC gc
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))->display
.x
->normal_gc
;
2151 /* If the display is already accurate, do nothing. */
2153 && start
== XINT (bar
->start
)
2154 && end
== XINT (bar
->end
))
2160 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (XINT (bar
->width
));
2161 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2162 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2164 /* Make sure the values are reasonable, and try to preserve
2165 the distance between start and end. */
2167 int length
= end
- start
;
2171 else if (start
> top_range
)
2173 end
= start
+ length
;
2177 else if (end
> top_range
&& ! dragging
)
2181 /* Store the adjusted setting in the scroll bar. */
2182 XSET (bar
->start
, Lisp_Int
, start
);
2183 XSET (bar
->end
, Lisp_Int
, end
);
2185 /* Clip the end position, just for display. */
2186 if (end
> top_range
)
2189 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
2190 below top positions, to make sure the handle is always at least
2191 that many pixels tall. */
2192 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
2194 /* Draw the empty space above the handle. Note that we can't clear
2195 zero-height areas; that means "clear to end of window." */
2197 XClearArea (x_current_display
, w
,
2199 /* x, y, width, height, and exposures. */
2200 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2201 VERTICAL_SCROLL_BAR_TOP_BORDER
,
2202 inside_width
, start
,
2205 /* Draw the handle itself. */
2206 XFillRectangle (x_current_display
, w
, gc
,
2208 /* x, y, width, height */
2209 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2210 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
2211 inside_width
, end
- start
);
2214 /* Draw the empty space below the handle. Note that we can't
2215 clear zero-height areas; that means "clear to end of window." */
2216 if (end
< inside_height
)
2217 XClearArea (x_current_display
, w
,
2219 /* x, y, width, height, and exposures. */
2220 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
2221 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
2222 inside_width
, inside_height
- end
,
2230 /* Move a scroll bar around on the screen, to accommodate changing
2231 window configurations. */
2233 x_scroll_bar_move (bar
, top
, left
, width
, height
)
2234 struct scroll_bar
*bar
;
2235 int top
, left
, width
, height
;
2241 unsigned int mask
= 0;
2248 if (left
!= XINT (bar
->left
)) mask
|= CWX
;
2249 if (top
!= XINT (bar
->top
)) mask
|= CWY
;
2250 if (width
!= XINT (bar
->width
)) mask
|= CWWidth
;
2251 if (height
!= XINT (bar
->height
)) mask
|= CWHeight
;
2254 XConfigureWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
),
2258 XSET (bar
->left
, Lisp_Int
, left
);
2259 XSET (bar
->top
, Lisp_Int
, top
);
2260 XSET (bar
->width
, Lisp_Int
, width
);
2261 XSET (bar
->height
, Lisp_Int
, height
);
2266 /* Destroy the X window for BAR, and set its Emacs window's scroll bar
2269 x_scroll_bar_remove (bar
)
2270 struct scroll_bar
*bar
;
2272 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2276 /* Destroy the window. */
2277 XDestroyWindow (x_current_display
, SCROLL_BAR_X_WINDOW (bar
));
2279 /* Disassociate this scroll bar from its window. */
2280 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
2285 /* Set the handle of the vertical scroll bar for WINDOW to indicate
2286 that we are displaying PORTION characters out of a total of WHOLE
2287 characters, starting at POSITION. If WINDOW has no scroll bar,
2290 XTset_vertical_scroll_bar (window
, portion
, whole
, position
)
2291 struct window
*window
;
2292 int portion
, whole
, position
;
2294 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2295 int top
= XINT (window
->top
);
2296 int left
= WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window
);
2297 int height
= WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window
);
2299 /* Where should this scroll bar be, pixelwise? */
2300 int pixel_top
= CHAR_TO_PIXEL_ROW (f
, top
);
2301 int pixel_left
= CHAR_TO_PIXEL_COL (f
, left
);
2302 int pixel_width
= VERTICAL_SCROLL_BAR_PIXEL_WIDTH (f
);
2303 int pixel_height
= VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f
, height
);
2305 struct scroll_bar
*bar
;
2307 /* Does the scroll bar exist yet? */
2308 if (NILP (window
->vertical_scroll_bar
))
2309 bar
= x_scroll_bar_create (window
,
2310 pixel_top
, pixel_left
,
2311 pixel_width
, pixel_height
);
2314 /* It may just need to be moved and resized. */
2315 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2316 x_scroll_bar_move (bar
, pixel_top
, pixel_left
, pixel_width
, pixel_height
);
2319 /* Set the scroll bar's current state, unless we're currently being
2321 if (NILP (bar
->dragging
))
2324 VERTICAL_SCROLL_BAR_TOP_RANGE (pixel_height
);
2327 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
2330 int start
= ((double) position
* top_range
) / whole
;
2331 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
2333 x_scroll_bar_set_handle (bar
, start
, end
, 0);
2337 XSET (window
->vertical_scroll_bar
, Lisp_Vector
, bar
);
2341 /* The following three hooks are used when we're doing a thorough
2342 redisplay of the frame. We don't explicitly know which scroll bars
2343 are going to be deleted, because keeping track of when windows go
2344 away is a real pain - "Can you say set-window-configuration, boys
2345 and girls?" Instead, we just assert at the beginning of redisplay
2346 that *all* scroll bars are to be removed, and then save a scroll bar
2347 from the fiery pit when we actually redisplay its window. */
2349 /* Arrange for all scroll bars on FRAME to be removed at the next call
2350 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
2351 `*redeem_scroll_bar_hook' is applied to its window before the judgement. */
2353 XTcondemn_scroll_bars (frame
)
2356 /* The condemned list should be empty at this point; if it's not,
2357 then the rest of Emacs isn't using the condemn/redeem/judge
2358 protocol correctly. */
2359 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
2362 /* Move them all to the "condemned" list. */
2363 FRAME_CONDEMNED_SCROLL_BARS (frame
) = FRAME_SCROLL_BARS (frame
);
2364 FRAME_SCROLL_BARS (frame
) = Qnil
;
2367 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
2368 Note that WINDOW isn't necessarily condemned at all. */
2370 XTredeem_scroll_bar (window
)
2371 struct window
*window
;
2373 struct scroll_bar
*bar
;
2375 /* We can't redeem this window's scroll bar if it doesn't have one. */
2376 if (NILP (window
->vertical_scroll_bar
))
2379 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
2381 /* Unlink it from the condemned list. */
2383 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
2385 if (NILP (bar
->prev
))
2387 /* If the prev pointer is nil, it must be the first in one of
2389 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
2390 /* It's not condemned. Everything's fine. */
2392 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
2393 window
->vertical_scroll_bar
))
2394 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
2396 /* If its prev pointer is nil, it must be at the front of
2397 one or the other! */
2401 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
2403 if (! NILP (bar
->next
))
2404 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
2406 bar
->next
= FRAME_SCROLL_BARS (f
);
2408 XSET (FRAME_SCROLL_BARS (f
), Lisp_Vector
, bar
);
2409 if (! NILP (bar
->next
))
2410 XSET (XSCROLL_BAR (bar
->next
)->prev
, Lisp_Vector
, bar
);
2414 /* Remove all scroll bars on FRAME that haven't been saved since the
2415 last call to `*condemn_scroll_bars_hook'. */
2417 XTjudge_scroll_bars (f
)
2420 Lisp_Object bar
, next
;
2422 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
2424 /* Clear out the condemned list now so we won't try to process any
2425 more events on the hapless scroll bars. */
2426 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
2428 for (; ! NILP (bar
); bar
= next
)
2430 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
2432 x_scroll_bar_remove (b
);
2435 b
->next
= b
->prev
= Qnil
;
2438 /* Now there should be no references to the condemned scroll bars,
2439 and they should get garbage-collected. */
2443 /* Handle an Expose or GraphicsExpose event on a scroll bar.
2445 This may be called from a signal handler, so we have to ignore GC
2448 x_scroll_bar_expose (bar
, event
)
2449 struct scroll_bar
*bar
;
2452 Window w
= SCROLL_BAR_X_WINDOW (bar
);
2453 GC gc
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))->display
.x
->normal_gc
;
2457 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
2459 /* Draw a one-pixel border just inside the edges of the scroll bar. */
2460 XDrawRectangle (x_current_display
, w
, gc
,
2462 /* x, y, width, height */
2463 0, 0, XINT (bar
->width
) - 1, XINT (bar
->height
) - 1);
2468 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
2469 is set to something other than no_event, it is enqueued.
2471 This may be called from a signal handler, so we have to ignore GC
2474 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
2475 struct scroll_bar
*bar
;
2477 struct input_event
*emacs_event
;
2479 if (XGCTYPE (bar
->window
) != Lisp_Window
)
2482 emacs_event
->kind
= scroll_bar_click
;
2483 emacs_event
->code
= event
->xbutton
.button
- Button1
;
2484 emacs_event
->modifiers
=
2485 (x_x_to_emacs_modifiers (event
->xbutton
.state
)
2486 | (event
->type
== ButtonRelease
2489 emacs_event
->frame_or_window
= bar
->window
;
2490 emacs_event
->timestamp
= event
->xbutton
.time
;
2492 int internal_height
=
2493 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2495 VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2496 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
2499 if (y
> top_range
) y
= top_range
;
2501 if (y
< XINT (bar
->start
))
2502 emacs_event
->part
= scroll_bar_above_handle
;
2503 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
2504 emacs_event
->part
= scroll_bar_handle
;
2506 emacs_event
->part
= scroll_bar_below_handle
;
2508 /* Just because the user has clicked on the handle doesn't mean
2509 they want to drag it. Lisp code needs to be able to decide
2510 whether or not we're dragging. */
2512 /* If the user has just clicked on the handle, record where they're
2514 if (event
->type
== ButtonPress
2515 && emacs_event
->part
== scroll_bar_handle
)
2516 XSET (bar
->dragging
, Lisp_Int
, y
- XINT (bar
->start
));
2519 /* If the user has released the handle, set it to its final position. */
2520 if (event
->type
== ButtonRelease
2521 && ! NILP (bar
->dragging
))
2523 int new_start
= y
- XINT (bar
->dragging
);
2524 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2526 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2527 bar
->dragging
= Qnil
;
2530 /* Same deal here as the other #if 0. */
2532 /* Clicks on the handle are always reported as occurring at the top of
2534 if (emacs_event
->part
== scroll_bar_handle
)
2535 emacs_event
->x
= bar
->start
;
2537 XSET (emacs_event
->x
, Lisp_Int
, y
);
2539 XSET (emacs_event
->x
, Lisp_Int
, y
);
2542 XSET (emacs_event
->y
, Lisp_Int
, top_range
);
2546 /* Handle some mouse motion while someone is dragging the scroll bar.
2548 This may be called from a signal handler, so we have to ignore GC
2551 x_scroll_bar_note_movement (bar
, event
)
2552 struct scroll_bar
*bar
;
2555 last_mouse_movement_time
= event
->xmotion
.time
;
2558 XSET (last_mouse_scroll_bar
, Lisp_Vector
, bar
);
2560 /* If we're dragging the bar, display it. */
2561 if (! GC_NILP (bar
->dragging
))
2563 /* Where should the handle be now? */
2564 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
2566 if (new_start
!= XINT (bar
->start
))
2568 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
2570 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
2574 /* Call XQueryPointer so we'll get an event the next time the mouse
2575 moves and we can see *still* on the same position. */
2579 XQueryPointer (event
->xmotion
.display
, event
->xmotion
.window
,
2580 (Window
*) &dummy
, (Window
*) &dummy
,
2581 &dummy
, &dummy
, &dummy
, &dummy
,
2582 (unsigned int *) &dummy
);
2586 /* Return information to the user about the current position of the mouse
2587 on the scroll bar. */
2589 x_scroll_bar_report_motion (f
, bar_window
, part
, x
, y
, time
)
2591 Lisp_Object
*bar_window
;
2592 enum scroll_bar_part
*part
;
2594 unsigned long *time
;
2596 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
2598 Window dummy_window
;
2600 unsigned int dummy_mask
;
2604 /* Get the mouse's position relative to the scroll bar window, and
2606 if (! XQueryPointer (x_current_display
,
2607 SCROLL_BAR_X_WINDOW (bar
),
2609 /* Root, child, root x and root y. */
2610 &dummy_window
, &dummy_window
,
2611 &dummy_coord
, &dummy_coord
,
2613 /* Position relative to scroll bar. */
2616 /* Mouse buttons and modifier keys. */
2622 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar
->height
));
2624 = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar
->height
));
2626 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
2628 if (! NILP (bar
->dragging
))
2629 win_y
-= XINT (bar
->dragging
);
2633 if (win_y
> top_range
)
2636 *f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
2637 *bar_window
= bar
->window
;
2639 if (! NILP (bar
->dragging
))
2640 *part
= scroll_bar_handle
;
2641 else if (win_y
< XINT (bar
->start
))
2642 *part
= scroll_bar_above_handle
;
2643 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
2644 *part
= scroll_bar_handle
;
2646 *part
= scroll_bar_below_handle
;
2648 XSET (*x
, Lisp_Int
, win_y
);
2649 XSET (*y
, Lisp_Int
, top_range
);
2652 last_mouse_scroll_bar
= Qnil
;
2655 *time
= last_mouse_movement_time
;
2661 /* The screen has been cleared so we may have changed foreground or
2662 background colors, and the scroll bars may need to be redrawn.
2663 Clear out the scroll bars, and ask for expose events, so we can
2666 x_scroll_bar_clear (f
)
2671 for (bar
= FRAME_SCROLL_BARS (f
);
2672 XTYPE (bar
) == Lisp_Vector
;
2673 bar
= XSCROLL_BAR (bar
)->next
)
2674 XClearArea (x_current_display
, SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
2678 /* This processes Expose events from the menubar specific X event
2679 loop in menubar.c. This allows to redisplay the frame if necessary
2680 when handling menubar or popup items. */
2683 process_expose_from_menu (event
)
2690 f
= x_window_to_frame (event
.xexpose
.window
);
2693 if (f
->async_visible
== 0)
2695 f
->async_visible
= 1;
2696 f
->async_iconified
= 0;
2697 SET_FRAME_GARBAGED (f
);
2701 dumprectangle (x_window_to_frame (event
.xexpose
.window
),
2702 event
.xexpose
.x
, event
.xexpose
.y
,
2703 event
.xexpose
.width
, event
.xexpose
.height
);
2708 struct scroll_bar
*bar
2709 = x_window_to_scroll_bar (event
.xexpose
.window
);
2712 x_scroll_bar_expose (bar
, &event
);
2719 /* The main X event-reading loop - XTread_socket. */
2721 /* Timestamp of enter window event. This is only used by XTread_socket,
2722 but we have to put it out here, since static variables within functions
2723 sometimes don't work. */
2724 static Time enter_timestamp
;
2726 /* This holds the state XLookupString needs to implement dead keys
2727 and other tricks known as "compose processing". _X Window System_
2728 says that a portable program can't use this, but Stephen Gildea assures
2729 me that letting the compiler initialize it to zeros will work okay.
2731 This must be defined outside of XTread_socket, for the same reasons
2732 given for enter_timestamp, above. */
2733 static XComposeStatus compose_status
;
2735 /* Communication with window managers. */
2736 Atom Xatom_wm_protocols
;
2738 /* Kinds of protocol things we may receive. */
2739 Atom Xatom_wm_take_focus
;
2740 Atom Xatom_wm_save_yourself
;
2741 Atom Xatom_wm_delete_window
;
2743 /* Other WM communication */
2744 Atom Xatom_wm_configure_denied
; /* When our config request is denied */
2745 Atom Xatom_wm_window_moved
; /* When the WM moves us. */
2747 /* Window manager communication. */
2748 Atom Xatom_wm_change_state
;
2750 /* Record the last 100 characters stored
2751 to help debug the loss-of-chars-during-GC problem. */
2753 short temp_buffer
[100];
2755 /* Read events coming from the X server.
2756 This routine is called by the SIGIO handler.
2757 We return as soon as there are no more events to be read.
2759 Events representing keys are stored in buffer BUFP,
2760 which can hold up to NUMCHARS characters.
2761 We return the number of characters stored into the buffer,
2762 thus pretending to be `read'.
2764 WAITP is nonzero if we should block until input arrives.
2765 EXPECTED is nonzero if the caller knows input is available. */
2768 XTread_socket (sd
, bufp
, numchars
, waitp
, expected
)
2770 register struct input_event
*bufp
;
2771 register int numchars
;
2778 int items_pending
; /* How many items are in the X queue. */
2781 int event_found
= 0;
2785 if (interrupt_input_blocked
)
2787 interrupt_input_pending
= 1;
2791 interrupt_input_pending
= 0;
2795 abort (); /* Don't think this happens. */
2798 /* If available, Xlib uses FIOSNBIO to make the socket
2799 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
2800 FIOSNBIO is ignored, and instead of signalling EWOULDBLOCK,
2801 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
2802 fcntl (fileno (stdin
), F_SETFL
, 0);
2803 #endif /* ! defined (FIOSNBIO) */
2807 if (! (fcntl (fileno (stdin
), F_GETFL
, 0) & O_NDELAY
))
2809 extern int read_alarm_should_throw
;
2810 read_alarm_should_throw
= 1;
2811 XPeekEvent (XDISPLAY
&event
);
2812 read_alarm_should_throw
= 0;
2814 #endif /* HAVE_SELECT */
2817 while (XStuffPending () != 0)
2819 XNextEvent (XDISPLAY
&event
);
2827 if (event
.xclient
.message_type
== Xatom_wm_protocols
2828 && event
.xclient
.format
== 32)
2830 if (event
.xclient
.data
.l
[0] == Xatom_wm_take_focus
)
2832 #ifdef USE_X_TOOLKIT
2833 /* f = x_any_window_to_frame (event.xclient.window); */
2834 f
= x_window_to_frame (event
.xclient
.window
);
2836 f
= x_window_to_frame (event
.xclient
.window
);
2839 x_focus_on_frame (f
);
2840 /* Not certain about handling scroll bars here */
2842 else if (event
.xclient
.data
.l
[0] == Xatom_wm_save_yourself
)
2844 /* Save state modify the WM_COMMAND property to
2845 something which can reinstate us. This notifies
2846 the session manager, who's looking for such a
2847 PropertyNotify. Can restart processing when
2848 a keyboard or mouse event arrives. */
2853 else if (event
.xclient
.data
.l
[0] == Xatom_wm_delete_window
)
2855 struct frame
*f
= x_any_window_to_frame (event
.xclient
.window
);
2862 bufp
->kind
= delete_window_event
;
2863 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
2871 else if (event
.xclient
.message_type
== Xatom_wm_configure_denied
)
2874 else if (event
.xclient
.message_type
== Xatom_wm_window_moved
)
2877 struct frame
*f
= x_window_to_frame (event
.xclient
.window
);
2879 new_x
= event
.xclient
.data
.s
[0];
2880 new_y
= event
.xclient
.data
.s
[1];
2884 f
->display
.x
->left_pos
= new_x
;
2885 f
->display
.x
->top_pos
= new_y
;
2891 #ifdef NEW_SELECTIONS
2892 case SelectionNotify
:
2893 #ifdef USE_X_TOOLKIT
2894 if (x_window_to_frame (event
.xselection
.requestor
))
2895 x_handle_selection_notify (&event
);
2898 #else /* not USE_X_TOOLKIT */
2899 x_handle_selection_notify (&event
);
2900 #endif /* not USE_X_TOOLKIT */
2902 #endif /* NEW_SELECTIONS */
2904 case SelectionClear
: /* Someone has grabbed ownership. */
2905 #ifdef NEW_SELECTIONS
2907 #ifdef USE_X_TOOLKIT
2908 if (x_window_to_frame (event
.xselectionclear
.window
))
2910 #endif /* USE_X_TOOLKIT */
2911 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
2916 bufp
->kind
= selection_clear_event
;
2917 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
2918 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
2919 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
2924 #ifdef USE_X_TOOLKIT
2928 #endif /* USE_X_TOOLKIT */
2930 #else /* not NEW_SELECTIONS */
2931 x_disown_selection (event
.xselectionclear
.window
,
2932 event
.xselectionclear
.selection
,
2933 event
.xselectionclear
.time
);
2934 #endif /* not NEW_SELECTIONS */
2937 case SelectionRequest
: /* Someone wants our selection. */
2938 #ifdef NEW_SELECTIONS
2940 #ifdef USE_X_TOOLKIT
2941 if (x_window_to_frame (event
.xselectionrequest
.owner
))
2943 #endif /* USE_X_TOOLKIT */
2944 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
2949 bufp
->kind
= selection_request_event
;
2950 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
2951 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
2952 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
2953 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
2954 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
2955 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
2960 #ifdef USE_X_TOOLKIT
2964 #endif /* USE_X_TOOLKIT */
2966 #else /* not NEW_SELECTIONS */
2967 x_answer_selection_request (event
);
2968 #endif /* not NEW_SELECTIONS */
2971 case PropertyNotify
:
2972 #ifdef NEW_SELECTIONS
2973 #ifdef USE_X_TOOLKIT
2974 if (x_any_window_to_frame (event
.xproperty
.window
))
2975 x_handle_property_notify (&event
);
2978 #else /* not USE_X_TOOLKIT */
2979 x_handle_property_notify (&event
);
2980 #endif /* not USE_X_TOOLKIT */
2981 #else /* not NEW_SELECTIONS */
2982 /* If we're being told about a root window property, then it's
2983 a cut buffer change. */
2984 if (event
.xproperty
.window
== ROOT_WINDOW
)
2985 x_invalidate_cut_buffer_cache (&event
.xproperty
);
2987 /* Otherwise, we're probably handling an incremental
2988 selection transmission. */
2991 /* If we were to do this synchronously, there'd be no worry
2992 about re-selecting. */
2993 x_send_incremental (event
);
2995 #endif /* not NEW_SELECTIONS */
2998 case ReparentNotify
:
2999 f
= x_window_to_frame (event
.xreparent
.window
);
3001 f
->display
.x
->parent_desc
= event
.xreparent
.parent
;
3005 f
= x_window_to_frame (event
.xexpose
.window
);
3008 if (f
->async_visible
== 0)
3010 f
->async_visible
= 1;
3011 f
->async_iconified
= 0;
3012 SET_FRAME_GARBAGED (f
);
3016 dumprectangle (x_window_to_frame (event
.xexpose
.window
),
3017 event
.xexpose
.x
, event
.xexpose
.y
,
3018 event
.xexpose
.width
, event
.xexpose
.height
);
3023 struct scroll_bar
*bar
3024 = x_window_to_scroll_bar (event
.xexpose
.window
);
3027 x_scroll_bar_expose (bar
, &event
);
3028 #ifdef USE_X_TOOLKIT
3031 #endif /* USE_X_TOOLKIT */
3035 case GraphicsExpose
: /* This occurs when an XCopyArea's
3036 source area was obscured or not
3038 f
= x_window_to_frame (event
.xgraphicsexpose
.drawable
);
3042 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
3043 event
.xgraphicsexpose
.width
,
3044 event
.xgraphicsexpose
.height
);
3046 #ifdef USE_X_TOOLKIT
3049 #endif /* USE_X_TOOLKIT */
3052 case NoExpose
: /* This occurs when an XCopyArea's
3053 source area was completely
3056 #else /* ! defined (HAVE_X11) */
3058 if (event
.subwindow
!= 0)
3059 break; /* duplicate event */
3060 f
= x_window_to_frame (event
.window
);
3061 if (event
.window
== f
->display
.x
->icon_desc
)
3064 f
->async_iconified
= 1;
3066 if (event
.window
== FRAME_X_WINDOW (f
))
3068 /* Say must check all windows' needs_exposure flags. */
3069 expose_all_windows
= 1;
3070 f
->display
.x
->needs_exposure
= 1;
3071 f
->async_visible
= 1;
3076 if (event
.subwindow
!= 0)
3077 break; /* duplicate event */
3078 f
= x_window_to_frame (event
.window
);
3079 if (event
.window
== f
->display
.x
->icon_desc
)
3084 /* If window already needs full redraw, ignore this rectangle. */
3085 if (expose_all_windows
&& f
->display
.x
->needs_exposure
)
3087 /* Put the event on the queue of rectangles to redraw. */
3088 if (enqueue_event (&event
, &x_expose_queue
))
3089 /* If it is full, we can't record the rectangle,
3090 so redraw this entire window. */
3092 /* Say must check all windows' needs_exposure flags. */
3093 expose_all_windows
= 1;
3094 f
->display
.x
->needs_exposure
= 1;
3099 /* This should happen only when we are expecting it,
3100 in x_read_exposes. */
3102 #endif /* ! defined (HAVE_X11) */
3106 f
= x_window_to_frame (event
.xunmap
.window
);
3107 if (f
) /* F may no longer exist if
3108 the frame was deleted. */
3110 /* While a frame is unmapped, display generation is
3111 disabled; you don't want to spend time updating a
3112 display that won't ever be seen. */
3113 f
->async_visible
= 0;
3114 /* The window manager never makes a window invisible
3115 ("withdrawn"); all it does is switch between visible
3116 and iconified. Frames get into the invisible state
3117 only through x_make_frame_invisible. */
3118 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
3119 f
->async_iconified
= 1;
3121 #ifdef USE_X_TOOLKIT
3123 #endif /* USE_X_TOOLKIT */
3127 #ifdef USE_X_TOOLKIT
3128 f
= x_any_window_to_frame (event
.xmap
.window
);
3129 #else /* not USE_X_TOOLKIT */
3130 f
= x_window_to_frame (event
.xmap
.window
);
3131 #endif /* not USE_X_TOOLKIT */
3134 f
->async_visible
= 1;
3135 f
->async_iconified
= 0;
3137 /* wait_reading_process_input will notice this and update
3138 the frame's display structures. */
3139 SET_FRAME_GARBAGED (f
);
3141 #ifdef USE_X_TOOLKIT
3143 #endif /* USE_X_TOOLKIT */
3146 /* Turn off processing if we become fully obscured. */
3147 case VisibilityNotify
:
3150 #else /* ! defined (HAVE_X11) */
3152 f
= x_window_to_frame (event
.window
);
3153 if (event
.window
== f
->display
.x
->icon_desc
)
3154 f
->async_iconified
= 0;
3155 if (event
.window
== FRAME_X_WINDOW (f
))
3156 f
->async_visible
= 0;
3158 #endif /* ! defined (HAVE_X11) */
3162 f
= x_any_window_to_frame (event
.xkey
.window
);
3166 KeySym keysym
, orig_keysym
;
3167 /* al%imercury@uunet.uu.net says that making this 81 instead of
3168 80 fixed a bug whereby meta chars made his Emacs hang. */
3169 unsigned char copy_buffer
[81];
3173 |= x_emacs_to_x_modifiers (extra_keyboard_modifiers
);
3174 modifiers
= event
.xkey
.state
;
3176 /* This will have to go some day... */
3178 /* make_lispy_event turns chars into control chars.
3179 Don't do it here because XLookupString is too eager. */
3180 event
.xkey
.state
&= ~ControlMask
;
3182 XLookupString (&event
.xkey
, copy_buffer
, 80, &keysym
,
3185 /* Strip off the vendor-specific keysym bit, and take a shot
3186 at recognizing the codes. HP servers have extra keysyms
3187 that fit into the MiscFunctionKey category. */
3188 orig_keysym
= keysym
;
3193 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
3194 || keysym
== XK_Delete
3195 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
3196 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
3198 /* This recognizes the "extended function keys".
3199 It seems there's no cleaner way.
3200 Test IsModifierKey to avoid handling mode_switch
3202 || ((unsigned) (keysym
) >= XK_Select
3203 && (unsigned)(keysym
) < XK_KP_Space
)
3205 #ifdef XK_dead_circumflex
3206 || orig_keysym
== XK_dead_circumflex
3208 #ifdef XK_dead_grave
3209 || orig_keysym
== XK_dead_grave
3211 #ifdef XK_dead_tilde
3212 || orig_keysym
== XK_dead_tilde
3214 #ifdef XK_dead_diaeresis
3215 || orig_keysym
== XK_dead_diaeresis
3217 #ifdef XK_dead_macron
3218 || orig_keysym
== XK_dead_macron
3220 #ifdef XK_dead_degree
3221 || orig_keysym
== XK_dead_degree
3223 #ifdef XK_dead_acute
3224 || orig_keysym
== XK_dead_acute
3226 #ifdef XK_dead_cedilla
3227 || orig_keysym
== XK_dead_cedilla
3229 #ifdef XK_dead_breve
3230 || orig_keysym
== XK_dead_breve
3232 #ifdef XK_dead_ogonek
3233 || orig_keysym
== XK_dead_ogonek
3235 #ifdef XK_dead_caron
3236 || orig_keysym
== XK_dead_caron
3238 #ifdef XK_dead_doubleacute
3239 || orig_keysym
== XK_dead_doubleacute
3241 #ifdef XK_dead_abovedot
3242 || orig_keysym
== XK_dead_abovedot
3244 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
3245 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
3246 || x_is_vendor_fkey (orig_keysym
))
3247 && ! (IsModifierKey (orig_keysym
)
3249 #ifdef XK_Mode_switch
3250 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
3253 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
3255 #endif /* not HAVE_X11R5 */
3258 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3260 temp_buffer
[temp_index
++] = keysym
;
3261 bufp
->kind
= non_ascii_keystroke
;
3262 bufp
->code
= keysym
;
3263 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3264 bufp
->modifiers
= x_x_to_emacs_modifiers (modifiers
);
3265 bufp
->timestamp
= event
.xkey
.time
;
3270 else if (numchars
> nbytes
)
3274 for (i
= 0; i
< nbytes
; i
++)
3276 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
3278 temp_buffer
[temp_index
++] = copy_buffer
[i
];
3279 bufp
->kind
= ascii_keystroke
;
3280 bufp
->code
= copy_buffer
[i
];
3281 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3282 bufp
->modifiers
= x_x_to_emacs_modifiers (modifiers
);
3283 bufp
->timestamp
= event
.xkey
.time
;
3297 #else /* ! defined (HAVE_X11) */
3300 register char *where_mapping
;
3302 f
= x_window_to_frame (event
.window
);
3303 /* Ignore keys typed on icon windows. */
3304 if (f
!= 0 && event
.window
== f
->display
.x
->icon_desc
)
3306 where_mapping
= XLookupMapping (&event
, &nbytes
);
3307 /* Nasty fix for arrow keys */
3308 if (!nbytes
&& IsCursorKey (event
.detail
& 0xff))
3310 switch (event
.detail
& 0xff)
3312 case KC_CURSOR_LEFT
:
3313 where_mapping
= "\002";
3315 case KC_CURSOR_RIGHT
:
3316 where_mapping
= "\006";
3319 where_mapping
= "\020";
3321 case KC_CURSOR_DOWN
:
3322 where_mapping
= "\016";
3327 if (numchars
- nbytes
> 0)
3331 for (i
= 0; i
< nbytes
; i
++)
3333 bufp
->kind
= ascii_keystroke
;
3334 bufp
->code
= where_mapping
[i
];
3335 XSET (bufp
->time
, Lisp_Int
, event
.xkey
.time
);
3336 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3344 #endif /* ! defined (HAVE_X11) */
3348 /* Here's a possible interpretation of the whole
3349 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a
3350 FocusIn event, you have to get a FocusOut event before you
3351 relinquish the focus. If you haven't received a FocusIn event,
3352 then a mere LeaveNotify is enough to free you. */
3355 f
= x_any_window_to_frame (event
.xcrossing
.window
);
3357 if (event
.xcrossing
.focus
) /* Entered Window */
3359 /* Avoid nasty pop/raise loops. */
3360 if (f
&& (!(f
->auto_raise
)
3362 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
3364 x_new_focus_frame (f
);
3365 enter_timestamp
= event
.xcrossing
.time
;
3368 else if (f
== x_focus_frame
)
3369 x_new_focus_frame (0);
3370 #ifdef USE_X_TOOLKIT
3372 #endif /* USE_X_TOOLKIT */
3376 f
= x_any_window_to_frame (event
.xfocus
.window
);
3377 if (event
.xfocus
.detail
!= NotifyPointer
)
3378 x_focus_event_frame
= f
;
3380 x_new_focus_frame (f
);
3381 #ifdef USE_X_TOOLKIT
3383 #endif /* USE_X_TOOLKIT */
3388 f
= x_any_window_to_frame (event
.xcrossing
.window
);
3390 if (event
.xcrossing
.focus
)
3392 if (! x_focus_event_frame
)
3393 x_new_focus_frame (0);
3395 x_new_focus_frame (f
);
3399 if (f
== x_focus_event_frame
)
3400 x_focus_event_frame
= 0;
3401 if (f
== x_focus_frame
)
3402 x_new_focus_frame (0);
3404 #ifdef USE_X_TOOLKIT
3406 #endif /* USE_X_TOOLKIT */
3410 f
= x_any_window_to_frame (event
.xfocus
.window
);
3411 if (event
.xfocus
.detail
!= NotifyPointer
3412 && f
== x_focus_event_frame
)
3413 x_focus_event_frame
= 0;
3414 if (f
&& f
== x_focus_frame
)
3415 x_new_focus_frame (0);
3416 #ifdef USE_X_TOOLKIT
3418 #endif /* USE_X_TOOLKIT */
3421 #else /* ! defined (HAVE_X11) */
3424 if ((event
.detail
& 0xFF) == 1)
3425 break; /* Coming from our own subwindow */
3426 if (event
.subwindow
!= 0)
3427 break; /* Entering our own subwindow. */
3430 f
= x_window_to_frame (event
.window
);
3433 x_new_focus_frame (f
);
3438 if ((event
.detail
& 0xFF) == 1)
3439 break; /* Entering our own subwindow */
3440 if (event
.subwindow
!= 0)
3441 break; /* Leaving our own subwindow. */
3444 if (x_focus_frame
== 0
3445 && x_input_frame
!= 0
3446 && x_input_frame
== x_window_to_frame (event
.window
)
3447 && event
.window
== FRAME_X_WINDOW (x_input_frame
))
3452 frame_unhighlight (f
);
3455 #endif /* ! defined (HAVE_X11) */
3460 if (x_mouse_grabbed
)
3461 f
= last_mouse_frame
;
3463 f
= x_window_to_frame (event
.xmotion
.window
);
3465 note_mouse_movement (f
, &event
.xmotion
);
3468 struct scroll_bar
*bar
3469 = x_window_to_scroll_bar (event
.xmotion
.window
);
3472 x_scroll_bar_note_movement (bar
, &event
);
3475 #ifdef USE_X_TOOLKIT
3477 #endif /* USE_X_TOOLKIT */
3480 case ConfigureNotify
:
3481 f
= x_any_window_to_frame (event
.xconfigure
.window
);
3482 #ifdef USE_X_TOOLKIT
3484 && ! event
.xconfigure
.send_event
3485 && (event
.xconfigure
.window
== XtWindow (f
->display
.x
->widget
)))
3490 /* Find the position of the outside upper-left corner of
3491 the window, in the root coordinate system. Don't
3492 refer to the parent window here; we may be processing
3493 this event after the window manager has changed our
3494 parent, but before we have reached the ReparentNotify. */
3495 XTranslateCoordinates (x_current_display
,
3497 /* From-window, to-window. */
3498 XtWindow (f
->display
.x
->widget
),
3501 /* From-position, to-position. */
3502 -event
.xconfigure
.border_width
,
3503 -event
.xconfigure
.border_width
,
3508 event
.xconfigure
.x
= win_x
;
3509 event
.xconfigure
.y
= win_y
;
3511 f
->display
.x
->pixel_width
= event
.xconfigure
.width
;
3512 f
->display
.x
->pixel_height
= event
.xconfigure
.height
;
3513 f
->display
.x
->left_pos
= event
.xconfigure
.x
;
3514 f
->display
.x
->top_pos
= event
.xconfigure
.y
;
3517 #else /* not USE_X_TOOLKIT */
3520 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
3521 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
3523 /* Even if the number of character rows and columns has
3524 not changed, the font size may have changed, so we need
3525 to check the pixel dimensions as well. */
3526 if (columns
!= f
->width
3527 || rows
!= f
->height
3528 || event
.xconfigure
.width
!= f
->display
.x
->pixel_width
3529 || event
.xconfigure
.height
!= f
->display
.x
->pixel_height
)
3531 change_frame_size (f
, rows
, columns
, 0, 1);
3532 SET_FRAME_GARBAGED (f
);
3535 if (! event
.xconfigure
.send_event
)
3540 /* Find the position of the outside upper-left corner of
3541 the window, in the root coordinate system. Don't
3542 refer to the parent window here; we may be processing
3543 this event after the window manager has changed our
3544 parent, but before we have reached the ReparentNotify. */
3545 XTranslateCoordinates (x_current_display
,
3547 /* From-window, to-window. */
3548 f
->display
.x
->window_desc
,
3551 /* From-position, to-position. */
3552 -event
.xconfigure
.border_width
,
3553 -event
.xconfigure
.border_width
,
3558 event
.xconfigure
.x
= win_x
;
3559 event
.xconfigure
.y
= win_y
;
3562 f
->display
.x
->pixel_width
= event
.xconfigure
.width
;
3563 f
->display
.x
->pixel_height
= event
.xconfigure
.height
;
3564 f
->display
.x
->left_pos
= event
.xconfigure
.x
;
3565 f
->display
.x
->top_pos
= event
.xconfigure
.y
;
3567 #endif /* not USE_X_TOOLKIT */
3573 /* If we decide we want to generate an event to be seen
3574 by the rest of Emacs, we put it here. */
3575 struct input_event emacs_event
;
3576 emacs_event
.kind
= no_event
;
3578 f
= x_window_to_frame (event
.xbutton
.window
);
3581 if (!x_focus_frame
|| (f
== x_focus_frame
))
3582 construct_mouse_click (&emacs_event
, &event
, f
);
3586 struct scroll_bar
*bar
=
3587 x_window_to_scroll_bar (event
.xbutton
.window
);
3590 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
3591 #ifdef USE_X_TOOLKIT
3594 f
= x_any_window_to_frame (event
.xbutton
.window
);
3595 if (f
&& event
.type
== ButtonPress
)
3596 construct_menu_click (&emacs_event
,
3599 #endif /* USE_X_TOOLKIT */
3602 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
3604 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
3610 #ifdef USE_X_TOOLKIT
3612 #endif /* USE_X_TOOLKIT */
3616 #else /* ! defined (HAVE_X11) */
3618 case ButtonReleased
:
3619 f
= x_window_to_frame (event
.window
);
3622 if (event
.window
== f
->display
.x
->icon_desc
)
3624 x_make_frame_visible (f
);
3626 if (warp_mouse_on_deiconify
)
3627 XWarpMouse (FRAME_X_WINDOW (f
), 10, 10);
3630 if (event
.window
== FRAME_X_WINDOW (f
))
3636 enqueue_event (&event
, &x_mouse_queue
);
3639 bufp
->kind
= ascii_keystroke
;
3640 bufp
->code
= 'X' & 037; /* C-x */
3641 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3642 XSET (bufp
->time
, Lisp_Int
, event
.xkey
.time
);
3645 bufp
->kind
= ascii_keystroke
;
3646 bufp
->code
= 0; /* C-@ */
3647 XSET (bufp
->frame_or_window
, Lisp_Frame
, f
);
3648 XSET (bufp
->time
, Lisp_Int
, event
.xkey
.time
);
3655 #endif /* ! defined (HAVE_X11) */
3659 case CirculateNotify
:
3661 case CirculateRequest
:
3664 #endif /* ! defined (HAVE_X11) */
3667 /* Someone has changed the keyboard mapping - update the
3669 switch (event
.xmapping
.request
)
3671 case MappingModifier
:
3672 x_find_modifier_meanings ();
3673 /* This is meant to fall through. */
3674 case MappingKeyboard
:
3675 XRefreshKeyboardMapping (&event
.xmapping
);
3677 #ifdef USE_X_TOOLKIT
3679 #endif /* USE_X_TOOLKIT */
3683 #ifdef USE_X_TOOLKIT
3686 XtDispatchEvent (&event
);
3688 #endif /* USE_X_TOOLKIT */
3695 /* On some systems, an X bug causes Emacs to get no more events
3696 when the window is destroyed. Detect that. (1994.) */
3697 XNoOp (x_current_display
);
3698 #endif /* X_IO_BUG */
3700 #if 0 /* This fails for serial-line connections to the X server,
3701 because the characters arrive one by one, and a partial
3702 command makes select return but gives nothing to read.
3703 We'll have to hope that the bug that this tried to fix
3704 in 1988 has been fixed in Xlib or the X server. */
3706 if (expected
&& ! event_found
)
3708 /* AOJ 880406: if select returns true but XPending doesn't, it means that
3709 there is an EOF condition; in other words, that X has died.
3710 Act as if there had been a hangup. */
3711 int fd
= ConnectionNumber (x_current_display
);
3712 SELECT_TYPE mask
, junk1
, junk2
;
3717 EMACS_SET_SECS_USECS (timeout
, 0, 0);
3720 if (0 != select (fd
+ 1, &mask
, &junk1
, &junk2
, &timeout
)
3721 && !XStuffPending ())
3722 kill (getpid (), SIGHUP
);
3724 #endif /* HAVE_SELECT */
3728 if (updating_frame
== 0)
3729 x_do_pending_expose ();
3737 /* Read and process only Expose events
3738 until we get an ExposeCopy event; then return.
3739 This is used in insert/delete line.
3740 We assume input is already blocked. */
3746 XKeyPressedEvent event
;
3750 /* while there are more events*/
3751 XMaskEvent (ExposeWindow
| ExposeRegion
| ExposeCopy
, &event
);
3755 if (event
.subwindow
!= 0)
3756 break; /* duplicate event */
3757 f
= x_window_to_frame (event
.window
);
3758 if (event
.window
== f
->display
.x
->icon_desc
)
3763 if (event
.window
== FRAME_X_WINDOW (f
))
3765 expose_all_windows
= 1;
3766 f
->display
.x
->needs_exposure
= 1;
3772 if (event
.subwindow
!= 0)
3773 break; /* duplicate event */
3774 f
= x_window_to_frame (event
.window
);
3775 if (event
.window
== f
->display
.x
->icon_desc
)
3780 /* If window already needs full redraw, ignore this rectangle. */
3781 if (expose_all_windows
&& f
->display
.x
->needs_exposure
)
3783 /* Put the event on the queue of rectangles to redraw. */
3784 if (enqueue_event (&event
, &x_expose_queue
))
3785 /* If it is full, we can't record the rectangle,
3786 so redraw this entire window. */
3788 /* Say must check all windows' needs_exposure flags. */
3789 expose_all_windows
= 1;
3790 f
->display
.x
->needs_exposure
= 1;
3799 #endif /* HAVE_X11 */
3802 /* Drawing the cursor. */
3805 /* Draw a hollow box cursor. Don't change the inside of the box. */
3811 int left
= CHAR_TO_PIXEL_COL (f
, f
->cursor_x
);
3812 int top
= CHAR_TO_PIXEL_ROW (f
, f
->cursor_y
);
3813 int width
= FONT_WIDTH (f
->display
.x
->font
);
3814 int height
= FONT_HEIGHT (f
->display
.x
->font
);
3817 XDrawRectangle (x_current_display
, FRAME_X_WINDOW (f
),
3818 f
->display
.x
->cursor_gc
,
3819 left
, top
, width
- 1, height
- 1);
3820 #else /* ! defined (HAVE_X11) */
3821 XPixSet (FRAME_X_WINDOW (f
),
3822 left
, top
, width
, 1,
3823 f
->display
.x
->cursor_pixel
);
3825 XPixSet (FRAME_X_WINDOW (f
),
3826 left
, top
, 1, height
,
3827 f
->display
.x
->cursor_pixel
);
3829 XPixSet (FRAME_X_WINDOW (f
),
3830 left
+width
-1, top
, 1, height
,
3831 f
->display
.x
->cursor_pixel
);
3833 XPixSet (FRAME_X_WINDOW (f
),
3834 left
, top
+height
-1, width
, 1,
3835 f
->display
.x
->cursor_pixel
);
3836 #endif /* ! defined (HAVE_X11) */
3839 /* Clear the cursor of frame F to background color,
3840 and mark the cursor as not shown.
3841 This is used when the text where the cursor is
3842 is about to be rewritten. */
3850 if (! FRAME_VISIBLE_P (f
)
3851 || f
->phys_cursor_x
< 0)
3855 x_display_cursor (f
, 0);
3856 #else /* ! defined (HAVE_X11) */
3857 XPixSet (FRAME_X_WINDOW (f
),
3858 CHAR_TO_PIXEL_COL (f
, f
->phys_cursor_x
),
3859 CHAR_TO_PIXEL_ROW (f
, f
->phys_cursor_y
),
3860 FONT_WIDTH (f
->display
.x
->font
), FONT_HEIGHT (f
->display
.x
->font
),
3861 f
->display
.x
->background_pixel
);
3862 #endif /* ! defined (HAVE_X11) */
3863 f
->phys_cursor_x
= -1;
3866 /* Redraw the glyph at ROW, COLUMN on frame F, in the style
3867 HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the
3871 x_draw_single_glyph (f
, row
, column
, glyph
, highlight
)
3878 CHAR_TO_PIXEL_COL (f
, column
),
3879 CHAR_TO_PIXEL_ROW (f
, row
),
3880 &glyph
, 1, highlight
);
3884 x_display_bar_cursor (f
, on
)
3888 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
3890 /* This is pointless on invisible frames, and dangerous on garbaged
3891 frames; in the latter case, the frame may be in the midst of
3892 changing its size, and curs_x and curs_y may be off the frame. */
3893 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
3896 if (! on
&& f
->phys_cursor_x
< 0)
3899 /* If we're not updating, then we want to use the current frame's
3900 cursor position, not our local idea of where the cursor ought to be. */
3901 if (f
!= updating_frame
)
3903 curs_x
= FRAME_CURSOR_X (f
);
3904 curs_y
= FRAME_CURSOR_Y (f
);
3907 /* If there is anything wrong with the current cursor state, remove it. */
3908 if (f
->phys_cursor_x
>= 0
3910 || f
->phys_cursor_x
!= curs_x
3911 || f
->phys_cursor_y
!= curs_y
3912 || f
->display
.x
->current_cursor
!= bar_cursor
))
3914 /* Erase the cursor by redrawing the character underneath it. */
3915 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
3916 f
->phys_cursor_glyph
,
3917 current_glyphs
->highlight
[f
->phys_cursor_y
]);
3918 f
->phys_cursor_x
= -1;
3921 /* If we now need a cursor in the new place or in the new form, do it so. */
3923 && (f
->phys_cursor_x
< 0
3924 || (f
->display
.x
->current_cursor
!= bar_cursor
)))
3926 f
->phys_cursor_glyph
3927 = ((current_glyphs
->enable
[curs_y
]
3928 && curs_x
< current_glyphs
->used
[curs_y
])
3929 ? current_glyphs
->glyphs
[curs_y
][curs_x
]
3931 XFillRectangle (x_current_display
, FRAME_X_WINDOW (f
),
3932 f
->display
.x
->cursor_gc
,
3933 CHAR_TO_PIXEL_COL (f
, curs_x
),
3934 CHAR_TO_PIXEL_ROW (f
, curs_y
),
3935 1, FONT_HEIGHT (f
->display
.x
->font
));
3937 f
->phys_cursor_x
= curs_x
;
3938 f
->phys_cursor_y
= curs_y
;
3940 f
->display
.x
->current_cursor
= bar_cursor
;
3943 if (updating_frame
!= f
)
3948 /* Turn the displayed cursor of frame F on or off according to ON.
3949 If ON is nonzero, where to put the cursor is specified
3950 by F->cursor_x and F->cursor_y. */
3953 x_display_box_cursor (f
, on
)
3957 struct frame_glyphs
*current_glyphs
= FRAME_CURRENT_GLYPHS (f
);
3959 /* This is pointless on invisible frames, and dangerous on garbaged
3960 frames; in the latter case, the frame may be in the midst of
3961 changing its size, and curs_x and curs_y may be off the frame. */
3962 if (! FRAME_VISIBLE_P (f
) || FRAME_GARBAGED_P (f
))
3965 /* If cursor is off and we want it off, return quickly. */
3966 if (!on
&& f
->phys_cursor_x
< 0)
3969 /* If we're not updating, then we want to use the current frame's
3970 cursor position, not our local idea of where the cursor ought to be. */
3971 if (f
!= updating_frame
)
3973 curs_x
= FRAME_CURSOR_X (f
);
3974 curs_y
= FRAME_CURSOR_Y (f
);
3977 /* If cursor is currently being shown and we don't want it to be
3978 or it is in the wrong place,
3979 or we want a hollow box and it's not so, (pout!)
3981 if (f
->phys_cursor_x
>= 0
3983 || f
->phys_cursor_x
!= curs_x
3984 || f
->phys_cursor_y
!= curs_y
3985 || (f
->display
.x
->current_cursor
!= hollow_box_cursor
3986 && (f
!= x_highlight_frame
))))
3988 /* Erase the cursor by redrawing the character underneath it. */
3989 x_draw_single_glyph (f
, f
->phys_cursor_y
, f
->phys_cursor_x
,
3990 f
->phys_cursor_glyph
,
3991 current_glyphs
->highlight
[f
->phys_cursor_y
]);
3992 f
->phys_cursor_x
= -1;
3995 /* If we want to show a cursor,
3996 or we want a box cursor and it's not so,
3997 write it in the right place. */
3999 && (f
->phys_cursor_x
< 0
4000 || (f
->display
.x
->current_cursor
!= filled_box_cursor
4001 && f
== x_highlight_frame
)))
4003 f
->phys_cursor_glyph
4004 = ((current_glyphs
->enable
[curs_y
]
4005 && curs_x
< current_glyphs
->used
[curs_y
])
4006 ? current_glyphs
->glyphs
[curs_y
][curs_x
]
4008 if (f
!= x_highlight_frame
)
4011 f
->display
.x
->current_cursor
= hollow_box_cursor
;
4015 x_draw_single_glyph (f
, curs_y
, curs_x
,
4016 f
->phys_cursor_glyph
, 2);
4017 f
->display
.x
->current_cursor
= filled_box_cursor
;
4020 f
->phys_cursor_x
= curs_x
;
4021 f
->phys_cursor_y
= curs_y
;
4024 if (updating_frame
!= f
)
4028 x_display_cursor (f
, on
)
4034 if (FRAME_DESIRED_CURSOR (f
) == filled_box_cursor
)
4035 x_display_box_cursor (f
, on
);
4036 else if (FRAME_DESIRED_CURSOR (f
) == bar_cursor
)
4037 x_display_bar_cursor (f
, on
);
4039 /* Those are the only two we have implemented! */
4047 /* Refresh bitmap kitchen sink icon for frame F
4048 when we get an expose event for it. */
4054 /* Normally, the window manager handles this function. */
4055 #else /* ! defined (HAVE_X11) */
4058 if (f
->display
.x
->icon_bitmap_flag
)
4059 XBitmapBitsPut (f
->display
.x
->icon_desc
, 0, 0, sink_width
, sink_height
,
4060 sink_bits
, BlackPixel
, WHITE_PIX_DEFAULT
,
4061 icon_bitmap
, GXcopy
, AllPlanes
);
4064 extern struct frame
*selected_frame
;
4065 struct Lisp_String
*str
;
4066 unsigned char *string
;
4069 = XSTRING (XBUFFER (XWINDOW (f
->selected_window
)->buffer
)->name
)->data
;
4071 if (f
->display
.x
->icon_label
!= string
)
4073 f
->display
.x
->icon_label
= string
;
4074 XChangeWindow (f
->display
.x
->icon_desc
,
4075 XQueryWidth (string
, icon_font_info
->id
) + 10,
4076 icon_font_info
->height
+ 10);
4079 XText (f
->display
.x
->icon_desc
, 5, 5, string
,
4080 str
->size
, icon_font_info
->id
,
4081 BLACK_PIX_DEFAULT
, WHITE_PIX_DEFAULT
);
4084 #endif /* ! defined (HAVE_X11) */
4087 /* Make the x-window of frame F use the gnu icon bitmap. */
4096 if (FRAME_X_WINDOW (f
) == 0)
4102 XCreateBitmapFromData (x_current_display
, FRAME_X_WINDOW (f
),
4103 gnu_bits
, gnu_width
, gnu_height
);
4104 x_wm_set_icon_pixmap (f
, icon_bitmap
);
4105 f
->display
.x
->icon_bitmap_flag
= 1;
4106 #else /* ! defined (HAVE_X11) */
4107 if (f
->display
.x
->icon_desc
)
4109 XClearIconWindow (FRAME_X_WINDOW (f
));
4110 XDestroyWindow (f
->display
.x
->icon_desc
);
4113 icon_window
= XCreateWindow (f
->display
.x
->parent_desc
,
4114 0, 0, sink_width
, sink_height
,
4115 2, WhitePixmap
, (Pixmap
) NULL
);
4117 if (icon_window
== 0)
4120 XSetIconWindow (FRAME_X_WINDOW (f
), icon_window
);
4121 XSelectInput (icon_window
, ExposeWindow
| UnmapWindow
);
4123 f
->display
.x
->icon_desc
= icon_window
;
4124 f
->display
.x
->icon_bitmap_flag
= 1;
4126 if (icon_bitmap
== 0)
4128 = XStoreBitmap (sink_mask_width
, sink_mask_height
, sink_mask_bits
);
4129 #endif /* ! defined (HAVE_X11) */
4135 /* Make the x-window of frame F use a rectangle with text. */
4138 x_text_icon (f
, icon_name
)
4146 char *X_DefaultValue
;
4150 #define WhitePixel 1
4151 #endif /* WhitePixel */
4154 #define BlackPixel 0
4155 #endif /* BlackPixel */
4156 #endif /* HAVE_X11 */
4158 if (FRAME_X_WINDOW (f
) == 0)
4163 f
->display
.x
->icon_label
= icon_name
;
4165 if (! f
->display
.x
->icon_label
)
4166 f
->display
.x
->icon_label
= " *emacs* ";
4169 XSetIconName (x_current_display
, FRAME_X_WINDOW (f
),
4170 (char *) f
->display
.x
->icon_label
);
4173 f
->display
.x
->icon_bitmap_flag
= 0;
4174 x_wm_set_icon_pixmap (f
, 0);
4175 #else /* ! defined (HAVE_X11) */
4176 if (icon_font_info
== 0)
4178 = XGetFont (XGetDefault (XDISPLAY
4179 (char *) XSTRING (Vinvocation_name
)->data
,
4182 if (f
->display
.x
->icon_desc
)
4184 XClearIconWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4185 XDestroyWindow (XDISPLAY f
->display
.x
->icon_desc
);
4189 f
->display
.x
->icon_label
= (unsigned char *) icon_name
;
4191 if (! f
->display
.x
->icon_label
)
4192 f
->display
.x
->icon_label
= XSTRING (f
->name
)->data
;
4194 width
= XStringWidth (f
->display
.x
->icon_label
, icon_font_info
, 0, 0);
4195 icon_window
= XCreateWindow (f
->display
.x
->parent_desc
,
4196 f
->display
.x
->left_pos
,
4197 f
->display
.x
->top_pos
,
4198 width
+ 10, icon_font_info
->height
+ 10,
4199 2, BlackPixmap
, WhitePixmap
);
4201 if (icon_window
== 0)
4204 XSetIconWindow (FRAME_X_WINDOW (f
), icon_window
);
4205 XSelectInput (icon_window
, ExposeWindow
| ExposeRegion
| UnmapWindow
| ButtonPressed
);
4207 f
->display
.x
->icon_desc
= icon_window
;
4208 f
->display
.x
->icon_bitmap_flag
= 0;
4209 f
->display
.x
->icon_label
= 0;
4210 #endif /* ! defined (HAVE_X11) */
4215 /* Handling X errors. */
4217 /* Shut down Emacs in an orderly fashion, because of a SIGPIPE on the
4218 X server's connection, or an error reported via the X protocol. */
4221 x_connection_closed ()
4226 shut_down_emacs (0, 1, Qnil
);
4231 /* An X error handler which prints an error message and then kills
4232 Emacs. This is what's normally installed as Xlib's handler for
4235 x_error_quitter (display
, error
)
4241 /* Note that there is no real way portable across R3/R4 to get the
4242 original error handler. */
4244 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
4245 fprintf (stderr
, "X protocol error: %s on protocol request %d\n",
4246 buf
, error
->request_code
);
4249 /* While we're testing Emacs 19, we'll just dump core whenever we
4250 get an X error, so we can figure out why it happened. */
4254 x_connection_closed ();
4257 /* A handler for X IO errors which prints an error message and then
4258 kills Emacs. This is what is always installed as Xlib's handler
4261 x_io_error_quitter (display
)
4264 fprintf (stderr
, "Connection to X server %s lost.\n",
4265 XDisplayName (DisplayString (display
)));
4268 /* While we're testing Emacs 19, we'll just dump core whenever we
4269 get an X error, so we can figure out why it happened. */
4273 x_connection_closed ();
4276 /* A buffer for storing X error messages. */
4277 static char *x_caught_error_message
;
4278 #define X_CAUGHT_ERROR_MESSAGE_SIZE 200
4280 /* An X error handler which stores the error message in
4281 x_caught_error_message. This is what's installed when
4282 x_catch_errors is in effect. */
4284 x_error_catcher (display
, error
)
4288 XGetErrorText (display
, error
->error_code
,
4289 x_caught_error_message
, X_CAUGHT_ERROR_MESSAGE_SIZE
);
4293 /* Begin trapping X errors.
4295 After calling this function, X protocol errors no longer cause
4296 Emacs to exit; instead, they are recorded in x_cfc_error_message.
4298 Calling x_check_errors signals an Emacs error if an X error has
4299 occurred since the last call to x_catch_errors or x_check_errors.
4301 Calling x_uncatch_errors resumes the normal error handling. */
4303 void x_catch_errors (), x_check_errors (), x_uncatch_errors ();
4308 /* Make sure any errors from previous requests have been dealt with. */
4309 XSync (x_current_display
, False
);
4311 /* Set up the error buffer. */
4312 x_caught_error_message
4313 = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE
);
4314 x_caught_error_message
[0] = '\0';
4316 /* Install our little error handler. */
4317 XHandleError (x_error_catcher
);
4320 /* If any X protocol errors have arrived since the last call to
4321 x_catch_errors or x_check_errors, signal an Emacs error using
4322 sprintf (a buffer, FORMAT, the x error message text) as the text. */
4325 x_check_errors (format
)
4328 /* Make sure to catch any errors incurred so far. */
4329 XSync (x_current_display
, False
);
4331 if (x_caught_error_message
[0])
4333 char buf
[X_CAUGHT_ERROR_MESSAGE_SIZE
+ 56];
4335 sprintf (buf
, format
, x_caught_error_message
);
4336 x_uncatch_errors ();
4341 /* Nonzero if we had any X protocol errors since we did x_catch_errors. */
4346 /* Make sure to catch any errors incurred so far. */
4347 XSync (x_current_display
, False
);
4349 return x_caught_error_message
[0] != 0;
4352 /* Stop catching X protocol errors and let them make Emacs die. */
4357 xfree (x_caught_error_message
);
4358 x_caught_error_message
= 0;
4359 XHandleError (x_error_quitter
);
4363 static unsigned int x_wire_count
;
4366 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
4371 /* Changing the font of the frame. */
4373 /* Set the font of the x-window specified by frame F
4374 to the font named NEWNAME. This is safe to use
4375 even before F has an actual x-window. */
4385 /* A table of all the fonts we have already loaded. */
4386 static struct font_info
*x_font_table
;
4388 /* The current capacity of x_font_table. */
4389 static int x_font_table_size
;
4391 /* The number of fonts actually stored in x_font_table.
4392 x_font_table[n] is used and valid iff 0 <= n < n_fonts.
4393 0 <= n_fonts <= x_font_table_size. */
4397 x_new_font (f
, fontname
)
4399 register char *fontname
;
4402 int n_matching_fonts
;
4403 XFontStruct
*font_info
;
4406 /* Get a list of all the fonts that match this name. Once we
4407 have a list of matching fonts, we compare them against the fonts
4408 we already have by comparing font ids. */
4409 font_names
= (char **) XListFonts (x_current_display
, fontname
,
4410 1024, &n_matching_fonts
);
4411 /* Apparently it doesn't set n_matching_fonts to zero when it can't
4412 find any matches; font_names == 0 is the only clue. */
4414 n_matching_fonts
= 0;
4416 /* Don't just give up if n_matching_fonts is 0.
4417 Apparently there's a bug on Suns: XListFontsWithInfo can
4418 fail to find a font, but XLoadQueryFont may still find it. */
4420 /* See if we've already loaded a matching font. */
4421 already_loaded
= -1;
4422 if (n_matching_fonts
!= 0)
4426 for (i
= 0; i
< n_fonts
; i
++)
4427 for (j
= 0; j
< n_matching_fonts
; j
++)
4428 if (!strcmp (x_font_table
[i
].name
, font_names
[j
]))
4431 fontname
= font_names
[j
];
4437 /* If we have, just return it from the table. */
4438 if (already_loaded
>= 0)
4439 f
->display
.x
->font
= x_font_table
[already_loaded
].font
;
4441 /* Otherwise, load the font and add it to the table. */
4447 /* Try to find a character-cell font in the list. */
4449 /* A laudable goal, but this isn't how to do it. */
4450 for (i
= 0; i
< n_matching_fonts
; i
++)
4451 if (! font_info
[i
].per_char
)
4457 /* See comment above. */
4458 if (n_matching_fonts
!= 0)
4459 fontname
= font_names
[i
];
4461 font
= (XFontStruct
*) XLoadQueryFont (x_current_display
, fontname
);
4464 /* Free the information from XListFonts. */
4465 if (n_matching_fonts
)
4466 XFreeFontNames (font_names
);
4470 /* Do we need to create the table? */
4471 if (x_font_table_size
== 0)
4473 x_font_table_size
= 16;
4475 = (struct font_info
*) xmalloc (x_font_table_size
4476 * sizeof (x_font_table
[0]));
4478 /* Do we need to grow the table? */
4479 else if (n_fonts
>= x_font_table_size
)
4481 x_font_table_size
*= 2;
4483 = (struct font_info
*) xrealloc (x_font_table
,
4485 * sizeof (x_font_table
[0])));
4488 x_font_table
[n_fonts
].name
= (char *) xmalloc (strlen (fontname
) + 1);
4489 bcopy (fontname
, x_font_table
[n_fonts
].name
, strlen (fontname
) + 1);
4490 f
->display
.x
->font
= x_font_table
[n_fonts
++].font
= font
;
4493 /* Now make the frame display the given font. */
4494 if (FRAME_X_WINDOW (f
) != 0)
4496 XSetFont (x_current_display
, f
->display
.x
->normal_gc
,
4497 f
->display
.x
->font
->fid
);
4498 XSetFont (x_current_display
, f
->display
.x
->reverse_gc
,
4499 f
->display
.x
->font
->fid
);
4500 XSetFont (x_current_display
, f
->display
.x
->cursor_gc
,
4501 f
->display
.x
->font
->fid
);
4503 x_set_window_size (f
, 0, f
->width
, f
->height
);
4507 Lisp_Object lispy_name
;
4509 lispy_name
= build_string (fontname
);
4511 /* Free the information from XListFonts. The data
4512 we actually retain comes from XLoadQueryFont. */
4513 XFreeFontNames (font_names
);
4518 #else /* ! defined (HAVE_X11) */
4519 x_new_font (f
, newname
)
4521 register char *newname
;
4526 temp
= XGetFont (newname
);
4527 if (temp
== (FONT_TYPE
*) 0)
4530 if (f
->display
.x
->font
)
4531 XLoseFont (f
->display
.x
->font
);
4533 f
->display
.x
->font
= temp
;
4535 if (FRAME_X_WINDOW (f
) != 0)
4536 x_set_window_size (f
, 0, f
->width
, f
->height
);
4540 #endif /* ! defined (HAVE_X11) */
4542 x_calc_absolute_position (f
)
4547 int win_x
= 0, win_y
= 0;
4549 /* Find the position of the outside upper-left corner of
4550 the inner window, with respect to the outer window. */
4551 if (f
->display
.x
->parent_desc
!= ROOT_WINDOW
)
4554 XTranslateCoordinates (x_current_display
,
4556 /* From-window, to-window. */
4557 f
->display
.x
->window_desc
,
4558 f
->display
.x
->parent_desc
,
4560 /* From-position, to-position. */
4561 0, 0, &win_x
, &win_y
,
4568 /* Treat negative positions as relative to the leftmost bottommost
4569 position that fits on the screen. */
4570 if (f
->display
.x
->left_pos
< 0)
4571 f
->display
.x
->left_pos
= (x_screen_width
4572 - 2 * f
->display
.x
->border_width
- win_x
4574 + f
->display
.x
->left_pos
);
4576 if (f
->display
.x
->top_pos
< 0)
4577 f
->display
.x
->top_pos
= (x_screen_height
4578 - 2 * f
->display
.x
->border_width
- win_y
4580 + f
->display
.x
->top_pos
);
4582 #else /* ! defined (HAVE_X11) */
4583 WINDOWINFO_TYPE parentinfo
;
4585 XGetWindowInfo (FRAME_X_WINDOW (f
), &parentinfo
);
4587 if (f
->display
.x
->left_pos
< 0)
4588 f
->display
.x
->left_pos
= parentinfo
.width
+ (f
->display
.x
->left_pos
+ 1)
4589 - PIXEL_WIDTH (f
) - 2 * f
->display
.x
->internal_border_width
;
4591 if (f
->display
.x
->top_pos
< 0)
4592 f
->display
.x
->top_pos
= parentinfo
.height
+ (f
->display
.x
->top_pos
+ 1)
4593 - PIXEL_HEIGHT (f
) - 2 * f
->display
.x
->internal_border_width
;
4594 #endif /* ! defined (HAVE_X11) */
4597 x_set_offset (f
, xoff
, yoff
)
4599 register int xoff
, yoff
;
4601 f
->display
.x
->top_pos
= yoff
;
4602 f
->display
.x
->left_pos
= xoff
;
4603 x_calc_absolute_position (f
);
4606 #ifdef USE_X_TOOLKIT
4607 XMoveWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
),
4608 f
->display
.x
->left_pos
, f
->display
.x
->top_pos
);
4609 #else /* not USE_X_TOOLKIT */
4610 XMoveWindow (XDISPLAY
FRAME_X_WINDOW (f
),
4611 f
->display
.x
->left_pos
, f
->display
.x
->top_pos
);
4612 #endif /* not USE_X_TOOLKIT */
4614 x_wm_set_size_hint (f
, 0, 1, xoff
, yoff
);
4615 #endif /* ! defined (HAVE_X11) */
4619 /* Call this to change the size of frame F's x-window.
4620 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
4621 for this size change and subsequent size changes.
4622 Otherwise we leave the window gravity unchanged. */
4624 x_set_window_size (f
, change_gravity
, cols
, rows
)
4629 int pixelwidth
, pixelheight
;
4632 #ifdef USE_X_TOOLKIT
4634 EmacsFrameSetCharSize (f
->display
.x
->edit_widget
, cols
, rows
);
4637 #else /* not USE_X_TOOLKIT */
4641 check_frame_size (f
, &rows
, &cols
);
4642 f
->display
.x
->vertical_scroll_bar_extra
4643 = (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
4644 ? VERTICAL_SCROLL_BAR_PIXEL_WIDTH (f
)
4646 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
4647 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
4650 x_wm_set_size_hint (f
, 0, change_gravity
, 0, 0);
4651 #endif /* ! defined (HAVE_X11) */
4652 XChangeWindowSize (FRAME_X_WINDOW (f
), pixelwidth
, pixelheight
);
4654 /* Now, strictly speaking, we can't be sure that this is accurate,
4655 but the window manager will get around to dealing with the size
4656 change request eventually, and we'll hear how it went when the
4657 ConfigureNotify event gets here.
4659 We could just not bother storing any of this information here,
4660 and let the ConfigureNotify event set everything up, but that
4661 might be kind of confusing to the lisp code, since size changes
4662 wouldn't be reported in the frame parameters until some random
4663 point in the future when the ConfigureNotify event arrives. */
4664 change_frame_size (f
, rows
, cols
, 0, 0);
4665 PIXEL_WIDTH (f
) = pixelwidth
;
4666 PIXEL_HEIGHT (f
) = pixelheight
;
4668 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
4669 receive in the ConfigureNotify event; if we get what we asked
4670 for, then the event won't cause the screen to become garbaged, so
4671 we have to make sure to do it here. */
4672 SET_FRAME_GARBAGED (f
);
4676 #endif /* not USE_X_TOOLKIT */
4680 x_set_resize_hint (f
)
4683 XSetResizeHint (FRAME_X_WINDOW (f
),
4684 2 * f
->display
.x
->internal_border_width
,
4685 2 * f
->display
.x
->internal_border_width
,
4686 FONT_WIDTH (f
->display
.x
->font
),
4687 FONT_HEIGHT (f
->display
.x
->font
));
4689 #endif /* HAVE_X11 */
4691 /* Mouse warping, focus shifting, raising and lowering. */
4693 x_set_mouse_position (f
, x
, y
)
4699 #if 0 /* Let the user ask for this if he wants it. */
4703 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->display
.x
->font
) / 2;
4704 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + FONT_HEIGHT (f
->display
.x
->font
) / 2;
4706 if (pix_x
< 0) pix_x
= 0;
4707 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
4709 if (pix_y
< 0) pix_y
= 0;
4710 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
4714 XWarpMousePointer (FRAME_X_WINDOW (f
), pix_x
, pix_y
);
4719 x_focus_on_frame (f
)
4722 #if 0 /* This proves to be unpleasant. */
4726 /* I don't think that the ICCCM allows programs to do things like this
4727 without the interaction of the window manager. Whatever you end up
4728 doing with this code, do it to x_unfocus_frame too. */
4729 XSetInputFocus (x_current_display
, FRAME_X_WINDOW (f
),
4730 RevertToPointerRoot
, CurrentTime
);
4738 /* Look at the remarks in x_focus_on_frame. */
4739 if (x_focus_frame
== f
)
4740 XSetInputFocus (x_current_display
, PointerRoot
,
4741 RevertToPointerRoot
, CurrentTime
);
4745 #endif /* ! defined (HAVE_X11) */
4747 /* Raise frame F. */
4752 if (f
->async_visible
)
4755 #ifdef USE_X_TOOLKIT
4756 XRaiseWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
));
4757 #else /* not USE_X_TOOLKIT */
4758 XRaiseWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4759 #endif /* not USE_X_TOOLKIT */
4765 /* Lower frame F. */
4770 if (f
->async_visible
)
4773 #ifdef USE_X_TOOLKIT
4774 XLowerWindow (XDISPLAY
XtWindow (f
->display
.x
->widget
));
4775 #else /* not USE_X_TOOLKIT */
4776 XLowerWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4777 #endif /* not USE_X_TOOLKIT */
4784 XTframe_raise_lower (f
, raise
)
4795 /* Change from withdrawn state to mapped state. */
4797 x_make_frame_visible (f
)
4804 if (! FRAME_VISIBLE_P (f
))
4807 if (! EQ (Vx_no_window_manager
, Qt
))
4808 x_wm_set_window_state (f
, NormalState
);
4809 #ifdef USE_X_TOOLKIT
4810 XtPopup (f
->display
.x
->widget
, XtGrabNone
);
4811 #else /* not USE_X_TOOLKIT */
4812 XMapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4813 #endif /* not USE_X_TOOLKIT */
4814 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4815 XMapSubwindows (x_current_display
, FRAME_X_WINDOW (f
));
4816 #else /* ! defined (HAVE_X11) */
4817 XMapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4818 if (f
->display
.x
->icon_desc
!= 0)
4819 XUnmapWindow (f
->display
.x
->icon_desc
);
4821 /* Handled by the MapNotify event for X11 */
4822 f
->async_visible
= 1;
4823 f
->async_iconified
= 0;
4825 /* NOTE: this may cause problems for the first frame. */
4827 #endif /* ! defined (HAVE_X11) */
4835 /* Change from mapped state to withdrawn state. */
4837 x_make_frame_invisible (f
)
4842 /* Don't keep the highlight on an invisible frame. */
4843 if (x_highlight_frame
== f
)
4844 x_highlight_frame
= 0;
4846 if (! f
->async_visible
&& ! f
->async_iconified
)
4853 #ifdef USE_X_TOOLKIT
4854 if (! XWithdrawWindow (x_current_display
, XtWindow (f
->display
.x
->widget
),
4855 DefaultScreen (x_current_display
)))
4856 #else /* not USE_X_TOOLKIT */
4857 if (! XWithdrawWindow (x_current_display
, FRAME_X_WINDOW (f
),
4858 DefaultScreen (x_current_display
)))
4859 #endif /* not USE_X_TOOLKIT */
4861 UNBLOCK_INPUT_RESIGNAL
;
4862 error ("can't notify window manager of window withdrawal");
4865 #else /* ! defined (HAVE_X11R4) */
4868 /* Tell the window manager what we're going to do. */
4869 if (! EQ (Vx_no_window_manager
, Qt
))
4873 unmap
.xunmap
.type
= UnmapNotify
;
4874 #ifdef USE_X_TOOLKIT
4875 unmap
.xunmap
.window
= XtWindow (f
->display
.x
->widget
);
4876 #else /* not USE_X_TOOLKIT */
4877 unmap
.xunmap
.window
= FRAME_X_WINDOW (f
);
4878 #endif /* not USE_X_TOOLKIT */
4879 unmap
.xunmap
.event
= DefaultRootWindow (x_current_display
);
4880 unmap
.xunmap
.from_configure
= False
;
4881 if (! XSendEvent (x_current_display
,
4882 DefaultRootWindow (x_current_display
),
4884 SubstructureRedirectMask
|SubstructureNotifyMask
,
4887 UNBLOCK_INPUT_RESIGNAL
;
4888 error ("can't notify window manager of withdrawal");
4892 /* Unmap the window ourselves. Cheeky! */
4893 #ifdef USE_X_TOOLKIT
4894 XUnmapWindow (x_current_display
, XtWindow (f
->display
.x
->widget
));
4895 #else /* not USE_X_TOOLKIT */
4896 XUnmapWindow (x_current_display
, FRAME_X_WINDOW (f
));
4897 #endif /* not USE_X_TOOLKIT */
4898 #else /* ! defined (HAVE_X11) */
4900 XUnmapWindow (FRAME_X_WINDOW (f
));
4901 f
->async_visible
= 0; /* Handled by the UnMap event for X11 */
4902 if (f
->display
.x
->icon_desc
!= 0)
4903 XUnmapWindow (f
->display
.x
->icon_desc
);
4905 #endif /* ! defined (HAVE_X11) */
4906 #endif /* ! defined (HAVE_X11R4) */
4912 /* Change window state from mapped to iconified. */
4920 /* Don't keep the highlight on an invisible frame. */
4921 if (x_highlight_frame
== f
)
4922 x_highlight_frame
= 0;
4924 if (f
->async_iconified
)
4927 #ifdef USE_X_TOOLKIT
4929 result
= XIconifyWindow (x_current_display
,
4930 XtWindow (f
->display
.x
->widget
),
4931 DefaultScreen (x_current_display
));
4935 error ("Can't notify window manager of iconification.");
4937 f
->async_iconified
= 1;
4942 #else /* not USE_X_TOOLKIT */
4947 /* Since we don't know which revision of X we're running, we'll use both
4948 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
4950 /* X11R4: send a ClientMessage to the window manager using the
4951 WM_CHANGE_STATE type. */
4955 message
.xclient
.window
= FRAME_X_WINDOW (f
);
4956 message
.xclient
.type
= ClientMessage
;
4957 message
.xclient
.message_type
= Xatom_wm_change_state
;
4958 message
.xclient
.format
= 32;
4959 message
.xclient
.data
.l
[0] = IconicState
;
4961 if (! XSendEvent (x_current_display
,
4962 DefaultRootWindow (x_current_display
),
4964 SubstructureRedirectMask
| SubstructureNotifyMask
,
4967 UNBLOCK_INPUT_RESIGNAL
;
4968 error ("Can't notify window manager of iconification.");
4972 /* X11R3: set the initial_state field of the window manager hints to
4974 x_wm_set_window_state (f
, IconicState
);
4976 if (!FRAME_VISIBLE_P (f
))
4978 /* If the frame was withdrawn, before, we must map it. */
4979 XMapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4980 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4981 XMapSubwindows (x_current_display
, FRAME_X_WINDOW (f
));
4984 f
->async_iconified
= 1;
4985 #else /* ! defined (HAVE_X11) */
4986 XUnmapWindow (XDISPLAY
FRAME_X_WINDOW (f
));
4988 f
->async_visible
= 0; /* Handled in the UnMap event for X11. */
4989 if (f
->display
.x
->icon_desc
!= 0)
4991 XMapWindow (XDISPLAY f
->display
.x
->icon_desc
);
4994 #endif /* ! defined (HAVE_X11) */
4998 #endif /* not USE_X_TOOLKIT */
5001 /* Destroy the X window of frame F. */
5003 x_destroy_window (f
)
5008 if (f
->display
.x
->icon_desc
!= 0)
5009 XDestroyWindow (XDISPLAY f
->display
.x
->icon_desc
);
5010 XDestroyWindow (XDISPLAY f
->display
.x
->window_desc
);
5011 #ifdef USE_X_TOOLKIT
5012 XtDestroyWidget (f
->display
.x
->widget
);
5013 free_frame_menubar (f
);
5014 #endif /* USE_X_TOOLKIT */
5016 free_frame_faces (f
);
5019 xfree (f
->display
.x
);
5021 if (f
== x_focus_frame
)
5023 if (f
== x_highlight_frame
)
5024 x_highlight_frame
= 0;
5029 /* Manage event queues for X10. */
5033 /* Manage event queues.
5035 This code is only used by the X10 support.
5037 We cannot leave events in the X queue and get them when we are ready
5038 because X does not provide a subroutine to get only a certain kind
5039 of event but not block if there are no queued events of that kind.
5041 Therefore, we must examine events as they come in and copy events
5042 of certain kinds into our private queues.
5044 All ExposeRegion events are put in x_expose_queue.
5045 All ButtonPress and ButtonRelease events are put in x_mouse_queue. */
5048 /* Write the event *P_XREP into the event queue *QUEUE.
5049 If the queue is full, do nothing, but return nonzero. */
5052 enqueue_event (p_xrep
, queue
)
5053 register XEvent
*p_xrep
;
5054 register struct event_queue
*queue
;
5056 int newindex
= queue
->windex
+ 1;
5057 if (newindex
== EVENT_BUFFER_SIZE
)
5059 if (newindex
== queue
->rindex
)
5061 queue
->xrep
[queue
->windex
] = *p_xrep
;
5062 queue
->windex
= newindex
;
5066 /* Fetch the next event from queue *QUEUE and store it in *P_XREP.
5067 If *QUEUE is empty, do nothing and return 0. */
5070 dequeue_event (p_xrep
, queue
)
5071 register XEvent
*p_xrep
;
5072 register struct event_queue
*queue
;
5074 if (queue
->windex
== queue
->rindex
)
5076 *p_xrep
= queue
->xrep
[queue
->rindex
++];
5077 if (queue
->rindex
== EVENT_BUFFER_SIZE
)
5082 /* Return the number of events buffered in *QUEUE. */
5085 queue_event_count (queue
)
5086 register struct event_queue
*queue
;
5088 int tem
= queue
->windex
- queue
->rindex
;
5091 return EVENT_BUFFER_SIZE
+ tem
;
5094 /* Return nonzero if mouse input is pending. */
5097 mouse_event_pending_p ()
5099 return queue_event_count (&x_mouse_queue
);
5101 #endif /* HAVE_X11 */
5103 /* Setting window manager hints. */
5107 /* Record the gravity used previously, in case CHANGE_GRAVITY is 0. */
5108 static int previous_gravity
;
5110 /* SPEC_X and SPEC_Y are the specified positions.
5111 We look only at their sign, to decide the gravity.
5112 If CHANGE_GRAVITY is 0, we ignore SPEC_X and SPEC_Y
5113 and leave the gravity unchanged. */
5115 x_wm_set_size_hint (f
, prompting
, change_gravity
, spec_x
, spec_y
)
5121 XSizeHints size_hints
;
5123 #ifdef USE_X_TOOLKIT
5124 Window window
= XtWindow (f
->display
.x
->widget
);
5125 #else /* not USE_X_TOOLKIT */
5126 Window window
= FRAME_X_WINDOW (f
);
5127 #endif /* not USE_X_TOOLKIT */
5129 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
5131 flexlines
= f
->height
;
5133 size_hints
.x
= f
->display
.x
->left_pos
;
5134 size_hints
.y
= f
->display
.x
->top_pos
;
5135 size_hints
.height
= PIXEL_HEIGHT (f
);
5136 size_hints
.width
= PIXEL_WIDTH (f
);
5137 size_hints
.width_inc
= FONT_WIDTH (f
->display
.x
->font
);
5138 size_hints
.height_inc
= FONT_HEIGHT (f
->display
.x
->font
);
5140 size_hints
.max_width
= x_screen_width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
5141 size_hints
.max_height
= x_screen_height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
5144 int base_width
, base_height
;
5146 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
5147 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
5150 int min_rows
= 0, min_cols
= 0;
5151 check_frame_size (f
, &min_rows
, &min_cols
);
5153 /* The window manager uses the base width hints to calculate the
5154 current number of rows and columns in the frame while
5155 resizing; min_width and min_height aren't useful for this
5156 purpose, since they might not give the dimensions for a
5157 zero-row, zero-column frame.
5159 We use the base_width and base_height members if we have
5160 them; otherwise, we set the min_width and min_height members
5161 to the size for a zero x zero frame. */
5164 size_hints
.flags
|= PBaseSize
;
5165 size_hints
.base_width
= base_width
;
5166 size_hints
.base_height
= base_height
;
5167 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
5168 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
5170 size_hints
.min_width
= base_width
;
5171 size_hints
.min_height
= base_height
;
5178 size_hints
.flags
|= prompting
;
5181 XSizeHints hints
; /* Sometimes I hate X Windows... */
5183 if (XGetNormalHints (x_current_display
, window
, &hints
) == 0)
5185 if (hints
.flags
& PSize
)
5186 size_hints
.flags
|= PSize
;
5187 if (hints
.flags
& PPosition
)
5188 size_hints
.flags
|= PPosition
;
5189 if (hints
.flags
& USPosition
)
5190 size_hints
.flags
|= USPosition
;
5191 if (hints
.flags
& USSize
)
5192 size_hints
.flags
|= USSize
;
5194 #if defined (PWinGravity)
5197 switch (((spec_x
< 0) << 1) + (spec_y
< 0))
5200 size_hints
.win_gravity
= NorthWestGravity
;
5203 size_hints
.win_gravity
= NorthEastGravity
;
5206 size_hints
.win_gravity
= SouthWestGravity
;
5209 size_hints
.win_gravity
= SouthEastGravity
;
5212 previous_gravity
= size_hints
.win_gravity
;
5215 size_hints
.win_gravity
= previous_gravity
;
5217 size_hints
.flags
|= PWinGravity
;
5218 #endif /* PWinGravity */
5221 XSetWMNormalHints (x_current_display
, window
, &size_hints
);
5223 XSetNormalHints (x_current_display
, window
, &size_hints
);
5227 /* Used for IconicState or NormalState */
5228 x_wm_set_window_state (f
, state
)
5232 #ifdef USE_X_TOOLKIT
5233 Window window
= XtWindow (f
->display
.x
->widget
);
5234 #else /* not USE_X_TOOLKIT */
5235 Window window
= FRAME_X_WINDOW (f
);
5236 #endif /* not USE_X_TOOLKIT */
5238 f
->display
.x
->wm_hints
.flags
|= StateHint
;
5239 f
->display
.x
->wm_hints
.initial_state
= state
;
5241 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5244 x_wm_set_icon_pixmap (f
, icon_pixmap
)
5248 Window window
= FRAME_X_WINDOW (f
);
5252 f
->display
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
5253 f
->display
.x
->wm_hints
.flags
|= IconPixmapHint
;
5256 f
->display
.x
->wm_hints
.flags
&= ~IconPixmapHint
;
5258 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5261 x_wm_set_icon_position (f
, icon_x
, icon_y
)
5265 Window window
= FRAME_X_WINDOW (f
);
5267 f
->display
.x
->wm_hints
.flags
|= IconPositionHint
;
5268 f
->display
.x
->wm_hints
.icon_x
= icon_x
;
5269 f
->display
.x
->wm_hints
.icon_y
= icon_y
;
5271 XSetWMHints (x_current_display
, window
, &f
->display
.x
->wm_hints
);
5275 /* Initialization. */
5277 #ifdef USE_X_TOOLKIT
5278 static XrmOptionDescRec emacs_options
[] = {
5279 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
5280 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
5282 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
5283 XrmoptionSepArg
, NULL
},
5284 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
5286 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5287 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5288 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
5289 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5290 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
5291 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
5292 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
5294 #endif /* USE_X_TOOLKIT */
5297 x_term_init (display_name
)
5304 #ifndef F_SETOWN_BUG
5306 extern int old_fcntl_owner
;
5307 #endif /* ! defined (F_SETOWN) */
5308 #endif /* F_SETOWN_BUG */
5310 x_focus_frame
= x_highlight_frame
= 0;
5312 #ifdef USE_X_TOOLKIT
5313 argv
= (char **) XtMalloc (3 * sizeof (char *));
5315 argv
[1] = "-display";
5316 argv
[2] = display_name
;
5318 Xt_app_shell
= XtAppInitialize (&Xt_app_con
, "Emacs",
5319 emacs_options
, XtNumber (emacs_options
),
5323 x_current_display
= XtDisplay (Xt_app_shell
);
5325 #else /* not USE_X_TOOLKIT */
5326 x_current_display
= XOpenDisplay (display_name
);
5327 #endif /* not USE_X_TOOLKIT */
5328 if (x_current_display
== 0)
5329 fatal ("X server %s not responding.\n\
5330 Check the DISPLAY environment variable or use \"-d\"\n",
5336 XSetAfterFunction (x_current_display
, x_trace_wire
);
5338 hostname
= get_system_name ();
5339 x_id_name
= (char *) xmalloc (XSTRING (Vinvocation_name
)->size
5342 sprintf (x_id_name
, "%s@%s", XSTRING (Vinvocation_name
)->data
, hostname
);
5345 /* Figure out which modifier bits mean what. */
5346 x_find_modifier_meanings ();
5348 /* Get the scroll bar cursor. */
5349 x_vertical_scroll_bar_cursor
5350 = XCreateFontCursor (x_current_display
, XC_sb_v_double_arrow
);
5353 /* Watch for PropertyNotify events on the root window; we use them
5354 to figure out when to invalidate our cache of the cut buffers. */
5355 x_watch_cut_buffer_cache ();
5358 if (ConnectionNumber (x_current_display
) != 0)
5359 change_keyboard_wait_descriptor (ConnectionNumber (x_current_display
));
5360 change_input_fd (ConnectionNumber (x_current_display
));
5362 #endif /* ! defined (HAVE_X11) */
5364 #ifndef F_SETOWN_BUG
5366 old_fcntl_owner
= fcntl (ConnectionNumber (x_current_display
), F_GETOWN
, 0);
5367 #ifdef F_SETOWN_SOCK_NEG
5368 /* stdin is a socket here */
5369 fcntl (ConnectionNumber (x_current_display
), F_SETOWN
, -getpid ());
5370 #else /* ! defined (F_SETOWN_SOCK_NEG) */
5371 fcntl (ConnectionNumber (x_current_display
), F_SETOWN
, getpid ());
5372 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
5373 #endif /* ! defined (F_SETOWN) */
5374 #endif /* F_SETOWN_BUG */
5378 #endif /* ! defined (SIGIO) */
5380 expose_all_windows
= 0;
5382 clear_frame_hook
= XTclear_frame
;
5383 clear_end_of_line_hook
= XTclear_end_of_line
;
5384 ins_del_lines_hook
= XTins_del_lines
;
5385 change_line_highlight_hook
= XTchange_line_highlight
;
5386 insert_glyphs_hook
= XTinsert_glyphs
;
5387 write_glyphs_hook
= XTwrite_glyphs
;
5388 delete_glyphs_hook
= XTdelete_glyphs
;
5389 ring_bell_hook
= XTring_bell
;
5390 reset_terminal_modes_hook
= XTreset_terminal_modes
;
5391 set_terminal_modes_hook
= XTset_terminal_modes
;
5392 update_begin_hook
= XTupdate_begin
;
5393 update_end_hook
= XTupdate_end
;
5394 set_terminal_window_hook
= XTset_terminal_window
;
5395 read_socket_hook
= XTread_socket
;
5396 cursor_to_hook
= XTcursor_to
;
5397 reassert_line_highlight_hook
= XTreassert_line_highlight
;
5398 mouse_position_hook
= XTmouse_position
;
5399 frame_rehighlight_hook
= XTframe_rehighlight
;
5400 frame_raise_lower_hook
= XTframe_raise_lower
;
5401 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
5402 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
5403 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
5404 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
5406 scroll_region_ok
= 1; /* we'll scroll partial frames */
5407 char_ins_del_ok
= 0; /* just as fast to write the line */
5408 line_ins_del_ok
= 1; /* we'll just blt 'em */
5409 fast_clear_end_of_line
= 1; /* X does this well */
5410 memory_below_frame
= 0; /* we don't remember what scrolls
5414 /* Try to use interrupt input; if we can't, then start polling. */
5415 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
5417 /* Note that there is no real way portable across R3/R4 to get the
5418 original error handler. */
5419 XHandleError (x_error_quitter
);
5420 XHandleIOError (x_io_error_quitter
);
5422 /* Disable Window Change signals; they are handled by X events. */
5424 signal (SIGWINCH
, SIG_DFL
);
5425 #endif /* ! defined (SIGWINCH) */
5427 signal (SIGPIPE
, x_connection_closed
);
5433 staticpro (&last_mouse_scroll_bar
);
5434 last_mouse_scroll_bar
= Qnil
;
5436 #endif /* ! defined (HAVE_X11) */
5437 #endif /* ! defined (HAVE_X_WINDOWS) */