Commit | Line | Data |
---|---|---|
01f1ba30 | 1 | /* Functions for the X window system. |
7d8a0b55 | 2 | Copyright (C) 1989, 92, 93, 94, 95, 96, 97, 98, 99, 2000,01,02,03,04 |
333b20bb | 3 | Free Software Foundation. |
01f1ba30 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 | |
1113d9db | 9 | the Free Software Foundation; either version 2, or (at your option) |
01f1ba30 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. */ | |
01f1ba30 | 21 | |
c389a86d | 22 | #include <config.h> |
68c45bf0 | 23 | #include <signal.h> |
333b20bb | 24 | #include <stdio.h> |
d62c8769 | 25 | #include <math.h> |
c389a86d | 26 | |
3ecaf7e5 RS |
27 | #ifdef HAVE_UNISTD_H |
28 | #include <unistd.h> | |
29 | #endif | |
30 | ||
40e6f148 | 31 | /* This makes the fields of a Display accessible, in Xlib header files. */ |
333b20bb | 32 | |
40e6f148 RS |
33 | #define XLIB_ILLEGAL_ACCESS |
34 | ||
01f1ba30 JB |
35 | #include "lisp.h" |
36 | #include "xterm.h" | |
f676886a | 37 | #include "frame.h" |
01f1ba30 JB |
38 | #include "window.h" |
39 | #include "buffer.h" | |
58cad5ed | 40 | #include "intervals.h" |
01f1ba30 | 41 | #include "dispextern.h" |
1f98fa48 | 42 | #include "keyboard.h" |
9ac0d9e0 | 43 | #include "blockinput.h" |
57bda87a | 44 | #include <epaths.h> |
942ea06d | 45 | #include "charset.h" |
96db09e4 | 46 | #include "coding.h" |
942ea06d | 47 | #include "fontset.h" |
333b20bb GM |
48 | #include "systime.h" |
49 | #include "termhooks.h" | |
4ae9a85e | 50 | #include "atimer.h" |
28d440ab | 51 | #include "termchar.h" |
01f1ba30 JB |
52 | |
53 | #ifdef HAVE_X_WINDOWS | |
67ba84d1 | 54 | |
67ba84d1 | 55 | #include <ctype.h> |
63cec32f GM |
56 | #include <sys/types.h> |
57 | #include <sys/stat.h> | |
01f1ba30 | 58 | |
0a93081c | 59 | #ifndef VMS |
0505a740 | 60 | #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */ |
ef493a27 RS |
61 | #include "bitmaps/gray.xbm" |
62 | #else | |
dbc4e1c1 | 63 | #include <X11/bitmaps/gray> |
ef493a27 | 64 | #endif |
0a93081c JB |
65 | #else |
66 | #include "[.bitmaps]gray.xbm" | |
67 | #endif | |
dbc4e1c1 | 68 | |
488dd4c4 JD |
69 | #ifdef USE_GTK |
70 | #include "gtkutil.h" | |
71 | #endif | |
72 | ||
9ef48a9d RS |
73 | #ifdef USE_X_TOOLKIT |
74 | #include <X11/Shell.h> | |
75 | ||
398ffa92 | 76 | #ifndef USE_MOTIF |
9ef48a9d RS |
77 | #include <X11/Xaw/Paned.h> |
78 | #include <X11/Xaw/Label.h> | |
398ffa92 | 79 | #endif /* USE_MOTIF */ |
9ef48a9d RS |
80 | |
81 | #ifdef USG | |
82 | #undef USG /* ####KLUDGE for Solaris 2.2 and up */ | |
83 | #include <X11/Xos.h> | |
84 | #define USG | |
85 | #else | |
86 | #include <X11/Xos.h> | |
87 | #endif | |
88 | ||
89 | #include "widget.h" | |
90 | ||
91 | #include "../lwlib/lwlib.h" | |
92 | ||
333b20bb GM |
93 | #ifdef USE_MOTIF |
94 | #include <Xm/Xm.h> | |
95 | #include <Xm/DialogS.h> | |
96 | #include <Xm/FileSB.h> | |
97 | #endif | |
98 | ||
3b882b1d RS |
99 | /* Do the EDITRES protocol if running X11R5 |
100 | Exception: HP-UX (at least version A.09.05) has X11R5 without EditRes */ | |
333b20bb | 101 | |
3b882b1d | 102 | #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES) |
6c32dd68 | 103 | #define HACK_EDITRES |
b9dc4443 | 104 | extern void _XEditResCheckMessages (); |
6c32dd68 PR |
105 | #endif /* R5 + Athena */ |
106 | ||
333b20bb GM |
107 | /* Unique id counter for widgets created by the Lucid Widget Library. */ |
108 | ||
6c32dd68 PR |
109 | extern LWLIB_ID widget_id_tick; |
110 | ||
e3881aa0 | 111 | #ifdef USE_LUCID |
82c90203 | 112 | /* This is part of a kludge--see lwlib/xlwmenu.c. */ |
03e2c340 | 113 | extern XFontStruct *xlwmenu_default_font; |
e3881aa0 | 114 | #endif |
9ef48a9d | 115 | |
6bc20398 | 116 | extern void free_frame_menubar (); |
d62c8769 | 117 | extern double atof (); |
333b20bb | 118 | |
fc2cdd9a GM |
119 | #ifdef USE_MOTIF |
120 | ||
121 | /* LessTif/Motif version info. */ | |
122 | ||
123 | static Lisp_Object Vmotif_version_string; | |
124 | ||
125 | #endif /* USE_MOTIF */ | |
126 | ||
9ef48a9d RS |
127 | #endif /* USE_X_TOOLKIT */ |
128 | ||
8a16bd4f LK |
129 | #ifdef USE_GTK |
130 | ||
131 | /* GTK+ version info */ | |
132 | ||
133 | static Lisp_Object Vgtk_version_string; | |
134 | ||
135 | #endif /* USE_GTK */ | |
136 | ||
9d317b2c RS |
137 | #ifdef HAVE_X11R4 |
138 | #define MAXREQUEST(dpy) (XMaxRequestSize (dpy)) | |
139 | #else | |
140 | #define MAXREQUEST(dpy) ((dpy)->max_request_size) | |
141 | #endif | |
142 | ||
333b20bb GM |
143 | /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses |
144 | it, and including `bitmaps/gray' more than once is a problem when | |
145 | config.h defines `static' as an empty replacement string. */ | |
146 | ||
147 | int gray_bitmap_width = gray_width; | |
148 | int gray_bitmap_height = gray_height; | |
62906360 | 149 | char *gray_bitmap_bits = gray_bits; |
333b20bb | 150 | |
0af913d7 | 151 | /* Non-zero means we're allowed to display an hourglass cursor. */ |
333b20bb | 152 | |
0af913d7 | 153 | int display_hourglass_p; |
333b20bb | 154 | |
255e4140 JD |
155 | /* Non-zero means prompt with the old GTK file selection dialog. */ |
156 | ||
157 | int x_use_old_gtk_file_dialog; | |
158 | ||
01f1ba30 | 159 | /* The background and shape of the mouse pointer, and shape when not |
b9dc4443 | 160 | over text or in the modeline. */ |
333b20bb | 161 | |
01f1ba30 | 162 | Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape; |
0af913d7 | 163 | Lisp_Object Vx_hourglass_pointer_shape; |
333b20bb | 164 | |
ca0ecbf5 | 165 | /* The shape when over mouse-sensitive text. */ |
333b20bb | 166 | |
ca0ecbf5 | 167 | Lisp_Object Vx_sensitive_text_pointer_shape; |
01f1ba30 | 168 | |
8fb4ec9c GM |
169 | /* If non-nil, the pointer shape to indicate that windows can be |
170 | dragged horizontally. */ | |
171 | ||
172 | Lisp_Object Vx_window_horizontal_drag_shape; | |
173 | ||
b9dc4443 | 174 | /* Color of chars displayed in cursor box. */ |
333b20bb | 175 | |
01f1ba30 JB |
176 | Lisp_Object Vx_cursor_fore_pixel; |
177 | ||
b9dc4443 | 178 | /* Nonzero if using X. */ |
333b20bb | 179 | |
b9dc4443 | 180 | static int x_in_use; |
01f1ba30 | 181 | |
b9dc4443 | 182 | /* Non nil if no window manager is in use. */ |
333b20bb | 183 | |
01f1ba30 JB |
184 | Lisp_Object Vx_no_window_manager; |
185 | ||
942ea06d | 186 | /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */ |
333b20bb | 187 | |
942ea06d KH |
188 | Lisp_Object Vx_pixel_size_width_font_regexp; |
189 | ||
baaed68e | 190 | Lisp_Object Qnone; |
8af1d7ca | 191 | Lisp_Object Qsuppress_icon; |
01f1ba30 | 192 | Lisp_Object Qundefined_color; |
ae782866 | 193 | Lisp_Object Qcompound_text, Qcancel_timer; |
01f1ba30 | 194 | |
7c0d3ed8 | 195 | /* In dispnew.c */ |
f9942c9e | 196 | |
01f1ba30 JB |
197 | extern Lisp_Object Vwindow_system_version; |
198 | ||
7c0d3ed8 | 199 | /* The below are defined in frame.c. */ |
333b20bb | 200 | |
f1d2ce7f | 201 | #if GLYPH_DEBUG |
eaf1eea9 GM |
202 | int image_cache_refcount, dpyinfo_refcount; |
203 | #endif | |
204 | ||
205 | ||
01f1ba30 | 206 | \f |
11ae94fe | 207 | /* Error if we are not connected to X. */ |
333b20bb | 208 | |
7fc9de26 | 209 | void |
11ae94fe RS |
210 | check_x () |
211 | { | |
b9dc4443 | 212 | if (! x_in_use) |
11ae94fe RS |
213 | error ("X windows are not in use or not initialized"); |
214 | } | |
215 | ||
1c59f5df RS |
216 | /* Nonzero if we can use mouse menus. |
217 | You should not call this unless HAVE_MENUS is defined. */ | |
75cc8ee5 RS |
218 | |
219 | int | |
1c59f5df | 220 | have_menus_p () |
75cc8ee5 | 221 | { |
b9dc4443 RS |
222 | return x_in_use; |
223 | } | |
224 | ||
225 | /* Extract a frame as a FRAME_PTR, defaulting to the selected frame | |
226 | and checking validity for X. */ | |
227 | ||
228 | FRAME_PTR | |
229 | check_x_frame (frame) | |
230 | Lisp_Object frame; | |
231 | { | |
232 | FRAME_PTR f; | |
233 | ||
234 | if (NILP (frame)) | |
0fe92f72 | 235 | frame = selected_frame; |
b7826503 | 236 | CHECK_LIVE_FRAME (frame); |
0fe92f72 | 237 | f = XFRAME (frame); |
b9dc4443 | 238 | if (! FRAME_X_P (f)) |
1c59f5df | 239 | error ("Non-X frame used"); |
b9dc4443 | 240 | return f; |
75cc8ee5 RS |
241 | } |
242 | ||
b9dc4443 RS |
243 | /* Let the user specify an X display with a frame. |
244 | nil stands for the selected frame--or, if that is not an X frame, | |
245 | the first X display on the list. */ | |
246 | ||
7c0d3ed8 | 247 | struct x_display_info * |
b9dc4443 RS |
248 | check_x_display_info (frame) |
249 | Lisp_Object frame; | |
250 | { | |
8ec8a5ec | 251 | struct x_display_info *dpyinfo = NULL; |
177c0ea7 | 252 | |
b9dc4443 RS |
253 | if (NILP (frame)) |
254 | { | |
0fe92f72 | 255 | struct frame *sf = XFRAME (selected_frame); |
177c0ea7 | 256 | |
0fe92f72 | 257 | if (FRAME_X_P (sf) && FRAME_LIVE_P (sf)) |
8ec8a5ec | 258 | dpyinfo = FRAME_X_DISPLAY_INFO (sf); |
b9dc4443 | 259 | else if (x_display_list != 0) |
8ec8a5ec | 260 | dpyinfo = x_display_list; |
b9dc4443 RS |
261 | else |
262 | error ("X windows are not in use or not initialized"); | |
263 | } | |
b6660415 KL |
264 | else if (INTEGERP (frame)) |
265 | { | |
266 | struct display *d = get_display (XINT (frame)); | |
267 | ||
268 | if (!d) | |
269 | wrong_type_argument (Qdisplay_live_p, frame); | |
270 | if (d->type != output_x_window) | |
271 | error ("Display %d is not an X display", XINT (frame)); | |
272 | ||
273 | dpyinfo = d->display_info.x; | |
274 | } | |
b9dc4443 | 275 | else if (STRINGP (frame)) |
8ec8a5ec | 276 | dpyinfo = x_display_info_for_name (frame); |
b9dc4443 RS |
277 | else |
278 | { | |
ba4c10fd | 279 | FRAME_PTR f = check_x_frame (frame); |
8ec8a5ec | 280 | dpyinfo = FRAME_X_DISPLAY_INFO (f); |
b9dc4443 | 281 | } |
8ec8a5ec GM |
282 | |
283 | return dpyinfo; | |
b9dc4443 | 284 | } |
333b20bb | 285 | |
b9dc4443 | 286 | \f |
f676886a JB |
287 | /* Return the Emacs frame-object corresponding to an X window. |
288 | It could be the frame's main window or an icon window. */ | |
01f1ba30 | 289 | |
34ca5317 | 290 | /* This function can be called during GC, so use GC_xxx type test macros. */ |
bcb2db92 | 291 | |
f676886a | 292 | struct frame * |
2d271e2e KH |
293 | x_window_to_frame (dpyinfo, wdesc) |
294 | struct x_display_info *dpyinfo; | |
01f1ba30 JB |
295 | int wdesc; |
296 | { | |
f676886a JB |
297 | Lisp_Object tail, frame; |
298 | struct frame *f; | |
01f1ba30 | 299 | |
10b43ac3 JD |
300 | if (wdesc == None) return 0; |
301 | ||
8e713be6 | 302 | for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) |
01f1ba30 | 303 | { |
8e713be6 | 304 | frame = XCAR (tail); |
34ca5317 | 305 | if (!GC_FRAMEP (frame)) |
01f1ba30 | 306 | continue; |
f676886a | 307 | f = XFRAME (frame); |
2d764c78 | 308 | if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) |
2d271e2e | 309 | continue; |
0af913d7 | 310 | if (f->output_data.x->hourglass_window == wdesc) |
17cbbf95 | 311 | return f; |
9ef48a9d | 312 | #ifdef USE_X_TOOLKIT |
177c0ea7 | 313 | if ((f->output_data.x->edit_widget |
7556890b | 314 | && XtWindow (f->output_data.x->edit_widget) == wdesc) |
333b20bb GM |
315 | /* A tooltip frame? */ |
316 | || (!f->output_data.x->edit_widget | |
317 | && FRAME_X_WINDOW (f) == wdesc) | |
7556890b | 318 | || f->output_data.x->icon_desc == wdesc) |
9ef48a9d RS |
319 | return f; |
320 | #else /* not USE_X_TOOLKIT */ | |
488dd4c4 JD |
321 | #ifdef USE_GTK |
322 | if (f->output_data.x->edit_widget) | |
323 | { | |
810f2256 | 324 | GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc); |
488dd4c4 JD |
325 | struct x_output *x = f->output_data.x; |
326 | if (gwdesc != 0 && gwdesc == x->edit_widget) | |
327 | return f; | |
328 | } | |
329 | #endif /* USE_GTK */ | |
fe24a618 | 330 | if (FRAME_X_WINDOW (f) == wdesc |
7556890b | 331 | || f->output_data.x->icon_desc == wdesc) |
f676886a | 332 | return f; |
9ef48a9d RS |
333 | #endif /* not USE_X_TOOLKIT */ |
334 | } | |
335 | return 0; | |
336 | } | |
337 | ||
488dd4c4 | 338 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
9ef48a9d RS |
339 | /* Like x_window_to_frame but also compares the window with the widget's |
340 | windows. */ | |
341 | ||
342 | struct frame * | |
2d271e2e KH |
343 | x_any_window_to_frame (dpyinfo, wdesc) |
344 | struct x_display_info *dpyinfo; | |
9ef48a9d RS |
345 | int wdesc; |
346 | { | |
347 | Lisp_Object tail, frame; | |
17cbbf95 | 348 | struct frame *f, *found; |
7556890b | 349 | struct x_output *x; |
9ef48a9d | 350 | |
10b43ac3 JD |
351 | if (wdesc == None) return NULL; |
352 | ||
17cbbf95 GM |
353 | found = NULL; |
354 | for (tail = Vframe_list; GC_CONSP (tail) && !found; tail = XCDR (tail)) | |
9ef48a9d | 355 | { |
8e713be6 | 356 | frame = XCAR (tail); |
34ca5317 | 357 | if (!GC_FRAMEP (frame)) |
9ef48a9d | 358 | continue; |
177c0ea7 | 359 | |
9ef48a9d | 360 | f = XFRAME (frame); |
17cbbf95 | 361 | if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo) |
333b20bb | 362 | { |
17cbbf95 GM |
363 | /* This frame matches if the window is any of its widgets. */ |
364 | x = f->output_data.x; | |
0af913d7 | 365 | if (x->hourglass_window == wdesc) |
17cbbf95 GM |
366 | found = f; |
367 | else if (x->widget) | |
368 | { | |
488dd4c4 | 369 | #ifdef USE_GTK |
810f2256 | 370 | GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc); |
488dd4c4 JD |
371 | if (gwdesc != 0 |
372 | && (gwdesc == x->widget | |
373 | || gwdesc == x->edit_widget | |
374 | || gwdesc == x->vbox_widget | |
375 | || gwdesc == x->menubar_widget)) | |
376 | found = f; | |
377 | #else | |
177c0ea7 JB |
378 | if (wdesc == XtWindow (x->widget) |
379 | || wdesc == XtWindow (x->column_widget) | |
17cbbf95 GM |
380 | || wdesc == XtWindow (x->edit_widget)) |
381 | found = f; | |
382 | /* Match if the window is this frame's menubar. */ | |
383 | else if (lw_window_is_in_menubar (wdesc, x->menubar_widget)) | |
384 | found = f; | |
488dd4c4 | 385 | #endif |
17cbbf95 GM |
386 | } |
387 | else if (FRAME_X_WINDOW (f) == wdesc) | |
388 | /* A tooltip frame. */ | |
389 | found = f; | |
333b20bb | 390 | } |
01f1ba30 | 391 | } |
177c0ea7 | 392 | |
17cbbf95 | 393 | return found; |
01f1ba30 | 394 | } |
5e65b9ab | 395 | |
5fbc3f3a KH |
396 | /* Likewise, but exclude the menu bar widget. */ |
397 | ||
398 | struct frame * | |
399 | x_non_menubar_window_to_frame (dpyinfo, wdesc) | |
400 | struct x_display_info *dpyinfo; | |
401 | int wdesc; | |
402 | { | |
403 | Lisp_Object tail, frame; | |
404 | struct frame *f; | |
7556890b | 405 | struct x_output *x; |
5fbc3f3a | 406 | |
10b43ac3 JD |
407 | if (wdesc == None) return 0; |
408 | ||
8e713be6 | 409 | for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) |
5fbc3f3a | 410 | { |
8e713be6 | 411 | frame = XCAR (tail); |
5fbc3f3a KH |
412 | if (!GC_FRAMEP (frame)) |
413 | continue; | |
414 | f = XFRAME (frame); | |
2d764c78 | 415 | if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) |
5fbc3f3a | 416 | continue; |
7556890b | 417 | x = f->output_data.x; |
5fbc3f3a | 418 | /* This frame matches if the window is any of its widgets. */ |
0af913d7 | 419 | if (x->hourglass_window == wdesc) |
17cbbf95 GM |
420 | return f; |
421 | else if (x->widget) | |
333b20bb | 422 | { |
488dd4c4 | 423 | #ifdef USE_GTK |
810f2256 | 424 | GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc); |
488dd4c4 JD |
425 | if (gwdesc != 0 |
426 | && (gwdesc == x->widget | |
427 | || gwdesc == x->edit_widget | |
428 | || gwdesc == x->vbox_widget)) | |
429 | return f; | |
430 | #else | |
177c0ea7 JB |
431 | if (wdesc == XtWindow (x->widget) |
432 | || wdesc == XtWindow (x->column_widget) | |
333b20bb GM |
433 | || wdesc == XtWindow (x->edit_widget)) |
434 | return f; | |
488dd4c4 | 435 | #endif |
333b20bb GM |
436 | } |
437 | else if (FRAME_X_WINDOW (f) == wdesc) | |
438 | /* A tooltip frame. */ | |
5fbc3f3a KH |
439 | return f; |
440 | } | |
441 | return 0; | |
442 | } | |
443 | ||
fd3a3022 RS |
444 | /* Likewise, but consider only the menu bar widget. */ |
445 | ||
446 | struct frame * | |
447 | x_menubar_window_to_frame (dpyinfo, wdesc) | |
448 | struct x_display_info *dpyinfo; | |
449 | int wdesc; | |
450 | { | |
451 | Lisp_Object tail, frame; | |
452 | struct frame *f; | |
7556890b | 453 | struct x_output *x; |
fd3a3022 | 454 | |
10b43ac3 JD |
455 | if (wdesc == None) return 0; |
456 | ||
8e713be6 | 457 | for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) |
fd3a3022 | 458 | { |
8e713be6 | 459 | frame = XCAR (tail); |
fd3a3022 RS |
460 | if (!GC_FRAMEP (frame)) |
461 | continue; | |
462 | f = XFRAME (frame); | |
2d764c78 | 463 | if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) |
fd3a3022 | 464 | continue; |
7556890b | 465 | x = f->output_data.x; |
fd3a3022 | 466 | /* Match if the window is this frame's menubar. */ |
488dd4c4 JD |
467 | #ifdef USE_GTK |
468 | if (x->menubar_widget) | |
469 | { | |
810f2256 | 470 | GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc); |
488dd4c4 | 471 | int found = 0; |
177c0ea7 | 472 | |
488dd4c4 JD |
473 | BLOCK_INPUT; |
474 | if (gwdesc != 0 | |
475 | && (gwdesc == x->menubar_widget | |
476 | || gtk_widget_get_parent (gwdesc) == x->menubar_widget)) | |
477 | found = 1; | |
478 | UNBLOCK_INPUT; | |
479 | if (found) return f; | |
480 | } | |
481 | #else | |
333b20bb GM |
482 | if (x->menubar_widget |
483 | && lw_window_is_in_menubar (wdesc, x->menubar_widget)) | |
fd3a3022 | 484 | return f; |
488dd4c4 | 485 | #endif |
fd3a3022 RS |
486 | } |
487 | return 0; | |
488 | } | |
489 | ||
5e65b9ab RS |
490 | /* Return the frame whose principal (outermost) window is WDESC. |
491 | If WDESC is some other (smaller) window, we return 0. */ | |
492 | ||
493 | struct frame * | |
2d271e2e KH |
494 | x_top_window_to_frame (dpyinfo, wdesc) |
495 | struct x_display_info *dpyinfo; | |
5e65b9ab RS |
496 | int wdesc; |
497 | { | |
498 | Lisp_Object tail, frame; | |
499 | struct frame *f; | |
7556890b | 500 | struct x_output *x; |
5e65b9ab | 501 | |
10b43ac3 JD |
502 | if (wdesc == None) return 0; |
503 | ||
8e713be6 | 504 | for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) |
5e65b9ab | 505 | { |
8e713be6 | 506 | frame = XCAR (tail); |
34ca5317 | 507 | if (!GC_FRAMEP (frame)) |
5e65b9ab RS |
508 | continue; |
509 | f = XFRAME (frame); | |
2d764c78 | 510 | if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo) |
2d271e2e | 511 | continue; |
7556890b | 512 | x = f->output_data.x; |
333b20bb GM |
513 | |
514 | if (x->widget) | |
515 | { | |
516 | /* This frame matches if the window is its topmost widget. */ | |
488dd4c4 | 517 | #ifdef USE_GTK |
810f2256 | 518 | GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc); |
488dd4c4 JD |
519 | if (gwdesc == x->widget) |
520 | return f; | |
521 | #else | |
333b20bb GM |
522 | if (wdesc == XtWindow (x->widget)) |
523 | return f; | |
7a994728 KH |
524 | #if 0 /* I don't know why it did this, |
525 | but it seems logically wrong, | |
526 | and it causes trouble for MapNotify events. */ | |
333b20bb | 527 | /* Match if the window is this frame's menubar. */ |
177c0ea7 | 528 | if (x->menubar_widget |
333b20bb GM |
529 | && wdesc == XtWindow (x->menubar_widget)) |
530 | return f; | |
488dd4c4 | 531 | #endif |
7a994728 | 532 | #endif |
333b20bb GM |
533 | } |
534 | else if (FRAME_X_WINDOW (f) == wdesc) | |
535 | /* Tooltip frame. */ | |
536 | return f; | |
5e65b9ab RS |
537 | } |
538 | return 0; | |
539 | } | |
488dd4c4 | 540 | #endif /* USE_X_TOOLKIT || USE_GTK */ |
01f1ba30 | 541 | |
01f1ba30 | 542 | \f |
203c1d73 | 543 | |
eaf1eea9 GM |
544 | static Lisp_Object unwind_create_frame P_ ((Lisp_Object)); |
545 | static Lisp_Object unwind_create_tip_frame P_ ((Lisp_Object)); | |
7c0d3ed8 | 546 | |
d62c8769 | 547 | void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
ea0a1f53 | 548 | static void x_set_wait_for_wm P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
d62c8769 GM |
549 | void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
550 | void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
551 | void x_set_cursor_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
552 | void x_set_border_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
553 | void x_set_cursor_type P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
554 | void x_set_icon_type P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
555 | void x_set_icon_name P_ ((struct frame *, Lisp_Object, Lisp_Object)); | |
d62c8769 | 556 | void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
d62c8769 | 557 | void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
d62c8769 | 558 | void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
9ea173e8 | 559 | void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); |
333b20bb GM |
560 | void x_set_scroll_bar_foreground P_ ((struct frame *, Lisp_Object, |
561 | Lisp_Object)); | |
562 | void x_set_scroll_bar_background P_ ((struct frame *, Lisp_Object, | |
563 | Lisp_Object)); | |
564 | static Lisp_Object x_default_scroll_bar_color_parameter P_ ((struct frame *, | |
565 | Lisp_Object, | |
566 | Lisp_Object, | |
567 | char *, char *, | |
568 | int)); | |
01f1ba30 | 569 | \f |
49d41073 | 570 | |
08a90d6a | 571 | /* Store the screen positions of frame F into XPTR and YPTR. |
e9445337 RS |
572 | These are the positions of the containing window manager window, |
573 | not Emacs's own window. */ | |
574 | ||
575 | void | |
576 | x_real_positions (f, xptr, yptr) | |
577 | FRAME_PTR f; | |
578 | int *xptr, *yptr; | |
579 | { | |
49d41073 EZ |
580 | int win_x, win_y, outer_x, outer_y; |
581 | int real_x = 0, real_y = 0; | |
582 | int had_errors = 0; | |
583 | Window win = f->output_data.x->parent_desc; | |
e9445337 | 584 | |
49d41073 | 585 | int count; |
043835a3 | 586 | |
49d41073 EZ |
587 | BLOCK_INPUT; |
588 | ||
589 | count = x_catch_errors (FRAME_X_DISPLAY (f)); | |
043835a3 | 590 | |
49d41073 EZ |
591 | if (win == FRAME_X_DISPLAY_INFO (f)->root_window) |
592 | win = FRAME_OUTER_WINDOW (f); | |
593 | ||
594 | /* This loop traverses up the containment tree until we hit the root | |
595 | window. Window managers may intersect many windows between our window | |
596 | and the root window. The window we find just before the root window | |
597 | should be the outer WM window. */ | |
598 | for (;;) | |
e9445337 | 599 | { |
49d41073 EZ |
600 | Window wm_window, rootw; |
601 | Window *tmp_children; | |
602 | unsigned int tmp_nchildren; | |
e7161ad9 | 603 | int success; |
ca7bac79 | 604 | |
e7161ad9 RS |
605 | success = XQueryTree (FRAME_X_DISPLAY (f), win, &rootw, |
606 | &wm_window, &tmp_children, &tmp_nchildren); | |
08a90d6a | 607 | |
49d41073 | 608 | had_errors = x_had_errors_p (FRAME_X_DISPLAY (f)); |
08a90d6a | 609 | |
e7161ad9 RS |
610 | /* Don't free tmp_children if XQueryTree failed. */ |
611 | if (! success) | |
612 | break; | |
613 | ||
614 | XFree ((char *) tmp_children); | |
615 | ||
49d41073 EZ |
616 | if (wm_window == rootw || had_errors) |
617 | break; | |
08a90d6a | 618 | |
49d41073 EZ |
619 | win = wm_window; |
620 | } | |
177c0ea7 | 621 | |
49d41073 EZ |
622 | if (! had_errors) |
623 | { | |
624 | int ign; | |
625 | Window child, rootw; | |
177c0ea7 | 626 | |
49d41073 EZ |
627 | /* Get the real coordinates for the WM window upper left corner */ |
628 | XGetGeometry (FRAME_X_DISPLAY (f), win, | |
629 | &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign); | |
630 | ||
631 | /* Translate real coordinates to coordinates relative to our | |
632 | window. For our window, the upper left corner is 0, 0. | |
633 | Since the upper left corner of the WM window is outside | |
634 | our window, win_x and win_y will be negative: | |
635 | ||
636 | ------------------ ---> x | |
637 | | title | | |
638 | | ----------------- v y | |
639 | | | our window | |
640 | */ | |
8a07bba0 | 641 | XTranslateCoordinates (FRAME_X_DISPLAY (f), |
e9445337 | 642 | |
8a07bba0 | 643 | /* From-window, to-window. */ |
8a07bba0 | 644 | FRAME_X_DISPLAY_INFO (f)->root_window, |
49d41073 | 645 | FRAME_X_WINDOW (f), |
e9445337 | 646 | |
8a07bba0 | 647 | /* From-position, to-position. */ |
49d41073 | 648 | real_x, real_y, &win_x, &win_y, |
08a90d6a | 649 | |
8a07bba0 RS |
650 | /* Child of win. */ |
651 | &child); | |
e9445337 | 652 | |
49d41073 | 653 | if (FRAME_X_WINDOW (f) == FRAME_OUTER_WINDOW (f)) |
845e9d85 | 654 | { |
49d41073 EZ |
655 | outer_x = win_x; |
656 | outer_y = win_y; | |
845e9d85 | 657 | } |
49d41073 EZ |
658 | else |
659 | { | |
660 | XTranslateCoordinates (FRAME_X_DISPLAY (f), | |
ca7bac79 | 661 | |
49d41073 EZ |
662 | /* From-window, to-window. */ |
663 | FRAME_X_DISPLAY_INFO (f)->root_window, | |
664 | FRAME_OUTER_WINDOW (f), | |
177c0ea7 | 665 | |
49d41073 EZ |
666 | /* From-position, to-position. */ |
667 | real_x, real_y, &outer_x, &outer_y, | |
177c0ea7 | 668 | |
49d41073 EZ |
669 | /* Child of win. */ |
670 | &child); | |
be786000 | 671 | } |
08a90d6a | 672 | |
49d41073 EZ |
673 | had_errors = x_had_errors_p (FRAME_X_DISPLAY (f)); |
674 | } | |
177c0ea7 | 675 | |
49d41073 | 676 | x_uncatch_errors (FRAME_X_DISPLAY (f), count); |
177c0ea7 | 677 | |
49d41073 EZ |
678 | UNBLOCK_INPUT; |
679 | ||
680 | if (had_errors) return; | |
177c0ea7 | 681 | |
be786000 KS |
682 | f->x_pixels_diff = -win_x; |
683 | f->y_pixels_diff = -win_y; | |
684 | ||
685 | FRAME_X_OUTPUT (f)->x_pixels_outer_diff = -outer_x; | |
686 | FRAME_X_OUTPUT (f)->y_pixels_outer_diff = -outer_y; | |
49d41073 EZ |
687 | |
688 | *xptr = real_x; | |
689 | *yptr = real_y; | |
e9445337 RS |
690 | } |
691 | ||
01f1ba30 | 692 | \f |
82978295 | 693 | |
d62c8769 GM |
694 | |
695 | /* Gamma-correct COLOR on frame F. */ | |
696 | ||
697 | void | |
698 | gamma_correct (f, color) | |
699 | struct frame *f; | |
700 | XColor *color; | |
701 | { | |
702 | if (f->gamma) | |
703 | { | |
704 | color->red = pow (color->red / 65535.0, f->gamma) * 65535.0 + 0.5; | |
705 | color->green = pow (color->green / 65535.0, f->gamma) * 65535.0 + 0.5; | |
706 | color->blue = pow (color->blue / 65535.0, f->gamma) * 65535.0 + 0.5; | |
707 | } | |
708 | } | |
709 | ||
710 | ||
7b746c38 GM |
711 | /* Decide if color named COLOR_NAME is valid for use on frame F. If |
712 | so, return the RGB values in COLOR. If ALLOC_P is non-zero, | |
713 | allocate the color. Value is zero if COLOR_NAME is invalid, or | |
714 | no color could be allocated. */ | |
e12d55b2 | 715 | |
01f1ba30 | 716 | int |
7b746c38 GM |
717 | x_defined_color (f, color_name, color, alloc_p) |
718 | struct frame *f; | |
719 | char *color_name; | |
720 | XColor *color; | |
721 | int alloc_p; | |
01f1ba30 | 722 | { |
7b746c38 GM |
723 | int success_p; |
724 | Display *dpy = FRAME_X_DISPLAY (f); | |
725 | Colormap cmap = FRAME_X_COLORMAP (f); | |
01f1ba30 JB |
726 | |
727 | BLOCK_INPUT; | |
7b746c38 GM |
728 | success_p = XParseColor (dpy, cmap, color_name, color); |
729 | if (success_p && alloc_p) | |
730 | success_p = x_alloc_nearest_color (f, cmap, color); | |
01f1ba30 JB |
731 | UNBLOCK_INPUT; |
732 | ||
7b746c38 | 733 | return success_p; |
01f1ba30 JB |
734 | } |
735 | ||
9b2956e2 GM |
736 | |
737 | /* Return the pixel color value for color COLOR_NAME on frame F. If F | |
738 | is a monochrome frame, return MONO_COLOR regardless of what ARG says. | |
739 | Signal an error if color can't be allocated. */ | |
01f1ba30 JB |
740 | |
741 | int | |
9b2956e2 | 742 | x_decode_color (f, color_name, mono_color) |
b9dc4443 | 743 | FRAME_PTR f; |
9b2956e2 GM |
744 | Lisp_Object color_name; |
745 | int mono_color; | |
01f1ba30 | 746 | { |
b9dc4443 | 747 | XColor cdef; |
01f1ba30 | 748 | |
b7826503 | 749 | CHECK_STRING (color_name); |
01f1ba30 | 750 | |
9b2956e2 GM |
751 | #if 0 /* Don't do this. It's wrong when we're not using the default |
752 | colormap, it makes freeing difficult, and it's probably not | |
753 | an important optimization. */ | |
d5db4077 | 754 | if (strcmp (SDATA (color_name), "black") == 0) |
b9dc4443 | 755 | return BLACK_PIX_DEFAULT (f); |
d5db4077 | 756 | else if (strcmp (SDATA (color_name), "white") == 0) |
b9dc4443 | 757 | return WHITE_PIX_DEFAULT (f); |
9b2956e2 | 758 | #endif |
01f1ba30 | 759 | |
9b2956e2 | 760 | /* Return MONO_COLOR for monochrome frames. */ |
b9dc4443 | 761 | if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1) |
9b2956e2 | 762 | return mono_color; |
01f1ba30 | 763 | |
2d764c78 | 764 | /* x_defined_color is responsible for coping with failures |
95626e11 | 765 | by looking for a near-miss. */ |
d5db4077 | 766 | if (x_defined_color (f, SDATA (color_name), &cdef, 1)) |
95626e11 RS |
767 | return cdef.pixel; |
768 | ||
c301be26 GM |
769 | Fsignal (Qerror, Fcons (build_string ("Undefined color"), |
770 | Fcons (color_name, Qnil))); | |
771 | return 0; | |
01f1ba30 | 772 | } |
9b2956e2 GM |
773 | |
774 | ||
01f1ba30 | 775 | \f |
ea0a1f53 GM |
776 | /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is |
777 | the previous value of that parameter, NEW_VALUE is the new value. | |
778 | See also the comment of wait_for_wm in struct x_output. */ | |
779 | ||
780 | static void | |
781 | x_set_wait_for_wm (f, new_value, old_value) | |
782 | struct frame *f; | |
783 | Lisp_Object new_value, old_value; | |
784 | { | |
785 | f->output_data.x->wait_for_wm = !NILP (new_value); | |
786 | } | |
787 | ||
993d0721 JB |
788 | #ifdef USE_GTK |
789 | ||
465aa50a JD |
790 | /* Set icon from FILE for frame F. By using GTK functions the icon |
791 | may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */ | |
993d0721 JB |
792 | |
793 | int | |
810f2256 | 794 | xg_set_icon (f, file) |
465aa50a | 795 | FRAME_PTR f; |
993d0721 JB |
796 | Lisp_Object file; |
797 | { | |
465aa50a JD |
798 | struct gcpro gcpro1; |
799 | int result = 0; | |
800 | Lisp_Object found; | |
993d0721 | 801 | |
465aa50a | 802 | GCPRO1 (found); |
993d0721 | 803 | |
465aa50a JD |
804 | found = x_find_image_file (file); |
805 | ||
806 | if (! NILP (found)) | |
807 | { | |
808 | GdkPixbuf *pixbuf; | |
809 | GError *err = NULL; | |
810 | char *filename; | |
811 | ||
812 | filename = SDATA (found); | |
813 | BLOCK_INPUT; | |
814 | ||
815 | pixbuf = gdk_pixbuf_new_from_file (filename, &err); | |
816 | ||
817 | if (pixbuf) | |
818 | { | |
819 | gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
820 | pixbuf); | |
821 | g_object_unref (pixbuf); | |
822 | ||
823 | result = 1; | |
824 | } | |
825 | else | |
826 | g_error_free (err); | |
827 | ||
828 | UNBLOCK_INPUT; | |
829 | } | |
830 | ||
831 | UNGCPRO; | |
832 | return result; | |
993d0721 JB |
833 | } |
834 | #endif /* USE_GTK */ | |
835 | ||
ea0a1f53 | 836 | |
f676886a | 837 | /* Functions called only from `x_set_frame_param' |
01f1ba30 JB |
838 | to set individual parameters. |
839 | ||
fe24a618 | 840 | If FRAME_X_WINDOW (f) is 0, |
f676886a | 841 | the frame is being created and its X-window does not exist yet. |
01f1ba30 JB |
842 | In that case, just record the parameter's new value |
843 | in the standard place; do not attempt to change the window. */ | |
844 | ||
845 | void | |
f676886a JB |
846 | x_set_foreground_color (f, arg, oldval) |
847 | struct frame *f; | |
01f1ba30 JB |
848 | Lisp_Object arg, oldval; |
849 | { | |
09393d07 GM |
850 | struct x_output *x = f->output_data.x; |
851 | unsigned long fg, old_fg; | |
a76206dc | 852 | |
09393d07 GM |
853 | fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
854 | old_fg = x->foreground_pixel; | |
855 | x->foreground_pixel = fg; | |
a76206dc | 856 | |
fe24a618 | 857 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 858 | { |
09393d07 | 859 | Display *dpy = FRAME_X_DISPLAY (f); |
177c0ea7 | 860 | |
09393d07 GM |
861 | BLOCK_INPUT; |
862 | XSetForeground (dpy, x->normal_gc, fg); | |
863 | XSetBackground (dpy, x->reverse_gc, fg); | |
36d42089 | 864 | |
09393d07 GM |
865 | if (x->cursor_pixel == old_fg) |
866 | { | |
867 | unload_color (f, x->cursor_pixel); | |
868 | x->cursor_pixel = x_copy_color (f, fg); | |
869 | XSetBackground (dpy, x->cursor_gc, x->cursor_pixel); | |
870 | } | |
177c0ea7 | 871 | |
01f1ba30 | 872 | UNBLOCK_INPUT; |
177c0ea7 | 873 | |
05c8abbe | 874 | update_face_from_frame_parameter (f, Qforeground_color, arg); |
177c0ea7 | 875 | |
179956b9 | 876 | if (FRAME_VISIBLE_P (f)) |
f676886a | 877 | redraw_frame (f); |
01f1ba30 | 878 | } |
177c0ea7 | 879 | |
09393d07 | 880 | unload_color (f, old_fg); |
01f1ba30 JB |
881 | } |
882 | ||
883 | void | |
f676886a JB |
884 | x_set_background_color (f, arg, oldval) |
885 | struct frame *f; | |
01f1ba30 JB |
886 | Lisp_Object arg, oldval; |
887 | { | |
09393d07 GM |
888 | struct x_output *x = f->output_data.x; |
889 | unsigned long bg; | |
01f1ba30 | 890 | |
09393d07 GM |
891 | bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f)); |
892 | unload_color (f, x->background_pixel); | |
893 | x->background_pixel = bg; | |
a76206dc | 894 | |
fe24a618 | 895 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 896 | { |
09393d07 | 897 | Display *dpy = FRAME_X_DISPLAY (f); |
177c0ea7 | 898 | |
09393d07 GM |
899 | BLOCK_INPUT; |
900 | XSetBackground (dpy, x->normal_gc, bg); | |
901 | XSetForeground (dpy, x->reverse_gc, bg); | |
902 | XSetWindowBackground (dpy, FRAME_X_WINDOW (f), bg); | |
903 | XSetForeground (dpy, x->cursor_gc, bg); | |
904 | ||
488dd4c4 JD |
905 | #ifdef USE_GTK |
906 | xg_set_background_color (f, bg); | |
907 | #endif | |
908 | ||
f76e0368 GM |
909 | #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with |
910 | toolkit scroll bars. */ | |
911 | { | |
912 | Lisp_Object bar; | |
913 | for (bar = FRAME_SCROLL_BARS (f); | |
914 | !NILP (bar); | |
915 | bar = XSCROLL_BAR (bar)->next) | |
916 | { | |
917 | Window window = SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)); | |
918 | XSetWindowBackground (dpy, window, bg); | |
919 | } | |
920 | } | |
921 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
01f1ba30 | 922 | |
09393d07 | 923 | UNBLOCK_INPUT; |
05c8abbe | 924 | update_face_from_frame_parameter (f, Qbackground_color, arg); |
ea96210c | 925 | |
179956b9 | 926 | if (FRAME_VISIBLE_P (f)) |
f676886a | 927 | redraw_frame (f); |
01f1ba30 JB |
928 | } |
929 | } | |
930 | ||
931 | void | |
f676886a JB |
932 | x_set_mouse_color (f, arg, oldval) |
933 | struct frame *f; | |
01f1ba30 JB |
934 | Lisp_Object arg, oldval; |
935 | { | |
09393d07 GM |
936 | struct x_output *x = f->output_data.x; |
937 | Display *dpy = FRAME_X_DISPLAY (f); | |
3d970f28 | 938 | Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; |
0af913d7 | 939 | Cursor hourglass_cursor, horizontal_drag_cursor; |
1dc6cfa6 | 940 | int count; |
51a1d2d8 | 941 | unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
09393d07 | 942 | unsigned long mask_color = x->background_pixel; |
a76206dc | 943 | |
51a1d2d8 | 944 | /* Don't let pointers be invisible. */ |
09393d07 | 945 | if (mask_color == pixel) |
bcf26b38 GM |
946 | { |
947 | x_free_colors (f, &pixel, 1); | |
09393d07 | 948 | pixel = x_copy_color (f, x->foreground_pixel); |
bcf26b38 | 949 | } |
a76206dc | 950 | |
09393d07 GM |
951 | unload_color (f, x->mouse_pixel); |
952 | x->mouse_pixel = pixel; | |
01f1ba30 JB |
953 | |
954 | BLOCK_INPUT; | |
fe24a618 | 955 | |
eb8c3be9 | 956 | /* It's not okay to crash if the user selects a screwy cursor. */ |
09393d07 | 957 | count = x_catch_errors (dpy); |
fe24a618 | 958 | |
09393d07 | 959 | if (!NILP (Vx_pointer_shape)) |
01f1ba30 | 960 | { |
b7826503 | 961 | CHECK_NUMBER (Vx_pointer_shape); |
09393d07 | 962 | cursor = XCreateFontCursor (dpy, XINT (Vx_pointer_shape)); |
01f1ba30 JB |
963 | } |
964 | else | |
09393d07 GM |
965 | cursor = XCreateFontCursor (dpy, XC_xterm); |
966 | x_check_errors (dpy, "bad text pointer cursor: %s"); | |
01f1ba30 | 967 | |
09393d07 | 968 | if (!NILP (Vx_nontext_pointer_shape)) |
01f1ba30 | 969 | { |
b7826503 | 970 | CHECK_NUMBER (Vx_nontext_pointer_shape); |
09393d07 GM |
971 | nontext_cursor |
972 | = XCreateFontCursor (dpy, XINT (Vx_nontext_pointer_shape)); | |
01f1ba30 JB |
973 | } |
974 | else | |
09393d07 GM |
975 | nontext_cursor = XCreateFontCursor (dpy, XC_left_ptr); |
976 | x_check_errors (dpy, "bad nontext pointer cursor: %s"); | |
01f1ba30 | 977 | |
09393d07 | 978 | if (!NILP (Vx_hourglass_pointer_shape)) |
333b20bb | 979 | { |
b7826503 | 980 | CHECK_NUMBER (Vx_hourglass_pointer_shape); |
09393d07 GM |
981 | hourglass_cursor |
982 | = XCreateFontCursor (dpy, XINT (Vx_hourglass_pointer_shape)); | |
333b20bb GM |
983 | } |
984 | else | |
09393d07 GM |
985 | hourglass_cursor = XCreateFontCursor (dpy, XC_watch); |
986 | x_check_errors (dpy, "bad hourglass pointer cursor: %s"); | |
177c0ea7 | 987 | |
09393d07 | 988 | if (!NILP (Vx_mode_pointer_shape)) |
01f1ba30 | 989 | { |
b7826503 | 990 | CHECK_NUMBER (Vx_mode_pointer_shape); |
09393d07 | 991 | mode_cursor = XCreateFontCursor (dpy, XINT (Vx_mode_pointer_shape)); |
01f1ba30 JB |
992 | } |
993 | else | |
09393d07 GM |
994 | mode_cursor = XCreateFontCursor (dpy, XC_xterm); |
995 | x_check_errors (dpy, "bad modeline pointer cursor: %s"); | |
95f80c78 | 996 | |
09393d07 | 997 | if (!NILP (Vx_sensitive_text_pointer_shape)) |
95f80c78 | 998 | { |
b7826503 | 999 | CHECK_NUMBER (Vx_sensitive_text_pointer_shape); |
3d970f28 | 1000 | hand_cursor |
09393d07 | 1001 | = XCreateFontCursor (dpy, XINT (Vx_sensitive_text_pointer_shape)); |
95f80c78 FP |
1002 | } |
1003 | else | |
3d970f28 | 1004 | hand_cursor = XCreateFontCursor (dpy, XC_hand2); |
01f1ba30 | 1005 | |
8fb4ec9c GM |
1006 | if (!NILP (Vx_window_horizontal_drag_shape)) |
1007 | { | |
b7826503 | 1008 | CHECK_NUMBER (Vx_window_horizontal_drag_shape); |
8fb4ec9c | 1009 | horizontal_drag_cursor |
09393d07 | 1010 | = XCreateFontCursor (dpy, XINT (Vx_window_horizontal_drag_shape)); |
8fb4ec9c GM |
1011 | } |
1012 | else | |
1013 | horizontal_drag_cursor | |
09393d07 | 1014 | = XCreateFontCursor (dpy, XC_sb_h_double_arrow); |
8fb4ec9c | 1015 | |
fe24a618 | 1016 | /* Check and report errors with the above calls. */ |
09393d07 GM |
1017 | x_check_errors (dpy, "can't set cursor shape: %s"); |
1018 | x_uncatch_errors (dpy, count); | |
fe24a618 | 1019 | |
01f1ba30 JB |
1020 | { |
1021 | XColor fore_color, back_color; | |
1022 | ||
09393d07 | 1023 | fore_color.pixel = x->mouse_pixel; |
a31fedb7 | 1024 | x_query_color (f, &fore_color); |
01f1ba30 | 1025 | back_color.pixel = mask_color; |
a31fedb7 | 1026 | x_query_color (f, &back_color); |
177c0ea7 | 1027 | |
09393d07 GM |
1028 | XRecolorCursor (dpy, cursor, &fore_color, &back_color); |
1029 | XRecolorCursor (dpy, nontext_cursor, &fore_color, &back_color); | |
1030 | XRecolorCursor (dpy, mode_cursor, &fore_color, &back_color); | |
3d970f28 | 1031 | XRecolorCursor (dpy, hand_cursor, &fore_color, &back_color); |
09393d07 GM |
1032 | XRecolorCursor (dpy, hourglass_cursor, &fore_color, &back_color); |
1033 | XRecolorCursor (dpy, horizontal_drag_cursor, &fore_color, &back_color); | |
01f1ba30 | 1034 | } |
01f1ba30 | 1035 | |
fe24a618 | 1036 | if (FRAME_X_WINDOW (f) != 0) |
09393d07 GM |
1037 | XDefineCursor (dpy, FRAME_X_WINDOW (f), cursor); |
1038 | ||
1039 | if (cursor != x->text_cursor | |
1040 | && x->text_cursor != 0) | |
1041 | XFreeCursor (dpy, x->text_cursor); | |
1042 | x->text_cursor = cursor; | |
1043 | ||
1044 | if (nontext_cursor != x->nontext_cursor | |
1045 | && x->nontext_cursor != 0) | |
1046 | XFreeCursor (dpy, x->nontext_cursor); | |
1047 | x->nontext_cursor = nontext_cursor; | |
1048 | ||
1049 | if (hourglass_cursor != x->hourglass_cursor | |
1050 | && x->hourglass_cursor != 0) | |
1051 | XFreeCursor (dpy, x->hourglass_cursor); | |
1052 | x->hourglass_cursor = hourglass_cursor; | |
1053 | ||
1054 | if (mode_cursor != x->modeline_cursor | |
1055 | && x->modeline_cursor != 0) | |
1056 | XFreeCursor (dpy, f->output_data.x->modeline_cursor); | |
1057 | x->modeline_cursor = mode_cursor; | |
177c0ea7 | 1058 | |
3d970f28 KS |
1059 | if (hand_cursor != x->hand_cursor |
1060 | && x->hand_cursor != 0) | |
1061 | XFreeCursor (dpy, x->hand_cursor); | |
1062 | x->hand_cursor = hand_cursor; | |
01f1ba30 | 1063 | |
09393d07 GM |
1064 | if (horizontal_drag_cursor != x->horizontal_drag_cursor |
1065 | && x->horizontal_drag_cursor != 0) | |
1066 | XFreeCursor (dpy, x->horizontal_drag_cursor); | |
1067 | x->horizontal_drag_cursor = horizontal_drag_cursor; | |
8fb4ec9c | 1068 | |
09393d07 | 1069 | XFlush (dpy); |
01f1ba30 | 1070 | UNBLOCK_INPUT; |
05c8abbe GM |
1071 | |
1072 | update_face_from_frame_parameter (f, Qmouse_color, arg); | |
01f1ba30 JB |
1073 | } |
1074 | ||
1075 | void | |
f676886a JB |
1076 | x_set_cursor_color (f, arg, oldval) |
1077 | struct frame *f; | |
01f1ba30 JB |
1078 | Lisp_Object arg, oldval; |
1079 | { | |
a76206dc | 1080 | unsigned long fore_pixel, pixel; |
10168ebb | 1081 | int fore_pixel_allocated_p = 0, pixel_allocated_p = 0; |
09393d07 | 1082 | struct x_output *x = f->output_data.x; |
01f1ba30 | 1083 | |
10168ebb GM |
1084 | if (!NILP (Vx_cursor_fore_pixel)) |
1085 | { | |
1086 | fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel, | |
1087 | WHITE_PIX_DEFAULT (f)); | |
1088 | fore_pixel_allocated_p = 1; | |
1089 | } | |
01f1ba30 | 1090 | else |
09393d07 | 1091 | fore_pixel = x->background_pixel; |
177c0ea7 | 1092 | |
a76206dc | 1093 | pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
10168ebb | 1094 | pixel_allocated_p = 1; |
a76206dc | 1095 | |
f9942c9e | 1096 | /* Make sure that the cursor color differs from the background color. */ |
09393d07 | 1097 | if (pixel == x->background_pixel) |
01f1ba30 | 1098 | { |
10168ebb GM |
1099 | if (pixel_allocated_p) |
1100 | { | |
1101 | x_free_colors (f, &pixel, 1); | |
1102 | pixel_allocated_p = 0; | |
1103 | } | |
177c0ea7 | 1104 | |
09393d07 | 1105 | pixel = x->mouse_pixel; |
a76206dc | 1106 | if (pixel == fore_pixel) |
10168ebb GM |
1107 | { |
1108 | if (fore_pixel_allocated_p) | |
1109 | { | |
1110 | x_free_colors (f, &fore_pixel, 1); | |
1111 | fore_pixel_allocated_p = 0; | |
1112 | } | |
09393d07 | 1113 | fore_pixel = x->background_pixel; |
10168ebb | 1114 | } |
01f1ba30 | 1115 | } |
a76206dc | 1116 | |
09393d07 | 1117 | unload_color (f, x->cursor_foreground_pixel); |
10168ebb GM |
1118 | if (!fore_pixel_allocated_p) |
1119 | fore_pixel = x_copy_color (f, fore_pixel); | |
09393d07 | 1120 | x->cursor_foreground_pixel = fore_pixel; |
01f1ba30 | 1121 | |
09393d07 | 1122 | unload_color (f, x->cursor_pixel); |
10168ebb GM |
1123 | if (!pixel_allocated_p) |
1124 | pixel = x_copy_color (f, pixel); | |
09393d07 | 1125 | x->cursor_pixel = pixel; |
a76206dc | 1126 | |
fe24a618 | 1127 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 1128 | { |
01f1ba30 | 1129 | BLOCK_INPUT; |
09393d07 GM |
1130 | XSetBackground (FRAME_X_DISPLAY (f), x->cursor_gc, x->cursor_pixel); |
1131 | XSetForeground (FRAME_X_DISPLAY (f), x->cursor_gc, fore_pixel); | |
01f1ba30 | 1132 | UNBLOCK_INPUT; |
01f1ba30 | 1133 | |
179956b9 | 1134 | if (FRAME_VISIBLE_P (f)) |
01f1ba30 | 1135 | { |
cedadcfa RS |
1136 | x_update_cursor (f, 0); |
1137 | x_update_cursor (f, 1); | |
01f1ba30 JB |
1138 | } |
1139 | } | |
05c8abbe GM |
1140 | |
1141 | update_face_from_frame_parameter (f, Qcursor_color, arg); | |
01f1ba30 | 1142 | } |
943b580d | 1143 | \f |
f676886a | 1144 | /* Set the border-color of frame F to pixel value PIX. |
01f1ba30 | 1145 | Note that this does not fully take effect if done before |
f676886a | 1146 | F has an x-window. */ |
01f1ba30 | 1147 | |
968b1234 | 1148 | void |
f676886a JB |
1149 | x_set_border_pixel (f, pix) |
1150 | struct frame *f; | |
01f1ba30 JB |
1151 | int pix; |
1152 | { | |
a76206dc | 1153 | unload_color (f, f->output_data.x->border_pixel); |
7556890b | 1154 | f->output_data.x->border_pixel = pix; |
01f1ba30 | 1155 | |
be786000 | 1156 | if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0) |
01f1ba30 | 1157 | { |
01f1ba30 | 1158 | BLOCK_INPUT; |
b9dc4443 | 1159 | XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
270958e8 | 1160 | (unsigned long)pix); |
01f1ba30 JB |
1161 | UNBLOCK_INPUT; |
1162 | ||
179956b9 | 1163 | if (FRAME_VISIBLE_P (f)) |
f676886a | 1164 | redraw_frame (f); |
01f1ba30 JB |
1165 | } |
1166 | } | |
1167 | ||
7c0d3ed8 KS |
1168 | /* Set the border-color of frame F to value described by ARG. |
1169 | ARG can be a string naming a color. | |
1170 | The border-color is used for the border that is drawn by the X server. | |
1171 | Note that this does not fully take effect if done before | |
1172 | F has an x-window; it must be redone when the window is created. | |
1173 | ||
1174 | Note: this is done in two routines because of the way X10 works. | |
1175 | ||
1176 | Note: under X11, this is normally the province of the window manager, | |
1177 | and so emacs' border colors may be overridden. */ | |
1178 | ||
1179 | void | |
1180 | x_set_border_color (f, arg, oldval) | |
1181 | struct frame *f; | |
1182 | Lisp_Object arg, oldval; | |
1183 | { | |
1184 | int pix; | |
1185 | ||
1186 | CHECK_STRING (arg); | |
1187 | pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); | |
1188 | x_set_border_pixel (f, pix); | |
1189 | update_face_from_frame_parameter (f, Qborder_color, arg); | |
1190 | } | |
0d1469d6 | 1191 | |
0d1469d6 GM |
1192 | |
1193 | void | |
1194 | x_set_cursor_type (f, arg, oldval) | |
1195 | FRAME_PTR f; | |
1196 | Lisp_Object arg, oldval; | |
1197 | { | |
33b2311e | 1198 | set_frame_cursor_types (f, arg); |
dbc4e1c1 | 1199 | |
75691005 RS |
1200 | /* Make sure the cursor gets redrawn. */ |
1201 | cursor_type_changed = 1; | |
dbc4e1c1 | 1202 | } |
943b580d | 1203 | \f |
01f1ba30 | 1204 | void |
f676886a JB |
1205 | x_set_icon_type (f, arg, oldval) |
1206 | struct frame *f; | |
01f1ba30 JB |
1207 | Lisp_Object arg, oldval; |
1208 | { | |
01f1ba30 JB |
1209 | int result; |
1210 | ||
203c1d73 RS |
1211 | if (STRINGP (arg)) |
1212 | { | |
1213 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | |
1214 | return; | |
1215 | } | |
1216 | else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) | |
01f1ba30 JB |
1217 | return; |
1218 | ||
1219 | BLOCK_INPUT; | |
265a9e55 | 1220 | if (NILP (arg)) |
80534dd6 | 1221 | result = x_text_icon (f, |
d5db4077 | 1222 | (char *) SDATA ((!NILP (f->icon_name) |
f468da95 | 1223 | ? f->icon_name |
d5db4077 | 1224 | : f->name))); |
f1c7b5a6 RS |
1225 | else |
1226 | result = x_bitmap_icon (f, arg); | |
01f1ba30 JB |
1227 | |
1228 | if (result) | |
1229 | { | |
01f1ba30 | 1230 | UNBLOCK_INPUT; |
0fb53770 | 1231 | error ("No icon window available"); |
01f1ba30 JB |
1232 | } |
1233 | ||
b9dc4443 | 1234 | XFlush (FRAME_X_DISPLAY (f)); |
01f1ba30 JB |
1235 | UNBLOCK_INPUT; |
1236 | } | |
1237 | ||
80534dd6 KH |
1238 | void |
1239 | x_set_icon_name (f, arg, oldval) | |
1240 | struct frame *f; | |
1241 | Lisp_Object arg, oldval; | |
1242 | { | |
80534dd6 KH |
1243 | int result; |
1244 | ||
1245 | if (STRINGP (arg)) | |
1246 | { | |
1247 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | |
1248 | return; | |
1249 | } | |
1250 | else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) | |
1251 | return; | |
1252 | ||
f468da95 | 1253 | f->icon_name = arg; |
80534dd6 | 1254 | |
7556890b | 1255 | if (f->output_data.x->icon_bitmap != 0) |
80534dd6 KH |
1256 | return; |
1257 | ||
1258 | BLOCK_INPUT; | |
1259 | ||
1260 | result = x_text_icon (f, | |
d5db4077 KR |
1261 | (char *) SDATA ((!NILP (f->icon_name) |
1262 | ? f->icon_name | |
1263 | : !NILP (f->title) | |
1264 | ? f->title | |
1265 | : f->name))); | |
80534dd6 KH |
1266 | |
1267 | if (result) | |
1268 | { | |
1269 | UNBLOCK_INPUT; | |
1270 | error ("No icon window available"); | |
1271 | } | |
1272 | ||
80534dd6 KH |
1273 | XFlush (FRAME_X_DISPLAY (f)); |
1274 | UNBLOCK_INPUT; | |
1275 | } | |
7c0d3ed8 | 1276 | |
943b580d | 1277 | \f |
01f1ba30 | 1278 | void |
7c0d3ed8 | 1279 | x_set_menu_bar_lines (f, value, oldval) |
f676886a | 1280 | struct frame *f; |
7c0d3ed8 | 1281 | Lisp_Object value, oldval; |
01f1ba30 | 1282 | { |
7c0d3ed8 | 1283 | int nlines; |
121e8a82 | 1284 | #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) |
7c0d3ed8 KS |
1285 | int olines = FRAME_MENU_BAR_LINES (f); |
1286 | #endif | |
177c0ea7 | 1287 | |
7c0d3ed8 KS |
1288 | /* Right now, menu bars don't work properly in minibuf-only frames; |
1289 | most of the commands try to apply themselves to the minibuffer | |
1290 | frame itself, and get an error because you can't switch buffers | |
1291 | in or split the minibuffer window. */ | |
1292 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1293 | return; | |
177c0ea7 | 1294 | |
7c0d3ed8 KS |
1295 | if (INTEGERP (value)) |
1296 | nlines = XINT (value); | |
ea96210c | 1297 | else |
7c0d3ed8 | 1298 | nlines = 0; |
a367641f | 1299 | |
7c0d3ed8 KS |
1300 | /* Make sure we redisplay all windows in this frame. */ |
1301 | windows_or_buffers_changed++; | |
3d09b6be | 1302 | |
488dd4c4 | 1303 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
9ef48a9d RS |
1304 | FRAME_MENU_BAR_LINES (f) = 0; |
1305 | if (nlines) | |
0d8ef3f4 RS |
1306 | { |
1307 | FRAME_EXTERNAL_MENU_BAR (f) = 1; | |
97a1ff91 | 1308 | if (FRAME_X_P (f) && f->output_data.x->menubar_widget == 0) |
0d8ef3f4 RS |
1309 | /* Make sure next redisplay shows the menu bar. */ |
1310 | XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt; | |
1311 | } | |
9ef48a9d RS |
1312 | else |
1313 | { | |
6bc20398 FP |
1314 | if (FRAME_EXTERNAL_MENU_BAR (f) == 1) |
1315 | free_frame_menubar (f); | |
9ef48a9d | 1316 | FRAME_EXTERNAL_MENU_BAR (f) = 0; |
97a1ff91 RS |
1317 | if (FRAME_X_P (f)) |
1318 | f->output_data.x->menubar_widget = 0; | |
9ef48a9d | 1319 | } |
488dd4c4 | 1320 | #else /* not USE_X_TOOLKIT && not USE_GTK */ |
d043f1a4 | 1321 | FRAME_MENU_BAR_LINES (f) = nlines; |
7c0d3ed8 | 1322 | change_window_heights (f->root_window, nlines - olines); |
9ef48a9d | 1323 | #endif /* not USE_X_TOOLKIT */ |
333b20bb GM |
1324 | adjust_glyphs (f); |
1325 | } | |
1326 | ||
1327 | ||
1328 | /* Set the number of lines used for the tool bar of frame F to VALUE. | |
1329 | VALUE not an integer, or < 0 means set the lines to zero. OLDVAL | |
1330 | is the old number of tool bar lines. This function changes the | |
1331 | height of all windows on frame F to match the new tool bar height. | |
1332 | The frame's height doesn't change. */ | |
1333 | ||
1334 | void | |
9ea173e8 | 1335 | x_set_tool_bar_lines (f, value, oldval) |
333b20bb GM |
1336 | struct frame *f; |
1337 | Lisp_Object value, oldval; | |
1338 | { | |
52de7ce9 GM |
1339 | int delta, nlines, root_height; |
1340 | Lisp_Object root_window; | |
333b20bb | 1341 | |
e870b7ba GM |
1342 | /* Treat tool bars like menu bars. */ |
1343 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1344 | return; | |
1345 | ||
333b20bb GM |
1346 | /* Use VALUE only if an integer >= 0. */ |
1347 | if (INTEGERP (value) && XINT (value) >= 0) | |
1348 | nlines = XFASTINT (value); | |
1349 | else | |
1350 | nlines = 0; | |
1351 | ||
488dd4c4 JD |
1352 | #ifdef USE_GTK |
1353 | FRAME_TOOL_BAR_LINES (f) = 0; | |
1354 | if (nlines) | |
1355 | { | |
1356 | FRAME_EXTERNAL_TOOL_BAR (f) = 1; | |
1357 | if (FRAME_X_P (f) && f->output_data.x->toolbar_widget == 0) | |
1358 | /* Make sure next redisplay shows the tool bar. */ | |
1359 | XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt; | |
1360 | update_frame_tool_bar (f); | |
1361 | } | |
1362 | else | |
1363 | { | |
1364 | if (FRAME_EXTERNAL_TOOL_BAR (f)) | |
1365 | free_frame_tool_bar (f); | |
1366 | FRAME_EXTERNAL_TOOL_BAR (f) = 0; | |
1367 | } | |
1368 | ||
1369 | return; | |
1370 | #endif | |
177c0ea7 | 1371 | |
488dd4c4 | 1372 | /* Make sure we redisplay all windows in this frame. */ |
333b20bb GM |
1373 | ++windows_or_buffers_changed; |
1374 | ||
9ea173e8 | 1375 | delta = nlines - FRAME_TOOL_BAR_LINES (f); |
52de7ce9 GM |
1376 | |
1377 | /* Don't resize the tool-bar to more than we have room for. */ | |
1378 | root_window = FRAME_ROOT_WINDOW (f); | |
be786000 | 1379 | root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window)); |
52de7ce9 GM |
1380 | if (root_height - delta < 1) |
1381 | { | |
1382 | delta = root_height - 1; | |
1383 | nlines = FRAME_TOOL_BAR_LINES (f) + delta; | |
1384 | } | |
1385 | ||
9ea173e8 | 1386 | FRAME_TOOL_BAR_LINES (f) = nlines; |
7c0d3ed8 | 1387 | change_window_heights (root_window, delta); |
333b20bb | 1388 | adjust_glyphs (f); |
177c0ea7 | 1389 | |
ccba751c GM |
1390 | /* We also have to make sure that the internal border at the top of |
1391 | the frame, below the menu bar or tool bar, is redrawn when the | |
1392 | tool bar disappears. This is so because the internal border is | |
1393 | below the tool bar if one is displayed, but is below the menu bar | |
1394 | if there isn't a tool bar. The tool bar draws into the area | |
1395 | below the menu bar. */ | |
1396 | if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) | |
1397 | { | |
385ed61f | 1398 | clear_frame (f); |
fb3cd89b | 1399 | clear_current_matrices (f); |
ccba751c | 1400 | } |
b6f91066 GM |
1401 | |
1402 | /* If the tool bar gets smaller, the internal border below it | |
1403 | has to be cleared. It was formerly part of the display | |
1404 | of the larger tool bar, and updating windows won't clear it. */ | |
1405 | if (delta < 0) | |
1406 | { | |
1407 | int height = FRAME_INTERNAL_BORDER_WIDTH (f); | |
be786000 KS |
1408 | int width = FRAME_PIXEL_WIDTH (f); |
1409 | int y = nlines * FRAME_LINE_HEIGHT (f); | |
b6f91066 GM |
1410 | |
1411 | BLOCK_INPUT; | |
161d30fd GM |
1412 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
1413 | 0, y, width, height, False); | |
b6f91066 | 1414 | UNBLOCK_INPUT; |
ddc24747 GM |
1415 | |
1416 | if (WINDOWP (f->tool_bar_window)) | |
1417 | clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix); | |
b6f91066 | 1418 | } |
333b20bb GM |
1419 | } |
1420 | ||
1421 | ||
1422 | /* Set the foreground color for scroll bars on frame F to VALUE. | |
1423 | VALUE should be a string, a color name. If it isn't a string or | |
1424 | isn't a valid color name, do nothing. OLDVAL is the old value of | |
1425 | the frame parameter. */ | |
1426 | ||
1427 | void | |
1428 | x_set_scroll_bar_foreground (f, value, oldval) | |
1429 | struct frame *f; | |
1430 | Lisp_Object value, oldval; | |
1431 | { | |
1432 | unsigned long pixel; | |
177c0ea7 | 1433 | |
333b20bb GM |
1434 | if (STRINGP (value)) |
1435 | pixel = x_decode_color (f, value, BLACK_PIX_DEFAULT (f)); | |
1436 | else | |
1437 | pixel = -1; | |
1438 | ||
1439 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
1440 | unload_color (f, f->output_data.x->scroll_bar_foreground_pixel); | |
177c0ea7 | 1441 | |
333b20bb GM |
1442 | f->output_data.x->scroll_bar_foreground_pixel = pixel; |
1443 | if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) | |
1444 | { | |
1445 | /* Remove all scroll bars because they have wrong colors. */ | |
428a555e KL |
1446 | if (FRAME_DISPLAY (f)->condemn_scroll_bars_hook) |
1447 | (*FRAME_DISPLAY (f)->condemn_scroll_bars_hook) (f); | |
1448 | if (FRAME_DISPLAY (f)->judge_scroll_bars_hook) | |
1449 | (*FRAME_DISPLAY (f)->judge_scroll_bars_hook) (f); | |
05c8abbe GM |
1450 | |
1451 | update_face_from_frame_parameter (f, Qscroll_bar_foreground, value); | |
333b20bb GM |
1452 | redraw_frame (f); |
1453 | } | |
1454 | } | |
1455 | ||
1456 | ||
1457 | /* Set the background color for scroll bars on frame F to VALUE VALUE | |
1458 | should be a string, a color name. If it isn't a string or isn't a | |
1459 | valid color name, do nothing. OLDVAL is the old value of the frame | |
1460 | parameter. */ | |
1461 | ||
1462 | void | |
1463 | x_set_scroll_bar_background (f, value, oldval) | |
1464 | struct frame *f; | |
1465 | Lisp_Object value, oldval; | |
1466 | { | |
1467 | unsigned long pixel; | |
1468 | ||
1469 | if (STRINGP (value)) | |
1470 | pixel = x_decode_color (f, value, WHITE_PIX_DEFAULT (f)); | |
1471 | else | |
1472 | pixel = -1; | |
177c0ea7 | 1473 | |
333b20bb GM |
1474 | if (f->output_data.x->scroll_bar_background_pixel != -1) |
1475 | unload_color (f, f->output_data.x->scroll_bar_background_pixel); | |
177c0ea7 | 1476 | |
f15340b7 MB |
1477 | #ifdef USE_TOOLKIT_SCROLL_BARS |
1478 | /* Scrollbar shadow colors. */ | |
1479 | if (f->output_data.x->scroll_bar_top_shadow_pixel != -1) | |
1480 | { | |
1481 | unload_color (f, f->output_data.x->scroll_bar_top_shadow_pixel); | |
1482 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
1483 | } | |
1484 | if (f->output_data.x->scroll_bar_bottom_shadow_pixel != -1) | |
1485 | { | |
1486 | unload_color (f, f->output_data.x->scroll_bar_bottom_shadow_pixel); | |
1487 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
1488 | } | |
1489 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
1490 | ||
333b20bb GM |
1491 | f->output_data.x->scroll_bar_background_pixel = pixel; |
1492 | if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) | |
1493 | { | |
1494 | /* Remove all scroll bars because they have wrong colors. */ | |
428a555e KL |
1495 | if (FRAME_DISPLAY (f)->condemn_scroll_bars_hook) |
1496 | (*FRAME_DISPLAY (f)->condemn_scroll_bars_hook) (f); | |
1497 | if (FRAME_DISPLAY (f)->judge_scroll_bars_hook) | |
1498 | (*FRAME_DISPLAY (f)->judge_scroll_bars_hook) (f); | |
177c0ea7 | 1499 | |
05c8abbe | 1500 | update_face_from_frame_parameter (f, Qscroll_bar_background, value); |
333b20bb GM |
1501 | redraw_frame (f); |
1502 | } | |
d043f1a4 | 1503 | } |
333b20bb | 1504 | |
943b580d | 1505 | \f |
3a258507 | 1506 | /* Encode Lisp string STRING as a text in a format appropriate for |
96db09e4 KH |
1507 | XICCC (X Inter Client Communication Conventions). |
1508 | ||
1509 | If STRING contains only ASCII characters, do no conversion and | |
1510 | return the string data of STRING. Otherwise, encode the text by | |
1511 | CODING_SYSTEM, and return a newly allocated memory area which | |
1512 | should be freed by `xfree' by a caller. | |
1513 | ||
37323f34 EZ |
1514 | SELECTIONP non-zero means the string is being encoded for an X |
1515 | selection, so it is safe to run pre-write conversions (which | |
1516 | may run Lisp code). | |
1517 | ||
96db09e4 KH |
1518 | Store the byte length of resulting text in *TEXT_BYTES. |
1519 | ||
d60660d6 | 1520 | If the text contains only ASCII and Latin-1, store 1 in *STRING_P, |
96db09e4 | 1521 | which means that the `encoding' of the result can be `STRING'. |
d60660d6 | 1522 | Otherwise store 0 in *STRINGP, which means that the `encoding' of |
96db09e4 KH |
1523 | the result should be `COMPOUND_TEXT'. */ |
1524 | ||
1525 | unsigned char * | |
37323f34 | 1526 | x_encode_text (string, coding_system, selectionp, text_bytes, stringp) |
96db09e4 | 1527 | Lisp_Object string, coding_system; |
d60660d6 | 1528 | int *text_bytes, *stringp; |
37323f34 | 1529 | int selectionp; |
96db09e4 | 1530 | { |
d5db4077 KR |
1531 | unsigned char *str = SDATA (string); |
1532 | int chars = SCHARS (string); | |
1533 | int bytes = SBYTES (string); | |
96db09e4 KH |
1534 | int charset_info; |
1535 | int bufsize; | |
1536 | unsigned char *buf; | |
1537 | struct coding_system coding; | |
43dc73f1 | 1538 | extern Lisp_Object Qcompound_text_with_extensions; |
96db09e4 KH |
1539 | |
1540 | charset_info = find_charset_in_text (str, chars, bytes, NULL, Qnil); | |
1541 | if (charset_info == 0) | |
1542 | { | |
1543 | /* No multibyte character in OBJ. We need not encode it. */ | |
1544 | *text_bytes = bytes; | |
d60660d6 | 1545 | *stringp = 1; |
96db09e4 KH |
1546 | return str; |
1547 | } | |
1548 | ||
1549 | setup_coding_system (coding_system, &coding); | |
37323f34 EZ |
1550 | if (selectionp |
1551 | && SYMBOLP (coding.pre_write_conversion) | |
1552 | && !NILP (Ffboundp (coding.pre_write_conversion))) | |
1553 | { | |
1554 | string = run_pre_post_conversion_on_str (string, &coding, 1); | |
d5db4077 KR |
1555 | str = SDATA (string); |
1556 | chars = SCHARS (string); | |
1557 | bytes = SBYTES (string); | |
37323f34 | 1558 | } |
96db09e4 KH |
1559 | coding.src_multibyte = 1; |
1560 | coding.dst_multibyte = 0; | |
1561 | coding.mode |= CODING_MODE_LAST_BLOCK; | |
d60660d6 KH |
1562 | if (coding.type == coding_type_iso2022) |
1563 | coding.flags |= CODING_FLAG_ISO_SAFE; | |
35bc5887 KH |
1564 | /* We suppress producing escape sequences for composition. */ |
1565 | coding.composing = COMPOSITION_DISABLED; | |
96db09e4 KH |
1566 | bufsize = encoding_buffer_size (&coding, bytes); |
1567 | buf = (unsigned char *) xmalloc (bufsize); | |
1568 | encode_coding (&coding, str, buf, bytes, bufsize); | |
1569 | *text_bytes = coding.produced; | |
43dc73f1 EZ |
1570 | *stringp = (charset_info == 1 |
1571 | || (!EQ (coding_system, Qcompound_text) | |
1572 | && !EQ (coding_system, Qcompound_text_with_extensions))); | |
96db09e4 KH |
1573 | return buf; |
1574 | } | |
1575 | ||
1576 | \f | |
b10daec7 JD |
1577 | /* Set the WM name to NAME for frame F. Also set the icon name. |
1578 | If the frame already has an icon name, use that, otherwise set the | |
1579 | icon name to NAME. */ | |
f945b920 | 1580 | |
b10daec7 JD |
1581 | static void |
1582 | x_set_name_internal (f, name) | |
1583 | FRAME_PTR f; | |
f945b920 | 1584 | Lisp_Object name; |
f945b920 | 1585 | { |
fe24a618 | 1586 | if (FRAME_X_WINDOW (f)) |
01f1ba30 | 1587 | { |
01f1ba30 | 1588 | BLOCK_INPUT; |
fe24a618 JB |
1589 | #ifdef HAVE_X11R4 |
1590 | { | |
80534dd6 | 1591 | XTextProperty text, icon; |
d60660d6 | 1592 | int bytes, stringp; |
b10daec7 | 1593 | int do_free_icon_value = 0, do_free_text_value = 0; |
11270583 | 1594 | Lisp_Object coding_system; |
80534dd6 | 1595 | |
b10daec7 | 1596 | coding_system = Qcompound_text; |
3201ea57 KH |
1597 | /* Note: Encoding strategy |
1598 | ||
1599 | We encode NAME by compound-text and use "COMPOUND-TEXT" in | |
1600 | text.encoding. But, there are non-internationalized window | |
1601 | managers which don't support that encoding. So, if NAME | |
1602 | contains only ASCII and 8859-1 characters, encode it by | |
1603 | iso-latin-1, and use "STRING" in text.encoding hoping that | |
34e8c597 | 1604 | such window managers at least analyze this format correctly, |
3201ea57 KH |
1605 | i.e. treat 8-bit bytes as 8859-1 characters. |
1606 | ||
1607 | We may also be able to use "UTF8_STRING" in text.encoding | |
34e8c597 | 1608 | in the future which can encode all Unicode characters. |
3201ea57 KH |
1609 | But, for the moment, there's no way to know that the |
1610 | current window manager supports it or not. */ | |
37323f34 | 1611 | text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp); |
d60660d6 | 1612 | text.encoding = (stringp ? XA_STRING |
96db09e4 | 1613 | : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); |
fe24a618 | 1614 | text.format = 8; |
96db09e4 | 1615 | text.nitems = bytes; |
80534dd6 | 1616 | |
b10daec7 JD |
1617 | /* Check early, because ENCODE_UTF_8 below may GC and name may be |
1618 | relocated. */ | |
1619 | do_free_text_value = text.value != SDATA (name); | |
1620 | ||
96db09e4 KH |
1621 | if (NILP (f->icon_name)) |
1622 | { | |
1623 | icon = text; | |
1624 | } | |
1625 | else | |
1626 | { | |
3201ea57 | 1627 | /* See the above comment "Note: Encoding strategy". */ |
37323f34 | 1628 | icon.value = x_encode_text (f->icon_name, coding_system, 0, |
d60660d6 KH |
1629 | &bytes, &stringp); |
1630 | icon.encoding = (stringp ? XA_STRING | |
96db09e4 KH |
1631 | : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); |
1632 | icon.format = 8; | |
1633 | icon.nitems = bytes; | |
b10daec7 | 1634 | do_free_icon_value = icon.value != SDATA (f->icon_name); |
96db09e4 | 1635 | } |
b10daec7 | 1636 | |
488dd4c4 JD |
1637 | #ifdef USE_GTK |
1638 | gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
00267f94 | 1639 | SDATA (ENCODE_UTF_8 (name))); |
488dd4c4 | 1640 | #else /* not USE_GTK */ |
2436a4e4 | 1641 | XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); |
7c0d3ed8 | 1642 | #endif /* not USE_GTK */ |
abb4b7ec | 1643 | |
7c0d3ed8 | 1644 | XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon); |
abb4b7ec | 1645 | |
b10daec7 | 1646 | if (do_free_icon_value) |
7c0d3ed8 | 1647 | xfree (icon.value); |
b10daec7 | 1648 | if (do_free_text_value) |
7c0d3ed8 KS |
1649 | xfree (text.value); |
1650 | } | |
1651 | #else /* not HAVE_X11R4 */ | |
1652 | XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
1653 | SDATA (name)); | |
1654 | XStoreName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
1655 | SDATA (name)); | |
1656 | #endif /* not HAVE_X11R4 */ | |
1657 | UNBLOCK_INPUT; | |
1658 | } | |
abb4b7ec RS |
1659 | } |
1660 | ||
b10daec7 JD |
1661 | /* Change the name of frame F to NAME. If NAME is nil, set F's name to |
1662 | x_id_name. | |
1663 | ||
1664 | If EXPLICIT is non-zero, that indicates that lisp code is setting the | |
1665 | name; if NAME is a string, set F's name to NAME and set | |
1666 | F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | |
1667 | ||
1668 | If EXPLICIT is zero, that indicates that Emacs redisplay code is | |
1669 | suggesting a new name, which lisp code should override; if | |
1670 | F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
1671 | ||
1672 | void | |
1673 | x_set_name (f, name, explicit) | |
1674 | struct frame *f; | |
1675 | Lisp_Object name; | |
1676 | int explicit; | |
1677 | { | |
1678 | /* Make sure that requests from lisp code override requests from | |
1679 | Emacs redisplay code. */ | |
1680 | if (explicit) | |
1681 | { | |
1682 | /* If we're switching from explicit to implicit, we had better | |
1683 | update the mode lines and thereby update the title. */ | |
1684 | if (f->explicit_name && NILP (name)) | |
1685 | update_mode_lines = 1; | |
1686 | ||
1687 | f->explicit_name = ! NILP (name); | |
1688 | } | |
1689 | else if (f->explicit_name) | |
1690 | return; | |
1691 | ||
1692 | /* If NAME is nil, set the name to the x_id_name. */ | |
1693 | if (NILP (name)) | |
1694 | { | |
1695 | /* Check for no change needed in this very common case | |
1696 | before we do any consing. */ | |
1697 | if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name, | |
1698 | SDATA (f->name))) | |
1699 | return; | |
1700 | name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name); | |
1701 | } | |
1702 | else | |
1703 | CHECK_STRING (name); | |
1704 | ||
1705 | /* Don't change the name if it's already NAME. */ | |
1706 | if (! NILP (Fstring_equal (name, f->name))) | |
1707 | return; | |
1708 | ||
1709 | f->name = name; | |
1710 | ||
1711 | /* For setting the frame title, the title parameter should override | |
1712 | the name parameter. */ | |
1713 | if (! NILP (f->title)) | |
1714 | name = f->title; | |
1715 | ||
1716 | x_set_name_internal (f, name); | |
1717 | } | |
1718 | ||
7c0d3ed8 KS |
1719 | /* This function should be called when the user's lisp code has |
1720 | specified a name for the frame; the name will override any set by the | |
1721 | redisplay code. */ | |
1722 | void | |
1723 | x_explicitly_set_name (f, arg, oldval) | |
1724 | FRAME_PTR f; | |
1725 | Lisp_Object arg, oldval; | |
3402e1a4 | 1726 | { |
7c0d3ed8 | 1727 | x_set_name (f, arg, 1); |
3402e1a4 RS |
1728 | } |
1729 | ||
7c0d3ed8 KS |
1730 | /* This function should be called by Emacs redisplay code to set the |
1731 | name; names set this way will never override names set by the user's | |
1732 | lisp code. */ | |
1733 | void | |
1734 | x_implicitly_set_name (f, arg, oldval) | |
1735 | FRAME_PTR f; | |
1736 | Lisp_Object arg, oldval; | |
333b20bb | 1737 | { |
7c0d3ed8 KS |
1738 | x_set_name (f, arg, 0); |
1739 | } | |
1740 | \f | |
1741 | /* Change the title of frame F to NAME. | |
1742 | If NAME is nil, use the frame name as the title. | |
60fb3ee1 | 1743 | |
7c0d3ed8 KS |
1744 | If EXPLICIT is non-zero, that indicates that lisp code is setting the |
1745 | name; if NAME is a string, set F's name to NAME and set | |
1746 | F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | |
60fb3ee1 | 1747 | |
7c0d3ed8 KS |
1748 | If EXPLICIT is zero, that indicates that Emacs redisplay code is |
1749 | suggesting a new name, which lisp code should override; if | |
1750 | F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
01f1ba30 | 1751 | |
7c0d3ed8 KS |
1752 | void |
1753 | x_set_title (f, name, old_name) | |
1754 | struct frame *f; | |
1755 | Lisp_Object name, old_name; | |
01f1ba30 | 1756 | { |
7c0d3ed8 KS |
1757 | /* Don't change the title if it's already NAME. */ |
1758 | if (EQ (name, f->title)) | |
1759 | return; | |
01f1ba30 | 1760 | |
7c0d3ed8 | 1761 | update_mode_lines = 1; |
60fb3ee1 | 1762 | |
7c0d3ed8 | 1763 | f->title = name; |
f9942c9e | 1764 | |
7c0d3ed8 KS |
1765 | if (NILP (name)) |
1766 | name = f->name; | |
1767 | else | |
1768 | CHECK_STRING (name); | |
f9942c9e | 1769 | |
b10daec7 | 1770 | x_set_name_internal (f, name); |
01f1ba30 JB |
1771 | } |
1772 | ||
7c0d3ed8 KS |
1773 | void |
1774 | x_set_scroll_bar_default_width (f) | |
e4f79258 | 1775 | struct frame *f; |
e4f79258 | 1776 | { |
be786000 | 1777 | int wid = FRAME_COLUMN_WIDTH (f); |
01f1ba30 | 1778 | |
7c0d3ed8 KS |
1779 | #ifdef USE_TOOLKIT_SCROLL_BARS |
1780 | /* A minimum width of 14 doesn't look good for toolkit scroll bars. */ | |
1781 | int width = 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM; | |
be786000 KS |
1782 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (width + wid - 1) / wid; |
1783 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = width; | |
7c0d3ed8 KS |
1784 | #else |
1785 | /* Make the actual width at least 14 pixels and a multiple of a | |
1786 | character width. */ | |
be786000 | 1787 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid; |
01f1ba30 | 1788 | |
7c0d3ed8 KS |
1789 | /* Use all of that space (aside from required margins) for the |
1790 | scroll bar. */ | |
be786000 | 1791 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 0; |
7c0d3ed8 | 1792 | #endif |
01f1ba30 | 1793 | } |
333b20bb | 1794 | |
7c0d3ed8 | 1795 | \f |
333b20bb GM |
1796 | /* Record in frame F the specified or default value according to ALIST |
1797 | of the parameter named PROP (a Lisp symbol). If no value is | |
1798 | specified for PROP, look for an X default for XPROP on the frame | |
1799 | named NAME. If that is not found either, use the value DEFLT. */ | |
1800 | ||
1801 | static Lisp_Object | |
1802 | x_default_scroll_bar_color_parameter (f, alist, prop, xprop, xclass, | |
1803 | foreground_p) | |
1804 | struct frame *f; | |
1805 | Lisp_Object alist; | |
1806 | Lisp_Object prop; | |
1807 | char *xprop; | |
1808 | char *xclass; | |
1809 | int foreground_p; | |
1810 | { | |
1811 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | |
1812 | Lisp_Object tem; | |
1813 | ||
1814 | tem = x_get_arg (dpyinfo, alist, prop, xprop, xclass, RES_TYPE_STRING); | |
1815 | if (EQ (tem, Qunbound)) | |
1816 | { | |
1817 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
1818 | ||
1819 | /* See if an X resource for the scroll bar color has been | |
1820 | specified. */ | |
1821 | tem = display_x_get_resource (dpyinfo, | |
1822 | build_string (foreground_p | |
1823 | ? "foreground" | |
1824 | : "background"), | |
c0ec53ad | 1825 | empty_string, |
333b20bb | 1826 | build_string ("verticalScrollBar"), |
c0ec53ad | 1827 | empty_string); |
333b20bb GM |
1828 | if (!STRINGP (tem)) |
1829 | { | |
1830 | /* If nothing has been specified, scroll bars will use a | |
1831 | toolkit-dependent default. Because these defaults are | |
1832 | difficult to get at without actually creating a scroll | |
1833 | bar, use nil to indicate that no color has been | |
1834 | specified. */ | |
1835 | tem = Qnil; | |
1836 | } | |
177c0ea7 | 1837 | |
333b20bb | 1838 | #else /* not USE_TOOLKIT_SCROLL_BARS */ |
177c0ea7 | 1839 | |
333b20bb | 1840 | tem = Qnil; |
177c0ea7 | 1841 | |
333b20bb GM |
1842 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
1843 | } | |
1844 | ||
1845 | x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil)); | |
1846 | return tem; | |
1847 | } | |
1848 | ||
1849 | ||
01f1ba30 | 1850 | |
f58534a3 RS |
1851 | #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS) |
1852 | ||
1853 | Status | |
1854 | XSetWMProtocols (dpy, w, protocols, count) | |
1855 | Display *dpy; | |
1856 | Window w; | |
1857 | Atom *protocols; | |
1858 | int count; | |
1859 | { | |
1860 | Atom prop; | |
1861 | prop = XInternAtom (dpy, "WM_PROTOCOLS", False); | |
1862 | if (prop == None) return False; | |
1863 | XChangeProperty (dpy, w, prop, XA_ATOM, 32, PropModeReplace, | |
1864 | (unsigned char *) protocols, count); | |
1865 | return True; | |
1866 | } | |
9ef48a9d RS |
1867 | #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */ |
1868 | \f | |
1869 | #ifdef USE_X_TOOLKIT | |
1870 | ||
8e3d10a9 RS |
1871 | /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS, |
1872 | WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may | |
59aa6c90 RS |
1873 | already be present because of the toolkit (Motif adds some of them, |
1874 | for example, but Xt doesn't). */ | |
9ef48a9d RS |
1875 | |
1876 | static void | |
b9dc4443 RS |
1877 | hack_wm_protocols (f, widget) |
1878 | FRAME_PTR f; | |
9ef48a9d RS |
1879 | Widget widget; |
1880 | { | |
1881 | Display *dpy = XtDisplay (widget); | |
1882 | Window w = XtWindow (widget); | |
1883 | int need_delete = 1; | |
1884 | int need_focus = 1; | |
59aa6c90 | 1885 | int need_save = 1; |
9ef48a9d RS |
1886 | |
1887 | BLOCK_INPUT; | |
1888 | { | |
1889 | Atom type, *atoms = 0; | |
1890 | int format = 0; | |
1891 | unsigned long nitems = 0; | |
1892 | unsigned long bytes_after; | |
1893 | ||
270958e8 KH |
1894 | if ((XGetWindowProperty (dpy, w, |
1895 | FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols, | |
34d5ae1e | 1896 | (long)0, (long)100, False, XA_ATOM, |
270958e8 KH |
1897 | &type, &format, &nitems, &bytes_after, |
1898 | (unsigned char **) &atoms) | |
1899 | == Success) | |
9ef48a9d RS |
1900 | && format == 32 && type == XA_ATOM) |
1901 | while (nitems > 0) | |
1902 | { | |
1903 | nitems--; | |
b9dc4443 RS |
1904 | if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window) |
1905 | need_delete = 0; | |
1906 | else if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus) | |
1907 | need_focus = 0; | |
1908 | else if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself) | |
1909 | need_save = 0; | |
9ef48a9d RS |
1910 | } |
1911 | if (atoms) XFree ((char *) atoms); | |
1912 | } | |
1913 | { | |
1914 | Atom props [10]; | |
1915 | int count = 0; | |
b9dc4443 RS |
1916 | if (need_delete) |
1917 | props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window; | |
1918 | if (need_focus) | |
1919 | props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus; | |
1920 | if (need_save) | |
1921 | props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself; | |
9ef48a9d | 1922 | if (count) |
b9dc4443 RS |
1923 | XChangeProperty (dpy, w, FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols, |
1924 | XA_ATOM, 32, PropModeAppend, | |
9ef48a9d RS |
1925 | (unsigned char *) props, count); |
1926 | } | |
1927 | UNBLOCK_INPUT; | |
1928 | } | |
1929 | #endif | |
86779fac GM |
1930 | |
1931 | ||
5a7df7d7 GM |
1932 | \f |
1933 | /* Support routines for XIC (X Input Context). */ | |
86779fac | 1934 | |
5a7df7d7 GM |
1935 | #ifdef HAVE_X_I18N |
1936 | ||
1937 | static XFontSet xic_create_xfontset P_ ((struct frame *, char *)); | |
1938 | static XIMStyle best_xim_style P_ ((XIMStyles *, XIMStyles *)); | |
1939 | ||
1940 | ||
1576f1ad | 1941 | /* Supported XIM styles, ordered by preference. */ |
5a7df7d7 GM |
1942 | |
1943 | static XIMStyle supported_xim_styles[] = | |
1944 | { | |
1945 | XIMPreeditPosition | XIMStatusArea, | |
1946 | XIMPreeditPosition | XIMStatusNothing, | |
1947 | XIMPreeditPosition | XIMStatusNone, | |
1948 | XIMPreeditNothing | XIMStatusArea, | |
1949 | XIMPreeditNothing | XIMStatusNothing, | |
1950 | XIMPreeditNothing | XIMStatusNone, | |
1951 | XIMPreeditNone | XIMStatusArea, | |
1952 | XIMPreeditNone | XIMStatusNothing, | |
1953 | XIMPreeditNone | XIMStatusNone, | |
1954 | 0, | |
1955 | }; | |
1956 | ||
1957 | ||
c27ed90a | 1958 | /* Create an X fontset on frame F with base font name BASE_FONTNAME. */ |
5a7df7d7 GM |
1959 | |
1960 | static XFontSet | |
1961 | xic_create_xfontset (f, base_fontname) | |
86779fac | 1962 | struct frame *f; |
5a7df7d7 | 1963 | char *base_fontname; |
86779fac | 1964 | { |
c27ed90a | 1965 | XFontSet xfs = NULL; |
63ea8ea5 | 1966 | char **missing_list = NULL; |
5a7df7d7 GM |
1967 | int missing_count; |
1968 | char *def_string; | |
c27ed90a JD |
1969 | Lisp_Object rest, frame; |
1970 | ||
1971 | /* See if there is another frame already using same fontset. */ | |
1972 | FOR_EACH_FRAME (rest, frame) | |
1973 | { | |
1974 | struct frame *cf = XFRAME (frame); | |
1975 | if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf) | |
1976 | && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f) | |
9db6ae81 | 1977 | && FRAME_XIC_BASE_FONTNAME (cf) |
c27ed90a JD |
1978 | && !strcmp (FRAME_XIC_BASE_FONTNAME (cf), base_fontname)) |
1979 | { | |
1980 | xfs = FRAME_XIC_FONTSET (cf); | |
1981 | break; | |
1982 | } | |
1983 | } | |
177c0ea7 | 1984 | |
c27ed90a | 1985 | if (!xfs) |
63ea8ea5 JD |
1986 | { |
1987 | /* New fontset. */ | |
1988 | xfs = XCreateFontSet (FRAME_X_DISPLAY (f), | |
1989 | base_fontname, &missing_list, | |
1990 | &missing_count, &def_string); | |
1991 | if (missing_list) | |
1992 | XFreeStringList (missing_list); | |
1993 | } | |
177c0ea7 | 1994 | |
c27ed90a JD |
1995 | if (FRAME_XIC_BASE_FONTNAME (f)) |
1996 | xfree (FRAME_XIC_BASE_FONTNAME (f)); | |
1997 | FRAME_XIC_BASE_FONTNAME (f) = xstrdup (base_fontname); | |
177c0ea7 | 1998 | |
c27ed90a | 1999 | /* No need to free def_string. */ |
5a7df7d7 GM |
2000 | return xfs; |
2001 | } | |
2002 | ||
c27ed90a JD |
2003 | /* Free the X fontset of frame F if it is the last frame using it. */ |
2004 | ||
2005 | void | |
2006 | xic_free_xfontset (f) | |
2007 | struct frame *f; | |
2008 | { | |
2009 | Lisp_Object rest, frame; | |
2010 | int shared_p = 0; | |
2011 | ||
2012 | if (!FRAME_XIC_FONTSET (f)) | |
2013 | return; | |
2014 | ||
2015 | /* See if there is another frame sharing the same fontset. */ | |
2016 | FOR_EACH_FRAME (rest, frame) | |
2017 | { | |
2018 | struct frame *cf = XFRAME (frame); | |
2019 | if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf) | |
2020 | && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f) | |
2021 | && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f)) | |
2022 | { | |
2023 | shared_p = 1; | |
2024 | break; | |
2025 | } | |
2026 | } | |
2027 | ||
2028 | if (!shared_p) | |
2029 | /* The fontset is not used anymore. It is safe to free it. */ | |
2030 | XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); | |
2031 | ||
2032 | if (FRAME_XIC_BASE_FONTNAME (f)) | |
2033 | xfree (FRAME_XIC_BASE_FONTNAME (f)); | |
2034 | FRAME_XIC_BASE_FONTNAME (f) = NULL; | |
2035 | FRAME_XIC_FONTSET (f) = NULL; | |
2036 | } | |
2037 | ||
5a7df7d7 GM |
2038 | |
2039 | /* Value is the best input style, given user preferences USER (already | |
2040 | checked to be supported by Emacs), and styles supported by the | |
2041 | input method XIM. */ | |
2042 | ||
2043 | static XIMStyle | |
2044 | best_xim_style (user, xim) | |
2045 | XIMStyles *user; | |
2046 | XIMStyles *xim; | |
2047 | { | |
2048 | int i, j; | |
2049 | ||
2050 | for (i = 0; i < user->count_styles; ++i) | |
2051 | for (j = 0; j < xim->count_styles; ++j) | |
2052 | if (user->supported_styles[i] == xim->supported_styles[j]) | |
2053 | return user->supported_styles[i]; | |
2054 | ||
2055 | /* Return the default style. */ | |
2056 | return XIMPreeditNothing | XIMStatusNothing; | |
2057 | } | |
2058 | ||
2059 | /* Create XIC for frame F. */ | |
2060 | ||
5df79d3d GM |
2061 | static XIMStyle xic_style; |
2062 | ||
5a7df7d7 GM |
2063 | void |
2064 | create_frame_xic (f) | |
2065 | struct frame *f; | |
2066 | { | |
5a7df7d7 GM |
2067 | XIM xim; |
2068 | XIC xic = NULL; | |
2069 | XFontSet xfs = NULL; | |
86779fac | 2070 | |
5a7df7d7 GM |
2071 | if (FRAME_XIC (f)) |
2072 | return; | |
177c0ea7 | 2073 | |
5a7df7d7 GM |
2074 | xim = FRAME_X_XIM (f); |
2075 | if (xim) | |
2076 | { | |
d9d57cb2 DL |
2077 | XRectangle s_area; |
2078 | XPoint spot; | |
5a7df7d7 GM |
2079 | XVaNestedList preedit_attr; |
2080 | XVaNestedList status_attr; | |
2081 | char *base_fontname; | |
2082 | int fontset; | |
2083 | ||
d9d57cb2 DL |
2084 | s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1; |
2085 | spot.x = 0; spot.y = 1; | |
5a7df7d7 GM |
2086 | /* Create X fontset. */ |
2087 | fontset = FRAME_FONTSET (f); | |
2088 | if (fontset < 0) | |
2089 | base_fontname = "-*-*-*-r-normal--14-*-*-*-*-*-*-*"; | |
2090 | else | |
2091 | { | |
6ecb43ce KH |
2092 | /* Determine the base fontname from the ASCII font name of |
2093 | FONTSET. */ | |
d5db4077 | 2094 | char *ascii_font = (char *) SDATA (fontset_ascii (fontset)); |
6ecb43ce | 2095 | char *p = ascii_font; |
5a7df7d7 | 2096 | int i; |
6ecb43ce KH |
2097 | |
2098 | for (i = 0; *p; p++) | |
2099 | if (*p == '-') i++; | |
2100 | if (i != 14) | |
2101 | /* As the font name doesn't conform to XLFD, we can't | |
2102 | modify it to get a suitable base fontname for the | |
2103 | frame. */ | |
2104 | base_fontname = "-*-*-*-r-normal--14-*-*-*-*-*-*-*"; | |
2105 | else | |
2106 | { | |
2107 | int len = strlen (ascii_font) + 1; | |
8ec8a5ec | 2108 | char *p1 = NULL; |
6ecb43ce KH |
2109 | |
2110 | for (i = 0, p = ascii_font; i < 8; p++) | |
2111 | { | |
2112 | if (*p == '-') | |
2113 | { | |
2114 | i++; | |
2115 | if (i == 3) | |
2116 | p1 = p + 1; | |
2117 | } | |
2118 | } | |
2119 | base_fontname = (char *) alloca (len); | |
2120 | bzero (base_fontname, len); | |
2121 | strcpy (base_fontname, "-*-*-"); | |
2122 | bcopy (p1, base_fontname + 5, p - p1); | |
2123 | strcat (base_fontname, "*-*-*-*-*-*-*"); | |
2124 | } | |
5a7df7d7 GM |
2125 | } |
2126 | xfs = xic_create_xfontset (f, base_fontname); | |
86779fac | 2127 | |
5a7df7d7 GM |
2128 | /* Determine XIC style. */ |
2129 | if (xic_style == 0) | |
2130 | { | |
2131 | XIMStyles supported_list; | |
2132 | supported_list.count_styles = (sizeof supported_xim_styles | |
2133 | / sizeof supported_xim_styles[0]); | |
2134 | supported_list.supported_styles = supported_xim_styles; | |
2135 | xic_style = best_xim_style (&supported_list, | |
2136 | FRAME_X_XIM_STYLES (f)); | |
2137 | } | |
86779fac | 2138 | |
5a7df7d7 GM |
2139 | preedit_attr = XVaCreateNestedList (0, |
2140 | XNFontSet, xfs, | |
2141 | XNForeground, | |
2142 | FRAME_FOREGROUND_PIXEL (f), | |
2143 | XNBackground, | |
2144 | FRAME_BACKGROUND_PIXEL (f), | |
2145 | (xic_style & XIMPreeditPosition | |
2146 | ? XNSpotLocation | |
2147 | : NULL), | |
2148 | &spot, | |
2149 | NULL); | |
2150 | status_attr = XVaCreateNestedList (0, | |
2151 | XNArea, | |
2152 | &s_area, | |
2153 | XNFontSet, | |
2154 | xfs, | |
2155 | XNForeground, | |
2156 | FRAME_FOREGROUND_PIXEL (f), | |
2157 | XNBackground, | |
2158 | FRAME_BACKGROUND_PIXEL (f), | |
2159 | NULL); | |
2160 | ||
2161 | xic = XCreateIC (xim, | |
2162 | XNInputStyle, xic_style, | |
810f2256 JD |
2163 | XNClientWindow, FRAME_X_WINDOW (f), |
2164 | XNFocusWindow, FRAME_X_WINDOW (f), | |
5a7df7d7 GM |
2165 | XNStatusAttributes, status_attr, |
2166 | XNPreeditAttributes, preedit_attr, | |
2167 | NULL); | |
2168 | XFree (preedit_attr); | |
2169 | XFree (status_attr); | |
2170 | } | |
177c0ea7 | 2171 | |
5a7df7d7 GM |
2172 | FRAME_XIC (f) = xic; |
2173 | FRAME_XIC_STYLE (f) = xic_style; | |
2174 | FRAME_XIC_FONTSET (f) = xfs; | |
86779fac GM |
2175 | } |
2176 | ||
5a7df7d7 GM |
2177 | |
2178 | /* Destroy XIC and free XIC fontset of frame F, if any. */ | |
2179 | ||
2180 | void | |
2181 | free_frame_xic (f) | |
2182 | struct frame *f; | |
2183 | { | |
2184 | if (FRAME_XIC (f) == NULL) | |
2185 | return; | |
177c0ea7 | 2186 | |
5a7df7d7 | 2187 | XDestroyIC (FRAME_XIC (f)); |
c27ed90a | 2188 | xic_free_xfontset (f); |
5a7df7d7 GM |
2189 | |
2190 | FRAME_XIC (f) = NULL; | |
5a7df7d7 GM |
2191 | } |
2192 | ||
2193 | ||
2194 | /* Place preedit area for XIC of window W's frame to specified | |
2195 | pixel position X/Y. X and Y are relative to window W. */ | |
2196 | ||
2197 | void | |
2198 | xic_set_preeditarea (w, x, y) | |
2199 | struct window *w; | |
2200 | int x, y; | |
2201 | { | |
2202 | struct frame *f = XFRAME (w->frame); | |
2203 | XVaNestedList attr; | |
2204 | XPoint spot; | |
177c0ea7 | 2205 | |
17e6d491 | 2206 | spot.x = WINDOW_TO_FRAME_PIXEL_X (w, x) + WINDOW_LEFT_FRINGE_WIDTH (w); |
5a7df7d7 GM |
2207 | spot.y = WINDOW_TO_FRAME_PIXEL_Y (w, y) + FONT_BASE (FRAME_FONT (f)); |
2208 | attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); | |
2209 | XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL); | |
2210 | XFree (attr); | |
2211 | } | |
2212 | ||
2213 | ||
2214 | /* Place status area for XIC in bottom right corner of frame F.. */ | |
2215 | ||
2216 | void | |
2217 | xic_set_statusarea (f) | |
2218 | struct frame *f; | |
2219 | { | |
2220 | XIC xic = FRAME_XIC (f); | |
2221 | XVaNestedList attr; | |
2222 | XRectangle area; | |
2223 | XRectangle *needed; | |
2224 | ||
2225 | /* Negotiate geometry of status area. If input method has existing | |
2226 | status area, use its current size. */ | |
2227 | area.x = area.y = area.width = area.height = 0; | |
2228 | attr = XVaCreateNestedList (0, XNAreaNeeded, &area, NULL); | |
2229 | XSetICValues (xic, XNStatusAttributes, attr, NULL); | |
2230 | XFree (attr); | |
177c0ea7 | 2231 | |
5a7df7d7 GM |
2232 | attr = XVaCreateNestedList (0, XNAreaNeeded, &needed, NULL); |
2233 | XGetICValues (xic, XNStatusAttributes, attr, NULL); | |
2234 | XFree (attr); | |
2235 | ||
2236 | if (needed->width == 0) /* Use XNArea instead of XNAreaNeeded */ | |
2237 | { | |
2238 | attr = XVaCreateNestedList (0, XNArea, &needed, NULL); | |
2239 | XGetICValues (xic, XNStatusAttributes, attr, NULL); | |
2240 | XFree (attr); | |
2241 | } | |
2242 | ||
2243 | area.width = needed->width; | |
2244 | area.height = needed->height; | |
be786000 KS |
2245 | area.x = FRAME_PIXEL_WIDTH (f) - area.width - FRAME_INTERNAL_BORDER_WIDTH (f); |
2246 | area.y = (FRAME_PIXEL_HEIGHT (f) - area.height | |
488dd4c4 JD |
2247 | - FRAME_MENUBAR_HEIGHT (f) |
2248 | - FRAME_TOOLBAR_HEIGHT (f) | |
2249 | - FRAME_INTERNAL_BORDER_WIDTH (f)); | |
5a7df7d7 GM |
2250 | XFree (needed); |
2251 | ||
2252 | attr = XVaCreateNestedList (0, XNArea, &area, NULL); | |
810f2256 | 2253 | XSetICValues (xic, XNStatusAttributes, attr, NULL); |
5a7df7d7 GM |
2254 | XFree (attr); |
2255 | } | |
2256 | ||
2257 | ||
2258 | /* Set X fontset for XIC of frame F, using base font name | |
2259 | BASE_FONTNAME. Called when a new Emacs fontset is chosen. */ | |
2260 | ||
2261 | void | |
2262 | xic_set_xfontset (f, base_fontname) | |
2263 | struct frame *f; | |
2264 | char *base_fontname; | |
2265 | { | |
2266 | XVaNestedList attr; | |
2267 | XFontSet xfs; | |
2268 | ||
c27ed90a JD |
2269 | xic_free_xfontset (f); |
2270 | ||
5a7df7d7 GM |
2271 | xfs = xic_create_xfontset (f, base_fontname); |
2272 | ||
2273 | attr = XVaCreateNestedList (0, XNFontSet, xfs, NULL); | |
2274 | if (FRAME_XIC_STYLE (f) & XIMPreeditPosition) | |
2275 | XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL); | |
2276 | if (FRAME_XIC_STYLE (f) & XIMStatusArea) | |
2277 | XSetICValues (FRAME_XIC (f), XNStatusAttributes, attr, NULL); | |
2278 | XFree (attr); | |
177c0ea7 | 2279 | |
5a7df7d7 GM |
2280 | FRAME_XIC_FONTSET (f) = xfs; |
2281 | } | |
2282 | ||
2283 | #endif /* HAVE_X_I18N */ | |
2284 | ||
2285 | ||
9ef48a9d | 2286 | \f |
8fc2766b RS |
2287 | #ifdef USE_X_TOOLKIT |
2288 | ||
2289 | /* Create and set up the X widget for frame F. */ | |
f58534a3 | 2290 | |
01f1ba30 | 2291 | static void |
a7f7d550 FP |
2292 | x_window (f, window_prompting, minibuffer_only) |
2293 | struct frame *f; | |
2294 | long window_prompting; | |
2295 | int minibuffer_only; | |
01f1ba30 | 2296 | { |
9ef48a9d | 2297 | XClassHint class_hints; |
31ac8d8c FP |
2298 | XSetWindowAttributes attributes; |
2299 | unsigned long attribute_mask; | |
9ef48a9d RS |
2300 | Widget shell_widget; |
2301 | Widget pane_widget; | |
6c32dd68 | 2302 | Widget frame_widget; |
9ef48a9d RS |
2303 | Arg al [25]; |
2304 | int ac; | |
2305 | ||
2306 | BLOCK_INPUT; | |
2307 | ||
b7975ee4 KH |
2308 | /* Use the resource name as the top-level widget name |
2309 | for looking up resources. Make a non-Lisp copy | |
2310 | for the window manager, so GC relocation won't bother it. | |
2311 | ||
2312 | Elsewhere we specify the window name for the window manager. */ | |
177c0ea7 | 2313 | |
cca176a0 | 2314 | { |
d5db4077 | 2315 | char *str = (char *) SDATA (Vx_resource_name); |
b7975ee4 | 2316 | f->namebuf = (char *) xmalloc (strlen (str) + 1); |
cca176a0 KH |
2317 | strcpy (f->namebuf, str); |
2318 | } | |
9ef48a9d RS |
2319 | |
2320 | ac = 0; | |
2321 | XtSetArg (al[ac], XtNallowShellResize, 1); ac++; | |
2322 | XtSetArg (al[ac], XtNinput, 1); ac++; | |
97787173 | 2323 | XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++; |
be786000 | 2324 | XtSetArg (al[ac], XtNborderWidth, f->border_width); ac++; |
9b2956e2 GM |
2325 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; |
2326 | XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++; | |
2327 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; | |
cca176a0 | 2328 | shell_widget = XtAppCreateShell (f->namebuf, EMACS_CLASS, |
7a994728 | 2329 | applicationShellWidgetClass, |
82c90203 | 2330 | FRAME_X_DISPLAY (f), al, ac); |
9ef48a9d | 2331 | |
7556890b | 2332 | f->output_data.x->widget = shell_widget; |
9ef48a9d RS |
2333 | /* maybe_set_screen_title_format (shell_widget); */ |
2334 | ||
6c32dd68 PR |
2335 | pane_widget = lw_create_widget ("main", "pane", widget_id_tick++, |
2336 | (widget_value *) NULL, | |
2337 | shell_widget, False, | |
2338 | (lw_callback) NULL, | |
2339 | (lw_callback) NULL, | |
b6e11efd | 2340 | (lw_callback) NULL, |
6c32dd68 | 2341 | (lw_callback) NULL); |
9ef48a9d | 2342 | |
9b2956e2 GM |
2343 | ac = 0; |
2344 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; | |
2345 | XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++; | |
2346 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; | |
2347 | XtSetValues (pane_widget, al, ac); | |
7556890b | 2348 | f->output_data.x->column_widget = pane_widget; |
a7f7d550 | 2349 | |
177c0ea7 | 2350 | /* mappedWhenManaged to false tells to the paned window to not map/unmap |
5e65b9ab | 2351 | the emacs screen when changing menubar. This reduces flickering. */ |
9ef48a9d RS |
2352 | |
2353 | ac = 0; | |
2354 | XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++; | |
2355 | XtSetArg (al[ac], XtNshowGrip, 0); ac++; | |
2356 | XtSetArg (al[ac], XtNallowResize, 1); ac++; | |
2357 | XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++; | |
2358 | XtSetArg (al[ac], XtNemacsFrame, f); ac++; | |
9b2956e2 GM |
2359 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; |
2360 | XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++; | |
2361 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; | |
2362 | frame_widget = XtCreateWidget (f->namebuf, emacsFrameClass, pane_widget, | |
2363 | al, ac); | |
177c0ea7 | 2364 | |
7556890b | 2365 | f->output_data.x->edit_widget = frame_widget; |
177c0ea7 JB |
2366 | |
2367 | XtManageChild (frame_widget); | |
a7f7d550 FP |
2368 | |
2369 | /* Do some needed geometry management. */ | |
2370 | { | |
2371 | int len; | |
2372 | char *tem, shell_position[32]; | |
74305183 | 2373 | Arg al[10]; |
a7f7d550 | 2374 | int ac = 0; |
5031cc10 | 2375 | int extra_borders = 0; |
177c0ea7 | 2376 | int menubar_size |
7556890b RS |
2377 | = (f->output_data.x->menubar_widget |
2378 | ? (f->output_data.x->menubar_widget->core.height | |
2379 | + f->output_data.x->menubar_widget->core.border_width) | |
8fc2766b | 2380 | : 0); |
a7f7d550 | 2381 | |
f7008aff RS |
2382 | #if 0 /* Experimentally, we now get the right results |
2383 | for -geometry -0-0 without this. 24 Aug 96, rms. */ | |
01cbdba5 RS |
2384 | if (FRAME_EXTERNAL_MENU_BAR (f)) |
2385 | { | |
dd254b21 | 2386 | Dimension ibw = 0; |
01cbdba5 RS |
2387 | XtVaGetValues (pane_widget, XtNinternalBorderWidth, &ibw, NULL); |
2388 | menubar_size += ibw; | |
2389 | } | |
f7008aff | 2390 | #endif |
01cbdba5 | 2391 | |
7556890b | 2392 | f->output_data.x->menubar_height = menubar_size; |
00983aba | 2393 | |
440b0bfd | 2394 | #ifndef USE_LUCID |
5031cc10 KH |
2395 | /* Motif seems to need this amount added to the sizes |
2396 | specified for the shell widget. The Athena/Lucid widgets don't. | |
2397 | Both conclusions reached experimentally. -- rms. */ | |
440b0bfd RS |
2398 | XtVaGetValues (f->output_data.x->edit_widget, XtNinternalBorderWidth, |
2399 | &extra_borders, NULL); | |
2400 | extra_borders *= 2; | |
2401 | #endif | |
5031cc10 | 2402 | |
97787173 RS |
2403 | /* Convert our geometry parameters into a geometry string |
2404 | and specify it. | |
2405 | Note that we do not specify here whether the position | |
2406 | is a user-specified or program-specified one. | |
2407 | We pass that information later, in x_wm_set_size_hints. */ | |
2408 | { | |
be786000 | 2409 | int left = f->left_pos; |
97787173 | 2410 | int xneg = window_prompting & XNegative; |
be786000 | 2411 | int top = f->top_pos; |
97787173 RS |
2412 | int yneg = window_prompting & YNegative; |
2413 | if (xneg) | |
2414 | left = -left; | |
2415 | if (yneg) | |
2416 | top = -top; | |
c760f47e KH |
2417 | |
2418 | if (window_prompting & USPosition) | |
5031cc10 | 2419 | sprintf (shell_position, "=%dx%d%c%d%c%d", |
be786000 KS |
2420 | FRAME_PIXEL_WIDTH (f) + extra_borders, |
2421 | FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders, | |
c760f47e KH |
2422 | (xneg ? '-' : '+'), left, |
2423 | (yneg ? '-' : '+'), top); | |
2424 | else | |
74305183 JD |
2425 | { |
2426 | sprintf (shell_position, "=%dx%d", | |
2427 | FRAME_PIXEL_WIDTH (f) + extra_borders, | |
2428 | FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders); | |
2429 | ||
2430 | /* Setting x and y when the position is not specified in | |
2431 | the geometry string will set program position in the WM hints. | |
2432 | If Emacs had just one program position, we could set it in | |
2433 | fallback resources, but since each make-frame call can specify | |
2434 | different program positions, this is easier. */ | |
2435 | XtSetArg (al[ac], XtNx, left); ac++; | |
2436 | XtSetArg (al[ac], XtNy, top); ac++; | |
2437 | } | |
97787173 RS |
2438 | } |
2439 | ||
a7f7d550 | 2440 | len = strlen (shell_position) + 1; |
77110caa RS |
2441 | /* We don't free this because we don't know whether |
2442 | it is safe to free it while the frame exists. | |
2443 | It isn't worth the trouble of arranging to free it | |
2444 | when the frame is deleted. */ | |
a7f7d550 FP |
2445 | tem = (char *) xmalloc (len); |
2446 | strncpy (tem, shell_position, len); | |
2447 | XtSetArg (al[ac], XtNgeometry, tem); ac++; | |
2448 | XtSetValues (shell_widget, al, ac); | |
2449 | } | |
2450 | ||
9ef48a9d RS |
2451 | XtManageChild (pane_widget); |
2452 | XtRealizeWidget (shell_widget); | |
2453 | ||
177c0ea7 | 2454 | FRAME_X_WINDOW (f) = XtWindow (frame_widget); |
9ef48a9d RS |
2455 | |
2456 | validate_x_resource_name (); | |
b7975ee4 | 2457 | |
d5db4077 KR |
2458 | class_hints.res_name = (char *) SDATA (Vx_resource_name); |
2459 | class_hints.res_class = (char *) SDATA (Vx_resource_class); | |
b9dc4443 | 2460 | XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints); |
5a7df7d7 GM |
2461 | |
2462 | #ifdef HAVE_X_I18N | |
2463 | FRAME_XIC (f) = NULL; | |
1576f1ad DL |
2464 | if (use_xim) |
2465 | create_frame_xic (f); | |
5a7df7d7 | 2466 | #endif |
64d16748 | 2467 | |
7556890b RS |
2468 | f->output_data.x->wm_hints.input = True; |
2469 | f->output_data.x->wm_hints.flags |= InputHint; | |
b9dc4443 | 2470 | XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 2471 | &f->output_data.x->wm_hints); |
b8228beb | 2472 | |
c4ec904f | 2473 | hack_wm_protocols (f, shell_widget); |
9ef48a9d | 2474 | |
6c32dd68 PR |
2475 | #ifdef HACK_EDITRES |
2476 | XtAddEventHandler (shell_widget, 0, True, _XEditResCheckMessages, 0); | |
2477 | #endif | |
2478 | ||
9ef48a9d | 2479 | /* Do a stupid property change to force the server to generate a |
333b20bb | 2480 | PropertyNotify event so that the event_stream server timestamp will |
9ef48a9d RS |
2481 | be initialized to something relevant to the time we created the window. |
2482 | */ | |
6c32dd68 | 2483 | XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget), |
b9dc4443 RS |
2484 | FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols, |
2485 | XA_ATOM, 32, PropModeAppend, | |
9ef48a9d RS |
2486 | (unsigned char*) NULL, 0); |
2487 | ||
5a7df7d7 | 2488 | /* Make all the standard events reach the Emacs frame. */ |
31ac8d8c | 2489 | attributes.event_mask = STANDARD_EVENT_SET; |
5a7df7d7 GM |
2490 | |
2491 | #ifdef HAVE_X_I18N | |
2492 | if (FRAME_XIC (f)) | |
2493 | { | |
2494 | /* XIM server might require some X events. */ | |
2495 | unsigned long fevent = NoEventMask; | |
810f2256 | 2496 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
5a7df7d7 GM |
2497 | attributes.event_mask |= fevent; |
2498 | } | |
2499 | #endif /* HAVE_X_I18N */ | |
177c0ea7 | 2500 | |
31ac8d8c FP |
2501 | attribute_mask = CWEventMask; |
2502 | XChangeWindowAttributes (XtDisplay (shell_widget), XtWindow (shell_widget), | |
2503 | attribute_mask, &attributes); | |
2504 | ||
6c32dd68 | 2505 | XtMapWidget (frame_widget); |
9ef48a9d | 2506 | |
8fc2766b RS |
2507 | /* x_set_name normally ignores requests to set the name if the |
2508 | requested name is the same as the current name. This is the one | |
2509 | place where that assumption isn't correct; f->name is set, but | |
2510 | the X server hasn't been told. */ | |
2511 | { | |
2512 | Lisp_Object name; | |
2513 | int explicit = f->explicit_name; | |
2514 | ||
2515 | f->explicit_name = 0; | |
2516 | name = f->name; | |
2517 | f->name = Qnil; | |
2518 | x_set_name (f, name, explicit); | |
2519 | } | |
2520 | ||
b9dc4443 | 2521 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 2522 | f->output_data.x->text_cursor); |
8fc2766b RS |
2523 | |
2524 | UNBLOCK_INPUT; | |
2525 | ||
495fa05e GM |
2526 | /* This is a no-op, except under Motif. Make sure main areas are |
2527 | set to something reasonable, in case we get an error later. */ | |
2528 | lw_set_main_areas (pane_widget, 0, frame_widget); | |
8fc2766b RS |
2529 | } |
2530 | ||
9ef48a9d | 2531 | #else /* not USE_X_TOOLKIT */ |
488dd4c4 JD |
2532 | #ifdef USE_GTK |
2533 | void | |
2534 | x_window (f) | |
2535 | FRAME_PTR f; | |
2536 | { | |
2537 | if (! xg_create_frame_widgets (f)) | |
2538 | error ("Unable to create window"); | |
1fcfb866 JD |
2539 | |
2540 | #ifdef HAVE_X_I18N | |
2541 | FRAME_XIC (f) = NULL; | |
b59dd9c8 | 2542 | if (use_xim) |
1576f1ad DL |
2543 | { |
2544 | BLOCK_INPUT; | |
2545 | create_frame_xic (f); | |
2546 | if (FRAME_XIC (f)) | |
2547 | { | |
2548 | /* XIM server might require some X events. */ | |
2549 | unsigned long fevent = NoEventMask; | |
810f2256 | 2550 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
1fcfb866 | 2551 | |
1576f1ad DL |
2552 | if (fevent != NoEventMask) |
2553 | { | |
2554 | XSetWindowAttributes attributes; | |
2555 | XWindowAttributes wattr; | |
2556 | unsigned long attribute_mask; | |
2557 | ||
2558 | XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2559 | &wattr); | |
2560 | attributes.event_mask = wattr.your_event_mask | fevent; | |
2561 | attribute_mask = CWEventMask; | |
2562 | XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2563 | attribute_mask, &attributes); | |
2564 | } | |
2565 | } | |
2566 | UNBLOCK_INPUT; | |
2567 | } | |
1fcfb866 | 2568 | #endif |
488dd4c4 | 2569 | } |
9ef48a9d | 2570 | |
488dd4c4 | 2571 | #else /*! USE_GTK */ |
8fc2766b RS |
2572 | /* Create and set up the X window for frame F. */ |
2573 | ||
201d8c78 | 2574 | void |
8fc2766b RS |
2575 | x_window (f) |
2576 | struct frame *f; | |
2577 | ||
2578 | { | |
2579 | XClassHint class_hints; | |
2580 | XSetWindowAttributes attributes; | |
2581 | unsigned long attribute_mask; | |
2582 | ||
7556890b RS |
2583 | attributes.background_pixel = f->output_data.x->background_pixel; |
2584 | attributes.border_pixel = f->output_data.x->border_pixel; | |
01f1ba30 JB |
2585 | attributes.bit_gravity = StaticGravity; |
2586 | attributes.backing_store = NotUseful; | |
2587 | attributes.save_under = True; | |
2588 | attributes.event_mask = STANDARD_EVENT_SET; | |
9b2956e2 GM |
2589 | attributes.colormap = FRAME_X_COLORMAP (f); |
2590 | attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask | |
2591 | | CWColormap); | |
01f1ba30 JB |
2592 | |
2593 | BLOCK_INPUT; | |
fe24a618 | 2594 | FRAME_X_WINDOW (f) |
b9dc4443 | 2595 | = XCreateWindow (FRAME_X_DISPLAY (f), |
7556890b | 2596 | f->output_data.x->parent_desc, |
be786000 KS |
2597 | f->left_pos, |
2598 | f->top_pos, | |
2599 | FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), | |
2600 | f->border_width, | |
01f1ba30 JB |
2601 | CopyFromParent, /* depth */ |
2602 | InputOutput, /* class */ | |
383d6ffc | 2603 | FRAME_X_VISUAL (f), |
01f1ba30 | 2604 | attribute_mask, &attributes); |
5a7df7d7 GM |
2605 | |
2606 | #ifdef HAVE_X_I18N | |
4dacadcc | 2607 | if (use_xim) |
5a7df7d7 | 2608 | { |
1576f1ad DL |
2609 | create_frame_xic (f); |
2610 | if (FRAME_XIC (f)) | |
2611 | { | |
2612 | /* XIM server might require some X events. */ | |
2613 | unsigned long fevent = NoEventMask; | |
810f2256 | 2614 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
1576f1ad DL |
2615 | attributes.event_mask |= fevent; |
2616 | attribute_mask = CWEventMask; | |
2617 | XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2618 | attribute_mask, &attributes); | |
2619 | } | |
5a7df7d7 GM |
2620 | } |
2621 | #endif /* HAVE_X_I18N */ | |
177c0ea7 | 2622 | |
d387c960 | 2623 | validate_x_resource_name (); |
b7975ee4 | 2624 | |
d5db4077 KR |
2625 | class_hints.res_name = (char *) SDATA (Vx_resource_name); |
2626 | class_hints.res_class = (char *) SDATA (Vx_resource_class); | |
b9dc4443 | 2627 | XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints); |
01f1ba30 | 2628 | |
00983aba KH |
2629 | /* The menubar is part of the ordinary display; |
2630 | it does not count in addition to the height of the window. */ | |
7556890b | 2631 | f->output_data.x->menubar_height = 0; |
00983aba | 2632 | |
179956b9 JB |
2633 | /* This indicates that we use the "Passive Input" input model. |
2634 | Unless we do this, we don't get the Focus{In,Out} events that we | |
2635 | need to draw the cursor correctly. Accursed bureaucrats. | |
b9dc4443 | 2636 | XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */ |
179956b9 | 2637 | |
7556890b RS |
2638 | f->output_data.x->wm_hints.input = True; |
2639 | f->output_data.x->wm_hints.flags |= InputHint; | |
b9dc4443 | 2640 | XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 2641 | &f->output_data.x->wm_hints); |
6d078211 | 2642 | f->output_data.x->wm_hints.icon_pixmap = None; |
179956b9 | 2643 | |
032e4ebe RS |
2644 | /* Request "save yourself" and "delete window" commands from wm. */ |
2645 | { | |
2646 | Atom protocols[2]; | |
b9dc4443 RS |
2647 | protocols[0] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window; |
2648 | protocols[1] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself; | |
2649 | XSetWMProtocols (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), protocols, 2); | |
032e4ebe | 2650 | } |
9ef48a9d | 2651 | |
e373f201 JB |
2652 | /* x_set_name normally ignores requests to set the name if the |
2653 | requested name is the same as the current name. This is the one | |
2654 | place where that assumption isn't correct; f->name is set, but | |
2655 | the X server hasn't been told. */ | |
2656 | { | |
98381190 | 2657 | Lisp_Object name; |
cf177271 | 2658 | int explicit = f->explicit_name; |
e373f201 | 2659 | |
cf177271 | 2660 | f->explicit_name = 0; |
98381190 KH |
2661 | name = f->name; |
2662 | f->name = Qnil; | |
cf177271 | 2663 | x_set_name (f, name, explicit); |
e373f201 JB |
2664 | } |
2665 | ||
b9dc4443 | 2666 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 2667 | f->output_data.x->text_cursor); |
9ef48a9d | 2668 | |
01f1ba30 JB |
2669 | UNBLOCK_INPUT; |
2670 | ||
fe24a618 | 2671 | if (FRAME_X_WINDOW (f) == 0) |
9ef48a9d | 2672 | error ("Unable to create window"); |
01f1ba30 JB |
2673 | } |
2674 | ||
488dd4c4 | 2675 | #endif /* not USE_GTK */ |
8fc2766b RS |
2676 | #endif /* not USE_X_TOOLKIT */ |
2677 | ||
289978b5 LT |
2678 | /* Verify that the icon position args for this window are valid. */ |
2679 | ||
2680 | static void | |
2681 | x_icon_verify (f, parms) | |
2682 | struct frame *f; | |
2683 | Lisp_Object parms; | |
2684 | { | |
2685 | Lisp_Object icon_x, icon_y; | |
2686 | ||
2687 | /* Set the position of the icon. Note that twm groups all | |
2688 | icons in an icon window. */ | |
2689 | icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); | |
2690 | icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); | |
2691 | if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) | |
2692 | { | |
2693 | CHECK_NUMBER (icon_x); | |
2694 | CHECK_NUMBER (icon_y); | |
2695 | } | |
2696 | else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) | |
2697 | error ("Both left and top icon corners of icon must be specified"); | |
2698 | } | |
2699 | ||
01f1ba30 JB |
2700 | /* Handle the icon stuff for this window. Perhaps later we might |
2701 | want an x_set_icon_position which can be called interactively as | |
b9dc4443 | 2702 | well. */ |
01f1ba30 JB |
2703 | |
2704 | static void | |
f676886a JB |
2705 | x_icon (f, parms) |
2706 | struct frame *f; | |
01f1ba30 JB |
2707 | Lisp_Object parms; |
2708 | { | |
f9942c9e | 2709 | Lisp_Object icon_x, icon_y; |
abb4b7ec | 2710 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
01f1ba30 JB |
2711 | |
2712 | /* Set the position of the icon. Note that twm groups all | |
b9dc4443 | 2713 | icons in an icon window. */ |
7c0d3ed8 KS |
2714 | icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); |
2715 | icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); | |
f9942c9e | 2716 | if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) |
01f1ba30 | 2717 | { |
b7826503 PJ |
2718 | CHECK_NUMBER (icon_x); |
2719 | CHECK_NUMBER (icon_y); | |
01f1ba30 | 2720 | } |
f9942c9e | 2721 | else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) |
01f1ba30 | 2722 | error ("Both left and top icon corners of icon must be specified"); |
01f1ba30 | 2723 | |
f9942c9e JB |
2724 | BLOCK_INPUT; |
2725 | ||
fe24a618 JB |
2726 | if (! EQ (icon_x, Qunbound)) |
2727 | x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y)); | |
f9942c9e | 2728 | |
01f1ba30 | 2729 | /* Start up iconic or window? */ |
49795535 | 2730 | x_wm_set_window_state |
333b20bb GM |
2731 | (f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL), |
2732 | Qicon) | |
49795535 JB |
2733 | ? IconicState |
2734 | : NormalState)); | |
01f1ba30 | 2735 | |
d5db4077 | 2736 | x_text_icon (f, (char *) SDATA ((!NILP (f->icon_name) |
f468da95 | 2737 | ? f->icon_name |
d5db4077 | 2738 | : f->name))); |
80534dd6 | 2739 | |
01f1ba30 JB |
2740 | UNBLOCK_INPUT; |
2741 | } | |
2742 | ||
b243755a | 2743 | /* Make the GCs needed for this window, setting the |
01f1ba30 JB |
2744 | background, border and mouse colors; also create the |
2745 | mouse cursor and the gray border tile. */ | |
2746 | ||
f945b920 JB |
2747 | static char cursor_bits[] = |
2748 | { | |
2749 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
2750 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
2751 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
2752 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
2753 | }; | |
2754 | ||
01f1ba30 | 2755 | static void |
f676886a JB |
2756 | x_make_gc (f) |
2757 | struct frame *f; | |
01f1ba30 JB |
2758 | { |
2759 | XGCValues gc_values; | |
01f1ba30 | 2760 | |
6afb1d07 JB |
2761 | BLOCK_INPUT; |
2762 | ||
b243755a | 2763 | /* Create the GCs of this frame. |
9ef48a9d | 2764 | Note that many default values are used. */ |
01f1ba30 JB |
2765 | |
2766 | /* Normal video */ | |
be786000 | 2767 | gc_values.font = FRAME_FONT (f)->fid; |
7556890b RS |
2768 | gc_values.foreground = f->output_data.x->foreground_pixel; |
2769 | gc_values.background = f->output_data.x->background_pixel; | |
9ef48a9d | 2770 | gc_values.line_width = 0; /* Means 1 using fast algorithm. */ |
959e647d GM |
2771 | f->output_data.x->normal_gc |
2772 | = XCreateGC (FRAME_X_DISPLAY (f), | |
2773 | FRAME_X_WINDOW (f), | |
2774 | GCLineWidth | GCFont | GCForeground | GCBackground, | |
2775 | &gc_values); | |
01f1ba30 | 2776 | |
b9dc4443 | 2777 | /* Reverse video style. */ |
7556890b RS |
2778 | gc_values.foreground = f->output_data.x->background_pixel; |
2779 | gc_values.background = f->output_data.x->foreground_pixel; | |
959e647d GM |
2780 | f->output_data.x->reverse_gc |
2781 | = XCreateGC (FRAME_X_DISPLAY (f), | |
2782 | FRAME_X_WINDOW (f), | |
2783 | GCFont | GCForeground | GCBackground | GCLineWidth, | |
2784 | &gc_values); | |
01f1ba30 | 2785 | |
9ef48a9d | 2786 | /* Cursor has cursor-color background, background-color foreground. */ |
7556890b RS |
2787 | gc_values.foreground = f->output_data.x->background_pixel; |
2788 | gc_values.background = f->output_data.x->cursor_pixel; | |
01f1ba30 JB |
2789 | gc_values.fill_style = FillOpaqueStippled; |
2790 | gc_values.stipple | |
b9dc4443 RS |
2791 | = XCreateBitmapFromData (FRAME_X_DISPLAY (f), |
2792 | FRAME_X_DISPLAY_INFO (f)->root_window, | |
01f1ba30 | 2793 | cursor_bits, 16, 16); |
7556890b | 2794 | f->output_data.x->cursor_gc |
b9dc4443 | 2795 | = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
01f1ba30 | 2796 | (GCFont | GCForeground | GCBackground |
ac1f48a4 | 2797 | | GCFillStyle /* | GCStipple */ | GCLineWidth), |
01f1ba30 JB |
2798 | &gc_values); |
2799 | ||
333b20bb GM |
2800 | /* Reliefs. */ |
2801 | f->output_data.x->white_relief.gc = 0; | |
2802 | f->output_data.x->black_relief.gc = 0; | |
2803 | ||
01f1ba30 | 2804 | /* Create the gray border tile used when the pointer is not in |
f676886a | 2805 | the frame. Since this depends on the frame's pixel values, |
9ef48a9d | 2806 | this must be done on a per-frame basis. */ |
7556890b | 2807 | f->output_data.x->border_tile |
d043f1a4 | 2808 | = (XCreatePixmapFromBitmapData |
177c0ea7 | 2809 | (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, |
d043f1a4 | 2810 | gray_bits, gray_width, gray_height, |
7556890b RS |
2811 | f->output_data.x->foreground_pixel, |
2812 | f->output_data.x->background_pixel, | |
ab452f99 | 2813 | DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)))); |
6afb1d07 JB |
2814 | |
2815 | UNBLOCK_INPUT; | |
01f1ba30 | 2816 | } |
01f1ba30 | 2817 | |
959e647d GM |
2818 | |
2819 | /* Free what was was allocated in x_make_gc. */ | |
2820 | ||
2821 | void | |
2822 | x_free_gcs (f) | |
2823 | struct frame *f; | |
2824 | { | |
2825 | Display *dpy = FRAME_X_DISPLAY (f); | |
2826 | ||
2827 | BLOCK_INPUT; | |
177c0ea7 | 2828 | |
959e647d GM |
2829 | if (f->output_data.x->normal_gc) |
2830 | { | |
2831 | XFreeGC (dpy, f->output_data.x->normal_gc); | |
2832 | f->output_data.x->normal_gc = 0; | |
2833 | } | |
2834 | ||
2835 | if (f->output_data.x->reverse_gc) | |
2836 | { | |
2837 | XFreeGC (dpy, f->output_data.x->reverse_gc); | |
2838 | f->output_data.x->reverse_gc = 0; | |
2839 | } | |
177c0ea7 | 2840 | |
959e647d GM |
2841 | if (f->output_data.x->cursor_gc) |
2842 | { | |
2843 | XFreeGC (dpy, f->output_data.x->cursor_gc); | |
2844 | f->output_data.x->cursor_gc = 0; | |
2845 | } | |
2846 | ||
2847 | if (f->output_data.x->border_tile) | |
2848 | { | |
2849 | XFreePixmap (dpy, f->output_data.x->border_tile); | |
2850 | f->output_data.x->border_tile = 0; | |
2851 | } | |
2852 | ||
2853 | UNBLOCK_INPUT; | |
2854 | } | |
2855 | ||
2856 | ||
eaf1eea9 GM |
2857 | /* Handler for signals raised during x_create_frame and |
2858 | x_create_top_frame. FRAME is the frame which is partially | |
2859 | constructed. */ | |
2860 | ||
2861 | static Lisp_Object | |
2862 | unwind_create_frame (frame) | |
2863 | Lisp_Object frame; | |
2864 | { | |
2865 | struct frame *f = XFRAME (frame); | |
2866 | ||
2867 | /* If frame is ``official'', nothing to do. */ | |
2868 | if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame)) | |
2869 | { | |
f1d2ce7f | 2870 | #if GLYPH_DEBUG |
eaf1eea9 GM |
2871 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
2872 | #endif | |
177c0ea7 | 2873 | |
eaf1eea9 GM |
2874 | x_free_frame_resources (f); |
2875 | ||
2876 | /* Check that reference counts are indeed correct. */ | |
2877 | xassert (dpyinfo->reference_count == dpyinfo_refcount); | |
2878 | xassert (dpyinfo->image_cache->refcount == image_cache_refcount); | |
c844a81a | 2879 | return Qt; |
eaf1eea9 | 2880 | } |
177c0ea7 | 2881 | |
eaf1eea9 GM |
2882 | return Qnil; |
2883 | } | |
2884 | ||
2885 | ||
f676886a | 2886 | DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, |
01f1ba30 | 2887 | 1, 1, 0, |
7ee72033 | 2888 | doc: /* Make a new X window, which is called a "frame" in Emacs terms. |
c061c855 GM |
2889 | Returns an Emacs frame object. |
2890 | ALIST is an alist of frame parameters. | |
2891 | If the parameters specify that the frame should not have a minibuffer, | |
2892 | and do not specify a specific minibuffer window to use, | |
2893 | then `default-minibuffer-frame' must be a frame whose minibuffer can | |
2894 | be shared by the new frame. | |
2895 | ||
7ee72033 MB |
2896 | This function is an internal primitive--use `make-frame' instead. */) |
2897 | (parms) | |
01f1ba30 JB |
2898 | Lisp_Object parms; |
2899 | { | |
f676886a | 2900 | struct frame *f; |
2365c027 | 2901 | Lisp_Object frame, tem; |
01f1ba30 JB |
2902 | Lisp_Object name; |
2903 | int minibuffer_only = 0; | |
2904 | long window_prompting = 0; | |
2905 | int width, height; | |
331379bf | 2906 | int count = SPECPDL_INDEX (); |
ecaca587 | 2907 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
b9dc4443 | 2908 | Lisp_Object display; |
333b20bb | 2909 | struct x_display_info *dpyinfo = NULL; |
a59e4f3d | 2910 | Lisp_Object parent; |
e557f19d | 2911 | struct kboard *kb; |
01f1ba30 | 2912 | |
b7975ee4 KH |
2913 | /* Use this general default value to start with |
2914 | until we know if this frame has a specified name. */ | |
2915 | Vx_resource_name = Vinvocation_name; | |
2916 | ||
b6660415 | 2917 | display = x_get_arg (dpyinfo, parms, Qdisplay_id, 0, 0, RES_TYPE_NUMBER); |
1705c933 | 2918 | if (EQ (display, Qunbound)) |
b6660415 | 2919 | display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING); |
b9dc4443 RS |
2920 | if (EQ (display, Qunbound)) |
2921 | display = Qnil; | |
2922 | dpyinfo = check_x_display_info (display); | |
e557f19d KH |
2923 | #ifdef MULTI_KBOARD |
2924 | kb = dpyinfo->kboard; | |
2925 | #else | |
2926 | kb = &the_only_kboard; | |
2927 | #endif | |
b9dc4443 | 2928 | |
333b20bb | 2929 | name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); |
6a5e54e2 | 2930 | if (!STRINGP (name) |
cf177271 JB |
2931 | && ! EQ (name, Qunbound) |
2932 | && ! NILP (name)) | |
08a90d6a | 2933 | error ("Invalid frame name--not a string or nil"); |
01f1ba30 | 2934 | |
b7975ee4 KH |
2935 | if (STRINGP (name)) |
2936 | Vx_resource_name = name; | |
2937 | ||
a59e4f3d | 2938 | /* See if parent window is specified. */ |
333b20bb | 2939 | parent = x_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER); |
a59e4f3d RS |
2940 | if (EQ (parent, Qunbound)) |
2941 | parent = Qnil; | |
2942 | if (! NILP (parent)) | |
b7826503 | 2943 | CHECK_NUMBER (parent); |
a59e4f3d | 2944 | |
ecaca587 RS |
2945 | /* make_frame_without_minibuffer can run Lisp code and garbage collect. */ |
2946 | /* No need to protect DISPLAY because that's not used after passing | |
2947 | it to make_frame_without_minibuffer. */ | |
2948 | frame = Qnil; | |
2949 | GCPRO4 (parms, parent, name, frame); | |
333b20bb GM |
2950 | tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer", |
2951 | RES_TYPE_SYMBOL); | |
f9942c9e | 2952 | if (EQ (tem, Qnone) || NILP (tem)) |
2526c290 | 2953 | f = make_frame_without_minibuffer (Qnil, kb, display); |
f9942c9e | 2954 | else if (EQ (tem, Qonly)) |
01f1ba30 | 2955 | { |
f676886a | 2956 | f = make_minibuffer_frame (); |
01f1ba30 JB |
2957 | minibuffer_only = 1; |
2958 | } | |
6a5e54e2 | 2959 | else if (WINDOWP (tem)) |
2526c290 | 2960 | f = make_frame_without_minibuffer (tem, kb, display); |
f9942c9e JB |
2961 | else |
2962 | f = make_frame (1); | |
01f1ba30 | 2963 | |
ecaca587 RS |
2964 | XSETFRAME (frame, f); |
2965 | ||
a3c87d4e JB |
2966 | /* Note that X Windows does support scroll bars. */ |
2967 | FRAME_CAN_HAVE_SCROLL_BARS (f) = 1; | |
179956b9 | 2968 | |
428a555e KL |
2969 | f->display = dpyinfo->frame_display; |
2970 | f->display->reference_count++; | |
2971 | ||
08a90d6a | 2972 | f->output_method = output_x_window; |
7556890b RS |
2973 | f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output)); |
2974 | bzero (f->output_data.x, sizeof (struct x_output)); | |
2975 | f->output_data.x->icon_bitmap = -1; | |
be786000 | 2976 | FRAME_FONTSET (f) = -1; |
333b20bb GM |
2977 | f->output_data.x->scroll_bar_foreground_pixel = -1; |
2978 | f->output_data.x->scroll_bar_background_pixel = -1; | |
f15340b7 MB |
2979 | #ifdef USE_TOOLKIT_SCROLL_BARS |
2980 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
2981 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
2982 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
eaf1eea9 | 2983 | record_unwind_protect (unwind_create_frame, frame); |
08a90d6a | 2984 | |
f468da95 | 2985 | f->icon_name |
333b20bb GM |
2986 | = x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title", |
2987 | RES_TYPE_STRING); | |
f468da95 RS |
2988 | if (! STRINGP (f->icon_name)) |
2989 | f->icon_name = Qnil; | |
80534dd6 | 2990 | |
08a90d6a | 2991 | FRAME_X_DISPLAY_INFO (f) = dpyinfo; |
f1d2ce7f | 2992 | #if GLYPH_DEBUG |
eaf1eea9 GM |
2993 | image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount; |
2994 | dpyinfo_refcount = dpyinfo->reference_count; | |
2995 | #endif /* GLYPH_DEBUG */ | |
73410c76 | 2996 | #ifdef MULTI_KBOARD |
e557f19d | 2997 | FRAME_KBOARD (f) = kb; |
73410c76 | 2998 | #endif |
08a90d6a | 2999 | |
9b2956e2 GM |
3000 | /* These colors will be set anyway later, but it's important |
3001 | to get the color reference counts right, so initialize them! */ | |
3002 | { | |
3003 | Lisp_Object black; | |
3004 | struct gcpro gcpro1; | |
cefecbcf GM |
3005 | |
3006 | /* Function x_decode_color can signal an error. Make | |
3007 | sure to initialize color slots so that we won't try | |
3008 | to free colors we haven't allocated. */ | |
3009 | f->output_data.x->foreground_pixel = -1; | |
3010 | f->output_data.x->background_pixel = -1; | |
3011 | f->output_data.x->cursor_pixel = -1; | |
3012 | f->output_data.x->cursor_foreground_pixel = -1; | |
3013 | f->output_data.x->border_pixel = -1; | |
3014 | f->output_data.x->mouse_pixel = -1; | |
177c0ea7 | 3015 | |
9b2956e2 GM |
3016 | black = build_string ("black"); |
3017 | GCPRO1 (black); | |
3018 | f->output_data.x->foreground_pixel | |
3019 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3020 | f->output_data.x->background_pixel | |
3021 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3022 | f->output_data.x->cursor_pixel | |
3023 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3024 | f->output_data.x->cursor_foreground_pixel | |
3025 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3026 | f->output_data.x->border_pixel | |
3027 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3028 | f->output_data.x->mouse_pixel | |
3029 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
3030 | UNGCPRO; | |
3031 | } | |
3032 | ||
a59e4f3d RS |
3033 | /* Specify the parent under which to make this X window. */ |
3034 | ||
3035 | if (!NILP (parent)) | |
3036 | { | |
8c239ac3 | 3037 | f->output_data.x->parent_desc = (Window) XFASTINT (parent); |
7556890b | 3038 | f->output_data.x->explicit_parent = 1; |
a59e4f3d RS |
3039 | } |
3040 | else | |
3041 | { | |
7556890b RS |
3042 | f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; |
3043 | f->output_data.x->explicit_parent = 0; | |
a59e4f3d RS |
3044 | } |
3045 | ||
cf177271 JB |
3046 | /* Set the name; the functions to which we pass f expect the name to |
3047 | be set. */ | |
3048 | if (EQ (name, Qunbound) || NILP (name)) | |
3049 | { | |
08a90d6a | 3050 | f->name = build_string (dpyinfo->x_id_name); |
cf177271 JB |
3051 | f->explicit_name = 0; |
3052 | } | |
3053 | else | |
3054 | { | |
3055 | f->name = name; | |
3056 | f->explicit_name = 1; | |
9ef48a9d RS |
3057 | /* use the frame's title when getting resources for this frame. */ |
3058 | specbind (Qx_resource_name, name); | |
cf177271 | 3059 | } |
01f1ba30 | 3060 | |
7f19e125 KL |
3061 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qx), Qnil)); |
3062 | ||
01f1ba30 JB |
3063 | /* Extract the window parameters from the supplied values |
3064 | that are needed to determine window geometry. */ | |
d387c960 JB |
3065 | { |
3066 | Lisp_Object font; | |
3067 | ||
333b20bb | 3068 | font = x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING); |
2ee3abaa | 3069 | |
6817eab4 | 3070 | BLOCK_INPUT; |
e5e548e3 RS |
3071 | /* First, try whatever font the caller has specified. */ |
3072 | if (STRINGP (font)) | |
942ea06d | 3073 | { |
49965a29 | 3074 | tem = Fquery_fontset (font, Qnil); |
477f8642 | 3075 | if (STRINGP (tem)) |
d5db4077 | 3076 | font = x_new_fontset (f, SDATA (tem)); |
942ea06d | 3077 | else |
d5db4077 | 3078 | font = x_new_font (f, SDATA (font)); |
942ea06d | 3079 | } |
177c0ea7 | 3080 | |
e5e548e3 | 3081 | /* Try out a font which we hope has bold and italic variations. */ |
333b20bb GM |
3082 | if (!STRINGP (font)) |
3083 | font = x_new_font (f, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1"); | |
e5e548e3 | 3084 | if (!STRINGP (font)) |
a6ac02af | 3085 | font = x_new_font (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1"); |
e5e548e3 | 3086 | if (! STRINGP (font)) |
a6ac02af | 3087 | font = x_new_font (f, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1"); |
e5e548e3 RS |
3088 | if (! STRINGP (font)) |
3089 | /* This was formerly the first thing tried, but it finds too many fonts | |
3090 | and takes too long. */ | |
3091 | font = x_new_font (f, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1"); | |
3092 | /* If those didn't work, look for something which will at least work. */ | |
3093 | if (! STRINGP (font)) | |
a6ac02af | 3094 | font = x_new_font (f, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1"); |
6817eab4 JB |
3095 | UNBLOCK_INPUT; |
3096 | if (! STRINGP (font)) | |
e5e548e3 RS |
3097 | font = build_string ("fixed"); |
3098 | ||
477f8642 | 3099 | x_default_parameter (f, parms, Qfont, font, |
333b20bb | 3100 | "font", "Font", RES_TYPE_STRING); |
d387c960 | 3101 | } |
9ef48a9d | 3102 | |
e3881aa0 | 3103 | #ifdef USE_LUCID |
82c90203 RS |
3104 | /* Prevent lwlib/xlwmenu.c from crashing because of a bug |
3105 | whereby it fails to get any font. */ | |
be786000 | 3106 | xlwmenu_default_font = FRAME_FONT (f); |
dd254b21 | 3107 | #endif |
82c90203 | 3108 | |
cf177271 | 3109 | x_default_parameter (f, parms, Qborder_width, make_number (2), |
333b20bb | 3110 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); |
177c0ea7 | 3111 | |
4e397688 | 3112 | /* This defaults to 1 in order to match xterm. We recognize either |
ddf768c3 JB |
3113 | internalBorderWidth or internalBorder (which is what xterm calls |
3114 | it). */ | |
3115 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
3116 | { | |
3117 | Lisp_Object value; | |
3118 | ||
abb4b7ec | 3119 | value = x_get_arg (dpyinfo, parms, Qinternal_border_width, |
333b20bb | 3120 | "internalBorder", "internalBorder", RES_TYPE_NUMBER); |
ddf768c3 JB |
3121 | if (! EQ (value, Qunbound)) |
3122 | parms = Fcons (Fcons (Qinternal_border_width, value), | |
3123 | parms); | |
3124 | } | |
dca97592 | 3125 | x_default_parameter (f, parms, Qinternal_border_width, make_number (1), |
333b20bb GM |
3126 | "internalBorderWidth", "internalBorderWidth", |
3127 | RES_TYPE_NUMBER); | |
1ab3d87e | 3128 | x_default_parameter (f, parms, Qvertical_scroll_bars, Qleft, |
333b20bb GM |
3129 | "verticalScrollBars", "ScrollBars", |
3130 | RES_TYPE_SYMBOL); | |
01f1ba30 | 3131 | |
b9dc4443 | 3132 | /* Also do the stuff which must be set before the window exists. */ |
cf177271 | 3133 | x_default_parameter (f, parms, Qforeground_color, build_string ("black"), |
333b20bb | 3134 | "foreground", "Foreground", RES_TYPE_STRING); |
cf177271 | 3135 | x_default_parameter (f, parms, Qbackground_color, build_string ("white"), |
0b60fc91 | 3136 | "background", "Background", RES_TYPE_STRING); |
cf177271 | 3137 | x_default_parameter (f, parms, Qmouse_color, build_string ("black"), |
333b20bb | 3138 | "pointerColor", "Foreground", RES_TYPE_STRING); |
cf177271 | 3139 | x_default_parameter (f, parms, Qcursor_color, build_string ("black"), |
333b20bb | 3140 | "cursorColor", "Foreground", RES_TYPE_STRING); |
cf177271 | 3141 | x_default_parameter (f, parms, Qborder_color, build_string ("black"), |
333b20bb | 3142 | "borderColor", "BorderColor", RES_TYPE_STRING); |
d62c8769 GM |
3143 | x_default_parameter (f, parms, Qscreen_gamma, Qnil, |
3144 | "screenGamma", "ScreenGamma", RES_TYPE_FLOAT); | |
563b67aa GM |
3145 | x_default_parameter (f, parms, Qline_spacing, Qnil, |
3146 | "lineSpacing", "LineSpacing", RES_TYPE_NUMBER); | |
b3ba0aa8 KS |
3147 | x_default_parameter (f, parms, Qleft_fringe, Qnil, |
3148 | "leftFringe", "LeftFringe", RES_TYPE_NUMBER); | |
3149 | x_default_parameter (f, parms, Qright_fringe, Qnil, | |
3150 | "rightFringe", "RightFringe", RES_TYPE_NUMBER); | |
333b20bb GM |
3151 | |
3152 | x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground, | |
3153 | "scrollBarForeground", | |
3154 | "ScrollBarForeground", 1); | |
3155 | x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background, | |
3156 | "scrollBarBackground", | |
3157 | "ScrollBarBackground", 0); | |
3158 | ||
3159 | /* Init faces before x_default_parameter is called for scroll-bar | |
3160 | parameters because that function calls x_set_scroll_bar_width, | |
3161 | which calls change_frame_size, which calls Fset_window_buffer, | |
3162 | which runs hooks, which call Fvertical_motion. At the end, we | |
3163 | end up in init_iterator with a null face cache, which should not | |
3164 | happen. */ | |
3165 | init_frame_faces (f); | |
177c0ea7 | 3166 | |
c7bcb20d | 3167 | x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1), |
333b20bb | 3168 | "menuBar", "MenuBar", RES_TYPE_NUMBER); |
e33455ca | 3169 | x_default_parameter (f, parms, Qtool_bar_lines, make_number (1), |
333b20bb | 3170 | "toolBar", "ToolBar", RES_TYPE_NUMBER); |
79873d50 | 3171 | x_default_parameter (f, parms, Qbuffer_predicate, Qnil, |
333b20bb GM |
3172 | "bufferPredicate", "BufferPredicate", |
3173 | RES_TYPE_SYMBOL); | |
c2304e02 | 3174 | x_default_parameter (f, parms, Qtitle, Qnil, |
333b20bb | 3175 | "title", "Title", RES_TYPE_STRING); |
ea0a1f53 GM |
3176 | x_default_parameter (f, parms, Qwait_for_wm, Qt, |
3177 | "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN); | |
49d41073 EZ |
3178 | x_default_parameter (f, parms, Qfullscreen, Qnil, |
3179 | "fullscreen", "Fullscreen", RES_TYPE_SYMBOL); | |
90eb1019 | 3180 | |
7556890b | 3181 | f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; |
35f59f6b | 3182 | |
35f59f6b | 3183 | /* Compute the size of the X window. */ |
7c0d3ed8 | 3184 | window_prompting = x_figure_window_size (f, parms, 1); |
38d22040 | 3185 | |
495fa05e GM |
3186 | tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); |
3187 | f->no_split = minibuffer_only || EQ (tem, Qt); | |
3188 | ||
289978b5 LT |
3189 | x_icon_verify (f, parms); |
3190 | ||
6a1bcd01 | 3191 | /* Create the X widget or window. */ |
a7f7d550 FP |
3192 | #ifdef USE_X_TOOLKIT |
3193 | x_window (f, window_prompting, minibuffer_only); | |
3194 | #else | |
f676886a | 3195 | x_window (f); |
a7f7d550 | 3196 | #endif |
177c0ea7 | 3197 | |
f676886a JB |
3198 | x_icon (f, parms); |
3199 | x_make_gc (f); | |
01f1ba30 | 3200 | |
495fa05e GM |
3201 | /* Now consider the frame official. */ |
3202 | FRAME_X_DISPLAY_INFO (f)->reference_count++; | |
3203 | Vframe_list = Fcons (frame, Vframe_list); | |
3204 | ||
f9942c9e JB |
3205 | /* We need to do this after creating the X window, so that the |
3206 | icon-creation functions can say whose icon they're describing. */ | |
cf177271 | 3207 | x_default_parameter (f, parms, Qicon_type, Qnil, |
333b20bb | 3208 | "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL); |
f9942c9e | 3209 | |
cf177271 | 3210 | x_default_parameter (f, parms, Qauto_raise, Qnil, |
333b20bb | 3211 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
cf177271 | 3212 | x_default_parameter (f, parms, Qauto_lower, Qnil, |
333b20bb | 3213 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
dbc4e1c1 | 3214 | x_default_parameter (f, parms, Qcursor_type, Qbox, |
333b20bb | 3215 | "cursorType", "CursorType", RES_TYPE_SYMBOL); |
28d7281d GM |
3216 | x_default_parameter (f, parms, Qscroll_bar_width, Qnil, |
3217 | "scrollBarWidth", "ScrollBarWidth", | |
3218 | RES_TYPE_NUMBER); | |
f9942c9e | 3219 | |
be786000 | 3220 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
01f1ba30 | 3221 | Change will not be effected unless different from the current |
be786000 KS |
3222 | FRAME_LINES (f). */ |
3223 | width = FRAME_COLS (f); | |
3224 | height = FRAME_LINES (f); | |
177c0ea7 | 3225 | |
be786000 KS |
3226 | SET_FRAME_COLS (f, 0); |
3227 | FRAME_LINES (f) = 0; | |
8938a4fb | 3228 | change_frame_size (f, height, width, 1, 0, 0); |
d043f1a4 | 3229 | |
488dd4c4 | 3230 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
495fa05e GM |
3231 | /* Create the menu bar. */ |
3232 | if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f)) | |
3233 | { | |
3234 | /* If this signals an error, we haven't set size hints for the | |
3235 | frame and we didn't make it visible. */ | |
3236 | initialize_frame_menubar (f); | |
3237 | ||
488dd4c4 | 3238 | #ifndef USE_GTK |
495fa05e GM |
3239 | /* This is a no-op, except under Motif where it arranges the |
3240 | main window for the widgets on it. */ | |
3241 | lw_set_main_areas (f->output_data.x->column_widget, | |
3242 | f->output_data.x->menubar_widget, | |
3243 | f->output_data.x->edit_widget); | |
488dd4c4 | 3244 | #endif /* not USE_GTK */ |
495fa05e | 3245 | } |
488dd4c4 | 3246 | #endif /* USE_X_TOOLKIT || USE_GTK */ |
495fa05e GM |
3247 | |
3248 | /* Tell the server what size and position, etc, we want, and how | |
3249 | badly we want them. This should be done after we have the menu | |
3250 | bar so that its size can be taken into account. */ | |
01f1ba30 | 3251 | BLOCK_INPUT; |
7989f084 | 3252 | x_wm_set_size_hint (f, window_prompting, 0); |
01f1ba30 JB |
3253 | UNBLOCK_INPUT; |
3254 | ||
495fa05e GM |
3255 | /* Make the window appear on the frame and enable display, unless |
3256 | the caller says not to. However, with explicit parent, Emacs | |
3257 | cannot control visibility, so don't try. */ | |
7556890b | 3258 | if (! f->output_data.x->explicit_parent) |
a59e4f3d RS |
3259 | { |
3260 | Lisp_Object visibility; | |
49795535 | 3261 | |
333b20bb GM |
3262 | visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, |
3263 | RES_TYPE_SYMBOL); | |
a59e4f3d RS |
3264 | if (EQ (visibility, Qunbound)) |
3265 | visibility = Qt; | |
49795535 | 3266 | |
a59e4f3d RS |
3267 | if (EQ (visibility, Qicon)) |
3268 | x_iconify_frame (f); | |
3269 | else if (! NILP (visibility)) | |
3270 | x_make_frame_visible (f); | |
3271 | else | |
3272 | /* Must have been Qnil. */ | |
3273 | ; | |
3274 | } | |
01f1ba30 | 3275 | |
231d6cfb JD |
3276 | /* Set the WM leader property. GTK does this itself, so this is not |
3277 | needed when using GTK. */ | |
3278 | if (dpyinfo->client_leader_window != 0) | |
3279 | { | |
3280 | BLOCK_INPUT; | |
3281 | XChangeProperty (FRAME_X_DISPLAY (f), | |
3282 | FRAME_OUTER_WINDOW (f), | |
3283 | dpyinfo->Xatom_wm_client_leader, | |
3284 | XA_WINDOW, 32, PropModeReplace, | |
3285 | (char *) &dpyinfo->client_leader_window, 1); | |
3286 | UNBLOCK_INPUT; | |
3287 | } | |
3288 | ||
495fa05e | 3289 | UNGCPRO; |
9e57df62 GM |
3290 | |
3291 | /* Make sure windows on this frame appear in calls to next-window | |
3292 | and similar functions. */ | |
3293 | Vwindow_list = Qnil; | |
177c0ea7 | 3294 | |
9ef48a9d | 3295 | return unbind_to (count, frame); |
01f1ba30 JB |
3296 | } |
3297 | ||
eaf1eea9 | 3298 | |
0d17d282 KH |
3299 | /* FRAME is used only to get a handle on the X display. We don't pass the |
3300 | display info directly because we're called from frame.c, which doesn't | |
3301 | know about that structure. */ | |
e4f79258 | 3302 | |
87498171 | 3303 | Lisp_Object |
0d17d282 KH |
3304 | x_get_focus_frame (frame) |
3305 | struct frame *frame; | |
87498171 | 3306 | { |
0d17d282 | 3307 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (frame); |
87498171 | 3308 | Lisp_Object xfocus; |
0d17d282 | 3309 | if (! dpyinfo->x_focus_frame) |
87498171 KH |
3310 | return Qnil; |
3311 | ||
0d17d282 | 3312 | XSETFRAME (xfocus, dpyinfo->x_focus_frame); |
87498171 KH |
3313 | return xfocus; |
3314 | } | |
f0614854 | 3315 | |
3decc1e7 GM |
3316 | |
3317 | /* In certain situations, when the window manager follows a | |
3318 | click-to-focus policy, there seems to be no way around calling | |
3319 | XSetInputFocus to give another frame the input focus . | |
3320 | ||
3321 | In an ideal world, XSetInputFocus should generally be avoided so | |
3322 | that applications don't interfere with the window manager's focus | |
3323 | policy. But I think it's okay to use when it's clearly done | |
3324 | following a user-command. */ | |
3325 | ||
3326 | DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0, | |
7ee72033 MB |
3327 | doc: /* Set the input focus to FRAME. |
3328 | FRAME nil means use the selected frame. */) | |
3329 | (frame) | |
3decc1e7 GM |
3330 | Lisp_Object frame; |
3331 | { | |
3332 | struct frame *f = check_x_frame (frame); | |
3333 | Display *dpy = FRAME_X_DISPLAY (f); | |
3334 | int count; | |
3335 | ||
3336 | BLOCK_INPUT; | |
3337 | count = x_catch_errors (dpy); | |
3338 | XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
3339 | RevertToParent, CurrentTime); | |
3340 | x_uncatch_errors (dpy, count); | |
3341 | UNBLOCK_INPUT; | |
177c0ea7 | 3342 | |
3decc1e7 GM |
3343 | return Qnil; |
3344 | } | |
3345 | ||
f0614854 | 3346 | \f |
2d764c78 | 3347 | DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, |
7ee72033 MB |
3348 | doc: /* Internal function called by `color-defined-p', which see. */) |
3349 | (color, frame) | |
b9dc4443 | 3350 | Lisp_Object color, frame; |
e12d55b2 | 3351 | { |
b9dc4443 RS |
3352 | XColor foo; |
3353 | FRAME_PTR f = check_x_frame (frame); | |
e12d55b2 | 3354 | |
b7826503 | 3355 | CHECK_STRING (color); |
b9dc4443 | 3356 | |
d5db4077 | 3357 | if (x_defined_color (f, SDATA (color), &foo, 0)) |
e12d55b2 RS |
3358 | return Qt; |
3359 | else | |
3360 | return Qnil; | |
3361 | } | |
3362 | ||
2d764c78 | 3363 | DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0, |
7ee72033 MB |
3364 | doc: /* Internal function called by `color-values', which see. */) |
3365 | (color, frame) | |
b9dc4443 | 3366 | Lisp_Object color, frame; |
01f1ba30 | 3367 | { |
b9dc4443 RS |
3368 | XColor foo; |
3369 | FRAME_PTR f = check_x_frame (frame); | |
3370 | ||
b7826503 | 3371 | CHECK_STRING (color); |
01f1ba30 | 3372 | |
d5db4077 | 3373 | if (x_defined_color (f, SDATA (color), &foo, 0)) |
57c82a63 RS |
3374 | { |
3375 | Lisp_Object rgb[3]; | |
3376 | ||
3377 | rgb[0] = make_number (foo.red); | |
3378 | rgb[1] = make_number (foo.green); | |
3379 | rgb[2] = make_number (foo.blue); | |
3380 | return Flist (3, rgb); | |
3381 | } | |
01f1ba30 JB |
3382 | else |
3383 | return Qnil; | |
3384 | } | |
3385 | ||
2d764c78 | 3386 | DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, |
7ee72033 MB |
3387 | doc: /* Internal function called by `display-color-p', which see. */) |
3388 | (display) | |
08a90d6a | 3389 | Lisp_Object display; |
01f1ba30 | 3390 | { |
08a90d6a | 3391 | struct x_display_info *dpyinfo = check_x_display_info (display); |
11ae94fe | 3392 | |
b9dc4443 | 3393 | if (dpyinfo->n_planes <= 2) |
01f1ba30 JB |
3394 | return Qnil; |
3395 | ||
b9dc4443 | 3396 | switch (dpyinfo->visual->class) |
01f1ba30 JB |
3397 | { |
3398 | case StaticColor: | |
3399 | case PseudoColor: | |
3400 | case TrueColor: | |
3401 | case DirectColor: | |
3402 | return Qt; | |
3403 | ||
3404 | default: | |
3405 | return Qnil; | |
3406 | } | |
3407 | } | |
3408 | ||
d0c9d219 | 3409 | DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p, |
c061c855 | 3410 | 0, 1, 0, |
7ee72033 | 3411 | doc: /* Return t if the X display supports shades of gray. |
c061c855 GM |
3412 | Note that color displays do support shades of gray. |
3413 | The optional argument DISPLAY specifies which display to ask about. | |
3414 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3415 | If omitted or nil, that stands for the selected frame's display. */) |
3416 | (display) | |
08a90d6a | 3417 | Lisp_Object display; |
d0c9d219 | 3418 | { |
08a90d6a | 3419 | struct x_display_info *dpyinfo = check_x_display_info (display); |
d0c9d219 | 3420 | |
ae6b58f9 | 3421 | if (dpyinfo->n_planes <= 1) |
b9dc4443 RS |
3422 | return Qnil; |
3423 | ||
ae6b58f9 RS |
3424 | switch (dpyinfo->visual->class) |
3425 | { | |
3426 | case StaticColor: | |
3427 | case PseudoColor: | |
3428 | case TrueColor: | |
3429 | case DirectColor: | |
3430 | case StaticGray: | |
3431 | case GrayScale: | |
3432 | return Qt; | |
3433 | ||
3434 | default: | |
3435 | return Qnil; | |
3436 | } | |
d0c9d219 RS |
3437 | } |
3438 | ||
41beb8fc | 3439 | DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, |
c061c855 | 3440 | 0, 1, 0, |
7ee72033 | 3441 | doc: /* Returns the width in pixels of the X display DISPLAY. |
c061c855 GM |
3442 | The optional argument DISPLAY specifies which display to ask about. |
3443 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3444 | If omitted or nil, that stands for the selected frame's display. */) |
3445 | (display) | |
08a90d6a | 3446 | Lisp_Object display; |
41beb8fc | 3447 | { |
08a90d6a | 3448 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 RS |
3449 | |
3450 | return make_number (dpyinfo->width); | |
41beb8fc RS |
3451 | } |
3452 | ||
3453 | DEFUN ("x-display-pixel-height", Fx_display_pixel_height, | |
c061c855 | 3454 | Sx_display_pixel_height, 0, 1, 0, |
7ee72033 | 3455 | doc: /* Returns the height in pixels of the X display DISPLAY. |
c061c855 GM |
3456 | The optional argument DISPLAY specifies which display to ask about. |
3457 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3458 | If omitted or nil, that stands for the selected frame's display. */) |
3459 | (display) | |
08a90d6a | 3460 | Lisp_Object display; |
41beb8fc | 3461 | { |
08a90d6a | 3462 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 RS |
3463 | |
3464 | return make_number (dpyinfo->height); | |
41beb8fc RS |
3465 | } |
3466 | ||
3467 | DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, | |
c061c855 | 3468 | 0, 1, 0, |
7ee72033 | 3469 | doc: /* Returns the number of bitplanes of the X display DISPLAY. |
c061c855 GM |
3470 | The optional argument DISPLAY specifies which display to ask about. |
3471 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3472 | If omitted or nil, that stands for the selected frame's display. */) |
3473 | (display) | |
08a90d6a | 3474 | Lisp_Object display; |
41beb8fc | 3475 | { |
08a90d6a | 3476 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 RS |
3477 | |
3478 | return make_number (dpyinfo->n_planes); | |
41beb8fc RS |
3479 | } |
3480 | ||
3481 | DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells, | |
c061c855 | 3482 | 0, 1, 0, |
7ee72033 | 3483 | doc: /* Returns the number of color cells of the X display DISPLAY. |
c061c855 GM |
3484 | The optional argument DISPLAY specifies which display to ask about. |
3485 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3486 | If omitted or nil, that stands for the selected frame's display. */) |
3487 | (display) | |
08a90d6a | 3488 | Lisp_Object display; |
41beb8fc | 3489 | { |
08a90d6a | 3490 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 | 3491 | |
334faa08 JD |
3492 | int nr_planes = DisplayPlanes (dpyinfo->display, |
3493 | XScreenNumberOfScreen (dpyinfo->screen)); | |
3494 | ||
3495 | /* Truncate nr_planes to 24 to avoid integer overflow. | |
3496 | Some displays says 32, but only 24 bits are actually significant. | |
3497 | There are only very few and rare video cards that have more than | |
3498 | 24 significant bits. Also 24 bits is more than 16 million colors, | |
3499 | it "should be enough for everyone". */ | |
3500 | if (nr_planes > 24) nr_planes = 24; | |
3501 | ||
3502 | return make_number (1 << nr_planes); | |
41beb8fc RS |
3503 | } |
3504 | ||
9d317b2c RS |
3505 | DEFUN ("x-server-max-request-size", Fx_server_max_request_size, |
3506 | Sx_server_max_request_size, | |
c061c855 | 3507 | 0, 1, 0, |
7ee72033 | 3508 | doc: /* Returns the maximum request size of the X server of display DISPLAY. |
c061c855 GM |
3509 | The optional argument DISPLAY specifies which display to ask about. |
3510 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3511 | If omitted or nil, that stands for the selected frame's display. */) |
3512 | (display) | |
08a90d6a | 3513 | Lisp_Object display; |
9d317b2c | 3514 | { |
08a90d6a | 3515 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 RS |
3516 | |
3517 | return make_number (MAXREQUEST (dpyinfo->display)); | |
9d317b2c RS |
3518 | } |
3519 | ||
41beb8fc | 3520 | DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0, |
95d62d8a RS |
3521 | doc: /* Returns the "vendor ID" string of the X server of display DISPLAY. |
3522 | \(Labelling every distributor as a "vendor" embodies the false assumption | |
3523 | that operating systems cannot be developed and distributed noncommercially.) | |
c061c855 GM |
3524 | The optional argument DISPLAY specifies which display to ask about. |
3525 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3526 | If omitted or nil, that stands for the selected frame's display. */) |
3527 | (display) | |
08a90d6a | 3528 | Lisp_Object display; |
41beb8fc | 3529 | { |
08a90d6a | 3530 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 RS |
3531 | char *vendor = ServerVendor (dpyinfo->display); |
3532 | ||
41beb8fc RS |
3533 | if (! vendor) vendor = ""; |
3534 | return build_string (vendor); | |
3535 | } | |
3536 | ||
3537 | DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0, | |
7ee72033 | 3538 | doc: /* Returns the version numbers of the X server of display DISPLAY. |
c061c855 | 3539 | The value is a list of three integers: the major and minor |
95d62d8a | 3540 | version numbers of the X Protocol in use, and the distributor-specific release |
c061c855 GM |
3541 | number. See also the function `x-server-vendor'. |
3542 | ||
3543 | The optional argument DISPLAY specifies which display to ask about. | |
3544 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3545 | If omitted or nil, that stands for the selected frame's display. */) |
3546 | (display) | |
08a90d6a | 3547 | Lisp_Object display; |
41beb8fc | 3548 | { |
08a90d6a | 3549 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 | 3550 | Display *dpy = dpyinfo->display; |
11ae94fe | 3551 | |
41beb8fc RS |
3552 | return Fcons (make_number (ProtocolVersion (dpy)), |
3553 | Fcons (make_number (ProtocolRevision (dpy)), | |
3554 | Fcons (make_number (VendorRelease (dpy)), Qnil))); | |
3555 | } | |
3556 | ||
3557 | DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0, | |
7ee72033 | 3558 | doc: /* Return the number of screens on the X server of display DISPLAY. |
c061c855 GM |
3559 | The optional argument DISPLAY specifies which display to ask about. |
3560 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3561 | If omitted or nil, that stands for the selected frame's display. */) |
3562 | (display) | |
08a90d6a | 3563 | Lisp_Object display; |
41beb8fc | 3564 | { |
08a90d6a | 3565 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 RS |
3566 | |
3567 | return make_number (ScreenCount (dpyinfo->display)); | |
41beb8fc RS |
3568 | } |
3569 | ||
3570 | DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0, | |
7ee72033 | 3571 | doc: /* Return the height in millimeters of the X display DISPLAY. |
c061c855 GM |
3572 | The optional argument DISPLAY specifies which display to ask about. |
3573 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3574 | If omitted or nil, that stands for the selected frame's display. */) |
3575 | (display) | |
08a90d6a | 3576 | Lisp_Object display; |
41beb8fc | 3577 | { |
08a90d6a | 3578 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 RS |
3579 | |
3580 | return make_number (HeightMMOfScreen (dpyinfo->screen)); | |
41beb8fc RS |
3581 | } |
3582 | ||
3583 | DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, | |
7ee72033 | 3584 | doc: /* Return the width in millimeters of the X display DISPLAY. |
c061c855 GM |
3585 | The optional argument DISPLAY specifies which display to ask about. |
3586 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3587 | If omitted or nil, that stands for the selected frame's display. */) |
3588 | (display) | |
08a90d6a | 3589 | Lisp_Object display; |
41beb8fc | 3590 | { |
08a90d6a | 3591 | struct x_display_info *dpyinfo = check_x_display_info (display); |
b9dc4443 RS |
3592 | |
3593 | return make_number (WidthMMOfScreen (dpyinfo->screen)); | |
41beb8fc RS |
3594 | } |
3595 | ||
3596 | DEFUN ("x-display-backing-store", Fx_display_backing_store, | |
c061c855 | 3597 | Sx_display_backing_store, 0, 1, 0, |
7ee72033 | 3598 | doc: /* Returns an indication of whether X display DISPLAY does backing store. |
c061c855 GM |
3599 | The value may be `always', `when-mapped', or `not-useful'. |
3600 | The optional argument DISPLAY specifies which display to ask about. | |
3601 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3602 | If omitted or nil, that stands for the selected frame's display. */) |
3603 | (display) | |
08a90d6a | 3604 | Lisp_Object display; |
41beb8fc | 3605 | { |
08a90d6a | 3606 | struct x_display_info *dpyinfo = check_x_display_info (display); |
8ec8a5ec | 3607 | Lisp_Object result; |
11ae94fe | 3608 | |
b9dc4443 | 3609 | switch (DoesBackingStore (dpyinfo->screen)) |
41beb8fc RS |
3610 | { |
3611 | case Always: | |
8ec8a5ec GM |
3612 | result = intern ("always"); |
3613 | break; | |
41beb8fc RS |
3614 | |
3615 | case WhenMapped: | |
8ec8a5ec GM |
3616 | result = intern ("when-mapped"); |
3617 | break; | |
41beb8fc RS |
3618 | |
3619 | case NotUseful: | |
8ec8a5ec GM |
3620 | result = intern ("not-useful"); |
3621 | break; | |
41beb8fc RS |
3622 | |
3623 | default: | |
3624 | error ("Strange value for BackingStore parameter of screen"); | |
8ec8a5ec | 3625 | result = Qnil; |
41beb8fc | 3626 | } |
8ec8a5ec GM |
3627 | |
3628 | return result; | |
41beb8fc RS |
3629 | } |
3630 | ||
3631 | DEFUN ("x-display-visual-class", Fx_display_visual_class, | |
c061c855 | 3632 | Sx_display_visual_class, 0, 1, 0, |
7ee72033 | 3633 | doc: /* Return the visual class of the X display DISPLAY. |
c061c855 GM |
3634 | The value is one of the symbols `static-gray', `gray-scale', |
3635 | `static-color', `pseudo-color', `true-color', or `direct-color'. | |
3636 | ||
3637 | The optional argument DISPLAY specifies which display to ask about. | |
3638 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3639 | If omitted or nil, that stands for the selected frame's display. */) |
3640 | (display) | |
08a90d6a | 3641 | Lisp_Object display; |
41beb8fc | 3642 | { |
08a90d6a | 3643 | struct x_display_info *dpyinfo = check_x_display_info (display); |
8ec8a5ec | 3644 | Lisp_Object result; |
11ae94fe | 3645 | |
b9dc4443 | 3646 | switch (dpyinfo->visual->class) |
41beb8fc | 3647 | { |
8ec8a5ec GM |
3648 | case StaticGray: |
3649 | result = intern ("static-gray"); | |
3650 | break; | |
3651 | case GrayScale: | |
3652 | result = intern ("gray-scale"); | |
3653 | break; | |
3654 | case StaticColor: | |
3655 | result = intern ("static-color"); | |
3656 | break; | |
3657 | case PseudoColor: | |
3658 | result = intern ("pseudo-color"); | |
3659 | break; | |
3660 | case TrueColor: | |
3661 | result = intern ("true-color"); | |
3662 | break; | |
3663 | case DirectColor: | |
3664 | result = intern ("direct-color"); | |
3665 | break; | |
41beb8fc RS |
3666 | default: |
3667 | error ("Display has an unknown visual class"); | |
8ec8a5ec | 3668 | result = Qnil; |
41beb8fc | 3669 | } |
177c0ea7 | 3670 | |
8ec8a5ec | 3671 | return result; |
41beb8fc RS |
3672 | } |
3673 | ||
3674 | DEFUN ("x-display-save-under", Fx_display_save_under, | |
c061c855 | 3675 | Sx_display_save_under, 0, 1, 0, |
7ee72033 | 3676 | doc: /* Returns t if the X display DISPLAY supports the save-under feature. |
c061c855 GM |
3677 | The optional argument DISPLAY specifies which display to ask about. |
3678 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
3679 | If omitted or nil, that stands for the selected frame's display. */) |
3680 | (display) | |
08a90d6a | 3681 | Lisp_Object display; |
41beb8fc | 3682 | { |
08a90d6a | 3683 | struct x_display_info *dpyinfo = check_x_display_info (display); |
11ae94fe | 3684 | |
b9dc4443 | 3685 | if (DoesSaveUnders (dpyinfo->screen) == True) |
41beb8fc RS |
3686 | return Qt; |
3687 | else | |
3688 | return Qnil; | |
3689 | } | |
3690 | \f | |
b9dc4443 | 3691 | int |
55caf99c RS |
3692 | x_pixel_width (f) |
3693 | register struct frame *f; | |
01f1ba30 | 3694 | { |
be786000 | 3695 | return FRAME_PIXEL_WIDTH (f); |
01f1ba30 JB |
3696 | } |
3697 | ||
b9dc4443 | 3698 | int |
55caf99c RS |
3699 | x_pixel_height (f) |
3700 | register struct frame *f; | |
01f1ba30 | 3701 | { |
be786000 | 3702 | return FRAME_PIXEL_HEIGHT (f); |
55caf99c RS |
3703 | } |
3704 | ||
b9dc4443 | 3705 | int |
55caf99c RS |
3706 | x_char_width (f) |
3707 | register struct frame *f; | |
3708 | { | |
be786000 | 3709 | return FRAME_COLUMN_WIDTH (f); |
55caf99c RS |
3710 | } |
3711 | ||
b9dc4443 | 3712 | int |
55caf99c RS |
3713 | x_char_height (f) |
3714 | register struct frame *f; | |
3715 | { | |
be786000 | 3716 | return FRAME_LINE_HEIGHT (f); |
01f1ba30 | 3717 | } |
b9dc4443 RS |
3718 | |
3719 | int | |
f03f2489 RS |
3720 | x_screen_planes (f) |
3721 | register struct frame *f; | |
b9dc4443 | 3722 | { |
f03f2489 | 3723 | return FRAME_X_DISPLAY_INFO (f)->n_planes; |
b9dc4443 | 3724 | } |
01f1ba30 | 3725 | |
a6ad00c0 GM |
3726 | |
3727 | \f | |
3728 | /************************************************************************ | |
3729 | X Displays | |
3730 | ************************************************************************/ | |
3731 | ||
01f1ba30 | 3732 | \f |
a6ad00c0 GM |
3733 | /* Mapping visual names to visuals. */ |
3734 | ||
3735 | static struct visual_class | |
3736 | { | |
3737 | char *name; | |
3738 | int class; | |
3739 | } | |
3740 | visual_classes[] = | |
3741 | { | |
3742 | {"StaticGray", StaticGray}, | |
3743 | {"GrayScale", GrayScale}, | |
3744 | {"StaticColor", StaticColor}, | |
3745 | {"PseudoColor", PseudoColor}, | |
3746 | {"TrueColor", TrueColor}, | |
3747 | {"DirectColor", DirectColor}, | |
9908a324 | 3748 | {NULL, 0} |
a6ad00c0 GM |
3749 | }; |
3750 | ||
3751 | ||
404daac1 | 3752 | #ifndef HAVE_XSCREENNUMBEROFSCREEN |
a6ad00c0 GM |
3753 | |
3754 | /* Value is the screen number of screen SCR. This is a substitute for | |
3755 | the X function with the same name when that doesn't exist. */ | |
3756 | ||
404daac1 RS |
3757 | int |
3758 | XScreenNumberOfScreen (scr) | |
3759 | register Screen *scr; | |
3760 | { | |
a6ad00c0 GM |
3761 | Display *dpy = scr->display; |
3762 | int i; | |
3df34fdb | 3763 | |
a6ad00c0 | 3764 | for (i = 0; i < dpy->nscreens; ++i) |
fbd5ceb2 | 3765 | if (scr == dpy->screens + i) |
a6ad00c0 | 3766 | break; |
404daac1 | 3767 | |
a6ad00c0 | 3768 | return i; |
404daac1 | 3769 | } |
a6ad00c0 | 3770 | |
404daac1 RS |
3771 | #endif /* not HAVE_XSCREENNUMBEROFSCREEN */ |
3772 | ||
01f1ba30 | 3773 | |
a6ad00c0 GM |
3774 | /* Select the visual that should be used on display DPYINFO. Set |
3775 | members of DPYINFO appropriately. Called from x_term_init. */ | |
fe24a618 | 3776 | |
a6ad00c0 GM |
3777 | void |
3778 | select_visual (dpyinfo) | |
3779 | struct x_display_info *dpyinfo; | |
3780 | { | |
3781 | Display *dpy = dpyinfo->display; | |
3782 | Screen *screen = dpyinfo->screen; | |
3783 | Lisp_Object value; | |
fe24a618 | 3784 | |
a6ad00c0 GM |
3785 | /* See if a visual is specified. */ |
3786 | value = display_x_get_resource (dpyinfo, | |
3787 | build_string ("visualClass"), | |
3788 | build_string ("VisualClass"), | |
3789 | Qnil, Qnil); | |
3790 | if (STRINGP (value)) | |
3791 | { | |
3792 | /* VALUE should be of the form CLASS-DEPTH, where CLASS is one | |
3793 | of `PseudoColor', `TrueColor' etc. and DEPTH is the color | |
3794 | depth, a decimal number. NAME is compared with case ignored. */ | |
d5db4077 | 3795 | char *s = (char *) alloca (SBYTES (value) + 1); |
a6ad00c0 GM |
3796 | char *dash; |
3797 | int i, class = -1; | |
3798 | XVisualInfo vinfo; | |
3799 | ||
d5db4077 | 3800 | strcpy (s, SDATA (value)); |
a6ad00c0 GM |
3801 | dash = index (s, '-'); |
3802 | if (dash) | |
3803 | { | |
3804 | dpyinfo->n_planes = atoi (dash + 1); | |
3805 | *dash = '\0'; | |
3806 | } | |
3807 | else | |
3808 | /* We won't find a matching visual with depth 0, so that | |
3809 | an error will be printed below. */ | |
3810 | dpyinfo->n_planes = 0; | |
f0614854 | 3811 | |
a6ad00c0 GM |
3812 | /* Determine the visual class. */ |
3813 | for (i = 0; visual_classes[i].name; ++i) | |
3814 | if (xstricmp (s, visual_classes[i].name) == 0) | |
3815 | { | |
3816 | class = visual_classes[i].class; | |
3817 | break; | |
3818 | } | |
01f1ba30 | 3819 | |
a6ad00c0 GM |
3820 | /* Look up a matching visual for the specified class. */ |
3821 | if (class == -1 | |
3822 | || !XMatchVisualInfo (dpy, XScreenNumberOfScreen (screen), | |
3823 | dpyinfo->n_planes, class, &vinfo)) | |
d5db4077 | 3824 | fatal ("Invalid visual specification `%s'", SDATA (value)); |
177c0ea7 | 3825 | |
a6ad00c0 GM |
3826 | dpyinfo->visual = vinfo.visual; |
3827 | } | |
01f1ba30 JB |
3828 | else |
3829 | { | |
a6ad00c0 GM |
3830 | int n_visuals; |
3831 | XVisualInfo *vinfo, vinfo_template; | |
177c0ea7 | 3832 | |
a6ad00c0 GM |
3833 | dpyinfo->visual = DefaultVisualOfScreen (screen); |
3834 | ||
3835 | #ifdef HAVE_X11R4 | |
3836 | vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual); | |
3837 | #else | |
3838 | vinfo_template.visualid = dpyinfo->visual->visualid; | |
3839 | #endif | |
3840 | vinfo_template.screen = XScreenNumberOfScreen (screen); | |
3841 | vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask, | |
3842 | &vinfo_template, &n_visuals); | |
3843 | if (n_visuals != 1) | |
3844 | fatal ("Can't get proper X visual info"); | |
3845 | ||
94ac875b | 3846 | dpyinfo->n_planes = vinfo->depth; |
a6ad00c0 GM |
3847 | XFree ((char *) vinfo); |
3848 | } | |
01f1ba30 | 3849 | } |
01f1ba30 | 3850 | |
a6ad00c0 | 3851 | |
b9dc4443 RS |
3852 | /* Return the X display structure for the display named NAME. |
3853 | Open a new connection if necessary. */ | |
3854 | ||
3855 | struct x_display_info * | |
3856 | x_display_info_for_name (name) | |
3857 | Lisp_Object name; | |
3858 | { | |
08a90d6a | 3859 | Lisp_Object names; |
b9dc4443 RS |
3860 | struct x_display_info *dpyinfo; |
3861 | ||
b7826503 | 3862 | CHECK_STRING (name); |
b9dc4443 | 3863 | |
2246281f KL |
3864 | #if 0 |
3865 | if (! EQ (Vinitial_window_system, intern ("x"))) | |
3866 | error ("Not using X Windows"); /* That doesn't stop us anymore. */ | |
3867 | #endif | |
806048df | 3868 | |
08a90d6a RS |
3869 | for (dpyinfo = x_display_list, names = x_display_name_list; |
3870 | dpyinfo; | |
8e713be6 | 3871 | dpyinfo = dpyinfo->next, names = XCDR (names)) |
b9dc4443 RS |
3872 | { |
3873 | Lisp_Object tem; | |
8e713be6 | 3874 | tem = Fstring_equal (XCAR (XCAR (names)), name); |
08a90d6a | 3875 | if (!NILP (tem)) |
b9dc4443 RS |
3876 | return dpyinfo; |
3877 | } | |
3878 | ||
b7975ee4 KH |
3879 | /* Use this general default value to start with. */ |
3880 | Vx_resource_name = Vinvocation_name; | |
3881 | ||
b9dc4443 RS |
3882 | validate_x_resource_name (); |
3883 | ||
9b207e8e | 3884 | dpyinfo = x_term_init (name, (char *)0, |
d5db4077 | 3885 | (char *) SDATA (Vx_resource_name)); |
b9dc4443 | 3886 | |
08a90d6a | 3887 | if (dpyinfo == 0) |
d5db4077 | 3888 | error ("Cannot connect to X server %s", SDATA (name)); |
08a90d6a | 3889 | |
b9dc4443 RS |
3890 | x_in_use = 1; |
3891 | XSETFASTINT (Vwindow_system_version, 11); | |
3892 | ||
3893 | return dpyinfo; | |
3894 | } | |
3895 | ||
a6ad00c0 | 3896 | |
01f1ba30 | 3897 | DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, |
c061c855 | 3898 | 1, 3, 0, |
7ee72033 | 3899 | doc: /* Open a connection to an X server. |
c061c855 GM |
3900 | DISPLAY is the name of the display to connect to. |
3901 | Optional second arg XRM-STRING is a string of resources in xrdb format. | |
3902 | If the optional third arg MUST-SUCCEED is non-nil, | |
7ee72033 MB |
3903 | terminate Emacs if we can't open the connection. */) |
3904 | (display, xrm_string, must_succeed) | |
08a90d6a | 3905 | Lisp_Object display, xrm_string, must_succeed; |
01f1ba30 | 3906 | { |
01f1ba30 | 3907 | unsigned char *xrm_option; |
b9dc4443 | 3908 | struct x_display_info *dpyinfo; |
01f1ba30 | 3909 | |
b7826503 | 3910 | CHECK_STRING (display); |
d387c960 | 3911 | if (! NILP (xrm_string)) |
b7826503 | 3912 | CHECK_STRING (xrm_string); |
01f1ba30 | 3913 | |
2246281f KL |
3914 | #if 0 |
3915 | if (! EQ (Vinitial_window_system, intern ("x"))) | |
3916 | error ("Not using X Windows"); /* That doesn't stop us anymore. */ | |
3917 | #endif | |
806048df | 3918 | |
d387c960 | 3919 | if (! NILP (xrm_string)) |
d5db4077 | 3920 | xrm_option = (unsigned char *) SDATA (xrm_string); |
01f1ba30 JB |
3921 | else |
3922 | xrm_option = (unsigned char *) 0; | |
d387c960 JB |
3923 | |
3924 | validate_x_resource_name (); | |
3925 | ||
e1b1bee8 | 3926 | /* This is what opens the connection and sets x_current_display. |
b9dc4443 RS |
3927 | This also initializes many symbols, such as those used for input. */ |
3928 | dpyinfo = x_term_init (display, xrm_option, | |
d5db4077 | 3929 | (char *) SDATA (Vx_resource_name)); |
f1c16f36 | 3930 | |
08a90d6a RS |
3931 | if (dpyinfo == 0) |
3932 | { | |
3933 | if (!NILP (must_succeed)) | |
10ffbc14 GM |
3934 | fatal ("Cannot connect to X server %s.\n\ |
3935 | Check the DISPLAY environment variable or use `-d'.\n\ | |
842a9389 JB |
3936 | Also use the `xauth' program to verify that you have the proper\n\ |
3937 | authorization information needed to connect the X server.\n\ | |
bf770132 | 3938 | An insecure way to solve the problem may be to use `xhost'.\n", |
d5db4077 | 3939 | SDATA (display)); |
08a90d6a | 3940 | else |
d5db4077 | 3941 | error ("Cannot connect to X server %s", SDATA (display)); |
08a90d6a RS |
3942 | } |
3943 | ||
b9dc4443 | 3944 | x_in_use = 1; |
01f1ba30 | 3945 | |
b9dc4443 | 3946 | XSETFASTINT (Vwindow_system_version, 11); |
01f1ba30 JB |
3947 | return Qnil; |
3948 | } | |
3949 | ||
08a90d6a RS |
3950 | DEFUN ("x-close-connection", Fx_close_connection, |
3951 | Sx_close_connection, 1, 1, 0, | |
7ee72033 | 3952 | doc: /* Close the connection to DISPLAY's X server. |
c061c855 | 3953 | For DISPLAY, specify either a frame or a display name (a string). |
7ee72033 MB |
3954 | If DISPLAY is nil, that stands for the selected frame's display. */) |
3955 | (display) | |
c061c855 | 3956 | Lisp_Object display; |
01f1ba30 | 3957 | { |
08a90d6a | 3958 | struct x_display_info *dpyinfo = check_x_display_info (display); |
08a90d6a | 3959 | int i; |
3457bc6e | 3960 | |
08a90d6a RS |
3961 | if (dpyinfo->reference_count > 0) |
3962 | error ("Display still has frames on it"); | |
01f1ba30 | 3963 | |
08a90d6a RS |
3964 | BLOCK_INPUT; |
3965 | /* Free the fonts in the font table. */ | |
3966 | for (i = 0; i < dpyinfo->n_fonts; i++) | |
333b20bb GM |
3967 | if (dpyinfo->font_table[i].name) |
3968 | { | |
333b20bb GM |
3969 | XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font); |
3970 | } | |
3971 | ||
08a90d6a RS |
3972 | x_destroy_all_bitmaps (dpyinfo); |
3973 | XSetCloseDownMode (dpyinfo->display, DestroyAll); | |
82c90203 RS |
3974 | |
3975 | #ifdef USE_X_TOOLKIT | |
3976 | XtCloseDisplay (dpyinfo->display); | |
3977 | #else | |
08a90d6a | 3978 | XCloseDisplay (dpyinfo->display); |
82c90203 | 3979 | #endif |
08a90d6a RS |
3980 | |
3981 | x_delete_display (dpyinfo); | |
3982 | UNBLOCK_INPUT; | |
3457bc6e | 3983 | |
01f1ba30 JB |
3984 | return Qnil; |
3985 | } | |
3986 | ||
08a90d6a | 3987 | DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0, |
7ee72033 MB |
3988 | doc: /* Return the list of display names that Emacs has connections to. */) |
3989 | () | |
08a90d6a RS |
3990 | { |
3991 | Lisp_Object tail, result; | |
3992 | ||
3993 | result = Qnil; | |
8e713be6 KR |
3994 | for (tail = x_display_name_list; ! NILP (tail); tail = XCDR (tail)) |
3995 | result = Fcons (XCAR (XCAR (tail)), result); | |
08a90d6a RS |
3996 | |
3997 | return result; | |
3998 | } | |
3999 | ||
4000 | DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0, | |
7ee72033 | 4001 | doc: /* If ON is non-nil, report X errors as soon as the erring request is made. |
c061c855 GM |
4002 | If ON is nil, allow buffering of requests. |
4003 | Turning on synchronization prohibits the Xlib routines from buffering | |
4004 | requests and seriously degrades performance, but makes debugging much | |
4005 | easier. | |
4006 | The optional second argument DISPLAY specifies which display to act on. | |
4007 | DISPLAY should be either a frame or a display name (a string). | |
7ee72033 MB |
4008 | If DISPLAY is omitted or nil, that stands for the selected frame's display. */) |
4009 | (on, display) | |
08a90d6a | 4010 | Lisp_Object display, on; |
01f1ba30 | 4011 | { |
08a90d6a | 4012 | struct x_display_info *dpyinfo = check_x_display_info (display); |
11ae94fe | 4013 | |
b9dc4443 | 4014 | XSynchronize (dpyinfo->display, !EQ (on, Qnil)); |
01f1ba30 JB |
4015 | |
4016 | return Qnil; | |
4017 | } | |
4018 | ||
b9dc4443 | 4019 | /* Wait for responses to all X commands issued so far for frame F. */ |
6b7b1820 RS |
4020 | |
4021 | void | |
b9dc4443 RS |
4022 | x_sync (f) |
4023 | FRAME_PTR f; | |
6b7b1820 | 4024 | { |
4e87f4d2 | 4025 | BLOCK_INPUT; |
b9dc4443 | 4026 | XSync (FRAME_X_DISPLAY (f), False); |
4e87f4d2 | 4027 | UNBLOCK_INPUT; |
6b7b1820 | 4028 | } |
333b20bb | 4029 | |
01f1ba30 | 4030 | \f |
333b20bb | 4031 | /*********************************************************************** |
7a060cd4 | 4032 | Window properties |
333b20bb | 4033 | ***********************************************************************/ |
f1c16f36 | 4034 | |
7a060cd4 KS |
4035 | DEFUN ("x-change-window-property", Fx_change_window_property, |
4036 | Sx_change_window_property, 2, 6, 0, | |
4037 | doc: /* Change window property PROP to VALUE on the X window of FRAME. | |
4038 | PROP must be a string. | |
4039 | VALUE may be a string or a list of conses, numbers and/or strings. | |
4040 | If an element in the list is a string, it is converted to | |
4041 | an Atom and the value of the Atom is used. If an element is a cons, | |
4042 | it is converted to a 32 bit number where the car is the 16 top bits and the | |
4043 | cdr is the lower 16 bits. | |
4044 | FRAME nil or omitted means use the selected frame. | |
4045 | If TYPE is given and non-nil, it is the name of the type of VALUE. | |
4046 | If TYPE is not given or nil, the type is STRING. | |
4047 | FORMAT gives the size in bits of each element if VALUE is a list. | |
4048 | It must be one of 8, 16 or 32. | |
4049 | If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8. | |
4050 | If OUTER_P is non-nil, the property is changed for the outer X window of | |
4051 | FRAME. Default is to change on the edit X window. | |
333b20bb | 4052 | |
7a060cd4 KS |
4053 | Value is VALUE. */) |
4054 | (prop, value, frame, type, format, outer_p) | |
4055 | Lisp_Object prop, value, frame, type, format, outer_p; | |
4056 | { | |
4057 | struct frame *f = check_x_frame (frame); | |
4058 | Atom prop_atom; | |
4059 | Atom target_type = XA_STRING; | |
4060 | int element_format = 8; | |
4061 | unsigned char *data; | |
4062 | int nelements; | |
4063 | Window w; | |
333b20bb | 4064 | |
7a060cd4 | 4065 | CHECK_STRING (prop); |
333b20bb | 4066 | |
7a060cd4 KS |
4067 | if (! NILP (format)) |
4068 | { | |
4069 | CHECK_NUMBER (format); | |
4070 | element_format = XFASTINT (format); | |
333b20bb | 4071 | |
7a060cd4 KS |
4072 | if (element_format != 8 && element_format != 16 |
4073 | && element_format != 32) | |
4074 | error ("FORMAT must be one of 8, 16 or 32"); | |
4075 | } | |
333b20bb | 4076 | |
7a060cd4 KS |
4077 | if (CONSP (value)) |
4078 | { | |
4079 | nelements = x_check_property_data (value); | |
4080 | if (nelements == -1) | |
4081 | error ("Bad data in VALUE, must be number, string or cons"); | |
333b20bb | 4082 | |
7a060cd4 KS |
4083 | if (element_format == 8) |
4084 | data = (unsigned char *) xmalloc (nelements); | |
4085 | else if (element_format == 16) | |
4086 | data = (unsigned char *) xmalloc (nelements*2); | |
4087 | else | |
4088 | data = (unsigned char *) xmalloc (nelements*4); | |
333b20bb | 4089 | |
7a060cd4 KS |
4090 | x_fill_property_data (FRAME_X_DISPLAY (f), value, data, element_format); |
4091 | } | |
4092 | else | |
4093 | { | |
4094 | CHECK_STRING (value); | |
4095 | data = SDATA (value); | |
4096 | nelements = SCHARS (value); | |
4097 | } | |
333b20bb | 4098 | |
7a060cd4 KS |
4099 | BLOCK_INPUT; |
4100 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False); | |
4101 | if (! NILP (type)) | |
4102 | { | |
4103 | CHECK_STRING (type); | |
4104 | target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False); | |
4105 | } | |
333b20bb | 4106 | |
7a060cd4 KS |
4107 | if (! NILP (outer_p)) w = FRAME_OUTER_WINDOW (f); |
4108 | else w = FRAME_X_WINDOW (f); | |
4109 | ||
4110 | XChangeProperty (FRAME_X_DISPLAY (f), w, | |
4111 | prop_atom, target_type, element_format, PropModeReplace, | |
4112 | data, nelements); | |
333b20bb | 4113 | |
7a060cd4 | 4114 | if (CONSP (value)) xfree (data); |
333b20bb | 4115 | |
7a060cd4 KS |
4116 | /* Make sure the property is set when we return. */ |
4117 | XFlush (FRAME_X_DISPLAY (f)); | |
4118 | UNBLOCK_INPUT; | |
333b20bb | 4119 | |
7a060cd4 | 4120 | return value; |
333b20bb GM |
4121 | } |
4122 | ||
4123 | ||
7a060cd4 KS |
4124 | DEFUN ("x-delete-window-property", Fx_delete_window_property, |
4125 | Sx_delete_window_property, 1, 2, 0, | |
4126 | doc: /* Remove window property PROP from X window of FRAME. | |
4127 | FRAME nil or omitted means use the selected frame. Value is PROP. */) | |
4128 | (prop, frame) | |
4129 | Lisp_Object prop, frame; | |
333b20bb | 4130 | { |
7a060cd4 KS |
4131 | struct frame *f = check_x_frame (frame); |
4132 | Atom prop_atom; | |
333b20bb | 4133 | |
7a060cd4 KS |
4134 | CHECK_STRING (prop); |
4135 | BLOCK_INPUT; | |
4136 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False); | |
4137 | XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), prop_atom); | |
333b20bb | 4138 | |
7a060cd4 KS |
4139 | /* Make sure the property is removed when we return. */ |
4140 | XFlush (FRAME_X_DISPLAY (f)); | |
4141 | UNBLOCK_INPUT; | |
177c0ea7 | 4142 | |
7a060cd4 | 4143 | return prop; |
333b20bb | 4144 | } |
333b20bb GM |
4145 | |
4146 | ||
4147 | DEFUN ("x-window-property", Fx_window_property, Sx_window_property, | |
b4715a72 | 4148 | 1, 6, 0, |
7ee72033 | 4149 | doc: /* Value is the value of window property PROP on FRAME. |
b4715a72 JD |
4150 | If FRAME is nil or omitted, use the selected frame. |
4151 | If TYPE is nil or omitted, get the property as a string. Otherwise TYPE | |
4152 | is the name of the Atom that denotes the type expected. | |
4153 | If SOURCE is non-nil, get the property on that window instead of from | |
4154 | FRAME. The number 0 denotes the root window. | |
4155 | If DELETE_P is non-nil, delete the property after retreiving it. | |
4156 | If VECTOR_RET_P is non-nil, don't return a string but a vector of values. | |
4157 | ||
4158 | Value is nil if FRAME hasn't a property with name PROP or if PROP has | |
4159 | no value of TYPE. */) | |
4160 | (prop, frame, type, source, delete_p, vector_ret_p) | |
4161 | Lisp_Object prop, frame, type, source, delete_p, vector_ret_p; | |
333b20bb GM |
4162 | { |
4163 | struct frame *f = check_x_frame (frame); | |
4164 | Atom prop_atom; | |
4165 | int rc; | |
4166 | Lisp_Object prop_value = Qnil; | |
4167 | char *tmp_data = NULL; | |
4168 | Atom actual_type; | |
b4715a72 | 4169 | Atom target_type = XA_STRING; |
333b20bb GM |
4170 | int actual_format; |
4171 | unsigned long actual_size, bytes_remaining; | |
b4715a72 JD |
4172 | Window target_window = FRAME_X_WINDOW (f); |
4173 | struct gcpro gcpro1; | |
333b20bb | 4174 | |
b4715a72 | 4175 | GCPRO1 (prop_value); |
b7826503 | 4176 | CHECK_STRING (prop); |
b4715a72 JD |
4177 | |
4178 | if (! NILP (source)) | |
4179 | { | |
4180 | if (NUMBERP (source)) | |
4181 | { | |
4182 | if (FLOATP (source)) | |
4183 | target_window = (Window) XFLOAT (source); | |
4184 | else | |
4185 | target_window = XFASTINT (source); | |
4186 | ||
4187 | if (target_window == 0) | |
4188 | target_window = FRAME_X_DISPLAY_INFO (f)->root_window; | |
4189 | } | |
4190 | else if (CONSP (source)) | |
4191 | target_window = cons_to_long (source); | |
4192 | } | |
4193 | ||
333b20bb | 4194 | BLOCK_INPUT; |
b4715a72 JD |
4195 | if (STRINGP (type)) |
4196 | { | |
4197 | if (strcmp ("AnyPropertyType", SDATA (type)) == 0) | |
4198 | target_type = AnyPropertyType; | |
4199 | else | |
4200 | target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False); | |
4201 | } | |
4202 | ||
d5db4077 | 4203 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False); |
b4715a72 JD |
4204 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, |
4205 | prop_atom, 0, 0, False, target_type, | |
333b20bb GM |
4206 | &actual_type, &actual_format, &actual_size, |
4207 | &bytes_remaining, (unsigned char **) &tmp_data); | |
4208 | if (rc == Success) | |
4209 | { | |
4210 | int size = bytes_remaining; | |
4211 | ||
4212 | XFree (tmp_data); | |
4213 | tmp_data = NULL; | |
4214 | ||
b4715a72 | 4215 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, |
333b20bb | 4216 | prop_atom, 0, bytes_remaining, |
b4715a72 | 4217 | ! NILP (delete_p), target_type, |
177c0ea7 JB |
4218 | &actual_type, &actual_format, |
4219 | &actual_size, &bytes_remaining, | |
333b20bb | 4220 | (unsigned char **) &tmp_data); |
4c8c7926 | 4221 | if (rc == Success && tmp_data) |
b4715a72 JD |
4222 | { |
4223 | if (NILP (vector_ret_p)) | |
4224 | prop_value = make_string (tmp_data, size); | |
4225 | else | |
4226 | prop_value = x_property_data_to_lisp (f, | |
4227 | (unsigned char *) tmp_data, | |
4228 | actual_type, | |
4229 | actual_format, | |
4230 | actual_size); | |
4231 | } | |
333b20bb | 4232 | |
b4715a72 | 4233 | if (tmp_data) XFree (tmp_data); |
333b20bb GM |
4234 | } |
4235 | ||
4236 | UNBLOCK_INPUT; | |
b4715a72 | 4237 | UNGCPRO; |
333b20bb GM |
4238 | return prop_value; |
4239 | } | |
4240 | ||
4241 | ||
4242 | \f | |
4243 | /*********************************************************************** | |
4244 | Busy cursor | |
4245 | ***********************************************************************/ | |
4246 | ||
4ae9a85e | 4247 | /* If non-null, an asynchronous timer that, when it expires, displays |
0af913d7 | 4248 | an hourglass cursor on all frames. */ |
333b20bb | 4249 | |
0af913d7 | 4250 | static struct atimer *hourglass_atimer; |
333b20bb | 4251 | |
0af913d7 | 4252 | /* Non-zero means an hourglass cursor is currently shown. */ |
333b20bb | 4253 | |
0af913d7 | 4254 | static int hourglass_shown_p; |
333b20bb | 4255 | |
0af913d7 | 4256 | /* Number of seconds to wait before displaying an hourglass cursor. */ |
333b20bb | 4257 | |
0af913d7 | 4258 | static Lisp_Object Vhourglass_delay; |
333b20bb | 4259 | |
0af913d7 | 4260 | /* Default number of seconds to wait before displaying an hourglass |
4ae9a85e GM |
4261 | cursor. */ |
4262 | ||
0af913d7 | 4263 | #define DEFAULT_HOURGLASS_DELAY 1 |
4ae9a85e GM |
4264 | |
4265 | /* Function prototypes. */ | |
4266 | ||
0af913d7 GM |
4267 | static void show_hourglass P_ ((struct atimer *)); |
4268 | static void hide_hourglass P_ ((void)); | |
4ae9a85e GM |
4269 | |
4270 | ||
0af913d7 | 4271 | /* Cancel a currently active hourglass timer, and start a new one. */ |
4ae9a85e GM |
4272 | |
4273 | void | |
0af913d7 | 4274 | start_hourglass () |
333b20bb | 4275 | { |
4ae9a85e | 4276 | EMACS_TIME delay; |
3caa99d3 | 4277 | int secs, usecs = 0; |
177c0ea7 | 4278 | |
0af913d7 | 4279 | cancel_hourglass (); |
4ae9a85e | 4280 | |
0af913d7 GM |
4281 | if (INTEGERP (Vhourglass_delay) |
4282 | && XINT (Vhourglass_delay) > 0) | |
4283 | secs = XFASTINT (Vhourglass_delay); | |
4284 | else if (FLOATP (Vhourglass_delay) | |
4285 | && XFLOAT_DATA (Vhourglass_delay) > 0) | |
3caa99d3 GM |
4286 | { |
4287 | Lisp_Object tem; | |
0af913d7 | 4288 | tem = Ftruncate (Vhourglass_delay, Qnil); |
3caa99d3 | 4289 | secs = XFASTINT (tem); |
0af913d7 | 4290 | usecs = (XFLOAT_DATA (Vhourglass_delay) - secs) * 1000000; |
3caa99d3 | 4291 | } |
4ae9a85e | 4292 | else |
0af913d7 | 4293 | secs = DEFAULT_HOURGLASS_DELAY; |
177c0ea7 | 4294 | |
3caa99d3 | 4295 | EMACS_SET_SECS_USECS (delay, secs, usecs); |
0af913d7 GM |
4296 | hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay, |
4297 | show_hourglass, NULL); | |
4ae9a85e GM |
4298 | } |
4299 | ||
4300 | ||
0af913d7 | 4301 | /* Cancel the hourglass cursor timer if active, hide a busy cursor if |
4ae9a85e GM |
4302 | shown. */ |
4303 | ||
4304 | void | |
0af913d7 | 4305 | cancel_hourglass () |
4ae9a85e | 4306 | { |
0af913d7 | 4307 | if (hourglass_atimer) |
99f01f62 | 4308 | { |
0af913d7 GM |
4309 | cancel_atimer (hourglass_atimer); |
4310 | hourglass_atimer = NULL; | |
99f01f62 | 4311 | } |
177c0ea7 | 4312 | |
0af913d7 GM |
4313 | if (hourglass_shown_p) |
4314 | hide_hourglass (); | |
4ae9a85e GM |
4315 | } |
4316 | ||
4317 | ||
0af913d7 GM |
4318 | /* Timer function of hourglass_atimer. TIMER is equal to |
4319 | hourglass_atimer. | |
4ae9a85e | 4320 | |
0af913d7 GM |
4321 | Display an hourglass pointer on all frames by mapping the frames' |
4322 | hourglass_window. Set the hourglass_p flag in the frames' | |
4323 | output_data.x structure to indicate that an hourglass cursor is | |
4324 | shown on the frames. */ | |
4ae9a85e GM |
4325 | |
4326 | static void | |
0af913d7 | 4327 | show_hourglass (timer) |
4ae9a85e GM |
4328 | struct atimer *timer; |
4329 | { | |
4330 | /* The timer implementation will cancel this timer automatically | |
0af913d7 | 4331 | after this function has run. Set hourglass_atimer to null |
4ae9a85e | 4332 | so that we know the timer doesn't have to be canceled. */ |
0af913d7 | 4333 | hourglass_atimer = NULL; |
4ae9a85e | 4334 | |
0af913d7 | 4335 | if (!hourglass_shown_p) |
333b20bb GM |
4336 | { |
4337 | Lisp_Object rest, frame; | |
177c0ea7 | 4338 | |
4ae9a85e | 4339 | BLOCK_INPUT; |
177c0ea7 | 4340 | |
333b20bb | 4341 | FOR_EACH_FRAME (rest, frame) |
5f7a1890 GM |
4342 | { |
4343 | struct frame *f = XFRAME (frame); | |
177c0ea7 | 4344 | |
5f7a1890 GM |
4345 | if (FRAME_LIVE_P (f) && FRAME_X_P (f) && FRAME_X_DISPLAY (f)) |
4346 | { | |
4347 | Display *dpy = FRAME_X_DISPLAY (f); | |
177c0ea7 | 4348 | |
5f7a1890 GM |
4349 | #ifdef USE_X_TOOLKIT |
4350 | if (f->output_data.x->widget) | |
4351 | #else | |
4352 | if (FRAME_OUTER_WINDOW (f)) | |
4353 | #endif | |
4354 | { | |
0af913d7 | 4355 | f->output_data.x->hourglass_p = 1; |
177c0ea7 | 4356 | |
0af913d7 | 4357 | if (!f->output_data.x->hourglass_window) |
5f7a1890 GM |
4358 | { |
4359 | unsigned long mask = CWCursor; | |
4360 | XSetWindowAttributes attrs; | |
49b8b5dc JD |
4361 | #ifdef USE_GTK |
4362 | Window parent = FRAME_X_WINDOW (f); | |
4363 | #else | |
4364 | Window parent = FRAME_OUTER_WINDOW (f); | |
4365 | #endif | |
0af913d7 | 4366 | attrs.cursor = f->output_data.x->hourglass_cursor; |
177c0ea7 | 4367 | |
0af913d7 | 4368 | f->output_data.x->hourglass_window |
49b8b5dc | 4369 | = XCreateWindow (dpy, parent, |
5f7a1890 GM |
4370 | 0, 0, 32000, 32000, 0, 0, |
4371 | InputOnly, | |
4372 | CopyFromParent, | |
4373 | mask, &attrs); | |
4374 | } | |
177c0ea7 | 4375 | |
0af913d7 | 4376 | XMapRaised (dpy, f->output_data.x->hourglass_window); |
5f7a1890 GM |
4377 | XFlush (dpy); |
4378 | } | |
4379 | } | |
4380 | } | |
333b20bb | 4381 | |
0af913d7 | 4382 | hourglass_shown_p = 1; |
4ae9a85e GM |
4383 | UNBLOCK_INPUT; |
4384 | } | |
333b20bb GM |
4385 | } |
4386 | ||
4387 | ||
0af913d7 GM |
4388 | /* Hide the hourglass pointer on all frames, if it is currently |
4389 | shown. */ | |
333b20bb | 4390 | |
4ae9a85e | 4391 | static void |
0af913d7 | 4392 | hide_hourglass () |
4ae9a85e | 4393 | { |
0af913d7 | 4394 | if (hourglass_shown_p) |
333b20bb | 4395 | { |
4ae9a85e GM |
4396 | Lisp_Object rest, frame; |
4397 | ||
4398 | BLOCK_INPUT; | |
4399 | FOR_EACH_FRAME (rest, frame) | |
333b20bb | 4400 | { |
4ae9a85e | 4401 | struct frame *f = XFRAME (frame); |
177c0ea7 | 4402 | |
4ae9a85e GM |
4403 | if (FRAME_X_P (f) |
4404 | /* Watch out for newly created frames. */ | |
0af913d7 | 4405 | && f->output_data.x->hourglass_window) |
4ae9a85e | 4406 | { |
0af913d7 GM |
4407 | XUnmapWindow (FRAME_X_DISPLAY (f), |
4408 | f->output_data.x->hourglass_window); | |
4409 | /* Sync here because XTread_socket looks at the | |
4410 | hourglass_p flag that is reset to zero below. */ | |
4ae9a85e | 4411 | XSync (FRAME_X_DISPLAY (f), False); |
0af913d7 | 4412 | f->output_data.x->hourglass_p = 0; |
4ae9a85e | 4413 | } |
333b20bb | 4414 | } |
333b20bb | 4415 | |
0af913d7 | 4416 | hourglass_shown_p = 0; |
4ae9a85e GM |
4417 | UNBLOCK_INPUT; |
4418 | } | |
333b20bb GM |
4419 | } |
4420 | ||
4421 | ||
4422 | \f | |
4423 | /*********************************************************************** | |
4424 | Tool tips | |
4425 | ***********************************************************************/ | |
4426 | ||
4427 | static Lisp_Object x_create_tip_frame P_ ((struct x_display_info *, | |
275841bf | 4428 | Lisp_Object, Lisp_Object)); |
06d62053 | 4429 | static void compute_tip_xy P_ ((struct frame *, Lisp_Object, Lisp_Object, |
ab452f99 | 4430 | Lisp_Object, int, int, int *, int *)); |
177c0ea7 | 4431 | |
44b5a125 | 4432 | /* The frame of a currently visible tooltip. */ |
333b20bb | 4433 | |
44b5a125 | 4434 | Lisp_Object tip_frame; |
333b20bb GM |
4435 | |
4436 | /* If non-nil, a timer started that hides the last tooltip when it | |
4437 | fires. */ | |
4438 | ||
4439 | Lisp_Object tip_timer; | |
4440 | Window tip_window; | |
4441 | ||
06d62053 GM |
4442 | /* If non-nil, a vector of 3 elements containing the last args |
4443 | with which x-show-tip was called. See there. */ | |
4444 | ||
4445 | Lisp_Object last_show_tip_args; | |
4446 | ||
d63931a2 GM |
4447 | /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */ |
4448 | ||
4449 | Lisp_Object Vx_max_tooltip_size; | |
4450 | ||
eaf1eea9 GM |
4451 | |
4452 | static Lisp_Object | |
4453 | unwind_create_tip_frame (frame) | |
4454 | Lisp_Object frame; | |
4455 | { | |
c844a81a GM |
4456 | Lisp_Object deleted; |
4457 | ||
4458 | deleted = unwind_create_frame (frame); | |
4459 | if (EQ (deleted, Qt)) | |
4460 | { | |
4461 | tip_window = None; | |
4462 | tip_frame = Qnil; | |
4463 | } | |
177c0ea7 | 4464 | |
c844a81a | 4465 | return deleted; |
eaf1eea9 GM |
4466 | } |
4467 | ||
4468 | ||
333b20bb | 4469 | /* Create a frame for a tooltip on the display described by DPYINFO. |
275841bf GM |
4470 | PARMS is a list of frame parameters. TEXT is the string to |
4471 | display in the tip frame. Value is the frame. | |
eaf1eea9 GM |
4472 | |
4473 | Note that functions called here, esp. x_default_parameter can | |
4474 | signal errors, for instance when a specified color name is | |
4475 | undefined. We have to make sure that we're in a consistent state | |
4476 | when this happens. */ | |
333b20bb GM |
4477 | |
4478 | static Lisp_Object | |
275841bf | 4479 | x_create_tip_frame (dpyinfo, parms, text) |
333b20bb | 4480 | struct x_display_info *dpyinfo; |
275841bf | 4481 | Lisp_Object parms, text; |
333b20bb GM |
4482 | { |
4483 | struct frame *f; | |
4484 | Lisp_Object frame, tem; | |
4485 | Lisp_Object name; | |
333b20bb GM |
4486 | long window_prompting = 0; |
4487 | int width, height; | |
331379bf | 4488 | int count = SPECPDL_INDEX (); |
b6d7acec | 4489 | struct gcpro gcpro1, gcpro2, gcpro3; |
333b20bb | 4490 | struct kboard *kb; |
06d62053 | 4491 | int face_change_count_before = face_change_count; |
275841bf GM |
4492 | Lisp_Object buffer; |
4493 | struct buffer *old_buffer; | |
333b20bb GM |
4494 | |
4495 | check_x (); | |
4496 | ||
4497 | /* Use this general default value to start with until we know if | |
4498 | this frame has a specified name. */ | |
4499 | Vx_resource_name = Vinvocation_name; | |
4500 | ||
4501 | #ifdef MULTI_KBOARD | |
4502 | kb = dpyinfo->kboard; | |
4503 | #else | |
4504 | kb = &the_only_kboard; | |
4505 | #endif | |
4506 | ||
4507 | /* Get the name of the frame to use for resource lookup. */ | |
4508 | name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); | |
4509 | if (!STRINGP (name) | |
4510 | && !EQ (name, Qunbound) | |
4511 | && !NILP (name)) | |
4512 | error ("Invalid frame name--not a string or nil"); | |
9d3d44ba | 4513 | |
333b20bb GM |
4514 | Vx_resource_name = name; |
4515 | ||
4516 | frame = Qnil; | |
4517 | GCPRO3 (parms, name, frame); | |
44b5a125 | 4518 | f = make_frame (1); |
333b20bb | 4519 | XSETFRAME (frame, f); |
275841bf GM |
4520 | |
4521 | buffer = Fget_buffer_create (build_string (" *tip*")); | |
be786000 | 4522 | Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil); |
275841bf GM |
4523 | old_buffer = current_buffer; |
4524 | set_buffer_internal_1 (XBUFFER (buffer)); | |
d63931a2 | 4525 | current_buffer->truncate_lines = Qnil; |
5c2a995d KH |
4526 | specbind (Qinhibit_read_only, Qt); |
4527 | specbind (Qinhibit_modification_hooks, Qt); | |
275841bf GM |
4528 | Ferase_buffer (); |
4529 | Finsert (1, &text); | |
4530 | set_buffer_internal_1 (old_buffer); | |
177c0ea7 | 4531 | |
333b20bb | 4532 | FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; |
8a1a7743 | 4533 | record_unwind_protect (unwind_create_tip_frame, frame); |
333b20bb | 4534 | |
428a555e KL |
4535 | f->display = dpyinfo->frame_display; |
4536 | f->display->reference_count++; | |
daf01701 | 4537 | |
eaf1eea9 GM |
4538 | /* By setting the output method, we're essentially saying that |
4539 | the frame is live, as per FRAME_LIVE_P. If we get a signal | |
4540 | from this point on, x_destroy_window might screw up reference | |
4541 | counts etc. */ | |
333b20bb GM |
4542 | f->output_method = output_x_window; |
4543 | f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output)); | |
4544 | bzero (f->output_data.x, sizeof (struct x_output)); | |
4545 | f->output_data.x->icon_bitmap = -1; | |
be786000 | 4546 | FRAME_FONTSET (f) = -1; |
61d461a8 GM |
4547 | f->output_data.x->scroll_bar_foreground_pixel = -1; |
4548 | f->output_data.x->scroll_bar_background_pixel = -1; | |
f15340b7 MB |
4549 | #ifdef USE_TOOLKIT_SCROLL_BARS |
4550 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
4551 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
4552 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
333b20bb GM |
4553 | f->icon_name = Qnil; |
4554 | FRAME_X_DISPLAY_INFO (f) = dpyinfo; | |
f1d2ce7f | 4555 | #if GLYPH_DEBUG |
eaf1eea9 GM |
4556 | image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount; |
4557 | dpyinfo_refcount = dpyinfo->reference_count; | |
4558 | #endif /* GLYPH_DEBUG */ | |
333b20bb GM |
4559 | #ifdef MULTI_KBOARD |
4560 | FRAME_KBOARD (f) = kb; | |
4561 | #endif | |
4562 | f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; | |
4563 | f->output_data.x->explicit_parent = 0; | |
4564 | ||
61d461a8 GM |
4565 | /* These colors will be set anyway later, but it's important |
4566 | to get the color reference counts right, so initialize them! */ | |
4567 | { | |
4568 | Lisp_Object black; | |
4569 | struct gcpro gcpro1; | |
177c0ea7 | 4570 | |
9d3d44ba KL |
4571 | /* Function x_decode_color can signal an error. Make |
4572 | sure to initialize color slots so that we won't try | |
4573 | to free colors we haven't allocated. */ | |
4574 | f->output_data.x->foreground_pixel = -1; | |
4575 | f->output_data.x->background_pixel = -1; | |
4576 | f->output_data.x->cursor_pixel = -1; | |
4577 | f->output_data.x->cursor_foreground_pixel = -1; | |
4578 | f->output_data.x->border_pixel = -1; | |
4579 | f->output_data.x->mouse_pixel = -1; | |
4580 | ||
61d461a8 GM |
4581 | black = build_string ("black"); |
4582 | GCPRO1 (black); | |
4583 | f->output_data.x->foreground_pixel | |
4584 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4585 | f->output_data.x->background_pixel | |
4586 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4587 | f->output_data.x->cursor_pixel | |
4588 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4589 | f->output_data.x->cursor_foreground_pixel | |
4590 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4591 | f->output_data.x->border_pixel | |
4592 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4593 | f->output_data.x->mouse_pixel | |
4594 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4595 | UNGCPRO; | |
4596 | } | |
4597 | ||
333b20bb GM |
4598 | /* Set the name; the functions to which we pass f expect the name to |
4599 | be set. */ | |
4600 | if (EQ (name, Qunbound) || NILP (name)) | |
4601 | { | |
4602 | f->name = build_string (dpyinfo->x_id_name); | |
4603 | f->explicit_name = 0; | |
4604 | } | |
4605 | else | |
4606 | { | |
4607 | f->name = name; | |
4608 | f->explicit_name = 1; | |
4609 | /* use the frame's title when getting resources for this frame. */ | |
4610 | specbind (Qx_resource_name, name); | |
4611 | } | |
4612 | ||
eaf1eea9 GM |
4613 | /* Extract the window parameters from the supplied values that are |
4614 | needed to determine window geometry. */ | |
333b20bb GM |
4615 | { |
4616 | Lisp_Object font; | |
4617 | ||
4618 | font = x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING); | |
4619 | ||
4620 | BLOCK_INPUT; | |
4621 | /* First, try whatever font the caller has specified. */ | |
4622 | if (STRINGP (font)) | |
4623 | { | |
4624 | tem = Fquery_fontset (font, Qnil); | |
4625 | if (STRINGP (tem)) | |
d5db4077 | 4626 | font = x_new_fontset (f, SDATA (tem)); |
333b20bb | 4627 | else |
d5db4077 | 4628 | font = x_new_font (f, SDATA (font)); |
333b20bb | 4629 | } |
177c0ea7 | 4630 | |
333b20bb GM |
4631 | /* Try out a font which we hope has bold and italic variations. */ |
4632 | if (!STRINGP (font)) | |
4633 | font = x_new_font (f, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1"); | |
4634 | if (!STRINGP (font)) | |
4635 | font = x_new_font (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1"); | |
4636 | if (! STRINGP (font)) | |
4637 | font = x_new_font (f, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1"); | |
4638 | if (! STRINGP (font)) | |
4639 | /* This was formerly the first thing tried, but it finds too many fonts | |
4640 | and takes too long. */ | |
4641 | font = x_new_font (f, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1"); | |
4642 | /* If those didn't work, look for something which will at least work. */ | |
4643 | if (! STRINGP (font)) | |
4644 | font = x_new_font (f, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1"); | |
4645 | UNBLOCK_INPUT; | |
4646 | if (! STRINGP (font)) | |
4647 | font = build_string ("fixed"); | |
4648 | ||
4649 | x_default_parameter (f, parms, Qfont, font, | |
4650 | "font", "Font", RES_TYPE_STRING); | |
4651 | } | |
4652 | ||
4653 | x_default_parameter (f, parms, Qborder_width, make_number (2), | |
4654 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); | |
177c0ea7 | 4655 | |
9d3d44ba | 4656 | /* This defaults to 1 in order to match xterm. We recognize either |
333b20bb GM |
4657 | internalBorderWidth or internalBorder (which is what xterm calls |
4658 | it). */ | |
4659 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
4660 | { | |
4661 | Lisp_Object value; | |
4662 | ||
4663 | value = x_get_arg (dpyinfo, parms, Qinternal_border_width, | |
4664 | "internalBorder", "internalBorder", RES_TYPE_NUMBER); | |
4665 | if (! EQ (value, Qunbound)) | |
4666 | parms = Fcons (Fcons (Qinternal_border_width, value), | |
4667 | parms); | |
4668 | } | |
4669 | ||
4670 | x_default_parameter (f, parms, Qinternal_border_width, make_number (1), | |
4671 | "internalBorderWidth", "internalBorderWidth", | |
4672 | RES_TYPE_NUMBER); | |
4673 | ||
4674 | /* Also do the stuff which must be set before the window exists. */ | |
4675 | x_default_parameter (f, parms, Qforeground_color, build_string ("black"), | |
4676 | "foreground", "Foreground", RES_TYPE_STRING); | |
4677 | x_default_parameter (f, parms, Qbackground_color, build_string ("white"), | |
4678 | "background", "Background", RES_TYPE_STRING); | |
4679 | x_default_parameter (f, parms, Qmouse_color, build_string ("black"), | |
4680 | "pointerColor", "Foreground", RES_TYPE_STRING); | |
4681 | x_default_parameter (f, parms, Qcursor_color, build_string ("black"), | |
4682 | "cursorColor", "Foreground", RES_TYPE_STRING); | |
4683 | x_default_parameter (f, parms, Qborder_color, build_string ("black"), | |
4684 | "borderColor", "BorderColor", RES_TYPE_STRING); | |
4685 | ||
4686 | /* Init faces before x_default_parameter is called for scroll-bar | |
4687 | parameters because that function calls x_set_scroll_bar_width, | |
4688 | which calls change_frame_size, which calls Fset_window_buffer, | |
4689 | which runs hooks, which call Fvertical_motion. At the end, we | |
4690 | end up in init_iterator with a null face cache, which should not | |
4691 | happen. */ | |
4692 | init_frame_faces (f); | |
177c0ea7 | 4693 | |
333b20bb | 4694 | f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; |
333b20bb | 4695 | |
7c0d3ed8 | 4696 | window_prompting = x_figure_window_size (f, parms, 0); |
333b20bb | 4697 | |
333b20bb GM |
4698 | { |
4699 | XSetWindowAttributes attrs; | |
4700 | unsigned long mask; | |
177c0ea7 | 4701 | |
333b20bb | 4702 | BLOCK_INPUT; |
c51d2b5e GM |
4703 | mask = CWBackPixel | CWOverrideRedirect | CWEventMask; |
4704 | if (DoesSaveUnders (dpyinfo->screen)) | |
4705 | mask |= CWSaveUnder; | |
177c0ea7 | 4706 | |
9b2956e2 GM |
4707 | /* Window managers look at the override-redirect flag to determine |
4708 | whether or net to give windows a decoration (Xlib spec, chapter | |
333b20bb GM |
4709 | 3.2.8). */ |
4710 | attrs.override_redirect = True; | |
4711 | attrs.save_under = True; | |
4712 | attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f); | |
4713 | /* Arrange for getting MapNotify and UnmapNotify events. */ | |
4714 | attrs.event_mask = StructureNotifyMask; | |
4715 | tip_window | |
4716 | = FRAME_X_WINDOW (f) | |
4717 | = XCreateWindow (FRAME_X_DISPLAY (f), | |
4718 | FRAME_X_DISPLAY_INFO (f)->root_window, | |
4719 | /* x, y, width, height */ | |
4720 | 0, 0, 1, 1, | |
4721 | /* Border. */ | |
4722 | 1, | |
4723 | CopyFromParent, InputOutput, CopyFromParent, | |
4724 | mask, &attrs); | |
4725 | UNBLOCK_INPUT; | |
4726 | } | |
4727 | ||
4728 | x_make_gc (f); | |
4729 | ||
333b20bb GM |
4730 | x_default_parameter (f, parms, Qauto_raise, Qnil, |
4731 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
4732 | x_default_parameter (f, parms, Qauto_lower, Qnil, | |
4733 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
4734 | x_default_parameter (f, parms, Qcursor_type, Qbox, | |
4735 | "cursorType", "CursorType", RES_TYPE_SYMBOL); | |
4736 | ||
be786000 | 4737 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
333b20bb | 4738 | Change will not be effected unless different from the current |
be786000 KS |
4739 | FRAME_LINES (f). */ |
4740 | width = FRAME_COLS (f); | |
4741 | height = FRAME_LINES (f); | |
4742 | SET_FRAME_COLS (f, 0); | |
4743 | FRAME_LINES (f) = 0; | |
8938a4fb | 4744 | change_frame_size (f, height, width, 1, 0, 0); |
177c0ea7 | 4745 | |
cd1d850f JPW |
4746 | /* Add `tooltip' frame parameter's default value. */ |
4747 | if (NILP (Fframe_parameter (frame, intern ("tooltip")))) | |
4748 | Fmodify_frame_parameters (frame, Fcons (Fcons (intern ("tooltip"), Qt), | |
4749 | Qnil)); | |
177c0ea7 | 4750 | |
035d5114 | 4751 | /* Set up faces after all frame parameters are known. This call |
6801a572 GM |
4752 | also merges in face attributes specified for new frames. |
4753 | ||
4754 | Frame parameters may be changed if .Xdefaults contains | |
4755 | specifications for the default font. For example, if there is an | |
4756 | `Emacs.default.attributeBackground: pink', the `background-color' | |
4757 | attribute of the frame get's set, which let's the internal border | |
4758 | of the tooltip frame appear in pink. Prevent this. */ | |
4759 | { | |
4760 | Lisp_Object bg = Fframe_parameter (frame, Qbackground_color); | |
4761 | ||
4762 | /* Set tip_frame here, so that */ | |
4763 | tip_frame = frame; | |
4764 | call1 (Qface_set_after_frame_default, frame); | |
177c0ea7 | 4765 | |
6801a572 GM |
4766 | if (!EQ (bg, Fframe_parameter (frame, Qbackground_color))) |
4767 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg), | |
4768 | Qnil)); | |
4769 | } | |
177c0ea7 | 4770 | |
7f19e125 KL |
4771 | Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qx), Qnil)); |
4772 | ||
333b20bb GM |
4773 | f->no_split = 1; |
4774 | ||
4775 | UNGCPRO; | |
4776 | ||
4777 | /* It is now ok to make the frame official even if we get an error | |
4778 | below. And the frame needs to be on Vframe_list or making it | |
4779 | visible won't work. */ | |
4780 | Vframe_list = Fcons (frame, Vframe_list); | |
4781 | ||
4782 | /* Now that the frame is official, it counts as a reference to | |
4783 | its display. */ | |
4784 | FRAME_X_DISPLAY_INFO (f)->reference_count++; | |
4785 | ||
06d62053 GM |
4786 | /* Setting attributes of faces of the tooltip frame from resources |
4787 | and similar will increment face_change_count, which leads to the | |
4788 | clearing of all current matrices. Since this isn't necessary | |
4789 | here, avoid it by resetting face_change_count to the value it | |
4790 | had before we created the tip frame. */ | |
4791 | face_change_count = face_change_count_before; | |
4792 | ||
eaf1eea9 | 4793 | /* Discard the unwind_protect. */ |
333b20bb GM |
4794 | return unbind_to (count, frame); |
4795 | } | |
4796 | ||
4797 | ||
06d62053 GM |
4798 | /* Compute where to display tip frame F. PARMS is the list of frame |
4799 | parameters for F. DX and DY are specified offsets from the current | |
ab452f99 GM |
4800 | location of the mouse. WIDTH and HEIGHT are the width and height |
4801 | of the tooltip. Return coordinates relative to the root window of | |
4802 | the display in *ROOT_X, and *ROOT_Y. */ | |
06d62053 GM |
4803 | |
4804 | static void | |
ab452f99 | 4805 | compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y) |
06d62053 GM |
4806 | struct frame *f; |
4807 | Lisp_Object parms, dx, dy; | |
ab452f99 | 4808 | int width, height; |
06d62053 GM |
4809 | int *root_x, *root_y; |
4810 | { | |
4811 | Lisp_Object left, top; | |
4812 | int win_x, win_y; | |
4813 | Window root, child; | |
4814 | unsigned pmask; | |
177c0ea7 | 4815 | |
06d62053 GM |
4816 | /* User-specified position? */ |
4817 | left = Fcdr (Fassq (Qleft, parms)); | |
4818 | top = Fcdr (Fassq (Qtop, parms)); | |
177c0ea7 | 4819 | |
06d62053 GM |
4820 | /* Move the tooltip window where the mouse pointer is. Resize and |
4821 | show it. */ | |
570d22b0 | 4822 | if (!INTEGERP (left) || !INTEGERP (top)) |
ab452f99 GM |
4823 | { |
4824 | BLOCK_INPUT; | |
4825 | XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, | |
4826 | &root, &child, root_x, root_y, &win_x, &win_y, &pmask); | |
4827 | UNBLOCK_INPUT; | |
4828 | } | |
06d62053 | 4829 | |
06d62053 GM |
4830 | if (INTEGERP (top)) |
4831 | *root_y = XINT (top); | |
ab452f99 GM |
4832 | else if (*root_y + XINT (dy) - height < 0) |
4833 | *root_y -= XINT (dy); | |
4834 | else | |
4835 | { | |
4836 | *root_y -= height; | |
4837 | *root_y += XINT (dy); | |
4838 | } | |
4839 | ||
4840 | if (INTEGERP (left)) | |
4841 | *root_x = XINT (left); | |
d682d3df RS |
4842 | else if (*root_x + XINT (dx) + width <= FRAME_X_DISPLAY_INFO (f)->width) |
4843 | /* It fits to the right of the pointer. */ | |
4844 | *root_x += XINT (dx); | |
4845 | else if (width + XINT (dx) <= *root_x) | |
4846 | /* It fits to the left of the pointer. */ | |
ab452f99 GM |
4847 | *root_x -= width + XINT (dx); |
4848 | else | |
d682d3df RS |
4849 | /* Put it left-justified on the screen--it ought to fit that way. */ |
4850 | *root_x = 0; | |
06d62053 GM |
4851 | } |
4852 | ||
4853 | ||
0634ce98 | 4854 | DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, |
7ee72033 | 4855 | doc: /* Show STRING in a "tooltip" window on frame FRAME. |
c061c855 GM |
4856 | A tooltip window is a small X window displaying a string. |
4857 | ||
4858 | FRAME nil or omitted means use the selected frame. | |
4859 | ||
4860 | PARMS is an optional list of frame parameters which can be used to | |
4861 | change the tooltip's appearance. | |
4862 | ||
4863 | Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil | |
4864 | means use the default timeout of 5 seconds. | |
4865 | ||
4866 | If the list of frame parameters PARAMS contains a `left' parameters, | |
4867 | the tooltip is displayed at that x-position. Otherwise it is | |
4868 | displayed at the mouse position, with offset DX added (default is 5 if | |
4869 | DX isn't specified). Likewise for the y-position; if a `top' frame | |
4870 | parameter is specified, it determines the y-position of the tooltip | |
4871 | window, otherwise it is displayed at the mouse position, with offset | |
4872 | DY added (default is -10). | |
4873 | ||
4874 | A tooltip's maximum size is specified by `x-max-tooltip-size'. | |
7ee72033 MB |
4875 | Text larger than the specified size is clipped. */) |
4876 | (string, frame, parms, timeout, dx, dy) | |
0634ce98 | 4877 | Lisp_Object string, frame, parms, timeout, dx, dy; |
333b20bb GM |
4878 | { |
4879 | struct frame *f; | |
4880 | struct window *w; | |
06d62053 | 4881 | int root_x, root_y; |
333b20bb GM |
4882 | struct buffer *old_buffer; |
4883 | struct text_pos pos; | |
4884 | int i, width, height; | |
393f2d14 | 4885 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
333b20bb | 4886 | int old_windows_or_buffers_changed = windows_or_buffers_changed; |
331379bf | 4887 | int count = SPECPDL_INDEX (); |
177c0ea7 | 4888 | |
333b20bb GM |
4889 | specbind (Qinhibit_redisplay, Qt); |
4890 | ||
393f2d14 | 4891 | GCPRO4 (string, parms, frame, timeout); |
333b20bb | 4892 | |
b7826503 | 4893 | CHECK_STRING (string); |
333b20bb GM |
4894 | f = check_x_frame (frame); |
4895 | if (NILP (timeout)) | |
4896 | timeout = make_number (5); | |
4897 | else | |
b7826503 | 4898 | CHECK_NATNUM (timeout); |
177c0ea7 | 4899 | |
0634ce98 GM |
4900 | if (NILP (dx)) |
4901 | dx = make_number (5); | |
4902 | else | |
b7826503 | 4903 | CHECK_NUMBER (dx); |
177c0ea7 | 4904 | |
0634ce98 | 4905 | if (NILP (dy)) |
12c67a7f | 4906 | dy = make_number (-10); |
0634ce98 | 4907 | else |
b7826503 | 4908 | CHECK_NUMBER (dy); |
333b20bb | 4909 | |
06d62053 GM |
4910 | if (NILP (last_show_tip_args)) |
4911 | last_show_tip_args = Fmake_vector (make_number (3), Qnil); | |
4912 | ||
4913 | if (!NILP (tip_frame)) | |
4914 | { | |
4915 | Lisp_Object last_string = AREF (last_show_tip_args, 0); | |
4916 | Lisp_Object last_frame = AREF (last_show_tip_args, 1); | |
4917 | Lisp_Object last_parms = AREF (last_show_tip_args, 2); | |
4918 | ||
4919 | if (EQ (frame, last_frame) | |
4920 | && !NILP (Fequal (last_string, string)) | |
4921 | && !NILP (Fequal (last_parms, parms))) | |
4922 | { | |
4923 | struct frame *f = XFRAME (tip_frame); | |
177c0ea7 | 4924 | |
06d62053 GM |
4925 | /* Only DX and DY have changed. */ |
4926 | if (!NILP (tip_timer)) | |
ae782866 GM |
4927 | { |
4928 | Lisp_Object timer = tip_timer; | |
4929 | tip_timer = Qnil; | |
4930 | call1 (Qcancel_timer, timer); | |
4931 | } | |
06d62053 GM |
4932 | |
4933 | BLOCK_INPUT; | |
be786000 KS |
4934 | compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f), |
4935 | FRAME_PIXEL_HEIGHT (f), &root_x, &root_y); | |
06d62053 | 4936 | XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
ab452f99 | 4937 | root_x, root_y); |
06d62053 GM |
4938 | UNBLOCK_INPUT; |
4939 | goto start_timer; | |
4940 | } | |
4941 | } | |
4942 | ||
333b20bb GM |
4943 | /* Hide a previous tip, if any. */ |
4944 | Fx_hide_tip (); | |
4945 | ||
06d62053 GM |
4946 | ASET (last_show_tip_args, 0, string); |
4947 | ASET (last_show_tip_args, 1, frame); | |
4948 | ASET (last_show_tip_args, 2, parms); | |
4949 | ||
333b20bb GM |
4950 | /* Add default values to frame parameters. */ |
4951 | if (NILP (Fassq (Qname, parms))) | |
4952 | parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms); | |
4953 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
4954 | parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms); | |
4955 | if (NILP (Fassq (Qborder_width, parms))) | |
4956 | parms = Fcons (Fcons (Qborder_width, make_number (1)), parms); | |
4957 | if (NILP (Fassq (Qborder_color, parms))) | |
4958 | parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms); | |
4959 | if (NILP (Fassq (Qbackground_color, parms))) | |
4960 | parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")), | |
4961 | parms); | |
4962 | ||
4963 | /* Create a frame for the tooltip, and record it in the global | |
4964 | variable tip_frame. */ | |
275841bf | 4965 | frame = x_create_tip_frame (FRAME_X_DISPLAY_INFO (f), parms, string); |
44b5a125 | 4966 | f = XFRAME (frame); |
333b20bb | 4967 | |
d63931a2 | 4968 | /* Set up the frame's root window. */ |
333b20bb | 4969 | w = XWINDOW (FRAME_ROOT_WINDOW (f)); |
be786000 | 4970 | w->left_col = w->top_line = make_number (0); |
177c0ea7 | 4971 | |
d63931a2 GM |
4972 | if (CONSP (Vx_max_tooltip_size) |
4973 | && INTEGERP (XCAR (Vx_max_tooltip_size)) | |
4974 | && XINT (XCAR (Vx_max_tooltip_size)) > 0 | |
4975 | && INTEGERP (XCDR (Vx_max_tooltip_size)) | |
4976 | && XINT (XCDR (Vx_max_tooltip_size)) > 0) | |
4977 | { | |
be786000 KS |
4978 | w->total_cols = XCAR (Vx_max_tooltip_size); |
4979 | w->total_lines = XCDR (Vx_max_tooltip_size); | |
d63931a2 GM |
4980 | } |
4981 | else | |
4982 | { | |
be786000 KS |
4983 | w->total_cols = make_number (80); |
4984 | w->total_lines = make_number (40); | |
d63931a2 | 4985 | } |
177c0ea7 | 4986 | |
be786000 | 4987 | FRAME_TOTAL_COLS (f) = XINT (w->total_cols); |
333b20bb GM |
4988 | adjust_glyphs (f); |
4989 | w->pseudo_window_p = 1; | |
4990 | ||
4991 | /* Display the tooltip text in a temporary buffer. */ | |
333b20bb | 4992 | old_buffer = current_buffer; |
275841bf | 4993 | set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer)); |
d63931a2 | 4994 | current_buffer->truncate_lines = Qnil; |
333b20bb GM |
4995 | clear_glyph_matrix (w->desired_matrix); |
4996 | clear_glyph_matrix (w->current_matrix); | |
4997 | SET_TEXT_POS (pos, BEGV, BEGV_BYTE); | |
4998 | try_window (FRAME_ROOT_WINDOW (f), pos); | |
4999 | ||
5000 | /* Compute width and height of the tooltip. */ | |
5001 | width = height = 0; | |
5002 | for (i = 0; i < w->desired_matrix->nrows; ++i) | |
5003 | { | |
5004 | struct glyph_row *row = &w->desired_matrix->rows[i]; | |
5005 | struct glyph *last; | |
5006 | int row_width; | |
5007 | ||
5008 | /* Stop at the first empty row at the end. */ | |
5009 | if (!row->enabled_p || !row->displays_text_p) | |
5010 | break; | |
5011 | ||
d7bf0342 GM |
5012 | /* Let the row go over the full width of the frame. */ |
5013 | row->full_width_p = 1; | |
333b20bb | 5014 | |
e3130015 | 5015 | /* There's a glyph at the end of rows that is used to place |
333b20bb GM |
5016 | the cursor there. Don't include the width of this glyph. */ |
5017 | if (row->used[TEXT_AREA]) | |
5018 | { | |
5019 | last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1]; | |
5020 | row_width = row->pixel_width - last->pixel_width; | |
5021 | } | |
5022 | else | |
5023 | row_width = row->pixel_width; | |
177c0ea7 | 5024 | |
333b20bb GM |
5025 | height += row->height; |
5026 | width = max (width, row_width); | |
5027 | } | |
5028 | ||
5029 | /* Add the frame's internal border to the width and height the X | |
5030 | window should have. */ | |
5031 | height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
5032 | width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
5033 | ||
5034 | /* Move the tooltip window where the mouse pointer is. Resize and | |
5035 | show it. */ | |
ab452f99 | 5036 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); |
0634ce98 | 5037 | |
0634ce98 | 5038 | BLOCK_INPUT; |
333b20bb | 5039 | XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
ab452f99 | 5040 | root_x, root_y, width, height); |
333b20bb GM |
5041 | XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
5042 | UNBLOCK_INPUT; | |
177c0ea7 | 5043 | |
333b20bb GM |
5044 | /* Draw into the window. */ |
5045 | w->must_be_updated_p = 1; | |
5046 | update_single_window (w, 1); | |
5047 | ||
5048 | /* Restore original current buffer. */ | |
5049 | set_buffer_internal_1 (old_buffer); | |
5050 | windows_or_buffers_changed = old_windows_or_buffers_changed; | |
5051 | ||
06d62053 | 5052 | start_timer: |
333b20bb GM |
5053 | /* Let the tip disappear after timeout seconds. */ |
5054 | tip_timer = call3 (intern ("run-at-time"), timeout, Qnil, | |
5055 | intern ("x-hide-tip")); | |
a744a2ec DL |
5056 | |
5057 | UNGCPRO; | |
333b20bb GM |
5058 | return unbind_to (count, Qnil); |
5059 | } | |
5060 | ||
5061 | ||
5062 | DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0, | |
7ee72033 MB |
5063 | doc: /* Hide the current tooltip window, if there is any. |
5064 | Value is t if tooltip was open, nil otherwise. */) | |
5065 | () | |
333b20bb | 5066 | { |
44b5a125 | 5067 | int count; |
c0006262 GM |
5068 | Lisp_Object deleted, frame, timer; |
5069 | struct gcpro gcpro1, gcpro2; | |
44b5a125 GM |
5070 | |
5071 | /* Return quickly if nothing to do. */ | |
c0006262 | 5072 | if (NILP (tip_timer) && NILP (tip_frame)) |
44b5a125 | 5073 | return Qnil; |
177c0ea7 | 5074 | |
c0006262 GM |
5075 | frame = tip_frame; |
5076 | timer = tip_timer; | |
5077 | GCPRO2 (frame, timer); | |
5078 | tip_frame = tip_timer = deleted = Qnil; | |
177c0ea7 | 5079 | |
331379bf | 5080 | count = SPECPDL_INDEX (); |
333b20bb | 5081 | specbind (Qinhibit_redisplay, Qt); |
44b5a125 | 5082 | specbind (Qinhibit_quit, Qt); |
177c0ea7 | 5083 | |
c0006262 | 5084 | if (!NILP (timer)) |
ae782866 | 5085 | call1 (Qcancel_timer, timer); |
333b20bb | 5086 | |
c0006262 | 5087 | if (FRAMEP (frame)) |
333b20bb | 5088 | { |
44b5a125 GM |
5089 | Fdelete_frame (frame, Qnil); |
5090 | deleted = Qt; | |
f6c44811 GM |
5091 | |
5092 | #ifdef USE_LUCID | |
5093 | /* Bloodcurdling hack alert: The Lucid menu bar widget's | |
5094 | redisplay procedure is not called when a tip frame over menu | |
5095 | items is unmapped. Redisplay the menu manually... */ | |
5096 | { | |
5097 | struct frame *f = SELECTED_FRAME (); | |
5098 | Widget w = f->output_data.x->menubar_widget; | |
5099 | extern void xlwmenu_redisplay P_ ((Widget)); | |
9180dc8c | 5100 | |
f6c44811 | 5101 | if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen) |
dbc64aa7 | 5102 | && w != NULL) |
f6c44811 GM |
5103 | { |
5104 | BLOCK_INPUT; | |
5105 | xlwmenu_redisplay (w); | |
5106 | UNBLOCK_INPUT; | |
5107 | } | |
5108 | } | |
5109 | #endif /* USE_LUCID */ | |
333b20bb GM |
5110 | } |
5111 | ||
c0006262 | 5112 | UNGCPRO; |
44b5a125 | 5113 | return unbind_to (count, deleted); |
333b20bb GM |
5114 | } |
5115 | ||
5116 | ||
5117 | \f | |
5118 | /*********************************************************************** | |
5119 | File selection dialog | |
5120 | ***********************************************************************/ | |
5121 | ||
5122 | #ifdef USE_MOTIF | |
5123 | ||
5124 | /* Callback for "OK" and "Cancel" on file selection dialog. */ | |
5125 | ||
5126 | static void | |
5127 | file_dialog_cb (widget, client_data, call_data) | |
5128 | Widget widget; | |
5129 | XtPointer call_data, client_data; | |
5130 | { | |
5131 | int *result = (int *) client_data; | |
5132 | XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data; | |
5133 | *result = cb->reason; | |
5134 | } | |
5135 | ||
5136 | ||
a779d213 GM |
5137 | /* Callback for unmapping a file selection dialog. This is used to |
5138 | capture the case where a dialog is closed via a window manager's | |
5139 | closer button, for example. Using a XmNdestroyCallback didn't work | |
5140 | in this case. */ | |
5141 | ||
5142 | static void | |
5143 | file_dialog_unmap_cb (widget, client_data, call_data) | |
5144 | Widget widget; | |
5145 | XtPointer call_data, client_data; | |
5146 | { | |
5147 | int *result = (int *) client_data; | |
5148 | *result = XmCR_CANCEL; | |
5149 | } | |
5150 | ||
24ca7c5a JD |
5151 | static Lisp_Object |
5152 | clean_up_file_dialog (arg) | |
5153 | Lisp_Object arg; | |
5154 | { | |
5155 | struct Lisp_Save_Value *p = XSAVE_VALUE (arg); | |
5156 | Widget dialog = (Widget) p->pointer; | |
5157 | ||
5158 | /* Clean up. */ | |
5159 | BLOCK_INPUT; | |
5160 | XtUnmanageChild (dialog); | |
5161 | XtDestroyWidget (dialog); | |
5162 | x_menu_set_in_use (0); | |
5163 | UNBLOCK_INPUT; | |
5164 | ||
5165 | return Qnil; | |
5166 | } | |
5167 | ||
a779d213 | 5168 | |
f9d64bb3 | 5169 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
7ee72033 | 5170 | doc: /* Read file name, prompting with PROMPT in directory DIR. |
f9d64bb3 JD |
5171 | Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file |
5172 | selection box, if specified. If MUSTMATCH is non-nil, the returned file | |
5173 | or directory must exist. ONLY-DIR-P is ignored." */) | |
5174 | (prompt, dir, default_filename, mustmatch, only_dir_p) | |
5175 | Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p; | |
333b20bb GM |
5176 | { |
5177 | int result; | |
0fe92f72 | 5178 | struct frame *f = SELECTED_FRAME (); |
333b20bb | 5179 | Lisp_Object file = Qnil; |
f9d64bb3 | 5180 | Widget dialog, text, help; |
333b20bb GM |
5181 | Arg al[10]; |
5182 | int ac = 0; | |
5183 | extern XtAppContext Xt_app_con; | |
333b20bb | 5184 | XmString dir_xmstring, pattern_xmstring; |
65b21658 | 5185 | int count = SPECPDL_INDEX (); |
f9d64bb3 | 5186 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
333b20bb | 5187 | |
f9d64bb3 | 5188 | GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
24ca7c5a | 5189 | |
5ae53dcf | 5190 | if (popup_activated ()) |
24ca7c5a JD |
5191 | error ("Trying to use a menu from within a menu-entry"); |
5192 | ||
b7826503 PJ |
5193 | CHECK_STRING (prompt); |
5194 | CHECK_STRING (dir); | |
333b20bb GM |
5195 | |
5196 | /* Prevent redisplay. */ | |
5197 | specbind (Qinhibit_redisplay, Qt); | |
5198 | ||
5199 | BLOCK_INPUT; | |
5200 | ||
5201 | /* Create the dialog with PROMPT as title, using DIR as initial | |
5202 | directory and using "*" as pattern. */ | |
5203 | dir = Fexpand_file_name (dir, Qnil); | |
d5db4077 | 5204 | dir_xmstring = XmStringCreateLocalized (SDATA (dir)); |
333b20bb | 5205 | pattern_xmstring = XmStringCreateLocalized ("*"); |
177c0ea7 | 5206 | |
d5db4077 | 5207 | XtSetArg (al[ac], XmNtitle, SDATA (prompt)); ++ac; |
333b20bb GM |
5208 | XtSetArg (al[ac], XmNdirectory, dir_xmstring); ++ac; |
5209 | XtSetArg (al[ac], XmNpattern, pattern_xmstring); ++ac; | |
5210 | XtSetArg (al[ac], XmNresizePolicy, XmRESIZE_GROW); ++ac; | |
5211 | XtSetArg (al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ++ac; | |
5212 | dialog = XmCreateFileSelectionDialog (f->output_data.x->widget, | |
5213 | "fsb", al, ac); | |
5214 | XmStringFree (dir_xmstring); | |
5215 | XmStringFree (pattern_xmstring); | |
5216 | ||
5217 | /* Add callbacks for OK and Cancel. */ | |
5218 | XtAddCallback (dialog, XmNokCallback, file_dialog_cb, | |
5219 | (XtPointer) &result); | |
5220 | XtAddCallback (dialog, XmNcancelCallback, file_dialog_cb, | |
5221 | (XtPointer) &result); | |
a779d213 GM |
5222 | XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb, |
5223 | (XtPointer) &result); | |
333b20bb | 5224 | |
f9d64bb3 | 5225 | /* Remove the help button since we can't display help. */ |
333b20bb | 5226 | help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON); |
f9d64bb3 | 5227 | XtUnmanageChild (help); |
333b20bb | 5228 | |
177c0ea7 | 5229 | /* Mark OK button as default. */ |
333b20bb GM |
5230 | XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON), |
5231 | XmNshowAsDefault, True, NULL); | |
5232 | ||
5233 | /* If MUSTMATCH is non-nil, disable the file entry field of the | |
5234 | dialog, so that the user must select a file from the files list | |
5235 | box. We can't remove it because we wouldn't have a way to get at | |
5236 | the result file name, then. */ | |
5237 | text = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT); | |
5238 | if (!NILP (mustmatch)) | |
5239 | { | |
5240 | Widget label; | |
5241 | label = XmFileSelectionBoxGetChild (dialog, XmDIALOG_SELECTION_LABEL); | |
5242 | XtSetSensitive (text, False); | |
5243 | XtSetSensitive (label, False); | |
5244 | } | |
5245 | ||
5246 | /* Manage the dialog, so that list boxes get filled. */ | |
5247 | XtManageChild (dialog); | |
5248 | ||
333b20bb GM |
5249 | if (STRINGP (default_filename)) |
5250 | { | |
5251 | XmString default_xmstring; | |
f9d64bb3 JD |
5252 | Widget wtext = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT); |
5253 | Widget list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST); | |
333b20bb | 5254 | |
f9d64bb3 JD |
5255 | XmTextPosition last_pos = XmTextFieldGetLastPosition (wtext); |
5256 | XmTextFieldReplace (wtext, 0, last_pos, | |
5257 | (SDATA (Ffile_name_nondirectory (default_filename)))); | |
333b20bb | 5258 | |
f9d64bb3 JD |
5259 | /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME |
5260 | must include the path for this to work. */ | |
5261 | ||
5262 | default_xmstring = XmStringCreateLocalized (SDATA (default_filename)); | |
333b20bb | 5263 | |
f9d64bb3 JD |
5264 | if (XmListItemExists (list, default_xmstring)) |
5265 | { | |
5266 | int item_pos = XmListItemPos (list, default_xmstring); | |
5267 | /* Select the item and scroll it into view. */ | |
5268 | XmListSelectPos (list, item_pos, True); | |
5269 | XmListSetPos (list, item_pos); | |
5270 | } | |
333b20bb | 5271 | |
f9d64bb3 | 5272 | XmStringFree (default_xmstring); |
333b20bb GM |
5273 | } |
5274 | ||
24ca7c5a JD |
5275 | record_unwind_protect (clean_up_file_dialog, make_save_value (dialog, 0)); |
5276 | ||
bf338245 | 5277 | /* Process events until the user presses Cancel or OK. */ |
5ae53dcf | 5278 | x_menu_set_in_use (1); |
03100098 | 5279 | result = 0; |
a779d213 | 5280 | while (result == 0) |
563b384d | 5281 | { |
bf338245 | 5282 | XEvent event; |
24ca7c5a | 5283 | x_menu_wait_for_event (0); |
bf338245 | 5284 | XtAppNextEvent (Xt_app_con, &event); |
9f6fcdc5 JD |
5285 | if (event.type == KeyPress |
5286 | && FRAME_X_DISPLAY (f) == event.xkey.display) | |
5287 | { | |
5288 | KeySym keysym = XLookupKeysym (&event.xkey, 0); | |
5289 | ||
5290 | /* Pop down on C-g. */ | |
5291 | if (keysym == XK_g && (event.xkey.state & ControlMask) != 0) | |
5292 | XtUnmanageChild (dialog); | |
5293 | } | |
5294 | ||
24ca7c5a | 5295 | (void) x_dispatch_event (&event, FRAME_X_DISPLAY (f)); |
563b384d | 5296 | } |
03100098 | 5297 | |
333b20bb GM |
5298 | /* Get the result. */ |
5299 | if (result == XmCR_OK) | |
5300 | { | |
5301 | XmString text; | |
5302 | String data; | |
177c0ea7 | 5303 | |
d1670063 | 5304 | XtVaGetValues (dialog, XmNtextString, &text, NULL); |
333b20bb GM |
5305 | XmStringGetLtoR (text, XmFONTLIST_DEFAULT_TAG, &data); |
5306 | XmStringFree (text); | |
5307 | file = build_string (data); | |
5308 | XtFree (data); | |
5309 | } | |
5310 | else | |
5311 | file = Qnil; | |
5312 | ||
333b20bb GM |
5313 | UNBLOCK_INPUT; |
5314 | UNGCPRO; | |
5315 | ||
5316 | /* Make "Cancel" equivalent to C-g. */ | |
5317 | if (NILP (file)) | |
5318 | Fsignal (Qquit, Qnil); | |
177c0ea7 | 5319 | |
333b20bb GM |
5320 | return unbind_to (count, file); |
5321 | } | |
5322 | ||
5323 | #endif /* USE_MOTIF */ | |
5324 | ||
488dd4c4 JD |
5325 | #ifdef USE_GTK |
5326 | ||
24ca7c5a JD |
5327 | static Lisp_Object |
5328 | clean_up_dialog (arg) | |
5329 | Lisp_Object arg; | |
5330 | { | |
5331 | x_menu_set_in_use (0); | |
5332 | ||
5333 | return Qnil; | |
5334 | } | |
5335 | ||
f9d64bb3 JD |
5336 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
5337 | doc: /* Read file name, prompting with PROMPT in directory DIR. | |
5338 | Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file | |
5339 | selection box, if specified. If MUSTMATCH is non-nil, the returned file | |
5340 | or directory must exist. If ONLY-DIR-P is non-nil, the user can only select | |
5341 | directories. */) | |
5342 | (prompt, dir, default_filename, mustmatch, only_dir_p) | |
5343 | Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p; | |
488dd4c4 JD |
5344 | { |
5345 | FRAME_PTR f = SELECTED_FRAME (); | |
5346 | char *fn; | |
5347 | Lisp_Object file = Qnil; | |
24ca7c5a | 5348 | int count = SPECPDL_INDEX (); |
f9d64bb3 | 5349 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
488dd4c4 | 5350 | char *cdef_file; |
177c0ea7 | 5351 | |
f9d64bb3 | 5352 | GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
24ca7c5a | 5353 | |
5ae53dcf | 5354 | if (popup_activated ()) |
24ca7c5a JD |
5355 | error ("Trying to use a menu from within a menu-entry"); |
5356 | ||
488dd4c4 JD |
5357 | CHECK_STRING (prompt); |
5358 | CHECK_STRING (dir); | |
5359 | ||
5360 | /* Prevent redisplay. */ | |
5361 | specbind (Qinhibit_redisplay, Qt); | |
24ca7c5a | 5362 | record_unwind_protect (clean_up_dialog, Qnil); |
488dd4c4 JD |
5363 | |
5364 | BLOCK_INPUT; | |
5365 | ||
5366 | if (STRINGP (default_filename)) | |
5367 | cdef_file = SDATA (default_filename); | |
5368 | else | |
5369 | cdef_file = SDATA (dir); | |
5370 | ||
f9d64bb3 JD |
5371 | fn = xg_get_file_name (f, SDATA (prompt), cdef_file, |
5372 | ! NILP (mustmatch), | |
5373 | ! NILP (only_dir_p)); | |
177c0ea7 | 5374 | |
488dd4c4 JD |
5375 | if (fn) |
5376 | { | |
5377 | file = build_string (fn); | |
5378 | xfree (fn); | |
5379 | } | |
5380 | ||
5381 | UNBLOCK_INPUT; | |
5382 | UNGCPRO; | |
5383 | ||
5384 | /* Make "Cancel" equivalent to C-g. */ | |
5385 | if (NILP (file)) | |
5386 | Fsignal (Qquit, Qnil); | |
177c0ea7 | 5387 | |
488dd4c4 JD |
5388 | return unbind_to (count, file); |
5389 | } | |
5390 | ||
5391 | #endif /* USE_GTK */ | |
333b20bb GM |
5392 | |
5393 | \f | |
82bab41c GM |
5394 | /*********************************************************************** |
5395 | Keyboard | |
5396 | ***********************************************************************/ | |
5397 | ||
5398 | #ifdef HAVE_XKBGETKEYBOARD | |
5399 | #include <X11/XKBlib.h> | |
5400 | #include <X11/keysym.h> | |
5401 | #endif | |
5402 | ||
5403 | DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p, | |
5404 | Sx_backspace_delete_keys_p, 0, 1, 0, | |
7ee72033 | 5405 | doc: /* Check if both Backspace and Delete keys are on the keyboard of FRAME. |
c061c855 GM |
5406 | FRAME nil means use the selected frame. |
5407 | Value is t if we know that both keys are present, and are mapped to the | |
7ee72033 MB |
5408 | usual X keysyms. */) |
5409 | (frame) | |
82bab41c GM |
5410 | Lisp_Object frame; |
5411 | { | |
5412 | #ifdef HAVE_XKBGETKEYBOARD | |
5413 | XkbDescPtr kb; | |
5414 | struct frame *f = check_x_frame (frame); | |
5415 | Display *dpy = FRAME_X_DISPLAY (f); | |
5416 | Lisp_Object have_keys; | |
46f6a258 | 5417 | int major, minor, op, event, error; |
82bab41c GM |
5418 | |
5419 | BLOCK_INPUT; | |
46f6a258 GM |
5420 | |
5421 | /* Check library version in case we're dynamically linked. */ | |
5422 | major = XkbMajorVersion; | |
5423 | minor = XkbMinorVersion; | |
5424 | if (!XkbLibraryVersion (&major, &minor)) | |
c1efd260 GM |
5425 | { |
5426 | UNBLOCK_INPUT; | |
5427 | return Qnil; | |
5428 | } | |
46f6a258 GM |
5429 | |
5430 | /* Check that the server supports XKB. */ | |
5431 | major = XkbMajorVersion; | |
5432 | minor = XkbMinorVersion; | |
5433 | if (!XkbQueryExtension (dpy, &op, &event, &error, &major, &minor)) | |
c1efd260 GM |
5434 | { |
5435 | UNBLOCK_INPUT; | |
5436 | return Qnil; | |
5437 | } | |
177c0ea7 | 5438 | |
46f6a258 | 5439 | have_keys = Qnil; |
c1efd260 | 5440 | kb = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd); |
82bab41c GM |
5441 | if (kb) |
5442 | { | |
5443 | int delete_keycode = 0, backspace_keycode = 0, i; | |
c1efd260 GM |
5444 | |
5445 | if (XkbGetNames (dpy, XkbAllNamesMask, kb) == Success) | |
82bab41c | 5446 | { |
c1efd260 GM |
5447 | for (i = kb->min_key_code; |
5448 | (i < kb->max_key_code | |
5449 | && (delete_keycode == 0 || backspace_keycode == 0)); | |
5450 | ++i) | |
5451 | { | |
d63931a2 GM |
5452 | /* The XKB symbolic key names can be seen most easily in |
5453 | the PS file generated by `xkbprint -label name | |
5454 | $DISPLAY'. */ | |
c1efd260 GM |
5455 | if (bcmp ("DELE", kb->names->keys[i].name, 4) == 0) |
5456 | delete_keycode = i; | |
5457 | else if (bcmp ("BKSP", kb->names->keys[i].name, 4) == 0) | |
5458 | backspace_keycode = i; | |
5459 | } | |
5460 | ||
5461 | XkbFreeNames (kb, 0, True); | |
82bab41c GM |
5462 | } |
5463 | ||
c1efd260 | 5464 | XkbFreeClientMap (kb, 0, True); |
177c0ea7 | 5465 | |
82bab41c GM |
5466 | if (delete_keycode |
5467 | && backspace_keycode | |
5468 | && XKeysymToKeycode (dpy, XK_Delete) == delete_keycode | |
5469 | && XKeysymToKeycode (dpy, XK_BackSpace) == backspace_keycode) | |
5470 | have_keys = Qt; | |
5471 | } | |
5472 | UNBLOCK_INPUT; | |
5473 | return have_keys; | |
5474 | #else /* not HAVE_XKBGETKEYBOARD */ | |
5475 | return Qnil; | |
5476 | #endif /* not HAVE_XKBGETKEYBOARD */ | |
5477 | } | |
5478 | ||
5479 | ||
5480 | \f | |
333b20bb GM |
5481 | /*********************************************************************** |
5482 | Initialization | |
5483 | ***********************************************************************/ | |
5484 | ||
4dacadcc | 5485 | /* Keep this list in the same order as frame_parms in frame.c. |
7c0d3ed8 KS |
5486 | Use 0 for unsupported frame parameters. */ |
5487 | ||
5488 | frame_parm_handler x_frame_parm_handlers[] = | |
5489 | { | |
5490 | x_set_autoraise, | |
5491 | x_set_autolower, | |
5492 | x_set_background_color, | |
5493 | x_set_border_color, | |
5494 | x_set_border_width, | |
5495 | x_set_cursor_color, | |
5496 | x_set_cursor_type, | |
5497 | x_set_font, | |
5498 | x_set_foreground_color, | |
5499 | x_set_icon_name, | |
5500 | x_set_icon_type, | |
5501 | x_set_internal_border_width, | |
5502 | x_set_menu_bar_lines, | |
5503 | x_set_mouse_color, | |
5504 | x_explicitly_set_name, | |
5505 | x_set_scroll_bar_width, | |
5506 | x_set_title, | |
5507 | x_set_unsplittable, | |
5508 | x_set_vertical_scroll_bars, | |
5509 | x_set_visibility, | |
5510 | x_set_tool_bar_lines, | |
5511 | x_set_scroll_bar_foreground, | |
5512 | x_set_scroll_bar_background, | |
5513 | x_set_screen_gamma, | |
5514 | x_set_line_spacing, | |
5515 | x_set_fringe_width, | |
5516 | x_set_fringe_width, | |
5517 | x_set_wait_for_wm, | |
5518 | x_set_fullscreen, | |
5519 | }; | |
5520 | ||
333b20bb GM |
5521 | void |
5522 | syms_of_xfns () | |
5523 | { | |
5524 | /* This is zero if not using X windows. */ | |
5525 | x_in_use = 0; | |
5526 | ||
5527 | /* The section below is built by the lisp expression at the top of the file, | |
5528 | just above where these variables are declared. */ | |
5529 | /*&&& init symbols here &&&*/ | |
baaed68e JB |
5530 | Qnone = intern ("none"); |
5531 | staticpro (&Qnone); | |
8af1d7ca JB |
5532 | Qsuppress_icon = intern ("suppress-icon"); |
5533 | staticpro (&Qsuppress_icon); | |
01f1ba30 | 5534 | Qundefined_color = intern ("undefined-color"); |
f9942c9e | 5535 | staticpro (&Qundefined_color); |
96db09e4 KH |
5536 | Qcompound_text = intern ("compound-text"); |
5537 | staticpro (&Qcompound_text); | |
ae782866 GM |
5538 | Qcancel_timer = intern ("cancel-timer"); |
5539 | staticpro (&Qcancel_timer); | |
f9942c9e JB |
5540 | /* This is the end of symbol initialization. */ |
5541 | ||
58cad5ed KH |
5542 | /* Text property `display' should be nonsticky by default. */ |
5543 | Vtext_property_default_nonsticky | |
5544 | = Fcons (Fcons (Qdisplay, Qt), Vtext_property_default_nonsticky); | |
5545 | ||
5546 | ||
01f1ba30 JB |
5547 | Fput (Qundefined_color, Qerror_conditions, |
5548 | Fcons (Qundefined_color, Fcons (Qerror, Qnil))); | |
5549 | Fput (Qundefined_color, Qerror_message, | |
5550 | build_string ("Undefined color")); | |
5551 | ||
7ee72033 MB |
5552 | DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape, |
5553 | doc: /* The shape of the pointer when over text. | |
c061c855 GM |
5554 | Changing the value does not affect existing frames |
5555 | unless you set the mouse color. */); | |
01f1ba30 JB |
5556 | Vx_pointer_shape = Qnil; |
5557 | ||
ca0ecbf5 | 5558 | #if 0 /* This doesn't really do anything. */ |
7ee72033 MB |
5559 | DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape, |
5560 | doc: /* The shape of the pointer when not over text. | |
c061c855 GM |
5561 | This variable takes effect when you create a new frame |
5562 | or when you set the mouse color. */); | |
af01ef26 | 5563 | #endif |
01f1ba30 JB |
5564 | Vx_nontext_pointer_shape = Qnil; |
5565 | ||
7ee72033 MB |
5566 | DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape, |
5567 | doc: /* The shape of the pointer when Emacs is busy. | |
c061c855 GM |
5568 | This variable takes effect when you create a new frame |
5569 | or when you set the mouse color. */); | |
0af913d7 | 5570 | Vx_hourglass_pointer_shape = Qnil; |
333b20bb | 5571 | |
7ee72033 MB |
5572 | DEFVAR_BOOL ("display-hourglass", &display_hourglass_p, |
5573 | doc: /* Non-zero means Emacs displays an hourglass pointer on window systems. */); | |
0af913d7 | 5574 | display_hourglass_p = 1; |
177c0ea7 | 5575 | |
7ee72033 MB |
5576 | DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay, |
5577 | doc: /* *Seconds to wait before displaying an hourglass pointer. | |
c061c855 | 5578 | Value must be an integer or float. */); |
0af913d7 | 5579 | Vhourglass_delay = make_number (DEFAULT_HOURGLASS_DELAY); |
4ae9a85e | 5580 | |
ca0ecbf5 | 5581 | #if 0 /* This doesn't really do anything. */ |
7ee72033 MB |
5582 | DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape, |
5583 | doc: /* The shape of the pointer when over the mode line. | |
c061c855 GM |
5584 | This variable takes effect when you create a new frame |
5585 | or when you set the mouse color. */); | |
af01ef26 | 5586 | #endif |
01f1ba30 JB |
5587 | Vx_mode_pointer_shape = Qnil; |
5588 | ||
d3b06468 | 5589 | DEFVAR_LISP ("x-sensitive-text-pointer-shape", |
7ee72033 MB |
5590 | &Vx_sensitive_text_pointer_shape, |
5591 | doc: /* The shape of the pointer when over mouse-sensitive text. | |
c061c855 GM |
5592 | This variable takes effect when you create a new frame |
5593 | or when you set the mouse color. */); | |
ca0ecbf5 | 5594 | Vx_sensitive_text_pointer_shape = Qnil; |
95f80c78 | 5595 | |
8fb4ec9c | 5596 | DEFVAR_LISP ("x-window-horizontal-drag-cursor", |
7ee72033 MB |
5597 | &Vx_window_horizontal_drag_shape, |
5598 | doc: /* Pointer shape to use for indicating a window can be dragged horizontally. | |
c061c855 GM |
5599 | This variable takes effect when you create a new frame |
5600 | or when you set the mouse color. */); | |
8fb4ec9c GM |
5601 | Vx_window_horizontal_drag_shape = Qnil; |
5602 | ||
7ee72033 MB |
5603 | DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel, |
5604 | doc: /* A string indicating the foreground color of the cursor box. */); | |
01f1ba30 JB |
5605 | Vx_cursor_fore_pixel = Qnil; |
5606 | ||
7ee72033 MB |
5607 | DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size, |
5608 | doc: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS). | |
c061c855 | 5609 | Text larger than this is clipped. */); |
d63931a2 | 5610 | Vx_max_tooltip_size = Fcons (make_number (80), make_number (40)); |
177c0ea7 | 5611 | |
7ee72033 MB |
5612 | DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager, |
5613 | doc: /* Non-nil if no X window manager is in use. | |
c061c855 GM |
5614 | Emacs doesn't try to figure this out; this is always nil |
5615 | unless you set it to something else. */); | |
2d38195d RS |
5616 | /* We don't have any way to find this out, so set it to nil |
5617 | and maybe the user would like to set it to t. */ | |
5618 | Vx_no_window_manager = Qnil; | |
1d3dac41 | 5619 | |
942ea06d | 5620 | DEFVAR_LISP ("x-pixel-size-width-font-regexp", |
7ee72033 MB |
5621 | &Vx_pixel_size_width_font_regexp, |
5622 | doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. | |
c061c855 GM |
5623 | |
5624 | Since Emacs gets width of a font matching with this regexp from | |
5625 | PIXEL_SIZE field of the name, font finding mechanism gets faster for | |
5626 | such a font. This is especially effective for such large fonts as | |
5627 | Chinese, Japanese, and Korean. */); | |
942ea06d KH |
5628 | Vx_pixel_size_width_font_regexp = Qnil; |
5629 | ||
255e4140 JD |
5630 | /* This is not ifdef:ed, so other builds than GTK can customize it. */ |
5631 | DEFVAR_BOOL ("x-use-old-gtk-file-dialog", &x_use_old_gtk_file_dialog, | |
5632 | doc: /* *Non-nil means prompt with the old GTK file selection dialog. | |
5633 | If nil or if the file selection dialog is not available, the new GTK file | |
5634 | chooser is used instead. To turn off all file dialogs set the | |
5635 | variable `use-file-dialog'. */); | |
5636 | x_use_old_gtk_file_dialog = 0; | |
5637 | ||
1d3dac41 | 5638 | #ifdef USE_X_TOOLKIT |
6f3f6a8d | 5639 | Fprovide (intern ("x-toolkit"), Qnil); |
5b827abb | 5640 | #ifdef USE_MOTIF |
6f3f6a8d | 5641 | Fprovide (intern ("motif"), Qnil); |
fc2cdd9a | 5642 | |
7ee72033 MB |
5643 | DEFVAR_LISP ("motif-version-string", &Vmotif_version_string, |
5644 | doc: /* Version info for LessTif/Motif. */); | |
fc2cdd9a GM |
5645 | Vmotif_version_string = build_string (XmVERSION_STRING); |
5646 | #endif /* USE_MOTIF */ | |
5647 | #endif /* USE_X_TOOLKIT */ | |
01f1ba30 | 5648 | |
8a16bd4f | 5649 | #ifdef USE_GTK |
1ec2a572 JD |
5650 | /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it |
5651 | is not an X toolkit in that sense (USE_X_TOOLKIT is not defined). | |
5652 | But for a user it is a toolkit for X, and indeed, configure | |
5653 | accepts --with-x-toolkit=gtk. */ | |
5654 | Fprovide (intern ("x-toolkit"), Qnil); | |
8a16bd4f LK |
5655 | Fprovide (intern ("gtk"), Qnil); |
5656 | ||
5657 | DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string, | |
5658 | doc: /* Version info for GTK+. */); | |
5659 | { | |
5660 | char gtk_version[40]; | |
5661 | g_snprintf (gtk_version, sizeof (gtk_version), "%u.%u.%u", | |
5662 | GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION); | |
5663 | Vgtk_version_string = build_string (gtk_version); | |
5664 | } | |
5665 | #endif /* USE_GTK */ | |
5666 | ||
333b20bb GM |
5667 | /* X window properties. */ |
5668 | defsubr (&Sx_change_window_property); | |
5669 | defsubr (&Sx_delete_window_property); | |
5670 | defsubr (&Sx_window_property); | |
5671 | ||
2d764c78 | 5672 | defsubr (&Sxw_display_color_p); |
d0c9d219 | 5673 | defsubr (&Sx_display_grayscale_p); |
2d764c78 EZ |
5674 | defsubr (&Sxw_color_defined_p); |
5675 | defsubr (&Sxw_color_values); | |
9d317b2c | 5676 | defsubr (&Sx_server_max_request_size); |
41beb8fc RS |
5677 | defsubr (&Sx_server_vendor); |
5678 | defsubr (&Sx_server_version); | |
5679 | defsubr (&Sx_display_pixel_width); | |
5680 | defsubr (&Sx_display_pixel_height); | |
5681 | defsubr (&Sx_display_mm_width); | |
5682 | defsubr (&Sx_display_mm_height); | |
5683 | defsubr (&Sx_display_screens); | |
5684 | defsubr (&Sx_display_planes); | |
5685 | defsubr (&Sx_display_color_cells); | |
5686 | defsubr (&Sx_display_visual_class); | |
5687 | defsubr (&Sx_display_backing_store); | |
5688 | defsubr (&Sx_display_save_under); | |
f676886a | 5689 | defsubr (&Sx_create_frame); |
01f1ba30 | 5690 | defsubr (&Sx_open_connection); |
08a90d6a RS |
5691 | defsubr (&Sx_close_connection); |
5692 | defsubr (&Sx_display_list); | |
01f1ba30 | 5693 | defsubr (&Sx_synchronize); |
3decc1e7 | 5694 | defsubr (&Sx_focus_frame); |
82bab41c | 5695 | defsubr (&Sx_backspace_delete_keys_p); |
177c0ea7 | 5696 | |
942ea06d KH |
5697 | /* Setting callback functions for fontset handler. */ |
5698 | get_font_info_func = x_get_font_info; | |
333b20bb GM |
5699 | |
5700 | #if 0 /* This function pointer doesn't seem to be used anywhere. | |
5701 | And the pointer assigned has the wrong type, anyway. */ | |
942ea06d | 5702 | list_fonts_func = x_list_fonts; |
333b20bb | 5703 | #endif |
177c0ea7 | 5704 | |
942ea06d | 5705 | load_font_func = x_load_font; |
bc1958c4 | 5706 | find_ccl_program_func = x_find_ccl_program; |
942ea06d KH |
5707 | query_font_func = x_query_font; |
5708 | set_frame_fontset_func = x_set_font; | |
5709 | check_window_system_func = check_x; | |
333b20bb | 5710 | |
0af913d7 GM |
5711 | hourglass_atimer = NULL; |
5712 | hourglass_shown_p = 0; | |
333b20bb GM |
5713 | |
5714 | defsubr (&Sx_show_tip); | |
5715 | defsubr (&Sx_hide_tip); | |
333b20bb | 5716 | tip_timer = Qnil; |
44b5a125 GM |
5717 | staticpro (&tip_timer); |
5718 | tip_frame = Qnil; | |
5719 | staticpro (&tip_frame); | |
333b20bb | 5720 | |
06d62053 GM |
5721 | last_show_tip_args = Qnil; |
5722 | staticpro (&last_show_tip_args); | |
5723 | ||
29fabd8c | 5724 | #if defined (USE_MOTIF) || defined (USE_GTK) |
333b20bb GM |
5725 | defsubr (&Sx_file_dialog); |
5726 | #endif | |
5727 | } | |
5728 | ||
01f1ba30 | 5729 | #endif /* HAVE_X_WINDOWS */ |
ab5796a9 MB |
5730 | |
5731 | /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288 | |
5732 | (do not change this comment) */ |