Commit | Line | Data |
---|---|---|
dc6f92b8 | 1 | /* X Communication module for terminals which understand the X protocol. |
1c7e22fd | 2 | Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000 |
06a2c219 | 3 | Free Software Foundation, Inc. |
dc6f92b8 JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
4746118a | 9 | the Free Software Foundation; either version 2, or (at your option) |
dc6f92b8 JB |
10 | any later version. |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
dc6f92b8 | 21 | |
06a2c219 | 22 | /* New display code by Gerd Moellmann <gerd@gnu.org>. */ |
3afe33e7 RS |
23 | /* Xt features made by Fred Pierresteguy. */ |
24 | ||
68c45bf0 PE |
25 | #include <config.h> |
26 | ||
039440c4 | 27 | /* On 4.3 these lose if they come after xterm.h. */ |
039440c4 | 28 | /* Putting these at the beginning seems to be standard for other .c files. */ |
039440c4 RS |
29 | #include <signal.h> |
30 | ||
4846819e RS |
31 | #include <stdio.h> |
32 | ||
dc6f92b8 JB |
33 | #ifdef HAVE_X_WINDOWS |
34 | ||
35 | #include "lisp.h" | |
9ac0d9e0 | 36 | #include "blockinput.h" |
dc6f92b8 | 37 | |
ae79c227 AS |
38 | /* Need syssignal.h for various externs and definitions that may be required |
39 | by some configurations for calls to signal later in this source file. */ | |
40 | #include "syssignal.h" | |
41 | ||
dc6f92b8 JB |
42 | /* This may include sys/types.h, and that somehow loses |
43 | if this is not done before the other system files. */ | |
44 | #include "xterm.h" | |
f451eb13 | 45 | #include <X11/cursorfont.h> |
dc6f92b8 JB |
46 | |
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 | 51 | #endif /* makedev */ |
dc6f92b8 | 52 | |
6df54671 | 53 | #ifdef BSD_SYSTEM |
dc6f92b8 | 54 | #include <sys/ioctl.h> |
6df54671 | 55 | #endif /* ! defined (BSD_SYSTEM) */ |
dc6f92b8 | 56 | |
2d368234 | 57 | #include "systty.h" |
3a2712f9 | 58 | #include "systime.h" |
dc6f92b8 | 59 | |
b8009dd1 | 60 | #ifndef INCLUDED_FCNTL |
dc6f92b8 | 61 | #include <fcntl.h> |
b8009dd1 | 62 | #endif |
dc6f92b8 JB |
63 | #include <ctype.h> |
64 | #include <errno.h> | |
65 | #include <setjmp.h> | |
66 | #include <sys/stat.h> | |
a0a7635f RS |
67 | /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */ |
68 | /* #include <sys/param.h> */ | |
dc6f92b8 | 69 | |
dc43ef94 | 70 | #include "charset.h" |
379b5ac0 | 71 | #include "coding.h" |
dc43ef94 | 72 | #include "ccl.h" |
7a13e894 | 73 | #include "frame.h" |
dc6f92b8 | 74 | #include "dispextern.h" |
ee569018 | 75 | #include "fontset.h" |
dc6f92b8 JB |
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" |
dc6f92b8 | 84 | #include "disptab.h" |
dc6f92b8 | 85 | #include "buffer.h" |
f451eb13 | 86 | #include "window.h" |
3b2fa4e6 | 87 | #include "keyboard.h" |
bde7c500 | 88 | #include "intervals.h" |
dfcf069d | 89 | #include "process.h" |
bffcfca9 | 90 | #include "atimer.h" |
dc6f92b8 | 91 | |
d2bd6bc4 RS |
92 | #ifdef USE_X_TOOLKIT |
93 | #include <X11/Shell.h> | |
94 | #endif | |
95 | ||
06a2c219 GM |
96 | #ifdef HAVE_SYS_TIME_H |
97 | #include <sys/time.h> | |
98 | #endif | |
99 | #ifdef HAVE_UNISTD_H | |
100 | #include <unistd.h> | |
101 | #endif | |
102 | ||
3afe33e7 | 103 | #ifdef USE_X_TOOLKIT |
06a2c219 | 104 | |
952291d9 GM |
105 | extern void free_frame_menubar P_ ((struct frame *)); |
106 | extern struct frame *x_menubar_window_to_frame P_ ((struct x_display_info *, | |
107 | int)); | |
06a2c219 | 108 | |
0fdff6bb RS |
109 | #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES) |
110 | #define HACK_EDITRES | |
111 | extern void _XEditResCheckMessages (); | |
112 | #endif /* not NO_EDITRES */ | |
06a2c219 GM |
113 | |
114 | /* Include toolkit specific headers for the scroll bar widget. */ | |
115 | ||
116 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
117 | #if defined USE_MOTIF | |
118 | #include <Xm/Xm.h> /* for LESSTIF_VERSION */ | |
119 | #include <Xm/ScrollBar.h> | |
120 | #include <Xm/ScrollBarP.h> | |
ec18280f SM |
121 | #else /* !USE_MOTIF i.e. use Xaw */ |
122 | ||
123 | #ifdef HAVE_XAW3D | |
06a2c219 | 124 | #include <X11/Xaw3d/Simple.h> |
06a2c219 GM |
125 | #include <X11/Xaw3d/Scrollbar.h> |
126 | #define ARROW_SCROLLBAR | |
127 | #include <X11/Xaw3d/ScrollbarP.h> | |
ec18280f SM |
128 | #else /* !HAVE_XAW3D */ |
129 | #include <X11/Xaw/Simple.h> | |
130 | #include <X11/Xaw/Scrollbar.h> | |
131 | #endif /* !HAVE_XAW3D */ | |
132 | #ifndef XtNpickTop | |
133 | #define XtNpickTop "pickTop" | |
134 | #endif /* !XtNpickTop */ | |
135 | #endif /* !USE_MOTIF */ | |
06a2c219 GM |
136 | #endif /* USE_TOOLKIT_SCROLL_BARS */ |
137 | ||
3afe33e7 RS |
138 | #endif /* USE_X_TOOLKIT */ |
139 | ||
b849c413 RS |
140 | #ifndef USE_X_TOOLKIT |
141 | #define x_any_window_to_frame x_window_to_frame | |
5627c40e | 142 | #define x_top_window_to_frame x_window_to_frame |
b849c413 RS |
143 | #endif |
144 | ||
546e6d5b | 145 | #ifdef USE_X_TOOLKIT |
d067ea8b | 146 | #include "widget.h" |
546e6d5b RS |
147 | #ifndef XtNinitialState |
148 | #define XtNinitialState "initialState" | |
149 | #endif | |
150 | #endif | |
151 | ||
e4b68333 | 152 | #ifndef min |
06a2c219 | 153 | #define min(a,b) ((a) < (b) ? (a) : (b)) |
e4b68333 RS |
154 | #endif |
155 | #ifndef max | |
06a2c219 GM |
156 | #define max(a,b) ((a) > (b) ? (a) : (b)) |
157 | #endif | |
158 | ||
159 | #define abs(x) ((x) < 0 ? -(x) : (x)) | |
160 | ||
161 | #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER)) | |
162 | ||
163 | \f | |
164 | /* Bitmaps for truncated lines. */ | |
165 | ||
166 | enum bitmap_type | |
167 | { | |
168 | NO_BITMAP, | |
169 | LEFT_TRUNCATION_BITMAP, | |
170 | RIGHT_TRUNCATION_BITMAP, | |
171 | OVERLAY_ARROW_BITMAP, | |
172 | CONTINUED_LINE_BITMAP, | |
173 | CONTINUATION_LINE_BITMAP, | |
174 | ZV_LINE_BITMAP | |
175 | }; | |
176 | ||
177 | /* Bitmap drawn to indicate lines not displaying text if | |
178 | `indicate-empty-lines' is non-nil. */ | |
179 | ||
180 | #define zv_width 8 | |
181 | #define zv_height 8 | |
182 | static unsigned char zv_bits[] = { | |
183 | 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00}; | |
184 | ||
185 | /* An arrow like this: `<-'. */ | |
186 | ||
187 | #define left_width 8 | |
188 | #define left_height 8 | |
189 | static unsigned char left_bits[] = { | |
190 | 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18}; | |
191 | ||
110859fc GM |
192 | /* Right truncation arrow bitmap `->'. */ |
193 | ||
194 | #define right_width 8 | |
195 | #define right_height 8 | |
196 | static unsigned char right_bits[] = { | |
197 | 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18}; | |
198 | ||
06a2c219 GM |
199 | /* Marker for continued lines. */ |
200 | ||
201 | #define continued_width 8 | |
202 | #define continued_height 8 | |
203 | static unsigned char continued_bits[] = { | |
110859fc GM |
204 | 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c}; |
205 | ||
206 | /* Marker for continuation lines. */ | |
06a2c219 GM |
207 | |
208 | #define continuation_width 8 | |
209 | #define continuation_height 8 | |
210 | static unsigned char continuation_bits[] = { | |
110859fc | 211 | 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e}; |
06a2c219 | 212 | |
110859fc | 213 | /* Overlay arrow bitmap. */ |
06a2c219 | 214 | |
110859fc GM |
215 | #if 0 |
216 | /* A bomb. */ | |
06a2c219 GM |
217 | #define ov_width 8 |
218 | #define ov_height 8 | |
219 | static unsigned char ov_bits[] = { | |
220 | 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c}; | |
06a2c219 | 221 | #else |
110859fc | 222 | /* A triangular arrow. */ |
06a2c219 GM |
223 | #define ov_width 8 |
224 | #define ov_height 8 | |
225 | static unsigned char ov_bits[] = { | |
110859fc GM |
226 | 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03}; |
227 | ||
e4b68333 | 228 | #endif |
06a2c219 GM |
229 | |
230 | extern Lisp_Object Qhelp_echo; | |
231 | ||
69388238 | 232 | \f |
06a2c219 GM |
233 | /* Non-zero means Emacs uses toolkit scroll bars. */ |
234 | ||
235 | int x_toolkit_scroll_bars_p; | |
236 | ||
237 | /* If a string, XTread_socket generates an event to display that string. | |
238 | (The display is done in read_char.) */ | |
239 | ||
240 | static Lisp_Object help_echo; | |
7cea38bc | 241 | static Lisp_Object help_echo_window; |
be010514 GM |
242 | static Lisp_Object help_echo_object; |
243 | static int help_echo_pos; | |
06a2c219 GM |
244 | |
245 | /* Temporary variable for XTread_socket. */ | |
246 | ||
247 | static Lisp_Object previous_help_echo; | |
248 | ||
249 | /* Non-zero means that a HELP_EVENT has been generated since Emacs | |
250 | start. */ | |
251 | ||
252 | static int any_help_event_p; | |
253 | ||
254 | /* Non-zero means draw block and hollow cursor as wide as the glyph | |
255 | under it. For example, if a block cursor is over a tab, it will be | |
256 | drawn as wide as that tab on the display. */ | |
257 | ||
258 | int x_stretch_cursor_p; | |
259 | ||
260 | /* This is a chain of structures for all the X displays currently in | |
261 | use. */ | |
262 | ||
334208b7 | 263 | struct x_display_info *x_display_list; |
dc6f92b8 | 264 | |
06a2c219 GM |
265 | /* This is a list of cons cells, each of the form (NAME |
266 | . FONT-LIST-CACHE), one for each element of x_display_list and in | |
267 | the same order. NAME is the name of the frame. FONT-LIST-CACHE | |
268 | records previous values returned by x-list-fonts. */ | |
269 | ||
7a13e894 | 270 | Lisp_Object x_display_name_list; |
f451eb13 | 271 | |
987d2ad1 | 272 | /* Frame being updated by update_frame. This is declared in term.c. |
06a2c219 GM |
273 | This is set by update_begin and looked at by all the XT functions. |
274 | It is zero while not inside an update. In that case, the XT | |
275 | functions assume that `selected_frame' is the frame to apply to. */ | |
276 | ||
d0386f2a | 277 | extern struct frame *updating_frame; |
dc6f92b8 | 278 | |
dfcf069d | 279 | extern int waiting_for_input; |
0e81d8cd | 280 | |
06a2c219 GM |
281 | /* This is a frame waiting to be auto-raised, within XTread_socket. */ |
282 | ||
0134a210 RS |
283 | struct frame *pending_autoraise_frame; |
284 | ||
7f9c7f94 RS |
285 | #ifdef USE_X_TOOLKIT |
286 | /* The application context for Xt use. */ | |
287 | XtAppContext Xt_app_con; | |
06a2c219 GM |
288 | static String Xt_default_resources[] = {0}; |
289 | #endif /* USE_X_TOOLKIT */ | |
665881ad | 290 | |
06a2c219 GM |
291 | /* Nominal cursor position -- where to draw output. |
292 | HPOS and VPOS are window relative glyph matrix coordinates. | |
293 | X and Y are window relative pixel coordinates. */ | |
dc6f92b8 | 294 | |
06a2c219 | 295 | struct cursor_pos output_cursor; |
dc6f92b8 | 296 | |
bffcfca9 GM |
297 | /* Non-zero means user is interacting with a toolkit scroll bar. */ |
298 | ||
299 | static int toolkit_scroll_bar_interaction; | |
dc6f92b8 | 300 | |
69388238 RS |
301 | /* Mouse movement. |
302 | ||
06a2c219 | 303 | Formerly, we used PointerMotionHintMask (in standard_event_mask) |
f5bb65ec RS |
304 | so that we would have to call XQueryPointer after each MotionNotify |
305 | event to ask for another such event. However, this made mouse tracking | |
306 | slow, and there was a bug that made it eventually stop. | |
307 | ||
308 | Simply asking for MotionNotify all the time seems to work better. | |
309 | ||
69388238 RS |
310 | In order to avoid asking for motion events and then throwing most |
311 | of them away or busy-polling the server for mouse positions, we ask | |
312 | the server for pointer motion hints. This means that we get only | |
313 | one event per group of mouse movements. "Groups" are delimited by | |
314 | other kinds of events (focus changes and button clicks, for | |
315 | example), or by XQueryPointer calls; when one of these happens, we | |
316 | get another MotionNotify event the next time the mouse moves. This | |
317 | is at least as efficient as getting motion events when mouse | |
318 | tracking is on, and I suspect only negligibly worse when tracking | |
f5bb65ec | 319 | is off. */ |
69388238 RS |
320 | |
321 | /* Where the mouse was last time we reported a mouse event. */ | |
69388238 | 322 | |
06a2c219 GM |
323 | FRAME_PTR last_mouse_frame; |
324 | static XRectangle last_mouse_glyph; | |
2237cac9 RS |
325 | static Lisp_Object last_mouse_press_frame; |
326 | ||
69388238 RS |
327 | /* The scroll bar in which the last X motion event occurred. |
328 | ||
06a2c219 GM |
329 | If the last X motion event occurred in a scroll bar, we set this so |
330 | XTmouse_position can know whether to report a scroll bar motion or | |
69388238 RS |
331 | an ordinary motion. |
332 | ||
06a2c219 GM |
333 | If the last X motion event didn't occur in a scroll bar, we set |
334 | this to Qnil, to tell XTmouse_position to return an ordinary motion | |
335 | event. */ | |
336 | ||
69388238 RS |
337 | static Lisp_Object last_mouse_scroll_bar; |
338 | ||
69388238 RS |
339 | /* This is a hack. We would really prefer that XTmouse_position would |
340 | return the time associated with the position it returns, but there | |
06a2c219 | 341 | doesn't seem to be any way to wrest the time-stamp from the server |
69388238 RS |
342 | along with the position query. So, we just keep track of the time |
343 | of the last movement we received, and return that in hopes that | |
344 | it's somewhat accurate. */ | |
06a2c219 | 345 | |
69388238 RS |
346 | static Time last_mouse_movement_time; |
347 | ||
06a2c219 GM |
348 | /* Incremented by XTread_socket whenever it really tries to read |
349 | events. */ | |
350 | ||
c0a04927 RS |
351 | #ifdef __STDC__ |
352 | static int volatile input_signal_count; | |
353 | #else | |
354 | static int input_signal_count; | |
355 | #endif | |
356 | ||
7a13e894 | 357 | /* Used locally within XTread_socket. */ |
06a2c219 | 358 | |
7a13e894 | 359 | static int x_noop_count; |
dc6f92b8 | 360 | |
7a13e894 | 361 | /* Initial values of argv and argc. */ |
06a2c219 | 362 | |
7a13e894 RS |
363 | extern char **initial_argv; |
364 | extern int initial_argc; | |
dc6f92b8 | 365 | |
7a13e894 | 366 | extern Lisp_Object Vcommand_line_args, Vsystem_name; |
dc6f92b8 | 367 | |
06a2c219 | 368 | /* Tells if a window manager is present or not. */ |
7a13e894 RS |
369 | |
370 | extern Lisp_Object Vx_no_window_manager; | |
dc6f92b8 | 371 | |
c2df547c | 372 | extern Lisp_Object Qface, Qmouse_face; |
b8009dd1 | 373 | |
dc6f92b8 JB |
374 | extern int errno; |
375 | ||
dfeccd2d | 376 | /* A mask of extra modifier bits to put into every keyboard char. */ |
06a2c219 | 377 | |
64bb1782 RS |
378 | extern int extra_keyboard_modifiers; |
379 | ||
59e755be KH |
380 | static Lisp_Object Qvendor_specific_keysyms; |
381 | ||
952291d9 GM |
382 | extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *)); |
383 | extern Lisp_Object x_icon_type P_ ((struct frame *)); | |
c32cdd9a | 384 | |
7a13e894 | 385 | |
06a2c219 GM |
386 | /* Enumeration for overriding/changing the face to use for drawing |
387 | glyphs in x_draw_glyphs. */ | |
388 | ||
389 | enum draw_glyphs_face | |
390 | { | |
391 | DRAW_NORMAL_TEXT, | |
392 | DRAW_INVERSE_VIDEO, | |
393 | DRAW_CURSOR, | |
394 | DRAW_MOUSE_FACE, | |
395 | DRAW_IMAGE_RAISED, | |
396 | DRAW_IMAGE_SUNKEN | |
397 | }; | |
398 | ||
71b8321e | 399 | static void x_update_window_end P_ ((struct window *, int, int)); |
06a2c219 GM |
400 | static void frame_to_window_pixel_xy P_ ((struct window *, int *, int *)); |
401 | void x_delete_display P_ ((struct x_display_info *)); | |
402 | static unsigned int x_x_to_emacs_modifiers P_ ((struct x_display_info *, | |
403 | unsigned)); | |
404 | static int fast_find_position P_ ((struct window *, int, int *, int *, | |
405 | int *, int *)); | |
406 | static void set_output_cursor P_ ((struct cursor_pos *)); | |
407 | static struct glyph *x_y_to_hpos_vpos P_ ((struct window *, int, int, | |
408 | int *, int *, int *)); | |
409 | static void note_mode_line_highlight P_ ((struct window *, int, int)); | |
06a2c219 | 410 | static void note_mouse_highlight P_ ((struct frame *, int, int)); |
9ea173e8 GM |
411 | static void note_tool_bar_highlight P_ ((struct frame *f, int, int)); |
412 | static void x_handle_tool_bar_click P_ ((struct frame *, XButtonEvent *)); | |
06a2c219 GM |
413 | static void show_mouse_face P_ ((struct x_display_info *, |
414 | enum draw_glyphs_face)); | |
415 | static int x_io_error_quitter P_ ((Display *)); | |
416 | int x_catch_errors P_ ((Display *)); | |
417 | void x_uncatch_errors P_ ((Display *, int)); | |
418 | void x_lower_frame P_ ((struct frame *)); | |
419 | void x_scroll_bar_clear P_ ((struct frame *)); | |
420 | int x_had_errors_p P_ ((Display *)); | |
421 | void x_wm_set_size_hint P_ ((struct frame *, long, int)); | |
422 | void x_raise_frame P_ ((struct frame *)); | |
423 | void x_set_window_size P_ ((struct frame *, int, int, int)); | |
424 | void x_wm_set_window_state P_ ((struct frame *, int)); | |
425 | void x_wm_set_icon_pixmap P_ ((struct frame *, int)); | |
426 | void x_initialize P_ ((void)); | |
427 | static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); | |
428 | static int x_compute_min_glyph_bounds P_ ((struct frame *)); | |
429 | static void x_draw_phys_cursor_glyph P_ ((struct window *, | |
430 | struct glyph_row *, | |
431 | enum draw_glyphs_face)); | |
432 | static void x_update_end P_ ((struct frame *)); | |
433 | static void XTframe_up_to_date P_ ((struct frame *)); | |
434 | static void XTreassert_line_highlight P_ ((int, int)); | |
435 | static void x_change_line_highlight P_ ((int, int, int, int)); | |
436 | static void XTset_terminal_modes P_ ((void)); | |
437 | static void XTreset_terminal_modes P_ ((void)); | |
438 | static void XTcursor_to P_ ((int, int, int, int)); | |
439 | static void x_write_glyphs P_ ((struct glyph *, int)); | |
440 | static void x_clear_end_of_line P_ ((int)); | |
441 | static void x_clear_frame P_ ((void)); | |
442 | static void x_clear_cursor P_ ((struct window *)); | |
443 | static void frame_highlight P_ ((struct frame *)); | |
444 | static void frame_unhighlight P_ ((struct frame *)); | |
445 | static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *)); | |
446 | static void XTframe_rehighlight P_ ((struct frame *)); | |
447 | static void x_frame_rehighlight P_ ((struct x_display_info *)); | |
448 | static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); | |
f02d8aa0 | 449 | static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int)); |
06a2c219 GM |
450 | static int x_intersect_rectangles P_ ((XRectangle *, XRectangle *, |
451 | XRectangle *)); | |
452 | static void expose_frame P_ ((struct frame *, int, int, int, int)); | |
453 | static void expose_window_tree P_ ((struct window *, XRectangle *)); | |
454 | static void expose_window P_ ((struct window *, XRectangle *)); | |
455 | static void expose_area P_ ((struct window *, struct glyph_row *, | |
456 | XRectangle *, enum glyph_row_area)); | |
457 | static void expose_line P_ ((struct window *, struct glyph_row *, | |
458 | XRectangle *)); | |
459 | static void x_update_cursor_in_window_tree P_ ((struct window *, int)); | |
460 | static void x_update_window_cursor P_ ((struct window *, int)); | |
461 | static void x_erase_phys_cursor P_ ((struct window *)); | |
462 | void x_display_and_set_cursor P_ ((struct window *, int, int, int, int, int)); | |
463 | static void x_draw_bitmap P_ ((struct window *, struct glyph_row *, | |
464 | enum bitmap_type)); | |
465 | ||
466 | static void x_clip_to_row P_ ((struct window *, struct glyph_row *, | |
467 | GC, int)); | |
468 | static int x_phys_cursor_in_rect_p P_ ((struct window *, XRectangle *)); | |
469 | static void x_draw_row_bitmaps P_ ((struct window *, struct glyph_row *)); | |
470 | static void note_overwritten_text_cursor P_ ((struct window *, int, int)); | |
471 | static void x_flush P_ ((struct frame *f)); | |
952291d9 GM |
472 | static void x_update_begin P_ ((struct frame *)); |
473 | static void x_update_window_begin P_ ((struct window *)); | |
474 | static void x_draw_vertical_border P_ ((struct window *)); | |
475 | static void x_after_update_window_line P_ ((struct glyph_row *)); | |
476 | static INLINE void take_vertical_position_into_account P_ ((struct it *)); | |
477 | static void x_produce_stretch_glyph P_ ((struct it *)); | |
478 | ||
06a2c219 GM |
479 | |
480 | /* Flush display of frame F, or of all frames if F is null. */ | |
481 | ||
482 | static void | |
483 | x_flush (f) | |
484 | struct frame *f; | |
485 | { | |
486 | BLOCK_INPUT; | |
487 | if (f == NULL) | |
488 | { | |
489 | Lisp_Object rest, frame; | |
490 | FOR_EACH_FRAME (rest, frame) | |
491 | x_flush (XFRAME (frame)); | |
492 | } | |
493 | else if (FRAME_X_P (f)) | |
494 | XFlush (FRAME_X_DISPLAY (f)); | |
495 | UNBLOCK_INPUT; | |
496 | } | |
497 | ||
dc6f92b8 | 498 | |
06a2c219 GM |
499 | /* Remove calls to XFlush by defining XFlush to an empty replacement. |
500 | Calls to XFlush should be unnecessary because the X output buffer | |
501 | is flushed automatically as needed by calls to XPending, | |
502 | XNextEvent, or XWindowEvent according to the XFlush man page. | |
503 | XTread_socket calls XPending. Removing XFlush improves | |
504 | performance. */ | |
505 | ||
506 | #define XFlush(DISPLAY) (void) 0 | |
b8009dd1 | 507 | |
334208b7 | 508 | \f |
06a2c219 GM |
509 | /*********************************************************************** |
510 | Debugging | |
511 | ***********************************************************************/ | |
512 | ||
9382638d | 513 | #if 0 |
06a2c219 GM |
514 | |
515 | /* This is a function useful for recording debugging information about | |
516 | the sequence of occurrences in this file. */ | |
9382638d KH |
517 | |
518 | struct record | |
519 | { | |
520 | char *locus; | |
521 | int type; | |
522 | }; | |
523 | ||
524 | struct record event_record[100]; | |
525 | ||
526 | int event_record_index; | |
527 | ||
528 | record_event (locus, type) | |
529 | char *locus; | |
530 | int type; | |
531 | { | |
532 | if (event_record_index == sizeof (event_record) / sizeof (struct record)) | |
533 | event_record_index = 0; | |
534 | ||
535 | event_record[event_record_index].locus = locus; | |
536 | event_record[event_record_index].type = type; | |
537 | event_record_index++; | |
538 | } | |
539 | ||
540 | #endif /* 0 */ | |
06a2c219 GM |
541 | |
542 | ||
9382638d | 543 | \f |
334208b7 RS |
544 | /* Return the struct x_display_info corresponding to DPY. */ |
545 | ||
546 | struct x_display_info * | |
547 | x_display_info_for_display (dpy) | |
548 | Display *dpy; | |
549 | { | |
550 | struct x_display_info *dpyinfo; | |
551 | ||
552 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) | |
553 | if (dpyinfo->display == dpy) | |
554 | return dpyinfo; | |
16bd92ea | 555 | |
334208b7 RS |
556 | return 0; |
557 | } | |
f451eb13 | 558 | |
06a2c219 GM |
559 | |
560 | \f | |
561 | /*********************************************************************** | |
562 | Starting and ending an update | |
563 | ***********************************************************************/ | |
564 | ||
565 | /* Start an update of frame F. This function is installed as a hook | |
566 | for update_begin, i.e. it is called when update_begin is called. | |
567 | This function is called prior to calls to x_update_window_begin for | |
568 | each window being updated. Currently, there is nothing to do here | |
569 | because all interesting stuff is done on a window basis. */ | |
dc6f92b8 | 570 | |
dfcf069d | 571 | static void |
06a2c219 | 572 | x_update_begin (f) |
f676886a | 573 | struct frame *f; |
58769bee | 574 | { |
06a2c219 GM |
575 | /* Nothing to do. */ |
576 | } | |
dc6f92b8 | 577 | |
dc6f92b8 | 578 | |
06a2c219 GM |
579 | /* Start update of window W. Set the global variable updated_window |
580 | to the window being updated and set output_cursor to the cursor | |
581 | position of W. */ | |
dc6f92b8 | 582 | |
06a2c219 GM |
583 | static void |
584 | x_update_window_begin (w) | |
585 | struct window *w; | |
586 | { | |
587 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
588 | struct x_display_info *display_info = FRAME_X_DISPLAY_INFO (f); | |
589 | ||
590 | updated_window = w; | |
591 | set_output_cursor (&w->cursor); | |
b8009dd1 | 592 | |
06a2c219 | 593 | BLOCK_INPUT; |
d1bc4182 | 594 | |
06a2c219 | 595 | if (f == display_info->mouse_face_mouse_frame) |
b8009dd1 | 596 | { |
514e4681 | 597 | /* Don't do highlighting for mouse motion during the update. */ |
06a2c219 | 598 | display_info->mouse_face_defer = 1; |
37c2c98b | 599 | |
06a2c219 GM |
600 | /* If F needs to be redrawn, simply forget about any prior mouse |
601 | highlighting. */ | |
9f67f20b | 602 | if (FRAME_GARBAGED_P (f)) |
06a2c219 GM |
603 | display_info->mouse_face_window = Qnil; |
604 | ||
64f26cf5 GM |
605 | #if 0 /* Rows in a current matrix containing glyphs in mouse-face have |
606 | their mouse_face_p flag set, which means that they are always | |
607 | unequal to rows in a desired matrix which never have that | |
608 | flag set. So, rows containing mouse-face glyphs are never | |
609 | scrolled, and we don't have to switch the mouse highlight off | |
610 | here to prevent it from being scrolled. */ | |
611 | ||
06a2c219 GM |
612 | /* Can we tell that this update does not affect the window |
613 | where the mouse highlight is? If so, no need to turn off. | |
614 | Likewise, don't do anything if the frame is garbaged; | |
615 | in that case, the frame's current matrix that we would use | |
616 | is all wrong, and we will redisplay that line anyway. */ | |
617 | if (!NILP (display_info->mouse_face_window) | |
618 | && w == XWINDOW (display_info->mouse_face_window)) | |
514e4681 | 619 | { |
06a2c219 | 620 | int i; |
514e4681 | 621 | |
06a2c219 GM |
622 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
623 | if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i)) | |
514e4681 RS |
624 | break; |
625 | ||
06a2c219 GM |
626 | if (i < w->desired_matrix->nrows) |
627 | clear_mouse_face (display_info); | |
514e4681 | 628 | } |
64f26cf5 | 629 | #endif /* 0 */ |
b8009dd1 | 630 | } |
6ccf47d1 | 631 | |
dc6f92b8 JB |
632 | UNBLOCK_INPUT; |
633 | } | |
634 | ||
06a2c219 GM |
635 | |
636 | /* Draw a vertical window border to the right of window W if W doesn't | |
637 | have vertical scroll bars. */ | |
638 | ||
dfcf069d | 639 | static void |
06a2c219 GM |
640 | x_draw_vertical_border (w) |
641 | struct window *w; | |
58769bee | 642 | { |
06a2c219 GM |
643 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
644 | ||
645 | /* Redraw borders between horizontally adjacent windows. Don't | |
646 | do it for frames with vertical scroll bars because either the | |
647 | right scroll bar of a window, or the left scroll bar of its | |
648 | neighbor will suffice as a border. */ | |
649 | if (!WINDOW_RIGHTMOST_P (w) | |
650 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
651 | { | |
652 | int x0, x1, y0, y1; | |
dc6f92b8 | 653 | |
06a2c219 | 654 | window_box_edges (w, -1, &x0, &y0, &x1, &y1); |
110859fc | 655 | x1 += FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f); |
06a2c219 GM |
656 | y1 -= 1; |
657 | ||
658 | XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
659 | f->output_data.x->normal_gc, x1, y0, x1, y1); | |
660 | } | |
661 | } | |
662 | ||
663 | ||
71b8321e GM |
664 | /* End update of window W (which is equal to updated_window). |
665 | ||
666 | Draw vertical borders between horizontally adjacent windows, and | |
667 | display W's cursor if CURSOR_ON_P is non-zero. | |
668 | ||
669 | MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing | |
670 | glyphs in mouse-face were overwritten. In that case we have to | |
671 | make sure that the mouse-highlight is properly redrawn. | |
672 | ||
673 | W may be a menu bar pseudo-window in case we don't have X toolkit | |
674 | support. Such windows don't have a cursor, so don't display it | |
675 | here. */ | |
06a2c219 GM |
676 | |
677 | static void | |
71b8321e | 678 | x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p) |
06a2c219 | 679 | struct window *w; |
71b8321e | 680 | int cursor_on_p, mouse_face_overwritten_p; |
06a2c219 GM |
681 | { |
682 | if (!w->pseudo_window_p) | |
683 | { | |
71b8321e GM |
684 | struct x_display_info *dpyinfo |
685 | = FRAME_X_DISPLAY_INFO (XFRAME (w->frame)); | |
686 | ||
06a2c219 | 687 | BLOCK_INPUT; |
71b8321e GM |
688 | |
689 | /* If a row with mouse-face was overwritten, arrange for | |
690 | XTframe_up_to_date to redisplay the mouse highlight. */ | |
691 | if (mouse_face_overwritten_p) | |
692 | { | |
693 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
694 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
695 | dpyinfo->mouse_face_window = Qnil; | |
696 | } | |
697 | ||
06a2c219 GM |
698 | if (cursor_on_p) |
699 | x_display_and_set_cursor (w, 1, output_cursor.hpos, | |
700 | output_cursor.vpos, | |
701 | output_cursor.x, output_cursor.y); | |
71b8321e | 702 | |
06a2c219 GM |
703 | x_draw_vertical_border (w); |
704 | UNBLOCK_INPUT; | |
705 | } | |
706 | ||
707 | updated_window = NULL; | |
708 | } | |
dc6f92b8 | 709 | |
dc6f92b8 | 710 | |
06a2c219 GM |
711 | /* End update of frame F. This function is installed as a hook in |
712 | update_end. */ | |
713 | ||
714 | static void | |
715 | x_update_end (f) | |
716 | struct frame *f; | |
717 | { | |
718 | /* Mouse highlight may be displayed again. */ | |
aa8bff2e | 719 | FRAME_X_DISPLAY_INFO (f)->mouse_face_defer = 0; |
b8009dd1 | 720 | |
06a2c219 | 721 | BLOCK_INPUT; |
334208b7 | 722 | XFlush (FRAME_X_DISPLAY (f)); |
dc6f92b8 JB |
723 | UNBLOCK_INPUT; |
724 | } | |
b8009dd1 | 725 | |
06a2c219 GM |
726 | |
727 | /* This function is called from various places in xdisp.c whenever a | |
728 | complete update has been performed. The global variable | |
729 | updated_window is not available here. */ | |
b8009dd1 | 730 | |
dfcf069d | 731 | static void |
b8009dd1 | 732 | XTframe_up_to_date (f) |
06a2c219 | 733 | struct frame *f; |
b8009dd1 | 734 | { |
06a2c219 | 735 | if (FRAME_X_P (f)) |
514e4681 | 736 | { |
06a2c219 | 737 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
71b8321e | 738 | |
06a2c219 GM |
739 | if (dpyinfo->mouse_face_deferred_gc |
740 | || f == dpyinfo->mouse_face_mouse_frame) | |
741 | { | |
742 | BLOCK_INPUT; | |
743 | if (dpyinfo->mouse_face_mouse_frame) | |
744 | note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, | |
745 | dpyinfo->mouse_face_mouse_x, | |
746 | dpyinfo->mouse_face_mouse_y); | |
747 | dpyinfo->mouse_face_deferred_gc = 0; | |
748 | UNBLOCK_INPUT; | |
749 | } | |
514e4681 | 750 | } |
b8009dd1 | 751 | } |
06a2c219 GM |
752 | |
753 | ||
754 | /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay | |
755 | arrow bitmaps, or clear the areas where they would be displayed | |
756 | before DESIRED_ROW is made current. The window being updated is | |
757 | found in updated_window. This function It is called from | |
758 | update_window_line only if it is known that there are differences | |
759 | between bitmaps to be drawn between current row and DESIRED_ROW. */ | |
760 | ||
761 | static void | |
762 | x_after_update_window_line (desired_row) | |
763 | struct glyph_row *desired_row; | |
764 | { | |
765 | struct window *w = updated_window; | |
766 | ||
767 | xassert (w); | |
768 | ||
769 | if (!desired_row->mode_line_p && !w->pseudo_window_p) | |
770 | { | |
771 | BLOCK_INPUT; | |
772 | x_draw_row_bitmaps (w, desired_row); | |
773 | ||
774 | /* When a window has disappeared, make sure that no rest of | |
775 | full-width rows stays visible in the internal border. */ | |
776 | if (windows_or_buffers_changed) | |
777 | { | |
778 | struct frame *f = XFRAME (w->frame); | |
779 | int width = FRAME_INTERNAL_BORDER_WIDTH (f); | |
780 | int height = desired_row->visible_height; | |
110859fc GM |
781 | int x = (window_box_right (w, -1) |
782 | + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f)); | |
06a2c219 GM |
783 | int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); |
784 | ||
785 | XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
786 | x, y, width, height, False); | |
787 | } | |
788 | ||
789 | UNBLOCK_INPUT; | |
790 | } | |
791 | } | |
792 | ||
793 | ||
794 | /* Draw the bitmap WHICH in one of the areas to the left or right of | |
795 | window W. ROW is the glyph row for which to display the bitmap; it | |
796 | determines the vertical position at which the bitmap has to be | |
797 | drawn. */ | |
798 | ||
799 | static void | |
800 | x_draw_bitmap (w, row, which) | |
801 | struct window *w; | |
802 | struct glyph_row *row; | |
803 | enum bitmap_type which; | |
804 | { | |
805 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
806 | Display *display = FRAME_X_DISPLAY (f); | |
807 | Window window = FRAME_X_WINDOW (f); | |
808 | int x, y, wd, h, dy; | |
809 | unsigned char *bits; | |
810 | Pixmap pixmap; | |
811 | GC gc = f->output_data.x->normal_gc; | |
812 | struct face *face; | |
813 | int depth = DefaultDepthOfScreen (FRAME_X_SCREEN (f)); | |
814 | ||
815 | /* Must clip because of partially visible lines. */ | |
816 | x_clip_to_row (w, row, gc, 1); | |
817 | ||
818 | switch (which) | |
819 | { | |
820 | case LEFT_TRUNCATION_BITMAP: | |
821 | wd = left_width; | |
822 | h = left_height; | |
823 | bits = left_bits; | |
824 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) | |
825 | - wd | |
110859fc | 826 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); |
06a2c219 GM |
827 | break; |
828 | ||
829 | case OVERLAY_ARROW_BITMAP: | |
830 | wd = left_width; | |
831 | h = left_height; | |
832 | bits = ov_bits; | |
833 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) | |
834 | - wd | |
110859fc | 835 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); |
06a2c219 GM |
836 | break; |
837 | ||
838 | case RIGHT_TRUNCATION_BITMAP: | |
839 | wd = right_width; | |
840 | h = right_height; | |
841 | bits = right_bits; | |
842 | x = window_box_right (w, -1); | |
110859fc | 843 | x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; |
06a2c219 GM |
844 | break; |
845 | ||
846 | case CONTINUED_LINE_BITMAP: | |
847 | wd = right_width; | |
848 | h = right_height; | |
849 | bits = continued_bits; | |
850 | x = window_box_right (w, -1); | |
110859fc | 851 | x += (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) - wd) / 2; |
06a2c219 GM |
852 | break; |
853 | ||
854 | case CONTINUATION_LINE_BITMAP: | |
855 | wd = continuation_width; | |
856 | h = continuation_height; | |
857 | bits = continuation_bits; | |
858 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) | |
859 | - wd | |
110859fc | 860 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); |
06a2c219 GM |
861 | break; |
862 | ||
863 | case ZV_LINE_BITMAP: | |
864 | wd = zv_width; | |
865 | h = zv_height; | |
866 | bits = zv_bits; | |
867 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) | |
868 | - wd | |
110859fc | 869 | - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - wd) / 2); |
06a2c219 GM |
870 | break; |
871 | ||
872 | default: | |
873 | abort (); | |
874 | } | |
875 | ||
876 | /* Convert to frame coordinates. Set dy to the offset in the row to | |
877 | start drawing the bitmap. */ | |
878 | y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
879 | dy = (row->height - h) / 2; | |
880 | ||
881 | /* Draw the bitmap. I believe these small pixmaps can be cached | |
882 | by the server. */ | |
883 | face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); | |
884 | pixmap = XCreatePixmapFromBitmapData (display, window, bits, wd, h, | |
885 | face->foreground, | |
886 | face->background, depth); | |
887 | XCopyArea (display, pixmap, window, gc, 0, 0, wd, h, x, y + dy); | |
888 | XFreePixmap (display, pixmap); | |
889 | XSetClipMask (display, gc, None); | |
890 | } | |
891 | ||
892 | ||
893 | /* Draw flags bitmaps for glyph row ROW on window W. Call this | |
894 | function with input blocked. */ | |
895 | ||
896 | static void | |
897 | x_draw_row_bitmaps (w, row) | |
898 | struct window *w; | |
899 | struct glyph_row *row; | |
900 | { | |
901 | struct frame *f = XFRAME (w->frame); | |
902 | enum bitmap_type bitmap; | |
903 | struct face *face; | |
045dee35 | 904 | int header_line_height = -1; |
06a2c219 GM |
905 | |
906 | xassert (interrupt_input_blocked); | |
907 | ||
908 | /* If row is completely invisible, because of vscrolling, we | |
909 | don't have to draw anything. */ | |
910 | if (row->visible_height <= 0) | |
911 | return; | |
912 | ||
913 | face = FACE_FROM_ID (f, BITMAP_AREA_FACE_ID); | |
914 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
915 | ||
916 | /* Decide which bitmap to draw at the left side. */ | |
917 | if (row->overlay_arrow_p) | |
918 | bitmap = OVERLAY_ARROW_BITMAP; | |
919 | else if (row->truncated_on_left_p) | |
920 | bitmap = LEFT_TRUNCATION_BITMAP; | |
921 | else if (MATRIX_ROW_CONTINUATION_LINE_P (row)) | |
922 | bitmap = CONTINUATION_LINE_BITMAP; | |
923 | else if (row->indicate_empty_line_p) | |
924 | bitmap = ZV_LINE_BITMAP; | |
925 | else | |
926 | bitmap = NO_BITMAP; | |
927 | ||
928 | /* Clear flags area if no bitmap to draw or if bitmap doesn't fill | |
929 | the flags area. */ | |
930 | if (bitmap == NO_BITMAP | |
110859fc | 931 | || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) |
06a2c219 GM |
932 | || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) |
933 | { | |
934 | /* If W has a vertical border to its left, don't draw over it. */ | |
935 | int border = ((XFASTINT (w->left) > 0 | |
936 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
937 | ? 1 : 0); | |
938 | int left = window_box_left (w, -1); | |
939 | ||
045dee35 GM |
940 | if (header_line_height < 0) |
941 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
dcd08bfb GM |
942 | |
943 | /* In case the same realized face is used for bitmap areas and | |
944 | for something displayed in the text (e.g. face `region' on | |
945 | mono-displays, the fill style may have been changed to | |
946 | FillSolid in x_draw_glyph_string_background. */ | |
947 | if (face->stipple) | |
948 | XSetFillStyle (FRAME_X_DISPLAY (f), face->gc, FillOpaqueStippled); | |
949 | else | |
950 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->background); | |
951 | ||
06a2c219 GM |
952 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
953 | face->gc, | |
954 | (left | |
110859fc | 955 | - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) |
06a2c219 | 956 | + border), |
045dee35 | 957 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, |
06a2c219 | 958 | row->y)), |
110859fc | 959 | FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) - border, |
06a2c219 | 960 | row->visible_height); |
dcd08bfb GM |
961 | if (!face->stipple) |
962 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); | |
06a2c219 GM |
963 | } |
964 | ||
965 | /* Draw the left bitmap. */ | |
966 | if (bitmap != NO_BITMAP) | |
967 | x_draw_bitmap (w, row, bitmap); | |
968 | ||
969 | /* Decide which bitmap to draw at the right side. */ | |
970 | if (row->truncated_on_right_p) | |
971 | bitmap = RIGHT_TRUNCATION_BITMAP; | |
972 | else if (row->continued_p) | |
973 | bitmap = CONTINUED_LINE_BITMAP; | |
974 | else | |
975 | bitmap = NO_BITMAP; | |
976 | ||
977 | /* Clear flags area if no bitmap to draw of if bitmap doesn't fill | |
978 | the flags area. */ | |
979 | if (bitmap == NO_BITMAP | |
110859fc | 980 | || FRAME_FLAGS_BITMAP_WIDTH (f) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f) |
06a2c219 GM |
981 | || row->height > FRAME_FLAGS_BITMAP_HEIGHT (f)) |
982 | { | |
983 | int right = window_box_right (w, -1); | |
984 | ||
045dee35 GM |
985 | if (header_line_height < 0) |
986 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
dcd08bfb GM |
987 | |
988 | /* In case the same realized face is used for bitmap areas and | |
989 | for something displayed in the text (e.g. face `region' on | |
990 | mono-displays, the fill style may have been changed to | |
991 | FillSolid in x_draw_glyph_string_background. */ | |
992 | if (face->stipple) | |
993 | XSetFillStyle (FRAME_X_DISPLAY (f), face->gc, FillOpaqueStippled); | |
994 | else | |
995 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->background); | |
06a2c219 GM |
996 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
997 | face->gc, | |
998 | right, | |
045dee35 | 999 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, |
06a2c219 | 1000 | row->y)), |
110859fc | 1001 | FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f), |
06a2c219 | 1002 | row->visible_height); |
dcd08bfb GM |
1003 | if (!face->stipple) |
1004 | XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); | |
06a2c219 GM |
1005 | } |
1006 | ||
1007 | /* Draw the right bitmap. */ | |
1008 | if (bitmap != NO_BITMAP) | |
1009 | x_draw_bitmap (w, row, bitmap); | |
1010 | } | |
1011 | ||
dc6f92b8 | 1012 | \f |
06a2c219 GM |
1013 | /*********************************************************************** |
1014 | Line Highlighting | |
1015 | ***********************************************************************/ | |
dc6f92b8 | 1016 | |
06a2c219 GM |
1017 | /* External interface to control of standout mode. Not used for X |
1018 | frames. Aborts when called. */ | |
1019 | ||
1020 | static void | |
dc6f92b8 JB |
1021 | XTreassert_line_highlight (new, vpos) |
1022 | int new, vpos; | |
1023 | { | |
06a2c219 | 1024 | abort (); |
dc6f92b8 JB |
1025 | } |
1026 | ||
06a2c219 GM |
1027 | |
1028 | /* Call this when about to modify line at position VPOS and change | |
1029 | whether it is highlighted. Not used for X frames. Aborts when | |
1030 | called. */ | |
dc6f92b8 | 1031 | |
dfcf069d | 1032 | static void |
06a2c219 GM |
1033 | x_change_line_highlight (new_highlight, vpos, y, first_unused_hpos) |
1034 | int new_highlight, vpos, y, first_unused_hpos; | |
dc6f92b8 | 1035 | { |
06a2c219 | 1036 | abort (); |
dc6f92b8 JB |
1037 | } |
1038 | ||
06a2c219 GM |
1039 | |
1040 | /* This is called when starting Emacs and when restarting after | |
1041 | suspend. When starting Emacs, no X window is mapped. And nothing | |
1042 | must be done to Emacs's own window if it is suspended (though that | |
1043 | rarely happens). */ | |
dc6f92b8 | 1044 | |
dfcf069d | 1045 | static void |
dc6f92b8 JB |
1046 | XTset_terminal_modes () |
1047 | { | |
1048 | } | |
1049 | ||
06a2c219 GM |
1050 | /* This is called when exiting or suspending Emacs. Exiting will make |
1051 | the X-windows go away, and suspending requires no action. */ | |
dc6f92b8 | 1052 | |
dfcf069d | 1053 | static void |
dc6f92b8 JB |
1054 | XTreset_terminal_modes () |
1055 | { | |
dc6f92b8 | 1056 | } |
06a2c219 GM |
1057 | |
1058 | ||
dc6f92b8 | 1059 | \f |
06a2c219 GM |
1060 | /*********************************************************************** |
1061 | Output Cursor | |
1062 | ***********************************************************************/ | |
1063 | ||
1064 | /* Set the global variable output_cursor to CURSOR. All cursor | |
1065 | positions are relative to updated_window. */ | |
dc6f92b8 | 1066 | |
dfcf069d | 1067 | static void |
06a2c219 GM |
1068 | set_output_cursor (cursor) |
1069 | struct cursor_pos *cursor; | |
dc6f92b8 | 1070 | { |
06a2c219 GM |
1071 | output_cursor.hpos = cursor->hpos; |
1072 | output_cursor.vpos = cursor->vpos; | |
1073 | output_cursor.x = cursor->x; | |
1074 | output_cursor.y = cursor->y; | |
1075 | } | |
1076 | ||
1077 | ||
1078 | /* Set a nominal cursor position. | |
dc6f92b8 | 1079 | |
06a2c219 GM |
1080 | HPOS and VPOS are column/row positions in a window glyph matrix. X |
1081 | and Y are window text area relative pixel positions. | |
1082 | ||
1083 | If this is done during an update, updated_window will contain the | |
1084 | window that is being updated and the position is the future output | |
1085 | cursor position for that window. If updated_window is null, use | |
1086 | selected_window and display the cursor at the given position. */ | |
1087 | ||
1088 | static void | |
1089 | XTcursor_to (vpos, hpos, y, x) | |
1090 | int vpos, hpos, y, x; | |
1091 | { | |
1092 | struct window *w; | |
1093 | ||
1094 | /* If updated_window is not set, work on selected_window. */ | |
1095 | if (updated_window) | |
1096 | w = updated_window; | |
1097 | else | |
1098 | w = XWINDOW (selected_window); | |
dbcb258a | 1099 | |
06a2c219 GM |
1100 | /* Set the output cursor. */ |
1101 | output_cursor.hpos = hpos; | |
1102 | output_cursor.vpos = vpos; | |
1103 | output_cursor.x = x; | |
1104 | output_cursor.y = y; | |
dc6f92b8 | 1105 | |
06a2c219 GM |
1106 | /* If not called as part of an update, really display the cursor. |
1107 | This will also set the cursor position of W. */ | |
1108 | if (updated_window == NULL) | |
dc6f92b8 JB |
1109 | { |
1110 | BLOCK_INPUT; | |
06a2c219 | 1111 | x_display_cursor (w, 1, hpos, vpos, x, y); |
b86bd3dd | 1112 | XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ())); |
dc6f92b8 JB |
1113 | UNBLOCK_INPUT; |
1114 | } | |
1115 | } | |
dc43ef94 | 1116 | |
06a2c219 GM |
1117 | |
1118 | \f | |
1119 | /*********************************************************************** | |
1120 | Display Iterator | |
1121 | ***********************************************************************/ | |
1122 | ||
1123 | /* Function prototypes of this page. */ | |
1124 | ||
1125 | static struct face *x_get_glyph_face_and_encoding P_ ((struct frame *, | |
1126 | struct glyph *, | |
ee569018 KH |
1127 | XChar2b *, |
1128 | int *)); | |
06a2c219 GM |
1129 | static struct face *x_get_char_face_and_encoding P_ ((struct frame *, int, |
1130 | int, XChar2b *, int)); | |
1131 | static XCharStruct *x_per_char_metric P_ ((XFontStruct *, XChar2b *)); | |
1132 | static void x_encode_char P_ ((int, XChar2b *, struct font_info *)); | |
1133 | static void x_append_glyph P_ ((struct it *)); | |
b4192550 | 1134 | static void x_append_composite_glyph P_ ((struct it *)); |
06a2c219 GM |
1135 | static void x_append_stretch_glyph P_ ((struct it *it, Lisp_Object, |
1136 | int, int, double)); | |
1137 | static void x_produce_glyphs P_ ((struct it *)); | |
06a2c219 | 1138 | static void x_produce_image_glyph P_ ((struct it *it)); |
ee569018 KH |
1139 | |
1140 | ||
1141 | /* Return a pointer to per-char metric information in FONT of a | |
1142 | character pointed by B which is a pointer to an XChar2b. */ | |
1143 | ||
1144 | #define PER_CHAR_METRIC(font, b) \ | |
1145 | ((font)->per_char \ | |
1146 | ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \ | |
1147 | + (((font)->min_byte1 || (font)->max_byte1) \ | |
1148 | ? (((b)->byte1 - (font)->min_byte1) \ | |
1149 | * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \ | |
1150 | : 0)) \ | |
1151 | : &((font)->max_bounds)) | |
dc43ef94 | 1152 | |
dc6f92b8 | 1153 | |
e2ef8ee6 GM |
1154 | /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B |
1155 | is not contained in the font. */ | |
dc43ef94 | 1156 | |
06a2c219 | 1157 | static INLINE XCharStruct * |
ee569018 | 1158 | x_per_char_metric (font, char2b) |
06a2c219 GM |
1159 | XFontStruct *font; |
1160 | XChar2b *char2b; | |
1161 | { | |
1162 | /* The result metric information. */ | |
1163 | XCharStruct *pcm = NULL; | |
dc6f92b8 | 1164 | |
06a2c219 | 1165 | xassert (font && char2b); |
dc6f92b8 | 1166 | |
06a2c219 | 1167 | if (font->per_char != NULL) |
dc6f92b8 | 1168 | { |
06a2c219 | 1169 | if (font->min_byte1 == 0 && font->max_byte1 == 0) |
dc43ef94 | 1170 | { |
06a2c219 GM |
1171 | /* min_char_or_byte2 specifies the linear character index |
1172 | corresponding to the first element of the per_char array, | |
1173 | max_char_or_byte2 is the index of the last character. A | |
1174 | character with non-zero CHAR2B->byte1 is not in the font. | |
1175 | A character with byte2 less than min_char_or_byte2 or | |
1176 | greater max_char_or_byte2 is not in the font. */ | |
1177 | if (char2b->byte1 == 0 | |
1178 | && char2b->byte2 >= font->min_char_or_byte2 | |
1179 | && char2b->byte2 <= font->max_char_or_byte2) | |
1180 | pcm = font->per_char + char2b->byte2 - font->min_char_or_byte2; | |
dc43ef94 | 1181 | } |
06a2c219 | 1182 | else |
dc6f92b8 | 1183 | { |
06a2c219 GM |
1184 | /* If either min_byte1 or max_byte1 are nonzero, both |
1185 | min_char_or_byte2 and max_char_or_byte2 are less than | |
1186 | 256, and the 2-byte character index values corresponding | |
1187 | to the per_char array element N (counting from 0) are: | |
1188 | ||
1189 | byte1 = N/D + min_byte1 | |
1190 | byte2 = N\D + min_char_or_byte2 | |
1191 | ||
1192 | where: | |
1193 | ||
1194 | D = max_char_or_byte2 - min_char_or_byte2 + 1 | |
1195 | / = integer division | |
1196 | \ = integer modulus */ | |
1197 | if (char2b->byte1 >= font->min_byte1 | |
1198 | && char2b->byte1 <= font->max_byte1 | |
1199 | && char2b->byte2 >= font->min_char_or_byte2 | |
1200 | && char2b->byte2 <= font->max_char_or_byte2) | |
1201 | { | |
1202 | pcm = (font->per_char | |
1203 | + ((font->max_char_or_byte2 - font->min_char_or_byte2 + 1) | |
1204 | * (char2b->byte1 - font->min_byte1)) | |
1205 | + (char2b->byte2 - font->min_char_or_byte2)); | |
1206 | } | |
dc6f92b8 | 1207 | } |
06a2c219 GM |
1208 | } |
1209 | else | |
1210 | { | |
1211 | /* If the per_char pointer is null, all glyphs between the first | |
1212 | and last character indexes inclusive have the same | |
1213 | information, as given by both min_bounds and max_bounds. */ | |
1214 | if (char2b->byte2 >= font->min_char_or_byte2 | |
1215 | && char2b->byte2 <= font->max_char_or_byte2) | |
1216 | pcm = &font->max_bounds; | |
1217 | } | |
dc6f92b8 | 1218 | |
ee569018 | 1219 | return ((pcm == NULL |
3e71d8f2 | 1220 | || (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0)) |
ee569018 | 1221 | ? NULL : pcm); |
06a2c219 | 1222 | } |
b73b6aaf | 1223 | |
57b03282 | 1224 | |
06a2c219 GM |
1225 | /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is |
1226 | the two-byte form of C. Encoding is returned in *CHAR2B. */ | |
dc43ef94 | 1227 | |
06a2c219 GM |
1228 | static INLINE void |
1229 | x_encode_char (c, char2b, font_info) | |
1230 | int c; | |
1231 | XChar2b *char2b; | |
1232 | struct font_info *font_info; | |
1233 | { | |
1234 | int charset = CHAR_CHARSET (c); | |
1235 | XFontStruct *font = font_info->font; | |
1236 | ||
1237 | /* FONT_INFO may define a scheme by which to encode byte1 and byte2. | |
1238 | This may be either a program in a special encoder language or a | |
1239 | fixed encoding. */ | |
1240 | if (font_info->font_encoder) | |
1241 | { | |
1242 | /* It's a program. */ | |
1243 | struct ccl_program *ccl = font_info->font_encoder; | |
1244 | ||
1245 | if (CHARSET_DIMENSION (charset) == 1) | |
1246 | { | |
1247 | ccl->reg[0] = charset; | |
1248 | ccl->reg[1] = char2b->byte2; | |
1249 | } | |
1250 | else | |
1251 | { | |
1252 | ccl->reg[0] = charset; | |
1253 | ccl->reg[1] = char2b->byte1; | |
1254 | ccl->reg[2] = char2b->byte2; | |
1255 | } | |
1256 | ||
1257 | ccl_driver (ccl, NULL, NULL, 0, 0, NULL); | |
1258 | ||
1259 | /* We assume that MSBs are appropriately set/reset by CCL | |
1260 | program. */ | |
1261 | if (font->max_byte1 == 0) /* 1-byte font */ | |
ee569018 | 1262 | char2b->byte1 = 0, char2b->byte2 = ccl->reg[1]; |
06a2c219 GM |
1263 | else |
1264 | char2b->byte1 = ccl->reg[1], char2b->byte2 = ccl->reg[2]; | |
1265 | } | |
1266 | else if (font_info->encoding[charset]) | |
1267 | { | |
1268 | /* Fixed encoding scheme. See fontset.h for the meaning of the | |
1269 | encoding numbers. */ | |
1270 | int enc = font_info->encoding[charset]; | |
1271 | ||
1272 | if ((enc == 1 || enc == 2) | |
1273 | && CHARSET_DIMENSION (charset) == 2) | |
1274 | char2b->byte1 |= 0x80; | |
1275 | ||
1276 | if (enc == 1 || enc == 3) | |
1277 | char2b->byte2 |= 0x80; | |
1278 | } | |
1279 | } | |
1280 | ||
1281 | ||
1282 | /* Get face and two-byte form of character C in face FACE_ID on frame | |
1283 | F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero | |
1284 | means we want to display multibyte text. Value is a pointer to a | |
1285 | realized face that is ready for display. */ | |
1286 | ||
1287 | static INLINE struct face * | |
1288 | x_get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p) | |
1289 | struct frame *f; | |
1290 | int c, face_id; | |
1291 | XChar2b *char2b; | |
1292 | int multibyte_p; | |
1293 | { | |
1294 | struct face *face = FACE_FROM_ID (f, face_id); | |
1295 | ||
1296 | if (!multibyte_p) | |
1297 | { | |
1298 | /* Unibyte case. We don't have to encode, but we have to make | |
1299 | sure to use a face suitable for unibyte. */ | |
1300 | char2b->byte1 = 0; | |
1301 | char2b->byte2 = c; | |
ee569018 KH |
1302 | face_id = FACE_FOR_CHAR (f, face, c); |
1303 | face = FACE_FROM_ID (f, face_id); | |
06a2c219 GM |
1304 | } |
1305 | else if (c < 128 && face_id < BASIC_FACE_ID_SENTINEL) | |
1306 | { | |
1307 | /* Case of ASCII in a face known to fit ASCII. */ | |
1308 | char2b->byte1 = 0; | |
1309 | char2b->byte2 = c; | |
1310 | } | |
1311 | else | |
1312 | { | |
1313 | int c1, c2, charset; | |
1314 | ||
1315 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1316 | really a one-byte character so that byte1 is zero. */ | |
1317 | SPLIT_CHAR (c, charset, c1, c2); | |
1318 | if (c2 > 0) | |
1319 | char2b->byte1 = c1, char2b->byte2 = c2; | |
1320 | else | |
1321 | char2b->byte1 = 0, char2b->byte2 = c1; | |
1322 | ||
06a2c219 | 1323 | /* Maybe encode the character in *CHAR2B. */ |
ee569018 | 1324 | if (face->font != NULL) |
06a2c219 GM |
1325 | { |
1326 | struct font_info *font_info | |
1327 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1328 | if (font_info) | |
ee569018 | 1329 | x_encode_char (c, char2b, font_info); |
06a2c219 GM |
1330 | } |
1331 | } | |
1332 | ||
1333 | /* Make sure X resources of the face are allocated. */ | |
1334 | xassert (face != NULL); | |
1335 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1336 | ||
1337 | return face; | |
1338 | } | |
1339 | ||
1340 | ||
1341 | /* Get face and two-byte form of character glyph GLYPH on frame F. | |
43d120d8 | 1342 | The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is |
06a2c219 GM |
1343 | a pointer to a realized face that is ready for display. */ |
1344 | ||
1345 | static INLINE struct face * | |
ee569018 | 1346 | x_get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p) |
06a2c219 GM |
1347 | struct frame *f; |
1348 | struct glyph *glyph; | |
1349 | XChar2b *char2b; | |
ee569018 | 1350 | int *two_byte_p; |
06a2c219 GM |
1351 | { |
1352 | struct face *face; | |
1353 | ||
1354 | xassert (glyph->type == CHAR_GLYPH); | |
43d120d8 | 1355 | face = FACE_FROM_ID (f, glyph->face_id); |
06a2c219 | 1356 | |
ee569018 KH |
1357 | if (two_byte_p) |
1358 | *two_byte_p = 0; | |
1359 | ||
06a2c219 GM |
1360 | if (!glyph->multibyte_p) |
1361 | { | |
1362 | /* Unibyte case. We don't have to encode, but we have to make | |
1363 | sure to use a face suitable for unibyte. */ | |
1364 | char2b->byte1 = 0; | |
43d120d8 | 1365 | char2b->byte2 = glyph->u.ch; |
06a2c219 | 1366 | } |
43d120d8 KH |
1367 | else if (glyph->u.ch < 128 |
1368 | && glyph->face_id < BASIC_FACE_ID_SENTINEL) | |
06a2c219 GM |
1369 | { |
1370 | /* Case of ASCII in a face known to fit ASCII. */ | |
1371 | char2b->byte1 = 0; | |
43d120d8 | 1372 | char2b->byte2 = glyph->u.ch; |
06a2c219 GM |
1373 | } |
1374 | else | |
1375 | { | |
1376 | int c1, c2, charset; | |
1377 | ||
1378 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1379 | really a one-byte character so that byte1 is zero. */ | |
43d120d8 | 1380 | SPLIT_CHAR (glyph->u.ch, charset, c1, c2); |
06a2c219 GM |
1381 | if (c2 > 0) |
1382 | char2b->byte1 = c1, char2b->byte2 = c2; | |
1383 | else | |
1384 | char2b->byte1 = 0, char2b->byte2 = c1; | |
1385 | ||
1386 | /* Maybe encode the character in *CHAR2B. */ | |
1387 | if (charset != CHARSET_ASCII) | |
1388 | { | |
1389 | struct font_info *font_info | |
1390 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1391 | if (font_info) | |
1392 | { | |
43d120d8 | 1393 | x_encode_char (glyph->u.ch, char2b, font_info); |
ee569018 KH |
1394 | if (two_byte_p) |
1395 | *two_byte_p | |
1396 | = ((XFontStruct *) (font_info->font))->max_byte1 > 0; | |
06a2c219 GM |
1397 | } |
1398 | } | |
1399 | } | |
1400 | ||
1401 | /* Make sure X resources of the face are allocated. */ | |
1402 | xassert (face != NULL); | |
1403 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1404 | return face; | |
1405 | } | |
1406 | ||
1407 | ||
1408 | /* Store one glyph for IT->char_to_display in IT->glyph_row. | |
1409 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1410 | ||
1411 | static INLINE void | |
1412 | x_append_glyph (it) | |
1413 | struct it *it; | |
1414 | { | |
1415 | struct glyph *glyph; | |
1416 | enum glyph_row_area area = it->area; | |
1417 | ||
1418 | xassert (it->glyph_row); | |
1419 | xassert (it->char_to_display != '\n' && it->char_to_display != '\t'); | |
1420 | ||
1421 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1422 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1423 | { | |
06a2c219 GM |
1424 | glyph->charpos = CHARPOS (it->position); |
1425 | glyph->object = it->object; | |
88d75730 | 1426 | glyph->pixel_width = it->pixel_width; |
06a2c219 | 1427 | glyph->voffset = it->voffset; |
88d75730 | 1428 | glyph->type = CHAR_GLYPH; |
06a2c219 | 1429 | glyph->multibyte_p = it->multibyte_p; |
88d75730 GM |
1430 | glyph->left_box_line_p = it->start_of_box_run_p; |
1431 | glyph->right_box_line_p = it->end_of_box_run_p; | |
66ac4b0e GM |
1432 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1433 | || it->phys_descent > it->descent); | |
88d75730 | 1434 | glyph->padding_p = 0; |
ee569018 | 1435 | glyph->glyph_not_available_p = it->glyph_not_available_p; |
88d75730 GM |
1436 | glyph->face_id = it->face_id; |
1437 | glyph->u.ch = it->char_to_display; | |
06a2c219 GM |
1438 | ++it->glyph_row->used[area]; |
1439 | } | |
1440 | } | |
1441 | ||
b4192550 KH |
1442 | /* Store one glyph for the composition IT->cmp_id in IT->glyph_row. |
1443 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1444 | ||
1445 | static INLINE void | |
1446 | x_append_composite_glyph (it) | |
1447 | struct it *it; | |
1448 | { | |
1449 | struct glyph *glyph; | |
1450 | enum glyph_row_area area = it->area; | |
1451 | ||
1452 | xassert (it->glyph_row); | |
1453 | ||
1454 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1455 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1456 | { | |
b4192550 KH |
1457 | glyph->charpos = CHARPOS (it->position); |
1458 | glyph->object = it->object; | |
88d75730 | 1459 | glyph->pixel_width = it->pixel_width; |
b4192550 | 1460 | glyph->voffset = it->voffset; |
88d75730 | 1461 | glyph->type = COMPOSITE_GLYPH; |
b4192550 | 1462 | glyph->multibyte_p = it->multibyte_p; |
88d75730 GM |
1463 | glyph->left_box_line_p = it->start_of_box_run_p; |
1464 | glyph->right_box_line_p = it->end_of_box_run_p; | |
b4192550 KH |
1465 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1466 | || it->phys_descent > it->descent); | |
88d75730 GM |
1467 | glyph->padding_p = 0; |
1468 | glyph->glyph_not_available_p = 0; | |
1469 | glyph->face_id = it->face_id; | |
1470 | glyph->u.cmp_id = it->cmp_id; | |
b4192550 KH |
1471 | ++it->glyph_row->used[area]; |
1472 | } | |
1473 | } | |
1474 | ||
06a2c219 GM |
1475 | |
1476 | /* Change IT->ascent and IT->height according to the setting of | |
1477 | IT->voffset. */ | |
1478 | ||
1479 | static INLINE void | |
1480 | take_vertical_position_into_account (it) | |
1481 | struct it *it; | |
1482 | { | |
1483 | if (it->voffset) | |
1484 | { | |
1485 | if (it->voffset < 0) | |
1486 | /* Increase the ascent so that we can display the text higher | |
1487 | in the line. */ | |
1488 | it->ascent += abs (it->voffset); | |
1489 | else | |
1490 | /* Increase the descent so that we can display the text lower | |
1491 | in the line. */ | |
1492 | it->descent += it->voffset; | |
1493 | } | |
1494 | } | |
1495 | ||
1496 | ||
1497 | /* Produce glyphs/get display metrics for the image IT is loaded with. | |
1498 | See the description of struct display_iterator in dispextern.h for | |
1499 | an overview of struct display_iterator. */ | |
1500 | ||
1501 | static void | |
1502 | x_produce_image_glyph (it) | |
1503 | struct it *it; | |
1504 | { | |
1505 | struct image *img; | |
1506 | struct face *face; | |
1507 | ||
1508 | xassert (it->what == IT_IMAGE); | |
1509 | ||
1510 | face = FACE_FROM_ID (it->f, it->face_id); | |
1511 | img = IMAGE_FROM_ID (it->f, it->image_id); | |
1512 | xassert (img); | |
1513 | ||
1514 | /* Make sure X resources of the face and image are loaded. */ | |
1515 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1516 | prepare_image_for_display (it->f, img); | |
1517 | ||
95af8492 | 1518 | it->ascent = it->phys_ascent = image_ascent (img, face); |
66ac4b0e | 1519 | it->descent = it->phys_descent = img->height + 2 * img->margin - it->ascent; |
06a2c219 GM |
1520 | it->pixel_width = img->width + 2 * img->margin; |
1521 | ||
1522 | it->nglyphs = 1; | |
1523 | ||
1524 | if (face->box != FACE_NO_BOX) | |
1525 | { | |
1526 | it->ascent += face->box_line_width; | |
1527 | it->descent += face->box_line_width; | |
1528 | ||
1529 | if (it->start_of_box_run_p) | |
1530 | it->pixel_width += face->box_line_width; | |
1531 | if (it->end_of_box_run_p) | |
1532 | it->pixel_width += face->box_line_width; | |
1533 | } | |
1534 | ||
1535 | take_vertical_position_into_account (it); | |
1536 | ||
1537 | if (it->glyph_row) | |
1538 | { | |
1539 | struct glyph *glyph; | |
1540 | enum glyph_row_area area = it->area; | |
1541 | ||
1542 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1543 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1544 | { | |
06a2c219 GM |
1545 | glyph->charpos = CHARPOS (it->position); |
1546 | glyph->object = it->object; | |
88d75730 | 1547 | glyph->pixel_width = it->pixel_width; |
06a2c219 | 1548 | glyph->voffset = it->voffset; |
88d75730 | 1549 | glyph->type = IMAGE_GLYPH; |
06a2c219 | 1550 | glyph->multibyte_p = it->multibyte_p; |
88d75730 GM |
1551 | glyph->left_box_line_p = it->start_of_box_run_p; |
1552 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1553 | glyph->overlaps_vertically_p = 0; | |
1554 | glyph->padding_p = 0; | |
1555 | glyph->glyph_not_available_p = 0; | |
1556 | glyph->face_id = it->face_id; | |
1557 | glyph->u.img_id = img->id; | |
06a2c219 GM |
1558 | ++it->glyph_row->used[area]; |
1559 | } | |
1560 | } | |
1561 | } | |
1562 | ||
1563 | ||
1564 | /* Append a stretch glyph to IT->glyph_row. OBJECT is the source | |
1565 | of the glyph, WIDTH and HEIGHT are the width and height of the | |
1566 | stretch. ASCENT is the percentage/100 of HEIGHT to use for the | |
1567 | ascent of the glyph (0 <= ASCENT <= 1). */ | |
1568 | ||
1569 | static void | |
1570 | x_append_stretch_glyph (it, object, width, height, ascent) | |
1571 | struct it *it; | |
1572 | Lisp_Object object; | |
1573 | int width, height; | |
1574 | double ascent; | |
1575 | { | |
1576 | struct glyph *glyph; | |
1577 | enum glyph_row_area area = it->area; | |
1578 | ||
1579 | xassert (ascent >= 0 && ascent <= 1); | |
1580 | ||
1581 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1582 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1583 | { | |
06a2c219 GM |
1584 | glyph->charpos = CHARPOS (it->position); |
1585 | glyph->object = object; | |
88d75730 | 1586 | glyph->pixel_width = width; |
06a2c219 | 1587 | glyph->voffset = it->voffset; |
88d75730 | 1588 | glyph->type = STRETCH_GLYPH; |
06a2c219 | 1589 | glyph->multibyte_p = it->multibyte_p; |
88d75730 GM |
1590 | glyph->left_box_line_p = it->start_of_box_run_p; |
1591 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1592 | glyph->overlaps_vertically_p = 0; | |
1593 | glyph->padding_p = 0; | |
1594 | glyph->glyph_not_available_p = 0; | |
1595 | glyph->face_id = it->face_id; | |
1596 | glyph->u.stretch.ascent = height * ascent; | |
1597 | glyph->u.stretch.height = height; | |
06a2c219 GM |
1598 | ++it->glyph_row->used[area]; |
1599 | } | |
1600 | } | |
1601 | ||
1602 | ||
1603 | /* Produce a stretch glyph for iterator IT. IT->object is the value | |
1604 | of the glyph property displayed. The value must be a list | |
1605 | `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs | |
1606 | being recognized: | |
1607 | ||
1608 | 1. `:width WIDTH' specifies that the space should be WIDTH * | |
1609 | canonical char width wide. WIDTH may be an integer or floating | |
1610 | point number. | |
1611 | ||
1612 | 2. `:relative-width FACTOR' specifies that the width of the stretch | |
1613 | should be computed from the width of the first character having the | |
1614 | `glyph' property, and should be FACTOR times that width. | |
1615 | ||
1616 | 3. `:align-to HPOS' specifies that the space should be wide enough | |
1617 | to reach HPOS, a value in canonical character units. | |
1618 | ||
1619 | Exactly one of the above pairs must be present. | |
1620 | ||
1621 | 4. `:height HEIGHT' specifies that the height of the stretch produced | |
1622 | should be HEIGHT, measured in canonical character units. | |
1623 | ||
1624 | 5. `:relative-height FACTOR' specifies that the height of the the | |
1625 | stretch should be FACTOR times the height of the characters having | |
1626 | the glyph property. | |
1627 | ||
1628 | Either none or exactly one of 4 or 5 must be present. | |
1629 | ||
1630 | 6. `:ascent ASCENT' specifies that ASCENT percent of the height | |
1631 | of the stretch should be used for the ascent of the stretch. | |
1632 | ASCENT must be in the range 0 <= ASCENT <= 100. */ | |
1633 | ||
1634 | #define NUMVAL(X) \ | |
1635 | ((INTEGERP (X) || FLOATP (X)) \ | |
1636 | ? XFLOATINT (X) \ | |
1637 | : - 1) | |
1638 | ||
1639 | ||
1640 | static void | |
1641 | x_produce_stretch_glyph (it) | |
1642 | struct it *it; | |
1643 | { | |
1644 | /* (space :width WIDTH :height HEIGHT. */ | |
3e71d8f2 GM |
1645 | #if GLYPH_DEBUG |
1646 | extern Lisp_Object Qspace; | |
1647 | #endif | |
1648 | extern Lisp_Object QCwidth, QCheight, QCascent; | |
06a2c219 GM |
1649 | extern Lisp_Object QCrelative_width, QCrelative_height; |
1650 | extern Lisp_Object QCalign_to; | |
1651 | Lisp_Object prop, plist; | |
1652 | double width = 0, height = 0, ascent = 0; | |
1653 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
1654 | XFontStruct *font = face->font ? face->font : FRAME_FONT (it->f); | |
1655 | ||
1656 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1657 | ||
1658 | /* List should start with `space'. */ | |
1659 | xassert (CONSP (it->object) && EQ (XCAR (it->object), Qspace)); | |
1660 | plist = XCDR (it->object); | |
1661 | ||
1662 | /* Compute the width of the stretch. */ | |
1663 | if (prop = Fplist_get (plist, QCwidth), | |
1664 | NUMVAL (prop) > 0) | |
1665 | /* Absolute width `:width WIDTH' specified and valid. */ | |
1666 | width = NUMVAL (prop) * CANON_X_UNIT (it->f); | |
1667 | else if (prop = Fplist_get (plist, QCrelative_width), | |
1668 | NUMVAL (prop) > 0) | |
1669 | { | |
1670 | /* Relative width `:relative-width FACTOR' specified and valid. | |
1671 | Compute the width of the characters having the `glyph' | |
1672 | property. */ | |
1673 | struct it it2; | |
1674 | unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); | |
1675 | ||
1676 | it2 = *it; | |
1677 | if (it->multibyte_p) | |
1678 | { | |
1679 | int maxlen = ((IT_BYTEPOS (*it) >= GPT ? ZV : GPT) | |
1680 | - IT_BYTEPOS (*it)); | |
1681 | it2.c = STRING_CHAR_AND_LENGTH (p, maxlen, it2.len); | |
1682 | } | |
1683 | else | |
1684 | it2.c = *p, it2.len = 1; | |
1685 | ||
1686 | it2.glyph_row = NULL; | |
1687 | it2.what = IT_CHARACTER; | |
1688 | x_produce_glyphs (&it2); | |
1689 | width = NUMVAL (prop) * it2.pixel_width; | |
1690 | } | |
1691 | else if (prop = Fplist_get (plist, QCalign_to), | |
1692 | NUMVAL (prop) > 0) | |
1693 | width = NUMVAL (prop) * CANON_X_UNIT (it->f) - it->current_x; | |
1694 | else | |
1695 | /* Nothing specified -> width defaults to canonical char width. */ | |
1696 | width = CANON_X_UNIT (it->f); | |
1697 | ||
1698 | /* Compute height. */ | |
1699 | if (prop = Fplist_get (plist, QCheight), | |
1700 | NUMVAL (prop) > 0) | |
1701 | height = NUMVAL (prop) * CANON_Y_UNIT (it->f); | |
1702 | else if (prop = Fplist_get (plist, QCrelative_height), | |
1703 | NUMVAL (prop) > 0) | |
1704 | height = FONT_HEIGHT (font) * NUMVAL (prop); | |
1705 | else | |
1706 | height = FONT_HEIGHT (font); | |
1707 | ||
1708 | /* Compute percentage of height used for ascent. If | |
1709 | `:ascent ASCENT' is present and valid, use that. Otherwise, | |
1710 | derive the ascent from the font in use. */ | |
1711 | if (prop = Fplist_get (plist, QCascent), | |
1712 | NUMVAL (prop) > 0 && NUMVAL (prop) <= 100) | |
1713 | ascent = NUMVAL (prop) / 100.0; | |
1714 | else | |
1715 | ascent = (double) font->ascent / FONT_HEIGHT (font); | |
1716 | ||
1717 | if (width <= 0) | |
1718 | width = 1; | |
1719 | if (height <= 0) | |
1720 | height = 1; | |
1721 | ||
1722 | if (it->glyph_row) | |
1723 | { | |
1724 | Lisp_Object object = it->stack[it->sp - 1].string; | |
1725 | if (!STRINGP (object)) | |
1726 | object = it->w->buffer; | |
1727 | x_append_stretch_glyph (it, object, width, height, ascent); | |
1728 | } | |
1729 | ||
1730 | it->pixel_width = width; | |
66ac4b0e GM |
1731 | it->ascent = it->phys_ascent = height * ascent; |
1732 | it->descent = it->phys_descent = height - it->ascent; | |
06a2c219 GM |
1733 | it->nglyphs = 1; |
1734 | ||
1735 | if (face->box != FACE_NO_BOX) | |
1736 | { | |
1737 | it->ascent += face->box_line_width; | |
1738 | it->descent += face->box_line_width; | |
1739 | ||
1740 | if (it->start_of_box_run_p) | |
1741 | it->pixel_width += face->box_line_width; | |
1742 | if (it->end_of_box_run_p) | |
1743 | it->pixel_width += face->box_line_width; | |
1744 | } | |
1745 | ||
1746 | take_vertical_position_into_account (it); | |
1747 | } | |
1748 | ||
b4192550 KH |
1749 | /* Return proper value to be used as baseline offset of font that has |
1750 | ASCENT and DESCENT to draw characters by the font at the vertical | |
1751 | center of the line of frame F. | |
1752 | ||
1753 | Here, out task is to find the value of BOFF in the following figure; | |
1754 | ||
1755 | -------------------------+-----------+- | |
1756 | -+-+---------+-+ | | | |
1757 | | | | | | | | |
1758 | | | | | F_ASCENT F_HEIGHT | |
1759 | | | | ASCENT | | | |
1760 | HEIGHT | | | | | | |
1761 | | | |-|-+------+-----------|------- baseline | |
1762 | | | | | BOFF | | | |
1763 | | |---------|-+-+ | | | |
1764 | | | | DESCENT | | | |
1765 | -+-+---------+-+ F_DESCENT | | |
1766 | -------------------------+-----------+- | |
1767 | ||
1768 | -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT | |
1769 | BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT | |
1770 | DESCENT = FONT->descent | |
1771 | HEIGHT = FONT_HEIGHT (FONT) | |
1772 | F_DESCENT = (F->output_data.x->font->descent | |
1773 | - F->output_data.x->baseline_offset) | |
1774 | F_HEIGHT = FRAME_LINE_HEIGHT (F) | |
1775 | */ | |
1776 | ||
1777 | #define VCENTER_BASELINE_OFFSET(FONT, F) \ | |
1778 | ((FONT)->descent \ | |
1779 | + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT))) / 2 \ | |
1780 | - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset)) | |
06a2c219 GM |
1781 | |
1782 | /* Produce glyphs/get display metrics for the display element IT is | |
1783 | loaded with. See the description of struct display_iterator in | |
1784 | dispextern.h for an overview of struct display_iterator. */ | |
1785 | ||
1786 | static void | |
1787 | x_produce_glyphs (it) | |
1788 | struct it *it; | |
1789 | { | |
ee569018 KH |
1790 | it->glyph_not_available_p = 0; |
1791 | ||
06a2c219 GM |
1792 | if (it->what == IT_CHARACTER) |
1793 | { | |
1794 | XChar2b char2b; | |
1795 | XFontStruct *font; | |
ee569018 | 1796 | struct face *face = FACE_FROM_ID (it->f, it->face_id); |
06a2c219 | 1797 | XCharStruct *pcm; |
06a2c219 | 1798 | int font_not_found_p; |
b4192550 KH |
1799 | struct font_info *font_info; |
1800 | int boff; /* baseline offset */ | |
a4249304 KH |
1801 | /* We may change it->multibyte_p upon unibyte<->multibyte |
1802 | conversion. So, save the current value now and restore it | |
1803 | later. | |
1804 | ||
1805 | Note: It seems that we don't have to record multibyte_p in | |
1806 | struct glyph because the character code itself tells if or | |
1807 | not the character is multibyte. Thus, in the future, we must | |
1808 | consider eliminating the field `multibyte_p' in the struct | |
1809 | glyph. | |
1810 | */ | |
1811 | int saved_multibyte_p = it->multibyte_p; | |
06a2c219 | 1812 | |
ee569018 KH |
1813 | /* Maybe translate single-byte characters to multibyte, or the |
1814 | other way. */ | |
06a2c219 | 1815 | it->char_to_display = it->c; |
ee569018 | 1816 | if (!ASCII_BYTE_P (it->c)) |
06a2c219 | 1817 | { |
ee569018 KH |
1818 | if (unibyte_display_via_language_environment |
1819 | && SINGLE_BYTE_CHAR_P (it->c) | |
1820 | && (it->c >= 0240 | |
1821 | || !NILP (Vnonascii_translation_table))) | |
1822 | { | |
1823 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
a4249304 | 1824 | it->multibyte_p = 1; |
ee569018 KH |
1825 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1826 | face = FACE_FROM_ID (it->f, it->face_id); | |
1827 | } | |
1828 | else if (!SINGLE_BYTE_CHAR_P (it->c) | |
1829 | && !it->multibyte_p) | |
1830 | { | |
1831 | it->char_to_display = multibyte_char_to_unibyte (it->c, Qnil); | |
a4249304 | 1832 | it->multibyte_p = 0; |
ee569018 KH |
1833 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1834 | face = FACE_FROM_ID (it->f, it->face_id); | |
1835 | } | |
06a2c219 GM |
1836 | } |
1837 | ||
ee569018 KH |
1838 | /* Get font to use. Encode IT->char_to_display. */ |
1839 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
1840 | it->face_id, &char2b, | |
1841 | it->multibyte_p); | |
06a2c219 GM |
1842 | font = face->font; |
1843 | ||
1844 | /* When no suitable font found, use the default font. */ | |
1845 | font_not_found_p = font == NULL; | |
1846 | if (font_not_found_p) | |
b4192550 KH |
1847 | { |
1848 | font = FRAME_FONT (it->f); | |
1849 | boff = it->f->output_data.x->baseline_offset; | |
1850 | font_info = NULL; | |
1851 | } | |
1852 | else | |
1853 | { | |
1854 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
1855 | boff = font_info->baseline_offset; | |
1856 | if (font_info->vertical_centering) | |
1857 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
1858 | } | |
06a2c219 GM |
1859 | |
1860 | if (it->char_to_display >= ' ' | |
1861 | && (!it->multibyte_p || it->char_to_display < 128)) | |
1862 | { | |
1863 | /* Either unibyte or ASCII. */ | |
1864 | int stretched_p; | |
1865 | ||
1866 | it->nglyphs = 1; | |
06a2c219 GM |
1867 | |
1868 | pcm = x_per_char_metric (font, &char2b); | |
b4192550 KH |
1869 | it->ascent = font->ascent + boff; |
1870 | it->descent = font->descent - boff; | |
474848ac GM |
1871 | |
1872 | if (pcm) | |
1873 | { | |
1874 | it->phys_ascent = pcm->ascent + boff; | |
1875 | it->phys_descent = pcm->descent - boff; | |
1876 | it->pixel_width = pcm->width; | |
1877 | } | |
1878 | else | |
1879 | { | |
1880 | it->glyph_not_available_p = 1; | |
1881 | it->phys_ascent = font->ascent + boff; | |
1882 | it->phys_descent = font->descent - boff; | |
1883 | it->pixel_width = FONT_WIDTH (font); | |
1884 | } | |
06a2c219 GM |
1885 | |
1886 | /* If this is a space inside a region of text with | |
1887 | `space-width' property, change its width. */ | |
1888 | stretched_p = it->char_to_display == ' ' && !NILP (it->space_width); | |
1889 | if (stretched_p) | |
1890 | it->pixel_width *= XFLOATINT (it->space_width); | |
1891 | ||
1892 | /* If face has a box, add the box thickness to the character | |
1893 | height. If character has a box line to the left and/or | |
1894 | right, add the box line width to the character's width. */ | |
1895 | if (face->box != FACE_NO_BOX) | |
1896 | { | |
1897 | int thick = face->box_line_width; | |
1898 | ||
1899 | it->ascent += thick; | |
1900 | it->descent += thick; | |
1901 | ||
1902 | if (it->start_of_box_run_p) | |
1903 | it->pixel_width += thick; | |
1904 | if (it->end_of_box_run_p) | |
1905 | it->pixel_width += thick; | |
1906 | } | |
1907 | ||
1908 | /* If face has an overline, add the height of the overline | |
1909 | (1 pixel) and a 1 pixel margin to the character height. */ | |
1910 | if (face->overline_p) | |
1911 | it->ascent += 2; | |
1912 | ||
1913 | take_vertical_position_into_account (it); | |
1914 | ||
1915 | /* If we have to actually produce glyphs, do it. */ | |
1916 | if (it->glyph_row) | |
1917 | { | |
1918 | if (stretched_p) | |
1919 | { | |
1920 | /* Translate a space with a `space-width' property | |
1921 | into a stretch glyph. */ | |
1922 | double ascent = (double) font->ascent / FONT_HEIGHT (font); | |
1923 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
1924 | it->ascent + it->descent, ascent); | |
1925 | } | |
1926 | else | |
1927 | x_append_glyph (it); | |
1928 | ||
1929 | /* If characters with lbearing or rbearing are displayed | |
1930 | in this line, record that fact in a flag of the | |
1931 | glyph row. This is used to optimize X output code. */ | |
1c7e22fd | 1932 | if (pcm && (pcm->lbearing < 0 || pcm->rbearing > pcm->width)) |
06a2c219 GM |
1933 | it->glyph_row->contains_overlapping_glyphs_p = 1; |
1934 | } | |
1935 | } | |
1936 | else if (it->char_to_display == '\n') | |
1937 | { | |
1938 | /* A newline has no width but we need the height of the line. */ | |
1939 | it->pixel_width = 0; | |
1940 | it->nglyphs = 0; | |
b4192550 KH |
1941 | it->ascent = it->phys_ascent = font->ascent + boff; |
1942 | it->descent = it->phys_descent = font->descent - boff; | |
06a2c219 GM |
1943 | |
1944 | if (face->box != FACE_NO_BOX) | |
1945 | { | |
1946 | int thick = face->box_line_width; | |
1947 | it->ascent += thick; | |
1948 | it->descent += thick; | |
1949 | } | |
1950 | } | |
1951 | else if (it->char_to_display == '\t') | |
1952 | { | |
1953 | int tab_width = it->tab_width * CANON_X_UNIT (it->f); | |
d365f5bb | 1954 | int x = it->current_x + it->continuation_lines_width; |
06a2c219 | 1955 | int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; |
2a32b5ea GM |
1956 | |
1957 | /* If the distance from the current position to the next tab | |
1958 | stop is less than a canonical character width, use the | |
1959 | tab stop after that. */ | |
1960 | if (next_tab_x - x < CANON_X_UNIT (it->f)) | |
1961 | next_tab_x += tab_width; | |
06a2c219 GM |
1962 | |
1963 | it->pixel_width = next_tab_x - x; | |
1964 | it->nglyphs = 1; | |
b4192550 KH |
1965 | it->ascent = it->phys_ascent = font->ascent + boff; |
1966 | it->descent = it->phys_descent = font->descent - boff; | |
06a2c219 GM |
1967 | |
1968 | if (it->glyph_row) | |
1969 | { | |
1970 | double ascent = (double) it->ascent / (it->ascent + it->descent); | |
1971 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
1972 | it->ascent + it->descent, ascent); | |
1973 | } | |
1974 | } | |
1975 | else | |
1976 | { | |
1977 | /* A multi-byte character. Assume that the display width of the | |
1978 | character is the width of the character multiplied by the | |
b4192550 | 1979 | width of the font. */ |
06a2c219 | 1980 | |
b4192550 KH |
1981 | /* If we found a font, this font should give us the right |
1982 | metrics. If we didn't find a font, use the frame's | |
1983 | default font and calculate the width of the character | |
1984 | from the charset width; this is what old redisplay code | |
1985 | did. */ | |
1986 | pcm = x_per_char_metric (font, &char2b); | |
ee569018 KH |
1987 | if (font_not_found_p || !pcm) |
1988 | { | |
1989 | int charset = CHAR_CHARSET (it->char_to_display); | |
1990 | ||
1991 | it->glyph_not_available_p = 1; | |
1992 | it->pixel_width = (FONT_WIDTH (FRAME_FONT (it->f)) | |
1993 | * CHARSET_WIDTH (charset)); | |
1994 | it->phys_ascent = font->ascent + boff; | |
1995 | it->phys_descent = font->descent - boff; | |
1996 | } | |
1997 | else | |
1998 | { | |
1999 | it->pixel_width = pcm->width; | |
2000 | it->phys_ascent = pcm->ascent + boff; | |
2001 | it->phys_descent = pcm->descent - boff; | |
2002 | if (it->glyph_row | |
2003 | && (pcm->lbearing < 0 | |
2004 | || pcm->rbearing > pcm->width)) | |
2005 | it->glyph_row->contains_overlapping_glyphs_p = 1; | |
2006 | } | |
b4192550 KH |
2007 | it->nglyphs = 1; |
2008 | it->ascent = font->ascent + boff; | |
2009 | it->descent = font->descent - boff; | |
06a2c219 GM |
2010 | if (face->box != FACE_NO_BOX) |
2011 | { | |
2012 | int thick = face->box_line_width; | |
2013 | it->ascent += thick; | |
2014 | it->descent += thick; | |
2015 | ||
2016 | if (it->start_of_box_run_p) | |
2017 | it->pixel_width += thick; | |
2018 | if (it->end_of_box_run_p) | |
2019 | it->pixel_width += thick; | |
2020 | } | |
2021 | ||
2022 | /* If face has an overline, add the height of the overline | |
2023 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2024 | if (face->overline_p) | |
2025 | it->ascent += 2; | |
2026 | ||
2027 | take_vertical_position_into_account (it); | |
2028 | ||
2029 | if (it->glyph_row) | |
2030 | x_append_glyph (it); | |
2031 | } | |
a4249304 | 2032 | it->multibyte_p = saved_multibyte_p; |
06a2c219 | 2033 | } |
b4192550 KH |
2034 | else if (it->what == IT_COMPOSITION) |
2035 | { | |
2036 | /* Note: A composition is represented as one glyph in the | |
2037 | glyph matrix. There are no padding glyphs. */ | |
2038 | XChar2b char2b; | |
2039 | XFontStruct *font; | |
ee569018 | 2040 | struct face *face = FACE_FROM_ID (it->f, it->face_id); |
b4192550 KH |
2041 | XCharStruct *pcm; |
2042 | int font_not_found_p; | |
2043 | struct font_info *font_info; | |
2044 | int boff; /* baseline offset */ | |
2045 | struct composition *cmp = composition_table[it->cmp_id]; | |
2046 | ||
2047 | /* Maybe translate single-byte characters to multibyte. */ | |
2048 | it->char_to_display = it->c; | |
2049 | if (unibyte_display_via_language_environment | |
2050 | && SINGLE_BYTE_CHAR_P (it->c) | |
2051 | && (it->c >= 0240 | |
2052 | || (it->c >= 0200 | |
2053 | && !NILP (Vnonascii_translation_table)))) | |
2054 | { | |
2055 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
b4192550 KH |
2056 | } |
2057 | ||
2058 | /* Get face and font to use. Encode IT->char_to_display. */ | |
ee569018 KH |
2059 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
2060 | face = FACE_FROM_ID (it->f, it->face_id); | |
2061 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
2062 | it->face_id, &char2b, it->multibyte_p); | |
b4192550 KH |
2063 | font = face->font; |
2064 | ||
2065 | /* When no suitable font found, use the default font. */ | |
2066 | font_not_found_p = font == NULL; | |
2067 | if (font_not_found_p) | |
2068 | { | |
2069 | font = FRAME_FONT (it->f); | |
2070 | boff = it->f->output_data.x->baseline_offset; | |
2071 | font_info = NULL; | |
2072 | } | |
2073 | else | |
2074 | { | |
2075 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2076 | boff = font_info->baseline_offset; | |
2077 | if (font_info->vertical_centering) | |
2078 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2079 | } | |
2080 | ||
2081 | /* There are no padding glyphs, so there is only one glyph to | |
2082 | produce for the composition. Important is that pixel_width, | |
2083 | ascent and descent are the values of what is drawn by | |
2084 | draw_glyphs (i.e. the values of the overall glyphs composed). */ | |
2085 | it->nglyphs = 1; | |
2086 | ||
2087 | /* If we have not yet calculated pixel size data of glyphs of | |
2088 | the composition for the current face font, calculate them | |
2089 | now. Theoretically, we have to check all fonts for the | |
2090 | glyphs, but that requires much time and memory space. So, | |
2091 | here we check only the font of the first glyph. This leads | |
2092 | to incorrect display very rarely, and C-l (recenter) can | |
2093 | correct the display anyway. */ | |
2094 | if (cmp->font != (void *) font) | |
2095 | { | |
2096 | /* Ascent and descent of the font of the first character of | |
2097 | this composition (adjusted by baseline offset). Ascent | |
2098 | and descent of overall glyphs should not be less than | |
2099 | them respectively. */ | |
2100 | int font_ascent = font->ascent + boff; | |
2101 | int font_descent = font->descent - boff; | |
2102 | /* Bounding box of the overall glyphs. */ | |
2103 | int leftmost, rightmost, lowest, highest; | |
329bed06 | 2104 | int i, width, ascent, descent; |
b4192550 KH |
2105 | |
2106 | cmp->font = (void *) font; | |
2107 | ||
2108 | /* Initialize the bounding box. */ | |
2109 | pcm = x_per_char_metric (font, &char2b); | |
329bed06 GM |
2110 | if (pcm) |
2111 | { | |
2112 | width = pcm->width; | |
2113 | ascent = pcm->ascent; | |
2114 | descent = pcm->descent; | |
2115 | } | |
2116 | else | |
2117 | { | |
2118 | width = FONT_WIDTH (font); | |
2119 | ascent = font->ascent; | |
2120 | descent = font->descent; | |
2121 | } | |
2122 | ||
2123 | rightmost = width; | |
2124 | lowest = - descent + boff; | |
2125 | highest = ascent + boff; | |
b4192550 | 2126 | leftmost = 0; |
329bed06 | 2127 | |
b4192550 KH |
2128 | if (font_info |
2129 | && font_info->default_ascent | |
2130 | && CHAR_TABLE_P (Vuse_default_ascent) | |
2131 | && !NILP (Faref (Vuse_default_ascent, | |
2132 | make_number (it->char_to_display)))) | |
2133 | highest = font_info->default_ascent + boff; | |
2134 | ||
2135 | /* Draw the first glyph at the normal position. It may be | |
2136 | shifted to right later if some other glyphs are drawn at | |
2137 | the left. */ | |
2138 | cmp->offsets[0] = 0; | |
2139 | cmp->offsets[1] = boff; | |
2140 | ||
2141 | /* Set cmp->offsets for the remaining glyphs. */ | |
2142 | for (i = 1; i < cmp->glyph_len; i++) | |
2143 | { | |
2144 | int left, right, btm, top; | |
2145 | int ch = COMPOSITION_GLYPH (cmp, i); | |
ee569018 KH |
2146 | int face_id = FACE_FOR_CHAR (it->f, face, ch); |
2147 | ||
2148 | face = FACE_FROM_ID (it->f, face_id); | |
2149 | x_get_char_face_and_encoding (it->f, ch, face->id, &char2b, | |
2150 | it->multibyte_p); | |
b4192550 KH |
2151 | font = face->font; |
2152 | if (font == NULL) | |
2153 | { | |
2154 | font = FRAME_FONT (it->f); | |
2155 | boff = it->f->output_data.x->baseline_offset; | |
2156 | font_info = NULL; | |
2157 | } | |
2158 | else | |
2159 | { | |
2160 | font_info | |
2161 | = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2162 | boff = font_info->baseline_offset; | |
2163 | if (font_info->vertical_centering) | |
2164 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2165 | } | |
2166 | ||
2167 | pcm = x_per_char_metric (font, &char2b); | |
329bed06 GM |
2168 | if (pcm) |
2169 | { | |
2170 | width = pcm->width; | |
2171 | ascent = pcm->ascent; | |
2172 | descent = pcm->descent; | |
2173 | } | |
2174 | else | |
2175 | { | |
2176 | width = FONT_WIDTH (font); | |
2177 | ascent = font->ascent; | |
2178 | descent = font->descent; | |
2179 | } | |
b4192550 KH |
2180 | |
2181 | if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) | |
2182 | { | |
2183 | /* Relative composition with or without | |
2184 | alternate chars. */ | |
329bed06 GM |
2185 | left = (leftmost + rightmost - width) / 2; |
2186 | btm = - descent + boff; | |
b4192550 KH |
2187 | if (font_info && font_info->relative_compose |
2188 | && (! CHAR_TABLE_P (Vignore_relative_composition) | |
2189 | || NILP (Faref (Vignore_relative_composition, | |
2190 | make_number (ch))))) | |
2191 | { | |
2192 | ||
329bed06 | 2193 | if (- descent >= font_info->relative_compose) |
b4192550 KH |
2194 | /* One extra pixel between two glyphs. */ |
2195 | btm = highest + 1; | |
329bed06 | 2196 | else if (ascent <= 0) |
b4192550 | 2197 | /* One extra pixel between two glyphs. */ |
329bed06 | 2198 | btm = lowest - 1 - ascent - descent; |
b4192550 KH |
2199 | } |
2200 | } | |
2201 | else | |
2202 | { | |
2203 | /* A composition rule is specified by an integer | |
2204 | value that encodes global and new reference | |
2205 | points (GREF and NREF). GREF and NREF are | |
2206 | specified by numbers as below: | |
2207 | ||
2208 | 0---1---2 -- ascent | |
2209 | | | | |
2210 | | | | |
2211 | | | | |
2212 | 9--10--11 -- center | |
2213 | | | | |
2214 | ---3---4---5--- baseline | |
2215 | | | | |
2216 | 6---7---8 -- descent | |
2217 | */ | |
2218 | int rule = COMPOSITION_RULE (cmp, i); | |
2219 | int gref, nref, grefx, grefy, nrefx, nrefy; | |
2220 | ||
2221 | COMPOSITION_DECODE_RULE (rule, gref, nref); | |
2222 | grefx = gref % 3, nrefx = nref % 3; | |
2223 | grefy = gref / 3, nrefy = nref / 3; | |
2224 | ||
2225 | left = (leftmost | |
2226 | + grefx * (rightmost - leftmost) / 2 | |
329bed06 | 2227 | - nrefx * width / 2); |
b4192550 KH |
2228 | btm = ((grefy == 0 ? highest |
2229 | : grefy == 1 ? 0 | |
2230 | : grefy == 2 ? lowest | |
2231 | : (highest + lowest) / 2) | |
329bed06 GM |
2232 | - (nrefy == 0 ? ascent + descent |
2233 | : nrefy == 1 ? descent - boff | |
b4192550 | 2234 | : nrefy == 2 ? 0 |
329bed06 | 2235 | : (ascent + descent) / 2)); |
b4192550 KH |
2236 | } |
2237 | ||
2238 | cmp->offsets[i * 2] = left; | |
329bed06 | 2239 | cmp->offsets[i * 2 + 1] = btm + descent; |
b4192550 KH |
2240 | |
2241 | /* Update the bounding box of the overall glyphs. */ | |
329bed06 GM |
2242 | right = left + width; |
2243 | top = btm + descent + ascent; | |
b4192550 KH |
2244 | if (left < leftmost) |
2245 | leftmost = left; | |
2246 | if (right > rightmost) | |
2247 | rightmost = right; | |
2248 | if (top > highest) | |
2249 | highest = top; | |
2250 | if (btm < lowest) | |
2251 | lowest = btm; | |
2252 | } | |
2253 | ||
2254 | /* If there are glyphs whose x-offsets are negative, | |
2255 | shift all glyphs to the right and make all x-offsets | |
2256 | non-negative. */ | |
2257 | if (leftmost < 0) | |
2258 | { | |
2259 | for (i = 0; i < cmp->glyph_len; i++) | |
2260 | cmp->offsets[i * 2] -= leftmost; | |
2261 | rightmost -= leftmost; | |
2262 | } | |
2263 | ||
2264 | cmp->pixel_width = rightmost; | |
2265 | cmp->ascent = highest; | |
2266 | cmp->descent = - lowest; | |
2267 | if (cmp->ascent < font_ascent) | |
2268 | cmp->ascent = font_ascent; | |
2269 | if (cmp->descent < font_descent) | |
2270 | cmp->descent = font_descent; | |
2271 | } | |
2272 | ||
2273 | it->pixel_width = cmp->pixel_width; | |
2274 | it->ascent = it->phys_ascent = cmp->ascent; | |
2275 | it->descent = it->phys_descent = cmp->descent; | |
2276 | ||
2277 | if (face->box != FACE_NO_BOX) | |
2278 | { | |
2279 | int thick = face->box_line_width; | |
2280 | it->ascent += thick; | |
2281 | it->descent += thick; | |
2282 | ||
2283 | if (it->start_of_box_run_p) | |
2284 | it->pixel_width += thick; | |
2285 | if (it->end_of_box_run_p) | |
2286 | it->pixel_width += thick; | |
2287 | } | |
2288 | ||
2289 | /* If face has an overline, add the height of the overline | |
2290 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2291 | if (face->overline_p) | |
2292 | it->ascent += 2; | |
2293 | ||
2294 | take_vertical_position_into_account (it); | |
2295 | ||
2296 | if (it->glyph_row) | |
2297 | x_append_composite_glyph (it); | |
2298 | } | |
06a2c219 GM |
2299 | else if (it->what == IT_IMAGE) |
2300 | x_produce_image_glyph (it); | |
2301 | else if (it->what == IT_STRETCH) | |
2302 | x_produce_stretch_glyph (it); | |
2303 | ||
3017fdd1 GM |
2304 | /* Accumulate dimensions. Note: can't assume that it->descent > 0 |
2305 | because this isn't true for images with `:ascent 100'. */ | |
2306 | xassert (it->ascent >= 0 && it->descent >= 0); | |
06a2c219 GM |
2307 | if (it->area == TEXT_AREA) |
2308 | it->current_x += it->pixel_width; | |
66ac4b0e | 2309 | |
d365f5bb GM |
2310 | it->descent += it->extra_line_spacing; |
2311 | ||
06a2c219 GM |
2312 | it->max_ascent = max (it->max_ascent, it->ascent); |
2313 | it->max_descent = max (it->max_descent, it->descent); | |
66ac4b0e GM |
2314 | it->max_phys_ascent = max (it->max_phys_ascent, it->phys_ascent); |
2315 | it->max_phys_descent = max (it->max_phys_descent, it->phys_descent); | |
06a2c219 GM |
2316 | } |
2317 | ||
2318 | ||
2319 | /* Estimate the pixel height of the mode or top line on frame F. | |
2320 | FACE_ID specifies what line's height to estimate. */ | |
2321 | ||
2322 | int | |
2323 | x_estimate_mode_line_height (f, face_id) | |
2324 | struct frame *f; | |
2325 | enum face_id face_id; | |
2326 | { | |
2327 | int height = 1; | |
2328 | ||
2329 | /* This function is called so early when Emacs starts that the face | |
2330 | cache and mode line face are not yet initialized. */ | |
2331 | if (FRAME_FACE_CACHE (f)) | |
2332 | { | |
2333 | struct face *face = FACE_FROM_ID (f, face_id); | |
2334 | if (face) | |
2335 | height = FONT_HEIGHT (face->font) + 2 * face->box_line_width; | |
2336 | } | |
2337 | ||
2338 | return height; | |
2339 | } | |
2340 | ||
2341 | \f | |
2342 | /*********************************************************************** | |
2343 | Glyph display | |
2344 | ***********************************************************************/ | |
2345 | ||
2346 | /* A sequence of glyphs to be drawn in the same face. | |
2347 | ||
2348 | This data structure is not really completely X specific, so it | |
2349 | could possibly, at least partially, be useful for other systems. It | |
2350 | is currently not part of the external redisplay interface because | |
2351 | it's not clear what other systems will need. */ | |
2352 | ||
2353 | struct glyph_string | |
2354 | { | |
2355 | /* X-origin of the string. */ | |
2356 | int x; | |
2357 | ||
2358 | /* Y-origin and y-position of the base line of this string. */ | |
2359 | int y, ybase; | |
2360 | ||
2361 | /* The width of the string, not including a face extension. */ | |
2362 | int width; | |
2363 | ||
2364 | /* The width of the string, including a face extension. */ | |
2365 | int background_width; | |
2366 | ||
2367 | /* The height of this string. This is the height of the line this | |
2368 | string is drawn in, and can be different from the height of the | |
2369 | font the string is drawn in. */ | |
2370 | int height; | |
2371 | ||
2372 | /* Number of pixels this string overwrites in front of its x-origin. | |
2373 | This number is zero if the string has an lbearing >= 0; it is | |
2374 | -lbearing, if the string has an lbearing < 0. */ | |
2375 | int left_overhang; | |
2376 | ||
2377 | /* Number of pixels this string overwrites past its right-most | |
2378 | nominal x-position, i.e. x + width. Zero if the string's | |
2379 | rbearing is <= its nominal width, rbearing - width otherwise. */ | |
2380 | int right_overhang; | |
2381 | ||
2382 | /* The frame on which the glyph string is drawn. */ | |
2383 | struct frame *f; | |
2384 | ||
2385 | /* The window on which the glyph string is drawn. */ | |
2386 | struct window *w; | |
2387 | ||
2388 | /* X display and window for convenience. */ | |
2389 | Display *display; | |
2390 | Window window; | |
2391 | ||
2392 | /* The glyph row for which this string was built. It determines the | |
2393 | y-origin and height of the string. */ | |
2394 | struct glyph_row *row; | |
2395 | ||
2396 | /* The area within row. */ | |
2397 | enum glyph_row_area area; | |
2398 | ||
2399 | /* Characters to be drawn, and number of characters. */ | |
2400 | XChar2b *char2b; | |
2401 | int nchars; | |
2402 | ||
06a2c219 GM |
2403 | /* A face-override for drawing cursors, mouse face and similar. */ |
2404 | enum draw_glyphs_face hl; | |
2405 | ||
2406 | /* Face in which this string is to be drawn. */ | |
2407 | struct face *face; | |
2408 | ||
2409 | /* Font in which this string is to be drawn. */ | |
2410 | XFontStruct *font; | |
2411 | ||
2412 | /* Font info for this string. */ | |
2413 | struct font_info *font_info; | |
2414 | ||
b4192550 KH |
2415 | /* Non-null means this string describes (part of) a composition. |
2416 | All characters from char2b are drawn composed. */ | |
2417 | struct composition *cmp; | |
06a2c219 GM |
2418 | |
2419 | /* Index of this glyph string's first character in the glyph | |
b4192550 KH |
2420 | definition of CMP. If this is zero, this glyph string describes |
2421 | the first character of a composition. */ | |
06a2c219 GM |
2422 | int gidx; |
2423 | ||
2424 | /* 1 means this glyph strings face has to be drawn to the right end | |
2425 | of the window's drawing area. */ | |
2426 | unsigned extends_to_end_of_line_p : 1; | |
2427 | ||
2428 | /* 1 means the background of this string has been drawn. */ | |
2429 | unsigned background_filled_p : 1; | |
2430 | ||
2431 | /* 1 means glyph string must be drawn with 16-bit functions. */ | |
2432 | unsigned two_byte_p : 1; | |
2433 | ||
2434 | /* 1 means that the original font determined for drawing this glyph | |
2435 | string could not be loaded. The member `font' has been set to | |
2436 | the frame's default font in this case. */ | |
2437 | unsigned font_not_found_p : 1; | |
2438 | ||
2439 | /* 1 means that the face in which this glyph string is drawn has a | |
2440 | stipple pattern. */ | |
2441 | unsigned stippled_p : 1; | |
2442 | ||
66ac4b0e GM |
2443 | /* 1 means only the foreground of this glyph string must be drawn, |
2444 | and we should use the physical height of the line this glyph | |
2445 | string appears in as clip rect. */ | |
2446 | unsigned for_overlaps_p : 1; | |
2447 | ||
06a2c219 GM |
2448 | /* The GC to use for drawing this glyph string. */ |
2449 | GC gc; | |
2450 | ||
2451 | /* A pointer to the first glyph in the string. This glyph | |
2452 | corresponds to char2b[0]. Needed to draw rectangles if | |
2453 | font_not_found_p is 1. */ | |
2454 | struct glyph *first_glyph; | |
2455 | ||
2456 | /* Image, if any. */ | |
2457 | struct image *img; | |
2458 | ||
2459 | struct glyph_string *next, *prev; | |
2460 | }; | |
2461 | ||
2462 | ||
5c187dee | 2463 | #if 0 |
06a2c219 GM |
2464 | |
2465 | static void | |
2466 | x_dump_glyph_string (s) | |
2467 | struct glyph_string *s; | |
2468 | { | |
2469 | fprintf (stderr, "glyph string\n"); | |
2470 | fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n", | |
2471 | s->x, s->y, s->width, s->height); | |
2472 | fprintf (stderr, " ybase = %d\n", s->ybase); | |
2473 | fprintf (stderr, " hl = %d\n", s->hl); | |
2474 | fprintf (stderr, " left overhang = %d, right = %d\n", | |
2475 | s->left_overhang, s->right_overhang); | |
2476 | fprintf (stderr, " nchars = %d\n", s->nchars); | |
2477 | fprintf (stderr, " extends to end of line = %d\n", | |
2478 | s->extends_to_end_of_line_p); | |
2479 | fprintf (stderr, " font height = %d\n", FONT_HEIGHT (s->font)); | |
2480 | fprintf (stderr, " bg width = %d\n", s->background_width); | |
2481 | } | |
2482 | ||
2483 | #endif /* GLYPH_DEBUG */ | |
2484 | ||
2485 | ||
2486 | ||
2487 | static void x_append_glyph_string_lists P_ ((struct glyph_string **, | |
2488 | struct glyph_string **, | |
2489 | struct glyph_string *, | |
2490 | struct glyph_string *)); | |
2491 | static void x_prepend_glyph_string_lists P_ ((struct glyph_string **, | |
2492 | struct glyph_string **, | |
2493 | struct glyph_string *, | |
2494 | struct glyph_string *)); | |
2495 | static void x_append_glyph_string P_ ((struct glyph_string **, | |
2496 | struct glyph_string **, | |
2497 | struct glyph_string *)); | |
2498 | static int x_left_overwritten P_ ((struct glyph_string *)); | |
2499 | static int x_left_overwriting P_ ((struct glyph_string *)); | |
2500 | static int x_right_overwritten P_ ((struct glyph_string *)); | |
2501 | static int x_right_overwriting P_ ((struct glyph_string *)); | |
66ac4b0e GM |
2502 | static int x_fill_glyph_string P_ ((struct glyph_string *, int, int, int, |
2503 | int)); | |
06a2c219 GM |
2504 | static void x_init_glyph_string P_ ((struct glyph_string *, |
2505 | XChar2b *, struct window *, | |
2506 | struct glyph_row *, | |
2507 | enum glyph_row_area, int, | |
2508 | enum draw_glyphs_face)); | |
2509 | static int x_draw_glyphs P_ ((struct window *, int , struct glyph_row *, | |
2510 | enum glyph_row_area, int, int, | |
66ac4b0e | 2511 | enum draw_glyphs_face, int *, int *, int)); |
06a2c219 GM |
2512 | static void x_set_glyph_string_clipping P_ ((struct glyph_string *)); |
2513 | static void x_set_glyph_string_gc P_ ((struct glyph_string *)); | |
2514 | static void x_draw_glyph_string_background P_ ((struct glyph_string *, | |
2515 | int)); | |
2516 | static void x_draw_glyph_string_foreground P_ ((struct glyph_string *)); | |
b4192550 | 2517 | static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *)); |
06a2c219 GM |
2518 | static void x_draw_glyph_string_box P_ ((struct glyph_string *)); |
2519 | static void x_draw_glyph_string P_ ((struct glyph_string *)); | |
2520 | static void x_compute_glyph_string_overhangs P_ ((struct glyph_string *)); | |
2521 | static void x_set_cursor_gc P_ ((struct glyph_string *)); | |
2522 | static void x_set_mode_line_face_gc P_ ((struct glyph_string *)); | |
2523 | static void x_set_mouse_face_gc P_ ((struct glyph_string *)); | |
2524 | static void x_get_glyph_overhangs P_ ((struct glyph *, struct frame *, | |
2525 | int *, int *)); | |
2526 | static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int)); | |
2527 | static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap, | |
68c45bf0 | 2528 | unsigned long *, double, int)); |
06a2c219 | 2529 | static void x_setup_relief_color P_ ((struct frame *, struct relief *, |
68c45bf0 | 2530 | double, int, unsigned long)); |
06a2c219 GM |
2531 | static void x_setup_relief_colors P_ ((struct glyph_string *)); |
2532 | static void x_draw_image_glyph_string P_ ((struct glyph_string *)); | |
2533 | static void x_draw_image_relief P_ ((struct glyph_string *)); | |
2534 | static void x_draw_image_foreground P_ ((struct glyph_string *)); | |
2535 | static void x_draw_image_foreground_1 P_ ((struct glyph_string *, Pixmap)); | |
2536 | static void x_fill_image_glyph_string P_ ((struct glyph_string *)); | |
2537 | static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, | |
2538 | int, int, int)); | |
2539 | static void x_draw_relief_rect P_ ((struct frame *, int, int, int, int, | |
2540 | int, int, int, int, XRectangle *)); | |
2541 | static void x_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, | |
2542 | int, int, int, XRectangle *)); | |
66ac4b0e GM |
2543 | static void x_fix_overlapping_area P_ ((struct window *, struct glyph_row *, |
2544 | enum glyph_row_area)); | |
209f68d9 GM |
2545 | static int x_fill_stretch_glyph_string P_ ((struct glyph_string *, |
2546 | struct glyph_row *, | |
2547 | enum glyph_row_area, int, int)); | |
06a2c219 | 2548 | |
163dcff3 GM |
2549 | #if GLYPH_DEBUG |
2550 | static void x_check_font P_ ((struct frame *, XFontStruct *)); | |
2551 | #endif | |
2552 | ||
06a2c219 | 2553 | |
06a2c219 GM |
2554 | /* Append the list of glyph strings with head H and tail T to the list |
2555 | with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */ | |
2556 | ||
2557 | static INLINE void | |
2558 | x_append_glyph_string_lists (head, tail, h, t) | |
2559 | struct glyph_string **head, **tail; | |
2560 | struct glyph_string *h, *t; | |
2561 | { | |
2562 | if (h) | |
2563 | { | |
2564 | if (*head) | |
2565 | (*tail)->next = h; | |
2566 | else | |
2567 | *head = h; | |
2568 | h->prev = *tail; | |
2569 | *tail = t; | |
2570 | } | |
2571 | } | |
2572 | ||
2573 | ||
2574 | /* Prepend the list of glyph strings with head H and tail T to the | |
2575 | list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the | |
2576 | result. */ | |
2577 | ||
2578 | static INLINE void | |
2579 | x_prepend_glyph_string_lists (head, tail, h, t) | |
2580 | struct glyph_string **head, **tail; | |
2581 | struct glyph_string *h, *t; | |
2582 | { | |
2583 | if (h) | |
2584 | { | |
2585 | if (*head) | |
2586 | (*head)->prev = t; | |
2587 | else | |
2588 | *tail = t; | |
2589 | t->next = *head; | |
2590 | *head = h; | |
2591 | } | |
2592 | } | |
2593 | ||
2594 | ||
2595 | /* Append glyph string S to the list with head *HEAD and tail *TAIL. | |
2596 | Set *HEAD and *TAIL to the resulting list. */ | |
2597 | ||
2598 | static INLINE void | |
2599 | x_append_glyph_string (head, tail, s) | |
2600 | struct glyph_string **head, **tail; | |
2601 | struct glyph_string *s; | |
2602 | { | |
2603 | s->next = s->prev = NULL; | |
2604 | x_append_glyph_string_lists (head, tail, s, s); | |
2605 | } | |
2606 | ||
2607 | ||
2608 | /* Set S->gc to a suitable GC for drawing glyph string S in cursor | |
2609 | face. */ | |
2610 | ||
2611 | static void | |
2612 | x_set_cursor_gc (s) | |
2613 | struct glyph_string *s; | |
2614 | { | |
2615 | if (s->font == FRAME_FONT (s->f) | |
2616 | && s->face->background == FRAME_BACKGROUND_PIXEL (s->f) | |
2617 | && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f) | |
b4192550 | 2618 | && !s->cmp) |
06a2c219 GM |
2619 | s->gc = s->f->output_data.x->cursor_gc; |
2620 | else | |
2621 | { | |
2622 | /* Cursor on non-default face: must merge. */ | |
2623 | XGCValues xgcv; | |
2624 | unsigned long mask; | |
2625 | ||
2626 | xgcv.background = s->f->output_data.x->cursor_pixel; | |
2627 | xgcv.foreground = s->face->background; | |
2628 | ||
2629 | /* If the glyph would be invisible, try a different foreground. */ | |
2630 | if (xgcv.foreground == xgcv.background) | |
2631 | xgcv.foreground = s->face->foreground; | |
2632 | if (xgcv.foreground == xgcv.background) | |
2633 | xgcv.foreground = s->f->output_data.x->cursor_foreground_pixel; | |
2634 | if (xgcv.foreground == xgcv.background) | |
2635 | xgcv.foreground = s->face->foreground; | |
2636 | ||
2637 | /* Make sure the cursor is distinct from text in this face. */ | |
2638 | if (xgcv.background == s->face->background | |
2639 | && xgcv.foreground == s->face->foreground) | |
2640 | { | |
2641 | xgcv.background = s->face->foreground; | |
2642 | xgcv.foreground = s->face->background; | |
2643 | } | |
2644 | ||
2645 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2646 | xgcv.font = s->font->fid; | |
2647 | xgcv.graphics_exposures = False; | |
2648 | mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures; | |
2649 | ||
2650 | if (FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2651 | XChangeGC (s->display, FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2652 | mask, &xgcv); | |
2653 | else | |
2654 | FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2655 | = XCreateGC (s->display, s->window, mask, &xgcv); | |
2656 | ||
2657 | s->gc = FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2658 | } | |
2659 | } | |
2660 | ||
2661 | ||
2662 | /* Set up S->gc of glyph string S for drawing text in mouse face. */ | |
2663 | ||
2664 | static void | |
2665 | x_set_mouse_face_gc (s) | |
2666 | struct glyph_string *s; | |
2667 | { | |
2668 | int face_id; | |
ee569018 | 2669 | struct face *face; |
06a2c219 GM |
2670 | |
2671 | /* What face has to be used for the mouse face? */ | |
2672 | face_id = FRAME_X_DISPLAY_INFO (s->f)->mouse_face_face_id; | |
ee569018 | 2673 | face = FACE_FROM_ID (s->f, face_id); |
033e3e18 GM |
2674 | if (s->first_glyph->type == CHAR_GLYPH) |
2675 | face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch); | |
2676 | else | |
2677 | face_id = FACE_FOR_CHAR (s->f, face, 0); | |
06a2c219 GM |
2678 | s->face = FACE_FROM_ID (s->f, face_id); |
2679 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); | |
2680 | ||
2681 | /* If font in this face is same as S->font, use it. */ | |
2682 | if (s->font == s->face->font) | |
2683 | s->gc = s->face->gc; | |
2684 | else | |
2685 | { | |
2686 | /* Otherwise construct scratch_cursor_gc with values from FACE | |
2687 | but font FONT. */ | |
2688 | XGCValues xgcv; | |
2689 | unsigned long mask; | |
2690 | ||
2691 | xgcv.background = s->face->background; | |
2692 | xgcv.foreground = s->face->foreground; | |
2693 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2694 | xgcv.font = s->font->fid; | |
2695 | xgcv.graphics_exposures = False; | |
2696 | mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures; | |
2697 | ||
2698 | if (FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2699 | XChangeGC (s->display, FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2700 | mask, &xgcv); | |
2701 | else | |
2702 | FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2703 | = XCreateGC (s->display, s->window, mask, &xgcv); | |
2704 | ||
2705 | s->gc = FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2706 | } | |
2707 | ||
2708 | xassert (s->gc != 0); | |
2709 | } | |
2710 | ||
2711 | ||
2712 | /* Set S->gc of glyph string S to a GC suitable for drawing a mode line. | |
2713 | Faces to use in the mode line have already been computed when the | |
2714 | matrix was built, so there isn't much to do, here. */ | |
2715 | ||
2716 | static INLINE void | |
2717 | x_set_mode_line_face_gc (s) | |
2718 | struct glyph_string *s; | |
2719 | { | |
2720 | s->gc = s->face->gc; | |
06a2c219 GM |
2721 | } |
2722 | ||
2723 | ||
2724 | /* Set S->gc of glyph string S for drawing that glyph string. Set | |
2725 | S->stippled_p to a non-zero value if the face of S has a stipple | |
2726 | pattern. */ | |
2727 | ||
2728 | static INLINE void | |
2729 | x_set_glyph_string_gc (s) | |
2730 | struct glyph_string *s; | |
2731 | { | |
209f68d9 GM |
2732 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); |
2733 | ||
06a2c219 GM |
2734 | if (s->hl == DRAW_NORMAL_TEXT) |
2735 | { | |
2736 | s->gc = s->face->gc; | |
2737 | s->stippled_p = s->face->stipple != 0; | |
2738 | } | |
2739 | else if (s->hl == DRAW_INVERSE_VIDEO) | |
2740 | { | |
2741 | x_set_mode_line_face_gc (s); | |
2742 | s->stippled_p = s->face->stipple != 0; | |
2743 | } | |
2744 | else if (s->hl == DRAW_CURSOR) | |
2745 | { | |
2746 | x_set_cursor_gc (s); | |
2747 | s->stippled_p = 0; | |
2748 | } | |
2749 | else if (s->hl == DRAW_MOUSE_FACE) | |
2750 | { | |
2751 | x_set_mouse_face_gc (s); | |
2752 | s->stippled_p = s->face->stipple != 0; | |
2753 | } | |
2754 | else if (s->hl == DRAW_IMAGE_RAISED | |
2755 | || s->hl == DRAW_IMAGE_SUNKEN) | |
2756 | { | |
2757 | s->gc = s->face->gc; | |
2758 | s->stippled_p = s->face->stipple != 0; | |
2759 | } | |
2760 | else | |
2761 | { | |
2762 | s->gc = s->face->gc; | |
2763 | s->stippled_p = s->face->stipple != 0; | |
2764 | } | |
2765 | ||
2766 | /* GC must have been set. */ | |
2767 | xassert (s->gc != 0); | |
2768 | } | |
2769 | ||
2770 | ||
2771 | /* Return in *R the clipping rectangle for glyph string S. */ | |
2772 | ||
2773 | static void | |
2774 | x_get_glyph_string_clip_rect (s, r) | |
2775 | struct glyph_string *s; | |
2776 | XRectangle *r; | |
2777 | { | |
2778 | if (s->row->full_width_p) | |
2779 | { | |
2780 | /* Draw full-width. X coordinates are relative to S->w->left. */ | |
1da3fd71 GM |
2781 | int canon_x = CANON_X_UNIT (s->f); |
2782 | ||
2783 | r->x = WINDOW_LEFT_MARGIN (s->w) * canon_x; | |
2784 | r->width = XFASTINT (s->w->width) * canon_x; | |
06a2c219 GM |
2785 | |
2786 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (s->f)) | |
2787 | { | |
1da3fd71 | 2788 | int width = FRAME_SCROLL_BAR_WIDTH (s->f) * canon_x; |
06a2c219 GM |
2789 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s->f)) |
2790 | r->x -= width; | |
2791 | } | |
2792 | ||
b9432a85 | 2793 | r->x += FRAME_INTERNAL_BORDER_WIDTH (s->f); |
1da3fd71 | 2794 | |
06a2c219 GM |
2795 | /* Unless displaying a mode or menu bar line, which are always |
2796 | fully visible, clip to the visible part of the row. */ | |
2797 | if (s->w->pseudo_window_p) | |
2798 | r->height = s->row->visible_height; | |
2799 | else | |
2800 | r->height = s->height; | |
2801 | } | |
2802 | else | |
2803 | { | |
2804 | /* This is a text line that may be partially visible. */ | |
2805 | r->x = WINDOW_AREA_TO_FRAME_PIXEL_X (s->w, s->area, 0); | |
2806 | r->width = window_box_width (s->w, s->area); | |
2807 | r->height = s->row->visible_height; | |
2808 | } | |
2809 | ||
2810 | /* Don't use S->y for clipping because it doesn't take partially | |
2811 | visible lines into account. For example, it can be negative for | |
2812 | partially visible lines at the top of a window. */ | |
2813 | if (!s->row->full_width_p | |
2814 | && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s->w, s->row)) | |
045dee35 | 2815 | r->y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); |
06a2c219 GM |
2816 | else |
2817 | r->y = max (0, s->row->y); | |
06a2c219 | 2818 | |
9ea173e8 | 2819 | /* If drawing a tool-bar window, draw it over the internal border |
06a2c219 | 2820 | at the top of the window. */ |
9ea173e8 | 2821 | if (s->w == XWINDOW (s->f->tool_bar_window)) |
06a2c219 | 2822 | r->y -= s->f->output_data.x->internal_border_width; |
66ac4b0e GM |
2823 | |
2824 | /* If S draws overlapping rows, it's sufficient to use the top and | |
2825 | bottom of the window for clipping because this glyph string | |
2826 | intentionally draws over other lines. */ | |
2827 | if (s->for_overlaps_p) | |
2828 | { | |
045dee35 | 2829 | r->y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); |
66ac4b0e GM |
2830 | r->height = window_text_bottom_y (s->w) - r->y; |
2831 | } | |
2832 | ||
2833 | r->y = WINDOW_TO_FRAME_PIXEL_Y (s->w, r->y); | |
06a2c219 GM |
2834 | } |
2835 | ||
2836 | ||
2837 | /* Set clipping for output of glyph string S. S may be part of a mode | |
2838 | line or menu if we don't have X toolkit support. */ | |
2839 | ||
2840 | static INLINE void | |
2841 | x_set_glyph_string_clipping (s) | |
2842 | struct glyph_string *s; | |
2843 | { | |
2844 | XRectangle r; | |
2845 | x_get_glyph_string_clip_rect (s, &r); | |
2846 | XSetClipRectangles (s->display, s->gc, 0, 0, &r, 1, Unsorted); | |
2847 | } | |
2848 | ||
2849 | ||
2850 | /* Compute left and right overhang of glyph string S. If S is a glyph | |
b4192550 | 2851 | string for a composition, assume overhangs don't exist. */ |
06a2c219 GM |
2852 | |
2853 | static INLINE void | |
2854 | x_compute_glyph_string_overhangs (s) | |
2855 | struct glyph_string *s; | |
2856 | { | |
b4192550 | 2857 | if (s->cmp == NULL |
06a2c219 GM |
2858 | && s->first_glyph->type == CHAR_GLYPH) |
2859 | { | |
2860 | XCharStruct cs; | |
2861 | int direction, font_ascent, font_descent; | |
2862 | XTextExtents16 (s->font, s->char2b, s->nchars, &direction, | |
2863 | &font_ascent, &font_descent, &cs); | |
2864 | s->right_overhang = cs.rbearing > cs.width ? cs.rbearing - cs.width : 0; | |
2865 | s->left_overhang = cs.lbearing < 0 ? -cs.lbearing : 0; | |
2866 | } | |
2867 | } | |
2868 | ||
2869 | ||
2870 | /* Compute overhangs and x-positions for glyph string S and its | |
2871 | predecessors, or successors. X is the starting x-position for S. | |
2872 | BACKWARD_P non-zero means process predecessors. */ | |
2873 | ||
2874 | static void | |
2875 | x_compute_overhangs_and_x (s, x, backward_p) | |
2876 | struct glyph_string *s; | |
2877 | int x; | |
2878 | int backward_p; | |
2879 | { | |
2880 | if (backward_p) | |
2881 | { | |
2882 | while (s) | |
2883 | { | |
2884 | x_compute_glyph_string_overhangs (s); | |
2885 | x -= s->width; | |
2886 | s->x = x; | |
2887 | s = s->prev; | |
2888 | } | |
2889 | } | |
2890 | else | |
2891 | { | |
2892 | while (s) | |
2893 | { | |
2894 | x_compute_glyph_string_overhangs (s); | |
2895 | s->x = x; | |
2896 | x += s->width; | |
2897 | s = s->next; | |
2898 | } | |
2899 | } | |
2900 | } | |
2901 | ||
2902 | ||
2903 | /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on | |
b4192550 KH |
2904 | frame F. Overhangs of glyphs other than type CHAR_GLYPH are |
2905 | assumed to be zero. */ | |
06a2c219 GM |
2906 | |
2907 | static void | |
2908 | x_get_glyph_overhangs (glyph, f, left, right) | |
2909 | struct glyph *glyph; | |
2910 | struct frame *f; | |
2911 | int *left, *right; | |
2912 | { | |
06a2c219 GM |
2913 | *left = *right = 0; |
2914 | ||
b4192550 | 2915 | if (glyph->type == CHAR_GLYPH) |
06a2c219 GM |
2916 | { |
2917 | XFontStruct *font; | |
2918 | struct face *face; | |
2919 | struct font_info *font_info; | |
2920 | XChar2b char2b; | |
ee569018 KH |
2921 | XCharStruct *pcm; |
2922 | ||
2923 | face = x_get_glyph_face_and_encoding (f, glyph, &char2b, NULL); | |
06a2c219 GM |
2924 | font = face->font; |
2925 | font_info = FONT_INFO_FROM_ID (f, face->font_info_id); | |
ee569018 KH |
2926 | if (font |
2927 | && (pcm = x_per_char_metric (font, &char2b))) | |
06a2c219 | 2928 | { |
06a2c219 GM |
2929 | if (pcm->rbearing > pcm->width) |
2930 | *right = pcm->rbearing - pcm->width; | |
2931 | if (pcm->lbearing < 0) | |
2932 | *left = -pcm->lbearing; | |
2933 | } | |
2934 | } | |
2935 | } | |
2936 | ||
2937 | ||
2938 | /* Return the index of the first glyph preceding glyph string S that | |
2939 | is overwritten by S because of S's left overhang. Value is -1 | |
2940 | if no glyphs are overwritten. */ | |
2941 | ||
2942 | static int | |
2943 | x_left_overwritten (s) | |
2944 | struct glyph_string *s; | |
2945 | { | |
2946 | int k; | |
2947 | ||
2948 | if (s->left_overhang) | |
2949 | { | |
2950 | int x = 0, i; | |
2951 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
2952 | int first = s->first_glyph - glyphs; | |
2953 | ||
2954 | for (i = first - 1; i >= 0 && x > -s->left_overhang; --i) | |
2955 | x -= glyphs[i].pixel_width; | |
2956 | ||
2957 | k = i + 1; | |
2958 | } | |
2959 | else | |
2960 | k = -1; | |
2961 | ||
2962 | return k; | |
2963 | } | |
2964 | ||
2965 | ||
2966 | /* Return the index of the first glyph preceding glyph string S that | |
2967 | is overwriting S because of its right overhang. Value is -1 if no | |
2968 | glyph in front of S overwrites S. */ | |
2969 | ||
2970 | static int | |
2971 | x_left_overwriting (s) | |
2972 | struct glyph_string *s; | |
2973 | { | |
2974 | int i, k, x; | |
2975 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
2976 | int first = s->first_glyph - glyphs; | |
2977 | ||
2978 | k = -1; | |
2979 | x = 0; | |
2980 | for (i = first - 1; i >= 0; --i) | |
2981 | { | |
2982 | int left, right; | |
2983 | x_get_glyph_overhangs (glyphs + i, s->f, &left, &right); | |
2984 | if (x + right > 0) | |
2985 | k = i; | |
2986 | x -= glyphs[i].pixel_width; | |
2987 | } | |
2988 | ||
2989 | return k; | |
2990 | } | |
2991 | ||
2992 | ||
2993 | /* Return the index of the last glyph following glyph string S that is | |
2994 | not overwritten by S because of S's right overhang. Value is -1 if | |
2995 | no such glyph is found. */ | |
2996 | ||
2997 | static int | |
2998 | x_right_overwritten (s) | |
2999 | struct glyph_string *s; | |
3000 | { | |
3001 | int k = -1; | |
3002 | ||
3003 | if (s->right_overhang) | |
3004 | { | |
3005 | int x = 0, i; | |
3006 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
b4192550 | 3007 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); |
06a2c219 GM |
3008 | int end = s->row->used[s->area]; |
3009 | ||
3010 | for (i = first; i < end && s->right_overhang > x; ++i) | |
3011 | x += glyphs[i].pixel_width; | |
3012 | ||
3013 | k = i; | |
3014 | } | |
3015 | ||
3016 | return k; | |
3017 | } | |
3018 | ||
3019 | ||
3020 | /* Return the index of the last glyph following glyph string S that | |
3021 | overwrites S because of its left overhang. Value is negative | |
3022 | if no such glyph is found. */ | |
3023 | ||
3024 | static int | |
3025 | x_right_overwriting (s) | |
3026 | struct glyph_string *s; | |
3027 | { | |
3028 | int i, k, x; | |
3029 | int end = s->row->used[s->area]; | |
3030 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
b4192550 | 3031 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); |
06a2c219 GM |
3032 | |
3033 | k = -1; | |
3034 | x = 0; | |
3035 | for (i = first; i < end; ++i) | |
3036 | { | |
3037 | int left, right; | |
3038 | x_get_glyph_overhangs (glyphs + i, s->f, &left, &right); | |
3039 | if (x - left < 0) | |
3040 | k = i; | |
3041 | x += glyphs[i].pixel_width; | |
3042 | } | |
3043 | ||
3044 | return k; | |
3045 | } | |
3046 | ||
3047 | ||
3048 | /* Fill rectangle X, Y, W, H with background color of glyph string S. */ | |
3049 | ||
3050 | static INLINE void | |
3051 | x_clear_glyph_string_rect (s, x, y, w, h) | |
3052 | struct glyph_string *s; | |
3053 | int x, y, w, h; | |
3054 | { | |
3055 | XGCValues xgcv; | |
3056 | XGetGCValues (s->display, s->gc, GCForeground | GCBackground, &xgcv); | |
3057 | XSetForeground (s->display, s->gc, xgcv.background); | |
3058 | XFillRectangle (s->display, s->window, s->gc, x, y, w, h); | |
3059 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
3060 | } | |
3061 | ||
3062 | ||
3063 | /* Draw the background of glyph_string S. If S->background_filled_p | |
3064 | is non-zero don't draw it. FORCE_P non-zero means draw the | |
3065 | background even if it wouldn't be drawn normally. This is used | |
b4192550 KH |
3066 | when a string preceding S draws into the background of S, or S |
3067 | contains the first component of a composition. */ | |
06a2c219 GM |
3068 | |
3069 | static void | |
3070 | x_draw_glyph_string_background (s, force_p) | |
3071 | struct glyph_string *s; | |
3072 | int force_p; | |
3073 | { | |
3074 | /* Nothing to do if background has already been drawn or if it | |
3075 | shouldn't be drawn in the first place. */ | |
3076 | if (!s->background_filled_p) | |
3077 | { | |
b4192550 | 3078 | if (s->stippled_p) |
06a2c219 GM |
3079 | { |
3080 | /* Fill background with a stipple pattern. */ | |
3081 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
3082 | XFillRectangle (s->display, s->window, s->gc, s->x, | |
3083 | s->y + s->face->box_line_width, | |
3084 | s->background_width, | |
3085 | s->height - 2 * s->face->box_line_width); | |
3086 | XSetFillStyle (s->display, s->gc, FillSolid); | |
3087 | s->background_filled_p = 1; | |
3088 | } | |
3089 | else if (FONT_HEIGHT (s->font) < s->height - 2 * s->face->box_line_width | |
3090 | || s->font_not_found_p | |
3091 | || s->extends_to_end_of_line_p | |
06a2c219 GM |
3092 | || force_p) |
3093 | { | |
3094 | x_clear_glyph_string_rect (s, s->x, s->y + s->face->box_line_width, | |
3095 | s->background_width, | |
3096 | s->height - 2 * s->face->box_line_width); | |
3097 | s->background_filled_p = 1; | |
3098 | } | |
3099 | } | |
3100 | } | |
3101 | ||
3102 | ||
3103 | /* Draw the foreground of glyph string S. */ | |
3104 | ||
3105 | static void | |
3106 | x_draw_glyph_string_foreground (s) | |
3107 | struct glyph_string *s; | |
3108 | { | |
3109 | int i, x; | |
3110 | ||
3111 | /* If first glyph of S has a left box line, start drawing the text | |
3112 | of S to the right of that box line. */ | |
3113 | if (s->face->box != FACE_NO_BOX | |
3114 | && s->first_glyph->left_box_line_p) | |
3115 | x = s->x + s->face->box_line_width; | |
3116 | else | |
3117 | x = s->x; | |
3118 | ||
b4192550 KH |
3119 | /* Draw characters of S as rectangles if S's font could not be |
3120 | loaded. */ | |
3121 | if (s->font_not_found_p) | |
06a2c219 | 3122 | { |
b4192550 | 3123 | for (i = 0; i < s->nchars; ++i) |
06a2c219 | 3124 | { |
b4192550 KH |
3125 | struct glyph *g = s->first_glyph + i; |
3126 | XDrawRectangle (s->display, s->window, | |
3127 | s->gc, x, s->y, g->pixel_width - 1, | |
3128 | s->height - 1); | |
3129 | x += g->pixel_width; | |
06a2c219 GM |
3130 | } |
3131 | } | |
3132 | else | |
3133 | { | |
b4192550 KH |
3134 | char *char1b = (char *) s->char2b; |
3135 | int boff = s->font_info->baseline_offset; | |
06a2c219 | 3136 | |
b4192550 KH |
3137 | if (s->font_info->vertical_centering) |
3138 | boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff; | |
3139 | ||
3140 | /* If we can use 8-bit functions, condense S->char2b. */ | |
3141 | if (!s->two_byte_p) | |
3142 | for (i = 0; i < s->nchars; ++i) | |
3143 | char1b[i] = s->char2b[i].byte2; | |
3144 | ||
3145 | /* Draw text with XDrawString if background has already been | |
3146 | filled. Otherwise, use XDrawImageString. (Note that | |
3147 | XDrawImageString is usually faster than XDrawString.) Always | |
3148 | use XDrawImageString when drawing the cursor so that there is | |
3149 | no chance that characters under a box cursor are invisible. */ | |
3150 | if (s->for_overlaps_p | |
3151 | || (s->background_filled_p && s->hl != DRAW_CURSOR)) | |
3152 | { | |
3153 | /* Draw characters with 16-bit or 8-bit functions. */ | |
3154 | if (s->two_byte_p) | |
3155 | XDrawString16 (s->display, s->window, s->gc, x, | |
3156 | s->ybase - boff, s->char2b, s->nchars); | |
3157 | else | |
3158 | XDrawString (s->display, s->window, s->gc, x, | |
3159 | s->ybase - boff, char1b, s->nchars); | |
3160 | } | |
06a2c219 GM |
3161 | else |
3162 | { | |
b4192550 KH |
3163 | if (s->two_byte_p) |
3164 | XDrawImageString16 (s->display, s->window, s->gc, x, | |
3165 | s->ybase - boff, s->char2b, s->nchars); | |
06a2c219 | 3166 | else |
b4192550 KH |
3167 | XDrawImageString (s->display, s->window, s->gc, x, |
3168 | s->ybase - boff, char1b, s->nchars); | |
3169 | } | |
3170 | } | |
3171 | } | |
06a2c219 | 3172 | |
b4192550 | 3173 | /* Draw the foreground of composite glyph string S. */ |
06a2c219 | 3174 | |
b4192550 KH |
3175 | static void |
3176 | x_draw_composite_glyph_string_foreground (s) | |
3177 | struct glyph_string *s; | |
3178 | { | |
3179 | int i, x; | |
06a2c219 | 3180 | |
b4192550 KH |
3181 | /* If first glyph of S has a left box line, start drawing the text |
3182 | of S to the right of that box line. */ | |
3183 | if (s->face->box != FACE_NO_BOX | |
3184 | && s->first_glyph->left_box_line_p) | |
3185 | x = s->x + s->face->box_line_width; | |
3186 | else | |
3187 | x = s->x; | |
06a2c219 | 3188 | |
b4192550 KH |
3189 | /* S is a glyph string for a composition. S->gidx is the index of |
3190 | the first character drawn for glyphs of this composition. | |
3191 | S->gidx == 0 means we are drawing the very first character of | |
3192 | this composition. */ | |
06a2c219 | 3193 | |
b4192550 KH |
3194 | /* Draw a rectangle for the composition if the font for the very |
3195 | first character of the composition could not be loaded. */ | |
3196 | if (s->font_not_found_p) | |
3197 | { | |
3198 | if (s->gidx == 0) | |
3199 | XDrawRectangle (s->display, s->window, s->gc, x, s->y, | |
3200 | s->width - 1, s->height - 1); | |
3201 | } | |
3202 | else | |
3203 | { | |
3204 | for (i = 0; i < s->nchars; i++, ++s->gidx) | |
3205 | XDrawString16 (s->display, s->window, s->gc, | |
3206 | x + s->cmp->offsets[s->gidx * 2], | |
3207 | s->ybase - s->cmp->offsets[s->gidx * 2 + 1], | |
3208 | s->char2b + i, 1); | |
06a2c219 GM |
3209 | } |
3210 | } | |
3211 | ||
3212 | ||
80c32bcc GM |
3213 | #ifdef USE_X_TOOLKIT |
3214 | ||
3e71d8f2 | 3215 | static struct frame *x_frame_of_widget P_ ((Widget)); |
80c32bcc | 3216 | |
3e71d8f2 GM |
3217 | |
3218 | /* Return the frame on which widget WIDGET is used.. Abort if frame | |
3219 | cannot be determined. */ | |
3220 | ||
e851c833 | 3221 | static struct frame * |
3e71d8f2 | 3222 | x_frame_of_widget (widget) |
80c32bcc | 3223 | Widget widget; |
80c32bcc | 3224 | { |
80c32bcc | 3225 | struct x_display_info *dpyinfo; |
5c187dee | 3226 | Lisp_Object tail; |
3e71d8f2 GM |
3227 | struct frame *f; |
3228 | ||
80c32bcc GM |
3229 | dpyinfo = x_display_info_for_display (XtDisplay (widget)); |
3230 | ||
3231 | /* Find the top-level shell of the widget. Note that this function | |
3232 | can be called when the widget is not yet realized, so XtWindow | |
3233 | (widget) == 0. That's the reason we can't simply use | |
3234 | x_any_window_to_frame. */ | |
3235 | while (!XtIsTopLevelShell (widget)) | |
3236 | widget = XtParent (widget); | |
3237 | ||
3238 | /* Look for a frame with that top-level widget. Allocate the color | |
3239 | on that frame to get the right gamma correction value. */ | |
3240 | for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) | |
3241 | if (GC_FRAMEP (XCAR (tail)) | |
3242 | && (f = XFRAME (XCAR (tail)), | |
3243 | (f->output_data.nothing != 1 | |
3244 | && FRAME_X_DISPLAY_INFO (f) == dpyinfo)) | |
3245 | && f->output_data.x->widget == widget) | |
3e71d8f2 | 3246 | return f; |
80c32bcc GM |
3247 | |
3248 | abort (); | |
3249 | } | |
3250 | ||
3e71d8f2 GM |
3251 | |
3252 | /* Allocate the color COLOR->pixel on the screen and display of | |
3253 | widget WIDGET in colormap CMAP. If an exact match cannot be | |
3254 | allocated, try the nearest color available. Value is non-zero | |
3255 | if successful. This is called from lwlib. */ | |
3256 | ||
3257 | int | |
3258 | x_alloc_nearest_color_for_widget (widget, cmap, color) | |
3259 | Widget widget; | |
3260 | Colormap cmap; | |
3261 | XColor *color; | |
3262 | { | |
3263 | struct frame *f = x_frame_of_widget (widget); | |
3264 | return x_alloc_nearest_color (f, cmap, color); | |
3265 | } | |
3266 | ||
3267 | ||
46d516e5 MB |
3268 | /* Allocate a color which is lighter or darker than *PIXEL by FACTOR |
3269 | or DELTA. Try a color with RGB values multiplied by FACTOR first. | |
3270 | If this produces the same color as PIXEL, try a color where all RGB | |
3271 | values have DELTA added. Return the allocated color in *PIXEL. | |
3272 | DISPLAY is the X display, CMAP is the colormap to operate on. | |
3273 | Value is non-zero if successful. */ | |
3274 | ||
3275 | int | |
3276 | x_alloc_lighter_color_for_widget (widget, display, cmap, pixel, factor, delta) | |
3277 | Widget widget; | |
3278 | Display *display; | |
3279 | Colormap cmap; | |
3280 | unsigned long *pixel; | |
3281 | double factor; | |
3282 | int delta; | |
3283 | { | |
3284 | struct frame *f = x_frame_of_widget (widget); | |
3285 | return x_alloc_lighter_color (f, display, cmap, pixel, factor, delta); | |
3286 | } | |
3287 | ||
3288 | ||
80c32bcc GM |
3289 | #endif /* USE_X_TOOLKIT */ |
3290 | ||
3291 | ||
06a2c219 GM |
3292 | /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap |
3293 | CMAP. If an exact match can't be allocated, try the nearest color | |
3294 | available. Value is non-zero if successful. Set *COLOR to the | |
3295 | color allocated. */ | |
3296 | ||
3297 | int | |
80c32bcc GM |
3298 | x_alloc_nearest_color (f, cmap, color) |
3299 | struct frame *f; | |
06a2c219 GM |
3300 | Colormap cmap; |
3301 | XColor *color; | |
3302 | { | |
80c32bcc GM |
3303 | Display *display = FRAME_X_DISPLAY (f); |
3304 | Screen *screen = FRAME_X_SCREEN (f); | |
3305 | int rc; | |
3306 | ||
3307 | gamma_correct (f, color); | |
3308 | rc = XAllocColor (display, cmap, color); | |
06a2c219 GM |
3309 | if (rc == 0) |
3310 | { | |
3311 | /* If we got to this point, the colormap is full, so we're going | |
3312 | to try to get the next closest color. The algorithm used is | |
3313 | a least-squares matching, which is what X uses for closest | |
3314 | color matching with StaticColor visuals. */ | |
3315 | int nearest, i; | |
3316 | unsigned long nearest_delta = ~0; | |
3317 | int ncells = XDisplayCells (display, XScreenNumberOfScreen (screen)); | |
3318 | XColor *cells = (XColor *) alloca (ncells * sizeof *cells); | |
3319 | ||
3320 | for (i = 0; i < ncells; ++i) | |
3321 | cells[i].pixel = i; | |
3322 | XQueryColors (display, cmap, cells, ncells); | |
3323 | ||
3324 | for (nearest = i = 0; i < ncells; ++i) | |
3325 | { | |
3326 | long dred = (color->red >> 8) - (cells[i].red >> 8); | |
3327 | long dgreen = (color->green >> 8) - (cells[i].green >> 8); | |
3328 | long dblue = (color->blue >> 8) - (cells[i].blue >> 8); | |
3329 | unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; | |
3330 | ||
3331 | if (delta < nearest_delta) | |
3332 | { | |
3333 | nearest = i; | |
3334 | nearest_delta = delta; | |
3335 | } | |
3336 | } | |
3337 | ||
3338 | color->red = cells[nearest].red; | |
3339 | color->green = cells[nearest].green; | |
3340 | color->blue = cells[nearest].blue; | |
3341 | rc = XAllocColor (display, cmap, color); | |
3342 | } | |
3343 | ||
d9c545da GM |
3344 | #ifdef DEBUG_X_COLORS |
3345 | if (rc) | |
3346 | register_color (color->pixel); | |
3347 | #endif /* DEBUG_X_COLORS */ | |
3348 | ||
06a2c219 GM |
3349 | return rc; |
3350 | } | |
3351 | ||
3352 | ||
d9c545da GM |
3353 | /* Allocate color PIXEL on frame F. PIXEL must already be allocated. |
3354 | It's necessary to do this instead of just using PIXEL directly to | |
3355 | get color reference counts right. */ | |
3356 | ||
3357 | unsigned long | |
3358 | x_copy_color (f, pixel) | |
3359 | struct frame *f; | |
3360 | unsigned long pixel; | |
3361 | { | |
3362 | XColor color; | |
3363 | ||
3364 | color.pixel = pixel; | |
3365 | BLOCK_INPUT; | |
3366 | XQueryColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &color); | |
3367 | XAllocColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &color); | |
3368 | UNBLOCK_INPUT; | |
3369 | #ifdef DEBUG_X_COLORS | |
3370 | register_color (pixel); | |
3371 | #endif | |
3372 | return color.pixel; | |
3373 | } | |
3374 | ||
3375 | ||
3e71d8f2 GM |
3376 | /* Allocate color PIXEL on display DPY. PIXEL must already be allocated. |
3377 | It's necessary to do this instead of just using PIXEL directly to | |
3378 | get color reference counts right. */ | |
3379 | ||
3380 | unsigned long | |
3381 | x_copy_dpy_color (dpy, cmap, pixel) | |
3382 | Display *dpy; | |
3383 | Colormap cmap; | |
3384 | unsigned long pixel; | |
3385 | { | |
3386 | XColor color; | |
3387 | ||
3388 | color.pixel = pixel; | |
3389 | BLOCK_INPUT; | |
3390 | XQueryColor (dpy, cmap, &color); | |
3391 | XAllocColor (dpy, cmap, &color); | |
3392 | UNBLOCK_INPUT; | |
3393 | #ifdef DEBUG_X_COLORS | |
3394 | register_color (pixel); | |
3395 | #endif | |
3396 | return color.pixel; | |
3397 | } | |
3398 | ||
3399 | ||
06a2c219 GM |
3400 | /* Allocate a color which is lighter or darker than *PIXEL by FACTOR |
3401 | or DELTA. Try a color with RGB values multiplied by FACTOR first. | |
3402 | If this produces the same color as PIXEL, try a color where all RGB | |
3403 | values have DELTA added. Return the allocated color in *PIXEL. | |
3404 | DISPLAY is the X display, CMAP is the colormap to operate on. | |
3405 | Value is non-zero if successful. */ | |
3406 | ||
3407 | static int | |
3408 | x_alloc_lighter_color (f, display, cmap, pixel, factor, delta) | |
3409 | struct frame *f; | |
3410 | Display *display; | |
3411 | Colormap cmap; | |
3412 | unsigned long *pixel; | |
68c45bf0 | 3413 | double factor; |
06a2c219 GM |
3414 | int delta; |
3415 | { | |
3416 | XColor color, new; | |
3417 | int success_p; | |
3418 | ||
3419 | /* Get RGB color values. */ | |
3420 | color.pixel = *pixel; | |
3421 | XQueryColor (display, cmap, &color); | |
3422 | ||
3423 | /* Change RGB values by specified FACTOR. Avoid overflow! */ | |
3424 | xassert (factor >= 0); | |
3425 | new.red = min (0xffff, factor * color.red); | |
3426 | new.green = min (0xffff, factor * color.green); | |
3427 | new.blue = min (0xffff, factor * color.blue); | |
3428 | ||
3429 | /* Try to allocate the color. */ | |
80c32bcc | 3430 | success_p = x_alloc_nearest_color (f, cmap, &new); |
06a2c219 GM |
3431 | if (success_p) |
3432 | { | |
3433 | if (new.pixel == *pixel) | |
3434 | { | |
3435 | /* If we end up with the same color as before, try adding | |
3436 | delta to the RGB values. */ | |
0d605c67 | 3437 | x_free_colors (f, &new.pixel, 1); |
06a2c219 GM |
3438 | |
3439 | new.red = min (0xffff, delta + color.red); | |
3440 | new.green = min (0xffff, delta + color.green); | |
3441 | new.blue = min (0xffff, delta + color.blue); | |
80c32bcc | 3442 | success_p = x_alloc_nearest_color (f, cmap, &new); |
06a2c219 GM |
3443 | } |
3444 | else | |
3445 | success_p = 1; | |
3446 | *pixel = new.pixel; | |
3447 | } | |
3448 | ||
3449 | return success_p; | |
3450 | } | |
3451 | ||
3452 | ||
3453 | /* Set up the foreground color for drawing relief lines of glyph | |
3454 | string S. RELIEF is a pointer to a struct relief containing the GC | |
3455 | with which lines will be drawn. Use a color that is FACTOR or | |
3456 | DELTA lighter or darker than the relief's background which is found | |
3457 | in S->f->output_data.x->relief_background. If such a color cannot | |
3458 | be allocated, use DEFAULT_PIXEL, instead. */ | |
3459 | ||
3460 | static void | |
3461 | x_setup_relief_color (f, relief, factor, delta, default_pixel) | |
3462 | struct frame *f; | |
3463 | struct relief *relief; | |
68c45bf0 | 3464 | double factor; |
06a2c219 GM |
3465 | int delta; |
3466 | unsigned long default_pixel; | |
3467 | { | |
3468 | XGCValues xgcv; | |
3469 | struct x_output *di = f->output_data.x; | |
3470 | unsigned long mask = GCForeground | GCLineWidth | GCGraphicsExposures; | |
3471 | unsigned long pixel; | |
3472 | unsigned long background = di->relief_background; | |
43bd1b2b | 3473 | Colormap cmap = FRAME_X_COLORMAP (f); |
dcd08bfb GM |
3474 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
3475 | Display *dpy = FRAME_X_DISPLAY (f); | |
06a2c219 GM |
3476 | |
3477 | xgcv.graphics_exposures = False; | |
3478 | xgcv.line_width = 1; | |
3479 | ||
3480 | /* Free previously allocated color. The color cell will be reused | |
3481 | when it has been freed as many times as it was allocated, so this | |
3482 | doesn't affect faces using the same colors. */ | |
3483 | if (relief->gc | |
3484 | && relief->allocated_p) | |
3485 | { | |
0d605c67 | 3486 | x_free_colors (f, &relief->pixel, 1); |
06a2c219 GM |
3487 | relief->allocated_p = 0; |
3488 | } | |
3489 | ||
3490 | /* Allocate new color. */ | |
3491 | xgcv.foreground = default_pixel; | |
3492 | pixel = background; | |
dcd08bfb GM |
3493 | if (dpyinfo->n_planes != 1 |
3494 | && x_alloc_lighter_color (f, dpy, cmap, &pixel, factor, delta)) | |
06a2c219 GM |
3495 | { |
3496 | relief->allocated_p = 1; | |
3497 | xgcv.foreground = relief->pixel = pixel; | |
3498 | } | |
3499 | ||
3500 | if (relief->gc == 0) | |
3501 | { | |
dcd08bfb | 3502 | xgcv.stipple = dpyinfo->gray; |
06a2c219 | 3503 | mask |= GCStipple; |
dcd08bfb | 3504 | relief->gc = XCreateGC (dpy, FRAME_X_WINDOW (f), mask, &xgcv); |
06a2c219 GM |
3505 | } |
3506 | else | |
dcd08bfb | 3507 | XChangeGC (dpy, relief->gc, mask, &xgcv); |
06a2c219 GM |
3508 | } |
3509 | ||
3510 | ||
3511 | /* Set up colors for the relief lines around glyph string S. */ | |
3512 | ||
3513 | static void | |
3514 | x_setup_relief_colors (s) | |
3515 | struct glyph_string *s; | |
3516 | { | |
3517 | struct x_output *di = s->f->output_data.x; | |
3518 | unsigned long color; | |
3519 | ||
3520 | if (s->face->use_box_color_for_shadows_p) | |
3521 | color = s->face->box_color; | |
3522 | else | |
3523 | { | |
3524 | XGCValues xgcv; | |
3525 | ||
3526 | /* Get the background color of the face. */ | |
3527 | XGetGCValues (s->display, s->gc, GCBackground, &xgcv); | |
3528 | color = xgcv.background; | |
3529 | } | |
3530 | ||
3531 | if (di->white_relief.gc == 0 | |
3532 | || color != di->relief_background) | |
3533 | { | |
3534 | di->relief_background = color; | |
3535 | x_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000, | |
3536 | WHITE_PIX_DEFAULT (s->f)); | |
3537 | x_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000, | |
3538 | BLACK_PIX_DEFAULT (s->f)); | |
3539 | } | |
3540 | } | |
3541 | ||
3542 | ||
3543 | /* Draw a relief on frame F inside the rectangle given by LEFT_X, | |
3544 | TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief | |
3545 | to draw, it must be >= 0. RAISED_P non-zero means draw a raised | |
3546 | relief. LEFT_P non-zero means draw a relief on the left side of | |
3547 | the rectangle. RIGHT_P non-zero means draw a relief on the right | |
3548 | side of the rectangle. CLIP_RECT is the clipping rectangle to use | |
3549 | when drawing. */ | |
3550 | ||
3551 | static void | |
3552 | x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, | |
3553 | raised_p, left_p, right_p, clip_rect) | |
3554 | struct frame *f; | |
3555 | int left_x, top_y, right_x, bottom_y, left_p, right_p, raised_p; | |
3556 | XRectangle *clip_rect; | |
3557 | { | |
3558 | int i; | |
3559 | GC gc; | |
3560 | ||
3561 | if (raised_p) | |
3562 | gc = f->output_data.x->white_relief.gc; | |
3563 | else | |
3564 | gc = f->output_data.x->black_relief.gc; | |
3565 | XSetClipRectangles (FRAME_X_DISPLAY (f), gc, 0, 0, clip_rect, 1, Unsorted); | |
3566 | ||
3567 | /* Top. */ | |
3568 | for (i = 0; i < width; ++i) | |
3569 | XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
3570 | left_x + i * left_p, top_y + i, | |
3571 | right_x + 1 - i * right_p, top_y + i); | |
3572 | ||
3573 | /* Left. */ | |
3574 | if (left_p) | |
3575 | for (i = 0; i < width; ++i) | |
3576 | XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
3577 | left_x + i, top_y + i, left_x + i, bottom_y - i); | |
3578 | ||
3579 | XSetClipMask (FRAME_X_DISPLAY (f), gc, None); | |
3580 | if (raised_p) | |
3581 | gc = f->output_data.x->black_relief.gc; | |
3582 | else | |
3583 | gc = f->output_data.x->white_relief.gc; | |
3584 | XSetClipRectangles (FRAME_X_DISPLAY (f), gc, 0, 0, clip_rect, 1, Unsorted); | |
3585 | ||
3586 | /* Bottom. */ | |
3587 | for (i = 0; i < width; ++i) | |
3588 | XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
3589 | left_x + i * left_p, bottom_y - i, | |
3590 | right_x + 1 - i * right_p, bottom_y - i); | |
3591 | ||
3592 | /* Right. */ | |
3593 | if (right_p) | |
3594 | for (i = 0; i < width; ++i) | |
3595 | XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
3596 | right_x - i, top_y + i + 1, right_x - i, bottom_y - i); | |
3597 | ||
3598 | XSetClipMask (FRAME_X_DISPLAY (f), gc, None); | |
3599 | } | |
3600 | ||
3601 | ||
3602 | /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y, | |
3603 | RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to | |
3604 | draw, it must be >= 0. LEFT_P non-zero means draw a line on the | |
3605 | left side of the rectangle. RIGHT_P non-zero means draw a line | |
3606 | on the right side of the rectangle. CLIP_RECT is the clipping | |
3607 | rectangle to use when drawing. */ | |
3608 | ||
3609 | static void | |
3610 | x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3611 | left_p, right_p, clip_rect) | |
3612 | struct glyph_string *s; | |
3613 | int left_x, top_y, right_x, bottom_y, left_p, right_p; | |
3614 | XRectangle *clip_rect; | |
3615 | { | |
3616 | XGCValues xgcv; | |
3617 | ||
3618 | XGetGCValues (s->display, s->gc, GCForeground, &xgcv); | |
3619 | XSetForeground (s->display, s->gc, s->face->box_color); | |
3620 | XSetClipRectangles (s->display, s->gc, 0, 0, clip_rect, 1, Unsorted); | |
3621 | ||
3622 | /* Top. */ | |
3623 | XFillRectangle (s->display, s->window, s->gc, | |
58e4fce8 | 3624 | left_x, top_y, right_x - left_x + 1, width); |
06a2c219 GM |
3625 | |
3626 | /* Left. */ | |
3627 | if (left_p) | |
3628 | XFillRectangle (s->display, s->window, s->gc, | |
58e4fce8 | 3629 | left_x, top_y, width, bottom_y - top_y + 1); |
06a2c219 GM |
3630 | |
3631 | /* Bottom. */ | |
3632 | XFillRectangle (s->display, s->window, s->gc, | |
58e4fce8 | 3633 | left_x, bottom_y - width + 1, right_x - left_x + 1, width); |
06a2c219 GM |
3634 | |
3635 | /* Right. */ | |
3636 | if (right_p) | |
3637 | XFillRectangle (s->display, s->window, s->gc, | |
58e4fce8 | 3638 | right_x - width + 1, top_y, width, bottom_y - top_y + 1); |
06a2c219 GM |
3639 | |
3640 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
3641 | XSetClipMask (s->display, s->gc, None); | |
3642 | } | |
3643 | ||
3644 | ||
3645 | /* Draw a box around glyph string S. */ | |
3646 | ||
3647 | static void | |
3648 | x_draw_glyph_string_box (s) | |
3649 | struct glyph_string *s; | |
3650 | { | |
3651 | int width, left_x, right_x, top_y, bottom_y, last_x, raised_p; | |
3652 | int left_p, right_p; | |
3653 | struct glyph *last_glyph; | |
3654 | XRectangle clip_rect; | |
3655 | ||
3656 | last_x = window_box_right (s->w, s->area); | |
3657 | if (s->row->full_width_p | |
3658 | && !s->w->pseudo_window_p) | |
3659 | { | |
110859fc | 3660 | last_x += FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s->f); |
06a2c219 GM |
3661 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s->f)) |
3662 | last_x += FRAME_SCROLL_BAR_WIDTH (s->f) * CANON_X_UNIT (s->f); | |
3663 | } | |
3664 | ||
3665 | /* The glyph that may have a right box line. */ | |
b4192550 | 3666 | last_glyph = (s->cmp || s->img |
06a2c219 GM |
3667 | ? s->first_glyph |
3668 | : s->first_glyph + s->nchars - 1); | |
3669 | ||
3670 | width = s->face->box_line_width; | |
3671 | raised_p = s->face->box == FACE_RAISED_BOX; | |
3672 | left_x = s->x; | |
3673 | right_x = ((s->row->full_width_p | |
1da3fd71 | 3674 | ? last_x - 1 |
a7aeb2de | 3675 | : min (last_x, s->x + s->background_width) - 1)); |
06a2c219 GM |
3676 | top_y = s->y; |
3677 | bottom_y = top_y + s->height - 1; | |
3678 | ||
3679 | left_p = (s->first_glyph->left_box_line_p | |
3680 | || (s->hl == DRAW_MOUSE_FACE | |
3681 | && (s->prev == NULL | |
3682 | || s->prev->hl != s->hl))); | |
3683 | right_p = (last_glyph->right_box_line_p | |
3684 | || (s->hl == DRAW_MOUSE_FACE | |
3685 | && (s->next == NULL | |
3686 | || s->next->hl != s->hl))); | |
3687 | ||
3688 | x_get_glyph_string_clip_rect (s, &clip_rect); | |
3689 | ||
3690 | if (s->face->box == FACE_SIMPLE_BOX) | |
3691 | x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3692 | left_p, right_p, &clip_rect); | |
3693 | else | |
3694 | { | |
3695 | x_setup_relief_colors (s); | |
3696 | x_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, | |
3697 | width, raised_p, left_p, right_p, &clip_rect); | |
3698 | } | |
3699 | } | |
3700 | ||
3701 | ||
3702 | /* Draw foreground of image glyph string S. */ | |
3703 | ||
3704 | static void | |
3705 | x_draw_image_foreground (s) | |
3706 | struct glyph_string *s; | |
3707 | { | |
3708 | int x; | |
95af8492 | 3709 | int y = s->ybase - image_ascent (s->img, s->face); |
06a2c219 GM |
3710 | |
3711 | /* If first glyph of S has a left box line, start drawing it to the | |
3712 | right of that line. */ | |
3713 | if (s->face->box != FACE_NO_BOX | |
3714 | && s->first_glyph->left_box_line_p) | |
3715 | x = s->x + s->face->box_line_width; | |
3716 | else | |
3717 | x = s->x; | |
3718 | ||
3719 | /* If there is a margin around the image, adjust x- and y-position | |
3720 | by that margin. */ | |
3721 | if (s->img->margin) | |
3722 | { | |
3723 | x += s->img->margin; | |
3724 | y += s->img->margin; | |
3725 | } | |
3726 | ||
3727 | if (s->img->pixmap) | |
3728 | { | |
3729 | if (s->img->mask) | |
3730 | { | |
3731 | /* We can't set both a clip mask and use XSetClipRectangles | |
3732 | because the latter also sets a clip mask. We also can't | |
3733 | trust on the shape extension to be available | |
3734 | (XShapeCombineRegion). So, compute the rectangle to draw | |
3735 | manually. */ | |
3736 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
3737 | | GCFunction); | |
3738 | XGCValues xgcv; | |
3739 | XRectangle clip_rect, image_rect, r; | |
3740 | ||
3741 | xgcv.clip_mask = s->img->mask; | |
3742 | xgcv.clip_x_origin = x; | |
3743 | xgcv.clip_y_origin = y; | |
3744 | xgcv.function = GXcopy; | |
3745 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
3746 | ||
3747 | x_get_glyph_string_clip_rect (s, &clip_rect); | |
3748 | image_rect.x = x; | |
3749 | image_rect.y = y; | |
3750 | image_rect.width = s->img->width; | |
3751 | image_rect.height = s->img->height; | |
3752 | if (x_intersect_rectangles (&clip_rect, &image_rect, &r)) | |
3753 | XCopyArea (s->display, s->img->pixmap, s->window, s->gc, | |
3754 | r.x - x, r.y - y, r.width, r.height, r.x, r.y); | |
3755 | } | |
3756 | else | |
3757 | { | |
49ad1d99 GM |
3758 | unsigned long mask = GCClipXOrigin | GCClipYOrigin | GCFunction; |
3759 | XGCValues xgcv; | |
3760 | XRectangle clip_rect, image_rect, r; | |
3761 | ||
3762 | x_get_glyph_string_clip_rect (s, &clip_rect); | |
3763 | image_rect.x = x; | |
3764 | image_rect.y = y; | |
3765 | image_rect.width = s->img->width; | |
3766 | image_rect.height = s->img->height; | |
3767 | if (x_intersect_rectangles (&clip_rect, &image_rect, &r)) | |
3768 | XCopyArea (s->display, s->img->pixmap, s->window, s->gc, | |
3769 | r.x - x, r.y - y, r.width, r.height, r.x, r.y); | |
06a2c219 GM |
3770 | |
3771 | /* When the image has a mask, we can expect that at | |
3772 | least part of a mouse highlight or a block cursor will | |
3773 | be visible. If the image doesn't have a mask, make | |
3774 | a block cursor visible by drawing a rectangle around | |
3775 | the image. I believe it's looking better if we do | |
3776 | nothing here for mouse-face. */ | |
3777 | if (s->hl == DRAW_CURSOR) | |
3778 | XDrawRectangle (s->display, s->window, s->gc, x, y, | |
3779 | s->img->width - 1, s->img->height - 1); | |
3780 | } | |
3781 | } | |
3782 | else | |
3783 | /* Draw a rectangle if image could not be loaded. */ | |
3784 | XDrawRectangle (s->display, s->window, s->gc, x, y, | |
3785 | s->img->width - 1, s->img->height - 1); | |
3786 | } | |
3787 | ||
3788 | ||
3789 | /* Draw a relief around the image glyph string S. */ | |
3790 | ||
3791 | static void | |
3792 | x_draw_image_relief (s) | |
3793 | struct glyph_string *s; | |
3794 | { | |
3795 | int x0, y0, x1, y1, thick, raised_p; | |
3796 | XRectangle r; | |
3797 | int x; | |
95af8492 | 3798 | int y = s->ybase - image_ascent (s->img, s->face); |
06a2c219 GM |
3799 | |
3800 | /* If first glyph of S has a left box line, start drawing it to the | |
3801 | right of that line. */ | |
3802 | if (s->face->box != FACE_NO_BOX | |
3803 | && s->first_glyph->left_box_line_p) | |
3804 | x = s->x + s->face->box_line_width; | |
3805 | else | |
3806 | x = s->x; | |
3807 | ||
3808 | /* If there is a margin around the image, adjust x- and y-position | |
3809 | by that margin. */ | |
3810 | if (s->img->margin) | |
3811 | { | |
3812 | x += s->img->margin; | |
3813 | y += s->img->margin; | |
3814 | } | |
3815 | ||
3816 | if (s->hl == DRAW_IMAGE_SUNKEN | |
3817 | || s->hl == DRAW_IMAGE_RAISED) | |
3818 | { | |
9ea173e8 | 3819 | thick = tool_bar_button_relief > 0 ? tool_bar_button_relief : 3; |
06a2c219 GM |
3820 | raised_p = s->hl == DRAW_IMAGE_RAISED; |
3821 | } | |
3822 | else | |
3823 | { | |
3824 | thick = abs (s->img->relief); | |
3825 | raised_p = s->img->relief > 0; | |
3826 | } | |
3827 | ||
3828 | x0 = x - thick; | |
3829 | y0 = y - thick; | |
3830 | x1 = x + s->img->width + thick - 1; | |
3831 | y1 = y + s->img->height + thick - 1; | |
3832 | ||
3833 | x_setup_relief_colors (s); | |
3834 | x_get_glyph_string_clip_rect (s, &r); | |
3835 | x_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, 1, 1, &r); | |
3836 | } | |
3837 | ||
3838 | ||
3839 | /* Draw the foreground of image glyph string S to PIXMAP. */ | |
3840 | ||
3841 | static void | |
3842 | x_draw_image_foreground_1 (s, pixmap) | |
3843 | struct glyph_string *s; | |
3844 | Pixmap pixmap; | |
3845 | { | |
3846 | int x; | |
95af8492 | 3847 | int y = s->ybase - s->y - image_ascent (s->img, s->face); |
06a2c219 GM |
3848 | |
3849 | /* If first glyph of S has a left box line, start drawing it to the | |
3850 | right of that line. */ | |
3851 | if (s->face->box != FACE_NO_BOX | |
3852 | && s->first_glyph->left_box_line_p) | |
3853 | x = s->face->box_line_width; | |
3854 | else | |
3855 | x = 0; | |
3856 | ||
3857 | /* If there is a margin around the image, adjust x- and y-position | |
3858 | by that margin. */ | |
3859 | if (s->img->margin) | |
3860 | { | |
3861 | x += s->img->margin; | |
3862 | y += s->img->margin; | |
3863 | } | |
dc43ef94 | 3864 | |
06a2c219 GM |
3865 | if (s->img->pixmap) |
3866 | { | |
3867 | if (s->img->mask) | |
3868 | { | |
3869 | /* We can't set both a clip mask and use XSetClipRectangles | |
3870 | because the latter also sets a clip mask. We also can't | |
3871 | trust on the shape extension to be available | |
3872 | (XShapeCombineRegion). So, compute the rectangle to draw | |
3873 | manually. */ | |
3874 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
3875 | | GCFunction); | |
3876 | XGCValues xgcv; | |
3877 | ||
3878 | xgcv.clip_mask = s->img->mask; | |
3879 | xgcv.clip_x_origin = x; | |
3880 | xgcv.clip_y_origin = y; | |
3881 | xgcv.function = GXcopy; | |
3882 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
3883 | ||
3884 | XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, | |
3885 | 0, 0, s->img->width, s->img->height, x, y); | |
3886 | XSetClipMask (s->display, s->gc, None); | |
3887 | } | |
3888 | else | |
3889 | { | |
3890 | XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, | |
3891 | 0, 0, s->img->width, s->img->height, x, y); | |
3892 | ||
3893 | /* When the image has a mask, we can expect that at | |
3894 | least part of a mouse highlight or a block cursor will | |
3895 | be visible. If the image doesn't have a mask, make | |
3896 | a block cursor visible by drawing a rectangle around | |
3897 | the image. I believe it's looking better if we do | |
3898 | nothing here for mouse-face. */ | |
3899 | if (s->hl == DRAW_CURSOR) | |
3900 | XDrawRectangle (s->display, pixmap, s->gc, x, y, | |
3901 | s->img->width - 1, s->img->height - 1); | |
3902 | } | |
3903 | } | |
3904 | else | |
3905 | /* Draw a rectangle if image could not be loaded. */ | |
3906 | XDrawRectangle (s->display, pixmap, s->gc, x, y, | |
3907 | s->img->width - 1, s->img->height - 1); | |
3908 | } | |
dc43ef94 | 3909 | |
990ba854 | 3910 | |
06a2c219 GM |
3911 | /* Draw part of the background of glyph string S. X, Y, W, and H |
3912 | give the rectangle to draw. */ | |
a9a5b0a5 | 3913 | |
06a2c219 GM |
3914 | static void |
3915 | x_draw_glyph_string_bg_rect (s, x, y, w, h) | |
3916 | struct glyph_string *s; | |
3917 | int x, y, w, h; | |
3918 | { | |
3919 | if (s->stippled_p) | |
3920 | { | |
3921 | /* Fill background with a stipple pattern. */ | |
3922 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
3923 | XFillRectangle (s->display, s->window, s->gc, x, y, w, h); | |
3924 | XSetFillStyle (s->display, s->gc, FillSolid); | |
3925 | } | |
3926 | else | |
3927 | x_clear_glyph_string_rect (s, x, y, w, h); | |
3928 | } | |
07e34cb0 | 3929 | |
b5210ea7 | 3930 | |
06a2c219 | 3931 | /* Draw image glyph string S. |
dc43ef94 | 3932 | |
06a2c219 GM |
3933 | s->y |
3934 | s->x +------------------------- | |
3935 | | s->face->box | |
3936 | | | |
3937 | | +------------------------- | |
3938 | | | s->img->margin | |
3939 | | | | |
3940 | | | +------------------- | |
3941 | | | | the image | |
dc43ef94 | 3942 | |
06a2c219 | 3943 | */ |
dc43ef94 | 3944 | |
06a2c219 GM |
3945 | static void |
3946 | x_draw_image_glyph_string (s) | |
3947 | struct glyph_string *s; | |
3948 | { | |
3949 | int x, y; | |
3950 | int box_line_width = s->face->box_line_width; | |
3951 | int margin = s->img->margin; | |
3952 | int height; | |
3953 | Pixmap pixmap = None; | |
3954 | ||
3955 | height = s->height - 2 * box_line_width; | |
3956 | ||
3957 | /* Fill background with face under the image. Do it only if row is | |
3958 | taller than image or if image has a clip mask to reduce | |
3959 | flickering. */ | |
3960 | s->stippled_p = s->face->stipple != 0; | |
3961 | if (height > s->img->height | |
3962 | || margin | |
3963 | || s->img->mask | |
3964 | || s->img->pixmap == 0 | |
3965 | || s->width != s->background_width) | |
3966 | { | |
3967 | if (box_line_width && s->first_glyph->left_box_line_p) | |
3968 | x = s->x + box_line_width; | |
3969 | else | |
3970 | x = s->x; | |
3971 | ||
3972 | y = s->y + box_line_width; | |
3973 | ||
3974 | if (s->img->mask) | |
3975 | { | |
f9b5db02 GM |
3976 | /* Create a pixmap as large as the glyph string. Fill it |
3977 | with the background color. Copy the image to it, using | |
3978 | its mask. Copy the temporary pixmap to the display. */ | |
06a2c219 GM |
3979 | Screen *screen = FRAME_X_SCREEN (s->f); |
3980 | int depth = DefaultDepthOfScreen (screen); | |
3981 | ||
3982 | /* Create a pixmap as large as the glyph string. */ | |
3983 | pixmap = XCreatePixmap (s->display, s->window, | |
3984 | s->background_width, | |
3985 | s->height, depth); | |
3986 | ||
3987 | /* Don't clip in the following because we're working on the | |
3988 | pixmap. */ | |
3989 | XSetClipMask (s->display, s->gc, None); | |
3990 | ||
3991 | /* Fill the pixmap with the background color/stipple. */ | |
3992 | if (s->stippled_p) | |
3993 | { | |
3994 | /* Fill background with a stipple pattern. */ | |
3995 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
3996 | XFillRectangle (s->display, pixmap, s->gc, | |
3997 | 0, 0, s->background_width, s->height); | |
3998 | XSetFillStyle (s->display, s->gc, FillSolid); | |
3999 | } | |
4000 | else | |
4001 | { | |
4002 | XGCValues xgcv; | |
4003 | XGetGCValues (s->display, s->gc, GCForeground | GCBackground, | |
4004 | &xgcv); | |
4005 | XSetForeground (s->display, s->gc, xgcv.background); | |
4006 | XFillRectangle (s->display, pixmap, s->gc, | |
4007 | 0, 0, s->background_width, s->height); | |
4008 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4009 | } | |
4010 | } | |
4011 | else | |
06a2c219 GM |
4012 | x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height); |
4013 | ||
4014 | s->background_filled_p = 1; | |
4015 | } | |
dc43ef94 | 4016 | |
06a2c219 GM |
4017 | /* Draw the foreground. */ |
4018 | if (pixmap != None) | |
4019 | { | |
4020 | x_draw_image_foreground_1 (s, pixmap); | |
4021 | x_set_glyph_string_clipping (s); | |
4022 | XCopyArea (s->display, pixmap, s->window, s->gc, | |
4023 | 0, 0, s->background_width, s->height, s->x, s->y); | |
4024 | XFreePixmap (s->display, pixmap); | |
4025 | } | |
4026 | else | |
4027 | x_draw_image_foreground (s); | |
b5210ea7 | 4028 | |
06a2c219 GM |
4029 | /* If we must draw a relief around the image, do it. */ |
4030 | if (s->img->relief | |
4031 | || s->hl == DRAW_IMAGE_RAISED | |
4032 | || s->hl == DRAW_IMAGE_SUNKEN) | |
4033 | x_draw_image_relief (s); | |
4034 | } | |
8c1a6a84 | 4035 | |
990ba854 | 4036 | |
06a2c219 | 4037 | /* Draw stretch glyph string S. */ |
dc43ef94 | 4038 | |
06a2c219 GM |
4039 | static void |
4040 | x_draw_stretch_glyph_string (s) | |
4041 | struct glyph_string *s; | |
4042 | { | |
4043 | xassert (s->first_glyph->type == STRETCH_GLYPH); | |
4044 | s->stippled_p = s->face->stipple != 0; | |
990ba854 | 4045 | |
06a2c219 GM |
4046 | if (s->hl == DRAW_CURSOR |
4047 | && !x_stretch_cursor_p) | |
4048 | { | |
4049 | /* If `x-stretch-block-cursor' is nil, don't draw a block cursor | |
4050 | as wide as the stretch glyph. */ | |
4051 | int width = min (CANON_X_UNIT (s->f), s->background_width); | |
990ba854 | 4052 | |
06a2c219 GM |
4053 | /* Draw cursor. */ |
4054 | x_draw_glyph_string_bg_rect (s, s->x, s->y, width, s->height); | |
0cdd0c9f | 4055 | |
06a2c219 GM |
4056 | /* Clear rest using the GC of the original non-cursor face. */ |
4057 | if (width < s->background_width) | |
4058 | { | |
4059 | GC gc = s->face->gc; | |
4060 | int x = s->x + width, y = s->y; | |
4061 | int w = s->background_width - width, h = s->height; | |
4062 | XRectangle r; | |
dc43ef94 | 4063 | |
06a2c219 GM |
4064 | x_get_glyph_string_clip_rect (s, &r); |
4065 | XSetClipRectangles (s->display, gc, 0, 0, &r, 1, Unsorted); | |
97210f4e | 4066 | |
06a2c219 GM |
4067 | if (s->face->stipple) |
4068 | { | |
4069 | /* Fill background with a stipple pattern. */ | |
4070 | XSetFillStyle (s->display, gc, FillOpaqueStippled); | |
4071 | XFillRectangle (s->display, s->window, gc, x, y, w, h); | |
4072 | XSetFillStyle (s->display, gc, FillSolid); | |
4073 | } | |
4074 | else | |
4075 | { | |
4076 | XGCValues xgcv; | |
4077 | XGetGCValues (s->display, gc, GCForeground | GCBackground, &xgcv); | |
4078 | XSetForeground (s->display, gc, xgcv.background); | |
4079 | XFillRectangle (s->display, s->window, gc, x, y, w, h); | |
4080 | XSetForeground (s->display, gc, xgcv.foreground); | |
4081 | } | |
4082 | } | |
4083 | } | |
4084 | else | |
4085 | x_draw_glyph_string_bg_rect (s, s->x, s->y, s->background_width, | |
4086 | s->height); | |
4087 | ||
4088 | s->background_filled_p = 1; | |
4089 | } | |
4090 | ||
4091 | ||
4092 | /* Draw glyph string S. */ | |
4093 | ||
4094 | static void | |
4095 | x_draw_glyph_string (s) | |
4096 | struct glyph_string *s; | |
4097 | { | |
4098 | /* If S draws into the background of its successor, draw the | |
4099 | background of the successor first so that S can draw into it. | |
4100 | This makes S->next use XDrawString instead of XDrawImageString. */ | |
66ac4b0e | 4101 | if (s->next && s->right_overhang && !s->for_overlaps_p) |
06a2c219 GM |
4102 | { |
4103 | xassert (s->next->img == NULL); | |
4104 | x_set_glyph_string_gc (s->next); | |
4105 | x_set_glyph_string_clipping (s->next); | |
4106 | x_draw_glyph_string_background (s->next, 1); | |
4107 | } | |
97210f4e | 4108 | |
06a2c219 GM |
4109 | /* Set up S->gc, set clipping and draw S. */ |
4110 | x_set_glyph_string_gc (s); | |
4111 | x_set_glyph_string_clipping (s); | |
4112 | ||
4113 | switch (s->first_glyph->type) | |
4114 | { | |
4115 | case IMAGE_GLYPH: | |
4116 | x_draw_image_glyph_string (s); | |
4117 | break; | |
4118 | ||
4119 | case STRETCH_GLYPH: | |
4120 | x_draw_stretch_glyph_string (s); | |
4121 | break; | |
4122 | ||
4123 | case CHAR_GLYPH: | |
66ac4b0e GM |
4124 | if (s->for_overlaps_p) |
4125 | s->background_filled_p = 1; | |
4126 | else | |
4127 | x_draw_glyph_string_background (s, 0); | |
06a2c219 GM |
4128 | x_draw_glyph_string_foreground (s); |
4129 | break; | |
4130 | ||
b4192550 KH |
4131 | case COMPOSITE_GLYPH: |
4132 | if (s->for_overlaps_p || s->gidx > 0) | |
4133 | s->background_filled_p = 1; | |
4134 | else | |
4135 | x_draw_glyph_string_background (s, 1); | |
4136 | x_draw_composite_glyph_string_foreground (s); | |
4137 | break; | |
4138 | ||
06a2c219 GM |
4139 | default: |
4140 | abort (); | |
4141 | } | |
4142 | ||
66ac4b0e | 4143 | if (!s->for_overlaps_p) |
06a2c219 | 4144 | { |
66ac4b0e GM |
4145 | /* Draw underline. */ |
4146 | if (s->face->underline_p) | |
4147 | { | |
4148 | unsigned long dy, h; | |
06a2c219 | 4149 | |
66ac4b0e GM |
4150 | if (!XGetFontProperty (s->font, XA_UNDERLINE_THICKNESS, &h)) |
4151 | h = 1; | |
4152 | if (!XGetFontProperty (s->font, XA_UNDERLINE_POSITION, &dy)) | |
4153 | dy = s->height - h; | |
06a2c219 | 4154 | |
66ac4b0e GM |
4155 | if (s->face->underline_defaulted_p) |
4156 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4157 | s->width, h); | |
4158 | else | |
4159 | { | |
4160 | XGCValues xgcv; | |
4161 | XGetGCValues (s->display, s->gc, GCForeground, &xgcv); | |
4162 | XSetForeground (s->display, s->gc, s->face->underline_color); | |
4163 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4164 | s->width, h); | |
4165 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4166 | } | |
dc6f92b8 | 4167 | } |
07e34cb0 | 4168 | |
66ac4b0e GM |
4169 | /* Draw overline. */ |
4170 | if (s->face->overline_p) | |
06a2c219 | 4171 | { |
66ac4b0e GM |
4172 | unsigned long dy = 0, h = 1; |
4173 | ||
4174 | if (s->face->overline_color_defaulted_p) | |
4175 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4176 | s->width, h); | |
4177 | else | |
4178 | { | |
4179 | XGCValues xgcv; | |
4180 | XGetGCValues (s->display, s->gc, GCForeground, &xgcv); | |
4181 | XSetForeground (s->display, s->gc, s->face->overline_color); | |
4182 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4183 | s->width, h); | |
4184 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4185 | } | |
06a2c219 | 4186 | } |
06a2c219 | 4187 | |
66ac4b0e GM |
4188 | /* Draw strike-through. */ |
4189 | if (s->face->strike_through_p) | |
06a2c219 | 4190 | { |
66ac4b0e GM |
4191 | unsigned long h = 1; |
4192 | unsigned long dy = (s->height - h) / 2; | |
4193 | ||
4194 | if (s->face->strike_through_color_defaulted_p) | |
4195 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4196 | s->width, h); | |
4197 | else | |
4198 | { | |
4199 | XGCValues xgcv; | |
4200 | XGetGCValues (s->display, s->gc, GCForeground, &xgcv); | |
4201 | XSetForeground (s->display, s->gc, s->face->strike_through_color); | |
4202 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4203 | s->width, h); | |
4204 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4205 | } | |
06a2c219 | 4206 | } |
06a2c219 | 4207 | |
66ac4b0e GM |
4208 | /* Draw relief. */ |
4209 | if (s->face->box != FACE_NO_BOX) | |
4210 | x_draw_glyph_string_box (s); | |
4211 | } | |
06a2c219 GM |
4212 | |
4213 | /* Reset clipping. */ | |
4214 | XSetClipMask (s->display, s->gc, None); | |
dc6f92b8 | 4215 | } |
07e34cb0 | 4216 | |
06a2c219 | 4217 | |
b4192550 KH |
4218 | static int x_fill_composite_glyph_string P_ ((struct glyph_string *, |
4219 | struct face **, int)); | |
06a2c219 | 4220 | |
06a2c219 | 4221 | |
209f68d9 GM |
4222 | /* Fill glyph string S with composition components specified by S->cmp. |
4223 | ||
b4192550 KH |
4224 | FACES is an array of faces for all components of this composition. |
4225 | S->gidx is the index of the first component for S. | |
4226 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
209f68d9 | 4227 | use its physical height for clipping. |
06a2c219 | 4228 | |
b4192550 | 4229 | Value is the index of a component not in S. */ |
07e34cb0 | 4230 | |
b4192550 KH |
4231 | static int |
4232 | x_fill_composite_glyph_string (s, faces, overlaps_p) | |
06a2c219 | 4233 | struct glyph_string *s; |
b4192550 | 4234 | struct face **faces; |
66ac4b0e | 4235 | int overlaps_p; |
07e34cb0 | 4236 | { |
b4192550 | 4237 | int i; |
06a2c219 | 4238 | |
b4192550 | 4239 | xassert (s); |
06a2c219 | 4240 | |
b4192550 | 4241 | s->for_overlaps_p = overlaps_p; |
06a2c219 | 4242 | |
b4192550 KH |
4243 | s->face = faces[s->gidx]; |
4244 | s->font = s->face->font; | |
4245 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
06a2c219 | 4246 | |
b4192550 KH |
4247 | /* For all glyphs of this composition, starting at the offset |
4248 | S->gidx, until we reach the end of the definition or encounter a | |
4249 | glyph that requires the different face, add it to S. */ | |
4250 | ++s->nchars; | |
4251 | for (i = s->gidx + 1; i < s->cmp->glyph_len && faces[i] == s->face; ++i) | |
4252 | ++s->nchars; | |
06a2c219 | 4253 | |
b4192550 KH |
4254 | /* All glyph strings for the same composition has the same width, |
4255 | i.e. the width set for the first component of the composition. */ | |
06a2c219 | 4256 | |
06a2c219 GM |
4257 | s->width = s->first_glyph->pixel_width; |
4258 | ||
4259 | /* If the specified font could not be loaded, use the frame's | |
4260 | default font, but record the fact that we couldn't load it in | |
4261 | the glyph string so that we can draw rectangles for the | |
4262 | characters of the glyph string. */ | |
4263 | if (s->font == NULL) | |
4264 | { | |
4265 | s->font_not_found_p = 1; | |
4266 | s->font = FRAME_FONT (s->f); | |
4267 | } | |
4268 | ||
4269 | /* Adjust base line for subscript/superscript text. */ | |
4270 | s->ybase += s->first_glyph->voffset; | |
4271 | ||
4272 | xassert (s->face && s->face->gc); | |
4273 | ||
4274 | /* This glyph string must always be drawn with 16-bit functions. */ | |
4275 | s->two_byte_p = 1; | |
b4192550 KH |
4276 | |
4277 | return s->gidx + s->nchars; | |
06a2c219 GM |
4278 | } |
4279 | ||
4280 | ||
209f68d9 GM |
4281 | /* Fill glyph string S from a sequence of character glyphs. |
4282 | ||
06a2c219 | 4283 | FACE_ID is the face id of the string. START is the index of the |
66ac4b0e GM |
4284 | first glyph to consider, END is the index of the last + 1. |
4285 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
209f68d9 | 4286 | use its physical height for clipping. |
66ac4b0e GM |
4287 | |
4288 | Value is the index of the first glyph not in S. */ | |
06a2c219 GM |
4289 | |
4290 | static int | |
66ac4b0e | 4291 | x_fill_glyph_string (s, face_id, start, end, overlaps_p) |
06a2c219 GM |
4292 | struct glyph_string *s; |
4293 | int face_id; | |
66ac4b0e | 4294 | int start, end, overlaps_p; |
06a2c219 GM |
4295 | { |
4296 | struct glyph *glyph, *last; | |
4297 | int voffset; | |
ee569018 | 4298 | int glyph_not_available_p; |
06a2c219 | 4299 | |
06a2c219 GM |
4300 | xassert (s->f == XFRAME (s->w->frame)); |
4301 | xassert (s->nchars == 0); | |
4302 | xassert (start >= 0 && end > start); | |
4303 | ||
66ac4b0e | 4304 | s->for_overlaps_p = overlaps_p, |
06a2c219 GM |
4305 | glyph = s->row->glyphs[s->area] + start; |
4306 | last = s->row->glyphs[s->area] + end; | |
4307 | voffset = glyph->voffset; | |
4308 | ||
ee569018 KH |
4309 | glyph_not_available_p = glyph->glyph_not_available_p; |
4310 | ||
06a2c219 GM |
4311 | while (glyph < last |
4312 | && glyph->type == CHAR_GLYPH | |
4313 | && glyph->voffset == voffset | |
ee569018 KH |
4314 | /* Same face id implies same font, nowadays. */ |
4315 | && glyph->face_id == face_id | |
4316 | && glyph->glyph_not_available_p == glyph_not_available_p) | |
06a2c219 | 4317 | { |
ee569018 KH |
4318 | int two_byte_p; |
4319 | ||
06a2c219 | 4320 | s->face = x_get_glyph_face_and_encoding (s->f, glyph, |
ee569018 KH |
4321 | s->char2b + s->nchars, |
4322 | &two_byte_p); | |
4323 | s->two_byte_p = two_byte_p; | |
06a2c219 GM |
4324 | ++s->nchars; |
4325 | xassert (s->nchars <= end - start); | |
4326 | s->width += glyph->pixel_width; | |
4327 | ++glyph; | |
4328 | } | |
4329 | ||
4330 | s->font = s->face->font; | |
4331 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
4332 | ||
4333 | /* If the specified font could not be loaded, use the frame's font, | |
4334 | but record the fact that we couldn't load it in | |
4335 | S->font_not_found_p so that we can draw rectangles for the | |
4336 | characters of the glyph string. */ | |
ee569018 | 4337 | if (s->font == NULL || glyph_not_available_p) |
06a2c219 GM |
4338 | { |
4339 | s->font_not_found_p = 1; | |
4340 | s->font = FRAME_FONT (s->f); | |
4341 | } | |
4342 | ||
4343 | /* Adjust base line for subscript/superscript text. */ | |
4344 | s->ybase += voffset; | |
66ac4b0e | 4345 | |
06a2c219 GM |
4346 | xassert (s->face && s->face->gc); |
4347 | return glyph - s->row->glyphs[s->area]; | |
07e34cb0 | 4348 | } |
dc6f92b8 | 4349 | |
06a2c219 GM |
4350 | |
4351 | /* Fill glyph string S from image glyph S->first_glyph. */ | |
dc6f92b8 | 4352 | |
dfcf069d | 4353 | static void |
06a2c219 GM |
4354 | x_fill_image_glyph_string (s) |
4355 | struct glyph_string *s; | |
4356 | { | |
4357 | xassert (s->first_glyph->type == IMAGE_GLYPH); | |
43d120d8 | 4358 | s->img = IMAGE_FROM_ID (s->f, s->first_glyph->u.img_id); |
06a2c219 | 4359 | xassert (s->img); |
43d120d8 | 4360 | s->face = FACE_FROM_ID (s->f, s->first_glyph->face_id); |
06a2c219 GM |
4361 | s->font = s->face->font; |
4362 | s->width = s->first_glyph->pixel_width; | |
4363 | ||
4364 | /* Adjust base line for subscript/superscript text. */ | |
4365 | s->ybase += s->first_glyph->voffset; | |
4366 | } | |
4367 | ||
4368 | ||
209f68d9 | 4369 | /* Fill glyph string S from a sequence of stretch glyphs. |
06a2c219 | 4370 | |
209f68d9 GM |
4371 | ROW is the glyph row in which the glyphs are found, AREA is the |
4372 | area within the row. START is the index of the first glyph to | |
4373 | consider, END is the index of the last + 1. | |
4374 | ||
4375 | Value is the index of the first glyph not in S. */ | |
4376 | ||
4377 | static int | |
4378 | x_fill_stretch_glyph_string (s, row, area, start, end) | |
06a2c219 | 4379 | struct glyph_string *s; |
209f68d9 GM |
4380 | struct glyph_row *row; |
4381 | enum glyph_row_area area; | |
4382 | int start, end; | |
06a2c219 | 4383 | { |
209f68d9 GM |
4384 | struct glyph *glyph, *last; |
4385 | int voffset, face_id; | |
4386 | ||
06a2c219 | 4387 | xassert (s->first_glyph->type == STRETCH_GLYPH); |
209f68d9 GM |
4388 | |
4389 | glyph = s->row->glyphs[s->area] + start; | |
4390 | last = s->row->glyphs[s->area] + end; | |
4391 | face_id = glyph->face_id; | |
4392 | s->face = FACE_FROM_ID (s->f, face_id); | |
06a2c219 | 4393 | s->font = s->face->font; |
209f68d9 GM |
4394 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); |
4395 | s->width = glyph->pixel_width; | |
4396 | voffset = glyph->voffset; | |
4397 | ||
4398 | for (++glyph; | |
4399 | (glyph < last | |
4400 | && glyph->type == STRETCH_GLYPH | |
4401 | && glyph->voffset == voffset | |
4402 | && glyph->face_id == face_id); | |
4403 | ++glyph) | |
4404 | s->width += glyph->pixel_width; | |
06a2c219 GM |
4405 | |
4406 | /* Adjust base line for subscript/superscript text. */ | |
209f68d9 GM |
4407 | s->ybase += voffset; |
4408 | ||
4409 | xassert (s->face && s->face->gc); | |
4410 | return glyph - s->row->glyphs[s->area]; | |
06a2c219 GM |
4411 | } |
4412 | ||
4413 | ||
4414 | /* Initialize glyph string S. CHAR2B is a suitably allocated vector | |
4415 | of XChar2b structures for S; it can't be allocated in | |
4416 | x_init_glyph_string because it must be allocated via `alloca'. W | |
4417 | is the window on which S is drawn. ROW and AREA are the glyph row | |
4418 | and area within the row from which S is constructed. START is the | |
4419 | index of the first glyph structure covered by S. HL is a | |
4420 | face-override for drawing S. */ | |
4421 | ||
4422 | static void | |
4423 | x_init_glyph_string (s, char2b, w, row, area, start, hl) | |
4424 | struct glyph_string *s; | |
4425 | XChar2b *char2b; | |
4426 | struct window *w; | |
4427 | struct glyph_row *row; | |
4428 | enum glyph_row_area area; | |
4429 | int start; | |
4430 | enum draw_glyphs_face hl; | |
4431 | { | |
4432 | bzero (s, sizeof *s); | |
4433 | s->w = w; | |
4434 | s->f = XFRAME (w->frame); | |
4435 | s->display = FRAME_X_DISPLAY (s->f); | |
4436 | s->window = FRAME_X_WINDOW (s->f); | |
4437 | s->char2b = char2b; | |
4438 | s->hl = hl; | |
4439 | s->row = row; | |
4440 | s->area = area; | |
4441 | s->first_glyph = row->glyphs[area] + start; | |
4442 | s->height = row->height; | |
4443 | s->y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
4444 | ||
9ea173e8 GM |
4445 | /* Display the internal border below the tool-bar window. */ |
4446 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
06a2c219 GM |
4447 | s->y -= s->f->output_data.x->internal_border_width; |
4448 | ||
4449 | s->ybase = s->y + row->ascent; | |
4450 | } | |
4451 | ||
4452 | ||
4453 | /* Set background width of glyph string S. START is the index of the | |
4454 | first glyph following S. LAST_X is the right-most x-position + 1 | |
4455 | in the drawing area. */ | |
4456 | ||
4457 | static INLINE void | |
4458 | x_set_glyph_string_background_width (s, start, last_x) | |
4459 | struct glyph_string *s; | |
4460 | int start; | |
4461 | int last_x; | |
4462 | { | |
4463 | /* If the face of this glyph string has to be drawn to the end of | |
4464 | the drawing area, set S->extends_to_end_of_line_p. */ | |
4465 | struct face *default_face = FACE_FROM_ID (s->f, DEFAULT_FACE_ID); | |
4466 | ||
4467 | if (start == s->row->used[s->area] | |
4468 | && s->hl == DRAW_NORMAL_TEXT | |
4469 | && ((s->area == TEXT_AREA && s->row->fill_line_p) | |
4470 | || s->face->background != default_face->background | |
4471 | || s->face->stipple != default_face->stipple)) | |
4472 | s->extends_to_end_of_line_p = 1; | |
4473 | ||
4474 | /* If S extends its face to the end of the line, set its | |
4475 | background_width to the distance to the right edge of the drawing | |
4476 | area. */ | |
4477 | if (s->extends_to_end_of_line_p) | |
1da3fd71 | 4478 | s->background_width = last_x - s->x + 1; |
06a2c219 GM |
4479 | else |
4480 | s->background_width = s->width; | |
4481 | } | |
4482 | ||
4483 | ||
4484 | /* Add a glyph string for a stretch glyph to the list of strings | |
4485 | between HEAD and TAIL. START is the index of the stretch glyph in | |
4486 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4487 | in that glyph row area. X is the current output position assigned | |
4488 | to the new glyph string constructed. HL overrides that face of the | |
4489 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4490 | is the right-most x-position of the drawing area. */ | |
4491 | ||
8abee2e1 DL |
4492 | /* SunOS 4 bundled cc, barfed on continuations in the arg lists here |
4493 | and below -- keep them on one line. */ | |
4494 | #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ | |
06a2c219 GM |
4495 | do \ |
4496 | { \ | |
4497 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4498 | x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \ | |
209f68d9 | 4499 | START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \ |
06a2c219 | 4500 | x_append_glyph_string (&HEAD, &TAIL, s); \ |
06a2c219 GM |
4501 | s->x = (X); \ |
4502 | } \ | |
4503 | while (0) | |
4504 | ||
4505 | ||
4506 | /* Add a glyph string for an image glyph to the list of strings | |
4507 | between HEAD and TAIL. START is the index of the image glyph in | |
4508 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4509 | in that glyph row area. X is the current output position assigned | |
4510 | to the new glyph string constructed. HL overrides that face of the | |
4511 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4512 | is the right-most x-position of the drawing area. */ | |
4513 | ||
8abee2e1 | 4514 | #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ |
06a2c219 GM |
4515 | do \ |
4516 | { \ | |
4517 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4518 | x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \ | |
4519 | x_fill_image_glyph_string (s); \ | |
4520 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
4521 | ++START; \ | |
4522 | s->x = (X); \ | |
4523 | } \ | |
4524 | while (0) | |
4525 | ||
4526 | ||
4527 | /* Add a glyph string for a sequence of character glyphs to the list | |
4528 | of strings between HEAD and TAIL. START is the index of the first | |
4529 | glyph in row area AREA of glyph row ROW that is part of the new | |
4530 | glyph string. END is the index of the last glyph in that glyph row | |
4531 | area. X is the current output position assigned to the new glyph | |
4532 | string constructed. HL overrides that face of the glyph; e.g. it | |
4533 | is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the | |
4534 | right-most x-position of the drawing area. */ | |
4535 | ||
8abee2e1 | 4536 | #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ |
06a2c219 GM |
4537 | do \ |
4538 | { \ | |
3e71d8f2 | 4539 | int c, face_id; \ |
06a2c219 GM |
4540 | XChar2b *char2b; \ |
4541 | \ | |
43d120d8 | 4542 | c = (ROW)->glyphs[AREA][START].u.ch; \ |
43d120d8 | 4543 | face_id = (ROW)->glyphs[AREA][START].face_id; \ |
06a2c219 | 4544 | \ |
b4192550 KH |
4545 | s = (struct glyph_string *) alloca (sizeof *s); \ |
4546 | char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \ | |
4547 | x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \ | |
4548 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
b4192550 KH |
4549 | s->x = (X); \ |
4550 | START = x_fill_glyph_string (s, face_id, START, END, \ | |
66ac4b0e | 4551 | OVERLAPS_P); \ |
06a2c219 GM |
4552 | } \ |
4553 | while (0) | |
4554 | ||
4555 | ||
b4192550 KH |
4556 | /* Add a glyph string for a composite sequence to the list of strings |
4557 | between HEAD and TAIL. START is the index of the first glyph in | |
4558 | row area AREA of glyph row ROW that is part of the new glyph | |
4559 | string. END is the index of the last glyph in that glyph row area. | |
4560 | X is the current output position assigned to the new glyph string | |
4561 | constructed. HL overrides that face of the glyph; e.g. it is | |
4562 | DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most | |
4563 | x-position of the drawing area. */ | |
4564 | ||
6c27ec25 | 4565 | #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ |
b4192550 | 4566 | do { \ |
43d120d8 KH |
4567 | int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \ |
4568 | int face_id = (ROW)->glyphs[AREA][START].face_id; \ | |
ee569018 | 4569 | struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \ |
b4192550 KH |
4570 | struct composition *cmp = composition_table[cmp_id]; \ |
4571 | int glyph_len = cmp->glyph_len; \ | |
4572 | XChar2b *char2b; \ | |
4573 | struct face **faces; \ | |
4574 | struct glyph_string *first_s = NULL; \ | |
4575 | int n; \ | |
4576 | \ | |
ee569018 | 4577 | base_face = base_face->ascii_face; \ |
b4192550 KH |
4578 | char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \ |
4579 | faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \ | |
4580 | /* At first, fill in `char2b' and `faces'. */ \ | |
4581 | for (n = 0; n < glyph_len; n++) \ | |
4582 | { \ | |
43d120d8 | 4583 | int c = COMPOSITION_GLYPH (cmp, n); \ |
ee569018 KH |
4584 | int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \ |
4585 | faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \ | |
4586 | x_get_char_face_and_encoding (XFRAME (w->frame), c, \ | |
4587 | this_face_id, char2b + n, 1); \ | |
b4192550 KH |
4588 | } \ |
4589 | \ | |
4590 | /* Make glyph_strings for each glyph sequence that is drawable by \ | |
4591 | the same face, and append them to HEAD/TAIL. */ \ | |
4592 | for (n = 0; n < cmp->glyph_len;) \ | |
4593 | { \ | |
4594 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4595 | x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \ | |
4596 | x_append_glyph_string (&(HEAD), &(TAIL), s); \ | |
4597 | s->cmp = cmp; \ | |
4598 | s->gidx = n; \ | |
b4192550 KH |
4599 | s->x = (X); \ |
4600 | \ | |
4601 | if (n == 0) \ | |
4602 | first_s = s; \ | |
4603 | \ | |
4604 | n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \ | |
4605 | } \ | |
4606 | \ | |
4607 | ++START; \ | |
4608 | s = first_s; \ | |
4609 | } while (0) | |
4610 | ||
4611 | ||
06a2c219 GM |
4612 | /* Build a list of glyph strings between HEAD and TAIL for the glyphs |
4613 | of AREA of glyph row ROW on window W between indices START and END. | |
4614 | HL overrides the face for drawing glyph strings, e.g. it is | |
4615 | DRAW_CURSOR to draw a cursor. X and LAST_X are start and end | |
4616 | x-positions of the drawing area. | |
4617 | ||
4618 | This is an ugly monster macro construct because we must use alloca | |
4619 | to allocate glyph strings (because x_draw_glyphs can be called | |
4620 | asynchronously). */ | |
4621 | ||
8abee2e1 | 4622 | #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ |
06a2c219 GM |
4623 | do \ |
4624 | { \ | |
4625 | HEAD = TAIL = NULL; \ | |
4626 | while (START < END) \ | |
4627 | { \ | |
4628 | struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \ | |
4629 | switch (first_glyph->type) \ | |
4630 | { \ | |
4631 | case CHAR_GLYPH: \ | |
4632 | BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \ | |
66ac4b0e GM |
4633 | TAIL, HL, X, LAST_X, \ |
4634 | OVERLAPS_P); \ | |
06a2c219 GM |
4635 | break; \ |
4636 | \ | |
b4192550 KH |
4637 | case COMPOSITE_GLYPH: \ |
4638 | BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \ | |
4639 | HEAD, TAIL, HL, X, LAST_X,\ | |
4640 | OVERLAPS_P); \ | |
4641 | break; \ | |
4642 | \ | |
06a2c219 GM |
4643 | case STRETCH_GLYPH: \ |
4644 | BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \ | |
4645 | HEAD, TAIL, HL, X, LAST_X); \ | |
4646 | break; \ | |
4647 | \ | |
4648 | case IMAGE_GLYPH: \ | |
4649 | BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \ | |
4650 | TAIL, HL, X, LAST_X); \ | |
4651 | break; \ | |
4652 | \ | |
4653 | default: \ | |
4654 | abort (); \ | |
4655 | } \ | |
4656 | \ | |
4657 | x_set_glyph_string_background_width (s, START, LAST_X); \ | |
4658 | (X) += s->width; \ | |
4659 | } \ | |
4660 | } \ | |
4661 | while (0) | |
4662 | ||
4663 | ||
4664 | /* Draw glyphs between START and END in AREA of ROW on window W, | |
4665 | starting at x-position X. X is relative to AREA in W. HL is a | |
4666 | face-override with the following meaning: | |
4667 | ||
4668 | DRAW_NORMAL_TEXT draw normally | |
4669 | DRAW_CURSOR draw in cursor face | |
4670 | DRAW_MOUSE_FACE draw in mouse face. | |
4671 | DRAW_INVERSE_VIDEO draw in mode line face | |
4672 | DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it | |
4673 | DRAW_IMAGE_RAISED draw an image with a raised relief around it | |
4674 | ||
4675 | If REAL_START is non-null, return in *REAL_START the real starting | |
4676 | position for display. This can be different from START in case | |
4677 | overlapping glyphs must be displayed. If REAL_END is non-null, | |
4678 | return in *REAL_END the real end position for display. This can be | |
4679 | different from END in case overlapping glyphs must be displayed. | |
4680 | ||
66ac4b0e GM |
4681 | If OVERLAPS_P is non-zero, draw only the foreground of characters |
4682 | and clip to the physical height of ROW. | |
4683 | ||
06a2c219 GM |
4684 | Value is the x-position reached, relative to AREA of W. */ |
4685 | ||
4686 | static int | |
66ac4b0e GM |
4687 | x_draw_glyphs (w, x, row, area, start, end, hl, real_start, real_end, |
4688 | overlaps_p) | |
06a2c219 GM |
4689 | struct window *w; |
4690 | int x; | |
4691 | struct glyph_row *row; | |
4692 | enum glyph_row_area area; | |
4693 | int start, end; | |
4694 | enum draw_glyphs_face hl; | |
4695 | int *real_start, *real_end; | |
66ac4b0e | 4696 | int overlaps_p; |
dc6f92b8 | 4697 | { |
06a2c219 GM |
4698 | struct glyph_string *head, *tail; |
4699 | struct glyph_string *s; | |
4700 | int last_x, area_width; | |
4701 | int x_reached; | |
4702 | int i, j; | |
4703 | ||
4704 | /* Let's rather be paranoid than getting a SEGV. */ | |
06a2c219 | 4705 | end = min (end, row->used[area]); |
a8710abf GM |
4706 | start = max (0, start); |
4707 | start = min (end, start); | |
06a2c219 GM |
4708 | if (real_start) |
4709 | *real_start = start; | |
4710 | if (real_end) | |
4711 | *real_end = end; | |
4712 | ||
4713 | /* Translate X to frame coordinates. Set last_x to the right | |
4714 | end of the drawing area. */ | |
4715 | if (row->full_width_p) | |
4716 | { | |
4717 | /* X is relative to the left edge of W, without scroll bars | |
4718 | or flag areas. */ | |
4719 | struct frame *f = XFRAME (w->frame); | |
110859fc | 4720 | /* int width = FRAME_FLAGS_AREA_WIDTH (f); */ |
06a2c219 | 4721 | int window_left_x = WINDOW_LEFT_MARGIN (w) * CANON_X_UNIT (f); |
dc6f92b8 | 4722 | |
06a2c219 GM |
4723 | x += window_left_x; |
4724 | area_width = XFASTINT (w->width) * CANON_X_UNIT (f); | |
4725 | last_x = window_left_x + area_width; | |
4726 | ||
4727 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
4728 | { | |
110859fc | 4729 | int width = FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); |
06a2c219 GM |
4730 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) |
4731 | last_x += width; | |
4732 | else | |
4733 | x -= width; | |
4734 | } | |
dc6f92b8 | 4735 | |
b9432a85 GM |
4736 | x += FRAME_INTERNAL_BORDER_WIDTH (f); |
4737 | last_x -= FRAME_INTERNAL_BORDER_WIDTH (f); | |
06a2c219 GM |
4738 | } |
4739 | else | |
dc6f92b8 | 4740 | { |
06a2c219 GM |
4741 | x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, x); |
4742 | area_width = window_box_width (w, area); | |
4743 | last_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, area_width); | |
dc6f92b8 JB |
4744 | } |
4745 | ||
06a2c219 GM |
4746 | /* Build a doubly-linked list of glyph_string structures between |
4747 | head and tail from what we have to draw. Note that the macro | |
4748 | BUILD_GLYPH_STRINGS will modify its start parameter. That's | |
4749 | the reason we use a separate variable `i'. */ | |
4750 | i = start; | |
66ac4b0e GM |
4751 | BUILD_GLYPH_STRINGS (w, row, area, i, end, head, tail, hl, x, last_x, |
4752 | overlaps_p); | |
06a2c219 GM |
4753 | if (tail) |
4754 | x_reached = tail->x + tail->background_width; | |
4755 | else | |
4756 | x_reached = x; | |
90e65f07 | 4757 | |
06a2c219 GM |
4758 | /* If there are any glyphs with lbearing < 0 or rbearing > width in |
4759 | the row, redraw some glyphs in front or following the glyph | |
4760 | strings built above. */ | |
a8710abf | 4761 | if (head && !overlaps_p && row->contains_overlapping_glyphs_p) |
06a2c219 GM |
4762 | { |
4763 | int dummy_x = 0; | |
4764 | struct glyph_string *h, *t; | |
4765 | ||
4766 | /* Compute overhangs for all glyph strings. */ | |
4767 | for (s = head; s; s = s->next) | |
4768 | x_compute_glyph_string_overhangs (s); | |
4769 | ||
4770 | /* Prepend glyph strings for glyphs in front of the first glyph | |
4771 | string that are overwritten because of the first glyph | |
4772 | string's left overhang. The background of all strings | |
4773 | prepended must be drawn because the first glyph string | |
4774 | draws over it. */ | |
4775 | i = x_left_overwritten (head); | |
4776 | if (i >= 0) | |
4777 | { | |
4778 | j = i; | |
4779 | BUILD_GLYPH_STRINGS (w, row, area, j, start, h, t, | |
66ac4b0e GM |
4780 | DRAW_NORMAL_TEXT, dummy_x, last_x, |
4781 | overlaps_p); | |
06a2c219 GM |
4782 | start = i; |
4783 | if (real_start) | |
4784 | *real_start = start; | |
4785 | x_compute_overhangs_and_x (t, head->x, 1); | |
4786 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
4787 | } | |
58769bee | 4788 | |
06a2c219 GM |
4789 | /* Prepend glyph strings for glyphs in front of the first glyph |
4790 | string that overwrite that glyph string because of their | |
4791 | right overhang. For these strings, only the foreground must | |
4792 | be drawn, because it draws over the glyph string at `head'. | |
4793 | The background must not be drawn because this would overwrite | |
4794 | right overhangs of preceding glyphs for which no glyph | |
4795 | strings exist. */ | |
4796 | i = x_left_overwriting (head); | |
4797 | if (i >= 0) | |
4798 | { | |
4799 | BUILD_GLYPH_STRINGS (w, row, area, i, start, h, t, | |
66ac4b0e GM |
4800 | DRAW_NORMAL_TEXT, dummy_x, last_x, |
4801 | overlaps_p); | |
06a2c219 GM |
4802 | for (s = h; s; s = s->next) |
4803 | s->background_filled_p = 1; | |
4804 | if (real_start) | |
4805 | *real_start = i; | |
4806 | x_compute_overhangs_and_x (t, head->x, 1); | |
4807 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
4808 | } | |
dbcb258a | 4809 | |
06a2c219 GM |
4810 | /* Append glyphs strings for glyphs following the last glyph |
4811 | string tail that are overwritten by tail. The background of | |
4812 | these strings has to be drawn because tail's foreground draws | |
4813 | over it. */ | |
4814 | i = x_right_overwritten (tail); | |
4815 | if (i >= 0) | |
4816 | { | |
4817 | BUILD_GLYPH_STRINGS (w, row, area, end, i, h, t, | |
66ac4b0e GM |
4818 | DRAW_NORMAL_TEXT, x, last_x, |
4819 | overlaps_p); | |
06a2c219 GM |
4820 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); |
4821 | x_append_glyph_string_lists (&head, &tail, h, t); | |
4822 | if (real_end) | |
4823 | *real_end = i; | |
4824 | } | |
dc6f92b8 | 4825 | |
06a2c219 GM |
4826 | /* Append glyph strings for glyphs following the last glyph |
4827 | string tail that overwrite tail. The foreground of such | |
4828 | glyphs has to be drawn because it writes into the background | |
4829 | of tail. The background must not be drawn because it could | |
4830 | paint over the foreground of following glyphs. */ | |
4831 | i = x_right_overwriting (tail); | |
4832 | if (i >= 0) | |
4833 | { | |
4834 | BUILD_GLYPH_STRINGS (w, row, area, end, i, h, t, | |
66ac4b0e GM |
4835 | DRAW_NORMAL_TEXT, x, last_x, |
4836 | overlaps_p); | |
06a2c219 GM |
4837 | for (s = h; s; s = s->next) |
4838 | s->background_filled_p = 1; | |
4839 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); | |
4840 | x_append_glyph_string_lists (&head, &tail, h, t); | |
4841 | if (real_end) | |
4842 | *real_end = i; | |
4843 | } | |
4844 | } | |
58769bee | 4845 | |
06a2c219 GM |
4846 | /* Draw all strings. */ |
4847 | for (s = head; s; s = s->next) | |
4848 | x_draw_glyph_string (s); | |
dc6f92b8 | 4849 | |
06a2c219 GM |
4850 | /* Value is the x-position up to which drawn, relative to AREA of W. |
4851 | This doesn't include parts drawn because of overhangs. */ | |
4852 | x_reached = FRAME_TO_WINDOW_PIXEL_X (w, x_reached); | |
4853 | if (!row->full_width_p) | |
4854 | { | |
4855 | if (area > LEFT_MARGIN_AREA) | |
4856 | x_reached -= window_box_width (w, LEFT_MARGIN_AREA); | |
4857 | if (area > TEXT_AREA) | |
4858 | x_reached -= window_box_width (w, TEXT_AREA); | |
4859 | } | |
a8710abf | 4860 | |
06a2c219 GM |
4861 | return x_reached; |
4862 | } | |
dc6f92b8 | 4863 | |
dc6f92b8 | 4864 | |
66ac4b0e GM |
4865 | /* Fix the display of area AREA of overlapping row ROW in window W. */ |
4866 | ||
4867 | static void | |
4868 | x_fix_overlapping_area (w, row, area) | |
4869 | struct window *w; | |
4870 | struct glyph_row *row; | |
4871 | enum glyph_row_area area; | |
4872 | { | |
4873 | int i, x; | |
4874 | ||
4875 | BLOCK_INPUT; | |
4876 | ||
4877 | if (area == LEFT_MARGIN_AREA) | |
4878 | x = 0; | |
4879 | else if (area == TEXT_AREA) | |
4880 | x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
4881 | else | |
4882 | x = (window_box_width (w, LEFT_MARGIN_AREA) | |
4883 | + window_box_width (w, TEXT_AREA)); | |
4884 | ||
4885 | for (i = 0; i < row->used[area];) | |
4886 | { | |
4887 | if (row->glyphs[area][i].overlaps_vertically_p) | |
4888 | { | |
4889 | int start = i, start_x = x; | |
4890 | ||
4891 | do | |
4892 | { | |
4893 | x += row->glyphs[area][i].pixel_width; | |
4894 | ++i; | |
4895 | } | |
4896 | while (i < row->used[area] | |
4897 | && row->glyphs[area][i].overlaps_vertically_p); | |
4898 | ||
4899 | x_draw_glyphs (w, start_x, row, area, start, i, | |
4900 | (row->inverse_p | |
4901 | ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT), | |
4902 | NULL, NULL, 1); | |
4903 | } | |
4904 | else | |
4905 | { | |
4906 | x += row->glyphs[area][i].pixel_width; | |
4907 | ++i; | |
4908 | } | |
4909 | } | |
4910 | ||
4911 | UNBLOCK_INPUT; | |
4912 | } | |
4913 | ||
4914 | ||
06a2c219 GM |
4915 | /* Output LEN glyphs starting at START at the nominal cursor position. |
4916 | Advance the nominal cursor over the text. The global variable | |
4917 | updated_window contains the window being updated, updated_row is | |
4918 | the glyph row being updated, and updated_area is the area of that | |
4919 | row being updated. */ | |
dc6f92b8 | 4920 | |
06a2c219 GM |
4921 | static void |
4922 | x_write_glyphs (start, len) | |
4923 | struct glyph *start; | |
4924 | int len; | |
4925 | { | |
4926 | int x, hpos, real_start, real_end; | |
d9cdbb3d | 4927 | |
06a2c219 | 4928 | xassert (updated_window && updated_row); |
dc6f92b8 | 4929 | BLOCK_INPUT; |
06a2c219 GM |
4930 | |
4931 | /* Write glyphs. */ | |
dc6f92b8 | 4932 | |
06a2c219 GM |
4933 | hpos = start - updated_row->glyphs[updated_area]; |
4934 | x = x_draw_glyphs (updated_window, output_cursor.x, | |
4935 | updated_row, updated_area, | |
4936 | hpos, hpos + len, | |
4937 | (updated_row->inverse_p | |
4938 | ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT), | |
66ac4b0e | 4939 | &real_start, &real_end, 0); |
b30ec466 | 4940 | |
06a2c219 GM |
4941 | /* If we drew over the cursor, note that it is not visible any more. */ |
4942 | note_overwritten_text_cursor (updated_window, real_start, | |
4943 | real_end - real_start); | |
dc6f92b8 JB |
4944 | |
4945 | UNBLOCK_INPUT; | |
06a2c219 GM |
4946 | |
4947 | /* Advance the output cursor. */ | |
4948 | output_cursor.hpos += len; | |
4949 | output_cursor.x = x; | |
dc6f92b8 JB |
4950 | } |
4951 | ||
0cdd0c9f | 4952 | |
06a2c219 | 4953 | /* Insert LEN glyphs from START at the nominal cursor position. */ |
0cdd0c9f | 4954 | |
06a2c219 GM |
4955 | static void |
4956 | x_insert_glyphs (start, len) | |
4957 | struct glyph *start; | |
4958 | register int len; | |
4959 | { | |
4960 | struct frame *f; | |
4961 | struct window *w; | |
4962 | int line_height, shift_by_width, shifted_region_width; | |
4963 | struct glyph_row *row; | |
4964 | struct glyph *glyph; | |
4965 | int frame_x, frame_y, hpos, real_start, real_end; | |
58769bee | 4966 | |
06a2c219 | 4967 | xassert (updated_window && updated_row); |
0cdd0c9f | 4968 | BLOCK_INPUT; |
06a2c219 GM |
4969 | w = updated_window; |
4970 | f = XFRAME (WINDOW_FRAME (w)); | |
4971 | ||
4972 | /* Get the height of the line we are in. */ | |
4973 | row = updated_row; | |
4974 | line_height = row->height; | |
4975 | ||
4976 | /* Get the width of the glyphs to insert. */ | |
4977 | shift_by_width = 0; | |
4978 | for (glyph = start; glyph < start + len; ++glyph) | |
4979 | shift_by_width += glyph->pixel_width; | |
4980 | ||
4981 | /* Get the width of the region to shift right. */ | |
4982 | shifted_region_width = (window_box_width (w, updated_area) | |
4983 | - output_cursor.x | |
4984 | - shift_by_width); | |
4985 | ||
4986 | /* Shift right. */ | |
4987 | frame_x = WINDOW_TO_FRAME_PIXEL_X (w, output_cursor.x); | |
4988 | frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y); | |
4989 | XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), FRAME_X_WINDOW (f), | |
4990 | f->output_data.x->normal_gc, | |
4991 | frame_x, frame_y, | |
4992 | shifted_region_width, line_height, | |
4993 | frame_x + shift_by_width, frame_y); | |
4994 | ||
4995 | /* Write the glyphs. */ | |
4996 | hpos = start - row->glyphs[updated_area]; | |
4997 | x_draw_glyphs (w, output_cursor.x, row, updated_area, hpos, hpos + len, | |
66ac4b0e | 4998 | DRAW_NORMAL_TEXT, &real_start, &real_end, 0); |
06a2c219 GM |
4999 | note_overwritten_text_cursor (w, real_start, real_end - real_start); |
5000 | ||
5001 | /* Advance the output cursor. */ | |
5002 | output_cursor.hpos += len; | |
5003 | output_cursor.x += shift_by_width; | |
0cdd0c9f RS |
5004 | UNBLOCK_INPUT; |
5005 | } | |
0cdd0c9f | 5006 | |
0cdd0c9f | 5007 | |
06a2c219 GM |
5008 | /* Delete N glyphs at the nominal cursor position. Not implemented |
5009 | for X frames. */ | |
c83febd7 RS |
5010 | |
5011 | static void | |
06a2c219 GM |
5012 | x_delete_glyphs (n) |
5013 | register int n; | |
c83febd7 | 5014 | { |
06a2c219 | 5015 | abort (); |
c83febd7 RS |
5016 | } |
5017 | ||
0cdd0c9f | 5018 | |
06a2c219 GM |
5019 | /* Erase the current text line from the nominal cursor position |
5020 | (inclusive) to pixel column TO_X (exclusive). The idea is that | |
5021 | everything from TO_X onward is already erased. | |
5022 | ||
5023 | TO_X is a pixel position relative to updated_area of | |
5024 | updated_window. TO_X == -1 means clear to the end of this area. */ | |
dc6f92b8 | 5025 | |
06a2c219 GM |
5026 | static void |
5027 | x_clear_end_of_line (to_x) | |
5028 | int to_x; | |
5029 | { | |
5030 | struct frame *f; | |
5031 | struct window *w = updated_window; | |
5032 | int max_x, min_y, max_y; | |
5033 | int from_x, from_y, to_y; | |
5034 | ||
5035 | xassert (updated_window && updated_row); | |
5036 | f = XFRAME (w->frame); | |
5037 | ||
5038 | if (updated_row->full_width_p) | |
5039 | { | |
5040 | max_x = XFASTINT (w->width) * CANON_X_UNIT (f); | |
5041 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f) | |
5042 | && !w->pseudo_window_p) | |
5043 | max_x += FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); | |
0cdd0c9f | 5044 | } |
06a2c219 GM |
5045 | else |
5046 | max_x = window_box_width (w, updated_area); | |
5047 | max_y = window_text_bottom_y (w); | |
dc6f92b8 | 5048 | |
06a2c219 GM |
5049 | /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end |
5050 | of window. For TO_X > 0, truncate to end of drawing area. */ | |
5051 | if (to_x == 0) | |
5052 | return; | |
5053 | else if (to_x < 0) | |
5054 | to_x = max_x; | |
5055 | else | |
5056 | to_x = min (to_x, max_x); | |
dbc4e1c1 | 5057 | |
06a2c219 GM |
5058 | to_y = min (max_y, output_cursor.y + updated_row->height); |
5059 | ||
5060 | /* Notice if the cursor will be cleared by this operation. */ | |
5061 | if (!updated_row->full_width_p) | |
5062 | note_overwritten_text_cursor (w, output_cursor.hpos, -1); | |
dbc4e1c1 | 5063 | |
06a2c219 GM |
5064 | from_x = output_cursor.x; |
5065 | ||
5066 | /* Translate to frame coordinates. */ | |
5067 | if (updated_row->full_width_p) | |
5068 | { | |
5069 | from_x = WINDOW_TO_FRAME_PIXEL_X (w, from_x); | |
5070 | to_x = WINDOW_TO_FRAME_PIXEL_X (w, to_x); | |
5071 | } | |
0cdd0c9f RS |
5072 | else |
5073 | { | |
06a2c219 GM |
5074 | from_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, from_x); |
5075 | to_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, to_x); | |
5076 | } | |
5077 | ||
045dee35 | 5078 | min_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); |
06a2c219 GM |
5079 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, max (min_y, output_cursor.y)); |
5080 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, to_y); | |
5081 | ||
5082 | /* Prevent inadvertently clearing to end of the X window. */ | |
5083 | if (to_x > from_x && to_y > from_y) | |
5084 | { | |
5085 | BLOCK_INPUT; | |
5086 | XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
5087 | from_x, from_y, to_x - from_x, to_y - from_y, | |
5088 | False); | |
5089 | UNBLOCK_INPUT; | |
0cdd0c9f | 5090 | } |
0cdd0c9f | 5091 | } |
dbc4e1c1 | 5092 | |
0cdd0c9f | 5093 | |
06a2c219 | 5094 | /* Clear entire frame. If updating_frame is non-null, clear that |
b86bd3dd | 5095 | frame. Otherwise clear the selected frame. */ |
06a2c219 GM |
5096 | |
5097 | static void | |
5098 | x_clear_frame () | |
0cdd0c9f | 5099 | { |
06a2c219 | 5100 | struct frame *f; |
0cdd0c9f | 5101 | |
06a2c219 GM |
5102 | if (updating_frame) |
5103 | f = updating_frame; | |
0cdd0c9f | 5104 | else |
b86bd3dd | 5105 | f = SELECTED_FRAME (); |
58769bee | 5106 | |
06a2c219 GM |
5107 | /* Clearing the frame will erase any cursor, so mark them all as no |
5108 | longer visible. */ | |
5109 | mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
5110 | output_cursor.hpos = output_cursor.vpos = 0; | |
5111 | output_cursor.x = -1; | |
5112 | ||
5113 | /* We don't set the output cursor here because there will always | |
5114 | follow an explicit cursor_to. */ | |
5115 | BLOCK_INPUT; | |
5116 | XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); | |
5117 | ||
5118 | /* We have to clear the scroll bars, too. If we have changed | |
5119 | colors or something like that, then they should be notified. */ | |
5120 | x_scroll_bar_clear (f); | |
0cdd0c9f | 5121 | |
06a2c219 GM |
5122 | XFlush (FRAME_X_DISPLAY (f)); |
5123 | UNBLOCK_INPUT; | |
dc6f92b8 | 5124 | } |
06a2c219 GM |
5125 | |
5126 | ||
dc6f92b8 | 5127 | \f |
dbc4e1c1 JB |
5128 | /* Invert the middle quarter of the frame for .15 sec. */ |
5129 | ||
06a2c219 GM |
5130 | /* We use the select system call to do the waiting, so we have to make |
5131 | sure it's available. If it isn't, we just won't do visual bells. */ | |
5132 | ||
dbc4e1c1 JB |
5133 | #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) |
5134 | ||
06a2c219 GM |
5135 | |
5136 | /* Subtract the `struct timeval' values X and Y, storing the result in | |
5137 | *RESULT. Return 1 if the difference is negative, otherwise 0. */ | |
dbc4e1c1 JB |
5138 | |
5139 | static int | |
5140 | timeval_subtract (result, x, y) | |
5141 | struct timeval *result, x, y; | |
5142 | { | |
06a2c219 GM |
5143 | /* Perform the carry for the later subtraction by updating y. This |
5144 | is safer because on some systems the tv_sec member is unsigned. */ | |
dbc4e1c1 JB |
5145 | if (x.tv_usec < y.tv_usec) |
5146 | { | |
5147 | int nsec = (y.tv_usec - x.tv_usec) / 1000000 + 1; | |
5148 | y.tv_usec -= 1000000 * nsec; | |
5149 | y.tv_sec += nsec; | |
5150 | } | |
06a2c219 | 5151 | |
dbc4e1c1 JB |
5152 | if (x.tv_usec - y.tv_usec > 1000000) |
5153 | { | |
5154 | int nsec = (y.tv_usec - x.tv_usec) / 1000000; | |
5155 | y.tv_usec += 1000000 * nsec; | |
5156 | y.tv_sec -= nsec; | |
5157 | } | |
5158 | ||
06a2c219 GM |
5159 | /* Compute the time remaining to wait. tv_usec is certainly |
5160 | positive. */ | |
dbc4e1c1 JB |
5161 | result->tv_sec = x.tv_sec - y.tv_sec; |
5162 | result->tv_usec = x.tv_usec - y.tv_usec; | |
5163 | ||
06a2c219 GM |
5164 | /* Return indication of whether the result should be considered |
5165 | negative. */ | |
dbc4e1c1 JB |
5166 | return x.tv_sec < y.tv_sec; |
5167 | } | |
dc6f92b8 | 5168 | |
dfcf069d | 5169 | void |
f676886a JB |
5170 | XTflash (f) |
5171 | struct frame *f; | |
dc6f92b8 | 5172 | { |
dbc4e1c1 | 5173 | BLOCK_INPUT; |
dc6f92b8 | 5174 | |
dbc4e1c1 JB |
5175 | { |
5176 | GC gc; | |
dc6f92b8 | 5177 | |
06a2c219 GM |
5178 | /* Create a GC that will use the GXxor function to flip foreground |
5179 | pixels into background pixels. */ | |
dbc4e1c1 JB |
5180 | { |
5181 | XGCValues values; | |
dc6f92b8 | 5182 | |
dbc4e1c1 | 5183 | values.function = GXxor; |
7556890b RS |
5184 | values.foreground = (f->output_data.x->foreground_pixel |
5185 | ^ f->output_data.x->background_pixel); | |
58769bee | 5186 | |
334208b7 | 5187 | gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
dbc4e1c1 JB |
5188 | GCFunction | GCForeground, &values); |
5189 | } | |
dc6f92b8 | 5190 | |
dbc4e1c1 | 5191 | { |
e84e14c3 RS |
5192 | /* Get the height not including a menu bar widget. */ |
5193 | int height = CHAR_TO_PIXEL_HEIGHT (f, FRAME_HEIGHT (f)); | |
5194 | /* Height of each line to flash. */ | |
5195 | int flash_height = FRAME_LINE_HEIGHT (f); | |
5196 | /* These will be the left and right margins of the rectangles. */ | |
5197 | int flash_left = FRAME_INTERNAL_BORDER_WIDTH (f); | |
5198 | int flash_right = PIXEL_WIDTH (f) - FRAME_INTERNAL_BORDER_WIDTH (f); | |
5199 | ||
5200 | int width; | |
5201 | ||
5202 | /* Don't flash the area between a scroll bar and the frame | |
5203 | edge it is next to. */ | |
5204 | switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f)) | |
5205 | { | |
5206 | case vertical_scroll_bar_left: | |
5207 | flash_left += VERTICAL_SCROLL_BAR_WIDTH_TRIM; | |
5208 | break; | |
5209 | ||
5210 | case vertical_scroll_bar_right: | |
5211 | flash_right -= VERTICAL_SCROLL_BAR_WIDTH_TRIM; | |
5212 | break; | |
06a2c219 GM |
5213 | |
5214 | default: | |
5215 | break; | |
e84e14c3 RS |
5216 | } |
5217 | ||
5218 | width = flash_right - flash_left; | |
5219 | ||
5220 | /* If window is tall, flash top and bottom line. */ | |
5221 | if (height > 3 * FRAME_LINE_HEIGHT (f)) | |
5222 | { | |
5223 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
06a2c219 GM |
5224 | flash_left, |
5225 | (FRAME_INTERNAL_BORDER_WIDTH (f) | |
9ea173e8 | 5226 | + FRAME_TOOL_BAR_LINES (f) * CANON_Y_UNIT (f)), |
e84e14c3 RS |
5227 | width, flash_height); |
5228 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
5229 | flash_left, | |
5230 | (height - flash_height | |
5231 | - FRAME_INTERNAL_BORDER_WIDTH (f)), | |
5232 | width, flash_height); | |
5233 | } | |
5234 | else | |
5235 | /* If it is short, flash it all. */ | |
5236 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
5237 | flash_left, FRAME_INTERNAL_BORDER_WIDTH (f), | |
5238 | width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); | |
dc6f92b8 | 5239 | |
06a2c219 | 5240 | x_flush (f); |
dc6f92b8 | 5241 | |
dbc4e1c1 | 5242 | { |
06a2c219 | 5243 | struct timeval wakeup; |
dc6f92b8 | 5244 | |
66c30ea1 | 5245 | EMACS_GET_TIME (wakeup); |
dc6f92b8 | 5246 | |
dbc4e1c1 JB |
5247 | /* Compute time to wait until, propagating carry from usecs. */ |
5248 | wakeup.tv_usec += 150000; | |
5249 | wakeup.tv_sec += (wakeup.tv_usec / 1000000); | |
5250 | wakeup.tv_usec %= 1000000; | |
5251 | ||
5252 | /* Keep waiting until past the time wakeup. */ | |
5253 | while (1) | |
5254 | { | |
5255 | struct timeval timeout; | |
5256 | ||
66c30ea1 | 5257 | EMACS_GET_TIME (timeout); |
dbc4e1c1 JB |
5258 | |
5259 | /* In effect, timeout = wakeup - timeout. | |
5260 | Break if result would be negative. */ | |
5261 | if (timeval_subtract (&timeout, wakeup, timeout)) | |
5262 | break; | |
5263 | ||
5264 | /* Try to wait that long--but we might wake up sooner. */ | |
c32cdd9a | 5265 | select (0, NULL, NULL, NULL, &timeout); |
dbc4e1c1 JB |
5266 | } |
5267 | } | |
58769bee | 5268 | |
e84e14c3 RS |
5269 | /* If window is tall, flash top and bottom line. */ |
5270 | if (height > 3 * FRAME_LINE_HEIGHT (f)) | |
5271 | { | |
5272 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
06a2c219 GM |
5273 | flash_left, |
5274 | (FRAME_INTERNAL_BORDER_WIDTH (f) | |
9ea173e8 | 5275 | + FRAME_TOOL_BAR_LINES (f) * CANON_Y_UNIT (f)), |
e84e14c3 RS |
5276 | width, flash_height); |
5277 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
5278 | flash_left, | |
5279 | (height - flash_height | |
5280 | - FRAME_INTERNAL_BORDER_WIDTH (f)), | |
5281 | width, flash_height); | |
5282 | } | |
5283 | else | |
5284 | /* If it is short, flash it all. */ | |
5285 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
5286 | flash_left, FRAME_INTERNAL_BORDER_WIDTH (f), | |
5287 | width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); | |
5288 | ||
334208b7 | 5289 | XFreeGC (FRAME_X_DISPLAY (f), gc); |
06a2c219 | 5290 | x_flush (f); |
dc6f92b8 | 5291 | } |
dbc4e1c1 JB |
5292 | } |
5293 | ||
5294 | UNBLOCK_INPUT; | |
dc6f92b8 JB |
5295 | } |
5296 | ||
06a2c219 | 5297 | #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */ |
dbc4e1c1 JB |
5298 | |
5299 | ||
dc6f92b8 JB |
5300 | /* Make audible bell. */ |
5301 | ||
dfcf069d | 5302 | void |
dc6f92b8 JB |
5303 | XTring_bell () |
5304 | { | |
b86bd3dd GM |
5305 | struct frame *f = SELECTED_FRAME (); |
5306 | ||
5307 | if (FRAME_X_DISPLAY (f)) | |
5308 | { | |
dbc4e1c1 | 5309 | #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) |
b86bd3dd GM |
5310 | if (visible_bell) |
5311 | XTflash (f); | |
5312 | else | |
dbc4e1c1 | 5313 | #endif |
b86bd3dd GM |
5314 | { |
5315 | BLOCK_INPUT; | |
5316 | XBell (FRAME_X_DISPLAY (f), 0); | |
5317 | XFlush (FRAME_X_DISPLAY (f)); | |
5318 | UNBLOCK_INPUT; | |
5319 | } | |
dc6f92b8 JB |
5320 | } |
5321 | } | |
06a2c219 | 5322 | |
dc6f92b8 | 5323 | \f |
06a2c219 GM |
5324 | /* Specify how many text lines, from the top of the window, |
5325 | should be affected by insert-lines and delete-lines operations. | |
5326 | This, and those operations, are used only within an update | |
5327 | that is bounded by calls to x_update_begin and x_update_end. */ | |
dc6f92b8 | 5328 | |
dfcf069d | 5329 | static void |
06a2c219 GM |
5330 | XTset_terminal_window (n) |
5331 | register int n; | |
dc6f92b8 | 5332 | { |
06a2c219 | 5333 | /* This function intentionally left blank. */ |
dc6f92b8 JB |
5334 | } |
5335 | ||
06a2c219 GM |
5336 | |
5337 | \f | |
5338 | /*********************************************************************** | |
5339 | Line Dance | |
5340 | ***********************************************************************/ | |
5341 | ||
5342 | /* Perform an insert-lines or delete-lines operation, inserting N | |
5343 | lines or deleting -N lines at vertical position VPOS. */ | |
5344 | ||
dfcf069d | 5345 | static void |
06a2c219 GM |
5346 | x_ins_del_lines (vpos, n) |
5347 | int vpos, n; | |
dc6f92b8 JB |
5348 | { |
5349 | abort (); | |
5350 | } | |
06a2c219 GM |
5351 | |
5352 | ||
5353 | /* Scroll part of the display as described by RUN. */ | |
dc6f92b8 | 5354 | |
dfcf069d | 5355 | static void |
06a2c219 GM |
5356 | x_scroll_run (w, run) |
5357 | struct window *w; | |
5358 | struct run *run; | |
dc6f92b8 | 5359 | { |
06a2c219 GM |
5360 | struct frame *f = XFRAME (w->frame); |
5361 | int x, y, width, height, from_y, to_y, bottom_y; | |
5362 | ||
5363 | /* Get frame-relative bounding box of the text display area of W, | |
5364 | without mode lines. Include in this box the flags areas to the | |
5365 | left and right of W. */ | |
5366 | window_box (w, -1, &x, &y, &width, &height); | |
110859fc GM |
5367 | width += FRAME_X_FLAGS_AREA_WIDTH (f); |
5368 | x -= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f); | |
06a2c219 GM |
5369 | |
5370 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->current_y); | |
5371 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->desired_y); | |
5372 | bottom_y = y + height; | |
dc6f92b8 | 5373 | |
06a2c219 GM |
5374 | if (to_y < from_y) |
5375 | { | |
5376 | /* Scrolling up. Make sure we don't copy part of the mode | |
5377 | line at the bottom. */ | |
5378 | if (from_y + run->height > bottom_y) | |
5379 | height = bottom_y - from_y; | |
5380 | else | |
5381 | height = run->height; | |
5382 | } | |
dc6f92b8 | 5383 | else |
06a2c219 GM |
5384 | { |
5385 | /* Scolling down. Make sure we don't copy over the mode line. | |
5386 | at the bottom. */ | |
5387 | if (to_y + run->height > bottom_y) | |
5388 | height = bottom_y - to_y; | |
5389 | else | |
5390 | height = run->height; | |
5391 | } | |
7a13e894 | 5392 | |
06a2c219 GM |
5393 | BLOCK_INPUT; |
5394 | ||
5395 | /* Cursor off. Will be switched on again in x_update_window_end. */ | |
5396 | updated_window = w; | |
5397 | x_clear_cursor (w); | |
5398 | ||
5399 | XCopyArea (FRAME_X_DISPLAY (f), | |
5400 | FRAME_X_WINDOW (f), FRAME_X_WINDOW (f), | |
5401 | f->output_data.x->normal_gc, | |
5402 | x, from_y, | |
5403 | width, height, | |
5404 | x, to_y); | |
5405 | ||
5406 | UNBLOCK_INPUT; | |
5407 | } | |
dc6f92b8 | 5408 | |
dc6f92b8 | 5409 | |
06a2c219 GM |
5410 | \f |
5411 | /*********************************************************************** | |
5412 | Exposure Events | |
5413 | ***********************************************************************/ | |
5414 | ||
5415 | /* Redisplay an exposed area of frame F. X and Y are the upper-left | |
5416 | corner of the exposed rectangle. W and H are width and height of | |
5417 | the exposed area. All are pixel values. W or H zero means redraw | |
5418 | the entire frame. */ | |
dc6f92b8 | 5419 | |
06a2c219 GM |
5420 | static void |
5421 | expose_frame (f, x, y, w, h) | |
5422 | struct frame *f; | |
5423 | int x, y, w, h; | |
dc6f92b8 | 5424 | { |
06a2c219 | 5425 | XRectangle r; |
dc6f92b8 | 5426 | |
06a2c219 | 5427 | TRACE ((stderr, "expose_frame ")); |
dc6f92b8 | 5428 | |
06a2c219 GM |
5429 | /* No need to redraw if frame will be redrawn soon. */ |
5430 | if (FRAME_GARBAGED_P (f)) | |
dc6f92b8 | 5431 | { |
06a2c219 GM |
5432 | TRACE ((stderr, " garbaged\n")); |
5433 | return; | |
5434 | } | |
5435 | ||
5436 | /* If basic faces haven't been realized yet, there is no point in | |
5437 | trying to redraw anything. This can happen when we get an expose | |
5438 | event while Emacs is starting, e.g. by moving another window. */ | |
5439 | if (FRAME_FACE_CACHE (f) == NULL | |
5440 | || FRAME_FACE_CACHE (f)->used < BASIC_FACE_ID_SENTINEL) | |
5441 | { | |
5442 | TRACE ((stderr, " no faces\n")); | |
5443 | return; | |
58769bee | 5444 | } |
06a2c219 GM |
5445 | |
5446 | if (w == 0 || h == 0) | |
58769bee | 5447 | { |
06a2c219 GM |
5448 | r.x = r.y = 0; |
5449 | r.width = CANON_X_UNIT (f) * f->width; | |
5450 | r.height = CANON_Y_UNIT (f) * f->height; | |
dc6f92b8 JB |
5451 | } |
5452 | else | |
5453 | { | |
06a2c219 GM |
5454 | r.x = x; |
5455 | r.y = y; | |
5456 | r.width = w; | |
5457 | r.height = h; | |
5458 | } | |
5459 | ||
5460 | TRACE ((stderr, "(%d, %d, %d, %d)\n", r.x, r.y, r.width, r.height)); | |
5461 | expose_window_tree (XWINDOW (f->root_window), &r); | |
5462 | ||
9ea173e8 | 5463 | if (WINDOWP (f->tool_bar_window)) |
06a2c219 | 5464 | { |
9ea173e8 | 5465 | struct window *w = XWINDOW (f->tool_bar_window); |
06a2c219 GM |
5466 | XRectangle window_rect; |
5467 | XRectangle intersection_rect; | |
5468 | int window_x, window_y, window_width, window_height; | |
5469 | ||
5470 | ||
5471 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); | |
5472 | window_rect.x = window_x; | |
5473 | window_rect.y = window_y; | |
5474 | window_rect.width = window_width; | |
5475 | window_rect.height = window_height; | |
5476 | ||
5477 | if (x_intersect_rectangles (&r, &window_rect, &intersection_rect)) | |
5478 | expose_window (w, &intersection_rect); | |
5479 | } | |
5480 | ||
5481 | #ifndef USE_X_TOOLKIT | |
5482 | if (WINDOWP (f->menu_bar_window)) | |
5483 | { | |
5484 | struct window *w = XWINDOW (f->menu_bar_window); | |
5485 | XRectangle window_rect; | |
5486 | XRectangle intersection_rect; | |
5487 | int window_x, window_y, window_width, window_height; | |
5488 | ||
5489 | ||
5490 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); | |
5491 | window_rect.x = window_x; | |
5492 | window_rect.y = window_y; | |
5493 | window_rect.width = window_width; | |
5494 | window_rect.height = window_height; | |
5495 | ||
5496 | if (x_intersect_rectangles (&r, &window_rect, &intersection_rect)) | |
5497 | expose_window (w, &intersection_rect); | |
dc6f92b8 | 5498 | } |
06a2c219 | 5499 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
5500 | } |
5501 | ||
06a2c219 GM |
5502 | |
5503 | /* Redraw (parts) of all windows in the window tree rooted at W that | |
5504 | intersect R. R contains frame pixel coordinates. */ | |
5505 | ||
58769bee | 5506 | static void |
06a2c219 GM |
5507 | expose_window_tree (w, r) |
5508 | struct window *w; | |
5509 | XRectangle *r; | |
dc6f92b8 | 5510 | { |
06a2c219 GM |
5511 | while (w) |
5512 | { | |
5513 | if (!NILP (w->hchild)) | |
5514 | expose_window_tree (XWINDOW (w->hchild), r); | |
5515 | else if (!NILP (w->vchild)) | |
5516 | expose_window_tree (XWINDOW (w->vchild), r); | |
5517 | else | |
5518 | { | |
5519 | XRectangle window_rect; | |
5520 | XRectangle intersection_rect; | |
5521 | struct frame *f = XFRAME (w->frame); | |
5522 | int window_x, window_y, window_width, window_height; | |
5523 | ||
5524 | /* Frame-relative pixel rectangle of W. */ | |
5525 | window_box (w, -1, &window_x, &window_y, &window_width, | |
5526 | &window_height); | |
5527 | window_rect.x | |
5528 | = (window_x | |
110859fc | 5529 | - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f) |
714dc26c | 5530 | - FRAME_LEFT_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f)); |
06a2c219 GM |
5531 | window_rect.y = window_y; |
5532 | window_rect.width | |
5533 | = (window_width | |
110859fc | 5534 | + FRAME_X_FLAGS_AREA_WIDTH (f) |
06a2c219 GM |
5535 | + FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f)); |
5536 | window_rect.height | |
5537 | = window_height + CURRENT_MODE_LINE_HEIGHT (w); | |
5538 | ||
5539 | if (x_intersect_rectangles (r, &window_rect, &intersection_rect)) | |
5540 | expose_window (w, &intersection_rect); | |
5541 | } | |
58769bee | 5542 | |
06a2c219 GM |
5543 | w = NILP (w->next) ? 0 : XWINDOW (w->next); |
5544 | } | |
5545 | } | |
58769bee | 5546 | |
dc6f92b8 | 5547 | |
06a2c219 GM |
5548 | /* Redraw the part of glyph row area AREA of glyph row ROW on window W |
5549 | which intersects rectangle R. R is in window-relative coordinates. */ | |
5550 | ||
5551 | static void | |
5552 | expose_area (w, row, r, area) | |
5553 | struct window *w; | |
5554 | struct glyph_row *row; | |
5555 | XRectangle *r; | |
5556 | enum glyph_row_area area; | |
5557 | { | |
5558 | int x; | |
5559 | struct glyph *first = row->glyphs[area]; | |
5560 | struct glyph *end = row->glyphs[area] + row->used[area]; | |
5561 | struct glyph *last; | |
5562 | int first_x; | |
5563 | ||
5564 | /* Set x to the window-relative start position for drawing glyphs of | |
5565 | AREA. The first glyph of the text area can be partially visible. | |
5566 | The first glyphs of other areas cannot. */ | |
5567 | if (area == LEFT_MARGIN_AREA) | |
5568 | x = 0; | |
5569 | else if (area == TEXT_AREA) | |
5570 | x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5571 | else | |
5572 | x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5573 | + window_box_width (w, TEXT_AREA)); | |
5574 | ||
6fb13182 GM |
5575 | if (area == TEXT_AREA && row->fill_line_p) |
5576 | /* If row extends face to end of line write the whole line. */ | |
5577 | x_draw_glyphs (w, x, row, area, | |
5578 | 0, row->used[area], | |
06a2c219 | 5579 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, |
66ac4b0e | 5580 | NULL, NULL, 0); |
6fb13182 GM |
5581 | else |
5582 | { | |
5583 | /* Find the first glyph that must be redrawn. */ | |
5584 | while (first < end | |
5585 | && x + first->pixel_width < r->x) | |
5586 | { | |
5587 | x += first->pixel_width; | |
5588 | ++first; | |
5589 | } | |
5590 | ||
5591 | /* Find the last one. */ | |
5592 | last = first; | |
5593 | first_x = x; | |
5594 | while (last < end | |
5595 | && x < r->x + r->width) | |
5596 | { | |
5597 | x += last->pixel_width; | |
5598 | ++last; | |
5599 | } | |
5600 | ||
5601 | /* Repaint. */ | |
5602 | if (last > first) | |
5603 | x_draw_glyphs (w, first_x, row, area, | |
5604 | first - row->glyphs[area], | |
5605 | last - row->glyphs[area], | |
5606 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, | |
5607 | NULL, NULL, 0); | |
5608 | } | |
06a2c219 GM |
5609 | } |
5610 | ||
58769bee | 5611 | |
06a2c219 GM |
5612 | /* Redraw the parts of the glyph row ROW on window W intersecting |
5613 | rectangle R. R is in window-relative coordinates. */ | |
dc6f92b8 | 5614 | |
06a2c219 GM |
5615 | static void |
5616 | expose_line (w, row, r) | |
5617 | struct window *w; | |
5618 | struct glyph_row *row; | |
5619 | XRectangle *r; | |
5620 | { | |
5621 | xassert (row->enabled_p); | |
5622 | ||
5623 | if (row->mode_line_p || w->pseudo_window_p) | |
5624 | x_draw_glyphs (w, 0, row, TEXT_AREA, 0, row->used[TEXT_AREA], | |
5625 | row->inverse_p ? DRAW_INVERSE_VIDEO : DRAW_NORMAL_TEXT, | |
66ac4b0e | 5626 | NULL, NULL, 0); |
06a2c219 GM |
5627 | else |
5628 | { | |
5629 | if (row->used[LEFT_MARGIN_AREA]) | |
5630 | expose_area (w, row, r, LEFT_MARGIN_AREA); | |
5631 | if (row->used[TEXT_AREA]) | |
5632 | expose_area (w, row, r, TEXT_AREA); | |
5633 | if (row->used[RIGHT_MARGIN_AREA]) | |
5634 | expose_area (w, row, r, RIGHT_MARGIN_AREA); | |
5635 | x_draw_row_bitmaps (w, row); | |
5636 | } | |
5637 | } | |
dc6f92b8 | 5638 | |
58769bee | 5639 | |
06a2c219 GM |
5640 | /* Return non-zero if W's cursor intersects rectangle R. */ |
5641 | ||
5642 | static int | |
5643 | x_phys_cursor_in_rect_p (w, r) | |
5644 | struct window *w; | |
5645 | XRectangle *r; | |
5646 | { | |
5647 | XRectangle cr, result; | |
5648 | struct glyph *cursor_glyph; | |
5649 | ||
5650 | cursor_glyph = get_phys_cursor_glyph (w); | |
5651 | if (cursor_glyph) | |
5652 | { | |
5653 | cr.x = w->phys_cursor.x; | |
5654 | cr.y = w->phys_cursor.y; | |
5655 | cr.width = cursor_glyph->pixel_width; | |
5656 | cr.height = w->phys_cursor_height; | |
5657 | return x_intersect_rectangles (&cr, r, &result); | |
5658 | } | |
5659 | else | |
5660 | return 0; | |
dc6f92b8 | 5661 | } |
dc6f92b8 | 5662 | |
06a2c219 GM |
5663 | |
5664 | /* Redraw a rectangle of window W. R is a rectangle in window | |
5665 | relative coordinates. Call this function with input blocked. */ | |
dc6f92b8 JB |
5666 | |
5667 | static void | |
06a2c219 GM |
5668 | expose_window (w, r) |
5669 | struct window *w; | |
5670 | XRectangle *r; | |
dc6f92b8 | 5671 | { |
06a2c219 GM |
5672 | struct glyph_row *row; |
5673 | int y; | |
5674 | int yb = window_text_bottom_y (w); | |
5675 | int cursor_cleared_p; | |
dc6f92b8 | 5676 | |
80c32bcc GM |
5677 | /* If window is not yet fully initialized, do nothing. This can |
5678 | happen when toolkit scroll bars are used and a window is split. | |
5679 | Reconfiguring the scroll bar will generate an expose for a newly | |
5680 | created window. */ | |
5681 | if (w->current_matrix == NULL) | |
5682 | return; | |
5683 | ||
06a2c219 GM |
5684 | TRACE ((stderr, "expose_window (%d, %d, %d, %d)\n", |
5685 | r->x, r->y, r->width, r->height)); | |
dc6f92b8 | 5686 | |
06a2c219 GM |
5687 | /* Convert to window coordinates. */ |
5688 | r->x = FRAME_TO_WINDOW_PIXEL_X (w, r->x); | |
5689 | r->y = FRAME_TO_WINDOW_PIXEL_Y (w, r->y); | |
dc6f92b8 | 5690 | |
06a2c219 GM |
5691 | /* Turn off the cursor. */ |
5692 | if (!w->pseudo_window_p | |
5693 | && x_phys_cursor_in_rect_p (w, r)) | |
5694 | { | |
5695 | x_clear_cursor (w); | |
5696 | cursor_cleared_p = 1; | |
5697 | } | |
5698 | else | |
5699 | cursor_cleared_p = 0; | |
5700 | ||
5701 | /* Find the first row intersecting the rectangle R. */ | |
5702 | row = w->current_matrix->rows; | |
5703 | y = 0; | |
5704 | while (row->enabled_p | |
5705 | && y < yb | |
5706 | && y + row->height < r->y) | |
5707 | { | |
5708 | y += row->height; | |
5709 | ++row; | |
5710 | } | |
5711 | ||
dc6f92b8 | 5712 | /* Display the text in the rectangle, one text line at a time. */ |
06a2c219 GM |
5713 | while (row->enabled_p |
5714 | && y < yb | |
5715 | && y < r->y + r->height) | |
5716 | { | |
5717 | expose_line (w, row, r); | |
5718 | y += row->height; | |
5719 | ++row; | |
5720 | } | |
5721 | ||
5722 | /* Display the mode line if there is one. */ | |
5723 | if (WINDOW_WANTS_MODELINE_P (w) | |
5724 | && (row = MATRIX_MODE_LINE_ROW (w->current_matrix), | |
5725 | row->enabled_p) | |
5726 | && row->y < r->y + r->height) | |
5727 | expose_line (w, row, r); | |
dc6f92b8 | 5728 | |
06a2c219 | 5729 | if (!w->pseudo_window_p) |
dc6f92b8 | 5730 | { |
06a2c219 GM |
5731 | /* Draw border between windows. */ |
5732 | x_draw_vertical_border (w); | |
5733 | ||
5734 | /* Turn the cursor on again. */ | |
5735 | if (cursor_cleared_p) | |
5736 | x_update_window_cursor (w, 1); | |
5737 | } | |
5738 | } | |
dc6f92b8 | 5739 | |
dc6f92b8 | 5740 | |
06a2c219 GM |
5741 | /* Determine the intersection of two rectangles R1 and R2. Return |
5742 | the intersection in *RESULT. Value is non-zero if RESULT is not | |
5743 | empty. */ | |
5744 | ||
5745 | static int | |
5746 | x_intersect_rectangles (r1, r2, result) | |
5747 | XRectangle *r1, *r2, *result; | |
5748 | { | |
5749 | XRectangle *left, *right; | |
5750 | XRectangle *upper, *lower; | |
5751 | int intersection_p = 0; | |
5752 | ||
5753 | /* Rearrange so that R1 is the left-most rectangle. */ | |
5754 | if (r1->x < r2->x) | |
5755 | left = r1, right = r2; | |
5756 | else | |
5757 | left = r2, right = r1; | |
5758 | ||
5759 | /* X0 of the intersection is right.x0, if this is inside R1, | |
5760 | otherwise there is no intersection. */ | |
5761 | if (right->x <= left->x + left->width) | |
5762 | { | |
5763 | result->x = right->x; | |
5764 | ||
5765 | /* The right end of the intersection is the minimum of the | |
5766 | the right ends of left and right. */ | |
5767 | result->width = (min (left->x + left->width, right->x + right->width) | |
5768 | - result->x); | |
5769 | ||
5770 | /* Same game for Y. */ | |
5771 | if (r1->y < r2->y) | |
5772 | upper = r1, lower = r2; | |
5773 | else | |
5774 | upper = r2, lower = r1; | |
5775 | ||
5776 | /* The upper end of the intersection is lower.y0, if this is inside | |
5777 | of upper. Otherwise, there is no intersection. */ | |
5778 | if (lower->y <= upper->y + upper->height) | |
dc43ef94 | 5779 | { |
06a2c219 GM |
5780 | result->y = lower->y; |
5781 | ||
5782 | /* The lower end of the intersection is the minimum of the lower | |
5783 | ends of upper and lower. */ | |
5784 | result->height = (min (lower->y + lower->height, | |
5785 | upper->y + upper->height) | |
5786 | - result->y); | |
5787 | intersection_p = 1; | |
dc43ef94 | 5788 | } |
dc6f92b8 JB |
5789 | } |
5790 | ||
06a2c219 | 5791 | return intersection_p; |
dc6f92b8 | 5792 | } |
06a2c219 GM |
5793 | |
5794 | ||
5795 | ||
5796 | ||
dc6f92b8 | 5797 | \f |
dc6f92b8 | 5798 | static void |
334208b7 RS |
5799 | frame_highlight (f) |
5800 | struct frame *f; | |
dc6f92b8 | 5801 | { |
b3e1e05c JB |
5802 | /* We used to only do this if Vx_no_window_manager was non-nil, but |
5803 | the ICCCM (section 4.1.6) says that the window's border pixmap | |
5804 | and border pixel are window attributes which are "private to the | |
5805 | client", so we can always change it to whatever we want. */ | |
5806 | BLOCK_INPUT; | |
334208b7 | 5807 | XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 5808 | f->output_data.x->border_pixel); |
b3e1e05c | 5809 | UNBLOCK_INPUT; |
5d46f928 | 5810 | x_update_cursor (f, 1); |
dc6f92b8 JB |
5811 | } |
5812 | ||
5813 | static void | |
334208b7 RS |
5814 | frame_unhighlight (f) |
5815 | struct frame *f; | |
dc6f92b8 | 5816 | { |
b3e1e05c JB |
5817 | /* We used to only do this if Vx_no_window_manager was non-nil, but |
5818 | the ICCCM (section 4.1.6) says that the window's border pixmap | |
5819 | and border pixel are window attributes which are "private to the | |
5820 | client", so we can always change it to whatever we want. */ | |
5821 | BLOCK_INPUT; | |
334208b7 | 5822 | XSetWindowBorderPixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 5823 | f->output_data.x->border_tile); |
b3e1e05c | 5824 | UNBLOCK_INPUT; |
5d46f928 | 5825 | x_update_cursor (f, 1); |
dc6f92b8 | 5826 | } |
dc6f92b8 | 5827 | |
f676886a JB |
5828 | /* The focus has changed. Update the frames as necessary to reflect |
5829 | the new situation. Note that we can't change the selected frame | |
c5acd733 | 5830 | here, because the Lisp code we are interrupting might become confused. |
eb8c3be9 | 5831 | Each event gets marked with the frame in which it occurred, so the |
c5acd733 | 5832 | Lisp code can tell when the switch took place by examining the events. */ |
dc6f92b8 | 5833 | |
6d4238f3 | 5834 | static void |
0f941935 KH |
5835 | x_new_focus_frame (dpyinfo, frame) |
5836 | struct x_display_info *dpyinfo; | |
f676886a | 5837 | struct frame *frame; |
dc6f92b8 | 5838 | { |
0f941935 | 5839 | struct frame *old_focus = dpyinfo->x_focus_frame; |
dc6f92b8 | 5840 | |
0f941935 | 5841 | if (frame != dpyinfo->x_focus_frame) |
dc6f92b8 | 5842 | { |
58769bee | 5843 | /* Set this before calling other routines, so that they see |
f676886a | 5844 | the correct value of x_focus_frame. */ |
0f941935 | 5845 | dpyinfo->x_focus_frame = frame; |
6d4238f3 JB |
5846 | |
5847 | if (old_focus && old_focus->auto_lower) | |
f676886a | 5848 | x_lower_frame (old_focus); |
dc6f92b8 JB |
5849 | |
5850 | #if 0 | |
f676886a | 5851 | selected_frame = frame; |
e0c1aef2 KH |
5852 | XSETFRAME (XWINDOW (selected_frame->selected_window)->frame, |
5853 | selected_frame); | |
f676886a JB |
5854 | Fselect_window (selected_frame->selected_window); |
5855 | choose_minibuf_frame (); | |
c118dd06 | 5856 | #endif /* ! 0 */ |
dc6f92b8 | 5857 | |
0f941935 KH |
5858 | if (dpyinfo->x_focus_frame && dpyinfo->x_focus_frame->auto_raise) |
5859 | pending_autoraise_frame = dpyinfo->x_focus_frame; | |
0134a210 RS |
5860 | else |
5861 | pending_autoraise_frame = 0; | |
6d4238f3 | 5862 | } |
dc6f92b8 | 5863 | |
0f941935 | 5864 | x_frame_rehighlight (dpyinfo); |
6d4238f3 JB |
5865 | } |
5866 | ||
37c2c98b RS |
5867 | /* Handle an event saying the mouse has moved out of an Emacs frame. */ |
5868 | ||
5869 | void | |
0f941935 KH |
5870 | x_mouse_leave (dpyinfo) |
5871 | struct x_display_info *dpyinfo; | |
37c2c98b | 5872 | { |
0f941935 | 5873 | x_new_focus_frame (dpyinfo, dpyinfo->x_focus_event_frame); |
37c2c98b | 5874 | } |
6d4238f3 | 5875 | |
f451eb13 JB |
5876 | /* The focus has changed, or we have redirected a frame's focus to |
5877 | another frame (this happens when a frame uses a surrogate | |
06a2c219 | 5878 | mini-buffer frame). Shift the highlight as appropriate. |
0f941935 KH |
5879 | |
5880 | The FRAME argument doesn't necessarily have anything to do with which | |
06a2c219 | 5881 | frame is being highlighted or un-highlighted; we only use it to find |
0f941935 | 5882 | the appropriate X display info. */ |
06a2c219 | 5883 | |
6d4238f3 | 5884 | static void |
0f941935 KH |
5885 | XTframe_rehighlight (frame) |
5886 | struct frame *frame; | |
6d4238f3 | 5887 | { |
0f941935 KH |
5888 | x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame)); |
5889 | } | |
6d4238f3 | 5890 | |
0f941935 KH |
5891 | static void |
5892 | x_frame_rehighlight (dpyinfo) | |
5893 | struct x_display_info *dpyinfo; | |
5894 | { | |
5895 | struct frame *old_highlight = dpyinfo->x_highlight_frame; | |
5896 | ||
5897 | if (dpyinfo->x_focus_frame) | |
6d4238f3 | 5898 | { |
0f941935 KH |
5899 | dpyinfo->x_highlight_frame |
5900 | = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame))) | |
5901 | ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame)) | |
5902 | : dpyinfo->x_focus_frame); | |
5903 | if (! FRAME_LIVE_P (dpyinfo->x_highlight_frame)) | |
f451eb13 | 5904 | { |
0f941935 KH |
5905 | FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame) = Qnil; |
5906 | dpyinfo->x_highlight_frame = dpyinfo->x_focus_frame; | |
f451eb13 | 5907 | } |
dc6f92b8 | 5908 | } |
6d4238f3 | 5909 | else |
0f941935 | 5910 | dpyinfo->x_highlight_frame = 0; |
dc6f92b8 | 5911 | |
0f941935 | 5912 | if (dpyinfo->x_highlight_frame != old_highlight) |
6d4238f3 JB |
5913 | { |
5914 | if (old_highlight) | |
f676886a | 5915 | frame_unhighlight (old_highlight); |
0f941935 KH |
5916 | if (dpyinfo->x_highlight_frame) |
5917 | frame_highlight (dpyinfo->x_highlight_frame); | |
6d4238f3 | 5918 | } |
dc6f92b8 | 5919 | } |
06a2c219 GM |
5920 | |
5921 | ||
dc6f92b8 | 5922 | \f |
06a2c219 | 5923 | /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */ |
dc6f92b8 | 5924 | |
28430d3c JB |
5925 | /* Initialize mode_switch_bit and modifier_meaning. */ |
5926 | static void | |
334208b7 RS |
5927 | x_find_modifier_meanings (dpyinfo) |
5928 | struct x_display_info *dpyinfo; | |
28430d3c | 5929 | { |
f689eb05 | 5930 | int min_code, max_code; |
28430d3c JB |
5931 | KeySym *syms; |
5932 | int syms_per_code; | |
5933 | XModifierKeymap *mods; | |
5934 | ||
334208b7 RS |
5935 | dpyinfo->meta_mod_mask = 0; |
5936 | dpyinfo->shift_lock_mask = 0; | |
5937 | dpyinfo->alt_mod_mask = 0; | |
5938 | dpyinfo->super_mod_mask = 0; | |
5939 | dpyinfo->hyper_mod_mask = 0; | |
58769bee | 5940 | |
9658a521 | 5941 | #ifdef HAVE_X11R4 |
334208b7 | 5942 | XDisplayKeycodes (dpyinfo->display, &min_code, &max_code); |
9658a521 | 5943 | #else |
4a60f8c5 RS |
5944 | min_code = dpyinfo->display->min_keycode; |
5945 | max_code = dpyinfo->display->max_keycode; | |
9658a521 JB |
5946 | #endif |
5947 | ||
334208b7 | 5948 | syms = XGetKeyboardMapping (dpyinfo->display, |
28430d3c JB |
5949 | min_code, max_code - min_code + 1, |
5950 | &syms_per_code); | |
334208b7 | 5951 | mods = XGetModifierMapping (dpyinfo->display); |
28430d3c | 5952 | |
58769bee | 5953 | /* Scan the modifier table to see which modifier bits the Meta and |
11edeb03 | 5954 | Alt keysyms are on. */ |
28430d3c | 5955 | { |
06a2c219 | 5956 | int row, col; /* The row and column in the modifier table. */ |
28430d3c JB |
5957 | |
5958 | for (row = 3; row < 8; row++) | |
5959 | for (col = 0; col < mods->max_keypermod; col++) | |
5960 | { | |
0299d313 RS |
5961 | KeyCode code |
5962 | = mods->modifiermap[(row * mods->max_keypermod) + col]; | |
28430d3c | 5963 | |
af92970c KH |
5964 | /* Zeroes are used for filler. Skip them. */ |
5965 | if (code == 0) | |
5966 | continue; | |
5967 | ||
28430d3c JB |
5968 | /* Are any of this keycode's keysyms a meta key? */ |
5969 | { | |
5970 | int code_col; | |
5971 | ||
5972 | for (code_col = 0; code_col < syms_per_code; code_col++) | |
5973 | { | |
f689eb05 | 5974 | int sym = syms[((code - min_code) * syms_per_code) + code_col]; |
28430d3c | 5975 | |
f689eb05 | 5976 | switch (sym) |
28430d3c | 5977 | { |
f689eb05 JB |
5978 | case XK_Meta_L: |
5979 | case XK_Meta_R: | |
334208b7 | 5980 | dpyinfo->meta_mod_mask |= (1 << row); |
28430d3c | 5981 | break; |
f689eb05 JB |
5982 | |
5983 | case XK_Alt_L: | |
5984 | case XK_Alt_R: | |
334208b7 | 5985 | dpyinfo->alt_mod_mask |= (1 << row); |
a3c44b14 RS |
5986 | break; |
5987 | ||
5988 | case XK_Hyper_L: | |
5989 | case XK_Hyper_R: | |
334208b7 | 5990 | dpyinfo->hyper_mod_mask |= (1 << row); |
a3c44b14 RS |
5991 | break; |
5992 | ||
5993 | case XK_Super_L: | |
5994 | case XK_Super_R: | |
334208b7 | 5995 | dpyinfo->super_mod_mask |= (1 << row); |
f689eb05 | 5996 | break; |
11edeb03 JB |
5997 | |
5998 | case XK_Shift_Lock: | |
5999 | /* Ignore this if it's not on the lock modifier. */ | |
6000 | if ((1 << row) == LockMask) | |
334208b7 | 6001 | dpyinfo->shift_lock_mask = LockMask; |
11edeb03 | 6002 | break; |
28430d3c JB |
6003 | } |
6004 | } | |
6005 | } | |
6006 | } | |
6007 | } | |
6008 | ||
f689eb05 | 6009 | /* If we couldn't find any meta keys, accept any alt keys as meta keys. */ |
334208b7 | 6010 | if (! dpyinfo->meta_mod_mask) |
a3c44b14 | 6011 | { |
334208b7 RS |
6012 | dpyinfo->meta_mod_mask = dpyinfo->alt_mod_mask; |
6013 | dpyinfo->alt_mod_mask = 0; | |
a3c44b14 | 6014 | } |
f689eb05 | 6015 | |
148c4b70 RS |
6016 | /* If some keys are both alt and meta, |
6017 | make them just meta, not alt. */ | |
334208b7 | 6018 | if (dpyinfo->alt_mod_mask & dpyinfo->meta_mod_mask) |
148c4b70 | 6019 | { |
334208b7 | 6020 | dpyinfo->alt_mod_mask &= ~dpyinfo->meta_mod_mask; |
148c4b70 | 6021 | } |
58769bee | 6022 | |
28430d3c | 6023 | XFree ((char *) syms); |
f689eb05 | 6024 | XFreeModifiermap (mods); |
28430d3c JB |
6025 | } |
6026 | ||
dfeccd2d JB |
6027 | /* Convert between the modifier bits X uses and the modifier bits |
6028 | Emacs uses. */ | |
06a2c219 | 6029 | |
7c5283e4 | 6030 | static unsigned int |
334208b7 RS |
6031 | x_x_to_emacs_modifiers (dpyinfo, state) |
6032 | struct x_display_info *dpyinfo; | |
dc6f92b8 JB |
6033 | unsigned int state; |
6034 | { | |
334208b7 RS |
6035 | return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0) |
6036 | | ((state & ControlMask) ? ctrl_modifier : 0) | |
6037 | | ((state & dpyinfo->meta_mod_mask) ? meta_modifier : 0) | |
6038 | | ((state & dpyinfo->alt_mod_mask) ? alt_modifier : 0) | |
6039 | | ((state & dpyinfo->super_mod_mask) ? super_modifier : 0) | |
6040 | | ((state & dpyinfo->hyper_mod_mask) ? hyper_modifier : 0)); | |
dc6f92b8 JB |
6041 | } |
6042 | ||
dfeccd2d | 6043 | static unsigned int |
334208b7 RS |
6044 | x_emacs_to_x_modifiers (dpyinfo, state) |
6045 | struct x_display_info *dpyinfo; | |
dfeccd2d JB |
6046 | unsigned int state; |
6047 | { | |
334208b7 RS |
6048 | return ( ((state & alt_modifier) ? dpyinfo->alt_mod_mask : 0) |
6049 | | ((state & super_modifier) ? dpyinfo->super_mod_mask : 0) | |
6050 | | ((state & hyper_modifier) ? dpyinfo->hyper_mod_mask : 0) | |
6051 | | ((state & shift_modifier) ? ShiftMask : 0) | |
6052 | | ((state & ctrl_modifier) ? ControlMask : 0) | |
6053 | | ((state & meta_modifier) ? dpyinfo->meta_mod_mask : 0)); | |
dfeccd2d | 6054 | } |
d047c4eb KH |
6055 | |
6056 | /* Convert a keysym to its name. */ | |
6057 | ||
6058 | char * | |
6059 | x_get_keysym_name (keysym) | |
6060 | KeySym keysym; | |
6061 | { | |
6062 | char *value; | |
6063 | ||
6064 | BLOCK_INPUT; | |
6065 | value = XKeysymToString (keysym); | |
6066 | UNBLOCK_INPUT; | |
6067 | ||
6068 | return value; | |
6069 | } | |
06a2c219 GM |
6070 | |
6071 | ||
e4571a43 JB |
6072 | \f |
6073 | /* Mouse clicks and mouse movement. Rah. */ | |
e4571a43 | 6074 | |
06a2c219 GM |
6075 | /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph |
6076 | co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the | |
6077 | glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do | |
6078 | not force the value into range. */ | |
69388238 | 6079 | |
c8dba240 | 6080 | void |
69388238 | 6081 | pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip) |
e4571a43 | 6082 | FRAME_PTR f; |
69388238 | 6083 | register int pix_x, pix_y; |
e4571a43 JB |
6084 | register int *x, *y; |
6085 | XRectangle *bounds; | |
69388238 | 6086 | int noclip; |
e4571a43 | 6087 | { |
06a2c219 | 6088 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down |
69388238 RS |
6089 | even for negative values. */ |
6090 | if (pix_x < 0) | |
7556890b | 6091 | pix_x -= FONT_WIDTH ((f)->output_data.x->font) - 1; |
69388238 | 6092 | if (pix_y < 0) |
7556890b | 6093 | pix_y -= (f)->output_data.x->line_height - 1; |
69388238 | 6094 | |
e4571a43 JB |
6095 | pix_x = PIXEL_TO_CHAR_COL (f, pix_x); |
6096 | pix_y = PIXEL_TO_CHAR_ROW (f, pix_y); | |
6097 | ||
6098 | if (bounds) | |
6099 | { | |
7556890b RS |
6100 | bounds->width = FONT_WIDTH (f->output_data.x->font); |
6101 | bounds->height = f->output_data.x->line_height; | |
e4571a43 JB |
6102 | bounds->x = CHAR_TO_PIXEL_COL (f, pix_x); |
6103 | bounds->y = CHAR_TO_PIXEL_ROW (f, pix_y); | |
6104 | } | |
6105 | ||
69388238 RS |
6106 | if (!noclip) |
6107 | { | |
6108 | if (pix_x < 0) | |
6109 | pix_x = 0; | |
3cbd2e0b RS |
6110 | else if (pix_x > FRAME_WINDOW_WIDTH (f)) |
6111 | pix_x = FRAME_WINDOW_WIDTH (f); | |
69388238 RS |
6112 | |
6113 | if (pix_y < 0) | |
6114 | pix_y = 0; | |
6115 | else if (pix_y > f->height) | |
6116 | pix_y = f->height; | |
6117 | } | |
e4571a43 JB |
6118 | |
6119 | *x = pix_x; | |
6120 | *y = pix_y; | |
6121 | } | |
6122 | ||
06a2c219 GM |
6123 | |
6124 | /* Given HPOS/VPOS in the current matrix of W, return corresponding | |
6125 | frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we | |
6126 | can't tell the positions because W's display is not up to date, | |
6127 | return 0. */ | |
6128 | ||
6129 | int | |
6130 | glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y) | |
6131 | struct window *w; | |
6132 | int hpos, vpos; | |
6133 | int *frame_x, *frame_y; | |
2b5c9e71 | 6134 | { |
06a2c219 GM |
6135 | int success_p; |
6136 | ||
6137 | xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w); | |
6138 | xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h); | |
6139 | ||
6140 | if (display_completed) | |
6141 | { | |
6142 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos); | |
6143 | struct glyph *glyph = row->glyphs[TEXT_AREA]; | |
6144 | struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]); | |
6145 | ||
6146 | *frame_y = row->y; | |
6147 | *frame_x = row->x; | |
6148 | while (glyph < end) | |
6149 | { | |
6150 | *frame_x += glyph->pixel_width; | |
6151 | ++glyph; | |
6152 | } | |
6153 | ||
6154 | success_p = 1; | |
6155 | } | |
6156 | else | |
6157 | { | |
6158 | *frame_y = *frame_x = 0; | |
6159 | success_p = 0; | |
6160 | } | |
6161 | ||
6162 | *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, *frame_y); | |
6163 | *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, *frame_x); | |
6164 | return success_p; | |
2b5c9e71 RS |
6165 | } |
6166 | ||
06a2c219 | 6167 | |
dc6f92b8 JB |
6168 | /* Prepare a mouse-event in *RESULT for placement in the input queue. |
6169 | ||
6170 | If the event is a button press, then note that we have grabbed | |
f451eb13 | 6171 | the mouse. */ |
dc6f92b8 JB |
6172 | |
6173 | static Lisp_Object | |
f451eb13 | 6174 | construct_mouse_click (result, event, f) |
dc6f92b8 JB |
6175 | struct input_event *result; |
6176 | XButtonEvent *event; | |
f676886a | 6177 | struct frame *f; |
dc6f92b8 | 6178 | { |
f451eb13 | 6179 | /* Make the event type no_event; we'll change that when we decide |
dc6f92b8 | 6180 | otherwise. */ |
f451eb13 | 6181 | result->kind = mouse_click; |
69388238 | 6182 | result->code = event->button - Button1; |
1113d9db | 6183 | result->timestamp = event->time; |
334208b7 RS |
6184 | result->modifiers = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), |
6185 | event->state) | |
f689eb05 | 6186 | | (event->type == ButtonRelease |
58769bee | 6187 | ? up_modifier |
f689eb05 | 6188 | : down_modifier)); |
dc6f92b8 | 6189 | |
06a2c219 GM |
6190 | XSETINT (result->x, event->x); |
6191 | XSETINT (result->y, event->y); | |
6192 | XSETFRAME (result->frame_or_window, f); | |
0f8aabe9 | 6193 | result->arg = Qnil; |
06a2c219 | 6194 | return Qnil; |
dc6f92b8 | 6195 | } |
b849c413 | 6196 | |
69388238 | 6197 | \f |
90e65f07 JB |
6198 | /* Function to report a mouse movement to the mainstream Emacs code. |
6199 | The input handler calls this. | |
6200 | ||
6201 | We have received a mouse movement event, which is given in *event. | |
6202 | If the mouse is over a different glyph than it was last time, tell | |
6203 | the mainstream emacs code by setting mouse_moved. If not, ask for | |
6204 | another motion event, so we can check again the next time it moves. */ | |
b8009dd1 | 6205 | |
06a2c219 GM |
6206 | static XMotionEvent last_mouse_motion_event; |
6207 | static Lisp_Object last_mouse_motion_frame; | |
6208 | ||
90e65f07 | 6209 | static void |
12ba150f | 6210 | note_mouse_movement (frame, event) |
f676886a | 6211 | FRAME_PTR frame; |
90e65f07 | 6212 | XMotionEvent *event; |
90e65f07 | 6213 | { |
e5d77022 | 6214 | last_mouse_movement_time = event->time; |
06a2c219 GM |
6215 | last_mouse_motion_event = *event; |
6216 | XSETFRAME (last_mouse_motion_frame, frame); | |
e5d77022 | 6217 | |
27f338af RS |
6218 | if (event->window != FRAME_X_WINDOW (frame)) |
6219 | { | |
39d8bb4d | 6220 | frame->mouse_moved = 1; |
27f338af | 6221 | last_mouse_scroll_bar = Qnil; |
27f338af | 6222 | note_mouse_highlight (frame, -1, -1); |
27f338af RS |
6223 | } |
6224 | ||
90e65f07 | 6225 | /* Has the mouse moved off the glyph it was on at the last sighting? */ |
27f338af RS |
6226 | else if (event->x < last_mouse_glyph.x |
6227 | || event->x >= last_mouse_glyph.x + last_mouse_glyph.width | |
6228 | || event->y < last_mouse_glyph.y | |
6229 | || event->y >= last_mouse_glyph.y + last_mouse_glyph.height) | |
12ba150f | 6230 | { |
39d8bb4d | 6231 | frame->mouse_moved = 1; |
ab648270 | 6232 | last_mouse_scroll_bar = Qnil; |
b8009dd1 | 6233 | note_mouse_highlight (frame, event->x, event->y); |
90e65f07 JB |
6234 | } |
6235 | } | |
6236 | ||
bf1c0ba1 | 6237 | /* This is used for debugging, to turn off note_mouse_highlight. */ |
bf1c0ba1 | 6238 | |
06a2c219 GM |
6239 | int disable_mouse_highlight; |
6240 | ||
6241 | ||
6242 | \f | |
6243 | /************************************************************************ | |
6244 | Mouse Face | |
6245 | ************************************************************************/ | |
6246 | ||
6247 | /* Find the glyph under window-relative coordinates X/Y in window W. | |
6248 | Consider only glyphs from buffer text, i.e. no glyphs from overlay | |
6249 | strings. Return in *HPOS and *VPOS the row and column number of | |
6250 | the glyph found. Return in *AREA the glyph area containing X. | |
6251 | Value is a pointer to the glyph found or null if X/Y is not on | |
6252 | text, or we can't tell because W's current matrix is not up to | |
6253 | date. */ | |
6254 | ||
6255 | static struct glyph * | |
6256 | x_y_to_hpos_vpos (w, x, y, hpos, vpos, area) | |
6257 | struct window *w; | |
6258 | int x, y; | |
6259 | int *hpos, *vpos, *area; | |
6260 | { | |
6261 | struct glyph *glyph, *end; | |
3e71d8f2 | 6262 | struct glyph_row *row = NULL; |
06a2c219 GM |
6263 | int x0, i, left_area_width; |
6264 | ||
6265 | /* Find row containing Y. Give up if some row is not enabled. */ | |
6266 | for (i = 0; i < w->current_matrix->nrows; ++i) | |
6267 | { | |
6268 | row = MATRIX_ROW (w->current_matrix, i); | |
6269 | if (!row->enabled_p) | |
6270 | return NULL; | |
6271 | if (y >= row->y && y < MATRIX_ROW_BOTTOM_Y (row)) | |
6272 | break; | |
6273 | } | |
6274 | ||
6275 | *vpos = i; | |
6276 | *hpos = 0; | |
6277 | ||
6278 | /* Give up if Y is not in the window. */ | |
6279 | if (i == w->current_matrix->nrows) | |
6280 | return NULL; | |
6281 | ||
6282 | /* Get the glyph area containing X. */ | |
6283 | if (w->pseudo_window_p) | |
6284 | { | |
6285 | *area = TEXT_AREA; | |
6286 | x0 = 0; | |
6287 | } | |
6288 | else | |
6289 | { | |
6290 | left_area_width = window_box_width (w, LEFT_MARGIN_AREA); | |
6291 | if (x < left_area_width) | |
6292 | { | |
6293 | *area = LEFT_MARGIN_AREA; | |
6294 | x0 = 0; | |
6295 | } | |
6296 | else if (x < left_area_width + window_box_width (w, TEXT_AREA)) | |
6297 | { | |
6298 | *area = TEXT_AREA; | |
6299 | x0 = row->x + left_area_width; | |
6300 | } | |
6301 | else | |
6302 | { | |
6303 | *area = RIGHT_MARGIN_AREA; | |
6304 | x0 = left_area_width + window_box_width (w, TEXT_AREA); | |
6305 | } | |
6306 | } | |
6307 | ||
6308 | /* Find glyph containing X. */ | |
6309 | glyph = row->glyphs[*area]; | |
6310 | end = glyph + row->used[*area]; | |
6311 | while (glyph < end) | |
6312 | { | |
6313 | if (x < x0 + glyph->pixel_width) | |
6314 | { | |
6315 | if (w->pseudo_window_p) | |
6316 | break; | |
6317 | else if (BUFFERP (glyph->object)) | |
6318 | break; | |
6319 | } | |
6320 | ||
6321 | x0 += glyph->pixel_width; | |
6322 | ++glyph; | |
6323 | } | |
6324 | ||
6325 | if (glyph == end) | |
6326 | return NULL; | |
6327 | ||
6328 | *hpos = glyph - row->glyphs[*area]; | |
6329 | return glyph; | |
6330 | } | |
6331 | ||
6332 | ||
6333 | /* Convert frame-relative x/y to coordinates relative to window W. | |
6334 | Takes pseudo-windows into account. */ | |
6335 | ||
6336 | static void | |
6337 | frame_to_window_pixel_xy (w, x, y) | |
6338 | struct window *w; | |
6339 | int *x, *y; | |
6340 | { | |
6341 | if (w->pseudo_window_p) | |
6342 | { | |
6343 | /* A pseudo-window is always full-width, and starts at the | |
6344 | left edge of the frame, plus a frame border. */ | |
6345 | struct frame *f = XFRAME (w->frame); | |
6346 | *x -= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f); | |
6347 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6348 | } | |
6349 | else | |
6350 | { | |
6351 | *x = FRAME_TO_WINDOW_PIXEL_X (w, *x); | |
6352 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6353 | } | |
6354 | } | |
6355 | ||
6356 | ||
6357 | /* Take proper action when mouse has moved to the mode or top line of | |
6358 | window W, x-position X. MODE_LINE_P non-zero means mouse is on the | |
6359 | mode line. X is relative to the start of the text display area of | |
6360 | W, so the width of bitmap areas and scroll bars must be subtracted | |
6361 | to get a position relative to the start of the mode line. */ | |
6362 | ||
6363 | static void | |
6364 | note_mode_line_highlight (w, x, mode_line_p) | |
6365 | struct window *w; | |
6366 | int x, mode_line_p; | |
6367 | { | |
6368 | struct frame *f = XFRAME (w->frame); | |
6369 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
6370 | Cursor cursor = dpyinfo->vertical_scroll_bar_cursor; | |
6371 | struct glyph_row *row; | |
6372 | ||
6373 | if (mode_line_p) | |
6374 | row = MATRIX_MODE_LINE_ROW (w->current_matrix); | |
6375 | else | |
045dee35 | 6376 | row = MATRIX_HEADER_LINE_ROW (w->current_matrix); |
06a2c219 GM |
6377 | |
6378 | if (row->enabled_p) | |
6379 | { | |
6380 | struct glyph *glyph, *end; | |
6381 | Lisp_Object help, map; | |
6382 | int x0; | |
6383 | ||
6384 | /* Find the glyph under X. */ | |
6385 | glyph = row->glyphs[TEXT_AREA]; | |
6386 | end = glyph + row->used[TEXT_AREA]; | |
6387 | x0 = - (FRAME_LEFT_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f) | |
110859fc | 6388 | + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f)); |
06a2c219 GM |
6389 | while (glyph < end |
6390 | && x >= x0 + glyph->pixel_width) | |
6391 | { | |
6392 | x0 += glyph->pixel_width; | |
6393 | ++glyph; | |
6394 | } | |
6395 | ||
6396 | if (glyph < end | |
6397 | && STRINGP (glyph->object) | |
6398 | && XSTRING (glyph->object)->intervals | |
6399 | && glyph->charpos >= 0 | |
6400 | && glyph->charpos < XSTRING (glyph->object)->size) | |
6401 | { | |
6402 | /* If we're on a string with `help-echo' text property, | |
6403 | arrange for the help to be displayed. This is done by | |
6404 | setting the global variable help_echo to the help string. */ | |
6405 | help = Fget_text_property (make_number (glyph->charpos), | |
6406 | Qhelp_echo, glyph->object); | |
b7e80413 | 6407 | if (!NILP (help)) |
be010514 GM |
6408 | { |
6409 | help_echo = help; | |
7cea38bc | 6410 | XSETWINDOW (help_echo_window, w); |
be010514 GM |
6411 | help_echo_object = glyph->object; |
6412 | help_echo_pos = glyph->charpos; | |
6413 | } | |
06a2c219 GM |
6414 | |
6415 | /* Change the mouse pointer according to what is under X/Y. */ | |
6416 | map = Fget_text_property (make_number (glyph->charpos), | |
6417 | Qlocal_map, glyph->object); | |
6418 | if (!NILP (Fkeymapp (map))) | |
6419 | cursor = f->output_data.x->nontext_cursor; | |
be010514 GM |
6420 | else |
6421 | { | |
6422 | map = Fget_text_property (make_number (glyph->charpos), | |
6423 | Qkeymap, glyph->object); | |
6424 | if (!NILP (Fkeymapp (map))) | |
6425 | cursor = f->output_data.x->nontext_cursor; | |
6426 | } | |
06a2c219 GM |
6427 | } |
6428 | } | |
6429 | ||
6430 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), cursor); | |
6431 | } | |
6432 | ||
6433 | ||
6434 | /* Take proper action when the mouse has moved to position X, Y on | |
6435 | frame F as regards highlighting characters that have mouse-face | |
6436 | properties. Also de-highlighting chars where the mouse was before. | |
27f338af | 6437 | X and Y can be negative or out of range. */ |
b8009dd1 RS |
6438 | |
6439 | static void | |
6440 | note_mouse_highlight (f, x, y) | |
06a2c219 | 6441 | struct frame *f; |
c32cdd9a | 6442 | int x, y; |
b8009dd1 | 6443 | { |
06a2c219 GM |
6444 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
6445 | int portion; | |
b8009dd1 RS |
6446 | Lisp_Object window; |
6447 | struct window *w; | |
6448 | ||
06a2c219 GM |
6449 | /* When a menu is active, don't highlight because this looks odd. */ |
6450 | #ifdef USE_X_TOOLKIT | |
6451 | if (popup_activated ()) | |
6452 | return; | |
6453 | #endif | |
6454 | ||
04fff9c0 GM |
6455 | if (disable_mouse_highlight |
6456 | || !f->glyphs_initialized_p) | |
bf1c0ba1 RS |
6457 | return; |
6458 | ||
06a2c219 GM |
6459 | dpyinfo->mouse_face_mouse_x = x; |
6460 | dpyinfo->mouse_face_mouse_y = y; | |
6461 | dpyinfo->mouse_face_mouse_frame = f; | |
b8009dd1 | 6462 | |
06a2c219 | 6463 | if (dpyinfo->mouse_face_defer) |
b8009dd1 RS |
6464 | return; |
6465 | ||
514e4681 RS |
6466 | if (gc_in_progress) |
6467 | { | |
06a2c219 | 6468 | dpyinfo->mouse_face_deferred_gc = 1; |
514e4681 RS |
6469 | return; |
6470 | } | |
6471 | ||
b8009dd1 | 6472 | /* Which window is that in? */ |
06a2c219 | 6473 | window = window_from_coordinates (f, x, y, &portion, 1); |
b8009dd1 RS |
6474 | |
6475 | /* If we were displaying active text in another window, clear that. */ | |
06a2c219 GM |
6476 | if (! EQ (window, dpyinfo->mouse_face_window)) |
6477 | clear_mouse_face (dpyinfo); | |
6478 | ||
6479 | /* Not on a window -> return. */ | |
6480 | if (!WINDOWP (window)) | |
6481 | return; | |
6482 | ||
6483 | /* Convert to window-relative pixel coordinates. */ | |
6484 | w = XWINDOW (window); | |
6485 | frame_to_window_pixel_xy (w, &x, &y); | |
6486 | ||
9ea173e8 | 6487 | /* Handle tool-bar window differently since it doesn't display a |
06a2c219 | 6488 | buffer. */ |
9ea173e8 | 6489 | if (EQ (window, f->tool_bar_window)) |
06a2c219 | 6490 | { |
9ea173e8 | 6491 | note_tool_bar_highlight (f, x, y); |
06a2c219 GM |
6492 | return; |
6493 | } | |
6494 | ||
6495 | if (portion == 1 || portion == 3) | |
6496 | { | |
6497 | /* Mouse is on the mode or top line. */ | |
6498 | note_mode_line_highlight (w, x, portion == 1); | |
6499 | return; | |
6500 | } | |
6501 | else | |
6502 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
6503 | f->output_data.x->text_cursor); | |
b8009dd1 | 6504 | |
0cdd0c9f RS |
6505 | /* Are we in a window whose display is up to date? |
6506 | And verify the buffer's text has not changed. */ | |
06a2c219 GM |
6507 | if (/* Within text portion of the window. */ |
6508 | portion == 0 | |
0cdd0c9f | 6509 | && EQ (w->window_end_valid, w->buffer) |
26459b28 KH |
6510 | && XFASTINT (w->last_modified) == BUF_MODIFF (XBUFFER (w->buffer)) |
6511 | && (XFASTINT (w->last_overlay_modified) | |
6512 | == BUF_OVERLAY_MODIFF (XBUFFER (w->buffer)))) | |
b8009dd1 | 6513 | { |
06a2c219 GM |
6514 | int hpos, vpos, pos, i, area; |
6515 | struct glyph *glyph; | |
b8009dd1 | 6516 | |
06a2c219 GM |
6517 | /* Find the glyph under X/Y. */ |
6518 | glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, &area); | |
6519 | ||
6520 | /* Clear mouse face if X/Y not over text. */ | |
6521 | if (glyph == NULL | |
6522 | || area != TEXT_AREA | |
6523 | || !MATRIX_ROW (w->current_matrix, vpos)->displays_text_p) | |
b8009dd1 | 6524 | { |
06a2c219 GM |
6525 | clear_mouse_face (dpyinfo); |
6526 | return; | |
6527 | } | |
6528 | ||
6529 | pos = glyph->charpos; | |
6530 | xassert (w->pseudo_window_p || BUFFERP (glyph->object)); | |
6531 | ||
6532 | /* Check for mouse-face and help-echo. */ | |
6533 | { | |
6534 | Lisp_Object mouse_face, overlay, position; | |
6535 | Lisp_Object *overlay_vec; | |
6536 | int len, noverlays; | |
6537 | struct buffer *obuf; | |
6538 | int obegv, ozv; | |
6539 | ||
6540 | /* If we get an out-of-range value, return now; avoid an error. */ | |
6541 | if (pos > BUF_Z (XBUFFER (w->buffer))) | |
6542 | return; | |
6543 | ||
6544 | /* Make the window's buffer temporarily current for | |
6545 | overlays_at and compute_char_face. */ | |
6546 | obuf = current_buffer; | |
6547 | current_buffer = XBUFFER (w->buffer); | |
6548 | obegv = BEGV; | |
6549 | ozv = ZV; | |
6550 | BEGV = BEG; | |
6551 | ZV = Z; | |
6552 | ||
6553 | /* Is this char mouse-active or does it have help-echo? */ | |
6554 | XSETINT (position, pos); | |
6555 | ||
6556 | /* Put all the overlays we want in a vector in overlay_vec. | |
6557 | Store the length in len. If there are more than 10, make | |
6558 | enough space for all, and try again. */ | |
6559 | len = 10; | |
6560 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
bc592036 | 6561 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL, 0); |
06a2c219 GM |
6562 | if (noverlays > len) |
6563 | { | |
6564 | len = noverlays; | |
6565 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
bc592036 | 6566 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL,0); |
06a2c219 | 6567 | } |
f8349001 GM |
6568 | |
6569 | /* Sort overlays into increasing priority order. */ | |
06a2c219 GM |
6570 | noverlays = sort_overlays (overlay_vec, noverlays, w); |
6571 | ||
6572 | /* Check mouse-face highlighting. */ | |
6573 | if (! (EQ (window, dpyinfo->mouse_face_window) | |
6574 | && vpos >= dpyinfo->mouse_face_beg_row | |
6575 | && vpos <= dpyinfo->mouse_face_end_row | |
6576 | && (vpos > dpyinfo->mouse_face_beg_row | |
6577 | || hpos >= dpyinfo->mouse_face_beg_col) | |
6578 | && (vpos < dpyinfo->mouse_face_end_row | |
6579 | || hpos < dpyinfo->mouse_face_end_col | |
6580 | || dpyinfo->mouse_face_past_end))) | |
6581 | { | |
6582 | /* Clear the display of the old active region, if any. */ | |
6583 | clear_mouse_face (dpyinfo); | |
6584 | ||
6585 | /* Find the highest priority overlay that has a mouse-face prop. */ | |
6586 | overlay = Qnil; | |
f8349001 | 6587 | for (i = noverlays - 1; i >= 0; --i) |
06a2c219 GM |
6588 | { |
6589 | mouse_face = Foverlay_get (overlay_vec[i], Qmouse_face); | |
6590 | if (!NILP (mouse_face)) | |
6591 | { | |
6592 | overlay = overlay_vec[i]; | |
6593 | break; | |
6594 | } | |
6595 | } | |
6596 | ||
6597 | /* If no overlay applies, get a text property. */ | |
6598 | if (NILP (overlay)) | |
6599 | mouse_face = Fget_text_property (position, Qmouse_face, w->buffer); | |
6600 | ||
6601 | /* Handle the overlay case. */ | |
6602 | if (! NILP (overlay)) | |
6603 | { | |
6604 | /* Find the range of text around this char that | |
6605 | should be active. */ | |
6606 | Lisp_Object before, after; | |
6607 | int ignore; | |
6608 | ||
6609 | before = Foverlay_start (overlay); | |
6610 | after = Foverlay_end (overlay); | |
6611 | /* Record this as the current active region. */ | |
6612 | fast_find_position (w, XFASTINT (before), | |
6613 | &dpyinfo->mouse_face_beg_col, | |
6614 | &dpyinfo->mouse_face_beg_row, | |
6615 | &dpyinfo->mouse_face_beg_x, | |
6616 | &dpyinfo->mouse_face_beg_y); | |
6617 | dpyinfo->mouse_face_past_end | |
6618 | = !fast_find_position (w, XFASTINT (after), | |
6619 | &dpyinfo->mouse_face_end_col, | |
6620 | &dpyinfo->mouse_face_end_row, | |
6621 | &dpyinfo->mouse_face_end_x, | |
6622 | &dpyinfo->mouse_face_end_y); | |
6623 | dpyinfo->mouse_face_window = window; | |
6624 | dpyinfo->mouse_face_face_id | |
6625 | = face_at_buffer_position (w, pos, 0, 0, | |
6626 | &ignore, pos + 1, 1); | |
6627 | ||
6628 | /* Display it as active. */ | |
6629 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6630 | } | |
6631 | /* Handle the text property case. */ | |
6632 | else if (! NILP (mouse_face)) | |
6633 | { | |
6634 | /* Find the range of text around this char that | |
6635 | should be active. */ | |
6636 | Lisp_Object before, after, beginning, end; | |
6637 | int ignore; | |
6638 | ||
6639 | beginning = Fmarker_position (w->start); | |
6640 | XSETINT (end, (BUF_Z (XBUFFER (w->buffer)) | |
6641 | - XFASTINT (w->window_end_pos))); | |
6642 | before | |
6643 | = Fprevious_single_property_change (make_number (pos + 1), | |
6644 | Qmouse_face, | |
6645 | w->buffer, beginning); | |
6646 | after | |
6647 | = Fnext_single_property_change (position, Qmouse_face, | |
6648 | w->buffer, end); | |
6649 | /* Record this as the current active region. */ | |
6650 | fast_find_position (w, XFASTINT (before), | |
6651 | &dpyinfo->mouse_face_beg_col, | |
6652 | &dpyinfo->mouse_face_beg_row, | |
6653 | &dpyinfo->mouse_face_beg_x, | |
6654 | &dpyinfo->mouse_face_beg_y); | |
6655 | dpyinfo->mouse_face_past_end | |
6656 | = !fast_find_position (w, XFASTINT (after), | |
6657 | &dpyinfo->mouse_face_end_col, | |
6658 | &dpyinfo->mouse_face_end_row, | |
6659 | &dpyinfo->mouse_face_end_x, | |
6660 | &dpyinfo->mouse_face_end_y); | |
6661 | dpyinfo->mouse_face_window = window; | |
6662 | dpyinfo->mouse_face_face_id | |
6663 | = face_at_buffer_position (w, pos, 0, 0, | |
6664 | &ignore, pos + 1, 1); | |
6665 | ||
6666 | /* Display it as active. */ | |
6667 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
6668 | } | |
6669 | } | |
6670 | ||
6671 | /* Look for a `help-echo' property. */ | |
6672 | { | |
743934db | 6673 | Lisp_Object help, overlay; |
06a2c219 GM |
6674 | |
6675 | /* Check overlays first. */ | |
f9b5db02 | 6676 | help = overlay = Qnil; |
f8349001 | 6677 | for (i = noverlays - 1; i >= 0 && NILP (help); --i) |
743934db GM |
6678 | { |
6679 | overlay = overlay_vec[i]; | |
6680 | help = Foverlay_get (overlay, Qhelp_echo); | |
6681 | } | |
be010514 GM |
6682 | |
6683 | if (!NILP (help)) | |
6684 | { | |
6685 | help_echo = help; | |
7cea38bc | 6686 | help_echo_window = window; |
743934db | 6687 | help_echo_object = overlay; |
be010514 GM |
6688 | help_echo_pos = pos; |
6689 | } | |
6690 | else | |
6691 | { | |
6692 | /* Try text properties. */ | |
6693 | if ((STRINGP (glyph->object) | |
06a2c219 GM |
6694 | && glyph->charpos >= 0 |
6695 | && glyph->charpos < XSTRING (glyph->object)->size) | |
6696 | || (BUFFERP (glyph->object) | |
6697 | && glyph->charpos >= BEGV | |
be010514 GM |
6698 | && glyph->charpos < ZV)) |
6699 | help = Fget_text_property (make_number (glyph->charpos), | |
6700 | Qhelp_echo, glyph->object); | |
06a2c219 | 6701 | |
be010514 GM |
6702 | if (!NILP (help)) |
6703 | { | |
6704 | help_echo = help; | |
7cea38bc | 6705 | help_echo_window = window; |
be010514 GM |
6706 | help_echo_object = glyph->object; |
6707 | help_echo_pos = glyph->charpos; | |
6708 | } | |
6709 | } | |
06a2c219 GM |
6710 | } |
6711 | ||
6712 | BEGV = obegv; | |
6713 | ZV = ozv; | |
6714 | current_buffer = obuf; | |
6715 | } | |
6716 | } | |
6717 | } | |
6718 | ||
6719 | static void | |
6720 | redo_mouse_highlight () | |
6721 | { | |
6722 | if (!NILP (last_mouse_motion_frame) | |
6723 | && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame))) | |
6724 | note_mouse_highlight (XFRAME (last_mouse_motion_frame), | |
6725 | last_mouse_motion_event.x, | |
6726 | last_mouse_motion_event.y); | |
6727 | } | |
6728 | ||
6729 | ||
6730 | \f | |
6731 | /*********************************************************************** | |
9ea173e8 | 6732 | Tool-bars |
06a2c219 GM |
6733 | ***********************************************************************/ |
6734 | ||
9ea173e8 GM |
6735 | static int x_tool_bar_item P_ ((struct frame *, int, int, |
6736 | struct glyph **, int *, int *, int *)); | |
06a2c219 | 6737 | |
9ea173e8 | 6738 | /* Tool-bar item index of the item on which a mouse button was pressed |
06a2c219 GM |
6739 | or -1. */ |
6740 | ||
9ea173e8 | 6741 | static int last_tool_bar_item; |
06a2c219 GM |
6742 | |
6743 | ||
9ea173e8 GM |
6744 | /* Get information about the tool-bar item at position X/Y on frame F. |
6745 | Return in *GLYPH a pointer to the glyph of the tool-bar item in | |
6746 | the current matrix of the tool-bar window of F, or NULL if not | |
6747 | on a tool-bar item. Return in *PROP_IDX the index of the tool-bar | |
6748 | item in F->current_tool_bar_items. Value is | |
06a2c219 | 6749 | |
9ea173e8 | 6750 | -1 if X/Y is not on a tool-bar item |
06a2c219 GM |
6751 | 0 if X/Y is on the same item that was highlighted before. |
6752 | 1 otherwise. */ | |
6753 | ||
6754 | static int | |
9ea173e8 | 6755 | x_tool_bar_item (f, x, y, glyph, hpos, vpos, prop_idx) |
06a2c219 GM |
6756 | struct frame *f; |
6757 | int x, y; | |
6758 | struct glyph **glyph; | |
6759 | int *hpos, *vpos, *prop_idx; | |
6760 | { | |
6761 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
9ea173e8 | 6762 | struct window *w = XWINDOW (f->tool_bar_window); |
06a2c219 GM |
6763 | int area; |
6764 | ||
6765 | /* Find the glyph under X/Y. */ | |
6766 | *glyph = x_y_to_hpos_vpos (w, x, y, hpos, vpos, &area); | |
6767 | if (*glyph == NULL) | |
6768 | return -1; | |
6769 | ||
9ea173e8 GM |
6770 | /* Get the start of this tool-bar item's properties in |
6771 | f->current_tool_bar_items. */ | |
6772 | if (!tool_bar_item_info (f, *glyph, prop_idx)) | |
06a2c219 GM |
6773 | return -1; |
6774 | ||
6775 | /* Is mouse on the highlighted item? */ | |
9ea173e8 | 6776 | if (EQ (f->tool_bar_window, dpyinfo->mouse_face_window) |
06a2c219 GM |
6777 | && *vpos >= dpyinfo->mouse_face_beg_row |
6778 | && *vpos <= dpyinfo->mouse_face_end_row | |
6779 | && (*vpos > dpyinfo->mouse_face_beg_row | |
6780 | || *hpos >= dpyinfo->mouse_face_beg_col) | |
6781 | && (*vpos < dpyinfo->mouse_face_end_row | |
6782 | || *hpos < dpyinfo->mouse_face_end_col | |
6783 | || dpyinfo->mouse_face_past_end)) | |
6784 | return 0; | |
6785 | ||
6786 | return 1; | |
6787 | } | |
6788 | ||
6789 | ||
9ea173e8 | 6790 | /* Handle mouse button event on the tool-bar of frame F, at |
06a2c219 GM |
6791 | frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress |
6792 | or ButtonRelase. */ | |
6793 | ||
6794 | static void | |
9ea173e8 | 6795 | x_handle_tool_bar_click (f, button_event) |
06a2c219 GM |
6796 | struct frame *f; |
6797 | XButtonEvent *button_event; | |
6798 | { | |
6799 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
9ea173e8 | 6800 | struct window *w = XWINDOW (f->tool_bar_window); |
06a2c219 GM |
6801 | int hpos, vpos, prop_idx; |
6802 | struct glyph *glyph; | |
6803 | Lisp_Object enabled_p; | |
6804 | int x = button_event->x; | |
6805 | int y = button_event->y; | |
6806 | ||
9ea173e8 | 6807 | /* If not on the highlighted tool-bar item, return. */ |
06a2c219 | 6808 | frame_to_window_pixel_xy (w, &x, &y); |
9ea173e8 | 6809 | if (x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx) != 0) |
06a2c219 GM |
6810 | return; |
6811 | ||
6812 | /* If item is disabled, do nothing. */ | |
9ea173e8 GM |
6813 | enabled_p = (XVECTOR (f->current_tool_bar_items) |
6814 | ->contents[prop_idx + TOOL_BAR_ITEM_ENABLED_P]); | |
06a2c219 GM |
6815 | if (NILP (enabled_p)) |
6816 | return; | |
6817 | ||
6818 | if (button_event->type == ButtonPress) | |
6819 | { | |
6820 | /* Show item in pressed state. */ | |
6821 | show_mouse_face (dpyinfo, DRAW_IMAGE_SUNKEN); | |
6822 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_SUNKEN; | |
9ea173e8 | 6823 | last_tool_bar_item = prop_idx; |
06a2c219 GM |
6824 | } |
6825 | else | |
6826 | { | |
6827 | Lisp_Object key, frame; | |
6828 | struct input_event event; | |
6829 | ||
6830 | /* Show item in released state. */ | |
6831 | show_mouse_face (dpyinfo, DRAW_IMAGE_RAISED); | |
6832 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_RAISED; | |
6833 | ||
9ea173e8 GM |
6834 | key = (XVECTOR (f->current_tool_bar_items) |
6835 | ->contents[prop_idx + TOOL_BAR_ITEM_KEY]); | |
06a2c219 GM |
6836 | |
6837 | XSETFRAME (frame, f); | |
9ea173e8 | 6838 | event.kind = TOOL_BAR_EVENT; |
0f1a9b23 GM |
6839 | event.frame_or_window = frame; |
6840 | event.arg = frame; | |
06a2c219 GM |
6841 | kbd_buffer_store_event (&event); |
6842 | ||
9ea173e8 | 6843 | event.kind = TOOL_BAR_EVENT; |
0f1a9b23 GM |
6844 | event.frame_or_window = frame; |
6845 | event.arg = key; | |
06a2c219 GM |
6846 | event.modifiers = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), |
6847 | button_event->state); | |
6848 | kbd_buffer_store_event (&event); | |
9ea173e8 | 6849 | last_tool_bar_item = -1; |
06a2c219 GM |
6850 | } |
6851 | } | |
6852 | ||
6853 | ||
9ea173e8 GM |
6854 | /* Possibly highlight a tool-bar item on frame F when mouse moves to |
6855 | tool-bar window-relative coordinates X/Y. Called from | |
06a2c219 GM |
6856 | note_mouse_highlight. */ |
6857 | ||
6858 | static void | |
9ea173e8 | 6859 | note_tool_bar_highlight (f, x, y) |
06a2c219 GM |
6860 | struct frame *f; |
6861 | int x, y; | |
6862 | { | |
9ea173e8 | 6863 | Lisp_Object window = f->tool_bar_window; |
06a2c219 GM |
6864 | struct window *w = XWINDOW (window); |
6865 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
6866 | int hpos, vpos; | |
6867 | struct glyph *glyph; | |
6868 | struct glyph_row *row; | |
5c187dee | 6869 | int i; |
06a2c219 GM |
6870 | Lisp_Object enabled_p; |
6871 | int prop_idx; | |
6872 | enum draw_glyphs_face draw = DRAW_IMAGE_RAISED; | |
5c187dee | 6873 | int mouse_down_p, rc; |
06a2c219 GM |
6874 | |
6875 | /* Function note_mouse_highlight is called with negative x(y | |
6876 | values when mouse moves outside of the frame. */ | |
6877 | if (x <= 0 || y <= 0) | |
6878 | { | |
6879 | clear_mouse_face (dpyinfo); | |
6880 | return; | |
6881 | } | |
6882 | ||
9ea173e8 | 6883 | rc = x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx); |
06a2c219 GM |
6884 | if (rc < 0) |
6885 | { | |
9ea173e8 | 6886 | /* Not on tool-bar item. */ |
06a2c219 GM |
6887 | clear_mouse_face (dpyinfo); |
6888 | return; | |
6889 | } | |
6890 | else if (rc == 0) | |
9ea173e8 | 6891 | /* On same tool-bar item as before. */ |
06a2c219 | 6892 | goto set_help_echo; |
b8009dd1 | 6893 | |
06a2c219 GM |
6894 | clear_mouse_face (dpyinfo); |
6895 | ||
9ea173e8 | 6896 | /* Mouse is down, but on different tool-bar item? */ |
06a2c219 GM |
6897 | mouse_down_p = (dpyinfo->grabbed |
6898 | && f == last_mouse_frame | |
6899 | && FRAME_LIVE_P (f)); | |
6900 | if (mouse_down_p | |
9ea173e8 | 6901 | && last_tool_bar_item != prop_idx) |
06a2c219 GM |
6902 | return; |
6903 | ||
6904 | dpyinfo->mouse_face_image_state = DRAW_NORMAL_TEXT; | |
6905 | draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED; | |
6906 | ||
9ea173e8 GM |
6907 | /* If tool-bar item is not enabled, don't highlight it. */ |
6908 | enabled_p = (XVECTOR (f->current_tool_bar_items) | |
6909 | ->contents[prop_idx + TOOL_BAR_ITEM_ENABLED_P]); | |
06a2c219 GM |
6910 | if (!NILP (enabled_p)) |
6911 | { | |
6912 | /* Compute the x-position of the glyph. In front and past the | |
6913 | image is a space. We include this is the highlighted area. */ | |
6914 | row = MATRIX_ROW (w->current_matrix, vpos); | |
6915 | for (i = x = 0; i < hpos; ++i) | |
6916 | x += row->glyphs[TEXT_AREA][i].pixel_width; | |
6917 | ||
6918 | /* Record this as the current active region. */ | |
6919 | dpyinfo->mouse_face_beg_col = hpos; | |
6920 | dpyinfo->mouse_face_beg_row = vpos; | |
6921 | dpyinfo->mouse_face_beg_x = x; | |
6922 | dpyinfo->mouse_face_beg_y = row->y; | |
6923 | dpyinfo->mouse_face_past_end = 0; | |
6924 | ||
6925 | dpyinfo->mouse_face_end_col = hpos + 1; | |
6926 | dpyinfo->mouse_face_end_row = vpos; | |
6927 | dpyinfo->mouse_face_end_x = x + glyph->pixel_width; | |
6928 | dpyinfo->mouse_face_end_y = row->y; | |
6929 | dpyinfo->mouse_face_window = window; | |
9ea173e8 | 6930 | dpyinfo->mouse_face_face_id = TOOL_BAR_FACE_ID; |
06a2c219 GM |
6931 | |
6932 | /* Display it as active. */ | |
6933 | show_mouse_face (dpyinfo, draw); | |
6934 | dpyinfo->mouse_face_image_state = draw; | |
b8009dd1 | 6935 | } |
06a2c219 GM |
6936 | |
6937 | set_help_echo: | |
6938 | ||
9ea173e8 | 6939 | /* Set help_echo to a help string.to display for this tool-bar item. |
06a2c219 | 6940 | XTread_socket does the rest. */ |
7cea38bc | 6941 | help_echo_object = help_echo_window = Qnil; |
be010514 | 6942 | help_echo_pos = -1; |
9ea173e8 GM |
6943 | help_echo = (XVECTOR (f->current_tool_bar_items) |
6944 | ->contents[prop_idx + TOOL_BAR_ITEM_HELP]); | |
b7e80413 | 6945 | if (NILP (help_echo)) |
9ea173e8 GM |
6946 | help_echo = (XVECTOR (f->current_tool_bar_items) |
6947 | ->contents[prop_idx + TOOL_BAR_ITEM_CAPTION]); | |
b8009dd1 | 6948 | } |
4d73d038 | 6949 | |
06a2c219 GM |
6950 | |
6951 | \f | |
6952 | /* Find the glyph matrix position of buffer position POS in window W. | |
6953 | *HPOS, *VPOS, *X, and *Y are set to the positions found. W's | |
6954 | current glyphs must be up to date. If POS is above window start | |
6955 | return (0, 0, 0, 0). If POS is after end of W, return end of | |
6956 | last line in W. */ | |
b8009dd1 RS |
6957 | |
6958 | static int | |
06a2c219 GM |
6959 | fast_find_position (w, pos, hpos, vpos, x, y) |
6960 | struct window *w; | |
b8009dd1 | 6961 | int pos; |
06a2c219 | 6962 | int *hpos, *vpos, *x, *y; |
b8009dd1 | 6963 | { |
b8009dd1 | 6964 | int i; |
bf1c0ba1 | 6965 | int lastcol; |
06a2c219 GM |
6966 | int maybe_next_line_p = 0; |
6967 | int line_start_position; | |
6968 | int yb = window_text_bottom_y (w); | |
6969 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, 0); | |
6970 | struct glyph_row *best_row = row; | |
6971 | int row_vpos = 0, best_row_vpos = 0; | |
6972 | int current_x; | |
6973 | ||
6974 | while (row->y < yb) | |
b8009dd1 | 6975 | { |
06a2c219 GM |
6976 | if (row->used[TEXT_AREA]) |
6977 | line_start_position = row->glyphs[TEXT_AREA]->charpos; | |
6978 | else | |
6979 | line_start_position = 0; | |
6980 | ||
6981 | if (line_start_position > pos) | |
b8009dd1 | 6982 | break; |
77b68646 RS |
6983 | /* If the position sought is the end of the buffer, |
6984 | don't include the blank lines at the bottom of the window. */ | |
06a2c219 GM |
6985 | else if (line_start_position == pos |
6986 | && pos == BUF_ZV (XBUFFER (w->buffer))) | |
77b68646 | 6987 | { |
06a2c219 | 6988 | maybe_next_line_p = 1; |
77b68646 RS |
6989 | break; |
6990 | } | |
06a2c219 GM |
6991 | else if (line_start_position > 0) |
6992 | { | |
6993 | best_row = row; | |
6994 | best_row_vpos = row_vpos; | |
6995 | } | |
4b0bb6f3 GM |
6996 | |
6997 | if (row->y + row->height >= yb) | |
6998 | break; | |
06a2c219 GM |
6999 | |
7000 | ++row; | |
7001 | ++row_vpos; | |
b8009dd1 | 7002 | } |
06a2c219 GM |
7003 | |
7004 | /* Find the right column within BEST_ROW. */ | |
7005 | lastcol = 0; | |
7006 | current_x = best_row->x; | |
7007 | for (i = 0; i < best_row->used[TEXT_AREA]; i++) | |
bf1c0ba1 | 7008 | { |
06a2c219 GM |
7009 | struct glyph *glyph = best_row->glyphs[TEXT_AREA] + i; |
7010 | int charpos; | |
7011 | ||
7012 | charpos = glyph->charpos; | |
7013 | if (charpos == pos) | |
bf1c0ba1 | 7014 | { |
06a2c219 GM |
7015 | *hpos = i; |
7016 | *vpos = best_row_vpos; | |
7017 | *x = current_x; | |
7018 | *y = best_row->y; | |
bf1c0ba1 RS |
7019 | return 1; |
7020 | } | |
06a2c219 | 7021 | else if (charpos > pos) |
4d73d038 | 7022 | break; |
06a2c219 GM |
7023 | else if (charpos > 0) |
7024 | lastcol = i; | |
7025 | ||
7026 | current_x += glyph->pixel_width; | |
bf1c0ba1 | 7027 | } |
b8009dd1 | 7028 | |
77b68646 RS |
7029 | /* If we're looking for the end of the buffer, |
7030 | and we didn't find it in the line we scanned, | |
7031 | use the start of the following line. */ | |
06a2c219 | 7032 | if (maybe_next_line_p) |
77b68646 | 7033 | { |
06a2c219 GM |
7034 | ++best_row; |
7035 | ++best_row_vpos; | |
7036 | lastcol = 0; | |
7037 | current_x = best_row->x; | |
77b68646 RS |
7038 | } |
7039 | ||
06a2c219 GM |
7040 | *vpos = best_row_vpos; |
7041 | *hpos = lastcol + 1; | |
7042 | *x = current_x; | |
7043 | *y = best_row->y; | |
b8009dd1 RS |
7044 | return 0; |
7045 | } | |
7046 | ||
06a2c219 | 7047 | |
b8009dd1 RS |
7048 | /* Display the active region described by mouse_face_* |
7049 | in its mouse-face if HL > 0, in its normal face if HL = 0. */ | |
7050 | ||
7051 | static void | |
06a2c219 | 7052 | show_mouse_face (dpyinfo, draw) |
7a13e894 | 7053 | struct x_display_info *dpyinfo; |
06a2c219 | 7054 | enum draw_glyphs_face draw; |
b8009dd1 | 7055 | { |
7a13e894 | 7056 | struct window *w = XWINDOW (dpyinfo->mouse_face_window); |
06a2c219 | 7057 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
b8009dd1 | 7058 | int i; |
06a2c219 GM |
7059 | int cursor_off_p = 0; |
7060 | struct cursor_pos saved_cursor; | |
7061 | ||
7062 | saved_cursor = output_cursor; | |
7063 | ||
7064 | /* If window is in the process of being destroyed, don't bother | |
7065 | to do anything. */ | |
7066 | if (w->current_matrix == NULL) | |
7067 | goto set_x_cursor; | |
7068 | ||
7069 | /* Recognize when we are called to operate on rows that don't exist | |
7070 | anymore. This can happen when a window is split. */ | |
7071 | if (dpyinfo->mouse_face_end_row >= w->current_matrix->nrows) | |
7072 | goto set_x_cursor; | |
7073 | ||
7074 | set_output_cursor (&w->phys_cursor); | |
7075 | ||
7076 | /* Note that mouse_face_beg_row etc. are window relative. */ | |
7077 | for (i = dpyinfo->mouse_face_beg_row; | |
7078 | i <= dpyinfo->mouse_face_end_row; | |
7079 | i++) | |
7080 | { | |
7081 | int start_hpos, end_hpos, start_x; | |
7082 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, i); | |
7083 | ||
7084 | /* Don't do anything if row doesn't have valid contents. */ | |
7085 | if (!row->enabled_p) | |
7086 | continue; | |
7087 | ||
7088 | /* For all but the first row, the highlight starts at column 0. */ | |
7089 | if (i == dpyinfo->mouse_face_beg_row) | |
7090 | { | |
7091 | start_hpos = dpyinfo->mouse_face_beg_col; | |
7092 | start_x = dpyinfo->mouse_face_beg_x; | |
7093 | } | |
7094 | else | |
7095 | { | |
7096 | start_hpos = 0; | |
7097 | start_x = 0; | |
7098 | } | |
7099 | ||
7100 | if (i == dpyinfo->mouse_face_end_row) | |
7101 | end_hpos = dpyinfo->mouse_face_end_col; | |
7102 | else | |
7103 | end_hpos = row->used[TEXT_AREA]; | |
7104 | ||
7105 | /* If the cursor's in the text we are about to rewrite, turn the | |
7106 | cursor off. */ | |
7107 | if (!w->pseudo_window_p | |
7108 | && i == output_cursor.vpos | |
7109 | && output_cursor.hpos >= start_hpos - 1 | |
7110 | && output_cursor.hpos <= end_hpos) | |
514e4681 | 7111 | { |
06a2c219 GM |
7112 | x_update_window_cursor (w, 0); |
7113 | cursor_off_p = 1; | |
514e4681 | 7114 | } |
b8009dd1 | 7115 | |
06a2c219 | 7116 | if (end_hpos > start_hpos) |
64f26cf5 GM |
7117 | { |
7118 | row->mouse_face_p = draw == DRAW_MOUSE_FACE; | |
7119 | x_draw_glyphs (w, start_x, row, TEXT_AREA, | |
7120 | start_hpos, end_hpos, draw, NULL, NULL, 0); | |
7121 | } | |
b8009dd1 RS |
7122 | } |
7123 | ||
514e4681 | 7124 | /* If we turned the cursor off, turn it back on. */ |
06a2c219 GM |
7125 | if (cursor_off_p) |
7126 | x_display_cursor (w, 1, | |
7127 | output_cursor.hpos, output_cursor.vpos, | |
7128 | output_cursor.x, output_cursor.y); | |
2729a2b5 | 7129 | |
06a2c219 | 7130 | output_cursor = saved_cursor; |
fb3b7de5 | 7131 | |
06a2c219 GM |
7132 | set_x_cursor: |
7133 | ||
7134 | /* Change the mouse cursor. */ | |
7135 | if (draw == DRAW_NORMAL_TEXT) | |
7136 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
7137 | f->output_data.x->text_cursor); | |
7138 | else if (draw == DRAW_MOUSE_FACE) | |
334208b7 | 7139 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 7140 | f->output_data.x->cross_cursor); |
27ead1d5 | 7141 | else |
334208b7 | 7142 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
06a2c219 | 7143 | f->output_data.x->nontext_cursor); |
b8009dd1 RS |
7144 | } |
7145 | ||
7146 | /* Clear out the mouse-highlighted active region. | |
06a2c219 | 7147 | Redraw it un-highlighted first. */ |
b8009dd1 | 7148 | |
06a2c219 | 7149 | void |
7a13e894 RS |
7150 | clear_mouse_face (dpyinfo) |
7151 | struct x_display_info *dpyinfo; | |
b8009dd1 | 7152 | { |
06a2c219 GM |
7153 | if (tip_frame) |
7154 | return; | |
7155 | ||
7a13e894 | 7156 | if (! NILP (dpyinfo->mouse_face_window)) |
06a2c219 | 7157 | show_mouse_face (dpyinfo, DRAW_NORMAL_TEXT); |
b8009dd1 | 7158 | |
7a13e894 RS |
7159 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; |
7160 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7161 | dpyinfo->mouse_face_window = Qnil; | |
b8009dd1 | 7162 | } |
e687d06e | 7163 | |
71b8321e GM |
7164 | |
7165 | /* Clear any mouse-face on window W. This function is part of the | |
7166 | redisplay interface, and is called from try_window_id and similar | |
7167 | functions to ensure the mouse-highlight is off. */ | |
7168 | ||
7169 | static void | |
7170 | x_clear_mouse_face (w) | |
7171 | struct window *w; | |
7172 | { | |
7173 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (XFRAME (w->frame)); | |
7174 | Lisp_Object window; | |
7175 | ||
2e636f9d | 7176 | BLOCK_INPUT; |
71b8321e GM |
7177 | XSETWINDOW (window, w); |
7178 | if (EQ (window, dpyinfo->mouse_face_window)) | |
7179 | clear_mouse_face (dpyinfo); | |
2e636f9d | 7180 | UNBLOCK_INPUT; |
71b8321e GM |
7181 | } |
7182 | ||
7183 | ||
e687d06e RS |
7184 | /* Just discard the mouse face information for frame F, if any. |
7185 | This is used when the size of F is changed. */ | |
7186 | ||
dfcf069d | 7187 | void |
e687d06e RS |
7188 | cancel_mouse_face (f) |
7189 | FRAME_PTR f; | |
7190 | { | |
7191 | Lisp_Object window; | |
7192 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
7193 | ||
7194 | window = dpyinfo->mouse_face_window; | |
7195 | if (! NILP (window) && XFRAME (XWINDOW (window)->frame) == f) | |
7196 | { | |
7197 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
7198 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7199 | dpyinfo->mouse_face_window = Qnil; | |
7200 | } | |
7201 | } | |
b8009dd1 | 7202 | \f |
ab648270 JB |
7203 | static struct scroll_bar *x_window_to_scroll_bar (); |
7204 | static void x_scroll_bar_report_motion (); | |
12ba150f | 7205 | |
90e65f07 | 7206 | /* Return the current position of the mouse. |
2d7fc7e8 | 7207 | *fp should be a frame which indicates which display to ask about. |
90e65f07 | 7208 | |
2d7fc7e8 | 7209 | If the mouse movement started in a scroll bar, set *fp, *bar_window, |
ab648270 | 7210 | and *part to the frame, window, and scroll bar part that the mouse |
12ba150f | 7211 | is over. Set *x and *y to the portion and whole of the mouse's |
ab648270 | 7212 | position on the scroll bar. |
12ba150f | 7213 | |
2d7fc7e8 | 7214 | If the mouse movement started elsewhere, set *fp to the frame the |
12ba150f JB |
7215 | mouse is on, *bar_window to nil, and *x and *y to the character cell |
7216 | the mouse is over. | |
7217 | ||
06a2c219 | 7218 | Set *time to the server time-stamp for the time at which the mouse |
12ba150f JB |
7219 | was at this position. |
7220 | ||
a135645a RS |
7221 | Don't store anything if we don't have a valid set of values to report. |
7222 | ||
90e65f07 | 7223 | This clears the mouse_moved flag, so we can wait for the next mouse |
f5bb65ec | 7224 | movement. */ |
90e65f07 JB |
7225 | |
7226 | static void | |
1cf412ec | 7227 | XTmouse_position (fp, insist, bar_window, part, x, y, time) |
334208b7 | 7228 | FRAME_PTR *fp; |
1cf412ec | 7229 | int insist; |
12ba150f | 7230 | Lisp_Object *bar_window; |
ab648270 | 7231 | enum scroll_bar_part *part; |
90e65f07 | 7232 | Lisp_Object *x, *y; |
e5d77022 | 7233 | unsigned long *time; |
90e65f07 | 7234 | { |
a135645a RS |
7235 | FRAME_PTR f1; |
7236 | ||
90e65f07 JB |
7237 | BLOCK_INPUT; |
7238 | ||
8bcee03e | 7239 | if (! NILP (last_mouse_scroll_bar) && insist == 0) |
334208b7 | 7240 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); |
90e65f07 JB |
7241 | else |
7242 | { | |
12ba150f JB |
7243 | Window root; |
7244 | int root_x, root_y; | |
90e65f07 | 7245 | |
12ba150f JB |
7246 | Window dummy_window; |
7247 | int dummy; | |
7248 | ||
39d8bb4d KH |
7249 | Lisp_Object frame, tail; |
7250 | ||
7251 | /* Clear the mouse-moved flag for every frame on this display. */ | |
7252 | FOR_EACH_FRAME (tail, frame) | |
7253 | if (FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp)) | |
7254 | XFRAME (frame)->mouse_moved = 0; | |
7255 | ||
ab648270 | 7256 | last_mouse_scroll_bar = Qnil; |
12ba150f JB |
7257 | |
7258 | /* Figure out which root window we're on. */ | |
334208b7 RS |
7259 | XQueryPointer (FRAME_X_DISPLAY (*fp), |
7260 | DefaultRootWindow (FRAME_X_DISPLAY (*fp)), | |
12ba150f JB |
7261 | |
7262 | /* The root window which contains the pointer. */ | |
7263 | &root, | |
7264 | ||
7265 | /* Trash which we can't trust if the pointer is on | |
7266 | a different screen. */ | |
7267 | &dummy_window, | |
7268 | ||
7269 | /* The position on that root window. */ | |
58769bee | 7270 | &root_x, &root_y, |
12ba150f JB |
7271 | |
7272 | /* More trash we can't trust. */ | |
7273 | &dummy, &dummy, | |
7274 | ||
7275 | /* Modifier keys and pointer buttons, about which | |
7276 | we don't care. */ | |
7277 | (unsigned int *) &dummy); | |
7278 | ||
7279 | /* Now we have a position on the root; find the innermost window | |
7280 | containing the pointer. */ | |
7281 | { | |
7282 | Window win, child; | |
7283 | int win_x, win_y; | |
06a2c219 | 7284 | int parent_x = 0, parent_y = 0; |
e99db5a1 | 7285 | int count; |
12ba150f JB |
7286 | |
7287 | win = root; | |
69388238 | 7288 | |
2d7fc7e8 RS |
7289 | /* XTranslateCoordinates can get errors if the window |
7290 | structure is changing at the same time this function | |
7291 | is running. So at least we must not crash from them. */ | |
7292 | ||
e99db5a1 | 7293 | count = x_catch_errors (FRAME_X_DISPLAY (*fp)); |
2d7fc7e8 | 7294 | |
334208b7 | 7295 | if (FRAME_X_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame |
23faf38f | 7296 | && FRAME_LIVE_P (last_mouse_frame)) |
12ba150f | 7297 | { |
69388238 RS |
7298 | /* If mouse was grabbed on a frame, give coords for that frame |
7299 | even if the mouse is now outside it. */ | |
334208b7 | 7300 | XTranslateCoordinates (FRAME_X_DISPLAY (*fp), |
69388238 | 7301 | |
12ba150f | 7302 | /* From-window, to-window. */ |
69388238 | 7303 | root, FRAME_X_WINDOW (last_mouse_frame), |
12ba150f JB |
7304 | |
7305 | /* From-position, to-position. */ | |
7306 | root_x, root_y, &win_x, &win_y, | |
7307 | ||
7308 | /* Child of win. */ | |
7309 | &child); | |
69388238 RS |
7310 | f1 = last_mouse_frame; |
7311 | } | |
7312 | else | |
7313 | { | |
7314 | while (1) | |
7315 | { | |
334208b7 | 7316 | XTranslateCoordinates (FRAME_X_DISPLAY (*fp), |
12ba150f | 7317 | |
69388238 RS |
7318 | /* From-window, to-window. */ |
7319 | root, win, | |
12ba150f | 7320 | |
69388238 RS |
7321 | /* From-position, to-position. */ |
7322 | root_x, root_y, &win_x, &win_y, | |
7323 | ||
7324 | /* Child of win. */ | |
7325 | &child); | |
7326 | ||
9af3143a | 7327 | if (child == None || child == win) |
69388238 RS |
7328 | break; |
7329 | ||
7330 | win = child; | |
7331 | parent_x = win_x; | |
7332 | parent_y = win_y; | |
7333 | } | |
12ba150f | 7334 | |
69388238 RS |
7335 | /* Now we know that: |
7336 | win is the innermost window containing the pointer | |
7337 | (XTC says it has no child containing the pointer), | |
7338 | win_x and win_y are the pointer's position in it | |
7339 | (XTC did this the last time through), and | |
7340 | parent_x and parent_y are the pointer's position in win's parent. | |
7341 | (They are what win_x and win_y were when win was child. | |
7342 | If win is the root window, it has no parent, and | |
7343 | parent_{x,y} are invalid, but that's okay, because we'll | |
7344 | never use them in that case.) */ | |
7345 | ||
7346 | /* Is win one of our frames? */ | |
19126e11 | 7347 | f1 = x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp), win); |
69388238 | 7348 | } |
58769bee | 7349 | |
2d7fc7e8 RS |
7350 | if (x_had_errors_p (FRAME_X_DISPLAY (*fp))) |
7351 | f1 = 0; | |
7352 | ||
e99db5a1 | 7353 | x_uncatch_errors (FRAME_X_DISPLAY (*fp), count); |
2d7fc7e8 | 7354 | |
ab648270 | 7355 | /* If not, is it one of our scroll bars? */ |
a135645a | 7356 | if (! f1) |
12ba150f | 7357 | { |
ab648270 | 7358 | struct scroll_bar *bar = x_window_to_scroll_bar (win); |
12ba150f JB |
7359 | |
7360 | if (bar) | |
7361 | { | |
a135645a | 7362 | f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
12ba150f JB |
7363 | win_x = parent_x; |
7364 | win_y = parent_y; | |
7365 | } | |
7366 | } | |
90e65f07 | 7367 | |
8bcee03e | 7368 | if (f1 == 0 && insist > 0) |
b86bd3dd | 7369 | f1 = SELECTED_FRAME (); |
1cf412ec | 7370 | |
a135645a | 7371 | if (f1) |
12ba150f | 7372 | { |
06a2c219 GM |
7373 | /* Ok, we found a frame. Store all the values. |
7374 | last_mouse_glyph is a rectangle used to reduce the | |
7375 | generation of mouse events. To not miss any motion | |
7376 | events, we must divide the frame into rectangles of the | |
7377 | size of the smallest character that could be displayed | |
7378 | on it, i.e. into the same rectangles that matrices on | |
7379 | the frame are divided into. */ | |
7380 | ||
7381 | #if OLD_REDISPLAY_CODE | |
2b5c9e71 | 7382 | int ignore1, ignore2; |
2b5c9e71 | 7383 | pixel_to_glyph_coords (f1, win_x, win_y, &ignore1, &ignore2, |
334208b7 | 7384 | &last_mouse_glyph, |
1cf412ec RS |
7385 | FRAME_X_DISPLAY_INFO (f1)->grabbed |
7386 | || insist); | |
06a2c219 GM |
7387 | #else |
7388 | { | |
7389 | int width = FRAME_SMALLEST_CHAR_WIDTH (f1); | |
7390 | int height = FRAME_SMALLEST_FONT_HEIGHT (f1); | |
7391 | int x = win_x; | |
7392 | int y = win_y; | |
7393 | ||
7394 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to | |
7395 | round down even for negative values. */ | |
7396 | if (x < 0) | |
7397 | x -= width - 1; | |
7398 | if (y < 0) | |
7399 | y -= height - 1; | |
7400 | ||
7401 | last_mouse_glyph.width = width; | |
7402 | last_mouse_glyph.height = height; | |
7403 | last_mouse_glyph.x = (x + width - 1) / width * width; | |
7404 | last_mouse_glyph.y = (y + height - 1) / height * height; | |
7405 | } | |
7406 | #endif | |
12ba150f JB |
7407 | |
7408 | *bar_window = Qnil; | |
7409 | *part = 0; | |
334208b7 | 7410 | *fp = f1; |
e0c1aef2 KH |
7411 | XSETINT (*x, win_x); |
7412 | XSETINT (*y, win_y); | |
12ba150f JB |
7413 | *time = last_mouse_movement_time; |
7414 | } | |
7415 | } | |
7416 | } | |
90e65f07 JB |
7417 | |
7418 | UNBLOCK_INPUT; | |
7419 | } | |
f451eb13 | 7420 | |
06a2c219 | 7421 | |
06a2c219 | 7422 | #ifdef USE_X_TOOLKIT |
bffcfca9 GM |
7423 | |
7424 | /* Atimer callback function for TIMER. Called every 0.1s to process | |
7425 | Xt timeouts, if needed. We must avoid calling XtAppPending as | |
7426 | much as possible because that function does an implicit XFlush | |
7427 | that slows us down. */ | |
7428 | ||
7429 | static void | |
7430 | x_process_timeouts (timer) | |
7431 | struct atimer *timer; | |
7432 | { | |
7433 | if (toolkit_scroll_bar_interaction || popup_activated_flag) | |
7434 | { | |
7435 | BLOCK_INPUT; | |
7436 | while (XtAppPending (Xt_app_con) & XtIMTimer) | |
7437 | XtAppProcessEvent (Xt_app_con, XtIMTimer); | |
7438 | UNBLOCK_INPUT; | |
7439 | } | |
06a2c219 GM |
7440 | } |
7441 | ||
bffcfca9 | 7442 | #endif /* USE_X_TOOLKIT */ |
06a2c219 GM |
7443 | |
7444 | \f | |
7445 | /* Scroll bar support. */ | |
7446 | ||
7447 | /* Given an X window ID, find the struct scroll_bar which manages it. | |
7448 | This can be called in GC, so we have to make sure to strip off mark | |
7449 | bits. */ | |
bffcfca9 | 7450 | |
06a2c219 GM |
7451 | static struct scroll_bar * |
7452 | x_window_to_scroll_bar (window_id) | |
7453 | Window window_id; | |
7454 | { | |
7455 | Lisp_Object tail; | |
7456 | ||
7457 | for (tail = Vframe_list; | |
7458 | XGCTYPE (tail) == Lisp_Cons; | |
8e713be6 | 7459 | tail = XCDR (tail)) |
06a2c219 GM |
7460 | { |
7461 | Lisp_Object frame, bar, condemned; | |
7462 | ||
8e713be6 | 7463 | frame = XCAR (tail); |
06a2c219 GM |
7464 | /* All elements of Vframe_list should be frames. */ |
7465 | if (! GC_FRAMEP (frame)) | |
7466 | abort (); | |
7467 | ||
7468 | /* Scan this frame's scroll bar list for a scroll bar with the | |
7469 | right window ID. */ | |
7470 | condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); | |
7471 | for (bar = FRAME_SCROLL_BARS (XFRAME (frame)); | |
7472 | /* This trick allows us to search both the ordinary and | |
7473 | condemned scroll bar lists with one loop. */ | |
7474 | ! GC_NILP (bar) || (bar = condemned, | |
7475 | condemned = Qnil, | |
7476 | ! GC_NILP (bar)); | |
7477 | bar = XSCROLL_BAR (bar)->next) | |
7478 | if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)) == window_id) | |
7479 | return XSCROLL_BAR (bar); | |
7480 | } | |
7481 | ||
7482 | return 0; | |
7483 | } | |
7484 | ||
7485 | ||
7486 | \f | |
7487 | /************************************************************************ | |
7488 | Toolkit scroll bars | |
7489 | ************************************************************************/ | |
7490 | ||
7491 | #if USE_TOOLKIT_SCROLL_BARS | |
7492 | ||
7493 | static void x_scroll_bar_to_input_event P_ ((XEvent *, struct input_event *)); | |
7494 | static void x_send_scroll_bar_event P_ ((Lisp_Object, int, int, int)); | |
7495 | static void x_create_toolkit_scroll_bar P_ ((struct frame *, | |
7496 | struct scroll_bar *)); | |
7497 | static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *, | |
7498 | int, int, int)); | |
7499 | ||
7500 | ||
7501 | /* Id of action hook installed for scroll bars. */ | |
7502 | ||
7503 | static XtActionHookId action_hook_id; | |
7504 | ||
7505 | /* Lisp window being scrolled. Set when starting to interact with | |
7506 | a toolkit scroll bar, reset to nil when ending the interaction. */ | |
7507 | ||
7508 | static Lisp_Object window_being_scrolled; | |
7509 | ||
7510 | /* Last scroll bar part sent in xm_scroll_callback. */ | |
7511 | ||
7512 | static int last_scroll_bar_part; | |
7513 | ||
ec18280f SM |
7514 | /* Whether this is an Xaw with arrow-scrollbars. This should imply |
7515 | that movements of 1/20 of the screen size are mapped to up/down. */ | |
7516 | ||
7517 | static Boolean xaw3d_arrow_scroll; | |
7518 | ||
7519 | /* Whether the drag scrolling maintains the mouse at the top of the | |
7520 | thumb. If not, resizing the thumb needs to be done more carefully | |
7521 | to avoid jerkyness. */ | |
7522 | ||
7523 | static Boolean xaw3d_pick_top; | |
7524 | ||
06a2c219 GM |
7525 | |
7526 | /* Action hook installed via XtAppAddActionHook when toolkit scroll | |
ec18280f | 7527 | bars are used.. The hook is responsible for detecting when |
06a2c219 GM |
7528 | the user ends an interaction with the scroll bar, and generates |
7529 | a `end-scroll' scroll_bar_click' event if so. */ | |
7530 | ||
7531 | static void | |
7532 | xt_action_hook (widget, client_data, action_name, event, params, | |
7533 | num_params) | |
7534 | Widget widget; | |
7535 | XtPointer client_data; | |
7536 | String action_name; | |
7537 | XEvent *event; | |
7538 | String *params; | |
7539 | Cardinal *num_params; | |
7540 | { | |
7541 | int scroll_bar_p; | |
7542 | char *end_action; | |
7543 | ||
7544 | #ifdef USE_MOTIF | |
7545 | scroll_bar_p = XmIsScrollBar (widget); | |
7546 | end_action = "Release"; | |
ec18280f | 7547 | #else /* !USE_MOTIF i.e. use Xaw */ |
06a2c219 GM |
7548 | scroll_bar_p = XtIsSubclass (widget, scrollbarWidgetClass); |
7549 | end_action = "EndScroll"; | |
ec18280f | 7550 | #endif /* USE_MOTIF */ |
06a2c219 | 7551 | |
06a2c219 GM |
7552 | if (scroll_bar_p |
7553 | && strcmp (action_name, end_action) == 0 | |
7554 | && WINDOWP (window_being_scrolled)) | |
7555 | { | |
7556 | struct window *w; | |
7557 | ||
7558 | x_send_scroll_bar_event (window_being_scrolled, | |
7559 | scroll_bar_end_scroll, 0, 0); | |
7560 | w = XWINDOW (window_being_scrolled); | |
7561 | XSCROLL_BAR (w->vertical_scroll_bar)->dragging = Qnil; | |
7562 | window_being_scrolled = Qnil; | |
7563 | last_scroll_bar_part = -1; | |
bffcfca9 GM |
7564 | |
7565 | /* Xt timeouts no longer needed. */ | |
7566 | toolkit_scroll_bar_interaction = 0; | |
06a2c219 GM |
7567 | } |
7568 | } | |
7569 | ||
7570 | ||
7571 | /* Send a client message with message type Xatom_Scrollbar for a | |
7572 | scroll action to the frame of WINDOW. PART is a value identifying | |
7573 | the part of the scroll bar that was clicked on. PORTION is the | |
7574 | amount to scroll of a whole of WHOLE. */ | |
7575 | ||
7576 | static void | |
7577 | x_send_scroll_bar_event (window, part, portion, whole) | |
7578 | Lisp_Object window; | |
7579 | int part, portion, whole; | |
7580 | { | |
7581 | XEvent event; | |
7582 | XClientMessageEvent *ev = (XClientMessageEvent *) &event; | |
7583 | struct frame *f = XFRAME (XWINDOW (window)->frame); | |
7584 | ||
7585 | /* Construct a ClientMessage event to send to the frame. */ | |
7586 | ev->type = ClientMessage; | |
7587 | ev->message_type = FRAME_X_DISPLAY_INFO (f)->Xatom_Scrollbar; | |
7588 | ev->display = FRAME_X_DISPLAY (f); | |
7589 | ev->window = FRAME_X_WINDOW (f); | |
7590 | ev->format = 32; | |
52e386c2 | 7591 | ev->data.l[0] = (long) XFASTINT (window); |
06a2c219 GM |
7592 | ev->data.l[1] = (long) part; |
7593 | ev->data.l[2] = (long) 0; | |
7594 | ev->data.l[3] = (long) portion; | |
7595 | ev->data.l[4] = (long) whole; | |
7596 | ||
bffcfca9 GM |
7597 | /* Make Xt timeouts work while the scroll bar is active. */ |
7598 | toolkit_scroll_bar_interaction = 1; | |
7599 | ||
06a2c219 GM |
7600 | /* Setting the event mask to zero means that the message will |
7601 | be sent to the client that created the window, and if that | |
7602 | window no longer exists, no event will be sent. */ | |
7603 | BLOCK_INPUT; | |
7604 | XSendEvent (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), False, 0, &event); | |
7605 | UNBLOCK_INPUT; | |
7606 | } | |
7607 | ||
7608 | ||
7609 | /* Transform a scroll bar ClientMessage EVENT to an Emacs input event | |
7610 | in *IEVENT. */ | |
7611 | ||
7612 | static void | |
7613 | x_scroll_bar_to_input_event (event, ievent) | |
7614 | XEvent *event; | |
7615 | struct input_event *ievent; | |
7616 | { | |
7617 | XClientMessageEvent *ev = (XClientMessageEvent *) event; | |
52e386c2 KR |
7618 | Lisp_Object window; |
7619 | struct frame *f; | |
7620 | ||
7621 | XSETFASTINT (window, ev->data.l[0]); | |
7622 | f = XFRAME (XWINDOW (window)->frame); | |
06a2c219 GM |
7623 | |
7624 | ievent->kind = scroll_bar_click; | |
7625 | ievent->frame_or_window = window; | |
0f8aabe9 | 7626 | ievent->arg = Qnil; |
06a2c219 GM |
7627 | ievent->timestamp = XtLastTimestampProcessed (FRAME_X_DISPLAY (f)); |
7628 | ievent->part = ev->data.l[1]; | |
7629 | ievent->code = ev->data.l[2]; | |
7630 | ievent->x = make_number ((int) ev->data.l[3]); | |
7631 | ievent->y = make_number ((int) ev->data.l[4]); | |
7632 | ievent->modifiers = 0; | |
7633 | } | |
7634 | ||
7635 | ||
7636 | #ifdef USE_MOTIF | |
7637 | ||
7638 | /* Minimum and maximum values used for Motif scroll bars. */ | |
7639 | ||
7640 | #define XM_SB_MIN 1 | |
7641 | #define XM_SB_MAX 10000000 | |
7642 | #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN) | |
7643 | ||
7644 | ||
7645 | /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll | |
7646 | bar widget. CLIENT_DATA is a pointer to the scroll_bar structure. | |
7647 | CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */ | |
7648 | ||
7649 | static void | |
7650 | xm_scroll_callback (widget, client_data, call_data) | |
7651 | Widget widget; | |
7652 | XtPointer client_data, call_data; | |
7653 | { | |
7654 | struct scroll_bar *bar = (struct scroll_bar *) client_data; | |
7655 | XmScrollBarCallbackStruct *cs = (XmScrollBarCallbackStruct *) call_data; | |
7656 | double percent; | |
7657 | int part = -1, whole = 0, portion = 0; | |
7658 | ||
7659 | switch (cs->reason) | |
7660 | { | |
7661 | case XmCR_DECREMENT: | |
7662 | bar->dragging = Qnil; | |
7663 | part = scroll_bar_up_arrow; | |
7664 | break; | |
7665 | ||
7666 | case XmCR_INCREMENT: | |
7667 | bar->dragging = Qnil; | |
7668 | part = scroll_bar_down_arrow; | |
7669 | break; | |
7670 | ||
7671 | case XmCR_PAGE_DECREMENT: | |
7672 | bar->dragging = Qnil; | |
7673 | part = scroll_bar_above_handle; | |
7674 | break; | |
7675 | ||
7676 | case XmCR_PAGE_INCREMENT: | |
7677 | bar->dragging = Qnil; | |
7678 | part = scroll_bar_below_handle; | |
7679 | break; | |
7680 | ||
7681 | case XmCR_TO_TOP: | |
7682 | bar->dragging = Qnil; | |
7683 | part = scroll_bar_to_top; | |
7684 | break; | |
7685 | ||
7686 | case XmCR_TO_BOTTOM: | |
7687 | bar->dragging = Qnil; | |
7688 | part = scroll_bar_to_bottom; | |
7689 | break; | |
7690 | ||
7691 | case XmCR_DRAG: | |
7692 | { | |
7693 | int slider_size; | |
7694 | int dragging_down_p = (INTEGERP (bar->dragging) | |
7695 | && XINT (bar->dragging) <= cs->value); | |
7696 | ||
7697 | /* Get the slider size. */ | |
7698 | BLOCK_INPUT; | |
7699 | XtVaGetValues (widget, XmNsliderSize, &slider_size, NULL); | |
7700 | UNBLOCK_INPUT; | |
7701 | ||
7702 | /* At the max position of the scroll bar, do a line-wise | |
7703 | movement. Without doing anything, the LessTif scroll bar | |
7704 | calls us with the same cs->value again and again. If we | |
7705 | want to make sure that we can reach the end of the buffer, | |
7706 | we have to do something. | |
7707 | ||
7708 | Implementation note: setting bar->dragging always to | |
7709 | cs->value gives a smoother movement at the max position. | |
7710 | Setting it to nil when doing line-wise movement gives | |
7711 | a better slider behavior. */ | |
7712 | ||
7713 | if (cs->value + slider_size == XM_SB_MAX | |
7714 | || (dragging_down_p | |
7715 | && last_scroll_bar_part == scroll_bar_down_arrow)) | |
7716 | { | |
7717 | part = scroll_bar_down_arrow; | |
7718 | bar->dragging = Qnil; | |
7719 | } | |
7720 | else | |
7721 | { | |
7722 | whole = XM_SB_RANGE; | |
7723 | portion = min (cs->value - XM_SB_MIN, XM_SB_MAX - slider_size); | |
7724 | part = scroll_bar_handle; | |
7725 | bar->dragging = make_number (cs->value); | |
7726 | } | |
7727 | } | |
7728 | break; | |
7729 | ||
7730 | case XmCR_VALUE_CHANGED: | |
7731 | break; | |
7732 | }; | |
7733 | ||
7734 | if (part >= 0) | |
7735 | { | |
7736 | window_being_scrolled = bar->window; | |
7737 | last_scroll_bar_part = part; | |
7738 | x_send_scroll_bar_event (bar->window, part, portion, whole); | |
7739 | } | |
7740 | } | |
7741 | ||
7742 | ||
ec18280f | 7743 | #else /* !USE_MOTIF, i.e. Xaw. */ |
06a2c219 GM |
7744 | |
7745 | ||
ec18280f | 7746 | /* Xaw scroll bar callback. Invoked when the thumb is dragged. |
06a2c219 GM |
7747 | WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the |
7748 | scroll bar struct. CALL_DATA is a pointer to a float saying where | |
7749 | the thumb is. */ | |
7750 | ||
7751 | static void | |
ec18280f | 7752 | xaw_jump_callback (widget, client_data, call_data) |
06a2c219 GM |
7753 | Widget widget; |
7754 | XtPointer client_data, call_data; | |
7755 | { | |
7756 | struct scroll_bar *bar = (struct scroll_bar *) client_data; | |
7757 | float top = *(float *) call_data; | |
7758 | float shown; | |
ec18280f SM |
7759 | int whole, portion, height; |
7760 | int part; | |
06a2c219 GM |
7761 | |
7762 | /* Get the size of the thumb, a value between 0 and 1. */ | |
7763 | BLOCK_INPUT; | |
ec18280f | 7764 | XtVaGetValues (widget, XtNshown, &shown, XtNheight, &height, NULL); |
06a2c219 GM |
7765 | UNBLOCK_INPUT; |
7766 | ||
7767 | whole = 10000000; | |
7768 | portion = shown < 1 ? top * whole : 0; | |
06a2c219 | 7769 | |
ec18280f SM |
7770 | if (shown < 1 && (abs (top + shown - 1) < 1.0/height)) |
7771 | /* Some derivatives of Xaw refuse to shrink the thumb when you reach | |
7772 | the bottom, so we force the scrolling whenever we see that we're | |
7773 | too close to the bottom (in x_set_toolkit_scroll_bar_thumb | |
7774 | we try to ensure that we always stay two pixels away from the | |
7775 | bottom). */ | |
06a2c219 GM |
7776 | part = scroll_bar_down_arrow; |
7777 | else | |
7778 | part = scroll_bar_handle; | |
7779 | ||
7780 | window_being_scrolled = bar->window; | |
7781 | bar->dragging = make_number (portion); | |
7782 | last_scroll_bar_part = part; | |
7783 | x_send_scroll_bar_event (bar->window, part, portion, whole); | |
7784 | } | |
7785 | ||
7786 | ||
ec18280f SM |
7787 | /* Xaw scroll bar callback. Invoked for incremental scrolling., |
7788 | i.e. line or page up or down. WIDGET is the Xaw scroll bar | |
06a2c219 GM |
7789 | widget. CLIENT_DATA is a pointer to the scroll_bar structure for |
7790 | the scroll bar. CALL_DATA is an integer specifying the action that | |
7791 | has taken place. It's magnitude is in the range 0..height of the | |
7792 | scroll bar. Negative values mean scroll towards buffer start. | |
7793 | Values < height of scroll bar mean line-wise movement. */ | |
7794 | ||
7795 | static void | |
ec18280f | 7796 | xaw_scroll_callback (widget, client_data, call_data) |
06a2c219 GM |
7797 | Widget widget; |
7798 | XtPointer client_data, call_data; | |
7799 | { | |
7800 | struct scroll_bar *bar = (struct scroll_bar *) client_data; | |
7801 | int position = (int) call_data; | |
7802 | Dimension height; | |
7803 | int part; | |
7804 | ||
7805 | /* Get the height of the scroll bar. */ | |
7806 | BLOCK_INPUT; | |
7807 | XtVaGetValues (widget, XtNheight, &height, NULL); | |
7808 | UNBLOCK_INPUT; | |
7809 | ||
ec18280f SM |
7810 | if (abs (position) >= height) |
7811 | part = (position < 0) ? scroll_bar_above_handle : scroll_bar_below_handle; | |
7812 | ||
7813 | /* If Xaw3d was compiled with ARROW_SCROLLBAR, | |
7814 | it maps line-movement to call_data = max(5, height/20). */ | |
7815 | else if (xaw3d_arrow_scroll && abs (position) <= max (5, height / 20)) | |
7816 | part = (position < 0) ? scroll_bar_up_arrow : scroll_bar_down_arrow; | |
06a2c219 | 7817 | else |
ec18280f | 7818 | part = scroll_bar_move_ratio; |
06a2c219 GM |
7819 | |
7820 | window_being_scrolled = bar->window; | |
7821 | bar->dragging = Qnil; | |
7822 | last_scroll_bar_part = part; | |
ec18280f | 7823 | x_send_scroll_bar_event (bar->window, part, position, height); |
06a2c219 GM |
7824 | } |
7825 | ||
7826 | ||
7827 | #endif /* not USE_MOTIF */ | |
7828 | ||
7829 | ||
7830 | /* Create the widget for scroll bar BAR on frame F. Record the widget | |
7831 | and X window of the scroll bar in BAR. */ | |
7832 | ||
7833 | static void | |
7834 | x_create_toolkit_scroll_bar (f, bar) | |
7835 | struct frame *f; | |
7836 | struct scroll_bar *bar; | |
7837 | { | |
7838 | Window xwindow; | |
7839 | Widget widget; | |
7840 | Arg av[20]; | |
7841 | int ac = 0; | |
7842 | char *scroll_bar_name = "verticalScrollBar"; | |
7843 | unsigned long pixel; | |
7844 | ||
7845 | BLOCK_INPUT; | |
7846 | ||
7847 | #ifdef USE_MOTIF | |
7848 | /* LessTif 0.85, problems: | |
7849 | ||
7850 | 1. When the mouse if over the scroll bar, the scroll bar will | |
7851 | get keyboard events. I didn't find a way to turn this off. | |
7852 | ||
7853 | 2. Do we have to explicitly set the cursor to get an arrow | |
7854 | cursor (see below)? */ | |
7855 | ||
7856 | /* Set resources. Create the widget. */ | |
7857 | XtSetArg (av[ac], XtNmappedWhenManaged, False); ++ac; | |
7858 | XtSetArg (av[ac], XmNminimum, XM_SB_MIN); ++ac; | |
7859 | XtSetArg (av[ac], XmNmaximum, XM_SB_MAX); ++ac; | |
7860 | XtSetArg (av[ac], XmNorientation, XmVERTICAL); ++ac; | |
7861 | XtSetArg (av[ac], XmNprocessingDirection, XmMAX_ON_BOTTOM), ++ac; | |
7862 | XtSetArg (av[ac], XmNincrement, 1); ++ac; | |
7863 | XtSetArg (av[ac], XmNpageIncrement, 1); ++ac; | |
7864 | ||
7865 | pixel = f->output_data.x->scroll_bar_foreground_pixel; | |
7866 | if (pixel != -1) | |
7867 | { | |
7868 | XtSetArg (av[ac], XmNforeground, pixel); | |
7869 | ++ac; | |
7870 | } | |
7871 | ||
7872 | pixel = f->output_data.x->scroll_bar_background_pixel; | |
7873 | if (pixel != -1) | |
7874 | { | |
7875 | XtSetArg (av[ac], XmNbackground, pixel); | |
7876 | ++ac; | |
7877 | } | |
7878 | ||
7879 | widget = XmCreateScrollBar (f->output_data.x->edit_widget, | |
7880 | scroll_bar_name, av, ac); | |
7881 | ||
7882 | /* Add one callback for everything that can happen. */ | |
7883 | XtAddCallback (widget, XmNdecrementCallback, xm_scroll_callback, | |
7884 | (XtPointer) bar); | |
7885 | XtAddCallback (widget, XmNdragCallback, xm_scroll_callback, | |
7886 | (XtPointer) bar); | |
7887 | XtAddCallback (widget, XmNincrementCallback, xm_scroll_callback, | |
7888 | (XtPointer) bar); | |
7889 | XtAddCallback (widget, XmNpageDecrementCallback, xm_scroll_callback, | |
7890 | (XtPointer) bar); | |
7891 | XtAddCallback (widget, XmNpageIncrementCallback, xm_scroll_callback, | |
7892 | (XtPointer) bar); | |
7893 | XtAddCallback (widget, XmNtoBottomCallback, xm_scroll_callback, | |
7894 | (XtPointer) bar); | |
7895 | XtAddCallback (widget, XmNtoTopCallback, xm_scroll_callback, | |
7896 | (XtPointer) bar); | |
7897 | ||
7898 | /* Realize the widget. Only after that is the X window created. */ | |
7899 | XtRealizeWidget (widget); | |
7900 | ||
7901 | /* Set the cursor to an arrow. I didn't find a resource to do that. | |
7902 | And I'm wondering why it hasn't an arrow cursor by default. */ | |
7903 | XDefineCursor (XtDisplay (widget), XtWindow (widget), | |
7904 | f->output_data.x->nontext_cursor); | |
7905 | ||
ec18280f | 7906 | #else /* !USE_MOTIF i.e. use Xaw */ |
06a2c219 GM |
7907 | |
7908 | /* Set resources. Create the widget. The background of the | |
7909 | Xaw3d scroll bar widget is a little bit light for my taste. | |
7910 | We don't alter it here to let users change it according | |
7911 | to their taste with `emacs*verticalScrollBar.background: xxx'. */ | |
7912 | XtSetArg (av[ac], XtNmappedWhenManaged, False); ++ac; | |
7913 | XtSetArg (av[ac], XtNorientation, XtorientVertical); ++ac; | |
ec18280f SM |
7914 | /* For smoother scrolling with Xaw3d -sm */ |
7915 | /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */ | |
7916 | /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */ | |
06a2c219 GM |
7917 | |
7918 | pixel = f->output_data.x->scroll_bar_foreground_pixel; | |
7919 | if (pixel != -1) | |
7920 | { | |
7921 | XtSetArg (av[ac], XtNforeground, pixel); | |
7922 | ++ac; | |
7923 | } | |
7924 | ||
7925 | pixel = f->output_data.x->scroll_bar_background_pixel; | |
7926 | if (pixel != -1) | |
7927 | { | |
7928 | XtSetArg (av[ac], XtNbackground, pixel); | |
7929 | ++ac; | |
7930 | } | |
7931 | ||
7932 | widget = XtCreateWidget (scroll_bar_name, scrollbarWidgetClass, | |
7933 | f->output_data.x->edit_widget, av, ac); | |
ec18280f SM |
7934 | |
7935 | { | |
7936 | char *initial = ""; | |
7937 | char *val = initial; | |
7938 | XtVaGetValues (widget, XtNscrollVCursor, (XtPointer) &val, | |
7939 | XtNpickTop, (XtPointer) &xaw3d_pick_top, NULL); | |
7940 | if (val == initial) | |
7941 | { /* ARROW_SCROLL */ | |
7942 | xaw3d_arrow_scroll = True; | |
7943 | /* Isn't that just a personal preference ? -sm */ | |
7944 | XtVaSetValues (widget, XtNcursorName, "top_left_arrow", NULL); | |
7945 | } | |
7946 | } | |
06a2c219 GM |
7947 | |
7948 | /* Define callbacks. */ | |
ec18280f SM |
7949 | XtAddCallback (widget, XtNjumpProc, xaw_jump_callback, (XtPointer) bar); |
7950 | XtAddCallback (widget, XtNscrollProc, xaw_scroll_callback, | |
06a2c219 GM |
7951 | (XtPointer) bar); |
7952 | ||
7953 | /* Realize the widget. Only after that is the X window created. */ | |
7954 | XtRealizeWidget (widget); | |
7955 | ||
ec18280f | 7956 | #endif /* !USE_MOTIF */ |
06a2c219 GM |
7957 | |
7958 | /* Install an action hook that let's us detect when the user | |
7959 | finishes interacting with a scroll bar. */ | |
7960 | if (action_hook_id == 0) | |
7961 | action_hook_id = XtAppAddActionHook (Xt_app_con, xt_action_hook, 0); | |
7962 | ||
7963 | /* Remember X window and widget in the scroll bar vector. */ | |
7964 | SET_SCROLL_BAR_X_WIDGET (bar, widget); | |
7965 | xwindow = XtWindow (widget); | |
7966 | SET_SCROLL_BAR_X_WINDOW (bar, xwindow); | |
7967 | ||
7968 | UNBLOCK_INPUT; | |
7969 | } | |
7970 | ||
7971 | ||
7972 | /* Set the thumb size and position of scroll bar BAR. We are currently | |
7973 | displaying PORTION out of a whole WHOLE, and our position POSITION. */ | |
7974 | ||
7975 | static void | |
7976 | x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole) | |
7977 | struct scroll_bar *bar; | |
7978 | int portion, position, whole; | |
f451eb13 | 7979 | { |
06a2c219 | 7980 | float top, shown; |
06a2c219 | 7981 | Widget widget = SCROLL_BAR_X_WIDGET (bar); |
f451eb13 | 7982 | |
06a2c219 GM |
7983 | if (whole == 0) |
7984 | top = 0, shown = 1; | |
7985 | else | |
f451eb13 | 7986 | { |
06a2c219 GM |
7987 | top = (float) position / whole; |
7988 | shown = (float) portion / whole; | |
7989 | } | |
f451eb13 | 7990 | |
06a2c219 | 7991 | BLOCK_INPUT; |
f451eb13 | 7992 | |
06a2c219 GM |
7993 | #ifdef USE_MOTIF |
7994 | { | |
7995 | int size, value; | |
7996 | Boolean arrow1_selected, arrow2_selected; | |
7997 | unsigned char flags; | |
7998 | XmScrollBarWidget sb; | |
7999 | ||
ec18280f | 8000 | /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX |
06a2c219 GM |
8001 | is the scroll bar's maximum and MIN is the scroll bar's minimum |
8002 | value. */ | |
8003 | size = shown * XM_SB_RANGE; | |
8004 | size = min (size, XM_SB_RANGE); | |
8005 | size = max (size, 1); | |
8006 | ||
8007 | /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */ | |
8008 | value = top * XM_SB_RANGE; | |
8009 | value = min (value, XM_SB_MAX - size); | |
8010 | value = max (value, XM_SB_MIN); | |
8011 | ||
8012 | /* LessTif: Calling XmScrollBarSetValues after an increment or | |
8013 | decrement turns off auto-repeat LessTif-internally. This can | |
8014 | be seen in ScrollBar.c which resets Arrow1Selected and | |
8015 | Arrow2Selected. It also sets internal flags so that LessTif | |
8016 | believes the mouse is in the slider. We either have to change | |
8017 | our code, or work around that by accessing private data. */ | |
8018 | ||
8019 | sb = (XmScrollBarWidget) widget; | |
8020 | arrow1_selected = sb->scrollBar.arrow1_selected; | |
8021 | arrow2_selected = sb->scrollBar.arrow2_selected; | |
8022 | flags = sb->scrollBar.flags; | |
8023 | ||
8024 | if (NILP (bar->dragging)) | |
8025 | XmScrollBarSetValues (widget, value, size, 0, 0, False); | |
8026 | else if (last_scroll_bar_part == scroll_bar_down_arrow) | |
8027 | /* This has the negative side effect that the slider value is | |
ec18280f | 8028 | not what it would be if we scrolled here using line-wise or |
06a2c219 GM |
8029 | page-wise movement. */ |
8030 | XmScrollBarSetValues (widget, value, XM_SB_RANGE - value, 0, 0, False); | |
8031 | else | |
8032 | { | |
8033 | /* If currently dragging, only update the slider size. | |
8034 | This reduces flicker effects. */ | |
8035 | int old_value, old_size, increment, page_increment; | |
8036 | ||
8037 | XmScrollBarGetValues (widget, &old_value, &old_size, | |
8038 | &increment, &page_increment); | |
8039 | XmScrollBarSetValues (widget, old_value, | |
8040 | min (size, XM_SB_RANGE - old_value), | |
8041 | 0, 0, False); | |
8042 | } | |
8043 | ||
8044 | sb->scrollBar.arrow1_selected = arrow1_selected; | |
8045 | sb->scrollBar.arrow2_selected = arrow2_selected; | |
8046 | sb->scrollBar.flags = flags; | |
8047 | } | |
ec18280f | 8048 | #else /* !USE_MOTIF i.e. use Xaw */ |
06a2c219 | 8049 | { |
ec18280f SM |
8050 | float old_top, old_shown; |
8051 | Dimension height; | |
8052 | XtVaGetValues (widget, | |
8053 | XtNtopOfThumb, &old_top, | |
8054 | XtNshown, &old_shown, | |
8055 | XtNheight, &height, | |
8056 | NULL); | |
8057 | ||
8058 | /* Massage the top+shown values. */ | |
8059 | if (NILP (bar->dragging) || last_scroll_bar_part == scroll_bar_down_arrow) | |
8060 | top = max (0, min (1, top)); | |
8061 | else | |
8062 | top = old_top; | |
8063 | /* Keep two pixels available for moving the thumb down. */ | |
8064 | shown = max (0, min (1 - top - (2.0 / height), shown)); | |
06a2c219 GM |
8065 | |
8066 | /* If the call to XawScrollbarSetThumb below doesn't seem to work, | |
8067 | check that your system's configuration file contains a define | |
8068 | for `NARROWPROTO'. See s/freebsd.h for an example. */ | |
ec18280f | 8069 | if (top != old_top || shown != old_shown) |
eb393530 | 8070 | { |
ec18280f | 8071 | if (NILP (bar->dragging)) |
eb393530 | 8072 | XawScrollbarSetThumb (widget, top, shown); |
06a2c219 GM |
8073 | else |
8074 | { | |
ec18280f SM |
8075 | #ifdef HAVE_XAW3D |
8076 | ScrollbarWidget sb = (ScrollbarWidget) widget; | |
3e71d8f2 | 8077 | int scroll_mode = 0; |
ec18280f SM |
8078 | |
8079 | /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */ | |
8080 | if (xaw3d_arrow_scroll) | |
8081 | { | |
8082 | /* Xaw3d stupidly ignores resize requests while dragging | |
8083 | so we have to make it believe it's not in dragging mode. */ | |
8084 | scroll_mode = sb->scrollbar.scroll_mode; | |
8085 | if (scroll_mode == 2) | |
8086 | sb->scrollbar.scroll_mode = 0; | |
8087 | } | |
8088 | #endif | |
8089 | /* Try to make the scrolling a tad smoother. */ | |
8090 | if (!xaw3d_pick_top) | |
8091 | shown = min (shown, old_shown); | |
8092 | ||
8093 | XawScrollbarSetThumb (widget, top, shown); | |
8094 | ||
8095 | #ifdef HAVE_XAW3D | |
8096 | if (xaw3d_arrow_scroll && scroll_mode == 2) | |
8097 | sb->scrollbar.scroll_mode = scroll_mode; | |
8098 | #endif | |
06a2c219 | 8099 | } |
06a2c219 GM |
8100 | } |
8101 | } | |
ec18280f | 8102 | #endif /* !USE_MOTIF */ |
06a2c219 GM |
8103 | |
8104 | UNBLOCK_INPUT; | |
f451eb13 JB |
8105 | } |
8106 | ||
06a2c219 GM |
8107 | #endif /* USE_TOOLKIT_SCROLL_BARS */ |
8108 | ||
8109 | ||
8110 | \f | |
8111 | /************************************************************************ | |
8112 | Scroll bars, general | |
8113 | ************************************************************************/ | |
8114 | ||
8115 | /* Create a scroll bar and return the scroll bar vector for it. W is | |
8116 | the Emacs window on which to create the scroll bar. TOP, LEFT, | |
8117 | WIDTH and HEIGHT are.the pixel coordinates and dimensions of the | |
8118 | scroll bar. */ | |
8119 | ||
ab648270 | 8120 | static struct scroll_bar * |
06a2c219 GM |
8121 | x_scroll_bar_create (w, top, left, width, height) |
8122 | struct window *w; | |
f451eb13 JB |
8123 | int top, left, width, height; |
8124 | { | |
06a2c219 | 8125 | struct frame *f = XFRAME (w->frame); |
334208b7 RS |
8126 | struct scroll_bar *bar |
8127 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | |
f451eb13 JB |
8128 | |
8129 | BLOCK_INPUT; | |
8130 | ||
06a2c219 GM |
8131 | #if USE_TOOLKIT_SCROLL_BARS |
8132 | x_create_toolkit_scroll_bar (f, bar); | |
8133 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
f451eb13 JB |
8134 | { |
8135 | XSetWindowAttributes a; | |
8136 | unsigned long mask; | |
5c187dee | 8137 | Window window; |
06a2c219 GM |
8138 | |
8139 | a.background_pixel = f->output_data.x->scroll_bar_background_pixel; | |
8140 | if (a.background_pixel == -1) | |
8141 | a.background_pixel = f->output_data.x->background_pixel; | |
8142 | ||
12ba150f | 8143 | a.event_mask = (ButtonPressMask | ButtonReleaseMask |
9a572e2a | 8144 | | ButtonMotionMask | PointerMotionHintMask |
12ba150f | 8145 | | ExposureMask); |
7a13e894 | 8146 | a.cursor = FRAME_X_DISPLAY_INFO (f)->vertical_scroll_bar_cursor; |
f451eb13 | 8147 | |
dbc4e1c1 | 8148 | mask = (CWBackPixel | CWEventMask | CWCursor); |
f451eb13 | 8149 | |
06a2c219 GM |
8150 | /* Clear the area of W that will serve as a scroll bar. This is |
8151 | for the case that a window has been split horizontally. In | |
8152 | this case, no clear_frame is generated to reduce flickering. */ | |
8153 | XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
8154 | left, top, width, | |
8155 | window_box_height (w), False); | |
8156 | ||
8157 | window = XCreateWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
8158 | /* Position and size of scroll bar. */ | |
8159 | left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
8160 | top, | |
8161 | width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
8162 | height, | |
8163 | /* Border width, depth, class, and visual. */ | |
8164 | 0, | |
8165 | CopyFromParent, | |
8166 | CopyFromParent, | |
8167 | CopyFromParent, | |
8168 | /* Attributes. */ | |
8169 | mask, &a); | |
8170 | SET_SCROLL_BAR_X_WINDOW (bar, window); | |
f451eb13 | 8171 | } |
06a2c219 | 8172 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
f451eb13 | 8173 | |
06a2c219 | 8174 | XSETWINDOW (bar->window, w); |
e0c1aef2 KH |
8175 | XSETINT (bar->top, top); |
8176 | XSETINT (bar->left, left); | |
8177 | XSETINT (bar->width, width); | |
8178 | XSETINT (bar->height, height); | |
8179 | XSETINT (bar->start, 0); | |
8180 | XSETINT (bar->end, 0); | |
12ba150f | 8181 | bar->dragging = Qnil; |
f451eb13 JB |
8182 | |
8183 | /* Add bar to its frame's list of scroll bars. */ | |
334208b7 | 8184 | bar->next = FRAME_SCROLL_BARS (f); |
12ba150f | 8185 | bar->prev = Qnil; |
334208b7 | 8186 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); |
06a2c219 | 8187 | if (!NILP (bar->next)) |
e0c1aef2 | 8188 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); |
f451eb13 | 8189 | |
06a2c219 GM |
8190 | /* Map the window/widget. */ |
8191 | #if USE_TOOLKIT_SCROLL_BARS | |
8192 | XtMapWidget (SCROLL_BAR_X_WIDGET (bar)); | |
8193 | XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar), | |
8194 | left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
8195 | top, | |
8196 | width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
8197 | height, 0); | |
8198 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
7f9c7f94 | 8199 | XMapRaised (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar)); |
06a2c219 | 8200 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
f451eb13 JB |
8201 | |
8202 | UNBLOCK_INPUT; | |
12ba150f | 8203 | return bar; |
f451eb13 JB |
8204 | } |
8205 | ||
06a2c219 | 8206 | |
12ba150f | 8207 | /* Draw BAR's handle in the proper position. |
06a2c219 | 8208 | |
12ba150f JB |
8209 | If the handle is already drawn from START to END, don't bother |
8210 | redrawing it, unless REBUILD is non-zero; in that case, always | |
8211 | redraw it. (REBUILD is handy for drawing the handle after expose | |
58769bee | 8212 | events.) |
12ba150f JB |
8213 | |
8214 | Normally, we want to constrain the start and end of the handle to | |
06a2c219 GM |
8215 | fit inside its rectangle, but if the user is dragging the scroll |
8216 | bar handle, we want to let them drag it down all the way, so that | |
8217 | the bar's top is as far down as it goes; otherwise, there's no way | |
8218 | to move to the very end of the buffer. */ | |
8219 | ||
5c187dee GM |
8220 | #ifndef USE_TOOLKIT_SCROLL_BARS |
8221 | ||
f451eb13 | 8222 | static void |
ab648270 JB |
8223 | x_scroll_bar_set_handle (bar, start, end, rebuild) |
8224 | struct scroll_bar *bar; | |
f451eb13 | 8225 | int start, end; |
12ba150f | 8226 | int rebuild; |
f451eb13 | 8227 | { |
12ba150f | 8228 | int dragging = ! NILP (bar->dragging); |
ab648270 | 8229 | Window w = SCROLL_BAR_X_WINDOW (bar); |
334208b7 | 8230 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
7556890b | 8231 | GC gc = f->output_data.x->normal_gc; |
12ba150f JB |
8232 | |
8233 | /* If the display is already accurate, do nothing. */ | |
8234 | if (! rebuild | |
8235 | && start == XINT (bar->start) | |
8236 | && end == XINT (bar->end)) | |
8237 | return; | |
8238 | ||
f451eb13 JB |
8239 | BLOCK_INPUT; |
8240 | ||
8241 | { | |
d9cdbb3d RS |
8242 | int inside_width = VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f, XINT (bar->width)); |
8243 | int inside_height = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height)); | |
8244 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | |
f451eb13 JB |
8245 | |
8246 | /* Make sure the values are reasonable, and try to preserve | |
8247 | the distance between start and end. */ | |
12ba150f JB |
8248 | { |
8249 | int length = end - start; | |
8250 | ||
8251 | if (start < 0) | |
8252 | start = 0; | |
8253 | else if (start > top_range) | |
8254 | start = top_range; | |
8255 | end = start + length; | |
8256 | ||
8257 | if (end < start) | |
8258 | end = start; | |
8259 | else if (end > top_range && ! dragging) | |
8260 | end = top_range; | |
8261 | } | |
f451eb13 | 8262 | |
ab648270 | 8263 | /* Store the adjusted setting in the scroll bar. */ |
e0c1aef2 KH |
8264 | XSETINT (bar->start, start); |
8265 | XSETINT (bar->end, end); | |
f451eb13 | 8266 | |
12ba150f JB |
8267 | /* Clip the end position, just for display. */ |
8268 | if (end > top_range) | |
8269 | end = top_range; | |
f451eb13 | 8270 | |
ab648270 | 8271 | /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels |
12ba150f JB |
8272 | below top positions, to make sure the handle is always at least |
8273 | that many pixels tall. */ | |
ab648270 | 8274 | end += VERTICAL_SCROLL_BAR_MIN_HANDLE; |
f451eb13 | 8275 | |
12ba150f JB |
8276 | /* Draw the empty space above the handle. Note that we can't clear |
8277 | zero-height areas; that means "clear to end of window." */ | |
8278 | if (0 < start) | |
334208b7 | 8279 | XClearArea (FRAME_X_DISPLAY (f), w, |
f451eb13 | 8280 | |
12ba150f | 8281 | /* x, y, width, height, and exposures. */ |
ab648270 JB |
8282 | VERTICAL_SCROLL_BAR_LEFT_BORDER, |
8283 | VERTICAL_SCROLL_BAR_TOP_BORDER, | |
12ba150f JB |
8284 | inside_width, start, |
8285 | False); | |
f451eb13 | 8286 | |
06a2c219 GM |
8287 | /* Change to proper foreground color if one is specified. */ |
8288 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
8289 | XSetForeground (FRAME_X_DISPLAY (f), gc, | |
8290 | f->output_data.x->scroll_bar_foreground_pixel); | |
8291 | ||
12ba150f | 8292 | /* Draw the handle itself. */ |
334208b7 | 8293 | XFillRectangle (FRAME_X_DISPLAY (f), w, gc, |
f451eb13 | 8294 | |
12ba150f | 8295 | /* x, y, width, height */ |
ab648270 JB |
8296 | VERTICAL_SCROLL_BAR_LEFT_BORDER, |
8297 | VERTICAL_SCROLL_BAR_TOP_BORDER + start, | |
12ba150f | 8298 | inside_width, end - start); |
f451eb13 | 8299 | |
06a2c219 GM |
8300 | /* Restore the foreground color of the GC if we changed it above. */ |
8301 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
8302 | XSetForeground (FRAME_X_DISPLAY (f), gc, | |
8303 | f->output_data.x->foreground_pixel); | |
f451eb13 | 8304 | |
12ba150f JB |
8305 | /* Draw the empty space below the handle. Note that we can't |
8306 | clear zero-height areas; that means "clear to end of window." */ | |
8307 | if (end < inside_height) | |
334208b7 | 8308 | XClearArea (FRAME_X_DISPLAY (f), w, |
f451eb13 | 8309 | |
12ba150f | 8310 | /* x, y, width, height, and exposures. */ |
ab648270 JB |
8311 | VERTICAL_SCROLL_BAR_LEFT_BORDER, |
8312 | VERTICAL_SCROLL_BAR_TOP_BORDER + end, | |
12ba150f JB |
8313 | inside_width, inside_height - end, |
8314 | False); | |
f451eb13 | 8315 | |
f451eb13 JB |
8316 | } |
8317 | ||
f451eb13 JB |
8318 | UNBLOCK_INPUT; |
8319 | } | |
8320 | ||
5c187dee | 8321 | #endif /* !USE_TOOLKIT_SCROLL_BARS */ |
f451eb13 | 8322 | |
06a2c219 GM |
8323 | /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to |
8324 | nil. */ | |
58769bee | 8325 | |
12ba150f | 8326 | static void |
ab648270 JB |
8327 | x_scroll_bar_remove (bar) |
8328 | struct scroll_bar *bar; | |
12ba150f | 8329 | { |
12ba150f JB |
8330 | BLOCK_INPUT; |
8331 | ||
06a2c219 GM |
8332 | #if USE_TOOLKIT_SCROLL_BARS |
8333 | XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar)); | |
8334 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
5c187dee GM |
8335 | { |
8336 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
8337 | XDestroyWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar)); | |
8338 | } | |
06a2c219 GM |
8339 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
8340 | ||
ab648270 JB |
8341 | /* Disassociate this scroll bar from its window. */ |
8342 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | |
12ba150f JB |
8343 | |
8344 | UNBLOCK_INPUT; | |
8345 | } | |
8346 | ||
06a2c219 | 8347 | |
12ba150f JB |
8348 | /* Set the handle of the vertical scroll bar for WINDOW to indicate |
8349 | that we are displaying PORTION characters out of a total of WHOLE | |
ab648270 | 8350 | characters, starting at POSITION. If WINDOW has no scroll bar, |
12ba150f | 8351 | create one. */ |
06a2c219 | 8352 | |
12ba150f | 8353 | static void |
06a2c219 GM |
8354 | XTset_vertical_scroll_bar (w, portion, whole, position) |
8355 | struct window *w; | |
f451eb13 JB |
8356 | int portion, whole, position; |
8357 | { | |
06a2c219 | 8358 | struct frame *f = XFRAME (w->frame); |
ab648270 | 8359 | struct scroll_bar *bar; |
3c6ede7b | 8360 | int top, height, left, sb_left, width, sb_width; |
06a2c219 | 8361 | int window_x, window_y, window_width, window_height; |
06a2c219 | 8362 | |
3c6ede7b | 8363 | /* Get window dimensions. */ |
06a2c219 | 8364 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); |
3c6ede7b GM |
8365 | top = window_y; |
8366 | width = FRAME_SCROLL_BAR_COLS (f) * CANON_X_UNIT (f); | |
8367 | height = window_height; | |
06a2c219 | 8368 | |
3c6ede7b | 8369 | /* Compute the left edge of the scroll bar area. */ |
06a2c219 | 8370 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) |
3c6ede7b GM |
8371 | left = XINT (w->left) + XINT (w->width) - FRAME_SCROLL_BAR_COLS (f); |
8372 | else | |
8373 | left = XFASTINT (w->left); | |
8374 | left *= CANON_X_UNIT (f); | |
8375 | left += FRAME_INTERNAL_BORDER_WIDTH (f); | |
8376 | ||
8377 | /* Compute the width of the scroll bar which might be less than | |
8378 | the width of the area reserved for the scroll bar. */ | |
8379 | if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0) | |
8380 | sb_width = FRAME_SCROLL_BAR_PIXEL_WIDTH (f); | |
06a2c219 | 8381 | else |
3c6ede7b | 8382 | sb_width = width; |
12ba150f | 8383 | |
3c6ede7b GM |
8384 | /* Compute the left edge of the scroll bar. */ |
8385 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
8386 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
8387 | sb_left = left + width - sb_width - (width - sb_width) / 2; | |
8388 | else | |
8389 | sb_left = left + (width - sb_width) / 2; | |
8390 | #else | |
8391 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
8392 | sb_left = left + width - sb_width; | |
8393 | else | |
8394 | sb_left = left; | |
8395 | #endif | |
8396 | ||
ab648270 | 8397 | /* Does the scroll bar exist yet? */ |
06a2c219 | 8398 | if (NILP (w->vertical_scroll_bar)) |
3c6ede7b | 8399 | { |
80c32bcc | 8400 | BLOCK_INPUT; |
3c6ede7b GM |
8401 | XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
8402 | left, top, width, height, False); | |
80c32bcc | 8403 | UNBLOCK_INPUT; |
3c6ede7b GM |
8404 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height); |
8405 | } | |
f451eb13 | 8406 | else |
12ba150f JB |
8407 | { |
8408 | /* It may just need to be moved and resized. */ | |
06a2c219 GM |
8409 | unsigned int mask = 0; |
8410 | ||
8411 | bar = XSCROLL_BAR (w->vertical_scroll_bar); | |
8412 | ||
8413 | BLOCK_INPUT; | |
8414 | ||
3c6ede7b | 8415 | if (sb_left != XINT (bar->left)) |
06a2c219 | 8416 | mask |= CWX; |
3c6ede7b | 8417 | if (top != XINT (bar->top)) |
06a2c219 | 8418 | mask |= CWY; |
3c6ede7b | 8419 | if (sb_width != XINT (bar->width)) |
06a2c219 | 8420 | mask |= CWWidth; |
3c6ede7b | 8421 | if (height != XINT (bar->height)) |
06a2c219 GM |
8422 | mask |= CWHeight; |
8423 | ||
8424 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
fe6f39d9 GM |
8425 | |
8426 | /* Since toolkit scroll bars are smaller than the space reserved | |
8427 | for them on the frame, we have to clear "under" them. */ | |
8428 | XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
3c6ede7b | 8429 | left, top, width, height, False); |
06a2c219 GM |
8430 | |
8431 | /* Move/size the scroll bar widget. */ | |
8432 | if (mask) | |
8433 | XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar), | |
3c6ede7b GM |
8434 | sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, |
8435 | top, | |
8436 | sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
8437 | height, 0); | |
06a2c219 GM |
8438 | |
8439 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
8440 | ||
e1f6572f RS |
8441 | if (VERTICAL_SCROLL_BAR_WIDTH_TRIM) |
8442 | { | |
8443 | /* Clear areas not covered by the scroll bar. This makes sure a | |
8444 | previous mode line display is cleared after C-x 2 C-x 1, for | |
8445 | example. Non-toolkit scroll bars are as wide as the area | |
8446 | reserved for scroll bars - trim at both sides. */ | |
8447 | XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
8448 | left, top, VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
8449 | height, False); | |
8450 | XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
8451 | left + width - VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
8452 | top, VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
8453 | height, False); | |
8454 | } | |
06a2c219 GM |
8455 | |
8456 | /* Move/size the scroll bar window. */ | |
8457 | if (mask) | |
8458 | { | |
8459 | XWindowChanges wc; | |
8460 | ||
3c6ede7b GM |
8461 | wc.x = sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM; |
8462 | wc.y = top; | |
8463 | wc.width = sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2; | |
8464 | wc.height = height; | |
06a2c219 GM |
8465 | XConfigureWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar), |
8466 | mask, &wc); | |
8467 | } | |
8468 | ||
8469 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ | |
8470 | ||
8471 | /* Remember new settings. */ | |
3c6ede7b GM |
8472 | XSETINT (bar->left, sb_left); |
8473 | XSETINT (bar->top, top); | |
8474 | XSETINT (bar->width, sb_width); | |
8475 | XSETINT (bar->height, height); | |
06a2c219 GM |
8476 | |
8477 | UNBLOCK_INPUT; | |
12ba150f | 8478 | } |
f451eb13 | 8479 | |
06a2c219 GM |
8480 | #if USE_TOOLKIT_SCROLL_BARS |
8481 | x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole); | |
8482 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
ab648270 | 8483 | /* Set the scroll bar's current state, unless we're currently being |
f451eb13 | 8484 | dragged. */ |
12ba150f | 8485 | if (NILP (bar->dragging)) |
f451eb13 | 8486 | { |
92857db0 | 8487 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height); |
f451eb13 | 8488 | |
12ba150f | 8489 | if (whole == 0) |
ab648270 | 8490 | x_scroll_bar_set_handle (bar, 0, top_range, 0); |
12ba150f JB |
8491 | else |
8492 | { | |
43f868f5 JB |
8493 | int start = ((double) position * top_range) / whole; |
8494 | int end = ((double) (position + portion) * top_range) / whole; | |
ab648270 | 8495 | x_scroll_bar_set_handle (bar, start, end, 0); |
12ba150f | 8496 | } |
f451eb13 | 8497 | } |
06a2c219 | 8498 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
f451eb13 | 8499 | |
06a2c219 | 8500 | XSETVECTOR (w->vertical_scroll_bar, bar); |
f451eb13 JB |
8501 | } |
8502 | ||
12ba150f | 8503 | |
f451eb13 | 8504 | /* The following three hooks are used when we're doing a thorough |
ab648270 | 8505 | redisplay of the frame. We don't explicitly know which scroll bars |
f451eb13 | 8506 | are going to be deleted, because keeping track of when windows go |
12ba150f JB |
8507 | away is a real pain - "Can you say set-window-configuration, boys |
8508 | and girls?" Instead, we just assert at the beginning of redisplay | |
ab648270 | 8509 | that *all* scroll bars are to be removed, and then save a scroll bar |
12ba150f | 8510 | from the fiery pit when we actually redisplay its window. */ |
f451eb13 | 8511 | |
ab648270 JB |
8512 | /* Arrange for all scroll bars on FRAME to be removed at the next call |
8513 | to `*judge_scroll_bars_hook'. A scroll bar may be spared if | |
06a2c219 GM |
8514 | `*redeem_scroll_bar_hook' is applied to its window before the judgment. */ |
8515 | ||
58769bee | 8516 | static void |
ab648270 | 8517 | XTcondemn_scroll_bars (frame) |
f451eb13 JB |
8518 | FRAME_PTR frame; |
8519 | { | |
f9e24cb9 RS |
8520 | /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */ |
8521 | while (! NILP (FRAME_SCROLL_BARS (frame))) | |
8522 | { | |
8523 | Lisp_Object bar; | |
8524 | bar = FRAME_SCROLL_BARS (frame); | |
8525 | FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next; | |
8526 | XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame); | |
8527 | XSCROLL_BAR (bar)->prev = Qnil; | |
8528 | if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame))) | |
8529 | XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar; | |
8530 | FRAME_CONDEMNED_SCROLL_BARS (frame) = bar; | |
8531 | } | |
f451eb13 JB |
8532 | } |
8533 | ||
06a2c219 | 8534 | /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle. |
12ba150f | 8535 | Note that WINDOW isn't necessarily condemned at all. */ |
f451eb13 | 8536 | static void |
ab648270 | 8537 | XTredeem_scroll_bar (window) |
12ba150f | 8538 | struct window *window; |
f451eb13 | 8539 | { |
ab648270 | 8540 | struct scroll_bar *bar; |
12ba150f | 8541 | |
ab648270 JB |
8542 | /* We can't redeem this window's scroll bar if it doesn't have one. */ |
8543 | if (NILP (window->vertical_scroll_bar)) | |
12ba150f JB |
8544 | abort (); |
8545 | ||
ab648270 | 8546 | bar = XSCROLL_BAR (window->vertical_scroll_bar); |
12ba150f JB |
8547 | |
8548 | /* Unlink it from the condemned list. */ | |
8549 | { | |
8550 | FRAME_PTR f = XFRAME (WINDOW_FRAME (window)); | |
8551 | ||
8552 | if (NILP (bar->prev)) | |
8553 | { | |
8554 | /* If the prev pointer is nil, it must be the first in one of | |
8555 | the lists. */ | |
ab648270 | 8556 | if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar)) |
12ba150f JB |
8557 | /* It's not condemned. Everything's fine. */ |
8558 | return; | |
ab648270 JB |
8559 | else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f), |
8560 | window->vertical_scroll_bar)) | |
8561 | FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next; | |
12ba150f JB |
8562 | else |
8563 | /* If its prev pointer is nil, it must be at the front of | |
8564 | one or the other! */ | |
8565 | abort (); | |
8566 | } | |
8567 | else | |
ab648270 | 8568 | XSCROLL_BAR (bar->prev)->next = bar->next; |
12ba150f JB |
8569 | |
8570 | if (! NILP (bar->next)) | |
ab648270 | 8571 | XSCROLL_BAR (bar->next)->prev = bar->prev; |
12ba150f | 8572 | |
ab648270 | 8573 | bar->next = FRAME_SCROLL_BARS (f); |
12ba150f | 8574 | bar->prev = Qnil; |
e0c1aef2 | 8575 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); |
12ba150f | 8576 | if (! NILP (bar->next)) |
e0c1aef2 | 8577 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); |
12ba150f | 8578 | } |
f451eb13 JB |
8579 | } |
8580 | ||
ab648270 JB |
8581 | /* Remove all scroll bars on FRAME that haven't been saved since the |
8582 | last call to `*condemn_scroll_bars_hook'. */ | |
06a2c219 | 8583 | |
f451eb13 | 8584 | static void |
ab648270 | 8585 | XTjudge_scroll_bars (f) |
12ba150f | 8586 | FRAME_PTR f; |
f451eb13 | 8587 | { |
12ba150f | 8588 | Lisp_Object bar, next; |
f451eb13 | 8589 | |
ab648270 | 8590 | bar = FRAME_CONDEMNED_SCROLL_BARS (f); |
cf7cb199 JB |
8591 | |
8592 | /* Clear out the condemned list now so we won't try to process any | |
ab648270 JB |
8593 | more events on the hapless scroll bars. */ |
8594 | FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil; | |
cf7cb199 JB |
8595 | |
8596 | for (; ! NILP (bar); bar = next) | |
f451eb13 | 8597 | { |
ab648270 | 8598 | struct scroll_bar *b = XSCROLL_BAR (bar); |
12ba150f | 8599 | |
ab648270 | 8600 | x_scroll_bar_remove (b); |
12ba150f JB |
8601 | |
8602 | next = b->next; | |
8603 | b->next = b->prev = Qnil; | |
f451eb13 | 8604 | } |
12ba150f | 8605 | |
ab648270 | 8606 | /* Now there should be no references to the condemned scroll bars, |
12ba150f | 8607 | and they should get garbage-collected. */ |
f451eb13 JB |
8608 | } |
8609 | ||
8610 | ||
06a2c219 GM |
8611 | /* Handle an Expose or GraphicsExpose event on a scroll bar. This |
8612 | is a no-op when using toolkit scroll bars. | |
ab648270 JB |
8613 | |
8614 | This may be called from a signal handler, so we have to ignore GC | |
8615 | mark bits. */ | |
06a2c219 | 8616 | |
f451eb13 | 8617 | static void |
ab648270 JB |
8618 | x_scroll_bar_expose (bar, event) |
8619 | struct scroll_bar *bar; | |
f451eb13 JB |
8620 | XEvent *event; |
8621 | { | |
06a2c219 GM |
8622 | #ifndef USE_TOOLKIT_SCROLL_BARS |
8623 | ||
ab648270 | 8624 | Window w = SCROLL_BAR_X_WINDOW (bar); |
334208b7 | 8625 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
7556890b | 8626 | GC gc = f->output_data.x->normal_gc; |
3cbd2e0b | 8627 | int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM; |
12ba150f | 8628 | |
f451eb13 JB |
8629 | BLOCK_INPUT; |
8630 | ||
ab648270 | 8631 | x_scroll_bar_set_handle (bar, XINT (bar->start), XINT (bar->end), 1); |
f451eb13 | 8632 | |
06a2c219 | 8633 | /* Draw a one-pixel border just inside the edges of the scroll bar. */ |
334208b7 | 8634 | XDrawRectangle (FRAME_X_DISPLAY (f), w, gc, |
f451eb13 JB |
8635 | |
8636 | /* x, y, width, height */ | |
d9cdbb3d | 8637 | 0, 0, |
3cbd2e0b | 8638 | XINT (bar->width) - 1 - width_trim - width_trim, |
d9cdbb3d RS |
8639 | XINT (bar->height) - 1); |
8640 | ||
f451eb13 | 8641 | UNBLOCK_INPUT; |
06a2c219 GM |
8642 | |
8643 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ | |
f451eb13 JB |
8644 | } |
8645 | ||
ab648270 JB |
8646 | /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind |
8647 | is set to something other than no_event, it is enqueued. | |
8648 | ||
8649 | This may be called from a signal handler, so we have to ignore GC | |
8650 | mark bits. */ | |
06a2c219 | 8651 | |
5c187dee GM |
8652 | #ifndef USE_TOOLKIT_SCROLL_BARS |
8653 | ||
f451eb13 | 8654 | static void |
ab648270 JB |
8655 | x_scroll_bar_handle_click (bar, event, emacs_event) |
8656 | struct scroll_bar *bar; | |
f451eb13 JB |
8657 | XEvent *event; |
8658 | struct input_event *emacs_event; | |
8659 | { | |
0299d313 | 8660 | if (! GC_WINDOWP (bar->window)) |
12ba150f JB |
8661 | abort (); |
8662 | ||
ab648270 | 8663 | emacs_event->kind = scroll_bar_click; |
69388238 | 8664 | emacs_event->code = event->xbutton.button - Button1; |
0299d313 RS |
8665 | emacs_event->modifiers |
8666 | = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO | |
8667 | (XFRAME (WINDOW_FRAME (XWINDOW (bar->window)))), | |
8668 | event->xbutton.state) | |
8669 | | (event->type == ButtonRelease | |
8670 | ? up_modifier | |
8671 | : down_modifier)); | |
12ba150f | 8672 | emacs_event->frame_or_window = bar->window; |
0f8aabe9 | 8673 | emacs_event->arg = Qnil; |
f451eb13 | 8674 | emacs_event->timestamp = event->xbutton.time; |
12ba150f | 8675 | { |
06a2c219 | 8676 | #if 0 |
d9cdbb3d | 8677 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
0299d313 | 8678 | int internal_height |
d9cdbb3d | 8679 | = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height)); |
06a2c219 | 8680 | #endif |
0299d313 | 8681 | int top_range |
d9cdbb3d | 8682 | = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
ab648270 | 8683 | int y = event->xbutton.y - VERTICAL_SCROLL_BAR_TOP_BORDER; |
12ba150f JB |
8684 | |
8685 | if (y < 0) y = 0; | |
8686 | if (y > top_range) y = top_range; | |
8687 | ||
8688 | if (y < XINT (bar->start)) | |
ab648270 JB |
8689 | emacs_event->part = scroll_bar_above_handle; |
8690 | else if (y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE) | |
8691 | emacs_event->part = scroll_bar_handle; | |
12ba150f | 8692 | else |
ab648270 | 8693 | emacs_event->part = scroll_bar_below_handle; |
929787e1 JB |
8694 | |
8695 | /* Just because the user has clicked on the handle doesn't mean | |
5116f055 JB |
8696 | they want to drag it. Lisp code needs to be able to decide |
8697 | whether or not we're dragging. */ | |
929787e1 | 8698 | #if 0 |
12ba150f JB |
8699 | /* If the user has just clicked on the handle, record where they're |
8700 | holding it. */ | |
8701 | if (event->type == ButtonPress | |
ab648270 | 8702 | && emacs_event->part == scroll_bar_handle) |
e0c1aef2 | 8703 | XSETINT (bar->dragging, y - XINT (bar->start)); |
929787e1 | 8704 | #endif |
12ba150f JB |
8705 | |
8706 | /* If the user has released the handle, set it to its final position. */ | |
8707 | if (event->type == ButtonRelease | |
8708 | && ! NILP (bar->dragging)) | |
8709 | { | |
8710 | int new_start = y - XINT (bar->dragging); | |
8711 | int new_end = new_start + (XINT (bar->end) - XINT (bar->start)); | |
f451eb13 | 8712 | |
ab648270 | 8713 | x_scroll_bar_set_handle (bar, new_start, new_end, 0); |
12ba150f JB |
8714 | bar->dragging = Qnil; |
8715 | } | |
f451eb13 | 8716 | |
5116f055 JB |
8717 | /* Same deal here as the other #if 0. */ |
8718 | #if 0 | |
58769bee | 8719 | /* Clicks on the handle are always reported as occurring at the top of |
12ba150f | 8720 | the handle. */ |
ab648270 | 8721 | if (emacs_event->part == scroll_bar_handle) |
12ba150f JB |
8722 | emacs_event->x = bar->start; |
8723 | else | |
e0c1aef2 | 8724 | XSETINT (emacs_event->x, y); |
5116f055 | 8725 | #else |
e0c1aef2 | 8726 | XSETINT (emacs_event->x, y); |
5116f055 | 8727 | #endif |
f451eb13 | 8728 | |
e0c1aef2 | 8729 | XSETINT (emacs_event->y, top_range); |
12ba150f JB |
8730 | } |
8731 | } | |
f451eb13 | 8732 | |
ab648270 JB |
8733 | /* Handle some mouse motion while someone is dragging the scroll bar. |
8734 | ||
8735 | This may be called from a signal handler, so we have to ignore GC | |
8736 | mark bits. */ | |
06a2c219 | 8737 | |
f451eb13 | 8738 | static void |
ab648270 JB |
8739 | x_scroll_bar_note_movement (bar, event) |
8740 | struct scroll_bar *bar; | |
f451eb13 JB |
8741 | XEvent *event; |
8742 | { | |
39d8bb4d KH |
8743 | FRAME_PTR f = XFRAME (XWINDOW (bar->window)->frame); |
8744 | ||
f451eb13 JB |
8745 | last_mouse_movement_time = event->xmotion.time; |
8746 | ||
39d8bb4d | 8747 | f->mouse_moved = 1; |
e0c1aef2 | 8748 | XSETVECTOR (last_mouse_scroll_bar, bar); |
f451eb13 JB |
8749 | |
8750 | /* If we're dragging the bar, display it. */ | |
ab648270 | 8751 | if (! GC_NILP (bar->dragging)) |
f451eb13 JB |
8752 | { |
8753 | /* Where should the handle be now? */ | |
12ba150f | 8754 | int new_start = event->xmotion.y - XINT (bar->dragging); |
f451eb13 | 8755 | |
12ba150f | 8756 | if (new_start != XINT (bar->start)) |
f451eb13 | 8757 | { |
12ba150f | 8758 | int new_end = new_start + (XINT (bar->end) - XINT (bar->start)); |
58769bee | 8759 | |
ab648270 | 8760 | x_scroll_bar_set_handle (bar, new_start, new_end, 0); |
f451eb13 JB |
8761 | } |
8762 | } | |
f451eb13 JB |
8763 | } |
8764 | ||
5c187dee GM |
8765 | #endif /* !USE_TOOLKIT_SCROLL_BARS */ |
8766 | ||
12ba150f | 8767 | /* Return information to the user about the current position of the mouse |
ab648270 | 8768 | on the scroll bar. */ |
06a2c219 | 8769 | |
12ba150f | 8770 | static void |
334208b7 RS |
8771 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) |
8772 | FRAME_PTR *fp; | |
12ba150f | 8773 | Lisp_Object *bar_window; |
ab648270 | 8774 | enum scroll_bar_part *part; |
12ba150f JB |
8775 | Lisp_Object *x, *y; |
8776 | unsigned long *time; | |
8777 | { | |
ab648270 | 8778 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); |
334208b7 RS |
8779 | Window w = SCROLL_BAR_X_WINDOW (bar); |
8780 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
12ba150f | 8781 | int win_x, win_y; |
559cb2fb JB |
8782 | Window dummy_window; |
8783 | int dummy_coord; | |
8784 | unsigned int dummy_mask; | |
12ba150f | 8785 | |
cf7cb199 JB |
8786 | BLOCK_INPUT; |
8787 | ||
ab648270 | 8788 | /* Get the mouse's position relative to the scroll bar window, and |
12ba150f | 8789 | report that. */ |
334208b7 | 8790 | if (! XQueryPointer (FRAME_X_DISPLAY (f), w, |
12ba150f | 8791 | |
559cb2fb JB |
8792 | /* Root, child, root x and root y. */ |
8793 | &dummy_window, &dummy_window, | |
8794 | &dummy_coord, &dummy_coord, | |
12ba150f | 8795 | |
559cb2fb JB |
8796 | /* Position relative to scroll bar. */ |
8797 | &win_x, &win_y, | |
12ba150f | 8798 | |
559cb2fb JB |
8799 | /* Mouse buttons and modifier keys. */ |
8800 | &dummy_mask)) | |
7a13e894 | 8801 | ; |
559cb2fb JB |
8802 | else |
8803 | { | |
06a2c219 | 8804 | #if 0 |
559cb2fb | 8805 | int inside_height |
d9cdbb3d | 8806 | = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height)); |
06a2c219 | 8807 | #endif |
559cb2fb | 8808 | int top_range |
d9cdbb3d | 8809 | = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
559cb2fb JB |
8810 | |
8811 | win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER; | |
8812 | ||
8813 | if (! NILP (bar->dragging)) | |
8814 | win_y -= XINT (bar->dragging); | |
8815 | ||
8816 | if (win_y < 0) | |
8817 | win_y = 0; | |
8818 | if (win_y > top_range) | |
8819 | win_y = top_range; | |
8820 | ||
334208b7 | 8821 | *fp = f; |
7a13e894 | 8822 | *bar_window = bar->window; |
559cb2fb JB |
8823 | |
8824 | if (! NILP (bar->dragging)) | |
8825 | *part = scroll_bar_handle; | |
8826 | else if (win_y < XINT (bar->start)) | |
8827 | *part = scroll_bar_above_handle; | |
8828 | else if (win_y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE) | |
8829 | *part = scroll_bar_handle; | |
8830 | else | |
8831 | *part = scroll_bar_below_handle; | |
12ba150f | 8832 | |
e0c1aef2 KH |
8833 | XSETINT (*x, win_y); |
8834 | XSETINT (*y, top_range); | |
12ba150f | 8835 | |
39d8bb4d | 8836 | f->mouse_moved = 0; |
559cb2fb JB |
8837 | last_mouse_scroll_bar = Qnil; |
8838 | } | |
12ba150f | 8839 | |
559cb2fb | 8840 | *time = last_mouse_movement_time; |
cf7cb199 | 8841 | |
cf7cb199 | 8842 | UNBLOCK_INPUT; |
12ba150f JB |
8843 | } |
8844 | ||
f451eb13 | 8845 | |
dbc4e1c1 | 8846 | /* The screen has been cleared so we may have changed foreground or |
ab648270 JB |
8847 | background colors, and the scroll bars may need to be redrawn. |
8848 | Clear out the scroll bars, and ask for expose events, so we can | |
dbc4e1c1 JB |
8849 | redraw them. */ |
8850 | ||
dfcf069d | 8851 | void |
ab648270 | 8852 | x_scroll_bar_clear (f) |
dbc4e1c1 JB |
8853 | FRAME_PTR f; |
8854 | { | |
06a2c219 | 8855 | #ifndef USE_TOOLKIT_SCROLL_BARS |
dbc4e1c1 JB |
8856 | Lisp_Object bar; |
8857 | ||
b80c363e RS |
8858 | /* We can have scroll bars even if this is 0, |
8859 | if we just turned off scroll bar mode. | |
8860 | But in that case we should not clear them. */ | |
8861 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
8862 | for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); | |
8863 | bar = XSCROLL_BAR (bar)->next) | |
8864 | XClearArea (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)), | |
8865 | 0, 0, 0, 0, True); | |
06a2c219 | 8866 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
dbc4e1c1 JB |
8867 | } |
8868 | ||
06a2c219 | 8869 | /* This processes Expose events from the menu-bar specific X event |
19126e11 | 8870 | loop in xmenu.c. This allows to redisplay the frame if necessary |
06a2c219 | 8871 | when handling menu-bar or pop-up items. */ |
3afe33e7 | 8872 | |
06a2c219 | 8873 | int |
3afe33e7 RS |
8874 | process_expose_from_menu (event) |
8875 | XEvent event; | |
8876 | { | |
8877 | FRAME_PTR f; | |
19126e11 | 8878 | struct x_display_info *dpyinfo; |
06a2c219 | 8879 | int frame_exposed_p = 0; |
3afe33e7 | 8880 | |
f94397b5 KH |
8881 | BLOCK_INPUT; |
8882 | ||
19126e11 KH |
8883 | dpyinfo = x_display_info_for_display (event.xexpose.display); |
8884 | f = x_window_to_frame (dpyinfo, event.xexpose.window); | |
3afe33e7 RS |
8885 | if (f) |
8886 | { | |
8887 | if (f->async_visible == 0) | |
8888 | { | |
8889 | f->async_visible = 1; | |
8890 | f->async_iconified = 0; | |
06c488fd | 8891 | f->output_data.x->has_been_visible = 1; |
3afe33e7 RS |
8892 | SET_FRAME_GARBAGED (f); |
8893 | } | |
8894 | else | |
8895 | { | |
06a2c219 GM |
8896 | expose_frame (x_window_to_frame (dpyinfo, event.xexpose.window), |
8897 | event.xexpose.x, event.xexpose.y, | |
8898 | event.xexpose.width, event.xexpose.height); | |
8899 | frame_exposed_p = 1; | |
3afe33e7 RS |
8900 | } |
8901 | } | |
8902 | else | |
8903 | { | |
8904 | struct scroll_bar *bar | |
8905 | = x_window_to_scroll_bar (event.xexpose.window); | |
58769bee | 8906 | |
3afe33e7 RS |
8907 | if (bar) |
8908 | x_scroll_bar_expose (bar, &event); | |
8909 | } | |
f94397b5 KH |
8910 | |
8911 | UNBLOCK_INPUT; | |
06a2c219 | 8912 | return frame_exposed_p; |
3afe33e7 | 8913 | } |
09756a85 RS |
8914 | \f |
8915 | /* Define a queue to save up SelectionRequest events for later handling. */ | |
8916 | ||
8917 | struct selection_event_queue | |
8918 | { | |
8919 | XEvent event; | |
8920 | struct selection_event_queue *next; | |
8921 | }; | |
8922 | ||
8923 | static struct selection_event_queue *queue; | |
8924 | ||
8925 | /* Nonzero means queue up certain events--don't process them yet. */ | |
06a2c219 | 8926 | |
09756a85 RS |
8927 | static int x_queue_selection_requests; |
8928 | ||
8929 | /* Queue up an X event *EVENT, to be processed later. */ | |
dbc4e1c1 | 8930 | |
09756a85 | 8931 | static void |
334208b7 RS |
8932 | x_queue_event (f, event) |
8933 | FRAME_PTR f; | |
09756a85 RS |
8934 | XEvent *event; |
8935 | { | |
8936 | struct selection_event_queue *queue_tmp | |
06a2c219 | 8937 | = (struct selection_event_queue *) xmalloc (sizeof (struct selection_event_queue)); |
09756a85 | 8938 | |
58769bee | 8939 | if (queue_tmp != NULL) |
09756a85 RS |
8940 | { |
8941 | queue_tmp->event = *event; | |
8942 | queue_tmp->next = queue; | |
8943 | queue = queue_tmp; | |
8944 | } | |
8945 | } | |
8946 | ||
8947 | /* Take all the queued events and put them back | |
8948 | so that they get processed afresh. */ | |
8949 | ||
8950 | static void | |
db3906fd RS |
8951 | x_unqueue_events (display) |
8952 | Display *display; | |
09756a85 | 8953 | { |
58769bee | 8954 | while (queue != NULL) |
09756a85 RS |
8955 | { |
8956 | struct selection_event_queue *queue_tmp = queue; | |
db3906fd | 8957 | XPutBackEvent (display, &queue_tmp->event); |
09756a85 | 8958 | queue = queue_tmp->next; |
06a2c219 | 8959 | xfree ((char *)queue_tmp); |
09756a85 RS |
8960 | } |
8961 | } | |
8962 | ||
8963 | /* Start queuing SelectionRequest events. */ | |
8964 | ||
8965 | void | |
db3906fd RS |
8966 | x_start_queuing_selection_requests (display) |
8967 | Display *display; | |
09756a85 RS |
8968 | { |
8969 | x_queue_selection_requests++; | |
8970 | } | |
8971 | ||
8972 | /* Stop queuing SelectionRequest events. */ | |
8973 | ||
8974 | void | |
db3906fd RS |
8975 | x_stop_queuing_selection_requests (display) |
8976 | Display *display; | |
09756a85 RS |
8977 | { |
8978 | x_queue_selection_requests--; | |
db3906fd | 8979 | x_unqueue_events (display); |
09756a85 | 8980 | } |
f451eb13 JB |
8981 | \f |
8982 | /* The main X event-reading loop - XTread_socket. */ | |
dc6f92b8 | 8983 | |
06a2c219 | 8984 | /* Time stamp of enter window event. This is only used by XTread_socket, |
dc6f92b8 JB |
8985 | but we have to put it out here, since static variables within functions |
8986 | sometimes don't work. */ | |
06a2c219 | 8987 | |
dc6f92b8 JB |
8988 | static Time enter_timestamp; |
8989 | ||
11edeb03 | 8990 | /* This holds the state XLookupString needs to implement dead keys |
58769bee | 8991 | and other tricks known as "compose processing". _X Window System_ |
11edeb03 JB |
8992 | says that a portable program can't use this, but Stephen Gildea assures |
8993 | me that letting the compiler initialize it to zeros will work okay. | |
8994 | ||
8995 | This must be defined outside of XTread_socket, for the same reasons | |
06a2c219 GM |
8996 | given for enter_time stamp, above. */ |
8997 | ||
11edeb03 JB |
8998 | static XComposeStatus compose_status; |
8999 | ||
10e6549c RS |
9000 | /* Record the last 100 characters stored |
9001 | to help debug the loss-of-chars-during-GC problem. */ | |
06a2c219 | 9002 | |
2224b905 RS |
9003 | static int temp_index; |
9004 | static short temp_buffer[100]; | |
10e6549c | 9005 | |
7a13e894 RS |
9006 | /* Set this to nonzero to fake an "X I/O error" |
9007 | on a particular display. */ | |
06a2c219 | 9008 | |
7a13e894 RS |
9009 | struct x_display_info *XTread_socket_fake_io_error; |
9010 | ||
2224b905 RS |
9011 | /* When we find no input here, we occasionally do a no-op command |
9012 | to verify that the X server is still running and we can still talk with it. | |
9013 | We try all the open displays, one by one. | |
9014 | This variable is used for cycling thru the displays. */ | |
06a2c219 | 9015 | |
2224b905 RS |
9016 | static struct x_display_info *next_noop_dpyinfo; |
9017 | ||
06a2c219 GM |
9018 | #define SET_SAVED_MENU_EVENT(size) \ |
9019 | do \ | |
9020 | { \ | |
9021 | if (f->output_data.x->saved_menu_event == 0) \ | |
9022 | f->output_data.x->saved_menu_event \ | |
9023 | = (XEvent *) xmalloc (sizeof (XEvent)); \ | |
9024 | bcopy (&event, f->output_data.x->saved_menu_event, size); \ | |
9025 | if (numchars >= 1) \ | |
9026 | { \ | |
9027 | bufp->kind = menu_bar_activate_event; \ | |
9028 | XSETFRAME (bufp->frame_or_window, f); \ | |
0f8aabe9 | 9029 | bufp->arg = Qnil; \ |
06a2c219 GM |
9030 | bufp++; \ |
9031 | count++; \ | |
9032 | numchars--; \ | |
9033 | } \ | |
9034 | } \ | |
9035 | while (0) | |
9036 | ||
8805890a | 9037 | #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent)) |
06a2c219 | 9038 | #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent)) |
8805890a | 9039 | |
dc6f92b8 JB |
9040 | /* Read events coming from the X server. |
9041 | This routine is called by the SIGIO handler. | |
9042 | We return as soon as there are no more events to be read. | |
9043 | ||
9044 | Events representing keys are stored in buffer BUFP, | |
9045 | which can hold up to NUMCHARS characters. | |
9046 | We return the number of characters stored into the buffer, | |
9047 | thus pretending to be `read'. | |
9048 | ||
dc6f92b8 JB |
9049 | EXPECTED is nonzero if the caller knows input is available. */ |
9050 | ||
7c5283e4 | 9051 | int |
f66868ba | 9052 | XTread_socket (sd, bufp, numchars, expected) |
dc6f92b8 | 9053 | register int sd; |
8805890a KH |
9054 | /* register */ struct input_event *bufp; |
9055 | /* register */ int numchars; | |
dc6f92b8 JB |
9056 | int expected; |
9057 | { | |
9058 | int count = 0; | |
9059 | int nbytes = 0; | |
dc6f92b8 | 9060 | XEvent event; |
f676886a | 9061 | struct frame *f; |
66f55a9d | 9062 | int event_found = 0; |
334208b7 | 9063 | struct x_display_info *dpyinfo; |
379b5ac0 | 9064 | struct coding_system coding; |
dc6f92b8 | 9065 | |
9ac0d9e0 | 9066 | if (interrupt_input_blocked) |
dc6f92b8 | 9067 | { |
9ac0d9e0 | 9068 | interrupt_input_pending = 1; |
dc6f92b8 JB |
9069 | return -1; |
9070 | } | |
9071 | ||
9ac0d9e0 | 9072 | interrupt_input_pending = 0; |
dc6f92b8 | 9073 | BLOCK_INPUT; |
c0a04927 RS |
9074 | |
9075 | /* So people can tell when we have read the available input. */ | |
9076 | input_signal_count++; | |
9077 | ||
dc6f92b8 | 9078 | if (numchars <= 0) |
06a2c219 | 9079 | abort (); /* Don't think this happens. */ |
dc6f92b8 | 9080 | |
bde5503b GM |
9081 | ++handling_signal; |
9082 | ||
379b5ac0 KH |
9083 | /* The input should be decoded if it is from XIM. Currently the |
9084 | locale of XIM is the same as that of the system. So, we can use | |
9085 | Vlocale_coding_system which is initialized properly at Emacs | |
9086 | startup time. */ | |
9087 | setup_coding_system (Vlocale_coding_system, &coding); | |
9088 | coding.src_multibyte = 0; | |
9089 | coding.dst_multibyte = 1; | |
9090 | /* The input is converted to events, thus we can't handle | |
9091 | composition. Anyway, there's no XIM that gives us composition | |
9092 | information. */ | |
9093 | coding.composing = COMPOSITION_DISABLED; | |
9094 | ||
7a13e894 RS |
9095 | /* Find the display we are supposed to read input for. |
9096 | It's the one communicating on descriptor SD. */ | |
9097 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) | |
9098 | { | |
9099 | #if 0 /* This ought to be unnecessary; let's verify it. */ | |
dc6f92b8 | 9100 | #ifdef FIOSNBIO |
7a13e894 RS |
9101 | /* If available, Xlib uses FIOSNBIO to make the socket |
9102 | non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set, | |
e6cbea31 | 9103 | FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK, |
06a2c219 | 9104 | a read returns 0, which Xlib interprets as equivalent to EPIPE. */ |
7a13e894 | 9105 | fcntl (dpyinfo->connection, F_SETFL, 0); |
c118dd06 | 9106 | #endif /* ! defined (FIOSNBIO) */ |
7a13e894 | 9107 | #endif |
dc6f92b8 | 9108 | |
7a13e894 RS |
9109 | #if 0 /* This code can't be made to work, with multiple displays, |
9110 | and appears not to be used on any system any more. | |
9111 | Also keyboard.c doesn't turn O_NDELAY on and off | |
9112 | for X connections. */ | |
dc6f92b8 JB |
9113 | #ifndef SIGIO |
9114 | #ifndef HAVE_SELECT | |
7a13e894 RS |
9115 | if (! (fcntl (dpyinfo->connection, F_GETFL, 0) & O_NDELAY)) |
9116 | { | |
9117 | extern int read_alarm_should_throw; | |
9118 | read_alarm_should_throw = 1; | |
9119 | XPeekEvent (dpyinfo->display, &event); | |
9120 | read_alarm_should_throw = 0; | |
9121 | } | |
c118dd06 JB |
9122 | #endif /* HAVE_SELECT */ |
9123 | #endif /* SIGIO */ | |
7a13e894 | 9124 | #endif |
dc6f92b8 | 9125 | |
7a13e894 RS |
9126 | /* For debugging, this gives a way to fake an I/O error. */ |
9127 | if (dpyinfo == XTread_socket_fake_io_error) | |
9128 | { | |
9129 | XTread_socket_fake_io_error = 0; | |
9130 | x_io_error_quitter (dpyinfo->display); | |
9131 | } | |
dc6f92b8 | 9132 | |
06a2c219 | 9133 | while (XPending (dpyinfo->display)) |
dc6f92b8 | 9134 | { |
7a13e894 | 9135 | XNextEvent (dpyinfo->display, &event); |
06a2c219 | 9136 | |
531483fb | 9137 | #ifdef HAVE_X_I18N |
d1bc4182 | 9138 | { |
f2be1146 GM |
9139 | /* Filter events for the current X input method. |
9140 | XFilterEvent returns non-zero if the input method has | |
9141 | consumed the event. We pass the frame's X window to | |
9142 | XFilterEvent because that's the one for which the IC | |
9143 | was created. */ | |
f5d11644 GM |
9144 | struct frame *f1 = x_any_window_to_frame (dpyinfo, |
9145 | event.xclient.window); | |
9146 | if (XFilterEvent (&event, f1 ? FRAME_X_WINDOW (f1) : None)) | |
d1bc4182 RS |
9147 | break; |
9148 | } | |
0cd6403b | 9149 | #endif |
7a13e894 RS |
9150 | event_found = 1; |
9151 | ||
9152 | switch (event.type) | |
9153 | { | |
9154 | case ClientMessage: | |
c047688c | 9155 | { |
7a13e894 RS |
9156 | if (event.xclient.message_type |
9157 | == dpyinfo->Xatom_wm_protocols | |
9158 | && event.xclient.format == 32) | |
c047688c | 9159 | { |
7a13e894 RS |
9160 | if (event.xclient.data.l[0] |
9161 | == dpyinfo->Xatom_wm_take_focus) | |
c047688c | 9162 | { |
8c1a6a84 RS |
9163 | /* Use x_any_window_to_frame because this |
9164 | could be the shell widget window | |
9165 | if the frame has no title bar. */ | |
9166 | f = x_any_window_to_frame (dpyinfo, event.xclient.window); | |
6c183ba5 RS |
9167 | #ifdef HAVE_X_I18N |
9168 | /* Not quite sure this is needed -pd */ | |
8c1a6a84 | 9169 | if (f && FRAME_XIC (f)) |
6c183ba5 RS |
9170 | XSetICFocus (FRAME_XIC (f)); |
9171 | #endif | |
f1da8f06 GM |
9172 | #if 0 /* Emacs sets WM hints whose `input' field is `true'. This |
9173 | instructs the WM to set the input focus automatically for | |
9174 | Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS | |
9175 | tells the WM to send us a ClientMessage WM_TAKE_FOCUS after | |
9176 | it has set the focus. So, XSetInputFocus below is not | |
9177 | needed. | |
9178 | ||
9179 | The call to XSetInputFocus below has also caused trouble. In | |
9180 | cases where the XSetInputFocus done by the WM and the one | |
9181 | below are temporally close (on a fast machine), the call | |
9182 | below can generate additional FocusIn events which confuse | |
9183 | Emacs. */ | |
9184 | ||
bf7253f4 RS |
9185 | /* Since we set WM_TAKE_FOCUS, we must call |
9186 | XSetInputFocus explicitly. But not if f is null, | |
9187 | since that might be an event for a deleted frame. */ | |
7a13e894 | 9188 | if (f) |
bf7253f4 RS |
9189 | { |
9190 | Display *d = event.xclient.display; | |
9191 | /* Catch and ignore errors, in case window has been | |
9192 | iconified by a window manager such as GWM. */ | |
9193 | int count = x_catch_errors (d); | |
9194 | XSetInputFocus (d, event.xclient.window, | |
e1f6572f RS |
9195 | /* The ICCCM says this is |
9196 | the only valid choice. */ | |
9197 | RevertToParent, | |
bf7253f4 RS |
9198 | event.xclient.data.l[1]); |
9199 | /* This is needed to detect the error | |
9200 | if there is an error. */ | |
9201 | XSync (d, False); | |
9202 | x_uncatch_errors (d, count); | |
9203 | } | |
7a13e894 | 9204 | /* Not certain about handling scroll bars here */ |
f1da8f06 | 9205 | #endif /* 0 */ |
c047688c | 9206 | } |
7a13e894 RS |
9207 | else if (event.xclient.data.l[0] |
9208 | == dpyinfo->Xatom_wm_save_yourself) | |
9209 | { | |
9210 | /* Save state modify the WM_COMMAND property to | |
06a2c219 | 9211 | something which can reinstate us. This notifies |
7a13e894 RS |
9212 | the session manager, who's looking for such a |
9213 | PropertyNotify. Can restart processing when | |
06a2c219 | 9214 | a keyboard or mouse event arrives. */ |
7a13e894 RS |
9215 | if (numchars > 0) |
9216 | { | |
19126e11 KH |
9217 | f = x_top_window_to_frame (dpyinfo, |
9218 | event.xclient.window); | |
7a13e894 RS |
9219 | |
9220 | /* This is just so we only give real data once | |
9221 | for a single Emacs process. */ | |
b86bd3dd | 9222 | if (f == SELECTED_FRAME ()) |
7a13e894 RS |
9223 | XSetCommand (FRAME_X_DISPLAY (f), |
9224 | event.xclient.window, | |
9225 | initial_argv, initial_argc); | |
f000f5c5 | 9226 | else if (f) |
7a13e894 RS |
9227 | XSetCommand (FRAME_X_DISPLAY (f), |
9228 | event.xclient.window, | |
9229 | 0, 0); | |
9230 | } | |
9231 | } | |
9232 | else if (event.xclient.data.l[0] | |
9233 | == dpyinfo->Xatom_wm_delete_window) | |
1fb20991 | 9234 | { |
19126e11 KH |
9235 | struct frame *f |
9236 | = x_any_window_to_frame (dpyinfo, | |
9237 | event.xclient.window); | |
1fb20991 | 9238 | |
7a13e894 RS |
9239 | if (f) |
9240 | { | |
9241 | if (numchars == 0) | |
9242 | abort (); | |
1fb20991 | 9243 | |
7a13e894 RS |
9244 | bufp->kind = delete_window_event; |
9245 | XSETFRAME (bufp->frame_or_window, f); | |
0f8aabe9 | 9246 | bufp->arg = Qnil; |
7a13e894 RS |
9247 | bufp++; |
9248 | ||
9249 | count += 1; | |
9250 | numchars -= 1; | |
9251 | } | |
1fb20991 | 9252 | } |
c047688c | 9253 | } |
7a13e894 RS |
9254 | else if (event.xclient.message_type |
9255 | == dpyinfo->Xatom_wm_configure_denied) | |
9256 | { | |
9257 | } | |
9258 | else if (event.xclient.message_type | |
9259 | == dpyinfo->Xatom_wm_window_moved) | |
9260 | { | |
9261 | int new_x, new_y; | |
19126e11 KH |
9262 | struct frame *f |
9263 | = x_window_to_frame (dpyinfo, event.xclient.window); | |
58769bee | 9264 | |
7a13e894 RS |
9265 | new_x = event.xclient.data.s[0]; |
9266 | new_y = event.xclient.data.s[1]; | |
1fb20991 | 9267 | |
7a13e894 RS |
9268 | if (f) |
9269 | { | |
7556890b RS |
9270 | f->output_data.x->left_pos = new_x; |
9271 | f->output_data.x->top_pos = new_y; | |
7a13e894 | 9272 | } |
1fb20991 | 9273 | } |
0fdff6bb | 9274 | #ifdef HACK_EDITRES |
7a13e894 RS |
9275 | else if (event.xclient.message_type |
9276 | == dpyinfo->Xatom_editres) | |
9277 | { | |
19126e11 KH |
9278 | struct frame *f |
9279 | = x_any_window_to_frame (dpyinfo, event.xclient.window); | |
7556890b | 9280 | _XEditResCheckMessages (f->output_data.x->widget, NULL, |
19126e11 | 9281 | &event, NULL); |
7a13e894 | 9282 | } |
0fdff6bb | 9283 | #endif /* HACK_EDITRES */ |
06a2c219 GM |
9284 | else if ((event.xclient.message_type |
9285 | == dpyinfo->Xatom_DONE) | |
9286 | || (event.xclient.message_type | |
9287 | == dpyinfo->Xatom_PAGE)) | |
9288 | { | |
9289 | /* Ghostview job completed. Kill it. We could | |
9290 | reply with "Next" if we received "Page", but we | |
9291 | currently never do because we are interested in | |
9292 | images, only, which should have 1 page. */ | |
06a2c219 GM |
9293 | Pixmap pixmap = (Pixmap) event.xclient.data.l[1]; |
9294 | struct frame *f | |
9295 | = x_window_to_frame (dpyinfo, event.xclient.window); | |
9296 | x_kill_gs_process (pixmap, f); | |
9297 | expose_frame (f, 0, 0, 0, 0); | |
9298 | } | |
9299 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
9300 | /* Scroll bar callbacks send a ClientMessage from which | |
9301 | we construct an input_event. */ | |
9302 | else if (event.xclient.message_type | |
9303 | == dpyinfo->Xatom_Scrollbar) | |
9304 | { | |
9305 | x_scroll_bar_to_input_event (&event, bufp); | |
9306 | ++bufp, ++count, --numchars; | |
9307 | goto out; | |
9308 | } | |
9309 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
9310 | else | |
9311 | goto OTHER; | |
7a13e894 RS |
9312 | } |
9313 | break; | |
dc6f92b8 | 9314 | |
7a13e894 | 9315 | case SelectionNotify: |
3afe33e7 | 9316 | #ifdef USE_X_TOOLKIT |
19126e11 | 9317 | if (! x_window_to_frame (dpyinfo, event.xselection.requestor)) |
7a13e894 | 9318 | goto OTHER; |
3afe33e7 | 9319 | #endif /* not USE_X_TOOLKIT */ |
dfcf069d | 9320 | x_handle_selection_notify (&event.xselection); |
7a13e894 | 9321 | break; |
d56a553a | 9322 | |
06a2c219 | 9323 | case SelectionClear: /* Someone has grabbed ownership. */ |
3afe33e7 | 9324 | #ifdef USE_X_TOOLKIT |
19126e11 | 9325 | if (! x_window_to_frame (dpyinfo, event.xselectionclear.window)) |
7a13e894 | 9326 | goto OTHER; |
3afe33e7 | 9327 | #endif /* USE_X_TOOLKIT */ |
7a13e894 RS |
9328 | { |
9329 | XSelectionClearEvent *eventp = (XSelectionClearEvent *) &event; | |
d56a553a | 9330 | |
7a13e894 RS |
9331 | if (numchars == 0) |
9332 | abort (); | |
d56a553a | 9333 | |
7a13e894 RS |
9334 | bufp->kind = selection_clear_event; |
9335 | SELECTION_EVENT_DISPLAY (bufp) = eventp->display; | |
9336 | SELECTION_EVENT_SELECTION (bufp) = eventp->selection; | |
9337 | SELECTION_EVENT_TIME (bufp) = eventp->time; | |
e6cbea31 | 9338 | bufp->frame_or_window = Qnil; |
0f8aabe9 | 9339 | bufp->arg = Qnil; |
7a13e894 | 9340 | bufp++; |
d56a553a | 9341 | |
7a13e894 RS |
9342 | count += 1; |
9343 | numchars -= 1; | |
9344 | } | |
9345 | break; | |
dc6f92b8 | 9346 | |
06a2c219 | 9347 | case SelectionRequest: /* Someone wants our selection. */ |
3afe33e7 | 9348 | #ifdef USE_X_TOOLKIT |
19126e11 | 9349 | if (!x_window_to_frame (dpyinfo, event.xselectionrequest.owner)) |
7a13e894 | 9350 | goto OTHER; |
3afe33e7 | 9351 | #endif /* USE_X_TOOLKIT */ |
7a13e894 | 9352 | if (x_queue_selection_requests) |
19126e11 | 9353 | x_queue_event (x_window_to_frame (dpyinfo, event.xselectionrequest.owner), |
7a13e894 RS |
9354 | &event); |
9355 | else | |
9356 | { | |
9357 | XSelectionRequestEvent *eventp = (XSelectionRequestEvent *) &event; | |
dc6f92b8 | 9358 | |
7a13e894 RS |
9359 | if (numchars == 0) |
9360 | abort (); | |
9361 | ||
9362 | bufp->kind = selection_request_event; | |
9363 | SELECTION_EVENT_DISPLAY (bufp) = eventp->display; | |
9364 | SELECTION_EVENT_REQUESTOR (bufp) = eventp->requestor; | |
9365 | SELECTION_EVENT_SELECTION (bufp) = eventp->selection; | |
9366 | SELECTION_EVENT_TARGET (bufp) = eventp->target; | |
9367 | SELECTION_EVENT_PROPERTY (bufp) = eventp->property; | |
9368 | SELECTION_EVENT_TIME (bufp) = eventp->time; | |
e6cbea31 | 9369 | bufp->frame_or_window = Qnil; |
0f8aabe9 | 9370 | bufp->arg = Qnil; |
7a13e894 RS |
9371 | bufp++; |
9372 | ||
9373 | count += 1; | |
9374 | numchars -= 1; | |
9375 | } | |
9376 | break; | |
9377 | ||
9378 | case PropertyNotify: | |
3afe33e7 | 9379 | #ifdef USE_X_TOOLKIT |
19126e11 | 9380 | if (!x_any_window_to_frame (dpyinfo, event.xproperty.window)) |
7a13e894 | 9381 | goto OTHER; |
3afe33e7 | 9382 | #endif /* not USE_X_TOOLKIT */ |
dfcf069d | 9383 | x_handle_property_notify (&event.xproperty); |
7a13e894 | 9384 | break; |
dc6f92b8 | 9385 | |
7a13e894 | 9386 | case ReparentNotify: |
19126e11 | 9387 | f = x_top_window_to_frame (dpyinfo, event.xreparent.window); |
7a13e894 RS |
9388 | if (f) |
9389 | { | |
9390 | int x, y; | |
7556890b | 9391 | f->output_data.x->parent_desc = event.xreparent.parent; |
7a13e894 | 9392 | x_real_positions (f, &x, &y); |
7556890b RS |
9393 | f->output_data.x->left_pos = x; |
9394 | f->output_data.x->top_pos = y; | |
7a13e894 RS |
9395 | } |
9396 | break; | |
3bd330d4 | 9397 | |
7a13e894 | 9398 | case Expose: |
19126e11 | 9399 | f = x_window_to_frame (dpyinfo, event.xexpose.window); |
7a13e894 | 9400 | if (f) |
dc6f92b8 | 9401 | { |
7a13e894 RS |
9402 | if (f->async_visible == 0) |
9403 | { | |
9404 | f->async_visible = 1; | |
9405 | f->async_iconified = 0; | |
06c488fd | 9406 | f->output_data.x->has_been_visible = 1; |
7a13e894 RS |
9407 | SET_FRAME_GARBAGED (f); |
9408 | } | |
9409 | else | |
06a2c219 GM |
9410 | expose_frame (x_window_to_frame (dpyinfo, |
9411 | event.xexpose.window), | |
9412 | event.xexpose.x, event.xexpose.y, | |
9413 | event.xexpose.width, event.xexpose.height); | |
dc6f92b8 JB |
9414 | } |
9415 | else | |
7a13e894 | 9416 | { |
06a2c219 GM |
9417 | #ifdef USE_TOOLKIT_SCROLL_BARS |
9418 | /* Dispatch event to the widget. */ | |
9419 | goto OTHER; | |
9420 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
7a13e894 RS |
9421 | struct scroll_bar *bar |
9422 | = x_window_to_scroll_bar (event.xexpose.window); | |
58769bee | 9423 | |
7a13e894 RS |
9424 | if (bar) |
9425 | x_scroll_bar_expose (bar, &event); | |
3afe33e7 | 9426 | #ifdef USE_X_TOOLKIT |
7a13e894 RS |
9427 | else |
9428 | goto OTHER; | |
3afe33e7 | 9429 | #endif /* USE_X_TOOLKIT */ |
06a2c219 | 9430 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
7a13e894 RS |
9431 | } |
9432 | break; | |
dc6f92b8 | 9433 | |
7a13e894 RS |
9434 | case GraphicsExpose: /* This occurs when an XCopyArea's |
9435 | source area was obscured or not | |
9436 | available.*/ | |
19126e11 | 9437 | f = x_window_to_frame (dpyinfo, event.xgraphicsexpose.drawable); |
7a13e894 RS |
9438 | if (f) |
9439 | { | |
06a2c219 GM |
9440 | expose_frame (f, |
9441 | event.xgraphicsexpose.x, event.xgraphicsexpose.y, | |
9442 | event.xgraphicsexpose.width, | |
9443 | event.xgraphicsexpose.height); | |
7a13e894 | 9444 | } |
3afe33e7 | 9445 | #ifdef USE_X_TOOLKIT |
7a13e894 RS |
9446 | else |
9447 | goto OTHER; | |
3afe33e7 | 9448 | #endif /* USE_X_TOOLKIT */ |
7a13e894 | 9449 | break; |
dc6f92b8 | 9450 | |
7a13e894 | 9451 | case NoExpose: /* This occurs when an XCopyArea's |
06a2c219 GM |
9452 | source area was completely |
9453 | available */ | |
7a13e894 | 9454 | break; |
dc6f92b8 | 9455 | |
7a13e894 | 9456 | case UnmapNotify: |
06a2c219 GM |
9457 | /* Redo the mouse-highlight after the tooltip has gone. */ |
9458 | if (event.xmap.window == tip_window) | |
9459 | { | |
9460 | tip_window = 0; | |
9461 | redo_mouse_highlight (); | |
9462 | } | |
9463 | ||
91ea2a7a | 9464 | f = x_top_window_to_frame (dpyinfo, event.xunmap.window); |
7a13e894 RS |
9465 | if (f) /* F may no longer exist if |
9466 | the frame was deleted. */ | |
9467 | { | |
9468 | /* While a frame is unmapped, display generation is | |
9469 | disabled; you don't want to spend time updating a | |
9470 | display that won't ever be seen. */ | |
9471 | f->async_visible = 0; | |
9472 | /* We can't distinguish, from the event, whether the window | |
9473 | has become iconified or invisible. So assume, if it | |
9474 | was previously visible, than now it is iconified. | |
1aa6072f RS |
9475 | But x_make_frame_invisible clears both |
9476 | the visible flag and the iconified flag; | |
9477 | and that way, we know the window is not iconified now. */ | |
7a13e894 | 9478 | if (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)) |
1aa6072f RS |
9479 | { |
9480 | f->async_iconified = 1; | |
bddd097c | 9481 | |
1aa6072f RS |
9482 | bufp->kind = iconify_event; |
9483 | XSETFRAME (bufp->frame_or_window, f); | |
0f8aabe9 | 9484 | bufp->arg = Qnil; |
1aa6072f RS |
9485 | bufp++; |
9486 | count++; | |
9487 | numchars--; | |
9488 | } | |
7a13e894 | 9489 | } |
7a13e894 | 9490 | goto OTHER; |
dc6f92b8 | 9491 | |
7a13e894 | 9492 | case MapNotify: |
06a2c219 GM |
9493 | if (event.xmap.window == tip_window) |
9494 | /* The tooltip has been drawn already. Avoid | |
9495 | the SET_FRAME_GARBAGED below. */ | |
9496 | goto OTHER; | |
9497 | ||
9498 | /* We use x_top_window_to_frame because map events can | |
9499 | come for sub-windows and they don't mean that the | |
9500 | frame is visible. */ | |
19126e11 | 9501 | f = x_top_window_to_frame (dpyinfo, event.xmap.window); |
7a13e894 RS |
9502 | if (f) |
9503 | { | |
9504 | f->async_visible = 1; | |
9505 | f->async_iconified = 0; | |
06c488fd | 9506 | f->output_data.x->has_been_visible = 1; |
dc6f92b8 | 9507 | |
7a13e894 RS |
9508 | /* wait_reading_process_input will notice this and update |
9509 | the frame's display structures. */ | |
9510 | SET_FRAME_GARBAGED (f); | |
bddd097c | 9511 | |
d806e720 RS |
9512 | if (f->iconified) |
9513 | { | |
9514 | bufp->kind = deiconify_event; | |
9515 | XSETFRAME (bufp->frame_or_window, f); | |
0f8aabe9 | 9516 | bufp->arg = Qnil; |
d806e720 RS |
9517 | bufp++; |
9518 | count++; | |
9519 | numchars--; | |
9520 | } | |
e73ec6fa | 9521 | else if (! NILP (Vframe_list) |
8e713be6 | 9522 | && ! NILP (XCDR (Vframe_list))) |
78aa2ba5 KH |
9523 | /* Force a redisplay sooner or later |
9524 | to update the frame titles | |
9525 | in case this is the second frame. */ | |
9526 | record_asynch_buffer_change (); | |
7a13e894 | 9527 | } |
7a13e894 | 9528 | goto OTHER; |
dc6f92b8 | 9529 | |
7a13e894 | 9530 | case KeyPress: |
19126e11 | 9531 | f = x_any_window_to_frame (dpyinfo, event.xkey.window); |
f451eb13 | 9532 | |
06a2c219 GM |
9533 | #ifdef USE_MOTIF |
9534 | /* I couldn't find a way to prevent LessTif scroll bars | |
9535 | from consuming key events. */ | |
9536 | if (f == 0) | |
9537 | { | |
9538 | Widget widget = XtWindowToWidget (dpyinfo->display, | |
9539 | event.xkey.window); | |
9540 | if (widget && XmIsScrollBar (widget)) | |
9541 | { | |
9542 | widget = XtParent (widget); | |
9543 | f = x_any_window_to_frame (dpyinfo, XtWindow (widget)); | |
9544 | } | |
9545 | } | |
9546 | #endif /* USE_MOTIF */ | |
9547 | ||
7a13e894 RS |
9548 | if (f != 0) |
9549 | { | |
9550 | KeySym keysym, orig_keysym; | |
379b5ac0 KH |
9551 | /* al%imercury@uunet.uu.net says that making this 81 |
9552 | instead of 80 fixed a bug whereby meta chars made | |
9553 | his Emacs hang. | |
9554 | ||
9555 | It seems that some version of XmbLookupString has | |
9556 | a bug of not returning XBufferOverflow in | |
9557 | status_return even if the input is too long to | |
9558 | fit in 81 bytes. So, we must prepare sufficient | |
9559 | bytes for copy_buffer. 513 bytes (256 chars for | |
9560 | two-byte character set) seems to be a faily good | |
9561 | approximation. -- 2000.8.10 handa@etl.go.jp */ | |
9562 | unsigned char copy_buffer[513]; | |
9563 | unsigned char *copy_bufptr = copy_buffer; | |
9564 | int copy_bufsiz = sizeof (copy_buffer); | |
7a13e894 | 9565 | int modifiers; |
64bb1782 | 9566 | |
7a13e894 RS |
9567 | event.xkey.state |
9568 | |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f), | |
9569 | extra_keyboard_modifiers); | |
9570 | modifiers = event.xkey.state; | |
3a2712f9 | 9571 | |
7a13e894 | 9572 | /* This will have to go some day... */ |
752a043f | 9573 | |
7a13e894 RS |
9574 | /* make_lispy_event turns chars into control chars. |
9575 | Don't do it here because XLookupString is too eager. */ | |
9576 | event.xkey.state &= ~ControlMask; | |
5d46f928 RS |
9577 | event.xkey.state &= ~(dpyinfo->meta_mod_mask |
9578 | | dpyinfo->super_mod_mask | |
9579 | | dpyinfo->hyper_mod_mask | |
9580 | | dpyinfo->alt_mod_mask); | |
9581 | ||
1cf4a0d1 RS |
9582 | /* In case Meta is ComposeCharacter, |
9583 | clear its status. According to Markus Ehrnsperger | |
9584 | Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de | |
9585 | this enables ComposeCharacter to work whether or | |
9586 | not it is combined with Meta. */ | |
9587 | if (modifiers & dpyinfo->meta_mod_mask) | |
9588 | bzero (&compose_status, sizeof (compose_status)); | |
9589 | ||
6c183ba5 RS |
9590 | #ifdef HAVE_X_I18N |
9591 | if (FRAME_XIC (f)) | |
9592 | { | |
f5d11644 GM |
9593 | Status status_return; |
9594 | ||
6c183ba5 | 9595 | nbytes = XmbLookupString (FRAME_XIC (f), |
f5d11644 GM |
9596 | &event.xkey, copy_bufptr, |
9597 | copy_bufsiz, &keysym, | |
6c183ba5 | 9598 | &status_return); |
f5d11644 GM |
9599 | if (status_return == XBufferOverflow) |
9600 | { | |
9601 | copy_bufsiz = nbytes + 1; | |
9602 | copy_bufptr = (char *) alloca (copy_bufsiz); | |
9603 | nbytes = XmbLookupString (FRAME_XIC (f), | |
9604 | &event.xkey, copy_bufptr, | |
9605 | copy_bufsiz, &keysym, | |
9606 | &status_return); | |
9607 | } | |
9608 | ||
1decb680 PE |
9609 | if (status_return == XLookupNone) |
9610 | break; | |
9611 | else if (status_return == XLookupChars) | |
fdd9d55e GM |
9612 | { |
9613 | keysym = NoSymbol; | |
9614 | modifiers = 0; | |
9615 | } | |
1decb680 PE |
9616 | else if (status_return != XLookupKeySym |
9617 | && status_return != XLookupBoth) | |
9618 | abort (); | |
6c183ba5 RS |
9619 | } |
9620 | else | |
379b5ac0 KH |
9621 | nbytes = XLookupString (&event.xkey, copy_bufptr, |
9622 | copy_bufsiz, &keysym, | |
9623 | &compose_status); | |
6c183ba5 | 9624 | #else |
379b5ac0 KH |
9625 | nbytes = XLookupString (&event.xkey, copy_bufptr, |
9626 | copy_bufsiz, &keysym, | |
9627 | &compose_status); | |
6c183ba5 | 9628 | #endif |
dc6f92b8 | 9629 | |
7a13e894 | 9630 | orig_keysym = keysym; |
55123275 | 9631 | |
7a13e894 RS |
9632 | if (numchars > 1) |
9633 | { | |
9634 | if (((keysym >= XK_BackSpace && keysym <= XK_Escape) | |
9635 | || keysym == XK_Delete | |
1097aea0 | 9636 | #ifdef XK_ISO_Left_Tab |
441affdb | 9637 | || (keysym >= XK_ISO_Left_Tab && keysym <= XK_ISO_Enter) |
1097aea0 | 9638 | #endif |
852bff8f | 9639 | || (keysym >= XK_Kanji && keysym <= XK_Eisu_toggle) |
7a13e894 RS |
9640 | || IsCursorKey (keysym) /* 0xff50 <= x < 0xff60 */ |
9641 | || IsMiscFunctionKey (keysym) /* 0xff60 <= x < VARIES */ | |
c34790e0 | 9642 | #ifdef HPUX |
7a13e894 RS |
9643 | /* This recognizes the "extended function keys". |
9644 | It seems there's no cleaner way. | |
9645 | Test IsModifierKey to avoid handling mode_switch | |
9646 | incorrectly. */ | |
9647 | || ((unsigned) (keysym) >= XK_Select | |
9648 | && (unsigned)(keysym) < XK_KP_Space) | |
69388238 RS |
9649 | #endif |
9650 | #ifdef XK_dead_circumflex | |
7a13e894 | 9651 | || orig_keysym == XK_dead_circumflex |
69388238 RS |
9652 | #endif |
9653 | #ifdef XK_dead_grave | |
7a13e894 | 9654 | || orig_keysym == XK_dead_grave |
69388238 RS |
9655 | #endif |
9656 | #ifdef XK_dead_tilde | |
7a13e894 | 9657 | || orig_keysym == XK_dead_tilde |
69388238 RS |
9658 | #endif |
9659 | #ifdef XK_dead_diaeresis | |
7a13e894 | 9660 | || orig_keysym == XK_dead_diaeresis |
69388238 RS |
9661 | #endif |
9662 | #ifdef XK_dead_macron | |
7a13e894 | 9663 | || orig_keysym == XK_dead_macron |
69388238 RS |
9664 | #endif |
9665 | #ifdef XK_dead_degree | |
7a13e894 | 9666 | || orig_keysym == XK_dead_degree |
69388238 RS |
9667 | #endif |
9668 | #ifdef XK_dead_acute | |
7a13e894 | 9669 | || orig_keysym == XK_dead_acute |
69388238 RS |
9670 | #endif |
9671 | #ifdef XK_dead_cedilla | |
7a13e894 | 9672 | || orig_keysym == XK_dead_cedilla |
69388238 RS |
9673 | #endif |
9674 | #ifdef XK_dead_breve | |
7a13e894 | 9675 | || orig_keysym == XK_dead_breve |
69388238 RS |
9676 | #endif |
9677 | #ifdef XK_dead_ogonek | |
7a13e894 | 9678 | || orig_keysym == XK_dead_ogonek |
69388238 RS |
9679 | #endif |
9680 | #ifdef XK_dead_caron | |
7a13e894 | 9681 | || orig_keysym == XK_dead_caron |
69388238 RS |
9682 | #endif |
9683 | #ifdef XK_dead_doubleacute | |
7a13e894 | 9684 | || orig_keysym == XK_dead_doubleacute |
69388238 RS |
9685 | #endif |
9686 | #ifdef XK_dead_abovedot | |
7a13e894 | 9687 | || orig_keysym == XK_dead_abovedot |
c34790e0 | 9688 | #endif |
7a13e894 RS |
9689 | || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */ |
9690 | || IsFunctionKey (keysym) /* 0xffbe <= x < 0xffe1 */ | |
9691 | /* Any "vendor-specific" key is ok. */ | |
9692 | || (orig_keysym & (1 << 28))) | |
9693 | && ! (IsModifierKey (orig_keysym) | |
7719aa06 RS |
9694 | #ifndef HAVE_X11R5 |
9695 | #ifdef XK_Mode_switch | |
7a13e894 | 9696 | || ((unsigned)(orig_keysym) == XK_Mode_switch) |
7719aa06 RS |
9697 | #endif |
9698 | #ifdef XK_Num_Lock | |
7a13e894 | 9699 | || ((unsigned)(orig_keysym) == XK_Num_Lock) |
7719aa06 RS |
9700 | #endif |
9701 | #endif /* not HAVE_X11R5 */ | |
7a13e894 | 9702 | )) |
dc6f92b8 | 9703 | { |
10e6549c RS |
9704 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
9705 | temp_index = 0; | |
7a13e894 RS |
9706 | temp_buffer[temp_index++] = keysym; |
9707 | bufp->kind = non_ascii_keystroke; | |
9708 | bufp->code = keysym; | |
e0c1aef2 | 9709 | XSETFRAME (bufp->frame_or_window, f); |
0f8aabe9 | 9710 | bufp->arg = Qnil; |
334208b7 RS |
9711 | bufp->modifiers |
9712 | = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), | |
9713 | modifiers); | |
1113d9db | 9714 | bufp->timestamp = event.xkey.time; |
dc6f92b8 | 9715 | bufp++; |
7a13e894 RS |
9716 | count++; |
9717 | numchars--; | |
dc6f92b8 | 9718 | } |
7a13e894 RS |
9719 | else if (numchars > nbytes) |
9720 | { | |
9721 | register int i; | |
379b5ac0 KH |
9722 | register int c; |
9723 | unsigned char *p, *pend; | |
9724 | int nchars, len; | |
7a13e894 RS |
9725 | |
9726 | for (i = 0; i < nbytes; i++) | |
9727 | { | |
379b5ac0 KH |
9728 | if (temp_index == (sizeof temp_buffer |
9729 | / sizeof (short))) | |
7a13e894 | 9730 | temp_index = 0; |
379b5ac0 KH |
9731 | temp_buffer[temp_index++] = copy_bufptr[i]; |
9732 | } | |
9733 | ||
9734 | if (/* If the event is not from XIM, */ | |
9735 | event.xkey.keycode != 0 | |
9736 | /* or the current locale doesn't request | |
9737 | decoding of the intup data, ... */ | |
9738 | || coding.type == coding_type_raw_text | |
9739 | || coding.type == coding_type_no_conversion) | |
9740 | { | |
9741 | /* ... we can use the input data as is. */ | |
9742 | nchars = nbytes; | |
9743 | } | |
9744 | else | |
9745 | { | |
9746 | /* We have to decode the input data. */ | |
9747 | int require; | |
9748 | unsigned char *p; | |
9749 | ||
9750 | require = decoding_buffer_size (&coding, nbytes); | |
9751 | p = (unsigned char *) alloca (require); | |
9752 | coding.mode |= CODING_MODE_LAST_BLOCK; | |
9753 | decode_coding (&coding, copy_bufptr, p, | |
9754 | nbytes, require); | |
9755 | nbytes = coding.produced; | |
9756 | nchars = coding.produced_char; | |
9757 | copy_bufptr = p; | |
9758 | } | |
9759 | ||
9760 | /* Convert the input data to a sequence of | |
9761 | character events. */ | |
9762 | for (i = 0; i < nbytes; i += len) | |
9763 | { | |
9764 | c = STRING_CHAR_AND_LENGTH (copy_bufptr + i, | |
9765 | nbytes - i, len); | |
9766 | bufp->kind = (SINGLE_BYTE_CHAR_P (c) | |
9767 | ? ascii_keystroke | |
9768 | : multibyte_char_keystroke); | |
9769 | bufp->code = c; | |
7a13e894 | 9770 | XSETFRAME (bufp->frame_or_window, f); |
0f8aabe9 | 9771 | bufp->arg = Qnil; |
7a13e894 RS |
9772 | bufp->modifiers |
9773 | = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), | |
9774 | modifiers); | |
9775 | bufp->timestamp = event.xkey.time; | |
9776 | bufp++; | |
9777 | } | |
9778 | ||
379b5ac0 KH |
9779 | count += nchars; |
9780 | numchars -= nchars; | |
1decb680 PE |
9781 | |
9782 | if (keysym == NoSymbol) | |
9783 | break; | |
7a13e894 RS |
9784 | } |
9785 | else | |
9786 | abort (); | |
dc6f92b8 | 9787 | } |
10e6549c RS |
9788 | else |
9789 | abort (); | |
dc6f92b8 | 9790 | } |
59ddecde GM |
9791 | #ifdef HAVE_X_I18N |
9792 | /* Don't dispatch this event since XtDispatchEvent calls | |
9793 | XFilterEvent, and two calls in a row may freeze the | |
9794 | client. */ | |
9795 | break; | |
9796 | #else | |
717ca130 | 9797 | goto OTHER; |
59ddecde | 9798 | #endif |
f451eb13 | 9799 | |
f5d11644 | 9800 | case KeyRelease: |
59ddecde GM |
9801 | #ifdef HAVE_X_I18N |
9802 | /* Don't dispatch this event since XtDispatchEvent calls | |
9803 | XFilterEvent, and two calls in a row may freeze the | |
9804 | client. */ | |
9805 | break; | |
9806 | #else | |
f5d11644 | 9807 | goto OTHER; |
59ddecde | 9808 | #endif |
f5d11644 | 9809 | |
7a13e894 | 9810 | /* Here's a possible interpretation of the whole |
06a2c219 GM |
9811 | FocusIn-EnterNotify FocusOut-LeaveNotify mess. If |
9812 | you get a FocusIn event, you have to get a FocusOut | |
9813 | event before you relinquish the focus. If you | |
9814 | haven't received a FocusIn event, then a mere | |
9815 | LeaveNotify is enough to free you. */ | |
f451eb13 | 9816 | |
7a13e894 | 9817 | case EnterNotify: |
06a2c219 GM |
9818 | { |
9819 | int from_menu_bar_p = 0; | |
9820 | ||
9821 | f = x_any_window_to_frame (dpyinfo, event.xcrossing.window); | |
9822 | ||
9823 | #ifdef LESSTIF_VERSION | |
9824 | /* When clicking outside of a menu bar popup to close | |
9825 | it, we get a FocusIn/ EnterNotify sequence of | |
9826 | events. The flag event.xcrossing.focus is not set | |
9827 | in the EnterNotify event of that sequence because | |
9828 | the focus is in the menu bar, | |
9829 | event.xcrossing.window is the frame's X window. | |
9830 | Unconditionally setting the focus frame to null in | |
9831 | this case is not the right thing, because no event | |
9832 | follows that could set the focus frame to the right | |
9833 | value. | |
9834 | ||
9835 | This could be a LessTif bug, but I wasn't able to | |
9836 | reproduce the behavior in a simple test program. | |
9837 | ||
9838 | (gerd, LessTif 0.88.1). */ | |
9839 | ||
9840 | if (!event.xcrossing.focus | |
9841 | && f | |
9842 | && f->output_data.x->menubar_widget) | |
9843 | { | |
9844 | Window focus; | |
9845 | int revert; | |
9846 | ||
9847 | XGetInputFocus (FRAME_X_DISPLAY (f), &focus, &revert); | |
9848 | if (focus == XtWindow (f->output_data.x->menubar_widget)) | |
9849 | from_menu_bar_p = 1; | |
9850 | } | |
9851 | #endif /* LESSTIF_VERSION */ | |
6d4238f3 | 9852 | |
06a2c219 GM |
9853 | if (event.xcrossing.focus || from_menu_bar_p) |
9854 | { | |
9855 | /* Avoid nasty pop/raise loops. */ | |
9856 | if (f && (!(f->auto_raise) | |
9857 | || !(f->auto_lower) | |
9858 | || (event.xcrossing.time - enter_timestamp) > 500)) | |
9859 | { | |
9860 | x_new_focus_frame (dpyinfo, f); | |
9861 | enter_timestamp = event.xcrossing.time; | |
9862 | } | |
9863 | } | |
9864 | else if (f == dpyinfo->x_focus_frame) | |
9865 | x_new_focus_frame (dpyinfo, 0); | |
9866 | ||
9867 | /* EnterNotify counts as mouse movement, | |
9868 | so update things that depend on mouse position. */ | |
9869 | if (f && !f->output_data.x->busy_p) | |
9870 | note_mouse_movement (f, &event.xmotion); | |
9871 | goto OTHER; | |
9872 | } | |
dc6f92b8 | 9873 | |
7a13e894 | 9874 | case FocusIn: |
19126e11 | 9875 | f = x_any_window_to_frame (dpyinfo, event.xfocus.window); |
7a13e894 | 9876 | if (event.xfocus.detail != NotifyPointer) |
0f941935 | 9877 | dpyinfo->x_focus_event_frame = f; |
7a13e894 | 9878 | if (f) |
eb72635f GM |
9879 | { |
9880 | x_new_focus_frame (dpyinfo, f); | |
9881 | ||
9882 | /* Don't stop displaying the initial startup message | |
9883 | for a switch-frame event we don't need. */ | |
9884 | if (GC_NILP (Vterminal_frame) | |
9885 | && GC_CONSP (Vframe_list) | |
9886 | && !GC_NILP (XCDR (Vframe_list))) | |
9887 | { | |
9888 | bufp->kind = FOCUS_IN_EVENT; | |
9889 | XSETFRAME (bufp->frame_or_window, f); | |
0f8aabe9 | 9890 | bufp->arg = Qnil; |
eb72635f GM |
9891 | ++bufp, ++count, --numchars; |
9892 | } | |
9893 | } | |
f9e24cb9 | 9894 | |
6c183ba5 RS |
9895 | #ifdef HAVE_X_I18N |
9896 | if (f && FRAME_XIC (f)) | |
9897 | XSetICFocus (FRAME_XIC (f)); | |
9898 | #endif | |
9899 | ||
7a13e894 | 9900 | goto OTHER; |
10c5e63d | 9901 | |
7a13e894 | 9902 | case LeaveNotify: |
19126e11 | 9903 | f = x_top_window_to_frame (dpyinfo, event.xcrossing.window); |
7a13e894 | 9904 | if (f) |
10c5e63d | 9905 | { |
06a2c219 GM |
9906 | Lisp_Object frame; |
9907 | int from_menu_bar_p = 0; | |
9908 | ||
7a13e894 | 9909 | if (f == dpyinfo->mouse_face_mouse_frame) |
06a2c219 GM |
9910 | { |
9911 | /* If we move outside the frame, then we're | |
9912 | certainly no longer on any text in the frame. */ | |
9913 | clear_mouse_face (dpyinfo); | |
9914 | dpyinfo->mouse_face_mouse_frame = 0; | |
9915 | } | |
9916 | ||
9917 | /* Generate a nil HELP_EVENT to cancel a help-echo. | |
9918 | Do it only if there's something to cancel. | |
9919 | Otherwise, the startup message is cleared when | |
9920 | the mouse leaves the frame. */ | |
9921 | if (any_help_event_p) | |
9922 | { | |
be010514 GM |
9923 | Lisp_Object frame; |
9924 | int n; | |
9925 | ||
06a2c219 | 9926 | XSETFRAME (frame, f); |
5ab2570d GM |
9927 | n = gen_help_event (bufp, numchars, |
9928 | Qnil, frame, Qnil, Qnil, 0); | |
be010514 | 9929 | bufp += n, count += n, numchars -= n; |
06a2c219 | 9930 | } |
7a13e894 | 9931 | |
06a2c219 GM |
9932 | #ifdef LESSTIF_VERSION |
9933 | /* Please see the comment at the start of the | |
9934 | EnterNotify case. */ | |
9935 | if (!event.xcrossing.focus | |
9936 | && f->output_data.x->menubar_widget) | |
9937 | { | |
9938 | Window focus; | |
9939 | int revert; | |
9940 | XGetInputFocus (FRAME_X_DISPLAY (f), &focus, &revert); | |
9941 | if (focus == XtWindow (f->output_data.x->menubar_widget)) | |
9942 | from_menu_bar_p = 1; | |
9943 | } | |
9944 | #endif /* LESSTIF_VERSION */ | |
9945 | ||
9946 | if (event.xcrossing.focus || from_menu_bar_p) | |
0f941935 | 9947 | x_mouse_leave (dpyinfo); |
10c5e63d | 9948 | else |
7a13e894 | 9949 | { |
0f941935 KH |
9950 | if (f == dpyinfo->x_focus_event_frame) |
9951 | dpyinfo->x_focus_event_frame = 0; | |
9952 | if (f == dpyinfo->x_focus_frame) | |
9953 | x_new_focus_frame (dpyinfo, 0); | |
7a13e894 | 9954 | } |
10c5e63d | 9955 | } |
7a13e894 | 9956 | goto OTHER; |
dc6f92b8 | 9957 | |
7a13e894 | 9958 | case FocusOut: |
19126e11 | 9959 | f = x_any_window_to_frame (dpyinfo, event.xfocus.window); |
7a13e894 | 9960 | if (event.xfocus.detail != NotifyPointer |
0f941935 KH |
9961 | && f == dpyinfo->x_focus_event_frame) |
9962 | dpyinfo->x_focus_event_frame = 0; | |
9963 | if (f && f == dpyinfo->x_focus_frame) | |
9964 | x_new_focus_frame (dpyinfo, 0); | |
f9e24cb9 | 9965 | |
6c183ba5 RS |
9966 | #ifdef HAVE_X_I18N |
9967 | if (f && FRAME_XIC (f)) | |
9968 | XUnsetICFocus (FRAME_XIC (f)); | |
9969 | #endif | |
9970 | ||
7a13e894 | 9971 | goto OTHER; |
dc6f92b8 | 9972 | |
7a13e894 | 9973 | case MotionNotify: |
dc6f92b8 | 9974 | { |
06a2c219 | 9975 | previous_help_echo = help_echo; |
7cea38bc | 9976 | help_echo = help_echo_object = help_echo_window = Qnil; |
be010514 | 9977 | help_echo_pos = -1; |
06a2c219 | 9978 | |
7a13e894 RS |
9979 | if (dpyinfo->grabbed && last_mouse_frame |
9980 | && FRAME_LIVE_P (last_mouse_frame)) | |
9981 | f = last_mouse_frame; | |
9982 | else | |
19126e11 | 9983 | f = x_window_to_frame (dpyinfo, event.xmotion.window); |
06a2c219 | 9984 | |
7a13e894 RS |
9985 | if (f) |
9986 | note_mouse_movement (f, &event.xmotion); | |
9987 | else | |
9988 | { | |
e88b3c50 | 9989 | #ifndef USE_TOOLKIT_SCROLL_BARS |
7a13e894 RS |
9990 | struct scroll_bar *bar |
9991 | = x_window_to_scroll_bar (event.xmotion.window); | |
f451eb13 | 9992 | |
7a13e894 RS |
9993 | if (bar) |
9994 | x_scroll_bar_note_movement (bar, &event); | |
e88b3c50 | 9995 | #endif /* USE_TOOLKIT_SCROLL_BARS */ |
b8009dd1 | 9996 | |
06a2c219 GM |
9997 | /* If we move outside the frame, then we're |
9998 | certainly no longer on any text in the frame. */ | |
7a13e894 RS |
9999 | clear_mouse_face (dpyinfo); |
10000 | } | |
06a2c219 GM |
10001 | |
10002 | /* If the contents of the global variable help_echo | |
10003 | has changed, generate a HELP_EVENT. */ | |
b7e80413 SM |
10004 | if (!NILP (help_echo) |
10005 | || !NILP (previous_help_echo)) | |
06a2c219 GM |
10006 | { |
10007 | Lisp_Object frame; | |
be010514 | 10008 | int n; |
06a2c219 GM |
10009 | |
10010 | if (f) | |
10011 | XSETFRAME (frame, f); | |
10012 | else | |
10013 | frame = Qnil; | |
10014 | ||
10015 | any_help_event_p = 1; | |
5ab2570d | 10016 | n = gen_help_event (bufp, numchars, help_echo, frame, |
7cea38bc GM |
10017 | help_echo_window, help_echo_object, |
10018 | help_echo_pos); | |
be010514 | 10019 | bufp += n, count += n, numchars -= n; |
06a2c219 GM |
10020 | } |
10021 | ||
10022 | goto OTHER; | |
dc6f92b8 | 10023 | } |
dc6f92b8 | 10024 | |
7a13e894 | 10025 | case ConfigureNotify: |
9829ddba RS |
10026 | f = x_top_window_to_frame (dpyinfo, event.xconfigure.window); |
10027 | if (f) | |
af395ec1 | 10028 | { |
5c187dee | 10029 | #ifndef USE_X_TOOLKIT |
bf1b7b30 KH |
10030 | int rows = PIXEL_TO_CHAR_HEIGHT (f, event.xconfigure.height); |
10031 | int columns = PIXEL_TO_CHAR_WIDTH (f, event.xconfigure.width); | |
5c187dee | 10032 | |
2d7fc7e8 RS |
10033 | /* In the toolkit version, change_frame_size |
10034 | is called by the code that handles resizing | |
10035 | of the EmacsFrame widget. */ | |
7a13e894 | 10036 | |
7a13e894 RS |
10037 | /* Even if the number of character rows and columns has |
10038 | not changed, the font size may have changed, so we need | |
10039 | to check the pixel dimensions as well. */ | |
10040 | if (columns != f->width | |
10041 | || rows != f->height | |
7556890b RS |
10042 | || event.xconfigure.width != f->output_data.x->pixel_width |
10043 | || event.xconfigure.height != f->output_data.x->pixel_height) | |
7a13e894 | 10044 | { |
7d1e984f | 10045 | change_frame_size (f, rows, columns, 0, 1, 0); |
7a13e894 | 10046 | SET_FRAME_GARBAGED (f); |
e687d06e | 10047 | cancel_mouse_face (f); |
7a13e894 | 10048 | } |
2d7fc7e8 | 10049 | #endif |
af395ec1 | 10050 | |
7556890b RS |
10051 | f->output_data.x->pixel_width = event.xconfigure.width; |
10052 | f->output_data.x->pixel_height = event.xconfigure.height; | |
7a13e894 RS |
10053 | |
10054 | /* What we have now is the position of Emacs's own window. | |
10055 | Convert that to the position of the window manager window. */ | |
dcb07ae9 RS |
10056 | x_real_positions (f, &f->output_data.x->left_pos, |
10057 | &f->output_data.x->top_pos); | |
10058 | ||
f5d11644 GM |
10059 | #ifdef HAVE_X_I18N |
10060 | if (FRAME_XIC (f) && (FRAME_XIC_STYLE (f) & XIMStatusArea)) | |
10061 | xic_set_statusarea (f); | |
10062 | #endif | |
10063 | ||
dcb07ae9 RS |
10064 | if (f->output_data.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window) |
10065 | { | |
10066 | /* Since the WM decorations come below top_pos now, | |
10067 | we must put them below top_pos in the future. */ | |
10068 | f->output_data.x->win_gravity = NorthWestGravity; | |
10069 | x_wm_set_size_hint (f, (long) 0, 0); | |
10070 | } | |
8f08dc93 KH |
10071 | #ifdef USE_MOTIF |
10072 | /* Some window managers pass (0,0) as the location of | |
10073 | the window, and the Motif event handler stores it | |
10074 | in the emacs widget, which messes up Motif menus. */ | |
10075 | if (event.xconfigure.x == 0 && event.xconfigure.y == 0) | |
10076 | { | |
10077 | event.xconfigure.x = f->output_data.x->widget->core.x; | |
10078 | event.xconfigure.y = f->output_data.x->widget->core.y; | |
10079 | } | |
06a2c219 | 10080 | #endif /* USE_MOTIF */ |
7a13e894 | 10081 | } |
2d7fc7e8 | 10082 | goto OTHER; |
dc6f92b8 | 10083 | |
7a13e894 RS |
10084 | case ButtonPress: |
10085 | case ButtonRelease: | |
10086 | { | |
10087 | /* If we decide we want to generate an event to be seen | |
10088 | by the rest of Emacs, we put it here. */ | |
10089 | struct input_event emacs_event; | |
9ea173e8 | 10090 | int tool_bar_p = 0; |
06a2c219 | 10091 | |
7a13e894 | 10092 | emacs_event.kind = no_event; |
7a13e894 | 10093 | bzero (&compose_status, sizeof (compose_status)); |
9b07615b | 10094 | |
06a2c219 GM |
10095 | if (dpyinfo->grabbed |
10096 | && last_mouse_frame | |
9f67f20b RS |
10097 | && FRAME_LIVE_P (last_mouse_frame)) |
10098 | f = last_mouse_frame; | |
10099 | else | |
2224b905 | 10100 | f = x_window_to_frame (dpyinfo, event.xbutton.window); |
9f67f20b | 10101 | |
06a2c219 GM |
10102 | if (f) |
10103 | { | |
9ea173e8 GM |
10104 | /* Is this in the tool-bar? */ |
10105 | if (WINDOWP (f->tool_bar_window) | |
10106 | && XFASTINT (XWINDOW (f->tool_bar_window)->height)) | |
06a2c219 GM |
10107 | { |
10108 | Lisp_Object window; | |
10109 | int p, x, y; | |
10110 | ||
10111 | x = event.xbutton.x; | |
10112 | y = event.xbutton.y; | |
10113 | ||
10114 | /* Set x and y. */ | |
10115 | window = window_from_coordinates (f, x, y, &p, 1); | |
9ea173e8 | 10116 | if (EQ (window, f->tool_bar_window)) |
06a2c219 | 10117 | { |
9ea173e8 GM |
10118 | x_handle_tool_bar_click (f, &event.xbutton); |
10119 | tool_bar_p = 1; | |
06a2c219 GM |
10120 | } |
10121 | } | |
10122 | ||
9ea173e8 | 10123 | if (!tool_bar_p) |
06a2c219 GM |
10124 | if (!dpyinfo->x_focus_frame |
10125 | || f == dpyinfo->x_focus_frame) | |
10126 | construct_mouse_click (&emacs_event, &event, f); | |
7a13e894 RS |
10127 | } |
10128 | else | |
10129 | { | |
06a2c219 | 10130 | #ifndef USE_TOOLKIT_SCROLL_BARS |
7a13e894 RS |
10131 | struct scroll_bar *bar |
10132 | = x_window_to_scroll_bar (event.xbutton.window); | |
f451eb13 | 10133 | |
7a13e894 RS |
10134 | if (bar) |
10135 | x_scroll_bar_handle_click (bar, &event, &emacs_event); | |
06a2c219 | 10136 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
7a13e894 RS |
10137 | } |
10138 | ||
10139 | if (event.type == ButtonPress) | |
10140 | { | |
10141 | dpyinfo->grabbed |= (1 << event.xbutton.button); | |
10142 | last_mouse_frame = f; | |
edad46f6 KH |
10143 | /* Ignore any mouse motion that happened |
10144 | before this event; any subsequent mouse-movement | |
10145 | Emacs events should reflect only motion after | |
10146 | the ButtonPress. */ | |
a00e91cd KH |
10147 | if (f != 0) |
10148 | f->mouse_moved = 0; | |
06a2c219 | 10149 | |
9ea173e8 GM |
10150 | if (!tool_bar_p) |
10151 | last_tool_bar_item = -1; | |
7a13e894 | 10152 | } |
3afe33e7 RS |
10153 | else |
10154 | { | |
7a13e894 | 10155 | dpyinfo->grabbed &= ~(1 << event.xbutton.button); |
3afe33e7 | 10156 | } |
23faf38f | 10157 | |
7a13e894 RS |
10158 | if (numchars >= 1 && emacs_event.kind != no_event) |
10159 | { | |
10160 | bcopy (&emacs_event, bufp, sizeof (struct input_event)); | |
10161 | bufp++; | |
10162 | count++; | |
10163 | numchars--; | |
10164 | } | |
3afe33e7 RS |
10165 | |
10166 | #ifdef USE_X_TOOLKIT | |
2224b905 RS |
10167 | f = x_menubar_window_to_frame (dpyinfo, event.xbutton.window); |
10168 | /* For a down-event in the menu bar, | |
10169 | don't pass it to Xt right now. | |
10170 | Instead, save it away | |
10171 | and we will pass it to Xt from kbd_buffer_get_event. | |
10172 | That way, we can run some Lisp code first. */ | |
91375f8f RS |
10173 | if (f && event.type == ButtonPress |
10174 | /* Verify the event is really within the menu bar | |
10175 | and not just sent to it due to grabbing. */ | |
10176 | && event.xbutton.x >= 0 | |
10177 | && event.xbutton.x < f->output_data.x->pixel_width | |
10178 | && event.xbutton.y >= 0 | |
10179 | && event.xbutton.y < f->output_data.x->menubar_height | |
10180 | && event.xbutton.same_screen) | |
2224b905 | 10181 | { |
8805890a | 10182 | SET_SAVED_BUTTON_EVENT; |
2237cac9 RS |
10183 | XSETFRAME (last_mouse_press_frame, f); |
10184 | } | |
10185 | else if (event.type == ButtonPress) | |
10186 | { | |
10187 | last_mouse_press_frame = Qnil; | |
30e671c3 | 10188 | goto OTHER; |
ce89ef46 | 10189 | } |
06a2c219 | 10190 | |
2237cac9 RS |
10191 | #ifdef USE_MOTIF /* This should do not harm for Lucid, |
10192 | but I am trying to be cautious. */ | |
ce89ef46 RS |
10193 | else if (event.type == ButtonRelease) |
10194 | { | |
2237cac9 | 10195 | if (!NILP (last_mouse_press_frame)) |
f10ded1c | 10196 | { |
2237cac9 RS |
10197 | f = XFRAME (last_mouse_press_frame); |
10198 | if (f->output_data.x) | |
06a2c219 | 10199 | SET_SAVED_BUTTON_EVENT; |
f10ded1c | 10200 | } |
06a2c219 | 10201 | else |
30e671c3 | 10202 | goto OTHER; |
2224b905 | 10203 | } |
2237cac9 | 10204 | #endif /* USE_MOTIF */ |
2224b905 RS |
10205 | else |
10206 | goto OTHER; | |
3afe33e7 | 10207 | #endif /* USE_X_TOOLKIT */ |
7a13e894 RS |
10208 | } |
10209 | break; | |
dc6f92b8 | 10210 | |
7a13e894 | 10211 | case CirculateNotify: |
06a2c219 GM |
10212 | goto OTHER; |
10213 | ||
7a13e894 | 10214 | case CirculateRequest: |
06a2c219 GM |
10215 | goto OTHER; |
10216 | ||
10217 | case VisibilityNotify: | |
10218 | goto OTHER; | |
dc6f92b8 | 10219 | |
7a13e894 RS |
10220 | case MappingNotify: |
10221 | /* Someone has changed the keyboard mapping - update the | |
10222 | local cache. */ | |
10223 | switch (event.xmapping.request) | |
10224 | { | |
10225 | case MappingModifier: | |
10226 | x_find_modifier_meanings (dpyinfo); | |
10227 | /* This is meant to fall through. */ | |
10228 | case MappingKeyboard: | |
10229 | XRefreshKeyboardMapping (&event.xmapping); | |
10230 | } | |
7a13e894 | 10231 | goto OTHER; |
dc6f92b8 | 10232 | |
7a13e894 | 10233 | default: |
7a13e894 | 10234 | OTHER: |
717ca130 | 10235 | #ifdef USE_X_TOOLKIT |
7a13e894 RS |
10236 | BLOCK_INPUT; |
10237 | XtDispatchEvent (&event); | |
10238 | UNBLOCK_INPUT; | |
3afe33e7 | 10239 | #endif /* USE_X_TOOLKIT */ |
7a13e894 RS |
10240 | break; |
10241 | } | |
dc6f92b8 JB |
10242 | } |
10243 | } | |
10244 | ||
06a2c219 GM |
10245 | out:; |
10246 | ||
9a5196d0 RS |
10247 | /* On some systems, an X bug causes Emacs to get no more events |
10248 | when the window is destroyed. Detect that. (1994.) */ | |
58769bee | 10249 | if (! event_found) |
ef2a22d0 | 10250 | { |
ef2a22d0 RS |
10251 | /* Emacs and the X Server eats up CPU time if XNoOp is done every time. |
10252 | One XNOOP in 100 loops will make Emacs terminate. | |
10253 | B. Bretthauer, 1994 */ | |
10254 | x_noop_count++; | |
58769bee | 10255 | if (x_noop_count >= 100) |
ef2a22d0 RS |
10256 | { |
10257 | x_noop_count=0; | |
2224b905 RS |
10258 | |
10259 | if (next_noop_dpyinfo == 0) | |
10260 | next_noop_dpyinfo = x_display_list; | |
10261 | ||
10262 | XNoOp (next_noop_dpyinfo->display); | |
10263 | ||
10264 | /* Each time we get here, cycle through the displays now open. */ | |
10265 | next_noop_dpyinfo = next_noop_dpyinfo->next; | |
ef2a22d0 RS |
10266 | } |
10267 | } | |
502add23 | 10268 | |
06a2c219 | 10269 | /* If the focus was just given to an auto-raising frame, |
0134a210 | 10270 | raise it now. */ |
7a13e894 | 10271 | /* ??? This ought to be able to handle more than one such frame. */ |
0134a210 RS |
10272 | if (pending_autoraise_frame) |
10273 | { | |
10274 | x_raise_frame (pending_autoraise_frame); | |
10275 | pending_autoraise_frame = 0; | |
10276 | } | |
0134a210 | 10277 | |
dc6f92b8 | 10278 | UNBLOCK_INPUT; |
bde5503b | 10279 | --handling_signal; |
dc6f92b8 JB |
10280 | return count; |
10281 | } | |
06a2c219 GM |
10282 | |
10283 | ||
10284 | ||
dc6f92b8 | 10285 | \f |
06a2c219 GM |
10286 | /*********************************************************************** |
10287 | Text Cursor | |
10288 | ***********************************************************************/ | |
10289 | ||
10290 | /* Note if the text cursor of window W has been overwritten by a | |
10291 | drawing operation that outputs N glyphs starting at HPOS in the | |
10292 | line given by output_cursor.vpos. N < 0 means all the rest of the | |
10293 | line after HPOS has been written. */ | |
10294 | ||
10295 | static void | |
10296 | note_overwritten_text_cursor (w, hpos, n) | |
10297 | struct window *w; | |
10298 | int hpos, n; | |
10299 | { | |
10300 | if (updated_area == TEXT_AREA | |
10301 | && output_cursor.vpos == w->phys_cursor.vpos | |
10302 | && hpos <= w->phys_cursor.hpos | |
10303 | && (n < 0 | |
10304 | || hpos + n > w->phys_cursor.hpos)) | |
10305 | w->phys_cursor_on_p = 0; | |
10306 | } | |
f451eb13 JB |
10307 | |
10308 | ||
06a2c219 GM |
10309 | /* Set clipping for output in glyph row ROW. W is the window in which |
10310 | we operate. GC is the graphics context to set clipping in. | |
10311 | WHOLE_LINE_P non-zero means include the areas used for truncation | |
10312 | mark display and alike in the clipping rectangle. | |
10313 | ||
10314 | ROW may be a text row or, e.g., a mode line. Text rows must be | |
10315 | clipped to the interior of the window dedicated to text display, | |
10316 | mode lines must be clipped to the whole window. */ | |
dc6f92b8 JB |
10317 | |
10318 | static void | |
06a2c219 GM |
10319 | x_clip_to_row (w, row, gc, whole_line_p) |
10320 | struct window *w; | |
10321 | struct glyph_row *row; | |
10322 | GC gc; | |
10323 | int whole_line_p; | |
dc6f92b8 | 10324 | { |
06a2c219 GM |
10325 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
10326 | XRectangle clip_rect; | |
10327 | int window_x, window_y, window_width, window_height; | |
dc6f92b8 | 10328 | |
06a2c219 | 10329 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); |
5c1aae96 | 10330 | |
06a2c219 GM |
10331 | clip_rect.x = WINDOW_TO_FRAME_PIXEL_X (w, 0); |
10332 | clip_rect.y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
10333 | clip_rect.y = max (clip_rect.y, window_y); | |
10334 | clip_rect.width = window_width; | |
10335 | clip_rect.height = row->visible_height; | |
5c1aae96 | 10336 | |
06a2c219 GM |
10337 | /* If clipping to the whole line, including trunc marks, extend |
10338 | the rectangle to the left and increase its width. */ | |
10339 | if (whole_line_p) | |
10340 | { | |
110859fc GM |
10341 | clip_rect.x -= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f); |
10342 | clip_rect.width += FRAME_X_FLAGS_AREA_WIDTH (f); | |
06a2c219 | 10343 | } |
5c1aae96 | 10344 | |
06a2c219 | 10345 | XSetClipRectangles (FRAME_X_DISPLAY (f), gc, 0, 0, &clip_rect, 1, Unsorted); |
dc6f92b8 JB |
10346 | } |
10347 | ||
06a2c219 GM |
10348 | |
10349 | /* Draw a hollow box cursor on window W in glyph row ROW. */ | |
dc6f92b8 JB |
10350 | |
10351 | static void | |
06a2c219 GM |
10352 | x_draw_hollow_cursor (w, row) |
10353 | struct window *w; | |
10354 | struct glyph_row *row; | |
dc6f92b8 | 10355 | { |
06a2c219 GM |
10356 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
10357 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
10358 | Display *dpy = FRAME_X_DISPLAY (f); | |
10359 | int x, y, wd, h; | |
10360 | XGCValues xgcv; | |
10361 | struct glyph *cursor_glyph; | |
10362 | GC gc; | |
10363 | ||
10364 | /* Compute frame-relative coordinates from window-relative | |
10365 | coordinates. */ | |
10366 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); | |
10367 | y = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y) | |
10368 | + row->ascent - w->phys_cursor_ascent); | |
10369 | h = row->height - 1; | |
10370 | ||
10371 | /* Get the glyph the cursor is on. If we can't tell because | |
10372 | the current matrix is invalid or such, give up. */ | |
10373 | cursor_glyph = get_phys_cursor_glyph (w); | |
10374 | if (cursor_glyph == NULL) | |
dc6f92b8 JB |
10375 | return; |
10376 | ||
06a2c219 GM |
10377 | /* Compute the width of the rectangle to draw. If on a stretch |
10378 | glyph, and `x-stretch-block-cursor' is nil, don't draw a | |
10379 | rectangle as wide as the glyph, but use a canonical character | |
10380 | width instead. */ | |
10381 | wd = cursor_glyph->pixel_width - 1; | |
10382 | if (cursor_glyph->type == STRETCH_GLYPH | |
10383 | && !x_stretch_cursor_p) | |
10384 | wd = min (CANON_X_UNIT (f), wd); | |
10385 | ||
10386 | /* The foreground of cursor_gc is typically the same as the normal | |
10387 | background color, which can cause the cursor box to be invisible. */ | |
10388 | xgcv.foreground = f->output_data.x->cursor_pixel; | |
10389 | if (dpyinfo->scratch_cursor_gc) | |
10390 | XChangeGC (dpy, dpyinfo->scratch_cursor_gc, GCForeground, &xgcv); | |
10391 | else | |
10392 | dpyinfo->scratch_cursor_gc = XCreateGC (dpy, FRAME_X_WINDOW (f), | |
10393 | GCForeground, &xgcv); | |
10394 | gc = dpyinfo->scratch_cursor_gc; | |
10395 | ||
10396 | /* Set clipping, draw the rectangle, and reset clipping again. */ | |
10397 | x_clip_to_row (w, row, gc, 0); | |
10398 | XDrawRectangle (dpy, FRAME_X_WINDOW (f), gc, x, y, wd, h); | |
10399 | XSetClipMask (dpy, gc, None); | |
dc6f92b8 JB |
10400 | } |
10401 | ||
06a2c219 GM |
10402 | |
10403 | /* Draw a bar cursor on window W in glyph row ROW. | |
10404 | ||
10405 | Implementation note: One would like to draw a bar cursor with an | |
10406 | angle equal to the one given by the font property XA_ITALIC_ANGLE. | |
10407 | Unfortunately, I didn't find a font yet that has this property set. | |
10408 | --gerd. */ | |
dc6f92b8 JB |
10409 | |
10410 | static void | |
f02d8aa0 | 10411 | x_draw_bar_cursor (w, row, width) |
06a2c219 GM |
10412 | struct window *w; |
10413 | struct glyph_row *row; | |
f02d8aa0 | 10414 | int width; |
dc6f92b8 | 10415 | { |
92f424df GM |
10416 | struct frame *f = XFRAME (w->frame); |
10417 | struct glyph *cursor_glyph; | |
10418 | GC gc; | |
10419 | int x; | |
10420 | unsigned long mask; | |
10421 | XGCValues xgcv; | |
10422 | Display *dpy; | |
10423 | Window window; | |
06a2c219 | 10424 | |
92f424df GM |
10425 | /* If cursor is out of bounds, don't draw garbage. This can happen |
10426 | in mini-buffer windows when switching between echo area glyphs | |
10427 | and mini-buffer. */ | |
10428 | cursor_glyph = get_phys_cursor_glyph (w); | |
10429 | if (cursor_glyph == NULL) | |
10430 | return; | |
06a2c219 | 10431 | |
92f424df GM |
10432 | /* If on an image, draw like a normal cursor. That's usually better |
10433 | visible than drawing a bar, esp. if the image is large so that | |
10434 | the bar might not be in the window. */ | |
10435 | if (cursor_glyph->type == IMAGE_GLYPH) | |
10436 | { | |
10437 | struct glyph_row *row; | |
10438 | row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos); | |
10439 | x_draw_phys_cursor_glyph (w, row, DRAW_CURSOR); | |
10440 | } | |
10441 | else | |
10442 | { | |
06a2c219 GM |
10443 | xgcv.background = f->output_data.x->cursor_pixel; |
10444 | xgcv.foreground = f->output_data.x->cursor_pixel; | |
10445 | xgcv.graphics_exposures = 0; | |
10446 | mask = GCForeground | GCBackground | GCGraphicsExposures; | |
10447 | dpy = FRAME_X_DISPLAY (f); | |
10448 | window = FRAME_X_WINDOW (f); | |
10449 | gc = FRAME_X_DISPLAY_INFO (f)->scratch_cursor_gc; | |
92f424df | 10450 | |
06a2c219 GM |
10451 | if (gc) |
10452 | XChangeGC (dpy, gc, mask, &xgcv); | |
10453 | else | |
10454 | { | |
10455 | gc = XCreateGC (dpy, window, mask, &xgcv); | |
10456 | FRAME_X_DISPLAY_INFO (f)->scratch_cursor_gc = gc; | |
10457 | } | |
92f424df | 10458 | |
f02d8aa0 GM |
10459 | if (width < 0) |
10460 | width = f->output_data.x->cursor_width; | |
92f424df | 10461 | |
06a2c219 GM |
10462 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
10463 | x_clip_to_row (w, row, gc, 0); | |
10464 | XFillRectangle (dpy, window, gc, | |
10465 | x, | |
10466 | WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y), | |
f02d8aa0 | 10467 | min (cursor_glyph->pixel_width, width), |
06a2c219 GM |
10468 | row->height); |
10469 | XSetClipMask (dpy, gc, None); | |
10470 | } | |
dc6f92b8 JB |
10471 | } |
10472 | ||
06a2c219 GM |
10473 | |
10474 | /* Clear the cursor of window W to background color, and mark the | |
10475 | cursor as not shown. This is used when the text where the cursor | |
10476 | is is about to be rewritten. */ | |
10477 | ||
dc6f92b8 | 10478 | static void |
06a2c219 GM |
10479 | x_clear_cursor (w) |
10480 | struct window *w; | |
dc6f92b8 | 10481 | { |
06a2c219 GM |
10482 | if (FRAME_VISIBLE_P (XFRAME (w->frame)) && w->phys_cursor_on_p) |
10483 | x_update_window_cursor (w, 0); | |
10484 | } | |
90e65f07 | 10485 | |
dbc4e1c1 | 10486 | |
06a2c219 GM |
10487 | /* Draw the cursor glyph of window W in glyph row ROW. See the |
10488 | comment of x_draw_glyphs for the meaning of HL. */ | |
dbc4e1c1 | 10489 | |
06a2c219 GM |
10490 | static void |
10491 | x_draw_phys_cursor_glyph (w, row, hl) | |
10492 | struct window *w; | |
10493 | struct glyph_row *row; | |
10494 | enum draw_glyphs_face hl; | |
10495 | { | |
10496 | /* If cursor hpos is out of bounds, don't draw garbage. This can | |
10497 | happen in mini-buffer windows when switching between echo area | |
10498 | glyphs and mini-buffer. */ | |
10499 | if (w->phys_cursor.hpos < row->used[TEXT_AREA]) | |
66ac4b0e GM |
10500 | { |
10501 | x_draw_glyphs (w, w->phys_cursor.x, row, TEXT_AREA, | |
10502 | w->phys_cursor.hpos, w->phys_cursor.hpos + 1, | |
10503 | hl, 0, 0, 0); | |
10504 | ||
10505 | /* When we erase the cursor, and ROW is overlapped by other | |
10506 | rows, make sure that these overlapping parts of other rows | |
10507 | are redrawn. */ | |
10508 | if (hl == DRAW_NORMAL_TEXT && row->overlapped_p) | |
10509 | { | |
10510 | if (row > w->current_matrix->rows | |
10511 | && MATRIX_ROW_OVERLAPS_SUCC_P (row - 1)) | |
10512 | x_fix_overlapping_area (w, row - 1, TEXT_AREA); | |
10513 | ||
10514 | if (MATRIX_ROW_BOTTOM_Y (row) < window_text_bottom_y (w) | |
10515 | && MATRIX_ROW_OVERLAPS_PRED_P (row + 1)) | |
10516 | x_fix_overlapping_area (w, row + 1, TEXT_AREA); | |
10517 | } | |
10518 | } | |
06a2c219 | 10519 | } |
dbc4e1c1 | 10520 | |
eea6af04 | 10521 | |
06a2c219 | 10522 | /* Erase the image of a cursor of window W from the screen. */ |
eea6af04 | 10523 | |
06a2c219 GM |
10524 | static void |
10525 | x_erase_phys_cursor (w) | |
10526 | struct window *w; | |
10527 | { | |
10528 | struct frame *f = XFRAME (w->frame); | |
10529 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
10530 | int hpos = w->phys_cursor.hpos; | |
10531 | int vpos = w->phys_cursor.vpos; | |
10532 | int mouse_face_here_p = 0; | |
10533 | struct glyph_matrix *active_glyphs = w->current_matrix; | |
10534 | struct glyph_row *cursor_row; | |
10535 | struct glyph *cursor_glyph; | |
10536 | enum draw_glyphs_face hl; | |
10537 | ||
10538 | /* No cursor displayed or row invalidated => nothing to do on the | |
10539 | screen. */ | |
10540 | if (w->phys_cursor_type == NO_CURSOR) | |
10541 | goto mark_cursor_off; | |
10542 | ||
10543 | /* VPOS >= active_glyphs->nrows means that window has been resized. | |
10544 | Don't bother to erase the cursor. */ | |
10545 | if (vpos >= active_glyphs->nrows) | |
10546 | goto mark_cursor_off; | |
10547 | ||
10548 | /* If row containing cursor is marked invalid, there is nothing we | |
10549 | can do. */ | |
10550 | cursor_row = MATRIX_ROW (active_glyphs, vpos); | |
10551 | if (!cursor_row->enabled_p) | |
10552 | goto mark_cursor_off; | |
10553 | ||
10554 | /* This can happen when the new row is shorter than the old one. | |
10555 | In this case, either x_draw_glyphs or clear_end_of_line | |
10556 | should have cleared the cursor. Note that we wouldn't be | |
10557 | able to erase the cursor in this case because we don't have a | |
10558 | cursor glyph at hand. */ | |
10559 | if (w->phys_cursor.hpos >= cursor_row->used[TEXT_AREA]) | |
10560 | goto mark_cursor_off; | |
10561 | ||
10562 | /* If the cursor is in the mouse face area, redisplay that when | |
10563 | we clear the cursor. */ | |
8801a864 KR |
10564 | if (! NILP (dpyinfo->mouse_face_window) |
10565 | && w == XWINDOW (dpyinfo->mouse_face_window) | |
06a2c219 GM |
10566 | && (vpos > dpyinfo->mouse_face_beg_row |
10567 | || (vpos == dpyinfo->mouse_face_beg_row | |
10568 | && hpos >= dpyinfo->mouse_face_beg_col)) | |
10569 | && (vpos < dpyinfo->mouse_face_end_row | |
10570 | || (vpos == dpyinfo->mouse_face_end_row | |
10571 | && hpos < dpyinfo->mouse_face_end_col)) | |
10572 | /* Don't redraw the cursor's spot in mouse face if it is at the | |
10573 | end of a line (on a newline). The cursor appears there, but | |
10574 | mouse highlighting does not. */ | |
10575 | && cursor_row->used[TEXT_AREA] > hpos) | |
10576 | mouse_face_here_p = 1; | |
10577 | ||
10578 | /* Maybe clear the display under the cursor. */ | |
10579 | if (w->phys_cursor_type == HOLLOW_BOX_CURSOR) | |
10580 | { | |
10581 | int x; | |
045dee35 | 10582 | int header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); |
dbc4e1c1 | 10583 | |
06a2c219 GM |
10584 | cursor_glyph = get_phys_cursor_glyph (w); |
10585 | if (cursor_glyph == NULL) | |
10586 | goto mark_cursor_off; | |
dbc4e1c1 | 10587 | |
06a2c219 GM |
10588 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x), |
10589 | ||
10590 | XClearArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
10591 | x, | |
045dee35 | 10592 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, |
06a2c219 GM |
10593 | cursor_row->y)), |
10594 | cursor_glyph->pixel_width, | |
10595 | cursor_row->visible_height, | |
10596 | False); | |
dbc4e1c1 | 10597 | } |
06a2c219 GM |
10598 | |
10599 | /* Erase the cursor by redrawing the character underneath it. */ | |
10600 | if (mouse_face_here_p) | |
10601 | hl = DRAW_MOUSE_FACE; | |
10602 | else if (cursor_row->inverse_p) | |
10603 | hl = DRAW_INVERSE_VIDEO; | |
10604 | else | |
10605 | hl = DRAW_NORMAL_TEXT; | |
10606 | x_draw_phys_cursor_glyph (w, cursor_row, hl); | |
dbc4e1c1 | 10607 | |
06a2c219 GM |
10608 | mark_cursor_off: |
10609 | w->phys_cursor_on_p = 0; | |
10610 | w->phys_cursor_type = NO_CURSOR; | |
dbc4e1c1 JB |
10611 | } |
10612 | ||
10613 | ||
06a2c219 GM |
10614 | /* Display or clear cursor of window W. If ON is zero, clear the |
10615 | cursor. If it is non-zero, display the cursor. If ON is nonzero, | |
10616 | where to put the cursor is specified by HPOS, VPOS, X and Y. */ | |
dbc4e1c1 | 10617 | |
06a2c219 GM |
10618 | void |
10619 | x_display_and_set_cursor (w, on, hpos, vpos, x, y) | |
10620 | struct window *w; | |
10621 | int on, hpos, vpos, x, y; | |
dbc4e1c1 | 10622 | { |
06a2c219 GM |
10623 | struct frame *f = XFRAME (w->frame); |
10624 | int new_cursor_type; | |
f02d8aa0 | 10625 | int new_cursor_width; |
06a2c219 GM |
10626 | struct glyph_matrix *current_glyphs; |
10627 | struct glyph_row *glyph_row; | |
10628 | struct glyph *glyph; | |
dbc4e1c1 | 10629 | |
49d838ea | 10630 | /* This is pointless on invisible frames, and dangerous on garbaged |
06a2c219 GM |
10631 | windows and frames; in the latter case, the frame or window may |
10632 | be in the midst of changing its size, and x and y may be off the | |
10633 | window. */ | |
10634 | if (! FRAME_VISIBLE_P (f) | |
10635 | || FRAME_GARBAGED_P (f) | |
10636 | || vpos >= w->current_matrix->nrows | |
10637 | || hpos >= w->current_matrix->matrix_w) | |
dc6f92b8 JB |
10638 | return; |
10639 | ||
10640 | /* If cursor is off and we want it off, return quickly. */ | |
06a2c219 | 10641 | if (!on && !w->phys_cursor_on_p) |
dc6f92b8 JB |
10642 | return; |
10643 | ||
06a2c219 GM |
10644 | current_glyphs = w->current_matrix; |
10645 | glyph_row = MATRIX_ROW (current_glyphs, vpos); | |
10646 | glyph = glyph_row->glyphs[TEXT_AREA] + hpos; | |
10647 | ||
10648 | /* If cursor row is not enabled, we don't really know where to | |
10649 | display the cursor. */ | |
10650 | if (!glyph_row->enabled_p) | |
10651 | { | |
10652 | w->phys_cursor_on_p = 0; | |
10653 | return; | |
10654 | } | |
10655 | ||
10656 | xassert (interrupt_input_blocked); | |
10657 | ||
10658 | /* Set new_cursor_type to the cursor we want to be displayed. In a | |
10659 | mini-buffer window, we want the cursor only to appear if we are | |
10660 | reading input from this window. For the selected window, we want | |
10661 | the cursor type given by the frame parameter. If explicitly | |
10662 | marked off, draw no cursor. In all other cases, we want a hollow | |
10663 | box cursor. */ | |
f02d8aa0 | 10664 | new_cursor_width = -1; |
9b4a7047 GM |
10665 | if (cursor_in_echo_area |
10666 | && FRAME_HAS_MINIBUF_P (f) | |
10667 | && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window)) | |
06a2c219 | 10668 | { |
9b4a7047 GM |
10669 | if (w == XWINDOW (echo_area_window)) |
10670 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
06a2c219 GM |
10671 | else |
10672 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
10673 | } | |
06a2c219 | 10674 | else |
9b4a7047 GM |
10675 | { |
10676 | if (w != XWINDOW (selected_window) | |
10677 | || f != FRAME_X_DISPLAY_INFO (f)->x_highlight_frame) | |
10678 | { | |
e55a0b79 GM |
10679 | extern int cursor_in_non_selected_windows; |
10680 | ||
5cefa566 GM |
10681 | if (MINI_WINDOW_P (w) |
10682 | || !cursor_in_non_selected_windows | |
10683 | || NILP (XBUFFER (w->buffer)->cursor_type)) | |
9b4a7047 GM |
10684 | new_cursor_type = NO_CURSOR; |
10685 | else | |
10686 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
10687 | } | |
10688 | else if (w->cursor_off_p) | |
10689 | new_cursor_type = NO_CURSOR; | |
10690 | else | |
f02d8aa0 GM |
10691 | { |
10692 | struct buffer *b = XBUFFER (w->buffer); | |
10693 | ||
10694 | if (EQ (b->cursor_type, Qt)) | |
10695 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
10696 | else | |
10697 | new_cursor_type = x_specified_cursor_type (b->cursor_type, | |
10698 | &new_cursor_width); | |
10699 | } | |
9b4a7047 | 10700 | } |
06a2c219 GM |
10701 | |
10702 | /* If cursor is currently being shown and we don't want it to be or | |
10703 | it is in the wrong place, or the cursor type is not what we want, | |
dc6f92b8 | 10704 | erase it. */ |
06a2c219 | 10705 | if (w->phys_cursor_on_p |
dc6f92b8 | 10706 | && (!on |
06a2c219 GM |
10707 | || w->phys_cursor.x != x |
10708 | || w->phys_cursor.y != y | |
10709 | || new_cursor_type != w->phys_cursor_type)) | |
10710 | x_erase_phys_cursor (w); | |
10711 | ||
10712 | /* If the cursor is now invisible and we want it to be visible, | |
10713 | display it. */ | |
10714 | if (on && !w->phys_cursor_on_p) | |
10715 | { | |
10716 | w->phys_cursor_ascent = glyph_row->ascent; | |
10717 | w->phys_cursor_height = glyph_row->height; | |
10718 | ||
10719 | /* Set phys_cursor_.* before x_draw_.* is called because some | |
10720 | of them may need the information. */ | |
10721 | w->phys_cursor.x = x; | |
10722 | w->phys_cursor.y = glyph_row->y; | |
10723 | w->phys_cursor.hpos = hpos; | |
10724 | w->phys_cursor.vpos = vpos; | |
10725 | w->phys_cursor_type = new_cursor_type; | |
10726 | w->phys_cursor_on_p = 1; | |
10727 | ||
10728 | switch (new_cursor_type) | |
dc6f92b8 | 10729 | { |
06a2c219 GM |
10730 | case HOLLOW_BOX_CURSOR: |
10731 | x_draw_hollow_cursor (w, glyph_row); | |
10732 | break; | |
10733 | ||
10734 | case FILLED_BOX_CURSOR: | |
10735 | x_draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR); | |
10736 | break; | |
10737 | ||
10738 | case BAR_CURSOR: | |
f02d8aa0 | 10739 | x_draw_bar_cursor (w, glyph_row, new_cursor_width); |
06a2c219 GM |
10740 | break; |
10741 | ||
10742 | case NO_CURSOR: | |
10743 | break; | |
dc6f92b8 | 10744 | |
06a2c219 GM |
10745 | default: |
10746 | abort (); | |
10747 | } | |
59ddecde GM |
10748 | |
10749 | #ifdef HAVE_X_I18N | |
10750 | if (w == XWINDOW (f->selected_window)) | |
10751 | if (FRAME_XIC (f) && (FRAME_XIC_STYLE (f) & XIMPreeditPosition)) | |
10752 | xic_set_preeditarea (w, x, y); | |
10753 | #endif | |
dc6f92b8 JB |
10754 | } |
10755 | ||
06a2c219 | 10756 | #ifndef XFlush |
f676886a | 10757 | if (updating_frame != f) |
334208b7 | 10758 | XFlush (FRAME_X_DISPLAY (f)); |
06a2c219 | 10759 | #endif |
dc6f92b8 JB |
10760 | } |
10761 | ||
06a2c219 GM |
10762 | |
10763 | /* Display the cursor on window W, or clear it. X and Y are window | |
10764 | relative pixel coordinates. HPOS and VPOS are glyph matrix | |
10765 | positions. If W is not the selected window, display a hollow | |
10766 | cursor. ON non-zero means display the cursor at X, Y which | |
10767 | correspond to HPOS, VPOS, otherwise it is cleared. */ | |
5d46f928 | 10768 | |
dfcf069d | 10769 | void |
06a2c219 GM |
10770 | x_display_cursor (w, on, hpos, vpos, x, y) |
10771 | struct window *w; | |
10772 | int on, hpos, vpos, x, y; | |
dc6f92b8 | 10773 | { |
f94397b5 | 10774 | BLOCK_INPUT; |
06a2c219 | 10775 | x_display_and_set_cursor (w, on, hpos, vpos, x, y); |
5d46f928 RS |
10776 | UNBLOCK_INPUT; |
10777 | } | |
10778 | ||
06a2c219 GM |
10779 | |
10780 | /* Display the cursor on window W, or clear it, according to ON_P. | |
5d46f928 RS |
10781 | Don't change the cursor's position. */ |
10782 | ||
dfcf069d | 10783 | void |
06a2c219 | 10784 | x_update_cursor (f, on_p) |
5d46f928 | 10785 | struct frame *f; |
5d46f928 | 10786 | { |
06a2c219 GM |
10787 | x_update_cursor_in_window_tree (XWINDOW (f->root_window), on_p); |
10788 | } | |
10789 | ||
10790 | ||
10791 | /* Call x_update_window_cursor with parameter ON_P on all leaf windows | |
10792 | in the window tree rooted at W. */ | |
10793 | ||
10794 | static void | |
10795 | x_update_cursor_in_window_tree (w, on_p) | |
10796 | struct window *w; | |
10797 | int on_p; | |
10798 | { | |
10799 | while (w) | |
10800 | { | |
10801 | if (!NILP (w->hchild)) | |
10802 | x_update_cursor_in_window_tree (XWINDOW (w->hchild), on_p); | |
10803 | else if (!NILP (w->vchild)) | |
10804 | x_update_cursor_in_window_tree (XWINDOW (w->vchild), on_p); | |
10805 | else | |
10806 | x_update_window_cursor (w, on_p); | |
10807 | ||
10808 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
10809 | } | |
10810 | } | |
5d46f928 | 10811 | |
f94397b5 | 10812 | |
06a2c219 GM |
10813 | /* Switch the display of W's cursor on or off, according to the value |
10814 | of ON. */ | |
10815 | ||
10816 | static void | |
10817 | x_update_window_cursor (w, on) | |
10818 | struct window *w; | |
10819 | int on; | |
10820 | { | |
16b5d424 GM |
10821 | /* Don't update cursor in windows whose frame is in the process |
10822 | of being deleted. */ | |
10823 | if (w->current_matrix) | |
10824 | { | |
10825 | BLOCK_INPUT; | |
10826 | x_display_and_set_cursor (w, on, w->phys_cursor.hpos, w->phys_cursor.vpos, | |
10827 | w->phys_cursor.x, w->phys_cursor.y); | |
10828 | UNBLOCK_INPUT; | |
10829 | } | |
dc6f92b8 | 10830 | } |
06a2c219 GM |
10831 | |
10832 | ||
10833 | ||
dc6f92b8 JB |
10834 | \f |
10835 | /* Icons. */ | |
10836 | ||
f676886a | 10837 | /* Refresh bitmap kitchen sink icon for frame F |
06a2c219 | 10838 | when we get an expose event for it. */ |
dc6f92b8 | 10839 | |
dfcf069d | 10840 | void |
f676886a JB |
10841 | refreshicon (f) |
10842 | struct frame *f; | |
dc6f92b8 | 10843 | { |
06a2c219 | 10844 | /* Normally, the window manager handles this function. */ |
dc6f92b8 JB |
10845 | } |
10846 | ||
dbc4e1c1 | 10847 | /* Make the x-window of frame F use the gnu icon bitmap. */ |
dc6f92b8 JB |
10848 | |
10849 | int | |
990ba854 | 10850 | x_bitmap_icon (f, file) |
f676886a | 10851 | struct frame *f; |
990ba854 | 10852 | Lisp_Object file; |
dc6f92b8 | 10853 | { |
06a2c219 | 10854 | int bitmap_id; |
dc6f92b8 | 10855 | |
c118dd06 | 10856 | if (FRAME_X_WINDOW (f) == 0) |
dc6f92b8 JB |
10857 | return 1; |
10858 | ||
990ba854 | 10859 | /* Free up our existing icon bitmap if any. */ |
7556890b RS |
10860 | if (f->output_data.x->icon_bitmap > 0) |
10861 | x_destroy_bitmap (f, f->output_data.x->icon_bitmap); | |
10862 | f->output_data.x->icon_bitmap = 0; | |
990ba854 RS |
10863 | |
10864 | if (STRINGP (file)) | |
7f2ae036 RS |
10865 | bitmap_id = x_create_bitmap_from_file (f, file); |
10866 | else | |
10867 | { | |
990ba854 | 10868 | /* Create the GNU bitmap if necessary. */ |
5bf01b68 | 10869 | if (FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id < 0) |
334208b7 RS |
10870 | FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id |
10871 | = x_create_bitmap_from_data (f, gnu_bits, | |
10872 | gnu_width, gnu_height); | |
990ba854 RS |
10873 | |
10874 | /* The first time we create the GNU bitmap, | |
06a2c219 | 10875 | this increments the ref-count one extra time. |
990ba854 RS |
10876 | As a result, the GNU bitmap is never freed. |
10877 | That way, we don't have to worry about allocating it again. */ | |
334208b7 | 10878 | x_reference_bitmap (f, FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id); |
990ba854 | 10879 | |
334208b7 | 10880 | bitmap_id = FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id; |
7f2ae036 RS |
10881 | } |
10882 | ||
10883 | x_wm_set_icon_pixmap (f, bitmap_id); | |
7556890b | 10884 | f->output_data.x->icon_bitmap = bitmap_id; |
dc6f92b8 JB |
10885 | |
10886 | return 0; | |
10887 | } | |
10888 | ||
10889 | ||
1be2d067 KH |
10890 | /* Make the x-window of frame F use a rectangle with text. |
10891 | Use ICON_NAME as the text. */ | |
dc6f92b8 JB |
10892 | |
10893 | int | |
f676886a JB |
10894 | x_text_icon (f, icon_name) |
10895 | struct frame *f; | |
dc6f92b8 JB |
10896 | char *icon_name; |
10897 | { | |
c118dd06 | 10898 | if (FRAME_X_WINDOW (f) == 0) |
dc6f92b8 JB |
10899 | return 1; |
10900 | ||
1be2d067 KH |
10901 | #ifdef HAVE_X11R4 |
10902 | { | |
10903 | XTextProperty text; | |
10904 | text.value = (unsigned char *) icon_name; | |
10905 | text.encoding = XA_STRING; | |
10906 | text.format = 8; | |
10907 | text.nitems = strlen (icon_name); | |
10908 | #ifdef USE_X_TOOLKIT | |
7556890b | 10909 | XSetWMIconName (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget), |
1be2d067 KH |
10910 | &text); |
10911 | #else /* not USE_X_TOOLKIT */ | |
10912 | XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text); | |
10913 | #endif /* not USE_X_TOOLKIT */ | |
10914 | } | |
10915 | #else /* not HAVE_X11R4 */ | |
10916 | XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), icon_name); | |
10917 | #endif /* not HAVE_X11R4 */ | |
58769bee | 10918 | |
7556890b RS |
10919 | if (f->output_data.x->icon_bitmap > 0) |
10920 | x_destroy_bitmap (f, f->output_data.x->icon_bitmap); | |
10921 | f->output_data.x->icon_bitmap = 0; | |
b1c884c3 | 10922 | x_wm_set_icon_pixmap (f, 0); |
dc6f92b8 JB |
10923 | |
10924 | return 0; | |
10925 | } | |
10926 | \f | |
e99db5a1 RS |
10927 | #define X_ERROR_MESSAGE_SIZE 200 |
10928 | ||
10929 | /* If non-nil, this should be a string. | |
10930 | It means catch X errors and store the error message in this string. */ | |
10931 | ||
10932 | static Lisp_Object x_error_message_string; | |
10933 | ||
10934 | /* An X error handler which stores the error message in | |
10935 | x_error_message_string. This is called from x_error_handler if | |
10936 | x_catch_errors is in effect. */ | |
10937 | ||
06a2c219 | 10938 | static void |
e99db5a1 RS |
10939 | x_error_catcher (display, error) |
10940 | Display *display; | |
10941 | XErrorEvent *error; | |
10942 | { | |
10943 | XGetErrorText (display, error->error_code, | |
10944 | XSTRING (x_error_message_string)->data, | |
10945 | X_ERROR_MESSAGE_SIZE); | |
10946 | } | |
10947 | ||
10948 | /* Begin trapping X errors for display DPY. Actually we trap X errors | |
10949 | for all displays, but DPY should be the display you are actually | |
10950 | operating on. | |
10951 | ||
10952 | After calling this function, X protocol errors no longer cause | |
10953 | Emacs to exit; instead, they are recorded in the string | |
10954 | stored in x_error_message_string. | |
10955 | ||
10956 | Calling x_check_errors signals an Emacs error if an X error has | |
10957 | occurred since the last call to x_catch_errors or x_check_errors. | |
10958 | ||
10959 | Calling x_uncatch_errors resumes the normal error handling. */ | |
10960 | ||
10961 | void x_check_errors (); | |
10962 | static Lisp_Object x_catch_errors_unwind (); | |
10963 | ||
10964 | int | |
10965 | x_catch_errors (dpy) | |
10966 | Display *dpy; | |
10967 | { | |
10968 | int count = specpdl_ptr - specpdl; | |
10969 | ||
10970 | /* Make sure any errors from previous requests have been dealt with. */ | |
10971 | XSync (dpy, False); | |
10972 | ||
10973 | record_unwind_protect (x_catch_errors_unwind, x_error_message_string); | |
10974 | ||
10975 | x_error_message_string = make_uninit_string (X_ERROR_MESSAGE_SIZE); | |
10976 | XSTRING (x_error_message_string)->data[0] = 0; | |
10977 | ||
10978 | return count; | |
10979 | } | |
10980 | ||
10981 | /* Unbind the binding that we made to check for X errors. */ | |
10982 | ||
10983 | static Lisp_Object | |
10984 | x_catch_errors_unwind (old_val) | |
10985 | Lisp_Object old_val; | |
10986 | { | |
10987 | x_error_message_string = old_val; | |
10988 | return Qnil; | |
10989 | } | |
10990 | ||
10991 | /* If any X protocol errors have arrived since the last call to | |
10992 | x_catch_errors or x_check_errors, signal an Emacs error using | |
10993 | sprintf (a buffer, FORMAT, the x error message text) as the text. */ | |
10994 | ||
10995 | void | |
10996 | x_check_errors (dpy, format) | |
10997 | Display *dpy; | |
10998 | char *format; | |
10999 | { | |
11000 | /* Make sure to catch any errors incurred so far. */ | |
11001 | XSync (dpy, False); | |
11002 | ||
11003 | if (XSTRING (x_error_message_string)->data[0]) | |
11004 | error (format, XSTRING (x_error_message_string)->data); | |
11005 | } | |
11006 | ||
9829ddba RS |
11007 | /* Nonzero if we had any X protocol errors |
11008 | since we did x_catch_errors on DPY. */ | |
e99db5a1 RS |
11009 | |
11010 | int | |
11011 | x_had_errors_p (dpy) | |
11012 | Display *dpy; | |
11013 | { | |
11014 | /* Make sure to catch any errors incurred so far. */ | |
11015 | XSync (dpy, False); | |
11016 | ||
11017 | return XSTRING (x_error_message_string)->data[0] != 0; | |
11018 | } | |
11019 | ||
9829ddba RS |
11020 | /* Forget about any errors we have had, since we did x_catch_errors on DPY. */ |
11021 | ||
06a2c219 | 11022 | void |
9829ddba RS |
11023 | x_clear_errors (dpy) |
11024 | Display *dpy; | |
11025 | { | |
11026 | XSTRING (x_error_message_string)->data[0] = 0; | |
11027 | } | |
11028 | ||
e99db5a1 RS |
11029 | /* Stop catching X protocol errors and let them make Emacs die. |
11030 | DPY should be the display that was passed to x_catch_errors. | |
11031 | COUNT should be the value that was returned by | |
11032 | the corresponding call to x_catch_errors. */ | |
11033 | ||
11034 | void | |
11035 | x_uncatch_errors (dpy, count) | |
11036 | Display *dpy; | |
11037 | int count; | |
11038 | { | |
11039 | unbind_to (count, Qnil); | |
11040 | } | |
11041 | ||
11042 | #if 0 | |
11043 | static unsigned int x_wire_count; | |
11044 | x_trace_wire () | |
11045 | { | |
11046 | fprintf (stderr, "Lib call: %d\n", ++x_wire_count); | |
11047 | } | |
11048 | #endif /* ! 0 */ | |
11049 | ||
11050 | \f | |
11051 | /* Handle SIGPIPE, which can happen when the connection to a server | |
11052 | simply goes away. SIGPIPE is handled by x_connection_signal. | |
11053 | Don't need to do anything, because the write which caused the | |
11054 | SIGPIPE will fail, causing Xlib to invoke the X IO error handler, | |
06a2c219 | 11055 | which will do the appropriate cleanup for us. */ |
e99db5a1 RS |
11056 | |
11057 | static SIGTYPE | |
11058 | x_connection_signal (signalnum) /* If we don't have an argument, */ | |
06a2c219 | 11059 | int signalnum; /* some compilers complain in signal calls. */ |
e99db5a1 RS |
11060 | { |
11061 | #ifdef USG | |
11062 | /* USG systems forget handlers when they are used; | |
11063 | must reestablish each time */ | |
11064 | signal (signalnum, x_connection_signal); | |
11065 | #endif /* USG */ | |
11066 | } | |
11067 | \f | |
4746118a JB |
11068 | /* Handling X errors. */ |
11069 | ||
7a13e894 | 11070 | /* Handle the loss of connection to display DISPLAY. */ |
16bd92ea | 11071 | |
4746118a | 11072 | static SIGTYPE |
7a13e894 RS |
11073 | x_connection_closed (display, error_message) |
11074 | Display *display; | |
11075 | char *error_message; | |
4746118a | 11076 | { |
7a13e894 RS |
11077 | struct x_display_info *dpyinfo = x_display_info_for_display (display); |
11078 | Lisp_Object frame, tail; | |
11079 | ||
6186a4a0 RS |
11080 | /* Indicate that this display is dead. */ |
11081 | ||
2e465cdd | 11082 | #if 0 /* Closing the display caused a bus error on OpenWindows. */ |
f613a4c8 | 11083 | #ifdef USE_X_TOOLKIT |
adabc3a9 | 11084 | XtCloseDisplay (display); |
2e465cdd | 11085 | #endif |
f613a4c8 | 11086 | #endif |
adabc3a9 | 11087 | |
9e80b57d KR |
11088 | if (dpyinfo) |
11089 | dpyinfo->display = 0; | |
6186a4a0 | 11090 | |
06a2c219 | 11091 | /* First delete frames whose mini-buffers are on frames |
7a13e894 RS |
11092 | that are on the dead display. */ |
11093 | FOR_EACH_FRAME (tail, frame) | |
11094 | { | |
11095 | Lisp_Object minibuf_frame; | |
11096 | minibuf_frame | |
11097 | = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame)))); | |
f48f33ca RS |
11098 | if (FRAME_X_P (XFRAME (frame)) |
11099 | && FRAME_X_P (XFRAME (minibuf_frame)) | |
11100 | && ! EQ (frame, minibuf_frame) | |
11101 | && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame)) == dpyinfo) | |
7a13e894 RS |
11102 | Fdelete_frame (frame, Qt); |
11103 | } | |
11104 | ||
11105 | /* Now delete all remaining frames on the dead display. | |
06a2c219 | 11106 | We are now sure none of these is used as the mini-buffer |
7a13e894 RS |
11107 | for another frame that we need to delete. */ |
11108 | FOR_EACH_FRAME (tail, frame) | |
f48f33ca RS |
11109 | if (FRAME_X_P (XFRAME (frame)) |
11110 | && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) | |
07a7096a KH |
11111 | { |
11112 | /* Set this to t so that Fdelete_frame won't get confused | |
11113 | trying to find a replacement. */ | |
11114 | FRAME_KBOARD (XFRAME (frame))->Vdefault_minibuffer_frame = Qt; | |
11115 | Fdelete_frame (frame, Qt); | |
11116 | } | |
7a13e894 | 11117 | |
482a1bd2 KH |
11118 | if (dpyinfo) |
11119 | x_delete_display (dpyinfo); | |
7a13e894 RS |
11120 | |
11121 | if (x_display_list == 0) | |
11122 | { | |
f8d07b62 | 11123 | fprintf (stderr, "%s\n", error_message); |
7a13e894 RS |
11124 | shut_down_emacs (0, 0, Qnil); |
11125 | exit (70); | |
11126 | } | |
12ba150f | 11127 | |
7a13e894 RS |
11128 | /* Ordinary stack unwind doesn't deal with these. */ |
11129 | #ifdef SIGIO | |
11130 | sigunblock (sigmask (SIGIO)); | |
11131 | #endif | |
11132 | sigunblock (sigmask (SIGALRM)); | |
11133 | TOTALLY_UNBLOCK_INPUT; | |
11134 | ||
aa4d9a9e | 11135 | clear_waiting_for_input (); |
7a13e894 | 11136 | error ("%s", error_message); |
4746118a JB |
11137 | } |
11138 | ||
7a13e894 RS |
11139 | /* This is the usual handler for X protocol errors. |
11140 | It kills all frames on the display that we got the error for. | |
11141 | If that was the only one, it prints an error message and kills Emacs. */ | |
11142 | ||
06a2c219 | 11143 | static void |
c118dd06 JB |
11144 | x_error_quitter (display, error) |
11145 | Display *display; | |
11146 | XErrorEvent *error; | |
11147 | { | |
7a13e894 | 11148 | char buf[256], buf1[356]; |
dc6f92b8 | 11149 | |
58769bee | 11150 | /* Note that there is no real way portable across R3/R4 to get the |
c118dd06 | 11151 | original error handler. */ |
dc6f92b8 | 11152 | |
c118dd06 | 11153 | XGetErrorText (display, error->error_code, buf, sizeof (buf)); |
0a0fdc70 | 11154 | sprintf (buf1, "X protocol error: %s on protocol request %d", |
c118dd06 | 11155 | buf, error->request_code); |
7a13e894 | 11156 | x_connection_closed (display, buf1); |
dc6f92b8 JB |
11157 | } |
11158 | ||
e99db5a1 RS |
11159 | /* This is the first-level handler for X protocol errors. |
11160 | It calls x_error_quitter or x_error_catcher. */ | |
7a13e894 | 11161 | |
8922af5f | 11162 | static int |
e99db5a1 | 11163 | x_error_handler (display, error) |
8922af5f | 11164 | Display *display; |
e99db5a1 | 11165 | XErrorEvent *error; |
8922af5f | 11166 | { |
e99db5a1 RS |
11167 | if (! NILP (x_error_message_string)) |
11168 | x_error_catcher (display, error); | |
11169 | else | |
11170 | x_error_quitter (display, error); | |
06a2c219 | 11171 | return 0; |
f9e24cb9 | 11172 | } |
c118dd06 | 11173 | |
e99db5a1 RS |
11174 | /* This is the handler for X IO errors, always. |
11175 | It kills all frames on the display that we lost touch with. | |
11176 | If that was the only one, it prints an error message and kills Emacs. */ | |
7a13e894 | 11177 | |
c118dd06 | 11178 | static int |
e99db5a1 | 11179 | x_io_error_quitter (display) |
c118dd06 | 11180 | Display *display; |
c118dd06 | 11181 | { |
e99db5a1 | 11182 | char buf[256]; |
dc6f92b8 | 11183 | |
e99db5a1 RS |
11184 | sprintf (buf, "Connection lost to X server `%s'", DisplayString (display)); |
11185 | x_connection_closed (display, buf); | |
06a2c219 | 11186 | return 0; |
dc6f92b8 | 11187 | } |
dc6f92b8 | 11188 | \f |
f451eb13 JB |
11189 | /* Changing the font of the frame. */ |
11190 | ||
76bcdf39 RS |
11191 | /* Give frame F the font named FONTNAME as its default font, and |
11192 | return the full name of that font. FONTNAME may be a wildcard | |
11193 | pattern; in that case, we choose some font that fits the pattern. | |
11194 | The return value shows which font we chose. */ | |
11195 | ||
b5cf7a0e | 11196 | Lisp_Object |
f676886a JB |
11197 | x_new_font (f, fontname) |
11198 | struct frame *f; | |
dc6f92b8 JB |
11199 | register char *fontname; |
11200 | { | |
dc43ef94 | 11201 | struct font_info *fontp |
ee569018 | 11202 | = FS_LOAD_FONT (f, 0, fontname, -1); |
dc6f92b8 | 11203 | |
dc43ef94 KH |
11204 | if (!fontp) |
11205 | return Qnil; | |
2224a5fc | 11206 | |
dc43ef94 | 11207 | f->output_data.x->font = (XFontStruct *) (fontp->font); |
b4192550 | 11208 | f->output_data.x->baseline_offset = fontp->baseline_offset; |
dc43ef94 KH |
11209 | f->output_data.x->fontset = -1; |
11210 | ||
b2cad826 KH |
11211 | /* Compute the scroll bar width in character columns. */ |
11212 | if (f->scroll_bar_pixel_width > 0) | |
11213 | { | |
7556890b | 11214 | int wid = FONT_WIDTH (f->output_data.x->font); |
b2cad826 KH |
11215 | f->scroll_bar_cols = (f->scroll_bar_pixel_width + wid-1) / wid; |
11216 | } | |
11217 | else | |
4e61bddf RS |
11218 | { |
11219 | int wid = FONT_WIDTH (f->output_data.x->font); | |
11220 | f->scroll_bar_cols = (14 + wid - 1) / wid; | |
11221 | } | |
b2cad826 | 11222 | |
f676886a | 11223 | /* Now make the frame display the given font. */ |
c118dd06 | 11224 | if (FRAME_X_WINDOW (f) != 0) |
dc6f92b8 | 11225 | { |
7556890b RS |
11226 | XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->normal_gc, |
11227 | f->output_data.x->font->fid); | |
11228 | XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->reverse_gc, | |
11229 | f->output_data.x->font->fid); | |
11230 | XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->cursor_gc, | |
11231 | f->output_data.x->font->fid); | |
f676886a | 11232 | |
a27f9f86 | 11233 | frame_update_line_height (f); |
0134a210 | 11234 | x_set_window_size (f, 0, f->width, f->height); |
dc6f92b8 | 11235 | } |
a27f9f86 RS |
11236 | else |
11237 | /* If we are setting a new frame's font for the first time, | |
11238 | there are no faces yet, so this font's height is the line height. */ | |
7556890b | 11239 | f->output_data.x->line_height = FONT_HEIGHT (f->output_data.x->font); |
dc6f92b8 | 11240 | |
dc43ef94 KH |
11241 | return build_string (fontp->full_name); |
11242 | } | |
11243 | ||
11244 | /* Give frame F the fontset named FONTSETNAME as its default font, and | |
11245 | return the full name of that fontset. FONTSETNAME may be a wildcard | |
b5210ea7 KH |
11246 | pattern; in that case, we choose some fontset that fits the pattern. |
11247 | The return value shows which fontset we chose. */ | |
b5cf7a0e | 11248 | |
dc43ef94 KH |
11249 | Lisp_Object |
11250 | x_new_fontset (f, fontsetname) | |
11251 | struct frame *f; | |
11252 | char *fontsetname; | |
11253 | { | |
ee569018 | 11254 | int fontset = fs_query_fontset (build_string (fontsetname), 0); |
dc43ef94 | 11255 | Lisp_Object result; |
b5cf7a0e | 11256 | |
dc43ef94 KH |
11257 | if (fontset < 0) |
11258 | return Qnil; | |
b5cf7a0e | 11259 | |
2da424f1 KH |
11260 | if (f->output_data.x->fontset == fontset) |
11261 | /* This fontset is already set in frame F. There's nothing more | |
11262 | to do. */ | |
ee569018 | 11263 | return fontset_name (fontset); |
dc43ef94 | 11264 | |
ee569018 | 11265 | result = x_new_font (f, (XSTRING (fontset_ascii (fontset))->data)); |
dc43ef94 KH |
11266 | |
11267 | if (!STRINGP (result)) | |
11268 | /* Can't load ASCII font. */ | |
11269 | return Qnil; | |
11270 | ||
11271 | /* Since x_new_font doesn't update any fontset information, do it now. */ | |
11272 | f->output_data.x->fontset = fontset; | |
dc43ef94 | 11273 | |
f5d11644 GM |
11274 | #ifdef HAVE_X_I18N |
11275 | if (FRAME_XIC (f) | |
11276 | && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea))) | |
ee569018 | 11277 | xic_set_xfontset (f, XSTRING (fontset_ascii (fontset))->data); |
f5d11644 GM |
11278 | #endif |
11279 | ||
dc43ef94 | 11280 | return build_string (fontsetname); |
dc6f92b8 | 11281 | } |
f5d11644 GM |
11282 | |
11283 | \f | |
11284 | /*********************************************************************** | |
11285 | X Input Methods | |
11286 | ***********************************************************************/ | |
11287 | ||
11288 | #ifdef HAVE_X_I18N | |
11289 | ||
11290 | #ifdef HAVE_X11R6 | |
11291 | ||
11292 | /* XIM destroy callback function, which is called whenever the | |
11293 | connection to input method XIM dies. CLIENT_DATA contains a | |
11294 | pointer to the x_display_info structure corresponding to XIM. */ | |
11295 | ||
11296 | static void | |
11297 | xim_destroy_callback (xim, client_data, call_data) | |
11298 | XIM xim; | |
11299 | XPointer client_data; | |
11300 | XPointer call_data; | |
11301 | { | |
11302 | struct x_display_info *dpyinfo = (struct x_display_info *) client_data; | |
11303 | Lisp_Object frame, tail; | |
11304 | ||
11305 | BLOCK_INPUT; | |
11306 | ||
11307 | /* No need to call XDestroyIC.. */ | |
11308 | FOR_EACH_FRAME (tail, frame) | |
11309 | { | |
11310 | struct frame *f = XFRAME (frame); | |
11311 | if (FRAME_X_DISPLAY_INFO (f) == dpyinfo) | |
11312 | { | |
11313 | FRAME_XIC (f) = NULL; | |
11314 | if (FRAME_XIC_FONTSET (f)) | |
11315 | { | |
11316 | XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); | |
11317 | FRAME_XIC_FONTSET (f) = NULL; | |
11318 | } | |
11319 | } | |
11320 | } | |
11321 | ||
11322 | /* No need to call XCloseIM. */ | |
11323 | dpyinfo->xim = NULL; | |
11324 | XFree (dpyinfo->xim_styles); | |
11325 | UNBLOCK_INPUT; | |
11326 | } | |
11327 | ||
11328 | #endif /* HAVE_X11R6 */ | |
11329 | ||
11330 | /* Open the connection to the XIM server on display DPYINFO. | |
11331 | RESOURCE_NAME is the resource name Emacs uses. */ | |
11332 | ||
11333 | static void | |
11334 | xim_open_dpy (dpyinfo, resource_name) | |
11335 | struct x_display_info *dpyinfo; | |
11336 | char *resource_name; | |
11337 | { | |
287f7dd6 | 11338 | #ifdef USE_XIM |
f5d11644 GM |
11339 | XIM xim; |
11340 | ||
11341 | xim = XOpenIM (dpyinfo->display, dpyinfo->xrdb, resource_name, EMACS_CLASS); | |
11342 | dpyinfo->xim = xim; | |
11343 | ||
11344 | if (xim) | |
11345 | { | |
f5d11644 GM |
11346 | #ifdef HAVE_X11R6 |
11347 | XIMCallback destroy; | |
11348 | #endif | |
11349 | ||
11350 | /* Get supported styles and XIM values. */ | |
11351 | XGetIMValues (xim, XNQueryInputStyle, &dpyinfo->xim_styles, NULL); | |
11352 | ||
11353 | #ifdef HAVE_X11R6 | |
11354 | destroy.callback = xim_destroy_callback; | |
11355 | destroy.client_data = (XPointer)dpyinfo; | |
68642df6 | 11356 | /* This isn't prptotyped in OSF 5.0. */ |
f5d11644 GM |
11357 | XSetIMValues (xim, XNDestroyCallback, &destroy, NULL); |
11358 | #endif | |
11359 | } | |
287f7dd6 GM |
11360 | |
11361 | #else /* not USE_XIM */ | |
11362 | dpyinfo->xim = NULL; | |
11363 | #endif /* not USE_XIM */ | |
f5d11644 GM |
11364 | } |
11365 | ||
11366 | ||
b9de836c | 11367 | #ifdef HAVE_X11R6_XIM |
f5d11644 GM |
11368 | |
11369 | struct xim_inst_t | |
11370 | { | |
11371 | struct x_display_info *dpyinfo; | |
11372 | char *resource_name; | |
11373 | }; | |
11374 | ||
11375 | /* XIM instantiate callback function, which is called whenever an XIM | |
11376 | server is available. DISPLAY is teh display of the XIM. | |
11377 | CLIENT_DATA contains a pointer to an xim_inst_t structure created | |
11378 | when the callback was registered. */ | |
11379 | ||
11380 | static void | |
11381 | xim_instantiate_callback (display, client_data, call_data) | |
11382 | Display *display; | |
11383 | XPointer client_data; | |
11384 | XPointer call_data; | |
11385 | { | |
11386 | struct xim_inst_t *xim_inst = (struct xim_inst_t *) client_data; | |
11387 | struct x_display_info *dpyinfo = xim_inst->dpyinfo; | |
11388 | ||
11389 | /* We don't support multiple XIM connections. */ | |
11390 | if (dpyinfo->xim) | |
11391 | return; | |
11392 | ||
11393 | xim_open_dpy (dpyinfo, xim_inst->resource_name); | |
11394 | ||
11395 | /* Create XIC for the existing frames on the same display, as long | |
11396 | as they have no XIC. */ | |
11397 | if (dpyinfo->xim && dpyinfo->reference_count > 0) | |
11398 | { | |
11399 | Lisp_Object tail, frame; | |
11400 | ||
11401 | BLOCK_INPUT; | |
11402 | FOR_EACH_FRAME (tail, frame) | |
11403 | { | |
11404 | struct frame *f = XFRAME (frame); | |
11405 | ||
11406 | if (FRAME_X_DISPLAY_INFO (f) == xim_inst->dpyinfo) | |
11407 | if (FRAME_XIC (f) == NULL) | |
11408 | { | |
11409 | create_frame_xic (f); | |
11410 | if (FRAME_XIC_STYLE (f) & XIMStatusArea) | |
11411 | xic_set_statusarea (f); | |
11412 | if (FRAME_XIC_STYLE (f) & XIMPreeditPosition) | |
11413 | { | |
11414 | struct window *w = XWINDOW (f->selected_window); | |
11415 | xic_set_preeditarea (w, w->cursor.x, w->cursor.y); | |
11416 | } | |
11417 | } | |
11418 | } | |
11419 | ||
11420 | UNBLOCK_INPUT; | |
11421 | } | |
11422 | } | |
11423 | ||
b9de836c | 11424 | #endif /* HAVE_X11R6_XIM */ |
f5d11644 GM |
11425 | |
11426 | ||
11427 | /* Open a connection to the XIM server on display DPYINFO. | |
11428 | RESOURCE_NAME is the resource name for Emacs. On X11R5, open the | |
11429 | connection only at the first time. On X11R6, open the connection | |
11430 | in the XIM instantiate callback function. */ | |
11431 | ||
11432 | static void | |
11433 | xim_initialize (dpyinfo, resource_name) | |
11434 | struct x_display_info *dpyinfo; | |
11435 | char *resource_name; | |
11436 | { | |
287f7dd6 | 11437 | #ifdef USE_XIM |
b9de836c | 11438 | #ifdef HAVE_X11R6_XIM |
f5d11644 GM |
11439 | struct xim_inst_t *xim_inst; |
11440 | int len; | |
11441 | ||
11442 | dpyinfo->xim = NULL; | |
11443 | xim_inst = (struct xim_inst_t *) xmalloc (sizeof (struct xim_inst_t)); | |
11444 | xim_inst->dpyinfo = dpyinfo; | |
11445 | len = strlen (resource_name); | |
11446 | xim_inst->resource_name = (char *) xmalloc (len + 1); | |
11447 | bcopy (resource_name, xim_inst->resource_name, len + 1); | |
11448 | XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb, | |
11449 | resource_name, EMACS_CLASS, | |
11450 | xim_instantiate_callback, | |
2ebb2f8b DL |
11451 | /* Fixme: This is XPointer in |
11452 | XFree86 but (XPointer *) on | |
11453 | Tru64, at least. */ | |
11454 | (XPointer) xim_inst); | |
b9de836c | 11455 | #else /* not HAVE_X11R6_XIM */ |
f5d11644 GM |
11456 | dpyinfo->xim = NULL; |
11457 | xim_open_dpy (dpyinfo, resource_name); | |
b9de836c | 11458 | #endif /* not HAVE_X11R6_XIM */ |
287f7dd6 GM |
11459 | |
11460 | #else /* not USE_XIM */ | |
11461 | dpyinfo->xim = NULL; | |
11462 | #endif /* not USE_XIM */ | |
f5d11644 GM |
11463 | } |
11464 | ||
11465 | ||
11466 | /* Close the connection to the XIM server on display DPYINFO. */ | |
11467 | ||
11468 | static void | |
11469 | xim_close_dpy (dpyinfo) | |
11470 | struct x_display_info *dpyinfo; | |
11471 | { | |
287f7dd6 | 11472 | #ifdef USE_XIM |
b9de836c | 11473 | #ifdef HAVE_X11R6_XIM |
f5d11644 GM |
11474 | XUnregisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb, |
11475 | NULL, EMACS_CLASS, | |
11476 | xim_instantiate_callback, NULL); | |
b9de836c | 11477 | #endif /* not HAVE_X11R6_XIM */ |
f5d11644 GM |
11478 | XCloseIM (dpyinfo->xim); |
11479 | dpyinfo->xim = NULL; | |
11480 | XFree (dpyinfo->xim_styles); | |
287f7dd6 | 11481 | #endif /* USE_XIM */ |
f5d11644 GM |
11482 | } |
11483 | ||
b9de836c | 11484 | #endif /* not HAVE_X11R6_XIM */ |
f5d11644 GM |
11485 | |
11486 | ||
dc6f92b8 | 11487 | \f |
2e365682 RS |
11488 | /* Calculate the absolute position in frame F |
11489 | from its current recorded position values and gravity. */ | |
11490 | ||
dfcf069d | 11491 | void |
43bca5d5 | 11492 | x_calc_absolute_position (f) |
f676886a | 11493 | struct frame *f; |
dc6f92b8 | 11494 | { |
06a2c219 | 11495 | Window child; |
6dba1858 | 11496 | int win_x = 0, win_y = 0; |
7556890b | 11497 | int flags = f->output_data.x->size_hint_flags; |
c81412a0 KH |
11498 | int this_window; |
11499 | ||
9829ddba RS |
11500 | /* We have nothing to do if the current position |
11501 | is already for the top-left corner. */ | |
11502 | if (! ((flags & XNegative) || (flags & YNegative))) | |
11503 | return; | |
11504 | ||
c81412a0 | 11505 | #ifdef USE_X_TOOLKIT |
7556890b | 11506 | this_window = XtWindow (f->output_data.x->widget); |
c81412a0 KH |
11507 | #else |
11508 | this_window = FRAME_X_WINDOW (f); | |
11509 | #endif | |
6dba1858 RS |
11510 | |
11511 | /* Find the position of the outside upper-left corner of | |
9829ddba RS |
11512 | the inner window, with respect to the outer window. |
11513 | But do this only if we will need the results. */ | |
7556890b | 11514 | if (f->output_data.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window) |
6dba1858 | 11515 | { |
9829ddba RS |
11516 | int count; |
11517 | ||
6dba1858 | 11518 | BLOCK_INPUT; |
9829ddba RS |
11519 | count = x_catch_errors (FRAME_X_DISPLAY (f)); |
11520 | while (1) | |
11521 | { | |
11522 | x_clear_errors (FRAME_X_DISPLAY (f)); | |
11523 | XTranslateCoordinates (FRAME_X_DISPLAY (f), | |
11524 | ||
11525 | /* From-window, to-window. */ | |
11526 | this_window, | |
11527 | f->output_data.x->parent_desc, | |
11528 | ||
11529 | /* From-position, to-position. */ | |
11530 | 0, 0, &win_x, &win_y, | |
11531 | ||
11532 | /* Child of win. */ | |
11533 | &child); | |
11534 | if (x_had_errors_p (FRAME_X_DISPLAY (f))) | |
11535 | { | |
11536 | Window newroot, newparent = 0xdeadbeef; | |
11537 | Window *newchildren; | |
2ebb2f8b | 11538 | unsigned int nchildren; |
9829ddba RS |
11539 | |
11540 | if (! XQueryTree (FRAME_X_DISPLAY (f), this_window, &newroot, | |
11541 | &newparent, &newchildren, &nchildren)) | |
11542 | break; | |
58769bee | 11543 | |
7c3c78a3 | 11544 | XFree ((char *) newchildren); |
6dba1858 | 11545 | |
9829ddba RS |
11546 | f->output_data.x->parent_desc = newparent; |
11547 | } | |
11548 | else | |
11549 | break; | |
11550 | } | |
6dba1858 | 11551 | |
9829ddba | 11552 | x_uncatch_errors (FRAME_X_DISPLAY (f), count); |
6dba1858 RS |
11553 | UNBLOCK_INPUT; |
11554 | } | |
11555 | ||
11556 | /* Treat negative positions as relative to the leftmost bottommost | |
11557 | position that fits on the screen. */ | |
20f55f9a | 11558 | if (flags & XNegative) |
7556890b | 11559 | f->output_data.x->left_pos = (FRAME_X_DISPLAY_INFO (f)->width |
2e365682 RS |
11560 | - 2 * f->output_data.x->border_width - win_x |
11561 | - PIXEL_WIDTH (f) | |
11562 | + f->output_data.x->left_pos); | |
dc6f92b8 | 11563 | |
20f55f9a | 11564 | if (flags & YNegative) |
06a2c219 GM |
11565 | { |
11566 | int menubar_height = 0; | |
11567 | ||
11568 | #ifdef USE_X_TOOLKIT | |
11569 | if (f->output_data.x->menubar_widget) | |
11570 | menubar_height | |
11571 | = (f->output_data.x->menubar_widget->core.height | |
11572 | + f->output_data.x->menubar_widget->core.border_width); | |
11573 | #endif | |
11574 | ||
11575 | f->output_data.x->top_pos = (FRAME_X_DISPLAY_INFO (f)->height | |
11576 | - 2 * f->output_data.x->border_width | |
11577 | - win_y | |
11578 | - PIXEL_HEIGHT (f) | |
11579 | - menubar_height | |
11580 | + f->output_data.x->top_pos); | |
11581 | } | |
2e365682 | 11582 | |
3a35ab44 RS |
11583 | /* The left_pos and top_pos |
11584 | are now relative to the top and left screen edges, | |
11585 | so the flags should correspond. */ | |
7556890b | 11586 | f->output_data.x->size_hint_flags &= ~ (XNegative | YNegative); |
dc6f92b8 JB |
11587 | } |
11588 | ||
3a35ab44 RS |
11589 | /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position, |
11590 | to really change the position, and 0 when calling from | |
11591 | x_make_frame_visible (in that case, XOFF and YOFF are the current | |
aa3ff7c9 KH |
11592 | position values). It is -1 when calling from x_set_frame_parameters, |
11593 | which means, do adjust for borders but don't change the gravity. */ | |
3a35ab44 | 11594 | |
dfcf069d | 11595 | void |
dc05a16b | 11596 | x_set_offset (f, xoff, yoff, change_gravity) |
f676886a | 11597 | struct frame *f; |
dc6f92b8 | 11598 | register int xoff, yoff; |
dc05a16b | 11599 | int change_gravity; |
dc6f92b8 | 11600 | { |
4a4cbdd5 KH |
11601 | int modified_top, modified_left; |
11602 | ||
aa3ff7c9 | 11603 | if (change_gravity > 0) |
3a35ab44 | 11604 | { |
7556890b RS |
11605 | f->output_data.x->top_pos = yoff; |
11606 | f->output_data.x->left_pos = xoff; | |
11607 | f->output_data.x->size_hint_flags &= ~ (XNegative | YNegative); | |
3a35ab44 | 11608 | if (xoff < 0) |
7556890b | 11609 | f->output_data.x->size_hint_flags |= XNegative; |
3a35ab44 | 11610 | if (yoff < 0) |
7556890b RS |
11611 | f->output_data.x->size_hint_flags |= YNegative; |
11612 | f->output_data.x->win_gravity = NorthWestGravity; | |
3a35ab44 | 11613 | } |
43bca5d5 | 11614 | x_calc_absolute_position (f); |
dc6f92b8 JB |
11615 | |
11616 | BLOCK_INPUT; | |
c32cdd9a | 11617 | x_wm_set_size_hint (f, (long) 0, 0); |
3a35ab44 | 11618 | |
7556890b RS |
11619 | modified_left = f->output_data.x->left_pos; |
11620 | modified_top = f->output_data.x->top_pos; | |
e73ec6fa RS |
11621 | #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal, |
11622 | this seems to be unnecessary and incorrect. rms, 4/17/97. */ | |
11623 | /* It is a mystery why we need to add the border_width here | |
11624 | when the frame is already visible, but experiment says we do. */ | |
aa3ff7c9 | 11625 | if (change_gravity != 0) |
4a4cbdd5 | 11626 | { |
7556890b RS |
11627 | modified_left += f->output_data.x->border_width; |
11628 | modified_top += f->output_data.x->border_width; | |
4a4cbdd5 | 11629 | } |
e73ec6fa | 11630 | #endif |
4a4cbdd5 | 11631 | |
3afe33e7 | 11632 | #ifdef USE_X_TOOLKIT |
7556890b | 11633 | XMoveWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget), |
4a4cbdd5 | 11634 | modified_left, modified_top); |
3afe33e7 | 11635 | #else /* not USE_X_TOOLKIT */ |
334208b7 | 11636 | XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
4a4cbdd5 | 11637 | modified_left, modified_top); |
3afe33e7 | 11638 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
11639 | UNBLOCK_INPUT; |
11640 | } | |
11641 | ||
bc20ebbf FP |
11642 | /* Call this to change the size of frame F's x-window. |
11643 | If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity | |
11644 | for this size change and subsequent size changes. | |
11645 | Otherwise we leave the window gravity unchanged. */ | |
dc6f92b8 | 11646 | |
dfcf069d | 11647 | void |
bc20ebbf | 11648 | x_set_window_size (f, change_gravity, cols, rows) |
f676886a | 11649 | struct frame *f; |
bc20ebbf | 11650 | int change_gravity; |
b1c884c3 | 11651 | int cols, rows; |
dc6f92b8 | 11652 | { |
06a2c219 | 11653 | #ifndef USE_X_TOOLKIT |
dc6f92b8 | 11654 | int pixelwidth, pixelheight; |
06a2c219 | 11655 | #endif |
dc6f92b8 | 11656 | |
80fd1fe2 | 11657 | BLOCK_INPUT; |
aee9a898 RS |
11658 | |
11659 | #ifdef USE_X_TOOLKIT | |
3a20653d RS |
11660 | { |
11661 | /* The x and y position of the widget is clobbered by the | |
11662 | call to XtSetValues within EmacsFrameSetCharSize. | |
11663 | This is a real kludge, but I don't understand Xt so I can't | |
11664 | figure out a correct fix. Can anyone else tell me? -- rms. */ | |
7556890b RS |
11665 | int xpos = f->output_data.x->widget->core.x; |
11666 | int ypos = f->output_data.x->widget->core.y; | |
11667 | EmacsFrameSetCharSize (f->output_data.x->edit_widget, cols, rows); | |
11668 | f->output_data.x->widget->core.x = xpos; | |
11669 | f->output_data.x->widget->core.y = ypos; | |
3a20653d | 11670 | } |
80fd1fe2 FP |
11671 | |
11672 | #else /* not USE_X_TOOLKIT */ | |
11673 | ||
b1c884c3 | 11674 | check_frame_size (f, &rows, &cols); |
7556890b | 11675 | f->output_data.x->vertical_scroll_bar_extra |
b2cad826 KH |
11676 | = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f) |
11677 | ? 0 | |
11678 | : FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0 | |
480407eb | 11679 | ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f) |
7556890b | 11680 | : (FRAME_SCROLL_BAR_COLS (f) * FONT_WIDTH (f->output_data.x->font))); |
06a2c219 | 11681 | f->output_data.x->flags_areas_extra |
110859fc | 11682 | = FRAME_FLAGS_AREA_WIDTH (f); |
f451eb13 JB |
11683 | pixelwidth = CHAR_TO_PIXEL_WIDTH (f, cols); |
11684 | pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows); | |
dc6f92b8 | 11685 | |
7556890b | 11686 | f->output_data.x->win_gravity = NorthWestGravity; |
c32cdd9a | 11687 | x_wm_set_size_hint (f, (long) 0, 0); |
6ccf47d1 | 11688 | |
334208b7 RS |
11689 | XSync (FRAME_X_DISPLAY (f), False); |
11690 | XResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
11691 | pixelwidth, pixelheight); | |
b1c884c3 JB |
11692 | |
11693 | /* Now, strictly speaking, we can't be sure that this is accurate, | |
11694 | but the window manager will get around to dealing with the size | |
11695 | change request eventually, and we'll hear how it went when the | |
dbc4e1c1 JB |
11696 | ConfigureNotify event gets here. |
11697 | ||
11698 | We could just not bother storing any of this information here, | |
11699 | and let the ConfigureNotify event set everything up, but that | |
fddd5ceb | 11700 | might be kind of confusing to the Lisp code, since size changes |
dbc4e1c1 | 11701 | wouldn't be reported in the frame parameters until some random |
fddd5ceb RS |
11702 | point in the future when the ConfigureNotify event arrives. |
11703 | ||
11704 | We pass 1 for DELAY since we can't run Lisp code inside of | |
11705 | a BLOCK_INPUT. */ | |
7d1e984f | 11706 | change_frame_size (f, rows, cols, 0, 1, 0); |
b1c884c3 JB |
11707 | PIXEL_WIDTH (f) = pixelwidth; |
11708 | PIXEL_HEIGHT (f) = pixelheight; | |
11709 | ||
aee9a898 RS |
11710 | /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to |
11711 | receive in the ConfigureNotify event; if we get what we asked | |
11712 | for, then the event won't cause the screen to become garbaged, so | |
11713 | we have to make sure to do it here. */ | |
11714 | SET_FRAME_GARBAGED (f); | |
11715 | ||
11716 | XFlush (FRAME_X_DISPLAY (f)); | |
11717 | ||
11718 | #endif /* not USE_X_TOOLKIT */ | |
11719 | ||
4d73d038 | 11720 | /* If cursor was outside the new size, mark it as off. */ |
06a2c219 | 11721 | mark_window_cursors_off (XWINDOW (f->root_window)); |
4d73d038 | 11722 | |
aee9a898 RS |
11723 | /* Clear out any recollection of where the mouse highlighting was, |
11724 | since it might be in a place that's outside the new frame size. | |
11725 | Actually checking whether it is outside is a pain in the neck, | |
11726 | so don't try--just let the highlighting be done afresh with new size. */ | |
e687d06e | 11727 | cancel_mouse_face (f); |
dbc4e1c1 | 11728 | |
dc6f92b8 JB |
11729 | UNBLOCK_INPUT; |
11730 | } | |
dc6f92b8 | 11731 | \f |
d047c4eb | 11732 | /* Mouse warping. */ |
dc6f92b8 | 11733 | |
9b378208 | 11734 | void |
f676886a JB |
11735 | x_set_mouse_position (f, x, y) |
11736 | struct frame *f; | |
dc6f92b8 JB |
11737 | int x, y; |
11738 | { | |
11739 | int pix_x, pix_y; | |
11740 | ||
7556890b RS |
11741 | pix_x = CHAR_TO_PIXEL_COL (f, x) + FONT_WIDTH (f->output_data.x->font) / 2; |
11742 | pix_y = CHAR_TO_PIXEL_ROW (f, y) + f->output_data.x->line_height / 2; | |
f451eb13 JB |
11743 | |
11744 | if (pix_x < 0) pix_x = 0; | |
11745 | if (pix_x > PIXEL_WIDTH (f)) pix_x = PIXEL_WIDTH (f); | |
11746 | ||
11747 | if (pix_y < 0) pix_y = 0; | |
11748 | if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f); | |
dc6f92b8 JB |
11749 | |
11750 | BLOCK_INPUT; | |
dc6f92b8 | 11751 | |
334208b7 RS |
11752 | XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), |
11753 | 0, 0, 0, 0, pix_x, pix_y); | |
dc6f92b8 JB |
11754 | UNBLOCK_INPUT; |
11755 | } | |
11756 | ||
9b378208 RS |
11757 | /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */ |
11758 | ||
11759 | void | |
11760 | x_set_mouse_pixel_position (f, pix_x, pix_y) | |
11761 | struct frame *f; | |
11762 | int pix_x, pix_y; | |
11763 | { | |
11764 | BLOCK_INPUT; | |
11765 | ||
334208b7 RS |
11766 | XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), |
11767 | 0, 0, 0, 0, pix_x, pix_y); | |
9b378208 RS |
11768 | UNBLOCK_INPUT; |
11769 | } | |
d047c4eb KH |
11770 | \f |
11771 | /* focus shifting, raising and lowering. */ | |
9b378208 | 11772 | |
dfcf069d | 11773 | void |
f676886a JB |
11774 | x_focus_on_frame (f) |
11775 | struct frame *f; | |
dc6f92b8 | 11776 | { |
1fb20991 | 11777 | #if 0 /* This proves to be unpleasant. */ |
f676886a | 11778 | x_raise_frame (f); |
1fb20991 | 11779 | #endif |
6d4238f3 JB |
11780 | #if 0 |
11781 | /* I don't think that the ICCCM allows programs to do things like this | |
11782 | without the interaction of the window manager. Whatever you end up | |
f676886a | 11783 | doing with this code, do it to x_unfocus_frame too. */ |
334208b7 | 11784 | XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
dc6f92b8 | 11785 | RevertToPointerRoot, CurrentTime); |
c118dd06 | 11786 | #endif /* ! 0 */ |
dc6f92b8 JB |
11787 | } |
11788 | ||
dfcf069d | 11789 | void |
f676886a JB |
11790 | x_unfocus_frame (f) |
11791 | struct frame *f; | |
dc6f92b8 | 11792 | { |
6d4238f3 | 11793 | #if 0 |
f676886a | 11794 | /* Look at the remarks in x_focus_on_frame. */ |
0f941935 | 11795 | if (FRAME_X_DISPLAY_INFO (f)->x_focus_frame == f) |
334208b7 | 11796 | XSetInputFocus (FRAME_X_DISPLAY (f), PointerRoot, |
dc6f92b8 | 11797 | RevertToPointerRoot, CurrentTime); |
c118dd06 | 11798 | #endif /* ! 0 */ |
dc6f92b8 JB |
11799 | } |
11800 | ||
f676886a | 11801 | /* Raise frame F. */ |
dc6f92b8 | 11802 | |
dfcf069d | 11803 | void |
f676886a JB |
11804 | x_raise_frame (f) |
11805 | struct frame *f; | |
dc6f92b8 | 11806 | { |
3a88c238 | 11807 | if (f->async_visible) |
dc6f92b8 JB |
11808 | { |
11809 | BLOCK_INPUT; | |
3afe33e7 | 11810 | #ifdef USE_X_TOOLKIT |
7556890b | 11811 | XRaiseWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget)); |
3afe33e7 | 11812 | #else /* not USE_X_TOOLKIT */ |
334208b7 | 11813 | XRaiseWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
3afe33e7 | 11814 | #endif /* not USE_X_TOOLKIT */ |
334208b7 | 11815 | XFlush (FRAME_X_DISPLAY (f)); |
dc6f92b8 JB |
11816 | UNBLOCK_INPUT; |
11817 | } | |
11818 | } | |
11819 | ||
f676886a | 11820 | /* Lower frame F. */ |
dc6f92b8 | 11821 | |
dfcf069d | 11822 | void |
f676886a JB |
11823 | x_lower_frame (f) |
11824 | struct frame *f; | |
dc6f92b8 | 11825 | { |
3a88c238 | 11826 | if (f->async_visible) |
dc6f92b8 JB |
11827 | { |
11828 | BLOCK_INPUT; | |
3afe33e7 | 11829 | #ifdef USE_X_TOOLKIT |
7556890b | 11830 | XLowerWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget)); |
3afe33e7 | 11831 | #else /* not USE_X_TOOLKIT */ |
334208b7 | 11832 | XLowerWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
3afe33e7 | 11833 | #endif /* not USE_X_TOOLKIT */ |
334208b7 | 11834 | XFlush (FRAME_X_DISPLAY (f)); |
dc6f92b8 JB |
11835 | UNBLOCK_INPUT; |
11836 | } | |
11837 | } | |
11838 | ||
dbc4e1c1 | 11839 | static void |
6b0442dc | 11840 | XTframe_raise_lower (f, raise_flag) |
dbc4e1c1 | 11841 | FRAME_PTR f; |
6b0442dc | 11842 | int raise_flag; |
dbc4e1c1 | 11843 | { |
6b0442dc | 11844 | if (raise_flag) |
dbc4e1c1 JB |
11845 | x_raise_frame (f); |
11846 | else | |
11847 | x_lower_frame (f); | |
11848 | } | |
d047c4eb KH |
11849 | \f |
11850 | /* Change of visibility. */ | |
dc6f92b8 | 11851 | |
9382638d KH |
11852 | /* This tries to wait until the frame is really visible. |
11853 | However, if the window manager asks the user where to position | |
11854 | the frame, this will return before the user finishes doing that. | |
11855 | The frame will not actually be visible at that time, | |
11856 | but it will become visible later when the window manager | |
11857 | finishes with it. */ | |
11858 | ||
dfcf069d | 11859 | void |
f676886a JB |
11860 | x_make_frame_visible (f) |
11861 | struct frame *f; | |
dc6f92b8 | 11862 | { |
990ba854 | 11863 | Lisp_Object type; |
1aa6072f | 11864 | int original_top, original_left; |
31be9251 GM |
11865 | int retry_count = 2; |
11866 | ||
11867 | retry: | |
dc6f92b8 | 11868 | |
dc6f92b8 | 11869 | BLOCK_INPUT; |
dc6f92b8 | 11870 | |
990ba854 RS |
11871 | type = x_icon_type (f); |
11872 | if (!NILP (type)) | |
11873 | x_bitmap_icon (f, type); | |
bdcd49ba | 11874 | |
f676886a | 11875 | if (! FRAME_VISIBLE_P (f)) |
90e65f07 | 11876 | { |
1aa6072f RS |
11877 | /* We test FRAME_GARBAGED_P here to make sure we don't |
11878 | call x_set_offset a second time | |
11879 | if we get to x_make_frame_visible a second time | |
11880 | before the window gets really visible. */ | |
11881 | if (! FRAME_ICONIFIED_P (f) | |
11882 | && ! f->output_data.x->asked_for_visible) | |
11883 | x_set_offset (f, f->output_data.x->left_pos, f->output_data.x->top_pos, 0); | |
11884 | ||
11885 | f->output_data.x->asked_for_visible = 1; | |
11886 | ||
90e65f07 | 11887 | if (! EQ (Vx_no_window_manager, Qt)) |
f676886a | 11888 | x_wm_set_window_state (f, NormalState); |
3afe33e7 | 11889 | #ifdef USE_X_TOOLKIT |
d7a38a2e | 11890 | /* This was XtPopup, but that did nothing for an iconified frame. */ |
7556890b | 11891 | XtMapWidget (f->output_data.x->widget); |
3afe33e7 | 11892 | #else /* not USE_X_TOOLKIT */ |
7f9c7f94 | 11893 | XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
3afe33e7 | 11894 | #endif /* not USE_X_TOOLKIT */ |
0134a210 RS |
11895 | #if 0 /* This seems to bring back scroll bars in the wrong places |
11896 | if the window configuration has changed. They seem | |
11897 | to come back ok without this. */ | |
ab648270 | 11898 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
334208b7 | 11899 | XMapSubwindows (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
0134a210 | 11900 | #endif |
90e65f07 | 11901 | } |
dc6f92b8 | 11902 | |
334208b7 | 11903 | XFlush (FRAME_X_DISPLAY (f)); |
90e65f07 | 11904 | |
0dacf791 RS |
11905 | /* Synchronize to ensure Emacs knows the frame is visible |
11906 | before we do anything else. We do this loop with input not blocked | |
11907 | so that incoming events are handled. */ | |
11908 | { | |
11909 | Lisp_Object frame; | |
12ce2351 | 11910 | int count; |
28c01ffe RS |
11911 | /* This must be before UNBLOCK_INPUT |
11912 | since events that arrive in response to the actions above | |
11913 | will set it when they are handled. */ | |
11914 | int previously_visible = f->output_data.x->has_been_visible; | |
1aa6072f RS |
11915 | |
11916 | original_left = f->output_data.x->left_pos; | |
11917 | original_top = f->output_data.x->top_pos; | |
c0a04927 RS |
11918 | |
11919 | /* This must come after we set COUNT. */ | |
11920 | UNBLOCK_INPUT; | |
11921 | ||
2745e6c4 | 11922 | /* We unblock here so that arriving X events are processed. */ |
1aa6072f | 11923 | |
dcb07ae9 RS |
11924 | /* Now move the window back to where it was "supposed to be". |
11925 | But don't do it if the gravity is negative. | |
11926 | When the gravity is negative, this uses a position | |
28c01ffe RS |
11927 | that is 3 pixels too low. Perhaps that's really the border width. |
11928 | ||
11929 | Don't do this if the window has never been visible before, | |
11930 | because the window manager may choose the position | |
11931 | and we don't want to override it. */ | |
1aa6072f | 11932 | |
4d3f5d9a | 11933 | if (! FRAME_VISIBLE_P (f) && ! FRAME_ICONIFIED_P (f) |
06c488fd | 11934 | && f->output_data.x->win_gravity == NorthWestGravity |
28c01ffe | 11935 | && previously_visible) |
1aa6072f | 11936 | { |
2745e6c4 RS |
11937 | Drawable rootw; |
11938 | int x, y; | |
11939 | unsigned int width, height, border, depth; | |
06a2c219 | 11940 | |
1aa6072f | 11941 | BLOCK_INPUT; |
9829ddba | 11942 | |
06a2c219 GM |
11943 | /* On some window managers (such as FVWM) moving an existing |
11944 | window, even to the same place, causes the window manager | |
11945 | to introduce an offset. This can cause the window to move | |
11946 | to an unexpected location. Check the geometry (a little | |
11947 | slow here) and then verify that the window is in the right | |
11948 | place. If the window is not in the right place, move it | |
11949 | there, and take the potential window manager hit. */ | |
2745e6c4 RS |
11950 | XGetGeometry (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), |
11951 | &rootw, &x, &y, &width, &height, &border, &depth); | |
11952 | ||
11953 | if (original_left != x || original_top != y) | |
11954 | XMoveWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), | |
11955 | original_left, original_top); | |
11956 | ||
1aa6072f RS |
11957 | UNBLOCK_INPUT; |
11958 | } | |
9829ddba | 11959 | |
e0c1aef2 | 11960 | XSETFRAME (frame, f); |
c0a04927 | 11961 | |
12ce2351 GM |
11962 | /* Wait until the frame is visible. Process X events until a |
11963 | MapNotify event has been seen, or until we think we won't get a | |
11964 | MapNotify at all.. */ | |
11965 | for (count = input_signal_count + 10; | |
11966 | input_signal_count < count && !FRAME_VISIBLE_P (f);) | |
2a6cf806 | 11967 | { |
12ce2351 | 11968 | /* Force processing of queued events. */ |
334208b7 | 11969 | x_sync (f); |
12ce2351 GM |
11970 | |
11971 | /* Machines that do polling rather than SIGIO have been | |
11972 | observed to go into a busy-wait here. So we'll fake an | |
11973 | alarm signal to let the handler know that there's something | |
11974 | to be read. We used to raise a real alarm, but it seems | |
11975 | that the handler isn't always enabled here. This is | |
11976 | probably a bug. */ | |
8b2f8d4e | 11977 | if (input_polling_used ()) |
3b2fa4e6 | 11978 | { |
12ce2351 GM |
11979 | /* It could be confusing if a real alarm arrives while |
11980 | processing the fake one. Turn it off and let the | |
11981 | handler reset it. */ | |
3e71d8f2 | 11982 | extern void poll_for_input_1 P_ ((void)); |
bffcfca9 GM |
11983 | int old_poll_suppress_count = poll_suppress_count; |
11984 | poll_suppress_count = 1; | |
11985 | poll_for_input_1 (); | |
11986 | poll_suppress_count = old_poll_suppress_count; | |
3b2fa4e6 | 11987 | } |
12ce2351 GM |
11988 | |
11989 | /* See if a MapNotify event has been processed. */ | |
11990 | FRAME_SAMPLE_VISIBILITY (f); | |
2a6cf806 | 11991 | } |
31be9251 GM |
11992 | |
11993 | /* 2000-09-28: In | |
11994 | ||
11995 | (let ((f (selected-frame))) | |
11996 | (iconify-frame f) | |
11997 | (raise-frame f)) | |
11998 | ||
11999 | the frame is not raised with various window managers on | |
12000 | FreeBSD, Linux and Solaris. It turns out that, for some | |
12001 | unknown reason, the call to XtMapWidget is completely ignored. | |
12002 | Mapping the widget a second time works. */ | |
12003 | ||
12004 | if (!FRAME_VISIBLE_P (f) && --retry_count > 0) | |
12005 | goto retry; | |
0dacf791 | 12006 | } |
dc6f92b8 JB |
12007 | } |
12008 | ||
06a2c219 | 12009 | /* Change from mapped state to withdrawn state. */ |
dc6f92b8 | 12010 | |
d047c4eb KH |
12011 | /* Make the frame visible (mapped and not iconified). */ |
12012 | ||
dfcf069d | 12013 | void |
f676886a JB |
12014 | x_make_frame_invisible (f) |
12015 | struct frame *f; | |
dc6f92b8 | 12016 | { |
546e6d5b RS |
12017 | Window window; |
12018 | ||
12019 | #ifdef USE_X_TOOLKIT | |
12020 | /* Use the frame's outermost window, not the one we normally draw on. */ | |
7556890b | 12021 | window = XtWindow (f->output_data.x->widget); |
546e6d5b RS |
12022 | #else /* not USE_X_TOOLKIT */ |
12023 | window = FRAME_X_WINDOW (f); | |
12024 | #endif /* not USE_X_TOOLKIT */ | |
dc6f92b8 | 12025 | |
9319ae23 | 12026 | /* Don't keep the highlight on an invisible frame. */ |
0f941935 KH |
12027 | if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f) |
12028 | FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0; | |
9319ae23 | 12029 | |
5627c40e | 12030 | #if 0/* This might add unreliability; I don't trust it -- rms. */ |
9319ae23 | 12031 | if (! f->async_visible && ! f->async_iconified) |
dc6f92b8 | 12032 | return; |
5627c40e | 12033 | #endif |
dc6f92b8 JB |
12034 | |
12035 | BLOCK_INPUT; | |
c118dd06 | 12036 | |
af31d76f RS |
12037 | /* Before unmapping the window, update the WM_SIZE_HINTS property to claim |
12038 | that the current position of the window is user-specified, rather than | |
12039 | program-specified, so that when the window is mapped again, it will be | |
12040 | placed at the same location, without forcing the user to position it | |
12041 | by hand again (they have already done that once for this window.) */ | |
c32cdd9a | 12042 | x_wm_set_size_hint (f, (long) 0, 1); |
af31d76f | 12043 | |
c118dd06 JB |
12044 | #ifdef HAVE_X11R4 |
12045 | ||
334208b7 RS |
12046 | if (! XWithdrawWindow (FRAME_X_DISPLAY (f), window, |
12047 | DefaultScreen (FRAME_X_DISPLAY (f)))) | |
c118dd06 JB |
12048 | { |
12049 | UNBLOCK_INPUT_RESIGNAL; | |
546e6d5b | 12050 | error ("Can't notify window manager of window withdrawal"); |
c118dd06 | 12051 | } |
c118dd06 | 12052 | #else /* ! defined (HAVE_X11R4) */ |
16bd92ea | 12053 | |
c118dd06 | 12054 | /* Tell the window manager what we're going to do. */ |
dc6f92b8 JB |
12055 | if (! EQ (Vx_no_window_manager, Qt)) |
12056 | { | |
16bd92ea | 12057 | XEvent unmap; |
dc6f92b8 | 12058 | |
16bd92ea | 12059 | unmap.xunmap.type = UnmapNotify; |
546e6d5b | 12060 | unmap.xunmap.window = window; |
334208b7 | 12061 | unmap.xunmap.event = DefaultRootWindow (FRAME_X_DISPLAY (f)); |
16bd92ea | 12062 | unmap.xunmap.from_configure = False; |
334208b7 RS |
12063 | if (! XSendEvent (FRAME_X_DISPLAY (f), |
12064 | DefaultRootWindow (FRAME_X_DISPLAY (f)), | |
16bd92ea | 12065 | False, |
06a2c219 | 12066 | SubstructureRedirectMaskSubstructureNotifyMask, |
16bd92ea JB |
12067 | &unmap)) |
12068 | { | |
12069 | UNBLOCK_INPUT_RESIGNAL; | |
546e6d5b | 12070 | error ("Can't notify window manager of withdrawal"); |
16bd92ea | 12071 | } |
dc6f92b8 JB |
12072 | } |
12073 | ||
16bd92ea | 12074 | /* Unmap the window ourselves. Cheeky! */ |
334208b7 | 12075 | XUnmapWindow (FRAME_X_DISPLAY (f), window); |
c118dd06 | 12076 | #endif /* ! defined (HAVE_X11R4) */ |
dc6f92b8 | 12077 | |
5627c40e RS |
12078 | /* We can't distinguish this from iconification |
12079 | just by the event that we get from the server. | |
12080 | So we can't win using the usual strategy of letting | |
12081 | FRAME_SAMPLE_VISIBILITY set this. So do it by hand, | |
12082 | and synchronize with the server to make sure we agree. */ | |
12083 | f->visible = 0; | |
12084 | FRAME_ICONIFIED_P (f) = 0; | |
12085 | f->async_visible = 0; | |
12086 | f->async_iconified = 0; | |
12087 | ||
334208b7 | 12088 | x_sync (f); |
5627c40e | 12089 | |
dc6f92b8 JB |
12090 | UNBLOCK_INPUT; |
12091 | } | |
12092 | ||
06a2c219 | 12093 | /* Change window state from mapped to iconified. */ |
dc6f92b8 | 12094 | |
dfcf069d | 12095 | void |
f676886a JB |
12096 | x_iconify_frame (f) |
12097 | struct frame *f; | |
dc6f92b8 | 12098 | { |
3afe33e7 | 12099 | int result; |
990ba854 | 12100 | Lisp_Object type; |
dc6f92b8 | 12101 | |
9319ae23 | 12102 | /* Don't keep the highlight on an invisible frame. */ |
0f941935 KH |
12103 | if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f) |
12104 | FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0; | |
9319ae23 | 12105 | |
3a88c238 | 12106 | if (f->async_iconified) |
dc6f92b8 JB |
12107 | return; |
12108 | ||
3afe33e7 | 12109 | BLOCK_INPUT; |
546e6d5b | 12110 | |
9af3143a RS |
12111 | FRAME_SAMPLE_VISIBILITY (f); |
12112 | ||
990ba854 RS |
12113 | type = x_icon_type (f); |
12114 | if (!NILP (type)) | |
12115 | x_bitmap_icon (f, type); | |
bdcd49ba RS |
12116 | |
12117 | #ifdef USE_X_TOOLKIT | |
12118 | ||
546e6d5b RS |
12119 | if (! FRAME_VISIBLE_P (f)) |
12120 | { | |
12121 | if (! EQ (Vx_no_window_manager, Qt)) | |
12122 | x_wm_set_window_state (f, IconicState); | |
12123 | /* This was XtPopup, but that did nothing for an iconified frame. */ | |
7556890b | 12124 | XtMapWidget (f->output_data.x->widget); |
9cf30a30 RS |
12125 | /* The server won't give us any event to indicate |
12126 | that an invisible frame was changed to an icon, | |
12127 | so we have to record it here. */ | |
12128 | f->iconified = 1; | |
1e6bc770 | 12129 | f->visible = 1; |
9cf30a30 | 12130 | f->async_iconified = 1; |
1e6bc770 | 12131 | f->async_visible = 0; |
546e6d5b RS |
12132 | UNBLOCK_INPUT; |
12133 | return; | |
12134 | } | |
12135 | ||
334208b7 | 12136 | result = XIconifyWindow (FRAME_X_DISPLAY (f), |
7556890b | 12137 | XtWindow (f->output_data.x->widget), |
334208b7 | 12138 | DefaultScreen (FRAME_X_DISPLAY (f))); |
3afe33e7 RS |
12139 | UNBLOCK_INPUT; |
12140 | ||
12141 | if (!result) | |
546e6d5b | 12142 | error ("Can't notify window manager of iconification"); |
3afe33e7 RS |
12143 | |
12144 | f->async_iconified = 1; | |
1e6bc770 RS |
12145 | f->async_visible = 0; |
12146 | ||
8c002a25 KH |
12147 | |
12148 | BLOCK_INPUT; | |
334208b7 | 12149 | XFlush (FRAME_X_DISPLAY (f)); |
8c002a25 | 12150 | UNBLOCK_INPUT; |
3afe33e7 RS |
12151 | #else /* not USE_X_TOOLKIT */ |
12152 | ||
fd13dbb2 RS |
12153 | /* Make sure the X server knows where the window should be positioned, |
12154 | in case the user deiconifies with the window manager. */ | |
12155 | if (! FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f)) | |
7556890b | 12156 | x_set_offset (f, f->output_data.x->left_pos, f->output_data.x->top_pos, 0); |
fd13dbb2 | 12157 | |
16bd92ea JB |
12158 | /* Since we don't know which revision of X we're running, we'll use both |
12159 | the X11R3 and X11R4 techniques. I don't know if this is a good idea. */ | |
12160 | ||
12161 | /* X11R4: send a ClientMessage to the window manager using the | |
12162 | WM_CHANGE_STATE type. */ | |
12163 | { | |
12164 | XEvent message; | |
58769bee | 12165 | |
c118dd06 | 12166 | message.xclient.window = FRAME_X_WINDOW (f); |
16bd92ea | 12167 | message.xclient.type = ClientMessage; |
334208b7 | 12168 | message.xclient.message_type = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_change_state; |
16bd92ea JB |
12169 | message.xclient.format = 32; |
12170 | message.xclient.data.l[0] = IconicState; | |
12171 | ||
334208b7 RS |
12172 | if (! XSendEvent (FRAME_X_DISPLAY (f), |
12173 | DefaultRootWindow (FRAME_X_DISPLAY (f)), | |
16bd92ea JB |
12174 | False, |
12175 | SubstructureRedirectMask | SubstructureNotifyMask, | |
12176 | &message)) | |
dc6f92b8 JB |
12177 | { |
12178 | UNBLOCK_INPUT_RESIGNAL; | |
546e6d5b | 12179 | error ("Can't notify window manager of iconification"); |
dc6f92b8 | 12180 | } |
16bd92ea | 12181 | } |
dc6f92b8 | 12182 | |
58769bee | 12183 | /* X11R3: set the initial_state field of the window manager hints to |
16bd92ea JB |
12184 | IconicState. */ |
12185 | x_wm_set_window_state (f, IconicState); | |
dc6f92b8 | 12186 | |
a9c00105 RS |
12187 | if (!FRAME_VISIBLE_P (f)) |
12188 | { | |
12189 | /* If the frame was withdrawn, before, we must map it. */ | |
7f9c7f94 | 12190 | XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
a9c00105 RS |
12191 | } |
12192 | ||
3a88c238 | 12193 | f->async_iconified = 1; |
1e6bc770 | 12194 | f->async_visible = 0; |
dc6f92b8 | 12195 | |
334208b7 | 12196 | XFlush (FRAME_X_DISPLAY (f)); |
dc6f92b8 | 12197 | UNBLOCK_INPUT; |
8c002a25 | 12198 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 | 12199 | } |
d047c4eb | 12200 | \f |
c0ff3fab | 12201 | /* Destroy the X window of frame F. */ |
dc6f92b8 | 12202 | |
dfcf069d | 12203 | void |
c0ff3fab | 12204 | x_destroy_window (f) |
f676886a | 12205 | struct frame *f; |
dc6f92b8 | 12206 | { |
7f9c7f94 RS |
12207 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
12208 | ||
dc6f92b8 | 12209 | BLOCK_INPUT; |
c0ff3fab | 12210 | |
6186a4a0 RS |
12211 | /* If a display connection is dead, don't try sending more |
12212 | commands to the X server. */ | |
12213 | if (dpyinfo->display != 0) | |
12214 | { | |
12215 | if (f->output_data.x->icon_desc != 0) | |
12216 | XDestroyWindow (FRAME_X_DISPLAY (f), f->output_data.x->icon_desc); | |
31f41daf | 12217 | #ifdef HAVE_X_I18N |
f5d11644 GM |
12218 | if (FRAME_XIC (f)) |
12219 | free_frame_xic (f); | |
31f41daf | 12220 | #endif |
6186a4a0 | 12221 | XDestroyWindow (FRAME_X_DISPLAY (f), f->output_data.x->window_desc); |
3afe33e7 | 12222 | #ifdef USE_X_TOOLKIT |
06a2c219 GM |
12223 | if (f->output_data.x->widget) |
12224 | XtDestroyWidget (f->output_data.x->widget); | |
6186a4a0 | 12225 | free_frame_menubar (f); |
3afe33e7 RS |
12226 | #endif /* USE_X_TOOLKIT */ |
12227 | ||
3e71d8f2 GM |
12228 | unload_color (f, f->output_data.x->foreground_pixel); |
12229 | unload_color (f, f->output_data.x->background_pixel); | |
12230 | unload_color (f, f->output_data.x->cursor_pixel); | |
12231 | unload_color (f, f->output_data.x->cursor_foreground_pixel); | |
12232 | unload_color (f, f->output_data.x->border_pixel); | |
12233 | unload_color (f, f->output_data.x->mouse_pixel); | |
12234 | if (f->output_data.x->scroll_bar_background_pixel != -1) | |
12235 | unload_color (f, f->output_data.x->scroll_bar_background_pixel); | |
12236 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
12237 | unload_color (f, f->output_data.x->scroll_bar_foreground_pixel); | |
12238 | if (f->output_data.x->white_relief.allocated_p) | |
12239 | unload_color (f, f->output_data.x->white_relief.pixel); | |
12240 | if (f->output_data.x->black_relief.allocated_p) | |
12241 | unload_color (f, f->output_data.x->black_relief.pixel); | |
12242 | ||
6186a4a0 RS |
12243 | free_frame_faces (f); |
12244 | XFlush (FRAME_X_DISPLAY (f)); | |
12245 | } | |
dc6f92b8 | 12246 | |
df89d8a4 | 12247 | if (f->output_data.x->saved_menu_event) |
06a2c219 | 12248 | xfree (f->output_data.x->saved_menu_event); |
0c49ce2f | 12249 | |
7556890b RS |
12250 | xfree (f->output_data.x); |
12251 | f->output_data.x = 0; | |
0f941935 KH |
12252 | if (f == dpyinfo->x_focus_frame) |
12253 | dpyinfo->x_focus_frame = 0; | |
12254 | if (f == dpyinfo->x_focus_event_frame) | |
12255 | dpyinfo->x_focus_event_frame = 0; | |
12256 | if (f == dpyinfo->x_highlight_frame) | |
12257 | dpyinfo->x_highlight_frame = 0; | |
c0ff3fab | 12258 | |
7f9c7f94 RS |
12259 | dpyinfo->reference_count--; |
12260 | ||
12261 | if (f == dpyinfo->mouse_face_mouse_frame) | |
dc05a16b | 12262 | { |
7f9c7f94 RS |
12263 | dpyinfo->mouse_face_beg_row |
12264 | = dpyinfo->mouse_face_beg_col = -1; | |
12265 | dpyinfo->mouse_face_end_row | |
12266 | = dpyinfo->mouse_face_end_col = -1; | |
12267 | dpyinfo->mouse_face_window = Qnil; | |
21323706 RS |
12268 | dpyinfo->mouse_face_deferred_gc = 0; |
12269 | dpyinfo->mouse_face_mouse_frame = 0; | |
dc05a16b | 12270 | } |
0134a210 | 12271 | |
c0ff3fab | 12272 | UNBLOCK_INPUT; |
dc6f92b8 JB |
12273 | } |
12274 | \f | |
f451eb13 JB |
12275 | /* Setting window manager hints. */ |
12276 | ||
af31d76f RS |
12277 | /* Set the normal size hints for the window manager, for frame F. |
12278 | FLAGS is the flags word to use--or 0 meaning preserve the flags | |
12279 | that the window now has. | |
12280 | If USER_POSITION is nonzero, we set the USPosition | |
12281 | flag (this is useful when FLAGS is 0). */ | |
6dba1858 | 12282 | |
dfcf069d | 12283 | void |
af31d76f | 12284 | x_wm_set_size_hint (f, flags, user_position) |
f676886a | 12285 | struct frame *f; |
af31d76f RS |
12286 | long flags; |
12287 | int user_position; | |
dc6f92b8 JB |
12288 | { |
12289 | XSizeHints size_hints; | |
3afe33e7 RS |
12290 | |
12291 | #ifdef USE_X_TOOLKIT | |
7e4f2521 FP |
12292 | Arg al[2]; |
12293 | int ac = 0; | |
12294 | Dimension widget_width, widget_height; | |
7556890b | 12295 | Window window = XtWindow (f->output_data.x->widget); |
3afe33e7 | 12296 | #else /* not USE_X_TOOLKIT */ |
c118dd06 | 12297 | Window window = FRAME_X_WINDOW (f); |
3afe33e7 | 12298 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 | 12299 | |
b72a58fd RS |
12300 | /* Setting PMaxSize caused various problems. */ |
12301 | size_hints.flags = PResizeInc | PMinSize /* | PMaxSize */; | |
dc6f92b8 | 12302 | |
7556890b RS |
12303 | size_hints.x = f->output_data.x->left_pos; |
12304 | size_hints.y = f->output_data.x->top_pos; | |
7553a6b7 | 12305 | |
7e4f2521 FP |
12306 | #ifdef USE_X_TOOLKIT |
12307 | XtSetArg (al[ac], XtNwidth, &widget_width); ac++; | |
12308 | XtSetArg (al[ac], XtNheight, &widget_height); ac++; | |
7556890b | 12309 | XtGetValues (f->output_data.x->widget, al, ac); |
7e4f2521 FP |
12310 | size_hints.height = widget_height; |
12311 | size_hints.width = widget_width; | |
12312 | #else /* not USE_X_TOOLKIT */ | |
f676886a JB |
12313 | size_hints.height = PIXEL_HEIGHT (f); |
12314 | size_hints.width = PIXEL_WIDTH (f); | |
7e4f2521 | 12315 | #endif /* not USE_X_TOOLKIT */ |
7553a6b7 | 12316 | |
7556890b RS |
12317 | size_hints.width_inc = FONT_WIDTH (f->output_data.x->font); |
12318 | size_hints.height_inc = f->output_data.x->line_height; | |
334208b7 RS |
12319 | size_hints.max_width |
12320 | = FRAME_X_DISPLAY_INFO (f)->width - CHAR_TO_PIXEL_WIDTH (f, 0); | |
12321 | size_hints.max_height | |
12322 | = FRAME_X_DISPLAY_INFO (f)->height - CHAR_TO_PIXEL_HEIGHT (f, 0); | |
0134a210 | 12323 | |
d067ea8b KH |
12324 | /* Calculate the base and minimum sizes. |
12325 | ||
12326 | (When we use the X toolkit, we don't do it here. | |
12327 | Instead we copy the values that the widgets are using, below.) */ | |
12328 | #ifndef USE_X_TOOLKIT | |
b1c884c3 | 12329 | { |
b0342f17 | 12330 | int base_width, base_height; |
0134a210 | 12331 | int min_rows = 0, min_cols = 0; |
b0342f17 | 12332 | |
f451eb13 JB |
12333 | base_width = CHAR_TO_PIXEL_WIDTH (f, 0); |
12334 | base_height = CHAR_TO_PIXEL_HEIGHT (f, 0); | |
b0342f17 | 12335 | |
0134a210 | 12336 | check_frame_size (f, &min_rows, &min_cols); |
b0342f17 | 12337 | |
0134a210 RS |
12338 | /* The window manager uses the base width hints to calculate the |
12339 | current number of rows and columns in the frame while | |
12340 | resizing; min_width and min_height aren't useful for this | |
12341 | purpose, since they might not give the dimensions for a | |
12342 | zero-row, zero-column frame. | |
58769bee | 12343 | |
0134a210 RS |
12344 | We use the base_width and base_height members if we have |
12345 | them; otherwise, we set the min_width and min_height members | |
12346 | to the size for a zero x zero frame. */ | |
b0342f17 JB |
12347 | |
12348 | #ifdef HAVE_X11R4 | |
0134a210 RS |
12349 | size_hints.flags |= PBaseSize; |
12350 | size_hints.base_width = base_width; | |
12351 | size_hints.base_height = base_height; | |
12352 | size_hints.min_width = base_width + min_cols * size_hints.width_inc; | |
12353 | size_hints.min_height = base_height + min_rows * size_hints.height_inc; | |
b0342f17 | 12354 | #else |
0134a210 RS |
12355 | size_hints.min_width = base_width; |
12356 | size_hints.min_height = base_height; | |
b0342f17 | 12357 | #endif |
b1c884c3 | 12358 | } |
dc6f92b8 | 12359 | |
d067ea8b | 12360 | /* If we don't need the old flags, we don't need the old hint at all. */ |
af31d76f | 12361 | if (flags) |
dc6f92b8 | 12362 | { |
d067ea8b KH |
12363 | size_hints.flags |= flags; |
12364 | goto no_read; | |
12365 | } | |
12366 | #endif /* not USE_X_TOOLKIT */ | |
12367 | ||
12368 | { | |
12369 | XSizeHints hints; /* Sometimes I hate X Windows... */ | |
12370 | long supplied_return; | |
12371 | int value; | |
af31d76f RS |
12372 | |
12373 | #ifdef HAVE_X11R4 | |
d067ea8b KH |
12374 | value = XGetWMNormalHints (FRAME_X_DISPLAY (f), window, &hints, |
12375 | &supplied_return); | |
af31d76f | 12376 | #else |
d067ea8b | 12377 | value = XGetNormalHints (FRAME_X_DISPLAY (f), window, &hints); |
af31d76f | 12378 | #endif |
58769bee | 12379 | |
d067ea8b KH |
12380 | #ifdef USE_X_TOOLKIT |
12381 | size_hints.base_height = hints.base_height; | |
12382 | size_hints.base_width = hints.base_width; | |
12383 | size_hints.min_height = hints.min_height; | |
12384 | size_hints.min_width = hints.min_width; | |
12385 | #endif | |
12386 | ||
12387 | if (flags) | |
12388 | size_hints.flags |= flags; | |
12389 | else | |
12390 | { | |
12391 | if (value == 0) | |
12392 | hints.flags = 0; | |
12393 | if (hints.flags & PSize) | |
12394 | size_hints.flags |= PSize; | |
12395 | if (hints.flags & PPosition) | |
12396 | size_hints.flags |= PPosition; | |
12397 | if (hints.flags & USPosition) | |
12398 | size_hints.flags |= USPosition; | |
12399 | if (hints.flags & USSize) | |
12400 | size_hints.flags |= USSize; | |
12401 | } | |
12402 | } | |
12403 | ||
06a2c219 | 12404 | #ifndef USE_X_TOOLKIT |
d067ea8b | 12405 | no_read: |
06a2c219 | 12406 | #endif |
0134a210 | 12407 | |
af31d76f | 12408 | #ifdef PWinGravity |
7556890b | 12409 | size_hints.win_gravity = f->output_data.x->win_gravity; |
af31d76f | 12410 | size_hints.flags |= PWinGravity; |
dc05a16b | 12411 | |
af31d76f | 12412 | if (user_position) |
6dba1858 | 12413 | { |
af31d76f RS |
12414 | size_hints.flags &= ~ PPosition; |
12415 | size_hints.flags |= USPosition; | |
6dba1858 | 12416 | } |
2554751d | 12417 | #endif /* PWinGravity */ |
6dba1858 | 12418 | |
b0342f17 | 12419 | #ifdef HAVE_X11R4 |
334208b7 | 12420 | XSetWMNormalHints (FRAME_X_DISPLAY (f), window, &size_hints); |
b0342f17 | 12421 | #else |
334208b7 | 12422 | XSetNormalHints (FRAME_X_DISPLAY (f), window, &size_hints); |
b0342f17 | 12423 | #endif |
dc6f92b8 JB |
12424 | } |
12425 | ||
12426 | /* Used for IconicState or NormalState */ | |
06a2c219 | 12427 | |
dfcf069d | 12428 | void |
f676886a JB |
12429 | x_wm_set_window_state (f, state) |
12430 | struct frame *f; | |
dc6f92b8 JB |
12431 | int state; |
12432 | { | |
3afe33e7 | 12433 | #ifdef USE_X_TOOLKIT |
546e6d5b RS |
12434 | Arg al[1]; |
12435 | ||
12436 | XtSetArg (al[0], XtNinitialState, state); | |
7556890b | 12437 | XtSetValues (f->output_data.x->widget, al, 1); |
3afe33e7 | 12438 | #else /* not USE_X_TOOLKIT */ |
c118dd06 | 12439 | Window window = FRAME_X_WINDOW (f); |
dc6f92b8 | 12440 | |
7556890b RS |
12441 | f->output_data.x->wm_hints.flags |= StateHint; |
12442 | f->output_data.x->wm_hints.initial_state = state; | |
b1c884c3 | 12443 | |
7556890b | 12444 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints); |
546e6d5b | 12445 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
12446 | } |
12447 | ||
dfcf069d | 12448 | void |
7f2ae036 | 12449 | x_wm_set_icon_pixmap (f, pixmap_id) |
f676886a | 12450 | struct frame *f; |
7f2ae036 | 12451 | int pixmap_id; |
dc6f92b8 | 12452 | { |
d2bd6bc4 RS |
12453 | Pixmap icon_pixmap; |
12454 | ||
06a2c219 | 12455 | #ifndef USE_X_TOOLKIT |
c118dd06 | 12456 | Window window = FRAME_X_WINDOW (f); |
75231bad | 12457 | #endif |
dc6f92b8 | 12458 | |
7f2ae036 | 12459 | if (pixmap_id > 0) |
dbc4e1c1 | 12460 | { |
d2bd6bc4 | 12461 | icon_pixmap = x_bitmap_pixmap (f, pixmap_id); |
7556890b | 12462 | f->output_data.x->wm_hints.icon_pixmap = icon_pixmap; |
dbc4e1c1 JB |
12463 | } |
12464 | else | |
68568555 RS |
12465 | { |
12466 | /* It seems there is no way to turn off use of an icon pixmap. | |
12467 | The following line does it, only if no icon has yet been created, | |
12468 | for some window managers. But with mwm it crashes. | |
12469 | Some people say it should clear the IconPixmapHint bit in this case, | |
12470 | but that doesn't work, and the X consortium said it isn't the | |
12471 | right thing at all. Since there is no way to win, | |
12472 | best to explicitly give up. */ | |
12473 | #if 0 | |
12474 | f->output_data.x->wm_hints.icon_pixmap = None; | |
12475 | #else | |
12476 | return; | |
12477 | #endif | |
12478 | } | |
b1c884c3 | 12479 | |
d2bd6bc4 RS |
12480 | #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */ |
12481 | ||
12482 | { | |
12483 | Arg al[1]; | |
12484 | XtSetArg (al[0], XtNiconPixmap, icon_pixmap); | |
12485 | XtSetValues (f->output_data.x->widget, al, 1); | |
12486 | } | |
12487 | ||
12488 | #else /* not USE_X_TOOLKIT */ | |
12489 | ||
7556890b RS |
12490 | f->output_data.x->wm_hints.flags |= IconPixmapHint; |
12491 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints); | |
d2bd6bc4 RS |
12492 | |
12493 | #endif /* not USE_X_TOOLKIT */ | |
dc6f92b8 JB |
12494 | } |
12495 | ||
dfcf069d | 12496 | void |
f676886a JB |
12497 | x_wm_set_icon_position (f, icon_x, icon_y) |
12498 | struct frame *f; | |
dc6f92b8 JB |
12499 | int icon_x, icon_y; |
12500 | { | |
75231bad | 12501 | #ifdef USE_X_TOOLKIT |
7556890b | 12502 | Window window = XtWindow (f->output_data.x->widget); |
75231bad | 12503 | #else |
c118dd06 | 12504 | Window window = FRAME_X_WINDOW (f); |
75231bad | 12505 | #endif |
dc6f92b8 | 12506 | |
7556890b RS |
12507 | f->output_data.x->wm_hints.flags |= IconPositionHint; |
12508 | f->output_data.x->wm_hints.icon_x = icon_x; | |
12509 | f->output_data.x->wm_hints.icon_y = icon_y; | |
b1c884c3 | 12510 | |
7556890b | 12511 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints); |
dc6f92b8 JB |
12512 | } |
12513 | ||
12514 | \f | |
06a2c219 GM |
12515 | /*********************************************************************** |
12516 | Fonts | |
12517 | ***********************************************************************/ | |
dc43ef94 KH |
12518 | |
12519 | /* Return a pointer to struct font_info of font FONT_IDX of frame F. */ | |
06a2c219 | 12520 | |
dc43ef94 KH |
12521 | struct font_info * |
12522 | x_get_font_info (f, font_idx) | |
12523 | FRAME_PTR f; | |
12524 | int font_idx; | |
12525 | { | |
12526 | return (FRAME_X_FONT_TABLE (f) + font_idx); | |
12527 | } | |
12528 | ||
12529 | ||
12530 | /* Return a list of names of available fonts matching PATTERN on frame | |
12531 | F. If SIZE is not 0, it is the size (maximum bound width) of fonts | |
12532 | to be listed. Frame F NULL means we have not yet created any | |
12533 | frame on X, and consult the first display in x_display_list. | |
12534 | MAXNAMES sets a limit on how many fonts to match. */ | |
12535 | ||
12536 | Lisp_Object | |
12537 | x_list_fonts (f, pattern, size, maxnames) | |
12538 | FRAME_PTR f; | |
12539 | Lisp_Object pattern; | |
12540 | int size; | |
12541 | int maxnames; | |
12542 | { | |
06a2c219 GM |
12543 | Lisp_Object list = Qnil, patterns, newlist = Qnil, key = Qnil; |
12544 | Lisp_Object tem, second_best; | |
dc43ef94 | 12545 | Display *dpy = f != NULL ? FRAME_X_DISPLAY (f) : x_display_list->display; |
09c6077f | 12546 | int try_XLoadQueryFont = 0; |
53ca4657 | 12547 | int count; |
dc43ef94 | 12548 | |
6b0efe73 | 12549 | patterns = Fassoc (pattern, Valternate_fontname_alist); |
2da424f1 KH |
12550 | if (NILP (patterns)) |
12551 | patterns = Fcons (pattern, Qnil); | |
81ba44e5 | 12552 | |
09c6077f KH |
12553 | if (maxnames == 1 && !size) |
12554 | /* We can return any single font matching PATTERN. */ | |
12555 | try_XLoadQueryFont = 1; | |
9a32686f | 12556 | |
8e713be6 | 12557 | for (; CONSP (patterns); patterns = XCDR (patterns)) |
dc43ef94 | 12558 | { |
dc43ef94 | 12559 | int num_fonts; |
3e71d8f2 | 12560 | char **names = NULL; |
dc43ef94 | 12561 | |
8e713be6 | 12562 | pattern = XCAR (patterns); |
536f4067 RS |
12563 | /* See if we cached the result for this particular query. |
12564 | The cache is an alist of the form: | |
12565 | (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...) | |
12566 | */ | |
8e713be6 | 12567 | if (f && (tem = XCDR (FRAME_X_DISPLAY_INFO (f)->name_list_element), |
b5210ea7 KH |
12568 | key = Fcons (pattern, make_number (maxnames)), |
12569 | !NILP (list = Fassoc (key, tem)))) | |
12570 | { | |
12571 | list = Fcdr_safe (list); | |
12572 | /* We have a cashed list. Don't have to get the list again. */ | |
12573 | goto label_cached; | |
12574 | } | |
12575 | ||
12576 | /* At first, put PATTERN in the cache. */ | |
09c6077f | 12577 | |
dc43ef94 | 12578 | BLOCK_INPUT; |
17d85edc KH |
12579 | count = x_catch_errors (dpy); |
12580 | ||
09c6077f KH |
12581 | if (try_XLoadQueryFont) |
12582 | { | |
12583 | XFontStruct *font; | |
12584 | unsigned long value; | |
12585 | ||
12586 | font = XLoadQueryFont (dpy, XSTRING (pattern)->data); | |
17d85edc KH |
12587 | if (x_had_errors_p (dpy)) |
12588 | { | |
12589 | /* This error is perhaps due to insufficient memory on X | |
12590 | server. Let's just ignore it. */ | |
12591 | font = NULL; | |
12592 | x_clear_errors (dpy); | |
12593 | } | |
12594 | ||
09c6077f KH |
12595 | if (font |
12596 | && XGetFontProperty (font, XA_FONT, &value)) | |
12597 | { | |
12598 | char *name = (char *) XGetAtomName (dpy, (Atom) value); | |
12599 | int len = strlen (name); | |
01c752b5 | 12600 | char *tmp; |
09c6077f | 12601 | |
6f6512e8 KH |
12602 | /* If DXPC (a Differential X Protocol Compressor) |
12603 | Ver.3.7 is running, XGetAtomName will return null | |
12604 | string. We must avoid such a name. */ | |
12605 | if (len == 0) | |
12606 | try_XLoadQueryFont = 0; | |
12607 | else | |
12608 | { | |
12609 | num_fonts = 1; | |
12610 | names = (char **) alloca (sizeof (char *)); | |
12611 | /* Some systems only allow alloca assigned to a | |
12612 | simple var. */ | |
12613 | tmp = (char *) alloca (len + 1); names[0] = tmp; | |
12614 | bcopy (name, names[0], len + 1); | |
12615 | XFree (name); | |
12616 | } | |
09c6077f KH |
12617 | } |
12618 | else | |
12619 | try_XLoadQueryFont = 0; | |
a083fd23 RS |
12620 | |
12621 | if (font) | |
12622 | XFreeFont (dpy, font); | |
09c6077f KH |
12623 | } |
12624 | ||
12625 | if (!try_XLoadQueryFont) | |
17d85edc KH |
12626 | { |
12627 | /* We try at least 10 fonts because XListFonts will return | |
12628 | auto-scaled fonts at the head. */ | |
12629 | names = XListFonts (dpy, XSTRING (pattern)->data, max (maxnames, 10), | |
12630 | &num_fonts); | |
12631 | if (x_had_errors_p (dpy)) | |
12632 | { | |
12633 | /* This error is perhaps due to insufficient memory on X | |
12634 | server. Let's just ignore it. */ | |
12635 | names = NULL; | |
12636 | x_clear_errors (dpy); | |
12637 | } | |
12638 | } | |
12639 | ||
12640 | x_uncatch_errors (dpy, count); | |
dc43ef94 KH |
12641 | UNBLOCK_INPUT; |
12642 | ||
12643 | if (names) | |
12644 | { | |
12645 | int i; | |
dc43ef94 KH |
12646 | |
12647 | /* Make a list of all the fonts we got back. | |
12648 | Store that in the font cache for the display. */ | |
12649 | for (i = 0; i < num_fonts; i++) | |
12650 | { | |
06a2c219 | 12651 | int width = 0; |
dc43ef94 | 12652 | char *p = names[i]; |
06a2c219 GM |
12653 | int average_width = -1, dashes = 0; |
12654 | ||
dc43ef94 | 12655 | /* Count the number of dashes in NAMES[I]. If there are |
b5210ea7 KH |
12656 | 14 dashes, and the field value following 12th dash |
12657 | (AVERAGE_WIDTH) is 0, this is a auto-scaled font which | |
12658 | is usually too ugly to be used for editing. Let's | |
12659 | ignore it. */ | |
dc43ef94 KH |
12660 | while (*p) |
12661 | if (*p++ == '-') | |
12662 | { | |
12663 | dashes++; | |
12664 | if (dashes == 7) /* PIXEL_SIZE field */ | |
12665 | width = atoi (p); | |
12666 | else if (dashes == 12) /* AVERAGE_WIDTH field */ | |
12667 | average_width = atoi (p); | |
12668 | } | |
12669 | if (dashes < 14 || average_width != 0) | |
12670 | { | |
12671 | tem = build_string (names[i]); | |
12672 | if (NILP (Fassoc (tem, list))) | |
12673 | { | |
12674 | if (STRINGP (Vx_pixel_size_width_font_regexp) | |
f39db7ea RS |
12675 | && ((fast_c_string_match_ignore_case |
12676 | (Vx_pixel_size_width_font_regexp, names[i])) | |
dc43ef94 KH |
12677 | >= 0)) |
12678 | /* We can set the value of PIXEL_SIZE to the | |
b5210ea7 | 12679 | width of this font. */ |
dc43ef94 KH |
12680 | list = Fcons (Fcons (tem, make_number (width)), list); |
12681 | else | |
12682 | /* For the moment, width is not known. */ | |
12683 | list = Fcons (Fcons (tem, Qnil), list); | |
12684 | } | |
12685 | } | |
12686 | } | |
09c6077f KH |
12687 | if (!try_XLoadQueryFont) |
12688 | XFreeFontNames (names); | |
dc43ef94 KH |
12689 | } |
12690 | ||
b5210ea7 | 12691 | /* Now store the result in the cache. */ |
dc43ef94 | 12692 | if (f != NULL) |
8e713be6 | 12693 | XCDR (FRAME_X_DISPLAY_INFO (f)->name_list_element) |
dc43ef94 | 12694 | = Fcons (Fcons (key, list), |
8e713be6 | 12695 | XCDR (FRAME_X_DISPLAY_INFO (f)->name_list_element)); |
dc43ef94 | 12696 | |
b5210ea7 KH |
12697 | label_cached: |
12698 | if (NILP (list)) continue; /* Try the remaining alternatives. */ | |
dc43ef94 | 12699 | |
b5210ea7 KH |
12700 | newlist = second_best = Qnil; |
12701 | /* Make a list of the fonts that have the right width. */ | |
8e713be6 | 12702 | for (; CONSP (list); list = XCDR (list)) |
b5210ea7 | 12703 | { |
536f4067 RS |
12704 | int found_size; |
12705 | ||
8e713be6 | 12706 | tem = XCAR (list); |
dc43ef94 | 12707 | |
8e713be6 | 12708 | if (!CONSP (tem) || NILP (XCAR (tem))) |
b5210ea7 KH |
12709 | continue; |
12710 | if (!size) | |
12711 | { | |
8e713be6 | 12712 | newlist = Fcons (XCAR (tem), newlist); |
b5210ea7 KH |
12713 | continue; |
12714 | } | |
dc43ef94 | 12715 | |
8e713be6 | 12716 | if (!INTEGERP (XCDR (tem))) |
dc43ef94 | 12717 | { |
b5210ea7 KH |
12718 | /* Since we have not yet known the size of this font, we |
12719 | must try slow function call XLoadQueryFont. */ | |
dc43ef94 KH |
12720 | XFontStruct *thisinfo; |
12721 | ||
12722 | BLOCK_INPUT; | |
17d85edc | 12723 | count = x_catch_errors (dpy); |
dc43ef94 | 12724 | thisinfo = XLoadQueryFont (dpy, |
8e713be6 | 12725 | XSTRING (XCAR (tem))->data); |
17d85edc KH |
12726 | if (x_had_errors_p (dpy)) |
12727 | { | |
12728 | /* This error is perhaps due to insufficient memory on X | |
12729 | server. Let's just ignore it. */ | |
12730 | thisinfo = NULL; | |
12731 | x_clear_errors (dpy); | |
12732 | } | |
12733 | x_uncatch_errors (dpy, count); | |
dc43ef94 KH |
12734 | UNBLOCK_INPUT; |
12735 | ||
12736 | if (thisinfo) | |
12737 | { | |
8e713be6 | 12738 | XCDR (tem) |
536f4067 RS |
12739 | = (thisinfo->min_bounds.width == 0 |
12740 | ? make_number (0) | |
12741 | : make_number (thisinfo->max_bounds.width)); | |
dc43ef94 KH |
12742 | XFreeFont (dpy, thisinfo); |
12743 | } | |
12744 | else | |
b5210ea7 | 12745 | /* For unknown reason, the previous call of XListFont had |
06a2c219 | 12746 | returned a font which can't be opened. Record the size |
b5210ea7 | 12747 | as 0 not to try to open it again. */ |
8e713be6 | 12748 | XCDR (tem) = make_number (0); |
dc43ef94 | 12749 | } |
536f4067 | 12750 | |
8e713be6 | 12751 | found_size = XINT (XCDR (tem)); |
536f4067 | 12752 | if (found_size == size) |
8e713be6 | 12753 | newlist = Fcons (XCAR (tem), newlist); |
536f4067 | 12754 | else if (found_size > 0) |
b5210ea7 | 12755 | { |
536f4067 | 12756 | if (NILP (second_best)) |
b5210ea7 | 12757 | second_best = tem; |
536f4067 RS |
12758 | else if (found_size < size) |
12759 | { | |
8e713be6 KR |
12760 | if (XINT (XCDR (second_best)) > size |
12761 | || XINT (XCDR (second_best)) < found_size) | |
536f4067 RS |
12762 | second_best = tem; |
12763 | } | |
12764 | else | |
12765 | { | |
8e713be6 KR |
12766 | if (XINT (XCDR (second_best)) > size |
12767 | && XINT (XCDR (second_best)) > found_size) | |
536f4067 RS |
12768 | second_best = tem; |
12769 | } | |
b5210ea7 KH |
12770 | } |
12771 | } | |
12772 | if (!NILP (newlist)) | |
12773 | break; | |
12774 | else if (!NILP (second_best)) | |
12775 | { | |
8e713be6 | 12776 | newlist = Fcons (XCAR (second_best), Qnil); |
b5210ea7 | 12777 | break; |
dc43ef94 | 12778 | } |
dc43ef94 KH |
12779 | } |
12780 | ||
12781 | return newlist; | |
12782 | } | |
12783 | ||
06a2c219 GM |
12784 | |
12785 | #if GLYPH_DEBUG | |
12786 | ||
12787 | /* Check that FONT is valid on frame F. It is if it can be found in F's | |
12788 | font table. */ | |
12789 | ||
12790 | static void | |
12791 | x_check_font (f, font) | |
12792 | struct frame *f; | |
12793 | XFontStruct *font; | |
12794 | { | |
12795 | int i; | |
12796 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
12797 | ||
12798 | xassert (font != NULL); | |
12799 | ||
12800 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
12801 | if (dpyinfo->font_table[i].name | |
12802 | && font == dpyinfo->font_table[i].font) | |
12803 | break; | |
12804 | ||
12805 | xassert (i < dpyinfo->n_fonts); | |
12806 | } | |
12807 | ||
12808 | #endif /* GLYPH_DEBUG != 0 */ | |
12809 | ||
12810 | /* Set *W to the minimum width, *H to the minimum font height of FONT. | |
12811 | Note: There are (broken) X fonts out there with invalid XFontStruct | |
12812 | min_bounds contents. For example, handa@etl.go.jp reports that | |
12813 | "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts | |
12814 | have font->min_bounds.width == 0. */ | |
12815 | ||
12816 | static INLINE void | |
12817 | x_font_min_bounds (font, w, h) | |
12818 | XFontStruct *font; | |
12819 | int *w, *h; | |
12820 | { | |
12821 | *h = FONT_HEIGHT (font); | |
12822 | *w = font->min_bounds.width; | |
12823 | ||
12824 | /* Try to handle the case where FONT->min_bounds has invalid | |
12825 | contents. Since the only font known to have invalid min_bounds | |
12826 | is fixed-width, use max_bounds if min_bounds seems to be invalid. */ | |
12827 | if (*w <= 0) | |
12828 | *w = font->max_bounds.width; | |
12829 | } | |
12830 | ||
12831 | ||
12832 | /* Compute the smallest character width and smallest font height over | |
12833 | all fonts available on frame F. Set the members smallest_char_width | |
12834 | and smallest_font_height in F's x_display_info structure to | |
12835 | the values computed. Value is non-zero if smallest_font_height or | |
12836 | smallest_char_width become smaller than they were before. */ | |
12837 | ||
12838 | static int | |
12839 | x_compute_min_glyph_bounds (f) | |
12840 | struct frame *f; | |
12841 | { | |
12842 | int i; | |
12843 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
12844 | XFontStruct *font; | |
12845 | int old_width = dpyinfo->smallest_char_width; | |
12846 | int old_height = dpyinfo->smallest_font_height; | |
12847 | ||
12848 | dpyinfo->smallest_font_height = 100000; | |
12849 | dpyinfo->smallest_char_width = 100000; | |
12850 | ||
12851 | for (i = 0; i < dpyinfo->n_fonts; ++i) | |
12852 | if (dpyinfo->font_table[i].name) | |
12853 | { | |
12854 | struct font_info *fontp = dpyinfo->font_table + i; | |
12855 | int w, h; | |
12856 | ||
12857 | font = (XFontStruct *) fontp->font; | |
12858 | xassert (font != (XFontStruct *) ~0); | |
12859 | x_font_min_bounds (font, &w, &h); | |
12860 | ||
12861 | dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h); | |
12862 | dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w); | |
12863 | } | |
12864 | ||
12865 | xassert (dpyinfo->smallest_char_width > 0 | |
12866 | && dpyinfo->smallest_font_height > 0); | |
12867 | ||
12868 | return (dpyinfo->n_fonts == 1 | |
12869 | || dpyinfo->smallest_char_width < old_width | |
12870 | || dpyinfo->smallest_font_height < old_height); | |
12871 | } | |
12872 | ||
12873 | ||
dc43ef94 KH |
12874 | /* Load font named FONTNAME of the size SIZE for frame F, and return a |
12875 | pointer to the structure font_info while allocating it dynamically. | |
12876 | If SIZE is 0, load any size of font. | |
12877 | If loading is failed, return NULL. */ | |
12878 | ||
12879 | struct font_info * | |
12880 | x_load_font (f, fontname, size) | |
12881 | struct frame *f; | |
12882 | register char *fontname; | |
12883 | int size; | |
12884 | { | |
12885 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
12886 | Lisp_Object font_names; | |
d645aaa4 | 12887 | int count; |
dc43ef94 KH |
12888 | |
12889 | /* Get a list of all the fonts that match this name. Once we | |
12890 | have a list of matching fonts, we compare them against the fonts | |
12891 | we already have by comparing names. */ | |
09c6077f | 12892 | font_names = x_list_fonts (f, build_string (fontname), size, 1); |
dc43ef94 KH |
12893 | |
12894 | if (!NILP (font_names)) | |
12895 | { | |
12896 | Lisp_Object tail; | |
12897 | int i; | |
12898 | ||
12899 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
8e713be6 | 12900 | for (tail = font_names; CONSP (tail); tail = XCDR (tail)) |
06a2c219 GM |
12901 | if (dpyinfo->font_table[i].name |
12902 | && (!strcmp (dpyinfo->font_table[i].name, | |
8e713be6 | 12903 | XSTRING (XCAR (tail))->data) |
06a2c219 | 12904 | || !strcmp (dpyinfo->font_table[i].full_name, |
8e713be6 | 12905 | XSTRING (XCAR (tail))->data))) |
dc43ef94 KH |
12906 | return (dpyinfo->font_table + i); |
12907 | } | |
12908 | ||
12909 | /* Load the font and add it to the table. */ | |
12910 | { | |
12911 | char *full_name; | |
12912 | XFontStruct *font; | |
12913 | struct font_info *fontp; | |
12914 | unsigned long value; | |
06a2c219 | 12915 | int i; |
dc43ef94 | 12916 | |
2da424f1 KH |
12917 | /* If we have found fonts by x_list_font, load one of them. If |
12918 | not, we still try to load a font by the name given as FONTNAME | |
12919 | because XListFonts (called in x_list_font) of some X server has | |
12920 | a bug of not finding a font even if the font surely exists and | |
12921 | is loadable by XLoadQueryFont. */ | |
e1d6d5b9 | 12922 | if (size > 0 && !NILP (font_names)) |
8e713be6 | 12923 | fontname = (char *) XSTRING (XCAR (font_names))->data; |
dc43ef94 KH |
12924 | |
12925 | BLOCK_INPUT; | |
d645aaa4 | 12926 | count = x_catch_errors (FRAME_X_DISPLAY (f)); |
dc43ef94 | 12927 | font = (XFontStruct *) XLoadQueryFont (FRAME_X_DISPLAY (f), fontname); |
d645aaa4 KH |
12928 | if (x_had_errors_p (FRAME_X_DISPLAY (f))) |
12929 | { | |
12930 | /* This error is perhaps due to insufficient memory on X | |
12931 | server. Let's just ignore it. */ | |
12932 | font = NULL; | |
12933 | x_clear_errors (FRAME_X_DISPLAY (f)); | |
12934 | } | |
12935 | x_uncatch_errors (FRAME_X_DISPLAY (f), count); | |
dc43ef94 | 12936 | UNBLOCK_INPUT; |
b5210ea7 | 12937 | if (!font) |
dc43ef94 KH |
12938 | return NULL; |
12939 | ||
06a2c219 GM |
12940 | /* Find a free slot in the font table. */ |
12941 | for (i = 0; i < dpyinfo->n_fonts; ++i) | |
12942 | if (dpyinfo->font_table[i].name == NULL) | |
12943 | break; | |
12944 | ||
12945 | /* If no free slot found, maybe enlarge the font table. */ | |
12946 | if (i == dpyinfo->n_fonts | |
12947 | && dpyinfo->n_fonts == dpyinfo->font_table_size) | |
dc43ef94 | 12948 | { |
06a2c219 GM |
12949 | int sz; |
12950 | dpyinfo->font_table_size = max (16, 2 * dpyinfo->font_table_size); | |
12951 | sz = dpyinfo->font_table_size * sizeof *dpyinfo->font_table; | |
dc43ef94 | 12952 | dpyinfo->font_table |
06a2c219 | 12953 | = (struct font_info *) xrealloc (dpyinfo->font_table, sz); |
dc43ef94 KH |
12954 | } |
12955 | ||
06a2c219 GM |
12956 | fontp = dpyinfo->font_table + i; |
12957 | if (i == dpyinfo->n_fonts) | |
12958 | ++dpyinfo->n_fonts; | |
dc43ef94 KH |
12959 | |
12960 | /* Now fill in the slots of *FONTP. */ | |
12961 | BLOCK_INPUT; | |
12962 | fontp->font = font; | |
06a2c219 | 12963 | fontp->font_idx = i; |
dc43ef94 KH |
12964 | fontp->name = (char *) xmalloc (strlen (fontname) + 1); |
12965 | bcopy (fontname, fontp->name, strlen (fontname) + 1); | |
12966 | ||
12967 | /* Try to get the full name of FONT. Put it in FULL_NAME. */ | |
12968 | full_name = 0; | |
12969 | if (XGetFontProperty (font, XA_FONT, &value)) | |
12970 | { | |
12971 | char *name = (char *) XGetAtomName (FRAME_X_DISPLAY (f), (Atom) value); | |
12972 | char *p = name; | |
12973 | int dashes = 0; | |
12974 | ||
12975 | /* Count the number of dashes in the "full name". | |
12976 | If it is too few, this isn't really the font's full name, | |
12977 | so don't use it. | |
12978 | In X11R4, the fonts did not come with their canonical names | |
12979 | stored in them. */ | |
12980 | while (*p) | |
12981 | { | |
12982 | if (*p == '-') | |
12983 | dashes++; | |
12984 | p++; | |
12985 | } | |
12986 | ||
12987 | if (dashes >= 13) | |
12988 | { | |
12989 | full_name = (char *) xmalloc (p - name + 1); | |
12990 | bcopy (name, full_name, p - name + 1); | |
12991 | } | |
12992 | ||
12993 | XFree (name); | |
12994 | } | |
12995 | ||
12996 | if (full_name != 0) | |
12997 | fontp->full_name = full_name; | |
12998 | else | |
12999 | fontp->full_name = fontp->name; | |
13000 | ||
13001 | fontp->size = font->max_bounds.width; | |
d5749adb KH |
13002 | fontp->height = FONT_HEIGHT (font); |
13003 | { | |
13004 | /* For some font, ascent and descent in max_bounds field is | |
13005 | larger than the above value. */ | |
13006 | int max_height = font->max_bounds.ascent + font->max_bounds.descent; | |
13007 | if (max_height > fontp->height) | |
74848a96 | 13008 | fontp->height = max_height; |
d5749adb | 13009 | } |
dc43ef94 | 13010 | |
2da424f1 KH |
13011 | if (NILP (font_names)) |
13012 | { | |
13013 | /* We come here because of a bug of XListFonts mentioned at | |
13014 | the head of this block. Let's store this information in | |
13015 | the cache for x_list_fonts. */ | |
13016 | Lisp_Object lispy_name = build_string (fontname); | |
13017 | Lisp_Object lispy_full_name = build_string (fontp->full_name); | |
13018 | ||
8e713be6 | 13019 | XCDR (dpyinfo->name_list_element) |
2da424f1 KH |
13020 | = Fcons (Fcons (Fcons (lispy_name, make_number (256)), |
13021 | Fcons (Fcons (lispy_full_name, | |
13022 | make_number (fontp->size)), | |
13023 | Qnil)), | |
8e713be6 | 13024 | XCDR (dpyinfo->name_list_element)); |
2da424f1 | 13025 | if (full_name) |
8e713be6 | 13026 | XCDR (dpyinfo->name_list_element) |
2da424f1 KH |
13027 | = Fcons (Fcons (Fcons (lispy_full_name, make_number (256)), |
13028 | Fcons (Fcons (lispy_full_name, | |
13029 | make_number (fontp->size)), | |
13030 | Qnil)), | |
8e713be6 | 13031 | XCDR (dpyinfo->name_list_element)); |
2da424f1 KH |
13032 | } |
13033 | ||
dc43ef94 KH |
13034 | /* The slot `encoding' specifies how to map a character |
13035 | code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to | |
ee569018 KH |
13036 | the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or |
13037 | (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, | |
8ff102bd | 13038 | 2:0xA020..0xFF7F). For the moment, we don't know which charset |
06a2c219 | 13039 | uses this font. So, we set information in fontp->encoding[1] |
8ff102bd RS |
13040 | which is never used by any charset. If mapping can't be |
13041 | decided, set FONT_ENCODING_NOT_DECIDED. */ | |
dc43ef94 KH |
13042 | fontp->encoding[1] |
13043 | = (font->max_byte1 == 0 | |
13044 | /* 1-byte font */ | |
13045 | ? (font->min_char_or_byte2 < 0x80 | |
13046 | ? (font->max_char_or_byte2 < 0x80 | |
13047 | ? 0 /* 0x20..0x7F */ | |
8ff102bd | 13048 | : FONT_ENCODING_NOT_DECIDED) /* 0x20..0xFF */ |
dc43ef94 KH |
13049 | : 1) /* 0xA0..0xFF */ |
13050 | /* 2-byte font */ | |
13051 | : (font->min_byte1 < 0x80 | |
13052 | ? (font->max_byte1 < 0x80 | |
13053 | ? (font->min_char_or_byte2 < 0x80 | |
13054 | ? (font->max_char_or_byte2 < 0x80 | |
13055 | ? 0 /* 0x2020..0x7F7F */ | |
8ff102bd | 13056 | : FONT_ENCODING_NOT_DECIDED) /* 0x2020..0x7FFF */ |
dc43ef94 | 13057 | : 3) /* 0x20A0..0x7FFF */ |
8ff102bd | 13058 | : FONT_ENCODING_NOT_DECIDED) /* 0x20??..0xA0?? */ |
dc43ef94 KH |
13059 | : (font->min_char_or_byte2 < 0x80 |
13060 | ? (font->max_char_or_byte2 < 0x80 | |
13061 | ? 2 /* 0xA020..0xFF7F */ | |
8ff102bd | 13062 | : FONT_ENCODING_NOT_DECIDED) /* 0xA020..0xFFFF */ |
dc43ef94 KH |
13063 | : 1))); /* 0xA0A0..0xFFFF */ |
13064 | ||
13065 | fontp->baseline_offset | |
13066 | = (XGetFontProperty (font, dpyinfo->Xatom_MULE_BASELINE_OFFSET, &value) | |
13067 | ? (long) value : 0); | |
13068 | fontp->relative_compose | |
13069 | = (XGetFontProperty (font, dpyinfo->Xatom_MULE_RELATIVE_COMPOSE, &value) | |
13070 | ? (long) value : 0); | |
f78798df KH |
13071 | fontp->default_ascent |
13072 | = (XGetFontProperty (font, dpyinfo->Xatom_MULE_DEFAULT_ASCENT, &value) | |
13073 | ? (long) value : 0); | |
dc43ef94 | 13074 | |
06a2c219 GM |
13075 | /* Set global flag fonts_changed_p to non-zero if the font loaded |
13076 | has a character with a smaller width than any other character | |
13077 | before, or if the font loaded has a smalle>r height than any | |
13078 | other font loaded before. If this happens, it will make a | |
13079 | glyph matrix reallocation necessary. */ | |
13080 | fonts_changed_p = x_compute_min_glyph_bounds (f); | |
dc43ef94 | 13081 | UNBLOCK_INPUT; |
dc43ef94 KH |
13082 | return fontp; |
13083 | } | |
13084 | } | |
13085 | ||
06a2c219 GM |
13086 | |
13087 | /* Return a pointer to struct font_info of a font named FONTNAME for | |
13088 | frame F. If no such font is loaded, return NULL. */ | |
13089 | ||
dc43ef94 KH |
13090 | struct font_info * |
13091 | x_query_font (f, fontname) | |
13092 | struct frame *f; | |
13093 | register char *fontname; | |
13094 | { | |
13095 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
13096 | int i; | |
13097 | ||
13098 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
06a2c219 GM |
13099 | if (dpyinfo->font_table[i].name |
13100 | && (!strcmp (dpyinfo->font_table[i].name, fontname) | |
13101 | || !strcmp (dpyinfo->font_table[i].full_name, fontname))) | |
dc43ef94 KH |
13102 | return (dpyinfo->font_table + i); |
13103 | return NULL; | |
13104 | } | |
13105 | ||
06a2c219 GM |
13106 | |
13107 | /* Find a CCL program for a font specified by FONTP, and set the member | |
a6582676 KH |
13108 | `encoder' of the structure. */ |
13109 | ||
13110 | void | |
13111 | x_find_ccl_program (fontp) | |
13112 | struct font_info *fontp; | |
13113 | { | |
a42f54e6 | 13114 | Lisp_Object list, elt; |
a6582676 | 13115 | |
f9b5db02 | 13116 | elt = Qnil; |
8e713be6 | 13117 | for (list = Vfont_ccl_encoder_alist; CONSP (list); list = XCDR (list)) |
a6582676 | 13118 | { |
8e713be6 | 13119 | elt = XCAR (list); |
a6582676 | 13120 | if (CONSP (elt) |
8e713be6 KR |
13121 | && STRINGP (XCAR (elt)) |
13122 | && (fast_c_string_match_ignore_case (XCAR (elt), fontp->name) | |
a6582676 | 13123 | >= 0)) |
a42f54e6 KH |
13124 | break; |
13125 | } | |
f9b5db02 | 13126 | |
a42f54e6 KH |
13127 | if (! NILP (list)) |
13128 | { | |
d27f8ca7 KH |
13129 | struct ccl_program *ccl |
13130 | = (struct ccl_program *) xmalloc (sizeof (struct ccl_program)); | |
a42f54e6 | 13131 | |
8e713be6 | 13132 | if (setup_ccl_program (ccl, XCDR (elt)) < 0) |
a42f54e6 KH |
13133 | xfree (ccl); |
13134 | else | |
13135 | fontp->font_encoder = ccl; | |
a6582676 KH |
13136 | } |
13137 | } | |
13138 | ||
06a2c219 | 13139 | |
dc43ef94 | 13140 | \f |
06a2c219 GM |
13141 | /*********************************************************************** |
13142 | Initialization | |
13143 | ***********************************************************************/ | |
f451eb13 | 13144 | |
3afe33e7 RS |
13145 | #ifdef USE_X_TOOLKIT |
13146 | static XrmOptionDescRec emacs_options[] = { | |
13147 | {"-geometry", ".geometry", XrmoptionSepArg, NULL}, | |
13148 | {"-iconic", ".iconic", XrmoptionNoArg, (XtPointer) "yes"}, | |
13149 | ||
13150 | {"-internal-border-width", "*EmacsScreen.internalBorderWidth", | |
13151 | XrmoptionSepArg, NULL}, | |
13152 | {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg, NULL}, | |
13153 | ||
13154 | {"-T", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
13155 | {"-wn", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
13156 | {"-title", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
13157 | {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg, (XtPointer) NULL}, | |
13158 | {"-in", "*EmacsShell.iconName", XrmoptionSepArg, (XtPointer) NULL}, | |
13159 | {"-mc", "*pointerColor", XrmoptionSepArg, (XtPointer) NULL}, | |
13160 | {"-cr", "*cursorColor", XrmoptionSepArg, (XtPointer) NULL} | |
13161 | }; | |
13162 | #endif /* USE_X_TOOLKIT */ | |
13163 | ||
7a13e894 RS |
13164 | static int x_initialized; |
13165 | ||
29b38361 KH |
13166 | #ifdef MULTI_KBOARD |
13167 | /* Test whether two display-name strings agree up to the dot that separates | |
13168 | the screen number from the server number. */ | |
13169 | static int | |
13170 | same_x_server (name1, name2) | |
13171 | char *name1, *name2; | |
13172 | { | |
13173 | int seen_colon = 0; | |
cf591cc1 RS |
13174 | unsigned char *system_name = XSTRING (Vsystem_name)->data; |
13175 | int system_name_length = strlen (system_name); | |
13176 | int length_until_period = 0; | |
13177 | ||
13178 | while (system_name[length_until_period] != 0 | |
13179 | && system_name[length_until_period] != '.') | |
13180 | length_until_period++; | |
13181 | ||
13182 | /* Treat `unix' like an empty host name. */ | |
13183 | if (! strncmp (name1, "unix:", 5)) | |
13184 | name1 += 4; | |
13185 | if (! strncmp (name2, "unix:", 5)) | |
13186 | name2 += 4; | |
13187 | /* Treat this host's name like an empty host name. */ | |
13188 | if (! strncmp (name1, system_name, system_name_length) | |
13189 | && name1[system_name_length] == ':') | |
13190 | name1 += system_name_length; | |
13191 | if (! strncmp (name2, system_name, system_name_length) | |
13192 | && name2[system_name_length] == ':') | |
13193 | name2 += system_name_length; | |
13194 | /* Treat this host's domainless name like an empty host name. */ | |
13195 | if (! strncmp (name1, system_name, length_until_period) | |
13196 | && name1[length_until_period] == ':') | |
13197 | name1 += length_until_period; | |
13198 | if (! strncmp (name2, system_name, length_until_period) | |
13199 | && name2[length_until_period] == ':') | |
13200 | name2 += length_until_period; | |
13201 | ||
29b38361 KH |
13202 | for (; *name1 != '\0' && *name1 == *name2; name1++, name2++) |
13203 | { | |
13204 | if (*name1 == ':') | |
13205 | seen_colon++; | |
13206 | if (seen_colon && *name1 == '.') | |
13207 | return 1; | |
13208 | } | |
13209 | return (seen_colon | |
13210 | && (*name1 == '.' || *name1 == '\0') | |
13211 | && (*name2 == '.' || *name2 == '\0')); | |
13212 | } | |
13213 | #endif | |
13214 | ||
334208b7 | 13215 | struct x_display_info * |
1f8255f2 | 13216 | x_term_init (display_name, xrm_option, resource_name) |
334208b7 | 13217 | Lisp_Object display_name; |
1f8255f2 RS |
13218 | char *xrm_option; |
13219 | char *resource_name; | |
dc6f92b8 | 13220 | { |
334208b7 | 13221 | int connection; |
7a13e894 | 13222 | Display *dpy; |
334208b7 RS |
13223 | struct x_display_info *dpyinfo; |
13224 | XrmDatabase xrdb; | |
13225 | ||
60439948 KH |
13226 | BLOCK_INPUT; |
13227 | ||
7a13e894 RS |
13228 | if (!x_initialized) |
13229 | { | |
13230 | x_initialize (); | |
13231 | x_initialized = 1; | |
13232 | } | |
dc6f92b8 | 13233 | |
3afe33e7 | 13234 | #ifdef USE_X_TOOLKIT |
2d7fc7e8 RS |
13235 | /* weiner@footloose.sps.mot.com reports that this causes |
13236 | errors with X11R5: | |
13237 | X protocol error: BadAtom (invalid Atom parameter) | |
13238 | on protocol request 18skiloaf. | |
13239 | So let's not use it until R6. */ | |
13240 | #ifdef HAVE_X11XTR6 | |
bdcd49ba RS |
13241 | XtSetLanguageProc (NULL, NULL, NULL); |
13242 | #endif | |
13243 | ||
7f9c7f94 RS |
13244 | { |
13245 | int argc = 0; | |
13246 | char *argv[3]; | |
13247 | ||
13248 | argv[0] = ""; | |
13249 | argc = 1; | |
13250 | if (xrm_option) | |
13251 | { | |
13252 | argv[argc++] = "-xrm"; | |
13253 | argv[argc++] = xrm_option; | |
13254 | } | |
13255 | dpy = XtOpenDisplay (Xt_app_con, XSTRING (display_name)->data, | |
13256 | resource_name, EMACS_CLASS, | |
13257 | emacs_options, XtNumber (emacs_options), | |
13258 | &argc, argv); | |
39d8bb4d KH |
13259 | |
13260 | #ifdef HAVE_X11XTR6 | |
10537cb1 | 13261 | /* I think this is to compensate for XtSetLanguageProc. */ |
71f8198a | 13262 | fixup_locale (); |
39d8bb4d | 13263 | #endif |
7f9c7f94 | 13264 | } |
3afe33e7 RS |
13265 | |
13266 | #else /* not USE_X_TOOLKIT */ | |
bdcd49ba RS |
13267 | #ifdef HAVE_X11R5 |
13268 | XSetLocaleModifiers (""); | |
13269 | #endif | |
7a13e894 | 13270 | dpy = XOpenDisplay (XSTRING (display_name)->data); |
3afe33e7 | 13271 | #endif /* not USE_X_TOOLKIT */ |
334208b7 | 13272 | |
7a13e894 RS |
13273 | /* Detect failure. */ |
13274 | if (dpy == 0) | |
60439948 KH |
13275 | { |
13276 | UNBLOCK_INPUT; | |
13277 | return 0; | |
13278 | } | |
7a13e894 RS |
13279 | |
13280 | /* We have definitely succeeded. Record the new connection. */ | |
13281 | ||
13282 | dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info)); | |
13283 | ||
29b38361 KH |
13284 | #ifdef MULTI_KBOARD |
13285 | { | |
13286 | struct x_display_info *share; | |
13287 | Lisp_Object tail; | |
13288 | ||
13289 | for (share = x_display_list, tail = x_display_name_list; share; | |
8e713be6 KR |
13290 | share = share->next, tail = XCDR (tail)) |
13291 | if (same_x_server (XSTRING (XCAR (XCAR (tail)))->data, | |
29b38361 KH |
13292 | XSTRING (display_name)->data)) |
13293 | break; | |
13294 | if (share) | |
13295 | dpyinfo->kboard = share->kboard; | |
13296 | else | |
13297 | { | |
13298 | dpyinfo->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); | |
13299 | init_kboard (dpyinfo->kboard); | |
59e755be KH |
13300 | if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound)) |
13301 | { | |
13302 | char *vendor = ServerVendor (dpy); | |
9b6ed9f3 | 13303 | UNBLOCK_INPUT; |
59e755be KH |
13304 | dpyinfo->kboard->Vsystem_key_alist |
13305 | = call1 (Qvendor_specific_keysyms, | |
13306 | build_string (vendor ? vendor : "")); | |
9b6ed9f3 | 13307 | BLOCK_INPUT; |
59e755be KH |
13308 | } |
13309 | ||
29b38361 KH |
13310 | dpyinfo->kboard->next_kboard = all_kboards; |
13311 | all_kboards = dpyinfo->kboard; | |
0ad5446c KH |
13312 | /* Don't let the initial kboard remain current longer than necessary. |
13313 | That would cause problems if a file loaded on startup tries to | |
06a2c219 | 13314 | prompt in the mini-buffer. */ |
0ad5446c KH |
13315 | if (current_kboard == initial_kboard) |
13316 | current_kboard = dpyinfo->kboard; | |
29b38361 KH |
13317 | } |
13318 | dpyinfo->kboard->reference_count++; | |
13319 | } | |
b9737ad3 KH |
13320 | #endif |
13321 | ||
7a13e894 RS |
13322 | /* Put this display on the chain. */ |
13323 | dpyinfo->next = x_display_list; | |
13324 | x_display_list = dpyinfo; | |
13325 | ||
13326 | /* Put it on x_display_name_list as well, to keep them parallel. */ | |
13327 | x_display_name_list = Fcons (Fcons (display_name, Qnil), | |
13328 | x_display_name_list); | |
8e713be6 | 13329 | dpyinfo->name_list_element = XCAR (x_display_name_list); |
7a13e894 RS |
13330 | |
13331 | dpyinfo->display = dpy; | |
dc6f92b8 | 13332 | |
dc6f92b8 | 13333 | #if 0 |
7a13e894 | 13334 | XSetAfterFunction (x_current_display, x_trace_wire); |
c118dd06 | 13335 | #endif /* ! 0 */ |
7a13e894 RS |
13336 | |
13337 | dpyinfo->x_id_name | |
fc932ac6 RS |
13338 | = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name)) |
13339 | + STRING_BYTES (XSTRING (Vsystem_name)) | |
7a13e894 RS |
13340 | + 2); |
13341 | sprintf (dpyinfo->x_id_name, "%s@%s", | |
13342 | XSTRING (Vinvocation_name)->data, XSTRING (Vsystem_name)->data); | |
28430d3c JB |
13343 | |
13344 | /* Figure out which modifier bits mean what. */ | |
334208b7 | 13345 | x_find_modifier_meanings (dpyinfo); |
f451eb13 | 13346 | |
ab648270 | 13347 | /* Get the scroll bar cursor. */ |
7a13e894 | 13348 | dpyinfo->vertical_scroll_bar_cursor |
334208b7 | 13349 | = XCreateFontCursor (dpyinfo->display, XC_sb_v_double_arrow); |
f451eb13 | 13350 | |
334208b7 RS |
13351 | xrdb = x_load_resources (dpyinfo->display, xrm_option, |
13352 | resource_name, EMACS_CLASS); | |
13353 | #ifdef HAVE_XRMSETDATABASE | |
13354 | XrmSetDatabase (dpyinfo->display, xrdb); | |
13355 | #else | |
13356 | dpyinfo->display->db = xrdb; | |
13357 | #endif | |
547d9db8 | 13358 | /* Put the rdb where we can find it in a way that works on |
7a13e894 RS |
13359 | all versions. */ |
13360 | dpyinfo->xrdb = xrdb; | |
334208b7 RS |
13361 | |
13362 | dpyinfo->screen = ScreenOfDisplay (dpyinfo->display, | |
13363 | DefaultScreen (dpyinfo->display)); | |
5ff67d81 | 13364 | select_visual (dpyinfo); |
43bd1b2b | 13365 | dpyinfo->cmap = DefaultColormapOfScreen (dpyinfo->screen); |
334208b7 RS |
13366 | dpyinfo->height = HeightOfScreen (dpyinfo->screen); |
13367 | dpyinfo->width = WidthOfScreen (dpyinfo->screen); | |
13368 | dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen); | |
13369 | dpyinfo->grabbed = 0; | |
13370 | dpyinfo->reference_count = 0; | |
13371 | dpyinfo->icon_bitmap_id = -1; | |
06a2c219 | 13372 | dpyinfo->font_table = NULL; |
7a13e894 RS |
13373 | dpyinfo->n_fonts = 0; |
13374 | dpyinfo->font_table_size = 0; | |
13375 | dpyinfo->bitmaps = 0; | |
13376 | dpyinfo->bitmaps_size = 0; | |
13377 | dpyinfo->bitmaps_last = 0; | |
13378 | dpyinfo->scratch_cursor_gc = 0; | |
13379 | dpyinfo->mouse_face_mouse_frame = 0; | |
13380 | dpyinfo->mouse_face_deferred_gc = 0; | |
13381 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
13382 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
06a2c219 | 13383 | dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; |
7a13e894 RS |
13384 | dpyinfo->mouse_face_window = Qnil; |
13385 | dpyinfo->mouse_face_mouse_x = dpyinfo->mouse_face_mouse_y = 0; | |
13386 | dpyinfo->mouse_face_defer = 0; | |
0f941935 KH |
13387 | dpyinfo->x_focus_frame = 0; |
13388 | dpyinfo->x_focus_event_frame = 0; | |
13389 | dpyinfo->x_highlight_frame = 0; | |
06a2c219 | 13390 | dpyinfo->image_cache = make_image_cache (); |
334208b7 | 13391 | |
43bd1b2b | 13392 | /* See if a private colormap is requested. */ |
5ff67d81 GM |
13393 | if (dpyinfo->visual == DefaultVisualOfScreen (dpyinfo->screen)) |
13394 | { | |
13395 | if (dpyinfo->visual->class == PseudoColor) | |
13396 | { | |
13397 | Lisp_Object value; | |
13398 | value = display_x_get_resource (dpyinfo, | |
13399 | build_string ("privateColormap"), | |
13400 | build_string ("PrivateColormap"), | |
13401 | Qnil, Qnil); | |
13402 | if (STRINGP (value) | |
13403 | && (!strcmp (XSTRING (value)->data, "true") | |
13404 | || !strcmp (XSTRING (value)->data, "on"))) | |
13405 | dpyinfo->cmap = XCopyColormapAndFree (dpyinfo->display, dpyinfo->cmap); | |
13406 | } | |
43bd1b2b | 13407 | } |
5ff67d81 GM |
13408 | else |
13409 | dpyinfo->cmap = XCreateColormap (dpyinfo->display, dpyinfo->root_window, | |
13410 | dpyinfo->visual, AllocNone); | |
43bd1b2b | 13411 | |
06a2c219 GM |
13412 | { |
13413 | int screen_number = XScreenNumberOfScreen (dpyinfo->screen); | |
13414 | double pixels = DisplayHeight (dpyinfo->display, screen_number); | |
13415 | double mm = DisplayHeightMM (dpyinfo->display, screen_number); | |
13416 | dpyinfo->resy = pixels * 25.4 / mm; | |
13417 | pixels = DisplayWidth (dpyinfo->display, screen_number); | |
13418 | mm = DisplayWidthMM (dpyinfo->display, screen_number); | |
13419 | dpyinfo->resx = pixels * 25.4 / mm; | |
13420 | } | |
13421 | ||
334208b7 RS |
13422 | dpyinfo->Xatom_wm_protocols |
13423 | = XInternAtom (dpyinfo->display, "WM_PROTOCOLS", False); | |
13424 | dpyinfo->Xatom_wm_take_focus | |
13425 | = XInternAtom (dpyinfo->display, "WM_TAKE_FOCUS", False); | |
13426 | dpyinfo->Xatom_wm_save_yourself | |
13427 | = XInternAtom (dpyinfo->display, "WM_SAVE_YOURSELF", False); | |
13428 | dpyinfo->Xatom_wm_delete_window | |
13429 | = XInternAtom (dpyinfo->display, "WM_DELETE_WINDOW", False); | |
13430 | dpyinfo->Xatom_wm_change_state | |
13431 | = XInternAtom (dpyinfo->display, "WM_CHANGE_STATE", False); | |
13432 | dpyinfo->Xatom_wm_configure_denied | |
13433 | = XInternAtom (dpyinfo->display, "WM_CONFIGURE_DENIED", False); | |
13434 | dpyinfo->Xatom_wm_window_moved | |
13435 | = XInternAtom (dpyinfo->display, "WM_MOVED", False); | |
13436 | dpyinfo->Xatom_editres | |
13437 | = XInternAtom (dpyinfo->display, "Editres", False); | |
13438 | dpyinfo->Xatom_CLIPBOARD | |
13439 | = XInternAtom (dpyinfo->display, "CLIPBOARD", False); | |
13440 | dpyinfo->Xatom_TIMESTAMP | |
13441 | = XInternAtom (dpyinfo->display, "TIMESTAMP", False); | |
13442 | dpyinfo->Xatom_TEXT | |
13443 | = XInternAtom (dpyinfo->display, "TEXT", False); | |
dc43ef94 KH |
13444 | dpyinfo->Xatom_COMPOUND_TEXT |
13445 | = XInternAtom (dpyinfo->display, "COMPOUND_TEXT", False); | |
334208b7 RS |
13446 | dpyinfo->Xatom_DELETE |
13447 | = XInternAtom (dpyinfo->display, "DELETE", False); | |
13448 | dpyinfo->Xatom_MULTIPLE | |
13449 | = XInternAtom (dpyinfo->display, "MULTIPLE", False); | |
13450 | dpyinfo->Xatom_INCR | |
13451 | = XInternAtom (dpyinfo->display, "INCR", False); | |
13452 | dpyinfo->Xatom_EMACS_TMP | |
13453 | = XInternAtom (dpyinfo->display, "_EMACS_TMP_", False); | |
13454 | dpyinfo->Xatom_TARGETS | |
13455 | = XInternAtom (dpyinfo->display, "TARGETS", False); | |
13456 | dpyinfo->Xatom_NULL | |
13457 | = XInternAtom (dpyinfo->display, "NULL", False); | |
13458 | dpyinfo->Xatom_ATOM_PAIR | |
13459 | = XInternAtom (dpyinfo->display, "ATOM_PAIR", False); | |
dc43ef94 KH |
13460 | /* For properties of font. */ |
13461 | dpyinfo->Xatom_PIXEL_SIZE | |
13462 | = XInternAtom (dpyinfo->display, "PIXEL_SIZE", False); | |
13463 | dpyinfo->Xatom_MULE_BASELINE_OFFSET | |
13464 | = XInternAtom (dpyinfo->display, "_MULE_BASELINE_OFFSET", False); | |
13465 | dpyinfo->Xatom_MULE_RELATIVE_COMPOSE | |
13466 | = XInternAtom (dpyinfo->display, "_MULE_RELATIVE_COMPOSE", False); | |
f78798df KH |
13467 | dpyinfo->Xatom_MULE_DEFAULT_ASCENT |
13468 | = XInternAtom (dpyinfo->display, "_MULE_DEFAULT_ASCENT", False); | |
334208b7 | 13469 | |
06a2c219 GM |
13470 | /* Ghostscript support. */ |
13471 | dpyinfo->Xatom_PAGE = XInternAtom (dpyinfo->display, "PAGE", False); | |
13472 | dpyinfo->Xatom_DONE = XInternAtom (dpyinfo->display, "DONE", False); | |
13473 | ||
13474 | dpyinfo->Xatom_Scrollbar = XInternAtom (dpyinfo->display, "SCROLLBAR", | |
13475 | False); | |
13476 | ||
547d9db8 KH |
13477 | dpyinfo->cut_buffers_initialized = 0; |
13478 | ||
334208b7 RS |
13479 | connection = ConnectionNumber (dpyinfo->display); |
13480 | dpyinfo->connection = connection; | |
13481 | ||
dc43ef94 | 13482 | { |
5d7cc324 RS |
13483 | char null_bits[1]; |
13484 | ||
13485 | null_bits[0] = 0x00; | |
dc43ef94 KH |
13486 | |
13487 | dpyinfo->null_pixel | |
13488 | = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window, | |
13489 | null_bits, 1, 1, (long) 0, (long) 0, | |
13490 | 1); | |
13491 | } | |
13492 | ||
06a2c219 GM |
13493 | { |
13494 | extern int gray_bitmap_width, gray_bitmap_height; | |
13495 | extern unsigned char *gray_bitmap_bits; | |
13496 | dpyinfo->gray | |
13497 | = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window, | |
13498 | gray_bitmap_bits, | |
13499 | gray_bitmap_width, gray_bitmap_height, | |
13500 | (unsigned long) 1, (unsigned long) 0, 1); | |
13501 | } | |
13502 | ||
f5d11644 GM |
13503 | #ifdef HAVE_X_I18N |
13504 | xim_initialize (dpyinfo, resource_name); | |
13505 | #endif | |
13506 | ||
87485d6f MW |
13507 | #ifdef subprocesses |
13508 | /* This is only needed for distinguishing keyboard and process input. */ | |
334208b7 | 13509 | if (connection != 0) |
7a13e894 | 13510 | add_keyboard_wait_descriptor (connection); |
87485d6f | 13511 | #endif |
6d4238f3 | 13512 | |
041b69ac | 13513 | #ifndef F_SETOWN_BUG |
dc6f92b8 | 13514 | #ifdef F_SETOWN |
dc6f92b8 | 13515 | #ifdef F_SETOWN_SOCK_NEG |
61c3ce62 | 13516 | /* stdin is a socket here */ |
334208b7 | 13517 | fcntl (connection, F_SETOWN, -getpid ()); |
c118dd06 | 13518 | #else /* ! defined (F_SETOWN_SOCK_NEG) */ |
334208b7 | 13519 | fcntl (connection, F_SETOWN, getpid ()); |
c118dd06 JB |
13520 | #endif /* ! defined (F_SETOWN_SOCK_NEG) */ |
13521 | #endif /* ! defined (F_SETOWN) */ | |
041b69ac | 13522 | #endif /* F_SETOWN_BUG */ |
dc6f92b8 JB |
13523 | |
13524 | #ifdef SIGIO | |
eee20f6a KH |
13525 | if (interrupt_input) |
13526 | init_sigio (connection); | |
c118dd06 | 13527 | #endif /* ! defined (SIGIO) */ |
dc6f92b8 | 13528 | |
51b592fb | 13529 | #ifdef USE_LUCID |
f8c39f51 | 13530 | #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */ |
51b592fb RS |
13531 | /* Make sure that we have a valid font for dialog boxes |
13532 | so that Xt does not crash. */ | |
13533 | { | |
13534 | Display *dpy = dpyinfo->display; | |
13535 | XrmValue d, fr, to; | |
13536 | Font font; | |
e99db5a1 | 13537 | int count; |
51b592fb RS |
13538 | |
13539 | d.addr = (XPointer)&dpy; | |
13540 | d.size = sizeof (Display *); | |
13541 | fr.addr = XtDefaultFont; | |
13542 | fr.size = sizeof (XtDefaultFont); | |
13543 | to.size = sizeof (Font *); | |
13544 | to.addr = (XPointer)&font; | |
e99db5a1 | 13545 | count = x_catch_errors (dpy); |
51b592fb RS |
13546 | if (!XtCallConverter (dpy, XtCvtStringToFont, &d, 1, &fr, &to, NULL)) |
13547 | abort (); | |
13548 | if (x_had_errors_p (dpy) || !XQueryFont (dpy, font)) | |
13549 | XrmPutLineResource (&xrdb, "Emacs.dialog.*.font: 9x15"); | |
e99db5a1 | 13550 | x_uncatch_errors (dpy, count); |
51b592fb RS |
13551 | } |
13552 | #endif | |
f8c39f51 | 13553 | #endif |
51b592fb | 13554 | |
34e23e5a GM |
13555 | /* See if we should run in synchronous mode. This is useful |
13556 | for debugging X code. */ | |
13557 | { | |
13558 | Lisp_Object value; | |
13559 | value = display_x_get_resource (dpyinfo, | |
13560 | build_string ("synchronous"), | |
13561 | build_string ("Synchronous"), | |
13562 | Qnil, Qnil); | |
13563 | if (STRINGP (value) | |
13564 | && (!strcmp (XSTRING (value)->data, "true") | |
13565 | || !strcmp (XSTRING (value)->data, "on"))) | |
13566 | XSynchronize (dpyinfo->display, True); | |
13567 | } | |
13568 | ||
60439948 KH |
13569 | UNBLOCK_INPUT; |
13570 | ||
7a13e894 RS |
13571 | return dpyinfo; |
13572 | } | |
13573 | \f | |
13574 | /* Get rid of display DPYINFO, assuming all frames are already gone, | |
13575 | and without sending any more commands to the X server. */ | |
dc6f92b8 | 13576 | |
7a13e894 RS |
13577 | void |
13578 | x_delete_display (dpyinfo) | |
13579 | struct x_display_info *dpyinfo; | |
13580 | { | |
13581 | delete_keyboard_wait_descriptor (dpyinfo->connection); | |
13582 | ||
13583 | /* Discard this display from x_display_name_list and x_display_list. | |
13584 | We can't use Fdelq because that can quit. */ | |
13585 | if (! NILP (x_display_name_list) | |
8e713be6 KR |
13586 | && EQ (XCAR (x_display_name_list), dpyinfo->name_list_element)) |
13587 | x_display_name_list = XCDR (x_display_name_list); | |
7a13e894 RS |
13588 | else |
13589 | { | |
13590 | Lisp_Object tail; | |
13591 | ||
13592 | tail = x_display_name_list; | |
8e713be6 | 13593 | while (CONSP (tail) && CONSP (XCDR (tail))) |
7a13e894 | 13594 | { |
bffcfca9 | 13595 | if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element)) |
7a13e894 | 13596 | { |
8e713be6 | 13597 | XCDR (tail) = XCDR (XCDR (tail)); |
7a13e894 RS |
13598 | break; |
13599 | } | |
8e713be6 | 13600 | tail = XCDR (tail); |
7a13e894 RS |
13601 | } |
13602 | } | |
13603 | ||
9bda743f GM |
13604 | if (next_noop_dpyinfo == dpyinfo) |
13605 | next_noop_dpyinfo = dpyinfo->next; | |
13606 | ||
7a13e894 RS |
13607 | if (x_display_list == dpyinfo) |
13608 | x_display_list = dpyinfo->next; | |
7f9c7f94 RS |
13609 | else |
13610 | { | |
13611 | struct x_display_info *tail; | |
7a13e894 | 13612 | |
7f9c7f94 RS |
13613 | for (tail = x_display_list; tail; tail = tail->next) |
13614 | if (tail->next == dpyinfo) | |
13615 | tail->next = tail->next->next; | |
13616 | } | |
7a13e894 | 13617 | |
0d777288 RS |
13618 | #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */ |
13619 | #ifndef AIX /* On AIX, XCloseDisplay calls this. */ | |
7f9c7f94 RS |
13620 | XrmDestroyDatabase (dpyinfo->xrdb); |
13621 | #endif | |
0d777288 | 13622 | #endif |
29b38361 KH |
13623 | #ifdef MULTI_KBOARD |
13624 | if (--dpyinfo->kboard->reference_count == 0) | |
39f79001 | 13625 | delete_kboard (dpyinfo->kboard); |
b9737ad3 | 13626 | #endif |
f5d11644 GM |
13627 | #ifdef HAVE_X_I18N |
13628 | if (dpyinfo->xim) | |
13629 | xim_close_dpy (dpyinfo); | |
13630 | #endif | |
13631 | ||
b9737ad3 KH |
13632 | xfree (dpyinfo->font_table); |
13633 | xfree (dpyinfo->x_id_name); | |
13634 | xfree (dpyinfo); | |
7a13e894 RS |
13635 | } |
13636 | \f | |
13637 | /* Set up use of X before we make the first connection. */ | |
13638 | ||
06a2c219 GM |
13639 | static struct redisplay_interface x_redisplay_interface = |
13640 | { | |
13641 | x_produce_glyphs, | |
13642 | x_write_glyphs, | |
13643 | x_insert_glyphs, | |
13644 | x_clear_end_of_line, | |
13645 | x_scroll_run, | |
13646 | x_after_update_window_line, | |
13647 | x_update_window_begin, | |
13648 | x_update_window_end, | |
13649 | XTcursor_to, | |
13650 | x_flush, | |
71b8321e | 13651 | x_clear_mouse_face, |
66ac4b0e GM |
13652 | x_get_glyph_overhangs, |
13653 | x_fix_overlapping_area | |
06a2c219 GM |
13654 | }; |
13655 | ||
dfcf069d | 13656 | void |
7a13e894 RS |
13657 | x_initialize () |
13658 | { | |
06a2c219 GM |
13659 | rif = &x_redisplay_interface; |
13660 | ||
13661 | clear_frame_hook = x_clear_frame; | |
13662 | ins_del_lines_hook = x_ins_del_lines; | |
13663 | change_line_highlight_hook = x_change_line_highlight; | |
13664 | delete_glyphs_hook = x_delete_glyphs; | |
dc6f92b8 JB |
13665 | ring_bell_hook = XTring_bell; |
13666 | reset_terminal_modes_hook = XTreset_terminal_modes; | |
13667 | set_terminal_modes_hook = XTset_terminal_modes; | |
06a2c219 GM |
13668 | update_begin_hook = x_update_begin; |
13669 | update_end_hook = x_update_end; | |
dc6f92b8 JB |
13670 | set_terminal_window_hook = XTset_terminal_window; |
13671 | read_socket_hook = XTread_socket; | |
b8009dd1 | 13672 | frame_up_to_date_hook = XTframe_up_to_date; |
dc6f92b8 | 13673 | reassert_line_highlight_hook = XTreassert_line_highlight; |
90e65f07 | 13674 | mouse_position_hook = XTmouse_position; |
f451eb13 | 13675 | frame_rehighlight_hook = XTframe_rehighlight; |
dbc4e1c1 | 13676 | frame_raise_lower_hook = XTframe_raise_lower; |
ab648270 JB |
13677 | set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar; |
13678 | condemn_scroll_bars_hook = XTcondemn_scroll_bars; | |
13679 | redeem_scroll_bar_hook = XTredeem_scroll_bar; | |
13680 | judge_scroll_bars_hook = XTjudge_scroll_bars; | |
06a2c219 | 13681 | estimate_mode_line_height_hook = x_estimate_mode_line_height; |
58769bee | 13682 | |
f676886a | 13683 | scroll_region_ok = 1; /* we'll scroll partial frames */ |
dc6f92b8 JB |
13684 | char_ins_del_ok = 0; /* just as fast to write the line */ |
13685 | line_ins_del_ok = 1; /* we'll just blt 'em */ | |
13686 | fast_clear_end_of_line = 1; /* X does this well */ | |
58769bee | 13687 | memory_below_frame = 0; /* we don't remember what scrolls |
dc6f92b8 JB |
13688 | off the bottom */ |
13689 | baud_rate = 19200; | |
13690 | ||
7a13e894 | 13691 | x_noop_count = 0; |
9ea173e8 | 13692 | last_tool_bar_item = -1; |
06a2c219 GM |
13693 | any_help_event_p = 0; |
13694 | ||
b30b24cb RS |
13695 | /* Try to use interrupt input; if we can't, then start polling. */ |
13696 | Fset_input_mode (Qt, Qnil, Qt, Qnil); | |
13697 | ||
7f9c7f94 RS |
13698 | #ifdef USE_X_TOOLKIT |
13699 | XtToolkitInitialize (); | |
13700 | Xt_app_con = XtCreateApplicationContext (); | |
665881ad | 13701 | XtAppSetFallbackResources (Xt_app_con, Xt_default_resources); |
bffcfca9 GM |
13702 | |
13703 | /* Install an asynchronous timer that processes Xt timeout events | |
13704 | every 0.1s. This is necessary because some widget sets use | |
13705 | timeouts internally, for example the LessTif menu bar, or the | |
13706 | Xaw3d scroll bar. When Xt timouts aren't processed, these | |
13707 | widgets don't behave normally. */ | |
13708 | { | |
13709 | EMACS_TIME interval; | |
13710 | EMACS_SET_SECS_USECS (interval, 0, 100000); | |
13711 | start_atimer (ATIMER_CONTINUOUS, interval, x_process_timeouts, 0); | |
13712 | } | |
db74249b | 13713 | #endif |
bffcfca9 | 13714 | |
db74249b | 13715 | #if USE_TOOLKIT_SCROLL_BARS |
ec18280f SM |
13716 | xaw3d_arrow_scroll = False; |
13717 | xaw3d_pick_top = True; | |
7f9c7f94 RS |
13718 | #endif |
13719 | ||
58769bee | 13720 | /* Note that there is no real way portable across R3/R4 to get the |
c118dd06 | 13721 | original error handler. */ |
e99db5a1 | 13722 | XSetErrorHandler (x_error_handler); |
334208b7 | 13723 | XSetIOErrorHandler (x_io_error_quitter); |
dc6f92b8 | 13724 | |
06a2c219 | 13725 | /* Disable Window Change signals; they are handled by X events. */ |
dc6f92b8 JB |
13726 | #ifdef SIGWINCH |
13727 | signal (SIGWINCH, SIG_DFL); | |
c118dd06 | 13728 | #endif /* ! defined (SIGWINCH) */ |
dc6f92b8 | 13729 | |
92e2441b | 13730 | signal (SIGPIPE, x_connection_signal); |
dc6f92b8 | 13731 | } |
55123275 | 13732 | |
06a2c219 | 13733 | |
55123275 JB |
13734 | void |
13735 | syms_of_xterm () | |
13736 | { | |
e99db5a1 RS |
13737 | staticpro (&x_error_message_string); |
13738 | x_error_message_string = Qnil; | |
13739 | ||
7a13e894 RS |
13740 | staticpro (&x_display_name_list); |
13741 | x_display_name_list = Qnil; | |
334208b7 | 13742 | |
ab648270 | 13743 | staticpro (&last_mouse_scroll_bar); |
e53cb100 | 13744 | last_mouse_scroll_bar = Qnil; |
59e755be KH |
13745 | |
13746 | staticpro (&Qvendor_specific_keysyms); | |
13747 | Qvendor_specific_keysyms = intern ("vendor-specific-keysyms"); | |
2237cac9 RS |
13748 | |
13749 | staticpro (&last_mouse_press_frame); | |
13750 | last_mouse_press_frame = Qnil; | |
06a2c219 | 13751 | |
06a2c219 | 13752 | help_echo = Qnil; |
be010514 GM |
13753 | staticpro (&help_echo); |
13754 | help_echo_object = Qnil; | |
13755 | staticpro (&help_echo_object); | |
7cea38bc GM |
13756 | help_echo_window = Qnil; |
13757 | staticpro (&help_echo_window); | |
06a2c219 | 13758 | previous_help_echo = Qnil; |
be010514 GM |
13759 | staticpro (&previous_help_echo); |
13760 | help_echo_pos = -1; | |
06a2c219 GM |
13761 | |
13762 | DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p, | |
13763 | "*Non-nil means draw block cursor as wide as the glyph under it.\n\ | |
13764 | For example, if a block cursor is over a tab, it will be drawn as\n\ | |
13765 | wide as that tab on the display."); | |
13766 | x_stretch_cursor_p = 0; | |
13767 | ||
13768 | DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p, | |
13769 | "If not nil, Emacs uses toolkit scroll bars."); | |
13770 | #if USE_TOOLKIT_SCROLL_BARS | |
13771 | x_toolkit_scroll_bars_p = 1; | |
13772 | #else | |
13773 | x_toolkit_scroll_bars_p = 0; | |
13774 | #endif | |
13775 | ||
06a2c219 GM |
13776 | staticpro (&last_mouse_motion_frame); |
13777 | last_mouse_motion_frame = Qnil; | |
55123275 | 13778 | } |
6cf0ae86 RS |
13779 | |
13780 | #endif /* not HAVE_X_WINDOWS */ | |
06a2c219 | 13781 |