Commit | Line | Data |
---|---|---|
dc6f92b8 | 1 | /* X Communication module for terminals which understand the X protocol. |
b8009dd1 | 2 | Copyright (C) 1989, 1993, 1994 Free Software Foundation, Inc. |
dc6f92b8 JB |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
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 | |
4746118a | 8 | the Free Software Foundation; either version 2, or (at your option) |
dc6f92b8 JB |
9 | any later version. |
10 | ||
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. | |
15 | ||
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. */ | |
19 | ||
3afe33e7 RS |
20 | /* Xt features made by Fred Pierresteguy. */ |
21 | ||
d56a553a RS |
22 | #define NEW_SELECTIONS |
23 | ||
039440c4 RS |
24 | /* On 4.3 these lose if they come after xterm.h. */ |
25 | /* On HP-UX 8.0 signal.h loses if it comes after config.h. */ | |
26 | /* Putting these at the beginning seems to be standard for other .c files. */ | |
27 | #include <stdio.h> | |
28 | #include <signal.h> | |
29 | ||
18160b98 | 30 | #include <config.h> |
dc6f92b8 | 31 | |
3afe33e7 | 32 | /* Need syssignal.h for various externs and definitions that may be required |
bc20ebbf | 33 | by some configurations for calls to signal later in this source file. */ |
3afe33e7 RS |
34 | #include "syssignal.h" |
35 | ||
dc6f92b8 JB |
36 | #ifdef HAVE_X_WINDOWS |
37 | ||
38 | #include "lisp.h" | |
9ac0d9e0 | 39 | #include "blockinput.h" |
dc6f92b8 | 40 | |
dc6f92b8 JB |
41 | /* This may include sys/types.h, and that somehow loses |
42 | if this is not done before the other system files. */ | |
43 | #include "xterm.h" | |
f451eb13 | 44 | #include <X11/cursorfont.h> |
dc6f92b8 | 45 | |
16bd92ea | 46 | #ifndef USG |
dc6f92b8 JB |
47 | /* Load sys/types.h if not already loaded. |
48 | In some systems loading it twice is suicidal. */ | |
49 | #ifndef makedev | |
50 | #include <sys/types.h> | |
c118dd06 JB |
51 | #endif /* makedev */ |
52 | #endif /* USG */ | |
dc6f92b8 JB |
53 | |
54 | #ifdef BSD | |
55 | #include <sys/ioctl.h> | |
56 | #include <strings.h> | |
c118dd06 | 57 | #else /* ! defined (BSD) */ |
febf25d5 | 58 | #ifndef VMS |
dc6f92b8 | 59 | #include <string.h> |
febf25d5 | 60 | #endif |
c118dd06 | 61 | #endif /* ! defined (BSD) */ |
dc6f92b8 | 62 | |
2d368234 | 63 | #include "systty.h" |
3a2712f9 | 64 | #include "systime.h" |
dc6f92b8 | 65 | |
b8009dd1 | 66 | #ifndef INCLUDED_FCNTL |
dc6f92b8 | 67 | #include <fcntl.h> |
b8009dd1 | 68 | #endif |
dc6f92b8 JB |
69 | #include <ctype.h> |
70 | #include <errno.h> | |
71 | #include <setjmp.h> | |
72 | #include <sys/stat.h> | |
73 | #include <sys/param.h> | |
74 | ||
75 | #include "dispextern.h" | |
76 | #include "termhooks.h" | |
77 | #include "termopts.h" | |
78 | #include "termchar.h" | |
79 | #if 0 | |
80 | #include "sink.h" | |
81 | #include "sinkmask.h" | |
c118dd06 | 82 | #endif /* ! 0 */ |
dc6f92b8 | 83 | #include "gnu.h" |
f676886a | 84 | #include "frame.h" |
dc6f92b8 | 85 | #include "disptab.h" |
dc6f92b8 | 86 | #include "buffer.h" |
f451eb13 | 87 | #include "window.h" |
dc6f92b8 | 88 | |
3afe33e7 RS |
89 | #ifdef USE_X_TOOLKIT |
90 | extern XtAppContext Xt_app_con; | |
91 | extern Widget Xt_app_shell; | |
9d7e2e3e | 92 | extern void free_frame_menubar (); |
3afe33e7 RS |
93 | #endif /* USE_X_TOOLKIT */ |
94 | ||
b849c413 RS |
95 | #ifndef USE_X_TOOLKIT |
96 | #define x_any_window_to_frame x_window_to_frame | |
97 | #endif | |
98 | ||
dc6f92b8 JB |
99 | #ifdef HAVE_X11 |
100 | #define XMapWindow XMapRaised /* Raise them when mapping. */ | |
c118dd06 | 101 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
102 | #include <X/Xkeyboard.h> |
103 | /*#include <X/Xproto.h> */ | |
c118dd06 | 104 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 | 105 | |
c34efc6c JB |
106 | #ifdef FD_SET |
107 | /* We could get this from param.h, but better not to depend on finding that. | |
108 | And better not to risk that it might define other symbols used in this | |
109 | file. */ | |
110 | #ifdef FD_SETSIZE | |
111 | #define MAXDESC FD_SETSIZE | |
112 | #else | |
113 | #define MAXDESC 64 | |
114 | #endif | |
115 | #define SELECT_TYPE fd_set | |
116 | #else /* no FD_SET */ | |
117 | #define MAXDESC 32 | |
118 | #define SELECT_TYPE int | |
119 | ||
120 | /* Define the macros to access a single-int bitmap of descriptors. */ | |
121 | #define FD_SET(n, p) (*(p) |= (1 << (n))) | |
122 | #define FD_CLR(n, p) (*(p) &= ~(1 << (n))) | |
123 | #define FD_ISSET(n, p) (*(p) & (1 << (n))) | |
124 | #define FD_ZERO(p) (*(p) = 0) | |
125 | #endif /* no FD_SET */ | |
126 | ||
dc6f92b8 JB |
127 | /* For sending Meta-characters. Do we need this? */ |
128 | #define METABIT 0200 | |
129 | ||
130 | #define min(a,b) ((a)<(b) ? (a) : (b)) | |
131 | #define max(a,b) ((a)>(b) ? (a) : (b)) | |
69388238 | 132 | \f |
dc6f92b8 JB |
133 | /* Nonzero means we must reprint all windows |
134 | because 1) we received an ExposeWindow event | |
f451eb13 | 135 | or 2) we received too many ExposeRegion events to record. |
dc6f92b8 | 136 | |
f451eb13 | 137 | This is never needed under X11. */ |
dc6f92b8 JB |
138 | static int expose_all_windows; |
139 | ||
140 | /* Nonzero means we must reprint all icon windows. */ | |
141 | ||
142 | static int expose_all_icons; | |
143 | ||
144 | #ifndef HAVE_X11 | |
145 | /* ExposeRegion events, when received, are copied into this queue | |
146 | for later processing. */ | |
147 | ||
148 | static struct event_queue x_expose_queue; | |
149 | ||
69388238 | 150 | /* ButtonPress and ButtonReleased events, when received, |
dc6f92b8 JB |
151 | are copied into this queue for later processing. */ |
152 | ||
153 | struct event_queue x_mouse_queue; | |
c118dd06 | 154 | #endif /* HAVE_X11 */ |
dc6f92b8 | 155 | |
dc6f92b8 JB |
156 | #if defined (SIGIO) && defined (FIONREAD) |
157 | int BLOCK_INPUT_mask; | |
c118dd06 | 158 | #endif /* ! defined (SIGIO) && defined (FIONREAD) */ |
dc6f92b8 | 159 | |
dc6f92b8 JB |
160 | /* The id of a bitmap used for icon windows. |
161 | One such map is shared by all Emacs icon windows. | |
162 | This is zero if we have not yet had a need to create the bitmap. */ | |
163 | ||
164 | static Bitmap icon_bitmap; | |
165 | ||
166 | /* Font used for text icons. */ | |
167 | ||
168 | static FONT_TYPE *icon_font_info; | |
169 | ||
170 | /* Stuff for dealing with the main icon title. */ | |
171 | ||
172 | extern Lisp_Object Vcommand_line_args; | |
60fb3ee1 | 173 | char *hostname, *x_id_name; |
dc6f92b8 JB |
174 | |
175 | /* This is the X connection that we are using. */ | |
176 | ||
177 | Display *x_current_display; | |
178 | ||
ab648270 JB |
179 | /* The cursor to use for vertical scroll bars on x_current_display. */ |
180 | static Cursor x_vertical_scroll_bar_cursor; | |
f451eb13 | 181 | |
987d2ad1 | 182 | /* Frame being updated by update_frame. This is declared in term.c. |
d0386f2a | 183 | This is set by update_begin and looked at by all the |
dc6f92b8 | 184 | XT functions. It is zero while not inside an update. |
f676886a JB |
185 | In that case, the XT functions assume that `selected_frame' |
186 | is the frame to apply to. */ | |
d0386f2a | 187 | extern struct frame *updating_frame; |
dc6f92b8 | 188 | |
f676886a | 189 | /* The frame (if any) which has the X window that has keyboard focus. |
f451eb13 JB |
190 | Zero if none. This is examined by Ffocus_frame in frame.c. Note |
191 | that a mere EnterNotify event can set this; if you need to know the | |
192 | last frame specified in a FocusIn or FocusOut event, use | |
193 | x_focus_event_frame. */ | |
f676886a | 194 | struct frame *x_focus_frame; |
dc6f92b8 | 195 | |
f451eb13 JB |
196 | /* The last frame mentioned in a FocusIn or FocusOut event. This is |
197 | separate from x_focus_frame, because whether or not LeaveNotify | |
198 | events cause us to lose focus depends on whether or not we have | |
199 | received a FocusIn event for it. */ | |
200 | struct frame *x_focus_event_frame; | |
201 | ||
f676886a JB |
202 | /* The frame which currently has the visual highlight, and should get |
203 | keyboard input (other sorts of input have the frame encoded in the | |
204 | event). It points to the X focus frame's selected window's | |
205 | frame. It differs from x_focus_frame when we're using a global | |
6d4238f3 | 206 | minibuffer. */ |
f676886a | 207 | static struct frame *x_highlight_frame; |
6d4238f3 | 208 | |
dc6f92b8 | 209 | /* From .Xdefaults, the value of "emacs.WarpMouse". If non-zero, |
f676886a | 210 | mouse is moved to inside of frame when frame is de-iconified. */ |
dc6f92b8 JB |
211 | |
212 | static int warp_mouse_on_deiconify; | |
213 | ||
214 | /* During an update, maximum vpos for ins/del line operations to affect. */ | |
215 | ||
216 | static int flexlines; | |
217 | ||
218 | /* During an update, nonzero if chars output now should be highlighted. */ | |
219 | ||
220 | static int highlight; | |
221 | ||
222 | /* Nominal cursor position -- where to draw output. | |
223 | During an update, these are different from the cursor-box position. */ | |
224 | ||
225 | static int curs_x; | |
226 | static int curs_y; | |
227 | ||
69388238 RS |
228 | /* Mouse movement. |
229 | ||
230 | In order to avoid asking for motion events and then throwing most | |
231 | of them away or busy-polling the server for mouse positions, we ask | |
232 | the server for pointer motion hints. This means that we get only | |
233 | one event per group of mouse movements. "Groups" are delimited by | |
234 | other kinds of events (focus changes and button clicks, for | |
235 | example), or by XQueryPointer calls; when one of these happens, we | |
236 | get another MotionNotify event the next time the mouse moves. This | |
237 | is at least as efficient as getting motion events when mouse | |
238 | tracking is on, and I suspect only negligibly worse when tracking | |
239 | is off. | |
240 | ||
241 | The silly O'Reilly & Associates Nutshell guides barely document | |
242 | pointer motion hints at all (I think you have to infer how they | |
243 | work from an example), and the description of XQueryPointer doesn't | |
244 | mention that calling it causes you to get another motion hint from | |
245 | the server, which is very important. */ | |
246 | ||
247 | /* Where the mouse was last time we reported a mouse event. */ | |
248 | static FRAME_PTR last_mouse_frame; | |
249 | static XRectangle last_mouse_glyph; | |
250 | ||
251 | /* The scroll bar in which the last X motion event occurred. | |
252 | ||
253 | If the last X motion event occurred in a scroll bar, we set this | |
254 | so XTmouse_position can know whether to report a scroll bar motion or | |
255 | an ordinary motion. | |
256 | ||
257 | If the last X motion event didn't occur in a scroll bar, we set this | |
258 | to Qnil, to tell XTmouse_position to return an ordinary motion event. */ | |
259 | static Lisp_Object last_mouse_scroll_bar; | |
260 | ||
261 | /* Record which buttons are currently pressed. */ | |
262 | unsigned int x_mouse_grabbed; | |
263 | ||
264 | /* This is a hack. We would really prefer that XTmouse_position would | |
265 | return the time associated with the position it returns, but there | |
266 | doesn't seem to be any way to wrest the timestamp from the server | |
267 | along with the position query. So, we just keep track of the time | |
268 | of the last movement we received, and return that in hopes that | |
269 | it's somewhat accurate. */ | |
270 | static Time last_mouse_movement_time; | |
271 | ||
b8009dd1 RS |
272 | /* These variables describe the range of text currently shown |
273 | in its mouse-face, together with the window they apply to. | |
274 | As long as the mouse stays within this range, we need not | |
275 | redraw anything on its account. */ | |
276 | static int mouse_face_beg, mouse_face_end; | |
277 | static Lisp_Object mouse_face_window; | |
278 | static int mouse_face_face_id; | |
279 | ||
514e4681 RS |
280 | /* 1 if a mouse motion event came and we didn't handle it right away because |
281 | gc was in progress. */ | |
282 | static int mouse_face_deferred_gc; | |
283 | ||
b8009dd1 RS |
284 | /* FRAME and X, Y position of mouse when last checked for highlighting. */ |
285 | static FRAME_PTR mouse_face_mouse_frame; | |
286 | static int mouse_face_mouse_x, mouse_face_mouse_y; | |
287 | ||
288 | /* Nonzero means defer mouse-motion highlighting. */ | |
289 | static int mouse_face_defer; | |
290 | ||
dc6f92b8 JB |
291 | #ifdef HAVE_X11 |
292 | /* `t' if a mouse button is depressed. */ | |
293 | ||
294 | extern Lisp_Object Vmouse_depressed; | |
295 | ||
296 | /* Tells if a window manager is present or not. */ | |
297 | ||
298 | extern Lisp_Object Vx_no_window_manager; | |
299 | ||
300 | /* Timestamp that we requested selection data was made. */ | |
301 | extern Time requestor_time; | |
302 | ||
303 | /* ID of the window requesting selection data. */ | |
304 | extern Window requestor_window; | |
305 | ||
306 | /* Nonzero enables some debugging for the X interface code. */ | |
307 | extern int _Xdebug; | |
308 | ||
b8009dd1 RS |
309 | extern Qface, Qmouse_face; |
310 | ||
c118dd06 | 311 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
312 | |
313 | /* Bit patterns for the mouse cursor. */ | |
314 | ||
315 | short MouseCursor[] = { | |
316 | 0x0000, 0x0008, 0x0018, 0x0038, | |
317 | 0x0078, 0x00f8, 0x01f8, 0x03f8, | |
318 | 0x07f8, 0x00f8, 0x00d8, 0x0188, | |
319 | 0x0180, 0x0300, 0x0300, 0x0000}; | |
320 | ||
321 | short MouseMask[] = { | |
322 | 0x000c, 0x001c, 0x003c, 0x007c, | |
323 | 0x00fc, 0x01fc, 0x03fc, 0x07fc, | |
324 | 0x0ffc, 0x0ffc, 0x01fc, 0x03dc, | |
325 | 0x03cc, 0x0780, 0x0780, 0x0300}; | |
326 | ||
327 | static short grey_bits[] = { | |
328 | 0x0005, 0x000a, 0x0005, 0x000a}; | |
329 | ||
330 | static Pixmap GreyPixmap = 0; | |
c118dd06 | 331 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
332 | |
333 | /* From time to time we get info on an Emacs window, here. */ | |
334 | ||
335 | static WINDOWINFO_TYPE windowinfo; | |
336 | ||
337 | extern int errno; | |
338 | ||
dfeccd2d | 339 | /* A mask of extra modifier bits to put into every keyboard char. */ |
64bb1782 RS |
340 | extern int extra_keyboard_modifiers; |
341 | ||
dc6f92b8 JB |
342 | extern Display *XOpenDisplay (); |
343 | extern Window XCreateWindow (); | |
344 | ||
345 | extern Cursor XCreateCursor (); | |
346 | extern FONT_TYPE *XOpenFont (); | |
347 | ||
348 | static void flashback (); | |
c83febd7 | 349 | static void redraw_previous_char (); |
3afe33e7 | 350 | static unsigned int x_x_to_emacs_modifiers (); |
dc6f92b8 | 351 | |
b8009dd1 RS |
352 | static void note_mouse_highlight (); |
353 | static void clear_mouse_face (); | |
354 | static void show_mouse_face (); | |
355 | ||
dc6f92b8 JB |
356 | #ifndef HAVE_X11 |
357 | static void dumpqueue (); | |
c118dd06 | 358 | #endif /* HAVE_X11 */ |
dc6f92b8 JB |
359 | |
360 | void dumpborder (); | |
4746118a JB |
361 | static int XTcursor_to (); |
362 | static int XTclear_end_of_line (); | |
16bd92ea JB |
363 | |
364 | \f | |
f451eb13 JB |
365 | /* Starting and ending updates. |
366 | ||
367 | These hooks are called by update_frame at the beginning and end | |
f676886a JB |
368 | of a frame update. We record in `updating_frame' the identity |
369 | of the frame being updated, so that the XT... functions do not | |
370 | need to take a frame as argument. Most of the XT... functions | |
dc6f92b8 | 371 | should never be called except during an update, the only exceptions |
c83febd7 | 372 | being XTcursor_to, XTwrite_glyphs and XTreassert_line_highlight. */ |
dc6f92b8 JB |
373 | |
374 | extern int mouse_track_top, mouse_track_left, mouse_track_width; | |
375 | ||
376 | static | |
f676886a JB |
377 | XTupdate_begin (f) |
378 | struct frame *f; | |
dc6f92b8 JB |
379 | { |
380 | int mask; | |
381 | ||
f676886a | 382 | if (f == 0) |
dc6f92b8 JB |
383 | abort (); |
384 | ||
f676886a | 385 | flexlines = f->height; |
dc6f92b8 JB |
386 | highlight = 0; |
387 | ||
dc6f92b8 | 388 | BLOCK_INPUT; |
b8009dd1 RS |
389 | |
390 | if (f == mouse_face_mouse_frame) | |
391 | { | |
514e4681 | 392 | /* Don't do highlighting for mouse motion during the update. */ |
b8009dd1 RS |
393 | mouse_face_defer = 1; |
394 | if (!NILP (mouse_face_window)) | |
514e4681 RS |
395 | { |
396 | int firstline, lastline, i; | |
397 | struct window *w = XWINDOW (mouse_face_window); | |
398 | ||
399 | /* Find the first, and the last+1, lines affected by redisplay. */ | |
400 | for (firstline = 0; firstline < f->height; firstline++) | |
401 | if (FRAME_DESIRED_GLYPHS (f)->enable[firstline]) | |
402 | break; | |
403 | ||
404 | lastline = f->height; | |
405 | for (i = f->height - 1; i >= 0; i--) | |
406 | { | |
407 | if (FRAME_DESIRED_GLYPHS (f)->enable[i]) | |
408 | break; | |
409 | else | |
410 | lastline = i; | |
411 | } | |
412 | ||
413 | /* Can we tell that this update does not affect the window | |
414 | where the mouse highlight is? If so, no need to turn off. */ | |
415 | if (! (firstline > (XFASTINT (w->top) + window_internal_height (w)) | |
416 | || lastline < XFASTINT (w->top))) | |
417 | /* Otherwise turn off the mouse highlight now. */ | |
418 | clear_mouse_face (); | |
419 | } | |
b8009dd1 | 420 | } |
dc6f92b8 JB |
421 | #ifndef HAVE_X11 |
422 | dumpqueue (); | |
c118dd06 | 423 | #endif /* HAVE_X11 */ |
dc6f92b8 JB |
424 | UNBLOCK_INPUT; |
425 | } | |
426 | ||
f451eb13 | 427 | #ifndef HAVE_X11 |
dc6f92b8 | 428 | static void x_do_pending_expose (); |
f451eb13 | 429 | #endif |
dc6f92b8 JB |
430 | |
431 | static | |
f676886a JB |
432 | XTupdate_end (f) |
433 | struct frame *f; | |
dc6f92b8 JB |
434 | { |
435 | int mask; | |
436 | ||
dc6f92b8 JB |
437 | BLOCK_INPUT; |
438 | #ifndef HAVE_X11 | |
439 | dumpqueue (); | |
dc6f92b8 | 440 | x_do_pending_expose (); |
f451eb13 | 441 | #endif /* HAVE_X11 */ |
dc6f92b8 | 442 | |
f676886a | 443 | x_display_cursor (f, 1); |
dc6f92b8 | 444 | |
b8009dd1 RS |
445 | if (f == mouse_face_mouse_frame) |
446 | mouse_face_defer = 0; | |
447 | #if 0 | |
448 | /* This fails in the case of having updated only the echo area | |
449 | if we have switched buffers. In that case, FRAME_CURRENT_GLYPHS | |
450 | has no relation to the current contents, and its charstarts | |
451 | have no relation to the contents of the window-buffer. | |
452 | I don't know a clean way to check | |
453 | for that case. window_end_valid isn't set up yet. */ | |
454 | if (f == mouse_face_mouse_frame) | |
455 | note_mouse_highlight (f, mouse_face_mouse_x, mouse_face_mouse_y); | |
456 | #endif | |
457 | ||
dc6f92b8 JB |
458 | XFlushQueue (); |
459 | UNBLOCK_INPUT; | |
460 | } | |
b8009dd1 | 461 | |
514e4681 | 462 | /* This is called after a redisplay on frame F. */ |
b8009dd1 RS |
463 | |
464 | static | |
465 | XTframe_up_to_date (f) | |
466 | FRAME_PTR f; | |
467 | { | |
514e4681 RS |
468 | if (mouse_face_deferred_gc || f == mouse_face_mouse_frame) |
469 | { | |
470 | note_mouse_highlight (mouse_face_mouse_frame, | |
471 | mouse_face_mouse_x, mouse_face_mouse_y); | |
472 | mouse_face_deferred_gc = 0; | |
473 | } | |
b8009dd1 | 474 | } |
dc6f92b8 JB |
475 | \f |
476 | /* External interface to control of standout mode. | |
477 | Call this when about to modify line at position VPOS | |
478 | and not change whether it is highlighted. */ | |
479 | ||
480 | XTreassert_line_highlight (new, vpos) | |
481 | int new, vpos; | |
482 | { | |
483 | highlight = new; | |
484 | } | |
485 | ||
486 | /* Call this when about to modify line at position VPOS | |
487 | and change whether it is highlighted. */ | |
488 | ||
489 | static | |
490 | XTchange_line_highlight (new_highlight, vpos, first_unused_hpos) | |
491 | int new_highlight, vpos, first_unused_hpos; | |
492 | { | |
493 | highlight = new_highlight; | |
494 | XTcursor_to (vpos, 0); | |
f676886a | 495 | XTclear_end_of_line (updating_frame->width); |
dc6f92b8 JB |
496 | } |
497 | ||
498 | /* This is used when starting Emacs and when restarting after suspend. | |
499 | When starting Emacs, no X window is mapped. And nothing must be done | |
500 | to Emacs's own window if it is suspended (though that rarely happens). */ | |
501 | ||
502 | static | |
503 | XTset_terminal_modes () | |
504 | { | |
505 | } | |
506 | ||
507 | /* This is called when exiting or suspending Emacs. | |
508 | Exiting will make the X-windows go away, and suspending | |
509 | requires no action. */ | |
510 | ||
511 | static | |
512 | XTreset_terminal_modes () | |
513 | { | |
f676886a | 514 | /* XTclear_frame (); */ |
dc6f92b8 JB |
515 | } |
516 | \f | |
f451eb13 JB |
517 | /* Set the nominal cursor position of the frame. |
518 | This is where display update commands will take effect. | |
dc6f92b8 JB |
519 | This does not affect the place where the cursor-box is displayed. */ |
520 | ||
4746118a | 521 | static int |
dc6f92b8 JB |
522 | XTcursor_to (row, col) |
523 | register int row, col; | |
524 | { | |
525 | int mask; | |
526 | int orow = row; | |
527 | ||
528 | curs_x = col; | |
529 | curs_y = row; | |
530 | ||
f676886a | 531 | if (updating_frame == 0) |
dc6f92b8 JB |
532 | { |
533 | BLOCK_INPUT; | |
f676886a | 534 | x_display_cursor (selected_frame, 1); |
dc6f92b8 JB |
535 | XFlushQueue (); |
536 | UNBLOCK_INPUT; | |
537 | } | |
538 | } | |
539 | \f | |
540 | /* Display a sequence of N glyphs found at GP. | |
541 | WINDOW is the x-window to output to. LEFT and TOP are starting coords. | |
b8009dd1 RS |
542 | HL is 1 if this text is highlighted, 2 if the cursor is on it, |
543 | 3 if should appear in its mouse-face. | |
dc6f92b8 | 544 | |
07e34cb0 | 545 | FONT is the default font to use (for glyphs whose font-code is 0). |
dc6f92b8 | 546 | |
07e34cb0 JB |
547 | Since the display generation code is responsible for calling |
548 | compute_char_face and compute_glyph_face on everything it puts in | |
549 | the display structure, we can assume that the face code on each | |
28f72798 | 550 | glyph is a valid index into FRAME_COMPUTED_FACES (f), and the one |
f94397b5 KH |
551 | to which we can actually apply intern_face. |
552 | Call this function with input blocked. */ | |
dc6f92b8 | 553 | |
07e34cb0 JB |
554 | #if 1 |
555 | /* This is the multi-face code. */ | |
dc6f92b8 | 556 | |
dc6f92b8 | 557 | static void |
07e34cb0 | 558 | dumpglyphs (f, left, top, gp, n, hl) |
f676886a | 559 | struct frame *f; |
dc6f92b8 JB |
560 | int left, top; |
561 | register GLYPH *gp; /* Points to first GLYPH. */ | |
562 | register int n; /* Number of glyphs to display. */ | |
563 | int hl; | |
dc6f92b8 | 564 | { |
07e34cb0 JB |
565 | /* Holds characters to be displayed. */ |
566 | char *buf = (char *) alloca (f->width * sizeof (*buf)); | |
dc6f92b8 JB |
567 | register char *cp; /* Steps through buf[]. */ |
568 | register int tlen = GLYPH_TABLE_LENGTH; | |
569 | register Lisp_Object *tbase = GLYPH_TABLE_BASE; | |
c118dd06 | 570 | Window window = FRAME_X_WINDOW (f); |
dc6f92b8 | 571 | |
07e34cb0 | 572 | while (n > 0) |
dc6f92b8 JB |
573 | { |
574 | /* Get the face-code of the next GLYPH. */ | |
575 | int cf, len; | |
576 | int g = *gp; | |
577 | ||
07e34cb0 | 578 | GLYPH_FOLLOW_ALIASES (tbase, tlen, g); |
6f63ba79 | 579 | cf = FAST_GLYPH_FACE (g); |
dc6f92b8 JB |
580 | |
581 | /* Find the run of consecutive glyphs with the same face-code. | |
582 | Extract their character codes into BUF. */ | |
583 | cp = buf; | |
584 | while (n > 0) | |
585 | { | |
586 | g = *gp; | |
07e34cb0 | 587 | GLYPH_FOLLOW_ALIASES (tbase, tlen, g); |
6f63ba79 | 588 | if (FAST_GLYPH_FACE (g) != cf) |
dc6f92b8 JB |
589 | break; |
590 | ||
6f63ba79 | 591 | *cp++ = FAST_GLYPH_CHAR (g); |
dc6f92b8 JB |
592 | --n; |
593 | ++gp; | |
594 | } | |
595 | ||
596 | /* LEN gets the length of the run. */ | |
597 | len = cp - buf; | |
598 | ||
599 | /* Now output this run of chars, with the font and pixel values | |
600 | determined by the face code CF. */ | |
07e34cb0 JB |
601 | { |
602 | struct face *face = FRAME_DEFAULT_FACE (f); | |
603 | FONT_TYPE *font = FACE_FONT (face); | |
604 | GC gc = FACE_GC (face); | |
b73b6aaf RS |
605 | int defaulted = 1; |
606 | int gc_temporary = 0; | |
07e34cb0 | 607 | |
b8009dd1 RS |
608 | /* HL = 3 means use a mouse face previously chosen. */ |
609 | if (hl == 3) | |
610 | cf = mouse_face_face_id; | |
611 | ||
b73b6aaf RS |
612 | /* First look at the face of the text itself. */ |
613 | if (cf != 0) | |
07e34cb0 | 614 | { |
a07d4bc5 RS |
615 | /* It's possible for the display table to specify |
616 | a face code that is out of range. Use 0 in that case. */ | |
28f72798 JB |
617 | if (cf < 0 || cf >= FRAME_N_COMPUTED_FACES (f) |
618 | || FRAME_COMPUTED_FACES (f) [cf] == 0) | |
a07d4bc5 | 619 | cf = 0; |
07e34cb0 JB |
620 | |
621 | if (cf == 1) | |
622 | face = FRAME_MODE_LINE_FACE (f); | |
623 | else | |
28f72798 | 624 | face = intern_face (f, FRAME_COMPUTED_FACES (f) [cf]); |
07e34cb0 JB |
625 | font = FACE_FONT (face); |
626 | gc = FACE_GC (face); | |
b73b6aaf | 627 | defaulted = 0; |
07e34cb0 | 628 | } |
4a4dc352 JB |
629 | |
630 | /* Then comes the distinction between modeline and normal text. */ | |
07e34cb0 JB |
631 | else if (hl == 0) |
632 | ; | |
633 | else if (hl == 1) | |
634 | { | |
635 | face = FRAME_MODE_LINE_FACE (f); | |
636 | font = FACE_FONT (face); | |
637 | gc = FACE_GC (face); | |
b73b6aaf RS |
638 | defaulted = 0; |
639 | } | |
640 | ||
641 | #define FACE_DEFAULT (~0) | |
642 | ||
643 | /* Now override that if the cursor's on this character. */ | |
b5cf7a0e | 644 | if (hl == 2) |
b73b6aaf | 645 | { |
b5cf7a0e JB |
646 | if (defaulted |
647 | || !face->font | |
648 | || (int) face->font == FACE_DEFAULT) | |
649 | { | |
650 | gc = f->display.x->cursor_gc; | |
651 | } | |
652 | /* Cursor on non-default face: must merge. */ | |
653 | else | |
654 | { | |
655 | XGCValues xgcv; | |
656 | unsigned long mask; | |
657 | ||
658 | xgcv.background = f->display.x->cursor_pixel; | |
df5a440b RS |
659 | if (face == FRAME_DEFAULT_FACE (f)) |
660 | xgcv.foreground = f->display.x->cursor_foreground_pixel; | |
661 | else | |
662 | xgcv.foreground = face->foreground; | |
663 | /* If the glyph would be invisible, | |
664 | try a different foreground. */ | |
665 | if (xgcv.foreground == xgcv.background) | |
666 | xgcv.foreground = face->background; | |
667 | if (xgcv.foreground == xgcv.background) | |
668 | xgcv.foreground = f->display.x->cursor_foreground_pixel; | |
669 | if (xgcv.foreground == xgcv.background) | |
670 | xgcv.foreground = face->foreground; | |
671 | /* Make sure the cursor is distinct from text in this face. */ | |
672 | if (xgcv.background == face->background | |
673 | && xgcv.foreground == face->foreground) | |
674 | { | |
675 | xgcv.background = face->foreground; | |
676 | xgcv.foreground = face->background; | |
677 | } | |
b5cf7a0e JB |
678 | xgcv.font = face->font->fid; |
679 | xgcv.graphics_exposures = 0; | |
680 | mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures; | |
681 | gc = XCreateGC (x_current_display, FRAME_X_WINDOW (f), | |
682 | mask, &xgcv); | |
b73b6aaf | 683 | #if 0 |
b5cf7a0e JB |
684 | if (face->stipple && face->stipple != FACE_DEFAULT) |
685 | XSetStipple (x_current_display, gc, face->stipple); | |
b73b6aaf | 686 | #endif |
b5cf7a0e JB |
687 | gc_temporary = 1; |
688 | } | |
07e34cb0 | 689 | } |
07e34cb0 | 690 | |
b5cf7a0e JB |
691 | if ((int) font == FACE_DEFAULT) |
692 | font = f->display.x->font; | |
693 | ||
07e34cb0 JB |
694 | XDrawImageString (x_current_display, window, gc, |
695 | left, top + FONT_BASE (font), buf, len); | |
07e34cb0 | 696 | |
b73b6aaf RS |
697 | if (gc_temporary) |
698 | XFreeGC (x_current_display, gc); | |
699 | ||
07e34cb0 JB |
700 | /* We should probably check for XA_UNDERLINE_POSITION and |
701 | XA_UNDERLINE_THICKNESS properties on the font, but let's | |
702 | just get the thing working, and come back to that. */ | |
dc6f92b8 | 703 | { |
4a4dc352 | 704 | int underline_position = 1; |
07e34cb0 | 705 | |
4a4dc352 JB |
706 | if (font->descent <= underline_position) |
707 | underline_position = font->descent - 1; | |
07e34cb0 JB |
708 | |
709 | if (face->underline) | |
710 | XFillRectangle (x_current_display, FRAME_X_WINDOW (f), | |
711 | FACE_GC (face), | |
712 | left, (top | |
713 | + FONT_BASE (font) | |
714 | + underline_position), | |
715 | len * FONT_WIDTH (font), 1); | |
dc6f92b8 | 716 | } |
07e34cb0 JB |
717 | |
718 | left += len * FONT_WIDTH (font); | |
719 | } | |
dc6f92b8 JB |
720 | } |
721 | } | |
07e34cb0 JB |
722 | #endif /* 1 */ |
723 | ||
724 | #if 0 | |
725 | /* This is the old single-face code. */ | |
726 | ||
727 | static void | |
728 | dumpglyphs (f, left, top, gp, n, hl, font) | |
729 | struct frame *f; | |
730 | int left, top; | |
731 | register GLYPH *gp; /* Points to first GLYPH. */ | |
732 | register int n; /* Number of glyphs to display. */ | |
733 | int hl; | |
734 | FONT_TYPE *font; | |
735 | { | |
736 | register int len; | |
737 | Window window = FRAME_X_WINDOW (f); | |
738 | GC drawing_gc = (hl == 2 ? f->display.x->cursor_gc | |
739 | : (hl ? f->display.x->reverse_gc | |
740 | : f->display.x->normal_gc)); | |
741 | ||
742 | if (sizeof (GLYPH) == sizeof (XChar2b)) | |
743 | XDrawImageString16 (x_current_display, window, drawing_gc, | |
744 | left, top + FONT_BASE (font), (XChar2b *) gp, n); | |
745 | else if (sizeof (GLYPH) == sizeof (unsigned char)) | |
746 | XDrawImageString (x_current_display, window, drawing_gc, | |
747 | left, top + FONT_BASE (font), (char *) gp, n); | |
748 | else | |
749 | /* What size of glyph ARE you using? And does X have a function to | |
750 | draw them? */ | |
751 | abort (); | |
752 | } | |
753 | #endif | |
dc6f92b8 | 754 | \f |
f451eb13 JB |
755 | /* Output some text at the nominal frame cursor position. |
756 | Advance the cursor over the text. | |
dc6f92b8 JB |
757 | Output LEN glyphs at START. |
758 | ||
759 | `highlight', set up by XTreassert_line_highlight or XTchange_line_highlight, | |
760 | controls the pixel values used for foreground and background. */ | |
761 | ||
762 | static | |
763 | XTwrite_glyphs (start, len) | |
764 | register GLYPH *start; | |
765 | int len; | |
766 | { | |
767 | register int temp_length; | |
768 | int mask; | |
f676886a | 769 | struct frame *f; |
dc6f92b8 JB |
770 | |
771 | BLOCK_INPUT; | |
772 | ||
f676886a JB |
773 | f = updating_frame; |
774 | if (f == 0) | |
dc6f92b8 | 775 | { |
f676886a | 776 | f = selected_frame; |
dc6f92b8 | 777 | /* If not within an update, |
f676886a JB |
778 | output at the frame's visible cursor. */ |
779 | curs_x = f->cursor_x; | |
780 | curs_y = f->cursor_y; | |
dc6f92b8 JB |
781 | } |
782 | ||
f676886a | 783 | dumpglyphs (f, |
12ba150f JB |
784 | CHAR_TO_PIXEL_COL (f, curs_x), |
785 | CHAR_TO_PIXEL_ROW (f, curs_y), | |
07e34cb0 | 786 | start, len, highlight); |
90e65f07 JB |
787 | |
788 | /* If we drew on top of the cursor, note that it is turned off. */ | |
f676886a JB |
789 | if (curs_y == f->phys_cursor_y |
790 | && curs_x <= f->phys_cursor_x | |
791 | && curs_x + len > f->phys_cursor_x) | |
792 | f->phys_cursor_x = -1; | |
dc6f92b8 | 793 | |
f676886a | 794 | if (updating_frame == 0) |
dc6f92b8 | 795 | { |
f676886a JB |
796 | f->cursor_x += len; |
797 | x_display_cursor (f, 1); | |
798 | f->cursor_x -= len; | |
dc6f92b8 JB |
799 | } |
800 | else | |
801 | curs_x += len; | |
802 | ||
803 | UNBLOCK_INPUT; | |
804 | } | |
805 | \f | |
f451eb13 JB |
806 | /* Clear to the end of the line. |
807 | Erase the current text line from the nominal cursor position (inclusive) | |
dc6f92b8 JB |
808 | to column FIRST_UNUSED (exclusive). The idea is that everything |
809 | from FIRST_UNUSED onward is already erased. */ | |
810 | ||
4746118a | 811 | static int |
dc6f92b8 JB |
812 | XTclear_end_of_line (first_unused) |
813 | register int first_unused; | |
814 | { | |
f676886a | 815 | struct frame *f = updating_frame; |
dc6f92b8 JB |
816 | int mask; |
817 | ||
f676886a | 818 | if (f == 0) |
dc6f92b8 JB |
819 | abort (); |
820 | ||
f676886a | 821 | if (curs_y < 0 || curs_y >= f->height) |
dc6f92b8 JB |
822 | return; |
823 | if (first_unused <= 0) | |
824 | return; | |
825 | ||
f676886a JB |
826 | if (first_unused >= f->width) |
827 | first_unused = f->width; | |
dc6f92b8 JB |
828 | |
829 | BLOCK_INPUT; | |
830 | ||
90e65f07 | 831 | /* Notice if the cursor will be cleared by this operation. */ |
f676886a JB |
832 | if (curs_y == f->phys_cursor_y |
833 | && curs_x <= f->phys_cursor_x | |
834 | && f->phys_cursor_x < first_unused) | |
835 | f->phys_cursor_x = -1; | |
dc6f92b8 JB |
836 | |
837 | #ifdef HAVE_X11 | |
c118dd06 | 838 | XClearArea (x_current_display, FRAME_X_WINDOW (f), |
12ba150f JB |
839 | CHAR_TO_PIXEL_COL (f, curs_x), |
840 | CHAR_TO_PIXEL_ROW (f, curs_y), | |
f676886a | 841 | FONT_WIDTH (f->display.x->font) * (first_unused - curs_x), |
a27f9f86 | 842 | f->display.x->line_height, False); |
c83febd7 RS |
843 | #if 0 |
844 | redraw_previous_char (f, curs_x, curs_y); | |
845 | #endif | |
c118dd06 JB |
846 | #else /* ! defined (HAVE_X11) */ |
847 | XPixSet (FRAME_X_WINDOW (f), | |
12ba150f JB |
848 | CHAR_TO_PIXEL_COL (f, curs_x), |
849 | CHAR_TO_PIXEL_ROW (f, curs_y), | |
f676886a | 850 | FONT_WIDTH (f->display.x->font) * (first_unused - curs_x), |
a27f9f86 | 851 | f->display.x->line_height, |
f676886a | 852 | f->display.x->background_pixel); |
c118dd06 | 853 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
854 | |
855 | UNBLOCK_INPUT; | |
856 | } | |
857 | ||
c83febd7 RS |
858 | /* Erase the character (if any) at the position just before X, Y in frame F, |
859 | then redraw it and the character before it. | |
860 | This is necessary when we erase starting at X, | |
f94397b5 KH |
861 | in case the character after X overlaps into the one before X. |
862 | Call this function with input blocked. */ | |
c83febd7 RS |
863 | |
864 | static void | |
865 | redraw_previous_char (f, x, y) | |
866 | FRAME_PTR f; | |
867 | int x, y; | |
868 | { | |
869 | /* Erase the character before the new ones, in case | |
870 | what was here before overlaps it. | |
871 | Reoutput that character, and the previous character | |
872 | (in case the previous character overlaps it). */ | |
873 | if (x > 0) | |
874 | { | |
875 | int start_x = x - 2; | |
876 | if (start_x < 0) | |
877 | start_x = 0; | |
878 | XClearArea (x_current_display, FRAME_X_WINDOW (f), | |
879 | CHAR_TO_PIXEL_COL (f, x - 1), | |
880 | CHAR_TO_PIXEL_ROW (f, y), | |
881 | FONT_WIDTH (f->display.x->font), | |
a27f9f86 | 882 | f->display.x->line_height, False); |
c83febd7 RS |
883 | |
884 | dumpglyphs (f, CHAR_TO_PIXEL_COL (f, start_x), | |
885 | CHAR_TO_PIXEL_ROW (f, y), | |
886 | &FRAME_CURRENT_GLYPHS (f)->glyphs[y][start_x], | |
887 | x - start_x, highlight); | |
888 | } | |
889 | } | |
890 | ||
dc6f92b8 | 891 | static |
f676886a | 892 | XTclear_frame () |
dc6f92b8 JB |
893 | { |
894 | int mask; | |
f676886a | 895 | struct frame *f = updating_frame; |
dc6f92b8 | 896 | |
f676886a JB |
897 | if (f == 0) |
898 | f = selected_frame; | |
dc6f92b8 | 899 | |
f676886a | 900 | f->phys_cursor_x = -1; /* Cursor not visible. */ |
dc6f92b8 JB |
901 | curs_x = 0; /* Nominal cursor position is top left. */ |
902 | curs_y = 0; | |
903 | ||
904 | BLOCK_INPUT; | |
dbc4e1c1 | 905 | |
c118dd06 | 906 | XClear (FRAME_X_WINDOW (f)); |
dbc4e1c1 | 907 | |
ab648270 | 908 | /* We have to clear the scroll bars, too. If we have changed |
dbc4e1c1 | 909 | colors or something like that, then they should be notified. */ |
ab648270 | 910 | x_scroll_bar_clear (f); |
dbc4e1c1 | 911 | |
dc6f92b8 | 912 | #ifndef HAVE_X11 |
f676886a | 913 | dumpborder (f, 0); |
c118dd06 | 914 | #endif /* HAVE_X11 */ |
dbc4e1c1 | 915 | |
dc6f92b8 JB |
916 | XFlushQueue (); |
917 | UNBLOCK_INPUT; | |
918 | } | |
919 | \f | |
dbc4e1c1 JB |
920 | /* Invert the middle quarter of the frame for .15 sec. */ |
921 | ||
922 | /* We use the select system call to do the waiting, so we have to make sure | |
eb8c3be9 | 923 | it's available. If it isn't, we just won't do visual bells. */ |
dbc4e1c1 JB |
924 | #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) |
925 | ||
926 | /* Subtract the `struct timeval' values X and Y, | |
927 | storing the result in RESULT. | |
928 | Return 1 if the difference is negative, otherwise 0. */ | |
929 | ||
930 | static int | |
931 | timeval_subtract (result, x, y) | |
932 | struct timeval *result, x, y; | |
933 | { | |
934 | /* Perform the carry for the later subtraction by updating y. | |
935 | This is safer because on some systems | |
936 | the tv_sec member is unsigned. */ | |
937 | if (x.tv_usec < y.tv_usec) | |
938 | { | |
939 | int nsec = (y.tv_usec - x.tv_usec) / 1000000 + 1; | |
940 | y.tv_usec -= 1000000 * nsec; | |
941 | y.tv_sec += nsec; | |
942 | } | |
943 | if (x.tv_usec - y.tv_usec > 1000000) | |
944 | { | |
945 | int nsec = (y.tv_usec - x.tv_usec) / 1000000; | |
946 | y.tv_usec += 1000000 * nsec; | |
947 | y.tv_sec -= nsec; | |
948 | } | |
949 | ||
950 | /* Compute the time remaining to wait. tv_usec is certainly positive. */ | |
951 | result->tv_sec = x.tv_sec - y.tv_sec; | |
952 | result->tv_usec = x.tv_usec - y.tv_usec; | |
953 | ||
954 | /* Return indication of whether the result should be considered negative. */ | |
955 | return x.tv_sec < y.tv_sec; | |
956 | } | |
dc6f92b8 | 957 | |
f676886a JB |
958 | XTflash (f) |
959 | struct frame *f; | |
dc6f92b8 | 960 | { |
dbc4e1c1 | 961 | BLOCK_INPUT; |
dc6f92b8 | 962 | |
dbc4e1c1 JB |
963 | { |
964 | GC gc; | |
dc6f92b8 | 965 | |
dbc4e1c1 JB |
966 | /* Create a GC that will use the GXxor function to flip foreground pixels |
967 | into background pixels. */ | |
968 | { | |
969 | XGCValues values; | |
dc6f92b8 | 970 | |
dbc4e1c1 JB |
971 | values.function = GXxor; |
972 | values.foreground = (f->display.x->foreground_pixel | |
973 | ^ f->display.x->background_pixel); | |
974 | ||
975 | gc = XCreateGC (x_current_display, FRAME_X_WINDOW (f), | |
976 | GCFunction | GCForeground, &values); | |
977 | } | |
dc6f92b8 | 978 | |
dbc4e1c1 JB |
979 | { |
980 | int width = PIXEL_WIDTH (f); | |
981 | int height = PIXEL_HEIGHT (f); | |
dc6f92b8 | 982 | |
dbc4e1c1 JB |
983 | XFillRectangle (x_current_display, FRAME_X_WINDOW (f), gc, |
984 | width/4, height/4, width/2, height/2); | |
985 | XFlush (x_current_display); | |
dc6f92b8 | 986 | |
dbc4e1c1 JB |
987 | { |
988 | struct timeval wakeup, now; | |
dc6f92b8 | 989 | |
66c30ea1 | 990 | EMACS_GET_TIME (wakeup); |
dc6f92b8 | 991 | |
dbc4e1c1 JB |
992 | /* Compute time to wait until, propagating carry from usecs. */ |
993 | wakeup.tv_usec += 150000; | |
994 | wakeup.tv_sec += (wakeup.tv_usec / 1000000); | |
995 | wakeup.tv_usec %= 1000000; | |
996 | ||
997 | /* Keep waiting until past the time wakeup. */ | |
998 | while (1) | |
999 | { | |
1000 | struct timeval timeout; | |
1001 | ||
66c30ea1 | 1002 | EMACS_GET_TIME (timeout); |
dbc4e1c1 JB |
1003 | |
1004 | /* In effect, timeout = wakeup - timeout. | |
1005 | Break if result would be negative. */ | |
1006 | if (timeval_subtract (&timeout, wakeup, timeout)) | |
1007 | break; | |
1008 | ||
1009 | /* Try to wait that long--but we might wake up sooner. */ | |
1010 | select (0, 0, 0, 0, &timeout); | |
1011 | } | |
1012 | } | |
1013 | ||
1014 | XFillRectangle (x_current_display, FRAME_X_WINDOW (f), gc, | |
1015 | width/4, height/4, width/2, height/2); | |
1016 | XFreeGC (x_current_display, gc); | |
1017 | XFlush (x_current_display); | |
dc6f92b8 | 1018 | } |
dbc4e1c1 JB |
1019 | } |
1020 | ||
1021 | UNBLOCK_INPUT; | |
dc6f92b8 JB |
1022 | } |
1023 | ||
dbc4e1c1 JB |
1024 | #endif |
1025 | ||
1026 | ||
dc6f92b8 JB |
1027 | /* Make audible bell. */ |
1028 | ||
1029 | #ifdef HAVE_X11 | |
bc20ebbf | 1030 | #define XRINGBELL XBell (x_current_display, 0) |
c118dd06 | 1031 | #else /* ! defined (HAVE_X11) */ |
bc20ebbf | 1032 | #define XRINGBELL XFeep (0); |
c118dd06 | 1033 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
1034 | |
1035 | XTring_bell () | |
1036 | { | |
5a6ef893 RS |
1037 | if (x_current_display == 0) |
1038 | return; | |
1039 | ||
dbc4e1c1 | 1040 | #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) |
dc6f92b8 | 1041 | if (visible_bell) |
f676886a | 1042 | XTflash (selected_frame); |
dc6f92b8 | 1043 | else |
dbc4e1c1 | 1044 | #endif |
dc6f92b8 JB |
1045 | { |
1046 | BLOCK_INPUT; | |
1047 | XRINGBELL; | |
1048 | XFlushQueue (); | |
1049 | UNBLOCK_INPUT; | |
1050 | } | |
1051 | } | |
1052 | \f | |
f451eb13 JB |
1053 | /* Insert and delete character. |
1054 | These are not supposed to be used because we are supposed to turn | |
1055 | off the feature of using them. */ | |
dc6f92b8 JB |
1056 | |
1057 | static | |
1058 | XTinsert_glyphs (start, len) | |
1059 | register char *start; | |
1060 | register int len; | |
1061 | { | |
1062 | abort (); | |
1063 | } | |
1064 | ||
1065 | static | |
1066 | XTdelete_glyphs (n) | |
1067 | register int n; | |
1068 | { | |
1069 | abort (); | |
1070 | } | |
1071 | \f | |
1072 | /* Specify how many text lines, from the top of the window, | |
1073 | should be affected by insert-lines and delete-lines operations. | |
1074 | This, and those operations, are used only within an update | |
1075 | that is bounded by calls to XTupdate_begin and XTupdate_end. */ | |
1076 | ||
1077 | static | |
1078 | XTset_terminal_window (n) | |
1079 | register int n; | |
1080 | { | |
f676886a | 1081 | if (updating_frame == 0) |
dc6f92b8 JB |
1082 | abort (); |
1083 | ||
f676886a JB |
1084 | if ((n <= 0) || (n > updating_frame->height)) |
1085 | flexlines = updating_frame->height; | |
dc6f92b8 JB |
1086 | else |
1087 | flexlines = n; | |
1088 | } | |
1089 | \f | |
f451eb13 JB |
1090 | /* Perform an insert-lines operation. |
1091 | Insert N lines at a vertical position curs_y. */ | |
dc6f92b8 JB |
1092 | |
1093 | static void | |
1094 | stufflines (n) | |
1095 | register int n; | |
1096 | { | |
1097 | register int topregion, bottomregion; | |
1098 | register int length, newtop, mask; | |
f676886a JB |
1099 | register struct frame *f = updating_frame; |
1100 | int intborder = f->display.x->internal_border_width; | |
dc6f92b8 JB |
1101 | |
1102 | if (curs_y >= flexlines) | |
1103 | return; | |
1104 | ||
1105 | topregion = curs_y; | |
1106 | bottomregion = flexlines - (n + 1); | |
1107 | newtop = topregion + n; | |
1108 | length = (bottomregion - topregion) + 1; | |
1109 | ||
1110 | #ifndef HAVE_X11 | |
1111 | dumpqueue (); | |
c118dd06 | 1112 | #endif /* HAVE_X11 */ |
dc6f92b8 JB |
1113 | |
1114 | if ((length > 0) && (newtop <= flexlines)) | |
1115 | { | |
1116 | #ifdef HAVE_X11 | |
c118dd06 JB |
1117 | XCopyArea (x_current_display, FRAME_X_WINDOW (f), |
1118 | FRAME_X_WINDOW (f), f->display.x->normal_gc, | |
12ba150f | 1119 | intborder, CHAR_TO_PIXEL_ROW (f, topregion), |
f676886a | 1120 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1121 | length * f->display.x->line_height, intborder, |
12ba150f | 1122 | CHAR_TO_PIXEL_ROW (f, newtop)); |
c118dd06 JB |
1123 | #else /* ! defined (HAVE_X11) */ |
1124 | XMoveArea (FRAME_X_WINDOW (f), | |
12ba150f JB |
1125 | intborder, CHAR_TO_PIXEL_ROW (f, topregion), |
1126 | intborder, CHAR_TO_PIXEL_ROW (f, newtop), | |
f676886a | 1127 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1128 | length * f->display.x->line_height); |
dc6f92b8 JB |
1129 | /* Now we must process any ExposeRegion events that occur |
1130 | if the area being copied from is obscured. | |
1131 | We can't let it wait because further i/d operations | |
1132 | may want to copy this area to another area. */ | |
1133 | x_read_exposes (); | |
c118dd06 | 1134 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
1135 | } |
1136 | ||
1137 | newtop = min (newtop, (flexlines - 1)); | |
1138 | length = newtop - topregion; | |
1139 | if (length > 0) | |
1140 | { | |
1141 | #ifdef HAVE_X11 | |
c118dd06 | 1142 | XClearArea (x_current_display, FRAME_X_WINDOW (f), intborder, |
12ba150f | 1143 | CHAR_TO_PIXEL_ROW (f, topregion), |
f676886a | 1144 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1145 | n * f->display.x->line_height, False); |
c118dd06 JB |
1146 | #else /* ! defined (HAVE_X11) */ |
1147 | XPixSet (FRAME_X_WINDOW (f), | |
dc6f92b8 | 1148 | intborder, |
12ba150f | 1149 | CHAR_TO_PIXEL_ROW (f, topregion), |
f676886a | 1150 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1151 | n * f->display.x->line_height, |
f676886a | 1152 | f->display.x->background_pixel); |
c118dd06 | 1153 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
1154 | } |
1155 | } | |
1156 | ||
1157 | /* Perform a delete-lines operation, deleting N lines | |
1158 | at a vertical position curs_y. */ | |
1159 | ||
1160 | static void | |
1161 | scraplines (n) | |
1162 | register int n; | |
1163 | { | |
1164 | int mask; | |
f676886a JB |
1165 | register struct frame *f = updating_frame; |
1166 | int intborder = f->display.x->internal_border_width; | |
dc6f92b8 JB |
1167 | |
1168 | if (curs_y >= flexlines) | |
1169 | return; | |
1170 | ||
1171 | #ifndef HAVE_X11 | |
1172 | dumpqueue (); | |
c118dd06 | 1173 | #endif /* HAVE_X11 */ |
dc6f92b8 JB |
1174 | |
1175 | if ((curs_y + n) >= flexlines) | |
1176 | { | |
1177 | if (flexlines >= (curs_y + 1)) | |
1178 | { | |
1179 | #ifdef HAVE_X11 | |
c118dd06 | 1180 | XClearArea (x_current_display, FRAME_X_WINDOW (f), intborder, |
12ba150f | 1181 | CHAR_TO_PIXEL_ROW (f, curs_y), |
f676886a | 1182 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1183 | (flexlines - curs_y) * f->display.x->line_height, False); |
c118dd06 JB |
1184 | #else /* ! defined (HAVE_X11) */ |
1185 | XPixSet (FRAME_X_WINDOW (f), | |
12ba150f | 1186 | intborder, CHAR_TO_PIXEL_ROW (f, curs_y), |
f676886a | 1187 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1188 | (flexlines - curs_y) * f->display.x->line_height, |
f676886a | 1189 | f->display.x->background_pixel); |
c118dd06 | 1190 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
1191 | } |
1192 | } | |
1193 | else | |
1194 | { | |
1195 | #ifdef HAVE_X11 | |
c118dd06 JB |
1196 | XCopyArea (x_current_display, FRAME_X_WINDOW (f), |
1197 | FRAME_X_WINDOW (f), f->display.x->normal_gc, | |
dc6f92b8 | 1198 | intborder, |
12ba150f | 1199 | CHAR_TO_PIXEL_ROW (f, curs_y + n), |
f676886a | 1200 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1201 | (flexlines - (curs_y + n)) * f->display.x->line_height, |
12ba150f | 1202 | intborder, CHAR_TO_PIXEL_ROW (f, curs_y)); |
c118dd06 | 1203 | XClearArea (x_current_display, FRAME_X_WINDOW (f), |
dc6f92b8 | 1204 | intborder, |
12ba150f | 1205 | CHAR_TO_PIXEL_ROW (f, flexlines - n), |
f676886a | 1206 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1207 | n * f->display.x->line_height, False); |
c118dd06 JB |
1208 | #else /* ! defined (HAVE_X11) */ |
1209 | XMoveArea (FRAME_X_WINDOW (f), | |
dc6f92b8 | 1210 | intborder, |
12ba150f JB |
1211 | CHAR_TO_PIXEL_ROW (f, curs_y + n), |
1212 | intborder, CHAR_TO_PIXEL_ROW (f, curs_y), | |
f676886a | 1213 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1214 | (flexlines - (curs_y + n)) * f->display.x->line_height); |
dc6f92b8 JB |
1215 | /* Now we must process any ExposeRegion events that occur |
1216 | if the area being copied from is obscured. | |
1217 | We can't let it wait because further i/d operations | |
1218 | may want to copy this area to another area. */ | |
1219 | x_read_exposes (); | |
c118dd06 | 1220 | XPixSet (FRAME_X_WINDOW (f), intborder, |
12ba150f | 1221 | CHAR_TO_PIXEL_ROW (f, flexlines - n), |
f676886a | 1222 | f->width * FONT_WIDTH (f->display.x->font), |
a27f9f86 | 1223 | n * f->display.x->line_height, f->display.x->background_pixel); |
c118dd06 | 1224 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
1225 | } |
1226 | } | |
1227 | ||
1228 | /* Perform an insert-lines or delete-lines operation, | |
1229 | inserting N lines or deleting -N lines at vertical position VPOS. */ | |
1230 | ||
1231 | XTins_del_lines (vpos, n) | |
1232 | int vpos, n; | |
1233 | { | |
f676886a | 1234 | if (updating_frame == 0) |
dc6f92b8 JB |
1235 | abort (); |
1236 | ||
90e65f07 | 1237 | /* Hide the cursor. */ |
f676886a | 1238 | x_display_cursor (updating_frame, 0); |
dc6f92b8 JB |
1239 | |
1240 | XTcursor_to (vpos, 0); | |
1241 | ||
1242 | BLOCK_INPUT; | |
1243 | if (n >= 0) | |
1244 | stufflines (n); | |
1245 | else | |
1246 | scraplines (-n); | |
1247 | XFlushQueue (); | |
1248 | UNBLOCK_INPUT; | |
1249 | } | |
1250 | \f | |
f451eb13 | 1251 | /* Support routines for exposure events. */ |
dc6f92b8 JB |
1252 | static void clear_cursor (); |
1253 | ||
f676886a JB |
1254 | /* Output into a rectangle of an X-window (for frame F) |
1255 | the characters in f->phys_lines that overlap that rectangle. | |
dc6f92b8 | 1256 | TOP and LEFT are the position of the upper left corner of the rectangle. |
f94397b5 KH |
1257 | ROWS and COLS are the size of the rectangle. |
1258 | Call this function with input blocked. */ | |
dc6f92b8 JB |
1259 | |
1260 | static void | |
f676886a JB |
1261 | dumprectangle (f, left, top, cols, rows) |
1262 | struct frame *f; | |
dc6f92b8 JB |
1263 | register int left, top, cols, rows; |
1264 | { | |
f676886a | 1265 | register struct frame_glyphs *active_frame = FRAME_CURRENT_GLYPHS (f); |
dc6f92b8 JB |
1266 | int cursor_cleared = 0; |
1267 | int bottom, right; | |
1268 | register int y; | |
1269 | ||
f676886a | 1270 | if (FRAME_GARBAGED_P (f)) |
dc6f92b8 JB |
1271 | return; |
1272 | ||
dc6f92b8 JB |
1273 | /* Express rectangle as four edges, instead of position-and-size. */ |
1274 | bottom = top + rows; | |
1275 | right = left + cols; | |
1276 | ||
1277 | #ifndef HAVE_X11 /* Window manger does this for X11. */ | |
12ba150f JB |
1278 | { |
1279 | int intborder = f->display.x->internal_border_width; | |
1280 | ||
1281 | /* If the rectangle includes any of the internal border area, | |
1282 | redisplay the border emphasis. */ | |
1283 | if (top < intborder || left < intborder | |
a27f9f86 RS |
1284 | || bottom > intborder + f->height * f->display.x->line_height |
1285 | || right > intborder + f->width * f->display.x->line_height) | |
12ba150f JB |
1286 | dumpborder (f, 0); |
1287 | } | |
b8009dd1 | 1288 | #endif /* not HAVE_X11 Window manger does this for X11. */ |
dc6f92b8 JB |
1289 | |
1290 | /* Convert rectangle edges in pixels to edges in chars. | |
1291 | Round down for left and top, up for right and bottom. */ | |
12ba150f JB |
1292 | top = PIXEL_TO_CHAR_ROW (f, top); |
1293 | left = PIXEL_TO_CHAR_COL (f, left); | |
a27f9f86 | 1294 | bottom += (f->display.x->line_height - 1); |
f676886a | 1295 | right += (FONT_WIDTH (f->display.x->font) - 1); |
12ba150f JB |
1296 | bottom = PIXEL_TO_CHAR_ROW (f, bottom); |
1297 | right = PIXEL_TO_CHAR_COL (f, right); | |
dc6f92b8 JB |
1298 | |
1299 | /* Clip the rectangle to what can be visible. */ | |
1300 | if (left < 0) | |
1301 | left = 0; | |
1302 | if (top < 0) | |
1303 | top = 0; | |
f676886a JB |
1304 | if (right > f->width) |
1305 | right = f->width; | |
1306 | if (bottom > f->height) | |
1307 | bottom = f->height; | |
dc6f92b8 JB |
1308 | |
1309 | /* Get size in chars of the rectangle. */ | |
1310 | cols = right - left; | |
1311 | rows = bottom - top; | |
1312 | ||
1313 | /* If rectangle has zero area, return. */ | |
1314 | if (rows <= 0) return; | |
1315 | if (cols <= 0) return; | |
1316 | ||
1317 | /* Turn off the cursor if it is in the rectangle. | |
1318 | We will turn it back on afterward. */ | |
f676886a JB |
1319 | if ((f->phys_cursor_x >= left) && (f->phys_cursor_x < right) |
1320 | && (f->phys_cursor_y >= top) && (f->phys_cursor_y < bottom)) | |
dc6f92b8 | 1321 | { |
f676886a | 1322 | clear_cursor (f); |
dc6f92b8 JB |
1323 | cursor_cleared = 1; |
1324 | } | |
1325 | ||
1326 | /* Display the text in the rectangle, one text line at a time. */ | |
1327 | ||
1328 | for (y = top; y < bottom; y++) | |
1329 | { | |
f676886a | 1330 | GLYPH *line = &active_frame->glyphs[y][left]; |
dc6f92b8 | 1331 | |
f676886a | 1332 | if (! active_frame->enable[y] || left > active_frame->used[y]) |
dc6f92b8 JB |
1333 | continue; |
1334 | ||
f676886a | 1335 | dumpglyphs (f, |
12ba150f JB |
1336 | CHAR_TO_PIXEL_COL (f, left), |
1337 | CHAR_TO_PIXEL_ROW (f, y), | |
1338 | line, min (cols, active_frame->used[y] - left), | |
07e34cb0 | 1339 | active_frame->highlight[y]); |
dc6f92b8 JB |
1340 | } |
1341 | ||
1342 | /* Turn the cursor on if we turned it off. */ | |
1343 | ||
1344 | if (cursor_cleared) | |
f676886a | 1345 | x_display_cursor (f, 1); |
dc6f92b8 JB |
1346 | } |
1347 | ||
1348 | #ifndef HAVE_X11 | |
1349 | /* Process all queued ExposeRegion events. */ | |
1350 | ||
1351 | static void | |
1352 | dumpqueue () | |
1353 | { | |
1354 | register int i; | |
1355 | XExposeRegionEvent r; | |
1356 | ||
1357 | while (dequeue_event (&r, &x_expose_queue)) | |
1358 | { | |
f676886a JB |
1359 | struct frame *f = x_window_to_frame (r.window); |
1360 | if (f->display.x->icon_desc == r.window) | |
1361 | refreshicon (f); | |
dc6f92b8 | 1362 | else |
f676886a | 1363 | dumprectangle (f, r.x, r.y, r.width, r.height); |
dc6f92b8 JB |
1364 | } |
1365 | XFlushQueue (); | |
1366 | } | |
c118dd06 | 1367 | #endif /* HAVE_X11 */ |
dc6f92b8 | 1368 | \f |
f451eb13 | 1369 | /* Process all expose events that are pending, for X10. |
f676886a JB |
1370 | Redraws the cursor if necessary on any frame that |
1371 | is not in the process of being updated with update_frame. */ | |
dc6f92b8 | 1372 | |
f451eb13 | 1373 | #ifndef HAVE_X11 |
dc6f92b8 JB |
1374 | static void |
1375 | x_do_pending_expose () | |
1376 | { | |
1377 | int mask; | |
f676886a JB |
1378 | struct frame *f; |
1379 | Lisp_Object tail, frame; | |
dc6f92b8 JB |
1380 | |
1381 | if (expose_all_windows) | |
1382 | { | |
1383 | expose_all_windows = 0; | |
f676886a | 1384 | for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr) |
dc6f92b8 JB |
1385 | { |
1386 | register int temp_width, temp_height; | |
1387 | int intborder; | |
1388 | ||
f676886a | 1389 | frame = XCONS (tail)->car; |
ab648270 | 1390 | if (XGCTYPE (frame) != Lisp_Frame) |
dc6f92b8 | 1391 | continue; |
f676886a | 1392 | f = XFRAME (frame); |
b1c884c3 | 1393 | if (! FRAME_X_P (f)) |
dc6f92b8 | 1394 | continue; |
3a88c238 | 1395 | if (!f->async_visible) |
dc6f92b8 | 1396 | continue; |
f676886a | 1397 | if (!f->display.x->needs_exposure) |
dc6f92b8 JB |
1398 | continue; |
1399 | ||
f676886a | 1400 | intborder = f->display.x->internal_border_width; |
dc6f92b8 | 1401 | |
f676886a | 1402 | clear_cursor (f); |
c118dd06 | 1403 | XGetWindowInfo (FRAME_X_WINDOW (f), &windowinfo); |
dc6f92b8 | 1404 | temp_width = ((windowinfo.width - 2 * intborder |
ab648270 | 1405 | - f->display.x->v_scroll_bar_width) |
f676886a | 1406 | / FONT_WIDTH (f->display.x->font)); |
dc6f92b8 | 1407 | temp_height = ((windowinfo.height- 2 * intborder |
ab648270 | 1408 | - f->display.x->h_scroll_bar_height) |
a27f9f86 | 1409 | / f->display.x->line_height); |
f676886a | 1410 | if (temp_width != f->width || temp_height != f->height) |
dc6f92b8 | 1411 | { |
f676886a | 1412 | change_frame_size (f, max (1, temp_height), |
b1c884c3 | 1413 | max (1, temp_width), 0, 1); |
ab648270 | 1414 | x_resize_scroll_bars (f); |
dc6f92b8 | 1415 | } |
f676886a JB |
1416 | f->display.x->left_pos = windowinfo.x; |
1417 | f->display.x->top_pos = windowinfo.y; | |
1418 | dumprectangle (f, 0, 0, PIXEL_WIDTH (f), PIXEL_HEIGHT (f)); | |
dc6f92b8 | 1419 | #if 0 |
f676886a | 1420 | dumpborder (f, 0); |
c118dd06 | 1421 | #endif /* ! 0 */ |
f676886a JB |
1422 | f->display.x->needs_exposure = 0; |
1423 | if (updating_frame != f) | |
1424 | x_display_cursor (f, 1); | |
dc6f92b8 JB |
1425 | XFlushQueue (); |
1426 | } | |
1427 | } | |
1428 | else | |
1429 | /* Handle any individual-rectangle expose events queued | |
1430 | for various windows. */ | |
1431 | #ifdef HAVE_X11 | |
1432 | ; | |
c118dd06 | 1433 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 | 1434 | dumpqueue (); |
c118dd06 | 1435 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 | 1436 | } |
f451eb13 | 1437 | #endif |
dc6f92b8 JB |
1438 | |
1439 | #ifdef HAVE_X11 | |
1440 | static void | |
f676886a JB |
1441 | frame_highlight (frame) |
1442 | struct frame *frame; | |
dc6f92b8 | 1443 | { |
b3e1e05c JB |
1444 | /* We used to only do this if Vx_no_window_manager was non-nil, but |
1445 | the ICCCM (section 4.1.6) says that the window's border pixmap | |
1446 | and border pixel are window attributes which are "private to the | |
1447 | client", so we can always change it to whatever we want. */ | |
1448 | BLOCK_INPUT; | |
1449 | XSetWindowBorder (x_current_display, FRAME_X_WINDOW (frame), | |
1450 | frame->display.x->border_pixel); | |
1451 | UNBLOCK_INPUT; | |
f676886a | 1452 | x_display_cursor (frame, 1); |
dc6f92b8 JB |
1453 | } |
1454 | ||
1455 | static void | |
f676886a JB |
1456 | frame_unhighlight (frame) |
1457 | struct frame *frame; | |
dc6f92b8 | 1458 | { |
b3e1e05c JB |
1459 | /* We used to only do this if Vx_no_window_manager was non-nil, but |
1460 | the ICCCM (section 4.1.6) says that the window's border pixmap | |
1461 | and border pixel are window attributes which are "private to the | |
1462 | client", so we can always change it to whatever we want. */ | |
1463 | BLOCK_INPUT; | |
1464 | XSetWindowBorderPixmap (x_current_display, FRAME_X_WINDOW (frame), | |
1465 | frame->display.x->border_tile); | |
1466 | UNBLOCK_INPUT; | |
f676886a | 1467 | x_display_cursor (frame, 1); |
dc6f92b8 | 1468 | } |
c118dd06 | 1469 | #else /* ! defined (HAVE_X11) */ |
f676886a JB |
1470 | /* Dump the border-emphasis of frame F. |
1471 | If F is selected, this is a lining of the same color as the border, | |
dc6f92b8 | 1472 | just within the border, occupying a portion of the internal border. |
f676886a | 1473 | If F is not selected, it is background in the same place. |
dc6f92b8 JB |
1474 | If ALWAYS is 0, don't bother explicitly drawing if it's background. |
1475 | ||
f676886a | 1476 | ALWAYS = 1 is used when a frame becomes selected or deselected. |
dc6f92b8 JB |
1477 | In that case, we also turn the cursor off and on again |
1478 | so it will appear in the proper shape (solid if selected; else hollow.) */ | |
1479 | ||
1480 | static void | |
f676886a JB |
1481 | dumpborder (f, always) |
1482 | struct frame *f; | |
dc6f92b8 JB |
1483 | int always; |
1484 | { | |
f676886a JB |
1485 | int thickness = f->display.x->internal_border_width / 2; |
1486 | int width = PIXEL_WIDTH (f); | |
1487 | int height = PIXEL_HEIGHT (f); | |
dc6f92b8 JB |
1488 | int pixel; |
1489 | ||
f676886a | 1490 | if (f != selected_frame) |
dc6f92b8 JB |
1491 | { |
1492 | if (!always) | |
1493 | return; | |
1494 | ||
f676886a | 1495 | pixel = f->display.x->background_pixel; |
dc6f92b8 JB |
1496 | } |
1497 | else | |
1498 | { | |
f676886a | 1499 | pixel = f->display.x->border_pixel; |
dc6f92b8 JB |
1500 | } |
1501 | ||
c118dd06 JB |
1502 | XPixSet (FRAME_X_WINDOW (f), 0, 0, width, thickness, pixel); |
1503 | XPixSet (FRAME_X_WINDOW (f), 0, 0, thickness, height, pixel); | |
1504 | XPixSet (FRAME_X_WINDOW (f), 0, height - thickness, width, | |
dc6f92b8 | 1505 | thickness, pixel); |
c118dd06 | 1506 | XPixSet (FRAME_X_WINDOW (f), width - thickness, 0, thickness, |
dc6f92b8 JB |
1507 | height, pixel); |
1508 | ||
1509 | if (always) | |
f676886a | 1510 | x_display_cursor (f, 1); |
dc6f92b8 | 1511 | } |
c118dd06 | 1512 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 | 1513 | |
f676886a | 1514 | static void XTframe_rehighlight (); |
6d4238f3 | 1515 | |
f676886a JB |
1516 | /* The focus has changed. Update the frames as necessary to reflect |
1517 | the new situation. Note that we can't change the selected frame | |
dc6f92b8 | 1518 | here, because the lisp code we are interrupting might become confused. |
eb8c3be9 | 1519 | Each event gets marked with the frame in which it occurred, so the |
6d4238f3 | 1520 | lisp code can tell when the switch took place by examining the events. */ |
dc6f92b8 | 1521 | |
6d4238f3 | 1522 | static void |
f676886a JB |
1523 | x_new_focus_frame (frame) |
1524 | struct frame *frame; | |
dc6f92b8 | 1525 | { |
f676886a | 1526 | struct frame *old_focus = x_focus_frame; |
dc6f92b8 JB |
1527 | int events_enqueued = 0; |
1528 | ||
f676886a | 1529 | if (frame != x_focus_frame) |
dc6f92b8 | 1530 | { |
6d4238f3 | 1531 | /* Set this before calling other routines, so that they see |
f676886a JB |
1532 | the correct value of x_focus_frame. */ |
1533 | x_focus_frame = frame; | |
6d4238f3 JB |
1534 | |
1535 | if (old_focus && old_focus->auto_lower) | |
f676886a | 1536 | x_lower_frame (old_focus); |
dc6f92b8 JB |
1537 | |
1538 | #if 0 | |
f676886a JB |
1539 | selected_frame = frame; |
1540 | XSET (XWINDOW (selected_frame->selected_window)->frame, | |
1541 | Lisp_Frame, selected_frame); | |
1542 | Fselect_window (selected_frame->selected_window); | |
1543 | choose_minibuf_frame (); | |
c118dd06 | 1544 | #endif /* ! 0 */ |
dc6f92b8 | 1545 | |
f676886a JB |
1546 | if (x_focus_frame && x_focus_frame->auto_raise) |
1547 | x_raise_frame (x_focus_frame); | |
6d4238f3 | 1548 | } |
dc6f92b8 | 1549 | |
f676886a | 1550 | XTframe_rehighlight (); |
6d4238f3 JB |
1551 | } |
1552 | ||
1553 | ||
f451eb13 JB |
1554 | /* The focus has changed, or we have redirected a frame's focus to |
1555 | another frame (this happens when a frame uses a surrogate | |
1556 | minibuffer frame). Shift the highlight as appropriate. */ | |
6d4238f3 | 1557 | static void |
f676886a | 1558 | XTframe_rehighlight () |
6d4238f3 | 1559 | { |
f676886a | 1560 | struct frame *old_highlight = x_highlight_frame; |
6d4238f3 | 1561 | |
f676886a | 1562 | if (x_focus_frame) |
6d4238f3 | 1563 | { |
f451eb13 | 1564 | x_highlight_frame = |
ab648270 | 1565 | ((XGCTYPE (FRAME_FOCUS_FRAME (x_focus_frame)) == Lisp_Frame) |
f451eb13 JB |
1566 | ? XFRAME (FRAME_FOCUS_FRAME (x_focus_frame)) |
1567 | : x_focus_frame); | |
1568 | if (! FRAME_LIVE_P (x_highlight_frame)) | |
1569 | { | |
1570 | FRAME_FOCUS_FRAME (x_focus_frame) = Qnil; | |
1571 | x_highlight_frame = x_focus_frame; | |
1572 | } | |
dc6f92b8 | 1573 | } |
6d4238f3 | 1574 | else |
f676886a | 1575 | x_highlight_frame = 0; |
dc6f92b8 | 1576 | |
f676886a | 1577 | if (x_highlight_frame != old_highlight) |
6d4238f3 JB |
1578 | { |
1579 | if (old_highlight) | |
f676886a JB |
1580 | frame_unhighlight (old_highlight); |
1581 | if (x_highlight_frame) | |
1582 | frame_highlight (x_highlight_frame); | |
6d4238f3 | 1583 | } |
dc6f92b8 JB |
1584 | } |
1585 | \f | |
e4571a43 | 1586 | /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */ |
dc6f92b8 | 1587 | |
28430d3c JB |
1588 | /* Which modifier keys are on which modifier bits? |
1589 | ||
1590 | With each keystroke, X returns eight bits indicating which modifier | |
11edeb03 JB |
1591 | keys were held down when the key was pressed. The interpretation |
1592 | of the top five modifier bits depends on what keys are attached | |
28430d3c JB |
1593 | to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5 |
1594 | is the meta bit. | |
1595 | ||
1596 | x_meta_mod_mask is a mask containing the bits used for the meta key. | |
1597 | It may have more than one bit set, if more than one modifier bit | |
1598 | has meta keys on it. Basically, if EVENT is a KeyPress event, | |
11edeb03 JB |
1599 | the meta key is pressed if (EVENT.state & x_meta_mod_mask) != 0. |
1600 | ||
1601 | x_shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the | |
1602 | lock modifier bit, or zero otherwise. Non-alphabetic keys should | |
1603 | only be affected by the lock modifier bit if XK_Shift_Lock is in | |
1604 | use; XK_Caps_Lock should only affect alphabetic keys. With this | |
1605 | arrangement, the lock modifier should shift the character if | |
1606 | (EVENT.state & x_shift_lock_mask) != 0. */ | |
1607 | static int x_meta_mod_mask, x_shift_lock_mask; | |
28430d3c | 1608 | |
a3c44b14 RS |
1609 | /* These are like x_meta_mod_mask, but for different modifiers. */ |
1610 | static int x_alt_mod_mask, x_super_mod_mask, x_hyper_mod_mask; | |
1611 | ||
28430d3c JB |
1612 | /* Initialize mode_switch_bit and modifier_meaning. */ |
1613 | static void | |
1614 | x_find_modifier_meanings () | |
1615 | { | |
f689eb05 | 1616 | int min_code, max_code; |
28430d3c JB |
1617 | KeySym *syms; |
1618 | int syms_per_code; | |
1619 | XModifierKeymap *mods; | |
1620 | ||
1621 | x_meta_mod_mask = 0; | |
11edeb03 | 1622 | x_shift_lock_mask = 0; |
a3c44b14 RS |
1623 | x_alt_mod_mask = 0; |
1624 | x_super_mod_mask = 0; | |
1625 | x_hyper_mod_mask = 0; | |
28430d3c | 1626 | |
9658a521 | 1627 | #ifdef HAVE_X11R4 |
28430d3c | 1628 | XDisplayKeycodes (x_current_display, &min_code, &max_code); |
9658a521 JB |
1629 | #else |
1630 | min_code = x_current_display->min_keycode; | |
1631 | max_code = x_current_display->max_keycode; | |
1632 | #endif | |
1633 | ||
28430d3c JB |
1634 | syms = XGetKeyboardMapping (x_current_display, |
1635 | min_code, max_code - min_code + 1, | |
1636 | &syms_per_code); | |
1637 | mods = XGetModifierMapping (x_current_display); | |
1638 | ||
11edeb03 JB |
1639 | /* Scan the modifier table to see which modifier bits the Meta and |
1640 | Alt keysyms are on. */ | |
28430d3c JB |
1641 | { |
1642 | int row, col; /* The row and column in the modifier table. */ | |
1643 | ||
1644 | for (row = 3; row < 8; row++) | |
1645 | for (col = 0; col < mods->max_keypermod; col++) | |
1646 | { | |
1647 | KeyCode code = | |
1648 | mods->modifiermap[(row * mods->max_keypermod) + col]; | |
1649 | ||
af92970c KH |
1650 | /* Zeroes are used for filler. Skip them. */ |
1651 | if (code == 0) | |
1652 | continue; | |
1653 | ||
28430d3c JB |
1654 | /* Are any of this keycode's keysyms a meta key? */ |
1655 | { | |
1656 | int code_col; | |
1657 | ||
1658 | for (code_col = 0; code_col < syms_per_code; code_col++) | |
1659 | { | |
f689eb05 | 1660 | int sym = syms[((code - min_code) * syms_per_code) + code_col]; |
28430d3c | 1661 | |
f689eb05 | 1662 | switch (sym) |
28430d3c | 1663 | { |
f689eb05 JB |
1664 | case XK_Meta_L: |
1665 | case XK_Meta_R: | |
28430d3c JB |
1666 | x_meta_mod_mask |= (1 << row); |
1667 | break; | |
f689eb05 JB |
1668 | |
1669 | case XK_Alt_L: | |
1670 | case XK_Alt_R: | |
a3c44b14 RS |
1671 | x_alt_mod_mask |= (1 << row); |
1672 | break; | |
1673 | ||
1674 | case XK_Hyper_L: | |
1675 | case XK_Hyper_R: | |
1676 | x_hyper_mod_mask |= (1 << row); | |
1677 | break; | |
1678 | ||
1679 | case XK_Super_L: | |
1680 | case XK_Super_R: | |
1681 | x_super_mod_mask |= (1 << row); | |
f689eb05 | 1682 | break; |
11edeb03 JB |
1683 | |
1684 | case XK_Shift_Lock: | |
1685 | /* Ignore this if it's not on the lock modifier. */ | |
1686 | if ((1 << row) == LockMask) | |
1687 | x_shift_lock_mask = LockMask; | |
1688 | break; | |
28430d3c JB |
1689 | } |
1690 | } | |
1691 | } | |
1692 | } | |
1693 | } | |
1694 | ||
f689eb05 JB |
1695 | /* If we couldn't find any meta keys, accept any alt keys as meta keys. */ |
1696 | if (! x_meta_mod_mask) | |
a3c44b14 RS |
1697 | { |
1698 | x_meta_mod_mask = x_alt_mod_mask; | |
1699 | x_alt_mod_mask = 0; | |
1700 | } | |
f689eb05 | 1701 | |
148c4b70 RS |
1702 | /* If some keys are both alt and meta, |
1703 | make them just meta, not alt. */ | |
1704 | if (x_alt_mod_mask & x_meta_mod_mask) | |
1705 | { | |
1706 | x_alt_mod_mask &= ~x_meta_mod_mask; | |
1707 | } | |
1708 | ||
28430d3c | 1709 | XFree ((char *) syms); |
f689eb05 | 1710 | XFreeModifiermap (mods); |
28430d3c JB |
1711 | } |
1712 | ||
dfeccd2d JB |
1713 | /* Convert between the modifier bits X uses and the modifier bits |
1714 | Emacs uses. */ | |
7c5283e4 | 1715 | static unsigned int |
dfeccd2d | 1716 | x_x_to_emacs_modifiers (state) |
dc6f92b8 JB |
1717 | unsigned int state; |
1718 | { | |
11edeb03 JB |
1719 | return ( ((state & (ShiftMask | x_shift_lock_mask)) ? shift_modifier : 0) |
1720 | | ((state & ControlMask) ? ctrl_modifier : 0) | |
a3c44b14 RS |
1721 | | ((state & x_meta_mod_mask) ? meta_modifier : 0) |
1722 | | ((state & x_alt_mod_mask) ? alt_modifier : 0) | |
1723 | | ((state & x_super_mod_mask) ? super_modifier : 0) | |
1724 | | ((state & x_hyper_mod_mask) ? hyper_modifier : 0)); | |
dc6f92b8 JB |
1725 | } |
1726 | ||
dfeccd2d JB |
1727 | static unsigned int |
1728 | x_emacs_to_x_modifiers (state) | |
1729 | unsigned int state; | |
1730 | { | |
1731 | return ( ((state & alt_modifier) ? x_alt_mod_mask : 0) | |
1732 | | ((state & super_modifier) ? x_super_mod_mask : 0) | |
1733 | | ((state & hyper_modifier) ? x_hyper_mod_mask : 0) | |
1734 | | ((state & shift_modifier) ? ShiftMask : 0) | |
1735 | | ((state & ctrl_modifier) ? ControlMask : 0) | |
1736 | | ((state & meta_modifier) ? x_meta_mod_mask : 0)); | |
1737 | } | |
1738 | ||
e4571a43 JB |
1739 | /* Return true iff KEYSYM is a vendor-specific keysym that we should |
1740 | return as a function key. If you add a keysym to this, you should | |
1741 | make sure that the tables make_lispy_event uses contain a suitable | |
1742 | name for it. */ | |
1743 | static int | |
1744 | x_is_vendor_fkey (sym) | |
1745 | KeySym sym; | |
1746 | { | |
1747 | return 0 | |
1748 | #ifdef DXK_Remove | |
1749 | || (sym == DXK_Remove) | |
1750 | #endif | |
1751 | ; | |
1752 | } | |
1753 | ||
1754 | \f | |
1755 | /* Mouse clicks and mouse movement. Rah. */ | |
1756 | #ifdef HAVE_X11 | |
1757 | ||
1758 | /* Given a pixel position (PIX_X, PIX_Y) on the frame F, return | |
1759 | glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle | |
69388238 RS |
1760 | that the glyph at X, Y occupies, if BOUNDS != 0. |
1761 | If NOCLIP is nonzero, do not force the value into range. */ | |
1762 | ||
c8dba240 | 1763 | void |
69388238 | 1764 | pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip) |
e4571a43 | 1765 | FRAME_PTR f; |
69388238 | 1766 | register int pix_x, pix_y; |
e4571a43 JB |
1767 | register int *x, *y; |
1768 | XRectangle *bounds; | |
69388238 | 1769 | int noclip; |
e4571a43 | 1770 | { |
69388238 RS |
1771 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down |
1772 | even for negative values. */ | |
1773 | if (pix_x < 0) | |
1774 | pix_x -= FONT_WIDTH ((f)->display.x->font) - 1; | |
1775 | if (pix_y < 0) | |
a27f9f86 | 1776 | pix_y -= (f)->display.x->line_height - 1; |
69388238 | 1777 | |
e4571a43 JB |
1778 | pix_x = PIXEL_TO_CHAR_COL (f, pix_x); |
1779 | pix_y = PIXEL_TO_CHAR_ROW (f, pix_y); | |
1780 | ||
1781 | if (bounds) | |
1782 | { | |
1783 | bounds->width = FONT_WIDTH (f->display.x->font); | |
a27f9f86 | 1784 | bounds->height = f->display.x->line_height; |
e4571a43 JB |
1785 | bounds->x = CHAR_TO_PIXEL_COL (f, pix_x); |
1786 | bounds->y = CHAR_TO_PIXEL_ROW (f, pix_y); | |
1787 | } | |
1788 | ||
69388238 RS |
1789 | if (!noclip) |
1790 | { | |
1791 | if (pix_x < 0) | |
1792 | pix_x = 0; | |
1793 | else if (pix_x > f->width) | |
1794 | pix_x = f->width; | |
1795 | ||
1796 | if (pix_y < 0) | |
1797 | pix_y = 0; | |
1798 | else if (pix_y > f->height) | |
1799 | pix_y = f->height; | |
1800 | } | |
e4571a43 JB |
1801 | |
1802 | *x = pix_x; | |
1803 | *y = pix_y; | |
1804 | } | |
1805 | ||
2b5c9e71 RS |
1806 | void |
1807 | glyph_to_pixel_coords (f, x, y, pix_x, pix_y) | |
1808 | FRAME_PTR f; | |
1809 | register int x, y; | |
1810 | register int *pix_x, *pix_y; | |
1811 | { | |
1812 | *pix_x = CHAR_TO_PIXEL_COL (f, x); | |
1813 | *pix_y = CHAR_TO_PIXEL_ROW (f, y); | |
1814 | } | |
1815 | ||
dc6f92b8 JB |
1816 | /* Prepare a mouse-event in *RESULT for placement in the input queue. |
1817 | ||
1818 | If the event is a button press, then note that we have grabbed | |
f451eb13 | 1819 | the mouse. */ |
dc6f92b8 JB |
1820 | |
1821 | static Lisp_Object | |
f451eb13 | 1822 | construct_mouse_click (result, event, f) |
dc6f92b8 JB |
1823 | struct input_event *result; |
1824 | XButtonEvent *event; | |
f676886a | 1825 | struct frame *f; |
dc6f92b8 | 1826 | { |
f451eb13 | 1827 | /* Make the event type no_event; we'll change that when we decide |
dc6f92b8 | 1828 | otherwise. */ |
f451eb13 | 1829 | result->kind = mouse_click; |
69388238 | 1830 | result->code = event->button - Button1; |
1113d9db | 1831 | result->timestamp = event->time; |
dfeccd2d | 1832 | result->modifiers = (x_x_to_emacs_modifiers (event->state) |
f689eb05 JB |
1833 | | (event->type == ButtonRelease |
1834 | ? up_modifier | |
1835 | : down_modifier)); | |
dc6f92b8 JB |
1836 | |
1837 | /* Notice if the mouse is still grabbed. */ | |
1838 | if (event->type == ButtonPress) | |
1839 | { | |
1840 | if (! x_mouse_grabbed) | |
1841 | Vmouse_depressed = Qt; | |
90e65f07 | 1842 | x_mouse_grabbed |= (1 << event->button); |
69388238 | 1843 | last_mouse_frame = f; |
dc6f92b8 JB |
1844 | } |
1845 | else if (event->type == ButtonRelease) | |
1846 | { | |
90e65f07 | 1847 | x_mouse_grabbed &= ~(1 << event->button); |
dc6f92b8 JB |
1848 | if (!x_mouse_grabbed) |
1849 | Vmouse_depressed = Qnil; | |
1850 | } | |
1851 | ||
f451eb13 JB |
1852 | { |
1853 | int row, column; | |
dc6f92b8 | 1854 | |
2b5c9e71 | 1855 | #if 0 |
69388238 | 1856 | pixel_to_glyph_coords (f, event->x, event->y, &column, &row, NULL, 0); |
f451eb13 JB |
1857 | XFASTINT (result->x) = column; |
1858 | XFASTINT (result->y) = row; | |
2b5c9e71 | 1859 | #endif |
09fe4c31 RS |
1860 | XSET (result->x, Lisp_Int, event->x); |
1861 | XSET (result->y, Lisp_Int, event->y); | |
12ba150f | 1862 | XSET (result->frame_or_window, Lisp_Frame, f); |
f451eb13 | 1863 | } |
dc6f92b8 | 1864 | } |
b849c413 RS |
1865 | |
1866 | /* Prepare a menu-event in *RESULT for placement in the input queue. */ | |
1867 | ||
1868 | static Lisp_Object | |
1869 | construct_menu_click (result, event, f) | |
1870 | struct input_event *result; | |
1871 | XButtonEvent *event; | |
1872 | struct frame *f; | |
1873 | { | |
1874 | /* Make the event type no_event; we'll change that when we decide | |
1875 | otherwise. */ | |
1876 | result->kind = mouse_click; | |
1877 | XSET (result->code, Lisp_Int, event->button - Button1); | |
1878 | result->timestamp = event->time; | |
1879 | result->modifiers = (x_x_to_emacs_modifiers (event->state) | |
1880 | | (event->type == ButtonRelease | |
1881 | ? up_modifier | |
1882 | : down_modifier)); | |
1883 | ||
09fe4c31 RS |
1884 | XSET (result->x, Lisp_Int, event->x); |
1885 | XSET (result->y, Lisp_Int, -1); | |
c8dba240 | 1886 | XSET (result->frame_or_window, Lisp_Frame, f); |
b849c413 | 1887 | } |
69388238 | 1888 | \f |
90e65f07 JB |
1889 | /* Function to report a mouse movement to the mainstream Emacs code. |
1890 | The input handler calls this. | |
1891 | ||
1892 | We have received a mouse movement event, which is given in *event. | |
1893 | If the mouse is over a different glyph than it was last time, tell | |
1894 | the mainstream emacs code by setting mouse_moved. If not, ask for | |
1895 | another motion event, so we can check again the next time it moves. */ | |
b8009dd1 | 1896 | |
90e65f07 | 1897 | static void |
12ba150f | 1898 | note_mouse_movement (frame, event) |
f676886a | 1899 | FRAME_PTR frame; |
90e65f07 JB |
1900 | XMotionEvent *event; |
1901 | ||
1902 | { | |
e5d77022 JB |
1903 | last_mouse_movement_time = event->time; |
1904 | ||
90e65f07 JB |
1905 | /* Has the mouse moved off the glyph it was on at the last sighting? */ |
1906 | if (event->x < last_mouse_glyph.x | |
1907 | || event->x >= last_mouse_glyph.x + last_mouse_glyph.width | |
1908 | || event->y < last_mouse_glyph.y | |
1909 | || event->y >= last_mouse_glyph.y + last_mouse_glyph.height) | |
12ba150f JB |
1910 | { |
1911 | mouse_moved = 1; | |
ab648270 | 1912 | last_mouse_scroll_bar = Qnil; |
b8009dd1 RS |
1913 | |
1914 | note_mouse_highlight (frame, event->x, event->y); | |
1915 | ||
1916 | /* Ask for another mouse motion event. */ | |
1917 | { | |
1918 | int dummy; | |
1919 | ||
1920 | XQueryPointer (event->display, event->window, | |
1921 | (Window *) &dummy, (Window *) &dummy, | |
1922 | &dummy, &dummy, &dummy, &dummy, | |
1923 | (unsigned int *) &dummy); | |
1924 | } | |
12ba150f | 1925 | } |
90e65f07 JB |
1926 | else |
1927 | { | |
1928 | /* It's on the same glyph. Call XQueryPointer so we'll get an | |
1929 | event the next time the mouse moves and we can see if it's | |
1930 | *still* on the same glyph. */ | |
1931 | int dummy; | |
1932 | ||
1933 | XQueryPointer (event->display, event->window, | |
1934 | (Window *) &dummy, (Window *) &dummy, | |
1935 | &dummy, &dummy, &dummy, &dummy, | |
1936 | (unsigned int *) &dummy); | |
1937 | } | |
1938 | } | |
1939 | ||
bf1c0ba1 RS |
1940 | /* This is used for debugging, to turn off note_mouse_highlight. */ |
1941 | static int disable_mouse_highlight; | |
1942 | ||
b8009dd1 RS |
1943 | /* Take proper action when the mouse has moved to position X, Y on frame F |
1944 | as regards highlighting characters that have mouse-face properties. | |
1945 | Also dehighlighting chars where the mouse was before. */ | |
1946 | ||
1947 | static void | |
1948 | note_mouse_highlight (f, x, y) | |
1949 | FRAME_PTR f; | |
1950 | { | |
1951 | int row, column, portion; | |
1952 | XRectangle new_glyph; | |
1953 | Lisp_Object window; | |
1954 | struct window *w; | |
1955 | ||
bf1c0ba1 RS |
1956 | if (disable_mouse_highlight) |
1957 | return; | |
1958 | ||
b8009dd1 RS |
1959 | mouse_face_mouse_x = x; |
1960 | mouse_face_mouse_y = y; | |
1961 | mouse_face_mouse_frame = f; | |
1962 | ||
1963 | if (mouse_face_defer) | |
1964 | return; | |
1965 | ||
514e4681 RS |
1966 | if (gc_in_progress) |
1967 | { | |
1968 | mouse_face_deferred_gc = 1; | |
1969 | return; | |
1970 | } | |
1971 | ||
b8009dd1 RS |
1972 | /* Find out which glyph the mouse is on. */ |
1973 | pixel_to_glyph_coords (f, x, y, &column, &row, | |
1974 | &new_glyph, x_mouse_grabbed); | |
1975 | ||
1976 | /* Which window is that in? */ | |
1977 | window = window_from_coordinates (f, column, row, &portion); | |
1978 | w = XWINDOW (window); | |
1979 | ||
1980 | /* If we were displaying active text in another window, clear that. */ | |
1981 | if (! EQ (window, mouse_face_window)) | |
1982 | clear_mouse_face (); | |
1983 | ||
1984 | /* Are we in a window whose display is up to date? */ | |
1985 | if (WINDOWP (window) && portion == 0 | |
e444162e | 1986 | && EQ (w->window_end_valid, w->buffer)) |
b8009dd1 RS |
1987 | { |
1988 | int *ptr = FRAME_CURRENT_GLYPHS (f)->charstarts[row]; | |
1989 | int i, pos; | |
1990 | ||
1991 | /* Find which buffer position the mouse corresponds to. */ | |
1992 | for (i = column; i >= 0; i--) | |
1993 | if (ptr[i] > 0) | |
1994 | break; | |
1995 | pos = ptr[i]; | |
1996 | /* Is it outside the displayed active region (if any)? */ | |
1997 | if (pos > 0 | |
1998 | && ! (EQ (window, mouse_face_window) | |
1999 | && pos >= mouse_face_beg && pos < mouse_face_end)) | |
2000 | { | |
2001 | Lisp_Object mouse_face, overlay, position; | |
2002 | Lisp_Object *overlay_vec; | |
2003 | int len, noverlays, ignor1; | |
f8bdb8e6 | 2004 | struct buffer *obuf; |
e444162e | 2005 | int obegv, ozv; |
f8bdb8e6 | 2006 | |
e444162e RS |
2007 | /* If we get an out-of-range value, return now; avoid an error. */ |
2008 | if (pos > BUF_Z (XBUFFER (w->buffer))) | |
f8bdb8e6 | 2009 | return; |
b8009dd1 | 2010 | |
09fe4c31 RS |
2011 | /* Make the window's buffer temporarily current for |
2012 | overlays_at and compute_char_face. */ | |
f8bdb8e6 | 2013 | obuf = current_buffer; |
09fe4c31 | 2014 | current_buffer = XBUFFER (w->buffer); |
e444162e RS |
2015 | obegv = BEGV; |
2016 | ozv = ZV; | |
2017 | BEGV = BEG; | |
2018 | ZV = Z; | |
09fe4c31 | 2019 | |
b8009dd1 RS |
2020 | /* Yes. Clear the display of the old active region, if any. */ |
2021 | clear_mouse_face (); | |
2022 | ||
2023 | /* Is this char mouse-active? */ | |
2024 | XSET (position, Lisp_Int, pos); | |
2025 | ||
2026 | len = 10; | |
2027 | overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); | |
2028 | ||
2029 | /* Put all the overlays we want in a vector in overlay_vec. | |
2030 | Store the length in len. */ | |
2031 | noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, &ignor1); | |
09fe4c31 | 2032 | noverlays = sort_overlays (overlay_vec, noverlays, w); |
b8009dd1 RS |
2033 | |
2034 | /* Find the highest priority overlay that has a mouse-face prop. */ | |
2035 | overlay = Qnil; | |
2036 | for (i = 0; i < noverlays; i++) | |
2037 | { | |
2038 | mouse_face = Foverlay_get (overlay_vec[i], Qmouse_face); | |
2039 | if (!NILP (mouse_face)) | |
2040 | { | |
2041 | overlay = overlay_vec[i]; | |
2042 | break; | |
2043 | } | |
2044 | } | |
2045 | free (overlay_vec); | |
2046 | /* If no overlay applies, get a text property. */ | |
2047 | if (NILP (overlay)) | |
2048 | mouse_face = Fget_text_property (position, Qmouse_face, w->buffer); | |
2049 | ||
2050 | /* Handle the overlay case. */ | |
2051 | if (! NILP (overlay)) | |
2052 | { | |
2053 | /* Find the range of text around this char that | |
2054 | should be active. */ | |
2055 | Lisp_Object before, after; | |
2056 | int ignore; | |
2057 | ||
2058 | before = Foverlay_start (overlay); | |
2059 | after = Foverlay_end (overlay); | |
2060 | /* Record this as the current active region. */ | |
2061 | mouse_face_beg = XFASTINT (before); | |
2062 | mouse_face_end = XFASTINT (after); | |
2063 | mouse_face_window = window; | |
2064 | mouse_face_face_id = compute_char_face (f, w, pos, 0, 0, | |
2065 | &ignore, pos + 1, 1); | |
2066 | ||
2067 | /* Display it as active. */ | |
2068 | show_mouse_face (1); | |
2069 | } | |
2070 | /* Handle the text property case. */ | |
2071 | else if (! NILP (mouse_face)) | |
2072 | { | |
2073 | /* Find the range of text around this char that | |
2074 | should be active. */ | |
2075 | Lisp_Object before, after, beginning, end; | |
2076 | int ignore; | |
2077 | ||
2078 | beginning = Fmarker_position (w->start); | |
2079 | XSET (end, Lisp_Int, | |
09fe4c31 | 2080 | (BUF_Z (XBUFFER (w->buffer)) |
b8009dd1 RS |
2081 | - XFASTINT (w->window_end_pos))); |
2082 | before | |
2083 | = Fprevious_single_property_change (make_number (pos + 1), | |
2084 | Qmouse_face, | |
2085 | w->buffer, beginning); | |
2086 | after | |
2087 | = Fnext_single_property_change (position, Qmouse_face, | |
2088 | w->buffer, end); | |
2089 | /* Record this as the current active region. */ | |
2090 | mouse_face_beg = XFASTINT (before); | |
2091 | mouse_face_end = XFASTINT (after); | |
2092 | mouse_face_window = window; | |
2093 | mouse_face_face_id | |
2094 | = compute_char_face (f, w, pos, 0, 0, | |
2095 | &ignore, pos + 1, 1); | |
2096 | ||
2097 | /* Display it as active. */ | |
2098 | show_mouse_face (1); | |
2099 | } | |
e444162e RS |
2100 | BEGV = obegv; |
2101 | ZV = ozv; | |
09fe4c31 | 2102 | current_buffer = obuf; |
b8009dd1 RS |
2103 | } |
2104 | else if (pos <= 0) | |
2105 | clear_mouse_face (); | |
2106 | } | |
2107 | } | |
2108 | \f | |
2109 | /* Find the row and column of position POS in window WINDOW. | |
2110 | Store them in *COLUMNP and *ROWP. | |
bf1c0ba1 RS |
2111 | This assumes display in WINDOW is up to date. |
2112 | If POS is above start of WINDOW, return coords | |
2113 | of start of first screen line. | |
2114 | If POS is after end of WINDOW, return coords of end of last screen line. */ | |
b8009dd1 RS |
2115 | |
2116 | static int | |
2117 | fast_find_position (window, pos, columnp, rowp) | |
2118 | Lisp_Object window; | |
2119 | int pos; | |
2120 | int *columnp, *rowp; | |
2121 | { | |
2122 | struct window *w = XWINDOW (window); | |
2123 | FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); | |
2124 | int i; | |
2125 | int row; | |
2126 | int left = w->left; | |
2127 | int top = w->top; | |
2128 | int height = XFASTINT (w->height) - ! MINI_WINDOW_P (w); | |
2129 | int width = window_internal_width (w); | |
2130 | int *charstarts; | |
bf1c0ba1 | 2131 | int lastcol; |
b8009dd1 RS |
2132 | |
2133 | for (i = 0; | |
2134 | i < height; | |
2135 | i++) | |
2136 | { | |
2137 | int linestart = FRAME_CURRENT_GLYPHS (f)->charstarts[top + i][left]; | |
2138 | if (linestart > pos) | |
2139 | break; | |
2140 | if (linestart > 0) | |
2141 | row = i; | |
2142 | } | |
2143 | ||
2144 | charstarts = FRAME_CURRENT_GLYPHS (f)->charstarts[top + row]; | |
bf1c0ba1 | 2145 | lastcol = left; |
b8009dd1 | 2146 | for (i = 0; i < width; i++) |
bf1c0ba1 RS |
2147 | { |
2148 | if (charstarts[left + i] == pos) | |
2149 | { | |
2150 | *rowp = row + top; | |
2151 | *columnp = i + left; | |
2152 | return 1; | |
2153 | } | |
2154 | else if (charstarts[left + i] > pos) | |
2155 | lastcol = left + i; | |
2156 | } | |
b8009dd1 | 2157 | |
bf1c0ba1 RS |
2158 | *rowp = row + top; |
2159 | *columnp = lastcol; | |
b8009dd1 RS |
2160 | return 0; |
2161 | } | |
2162 | ||
2163 | /* Display the active region described by mouse_face_* | |
2164 | in its mouse-face if HL > 0, in its normal face if HL = 0. */ | |
2165 | ||
2166 | static void | |
2167 | show_mouse_face (hl) | |
2168 | int hl; | |
2169 | { | |
2170 | int begcol, begrow, endcol, endrow; | |
2171 | struct window *w = XWINDOW (mouse_face_window); | |
2172 | int width = window_internal_width (w); | |
2173 | FRAME_PTR f = XFRAME (WINDOW_FRAME (w)); | |
2174 | int i; | |
514e4681 RS |
2175 | int curs_x = f->phys_cursor_x; |
2176 | int curs_y = f->phys_cursor_y; | |
2177 | int cursor_off = 0; | |
b8009dd1 RS |
2178 | |
2179 | fast_find_position (mouse_face_window, mouse_face_beg, | |
2180 | &begcol, &begrow); | |
2181 | fast_find_position (mouse_face_window, mouse_face_end, | |
2182 | &endcol, &endrow); | |
2183 | ||
b8009dd1 RS |
2184 | for (i = begrow; i <= endrow; i++) |
2185 | { | |
2186 | int column = (i == begrow ? begcol : w->left); | |
2187 | int endcolumn = (i == endrow ? endcol : w->left + width); | |
514e4681 RS |
2188 | endcolumn = min (endcolumn, FRAME_CURRENT_GLYPHS (f)->used[i] - w->left); |
2189 | ||
2190 | /* If the cursor's in the text we are about to rewrite, | |
2191 | turn the cursor off. */ | |
2192 | if (i == curs_y | |
2193 | && (curs_x >= begrow - 1 || curs_x <= endrow)) | |
2194 | { | |
2195 | x_display_cursor (f, 0); | |
2196 | cursor_off = 1; | |
2197 | } | |
b8009dd1 RS |
2198 | |
2199 | dumpglyphs (f, | |
2200 | CHAR_TO_PIXEL_COL (f, column), | |
2201 | CHAR_TO_PIXEL_ROW (f, i), | |
2202 | FRAME_CURRENT_GLYPHS (f)->glyphs[i] + column, | |
2203 | endcolumn - column, | |
2204 | /* Highlight with mouse face if hl > 0. */ | |
2205 | hl > 0 ? 3 : 0); | |
2206 | } | |
2207 | ||
514e4681 RS |
2208 | /* If we turned the cursor off, turn it back on. */ |
2209 | if (cursor_off) | |
2210 | x_display_cursor (f, 1); | |
27ead1d5 FP |
2211 | |
2212 | /* Change the mouse cursor according to the value of HL. */ | |
2213 | if (hl > 0) | |
2214 | XDefineCursor (XDISPLAY FRAME_X_WINDOW (f), f->display.x->cross_cursor); | |
2215 | else | |
2216 | XDefineCursor (XDISPLAY FRAME_X_WINDOW (f), f->display.x->text_cursor); | |
b8009dd1 RS |
2217 | } |
2218 | ||
2219 | /* Clear out the mouse-highlighted active region. | |
2220 | Redraw it unhighlighted first. */ | |
2221 | ||
2222 | static void | |
2223 | clear_mouse_face () | |
2224 | { | |
2225 | if (! NILP (mouse_face_window)) | |
2226 | show_mouse_face (0); | |
2227 | ||
2228 | mouse_face_beg = -1; | |
2229 | mouse_face_end = -1; | |
2230 | mouse_face_window = Qnil; | |
2231 | } | |
2232 | \f | |
ab648270 JB |
2233 | static struct scroll_bar *x_window_to_scroll_bar (); |
2234 | static void x_scroll_bar_report_motion (); | |
12ba150f | 2235 | |
90e65f07 JB |
2236 | /* Return the current position of the mouse. |
2237 | ||
ab648270 JB |
2238 | If the mouse movement started in a scroll bar, set *f, *bar_window, |
2239 | and *part to the frame, window, and scroll bar part that the mouse | |
12ba150f | 2240 | is over. Set *x and *y to the portion and whole of the mouse's |
ab648270 | 2241 | position on the scroll bar. |
12ba150f JB |
2242 | |
2243 | If the mouse movement started elsewhere, set *f to the frame the | |
2244 | mouse is on, *bar_window to nil, and *x and *y to the character cell | |
2245 | the mouse is over. | |
2246 | ||
2247 | Set *time to the server timestamp for the time at which the mouse | |
2248 | was at this position. | |
2249 | ||
a135645a RS |
2250 | Don't store anything if we don't have a valid set of values to report. |
2251 | ||
90e65f07 | 2252 | This clears the mouse_moved flag, so we can wait for the next mouse |
12ba150f JB |
2253 | movement. This also calls XQueryPointer, which will cause the |
2254 | server to give us another MotionNotify when the mouse moves | |
2255 | again. */ | |
90e65f07 JB |
2256 | |
2257 | static void | |
12ba150f | 2258 | XTmouse_position (f, bar_window, part, x, y, time) |
472895ad | 2259 | FRAME_PTR *f; |
12ba150f | 2260 | Lisp_Object *bar_window; |
ab648270 | 2261 | enum scroll_bar_part *part; |
90e65f07 | 2262 | Lisp_Object *x, *y; |
e5d77022 | 2263 | unsigned long *time; |
90e65f07 | 2264 | { |
a135645a RS |
2265 | FRAME_PTR f1; |
2266 | ||
90e65f07 JB |
2267 | BLOCK_INPUT; |
2268 | ||
ab648270 JB |
2269 | if (! NILP (last_mouse_scroll_bar)) |
2270 | x_scroll_bar_report_motion (f, bar_window, part, x, y, time); | |
90e65f07 JB |
2271 | else |
2272 | { | |
12ba150f JB |
2273 | Window root; |
2274 | int root_x, root_y; | |
90e65f07 | 2275 | |
12ba150f JB |
2276 | Window dummy_window; |
2277 | int dummy; | |
2278 | ||
2279 | mouse_moved = 0; | |
ab648270 | 2280 | last_mouse_scroll_bar = Qnil; |
12ba150f JB |
2281 | |
2282 | /* Figure out which root window we're on. */ | |
2283 | XQueryPointer (x_current_display, | |
2284 | DefaultRootWindow (x_current_display), | |
2285 | ||
2286 | /* The root window which contains the pointer. */ | |
2287 | &root, | |
2288 | ||
2289 | /* Trash which we can't trust if the pointer is on | |
2290 | a different screen. */ | |
2291 | &dummy_window, | |
2292 | ||
2293 | /* The position on that root window. */ | |
2294 | &root_x, &root_y, | |
2295 | ||
2296 | /* More trash we can't trust. */ | |
2297 | &dummy, &dummy, | |
2298 | ||
2299 | /* Modifier keys and pointer buttons, about which | |
2300 | we don't care. */ | |
2301 | (unsigned int *) &dummy); | |
2302 | ||
2303 | /* Now we have a position on the root; find the innermost window | |
2304 | containing the pointer. */ | |
2305 | { | |
2306 | Window win, child; | |
2307 | int win_x, win_y; | |
2308 | int parent_x, parent_y; | |
2309 | ||
2310 | win = root; | |
69388238 RS |
2311 | |
2312 | if (x_mouse_grabbed) | |
12ba150f | 2313 | { |
69388238 RS |
2314 | /* If mouse was grabbed on a frame, give coords for that frame |
2315 | even if the mouse is now outside it. */ | |
12ba150f | 2316 | XTranslateCoordinates (x_current_display, |
69388238 | 2317 | |
12ba150f | 2318 | /* From-window, to-window. */ |
69388238 | 2319 | root, FRAME_X_WINDOW (last_mouse_frame), |
12ba150f JB |
2320 | |
2321 | /* From-position, to-position. */ | |
2322 | root_x, root_y, &win_x, &win_y, | |
2323 | ||
2324 | /* Child of win. */ | |
2325 | &child); | |
69388238 RS |
2326 | f1 = last_mouse_frame; |
2327 | } | |
2328 | else | |
2329 | { | |
2330 | while (1) | |
2331 | { | |
2332 | XTranslateCoordinates (x_current_display, | |
12ba150f | 2333 | |
69388238 RS |
2334 | /* From-window, to-window. */ |
2335 | root, win, | |
12ba150f | 2336 | |
69388238 RS |
2337 | /* From-position, to-position. */ |
2338 | root_x, root_y, &win_x, &win_y, | |
2339 | ||
2340 | /* Child of win. */ | |
2341 | &child); | |
2342 | ||
2343 | if (child == None) | |
2344 | break; | |
2345 | ||
2346 | win = child; | |
2347 | parent_x = win_x; | |
2348 | parent_y = win_y; | |
2349 | } | |
12ba150f | 2350 | |
69388238 RS |
2351 | /* Now we know that: |
2352 | win is the innermost window containing the pointer | |
2353 | (XTC says it has no child containing the pointer), | |
2354 | win_x and win_y are the pointer's position in it | |
2355 | (XTC did this the last time through), and | |
2356 | parent_x and parent_y are the pointer's position in win's parent. | |
2357 | (They are what win_x and win_y were when win was child. | |
2358 | If win is the root window, it has no parent, and | |
2359 | parent_{x,y} are invalid, but that's okay, because we'll | |
2360 | never use them in that case.) */ | |
2361 | ||
2362 | /* Is win one of our frames? */ | |
2b5c9e71 | 2363 | f1 = x_any_window_to_frame (win); |
69388238 | 2364 | } |
12ba150f | 2365 | |
ab648270 | 2366 | /* If not, is it one of our scroll bars? */ |
a135645a | 2367 | if (! f1) |
12ba150f | 2368 | { |
ab648270 | 2369 | struct scroll_bar *bar = x_window_to_scroll_bar (win); |
12ba150f JB |
2370 | |
2371 | if (bar) | |
2372 | { | |
a135645a | 2373 | f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
12ba150f JB |
2374 | win_x = parent_x; |
2375 | win_y = parent_y; | |
2376 | } | |
2377 | } | |
90e65f07 | 2378 | |
a135645a | 2379 | if (f1) |
12ba150f | 2380 | { |
2b5c9e71 RS |
2381 | int ignore1, ignore2; |
2382 | ||
2383 | /* Ok, we found a frame. Store all the values. */ | |
a135645a | 2384 | |
2b5c9e71 | 2385 | pixel_to_glyph_coords (f1, win_x, win_y, &ignore1, &ignore2, |
69388238 | 2386 | &last_mouse_glyph, x_mouse_grabbed); |
12ba150f JB |
2387 | |
2388 | *bar_window = Qnil; | |
2389 | *part = 0; | |
a135645a | 2390 | *f = f1; |
12ba150f JB |
2391 | XSET (*x, Lisp_Int, win_x); |
2392 | XSET (*y, Lisp_Int, win_y); | |
2393 | *time = last_mouse_movement_time; | |
2394 | } | |
2395 | } | |
2396 | } | |
90e65f07 JB |
2397 | |
2398 | UNBLOCK_INPUT; | |
2399 | } | |
2400 | ||
c118dd06 | 2401 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 | 2402 | #define XEvent XKeyPressedEvent |
c118dd06 JB |
2403 | #endif /* ! defined (HAVE_X11) */ |
2404 | \f | |
ab648270 | 2405 | /* Scroll bar support. */ |
f451eb13 | 2406 | |
ab648270 JB |
2407 | /* Given an X window ID, find the struct scroll_bar which manages it. |
2408 | This can be called in GC, so we have to make sure to strip off mark | |
2409 | bits. */ | |
2410 | static struct scroll_bar * | |
2411 | x_window_to_scroll_bar (window_id) | |
f451eb13 JB |
2412 | Window window_id; |
2413 | { | |
2414 | Lisp_Object tail, frame; | |
f451eb13 | 2415 | |
ab648270 JB |
2416 | for (tail = Vframe_list; |
2417 | XGCTYPE (tail) == Lisp_Cons; | |
2418 | tail = XCONS (tail)->cdr) | |
f451eb13 | 2419 | { |
abdda982 | 2420 | Lisp_Object frame, bar, condemned; |
f451eb13 | 2421 | |
abdda982 | 2422 | frame = XCONS (tail)->car; |
f451eb13 | 2423 | /* All elements of Vframe_list should be frames. */ |
ab648270 | 2424 | if (XGCTYPE (frame) != Lisp_Frame) |
f451eb13 JB |
2425 | abort (); |
2426 | ||
ab648270 | 2427 | /* Scan this frame's scroll bar list for a scroll bar with the |
f451eb13 | 2428 | right window ID. */ |
ab648270 JB |
2429 | condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); |
2430 | for (bar = FRAME_SCROLL_BARS (XFRAME (frame)); | |
cf7cb199 | 2431 | /* This trick allows us to search both the ordinary and |
ab648270 JB |
2432 | condemned scroll bar lists with one loop. */ |
2433 | ! GC_NILP (bar) || (bar = condemned, | |
2434 | condemned = Qnil, | |
2435 | ! GC_NILP (bar)); | |
bc20ebbf | 2436 | bar = XSCROLL_BAR (bar)->next) |
ab648270 JB |
2437 | if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)) == window_id) |
2438 | return XSCROLL_BAR (bar); | |
f451eb13 JB |
2439 | } |
2440 | ||
2441 | return 0; | |
2442 | } | |
2443 | ||
ab648270 JB |
2444 | /* Open a new X window to serve as a scroll bar, and return the |
2445 | scroll bar vector for it. */ | |
2446 | static struct scroll_bar * | |
2447 | x_scroll_bar_create (window, top, left, width, height) | |
12ba150f | 2448 | struct window *window; |
f451eb13 JB |
2449 | int top, left, width, height; |
2450 | { | |
12ba150f | 2451 | FRAME_PTR frame = XFRAME (WINDOW_FRAME (window)); |
ab648270 JB |
2452 | struct scroll_bar *bar = |
2453 | XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | |
f451eb13 JB |
2454 | |
2455 | BLOCK_INPUT; | |
2456 | ||
2457 | { | |
2458 | XSetWindowAttributes a; | |
2459 | unsigned long mask; | |
12ba150f JB |
2460 | a.background_pixel = frame->display.x->background_pixel; |
2461 | a.event_mask = (ButtonPressMask | ButtonReleaseMask | |
9a572e2a | 2462 | | ButtonMotionMask | PointerMotionHintMask |
12ba150f | 2463 | | ExposureMask); |
ab648270 | 2464 | a.cursor = x_vertical_scroll_bar_cursor; |
f451eb13 | 2465 | |
dbc4e1c1 | 2466 | mask = (CWBackPixel | CWEventMask | CWCursor); |
f451eb13 | 2467 | |
3afe33e7 RS |
2468 | #if 0 |
2469 | ||
2470 | ac = 0; | |
2471 | XtSetArg (al[ac], XtNx, left); ac++; | |
2472 | XtSetArg (al[ac], XtNy, top); ac++; | |
2473 | XtSetArg (al[ac], XtNwidth, width); ac++; | |
2474 | XtSetArg (al[ac], XtNheight, height); ac++; | |
2475 | XtSetArg (al[ac], XtNborderWidth, 0); ac++; | |
2476 | sb_widget = XtCreateManagedWidget ("box", | |
7246d1d3 KH |
2477 | boxWidgetClass, |
2478 | frame->display.x->edit_widget, al, ac); | |
2479 | SET_SCROLL_BAR_X_WINDOW | |
3afe33e7 RS |
2480 | (bar, sb_widget->core.window); |
2481 | #endif | |
7246d1d3 | 2482 | SET_SCROLL_BAR_X_WINDOW |
12ba150f JB |
2483 | (bar, |
2484 | XCreateWindow (x_current_display, FRAME_X_WINDOW (frame), | |
f451eb13 | 2485 | |
ab648270 | 2486 | /* Position and size of scroll bar. */ |
12ba150f | 2487 | left, top, width, height, |
f451eb13 | 2488 | |
12ba150f JB |
2489 | /* Border width, depth, class, and visual. */ |
2490 | 0, CopyFromParent, CopyFromParent, CopyFromParent, | |
f451eb13 | 2491 | |
12ba150f JB |
2492 | /* Attributes. */ |
2493 | mask, &a)); | |
f451eb13 JB |
2494 | } |
2495 | ||
12ba150f JB |
2496 | XSET (bar->window, Lisp_Window, window); |
2497 | XSET (bar->top, Lisp_Int, top); | |
2498 | XSET (bar->left, Lisp_Int, left); | |
2499 | XSET (bar->width, Lisp_Int, width); | |
2500 | XSET (bar->height, Lisp_Int, height); | |
2501 | XSET (bar->start, Lisp_Int, 0); | |
2502 | XSET (bar->end, Lisp_Int, 0); | |
2503 | bar->dragging = Qnil; | |
f451eb13 JB |
2504 | |
2505 | /* Add bar to its frame's list of scroll bars. */ | |
ab648270 | 2506 | bar->next = FRAME_SCROLL_BARS (frame); |
12ba150f | 2507 | bar->prev = Qnil; |
ab648270 | 2508 | XSET (FRAME_SCROLL_BARS (frame), Lisp_Vector, bar); |
12ba150f | 2509 | if (! NILP (bar->next)) |
ab648270 | 2510 | XSET (XSCROLL_BAR (bar->next)->prev, Lisp_Vector, bar); |
f451eb13 | 2511 | |
ab648270 | 2512 | XMapWindow (x_current_display, SCROLL_BAR_X_WINDOW (bar)); |
f451eb13 JB |
2513 | |
2514 | UNBLOCK_INPUT; | |
12ba150f JB |
2515 | |
2516 | return bar; | |
f451eb13 JB |
2517 | } |
2518 | ||
12ba150f JB |
2519 | /* Draw BAR's handle in the proper position. |
2520 | If the handle is already drawn from START to END, don't bother | |
2521 | redrawing it, unless REBUILD is non-zero; in that case, always | |
2522 | redraw it. (REBUILD is handy for drawing the handle after expose | |
2523 | events.) | |
2524 | ||
2525 | Normally, we want to constrain the start and end of the handle to | |
ab648270 | 2526 | fit inside its rectangle, but if the user is dragging the scroll bar |
12ba150f JB |
2527 | handle, we want to let them drag it down all the way, so that the |
2528 | bar's top is as far down as it goes; otherwise, there's no way to | |
2529 | move to the very end of the buffer. */ | |
f451eb13 | 2530 | static void |
ab648270 JB |
2531 | x_scroll_bar_set_handle (bar, start, end, rebuild) |
2532 | struct scroll_bar *bar; | |
f451eb13 | 2533 | int start, end; |
12ba150f | 2534 | int rebuild; |
f451eb13 | 2535 | { |
12ba150f | 2536 | int dragging = ! NILP (bar->dragging); |
ab648270 | 2537 | Window w = SCROLL_BAR_X_WINDOW (bar); |
12ba150f JB |
2538 | GC gc = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)))->display.x->normal_gc; |
2539 | ||
2540 | /* If the display is already accurate, do nothing. */ | |
2541 | if (! rebuild | |
2542 | && start == XINT (bar->start) | |
2543 | && end == XINT (bar->end)) | |
2544 | return; | |
2545 | ||
f451eb13 JB |
2546 | BLOCK_INPUT; |
2547 | ||
2548 | { | |
ab648270 JB |
2549 | int inside_width = VERTICAL_SCROLL_BAR_INSIDE_WIDTH (XINT (bar->width)); |
2550 | int inside_height = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar->height)); | |
2551 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar->height)); | |
f451eb13 JB |
2552 | |
2553 | /* Make sure the values are reasonable, and try to preserve | |
2554 | the distance between start and end. */ | |
12ba150f JB |
2555 | { |
2556 | int length = end - start; | |
2557 | ||
2558 | if (start < 0) | |
2559 | start = 0; | |
2560 | else if (start > top_range) | |
2561 | start = top_range; | |
2562 | end = start + length; | |
2563 | ||
2564 | if (end < start) | |
2565 | end = start; | |
2566 | else if (end > top_range && ! dragging) | |
2567 | end = top_range; | |
2568 | } | |
f451eb13 | 2569 | |
ab648270 | 2570 | /* Store the adjusted setting in the scroll bar. */ |
12ba150f JB |
2571 | XSET (bar->start, Lisp_Int, start); |
2572 | XSET (bar->end, Lisp_Int, end); | |
f451eb13 | 2573 | |
12ba150f JB |
2574 | /* Clip the end position, just for display. */ |
2575 | if (end > top_range) | |
2576 | end = top_range; | |
f451eb13 | 2577 | |
ab648270 | 2578 | /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels |
12ba150f JB |
2579 | below top positions, to make sure the handle is always at least |
2580 | that many pixels tall. */ | |
ab648270 | 2581 | end += VERTICAL_SCROLL_BAR_MIN_HANDLE; |
f451eb13 | 2582 | |
12ba150f JB |
2583 | /* Draw the empty space above the handle. Note that we can't clear |
2584 | zero-height areas; that means "clear to end of window." */ | |
2585 | if (0 < start) | |
2586 | XClearArea (x_current_display, w, | |
f451eb13 | 2587 | |
12ba150f | 2588 | /* x, y, width, height, and exposures. */ |
ab648270 JB |
2589 | VERTICAL_SCROLL_BAR_LEFT_BORDER, |
2590 | VERTICAL_SCROLL_BAR_TOP_BORDER, | |
12ba150f JB |
2591 | inside_width, start, |
2592 | False); | |
f451eb13 | 2593 | |
12ba150f JB |
2594 | /* Draw the handle itself. */ |
2595 | XFillRectangle (x_current_display, w, gc, | |
f451eb13 | 2596 | |
12ba150f | 2597 | /* x, y, width, height */ |
ab648270 JB |
2598 | VERTICAL_SCROLL_BAR_LEFT_BORDER, |
2599 | VERTICAL_SCROLL_BAR_TOP_BORDER + start, | |
12ba150f | 2600 | inside_width, end - start); |
f451eb13 | 2601 | |
f451eb13 | 2602 | |
12ba150f JB |
2603 | /* Draw the empty space below the handle. Note that we can't |
2604 | clear zero-height areas; that means "clear to end of window." */ | |
2605 | if (end < inside_height) | |
2606 | XClearArea (x_current_display, w, | |
f451eb13 | 2607 | |
12ba150f | 2608 | /* x, y, width, height, and exposures. */ |
ab648270 JB |
2609 | VERTICAL_SCROLL_BAR_LEFT_BORDER, |
2610 | VERTICAL_SCROLL_BAR_TOP_BORDER + end, | |
12ba150f JB |
2611 | inside_width, inside_height - end, |
2612 | False); | |
f451eb13 | 2613 | |
f451eb13 JB |
2614 | } |
2615 | ||
f451eb13 JB |
2616 | UNBLOCK_INPUT; |
2617 | } | |
2618 | ||
eb8c3be9 | 2619 | /* Move a scroll bar around on the screen, to accommodate changing |
12ba150f | 2620 | window configurations. */ |
f451eb13 | 2621 | static void |
ab648270 JB |
2622 | x_scroll_bar_move (bar, top, left, width, height) |
2623 | struct scroll_bar *bar; | |
f451eb13 JB |
2624 | int top, left, width, height; |
2625 | { | |
2626 | BLOCK_INPUT; | |
2627 | ||
2628 | { | |
2629 | XWindowChanges wc; | |
2630 | unsigned int mask = 0; | |
2631 | ||
2632 | wc.x = left; | |
2633 | wc.y = top; | |
2634 | wc.width = width; | |
2635 | wc.height = height; | |
2636 | ||
12ba150f JB |
2637 | if (left != XINT (bar->left)) mask |= CWX; |
2638 | if (top != XINT (bar->top)) mask |= CWY; | |
2639 | if (width != XINT (bar->width)) mask |= CWWidth; | |
2640 | if (height != XINT (bar->height)) mask |= CWHeight; | |
2641 | ||
2642 | if (mask) | |
ab648270 | 2643 | XConfigureWindow (x_current_display, SCROLL_BAR_X_WINDOW (bar), |
12ba150f | 2644 | mask, &wc); |
f451eb13 JB |
2645 | } |
2646 | ||
12ba150f JB |
2647 | XSET (bar->left, Lisp_Int, left); |
2648 | XSET (bar->top, Lisp_Int, top); | |
2649 | XSET (bar->width, Lisp_Int, width); | |
2650 | XSET (bar->height, Lisp_Int, height); | |
2651 | ||
f451eb13 JB |
2652 | UNBLOCK_INPUT; |
2653 | } | |
2654 | ||
ab648270 | 2655 | /* Destroy the X window for BAR, and set its Emacs window's scroll bar |
12ba150f JB |
2656 | to nil. */ |
2657 | static void | |
ab648270 JB |
2658 | x_scroll_bar_remove (bar) |
2659 | struct scroll_bar *bar; | |
12ba150f JB |
2660 | { |
2661 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
2662 | ||
2663 | BLOCK_INPUT; | |
2664 | ||
2665 | /* Destroy the window. */ | |
ab648270 | 2666 | XDestroyWindow (x_current_display, SCROLL_BAR_X_WINDOW (bar)); |
12ba150f | 2667 | |
ab648270 JB |
2668 | /* Disassociate this scroll bar from its window. */ |
2669 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | |
12ba150f JB |
2670 | |
2671 | UNBLOCK_INPUT; | |
2672 | } | |
2673 | ||
2674 | /* Set the handle of the vertical scroll bar for WINDOW to indicate | |
2675 | that we are displaying PORTION characters out of a total of WHOLE | |
ab648270 | 2676 | characters, starting at POSITION. If WINDOW has no scroll bar, |
12ba150f JB |
2677 | create one. */ |
2678 | static void | |
ab648270 | 2679 | XTset_vertical_scroll_bar (window, portion, whole, position) |
f451eb13 JB |
2680 | struct window *window; |
2681 | int portion, whole, position; | |
2682 | { | |
2683 | FRAME_PTR f = XFRAME (WINDOW_FRAME (window)); | |
f451eb13 | 2684 | int top = XINT (window->top); |
ab648270 JB |
2685 | int left = WINDOW_VERTICAL_SCROLL_BAR_COLUMN (window); |
2686 | int height = WINDOW_VERTICAL_SCROLL_BAR_HEIGHT (window); | |
f451eb13 | 2687 | |
ab648270 | 2688 | /* Where should this scroll bar be, pixelwise? */ |
12ba150f JB |
2689 | int pixel_top = CHAR_TO_PIXEL_ROW (f, top); |
2690 | int pixel_left = CHAR_TO_PIXEL_COL (f, left); | |
ab648270 JB |
2691 | int pixel_width = VERTICAL_SCROLL_BAR_PIXEL_WIDTH (f); |
2692 | int pixel_height = VERTICAL_SCROLL_BAR_PIXEL_HEIGHT (f, height); | |
f451eb13 | 2693 | |
ab648270 | 2694 | struct scroll_bar *bar; |
12ba150f | 2695 | |
ab648270 JB |
2696 | /* Does the scroll bar exist yet? */ |
2697 | if (NILP (window->vertical_scroll_bar)) | |
2698 | bar = x_scroll_bar_create (window, | |
f451eb13 JB |
2699 | pixel_top, pixel_left, |
2700 | pixel_width, pixel_height); | |
2701 | else | |
12ba150f JB |
2702 | { |
2703 | /* It may just need to be moved and resized. */ | |
ab648270 JB |
2704 | bar = XSCROLL_BAR (window->vertical_scroll_bar); |
2705 | x_scroll_bar_move (bar, pixel_top, pixel_left, pixel_width, pixel_height); | |
12ba150f | 2706 | } |
f451eb13 | 2707 | |
ab648270 | 2708 | /* Set the scroll bar's current state, unless we're currently being |
f451eb13 | 2709 | dragged. */ |
12ba150f | 2710 | if (NILP (bar->dragging)) |
f451eb13 | 2711 | { |
12ba150f | 2712 | int top_range = |
ab648270 | 2713 | VERTICAL_SCROLL_BAR_TOP_RANGE (pixel_height); |
f451eb13 | 2714 | |
12ba150f | 2715 | if (whole == 0) |
ab648270 | 2716 | x_scroll_bar_set_handle (bar, 0, top_range, 0); |
12ba150f JB |
2717 | else |
2718 | { | |
43f868f5 JB |
2719 | int start = ((double) position * top_range) / whole; |
2720 | int end = ((double) (position + portion) * top_range) / whole; | |
12ba150f | 2721 | |
ab648270 | 2722 | x_scroll_bar_set_handle (bar, start, end, 0); |
12ba150f | 2723 | } |
f451eb13 JB |
2724 | } |
2725 | ||
ab648270 | 2726 | XSET (window->vertical_scroll_bar, Lisp_Vector, bar); |
f451eb13 JB |
2727 | } |
2728 | ||
12ba150f | 2729 | |
f451eb13 | 2730 | /* The following three hooks are used when we're doing a thorough |
ab648270 | 2731 | redisplay of the frame. We don't explicitly know which scroll bars |
f451eb13 | 2732 | are going to be deleted, because keeping track of when windows go |
12ba150f JB |
2733 | away is a real pain - "Can you say set-window-configuration, boys |
2734 | and girls?" Instead, we just assert at the beginning of redisplay | |
ab648270 | 2735 | that *all* scroll bars are to be removed, and then save a scroll bar |
12ba150f | 2736 | from the fiery pit when we actually redisplay its window. */ |
f451eb13 | 2737 | |
ab648270 JB |
2738 | /* Arrange for all scroll bars on FRAME to be removed at the next call |
2739 | to `*judge_scroll_bars_hook'. A scroll bar may be spared if | |
2740 | `*redeem_scroll_bar_hook' is applied to its window before the judgement. */ | |
f451eb13 | 2741 | static void |
ab648270 | 2742 | XTcondemn_scroll_bars (frame) |
f451eb13 JB |
2743 | FRAME_PTR frame; |
2744 | { | |
12ba150f JB |
2745 | /* The condemned list should be empty at this point; if it's not, |
2746 | then the rest of Emacs isn't using the condemn/redeem/judge | |
2747 | protocol correctly. */ | |
ab648270 | 2748 | if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame))) |
12ba150f JB |
2749 | abort (); |
2750 | ||
2751 | /* Move them all to the "condemned" list. */ | |
ab648270 JB |
2752 | FRAME_CONDEMNED_SCROLL_BARS (frame) = FRAME_SCROLL_BARS (frame); |
2753 | FRAME_SCROLL_BARS (frame) = Qnil; | |
f451eb13 JB |
2754 | } |
2755 | ||
ab648270 | 2756 | /* Unmark WINDOW's scroll bar for deletion in this judgement cycle. |
12ba150f | 2757 | Note that WINDOW isn't necessarily condemned at all. */ |
f451eb13 | 2758 | static void |
ab648270 | 2759 | XTredeem_scroll_bar (window) |
12ba150f | 2760 | struct window *window; |
f451eb13 | 2761 | { |
ab648270 | 2762 | struct scroll_bar *bar; |
12ba150f | 2763 | |
ab648270 JB |
2764 | /* We can't redeem this window's scroll bar if it doesn't have one. */ |
2765 | if (NILP (window->vertical_scroll_bar)) | |
12ba150f JB |
2766 | abort (); |
2767 | ||
ab648270 | 2768 | bar = XSCROLL_BAR (window->vertical_scroll_bar); |
12ba150f JB |
2769 | |
2770 | /* Unlink it from the condemned list. */ | |
2771 | { | |
2772 | FRAME_PTR f = XFRAME (WINDOW_FRAME (window)); | |
2773 | ||
2774 | if (NILP (bar->prev)) | |
2775 | { | |
2776 | /* If the prev pointer is nil, it must be the first in one of | |
2777 | the lists. */ | |
ab648270 | 2778 | if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar)) |
12ba150f JB |
2779 | /* It's not condemned. Everything's fine. */ |
2780 | return; | |
ab648270 JB |
2781 | else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f), |
2782 | window->vertical_scroll_bar)) | |
2783 | FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next; | |
12ba150f JB |
2784 | else |
2785 | /* If its prev pointer is nil, it must be at the front of | |
2786 | one or the other! */ | |
2787 | abort (); | |
2788 | } | |
2789 | else | |
ab648270 | 2790 | XSCROLL_BAR (bar->prev)->next = bar->next; |
12ba150f JB |
2791 | |
2792 | if (! NILP (bar->next)) | |
ab648270 | 2793 | XSCROLL_BAR (bar->next)->prev = bar->prev; |
12ba150f | 2794 | |
ab648270 | 2795 | bar->next = FRAME_SCROLL_BARS (f); |
12ba150f | 2796 | bar->prev = Qnil; |
ab648270 | 2797 | XSET (FRAME_SCROLL_BARS (f), Lisp_Vector, bar); |
12ba150f | 2798 | if (! NILP (bar->next)) |
ab648270 | 2799 | XSET (XSCROLL_BAR (bar->next)->prev, Lisp_Vector, bar); |
12ba150f | 2800 | } |
f451eb13 JB |
2801 | } |
2802 | ||
ab648270 JB |
2803 | /* Remove all scroll bars on FRAME that haven't been saved since the |
2804 | last call to `*condemn_scroll_bars_hook'. */ | |
f451eb13 | 2805 | static void |
ab648270 | 2806 | XTjudge_scroll_bars (f) |
12ba150f | 2807 | FRAME_PTR f; |
f451eb13 | 2808 | { |
12ba150f | 2809 | Lisp_Object bar, next; |
f451eb13 | 2810 | |
ab648270 | 2811 | bar = FRAME_CONDEMNED_SCROLL_BARS (f); |
cf7cb199 JB |
2812 | |
2813 | /* Clear out the condemned list now so we won't try to process any | |
ab648270 JB |
2814 | more events on the hapless scroll bars. */ |
2815 | FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil; | |
cf7cb199 JB |
2816 | |
2817 | for (; ! NILP (bar); bar = next) | |
f451eb13 | 2818 | { |
ab648270 | 2819 | struct scroll_bar *b = XSCROLL_BAR (bar); |
12ba150f | 2820 | |
ab648270 | 2821 | x_scroll_bar_remove (b); |
12ba150f JB |
2822 | |
2823 | next = b->next; | |
2824 | b->next = b->prev = Qnil; | |
f451eb13 | 2825 | } |
12ba150f | 2826 | |
ab648270 | 2827 | /* Now there should be no references to the condemned scroll bars, |
12ba150f | 2828 | and they should get garbage-collected. */ |
f451eb13 JB |
2829 | } |
2830 | ||
2831 | ||
ab648270 JB |
2832 | /* Handle an Expose or GraphicsExpose event on a scroll bar. |
2833 | ||
2834 | This may be called from a signal handler, so we have to ignore GC | |
2835 | mark bits. */ | |
f451eb13 | 2836 | static void |
ab648270 JB |
2837 | x_scroll_bar_expose (bar, event) |
2838 | struct scroll_bar *bar; | |
f451eb13 JB |
2839 | XEvent *event; |
2840 | { | |
ab648270 | 2841 | Window w = SCROLL_BAR_X_WINDOW (bar); |
12ba150f JB |
2842 | GC gc = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)))->display.x->normal_gc; |
2843 | ||
f451eb13 JB |
2844 | BLOCK_INPUT; |
2845 | ||
ab648270 | 2846 | x_scroll_bar_set_handle (bar, XINT (bar->start), XINT (bar->end), 1); |
f451eb13 | 2847 | |
ab648270 | 2848 | /* Draw a one-pixel border just inside the edges of the scroll bar. */ |
12ba150f | 2849 | XDrawRectangle (x_current_display, w, gc, |
f451eb13 JB |
2850 | |
2851 | /* x, y, width, height */ | |
12ba150f | 2852 | 0, 0, XINT (bar->width) - 1, XINT (bar->height) - 1); |
f451eb13 | 2853 | |
f451eb13 JB |
2854 | UNBLOCK_INPUT; |
2855 | } | |
2856 | ||
ab648270 JB |
2857 | /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind |
2858 | is set to something other than no_event, it is enqueued. | |
2859 | ||
2860 | This may be called from a signal handler, so we have to ignore GC | |
2861 | mark bits. */ | |
f451eb13 | 2862 | static void |
ab648270 JB |
2863 | x_scroll_bar_handle_click (bar, event, emacs_event) |
2864 | struct scroll_bar *bar; | |
f451eb13 JB |
2865 | XEvent *event; |
2866 | struct input_event *emacs_event; | |
2867 | { | |
ab648270 | 2868 | if (XGCTYPE (bar->window) != Lisp_Window) |
12ba150f JB |
2869 | abort (); |
2870 | ||
ab648270 | 2871 | emacs_event->kind = scroll_bar_click; |
69388238 | 2872 | emacs_event->code = event->xbutton.button - Button1; |
f451eb13 | 2873 | emacs_event->modifiers = |
dfeccd2d | 2874 | (x_x_to_emacs_modifiers (event->xbutton.state) |
f451eb13 JB |
2875 | | (event->type == ButtonRelease |
2876 | ? up_modifier | |
2877 | : down_modifier)); | |
12ba150f | 2878 | emacs_event->frame_or_window = bar->window; |
f451eb13 | 2879 | emacs_event->timestamp = event->xbutton.time; |
12ba150f JB |
2880 | { |
2881 | int internal_height = | |
ab648270 | 2882 | VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar->height)); |
12ba150f | 2883 | int top_range = |
ab648270 JB |
2884 | VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar->height)); |
2885 | int y = event->xbutton.y - VERTICAL_SCROLL_BAR_TOP_BORDER; | |
12ba150f JB |
2886 | |
2887 | if (y < 0) y = 0; | |
2888 | if (y > top_range) y = top_range; | |
2889 | ||
2890 | if (y < XINT (bar->start)) | |
ab648270 JB |
2891 | emacs_event->part = scroll_bar_above_handle; |
2892 | else if (y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE) | |
2893 | emacs_event->part = scroll_bar_handle; | |
12ba150f | 2894 | else |
ab648270 | 2895 | emacs_event->part = scroll_bar_below_handle; |
929787e1 JB |
2896 | |
2897 | /* Just because the user has clicked on the handle doesn't mean | |
5116f055 JB |
2898 | they want to drag it. Lisp code needs to be able to decide |
2899 | whether or not we're dragging. */ | |
929787e1 | 2900 | #if 0 |
12ba150f JB |
2901 | /* If the user has just clicked on the handle, record where they're |
2902 | holding it. */ | |
2903 | if (event->type == ButtonPress | |
ab648270 | 2904 | && emacs_event->part == scroll_bar_handle) |
12ba150f | 2905 | XSET (bar->dragging, Lisp_Int, y - XINT (bar->start)); |
929787e1 | 2906 | #endif |
12ba150f JB |
2907 | |
2908 | /* If the user has released the handle, set it to its final position. */ | |
2909 | if (event->type == ButtonRelease | |
2910 | && ! NILP (bar->dragging)) | |
2911 | { | |
2912 | int new_start = y - XINT (bar->dragging); | |
2913 | int new_end = new_start + (XINT (bar->end) - XINT (bar->start)); | |
f451eb13 | 2914 | |
ab648270 | 2915 | x_scroll_bar_set_handle (bar, new_start, new_end, 0); |
12ba150f JB |
2916 | bar->dragging = Qnil; |
2917 | } | |
f451eb13 | 2918 | |
5116f055 JB |
2919 | /* Same deal here as the other #if 0. */ |
2920 | #if 0 | |
eb8c3be9 | 2921 | /* Clicks on the handle are always reported as occurring at the top of |
12ba150f | 2922 | the handle. */ |
ab648270 | 2923 | if (emacs_event->part == scroll_bar_handle) |
12ba150f JB |
2924 | emacs_event->x = bar->start; |
2925 | else | |
2926 | XSET (emacs_event->x, Lisp_Int, y); | |
5116f055 JB |
2927 | #else |
2928 | XSET (emacs_event->x, Lisp_Int, y); | |
2929 | #endif | |
f451eb13 | 2930 | |
12ba150f JB |
2931 | XSET (emacs_event->y, Lisp_Int, top_range); |
2932 | } | |
2933 | } | |
f451eb13 | 2934 | |
ab648270 JB |
2935 | /* Handle some mouse motion while someone is dragging the scroll bar. |
2936 | ||
2937 | This may be called from a signal handler, so we have to ignore GC | |
2938 | mark bits. */ | |
f451eb13 | 2939 | static void |
ab648270 JB |
2940 | x_scroll_bar_note_movement (bar, event) |
2941 | struct scroll_bar *bar; | |
f451eb13 JB |
2942 | XEvent *event; |
2943 | { | |
2944 | last_mouse_movement_time = event->xmotion.time; | |
2945 | ||
2946 | mouse_moved = 1; | |
ab648270 | 2947 | XSET (last_mouse_scroll_bar, Lisp_Vector, bar); |
f451eb13 JB |
2948 | |
2949 | /* If we're dragging the bar, display it. */ | |
ab648270 | 2950 | if (! GC_NILP (bar->dragging)) |
f451eb13 JB |
2951 | { |
2952 | /* Where should the handle be now? */ | |
12ba150f | 2953 | int new_start = event->xmotion.y - XINT (bar->dragging); |
f451eb13 | 2954 | |
12ba150f | 2955 | if (new_start != XINT (bar->start)) |
f451eb13 | 2956 | { |
12ba150f | 2957 | int new_end = new_start + (XINT (bar->end) - XINT (bar->start)); |
f451eb13 | 2958 | |
ab648270 | 2959 | x_scroll_bar_set_handle (bar, new_start, new_end, 0); |
f451eb13 JB |
2960 | } |
2961 | } | |
2962 | ||
2963 | /* Call XQueryPointer so we'll get an event the next time the mouse | |
2964 | moves and we can see *still* on the same position. */ | |
2965 | { | |
2966 | int dummy; | |
2967 | ||
2968 | XQueryPointer (event->xmotion.display, event->xmotion.window, | |
2969 | (Window *) &dummy, (Window *) &dummy, | |
2970 | &dummy, &dummy, &dummy, &dummy, | |
2971 | (unsigned int *) &dummy); | |
2972 | } | |
2973 | } | |
2974 | ||
12ba150f | 2975 | /* Return information to the user about the current position of the mouse |
ab648270 | 2976 | on the scroll bar. */ |
12ba150f | 2977 | static void |
ab648270 | 2978 | x_scroll_bar_report_motion (f, bar_window, part, x, y, time) |
12ba150f JB |
2979 | FRAME_PTR *f; |
2980 | Lisp_Object *bar_window; | |
ab648270 | 2981 | enum scroll_bar_part *part; |
12ba150f JB |
2982 | Lisp_Object *x, *y; |
2983 | unsigned long *time; | |
2984 | { | |
ab648270 | 2985 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); |
12ba150f | 2986 | int win_x, win_y; |
559cb2fb JB |
2987 | Window dummy_window; |
2988 | int dummy_coord; | |
2989 | unsigned int dummy_mask; | |
12ba150f | 2990 | |
cf7cb199 JB |
2991 | BLOCK_INPUT; |
2992 | ||
ab648270 | 2993 | /* Get the mouse's position relative to the scroll bar window, and |
12ba150f | 2994 | report that. */ |
559cb2fb JB |
2995 | if (! XQueryPointer (x_current_display, |
2996 | SCROLL_BAR_X_WINDOW (bar), | |
12ba150f | 2997 | |
559cb2fb JB |
2998 | /* Root, child, root x and root y. */ |
2999 | &dummy_window, &dummy_window, | |
3000 | &dummy_coord, &dummy_coord, | |
12ba150f | 3001 | |
559cb2fb JB |
3002 | /* Position relative to scroll bar. */ |
3003 | &win_x, &win_y, | |
12ba150f | 3004 | |
559cb2fb JB |
3005 | /* Mouse buttons and modifier keys. */ |
3006 | &dummy_mask)) | |
3007 | *f = 0; | |
3008 | else | |
3009 | { | |
3010 | int inside_height | |
3011 | = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (XINT (bar->height)); | |
3012 | int top_range | |
3013 | = VERTICAL_SCROLL_BAR_TOP_RANGE (XINT (bar->height)); | |
3014 | ||
3015 | win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER; | |
3016 | ||
3017 | if (! NILP (bar->dragging)) | |
3018 | win_y -= XINT (bar->dragging); | |
3019 | ||
3020 | if (win_y < 0) | |
3021 | win_y = 0; | |
3022 | if (win_y > top_range) | |
3023 | win_y = top_range; | |
3024 | ||
3025 | *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
3026 | *bar_window = bar->window; | |
3027 | ||
3028 | if (! NILP (bar->dragging)) | |
3029 | *part = scroll_bar_handle; | |
3030 | else if (win_y < XINT (bar->start)) | |
3031 | *part = scroll_bar_above_handle; | |
3032 | else if (win_y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE) | |
3033 | *part = scroll_bar_handle; | |
3034 | else | |
3035 | *part = scroll_bar_below_handle; | |
12ba150f | 3036 | |
559cb2fb JB |
3037 | XSET (*x, Lisp_Int, win_y); |
3038 | XSET (*y, Lisp_Int, top_range); | |
12ba150f | 3039 | |
559cb2fb JB |
3040 | mouse_moved = 0; |
3041 | last_mouse_scroll_bar = Qnil; | |
3042 | } | |
12ba150f | 3043 | |
559cb2fb | 3044 | *time = last_mouse_movement_time; |
cf7cb199 | 3045 | |
cf7cb199 | 3046 | UNBLOCK_INPUT; |
12ba150f JB |
3047 | } |
3048 | ||
f451eb13 | 3049 | |
dbc4e1c1 | 3050 | /* The screen has been cleared so we may have changed foreground or |
ab648270 JB |
3051 | background colors, and the scroll bars may need to be redrawn. |
3052 | Clear out the scroll bars, and ask for expose events, so we can | |
dbc4e1c1 JB |
3053 | redraw them. */ |
3054 | ||
ab648270 | 3055 | x_scroll_bar_clear (f) |
dbc4e1c1 JB |
3056 | FRAME_PTR f; |
3057 | { | |
3058 | Lisp_Object bar; | |
3059 | ||
ab648270 | 3060 | for (bar = FRAME_SCROLL_BARS (f); |
dbc4e1c1 | 3061 | XTYPE (bar) == Lisp_Vector; |
ab648270 JB |
3062 | bar = XSCROLL_BAR (bar)->next) |
3063 | XClearArea (x_current_display, SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)), | |
dbc4e1c1 JB |
3064 | 0, 0, 0, 0, True); |
3065 | } | |
3066 | ||
3afe33e7 RS |
3067 | /* This processes Expose events from the menubar specific X event |
3068 | loop in menubar.c. This allows to redisplay the frame if necessary | |
3069 | when handling menubar or popup items. */ | |
3070 | ||
3071 | void | |
3072 | process_expose_from_menu (event) | |
3073 | XEvent event; | |
3074 | { | |
3075 | FRAME_PTR f; | |
3076 | ||
f94397b5 KH |
3077 | BLOCK_INPUT; |
3078 | ||
3afe33e7 RS |
3079 | f = x_window_to_frame (event.xexpose.window); |
3080 | if (f) | |
3081 | { | |
3082 | if (f->async_visible == 0) | |
3083 | { | |
3084 | f->async_visible = 1; | |
3085 | f->async_iconified = 0; | |
3086 | SET_FRAME_GARBAGED (f); | |
3087 | } | |
3088 | else | |
3089 | { | |
3090 | dumprectangle (x_window_to_frame (event.xexpose.window), | |
3091 | event.xexpose.x, event.xexpose.y, | |
3092 | event.xexpose.width, event.xexpose.height); | |
3093 | } | |
3094 | } | |
3095 | else | |
3096 | { | |
3097 | struct scroll_bar *bar | |
3098 | = x_window_to_scroll_bar (event.xexpose.window); | |
3099 | ||
3100 | if (bar) | |
3101 | x_scroll_bar_expose (bar, &event); | |
3102 | } | |
f94397b5 KH |
3103 | |
3104 | UNBLOCK_INPUT; | |
3afe33e7 | 3105 | } |
dbc4e1c1 | 3106 | |
f451eb13 JB |
3107 | \f |
3108 | /* The main X event-reading loop - XTread_socket. */ | |
dc6f92b8 | 3109 | |
dc6f92b8 JB |
3110 | /* Timestamp of enter window event. This is only used by XTread_socket, |
3111 | but we have to put it out here, since static variables within functions | |
3112 | sometimes don't work. */ | |
3113 | static Time enter_timestamp; | |
3114 | ||
11edeb03 JB |
3115 | /* This holds the state XLookupString needs to implement dead keys |
3116 | and other tricks known as "compose processing". _X Window System_ | |
3117 | says that a portable program can't use this, but Stephen Gildea assures | |
3118 | me that letting the compiler initialize it to zeros will work okay. | |
3119 | ||
3120 | This must be defined outside of XTread_socket, for the same reasons | |
3121 | given for enter_timestamp, above. */ | |
3122 | static XComposeStatus compose_status; | |
3123 | ||
c047688c JA |
3124 | /* Communication with window managers. */ |
3125 | Atom Xatom_wm_protocols; | |
3126 | ||
3127 | /* Kinds of protocol things we may receive. */ | |
3128 | Atom Xatom_wm_take_focus; | |
3129 | Atom Xatom_wm_save_yourself; | |
3130 | Atom Xatom_wm_delete_window; | |
3131 | ||
3132 | /* Other WM communication */ | |
3133 | Atom Xatom_wm_configure_denied; /* When our config request is denied */ | |
3134 | Atom Xatom_wm_window_moved; /* When the WM moves us. */ | |
3135 | ||
d56a553a RS |
3136 | /* Window manager communication. */ |
3137 | Atom Xatom_wm_change_state; | |
3138 | ||
10e6549c RS |
3139 | /* Record the last 100 characters stored |
3140 | to help debug the loss-of-chars-during-GC problem. */ | |
3141 | int temp_index; | |
3142 | short temp_buffer[100]; | |
3143 | ||
dc6f92b8 JB |
3144 | /* Read events coming from the X server. |
3145 | This routine is called by the SIGIO handler. | |
3146 | We return as soon as there are no more events to be read. | |
3147 | ||
3148 | Events representing keys are stored in buffer BUFP, | |
3149 | which can hold up to NUMCHARS characters. | |
3150 | We return the number of characters stored into the buffer, | |
3151 | thus pretending to be `read'. | |
3152 | ||
3153 | WAITP is nonzero if we should block until input arrives. | |
3154 | EXPECTED is nonzero if the caller knows input is available. */ | |
3155 | ||
7c5283e4 | 3156 | int |
dc6f92b8 JB |
3157 | XTread_socket (sd, bufp, numchars, waitp, expected) |
3158 | register int sd; | |
3159 | register struct input_event *bufp; | |
3160 | register int numchars; | |
3161 | int waitp; | |
3162 | int expected; | |
3163 | { | |
3164 | int count = 0; | |
3165 | int nbytes = 0; | |
3166 | int mask; | |
3167 | int items_pending; /* How many items are in the X queue. */ | |
3168 | XEvent event; | |
f676886a | 3169 | struct frame *f; |
66f55a9d | 3170 | int event_found = 0; |
dc6f92b8 JB |
3171 | int prefix; |
3172 | Lisp_Object part; | |
3173 | ||
9ac0d9e0 | 3174 | if (interrupt_input_blocked) |
dc6f92b8 | 3175 | { |
9ac0d9e0 | 3176 | interrupt_input_pending = 1; |
dc6f92b8 JB |
3177 | return -1; |
3178 | } | |
3179 | ||
9ac0d9e0 | 3180 | interrupt_input_pending = 0; |
dc6f92b8 JB |
3181 | BLOCK_INPUT; |
3182 | ||
3183 | if (numchars <= 0) | |
3184 | abort (); /* Don't think this happens. */ | |
3185 | ||
3186 | #ifdef FIOSNBIO | |
3187 | /* If available, Xlib uses FIOSNBIO to make the socket | |
3188 | non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set, | |
3189 | FIOSNBIO is ignored, and instead of signalling EWOULDBLOCK, | |
3190 | a read returns 0, which Xlib interprets as equivalent to EPIPE. */ | |
3191 | fcntl (fileno (stdin), F_SETFL, 0); | |
c118dd06 | 3192 | #endif /* ! defined (FIOSNBIO) */ |
dc6f92b8 JB |
3193 | |
3194 | #ifndef SIGIO | |
3195 | #ifndef HAVE_SELECT | |
3196 | if (! (fcntl (fileno (stdin), F_GETFL, 0) & O_NDELAY)) | |
3197 | { | |
3198 | extern int read_alarm_should_throw; | |
3199 | read_alarm_should_throw = 1; | |
3200 | XPeekEvent (XDISPLAY &event); | |
3201 | read_alarm_should_throw = 0; | |
3202 | } | |
c118dd06 JB |
3203 | #endif /* HAVE_SELECT */ |
3204 | #endif /* SIGIO */ | |
dc6f92b8 JB |
3205 | |
3206 | while (XStuffPending () != 0) | |
3207 | { | |
3208 | XNextEvent (XDISPLAY &event); | |
3209 | event_found = 1; | |
3210 | ||
3211 | switch (event.type) | |
3212 | { | |
3213 | #ifdef HAVE_X11 | |
c047688c JA |
3214 | case ClientMessage: |
3215 | { | |
3216 | if (event.xclient.message_type == Xatom_wm_protocols | |
3217 | && event.xclient.format == 32) | |
3218 | { | |
3219 | if (event.xclient.data.l[0] == Xatom_wm_take_focus) | |
3220 | { | |
3afe33e7 RS |
3221 | #ifdef USE_X_TOOLKIT |
3222 | /* f = x_any_window_to_frame (event.xclient.window); */ | |
f676886a | 3223 | f = x_window_to_frame (event.xclient.window); |
3afe33e7 RS |
3224 | #else |
3225 | f = x_window_to_frame (event.xclient.window); | |
3226 | #endif | |
f676886a JB |
3227 | if (f) |
3228 | x_focus_on_frame (f); | |
ab648270 | 3229 | /* Not certain about handling scroll bars here */ |
c047688c JA |
3230 | } |
3231 | else if (event.xclient.data.l[0] == Xatom_wm_save_yourself) | |
3232 | { | |
3233 | /* Save state modify the WM_COMMAND property to | |
3234 | something which can reinstate us. This notifies | |
3235 | the session manager, who's looking for such a | |
3236 | PropertyNotify. Can restart processing when | |
3237 | a keyboard or mouse event arrives. */ | |
3238 | if (numchars > 0) | |
3239 | { | |
3240 | } | |
3241 | } | |
3242 | else if (event.xclient.data.l[0] == Xatom_wm_delete_window) | |
3243 | { | |
82aebaf4 | 3244 | struct frame *f = x_any_window_to_frame (event.xclient.window); |
c047688c | 3245 | |
f676886a | 3246 | if (f) |
1fb20991 RS |
3247 | { |
3248 | if (numchars == 0) | |
3249 | abort (); | |
3250 | ||
3251 | bufp->kind = delete_window_event; | |
3252 | XSET (bufp->frame_or_window, Lisp_Frame, f); | |
3253 | bufp++; | |
3254 | ||
3255 | count += 1; | |
3256 | numchars -= 1; | |
3257 | } | |
c047688c JA |
3258 | } |
3259 | } | |
3260 | else if (event.xclient.message_type == Xatom_wm_configure_denied) | |
3261 | { | |
3262 | } | |
3263 | else if (event.xclient.message_type == Xatom_wm_window_moved) | |
3264 | { | |
3265 | int new_x, new_y; | |
1fb20991 RS |
3266 | struct frame *f = x_window_to_frame (event.xclient.window); |
3267 | ||
4357eba7 JB |
3268 | new_x = event.xclient.data.s[0]; |
3269 | new_y = event.xclient.data.s[1]; | |
1fb20991 RS |
3270 | |
3271 | if (f) | |
3272 | { | |
3273 | f->display.x->left_pos = new_x; | |
3274 | f->display.x->top_pos = new_y; | |
3275 | } | |
c047688c JA |
3276 | } |
3277 | } | |
3278 | break; | |
dc6f92b8 | 3279 | |
d56a553a RS |
3280 | #ifdef NEW_SELECTIONS |
3281 | case SelectionNotify: | |
3afe33e7 RS |
3282 | #ifdef USE_X_TOOLKIT |
3283 | if (x_window_to_frame (event.xselection.requestor)) | |
3284 | x_handle_selection_notify (&event); | |
3285 | else | |
3286 | goto OTHER; | |
3287 | #else /* not USE_X_TOOLKIT */ | |
d56a553a | 3288 | x_handle_selection_notify (&event); |
3afe33e7 | 3289 | #endif /* not USE_X_TOOLKIT */ |
d56a553a | 3290 | break; |
3afe33e7 | 3291 | #endif /* NEW_SELECTIONS */ |
d56a553a | 3292 | |
dc6f92b8 | 3293 | case SelectionClear: /* Someone has grabbed ownership. */ |
d56a553a RS |
3294 | #ifdef NEW_SELECTIONS |
3295 | { | |
3afe33e7 RS |
3296 | #ifdef USE_X_TOOLKIT |
3297 | if (x_window_to_frame (event.xselectionclear.window)) | |
3298 | { | |
3299 | #endif /* USE_X_TOOLKIT */ | |
d56a553a RS |
3300 | XSelectionClearEvent *eventp = (XSelectionClearEvent *) &event; |
3301 | ||
3302 | if (numchars == 0) | |
3303 | abort (); | |
3304 | ||
3305 | bufp->kind = selection_clear_event; | |
3306 | SELECTION_EVENT_DISPLAY (bufp) = eventp->display; | |
3307 | SELECTION_EVENT_SELECTION (bufp) = eventp->selection; | |
3308 | SELECTION_EVENT_TIME (bufp) = eventp->time; | |
3309 | bufp++; | |
3310 | ||
3311 | count += 1; | |
3312 | numchars -= 1; | |
3afe33e7 | 3313 | #ifdef USE_X_TOOLKIT |
d56a553a | 3314 | } |
3afe33e7 RS |
3315 | else |
3316 | goto OTHER; | |
3317 | #endif /* USE_X_TOOLKIT */ | |
3318 | } | |
3319 | #else /* not NEW_SELECTIONS */ | |
dc6f92b8 JB |
3320 | x_disown_selection (event.xselectionclear.window, |
3321 | event.xselectionclear.selection, | |
3322 | event.xselectionclear.time); | |
3afe33e7 | 3323 | #endif /* not NEW_SELECTIONS */ |
dc6f92b8 JB |
3324 | break; |
3325 | ||
3326 | case SelectionRequest: /* Someone wants our selection. */ | |
d56a553a RS |
3327 | #ifdef NEW_SELECTIONS |
3328 | { | |
3afe33e7 RS |
3329 | #ifdef USE_X_TOOLKIT |
3330 | if (x_window_to_frame (event.xselectionrequest.owner)) | |
3331 | { | |
3332 | #endif /* USE_X_TOOLKIT */ | |
d56a553a RS |
3333 | XSelectionRequestEvent *eventp = (XSelectionRequestEvent *) &event; |
3334 | ||
3335 | if (numchars == 0) | |
3336 | abort (); | |
3337 | ||
3338 | bufp->kind = selection_request_event; | |
3339 | SELECTION_EVENT_DISPLAY (bufp) = eventp->display; | |
3340 | SELECTION_EVENT_REQUESTOR (bufp) = eventp->requestor; | |
3341 | SELECTION_EVENT_SELECTION (bufp) = eventp->selection; | |
3342 | SELECTION_EVENT_TARGET (bufp) = eventp->target; | |
3343 | SELECTION_EVENT_PROPERTY (bufp) = eventp->property; | |
3344 | SELECTION_EVENT_TIME (bufp) = eventp->time; | |
3345 | bufp++; | |
3346 | ||
3347 | count += 1; | |
3348 | numchars -= 1; | |
3afe33e7 | 3349 | #ifdef USE_X_TOOLKIT |
d56a553a | 3350 | } |
3afe33e7 RS |
3351 | else |
3352 | goto OTHER; | |
3353 | #endif /* USE_X_TOOLKIT */ | |
3354 | } | |
3355 | #else /* not NEW_SELECTIONS */ | |
dc6f92b8 | 3356 | x_answer_selection_request (event); |
3afe33e7 | 3357 | #endif /* not NEW_SELECTIONS */ |
dc6f92b8 JB |
3358 | break; |
3359 | ||
3360 | case PropertyNotify: | |
d56a553a | 3361 | #ifdef NEW_SELECTIONS |
3afe33e7 RS |
3362 | #ifdef USE_X_TOOLKIT |
3363 | if (x_any_window_to_frame (event.xproperty.window)) | |
3364 | x_handle_property_notify (&event); | |
3365 | else | |
3366 | goto OTHER; | |
3367 | #else /* not USE_X_TOOLKIT */ | |
d56a553a | 3368 | x_handle_property_notify (&event); |
3afe33e7 RS |
3369 | #endif /* not USE_X_TOOLKIT */ |
3370 | #else /* not NEW_SELECTIONS */ | |
28430d3c JB |
3371 | /* If we're being told about a root window property, then it's |
3372 | a cut buffer change. */ | |
3373 | if (event.xproperty.window == ROOT_WINDOW) | |
3374 | x_invalidate_cut_buffer_cache (&event.xproperty); | |
3375 | ||
3376 | /* Otherwise, we're probably handling an incremental | |
3377 | selection transmission. */ | |
3378 | else | |
3379 | { | |
3380 | /* If we were to do this synchronously, there'd be no worry | |
3381 | about re-selecting. */ | |
3382 | x_send_incremental (event); | |
3383 | } | |
3afe33e7 | 3384 | #endif /* not NEW_SELECTIONS */ |
dc6f92b8 JB |
3385 | break; |
3386 | ||
3bd330d4 RS |
3387 | case ReparentNotify: |
3388 | f = x_window_to_frame (event.xreparent.window); | |
3389 | if (f) | |
3390 | f->display.x->parent_desc = event.xreparent.parent; | |
3391 | break; | |
3392 | ||
dc6f92b8 | 3393 | case Expose: |
f676886a JB |
3394 | f = x_window_to_frame (event.xexpose.window); |
3395 | if (f) | |
dc6f92b8 | 3396 | { |
3a88c238 | 3397 | if (f->async_visible == 0) |
dc6f92b8 | 3398 | { |
3a88c238 JB |
3399 | f->async_visible = 1; |
3400 | f->async_iconified = 0; | |
f676886a | 3401 | SET_FRAME_GARBAGED (f); |
dc6f92b8 JB |
3402 | } |
3403 | else | |
f451eb13 JB |
3404 | { |
3405 | dumprectangle (x_window_to_frame (event.xexpose.window), | |
3406 | event.xexpose.x, event.xexpose.y, | |
3407 | event.xexpose.width, event.xexpose.height); | |
f451eb13 JB |
3408 | } |
3409 | } | |
3410 | else | |
3411 | { | |
ab648270 JB |
3412 | struct scroll_bar *bar |
3413 | = x_window_to_scroll_bar (event.xexpose.window); | |
3afe33e7 | 3414 | |
f451eb13 | 3415 | if (bar) |
3afe33e7 RS |
3416 | x_scroll_bar_expose (bar, &event); |
3417 | #ifdef USE_X_TOOLKIT | |
3418 | else | |
3419 | goto OTHER; | |
3420 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
3421 | } |
3422 | break; | |
3423 | ||
3424 | case GraphicsExpose: /* This occurs when an XCopyArea's | |
3425 | source area was obscured or not | |
3426 | available.*/ | |
f451eb13 JB |
3427 | f = x_window_to_frame (event.xgraphicsexpose.drawable); |
3428 | if (f) | |
3429 | { | |
3430 | dumprectangle (f, | |
3431 | event.xgraphicsexpose.x, event.xgraphicsexpose.y, | |
3432 | event.xgraphicsexpose.width, | |
3433 | event.xgraphicsexpose.height); | |
f451eb13 | 3434 | } |
3afe33e7 RS |
3435 | #ifdef USE_X_TOOLKIT |
3436 | else | |
3437 | goto OTHER; | |
3438 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
3439 | break; |
3440 | ||
3441 | case NoExpose: /* This occurs when an XCopyArea's | |
3442 | source area was completely | |
3443 | available */ | |
3444 | break; | |
c118dd06 | 3445 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
3446 | case ExposeWindow: |
3447 | if (event.subwindow != 0) | |
3448 | break; /* duplicate event */ | |
f676886a JB |
3449 | f = x_window_to_frame (event.window); |
3450 | if (event.window == f->display.x->icon_desc) | |
dc6f92b8 | 3451 | { |
f676886a | 3452 | refreshicon (f); |
3a88c238 | 3453 | f->async_iconified = 1; |
dc6f92b8 | 3454 | } |
c118dd06 | 3455 | if (event.window == FRAME_X_WINDOW (f)) |
dc6f92b8 JB |
3456 | { |
3457 | /* Say must check all windows' needs_exposure flags. */ | |
3458 | expose_all_windows = 1; | |
f676886a | 3459 | f->display.x->needs_exposure = 1; |
3a88c238 | 3460 | f->async_visible = 1; |
dc6f92b8 JB |
3461 | } |
3462 | break; | |
3463 | ||
3464 | case ExposeRegion: | |
3465 | if (event.subwindow != 0) | |
3466 | break; /* duplicate event */ | |
f676886a JB |
3467 | f = x_window_to_frame (event.window); |
3468 | if (event.window == f->display.x->icon_desc) | |
dc6f92b8 | 3469 | { |
f676886a | 3470 | refreshicon (f); |
dc6f92b8 JB |
3471 | break; |
3472 | } | |
3473 | /* If window already needs full redraw, ignore this rectangle. */ | |
f676886a | 3474 | if (expose_all_windows && f->display.x->needs_exposure) |
dc6f92b8 JB |
3475 | break; |
3476 | /* Put the event on the queue of rectangles to redraw. */ | |
3477 | if (enqueue_event (&event, &x_expose_queue)) | |
3478 | /* If it is full, we can't record the rectangle, | |
3479 | so redraw this entire window. */ | |
3480 | { | |
3481 | /* Say must check all windows' needs_exposure flags. */ | |
3482 | expose_all_windows = 1; | |
f676886a | 3483 | f->display.x->needs_exposure = 1; |
dc6f92b8 JB |
3484 | } |
3485 | break; | |
3486 | ||
3487 | case ExposeCopy: | |
3488 | /* This should happen only when we are expecting it, | |
3489 | in x_read_exposes. */ | |
3490 | abort (); | |
c118dd06 | 3491 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
3492 | |
3493 | #ifdef HAVE_X11 | |
3494 | case UnmapNotify: | |
f451eb13 JB |
3495 | f = x_window_to_frame (event.xunmap.window); |
3496 | if (f) /* F may no longer exist if | |
f676886a | 3497 | the frame was deleted. */ |
f451eb13 JB |
3498 | { |
3499 | /* While a frame is unmapped, display generation is | |
3500 | disabled; you don't want to spend time updating a | |
3501 | display that won't ever be seen. */ | |
3502 | f->async_visible = 0; | |
9319ae23 RS |
3503 | /* The window manager never makes a window invisible |
3504 | ("withdrawn"); all it does is switch between visible | |
3505 | and iconified. Frames get into the invisible state | |
041b69ac | 3506 | only through x_make_frame_invisible. */ |
9319ae23 RS |
3507 | if (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)) |
3508 | f->async_iconified = 1; | |
f451eb13 | 3509 | } |
3afe33e7 RS |
3510 | #ifdef USE_X_TOOLKIT |
3511 | goto OTHER; | |
3512 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
3513 | break; |
3514 | ||
3515 | case MapNotify: | |
3afe33e7 RS |
3516 | #ifdef USE_X_TOOLKIT |
3517 | f = x_any_window_to_frame (event.xmap.window); | |
3518 | #else /* not USE_X_TOOLKIT */ | |
f676886a | 3519 | f = x_window_to_frame (event.xmap.window); |
3afe33e7 | 3520 | #endif /* not USE_X_TOOLKIT */ |
f676886a | 3521 | if (f) |
dc6f92b8 | 3522 | { |
3a88c238 JB |
3523 | f->async_visible = 1; |
3524 | f->async_iconified = 0; | |
dc6f92b8 JB |
3525 | |
3526 | /* wait_reading_process_input will notice this and update | |
f676886a JB |
3527 | the frame's display structures. */ |
3528 | SET_FRAME_GARBAGED (f); | |
dc6f92b8 | 3529 | } |
3afe33e7 RS |
3530 | #ifdef USE_X_TOOLKIT |
3531 | goto OTHER; | |
3532 | #endif /* USE_X_TOOLKIT */ | |
3533 | break; | |
dc6f92b8 JB |
3534 | |
3535 | /* Turn off processing if we become fully obscured. */ | |
3536 | case VisibilityNotify: | |
3537 | break; | |
3538 | ||
c118dd06 | 3539 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 | 3540 | case UnmapWindow: |
f676886a JB |
3541 | f = x_window_to_frame (event.window); |
3542 | if (event.window == f->display.x->icon_desc) | |
3a88c238 | 3543 | f->async_iconified = 0; |
c118dd06 | 3544 | if (event.window == FRAME_X_WINDOW (f)) |
3a88c238 | 3545 | f->async_visible = 0; |
dc6f92b8 | 3546 | break; |
c118dd06 | 3547 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
3548 | |
3549 | #ifdef HAVE_X11 | |
3550 | case KeyPress: | |
1dea5a83 | 3551 | f = x_any_window_to_frame (event.xkey.window); |
f451eb13 | 3552 | |
f676886a | 3553 | if (f != 0) |
dc6f92b8 | 3554 | { |
2d368234 | 3555 | KeySym keysym, orig_keysym; |
bf6d8fb9 RS |
3556 | /* al%imercury@uunet.uu.net says that making this 81 instead of |
3557 | 80 fixed a bug whereby meta chars made his Emacs hang. */ | |
3558 | unsigned char copy_buffer[81]; | |
64bb1782 RS |
3559 | int modifiers; |
3560 | ||
dfeccd2d JB |
3561 | event.xkey.state |
3562 | |= x_emacs_to_x_modifiers (extra_keyboard_modifiers); | |
64bb1782 | 3563 | modifiers = event.xkey.state; |
3a2712f9 | 3564 | |
11edeb03 | 3565 | /* This will have to go some day... */ |
752a043f JB |
3566 | |
3567 | /* make_lispy_event turns chars into control chars. | |
3568 | Don't do it here because XLookupString is too eager. */ | |
3569 | event.xkey.state &= ~ControlMask; | |
11edeb03 JB |
3570 | nbytes = |
3571 | XLookupString (&event.xkey, copy_buffer, 80, &keysym, | |
3572 | &compose_status); | |
dc6f92b8 | 3573 | |
55123275 JB |
3574 | /* Strip off the vendor-specific keysym bit, and take a shot |
3575 | at recognizing the codes. HP servers have extra keysyms | |
3576 | that fit into the MiscFunctionKey category. */ | |
2d368234 | 3577 | orig_keysym = keysym; |
55123275 JB |
3578 | keysym &= ~(1<<28); |
3579 | ||
dc6f92b8 JB |
3580 | if (numchars > 1) |
3581 | { | |
64a07219 JB |
3582 | if (((keysym >= XK_BackSpace && keysym <= XK_Escape) |
3583 | || keysym == XK_Delete | |
3584 | || IsCursorKey (keysym) /* 0xff50 <= x < 0xff60 */ | |
3585 | || IsMiscFunctionKey (keysym) /* 0xff60 <= x < VARIES */ | |
c34790e0 | 3586 | #ifdef HPUX |
64a07219 JB |
3587 | /* This recognizes the "extended function keys". |
3588 | It seems there's no cleaner way. | |
3589 | Test IsModifierKey to avoid handling mode_switch | |
3590 | incorrectly. */ | |
3591 | || ((unsigned) (keysym) >= XK_Select | |
3592 | && (unsigned)(keysym) < XK_KP_Space) | |
69388238 RS |
3593 | #endif |
3594 | #ifdef XK_dead_circumflex | |
3595 | || orig_keysym == XK_dead_circumflex | |
3596 | #endif | |
3597 | #ifdef XK_dead_grave | |
3598 | || orig_keysym == XK_dead_grave | |
3599 | #endif | |
3600 | #ifdef XK_dead_tilde | |
3601 | || orig_keysym == XK_dead_tilde | |
3602 | #endif | |
3603 | #ifdef XK_dead_diaeresis | |
3604 | || orig_keysym == XK_dead_diaeresis | |
3605 | #endif | |
3606 | #ifdef XK_dead_macron | |
3607 | || orig_keysym == XK_dead_macron | |
3608 | #endif | |
3609 | #ifdef XK_dead_degree | |
3610 | || orig_keysym == XK_dead_degree | |
3611 | #endif | |
3612 | #ifdef XK_dead_acute | |
3613 | || orig_keysym == XK_dead_acute | |
3614 | #endif | |
3615 | #ifdef XK_dead_cedilla | |
3616 | || orig_keysym == XK_dead_cedilla | |
3617 | #endif | |
3618 | #ifdef XK_dead_breve | |
3619 | || orig_keysym == XK_dead_breve | |
3620 | #endif | |
3621 | #ifdef XK_dead_ogonek | |
3622 | || orig_keysym == XK_dead_ogonek | |
3623 | #endif | |
3624 | #ifdef XK_dead_caron | |
3625 | || orig_keysym == XK_dead_caron | |
3626 | #endif | |
3627 | #ifdef XK_dead_doubleacute | |
3628 | || orig_keysym == XK_dead_doubleacute | |
3629 | #endif | |
3630 | #ifdef XK_dead_abovedot | |
3631 | || orig_keysym == XK_dead_abovedot | |
c34790e0 | 3632 | #endif |
64a07219 JB |
3633 | || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */ |
3634 | || IsFunctionKey (keysym) /* 0xffbe <= x < 0xffe1 */ | |
3635 | || x_is_vendor_fkey (orig_keysym)) | |
7719aa06 RS |
3636 | && ! (IsModifierKey (orig_keysym) |
3637 | #ifndef HAVE_X11R5 | |
3638 | #ifdef XK_Mode_switch | |
3639 | || ((unsigned)(orig_keysym) == XK_Mode_switch) | |
3640 | #endif | |
3641 | #ifdef XK_Num_Lock | |
3642 | || ((unsigned)(orig_keysym) == XK_Num_Lock) | |
3643 | #endif | |
3644 | #endif /* not HAVE_X11R5 */ | |
3645 | )) | |
dc6f92b8 | 3646 | { |
10e6549c RS |
3647 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
3648 | temp_index = 0; | |
3649 | temp_buffer[temp_index++] = keysym; | |
dc6f92b8 | 3650 | bufp->kind = non_ascii_keystroke; |
69388238 | 3651 | bufp->code = keysym; |
12ba150f | 3652 | XSET (bufp->frame_or_window, Lisp_Frame, f); |
dfeccd2d | 3653 | bufp->modifiers = x_x_to_emacs_modifiers (modifiers); |
1113d9db | 3654 | bufp->timestamp = event.xkey.time; |
dc6f92b8 JB |
3655 | bufp++; |
3656 | count++; | |
3657 | numchars--; | |
3658 | } | |
3659 | else if (numchars > nbytes) | |
3660 | { | |
3661 | register int i; | |
3662 | ||
10e6549c | 3663 | for (i = 0; i < nbytes; i++) |
dc6f92b8 | 3664 | { |
10e6549c RS |
3665 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
3666 | temp_index = 0; | |
3667 | temp_buffer[temp_index++] = copy_buffer[i]; | |
dc6f92b8 | 3668 | bufp->kind = ascii_keystroke; |
69388238 | 3669 | bufp->code = copy_buffer[i]; |
12ba150f | 3670 | XSET (bufp->frame_or_window, Lisp_Frame, f); |
dfeccd2d | 3671 | bufp->modifiers = x_x_to_emacs_modifiers (modifiers); |
1113d9db | 3672 | bufp->timestamp = event.xkey.time; |
dc6f92b8 JB |
3673 | bufp++; |
3674 | } | |
dc6f92b8 JB |
3675 | |
3676 | count += nbytes; | |
3677 | numchars -= nbytes; | |
3678 | } | |
10e6549c RS |
3679 | else |
3680 | abort (); | |
dc6f92b8 | 3681 | } |
10e6549c RS |
3682 | else |
3683 | abort (); | |
dc6f92b8 JB |
3684 | } |
3685 | break; | |
c118dd06 | 3686 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
3687 | case KeyPressed: |
3688 | { | |
3689 | register char *where_mapping; | |
3690 | ||
f676886a | 3691 | f = x_window_to_frame (event.window); |
dc6f92b8 | 3692 | /* Ignore keys typed on icon windows. */ |
f676886a | 3693 | if (f != 0 && event.window == f->display.x->icon_desc) |
dc6f92b8 JB |
3694 | break; |
3695 | where_mapping = XLookupMapping (&event, &nbytes); | |
3696 | /* Nasty fix for arrow keys */ | |
3697 | if (!nbytes && IsCursorKey (event.detail & 0xff)) | |
3698 | { | |
3699 | switch (event.detail & 0xff) | |
3700 | { | |
3701 | case KC_CURSOR_LEFT: | |
3702 | where_mapping = "\002"; | |
3703 | break; | |
3704 | case KC_CURSOR_RIGHT: | |
3705 | where_mapping = "\006"; | |
3706 | break; | |
3707 | case KC_CURSOR_UP: | |
3708 | where_mapping = "\020"; | |
3709 | break; | |
3710 | case KC_CURSOR_DOWN: | |
3711 | where_mapping = "\016"; | |
3712 | break; | |
3713 | } | |
3714 | nbytes = 1; | |
3715 | } | |
3716 | if (numchars - nbytes > 0) | |
3717 | { | |
3718 | register int i; | |
3719 | ||
3720 | for (i = 0; i < nbytes; i++) | |
3721 | { | |
3722 | bufp->kind = ascii_keystroke; | |
69388238 | 3723 | bufp->code = where_mapping[i]; |
90e65f07 | 3724 | XSET (bufp->time, Lisp_Int, event.xkey.time); |
12ba150f | 3725 | XSET (bufp->frame_or_window, Lisp_Frame, f); |
dc6f92b8 JB |
3726 | bufp++; |
3727 | } | |
3728 | count += nbytes; | |
3729 | numchars -= nbytes; | |
3730 | } | |
3731 | } | |
3732 | break; | |
c118dd06 | 3733 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
3734 | |
3735 | #ifdef HAVE_X11 | |
f451eb13 JB |
3736 | |
3737 | /* Here's a possible interpretation of the whole | |
3738 | FocusIn-EnterNotify FocusOut-LeaveNotify mess. If you get a | |
3739 | FocusIn event, you have to get a FocusOut event before you | |
3740 | relinquish the focus. If you haven't received a FocusIn event, | |
3741 | then a mere LeaveNotify is enough to free you. */ | |
3742 | ||
dc6f92b8 | 3743 | case EnterNotify: |
1dea5a83 | 3744 | f = x_any_window_to_frame (event.xcrossing.window); |
6d4238f3 | 3745 | |
f451eb13 | 3746 | if (event.xcrossing.focus) /* Entered Window */ |
dc6f92b8 | 3747 | { |
dc6f92b8 | 3748 | /* Avoid nasty pop/raise loops. */ |
f676886a JB |
3749 | if (f && (!(f->auto_raise) |
3750 | || !(f->auto_lower) | |
dc6f92b8 JB |
3751 | || (event.xcrossing.time - enter_timestamp) > 500)) |
3752 | { | |
f676886a | 3753 | x_new_focus_frame (f); |
dc6f92b8 JB |
3754 | enter_timestamp = event.xcrossing.time; |
3755 | } | |
dc6f92b8 | 3756 | } |
f676886a JB |
3757 | else if (f == x_focus_frame) |
3758 | x_new_focus_frame (0); | |
3afe33e7 RS |
3759 | #ifdef USE_X_TOOLKIT |
3760 | goto OTHER; | |
3761 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
3762 | break; |
3763 | ||
3764 | case FocusIn: | |
1dea5a83 | 3765 | f = x_any_window_to_frame (event.xfocus.window); |
f451eb13 JB |
3766 | if (event.xfocus.detail != NotifyPointer) |
3767 | x_focus_event_frame = f; | |
f676886a JB |
3768 | if (f) |
3769 | x_new_focus_frame (f); | |
3afe33e7 RS |
3770 | #ifdef USE_X_TOOLKIT |
3771 | goto OTHER; | |
3772 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
3773 | break; |
3774 | ||
f451eb13 | 3775 | |
dc6f92b8 | 3776 | case LeaveNotify: |
1dea5a83 | 3777 | f = x_any_window_to_frame (event.xcrossing.window); |
b1c884c3 | 3778 | |
b8009dd1 RS |
3779 | if (f == mouse_face_mouse_frame) |
3780 | /* If we move outside the frame, | |
3781 | then we're certainly no longer on any text in the frame. */ | |
3782 | clear_mouse_face (); | |
3783 | ||
f451eb13 JB |
3784 | if (event.xcrossing.focus) |
3785 | { | |
3786 | if (! x_focus_event_frame) | |
3787 | x_new_focus_frame (0); | |
3788 | else | |
f676886a | 3789 | x_new_focus_frame (f); |
f451eb13 JB |
3790 | } |
3791 | else | |
3792 | { | |
3793 | if (f == x_focus_event_frame) | |
3794 | x_focus_event_frame = 0; | |
3795 | if (f == x_focus_frame) | |
f676886a | 3796 | x_new_focus_frame (0); |
dc6f92b8 | 3797 | } |
3afe33e7 RS |
3798 | #ifdef USE_X_TOOLKIT |
3799 | goto OTHER; | |
3800 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
3801 | break; |
3802 | ||
3803 | case FocusOut: | |
1dea5a83 | 3804 | f = x_any_window_to_frame (event.xfocus.window); |
f451eb13 JB |
3805 | if (event.xfocus.detail != NotifyPointer |
3806 | && f == x_focus_event_frame) | |
3807 | x_focus_event_frame = 0; | |
f676886a JB |
3808 | if (f && f == x_focus_frame) |
3809 | x_new_focus_frame (0); | |
3afe33e7 RS |
3810 | #ifdef USE_X_TOOLKIT |
3811 | goto OTHER; | |
3812 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
3813 | break; |
3814 | ||
c118dd06 | 3815 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
3816 | |
3817 | case EnterWindow: | |
3818 | if ((event.detail & 0xFF) == 1) | |
3819 | break; /* Coming from our own subwindow */ | |
3820 | if (event.subwindow != 0) | |
3821 | break; /* Entering our own subwindow. */ | |
3822 | ||
3823 | { | |
f676886a JB |
3824 | f = x_window_to_frame (event.window); |
3825 | x_mouse_frame = f; | |
dc6f92b8 | 3826 | |
f676886a | 3827 | x_new_focus_frame (f); |
dc6f92b8 JB |
3828 | } |
3829 | break; | |
3830 | ||
3831 | case LeaveWindow: | |
3832 | if ((event.detail & 0xFF) == 1) | |
3833 | break; /* Entering our own subwindow */ | |
3834 | if (event.subwindow != 0) | |
3835 | break; /* Leaving our own subwindow. */ | |
3836 | ||
f676886a JB |
3837 | x_mouse_frame = 0; |
3838 | if (x_focus_frame == 0 | |
3839 | && x_input_frame != 0 | |
3840 | && x_input_frame == x_window_to_frame (event.window) | |
c118dd06 | 3841 | && event.window == FRAME_X_WINDOW (x_input_frame)) |
dc6f92b8 | 3842 | { |
f676886a JB |
3843 | f = x_input_frame; |
3844 | x_input_frame = 0; | |
3845 | if (f) | |
3846 | frame_unhighlight (f); | |
dc6f92b8 JB |
3847 | } |
3848 | break; | |
c118dd06 | 3849 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
3850 | |
3851 | #ifdef HAVE_X11 | |
3852 | case MotionNotify: | |
3853 | { | |
69388238 RS |
3854 | if (x_mouse_grabbed) |
3855 | f = last_mouse_frame; | |
3856 | else | |
3857 | f = x_window_to_frame (event.xmotion.window); | |
f676886a | 3858 | if (f) |
12ba150f | 3859 | note_mouse_movement (f, &event.xmotion); |
f451eb13 | 3860 | else |
dc6f92b8 | 3861 | { |
69388238 RS |
3862 | struct scroll_bar *bar |
3863 | = x_window_to_scroll_bar (event.xmotion.window); | |
f451eb13 JB |
3864 | |
3865 | if (bar) | |
ab648270 | 3866 | x_scroll_bar_note_movement (bar, &event); |
b8009dd1 RS |
3867 | |
3868 | /* If we move outside the frame, | |
3869 | then we're certainly no longer on any text in the frame. */ | |
3870 | clear_mouse_face (); | |
dc6f92b8 | 3871 | } |
dc6f92b8 | 3872 | } |
3afe33e7 RS |
3873 | #ifdef USE_X_TOOLKIT |
3874 | goto OTHER; | |
3875 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
3876 | break; |
3877 | ||
3878 | case ConfigureNotify: | |
13ce2d73 | 3879 | f = x_any_window_to_frame (event.xconfigure.window); |
3afe33e7 | 3880 | #ifdef USE_X_TOOLKIT |
13ce2d73 FP |
3881 | if (f |
3882 | && ! event.xconfigure.send_event | |
3883 | && (event.xconfigure.window == XtWindow (f->display.x->widget))) | |
3884 | { | |
3885 | Window win, child; | |
3886 | int win_x, win_y; | |
3887 | ||
3888 | /* Find the position of the outside upper-left corner of | |
3889 | the window, in the root coordinate system. Don't | |
3890 | refer to the parent window here; we may be processing | |
3891 | this event after the window manager has changed our | |
3892 | parent, but before we have reached the ReparentNotify. */ | |
3893 | XTranslateCoordinates (x_current_display, | |
3894 | ||
3895 | /* From-window, to-window. */ | |
3896 | XtWindow (f->display.x->widget), | |
3897 | ROOT_WINDOW, | |
3898 | ||
3899 | /* From-position, to-position. */ | |
3900 | -event.xconfigure.border_width, | |
3901 | -event.xconfigure.border_width, | |
3902 | &win_x, &win_y, | |
3903 | ||
3904 | /* Child of win. */ | |
3905 | &child); | |
3906 | event.xconfigure.x = win_x; | |
3907 | event.xconfigure.y = win_y; | |
3908 | ||
3909 | f->display.x->pixel_width = event.xconfigure.width; | |
3910 | f->display.x->pixel_height = event.xconfigure.height; | |
3911 | f->display.x->left_pos = event.xconfigure.x; | |
3912 | f->display.x->top_pos = event.xconfigure.y; | |
3913 | } | |
3914 | goto OTHER; | |
3afe33e7 | 3915 | #else /* not USE_X_TOOLKIT */ |
dbc4e1c1 JB |
3916 | if (f) |
3917 | { | |
3918 | int rows = PIXEL_TO_CHAR_HEIGHT (f, event.xconfigure.height); | |
3919 | int columns = PIXEL_TO_CHAR_WIDTH (f, event.xconfigure.width); | |
3920 | ||
3921 | /* Even if the number of character rows and columns has | |
3922 | not changed, the font size may have changed, so we need | |
3923 | to check the pixel dimensions as well. */ | |
3924 | if (columns != f->width | |
3925 | || rows != f->height | |
3926 | || event.xconfigure.width != f->display.x->pixel_width | |
3927 | || event.xconfigure.height != f->display.x->pixel_height) | |
3928 | { | |
3929 | change_frame_size (f, rows, columns, 0, 1); | |
3930 | SET_FRAME_GARBAGED (f); | |
3931 | } | |
dc6f92b8 | 3932 | |
3bd330d4 | 3933 | if (! event.xconfigure.send_event) |
af395ec1 RS |
3934 | { |
3935 | Window win, child; | |
3936 | int win_x, win_y; | |
3937 | ||
6cc35d86 JB |
3938 | /* Find the position of the outside upper-left corner of |
3939 | the window, in the root coordinate system. Don't | |
3940 | refer to the parent window here; we may be processing | |
3941 | this event after the window manager has changed our | |
3942 | parent, but before we have reached the ReparentNotify. */ | |
af395ec1 RS |
3943 | XTranslateCoordinates (x_current_display, |
3944 | ||
3945 | /* From-window, to-window. */ | |
6cc35d86 | 3946 | f->display.x->window_desc, |
3bd330d4 | 3947 | ROOT_WINDOW, |
af395ec1 RS |
3948 | |
3949 | /* From-position, to-position. */ | |
6cc35d86 JB |
3950 | -event.xconfigure.border_width, |
3951 | -event.xconfigure.border_width, | |
af395ec1 RS |
3952 | &win_x, &win_y, |
3953 | ||
3954 | /* Child of win. */ | |
3955 | &child); | |
3956 | event.xconfigure.x = win_x; | |
3957 | event.xconfigure.y = win_y; | |
3958 | } | |
3959 | ||
dbc4e1c1 JB |
3960 | f->display.x->pixel_width = event.xconfigure.width; |
3961 | f->display.x->pixel_height = event.xconfigure.height; | |
3962 | f->display.x->left_pos = event.xconfigure.x; | |
3963 | f->display.x->top_pos = event.xconfigure.y; | |
3964 | } | |
3afe33e7 | 3965 | #endif /* not USE_X_TOOLKIT */ |
dbc4e1c1 | 3966 | break; |
dc6f92b8 JB |
3967 | |
3968 | case ButtonPress: | |
3969 | case ButtonRelease: | |
3970 | { | |
3971 | /* If we decide we want to generate an event to be seen | |
3972 | by the rest of Emacs, we put it here. */ | |
3973 | struct input_event emacs_event; | |
3974 | emacs_event.kind = no_event; | |
3975 | ||
f676886a JB |
3976 | f = x_window_to_frame (event.xbutton.window); |
3977 | if (f) | |
f451eb13 JB |
3978 | { |
3979 | if (!x_focus_frame || (f == x_focus_frame)) | |
69388238 | 3980 | construct_mouse_click (&emacs_event, &event, f); |
f451eb13 | 3981 | } |
dc6f92b8 | 3982 | else |
f451eb13 | 3983 | { |
ab648270 JB |
3984 | struct scroll_bar *bar = |
3985 | x_window_to_scroll_bar (event.xbutton.window); | |
f451eb13 JB |
3986 | |
3987 | if (bar) | |
ab648270 | 3988 | x_scroll_bar_handle_click (bar, &event, &emacs_event); |
3afe33e7 RS |
3989 | #ifdef USE_X_TOOLKIT |
3990 | else | |
3991 | { | |
3992 | f = x_any_window_to_frame (event.xbutton.window); | |
3993 | if (f && event.type == ButtonPress) | |
3994 | construct_menu_click (&emacs_event, | |
3995 | &event, f); | |
3996 | } | |
3997 | #endif /* USE_X_TOOLKIT */ | |
f451eb13 | 3998 | } |
dc6f92b8 JB |
3999 | |
4000 | if (numchars >= 1 && emacs_event.kind != no_event) | |
4001 | { | |
4002 | bcopy (&emacs_event, bufp, sizeof (struct input_event)); | |
4003 | bufp++; | |
4004 | count++; | |
4005 | numchars--; | |
4006 | } | |
3afe33e7 RS |
4007 | |
4008 | #ifdef USE_X_TOOLKIT | |
4009 | goto OTHER; | |
4010 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
4011 | } |
4012 | break; | |
4013 | ||
c118dd06 | 4014 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4015 | case ButtonPressed: |
4016 | case ButtonReleased: | |
f676886a JB |
4017 | f = x_window_to_frame (event.window); |
4018 | if (f) | |
dc6f92b8 | 4019 | { |
f676886a | 4020 | if (event.window == f->display.x->icon_desc) |
dc6f92b8 | 4021 | { |
f676886a | 4022 | x_make_frame_visible (f); |
dc6f92b8 JB |
4023 | |
4024 | if (warp_mouse_on_deiconify) | |
c118dd06 | 4025 | XWarpMouse (FRAME_X_WINDOW (f), 10, 10); |
dc6f92b8 JB |
4026 | break; |
4027 | } | |
c118dd06 | 4028 | if (event.window == FRAME_X_WINDOW (f)) |
dc6f92b8 | 4029 | { |
f676886a JB |
4030 | if (f->auto_raise) |
4031 | x_raise_frame (f); | |
dc6f92b8 JB |
4032 | } |
4033 | } | |
4034 | enqueue_event (&event, &x_mouse_queue); | |
4035 | if (numchars >= 2) | |
4036 | { | |
4037 | bufp->kind = ascii_keystroke; | |
69388238 | 4038 | bufp->code = 'X' & 037; /* C-x */ |
12ba150f | 4039 | XSET (bufp->frame_or_window, Lisp_Frame, f); |
90e65f07 | 4040 | XSET (bufp->time, Lisp_Int, event.xkey.time); |
dc6f92b8 JB |
4041 | bufp++; |
4042 | ||
4043 | bufp->kind = ascii_keystroke; | |
69388238 | 4044 | bufp->code = 0; /* C-@ */ |
12ba150f | 4045 | XSET (bufp->frame_or_window, Lisp_Frame, f); |
90e65f07 | 4046 | XSET (bufp->time, Lisp_Int, event.xkey.time); |
dc6f92b8 JB |
4047 | bufp++; |
4048 | ||
4049 | count += 2; | |
4050 | numchars -= 2; | |
4051 | } | |
4052 | break; | |
c118dd06 | 4053 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4054 | |
4055 | #ifdef HAVE_X11 | |
4056 | ||
4057 | case CirculateNotify: | |
4058 | break; | |
4059 | case CirculateRequest: | |
4060 | break; | |
4061 | ||
c118dd06 | 4062 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4063 | |
4064 | case MappingNotify: | |
11edeb03 JB |
4065 | /* Someone has changed the keyboard mapping - update the |
4066 | local cache. */ | |
4067 | switch (event.xmapping.request) | |
4068 | { | |
4069 | case MappingModifier: | |
4070 | x_find_modifier_meanings (); | |
4071 | /* This is meant to fall through. */ | |
4072 | case MappingKeyboard: | |
4073 | XRefreshKeyboardMapping (&event.xmapping); | |
4074 | } | |
3afe33e7 RS |
4075 | #ifdef USE_X_TOOLKIT |
4076 | goto OTHER; | |
4077 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
4078 | break; |
4079 | ||
4080 | default: | |
3afe33e7 RS |
4081 | #ifdef USE_X_TOOLKIT |
4082 | OTHER: | |
4083 | BLOCK_INPUT; | |
4084 | XtDispatchEvent (&event); | |
4085 | UNBLOCK_INPUT; | |
4086 | #endif /* USE_X_TOOLKIT */ | |
dc6f92b8 JB |
4087 | break; |
4088 | } | |
4089 | } | |
4090 | ||
502add23 RS |
4091 | #ifdef X_IO_BUG |
4092 | if (! event_found) | |
4093 | /* On some systems, an X bug causes Emacs to get no more events | |
7071e5dd | 4094 | when the window is destroyed. Detect that. (1994.) */ |
502add23 RS |
4095 | XNoOp (x_current_display); |
4096 | #endif /* X_IO_BUG */ | |
4097 | ||
7071e5dd RS |
4098 | #if 0 /* This fails for serial-line connections to the X server, |
4099 | because the characters arrive one by one, and a partial | |
4100 | command makes select return but gives nothing to read. | |
4101 | We'll have to hope that the bug that this tried to fix | |
4102 | in 1988 has been fixed in Xlib or the X server. */ | |
dc6f92b8 JB |
4103 | #ifdef HAVE_SELECT |
4104 | if (expected && ! event_found) | |
4105 | { | |
4106 | /* AOJ 880406: if select returns true but XPending doesn't, it means that | |
4107 | there is an EOF condition; in other words, that X has died. | |
4108 | Act as if there had been a hangup. */ | |
dc6f92b8 | 4109 | int fd = ConnectionNumber (x_current_display); |
307feb1f | 4110 | SELECT_TYPE mask, junk1, junk2; |
66f55a9d | 4111 | EMACS_TIME timeout; |
dc6f92b8 | 4112 | |
61c3ce62 RS |
4113 | FD_ZERO (&mask); |
4114 | FD_SET (fd, &mask); | |
66f55a9d | 4115 | EMACS_SET_SECS_USECS (timeout, 0, 0); |
307feb1f RS |
4116 | FD_ZERO (&junk1); |
4117 | FD_ZERO (&junk2); | |
4118 | if (0 != select (fd + 1, &mask, &junk1, &junk2, &timeout) | |
dc6f92b8 JB |
4119 | && !XStuffPending ()) |
4120 | kill (getpid (), SIGHUP); | |
4121 | } | |
61c3ce62 | 4122 | #endif /* HAVE_SELECT */ |
7071e5dd | 4123 | #endif /* 0 */ |
dc6f92b8 | 4124 | |
f451eb13 | 4125 | #ifndef HAVE_X11 |
f676886a | 4126 | if (updating_frame == 0) |
dc6f92b8 | 4127 | x_do_pending_expose (); |
f451eb13 | 4128 | #endif |
dc6f92b8 JB |
4129 | |
4130 | UNBLOCK_INPUT; | |
4131 | return count; | |
4132 | } | |
4133 | ||
4134 | #ifndef HAVE_X11 | |
4135 | /* Read and process only Expose events | |
4136 | until we get an ExposeCopy event; then return. | |
4137 | This is used in insert/delete line. | |
4138 | We assume input is already blocked. */ | |
4139 | ||
4140 | static void | |
4141 | x_read_exposes () | |
4142 | { | |
f676886a | 4143 | struct frame *f; |
dc6f92b8 JB |
4144 | XKeyPressedEvent event; |
4145 | ||
4146 | while (1) | |
4147 | { | |
4148 | /* while there are more events*/ | |
4149 | XMaskEvent (ExposeWindow | ExposeRegion | ExposeCopy, &event); | |
4150 | switch (event.type) | |
4151 | { | |
4152 | case ExposeWindow: | |
4153 | if (event.subwindow != 0) | |
4154 | break; /* duplicate event */ | |
f676886a JB |
4155 | f = x_window_to_frame (event.window); |
4156 | if (event.window == f->display.x->icon_desc) | |
dc6f92b8 | 4157 | { |
f676886a | 4158 | refreshicon (f); |
dc6f92b8 JB |
4159 | break; |
4160 | } | |
c118dd06 | 4161 | if (event.window == FRAME_X_WINDOW (f)) |
dc6f92b8 JB |
4162 | { |
4163 | expose_all_windows = 1; | |
f676886a | 4164 | f->display.x->needs_exposure = 1; |
dc6f92b8 JB |
4165 | break; |
4166 | } | |
4167 | break; | |
4168 | ||
4169 | case ExposeRegion: | |
4170 | if (event.subwindow != 0) | |
4171 | break; /* duplicate event */ | |
f676886a JB |
4172 | f = x_window_to_frame (event.window); |
4173 | if (event.window == f->display.x->icon_desc) | |
dc6f92b8 | 4174 | { |
f676886a | 4175 | refreshicon (f); |
dc6f92b8 JB |
4176 | break; |
4177 | } | |
4178 | /* If window already needs full redraw, ignore this rectangle. */ | |
f676886a | 4179 | if (expose_all_windows && f->display.x->needs_exposure) |
dc6f92b8 JB |
4180 | break; |
4181 | /* Put the event on the queue of rectangles to redraw. */ | |
4182 | if (enqueue_event (&event, &x_expose_queue)) | |
4183 | /* If it is full, we can't record the rectangle, | |
4184 | so redraw this entire window. */ | |
4185 | { | |
4186 | /* Say must check all windows' needs_exposure flags. */ | |
4187 | expose_all_windows = 1; | |
f676886a | 4188 | f->display.x->needs_exposure = 1; |
dc6f92b8 JB |
4189 | } |
4190 | break; | |
4191 | ||
4192 | case ExposeCopy: | |
4193 | return; | |
4194 | } | |
4195 | } | |
4196 | } | |
4197 | #endif /* HAVE_X11 */ | |
4198 | ||
dc6f92b8 | 4199 | \f |
f451eb13 JB |
4200 | /* Drawing the cursor. */ |
4201 | ||
4202 | ||
dc6f92b8 JB |
4203 | /* Draw a hollow box cursor. Don't change the inside of the box. */ |
4204 | ||
4205 | static void | |
f676886a JB |
4206 | x_draw_box (f) |
4207 | struct frame *f; | |
dc6f92b8 | 4208 | { |
12ba150f JB |
4209 | int left = CHAR_TO_PIXEL_COL (f, f->cursor_x); |
4210 | int top = CHAR_TO_PIXEL_ROW (f, f->cursor_y); | |
f676886a | 4211 | int width = FONT_WIDTH (f->display.x->font); |
a27f9f86 | 4212 | int height = f->display.x->line_height; |
dc6f92b8 JB |
4213 | |
4214 | #ifdef HAVE_X11 | |
c118dd06 | 4215 | XDrawRectangle (x_current_display, FRAME_X_WINDOW (f), |
f676886a | 4216 | f->display.x->cursor_gc, |
dc6f92b8 | 4217 | left, top, width - 1, height - 1); |
c118dd06 JB |
4218 | #else /* ! defined (HAVE_X11) */ |
4219 | XPixSet (FRAME_X_WINDOW (f), | |
dc6f92b8 | 4220 | left, top, width, 1, |
f676886a | 4221 | f->display.x->cursor_pixel); |
dc6f92b8 | 4222 | |
c118dd06 | 4223 | XPixSet (FRAME_X_WINDOW (f), |
dc6f92b8 | 4224 | left, top, 1, height, |
f676886a | 4225 | f->display.x->cursor_pixel); |
dc6f92b8 | 4226 | |
c118dd06 | 4227 | XPixSet (FRAME_X_WINDOW (f), |
dc6f92b8 | 4228 | left+width-1, top, 1, height, |
f676886a | 4229 | f->display.x->cursor_pixel); |
dc6f92b8 | 4230 | |
c118dd06 | 4231 | XPixSet (FRAME_X_WINDOW (f), |
dc6f92b8 | 4232 | left, top+height-1, width, 1, |
f676886a | 4233 | f->display.x->cursor_pixel); |
c118dd06 | 4234 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4235 | } |
4236 | ||
f676886a | 4237 | /* Clear the cursor of frame F to background color, |
dc6f92b8 JB |
4238 | and mark the cursor as not shown. |
4239 | This is used when the text where the cursor is | |
4240 | is about to be rewritten. */ | |
4241 | ||
4242 | static void | |
f676886a JB |
4243 | clear_cursor (f) |
4244 | struct frame *f; | |
dc6f92b8 JB |
4245 | { |
4246 | int mask; | |
4247 | ||
f451eb13 | 4248 | if (! FRAME_VISIBLE_P (f) |
f676886a | 4249 | || f->phys_cursor_x < 0) |
dc6f92b8 JB |
4250 | return; |
4251 | ||
4252 | #ifdef HAVE_X11 | |
f676886a | 4253 | x_display_cursor (f, 0); |
c118dd06 JB |
4254 | #else /* ! defined (HAVE_X11) */ |
4255 | XPixSet (FRAME_X_WINDOW (f), | |
12ba150f JB |
4256 | CHAR_TO_PIXEL_COL (f, f->phys_cursor_x), |
4257 | CHAR_TO_PIXEL_ROW (f, f->phys_cursor_y), | |
a27f9f86 | 4258 | FONT_WIDTH (f->display.x->font), f->display.x->line_height, |
f676886a | 4259 | f->display.x->background_pixel); |
c118dd06 | 4260 | #endif /* ! defined (HAVE_X11) */ |
f676886a | 4261 | f->phys_cursor_x = -1; |
dc6f92b8 JB |
4262 | } |
4263 | ||
f676886a | 4264 | /* Redraw the glyph at ROW, COLUMN on frame F, in the style |
90e65f07 JB |
4265 | HIGHLIGHT. HIGHLIGHT is as defined for dumpglyphs. Return the |
4266 | glyph drawn. */ | |
dc6f92b8 JB |
4267 | |
4268 | static void | |
f676886a JB |
4269 | x_draw_single_glyph (f, row, column, glyph, highlight) |
4270 | struct frame *f; | |
dc6f92b8 | 4271 | int row, column; |
90e65f07 | 4272 | GLYPH glyph; |
dc6f92b8 JB |
4273 | int highlight; |
4274 | { | |
f676886a | 4275 | dumpglyphs (f, |
12ba150f JB |
4276 | CHAR_TO_PIXEL_COL (f, column), |
4277 | CHAR_TO_PIXEL_ROW (f, row), | |
07e34cb0 | 4278 | &glyph, 1, highlight); |
dc6f92b8 JB |
4279 | } |
4280 | ||
dc6f92b8 | 4281 | static void |
dbc4e1c1 | 4282 | x_display_bar_cursor (f, on) |
f676886a | 4283 | struct frame *f; |
dc6f92b8 JB |
4284 | int on; |
4285 | { | |
f676886a | 4286 | struct frame_glyphs *current_glyphs = FRAME_CURRENT_GLYPHS (f); |
90e65f07 | 4287 | |
49d838ea JB |
4288 | /* This is pointless on invisible frames, and dangerous on garbaged |
4289 | frames; in the latter case, the frame may be in the midst of | |
4290 | changing its size, and curs_x and curs_y may be off the frame. */ | |
4291 | if (! FRAME_VISIBLE_P (f) || FRAME_GARBAGED_P (f)) | |
dbc4e1c1 JB |
4292 | return; |
4293 | ||
4294 | if (! on && f->phys_cursor_x < 0) | |
4295 | return; | |
4296 | ||
f676886a | 4297 | /* If we're not updating, then we want to use the current frame's |
1113d9db | 4298 | cursor position, not our local idea of where the cursor ought to be. */ |
f676886a | 4299 | if (f != updating_frame) |
1113d9db | 4300 | { |
f676886a JB |
4301 | curs_x = FRAME_CURSOR_X (f); |
4302 | curs_y = FRAME_CURSOR_Y (f); | |
1113d9db JB |
4303 | } |
4304 | ||
dbc4e1c1 JB |
4305 | /* If there is anything wrong with the current cursor state, remove it. */ |
4306 | if (f->phys_cursor_x >= 0 | |
4307 | && (!on | |
4308 | || f->phys_cursor_x != curs_x | |
4309 | || f->phys_cursor_y != curs_y | |
4310 | || f->display.x->current_cursor != bar_cursor)) | |
4311 | { | |
4312 | /* Erase the cursor by redrawing the character underneath it. */ | |
4313 | x_draw_single_glyph (f, f->phys_cursor_y, f->phys_cursor_x, | |
4314 | f->phys_cursor_glyph, | |
4315 | current_glyphs->highlight[f->phys_cursor_y]); | |
4316 | f->phys_cursor_x = -1; | |
4317 | } | |
4318 | ||
4319 | /* If we now need a cursor in the new place or in the new form, do it so. */ | |
4320 | if (on | |
4321 | && (f->phys_cursor_x < 0 | |
4322 | || (f->display.x->current_cursor != bar_cursor))) | |
4323 | { | |
4324 | f->phys_cursor_glyph | |
4325 | = ((current_glyphs->enable[curs_y] | |
4326 | && curs_x < current_glyphs->used[curs_y]) | |
4327 | ? current_glyphs->glyphs[curs_y][curs_x] | |
4328 | : SPACEGLYPH); | |
4329 | XFillRectangle (x_current_display, FRAME_X_WINDOW (f), | |
4330 | f->display.x->cursor_gc, | |
4331 | CHAR_TO_PIXEL_COL (f, curs_x), | |
4332 | CHAR_TO_PIXEL_ROW (f, curs_y), | |
a27f9f86 | 4333 | 1, f->display.x->line_height); |
dbc4e1c1 JB |
4334 | |
4335 | f->phys_cursor_x = curs_x; | |
4336 | f->phys_cursor_y = curs_y; | |
4337 | ||
4338 | f->display.x->current_cursor = bar_cursor; | |
4339 | } | |
4340 | ||
4341 | if (updating_frame != f) | |
4342 | XFlushQueue (); | |
4343 | } | |
4344 | ||
4345 | ||
4346 | /* Turn the displayed cursor of frame F on or off according to ON. | |
4347 | If ON is nonzero, where to put the cursor is specified | |
4348 | by F->cursor_x and F->cursor_y. */ | |
4349 | ||
4350 | static void | |
4351 | x_display_box_cursor (f, on) | |
4352 | struct frame *f; | |
4353 | int on; | |
4354 | { | |
4355 | struct frame_glyphs *current_glyphs = FRAME_CURRENT_GLYPHS (f); | |
4356 | ||
49d838ea JB |
4357 | /* This is pointless on invisible frames, and dangerous on garbaged |
4358 | frames; in the latter case, the frame may be in the midst of | |
4359 | changing its size, and curs_x and curs_y may be off the frame. */ | |
4360 | if (! FRAME_VISIBLE_P (f) || FRAME_GARBAGED_P (f)) | |
dc6f92b8 JB |
4361 | return; |
4362 | ||
4363 | /* If cursor is off and we want it off, return quickly. */ | |
f676886a | 4364 | if (!on && f->phys_cursor_x < 0) |
dc6f92b8 JB |
4365 | return; |
4366 | ||
dbc4e1c1 JB |
4367 | /* If we're not updating, then we want to use the current frame's |
4368 | cursor position, not our local idea of where the cursor ought to be. */ | |
4369 | if (f != updating_frame) | |
4370 | { | |
4371 | curs_x = FRAME_CURSOR_X (f); | |
4372 | curs_y = FRAME_CURSOR_Y (f); | |
4373 | } | |
4374 | ||
dc6f92b8 JB |
4375 | /* If cursor is currently being shown and we don't want it to be |
4376 | or it is in the wrong place, | |
4377 | or we want a hollow box and it's not so, (pout!) | |
4378 | erase it. */ | |
f676886a | 4379 | if (f->phys_cursor_x >= 0 |
dc6f92b8 | 4380 | && (!on |
f676886a JB |
4381 | || f->phys_cursor_x != curs_x |
4382 | || f->phys_cursor_y != curs_y | |
dbc4e1c1 | 4383 | || (f->display.x->current_cursor != hollow_box_cursor |
f676886a | 4384 | && (f != x_highlight_frame)))) |
dc6f92b8 JB |
4385 | { |
4386 | /* Erase the cursor by redrawing the character underneath it. */ | |
f676886a JB |
4387 | x_draw_single_glyph (f, f->phys_cursor_y, f->phys_cursor_x, |
4388 | f->phys_cursor_glyph, | |
4389 | current_glyphs->highlight[f->phys_cursor_y]); | |
4390 | f->phys_cursor_x = -1; | |
dc6f92b8 JB |
4391 | } |
4392 | ||
4393 | /* If we want to show a cursor, | |
4394 | or we want a box cursor and it's not so, | |
4395 | write it in the right place. */ | |
4396 | if (on | |
f676886a | 4397 | && (f->phys_cursor_x < 0 |
dbc4e1c1 | 4398 | || (f->display.x->current_cursor != filled_box_cursor |
f676886a | 4399 | && f == x_highlight_frame))) |
dc6f92b8 | 4400 | { |
f676886a | 4401 | f->phys_cursor_glyph |
1113d9db JB |
4402 | = ((current_glyphs->enable[curs_y] |
4403 | && curs_x < current_glyphs->used[curs_y]) | |
4404 | ? current_glyphs->glyphs[curs_y][curs_x] | |
90e65f07 | 4405 | : SPACEGLYPH); |
f676886a | 4406 | if (f != x_highlight_frame) |
dc6f92b8 | 4407 | { |
f676886a | 4408 | x_draw_box (f); |
dbc4e1c1 | 4409 | f->display.x->current_cursor = hollow_box_cursor; |
dc6f92b8 JB |
4410 | } |
4411 | else | |
4412 | { | |
f676886a JB |
4413 | x_draw_single_glyph (f, curs_y, curs_x, |
4414 | f->phys_cursor_glyph, 2); | |
dbc4e1c1 | 4415 | f->display.x->current_cursor = filled_box_cursor; |
dc6f92b8 JB |
4416 | } |
4417 | ||
f676886a JB |
4418 | f->phys_cursor_x = curs_x; |
4419 | f->phys_cursor_y = curs_y; | |
dc6f92b8 JB |
4420 | } |
4421 | ||
f676886a | 4422 | if (updating_frame != f) |
dc6f92b8 JB |
4423 | XFlushQueue (); |
4424 | } | |
4425 | ||
f676886a JB |
4426 | x_display_cursor (f, on) |
4427 | struct frame *f; | |
dc6f92b8 JB |
4428 | int on; |
4429 | { | |
f94397b5 KH |
4430 | BLOCK_INPUT; |
4431 | ||
dbc4e1c1 | 4432 | if (FRAME_DESIRED_CURSOR (f) == filled_box_cursor) |
f676886a | 4433 | x_display_box_cursor (f, on); |
dbc4e1c1 | 4434 | else if (FRAME_DESIRED_CURSOR (f) == bar_cursor) |
f676886a | 4435 | x_display_bar_cursor (f, on); |
dbc4e1c1 JB |
4436 | else |
4437 | /* Those are the only two we have implemented! */ | |
4438 | abort (); | |
f94397b5 KH |
4439 | |
4440 | UNBLOCK_INPUT; | |
dc6f92b8 JB |
4441 | } |
4442 | \f | |
4443 | /* Icons. */ | |
4444 | ||
f676886a | 4445 | /* Refresh bitmap kitchen sink icon for frame F |
dc6f92b8 JB |
4446 | when we get an expose event for it. */ |
4447 | ||
f676886a JB |
4448 | refreshicon (f) |
4449 | struct frame *f; | |
dc6f92b8 JB |
4450 | { |
4451 | #ifdef HAVE_X11 | |
4452 | /* Normally, the window manager handles this function. */ | |
c118dd06 | 4453 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4454 | int mask; |
4455 | ||
f676886a JB |
4456 | if (f->display.x->icon_bitmap_flag) |
4457 | XBitmapBitsPut (f->display.x->icon_desc, 0, 0, sink_width, sink_height, | |
dc6f92b8 JB |
4458 | sink_bits, BlackPixel, WHITE_PIX_DEFAULT, |
4459 | icon_bitmap, GXcopy, AllPlanes); | |
4460 | else | |
4461 | { | |
f676886a | 4462 | extern struct frame *selected_frame; |
dc6f92b8 JB |
4463 | struct Lisp_String *str; |
4464 | unsigned char *string; | |
4465 | ||
4466 | string | |
f676886a | 4467 | = XSTRING (XBUFFER (XWINDOW (f->selected_window)->buffer)->name)->data; |
dc6f92b8 | 4468 | |
f676886a | 4469 | if (f->display.x->icon_label != string) |
dc6f92b8 | 4470 | { |
f676886a JB |
4471 | f->display.x->icon_label = string; |
4472 | XChangeWindow (f->display.x->icon_desc, | |
dc6f92b8 JB |
4473 | XQueryWidth (string, icon_font_info->id) + 10, |
4474 | icon_font_info->height + 10); | |
4475 | } | |
4476 | ||
f676886a | 4477 | XText (f->display.x->icon_desc, 5, 5, string, |
dc6f92b8 JB |
4478 | str->size, icon_font_info->id, |
4479 | BLACK_PIX_DEFAULT, WHITE_PIX_DEFAULT); | |
4480 | } | |
4481 | XFlushQueue (); | |
c118dd06 | 4482 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4483 | } |
4484 | ||
dbc4e1c1 | 4485 | /* Make the x-window of frame F use the gnu icon bitmap. */ |
dc6f92b8 JB |
4486 | |
4487 | int | |
f676886a JB |
4488 | x_bitmap_icon (f) |
4489 | struct frame *f; | |
dc6f92b8 JB |
4490 | { |
4491 | int mask; | |
4492 | Window icon_window; | |
4493 | ||
c118dd06 | 4494 | if (FRAME_X_WINDOW (f) == 0) |
dc6f92b8 JB |
4495 | return 1; |
4496 | ||
4497 | #ifdef HAVE_X11 | |
8583db58 RS |
4498 | if (! icon_bitmap) |
4499 | icon_bitmap = | |
4500 | XCreateBitmapFromData (x_current_display, FRAME_X_WINDOW (f), | |
4501 | gnu_bits, gnu_width, gnu_height); | |
f676886a JB |
4502 | x_wm_set_icon_pixmap (f, icon_bitmap); |
4503 | f->display.x->icon_bitmap_flag = 1; | |
c118dd06 | 4504 | #else /* ! defined (HAVE_X11) */ |
f676886a | 4505 | if (f->display.x->icon_desc) |
dc6f92b8 | 4506 | { |
c118dd06 | 4507 | XClearIconWindow (FRAME_X_WINDOW (f)); |
f676886a | 4508 | XDestroyWindow (f->display.x->icon_desc); |
dc6f92b8 JB |
4509 | } |
4510 | ||
f676886a | 4511 | icon_window = XCreateWindow (f->display.x->parent_desc, |
dc6f92b8 JB |
4512 | 0, 0, sink_width, sink_height, |
4513 | 2, WhitePixmap, (Pixmap) NULL); | |
4514 | ||
4515 | if (icon_window == 0) | |
4516 | return 1; | |
4517 | ||
c118dd06 | 4518 | XSetIconWindow (FRAME_X_WINDOW (f), icon_window); |
dc6f92b8 JB |
4519 | XSelectInput (icon_window, ExposeWindow | UnmapWindow); |
4520 | ||
f676886a JB |
4521 | f->display.x->icon_desc = icon_window; |
4522 | f->display.x->icon_bitmap_flag = 1; | |
dc6f92b8 JB |
4523 | |
4524 | if (icon_bitmap == 0) | |
4525 | icon_bitmap | |
4526 | = XStoreBitmap (sink_mask_width, sink_mask_height, sink_mask_bits); | |
c118dd06 | 4527 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4528 | |
4529 | return 0; | |
4530 | } | |
4531 | ||
4532 | ||
f676886a | 4533 | /* Make the x-window of frame F use a rectangle with text. */ |
dc6f92b8 JB |
4534 | |
4535 | int | |
f676886a JB |
4536 | x_text_icon (f, icon_name) |
4537 | struct frame *f; | |
dc6f92b8 JB |
4538 | char *icon_name; |
4539 | { | |
4540 | #ifndef HAVE_X11 | |
4541 | int mask; | |
4542 | int width; | |
4543 | Window icon_window; | |
4544 | char *X_DefaultValue; | |
4545 | Bitmap b1; | |
4546 | ||
dc6f92b8 JB |
4547 | #ifndef WhitePixel |
4548 | #define WhitePixel 1 | |
c118dd06 | 4549 | #endif /* WhitePixel */ |
dc6f92b8 JB |
4550 | |
4551 | #ifndef BlackPixel | |
4552 | #define BlackPixel 0 | |
c118dd06 JB |
4553 | #endif /* BlackPixel */ |
4554 | #endif /* HAVE_X11 */ | |
dc6f92b8 | 4555 | |
c118dd06 | 4556 | if (FRAME_X_WINDOW (f) == 0) |
dc6f92b8 JB |
4557 | return 1; |
4558 | ||
dc6f92b8 JB |
4559 | #ifdef HAVE_X11 |
4560 | if (icon_name) | |
f676886a | 4561 | f->display.x->icon_label = icon_name; |
dc6f92b8 | 4562 | else |
f676886a JB |
4563 | if (! f->display.x->icon_label) |
4564 | f->display.x->icon_label = " *emacs* "; | |
dc6f92b8 | 4565 | |
dfeccd2d | 4566 | #if 0 |
c118dd06 | 4567 | XSetIconName (x_current_display, FRAME_X_WINDOW (f), |
f676886a | 4568 | (char *) f->display.x->icon_label); |
dfeccd2d | 4569 | #endif |
dc6f92b8 | 4570 | |
f676886a | 4571 | f->display.x->icon_bitmap_flag = 0; |
b1c884c3 | 4572 | x_wm_set_icon_pixmap (f, 0); |
c118dd06 | 4573 | #else /* ! defined (HAVE_X11) */ |
dbc4e1c1 JB |
4574 | if (icon_font_info == 0) |
4575 | icon_font_info | |
4576 | = XGetFont (XGetDefault (XDISPLAY | |
59653951 | 4577 | (char *) XSTRING (Vinvocation_name)->data, |
dbc4e1c1 JB |
4578 | "BodyFont")); |
4579 | ||
f676886a | 4580 | if (f->display.x->icon_desc) |
dc6f92b8 | 4581 | { |
c118dd06 | 4582 | XClearIconWindow (XDISPLAY FRAME_X_WINDOW (f)); |
f676886a | 4583 | XDestroyWindow (XDISPLAY f->display.x->icon_desc); |
dc6f92b8 JB |
4584 | } |
4585 | ||
4586 | if (icon_name) | |
f676886a | 4587 | f->display.x->icon_label = (unsigned char *) icon_name; |
dc6f92b8 | 4588 | else |
f676886a JB |
4589 | if (! f->display.x->icon_label) |
4590 | f->display.x->icon_label = XSTRING (f->name)->data; | |
dc6f92b8 | 4591 | |
f676886a JB |
4592 | width = XStringWidth (f->display.x->icon_label, icon_font_info, 0, 0); |
4593 | icon_window = XCreateWindow (f->display.x->parent_desc, | |
4594 | f->display.x->left_pos, | |
4595 | f->display.x->top_pos, | |
dc6f92b8 JB |
4596 | width + 10, icon_font_info->height + 10, |
4597 | 2, BlackPixmap, WhitePixmap); | |
4598 | ||
4599 | if (icon_window == 0) | |
4600 | return 1; | |
4601 | ||
c118dd06 | 4602 | XSetIconWindow (FRAME_X_WINDOW (f), icon_window); |
dc6f92b8 JB |
4603 | XSelectInput (icon_window, ExposeWindow | ExposeRegion | UnmapWindow | ButtonPressed); |
4604 | ||
f676886a JB |
4605 | f->display.x->icon_desc = icon_window; |
4606 | f->display.x->icon_bitmap_flag = 0; | |
4607 | f->display.x->icon_label = 0; | |
c118dd06 | 4608 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4609 | |
4610 | return 0; | |
4611 | } | |
4612 | \f | |
4746118a JB |
4613 | /* Handling X errors. */ |
4614 | ||
12ba150f JB |
4615 | /* Shut down Emacs in an orderly fashion, because of a SIGPIPE on the |
4616 | X server's connection, or an error reported via the X protocol. */ | |
16bd92ea | 4617 | |
4746118a | 4618 | static SIGTYPE |
c118dd06 | 4619 | x_connection_closed () |
4746118a JB |
4620 | { |
4621 | if (_Xdebug) | |
4622 | abort (); | |
12ba150f | 4623 | |
1cd2d6d4 | 4624 | shut_down_emacs (0, 1, Qnil); |
12ba150f JB |
4625 | |
4626 | exit (70); | |
4746118a JB |
4627 | } |
4628 | ||
8922af5f JB |
4629 | /* An X error handler which prints an error message and then kills |
4630 | Emacs. This is what's normally installed as Xlib's handler for | |
4631 | protocol errors. */ | |
c118dd06 JB |
4632 | static int |
4633 | x_error_quitter (display, error) | |
4634 | Display *display; | |
4635 | XErrorEvent *error; | |
4636 | { | |
4637 | char buf[256]; | |
dc6f92b8 | 4638 | |
c118dd06 JB |
4639 | /* Note that there is no real way portable across R3/R4 to get the |
4640 | original error handler. */ | |
dc6f92b8 | 4641 | |
c118dd06 JB |
4642 | XGetErrorText (display, error->error_code, buf, sizeof (buf)); |
4643 | fprintf (stderr, "X protocol error: %s on protocol request %d\n", | |
4644 | buf, error->request_code); | |
dc6f92b8 | 4645 | |
e09f9351 | 4646 | #if 0 |
12ba150f JB |
4647 | /* While we're testing Emacs 19, we'll just dump core whenever we |
4648 | get an X error, so we can figure out why it happened. */ | |
4649 | abort (); | |
e09f9351 | 4650 | #endif |
12ba150f | 4651 | |
c118dd06 | 4652 | x_connection_closed (); |
dc6f92b8 JB |
4653 | } |
4654 | ||
8922af5f JB |
4655 | /* A handler for X IO errors which prints an error message and then |
4656 | kills Emacs. This is what is always installed as Xlib's handler | |
4657 | for I/O errors. */ | |
4658 | static int | |
4659 | x_io_error_quitter (display) | |
4660 | Display *display; | |
4661 | { | |
4662 | fprintf (stderr, "Connection to X server %s lost.\n", | |
4663 | XDisplayName (DisplayString (display))); | |
4664 | ||
e09f9351 | 4665 | #if 0 |
8922af5f JB |
4666 | /* While we're testing Emacs 19, we'll just dump core whenever we |
4667 | get an X error, so we can figure out why it happened. */ | |
4668 | abort (); | |
e09f9351 | 4669 | #endif |
8922af5f JB |
4670 | |
4671 | x_connection_closed (); | |
4672 | } | |
4673 | ||
c118dd06 | 4674 | /* A buffer for storing X error messages. */ |
cef13e55 RS |
4675 | static char *x_caught_error_message; |
4676 | #define X_CAUGHT_ERROR_MESSAGE_SIZE 200 | |
c118dd06 JB |
4677 | |
4678 | /* An X error handler which stores the error message in | |
4679 | x_caught_error_message. This is what's installed when | |
4680 | x_catch_errors is in effect. */ | |
4681 | static int | |
4682 | x_error_catcher (display, error) | |
4683 | Display *display; | |
4684 | XErrorEvent *error; | |
4685 | { | |
4686 | XGetErrorText (display, error->error_code, | |
cef13e55 | 4687 | x_caught_error_message, X_CAUGHT_ERROR_MESSAGE_SIZE); |
c118dd06 JB |
4688 | } |
4689 | ||
4690 | ||
4691 | /* Begin trapping X errors. | |
dc6f92b8 | 4692 | |
c118dd06 JB |
4693 | After calling this function, X protocol errors no longer cause |
4694 | Emacs to exit; instead, they are recorded in x_cfc_error_message. | |
dc6f92b8 | 4695 | |
c118dd06 JB |
4696 | Calling x_check_errors signals an Emacs error if an X error has |
4697 | occurred since the last call to x_catch_errors or x_check_errors. | |
4698 | ||
4699 | Calling x_uncatch_errors resumes the normal error handling. */ | |
4700 | ||
bc20ebbf | 4701 | void x_catch_errors (), x_check_errors (), x_uncatch_errors (); |
c118dd06 JB |
4702 | |
4703 | void | |
4704 | x_catch_errors () | |
dc6f92b8 | 4705 | { |
c118dd06 JB |
4706 | /* Make sure any errors from previous requests have been dealt with. */ |
4707 | XSync (x_current_display, False); | |
dc6f92b8 | 4708 | |
c118dd06 | 4709 | /* Set up the error buffer. */ |
60f9aad3 | 4710 | x_caught_error_message |
cef13e55 RS |
4711 | = (char*) xmalloc (X_CAUGHT_ERROR_MESSAGE_SIZE); |
4712 | x_caught_error_message[0] = '\0'; | |
16bd92ea | 4713 | |
c118dd06 JB |
4714 | /* Install our little error handler. */ |
4715 | XHandleError (x_error_catcher); | |
4716 | } | |
16bd92ea | 4717 | |
c118dd06 JB |
4718 | /* If any X protocol errors have arrived since the last call to |
4719 | x_catch_errors or x_check_errors, signal an Emacs error using | |
4720 | sprintf (a buffer, FORMAT, the x error message text) as the text. */ | |
812361a1 | 4721 | |
c118dd06 JB |
4722 | void |
4723 | x_check_errors (format) | |
4724 | char *format; | |
4725 | { | |
4726 | /* Make sure to catch any errors incurred so far. */ | |
4727 | XSync (x_current_display, False); | |
16bd92ea | 4728 | |
cef13e55 | 4729 | if (x_caught_error_message[0]) |
c118dd06 | 4730 | { |
cef13e55 | 4731 | char buf[X_CAUGHT_ERROR_MESSAGE_SIZE + 56]; |
dc6f92b8 | 4732 | |
cef13e55 | 4733 | sprintf (buf, format, x_caught_error_message); |
c118dd06 JB |
4734 | x_uncatch_errors (); |
4735 | error (buf); | |
4736 | } | |
4737 | } | |
4738 | ||
b849c413 RS |
4739 | /* Nonzero if we had any X protocol errors since we did x_catch_errors. */ |
4740 | ||
4741 | int | |
4742 | x_had_errors_p () | |
4743 | { | |
4744 | /* Make sure to catch any errors incurred so far. */ | |
4745 | XSync (x_current_display, False); | |
4746 | ||
4747 | return x_caught_error_message[0] != 0; | |
4748 | } | |
4749 | ||
812361a1 RS |
4750 | /* Stop catching X protocol errors and let them make Emacs die. */ |
4751 | ||
c118dd06 JB |
4752 | void |
4753 | x_uncatch_errors () | |
4754 | { | |
9ac0d9e0 | 4755 | xfree (x_caught_error_message); |
cef13e55 | 4756 | x_caught_error_message = 0; |
c118dd06 | 4757 | XHandleError (x_error_quitter); |
dc6f92b8 JB |
4758 | } |
4759 | ||
dc6f92b8 JB |
4760 | #if 0 |
4761 | static unsigned int x_wire_count; | |
4762 | x_trace_wire () | |
4763 | { | |
4764 | fprintf (stderr, "Lib call: %d\n", ++x_wire_count); | |
4765 | } | |
c118dd06 | 4766 | #endif /* ! 0 */ |
dc6f92b8 JB |
4767 | |
4768 | \f | |
f451eb13 JB |
4769 | /* Changing the font of the frame. */ |
4770 | ||
f676886a | 4771 | /* Set the font of the x-window specified by frame F |
dc6f92b8 | 4772 | to the font named NEWNAME. This is safe to use |
f676886a | 4773 | even before F has an actual x-window. */ |
dc6f92b8 JB |
4774 | |
4775 | #ifdef HAVE_X11 | |
4776 | ||
2224a5fc RS |
4777 | struct font_info |
4778 | { | |
4779 | XFontStruct *font; | |
4780 | char *name; | |
4781 | }; | |
4782 | ||
dc6f92b8 | 4783 | /* A table of all the fonts we have already loaded. */ |
2224a5fc | 4784 | static struct font_info *x_font_table; |
dc6f92b8 JB |
4785 | |
4786 | /* The current capacity of x_font_table. */ | |
4787 | static int x_font_table_size; | |
4788 | ||
4789 | /* The number of fonts actually stored in x_font_table. | |
4790 | x_font_table[n] is used and valid iff 0 <= n < n_fonts. | |
4791 | 0 <= n_fonts <= x_font_table_size. */ | |
4792 | static int n_fonts; | |
4793 | ||
b5cf7a0e | 4794 | Lisp_Object |
f676886a JB |
4795 | x_new_font (f, fontname) |
4796 | struct frame *f; | |
dc6f92b8 JB |
4797 | register char *fontname; |
4798 | { | |
dc6f92b8 JB |
4799 | int already_loaded; |
4800 | int n_matching_fonts; | |
4801 | XFontStruct *font_info; | |
4802 | char **font_names; | |
4803 | ||
4804 | /* Get a list of all the fonts that match this name. Once we | |
4805 | have a list of matching fonts, we compare them against the fonts | |
4806 | we already have by comparing font ids. */ | |
2224a5fc RS |
4807 | font_names = (char **) XListFonts (x_current_display, fontname, |
4808 | 1024, &n_matching_fonts); | |
0c94f6ee JB |
4809 | /* Apparently it doesn't set n_matching_fonts to zero when it can't |
4810 | find any matches; font_names == 0 is the only clue. */ | |
4811 | if (! font_names) | |
4812 | n_matching_fonts = 0; | |
4813 | ||
5835f860 RS |
4814 | /* Don't just give up if n_matching_fonts is 0. |
4815 | Apparently there's a bug on Suns: XListFontsWithInfo can | |
4816 | fail to find a font, but XLoadQueryFont may still find it. */ | |
dc6f92b8 | 4817 | |
90e65f07 | 4818 | /* See if we've already loaded a matching font. */ |
5835f860 RS |
4819 | already_loaded = -1; |
4820 | if (n_matching_fonts != 0) | |
4821 | { | |
4822 | int i, j; | |
dc6f92b8 | 4823 | |
5835f860 RS |
4824 | for (i = 0; i < n_fonts; i++) |
4825 | for (j = 0; j < n_matching_fonts; j++) | |
2224a5fc | 4826 | if (!strcmp (x_font_table[i].name, font_names[j])) |
5835f860 RS |
4827 | { |
4828 | already_loaded = i; | |
4829 | fontname = font_names[j]; | |
4830 | goto found_font; | |
4831 | } | |
4832 | } | |
dc6f92b8 JB |
4833 | found_font: |
4834 | ||
4835 | /* If we have, just return it from the table. */ | |
2224a5fc RS |
4836 | if (already_loaded >= 0) |
4837 | f->display.x->font = x_font_table[already_loaded].font; | |
90e65f07 | 4838 | |
dc6f92b8 JB |
4839 | /* Otherwise, load the font and add it to the table. */ |
4840 | else | |
4841 | { | |
9696f58b | 4842 | int i; |
dc6f92b8 JB |
4843 | XFontStruct *font; |
4844 | ||
9696f58b | 4845 | /* Try to find a character-cell font in the list. */ |
f126bd67 JB |
4846 | #if 0 |
4847 | /* A laudable goal, but this isn't how to do it. */ | |
9696f58b JB |
4848 | for (i = 0; i < n_matching_fonts; i++) |
4849 | if (! font_info[i].per_char) | |
4850 | break; | |
f126bd67 JB |
4851 | #else |
4852 | i = 0; | |
4853 | #endif | |
9696f58b | 4854 | |
5835f860 RS |
4855 | /* See comment above. */ |
4856 | if (n_matching_fonts != 0) | |
9696f58b JB |
4857 | fontname = font_names[i]; |
4858 | ||
dc6f92b8 JB |
4859 | font = (XFontStruct *) XLoadQueryFont (x_current_display, fontname); |
4860 | if (! font) | |
5835f860 | 4861 | { |
2224a5fc | 4862 | /* Free the information from XListFonts. */ |
5835f860 | 4863 | if (n_matching_fonts) |
2224a5fc | 4864 | XFreeFontNames (font_names); |
5835f860 RS |
4865 | return Qnil; |
4866 | } | |
dc6f92b8 JB |
4867 | |
4868 | /* Do we need to create the table? */ | |
4869 | if (x_font_table_size == 0) | |
4870 | { | |
4871 | x_font_table_size = 16; | |
4872 | x_font_table | |
2224a5fc RS |
4873 | = (struct font_info *) xmalloc (x_font_table_size |
4874 | * sizeof (x_font_table[0])); | |
dc6f92b8 JB |
4875 | } |
4876 | /* Do we need to grow the table? */ | |
4877 | else if (n_fonts >= x_font_table_size) | |
4878 | { | |
90e65f07 | 4879 | x_font_table_size *= 2; |
dc6f92b8 | 4880 | x_font_table |
2224a5fc RS |
4881 | = (struct font_info *) xrealloc (x_font_table, |
4882 | (x_font_table_size | |
4883 | * sizeof (x_font_table[0]))); | |
dc6f92b8 JB |
4884 | } |
4885 | ||
dff815ef | 4886 | x_font_table[n_fonts].name = (char *) xmalloc (strlen (fontname) + 1); |
2224a5fc RS |
4887 | bcopy (fontname, x_font_table[n_fonts].name, strlen (fontname) + 1); |
4888 | f->display.x->font = x_font_table[n_fonts++].font = font; | |
dc6f92b8 | 4889 | } |
2224a5fc | 4890 | |
f676886a | 4891 | /* Now make the frame display the given font. */ |
c118dd06 | 4892 | if (FRAME_X_WINDOW (f) != 0) |
dc6f92b8 | 4893 | { |
f676886a JB |
4894 | XSetFont (x_current_display, f->display.x->normal_gc, |
4895 | f->display.x->font->fid); | |
4896 | XSetFont (x_current_display, f->display.x->reverse_gc, | |
4897 | f->display.x->font->fid); | |
4898 | XSetFont (x_current_display, f->display.x->cursor_gc, | |
4899 | f->display.x->font->fid); | |
4900 | ||
a27f9f86 | 4901 | frame_update_line_height (f); |
dc6f92b8 | 4902 | } |
a27f9f86 RS |
4903 | else |
4904 | /* If we are setting a new frame's font for the first time, | |
4905 | there are no faces yet, so this font's height is the line height. */ | |
4906 | f->display.x->line_height = FONT_HEIGHT (f); | |
dc6f92b8 | 4907 | |
b5cf7a0e | 4908 | { |
abdda982 | 4909 | Lisp_Object lispy_name; |
b5cf7a0e | 4910 | |
abdda982 | 4911 | lispy_name = build_string (fontname); |
b5cf7a0e | 4912 | |
2224a5fc | 4913 | /* Free the information from XListFonts. The data |
b5cf7a0e | 4914 | we actually retain comes from XLoadQueryFont. */ |
2224a5fc | 4915 | XFreeFontNames (font_names); |
b5cf7a0e JB |
4916 | |
4917 | return lispy_name; | |
4918 | } | |
dc6f92b8 | 4919 | } |
c118dd06 | 4920 | #else /* ! defined (HAVE_X11) */ |
f676886a JB |
4921 | x_new_font (f, newname) |
4922 | struct frame *f; | |
dc6f92b8 JB |
4923 | register char *newname; |
4924 | { | |
4925 | FONT_TYPE *temp; | |
4926 | int mask; | |
4927 | ||
4928 | temp = XGetFont (newname); | |
4929 | if (temp == (FONT_TYPE *) 0) | |
4930 | return 1; | |
4931 | ||
f676886a JB |
4932 | if (f->display.x->font) |
4933 | XLoseFont (f->display.x->font); | |
dc6f92b8 | 4934 | |
f676886a | 4935 | f->display.x->font = temp; |
dc6f92b8 | 4936 | |
c118dd06 | 4937 | if (FRAME_X_WINDOW (f) != 0) |
bc20ebbf | 4938 | x_set_window_size (f, 0, f->width, f->height); |
dc6f92b8 JB |
4939 | |
4940 | return 0; | |
4941 | } | |
c118dd06 | 4942 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 | 4943 | \f |
f676886a JB |
4944 | x_calc_absolute_position (f) |
4945 | struct frame *f; | |
dc6f92b8 JB |
4946 | { |
4947 | #ifdef HAVE_X11 | |
6dba1858 RS |
4948 | Window win, child; |
4949 | int win_x = 0, win_y = 0; | |
4950 | ||
4951 | /* Find the position of the outside upper-left corner of | |
4952 | the inner window, with respect to the outer window. */ | |
4953 | if (f->display.x->parent_desc != ROOT_WINDOW) | |
4954 | { | |
4955 | BLOCK_INPUT; | |
4956 | XTranslateCoordinates (x_current_display, | |
4957 | ||
4958 | /* From-window, to-window. */ | |
4959 | f->display.x->window_desc, | |
4960 | f->display.x->parent_desc, | |
4961 | ||
4962 | /* From-position, to-position. */ | |
4963 | 0, 0, &win_x, &win_y, | |
4964 | ||
4965 | /* Child of win. */ | |
4966 | &child); | |
4967 | UNBLOCK_INPUT; | |
4968 | } | |
4969 | ||
4970 | /* Treat negative positions as relative to the leftmost bottommost | |
4971 | position that fits on the screen. */ | |
f676886a | 4972 | if (f->display.x->left_pos < 0) |
31ea78fd | 4973 | f->display.x->left_pos = (x_screen_width |
69388238 | 4974 | - 2 * f->display.x->border_width - win_x |
31ea78fd JB |
4975 | - PIXEL_WIDTH (f) |
4976 | + f->display.x->left_pos); | |
dc6f92b8 | 4977 | |
f676886a | 4978 | if (f->display.x->top_pos < 0) |
31ea78fd | 4979 | f->display.x->top_pos = (x_screen_height |
69388238 | 4980 | - 2 * f->display.x->border_width - win_y |
31ea78fd JB |
4981 | - PIXEL_HEIGHT (f) |
4982 | + f->display.x->top_pos); | |
6dba1858 | 4983 | |
c118dd06 | 4984 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4985 | WINDOWINFO_TYPE parentinfo; |
4986 | ||
c118dd06 | 4987 | XGetWindowInfo (FRAME_X_WINDOW (f), &parentinfo); |
dc6f92b8 | 4988 | |
f676886a JB |
4989 | if (f->display.x->left_pos < 0) |
4990 | f->display.x->left_pos = parentinfo.width + (f->display.x->left_pos + 1) | |
4991 | - PIXEL_WIDTH (f) - 2 * f->display.x->internal_border_width; | |
dc6f92b8 | 4992 | |
f676886a JB |
4993 | if (f->display.x->top_pos < 0) |
4994 | f->display.x->top_pos = parentinfo.height + (f->display.x->top_pos + 1) | |
4995 | - PIXEL_HEIGHT (f) - 2 * f->display.x->internal_border_width; | |
c118dd06 | 4996 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
4997 | } |
4998 | ||
f676886a JB |
4999 | x_set_offset (f, xoff, yoff) |
5000 | struct frame *f; | |
dc6f92b8 JB |
5001 | register int xoff, yoff; |
5002 | { | |
f676886a JB |
5003 | f->display.x->top_pos = yoff; |
5004 | f->display.x->left_pos = xoff; | |
5005 | x_calc_absolute_position (f); | |
dc6f92b8 JB |
5006 | |
5007 | BLOCK_INPUT; | |
3afe33e7 RS |
5008 | #ifdef USE_X_TOOLKIT |
5009 | XMoveWindow (XDISPLAY XtWindow (f->display.x->widget), | |
5010 | f->display.x->left_pos, f->display.x->top_pos); | |
5011 | #else /* not USE_X_TOOLKIT */ | |
c118dd06 | 5012 | XMoveWindow (XDISPLAY FRAME_X_WINDOW (f), |
f676886a | 5013 | f->display.x->left_pos, f->display.x->top_pos); |
3afe33e7 | 5014 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 | 5015 | #ifdef HAVE_X11 |
bc20ebbf | 5016 | x_wm_set_size_hint (f, 0, 1, xoff, yoff); |
c118dd06 | 5017 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
5018 | UNBLOCK_INPUT; |
5019 | } | |
5020 | ||
bc20ebbf FP |
5021 | /* Call this to change the size of frame F's x-window. |
5022 | If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity | |
5023 | for this size change and subsequent size changes. | |
5024 | Otherwise we leave the window gravity unchanged. */ | |
dc6f92b8 | 5025 | |
bc20ebbf | 5026 | x_set_window_size (f, change_gravity, cols, rows) |
f676886a | 5027 | struct frame *f; |
bc20ebbf | 5028 | int change_gravity; |
b1c884c3 | 5029 | int cols, rows; |
dc6f92b8 JB |
5030 | { |
5031 | int pixelwidth, pixelheight; | |
5032 | int mask; | |
dc6f92b8 | 5033 | |
80fd1fe2 FP |
5034 | #ifdef USE_X_TOOLKIT |
5035 | BLOCK_INPUT; | |
5036 | EmacsFrameSetCharSize (f->display.x->edit_widget, cols, rows); | |
5037 | UNBLOCK_INPUT; | |
5038 | ||
5039 | #else /* not USE_X_TOOLKIT */ | |
5040 | ||
dc6f92b8 JB |
5041 | BLOCK_INPUT; |
5042 | ||
b1c884c3 | 5043 | check_frame_size (f, &rows, &cols); |
6dba1858 RS |
5044 | f->display.x->vertical_scroll_bar_extra |
5045 | = (FRAME_HAS_VERTICAL_SCROLL_BARS (f) | |
5046 | ? VERTICAL_SCROLL_BAR_PIXEL_WIDTH (f) | |
5047 | : 0); | |
f451eb13 JB |
5048 | pixelwidth = CHAR_TO_PIXEL_WIDTH (f, cols); |
5049 | pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows); | |
dc6f92b8 JB |
5050 | |
5051 | #ifdef HAVE_X11 | |
bc20ebbf | 5052 | x_wm_set_size_hint (f, 0, change_gravity, 0, 0); |
c118dd06 JB |
5053 | #endif /* ! defined (HAVE_X11) */ |
5054 | XChangeWindowSize (FRAME_X_WINDOW (f), pixelwidth, pixelheight); | |
b1c884c3 JB |
5055 | |
5056 | /* Now, strictly speaking, we can't be sure that this is accurate, | |
5057 | but the window manager will get around to dealing with the size | |
5058 | change request eventually, and we'll hear how it went when the | |
dbc4e1c1 JB |
5059 | ConfigureNotify event gets here. |
5060 | ||
5061 | We could just not bother storing any of this information here, | |
5062 | and let the ConfigureNotify event set everything up, but that | |
5063 | might be kind of confusing to the lisp code, since size changes | |
5064 | wouldn't be reported in the frame parameters until some random | |
5065 | point in the future when the ConfigureNotify event arrives. */ | |
8922af5f | 5066 | change_frame_size (f, rows, cols, 0, 0); |
b1c884c3 JB |
5067 | PIXEL_WIDTH (f) = pixelwidth; |
5068 | PIXEL_HEIGHT (f) = pixelheight; | |
5069 | ||
dbc4e1c1 JB |
5070 | /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to |
5071 | receive in the ConfigureNotify event; if we get what we asked | |
5072 | for, then the event won't cause the screen to become garbaged, so | |
5073 | we have to make sure to do it here. */ | |
5074 | SET_FRAME_GARBAGED (f); | |
5075 | ||
dc6f92b8 JB |
5076 | XFlushQueue (); |
5077 | UNBLOCK_INPUT; | |
80fd1fe2 | 5078 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
5079 | } |
5080 | ||
5081 | #ifndef HAVE_X11 | |
f676886a JB |
5082 | x_set_resize_hint (f) |
5083 | struct frame *f; | |
dc6f92b8 | 5084 | { |
12ba150f JB |
5085 | XSetResizeHint (FRAME_X_WINDOW (f), |
5086 | 2 * f->display.x->internal_border_width, | |
f676886a | 5087 | 2 * f->display.x->internal_border_width, |
12ba150f | 5088 | FONT_WIDTH (f->display.x->font), |
a27f9f86 | 5089 | f->display.x->line_height); |
dc6f92b8 | 5090 | } |
c118dd06 | 5091 | #endif /* HAVE_X11 */ |
dc6f92b8 | 5092 | \f |
f451eb13 | 5093 | /* Mouse warping, focus shifting, raising and lowering. */ |
dc6f92b8 | 5094 | |
f676886a JB |
5095 | x_set_mouse_position (f, x, y) |
5096 | struct frame *f; | |
dc6f92b8 JB |
5097 | int x, y; |
5098 | { | |
5099 | int pix_x, pix_y; | |
5100 | ||
4466efa5 | 5101 | #if 0 /* Let the user ask for this if he wants it. */ |
f676886a | 5102 | x_raise_frame (f); |
4466efa5 | 5103 | #endif |
dc6f92b8 | 5104 | |
12ba150f | 5105 | pix_x = CHAR_TO_PIXEL_COL (f, x) + FONT_WIDTH (f->display.x->font) / 2; |
a27f9f86 | 5106 | pix_y = CHAR_TO_PIXEL_ROW (f, y) + f->display.x->line_height / 2; |
f451eb13 JB |
5107 | |
5108 | if (pix_x < 0) pix_x = 0; | |
5109 | if (pix_x > PIXEL_WIDTH (f)) pix_x = PIXEL_WIDTH (f); | |
5110 | ||
5111 | if (pix_y < 0) pix_y = 0; | |
5112 | if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f); | |
dc6f92b8 JB |
5113 | |
5114 | BLOCK_INPUT; | |
dc6f92b8 | 5115 | |
c118dd06 | 5116 | XWarpMousePointer (FRAME_X_WINDOW (f), pix_x, pix_y); |
dc6f92b8 JB |
5117 | UNBLOCK_INPUT; |
5118 | } | |
5119 | ||
5120 | #ifdef HAVE_X11 | |
f676886a JB |
5121 | x_focus_on_frame (f) |
5122 | struct frame *f; | |
dc6f92b8 | 5123 | { |
1fb20991 | 5124 | #if 0 /* This proves to be unpleasant. */ |
f676886a | 5125 | x_raise_frame (f); |
1fb20991 | 5126 | #endif |
6d4238f3 JB |
5127 | #if 0 |
5128 | /* I don't think that the ICCCM allows programs to do things like this | |
5129 | without the interaction of the window manager. Whatever you end up | |
f676886a | 5130 | doing with this code, do it to x_unfocus_frame too. */ |
c118dd06 | 5131 | XSetInputFocus (x_current_display, FRAME_X_WINDOW (f), |
dc6f92b8 | 5132 | RevertToPointerRoot, CurrentTime); |
c118dd06 | 5133 | #endif /* ! 0 */ |
dc6f92b8 JB |
5134 | } |
5135 | ||
f676886a JB |
5136 | x_unfocus_frame (f) |
5137 | struct frame *f; | |
dc6f92b8 | 5138 | { |
6d4238f3 | 5139 | #if 0 |
f676886a JB |
5140 | /* Look at the remarks in x_focus_on_frame. */ |
5141 | if (x_focus_frame == f) | |
dc6f92b8 JB |
5142 | XSetInputFocus (x_current_display, PointerRoot, |
5143 | RevertToPointerRoot, CurrentTime); | |
c118dd06 | 5144 | #endif /* ! 0 */ |
dc6f92b8 JB |
5145 | } |
5146 | ||
c118dd06 | 5147 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 | 5148 | |
f676886a | 5149 | /* Raise frame F. */ |
dc6f92b8 | 5150 | |
f676886a JB |
5151 | x_raise_frame (f) |
5152 | struct frame *f; | |
dc6f92b8 | 5153 | { |
3a88c238 | 5154 | if (f->async_visible) |
dc6f92b8 JB |
5155 | { |
5156 | BLOCK_INPUT; | |
3afe33e7 RS |
5157 | #ifdef USE_X_TOOLKIT |
5158 | XRaiseWindow (XDISPLAY XtWindow (f->display.x->widget)); | |
5159 | #else /* not USE_X_TOOLKIT */ | |
c118dd06 | 5160 | XRaiseWindow (XDISPLAY FRAME_X_WINDOW (f)); |
3afe33e7 | 5161 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
5162 | XFlushQueue (); |
5163 | UNBLOCK_INPUT; | |
5164 | } | |
5165 | } | |
5166 | ||
f676886a | 5167 | /* Lower frame F. */ |
dc6f92b8 | 5168 | |
f676886a JB |
5169 | x_lower_frame (f) |
5170 | struct frame *f; | |
dc6f92b8 | 5171 | { |
3a88c238 | 5172 | if (f->async_visible) |
dc6f92b8 JB |
5173 | { |
5174 | BLOCK_INPUT; | |
3afe33e7 RS |
5175 | #ifdef USE_X_TOOLKIT |
5176 | XLowerWindow (XDISPLAY XtWindow (f->display.x->widget)); | |
5177 | #else /* not USE_X_TOOLKIT */ | |
c118dd06 | 5178 | XLowerWindow (XDISPLAY FRAME_X_WINDOW (f)); |
3afe33e7 | 5179 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
5180 | XFlushQueue (); |
5181 | UNBLOCK_INPUT; | |
5182 | } | |
5183 | } | |
5184 | ||
dbc4e1c1 JB |
5185 | static void |
5186 | XTframe_raise_lower (f, raise) | |
5187 | FRAME_PTR f; | |
5188 | int raise; | |
5189 | { | |
5190 | if (raise) | |
5191 | x_raise_frame (f); | |
5192 | else | |
5193 | x_lower_frame (f); | |
5194 | } | |
5195 | ||
5196 | ||
dc6f92b8 JB |
5197 | /* Change from withdrawn state to mapped state. */ |
5198 | ||
f676886a JB |
5199 | x_make_frame_visible (f) |
5200 | struct frame *f; | |
dc6f92b8 JB |
5201 | { |
5202 | int mask; | |
5203 | ||
dc6f92b8 | 5204 | BLOCK_INPUT; |
dc6f92b8 | 5205 | |
f676886a | 5206 | if (! FRAME_VISIBLE_P (f)) |
90e65f07 JB |
5207 | { |
5208 | #ifdef HAVE_X11 | |
5209 | if (! EQ (Vx_no_window_manager, Qt)) | |
f676886a | 5210 | x_wm_set_window_state (f, NormalState); |
3afe33e7 RS |
5211 | #ifdef USE_X_TOOLKIT |
5212 | XtPopup (f->display.x->widget, XtGrabNone); | |
5213 | #else /* not USE_X_TOOLKIT */ | |
c118dd06 | 5214 | XMapWindow (XDISPLAY FRAME_X_WINDOW (f)); |
3afe33e7 | 5215 | #endif /* not USE_X_TOOLKIT */ |
ab648270 | 5216 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
c118dd06 JB |
5217 | XMapSubwindows (x_current_display, FRAME_X_WINDOW (f)); |
5218 | #else /* ! defined (HAVE_X11) */ | |
5219 | XMapWindow (XDISPLAY FRAME_X_WINDOW (f)); | |
f676886a JB |
5220 | if (f->display.x->icon_desc != 0) |
5221 | XUnmapWindow (f->display.x->icon_desc); | |
dc6f92b8 | 5222 | |
90e65f07 | 5223 | /* Handled by the MapNotify event for X11 */ |
3a88c238 JB |
5224 | f->async_visible = 1; |
5225 | f->async_iconified = 0; | |
dc6f92b8 | 5226 | |
f676886a | 5227 | /* NOTE: this may cause problems for the first frame. */ |
90e65f07 | 5228 | XTcursor_to (0, 0); |
c118dd06 | 5229 | #endif /* ! defined (HAVE_X11) */ |
90e65f07 | 5230 | } |
dc6f92b8 | 5231 | |
dc6f92b8 | 5232 | XFlushQueue (); |
90e65f07 | 5233 | |
dc6f92b8 JB |
5234 | UNBLOCK_INPUT; |
5235 | } | |
5236 | ||
5237 | /* Change from mapped state to withdrawn state. */ | |
5238 | ||
f676886a JB |
5239 | x_make_frame_invisible (f) |
5240 | struct frame *f; | |
dc6f92b8 JB |
5241 | { |
5242 | int mask; | |
5243 | ||
9319ae23 RS |
5244 | /* Don't keep the highlight on an invisible frame. */ |
5245 | if (x_highlight_frame == f) | |
5246 | x_highlight_frame = 0; | |
5247 | ||
5248 | if (! f->async_visible && ! f->async_iconified) | |
dc6f92b8 JB |
5249 | return; |
5250 | ||
5251 | BLOCK_INPUT; | |
c118dd06 JB |
5252 | |
5253 | #ifdef HAVE_X11R4 | |
5254 | ||
bc20ebbf FP |
5255 | #ifdef USE_X_TOOLKIT |
5256 | if (! XWithdrawWindow (x_current_display, XtWindow (f->display.x->widget), | |
5257 | DefaultScreen (x_current_display))) | |
5258 | #else /* not USE_X_TOOLKIT */ | |
c118dd06 JB |
5259 | if (! XWithdrawWindow (x_current_display, FRAME_X_WINDOW (f), |
5260 | DefaultScreen (x_current_display))) | |
bc20ebbf | 5261 | #endif /* not USE_X_TOOLKIT */ |
c118dd06 JB |
5262 | { |
5263 | UNBLOCK_INPUT_RESIGNAL; | |
eb8c3be9 | 5264 | error ("can't notify window manager of window withdrawal"); |
c118dd06 JB |
5265 | } |
5266 | ||
5267 | #else /* ! defined (HAVE_X11R4) */ | |
dc6f92b8 | 5268 | #ifdef HAVE_X11 |
16bd92ea | 5269 | |
c118dd06 | 5270 | /* Tell the window manager what we're going to do. */ |
dc6f92b8 JB |
5271 | if (! EQ (Vx_no_window_manager, Qt)) |
5272 | { | |
16bd92ea | 5273 | XEvent unmap; |
dc6f92b8 | 5274 | |
16bd92ea | 5275 | unmap.xunmap.type = UnmapNotify; |
bc20ebbf FP |
5276 | #ifdef USE_X_TOOLKIT |
5277 | unmap.xunmap.window = XtWindow (f->display.x->widget); | |
5278 | #else /* not USE_X_TOOLKIT */ | |
c118dd06 | 5279 | unmap.xunmap.window = FRAME_X_WINDOW (f); |
bc20ebbf | 5280 | #endif /* not USE_X_TOOLKIT */ |
16bd92ea JB |
5281 | unmap.xunmap.event = DefaultRootWindow (x_current_display); |
5282 | unmap.xunmap.from_configure = False; | |
5283 | if (! XSendEvent (x_current_display, | |
5284 | DefaultRootWindow (x_current_display), | |
5285 | False, | |
5286 | SubstructureRedirectMask|SubstructureNotifyMask, | |
5287 | &unmap)) | |
5288 | { | |
5289 | UNBLOCK_INPUT_RESIGNAL; | |
5290 | error ("can't notify window manager of withdrawal"); | |
5291 | } | |
dc6f92b8 JB |
5292 | } |
5293 | ||
16bd92ea | 5294 | /* Unmap the window ourselves. Cheeky! */ |
bc20ebbf FP |
5295 | #ifdef USE_X_TOOLKIT |
5296 | XUnmapWindow (x_current_display, XtWindow (f->display.x->widget)); | |
5297 | #else /* not USE_X_TOOLKIT */ | |
c118dd06 | 5298 | XUnmapWindow (x_current_display, FRAME_X_WINDOW (f)); |
bc20ebbf | 5299 | #endif /* not USE_X_TOOLKIT */ |
c118dd06 | 5300 | #else /* ! defined (HAVE_X11) */ |
dc6f92b8 | 5301 | |
c118dd06 | 5302 | XUnmapWindow (FRAME_X_WINDOW (f)); |
3a88c238 | 5303 | f->async_visible = 0; /* Handled by the UnMap event for X11 */ |
f676886a | 5304 | if (f->display.x->icon_desc != 0) |
c118dd06 JB |
5305 | XUnmapWindow (f->display.x->icon_desc); |
5306 | ||
5307 | #endif /* ! defined (HAVE_X11) */ | |
5308 | #endif /* ! defined (HAVE_X11R4) */ | |
dc6f92b8 JB |
5309 | |
5310 | XFlushQueue (); | |
5311 | UNBLOCK_INPUT; | |
5312 | } | |
5313 | ||
dc6f92b8 JB |
5314 | /* Change window state from mapped to iconified. */ |
5315 | ||
f676886a JB |
5316 | x_iconify_frame (f) |
5317 | struct frame *f; | |
dc6f92b8 JB |
5318 | { |
5319 | int mask; | |
3afe33e7 | 5320 | int result; |
dc6f92b8 | 5321 | |
9319ae23 RS |
5322 | /* Don't keep the highlight on an invisible frame. */ |
5323 | if (x_highlight_frame == f) | |
5324 | x_highlight_frame = 0; | |
5325 | ||
3a88c238 | 5326 | if (f->async_iconified) |
dc6f92b8 JB |
5327 | return; |
5328 | ||
3afe33e7 RS |
5329 | #ifdef USE_X_TOOLKIT |
5330 | BLOCK_INPUT; | |
5331 | result = XIconifyWindow (x_current_display, | |
bc20ebbf | 5332 | XtWindow (f->display.x->widget), |
3afe33e7 RS |
5333 | DefaultScreen (x_current_display)); |
5334 | UNBLOCK_INPUT; | |
5335 | ||
5336 | if (!result) | |
5337 | error ("Can't notify window manager of iconification."); | |
5338 | ||
5339 | f->async_iconified = 1; | |
8c002a25 KH |
5340 | |
5341 | BLOCK_INPUT; | |
5342 | XFlushQueue (); | |
5343 | UNBLOCK_INPUT; | |
3afe33e7 RS |
5344 | #else /* not USE_X_TOOLKIT */ |
5345 | ||
dc6f92b8 JB |
5346 | BLOCK_INPUT; |
5347 | ||
5348 | #ifdef HAVE_X11 | |
16bd92ea JB |
5349 | /* Since we don't know which revision of X we're running, we'll use both |
5350 | the X11R3 and X11R4 techniques. I don't know if this is a good idea. */ | |
5351 | ||
5352 | /* X11R4: send a ClientMessage to the window manager using the | |
5353 | WM_CHANGE_STATE type. */ | |
5354 | { | |
5355 | XEvent message; | |
5356 | ||
c118dd06 | 5357 | message.xclient.window = FRAME_X_WINDOW (f); |
16bd92ea JB |
5358 | message.xclient.type = ClientMessage; |
5359 | message.xclient.message_type = Xatom_wm_change_state; | |
5360 | message.xclient.format = 32; | |
5361 | message.xclient.data.l[0] = IconicState; | |
5362 | ||
5363 | if (! XSendEvent (x_current_display, | |
5364 | DefaultRootWindow (x_current_display), | |
5365 | False, | |
5366 | SubstructureRedirectMask | SubstructureNotifyMask, | |
5367 | &message)) | |
dc6f92b8 JB |
5368 | { |
5369 | UNBLOCK_INPUT_RESIGNAL; | |
5370 | error ("Can't notify window manager of iconification."); | |
5371 | } | |
16bd92ea | 5372 | } |
dc6f92b8 | 5373 | |
16bd92ea JB |
5374 | /* X11R3: set the initial_state field of the window manager hints to |
5375 | IconicState. */ | |
5376 | x_wm_set_window_state (f, IconicState); | |
dc6f92b8 | 5377 | |
a9c00105 RS |
5378 | if (!FRAME_VISIBLE_P (f)) |
5379 | { | |
5380 | /* If the frame was withdrawn, before, we must map it. */ | |
5381 | XMapWindow (XDISPLAY FRAME_X_WINDOW (f)); | |
5382 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
5383 | XMapSubwindows (x_current_display, FRAME_X_WINDOW (f)); | |
5384 | } | |
5385 | ||
3a88c238 | 5386 | f->async_iconified = 1; |
c118dd06 JB |
5387 | #else /* ! defined (HAVE_X11) */ |
5388 | XUnmapWindow (XDISPLAY FRAME_X_WINDOW (f)); | |
dc6f92b8 | 5389 | |
3a88c238 | 5390 | f->async_visible = 0; /* Handled in the UnMap event for X11. */ |
f676886a | 5391 | if (f->display.x->icon_desc != 0) |
dc6f92b8 | 5392 | { |
f676886a JB |
5393 | XMapWindow (XDISPLAY f->display.x->icon_desc); |
5394 | refreshicon (f); | |
dc6f92b8 | 5395 | } |
c118dd06 | 5396 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 JB |
5397 | |
5398 | XFlushQueue (); | |
5399 | UNBLOCK_INPUT; | |
8c002a25 | 5400 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
5401 | } |
5402 | ||
c0ff3fab | 5403 | /* Destroy the X window of frame F. */ |
dc6f92b8 | 5404 | |
c0ff3fab | 5405 | x_destroy_window (f) |
f676886a | 5406 | struct frame *f; |
dc6f92b8 | 5407 | { |
dc6f92b8 | 5408 | BLOCK_INPUT; |
c0ff3fab JB |
5409 | |
5410 | if (f->display.x->icon_desc != 0) | |
5411 | XDestroyWindow (XDISPLAY f->display.x->icon_desc); | |
5412 | XDestroyWindow (XDISPLAY f->display.x->window_desc); | |
3afe33e7 RS |
5413 | #ifdef USE_X_TOOLKIT |
5414 | XtDestroyWidget (f->display.x->widget); | |
9d7e2e3e | 5415 | free_frame_menubar (f); |
3afe33e7 RS |
5416 | #endif /* USE_X_TOOLKIT */ |
5417 | ||
07e34cb0 | 5418 | free_frame_faces (f); |
dc6f92b8 | 5419 | XFlushQueue (); |
dc6f92b8 | 5420 | |
9ac0d9e0 | 5421 | xfree (f->display.x); |
c0ff3fab | 5422 | f->display.x = 0; |
f676886a JB |
5423 | if (f == x_focus_frame) |
5424 | x_focus_frame = 0; | |
5425 | if (f == x_highlight_frame) | |
5426 | x_highlight_frame = 0; | |
c0ff3fab JB |
5427 | |
5428 | UNBLOCK_INPUT; | |
dc6f92b8 JB |
5429 | } |
5430 | \f | |
f451eb13 JB |
5431 | /* Manage event queues for X10. */ |
5432 | ||
dc6f92b8 JB |
5433 | #ifndef HAVE_X11 |
5434 | ||
5435 | /* Manage event queues. | |
5436 | ||
5437 | This code is only used by the X10 support. | |
5438 | ||
5439 | We cannot leave events in the X queue and get them when we are ready | |
5440 | because X does not provide a subroutine to get only a certain kind | |
5441 | of event but not block if there are no queued events of that kind. | |
5442 | ||
5443 | Therefore, we must examine events as they come in and copy events | |
5444 | of certain kinds into our private queues. | |
5445 | ||
5446 | All ExposeRegion events are put in x_expose_queue. | |
69388238 | 5447 | All ButtonPress and ButtonRelease events are put in x_mouse_queue. */ |
dc6f92b8 JB |
5448 | |
5449 | ||
5450 | /* Write the event *P_XREP into the event queue *QUEUE. | |
5451 | If the queue is full, do nothing, but return nonzero. */ | |
5452 | ||
5453 | int | |
5454 | enqueue_event (p_xrep, queue) | |
5455 | register XEvent *p_xrep; | |
5456 | register struct event_queue *queue; | |
5457 | { | |
5458 | int newindex = queue->windex + 1; | |
5459 | if (newindex == EVENT_BUFFER_SIZE) | |
5460 | newindex = 0; | |
5461 | if (newindex == queue->rindex) | |
5462 | return -1; | |
5463 | queue->xrep[queue->windex] = *p_xrep; | |
5464 | queue->windex = newindex; | |
5465 | return 0; | |
5466 | } | |
5467 | ||
5468 | /* Fetch the next event from queue *QUEUE and store it in *P_XREP. | |
5469 | If *QUEUE is empty, do nothing and return 0. */ | |
5470 | ||
5471 | int | |
5472 | dequeue_event (p_xrep, queue) | |
5473 | register XEvent *p_xrep; | |
5474 | register struct event_queue *queue; | |
5475 | { | |
5476 | if (queue->windex == queue->rindex) | |
5477 | return 0; | |
5478 | *p_xrep = queue->xrep[queue->rindex++]; | |
5479 | if (queue->rindex == EVENT_BUFFER_SIZE) | |
5480 | queue->rindex = 0; | |
5481 | return 1; | |
5482 | } | |
5483 | ||
5484 | /* Return the number of events buffered in *QUEUE. */ | |
5485 | ||
5486 | int | |
5487 | queue_event_count (queue) | |
5488 | register struct event_queue *queue; | |
5489 | { | |
5490 | int tem = queue->windex - queue->rindex; | |
5491 | if (tem >= 0) | |
5492 | return tem; | |
5493 | return EVENT_BUFFER_SIZE + tem; | |
5494 | } | |
5495 | ||
5496 | /* Return nonzero if mouse input is pending. */ | |
5497 | ||
5498 | int | |
5499 | mouse_event_pending_p () | |
5500 | { | |
5501 | return queue_event_count (&x_mouse_queue); | |
5502 | } | |
c118dd06 | 5503 | #endif /* HAVE_X11 */ |
dc6f92b8 | 5504 | \f |
f451eb13 JB |
5505 | /* Setting window manager hints. */ |
5506 | ||
dc6f92b8 JB |
5507 | #ifdef HAVE_X11 |
5508 | ||
bc20ebbf FP |
5509 | /* Record the gravity used previously, in case CHANGE_GRAVITY is 0. */ |
5510 | static int previous_gravity; | |
5511 | ||
6dba1858 | 5512 | /* SPEC_X and SPEC_Y are the specified positions. |
bc20ebbf FP |
5513 | We look only at their sign, to decide the gravity. |
5514 | If CHANGE_GRAVITY is 0, we ignore SPEC_X and SPEC_Y | |
5515 | and leave the gravity unchanged. */ | |
6dba1858 | 5516 | |
bc20ebbf | 5517 | x_wm_set_size_hint (f, prompting, change_gravity, spec_x, spec_y) |
f676886a | 5518 | struct frame *f; |
dc6f92b8 | 5519 | long prompting; |
bc20ebbf | 5520 | int change_gravity; |
6dba1858 | 5521 | int spec_x, spec_y; |
dc6f92b8 JB |
5522 | { |
5523 | XSizeHints size_hints; | |
3afe33e7 RS |
5524 | |
5525 | #ifdef USE_X_TOOLKIT | |
7e4f2521 FP |
5526 | Arg al[2]; |
5527 | int ac = 0; | |
5528 | Dimension widget_width, widget_height; | |
bc20ebbf | 5529 | Window window = XtWindow (f->display.x->widget); |
3afe33e7 | 5530 | #else /* not USE_X_TOOLKIT */ |
c118dd06 | 5531 | Window window = FRAME_X_WINDOW (f); |
3afe33e7 | 5532 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 | 5533 | |
f7f79491 | 5534 | size_hints.flags = PResizeInc | PMinSize /* | PMaxSize */; |
dc6f92b8 | 5535 | |
f676886a JB |
5536 | flexlines = f->height; |
5537 | ||
5538 | size_hints.x = f->display.x->left_pos; | |
5539 | size_hints.y = f->display.x->top_pos; | |
7e4f2521 FP |
5540 | #ifdef USE_X_TOOLKIT |
5541 | XtSetArg (al[ac], XtNwidth, &widget_width); ac++; | |
5542 | XtSetArg (al[ac], XtNheight, &widget_height); ac++; | |
5543 | XtGetValues (f->display.x->column_widget, al, ac); | |
5544 | size_hints.height = widget_height; | |
5545 | size_hints.width = widget_width; | |
5546 | #else /* not USE_X_TOOLKIT */ | |
f676886a JB |
5547 | size_hints.height = PIXEL_HEIGHT (f); |
5548 | size_hints.width = PIXEL_WIDTH (f); | |
7e4f2521 | 5549 | #endif /* not USE_X_TOOLKIT */ |
f676886a | 5550 | size_hints.width_inc = FONT_WIDTH (f->display.x->font); |
a27f9f86 | 5551 | size_hints.height_inc = f->display.x->line_height; |
f7f79491 | 5552 | #if 0 |
12ba150f JB |
5553 | size_hints.max_width = x_screen_width - CHAR_TO_PIXEL_WIDTH (f, 0); |
5554 | size_hints.max_height = x_screen_height - CHAR_TO_PIXEL_HEIGHT (f, 0); | |
f7f79491 | 5555 | #endif |
b1c884c3 | 5556 | { |
b0342f17 JB |
5557 | int base_width, base_height; |
5558 | ||
f451eb13 JB |
5559 | base_width = CHAR_TO_PIXEL_WIDTH (f, 0); |
5560 | base_height = CHAR_TO_PIXEL_HEIGHT (f, 0); | |
b0342f17 JB |
5561 | |
5562 | { | |
5563 | int min_rows = 0, min_cols = 0; | |
5564 | check_frame_size (f, &min_rows, &min_cols); | |
5565 | ||
5566 | /* The window manager uses the base width hints to calculate the | |
5567 | current number of rows and columns in the frame while | |
5568 | resizing; min_width and min_height aren't useful for this | |
5569 | purpose, since they might not give the dimensions for a | |
5570 | zero-row, zero-column frame. | |
5571 | ||
5572 | We use the base_width and base_height members if we have | |
5573 | them; otherwise, we set the min_width and min_height members | |
5574 | to the size for a zero x zero frame. */ | |
5575 | ||
5576 | #ifdef HAVE_X11R4 | |
5577 | size_hints.flags |= PBaseSize; | |
5578 | size_hints.base_width = base_width; | |
5579 | size_hints.base_height = base_height; | |
5580 | size_hints.min_width = base_width + min_cols * size_hints.width_inc; | |
5581 | size_hints.min_height = base_height + min_rows * size_hints.height_inc; | |
5582 | #else | |
5583 | size_hints.min_width = base_width; | |
5584 | size_hints.min_height = base_height; | |
5585 | #endif | |
5586 | } | |
b1c884c3 | 5587 | |
b1c884c3 | 5588 | } |
dc6f92b8 JB |
5589 | |
5590 | if (prompting) | |
5591 | size_hints.flags |= prompting; | |
5592 | else | |
5593 | { | |
5594 | XSizeHints hints; /* Sometimes I hate X Windows... */ | |
5595 | ||
82ee0df4 RS |
5596 | if (XGetNormalHints (x_current_display, window, &hints) == 0) |
5597 | hints.flags = 0; | |
dc6f92b8 JB |
5598 | if (hints.flags & PSize) |
5599 | size_hints.flags |= PSize; | |
5600 | if (hints.flags & PPosition) | |
5601 | size_hints.flags |= PPosition; | |
5602 | if (hints.flags & USPosition) | |
5603 | size_hints.flags |= USPosition; | |
5604 | if (hints.flags & USSize) | |
5605 | size_hints.flags |= USSize; | |
5606 | } | |
2554751d | 5607 | #if defined (PWinGravity) |
bc20ebbf | 5608 | if (change_gravity) |
6dba1858 | 5609 | { |
bc20ebbf FP |
5610 | switch (((spec_x < 0) << 1) + (spec_y < 0)) |
5611 | { | |
5612 | case 0: | |
5613 | size_hints.win_gravity = NorthWestGravity; | |
5614 | break; | |
5615 | case 1: | |
5616 | size_hints.win_gravity = NorthEastGravity; | |
5617 | break; | |
5618 | case 2: | |
5619 | size_hints.win_gravity = SouthWestGravity; | |
5620 | break; | |
5621 | case 3: | |
5622 | size_hints.win_gravity = SouthEastGravity; | |
5623 | break; | |
5624 | } | |
5625 | previous_gravity = size_hints.win_gravity; | |
6dba1858 | 5626 | } |
bc20ebbf FP |
5627 | else |
5628 | size_hints.win_gravity = previous_gravity; | |
5629 | ||
6dba1858 | 5630 | size_hints.flags |= PWinGravity; |
2554751d | 5631 | #endif /* PWinGravity */ |
6dba1858 | 5632 | |
b0342f17 JB |
5633 | #ifdef HAVE_X11R4 |
5634 | XSetWMNormalHints (x_current_display, window, &size_hints); | |
5635 | #else | |
dc6f92b8 | 5636 | XSetNormalHints (x_current_display, window, &size_hints); |
b0342f17 | 5637 | #endif |
dc6f92b8 JB |
5638 | } |
5639 | ||
5640 | /* Used for IconicState or NormalState */ | |
f676886a JB |
5641 | x_wm_set_window_state (f, state) |
5642 | struct frame *f; | |
dc6f92b8 JB |
5643 | int state; |
5644 | { | |
3afe33e7 | 5645 | #ifdef USE_X_TOOLKIT |
bc20ebbf | 5646 | Window window = XtWindow (f->display.x->widget); |
3afe33e7 | 5647 | #else /* not USE_X_TOOLKIT */ |
c118dd06 | 5648 | Window window = FRAME_X_WINDOW (f); |
3afe33e7 | 5649 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 | 5650 | |
16bd92ea JB |
5651 | f->display.x->wm_hints.flags |= StateHint; |
5652 | f->display.x->wm_hints.initial_state = state; | |
b1c884c3 | 5653 | |
16bd92ea | 5654 | XSetWMHints (x_current_display, window, &f->display.x->wm_hints); |
dc6f92b8 JB |
5655 | } |
5656 | ||
f676886a JB |
5657 | x_wm_set_icon_pixmap (f, icon_pixmap) |
5658 | struct frame *f; | |
dc6f92b8 JB |
5659 | Pixmap icon_pixmap; |
5660 | { | |
c118dd06 | 5661 | Window window = FRAME_X_WINDOW (f); |
dc6f92b8 | 5662 | |
dbc4e1c1 JB |
5663 | if (icon_pixmap) |
5664 | { | |
5665 | f->display.x->wm_hints.icon_pixmap = icon_pixmap; | |
5666 | f->display.x->wm_hints.flags |= IconPixmapHint; | |
5667 | } | |
5668 | else | |
5669 | f->display.x->wm_hints.flags &= ~IconPixmapHint; | |
b1c884c3 | 5670 | |
16bd92ea | 5671 | XSetWMHints (x_current_display, window, &f->display.x->wm_hints); |
dc6f92b8 JB |
5672 | } |
5673 | ||
f676886a JB |
5674 | x_wm_set_icon_position (f, icon_x, icon_y) |
5675 | struct frame *f; | |
dc6f92b8 JB |
5676 | int icon_x, icon_y; |
5677 | { | |
c118dd06 | 5678 | Window window = FRAME_X_WINDOW (f); |
dc6f92b8 | 5679 | |
16bd92ea JB |
5680 | f->display.x->wm_hints.flags |= IconPositionHint; |
5681 | f->display.x->wm_hints.icon_x = icon_x; | |
5682 | f->display.x->wm_hints.icon_y = icon_y; | |
b1c884c3 | 5683 | |
16bd92ea | 5684 | XSetWMHints (x_current_display, window, &f->display.x->wm_hints); |
dc6f92b8 JB |
5685 | } |
5686 | ||
5687 | \f | |
f451eb13 JB |
5688 | /* Initialization. */ |
5689 | ||
3afe33e7 RS |
5690 | #ifdef USE_X_TOOLKIT |
5691 | static XrmOptionDescRec emacs_options[] = { | |
5692 | {"-geometry", ".geometry", XrmoptionSepArg, NULL}, | |
5693 | {"-iconic", ".iconic", XrmoptionNoArg, (XtPointer) "yes"}, | |
5694 | ||
5695 | {"-internal-border-width", "*EmacsScreen.internalBorderWidth", | |
5696 | XrmoptionSepArg, NULL}, | |
5697 | {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg, NULL}, | |
5698 | ||
5699 | {"-T", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
5700 | {"-wn", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
5701 | {"-title", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
5702 | {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg, (XtPointer) NULL}, | |
5703 | {"-in", "*EmacsShell.iconName", XrmoptionSepArg, (XtPointer) NULL}, | |
5704 | {"-mc", "*pointerColor", XrmoptionSepArg, (XtPointer) NULL}, | |
5705 | {"-cr", "*cursorColor", XrmoptionSepArg, (XtPointer) NULL} | |
5706 | }; | |
5707 | #endif /* USE_X_TOOLKIT */ | |
5708 | ||
dc6f92b8 JB |
5709 | void |
5710 | x_term_init (display_name) | |
5711 | char *display_name; | |
5712 | { | |
f676886a | 5713 | Lisp_Object frame; |
dc6f92b8 | 5714 | char *defaultvalue; |
3afe33e7 RS |
5715 | int argc = 0; |
5716 | char** argv = 0; | |
041b69ac | 5717 | #ifndef F_SETOWN_BUG |
dc6f92b8 JB |
5718 | #ifdef F_SETOWN |
5719 | extern int old_fcntl_owner; | |
c118dd06 | 5720 | #endif /* ! defined (F_SETOWN) */ |
041b69ac | 5721 | #endif /* F_SETOWN_BUG */ |
6d4238f3 | 5722 | |
f676886a | 5723 | x_focus_frame = x_highlight_frame = 0; |
dc6f92b8 | 5724 | |
3afe33e7 | 5725 | #ifdef USE_X_TOOLKIT |
5c94b90b | 5726 | argv = (char **) XtMalloc (3 * sizeof (char *)); |
3afe33e7 RS |
5727 | argv [0] = ""; |
5728 | argv [1] = "-display"; | |
5729 | argv [2] = display_name; | |
5730 | argc = 3; | |
5731 | Xt_app_shell = XtAppInitialize (&Xt_app_con, "Emacs", | |
bc20ebbf | 5732 | emacs_options, XtNumber (emacs_options), |
3afe33e7 RS |
5733 | &argc, argv, |
5734 | NULL, NULL, 0); | |
5735 | XtFree (argv); | |
5736 | x_current_display = XtDisplay (Xt_app_shell); | |
5737 | ||
5738 | #else /* not USE_X_TOOLKIT */ | |
dc6f92b8 | 5739 | x_current_display = XOpenDisplay (display_name); |
3afe33e7 | 5740 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 | 5741 | if (x_current_display == 0) |
041b69ac JB |
5742 | fatal ("X server %s not responding.\n\ |
5743 | Check the DISPLAY environment variable or use \"-d\"\n", | |
dc6f92b8 JB |
5744 | display_name); |
5745 | ||
5746 | #ifdef HAVE_X11 | |
5747 | { | |
dc6f92b8 JB |
5748 | #if 0 |
5749 | XSetAfterFunction (x_current_display, x_trace_wire); | |
c118dd06 | 5750 | #endif /* ! 0 */ |
8c86eccd | 5751 | hostname = get_system_name (); |
59653951 | 5752 | x_id_name = (char *) xmalloc (XSTRING (Vinvocation_name)->size |
60fb3ee1 JB |
5753 | + strlen (hostname) |
5754 | + 2); | |
59653951 | 5755 | sprintf (x_id_name, "%s@%s", XSTRING (Vinvocation_name)->data, hostname); |
dc6f92b8 | 5756 | } |
28430d3c JB |
5757 | |
5758 | /* Figure out which modifier bits mean what. */ | |
5759 | x_find_modifier_meanings (); | |
f451eb13 | 5760 | |
ab648270 | 5761 | /* Get the scroll bar cursor. */ |
d56a553a RS |
5762 | x_vertical_scroll_bar_cursor |
5763 | = XCreateFontCursor (x_current_display, XC_sb_v_double_arrow); | |
f451eb13 | 5764 | |
d56a553a | 5765 | #if 0 |
28430d3c JB |
5766 | /* Watch for PropertyNotify events on the root window; we use them |
5767 | to figure out when to invalidate our cache of the cut buffers. */ | |
5768 | x_watch_cut_buffer_cache (); | |
d56a553a | 5769 | #endif |
28430d3c | 5770 | |
a4fc7360 | 5771 | if (ConnectionNumber (x_current_display) != 0) |
61c3ce62 RS |
5772 | change_keyboard_wait_descriptor (ConnectionNumber (x_current_display)); |
5773 | change_input_fd (ConnectionNumber (x_current_display)); | |
6d4238f3 | 5774 | |
c118dd06 | 5775 | #endif /* ! defined (HAVE_X11) */ |
dc6f92b8 | 5776 | |
041b69ac | 5777 | #ifndef F_SETOWN_BUG |
dc6f92b8 | 5778 | #ifdef F_SETOWN |
61c3ce62 | 5779 | old_fcntl_owner = fcntl (ConnectionNumber (x_current_display), F_GETOWN, 0); |
dc6f92b8 | 5780 | #ifdef F_SETOWN_SOCK_NEG |
61c3ce62 RS |
5781 | /* stdin is a socket here */ |
5782 | fcntl (ConnectionNumber (x_current_display), F_SETOWN, -getpid ()); | |
c118dd06 | 5783 | #else /* ! defined (F_SETOWN_SOCK_NEG) */ |
61c3ce62 | 5784 | fcntl (ConnectionNumber (x_current_display), F_SETOWN, getpid ()); |
c118dd06 JB |
5785 | #endif /* ! defined (F_SETOWN_SOCK_NEG) */ |
5786 | #endif /* ! defined (F_SETOWN) */ | |
041b69ac | 5787 | #endif /* F_SETOWN_BUG */ |
dc6f92b8 JB |
5788 | |
5789 | #ifdef SIGIO | |
5790 | init_sigio (); | |
c118dd06 | 5791 | #endif /* ! defined (SIGIO) */ |
dc6f92b8 | 5792 | |
dc6f92b8 JB |
5793 | expose_all_windows = 0; |
5794 | ||
f676886a | 5795 | clear_frame_hook = XTclear_frame; |
dc6f92b8 JB |
5796 | clear_end_of_line_hook = XTclear_end_of_line; |
5797 | ins_del_lines_hook = XTins_del_lines; | |
5798 | change_line_highlight_hook = XTchange_line_highlight; | |
5799 | insert_glyphs_hook = XTinsert_glyphs; | |
5800 | write_glyphs_hook = XTwrite_glyphs; | |
5801 | delete_glyphs_hook = XTdelete_glyphs; | |
5802 | ring_bell_hook = XTring_bell; | |
5803 | reset_terminal_modes_hook = XTreset_terminal_modes; | |
5804 | set_terminal_modes_hook = XTset_terminal_modes; | |
5805 | update_begin_hook = XTupdate_begin; | |
5806 | update_end_hook = XTupdate_end; | |
5807 | set_terminal_window_hook = XTset_terminal_window; | |
5808 | read_socket_hook = XTread_socket; | |
b8009dd1 | 5809 | frame_up_to_date_hook = XTframe_up_to_date; |
dc6f92b8 JB |
5810 | cursor_to_hook = XTcursor_to; |
5811 | reassert_line_highlight_hook = XTreassert_line_highlight; | |
90e65f07 | 5812 | mouse_position_hook = XTmouse_position; |
f451eb13 | 5813 | frame_rehighlight_hook = XTframe_rehighlight; |
dbc4e1c1 | 5814 | frame_raise_lower_hook = XTframe_raise_lower; |
ab648270 JB |
5815 | set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar; |
5816 | condemn_scroll_bars_hook = XTcondemn_scroll_bars; | |
5817 | redeem_scroll_bar_hook = XTredeem_scroll_bar; | |
5818 | judge_scroll_bars_hook = XTjudge_scroll_bars; | |
dc6f92b8 | 5819 | |
f676886a | 5820 | scroll_region_ok = 1; /* we'll scroll partial frames */ |
dc6f92b8 JB |
5821 | char_ins_del_ok = 0; /* just as fast to write the line */ |
5822 | line_ins_del_ok = 1; /* we'll just blt 'em */ | |
5823 | fast_clear_end_of_line = 1; /* X does this well */ | |
f676886a | 5824 | memory_below_frame = 0; /* we don't remember what scrolls |
dc6f92b8 JB |
5825 | off the bottom */ |
5826 | baud_rate = 19200; | |
5827 | ||
b30b24cb RS |
5828 | /* Try to use interrupt input; if we can't, then start polling. */ |
5829 | Fset_input_mode (Qt, Qnil, Qt, Qnil); | |
5830 | ||
c118dd06 JB |
5831 | /* Note that there is no real way portable across R3/R4 to get the |
5832 | original error handler. */ | |
5833 | XHandleError (x_error_quitter); | |
8922af5f | 5834 | XHandleIOError (x_io_error_quitter); |
dc6f92b8 JB |
5835 | |
5836 | /* Disable Window Change signals; they are handled by X events. */ | |
5837 | #ifdef SIGWINCH | |
5838 | signal (SIGWINCH, SIG_DFL); | |
c118dd06 | 5839 | #endif /* ! defined (SIGWINCH) */ |
dc6f92b8 | 5840 | |
c118dd06 | 5841 | signal (SIGPIPE, x_connection_closed); |
dc6f92b8 | 5842 | } |
55123275 JB |
5843 | |
5844 | void | |
5845 | syms_of_xterm () | |
5846 | { | |
ab648270 | 5847 | staticpro (&last_mouse_scroll_bar); |
e53cb100 | 5848 | last_mouse_scroll_bar = Qnil; |
b8009dd1 RS |
5849 | staticpro (&mouse_face_window); |
5850 | mouse_face_window = Qnil; | |
55123275 | 5851 | } |
c118dd06 JB |
5852 | #endif /* ! defined (HAVE_X11) */ |
5853 | #endif /* ! defined (HAVE_X_WINDOWS) */ |