Commit | Line | Data |
---|---|---|
dc6f92b8 | 1 | /* X Communication module for terminals which understand the X protocol. |
abfb6b46 | 2 | Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001, 2002 |
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" | |
dc6f92b8 | 79 | #include "gnu.h" |
dc6f92b8 | 80 | #include "disptab.h" |
dc6f92b8 | 81 | #include "buffer.h" |
f451eb13 | 82 | #include "window.h" |
3b2fa4e6 | 83 | #include "keyboard.h" |
bde7c500 | 84 | #include "intervals.h" |
dfcf069d | 85 | #include "process.h" |
bffcfca9 | 86 | #include "atimer.h" |
8feddab4 | 87 | #include "keymap.h" |
dc6f92b8 | 88 | |
d2bd6bc4 RS |
89 | #ifdef USE_X_TOOLKIT |
90 | #include <X11/Shell.h> | |
91 | #endif | |
92 | ||
06a2c219 GM |
93 | #ifdef HAVE_SYS_TIME_H |
94 | #include <sys/time.h> | |
95 | #endif | |
96 | #ifdef HAVE_UNISTD_H | |
97 | #include <unistd.h> | |
98 | #endif | |
99 | ||
d624284c PJ |
100 | #ifdef USE_LUCID |
101 | extern int xlwmenu_window_p (Widget w, Window window); | |
102 | extern void xlwmenu_redisplay P_ ((Widget)); | |
103 | #endif | |
104 | ||
3afe33e7 | 105 | #ifdef USE_X_TOOLKIT |
06a2c219 | 106 | |
952291d9 GM |
107 | extern void free_frame_menubar P_ ((struct frame *)); |
108 | extern struct frame *x_menubar_window_to_frame P_ ((struct x_display_info *, | |
109 | int)); | |
06a2c219 | 110 | |
0fdff6bb RS |
111 | #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES) |
112 | #define HACK_EDITRES | |
113 | extern void _XEditResCheckMessages (); | |
114 | #endif /* not NO_EDITRES */ | |
06a2c219 GM |
115 | |
116 | /* Include toolkit specific headers for the scroll bar widget. */ | |
117 | ||
118 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
119 | #if defined USE_MOTIF | |
120 | #include <Xm/Xm.h> /* for LESSTIF_VERSION */ | |
121 | #include <Xm/ScrollBar.h> | |
ec18280f SM |
122 | #else /* !USE_MOTIF i.e. use Xaw */ |
123 | ||
124 | #ifdef HAVE_XAW3D | |
06a2c219 | 125 | #include <X11/Xaw3d/Simple.h> |
06a2c219 GM |
126 | #include <X11/Xaw3d/Scrollbar.h> |
127 | #define ARROW_SCROLLBAR | |
128 | #include <X11/Xaw3d/ScrollbarP.h> | |
ec18280f SM |
129 | #else /* !HAVE_XAW3D */ |
130 | #include <X11/Xaw/Simple.h> | |
131 | #include <X11/Xaw/Scrollbar.h> | |
132 | #endif /* !HAVE_XAW3D */ | |
133 | #ifndef XtNpickTop | |
134 | #define XtNpickTop "pickTop" | |
135 | #endif /* !XtNpickTop */ | |
136 | #endif /* !USE_MOTIF */ | |
06a2c219 GM |
137 | #endif /* USE_TOOLKIT_SCROLL_BARS */ |
138 | ||
3afe33e7 RS |
139 | #endif /* USE_X_TOOLKIT */ |
140 | ||
b849c413 RS |
141 | #ifndef USE_X_TOOLKIT |
142 | #define x_any_window_to_frame x_window_to_frame | |
5627c40e | 143 | #define x_top_window_to_frame x_window_to_frame |
b849c413 RS |
144 | #endif |
145 | ||
546e6d5b | 146 | #ifdef USE_X_TOOLKIT |
d067ea8b | 147 | #include "widget.h" |
546e6d5b RS |
148 | #ifndef XtNinitialState |
149 | #define XtNinitialState "initialState" | |
150 | #endif | |
151 | #endif | |
152 | ||
06a2c219 GM |
153 | #define abs(x) ((x) < 0 ? -(x) : (x)) |
154 | ||
155 | #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER)) | |
156 | ||
157 | \f | |
3f332ef3 | 158 | /* Fringe bitmaps. */ |
06a2c219 | 159 | |
3f332ef3 | 160 | enum fringe_bitmap_type |
06a2c219 | 161 | { |
3f332ef3 | 162 | NO_FRINGE_BITMAP, |
06a2c219 GM |
163 | LEFT_TRUNCATION_BITMAP, |
164 | RIGHT_TRUNCATION_BITMAP, | |
165 | OVERLAY_ARROW_BITMAP, | |
166 | CONTINUED_LINE_BITMAP, | |
167 | CONTINUATION_LINE_BITMAP, | |
168 | ZV_LINE_BITMAP | |
169 | }; | |
170 | ||
171 | /* Bitmap drawn to indicate lines not displaying text if | |
172 | `indicate-empty-lines' is non-nil. */ | |
173 | ||
174 | #define zv_width 8 | |
976b73d7 KS |
175 | #define zv_height 72 |
176 | #define zv_period 3 | |
06a2c219 | 177 | static unsigned char zv_bits[] = { |
976b73d7 KS |
178 | 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, |
179 | 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, | |
180 | 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, | |
181 | 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, | |
182 | 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, | |
183 | 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, | |
184 | 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, | |
185 | 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00}; | |
06a2c219 GM |
186 | |
187 | /* An arrow like this: `<-'. */ | |
188 | ||
189 | #define left_width 8 | |
190 | #define left_height 8 | |
191 | static unsigned char left_bits[] = { | |
192 | 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18}; | |
193 | ||
110859fc GM |
194 | /* Right truncation arrow bitmap `->'. */ |
195 | ||
196 | #define right_width 8 | |
197 | #define right_height 8 | |
198 | static unsigned char right_bits[] = { | |
199 | 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18}; | |
200 | ||
06a2c219 GM |
201 | /* Marker for continued lines. */ |
202 | ||
203 | #define continued_width 8 | |
204 | #define continued_height 8 | |
205 | static unsigned char continued_bits[] = { | |
110859fc GM |
206 | 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c}; |
207 | ||
208 | /* Marker for continuation lines. */ | |
06a2c219 GM |
209 | |
210 | #define continuation_width 8 | |
211 | #define continuation_height 8 | |
212 | static unsigned char continuation_bits[] = { | |
110859fc | 213 | 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e}; |
06a2c219 | 214 | |
110859fc | 215 | /* Overlay arrow bitmap. */ |
06a2c219 | 216 | |
110859fc GM |
217 | #if 0 |
218 | /* A bomb. */ | |
06a2c219 GM |
219 | #define ov_width 8 |
220 | #define ov_height 8 | |
221 | static unsigned char ov_bits[] = { | |
222 | 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c}; | |
06a2c219 | 223 | #else |
110859fc | 224 | /* A triangular arrow. */ |
06a2c219 GM |
225 | #define ov_width 8 |
226 | #define ov_height 8 | |
227 | static unsigned char ov_bits[] = { | |
110859fc GM |
228 | 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03}; |
229 | ||
e4b68333 | 230 | #endif |
06a2c219 GM |
231 | |
232 | extern Lisp_Object Qhelp_echo; | |
233 | ||
69388238 | 234 | \f |
5bf04520 | 235 | /* Non-nil means Emacs uses toolkit scroll bars. */ |
06a2c219 | 236 | |
5bf04520 | 237 | Lisp_Object Vx_toolkit_scroll_bars; |
06a2c219 GM |
238 | |
239 | /* If a string, XTread_socket generates an event to display that string. | |
240 | (The display is done in read_char.) */ | |
241 | ||
242 | static Lisp_Object help_echo; | |
7cea38bc | 243 | static Lisp_Object help_echo_window; |
be010514 GM |
244 | static Lisp_Object help_echo_object; |
245 | static int help_echo_pos; | |
06a2c219 GM |
246 | |
247 | /* Temporary variable for XTread_socket. */ | |
248 | ||
249 | static Lisp_Object previous_help_echo; | |
250 | ||
251 | /* Non-zero means that a HELP_EVENT has been generated since Emacs | |
252 | start. */ | |
253 | ||
254 | static int any_help_event_p; | |
255 | ||
503e457e PJ |
256 | /* Non-zero means autoselect window with the mouse cursor. */ |
257 | ||
ee8ceff8 | 258 | int mouse_autoselect_window; |
5bc62483 | 259 | |
ee8ceff8 | 260 | /* Last window where we saw the mouse. Used by mouse-autoselect-window. */ |
5bc62483 | 261 | static Lisp_Object last_window; |
503e457e | 262 | |
06a2c219 GM |
263 | /* Non-zero means draw block and hollow cursor as wide as the glyph |
264 | under it. For example, if a block cursor is over a tab, it will be | |
265 | drawn as wide as that tab on the display. */ | |
266 | ||
267 | int x_stretch_cursor_p; | |
268 | ||
a72d5ce5 GM |
269 | /* Non-zero means make use of UNDERLINE_POSITION font properties. */ |
270 | ||
271 | int x_use_underline_position_properties; | |
272 | ||
06a2c219 GM |
273 | /* This is a chain of structures for all the X displays currently in |
274 | use. */ | |
275 | ||
334208b7 | 276 | struct x_display_info *x_display_list; |
dc6f92b8 | 277 | |
06a2c219 GM |
278 | /* This is a list of cons cells, each of the form (NAME |
279 | . FONT-LIST-CACHE), one for each element of x_display_list and in | |
280 | the same order. NAME is the name of the frame. FONT-LIST-CACHE | |
281 | records previous values returned by x-list-fonts. */ | |
282 | ||
7a13e894 | 283 | Lisp_Object x_display_name_list; |
f451eb13 | 284 | |
987d2ad1 | 285 | /* Frame being updated by update_frame. This is declared in term.c. |
06a2c219 GM |
286 | This is set by update_begin and looked at by all the XT functions. |
287 | It is zero while not inside an update. In that case, the XT | |
288 | functions assume that `selected_frame' is the frame to apply to. */ | |
289 | ||
d0386f2a | 290 | extern struct frame *updating_frame; |
dc6f92b8 | 291 | |
06a2c219 GM |
292 | /* This is a frame waiting to be auto-raised, within XTread_socket. */ |
293 | ||
0134a210 RS |
294 | struct frame *pending_autoraise_frame; |
295 | ||
7f9c7f94 RS |
296 | #ifdef USE_X_TOOLKIT |
297 | /* The application context for Xt use. */ | |
298 | XtAppContext Xt_app_con; | |
06a2c219 GM |
299 | static String Xt_default_resources[] = {0}; |
300 | #endif /* USE_X_TOOLKIT */ | |
665881ad | 301 | |
06a2c219 GM |
302 | /* Nominal cursor position -- where to draw output. |
303 | HPOS and VPOS are window relative glyph matrix coordinates. | |
304 | X and Y are window relative pixel coordinates. */ | |
dc6f92b8 | 305 | |
06a2c219 | 306 | struct cursor_pos output_cursor; |
dc6f92b8 | 307 | |
bffcfca9 GM |
308 | /* Non-zero means user is interacting with a toolkit scroll bar. */ |
309 | ||
310 | static int toolkit_scroll_bar_interaction; | |
dc6f92b8 | 311 | |
69388238 RS |
312 | /* Mouse movement. |
313 | ||
06a2c219 | 314 | Formerly, we used PointerMotionHintMask (in standard_event_mask) |
f5bb65ec RS |
315 | so that we would have to call XQueryPointer after each MotionNotify |
316 | event to ask for another such event. However, this made mouse tracking | |
317 | slow, and there was a bug that made it eventually stop. | |
318 | ||
319 | Simply asking for MotionNotify all the time seems to work better. | |
320 | ||
69388238 RS |
321 | In order to avoid asking for motion events and then throwing most |
322 | of them away or busy-polling the server for mouse positions, we ask | |
323 | the server for pointer motion hints. This means that we get only | |
324 | one event per group of mouse movements. "Groups" are delimited by | |
325 | other kinds of events (focus changes and button clicks, for | |
326 | example), or by XQueryPointer calls; when one of these happens, we | |
327 | get another MotionNotify event the next time the mouse moves. This | |
328 | is at least as efficient as getting motion events when mouse | |
329 | tracking is on, and I suspect only negligibly worse when tracking | |
f5bb65ec | 330 | is off. */ |
69388238 RS |
331 | |
332 | /* Where the mouse was last time we reported a mouse event. */ | |
69388238 | 333 | |
06a2c219 GM |
334 | FRAME_PTR last_mouse_frame; |
335 | static XRectangle last_mouse_glyph; | |
2237cac9 RS |
336 | static Lisp_Object last_mouse_press_frame; |
337 | ||
69388238 RS |
338 | /* The scroll bar in which the last X motion event occurred. |
339 | ||
06a2c219 GM |
340 | If the last X motion event occurred in a scroll bar, we set this so |
341 | XTmouse_position can know whether to report a scroll bar motion or | |
69388238 RS |
342 | an ordinary motion. |
343 | ||
06a2c219 GM |
344 | If the last X motion event didn't occur in a scroll bar, we set |
345 | this to Qnil, to tell XTmouse_position to return an ordinary motion | |
346 | event. */ | |
347 | ||
69388238 RS |
348 | static Lisp_Object last_mouse_scroll_bar; |
349 | ||
69388238 RS |
350 | /* This is a hack. We would really prefer that XTmouse_position would |
351 | return the time associated with the position it returns, but there | |
06a2c219 | 352 | doesn't seem to be any way to wrest the time-stamp from the server |
69388238 RS |
353 | along with the position query. So, we just keep track of the time |
354 | of the last movement we received, and return that in hopes that | |
355 | it's somewhat accurate. */ | |
06a2c219 | 356 | |
69388238 RS |
357 | static Time last_mouse_movement_time; |
358 | ||
06a2c219 GM |
359 | /* Incremented by XTread_socket whenever it really tries to read |
360 | events. */ | |
361 | ||
c0a04927 RS |
362 | #ifdef __STDC__ |
363 | static int volatile input_signal_count; | |
364 | #else | |
365 | static int input_signal_count; | |
366 | #endif | |
367 | ||
7a13e894 | 368 | /* Used locally within XTread_socket. */ |
06a2c219 | 369 | |
7a13e894 | 370 | static int x_noop_count; |
dc6f92b8 | 371 | |
7a13e894 | 372 | /* Initial values of argv and argc. */ |
06a2c219 | 373 | |
7a13e894 RS |
374 | extern char **initial_argv; |
375 | extern int initial_argc; | |
dc6f92b8 | 376 | |
7a13e894 | 377 | extern Lisp_Object Vcommand_line_args, Vsystem_name; |
dc6f92b8 | 378 | |
06a2c219 | 379 | /* Tells if a window manager is present or not. */ |
7a13e894 RS |
380 | |
381 | extern Lisp_Object Vx_no_window_manager; | |
dc6f92b8 | 382 | |
c2df547c | 383 | extern Lisp_Object Qface, Qmouse_face; |
b8009dd1 | 384 | |
dc6f92b8 JB |
385 | extern int errno; |
386 | ||
dfeccd2d | 387 | /* A mask of extra modifier bits to put into every keyboard char. */ |
06a2c219 | 388 | |
31ade731 | 389 | extern EMACS_INT extra_keyboard_modifiers; |
64bb1782 | 390 | |
98659da6 KG |
391 | /* The keysyms to use for the various modifiers. */ |
392 | ||
393 | Lisp_Object Vx_alt_keysym, Vx_hyper_keysym, Vx_meta_keysym, Vx_super_keysym; | |
394 | static Lisp_Object Qalt, Qhyper, Qmeta, Qsuper, Qmodifier_value; | |
395 | ||
59e755be | 396 | static Lisp_Object Qvendor_specific_keysyms; |
c997eae5 | 397 | static Lisp_Object Qlatin_1, Qutf_8; |
59e755be | 398 | |
952291d9 GM |
399 | extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *)); |
400 | extern Lisp_Object x_icon_type P_ ((struct frame *)); | |
c32cdd9a | 401 | |
7a13e894 | 402 | |
06a2c219 GM |
403 | /* Enumeration for overriding/changing the face to use for drawing |
404 | glyphs in x_draw_glyphs. */ | |
405 | ||
406 | enum draw_glyphs_face | |
407 | { | |
408 | DRAW_NORMAL_TEXT, | |
409 | DRAW_INVERSE_VIDEO, | |
410 | DRAW_CURSOR, | |
411 | DRAW_MOUSE_FACE, | |
412 | DRAW_IMAGE_RAISED, | |
413 | DRAW_IMAGE_SUNKEN | |
414 | }; | |
415 | ||
b7f83f9e | 416 | static int cursor_in_mouse_face_p P_ ((struct window *)); |
fa262c07 | 417 | static int clear_mouse_face P_ ((struct x_display_info *)); |
651f03b6 | 418 | static int x_alloc_nearest_color_1 P_ ((Display *, Colormap, XColor *)); |
499b1844 | 419 | static void x_set_window_size_1 P_ ((struct frame *, int, int, int)); |
651f03b6 | 420 | static const XColor *x_color_cells P_ ((Display *, int *)); |
71b8321e | 421 | static void x_update_window_end P_ ((struct window *, int, int)); |
06a2c219 GM |
422 | static void frame_to_window_pixel_xy P_ ((struct window *, int *, int *)); |
423 | void x_delete_display P_ ((struct x_display_info *)); | |
424 | static unsigned int x_x_to_emacs_modifiers P_ ((struct x_display_info *, | |
425 | unsigned)); | |
426 | static int fast_find_position P_ ((struct window *, int, int *, int *, | |
7e376260 | 427 | int *, int *, Lisp_Object)); |
f9db2310 GM |
428 | static int fast_find_string_pos P_ ((struct window *, int, Lisp_Object, |
429 | int *, int *, int *, int *, int)); | |
06a2c219 GM |
430 | static void set_output_cursor P_ ((struct cursor_pos *)); |
431 | static struct glyph *x_y_to_hpos_vpos P_ ((struct window *, int, int, | |
f9db2310 | 432 | int *, int *, int *, int)); |
b436feb6 GM |
433 | static void note_mode_line_or_margin_highlight P_ ((struct window *, int, |
434 | int, int)); | |
06a2c219 | 435 | static void note_mouse_highlight P_ ((struct frame *, int, int)); |
9ea173e8 GM |
436 | static void note_tool_bar_highlight P_ ((struct frame *f, int, int)); |
437 | static void x_handle_tool_bar_click P_ ((struct frame *, XButtonEvent *)); | |
06a2c219 GM |
438 | static void show_mouse_face P_ ((struct x_display_info *, |
439 | enum draw_glyphs_face)); | |
440 | static int x_io_error_quitter P_ ((Display *)); | |
441 | int x_catch_errors P_ ((Display *)); | |
442 | void x_uncatch_errors P_ ((Display *, int)); | |
443 | void x_lower_frame P_ ((struct frame *)); | |
444 | void x_scroll_bar_clear P_ ((struct frame *)); | |
445 | int x_had_errors_p P_ ((Display *)); | |
446 | void x_wm_set_size_hint P_ ((struct frame *, long, int)); | |
447 | void x_raise_frame P_ ((struct frame *)); | |
448 | void x_set_window_size P_ ((struct frame *, int, int, int)); | |
449 | void x_wm_set_window_state P_ ((struct frame *, int)); | |
450 | void x_wm_set_icon_pixmap P_ ((struct frame *, int)); | |
451 | void x_initialize P_ ((void)); | |
452 | static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); | |
453 | static int x_compute_min_glyph_bounds P_ ((struct frame *)); | |
454 | static void x_draw_phys_cursor_glyph P_ ((struct window *, | |
455 | struct glyph_row *, | |
456 | enum draw_glyphs_face)); | |
457 | static void x_update_end P_ ((struct frame *)); | |
458 | static void XTframe_up_to_date P_ ((struct frame *)); | |
06a2c219 GM |
459 | static void XTset_terminal_modes P_ ((void)); |
460 | static void XTreset_terminal_modes P_ ((void)); | |
461 | static void XTcursor_to P_ ((int, int, int, int)); | |
462 | static void x_write_glyphs P_ ((struct glyph *, int)); | |
463 | static void x_clear_end_of_line P_ ((int)); | |
464 | static void x_clear_frame P_ ((void)); | |
465 | static void x_clear_cursor P_ ((struct window *)); | |
466 | static void frame_highlight P_ ((struct frame *)); | |
467 | static void frame_unhighlight P_ ((struct frame *)); | |
468 | static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *)); | |
469 | static void XTframe_rehighlight P_ ((struct frame *)); | |
470 | static void x_frame_rehighlight P_ ((struct x_display_info *)); | |
471 | static void x_draw_hollow_cursor P_ ((struct window *, struct glyph_row *)); | |
65c26775 EZ |
472 | static void x_draw_bar_cursor P_ ((struct window *, struct glyph_row *, int, |
473 | enum text_cursor_kinds)); | |
06a2c219 GM |
474 | static int x_intersect_rectangles P_ ((XRectangle *, XRectangle *, |
475 | XRectangle *)); | |
476 | static void expose_frame P_ ((struct frame *, int, int, int, int)); | |
82f053ab | 477 | static int expose_window_tree P_ ((struct window *, XRectangle *)); |
a39202f6 | 478 | static int expose_window P_ ((struct window *, XRectangle *)); |
06a2c219 GM |
479 | static void expose_area P_ ((struct window *, struct glyph_row *, |
480 | XRectangle *, enum glyph_row_area)); | |
82f053ab | 481 | static int expose_line P_ ((struct window *, struct glyph_row *, |
06a2c219 GM |
482 | XRectangle *)); |
483 | static void x_update_cursor_in_window_tree P_ ((struct window *, int)); | |
484 | static void x_update_window_cursor P_ ((struct window *, int)); | |
485 | static void x_erase_phys_cursor P_ ((struct window *)); | |
486 | void x_display_and_set_cursor P_ ((struct window *, int, int, int, int, int)); | |
3f332ef3 | 487 | static void x_draw_fringe_bitmap P_ ((struct window *, struct glyph_row *, |
976b73d7 | 488 | enum fringe_bitmap_type, int left_p)); |
06a2c219 GM |
489 | |
490 | static void x_clip_to_row P_ ((struct window *, struct glyph_row *, | |
491 | GC, int)); | |
492 | static int x_phys_cursor_in_rect_p P_ ((struct window *, XRectangle *)); | |
3f332ef3 | 493 | static void x_draw_row_fringe_bitmaps P_ ((struct window *, struct glyph_row *)); |
60626bab GM |
494 | static void notice_overwritten_cursor P_ ((struct window *, enum glyph_row_area, |
495 | int, int, int, int)); | |
06a2c219 | 496 | static void x_flush P_ ((struct frame *f)); |
952291d9 GM |
497 | static void x_update_begin P_ ((struct frame *)); |
498 | static void x_update_window_begin P_ ((struct window *)); | |
499 | static void x_draw_vertical_border P_ ((struct window *)); | |
500 | static void x_after_update_window_line P_ ((struct glyph_row *)); | |
501 | static INLINE void take_vertical_position_into_account P_ ((struct it *)); | |
502 | static void x_produce_stretch_glyph P_ ((struct it *)); | |
b52b65bd GM |
503 | static struct scroll_bar *x_window_to_scroll_bar P_ ((Window)); |
504 | static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *, | |
505 | enum scroll_bar_part *, | |
506 | Lisp_Object *, Lisp_Object *, | |
507 | unsigned long *)); | |
d0fa3e56 EZ |
508 | static void x_check_fullscreen P_ ((struct frame *)); |
509 | static void x_check_fullscreen_move P_ ((struct frame *)); | |
06a2c219 GM |
510 | |
511 | /* Flush display of frame F, or of all frames if F is null. */ | |
512 | ||
513 | static void | |
514 | x_flush (f) | |
515 | struct frame *f; | |
516 | { | |
517 | BLOCK_INPUT; | |
518 | if (f == NULL) | |
519 | { | |
520 | Lisp_Object rest, frame; | |
521 | FOR_EACH_FRAME (rest, frame) | |
522 | x_flush (XFRAME (frame)); | |
523 | } | |
524 | else if (FRAME_X_P (f)) | |
525 | XFlush (FRAME_X_DISPLAY (f)); | |
526 | UNBLOCK_INPUT; | |
527 | } | |
528 | ||
dc6f92b8 | 529 | |
06a2c219 GM |
530 | /* Remove calls to XFlush by defining XFlush to an empty replacement. |
531 | Calls to XFlush should be unnecessary because the X output buffer | |
532 | is flushed automatically as needed by calls to XPending, | |
533 | XNextEvent, or XWindowEvent according to the XFlush man page. | |
534 | XTread_socket calls XPending. Removing XFlush improves | |
535 | performance. */ | |
536 | ||
537 | #define XFlush(DISPLAY) (void) 0 | |
b8009dd1 | 538 | |
334208b7 | 539 | \f |
06a2c219 GM |
540 | /*********************************************************************** |
541 | Debugging | |
542 | ***********************************************************************/ | |
543 | ||
9382638d | 544 | #if 0 |
06a2c219 GM |
545 | |
546 | /* This is a function useful for recording debugging information about | |
547 | the sequence of occurrences in this file. */ | |
9382638d KH |
548 | |
549 | struct record | |
550 | { | |
551 | char *locus; | |
552 | int type; | |
553 | }; | |
554 | ||
555 | struct record event_record[100]; | |
556 | ||
557 | int event_record_index; | |
558 | ||
559 | record_event (locus, type) | |
560 | char *locus; | |
561 | int type; | |
562 | { | |
563 | if (event_record_index == sizeof (event_record) / sizeof (struct record)) | |
564 | event_record_index = 0; | |
565 | ||
566 | event_record[event_record_index].locus = locus; | |
567 | event_record[event_record_index].type = type; | |
568 | event_record_index++; | |
569 | } | |
570 | ||
571 | #endif /* 0 */ | |
06a2c219 GM |
572 | |
573 | ||
9382638d | 574 | \f |
334208b7 RS |
575 | /* Return the struct x_display_info corresponding to DPY. */ |
576 | ||
577 | struct x_display_info * | |
578 | x_display_info_for_display (dpy) | |
579 | Display *dpy; | |
580 | { | |
581 | struct x_display_info *dpyinfo; | |
582 | ||
583 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) | |
584 | if (dpyinfo->display == dpy) | |
585 | return dpyinfo; | |
16bd92ea | 586 | |
334208b7 RS |
587 | return 0; |
588 | } | |
f451eb13 | 589 | |
06a2c219 GM |
590 | |
591 | \f | |
592 | /*********************************************************************** | |
593 | Starting and ending an update | |
594 | ***********************************************************************/ | |
595 | ||
596 | /* Start an update of frame F. This function is installed as a hook | |
597 | for update_begin, i.e. it is called when update_begin is called. | |
598 | This function is called prior to calls to x_update_window_begin for | |
599 | each window being updated. Currently, there is nothing to do here | |
600 | because all interesting stuff is done on a window basis. */ | |
dc6f92b8 | 601 | |
dfcf069d | 602 | static void |
06a2c219 | 603 | x_update_begin (f) |
f676886a | 604 | struct frame *f; |
58769bee | 605 | { |
06a2c219 GM |
606 | /* Nothing to do. */ |
607 | } | |
dc6f92b8 | 608 | |
dc6f92b8 | 609 | |
06a2c219 GM |
610 | /* Start update of window W. Set the global variable updated_window |
611 | to the window being updated and set output_cursor to the cursor | |
612 | position of W. */ | |
dc6f92b8 | 613 | |
06a2c219 GM |
614 | static void |
615 | x_update_window_begin (w) | |
616 | struct window *w; | |
617 | { | |
618 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
619 | struct x_display_info *display_info = FRAME_X_DISPLAY_INFO (f); | |
620 | ||
621 | updated_window = w; | |
622 | set_output_cursor (&w->cursor); | |
b8009dd1 | 623 | |
06a2c219 | 624 | BLOCK_INPUT; |
d1bc4182 | 625 | |
06a2c219 | 626 | if (f == display_info->mouse_face_mouse_frame) |
b8009dd1 | 627 | { |
514e4681 | 628 | /* Don't do highlighting for mouse motion during the update. */ |
06a2c219 | 629 | display_info->mouse_face_defer = 1; |
37c2c98b | 630 | |
06a2c219 GM |
631 | /* If F needs to be redrawn, simply forget about any prior mouse |
632 | highlighting. */ | |
9f67f20b | 633 | if (FRAME_GARBAGED_P (f)) |
06a2c219 GM |
634 | display_info->mouse_face_window = Qnil; |
635 | ||
64f26cf5 GM |
636 | #if 0 /* Rows in a current matrix containing glyphs in mouse-face have |
637 | their mouse_face_p flag set, which means that they are always | |
638 | unequal to rows in a desired matrix which never have that | |
639 | flag set. So, rows containing mouse-face glyphs are never | |
640 | scrolled, and we don't have to switch the mouse highlight off | |
641 | here to prevent it from being scrolled. */ | |
642 | ||
06a2c219 GM |
643 | /* Can we tell that this update does not affect the window |
644 | where the mouse highlight is? If so, no need to turn off. | |
645 | Likewise, don't do anything if the frame is garbaged; | |
646 | in that case, the frame's current matrix that we would use | |
647 | is all wrong, and we will redisplay that line anyway. */ | |
648 | if (!NILP (display_info->mouse_face_window) | |
649 | && w == XWINDOW (display_info->mouse_face_window)) | |
514e4681 | 650 | { |
06a2c219 | 651 | int i; |
514e4681 | 652 | |
06a2c219 GM |
653 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
654 | if (MATRIX_ROW_ENABLED_P (w->desired_matrix, i)) | |
514e4681 RS |
655 | break; |
656 | ||
06a2c219 GM |
657 | if (i < w->desired_matrix->nrows) |
658 | clear_mouse_face (display_info); | |
514e4681 | 659 | } |
64f26cf5 | 660 | #endif /* 0 */ |
b8009dd1 | 661 | } |
6ccf47d1 | 662 | |
dc6f92b8 JB |
663 | UNBLOCK_INPUT; |
664 | } | |
665 | ||
06a2c219 GM |
666 | |
667 | /* Draw a vertical window border to the right of window W if W doesn't | |
668 | have vertical scroll bars. */ | |
669 | ||
dfcf069d | 670 | static void |
06a2c219 GM |
671 | x_draw_vertical_border (w) |
672 | struct window *w; | |
58769bee | 673 | { |
06a2c219 GM |
674 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
675 | ||
676 | /* Redraw borders between horizontally adjacent windows. Don't | |
677 | do it for frames with vertical scroll bars because either the | |
678 | right scroll bar of a window, or the left scroll bar of its | |
679 | neighbor will suffice as a border. */ | |
680 | if (!WINDOW_RIGHTMOST_P (w) | |
681 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
682 | { | |
683 | int x0, x1, y0, y1; | |
dc6f92b8 | 684 | |
06a2c219 | 685 | window_box_edges (w, -1, &x0, &y0, &x1, &y1); |
3f332ef3 | 686 | x1 += FRAME_X_RIGHT_FRINGE_WIDTH (f); |
06a2c219 GM |
687 | y1 -= 1; |
688 | ||
689 | XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
690 | f->output_data.x->normal_gc, x1, y0, x1, y1); | |
691 | } | |
692 | } | |
693 | ||
694 | ||
71b8321e GM |
695 | /* End update of window W (which is equal to updated_window). |
696 | ||
697 | Draw vertical borders between horizontally adjacent windows, and | |
698 | display W's cursor if CURSOR_ON_P is non-zero. | |
699 | ||
700 | MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing | |
701 | glyphs in mouse-face were overwritten. In that case we have to | |
702 | make sure that the mouse-highlight is properly redrawn. | |
703 | ||
704 | W may be a menu bar pseudo-window in case we don't have X toolkit | |
705 | support. Such windows don't have a cursor, so don't display it | |
706 | here. */ | |
06a2c219 GM |
707 | |
708 | static void | |
71b8321e | 709 | x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p) |
06a2c219 | 710 | struct window *w; |
71b8321e | 711 | int cursor_on_p, mouse_face_overwritten_p; |
06a2c219 | 712 | { |
140330de GM |
713 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (XFRAME (w->frame)); |
714 | ||
06a2c219 GM |
715 | if (!w->pseudo_window_p) |
716 | { | |
717 | BLOCK_INPUT; | |
71b8321e | 718 | |
06a2c219 GM |
719 | if (cursor_on_p) |
720 | x_display_and_set_cursor (w, 1, output_cursor.hpos, | |
721 | output_cursor.vpos, | |
722 | output_cursor.x, output_cursor.y); | |
71b8321e | 723 | |
06a2c219 GM |
724 | x_draw_vertical_border (w); |
725 | UNBLOCK_INPUT; | |
726 | } | |
727 | ||
140330de GM |
728 | /* If a row with mouse-face was overwritten, arrange for |
729 | XTframe_up_to_date to redisplay the mouse highlight. */ | |
730 | if (mouse_face_overwritten_p) | |
731 | { | |
732 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
733 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
734 | dpyinfo->mouse_face_window = Qnil; | |
735 | } | |
736 | ||
06a2c219 GM |
737 | updated_window = NULL; |
738 | } | |
dc6f92b8 | 739 | |
dc6f92b8 | 740 | |
06a2c219 GM |
741 | /* End update of frame F. This function is installed as a hook in |
742 | update_end. */ | |
743 | ||
744 | static void | |
745 | x_update_end (f) | |
746 | struct frame *f; | |
747 | { | |
748 | /* Mouse highlight may be displayed again. */ | |
aa8bff2e | 749 | FRAME_X_DISPLAY_INFO (f)->mouse_face_defer = 0; |
b8009dd1 | 750 | |
06a2c219 | 751 | BLOCK_INPUT; |
334208b7 | 752 | XFlush (FRAME_X_DISPLAY (f)); |
dc6f92b8 JB |
753 | UNBLOCK_INPUT; |
754 | } | |
b8009dd1 | 755 | |
06a2c219 GM |
756 | |
757 | /* This function is called from various places in xdisp.c whenever a | |
758 | complete update has been performed. The global variable | |
759 | updated_window is not available here. */ | |
b8009dd1 | 760 | |
dfcf069d | 761 | static void |
b8009dd1 | 762 | XTframe_up_to_date (f) |
06a2c219 | 763 | struct frame *f; |
b8009dd1 | 764 | { |
06a2c219 | 765 | if (FRAME_X_P (f)) |
514e4681 | 766 | { |
06a2c219 | 767 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
71b8321e | 768 | |
06a2c219 GM |
769 | if (dpyinfo->mouse_face_deferred_gc |
770 | || f == dpyinfo->mouse_face_mouse_frame) | |
771 | { | |
772 | BLOCK_INPUT; | |
773 | if (dpyinfo->mouse_face_mouse_frame) | |
774 | note_mouse_highlight (dpyinfo->mouse_face_mouse_frame, | |
775 | dpyinfo->mouse_face_mouse_x, | |
776 | dpyinfo->mouse_face_mouse_y); | |
777 | dpyinfo->mouse_face_deferred_gc = 0; | |
778 | UNBLOCK_INPUT; | |
779 | } | |
514e4681 | 780 | } |
b8009dd1 | 781 | } |
06a2c219 GM |
782 | |
783 | ||
784 | /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay | |
3f332ef3 | 785 | arrow bitmaps, or clear the fringes if no bitmaps are required |
06a2c219 GM |
786 | before DESIRED_ROW is made current. The window being updated is |
787 | found in updated_window. This function It is called from | |
788 | update_window_line only if it is known that there are differences | |
789 | between bitmaps to be drawn between current row and DESIRED_ROW. */ | |
790 | ||
791 | static void | |
792 | x_after_update_window_line (desired_row) | |
793 | struct glyph_row *desired_row; | |
794 | { | |
795 | struct window *w = updated_window; | |
ef253080 | 796 | struct frame *f; |
259cf6bc | 797 | int width, height; |
06a2c219 GM |
798 | |
799 | xassert (w); | |
800 | ||
801 | if (!desired_row->mode_line_p && !w->pseudo_window_p) | |
802 | { | |
803 | BLOCK_INPUT; | |
3f332ef3 | 804 | x_draw_row_fringe_bitmaps (w, desired_row); |
ef253080 GM |
805 | UNBLOCK_INPUT; |
806 | } | |
807 | ||
808 | /* When a window has disappeared, make sure that no rest of | |
809 | full-width rows stays visible in the internal border. Could | |
810 | check here if updated_window is the leftmost/rightmost window, | |
811 | but I guess it's not worth doing since vertically split windows | |
812 | are almost never used, internal border is rarely set, and the | |
813 | overhead is very small. */ | |
814 | if (windows_or_buffers_changed | |
815 | && desired_row->full_width_p | |
816 | && (f = XFRAME (w->frame), | |
817 | width = FRAME_INTERNAL_BORDER_WIDTH (f), | |
259cf6bc GM |
818 | width != 0) |
819 | && (height = desired_row->visible_height, | |
820 | height > 0)) | |
ef253080 | 821 | { |
ef253080 | 822 | int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); |
06a2c219 | 823 | |
ef253080 GM |
824 | /* Internal border is drawn below the tool bar. */ |
825 | if (WINDOWP (f->tool_bar_window) | |
826 | && w == XWINDOW (f->tool_bar_window)) | |
827 | y -= width; | |
06a2c219 | 828 | |
ef253080 GM |
829 | BLOCK_INPUT; |
830 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
831 | 0, y, width, height, False); | |
832 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
833 | f->output_data.x->pixel_width - width, | |
834 | y, width, height, False); | |
06a2c219 GM |
835 | UNBLOCK_INPUT; |
836 | } | |
837 | } | |
838 | ||
839 | ||
3f332ef3 | 840 | /* Draw the bitmap WHICH in one of the left or right fringes of |
06a2c219 GM |
841 | window W. ROW is the glyph row for which to display the bitmap; it |
842 | determines the vertical position at which the bitmap has to be | |
843 | drawn. */ | |
844 | ||
845 | static void | |
976b73d7 | 846 | x_draw_fringe_bitmap (w, row, which, left_p) |
06a2c219 GM |
847 | struct window *w; |
848 | struct glyph_row *row; | |
3f332ef3 | 849 | enum fringe_bitmap_type which; |
976b73d7 | 850 | int left_p; |
06a2c219 GM |
851 | { |
852 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
853 | Display *display = FRAME_X_DISPLAY (f); | |
854 | Window window = FRAME_X_WINDOW (f); | |
855 | int x, y, wd, h, dy; | |
976b73d7 | 856 | int b1, b2; |
b436feb6 | 857 | unsigned char *bits = NULL; |
06a2c219 GM |
858 | Pixmap pixmap; |
859 | GC gc = f->output_data.x->normal_gc; | |
860 | struct face *face; | |
861 | int depth = DefaultDepthOfScreen (FRAME_X_SCREEN (f)); | |
862 | ||
863 | /* Must clip because of partially visible lines. */ | |
864 | x_clip_to_row (w, row, gc, 1); | |
865 | ||
976b73d7 KS |
866 | /* Convert row to frame coordinates. */ |
867 | y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
868 | ||
06a2c219 GM |
869 | switch (which) |
870 | { | |
976b73d7 KS |
871 | case NO_FRINGE_BITMAP: |
872 | wd = 0; | |
873 | h = 0; | |
874 | break; | |
875 | ||
06a2c219 GM |
876 | case LEFT_TRUNCATION_BITMAP: |
877 | wd = left_width; | |
878 | h = left_height; | |
879 | bits = left_bits; | |
06a2c219 GM |
880 | break; |
881 | ||
882 | case OVERLAY_ARROW_BITMAP: | |
976b73d7 KS |
883 | wd = ov_width; |
884 | h = ov_height; | |
06a2c219 | 885 | bits = ov_bits; |
06a2c219 GM |
886 | break; |
887 | ||
888 | case RIGHT_TRUNCATION_BITMAP: | |
889 | wd = right_width; | |
890 | h = right_height; | |
891 | bits = right_bits; | |
06a2c219 GM |
892 | break; |
893 | ||
894 | case CONTINUED_LINE_BITMAP: | |
976b73d7 KS |
895 | wd = continued_width; |
896 | h = continued_height; | |
06a2c219 | 897 | bits = continued_bits; |
06a2c219 GM |
898 | break; |
899 | ||
900 | case CONTINUATION_LINE_BITMAP: | |
901 | wd = continuation_width; | |
902 | h = continuation_height; | |
903 | bits = continuation_bits; | |
06a2c219 GM |
904 | break; |
905 | ||
906 | case ZV_LINE_BITMAP: | |
907 | wd = zv_width; | |
976b73d7 KS |
908 | h = zv_height - (y % zv_period); |
909 | bits = zv_bits + (y % zv_period); | |
06a2c219 GM |
910 | break; |
911 | ||
912 | default: | |
913 | abort (); | |
914 | } | |
915 | ||
976b73d7 KS |
916 | /* Clip bitmap if too high. */ |
917 | if (h > row->height) | |
918 | h = row->height; | |
919 | ||
920 | /* Set dy to the offset in the row to start drawing the bitmap. */ | |
06a2c219 GM |
921 | dy = (row->height - h) / 2; |
922 | ||
976b73d7 KS |
923 | face = FACE_FROM_ID (f, FRINGE_FACE_ID); |
924 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
925 | ||
926 | /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill | |
927 | the fringe. */ | |
dbdc9702 | 928 | b1 = b2 = -1; |
976b73d7 KS |
929 | if (left_p) |
930 | { | |
931 | if (wd > FRAME_X_LEFT_FRINGE_WIDTH (f)) | |
932 | wd = FRAME_X_LEFT_FRINGE_WIDTH (f); | |
933 | x = (WINDOW_TO_FRAME_PIXEL_X (w, 0) | |
934 | - wd | |
935 | - (FRAME_X_LEFT_FRINGE_WIDTH (f) - wd) / 2); | |
936 | if (wd < FRAME_X_LEFT_FRINGE_WIDTH (f) || row->height > h) | |
937 | { | |
938 | /* If W has a vertical border to its left, don't draw over it. */ | |
939 | int border = ((XFASTINT (w->left) > 0 | |
940 | && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
941 | ? 1 : 0); | |
942 | b1 = (window_box_left (w, -1) | |
943 | - FRAME_X_LEFT_FRINGE_WIDTH (f) | |
944 | + border); | |
945 | b2 = (FRAME_X_LEFT_FRINGE_WIDTH (f) - border); | |
946 | } | |
947 | } | |
948 | else | |
949 | { | |
950 | if (wd > FRAME_X_RIGHT_FRINGE_WIDTH (f)) | |
951 | wd = FRAME_X_RIGHT_FRINGE_WIDTH (f); | |
952 | x = (window_box_right (w, -1) | |
953 | + (FRAME_X_RIGHT_FRINGE_WIDTH (f) - wd) / 2); | |
954 | /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill | |
955 | the fringe. */ | |
956 | if (wd < FRAME_X_RIGHT_FRINGE_WIDTH (f) || row->height > h) | |
957 | { | |
958 | b1 = window_box_right (w, -1); | |
959 | b2 = FRAME_X_RIGHT_FRINGE_WIDTH (f); | |
960 | } | |
961 | } | |
962 | ||
963 | if (b1 >= 0) | |
964 | { | |
965 | int header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); | |
966 | ||
967 | /* In case the same realized face is used for fringes and | |
968 | for something displayed in the text (e.g. face `region' on | |
969 | mono-displays, the fill style may have been changed to | |
970 | FillSolid in x_draw_glyph_string_background. */ | |
971 | if (face->stipple) | |
972 | XSetFillStyle (display, face->gc, FillOpaqueStippled); | |
973 | else | |
974 | XSetForeground (display, face->gc, face->background); | |
975 | ||
976 | XFillRectangle (display, window, face->gc, | |
977 | b1, | |
978 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
979 | row->y)), | |
980 | b2, | |
981 | row->visible_height); | |
982 | if (!face->stipple) | |
983 | XSetForeground (display, face->gc, face->foreground); | |
984 | } | |
985 | ||
dbdc9702 GM |
986 | if (which != NO_FRINGE_BITMAP) |
987 | { | |
988 | /* Draw the bitmap. I believe these small pixmaps can be cached | |
989 | by the server. */ | |
990 | pixmap = XCreatePixmapFromBitmapData (display, window, bits, wd, h, | |
991 | face->foreground, | |
992 | face->background, depth); | |
993 | XCopyArea (display, pixmap, window, gc, 0, 0, wd, h, x, y + dy); | |
994 | XFreePixmap (display, pixmap); | |
995 | } | |
996 | ||
06a2c219 GM |
997 | XSetClipMask (display, gc, None); |
998 | } | |
999 | ||
1000 | ||
3f332ef3 | 1001 | /* Draw fringe bitmaps for glyph row ROW on window W. Call this |
06a2c219 GM |
1002 | function with input blocked. */ |
1003 | ||
1004 | static void | |
3f332ef3 | 1005 | x_draw_row_fringe_bitmaps (w, row) |
06a2c219 GM |
1006 | struct window *w; |
1007 | struct glyph_row *row; | |
1008 | { | |
1009 | struct frame *f = XFRAME (w->frame); | |
3f332ef3 | 1010 | enum fringe_bitmap_type bitmap; |
06a2c219 GM |
1011 | |
1012 | xassert (interrupt_input_blocked); | |
1013 | ||
1014 | /* If row is completely invisible, because of vscrolling, we | |
1015 | don't have to draw anything. */ | |
1016 | if (row->visible_height <= 0) | |
1017 | return; | |
1018 | ||
976b73d7 KS |
1019 | if (FRAME_X_LEFT_FRINGE_WIDTH (f) != 0) |
1020 | { | |
1021 | /* Decide which bitmap to draw in the left fringe. */ | |
1022 | if (row->overlay_arrow_p) | |
1023 | bitmap = OVERLAY_ARROW_BITMAP; | |
1024 | else if (row->truncated_on_left_p) | |
1025 | bitmap = LEFT_TRUNCATION_BITMAP; | |
1026 | else if (MATRIX_ROW_CONTINUATION_LINE_P (row)) | |
1027 | bitmap = CONTINUATION_LINE_BITMAP; | |
1028 | else if (row->indicate_empty_line_p) | |
1029 | bitmap = ZV_LINE_BITMAP; | |
dcd08bfb | 1030 | else |
976b73d7 | 1031 | bitmap = NO_FRINGE_BITMAP; |
06a2c219 | 1032 | |
976b73d7 KS |
1033 | x_draw_fringe_bitmap (w, row, bitmap, 1); |
1034 | } | |
06a2c219 | 1035 | |
976b73d7 | 1036 | if (FRAME_X_RIGHT_FRINGE_WIDTH (f) != 0) |
06a2c219 | 1037 | { |
976b73d7 KS |
1038 | /* Decide which bitmap to draw in the right fringe. */ |
1039 | if (row->truncated_on_right_p) | |
1040 | bitmap = RIGHT_TRUNCATION_BITMAP; | |
1041 | else if (row->continued_p) | |
1042 | bitmap = CONTINUED_LINE_BITMAP; | |
1043 | else if (row->indicate_empty_line_p && FRAME_X_LEFT_FRINGE_WIDTH (f) == 0) | |
1044 | bitmap = ZV_LINE_BITMAP; | |
dcd08bfb | 1045 | else |
976b73d7 | 1046 | bitmap = NO_FRINGE_BITMAP; |
06a2c219 | 1047 | |
976b73d7 KS |
1048 | x_draw_fringe_bitmap (w, row, bitmap, 0); |
1049 | } | |
06a2c219 GM |
1050 | } |
1051 | ||
dc6f92b8 | 1052 | \f |
06a2c219 GM |
1053 | |
1054 | /* This is called when starting Emacs and when restarting after | |
1055 | suspend. When starting Emacs, no X window is mapped. And nothing | |
1056 | must be done to Emacs's own window if it is suspended (though that | |
1057 | rarely happens). */ | |
dc6f92b8 | 1058 | |
dfcf069d | 1059 | static void |
dc6f92b8 JB |
1060 | XTset_terminal_modes () |
1061 | { | |
1062 | } | |
1063 | ||
06a2c219 GM |
1064 | /* This is called when exiting or suspending Emacs. Exiting will make |
1065 | the X-windows go away, and suspending requires no action. */ | |
dc6f92b8 | 1066 | |
dfcf069d | 1067 | static void |
dc6f92b8 JB |
1068 | XTreset_terminal_modes () |
1069 | { | |
dc6f92b8 | 1070 | } |
06a2c219 GM |
1071 | |
1072 | ||
dc6f92b8 | 1073 | \f |
06a2c219 GM |
1074 | /*********************************************************************** |
1075 | Output Cursor | |
1076 | ***********************************************************************/ | |
1077 | ||
1078 | /* Set the global variable output_cursor to CURSOR. All cursor | |
1079 | positions are relative to updated_window. */ | |
dc6f92b8 | 1080 | |
dfcf069d | 1081 | static void |
06a2c219 GM |
1082 | set_output_cursor (cursor) |
1083 | struct cursor_pos *cursor; | |
dc6f92b8 | 1084 | { |
06a2c219 GM |
1085 | output_cursor.hpos = cursor->hpos; |
1086 | output_cursor.vpos = cursor->vpos; | |
1087 | output_cursor.x = cursor->x; | |
1088 | output_cursor.y = cursor->y; | |
1089 | } | |
1090 | ||
1091 | ||
1092 | /* Set a nominal cursor position. | |
dc6f92b8 | 1093 | |
06a2c219 GM |
1094 | HPOS and VPOS are column/row positions in a window glyph matrix. X |
1095 | and Y are window text area relative pixel positions. | |
1096 | ||
1097 | If this is done during an update, updated_window will contain the | |
1098 | window that is being updated and the position is the future output | |
1099 | cursor position for that window. If updated_window is null, use | |
1100 | selected_window and display the cursor at the given position. */ | |
1101 | ||
1102 | static void | |
1103 | XTcursor_to (vpos, hpos, y, x) | |
1104 | int vpos, hpos, y, x; | |
1105 | { | |
1106 | struct window *w; | |
1107 | ||
1108 | /* If updated_window is not set, work on selected_window. */ | |
1109 | if (updated_window) | |
1110 | w = updated_window; | |
1111 | else | |
1112 | w = XWINDOW (selected_window); | |
dbcb258a | 1113 | |
06a2c219 GM |
1114 | /* Set the output cursor. */ |
1115 | output_cursor.hpos = hpos; | |
1116 | output_cursor.vpos = vpos; | |
1117 | output_cursor.x = x; | |
1118 | output_cursor.y = y; | |
dc6f92b8 | 1119 | |
06a2c219 GM |
1120 | /* If not called as part of an update, really display the cursor. |
1121 | This will also set the cursor position of W. */ | |
1122 | if (updated_window == NULL) | |
dc6f92b8 JB |
1123 | { |
1124 | BLOCK_INPUT; | |
06a2c219 | 1125 | x_display_cursor (w, 1, hpos, vpos, x, y); |
b86bd3dd | 1126 | XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ())); |
dc6f92b8 JB |
1127 | UNBLOCK_INPUT; |
1128 | } | |
1129 | } | |
dc43ef94 | 1130 | |
06a2c219 GM |
1131 | |
1132 | \f | |
1133 | /*********************************************************************** | |
1134 | Display Iterator | |
1135 | ***********************************************************************/ | |
1136 | ||
1137 | /* Function prototypes of this page. */ | |
1138 | ||
1139 | static struct face *x_get_glyph_face_and_encoding P_ ((struct frame *, | |
1140 | struct glyph *, | |
ee569018 KH |
1141 | XChar2b *, |
1142 | int *)); | |
06a2c219 | 1143 | static struct face *x_get_char_face_and_encoding P_ ((struct frame *, int, |
abfb6b46 GM |
1144 | int, XChar2b *, int, |
1145 | int)); | |
06a2c219 GM |
1146 | static XCharStruct *x_per_char_metric P_ ((XFontStruct *, XChar2b *)); |
1147 | static void x_encode_char P_ ((int, XChar2b *, struct font_info *)); | |
1148 | static void x_append_glyph P_ ((struct it *)); | |
b4192550 | 1149 | static void x_append_composite_glyph P_ ((struct it *)); |
06a2c219 GM |
1150 | static void x_append_stretch_glyph P_ ((struct it *it, Lisp_Object, |
1151 | int, int, double)); | |
1152 | static void x_produce_glyphs P_ ((struct it *)); | |
06a2c219 | 1153 | static void x_produce_image_glyph P_ ((struct it *it)); |
ee569018 KH |
1154 | |
1155 | ||
e2ef8ee6 GM |
1156 | /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B |
1157 | is not contained in the font. */ | |
dc43ef94 | 1158 | |
06a2c219 | 1159 | static INLINE XCharStruct * |
ee569018 | 1160 | x_per_char_metric (font, char2b) |
06a2c219 GM |
1161 | XFontStruct *font; |
1162 | XChar2b *char2b; | |
1163 | { | |
1164 | /* The result metric information. */ | |
1165 | XCharStruct *pcm = NULL; | |
dc6f92b8 | 1166 | |
06a2c219 | 1167 | xassert (font && char2b); |
dc6f92b8 | 1168 | |
06a2c219 | 1169 | if (font->per_char != NULL) |
dc6f92b8 | 1170 | { |
06a2c219 | 1171 | if (font->min_byte1 == 0 && font->max_byte1 == 0) |
dc43ef94 | 1172 | { |
06a2c219 GM |
1173 | /* min_char_or_byte2 specifies the linear character index |
1174 | corresponding to the first element of the per_char array, | |
1175 | max_char_or_byte2 is the index of the last character. A | |
1176 | character with non-zero CHAR2B->byte1 is not in the font. | |
1177 | A character with byte2 less than min_char_or_byte2 or | |
1178 | greater max_char_or_byte2 is not in the font. */ | |
1179 | if (char2b->byte1 == 0 | |
1180 | && char2b->byte2 >= font->min_char_or_byte2 | |
1181 | && char2b->byte2 <= font->max_char_or_byte2) | |
1182 | pcm = font->per_char + char2b->byte2 - font->min_char_or_byte2; | |
dc43ef94 | 1183 | } |
06a2c219 | 1184 | else |
dc6f92b8 | 1185 | { |
06a2c219 GM |
1186 | /* If either min_byte1 or max_byte1 are nonzero, both |
1187 | min_char_or_byte2 and max_char_or_byte2 are less than | |
1188 | 256, and the 2-byte character index values corresponding | |
1189 | to the per_char array element N (counting from 0) are: | |
1190 | ||
1191 | byte1 = N/D + min_byte1 | |
1192 | byte2 = N\D + min_char_or_byte2 | |
1193 | ||
1194 | where: | |
1195 | ||
1196 | D = max_char_or_byte2 - min_char_or_byte2 + 1 | |
1197 | / = integer division | |
1198 | \ = integer modulus */ | |
1199 | if (char2b->byte1 >= font->min_byte1 | |
1200 | && char2b->byte1 <= font->max_byte1 | |
1201 | && char2b->byte2 >= font->min_char_or_byte2 | |
1202 | && char2b->byte2 <= font->max_char_or_byte2) | |
1203 | { | |
1204 | pcm = (font->per_char | |
1205 | + ((font->max_char_or_byte2 - font->min_char_or_byte2 + 1) | |
1206 | * (char2b->byte1 - font->min_byte1)) | |
1207 | + (char2b->byte2 - font->min_char_or_byte2)); | |
1208 | } | |
dc6f92b8 | 1209 | } |
06a2c219 GM |
1210 | } |
1211 | else | |
1212 | { | |
1213 | /* If the per_char pointer is null, all glyphs between the first | |
1214 | and last character indexes inclusive have the same | |
1215 | information, as given by both min_bounds and max_bounds. */ | |
1216 | if (char2b->byte2 >= font->min_char_or_byte2 | |
1217 | && char2b->byte2 <= font->max_char_or_byte2) | |
1218 | pcm = &font->max_bounds; | |
1219 | } | |
dc6f92b8 | 1220 | |
ee569018 | 1221 | return ((pcm == NULL |
3e71d8f2 | 1222 | || (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0)) |
ee569018 | 1223 | ? NULL : pcm); |
06a2c219 | 1224 | } |
b73b6aaf | 1225 | |
57b03282 | 1226 | |
06a2c219 GM |
1227 | /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is |
1228 | the two-byte form of C. Encoding is returned in *CHAR2B. */ | |
dc43ef94 | 1229 | |
06a2c219 GM |
1230 | static INLINE void |
1231 | x_encode_char (c, char2b, font_info) | |
1232 | int c; | |
1233 | XChar2b *char2b; | |
1234 | struct font_info *font_info; | |
1235 | { | |
1236 | int charset = CHAR_CHARSET (c); | |
1237 | XFontStruct *font = font_info->font; | |
1238 | ||
1239 | /* FONT_INFO may define a scheme by which to encode byte1 and byte2. | |
1240 | This may be either a program in a special encoder language or a | |
1241 | fixed encoding. */ | |
1242 | if (font_info->font_encoder) | |
1243 | { | |
1244 | /* It's a program. */ | |
1245 | struct ccl_program *ccl = font_info->font_encoder; | |
1246 | ||
1247 | if (CHARSET_DIMENSION (charset) == 1) | |
1248 | { | |
1249 | ccl->reg[0] = charset; | |
1250 | ccl->reg[1] = char2b->byte2; | |
1251 | } | |
1252 | else | |
1253 | { | |
1254 | ccl->reg[0] = charset; | |
1255 | ccl->reg[1] = char2b->byte1; | |
1256 | ccl->reg[2] = char2b->byte2; | |
1257 | } | |
1258 | ||
1259 | ccl_driver (ccl, NULL, NULL, 0, 0, NULL); | |
1260 | ||
1261 | /* We assume that MSBs are appropriately set/reset by CCL | |
1262 | program. */ | |
1263 | if (font->max_byte1 == 0) /* 1-byte font */ | |
ee569018 | 1264 | char2b->byte1 = 0, char2b->byte2 = ccl->reg[1]; |
06a2c219 GM |
1265 | else |
1266 | char2b->byte1 = ccl->reg[1], char2b->byte2 = ccl->reg[2]; | |
1267 | } | |
1268 | else if (font_info->encoding[charset]) | |
1269 | { | |
1270 | /* Fixed encoding scheme. See fontset.h for the meaning of the | |
1271 | encoding numbers. */ | |
1272 | int enc = font_info->encoding[charset]; | |
1273 | ||
1274 | if ((enc == 1 || enc == 2) | |
1275 | && CHARSET_DIMENSION (charset) == 2) | |
1276 | char2b->byte1 |= 0x80; | |
1277 | ||
1278 | if (enc == 1 || enc == 3) | |
1279 | char2b->byte2 |= 0x80; | |
1280 | } | |
1281 | } | |
1282 | ||
1283 | ||
1284 | /* Get face and two-byte form of character C in face FACE_ID on frame | |
1285 | F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero | |
abfb6b46 GM |
1286 | means we want to display multibyte text. DISPLAY_P non-zero means |
1287 | make sure that X resources for the face returned are allocated. | |
1288 | Value is a pointer to a realized face that is ready for display if | |
1289 | DISPLAY_P is non-zero. */ | |
06a2c219 GM |
1290 | |
1291 | static INLINE struct face * | |
abfb6b46 | 1292 | x_get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p, display_p) |
06a2c219 GM |
1293 | struct frame *f; |
1294 | int c, face_id; | |
1295 | XChar2b *char2b; | |
abfb6b46 | 1296 | int multibyte_p, display_p; |
06a2c219 GM |
1297 | { |
1298 | struct face *face = FACE_FROM_ID (f, face_id); | |
1299 | ||
1300 | if (!multibyte_p) | |
1301 | { | |
1302 | /* Unibyte case. We don't have to encode, but we have to make | |
1303 | sure to use a face suitable for unibyte. */ | |
1304 | char2b->byte1 = 0; | |
1305 | char2b->byte2 = c; | |
ee569018 KH |
1306 | face_id = FACE_FOR_CHAR (f, face, c); |
1307 | face = FACE_FROM_ID (f, face_id); | |
06a2c219 GM |
1308 | } |
1309 | else if (c < 128 && face_id < BASIC_FACE_ID_SENTINEL) | |
1310 | { | |
1311 | /* Case of ASCII in a face known to fit ASCII. */ | |
1312 | char2b->byte1 = 0; | |
1313 | char2b->byte2 = c; | |
1314 | } | |
1315 | else | |
1316 | { | |
1317 | int c1, c2, charset; | |
1318 | ||
1319 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1320 | really a one-byte character so that byte1 is zero. */ | |
1321 | SPLIT_CHAR (c, charset, c1, c2); | |
1322 | if (c2 > 0) | |
1323 | char2b->byte1 = c1, char2b->byte2 = c2; | |
1324 | else | |
1325 | char2b->byte1 = 0, char2b->byte2 = c1; | |
1326 | ||
06a2c219 | 1327 | /* Maybe encode the character in *CHAR2B. */ |
ee569018 | 1328 | if (face->font != NULL) |
06a2c219 GM |
1329 | { |
1330 | struct font_info *font_info | |
1331 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1332 | if (font_info) | |
ee569018 | 1333 | x_encode_char (c, char2b, font_info); |
06a2c219 GM |
1334 | } |
1335 | } | |
1336 | ||
1337 | /* Make sure X resources of the face are allocated. */ | |
abfb6b46 GM |
1338 | if (display_p) |
1339 | { | |
1340 | xassert (face != NULL); | |
1341 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1342 | } | |
06a2c219 GM |
1343 | |
1344 | return face; | |
1345 | } | |
1346 | ||
1347 | ||
1348 | /* Get face and two-byte form of character glyph GLYPH on frame F. | |
43d120d8 | 1349 | The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is |
06a2c219 GM |
1350 | a pointer to a realized face that is ready for display. */ |
1351 | ||
1352 | static INLINE struct face * | |
ee569018 | 1353 | x_get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p) |
06a2c219 GM |
1354 | struct frame *f; |
1355 | struct glyph *glyph; | |
1356 | XChar2b *char2b; | |
ee569018 | 1357 | int *two_byte_p; |
06a2c219 GM |
1358 | { |
1359 | struct face *face; | |
1360 | ||
1361 | xassert (glyph->type == CHAR_GLYPH); | |
43d120d8 | 1362 | face = FACE_FROM_ID (f, glyph->face_id); |
06a2c219 | 1363 | |
ee569018 KH |
1364 | if (two_byte_p) |
1365 | *two_byte_p = 0; | |
1366 | ||
06a2c219 GM |
1367 | if (!glyph->multibyte_p) |
1368 | { | |
1369 | /* Unibyte case. We don't have to encode, but we have to make | |
1370 | sure to use a face suitable for unibyte. */ | |
1371 | char2b->byte1 = 0; | |
43d120d8 | 1372 | char2b->byte2 = glyph->u.ch; |
06a2c219 | 1373 | } |
43d120d8 KH |
1374 | else if (glyph->u.ch < 128 |
1375 | && glyph->face_id < BASIC_FACE_ID_SENTINEL) | |
06a2c219 GM |
1376 | { |
1377 | /* Case of ASCII in a face known to fit ASCII. */ | |
1378 | char2b->byte1 = 0; | |
43d120d8 | 1379 | char2b->byte2 = glyph->u.ch; |
06a2c219 GM |
1380 | } |
1381 | else | |
1382 | { | |
1383 | int c1, c2, charset; | |
1384 | ||
1385 | /* Split characters into bytes. If c2 is -1 afterwards, C is | |
1386 | really a one-byte character so that byte1 is zero. */ | |
43d120d8 | 1387 | SPLIT_CHAR (glyph->u.ch, charset, c1, c2); |
06a2c219 GM |
1388 | if (c2 > 0) |
1389 | char2b->byte1 = c1, char2b->byte2 = c2; | |
1390 | else | |
1391 | char2b->byte1 = 0, char2b->byte2 = c1; | |
1392 | ||
1393 | /* Maybe encode the character in *CHAR2B. */ | |
1394 | if (charset != CHARSET_ASCII) | |
1395 | { | |
1396 | struct font_info *font_info | |
1397 | = FONT_INFO_FROM_ID (f, face->font_info_id); | |
1398 | if (font_info) | |
1399 | { | |
43d120d8 | 1400 | x_encode_char (glyph->u.ch, char2b, font_info); |
ee569018 KH |
1401 | if (two_byte_p) |
1402 | *two_byte_p | |
1403 | = ((XFontStruct *) (font_info->font))->max_byte1 > 0; | |
06a2c219 GM |
1404 | } |
1405 | } | |
1406 | } | |
1407 | ||
1408 | /* Make sure X resources of the face are allocated. */ | |
1409 | xassert (face != NULL); | |
1410 | PREPARE_FACE_FOR_DISPLAY (f, face); | |
1411 | return face; | |
1412 | } | |
1413 | ||
1414 | ||
1415 | /* Store one glyph for IT->char_to_display in IT->glyph_row. | |
1416 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1417 | ||
1418 | static INLINE void | |
1419 | x_append_glyph (it) | |
1420 | struct it *it; | |
1421 | { | |
1422 | struct glyph *glyph; | |
1423 | enum glyph_row_area area = it->area; | |
1424 | ||
1425 | xassert (it->glyph_row); | |
1426 | xassert (it->char_to_display != '\n' && it->char_to_display != '\t'); | |
1427 | ||
1428 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1429 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1430 | { | |
06a2c219 GM |
1431 | glyph->charpos = CHARPOS (it->position); |
1432 | glyph->object = it->object; | |
88d75730 | 1433 | glyph->pixel_width = it->pixel_width; |
06a2c219 | 1434 | glyph->voffset = it->voffset; |
88d75730 | 1435 | glyph->type = CHAR_GLYPH; |
06a2c219 | 1436 | glyph->multibyte_p = it->multibyte_p; |
88d75730 GM |
1437 | glyph->left_box_line_p = it->start_of_box_run_p; |
1438 | glyph->right_box_line_p = it->end_of_box_run_p; | |
66ac4b0e GM |
1439 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1440 | || it->phys_descent > it->descent); | |
88d75730 | 1441 | glyph->padding_p = 0; |
ee569018 | 1442 | glyph->glyph_not_available_p = it->glyph_not_available_p; |
88d75730 GM |
1443 | glyph->face_id = it->face_id; |
1444 | glyph->u.ch = it->char_to_display; | |
06a2c219 GM |
1445 | ++it->glyph_row->used[area]; |
1446 | } | |
1447 | } | |
1448 | ||
b4192550 KH |
1449 | /* Store one glyph for the composition IT->cmp_id in IT->glyph_row. |
1450 | Called from x_produce_glyphs when IT->glyph_row is non-null. */ | |
1451 | ||
1452 | static INLINE void | |
1453 | x_append_composite_glyph (it) | |
1454 | struct it *it; | |
1455 | { | |
1456 | struct glyph *glyph; | |
1457 | enum glyph_row_area area = it->area; | |
1458 | ||
1459 | xassert (it->glyph_row); | |
1460 | ||
1461 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1462 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1463 | { | |
b4192550 KH |
1464 | glyph->charpos = CHARPOS (it->position); |
1465 | glyph->object = it->object; | |
88d75730 | 1466 | glyph->pixel_width = it->pixel_width; |
b4192550 | 1467 | glyph->voffset = it->voffset; |
88d75730 | 1468 | glyph->type = COMPOSITE_GLYPH; |
b4192550 | 1469 | glyph->multibyte_p = it->multibyte_p; |
88d75730 GM |
1470 | glyph->left_box_line_p = it->start_of_box_run_p; |
1471 | glyph->right_box_line_p = it->end_of_box_run_p; | |
b4192550 KH |
1472 | glyph->overlaps_vertically_p = (it->phys_ascent > it->ascent |
1473 | || it->phys_descent > it->descent); | |
88d75730 GM |
1474 | glyph->padding_p = 0; |
1475 | glyph->glyph_not_available_p = 0; | |
1476 | glyph->face_id = it->face_id; | |
1477 | glyph->u.cmp_id = it->cmp_id; | |
b4192550 KH |
1478 | ++it->glyph_row->used[area]; |
1479 | } | |
1480 | } | |
1481 | ||
06a2c219 GM |
1482 | |
1483 | /* Change IT->ascent and IT->height according to the setting of | |
1484 | IT->voffset. */ | |
1485 | ||
1486 | static INLINE void | |
1487 | take_vertical_position_into_account (it) | |
1488 | struct it *it; | |
1489 | { | |
1490 | if (it->voffset) | |
1491 | { | |
1492 | if (it->voffset < 0) | |
1493 | /* Increase the ascent so that we can display the text higher | |
1494 | in the line. */ | |
1495 | it->ascent += abs (it->voffset); | |
1496 | else | |
1497 | /* Increase the descent so that we can display the text lower | |
1498 | in the line. */ | |
1499 | it->descent += it->voffset; | |
1500 | } | |
1501 | } | |
1502 | ||
1503 | ||
1504 | /* Produce glyphs/get display metrics for the image IT is loaded with. | |
1505 | See the description of struct display_iterator in dispextern.h for | |
1506 | an overview of struct display_iterator. */ | |
1507 | ||
1508 | static void | |
1509 | x_produce_image_glyph (it) | |
1510 | struct it *it; | |
1511 | { | |
1512 | struct image *img; | |
1513 | struct face *face; | |
1514 | ||
1515 | xassert (it->what == IT_IMAGE); | |
1516 | ||
1517 | face = FACE_FROM_ID (it->f, it->face_id); | |
1518 | img = IMAGE_FROM_ID (it->f, it->image_id); | |
1519 | xassert (img); | |
1520 | ||
1521 | /* Make sure X resources of the face and image are loaded. */ | |
1522 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1523 | prepare_image_for_display (it->f, img); | |
1524 | ||
95af8492 | 1525 | it->ascent = it->phys_ascent = image_ascent (img, face); |
22d650b8 GM |
1526 | it->descent = it->phys_descent = img->height + 2 * img->vmargin - it->ascent; |
1527 | it->pixel_width = img->width + 2 * img->hmargin; | |
06a2c219 GM |
1528 | |
1529 | it->nglyphs = 1; | |
1530 | ||
1531 | if (face->box != FACE_NO_BOX) | |
1532 | { | |
ea2ba0d4 KH |
1533 | if (face->box_line_width > 0) |
1534 | { | |
1535 | it->ascent += face->box_line_width; | |
1536 | it->descent += face->box_line_width; | |
1537 | } | |
06a2c219 GM |
1538 | |
1539 | if (it->start_of_box_run_p) | |
ea2ba0d4 | 1540 | it->pixel_width += abs (face->box_line_width); |
06a2c219 | 1541 | if (it->end_of_box_run_p) |
ea2ba0d4 | 1542 | it->pixel_width += abs (face->box_line_width); |
06a2c219 GM |
1543 | } |
1544 | ||
1545 | take_vertical_position_into_account (it); | |
1546 | ||
1547 | if (it->glyph_row) | |
1548 | { | |
1549 | struct glyph *glyph; | |
1550 | enum glyph_row_area area = it->area; | |
1551 | ||
1552 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1553 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1554 | { | |
06a2c219 GM |
1555 | glyph->charpos = CHARPOS (it->position); |
1556 | glyph->object = it->object; | |
88d75730 | 1557 | glyph->pixel_width = it->pixel_width; |
06a2c219 | 1558 | glyph->voffset = it->voffset; |
88d75730 | 1559 | glyph->type = IMAGE_GLYPH; |
06a2c219 | 1560 | glyph->multibyte_p = it->multibyte_p; |
88d75730 GM |
1561 | glyph->left_box_line_p = it->start_of_box_run_p; |
1562 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1563 | glyph->overlaps_vertically_p = 0; | |
1564 | glyph->padding_p = 0; | |
1565 | glyph->glyph_not_available_p = 0; | |
1566 | glyph->face_id = it->face_id; | |
1567 | glyph->u.img_id = img->id; | |
06a2c219 GM |
1568 | ++it->glyph_row->used[area]; |
1569 | } | |
1570 | } | |
1571 | } | |
1572 | ||
1573 | ||
1574 | /* Append a stretch glyph to IT->glyph_row. OBJECT is the source | |
1575 | of the glyph, WIDTH and HEIGHT are the width and height of the | |
1576 | stretch. ASCENT is the percentage/100 of HEIGHT to use for the | |
1577 | ascent of the glyph (0 <= ASCENT <= 1). */ | |
1578 | ||
1579 | static void | |
1580 | x_append_stretch_glyph (it, object, width, height, ascent) | |
1581 | struct it *it; | |
1582 | Lisp_Object object; | |
1583 | int width, height; | |
1584 | double ascent; | |
1585 | { | |
1586 | struct glyph *glyph; | |
1587 | enum glyph_row_area area = it->area; | |
1588 | ||
1589 | xassert (ascent >= 0 && ascent <= 1); | |
1590 | ||
1591 | glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area]; | |
1592 | if (glyph < it->glyph_row->glyphs[area + 1]) | |
1593 | { | |
06a2c219 GM |
1594 | glyph->charpos = CHARPOS (it->position); |
1595 | glyph->object = object; | |
88d75730 | 1596 | glyph->pixel_width = width; |
06a2c219 | 1597 | glyph->voffset = it->voffset; |
88d75730 | 1598 | glyph->type = STRETCH_GLYPH; |
06a2c219 | 1599 | glyph->multibyte_p = it->multibyte_p; |
88d75730 GM |
1600 | glyph->left_box_line_p = it->start_of_box_run_p; |
1601 | glyph->right_box_line_p = it->end_of_box_run_p; | |
1602 | glyph->overlaps_vertically_p = 0; | |
1603 | glyph->padding_p = 0; | |
1604 | glyph->glyph_not_available_p = 0; | |
1605 | glyph->face_id = it->face_id; | |
1606 | glyph->u.stretch.ascent = height * ascent; | |
1607 | glyph->u.stretch.height = height; | |
06a2c219 GM |
1608 | ++it->glyph_row->used[area]; |
1609 | } | |
1610 | } | |
1611 | ||
1612 | ||
1613 | /* Produce a stretch glyph for iterator IT. IT->object is the value | |
1614 | of the glyph property displayed. The value must be a list | |
1615 | `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs | |
1616 | being recognized: | |
1617 | ||
1618 | 1. `:width WIDTH' specifies that the space should be WIDTH * | |
1619 | canonical char width wide. WIDTH may be an integer or floating | |
1620 | point number. | |
1621 | ||
1622 | 2. `:relative-width FACTOR' specifies that the width of the stretch | |
1623 | should be computed from the width of the first character having the | |
1624 | `glyph' property, and should be FACTOR times that width. | |
1625 | ||
1626 | 3. `:align-to HPOS' specifies that the space should be wide enough | |
1627 | to reach HPOS, a value in canonical character units. | |
1628 | ||
1629 | Exactly one of the above pairs must be present. | |
1630 | ||
1631 | 4. `:height HEIGHT' specifies that the height of the stretch produced | |
1632 | should be HEIGHT, measured in canonical character units. | |
1633 | ||
269b7745 | 1634 | 5. `:relative-height FACTOR' specifies that the height of the |
06a2c219 GM |
1635 | stretch should be FACTOR times the height of the characters having |
1636 | the glyph property. | |
1637 | ||
1638 | Either none or exactly one of 4 or 5 must be present. | |
1639 | ||
1640 | 6. `:ascent ASCENT' specifies that ASCENT percent of the height | |
1641 | of the stretch should be used for the ascent of the stretch. | |
1642 | ASCENT must be in the range 0 <= ASCENT <= 100. */ | |
1643 | ||
1644 | #define NUMVAL(X) \ | |
1645 | ((INTEGERP (X) || FLOATP (X)) \ | |
1646 | ? XFLOATINT (X) \ | |
1647 | : - 1) | |
1648 | ||
1649 | ||
1650 | static void | |
1651 | x_produce_stretch_glyph (it) | |
1652 | struct it *it; | |
1653 | { | |
1654 | /* (space :width WIDTH :height HEIGHT. */ | |
3e71d8f2 GM |
1655 | #if GLYPH_DEBUG |
1656 | extern Lisp_Object Qspace; | |
1657 | #endif | |
1658 | extern Lisp_Object QCwidth, QCheight, QCascent; | |
06a2c219 GM |
1659 | extern Lisp_Object QCrelative_width, QCrelative_height; |
1660 | extern Lisp_Object QCalign_to; | |
1661 | Lisp_Object prop, plist; | |
1662 | double width = 0, height = 0, ascent = 0; | |
1663 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
1664 | XFontStruct *font = face->font ? face->font : FRAME_FONT (it->f); | |
1665 | ||
1666 | PREPARE_FACE_FOR_DISPLAY (it->f, face); | |
1667 | ||
1668 | /* List should start with `space'. */ | |
1669 | xassert (CONSP (it->object) && EQ (XCAR (it->object), Qspace)); | |
1670 | plist = XCDR (it->object); | |
1671 | ||
1672 | /* Compute the width of the stretch. */ | |
1673 | if (prop = Fplist_get (plist, QCwidth), | |
1674 | NUMVAL (prop) > 0) | |
1675 | /* Absolute width `:width WIDTH' specified and valid. */ | |
1676 | width = NUMVAL (prop) * CANON_X_UNIT (it->f); | |
1677 | else if (prop = Fplist_get (plist, QCrelative_width), | |
1678 | NUMVAL (prop) > 0) | |
1679 | { | |
1680 | /* Relative width `:relative-width FACTOR' specified and valid. | |
1681 | Compute the width of the characters having the `glyph' | |
1682 | property. */ | |
1683 | struct it it2; | |
1684 | unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); | |
1685 | ||
1686 | it2 = *it; | |
1687 | if (it->multibyte_p) | |
1688 | { | |
1689 | int maxlen = ((IT_BYTEPOS (*it) >= GPT ? ZV : GPT) | |
1690 | - IT_BYTEPOS (*it)); | |
1691 | it2.c = STRING_CHAR_AND_LENGTH (p, maxlen, it2.len); | |
1692 | } | |
1693 | else | |
1694 | it2.c = *p, it2.len = 1; | |
1695 | ||
1696 | it2.glyph_row = NULL; | |
1697 | it2.what = IT_CHARACTER; | |
1698 | x_produce_glyphs (&it2); | |
1699 | width = NUMVAL (prop) * it2.pixel_width; | |
1700 | } | |
1701 | else if (prop = Fplist_get (plist, QCalign_to), | |
1702 | NUMVAL (prop) > 0) | |
1703 | width = NUMVAL (prop) * CANON_X_UNIT (it->f) - it->current_x; | |
1704 | else | |
1705 | /* Nothing specified -> width defaults to canonical char width. */ | |
1706 | width = CANON_X_UNIT (it->f); | |
1707 | ||
1708 | /* Compute height. */ | |
1709 | if (prop = Fplist_get (plist, QCheight), | |
1710 | NUMVAL (prop) > 0) | |
1711 | height = NUMVAL (prop) * CANON_Y_UNIT (it->f); | |
1712 | else if (prop = Fplist_get (plist, QCrelative_height), | |
1713 | NUMVAL (prop) > 0) | |
1714 | height = FONT_HEIGHT (font) * NUMVAL (prop); | |
1715 | else | |
1716 | height = FONT_HEIGHT (font); | |
1717 | ||
1718 | /* Compute percentage of height used for ascent. If | |
1719 | `:ascent ASCENT' is present and valid, use that. Otherwise, | |
1720 | derive the ascent from the font in use. */ | |
1721 | if (prop = Fplist_get (plist, QCascent), | |
1722 | NUMVAL (prop) > 0 && NUMVAL (prop) <= 100) | |
1723 | ascent = NUMVAL (prop) / 100.0; | |
1724 | else | |
1725 | ascent = (double) font->ascent / FONT_HEIGHT (font); | |
1726 | ||
1727 | if (width <= 0) | |
1728 | width = 1; | |
1729 | if (height <= 0) | |
1730 | height = 1; | |
1731 | ||
1732 | if (it->glyph_row) | |
1733 | { | |
1734 | Lisp_Object object = it->stack[it->sp - 1].string; | |
1735 | if (!STRINGP (object)) | |
1736 | object = it->w->buffer; | |
1737 | x_append_stretch_glyph (it, object, width, height, ascent); | |
1738 | } | |
1739 | ||
1740 | it->pixel_width = width; | |
66ac4b0e GM |
1741 | it->ascent = it->phys_ascent = height * ascent; |
1742 | it->descent = it->phys_descent = height - it->ascent; | |
06a2c219 GM |
1743 | it->nglyphs = 1; |
1744 | ||
1745 | if (face->box != FACE_NO_BOX) | |
1746 | { | |
ea2ba0d4 KH |
1747 | if (face->box_line_width > 0) |
1748 | { | |
1749 | it->ascent += face->box_line_width; | |
1750 | it->descent += face->box_line_width; | |
1751 | } | |
06a2c219 GM |
1752 | |
1753 | if (it->start_of_box_run_p) | |
ea2ba0d4 | 1754 | it->pixel_width += abs (face->box_line_width); |
06a2c219 | 1755 | if (it->end_of_box_run_p) |
ea2ba0d4 | 1756 | it->pixel_width += abs (face->box_line_width); |
06a2c219 GM |
1757 | } |
1758 | ||
1759 | take_vertical_position_into_account (it); | |
1760 | } | |
1761 | ||
b4192550 KH |
1762 | /* Return proper value to be used as baseline offset of font that has |
1763 | ASCENT and DESCENT to draw characters by the font at the vertical | |
1764 | center of the line of frame F. | |
1765 | ||
1766 | Here, out task is to find the value of BOFF in the following figure; | |
1767 | ||
1768 | -------------------------+-----------+- | |
1769 | -+-+---------+-+ | | | |
1770 | | | | | | | | |
1771 | | | | | F_ASCENT F_HEIGHT | |
1772 | | | | ASCENT | | | |
1773 | HEIGHT | | | | | | |
1774 | | | |-|-+------+-----------|------- baseline | |
1775 | | | | | BOFF | | | |
1776 | | |---------|-+-+ | | | |
1777 | | | | DESCENT | | | |
1778 | -+-+---------+-+ F_DESCENT | | |
1779 | -------------------------+-----------+- | |
1780 | ||
1781 | -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT | |
1782 | BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT | |
1783 | DESCENT = FONT->descent | |
1784 | HEIGHT = FONT_HEIGHT (FONT) | |
1785 | F_DESCENT = (F->output_data.x->font->descent | |
1786 | - F->output_data.x->baseline_offset) | |
1787 | F_HEIGHT = FRAME_LINE_HEIGHT (F) | |
1788 | */ | |
1789 | ||
458f45fa KH |
1790 | #define VCENTER_BASELINE_OFFSET(FONT, F) \ |
1791 | ((FONT)->descent \ | |
1792 | + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \ | |
1793 | + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \ | |
1794 | - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset)) | |
06a2c219 GM |
1795 | |
1796 | /* Produce glyphs/get display metrics for the display element IT is | |
1797 | loaded with. See the description of struct display_iterator in | |
1798 | dispextern.h for an overview of struct display_iterator. */ | |
1799 | ||
1800 | static void | |
1801 | x_produce_glyphs (it) | |
1802 | struct it *it; | |
1803 | { | |
ee569018 KH |
1804 | it->glyph_not_available_p = 0; |
1805 | ||
06a2c219 GM |
1806 | if (it->what == IT_CHARACTER) |
1807 | { | |
1808 | XChar2b char2b; | |
1809 | XFontStruct *font; | |
ee569018 | 1810 | struct face *face = FACE_FROM_ID (it->f, it->face_id); |
06a2c219 | 1811 | XCharStruct *pcm; |
06a2c219 | 1812 | int font_not_found_p; |
b4192550 KH |
1813 | struct font_info *font_info; |
1814 | int boff; /* baseline offset */ | |
a4249304 KH |
1815 | /* We may change it->multibyte_p upon unibyte<->multibyte |
1816 | conversion. So, save the current value now and restore it | |
1817 | later. | |
1818 | ||
1819 | Note: It seems that we don't have to record multibyte_p in | |
1820 | struct glyph because the character code itself tells if or | |
1821 | not the character is multibyte. Thus, in the future, we must | |
1822 | consider eliminating the field `multibyte_p' in the struct | |
c347a1c3 | 1823 | glyph. */ |
a4249304 | 1824 | int saved_multibyte_p = it->multibyte_p; |
06a2c219 | 1825 | |
ee569018 KH |
1826 | /* Maybe translate single-byte characters to multibyte, or the |
1827 | other way. */ | |
06a2c219 | 1828 | it->char_to_display = it->c; |
ee569018 | 1829 | if (!ASCII_BYTE_P (it->c)) |
06a2c219 | 1830 | { |
ee569018 KH |
1831 | if (unibyte_display_via_language_environment |
1832 | && SINGLE_BYTE_CHAR_P (it->c) | |
1833 | && (it->c >= 0240 | |
1834 | || !NILP (Vnonascii_translation_table))) | |
1835 | { | |
1836 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
a4249304 | 1837 | it->multibyte_p = 1; |
ee569018 KH |
1838 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1839 | face = FACE_FROM_ID (it->f, it->face_id); | |
1840 | } | |
1841 | else if (!SINGLE_BYTE_CHAR_P (it->c) | |
1842 | && !it->multibyte_p) | |
1843 | { | |
c347a1c3 | 1844 | it->multibyte_p = 1; |
ee569018 KH |
1845 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
1846 | face = FACE_FROM_ID (it->f, it->face_id); | |
1847 | } | |
06a2c219 GM |
1848 | } |
1849 | ||
ee569018 KH |
1850 | /* Get font to use. Encode IT->char_to_display. */ |
1851 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
1852 | it->face_id, &char2b, | |
abfb6b46 | 1853 | it->multibyte_p, 0); |
06a2c219 GM |
1854 | font = face->font; |
1855 | ||
1856 | /* When no suitable font found, use the default font. */ | |
1857 | font_not_found_p = font == NULL; | |
1858 | if (font_not_found_p) | |
b4192550 KH |
1859 | { |
1860 | font = FRAME_FONT (it->f); | |
1861 | boff = it->f->output_data.x->baseline_offset; | |
1862 | font_info = NULL; | |
1863 | } | |
1864 | else | |
1865 | { | |
1866 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
1867 | boff = font_info->baseline_offset; | |
1868 | if (font_info->vertical_centering) | |
1869 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
1870 | } | |
06a2c219 GM |
1871 | |
1872 | if (it->char_to_display >= ' ' | |
1873 | && (!it->multibyte_p || it->char_to_display < 128)) | |
1874 | { | |
1875 | /* Either unibyte or ASCII. */ | |
1876 | int stretched_p; | |
1877 | ||
1878 | it->nglyphs = 1; | |
06a2c219 GM |
1879 | |
1880 | pcm = x_per_char_metric (font, &char2b); | |
b4192550 KH |
1881 | it->ascent = font->ascent + boff; |
1882 | it->descent = font->descent - boff; | |
474848ac GM |
1883 | |
1884 | if (pcm) | |
1885 | { | |
1886 | it->phys_ascent = pcm->ascent + boff; | |
1887 | it->phys_descent = pcm->descent - boff; | |
1888 | it->pixel_width = pcm->width; | |
1889 | } | |
1890 | else | |
1891 | { | |
1892 | it->glyph_not_available_p = 1; | |
1893 | it->phys_ascent = font->ascent + boff; | |
1894 | it->phys_descent = font->descent - boff; | |
1895 | it->pixel_width = FONT_WIDTH (font); | |
1896 | } | |
06a2c219 GM |
1897 | |
1898 | /* If this is a space inside a region of text with | |
1899 | `space-width' property, change its width. */ | |
1900 | stretched_p = it->char_to_display == ' ' && !NILP (it->space_width); | |
1901 | if (stretched_p) | |
1902 | it->pixel_width *= XFLOATINT (it->space_width); | |
1903 | ||
1904 | /* If face has a box, add the box thickness to the character | |
1905 | height. If character has a box line to the left and/or | |
1906 | right, add the box line width to the character's width. */ | |
1907 | if (face->box != FACE_NO_BOX) | |
1908 | { | |
1909 | int thick = face->box_line_width; | |
1910 | ||
ea2ba0d4 KH |
1911 | if (thick > 0) |
1912 | { | |
1913 | it->ascent += thick; | |
1914 | it->descent += thick; | |
1915 | } | |
1916 | else | |
1917 | thick = -thick; | |
1918 | ||
06a2c219 GM |
1919 | if (it->start_of_box_run_p) |
1920 | it->pixel_width += thick; | |
1921 | if (it->end_of_box_run_p) | |
1922 | it->pixel_width += thick; | |
1923 | } | |
1924 | ||
1925 | /* If face has an overline, add the height of the overline | |
1926 | (1 pixel) and a 1 pixel margin to the character height. */ | |
1927 | if (face->overline_p) | |
1928 | it->ascent += 2; | |
1929 | ||
1930 | take_vertical_position_into_account (it); | |
1931 | ||
1932 | /* If we have to actually produce glyphs, do it. */ | |
1933 | if (it->glyph_row) | |
1934 | { | |
1935 | if (stretched_p) | |
1936 | { | |
1937 | /* Translate a space with a `space-width' property | |
1938 | into a stretch glyph. */ | |
1939 | double ascent = (double) font->ascent / FONT_HEIGHT (font); | |
1940 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
1941 | it->ascent + it->descent, ascent); | |
1942 | } | |
1943 | else | |
1944 | x_append_glyph (it); | |
1945 | ||
1946 | /* If characters with lbearing or rbearing are displayed | |
1947 | in this line, record that fact in a flag of the | |
1948 | glyph row. This is used to optimize X output code. */ | |
1c7e22fd | 1949 | if (pcm && (pcm->lbearing < 0 || pcm->rbearing > pcm->width)) |
06a2c219 GM |
1950 | it->glyph_row->contains_overlapping_glyphs_p = 1; |
1951 | } | |
1952 | } | |
1953 | else if (it->char_to_display == '\n') | |
1954 | { | |
1955 | /* A newline has no width but we need the height of the line. */ | |
1956 | it->pixel_width = 0; | |
1957 | it->nglyphs = 0; | |
b4192550 KH |
1958 | it->ascent = it->phys_ascent = font->ascent + boff; |
1959 | it->descent = it->phys_descent = font->descent - boff; | |
06a2c219 | 1960 | |
ea2ba0d4 KH |
1961 | if (face->box != FACE_NO_BOX |
1962 | && face->box_line_width > 0) | |
06a2c219 | 1963 | { |
ea2ba0d4 KH |
1964 | it->ascent += face->box_line_width; |
1965 | it->descent += face->box_line_width; | |
06a2c219 GM |
1966 | } |
1967 | } | |
1968 | else if (it->char_to_display == '\t') | |
1969 | { | |
1970 | int tab_width = it->tab_width * CANON_X_UNIT (it->f); | |
d365f5bb | 1971 | int x = it->current_x + it->continuation_lines_width; |
06a2c219 | 1972 | int next_tab_x = ((1 + x + tab_width - 1) / tab_width) * tab_width; |
2a32b5ea GM |
1973 | |
1974 | /* If the distance from the current position to the next tab | |
1975 | stop is less than a canonical character width, use the | |
1976 | tab stop after that. */ | |
1977 | if (next_tab_x - x < CANON_X_UNIT (it->f)) | |
1978 | next_tab_x += tab_width; | |
06a2c219 GM |
1979 | |
1980 | it->pixel_width = next_tab_x - x; | |
1981 | it->nglyphs = 1; | |
b4192550 KH |
1982 | it->ascent = it->phys_ascent = font->ascent + boff; |
1983 | it->descent = it->phys_descent = font->descent - boff; | |
06a2c219 GM |
1984 | |
1985 | if (it->glyph_row) | |
1986 | { | |
1987 | double ascent = (double) it->ascent / (it->ascent + it->descent); | |
1988 | x_append_stretch_glyph (it, it->object, it->pixel_width, | |
1989 | it->ascent + it->descent, ascent); | |
1990 | } | |
1991 | } | |
1992 | else | |
1993 | { | |
1994 | /* A multi-byte character. Assume that the display width of the | |
1995 | character is the width of the character multiplied by the | |
b4192550 | 1996 | width of the font. */ |
06a2c219 | 1997 | |
b4192550 KH |
1998 | /* If we found a font, this font should give us the right |
1999 | metrics. If we didn't find a font, use the frame's | |
2000 | default font and calculate the width of the character | |
2001 | from the charset width; this is what old redisplay code | |
2002 | did. */ | |
2003 | pcm = x_per_char_metric (font, &char2b); | |
ee569018 KH |
2004 | if (font_not_found_p || !pcm) |
2005 | { | |
2006 | int charset = CHAR_CHARSET (it->char_to_display); | |
2007 | ||
2008 | it->glyph_not_available_p = 1; | |
2009 | it->pixel_width = (FONT_WIDTH (FRAME_FONT (it->f)) | |
2010 | * CHARSET_WIDTH (charset)); | |
2011 | it->phys_ascent = font->ascent + boff; | |
2012 | it->phys_descent = font->descent - boff; | |
2013 | } | |
2014 | else | |
2015 | { | |
2016 | it->pixel_width = pcm->width; | |
2017 | it->phys_ascent = pcm->ascent + boff; | |
2018 | it->phys_descent = pcm->descent - boff; | |
2019 | if (it->glyph_row | |
2020 | && (pcm->lbearing < 0 | |
2021 | || pcm->rbearing > pcm->width)) | |
2022 | it->glyph_row->contains_overlapping_glyphs_p = 1; | |
2023 | } | |
b4192550 KH |
2024 | it->nglyphs = 1; |
2025 | it->ascent = font->ascent + boff; | |
2026 | it->descent = font->descent - boff; | |
06a2c219 GM |
2027 | if (face->box != FACE_NO_BOX) |
2028 | { | |
2029 | int thick = face->box_line_width; | |
ea2ba0d4 KH |
2030 | |
2031 | if (thick > 0) | |
2032 | { | |
2033 | it->ascent += thick; | |
2034 | it->descent += thick; | |
2035 | } | |
2036 | else | |
2037 | thick = - thick; | |
06a2c219 GM |
2038 | |
2039 | if (it->start_of_box_run_p) | |
2040 | it->pixel_width += thick; | |
2041 | if (it->end_of_box_run_p) | |
2042 | it->pixel_width += thick; | |
2043 | } | |
2044 | ||
2045 | /* If face has an overline, add the height of the overline | |
2046 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2047 | if (face->overline_p) | |
2048 | it->ascent += 2; | |
2049 | ||
2050 | take_vertical_position_into_account (it); | |
2051 | ||
2052 | if (it->glyph_row) | |
2053 | x_append_glyph (it); | |
2054 | } | |
a4249304 | 2055 | it->multibyte_p = saved_multibyte_p; |
06a2c219 | 2056 | } |
b4192550 KH |
2057 | else if (it->what == IT_COMPOSITION) |
2058 | { | |
2059 | /* Note: A composition is represented as one glyph in the | |
2060 | glyph matrix. There are no padding glyphs. */ | |
2061 | XChar2b char2b; | |
2062 | XFontStruct *font; | |
ee569018 | 2063 | struct face *face = FACE_FROM_ID (it->f, it->face_id); |
b4192550 KH |
2064 | XCharStruct *pcm; |
2065 | int font_not_found_p; | |
2066 | struct font_info *font_info; | |
2067 | int boff; /* baseline offset */ | |
2068 | struct composition *cmp = composition_table[it->cmp_id]; | |
2069 | ||
2070 | /* Maybe translate single-byte characters to multibyte. */ | |
2071 | it->char_to_display = it->c; | |
2072 | if (unibyte_display_via_language_environment | |
2073 | && SINGLE_BYTE_CHAR_P (it->c) | |
2074 | && (it->c >= 0240 | |
2075 | || (it->c >= 0200 | |
2076 | && !NILP (Vnonascii_translation_table)))) | |
2077 | { | |
2078 | it->char_to_display = unibyte_char_to_multibyte (it->c); | |
b4192550 KH |
2079 | } |
2080 | ||
2081 | /* Get face and font to use. Encode IT->char_to_display. */ | |
ee569018 KH |
2082 | it->face_id = FACE_FOR_CHAR (it->f, face, it->char_to_display); |
2083 | face = FACE_FROM_ID (it->f, it->face_id); | |
2084 | x_get_char_face_and_encoding (it->f, it->char_to_display, | |
abfb6b46 | 2085 | it->face_id, &char2b, it->multibyte_p, 0); |
b4192550 KH |
2086 | font = face->font; |
2087 | ||
2088 | /* When no suitable font found, use the default font. */ | |
2089 | font_not_found_p = font == NULL; | |
2090 | if (font_not_found_p) | |
2091 | { | |
2092 | font = FRAME_FONT (it->f); | |
2093 | boff = it->f->output_data.x->baseline_offset; | |
2094 | font_info = NULL; | |
2095 | } | |
2096 | else | |
2097 | { | |
2098 | font_info = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2099 | boff = font_info->baseline_offset; | |
2100 | if (font_info->vertical_centering) | |
2101 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2102 | } | |
2103 | ||
2104 | /* There are no padding glyphs, so there is only one glyph to | |
2105 | produce for the composition. Important is that pixel_width, | |
2106 | ascent and descent are the values of what is drawn by | |
2107 | draw_glyphs (i.e. the values of the overall glyphs composed). */ | |
2108 | it->nglyphs = 1; | |
2109 | ||
2110 | /* If we have not yet calculated pixel size data of glyphs of | |
2111 | the composition for the current face font, calculate them | |
2112 | now. Theoretically, we have to check all fonts for the | |
2113 | glyphs, but that requires much time and memory space. So, | |
2114 | here we check only the font of the first glyph. This leads | |
2115 | to incorrect display very rarely, and C-l (recenter) can | |
2116 | correct the display anyway. */ | |
2117 | if (cmp->font != (void *) font) | |
2118 | { | |
2119 | /* Ascent and descent of the font of the first character of | |
2120 | this composition (adjusted by baseline offset). Ascent | |
2121 | and descent of overall glyphs should not be less than | |
2122 | them respectively. */ | |
2123 | int font_ascent = font->ascent + boff; | |
2124 | int font_descent = font->descent - boff; | |
2125 | /* Bounding box of the overall glyphs. */ | |
2126 | int leftmost, rightmost, lowest, highest; | |
329bed06 | 2127 | int i, width, ascent, descent; |
b4192550 KH |
2128 | |
2129 | cmp->font = (void *) font; | |
2130 | ||
2131 | /* Initialize the bounding box. */ | |
1bdeec2e KH |
2132 | if (font_info |
2133 | && (pcm = x_per_char_metric (font, &char2b))) | |
329bed06 GM |
2134 | { |
2135 | width = pcm->width; | |
2136 | ascent = pcm->ascent; | |
2137 | descent = pcm->descent; | |
2138 | } | |
2139 | else | |
2140 | { | |
2141 | width = FONT_WIDTH (font); | |
2142 | ascent = font->ascent; | |
2143 | descent = font->descent; | |
2144 | } | |
2145 | ||
2146 | rightmost = width; | |
2147 | lowest = - descent + boff; | |
2148 | highest = ascent + boff; | |
b4192550 | 2149 | leftmost = 0; |
329bed06 | 2150 | |
b4192550 KH |
2151 | if (font_info |
2152 | && font_info->default_ascent | |
2153 | && CHAR_TABLE_P (Vuse_default_ascent) | |
2154 | && !NILP (Faref (Vuse_default_ascent, | |
2155 | make_number (it->char_to_display)))) | |
2156 | highest = font_info->default_ascent + boff; | |
2157 | ||
2158 | /* Draw the first glyph at the normal position. It may be | |
2159 | shifted to right later if some other glyphs are drawn at | |
2160 | the left. */ | |
2161 | cmp->offsets[0] = 0; | |
2162 | cmp->offsets[1] = boff; | |
2163 | ||
2164 | /* Set cmp->offsets for the remaining glyphs. */ | |
2165 | for (i = 1; i < cmp->glyph_len; i++) | |
2166 | { | |
2167 | int left, right, btm, top; | |
2168 | int ch = COMPOSITION_GLYPH (cmp, i); | |
ee569018 KH |
2169 | int face_id = FACE_FOR_CHAR (it->f, face, ch); |
2170 | ||
2171 | face = FACE_FROM_ID (it->f, face_id); | |
2172 | x_get_char_face_and_encoding (it->f, ch, face->id, &char2b, | |
abfb6b46 | 2173 | it->multibyte_p, 0); |
b4192550 KH |
2174 | font = face->font; |
2175 | if (font == NULL) | |
2176 | { | |
2177 | font = FRAME_FONT (it->f); | |
2178 | boff = it->f->output_data.x->baseline_offset; | |
2179 | font_info = NULL; | |
2180 | } | |
2181 | else | |
2182 | { | |
2183 | font_info | |
2184 | = FONT_INFO_FROM_ID (it->f, face->font_info_id); | |
2185 | boff = font_info->baseline_offset; | |
2186 | if (font_info->vertical_centering) | |
2187 | boff = VCENTER_BASELINE_OFFSET (font, it->f) - boff; | |
2188 | } | |
2189 | ||
1bdeec2e KH |
2190 | if (font_info |
2191 | && (pcm = x_per_char_metric (font, &char2b))) | |
329bed06 GM |
2192 | { |
2193 | width = pcm->width; | |
2194 | ascent = pcm->ascent; | |
2195 | descent = pcm->descent; | |
2196 | } | |
2197 | else | |
2198 | { | |
2199 | width = FONT_WIDTH (font); | |
1bdeec2e KH |
2200 | ascent = 1; |
2201 | descent = 0; | |
329bed06 | 2202 | } |
b4192550 KH |
2203 | |
2204 | if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) | |
2205 | { | |
2206 | /* Relative composition with or without | |
2207 | alternate chars. */ | |
329bed06 GM |
2208 | left = (leftmost + rightmost - width) / 2; |
2209 | btm = - descent + boff; | |
b4192550 KH |
2210 | if (font_info && font_info->relative_compose |
2211 | && (! CHAR_TABLE_P (Vignore_relative_composition) | |
2212 | || NILP (Faref (Vignore_relative_composition, | |
2213 | make_number (ch))))) | |
2214 | { | |
2215 | ||
329bed06 | 2216 | if (- descent >= font_info->relative_compose) |
b4192550 KH |
2217 | /* One extra pixel between two glyphs. */ |
2218 | btm = highest + 1; | |
329bed06 | 2219 | else if (ascent <= 0) |
b4192550 | 2220 | /* One extra pixel between two glyphs. */ |
329bed06 | 2221 | btm = lowest - 1 - ascent - descent; |
b4192550 KH |
2222 | } |
2223 | } | |
2224 | else | |
2225 | { | |
2226 | /* A composition rule is specified by an integer | |
2227 | value that encodes global and new reference | |
2228 | points (GREF and NREF). GREF and NREF are | |
2229 | specified by numbers as below: | |
2230 | ||
2231 | 0---1---2 -- ascent | |
2232 | | | | |
2233 | | | | |
2234 | | | | |
2235 | 9--10--11 -- center | |
2236 | | | | |
2237 | ---3---4---5--- baseline | |
2238 | | | | |
2239 | 6---7---8 -- descent | |
2240 | */ | |
2241 | int rule = COMPOSITION_RULE (cmp, i); | |
2242 | int gref, nref, grefx, grefy, nrefx, nrefy; | |
2243 | ||
2244 | COMPOSITION_DECODE_RULE (rule, gref, nref); | |
2245 | grefx = gref % 3, nrefx = nref % 3; | |
2246 | grefy = gref / 3, nrefy = nref / 3; | |
2247 | ||
2248 | left = (leftmost | |
2249 | + grefx * (rightmost - leftmost) / 2 | |
329bed06 | 2250 | - nrefx * width / 2); |
b4192550 KH |
2251 | btm = ((grefy == 0 ? highest |
2252 | : grefy == 1 ? 0 | |
2253 | : grefy == 2 ? lowest | |
2254 | : (highest + lowest) / 2) | |
329bed06 GM |
2255 | - (nrefy == 0 ? ascent + descent |
2256 | : nrefy == 1 ? descent - boff | |
b4192550 | 2257 | : nrefy == 2 ? 0 |
329bed06 | 2258 | : (ascent + descent) / 2)); |
b4192550 KH |
2259 | } |
2260 | ||
2261 | cmp->offsets[i * 2] = left; | |
329bed06 | 2262 | cmp->offsets[i * 2 + 1] = btm + descent; |
b4192550 KH |
2263 | |
2264 | /* Update the bounding box of the overall glyphs. */ | |
329bed06 GM |
2265 | right = left + width; |
2266 | top = btm + descent + ascent; | |
b4192550 KH |
2267 | if (left < leftmost) |
2268 | leftmost = left; | |
2269 | if (right > rightmost) | |
2270 | rightmost = right; | |
2271 | if (top > highest) | |
2272 | highest = top; | |
2273 | if (btm < lowest) | |
2274 | lowest = btm; | |
2275 | } | |
2276 | ||
2277 | /* If there are glyphs whose x-offsets are negative, | |
2278 | shift all glyphs to the right and make all x-offsets | |
2279 | non-negative. */ | |
2280 | if (leftmost < 0) | |
2281 | { | |
2282 | for (i = 0; i < cmp->glyph_len; i++) | |
2283 | cmp->offsets[i * 2] -= leftmost; | |
2284 | rightmost -= leftmost; | |
2285 | } | |
2286 | ||
2287 | cmp->pixel_width = rightmost; | |
2288 | cmp->ascent = highest; | |
2289 | cmp->descent = - lowest; | |
2290 | if (cmp->ascent < font_ascent) | |
2291 | cmp->ascent = font_ascent; | |
2292 | if (cmp->descent < font_descent) | |
2293 | cmp->descent = font_descent; | |
2294 | } | |
2295 | ||
2296 | it->pixel_width = cmp->pixel_width; | |
2297 | it->ascent = it->phys_ascent = cmp->ascent; | |
2298 | it->descent = it->phys_descent = cmp->descent; | |
2299 | ||
2300 | if (face->box != FACE_NO_BOX) | |
2301 | { | |
2302 | int thick = face->box_line_width; | |
ea2ba0d4 KH |
2303 | |
2304 | if (thick > 0) | |
2305 | { | |
2306 | it->ascent += thick; | |
2307 | it->descent += thick; | |
2308 | } | |
2309 | else | |
2310 | thick = - thick; | |
b4192550 KH |
2311 | |
2312 | if (it->start_of_box_run_p) | |
2313 | it->pixel_width += thick; | |
2314 | if (it->end_of_box_run_p) | |
2315 | it->pixel_width += thick; | |
2316 | } | |
2317 | ||
2318 | /* If face has an overline, add the height of the overline | |
2319 | (1 pixel) and a 1 pixel margin to the character height. */ | |
2320 | if (face->overline_p) | |
2321 | it->ascent += 2; | |
2322 | ||
2323 | take_vertical_position_into_account (it); | |
2324 | ||
2325 | if (it->glyph_row) | |
2326 | x_append_composite_glyph (it); | |
2327 | } | |
06a2c219 GM |
2328 | else if (it->what == IT_IMAGE) |
2329 | x_produce_image_glyph (it); | |
2330 | else if (it->what == IT_STRETCH) | |
2331 | x_produce_stretch_glyph (it); | |
2332 | ||
3017fdd1 GM |
2333 | /* Accumulate dimensions. Note: can't assume that it->descent > 0 |
2334 | because this isn't true for images with `:ascent 100'. */ | |
2335 | xassert (it->ascent >= 0 && it->descent >= 0); | |
06a2c219 GM |
2336 | if (it->area == TEXT_AREA) |
2337 | it->current_x += it->pixel_width; | |
66ac4b0e | 2338 | |
d365f5bb GM |
2339 | it->descent += it->extra_line_spacing; |
2340 | ||
06a2c219 GM |
2341 | it->max_ascent = max (it->max_ascent, it->ascent); |
2342 | it->max_descent = max (it->max_descent, it->descent); | |
66ac4b0e GM |
2343 | it->max_phys_ascent = max (it->max_phys_ascent, it->phys_ascent); |
2344 | it->max_phys_descent = max (it->max_phys_descent, it->phys_descent); | |
06a2c219 GM |
2345 | } |
2346 | ||
2347 | ||
2348 | /* Estimate the pixel height of the mode or top line on frame F. | |
2349 | FACE_ID specifies what line's height to estimate. */ | |
2350 | ||
2351 | int | |
2352 | x_estimate_mode_line_height (f, face_id) | |
2353 | struct frame *f; | |
2354 | enum face_id face_id; | |
2355 | { | |
43281ee3 | 2356 | int height = FONT_HEIGHT (FRAME_FONT (f)); |
06a2c219 GM |
2357 | |
2358 | /* This function is called so early when Emacs starts that the face | |
2359 | cache and mode line face are not yet initialized. */ | |
2360 | if (FRAME_FACE_CACHE (f)) | |
2361 | { | |
2362 | struct face *face = FACE_FROM_ID (f, face_id); | |
2363 | if (face) | |
43281ee3 GM |
2364 | { |
2365 | if (face->font) | |
2366 | height = FONT_HEIGHT (face->font); | |
ea2ba0d4 KH |
2367 | if (face->box_line_width > 0) |
2368 | height += 2 * face->box_line_width; | |
43281ee3 | 2369 | } |
06a2c219 GM |
2370 | } |
2371 | ||
2372 | return height; | |
2373 | } | |
2374 | ||
2375 | \f | |
2376 | /*********************************************************************** | |
2377 | Glyph display | |
2378 | ***********************************************************************/ | |
2379 | ||
2380 | /* A sequence of glyphs to be drawn in the same face. | |
2381 | ||
2382 | This data structure is not really completely X specific, so it | |
2383 | could possibly, at least partially, be useful for other systems. It | |
2384 | is currently not part of the external redisplay interface because | |
2385 | it's not clear what other systems will need. */ | |
2386 | ||
2387 | struct glyph_string | |
2388 | { | |
2389 | /* X-origin of the string. */ | |
2390 | int x; | |
2391 | ||
2392 | /* Y-origin and y-position of the base line of this string. */ | |
2393 | int y, ybase; | |
2394 | ||
2395 | /* The width of the string, not including a face extension. */ | |
2396 | int width; | |
2397 | ||
2398 | /* The width of the string, including a face extension. */ | |
2399 | int background_width; | |
2400 | ||
2401 | /* The height of this string. This is the height of the line this | |
2402 | string is drawn in, and can be different from the height of the | |
2403 | font the string is drawn in. */ | |
2404 | int height; | |
2405 | ||
2406 | /* Number of pixels this string overwrites in front of its x-origin. | |
2407 | This number is zero if the string has an lbearing >= 0; it is | |
2408 | -lbearing, if the string has an lbearing < 0. */ | |
2409 | int left_overhang; | |
2410 | ||
2411 | /* Number of pixels this string overwrites past its right-most | |
2412 | nominal x-position, i.e. x + width. Zero if the string's | |
2413 | rbearing is <= its nominal width, rbearing - width otherwise. */ | |
2414 | int right_overhang; | |
2415 | ||
2416 | /* The frame on which the glyph string is drawn. */ | |
2417 | struct frame *f; | |
2418 | ||
2419 | /* The window on which the glyph string is drawn. */ | |
2420 | struct window *w; | |
2421 | ||
2422 | /* X display and window for convenience. */ | |
2423 | Display *display; | |
2424 | Window window; | |
2425 | ||
2426 | /* The glyph row for which this string was built. It determines the | |
2427 | y-origin and height of the string. */ | |
2428 | struct glyph_row *row; | |
2429 | ||
2430 | /* The area within row. */ | |
2431 | enum glyph_row_area area; | |
2432 | ||
2433 | /* Characters to be drawn, and number of characters. */ | |
2434 | XChar2b *char2b; | |
2435 | int nchars; | |
2436 | ||
06a2c219 GM |
2437 | /* A face-override for drawing cursors, mouse face and similar. */ |
2438 | enum draw_glyphs_face hl; | |
2439 | ||
2440 | /* Face in which this string is to be drawn. */ | |
2441 | struct face *face; | |
2442 | ||
2443 | /* Font in which this string is to be drawn. */ | |
2444 | XFontStruct *font; | |
2445 | ||
2446 | /* Font info for this string. */ | |
2447 | struct font_info *font_info; | |
2448 | ||
b4192550 KH |
2449 | /* Non-null means this string describes (part of) a composition. |
2450 | All characters from char2b are drawn composed. */ | |
2451 | struct composition *cmp; | |
06a2c219 GM |
2452 | |
2453 | /* Index of this glyph string's first character in the glyph | |
b4192550 KH |
2454 | definition of CMP. If this is zero, this glyph string describes |
2455 | the first character of a composition. */ | |
06a2c219 GM |
2456 | int gidx; |
2457 | ||
2458 | /* 1 means this glyph strings face has to be drawn to the right end | |
2459 | of the window's drawing area. */ | |
2460 | unsigned extends_to_end_of_line_p : 1; | |
2461 | ||
2462 | /* 1 means the background of this string has been drawn. */ | |
2463 | unsigned background_filled_p : 1; | |
2464 | ||
2465 | /* 1 means glyph string must be drawn with 16-bit functions. */ | |
2466 | unsigned two_byte_p : 1; | |
2467 | ||
2468 | /* 1 means that the original font determined for drawing this glyph | |
2469 | string could not be loaded. The member `font' has been set to | |
2470 | the frame's default font in this case. */ | |
2471 | unsigned font_not_found_p : 1; | |
2472 | ||
2473 | /* 1 means that the face in which this glyph string is drawn has a | |
2474 | stipple pattern. */ | |
2475 | unsigned stippled_p : 1; | |
2476 | ||
66ac4b0e GM |
2477 | /* 1 means only the foreground of this glyph string must be drawn, |
2478 | and we should use the physical height of the line this glyph | |
2479 | string appears in as clip rect. */ | |
2480 | unsigned for_overlaps_p : 1; | |
2481 | ||
06a2c219 GM |
2482 | /* The GC to use for drawing this glyph string. */ |
2483 | GC gc; | |
2484 | ||
2485 | /* A pointer to the first glyph in the string. This glyph | |
2486 | corresponds to char2b[0]. Needed to draw rectangles if | |
2487 | font_not_found_p is 1. */ | |
2488 | struct glyph *first_glyph; | |
2489 | ||
2490 | /* Image, if any. */ | |
2491 | struct image *img; | |
2492 | ||
2493 | struct glyph_string *next, *prev; | |
2494 | }; | |
2495 | ||
2496 | ||
61869b99 | 2497 | #if GLYPH_DEBUG |
06a2c219 GM |
2498 | |
2499 | static void | |
2500 | x_dump_glyph_string (s) | |
2501 | struct glyph_string *s; | |
2502 | { | |
2503 | fprintf (stderr, "glyph string\n"); | |
2504 | fprintf (stderr, " x, y, w, h = %d, %d, %d, %d\n", | |
2505 | s->x, s->y, s->width, s->height); | |
2506 | fprintf (stderr, " ybase = %d\n", s->ybase); | |
2507 | fprintf (stderr, " hl = %d\n", s->hl); | |
2508 | fprintf (stderr, " left overhang = %d, right = %d\n", | |
2509 | s->left_overhang, s->right_overhang); | |
2510 | fprintf (stderr, " nchars = %d\n", s->nchars); | |
2511 | fprintf (stderr, " extends to end of line = %d\n", | |
2512 | s->extends_to_end_of_line_p); | |
2513 | fprintf (stderr, " font height = %d\n", FONT_HEIGHT (s->font)); | |
2514 | fprintf (stderr, " bg width = %d\n", s->background_width); | |
2515 | } | |
2516 | ||
2517 | #endif /* GLYPH_DEBUG */ | |
2518 | ||
2519 | ||
2520 | ||
2521 | static void x_append_glyph_string_lists P_ ((struct glyph_string **, | |
2522 | struct glyph_string **, | |
2523 | struct glyph_string *, | |
2524 | struct glyph_string *)); | |
2525 | static void x_prepend_glyph_string_lists P_ ((struct glyph_string **, | |
2526 | struct glyph_string **, | |
2527 | struct glyph_string *, | |
2528 | struct glyph_string *)); | |
2529 | static void x_append_glyph_string P_ ((struct glyph_string **, | |
2530 | struct glyph_string **, | |
2531 | struct glyph_string *)); | |
2532 | static int x_left_overwritten P_ ((struct glyph_string *)); | |
2533 | static int x_left_overwriting P_ ((struct glyph_string *)); | |
2534 | static int x_right_overwritten P_ ((struct glyph_string *)); | |
2535 | static int x_right_overwriting P_ ((struct glyph_string *)); | |
66ac4b0e GM |
2536 | static int x_fill_glyph_string P_ ((struct glyph_string *, int, int, int, |
2537 | int)); | |
06a2c219 GM |
2538 | static void x_init_glyph_string P_ ((struct glyph_string *, |
2539 | XChar2b *, struct window *, | |
2540 | struct glyph_row *, | |
2541 | enum glyph_row_area, int, | |
2542 | enum draw_glyphs_face)); | |
2543 | static int x_draw_glyphs P_ ((struct window *, int , struct glyph_row *, | |
2544 | enum glyph_row_area, int, int, | |
f0a48a01 | 2545 | enum draw_glyphs_face, int)); |
06a2c219 GM |
2546 | static void x_set_glyph_string_clipping P_ ((struct glyph_string *)); |
2547 | static void x_set_glyph_string_gc P_ ((struct glyph_string *)); | |
2548 | static void x_draw_glyph_string_background P_ ((struct glyph_string *, | |
2549 | int)); | |
2550 | static void x_draw_glyph_string_foreground P_ ((struct glyph_string *)); | |
b4192550 | 2551 | static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *)); |
06a2c219 GM |
2552 | static void x_draw_glyph_string_box P_ ((struct glyph_string *)); |
2553 | static void x_draw_glyph_string P_ ((struct glyph_string *)); | |
2554 | static void x_compute_glyph_string_overhangs P_ ((struct glyph_string *)); | |
2555 | static void x_set_cursor_gc P_ ((struct glyph_string *)); | |
2556 | static void x_set_mode_line_face_gc P_ ((struct glyph_string *)); | |
2557 | static void x_set_mouse_face_gc P_ ((struct glyph_string *)); | |
2558 | static void x_get_glyph_overhangs P_ ((struct glyph *, struct frame *, | |
2559 | int *, int *)); | |
2560 | static void x_compute_overhangs_and_x P_ ((struct glyph_string *, int, int)); | |
2561 | static int x_alloc_lighter_color P_ ((struct frame *, Display *, Colormap, | |
68c45bf0 | 2562 | unsigned long *, double, int)); |
06a2c219 | 2563 | static void x_setup_relief_color P_ ((struct frame *, struct relief *, |
68c45bf0 | 2564 | double, int, unsigned long)); |
06a2c219 GM |
2565 | static void x_setup_relief_colors P_ ((struct glyph_string *)); |
2566 | static void x_draw_image_glyph_string P_ ((struct glyph_string *)); | |
2567 | static void x_draw_image_relief P_ ((struct glyph_string *)); | |
2568 | static void x_draw_image_foreground P_ ((struct glyph_string *)); | |
2569 | static void x_draw_image_foreground_1 P_ ((struct glyph_string *, Pixmap)); | |
2570 | static void x_fill_image_glyph_string P_ ((struct glyph_string *)); | |
2571 | static void x_clear_glyph_string_rect P_ ((struct glyph_string *, int, | |
2572 | int, int, int)); | |
2573 | static void x_draw_relief_rect P_ ((struct frame *, int, int, int, int, | |
2574 | int, int, int, int, XRectangle *)); | |
2575 | static void x_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, | |
2576 | int, int, int, XRectangle *)); | |
66ac4b0e GM |
2577 | static void x_fix_overlapping_area P_ ((struct window *, struct glyph_row *, |
2578 | enum glyph_row_area)); | |
209f68d9 GM |
2579 | static int x_fill_stretch_glyph_string P_ ((struct glyph_string *, |
2580 | struct glyph_row *, | |
2581 | enum glyph_row_area, int, int)); | |
06a2c219 | 2582 | |
163dcff3 GM |
2583 | #if GLYPH_DEBUG |
2584 | static void x_check_font P_ ((struct frame *, XFontStruct *)); | |
2585 | #endif | |
2586 | ||
06a2c219 | 2587 | |
06a2c219 GM |
2588 | /* Append the list of glyph strings with head H and tail T to the list |
2589 | with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */ | |
2590 | ||
2591 | static INLINE void | |
2592 | x_append_glyph_string_lists (head, tail, h, t) | |
2593 | struct glyph_string **head, **tail; | |
2594 | struct glyph_string *h, *t; | |
2595 | { | |
2596 | if (h) | |
2597 | { | |
2598 | if (*head) | |
2599 | (*tail)->next = h; | |
2600 | else | |
2601 | *head = h; | |
2602 | h->prev = *tail; | |
2603 | *tail = t; | |
2604 | } | |
2605 | } | |
2606 | ||
2607 | ||
2608 | /* Prepend the list of glyph strings with head H and tail T to the | |
2609 | list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the | |
2610 | result. */ | |
2611 | ||
2612 | static INLINE void | |
2613 | x_prepend_glyph_string_lists (head, tail, h, t) | |
2614 | struct glyph_string **head, **tail; | |
2615 | struct glyph_string *h, *t; | |
2616 | { | |
2617 | if (h) | |
2618 | { | |
2619 | if (*head) | |
2620 | (*head)->prev = t; | |
2621 | else | |
2622 | *tail = t; | |
2623 | t->next = *head; | |
2624 | *head = h; | |
2625 | } | |
2626 | } | |
2627 | ||
2628 | ||
2629 | /* Append glyph string S to the list with head *HEAD and tail *TAIL. | |
2630 | Set *HEAD and *TAIL to the resulting list. */ | |
2631 | ||
2632 | static INLINE void | |
2633 | x_append_glyph_string (head, tail, s) | |
2634 | struct glyph_string **head, **tail; | |
2635 | struct glyph_string *s; | |
2636 | { | |
2637 | s->next = s->prev = NULL; | |
2638 | x_append_glyph_string_lists (head, tail, s, s); | |
2639 | } | |
2640 | ||
2641 | ||
2642 | /* Set S->gc to a suitable GC for drawing glyph string S in cursor | |
2643 | face. */ | |
2644 | ||
2645 | static void | |
2646 | x_set_cursor_gc (s) | |
2647 | struct glyph_string *s; | |
2648 | { | |
2649 | if (s->font == FRAME_FONT (s->f) | |
2650 | && s->face->background == FRAME_BACKGROUND_PIXEL (s->f) | |
2651 | && s->face->foreground == FRAME_FOREGROUND_PIXEL (s->f) | |
b4192550 | 2652 | && !s->cmp) |
06a2c219 GM |
2653 | s->gc = s->f->output_data.x->cursor_gc; |
2654 | else | |
2655 | { | |
2656 | /* Cursor on non-default face: must merge. */ | |
2657 | XGCValues xgcv; | |
2658 | unsigned long mask; | |
2659 | ||
2660 | xgcv.background = s->f->output_data.x->cursor_pixel; | |
2661 | xgcv.foreground = s->face->background; | |
2662 | ||
2663 | /* If the glyph would be invisible, try a different foreground. */ | |
2664 | if (xgcv.foreground == xgcv.background) | |
2665 | xgcv.foreground = s->face->foreground; | |
2666 | if (xgcv.foreground == xgcv.background) | |
2667 | xgcv.foreground = s->f->output_data.x->cursor_foreground_pixel; | |
2668 | if (xgcv.foreground == xgcv.background) | |
2669 | xgcv.foreground = s->face->foreground; | |
2670 | ||
2671 | /* Make sure the cursor is distinct from text in this face. */ | |
2672 | if (xgcv.background == s->face->background | |
2673 | && xgcv.foreground == s->face->foreground) | |
2674 | { | |
2675 | xgcv.background = s->face->foreground; | |
2676 | xgcv.foreground = s->face->background; | |
2677 | } | |
2678 | ||
2679 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2680 | xgcv.font = s->font->fid; | |
2681 | xgcv.graphics_exposures = False; | |
2682 | mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures; | |
2683 | ||
2684 | if (FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2685 | XChangeGC (s->display, FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2686 | mask, &xgcv); | |
2687 | else | |
2688 | FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2689 | = XCreateGC (s->display, s->window, mask, &xgcv); | |
2690 | ||
2691 | s->gc = FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2692 | } | |
2693 | } | |
2694 | ||
2695 | ||
2696 | /* Set up S->gc of glyph string S for drawing text in mouse face. */ | |
2697 | ||
2698 | static void | |
2699 | x_set_mouse_face_gc (s) | |
2700 | struct glyph_string *s; | |
2701 | { | |
2702 | int face_id; | |
ee569018 | 2703 | struct face *face; |
06a2c219 | 2704 | |
e4ded23c | 2705 | /* What face has to be used last for the mouse face? */ |
06a2c219 | 2706 | face_id = FRAME_X_DISPLAY_INFO (s->f)->mouse_face_face_id; |
ee569018 | 2707 | face = FACE_FROM_ID (s->f, face_id); |
e4ded23c GM |
2708 | if (face == NULL) |
2709 | face = FACE_FROM_ID (s->f, MOUSE_FACE_ID); | |
2710 | ||
033e3e18 GM |
2711 | if (s->first_glyph->type == CHAR_GLYPH) |
2712 | face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch); | |
2713 | else | |
2714 | face_id = FACE_FOR_CHAR (s->f, face, 0); | |
06a2c219 GM |
2715 | s->face = FACE_FROM_ID (s->f, face_id); |
2716 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); | |
2717 | ||
2718 | /* If font in this face is same as S->font, use it. */ | |
2719 | if (s->font == s->face->font) | |
2720 | s->gc = s->face->gc; | |
2721 | else | |
2722 | { | |
2723 | /* Otherwise construct scratch_cursor_gc with values from FACE | |
2724 | but font FONT. */ | |
2725 | XGCValues xgcv; | |
2726 | unsigned long mask; | |
2727 | ||
2728 | xgcv.background = s->face->background; | |
2729 | xgcv.foreground = s->face->foreground; | |
2730 | IF_DEBUG (x_check_font (s->f, s->font)); | |
2731 | xgcv.font = s->font->fid; | |
2732 | xgcv.graphics_exposures = False; | |
2733 | mask = GCForeground | GCBackground | GCFont | GCGraphicsExposures; | |
2734 | ||
2735 | if (FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc) | |
2736 | XChangeGC (s->display, FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc, | |
2737 | mask, &xgcv); | |
2738 | else | |
2739 | FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc | |
2740 | = XCreateGC (s->display, s->window, mask, &xgcv); | |
2741 | ||
2742 | s->gc = FRAME_X_DISPLAY_INFO (s->f)->scratch_cursor_gc; | |
2743 | } | |
2744 | ||
2745 | xassert (s->gc != 0); | |
2746 | } | |
2747 | ||
2748 | ||
2749 | /* Set S->gc of glyph string S to a GC suitable for drawing a mode line. | |
2750 | Faces to use in the mode line have already been computed when the | |
2751 | matrix was built, so there isn't much to do, here. */ | |
2752 | ||
2753 | static INLINE void | |
2754 | x_set_mode_line_face_gc (s) | |
2755 | struct glyph_string *s; | |
2756 | { | |
2757 | s->gc = s->face->gc; | |
06a2c219 GM |
2758 | } |
2759 | ||
2760 | ||
2761 | /* Set S->gc of glyph string S for drawing that glyph string. Set | |
2762 | S->stippled_p to a non-zero value if the face of S has a stipple | |
2763 | pattern. */ | |
2764 | ||
2765 | static INLINE void | |
2766 | x_set_glyph_string_gc (s) | |
2767 | struct glyph_string *s; | |
2768 | { | |
209f68d9 GM |
2769 | PREPARE_FACE_FOR_DISPLAY (s->f, s->face); |
2770 | ||
06a2c219 GM |
2771 | if (s->hl == DRAW_NORMAL_TEXT) |
2772 | { | |
2773 | s->gc = s->face->gc; | |
2774 | s->stippled_p = s->face->stipple != 0; | |
2775 | } | |
2776 | else if (s->hl == DRAW_INVERSE_VIDEO) | |
2777 | { | |
2778 | x_set_mode_line_face_gc (s); | |
2779 | s->stippled_p = s->face->stipple != 0; | |
2780 | } | |
2781 | else if (s->hl == DRAW_CURSOR) | |
2782 | { | |
2783 | x_set_cursor_gc (s); | |
2784 | s->stippled_p = 0; | |
2785 | } | |
2786 | else if (s->hl == DRAW_MOUSE_FACE) | |
2787 | { | |
2788 | x_set_mouse_face_gc (s); | |
2789 | s->stippled_p = s->face->stipple != 0; | |
2790 | } | |
2791 | else if (s->hl == DRAW_IMAGE_RAISED | |
2792 | || s->hl == DRAW_IMAGE_SUNKEN) | |
2793 | { | |
2794 | s->gc = s->face->gc; | |
2795 | s->stippled_p = s->face->stipple != 0; | |
2796 | } | |
2797 | else | |
2798 | { | |
2799 | s->gc = s->face->gc; | |
2800 | s->stippled_p = s->face->stipple != 0; | |
2801 | } | |
2802 | ||
2803 | /* GC must have been set. */ | |
2804 | xassert (s->gc != 0); | |
2805 | } | |
2806 | ||
2807 | ||
2808 | /* Return in *R the clipping rectangle for glyph string S. */ | |
2809 | ||
2810 | static void | |
2811 | x_get_glyph_string_clip_rect (s, r) | |
2812 | struct glyph_string *s; | |
2813 | XRectangle *r; | |
2814 | { | |
2815 | if (s->row->full_width_p) | |
2816 | { | |
2817 | /* Draw full-width. X coordinates are relative to S->w->left. */ | |
1da3fd71 GM |
2818 | int canon_x = CANON_X_UNIT (s->f); |
2819 | ||
2820 | r->x = WINDOW_LEFT_MARGIN (s->w) * canon_x; | |
2821 | r->width = XFASTINT (s->w->width) * canon_x; | |
06a2c219 GM |
2822 | |
2823 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (s->f)) | |
2824 | { | |
1da3fd71 | 2825 | int width = FRAME_SCROLL_BAR_WIDTH (s->f) * canon_x; |
06a2c219 GM |
2826 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s->f)) |
2827 | r->x -= width; | |
2828 | } | |
2829 | ||
b9432a85 | 2830 | r->x += FRAME_INTERNAL_BORDER_WIDTH (s->f); |
1da3fd71 | 2831 | |
06a2c219 GM |
2832 | /* Unless displaying a mode or menu bar line, which are always |
2833 | fully visible, clip to the visible part of the row. */ | |
2834 | if (s->w->pseudo_window_p) | |
2835 | r->height = s->row->visible_height; | |
2836 | else | |
2837 | r->height = s->height; | |
2838 | } | |
2839 | else | |
2840 | { | |
2841 | /* This is a text line that may be partially visible. */ | |
2842 | r->x = WINDOW_AREA_TO_FRAME_PIXEL_X (s->w, s->area, 0); | |
2843 | r->width = window_box_width (s->w, s->area); | |
2844 | r->height = s->row->visible_height; | |
2845 | } | |
2846 | ||
66ac4b0e GM |
2847 | /* If S draws overlapping rows, it's sufficient to use the top and |
2848 | bottom of the window for clipping because this glyph string | |
2849 | intentionally draws over other lines. */ | |
2850 | if (s->for_overlaps_p) | |
2851 | { | |
045dee35 | 2852 | r->y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); |
66ac4b0e GM |
2853 | r->height = window_text_bottom_y (s->w) - r->y; |
2854 | } | |
98b8a90f GM |
2855 | else |
2856 | { | |
2857 | /* Don't use S->y for clipping because it doesn't take partially | |
2858 | visible lines into account. For example, it can be negative for | |
2859 | partially visible lines at the top of a window. */ | |
2860 | if (!s->row->full_width_p | |
2861 | && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s->w, s->row)) | |
2862 | r->y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s->w); | |
2863 | else | |
2864 | r->y = max (0, s->row->y); | |
2865 | ||
2866 | /* If drawing a tool-bar window, draw it over the internal border | |
2867 | at the top of the window. */ | |
2868 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
2869 | r->y -= s->f->output_data.x->internal_border_width; | |
2870 | } | |
2871 | ||
66ac4b0e | 2872 | r->y = WINDOW_TO_FRAME_PIXEL_Y (s->w, r->y); |
06a2c219 GM |
2873 | } |
2874 | ||
2875 | ||
2876 | /* Set clipping for output of glyph string S. S may be part of a mode | |
2877 | line or menu if we don't have X toolkit support. */ | |
2878 | ||
2879 | static INLINE void | |
2880 | x_set_glyph_string_clipping (s) | |
2881 | struct glyph_string *s; | |
2882 | { | |
2883 | XRectangle r; | |
2884 | x_get_glyph_string_clip_rect (s, &r); | |
2885 | XSetClipRectangles (s->display, s->gc, 0, 0, &r, 1, Unsorted); | |
2886 | } | |
2887 | ||
2888 | ||
2889 | /* Compute left and right overhang of glyph string S. If S is a glyph | |
b4192550 | 2890 | string for a composition, assume overhangs don't exist. */ |
06a2c219 GM |
2891 | |
2892 | static INLINE void | |
2893 | x_compute_glyph_string_overhangs (s) | |
2894 | struct glyph_string *s; | |
2895 | { | |
b4192550 | 2896 | if (s->cmp == NULL |
06a2c219 GM |
2897 | && s->first_glyph->type == CHAR_GLYPH) |
2898 | { | |
2899 | XCharStruct cs; | |
2900 | int direction, font_ascent, font_descent; | |
2901 | XTextExtents16 (s->font, s->char2b, s->nchars, &direction, | |
2902 | &font_ascent, &font_descent, &cs); | |
2903 | s->right_overhang = cs.rbearing > cs.width ? cs.rbearing - cs.width : 0; | |
2904 | s->left_overhang = cs.lbearing < 0 ? -cs.lbearing : 0; | |
2905 | } | |
2906 | } | |
2907 | ||
2908 | ||
2909 | /* Compute overhangs and x-positions for glyph string S and its | |
2910 | predecessors, or successors. X is the starting x-position for S. | |
2911 | BACKWARD_P non-zero means process predecessors. */ | |
2912 | ||
2913 | static void | |
2914 | x_compute_overhangs_and_x (s, x, backward_p) | |
2915 | struct glyph_string *s; | |
2916 | int x; | |
2917 | int backward_p; | |
2918 | { | |
2919 | if (backward_p) | |
2920 | { | |
2921 | while (s) | |
2922 | { | |
2923 | x_compute_glyph_string_overhangs (s); | |
2924 | x -= s->width; | |
2925 | s->x = x; | |
2926 | s = s->prev; | |
2927 | } | |
2928 | } | |
2929 | else | |
2930 | { | |
2931 | while (s) | |
2932 | { | |
2933 | x_compute_glyph_string_overhangs (s); | |
2934 | s->x = x; | |
2935 | x += s->width; | |
2936 | s = s->next; | |
2937 | } | |
2938 | } | |
2939 | } | |
2940 | ||
2941 | ||
2942 | /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on | |
b4192550 KH |
2943 | frame F. Overhangs of glyphs other than type CHAR_GLYPH are |
2944 | assumed to be zero. */ | |
06a2c219 GM |
2945 | |
2946 | static void | |
2947 | x_get_glyph_overhangs (glyph, f, left, right) | |
2948 | struct glyph *glyph; | |
2949 | struct frame *f; | |
2950 | int *left, *right; | |
2951 | { | |
06a2c219 GM |
2952 | *left = *right = 0; |
2953 | ||
b4192550 | 2954 | if (glyph->type == CHAR_GLYPH) |
06a2c219 GM |
2955 | { |
2956 | XFontStruct *font; | |
2957 | struct face *face; | |
2958 | struct font_info *font_info; | |
2959 | XChar2b char2b; | |
ee569018 KH |
2960 | XCharStruct *pcm; |
2961 | ||
2962 | face = x_get_glyph_face_and_encoding (f, glyph, &char2b, NULL); | |
06a2c219 GM |
2963 | font = face->font; |
2964 | font_info = FONT_INFO_FROM_ID (f, face->font_info_id); | |
ee569018 KH |
2965 | if (font |
2966 | && (pcm = x_per_char_metric (font, &char2b))) | |
06a2c219 | 2967 | { |
06a2c219 GM |
2968 | if (pcm->rbearing > pcm->width) |
2969 | *right = pcm->rbearing - pcm->width; | |
2970 | if (pcm->lbearing < 0) | |
2971 | *left = -pcm->lbearing; | |
2972 | } | |
2973 | } | |
2974 | } | |
2975 | ||
2976 | ||
2977 | /* Return the index of the first glyph preceding glyph string S that | |
2978 | is overwritten by S because of S's left overhang. Value is -1 | |
2979 | if no glyphs are overwritten. */ | |
2980 | ||
2981 | static int | |
2982 | x_left_overwritten (s) | |
2983 | struct glyph_string *s; | |
2984 | { | |
2985 | int k; | |
2986 | ||
2987 | if (s->left_overhang) | |
2988 | { | |
2989 | int x = 0, i; | |
2990 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
2991 | int first = s->first_glyph - glyphs; | |
2992 | ||
2993 | for (i = first - 1; i >= 0 && x > -s->left_overhang; --i) | |
2994 | x -= glyphs[i].pixel_width; | |
2995 | ||
2996 | k = i + 1; | |
2997 | } | |
2998 | else | |
2999 | k = -1; | |
3000 | ||
3001 | return k; | |
3002 | } | |
3003 | ||
3004 | ||
3005 | /* Return the index of the first glyph preceding glyph string S that | |
3006 | is overwriting S because of its right overhang. Value is -1 if no | |
3007 | glyph in front of S overwrites S. */ | |
3008 | ||
3009 | static int | |
3010 | x_left_overwriting (s) | |
3011 | struct glyph_string *s; | |
3012 | { | |
3013 | int i, k, x; | |
3014 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
3015 | int first = s->first_glyph - glyphs; | |
3016 | ||
3017 | k = -1; | |
3018 | x = 0; | |
3019 | for (i = first - 1; i >= 0; --i) | |
3020 | { | |
3021 | int left, right; | |
3022 | x_get_glyph_overhangs (glyphs + i, s->f, &left, &right); | |
3023 | if (x + right > 0) | |
3024 | k = i; | |
3025 | x -= glyphs[i].pixel_width; | |
3026 | } | |
3027 | ||
3028 | return k; | |
3029 | } | |
3030 | ||
3031 | ||
3032 | /* Return the index of the last glyph following glyph string S that is | |
3033 | not overwritten by S because of S's right overhang. Value is -1 if | |
3034 | no such glyph is found. */ | |
3035 | ||
3036 | static int | |
3037 | x_right_overwritten (s) | |
3038 | struct glyph_string *s; | |
3039 | { | |
3040 | int k = -1; | |
3041 | ||
3042 | if (s->right_overhang) | |
3043 | { | |
3044 | int x = 0, i; | |
3045 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
b4192550 | 3046 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); |
06a2c219 GM |
3047 | int end = s->row->used[s->area]; |
3048 | ||
3049 | for (i = first; i < end && s->right_overhang > x; ++i) | |
3050 | x += glyphs[i].pixel_width; | |
3051 | ||
3052 | k = i; | |
3053 | } | |
3054 | ||
3055 | return k; | |
3056 | } | |
3057 | ||
3058 | ||
3059 | /* Return the index of the last glyph following glyph string S that | |
3060 | overwrites S because of its left overhang. Value is negative | |
3061 | if no such glyph is found. */ | |
3062 | ||
3063 | static int | |
3064 | x_right_overwriting (s) | |
3065 | struct glyph_string *s; | |
3066 | { | |
3067 | int i, k, x; | |
3068 | int end = s->row->used[s->area]; | |
3069 | struct glyph *glyphs = s->row->glyphs[s->area]; | |
b4192550 | 3070 | int first = (s->first_glyph - glyphs) + (s->cmp ? 1 : s->nchars); |
06a2c219 GM |
3071 | |
3072 | k = -1; | |
3073 | x = 0; | |
3074 | for (i = first; i < end; ++i) | |
3075 | { | |
3076 | int left, right; | |
3077 | x_get_glyph_overhangs (glyphs + i, s->f, &left, &right); | |
3078 | if (x - left < 0) | |
3079 | k = i; | |
3080 | x += glyphs[i].pixel_width; | |
3081 | } | |
3082 | ||
3083 | return k; | |
3084 | } | |
3085 | ||
3086 | ||
3087 | /* Fill rectangle X, Y, W, H with background color of glyph string S. */ | |
3088 | ||
3089 | static INLINE void | |
3090 | x_clear_glyph_string_rect (s, x, y, w, h) | |
3091 | struct glyph_string *s; | |
3092 | int x, y, w, h; | |
3093 | { | |
3094 | XGCValues xgcv; | |
3095 | XGetGCValues (s->display, s->gc, GCForeground | GCBackground, &xgcv); | |
3096 | XSetForeground (s->display, s->gc, xgcv.background); | |
3097 | XFillRectangle (s->display, s->window, s->gc, x, y, w, h); | |
3098 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
3099 | } | |
3100 | ||
3101 | ||
3102 | /* Draw the background of glyph_string S. If S->background_filled_p | |
3103 | is non-zero don't draw it. FORCE_P non-zero means draw the | |
3104 | background even if it wouldn't be drawn normally. This is used | |
b4192550 KH |
3105 | when a string preceding S draws into the background of S, or S |
3106 | contains the first component of a composition. */ | |
06a2c219 GM |
3107 | |
3108 | static void | |
3109 | x_draw_glyph_string_background (s, force_p) | |
3110 | struct glyph_string *s; | |
3111 | int force_p; | |
3112 | { | |
3113 | /* Nothing to do if background has already been drawn or if it | |
3114 | shouldn't be drawn in the first place. */ | |
3115 | if (!s->background_filled_p) | |
3116 | { | |
ea2ba0d4 KH |
3117 | int box_line_width = max (s->face->box_line_width, 0); |
3118 | ||
b4192550 | 3119 | if (s->stippled_p) |
06a2c219 GM |
3120 | { |
3121 | /* Fill background with a stipple pattern. */ | |
3122 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
3123 | XFillRectangle (s->display, s->window, s->gc, s->x, | |
ea2ba0d4 | 3124 | s->y + box_line_width, |
06a2c219 | 3125 | s->background_width, |
ea2ba0d4 | 3126 | s->height - 2 * box_line_width); |
06a2c219 GM |
3127 | XSetFillStyle (s->display, s->gc, FillSolid); |
3128 | s->background_filled_p = 1; | |
3129 | } | |
ea2ba0d4 | 3130 | else if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width |
06a2c219 GM |
3131 | || s->font_not_found_p |
3132 | || s->extends_to_end_of_line_p | |
06a2c219 GM |
3133 | || force_p) |
3134 | { | |
ea2ba0d4 | 3135 | x_clear_glyph_string_rect (s, s->x, s->y + box_line_width, |
06a2c219 | 3136 | s->background_width, |
ea2ba0d4 | 3137 | s->height - 2 * box_line_width); |
06a2c219 GM |
3138 | s->background_filled_p = 1; |
3139 | } | |
3140 | } | |
3141 | } | |
3142 | ||
3143 | ||
3144 | /* Draw the foreground of glyph string S. */ | |
3145 | ||
3146 | static void | |
3147 | x_draw_glyph_string_foreground (s) | |
3148 | struct glyph_string *s; | |
3149 | { | |
3150 | int i, x; | |
3151 | ||
3152 | /* If first glyph of S has a left box line, start drawing the text | |
3153 | of S to the right of that box line. */ | |
3154 | if (s->face->box != FACE_NO_BOX | |
3155 | && s->first_glyph->left_box_line_p) | |
ea2ba0d4 | 3156 | x = s->x + abs (s->face->box_line_width); |
06a2c219 GM |
3157 | else |
3158 | x = s->x; | |
3159 | ||
b4192550 KH |
3160 | /* Draw characters of S as rectangles if S's font could not be |
3161 | loaded. */ | |
3162 | if (s->font_not_found_p) | |
06a2c219 | 3163 | { |
b4192550 | 3164 | for (i = 0; i < s->nchars; ++i) |
06a2c219 | 3165 | { |
b4192550 KH |
3166 | struct glyph *g = s->first_glyph + i; |
3167 | XDrawRectangle (s->display, s->window, | |
3168 | s->gc, x, s->y, g->pixel_width - 1, | |
3169 | s->height - 1); | |
3170 | x += g->pixel_width; | |
06a2c219 GM |
3171 | } |
3172 | } | |
3173 | else | |
3174 | { | |
b4192550 KH |
3175 | char *char1b = (char *) s->char2b; |
3176 | int boff = s->font_info->baseline_offset; | |
06a2c219 | 3177 | |
b4192550 KH |
3178 | if (s->font_info->vertical_centering) |
3179 | boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff; | |
3180 | ||
3181 | /* If we can use 8-bit functions, condense S->char2b. */ | |
3182 | if (!s->two_byte_p) | |
3183 | for (i = 0; i < s->nchars; ++i) | |
3184 | char1b[i] = s->char2b[i].byte2; | |
3185 | ||
3186 | /* Draw text with XDrawString if background has already been | |
3187 | filled. Otherwise, use XDrawImageString. (Note that | |
3188 | XDrawImageString is usually faster than XDrawString.) Always | |
3189 | use XDrawImageString when drawing the cursor so that there is | |
3190 | no chance that characters under a box cursor are invisible. */ | |
3191 | if (s->for_overlaps_p | |
3192 | || (s->background_filled_p && s->hl != DRAW_CURSOR)) | |
3193 | { | |
3194 | /* Draw characters with 16-bit or 8-bit functions. */ | |
3195 | if (s->two_byte_p) | |
3196 | XDrawString16 (s->display, s->window, s->gc, x, | |
3197 | s->ybase - boff, s->char2b, s->nchars); | |
3198 | else | |
3199 | XDrawString (s->display, s->window, s->gc, x, | |
3200 | s->ybase - boff, char1b, s->nchars); | |
3201 | } | |
06a2c219 GM |
3202 | else |
3203 | { | |
b4192550 KH |
3204 | if (s->two_byte_p) |
3205 | XDrawImageString16 (s->display, s->window, s->gc, x, | |
3206 | s->ybase - boff, s->char2b, s->nchars); | |
06a2c219 | 3207 | else |
b4192550 KH |
3208 | XDrawImageString (s->display, s->window, s->gc, x, |
3209 | s->ybase - boff, char1b, s->nchars); | |
3210 | } | |
3211 | } | |
3212 | } | |
06a2c219 | 3213 | |
b4192550 | 3214 | /* Draw the foreground of composite glyph string S. */ |
06a2c219 | 3215 | |
b4192550 KH |
3216 | static void |
3217 | x_draw_composite_glyph_string_foreground (s) | |
3218 | struct glyph_string *s; | |
3219 | { | |
3220 | int i, x; | |
06a2c219 | 3221 | |
b4192550 KH |
3222 | /* If first glyph of S has a left box line, start drawing the text |
3223 | of S to the right of that box line. */ | |
3224 | if (s->face->box != FACE_NO_BOX | |
3225 | && s->first_glyph->left_box_line_p) | |
ea2ba0d4 | 3226 | x = s->x + abs (s->face->box_line_width); |
b4192550 KH |
3227 | else |
3228 | x = s->x; | |
06a2c219 | 3229 | |
b4192550 KH |
3230 | /* S is a glyph string for a composition. S->gidx is the index of |
3231 | the first character drawn for glyphs of this composition. | |
3232 | S->gidx == 0 means we are drawing the very first character of | |
3233 | this composition. */ | |
06a2c219 | 3234 | |
b4192550 KH |
3235 | /* Draw a rectangle for the composition if the font for the very |
3236 | first character of the composition could not be loaded. */ | |
3237 | if (s->font_not_found_p) | |
3238 | { | |
3239 | if (s->gidx == 0) | |
3240 | XDrawRectangle (s->display, s->window, s->gc, x, s->y, | |
3241 | s->width - 1, s->height - 1); | |
3242 | } | |
3243 | else | |
3244 | { | |
3245 | for (i = 0; i < s->nchars; i++, ++s->gidx) | |
3246 | XDrawString16 (s->display, s->window, s->gc, | |
3247 | x + s->cmp->offsets[s->gidx * 2], | |
3248 | s->ybase - s->cmp->offsets[s->gidx * 2 + 1], | |
3249 | s->char2b + i, 1); | |
06a2c219 GM |
3250 | } |
3251 | } | |
3252 | ||
3253 | ||
80c32bcc GM |
3254 | #ifdef USE_X_TOOLKIT |
3255 | ||
3e71d8f2 | 3256 | static struct frame *x_frame_of_widget P_ ((Widget)); |
651f03b6 GM |
3257 | static Boolean cvt_string_to_pixel P_ ((Display *, XrmValue *, Cardinal *, |
3258 | XrmValue *, XrmValue *, XtPointer *)); | |
3259 | static void cvt_pixel_dtor P_ ((XtAppContext, XrmValue *, XtPointer, | |
3260 | XrmValue *, Cardinal *)); | |
80c32bcc | 3261 | |
3e71d8f2 GM |
3262 | |
3263 | /* Return the frame on which widget WIDGET is used.. Abort if frame | |
3264 | cannot be determined. */ | |
3265 | ||
e851c833 | 3266 | static struct frame * |
3e71d8f2 | 3267 | x_frame_of_widget (widget) |
80c32bcc | 3268 | Widget widget; |
80c32bcc | 3269 | { |
80c32bcc | 3270 | struct x_display_info *dpyinfo; |
5c187dee | 3271 | Lisp_Object tail; |
3e71d8f2 GM |
3272 | struct frame *f; |
3273 | ||
80c32bcc GM |
3274 | dpyinfo = x_display_info_for_display (XtDisplay (widget)); |
3275 | ||
3276 | /* Find the top-level shell of the widget. Note that this function | |
3277 | can be called when the widget is not yet realized, so XtWindow | |
3278 | (widget) == 0. That's the reason we can't simply use | |
3279 | x_any_window_to_frame. */ | |
3280 | while (!XtIsTopLevelShell (widget)) | |
3281 | widget = XtParent (widget); | |
3282 | ||
3283 | /* Look for a frame with that top-level widget. Allocate the color | |
3284 | on that frame to get the right gamma correction value. */ | |
3285 | for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) | |
3286 | if (GC_FRAMEP (XCAR (tail)) | |
3287 | && (f = XFRAME (XCAR (tail)), | |
3288 | (f->output_data.nothing != 1 | |
3289 | && FRAME_X_DISPLAY_INFO (f) == dpyinfo)) | |
3290 | && f->output_data.x->widget == widget) | |
3e71d8f2 | 3291 | return f; |
80c32bcc GM |
3292 | |
3293 | abort (); | |
3294 | } | |
3295 | ||
3e71d8f2 GM |
3296 | |
3297 | /* Allocate the color COLOR->pixel on the screen and display of | |
3298 | widget WIDGET in colormap CMAP. If an exact match cannot be | |
3299 | allocated, try the nearest color available. Value is non-zero | |
3300 | if successful. This is called from lwlib. */ | |
3301 | ||
3302 | int | |
3303 | x_alloc_nearest_color_for_widget (widget, cmap, color) | |
3304 | Widget widget; | |
3305 | Colormap cmap; | |
3306 | XColor *color; | |
3307 | { | |
3308 | struct frame *f = x_frame_of_widget (widget); | |
3309 | return x_alloc_nearest_color (f, cmap, color); | |
3310 | } | |
3311 | ||
3312 | ||
46d516e5 MB |
3313 | /* Allocate a color which is lighter or darker than *PIXEL by FACTOR |
3314 | or DELTA. Try a color with RGB values multiplied by FACTOR first. | |
3315 | If this produces the same color as PIXEL, try a color where all RGB | |
3316 | values have DELTA added. Return the allocated color in *PIXEL. | |
3317 | DISPLAY is the X display, CMAP is the colormap to operate on. | |
3318 | Value is non-zero if successful. */ | |
3319 | ||
3320 | int | |
3321 | x_alloc_lighter_color_for_widget (widget, display, cmap, pixel, factor, delta) | |
3322 | Widget widget; | |
3323 | Display *display; | |
3324 | Colormap cmap; | |
3325 | unsigned long *pixel; | |
3326 | double factor; | |
3327 | int delta; | |
3328 | { | |
3329 | struct frame *f = x_frame_of_widget (widget); | |
3330 | return x_alloc_lighter_color (f, display, cmap, pixel, factor, delta); | |
3331 | } | |
3332 | ||
3333 | ||
651f03b6 GM |
3334 | /* Structure specifying which arguments should be passed by Xt to |
3335 | cvt_string_to_pixel. We want the widget's screen and colormap. */ | |
3336 | ||
3337 | static XtConvertArgRec cvt_string_to_pixel_args[] = | |
3338 | { | |
3339 | {XtWidgetBaseOffset, (XtPointer) XtOffset (Widget, core.screen), | |
3340 | sizeof (Screen *)}, | |
3341 | {XtWidgetBaseOffset, (XtPointer) XtOffset (Widget, core.colormap), | |
3342 | sizeof (Colormap)} | |
3343 | }; | |
3344 | ||
3345 | ||
3346 | /* The address of this variable is returned by | |
3347 | cvt_string_to_pixel. */ | |
3348 | ||
3349 | static Pixel cvt_string_to_pixel_value; | |
3350 | ||
3351 | ||
3352 | /* Convert a color name to a pixel color. | |
3353 | ||
3354 | DPY is the display we are working on. | |
3355 | ||
3356 | ARGS is an array of *NARGS XrmValue structures holding additional | |
3357 | information about the widget for which the conversion takes place. | |
3358 | The contents of this array are determined by the specification | |
3359 | in cvt_string_to_pixel_args. | |
3360 | ||
3361 | FROM is a pointer to an XrmValue which points to the color name to | |
3362 | convert. TO is an XrmValue in which to return the pixel color. | |
3363 | ||
3364 | CLOSURE_RET is a pointer to user-data, in which we record if | |
3365 | we allocated the color or not. | |
3366 | ||
3367 | Value is True if successful, False otherwise. */ | |
3368 | ||
3369 | static Boolean | |
3370 | cvt_string_to_pixel (dpy, args, nargs, from, to, closure_ret) | |
3371 | Display *dpy; | |
3372 | XrmValue *args; | |
3373 | Cardinal *nargs; | |
3374 | XrmValue *from, *to; | |
3375 | XtPointer *closure_ret; | |
3376 | { | |
3377 | Screen *screen; | |
3378 | Colormap cmap; | |
3379 | Pixel pixel; | |
3380 | String color_name; | |
3381 | XColor color; | |
3382 | ||
3383 | if (*nargs != 2) | |
3384 | { | |
3385 | XtAppWarningMsg (XtDisplayToApplicationContext (dpy), | |
3386 | "wrongParameters", "cvt_string_to_pixel", | |
3387 | "XtToolkitError", | |
3388 | "Screen and colormap args required", NULL, NULL); | |
3389 | return False; | |
3390 | } | |
3391 | ||
3392 | screen = *(Screen **) args[0].addr; | |
3393 | cmap = *(Colormap *) args[1].addr; | |
3394 | color_name = (String) from->addr; | |
3395 | ||
3396 | if (strcmp (color_name, XtDefaultBackground) == 0) | |
3397 | { | |
3398 | *closure_ret = (XtPointer) False; | |
3399 | pixel = WhitePixelOfScreen (screen); | |
3400 | } | |
3401 | else if (strcmp (color_name, XtDefaultForeground) == 0) | |
3402 | { | |
3403 | *closure_ret = (XtPointer) False; | |
3404 | pixel = BlackPixelOfScreen (screen); | |
3405 | } | |
3406 | else if (XParseColor (dpy, cmap, color_name, &color) | |
3407 | && x_alloc_nearest_color_1 (dpy, cmap, &color)) | |
3408 | { | |
3409 | pixel = color.pixel; | |
3410 | *closure_ret = (XtPointer) True; | |
3411 | } | |
3412 | else | |
3413 | { | |
3414 | String params[1]; | |
3415 | Cardinal nparams = 1; | |
3416 | ||
3417 | params[0] = color_name; | |
3418 | XtAppWarningMsg (XtDisplayToApplicationContext (dpy), | |
3419 | "badValue", "cvt_string_to_pixel", | |
3420 | "XtToolkitError", "Invalid color `%s'", | |
3421 | params, &nparams); | |
3422 | return False; | |
3423 | } | |
3424 | ||
3425 | if (to->addr != NULL) | |
3426 | { | |
3427 | if (to->size < sizeof (Pixel)) | |
3428 | { | |
3429 | to->size = sizeof (Pixel); | |
3430 | return False; | |
3431 | } | |
3432 | ||
3433 | *(Pixel *) to->addr = pixel; | |
3434 | } | |
3435 | else | |
3436 | { | |
3437 | cvt_string_to_pixel_value = pixel; | |
3438 | to->addr = (XtPointer) &cvt_string_to_pixel_value; | |
3439 | } | |
3440 | ||
3441 | to->size = sizeof (Pixel); | |
3442 | return True; | |
3443 | } | |
3444 | ||
3445 | ||
3446 | /* Free a pixel color which was previously allocated via | |
3447 | cvt_string_to_pixel. This is registered as the destructor | |
3448 | for this type of resource via XtSetTypeConverter. | |
3449 | ||
3450 | APP is the application context in which we work. | |
3451 | ||
3452 | TO is a pointer to an XrmValue holding the color to free. | |
3453 | CLOSURE is the value we stored in CLOSURE_RET for this color | |
3454 | in cvt_string_to_pixel. | |
3455 | ||
3456 | ARGS and NARGS are like for cvt_string_to_pixel. */ | |
3457 | ||
3458 | static void | |
3459 | cvt_pixel_dtor (app, to, closure, args, nargs) | |
3460 | XtAppContext app; | |
3461 | XrmValuePtr to; | |
3462 | XtPointer closure; | |
3463 | XrmValuePtr args; | |
3464 | Cardinal *nargs; | |
3465 | { | |
3466 | if (*nargs != 2) | |
3467 | { | |
3468 | XtAppWarningMsg (app, "wrongParameters", "cvt_pixel_dtor", | |
3469 | "XtToolkitError", | |
3470 | "Screen and colormap arguments required", | |
3471 | NULL, NULL); | |
3472 | } | |
3473 | else if (closure != NULL) | |
3474 | { | |
3475 | /* We did allocate the pixel, so free it. */ | |
3476 | Screen *screen = *(Screen **) args[0].addr; | |
3477 | Colormap cmap = *(Colormap *) args[1].addr; | |
3478 | x_free_dpy_colors (DisplayOfScreen (screen), screen, cmap, | |
97762eb7 | 3479 | (Pixel *) to->addr, 1); |
651f03b6 GM |
3480 | } |
3481 | } | |
3482 | ||
3483 | ||
80c32bcc GM |
3484 | #endif /* USE_X_TOOLKIT */ |
3485 | ||
3486 | ||
f04e1297 | 3487 | /* Value is an array of XColor structures for the contents of the |
651f03b6 | 3488 | color map of display DPY. Set *NCELLS to the size of the array. |
f04e1297 GM |
3489 | Note that this probably shouldn't be called for large color maps, |
3490 | say a 24-bit TrueColor map. */ | |
3491 | ||
3492 | static const XColor * | |
651f03b6 GM |
3493 | x_color_cells (dpy, ncells) |
3494 | Display *dpy; | |
f04e1297 GM |
3495 | int *ncells; |
3496 | { | |
651f03b6 | 3497 | struct x_display_info *dpyinfo = x_display_info_for_display (dpy); |
f04e1297 GM |
3498 | |
3499 | if (dpyinfo->color_cells == NULL) | |
3500 | { | |
651f03b6 | 3501 | Screen *screen = dpyinfo->screen; |
f04e1297 GM |
3502 | int i; |
3503 | ||
3504 | dpyinfo->ncolor_cells | |
651f03b6 | 3505 | = XDisplayCells (dpy, XScreenNumberOfScreen (screen)); |
f04e1297 GM |
3506 | dpyinfo->color_cells |
3507 | = (XColor *) xmalloc (dpyinfo->ncolor_cells | |
3508 | * sizeof *dpyinfo->color_cells); | |
3509 | ||
3510 | for (i = 0; i < dpyinfo->ncolor_cells; ++i) | |
3511 | dpyinfo->color_cells[i].pixel = i; | |
3512 | ||
651f03b6 | 3513 | XQueryColors (dpy, dpyinfo->cmap, |
f04e1297 GM |
3514 | dpyinfo->color_cells, dpyinfo->ncolor_cells); |
3515 | } | |
3516 | ||
3517 | *ncells = dpyinfo->ncolor_cells; | |
3518 | return dpyinfo->color_cells; | |
3519 | } | |
3520 | ||
3521 | ||
3522 | /* On frame F, translate pixel colors to RGB values for the NCOLORS | |
3523 | colors in COLORS. Use cached information, if available. */ | |
3524 | ||
3525 | void | |
3526 | x_query_colors (f, colors, ncolors) | |
3527 | struct frame *f; | |
3528 | XColor *colors; | |
3529 | int ncolors; | |
3530 | { | |
3531 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
3532 | ||
3533 | if (dpyinfo->color_cells) | |
3534 | { | |
3535 | int i; | |
3536 | for (i = 0; i < ncolors; ++i) | |
3537 | { | |
3538 | unsigned long pixel = colors[i].pixel; | |
3539 | xassert (pixel < dpyinfo->ncolor_cells); | |
3540 | xassert (dpyinfo->color_cells[pixel].pixel == pixel); | |
3541 | colors[i] = dpyinfo->color_cells[pixel]; | |
3542 | } | |
3543 | } | |
3544 | else | |
3545 | XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), colors, ncolors); | |
3546 | } | |
3547 | ||
3548 | ||
3549 | /* On frame F, translate pixel color to RGB values for the color in | |
3550 | COLOR. Use cached information, if available. */ | |
3551 | ||
3552 | void | |
3553 | x_query_color (f, color) | |
3554 | struct frame *f; | |
3555 | XColor *color; | |
3556 | { | |
3557 | x_query_colors (f, color, 1); | |
3558 | } | |
3559 | ||
3560 | ||
651f03b6 GM |
3561 | /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an |
3562 | exact match can't be allocated, try the nearest color available. | |
3563 | Value is non-zero if successful. Set *COLOR to the color | |
3564 | allocated. */ | |
06a2c219 | 3565 | |
651f03b6 GM |
3566 | static int |
3567 | x_alloc_nearest_color_1 (dpy, cmap, color) | |
3568 | Display *dpy; | |
06a2c219 GM |
3569 | Colormap cmap; |
3570 | XColor *color; | |
3571 | { | |
80c32bcc GM |
3572 | int rc; |
3573 | ||
651f03b6 | 3574 | rc = XAllocColor (dpy, cmap, color); |
06a2c219 GM |
3575 | if (rc == 0) |
3576 | { | |
3577 | /* If we got to this point, the colormap is full, so we're going | |
3578 | to try to get the next closest color. The algorithm used is | |
3579 | a least-squares matching, which is what X uses for closest | |
3580 | color matching with StaticColor visuals. */ | |
3581 | int nearest, i; | |
3582 | unsigned long nearest_delta = ~0; | |
f04e1297 | 3583 | int ncells; |
651f03b6 | 3584 | const XColor *cells = x_color_cells (dpy, &ncells); |
06a2c219 GM |
3585 | |
3586 | for (nearest = i = 0; i < ncells; ++i) | |
3587 | { | |
3588 | long dred = (color->red >> 8) - (cells[i].red >> 8); | |
3589 | long dgreen = (color->green >> 8) - (cells[i].green >> 8); | |
3590 | long dblue = (color->blue >> 8) - (cells[i].blue >> 8); | |
3591 | unsigned long delta = dred * dred + dgreen * dgreen + dblue * dblue; | |
3592 | ||
3593 | if (delta < nearest_delta) | |
3594 | { | |
3595 | nearest = i; | |
3596 | nearest_delta = delta; | |
3597 | } | |
3598 | } | |
3599 | ||
3600 | color->red = cells[nearest].red; | |
3601 | color->green = cells[nearest].green; | |
3602 | color->blue = cells[nearest].blue; | |
651f03b6 | 3603 | rc = XAllocColor (dpy, cmap, color); |
06a2c219 | 3604 | } |
35efe0a1 GM |
3605 | else |
3606 | { | |
3607 | /* If allocation succeeded, and the allocated pixel color is not | |
3608 | equal to a cached pixel color recorded earlier, there was a | |
3609 | change in the colormap, so clear the color cache. */ | |
651f03b6 | 3610 | struct x_display_info *dpyinfo = x_display_info_for_display (dpy); |
35efe0a1 GM |
3611 | XColor *cached_color; |
3612 | ||
3613 | if (dpyinfo->color_cells | |
3614 | && (cached_color = &dpyinfo->color_cells[color->pixel], | |
cae71efe GM |
3615 | (cached_color->red != color->red |
3616 | || cached_color->blue != color->blue | |
3617 | || cached_color->green != color->green))) | |
35efe0a1 GM |
3618 | { |
3619 | xfree (dpyinfo->color_cells); | |
3620 | dpyinfo->color_cells = NULL; | |
3621 | dpyinfo->ncolor_cells = 0; | |
3622 | } | |
3623 | } | |
06a2c219 | 3624 | |
d9c545da GM |
3625 | #ifdef DEBUG_X_COLORS |
3626 | if (rc) | |
3627 | register_color (color->pixel); | |
3628 | #endif /* DEBUG_X_COLORS */ | |
3629 | ||
06a2c219 GM |
3630 | return rc; |
3631 | } | |
3632 | ||
3633 | ||
651f03b6 GM |
3634 | /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an |
3635 | exact match can't be allocated, try the nearest color available. | |
3636 | Value is non-zero if successful. Set *COLOR to the color | |
3637 | allocated. */ | |
3638 | ||
3639 | int | |
3640 | x_alloc_nearest_color (f, cmap, color) | |
3641 | struct frame *f; | |
3642 | Colormap cmap; | |
3643 | XColor *color; | |
3644 | { | |
3645 | gamma_correct (f, color); | |
3646 | return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f), cmap, color); | |
3647 | } | |
3648 | ||
3649 | ||
d9c545da GM |
3650 | /* Allocate color PIXEL on frame F. PIXEL must already be allocated. |
3651 | It's necessary to do this instead of just using PIXEL directly to | |
3652 | get color reference counts right. */ | |
3653 | ||
3654 | unsigned long | |
3655 | x_copy_color (f, pixel) | |
3656 | struct frame *f; | |
3657 | unsigned long pixel; | |
3658 | { | |
3659 | XColor color; | |
3660 | ||
3661 | color.pixel = pixel; | |
3662 | BLOCK_INPUT; | |
f04e1297 | 3663 | x_query_color (f, &color); |
d9c545da GM |
3664 | XAllocColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &color); |
3665 | UNBLOCK_INPUT; | |
3666 | #ifdef DEBUG_X_COLORS | |
3667 | register_color (pixel); | |
3668 | #endif | |
3669 | return color.pixel; | |
3670 | } | |
3671 | ||
3672 | ||
3e71d8f2 GM |
3673 | /* Allocate color PIXEL on display DPY. PIXEL must already be allocated. |
3674 | It's necessary to do this instead of just using PIXEL directly to | |
3675 | get color reference counts right. */ | |
3676 | ||
3677 | unsigned long | |
3678 | x_copy_dpy_color (dpy, cmap, pixel) | |
3679 | Display *dpy; | |
3680 | Colormap cmap; | |
3681 | unsigned long pixel; | |
3682 | { | |
3683 | XColor color; | |
3684 | ||
3685 | color.pixel = pixel; | |
3686 | BLOCK_INPUT; | |
3687 | XQueryColor (dpy, cmap, &color); | |
3688 | XAllocColor (dpy, cmap, &color); | |
3689 | UNBLOCK_INPUT; | |
3690 | #ifdef DEBUG_X_COLORS | |
3691 | register_color (pixel); | |
3692 | #endif | |
3693 | return color.pixel; | |
3694 | } | |
3695 | ||
3696 | ||
6d8b0acd | 3697 | /* Brightness beyond which a color won't have its highlight brightness |
d7361edf | 3698 | boosted. |
6d8b0acd | 3699 | |
d7361edf MB |
3700 | Nominally, highlight colors for `3d' faces are calculated by |
3701 | brightening an object's color by a constant scale factor, but this | |
3702 | doesn't yield good results for dark colors, so for colors who's | |
3703 | brightness is less than this value (on a scale of 0-65535) have an | |
3704 | use an additional additive factor. | |
6d8b0acd MB |
3705 | |
3706 | The value here is set so that the default menu-bar/mode-line color | |
3707 | (grey75) will not have its highlights changed at all. */ | |
3708 | #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000 | |
3709 | ||
3710 | ||
06a2c219 GM |
3711 | /* Allocate a color which is lighter or darker than *PIXEL by FACTOR |
3712 | or DELTA. Try a color with RGB values multiplied by FACTOR first. | |
3713 | If this produces the same color as PIXEL, try a color where all RGB | |
3714 | values have DELTA added. Return the allocated color in *PIXEL. | |
3715 | DISPLAY is the X display, CMAP is the colormap to operate on. | |
3716 | Value is non-zero if successful. */ | |
3717 | ||
3718 | static int | |
3719 | x_alloc_lighter_color (f, display, cmap, pixel, factor, delta) | |
3720 | struct frame *f; | |
3721 | Display *display; | |
3722 | Colormap cmap; | |
3723 | unsigned long *pixel; | |
68c45bf0 | 3724 | double factor; |
06a2c219 GM |
3725 | int delta; |
3726 | { | |
3727 | XColor color, new; | |
6d8b0acd | 3728 | long bright; |
06a2c219 GM |
3729 | int success_p; |
3730 | ||
3731 | /* Get RGB color values. */ | |
3732 | color.pixel = *pixel; | |
f04e1297 | 3733 | x_query_color (f, &color); |
06a2c219 GM |
3734 | |
3735 | /* Change RGB values by specified FACTOR. Avoid overflow! */ | |
3736 | xassert (factor >= 0); | |
3737 | new.red = min (0xffff, factor * color.red); | |
3738 | new.green = min (0xffff, factor * color.green); | |
3739 | new.blue = min (0xffff, factor * color.blue); | |
3740 | ||
d7361edf MB |
3741 | /* Calculate brightness of COLOR. */ |
3742 | bright = (2 * color.red + 3 * color.green + color.blue) / 6; | |
6d8b0acd MB |
3743 | |
3744 | /* We only boost colors that are darker than | |
3745 | HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */ | |
3746 | if (bright < HIGHLIGHT_COLOR_DARK_BOOST_LIMIT) | |
3747 | /* Make an additive adjustment to NEW, because it's dark enough so | |
3748 | that scaling by FACTOR alone isn't enough. */ | |
3749 | { | |
3750 | /* How far below the limit this color is (0 - 1, 1 being darker). */ | |
3751 | double dimness = 1 - (double)bright / HIGHLIGHT_COLOR_DARK_BOOST_LIMIT; | |
3752 | /* The additive adjustment. */ | |
d7361edf | 3753 | int min_delta = delta * dimness * factor / 2; |
6d8b0acd MB |
3754 | |
3755 | if (factor < 1) | |
3756 | { | |
6d8b0acd MB |
3757 | new.red = max (0, new.red - min_delta); |
3758 | new.green = max (0, new.green - min_delta); | |
3759 | new.blue = max (0, new.blue - min_delta); | |
3760 | } | |
3761 | else | |
3762 | { | |
3763 | new.red = min (0xffff, min_delta + new.red); | |
3764 | new.green = min (0xffff, min_delta + new.green); | |
3765 | new.blue = min (0xffff, min_delta + new.blue); | |
3766 | } | |
3767 | } | |
3768 | ||
06a2c219 | 3769 | /* Try to allocate the color. */ |
80c32bcc | 3770 | success_p = x_alloc_nearest_color (f, cmap, &new); |
06a2c219 GM |
3771 | if (success_p) |
3772 | { | |
3773 | if (new.pixel == *pixel) | |
3774 | { | |
3775 | /* If we end up with the same color as before, try adding | |
3776 | delta to the RGB values. */ | |
0d605c67 | 3777 | x_free_colors (f, &new.pixel, 1); |
06a2c219 GM |
3778 | |
3779 | new.red = min (0xffff, delta + color.red); | |
3780 | new.green = min (0xffff, delta + color.green); | |
3781 | new.blue = min (0xffff, delta + color.blue); | |
80c32bcc | 3782 | success_p = x_alloc_nearest_color (f, cmap, &new); |
06a2c219 GM |
3783 | } |
3784 | else | |
3785 | success_p = 1; | |
3786 | *pixel = new.pixel; | |
3787 | } | |
3788 | ||
3789 | return success_p; | |
3790 | } | |
3791 | ||
3792 | ||
3793 | /* Set up the foreground color for drawing relief lines of glyph | |
3794 | string S. RELIEF is a pointer to a struct relief containing the GC | |
3795 | with which lines will be drawn. Use a color that is FACTOR or | |
3796 | DELTA lighter or darker than the relief's background which is found | |
3797 | in S->f->output_data.x->relief_background. If such a color cannot | |
3798 | be allocated, use DEFAULT_PIXEL, instead. */ | |
3799 | ||
3800 | static void | |
3801 | x_setup_relief_color (f, relief, factor, delta, default_pixel) | |
3802 | struct frame *f; | |
3803 | struct relief *relief; | |
68c45bf0 | 3804 | double factor; |
06a2c219 GM |
3805 | int delta; |
3806 | unsigned long default_pixel; | |
3807 | { | |
3808 | XGCValues xgcv; | |
3809 | struct x_output *di = f->output_data.x; | |
3810 | unsigned long mask = GCForeground | GCLineWidth | GCGraphicsExposures; | |
3811 | unsigned long pixel; | |
3812 | unsigned long background = di->relief_background; | |
43bd1b2b | 3813 | Colormap cmap = FRAME_X_COLORMAP (f); |
dcd08bfb GM |
3814 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
3815 | Display *dpy = FRAME_X_DISPLAY (f); | |
06a2c219 GM |
3816 | |
3817 | xgcv.graphics_exposures = False; | |
3818 | xgcv.line_width = 1; | |
3819 | ||
3820 | /* Free previously allocated color. The color cell will be reused | |
3821 | when it has been freed as many times as it was allocated, so this | |
3822 | doesn't affect faces using the same colors. */ | |
3823 | if (relief->gc | |
3824 | && relief->allocated_p) | |
3825 | { | |
0d605c67 | 3826 | x_free_colors (f, &relief->pixel, 1); |
06a2c219 GM |
3827 | relief->allocated_p = 0; |
3828 | } | |
3829 | ||
3830 | /* Allocate new color. */ | |
3831 | xgcv.foreground = default_pixel; | |
3832 | pixel = background; | |
dcd08bfb GM |
3833 | if (dpyinfo->n_planes != 1 |
3834 | && x_alloc_lighter_color (f, dpy, cmap, &pixel, factor, delta)) | |
06a2c219 GM |
3835 | { |
3836 | relief->allocated_p = 1; | |
3837 | xgcv.foreground = relief->pixel = pixel; | |
3838 | } | |
3839 | ||
3840 | if (relief->gc == 0) | |
3841 | { | |
dcd08bfb | 3842 | xgcv.stipple = dpyinfo->gray; |
06a2c219 | 3843 | mask |= GCStipple; |
dcd08bfb | 3844 | relief->gc = XCreateGC (dpy, FRAME_X_WINDOW (f), mask, &xgcv); |
06a2c219 GM |
3845 | } |
3846 | else | |
dcd08bfb | 3847 | XChangeGC (dpy, relief->gc, mask, &xgcv); |
06a2c219 GM |
3848 | } |
3849 | ||
3850 | ||
3851 | /* Set up colors for the relief lines around glyph string S. */ | |
3852 | ||
3853 | static void | |
3854 | x_setup_relief_colors (s) | |
3855 | struct glyph_string *s; | |
3856 | { | |
3857 | struct x_output *di = s->f->output_data.x; | |
3858 | unsigned long color; | |
3859 | ||
3860 | if (s->face->use_box_color_for_shadows_p) | |
3861 | color = s->face->box_color; | |
e2a57b34 | 3862 | else if (s->first_glyph->type == IMAGE_GLYPH |
0cb8bb48 | 3863 | && s->img->pixmap |
e2a57b34 MB |
3864 | && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0)) |
3865 | color = IMAGE_BACKGROUND (s->img, s->f, 0); | |
06a2c219 GM |
3866 | else |
3867 | { | |
3868 | XGCValues xgcv; | |
3869 | ||
3870 | /* Get the background color of the face. */ | |
3871 | XGetGCValues (s->display, s->gc, GCBackground, &xgcv); | |
3872 | color = xgcv.background; | |
3873 | } | |
3874 | ||
3875 | if (di->white_relief.gc == 0 | |
3876 | || color != di->relief_background) | |
3877 | { | |
3878 | di->relief_background = color; | |
3879 | x_setup_relief_color (s->f, &di->white_relief, 1.2, 0x8000, | |
3880 | WHITE_PIX_DEFAULT (s->f)); | |
3881 | x_setup_relief_color (s->f, &di->black_relief, 0.6, 0x4000, | |
3882 | BLACK_PIX_DEFAULT (s->f)); | |
3883 | } | |
3884 | } | |
3885 | ||
3886 | ||
3887 | /* Draw a relief on frame F inside the rectangle given by LEFT_X, | |
3888 | TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief | |
3889 | to draw, it must be >= 0. RAISED_P non-zero means draw a raised | |
3890 | relief. LEFT_P non-zero means draw a relief on the left side of | |
3891 | the rectangle. RIGHT_P non-zero means draw a relief on the right | |
3892 | side of the rectangle. CLIP_RECT is the clipping rectangle to use | |
3893 | when drawing. */ | |
3894 | ||
3895 | static void | |
3896 | x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, | |
3897 | raised_p, left_p, right_p, clip_rect) | |
3898 | struct frame *f; | |
3899 | int left_x, top_y, right_x, bottom_y, left_p, right_p, raised_p; | |
3900 | XRectangle *clip_rect; | |
3901 | { | |
de507556 GM |
3902 | Display *dpy = FRAME_X_DISPLAY (f); |
3903 | Window window = FRAME_X_WINDOW (f); | |
06a2c219 GM |
3904 | int i; |
3905 | GC gc; | |
3906 | ||
3907 | if (raised_p) | |
3908 | gc = f->output_data.x->white_relief.gc; | |
3909 | else | |
3910 | gc = f->output_data.x->black_relief.gc; | |
de507556 | 3911 | XSetClipRectangles (dpy, gc, 0, 0, clip_rect, 1, Unsorted); |
06a2c219 GM |
3912 | |
3913 | /* Top. */ | |
3914 | for (i = 0; i < width; ++i) | |
de507556 | 3915 | XDrawLine (dpy, window, gc, |
06a2c219 GM |
3916 | left_x + i * left_p, top_y + i, |
3917 | right_x + 1 - i * right_p, top_y + i); | |
3918 | ||
3919 | /* Left. */ | |
3920 | if (left_p) | |
3921 | for (i = 0; i < width; ++i) | |
de507556 | 3922 | XDrawLine (dpy, window, gc, |
44655e77 | 3923 | left_x + i, top_y + i, left_x + i, bottom_y - i + 1); |
06a2c219 | 3924 | |
de507556 | 3925 | XSetClipMask (dpy, gc, None); |
06a2c219 GM |
3926 | if (raised_p) |
3927 | gc = f->output_data.x->black_relief.gc; | |
3928 | else | |
3929 | gc = f->output_data.x->white_relief.gc; | |
de507556 | 3930 | XSetClipRectangles (dpy, gc, 0, 0, clip_rect, 1, Unsorted); |
06a2c219 GM |
3931 | |
3932 | /* Bottom. */ | |
3933 | for (i = 0; i < width; ++i) | |
de507556 GM |
3934 | XDrawLine (dpy, window, gc, |
3935 | left_x + i * left_p, bottom_y - i, | |
327f42ee | 3936 | right_x + 1 - i * right_p, bottom_y - i); |
06a2c219 GM |
3937 | |
3938 | /* Right. */ | |
3939 | if (right_p) | |
3940 | for (i = 0; i < width; ++i) | |
de507556 | 3941 | XDrawLine (dpy, window, gc, |
06a2c219 GM |
3942 | right_x - i, top_y + i + 1, right_x - i, bottom_y - i); |
3943 | ||
de507556 | 3944 | XSetClipMask (dpy, gc, None); |
06a2c219 GM |
3945 | } |
3946 | ||
3947 | ||
3948 | /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y, | |
3949 | RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to | |
3950 | draw, it must be >= 0. LEFT_P non-zero means draw a line on the | |
3951 | left side of the rectangle. RIGHT_P non-zero means draw a line | |
3952 | on the right side of the rectangle. CLIP_RECT is the clipping | |
3953 | rectangle to use when drawing. */ | |
3954 | ||
3955 | static void | |
3956 | x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
3957 | left_p, right_p, clip_rect) | |
3958 | struct glyph_string *s; | |
3959 | int left_x, top_y, right_x, bottom_y, left_p, right_p; | |
3960 | XRectangle *clip_rect; | |
3961 | { | |
3962 | XGCValues xgcv; | |
3963 | ||
3964 | XGetGCValues (s->display, s->gc, GCForeground, &xgcv); | |
3965 | XSetForeground (s->display, s->gc, s->face->box_color); | |
3966 | XSetClipRectangles (s->display, s->gc, 0, 0, clip_rect, 1, Unsorted); | |
3967 | ||
3968 | /* Top. */ | |
3969 | XFillRectangle (s->display, s->window, s->gc, | |
58e4fce8 | 3970 | left_x, top_y, right_x - left_x + 1, width); |
06a2c219 GM |
3971 | |
3972 | /* Left. */ | |
3973 | if (left_p) | |
3974 | XFillRectangle (s->display, s->window, s->gc, | |
58e4fce8 | 3975 | left_x, top_y, width, bottom_y - top_y + 1); |
06a2c219 GM |
3976 | |
3977 | /* Bottom. */ | |
3978 | XFillRectangle (s->display, s->window, s->gc, | |
58e4fce8 | 3979 | left_x, bottom_y - width + 1, right_x - left_x + 1, width); |
06a2c219 GM |
3980 | |
3981 | /* Right. */ | |
3982 | if (right_p) | |
3983 | XFillRectangle (s->display, s->window, s->gc, | |
58e4fce8 | 3984 | right_x - width + 1, top_y, width, bottom_y - top_y + 1); |
06a2c219 GM |
3985 | |
3986 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
3987 | XSetClipMask (s->display, s->gc, None); | |
3988 | } | |
3989 | ||
3990 | ||
3991 | /* Draw a box around glyph string S. */ | |
3992 | ||
3993 | static void | |
3994 | x_draw_glyph_string_box (s) | |
3995 | struct glyph_string *s; | |
3996 | { | |
3997 | int width, left_x, right_x, top_y, bottom_y, last_x, raised_p; | |
3998 | int left_p, right_p; | |
3999 | struct glyph *last_glyph; | |
4000 | XRectangle clip_rect; | |
4001 | ||
4002 | last_x = window_box_right (s->w, s->area); | |
4003 | if (s->row->full_width_p | |
4004 | && !s->w->pseudo_window_p) | |
4005 | { | |
3f332ef3 | 4006 | last_x += FRAME_X_RIGHT_FRINGE_WIDTH (s->f); |
06a2c219 GM |
4007 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s->f)) |
4008 | last_x += FRAME_SCROLL_BAR_WIDTH (s->f) * CANON_X_UNIT (s->f); | |
4009 | } | |
4010 | ||
4011 | /* The glyph that may have a right box line. */ | |
b4192550 | 4012 | last_glyph = (s->cmp || s->img |
06a2c219 GM |
4013 | ? s->first_glyph |
4014 | : s->first_glyph + s->nchars - 1); | |
4015 | ||
ea2ba0d4 | 4016 | width = abs (s->face->box_line_width); |
06a2c219 GM |
4017 | raised_p = s->face->box == FACE_RAISED_BOX; |
4018 | left_x = s->x; | |
57ac7c81 GM |
4019 | right_x = (s->row->full_width_p && s->extends_to_end_of_line_p |
4020 | ? last_x - 1 | |
4021 | : min (last_x, s->x + s->background_width) - 1); | |
06a2c219 GM |
4022 | top_y = s->y; |
4023 | bottom_y = top_y + s->height - 1; | |
4024 | ||
4025 | left_p = (s->first_glyph->left_box_line_p | |
4026 | || (s->hl == DRAW_MOUSE_FACE | |
4027 | && (s->prev == NULL | |
4028 | || s->prev->hl != s->hl))); | |
4029 | right_p = (last_glyph->right_box_line_p | |
4030 | || (s->hl == DRAW_MOUSE_FACE | |
4031 | && (s->next == NULL | |
4032 | || s->next->hl != s->hl))); | |
327f42ee | 4033 | |
06a2c219 GM |
4034 | x_get_glyph_string_clip_rect (s, &clip_rect); |
4035 | ||
4036 | if (s->face->box == FACE_SIMPLE_BOX) | |
4037 | x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, | |
4038 | left_p, right_p, &clip_rect); | |
4039 | else | |
4040 | { | |
4041 | x_setup_relief_colors (s); | |
4042 | x_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y, | |
4043 | width, raised_p, left_p, right_p, &clip_rect); | |
4044 | } | |
4045 | } | |
4046 | ||
4047 | ||
4048 | /* Draw foreground of image glyph string S. */ | |
4049 | ||
4050 | static void | |
4051 | x_draw_image_foreground (s) | |
4052 | struct glyph_string *s; | |
4053 | { | |
4054 | int x; | |
95af8492 | 4055 | int y = s->ybase - image_ascent (s->img, s->face); |
06a2c219 GM |
4056 | |
4057 | /* If first glyph of S has a left box line, start drawing it to the | |
4058 | right of that line. */ | |
4059 | if (s->face->box != FACE_NO_BOX | |
4060 | && s->first_glyph->left_box_line_p) | |
ea2ba0d4 | 4061 | x = s->x + abs (s->face->box_line_width); |
06a2c219 GM |
4062 | else |
4063 | x = s->x; | |
4064 | ||
4065 | /* If there is a margin around the image, adjust x- and y-position | |
4066 | by that margin. */ | |
22d650b8 GM |
4067 | x += s->img->hmargin; |
4068 | y += s->img->vmargin; | |
06a2c219 GM |
4069 | |
4070 | if (s->img->pixmap) | |
4071 | { | |
4072 | if (s->img->mask) | |
4073 | { | |
4074 | /* We can't set both a clip mask and use XSetClipRectangles | |
4075 | because the latter also sets a clip mask. We also can't | |
4076 | trust on the shape extension to be available | |
4077 | (XShapeCombineRegion). So, compute the rectangle to draw | |
4078 | manually. */ | |
4079 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
4080 | | GCFunction); | |
4081 | XGCValues xgcv; | |
4082 | XRectangle clip_rect, image_rect, r; | |
4083 | ||
4084 | xgcv.clip_mask = s->img->mask; | |
4085 | xgcv.clip_x_origin = x; | |
4086 | xgcv.clip_y_origin = y; | |
4087 | xgcv.function = GXcopy; | |
4088 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
4089 | ||
4090 | x_get_glyph_string_clip_rect (s, &clip_rect); | |
4091 | image_rect.x = x; | |
4092 | image_rect.y = y; | |
4093 | image_rect.width = s->img->width; | |
4094 | image_rect.height = s->img->height; | |
4095 | if (x_intersect_rectangles (&clip_rect, &image_rect, &r)) | |
4096 | XCopyArea (s->display, s->img->pixmap, s->window, s->gc, | |
4097 | r.x - x, r.y - y, r.width, r.height, r.x, r.y); | |
4098 | } | |
4099 | else | |
4100 | { | |
49ad1d99 GM |
4101 | XRectangle clip_rect, image_rect, r; |
4102 | ||
4103 | x_get_glyph_string_clip_rect (s, &clip_rect); | |
4104 | image_rect.x = x; | |
4105 | image_rect.y = y; | |
4106 | image_rect.width = s->img->width; | |
4107 | image_rect.height = s->img->height; | |
4108 | if (x_intersect_rectangles (&clip_rect, &image_rect, &r)) | |
4109 | XCopyArea (s->display, s->img->pixmap, s->window, s->gc, | |
4110 | r.x - x, r.y - y, r.width, r.height, r.x, r.y); | |
06a2c219 GM |
4111 | |
4112 | /* When the image has a mask, we can expect that at | |
4113 | least part of a mouse highlight or a block cursor will | |
4114 | be visible. If the image doesn't have a mask, make | |
4115 | a block cursor visible by drawing a rectangle around | |
4116 | the image. I believe it's looking better if we do | |
4117 | nothing here for mouse-face. */ | |
4118 | if (s->hl == DRAW_CURSOR) | |
4119 | XDrawRectangle (s->display, s->window, s->gc, x, y, | |
4120 | s->img->width - 1, s->img->height - 1); | |
4121 | } | |
4122 | } | |
4123 | else | |
4124 | /* Draw a rectangle if image could not be loaded. */ | |
4125 | XDrawRectangle (s->display, s->window, s->gc, x, y, | |
4126 | s->img->width - 1, s->img->height - 1); | |
4127 | } | |
4128 | ||
4129 | ||
4130 | /* Draw a relief around the image glyph string S. */ | |
4131 | ||
4132 | static void | |
4133 | x_draw_image_relief (s) | |
4134 | struct glyph_string *s; | |
4135 | { | |
4136 | int x0, y0, x1, y1, thick, raised_p; | |
4137 | XRectangle r; | |
4138 | int x; | |
95af8492 | 4139 | int y = s->ybase - image_ascent (s->img, s->face); |
06a2c219 GM |
4140 | |
4141 | /* If first glyph of S has a left box line, start drawing it to the | |
4142 | right of that line. */ | |
4143 | if (s->face->box != FACE_NO_BOX | |
4144 | && s->first_glyph->left_box_line_p) | |
ea2ba0d4 | 4145 | x = s->x + abs (s->face->box_line_width); |
06a2c219 GM |
4146 | else |
4147 | x = s->x; | |
4148 | ||
4149 | /* If there is a margin around the image, adjust x- and y-position | |
4150 | by that margin. */ | |
22d650b8 GM |
4151 | x += s->img->hmargin; |
4152 | y += s->img->vmargin; | |
06a2c219 GM |
4153 | |
4154 | if (s->hl == DRAW_IMAGE_SUNKEN | |
4155 | || s->hl == DRAW_IMAGE_RAISED) | |
4156 | { | |
62854fe2 | 4157 | thick = tool_bar_button_relief >= 0 ? tool_bar_button_relief : DEFAULT_TOOL_BAR_BUTTON_RELIEF; |
06a2c219 GM |
4158 | raised_p = s->hl == DRAW_IMAGE_RAISED; |
4159 | } | |
4160 | else | |
4161 | { | |
4162 | thick = abs (s->img->relief); | |
4163 | raised_p = s->img->relief > 0; | |
4164 | } | |
4165 | ||
4166 | x0 = x - thick; | |
4167 | y0 = y - thick; | |
4168 | x1 = x + s->img->width + thick - 1; | |
4169 | y1 = y + s->img->height + thick - 1; | |
4170 | ||
4171 | x_setup_relief_colors (s); | |
4172 | x_get_glyph_string_clip_rect (s, &r); | |
4173 | x_draw_relief_rect (s->f, x0, y0, x1, y1, thick, raised_p, 1, 1, &r); | |
4174 | } | |
4175 | ||
4176 | ||
4177 | /* Draw the foreground of image glyph string S to PIXMAP. */ | |
4178 | ||
4179 | static void | |
4180 | x_draw_image_foreground_1 (s, pixmap) | |
4181 | struct glyph_string *s; | |
4182 | Pixmap pixmap; | |
4183 | { | |
4184 | int x; | |
95af8492 | 4185 | int y = s->ybase - s->y - image_ascent (s->img, s->face); |
06a2c219 GM |
4186 | |
4187 | /* If first glyph of S has a left box line, start drawing it to the | |
4188 | right of that line. */ | |
4189 | if (s->face->box != FACE_NO_BOX | |
4190 | && s->first_glyph->left_box_line_p) | |
ea2ba0d4 | 4191 | x = abs (s->face->box_line_width); |
06a2c219 GM |
4192 | else |
4193 | x = 0; | |
4194 | ||
4195 | /* If there is a margin around the image, adjust x- and y-position | |
4196 | by that margin. */ | |
22d650b8 GM |
4197 | x += s->img->hmargin; |
4198 | y += s->img->vmargin; | |
dc43ef94 | 4199 | |
06a2c219 GM |
4200 | if (s->img->pixmap) |
4201 | { | |
4202 | if (s->img->mask) | |
4203 | { | |
4204 | /* We can't set both a clip mask and use XSetClipRectangles | |
4205 | because the latter also sets a clip mask. We also can't | |
4206 | trust on the shape extension to be available | |
4207 | (XShapeCombineRegion). So, compute the rectangle to draw | |
4208 | manually. */ | |
4209 | unsigned long mask = (GCClipMask | GCClipXOrigin | GCClipYOrigin | |
4210 | | GCFunction); | |
4211 | XGCValues xgcv; | |
4212 | ||
4213 | xgcv.clip_mask = s->img->mask; | |
4214 | xgcv.clip_x_origin = x; | |
4215 | xgcv.clip_y_origin = y; | |
4216 | xgcv.function = GXcopy; | |
4217 | XChangeGC (s->display, s->gc, mask, &xgcv); | |
4218 | ||
4219 | XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, | |
4220 | 0, 0, s->img->width, s->img->height, x, y); | |
4221 | XSetClipMask (s->display, s->gc, None); | |
4222 | } | |
4223 | else | |
4224 | { | |
4225 | XCopyArea (s->display, s->img->pixmap, pixmap, s->gc, | |
4226 | 0, 0, s->img->width, s->img->height, x, y); | |
4227 | ||
4228 | /* When the image has a mask, we can expect that at | |
4229 | least part of a mouse highlight or a block cursor will | |
4230 | be visible. If the image doesn't have a mask, make | |
4231 | a block cursor visible by drawing a rectangle around | |
4232 | the image. I believe it's looking better if we do | |
4233 | nothing here for mouse-face. */ | |
4234 | if (s->hl == DRAW_CURSOR) | |
4235 | XDrawRectangle (s->display, pixmap, s->gc, x, y, | |
4236 | s->img->width - 1, s->img->height - 1); | |
4237 | } | |
4238 | } | |
4239 | else | |
4240 | /* Draw a rectangle if image could not be loaded. */ | |
4241 | XDrawRectangle (s->display, pixmap, s->gc, x, y, | |
4242 | s->img->width - 1, s->img->height - 1); | |
4243 | } | |
dc43ef94 | 4244 | |
990ba854 | 4245 | |
06a2c219 GM |
4246 | /* Draw part of the background of glyph string S. X, Y, W, and H |
4247 | give the rectangle to draw. */ | |
a9a5b0a5 | 4248 | |
06a2c219 GM |
4249 | static void |
4250 | x_draw_glyph_string_bg_rect (s, x, y, w, h) | |
4251 | struct glyph_string *s; | |
4252 | int x, y, w, h; | |
4253 | { | |
4254 | if (s->stippled_p) | |
4255 | { | |
4256 | /* Fill background with a stipple pattern. */ | |
4257 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
4258 | XFillRectangle (s->display, s->window, s->gc, x, y, w, h); | |
4259 | XSetFillStyle (s->display, s->gc, FillSolid); | |
4260 | } | |
4261 | else | |
4262 | x_clear_glyph_string_rect (s, x, y, w, h); | |
4263 | } | |
07e34cb0 | 4264 | |
b5210ea7 | 4265 | |
06a2c219 | 4266 | /* Draw image glyph string S. |
dc43ef94 | 4267 | |
06a2c219 GM |
4268 | s->y |
4269 | s->x +------------------------- | |
4270 | | s->face->box | |
4271 | | | |
4272 | | +------------------------- | |
4273 | | | s->img->margin | |
4274 | | | | |
4275 | | | +------------------- | |
4276 | | | | the image | |
dc43ef94 | 4277 | |
06a2c219 | 4278 | */ |
dc43ef94 | 4279 | |
06a2c219 GM |
4280 | static void |
4281 | x_draw_image_glyph_string (s) | |
4282 | struct glyph_string *s; | |
4283 | { | |
4284 | int x, y; | |
ea2ba0d4 KH |
4285 | int box_line_hwidth = abs (s->face->box_line_width); |
4286 | int box_line_vwidth = max (s->face->box_line_width, 0); | |
06a2c219 GM |
4287 | int height; |
4288 | Pixmap pixmap = None; | |
4289 | ||
ea2ba0d4 | 4290 | height = s->height - 2 * box_line_vwidth; |
06a2c219 GM |
4291 | |
4292 | /* Fill background with face under the image. Do it only if row is | |
4293 | taller than image or if image has a clip mask to reduce | |
4294 | flickering. */ | |
4295 | s->stippled_p = s->face->stipple != 0; | |
4296 | if (height > s->img->height | |
22d650b8 GM |
4297 | || s->img->hmargin |
4298 | || s->img->vmargin | |
06a2c219 GM |
4299 | || s->img->mask |
4300 | || s->img->pixmap == 0 | |
4301 | || s->width != s->background_width) | |
4302 | { | |
ea2ba0d4 KH |
4303 | if (box_line_hwidth && s->first_glyph->left_box_line_p) |
4304 | x = s->x + box_line_hwidth; | |
06a2c219 GM |
4305 | else |
4306 | x = s->x; | |
4307 | ||
ea2ba0d4 | 4308 | y = s->y + box_line_vwidth; |
06a2c219 GM |
4309 | |
4310 | if (s->img->mask) | |
4311 | { | |
f9b5db02 GM |
4312 | /* Create a pixmap as large as the glyph string. Fill it |
4313 | with the background color. Copy the image to it, using | |
4314 | its mask. Copy the temporary pixmap to the display. */ | |
06a2c219 GM |
4315 | Screen *screen = FRAME_X_SCREEN (s->f); |
4316 | int depth = DefaultDepthOfScreen (screen); | |
4317 | ||
4318 | /* Create a pixmap as large as the glyph string. */ | |
4319 | pixmap = XCreatePixmap (s->display, s->window, | |
4320 | s->background_width, | |
4321 | s->height, depth); | |
4322 | ||
4323 | /* Don't clip in the following because we're working on the | |
4324 | pixmap. */ | |
4325 | XSetClipMask (s->display, s->gc, None); | |
4326 | ||
4327 | /* Fill the pixmap with the background color/stipple. */ | |
4328 | if (s->stippled_p) | |
4329 | { | |
4330 | /* Fill background with a stipple pattern. */ | |
4331 | XSetFillStyle (s->display, s->gc, FillOpaqueStippled); | |
4332 | XFillRectangle (s->display, pixmap, s->gc, | |
4333 | 0, 0, s->background_width, s->height); | |
4334 | XSetFillStyle (s->display, s->gc, FillSolid); | |
4335 | } | |
4336 | else | |
4337 | { | |
4338 | XGCValues xgcv; | |
4339 | XGetGCValues (s->display, s->gc, GCForeground | GCBackground, | |
4340 | &xgcv); | |
4341 | XSetForeground (s->display, s->gc, xgcv.background); | |
4342 | XFillRectangle (s->display, pixmap, s->gc, | |
4343 | 0, 0, s->background_width, s->height); | |
4344 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4345 | } | |
4346 | } | |
4347 | else | |
06a2c219 GM |
4348 | x_draw_glyph_string_bg_rect (s, x, y, s->background_width, height); |
4349 | ||
4350 | s->background_filled_p = 1; | |
4351 | } | |
dc43ef94 | 4352 | |
06a2c219 GM |
4353 | /* Draw the foreground. */ |
4354 | if (pixmap != None) | |
4355 | { | |
4356 | x_draw_image_foreground_1 (s, pixmap); | |
4357 | x_set_glyph_string_clipping (s); | |
4358 | XCopyArea (s->display, pixmap, s->window, s->gc, | |
4359 | 0, 0, s->background_width, s->height, s->x, s->y); | |
4360 | XFreePixmap (s->display, pixmap); | |
4361 | } | |
4362 | else | |
4363 | x_draw_image_foreground (s); | |
b5210ea7 | 4364 | |
06a2c219 GM |
4365 | /* If we must draw a relief around the image, do it. */ |
4366 | if (s->img->relief | |
4367 | || s->hl == DRAW_IMAGE_RAISED | |
4368 | || s->hl == DRAW_IMAGE_SUNKEN) | |
4369 | x_draw_image_relief (s); | |
4370 | } | |
8c1a6a84 | 4371 | |
990ba854 | 4372 | |
06a2c219 | 4373 | /* Draw stretch glyph string S. */ |
dc43ef94 | 4374 | |
06a2c219 GM |
4375 | static void |
4376 | x_draw_stretch_glyph_string (s) | |
4377 | struct glyph_string *s; | |
4378 | { | |
4379 | xassert (s->first_glyph->type == STRETCH_GLYPH); | |
4380 | s->stippled_p = s->face->stipple != 0; | |
990ba854 | 4381 | |
06a2c219 GM |
4382 | if (s->hl == DRAW_CURSOR |
4383 | && !x_stretch_cursor_p) | |
4384 | { | |
4385 | /* If `x-stretch-block-cursor' is nil, don't draw a block cursor | |
4386 | as wide as the stretch glyph. */ | |
4387 | int width = min (CANON_X_UNIT (s->f), s->background_width); | |
990ba854 | 4388 | |
06a2c219 GM |
4389 | /* Draw cursor. */ |
4390 | x_draw_glyph_string_bg_rect (s, s->x, s->y, width, s->height); | |
0cdd0c9f | 4391 | |
06a2c219 GM |
4392 | /* Clear rest using the GC of the original non-cursor face. */ |
4393 | if (width < s->background_width) | |
4394 | { | |
06a2c219 GM |
4395 | int x = s->x + width, y = s->y; |
4396 | int w = s->background_width - width, h = s->height; | |
4397 | XRectangle r; | |
b7f83f9e | 4398 | GC gc; |
dc43ef94 | 4399 | |
b7f83f9e GM |
4400 | if (s->row->mouse_face_p |
4401 | && cursor_in_mouse_face_p (s->w)) | |
4402 | { | |
4403 | x_set_mouse_face_gc (s); | |
4404 | gc = s->gc; | |
4405 | } | |
4406 | else | |
4407 | gc = s->face->gc; | |
4408 | ||
06a2c219 GM |
4409 | x_get_glyph_string_clip_rect (s, &r); |
4410 | XSetClipRectangles (s->display, gc, 0, 0, &r, 1, Unsorted); | |
b7f83f9e | 4411 | |
06a2c219 GM |
4412 | if (s->face->stipple) |
4413 | { | |
4414 | /* Fill background with a stipple pattern. */ | |
4415 | XSetFillStyle (s->display, gc, FillOpaqueStippled); | |
4416 | XFillRectangle (s->display, s->window, gc, x, y, w, h); | |
4417 | XSetFillStyle (s->display, gc, FillSolid); | |
4418 | } | |
4419 | else | |
4420 | { | |
4421 | XGCValues xgcv; | |
4422 | XGetGCValues (s->display, gc, GCForeground | GCBackground, &xgcv); | |
4423 | XSetForeground (s->display, gc, xgcv.background); | |
4424 | XFillRectangle (s->display, s->window, gc, x, y, w, h); | |
4425 | XSetForeground (s->display, gc, xgcv.foreground); | |
4426 | } | |
4427 | } | |
4428 | } | |
61e9f9f3 | 4429 | else if (!s->background_filled_p) |
06a2c219 GM |
4430 | x_draw_glyph_string_bg_rect (s, s->x, s->y, s->background_width, |
4431 | s->height); | |
4432 | ||
4433 | s->background_filled_p = 1; | |
4434 | } | |
4435 | ||
4436 | ||
4437 | /* Draw glyph string S. */ | |
4438 | ||
4439 | static void | |
4440 | x_draw_glyph_string (s) | |
4441 | struct glyph_string *s; | |
4442 | { | |
4458cf11 KH |
4443 | int relief_drawn_p = 0; |
4444 | ||
06a2c219 GM |
4445 | /* If S draws into the background of its successor, draw the |
4446 | background of the successor first so that S can draw into it. | |
4447 | This makes S->next use XDrawString instead of XDrawImageString. */ | |
66ac4b0e | 4448 | if (s->next && s->right_overhang && !s->for_overlaps_p) |
06a2c219 GM |
4449 | { |
4450 | xassert (s->next->img == NULL); | |
4451 | x_set_glyph_string_gc (s->next); | |
4452 | x_set_glyph_string_clipping (s->next); | |
4453 | x_draw_glyph_string_background (s->next, 1); | |
4454 | } | |
97210f4e | 4455 | |
06a2c219 GM |
4456 | /* Set up S->gc, set clipping and draw S. */ |
4457 | x_set_glyph_string_gc (s); | |
06a2c219 | 4458 | |
4458cf11 KH |
4459 | /* Draw relief (if any) in advance for char/composition so that the |
4460 | glyph string can be drawn over it. */ | |
4461 | if (!s->for_overlaps_p | |
4462 | && s->face->box != FACE_NO_BOX | |
4463 | && (s->first_glyph->type == CHAR_GLYPH | |
4464 | || s->first_glyph->type == COMPOSITE_GLYPH)) | |
4465 | ||
4466 | { | |
e6269cbb | 4467 | x_set_glyph_string_clipping (s); |
4458cf11 KH |
4468 | x_draw_glyph_string_background (s, 1); |
4469 | x_draw_glyph_string_box (s); | |
e6269cbb | 4470 | x_set_glyph_string_clipping (s); |
4458cf11 KH |
4471 | relief_drawn_p = 1; |
4472 | } | |
e6269cbb GM |
4473 | else |
4474 | x_set_glyph_string_clipping (s); | |
4458cf11 | 4475 | |
06a2c219 GM |
4476 | switch (s->first_glyph->type) |
4477 | { | |
4478 | case IMAGE_GLYPH: | |
4479 | x_draw_image_glyph_string (s); | |
4480 | break; | |
4481 | ||
4482 | case STRETCH_GLYPH: | |
4483 | x_draw_stretch_glyph_string (s); | |
4484 | break; | |
4485 | ||
4486 | case CHAR_GLYPH: | |
66ac4b0e GM |
4487 | if (s->for_overlaps_p) |
4488 | s->background_filled_p = 1; | |
4489 | else | |
4490 | x_draw_glyph_string_background (s, 0); | |
06a2c219 GM |
4491 | x_draw_glyph_string_foreground (s); |
4492 | break; | |
4493 | ||
b4192550 KH |
4494 | case COMPOSITE_GLYPH: |
4495 | if (s->for_overlaps_p || s->gidx > 0) | |
4496 | s->background_filled_p = 1; | |
4497 | else | |
4498 | x_draw_glyph_string_background (s, 1); | |
4499 | x_draw_composite_glyph_string_foreground (s); | |
4500 | break; | |
4501 | ||
06a2c219 GM |
4502 | default: |
4503 | abort (); | |
4504 | } | |
4505 | ||
66ac4b0e | 4506 | if (!s->for_overlaps_p) |
06a2c219 | 4507 | { |
66ac4b0e GM |
4508 | /* Draw underline. */ |
4509 | if (s->face->underline_p) | |
4510 | { | |
e24e84cc GM |
4511 | unsigned long tem, h; |
4512 | int y; | |
06a2c219 | 4513 | |
e24e84cc | 4514 | /* Get the underline thickness. Default is 1 pixel. */ |
66ac4b0e GM |
4515 | if (!XGetFontProperty (s->font, XA_UNDERLINE_THICKNESS, &h)) |
4516 | h = 1; | |
e24e84cc GM |
4517 | |
4518 | /* Get the underline position. This is the recommended | |
4519 | vertical offset in pixels from the baseline to the top of | |
4520 | the underline. This is a signed value according to the | |
4521 | specs, and its default is | |
4522 | ||
4523 | ROUND ((maximum descent) / 2), with | |
4524 | ROUND(x) = floor (x + 0.5) */ | |
4525 | ||
a72d5ce5 GM |
4526 | if (x_use_underline_position_properties |
4527 | && XGetFontProperty (s->font, XA_UNDERLINE_POSITION, &tem)) | |
e24e84cc GM |
4528 | y = s->ybase + (long) tem; |
4529 | else if (s->face->font) | |
4530 | y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2; | |
4531 | else | |
a02f1be0 | 4532 | y = s->y + s->height - h; |
06a2c219 | 4533 | |
66ac4b0e | 4534 | if (s->face->underline_defaulted_p) |
e24e84cc GM |
4535 | XFillRectangle (s->display, s->window, s->gc, |
4536 | s->x, y, s->width, h); | |
66ac4b0e GM |
4537 | else |
4538 | { | |
4539 | XGCValues xgcv; | |
4540 | XGetGCValues (s->display, s->gc, GCForeground, &xgcv); | |
4541 | XSetForeground (s->display, s->gc, s->face->underline_color); | |
e24e84cc GM |
4542 | XFillRectangle (s->display, s->window, s->gc, |
4543 | s->x, y, s->width, h); | |
66ac4b0e GM |
4544 | XSetForeground (s->display, s->gc, xgcv.foreground); |
4545 | } | |
dc6f92b8 | 4546 | } |
07e34cb0 | 4547 | |
66ac4b0e GM |
4548 | /* Draw overline. */ |
4549 | if (s->face->overline_p) | |
06a2c219 | 4550 | { |
66ac4b0e GM |
4551 | unsigned long dy = 0, h = 1; |
4552 | ||
4553 | if (s->face->overline_color_defaulted_p) | |
4554 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4555 | s->width, h); | |
4556 | else | |
4557 | { | |
4558 | XGCValues xgcv; | |
4559 | XGetGCValues (s->display, s->gc, GCForeground, &xgcv); | |
4560 | XSetForeground (s->display, s->gc, s->face->overline_color); | |
4561 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4562 | s->width, h); | |
4563 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4564 | } | |
06a2c219 | 4565 | } |
06a2c219 | 4566 | |
66ac4b0e GM |
4567 | /* Draw strike-through. */ |
4568 | if (s->face->strike_through_p) | |
06a2c219 | 4569 | { |
66ac4b0e GM |
4570 | unsigned long h = 1; |
4571 | unsigned long dy = (s->height - h) / 2; | |
4572 | ||
4573 | if (s->face->strike_through_color_defaulted_p) | |
4574 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4575 | s->width, h); | |
4576 | else | |
4577 | { | |
4578 | XGCValues xgcv; | |
4579 | XGetGCValues (s->display, s->gc, GCForeground, &xgcv); | |
4580 | XSetForeground (s->display, s->gc, s->face->strike_through_color); | |
4581 | XFillRectangle (s->display, s->window, s->gc, s->x, s->y + dy, | |
4582 | s->width, h); | |
4583 | XSetForeground (s->display, s->gc, xgcv.foreground); | |
4584 | } | |
06a2c219 | 4585 | } |
06a2c219 | 4586 | |
4458cf11 KH |
4587 | /* Draw relief if not yet drawn. */ |
4588 | if (!relief_drawn_p && s->face->box != FACE_NO_BOX) | |
66ac4b0e GM |
4589 | x_draw_glyph_string_box (s); |
4590 | } | |
06a2c219 GM |
4591 | |
4592 | /* Reset clipping. */ | |
4593 | XSetClipMask (s->display, s->gc, None); | |
dc6f92b8 | 4594 | } |
07e34cb0 | 4595 | |
06a2c219 | 4596 | |
b4192550 KH |
4597 | static int x_fill_composite_glyph_string P_ ((struct glyph_string *, |
4598 | struct face **, int)); | |
06a2c219 | 4599 | |
06a2c219 | 4600 | |
209f68d9 GM |
4601 | /* Fill glyph string S with composition components specified by S->cmp. |
4602 | ||
b4192550 KH |
4603 | FACES is an array of faces for all components of this composition. |
4604 | S->gidx is the index of the first component for S. | |
4605 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
209f68d9 | 4606 | use its physical height for clipping. |
06a2c219 | 4607 | |
b4192550 | 4608 | Value is the index of a component not in S. */ |
07e34cb0 | 4609 | |
b4192550 KH |
4610 | static int |
4611 | x_fill_composite_glyph_string (s, faces, overlaps_p) | |
06a2c219 | 4612 | struct glyph_string *s; |
b4192550 | 4613 | struct face **faces; |
66ac4b0e | 4614 | int overlaps_p; |
07e34cb0 | 4615 | { |
b4192550 | 4616 | int i; |
06a2c219 | 4617 | |
b4192550 | 4618 | xassert (s); |
06a2c219 | 4619 | |
b4192550 | 4620 | s->for_overlaps_p = overlaps_p; |
06a2c219 | 4621 | |
b4192550 KH |
4622 | s->face = faces[s->gidx]; |
4623 | s->font = s->face->font; | |
4624 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
06a2c219 | 4625 | |
b4192550 KH |
4626 | /* For all glyphs of this composition, starting at the offset |
4627 | S->gidx, until we reach the end of the definition or encounter a | |
4628 | glyph that requires the different face, add it to S. */ | |
4629 | ++s->nchars; | |
4630 | for (i = s->gidx + 1; i < s->cmp->glyph_len && faces[i] == s->face; ++i) | |
4631 | ++s->nchars; | |
06a2c219 | 4632 | |
b4192550 KH |
4633 | /* All glyph strings for the same composition has the same width, |
4634 | i.e. the width set for the first component of the composition. */ | |
06a2c219 | 4635 | |
06a2c219 GM |
4636 | s->width = s->first_glyph->pixel_width; |
4637 | ||
4638 | /* If the specified font could not be loaded, use the frame's | |
4639 | default font, but record the fact that we couldn't load it in | |
4640 | the glyph string so that we can draw rectangles for the | |
4641 | characters of the glyph string. */ | |
4642 | if (s->font == NULL) | |
4643 | { | |
4644 | s->font_not_found_p = 1; | |
4645 | s->font = FRAME_FONT (s->f); | |
4646 | } | |
4647 | ||
4648 | /* Adjust base line for subscript/superscript text. */ | |
4649 | s->ybase += s->first_glyph->voffset; | |
4650 | ||
4651 | xassert (s->face && s->face->gc); | |
4652 | ||
4653 | /* This glyph string must always be drawn with 16-bit functions. */ | |
4654 | s->two_byte_p = 1; | |
b4192550 KH |
4655 | |
4656 | return s->gidx + s->nchars; | |
06a2c219 GM |
4657 | } |
4658 | ||
4659 | ||
209f68d9 GM |
4660 | /* Fill glyph string S from a sequence of character glyphs. |
4661 | ||
06a2c219 | 4662 | FACE_ID is the face id of the string. START is the index of the |
66ac4b0e GM |
4663 | first glyph to consider, END is the index of the last + 1. |
4664 | OVERLAPS_P non-zero means S should draw the foreground only, and | |
209f68d9 | 4665 | use its physical height for clipping. |
66ac4b0e GM |
4666 | |
4667 | Value is the index of the first glyph not in S. */ | |
06a2c219 GM |
4668 | |
4669 | static int | |
66ac4b0e | 4670 | x_fill_glyph_string (s, face_id, start, end, overlaps_p) |
06a2c219 GM |
4671 | struct glyph_string *s; |
4672 | int face_id; | |
66ac4b0e | 4673 | int start, end, overlaps_p; |
06a2c219 GM |
4674 | { |
4675 | struct glyph *glyph, *last; | |
4676 | int voffset; | |
ee569018 | 4677 | int glyph_not_available_p; |
06a2c219 | 4678 | |
06a2c219 GM |
4679 | xassert (s->f == XFRAME (s->w->frame)); |
4680 | xassert (s->nchars == 0); | |
4681 | xassert (start >= 0 && end > start); | |
4682 | ||
66ac4b0e | 4683 | s->for_overlaps_p = overlaps_p, |
06a2c219 GM |
4684 | glyph = s->row->glyphs[s->area] + start; |
4685 | last = s->row->glyphs[s->area] + end; | |
4686 | voffset = glyph->voffset; | |
4687 | ||
ee569018 KH |
4688 | glyph_not_available_p = glyph->glyph_not_available_p; |
4689 | ||
06a2c219 GM |
4690 | while (glyph < last |
4691 | && glyph->type == CHAR_GLYPH | |
4692 | && glyph->voffset == voffset | |
ee569018 KH |
4693 | /* Same face id implies same font, nowadays. */ |
4694 | && glyph->face_id == face_id | |
4695 | && glyph->glyph_not_available_p == glyph_not_available_p) | |
06a2c219 | 4696 | { |
ee569018 KH |
4697 | int two_byte_p; |
4698 | ||
06a2c219 | 4699 | s->face = x_get_glyph_face_and_encoding (s->f, glyph, |
ee569018 KH |
4700 | s->char2b + s->nchars, |
4701 | &two_byte_p); | |
4702 | s->two_byte_p = two_byte_p; | |
06a2c219 GM |
4703 | ++s->nchars; |
4704 | xassert (s->nchars <= end - start); | |
4705 | s->width += glyph->pixel_width; | |
4706 | ++glyph; | |
4707 | } | |
4708 | ||
4709 | s->font = s->face->font; | |
4710 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); | |
4711 | ||
4712 | /* If the specified font could not be loaded, use the frame's font, | |
4713 | but record the fact that we couldn't load it in | |
4714 | S->font_not_found_p so that we can draw rectangles for the | |
4715 | characters of the glyph string. */ | |
ee569018 | 4716 | if (s->font == NULL || glyph_not_available_p) |
06a2c219 GM |
4717 | { |
4718 | s->font_not_found_p = 1; | |
4719 | s->font = FRAME_FONT (s->f); | |
4720 | } | |
4721 | ||
4722 | /* Adjust base line for subscript/superscript text. */ | |
4723 | s->ybase += voffset; | |
66ac4b0e | 4724 | |
06a2c219 GM |
4725 | xassert (s->face && s->face->gc); |
4726 | return glyph - s->row->glyphs[s->area]; | |
07e34cb0 | 4727 | } |
dc6f92b8 | 4728 | |
06a2c219 GM |
4729 | |
4730 | /* Fill glyph string S from image glyph S->first_glyph. */ | |
dc6f92b8 | 4731 | |
dfcf069d | 4732 | static void |
06a2c219 GM |
4733 | x_fill_image_glyph_string (s) |
4734 | struct glyph_string *s; | |
4735 | { | |
4736 | xassert (s->first_glyph->type == IMAGE_GLYPH); | |
43d120d8 | 4737 | s->img = IMAGE_FROM_ID (s->f, s->first_glyph->u.img_id); |
06a2c219 | 4738 | xassert (s->img); |
43d120d8 | 4739 | s->face = FACE_FROM_ID (s->f, s->first_glyph->face_id); |
06a2c219 GM |
4740 | s->font = s->face->font; |
4741 | s->width = s->first_glyph->pixel_width; | |
4742 | ||
4743 | /* Adjust base line for subscript/superscript text. */ | |
4744 | s->ybase += s->first_glyph->voffset; | |
4745 | } | |
4746 | ||
4747 | ||
209f68d9 | 4748 | /* Fill glyph string S from a sequence of stretch glyphs. |
06a2c219 | 4749 | |
209f68d9 GM |
4750 | ROW is the glyph row in which the glyphs are found, AREA is the |
4751 | area within the row. START is the index of the first glyph to | |
4752 | consider, END is the index of the last + 1. | |
4753 | ||
4754 | Value is the index of the first glyph not in S. */ | |
4755 | ||
4756 | static int | |
4757 | x_fill_stretch_glyph_string (s, row, area, start, end) | |
06a2c219 | 4758 | struct glyph_string *s; |
209f68d9 GM |
4759 | struct glyph_row *row; |
4760 | enum glyph_row_area area; | |
4761 | int start, end; | |
06a2c219 | 4762 | { |
209f68d9 GM |
4763 | struct glyph *glyph, *last; |
4764 | int voffset, face_id; | |
4765 | ||
06a2c219 | 4766 | xassert (s->first_glyph->type == STRETCH_GLYPH); |
209f68d9 GM |
4767 | |
4768 | glyph = s->row->glyphs[s->area] + start; | |
4769 | last = s->row->glyphs[s->area] + end; | |
4770 | face_id = glyph->face_id; | |
4771 | s->face = FACE_FROM_ID (s->f, face_id); | |
06a2c219 | 4772 | s->font = s->face->font; |
209f68d9 GM |
4773 | s->font_info = FONT_INFO_FROM_ID (s->f, s->face->font_info_id); |
4774 | s->width = glyph->pixel_width; | |
4775 | voffset = glyph->voffset; | |
4776 | ||
4777 | for (++glyph; | |
4778 | (glyph < last | |
4779 | && glyph->type == STRETCH_GLYPH | |
4780 | && glyph->voffset == voffset | |
4781 | && glyph->face_id == face_id); | |
4782 | ++glyph) | |
4783 | s->width += glyph->pixel_width; | |
06a2c219 GM |
4784 | |
4785 | /* Adjust base line for subscript/superscript text. */ | |
209f68d9 GM |
4786 | s->ybase += voffset; |
4787 | ||
c296fc01 GM |
4788 | /* The case that face->gc == 0 is handled when drawing the glyph |
4789 | string by calling PREPARE_FACE_FOR_DISPLAY. */ | |
4790 | xassert (s->face); | |
209f68d9 | 4791 | return glyph - s->row->glyphs[s->area]; |
06a2c219 GM |
4792 | } |
4793 | ||
4794 | ||
4795 | /* Initialize glyph string S. CHAR2B is a suitably allocated vector | |
4796 | of XChar2b structures for S; it can't be allocated in | |
4797 | x_init_glyph_string because it must be allocated via `alloca'. W | |
4798 | is the window on which S is drawn. ROW and AREA are the glyph row | |
4799 | and area within the row from which S is constructed. START is the | |
4800 | index of the first glyph structure covered by S. HL is a | |
4801 | face-override for drawing S. */ | |
4802 | ||
4803 | static void | |
4804 | x_init_glyph_string (s, char2b, w, row, area, start, hl) | |
4805 | struct glyph_string *s; | |
4806 | XChar2b *char2b; | |
4807 | struct window *w; | |
4808 | struct glyph_row *row; | |
4809 | enum glyph_row_area area; | |
4810 | int start; | |
4811 | enum draw_glyphs_face hl; | |
4812 | { | |
4813 | bzero (s, sizeof *s); | |
4814 | s->w = w; | |
4815 | s->f = XFRAME (w->frame); | |
4816 | s->display = FRAME_X_DISPLAY (s->f); | |
4817 | s->window = FRAME_X_WINDOW (s->f); | |
4818 | s->char2b = char2b; | |
4819 | s->hl = hl; | |
4820 | s->row = row; | |
4821 | s->area = area; | |
4822 | s->first_glyph = row->glyphs[area] + start; | |
4823 | s->height = row->height; | |
4824 | s->y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
4825 | ||
9ea173e8 GM |
4826 | /* Display the internal border below the tool-bar window. */ |
4827 | if (s->w == XWINDOW (s->f->tool_bar_window)) | |
06a2c219 GM |
4828 | s->y -= s->f->output_data.x->internal_border_width; |
4829 | ||
4830 | s->ybase = s->y + row->ascent; | |
4831 | } | |
4832 | ||
4833 | ||
4834 | /* Set background width of glyph string S. START is the index of the | |
4835 | first glyph following S. LAST_X is the right-most x-position + 1 | |
4836 | in the drawing area. */ | |
4837 | ||
4838 | static INLINE void | |
4839 | x_set_glyph_string_background_width (s, start, last_x) | |
4840 | struct glyph_string *s; | |
4841 | int start; | |
4842 | int last_x; | |
4843 | { | |
4844 | /* If the face of this glyph string has to be drawn to the end of | |
4845 | the drawing area, set S->extends_to_end_of_line_p. */ | |
4846 | struct face *default_face = FACE_FROM_ID (s->f, DEFAULT_FACE_ID); | |
4847 | ||
4848 | if (start == s->row->used[s->area] | |
eb79f5cc | 4849 | && s->area == TEXT_AREA |
7b0870b2 GM |
4850 | && ((s->hl == DRAW_NORMAL_TEXT |
4851 | && (s->row->fill_line_p | |
4852 | || s->face->background != default_face->background | |
4853 | || s->face->stipple != default_face->stipple | |
4854 | || s->row->mouse_face_p)) | |
327f42ee GM |
4855 | || s->hl == DRAW_MOUSE_FACE |
4856 | || ((s->hl == DRAW_IMAGE_RAISED || s->hl == DRAW_IMAGE_SUNKEN) | |
4857 | && s->row->fill_line_p))) | |
7b0870b2 | 4858 | s->extends_to_end_of_line_p = 1; |
06a2c219 GM |
4859 | |
4860 | /* If S extends its face to the end of the line, set its | |
4861 | background_width to the distance to the right edge of the drawing | |
4862 | area. */ | |
4863 | if (s->extends_to_end_of_line_p) | |
1da3fd71 | 4864 | s->background_width = last_x - s->x + 1; |
06a2c219 GM |
4865 | else |
4866 | s->background_width = s->width; | |
4867 | } | |
4868 | ||
4869 | ||
4870 | /* Add a glyph string for a stretch glyph to the list of strings | |
4871 | between HEAD and TAIL. START is the index of the stretch glyph in | |
4872 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4873 | in that glyph row area. X is the current output position assigned | |
4874 | to the new glyph string constructed. HL overrides that face of the | |
4875 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4876 | is the right-most x-position of the drawing area. */ | |
4877 | ||
8abee2e1 DL |
4878 | /* SunOS 4 bundled cc, barfed on continuations in the arg lists here |
4879 | and below -- keep them on one line. */ | |
4880 | #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ | |
06a2c219 GM |
4881 | do \ |
4882 | { \ | |
4883 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4884 | x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \ | |
209f68d9 | 4885 | START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \ |
06a2c219 | 4886 | x_append_glyph_string (&HEAD, &TAIL, s); \ |
06a2c219 GM |
4887 | s->x = (X); \ |
4888 | } \ | |
4889 | while (0) | |
4890 | ||
4891 | ||
4892 | /* Add a glyph string for an image glyph to the list of strings | |
4893 | between HEAD and TAIL. START is the index of the image glyph in | |
4894 | row area AREA of glyph row ROW. END is the index of the last glyph | |
4895 | in that glyph row area. X is the current output position assigned | |
4896 | to the new glyph string constructed. HL overrides that face of the | |
4897 | glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X | |
4898 | is the right-most x-position of the drawing area. */ | |
4899 | ||
8abee2e1 | 4900 | #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \ |
06a2c219 GM |
4901 | do \ |
4902 | { \ | |
4903 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4904 | x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \ | |
4905 | x_fill_image_glyph_string (s); \ | |
4906 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
4907 | ++START; \ | |
4908 | s->x = (X); \ | |
4909 | } \ | |
4910 | while (0) | |
4911 | ||
4912 | ||
4913 | /* Add a glyph string for a sequence of character glyphs to the list | |
4914 | of strings between HEAD and TAIL. START is the index of the first | |
4915 | glyph in row area AREA of glyph row ROW that is part of the new | |
4916 | glyph string. END is the index of the last glyph in that glyph row | |
4917 | area. X is the current output position assigned to the new glyph | |
4918 | string constructed. HL overrides that face of the glyph; e.g. it | |
4919 | is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the | |
4920 | right-most x-position of the drawing area. */ | |
4921 | ||
8abee2e1 | 4922 | #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ |
06a2c219 GM |
4923 | do \ |
4924 | { \ | |
3e71d8f2 | 4925 | int c, face_id; \ |
06a2c219 GM |
4926 | XChar2b *char2b; \ |
4927 | \ | |
43d120d8 | 4928 | c = (ROW)->glyphs[AREA][START].u.ch; \ |
43d120d8 | 4929 | face_id = (ROW)->glyphs[AREA][START].face_id; \ |
06a2c219 | 4930 | \ |
b4192550 KH |
4931 | s = (struct glyph_string *) alloca (sizeof *s); \ |
4932 | char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \ | |
4933 | x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \ | |
4934 | x_append_glyph_string (&HEAD, &TAIL, s); \ | |
b4192550 KH |
4935 | s->x = (X); \ |
4936 | START = x_fill_glyph_string (s, face_id, START, END, \ | |
66ac4b0e | 4937 | OVERLAPS_P); \ |
06a2c219 GM |
4938 | } \ |
4939 | while (0) | |
4940 | ||
4941 | ||
b4192550 KH |
4942 | /* Add a glyph string for a composite sequence to the list of strings |
4943 | between HEAD and TAIL. START is the index of the first glyph in | |
4944 | row area AREA of glyph row ROW that is part of the new glyph | |
4945 | string. END is the index of the last glyph in that glyph row area. | |
4946 | X is the current output position assigned to the new glyph string | |
4947 | constructed. HL overrides that face of the glyph; e.g. it is | |
4948 | DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most | |
4949 | x-position of the drawing area. */ | |
4950 | ||
6c27ec25 | 4951 | #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ |
b4192550 | 4952 | do { \ |
43d120d8 KH |
4953 | int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \ |
4954 | int face_id = (ROW)->glyphs[AREA][START].face_id; \ | |
ee569018 | 4955 | struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \ |
b4192550 KH |
4956 | struct composition *cmp = composition_table[cmp_id]; \ |
4957 | int glyph_len = cmp->glyph_len; \ | |
4958 | XChar2b *char2b; \ | |
4959 | struct face **faces; \ | |
4960 | struct glyph_string *first_s = NULL; \ | |
4961 | int n; \ | |
4962 | \ | |
ee569018 | 4963 | base_face = base_face->ascii_face; \ |
b4192550 KH |
4964 | char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \ |
4965 | faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \ | |
4966 | /* At first, fill in `char2b' and `faces'. */ \ | |
4967 | for (n = 0; n < glyph_len; n++) \ | |
4968 | { \ | |
43d120d8 | 4969 | int c = COMPOSITION_GLYPH (cmp, n); \ |
ee569018 KH |
4970 | int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \ |
4971 | faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \ | |
4972 | x_get_char_face_and_encoding (XFRAME (w->frame), c, \ | |
abfb6b46 | 4973 | this_face_id, char2b + n, 1, 1); \ |
b4192550 KH |
4974 | } \ |
4975 | \ | |
4976 | /* Make glyph_strings for each glyph sequence that is drawable by \ | |
4977 | the same face, and append them to HEAD/TAIL. */ \ | |
4978 | for (n = 0; n < cmp->glyph_len;) \ | |
4979 | { \ | |
4980 | s = (struct glyph_string *) alloca (sizeof *s); \ | |
4981 | x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \ | |
4982 | x_append_glyph_string (&(HEAD), &(TAIL), s); \ | |
4983 | s->cmp = cmp; \ | |
4984 | s->gidx = n; \ | |
b4192550 KH |
4985 | s->x = (X); \ |
4986 | \ | |
4987 | if (n == 0) \ | |
4988 | first_s = s; \ | |
4989 | \ | |
4990 | n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \ | |
4991 | } \ | |
4992 | \ | |
4993 | ++START; \ | |
4994 | s = first_s; \ | |
4995 | } while (0) | |
4996 | ||
4997 | ||
06a2c219 GM |
4998 | /* Build a list of glyph strings between HEAD and TAIL for the glyphs |
4999 | of AREA of glyph row ROW on window W between indices START and END. | |
5000 | HL overrides the face for drawing glyph strings, e.g. it is | |
5001 | DRAW_CURSOR to draw a cursor. X and LAST_X are start and end | |
5002 | x-positions of the drawing area. | |
5003 | ||
5004 | This is an ugly monster macro construct because we must use alloca | |
5005 | to allocate glyph strings (because x_draw_glyphs can be called | |
5006 | asynchronously). */ | |
5007 | ||
8abee2e1 | 5008 | #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \ |
06a2c219 GM |
5009 | do \ |
5010 | { \ | |
5011 | HEAD = TAIL = NULL; \ | |
5012 | while (START < END) \ | |
5013 | { \ | |
5014 | struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \ | |
5015 | switch (first_glyph->type) \ | |
5016 | { \ | |
5017 | case CHAR_GLYPH: \ | |
5018 | BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \ | |
66ac4b0e GM |
5019 | TAIL, HL, X, LAST_X, \ |
5020 | OVERLAPS_P); \ | |
06a2c219 GM |
5021 | break; \ |
5022 | \ | |
b4192550 KH |
5023 | case COMPOSITE_GLYPH: \ |
5024 | BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \ | |
5025 | HEAD, TAIL, HL, X, LAST_X,\ | |
5026 | OVERLAPS_P); \ | |
5027 | break; \ | |
5028 | \ | |
06a2c219 GM |
5029 | case STRETCH_GLYPH: \ |
5030 | BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \ | |
5031 | HEAD, TAIL, HL, X, LAST_X); \ | |
5032 | break; \ | |
5033 | \ | |
5034 | case IMAGE_GLYPH: \ | |
5035 | BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \ | |
5036 | TAIL, HL, X, LAST_X); \ | |
5037 | break; \ | |
5038 | \ | |
5039 | default: \ | |
5040 | abort (); \ | |
5041 | } \ | |
5042 | \ | |
5043 | x_set_glyph_string_background_width (s, START, LAST_X); \ | |
5044 | (X) += s->width; \ | |
5045 | } \ | |
5046 | } \ | |
5047 | while (0) | |
5048 | ||
5049 | ||
5050 | /* Draw glyphs between START and END in AREA of ROW on window W, | |
5051 | starting at x-position X. X is relative to AREA in W. HL is a | |
5052 | face-override with the following meaning: | |
5053 | ||
5054 | DRAW_NORMAL_TEXT draw normally | |
5055 | DRAW_CURSOR draw in cursor face | |
5056 | DRAW_MOUSE_FACE draw in mouse face. | |
5057 | DRAW_INVERSE_VIDEO draw in mode line face | |
5058 | DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it | |
5059 | DRAW_IMAGE_RAISED draw an image with a raised relief around it | |
5060 | ||
66ac4b0e GM |
5061 | If OVERLAPS_P is non-zero, draw only the foreground of characters |
5062 | and clip to the physical height of ROW. | |
5063 | ||
06a2c219 GM |
5064 | Value is the x-position reached, relative to AREA of W. */ |
5065 | ||
5066 | static int | |
f0a48a01 | 5067 | x_draw_glyphs (w, x, row, area, start, end, hl, overlaps_p) |
06a2c219 GM |
5068 | struct window *w; |
5069 | int x; | |
5070 | struct glyph_row *row; | |
5071 | enum glyph_row_area area; | |
5072 | int start, end; | |
5073 | enum draw_glyphs_face hl; | |
66ac4b0e | 5074 | int overlaps_p; |
dc6f92b8 | 5075 | { |
06a2c219 GM |
5076 | struct glyph_string *head, *tail; |
5077 | struct glyph_string *s; | |
5078 | int last_x, area_width; | |
5079 | int x_reached; | |
5080 | int i, j; | |
5081 | ||
5082 | /* Let's rather be paranoid than getting a SEGV. */ | |
06a2c219 | 5083 | end = min (end, row->used[area]); |
a8710abf GM |
5084 | start = max (0, start); |
5085 | start = min (end, start); | |
06a2c219 GM |
5086 | |
5087 | /* Translate X to frame coordinates. Set last_x to the right | |
5088 | end of the drawing area. */ | |
5089 | if (row->full_width_p) | |
5090 | { | |
5091 | /* X is relative to the left edge of W, without scroll bars | |
3f332ef3 | 5092 | or fringes. */ |
06a2c219 | 5093 | struct frame *f = XFRAME (w->frame); |
06a2c219 | 5094 | int window_left_x = WINDOW_LEFT_MARGIN (w) * CANON_X_UNIT (f); |
dc6f92b8 | 5095 | |
06a2c219 GM |
5096 | x += window_left_x; |
5097 | area_width = XFASTINT (w->width) * CANON_X_UNIT (f); | |
5098 | last_x = window_left_x + area_width; | |
5099 | ||
5100 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
5101 | { | |
110859fc | 5102 | int width = FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); |
06a2c219 GM |
5103 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) |
5104 | last_x += width; | |
5105 | else | |
5106 | x -= width; | |
5107 | } | |
dc6f92b8 | 5108 | |
b9432a85 | 5109 | x += FRAME_INTERNAL_BORDER_WIDTH (f); |
98fedd97 | 5110 | last_x += FRAME_INTERNAL_BORDER_WIDTH (f); |
06a2c219 GM |
5111 | } |
5112 | else | |
dc6f92b8 | 5113 | { |
06a2c219 GM |
5114 | x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, x); |
5115 | area_width = window_box_width (w, area); | |
5116 | last_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, area, area_width); | |
dc6f92b8 JB |
5117 | } |
5118 | ||
06a2c219 GM |
5119 | /* Build a doubly-linked list of glyph_string structures between |
5120 | head and tail from what we have to draw. Note that the macro | |
5121 | BUILD_GLYPH_STRINGS will modify its start parameter. That's | |
5122 | the reason we use a separate variable `i'. */ | |
5123 | i = start; | |
66ac4b0e GM |
5124 | BUILD_GLYPH_STRINGS (w, row, area, i, end, head, tail, hl, x, last_x, |
5125 | overlaps_p); | |
06a2c219 GM |
5126 | if (tail) |
5127 | x_reached = tail->x + tail->background_width; | |
5128 | else | |
5129 | x_reached = x; | |
90e65f07 | 5130 | |
06a2c219 GM |
5131 | /* If there are any glyphs with lbearing < 0 or rbearing > width in |
5132 | the row, redraw some glyphs in front or following the glyph | |
5133 | strings built above. */ | |
a8710abf | 5134 | if (head && !overlaps_p && row->contains_overlapping_glyphs_p) |
06a2c219 GM |
5135 | { |
5136 | int dummy_x = 0; | |
5137 | struct glyph_string *h, *t; | |
5138 | ||
5139 | /* Compute overhangs for all glyph strings. */ | |
5140 | for (s = head; s; s = s->next) | |
5141 | x_compute_glyph_string_overhangs (s); | |
5142 | ||
5143 | /* Prepend glyph strings for glyphs in front of the first glyph | |
5144 | string that are overwritten because of the first glyph | |
5145 | string's left overhang. The background of all strings | |
5146 | prepended must be drawn because the first glyph string | |
5147 | draws over it. */ | |
5148 | i = x_left_overwritten (head); | |
5149 | if (i >= 0) | |
5150 | { | |
5151 | j = i; | |
5152 | BUILD_GLYPH_STRINGS (w, row, area, j, start, h, t, | |
66ac4b0e GM |
5153 | DRAW_NORMAL_TEXT, dummy_x, last_x, |
5154 | overlaps_p); | |
06a2c219 | 5155 | start = i; |
06a2c219 GM |
5156 | x_compute_overhangs_and_x (t, head->x, 1); |
5157 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
5158 | } | |
58769bee | 5159 | |
06a2c219 GM |
5160 | /* Prepend glyph strings for glyphs in front of the first glyph |
5161 | string that overwrite that glyph string because of their | |
5162 | right overhang. For these strings, only the foreground must | |
5163 | be drawn, because it draws over the glyph string at `head'. | |
5164 | The background must not be drawn because this would overwrite | |
5165 | right overhangs of preceding glyphs for which no glyph | |
5166 | strings exist. */ | |
5167 | i = x_left_overwriting (head); | |
5168 | if (i >= 0) | |
5169 | { | |
5170 | BUILD_GLYPH_STRINGS (w, row, area, i, start, h, t, | |
66ac4b0e GM |
5171 | DRAW_NORMAL_TEXT, dummy_x, last_x, |
5172 | overlaps_p); | |
06a2c219 GM |
5173 | for (s = h; s; s = s->next) |
5174 | s->background_filled_p = 1; | |
06a2c219 GM |
5175 | x_compute_overhangs_and_x (t, head->x, 1); |
5176 | x_prepend_glyph_string_lists (&head, &tail, h, t); | |
5177 | } | |
dbcb258a | 5178 | |
06a2c219 GM |
5179 | /* Append glyphs strings for glyphs following the last glyph |
5180 | string tail that are overwritten by tail. The background of | |
5181 | these strings has to be drawn because tail's foreground draws | |
5182 | over it. */ | |
5183 | i = x_right_overwritten (tail); | |
5184 | if (i >= 0) | |
5185 | { | |
5186 | BUILD_GLYPH_STRINGS (w, row, area, end, i, h, t, | |
66ac4b0e GM |
5187 | DRAW_NORMAL_TEXT, x, last_x, |
5188 | overlaps_p); | |
06a2c219 GM |
5189 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); |
5190 | x_append_glyph_string_lists (&head, &tail, h, t); | |
06a2c219 | 5191 | } |
dc6f92b8 | 5192 | |
06a2c219 GM |
5193 | /* Append glyph strings for glyphs following the last glyph |
5194 | string tail that overwrite tail. The foreground of such | |
5195 | glyphs has to be drawn because it writes into the background | |
5196 | of tail. The background must not be drawn because it could | |
5197 | paint over the foreground of following glyphs. */ | |
5198 | i = x_right_overwriting (tail); | |
5199 | if (i >= 0) | |
5200 | { | |
5201 | BUILD_GLYPH_STRINGS (w, row, area, end, i, h, t, | |
66ac4b0e GM |
5202 | DRAW_NORMAL_TEXT, x, last_x, |
5203 | overlaps_p); | |
06a2c219 GM |
5204 | for (s = h; s; s = s->next) |
5205 | s->background_filled_p = 1; | |
5206 | x_compute_overhangs_and_x (h, tail->x + tail->width, 0); | |
5207 | x_append_glyph_string_lists (&head, &tail, h, t); | |
06a2c219 GM |
5208 | } |
5209 | } | |
58769bee | 5210 | |
06a2c219 GM |
5211 | /* Draw all strings. */ |
5212 | for (s = head; s; s = s->next) | |
5213 | x_draw_glyph_string (s); | |
dc6f92b8 | 5214 | |
bb313871 GM |
5215 | if (area == TEXT_AREA |
5216 | && !row->full_width_p | |
5217 | /* When drawing overlapping rows, only the glyph strings' | |
5218 | foreground is drawn, which doesn't erase a cursor | |
5219 | completely. */ | |
5220 | && !overlaps_p) | |
f0a48a01 GM |
5221 | { |
5222 | int x0 = head ? head->x : x; | |
5223 | int x1 = tail ? tail->x + tail->background_width : x; | |
5224 | ||
5225 | x0 = FRAME_TO_WINDOW_PIXEL_X (w, x0); | |
5226 | x1 = FRAME_TO_WINDOW_PIXEL_X (w, x1); | |
5227 | ||
bb313871 | 5228 | if (XFASTINT (w->left_margin_width) != 0) |
f0a48a01 GM |
5229 | { |
5230 | int left_area_width = window_box_width (w, LEFT_MARGIN_AREA); | |
5231 | x0 -= left_area_width; | |
5232 | x1 -= left_area_width; | |
5233 | } | |
5234 | ||
60626bab GM |
5235 | notice_overwritten_cursor (w, area, x0, x1, |
5236 | row->y, MATRIX_ROW_BOTTOM_Y (row)); | |
f0a48a01 GM |
5237 | } |
5238 | ||
06a2c219 GM |
5239 | /* Value is the x-position up to which drawn, relative to AREA of W. |
5240 | This doesn't include parts drawn because of overhangs. */ | |
5241 | x_reached = FRAME_TO_WINDOW_PIXEL_X (w, x_reached); | |
5242 | if (!row->full_width_p) | |
5243 | { | |
f0a48a01 | 5244 | if (area > LEFT_MARGIN_AREA && XFASTINT (w->left_margin_width) != 0) |
06a2c219 GM |
5245 | x_reached -= window_box_width (w, LEFT_MARGIN_AREA); |
5246 | if (area > TEXT_AREA) | |
5247 | x_reached -= window_box_width (w, TEXT_AREA); | |
5248 | } | |
a8710abf | 5249 | |
06a2c219 GM |
5250 | return x_reached; |
5251 | } | |
dc6f92b8 | 5252 | |
dc6f92b8 | 5253 | |
66ac4b0e GM |
5254 | /* Fix the display of area AREA of overlapping row ROW in window W. */ |
5255 | ||
5256 | static void | |
5257 | x_fix_overlapping_area (w, row, area) | |
5258 | struct window *w; | |
5259 | struct glyph_row *row; | |
5260 | enum glyph_row_area area; | |
5261 | { | |
5262 | int i, x; | |
5263 | ||
5264 | BLOCK_INPUT; | |
5265 | ||
5266 | if (area == LEFT_MARGIN_AREA) | |
5267 | x = 0; | |
5268 | else if (area == TEXT_AREA) | |
5269 | x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5270 | else | |
5271 | x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5272 | + window_box_width (w, TEXT_AREA)); | |
5273 | ||
5274 | for (i = 0; i < row->used[area];) | |
5275 | { | |
5276 | if (row->glyphs[area][i].overlaps_vertically_p) | |
5277 | { | |
5278 | int start = i, start_x = x; | |
5279 | ||
5280 | do | |
5281 | { | |
5282 | x += row->glyphs[area][i].pixel_width; | |
5283 | ++i; | |
5284 | } | |
5285 | while (i < row->used[area] | |
5286 | && row->glyphs[area][i].overlaps_vertically_p); | |
5287 | ||
5288 | x_draw_glyphs (w, start_x, row, area, start, i, | |
f0a48a01 | 5289 | DRAW_NORMAL_TEXT, 1); |
66ac4b0e GM |
5290 | } |
5291 | else | |
5292 | { | |
5293 | x += row->glyphs[area][i].pixel_width; | |
5294 | ++i; | |
5295 | } | |
5296 | } | |
5297 | ||
5298 | UNBLOCK_INPUT; | |
5299 | } | |
5300 | ||
5301 | ||
06a2c219 GM |
5302 | /* Output LEN glyphs starting at START at the nominal cursor position. |
5303 | Advance the nominal cursor over the text. The global variable | |
5304 | updated_window contains the window being updated, updated_row is | |
5305 | the glyph row being updated, and updated_area is the area of that | |
5306 | row being updated. */ | |
dc6f92b8 | 5307 | |
06a2c219 GM |
5308 | static void |
5309 | x_write_glyphs (start, len) | |
5310 | struct glyph *start; | |
5311 | int len; | |
5312 | { | |
f0a48a01 | 5313 | int x, hpos; |
d9cdbb3d | 5314 | |
06a2c219 | 5315 | xassert (updated_window && updated_row); |
dc6f92b8 | 5316 | BLOCK_INPUT; |
06a2c219 GM |
5317 | |
5318 | /* Write glyphs. */ | |
dc6f92b8 | 5319 | |
06a2c219 GM |
5320 | hpos = start - updated_row->glyphs[updated_area]; |
5321 | x = x_draw_glyphs (updated_window, output_cursor.x, | |
5322 | updated_row, updated_area, | |
5323 | hpos, hpos + len, | |
f0a48a01 | 5324 | DRAW_NORMAL_TEXT, 0); |
dc6f92b8 JB |
5325 | |
5326 | UNBLOCK_INPUT; | |
06a2c219 GM |
5327 | |
5328 | /* Advance the output cursor. */ | |
5329 | output_cursor.hpos += len; | |
5330 | output_cursor.x = x; | |
dc6f92b8 JB |
5331 | } |
5332 | ||
0cdd0c9f | 5333 | |
06a2c219 | 5334 | /* Insert LEN glyphs from START at the nominal cursor position. */ |
0cdd0c9f | 5335 | |
06a2c219 GM |
5336 | static void |
5337 | x_insert_glyphs (start, len) | |
5338 | struct glyph *start; | |
5339 | register int len; | |
5340 | { | |
5341 | struct frame *f; | |
5342 | struct window *w; | |
5343 | int line_height, shift_by_width, shifted_region_width; | |
5344 | struct glyph_row *row; | |
5345 | struct glyph *glyph; | |
2beb36f9 | 5346 | int frame_x, frame_y, hpos; |
58769bee | 5347 | |
06a2c219 | 5348 | xassert (updated_window && updated_row); |
0cdd0c9f | 5349 | BLOCK_INPUT; |
06a2c219 GM |
5350 | w = updated_window; |
5351 | f = XFRAME (WINDOW_FRAME (w)); | |
5352 | ||
5353 | /* Get the height of the line we are in. */ | |
5354 | row = updated_row; | |
5355 | line_height = row->height; | |
5356 | ||
5357 | /* Get the width of the glyphs to insert. */ | |
5358 | shift_by_width = 0; | |
5359 | for (glyph = start; glyph < start + len; ++glyph) | |
5360 | shift_by_width += glyph->pixel_width; | |
5361 | ||
5362 | /* Get the width of the region to shift right. */ | |
5363 | shifted_region_width = (window_box_width (w, updated_area) | |
5364 | - output_cursor.x | |
5365 | - shift_by_width); | |
5366 | ||
5367 | /* Shift right. */ | |
bf0ab8a2 | 5368 | frame_x = window_box_left (w, updated_area) + output_cursor.x; |
06a2c219 GM |
5369 | frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y); |
5370 | XCopyArea (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), FRAME_X_WINDOW (f), | |
5371 | f->output_data.x->normal_gc, | |
5372 | frame_x, frame_y, | |
5373 | shifted_region_width, line_height, | |
5374 | frame_x + shift_by_width, frame_y); | |
5375 | ||
5376 | /* Write the glyphs. */ | |
5377 | hpos = start - row->glyphs[updated_area]; | |
5378 | x_draw_glyphs (w, output_cursor.x, row, updated_area, hpos, hpos + len, | |
f0a48a01 | 5379 | DRAW_NORMAL_TEXT, 0); |
06a2c219 GM |
5380 | |
5381 | /* Advance the output cursor. */ | |
5382 | output_cursor.hpos += len; | |
5383 | output_cursor.x += shift_by_width; | |
0cdd0c9f RS |
5384 | UNBLOCK_INPUT; |
5385 | } | |
0cdd0c9f | 5386 | |
0cdd0c9f | 5387 | |
06a2c219 GM |
5388 | /* Delete N glyphs at the nominal cursor position. Not implemented |
5389 | for X frames. */ | |
c83febd7 RS |
5390 | |
5391 | static void | |
06a2c219 GM |
5392 | x_delete_glyphs (n) |
5393 | register int n; | |
c83febd7 | 5394 | { |
06a2c219 | 5395 | abort (); |
c83febd7 RS |
5396 | } |
5397 | ||
0cdd0c9f | 5398 | |
c5e6e06b GM |
5399 | /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable. |
5400 | If they are <= 0, this is probably an error. */ | |
5401 | ||
5402 | void | |
5403 | x_clear_area (dpy, window, x, y, width, height, exposures) | |
5404 | Display *dpy; | |
5405 | Window window; | |
5406 | int x, y; | |
5407 | int width, height; | |
5408 | int exposures; | |
5409 | { | |
5410 | xassert (width > 0 && height > 0); | |
5411 | XClearArea (dpy, window, x, y, width, height, exposures); | |
5412 | } | |
5413 | ||
5414 | ||
06a2c219 GM |
5415 | /* Erase the current text line from the nominal cursor position |
5416 | (inclusive) to pixel column TO_X (exclusive). The idea is that | |
5417 | everything from TO_X onward is already erased. | |
5418 | ||
5419 | TO_X is a pixel position relative to updated_area of | |
5420 | updated_window. TO_X == -1 means clear to the end of this area. */ | |
dc6f92b8 | 5421 | |
06a2c219 GM |
5422 | static void |
5423 | x_clear_end_of_line (to_x) | |
5424 | int to_x; | |
5425 | { | |
5426 | struct frame *f; | |
5427 | struct window *w = updated_window; | |
5428 | int max_x, min_y, max_y; | |
5429 | int from_x, from_y, to_y; | |
5430 | ||
5431 | xassert (updated_window && updated_row); | |
5432 | f = XFRAME (w->frame); | |
5433 | ||
5434 | if (updated_row->full_width_p) | |
5435 | { | |
5436 | max_x = XFASTINT (w->width) * CANON_X_UNIT (f); | |
5437 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f) | |
5438 | && !w->pseudo_window_p) | |
5439 | max_x += FRAME_SCROLL_BAR_WIDTH (f) * CANON_X_UNIT (f); | |
0cdd0c9f | 5440 | } |
06a2c219 GM |
5441 | else |
5442 | max_x = window_box_width (w, updated_area); | |
5443 | max_y = window_text_bottom_y (w); | |
dc6f92b8 | 5444 | |
06a2c219 GM |
5445 | /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end |
5446 | of window. For TO_X > 0, truncate to end of drawing area. */ | |
5447 | if (to_x == 0) | |
5448 | return; | |
5449 | else if (to_x < 0) | |
5450 | to_x = max_x; | |
5451 | else | |
5452 | to_x = min (to_x, max_x); | |
dbc4e1c1 | 5453 | |
06a2c219 GM |
5454 | to_y = min (max_y, output_cursor.y + updated_row->height); |
5455 | ||
5456 | /* Notice if the cursor will be cleared by this operation. */ | |
5457 | if (!updated_row->full_width_p) | |
60626bab GM |
5458 | notice_overwritten_cursor (w, updated_area, |
5459 | output_cursor.x, -1, | |
5460 | updated_row->y, | |
5461 | MATRIX_ROW_BOTTOM_Y (updated_row)); | |
dbc4e1c1 | 5462 | |
06a2c219 GM |
5463 | from_x = output_cursor.x; |
5464 | ||
5465 | /* Translate to frame coordinates. */ | |
5466 | if (updated_row->full_width_p) | |
5467 | { | |
5468 | from_x = WINDOW_TO_FRAME_PIXEL_X (w, from_x); | |
5469 | to_x = WINDOW_TO_FRAME_PIXEL_X (w, to_x); | |
5470 | } | |
0cdd0c9f RS |
5471 | else |
5472 | { | |
06a2c219 GM |
5473 | from_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, from_x); |
5474 | to_x = WINDOW_AREA_TO_FRAME_PIXEL_X (w, updated_area, to_x); | |
5475 | } | |
5476 | ||
045dee35 | 5477 | min_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); |
06a2c219 GM |
5478 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, max (min_y, output_cursor.y)); |
5479 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, to_y); | |
5480 | ||
5481 | /* Prevent inadvertently clearing to end of the X window. */ | |
5482 | if (to_x > from_x && to_y > from_y) | |
5483 | { | |
5484 | BLOCK_INPUT; | |
c5e6e06b GM |
5485 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
5486 | from_x, from_y, to_x - from_x, to_y - from_y, | |
5487 | False); | |
06a2c219 | 5488 | UNBLOCK_INPUT; |
0cdd0c9f | 5489 | } |
0cdd0c9f | 5490 | } |
dbc4e1c1 | 5491 | |
0cdd0c9f | 5492 | |
06a2c219 | 5493 | /* Clear entire frame. If updating_frame is non-null, clear that |
b86bd3dd | 5494 | frame. Otherwise clear the selected frame. */ |
06a2c219 GM |
5495 | |
5496 | static void | |
5497 | x_clear_frame () | |
0cdd0c9f | 5498 | { |
06a2c219 | 5499 | struct frame *f; |
0cdd0c9f | 5500 | |
06a2c219 GM |
5501 | if (updating_frame) |
5502 | f = updating_frame; | |
0cdd0c9f | 5503 | else |
b86bd3dd | 5504 | f = SELECTED_FRAME (); |
58769bee | 5505 | |
06a2c219 GM |
5506 | /* Clearing the frame will erase any cursor, so mark them all as no |
5507 | longer visible. */ | |
5508 | mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); | |
5509 | output_cursor.hpos = output_cursor.vpos = 0; | |
5510 | output_cursor.x = -1; | |
5511 | ||
5512 | /* We don't set the output cursor here because there will always | |
5513 | follow an explicit cursor_to. */ | |
5514 | BLOCK_INPUT; | |
5515 | XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); | |
5516 | ||
5517 | /* We have to clear the scroll bars, too. If we have changed | |
5518 | colors or something like that, then they should be notified. */ | |
5519 | x_scroll_bar_clear (f); | |
0cdd0c9f | 5520 | |
06a2c219 GM |
5521 | XFlush (FRAME_X_DISPLAY (f)); |
5522 | UNBLOCK_INPUT; | |
dc6f92b8 | 5523 | } |
06a2c219 GM |
5524 | |
5525 | ||
dc6f92b8 | 5526 | \f |
dbc4e1c1 JB |
5527 | /* Invert the middle quarter of the frame for .15 sec. */ |
5528 | ||
06a2c219 GM |
5529 | /* We use the select system call to do the waiting, so we have to make |
5530 | sure it's available. If it isn't, we just won't do visual bells. */ | |
5531 | ||
dbc4e1c1 JB |
5532 | #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) |
5533 | ||
06a2c219 GM |
5534 | |
5535 | /* Subtract the `struct timeval' values X and Y, storing the result in | |
5536 | *RESULT. Return 1 if the difference is negative, otherwise 0. */ | |
dbc4e1c1 JB |
5537 | |
5538 | static int | |
5539 | timeval_subtract (result, x, y) | |
5540 | struct timeval *result, x, y; | |
5541 | { | |
06a2c219 GM |
5542 | /* Perform the carry for the later subtraction by updating y. This |
5543 | is safer because on some systems the tv_sec member is unsigned. */ | |
dbc4e1c1 JB |
5544 | if (x.tv_usec < y.tv_usec) |
5545 | { | |
5546 | int nsec = (y.tv_usec - x.tv_usec) / 1000000 + 1; | |
5547 | y.tv_usec -= 1000000 * nsec; | |
5548 | y.tv_sec += nsec; | |
5549 | } | |
06a2c219 | 5550 | |
dbc4e1c1 JB |
5551 | if (x.tv_usec - y.tv_usec > 1000000) |
5552 | { | |
5553 | int nsec = (y.tv_usec - x.tv_usec) / 1000000; | |
5554 | y.tv_usec += 1000000 * nsec; | |
5555 | y.tv_sec -= nsec; | |
5556 | } | |
5557 | ||
06a2c219 GM |
5558 | /* Compute the time remaining to wait. tv_usec is certainly |
5559 | positive. */ | |
dbc4e1c1 JB |
5560 | result->tv_sec = x.tv_sec - y.tv_sec; |
5561 | result->tv_usec = x.tv_usec - y.tv_usec; | |
5562 | ||
06a2c219 GM |
5563 | /* Return indication of whether the result should be considered |
5564 | negative. */ | |
dbc4e1c1 JB |
5565 | return x.tv_sec < y.tv_sec; |
5566 | } | |
dc6f92b8 | 5567 | |
dfcf069d | 5568 | void |
f676886a JB |
5569 | XTflash (f) |
5570 | struct frame *f; | |
dc6f92b8 | 5571 | { |
dbc4e1c1 | 5572 | BLOCK_INPUT; |
dc6f92b8 | 5573 | |
dbc4e1c1 JB |
5574 | { |
5575 | GC gc; | |
dc6f92b8 | 5576 | |
06a2c219 GM |
5577 | /* Create a GC that will use the GXxor function to flip foreground |
5578 | pixels into background pixels. */ | |
dbc4e1c1 JB |
5579 | { |
5580 | XGCValues values; | |
dc6f92b8 | 5581 | |
dbc4e1c1 | 5582 | values.function = GXxor; |
7556890b RS |
5583 | values.foreground = (f->output_data.x->foreground_pixel |
5584 | ^ f->output_data.x->background_pixel); | |
58769bee | 5585 | |
334208b7 | 5586 | gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
dbc4e1c1 JB |
5587 | GCFunction | GCForeground, &values); |
5588 | } | |
dc6f92b8 | 5589 | |
dbc4e1c1 | 5590 | { |
e84e14c3 RS |
5591 | /* Get the height not including a menu bar widget. */ |
5592 | int height = CHAR_TO_PIXEL_HEIGHT (f, FRAME_HEIGHT (f)); | |
5593 | /* Height of each line to flash. */ | |
5594 | int flash_height = FRAME_LINE_HEIGHT (f); | |
5595 | /* These will be the left and right margins of the rectangles. */ | |
5596 | int flash_left = FRAME_INTERNAL_BORDER_WIDTH (f); | |
5597 | int flash_right = PIXEL_WIDTH (f) - FRAME_INTERNAL_BORDER_WIDTH (f); | |
5598 | ||
5599 | int width; | |
5600 | ||
5601 | /* Don't flash the area between a scroll bar and the frame | |
5602 | edge it is next to. */ | |
5603 | switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f)) | |
5604 | { | |
5605 | case vertical_scroll_bar_left: | |
5606 | flash_left += VERTICAL_SCROLL_BAR_WIDTH_TRIM; | |
5607 | break; | |
5608 | ||
5609 | case vertical_scroll_bar_right: | |
5610 | flash_right -= VERTICAL_SCROLL_BAR_WIDTH_TRIM; | |
5611 | break; | |
06a2c219 GM |
5612 | |
5613 | default: | |
5614 | break; | |
e84e14c3 RS |
5615 | } |
5616 | ||
5617 | width = flash_right - flash_left; | |
5618 | ||
5619 | /* If window is tall, flash top and bottom line. */ | |
5620 | if (height > 3 * FRAME_LINE_HEIGHT (f)) | |
5621 | { | |
5622 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
06a2c219 GM |
5623 | flash_left, |
5624 | (FRAME_INTERNAL_BORDER_WIDTH (f) | |
9ea173e8 | 5625 | + FRAME_TOOL_BAR_LINES (f) * CANON_Y_UNIT (f)), |
e84e14c3 RS |
5626 | width, flash_height); |
5627 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
5628 | flash_left, | |
5629 | (height - flash_height | |
5630 | - FRAME_INTERNAL_BORDER_WIDTH (f)), | |
5631 | width, flash_height); | |
5632 | } | |
5633 | else | |
5634 | /* If it is short, flash it all. */ | |
5635 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
5636 | flash_left, FRAME_INTERNAL_BORDER_WIDTH (f), | |
5637 | width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); | |
dc6f92b8 | 5638 | |
06a2c219 | 5639 | x_flush (f); |
dc6f92b8 | 5640 | |
dbc4e1c1 | 5641 | { |
06a2c219 | 5642 | struct timeval wakeup; |
dc6f92b8 | 5643 | |
66c30ea1 | 5644 | EMACS_GET_TIME (wakeup); |
dc6f92b8 | 5645 | |
dbc4e1c1 JB |
5646 | /* Compute time to wait until, propagating carry from usecs. */ |
5647 | wakeup.tv_usec += 150000; | |
5648 | wakeup.tv_sec += (wakeup.tv_usec / 1000000); | |
5649 | wakeup.tv_usec %= 1000000; | |
5650 | ||
101922c3 GM |
5651 | /* Keep waiting until past the time wakeup or any input gets |
5652 | available. */ | |
5653 | while (! detect_input_pending ()) | |
dbc4e1c1 | 5654 | { |
101922c3 | 5655 | struct timeval current; |
dbc4e1c1 JB |
5656 | struct timeval timeout; |
5657 | ||
101922c3 | 5658 | EMACS_GET_TIME (current); |
dbc4e1c1 | 5659 | |
101922c3 GM |
5660 | /* Break if result would be negative. */ |
5661 | if (timeval_subtract (¤t, wakeup, current)) | |
dbc4e1c1 JB |
5662 | break; |
5663 | ||
101922c3 GM |
5664 | /* How long `select' should wait. */ |
5665 | timeout.tv_sec = 0; | |
5666 | timeout.tv_usec = 10000; | |
5667 | ||
dbc4e1c1 | 5668 | /* Try to wait that long--but we might wake up sooner. */ |
c32cdd9a | 5669 | select (0, NULL, NULL, NULL, &timeout); |
dbc4e1c1 JB |
5670 | } |
5671 | } | |
58769bee | 5672 | |
e84e14c3 RS |
5673 | /* If window is tall, flash top and bottom line. */ |
5674 | if (height > 3 * FRAME_LINE_HEIGHT (f)) | |
5675 | { | |
5676 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
06a2c219 GM |
5677 | flash_left, |
5678 | (FRAME_INTERNAL_BORDER_WIDTH (f) | |
9ea173e8 | 5679 | + FRAME_TOOL_BAR_LINES (f) * CANON_Y_UNIT (f)), |
e84e14c3 RS |
5680 | width, flash_height); |
5681 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
5682 | flash_left, | |
5683 | (height - flash_height | |
5684 | - FRAME_INTERNAL_BORDER_WIDTH (f)), | |
5685 | width, flash_height); | |
5686 | } | |
5687 | else | |
5688 | /* If it is short, flash it all. */ | |
5689 | XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, | |
5690 | flash_left, FRAME_INTERNAL_BORDER_WIDTH (f), | |
5691 | width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); | |
5692 | ||
334208b7 | 5693 | XFreeGC (FRAME_X_DISPLAY (f), gc); |
06a2c219 | 5694 | x_flush (f); |
dc6f92b8 | 5695 | } |
dbc4e1c1 JB |
5696 | } |
5697 | ||
5698 | UNBLOCK_INPUT; | |
dc6f92b8 JB |
5699 | } |
5700 | ||
06a2c219 | 5701 | #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */ |
dbc4e1c1 JB |
5702 | |
5703 | ||
dc6f92b8 JB |
5704 | /* Make audible bell. */ |
5705 | ||
dfcf069d | 5706 | void |
dc6f92b8 JB |
5707 | XTring_bell () |
5708 | { | |
b86bd3dd GM |
5709 | struct frame *f = SELECTED_FRAME (); |
5710 | ||
5711 | if (FRAME_X_DISPLAY (f)) | |
5712 | { | |
dbc4e1c1 | 5713 | #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) |
b86bd3dd GM |
5714 | if (visible_bell) |
5715 | XTflash (f); | |
5716 | else | |
dbc4e1c1 | 5717 | #endif |
b86bd3dd GM |
5718 | { |
5719 | BLOCK_INPUT; | |
5720 | XBell (FRAME_X_DISPLAY (f), 0); | |
5721 | XFlush (FRAME_X_DISPLAY (f)); | |
5722 | UNBLOCK_INPUT; | |
5723 | } | |
dc6f92b8 JB |
5724 | } |
5725 | } | |
06a2c219 | 5726 | |
dc6f92b8 | 5727 | \f |
06a2c219 GM |
5728 | /* Specify how many text lines, from the top of the window, |
5729 | should be affected by insert-lines and delete-lines operations. | |
5730 | This, and those operations, are used only within an update | |
5731 | that is bounded by calls to x_update_begin and x_update_end. */ | |
dc6f92b8 | 5732 | |
dfcf069d | 5733 | static void |
06a2c219 GM |
5734 | XTset_terminal_window (n) |
5735 | register int n; | |
dc6f92b8 | 5736 | { |
06a2c219 | 5737 | /* This function intentionally left blank. */ |
dc6f92b8 JB |
5738 | } |
5739 | ||
06a2c219 GM |
5740 | |
5741 | \f | |
5742 | /*********************************************************************** | |
5743 | Line Dance | |
5744 | ***********************************************************************/ | |
5745 | ||
5746 | /* Perform an insert-lines or delete-lines operation, inserting N | |
5747 | lines or deleting -N lines at vertical position VPOS. */ | |
5748 | ||
dfcf069d | 5749 | static void |
06a2c219 GM |
5750 | x_ins_del_lines (vpos, n) |
5751 | int vpos, n; | |
dc6f92b8 JB |
5752 | { |
5753 | abort (); | |
5754 | } | |
06a2c219 GM |
5755 | |
5756 | ||
5757 | /* Scroll part of the display as described by RUN. */ | |
dc6f92b8 | 5758 | |
dfcf069d | 5759 | static void |
06a2c219 GM |
5760 | x_scroll_run (w, run) |
5761 | struct window *w; | |
5762 | struct run *run; | |
dc6f92b8 | 5763 | { |
06a2c219 GM |
5764 | struct frame *f = XFRAME (w->frame); |
5765 | int x, y, width, height, from_y, to_y, bottom_y; | |
5766 | ||
5767 | /* Get frame-relative bounding box of the text display area of W, | |
3f332ef3 KS |
5768 | without mode lines. Include in this box the left and right |
5769 | fringe of W. */ | |
06a2c219 | 5770 | window_box (w, -1, &x, &y, &width, &height); |
3f332ef3 KS |
5771 | width += FRAME_X_FRINGE_WIDTH (f); |
5772 | x -= FRAME_X_LEFT_FRINGE_WIDTH (f); | |
06a2c219 GM |
5773 | |
5774 | from_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->current_y); | |
5775 | to_y = WINDOW_TO_FRAME_PIXEL_Y (w, run->desired_y); | |
5776 | bottom_y = y + height; | |
dc6f92b8 | 5777 | |
06a2c219 GM |
5778 | if (to_y < from_y) |
5779 | { | |
5780 | /* Scrolling up. Make sure we don't copy part of the mode | |
5781 | line at the bottom. */ | |
5782 | if (from_y + run->height > bottom_y) | |
5783 | height = bottom_y - from_y; | |
5784 | else | |
5785 | height = run->height; | |
5786 | } | |
dc6f92b8 | 5787 | else |
06a2c219 GM |
5788 | { |
5789 | /* Scolling down. Make sure we don't copy over the mode line. | |
5790 | at the bottom. */ | |
5791 | if (to_y + run->height > bottom_y) | |
5792 | height = bottom_y - to_y; | |
5793 | else | |
5794 | height = run->height; | |
5795 | } | |
7a13e894 | 5796 | |
06a2c219 GM |
5797 | BLOCK_INPUT; |
5798 | ||
5799 | /* Cursor off. Will be switched on again in x_update_window_end. */ | |
5800 | updated_window = w; | |
5801 | x_clear_cursor (w); | |
5802 | ||
5803 | XCopyArea (FRAME_X_DISPLAY (f), | |
5804 | FRAME_X_WINDOW (f), FRAME_X_WINDOW (f), | |
5805 | f->output_data.x->normal_gc, | |
5806 | x, from_y, | |
5807 | width, height, | |
5808 | x, to_y); | |
5809 | ||
5810 | UNBLOCK_INPUT; | |
5811 | } | |
dc6f92b8 | 5812 | |
dc6f92b8 | 5813 | |
06a2c219 GM |
5814 | \f |
5815 | /*********************************************************************** | |
5816 | Exposure Events | |
5817 | ***********************************************************************/ | |
5818 | ||
5819 | /* Redisplay an exposed area of frame F. X and Y are the upper-left | |
5820 | corner of the exposed rectangle. W and H are width and height of | |
5821 | the exposed area. All are pixel values. W or H zero means redraw | |
5822 | the entire frame. */ | |
dc6f92b8 | 5823 | |
06a2c219 GM |
5824 | static void |
5825 | expose_frame (f, x, y, w, h) | |
5826 | struct frame *f; | |
5827 | int x, y, w, h; | |
dc6f92b8 | 5828 | { |
06a2c219 | 5829 | XRectangle r; |
82f053ab | 5830 | int mouse_face_overwritten_p = 0; |
dc6f92b8 | 5831 | |
06a2c219 | 5832 | TRACE ((stderr, "expose_frame ")); |
dc6f92b8 | 5833 | |
06a2c219 GM |
5834 | /* No need to redraw if frame will be redrawn soon. */ |
5835 | if (FRAME_GARBAGED_P (f)) | |
dc6f92b8 | 5836 | { |
06a2c219 GM |
5837 | TRACE ((stderr, " garbaged\n")); |
5838 | return; | |
5839 | } | |
5840 | ||
5841 | /* If basic faces haven't been realized yet, there is no point in | |
5842 | trying to redraw anything. This can happen when we get an expose | |
5843 | event while Emacs is starting, e.g. by moving another window. */ | |
5844 | if (FRAME_FACE_CACHE (f) == NULL | |
5845 | || FRAME_FACE_CACHE (f)->used < BASIC_FACE_ID_SENTINEL) | |
5846 | { | |
5847 | TRACE ((stderr, " no faces\n")); | |
5848 | return; | |
58769bee | 5849 | } |
06a2c219 GM |
5850 | |
5851 | if (w == 0 || h == 0) | |
58769bee | 5852 | { |
06a2c219 GM |
5853 | r.x = r.y = 0; |
5854 | r.width = CANON_X_UNIT (f) * f->width; | |
5855 | r.height = CANON_Y_UNIT (f) * f->height; | |
dc6f92b8 JB |
5856 | } |
5857 | else | |
5858 | { | |
06a2c219 GM |
5859 | r.x = x; |
5860 | r.y = y; | |
5861 | r.width = w; | |
5862 | r.height = h; | |
5863 | } | |
5864 | ||
5865 | TRACE ((stderr, "(%d, %d, %d, %d)\n", r.x, r.y, r.width, r.height)); | |
82f053ab | 5866 | mouse_face_overwritten_p = expose_window_tree (XWINDOW (f->root_window), &r); |
06a2c219 | 5867 | |
9ea173e8 | 5868 | if (WINDOWP (f->tool_bar_window)) |
82f053ab GM |
5869 | mouse_face_overwritten_p |
5870 | |= expose_window (XWINDOW (f->tool_bar_window), &r); | |
06a2c219 GM |
5871 | |
5872 | #ifndef USE_X_TOOLKIT | |
5873 | if (WINDOWP (f->menu_bar_window)) | |
82f053ab GM |
5874 | mouse_face_overwritten_p |
5875 | |= expose_window (XWINDOW (f->menu_bar_window), &r); | |
06a2c219 | 5876 | #endif /* not USE_X_TOOLKIT */ |
82f053ab GM |
5877 | |
5878 | /* Some window managers support a focus-follows-mouse style with | |
5879 | delayed raising of frames. Imagine a partially obscured frame, | |
5880 | and moving the mouse into partially obscured mouse-face on that | |
5881 | frame. The visible part of the mouse-face will be highlighted, | |
5882 | then the WM raises the obscured frame. With at least one WM, KDE | |
5883 | 2.1, Emacs is not getting any event for the raising of the frame | |
5884 | (even tried with SubstructureRedirectMask), only Expose events. | |
5885 | These expose events will draw text normally, i.e. not | |
5886 | highlighted. Which means we must redo the highlight here. | |
5887 | Subsume it under ``we love X''. --gerd 2001-08-15 */ | |
5888 | if (mouse_face_overwritten_p && !FRAME_GARBAGED_P (f)) | |
5889 | { | |
5890 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
5891 | if (f == dpyinfo->mouse_face_mouse_frame) | |
5892 | { | |
5893 | int x = dpyinfo->mouse_face_mouse_x; | |
5894 | int y = dpyinfo->mouse_face_mouse_y; | |
5895 | clear_mouse_face (dpyinfo); | |
5896 | note_mouse_highlight (f, x, y); | |
5897 | } | |
5898 | } | |
dc6f92b8 JB |
5899 | } |
5900 | ||
06a2c219 GM |
5901 | |
5902 | /* Redraw (parts) of all windows in the window tree rooted at W that | |
82f053ab GM |
5903 | intersect R. R contains frame pixel coordinates. Value is |
5904 | non-zero if the exposure overwrites mouse-face. */ | |
06a2c219 | 5905 | |
82f053ab | 5906 | static int |
06a2c219 GM |
5907 | expose_window_tree (w, r) |
5908 | struct window *w; | |
5909 | XRectangle *r; | |
dc6f92b8 | 5910 | { |
82f053ab GM |
5911 | struct frame *f = XFRAME (w->frame); |
5912 | int mouse_face_overwritten_p = 0; | |
5913 | ||
5914 | while (w && !FRAME_GARBAGED_P (f)) | |
06a2c219 GM |
5915 | { |
5916 | if (!NILP (w->hchild)) | |
82f053ab GM |
5917 | mouse_face_overwritten_p |
5918 | |= expose_window_tree (XWINDOW (w->hchild), r); | |
06a2c219 | 5919 | else if (!NILP (w->vchild)) |
82f053ab GM |
5920 | mouse_face_overwritten_p |
5921 | |= expose_window_tree (XWINDOW (w->vchild), r); | |
5922 | else | |
5923 | mouse_face_overwritten_p |= expose_window (w, r); | |
5924 | ||
a02f1be0 | 5925 | w = NILP (w->next) ? NULL : XWINDOW (w->next); |
06a2c219 | 5926 | } |
82f053ab GM |
5927 | |
5928 | return mouse_face_overwritten_p; | |
06a2c219 | 5929 | } |
58769bee | 5930 | |
dc6f92b8 | 5931 | |
06a2c219 GM |
5932 | /* Redraw the part of glyph row area AREA of glyph row ROW on window W |
5933 | which intersects rectangle R. R is in window-relative coordinates. */ | |
5934 | ||
5935 | static void | |
5936 | expose_area (w, row, r, area) | |
5937 | struct window *w; | |
5938 | struct glyph_row *row; | |
5939 | XRectangle *r; | |
5940 | enum glyph_row_area area; | |
5941 | { | |
06a2c219 GM |
5942 | struct glyph *first = row->glyphs[area]; |
5943 | struct glyph *end = row->glyphs[area] + row->used[area]; | |
5944 | struct glyph *last; | |
4bc6dcc7 | 5945 | int first_x, start_x, x; |
06a2c219 | 5946 | |
6fb13182 GM |
5947 | if (area == TEXT_AREA && row->fill_line_p) |
5948 | /* If row extends face to end of line write the whole line. */ | |
153f5ed7 | 5949 | x_draw_glyphs (w, 0, row, area, 0, row->used[area], |
f0a48a01 | 5950 | DRAW_NORMAL_TEXT, 0); |
6fb13182 GM |
5951 | else |
5952 | { | |
4bc6dcc7 GM |
5953 | /* Set START_X to the window-relative start position for drawing glyphs of |
5954 | AREA. The first glyph of the text area can be partially visible. | |
5955 | The first glyphs of other areas cannot. */ | |
5956 | if (area == LEFT_MARGIN_AREA) | |
5957 | start_x = 0; | |
5958 | else if (area == TEXT_AREA) | |
5959 | start_x = row->x + window_box_width (w, LEFT_MARGIN_AREA); | |
5960 | else | |
5961 | start_x = (window_box_width (w, LEFT_MARGIN_AREA) | |
5962 | + window_box_width (w, TEXT_AREA)); | |
5963 | x = start_x; | |
5964 | ||
6fb13182 GM |
5965 | /* Find the first glyph that must be redrawn. */ |
5966 | while (first < end | |
5967 | && x + first->pixel_width < r->x) | |
5968 | { | |
5969 | x += first->pixel_width; | |
5970 | ++first; | |
5971 | } | |
5972 | ||
5973 | /* Find the last one. */ | |
5974 | last = first; | |
5975 | first_x = x; | |
5976 | while (last < end | |
5977 | && x < r->x + r->width) | |
5978 | { | |
5979 | x += last->pixel_width; | |
5980 | ++last; | |
5981 | } | |
5982 | ||
5983 | /* Repaint. */ | |
5984 | if (last > first) | |
4bc6dcc7 | 5985 | x_draw_glyphs (w, first_x - start_x, row, area, |
6fb13182 GM |
5986 | first - row->glyphs[area], |
5987 | last - row->glyphs[area], | |
f0a48a01 | 5988 | DRAW_NORMAL_TEXT, 0); |
6fb13182 | 5989 | } |
06a2c219 GM |
5990 | } |
5991 | ||
58769bee | 5992 | |
06a2c219 | 5993 | /* Redraw the parts of the glyph row ROW on window W intersecting |
82f053ab GM |
5994 | rectangle R. R is in window-relative coordinates. Value is |
5995 | non-zero if mouse-face was overwritten. */ | |
dc6f92b8 | 5996 | |
82f053ab | 5997 | static int |
06a2c219 GM |
5998 | expose_line (w, row, r) |
5999 | struct window *w; | |
6000 | struct glyph_row *row; | |
6001 | XRectangle *r; | |
6002 | { | |
6003 | xassert (row->enabled_p); | |
6004 | ||
6005 | if (row->mode_line_p || w->pseudo_window_p) | |
6006 | x_draw_glyphs (w, 0, row, TEXT_AREA, 0, row->used[TEXT_AREA], | |
f0a48a01 | 6007 | DRAW_NORMAL_TEXT, 0); |
06a2c219 GM |
6008 | else |
6009 | { | |
6010 | if (row->used[LEFT_MARGIN_AREA]) | |
6011 | expose_area (w, row, r, LEFT_MARGIN_AREA); | |
6012 | if (row->used[TEXT_AREA]) | |
6013 | expose_area (w, row, r, TEXT_AREA); | |
6014 | if (row->used[RIGHT_MARGIN_AREA]) | |
6015 | expose_area (w, row, r, RIGHT_MARGIN_AREA); | |
3f332ef3 | 6016 | x_draw_row_fringe_bitmaps (w, row); |
06a2c219 | 6017 | } |
82f053ab GM |
6018 | |
6019 | return row->mouse_face_p; | |
06a2c219 | 6020 | } |
dc6f92b8 | 6021 | |
58769bee | 6022 | |
06a2c219 GM |
6023 | /* Return non-zero if W's cursor intersects rectangle R. */ |
6024 | ||
6025 | static int | |
6026 | x_phys_cursor_in_rect_p (w, r) | |
6027 | struct window *w; | |
6028 | XRectangle *r; | |
6029 | { | |
6030 | XRectangle cr, result; | |
6031 | struct glyph *cursor_glyph; | |
6032 | ||
6033 | cursor_glyph = get_phys_cursor_glyph (w); | |
6034 | if (cursor_glyph) | |
6035 | { | |
6036 | cr.x = w->phys_cursor.x; | |
6037 | cr.y = w->phys_cursor.y; | |
6038 | cr.width = cursor_glyph->pixel_width; | |
6039 | cr.height = w->phys_cursor_height; | |
6040 | return x_intersect_rectangles (&cr, r, &result); | |
6041 | } | |
6042 | else | |
6043 | return 0; | |
dc6f92b8 | 6044 | } |
dc6f92b8 | 6045 | |
06a2c219 | 6046 | |
a02f1be0 GM |
6047 | /* Redraw the part of window W intersection rectangle FR. Pixel |
6048 | coordinates in FR are frame-relative. Call this function with | |
82f053ab GM |
6049 | input blocked. Value is non-zero if the exposure overwrites |
6050 | mouse-face. */ | |
dc6f92b8 | 6051 | |
a39202f6 | 6052 | static int |
a02f1be0 | 6053 | expose_window (w, fr) |
06a2c219 | 6054 | struct window *w; |
a02f1be0 | 6055 | XRectangle *fr; |
dc6f92b8 | 6056 | { |
a02f1be0 | 6057 | struct frame *f = XFRAME (w->frame); |
a02f1be0 | 6058 | XRectangle wr, r; |
82f053ab | 6059 | int mouse_face_overwritten_p = 0; |
dc6f92b8 | 6060 | |
80c32bcc GM |
6061 | /* If window is not yet fully initialized, do nothing. This can |
6062 | happen when toolkit scroll bars are used and a window is split. | |
6063 | Reconfiguring the scroll bar will generate an expose for a newly | |
6064 | created window. */ | |
a39202f6 | 6065 | if (w->current_matrix == NULL) |
82f053ab | 6066 | return 0; |
a39202f6 GM |
6067 | |
6068 | /* When we're currently updating the window, display and current | |
6069 | matrix usually don't agree. Arrange for a thorough display | |
6070 | later. */ | |
6071 | if (w == updated_window) | |
6072 | { | |
6073 | SET_FRAME_GARBAGED (f); | |
6074 | return 0; | |
6075 | } | |
80c32bcc | 6076 | |
a39202f6 | 6077 | /* Frame-relative pixel rectangle of W. */ |
a02f1be0 GM |
6078 | wr.x = XFASTINT (w->left) * CANON_X_UNIT (f); |
6079 | wr.y = XFASTINT (w->top) * CANON_Y_UNIT (f); | |
6080 | wr.width = XFASTINT (w->width) * CANON_X_UNIT (f); | |
6081 | wr.height = XFASTINT (w->height) * CANON_Y_UNIT (f); | |
6082 | ||
a39202f6 GM |
6083 | if (x_intersect_rectangles (fr, &wr, &r)) |
6084 | { | |
6085 | int yb = window_text_bottom_y (w); | |
6086 | struct glyph_row *row; | |
6087 | int cursor_cleared_p; | |
a02f1be0 | 6088 | |
a39202f6 GM |
6089 | TRACE ((stderr, "expose_window (%d, %d, %d, %d)\n", |
6090 | r.x, r.y, r.width, r.height)); | |
dc6f92b8 | 6091 | |
a39202f6 GM |
6092 | /* Convert to window coordinates. */ |
6093 | r.x = FRAME_TO_WINDOW_PIXEL_X (w, r.x); | |
6094 | r.y = FRAME_TO_WINDOW_PIXEL_Y (w, r.y); | |
dc6f92b8 | 6095 | |
a39202f6 GM |
6096 | /* Turn off the cursor. */ |
6097 | if (!w->pseudo_window_p | |
6098 | && x_phys_cursor_in_rect_p (w, &r)) | |
6099 | { | |
6100 | x_clear_cursor (w); | |
6101 | cursor_cleared_p = 1; | |
6102 | } | |
6103 | else | |
6104 | cursor_cleared_p = 0; | |
06a2c219 | 6105 | |
a39202f6 GM |
6106 | /* Find the first row intersecting the rectangle R. */ |
6107 | for (row = w->current_matrix->rows; | |
6108 | row->enabled_p; | |
6109 | ++row) | |
6110 | { | |
6111 | int y0 = row->y; | |
6112 | int y1 = MATRIX_ROW_BOTTOM_Y (row); | |
6113 | ||
6114 | if ((y0 >= r.y && y0 < r.y + r.height) | |
6115 | || (y1 > r.y && y1 < r.y + r.height) | |
6116 | || (r.y >= y0 && r.y < y1) | |
6117 | || (r.y + r.height > y0 && r.y + r.height < y1)) | |
82f053ab GM |
6118 | { |
6119 | if (expose_line (w, row, &r)) | |
6120 | mouse_face_overwritten_p = 1; | |
6121 | } | |
6122 | ||
a39202f6 GM |
6123 | if (y1 >= yb) |
6124 | break; | |
6125 | } | |
dc6f92b8 | 6126 | |
a39202f6 GM |
6127 | /* Display the mode line if there is one. */ |
6128 | if (WINDOW_WANTS_MODELINE_P (w) | |
6129 | && (row = MATRIX_MODE_LINE_ROW (w->current_matrix), | |
6130 | row->enabled_p) | |
6131 | && row->y < r.y + r.height) | |
82f053ab GM |
6132 | { |
6133 | if (expose_line (w, row, &r)) | |
6134 | mouse_face_overwritten_p = 1; | |
6135 | } | |
a39202f6 GM |
6136 | |
6137 | if (!w->pseudo_window_p) | |
6138 | { | |
6139 | /* Draw border between windows. */ | |
6140 | x_draw_vertical_border (w); | |
06a2c219 | 6141 | |
a39202f6 GM |
6142 | /* Turn the cursor on again. */ |
6143 | if (cursor_cleared_p) | |
6144 | x_update_window_cursor (w, 1); | |
6145 | } | |
06a2c219 | 6146 | } |
82f053ab GM |
6147 | |
6148 | return mouse_face_overwritten_p; | |
06a2c219 | 6149 | } |
dc6f92b8 | 6150 | |
dc6f92b8 | 6151 | |
06a2c219 GM |
6152 | /* Determine the intersection of two rectangles R1 and R2. Return |
6153 | the intersection in *RESULT. Value is non-zero if RESULT is not | |
6154 | empty. */ | |
6155 | ||
6156 | static int | |
6157 | x_intersect_rectangles (r1, r2, result) | |
6158 | XRectangle *r1, *r2, *result; | |
6159 | { | |
6160 | XRectangle *left, *right; | |
6161 | XRectangle *upper, *lower; | |
6162 | int intersection_p = 0; | |
6163 | ||
6164 | /* Rearrange so that R1 is the left-most rectangle. */ | |
6165 | if (r1->x < r2->x) | |
6166 | left = r1, right = r2; | |
6167 | else | |
6168 | left = r2, right = r1; | |
6169 | ||
6170 | /* X0 of the intersection is right.x0, if this is inside R1, | |
6171 | otherwise there is no intersection. */ | |
6172 | if (right->x <= left->x + left->width) | |
6173 | { | |
6174 | result->x = right->x; | |
6175 | ||
6176 | /* The right end of the intersection is the minimum of the | |
6177 | the right ends of left and right. */ | |
6178 | result->width = (min (left->x + left->width, right->x + right->width) | |
6179 | - result->x); | |
6180 | ||
6181 | /* Same game for Y. */ | |
6182 | if (r1->y < r2->y) | |
6183 | upper = r1, lower = r2; | |
6184 | else | |
6185 | upper = r2, lower = r1; | |
6186 | ||
6187 | /* The upper end of the intersection is lower.y0, if this is inside | |
6188 | of upper. Otherwise, there is no intersection. */ | |
6189 | if (lower->y <= upper->y + upper->height) | |
dc43ef94 | 6190 | { |
06a2c219 GM |
6191 | result->y = lower->y; |
6192 | ||
6193 | /* The lower end of the intersection is the minimum of the lower | |
6194 | ends of upper and lower. */ | |
6195 | result->height = (min (lower->y + lower->height, | |
6196 | upper->y + upper->height) | |
6197 | - result->y); | |
6198 | intersection_p = 1; | |
dc43ef94 | 6199 | } |
dc6f92b8 JB |
6200 | } |
6201 | ||
06a2c219 | 6202 | return intersection_p; |
dc6f92b8 | 6203 | } |
06a2c219 GM |
6204 | |
6205 | ||
6206 | ||
6207 | ||
dc6f92b8 | 6208 | \f |
dc6f92b8 | 6209 | static void |
334208b7 RS |
6210 | frame_highlight (f) |
6211 | struct frame *f; | |
dc6f92b8 | 6212 | { |
b3e1e05c JB |
6213 | /* We used to only do this if Vx_no_window_manager was non-nil, but |
6214 | the ICCCM (section 4.1.6) says that the window's border pixmap | |
6215 | and border pixel are window attributes which are "private to the | |
6216 | client", so we can always change it to whatever we want. */ | |
6217 | BLOCK_INPUT; | |
334208b7 | 6218 | XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 6219 | f->output_data.x->border_pixel); |
b3e1e05c | 6220 | UNBLOCK_INPUT; |
5d46f928 | 6221 | x_update_cursor (f, 1); |
dc6f92b8 JB |
6222 | } |
6223 | ||
6224 | static void | |
334208b7 RS |
6225 | frame_unhighlight (f) |
6226 | struct frame *f; | |
dc6f92b8 | 6227 | { |
b3e1e05c JB |
6228 | /* We used to only do this if Vx_no_window_manager was non-nil, but |
6229 | the ICCCM (section 4.1.6) says that the window's border pixmap | |
6230 | and border pixel are window attributes which are "private to the | |
6231 | client", so we can always change it to whatever we want. */ | |
6232 | BLOCK_INPUT; | |
334208b7 | 6233 | XSetWindowBorderPixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 6234 | f->output_data.x->border_tile); |
b3e1e05c | 6235 | UNBLOCK_INPUT; |
5d46f928 | 6236 | x_update_cursor (f, 1); |
dc6f92b8 | 6237 | } |
dc6f92b8 | 6238 | |
f676886a JB |
6239 | /* The focus has changed. Update the frames as necessary to reflect |
6240 | the new situation. Note that we can't change the selected frame | |
c5acd733 | 6241 | here, because the Lisp code we are interrupting might become confused. |
eb8c3be9 | 6242 | Each event gets marked with the frame in which it occurred, so the |
c5acd733 | 6243 | Lisp code can tell when the switch took place by examining the events. */ |
dc6f92b8 | 6244 | |
6d4238f3 | 6245 | static void |
0f941935 KH |
6246 | x_new_focus_frame (dpyinfo, frame) |
6247 | struct x_display_info *dpyinfo; | |
f676886a | 6248 | struct frame *frame; |
dc6f92b8 | 6249 | { |
0f941935 | 6250 | struct frame *old_focus = dpyinfo->x_focus_frame; |
dc6f92b8 | 6251 | |
0f941935 | 6252 | if (frame != dpyinfo->x_focus_frame) |
dc6f92b8 | 6253 | { |
58769bee | 6254 | /* Set this before calling other routines, so that they see |
f676886a | 6255 | the correct value of x_focus_frame. */ |
0f941935 | 6256 | dpyinfo->x_focus_frame = frame; |
6d4238f3 JB |
6257 | |
6258 | if (old_focus && old_focus->auto_lower) | |
f676886a | 6259 | x_lower_frame (old_focus); |
dc6f92b8 JB |
6260 | |
6261 | #if 0 | |
f676886a | 6262 | selected_frame = frame; |
e0c1aef2 KH |
6263 | XSETFRAME (XWINDOW (selected_frame->selected_window)->frame, |
6264 | selected_frame); | |
f676886a JB |
6265 | Fselect_window (selected_frame->selected_window); |
6266 | choose_minibuf_frame (); | |
c118dd06 | 6267 | #endif /* ! 0 */ |
dc6f92b8 | 6268 | |
0f941935 KH |
6269 | if (dpyinfo->x_focus_frame && dpyinfo->x_focus_frame->auto_raise) |
6270 | pending_autoraise_frame = dpyinfo->x_focus_frame; | |
0134a210 RS |
6271 | else |
6272 | pending_autoraise_frame = 0; | |
6d4238f3 | 6273 | } |
dc6f92b8 | 6274 | |
0f941935 | 6275 | x_frame_rehighlight (dpyinfo); |
6d4238f3 JB |
6276 | } |
6277 | ||
37c2c98b RS |
6278 | /* Handle an event saying the mouse has moved out of an Emacs frame. */ |
6279 | ||
6280 | void | |
0f941935 KH |
6281 | x_mouse_leave (dpyinfo) |
6282 | struct x_display_info *dpyinfo; | |
37c2c98b | 6283 | { |
0f941935 | 6284 | x_new_focus_frame (dpyinfo, dpyinfo->x_focus_event_frame); |
37c2c98b | 6285 | } |
6d4238f3 | 6286 | |
f451eb13 JB |
6287 | /* The focus has changed, or we have redirected a frame's focus to |
6288 | another frame (this happens when a frame uses a surrogate | |
06a2c219 | 6289 | mini-buffer frame). Shift the highlight as appropriate. |
0f941935 KH |
6290 | |
6291 | The FRAME argument doesn't necessarily have anything to do with which | |
06a2c219 | 6292 | frame is being highlighted or un-highlighted; we only use it to find |
0f941935 | 6293 | the appropriate X display info. */ |
06a2c219 | 6294 | |
6d4238f3 | 6295 | static void |
0f941935 KH |
6296 | XTframe_rehighlight (frame) |
6297 | struct frame *frame; | |
6d4238f3 | 6298 | { |
0f941935 KH |
6299 | x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame)); |
6300 | } | |
6d4238f3 | 6301 | |
0f941935 KH |
6302 | static void |
6303 | x_frame_rehighlight (dpyinfo) | |
6304 | struct x_display_info *dpyinfo; | |
6305 | { | |
6306 | struct frame *old_highlight = dpyinfo->x_highlight_frame; | |
6307 | ||
6308 | if (dpyinfo->x_focus_frame) | |
6d4238f3 | 6309 | { |
0f941935 KH |
6310 | dpyinfo->x_highlight_frame |
6311 | = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame))) | |
6312 | ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame)) | |
6313 | : dpyinfo->x_focus_frame); | |
6314 | if (! FRAME_LIVE_P (dpyinfo->x_highlight_frame)) | |
f451eb13 | 6315 | { |
0f941935 KH |
6316 | FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame) = Qnil; |
6317 | dpyinfo->x_highlight_frame = dpyinfo->x_focus_frame; | |
f451eb13 | 6318 | } |
dc6f92b8 | 6319 | } |
6d4238f3 | 6320 | else |
0f941935 | 6321 | dpyinfo->x_highlight_frame = 0; |
dc6f92b8 | 6322 | |
0f941935 | 6323 | if (dpyinfo->x_highlight_frame != old_highlight) |
6d4238f3 JB |
6324 | { |
6325 | if (old_highlight) | |
f676886a | 6326 | frame_unhighlight (old_highlight); |
0f941935 KH |
6327 | if (dpyinfo->x_highlight_frame) |
6328 | frame_highlight (dpyinfo->x_highlight_frame); | |
6d4238f3 | 6329 | } |
dc6f92b8 | 6330 | } |
06a2c219 GM |
6331 | |
6332 | ||
dc6f92b8 | 6333 | \f |
06a2c219 | 6334 | /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */ |
dc6f92b8 | 6335 | |
28430d3c JB |
6336 | /* Initialize mode_switch_bit and modifier_meaning. */ |
6337 | static void | |
334208b7 RS |
6338 | x_find_modifier_meanings (dpyinfo) |
6339 | struct x_display_info *dpyinfo; | |
28430d3c | 6340 | { |
f689eb05 | 6341 | int min_code, max_code; |
28430d3c JB |
6342 | KeySym *syms; |
6343 | int syms_per_code; | |
6344 | XModifierKeymap *mods; | |
6345 | ||
334208b7 RS |
6346 | dpyinfo->meta_mod_mask = 0; |
6347 | dpyinfo->shift_lock_mask = 0; | |
6348 | dpyinfo->alt_mod_mask = 0; | |
6349 | dpyinfo->super_mod_mask = 0; | |
6350 | dpyinfo->hyper_mod_mask = 0; | |
58769bee | 6351 | |
9658a521 | 6352 | #ifdef HAVE_X11R4 |
334208b7 | 6353 | XDisplayKeycodes (dpyinfo->display, &min_code, &max_code); |
9658a521 | 6354 | #else |
4a60f8c5 RS |
6355 | min_code = dpyinfo->display->min_keycode; |
6356 | max_code = dpyinfo->display->max_keycode; | |
9658a521 JB |
6357 | #endif |
6358 | ||
334208b7 | 6359 | syms = XGetKeyboardMapping (dpyinfo->display, |
28430d3c JB |
6360 | min_code, max_code - min_code + 1, |
6361 | &syms_per_code); | |
334208b7 | 6362 | mods = XGetModifierMapping (dpyinfo->display); |
28430d3c | 6363 | |
58769bee | 6364 | /* Scan the modifier table to see which modifier bits the Meta and |
11edeb03 | 6365 | Alt keysyms are on. */ |
28430d3c | 6366 | { |
06a2c219 | 6367 | int row, col; /* The row and column in the modifier table. */ |
28430d3c JB |
6368 | |
6369 | for (row = 3; row < 8; row++) | |
6370 | for (col = 0; col < mods->max_keypermod; col++) | |
6371 | { | |
0299d313 RS |
6372 | KeyCode code |
6373 | = mods->modifiermap[(row * mods->max_keypermod) + col]; | |
28430d3c | 6374 | |
af92970c KH |
6375 | /* Zeroes are used for filler. Skip them. */ |
6376 | if (code == 0) | |
6377 | continue; | |
6378 | ||
28430d3c JB |
6379 | /* Are any of this keycode's keysyms a meta key? */ |
6380 | { | |
6381 | int code_col; | |
6382 | ||
6383 | for (code_col = 0; code_col < syms_per_code; code_col++) | |
6384 | { | |
f689eb05 | 6385 | int sym = syms[((code - min_code) * syms_per_code) + code_col]; |
28430d3c | 6386 | |
f689eb05 | 6387 | switch (sym) |
28430d3c | 6388 | { |
f689eb05 JB |
6389 | case XK_Meta_L: |
6390 | case XK_Meta_R: | |
334208b7 | 6391 | dpyinfo->meta_mod_mask |= (1 << row); |
28430d3c | 6392 | break; |
f689eb05 JB |
6393 | |
6394 | case XK_Alt_L: | |
6395 | case XK_Alt_R: | |
334208b7 | 6396 | dpyinfo->alt_mod_mask |= (1 << row); |
a3c44b14 RS |
6397 | break; |
6398 | ||
6399 | case XK_Hyper_L: | |
6400 | case XK_Hyper_R: | |
334208b7 | 6401 | dpyinfo->hyper_mod_mask |= (1 << row); |
a3c44b14 RS |
6402 | break; |
6403 | ||
6404 | case XK_Super_L: | |
6405 | case XK_Super_R: | |
334208b7 | 6406 | dpyinfo->super_mod_mask |= (1 << row); |
f689eb05 | 6407 | break; |
11edeb03 JB |
6408 | |
6409 | case XK_Shift_Lock: | |
6410 | /* Ignore this if it's not on the lock modifier. */ | |
6411 | if ((1 << row) == LockMask) | |
334208b7 | 6412 | dpyinfo->shift_lock_mask = LockMask; |
11edeb03 | 6413 | break; |
28430d3c JB |
6414 | } |
6415 | } | |
6416 | } | |
6417 | } | |
6418 | } | |
6419 | ||
f689eb05 | 6420 | /* If we couldn't find any meta keys, accept any alt keys as meta keys. */ |
334208b7 | 6421 | if (! dpyinfo->meta_mod_mask) |
a3c44b14 | 6422 | { |
334208b7 RS |
6423 | dpyinfo->meta_mod_mask = dpyinfo->alt_mod_mask; |
6424 | dpyinfo->alt_mod_mask = 0; | |
a3c44b14 | 6425 | } |
f689eb05 | 6426 | |
148c4b70 RS |
6427 | /* If some keys are both alt and meta, |
6428 | make them just meta, not alt. */ | |
334208b7 | 6429 | if (dpyinfo->alt_mod_mask & dpyinfo->meta_mod_mask) |
148c4b70 | 6430 | { |
334208b7 | 6431 | dpyinfo->alt_mod_mask &= ~dpyinfo->meta_mod_mask; |
148c4b70 | 6432 | } |
58769bee | 6433 | |
28430d3c | 6434 | XFree ((char *) syms); |
f689eb05 | 6435 | XFreeModifiermap (mods); |
28430d3c JB |
6436 | } |
6437 | ||
dfeccd2d JB |
6438 | /* Convert between the modifier bits X uses and the modifier bits |
6439 | Emacs uses. */ | |
06a2c219 | 6440 | |
7c5283e4 | 6441 | static unsigned int |
334208b7 RS |
6442 | x_x_to_emacs_modifiers (dpyinfo, state) |
6443 | struct x_display_info *dpyinfo; | |
dc6f92b8 JB |
6444 | unsigned int state; |
6445 | { | |
98659da6 KG |
6446 | EMACS_UINT mod_meta = meta_modifier; |
6447 | EMACS_UINT mod_alt = alt_modifier; | |
6448 | EMACS_UINT mod_hyper = hyper_modifier; | |
6449 | EMACS_UINT mod_super = super_modifier; | |
6450 | Lisp_Object tem; | |
6451 | ||
6452 | tem = Fget (Vx_alt_keysym, Qmodifier_value); | |
6453 | if (! EQ (tem, Qnil)) mod_alt = XUINT (tem); | |
6454 | tem = Fget (Vx_meta_keysym, Qmodifier_value); | |
6455 | if (! EQ (tem, Qnil)) mod_meta = XUINT (tem); | |
6456 | tem = Fget (Vx_hyper_keysym, Qmodifier_value); | |
6457 | if (! EQ (tem, Qnil)) mod_hyper = XUINT (tem); | |
6458 | tem = Fget (Vx_super_keysym, Qmodifier_value); | |
6459 | if (! EQ (tem, Qnil)) mod_super = XUINT (tem); | |
6460 | ||
6461 | ||
334208b7 | 6462 | return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0) |
98659da6 KG |
6463 | | ((state & ControlMask) ? ctrl_modifier : 0) |
6464 | | ((state & dpyinfo->meta_mod_mask) ? mod_meta : 0) | |
6465 | | ((state & dpyinfo->alt_mod_mask) ? mod_alt : 0) | |
6466 | | ((state & dpyinfo->super_mod_mask) ? mod_super : 0) | |
6467 | | ((state & dpyinfo->hyper_mod_mask) ? mod_hyper : 0)); | |
dc6f92b8 JB |
6468 | } |
6469 | ||
dfeccd2d | 6470 | static unsigned int |
334208b7 RS |
6471 | x_emacs_to_x_modifiers (dpyinfo, state) |
6472 | struct x_display_info *dpyinfo; | |
dfeccd2d JB |
6473 | unsigned int state; |
6474 | { | |
98659da6 KG |
6475 | EMACS_UINT mod_meta = meta_modifier; |
6476 | EMACS_UINT mod_alt = alt_modifier; | |
6477 | EMACS_UINT mod_hyper = hyper_modifier; | |
6478 | EMACS_UINT mod_super = super_modifier; | |
6479 | ||
6480 | Lisp_Object tem; | |
6481 | ||
6482 | tem = Fget (Vx_alt_keysym, Qmodifier_value); | |
6483 | if (! EQ (tem, Qnil)) mod_alt = XUINT (tem); | |
6484 | tem = Fget (Vx_meta_keysym, Qmodifier_value); | |
6485 | if (! EQ (tem, Qnil)) mod_meta = XUINT (tem); | |
6486 | tem = Fget (Vx_hyper_keysym, Qmodifier_value); | |
6487 | if (! EQ (tem, Qnil)) mod_hyper = XUINT (tem); | |
6488 | tem = Fget (Vx_super_keysym, Qmodifier_value); | |
6489 | if (! EQ (tem, Qnil)) mod_super = XUINT (tem); | |
6490 | ||
6491 | ||
6492 | return ( ((state & mod_alt) ? dpyinfo->alt_mod_mask : 0) | |
6493 | | ((state & mod_super) ? dpyinfo->super_mod_mask : 0) | |
6494 | | ((state & mod_hyper) ? dpyinfo->hyper_mod_mask : 0) | |
6495 | | ((state & shift_modifier) ? ShiftMask : 0) | |
6496 | | ((state & ctrl_modifier) ? ControlMask : 0) | |
6497 | | ((state & mod_meta) ? dpyinfo->meta_mod_mask : 0)); | |
dfeccd2d | 6498 | } |
d047c4eb KH |
6499 | |
6500 | /* Convert a keysym to its name. */ | |
6501 | ||
6502 | char * | |
6503 | x_get_keysym_name (keysym) | |
6504 | KeySym keysym; | |
6505 | { | |
6506 | char *value; | |
6507 | ||
6508 | BLOCK_INPUT; | |
6509 | value = XKeysymToString (keysym); | |
6510 | UNBLOCK_INPUT; | |
6511 | ||
6512 | return value; | |
6513 | } | |
06a2c219 GM |
6514 | |
6515 | ||
e4571a43 JB |
6516 | \f |
6517 | /* Mouse clicks and mouse movement. Rah. */ | |
e4571a43 | 6518 | |
06a2c219 GM |
6519 | /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph |
6520 | co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the | |
6521 | glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do | |
6522 | not force the value into range. */ | |
69388238 | 6523 | |
c8dba240 | 6524 | void |
69388238 | 6525 | pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip) |
e4571a43 | 6526 | FRAME_PTR f; |
69388238 | 6527 | register int pix_x, pix_y; |
e4571a43 JB |
6528 | register int *x, *y; |
6529 | XRectangle *bounds; | |
69388238 | 6530 | int noclip; |
e4571a43 | 6531 | { |
06a2c219 | 6532 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down |
69388238 RS |
6533 | even for negative values. */ |
6534 | if (pix_x < 0) | |
7556890b | 6535 | pix_x -= FONT_WIDTH ((f)->output_data.x->font) - 1; |
69388238 | 6536 | if (pix_y < 0) |
7556890b | 6537 | pix_y -= (f)->output_data.x->line_height - 1; |
69388238 | 6538 | |
e4571a43 JB |
6539 | pix_x = PIXEL_TO_CHAR_COL (f, pix_x); |
6540 | pix_y = PIXEL_TO_CHAR_ROW (f, pix_y); | |
6541 | ||
6542 | if (bounds) | |
6543 | { | |
7556890b RS |
6544 | bounds->width = FONT_WIDTH (f->output_data.x->font); |
6545 | bounds->height = f->output_data.x->line_height; | |
e4571a43 JB |
6546 | bounds->x = CHAR_TO_PIXEL_COL (f, pix_x); |
6547 | bounds->y = CHAR_TO_PIXEL_ROW (f, pix_y); | |
6548 | } | |
6549 | ||
69388238 RS |
6550 | if (!noclip) |
6551 | { | |
6552 | if (pix_x < 0) | |
6553 | pix_x = 0; | |
3cbd2e0b RS |
6554 | else if (pix_x > FRAME_WINDOW_WIDTH (f)) |
6555 | pix_x = FRAME_WINDOW_WIDTH (f); | |
69388238 RS |
6556 | |
6557 | if (pix_y < 0) | |
6558 | pix_y = 0; | |
6559 | else if (pix_y > f->height) | |
6560 | pix_y = f->height; | |
6561 | } | |
e4571a43 JB |
6562 | |
6563 | *x = pix_x; | |
6564 | *y = pix_y; | |
6565 | } | |
6566 | ||
06a2c219 GM |
6567 | |
6568 | /* Given HPOS/VPOS in the current matrix of W, return corresponding | |
6569 | frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we | |
6570 | can't tell the positions because W's display is not up to date, | |
6571 | return 0. */ | |
6572 | ||
6573 | int | |
6574 | glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y) | |
6575 | struct window *w; | |
6576 | int hpos, vpos; | |
6577 | int *frame_x, *frame_y; | |
2b5c9e71 | 6578 | { |
06a2c219 GM |
6579 | int success_p; |
6580 | ||
6581 | xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w); | |
6582 | xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h); | |
6583 | ||
6584 | if (display_completed) | |
6585 | { | |
6586 | struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos); | |
6587 | struct glyph *glyph = row->glyphs[TEXT_AREA]; | |
6588 | struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]); | |
6589 | ||
6590 | *frame_y = row->y; | |
6591 | *frame_x = row->x; | |
6592 | while (glyph < end) | |
6593 | { | |
6594 | *frame_x += glyph->pixel_width; | |
6595 | ++glyph; | |
6596 | } | |
6597 | ||
6598 | success_p = 1; | |
6599 | } | |
6600 | else | |
6601 | { | |
6602 | *frame_y = *frame_x = 0; | |
6603 | success_p = 0; | |
6604 | } | |
6605 | ||
6606 | *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, *frame_y); | |
6607 | *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, *frame_x); | |
6608 | return success_p; | |
2b5c9e71 RS |
6609 | } |
6610 | ||
06a2c219 | 6611 | |
dc6f92b8 JB |
6612 | /* Prepare a mouse-event in *RESULT for placement in the input queue. |
6613 | ||
6614 | If the event is a button press, then note that we have grabbed | |
f451eb13 | 6615 | the mouse. */ |
dc6f92b8 JB |
6616 | |
6617 | static Lisp_Object | |
f451eb13 | 6618 | construct_mouse_click (result, event, f) |
dc6f92b8 JB |
6619 | struct input_event *result; |
6620 | XButtonEvent *event; | |
f676886a | 6621 | struct frame *f; |
dc6f92b8 | 6622 | { |
f451eb13 | 6623 | /* Make the event type no_event; we'll change that when we decide |
dc6f92b8 | 6624 | otherwise. */ |
f451eb13 | 6625 | result->kind = mouse_click; |
69388238 | 6626 | result->code = event->button - Button1; |
1113d9db | 6627 | result->timestamp = event->time; |
334208b7 RS |
6628 | result->modifiers = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), |
6629 | event->state) | |
f689eb05 | 6630 | | (event->type == ButtonRelease |
58769bee | 6631 | ? up_modifier |
f689eb05 | 6632 | : down_modifier)); |
dc6f92b8 | 6633 | |
06a2c219 GM |
6634 | XSETINT (result->x, event->x); |
6635 | XSETINT (result->y, event->y); | |
6636 | XSETFRAME (result->frame_or_window, f); | |
0f8aabe9 | 6637 | result->arg = Qnil; |
06a2c219 | 6638 | return Qnil; |
dc6f92b8 | 6639 | } |
b849c413 | 6640 | |
69388238 | 6641 | \f |
90e65f07 JB |
6642 | /* Function to report a mouse movement to the mainstream Emacs code. |
6643 | The input handler calls this. | |
6644 | ||
6645 | We have received a mouse movement event, which is given in *event. | |
6646 | If the mouse is over a different glyph than it was last time, tell | |
6647 | the mainstream emacs code by setting mouse_moved. If not, ask for | |
6648 | another motion event, so we can check again the next time it moves. */ | |
b8009dd1 | 6649 | |
06a2c219 GM |
6650 | static XMotionEvent last_mouse_motion_event; |
6651 | static Lisp_Object last_mouse_motion_frame; | |
6652 | ||
90e65f07 | 6653 | static void |
12ba150f | 6654 | note_mouse_movement (frame, event) |
f676886a | 6655 | FRAME_PTR frame; |
90e65f07 | 6656 | XMotionEvent *event; |
90e65f07 | 6657 | { |
e5d77022 | 6658 | last_mouse_movement_time = event->time; |
06a2c219 GM |
6659 | last_mouse_motion_event = *event; |
6660 | XSETFRAME (last_mouse_motion_frame, frame); | |
e5d77022 | 6661 | |
27f338af RS |
6662 | if (event->window != FRAME_X_WINDOW (frame)) |
6663 | { | |
39d8bb4d | 6664 | frame->mouse_moved = 1; |
27f338af | 6665 | last_mouse_scroll_bar = Qnil; |
27f338af | 6666 | note_mouse_highlight (frame, -1, -1); |
27f338af RS |
6667 | } |
6668 | ||
90e65f07 | 6669 | /* Has the mouse moved off the glyph it was on at the last sighting? */ |
27f338af RS |
6670 | else if (event->x < last_mouse_glyph.x |
6671 | || event->x >= last_mouse_glyph.x + last_mouse_glyph.width | |
6672 | || event->y < last_mouse_glyph.y | |
6673 | || event->y >= last_mouse_glyph.y + last_mouse_glyph.height) | |
12ba150f | 6674 | { |
39d8bb4d | 6675 | frame->mouse_moved = 1; |
ab648270 | 6676 | last_mouse_scroll_bar = Qnil; |
b8009dd1 | 6677 | note_mouse_highlight (frame, event->x, event->y); |
90e65f07 JB |
6678 | } |
6679 | } | |
6680 | ||
06a2c219 GM |
6681 | \f |
6682 | /************************************************************************ | |
6683 | Mouse Face | |
6684 | ************************************************************************/ | |
6685 | ||
6686 | /* Find the glyph under window-relative coordinates X/Y in window W. | |
6687 | Consider only glyphs from buffer text, i.e. no glyphs from overlay | |
6688 | strings. Return in *HPOS and *VPOS the row and column number of | |
6689 | the glyph found. Return in *AREA the glyph area containing X. | |
6690 | Value is a pointer to the glyph found or null if X/Y is not on | |
6691 | text, or we can't tell because W's current matrix is not up to | |
6692 | date. */ | |
6693 | ||
6694 | static struct glyph * | |
f9db2310 | 6695 | x_y_to_hpos_vpos (w, x, y, hpos, vpos, area, buffer_only_p) |
06a2c219 GM |
6696 | struct window *w; |
6697 | int x, y; | |
6698 | int *hpos, *vpos, *area; | |
f9db2310 | 6699 | int buffer_only_p; |
06a2c219 GM |
6700 | { |
6701 | struct glyph *glyph, *end; | |
3e71d8f2 | 6702 | struct glyph_row *row = NULL; |
06a2c219 GM |
6703 | int x0, i, left_area_width; |
6704 | ||
6705 | /* Find row containing Y. Give up if some row is not enabled. */ | |
6706 | for (i = 0; i < w->current_matrix->nrows; ++i) | |
6707 | { | |
6708 | row = MATRIX_ROW (w->current_matrix, i); | |
6709 | if (!row->enabled_p) | |
6710 | return NULL; | |
6711 | if (y >= row->y && y < MATRIX_ROW_BOTTOM_Y (row)) | |
6712 | break; | |
6713 | } | |
6714 | ||
6715 | *vpos = i; | |
6716 | *hpos = 0; | |
6717 | ||
6718 | /* Give up if Y is not in the window. */ | |
6719 | if (i == w->current_matrix->nrows) | |
6720 | return NULL; | |
6721 | ||
6722 | /* Get the glyph area containing X. */ | |
6723 | if (w->pseudo_window_p) | |
6724 | { | |
6725 | *area = TEXT_AREA; | |
6726 | x0 = 0; | |
6727 | } | |
6728 | else | |
6729 | { | |
6730 | left_area_width = window_box_width (w, LEFT_MARGIN_AREA); | |
6731 | if (x < left_area_width) | |
6732 | { | |
6733 | *area = LEFT_MARGIN_AREA; | |
6734 | x0 = 0; | |
6735 | } | |
6736 | else if (x < left_area_width + window_box_width (w, TEXT_AREA)) | |
6737 | { | |
6738 | *area = TEXT_AREA; | |
6739 | x0 = row->x + left_area_width; | |
6740 | } | |
6741 | else | |
6742 | { | |
6743 | *area = RIGHT_MARGIN_AREA; | |
6744 | x0 = left_area_width + window_box_width (w, TEXT_AREA); | |
6745 | } | |
6746 | } | |
6747 | ||
6748 | /* Find glyph containing X. */ | |
6749 | glyph = row->glyphs[*area]; | |
6750 | end = glyph + row->used[*area]; | |
6751 | while (glyph < end) | |
6752 | { | |
6753 | if (x < x0 + glyph->pixel_width) | |
6754 | { | |
6755 | if (w->pseudo_window_p) | |
6756 | break; | |
f9db2310 | 6757 | else if (!buffer_only_p || BUFFERP (glyph->object)) |
06a2c219 GM |
6758 | break; |
6759 | } | |
6760 | ||
6761 | x0 += glyph->pixel_width; | |
6762 | ++glyph; | |
6763 | } | |
6764 | ||
6765 | if (glyph == end) | |
6766 | return NULL; | |
6767 | ||
6768 | *hpos = glyph - row->glyphs[*area]; | |
6769 | return glyph; | |
6770 | } | |
6771 | ||
6772 | ||
6773 | /* Convert frame-relative x/y to coordinates relative to window W. | |
6774 | Takes pseudo-windows into account. */ | |
6775 | ||
6776 | static void | |
6777 | frame_to_window_pixel_xy (w, x, y) | |
6778 | struct window *w; | |
6779 | int *x, *y; | |
6780 | { | |
6781 | if (w->pseudo_window_p) | |
6782 | { | |
6783 | /* A pseudo-window is always full-width, and starts at the | |
6784 | left edge of the frame, plus a frame border. */ | |
6785 | struct frame *f = XFRAME (w->frame); | |
6786 | *x -= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f); | |
6787 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6788 | } | |
6789 | else | |
6790 | { | |
6791 | *x = FRAME_TO_WINDOW_PIXEL_X (w, *x); | |
6792 | *y = FRAME_TO_WINDOW_PIXEL_Y (w, *y); | |
6793 | } | |
6794 | } | |
6795 | ||
6796 | ||
b436feb6 GM |
6797 | /* Take proper action when mouse has moved to the mode or header line |
6798 | or marginal area of window W, x-position X and y-position Y. Area | |
6799 | is 1, 3, 6 or 7 for the mode line, header line, left and right | |
6800 | marginal area respectively. X is relative to the start of the text | |
6801 | display area of W, so the width of bitmap areas and scroll bars | |
6802 | must be subtracted to get a position relative to the start of the | |
6803 | mode line. */ | |
6804 | ||
06a2c219 | 6805 | static void |
b436feb6 | 6806 | note_mode_line_or_margin_highlight (w, x, y, portion) |
06a2c219 | 6807 | struct window *w; |
b436feb6 | 6808 | int x, y, portion; |
06a2c219 GM |
6809 | { |
6810 | struct frame *f = XFRAME (w->frame); | |
6811 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
6812 | Cursor cursor = dpyinfo->vertical_scroll_bar_cursor; | |
2a793c0c | 6813 | int charpos; |
b436feb6 | 6814 | Lisp_Object string, help, map, pos; |
06a2c219 | 6815 | |
b436feb6 GM |
6816 | if (portion == 1 || portion == 3) |
6817 | string = mode_line_string (w, x, y, portion == 1, &charpos); | |
6818 | else | |
6819 | string = marginal_area_string (w, x, y, portion, &charpos); | |
e371a781 | 6820 | |
b436feb6 | 6821 | if (STRINGP (string)) |
06a2c219 | 6822 | { |
b436feb6 | 6823 | pos = make_number (charpos); |
e371a781 | 6824 | |
b436feb6 GM |
6825 | /* If we're on a string with `help-echo' text property, arrange |
6826 | for the help to be displayed. This is done by setting the | |
6827 | global variable help_echo to the help string. */ | |
6828 | help = Fget_text_property (pos, Qhelp_echo, string); | |
6829 | if (!NILP (help)) | |
06a2c219 | 6830 | { |
b436feb6 GM |
6831 | help_echo = help; |
6832 | XSETWINDOW (help_echo_window, w); | |
6833 | help_echo_object = string; | |
6834 | help_echo_pos = charpos; | |
06a2c219 GM |
6835 | } |
6836 | ||
b436feb6 GM |
6837 | /* Change the mouse pointer according to what is under X/Y. */ |
6838 | map = Fget_text_property (pos, Qlocal_map, string); | |
6839 | if (!KEYMAPP (map)) | |
6840 | map = Fget_text_property (pos, Qkeymap, string); | |
6841 | if (KEYMAPP (map)) | |
6842 | cursor = f->output_data.x->nontext_cursor; | |
06a2c219 | 6843 | } |
b436feb6 | 6844 | |
06a2c219 GM |
6845 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), cursor); |
6846 | } | |
6847 | ||
6848 | ||
6849 | /* Take proper action when the mouse has moved to position X, Y on | |
6850 | frame F as regards highlighting characters that have mouse-face | |
6851 | properties. Also de-highlighting chars where the mouse was before. | |
27f338af | 6852 | X and Y can be negative or out of range. */ |
b8009dd1 RS |
6853 | |
6854 | static void | |
6855 | note_mouse_highlight (f, x, y) | |
06a2c219 | 6856 | struct frame *f; |
c32cdd9a | 6857 | int x, y; |
b8009dd1 | 6858 | { |
06a2c219 GM |
6859 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
6860 | int portion; | |
b8009dd1 RS |
6861 | Lisp_Object window; |
6862 | struct window *w; | |
0d487c52 GM |
6863 | Cursor cursor = None; |
6864 | struct buffer *b; | |
b8009dd1 | 6865 | |
06a2c219 GM |
6866 | /* When a menu is active, don't highlight because this looks odd. */ |
6867 | #ifdef USE_X_TOOLKIT | |
6868 | if (popup_activated ()) | |
6869 | return; | |
6870 | #endif | |
6871 | ||
66301061 | 6872 | if (NILP (Vmouse_highlight) |
04fff9c0 | 6873 | || !f->glyphs_initialized_p) |
bf1c0ba1 RS |
6874 | return; |
6875 | ||
06a2c219 GM |
6876 | dpyinfo->mouse_face_mouse_x = x; |
6877 | dpyinfo->mouse_face_mouse_y = y; | |
6878 | dpyinfo->mouse_face_mouse_frame = f; | |
b8009dd1 | 6879 | |
06a2c219 | 6880 | if (dpyinfo->mouse_face_defer) |
b8009dd1 RS |
6881 | return; |
6882 | ||
514e4681 RS |
6883 | if (gc_in_progress) |
6884 | { | |
06a2c219 | 6885 | dpyinfo->mouse_face_deferred_gc = 1; |
514e4681 RS |
6886 | return; |
6887 | } | |
6888 | ||
b8009dd1 | 6889 | /* Which window is that in? */ |
06a2c219 | 6890 | window = window_from_coordinates (f, x, y, &portion, 1); |
b8009dd1 RS |
6891 | |
6892 | /* If we were displaying active text in another window, clear that. */ | |
06a2c219 GM |
6893 | if (! EQ (window, dpyinfo->mouse_face_window)) |
6894 | clear_mouse_face (dpyinfo); | |
6895 | ||
6896 | /* Not on a window -> return. */ | |
6897 | if (!WINDOWP (window)) | |
6898 | return; | |
6899 | ||
6900 | /* Convert to window-relative pixel coordinates. */ | |
6901 | w = XWINDOW (window); | |
6902 | frame_to_window_pixel_xy (w, &x, &y); | |
6903 | ||
9ea173e8 | 6904 | /* Handle tool-bar window differently since it doesn't display a |
06a2c219 | 6905 | buffer. */ |
9ea173e8 | 6906 | if (EQ (window, f->tool_bar_window)) |
06a2c219 | 6907 | { |
9ea173e8 | 6908 | note_tool_bar_highlight (f, x, y); |
06a2c219 GM |
6909 | return; |
6910 | } | |
6911 | ||
b436feb6 GM |
6912 | /* Mouse is on the mode, header line or margin? */ |
6913 | if (portion == 1 || portion == 3 || portion == 6 || portion == 7) | |
06a2c219 | 6914 | { |
b436feb6 | 6915 | note_mode_line_or_margin_highlight (w, x, y, portion); |
06a2c219 GM |
6916 | return; |
6917 | } | |
0d487c52 GM |
6918 | |
6919 | if (portion == 2) | |
6920 | cursor = f->output_data.x->horizontal_drag_cursor; | |
06a2c219 | 6921 | else |
0d487c52 | 6922 | cursor = f->output_data.x->text_cursor; |
b8009dd1 | 6923 | |
0cdd0c9f RS |
6924 | /* Are we in a window whose display is up to date? |
6925 | And verify the buffer's text has not changed. */ | |
0d487c52 | 6926 | b = XBUFFER (w->buffer); |
06a2c219 GM |
6927 | if (/* Within text portion of the window. */ |
6928 | portion == 0 | |
0cdd0c9f | 6929 | && EQ (w->window_end_valid, w->buffer) |
0d487c52 GM |
6930 | && XFASTINT (w->last_modified) == BUF_MODIFF (b) |
6931 | && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b)) | |
b8009dd1 | 6932 | { |
06a2c219 GM |
6933 | int hpos, vpos, pos, i, area; |
6934 | struct glyph *glyph; | |
f9db2310 | 6935 | Lisp_Object object; |
0d487c52 GM |
6936 | Lisp_Object mouse_face = Qnil, overlay = Qnil, position; |
6937 | Lisp_Object *overlay_vec = NULL; | |
6938 | int len, noverlays; | |
6939 | struct buffer *obuf; | |
6940 | int obegv, ozv, same_region; | |
b8009dd1 | 6941 | |
06a2c219 | 6942 | /* Find the glyph under X/Y. */ |
f9db2310 | 6943 | glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, &area, 0); |
06a2c219 GM |
6944 | |
6945 | /* Clear mouse face if X/Y not over text. */ | |
6946 | if (glyph == NULL | |
6947 | || area != TEXT_AREA | |
6948 | || !MATRIX_ROW (w->current_matrix, vpos)->displays_text_p) | |
b8009dd1 | 6949 | { |
fa262c07 GM |
6950 | if (clear_mouse_face (dpyinfo)) |
6951 | cursor = None; | |
6952 | goto set_cursor; | |
06a2c219 GM |
6953 | } |
6954 | ||
6955 | pos = glyph->charpos; | |
f9db2310 GM |
6956 | object = glyph->object; |
6957 | if (!STRINGP (object) && !BUFFERP (object)) | |
fa262c07 | 6958 | goto set_cursor; |
06a2c219 | 6959 | |
0d487c52 GM |
6960 | /* If we get an out-of-range value, return now; avoid an error. */ |
6961 | if (BUFFERP (object) && pos > BUF_Z (b)) | |
fa262c07 | 6962 | goto set_cursor; |
06a2c219 | 6963 | |
0d487c52 GM |
6964 | /* Make the window's buffer temporarily current for |
6965 | overlays_at and compute_char_face. */ | |
6966 | obuf = current_buffer; | |
6967 | current_buffer = b; | |
6968 | obegv = BEGV; | |
6969 | ozv = ZV; | |
6970 | BEGV = BEG; | |
6971 | ZV = Z; | |
06a2c219 | 6972 | |
0d487c52 GM |
6973 | /* Is this char mouse-active or does it have help-echo? */ |
6974 | position = make_number (pos); | |
f9db2310 | 6975 | |
0d487c52 GM |
6976 | if (BUFFERP (object)) |
6977 | { | |
6978 | /* Put all the overlays we want in a vector in overlay_vec. | |
6979 | Store the length in len. If there are more than 10, make | |
6980 | enough space for all, and try again. */ | |
6981 | len = 10; | |
6982 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
6983 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL, 0); | |
6984 | if (noverlays > len) | |
6985 | { | |
6986 | len = noverlays; | |
6987 | overlay_vec = (Lisp_Object *) alloca (len * sizeof (Lisp_Object)); | |
6988 | noverlays = overlays_at (pos, 0, &overlay_vec, &len, NULL, NULL,0); | |
6989 | } | |
f8349001 | 6990 | |
0d487c52 GM |
6991 | /* Sort overlays into increasing priority order. */ |
6992 | noverlays = sort_overlays (overlay_vec, noverlays, w); | |
6993 | } | |
6994 | else | |
6995 | noverlays = 0; | |
6996 | ||
6997 | same_region = (EQ (window, dpyinfo->mouse_face_window) | |
6998 | && vpos >= dpyinfo->mouse_face_beg_row | |
6999 | && vpos <= dpyinfo->mouse_face_end_row | |
7000 | && (vpos > dpyinfo->mouse_face_beg_row | |
7001 | || hpos >= dpyinfo->mouse_face_beg_col) | |
7002 | && (vpos < dpyinfo->mouse_face_end_row | |
7003 | || hpos < dpyinfo->mouse_face_end_col | |
7004 | || dpyinfo->mouse_face_past_end)); | |
7005 | ||
7006 | if (same_region) | |
7007 | cursor = None; | |
7008 | ||
7009 | /* Check mouse-face highlighting. */ | |
7010 | if (! same_region | |
7011 | /* If there exists an overlay with mouse-face overlapping | |
7012 | the one we are currently highlighting, we have to | |
7013 | check if we enter the overlapping overlay, and then | |
7014 | highlight only that. */ | |
7015 | || (OVERLAYP (dpyinfo->mouse_face_overlay) | |
7016 | && mouse_face_overlay_overlaps (dpyinfo->mouse_face_overlay))) | |
7017 | { | |
0d487c52 GM |
7018 | /* Find the highest priority overlay that has a mouse-face |
7019 | property. */ | |
7020 | overlay = Qnil; | |
7021 | for (i = noverlays - 1; i >= 0 && NILP (overlay); --i) | |
7022 | { | |
7023 | mouse_face = Foverlay_get (overlay_vec[i], Qmouse_face); | |
7024 | if (!NILP (mouse_face)) | |
7025 | overlay = overlay_vec[i]; | |
7026 | } | |
8bd189fb GM |
7027 | |
7028 | /* If we're actually highlighting the same overlay as | |
7029 | before, there's no need to do that again. */ | |
7030 | if (!NILP (overlay) | |
7031 | && EQ (overlay, dpyinfo->mouse_face_overlay)) | |
7032 | goto check_help_echo; | |
f9db2310 | 7033 | |
8bd189fb GM |
7034 | dpyinfo->mouse_face_overlay = overlay; |
7035 | ||
7036 | /* Clear the display of the old active region, if any. */ | |
7037 | if (clear_mouse_face (dpyinfo)) | |
7038 | cursor = None; | |
7039 | ||
0d487c52 GM |
7040 | /* If no overlay applies, get a text property. */ |
7041 | if (NILP (overlay)) | |
7042 | mouse_face = Fget_text_property (position, Qmouse_face, object); | |
06a2c219 | 7043 | |
0d487c52 GM |
7044 | /* Handle the overlay case. */ |
7045 | if (!NILP (overlay)) | |
7046 | { | |
7047 | /* Find the range of text around this char that | |
7048 | should be active. */ | |
7049 | Lisp_Object before, after; | |
7050 | int ignore; | |
7051 | ||
7052 | before = Foverlay_start (overlay); | |
7053 | after = Foverlay_end (overlay); | |
7054 | /* Record this as the current active region. */ | |
7055 | fast_find_position (w, XFASTINT (before), | |
7056 | &dpyinfo->mouse_face_beg_col, | |
7057 | &dpyinfo->mouse_face_beg_row, | |
7058 | &dpyinfo->mouse_face_beg_x, | |
7e376260 GM |
7059 | &dpyinfo->mouse_face_beg_y, Qnil); |
7060 | ||
0d487c52 GM |
7061 | dpyinfo->mouse_face_past_end |
7062 | = !fast_find_position (w, XFASTINT (after), | |
7063 | &dpyinfo->mouse_face_end_col, | |
7064 | &dpyinfo->mouse_face_end_row, | |
7065 | &dpyinfo->mouse_face_end_x, | |
7e376260 | 7066 | &dpyinfo->mouse_face_end_y, Qnil); |
0d487c52 GM |
7067 | dpyinfo->mouse_face_window = window; |
7068 | dpyinfo->mouse_face_face_id | |
7069 | = face_at_buffer_position (w, pos, 0, 0, | |
7070 | &ignore, pos + 1, 1); | |
7071 | ||
7072 | /* Display it as active. */ | |
7073 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
58e5af83 | 7074 | cursor = None; |
0d487c52 GM |
7075 | } |
7076 | /* Handle the text property case. */ | |
7077 | else if (!NILP (mouse_face) && BUFFERP (object)) | |
7078 | { | |
7079 | /* Find the range of text around this char that | |
7080 | should be active. */ | |
7081 | Lisp_Object before, after, beginning, end; | |
7082 | int ignore; | |
7083 | ||
7084 | beginning = Fmarker_position (w->start); | |
7085 | end = make_number (BUF_Z (XBUFFER (object)) | |
7086 | - XFASTINT (w->window_end_pos)); | |
7087 | before | |
7088 | = Fprevious_single_property_change (make_number (pos + 1), | |
7089 | Qmouse_face, | |
7090 | object, beginning); | |
7091 | after | |
7092 | = Fnext_single_property_change (position, Qmouse_face, | |
7093 | object, end); | |
7094 | ||
7095 | /* Record this as the current active region. */ | |
7096 | fast_find_position (w, XFASTINT (before), | |
7097 | &dpyinfo->mouse_face_beg_col, | |
7098 | &dpyinfo->mouse_face_beg_row, | |
7099 | &dpyinfo->mouse_face_beg_x, | |
7e376260 | 7100 | &dpyinfo->mouse_face_beg_y, Qnil); |
0d487c52 GM |
7101 | dpyinfo->mouse_face_past_end |
7102 | = !fast_find_position (w, XFASTINT (after), | |
7103 | &dpyinfo->mouse_face_end_col, | |
7104 | &dpyinfo->mouse_face_end_row, | |
7105 | &dpyinfo->mouse_face_end_x, | |
7e376260 | 7106 | &dpyinfo->mouse_face_end_y, Qnil); |
0d487c52 GM |
7107 | dpyinfo->mouse_face_window = window; |
7108 | ||
7109 | if (BUFFERP (object)) | |
06a2c219 GM |
7110 | dpyinfo->mouse_face_face_id |
7111 | = face_at_buffer_position (w, pos, 0, 0, | |
7112 | &ignore, pos + 1, 1); | |
7113 | ||
0d487c52 GM |
7114 | /* Display it as active. */ |
7115 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
58e5af83 | 7116 | cursor = None; |
0d487c52 GM |
7117 | } |
7118 | else if (!NILP (mouse_face) && STRINGP (object)) | |
7119 | { | |
7120 | Lisp_Object b, e; | |
7121 | int ignore; | |
f9db2310 | 7122 | |
0d487c52 GM |
7123 | b = Fprevious_single_property_change (make_number (pos + 1), |
7124 | Qmouse_face, | |
7125 | object, Qnil); | |
7126 | e = Fnext_single_property_change (position, Qmouse_face, | |
7127 | object, Qnil); | |
7128 | if (NILP (b)) | |
7129 | b = make_number (0); | |
7130 | if (NILP (e)) | |
7131 | e = make_number (XSTRING (object)->size - 1); | |
7132 | fast_find_string_pos (w, XINT (b), object, | |
06a2c219 GM |
7133 | &dpyinfo->mouse_face_beg_col, |
7134 | &dpyinfo->mouse_face_beg_row, | |
7135 | &dpyinfo->mouse_face_beg_x, | |
0d487c52 GM |
7136 | &dpyinfo->mouse_face_beg_y, 0); |
7137 | fast_find_string_pos (w, XINT (e), object, | |
7138 | &dpyinfo->mouse_face_end_col, | |
7139 | &dpyinfo->mouse_face_end_row, | |
7140 | &dpyinfo->mouse_face_end_x, | |
7141 | &dpyinfo->mouse_face_end_y, 1); | |
7142 | dpyinfo->mouse_face_past_end = 0; | |
7143 | dpyinfo->mouse_face_window = window; | |
7144 | dpyinfo->mouse_face_face_id | |
7145 | = face_at_string_position (w, object, pos, 0, 0, 0, &ignore, | |
7146 | glyph->face_id, 1); | |
7147 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
58e5af83 | 7148 | cursor = None; |
0d487c52 | 7149 | } |
7e376260 GM |
7150 | else if (STRINGP (object) && NILP (mouse_face)) |
7151 | { | |
7152 | /* A string which doesn't have mouse-face, but | |
7153 | the text ``under'' it might have. */ | |
7154 | struct glyph_row *r = MATRIX_ROW (w->current_matrix, vpos); | |
7155 | int start = MATRIX_ROW_START_CHARPOS (r); | |
7156 | ||
7157 | pos = string_buffer_position (w, object, start); | |
7158 | if (pos > 0) | |
7159 | mouse_face = get_char_property_and_overlay (make_number (pos), | |
7160 | Qmouse_face, | |
7161 | w->buffer, | |
7162 | &overlay); | |
7163 | if (!NILP (mouse_face) && !NILP (overlay)) | |
7164 | { | |
7165 | Lisp_Object before = Foverlay_start (overlay); | |
7166 | Lisp_Object after = Foverlay_end (overlay); | |
91c153e2 | 7167 | int ignore; |
7e376260 GM |
7168 | |
7169 | /* Note that we might not be able to find position | |
7170 | BEFORE in the glyph matrix if the overlay is | |
7171 | entirely covered by a `display' property. In | |
7172 | this case, we overshoot. So let's stop in | |
7173 | the glyph matrix before glyphs for OBJECT. */ | |
7174 | fast_find_position (w, XFASTINT (before), | |
7175 | &dpyinfo->mouse_face_beg_col, | |
7176 | &dpyinfo->mouse_face_beg_row, | |
7177 | &dpyinfo->mouse_face_beg_x, | |
7178 | &dpyinfo->mouse_face_beg_y, | |
7179 | object); | |
7180 | ||
7181 | dpyinfo->mouse_face_past_end | |
7182 | = !fast_find_position (w, XFASTINT (after), | |
7183 | &dpyinfo->mouse_face_end_col, | |
7184 | &dpyinfo->mouse_face_end_row, | |
7185 | &dpyinfo->mouse_face_end_x, | |
7186 | &dpyinfo->mouse_face_end_y, | |
7187 | Qnil); | |
7188 | dpyinfo->mouse_face_window = window; | |
7189 | dpyinfo->mouse_face_face_id | |
7190 | = face_at_buffer_position (w, pos, 0, 0, | |
7191 | &ignore, pos + 1, 1); | |
7192 | ||
7193 | /* Display it as active. */ | |
7194 | show_mouse_face (dpyinfo, DRAW_MOUSE_FACE); | |
7195 | cursor = None; | |
7196 | } | |
7197 | } | |
0d487c52 | 7198 | } |
06a2c219 | 7199 | |
8bd189fb GM |
7200 | check_help_echo: |
7201 | ||
0d487c52 GM |
7202 | /* Look for a `help-echo' property. */ |
7203 | { | |
7204 | Lisp_Object help, overlay; | |
06a2c219 | 7205 | |
0d487c52 GM |
7206 | /* Check overlays first. */ |
7207 | help = overlay = Qnil; | |
7208 | for (i = noverlays - 1; i >= 0 && NILP (help); --i) | |
7209 | { | |
7210 | overlay = overlay_vec[i]; | |
7211 | help = Foverlay_get (overlay, Qhelp_echo); | |
7212 | } | |
be010514 | 7213 | |
0d487c52 GM |
7214 | if (!NILP (help)) |
7215 | { | |
7216 | help_echo = help; | |
7217 | help_echo_window = window; | |
7218 | help_echo_object = overlay; | |
7219 | help_echo_pos = pos; | |
7220 | } | |
7221 | else | |
7222 | { | |
7223 | Lisp_Object object = glyph->object; | |
7224 | int charpos = glyph->charpos; | |
7177d86b | 7225 | |
0d487c52 GM |
7226 | /* Try text properties. */ |
7227 | if (STRINGP (object) | |
7228 | && charpos >= 0 | |
7229 | && charpos < XSTRING (object)->size) | |
7230 | { | |
7231 | help = Fget_text_property (make_number (charpos), | |
7232 | Qhelp_echo, object); | |
7233 | if (NILP (help)) | |
7234 | { | |
7235 | /* If the string itself doesn't specify a help-echo, | |
7236 | see if the buffer text ``under'' it does. */ | |
7237 | struct glyph_row *r | |
7238 | = MATRIX_ROW (w->current_matrix, vpos); | |
7239 | int start = MATRIX_ROW_START_CHARPOS (r); | |
7240 | int pos = string_buffer_position (w, object, start); | |
7241 | if (pos > 0) | |
7242 | { | |
7e376260 | 7243 | help = Fget_char_property (make_number (pos), |
0d487c52 GM |
7244 | Qhelp_echo, w->buffer); |
7245 | if (!NILP (help)) | |
7246 | { | |
7247 | charpos = pos; | |
7248 | object = w->buffer; | |
7249 | } | |
7250 | } | |
7251 | } | |
7252 | } | |
7253 | else if (BUFFERP (object) | |
7254 | && charpos >= BEGV | |
7255 | && charpos < ZV) | |
7256 | help = Fget_text_property (make_number (charpos), Qhelp_echo, | |
7257 | object); | |
06a2c219 | 7258 | |
0d487c52 GM |
7259 | if (!NILP (help)) |
7260 | { | |
7261 | help_echo = help; | |
7262 | help_echo_window = window; | |
7263 | help_echo_object = object; | |
7264 | help_echo_pos = charpos; | |
7265 | } | |
7266 | } | |
06a2c219 | 7267 | } |
0d487c52 GM |
7268 | |
7269 | BEGV = obegv; | |
7270 | ZV = ozv; | |
7271 | current_buffer = obuf; | |
06a2c219 | 7272 | } |
0d487c52 | 7273 | |
fa262c07 GM |
7274 | set_cursor: |
7275 | ||
0d487c52 GM |
7276 | if (cursor != None) |
7277 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), cursor); | |
06a2c219 GM |
7278 | } |
7279 | ||
7280 | static void | |
7281 | redo_mouse_highlight () | |
7282 | { | |
7283 | if (!NILP (last_mouse_motion_frame) | |
7284 | && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame))) | |
7285 | note_mouse_highlight (XFRAME (last_mouse_motion_frame), | |
7286 | last_mouse_motion_event.x, | |
7287 | last_mouse_motion_event.y); | |
7288 | } | |
7289 | ||
7290 | ||
7291 | \f | |
7292 | /*********************************************************************** | |
9ea173e8 | 7293 | Tool-bars |
06a2c219 GM |
7294 | ***********************************************************************/ |
7295 | ||
9ea173e8 GM |
7296 | static int x_tool_bar_item P_ ((struct frame *, int, int, |
7297 | struct glyph **, int *, int *, int *)); | |
06a2c219 | 7298 | |
9ea173e8 | 7299 | /* Tool-bar item index of the item on which a mouse button was pressed |
06a2c219 GM |
7300 | or -1. */ |
7301 | ||
9ea173e8 | 7302 | static int last_tool_bar_item; |
06a2c219 GM |
7303 | |
7304 | ||
9ea173e8 GM |
7305 | /* Get information about the tool-bar item at position X/Y on frame F. |
7306 | Return in *GLYPH a pointer to the glyph of the tool-bar item in | |
7307 | the current matrix of the tool-bar window of F, or NULL if not | |
7308 | on a tool-bar item. Return in *PROP_IDX the index of the tool-bar | |
8daf1204 | 7309 | item in F->tool_bar_items. Value is |
06a2c219 | 7310 | |
9ea173e8 | 7311 | -1 if X/Y is not on a tool-bar item |
06a2c219 GM |
7312 | 0 if X/Y is on the same item that was highlighted before. |
7313 | 1 otherwise. */ | |
7314 | ||
7315 | static int | |
9ea173e8 | 7316 | x_tool_bar_item (f, x, y, glyph, hpos, vpos, prop_idx) |
06a2c219 GM |
7317 | struct frame *f; |
7318 | int x, y; | |
7319 | struct glyph **glyph; | |
7320 | int *hpos, *vpos, *prop_idx; | |
7321 | { | |
7322 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
9ea173e8 | 7323 | struct window *w = XWINDOW (f->tool_bar_window); |
06a2c219 GM |
7324 | int area; |
7325 | ||
7326 | /* Find the glyph under X/Y. */ | |
f9db2310 | 7327 | *glyph = x_y_to_hpos_vpos (w, x, y, hpos, vpos, &area, 0); |
06a2c219 GM |
7328 | if (*glyph == NULL) |
7329 | return -1; | |
7330 | ||
9ea173e8 | 7331 | /* Get the start of this tool-bar item's properties in |
8daf1204 | 7332 | f->tool_bar_items. */ |
9ea173e8 | 7333 | if (!tool_bar_item_info (f, *glyph, prop_idx)) |
06a2c219 GM |
7334 | return -1; |
7335 | ||
7336 | /* Is mouse on the highlighted item? */ | |
9ea173e8 | 7337 | if (EQ (f->tool_bar_window, dpyinfo->mouse_face_window) |
06a2c219 GM |
7338 | && *vpos >= dpyinfo->mouse_face_beg_row |
7339 | && *vpos <= dpyinfo->mouse_face_end_row | |
7340 | && (*vpos > dpyinfo->mouse_face_beg_row | |
7341 | || *hpos >= dpyinfo->mouse_face_beg_col) | |
7342 | && (*vpos < dpyinfo->mouse_face_end_row | |
7343 | || *hpos < dpyinfo->mouse_face_end_col | |
7344 | || dpyinfo->mouse_face_past_end)) | |
7345 | return 0; | |
7346 | ||
7347 | return 1; | |
7348 | } | |
7349 | ||
7350 | ||
9ea173e8 | 7351 | /* Handle mouse button event on the tool-bar of frame F, at |
6c4a22e6 | 7352 | frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress |
06a2c219 GM |
7353 | or ButtonRelase. */ |
7354 | ||
7355 | static void | |
9ea173e8 | 7356 | x_handle_tool_bar_click (f, button_event) |
06a2c219 GM |
7357 | struct frame *f; |
7358 | XButtonEvent *button_event; | |
7359 | { | |
7360 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
9ea173e8 | 7361 | struct window *w = XWINDOW (f->tool_bar_window); |
06a2c219 GM |
7362 | int hpos, vpos, prop_idx; |
7363 | struct glyph *glyph; | |
7364 | Lisp_Object enabled_p; | |
7365 | int x = button_event->x; | |
7366 | int y = button_event->y; | |
7367 | ||
9ea173e8 | 7368 | /* If not on the highlighted tool-bar item, return. */ |
06a2c219 | 7369 | frame_to_window_pixel_xy (w, &x, &y); |
9ea173e8 | 7370 | if (x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx) != 0) |
06a2c219 GM |
7371 | return; |
7372 | ||
7373 | /* If item is disabled, do nothing. */ | |
8daf1204 | 7374 | enabled_p = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_ENABLED_P); |
06a2c219 GM |
7375 | if (NILP (enabled_p)) |
7376 | return; | |
7377 | ||
7378 | if (button_event->type == ButtonPress) | |
7379 | { | |
7380 | /* Show item in pressed state. */ | |
7381 | show_mouse_face (dpyinfo, DRAW_IMAGE_SUNKEN); | |
7382 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_SUNKEN; | |
9ea173e8 | 7383 | last_tool_bar_item = prop_idx; |
06a2c219 GM |
7384 | } |
7385 | else | |
7386 | { | |
7387 | Lisp_Object key, frame; | |
7388 | struct input_event event; | |
7389 | ||
7390 | /* Show item in released state. */ | |
7391 | show_mouse_face (dpyinfo, DRAW_IMAGE_RAISED); | |
7392 | dpyinfo->mouse_face_image_state = DRAW_IMAGE_RAISED; | |
7393 | ||
8daf1204 | 7394 | key = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_KEY); |
06a2c219 GM |
7395 | |
7396 | XSETFRAME (frame, f); | |
9ea173e8 | 7397 | event.kind = TOOL_BAR_EVENT; |
0f1a9b23 GM |
7398 | event.frame_or_window = frame; |
7399 | event.arg = frame; | |
06a2c219 GM |
7400 | kbd_buffer_store_event (&event); |
7401 | ||
9ea173e8 | 7402 | event.kind = TOOL_BAR_EVENT; |
0f1a9b23 GM |
7403 | event.frame_or_window = frame; |
7404 | event.arg = key; | |
06a2c219 GM |
7405 | event.modifiers = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), |
7406 | button_event->state); | |
7407 | kbd_buffer_store_event (&event); | |
9ea173e8 | 7408 | last_tool_bar_item = -1; |
06a2c219 GM |
7409 | } |
7410 | } | |
7411 | ||
7412 | ||
9ea173e8 GM |
7413 | /* Possibly highlight a tool-bar item on frame F when mouse moves to |
7414 | tool-bar window-relative coordinates X/Y. Called from | |
06a2c219 GM |
7415 | note_mouse_highlight. */ |
7416 | ||
7417 | static void | |
9ea173e8 | 7418 | note_tool_bar_highlight (f, x, y) |
06a2c219 GM |
7419 | struct frame *f; |
7420 | int x, y; | |
7421 | { | |
9ea173e8 | 7422 | Lisp_Object window = f->tool_bar_window; |
06a2c219 GM |
7423 | struct window *w = XWINDOW (window); |
7424 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
7425 | int hpos, vpos; | |
7426 | struct glyph *glyph; | |
7427 | struct glyph_row *row; | |
5c187dee | 7428 | int i; |
06a2c219 GM |
7429 | Lisp_Object enabled_p; |
7430 | int prop_idx; | |
140330de | 7431 | enum draw_glyphs_face draw; |
5c187dee | 7432 | int mouse_down_p, rc; |
06a2c219 GM |
7433 | |
7434 | /* Function note_mouse_highlight is called with negative x(y | |
7435 | values when mouse moves outside of the frame. */ | |
7436 | if (x <= 0 || y <= 0) | |
7437 | { | |
7438 | clear_mouse_face (dpyinfo); | |
7439 | return; | |
7440 | } | |
7441 | ||
9ea173e8 | 7442 | rc = x_tool_bar_item (f, x, y, &glyph, &hpos, &vpos, &prop_idx); |
06a2c219 GM |
7443 | if (rc < 0) |
7444 | { | |
9ea173e8 | 7445 | /* Not on tool-bar item. */ |
06a2c219 GM |
7446 | clear_mouse_face (dpyinfo); |
7447 | return; | |
7448 | } | |
7449 | else if (rc == 0) | |
06a2c219 | 7450 | goto set_help_echo; |
b8009dd1 | 7451 | |
06a2c219 GM |
7452 | clear_mouse_face (dpyinfo); |
7453 | ||
9ea173e8 | 7454 | /* Mouse is down, but on different tool-bar item? */ |
06a2c219 GM |
7455 | mouse_down_p = (dpyinfo->grabbed |
7456 | && f == last_mouse_frame | |
7457 | && FRAME_LIVE_P (f)); | |
7458 | if (mouse_down_p | |
9ea173e8 | 7459 | && last_tool_bar_item != prop_idx) |
06a2c219 GM |
7460 | return; |
7461 | ||
7462 | dpyinfo->mouse_face_image_state = DRAW_NORMAL_TEXT; | |
7463 | draw = mouse_down_p ? DRAW_IMAGE_SUNKEN : DRAW_IMAGE_RAISED; | |
7464 | ||
9ea173e8 | 7465 | /* If tool-bar item is not enabled, don't highlight it. */ |
8daf1204 | 7466 | enabled_p = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_ENABLED_P); |
06a2c219 GM |
7467 | if (!NILP (enabled_p)) |
7468 | { | |
7469 | /* Compute the x-position of the glyph. In front and past the | |
7470 | image is a space. We include this is the highlighted area. */ | |
7471 | row = MATRIX_ROW (w->current_matrix, vpos); | |
7472 | for (i = x = 0; i < hpos; ++i) | |
7473 | x += row->glyphs[TEXT_AREA][i].pixel_width; | |
7474 | ||
7475 | /* Record this as the current active region. */ | |
7476 | dpyinfo->mouse_face_beg_col = hpos; | |
7477 | dpyinfo->mouse_face_beg_row = vpos; | |
7478 | dpyinfo->mouse_face_beg_x = x; | |
7479 | dpyinfo->mouse_face_beg_y = row->y; | |
7480 | dpyinfo->mouse_face_past_end = 0; | |
7481 | ||
7482 | dpyinfo->mouse_face_end_col = hpos + 1; | |
7483 | dpyinfo->mouse_face_end_row = vpos; | |
7484 | dpyinfo->mouse_face_end_x = x + glyph->pixel_width; | |
7485 | dpyinfo->mouse_face_end_y = row->y; | |
7486 | dpyinfo->mouse_face_window = window; | |
9ea173e8 | 7487 | dpyinfo->mouse_face_face_id = TOOL_BAR_FACE_ID; |
06a2c219 GM |
7488 | |
7489 | /* Display it as active. */ | |
7490 | show_mouse_face (dpyinfo, draw); | |
7491 | dpyinfo->mouse_face_image_state = draw; | |
b8009dd1 | 7492 | } |
06a2c219 GM |
7493 | |
7494 | set_help_echo: | |
7495 | ||
50590060 | 7496 | /* Set help_echo to a help string to display for this tool-bar item. |
06a2c219 | 7497 | XTread_socket does the rest. */ |
7cea38bc | 7498 | help_echo_object = help_echo_window = Qnil; |
be010514 | 7499 | help_echo_pos = -1; |
8daf1204 | 7500 | help_echo = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_HELP); |
b7e80413 | 7501 | if (NILP (help_echo)) |
8daf1204 | 7502 | help_echo = AREF (f->tool_bar_items, prop_idx + TOOL_BAR_ITEM_CAPTION); |
b8009dd1 | 7503 | } |
4d73d038 | 7504 | |
06a2c219 GM |
7505 | |
7506 | \f | |
9f8531e5 GM |
7507 | /* Find the glyph matrix position of buffer position CHARPOS in window |
7508 | *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's | |
7509 | current glyphs must be up to date. If CHARPOS is above window | |
7510 | start return (0, 0, 0, 0). If CHARPOS is after end of W, return end | |
7511 | of last line in W. In the row containing CHARPOS, stop before glyphs | |
7e376260 | 7512 | having STOP as object. */ |
b8009dd1 | 7513 | |
9f8531e5 GM |
7514 | #if 0 /* This is a version of fast_find_position that's more correct |
7515 | in the presence of hscrolling, for example. I didn't install | |
7516 | it right away because the problem fixed is minor, it failed | |
7517 | in 20.x as well, and I think it's too risky to install | |
7518 | so near the release of 21.1. 2001-09-25 gerd. */ | |
7519 | ||
7520 | static int | |
7521 | fast_find_position (w, charpos, hpos, vpos, x, y, stop) | |
7522 | struct window *w; | |
7523 | int charpos; | |
7524 | int *hpos, *vpos, *x, *y; | |
7525 | Lisp_Object stop; | |
7526 | { | |
7527 | struct glyph_row *row, *first; | |
7528 | struct glyph *glyph, *end; | |
7529 | int i, past_end = 0; | |
7530 | ||
7531 | first = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
62e33982 | 7532 | row = row_containing_pos (w, charpos, first, NULL, 0); |
9f8531e5 GM |
7533 | if (row == NULL) |
7534 | { | |
7535 | if (charpos < MATRIX_ROW_START_CHARPOS (first)) | |
7536 | { | |
7537 | *x = *y = *hpos = *vpos = 0; | |
7538 | return 0; | |
7539 | } | |
7540 | else | |
7541 | { | |
7542 | row = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); | |
7543 | past_end = 1; | |
7544 | } | |
7545 | } | |
7546 | ||
7547 | *x = row->x; | |
7548 | *y = row->y; | |
7549 | *vpos = MATRIX_ROW_VPOS (row, w->current_matrix); | |
7550 | ||
7551 | glyph = row->glyphs[TEXT_AREA]; | |
7552 | end = glyph + row->used[TEXT_AREA]; | |
7553 | ||
7554 | /* Skip over glyphs not having an object at the start of the row. | |
7555 | These are special glyphs like truncation marks on terminal | |
7556 | frames. */ | |
7557 | if (row->displays_text_p) | |
7558 | while (glyph < end | |
7559 | && INTEGERP (glyph->object) | |
7560 | && !EQ (stop, glyph->object) | |
7561 | && glyph->charpos < 0) | |
7562 | { | |
7563 | *x += glyph->pixel_width; | |
7564 | ++glyph; | |
7565 | } | |
7566 | ||
7567 | while (glyph < end | |
7568 | && !INTEGERP (glyph->object) | |
7569 | && !EQ (stop, glyph->object) | |
7570 | && (!BUFFERP (glyph->object) | |
7571 | || glyph->charpos < charpos)) | |
7572 | { | |
7573 | *x += glyph->pixel_width; | |
7574 | ++glyph; | |
7575 | } | |
7576 | ||
7577 | *hpos = glyph - row->glyphs[TEXT_AREA]; | |
7578 | return past_end; | |
7579 | } | |
7580 | ||
7581 | #else /* not 0 */ | |
7582 | ||
b8009dd1 | 7583 | static int |
7e376260 | 7584 | fast_find_position (w, pos, hpos, vpos, x, y, stop) |
06a2c219 | 7585 | struct window *w; |
b8009dd1 | 7586 | int pos; |
06a2c219 | 7587 | int *hpos, *vpos, *x, *y; |
7e376260 | 7588 | Lisp_Object stop; |
b8009dd1 | 7589 | { |
b8009dd1 | 7590 | int i; |
bf1c0ba1 | 7591 | int lastcol; |
06a2c219 GM |
7592 | int maybe_next_line_p = 0; |
7593 | int line_start_position; | |
7594 | int yb = window_text_bottom_y (w); | |
03d1a189 GM |
7595 | struct glyph_row *row, *best_row; |
7596 | int row_vpos, best_row_vpos; | |
06a2c219 GM |
7597 | int current_x; |
7598 | ||
03d1a189 GM |
7599 | row = best_row = MATRIX_FIRST_TEXT_ROW (w->current_matrix); |
7600 | row_vpos = best_row_vpos = MATRIX_ROW_VPOS (row, w->current_matrix); | |
7601 | ||
06a2c219 | 7602 | while (row->y < yb) |
b8009dd1 | 7603 | { |
06a2c219 GM |
7604 | if (row->used[TEXT_AREA]) |
7605 | line_start_position = row->glyphs[TEXT_AREA]->charpos; | |
7606 | else | |
7607 | line_start_position = 0; | |
7608 | ||
7609 | if (line_start_position > pos) | |
b8009dd1 | 7610 | break; |
77b68646 RS |
7611 | /* If the position sought is the end of the buffer, |
7612 | don't include the blank lines at the bottom of the window. */ | |
06a2c219 GM |
7613 | else if (line_start_position == pos |
7614 | && pos == BUF_ZV (XBUFFER (w->buffer))) | |
77b68646 | 7615 | { |
06a2c219 | 7616 | maybe_next_line_p = 1; |
77b68646 RS |
7617 | break; |
7618 | } | |
06a2c219 GM |
7619 | else if (line_start_position > 0) |
7620 | { | |
7621 | best_row = row; | |
7622 | best_row_vpos = row_vpos; | |
7623 | } | |
4b0bb6f3 GM |
7624 | |
7625 | if (row->y + row->height >= yb) | |
7626 | break; | |
06a2c219 GM |
7627 | |
7628 | ++row; | |
7629 | ++row_vpos; | |
b8009dd1 | 7630 | } |
06a2c219 GM |
7631 | |
7632 | /* Find the right column within BEST_ROW. */ | |
7633 | lastcol = 0; | |
7634 | current_x = best_row->x; | |
7635 | for (i = 0; i < best_row->used[TEXT_AREA]; i++) | |
bf1c0ba1 | 7636 | { |
06a2c219 | 7637 | struct glyph *glyph = best_row->glyphs[TEXT_AREA] + i; |
7e376260 | 7638 | int charpos = glyph->charpos; |
06a2c219 | 7639 | |
7e376260 | 7640 | if (BUFFERP (glyph->object)) |
bf1c0ba1 | 7641 | { |
7e376260 GM |
7642 | if (charpos == pos) |
7643 | { | |
7644 | *hpos = i; | |
7645 | *vpos = best_row_vpos; | |
7646 | *x = current_x; | |
7647 | *y = best_row->y; | |
7648 | return 1; | |
7649 | } | |
7650 | else if (charpos > pos) | |
7651 | break; | |
bf1c0ba1 | 7652 | } |
7e376260 | 7653 | else if (EQ (glyph->object, stop)) |
4d73d038 | 7654 | break; |
06a2c219 | 7655 | |
7e376260 GM |
7656 | if (charpos > 0) |
7657 | lastcol = i; | |
06a2c219 | 7658 | current_x += glyph->pixel_width; |
bf1c0ba1 | 7659 | } |
b8009dd1 | 7660 | |
77b68646 RS |
7661 | /* If we're looking for the end of the buffer, |
7662 | and we didn't find it in the line we scanned, | |
7663 | use the start of the following line. */ | |
06a2c219 | 7664 | if (maybe_next_line_p) |
77b68646 | 7665 | { |
06a2c219 GM |
7666 | ++best_row; |
7667 | ++best_row_vpos; | |
7668 | lastcol = 0; | |
7669 | current_x = best_row->x; | |
77b68646 RS |
7670 | } |
7671 | ||
06a2c219 GM |
7672 | *vpos = best_row_vpos; |
7673 | *hpos = lastcol + 1; | |
7674 | *x = current_x; | |
7675 | *y = best_row->y; | |
b8009dd1 RS |
7676 | return 0; |
7677 | } | |
7678 | ||
9f8531e5 GM |
7679 | #endif /* not 0 */ |
7680 | ||
06a2c219 | 7681 | |
269b7745 | 7682 | /* Find the position of the glyph for position POS in OBJECT in |
7a4bce14 PJ |
7683 | window W's current matrix, and return in *X, *Y the pixel |
7684 | coordinates, and return in *HPOS, *VPOS the column/row of the glyph. | |
f9db2310 GM |
7685 | |
7686 | RIGHT_P non-zero means return the position of the right edge of the | |
7687 | glyph, RIGHT_P zero means return the left edge position. | |
7688 | ||
7689 | If no glyph for POS exists in the matrix, return the position of | |
7690 | the glyph with the next smaller position that is in the matrix, if | |
7691 | RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS | |
7692 | exists in the matrix, return the position of the glyph with the | |
7693 | next larger position in OBJECT. | |
7694 | ||
7695 | Value is non-zero if a glyph was found. */ | |
7696 | ||
7697 | static int | |
7698 | fast_find_string_pos (w, pos, object, hpos, vpos, x, y, right_p) | |
7699 | struct window *w; | |
7700 | int pos; | |
7701 | Lisp_Object object; | |
7702 | int *hpos, *vpos, *x, *y; | |
7703 | int right_p; | |
7704 | { | |
7705 | int yb = window_text_bottom_y (w); | |
7706 | struct glyph_row *r; | |
7707 | struct glyph *best_glyph = NULL; | |
7708 | struct glyph_row *best_row = NULL; | |
7709 | int best_x = 0; | |
7710 | ||
7711 | for (r = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
7712 | r->enabled_p && r->y < yb; | |
7713 | ++r) | |
7714 | { | |
7715 | struct glyph *g = r->glyphs[TEXT_AREA]; | |
7716 | struct glyph *e = g + r->used[TEXT_AREA]; | |
7717 | int gx; | |
7718 | ||
7719 | for (gx = r->x; g < e; gx += g->pixel_width, ++g) | |
7720 | if (EQ (g->object, object)) | |
7721 | { | |
7722 | if (g->charpos == pos) | |
7723 | { | |
7724 | best_glyph = g; | |
7725 | best_x = gx; | |
7726 | best_row = r; | |
7727 | goto found; | |
7728 | } | |
7729 | else if (best_glyph == NULL | |
7730 | || ((abs (g->charpos - pos) | |
7731 | < abs (best_glyph->charpos - pos)) | |
7732 | && (right_p | |
7733 | ? g->charpos < pos | |
7734 | : g->charpos > pos))) | |
7735 | { | |
7736 | best_glyph = g; | |
7737 | best_x = gx; | |
7738 | best_row = r; | |
7739 | } | |
7740 | } | |
7741 | } | |
7742 | ||
7743 | found: | |
7744 | ||
7745 | if (best_glyph) | |
7746 | { | |
7747 | *x = best_x; | |
7748 | *hpos = best_glyph - best_row->glyphs[TEXT_AREA]; | |
7749 | ||
7750 | if (right_p) | |
7751 | { | |
7752 | *x += best_glyph->pixel_width; | |
7753 | ++*hpos; | |
7754 | } | |
7755 | ||
7756 | *y = best_row->y; | |
7757 | *vpos = best_row - w->current_matrix->rows; | |
7758 | } | |
7759 | ||
7760 | return best_glyph != NULL; | |
7761 | } | |
7762 | ||
7763 | ||
b8009dd1 RS |
7764 | /* Display the active region described by mouse_face_* |
7765 | in its mouse-face if HL > 0, in its normal face if HL = 0. */ | |
7766 | ||
7767 | static void | |
06a2c219 | 7768 | show_mouse_face (dpyinfo, draw) |
7a13e894 | 7769 | struct x_display_info *dpyinfo; |
06a2c219 | 7770 | enum draw_glyphs_face draw; |
b8009dd1 | 7771 | { |
7a13e894 | 7772 | struct window *w = XWINDOW (dpyinfo->mouse_face_window); |
06a2c219 | 7773 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
06a2c219 | 7774 | |
b2bbd509 GM |
7775 | if (/* If window is in the process of being destroyed, don't bother |
7776 | to do anything. */ | |
7777 | w->current_matrix != NULL | |
66301061 KS |
7778 | /* Don't update mouse highlight if hidden */ |
7779 | && (draw != DRAW_MOUSE_FACE || !dpyinfo->mouse_face_hidden) | |
b2bbd509 GM |
7780 | /* Recognize when we are called to operate on rows that don't exist |
7781 | anymore. This can happen when a window is split. */ | |
7782 | && dpyinfo->mouse_face_end_row < w->current_matrix->nrows) | |
06a2c219 | 7783 | { |
b2bbd509 GM |
7784 | int phys_cursor_on_p = w->phys_cursor_on_p; |
7785 | struct glyph_row *row, *first, *last; | |
06a2c219 | 7786 | |
b2bbd509 GM |
7787 | first = MATRIX_ROW (w->current_matrix, dpyinfo->mouse_face_beg_row); |
7788 | last = MATRIX_ROW (w->current_matrix, dpyinfo->mouse_face_end_row); | |
7789 | ||
7790 | for (row = first; row <= last && row->enabled_p; ++row) | |
06a2c219 | 7791 | { |
b2bbd509 | 7792 | int start_hpos, end_hpos, start_x; |
06a2c219 | 7793 | |
b2bbd509 GM |
7794 | /* For all but the first row, the highlight starts at column 0. */ |
7795 | if (row == first) | |
7796 | { | |
7797 | start_hpos = dpyinfo->mouse_face_beg_col; | |
7798 | start_x = dpyinfo->mouse_face_beg_x; | |
7799 | } | |
7800 | else | |
7801 | { | |
7802 | start_hpos = 0; | |
7803 | start_x = 0; | |
7804 | } | |
06a2c219 | 7805 | |
b2bbd509 GM |
7806 | if (row == last) |
7807 | end_hpos = dpyinfo->mouse_face_end_col; | |
7808 | else | |
7809 | end_hpos = row->used[TEXT_AREA]; | |
b8009dd1 | 7810 | |
b2bbd509 GM |
7811 | if (end_hpos > start_hpos) |
7812 | { | |
7813 | x_draw_glyphs (w, start_x, row, TEXT_AREA, | |
7814 | start_hpos, end_hpos, draw, 0); | |
b8009dd1 | 7815 | |
60626bab GM |
7816 | row->mouse_face_p |
7817 | = draw == DRAW_MOUSE_FACE || draw == DRAW_IMAGE_RAISED; | |
b2bbd509 GM |
7818 | } |
7819 | } | |
2729a2b5 | 7820 | |
b2bbd509 GM |
7821 | /* When we've written over the cursor, arrange for it to |
7822 | be displayed again. */ | |
7823 | if (phys_cursor_on_p && !w->phys_cursor_on_p) | |
7824 | x_display_cursor (w, 1, | |
7825 | w->phys_cursor.hpos, w->phys_cursor.vpos, | |
7826 | w->phys_cursor.x, w->phys_cursor.y); | |
7827 | } | |
fb3b7de5 | 7828 | |
06a2c219 GM |
7829 | /* Change the mouse cursor. */ |
7830 | if (draw == DRAW_NORMAL_TEXT) | |
7831 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
7832 | f->output_data.x->text_cursor); | |
7833 | else if (draw == DRAW_MOUSE_FACE) | |
334208b7 | 7834 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 7835 | f->output_data.x->cross_cursor); |
27ead1d5 | 7836 | else |
334208b7 | 7837 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
06a2c219 | 7838 | f->output_data.x->nontext_cursor); |
b8009dd1 RS |
7839 | } |
7840 | ||
7841 | /* Clear out the mouse-highlighted active region. | |
fa262c07 GM |
7842 | Redraw it un-highlighted first. Value is non-zero if mouse |
7843 | face was actually drawn unhighlighted. */ | |
b8009dd1 | 7844 | |
fa262c07 | 7845 | static int |
7a13e894 RS |
7846 | clear_mouse_face (dpyinfo) |
7847 | struct x_display_info *dpyinfo; | |
b8009dd1 | 7848 | { |
fa262c07 | 7849 | int cleared = 0; |
06a2c219 | 7850 | |
fa262c07 GM |
7851 | if (!NILP (dpyinfo->mouse_face_window)) |
7852 | { | |
7853 | show_mouse_face (dpyinfo, DRAW_NORMAL_TEXT); | |
7854 | cleared = 1; | |
7855 | } | |
b8009dd1 | 7856 | |
7a13e894 RS |
7857 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; |
7858 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7859 | dpyinfo->mouse_face_window = Qnil; | |
1b85dc1c | 7860 | dpyinfo->mouse_face_overlay = Qnil; |
fa262c07 | 7861 | return cleared; |
b8009dd1 | 7862 | } |
e687d06e | 7863 | |
71b8321e GM |
7864 | |
7865 | /* Clear any mouse-face on window W. This function is part of the | |
7866 | redisplay interface, and is called from try_window_id and similar | |
7867 | functions to ensure the mouse-highlight is off. */ | |
7868 | ||
7869 | static void | |
7870 | x_clear_mouse_face (w) | |
7871 | struct window *w; | |
7872 | { | |
7873 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (XFRAME (w->frame)); | |
7874 | Lisp_Object window; | |
7875 | ||
2e636f9d | 7876 | BLOCK_INPUT; |
71b8321e GM |
7877 | XSETWINDOW (window, w); |
7878 | if (EQ (window, dpyinfo->mouse_face_window)) | |
7879 | clear_mouse_face (dpyinfo); | |
2e636f9d | 7880 | UNBLOCK_INPUT; |
71b8321e GM |
7881 | } |
7882 | ||
7883 | ||
e687d06e RS |
7884 | /* Just discard the mouse face information for frame F, if any. |
7885 | This is used when the size of F is changed. */ | |
7886 | ||
dfcf069d | 7887 | void |
e687d06e RS |
7888 | cancel_mouse_face (f) |
7889 | FRAME_PTR f; | |
7890 | { | |
7891 | Lisp_Object window; | |
7892 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
7893 | ||
7894 | window = dpyinfo->mouse_face_window; | |
7895 | if (! NILP (window) && XFRAME (XWINDOW (window)->frame) == f) | |
7896 | { | |
7897 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
7898 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
7899 | dpyinfo->mouse_face_window = Qnil; | |
7900 | } | |
7901 | } | |
b52b65bd | 7902 | |
b8009dd1 | 7903 | \f |
b52b65bd GM |
7904 | static int glyph_rect P_ ((struct frame *f, int, int, XRectangle *)); |
7905 | ||
7906 | ||
7907 | /* Try to determine frame pixel position and size of the glyph under | |
7908 | frame pixel coordinates X/Y on frame F . Return the position and | |
7909 | size in *RECT. Value is non-zero if we could compute these | |
7910 | values. */ | |
7911 | ||
7912 | static int | |
7913 | glyph_rect (f, x, y, rect) | |
7914 | struct frame *f; | |
7915 | int x, y; | |
7916 | XRectangle *rect; | |
7917 | { | |
7918 | Lisp_Object window; | |
7919 | int part, found = 0; | |
7920 | ||
7921 | window = window_from_coordinates (f, x, y, &part, 0); | |
7922 | if (!NILP (window)) | |
7923 | { | |
7924 | struct window *w = XWINDOW (window); | |
7925 | struct glyph_row *r = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
7926 | struct glyph_row *end = r + w->current_matrix->nrows - 1; | |
b52b65bd GM |
7927 | |
7928 | frame_to_window_pixel_xy (w, &x, &y); | |
7929 | ||
7930 | for (; !found && r < end && r->enabled_p; ++r) | |
7931 | if (r->y >= y) | |
7932 | { | |
7933 | struct glyph *g = r->glyphs[TEXT_AREA]; | |
7934 | struct glyph *end = g + r->used[TEXT_AREA]; | |
7935 | int gx; | |
7936 | ||
7937 | for (gx = r->x; !found && g < end; gx += g->pixel_width, ++g) | |
7938 | if (gx >= x) | |
7939 | { | |
7940 | rect->width = g->pixel_width; | |
7941 | rect->height = r->height; | |
7942 | rect->x = WINDOW_TO_FRAME_PIXEL_X (w, gx); | |
7943 | rect->y = WINDOW_TO_FRAME_PIXEL_Y (w, r->y); | |
7944 | found = 1; | |
7945 | } | |
7946 | } | |
7947 | } | |
7948 | ||
7949 | return found; | |
7950 | } | |
7951 | ||
12ba150f | 7952 | |
90e65f07 | 7953 | /* Return the current position of the mouse. |
b52b65bd | 7954 | *FP should be a frame which indicates which display to ask about. |
90e65f07 | 7955 | |
b52b65bd GM |
7956 | If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW, |
7957 | and *PART to the frame, window, and scroll bar part that the mouse | |
7958 | is over. Set *X and *Y to the portion and whole of the mouse's | |
ab648270 | 7959 | position on the scroll bar. |
12ba150f | 7960 | |
b52b65bd GM |
7961 | If the mouse movement started elsewhere, set *FP to the frame the |
7962 | mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell | |
12ba150f JB |
7963 | the mouse is over. |
7964 | ||
b52b65bd | 7965 | Set *TIME to the server time-stamp for the time at which the mouse |
12ba150f JB |
7966 | was at this position. |
7967 | ||
a135645a RS |
7968 | Don't store anything if we don't have a valid set of values to report. |
7969 | ||
90e65f07 | 7970 | This clears the mouse_moved flag, so we can wait for the next mouse |
f5bb65ec | 7971 | movement. */ |
90e65f07 JB |
7972 | |
7973 | static void | |
1cf412ec | 7974 | XTmouse_position (fp, insist, bar_window, part, x, y, time) |
334208b7 | 7975 | FRAME_PTR *fp; |
1cf412ec | 7976 | int insist; |
12ba150f | 7977 | Lisp_Object *bar_window; |
ab648270 | 7978 | enum scroll_bar_part *part; |
90e65f07 | 7979 | Lisp_Object *x, *y; |
e5d77022 | 7980 | unsigned long *time; |
90e65f07 | 7981 | { |
a135645a RS |
7982 | FRAME_PTR f1; |
7983 | ||
90e65f07 JB |
7984 | BLOCK_INPUT; |
7985 | ||
8bcee03e | 7986 | if (! NILP (last_mouse_scroll_bar) && insist == 0) |
334208b7 | 7987 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time); |
90e65f07 JB |
7988 | else |
7989 | { | |
12ba150f JB |
7990 | Window root; |
7991 | int root_x, root_y; | |
90e65f07 | 7992 | |
12ba150f JB |
7993 | Window dummy_window; |
7994 | int dummy; | |
7995 | ||
39d8bb4d KH |
7996 | Lisp_Object frame, tail; |
7997 | ||
7998 | /* Clear the mouse-moved flag for every frame on this display. */ | |
7999 | FOR_EACH_FRAME (tail, frame) | |
8000 | if (FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp)) | |
8001 | XFRAME (frame)->mouse_moved = 0; | |
8002 | ||
ab648270 | 8003 | last_mouse_scroll_bar = Qnil; |
12ba150f JB |
8004 | |
8005 | /* Figure out which root window we're on. */ | |
334208b7 RS |
8006 | XQueryPointer (FRAME_X_DISPLAY (*fp), |
8007 | DefaultRootWindow (FRAME_X_DISPLAY (*fp)), | |
12ba150f JB |
8008 | |
8009 | /* The root window which contains the pointer. */ | |
8010 | &root, | |
8011 | ||
8012 | /* Trash which we can't trust if the pointer is on | |
8013 | a different screen. */ | |
8014 | &dummy_window, | |
8015 | ||
8016 | /* The position on that root window. */ | |
58769bee | 8017 | &root_x, &root_y, |
12ba150f JB |
8018 | |
8019 | /* More trash we can't trust. */ | |
8020 | &dummy, &dummy, | |
8021 | ||
8022 | /* Modifier keys and pointer buttons, about which | |
8023 | we don't care. */ | |
8024 | (unsigned int *) &dummy); | |
8025 | ||
8026 | /* Now we have a position on the root; find the innermost window | |
8027 | containing the pointer. */ | |
8028 | { | |
8029 | Window win, child; | |
8030 | int win_x, win_y; | |
06a2c219 | 8031 | int parent_x = 0, parent_y = 0; |
e99db5a1 | 8032 | int count; |
12ba150f JB |
8033 | |
8034 | win = root; | |
69388238 | 8035 | |
2d7fc7e8 RS |
8036 | /* XTranslateCoordinates can get errors if the window |
8037 | structure is changing at the same time this function | |
8038 | is running. So at least we must not crash from them. */ | |
8039 | ||
e99db5a1 | 8040 | count = x_catch_errors (FRAME_X_DISPLAY (*fp)); |
2d7fc7e8 | 8041 | |
334208b7 | 8042 | if (FRAME_X_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame |
23faf38f | 8043 | && FRAME_LIVE_P (last_mouse_frame)) |
12ba150f | 8044 | { |
69388238 RS |
8045 | /* If mouse was grabbed on a frame, give coords for that frame |
8046 | even if the mouse is now outside it. */ | |
334208b7 | 8047 | XTranslateCoordinates (FRAME_X_DISPLAY (*fp), |
69388238 | 8048 | |
12ba150f | 8049 | /* From-window, to-window. */ |
69388238 | 8050 | root, FRAME_X_WINDOW (last_mouse_frame), |
12ba150f JB |
8051 | |
8052 | /* From-position, to-position. */ | |
8053 | root_x, root_y, &win_x, &win_y, | |
8054 | ||
8055 | /* Child of win. */ | |
8056 | &child); | |
69388238 RS |
8057 | f1 = last_mouse_frame; |
8058 | } | |
8059 | else | |
8060 | { | |
8061 | while (1) | |
8062 | { | |
334208b7 | 8063 | XTranslateCoordinates (FRAME_X_DISPLAY (*fp), |
12ba150f | 8064 | |
69388238 RS |
8065 | /* From-window, to-window. */ |
8066 | root, win, | |
12ba150f | 8067 | |
69388238 RS |
8068 | /* From-position, to-position. */ |
8069 | root_x, root_y, &win_x, &win_y, | |
8070 | ||
8071 | /* Child of win. */ | |
8072 | &child); | |
8073 | ||
9af3143a | 8074 | if (child == None || child == win) |
69388238 RS |
8075 | break; |
8076 | ||
8077 | win = child; | |
8078 | parent_x = win_x; | |
8079 | parent_y = win_y; | |
8080 | } | |
12ba150f | 8081 | |
69388238 RS |
8082 | /* Now we know that: |
8083 | win is the innermost window containing the pointer | |
8084 | (XTC says it has no child containing the pointer), | |
8085 | win_x and win_y are the pointer's position in it | |
8086 | (XTC did this the last time through), and | |
8087 | parent_x and parent_y are the pointer's position in win's parent. | |
8088 | (They are what win_x and win_y were when win was child. | |
8089 | If win is the root window, it has no parent, and | |
8090 | parent_{x,y} are invalid, but that's okay, because we'll | |
8091 | never use them in that case.) */ | |
8092 | ||
8093 | /* Is win one of our frames? */ | |
19126e11 | 8094 | f1 = x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp), win); |
aad0f6ab GM |
8095 | |
8096 | #ifdef USE_X_TOOLKIT | |
8097 | /* If we end up with the menu bar window, say it's not | |
8098 | on the frame. */ | |
8099 | if (f1 != NULL | |
8100 | && f1->output_data.x->menubar_widget | |
8101 | && win == XtWindow (f1->output_data.x->menubar_widget)) | |
8102 | f1 = NULL; | |
8103 | #endif /* USE_X_TOOLKIT */ | |
69388238 | 8104 | } |
58769bee | 8105 | |
2d7fc7e8 RS |
8106 | if (x_had_errors_p (FRAME_X_DISPLAY (*fp))) |
8107 | f1 = 0; | |
8108 | ||
e99db5a1 | 8109 | x_uncatch_errors (FRAME_X_DISPLAY (*fp), count); |
2d7fc7e8 | 8110 | |
ab648270 | 8111 | /* If not, is it one of our scroll bars? */ |
a135645a | 8112 | if (! f1) |
12ba150f | 8113 | { |
ab648270 | 8114 | struct scroll_bar *bar = x_window_to_scroll_bar (win); |
12ba150f JB |
8115 | |
8116 | if (bar) | |
8117 | { | |
a135645a | 8118 | f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
12ba150f JB |
8119 | win_x = parent_x; |
8120 | win_y = parent_y; | |
8121 | } | |
8122 | } | |
90e65f07 | 8123 | |
8bcee03e | 8124 | if (f1 == 0 && insist > 0) |
b86bd3dd | 8125 | f1 = SELECTED_FRAME (); |
1cf412ec | 8126 | |
a135645a | 8127 | if (f1) |
12ba150f | 8128 | { |
06a2c219 GM |
8129 | /* Ok, we found a frame. Store all the values. |
8130 | last_mouse_glyph is a rectangle used to reduce the | |
8131 | generation of mouse events. To not miss any motion | |
8132 | events, we must divide the frame into rectangles of the | |
8133 | size of the smallest character that could be displayed | |
8134 | on it, i.e. into the same rectangles that matrices on | |
8135 | the frame are divided into. */ | |
8136 | ||
b52b65bd GM |
8137 | int width, height, gx, gy; |
8138 | XRectangle rect; | |
8139 | ||
8140 | if (glyph_rect (f1, win_x, win_y, &rect)) | |
8141 | last_mouse_glyph = rect; | |
8142 | else | |
8143 | { | |
8144 | width = FRAME_SMALLEST_CHAR_WIDTH (f1); | |
8145 | height = FRAME_SMALLEST_FONT_HEIGHT (f1); | |
8146 | gx = win_x; | |
8147 | gy = win_y; | |
06a2c219 | 8148 | |
b52b65bd GM |
8149 | /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to |
8150 | round down even for negative values. */ | |
8151 | if (gx < 0) | |
8152 | gx -= width - 1; | |
4f00e84d | 8153 | if (gy < 0) |
b52b65bd GM |
8154 | gy -= height - 1; |
8155 | gx = (gx + width - 1) / width * width; | |
8156 | gy = (gy + height - 1) / height * height; | |
8157 | ||
8158 | last_mouse_glyph.width = width; | |
8159 | last_mouse_glyph.height = height; | |
8160 | last_mouse_glyph.x = gx; | |
8161 | last_mouse_glyph.y = gy; | |
8162 | } | |
12ba150f JB |
8163 | |
8164 | *bar_window = Qnil; | |
8165 | *part = 0; | |
334208b7 | 8166 | *fp = f1; |
e0c1aef2 KH |
8167 | XSETINT (*x, win_x); |
8168 | XSETINT (*y, win_y); | |
12ba150f JB |
8169 | *time = last_mouse_movement_time; |
8170 | } | |
8171 | } | |
8172 | } | |
90e65f07 JB |
8173 | |
8174 | UNBLOCK_INPUT; | |
8175 | } | |
f451eb13 | 8176 | |
06a2c219 | 8177 | |
06a2c219 | 8178 | #ifdef USE_X_TOOLKIT |
bffcfca9 GM |
8179 | |
8180 | /* Atimer callback function for TIMER. Called every 0.1s to process | |
8181 | Xt timeouts, if needed. We must avoid calling XtAppPending as | |
8182 | much as possible because that function does an implicit XFlush | |
8183 | that slows us down. */ | |
8184 | ||
8185 | static void | |
8186 | x_process_timeouts (timer) | |
8187 | struct atimer *timer; | |
8188 | { | |
8189 | if (toolkit_scroll_bar_interaction || popup_activated_flag) | |
8190 | { | |
8191 | BLOCK_INPUT; | |
8192 | while (XtAppPending (Xt_app_con) & XtIMTimer) | |
8193 | XtAppProcessEvent (Xt_app_con, XtIMTimer); | |
8194 | UNBLOCK_INPUT; | |
8195 | } | |
06a2c219 GM |
8196 | } |
8197 | ||
bffcfca9 | 8198 | #endif /* USE_X_TOOLKIT */ |
06a2c219 GM |
8199 | |
8200 | \f | |
8201 | /* Scroll bar support. */ | |
8202 | ||
8203 | /* Given an X window ID, find the struct scroll_bar which manages it. | |
8204 | This can be called in GC, so we have to make sure to strip off mark | |
8205 | bits. */ | |
bffcfca9 | 8206 | |
06a2c219 GM |
8207 | static struct scroll_bar * |
8208 | x_window_to_scroll_bar (window_id) | |
8209 | Window window_id; | |
8210 | { | |
8211 | Lisp_Object tail; | |
8212 | ||
8213 | for (tail = Vframe_list; | |
8214 | XGCTYPE (tail) == Lisp_Cons; | |
8e713be6 | 8215 | tail = XCDR (tail)) |
06a2c219 GM |
8216 | { |
8217 | Lisp_Object frame, bar, condemned; | |
8218 | ||
8e713be6 | 8219 | frame = XCAR (tail); |
06a2c219 GM |
8220 | /* All elements of Vframe_list should be frames. */ |
8221 | if (! GC_FRAMEP (frame)) | |
8222 | abort (); | |
8223 | ||
8224 | /* Scan this frame's scroll bar list for a scroll bar with the | |
8225 | right window ID. */ | |
8226 | condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); | |
8227 | for (bar = FRAME_SCROLL_BARS (XFRAME (frame)); | |
8228 | /* This trick allows us to search both the ordinary and | |
8229 | condemned scroll bar lists with one loop. */ | |
8230 | ! GC_NILP (bar) || (bar = condemned, | |
8231 | condemned = Qnil, | |
8232 | ! GC_NILP (bar)); | |
8233 | bar = XSCROLL_BAR (bar)->next) | |
8234 | if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)) == window_id) | |
8235 | return XSCROLL_BAR (bar); | |
8236 | } | |
8237 | ||
8238 | return 0; | |
8239 | } | |
8240 | ||
8241 | ||
01f67d2c | 8242 | #if defined USE_LUCID |
c95fc5f1 GM |
8243 | |
8244 | /* Return the Lucid menu bar WINDOW is part of. Return null | |
8245 | if WINDOW is not part of a menu bar. */ | |
8246 | ||
8247 | static Widget | |
8248 | x_window_to_menu_bar (window) | |
8249 | Window window; | |
8250 | { | |
8251 | Lisp_Object tail; | |
8252 | ||
8253 | for (tail = Vframe_list; | |
8254 | XGCTYPE (tail) == Lisp_Cons; | |
8255 | tail = XCDR (tail)) | |
8256 | { | |
8257 | Lisp_Object frame = XCAR (tail); | |
8258 | Widget menu_bar = XFRAME (frame)->output_data.x->menubar_widget; | |
8259 | ||
8260 | if (menu_bar && xlwmenu_window_p (menu_bar, window)) | |
8261 | return menu_bar; | |
8262 | } | |
8263 | ||
8264 | return NULL; | |
8265 | } | |
8266 | ||
01f67d2c | 8267 | #endif /* USE_LUCID */ |
c95fc5f1 | 8268 | |
06a2c219 GM |
8269 | \f |
8270 | /************************************************************************ | |
8271 | Toolkit scroll bars | |
8272 | ************************************************************************/ | |
8273 | ||
eccc05db | 8274 | #ifdef USE_TOOLKIT_SCROLL_BARS |
06a2c219 GM |
8275 | |
8276 | static void x_scroll_bar_to_input_event P_ ((XEvent *, struct input_event *)); | |
8277 | static void x_send_scroll_bar_event P_ ((Lisp_Object, int, int, int)); | |
8278 | static void x_create_toolkit_scroll_bar P_ ((struct frame *, | |
8279 | struct scroll_bar *)); | |
8280 | static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *, | |
8281 | int, int, int)); | |
8282 | ||
8283 | ||
8284 | /* Id of action hook installed for scroll bars. */ | |
8285 | ||
8286 | static XtActionHookId action_hook_id; | |
8287 | ||
8288 | /* Lisp window being scrolled. Set when starting to interact with | |
8289 | a toolkit scroll bar, reset to nil when ending the interaction. */ | |
8290 | ||
8291 | static Lisp_Object window_being_scrolled; | |
8292 | ||
8293 | /* Last scroll bar part sent in xm_scroll_callback. */ | |
8294 | ||
8295 | static int last_scroll_bar_part; | |
8296 | ||
ec18280f SM |
8297 | /* Whether this is an Xaw with arrow-scrollbars. This should imply |
8298 | that movements of 1/20 of the screen size are mapped to up/down. */ | |
8299 | ||
8300 | static Boolean xaw3d_arrow_scroll; | |
8301 | ||
8302 | /* Whether the drag scrolling maintains the mouse at the top of the | |
8303 | thumb. If not, resizing the thumb needs to be done more carefully | |
8304 | to avoid jerkyness. */ | |
8305 | ||
8306 | static Boolean xaw3d_pick_top; | |
8307 | ||
06a2c219 GM |
8308 | |
8309 | /* Action hook installed via XtAppAddActionHook when toolkit scroll | |
ec18280f | 8310 | bars are used.. The hook is responsible for detecting when |
06a2c219 GM |
8311 | the user ends an interaction with the scroll bar, and generates |
8312 | a `end-scroll' scroll_bar_click' event if so. */ | |
8313 | ||
8314 | static void | |
8315 | xt_action_hook (widget, client_data, action_name, event, params, | |
8316 | num_params) | |
8317 | Widget widget; | |
8318 | XtPointer client_data; | |
8319 | String action_name; | |
8320 | XEvent *event; | |
8321 | String *params; | |
8322 | Cardinal *num_params; | |
8323 | { | |
8324 | int scroll_bar_p; | |
8325 | char *end_action; | |
8326 | ||
8327 | #ifdef USE_MOTIF | |
8328 | scroll_bar_p = XmIsScrollBar (widget); | |
8329 | end_action = "Release"; | |
ec18280f | 8330 | #else /* !USE_MOTIF i.e. use Xaw */ |
06a2c219 GM |
8331 | scroll_bar_p = XtIsSubclass (widget, scrollbarWidgetClass); |
8332 | end_action = "EndScroll"; | |
ec18280f | 8333 | #endif /* USE_MOTIF */ |
06a2c219 | 8334 | |
06a2c219 GM |
8335 | if (scroll_bar_p |
8336 | && strcmp (action_name, end_action) == 0 | |
8337 | && WINDOWP (window_being_scrolled)) | |
8338 | { | |
8339 | struct window *w; | |
8340 | ||
8341 | x_send_scroll_bar_event (window_being_scrolled, | |
8342 | scroll_bar_end_scroll, 0, 0); | |
8343 | w = XWINDOW (window_being_scrolled); | |
8344 | XSCROLL_BAR (w->vertical_scroll_bar)->dragging = Qnil; | |
8345 | window_being_scrolled = Qnil; | |
8346 | last_scroll_bar_part = -1; | |
bffcfca9 GM |
8347 | |
8348 | /* Xt timeouts no longer needed. */ | |
8349 | toolkit_scroll_bar_interaction = 0; | |
06a2c219 GM |
8350 | } |
8351 | } | |
8352 | ||
07b3d16e GM |
8353 | /* A vector of windows used for communication between |
8354 | x_send_scroll_bar_event and x_scroll_bar_to_input_event. */ | |
8355 | ||
8356 | static struct window **scroll_bar_windows; | |
8357 | static int scroll_bar_windows_size; | |
8358 | ||
06a2c219 GM |
8359 | |
8360 | /* Send a client message with message type Xatom_Scrollbar for a | |
8361 | scroll action to the frame of WINDOW. PART is a value identifying | |
8362 | the part of the scroll bar that was clicked on. PORTION is the | |
8363 | amount to scroll of a whole of WHOLE. */ | |
8364 | ||
8365 | static void | |
8366 | x_send_scroll_bar_event (window, part, portion, whole) | |
8367 | Lisp_Object window; | |
8368 | int part, portion, whole; | |
8369 | { | |
8370 | XEvent event; | |
8371 | XClientMessageEvent *ev = (XClientMessageEvent *) &event; | |
07b3d16e GM |
8372 | struct window *w = XWINDOW (window); |
8373 | struct frame *f = XFRAME (w->frame); | |
8374 | int i; | |
06a2c219 | 8375 | |
07b3d16e GM |
8376 | BLOCK_INPUT; |
8377 | ||
06a2c219 GM |
8378 | /* Construct a ClientMessage event to send to the frame. */ |
8379 | ev->type = ClientMessage; | |
8380 | ev->message_type = FRAME_X_DISPLAY_INFO (f)->Xatom_Scrollbar; | |
8381 | ev->display = FRAME_X_DISPLAY (f); | |
8382 | ev->window = FRAME_X_WINDOW (f); | |
8383 | ev->format = 32; | |
07b3d16e GM |
8384 | |
8385 | /* We can only transfer 32 bits in the XClientMessageEvent, which is | |
8386 | not enough to store a pointer or Lisp_Object on a 64 bit system. | |
8387 | So, store the window in scroll_bar_windows and pass the index | |
8388 | into that array in the event. */ | |
8389 | for (i = 0; i < scroll_bar_windows_size; ++i) | |
8390 | if (scroll_bar_windows[i] == NULL) | |
8391 | break; | |
8392 | ||
8393 | if (i == scroll_bar_windows_size) | |
8394 | { | |
8395 | int new_size = max (10, 2 * scroll_bar_windows_size); | |
8396 | size_t nbytes = new_size * sizeof *scroll_bar_windows; | |
8397 | size_t old_nbytes = scroll_bar_windows_size * sizeof *scroll_bar_windows; | |
8398 | ||
8399 | scroll_bar_windows = (struct window **) xrealloc (scroll_bar_windows, | |
8400 | nbytes); | |
8401 | bzero (&scroll_bar_windows[i], nbytes - old_nbytes); | |
8402 | scroll_bar_windows_size = new_size; | |
8403 | } | |
8404 | ||
8405 | scroll_bar_windows[i] = w; | |
8406 | ev->data.l[0] = (long) i; | |
06a2c219 GM |
8407 | ev->data.l[1] = (long) part; |
8408 | ev->data.l[2] = (long) 0; | |
8409 | ev->data.l[3] = (long) portion; | |
8410 | ev->data.l[4] = (long) whole; | |
8411 | ||
bffcfca9 GM |
8412 | /* Make Xt timeouts work while the scroll bar is active. */ |
8413 | toolkit_scroll_bar_interaction = 1; | |
8414 | ||
06a2c219 GM |
8415 | /* Setting the event mask to zero means that the message will |
8416 | be sent to the client that created the window, and if that | |
8417 | window no longer exists, no event will be sent. */ | |
06a2c219 GM |
8418 | XSendEvent (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), False, 0, &event); |
8419 | UNBLOCK_INPUT; | |
8420 | } | |
8421 | ||
8422 | ||
8423 | /* Transform a scroll bar ClientMessage EVENT to an Emacs input event | |
8424 | in *IEVENT. */ | |
8425 | ||
8426 | static void | |
8427 | x_scroll_bar_to_input_event (event, ievent) | |
8428 | XEvent *event; | |
8429 | struct input_event *ievent; | |
8430 | { | |
8431 | XClientMessageEvent *ev = (XClientMessageEvent *) event; | |
52e386c2 KR |
8432 | Lisp_Object window; |
8433 | struct frame *f; | |
07b3d16e GM |
8434 | struct window *w; |
8435 | ||
8436 | w = scroll_bar_windows[ev->data.l[0]]; | |
8437 | scroll_bar_windows[ev->data.l[0]] = NULL; | |
52e386c2 | 8438 | |
07b3d16e GM |
8439 | XSETWINDOW (window, w); |
8440 | f = XFRAME (w->frame); | |
06a2c219 GM |
8441 | |
8442 | ievent->kind = scroll_bar_click; | |
8443 | ievent->frame_or_window = window; | |
0f8aabe9 | 8444 | ievent->arg = Qnil; |
06a2c219 GM |
8445 | ievent->timestamp = XtLastTimestampProcessed (FRAME_X_DISPLAY (f)); |
8446 | ievent->part = ev->data.l[1]; | |
8447 | ievent->code = ev->data.l[2]; | |
8448 | ievent->x = make_number ((int) ev->data.l[3]); | |
8449 | ievent->y = make_number ((int) ev->data.l[4]); | |
8450 | ievent->modifiers = 0; | |
8451 | } | |
8452 | ||
8453 | ||
8454 | #ifdef USE_MOTIF | |
8455 | ||
8456 | /* Minimum and maximum values used for Motif scroll bars. */ | |
8457 | ||
8458 | #define XM_SB_MIN 1 | |
8459 | #define XM_SB_MAX 10000000 | |
8460 | #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN) | |
8461 | ||
8462 | ||
8463 | /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll | |
8464 | bar widget. CLIENT_DATA is a pointer to the scroll_bar structure. | |
8465 | CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */ | |
8466 | ||
8467 | static void | |
8468 | xm_scroll_callback (widget, client_data, call_data) | |
8469 | Widget widget; | |
8470 | XtPointer client_data, call_data; | |
8471 | { | |
8472 | struct scroll_bar *bar = (struct scroll_bar *) client_data; | |
8473 | XmScrollBarCallbackStruct *cs = (XmScrollBarCallbackStruct *) call_data; | |
06a2c219 GM |
8474 | int part = -1, whole = 0, portion = 0; |
8475 | ||
8476 | switch (cs->reason) | |
8477 | { | |
8478 | case XmCR_DECREMENT: | |
8479 | bar->dragging = Qnil; | |
8480 | part = scroll_bar_up_arrow; | |
8481 | break; | |
8482 | ||
8483 | case XmCR_INCREMENT: | |
8484 | bar->dragging = Qnil; | |
8485 | part = scroll_bar_down_arrow; | |
8486 | break; | |
8487 | ||
8488 | case XmCR_PAGE_DECREMENT: | |
8489 | bar->dragging = Qnil; | |
8490 | part = scroll_bar_above_handle; | |
8491 | break; | |
8492 | ||
8493 | case XmCR_PAGE_INCREMENT: | |
8494 | bar->dragging = Qnil; | |
8495 | part = scroll_bar_below_handle; | |
8496 | break; | |
8497 | ||
8498 | case XmCR_TO_TOP: | |
8499 | bar->dragging = Qnil; | |
8500 | part = scroll_bar_to_top; | |
8501 | break; | |
8502 | ||
8503 | case XmCR_TO_BOTTOM: | |
8504 | bar->dragging = Qnil; | |
8505 | part = scroll_bar_to_bottom; | |
8506 | break; | |
8507 | ||
8508 | case XmCR_DRAG: | |
8509 | { | |
8510 | int slider_size; | |
8511 | int dragging_down_p = (INTEGERP (bar->dragging) | |
8512 | && XINT (bar->dragging) <= cs->value); | |
8513 | ||
8514 | /* Get the slider size. */ | |
8515 | BLOCK_INPUT; | |
8516 | XtVaGetValues (widget, XmNsliderSize, &slider_size, NULL); | |
8517 | UNBLOCK_INPUT; | |
8518 | ||
6f2a7a68 SM |
8519 | whole = XM_SB_RANGE - slider_size; |
8520 | portion = min (cs->value - XM_SB_MIN, whole); | |
8521 | part = scroll_bar_handle; | |
8522 | bar->dragging = make_number (cs->value); | |
06a2c219 GM |
8523 | } |
8524 | break; | |
8525 | ||
8526 | case XmCR_VALUE_CHANGED: | |
8527 | break; | |
8528 | }; | |
8529 | ||
8530 | if (part >= 0) | |
8531 | { | |
8532 | window_being_scrolled = bar->window; | |
8533 | last_scroll_bar_part = part; | |
8534 | x_send_scroll_bar_event (bar->window, part, portion, whole); | |
8535 | } | |
8536 | } | |
8537 | ||
8538 | ||
ec18280f | 8539 | #else /* !USE_MOTIF, i.e. Xaw. */ |
06a2c219 GM |
8540 | |
8541 | ||
ec18280f | 8542 | /* Xaw scroll bar callback. Invoked when the thumb is dragged. |
06a2c219 GM |
8543 | WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the |
8544 | scroll bar struct. CALL_DATA is a pointer to a float saying where | |
8545 | the thumb is. */ | |
8546 | ||
8547 | static void | |
ec18280f | 8548 | xaw_jump_callback (widget, client_data, call_data) |
06a2c219 GM |
8549 | Widget widget; |
8550 | XtPointer client_data, call_data; | |
8551 | { | |
8552 | struct scroll_bar *bar = (struct scroll_bar *) client_data; | |
8553 | float top = *(float *) call_data; | |
8554 | float shown; | |
ec18280f SM |
8555 | int whole, portion, height; |
8556 | int part; | |
06a2c219 GM |
8557 | |
8558 | /* Get the size of the thumb, a value between 0 and 1. */ | |
8559 | BLOCK_INPUT; | |
ec18280f | 8560 | XtVaGetValues (widget, XtNshown, &shown, XtNheight, &height, NULL); |
06a2c219 GM |
8561 | UNBLOCK_INPUT; |
8562 | ||
8563 | whole = 10000000; | |
8564 | portion = shown < 1 ? top * whole : 0; | |
06a2c219 | 8565 | |
ec18280f SM |
8566 | if (shown < 1 && (abs (top + shown - 1) < 1.0/height)) |
8567 | /* Some derivatives of Xaw refuse to shrink the thumb when you reach | |
8568 | the bottom, so we force the scrolling whenever we see that we're | |
8569 | too close to the bottom (in x_set_toolkit_scroll_bar_thumb | |
8570 | we try to ensure that we always stay two pixels away from the | |
8571 | bottom). */ | |
06a2c219 GM |
8572 | part = scroll_bar_down_arrow; |
8573 | else | |
8574 | part = scroll_bar_handle; | |
8575 | ||
8576 | window_being_scrolled = bar->window; | |
8577 | bar->dragging = make_number (portion); | |
8578 | last_scroll_bar_part = part; | |
8579 | x_send_scroll_bar_event (bar->window, part, portion, whole); | |
8580 | } | |
8581 | ||
8582 | ||
ec18280f SM |
8583 | /* Xaw scroll bar callback. Invoked for incremental scrolling., |
8584 | i.e. line or page up or down. WIDGET is the Xaw scroll bar | |
06a2c219 GM |
8585 | widget. CLIENT_DATA is a pointer to the scroll_bar structure for |
8586 | the scroll bar. CALL_DATA is an integer specifying the action that | |
8587 | has taken place. It's magnitude is in the range 0..height of the | |
8588 | scroll bar. Negative values mean scroll towards buffer start. | |
8589 | Values < height of scroll bar mean line-wise movement. */ | |
8590 | ||
8591 | static void | |
ec18280f | 8592 | xaw_scroll_callback (widget, client_data, call_data) |
06a2c219 GM |
8593 | Widget widget; |
8594 | XtPointer client_data, call_data; | |
8595 | { | |
8596 | struct scroll_bar *bar = (struct scroll_bar *) client_data; | |
8597 | int position = (int) call_data; | |
8598 | Dimension height; | |
8599 | int part; | |
8600 | ||
8601 | /* Get the height of the scroll bar. */ | |
8602 | BLOCK_INPUT; | |
8603 | XtVaGetValues (widget, XtNheight, &height, NULL); | |
8604 | UNBLOCK_INPUT; | |
8605 | ||
ec18280f SM |
8606 | if (abs (position) >= height) |
8607 | part = (position < 0) ? scroll_bar_above_handle : scroll_bar_below_handle; | |
8608 | ||
8609 | /* If Xaw3d was compiled with ARROW_SCROLLBAR, | |
8610 | it maps line-movement to call_data = max(5, height/20). */ | |
8611 | else if (xaw3d_arrow_scroll && abs (position) <= max (5, height / 20)) | |
8612 | part = (position < 0) ? scroll_bar_up_arrow : scroll_bar_down_arrow; | |
06a2c219 | 8613 | else |
ec18280f | 8614 | part = scroll_bar_move_ratio; |
06a2c219 GM |
8615 | |
8616 | window_being_scrolled = bar->window; | |
8617 | bar->dragging = Qnil; | |
8618 | last_scroll_bar_part = part; | |
ec18280f | 8619 | x_send_scroll_bar_event (bar->window, part, position, height); |
06a2c219 GM |
8620 | } |
8621 | ||
8622 | ||
8623 | #endif /* not USE_MOTIF */ | |
8624 | ||
8625 | ||
8626 | /* Create the widget for scroll bar BAR on frame F. Record the widget | |
8627 | and X window of the scroll bar in BAR. */ | |
8628 | ||
8629 | static void | |
8630 | x_create_toolkit_scroll_bar (f, bar) | |
8631 | struct frame *f; | |
8632 | struct scroll_bar *bar; | |
8633 | { | |
8634 | Window xwindow; | |
8635 | Widget widget; | |
8636 | Arg av[20]; | |
8637 | int ac = 0; | |
8638 | char *scroll_bar_name = "verticalScrollBar"; | |
8639 | unsigned long pixel; | |
8640 | ||
8641 | BLOCK_INPUT; | |
8642 | ||
8643 | #ifdef USE_MOTIF | |
06a2c219 GM |
8644 | /* Set resources. Create the widget. */ |
8645 | XtSetArg (av[ac], XtNmappedWhenManaged, False); ++ac; | |
8646 | XtSetArg (av[ac], XmNminimum, XM_SB_MIN); ++ac; | |
8647 | XtSetArg (av[ac], XmNmaximum, XM_SB_MAX); ++ac; | |
8648 | XtSetArg (av[ac], XmNorientation, XmVERTICAL); ++ac; | |
8649 | XtSetArg (av[ac], XmNprocessingDirection, XmMAX_ON_BOTTOM), ++ac; | |
8650 | XtSetArg (av[ac], XmNincrement, 1); ++ac; | |
8651 | XtSetArg (av[ac], XmNpageIncrement, 1); ++ac; | |
8652 | ||
8653 | pixel = f->output_data.x->scroll_bar_foreground_pixel; | |
8654 | if (pixel != -1) | |
8655 | { | |
8656 | XtSetArg (av[ac], XmNforeground, pixel); | |
8657 | ++ac; | |
8658 | } | |
8659 | ||
8660 | pixel = f->output_data.x->scroll_bar_background_pixel; | |
8661 | if (pixel != -1) | |
8662 | { | |
8663 | XtSetArg (av[ac], XmNbackground, pixel); | |
8664 | ++ac; | |
8665 | } | |
8666 | ||
8667 | widget = XmCreateScrollBar (f->output_data.x->edit_widget, | |
8668 | scroll_bar_name, av, ac); | |
8669 | ||
8670 | /* Add one callback for everything that can happen. */ | |
8671 | XtAddCallback (widget, XmNdecrementCallback, xm_scroll_callback, | |
8672 | (XtPointer) bar); | |
8673 | XtAddCallback (widget, XmNdragCallback, xm_scroll_callback, | |
8674 | (XtPointer) bar); | |
8675 | XtAddCallback (widget, XmNincrementCallback, xm_scroll_callback, | |
8676 | (XtPointer) bar); | |
8677 | XtAddCallback (widget, XmNpageDecrementCallback, xm_scroll_callback, | |
8678 | (XtPointer) bar); | |
8679 | XtAddCallback (widget, XmNpageIncrementCallback, xm_scroll_callback, | |
8680 | (XtPointer) bar); | |
8681 | XtAddCallback (widget, XmNtoBottomCallback, xm_scroll_callback, | |
8682 | (XtPointer) bar); | |
8683 | XtAddCallback (widget, XmNtoTopCallback, xm_scroll_callback, | |
8684 | (XtPointer) bar); | |
8685 | ||
8686 | /* Realize the widget. Only after that is the X window created. */ | |
8687 | XtRealizeWidget (widget); | |
8688 | ||
8689 | /* Set the cursor to an arrow. I didn't find a resource to do that. | |
8690 | And I'm wondering why it hasn't an arrow cursor by default. */ | |
8691 | XDefineCursor (XtDisplay (widget), XtWindow (widget), | |
8692 | f->output_data.x->nontext_cursor); | |
8693 | ||
ec18280f | 8694 | #else /* !USE_MOTIF i.e. use Xaw */ |
06a2c219 GM |
8695 | |
8696 | /* Set resources. Create the widget. The background of the | |
8697 | Xaw3d scroll bar widget is a little bit light for my taste. | |
8698 | We don't alter it here to let users change it according | |
8699 | to their taste with `emacs*verticalScrollBar.background: xxx'. */ | |
8700 | XtSetArg (av[ac], XtNmappedWhenManaged, False); ++ac; | |
8701 | XtSetArg (av[ac], XtNorientation, XtorientVertical); ++ac; | |
ec18280f SM |
8702 | /* For smoother scrolling with Xaw3d -sm */ |
8703 | /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */ | |
06a2c219 GM |
8704 | |
8705 | pixel = f->output_data.x->scroll_bar_foreground_pixel; | |
8706 | if (pixel != -1) | |
8707 | { | |
8708 | XtSetArg (av[ac], XtNforeground, pixel); | |
8709 | ++ac; | |
8710 | } | |
8711 | ||
8712 | pixel = f->output_data.x->scroll_bar_background_pixel; | |
8713 | if (pixel != -1) | |
8714 | { | |
8715 | XtSetArg (av[ac], XtNbackground, pixel); | |
8716 | ++ac; | |
8717 | } | |
7c1bef7a MB |
8718 | |
8719 | /* Top/bottom shadow colors. */ | |
8720 | ||
8721 | /* Allocate them, if necessary. */ | |
8722 | if (f->output_data.x->scroll_bar_top_shadow_pixel == -1) | |
8723 | { | |
8724 | pixel = f->output_data.x->scroll_bar_background_pixel; | |
8725 | if (!x_alloc_lighter_color (f, FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), | |
8726 | &pixel, 1.2, 0x8000)) | |
8727 | pixel = -1; | |
8728 | f->output_data.x->scroll_bar_top_shadow_pixel = pixel; | |
8729 | } | |
8730 | if (f->output_data.x->scroll_bar_bottom_shadow_pixel == -1) | |
8731 | { | |
8732 | pixel = f->output_data.x->scroll_bar_background_pixel; | |
8733 | if (!x_alloc_lighter_color (f, FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), | |
8734 | &pixel, 0.6, 0x4000)) | |
8735 | pixel = -1; | |
8736 | f->output_data.x->scroll_bar_bottom_shadow_pixel = pixel; | |
8737 | } | |
8738 | ||
8739 | /* Tell the toolkit about them. */ | |
8740 | if (f->output_data.x->scroll_bar_top_shadow_pixel == -1 | |
8741 | || f->output_data.x->scroll_bar_bottom_shadow_pixel == -1) | |
8742 | /* We tried to allocate a color for the top/bottom shadow, and | |
8743 | failed, so tell Xaw3d to use dithering instead. */ | |
8744 | { | |
8745 | XtSetArg (av[ac], XtNbeNiceToColormap, True); | |
8746 | ++ac; | |
8747 | } | |
8748 | else | |
8749 | /* Tell what colors Xaw3d should use for the top/bottom shadow, to | |
8750 | be more consistent with other emacs 3d colors, and since Xaw3d is | |
8751 | not good at dealing with allocation failure. */ | |
8752 | { | |
8753 | /* This tells Xaw3d to use real colors instead of dithering for | |
8754 | the shadows. */ | |
8755 | XtSetArg (av[ac], XtNbeNiceToColormap, False); | |
8756 | ++ac; | |
8757 | ||
8758 | /* Specify the colors. */ | |
8759 | pixel = f->output_data.x->scroll_bar_top_shadow_pixel; | |
8760 | if (pixel != -1) | |
8761 | { | |
8762 | XtSetArg (av[ac], "topShadowPixel", pixel); | |
8763 | ++ac; | |
8764 | } | |
8765 | pixel = f->output_data.x->scroll_bar_bottom_shadow_pixel; | |
8766 | if (pixel != -1) | |
8767 | { | |
8768 | XtSetArg (av[ac], "bottomShadowPixel", pixel); | |
8769 | ++ac; | |
8770 | } | |
8771 | } | |
8772 | ||
06a2c219 GM |
8773 | widget = XtCreateWidget (scroll_bar_name, scrollbarWidgetClass, |
8774 | f->output_data.x->edit_widget, av, ac); | |
ec18280f SM |
8775 | |
8776 | { | |
8777 | char *initial = ""; | |
8778 | char *val = initial; | |
8779 | XtVaGetValues (widget, XtNscrollVCursor, (XtPointer) &val, | |
8780 | XtNpickTop, (XtPointer) &xaw3d_pick_top, NULL); | |
8781 | if (val == initial) | |
8782 | { /* ARROW_SCROLL */ | |
8783 | xaw3d_arrow_scroll = True; | |
8784 | /* Isn't that just a personal preference ? -sm */ | |
8785 | XtVaSetValues (widget, XtNcursorName, "top_left_arrow", NULL); | |
8786 | } | |
8787 | } | |
06a2c219 GM |
8788 | |
8789 | /* Define callbacks. */ | |
ec18280f SM |
8790 | XtAddCallback (widget, XtNjumpProc, xaw_jump_callback, (XtPointer) bar); |
8791 | XtAddCallback (widget, XtNscrollProc, xaw_scroll_callback, | |
06a2c219 GM |
8792 | (XtPointer) bar); |
8793 | ||
8794 | /* Realize the widget. Only after that is the X window created. */ | |
8795 | XtRealizeWidget (widget); | |
8796 | ||
ec18280f | 8797 | #endif /* !USE_MOTIF */ |
06a2c219 GM |
8798 | |
8799 | /* Install an action hook that let's us detect when the user | |
8800 | finishes interacting with a scroll bar. */ | |
8801 | if (action_hook_id == 0) | |
8802 | action_hook_id = XtAppAddActionHook (Xt_app_con, xt_action_hook, 0); | |
8803 | ||
8804 | /* Remember X window and widget in the scroll bar vector. */ | |
8805 | SET_SCROLL_BAR_X_WIDGET (bar, widget); | |
8806 | xwindow = XtWindow (widget); | |
8807 | SET_SCROLL_BAR_X_WINDOW (bar, xwindow); | |
8808 | ||
8809 | UNBLOCK_INPUT; | |
8810 | } | |
8811 | ||
8812 | ||
8813 | /* Set the thumb size and position of scroll bar BAR. We are currently | |
8814 | displaying PORTION out of a whole WHOLE, and our position POSITION. */ | |
8815 | ||
8816 | static void | |
8817 | x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole) | |
8818 | struct scroll_bar *bar; | |
8819 | int portion, position, whole; | |
f451eb13 | 8820 | { |
e83dc917 GM |
8821 | struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
8822 | Widget widget = SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar); | |
06a2c219 | 8823 | float top, shown; |
f451eb13 | 8824 | |
6f2a7a68 SM |
8825 | BLOCK_INPUT; |
8826 | ||
8827 | #ifdef USE_MOTIF | |
8828 | ||
8829 | /* We use an estimate of 30 chars per line rather than the real | |
8830 | `portion' value. This has the disadvantage that the thumb size | |
8831 | is not very representative, but it makes our life a lot easier. | |
8832 | Otherwise, we have to constantly adjust the thumb size, which | |
8833 | we can't always do quickly enough: while dragging, the size of | |
8834 | the thumb might prevent the user from dragging the thumb all the | |
8835 | way to the end. but Motif and some versions of Xaw3d don't allow | |
8836 | updating the thumb size while dragging. Also, even if we can update | |
8837 | its size, the update will often happen too late. | |
8838 | If you don't believe it, check out revision 1.650 of xterm.c to see | |
8839 | what hoops we were going through and the still poor behavior we got. */ | |
8840 | portion = XFASTINT (XWINDOW (bar->window)->height) * 30; | |
8841 | /* When the thumb is at the bottom, position == whole. | |
8842 | So we need to increase `whole' to make space for the thumb. */ | |
8843 | whole += portion; | |
8844 | ||
8845 | if (whole <= 0) | |
06a2c219 GM |
8846 | top = 0, shown = 1; |
8847 | else | |
f451eb13 | 8848 | { |
06a2c219 GM |
8849 | top = (float) position / whole; |
8850 | shown = (float) portion / whole; | |
8851 | } | |
f451eb13 | 8852 | |
6f2a7a68 SM |
8853 | if (NILP (bar->dragging)) |
8854 | { | |
8855 | int size, value; | |
06a2c219 | 8856 | |
6f2a7a68 SM |
8857 | /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX |
8858 | is the scroll bar's maximum and MIN is the scroll bar's minimum | |
8859 | value. */ | |
8860 | size = shown * XM_SB_RANGE; | |
8861 | size = min (size, XM_SB_RANGE); | |
8862 | size = max (size, 1); | |
06a2c219 | 8863 | |
6f2a7a68 SM |
8864 | /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */ |
8865 | value = top * XM_SB_RANGE; | |
8866 | value = min (value, XM_SB_MAX - size); | |
8867 | value = max (value, XM_SB_MIN); | |
8868 | ||
06a2c219 | 8869 | XmScrollBarSetValues (widget, value, size, 0, 0, False); |
6f2a7a68 | 8870 | } |
ec18280f | 8871 | #else /* !USE_MOTIF i.e. use Xaw */ |
6f2a7a68 SM |
8872 | |
8873 | if (whole == 0) | |
8874 | top = 0, shown = 1; | |
8875 | else | |
8876 | { | |
8877 | top = (float) position / whole; | |
8878 | shown = (float) portion / whole; | |
8879 | } | |
8880 | ||
06a2c219 | 8881 | { |
ec18280f SM |
8882 | float old_top, old_shown; |
8883 | Dimension height; | |
8884 | XtVaGetValues (widget, | |
8885 | XtNtopOfThumb, &old_top, | |
8886 | XtNshown, &old_shown, | |
8887 | XtNheight, &height, | |
8888 | NULL); | |
8889 | ||
8890 | /* Massage the top+shown values. */ | |
8891 | if (NILP (bar->dragging) || last_scroll_bar_part == scroll_bar_down_arrow) | |
8892 | top = max (0, min (1, top)); | |
8893 | else | |
8894 | top = old_top; | |
8895 | /* Keep two pixels available for moving the thumb down. */ | |
8896 | shown = max (0, min (1 - top - (2.0 / height), shown)); | |
06a2c219 GM |
8897 | |
8898 | /* If the call to XawScrollbarSetThumb below doesn't seem to work, | |
8899 | check that your system's configuration file contains a define | |
8900 | for `NARROWPROTO'. See s/freebsd.h for an example. */ | |
ec18280f | 8901 | if (top != old_top || shown != old_shown) |
eb393530 | 8902 | { |
ec18280f | 8903 | if (NILP (bar->dragging)) |
eb393530 | 8904 | XawScrollbarSetThumb (widget, top, shown); |
06a2c219 GM |
8905 | else |
8906 | { | |
ec18280f SM |
8907 | #ifdef HAVE_XAW3D |
8908 | ScrollbarWidget sb = (ScrollbarWidget) widget; | |
3e71d8f2 | 8909 | int scroll_mode = 0; |
ec18280f SM |
8910 | |
8911 | /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */ | |
8912 | if (xaw3d_arrow_scroll) | |
8913 | { | |
8914 | /* Xaw3d stupidly ignores resize requests while dragging | |
8915 | so we have to make it believe it's not in dragging mode. */ | |
8916 | scroll_mode = sb->scrollbar.scroll_mode; | |
8917 | if (scroll_mode == 2) | |
8918 | sb->scrollbar.scroll_mode = 0; | |
8919 | } | |
8920 | #endif | |
8921 | /* Try to make the scrolling a tad smoother. */ | |
8922 | if (!xaw3d_pick_top) | |
8923 | shown = min (shown, old_shown); | |
8924 | ||
8925 | XawScrollbarSetThumb (widget, top, shown); | |
8926 | ||
8927 | #ifdef HAVE_XAW3D | |
8928 | if (xaw3d_arrow_scroll && scroll_mode == 2) | |
8929 | sb->scrollbar.scroll_mode = scroll_mode; | |
8930 | #endif | |
06a2c219 | 8931 | } |
06a2c219 GM |
8932 | } |
8933 | } | |
ec18280f | 8934 | #endif /* !USE_MOTIF */ |
06a2c219 GM |
8935 | |
8936 | UNBLOCK_INPUT; | |
f451eb13 JB |
8937 | } |
8938 | ||
06a2c219 GM |
8939 | #endif /* USE_TOOLKIT_SCROLL_BARS */ |
8940 | ||
8941 | ||
8942 | \f | |
8943 | /************************************************************************ | |
8944 | Scroll bars, general | |
8945 | ************************************************************************/ | |
8946 | ||
8947 | /* Create a scroll bar and return the scroll bar vector for it. W is | |
8948 | the Emacs window on which to create the scroll bar. TOP, LEFT, | |
f7ccf929 | 8949 | WIDTH and HEIGHT are the pixel coordinates and dimensions of the |
06a2c219 GM |
8950 | scroll bar. */ |
8951 | ||
ab648270 | 8952 | static struct scroll_bar * |
06a2c219 GM |
8953 | x_scroll_bar_create (w, top, left, width, height) |
8954 | struct window *w; | |
f451eb13 JB |
8955 | int top, left, width, height; |
8956 | { | |
06a2c219 | 8957 | struct frame *f = XFRAME (w->frame); |
334208b7 RS |
8958 | struct scroll_bar *bar |
8959 | = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil)); | |
f451eb13 JB |
8960 | |
8961 | BLOCK_INPUT; | |
8962 | ||
eccc05db | 8963 | #ifdef USE_TOOLKIT_SCROLL_BARS |
06a2c219 GM |
8964 | x_create_toolkit_scroll_bar (f, bar); |
8965 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
f451eb13 JB |
8966 | { |
8967 | XSetWindowAttributes a; | |
8968 | unsigned long mask; | |
5c187dee | 8969 | Window window; |
06a2c219 GM |
8970 | |
8971 | a.background_pixel = f->output_data.x->scroll_bar_background_pixel; | |
8972 | if (a.background_pixel == -1) | |
8973 | a.background_pixel = f->output_data.x->background_pixel; | |
8974 | ||
12ba150f | 8975 | a.event_mask = (ButtonPressMask | ButtonReleaseMask |
9a572e2a | 8976 | | ButtonMotionMask | PointerMotionHintMask |
12ba150f | 8977 | | ExposureMask); |
7a13e894 | 8978 | a.cursor = FRAME_X_DISPLAY_INFO (f)->vertical_scroll_bar_cursor; |
f451eb13 | 8979 | |
dbc4e1c1 | 8980 | mask = (CWBackPixel | CWEventMask | CWCursor); |
f451eb13 | 8981 | |
06a2c219 GM |
8982 | /* Clear the area of W that will serve as a scroll bar. This is |
8983 | for the case that a window has been split horizontally. In | |
8984 | this case, no clear_frame is generated to reduce flickering. */ | |
7b49b9d2 GM |
8985 | if (width > 0 && height > 0) |
8986 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
8987 | left, top, width, | |
8988 | window_box_height (w), False); | |
06a2c219 GM |
8989 | |
8990 | window = XCreateWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
8991 | /* Position and size of scroll bar. */ | |
8992 | left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
8993 | top, | |
8994 | width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
8995 | height, | |
8996 | /* Border width, depth, class, and visual. */ | |
8997 | 0, | |
8998 | CopyFromParent, | |
8999 | CopyFromParent, | |
9000 | CopyFromParent, | |
9001 | /* Attributes. */ | |
9002 | mask, &a); | |
9003 | SET_SCROLL_BAR_X_WINDOW (bar, window); | |
f451eb13 | 9004 | } |
06a2c219 | 9005 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
f451eb13 | 9006 | |
06a2c219 | 9007 | XSETWINDOW (bar->window, w); |
e0c1aef2 KH |
9008 | XSETINT (bar->top, top); |
9009 | XSETINT (bar->left, left); | |
9010 | XSETINT (bar->width, width); | |
9011 | XSETINT (bar->height, height); | |
9012 | XSETINT (bar->start, 0); | |
9013 | XSETINT (bar->end, 0); | |
12ba150f | 9014 | bar->dragging = Qnil; |
f451eb13 JB |
9015 | |
9016 | /* Add bar to its frame's list of scroll bars. */ | |
334208b7 | 9017 | bar->next = FRAME_SCROLL_BARS (f); |
12ba150f | 9018 | bar->prev = Qnil; |
334208b7 | 9019 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); |
06a2c219 | 9020 | if (!NILP (bar->next)) |
e0c1aef2 | 9021 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); |
f451eb13 | 9022 | |
06a2c219 | 9023 | /* Map the window/widget. */ |
eccc05db | 9024 | #ifdef USE_TOOLKIT_SCROLL_BARS |
f964b4d7 GM |
9025 | { |
9026 | Widget scroll_bar = SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar); | |
9027 | XtConfigureWidget (scroll_bar, | |
9028 | left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
9029 | top, | |
9030 | width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
9031 | max (height, 1), 0); | |
9032 | XtMapWidget (scroll_bar); | |
9033 | } | |
06a2c219 | 9034 | #else /* not USE_TOOLKIT_SCROLL_BARS */ |
7f9c7f94 | 9035 | XMapRaised (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar)); |
06a2c219 | 9036 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
f451eb13 JB |
9037 | |
9038 | UNBLOCK_INPUT; | |
12ba150f | 9039 | return bar; |
f451eb13 JB |
9040 | } |
9041 | ||
06a2c219 | 9042 | |
12ba150f | 9043 | /* Draw BAR's handle in the proper position. |
06a2c219 | 9044 | |
12ba150f JB |
9045 | If the handle is already drawn from START to END, don't bother |
9046 | redrawing it, unless REBUILD is non-zero; in that case, always | |
9047 | redraw it. (REBUILD is handy for drawing the handle after expose | |
58769bee | 9048 | events.) |
12ba150f JB |
9049 | |
9050 | Normally, we want to constrain the start and end of the handle to | |
06a2c219 GM |
9051 | fit inside its rectangle, but if the user is dragging the scroll |
9052 | bar handle, we want to let them drag it down all the way, so that | |
9053 | the bar's top is as far down as it goes; otherwise, there's no way | |
9054 | to move to the very end of the buffer. */ | |
9055 | ||
5c187dee GM |
9056 | #ifndef USE_TOOLKIT_SCROLL_BARS |
9057 | ||
f451eb13 | 9058 | static void |
ab648270 JB |
9059 | x_scroll_bar_set_handle (bar, start, end, rebuild) |
9060 | struct scroll_bar *bar; | |
f451eb13 | 9061 | int start, end; |
12ba150f | 9062 | int rebuild; |
f451eb13 | 9063 | { |
12ba150f | 9064 | int dragging = ! NILP (bar->dragging); |
ab648270 | 9065 | Window w = SCROLL_BAR_X_WINDOW (bar); |
334208b7 | 9066 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
7556890b | 9067 | GC gc = f->output_data.x->normal_gc; |
12ba150f JB |
9068 | |
9069 | /* If the display is already accurate, do nothing. */ | |
9070 | if (! rebuild | |
9071 | && start == XINT (bar->start) | |
9072 | && end == XINT (bar->end)) | |
9073 | return; | |
9074 | ||
f451eb13 JB |
9075 | BLOCK_INPUT; |
9076 | ||
9077 | { | |
d9cdbb3d RS |
9078 | int inside_width = VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f, XINT (bar->width)); |
9079 | int inside_height = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height)); | |
9080 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); | |
f451eb13 JB |
9081 | |
9082 | /* Make sure the values are reasonable, and try to preserve | |
9083 | the distance between start and end. */ | |
12ba150f JB |
9084 | { |
9085 | int length = end - start; | |
9086 | ||
9087 | if (start < 0) | |
9088 | start = 0; | |
9089 | else if (start > top_range) | |
9090 | start = top_range; | |
9091 | end = start + length; | |
9092 | ||
9093 | if (end < start) | |
9094 | end = start; | |
9095 | else if (end > top_range && ! dragging) | |
9096 | end = top_range; | |
9097 | } | |
f451eb13 | 9098 | |
ab648270 | 9099 | /* Store the adjusted setting in the scroll bar. */ |
e0c1aef2 KH |
9100 | XSETINT (bar->start, start); |
9101 | XSETINT (bar->end, end); | |
f451eb13 | 9102 | |
12ba150f JB |
9103 | /* Clip the end position, just for display. */ |
9104 | if (end > top_range) | |
9105 | end = top_range; | |
f451eb13 | 9106 | |
ab648270 | 9107 | /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels |
12ba150f JB |
9108 | below top positions, to make sure the handle is always at least |
9109 | that many pixels tall. */ | |
ab648270 | 9110 | end += VERTICAL_SCROLL_BAR_MIN_HANDLE; |
f451eb13 | 9111 | |
12ba150f JB |
9112 | /* Draw the empty space above the handle. Note that we can't clear |
9113 | zero-height areas; that means "clear to end of window." */ | |
9114 | if (0 < start) | |
c5e6e06b GM |
9115 | x_clear_area (FRAME_X_DISPLAY (f), w, |
9116 | /* x, y, width, height, and exposures. */ | |
9117 | VERTICAL_SCROLL_BAR_LEFT_BORDER, | |
9118 | VERTICAL_SCROLL_BAR_TOP_BORDER, | |
9119 | inside_width, start, | |
9120 | False); | |
f451eb13 | 9121 | |
06a2c219 GM |
9122 | /* Change to proper foreground color if one is specified. */ |
9123 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
9124 | XSetForeground (FRAME_X_DISPLAY (f), gc, | |
9125 | f->output_data.x->scroll_bar_foreground_pixel); | |
9126 | ||
12ba150f | 9127 | /* Draw the handle itself. */ |
334208b7 | 9128 | XFillRectangle (FRAME_X_DISPLAY (f), w, gc, |
12ba150f | 9129 | /* x, y, width, height */ |
ab648270 JB |
9130 | VERTICAL_SCROLL_BAR_LEFT_BORDER, |
9131 | VERTICAL_SCROLL_BAR_TOP_BORDER + start, | |
12ba150f | 9132 | inside_width, end - start); |
f451eb13 | 9133 | |
06a2c219 GM |
9134 | /* Restore the foreground color of the GC if we changed it above. */ |
9135 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
9136 | XSetForeground (FRAME_X_DISPLAY (f), gc, | |
9137 | f->output_data.x->foreground_pixel); | |
f451eb13 | 9138 | |
12ba150f JB |
9139 | /* Draw the empty space below the handle. Note that we can't |
9140 | clear zero-height areas; that means "clear to end of window." */ | |
9141 | if (end < inside_height) | |
c5e6e06b GM |
9142 | x_clear_area (FRAME_X_DISPLAY (f), w, |
9143 | /* x, y, width, height, and exposures. */ | |
9144 | VERTICAL_SCROLL_BAR_LEFT_BORDER, | |
9145 | VERTICAL_SCROLL_BAR_TOP_BORDER + end, | |
9146 | inside_width, inside_height - end, | |
9147 | False); | |
f451eb13 | 9148 | |
f451eb13 JB |
9149 | } |
9150 | ||
f451eb13 JB |
9151 | UNBLOCK_INPUT; |
9152 | } | |
9153 | ||
5c187dee | 9154 | #endif /* !USE_TOOLKIT_SCROLL_BARS */ |
f451eb13 | 9155 | |
06a2c219 GM |
9156 | /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to |
9157 | nil. */ | |
58769bee | 9158 | |
12ba150f | 9159 | static void |
ab648270 JB |
9160 | x_scroll_bar_remove (bar) |
9161 | struct scroll_bar *bar; | |
12ba150f | 9162 | { |
e83dc917 | 9163 | struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
12ba150f JB |
9164 | BLOCK_INPUT; |
9165 | ||
eccc05db | 9166 | #ifdef USE_TOOLKIT_SCROLL_BARS |
e83dc917 GM |
9167 | XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar)); |
9168 | #else | |
9169 | XDestroyWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar)); | |
9170 | #endif | |
06a2c219 | 9171 | |
ab648270 JB |
9172 | /* Disassociate this scroll bar from its window. */ |
9173 | XWINDOW (bar->window)->vertical_scroll_bar = Qnil; | |
12ba150f JB |
9174 | |
9175 | UNBLOCK_INPUT; | |
9176 | } | |
9177 | ||
06a2c219 | 9178 | |
12ba150f JB |
9179 | /* Set the handle of the vertical scroll bar for WINDOW to indicate |
9180 | that we are displaying PORTION characters out of a total of WHOLE | |
ab648270 | 9181 | characters, starting at POSITION. If WINDOW has no scroll bar, |
12ba150f | 9182 | create one. */ |
06a2c219 | 9183 | |
12ba150f | 9184 | static void |
06a2c219 GM |
9185 | XTset_vertical_scroll_bar (w, portion, whole, position) |
9186 | struct window *w; | |
f451eb13 JB |
9187 | int portion, whole, position; |
9188 | { | |
06a2c219 | 9189 | struct frame *f = XFRAME (w->frame); |
ab648270 | 9190 | struct scroll_bar *bar; |
3c6ede7b | 9191 | int top, height, left, sb_left, width, sb_width; |
06a2c219 | 9192 | int window_x, window_y, window_width, window_height; |
06a2c219 | 9193 | |
3c6ede7b | 9194 | /* Get window dimensions. */ |
06a2c219 | 9195 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); |
3c6ede7b GM |
9196 | top = window_y; |
9197 | width = FRAME_SCROLL_BAR_COLS (f) * CANON_X_UNIT (f); | |
9198 | height = window_height; | |
06a2c219 | 9199 | |
3c6ede7b | 9200 | /* Compute the left edge of the scroll bar area. */ |
06a2c219 | 9201 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) |
3c6ede7b GM |
9202 | left = XINT (w->left) + XINT (w->width) - FRAME_SCROLL_BAR_COLS (f); |
9203 | else | |
9204 | left = XFASTINT (w->left); | |
9205 | left *= CANON_X_UNIT (f); | |
9206 | left += FRAME_INTERNAL_BORDER_WIDTH (f); | |
9207 | ||
9208 | /* Compute the width of the scroll bar which might be less than | |
9209 | the width of the area reserved for the scroll bar. */ | |
9210 | if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0) | |
9211 | sb_width = FRAME_SCROLL_BAR_PIXEL_WIDTH (f); | |
06a2c219 | 9212 | else |
3c6ede7b | 9213 | sb_width = width; |
12ba150f | 9214 | |
3c6ede7b GM |
9215 | /* Compute the left edge of the scroll bar. */ |
9216 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
9217 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
9218 | sb_left = left + width - sb_width - (width - sb_width) / 2; | |
9219 | else | |
9220 | sb_left = left + (width - sb_width) / 2; | |
9221 | #else | |
9222 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) | |
9223 | sb_left = left + width - sb_width; | |
9224 | else | |
9225 | sb_left = left; | |
9226 | #endif | |
9227 | ||
ab648270 | 9228 | /* Does the scroll bar exist yet? */ |
06a2c219 | 9229 | if (NILP (w->vertical_scroll_bar)) |
3c6ede7b | 9230 | { |
7b49b9d2 | 9231 | if (width > 0 && height > 0) |
b547b6e8 GM |
9232 | { |
9233 | BLOCK_INPUT; | |
9234 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
9235 | left, top, width, height, False); | |
9236 | UNBLOCK_INPUT; | |
9237 | } | |
9238 | ||
3c6ede7b GM |
9239 | bar = x_scroll_bar_create (w, top, sb_left, sb_width, height); |
9240 | } | |
f451eb13 | 9241 | else |
12ba150f JB |
9242 | { |
9243 | /* It may just need to be moved and resized. */ | |
06a2c219 GM |
9244 | unsigned int mask = 0; |
9245 | ||
9246 | bar = XSCROLL_BAR (w->vertical_scroll_bar); | |
9247 | ||
9248 | BLOCK_INPUT; | |
9249 | ||
3c6ede7b | 9250 | if (sb_left != XINT (bar->left)) |
06a2c219 | 9251 | mask |= CWX; |
3c6ede7b | 9252 | if (top != XINT (bar->top)) |
06a2c219 | 9253 | mask |= CWY; |
3c6ede7b | 9254 | if (sb_width != XINT (bar->width)) |
06a2c219 | 9255 | mask |= CWWidth; |
3c6ede7b | 9256 | if (height != XINT (bar->height)) |
06a2c219 GM |
9257 | mask |= CWHeight; |
9258 | ||
9259 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
fe6f39d9 GM |
9260 | |
9261 | /* Since toolkit scroll bars are smaller than the space reserved | |
9262 | for them on the frame, we have to clear "under" them. */ | |
7b49b9d2 | 9263 | if (width > 0 && height > 0) |
f964b4d7 GM |
9264 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
9265 | left, top, width, height, False); | |
06a2c219 GM |
9266 | |
9267 | /* Move/size the scroll bar widget. */ | |
9268 | if (mask) | |
e83dc917 | 9269 | XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar), |
3c6ede7b GM |
9270 | sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, |
9271 | top, | |
9272 | sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2, | |
f964b4d7 | 9273 | max (height, 1), 0); |
06a2c219 GM |
9274 | |
9275 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
9276 | ||
357e7376 GM |
9277 | /* Clear areas not covered by the scroll bar because of |
9278 | VERTICAL_SCROLL_BAR_WIDTH_TRIM. */ | |
e1f6572f RS |
9279 | if (VERTICAL_SCROLL_BAR_WIDTH_TRIM) |
9280 | { | |
c5e6e06b GM |
9281 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
9282 | left, top, VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
9283 | height, False); | |
9284 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
9285 | left + width - VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
9286 | top, VERTICAL_SCROLL_BAR_WIDTH_TRIM, | |
9287 | height, False); | |
e1f6572f | 9288 | } |
357e7376 GM |
9289 | |
9290 | /* Clear areas not covered by the scroll bar because it's not as | |
f7ccf929 | 9291 | wide as the area reserved for it. This makes sure a |
357e7376 GM |
9292 | previous mode line display is cleared after C-x 2 C-x 1, for |
9293 | example. */ | |
9294 | { | |
9295 | int area_width = FRAME_SCROLL_BAR_COLS (f) * CANON_X_UNIT (f); | |
9296 | int rest = area_width - sb_width; | |
38d2af0c GM |
9297 | if (rest > 0 && height > 0) |
9298 | { | |
9299 | if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) | |
9300 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
9301 | left + area_width - rest, top, | |
9302 | rest, height, False); | |
9303 | else | |
9304 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
9305 | left, top, rest, height, False); | |
9306 | } | |
357e7376 | 9307 | } |
06a2c219 GM |
9308 | |
9309 | /* Move/size the scroll bar window. */ | |
9310 | if (mask) | |
9311 | { | |
9312 | XWindowChanges wc; | |
9313 | ||
3c6ede7b GM |
9314 | wc.x = sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM; |
9315 | wc.y = top; | |
9316 | wc.width = sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2; | |
9317 | wc.height = height; | |
06a2c219 GM |
9318 | XConfigureWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar), |
9319 | mask, &wc); | |
9320 | } | |
9321 | ||
9322 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ | |
9323 | ||
9324 | /* Remember new settings. */ | |
3c6ede7b GM |
9325 | XSETINT (bar->left, sb_left); |
9326 | XSETINT (bar->top, top); | |
9327 | XSETINT (bar->width, sb_width); | |
9328 | XSETINT (bar->height, height); | |
06a2c219 GM |
9329 | |
9330 | UNBLOCK_INPUT; | |
12ba150f | 9331 | } |
f451eb13 | 9332 | |
eccc05db | 9333 | #ifdef USE_TOOLKIT_SCROLL_BARS |
06a2c219 GM |
9334 | x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole); |
9335 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
ab648270 | 9336 | /* Set the scroll bar's current state, unless we're currently being |
f451eb13 | 9337 | dragged. */ |
12ba150f | 9338 | if (NILP (bar->dragging)) |
f451eb13 | 9339 | { |
92857db0 | 9340 | int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height); |
f451eb13 | 9341 | |
12ba150f | 9342 | if (whole == 0) |
ab648270 | 9343 | x_scroll_bar_set_handle (bar, 0, top_range, 0); |
12ba150f JB |
9344 | else |
9345 | { | |
43f868f5 JB |
9346 | int start = ((double) position * top_range) / whole; |
9347 | int end = ((double) (position + portion) * top_range) / whole; | |
ab648270 | 9348 | x_scroll_bar_set_handle (bar, start, end, 0); |
12ba150f | 9349 | } |
f451eb13 | 9350 | } |
06a2c219 | 9351 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
f451eb13 | 9352 | |
06a2c219 | 9353 | XSETVECTOR (w->vertical_scroll_bar, bar); |
f451eb13 JB |
9354 | } |
9355 | ||
12ba150f | 9356 | |
f451eb13 | 9357 | /* The following three hooks are used when we're doing a thorough |
ab648270 | 9358 | redisplay of the frame. We don't explicitly know which scroll bars |
f451eb13 | 9359 | are going to be deleted, because keeping track of when windows go |
12ba150f JB |
9360 | away is a real pain - "Can you say set-window-configuration, boys |
9361 | and girls?" Instead, we just assert at the beginning of redisplay | |
ab648270 | 9362 | that *all* scroll bars are to be removed, and then save a scroll bar |
12ba150f | 9363 | from the fiery pit when we actually redisplay its window. */ |
f451eb13 | 9364 | |
ab648270 JB |
9365 | /* Arrange for all scroll bars on FRAME to be removed at the next call |
9366 | to `*judge_scroll_bars_hook'. A scroll bar may be spared if | |
06a2c219 GM |
9367 | `*redeem_scroll_bar_hook' is applied to its window before the judgment. */ |
9368 | ||
58769bee | 9369 | static void |
ab648270 | 9370 | XTcondemn_scroll_bars (frame) |
f451eb13 JB |
9371 | FRAME_PTR frame; |
9372 | { | |
f9e24cb9 RS |
9373 | /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */ |
9374 | while (! NILP (FRAME_SCROLL_BARS (frame))) | |
9375 | { | |
9376 | Lisp_Object bar; | |
9377 | bar = FRAME_SCROLL_BARS (frame); | |
9378 | FRAME_SCROLL_BARS (frame) = XSCROLL_BAR (bar)->next; | |
9379 | XSCROLL_BAR (bar)->next = FRAME_CONDEMNED_SCROLL_BARS (frame); | |
9380 | XSCROLL_BAR (bar)->prev = Qnil; | |
9381 | if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame))) | |
9382 | XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame))->prev = bar; | |
9383 | FRAME_CONDEMNED_SCROLL_BARS (frame) = bar; | |
9384 | } | |
f451eb13 JB |
9385 | } |
9386 | ||
fa2dfc30 | 9387 | |
06a2c219 | 9388 | /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle. |
12ba150f | 9389 | Note that WINDOW isn't necessarily condemned at all. */ |
fa2dfc30 | 9390 | |
f451eb13 | 9391 | static void |
ab648270 | 9392 | XTredeem_scroll_bar (window) |
12ba150f | 9393 | struct window *window; |
f451eb13 | 9394 | { |
ab648270 | 9395 | struct scroll_bar *bar; |
fa2dfc30 | 9396 | struct frame *f; |
12ba150f | 9397 | |
ab648270 JB |
9398 | /* We can't redeem this window's scroll bar if it doesn't have one. */ |
9399 | if (NILP (window->vertical_scroll_bar)) | |
12ba150f JB |
9400 | abort (); |
9401 | ||
ab648270 | 9402 | bar = XSCROLL_BAR (window->vertical_scroll_bar); |
12ba150f JB |
9403 | |
9404 | /* Unlink it from the condemned list. */ | |
fa2dfc30 GM |
9405 | f = XFRAME (WINDOW_FRAME (window)); |
9406 | if (NILP (bar->prev)) | |
9407 | { | |
9408 | /* If the prev pointer is nil, it must be the first in one of | |
9409 | the lists. */ | |
9410 | if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar)) | |
9411 | /* It's not condemned. Everything's fine. */ | |
9412 | return; | |
9413 | else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f), | |
9414 | window->vertical_scroll_bar)) | |
9415 | FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next; | |
9416 | else | |
9417 | /* If its prev pointer is nil, it must be at the front of | |
9418 | one or the other! */ | |
9419 | abort (); | |
9420 | } | |
9421 | else | |
9422 | XSCROLL_BAR (bar->prev)->next = bar->next; | |
12ba150f | 9423 | |
fa2dfc30 GM |
9424 | if (! NILP (bar->next)) |
9425 | XSCROLL_BAR (bar->next)->prev = bar->prev; | |
12ba150f | 9426 | |
fa2dfc30 GM |
9427 | bar->next = FRAME_SCROLL_BARS (f); |
9428 | bar->prev = Qnil; | |
9429 | XSETVECTOR (FRAME_SCROLL_BARS (f), bar); | |
9430 | if (! NILP (bar->next)) | |
9431 | XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar); | |
f451eb13 JB |
9432 | } |
9433 | ||
ab648270 JB |
9434 | /* Remove all scroll bars on FRAME that haven't been saved since the |
9435 | last call to `*condemn_scroll_bars_hook'. */ | |
06a2c219 | 9436 | |
f451eb13 | 9437 | static void |
ab648270 | 9438 | XTjudge_scroll_bars (f) |
12ba150f | 9439 | FRAME_PTR f; |
f451eb13 | 9440 | { |
12ba150f | 9441 | Lisp_Object bar, next; |
f451eb13 | 9442 | |
ab648270 | 9443 | bar = FRAME_CONDEMNED_SCROLL_BARS (f); |
cf7cb199 JB |
9444 | |
9445 | /* Clear out the condemned list now so we won't try to process any | |
ab648270 JB |
9446 | more events on the hapless scroll bars. */ |
9447 | FRAME_CONDEMNED_SCROLL_BARS (f) = Qnil; | |
cf7cb199 JB |
9448 | |
9449 | for (; ! NILP (bar); bar = next) | |
f451eb13 | 9450 | { |
ab648270 | 9451 | struct scroll_bar *b = XSCROLL_BAR (bar); |
12ba150f | 9452 | |
ab648270 | 9453 | x_scroll_bar_remove (b); |
12ba150f JB |
9454 | |
9455 | next = b->next; | |
9456 | b->next = b->prev = Qnil; | |
f451eb13 | 9457 | } |
12ba150f | 9458 | |
ab648270 | 9459 | /* Now there should be no references to the condemned scroll bars, |
12ba150f | 9460 | and they should get garbage-collected. */ |
f451eb13 JB |
9461 | } |
9462 | ||
9463 | ||
06a2c219 GM |
9464 | /* Handle an Expose or GraphicsExpose event on a scroll bar. This |
9465 | is a no-op when using toolkit scroll bars. | |
ab648270 JB |
9466 | |
9467 | This may be called from a signal handler, so we have to ignore GC | |
9468 | mark bits. */ | |
06a2c219 | 9469 | |
f451eb13 | 9470 | static void |
ab648270 JB |
9471 | x_scroll_bar_expose (bar, event) |
9472 | struct scroll_bar *bar; | |
f451eb13 JB |
9473 | XEvent *event; |
9474 | { | |
06a2c219 GM |
9475 | #ifndef USE_TOOLKIT_SCROLL_BARS |
9476 | ||
ab648270 | 9477 | Window w = SCROLL_BAR_X_WINDOW (bar); |
334208b7 | 9478 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
7556890b | 9479 | GC gc = f->output_data.x->normal_gc; |
3cbd2e0b | 9480 | int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM; |
12ba150f | 9481 | |
f451eb13 JB |
9482 | BLOCK_INPUT; |
9483 | ||
ab648270 | 9484 | x_scroll_bar_set_handle (bar, XINT (bar->start), XINT (bar->end), 1); |
f451eb13 | 9485 | |
06a2c219 | 9486 | /* Draw a one-pixel border just inside the edges of the scroll bar. */ |
334208b7 | 9487 | XDrawRectangle (FRAME_X_DISPLAY (f), w, gc, |
f451eb13 JB |
9488 | |
9489 | /* x, y, width, height */ | |
d9cdbb3d | 9490 | 0, 0, |
3cbd2e0b | 9491 | XINT (bar->width) - 1 - width_trim - width_trim, |
d9cdbb3d RS |
9492 | XINT (bar->height) - 1); |
9493 | ||
f451eb13 | 9494 | UNBLOCK_INPUT; |
06a2c219 GM |
9495 | |
9496 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ | |
f451eb13 JB |
9497 | } |
9498 | ||
ab648270 JB |
9499 | /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind |
9500 | is set to something other than no_event, it is enqueued. | |
9501 | ||
9502 | This may be called from a signal handler, so we have to ignore GC | |
9503 | mark bits. */ | |
06a2c219 | 9504 | |
5c187dee GM |
9505 | #ifndef USE_TOOLKIT_SCROLL_BARS |
9506 | ||
f451eb13 | 9507 | static void |
ab648270 JB |
9508 | x_scroll_bar_handle_click (bar, event, emacs_event) |
9509 | struct scroll_bar *bar; | |
f451eb13 JB |
9510 | XEvent *event; |
9511 | struct input_event *emacs_event; | |
9512 | { | |
0299d313 | 9513 | if (! GC_WINDOWP (bar->window)) |
12ba150f JB |
9514 | abort (); |
9515 | ||
ab648270 | 9516 | emacs_event->kind = scroll_bar_click; |
69388238 | 9517 | emacs_event->code = event->xbutton.button - Button1; |
0299d313 RS |
9518 | emacs_event->modifiers |
9519 | = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO | |
9520 | (XFRAME (WINDOW_FRAME (XWINDOW (bar->window)))), | |
9521 | event->xbutton.state) | |
9522 | | (event->type == ButtonRelease | |
9523 | ? up_modifier | |
9524 | : down_modifier)); | |
12ba150f | 9525 | emacs_event->frame_or_window = bar->window; |
0f8aabe9 | 9526 | emacs_event->arg = Qnil; |
f451eb13 | 9527 | emacs_event->timestamp = event->xbutton.time; |
12ba150f | 9528 | { |
06a2c219 | 9529 | #if 0 |
d9cdbb3d | 9530 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); |
0299d313 | 9531 | int internal_height |
d9cdbb3d | 9532 | = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height)); |
06a2c219 | 9533 | #endif |
0299d313 | 9534 | int top_range |
d9cdbb3d | 9535 | = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
ab648270 | 9536 | int y = event->xbutton.y - VERTICAL_SCROLL_BAR_TOP_BORDER; |
12ba150f JB |
9537 | |
9538 | if (y < 0) y = 0; | |
9539 | if (y > top_range) y = top_range; | |
9540 | ||
9541 | if (y < XINT (bar->start)) | |
ab648270 JB |
9542 | emacs_event->part = scroll_bar_above_handle; |
9543 | else if (y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE) | |
9544 | emacs_event->part = scroll_bar_handle; | |
12ba150f | 9545 | else |
ab648270 | 9546 | emacs_event->part = scroll_bar_below_handle; |
929787e1 JB |
9547 | |
9548 | /* Just because the user has clicked on the handle doesn't mean | |
5116f055 JB |
9549 | they want to drag it. Lisp code needs to be able to decide |
9550 | whether or not we're dragging. */ | |
929787e1 | 9551 | #if 0 |
12ba150f JB |
9552 | /* If the user has just clicked on the handle, record where they're |
9553 | holding it. */ | |
9554 | if (event->type == ButtonPress | |
ab648270 | 9555 | && emacs_event->part == scroll_bar_handle) |
e0c1aef2 | 9556 | XSETINT (bar->dragging, y - XINT (bar->start)); |
929787e1 | 9557 | #endif |
12ba150f JB |
9558 | |
9559 | /* If the user has released the handle, set it to its final position. */ | |
9560 | if (event->type == ButtonRelease | |
9561 | && ! NILP (bar->dragging)) | |
9562 | { | |
9563 | int new_start = y - XINT (bar->dragging); | |
9564 | int new_end = new_start + (XINT (bar->end) - XINT (bar->start)); | |
f451eb13 | 9565 | |
ab648270 | 9566 | x_scroll_bar_set_handle (bar, new_start, new_end, 0); |
12ba150f JB |
9567 | bar->dragging = Qnil; |
9568 | } | |
f451eb13 | 9569 | |
5116f055 JB |
9570 | /* Same deal here as the other #if 0. */ |
9571 | #if 0 | |
58769bee | 9572 | /* Clicks on the handle are always reported as occurring at the top of |
12ba150f | 9573 | the handle. */ |
ab648270 | 9574 | if (emacs_event->part == scroll_bar_handle) |
12ba150f JB |
9575 | emacs_event->x = bar->start; |
9576 | else | |
e0c1aef2 | 9577 | XSETINT (emacs_event->x, y); |
5116f055 | 9578 | #else |
e0c1aef2 | 9579 | XSETINT (emacs_event->x, y); |
5116f055 | 9580 | #endif |
f451eb13 | 9581 | |
e0c1aef2 | 9582 | XSETINT (emacs_event->y, top_range); |
12ba150f JB |
9583 | } |
9584 | } | |
f451eb13 | 9585 | |
ab648270 JB |
9586 | /* Handle some mouse motion while someone is dragging the scroll bar. |
9587 | ||
9588 | This may be called from a signal handler, so we have to ignore GC | |
9589 | mark bits. */ | |
06a2c219 | 9590 | |
f451eb13 | 9591 | static void |
ab648270 JB |
9592 | x_scroll_bar_note_movement (bar, event) |
9593 | struct scroll_bar *bar; | |
f451eb13 JB |
9594 | XEvent *event; |
9595 | { | |
39d8bb4d KH |
9596 | FRAME_PTR f = XFRAME (XWINDOW (bar->window)->frame); |
9597 | ||
f451eb13 JB |
9598 | last_mouse_movement_time = event->xmotion.time; |
9599 | ||
39d8bb4d | 9600 | f->mouse_moved = 1; |
e0c1aef2 | 9601 | XSETVECTOR (last_mouse_scroll_bar, bar); |
f451eb13 JB |
9602 | |
9603 | /* If we're dragging the bar, display it. */ | |
ab648270 | 9604 | if (! GC_NILP (bar->dragging)) |
f451eb13 JB |
9605 | { |
9606 | /* Where should the handle be now? */ | |
12ba150f | 9607 | int new_start = event->xmotion.y - XINT (bar->dragging); |
f451eb13 | 9608 | |
12ba150f | 9609 | if (new_start != XINT (bar->start)) |
f451eb13 | 9610 | { |
12ba150f | 9611 | int new_end = new_start + (XINT (bar->end) - XINT (bar->start)); |
58769bee | 9612 | |
ab648270 | 9613 | x_scroll_bar_set_handle (bar, new_start, new_end, 0); |
f451eb13 JB |
9614 | } |
9615 | } | |
f451eb13 JB |
9616 | } |
9617 | ||
5c187dee GM |
9618 | #endif /* !USE_TOOLKIT_SCROLL_BARS */ |
9619 | ||
12ba150f | 9620 | /* Return information to the user about the current position of the mouse |
ab648270 | 9621 | on the scroll bar. */ |
06a2c219 | 9622 | |
12ba150f | 9623 | static void |
334208b7 RS |
9624 | x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) |
9625 | FRAME_PTR *fp; | |
12ba150f | 9626 | Lisp_Object *bar_window; |
ab648270 | 9627 | enum scroll_bar_part *part; |
12ba150f JB |
9628 | Lisp_Object *x, *y; |
9629 | unsigned long *time; | |
9630 | { | |
ab648270 | 9631 | struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); |
334208b7 RS |
9632 | Window w = SCROLL_BAR_X_WINDOW (bar); |
9633 | FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); | |
12ba150f | 9634 | int win_x, win_y; |
559cb2fb JB |
9635 | Window dummy_window; |
9636 | int dummy_coord; | |
9637 | unsigned int dummy_mask; | |
12ba150f | 9638 | |
cf7cb199 JB |
9639 | BLOCK_INPUT; |
9640 | ||
ab648270 | 9641 | /* Get the mouse's position relative to the scroll bar window, and |
12ba150f | 9642 | report that. */ |
334208b7 | 9643 | if (! XQueryPointer (FRAME_X_DISPLAY (f), w, |
12ba150f | 9644 | |
559cb2fb JB |
9645 | /* Root, child, root x and root y. */ |
9646 | &dummy_window, &dummy_window, | |
9647 | &dummy_coord, &dummy_coord, | |
12ba150f | 9648 | |
559cb2fb JB |
9649 | /* Position relative to scroll bar. */ |
9650 | &win_x, &win_y, | |
12ba150f | 9651 | |
559cb2fb JB |
9652 | /* Mouse buttons and modifier keys. */ |
9653 | &dummy_mask)) | |
7a13e894 | 9654 | ; |
559cb2fb JB |
9655 | else |
9656 | { | |
06a2c219 | 9657 | #if 0 |
559cb2fb | 9658 | int inside_height |
d9cdbb3d | 9659 | = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height)); |
06a2c219 | 9660 | #endif |
559cb2fb | 9661 | int top_range |
d9cdbb3d | 9662 | = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); |
559cb2fb JB |
9663 | |
9664 | win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER; | |
9665 | ||
9666 | if (! NILP (bar->dragging)) | |
9667 | win_y -= XINT (bar->dragging); | |
9668 | ||
9669 | if (win_y < 0) | |
9670 | win_y = 0; | |
9671 | if (win_y > top_range) | |
9672 | win_y = top_range; | |
9673 | ||
334208b7 | 9674 | *fp = f; |
7a13e894 | 9675 | *bar_window = bar->window; |
559cb2fb JB |
9676 | |
9677 | if (! NILP (bar->dragging)) | |
9678 | *part = scroll_bar_handle; | |
9679 | else if (win_y < XINT (bar->start)) | |
9680 | *part = scroll_bar_above_handle; | |
9681 | else if (win_y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE) | |
9682 | *part = scroll_bar_handle; | |
9683 | else | |
9684 | *part = scroll_bar_below_handle; | |
12ba150f | 9685 | |
e0c1aef2 KH |
9686 | XSETINT (*x, win_y); |
9687 | XSETINT (*y, top_range); | |
12ba150f | 9688 | |
39d8bb4d | 9689 | f->mouse_moved = 0; |
559cb2fb JB |
9690 | last_mouse_scroll_bar = Qnil; |
9691 | } | |
12ba150f | 9692 | |
559cb2fb | 9693 | *time = last_mouse_movement_time; |
cf7cb199 | 9694 | |
cf7cb199 | 9695 | UNBLOCK_INPUT; |
12ba150f JB |
9696 | } |
9697 | ||
f451eb13 | 9698 | |
dbc4e1c1 | 9699 | /* The screen has been cleared so we may have changed foreground or |
ab648270 JB |
9700 | background colors, and the scroll bars may need to be redrawn. |
9701 | Clear out the scroll bars, and ask for expose events, so we can | |
dbc4e1c1 JB |
9702 | redraw them. */ |
9703 | ||
dfcf069d | 9704 | void |
ab648270 | 9705 | x_scroll_bar_clear (f) |
dbc4e1c1 JB |
9706 | FRAME_PTR f; |
9707 | { | |
06a2c219 | 9708 | #ifndef USE_TOOLKIT_SCROLL_BARS |
dbc4e1c1 JB |
9709 | Lisp_Object bar; |
9710 | ||
b80c363e RS |
9711 | /* We can have scroll bars even if this is 0, |
9712 | if we just turned off scroll bar mode. | |
9713 | But in that case we should not clear them. */ | |
9714 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) | |
9715 | for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar); | |
9716 | bar = XSCROLL_BAR (bar)->next) | |
c5e6e06b GM |
9717 | XClearArea (FRAME_X_DISPLAY (f), |
9718 | SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)), | |
b80c363e | 9719 | 0, 0, 0, 0, True); |
06a2c219 | 9720 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
dbc4e1c1 JB |
9721 | } |
9722 | ||
06a2c219 | 9723 | /* This processes Expose events from the menu-bar specific X event |
19126e11 | 9724 | loop in xmenu.c. This allows to redisplay the frame if necessary |
06a2c219 | 9725 | when handling menu-bar or pop-up items. */ |
3afe33e7 | 9726 | |
06a2c219 | 9727 | int |
3afe33e7 RS |
9728 | process_expose_from_menu (event) |
9729 | XEvent event; | |
9730 | { | |
9731 | FRAME_PTR f; | |
19126e11 | 9732 | struct x_display_info *dpyinfo; |
06a2c219 | 9733 | int frame_exposed_p = 0; |
3afe33e7 | 9734 | |
f94397b5 KH |
9735 | BLOCK_INPUT; |
9736 | ||
19126e11 KH |
9737 | dpyinfo = x_display_info_for_display (event.xexpose.display); |
9738 | f = x_window_to_frame (dpyinfo, event.xexpose.window); | |
3afe33e7 RS |
9739 | if (f) |
9740 | { | |
9741 | if (f->async_visible == 0) | |
9742 | { | |
9743 | f->async_visible = 1; | |
9744 | f->async_iconified = 0; | |
06c488fd | 9745 | f->output_data.x->has_been_visible = 1; |
3afe33e7 RS |
9746 | SET_FRAME_GARBAGED (f); |
9747 | } | |
9748 | else | |
9749 | { | |
06a2c219 GM |
9750 | expose_frame (x_window_to_frame (dpyinfo, event.xexpose.window), |
9751 | event.xexpose.x, event.xexpose.y, | |
9752 | event.xexpose.width, event.xexpose.height); | |
9753 | frame_exposed_p = 1; | |
3afe33e7 RS |
9754 | } |
9755 | } | |
9756 | else | |
9757 | { | |
9758 | struct scroll_bar *bar | |
9759 | = x_window_to_scroll_bar (event.xexpose.window); | |
58769bee | 9760 | |
3afe33e7 RS |
9761 | if (bar) |
9762 | x_scroll_bar_expose (bar, &event); | |
9763 | } | |
f94397b5 KH |
9764 | |
9765 | UNBLOCK_INPUT; | |
06a2c219 | 9766 | return frame_exposed_p; |
3afe33e7 | 9767 | } |
09756a85 RS |
9768 | \f |
9769 | /* Define a queue to save up SelectionRequest events for later handling. */ | |
9770 | ||
9771 | struct selection_event_queue | |
9772 | { | |
9773 | XEvent event; | |
9774 | struct selection_event_queue *next; | |
9775 | }; | |
9776 | ||
9777 | static struct selection_event_queue *queue; | |
9778 | ||
9779 | /* Nonzero means queue up certain events--don't process them yet. */ | |
06a2c219 | 9780 | |
09756a85 RS |
9781 | static int x_queue_selection_requests; |
9782 | ||
9783 | /* Queue up an X event *EVENT, to be processed later. */ | |
dbc4e1c1 | 9784 | |
09756a85 | 9785 | static void |
334208b7 RS |
9786 | x_queue_event (f, event) |
9787 | FRAME_PTR f; | |
09756a85 RS |
9788 | XEvent *event; |
9789 | { | |
9790 | struct selection_event_queue *queue_tmp | |
06a2c219 | 9791 | = (struct selection_event_queue *) xmalloc (sizeof (struct selection_event_queue)); |
09756a85 | 9792 | |
58769bee | 9793 | if (queue_tmp != NULL) |
09756a85 RS |
9794 | { |
9795 | queue_tmp->event = *event; | |
9796 | queue_tmp->next = queue; | |
9797 | queue = queue_tmp; | |
9798 | } | |
9799 | } | |
9800 | ||
9801 | /* Take all the queued events and put them back | |
9802 | so that they get processed afresh. */ | |
9803 | ||
9804 | static void | |
db3906fd RS |
9805 | x_unqueue_events (display) |
9806 | Display *display; | |
09756a85 | 9807 | { |
58769bee | 9808 | while (queue != NULL) |
09756a85 RS |
9809 | { |
9810 | struct selection_event_queue *queue_tmp = queue; | |
db3906fd | 9811 | XPutBackEvent (display, &queue_tmp->event); |
09756a85 | 9812 | queue = queue_tmp->next; |
06a2c219 | 9813 | xfree ((char *)queue_tmp); |
09756a85 RS |
9814 | } |
9815 | } | |
9816 | ||
9817 | /* Start queuing SelectionRequest events. */ | |
9818 | ||
9819 | void | |
db3906fd RS |
9820 | x_start_queuing_selection_requests (display) |
9821 | Display *display; | |
09756a85 RS |
9822 | { |
9823 | x_queue_selection_requests++; | |
9824 | } | |
9825 | ||
9826 | /* Stop queuing SelectionRequest events. */ | |
9827 | ||
9828 | void | |
db3906fd RS |
9829 | x_stop_queuing_selection_requests (display) |
9830 | Display *display; | |
09756a85 RS |
9831 | { |
9832 | x_queue_selection_requests--; | |
db3906fd | 9833 | x_unqueue_events (display); |
09756a85 | 9834 | } |
f451eb13 JB |
9835 | \f |
9836 | /* The main X event-reading loop - XTread_socket. */ | |
dc6f92b8 | 9837 | |
042c33d3 | 9838 | #if 0 |
06a2c219 | 9839 | /* Time stamp of enter window event. This is only used by XTread_socket, |
dc6f92b8 JB |
9840 | but we have to put it out here, since static variables within functions |
9841 | sometimes don't work. */ | |
06a2c219 | 9842 | |
dc6f92b8 | 9843 | static Time enter_timestamp; |
042c33d3 | 9844 | #endif |
dc6f92b8 | 9845 | |
11edeb03 | 9846 | /* This holds the state XLookupString needs to implement dead keys |
58769bee | 9847 | and other tricks known as "compose processing". _X Window System_ |
11edeb03 JB |
9848 | says that a portable program can't use this, but Stephen Gildea assures |
9849 | me that letting the compiler initialize it to zeros will work okay. | |
9850 | ||
9851 | This must be defined outside of XTread_socket, for the same reasons | |
f7d40b3b | 9852 | given for enter_timestamp, above. */ |
06a2c219 | 9853 | |
11edeb03 JB |
9854 | static XComposeStatus compose_status; |
9855 | ||
10e6549c RS |
9856 | /* Record the last 100 characters stored |
9857 | to help debug the loss-of-chars-during-GC problem. */ | |
06a2c219 | 9858 | |
2224b905 RS |
9859 | static int temp_index; |
9860 | static short temp_buffer[100]; | |
10e6549c | 9861 | |
7a13e894 RS |
9862 | /* Set this to nonzero to fake an "X I/O error" |
9863 | on a particular display. */ | |
06a2c219 | 9864 | |
7a13e894 RS |
9865 | struct x_display_info *XTread_socket_fake_io_error; |
9866 | ||
2224b905 RS |
9867 | /* When we find no input here, we occasionally do a no-op command |
9868 | to verify that the X server is still running and we can still talk with it. | |
9869 | We try all the open displays, one by one. | |
9870 | This variable is used for cycling thru the displays. */ | |
06a2c219 | 9871 | |
2224b905 RS |
9872 | static struct x_display_info *next_noop_dpyinfo; |
9873 | ||
06a2c219 GM |
9874 | #define SET_SAVED_MENU_EVENT(size) \ |
9875 | do \ | |
9876 | { \ | |
9877 | if (f->output_data.x->saved_menu_event == 0) \ | |
9878 | f->output_data.x->saved_menu_event \ | |
9879 | = (XEvent *) xmalloc (sizeof (XEvent)); \ | |
9880 | bcopy (&event, f->output_data.x->saved_menu_event, size); \ | |
9881 | if (numchars >= 1) \ | |
9882 | { \ | |
9883 | bufp->kind = menu_bar_activate_event; \ | |
9884 | XSETFRAME (bufp->frame_or_window, f); \ | |
0f8aabe9 | 9885 | bufp->arg = Qnil; \ |
06a2c219 GM |
9886 | bufp++; \ |
9887 | count++; \ | |
9888 | numchars--; \ | |
9889 | } \ | |
9890 | } \ | |
9891 | while (0) | |
9892 | ||
8805890a | 9893 | #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent)) |
06a2c219 | 9894 | #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent)) |
8805890a | 9895 | |
dc6f92b8 JB |
9896 | /* Read events coming from the X server. |
9897 | This routine is called by the SIGIO handler. | |
9898 | We return as soon as there are no more events to be read. | |
9899 | ||
9900 | Events representing keys are stored in buffer BUFP, | |
9901 | which can hold up to NUMCHARS characters. | |
9902 | We return the number of characters stored into the buffer, | |
9903 | thus pretending to be `read'. | |
9904 | ||
dc6f92b8 JB |
9905 | EXPECTED is nonzero if the caller knows input is available. */ |
9906 | ||
6f2a7a68 | 9907 | static int |
f66868ba | 9908 | XTread_socket (sd, bufp, numchars, expected) |
dc6f92b8 | 9909 | register int sd; |
8805890a KH |
9910 | /* register */ struct input_event *bufp; |
9911 | /* register */ int numchars; | |
dc6f92b8 JB |
9912 | int expected; |
9913 | { | |
9914 | int count = 0; | |
9915 | int nbytes = 0; | |
dc6f92b8 | 9916 | XEvent event; |
f676886a | 9917 | struct frame *f; |
66f55a9d | 9918 | int event_found = 0; |
334208b7 | 9919 | struct x_display_info *dpyinfo; |
379b5ac0 | 9920 | struct coding_system coding; |
dc6f92b8 | 9921 | |
9ac0d9e0 | 9922 | if (interrupt_input_blocked) |
dc6f92b8 | 9923 | { |
9ac0d9e0 | 9924 | interrupt_input_pending = 1; |
dc6f92b8 JB |
9925 | return -1; |
9926 | } | |
9927 | ||
9ac0d9e0 | 9928 | interrupt_input_pending = 0; |
dc6f92b8 | 9929 | BLOCK_INPUT; |
c0a04927 RS |
9930 | |
9931 | /* So people can tell when we have read the available input. */ | |
9932 | input_signal_count++; | |
9933 | ||
dc6f92b8 | 9934 | if (numchars <= 0) |
06a2c219 | 9935 | abort (); /* Don't think this happens. */ |
dc6f92b8 | 9936 | |
bde5503b GM |
9937 | ++handling_signal; |
9938 | ||
7a13e894 RS |
9939 | /* Find the display we are supposed to read input for. |
9940 | It's the one communicating on descriptor SD. */ | |
9941 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) | |
9942 | { | |
9943 | #if 0 /* This ought to be unnecessary; let's verify it. */ | |
dc6f92b8 | 9944 | #ifdef FIOSNBIO |
7a13e894 RS |
9945 | /* If available, Xlib uses FIOSNBIO to make the socket |
9946 | non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set, | |
e6cbea31 | 9947 | FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK, |
06a2c219 | 9948 | a read returns 0, which Xlib interprets as equivalent to EPIPE. */ |
7a13e894 | 9949 | fcntl (dpyinfo->connection, F_SETFL, 0); |
c118dd06 | 9950 | #endif /* ! defined (FIOSNBIO) */ |
7a13e894 | 9951 | #endif |
dc6f92b8 | 9952 | |
7a13e894 RS |
9953 | #if 0 /* This code can't be made to work, with multiple displays, |
9954 | and appears not to be used on any system any more. | |
9955 | Also keyboard.c doesn't turn O_NDELAY on and off | |
9956 | for X connections. */ | |
dc6f92b8 JB |
9957 | #ifndef SIGIO |
9958 | #ifndef HAVE_SELECT | |
7a13e894 RS |
9959 | if (! (fcntl (dpyinfo->connection, F_GETFL, 0) & O_NDELAY)) |
9960 | { | |
9961 | extern int read_alarm_should_throw; | |
9962 | read_alarm_should_throw = 1; | |
9963 | XPeekEvent (dpyinfo->display, &event); | |
9964 | read_alarm_should_throw = 0; | |
9965 | } | |
c118dd06 JB |
9966 | #endif /* HAVE_SELECT */ |
9967 | #endif /* SIGIO */ | |
7a13e894 | 9968 | #endif |
dc6f92b8 | 9969 | |
7a13e894 RS |
9970 | /* For debugging, this gives a way to fake an I/O error. */ |
9971 | if (dpyinfo == XTread_socket_fake_io_error) | |
9972 | { | |
9973 | XTread_socket_fake_io_error = 0; | |
9974 | x_io_error_quitter (dpyinfo->display); | |
9975 | } | |
dc6f92b8 | 9976 | |
5f30b957 JD |
9977 | #ifdef HAVE_X_SM |
9978 | BLOCK_INPUT; | |
9979 | count += x_session_check_input (bufp, &numchars); | |
9980 | UNBLOCK_INPUT; | |
9981 | #endif | |
9982 | ||
06a2c219 | 9983 | while (XPending (dpyinfo->display)) |
dc6f92b8 | 9984 | { |
7a13e894 | 9985 | XNextEvent (dpyinfo->display, &event); |
06a2c219 | 9986 | |
531483fb | 9987 | #ifdef HAVE_X_I18N |
d1bc4182 | 9988 | { |
f2be1146 GM |
9989 | /* Filter events for the current X input method. |
9990 | XFilterEvent returns non-zero if the input method has | |
9991 | consumed the event. We pass the frame's X window to | |
9992 | XFilterEvent because that's the one for which the IC | |
9993 | was created. */ | |
f5d11644 GM |
9994 | struct frame *f1 = x_any_window_to_frame (dpyinfo, |
9995 | event.xclient.window); | |
9996 | if (XFilterEvent (&event, f1 ? FRAME_X_WINDOW (f1) : None)) | |
d1bc4182 RS |
9997 | break; |
9998 | } | |
0cd6403b | 9999 | #endif |
7a13e894 RS |
10000 | event_found = 1; |
10001 | ||
10002 | switch (event.type) | |
10003 | { | |
10004 | case ClientMessage: | |
c047688c | 10005 | { |
7a13e894 RS |
10006 | if (event.xclient.message_type |
10007 | == dpyinfo->Xatom_wm_protocols | |
10008 | && event.xclient.format == 32) | |
c047688c | 10009 | { |
7a13e894 RS |
10010 | if (event.xclient.data.l[0] |
10011 | == dpyinfo->Xatom_wm_take_focus) | |
c047688c | 10012 | { |
8c1a6a84 RS |
10013 | /* Use x_any_window_to_frame because this |
10014 | could be the shell widget window | |
10015 | if the frame has no title bar. */ | |
10016 | f = x_any_window_to_frame (dpyinfo, event.xclient.window); | |
6c183ba5 RS |
10017 | #ifdef HAVE_X_I18N |
10018 | /* Not quite sure this is needed -pd */ | |
8c1a6a84 | 10019 | if (f && FRAME_XIC (f)) |
6c183ba5 RS |
10020 | XSetICFocus (FRAME_XIC (f)); |
10021 | #endif | |
f1da8f06 GM |
10022 | #if 0 /* Emacs sets WM hints whose `input' field is `true'. This |
10023 | instructs the WM to set the input focus automatically for | |
10024 | Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS | |
10025 | tells the WM to send us a ClientMessage WM_TAKE_FOCUS after | |
10026 | it has set the focus. So, XSetInputFocus below is not | |
10027 | needed. | |
10028 | ||
10029 | The call to XSetInputFocus below has also caused trouble. In | |
10030 | cases where the XSetInputFocus done by the WM and the one | |
10031 | below are temporally close (on a fast machine), the call | |
10032 | below can generate additional FocusIn events which confuse | |
10033 | Emacs. */ | |
10034 | ||
bf7253f4 RS |
10035 | /* Since we set WM_TAKE_FOCUS, we must call |
10036 | XSetInputFocus explicitly. But not if f is null, | |
10037 | since that might be an event for a deleted frame. */ | |
7a13e894 | 10038 | if (f) |
bf7253f4 RS |
10039 | { |
10040 | Display *d = event.xclient.display; | |
10041 | /* Catch and ignore errors, in case window has been | |
10042 | iconified by a window manager such as GWM. */ | |
10043 | int count = x_catch_errors (d); | |
10044 | XSetInputFocus (d, event.xclient.window, | |
e1f6572f RS |
10045 | /* The ICCCM says this is |
10046 | the only valid choice. */ | |
10047 | RevertToParent, | |
bf7253f4 RS |
10048 | event.xclient.data.l[1]); |
10049 | /* This is needed to detect the error | |
10050 | if there is an error. */ | |
10051 | XSync (d, False); | |
10052 | x_uncatch_errors (d, count); | |
10053 | } | |
7a13e894 | 10054 | /* Not certain about handling scroll bars here */ |
f1da8f06 | 10055 | #endif /* 0 */ |
c047688c | 10056 | } |
7a13e894 RS |
10057 | else if (event.xclient.data.l[0] |
10058 | == dpyinfo->Xatom_wm_save_yourself) | |
10059 | { | |
10060 | /* Save state modify the WM_COMMAND property to | |
06a2c219 | 10061 | something which can reinstate us. This notifies |
7a13e894 RS |
10062 | the session manager, who's looking for such a |
10063 | PropertyNotify. Can restart processing when | |
06a2c219 | 10064 | a keyboard or mouse event arrives. */ |
5f30b957 JD |
10065 | /* If we have a session manager, don't set this. |
10066 | KDE will then start two Emacsen, one for the | |
10067 | session manager and one for this. */ | |
10068 | if (numchars > 0 | |
10069 | #ifdef HAVE_X_SM | |
10070 | && ! x_session_have_connection () | |
10071 | #endif | |
10072 | ) | |
7a13e894 | 10073 | { |
19126e11 KH |
10074 | f = x_top_window_to_frame (dpyinfo, |
10075 | event.xclient.window); | |
7a13e894 RS |
10076 | /* This is just so we only give real data once |
10077 | for a single Emacs process. */ | |
b86bd3dd | 10078 | if (f == SELECTED_FRAME ()) |
7a13e894 RS |
10079 | XSetCommand (FRAME_X_DISPLAY (f), |
10080 | event.xclient.window, | |
10081 | initial_argv, initial_argc); | |
f000f5c5 | 10082 | else if (f) |
7a13e894 RS |
10083 | XSetCommand (FRAME_X_DISPLAY (f), |
10084 | event.xclient.window, | |
10085 | 0, 0); | |
10086 | } | |
10087 | } | |
10088 | else if (event.xclient.data.l[0] | |
10089 | == dpyinfo->Xatom_wm_delete_window) | |
1fb20991 | 10090 | { |
19126e11 KH |
10091 | struct frame *f |
10092 | = x_any_window_to_frame (dpyinfo, | |
10093 | event.xclient.window); | |
1fb20991 | 10094 | |
7a13e894 RS |
10095 | if (f) |
10096 | { | |
10097 | if (numchars == 0) | |
10098 | abort (); | |
1fb20991 | 10099 | |
7a13e894 RS |
10100 | bufp->kind = delete_window_event; |
10101 | XSETFRAME (bufp->frame_or_window, f); | |
0f8aabe9 | 10102 | bufp->arg = Qnil; |
7a13e894 RS |
10103 | bufp++; |
10104 | ||
10105 | count += 1; | |
10106 | numchars -= 1; | |
10107 | } | |
1fb20991 | 10108 | } |
c047688c | 10109 | } |
7a13e894 RS |
10110 | else if (event.xclient.message_type |
10111 | == dpyinfo->Xatom_wm_configure_denied) | |
10112 | { | |
10113 | } | |
10114 | else if (event.xclient.message_type | |
10115 | == dpyinfo->Xatom_wm_window_moved) | |
10116 | { | |
10117 | int new_x, new_y; | |
19126e11 KH |
10118 | struct frame *f |
10119 | = x_window_to_frame (dpyinfo, event.xclient.window); | |
58769bee | 10120 | |
7a13e894 RS |
10121 | new_x = event.xclient.data.s[0]; |
10122 | new_y = event.xclient.data.s[1]; | |
1fb20991 | 10123 | |
7a13e894 RS |
10124 | if (f) |
10125 | { | |
7556890b RS |
10126 | f->output_data.x->left_pos = new_x; |
10127 | f->output_data.x->top_pos = new_y; | |
7a13e894 | 10128 | } |
1fb20991 | 10129 | } |
0fdff6bb | 10130 | #ifdef HACK_EDITRES |
7a13e894 RS |
10131 | else if (event.xclient.message_type |
10132 | == dpyinfo->Xatom_editres) | |
10133 | { | |
19126e11 KH |
10134 | struct frame *f |
10135 | = x_any_window_to_frame (dpyinfo, event.xclient.window); | |
7556890b | 10136 | _XEditResCheckMessages (f->output_data.x->widget, NULL, |
19126e11 | 10137 | &event, NULL); |
7a13e894 | 10138 | } |
0fdff6bb | 10139 | #endif /* HACK_EDITRES */ |
06a2c219 GM |
10140 | else if ((event.xclient.message_type |
10141 | == dpyinfo->Xatom_DONE) | |
10142 | || (event.xclient.message_type | |
10143 | == dpyinfo->Xatom_PAGE)) | |
10144 | { | |
10145 | /* Ghostview job completed. Kill it. We could | |
10146 | reply with "Next" if we received "Page", but we | |
10147 | currently never do because we are interested in | |
10148 | images, only, which should have 1 page. */ | |
06a2c219 GM |
10149 | Pixmap pixmap = (Pixmap) event.xclient.data.l[1]; |
10150 | struct frame *f | |
10151 | = x_window_to_frame (dpyinfo, event.xclient.window); | |
10152 | x_kill_gs_process (pixmap, f); | |
10153 | expose_frame (f, 0, 0, 0, 0); | |
10154 | } | |
10155 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
10156 | /* Scroll bar callbacks send a ClientMessage from which | |
10157 | we construct an input_event. */ | |
10158 | else if (event.xclient.message_type | |
10159 | == dpyinfo->Xatom_Scrollbar) | |
10160 | { | |
10161 | x_scroll_bar_to_input_event (&event, bufp); | |
10162 | ++bufp, ++count, --numchars; | |
10163 | goto out; | |
10164 | } | |
10165 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
10166 | else | |
10167 | goto OTHER; | |
7a13e894 RS |
10168 | } |
10169 | break; | |
dc6f92b8 | 10170 | |
7a13e894 | 10171 | case SelectionNotify: |
3afe33e7 | 10172 | #ifdef USE_X_TOOLKIT |
19126e11 | 10173 | if (! x_window_to_frame (dpyinfo, event.xselection.requestor)) |
7a13e894 | 10174 | goto OTHER; |
3afe33e7 | 10175 | #endif /* not USE_X_TOOLKIT */ |
dfcf069d | 10176 | x_handle_selection_notify (&event.xselection); |
7a13e894 | 10177 | break; |
d56a553a | 10178 | |
06a2c219 | 10179 | case SelectionClear: /* Someone has grabbed ownership. */ |
3afe33e7 | 10180 | #ifdef USE_X_TOOLKIT |
19126e11 | 10181 | if (! x_window_to_frame (dpyinfo, event.xselectionclear.window)) |
7a13e894 | 10182 | goto OTHER; |
3afe33e7 | 10183 | #endif /* USE_X_TOOLKIT */ |
7a13e894 RS |
10184 | { |
10185 | XSelectionClearEvent *eventp = (XSelectionClearEvent *) &event; | |
d56a553a | 10186 | |
7a13e894 RS |
10187 | if (numchars == 0) |
10188 | abort (); | |
d56a553a | 10189 | |
7a13e894 RS |
10190 | bufp->kind = selection_clear_event; |
10191 | SELECTION_EVENT_DISPLAY (bufp) = eventp->display; | |
10192 | SELECTION_EVENT_SELECTION (bufp) = eventp->selection; | |
10193 | SELECTION_EVENT_TIME (bufp) = eventp->time; | |
e6cbea31 | 10194 | bufp->frame_or_window = Qnil; |
0f8aabe9 | 10195 | bufp->arg = Qnil; |
7a13e894 | 10196 | bufp++; |
d56a553a | 10197 | |
7a13e894 RS |
10198 | count += 1; |
10199 | numchars -= 1; | |
10200 | } | |
10201 | break; | |
dc6f92b8 | 10202 | |
06a2c219 | 10203 | case SelectionRequest: /* Someone wants our selection. */ |
3afe33e7 | 10204 | #ifdef USE_X_TOOLKIT |
19126e11 | 10205 | if (!x_window_to_frame (dpyinfo, event.xselectionrequest.owner)) |
7a13e894 | 10206 | goto OTHER; |
3afe33e7 | 10207 | #endif /* USE_X_TOOLKIT */ |
7a13e894 | 10208 | if (x_queue_selection_requests) |
19126e11 | 10209 | x_queue_event (x_window_to_frame (dpyinfo, event.xselectionrequest.owner), |
7a13e894 RS |
10210 | &event); |
10211 | else | |
10212 | { | |
1d2b2268 GM |
10213 | XSelectionRequestEvent *eventp |
10214 | = (XSelectionRequestEvent *) &event; | |
dc6f92b8 | 10215 | |
7a13e894 RS |
10216 | if (numchars == 0) |
10217 | abort (); | |
10218 | ||
10219 | bufp->kind = selection_request_event; | |
10220 | SELECTION_EVENT_DISPLAY (bufp) = eventp->display; | |
10221 | SELECTION_EVENT_REQUESTOR (bufp) = eventp->requestor; | |
10222 | SELECTION_EVENT_SELECTION (bufp) = eventp->selection; | |
10223 | SELECTION_EVENT_TARGET (bufp) = eventp->target; | |
10224 | SELECTION_EVENT_PROPERTY (bufp) = eventp->property; | |
10225 | SELECTION_EVENT_TIME (bufp) = eventp->time; | |
e6cbea31 | 10226 | bufp->frame_or_window = Qnil; |
0f8aabe9 | 10227 | bufp->arg = Qnil; |
7a13e894 RS |
10228 | bufp++; |
10229 | ||
10230 | count += 1; | |
10231 | numchars -= 1; | |
10232 | } | |
10233 | break; | |
10234 | ||
10235 | case PropertyNotify: | |
1d2b2268 GM |
10236 | #if 0 /* This is plain wrong. In the case that we are waiting for a |
10237 | PropertyNotify used as an ACK in incremental selection | |
10238 | transfer, the property will be on the receiver's window. */ | |
10239 | #if defined USE_X_TOOLKIT | |
19126e11 | 10240 | if (!x_any_window_to_frame (dpyinfo, event.xproperty.window)) |
7a13e894 | 10241 | goto OTHER; |
1d2b2268 GM |
10242 | #endif |
10243 | #endif | |
dfcf069d | 10244 | x_handle_property_notify (&event.xproperty); |
1d2b2268 | 10245 | goto OTHER; |
dc6f92b8 | 10246 | |
7a13e894 | 10247 | case ReparentNotify: |
19126e11 | 10248 | f = x_top_window_to_frame (dpyinfo, event.xreparent.window); |
7a13e894 RS |
10249 | if (f) |
10250 | { | |
10251 | int x, y; | |
7556890b | 10252 | f->output_data.x->parent_desc = event.xreparent.parent; |
7a13e894 | 10253 | x_real_positions (f, &x, &y); |
7556890b RS |
10254 | f->output_data.x->left_pos = x; |
10255 | f->output_data.x->top_pos = y; | |
7a13e894 RS |
10256 | } |
10257 | break; | |
3bd330d4 | 10258 | |
7a13e894 | 10259 | case Expose: |
19126e11 | 10260 | f = x_window_to_frame (dpyinfo, event.xexpose.window); |
7a13e894 | 10261 | if (f) |
dc6f92b8 | 10262 | { |
d0fa3e56 EZ |
10263 | x_check_fullscreen (f); |
10264 | ||
7a13e894 RS |
10265 | if (f->async_visible == 0) |
10266 | { | |
10267 | f->async_visible = 1; | |
10268 | f->async_iconified = 0; | |
06c488fd | 10269 | f->output_data.x->has_been_visible = 1; |
7a13e894 RS |
10270 | SET_FRAME_GARBAGED (f); |
10271 | } | |
10272 | else | |
06a2c219 GM |
10273 | expose_frame (x_window_to_frame (dpyinfo, |
10274 | event.xexpose.window), | |
10275 | event.xexpose.x, event.xexpose.y, | |
10276 | event.xexpose.width, event.xexpose.height); | |
dc6f92b8 JB |
10277 | } |
10278 | else | |
7a13e894 | 10279 | { |
12949a7f EZ |
10280 | #ifndef USE_TOOLKIT_SCROLL_BARS |
10281 | struct scroll_bar *bar; | |
10282 | #endif | |
01f67d2c | 10283 | #if defined USE_LUCID |
c95fc5f1 GM |
10284 | /* Submenus of the Lucid menu bar aren't widgets |
10285 | themselves, so there's no way to dispatch events | |
10286 | to them. Recognize this case separately. */ | |
10287 | { | |
10288 | Widget widget | |
10289 | = x_window_to_menu_bar (event.xexpose.window); | |
10290 | if (widget) | |
10291 | xlwmenu_redisplay (widget); | |
10292 | } | |
01f67d2c PJ |
10293 | #endif /* USE_LUCID */ |
10294 | ||
06a2c219 GM |
10295 | #ifdef USE_TOOLKIT_SCROLL_BARS |
10296 | /* Dispatch event to the widget. */ | |
10297 | goto OTHER; | |
10298 | #else /* not USE_TOOLKIT_SCROLL_BARS */ | |
12949a7f | 10299 | bar = x_window_to_scroll_bar (event.xexpose.window); |
58769bee | 10300 | |
7a13e894 RS |
10301 | if (bar) |
10302 | x_scroll_bar_expose (bar, &event); | |
3afe33e7 | 10303 | #ifdef USE_X_TOOLKIT |
7a13e894 RS |
10304 | else |
10305 | goto OTHER; | |
3afe33e7 | 10306 | #endif /* USE_X_TOOLKIT */ |
06a2c219 | 10307 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
7a13e894 RS |
10308 | } |
10309 | break; | |
dc6f92b8 | 10310 | |
7a13e894 | 10311 | case GraphicsExpose: /* This occurs when an XCopyArea's |
d624284c PJ |
10312 | source area was obscured or not |
10313 | available. */ | |
19126e11 | 10314 | f = x_window_to_frame (dpyinfo, event.xgraphicsexpose.drawable); |
7a13e894 RS |
10315 | if (f) |
10316 | { | |
06a2c219 GM |
10317 | expose_frame (f, |
10318 | event.xgraphicsexpose.x, event.xgraphicsexpose.y, | |
10319 | event.xgraphicsexpose.width, | |
10320 | event.xgraphicsexpose.height); | |
7a13e894 | 10321 | } |
3afe33e7 | 10322 | #ifdef USE_X_TOOLKIT |
7a13e894 RS |
10323 | else |
10324 | goto OTHER; | |
3afe33e7 | 10325 | #endif /* USE_X_TOOLKIT */ |
7a13e894 | 10326 | break; |
dc6f92b8 | 10327 | |
7a13e894 | 10328 | case NoExpose: /* This occurs when an XCopyArea's |
06a2c219 | 10329 | source area was completely |
d624284c | 10330 | available. */ |
7a13e894 | 10331 | break; |
dc6f92b8 | 10332 | |
7a13e894 | 10333 | case UnmapNotify: |
06a2c219 GM |
10334 | /* Redo the mouse-highlight after the tooltip has gone. */ |
10335 | if (event.xmap.window == tip_window) | |
10336 | { | |
10337 | tip_window = 0; | |
10338 | redo_mouse_highlight (); | |
10339 | } | |
10340 | ||
91ea2a7a | 10341 | f = x_top_window_to_frame (dpyinfo, event.xunmap.window); |
7a13e894 | 10342 | if (f) /* F may no longer exist if |
d624284c | 10343 | the frame was deleted. */ |
7a13e894 RS |
10344 | { |
10345 | /* While a frame is unmapped, display generation is | |
10346 | disabled; you don't want to spend time updating a | |
10347 | display that won't ever be seen. */ | |
10348 | f->async_visible = 0; | |
10349 | /* We can't distinguish, from the event, whether the window | |
10350 | has become iconified or invisible. So assume, if it | |
10351 | was previously visible, than now it is iconified. | |
1aa6072f RS |
10352 | But x_make_frame_invisible clears both |
10353 | the visible flag and the iconified flag; | |
10354 | and that way, we know the window is not iconified now. */ | |
7a13e894 | 10355 | if (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)) |
1aa6072f RS |
10356 | { |
10357 | f->async_iconified = 1; | |
bddd097c | 10358 | |
1aa6072f RS |
10359 | bufp->kind = iconify_event; |
10360 | XSETFRAME (bufp->frame_or_window, f); | |
0f8aabe9 | 10361 | bufp->arg = Qnil; |
1aa6072f RS |
10362 | bufp++; |
10363 | count++; | |
10364 | numchars--; | |
10365 | } | |
7a13e894 | 10366 | } |
7a13e894 | 10367 | goto OTHER; |
dc6f92b8 | 10368 | |
7a13e894 | 10369 | case MapNotify: |
06a2c219 GM |
10370 | if (event.xmap.window == tip_window) |
10371 | /* The tooltip has been drawn already. Avoid | |
10372 | the SET_FRAME_GARBAGED below. */ | |
10373 | goto OTHER; | |
10374 | ||
10375 | /* We use x_top_window_to_frame because map events can | |
10376 | come for sub-windows and they don't mean that the | |
10377 | frame is visible. */ | |
19126e11 | 10378 | f = x_top_window_to_frame (dpyinfo, event.xmap.window); |
7a13e894 RS |
10379 | if (f) |
10380 | { | |
10381 | f->async_visible = 1; | |
10382 | f->async_iconified = 0; | |
06c488fd | 10383 | f->output_data.x->has_been_visible = 1; |
dc6f92b8 | 10384 | |
7a13e894 RS |
10385 | /* wait_reading_process_input will notice this and update |
10386 | the frame's display structures. */ | |
10387 | SET_FRAME_GARBAGED (f); | |
bddd097c | 10388 | |
d806e720 RS |
10389 | if (f->iconified) |
10390 | { | |
10391 | bufp->kind = deiconify_event; | |
10392 | XSETFRAME (bufp->frame_or_window, f); | |
0f8aabe9 | 10393 | bufp->arg = Qnil; |
d806e720 RS |
10394 | bufp++; |
10395 | count++; | |
10396 | numchars--; | |
10397 | } | |
e73ec6fa | 10398 | else if (! NILP (Vframe_list) |
8e713be6 | 10399 | && ! NILP (XCDR (Vframe_list))) |
78aa2ba5 KH |
10400 | /* Force a redisplay sooner or later |
10401 | to update the frame titles | |
10402 | in case this is the second frame. */ | |
10403 | record_asynch_buffer_change (); | |
7a13e894 | 10404 | } |
7a13e894 | 10405 | goto OTHER; |
dc6f92b8 | 10406 | |
7a13e894 | 10407 | case KeyPress: |
2a793c0c PJ |
10408 | |
10409 | /* Dispatch KeyPress events when in menu. */ | |
10410 | if (popup_activated_flag) | |
10411 | goto OTHER; | |
10412 | ||
19126e11 | 10413 | f = x_any_window_to_frame (dpyinfo, event.xkey.window); |
f451eb13 | 10414 | |
66301061 KS |
10415 | if (!dpyinfo->mouse_face_hidden && INTEGERP (Vmouse_highlight)) |
10416 | { | |
10417 | dpyinfo->mouse_face_hidden = 1; | |
10418 | clear_mouse_face (dpyinfo); | |
10419 | } | |
10420 | ||
eccc05db | 10421 | #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS |
06a2c219 GM |
10422 | if (f == 0) |
10423 | { | |
2564ea1b GM |
10424 | /* Scroll bars consume key events, but we want |
10425 | the keys to go to the scroll bar's frame. */ | |
06a2c219 GM |
10426 | Widget widget = XtWindowToWidget (dpyinfo->display, |
10427 | event.xkey.window); | |
10428 | if (widget && XmIsScrollBar (widget)) | |
10429 | { | |
10430 | widget = XtParent (widget); | |
10431 | f = x_any_window_to_frame (dpyinfo, XtWindow (widget)); | |
10432 | } | |
10433 | } | |
eccc05db | 10434 | #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */ |
06a2c219 | 10435 | |
7a13e894 RS |
10436 | if (f != 0) |
10437 | { | |
10438 | KeySym keysym, orig_keysym; | |
379b5ac0 KH |
10439 | /* al%imercury@uunet.uu.net says that making this 81 |
10440 | instead of 80 fixed a bug whereby meta chars made | |
10441 | his Emacs hang. | |
10442 | ||
10443 | It seems that some version of XmbLookupString has | |
10444 | a bug of not returning XBufferOverflow in | |
10445 | status_return even if the input is too long to | |
10446 | fit in 81 bytes. So, we must prepare sufficient | |
10447 | bytes for copy_buffer. 513 bytes (256 chars for | |
6c4a22e6 | 10448 | two-byte character set) seems to be a fairly good |
379b5ac0 KH |
10449 | approximation. -- 2000.8.10 handa@etl.go.jp */ |
10450 | unsigned char copy_buffer[513]; | |
10451 | unsigned char *copy_bufptr = copy_buffer; | |
10452 | int copy_bufsiz = sizeof (copy_buffer); | |
7a13e894 | 10453 | int modifiers; |
c997eae5 | 10454 | Lisp_Object coding_system = Qlatin_1; |
64bb1782 | 10455 | |
7a13e894 RS |
10456 | event.xkey.state |
10457 | |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f), | |
10458 | extra_keyboard_modifiers); | |
10459 | modifiers = event.xkey.state; | |
3a2712f9 | 10460 | |
7a13e894 | 10461 | /* This will have to go some day... */ |
752a043f | 10462 | |
7a13e894 RS |
10463 | /* make_lispy_event turns chars into control chars. |
10464 | Don't do it here because XLookupString is too eager. */ | |
10465 | event.xkey.state &= ~ControlMask; | |
5d46f928 RS |
10466 | event.xkey.state &= ~(dpyinfo->meta_mod_mask |
10467 | | dpyinfo->super_mod_mask | |
10468 | | dpyinfo->hyper_mod_mask | |
10469 | | dpyinfo->alt_mod_mask); | |
10470 | ||
1cf4a0d1 RS |
10471 | /* In case Meta is ComposeCharacter, |
10472 | clear its status. According to Markus Ehrnsperger | |
10473 | Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de | |
10474 | this enables ComposeCharacter to work whether or | |
10475 | not it is combined with Meta. */ | |
10476 | if (modifiers & dpyinfo->meta_mod_mask) | |
10477 | bzero (&compose_status, sizeof (compose_status)); | |
10478 | ||
6c183ba5 RS |
10479 | #ifdef HAVE_X_I18N |
10480 | if (FRAME_XIC (f)) | |
10481 | { | |
f5d11644 GM |
10482 | Status status_return; |
10483 | ||
c997eae5 | 10484 | coding_system = Vlocale_coding_system; |
6c183ba5 | 10485 | nbytes = XmbLookupString (FRAME_XIC (f), |
f5d11644 GM |
10486 | &event.xkey, copy_bufptr, |
10487 | copy_bufsiz, &keysym, | |
6c183ba5 | 10488 | &status_return); |
f5d11644 GM |
10489 | if (status_return == XBufferOverflow) |
10490 | { | |
10491 | copy_bufsiz = nbytes + 1; | |
10492 | copy_bufptr = (char *) alloca (copy_bufsiz); | |
10493 | nbytes = XmbLookupString (FRAME_XIC (f), | |
10494 | &event.xkey, copy_bufptr, | |
10495 | copy_bufsiz, &keysym, | |
10496 | &status_return); | |
10497 | } | |
c997eae5 SM |
10498 | #ifdef X_HAVE_UTF8_STRING |
10499 | else if (status_return == XLookupKeySym) | |
10500 | { /* Try again but with utf-8. */ | |
10501 | coding_system = Qutf_8; | |
10502 | nbytes = Xutf8LookupString (FRAME_XIC (f), | |
10503 | &event.xkey, copy_bufptr, | |
10504 | copy_bufsiz, &keysym, | |
10505 | &status_return); | |
10506 | if (status_return == XBufferOverflow) | |
10507 | { | |
10508 | copy_bufsiz = nbytes + 1; | |
10509 | copy_bufptr = (char *) alloca (copy_bufsiz); | |
10510 | nbytes = Xutf8LookupString (FRAME_XIC (f), | |
10511 | &event.xkey, | |
10512 | copy_bufptr, | |
10513 | copy_bufsiz, &keysym, | |
10514 | &status_return); | |
10515 | } | |
10516 | } | |
10517 | #endif | |
f5d11644 | 10518 | |
1decb680 PE |
10519 | if (status_return == XLookupNone) |
10520 | break; | |
10521 | else if (status_return == XLookupChars) | |
fdd9d55e GM |
10522 | { |
10523 | keysym = NoSymbol; | |
10524 | modifiers = 0; | |
10525 | } | |
1decb680 PE |
10526 | else if (status_return != XLookupKeySym |
10527 | && status_return != XLookupBoth) | |
10528 | abort (); | |
6c183ba5 RS |
10529 | } |
10530 | else | |
379b5ac0 KH |
10531 | nbytes = XLookupString (&event.xkey, copy_bufptr, |
10532 | copy_bufsiz, &keysym, | |
10533 | &compose_status); | |
6c183ba5 | 10534 | #else |
379b5ac0 KH |
10535 | nbytes = XLookupString (&event.xkey, copy_bufptr, |
10536 | copy_bufsiz, &keysym, | |
10537 | &compose_status); | |
6c183ba5 | 10538 | #endif |
dc6f92b8 | 10539 | |
7a13e894 | 10540 | orig_keysym = keysym; |
55123275 | 10541 | |
7a13e894 RS |
10542 | if (numchars > 1) |
10543 | { | |
10544 | if (((keysym >= XK_BackSpace && keysym <= XK_Escape) | |
10545 | || keysym == XK_Delete | |
1097aea0 | 10546 | #ifdef XK_ISO_Left_Tab |
441affdb | 10547 | || (keysym >= XK_ISO_Left_Tab && keysym <= XK_ISO_Enter) |
1097aea0 | 10548 | #endif |
852bff8f | 10549 | || (keysym >= XK_Kanji && keysym <= XK_Eisu_toggle) |
7a13e894 RS |
10550 | || IsCursorKey (keysym) /* 0xff50 <= x < 0xff60 */ |
10551 | || IsMiscFunctionKey (keysym) /* 0xff60 <= x < VARIES */ | |
c34790e0 | 10552 | #ifdef HPUX |
7a13e894 RS |
10553 | /* This recognizes the "extended function keys". |
10554 | It seems there's no cleaner way. | |
10555 | Test IsModifierKey to avoid handling mode_switch | |
10556 | incorrectly. */ | |
10557 | || ((unsigned) (keysym) >= XK_Select | |
10558 | && (unsigned)(keysym) < XK_KP_Space) | |
69388238 RS |
10559 | #endif |
10560 | #ifdef XK_dead_circumflex | |
7a13e894 | 10561 | || orig_keysym == XK_dead_circumflex |
69388238 RS |
10562 | #endif |
10563 | #ifdef XK_dead_grave | |
7a13e894 | 10564 | || orig_keysym == XK_dead_grave |
69388238 RS |
10565 | #endif |
10566 | #ifdef XK_dead_tilde | |
7a13e894 | 10567 | || orig_keysym == XK_dead_tilde |
69388238 RS |
10568 | #endif |
10569 | #ifdef XK_dead_diaeresis | |
7a13e894 | 10570 | || orig_keysym == XK_dead_diaeresis |
69388238 RS |
10571 | #endif |
10572 | #ifdef XK_dead_macron | |
7a13e894 | 10573 | || orig_keysym == XK_dead_macron |
69388238 RS |
10574 | #endif |
10575 | #ifdef XK_dead_degree | |
7a13e894 | 10576 | || orig_keysym == XK_dead_degree |
69388238 RS |
10577 | #endif |
10578 | #ifdef XK_dead_acute | |
7a13e894 | 10579 | || orig_keysym == XK_dead_acute |
69388238 RS |
10580 | #endif |
10581 | #ifdef XK_dead_cedilla | |
7a13e894 | 10582 | || orig_keysym == XK_dead_cedilla |
69388238 RS |
10583 | #endif |
10584 | #ifdef XK_dead_breve | |
7a13e894 | 10585 | || orig_keysym == XK_dead_breve |
69388238 RS |
10586 | #endif |
10587 | #ifdef XK_dead_ogonek | |
7a13e894 | 10588 | || orig_keysym == XK_dead_ogonek |
69388238 RS |
10589 | #endif |
10590 | #ifdef XK_dead_caron | |
7a13e894 | 10591 | || orig_keysym == XK_dead_caron |
69388238 RS |
10592 | #endif |
10593 | #ifdef XK_dead_doubleacute | |
7a13e894 | 10594 | || orig_keysym == XK_dead_doubleacute |
69388238 RS |
10595 | #endif |
10596 | #ifdef XK_dead_abovedot | |
7a13e894 | 10597 | || orig_keysym == XK_dead_abovedot |
c34790e0 | 10598 | #endif |
7a13e894 RS |
10599 | || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */ |
10600 | || IsFunctionKey (keysym) /* 0xffbe <= x < 0xffe1 */ | |
10601 | /* Any "vendor-specific" key is ok. */ | |
f0e299de GM |
10602 | || (orig_keysym & (1 << 28)) |
10603 | || (keysym != NoSymbol && nbytes == 0)) | |
7a13e894 | 10604 | && ! (IsModifierKey (orig_keysym) |
7719aa06 RS |
10605 | #ifndef HAVE_X11R5 |
10606 | #ifdef XK_Mode_switch | |
7a13e894 | 10607 | || ((unsigned)(orig_keysym) == XK_Mode_switch) |
7719aa06 RS |
10608 | #endif |
10609 | #ifdef XK_Num_Lock | |
7a13e894 | 10610 | || ((unsigned)(orig_keysym) == XK_Num_Lock) |
7719aa06 RS |
10611 | #endif |
10612 | #endif /* not HAVE_X11R5 */ | |
7ef18d79 EZ |
10613 | /* The symbols from XK_ISO_Lock to |
10614 | XK_ISO_Last_Group_Lock doesn't have real | |
10615 | modifiers but should be treated similarly | |
10616 | to Mode_switch by Emacs. */ | |
10617 | #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock | |
10618 | || ((unsigned)(orig_keysym) >= XK_ISO_Lock | |
10619 | && (unsigned)(orig_keysym) <= XK_ISO_Last_Group_Lock) | |
10620 | #endif | |
7a13e894 | 10621 | )) |
dc6f92b8 | 10622 | { |
10e6549c RS |
10623 | if (temp_index == sizeof temp_buffer / sizeof (short)) |
10624 | temp_index = 0; | |
7a13e894 RS |
10625 | temp_buffer[temp_index++] = keysym; |
10626 | bufp->kind = non_ascii_keystroke; | |
10627 | bufp->code = keysym; | |
e0c1aef2 | 10628 | XSETFRAME (bufp->frame_or_window, f); |
0f8aabe9 | 10629 | bufp->arg = Qnil; |
334208b7 RS |
10630 | bufp->modifiers |
10631 | = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), | |
10632 | modifiers); | |
1113d9db | 10633 | bufp->timestamp = event.xkey.time; |
dc6f92b8 | 10634 | bufp++; |
7a13e894 RS |
10635 | count++; |
10636 | numchars--; | |
dc6f92b8 | 10637 | } |
7a13e894 RS |
10638 | else if (numchars > nbytes) |
10639 | { | |
10640 | register int i; | |
379b5ac0 | 10641 | register int c; |
379b5ac0 | 10642 | int nchars, len; |
7a13e894 | 10643 | |
c997eae5 SM |
10644 | /* The input should be decoded with `coding_system' |
10645 | which depends on which X*LookupString function | |
10646 | we used just above and the locale. */ | |
10647 | setup_coding_system (coding_system, &coding); | |
10648 | coding.src_multibyte = 0; | |
10649 | coding.dst_multibyte = 1; | |
10650 | /* The input is converted to events, thus we can't | |
10651 | handle composition. Anyway, there's no XIM that | |
10652 | gives us composition information. */ | |
10653 | coding.composing = COMPOSITION_DISABLED; | |
10654 | ||
7a13e894 RS |
10655 | for (i = 0; i < nbytes; i++) |
10656 | { | |
379b5ac0 KH |
10657 | if (temp_index == (sizeof temp_buffer |
10658 | / sizeof (short))) | |
7a13e894 | 10659 | temp_index = 0; |
379b5ac0 KH |
10660 | temp_buffer[temp_index++] = copy_bufptr[i]; |
10661 | } | |
10662 | ||
c997eae5 SM |
10663 | { |
10664 | /* Decode the input data. */ | |
10665 | int require; | |
10666 | unsigned char *p; | |
10667 | ||
10668 | require = decoding_buffer_size (&coding, nbytes); | |
10669 | p = (unsigned char *) alloca (require); | |
10670 | coding.mode |= CODING_MODE_LAST_BLOCK; | |
10671 | decode_coding (&coding, copy_bufptr, p, | |
10672 | nbytes, require); | |
10673 | nbytes = coding.produced; | |
10674 | nchars = coding.produced_char; | |
10675 | copy_bufptr = p; | |
10676 | } | |
379b5ac0 KH |
10677 | |
10678 | /* Convert the input data to a sequence of | |
10679 | character events. */ | |
10680 | for (i = 0; i < nbytes; i += len) | |
10681 | { | |
fee2aedc GM |
10682 | if (nchars == nbytes) |
10683 | c = copy_bufptr[i], len = 1; | |
10684 | else | |
10685 | c = STRING_CHAR_AND_LENGTH (copy_bufptr + i, | |
10686 | nbytes - i, len); | |
10687 | ||
379b5ac0 KH |
10688 | bufp->kind = (SINGLE_BYTE_CHAR_P (c) |
10689 | ? ascii_keystroke | |
10690 | : multibyte_char_keystroke); | |
10691 | bufp->code = c; | |
7a13e894 | 10692 | XSETFRAME (bufp->frame_or_window, f); |
0f8aabe9 | 10693 | bufp->arg = Qnil; |
7a13e894 RS |
10694 | bufp->modifiers |
10695 | = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), | |
10696 | modifiers); | |
10697 | bufp->timestamp = event.xkey.time; | |
10698 | bufp++; | |
10699 | } | |
10700 | ||
379b5ac0 KH |
10701 | count += nchars; |
10702 | numchars -= nchars; | |
1decb680 PE |
10703 | |
10704 | if (keysym == NoSymbol) | |
10705 | break; | |
7a13e894 RS |
10706 | } |
10707 | else | |
10708 | abort (); | |
dc6f92b8 | 10709 | } |
10e6549c RS |
10710 | else |
10711 | abort (); | |
dc6f92b8 | 10712 | } |
59ddecde GM |
10713 | #ifdef HAVE_X_I18N |
10714 | /* Don't dispatch this event since XtDispatchEvent calls | |
10715 | XFilterEvent, and two calls in a row may freeze the | |
10716 | client. */ | |
10717 | break; | |
10718 | #else | |
717ca130 | 10719 | goto OTHER; |
59ddecde | 10720 | #endif |
f451eb13 | 10721 | |
f5d11644 | 10722 | case KeyRelease: |
59ddecde GM |
10723 | #ifdef HAVE_X_I18N |
10724 | /* Don't dispatch this event since XtDispatchEvent calls | |
10725 | XFilterEvent, and two calls in a row may freeze the | |
10726 | client. */ | |
10727 | break; | |
10728 | #else | |
f5d11644 | 10729 | goto OTHER; |
59ddecde | 10730 | #endif |
f5d11644 | 10731 | |
7a13e894 | 10732 | /* Here's a possible interpretation of the whole |
06a2c219 GM |
10733 | FocusIn-EnterNotify FocusOut-LeaveNotify mess. If |
10734 | you get a FocusIn event, you have to get a FocusOut | |
10735 | event before you relinquish the focus. If you | |
10736 | haven't received a FocusIn event, then a mere | |
10737 | LeaveNotify is enough to free you. */ | |
f451eb13 | 10738 | |
7a13e894 | 10739 | case EnterNotify: |
06a2c219 | 10740 | { |
06a2c219 GM |
10741 | f = x_any_window_to_frame (dpyinfo, event.xcrossing.window); |
10742 | ||
2c850e26 | 10743 | #if 0 |
582c60f8 | 10744 | if (event.xcrossing.focus) |
06a2c219 GM |
10745 | { |
10746 | /* Avoid nasty pop/raise loops. */ | |
10747 | if (f && (!(f->auto_raise) | |
10748 | || !(f->auto_lower) | |
10749 | || (event.xcrossing.time - enter_timestamp) > 500)) | |
10750 | { | |
10751 | x_new_focus_frame (dpyinfo, f); | |
10752 | enter_timestamp = event.xcrossing.time; | |
10753 | } | |
10754 | } | |
10755 | else if (f == dpyinfo->x_focus_frame) | |
10756 | x_new_focus_frame (dpyinfo, 0); | |
2c850e26 RS |
10757 | #endif |
10758 | ||
06a2c219 GM |
10759 | /* EnterNotify counts as mouse movement, |
10760 | so update things that depend on mouse position. */ | |
2533c408 | 10761 | if (f && !f->output_data.x->hourglass_p) |
06a2c219 GM |
10762 | note_mouse_movement (f, &event.xmotion); |
10763 | goto OTHER; | |
10764 | } | |
dc6f92b8 | 10765 | |
7a13e894 | 10766 | case FocusIn: |
19126e11 | 10767 | f = x_any_window_to_frame (dpyinfo, event.xfocus.window); |
7a13e894 | 10768 | if (event.xfocus.detail != NotifyPointer) |
0f941935 | 10769 | dpyinfo->x_focus_event_frame = f; |
7a13e894 | 10770 | if (f) |
eb72635f GM |
10771 | { |
10772 | x_new_focus_frame (dpyinfo, f); | |
10773 | ||
10774 | /* Don't stop displaying the initial startup message | |
10775 | for a switch-frame event we don't need. */ | |
10776 | if (GC_NILP (Vterminal_frame) | |
10777 | && GC_CONSP (Vframe_list) | |
10778 | && !GC_NILP (XCDR (Vframe_list))) | |
10779 | { | |
10780 | bufp->kind = FOCUS_IN_EVENT; | |
10781 | XSETFRAME (bufp->frame_or_window, f); | |
0f8aabe9 | 10782 | bufp->arg = Qnil; |
eb72635f GM |
10783 | ++bufp, ++count, --numchars; |
10784 | } | |
10785 | } | |
f9e24cb9 | 10786 | |
6c183ba5 RS |
10787 | #ifdef HAVE_X_I18N |
10788 | if (f && FRAME_XIC (f)) | |
10789 | XSetICFocus (FRAME_XIC (f)); | |
10790 | #endif | |
10791 | ||
7a13e894 | 10792 | goto OTHER; |
10c5e63d | 10793 | |
7a13e894 | 10794 | case LeaveNotify: |
19126e11 | 10795 | f = x_top_window_to_frame (dpyinfo, event.xcrossing.window); |
7a13e894 | 10796 | if (f) |
10c5e63d | 10797 | { |
7a13e894 | 10798 | if (f == dpyinfo->mouse_face_mouse_frame) |
06a2c219 GM |
10799 | { |
10800 | /* If we move outside the frame, then we're | |
10801 | certainly no longer on any text in the frame. */ | |
10802 | clear_mouse_face (dpyinfo); | |
10803 | dpyinfo->mouse_face_mouse_frame = 0; | |
10804 | } | |
10805 | ||
10806 | /* Generate a nil HELP_EVENT to cancel a help-echo. | |
10807 | Do it only if there's something to cancel. | |
10808 | Otherwise, the startup message is cleared when | |
10809 | the mouse leaves the frame. */ | |
10810 | if (any_help_event_p) | |
10811 | { | |
be010514 GM |
10812 | Lisp_Object frame; |
10813 | int n; | |
10814 | ||
06a2c219 | 10815 | XSETFRAME (frame, f); |
82c5d67a | 10816 | help_echo = Qnil; |
5ab2570d GM |
10817 | n = gen_help_event (bufp, numchars, |
10818 | Qnil, frame, Qnil, Qnil, 0); | |
be010514 | 10819 | bufp += n, count += n, numchars -= n; |
06a2c219 | 10820 | } |
7a13e894 | 10821 | |
2c850e26 | 10822 | #if 0 |
582c60f8 | 10823 | if (event.xcrossing.focus) |
0f941935 | 10824 | x_mouse_leave (dpyinfo); |
10c5e63d | 10825 | else |
7a13e894 | 10826 | { |
0f941935 KH |
10827 | if (f == dpyinfo->x_focus_event_frame) |
10828 | dpyinfo->x_focus_event_frame = 0; | |
140d6643 | 10829 | if (f == dpyinfo->x_focus_frame) |
0f941935 | 10830 | x_new_focus_frame (dpyinfo, 0); |
7a13e894 | 10831 | } |
2c850e26 | 10832 | #endif |
10c5e63d | 10833 | } |
7a13e894 | 10834 | goto OTHER; |
dc6f92b8 | 10835 | |
7a13e894 | 10836 | case FocusOut: |
19126e11 | 10837 | f = x_any_window_to_frame (dpyinfo, event.xfocus.window); |
7a13e894 | 10838 | if (event.xfocus.detail != NotifyPointer |
0f941935 KH |
10839 | && f == dpyinfo->x_focus_event_frame) |
10840 | dpyinfo->x_focus_event_frame = 0; | |
10841 | if (f && f == dpyinfo->x_focus_frame) | |
10842 | x_new_focus_frame (dpyinfo, 0); | |
f9e24cb9 | 10843 | |
6c183ba5 RS |
10844 | #ifdef HAVE_X_I18N |
10845 | if (f && FRAME_XIC (f)) | |
10846 | XUnsetICFocus (FRAME_XIC (f)); | |
10847 | #endif | |
10848 | ||
7a13e894 | 10849 | goto OTHER; |
dc6f92b8 | 10850 | |
7a13e894 | 10851 | case MotionNotify: |
dc6f92b8 | 10852 | { |
06a2c219 | 10853 | previous_help_echo = help_echo; |
7cea38bc | 10854 | help_echo = help_echo_object = help_echo_window = Qnil; |
be010514 | 10855 | help_echo_pos = -1; |
06a2c219 | 10856 | |
7a13e894 RS |
10857 | if (dpyinfo->grabbed && last_mouse_frame |
10858 | && FRAME_LIVE_P (last_mouse_frame)) | |
10859 | f = last_mouse_frame; | |
10860 | else | |
19126e11 | 10861 | f = x_window_to_frame (dpyinfo, event.xmotion.window); |
06a2c219 | 10862 | |
66301061 KS |
10863 | if (dpyinfo->mouse_face_hidden) |
10864 | { | |
10865 | dpyinfo->mouse_face_hidden = 0; | |
10866 | clear_mouse_face (dpyinfo); | |
10867 | } | |
10868 | ||
7a13e894 | 10869 | if (f) |
5bc62483 PJ |
10870 | { |
10871 | ||
10872 | /* Generate SELECT_WINDOW_EVENTs when needed. */ | |
ee8ceff8 | 10873 | if (mouse_autoselect_window) |
5bc62483 PJ |
10874 | { |
10875 | Lisp_Object window; | |
10876 | int area; | |
10877 | ||
10878 | window = window_from_coordinates (f, | |
0fc8f792 | 10879 | event.xmotion.x, event.xmotion.y, |
5bc62483 PJ |
10880 | &area, 0); |
10881 | ||
10882 | /* Window will be selected only when it is not selected now and | |
10883 | last mouse movement event was not in it. Minibuffer window | |
10884 | will be selected iff it is active. */ | |
ce1295bd PJ |
10885 | if (WINDOWP(window) |
10886 | && !EQ (window, last_window) | |
5bc62483 PJ |
10887 | && !EQ (window, selected_window) |
10888 | && numchars > 0) | |
10889 | { | |
10890 | bufp->kind = SELECT_WINDOW_EVENT; | |
10891 | bufp->frame_or_window = window; | |
10892 | bufp->arg = Qnil; | |
10893 | ++bufp, ++count, --numchars; | |
10894 | } | |
10895 | ||
10896 | last_window=window; | |
10897 | } | |
10898 | note_mouse_movement (f, &event.xmotion); | |
10899 | } | |
7a13e894 RS |
10900 | else |
10901 | { | |
e88b3c50 | 10902 | #ifndef USE_TOOLKIT_SCROLL_BARS |
7a13e894 RS |
10903 | struct scroll_bar *bar |
10904 | = x_window_to_scroll_bar (event.xmotion.window); | |
f451eb13 | 10905 | |
7a13e894 RS |
10906 | if (bar) |
10907 | x_scroll_bar_note_movement (bar, &event); | |
e88b3c50 | 10908 | #endif /* USE_TOOLKIT_SCROLL_BARS */ |
b8009dd1 | 10909 | |
06a2c219 GM |
10910 | /* If we move outside the frame, then we're |
10911 | certainly no longer on any text in the frame. */ | |
7a13e894 RS |
10912 | clear_mouse_face (dpyinfo); |
10913 | } | |
06a2c219 GM |
10914 | |
10915 | /* If the contents of the global variable help_echo | |
10916 | has changed, generate a HELP_EVENT. */ | |
b7e80413 SM |
10917 | if (!NILP (help_echo) |
10918 | || !NILP (previous_help_echo)) | |
06a2c219 GM |
10919 | { |
10920 | Lisp_Object frame; | |
be010514 | 10921 | int n; |
06a2c219 GM |
10922 | |
10923 | if (f) | |
10924 | XSETFRAME (frame, f); | |
10925 | else | |
10926 | frame = Qnil; | |
10927 | ||
10928 | any_help_event_p = 1; | |
5ab2570d | 10929 | n = gen_help_event (bufp, numchars, help_echo, frame, |
7cea38bc GM |
10930 | help_echo_window, help_echo_object, |
10931 | help_echo_pos); | |
be010514 | 10932 | bufp += n, count += n, numchars -= n; |
06a2c219 GM |
10933 | } |
10934 | ||
10935 | goto OTHER; | |
dc6f92b8 | 10936 | } |
dc6f92b8 | 10937 | |
7a13e894 | 10938 | case ConfigureNotify: |
9829ddba RS |
10939 | f = x_top_window_to_frame (dpyinfo, event.xconfigure.window); |
10940 | if (f) | |
af395ec1 | 10941 | { |
7a4bce14 | 10942 | #ifndef USE_X_TOOLKIT |
d0fa3e56 EZ |
10943 | /* If there is a pending resize for fullscreen, don't |
10944 | do this one, the right one will come later. | |
10945 | The toolkit version doesn't seem to need this, but we | |
7a4bce14 | 10946 | need to reset it below. */ |
d0fa3e56 EZ |
10947 | int dont_resize = |
10948 | ((f->output_data.x->want_fullscreen & FULLSCREEN_WAIT) | |
10949 | && FRAME_NEW_WIDTH (f) != 0); | |
bf1b7b30 KH |
10950 | int rows = PIXEL_TO_CHAR_HEIGHT (f, event.xconfigure.height); |
10951 | int columns = PIXEL_TO_CHAR_WIDTH (f, event.xconfigure.width); | |
d0fa3e56 EZ |
10952 | if (dont_resize) |
10953 | goto OTHER; | |
5c187dee | 10954 | |
2d7fc7e8 RS |
10955 | /* In the toolkit version, change_frame_size |
10956 | is called by the code that handles resizing | |
10957 | of the EmacsFrame widget. */ | |
7a13e894 | 10958 | |
7a13e894 RS |
10959 | /* Even if the number of character rows and columns has |
10960 | not changed, the font size may have changed, so we need | |
10961 | to check the pixel dimensions as well. */ | |
10962 | if (columns != f->width | |
10963 | || rows != f->height | |
7556890b RS |
10964 | || event.xconfigure.width != f->output_data.x->pixel_width |
10965 | || event.xconfigure.height != f->output_data.x->pixel_height) | |
7a13e894 | 10966 | { |
7d1e984f | 10967 | change_frame_size (f, rows, columns, 0, 1, 0); |
7a13e894 | 10968 | SET_FRAME_GARBAGED (f); |
e687d06e | 10969 | cancel_mouse_face (f); |
7a13e894 | 10970 | } |
2d7fc7e8 | 10971 | #endif |
af395ec1 | 10972 | |
7556890b RS |
10973 | f->output_data.x->pixel_width = event.xconfigure.width; |
10974 | f->output_data.x->pixel_height = event.xconfigure.height; | |
7a13e894 RS |
10975 | |
10976 | /* What we have now is the position of Emacs's own window. | |
10977 | Convert that to the position of the window manager window. */ | |
dcb07ae9 RS |
10978 | x_real_positions (f, &f->output_data.x->left_pos, |
10979 | &f->output_data.x->top_pos); | |
10980 | ||
d0fa3e56 EZ |
10981 | x_check_fullscreen_move(f); |
10982 | if (f->output_data.x->want_fullscreen & FULLSCREEN_WAIT) | |
10983 | f->output_data.x->want_fullscreen &= | |
10984 | ~(FULLSCREEN_WAIT|FULLSCREEN_BOTH); | |
f5d11644 GM |
10985 | #ifdef HAVE_X_I18N |
10986 | if (FRAME_XIC (f) && (FRAME_XIC_STYLE (f) & XIMStatusArea)) | |
10987 | xic_set_statusarea (f); | |
10988 | #endif | |
10989 | ||
dcb07ae9 RS |
10990 | if (f->output_data.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window) |
10991 | { | |
10992 | /* Since the WM decorations come below top_pos now, | |
10993 | we must put them below top_pos in the future. */ | |
10994 | f->output_data.x->win_gravity = NorthWestGravity; | |
10995 | x_wm_set_size_hint (f, (long) 0, 0); | |
10996 | } | |
8f08dc93 KH |
10997 | #ifdef USE_MOTIF |
10998 | /* Some window managers pass (0,0) as the location of | |
10999 | the window, and the Motif event handler stores it | |
11000 | in the emacs widget, which messes up Motif menus. */ | |
11001 | if (event.xconfigure.x == 0 && event.xconfigure.y == 0) | |
11002 | { | |
11003 | event.xconfigure.x = f->output_data.x->widget->core.x; | |
11004 | event.xconfigure.y = f->output_data.x->widget->core.y; | |
11005 | } | |
06a2c219 | 11006 | #endif /* USE_MOTIF */ |
7a13e894 | 11007 | } |
2d7fc7e8 | 11008 | goto OTHER; |
dc6f92b8 | 11009 | |
7a13e894 RS |
11010 | case ButtonPress: |
11011 | case ButtonRelease: | |
11012 | { | |
11013 | /* If we decide we want to generate an event to be seen | |
11014 | by the rest of Emacs, we put it here. */ | |
11015 | struct input_event emacs_event; | |
9ea173e8 | 11016 | int tool_bar_p = 0; |
06a2c219 | 11017 | |
7a13e894 | 11018 | emacs_event.kind = no_event; |
7a13e894 | 11019 | bzero (&compose_status, sizeof (compose_status)); |
9b07615b | 11020 | |
06a2c219 GM |
11021 | if (dpyinfo->grabbed |
11022 | && last_mouse_frame | |
9f67f20b RS |
11023 | && FRAME_LIVE_P (last_mouse_frame)) |
11024 | f = last_mouse_frame; | |
11025 | else | |
2224b905 | 11026 | f = x_window_to_frame (dpyinfo, event.xbutton.window); |
9f67f20b | 11027 | |
06a2c219 GM |
11028 | if (f) |
11029 | { | |
9ea173e8 GM |
11030 | /* Is this in the tool-bar? */ |
11031 | if (WINDOWP (f->tool_bar_window) | |
11032 | && XFASTINT (XWINDOW (f->tool_bar_window)->height)) | |
06a2c219 GM |
11033 | { |
11034 | Lisp_Object window; | |
11035 | int p, x, y; | |
11036 | ||
11037 | x = event.xbutton.x; | |
11038 | y = event.xbutton.y; | |
11039 | ||
11040 | /* Set x and y. */ | |
11041 | window = window_from_coordinates (f, x, y, &p, 1); | |
9ea173e8 | 11042 | if (EQ (window, f->tool_bar_window)) |
06a2c219 | 11043 | { |
9ea173e8 GM |
11044 | x_handle_tool_bar_click (f, &event.xbutton); |
11045 | tool_bar_p = 1; | |
06a2c219 GM |
11046 | } |
11047 | } | |
11048 | ||
9ea173e8 | 11049 | if (!tool_bar_p) |
06a2c219 GM |
11050 | if (!dpyinfo->x_focus_frame |
11051 | || f == dpyinfo->x_focus_frame) | |
11052 | construct_mouse_click (&emacs_event, &event, f); | |
7a13e894 RS |
11053 | } |
11054 | else | |
11055 | { | |
06a2c219 | 11056 | #ifndef USE_TOOLKIT_SCROLL_BARS |
7a13e894 RS |
11057 | struct scroll_bar *bar |
11058 | = x_window_to_scroll_bar (event.xbutton.window); | |
f451eb13 | 11059 | |
7a13e894 RS |
11060 | if (bar) |
11061 | x_scroll_bar_handle_click (bar, &event, &emacs_event); | |
06a2c219 | 11062 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
7a13e894 RS |
11063 | } |
11064 | ||
11065 | if (event.type == ButtonPress) | |
11066 | { | |
11067 | dpyinfo->grabbed |= (1 << event.xbutton.button); | |
11068 | last_mouse_frame = f; | |
edad46f6 KH |
11069 | /* Ignore any mouse motion that happened |
11070 | before this event; any subsequent mouse-movement | |
11071 | Emacs events should reflect only motion after | |
11072 | the ButtonPress. */ | |
a00e91cd KH |
11073 | if (f != 0) |
11074 | f->mouse_moved = 0; | |
06a2c219 | 11075 | |
9ea173e8 GM |
11076 | if (!tool_bar_p) |
11077 | last_tool_bar_item = -1; | |
7a13e894 | 11078 | } |
3afe33e7 RS |
11079 | else |
11080 | { | |
7a13e894 | 11081 | dpyinfo->grabbed &= ~(1 << event.xbutton.button); |
3afe33e7 | 11082 | } |
23faf38f | 11083 | |
7a13e894 RS |
11084 | if (numchars >= 1 && emacs_event.kind != no_event) |
11085 | { | |
11086 | bcopy (&emacs_event, bufp, sizeof (struct input_event)); | |
11087 | bufp++; | |
11088 | count++; | |
11089 | numchars--; | |
11090 | } | |
3afe33e7 RS |
11091 | |
11092 | #ifdef USE_X_TOOLKIT | |
2224b905 RS |
11093 | f = x_menubar_window_to_frame (dpyinfo, event.xbutton.window); |
11094 | /* For a down-event in the menu bar, | |
11095 | don't pass it to Xt right now. | |
11096 | Instead, save it away | |
11097 | and we will pass it to Xt from kbd_buffer_get_event. | |
11098 | That way, we can run some Lisp code first. */ | |
91375f8f RS |
11099 | if (f && event.type == ButtonPress |
11100 | /* Verify the event is really within the menu bar | |
11101 | and not just sent to it due to grabbing. */ | |
11102 | && event.xbutton.x >= 0 | |
11103 | && event.xbutton.x < f->output_data.x->pixel_width | |
11104 | && event.xbutton.y >= 0 | |
11105 | && event.xbutton.y < f->output_data.x->menubar_height | |
11106 | && event.xbutton.same_screen) | |
2224b905 | 11107 | { |
8805890a | 11108 | SET_SAVED_BUTTON_EVENT; |
2237cac9 RS |
11109 | XSETFRAME (last_mouse_press_frame, f); |
11110 | } | |
11111 | else if (event.type == ButtonPress) | |
11112 | { | |
11113 | last_mouse_press_frame = Qnil; | |
30e671c3 | 11114 | goto OTHER; |
ce89ef46 | 11115 | } |
06a2c219 | 11116 | |
2237cac9 RS |
11117 | #ifdef USE_MOTIF /* This should do not harm for Lucid, |
11118 | but I am trying to be cautious. */ | |
ce89ef46 RS |
11119 | else if (event.type == ButtonRelease) |
11120 | { | |
2237cac9 | 11121 | if (!NILP (last_mouse_press_frame)) |
f10ded1c | 11122 | { |
2237cac9 RS |
11123 | f = XFRAME (last_mouse_press_frame); |
11124 | if (f->output_data.x) | |
06a2c219 | 11125 | SET_SAVED_BUTTON_EVENT; |
f10ded1c | 11126 | } |
06a2c219 | 11127 | else |
30e671c3 | 11128 | goto OTHER; |
2224b905 | 11129 | } |
2237cac9 | 11130 | #endif /* USE_MOTIF */ |
2224b905 RS |
11131 | else |
11132 | goto OTHER; | |
3afe33e7 | 11133 | #endif /* USE_X_TOOLKIT */ |
7a13e894 RS |
11134 | } |
11135 | break; | |
dc6f92b8 | 11136 | |
7a13e894 | 11137 | case CirculateNotify: |
06a2c219 GM |
11138 | goto OTHER; |
11139 | ||
7a13e894 | 11140 | case CirculateRequest: |
06a2c219 GM |
11141 | goto OTHER; |
11142 | ||
11143 | case VisibilityNotify: | |
11144 | goto OTHER; | |
dc6f92b8 | 11145 | |
7a13e894 RS |
11146 | case MappingNotify: |
11147 | /* Someone has changed the keyboard mapping - update the | |
11148 | local cache. */ | |
11149 | switch (event.xmapping.request) | |
11150 | { | |
11151 | case MappingModifier: | |
11152 | x_find_modifier_meanings (dpyinfo); | |
11153 | /* This is meant to fall through. */ | |
11154 | case MappingKeyboard: | |
11155 | XRefreshKeyboardMapping (&event.xmapping); | |
11156 | } | |
7a13e894 | 11157 | goto OTHER; |
dc6f92b8 | 11158 | |
7a13e894 | 11159 | default: |
7a13e894 | 11160 | OTHER: |
717ca130 | 11161 | #ifdef USE_X_TOOLKIT |
7a13e894 RS |
11162 | BLOCK_INPUT; |
11163 | XtDispatchEvent (&event); | |
11164 | UNBLOCK_INPUT; | |
3afe33e7 | 11165 | #endif /* USE_X_TOOLKIT */ |
7a13e894 RS |
11166 | break; |
11167 | } | |
dc6f92b8 JB |
11168 | } |
11169 | } | |
11170 | ||
06a2c219 GM |
11171 | out:; |
11172 | ||
9a5196d0 RS |
11173 | /* On some systems, an X bug causes Emacs to get no more events |
11174 | when the window is destroyed. Detect that. (1994.) */ | |
58769bee | 11175 | if (! event_found) |
ef2a22d0 | 11176 | { |
ef2a22d0 RS |
11177 | /* Emacs and the X Server eats up CPU time if XNoOp is done every time. |
11178 | One XNOOP in 100 loops will make Emacs terminate. | |
11179 | B. Bretthauer, 1994 */ | |
11180 | x_noop_count++; | |
58769bee | 11181 | if (x_noop_count >= 100) |
ef2a22d0 RS |
11182 | { |
11183 | x_noop_count=0; | |
2224b905 RS |
11184 | |
11185 | if (next_noop_dpyinfo == 0) | |
11186 | next_noop_dpyinfo = x_display_list; | |
11187 | ||
11188 | XNoOp (next_noop_dpyinfo->display); | |
11189 | ||
11190 | /* Each time we get here, cycle through the displays now open. */ | |
11191 | next_noop_dpyinfo = next_noop_dpyinfo->next; | |
ef2a22d0 RS |
11192 | } |
11193 | } | |
502add23 | 11194 | |
06a2c219 | 11195 | /* If the focus was just given to an auto-raising frame, |
0134a210 | 11196 | raise it now. */ |
7a13e894 | 11197 | /* ??? This ought to be able to handle more than one such frame. */ |
0134a210 RS |
11198 | if (pending_autoraise_frame) |
11199 | { | |
11200 | x_raise_frame (pending_autoraise_frame); | |
11201 | pending_autoraise_frame = 0; | |
11202 | } | |
0134a210 | 11203 | |
dc6f92b8 | 11204 | UNBLOCK_INPUT; |
bde5503b | 11205 | --handling_signal; |
dc6f92b8 JB |
11206 | return count; |
11207 | } | |
06a2c219 GM |
11208 | |
11209 | ||
11210 | ||
dc6f92b8 | 11211 | \f |
06a2c219 GM |
11212 | /*********************************************************************** |
11213 | Text Cursor | |
11214 | ***********************************************************************/ | |
11215 | ||
60626bab GM |
11216 | /* Notice when the text cursor of window W has been completely |
11217 | overwritten by a drawing operation that outputs glyphs in AREA | |
11218 | starting at X0 and ending at X1 in the line starting at Y0 and | |
11219 | ending at Y1. X coordinates are area-relative. X1 < 0 means all | |
11220 | the rest of the line after X0 has been written. Y coordinates | |
11221 | are window-relative. */ | |
06a2c219 GM |
11222 | |
11223 | static void | |
60626bab | 11224 | notice_overwritten_cursor (w, area, x0, x1, y0, y1) |
06a2c219 | 11225 | struct window *w; |
60626bab GM |
11226 | enum glyph_row_area area; |
11227 | int x0, y0, x1, y1; | |
06a2c219 | 11228 | { |
b3738089 GM |
11229 | if (area == TEXT_AREA && w->phys_cursor_on_p) |
11230 | { | |
11231 | int cx0 = w->phys_cursor.x; | |
11232 | int cx1 = cx0 + w->phys_cursor_width; | |
11233 | int cy0 = w->phys_cursor.y; | |
11234 | int cy1 = cy0 + w->phys_cursor_height; | |
11235 | ||
11236 | if (x0 <= cx0 && (x1 < 0 || x1 >= cx1)) | |
11237 | { | |
11238 | /* The cursor image will be completely removed from the | |
11239 | screen if the output area intersects the cursor area in | |
11240 | y-direction. When we draw in [y0 y1[, and some part of | |
11241 | the cursor is at y < y0, that part must have been drawn | |
11242 | before. When scrolling, the cursor is erased before | |
11243 | actually scrolling, so we don't come here. When not | |
11244 | scrolling, the rows above the old cursor row must have | |
11245 | changed, and in this case these rows must have written | |
516074a1 GM |
11246 | over the cursor image. |
11247 | ||
11248 | Likewise if part of the cursor is below y1, with the | |
11249 | exception of the cursor being in the first blank row at | |
11250 | the buffer and window end because update_text_area | |
4398e673 GM |
11251 | doesn't draw that row. (Except when it does, but |
11252 | that's handled in update_text_area.) */ | |
11253 | ||
f7c5994d | 11254 | if (((y0 >= cy0 && y0 < cy1) || (y1 > cy0 && y1 < cy1)) |
516074a1 | 11255 | && w->current_matrix->rows[w->phys_cursor.vpos].displays_text_p) |
b3738089 GM |
11256 | w->phys_cursor_on_p = 0; |
11257 | } | |
11258 | } | |
06a2c219 | 11259 | } |
f451eb13 JB |
11260 | |
11261 | ||
06a2c219 GM |
11262 | /* Set clipping for output in glyph row ROW. W is the window in which |
11263 | we operate. GC is the graphics context to set clipping in. | |
11264 | WHOLE_LINE_P non-zero means include the areas used for truncation | |
11265 | mark display and alike in the clipping rectangle. | |
11266 | ||
11267 | ROW may be a text row or, e.g., a mode line. Text rows must be | |
11268 | clipped to the interior of the window dedicated to text display, | |
11269 | mode lines must be clipped to the whole window. */ | |
dc6f92b8 JB |
11270 | |
11271 | static void | |
06a2c219 GM |
11272 | x_clip_to_row (w, row, gc, whole_line_p) |
11273 | struct window *w; | |
11274 | struct glyph_row *row; | |
11275 | GC gc; | |
11276 | int whole_line_p; | |
dc6f92b8 | 11277 | { |
06a2c219 GM |
11278 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
11279 | XRectangle clip_rect; | |
11280 | int window_x, window_y, window_width, window_height; | |
dc6f92b8 | 11281 | |
06a2c219 | 11282 | window_box (w, -1, &window_x, &window_y, &window_width, &window_height); |
5c1aae96 | 11283 | |
06a2c219 GM |
11284 | clip_rect.x = WINDOW_TO_FRAME_PIXEL_X (w, 0); |
11285 | clip_rect.y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y); | |
11286 | clip_rect.y = max (clip_rect.y, window_y); | |
11287 | clip_rect.width = window_width; | |
11288 | clip_rect.height = row->visible_height; | |
5c1aae96 | 11289 | |
06a2c219 GM |
11290 | /* If clipping to the whole line, including trunc marks, extend |
11291 | the rectangle to the left and increase its width. */ | |
11292 | if (whole_line_p) | |
11293 | { | |
3f332ef3 KS |
11294 | clip_rect.x -= FRAME_X_LEFT_FRINGE_WIDTH (f); |
11295 | clip_rect.width += FRAME_X_FRINGE_WIDTH (f); | |
06a2c219 | 11296 | } |
5c1aae96 | 11297 | |
06a2c219 | 11298 | XSetClipRectangles (FRAME_X_DISPLAY (f), gc, 0, 0, &clip_rect, 1, Unsorted); |
dc6f92b8 JB |
11299 | } |
11300 | ||
06a2c219 GM |
11301 | |
11302 | /* Draw a hollow box cursor on window W in glyph row ROW. */ | |
dc6f92b8 JB |
11303 | |
11304 | static void | |
06a2c219 GM |
11305 | x_draw_hollow_cursor (w, row) |
11306 | struct window *w; | |
11307 | struct glyph_row *row; | |
dc6f92b8 | 11308 | { |
06a2c219 GM |
11309 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
11310 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
11311 | Display *dpy = FRAME_X_DISPLAY (f); | |
11312 | int x, y, wd, h; | |
11313 | XGCValues xgcv; | |
11314 | struct glyph *cursor_glyph; | |
11315 | GC gc; | |
11316 | ||
11317 | /* Compute frame-relative coordinates from window-relative | |
11318 | coordinates. */ | |
11319 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); | |
11320 | y = (WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y) | |
11321 | + row->ascent - w->phys_cursor_ascent); | |
11322 | h = row->height - 1; | |
11323 | ||
11324 | /* Get the glyph the cursor is on. If we can't tell because | |
11325 | the current matrix is invalid or such, give up. */ | |
11326 | cursor_glyph = get_phys_cursor_glyph (w); | |
11327 | if (cursor_glyph == NULL) | |
dc6f92b8 JB |
11328 | return; |
11329 | ||
06a2c219 GM |
11330 | /* Compute the width of the rectangle to draw. If on a stretch |
11331 | glyph, and `x-stretch-block-cursor' is nil, don't draw a | |
11332 | rectangle as wide as the glyph, but use a canonical character | |
11333 | width instead. */ | |
11334 | wd = cursor_glyph->pixel_width - 1; | |
11335 | if (cursor_glyph->type == STRETCH_GLYPH | |
11336 | && !x_stretch_cursor_p) | |
11337 | wd = min (CANON_X_UNIT (f), wd); | |
b3738089 | 11338 | w->phys_cursor_width = wd; |
06a2c219 GM |
11339 | |
11340 | /* The foreground of cursor_gc is typically the same as the normal | |
11341 | background color, which can cause the cursor box to be invisible. */ | |
11342 | xgcv.foreground = f->output_data.x->cursor_pixel; | |
11343 | if (dpyinfo->scratch_cursor_gc) | |
11344 | XChangeGC (dpy, dpyinfo->scratch_cursor_gc, GCForeground, &xgcv); | |
11345 | else | |
11346 | dpyinfo->scratch_cursor_gc = XCreateGC (dpy, FRAME_X_WINDOW (f), | |
11347 | GCForeground, &xgcv); | |
11348 | gc = dpyinfo->scratch_cursor_gc; | |
11349 | ||
11350 | /* Set clipping, draw the rectangle, and reset clipping again. */ | |
11351 | x_clip_to_row (w, row, gc, 0); | |
11352 | XDrawRectangle (dpy, FRAME_X_WINDOW (f), gc, x, y, wd, h); | |
11353 | XSetClipMask (dpy, gc, None); | |
dc6f92b8 JB |
11354 | } |
11355 | ||
06a2c219 GM |
11356 | |
11357 | /* Draw a bar cursor on window W in glyph row ROW. | |
11358 | ||
11359 | Implementation note: One would like to draw a bar cursor with an | |
11360 | angle equal to the one given by the font property XA_ITALIC_ANGLE. | |
11361 | Unfortunately, I didn't find a font yet that has this property set. | |
11362 | --gerd. */ | |
dc6f92b8 JB |
11363 | |
11364 | static void | |
65c26775 | 11365 | x_draw_bar_cursor (w, row, width, kind) |
06a2c219 GM |
11366 | struct window *w; |
11367 | struct glyph_row *row; | |
f02d8aa0 | 11368 | int width; |
65c26775 | 11369 | enum text_cursor_kinds kind; |
dc6f92b8 | 11370 | { |
92f424df GM |
11371 | struct frame *f = XFRAME (w->frame); |
11372 | struct glyph *cursor_glyph; | |
06a2c219 | 11373 | |
92f424df GM |
11374 | /* If cursor is out of bounds, don't draw garbage. This can happen |
11375 | in mini-buffer windows when switching between echo area glyphs | |
11376 | and mini-buffer. */ | |
11377 | cursor_glyph = get_phys_cursor_glyph (w); | |
11378 | if (cursor_glyph == NULL) | |
11379 | return; | |
06a2c219 | 11380 | |
92f424df GM |
11381 | /* If on an image, draw like a normal cursor. That's usually better |
11382 | visible than drawing a bar, esp. if the image is large so that | |
11383 | the bar might not be in the window. */ | |
11384 | if (cursor_glyph->type == IMAGE_GLYPH) | |
11385 | { | |
11386 | struct glyph_row *row; | |
11387 | row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos); | |
11388 | x_draw_phys_cursor_glyph (w, row, DRAW_CURSOR); | |
11389 | } | |
11390 | else | |
11391 | { | |
34e5d0af GM |
11392 | Display *dpy = FRAME_X_DISPLAY (f); |
11393 | Window window = FRAME_X_WINDOW (f); | |
11394 | GC gc = FRAME_X_DISPLAY_INFO (f)->scratch_cursor_gc; | |
11395 | unsigned long mask = GCForeground | GCBackground | GCGraphicsExposures; | |
11396 | struct face *face = FACE_FROM_ID (f, cursor_glyph->face_id); | |
11397 | XGCValues xgcv; | |
11398 | ||
11399 | /* If the glyph's background equals the color we normally draw | |
11400 | the bar cursor in, the bar cursor in its normal color is | |
11401 | invisible. Use the glyph's foreground color instead in this | |
11402 | case, on the assumption that the glyph's colors are chosen so | |
11403 | that the glyph is legible. */ | |
11404 | if (face->background == f->output_data.x->cursor_pixel) | |
11405 | xgcv.background = xgcv.foreground = face->foreground; | |
11406 | else | |
11407 | xgcv.background = xgcv.foreground = f->output_data.x->cursor_pixel; | |
06a2c219 | 11408 | xgcv.graphics_exposures = 0; |
92f424df | 11409 | |
06a2c219 GM |
11410 | if (gc) |
11411 | XChangeGC (dpy, gc, mask, &xgcv); | |
11412 | else | |
11413 | { | |
11414 | gc = XCreateGC (dpy, window, mask, &xgcv); | |
11415 | FRAME_X_DISPLAY_INFO (f)->scratch_cursor_gc = gc; | |
11416 | } | |
92f424df | 11417 | |
f02d8aa0 GM |
11418 | if (width < 0) |
11419 | width = f->output_data.x->cursor_width; | |
34e5d0af | 11420 | width = min (cursor_glyph->pixel_width, width); |
92f424df | 11421 | |
b3738089 | 11422 | w->phys_cursor_width = width; |
06a2c219 | 11423 | x_clip_to_row (w, row, gc, 0); |
b3738089 | 11424 | |
65c26775 EZ |
11425 | if (kind == BAR_CURSOR) |
11426 | XFillRectangle (dpy, window, gc, | |
11427 | WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x), | |
11428 | WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y), | |
11429 | width, row->height); | |
11430 | else | |
11431 | XFillRectangle (dpy, window, gc, | |
11432 | WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x), | |
11433 | WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y + | |
11434 | row->height - width), | |
11435 | cursor_glyph->pixel_width, | |
11436 | width); | |
11437 | ||
06a2c219 GM |
11438 | XSetClipMask (dpy, gc, None); |
11439 | } | |
dc6f92b8 JB |
11440 | } |
11441 | ||
06a2c219 GM |
11442 | |
11443 | /* Clear the cursor of window W to background color, and mark the | |
11444 | cursor as not shown. This is used when the text where the cursor | |
11445 | is is about to be rewritten. */ | |
11446 | ||
dc6f92b8 | 11447 | static void |
06a2c219 GM |
11448 | x_clear_cursor (w) |
11449 | struct window *w; | |
dc6f92b8 | 11450 | { |
06a2c219 GM |
11451 | if (FRAME_VISIBLE_P (XFRAME (w->frame)) && w->phys_cursor_on_p) |
11452 | x_update_window_cursor (w, 0); | |
11453 | } | |
90e65f07 | 11454 | |
dbc4e1c1 | 11455 | |
06a2c219 GM |
11456 | /* Draw the cursor glyph of window W in glyph row ROW. See the |
11457 | comment of x_draw_glyphs for the meaning of HL. */ | |
dbc4e1c1 | 11458 | |
06a2c219 GM |
11459 | static void |
11460 | x_draw_phys_cursor_glyph (w, row, hl) | |
11461 | struct window *w; | |
11462 | struct glyph_row *row; | |
11463 | enum draw_glyphs_face hl; | |
11464 | { | |
11465 | /* If cursor hpos is out of bounds, don't draw garbage. This can | |
11466 | happen in mini-buffer windows when switching between echo area | |
11467 | glyphs and mini-buffer. */ | |
11468 | if (w->phys_cursor.hpos < row->used[TEXT_AREA]) | |
66ac4b0e | 11469 | { |
f0a48a01 GM |
11470 | int on_p = w->phys_cursor_on_p; |
11471 | ||
66ac4b0e GM |
11472 | x_draw_glyphs (w, w->phys_cursor.x, row, TEXT_AREA, |
11473 | w->phys_cursor.hpos, w->phys_cursor.hpos + 1, | |
f0a48a01 GM |
11474 | hl, 0); |
11475 | w->phys_cursor_on_p = on_p; | |
66ac4b0e | 11476 | |
b3738089 GM |
11477 | if (hl == DRAW_CURSOR) |
11478 | { | |
11479 | struct glyph *cursor_glyph = get_phys_cursor_glyph (w); | |
11480 | if (cursor_glyph) | |
ef58a7ec GM |
11481 | { |
11482 | if (x_stretch_cursor_p) | |
11483 | w->phys_cursor_width = cursor_glyph->pixel_width; | |
11484 | else | |
11485 | w->phys_cursor_width = min (CANON_X_UNIT (XFRAME (w->frame)), | |
11486 | cursor_glyph->pixel_width); | |
11487 | } | |
b3738089 GM |
11488 | } |
11489 | ||
66ac4b0e GM |
11490 | /* When we erase the cursor, and ROW is overlapped by other |
11491 | rows, make sure that these overlapping parts of other rows | |
11492 | are redrawn. */ | |
b3738089 | 11493 | else if (hl == DRAW_NORMAL_TEXT && row->overlapped_p) |
66ac4b0e GM |
11494 | { |
11495 | if (row > w->current_matrix->rows | |
11496 | && MATRIX_ROW_OVERLAPS_SUCC_P (row - 1)) | |
11497 | x_fix_overlapping_area (w, row - 1, TEXT_AREA); | |
11498 | ||
11499 | if (MATRIX_ROW_BOTTOM_Y (row) < window_text_bottom_y (w) | |
11500 | && MATRIX_ROW_OVERLAPS_PRED_P (row + 1)) | |
11501 | x_fix_overlapping_area (w, row + 1, TEXT_AREA); | |
11502 | } | |
11503 | } | |
06a2c219 | 11504 | } |
dbc4e1c1 | 11505 | |
eea6af04 | 11506 | |
06a2c219 | 11507 | /* Erase the image of a cursor of window W from the screen. */ |
eea6af04 | 11508 | |
06a2c219 GM |
11509 | static void |
11510 | x_erase_phys_cursor (w) | |
11511 | struct window *w; | |
11512 | { | |
11513 | struct frame *f = XFRAME (w->frame); | |
11514 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
11515 | int hpos = w->phys_cursor.hpos; | |
11516 | int vpos = w->phys_cursor.vpos; | |
11517 | int mouse_face_here_p = 0; | |
11518 | struct glyph_matrix *active_glyphs = w->current_matrix; | |
11519 | struct glyph_row *cursor_row; | |
11520 | struct glyph *cursor_glyph; | |
11521 | enum draw_glyphs_face hl; | |
11522 | ||
11523 | /* No cursor displayed or row invalidated => nothing to do on the | |
11524 | screen. */ | |
11525 | if (w->phys_cursor_type == NO_CURSOR) | |
11526 | goto mark_cursor_off; | |
11527 | ||
11528 | /* VPOS >= active_glyphs->nrows means that window has been resized. | |
11529 | Don't bother to erase the cursor. */ | |
11530 | if (vpos >= active_glyphs->nrows) | |
11531 | goto mark_cursor_off; | |
11532 | ||
11533 | /* If row containing cursor is marked invalid, there is nothing we | |
11534 | can do. */ | |
11535 | cursor_row = MATRIX_ROW (active_glyphs, vpos); | |
11536 | if (!cursor_row->enabled_p) | |
11537 | goto mark_cursor_off; | |
11538 | ||
a2c6de8e KS |
11539 | /* If row is completely invisible, don't attempt to delete a cursor which |
11540 | isn't there. This can happen if cursor is at top of a window, and | |
11541 | we switch to a buffer with a header line in that window. */ | |
11542 | if (cursor_row->visible_height <= 0) | |
11543 | goto mark_cursor_off; | |
11544 | ||
06a2c219 GM |
11545 | /* This can happen when the new row is shorter than the old one. |
11546 | In this case, either x_draw_glyphs or clear_end_of_line | |
11547 | should have cleared the cursor. Note that we wouldn't be | |
11548 | able to erase the cursor in this case because we don't have a | |
11549 | cursor glyph at hand. */ | |
11550 | if (w->phys_cursor.hpos >= cursor_row->used[TEXT_AREA]) | |
11551 | goto mark_cursor_off; | |
11552 | ||
11553 | /* If the cursor is in the mouse face area, redisplay that when | |
11554 | we clear the cursor. */ | |
8801a864 KR |
11555 | if (! NILP (dpyinfo->mouse_face_window) |
11556 | && w == XWINDOW (dpyinfo->mouse_face_window) | |
06a2c219 GM |
11557 | && (vpos > dpyinfo->mouse_face_beg_row |
11558 | || (vpos == dpyinfo->mouse_face_beg_row | |
11559 | && hpos >= dpyinfo->mouse_face_beg_col)) | |
11560 | && (vpos < dpyinfo->mouse_face_end_row | |
11561 | || (vpos == dpyinfo->mouse_face_end_row | |
11562 | && hpos < dpyinfo->mouse_face_end_col)) | |
11563 | /* Don't redraw the cursor's spot in mouse face if it is at the | |
11564 | end of a line (on a newline). The cursor appears there, but | |
11565 | mouse highlighting does not. */ | |
11566 | && cursor_row->used[TEXT_AREA] > hpos) | |
11567 | mouse_face_here_p = 1; | |
11568 | ||
11569 | /* Maybe clear the display under the cursor. */ | |
11570 | if (w->phys_cursor_type == HOLLOW_BOX_CURSOR) | |
11571 | { | |
11572 | int x; | |
045dee35 | 11573 | int header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); |
dbc4e1c1 | 11574 | |
06a2c219 GM |
11575 | cursor_glyph = get_phys_cursor_glyph (w); |
11576 | if (cursor_glyph == NULL) | |
11577 | goto mark_cursor_off; | |
dbc4e1c1 | 11578 | |
e0300d33 | 11579 | x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); |
06a2c219 | 11580 | |
c5e6e06b GM |
11581 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
11582 | x, | |
11583 | WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, | |
11584 | cursor_row->y)), | |
11585 | cursor_glyph->pixel_width, | |
11586 | cursor_row->visible_height, | |
11587 | False); | |
dbc4e1c1 | 11588 | } |
06a2c219 GM |
11589 | |
11590 | /* Erase the cursor by redrawing the character underneath it. */ | |
11591 | if (mouse_face_here_p) | |
11592 | hl = DRAW_MOUSE_FACE; | |
06a2c219 GM |
11593 | else |
11594 | hl = DRAW_NORMAL_TEXT; | |
11595 | x_draw_phys_cursor_glyph (w, cursor_row, hl); | |
dbc4e1c1 | 11596 | |
06a2c219 GM |
11597 | mark_cursor_off: |
11598 | w->phys_cursor_on_p = 0; | |
11599 | w->phys_cursor_type = NO_CURSOR; | |
dbc4e1c1 JB |
11600 | } |
11601 | ||
11602 | ||
b7f83f9e GM |
11603 | /* Non-zero if physical cursor of window W is within mouse face. */ |
11604 | ||
11605 | static int | |
11606 | cursor_in_mouse_face_p (w) | |
11607 | struct window *w; | |
11608 | { | |
11609 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (XFRAME (w->frame)); | |
11610 | int in_mouse_face = 0; | |
11611 | ||
11612 | if (WINDOWP (dpyinfo->mouse_face_window) | |
11613 | && XWINDOW (dpyinfo->mouse_face_window) == w) | |
11614 | { | |
11615 | int hpos = w->phys_cursor.hpos; | |
11616 | int vpos = w->phys_cursor.vpos; | |
11617 | ||
11618 | if (vpos >= dpyinfo->mouse_face_beg_row | |
11619 | && vpos <= dpyinfo->mouse_face_end_row | |
11620 | && (vpos > dpyinfo->mouse_face_beg_row | |
11621 | || hpos >= dpyinfo->mouse_face_beg_col) | |
11622 | && (vpos < dpyinfo->mouse_face_end_row | |
11623 | || hpos < dpyinfo->mouse_face_end_col | |
11624 | || dpyinfo->mouse_face_past_end)) | |
11625 | in_mouse_face = 1; | |
11626 | } | |
11627 | ||
11628 | return in_mouse_face; | |
11629 | } | |
11630 | ||
11631 | ||
06a2c219 GM |
11632 | /* Display or clear cursor of window W. If ON is zero, clear the |
11633 | cursor. If it is non-zero, display the cursor. If ON is nonzero, | |
11634 | where to put the cursor is specified by HPOS, VPOS, X and Y. */ | |
dbc4e1c1 | 11635 | |
06a2c219 GM |
11636 | void |
11637 | x_display_and_set_cursor (w, on, hpos, vpos, x, y) | |
11638 | struct window *w; | |
11639 | int on, hpos, vpos, x, y; | |
dbc4e1c1 | 11640 | { |
06a2c219 GM |
11641 | struct frame *f = XFRAME (w->frame); |
11642 | int new_cursor_type; | |
f02d8aa0 | 11643 | int new_cursor_width; |
06a2c219 GM |
11644 | struct glyph_matrix *current_glyphs; |
11645 | struct glyph_row *glyph_row; | |
11646 | struct glyph *glyph; | |
34368a22 | 11647 | int cursor_non_selected; |
dbc4e1c1 | 11648 | |
49d838ea | 11649 | /* This is pointless on invisible frames, and dangerous on garbaged |
06a2c219 GM |
11650 | windows and frames; in the latter case, the frame or window may |
11651 | be in the midst of changing its size, and x and y may be off the | |
11652 | window. */ | |
11653 | if (! FRAME_VISIBLE_P (f) | |
11654 | || FRAME_GARBAGED_P (f) | |
11655 | || vpos >= w->current_matrix->nrows | |
11656 | || hpos >= w->current_matrix->matrix_w) | |
dc6f92b8 JB |
11657 | return; |
11658 | ||
11659 | /* If cursor is off and we want it off, return quickly. */ | |
06a2c219 | 11660 | if (!on && !w->phys_cursor_on_p) |
dc6f92b8 JB |
11661 | return; |
11662 | ||
06a2c219 GM |
11663 | current_glyphs = w->current_matrix; |
11664 | glyph_row = MATRIX_ROW (current_glyphs, vpos); | |
11665 | glyph = glyph_row->glyphs[TEXT_AREA] + hpos; | |
11666 | ||
11667 | /* If cursor row is not enabled, we don't really know where to | |
11668 | display the cursor. */ | |
11669 | if (!glyph_row->enabled_p) | |
11670 | { | |
11671 | w->phys_cursor_on_p = 0; | |
11672 | return; | |
11673 | } | |
11674 | ||
11675 | xassert (interrupt_input_blocked); | |
11676 | ||
11677 | /* Set new_cursor_type to the cursor we want to be displayed. In a | |
11678 | mini-buffer window, we want the cursor only to appear if we are | |
11679 | reading input from this window. For the selected window, we want | |
11680 | the cursor type given by the frame parameter. If explicitly | |
11681 | marked off, draw no cursor. In all other cases, we want a hollow | |
11682 | box cursor. */ | |
34368a22 RS |
11683 | cursor_non_selected |
11684 | = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows, | |
11685 | w->buffer)); | |
f02d8aa0 | 11686 | new_cursor_width = -1; |
9b4a7047 GM |
11687 | if (cursor_in_echo_area |
11688 | && FRAME_HAS_MINIBUF_P (f) | |
11689 | && EQ (FRAME_MINIBUF_WINDOW (f), echo_area_window)) | |
06a2c219 | 11690 | { |
9b4a7047 GM |
11691 | if (w == XWINDOW (echo_area_window)) |
11692 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
34368a22 | 11693 | else if (cursor_non_selected) |
06a2c219 | 11694 | new_cursor_type = HOLLOW_BOX_CURSOR; |
9a7bdceb GM |
11695 | else |
11696 | new_cursor_type = NO_CURSOR; | |
06a2c219 | 11697 | } |
06a2c219 | 11698 | else |
9b4a7047 | 11699 | { |
7a58ab59 GM |
11700 | if (f != FRAME_X_DISPLAY_INFO (f)->x_highlight_frame |
11701 | || w != XWINDOW (f->selected_window)) | |
9b4a7047 | 11702 | { |
2c850e26 | 11703 | if ((MINI_WINDOW_P (w) && minibuf_level == 0) |
34368a22 | 11704 | || !cursor_non_selected |
5cefa566 | 11705 | || NILP (XBUFFER (w->buffer)->cursor_type)) |
9b4a7047 GM |
11706 | new_cursor_type = NO_CURSOR; |
11707 | else | |
11708 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
11709 | } | |
9b4a7047 | 11710 | else |
f02d8aa0 GM |
11711 | { |
11712 | struct buffer *b = XBUFFER (w->buffer); | |
11713 | ||
11714 | if (EQ (b->cursor_type, Qt)) | |
11715 | new_cursor_type = FRAME_DESIRED_CURSOR (f); | |
11716 | else | |
11717 | new_cursor_type = x_specified_cursor_type (b->cursor_type, | |
11718 | &new_cursor_width); | |
e1429afe KS |
11719 | if (w->cursor_off_p) |
11720 | { | |
11721 | if (new_cursor_type == FILLED_BOX_CURSOR) | |
11722 | new_cursor_type = HOLLOW_BOX_CURSOR; | |
11723 | else if (new_cursor_type == BAR_CURSOR && new_cursor_width > 1) | |
11724 | new_cursor_width = 1; | |
11725 | else | |
11726 | new_cursor_type = NO_CURSOR; | |
11727 | } | |
f02d8aa0 | 11728 | } |
9b4a7047 | 11729 | } |
06a2c219 GM |
11730 | |
11731 | /* If cursor is currently being shown and we don't want it to be or | |
11732 | it is in the wrong place, or the cursor type is not what we want, | |
dc6f92b8 | 11733 | erase it. */ |
06a2c219 | 11734 | if (w->phys_cursor_on_p |
dc6f92b8 | 11735 | && (!on |
06a2c219 GM |
11736 | || w->phys_cursor.x != x |
11737 | || w->phys_cursor.y != y | |
e1429afe KS |
11738 | || new_cursor_type != w->phys_cursor_type |
11739 | || (new_cursor_type == BAR_CURSOR | |
11740 | && new_cursor_width != w->phys_cursor_width))) | |
06a2c219 GM |
11741 | x_erase_phys_cursor (w); |
11742 | ||
11743 | /* If the cursor is now invisible and we want it to be visible, | |
11744 | display it. */ | |
11745 | if (on && !w->phys_cursor_on_p) | |
11746 | { | |
11747 | w->phys_cursor_ascent = glyph_row->ascent; | |
11748 | w->phys_cursor_height = glyph_row->height; | |
11749 | ||
11750 | /* Set phys_cursor_.* before x_draw_.* is called because some | |
11751 | of them may need the information. */ | |
11752 | w->phys_cursor.x = x; | |
11753 | w->phys_cursor.y = glyph_row->y; | |
11754 | w->phys_cursor.hpos = hpos; | |
11755 | w->phys_cursor.vpos = vpos; | |
11756 | w->phys_cursor_type = new_cursor_type; | |
11757 | w->phys_cursor_on_p = 1; | |
11758 | ||
11759 | switch (new_cursor_type) | |
dc6f92b8 | 11760 | { |
06a2c219 GM |
11761 | case HOLLOW_BOX_CURSOR: |
11762 | x_draw_hollow_cursor (w, glyph_row); | |
11763 | break; | |
11764 | ||
11765 | case FILLED_BOX_CURSOR: | |
11766 | x_draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR); | |
11767 | break; | |
11768 | ||
11769 | case BAR_CURSOR: | |
65c26775 EZ |
11770 | x_draw_bar_cursor (w, glyph_row, new_cursor_width, BAR_CURSOR); |
11771 | break; | |
11772 | ||
11773 | case HBAR_CURSOR: | |
b3738089 | 11774 | x_draw_bar_cursor (w, glyph_row, new_cursor_width, HBAR_CURSOR); |
06a2c219 GM |
11775 | break; |
11776 | ||
11777 | case NO_CURSOR: | |
4398e673 | 11778 | w->phys_cursor_width = 0; |
06a2c219 | 11779 | break; |
dc6f92b8 | 11780 | |
06a2c219 GM |
11781 | default: |
11782 | abort (); | |
11783 | } | |
59ddecde GM |
11784 | |
11785 | #ifdef HAVE_X_I18N | |
11786 | if (w == XWINDOW (f->selected_window)) | |
11787 | if (FRAME_XIC (f) && (FRAME_XIC_STYLE (f) & XIMPreeditPosition)) | |
11788 | xic_set_preeditarea (w, x, y); | |
11789 | #endif | |
dc6f92b8 JB |
11790 | } |
11791 | ||
06a2c219 | 11792 | #ifndef XFlush |
f676886a | 11793 | if (updating_frame != f) |
334208b7 | 11794 | XFlush (FRAME_X_DISPLAY (f)); |
06a2c219 | 11795 | #endif |
dc6f92b8 JB |
11796 | } |
11797 | ||
06a2c219 GM |
11798 | |
11799 | /* Display the cursor on window W, or clear it. X and Y are window | |
11800 | relative pixel coordinates. HPOS and VPOS are glyph matrix | |
11801 | positions. If W is not the selected window, display a hollow | |
11802 | cursor. ON non-zero means display the cursor at X, Y which | |
11803 | correspond to HPOS, VPOS, otherwise it is cleared. */ | |
5d46f928 | 11804 | |
dfcf069d | 11805 | void |
06a2c219 GM |
11806 | x_display_cursor (w, on, hpos, vpos, x, y) |
11807 | struct window *w; | |
11808 | int on, hpos, vpos, x, y; | |
dc6f92b8 | 11809 | { |
f94397b5 | 11810 | BLOCK_INPUT; |
06a2c219 | 11811 | x_display_and_set_cursor (w, on, hpos, vpos, x, y); |
5d46f928 RS |
11812 | UNBLOCK_INPUT; |
11813 | } | |
11814 | ||
06a2c219 GM |
11815 | |
11816 | /* Display the cursor on window W, or clear it, according to ON_P. | |
5d46f928 RS |
11817 | Don't change the cursor's position. */ |
11818 | ||
dfcf069d | 11819 | void |
06a2c219 | 11820 | x_update_cursor (f, on_p) |
5d46f928 | 11821 | struct frame *f; |
5d46f928 | 11822 | { |
06a2c219 GM |
11823 | x_update_cursor_in_window_tree (XWINDOW (f->root_window), on_p); |
11824 | } | |
11825 | ||
11826 | ||
11827 | /* Call x_update_window_cursor with parameter ON_P on all leaf windows | |
11828 | in the window tree rooted at W. */ | |
11829 | ||
11830 | static void | |
11831 | x_update_cursor_in_window_tree (w, on_p) | |
11832 | struct window *w; | |
11833 | int on_p; | |
11834 | { | |
11835 | while (w) | |
11836 | { | |
11837 | if (!NILP (w->hchild)) | |
11838 | x_update_cursor_in_window_tree (XWINDOW (w->hchild), on_p); | |
11839 | else if (!NILP (w->vchild)) | |
11840 | x_update_cursor_in_window_tree (XWINDOW (w->vchild), on_p); | |
11841 | else | |
11842 | x_update_window_cursor (w, on_p); | |
11843 | ||
11844 | w = NILP (w->next) ? 0 : XWINDOW (w->next); | |
11845 | } | |
11846 | } | |
5d46f928 | 11847 | |
f94397b5 | 11848 | |
06a2c219 GM |
11849 | /* Switch the display of W's cursor on or off, according to the value |
11850 | of ON. */ | |
11851 | ||
11852 | static void | |
11853 | x_update_window_cursor (w, on) | |
11854 | struct window *w; | |
11855 | int on; | |
11856 | { | |
16b5d424 GM |
11857 | /* Don't update cursor in windows whose frame is in the process |
11858 | of being deleted. */ | |
11859 | if (w->current_matrix) | |
11860 | { | |
11861 | BLOCK_INPUT; | |
11862 | x_display_and_set_cursor (w, on, w->phys_cursor.hpos, w->phys_cursor.vpos, | |
11863 | w->phys_cursor.x, w->phys_cursor.y); | |
11864 | UNBLOCK_INPUT; | |
11865 | } | |
dc6f92b8 | 11866 | } |
06a2c219 GM |
11867 | |
11868 | ||
11869 | ||
dc6f92b8 JB |
11870 | \f |
11871 | /* Icons. */ | |
11872 | ||
dbc4e1c1 | 11873 | /* Make the x-window of frame F use the gnu icon bitmap. */ |
dc6f92b8 JB |
11874 | |
11875 | int | |
990ba854 | 11876 | x_bitmap_icon (f, file) |
f676886a | 11877 | struct frame *f; |
990ba854 | 11878 | Lisp_Object file; |
dc6f92b8 | 11879 | { |
06a2c219 | 11880 | int bitmap_id; |
dc6f92b8 | 11881 | |
c118dd06 | 11882 | if (FRAME_X_WINDOW (f) == 0) |
dc6f92b8 JB |
11883 | return 1; |
11884 | ||
990ba854 | 11885 | /* Free up our existing icon bitmap if any. */ |
7556890b RS |
11886 | if (f->output_data.x->icon_bitmap > 0) |
11887 | x_destroy_bitmap (f, f->output_data.x->icon_bitmap); | |
11888 | f->output_data.x->icon_bitmap = 0; | |
990ba854 RS |
11889 | |
11890 | if (STRINGP (file)) | |
7f2ae036 RS |
11891 | bitmap_id = x_create_bitmap_from_file (f, file); |
11892 | else | |
11893 | { | |
990ba854 | 11894 | /* Create the GNU bitmap if necessary. */ |
5bf01b68 | 11895 | if (FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id < 0) |
334208b7 RS |
11896 | FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id |
11897 | = x_create_bitmap_from_data (f, gnu_bits, | |
11898 | gnu_width, gnu_height); | |
990ba854 RS |
11899 | |
11900 | /* The first time we create the GNU bitmap, | |
06a2c219 | 11901 | this increments the ref-count one extra time. |
990ba854 RS |
11902 | As a result, the GNU bitmap is never freed. |
11903 | That way, we don't have to worry about allocating it again. */ | |
334208b7 | 11904 | x_reference_bitmap (f, FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id); |
990ba854 | 11905 | |
334208b7 | 11906 | bitmap_id = FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id; |
7f2ae036 RS |
11907 | } |
11908 | ||
11909 | x_wm_set_icon_pixmap (f, bitmap_id); | |
7556890b | 11910 | f->output_data.x->icon_bitmap = bitmap_id; |
dc6f92b8 JB |
11911 | |
11912 | return 0; | |
11913 | } | |
11914 | ||
11915 | ||
1be2d067 KH |
11916 | /* Make the x-window of frame F use a rectangle with text. |
11917 | Use ICON_NAME as the text. */ | |
dc6f92b8 JB |
11918 | |
11919 | int | |
f676886a JB |
11920 | x_text_icon (f, icon_name) |
11921 | struct frame *f; | |
dc6f92b8 JB |
11922 | char *icon_name; |
11923 | { | |
c118dd06 | 11924 | if (FRAME_X_WINDOW (f) == 0) |
dc6f92b8 JB |
11925 | return 1; |
11926 | ||
1be2d067 KH |
11927 | #ifdef HAVE_X11R4 |
11928 | { | |
11929 | XTextProperty text; | |
11930 | text.value = (unsigned char *) icon_name; | |
11931 | text.encoding = XA_STRING; | |
11932 | text.format = 8; | |
11933 | text.nitems = strlen (icon_name); | |
11934 | #ifdef USE_X_TOOLKIT | |
7556890b | 11935 | XSetWMIconName (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget), |
1be2d067 KH |
11936 | &text); |
11937 | #else /* not USE_X_TOOLKIT */ | |
11938 | XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text); | |
11939 | #endif /* not USE_X_TOOLKIT */ | |
11940 | } | |
11941 | #else /* not HAVE_X11R4 */ | |
11942 | XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), icon_name); | |
11943 | #endif /* not HAVE_X11R4 */ | |
58769bee | 11944 | |
7556890b RS |
11945 | if (f->output_data.x->icon_bitmap > 0) |
11946 | x_destroy_bitmap (f, f->output_data.x->icon_bitmap); | |
11947 | f->output_data.x->icon_bitmap = 0; | |
b1c884c3 | 11948 | x_wm_set_icon_pixmap (f, 0); |
dc6f92b8 JB |
11949 | |
11950 | return 0; | |
11951 | } | |
11952 | \f | |
e99db5a1 RS |
11953 | #define X_ERROR_MESSAGE_SIZE 200 |
11954 | ||
11955 | /* If non-nil, this should be a string. | |
11956 | It means catch X errors and store the error message in this string. */ | |
11957 | ||
11958 | static Lisp_Object x_error_message_string; | |
11959 | ||
11960 | /* An X error handler which stores the error message in | |
11961 | x_error_message_string. This is called from x_error_handler if | |
11962 | x_catch_errors is in effect. */ | |
11963 | ||
06a2c219 | 11964 | static void |
e99db5a1 RS |
11965 | x_error_catcher (display, error) |
11966 | Display *display; | |
11967 | XErrorEvent *error; | |
11968 | { | |
11969 | XGetErrorText (display, error->error_code, | |
11970 | XSTRING (x_error_message_string)->data, | |
11971 | X_ERROR_MESSAGE_SIZE); | |
11972 | } | |
11973 | ||
11974 | /* Begin trapping X errors for display DPY. Actually we trap X errors | |
11975 | for all displays, but DPY should be the display you are actually | |
11976 | operating on. | |
11977 | ||
11978 | After calling this function, X protocol errors no longer cause | |
11979 | Emacs to exit; instead, they are recorded in the string | |
11980 | stored in x_error_message_string. | |
11981 | ||
11982 | Calling x_check_errors signals an Emacs error if an X error has | |
11983 | occurred since the last call to x_catch_errors or x_check_errors. | |
11984 | ||
11985 | Calling x_uncatch_errors resumes the normal error handling. */ | |
11986 | ||
11987 | void x_check_errors (); | |
11988 | static Lisp_Object x_catch_errors_unwind (); | |
11989 | ||
11990 | int | |
11991 | x_catch_errors (dpy) | |
11992 | Display *dpy; | |
11993 | { | |
11994 | int count = specpdl_ptr - specpdl; | |
11995 | ||
11996 | /* Make sure any errors from previous requests have been dealt with. */ | |
11997 | XSync (dpy, False); | |
11998 | ||
11999 | record_unwind_protect (x_catch_errors_unwind, x_error_message_string); | |
12000 | ||
12001 | x_error_message_string = make_uninit_string (X_ERROR_MESSAGE_SIZE); | |
12002 | XSTRING (x_error_message_string)->data[0] = 0; | |
12003 | ||
12004 | return count; | |
12005 | } | |
12006 | ||
12007 | /* Unbind the binding that we made to check for X errors. */ | |
12008 | ||
12009 | static Lisp_Object | |
12010 | x_catch_errors_unwind (old_val) | |
12011 | Lisp_Object old_val; | |
12012 | { | |
12013 | x_error_message_string = old_val; | |
12014 | return Qnil; | |
12015 | } | |
12016 | ||
12017 | /* If any X protocol errors have arrived since the last call to | |
12018 | x_catch_errors or x_check_errors, signal an Emacs error using | |
12019 | sprintf (a buffer, FORMAT, the x error message text) as the text. */ | |
12020 | ||
12021 | void | |
12022 | x_check_errors (dpy, format) | |
12023 | Display *dpy; | |
12024 | char *format; | |
12025 | { | |
12026 | /* Make sure to catch any errors incurred so far. */ | |
12027 | XSync (dpy, False); | |
12028 | ||
12029 | if (XSTRING (x_error_message_string)->data[0]) | |
12030 | error (format, XSTRING (x_error_message_string)->data); | |
12031 | } | |
12032 | ||
9829ddba RS |
12033 | /* Nonzero if we had any X protocol errors |
12034 | since we did x_catch_errors on DPY. */ | |
e99db5a1 RS |
12035 | |
12036 | int | |
12037 | x_had_errors_p (dpy) | |
12038 | Display *dpy; | |
12039 | { | |
12040 | /* Make sure to catch any errors incurred so far. */ | |
12041 | XSync (dpy, False); | |
12042 | ||
12043 | return XSTRING (x_error_message_string)->data[0] != 0; | |
12044 | } | |
12045 | ||
9829ddba RS |
12046 | /* Forget about any errors we have had, since we did x_catch_errors on DPY. */ |
12047 | ||
06a2c219 | 12048 | void |
9829ddba RS |
12049 | x_clear_errors (dpy) |
12050 | Display *dpy; | |
12051 | { | |
12052 | XSTRING (x_error_message_string)->data[0] = 0; | |
12053 | } | |
12054 | ||
e99db5a1 RS |
12055 | /* Stop catching X protocol errors and let them make Emacs die. |
12056 | DPY should be the display that was passed to x_catch_errors. | |
12057 | COUNT should be the value that was returned by | |
12058 | the corresponding call to x_catch_errors. */ | |
12059 | ||
12060 | void | |
12061 | x_uncatch_errors (dpy, count) | |
12062 | Display *dpy; | |
12063 | int count; | |
12064 | { | |
12065 | unbind_to (count, Qnil); | |
12066 | } | |
12067 | ||
12068 | #if 0 | |
12069 | static unsigned int x_wire_count; | |
12070 | x_trace_wire () | |
12071 | { | |
12072 | fprintf (stderr, "Lib call: %d\n", ++x_wire_count); | |
12073 | } | |
12074 | #endif /* ! 0 */ | |
12075 | ||
12076 | \f | |
12077 | /* Handle SIGPIPE, which can happen when the connection to a server | |
12078 | simply goes away. SIGPIPE is handled by x_connection_signal. | |
12079 | Don't need to do anything, because the write which caused the | |
12080 | SIGPIPE will fail, causing Xlib to invoke the X IO error handler, | |
06a2c219 | 12081 | which will do the appropriate cleanup for us. */ |
e99db5a1 RS |
12082 | |
12083 | static SIGTYPE | |
12084 | x_connection_signal (signalnum) /* If we don't have an argument, */ | |
06a2c219 | 12085 | int signalnum; /* some compilers complain in signal calls. */ |
e99db5a1 RS |
12086 | { |
12087 | #ifdef USG | |
12088 | /* USG systems forget handlers when they are used; | |
12089 | must reestablish each time */ | |
12090 | signal (signalnum, x_connection_signal); | |
12091 | #endif /* USG */ | |
12092 | } | |
0da1ab50 | 12093 | |
e99db5a1 | 12094 | \f |
0da1ab50 GM |
12095 | /************************************************************************ |
12096 | Handling X errors | |
12097 | ************************************************************************/ | |
4746118a | 12098 | |
f0e299de GM |
12099 | /* Error message passed to x_connection_closed. */ |
12100 | ||
12101 | static char *error_msg; | |
12102 | ||
a7248e4f | 12103 | /* Function installed as fatal_error_signal_hook in |
f0e299de GM |
12104 | x_connection_closed. Print the X error message, and exit normally, |
12105 | instead of dumping core when XtCloseDisplay fails. */ | |
12106 | ||
12107 | static void | |
12108 | x_fatal_error_signal () | |
12109 | { | |
12110 | fprintf (stderr, "%s\n", error_msg); | |
12111 | exit (70); | |
12112 | } | |
12113 | ||
0da1ab50 GM |
12114 | /* Handle the loss of connection to display DPY. ERROR_MESSAGE is |
12115 | the text of an error message that lead to the connection loss. */ | |
16bd92ea | 12116 | |
4746118a | 12117 | static SIGTYPE |
5978125e GM |
12118 | x_connection_closed (dpy, error_message) |
12119 | Display *dpy; | |
7a13e894 | 12120 | char *error_message; |
4746118a | 12121 | { |
5978125e | 12122 | struct x_display_info *dpyinfo = x_display_info_for_display (dpy); |
7a13e894 | 12123 | Lisp_Object frame, tail; |
0da1ab50 | 12124 | int count; |
0da1ab50 | 12125 | |
f0e299de GM |
12126 | error_msg = (char *) alloca (strlen (error_message) + 1); |
12127 | strcpy (error_msg, error_message); | |
1a532e54 GM |
12128 | handling_signal = 0; |
12129 | ||
0da1ab50 GM |
12130 | /* Prevent being called recursively because of an error condition |
12131 | below. Otherwise, we might end up with printing ``can't find per | |
12132 | display information'' in the recursive call instead of printing | |
12133 | the original message here. */ | |
12134 | count = x_catch_errors (dpy); | |
12135 | ||
8a4f36cc GM |
12136 | /* We have to close the display to inform Xt that it doesn't |
12137 | exist anymore. If we don't, Xt will continue to wait for | |
12138 | events from the display. As a consequence, a sequence of | |
12139 | ||
12140 | M-x make-frame-on-display RET :1 RET | |
12141 | ...kill the new frame, so that we get an IO error... | |
12142 | M-x make-frame-on-display RET :1 RET | |
12143 | ||
12144 | will indefinitely wait in Xt for events for display `:1', opened | |
12145 | in the first class to make-frame-on-display. | |
6186a4a0 | 12146 | |
8a4f36cc GM |
12147 | Closing the display is reported to lead to a bus error on |
12148 | OpenWindows in certain situations. I suspect that is a bug | |
12149 | in OpenWindows. I don't know how to cicumvent it here. */ | |
12150 | ||
f613a4c8 | 12151 | #ifdef USE_X_TOOLKIT |
ae24cb3b GM |
12152 | /* If DPYINFO is null, this means we didn't open the display |
12153 | in the first place, so don't try to close it. */ | |
12154 | if (dpyinfo) | |
f0e299de GM |
12155 | { |
12156 | extern void (*fatal_error_signal_hook) P_ ((void)); | |
12157 | fatal_error_signal_hook = x_fatal_error_signal; | |
12158 | XtCloseDisplay (dpy); | |
12159 | fatal_error_signal_hook = NULL; | |
12160 | } | |
f613a4c8 | 12161 | #endif |
adabc3a9 | 12162 | |
8a4f36cc | 12163 | /* Indicate that this display is dead. */ |
9e80b57d KR |
12164 | if (dpyinfo) |
12165 | dpyinfo->display = 0; | |
6186a4a0 | 12166 | |
06a2c219 | 12167 | /* First delete frames whose mini-buffers are on frames |
7a13e894 RS |
12168 | that are on the dead display. */ |
12169 | FOR_EACH_FRAME (tail, frame) | |
12170 | { | |
12171 | Lisp_Object minibuf_frame; | |
12172 | minibuf_frame | |
12173 | = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame)))); | |
f48f33ca RS |
12174 | if (FRAME_X_P (XFRAME (frame)) |
12175 | && FRAME_X_P (XFRAME (minibuf_frame)) | |
12176 | && ! EQ (frame, minibuf_frame) | |
12177 | && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame)) == dpyinfo) | |
7a13e894 RS |
12178 | Fdelete_frame (frame, Qt); |
12179 | } | |
12180 | ||
12181 | /* Now delete all remaining frames on the dead display. | |
06a2c219 | 12182 | We are now sure none of these is used as the mini-buffer |
7a13e894 RS |
12183 | for another frame that we need to delete. */ |
12184 | FOR_EACH_FRAME (tail, frame) | |
f48f33ca RS |
12185 | if (FRAME_X_P (XFRAME (frame)) |
12186 | && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) | |
07a7096a KH |
12187 | { |
12188 | /* Set this to t so that Fdelete_frame won't get confused | |
12189 | trying to find a replacement. */ | |
12190 | FRAME_KBOARD (XFRAME (frame))->Vdefault_minibuffer_frame = Qt; | |
12191 | Fdelete_frame (frame, Qt); | |
12192 | } | |
7a13e894 | 12193 | |
482a1bd2 KH |
12194 | if (dpyinfo) |
12195 | x_delete_display (dpyinfo); | |
7a13e894 | 12196 | |
0da1ab50 GM |
12197 | x_uncatch_errors (dpy, count); |
12198 | ||
7a13e894 RS |
12199 | if (x_display_list == 0) |
12200 | { | |
f0e299de | 12201 | fprintf (stderr, "%s\n", error_msg); |
7a13e894 RS |
12202 | shut_down_emacs (0, 0, Qnil); |
12203 | exit (70); | |
12204 | } | |
12ba150f | 12205 | |
7a13e894 RS |
12206 | /* Ordinary stack unwind doesn't deal with these. */ |
12207 | #ifdef SIGIO | |
12208 | sigunblock (sigmask (SIGIO)); | |
12209 | #endif | |
12210 | sigunblock (sigmask (SIGALRM)); | |
12211 | TOTALLY_UNBLOCK_INPUT; | |
12212 | ||
aa4d9a9e | 12213 | clear_waiting_for_input (); |
f0e299de | 12214 | error ("%s", error_msg); |
4746118a JB |
12215 | } |
12216 | ||
0da1ab50 | 12217 | |
7a13e894 RS |
12218 | /* This is the usual handler for X protocol errors. |
12219 | It kills all frames on the display that we got the error for. | |
12220 | If that was the only one, it prints an error message and kills Emacs. */ | |
12221 | ||
06a2c219 | 12222 | static void |
c118dd06 JB |
12223 | x_error_quitter (display, error) |
12224 | Display *display; | |
12225 | XErrorEvent *error; | |
12226 | { | |
7a13e894 | 12227 | char buf[256], buf1[356]; |
dc6f92b8 | 12228 | |
58769bee | 12229 | /* Note that there is no real way portable across R3/R4 to get the |
c118dd06 | 12230 | original error handler. */ |
dc6f92b8 | 12231 | |
c118dd06 | 12232 | XGetErrorText (display, error->error_code, buf, sizeof (buf)); |
0a0fdc70 | 12233 | sprintf (buf1, "X protocol error: %s on protocol request %d", |
c118dd06 | 12234 | buf, error->request_code); |
7a13e894 | 12235 | x_connection_closed (display, buf1); |
dc6f92b8 JB |
12236 | } |
12237 | ||
0da1ab50 | 12238 | |
e99db5a1 RS |
12239 | /* This is the first-level handler for X protocol errors. |
12240 | It calls x_error_quitter or x_error_catcher. */ | |
7a13e894 | 12241 | |
8922af5f | 12242 | static int |
e99db5a1 | 12243 | x_error_handler (display, error) |
8922af5f | 12244 | Display *display; |
e99db5a1 | 12245 | XErrorEvent *error; |
8922af5f | 12246 | { |
e99db5a1 RS |
12247 | if (! NILP (x_error_message_string)) |
12248 | x_error_catcher (display, error); | |
12249 | else | |
12250 | x_error_quitter (display, error); | |
06a2c219 | 12251 | return 0; |
f9e24cb9 | 12252 | } |
c118dd06 | 12253 | |
e99db5a1 RS |
12254 | /* This is the handler for X IO errors, always. |
12255 | It kills all frames on the display that we lost touch with. | |
12256 | If that was the only one, it prints an error message and kills Emacs. */ | |
7a13e894 | 12257 | |
c118dd06 | 12258 | static int |
e99db5a1 | 12259 | x_io_error_quitter (display) |
c118dd06 | 12260 | Display *display; |
c118dd06 | 12261 | { |
e99db5a1 | 12262 | char buf[256]; |
dc6f92b8 | 12263 | |
e99db5a1 RS |
12264 | sprintf (buf, "Connection lost to X server `%s'", DisplayString (display)); |
12265 | x_connection_closed (display, buf); | |
06a2c219 | 12266 | return 0; |
dc6f92b8 | 12267 | } |
dc6f92b8 | 12268 | \f |
f451eb13 JB |
12269 | /* Changing the font of the frame. */ |
12270 | ||
76bcdf39 RS |
12271 | /* Give frame F the font named FONTNAME as its default font, and |
12272 | return the full name of that font. FONTNAME may be a wildcard | |
12273 | pattern; in that case, we choose some font that fits the pattern. | |
12274 | The return value shows which font we chose. */ | |
12275 | ||
b5cf7a0e | 12276 | Lisp_Object |
f676886a JB |
12277 | x_new_font (f, fontname) |
12278 | struct frame *f; | |
dc6f92b8 JB |
12279 | register char *fontname; |
12280 | { | |
dc43ef94 | 12281 | struct font_info *fontp |
ee569018 | 12282 | = FS_LOAD_FONT (f, 0, fontname, -1); |
dc6f92b8 | 12283 | |
dc43ef94 KH |
12284 | if (!fontp) |
12285 | return Qnil; | |
2224a5fc | 12286 | |
dc43ef94 | 12287 | f->output_data.x->font = (XFontStruct *) (fontp->font); |
b4192550 | 12288 | f->output_data.x->baseline_offset = fontp->baseline_offset; |
dc43ef94 | 12289 | f->output_data.x->fontset = -1; |
976b73d7 KS |
12290 | |
12291 | x_compute_fringe_widths (f, 1); | |
12292 | ||
b2cad826 KH |
12293 | /* Compute the scroll bar width in character columns. */ |
12294 | if (f->scroll_bar_pixel_width > 0) | |
12295 | { | |
7556890b | 12296 | int wid = FONT_WIDTH (f->output_data.x->font); |
b2cad826 KH |
12297 | f->scroll_bar_cols = (f->scroll_bar_pixel_width + wid-1) / wid; |
12298 | } | |
12299 | else | |
4e61bddf RS |
12300 | { |
12301 | int wid = FONT_WIDTH (f->output_data.x->font); | |
12302 | f->scroll_bar_cols = (14 + wid - 1) / wid; | |
12303 | } | |
b2cad826 | 12304 | |
f676886a | 12305 | /* Now make the frame display the given font. */ |
c118dd06 | 12306 | if (FRAME_X_WINDOW (f) != 0) |
dc6f92b8 | 12307 | { |
7556890b RS |
12308 | XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->normal_gc, |
12309 | f->output_data.x->font->fid); | |
12310 | XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->reverse_gc, | |
12311 | f->output_data.x->font->fid); | |
12312 | XSetFont (FRAME_X_DISPLAY (f), f->output_data.x->cursor_gc, | |
12313 | f->output_data.x->font->fid); | |
f676886a | 12314 | |
a27f9f86 | 12315 | frame_update_line_height (f); |
3497f73e GM |
12316 | |
12317 | /* Don't change the size of a tip frame; there's no point in | |
12318 | doing it because it's done in Fx_show_tip, and it leads to | |
12319 | problems because the tip frame has no widget. */ | |
12320 | if (NILP (tip_frame) || XFRAME (tip_frame) != f) | |
12321 | x_set_window_size (f, 0, f->width, f->height); | |
dc6f92b8 | 12322 | } |
a27f9f86 RS |
12323 | else |
12324 | /* If we are setting a new frame's font for the first time, | |
12325 | there are no faces yet, so this font's height is the line height. */ | |
7556890b | 12326 | f->output_data.x->line_height = FONT_HEIGHT (f->output_data.x->font); |
dc6f92b8 | 12327 | |
dc43ef94 KH |
12328 | return build_string (fontp->full_name); |
12329 | } | |
12330 | ||
12331 | /* Give frame F the fontset named FONTSETNAME as its default font, and | |
12332 | return the full name of that fontset. FONTSETNAME may be a wildcard | |
b5210ea7 KH |
12333 | pattern; in that case, we choose some fontset that fits the pattern. |
12334 | The return value shows which fontset we chose. */ | |
b5cf7a0e | 12335 | |
dc43ef94 KH |
12336 | Lisp_Object |
12337 | x_new_fontset (f, fontsetname) | |
12338 | struct frame *f; | |
12339 | char *fontsetname; | |
12340 | { | |
ee569018 | 12341 | int fontset = fs_query_fontset (build_string (fontsetname), 0); |
dc43ef94 | 12342 | Lisp_Object result; |
b5cf7a0e | 12343 | |
dc43ef94 KH |
12344 | if (fontset < 0) |
12345 | return Qnil; | |
b5cf7a0e | 12346 | |
2da424f1 KH |
12347 | if (f->output_data.x->fontset == fontset) |
12348 | /* This fontset is already set in frame F. There's nothing more | |
12349 | to do. */ | |
ee569018 | 12350 | return fontset_name (fontset); |
dc43ef94 | 12351 | |
ee569018 | 12352 | result = x_new_font (f, (XSTRING (fontset_ascii (fontset))->data)); |
dc43ef94 KH |
12353 | |
12354 | if (!STRINGP (result)) | |
12355 | /* Can't load ASCII font. */ | |
12356 | return Qnil; | |
12357 | ||
12358 | /* Since x_new_font doesn't update any fontset information, do it now. */ | |
12359 | f->output_data.x->fontset = fontset; | |
dc43ef94 | 12360 | |
f5d11644 GM |
12361 | #ifdef HAVE_X_I18N |
12362 | if (FRAME_XIC (f) | |
12363 | && (FRAME_XIC_STYLE (f) & (XIMPreeditPosition | XIMStatusArea))) | |
ee569018 | 12364 | xic_set_xfontset (f, XSTRING (fontset_ascii (fontset))->data); |
f5d11644 GM |
12365 | #endif |
12366 | ||
dc43ef94 | 12367 | return build_string (fontsetname); |
dc6f92b8 | 12368 | } |
f5d11644 | 12369 | |
976b73d7 KS |
12370 | /* Compute actual fringe widths */ |
12371 | ||
12372 | void | |
12373 | x_compute_fringe_widths (f, redraw) | |
12374 | struct frame *f; | |
12375 | int redraw; | |
12376 | { | |
12377 | int o_left = f->output_data.x->left_fringe_width; | |
12378 | int o_right = f->output_data.x->right_fringe_width; | |
12379 | int o_cols = f->output_data.x->fringe_cols; | |
12380 | ||
12381 | Lisp_Object left_fringe = Fassq (Qleft_fringe, f->param_alist); | |
12382 | Lisp_Object right_fringe = Fassq (Qright_fringe, f->param_alist); | |
12383 | int left_fringe_width, right_fringe_width; | |
12384 | ||
12385 | if (!NILP (left_fringe)) | |
12386 | left_fringe = Fcdr (left_fringe); | |
12387 | if (!NILP (right_fringe)) | |
12388 | right_fringe = Fcdr (right_fringe); | |
12389 | ||
12390 | left_fringe_width = ((NILP (left_fringe) || !INTEGERP (left_fringe)) ? 8 : | |
12391 | XINT (left_fringe)); | |
12392 | right_fringe_width = ((NILP (right_fringe) || !INTEGERP (right_fringe)) ? 8 : | |
12393 | XINT (right_fringe)); | |
12394 | ||
12395 | if (left_fringe_width || right_fringe_width) | |
12396 | { | |
12397 | int left_wid = left_fringe_width >= 0 ? left_fringe_width : -left_fringe_width; | |
12398 | int right_wid = right_fringe_width >= 0 ? right_fringe_width : -right_fringe_width; | |
12399 | int conf_wid = left_wid + right_wid; | |
12400 | int font_wid = FONT_WIDTH (f->output_data.x->font); | |
12401 | int cols = (left_wid + right_wid + font_wid-1) / font_wid; | |
12402 | int real_wid = cols * font_wid; | |
12403 | if (left_wid && right_wid) | |
12404 | { | |
12405 | if (left_fringe_width < 0) | |
12406 | { | |
12407 | /* Left fringe width is fixed, adjust right fringe if necessary */ | |
12408 | f->output_data.x->left_fringe_width = left_wid; | |
12409 | f->output_data.x->right_fringe_width = real_wid - left_wid; | |
12410 | } | |
12411 | else if (right_fringe_width < 0) | |
12412 | { | |
12413 | /* Right fringe width is fixed, adjust left fringe if necessary */ | |
12414 | f->output_data.x->left_fringe_width = real_wid - right_wid; | |
12415 | f->output_data.x->right_fringe_width = right_wid; | |
12416 | } | |
12417 | else | |
12418 | { | |
12419 | /* Adjust both fringes with an equal amount. | |
12420 | Note that we are doing integer arithmetic here, so don't | |
12421 | lose a pixel if the total width is an odd number. */ | |
12422 | int fill = real_wid - conf_wid; | |
12423 | f->output_data.x->left_fringe_width = left_wid + fill/2; | |
12424 | f->output_data.x->right_fringe_width = right_wid + fill - fill/2; | |
12425 | } | |
12426 | } | |
12427 | else if (left_fringe_width) | |
12428 | { | |
12429 | f->output_data.x->left_fringe_width = real_wid; | |
12430 | f->output_data.x->right_fringe_width = 0; | |
12431 | } | |
12432 | else | |
12433 | { | |
12434 | f->output_data.x->left_fringe_width = 0; | |
12435 | f->output_data.x->right_fringe_width = real_wid; | |
12436 | } | |
12437 | f->output_data.x->fringe_cols = cols; | |
12438 | f->output_data.x->fringes_extra = real_wid; | |
12439 | } | |
12440 | else | |
12441 | { | |
12442 | f->output_data.x->left_fringe_width = 0; | |
12443 | f->output_data.x->right_fringe_width = 0; | |
12444 | f->output_data.x->fringe_cols = 0; | |
12445 | f->output_data.x->fringes_extra = 0; | |
12446 | } | |
12447 | ||
12448 | if (redraw && FRAME_VISIBLE_P (f)) | |
12449 | if (o_left != f->output_data.x->left_fringe_width || | |
12450 | o_right != f->output_data.x->right_fringe_width || | |
12451 | o_cols != f->output_data.x->fringe_cols) | |
12452 | redraw_frame (f); | |
12453 | } | |
f5d11644 GM |
12454 | \f |
12455 | /*********************************************************************** | |
12456 | X Input Methods | |
12457 | ***********************************************************************/ | |
12458 | ||
12459 | #ifdef HAVE_X_I18N | |
12460 | ||
12461 | #ifdef HAVE_X11R6 | |
12462 | ||
12463 | /* XIM destroy callback function, which is called whenever the | |
12464 | connection to input method XIM dies. CLIENT_DATA contains a | |
12465 | pointer to the x_display_info structure corresponding to XIM. */ | |
12466 | ||
12467 | static void | |
12468 | xim_destroy_callback (xim, client_data, call_data) | |
12469 | XIM xim; | |
12470 | XPointer client_data; | |
12471 | XPointer call_data; | |
12472 | { | |
12473 | struct x_display_info *dpyinfo = (struct x_display_info *) client_data; | |
12474 | Lisp_Object frame, tail; | |
12475 | ||
12476 | BLOCK_INPUT; | |
12477 | ||
12478 | /* No need to call XDestroyIC.. */ | |
12479 | FOR_EACH_FRAME (tail, frame) | |
12480 | { | |
12481 | struct frame *f = XFRAME (frame); | |
12482 | if (FRAME_X_DISPLAY_INFO (f) == dpyinfo) | |
12483 | { | |
12484 | FRAME_XIC (f) = NULL; | |
12485 | if (FRAME_XIC_FONTSET (f)) | |
12486 | { | |
12487 | XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); | |
12488 | FRAME_XIC_FONTSET (f) = NULL; | |
12489 | } | |
12490 | } | |
12491 | } | |
12492 | ||
12493 | /* No need to call XCloseIM. */ | |
12494 | dpyinfo->xim = NULL; | |
12495 | XFree (dpyinfo->xim_styles); | |
12496 | UNBLOCK_INPUT; | |
12497 | } | |
12498 | ||
12499 | #endif /* HAVE_X11R6 */ | |
12500 | ||
12501 | /* Open the connection to the XIM server on display DPYINFO. | |
12502 | RESOURCE_NAME is the resource name Emacs uses. */ | |
12503 | ||
12504 | static void | |
12505 | xim_open_dpy (dpyinfo, resource_name) | |
12506 | struct x_display_info *dpyinfo; | |
12507 | char *resource_name; | |
12508 | { | |
287f7dd6 | 12509 | #ifdef USE_XIM |
f5d11644 GM |
12510 | XIM xim; |
12511 | ||
12512 | xim = XOpenIM (dpyinfo->display, dpyinfo->xrdb, resource_name, EMACS_CLASS); | |
12513 | dpyinfo->xim = xim; | |
12514 | ||
12515 | if (xim) | |
12516 | { | |
f5d11644 GM |
12517 | #ifdef HAVE_X11R6 |
12518 | XIMCallback destroy; | |
12519 | #endif | |
12520 | ||
12521 | /* Get supported styles and XIM values. */ | |
12522 | XGetIMValues (xim, XNQueryInputStyle, &dpyinfo->xim_styles, NULL); | |
12523 | ||
12524 | #ifdef HAVE_X11R6 | |
12525 | destroy.callback = xim_destroy_callback; | |
12526 | destroy.client_data = (XPointer)dpyinfo; | |
cea2ad76 | 12527 | /* This isn't prototyped in OSF 5.0. */ |
f5d11644 GM |
12528 | XSetIMValues (xim, XNDestroyCallback, &destroy, NULL); |
12529 | #endif | |
12530 | } | |
287f7dd6 GM |
12531 | |
12532 | #else /* not USE_XIM */ | |
12533 | dpyinfo->xim = NULL; | |
12534 | #endif /* not USE_XIM */ | |
f5d11644 GM |
12535 | } |
12536 | ||
12537 | ||
b9de836c | 12538 | #ifdef HAVE_X11R6_XIM |
f5d11644 GM |
12539 | |
12540 | struct xim_inst_t | |
12541 | { | |
12542 | struct x_display_info *dpyinfo; | |
12543 | char *resource_name; | |
12544 | }; | |
12545 | ||
12546 | /* XIM instantiate callback function, which is called whenever an XIM | |
12547 | server is available. DISPLAY is teh display of the XIM. | |
12548 | CLIENT_DATA contains a pointer to an xim_inst_t structure created | |
12549 | when the callback was registered. */ | |
12550 | ||
12551 | static void | |
12552 | xim_instantiate_callback (display, client_data, call_data) | |
12553 | Display *display; | |
12554 | XPointer client_data; | |
12555 | XPointer call_data; | |
12556 | { | |
12557 | struct xim_inst_t *xim_inst = (struct xim_inst_t *) client_data; | |
12558 | struct x_display_info *dpyinfo = xim_inst->dpyinfo; | |
12559 | ||
12560 | /* We don't support multiple XIM connections. */ | |
12561 | if (dpyinfo->xim) | |
12562 | return; | |
12563 | ||
12564 | xim_open_dpy (dpyinfo, xim_inst->resource_name); | |
12565 | ||
12566 | /* Create XIC for the existing frames on the same display, as long | |
12567 | as they have no XIC. */ | |
12568 | if (dpyinfo->xim && dpyinfo->reference_count > 0) | |
12569 | { | |
12570 | Lisp_Object tail, frame; | |
12571 | ||
12572 | BLOCK_INPUT; | |
12573 | FOR_EACH_FRAME (tail, frame) | |
12574 | { | |
12575 | struct frame *f = XFRAME (frame); | |
12576 | ||
12577 | if (FRAME_X_DISPLAY_INFO (f) == xim_inst->dpyinfo) | |
12578 | if (FRAME_XIC (f) == NULL) | |
12579 | { | |
12580 | create_frame_xic (f); | |
12581 | if (FRAME_XIC_STYLE (f) & XIMStatusArea) | |
12582 | xic_set_statusarea (f); | |
12583 | if (FRAME_XIC_STYLE (f) & XIMPreeditPosition) | |
12584 | { | |
12585 | struct window *w = XWINDOW (f->selected_window); | |
12586 | xic_set_preeditarea (w, w->cursor.x, w->cursor.y); | |
12587 | } | |
12588 | } | |
12589 | } | |
12590 | ||
12591 | UNBLOCK_INPUT; | |
12592 | } | |
12593 | } | |
12594 | ||
b9de836c | 12595 | #endif /* HAVE_X11R6_XIM */ |
f5d11644 GM |
12596 | |
12597 | ||
12598 | /* Open a connection to the XIM server on display DPYINFO. | |
12599 | RESOURCE_NAME is the resource name for Emacs. On X11R5, open the | |
12600 | connection only at the first time. On X11R6, open the connection | |
12601 | in the XIM instantiate callback function. */ | |
12602 | ||
12603 | static void | |
12604 | xim_initialize (dpyinfo, resource_name) | |
12605 | struct x_display_info *dpyinfo; | |
12606 | char *resource_name; | |
12607 | { | |
287f7dd6 | 12608 | #ifdef USE_XIM |
b9de836c | 12609 | #ifdef HAVE_X11R6_XIM |
f5d11644 GM |
12610 | struct xim_inst_t *xim_inst; |
12611 | int len; | |
12612 | ||
12613 | dpyinfo->xim = NULL; | |
12614 | xim_inst = (struct xim_inst_t *) xmalloc (sizeof (struct xim_inst_t)); | |
12615 | xim_inst->dpyinfo = dpyinfo; | |
12616 | len = strlen (resource_name); | |
12617 | xim_inst->resource_name = (char *) xmalloc (len + 1); | |
12618 | bcopy (resource_name, xim_inst->resource_name, len + 1); | |
12619 | XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb, | |
12620 | resource_name, EMACS_CLASS, | |
12621 | xim_instantiate_callback, | |
2ebb2f8b DL |
12622 | /* Fixme: This is XPointer in |
12623 | XFree86 but (XPointer *) on | |
12624 | Tru64, at least. */ | |
12625 | (XPointer) xim_inst); | |
b9de836c | 12626 | #else /* not HAVE_X11R6_XIM */ |
f5d11644 GM |
12627 | dpyinfo->xim = NULL; |
12628 | xim_open_dpy (dpyinfo, resource_name); | |
b9de836c | 12629 | #endif /* not HAVE_X11R6_XIM */ |
287f7dd6 GM |
12630 | |
12631 | #else /* not USE_XIM */ | |
12632 | dpyinfo->xim = NULL; | |
12633 | #endif /* not USE_XIM */ | |
f5d11644 GM |
12634 | } |
12635 | ||
12636 | ||
12637 | /* Close the connection to the XIM server on display DPYINFO. */ | |
12638 | ||
12639 | static void | |
12640 | xim_close_dpy (dpyinfo) | |
12641 | struct x_display_info *dpyinfo; | |
12642 | { | |
287f7dd6 | 12643 | #ifdef USE_XIM |
b9de836c | 12644 | #ifdef HAVE_X11R6_XIM |
8a4f36cc GM |
12645 | if (dpyinfo->display) |
12646 | XUnregisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb, | |
12647 | NULL, EMACS_CLASS, | |
12648 | xim_instantiate_callback, NULL); | |
b9de836c | 12649 | #endif /* not HAVE_X11R6_XIM */ |
8a4f36cc GM |
12650 | if (dpyinfo->display) |
12651 | XCloseIM (dpyinfo->xim); | |
f5d11644 GM |
12652 | dpyinfo->xim = NULL; |
12653 | XFree (dpyinfo->xim_styles); | |
287f7dd6 | 12654 | #endif /* USE_XIM */ |
f5d11644 GM |
12655 | } |
12656 | ||
b9de836c | 12657 | #endif /* not HAVE_X11R6_XIM */ |
f5d11644 GM |
12658 | |
12659 | ||
dc6f92b8 | 12660 | \f |
2e365682 RS |
12661 | /* Calculate the absolute position in frame F |
12662 | from its current recorded position values and gravity. */ | |
12663 | ||
dfcf069d | 12664 | void |
43bca5d5 | 12665 | x_calc_absolute_position (f) |
f676886a | 12666 | struct frame *f; |
dc6f92b8 | 12667 | { |
06a2c219 | 12668 | Window child; |
6dba1858 | 12669 | int win_x = 0, win_y = 0; |
7556890b | 12670 | int flags = f->output_data.x->size_hint_flags; |
c81412a0 KH |
12671 | int this_window; |
12672 | ||
9829ddba RS |
12673 | /* We have nothing to do if the current position |
12674 | is already for the top-left corner. */ | |
12675 | if (! ((flags & XNegative) || (flags & YNegative))) | |
12676 | return; | |
12677 | ||
c81412a0 | 12678 | #ifdef USE_X_TOOLKIT |
7556890b | 12679 | this_window = XtWindow (f->output_data.x->widget); |
c81412a0 KH |
12680 | #else |
12681 | this_window = FRAME_X_WINDOW (f); | |
12682 | #endif | |
6dba1858 RS |
12683 | |
12684 | /* Find the position of the outside upper-left corner of | |
9829ddba RS |
12685 | the inner window, with respect to the outer window. |
12686 | But do this only if we will need the results. */ | |
7556890b | 12687 | if (f->output_data.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window) |
6dba1858 | 12688 | { |
9829ddba RS |
12689 | int count; |
12690 | ||
6dba1858 | 12691 | BLOCK_INPUT; |
9829ddba RS |
12692 | count = x_catch_errors (FRAME_X_DISPLAY (f)); |
12693 | while (1) | |
12694 | { | |
12695 | x_clear_errors (FRAME_X_DISPLAY (f)); | |
12696 | XTranslateCoordinates (FRAME_X_DISPLAY (f), | |
12697 | ||
12698 | /* From-window, to-window. */ | |
12699 | this_window, | |
12700 | f->output_data.x->parent_desc, | |
12701 | ||
12702 | /* From-position, to-position. */ | |
12703 | 0, 0, &win_x, &win_y, | |
12704 | ||
12705 | /* Child of win. */ | |
12706 | &child); | |
12707 | if (x_had_errors_p (FRAME_X_DISPLAY (f))) | |
12708 | { | |
12709 | Window newroot, newparent = 0xdeadbeef; | |
12710 | Window *newchildren; | |
2ebb2f8b | 12711 | unsigned int nchildren; |
9829ddba RS |
12712 | |
12713 | if (! XQueryTree (FRAME_X_DISPLAY (f), this_window, &newroot, | |
12714 | &newparent, &newchildren, &nchildren)) | |
12715 | break; | |
58769bee | 12716 | |
7c3c78a3 | 12717 | XFree ((char *) newchildren); |
6dba1858 | 12718 | |
9829ddba RS |
12719 | f->output_data.x->parent_desc = newparent; |
12720 | } | |
12721 | else | |
12722 | break; | |
12723 | } | |
6dba1858 | 12724 | |
9829ddba | 12725 | x_uncatch_errors (FRAME_X_DISPLAY (f), count); |
6dba1858 RS |
12726 | UNBLOCK_INPUT; |
12727 | } | |
12728 | ||
12729 | /* Treat negative positions as relative to the leftmost bottommost | |
12730 | position that fits on the screen. */ | |
20f55f9a | 12731 | if (flags & XNegative) |
7556890b | 12732 | f->output_data.x->left_pos = (FRAME_X_DISPLAY_INFO (f)->width |
2e365682 RS |
12733 | - 2 * f->output_data.x->border_width - win_x |
12734 | - PIXEL_WIDTH (f) | |
12735 | + f->output_data.x->left_pos); | |
dc6f92b8 | 12736 | |
7708ced0 GM |
12737 | { |
12738 | int height = PIXEL_HEIGHT (f); | |
06a2c219 | 12739 | |
7708ced0 GM |
12740 | #if defined USE_X_TOOLKIT && defined USE_MOTIF |
12741 | /* Something is fishy here. When using Motif, starting Emacs with | |
12742 | `-g -0-0', the frame appears too low by a few pixels. | |
12743 | ||
12744 | This seems to be so because initially, while Emacs is starting, | |
12745 | the column widget's height and the frame's pixel height are | |
12746 | different. The column widget's height is the right one. In | |
12747 | later invocations, when Emacs is up, the frame's pixel height | |
12748 | is right, though. | |
12749 | ||
12750 | It's not obvious where the initial small difference comes from. | |
12751 | 2000-12-01, gerd. */ | |
12752 | ||
12753 | XtVaGetValues (f->output_data.x->column_widget, XtNheight, &height, NULL); | |
06a2c219 | 12754 | #endif |
2e365682 | 12755 | |
7708ced0 GM |
12756 | if (flags & YNegative) |
12757 | f->output_data.x->top_pos = (FRAME_X_DISPLAY_INFO (f)->height | |
12758 | - 2 * f->output_data.x->border_width | |
12759 | - win_y | |
12760 | - height | |
12761 | + f->output_data.x->top_pos); | |
12762 | } | |
12763 | ||
3a35ab44 RS |
12764 | /* The left_pos and top_pos |
12765 | are now relative to the top and left screen edges, | |
12766 | so the flags should correspond. */ | |
7556890b | 12767 | f->output_data.x->size_hint_flags &= ~ (XNegative | YNegative); |
dc6f92b8 JB |
12768 | } |
12769 | ||
3a35ab44 RS |
12770 | /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position, |
12771 | to really change the position, and 0 when calling from | |
12772 | x_make_frame_visible (in that case, XOFF and YOFF are the current | |
aa3ff7c9 KH |
12773 | position values). It is -1 when calling from x_set_frame_parameters, |
12774 | which means, do adjust for borders but don't change the gravity. */ | |
3a35ab44 | 12775 | |
dfcf069d | 12776 | void |
dc05a16b | 12777 | x_set_offset (f, xoff, yoff, change_gravity) |
f676886a | 12778 | struct frame *f; |
dc6f92b8 | 12779 | register int xoff, yoff; |
dc05a16b | 12780 | int change_gravity; |
dc6f92b8 | 12781 | { |
4a4cbdd5 KH |
12782 | int modified_top, modified_left; |
12783 | ||
aa3ff7c9 | 12784 | if (change_gravity > 0) |
3a35ab44 | 12785 | { |
7556890b RS |
12786 | f->output_data.x->top_pos = yoff; |
12787 | f->output_data.x->left_pos = xoff; | |
12788 | f->output_data.x->size_hint_flags &= ~ (XNegative | YNegative); | |
3a35ab44 | 12789 | if (xoff < 0) |
7556890b | 12790 | f->output_data.x->size_hint_flags |= XNegative; |
3a35ab44 | 12791 | if (yoff < 0) |
7556890b RS |
12792 | f->output_data.x->size_hint_flags |= YNegative; |
12793 | f->output_data.x->win_gravity = NorthWestGravity; | |
3a35ab44 | 12794 | } |
43bca5d5 | 12795 | x_calc_absolute_position (f); |
dc6f92b8 JB |
12796 | |
12797 | BLOCK_INPUT; | |
c32cdd9a | 12798 | x_wm_set_size_hint (f, (long) 0, 0); |
3a35ab44 | 12799 | |
7556890b RS |
12800 | modified_left = f->output_data.x->left_pos; |
12801 | modified_top = f->output_data.x->top_pos; | |
e73ec6fa RS |
12802 | #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal, |
12803 | this seems to be unnecessary and incorrect. rms, 4/17/97. */ | |
12804 | /* It is a mystery why we need to add the border_width here | |
12805 | when the frame is already visible, but experiment says we do. */ | |
aa3ff7c9 | 12806 | if (change_gravity != 0) |
4a4cbdd5 | 12807 | { |
7556890b RS |
12808 | modified_left += f->output_data.x->border_width; |
12809 | modified_top += f->output_data.x->border_width; | |
4a4cbdd5 | 12810 | } |
e73ec6fa | 12811 | #endif |
4a4cbdd5 | 12812 | |
3afe33e7 | 12813 | #ifdef USE_X_TOOLKIT |
7556890b | 12814 | XMoveWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget), |
4a4cbdd5 | 12815 | modified_left, modified_top); |
3afe33e7 | 12816 | #else /* not USE_X_TOOLKIT */ |
334208b7 | 12817 | XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
4a4cbdd5 | 12818 | modified_left, modified_top); |
3afe33e7 | 12819 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
12820 | UNBLOCK_INPUT; |
12821 | } | |
12822 | ||
d0fa3e56 EZ |
12823 | /* Check if we need to resize the frame due to a fullscreen request. |
12824 | If so needed, resize the frame. */ | |
12825 | static void | |
12826 | x_check_fullscreen (f) | |
12827 | struct frame *f; | |
12828 | { | |
12829 | if (f->output_data.x->want_fullscreen & FULLSCREEN_BOTH) | |
12830 | { | |
12831 | int width, height, ign; | |
12832 | ||
12833 | x_real_positions (f, &f->output_data.x->left_pos, | |
12834 | &f->output_data.x->top_pos); | |
12835 | ||
12836 | x_fullscreen_adjust (f, &width, &height, &ign, &ign); | |
12837 | ||
12838 | /* We do not need to move the window, it shall be taken care of | |
12839 | when setting WM manager hints. | |
12840 | If the frame is visible already, the position is checked by | |
12841 | x_check_fullscreen_move. */ | |
12842 | if (f->width != width || f->height != height) | |
12843 | { | |
12844 | change_frame_size (f, height, width, 0, 1, 0); | |
12845 | SET_FRAME_GARBAGED (f); | |
12846 | cancel_mouse_face (f); | |
12847 | ||
12848 | /* Wait for the change of frame size to occur */ | |
12849 | f->output_data.x->want_fullscreen |= FULLSCREEN_WAIT; | |
12850 | ||
12851 | } | |
12852 | } | |
12853 | } | |
12854 | ||
12855 | /* If frame parameters are set after the frame is mapped, we need to move | |
12856 | the window. This is done in xfns.c. | |
12857 | Some window managers moves the window to the right position, some | |
12858 | moves the outer window manager window to the specified position. | |
12859 | Here we check that we are in the right spot. If not, make a second | |
12860 | move, assuming we are dealing with the second kind of window manager. */ | |
12861 | static void | |
12862 | x_check_fullscreen_move (f) | |
12863 | struct frame *f; | |
12864 | { | |
12865 | if (f->output_data.x->want_fullscreen & FULLSCREEN_MOVE_WAIT) | |
12866 | { | |
12867 | int expect_top = f->output_data.x->top_pos; | |
12868 | int expect_left = f->output_data.x->left_pos; | |
12869 | ||
12870 | if (f->output_data.x->want_fullscreen & FULLSCREEN_HEIGHT) | |
12871 | expect_top = 0; | |
12872 | if (f->output_data.x->want_fullscreen & FULLSCREEN_WIDTH) | |
12873 | expect_left = 0; | |
12874 | ||
12875 | if (expect_top != f->output_data.x->top_pos | |
12876 | || expect_left != f->output_data.x->left_pos) | |
12877 | x_set_offset (f, expect_left, expect_top, 1); | |
12878 | ||
12879 | /* Just do this once */ | |
12880 | f->output_data.x->want_fullscreen &= ~FULLSCREEN_MOVE_WAIT; | |
12881 | } | |
12882 | } | |
12883 | ||
12884 | ||
12885 | /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the | |
12886 | wanted positions of the WM window (not emacs window). | |
12887 | Return in *WIDTH and *HEIGHT the wanted width and height of Emacs | |
12888 | window (FRAME_X_WINDOW). | |
12889 | */ | |
12890 | void | |
12891 | x_fullscreen_adjust (f, width, height, top_pos, left_pos) | |
12892 | struct frame *f; | |
12893 | int *width; | |
12894 | int *height; | |
12895 | int *top_pos; | |
12896 | int *left_pos; | |
12897 | { | |
12898 | int newwidth = f->width, newheight = f->height; | |
12899 | ||
12900 | *top_pos = f->output_data.x->top_pos; | |
12901 | *left_pos = f->output_data.x->left_pos; | |
12902 | ||
12903 | if (f->output_data.x->want_fullscreen & FULLSCREEN_HEIGHT) | |
12904 | { | |
12905 | int ph; | |
12906 | ||
12907 | ph = FRAME_X_DISPLAY_INFO (f)->height; | |
12908 | newheight = PIXEL_TO_CHAR_HEIGHT (f, ph); | |
12909 | ph = CHAR_TO_PIXEL_HEIGHT (f, newheight) | |
12910 | - f->output_data.x->y_pixels_diff; | |
12911 | newheight = PIXEL_TO_CHAR_HEIGHT (f, ph); | |
12912 | *top_pos = 0; | |
12913 | } | |
12914 | ||
12915 | if (f->output_data.x->want_fullscreen & FULLSCREEN_WIDTH) | |
12916 | { | |
12917 | int pw; | |
12918 | ||
12919 | pw = FRAME_X_DISPLAY_INFO (f)->width; | |
12920 | newwidth = PIXEL_TO_CHAR_WIDTH (f, pw); | |
12921 | pw = CHAR_TO_PIXEL_WIDTH (f, newwidth) | |
12922 | - f->output_data.x->x_pixels_diff; | |
12923 | newwidth = PIXEL_TO_CHAR_WIDTH (f, pw); | |
12924 | *left_pos = 0; | |
12925 | } | |
12926 | ||
12927 | *width = newwidth; | |
12928 | *height = newheight; | |
12929 | } | |
12930 | ||
dc6f92b8 | 12931 | |
499b1844 GM |
12932 | /* Change the size of frame F's X window to COLS/ROWS in the case F |
12933 | doesn't have a widget. If CHANGE_GRAVITY is 1, we change to | |
12934 | top-left-corner window gravity for this size change and subsequent | |
12935 | size changes. Otherwise we leave the window gravity unchanged. */ | |
12936 | ||
12937 | static void | |
12938 | x_set_window_size_1 (f, change_gravity, cols, rows) | |
f676886a | 12939 | struct frame *f; |
bc20ebbf | 12940 | int change_gravity; |
b1c884c3 | 12941 | int cols, rows; |
dc6f92b8 JB |
12942 | { |
12943 | int pixelwidth, pixelheight; | |
80fd1fe2 | 12944 | |
b1c884c3 | 12945 | check_frame_size (f, &rows, &cols); |
7556890b | 12946 | f->output_data.x->vertical_scroll_bar_extra |
b2cad826 KH |
12947 | = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f) |
12948 | ? 0 | |
12949 | : FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0 | |
480407eb | 12950 | ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f) |
7556890b | 12951 | : (FRAME_SCROLL_BAR_COLS (f) * FONT_WIDTH (f->output_data.x->font))); |
976b73d7 KS |
12952 | |
12953 | x_compute_fringe_widths (f, 0); | |
12954 | ||
f451eb13 JB |
12955 | pixelwidth = CHAR_TO_PIXEL_WIDTH (f, cols); |
12956 | pixelheight = CHAR_TO_PIXEL_HEIGHT (f, rows); | |
dc6f92b8 | 12957 | |
7556890b | 12958 | f->output_data.x->win_gravity = NorthWestGravity; |
c32cdd9a | 12959 | x_wm_set_size_hint (f, (long) 0, 0); |
6ccf47d1 | 12960 | |
334208b7 RS |
12961 | XSync (FRAME_X_DISPLAY (f), False); |
12962 | XResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
12963 | pixelwidth, pixelheight); | |
b1c884c3 JB |
12964 | |
12965 | /* Now, strictly speaking, we can't be sure that this is accurate, | |
12966 | but the window manager will get around to dealing with the size | |
12967 | change request eventually, and we'll hear how it went when the | |
dbc4e1c1 JB |
12968 | ConfigureNotify event gets here. |
12969 | ||
12970 | We could just not bother storing any of this information here, | |
12971 | and let the ConfigureNotify event set everything up, but that | |
fddd5ceb | 12972 | might be kind of confusing to the Lisp code, since size changes |
dbc4e1c1 | 12973 | wouldn't be reported in the frame parameters until some random |
fddd5ceb RS |
12974 | point in the future when the ConfigureNotify event arrives. |
12975 | ||
12976 | We pass 1 for DELAY since we can't run Lisp code inside of | |
12977 | a BLOCK_INPUT. */ | |
7d1e984f | 12978 | change_frame_size (f, rows, cols, 0, 1, 0); |
b1c884c3 JB |
12979 | PIXEL_WIDTH (f) = pixelwidth; |
12980 | PIXEL_HEIGHT (f) = pixelheight; | |
12981 | ||
aee9a898 RS |
12982 | /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to |
12983 | receive in the ConfigureNotify event; if we get what we asked | |
12984 | for, then the event won't cause the screen to become garbaged, so | |
12985 | we have to make sure to do it here. */ | |
12986 | SET_FRAME_GARBAGED (f); | |
12987 | ||
12988 | XFlush (FRAME_X_DISPLAY (f)); | |
499b1844 GM |
12989 | } |
12990 | ||
12991 | ||
12992 | /* Call this to change the size of frame F's x-window. | |
12993 | If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity | |
12994 | for this size change and subsequent size changes. | |
12995 | Otherwise we leave the window gravity unchanged. */ | |
aee9a898 | 12996 | |
499b1844 GM |
12997 | void |
12998 | x_set_window_size (f, change_gravity, cols, rows) | |
12999 | struct frame *f; | |
13000 | int change_gravity; | |
13001 | int cols, rows; | |
13002 | { | |
13003 | BLOCK_INPUT; | |
13004 | ||
13005 | #ifdef USE_X_TOOLKIT | |
13006 | ||
f1f4d345 | 13007 | if (f->output_data.x->widget != NULL) |
499b1844 GM |
13008 | { |
13009 | /* The x and y position of the widget is clobbered by the | |
13010 | call to XtSetValues within EmacsFrameSetCharSize. | |
13011 | This is a real kludge, but I don't understand Xt so I can't | |
13012 | figure out a correct fix. Can anyone else tell me? -- rms. */ | |
13013 | int xpos = f->output_data.x->widget->core.x; | |
13014 | int ypos = f->output_data.x->widget->core.y; | |
13015 | EmacsFrameSetCharSize (f->output_data.x->edit_widget, cols, rows); | |
13016 | f->output_data.x->widget->core.x = xpos; | |
13017 | f->output_data.x->widget->core.y = ypos; | |
13018 | } | |
13019 | else | |
13020 | x_set_window_size_1 (f, change_gravity, cols, rows); | |
13021 | ||
13022 | #else /* not USE_X_TOOLKIT */ | |
13023 | ||
13024 | x_set_window_size_1 (f, change_gravity, cols, rows); | |
13025 | ||
aee9a898 RS |
13026 | #endif /* not USE_X_TOOLKIT */ |
13027 | ||
4d73d038 | 13028 | /* If cursor was outside the new size, mark it as off. */ |
06a2c219 | 13029 | mark_window_cursors_off (XWINDOW (f->root_window)); |
4d73d038 | 13030 | |
aee9a898 RS |
13031 | /* Clear out any recollection of where the mouse highlighting was, |
13032 | since it might be in a place that's outside the new frame size. | |
13033 | Actually checking whether it is outside is a pain in the neck, | |
13034 | so don't try--just let the highlighting be done afresh with new size. */ | |
e687d06e | 13035 | cancel_mouse_face (f); |
dbc4e1c1 | 13036 | |
dc6f92b8 JB |
13037 | UNBLOCK_INPUT; |
13038 | } | |
dc6f92b8 | 13039 | \f |
d047c4eb | 13040 | /* Mouse warping. */ |
dc6f92b8 | 13041 | |
9b378208 | 13042 | void |
f676886a JB |
13043 | x_set_mouse_position (f, x, y) |
13044 | struct frame *f; | |
dc6f92b8 JB |
13045 | int x, y; |
13046 | { | |
13047 | int pix_x, pix_y; | |
13048 | ||
7556890b RS |
13049 | pix_x = CHAR_TO_PIXEL_COL (f, x) + FONT_WIDTH (f->output_data.x->font) / 2; |
13050 | pix_y = CHAR_TO_PIXEL_ROW (f, y) + f->output_data.x->line_height / 2; | |
f451eb13 JB |
13051 | |
13052 | if (pix_x < 0) pix_x = 0; | |
13053 | if (pix_x > PIXEL_WIDTH (f)) pix_x = PIXEL_WIDTH (f); | |
13054 | ||
13055 | if (pix_y < 0) pix_y = 0; | |
13056 | if (pix_y > PIXEL_HEIGHT (f)) pix_y = PIXEL_HEIGHT (f); | |
dc6f92b8 JB |
13057 | |
13058 | BLOCK_INPUT; | |
dc6f92b8 | 13059 | |
334208b7 RS |
13060 | XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), |
13061 | 0, 0, 0, 0, pix_x, pix_y); | |
dc6f92b8 JB |
13062 | UNBLOCK_INPUT; |
13063 | } | |
13064 | ||
9b378208 RS |
13065 | /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */ |
13066 | ||
13067 | void | |
13068 | x_set_mouse_pixel_position (f, pix_x, pix_y) | |
13069 | struct frame *f; | |
13070 | int pix_x, pix_y; | |
13071 | { | |
13072 | BLOCK_INPUT; | |
13073 | ||
334208b7 RS |
13074 | XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), |
13075 | 0, 0, 0, 0, pix_x, pix_y); | |
9b378208 RS |
13076 | UNBLOCK_INPUT; |
13077 | } | |
d047c4eb KH |
13078 | \f |
13079 | /* focus shifting, raising and lowering. */ | |
9b378208 | 13080 | |
dfcf069d | 13081 | void |
f676886a JB |
13082 | x_focus_on_frame (f) |
13083 | struct frame *f; | |
dc6f92b8 | 13084 | { |
1fb20991 | 13085 | #if 0 /* This proves to be unpleasant. */ |
f676886a | 13086 | x_raise_frame (f); |
1fb20991 | 13087 | #endif |
6d4238f3 JB |
13088 | #if 0 |
13089 | /* I don't think that the ICCCM allows programs to do things like this | |
13090 | without the interaction of the window manager. Whatever you end up | |
f676886a | 13091 | doing with this code, do it to x_unfocus_frame too. */ |
334208b7 | 13092 | XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
dc6f92b8 | 13093 | RevertToPointerRoot, CurrentTime); |
c118dd06 | 13094 | #endif /* ! 0 */ |
dc6f92b8 JB |
13095 | } |
13096 | ||
dfcf069d | 13097 | void |
f676886a JB |
13098 | x_unfocus_frame (f) |
13099 | struct frame *f; | |
dc6f92b8 | 13100 | { |
6d4238f3 | 13101 | #if 0 |
f676886a | 13102 | /* Look at the remarks in x_focus_on_frame. */ |
0f941935 | 13103 | if (FRAME_X_DISPLAY_INFO (f)->x_focus_frame == f) |
334208b7 | 13104 | XSetInputFocus (FRAME_X_DISPLAY (f), PointerRoot, |
dc6f92b8 | 13105 | RevertToPointerRoot, CurrentTime); |
c118dd06 | 13106 | #endif /* ! 0 */ |
dc6f92b8 JB |
13107 | } |
13108 | ||
f676886a | 13109 | /* Raise frame F. */ |
dc6f92b8 | 13110 | |
dfcf069d | 13111 | void |
f676886a JB |
13112 | x_raise_frame (f) |
13113 | struct frame *f; | |
dc6f92b8 | 13114 | { |
3a88c238 | 13115 | if (f->async_visible) |
dc6f92b8 JB |
13116 | { |
13117 | BLOCK_INPUT; | |
3afe33e7 | 13118 | #ifdef USE_X_TOOLKIT |
7556890b | 13119 | XRaiseWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget)); |
3afe33e7 | 13120 | #else /* not USE_X_TOOLKIT */ |
334208b7 | 13121 | XRaiseWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
3afe33e7 | 13122 | #endif /* not USE_X_TOOLKIT */ |
334208b7 | 13123 | XFlush (FRAME_X_DISPLAY (f)); |
dc6f92b8 JB |
13124 | UNBLOCK_INPUT; |
13125 | } | |
13126 | } | |
13127 | ||
f676886a | 13128 | /* Lower frame F. */ |
dc6f92b8 | 13129 | |
dfcf069d | 13130 | void |
f676886a JB |
13131 | x_lower_frame (f) |
13132 | struct frame *f; | |
dc6f92b8 | 13133 | { |
3a88c238 | 13134 | if (f->async_visible) |
dc6f92b8 JB |
13135 | { |
13136 | BLOCK_INPUT; | |
3afe33e7 | 13137 | #ifdef USE_X_TOOLKIT |
7556890b | 13138 | XLowerWindow (FRAME_X_DISPLAY (f), XtWindow (f->output_data.x->widget)); |
3afe33e7 | 13139 | #else /* not USE_X_TOOLKIT */ |
334208b7 | 13140 | XLowerWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
3afe33e7 | 13141 | #endif /* not USE_X_TOOLKIT */ |
334208b7 | 13142 | XFlush (FRAME_X_DISPLAY (f)); |
dc6f92b8 JB |
13143 | UNBLOCK_INPUT; |
13144 | } | |
13145 | } | |
13146 | ||
dbc4e1c1 | 13147 | static void |
6b0442dc | 13148 | XTframe_raise_lower (f, raise_flag) |
dbc4e1c1 | 13149 | FRAME_PTR f; |
6b0442dc | 13150 | int raise_flag; |
dbc4e1c1 | 13151 | { |
6b0442dc | 13152 | if (raise_flag) |
dbc4e1c1 JB |
13153 | x_raise_frame (f); |
13154 | else | |
13155 | x_lower_frame (f); | |
13156 | } | |
d047c4eb KH |
13157 | \f |
13158 | /* Change of visibility. */ | |
dc6f92b8 | 13159 | |
9382638d KH |
13160 | /* This tries to wait until the frame is really visible. |
13161 | However, if the window manager asks the user where to position | |
13162 | the frame, this will return before the user finishes doing that. | |
13163 | The frame will not actually be visible at that time, | |
13164 | but it will become visible later when the window manager | |
13165 | finishes with it. */ | |
13166 | ||
dfcf069d | 13167 | void |
f676886a JB |
13168 | x_make_frame_visible (f) |
13169 | struct frame *f; | |
dc6f92b8 | 13170 | { |
990ba854 | 13171 | Lisp_Object type; |
1aa6072f | 13172 | int original_top, original_left; |
31be9251 GM |
13173 | int retry_count = 2; |
13174 | ||
13175 | retry: | |
dc6f92b8 | 13176 | |
dc6f92b8 | 13177 | BLOCK_INPUT; |
dc6f92b8 | 13178 | |
990ba854 RS |
13179 | type = x_icon_type (f); |
13180 | if (!NILP (type)) | |
13181 | x_bitmap_icon (f, type); | |
bdcd49ba | 13182 | |
f676886a | 13183 | if (! FRAME_VISIBLE_P (f)) |
90e65f07 | 13184 | { |
1aa6072f RS |
13185 | /* We test FRAME_GARBAGED_P here to make sure we don't |
13186 | call x_set_offset a second time | |
13187 | if we get to x_make_frame_visible a second time | |
13188 | before the window gets really visible. */ | |
13189 | if (! FRAME_ICONIFIED_P (f) | |
13190 | && ! f->output_data.x->asked_for_visible) | |
13191 | x_set_offset (f, f->output_data.x->left_pos, f->output_data.x->top_pos, 0); | |
13192 | ||
13193 | f->output_data.x->asked_for_visible = 1; | |
13194 | ||
90e65f07 | 13195 | if (! EQ (Vx_no_window_manager, Qt)) |
f676886a | 13196 | x_wm_set_window_state (f, NormalState); |
3afe33e7 | 13197 | #ifdef USE_X_TOOLKIT |
d7a38a2e | 13198 | /* This was XtPopup, but that did nothing for an iconified frame. */ |
7556890b | 13199 | XtMapWidget (f->output_data.x->widget); |
3afe33e7 | 13200 | #else /* not USE_X_TOOLKIT */ |
7f9c7f94 | 13201 | XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
3afe33e7 | 13202 | #endif /* not USE_X_TOOLKIT */ |
0134a210 RS |
13203 | #if 0 /* This seems to bring back scroll bars in the wrong places |
13204 | if the window configuration has changed. They seem | |
13205 | to come back ok without this. */ | |
ab648270 | 13206 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
334208b7 | 13207 | XMapSubwindows (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
0134a210 | 13208 | #endif |
90e65f07 | 13209 | } |
dc6f92b8 | 13210 | |
334208b7 | 13211 | XFlush (FRAME_X_DISPLAY (f)); |
90e65f07 | 13212 | |
0dacf791 RS |
13213 | /* Synchronize to ensure Emacs knows the frame is visible |
13214 | before we do anything else. We do this loop with input not blocked | |
13215 | so that incoming events are handled. */ | |
13216 | { | |
13217 | Lisp_Object frame; | |
12ce2351 | 13218 | int count; |
28c01ffe RS |
13219 | /* This must be before UNBLOCK_INPUT |
13220 | since events that arrive in response to the actions above | |
13221 | will set it when they are handled. */ | |
13222 | int previously_visible = f->output_data.x->has_been_visible; | |
1aa6072f RS |
13223 | |
13224 | original_left = f->output_data.x->left_pos; | |
13225 | original_top = f->output_data.x->top_pos; | |
c0a04927 RS |
13226 | |
13227 | /* This must come after we set COUNT. */ | |
13228 | UNBLOCK_INPUT; | |
13229 | ||
2745e6c4 | 13230 | /* We unblock here so that arriving X events are processed. */ |
1aa6072f | 13231 | |
dcb07ae9 RS |
13232 | /* Now move the window back to where it was "supposed to be". |
13233 | But don't do it if the gravity is negative. | |
13234 | When the gravity is negative, this uses a position | |
28c01ffe RS |
13235 | that is 3 pixels too low. Perhaps that's really the border width. |
13236 | ||
13237 | Don't do this if the window has never been visible before, | |
13238 | because the window manager may choose the position | |
13239 | and we don't want to override it. */ | |
1aa6072f | 13240 | |
4d3f5d9a | 13241 | if (! FRAME_VISIBLE_P (f) && ! FRAME_ICONIFIED_P (f) |
06c488fd | 13242 | && f->output_data.x->win_gravity == NorthWestGravity |
28c01ffe | 13243 | && previously_visible) |
1aa6072f | 13244 | { |
2745e6c4 RS |
13245 | Drawable rootw; |
13246 | int x, y; | |
13247 | unsigned int width, height, border, depth; | |
06a2c219 | 13248 | |
1aa6072f | 13249 | BLOCK_INPUT; |
9829ddba | 13250 | |
06a2c219 GM |
13251 | /* On some window managers (such as FVWM) moving an existing |
13252 | window, even to the same place, causes the window manager | |
13253 | to introduce an offset. This can cause the window to move | |
13254 | to an unexpected location. Check the geometry (a little | |
13255 | slow here) and then verify that the window is in the right | |
13256 | place. If the window is not in the right place, move it | |
13257 | there, and take the potential window manager hit. */ | |
2745e6c4 RS |
13258 | XGetGeometry (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), |
13259 | &rootw, &x, &y, &width, &height, &border, &depth); | |
13260 | ||
13261 | if (original_left != x || original_top != y) | |
13262 | XMoveWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), | |
13263 | original_left, original_top); | |
13264 | ||
1aa6072f RS |
13265 | UNBLOCK_INPUT; |
13266 | } | |
9829ddba | 13267 | |
e0c1aef2 | 13268 | XSETFRAME (frame, f); |
c0a04927 | 13269 | |
12ce2351 GM |
13270 | /* Wait until the frame is visible. Process X events until a |
13271 | MapNotify event has been seen, or until we think we won't get a | |
13272 | MapNotify at all.. */ | |
13273 | for (count = input_signal_count + 10; | |
13274 | input_signal_count < count && !FRAME_VISIBLE_P (f);) | |
2a6cf806 | 13275 | { |
12ce2351 | 13276 | /* Force processing of queued events. */ |
334208b7 | 13277 | x_sync (f); |
12ce2351 GM |
13278 | |
13279 | /* Machines that do polling rather than SIGIO have been | |
13280 | observed to go into a busy-wait here. So we'll fake an | |
13281 | alarm signal to let the handler know that there's something | |
13282 | to be read. We used to raise a real alarm, but it seems | |
13283 | that the handler isn't always enabled here. This is | |
13284 | probably a bug. */ | |
8b2f8d4e | 13285 | if (input_polling_used ()) |
3b2fa4e6 | 13286 | { |
12ce2351 GM |
13287 | /* It could be confusing if a real alarm arrives while |
13288 | processing the fake one. Turn it off and let the | |
13289 | handler reset it. */ | |
3e71d8f2 | 13290 | extern void poll_for_input_1 P_ ((void)); |
bffcfca9 GM |
13291 | int old_poll_suppress_count = poll_suppress_count; |
13292 | poll_suppress_count = 1; | |
13293 | poll_for_input_1 (); | |
13294 | poll_suppress_count = old_poll_suppress_count; | |
3b2fa4e6 | 13295 | } |
12ce2351 GM |
13296 | |
13297 | /* See if a MapNotify event has been processed. */ | |
13298 | FRAME_SAMPLE_VISIBILITY (f); | |
2a6cf806 | 13299 | } |
31be9251 GM |
13300 | |
13301 | /* 2000-09-28: In | |
13302 | ||
13303 | (let ((f (selected-frame))) | |
13304 | (iconify-frame f) | |
13305 | (raise-frame f)) | |
13306 | ||
13307 | the frame is not raised with various window managers on | |
13308 | FreeBSD, Linux and Solaris. It turns out that, for some | |
13309 | unknown reason, the call to XtMapWidget is completely ignored. | |
13310 | Mapping the widget a second time works. */ | |
13311 | ||
13312 | if (!FRAME_VISIBLE_P (f) && --retry_count > 0) | |
13313 | goto retry; | |
0dacf791 | 13314 | } |
dc6f92b8 JB |
13315 | } |
13316 | ||
06a2c219 | 13317 | /* Change from mapped state to withdrawn state. */ |
dc6f92b8 | 13318 | |
d047c4eb KH |
13319 | /* Make the frame visible (mapped and not iconified). */ |
13320 | ||
dfcf069d | 13321 | void |
f676886a JB |
13322 | x_make_frame_invisible (f) |
13323 | struct frame *f; | |
dc6f92b8 | 13324 | { |
546e6d5b RS |
13325 | Window window; |
13326 | ||
13327 | #ifdef USE_X_TOOLKIT | |
13328 | /* Use the frame's outermost window, not the one we normally draw on. */ | |
7556890b | 13329 | window = XtWindow (f->output_data.x->widget); |
546e6d5b RS |
13330 | #else /* not USE_X_TOOLKIT */ |
13331 | window = FRAME_X_WINDOW (f); | |
13332 | #endif /* not USE_X_TOOLKIT */ | |
dc6f92b8 | 13333 | |
9319ae23 | 13334 | /* Don't keep the highlight on an invisible frame. */ |
0f941935 KH |
13335 | if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f) |
13336 | FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0; | |
9319ae23 | 13337 | |
5627c40e | 13338 | #if 0/* This might add unreliability; I don't trust it -- rms. */ |
9319ae23 | 13339 | if (! f->async_visible && ! f->async_iconified) |
dc6f92b8 | 13340 | return; |
5627c40e | 13341 | #endif |
dc6f92b8 JB |
13342 | |
13343 | BLOCK_INPUT; | |
c118dd06 | 13344 | |
af31d76f RS |
13345 | /* Before unmapping the window, update the WM_SIZE_HINTS property to claim |
13346 | that the current position of the window is user-specified, rather than | |
13347 | program-specified, so that when the window is mapped again, it will be | |
13348 | placed at the same location, without forcing the user to position it | |
13349 | by hand again (they have already done that once for this window.) */ | |
c32cdd9a | 13350 | x_wm_set_size_hint (f, (long) 0, 1); |
af31d76f | 13351 | |
c118dd06 JB |
13352 | #ifdef HAVE_X11R4 |
13353 | ||
334208b7 RS |
13354 | if (! XWithdrawWindow (FRAME_X_DISPLAY (f), window, |
13355 | DefaultScreen (FRAME_X_DISPLAY (f)))) | |
c118dd06 JB |
13356 | { |
13357 | UNBLOCK_INPUT_RESIGNAL; | |
546e6d5b | 13358 | error ("Can't notify window manager of window withdrawal"); |
c118dd06 | 13359 | } |
c118dd06 | 13360 | #else /* ! defined (HAVE_X11R4) */ |
16bd92ea | 13361 | |
c118dd06 | 13362 | /* Tell the window manager what we're going to do. */ |
dc6f92b8 JB |
13363 | if (! EQ (Vx_no_window_manager, Qt)) |
13364 | { | |
16bd92ea | 13365 | XEvent unmap; |
dc6f92b8 | 13366 | |
16bd92ea | 13367 | unmap.xunmap.type = UnmapNotify; |
546e6d5b | 13368 | unmap.xunmap.window = window; |
334208b7 | 13369 | unmap.xunmap.event = DefaultRootWindow (FRAME_X_DISPLAY (f)); |
16bd92ea | 13370 | unmap.xunmap.from_configure = False; |
334208b7 RS |
13371 | if (! XSendEvent (FRAME_X_DISPLAY (f), |
13372 | DefaultRootWindow (FRAME_X_DISPLAY (f)), | |
16bd92ea | 13373 | False, |
06a2c219 | 13374 | SubstructureRedirectMaskSubstructureNotifyMask, |
16bd92ea JB |
13375 | &unmap)) |
13376 | { | |
13377 | UNBLOCK_INPUT_RESIGNAL; | |
546e6d5b | 13378 | error ("Can't notify window manager of withdrawal"); |
16bd92ea | 13379 | } |
dc6f92b8 JB |
13380 | } |
13381 | ||
16bd92ea | 13382 | /* Unmap the window ourselves. Cheeky! */ |
334208b7 | 13383 | XUnmapWindow (FRAME_X_DISPLAY (f), window); |
c118dd06 | 13384 | #endif /* ! defined (HAVE_X11R4) */ |
dc6f92b8 | 13385 | |
5627c40e RS |
13386 | /* We can't distinguish this from iconification |
13387 | just by the event that we get from the server. | |
13388 | So we can't win using the usual strategy of letting | |
13389 | FRAME_SAMPLE_VISIBILITY set this. So do it by hand, | |
13390 | and synchronize with the server to make sure we agree. */ | |
13391 | f->visible = 0; | |
13392 | FRAME_ICONIFIED_P (f) = 0; | |
13393 | f->async_visible = 0; | |
13394 | f->async_iconified = 0; | |
13395 | ||
334208b7 | 13396 | x_sync (f); |
5627c40e | 13397 | |
dc6f92b8 JB |
13398 | UNBLOCK_INPUT; |
13399 | } | |
13400 | ||
06a2c219 | 13401 | /* Change window state from mapped to iconified. */ |
dc6f92b8 | 13402 | |
dfcf069d | 13403 | void |
f676886a JB |
13404 | x_iconify_frame (f) |
13405 | struct frame *f; | |
dc6f92b8 | 13406 | { |
3afe33e7 | 13407 | int result; |
990ba854 | 13408 | Lisp_Object type; |
dc6f92b8 | 13409 | |
9319ae23 | 13410 | /* Don't keep the highlight on an invisible frame. */ |
0f941935 KH |
13411 | if (FRAME_X_DISPLAY_INFO (f)->x_highlight_frame == f) |
13412 | FRAME_X_DISPLAY_INFO (f)->x_highlight_frame = 0; | |
9319ae23 | 13413 | |
3a88c238 | 13414 | if (f->async_iconified) |
dc6f92b8 JB |
13415 | return; |
13416 | ||
3afe33e7 | 13417 | BLOCK_INPUT; |
546e6d5b | 13418 | |
9af3143a RS |
13419 | FRAME_SAMPLE_VISIBILITY (f); |
13420 | ||
990ba854 RS |
13421 | type = x_icon_type (f); |
13422 | if (!NILP (type)) | |
13423 | x_bitmap_icon (f, type); | |
bdcd49ba RS |
13424 | |
13425 | #ifdef USE_X_TOOLKIT | |
13426 | ||
546e6d5b RS |
13427 | if (! FRAME_VISIBLE_P (f)) |
13428 | { | |
13429 | if (! EQ (Vx_no_window_manager, Qt)) | |
13430 | x_wm_set_window_state (f, IconicState); | |
13431 | /* This was XtPopup, but that did nothing for an iconified frame. */ | |
7556890b | 13432 | XtMapWidget (f->output_data.x->widget); |
9cf30a30 RS |
13433 | /* The server won't give us any event to indicate |
13434 | that an invisible frame was changed to an icon, | |
13435 | so we have to record it here. */ | |
13436 | f->iconified = 1; | |
1e6bc770 | 13437 | f->visible = 1; |
9cf30a30 | 13438 | f->async_iconified = 1; |
1e6bc770 | 13439 | f->async_visible = 0; |
546e6d5b RS |
13440 | UNBLOCK_INPUT; |
13441 | return; | |
13442 | } | |
13443 | ||
334208b7 | 13444 | result = XIconifyWindow (FRAME_X_DISPLAY (f), |
7556890b | 13445 | XtWindow (f->output_data.x->widget), |
334208b7 | 13446 | DefaultScreen (FRAME_X_DISPLAY (f))); |
3afe33e7 RS |
13447 | UNBLOCK_INPUT; |
13448 | ||
13449 | if (!result) | |
546e6d5b | 13450 | error ("Can't notify window manager of iconification"); |
3afe33e7 RS |
13451 | |
13452 | f->async_iconified = 1; | |
1e6bc770 RS |
13453 | f->async_visible = 0; |
13454 | ||
8c002a25 KH |
13455 | |
13456 | BLOCK_INPUT; | |
334208b7 | 13457 | XFlush (FRAME_X_DISPLAY (f)); |
8c002a25 | 13458 | UNBLOCK_INPUT; |
3afe33e7 RS |
13459 | #else /* not USE_X_TOOLKIT */ |
13460 | ||
fd13dbb2 RS |
13461 | /* Make sure the X server knows where the window should be positioned, |
13462 | in case the user deiconifies with the window manager. */ | |
13463 | if (! FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f)) | |
7556890b | 13464 | x_set_offset (f, f->output_data.x->left_pos, f->output_data.x->top_pos, 0); |
fd13dbb2 | 13465 | |
16bd92ea JB |
13466 | /* Since we don't know which revision of X we're running, we'll use both |
13467 | the X11R3 and X11R4 techniques. I don't know if this is a good idea. */ | |
13468 | ||
13469 | /* X11R4: send a ClientMessage to the window manager using the | |
13470 | WM_CHANGE_STATE type. */ | |
13471 | { | |
13472 | XEvent message; | |
58769bee | 13473 | |
c118dd06 | 13474 | message.xclient.window = FRAME_X_WINDOW (f); |
16bd92ea | 13475 | message.xclient.type = ClientMessage; |
334208b7 | 13476 | message.xclient.message_type = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_change_state; |
16bd92ea JB |
13477 | message.xclient.format = 32; |
13478 | message.xclient.data.l[0] = IconicState; | |
13479 | ||
334208b7 RS |
13480 | if (! XSendEvent (FRAME_X_DISPLAY (f), |
13481 | DefaultRootWindow (FRAME_X_DISPLAY (f)), | |
16bd92ea JB |
13482 | False, |
13483 | SubstructureRedirectMask | SubstructureNotifyMask, | |
13484 | &message)) | |
dc6f92b8 JB |
13485 | { |
13486 | UNBLOCK_INPUT_RESIGNAL; | |
546e6d5b | 13487 | error ("Can't notify window manager of iconification"); |
dc6f92b8 | 13488 | } |
16bd92ea | 13489 | } |
dc6f92b8 | 13490 | |
58769bee | 13491 | /* X11R3: set the initial_state field of the window manager hints to |
16bd92ea JB |
13492 | IconicState. */ |
13493 | x_wm_set_window_state (f, IconicState); | |
dc6f92b8 | 13494 | |
a9c00105 RS |
13495 | if (!FRAME_VISIBLE_P (f)) |
13496 | { | |
13497 | /* If the frame was withdrawn, before, we must map it. */ | |
7f9c7f94 | 13498 | XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
a9c00105 RS |
13499 | } |
13500 | ||
3a88c238 | 13501 | f->async_iconified = 1; |
1e6bc770 | 13502 | f->async_visible = 0; |
dc6f92b8 | 13503 | |
334208b7 | 13504 | XFlush (FRAME_X_DISPLAY (f)); |
dc6f92b8 | 13505 | UNBLOCK_INPUT; |
8c002a25 | 13506 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 | 13507 | } |
19f71add | 13508 | |
d047c4eb | 13509 | \f |
19f71add | 13510 | /* Free X resources of frame F. */ |
dc6f92b8 | 13511 | |
dfcf069d | 13512 | void |
19f71add | 13513 | x_free_frame_resources (f) |
f676886a | 13514 | struct frame *f; |
dc6f92b8 | 13515 | { |
7f9c7f94 | 13516 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
c6ea2775 EZ |
13517 | Lisp_Object bar; |
13518 | struct scroll_bar *b; | |
7f9c7f94 | 13519 | |
dc6f92b8 | 13520 | BLOCK_INPUT; |
c0ff3fab | 13521 | |
6186a4a0 RS |
13522 | /* If a display connection is dead, don't try sending more |
13523 | commands to the X server. */ | |
19f71add | 13524 | if (dpyinfo->display) |
6186a4a0 | 13525 | { |
19f71add | 13526 | if (f->output_data.x->icon_desc) |
6186a4a0 | 13527 | XDestroyWindow (FRAME_X_DISPLAY (f), f->output_data.x->icon_desc); |
c6ea2775 EZ |
13528 | |
13529 | #ifdef USE_X_TOOLKIT | |
13530 | /* Explicitly destroy the scroll bars of the frame. Without | |
13531 | this, we get "BadDrawable" errors from the toolkit later on, | |
13532 | presumably from expose events generated for the disappearing | |
13533 | toolkit scroll bars. */ | |
13534 | for (bar = FRAME_SCROLL_BARS (f); !NILP (bar); bar = b->next) | |
13535 | { | |
13536 | b = XSCROLL_BAR (bar); | |
13537 | x_scroll_bar_remove (b); | |
13538 | } | |
13539 | #endif | |
13540 | ||
31f41daf | 13541 | #ifdef HAVE_X_I18N |
f5d11644 GM |
13542 | if (FRAME_XIC (f)) |
13543 | free_frame_xic (f); | |
31f41daf | 13544 | #endif |
c6ea2775 | 13545 | |
3afe33e7 | 13546 | #ifdef USE_X_TOOLKIT |
06a2c219 | 13547 | if (f->output_data.x->widget) |
30ca89f5 GM |
13548 | { |
13549 | XtDestroyWidget (f->output_data.x->widget); | |
13550 | f->output_data.x->widget = NULL; | |
13551 | } | |
c6ea2775 EZ |
13552 | /* Tooltips don't have widgets, only a simple X window, even if |
13553 | we are using a toolkit. */ | |
13554 | else if (FRAME_X_WINDOW (f)) | |
13555 | XDestroyWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); | |
13556 | ||
6186a4a0 | 13557 | free_frame_menubar (f); |
c6ea2775 EZ |
13558 | #else /* !USE_X_TOOLKIT */ |
13559 | if (FRAME_X_WINDOW (f)) | |
13560 | XDestroyWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); | |
13561 | #endif /* !USE_X_TOOLKIT */ | |
3afe33e7 | 13562 | |
3e71d8f2 GM |
13563 | unload_color (f, f->output_data.x->foreground_pixel); |
13564 | unload_color (f, f->output_data.x->background_pixel); | |
13565 | unload_color (f, f->output_data.x->cursor_pixel); | |
13566 | unload_color (f, f->output_data.x->cursor_foreground_pixel); | |
13567 | unload_color (f, f->output_data.x->border_pixel); | |
13568 | unload_color (f, f->output_data.x->mouse_pixel); | |
c6ea2775 | 13569 | |
3e71d8f2 GM |
13570 | if (f->output_data.x->scroll_bar_background_pixel != -1) |
13571 | unload_color (f, f->output_data.x->scroll_bar_background_pixel); | |
13572 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
13573 | unload_color (f, f->output_data.x->scroll_bar_foreground_pixel); | |
7c1bef7a MB |
13574 | #ifdef USE_TOOLKIT_SCROLL_BARS |
13575 | /* Scrollbar shadow colors. */ | |
13576 | if (f->output_data.x->scroll_bar_top_shadow_pixel != -1) | |
13577 | unload_color (f, f->output_data.x->scroll_bar_top_shadow_pixel); | |
13578 | if (f->output_data.x->scroll_bar_bottom_shadow_pixel != -1) | |
13579 | unload_color (f, f->output_data.x->scroll_bar_bottom_shadow_pixel); | |
13580 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
3e71d8f2 GM |
13581 | if (f->output_data.x->white_relief.allocated_p) |
13582 | unload_color (f, f->output_data.x->white_relief.pixel); | |
13583 | if (f->output_data.x->black_relief.allocated_p) | |
13584 | unload_color (f, f->output_data.x->black_relief.pixel); | |
4ca78676 | 13585 | |
19f71add GM |
13586 | if (FRAME_FACE_CACHE (f)) |
13587 | free_frame_faces (f); | |
13588 | ||
4ca78676 | 13589 | x_free_gcs (f); |
6186a4a0 RS |
13590 | XFlush (FRAME_X_DISPLAY (f)); |
13591 | } | |
dc6f92b8 | 13592 | |
df89d8a4 | 13593 | if (f->output_data.x->saved_menu_event) |
06a2c219 | 13594 | xfree (f->output_data.x->saved_menu_event); |
0c49ce2f | 13595 | |
7556890b | 13596 | xfree (f->output_data.x); |
19f71add GM |
13597 | f->output_data.x = NULL; |
13598 | ||
0f941935 KH |
13599 | if (f == dpyinfo->x_focus_frame) |
13600 | dpyinfo->x_focus_frame = 0; | |
13601 | if (f == dpyinfo->x_focus_event_frame) | |
13602 | dpyinfo->x_focus_event_frame = 0; | |
13603 | if (f == dpyinfo->x_highlight_frame) | |
13604 | dpyinfo->x_highlight_frame = 0; | |
c0ff3fab | 13605 | |
7f9c7f94 | 13606 | if (f == dpyinfo->mouse_face_mouse_frame) |
dc05a16b | 13607 | { |
7f9c7f94 RS |
13608 | dpyinfo->mouse_face_beg_row |
13609 | = dpyinfo->mouse_face_beg_col = -1; | |
13610 | dpyinfo->mouse_face_end_row | |
13611 | = dpyinfo->mouse_face_end_col = -1; | |
13612 | dpyinfo->mouse_face_window = Qnil; | |
21323706 RS |
13613 | dpyinfo->mouse_face_deferred_gc = 0; |
13614 | dpyinfo->mouse_face_mouse_frame = 0; | |
dc05a16b | 13615 | } |
0134a210 | 13616 | |
c0ff3fab | 13617 | UNBLOCK_INPUT; |
dc6f92b8 | 13618 | } |
19f71add GM |
13619 | |
13620 | ||
13621 | /* Destroy the X window of frame F. */ | |
13622 | ||
13623 | void | |
13624 | x_destroy_window (f) | |
13625 | struct frame *f; | |
13626 | { | |
13627 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
13628 | ||
13629 | /* If a display connection is dead, don't try sending more | |
13630 | commands to the X server. */ | |
13631 | if (dpyinfo->display != 0) | |
13632 | x_free_frame_resources (f); | |
13633 | ||
13634 | dpyinfo->reference_count--; | |
13635 | } | |
13636 | ||
dc6f92b8 | 13637 | \f |
f451eb13 JB |
13638 | /* Setting window manager hints. */ |
13639 | ||
af31d76f RS |
13640 | /* Set the normal size hints for the window manager, for frame F. |
13641 | FLAGS is the flags word to use--or 0 meaning preserve the flags | |
13642 | that the window now has. | |
13643 | If USER_POSITION is nonzero, we set the USPosition | |
13644 | flag (this is useful when FLAGS is 0). */ | |
6dba1858 | 13645 | |
dfcf069d | 13646 | void |
af31d76f | 13647 | x_wm_set_size_hint (f, flags, user_position) |
f676886a | 13648 | struct frame *f; |
af31d76f RS |
13649 | long flags; |
13650 | int user_position; | |
dc6f92b8 JB |
13651 | { |
13652 | XSizeHints size_hints; | |
3afe33e7 RS |
13653 | |
13654 | #ifdef USE_X_TOOLKIT | |
7e4f2521 FP |
13655 | Arg al[2]; |
13656 | int ac = 0; | |
13657 | Dimension widget_width, widget_height; | |
7556890b | 13658 | Window window = XtWindow (f->output_data.x->widget); |
3afe33e7 | 13659 | #else /* not USE_X_TOOLKIT */ |
c118dd06 | 13660 | Window window = FRAME_X_WINDOW (f); |
3afe33e7 | 13661 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 | 13662 | |
b72a58fd RS |
13663 | /* Setting PMaxSize caused various problems. */ |
13664 | size_hints.flags = PResizeInc | PMinSize /* | PMaxSize */; | |
dc6f92b8 | 13665 | |
7556890b RS |
13666 | size_hints.x = f->output_data.x->left_pos; |
13667 | size_hints.y = f->output_data.x->top_pos; | |
7553a6b7 | 13668 | |
7e4f2521 FP |
13669 | #ifdef USE_X_TOOLKIT |
13670 | XtSetArg (al[ac], XtNwidth, &widget_width); ac++; | |
13671 | XtSetArg (al[ac], XtNheight, &widget_height); ac++; | |
7556890b | 13672 | XtGetValues (f->output_data.x->widget, al, ac); |
7e4f2521 FP |
13673 | size_hints.height = widget_height; |
13674 | size_hints.width = widget_width; | |
13675 | #else /* not USE_X_TOOLKIT */ | |
f676886a JB |
13676 | size_hints.height = PIXEL_HEIGHT (f); |
13677 | size_hints.width = PIXEL_WIDTH (f); | |
7e4f2521 | 13678 | #endif /* not USE_X_TOOLKIT */ |
7553a6b7 | 13679 | |
7556890b RS |
13680 | size_hints.width_inc = FONT_WIDTH (f->output_data.x->font); |
13681 | size_hints.height_inc = f->output_data.x->line_height; | |
334208b7 RS |
13682 | size_hints.max_width |
13683 | = FRAME_X_DISPLAY_INFO (f)->width - CHAR_TO_PIXEL_WIDTH (f, 0); | |
13684 | size_hints.max_height | |
13685 | = FRAME_X_DISPLAY_INFO (f)->height - CHAR_TO_PIXEL_HEIGHT (f, 0); | |
0134a210 | 13686 | |
d067ea8b KH |
13687 | /* Calculate the base and minimum sizes. |
13688 | ||
13689 | (When we use the X toolkit, we don't do it here. | |
13690 | Instead we copy the values that the widgets are using, below.) */ | |
13691 | #ifndef USE_X_TOOLKIT | |
b1c884c3 | 13692 | { |
b0342f17 | 13693 | int base_width, base_height; |
0134a210 | 13694 | int min_rows = 0, min_cols = 0; |
b0342f17 | 13695 | |
f451eb13 JB |
13696 | base_width = CHAR_TO_PIXEL_WIDTH (f, 0); |
13697 | base_height = CHAR_TO_PIXEL_HEIGHT (f, 0); | |
b0342f17 | 13698 | |
0134a210 | 13699 | check_frame_size (f, &min_rows, &min_cols); |
b0342f17 | 13700 | |
0134a210 RS |
13701 | /* The window manager uses the base width hints to calculate the |
13702 | current number of rows and columns in the frame while | |
13703 | resizing; min_width and min_height aren't useful for this | |
13704 | purpose, since they might not give the dimensions for a | |
13705 | zero-row, zero-column frame. | |
58769bee | 13706 | |
0134a210 RS |
13707 | We use the base_width and base_height members if we have |
13708 | them; otherwise, we set the min_width and min_height members | |
13709 | to the size for a zero x zero frame. */ | |
b0342f17 JB |
13710 | |
13711 | #ifdef HAVE_X11R4 | |
0134a210 RS |
13712 | size_hints.flags |= PBaseSize; |
13713 | size_hints.base_width = base_width; | |
13714 | size_hints.base_height = base_height; | |
13715 | size_hints.min_width = base_width + min_cols * size_hints.width_inc; | |
13716 | size_hints.min_height = base_height + min_rows * size_hints.height_inc; | |
b0342f17 | 13717 | #else |
0134a210 RS |
13718 | size_hints.min_width = base_width; |
13719 | size_hints.min_height = base_height; | |
b0342f17 | 13720 | #endif |
b1c884c3 | 13721 | } |
dc6f92b8 | 13722 | |
d067ea8b | 13723 | /* If we don't need the old flags, we don't need the old hint at all. */ |
af31d76f | 13724 | if (flags) |
dc6f92b8 | 13725 | { |
d067ea8b KH |
13726 | size_hints.flags |= flags; |
13727 | goto no_read; | |
13728 | } | |
13729 | #endif /* not USE_X_TOOLKIT */ | |
13730 | ||
13731 | { | |
13732 | XSizeHints hints; /* Sometimes I hate X Windows... */ | |
13733 | long supplied_return; | |
13734 | int value; | |
af31d76f RS |
13735 | |
13736 | #ifdef HAVE_X11R4 | |
d067ea8b KH |
13737 | value = XGetWMNormalHints (FRAME_X_DISPLAY (f), window, &hints, |
13738 | &supplied_return); | |
af31d76f | 13739 | #else |
d067ea8b | 13740 | value = XGetNormalHints (FRAME_X_DISPLAY (f), window, &hints); |
af31d76f | 13741 | #endif |
58769bee | 13742 | |
d067ea8b KH |
13743 | #ifdef USE_X_TOOLKIT |
13744 | size_hints.base_height = hints.base_height; | |
13745 | size_hints.base_width = hints.base_width; | |
13746 | size_hints.min_height = hints.min_height; | |
13747 | size_hints.min_width = hints.min_width; | |
13748 | #endif | |
13749 | ||
13750 | if (flags) | |
13751 | size_hints.flags |= flags; | |
13752 | else | |
13753 | { | |
13754 | if (value == 0) | |
13755 | hints.flags = 0; | |
13756 | if (hints.flags & PSize) | |
13757 | size_hints.flags |= PSize; | |
13758 | if (hints.flags & PPosition) | |
13759 | size_hints.flags |= PPosition; | |
13760 | if (hints.flags & USPosition) | |
13761 | size_hints.flags |= USPosition; | |
13762 | if (hints.flags & USSize) | |
13763 | size_hints.flags |= USSize; | |
13764 | } | |
13765 | } | |
13766 | ||
06a2c219 | 13767 | #ifndef USE_X_TOOLKIT |
d067ea8b | 13768 | no_read: |
06a2c219 | 13769 | #endif |
0134a210 | 13770 | |
af31d76f | 13771 | #ifdef PWinGravity |
7556890b | 13772 | size_hints.win_gravity = f->output_data.x->win_gravity; |
af31d76f | 13773 | size_hints.flags |= PWinGravity; |
dc05a16b | 13774 | |
af31d76f | 13775 | if (user_position) |
6dba1858 | 13776 | { |
af31d76f RS |
13777 | size_hints.flags &= ~ PPosition; |
13778 | size_hints.flags |= USPosition; | |
6dba1858 | 13779 | } |
2554751d | 13780 | #endif /* PWinGravity */ |
6dba1858 | 13781 | |
b0342f17 | 13782 | #ifdef HAVE_X11R4 |
334208b7 | 13783 | XSetWMNormalHints (FRAME_X_DISPLAY (f), window, &size_hints); |
b0342f17 | 13784 | #else |
334208b7 | 13785 | XSetNormalHints (FRAME_X_DISPLAY (f), window, &size_hints); |
b0342f17 | 13786 | #endif |
dc6f92b8 JB |
13787 | } |
13788 | ||
13789 | /* Used for IconicState or NormalState */ | |
06a2c219 | 13790 | |
dfcf069d | 13791 | void |
f676886a JB |
13792 | x_wm_set_window_state (f, state) |
13793 | struct frame *f; | |
dc6f92b8 JB |
13794 | int state; |
13795 | { | |
3afe33e7 | 13796 | #ifdef USE_X_TOOLKIT |
546e6d5b RS |
13797 | Arg al[1]; |
13798 | ||
13799 | XtSetArg (al[0], XtNinitialState, state); | |
7556890b | 13800 | XtSetValues (f->output_data.x->widget, al, 1); |
3afe33e7 | 13801 | #else /* not USE_X_TOOLKIT */ |
c118dd06 | 13802 | Window window = FRAME_X_WINDOW (f); |
dc6f92b8 | 13803 | |
7556890b RS |
13804 | f->output_data.x->wm_hints.flags |= StateHint; |
13805 | f->output_data.x->wm_hints.initial_state = state; | |
b1c884c3 | 13806 | |
7556890b | 13807 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints); |
546e6d5b | 13808 | #endif /* not USE_X_TOOLKIT */ |
dc6f92b8 JB |
13809 | } |
13810 | ||
dfcf069d | 13811 | void |
7f2ae036 | 13812 | x_wm_set_icon_pixmap (f, pixmap_id) |
f676886a | 13813 | struct frame *f; |
7f2ae036 | 13814 | int pixmap_id; |
dc6f92b8 | 13815 | { |
d2bd6bc4 RS |
13816 | Pixmap icon_pixmap; |
13817 | ||
06a2c219 | 13818 | #ifndef USE_X_TOOLKIT |
c118dd06 | 13819 | Window window = FRAME_X_WINDOW (f); |
75231bad | 13820 | #endif |
dc6f92b8 | 13821 | |
7f2ae036 | 13822 | if (pixmap_id > 0) |
dbc4e1c1 | 13823 | { |
d2bd6bc4 | 13824 | icon_pixmap = x_bitmap_pixmap (f, pixmap_id); |
7556890b | 13825 | f->output_data.x->wm_hints.icon_pixmap = icon_pixmap; |
dbc4e1c1 JB |
13826 | } |
13827 | else | |
68568555 RS |
13828 | { |
13829 | /* It seems there is no way to turn off use of an icon pixmap. | |
13830 | The following line does it, only if no icon has yet been created, | |
13831 | for some window managers. But with mwm it crashes. | |
13832 | Some people say it should clear the IconPixmapHint bit in this case, | |
13833 | but that doesn't work, and the X consortium said it isn't the | |
13834 | right thing at all. Since there is no way to win, | |
13835 | best to explicitly give up. */ | |
13836 | #if 0 | |
13837 | f->output_data.x->wm_hints.icon_pixmap = None; | |
13838 | #else | |
13839 | return; | |
13840 | #endif | |
13841 | } | |
b1c884c3 | 13842 | |
d2bd6bc4 RS |
13843 | #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */ |
13844 | ||
13845 | { | |
13846 | Arg al[1]; | |
13847 | XtSetArg (al[0], XtNiconPixmap, icon_pixmap); | |
13848 | XtSetValues (f->output_data.x->widget, al, 1); | |
13849 | } | |
13850 | ||
13851 | #else /* not USE_X_TOOLKIT */ | |
13852 | ||
7556890b RS |
13853 | f->output_data.x->wm_hints.flags |= IconPixmapHint; |
13854 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints); | |
d2bd6bc4 RS |
13855 | |
13856 | #endif /* not USE_X_TOOLKIT */ | |
dc6f92b8 JB |
13857 | } |
13858 | ||
dfcf069d | 13859 | void |
f676886a JB |
13860 | x_wm_set_icon_position (f, icon_x, icon_y) |
13861 | struct frame *f; | |
dc6f92b8 JB |
13862 | int icon_x, icon_y; |
13863 | { | |
75231bad | 13864 | #ifdef USE_X_TOOLKIT |
7556890b | 13865 | Window window = XtWindow (f->output_data.x->widget); |
75231bad | 13866 | #else |
c118dd06 | 13867 | Window window = FRAME_X_WINDOW (f); |
75231bad | 13868 | #endif |
dc6f92b8 | 13869 | |
7556890b RS |
13870 | f->output_data.x->wm_hints.flags |= IconPositionHint; |
13871 | f->output_data.x->wm_hints.icon_x = icon_x; | |
13872 | f->output_data.x->wm_hints.icon_y = icon_y; | |
b1c884c3 | 13873 | |
7556890b | 13874 | XSetWMHints (FRAME_X_DISPLAY (f), window, &f->output_data.x->wm_hints); |
dc6f92b8 JB |
13875 | } |
13876 | ||
13877 | \f | |
06a2c219 GM |
13878 | /*********************************************************************** |
13879 | Fonts | |
13880 | ***********************************************************************/ | |
dc43ef94 KH |
13881 | |
13882 | /* Return a pointer to struct font_info of font FONT_IDX of frame F. */ | |
06a2c219 | 13883 | |
dc43ef94 KH |
13884 | struct font_info * |
13885 | x_get_font_info (f, font_idx) | |
13886 | FRAME_PTR f; | |
13887 | int font_idx; | |
13888 | { | |
13889 | return (FRAME_X_FONT_TABLE (f) + font_idx); | |
13890 | } | |
13891 | ||
13892 | ||
9c11f79e GM |
13893 | /* Return a list of names of available fonts matching PATTERN on frame F. |
13894 | ||
13895 | If SIZE is > 0, it is the size (maximum bounds width) of fonts | |
13896 | to be listed. | |
13897 | ||
13898 | SIZE < 0 means include scalable fonts. | |
13899 | ||
13900 | Frame F null means we have not yet created any frame on X, and | |
13901 | consult the first display in x_display_list. MAXNAMES sets a limit | |
13902 | on how many fonts to match. */ | |
dc43ef94 KH |
13903 | |
13904 | Lisp_Object | |
13905 | x_list_fonts (f, pattern, size, maxnames) | |
9c11f79e | 13906 | struct frame *f; |
dc43ef94 KH |
13907 | Lisp_Object pattern; |
13908 | int size; | |
13909 | int maxnames; | |
13910 | { | |
06a2c219 GM |
13911 | Lisp_Object list = Qnil, patterns, newlist = Qnil, key = Qnil; |
13912 | Lisp_Object tem, second_best; | |
9c11f79e GM |
13913 | struct x_display_info *dpyinfo |
13914 | = f ? FRAME_X_DISPLAY_INFO (f) : x_display_list; | |
13915 | Display *dpy = dpyinfo->display; | |
09c6077f | 13916 | int try_XLoadQueryFont = 0; |
53ca4657 | 13917 | int count; |
9c11f79e GM |
13918 | int allow_scalable_fonts_p = 0; |
13919 | ||
13920 | if (size < 0) | |
13921 | { | |
13922 | allow_scalable_fonts_p = 1; | |
13923 | size = 0; | |
13924 | } | |
dc43ef94 | 13925 | |
6b0efe73 | 13926 | patterns = Fassoc (pattern, Valternate_fontname_alist); |
2da424f1 KH |
13927 | if (NILP (patterns)) |
13928 | patterns = Fcons (pattern, Qnil); | |
81ba44e5 | 13929 | |
09c6077f KH |
13930 | if (maxnames == 1 && !size) |
13931 | /* We can return any single font matching PATTERN. */ | |
13932 | try_XLoadQueryFont = 1; | |
9a32686f | 13933 | |
8e713be6 | 13934 | for (; CONSP (patterns); patterns = XCDR (patterns)) |
dc43ef94 | 13935 | { |
dc43ef94 | 13936 | int num_fonts; |
3e71d8f2 | 13937 | char **names = NULL; |
dc43ef94 | 13938 | |
8e713be6 | 13939 | pattern = XCAR (patterns); |
536f4067 RS |
13940 | /* See if we cached the result for this particular query. |
13941 | The cache is an alist of the form: | |
9c11f79e GM |
13942 | ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */ |
13943 | tem = XCDR (dpyinfo->name_list_element); | |
13944 | key = Fcons (Fcons (pattern, make_number (maxnames)), | |
13945 | allow_scalable_fonts_p ? Qt : Qnil); | |
13946 | list = Fassoc (key, tem); | |
13947 | if (!NILP (list)) | |
b5210ea7 KH |
13948 | { |
13949 | list = Fcdr_safe (list); | |
13950 | /* We have a cashed list. Don't have to get the list again. */ | |
13951 | goto label_cached; | |
13952 | } | |
13953 | ||
13954 | /* At first, put PATTERN in the cache. */ | |
09c6077f | 13955 | |
dc43ef94 | 13956 | BLOCK_INPUT; |
17d85edc KH |
13957 | count = x_catch_errors (dpy); |
13958 | ||
09c6077f KH |
13959 | if (try_XLoadQueryFont) |
13960 | { | |
13961 | XFontStruct *font; | |
13962 | unsigned long value; | |
13963 | ||
13964 | font = XLoadQueryFont (dpy, XSTRING (pattern)->data); | |
17d85edc KH |
13965 | if (x_had_errors_p (dpy)) |
13966 | { | |
13967 | /* This error is perhaps due to insufficient memory on X | |
13968 | server. Let's just ignore it. */ | |
13969 | font = NULL; | |
13970 | x_clear_errors (dpy); | |
13971 | } | |
13972 | ||
09c6077f KH |
13973 | if (font |
13974 | && XGetFontProperty (font, XA_FONT, &value)) | |
13975 | { | |
13976 | char *name = (char *) XGetAtomName (dpy, (Atom) value); | |
13977 | int len = strlen (name); | |
01c752b5 | 13978 | char *tmp; |
09c6077f | 13979 | |
6f6512e8 KH |
13980 | /* If DXPC (a Differential X Protocol Compressor) |
13981 | Ver.3.7 is running, XGetAtomName will return null | |
13982 | string. We must avoid such a name. */ | |
13983 | if (len == 0) | |
13984 | try_XLoadQueryFont = 0; | |
13985 | else | |
13986 | { | |
13987 | num_fonts = 1; | |
13988 | names = (char **) alloca (sizeof (char *)); | |
13989 | /* Some systems only allow alloca assigned to a | |
13990 | simple var. */ | |
13991 | tmp = (char *) alloca (len + 1); names[0] = tmp; | |
13992 | bcopy (name, names[0], len + 1); | |
13993 | XFree (name); | |
13994 | } | |
09c6077f KH |
13995 | } |
13996 | else | |
13997 | try_XLoadQueryFont = 0; | |
a083fd23 RS |
13998 | |
13999 | if (font) | |
14000 | XFreeFont (dpy, font); | |
09c6077f KH |
14001 | } |
14002 | ||
14003 | if (!try_XLoadQueryFont) | |
17d85edc KH |
14004 | { |
14005 | /* We try at least 10 fonts because XListFonts will return | |
14006 | auto-scaled fonts at the head. */ | |
14007 | names = XListFonts (dpy, XSTRING (pattern)->data, max (maxnames, 10), | |
14008 | &num_fonts); | |
14009 | if (x_had_errors_p (dpy)) | |
14010 | { | |
14011 | /* This error is perhaps due to insufficient memory on X | |
14012 | server. Let's just ignore it. */ | |
14013 | names = NULL; | |
14014 | x_clear_errors (dpy); | |
14015 | } | |
14016 | } | |
14017 | ||
14018 | x_uncatch_errors (dpy, count); | |
dc43ef94 KH |
14019 | UNBLOCK_INPUT; |
14020 | ||
14021 | if (names) | |
14022 | { | |
14023 | int i; | |
dc43ef94 KH |
14024 | |
14025 | /* Make a list of all the fonts we got back. | |
14026 | Store that in the font cache for the display. */ | |
14027 | for (i = 0; i < num_fonts; i++) | |
14028 | { | |
06a2c219 | 14029 | int width = 0; |
dc43ef94 | 14030 | char *p = names[i]; |
06a2c219 GM |
14031 | int average_width = -1, dashes = 0; |
14032 | ||
dc43ef94 | 14033 | /* Count the number of dashes in NAMES[I]. If there are |
9c11f79e GM |
14034 | 14 dashes, and the field value following 12th dash |
14035 | (AVERAGE_WIDTH) is 0, this is a auto-scaled font which | |
14036 | is usually too ugly to be used for editing. Let's | |
14037 | ignore it. */ | |
dc43ef94 KH |
14038 | while (*p) |
14039 | if (*p++ == '-') | |
14040 | { | |
14041 | dashes++; | |
14042 | if (dashes == 7) /* PIXEL_SIZE field */ | |
14043 | width = atoi (p); | |
14044 | else if (dashes == 12) /* AVERAGE_WIDTH field */ | |
14045 | average_width = atoi (p); | |
14046 | } | |
9c11f79e GM |
14047 | |
14048 | if (allow_scalable_fonts_p | |
14049 | || dashes < 14 || average_width != 0) | |
dc43ef94 KH |
14050 | { |
14051 | tem = build_string (names[i]); | |
14052 | if (NILP (Fassoc (tem, list))) | |
14053 | { | |
14054 | if (STRINGP (Vx_pixel_size_width_font_regexp) | |
f39db7ea RS |
14055 | && ((fast_c_string_match_ignore_case |
14056 | (Vx_pixel_size_width_font_regexp, names[i])) | |
dc43ef94 KH |
14057 | >= 0)) |
14058 | /* We can set the value of PIXEL_SIZE to the | |
b5210ea7 | 14059 | width of this font. */ |
dc43ef94 KH |
14060 | list = Fcons (Fcons (tem, make_number (width)), list); |
14061 | else | |
14062 | /* For the moment, width is not known. */ | |
14063 | list = Fcons (Fcons (tem, Qnil), list); | |
14064 | } | |
14065 | } | |
14066 | } | |
e38f4136 | 14067 | |
09c6077f | 14068 | if (!try_XLoadQueryFont) |
e38f4136 GM |
14069 | { |
14070 | BLOCK_INPUT; | |
14071 | XFreeFontNames (names); | |
14072 | UNBLOCK_INPUT; | |
14073 | } | |
dc43ef94 KH |
14074 | } |
14075 | ||
b5210ea7 | 14076 | /* Now store the result in the cache. */ |
f3fbd155 KR |
14077 | XSETCDR (dpyinfo->name_list_element, |
14078 | Fcons (Fcons (key, list), XCDR (dpyinfo->name_list_element))); | |
dc43ef94 | 14079 | |
b5210ea7 KH |
14080 | label_cached: |
14081 | if (NILP (list)) continue; /* Try the remaining alternatives. */ | |
dc43ef94 | 14082 | |
b5210ea7 KH |
14083 | newlist = second_best = Qnil; |
14084 | /* Make a list of the fonts that have the right width. */ | |
8e713be6 | 14085 | for (; CONSP (list); list = XCDR (list)) |
b5210ea7 | 14086 | { |
536f4067 RS |
14087 | int found_size; |
14088 | ||
8e713be6 | 14089 | tem = XCAR (list); |
dc43ef94 | 14090 | |
8e713be6 | 14091 | if (!CONSP (tem) || NILP (XCAR (tem))) |
b5210ea7 KH |
14092 | continue; |
14093 | if (!size) | |
14094 | { | |
8e713be6 | 14095 | newlist = Fcons (XCAR (tem), newlist); |
b5210ea7 KH |
14096 | continue; |
14097 | } | |
dc43ef94 | 14098 | |
8e713be6 | 14099 | if (!INTEGERP (XCDR (tem))) |
dc43ef94 | 14100 | { |
b5210ea7 | 14101 | /* Since we have not yet known the size of this font, we |
9c11f79e | 14102 | must try slow function call XLoadQueryFont. */ |
dc43ef94 KH |
14103 | XFontStruct *thisinfo; |
14104 | ||
14105 | BLOCK_INPUT; | |
17d85edc | 14106 | count = x_catch_errors (dpy); |
dc43ef94 | 14107 | thisinfo = XLoadQueryFont (dpy, |
8e713be6 | 14108 | XSTRING (XCAR (tem))->data); |
17d85edc KH |
14109 | if (x_had_errors_p (dpy)) |
14110 | { | |
14111 | /* This error is perhaps due to insufficient memory on X | |
14112 | server. Let's just ignore it. */ | |
14113 | thisinfo = NULL; | |
14114 | x_clear_errors (dpy); | |
14115 | } | |
14116 | x_uncatch_errors (dpy, count); | |
dc43ef94 KH |
14117 | UNBLOCK_INPUT; |
14118 | ||
14119 | if (thisinfo) | |
14120 | { | |
f3fbd155 KR |
14121 | XSETCDR (tem, |
14122 | (thisinfo->min_bounds.width == 0 | |
14123 | ? make_number (0) | |
14124 | : make_number (thisinfo->max_bounds.width))); | |
e38f4136 | 14125 | BLOCK_INPUT; |
dc43ef94 | 14126 | XFreeFont (dpy, thisinfo); |
e38f4136 | 14127 | UNBLOCK_INPUT; |
dc43ef94 KH |
14128 | } |
14129 | else | |
b5210ea7 | 14130 | /* For unknown reason, the previous call of XListFont had |
06a2c219 | 14131 | returned a font which can't be opened. Record the size |
b5210ea7 | 14132 | as 0 not to try to open it again. */ |
f3fbd155 | 14133 | XSETCDR (tem, make_number (0)); |
dc43ef94 | 14134 | } |
536f4067 | 14135 | |
8e713be6 | 14136 | found_size = XINT (XCDR (tem)); |
536f4067 | 14137 | if (found_size == size) |
8e713be6 | 14138 | newlist = Fcons (XCAR (tem), newlist); |
536f4067 | 14139 | else if (found_size > 0) |
b5210ea7 | 14140 | { |
536f4067 | 14141 | if (NILP (second_best)) |
b5210ea7 | 14142 | second_best = tem; |
536f4067 RS |
14143 | else if (found_size < size) |
14144 | { | |
8e713be6 KR |
14145 | if (XINT (XCDR (second_best)) > size |
14146 | || XINT (XCDR (second_best)) < found_size) | |
536f4067 RS |
14147 | second_best = tem; |
14148 | } | |
14149 | else | |
14150 | { | |
8e713be6 KR |
14151 | if (XINT (XCDR (second_best)) > size |
14152 | && XINT (XCDR (second_best)) > found_size) | |
536f4067 RS |
14153 | second_best = tem; |
14154 | } | |
b5210ea7 KH |
14155 | } |
14156 | } | |
14157 | if (!NILP (newlist)) | |
14158 | break; | |
14159 | else if (!NILP (second_best)) | |
14160 | { | |
8e713be6 | 14161 | newlist = Fcons (XCAR (second_best), Qnil); |
b5210ea7 | 14162 | break; |
dc43ef94 | 14163 | } |
dc43ef94 KH |
14164 | } |
14165 | ||
14166 | return newlist; | |
14167 | } | |
14168 | ||
06a2c219 GM |
14169 | |
14170 | #if GLYPH_DEBUG | |
14171 | ||
14172 | /* Check that FONT is valid on frame F. It is if it can be found in F's | |
14173 | font table. */ | |
14174 | ||
14175 | static void | |
14176 | x_check_font (f, font) | |
14177 | struct frame *f; | |
14178 | XFontStruct *font; | |
14179 | { | |
14180 | int i; | |
14181 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
14182 | ||
14183 | xassert (font != NULL); | |
14184 | ||
14185 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
14186 | if (dpyinfo->font_table[i].name | |
14187 | && font == dpyinfo->font_table[i].font) | |
14188 | break; | |
14189 | ||
14190 | xassert (i < dpyinfo->n_fonts); | |
14191 | } | |
14192 | ||
14193 | #endif /* GLYPH_DEBUG != 0 */ | |
14194 | ||
14195 | /* Set *W to the minimum width, *H to the minimum font height of FONT. | |
14196 | Note: There are (broken) X fonts out there with invalid XFontStruct | |
14197 | min_bounds contents. For example, handa@etl.go.jp reports that | |
14198 | "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts | |
14199 | have font->min_bounds.width == 0. */ | |
14200 | ||
14201 | static INLINE void | |
14202 | x_font_min_bounds (font, w, h) | |
14203 | XFontStruct *font; | |
14204 | int *w, *h; | |
14205 | { | |
14206 | *h = FONT_HEIGHT (font); | |
14207 | *w = font->min_bounds.width; | |
14208 | ||
14209 | /* Try to handle the case where FONT->min_bounds has invalid | |
14210 | contents. Since the only font known to have invalid min_bounds | |
14211 | is fixed-width, use max_bounds if min_bounds seems to be invalid. */ | |
14212 | if (*w <= 0) | |
14213 | *w = font->max_bounds.width; | |
14214 | } | |
14215 | ||
14216 | ||
14217 | /* Compute the smallest character width and smallest font height over | |
14218 | all fonts available on frame F. Set the members smallest_char_width | |
14219 | and smallest_font_height in F's x_display_info structure to | |
14220 | the values computed. Value is non-zero if smallest_font_height or | |
14221 | smallest_char_width become smaller than they were before. */ | |
14222 | ||
14223 | static int | |
14224 | x_compute_min_glyph_bounds (f) | |
14225 | struct frame *f; | |
14226 | { | |
14227 | int i; | |
14228 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
14229 | XFontStruct *font; | |
14230 | int old_width = dpyinfo->smallest_char_width; | |
14231 | int old_height = dpyinfo->smallest_font_height; | |
14232 | ||
14233 | dpyinfo->smallest_font_height = 100000; | |
14234 | dpyinfo->smallest_char_width = 100000; | |
14235 | ||
14236 | for (i = 0; i < dpyinfo->n_fonts; ++i) | |
14237 | if (dpyinfo->font_table[i].name) | |
14238 | { | |
14239 | struct font_info *fontp = dpyinfo->font_table + i; | |
14240 | int w, h; | |
14241 | ||
14242 | font = (XFontStruct *) fontp->font; | |
14243 | xassert (font != (XFontStruct *) ~0); | |
14244 | x_font_min_bounds (font, &w, &h); | |
14245 | ||
14246 | dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h); | |
14247 | dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w); | |
14248 | } | |
14249 | ||
14250 | xassert (dpyinfo->smallest_char_width > 0 | |
14251 | && dpyinfo->smallest_font_height > 0); | |
14252 | ||
14253 | return (dpyinfo->n_fonts == 1 | |
14254 | || dpyinfo->smallest_char_width < old_width | |
14255 | || dpyinfo->smallest_font_height < old_height); | |
14256 | } | |
14257 | ||
14258 | ||
dc43ef94 KH |
14259 | /* Load font named FONTNAME of the size SIZE for frame F, and return a |
14260 | pointer to the structure font_info while allocating it dynamically. | |
14261 | If SIZE is 0, load any size of font. | |
14262 | If loading is failed, return NULL. */ | |
14263 | ||
14264 | struct font_info * | |
14265 | x_load_font (f, fontname, size) | |
14266 | struct frame *f; | |
14267 | register char *fontname; | |
14268 | int size; | |
14269 | { | |
14270 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
14271 | Lisp_Object font_names; | |
d645aaa4 | 14272 | int count; |
dc43ef94 KH |
14273 | |
14274 | /* Get a list of all the fonts that match this name. Once we | |
14275 | have a list of matching fonts, we compare them against the fonts | |
14276 | we already have by comparing names. */ | |
09c6077f | 14277 | font_names = x_list_fonts (f, build_string (fontname), size, 1); |
dc43ef94 KH |
14278 | |
14279 | if (!NILP (font_names)) | |
14280 | { | |
14281 | Lisp_Object tail; | |
14282 | int i; | |
14283 | ||
14284 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
8e713be6 | 14285 | for (tail = font_names; CONSP (tail); tail = XCDR (tail)) |
06a2c219 GM |
14286 | if (dpyinfo->font_table[i].name |
14287 | && (!strcmp (dpyinfo->font_table[i].name, | |
8e713be6 | 14288 | XSTRING (XCAR (tail))->data) |
06a2c219 | 14289 | || !strcmp (dpyinfo->font_table[i].full_name, |
8e713be6 | 14290 | XSTRING (XCAR (tail))->data))) |
dc43ef94 KH |
14291 | return (dpyinfo->font_table + i); |
14292 | } | |
14293 | ||
14294 | /* Load the font and add it to the table. */ | |
14295 | { | |
14296 | char *full_name; | |
14297 | XFontStruct *font; | |
14298 | struct font_info *fontp; | |
14299 | unsigned long value; | |
06a2c219 | 14300 | int i; |
dc43ef94 | 14301 | |
2da424f1 KH |
14302 | /* If we have found fonts by x_list_font, load one of them. If |
14303 | not, we still try to load a font by the name given as FONTNAME | |
14304 | because XListFonts (called in x_list_font) of some X server has | |
14305 | a bug of not finding a font even if the font surely exists and | |
14306 | is loadable by XLoadQueryFont. */ | |
e1d6d5b9 | 14307 | if (size > 0 && !NILP (font_names)) |
8e713be6 | 14308 | fontname = (char *) XSTRING (XCAR (font_names))->data; |
dc43ef94 KH |
14309 | |
14310 | BLOCK_INPUT; | |
d645aaa4 | 14311 | count = x_catch_errors (FRAME_X_DISPLAY (f)); |
dc43ef94 | 14312 | font = (XFontStruct *) XLoadQueryFont (FRAME_X_DISPLAY (f), fontname); |
d645aaa4 KH |
14313 | if (x_had_errors_p (FRAME_X_DISPLAY (f))) |
14314 | { | |
14315 | /* This error is perhaps due to insufficient memory on X | |
14316 | server. Let's just ignore it. */ | |
14317 | font = NULL; | |
14318 | x_clear_errors (FRAME_X_DISPLAY (f)); | |
14319 | } | |
14320 | x_uncatch_errors (FRAME_X_DISPLAY (f), count); | |
dc43ef94 | 14321 | UNBLOCK_INPUT; |
b5210ea7 | 14322 | if (!font) |
dc43ef94 KH |
14323 | return NULL; |
14324 | ||
06a2c219 GM |
14325 | /* Find a free slot in the font table. */ |
14326 | for (i = 0; i < dpyinfo->n_fonts; ++i) | |
14327 | if (dpyinfo->font_table[i].name == NULL) | |
14328 | break; | |
14329 | ||
14330 | /* If no free slot found, maybe enlarge the font table. */ | |
14331 | if (i == dpyinfo->n_fonts | |
14332 | && dpyinfo->n_fonts == dpyinfo->font_table_size) | |
dc43ef94 | 14333 | { |
06a2c219 GM |
14334 | int sz; |
14335 | dpyinfo->font_table_size = max (16, 2 * dpyinfo->font_table_size); | |
14336 | sz = dpyinfo->font_table_size * sizeof *dpyinfo->font_table; | |
dc43ef94 | 14337 | dpyinfo->font_table |
06a2c219 | 14338 | = (struct font_info *) xrealloc (dpyinfo->font_table, sz); |
dc43ef94 KH |
14339 | } |
14340 | ||
06a2c219 GM |
14341 | fontp = dpyinfo->font_table + i; |
14342 | if (i == dpyinfo->n_fonts) | |
14343 | ++dpyinfo->n_fonts; | |
dc43ef94 KH |
14344 | |
14345 | /* Now fill in the slots of *FONTP. */ | |
14346 | BLOCK_INPUT; | |
14347 | fontp->font = font; | |
06a2c219 | 14348 | fontp->font_idx = i; |
dc43ef94 KH |
14349 | fontp->name = (char *) xmalloc (strlen (fontname) + 1); |
14350 | bcopy (fontname, fontp->name, strlen (fontname) + 1); | |
14351 | ||
14352 | /* Try to get the full name of FONT. Put it in FULL_NAME. */ | |
14353 | full_name = 0; | |
14354 | if (XGetFontProperty (font, XA_FONT, &value)) | |
14355 | { | |
14356 | char *name = (char *) XGetAtomName (FRAME_X_DISPLAY (f), (Atom) value); | |
14357 | char *p = name; | |
14358 | int dashes = 0; | |
14359 | ||
14360 | /* Count the number of dashes in the "full name". | |
14361 | If it is too few, this isn't really the font's full name, | |
14362 | so don't use it. | |
14363 | In X11R4, the fonts did not come with their canonical names | |
14364 | stored in them. */ | |
14365 | while (*p) | |
14366 | { | |
14367 | if (*p == '-') | |
14368 | dashes++; | |
14369 | p++; | |
14370 | } | |
14371 | ||
14372 | if (dashes >= 13) | |
14373 | { | |
14374 | full_name = (char *) xmalloc (p - name + 1); | |
14375 | bcopy (name, full_name, p - name + 1); | |
14376 | } | |
14377 | ||
14378 | XFree (name); | |
14379 | } | |
14380 | ||
14381 | if (full_name != 0) | |
14382 | fontp->full_name = full_name; | |
14383 | else | |
14384 | fontp->full_name = fontp->name; | |
14385 | ||
14386 | fontp->size = font->max_bounds.width; | |
d5749adb | 14387 | fontp->height = FONT_HEIGHT (font); |
dc43ef94 | 14388 | |
2da424f1 KH |
14389 | if (NILP (font_names)) |
14390 | { | |
14391 | /* We come here because of a bug of XListFonts mentioned at | |
14392 | the head of this block. Let's store this information in | |
14393 | the cache for x_list_fonts. */ | |
14394 | Lisp_Object lispy_name = build_string (fontname); | |
14395 | Lisp_Object lispy_full_name = build_string (fontp->full_name); | |
9c11f79e GM |
14396 | Lisp_Object key = Fcons (Fcons (lispy_name, make_number (256)), |
14397 | Qnil); | |
2da424f1 | 14398 | |
f3fbd155 KR |
14399 | XSETCDR (dpyinfo->name_list_element, |
14400 | Fcons (Fcons (key, | |
14401 | Fcons (Fcons (lispy_full_name, | |
14402 | make_number (fontp->size)), | |
14403 | Qnil)), | |
14404 | XCDR (dpyinfo->name_list_element))); | |
2da424f1 | 14405 | if (full_name) |
9c11f79e GM |
14406 | { |
14407 | key = Fcons (Fcons (lispy_full_name, make_number (256)), | |
14408 | Qnil); | |
f3fbd155 KR |
14409 | XSETCDR (dpyinfo->name_list_element, |
14410 | Fcons (Fcons (key, | |
14411 | Fcons (Fcons (lispy_full_name, | |
14412 | make_number (fontp->size)), | |
14413 | Qnil)), | |
14414 | XCDR (dpyinfo->name_list_element))); | |
9c11f79e | 14415 | } |
2da424f1 KH |
14416 | } |
14417 | ||
dc43ef94 KH |
14418 | /* The slot `encoding' specifies how to map a character |
14419 | code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to | |
ee569018 KH |
14420 | the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or |
14421 | (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, | |
8ff102bd | 14422 | 2:0xA020..0xFF7F). For the moment, we don't know which charset |
06a2c219 | 14423 | uses this font. So, we set information in fontp->encoding[1] |
8ff102bd RS |
14424 | which is never used by any charset. If mapping can't be |
14425 | decided, set FONT_ENCODING_NOT_DECIDED. */ | |
dc43ef94 KH |
14426 | fontp->encoding[1] |
14427 | = (font->max_byte1 == 0 | |
14428 | /* 1-byte font */ | |
14429 | ? (font->min_char_or_byte2 < 0x80 | |
14430 | ? (font->max_char_or_byte2 < 0x80 | |
14431 | ? 0 /* 0x20..0x7F */ | |
8ff102bd | 14432 | : FONT_ENCODING_NOT_DECIDED) /* 0x20..0xFF */ |
dc43ef94 KH |
14433 | : 1) /* 0xA0..0xFF */ |
14434 | /* 2-byte font */ | |
14435 | : (font->min_byte1 < 0x80 | |
14436 | ? (font->max_byte1 < 0x80 | |
14437 | ? (font->min_char_or_byte2 < 0x80 | |
14438 | ? (font->max_char_or_byte2 < 0x80 | |
14439 | ? 0 /* 0x2020..0x7F7F */ | |
8ff102bd | 14440 | : FONT_ENCODING_NOT_DECIDED) /* 0x2020..0x7FFF */ |
dc43ef94 | 14441 | : 3) /* 0x20A0..0x7FFF */ |
8ff102bd | 14442 | : FONT_ENCODING_NOT_DECIDED) /* 0x20??..0xA0?? */ |
dc43ef94 KH |
14443 | : (font->min_char_or_byte2 < 0x80 |
14444 | ? (font->max_char_or_byte2 < 0x80 | |
14445 | ? 2 /* 0xA020..0xFF7F */ | |
8ff102bd | 14446 | : FONT_ENCODING_NOT_DECIDED) /* 0xA020..0xFFFF */ |
dc43ef94 KH |
14447 | : 1))); /* 0xA0A0..0xFFFF */ |
14448 | ||
14449 | fontp->baseline_offset | |
14450 | = (XGetFontProperty (font, dpyinfo->Xatom_MULE_BASELINE_OFFSET, &value) | |
14451 | ? (long) value : 0); | |
14452 | fontp->relative_compose | |
14453 | = (XGetFontProperty (font, dpyinfo->Xatom_MULE_RELATIVE_COMPOSE, &value) | |
14454 | ? (long) value : 0); | |
f78798df KH |
14455 | fontp->default_ascent |
14456 | = (XGetFontProperty (font, dpyinfo->Xatom_MULE_DEFAULT_ASCENT, &value) | |
14457 | ? (long) value : 0); | |
dc43ef94 | 14458 | |
06a2c219 GM |
14459 | /* Set global flag fonts_changed_p to non-zero if the font loaded |
14460 | has a character with a smaller width than any other character | |
437dfb9f | 14461 | before, or if the font loaded has a smaller height than any |
06a2c219 GM |
14462 | other font loaded before. If this happens, it will make a |
14463 | glyph matrix reallocation necessary. */ | |
437dfb9f | 14464 | fonts_changed_p |= x_compute_min_glyph_bounds (f); |
dc43ef94 | 14465 | UNBLOCK_INPUT; |
dc43ef94 KH |
14466 | return fontp; |
14467 | } | |
14468 | } | |
14469 | ||
06a2c219 GM |
14470 | |
14471 | /* Return a pointer to struct font_info of a font named FONTNAME for | |
14472 | frame F. If no such font is loaded, return NULL. */ | |
14473 | ||
dc43ef94 KH |
14474 | struct font_info * |
14475 | x_query_font (f, fontname) | |
14476 | struct frame *f; | |
14477 | register char *fontname; | |
14478 | { | |
14479 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
14480 | int i; | |
14481 | ||
14482 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
06a2c219 GM |
14483 | if (dpyinfo->font_table[i].name |
14484 | && (!strcmp (dpyinfo->font_table[i].name, fontname) | |
14485 | || !strcmp (dpyinfo->font_table[i].full_name, fontname))) | |
dc43ef94 KH |
14486 | return (dpyinfo->font_table + i); |
14487 | return NULL; | |
14488 | } | |
14489 | ||
06a2c219 GM |
14490 | |
14491 | /* Find a CCL program for a font specified by FONTP, and set the member | |
a6582676 KH |
14492 | `encoder' of the structure. */ |
14493 | ||
14494 | void | |
14495 | x_find_ccl_program (fontp) | |
14496 | struct font_info *fontp; | |
14497 | { | |
a42f54e6 | 14498 | Lisp_Object list, elt; |
a6582676 | 14499 | |
f9b5db02 | 14500 | elt = Qnil; |
8e713be6 | 14501 | for (list = Vfont_ccl_encoder_alist; CONSP (list); list = XCDR (list)) |
a6582676 | 14502 | { |
8e713be6 | 14503 | elt = XCAR (list); |
a6582676 | 14504 | if (CONSP (elt) |
8e713be6 | 14505 | && STRINGP (XCAR (elt)) |
9f2feff6 KH |
14506 | && ((fast_c_string_match_ignore_case (XCAR (elt), fontp->name) |
14507 | >= 0) | |
14508 | || (fast_c_string_match_ignore_case (XCAR (elt), fontp->full_name) | |
14509 | >= 0))) | |
a42f54e6 KH |
14510 | break; |
14511 | } | |
f9b5db02 | 14512 | |
a42f54e6 KH |
14513 | if (! NILP (list)) |
14514 | { | |
d27f8ca7 KH |
14515 | struct ccl_program *ccl |
14516 | = (struct ccl_program *) xmalloc (sizeof (struct ccl_program)); | |
a42f54e6 | 14517 | |
8e713be6 | 14518 | if (setup_ccl_program (ccl, XCDR (elt)) < 0) |
a42f54e6 KH |
14519 | xfree (ccl); |
14520 | else | |
14521 | fontp->font_encoder = ccl; | |
a6582676 KH |
14522 | } |
14523 | } | |
14524 | ||
06a2c219 | 14525 | |
dc43ef94 | 14526 | \f |
06a2c219 GM |
14527 | /*********************************************************************** |
14528 | Initialization | |
14529 | ***********************************************************************/ | |
f451eb13 | 14530 | |
3afe33e7 RS |
14531 | #ifdef USE_X_TOOLKIT |
14532 | static XrmOptionDescRec emacs_options[] = { | |
14533 | {"-geometry", ".geometry", XrmoptionSepArg, NULL}, | |
14534 | {"-iconic", ".iconic", XrmoptionNoArg, (XtPointer) "yes"}, | |
14535 | ||
14536 | {"-internal-border-width", "*EmacsScreen.internalBorderWidth", | |
14537 | XrmoptionSepArg, NULL}, | |
14538 | {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg, NULL}, | |
14539 | ||
14540 | {"-T", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
14541 | {"-wn", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
14542 | {"-title", "*EmacsShell.title", XrmoptionSepArg, (XtPointer) NULL}, | |
14543 | {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg, (XtPointer) NULL}, | |
14544 | {"-in", "*EmacsShell.iconName", XrmoptionSepArg, (XtPointer) NULL}, | |
14545 | {"-mc", "*pointerColor", XrmoptionSepArg, (XtPointer) NULL}, | |
14546 | {"-cr", "*cursorColor", XrmoptionSepArg, (XtPointer) NULL} | |
14547 | }; | |
14548 | #endif /* USE_X_TOOLKIT */ | |
14549 | ||
7a13e894 RS |
14550 | static int x_initialized; |
14551 | ||
29b38361 KH |
14552 | #ifdef MULTI_KBOARD |
14553 | /* Test whether two display-name strings agree up to the dot that separates | |
14554 | the screen number from the server number. */ | |
14555 | static int | |
14556 | same_x_server (name1, name2) | |
14557 | char *name1, *name2; | |
14558 | { | |
14559 | int seen_colon = 0; | |
cf591cc1 RS |
14560 | unsigned char *system_name = XSTRING (Vsystem_name)->data; |
14561 | int system_name_length = strlen (system_name); | |
14562 | int length_until_period = 0; | |
14563 | ||
14564 | while (system_name[length_until_period] != 0 | |
14565 | && system_name[length_until_period] != '.') | |
14566 | length_until_period++; | |
14567 | ||
14568 | /* Treat `unix' like an empty host name. */ | |
14569 | if (! strncmp (name1, "unix:", 5)) | |
14570 | name1 += 4; | |
14571 | if (! strncmp (name2, "unix:", 5)) | |
14572 | name2 += 4; | |
14573 | /* Treat this host's name like an empty host name. */ | |
14574 | if (! strncmp (name1, system_name, system_name_length) | |
14575 | && name1[system_name_length] == ':') | |
14576 | name1 += system_name_length; | |
14577 | if (! strncmp (name2, system_name, system_name_length) | |
14578 | && name2[system_name_length] == ':') | |
14579 | name2 += system_name_length; | |
14580 | /* Treat this host's domainless name like an empty host name. */ | |
14581 | if (! strncmp (name1, system_name, length_until_period) | |
14582 | && name1[length_until_period] == ':') | |
14583 | name1 += length_until_period; | |
14584 | if (! strncmp (name2, system_name, length_until_period) | |
14585 | && name2[length_until_period] == ':') | |
14586 | name2 += length_until_period; | |
14587 | ||
29b38361 KH |
14588 | for (; *name1 != '\0' && *name1 == *name2; name1++, name2++) |
14589 | { | |
14590 | if (*name1 == ':') | |
14591 | seen_colon++; | |
14592 | if (seen_colon && *name1 == '.') | |
14593 | return 1; | |
14594 | } | |
14595 | return (seen_colon | |
14596 | && (*name1 == '.' || *name1 == '\0') | |
14597 | && (*name2 == '.' || *name2 == '\0')); | |
14598 | } | |
14599 | #endif | |
14600 | ||
334208b7 | 14601 | struct x_display_info * |
1f8255f2 | 14602 | x_term_init (display_name, xrm_option, resource_name) |
334208b7 | 14603 | Lisp_Object display_name; |
1f8255f2 RS |
14604 | char *xrm_option; |
14605 | char *resource_name; | |
dc6f92b8 | 14606 | { |
334208b7 | 14607 | int connection; |
7a13e894 | 14608 | Display *dpy; |
334208b7 RS |
14609 | struct x_display_info *dpyinfo; |
14610 | XrmDatabase xrdb; | |
14611 | ||
60439948 KH |
14612 | BLOCK_INPUT; |
14613 | ||
7a13e894 RS |
14614 | if (!x_initialized) |
14615 | { | |
14616 | x_initialize (); | |
14617 | x_initialized = 1; | |
14618 | } | |
dc6f92b8 | 14619 | |
3afe33e7 | 14620 | #ifdef USE_X_TOOLKIT |
2d7fc7e8 RS |
14621 | /* weiner@footloose.sps.mot.com reports that this causes |
14622 | errors with X11R5: | |
14623 | X protocol error: BadAtom (invalid Atom parameter) | |
14624 | on protocol request 18skiloaf. | |
14625 | So let's not use it until R6. */ | |
14626 | #ifdef HAVE_X11XTR6 | |
bdcd49ba RS |
14627 | XtSetLanguageProc (NULL, NULL, NULL); |
14628 | #endif | |
14629 | ||
7f9c7f94 RS |
14630 | { |
14631 | int argc = 0; | |
14632 | char *argv[3]; | |
14633 | ||
14634 | argv[0] = ""; | |
14635 | argc = 1; | |
14636 | if (xrm_option) | |
14637 | { | |
14638 | argv[argc++] = "-xrm"; | |
14639 | argv[argc++] = xrm_option; | |
14640 | } | |
14641 | dpy = XtOpenDisplay (Xt_app_con, XSTRING (display_name)->data, | |
14642 | resource_name, EMACS_CLASS, | |
14643 | emacs_options, XtNumber (emacs_options), | |
14644 | &argc, argv); | |
39d8bb4d KH |
14645 | |
14646 | #ifdef HAVE_X11XTR6 | |
10537cb1 | 14647 | /* I think this is to compensate for XtSetLanguageProc. */ |
71f8198a | 14648 | fixup_locale (); |
39d8bb4d | 14649 | #endif |
7f9c7f94 | 14650 | } |
3afe33e7 RS |
14651 | |
14652 | #else /* not USE_X_TOOLKIT */ | |
bdcd49ba RS |
14653 | #ifdef HAVE_X11R5 |
14654 | XSetLocaleModifiers (""); | |
14655 | #endif | |
7a13e894 | 14656 | dpy = XOpenDisplay (XSTRING (display_name)->data); |
3afe33e7 | 14657 | #endif /* not USE_X_TOOLKIT */ |
334208b7 | 14658 | |
7a13e894 RS |
14659 | /* Detect failure. */ |
14660 | if (dpy == 0) | |
60439948 KH |
14661 | { |
14662 | UNBLOCK_INPUT; | |
14663 | return 0; | |
14664 | } | |
7a13e894 RS |
14665 | |
14666 | /* We have definitely succeeded. Record the new connection. */ | |
14667 | ||
14668 | dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info)); | |
f04e1297 | 14669 | bzero (dpyinfo, sizeof *dpyinfo); |
7a13e894 | 14670 | |
29b38361 KH |
14671 | #ifdef MULTI_KBOARD |
14672 | { | |
14673 | struct x_display_info *share; | |
14674 | Lisp_Object tail; | |
14675 | ||
14676 | for (share = x_display_list, tail = x_display_name_list; share; | |
8e713be6 KR |
14677 | share = share->next, tail = XCDR (tail)) |
14678 | if (same_x_server (XSTRING (XCAR (XCAR (tail)))->data, | |
29b38361 KH |
14679 | XSTRING (display_name)->data)) |
14680 | break; | |
14681 | if (share) | |
14682 | dpyinfo->kboard = share->kboard; | |
14683 | else | |
14684 | { | |
14685 | dpyinfo->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); | |
14686 | init_kboard (dpyinfo->kboard); | |
59e755be KH |
14687 | if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound)) |
14688 | { | |
14689 | char *vendor = ServerVendor (dpy); | |
9b6ed9f3 | 14690 | UNBLOCK_INPUT; |
59e755be KH |
14691 | dpyinfo->kboard->Vsystem_key_alist |
14692 | = call1 (Qvendor_specific_keysyms, | |
14693 | build_string (vendor ? vendor : "")); | |
9b6ed9f3 | 14694 | BLOCK_INPUT; |
59e755be KH |
14695 | } |
14696 | ||
29b38361 KH |
14697 | dpyinfo->kboard->next_kboard = all_kboards; |
14698 | all_kboards = dpyinfo->kboard; | |
0ad5446c KH |
14699 | /* Don't let the initial kboard remain current longer than necessary. |
14700 | That would cause problems if a file loaded on startup tries to | |
06a2c219 | 14701 | prompt in the mini-buffer. */ |
0ad5446c KH |
14702 | if (current_kboard == initial_kboard) |
14703 | current_kboard = dpyinfo->kboard; | |
29b38361 KH |
14704 | } |
14705 | dpyinfo->kboard->reference_count++; | |
14706 | } | |
b9737ad3 KH |
14707 | #endif |
14708 | ||
7a13e894 RS |
14709 | /* Put this display on the chain. */ |
14710 | dpyinfo->next = x_display_list; | |
14711 | x_display_list = dpyinfo; | |
14712 | ||
14713 | /* Put it on x_display_name_list as well, to keep them parallel. */ | |
14714 | x_display_name_list = Fcons (Fcons (display_name, Qnil), | |
14715 | x_display_name_list); | |
8e713be6 | 14716 | dpyinfo->name_list_element = XCAR (x_display_name_list); |
7a13e894 RS |
14717 | |
14718 | dpyinfo->display = dpy; | |
dc6f92b8 | 14719 | |
dc6f92b8 | 14720 | #if 0 |
7a13e894 | 14721 | XSetAfterFunction (x_current_display, x_trace_wire); |
c118dd06 | 14722 | #endif /* ! 0 */ |
7a13e894 RS |
14723 | |
14724 | dpyinfo->x_id_name | |
fc932ac6 RS |
14725 | = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name)) |
14726 | + STRING_BYTES (XSTRING (Vsystem_name)) | |
7a13e894 RS |
14727 | + 2); |
14728 | sprintf (dpyinfo->x_id_name, "%s@%s", | |
14729 | XSTRING (Vinvocation_name)->data, XSTRING (Vsystem_name)->data); | |
28430d3c JB |
14730 | |
14731 | /* Figure out which modifier bits mean what. */ | |
334208b7 | 14732 | x_find_modifier_meanings (dpyinfo); |
f451eb13 | 14733 | |
ab648270 | 14734 | /* Get the scroll bar cursor. */ |
7a13e894 | 14735 | dpyinfo->vertical_scroll_bar_cursor |
334208b7 | 14736 | = XCreateFontCursor (dpyinfo->display, XC_sb_v_double_arrow); |
f451eb13 | 14737 | |
334208b7 RS |
14738 | xrdb = x_load_resources (dpyinfo->display, xrm_option, |
14739 | resource_name, EMACS_CLASS); | |
14740 | #ifdef HAVE_XRMSETDATABASE | |
14741 | XrmSetDatabase (dpyinfo->display, xrdb); | |
14742 | #else | |
14743 | dpyinfo->display->db = xrdb; | |
14744 | #endif | |
547d9db8 | 14745 | /* Put the rdb where we can find it in a way that works on |
7a13e894 RS |
14746 | all versions. */ |
14747 | dpyinfo->xrdb = xrdb; | |
334208b7 RS |
14748 | |
14749 | dpyinfo->screen = ScreenOfDisplay (dpyinfo->display, | |
14750 | DefaultScreen (dpyinfo->display)); | |
5ff67d81 | 14751 | select_visual (dpyinfo); |
43bd1b2b | 14752 | dpyinfo->cmap = DefaultColormapOfScreen (dpyinfo->screen); |
334208b7 RS |
14753 | dpyinfo->height = HeightOfScreen (dpyinfo->screen); |
14754 | dpyinfo->width = WidthOfScreen (dpyinfo->screen); | |
14755 | dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen); | |
14756 | dpyinfo->grabbed = 0; | |
14757 | dpyinfo->reference_count = 0; | |
14758 | dpyinfo->icon_bitmap_id = -1; | |
06a2c219 | 14759 | dpyinfo->font_table = NULL; |
7a13e894 RS |
14760 | dpyinfo->n_fonts = 0; |
14761 | dpyinfo->font_table_size = 0; | |
14762 | dpyinfo->bitmaps = 0; | |
14763 | dpyinfo->bitmaps_size = 0; | |
14764 | dpyinfo->bitmaps_last = 0; | |
14765 | dpyinfo->scratch_cursor_gc = 0; | |
14766 | dpyinfo->mouse_face_mouse_frame = 0; | |
14767 | dpyinfo->mouse_face_deferred_gc = 0; | |
14768 | dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1; | |
14769 | dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1; | |
06a2c219 | 14770 | dpyinfo->mouse_face_face_id = DEFAULT_FACE_ID; |
7a13e894 | 14771 | dpyinfo->mouse_face_window = Qnil; |
0a61c667 | 14772 | dpyinfo->mouse_face_overlay = Qnil; |
7a13e894 RS |
14773 | dpyinfo->mouse_face_mouse_x = dpyinfo->mouse_face_mouse_y = 0; |
14774 | dpyinfo->mouse_face_defer = 0; | |
66301061 | 14775 | dpyinfo->mouse_face_hidden = 0; |
0f941935 KH |
14776 | dpyinfo->x_focus_frame = 0; |
14777 | dpyinfo->x_focus_event_frame = 0; | |
14778 | dpyinfo->x_highlight_frame = 0; | |
06a2c219 | 14779 | dpyinfo->image_cache = make_image_cache (); |
334208b7 | 14780 | |
43bd1b2b | 14781 | /* See if a private colormap is requested. */ |
5ff67d81 GM |
14782 | if (dpyinfo->visual == DefaultVisualOfScreen (dpyinfo->screen)) |
14783 | { | |
14784 | if (dpyinfo->visual->class == PseudoColor) | |
14785 | { | |
14786 | Lisp_Object value; | |
14787 | value = display_x_get_resource (dpyinfo, | |
14788 | build_string ("privateColormap"), | |
14789 | build_string ("PrivateColormap"), | |
14790 | Qnil, Qnil); | |
14791 | if (STRINGP (value) | |
14792 | && (!strcmp (XSTRING (value)->data, "true") | |
14793 | || !strcmp (XSTRING (value)->data, "on"))) | |
14794 | dpyinfo->cmap = XCopyColormapAndFree (dpyinfo->display, dpyinfo->cmap); | |
14795 | } | |
43bd1b2b | 14796 | } |
5ff67d81 GM |
14797 | else |
14798 | dpyinfo->cmap = XCreateColormap (dpyinfo->display, dpyinfo->root_window, | |
14799 | dpyinfo->visual, AllocNone); | |
43bd1b2b | 14800 | |
06a2c219 GM |
14801 | { |
14802 | int screen_number = XScreenNumberOfScreen (dpyinfo->screen); | |
14803 | double pixels = DisplayHeight (dpyinfo->display, screen_number); | |
14804 | double mm = DisplayHeightMM (dpyinfo->display, screen_number); | |
14805 | dpyinfo->resy = pixels * 25.4 / mm; | |
14806 | pixels = DisplayWidth (dpyinfo->display, screen_number); | |
14807 | mm = DisplayWidthMM (dpyinfo->display, screen_number); | |
14808 | dpyinfo->resx = pixels * 25.4 / mm; | |
14809 | } | |
14810 | ||
334208b7 RS |
14811 | dpyinfo->Xatom_wm_protocols |
14812 | = XInternAtom (dpyinfo->display, "WM_PROTOCOLS", False); | |
14813 | dpyinfo->Xatom_wm_take_focus | |
14814 | = XInternAtom (dpyinfo->display, "WM_TAKE_FOCUS", False); | |
14815 | dpyinfo->Xatom_wm_save_yourself | |
14816 | = XInternAtom (dpyinfo->display, "WM_SAVE_YOURSELF", False); | |
14817 | dpyinfo->Xatom_wm_delete_window | |
14818 | = XInternAtom (dpyinfo->display, "WM_DELETE_WINDOW", False); | |
14819 | dpyinfo->Xatom_wm_change_state | |
14820 | = XInternAtom (dpyinfo->display, "WM_CHANGE_STATE", False); | |
14821 | dpyinfo->Xatom_wm_configure_denied | |
14822 | = XInternAtom (dpyinfo->display, "WM_CONFIGURE_DENIED", False); | |
14823 | dpyinfo->Xatom_wm_window_moved | |
14824 | = XInternAtom (dpyinfo->display, "WM_MOVED", False); | |
14825 | dpyinfo->Xatom_editres | |
14826 | = XInternAtom (dpyinfo->display, "Editres", False); | |
14827 | dpyinfo->Xatom_CLIPBOARD | |
14828 | = XInternAtom (dpyinfo->display, "CLIPBOARD", False); | |
14829 | dpyinfo->Xatom_TIMESTAMP | |
14830 | = XInternAtom (dpyinfo->display, "TIMESTAMP", False); | |
14831 | dpyinfo->Xatom_TEXT | |
14832 | = XInternAtom (dpyinfo->display, "TEXT", False); | |
dc43ef94 KH |
14833 | dpyinfo->Xatom_COMPOUND_TEXT |
14834 | = XInternAtom (dpyinfo->display, "COMPOUND_TEXT", False); | |
334208b7 RS |
14835 | dpyinfo->Xatom_DELETE |
14836 | = XInternAtom (dpyinfo->display, "DELETE", False); | |
14837 | dpyinfo->Xatom_MULTIPLE | |
14838 | = XInternAtom (dpyinfo->display, "MULTIPLE", False); | |
14839 | dpyinfo->Xatom_INCR | |
14840 | = XInternAtom (dpyinfo->display, "INCR", False); | |
14841 | dpyinfo->Xatom_EMACS_TMP | |
14842 | = XInternAtom (dpyinfo->display, "_EMACS_TMP_", False); | |
14843 | dpyinfo->Xatom_TARGETS | |
14844 | = XInternAtom (dpyinfo->display, "TARGETS", False); | |
14845 | dpyinfo->Xatom_NULL | |
14846 | = XInternAtom (dpyinfo->display, "NULL", False); | |
14847 | dpyinfo->Xatom_ATOM_PAIR | |
14848 | = XInternAtom (dpyinfo->display, "ATOM_PAIR", False); | |
dc43ef94 KH |
14849 | /* For properties of font. */ |
14850 | dpyinfo->Xatom_PIXEL_SIZE | |
14851 | = XInternAtom (dpyinfo->display, "PIXEL_SIZE", False); | |
14852 | dpyinfo->Xatom_MULE_BASELINE_OFFSET | |
14853 | = XInternAtom (dpyinfo->display, "_MULE_BASELINE_OFFSET", False); | |
14854 | dpyinfo->Xatom_MULE_RELATIVE_COMPOSE | |
14855 | = XInternAtom (dpyinfo->display, "_MULE_RELATIVE_COMPOSE", False); | |
f78798df KH |
14856 | dpyinfo->Xatom_MULE_DEFAULT_ASCENT |
14857 | = XInternAtom (dpyinfo->display, "_MULE_DEFAULT_ASCENT", False); | |
334208b7 | 14858 | |
06a2c219 GM |
14859 | /* Ghostscript support. */ |
14860 | dpyinfo->Xatom_PAGE = XInternAtom (dpyinfo->display, "PAGE", False); | |
14861 | dpyinfo->Xatom_DONE = XInternAtom (dpyinfo->display, "DONE", False); | |
14862 | ||
14863 | dpyinfo->Xatom_Scrollbar = XInternAtom (dpyinfo->display, "SCROLLBAR", | |
14864 | False); | |
14865 | ||
547d9db8 KH |
14866 | dpyinfo->cut_buffers_initialized = 0; |
14867 | ||
334208b7 RS |
14868 | connection = ConnectionNumber (dpyinfo->display); |
14869 | dpyinfo->connection = connection; | |
14870 | ||
dc43ef94 | 14871 | { |
5d7cc324 RS |
14872 | char null_bits[1]; |
14873 | ||
14874 | null_bits[0] = 0x00; | |
dc43ef94 KH |
14875 | |
14876 | dpyinfo->null_pixel | |
14877 | = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window, | |
14878 | null_bits, 1, 1, (long) 0, (long) 0, | |
14879 | 1); | |
14880 | } | |
14881 | ||
06a2c219 GM |
14882 | { |
14883 | extern int gray_bitmap_width, gray_bitmap_height; | |
10659c77 | 14884 | extern char *gray_bitmap_bits; |
06a2c219 GM |
14885 | dpyinfo->gray |
14886 | = XCreatePixmapFromBitmapData (dpyinfo->display, dpyinfo->root_window, | |
14887 | gray_bitmap_bits, | |
14888 | gray_bitmap_width, gray_bitmap_height, | |
14889 | (unsigned long) 1, (unsigned long) 0, 1); | |
14890 | } | |
14891 | ||
f5d11644 GM |
14892 | #ifdef HAVE_X_I18N |
14893 | xim_initialize (dpyinfo, resource_name); | |
14894 | #endif | |
14895 | ||
87485d6f MW |
14896 | #ifdef subprocesses |
14897 | /* This is only needed for distinguishing keyboard and process input. */ | |
334208b7 | 14898 | if (connection != 0) |
7a13e894 | 14899 | add_keyboard_wait_descriptor (connection); |
87485d6f | 14900 | #endif |
6d4238f3 | 14901 | |
041b69ac | 14902 | #ifndef F_SETOWN_BUG |
dc6f92b8 | 14903 | #ifdef F_SETOWN |
dc6f92b8 | 14904 | #ifdef F_SETOWN_SOCK_NEG |
61c3ce62 | 14905 | /* stdin is a socket here */ |
334208b7 | 14906 | fcntl (connection, F_SETOWN, -getpid ()); |
c118dd06 | 14907 | #else /* ! defined (F_SETOWN_SOCK_NEG) */ |
334208b7 | 14908 | fcntl (connection, F_SETOWN, getpid ()); |
c118dd06 JB |
14909 | #endif /* ! defined (F_SETOWN_SOCK_NEG) */ |
14910 | #endif /* ! defined (F_SETOWN) */ | |
041b69ac | 14911 | #endif /* F_SETOWN_BUG */ |
dc6f92b8 JB |
14912 | |
14913 | #ifdef SIGIO | |
eee20f6a KH |
14914 | if (interrupt_input) |
14915 | init_sigio (connection); | |
c118dd06 | 14916 | #endif /* ! defined (SIGIO) */ |
dc6f92b8 | 14917 | |
51b592fb | 14918 | #ifdef USE_LUCID |
f8c39f51 | 14919 | #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */ |
51b592fb RS |
14920 | /* Make sure that we have a valid font for dialog boxes |
14921 | so that Xt does not crash. */ | |
14922 | { | |
14923 | Display *dpy = dpyinfo->display; | |
14924 | XrmValue d, fr, to; | |
14925 | Font font; | |
e99db5a1 | 14926 | int count; |
51b592fb RS |
14927 | |
14928 | d.addr = (XPointer)&dpy; | |
14929 | d.size = sizeof (Display *); | |
14930 | fr.addr = XtDefaultFont; | |
14931 | fr.size = sizeof (XtDefaultFont); | |
14932 | to.size = sizeof (Font *); | |
14933 | to.addr = (XPointer)&font; | |
e99db5a1 | 14934 | count = x_catch_errors (dpy); |
51b592fb RS |
14935 | if (!XtCallConverter (dpy, XtCvtStringToFont, &d, 1, &fr, &to, NULL)) |
14936 | abort (); | |
14937 | if (x_had_errors_p (dpy) || !XQueryFont (dpy, font)) | |
14938 | XrmPutLineResource (&xrdb, "Emacs.dialog.*.font: 9x15"); | |
e99db5a1 | 14939 | x_uncatch_errors (dpy, count); |
51b592fb RS |
14940 | } |
14941 | #endif | |
f8c39f51 | 14942 | #endif |
51b592fb | 14943 | |
34e23e5a GM |
14944 | /* See if we should run in synchronous mode. This is useful |
14945 | for debugging X code. */ | |
14946 | { | |
14947 | Lisp_Object value; | |
14948 | value = display_x_get_resource (dpyinfo, | |
14949 | build_string ("synchronous"), | |
14950 | build_string ("Synchronous"), | |
14951 | Qnil, Qnil); | |
14952 | if (STRINGP (value) | |
14953 | && (!strcmp (XSTRING (value)->data, "true") | |
14954 | || !strcmp (XSTRING (value)->data, "on"))) | |
14955 | XSynchronize (dpyinfo->display, True); | |
14956 | } | |
14957 | ||
60439948 KH |
14958 | UNBLOCK_INPUT; |
14959 | ||
7a13e894 RS |
14960 | return dpyinfo; |
14961 | } | |
14962 | \f | |
14963 | /* Get rid of display DPYINFO, assuming all frames are already gone, | |
14964 | and without sending any more commands to the X server. */ | |
dc6f92b8 | 14965 | |
7a13e894 RS |
14966 | void |
14967 | x_delete_display (dpyinfo) | |
14968 | struct x_display_info *dpyinfo; | |
14969 | { | |
14970 | delete_keyboard_wait_descriptor (dpyinfo->connection); | |
14971 | ||
14972 | /* Discard this display from x_display_name_list and x_display_list. | |
14973 | We can't use Fdelq because that can quit. */ | |
14974 | if (! NILP (x_display_name_list) | |
8e713be6 KR |
14975 | && EQ (XCAR (x_display_name_list), dpyinfo->name_list_element)) |
14976 | x_display_name_list = XCDR (x_display_name_list); | |
7a13e894 RS |
14977 | else |
14978 | { | |
14979 | Lisp_Object tail; | |
14980 | ||
14981 | tail = x_display_name_list; | |
8e713be6 | 14982 | while (CONSP (tail) && CONSP (XCDR (tail))) |
7a13e894 | 14983 | { |
bffcfca9 | 14984 | if (EQ (XCAR (XCDR (tail)), dpyinfo->name_list_element)) |
7a13e894 | 14985 | { |
f3fbd155 | 14986 | XSETCDR (tail, XCDR (XCDR (tail))); |
7a13e894 RS |
14987 | break; |
14988 | } | |
8e713be6 | 14989 | tail = XCDR (tail); |
7a13e894 RS |
14990 | } |
14991 | } | |
14992 | ||
9bda743f GM |
14993 | if (next_noop_dpyinfo == dpyinfo) |
14994 | next_noop_dpyinfo = dpyinfo->next; | |
14995 | ||
7a13e894 RS |
14996 | if (x_display_list == dpyinfo) |
14997 | x_display_list = dpyinfo->next; | |
7f9c7f94 RS |
14998 | else |
14999 | { | |
15000 | struct x_display_info *tail; | |
7a13e894 | 15001 | |
7f9c7f94 RS |
15002 | for (tail = x_display_list; tail; tail = tail->next) |
15003 | if (tail->next == dpyinfo) | |
15004 | tail->next = tail->next->next; | |
15005 | } | |
7a13e894 | 15006 | |
0d777288 RS |
15007 | #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */ |
15008 | #ifndef AIX /* On AIX, XCloseDisplay calls this. */ | |
7f9c7f94 RS |
15009 | XrmDestroyDatabase (dpyinfo->xrdb); |
15010 | #endif | |
0d777288 | 15011 | #endif |
29b38361 KH |
15012 | #ifdef MULTI_KBOARD |
15013 | if (--dpyinfo->kboard->reference_count == 0) | |
39f79001 | 15014 | delete_kboard (dpyinfo->kboard); |
b9737ad3 | 15015 | #endif |
f5d11644 GM |
15016 | #ifdef HAVE_X_I18N |
15017 | if (dpyinfo->xim) | |
15018 | xim_close_dpy (dpyinfo); | |
15019 | #endif | |
15020 | ||
b9737ad3 KH |
15021 | xfree (dpyinfo->font_table); |
15022 | xfree (dpyinfo->x_id_name); | |
f04e1297 | 15023 | xfree (dpyinfo->color_cells); |
b9737ad3 | 15024 | xfree (dpyinfo); |
7a13e894 | 15025 | } |
f04e1297 | 15026 | |
7a13e894 RS |
15027 | \f |
15028 | /* Set up use of X before we make the first connection. */ | |
15029 | ||
06a2c219 GM |
15030 | static struct redisplay_interface x_redisplay_interface = |
15031 | { | |
15032 | x_produce_glyphs, | |
15033 | x_write_glyphs, | |
15034 | x_insert_glyphs, | |
15035 | x_clear_end_of_line, | |
15036 | x_scroll_run, | |
15037 | x_after_update_window_line, | |
15038 | x_update_window_begin, | |
15039 | x_update_window_end, | |
15040 | XTcursor_to, | |
15041 | x_flush, | |
71b8321e | 15042 | x_clear_mouse_face, |
66ac4b0e GM |
15043 | x_get_glyph_overhangs, |
15044 | x_fix_overlapping_area | |
06a2c219 GM |
15045 | }; |
15046 | ||
dfcf069d | 15047 | void |
7a13e894 RS |
15048 | x_initialize () |
15049 | { | |
06a2c219 GM |
15050 | rif = &x_redisplay_interface; |
15051 | ||
15052 | clear_frame_hook = x_clear_frame; | |
15053 | ins_del_lines_hook = x_ins_del_lines; | |
06a2c219 | 15054 | delete_glyphs_hook = x_delete_glyphs; |
dc6f92b8 JB |
15055 | ring_bell_hook = XTring_bell; |
15056 | reset_terminal_modes_hook = XTreset_terminal_modes; | |
15057 | set_terminal_modes_hook = XTset_terminal_modes; | |
06a2c219 GM |
15058 | update_begin_hook = x_update_begin; |
15059 | update_end_hook = x_update_end; | |
dc6f92b8 JB |
15060 | set_terminal_window_hook = XTset_terminal_window; |
15061 | read_socket_hook = XTread_socket; | |
b8009dd1 | 15062 | frame_up_to_date_hook = XTframe_up_to_date; |
90e65f07 | 15063 | mouse_position_hook = XTmouse_position; |
f451eb13 | 15064 | frame_rehighlight_hook = XTframe_rehighlight; |
dbc4e1c1 | 15065 | frame_raise_lower_hook = XTframe_raise_lower; |
ab648270 JB |
15066 | set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar; |
15067 | condemn_scroll_bars_hook = XTcondemn_scroll_bars; | |
15068 | redeem_scroll_bar_hook = XTredeem_scroll_bar; | |
15069 | judge_scroll_bars_hook = XTjudge_scroll_bars; | |
06a2c219 | 15070 | estimate_mode_line_height_hook = x_estimate_mode_line_height; |
58769bee | 15071 | |
f676886a | 15072 | scroll_region_ok = 1; /* we'll scroll partial frames */ |
9017309f | 15073 | char_ins_del_ok = 1; |
dc6f92b8 JB |
15074 | line_ins_del_ok = 1; /* we'll just blt 'em */ |
15075 | fast_clear_end_of_line = 1; /* X does this well */ | |
58769bee | 15076 | memory_below_frame = 0; /* we don't remember what scrolls |
dc6f92b8 JB |
15077 | off the bottom */ |
15078 | baud_rate = 19200; | |
15079 | ||
7a13e894 | 15080 | x_noop_count = 0; |
9ea173e8 | 15081 | last_tool_bar_item = -1; |
06a2c219 GM |
15082 | any_help_event_p = 0; |
15083 | ||
b30b24cb RS |
15084 | /* Try to use interrupt input; if we can't, then start polling. */ |
15085 | Fset_input_mode (Qt, Qnil, Qt, Qnil); | |
15086 | ||
7f9c7f94 RS |
15087 | #ifdef USE_X_TOOLKIT |
15088 | XtToolkitInitialize (); | |
651f03b6 | 15089 | |
7f9c7f94 | 15090 | Xt_app_con = XtCreateApplicationContext (); |
651f03b6 GM |
15091 | |
15092 | /* Register a converter from strings to pixels, which uses | |
15093 | Emacs' color allocation infrastructure. */ | |
15094 | XtAppSetTypeConverter (Xt_app_con, | |
15095 | XtRString, XtRPixel, cvt_string_to_pixel, | |
15096 | cvt_string_to_pixel_args, | |
15097 | XtNumber (cvt_string_to_pixel_args), | |
15098 | XtCacheByDisplay, cvt_pixel_dtor); | |
15099 | ||
665881ad | 15100 | XtAppSetFallbackResources (Xt_app_con, Xt_default_resources); |
bffcfca9 GM |
15101 | |
15102 | /* Install an asynchronous timer that processes Xt timeout events | |
15103 | every 0.1s. This is necessary because some widget sets use | |
15104 | timeouts internally, for example the LessTif menu bar, or the | |
15105 | Xaw3d scroll bar. When Xt timouts aren't processed, these | |
15106 | widgets don't behave normally. */ | |
15107 | { | |
15108 | EMACS_TIME interval; | |
15109 | EMACS_SET_SECS_USECS (interval, 0, 100000); | |
15110 | start_atimer (ATIMER_CONTINUOUS, interval, x_process_timeouts, 0); | |
15111 | } | |
db74249b | 15112 | #endif |
bffcfca9 | 15113 | |
eccc05db | 15114 | #ifdef USE_TOOLKIT_SCROLL_BARS |
ec18280f SM |
15115 | xaw3d_arrow_scroll = False; |
15116 | xaw3d_pick_top = True; | |
7f9c7f94 RS |
15117 | #endif |
15118 | ||
58769bee | 15119 | /* Note that there is no real way portable across R3/R4 to get the |
c118dd06 | 15120 | original error handler. */ |
e99db5a1 | 15121 | XSetErrorHandler (x_error_handler); |
334208b7 | 15122 | XSetIOErrorHandler (x_io_error_quitter); |
dc6f92b8 | 15123 | |
06a2c219 | 15124 | /* Disable Window Change signals; they are handled by X events. */ |
dc6f92b8 JB |
15125 | #ifdef SIGWINCH |
15126 | signal (SIGWINCH, SIG_DFL); | |
a59facca | 15127 | #endif /* SIGWINCH */ |
dc6f92b8 | 15128 | |
92e2441b | 15129 | signal (SIGPIPE, x_connection_signal); |
5f30b957 JD |
15130 | |
15131 | #ifdef HAVE_X_SM | |
15132 | x_session_initialize (); | |
15133 | #endif | |
dc6f92b8 | 15134 | } |
55123275 | 15135 | |
06a2c219 | 15136 | |
55123275 JB |
15137 | void |
15138 | syms_of_xterm () | |
15139 | { | |
e99db5a1 RS |
15140 | staticpro (&x_error_message_string); |
15141 | x_error_message_string = Qnil; | |
15142 | ||
7a13e894 RS |
15143 | staticpro (&x_display_name_list); |
15144 | x_display_name_list = Qnil; | |
334208b7 | 15145 | |
ab648270 | 15146 | staticpro (&last_mouse_scroll_bar); |
e53cb100 | 15147 | last_mouse_scroll_bar = Qnil; |
59e755be KH |
15148 | |
15149 | staticpro (&Qvendor_specific_keysyms); | |
15150 | Qvendor_specific_keysyms = intern ("vendor-specific-keysyms"); | |
2237cac9 | 15151 | |
c997eae5 SM |
15152 | staticpro (&Qutf_8); |
15153 | Qutf_8 = intern ("utf-8"); | |
15154 | staticpro (&Qlatin_1); | |
15155 | Qlatin_1 = intern ("latin-1"); | |
15156 | ||
2237cac9 RS |
15157 | staticpro (&last_mouse_press_frame); |
15158 | last_mouse_press_frame = Qnil; | |
06a2c219 | 15159 | |
06a2c219 | 15160 | help_echo = Qnil; |
be010514 GM |
15161 | staticpro (&help_echo); |
15162 | help_echo_object = Qnil; | |
15163 | staticpro (&help_echo_object); | |
7cea38bc GM |
15164 | help_echo_window = Qnil; |
15165 | staticpro (&help_echo_window); | |
06a2c219 | 15166 | previous_help_echo = Qnil; |
be010514 GM |
15167 | staticpro (&previous_help_echo); |
15168 | help_echo_pos = -1; | |
06a2c219 | 15169 | |
ee8ceff8 | 15170 | DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window, |
503e457e | 15171 | doc: /* *Non-nil means autoselect window with mouse pointer. */); |
ee8ceff8 | 15172 | mouse_autoselect_window = 0; |
503e457e | 15173 | |
7ee72033 MB |
15174 | DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p, |
15175 | doc: /* *Non-nil means draw block cursor as wide as the glyph under it. | |
228299fa GM |
15176 | For example, if a block cursor is over a tab, it will be drawn as |
15177 | wide as that tab on the display. */); | |
06a2c219 GM |
15178 | x_stretch_cursor_p = 0; |
15179 | ||
a72d5ce5 | 15180 | DEFVAR_BOOL ("x-use-underline-position-properties", |
7ee72033 MB |
15181 | &x_use_underline_position_properties, |
15182 | doc: /* *Non-nil means make use of UNDERLINE_POSITION font properties. | |
f0529b5b | 15183 | nil means ignore them. If you encounter fonts with bogus |
228299fa GM |
15184 | UNDERLINE_POSITION font properties, for example 7x13 on XFree prior |
15185 | to 4.1, set this to nil. */); | |
a72d5ce5 GM |
15186 | x_use_underline_position_properties = 1; |
15187 | ||
7ee72033 MB |
15188 | DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, |
15189 | doc: /* What X toolkit scroll bars Emacs uses. | |
228299fa GM |
15190 | A value of nil means Emacs doesn't use X toolkit scroll bars. |
15191 | Otherwise, value is a symbol describing the X toolkit. */); | |
eccc05db | 15192 | #ifdef USE_TOOLKIT_SCROLL_BARS |
5bf04520 GM |
15193 | #ifdef USE_MOTIF |
15194 | Vx_toolkit_scroll_bars = intern ("motif"); | |
15195 | #elif defined HAVE_XAW3D | |
15196 | Vx_toolkit_scroll_bars = intern ("xaw3d"); | |
15197 | #else | |
15198 | Vx_toolkit_scroll_bars = intern ("xaw"); | |
15199 | #endif | |
06a2c219 | 15200 | #else |
5bf04520 | 15201 | Vx_toolkit_scroll_bars = Qnil; |
06a2c219 GM |
15202 | #endif |
15203 | ||
06a2c219 GM |
15204 | staticpro (&last_mouse_motion_frame); |
15205 | last_mouse_motion_frame = Qnil; | |
98659da6 KG |
15206 | |
15207 | Qmodifier_value = intern ("modifier-value"); | |
15208 | Qalt = intern ("alt"); | |
15209 | Fput (Qalt, Qmodifier_value, make_number (alt_modifier)); | |
15210 | Qhyper = intern ("hyper"); | |
15211 | Fput (Qhyper, Qmodifier_value, make_number (hyper_modifier)); | |
15212 | Qmeta = intern ("meta"); | |
15213 | Fput (Qmeta, Qmodifier_value, make_number (meta_modifier)); | |
15214 | Qsuper = intern ("super"); | |
15215 | Fput (Qsuper, Qmodifier_value, make_number (super_modifier)); | |
15216 | ||
15217 | DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym, | |
15218 | doc: /* Which keys Emacs uses for the alt modifier. | |
15219 | This should be one of the symbols `alt', `hyper', `meta', `super'. | |
15220 | For example, `alt' means use the Alt_L and Alt_R keysyms. The default | |
15221 | is nil, which is the same as `alt'. */); | |
15222 | Vx_alt_keysym = Qnil; | |
15223 | ||
15224 | DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym, | |
15225 | doc: /* Which keys Emacs uses for the hyper modifier. | |
15226 | This should be one of the symbols `alt', `hyper', `meta', `super'. | |
15227 | For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The | |
15228 | default is nil, which is the same as `hyper'. */); | |
15229 | Vx_hyper_keysym = Qnil; | |
15230 | ||
15231 | DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym, | |
15232 | doc: /* Which keys Emacs uses for the meta modifier. | |
15233 | This should be one of the symbols `alt', `hyper', `meta', `super'. | |
15234 | For example, `meta' means use the Meta_L and Meta_R keysyms. The | |
15235 | default is nil, which is the same as `meta'. */); | |
15236 | Vx_meta_keysym = Qnil; | |
15237 | ||
15238 | DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym, | |
15239 | doc: /* Which keys Emacs uses for the super modifier. | |
15240 | This should be one of the symbols `alt', `hyper', `meta', `super'. | |
15241 | For example, `super' means use the Super_L and Super_R keysyms. The | |
15242 | default is nil, which is the same as `super'. */); | |
15243 | Vx_super_keysym = Qnil; | |
15244 | ||
55123275 | 15245 | } |
6cf0ae86 | 15246 | |
1d6c120a | 15247 | #endif /* HAVE_X_WINDOWS */ |