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