Merge from mainline.
[emacs.git] / src / xfns.c
blobbbec8759cd1f35fc803394d6ac2d7f94f9dc0213
1 /* Functions for the X window system.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 #include <config.h>
22 #include <stdio.h>
23 #include <math.h>
24 #include <setjmp.h>
25 #include <ctype.h>
26 #include <unistd.h>
28 /* This makes the fields of a Display accessible, in Xlib header files. */
30 #define XLIB_ILLEGAL_ACCESS
32 #include "lisp.h"
33 #include "xterm.h"
34 #include "frame.h"
35 #include "window.h"
36 #include "buffer.h"
37 #include "intervals.h"
38 #include "dispextern.h"
39 #include "keyboard.h"
40 #include "blockinput.h"
41 #include <epaths.h>
42 #include "character.h"
43 #include "charset.h"
44 #include "coding.h"
45 #include "fontset.h"
46 #include "systime.h"
47 #include "termhooks.h"
48 #include "atimer.h"
49 #include "termchar.h"
50 #include "font.h"
52 #ifdef HAVE_X_WINDOWS
54 #include <ctype.h>
55 #include <sys/types.h>
56 #include <sys/stat.h>
58 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
59 #include "bitmaps/gray.xbm"
60 #else
61 #include <X11/bitmaps/gray>
62 #endif
64 #include "xsettings.h"
66 #ifdef USE_GTK
67 #include "gtkutil.h"
68 #endif
70 #ifdef USE_X_TOOLKIT
71 #include <X11/Shell.h>
73 #ifndef USE_MOTIF
74 #ifdef HAVE_XAW3D
75 #include <X11/Xaw3d/Paned.h>
76 #include <X11/Xaw3d/Label.h>
77 #else /* !HAVE_XAW3D */
78 #include <X11/Xaw/Paned.h>
79 #include <X11/Xaw/Label.h>
80 #endif /* HAVE_XAW3D */
81 #endif /* USE_MOTIF */
83 #ifdef USG
84 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
85 #include <X11/Xos.h>
86 #define USG
87 #else
88 #include <X11/Xos.h>
89 #endif
91 #include "widget.h"
93 #include "../lwlib/lwlib.h"
95 #ifdef USE_MOTIF
96 #include <Xm/Xm.h>
97 #include <Xm/DialogS.h>
98 #include <Xm/FileSB.h>
99 #include <Xm/List.h>
100 #include <Xm/TextF.h>
101 #endif
103 #ifdef USE_LUCID
104 #include "../lwlib/xlwmenu.h"
105 #endif
107 #if !defined(NO_EDITRES)
108 #define HACK_EDITRES
109 extern void _XEditResCheckMessages ();
110 #endif /* not defined NO_EDITRES */
112 /* Unique id counter for widgets created by the Lucid Widget Library. */
114 extern LWLIB_ID widget_id_tick;
116 extern void free_frame_menubar ();
117 extern double atof ();
119 #ifdef USE_MOTIF
121 /* LessTif/Motif version info. */
123 static Lisp_Object Vmotif_version_string;
125 #endif /* USE_MOTIF */
127 #endif /* USE_X_TOOLKIT */
129 #ifdef USE_GTK
131 /* GTK+ version info */
133 static Lisp_Object Vgtk_version_string;
135 #endif /* USE_GTK */
137 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
139 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
140 it, and including `bitmaps/gray' more than once is a problem when
141 config.h defines `static' as an empty replacement string. */
143 int gray_bitmap_width = gray_width;
144 int gray_bitmap_height = gray_height;
145 char *gray_bitmap_bits = gray_bits;
147 /* Non-zero means prompt with the old GTK file selection dialog. */
149 int x_gtk_use_old_file_dialog;
151 /* If non-zero, by default show hidden files in the GTK file chooser. */
153 int x_gtk_show_hidden_files;
155 /* If non-zero, don't show additional help text in the GTK file chooser. */
157 int x_gtk_file_dialog_help_text;
159 /* If non-zero, don't collapse to tool bar when it is detached. */
161 int x_gtk_whole_detached_tool_bar;
163 /* If non-zero, use Gtk+ tooltips. */
165 static int x_gtk_use_system_tooltips;
167 /* The background and shape of the mouse pointer, and shape when not
168 over text or in the modeline. */
170 Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape;
171 Lisp_Object Vx_hourglass_pointer_shape;
173 /* The shape when over mouse-sensitive text. */
175 Lisp_Object Vx_sensitive_text_pointer_shape;
177 /* If non-nil, the pointer shape to indicate that windows can be
178 dragged horizontally. */
180 Lisp_Object Vx_window_horizontal_drag_shape;
182 /* Color of chars displayed in cursor box. */
184 Lisp_Object Vx_cursor_fore_pixel;
186 /* Nonzero if using X. */
188 static int x_in_use;
190 /* Non nil if no window manager is in use. */
192 Lisp_Object Vx_no_window_manager;
194 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
196 Lisp_Object Vx_pixel_size_width_font_regexp;
198 Lisp_Object Qnone;
199 Lisp_Object Qsuppress_icon;
200 Lisp_Object Qundefined_color;
201 Lisp_Object Qcompound_text, Qcancel_timer;
202 Lisp_Object Qfont_param;
204 #if GLYPH_DEBUG
205 int image_cache_refcount, dpyinfo_refcount;
206 #endif
208 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
209 char *x_last_font_name;
210 #endif
213 /* Error if we are not connected to X. */
215 void
216 check_x (void)
218 if (! x_in_use)
219 error ("X windows are not in use or not initialized");
222 /* Nonzero if we can use mouse menus.
223 You should not call this unless HAVE_MENUS is defined. */
226 have_menus_p (void)
228 return x_in_use;
231 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
232 and checking validity for X. */
234 FRAME_PTR
235 check_x_frame (Lisp_Object frame)
237 FRAME_PTR f;
239 if (NILP (frame))
240 frame = selected_frame;
241 CHECK_LIVE_FRAME (frame);
242 f = XFRAME (frame);
243 if (! FRAME_X_P (f))
244 error ("Non-X frame used");
245 return f;
248 /* Let the user specify an X display with a Lisp object.
249 OBJECT may be nil, a frame or a terminal object.
250 nil stands for the selected frame--or, if that is not an X frame,
251 the first X display on the list. */
253 struct x_display_info *
254 check_x_display_info (Lisp_Object object)
256 struct x_display_info *dpyinfo = NULL;
258 if (NILP (object))
260 struct frame *sf = XFRAME (selected_frame);
262 if (FRAME_X_P (sf) && FRAME_LIVE_P (sf))
263 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
264 else if (x_display_list != 0)
265 dpyinfo = x_display_list;
266 else
267 error ("X windows are not in use or not initialized");
269 else if (TERMINALP (object))
271 struct terminal *t = get_terminal (object, 1);
273 if (t->type != output_x_window)
274 error ("Terminal %d is not an X display", XINT (object));
276 dpyinfo = t->display_info.x;
278 else if (STRINGP (object))
279 dpyinfo = x_display_info_for_name (object);
280 else
282 FRAME_PTR f = check_x_frame (object);
283 dpyinfo = FRAME_X_DISPLAY_INFO (f);
286 return dpyinfo;
290 /* Return the Emacs frame-object corresponding to an X window.
291 It could be the frame's main window or an icon window. */
293 /* This function can be called during GC, so use GC_xxx type test macros. */
295 struct frame *
296 x_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
298 Lisp_Object tail, frame;
299 struct frame *f;
301 if (wdesc == None) return 0;
303 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
305 frame = XCAR (tail);
306 if (!FRAMEP (frame))
307 continue;
308 f = XFRAME (frame);
309 if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
310 continue;
311 if (f->output_data.x->hourglass_window == wdesc)
312 return f;
313 #ifdef USE_X_TOOLKIT
314 if ((f->output_data.x->edit_widget
315 && XtWindow (f->output_data.x->edit_widget) == wdesc)
316 /* A tooltip frame? */
317 || (!f->output_data.x->edit_widget
318 && FRAME_X_WINDOW (f) == wdesc)
319 || f->output_data.x->icon_desc == wdesc)
320 return f;
321 #else /* not USE_X_TOOLKIT */
322 #ifdef USE_GTK
323 if (f->output_data.x->edit_widget)
325 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
326 struct x_output *x = f->output_data.x;
327 if (gwdesc != 0 && gwdesc == x->edit_widget)
328 return f;
330 #endif /* USE_GTK */
331 if (FRAME_X_WINDOW (f) == wdesc
332 || f->output_data.x->icon_desc == wdesc)
333 return f;
334 #endif /* not USE_X_TOOLKIT */
336 return 0;
339 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
340 /* Like x_window_to_frame but also compares the window with the widget's
341 windows. */
343 struct frame *
344 x_any_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
346 Lisp_Object tail, frame;
347 struct frame *f, *found;
348 struct x_output *x;
350 if (wdesc == None) return NULL;
352 found = NULL;
353 for (tail = Vframe_list; CONSP (tail) && !found; tail = XCDR (tail))
355 frame = XCAR (tail);
356 if (!FRAMEP (frame))
357 continue;
359 f = XFRAME (frame);
360 if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo)
362 /* This frame matches if the window is any of its widgets. */
363 x = f->output_data.x;
364 if (x->hourglass_window == wdesc)
365 found = f;
366 else if (x->widget)
368 #ifdef USE_GTK
369 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
370 if (gwdesc != 0
371 && gtk_widget_get_toplevel (gwdesc) == x->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
383 else if (FRAME_X_WINDOW (f) == wdesc)
384 /* A tooltip frame. */
385 found = f;
389 return found;
392 /* Likewise, but consider only the menu bar widget. */
394 struct frame *
395 x_menubar_window_to_frame (struct x_display_info *dpyinfo, XEvent *event)
397 Window wdesc = event->xany.window;
398 Lisp_Object tail, frame;
399 struct frame *f;
400 struct x_output *x;
402 if (wdesc == None) return 0;
404 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
406 frame = XCAR (tail);
407 if (!FRAMEP (frame))
408 continue;
409 f = XFRAME (frame);
410 if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
411 continue;
412 x = f->output_data.x;
413 #ifdef USE_GTK
414 if (x->menubar_widget && xg_event_is_for_menubar (f, event))
415 return f;
416 #else
417 /* Match if the window is this frame's menubar. */
418 if (x->menubar_widget
419 && lw_window_is_in_menubar (wdesc, x->menubar_widget))
420 return f;
421 #endif
423 return 0;
426 /* Return the frame whose principal (outermost) window is WDESC.
427 If WDESC is some other (smaller) window, we return 0. */
429 struct frame *
430 x_top_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
432 Lisp_Object tail, frame;
433 struct frame *f;
434 struct x_output *x;
436 if (wdesc == None) return 0;
438 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
440 frame = XCAR (tail);
441 if (!FRAMEP (frame))
442 continue;
443 f = XFRAME (frame);
444 if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
445 continue;
446 x = f->output_data.x;
448 if (x->widget)
450 /* This frame matches if the window is its topmost widget. */
451 #ifdef USE_GTK
452 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
453 if (gwdesc == x->widget)
454 return f;
455 #else
456 if (wdesc == XtWindow (x->widget))
457 return f;
458 #if 0 /* I don't know why it did this,
459 but it seems logically wrong,
460 and it causes trouble for MapNotify events. */
461 /* Match if the window is this frame's menubar. */
462 if (x->menubar_widget
463 && wdesc == XtWindow (x->menubar_widget))
464 return f;
465 #endif
466 #endif
468 else if (FRAME_X_WINDOW (f) == wdesc)
469 /* Tooltip frame. */
470 return f;
472 return 0;
474 #endif /* USE_X_TOOLKIT || USE_GTK */
478 static void x_default_font_parameter (struct frame *, Lisp_Object);
480 static Lisp_Object unwind_create_frame (Lisp_Object);
481 static Lisp_Object unwind_create_tip_frame (Lisp_Object);
483 void x_set_foreground_color (struct frame *, Lisp_Object, Lisp_Object);
484 static void x_set_wait_for_wm (struct frame *, Lisp_Object, Lisp_Object);
485 void x_set_background_color (struct frame *, Lisp_Object, Lisp_Object);
486 void x_set_mouse_color (struct frame *, Lisp_Object, Lisp_Object);
487 void x_set_cursor_color (struct frame *, Lisp_Object, Lisp_Object);
488 void x_set_border_color (struct frame *, Lisp_Object, Lisp_Object);
489 void x_set_cursor_type (struct frame *, Lisp_Object, Lisp_Object);
490 void x_set_icon_type (struct frame *, Lisp_Object, Lisp_Object);
491 void x_set_icon_name (struct frame *, Lisp_Object, Lisp_Object);
492 void x_explicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
493 void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
494 void x_set_title (struct frame *, Lisp_Object, Lisp_Object);
495 void x_set_tool_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
496 void x_set_scroll_bar_foreground (struct frame *, Lisp_Object,
497 Lisp_Object);
498 void x_set_scroll_bar_background (struct frame *, Lisp_Object,
499 Lisp_Object);
500 static Lisp_Object x_default_scroll_bar_color_parameter (struct frame *,
501 Lisp_Object,
502 Lisp_Object,
503 const char *, const char *,
504 int);
507 /* Store the screen positions of frame F into XPTR and YPTR.
508 These are the positions of the containing window manager window,
509 not Emacs's own window. */
511 void
512 x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
514 int win_x, win_y, outer_x, outer_y;
515 int real_x = 0, real_y = 0;
516 int had_errors = 0;
517 Window win = f->output_data.x->parent_desc;
518 Atom actual_type;
519 unsigned long actual_size, bytes_remaining;
520 int i, rc, actual_format;
521 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
522 long max_len = 400;
523 Display *dpy = FRAME_X_DISPLAY (f);
524 unsigned char *tmp_data = NULL;
525 Atom target_type = XA_CARDINAL;
527 BLOCK_INPUT;
529 x_catch_errors (dpy);
531 if (win == dpyinfo->root_window)
532 win = FRAME_OUTER_WINDOW (f);
534 /* This loop traverses up the containment tree until we hit the root
535 window. Window managers may intersect many windows between our window
536 and the root window. The window we find just before the root window
537 should be the outer WM window. */
538 for (;;)
540 Window wm_window, rootw;
541 Window *tmp_children;
542 unsigned int tmp_nchildren;
543 int success;
545 success = XQueryTree (FRAME_X_DISPLAY (f), win, &rootw,
546 &wm_window, &tmp_children, &tmp_nchildren);
548 had_errors = x_had_errors_p (FRAME_X_DISPLAY (f));
550 /* Don't free tmp_children if XQueryTree failed. */
551 if (! success)
552 break;
554 XFree ((char *) tmp_children);
556 if (wm_window == rootw || had_errors)
557 break;
559 win = wm_window;
562 if (! had_errors)
564 unsigned int ign;
565 Window child, rootw;
567 /* Get the real coordinates for the WM window upper left corner */
568 XGetGeometry (FRAME_X_DISPLAY (f), win,
569 &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign);
571 /* Translate real coordinates to coordinates relative to our
572 window. For our window, the upper left corner is 0, 0.
573 Since the upper left corner of the WM window is outside
574 our window, win_x and win_y will be negative:
576 ------------------ ---> x
577 | title |
578 | ----------------- v y
579 | | our window
581 XTranslateCoordinates (FRAME_X_DISPLAY (f),
583 /* From-window, to-window. */
584 FRAME_X_DISPLAY_INFO (f)->root_window,
585 FRAME_X_WINDOW (f),
587 /* From-position, to-position. */
588 real_x, real_y, &win_x, &win_y,
590 /* Child of win. */
591 &child);
593 if (FRAME_X_WINDOW (f) == FRAME_OUTER_WINDOW (f))
595 outer_x = win_x;
596 outer_y = win_y;
598 else
600 XTranslateCoordinates (FRAME_X_DISPLAY (f),
602 /* From-window, to-window. */
603 FRAME_X_DISPLAY_INFO (f)->root_window,
604 FRAME_OUTER_WINDOW (f),
606 /* From-position, to-position. */
607 real_x, real_y, &outer_x, &outer_y,
609 /* Child of win. */
610 &child);
613 had_errors = x_had_errors_p (FRAME_X_DISPLAY (f));
617 if (dpyinfo->root_window == f->output_data.x->parent_desc)
619 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
620 rc = XGetWindowProperty (dpy, win, dpyinfo->Xatom_net_frame_extents,
621 0, max_len, False, target_type,
622 &actual_type, &actual_format, &actual_size,
623 &bytes_remaining, &tmp_data);
625 if (rc == Success && actual_type == target_type && !x_had_errors_p (dpy)
626 && actual_size == 4 && actual_format == 32)
628 int ign;
629 Window rootw;
630 long *fe = (long *)tmp_data;
632 XGetGeometry (FRAME_X_DISPLAY (f), win,
633 &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign);
634 outer_x = -fe[0];
635 outer_y = -fe[2];
636 real_x -= fe[0];
637 real_y -= fe[2];
641 if (tmp_data) XFree (tmp_data);
643 x_uncatch_errors ();
645 UNBLOCK_INPUT;
647 if (had_errors) return;
649 f->x_pixels_diff = -win_x;
650 f->y_pixels_diff = -win_y;
652 FRAME_X_OUTPUT (f)->x_pixels_outer_diff = -outer_x;
653 FRAME_X_OUTPUT (f)->y_pixels_outer_diff = -outer_y;
655 *xptr = real_x;
656 *yptr = real_y;
662 /* Gamma-correct COLOR on frame F. */
664 void
665 gamma_correct (struct frame *f, XColor *color)
667 if (f->gamma)
669 color->red = pow (color->red / 65535.0, f->gamma) * 65535.0 + 0.5;
670 color->green = pow (color->green / 65535.0, f->gamma) * 65535.0 + 0.5;
671 color->blue = pow (color->blue / 65535.0, f->gamma) * 65535.0 + 0.5;
676 /* Decide if color named COLOR_NAME is valid for use on frame F. If
677 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
678 allocate the color. Value is zero if COLOR_NAME is invalid, or
679 no color could be allocated. */
682 x_defined_color (struct frame *f, const char *color_name,
683 XColor *color, int alloc_p)
685 int success_p = 0;
686 Display *dpy = FRAME_X_DISPLAY (f);
687 Colormap cmap = FRAME_X_COLORMAP (f);
689 BLOCK_INPUT;
690 #ifdef USE_GTK
691 success_p = xg_check_special_colors (f, color_name, color);
692 #endif
693 if (!success_p)
694 success_p = XParseColor (dpy, cmap, color_name, color);
695 if (success_p && alloc_p)
696 success_p = x_alloc_nearest_color (f, cmap, color);
697 UNBLOCK_INPUT;
699 return success_p;
703 /* Return the pixel color value for color COLOR_NAME on frame F. If F
704 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
705 Signal an error if color can't be allocated. */
708 x_decode_color (FRAME_PTR f, Lisp_Object color_name, int mono_color)
710 XColor cdef;
712 CHECK_STRING (color_name);
714 #if 0 /* Don't do this. It's wrong when we're not using the default
715 colormap, it makes freeing difficult, and it's probably not
716 an important optimization. */
717 if (strcmp (SDATA (color_name), "black") == 0)
718 return BLACK_PIX_DEFAULT (f);
719 else if (strcmp (SDATA (color_name), "white") == 0)
720 return WHITE_PIX_DEFAULT (f);
721 #endif
723 /* Return MONO_COLOR for monochrome frames. */
724 if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1)
725 return mono_color;
727 /* x_defined_color is responsible for coping with failures
728 by looking for a near-miss. */
729 if (x_defined_color (f, SDATA (color_name), &cdef, 1))
730 return cdef.pixel;
732 signal_error ("Undefined color", color_name);
737 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
738 the previous value of that parameter, NEW_VALUE is the new value.
739 See also the comment of wait_for_wm in struct x_output. */
741 static void
742 x_set_wait_for_wm (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
744 f->output_data.x->wait_for_wm = !NILP (new_value);
747 static void
748 x_set_tool_bar_position (struct frame *f,
749 Lisp_Object new_value,
750 Lisp_Object old_value)
752 if (! EQ (new_value, Qleft) && ! EQ (new_value, Qright)
753 && ! EQ (new_value, Qbottom) && ! EQ (new_value, Qtop))
754 return;
755 if (EQ (new_value, old_value)) return;
757 #ifdef USE_GTK
758 if (xg_change_toolbar_position (f, new_value))
759 f->tool_bar_position = new_value;
760 #endif
763 #ifdef USE_GTK
765 /* Set icon from FILE for frame F. By using GTK functions the icon
766 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
769 xg_set_icon (FRAME_PTR f, Lisp_Object file)
771 int result = 0;
772 Lisp_Object found;
774 found = x_find_image_file (file);
776 if (! NILP (found))
778 GdkPixbuf *pixbuf;
779 GError *err = NULL;
780 char *filename = (char *) SDATA (found);
781 BLOCK_INPUT;
783 pixbuf = gdk_pixbuf_new_from_file (filename, &err);
785 if (pixbuf)
787 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
788 pixbuf);
789 g_object_unref (pixbuf);
791 result = 1;
793 else
794 g_error_free (err);
796 UNBLOCK_INPUT;
799 return result;
803 xg_set_icon_from_xpm_data (FRAME_PTR f, const char **data)
805 int result = 0;
806 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (data);
808 if (!pixbuf)
809 return 0;
811 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), pixbuf);
812 g_object_unref (pixbuf);
813 return 1;
815 #endif /* USE_GTK */
818 /* Functions called only from `x_set_frame_param'
819 to set individual parameters.
821 If FRAME_X_WINDOW (f) is 0,
822 the frame is being created and its X-window does not exist yet.
823 In that case, just record the parameter's new value
824 in the standard place; do not attempt to change the window. */
826 void
827 x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
829 struct x_output *x = f->output_data.x;
830 unsigned long fg, old_fg;
832 fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
833 old_fg = FRAME_FOREGROUND_PIXEL (f);
834 FRAME_FOREGROUND_PIXEL (f) = fg;
836 if (FRAME_X_WINDOW (f) != 0)
838 Display *dpy = FRAME_X_DISPLAY (f);
840 BLOCK_INPUT;
841 XSetForeground (dpy, x->normal_gc, fg);
842 XSetBackground (dpy, x->reverse_gc, fg);
844 if (x->cursor_pixel == old_fg)
846 unload_color (f, x->cursor_pixel);
847 x->cursor_pixel = x_copy_color (f, fg);
848 XSetBackground (dpy, x->cursor_gc, x->cursor_pixel);
851 UNBLOCK_INPUT;
853 update_face_from_frame_parameter (f, Qforeground_color, arg);
855 if (FRAME_VISIBLE_P (f))
856 redraw_frame (f);
859 unload_color (f, old_fg);
862 void
863 x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
865 struct x_output *x = f->output_data.x;
866 unsigned long bg;
868 bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
869 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
870 FRAME_BACKGROUND_PIXEL (f) = bg;
872 if (FRAME_X_WINDOW (f) != 0)
874 Display *dpy = FRAME_X_DISPLAY (f);
876 BLOCK_INPUT;
877 XSetBackground (dpy, x->normal_gc, bg);
878 XSetForeground (dpy, x->reverse_gc, bg);
879 XSetWindowBackground (dpy, FRAME_X_WINDOW (f), bg);
880 XSetForeground (dpy, x->cursor_gc, bg);
882 #ifdef USE_GTK
883 xg_set_background_color (f, bg);
884 #endif
886 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
887 toolkit scroll bars. */
889 Lisp_Object bar;
890 for (bar = FRAME_SCROLL_BARS (f);
891 !NILP (bar);
892 bar = XSCROLL_BAR (bar)->next)
894 Window window = XSCROLL_BAR (bar)->x_window;
895 XSetWindowBackground (dpy, window, bg);
898 #endif /* USE_TOOLKIT_SCROLL_BARS */
900 UNBLOCK_INPUT;
901 update_face_from_frame_parameter (f, Qbackground_color, arg);
903 if (FRAME_VISIBLE_P (f))
904 redraw_frame (f);
908 static Cursor
909 make_invisible_cursor (struct frame *f)
911 Display *dpy = FRAME_X_DISPLAY (f);
912 static char const no_data[] = { 0 };
913 Pixmap pix;
914 XColor col;
915 Cursor c;
917 x_catch_errors (dpy);
918 pix = XCreateBitmapFromData (dpy, FRAME_X_DISPLAY_INFO (f)->root_window,
919 no_data, 1, 1);
920 if (! x_had_errors_p (dpy) && pix != None)
922 col.pixel = 0;
923 col.red = col.green = col.blue = 0;
924 col.flags = DoRed | DoGreen | DoBlue;
925 c = XCreatePixmapCursor (dpy, pix, pix, &col, &col, 0, 0);
926 if (x_had_errors_p (dpy) || c == None)
927 c = 0;
928 XFreePixmap (dpy, pix);
931 x_uncatch_errors ();
933 return c;
936 void
937 x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
939 struct x_output *x = f->output_data.x;
940 Display *dpy = FRAME_X_DISPLAY (f);
941 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
942 Cursor hourglass_cursor, horizontal_drag_cursor;
943 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
944 unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f);
946 /* Don't let pointers be invisible. */
947 if (mask_color == pixel)
949 x_free_colors (f, &pixel, 1);
950 pixel = x_copy_color (f, FRAME_FOREGROUND_PIXEL (f));
953 unload_color (f, x->mouse_pixel);
954 x->mouse_pixel = pixel;
956 BLOCK_INPUT;
958 /* It's not okay to crash if the user selects a screwy cursor. */
959 x_catch_errors (dpy);
961 if (!NILP (Vx_pointer_shape))
963 CHECK_NUMBER (Vx_pointer_shape);
964 cursor = XCreateFontCursor (dpy, XINT (Vx_pointer_shape));
966 else
967 cursor = XCreateFontCursor (dpy, XC_xterm);
968 x_check_errors (dpy, "bad text pointer cursor: %s");
970 if (!NILP (Vx_nontext_pointer_shape))
972 CHECK_NUMBER (Vx_nontext_pointer_shape);
973 nontext_cursor
974 = XCreateFontCursor (dpy, XINT (Vx_nontext_pointer_shape));
976 else
977 nontext_cursor = XCreateFontCursor (dpy, XC_left_ptr);
978 x_check_errors (dpy, "bad nontext pointer cursor: %s");
980 if (!NILP (Vx_hourglass_pointer_shape))
982 CHECK_NUMBER (Vx_hourglass_pointer_shape);
983 hourglass_cursor
984 = XCreateFontCursor (dpy, XINT (Vx_hourglass_pointer_shape));
986 else
987 hourglass_cursor = XCreateFontCursor (dpy, XC_watch);
988 x_check_errors (dpy, "bad hourglass pointer cursor: %s");
990 if (!NILP (Vx_mode_pointer_shape))
992 CHECK_NUMBER (Vx_mode_pointer_shape);
993 mode_cursor = XCreateFontCursor (dpy, XINT (Vx_mode_pointer_shape));
995 else
996 mode_cursor = XCreateFontCursor (dpy, XC_xterm);
997 x_check_errors (dpy, "bad modeline pointer cursor: %s");
999 if (!NILP (Vx_sensitive_text_pointer_shape))
1001 CHECK_NUMBER (Vx_sensitive_text_pointer_shape);
1002 hand_cursor
1003 = XCreateFontCursor (dpy, XINT (Vx_sensitive_text_pointer_shape));
1005 else
1006 hand_cursor = XCreateFontCursor (dpy, XC_hand2);
1008 if (!NILP (Vx_window_horizontal_drag_shape))
1010 CHECK_NUMBER (Vx_window_horizontal_drag_shape);
1011 horizontal_drag_cursor
1012 = XCreateFontCursor (dpy, XINT (Vx_window_horizontal_drag_shape));
1014 else
1015 horizontal_drag_cursor
1016 = XCreateFontCursor (dpy, XC_sb_h_double_arrow);
1018 /* Check and report errors with the above calls. */
1019 x_check_errors (dpy, "can't set cursor shape: %s");
1020 x_uncatch_errors ();
1023 XColor fore_color, back_color;
1025 fore_color.pixel = x->mouse_pixel;
1026 x_query_color (f, &fore_color);
1027 back_color.pixel = mask_color;
1028 x_query_color (f, &back_color);
1030 XRecolorCursor (dpy, cursor, &fore_color, &back_color);
1031 XRecolorCursor (dpy, nontext_cursor, &fore_color, &back_color);
1032 XRecolorCursor (dpy, mode_cursor, &fore_color, &back_color);
1033 XRecolorCursor (dpy, hand_cursor, &fore_color, &back_color);
1034 XRecolorCursor (dpy, hourglass_cursor, &fore_color, &back_color);
1035 XRecolorCursor (dpy, horizontal_drag_cursor, &fore_color, &back_color);
1038 if (FRAME_X_WINDOW (f) != 0)
1039 XDefineCursor (dpy, FRAME_X_WINDOW (f),
1040 f->output_data.x->current_cursor = cursor);
1042 if (FRAME_X_DISPLAY_INFO (f)->invisible_cursor == 0)
1043 FRAME_X_DISPLAY_INFO (f)->invisible_cursor = make_invisible_cursor (f);
1045 if (cursor != x->text_cursor
1046 && x->text_cursor != 0)
1047 XFreeCursor (dpy, x->text_cursor);
1048 x->text_cursor = cursor;
1050 if (nontext_cursor != x->nontext_cursor
1051 && x->nontext_cursor != 0)
1052 XFreeCursor (dpy, x->nontext_cursor);
1053 x->nontext_cursor = nontext_cursor;
1055 if (hourglass_cursor != x->hourglass_cursor
1056 && x->hourglass_cursor != 0)
1057 XFreeCursor (dpy, x->hourglass_cursor);
1058 x->hourglass_cursor = hourglass_cursor;
1060 if (mode_cursor != x->modeline_cursor
1061 && x->modeline_cursor != 0)
1062 XFreeCursor (dpy, f->output_data.x->modeline_cursor);
1063 x->modeline_cursor = mode_cursor;
1065 if (hand_cursor != x->hand_cursor
1066 && x->hand_cursor != 0)
1067 XFreeCursor (dpy, x->hand_cursor);
1068 x->hand_cursor = hand_cursor;
1070 if (horizontal_drag_cursor != x->horizontal_drag_cursor
1071 && x->horizontal_drag_cursor != 0)
1072 XFreeCursor (dpy, x->horizontal_drag_cursor);
1073 x->horizontal_drag_cursor = horizontal_drag_cursor;
1075 XFlush (dpy);
1076 UNBLOCK_INPUT;
1078 update_face_from_frame_parameter (f, Qmouse_color, arg);
1081 void
1082 x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1084 unsigned long fore_pixel, pixel;
1085 int fore_pixel_allocated_p = 0, pixel_allocated_p = 0;
1086 struct x_output *x = f->output_data.x;
1088 if (!NILP (Vx_cursor_fore_pixel))
1090 fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel,
1091 WHITE_PIX_DEFAULT (f));
1092 fore_pixel_allocated_p = 1;
1094 else
1095 fore_pixel = FRAME_BACKGROUND_PIXEL (f);
1097 pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1098 pixel_allocated_p = 1;
1100 /* Make sure that the cursor color differs from the background color. */
1101 if (pixel == FRAME_BACKGROUND_PIXEL (f))
1103 if (pixel_allocated_p)
1105 x_free_colors (f, &pixel, 1);
1106 pixel_allocated_p = 0;
1109 pixel = x->mouse_pixel;
1110 if (pixel == fore_pixel)
1112 if (fore_pixel_allocated_p)
1114 x_free_colors (f, &fore_pixel, 1);
1115 fore_pixel_allocated_p = 0;
1117 fore_pixel = FRAME_BACKGROUND_PIXEL (f);
1121 unload_color (f, x->cursor_foreground_pixel);
1122 if (!fore_pixel_allocated_p)
1123 fore_pixel = x_copy_color (f, fore_pixel);
1124 x->cursor_foreground_pixel = fore_pixel;
1126 unload_color (f, x->cursor_pixel);
1127 if (!pixel_allocated_p)
1128 pixel = x_copy_color (f, pixel);
1129 x->cursor_pixel = pixel;
1131 if (FRAME_X_WINDOW (f) != 0)
1133 BLOCK_INPUT;
1134 XSetBackground (FRAME_X_DISPLAY (f), x->cursor_gc, x->cursor_pixel);
1135 XSetForeground (FRAME_X_DISPLAY (f), x->cursor_gc, fore_pixel);
1136 UNBLOCK_INPUT;
1138 if (FRAME_VISIBLE_P (f))
1140 x_update_cursor (f, 0);
1141 x_update_cursor (f, 1);
1145 update_face_from_frame_parameter (f, Qcursor_color, arg);
1148 /* Set the border-color of frame F to pixel value PIX.
1149 Note that this does not fully take effect if done before
1150 F has an x-window. */
1152 void
1153 x_set_border_pixel (struct frame *f, int pix)
1155 unload_color (f, f->output_data.x->border_pixel);
1156 f->output_data.x->border_pixel = pix;
1158 if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0)
1160 BLOCK_INPUT;
1161 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1162 (unsigned long)pix);
1163 UNBLOCK_INPUT;
1165 if (FRAME_VISIBLE_P (f))
1166 redraw_frame (f);
1170 /* Set the border-color of frame F to value described by ARG.
1171 ARG can be a string naming a color.
1172 The border-color is used for the border that is drawn by the X server.
1173 Note that this does not fully take effect if done before
1174 F has an x-window; it must be redone when the window is created.
1176 Note: this is done in two routines because of the way X10 works.
1178 Note: under X11, this is normally the province of the window manager,
1179 and so emacs' border colors may be overridden. */
1181 void
1182 x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1184 int pix;
1186 CHECK_STRING (arg);
1187 pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1188 x_set_border_pixel (f, pix);
1189 update_face_from_frame_parameter (f, Qborder_color, arg);
1193 void
1194 x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
1196 set_frame_cursor_types (f, arg);
1198 /* Make sure the cursor gets redrawn. */
1199 cursor_type_changed = 1;
1202 void
1203 x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1205 int result;
1207 if (STRINGP (arg))
1209 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
1210 return;
1212 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
1213 return;
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);
1224 if (result)
1226 UNBLOCK_INPUT;
1227 error ("No icon window available");
1230 XFlush (FRAME_X_DISPLAY (f));
1231 UNBLOCK_INPUT;
1234 void
1235 x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1237 int result;
1239 if (STRINGP (arg))
1241 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
1242 return;
1244 else if (!NILP (arg) || NILP (oldval))
1245 return;
1247 f->icon_name = arg;
1249 if (f->output_data.x->icon_bitmap != 0)
1250 return;
1252 BLOCK_INPUT;
1254 result = x_text_icon (f,
1255 (char *) SDATA ((!NILP (f->icon_name)
1256 ? f->icon_name
1257 : !NILP (f->title)
1258 ? f->title
1259 : f->name)));
1261 if (result)
1263 UNBLOCK_INPUT;
1264 error ("No icon window available");
1267 XFlush (FRAME_X_DISPLAY (f));
1268 UNBLOCK_INPUT;
1272 void
1273 x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1275 int nlines;
1276 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1277 int olines = FRAME_MENU_BAR_LINES (f);
1278 #endif
1280 /* Right now, menu bars don't work properly in minibuf-only frames;
1281 most of the commands try to apply themselves to the minibuffer
1282 frame itself, and get an error because you can't switch buffers
1283 in or split the minibuffer window. */
1284 if (FRAME_MINIBUF_ONLY_P (f))
1285 return;
1287 if (INTEGERP (value))
1288 nlines = XINT (value);
1289 else
1290 nlines = 0;
1292 /* Make sure we redisplay all windows in this frame. */
1293 windows_or_buffers_changed++;
1295 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1296 FRAME_MENU_BAR_LINES (f) = 0;
1297 if (nlines)
1299 FRAME_EXTERNAL_MENU_BAR (f) = 1;
1300 if (FRAME_X_P (f) && f->output_data.x->menubar_widget == 0)
1301 /* Make sure next redisplay shows the menu bar. */
1302 XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt;
1304 else
1306 if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
1307 free_frame_menubar (f);
1308 FRAME_EXTERNAL_MENU_BAR (f) = 0;
1309 if (FRAME_X_P (f))
1310 f->output_data.x->menubar_widget = 0;
1312 #else /* not USE_X_TOOLKIT && not USE_GTK */
1313 FRAME_MENU_BAR_LINES (f) = nlines;
1314 change_window_heights (f->root_window, nlines - olines);
1316 /* If the menu bar height gets changed, the internal border below
1317 the top margin has to be cleared. Also, if the menu bar gets
1318 larger, the area for the added lines has to be cleared except for
1319 the first menu bar line that is to be drawn later. */
1320 if (nlines != olines)
1322 int height = FRAME_INTERNAL_BORDER_WIDTH (f);
1323 int width = FRAME_PIXEL_WIDTH (f);
1324 int y;
1326 /* height can be zero here. */
1327 if (height > 0 && width > 0)
1329 y = FRAME_TOP_MARGIN_HEIGHT (f);
1331 BLOCK_INPUT;
1332 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1333 0, y, width, height, False);
1334 UNBLOCK_INPUT;
1337 if (nlines > 1 && nlines > olines)
1339 y = (olines == 0 ? 1 : olines) * FRAME_LINE_HEIGHT (f);
1340 height = nlines * FRAME_LINE_HEIGHT (f) - y;
1342 BLOCK_INPUT;
1343 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1344 0, y, width, height, False);
1345 UNBLOCK_INPUT;
1348 if (nlines == 0 && WINDOWP (f->menu_bar_window))
1349 clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix);
1351 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1352 adjust_glyphs (f);
1356 /* Set the number of lines used for the tool bar of frame F to VALUE.
1357 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1358 is the old number of tool bar lines. This function changes the
1359 height of all windows on frame F to match the new tool bar height.
1360 The frame's height doesn't change. */
1362 void
1363 x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1365 int delta, nlines, root_height;
1366 Lisp_Object root_window;
1368 /* Treat tool bars like menu bars. */
1369 if (FRAME_MINIBUF_ONLY_P (f))
1370 return;
1372 /* Use VALUE only if an integer >= 0. */
1373 if (INTEGERP (value) && XINT (value) >= 0)
1374 nlines = XFASTINT (value);
1375 else
1376 nlines = 0;
1378 #ifdef USE_GTK
1379 FRAME_TOOL_BAR_LINES (f) = 0;
1380 if (nlines)
1382 FRAME_EXTERNAL_TOOL_BAR (f) = 1;
1383 if (FRAME_X_P (f) && f->output_data.x->toolbar_widget == 0)
1384 /* Make sure next redisplay shows the tool bar. */
1385 XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt;
1386 update_frame_tool_bar (f);
1388 else
1390 if (FRAME_EXTERNAL_TOOL_BAR (f))
1391 free_frame_tool_bar (f);
1392 FRAME_EXTERNAL_TOOL_BAR (f) = 0;
1395 return;
1396 #endif
1398 /* Make sure we redisplay all windows in this frame. */
1399 ++windows_or_buffers_changed;
1401 delta = nlines - FRAME_TOOL_BAR_LINES (f);
1403 /* Don't resize the tool-bar to more than we have room for. */
1404 root_window = FRAME_ROOT_WINDOW (f);
1405 root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window));
1406 if (root_height - delta < 1)
1408 delta = root_height - 1;
1409 nlines = FRAME_TOOL_BAR_LINES (f) + delta;
1412 FRAME_TOOL_BAR_LINES (f) = nlines;
1413 change_window_heights (root_window, delta);
1414 adjust_glyphs (f);
1416 /* We also have to make sure that the internal border at the top of
1417 the frame, below the menu bar or tool bar, is redrawn when the
1418 tool bar disappears. This is so because the internal border is
1419 below the tool bar if one is displayed, but is below the menu bar
1420 if there isn't a tool bar. The tool bar draws into the area
1421 below the menu bar. */
1422 if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
1424 clear_frame (f);
1425 clear_current_matrices (f);
1428 /* If the tool bar gets smaller, the internal border below it
1429 has to be cleared. It was formerly part of the display
1430 of the larger tool bar, and updating windows won't clear it. */
1431 if (delta < 0)
1433 int height = FRAME_INTERNAL_BORDER_WIDTH (f);
1434 int width = FRAME_PIXEL_WIDTH (f);
1435 int y = (FRAME_MENU_BAR_LINES (f) + nlines) * FRAME_LINE_HEIGHT (f);
1437 /* height can be zero here. */
1438 if (height > 0 && width > 0)
1440 BLOCK_INPUT;
1441 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1442 0, y, width, height, False);
1443 UNBLOCK_INPUT;
1446 if (WINDOWP (f->tool_bar_window))
1447 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix);
1452 /* Set the foreground color for scroll bars on frame F to VALUE.
1453 VALUE should be a string, a color name. If it isn't a string or
1454 isn't a valid color name, do nothing. OLDVAL is the old value of
1455 the frame parameter. */
1457 void
1458 x_set_scroll_bar_foreground (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1460 unsigned long pixel;
1462 if (STRINGP (value))
1463 pixel = x_decode_color (f, value, BLACK_PIX_DEFAULT (f));
1464 else
1465 pixel = -1;
1467 if (f->output_data.x->scroll_bar_foreground_pixel != -1)
1468 unload_color (f, f->output_data.x->scroll_bar_foreground_pixel);
1470 f->output_data.x->scroll_bar_foreground_pixel = pixel;
1471 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
1473 /* Remove all scroll bars because they have wrong colors. */
1474 if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
1475 (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
1476 if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
1477 (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
1479 update_face_from_frame_parameter (f, Qscroll_bar_foreground, value);
1480 redraw_frame (f);
1485 /* Set the background color for scroll bars on frame F to VALUE VALUE
1486 should be a string, a color name. If it isn't a string or isn't a
1487 valid color name, do nothing. OLDVAL is the old value of the frame
1488 parameter. */
1490 void
1491 x_set_scroll_bar_background (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1493 unsigned long pixel;
1495 if (STRINGP (value))
1496 pixel = x_decode_color (f, value, WHITE_PIX_DEFAULT (f));
1497 else
1498 pixel = -1;
1500 if (f->output_data.x->scroll_bar_background_pixel != -1)
1501 unload_color (f, f->output_data.x->scroll_bar_background_pixel);
1503 #ifdef USE_TOOLKIT_SCROLL_BARS
1504 /* Scrollbar shadow colors. */
1505 if (f->output_data.x->scroll_bar_top_shadow_pixel != -1)
1507 unload_color (f, f->output_data.x->scroll_bar_top_shadow_pixel);
1508 f->output_data.x->scroll_bar_top_shadow_pixel = -1;
1510 if (f->output_data.x->scroll_bar_bottom_shadow_pixel != -1)
1512 unload_color (f, f->output_data.x->scroll_bar_bottom_shadow_pixel);
1513 f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
1515 #endif /* USE_TOOLKIT_SCROLL_BARS */
1517 f->output_data.x->scroll_bar_background_pixel = pixel;
1518 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
1520 /* Remove all scroll bars because they have wrong colors. */
1521 if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
1522 (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
1523 if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
1524 (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
1526 update_face_from_frame_parameter (f, Qscroll_bar_background, value);
1527 redraw_frame (f);
1532 /* Encode Lisp string STRING as a text in a format appropriate for
1533 XICCC (X Inter Client Communication Conventions).
1535 This can call Lisp code, so callers must GCPRO.
1537 If STRING contains only ASCII characters, do no conversion and
1538 return the string data of STRING. Otherwise, encode the text by
1539 CODING_SYSTEM, and return a newly allocated memory area which
1540 should be freed by `xfree' by a caller.
1542 SELECTIONP non-zero means the string is being encoded for an X
1543 selection, so it is safe to run pre-write conversions (which
1544 may run Lisp code).
1546 Store the byte length of resulting text in *TEXT_BYTES.
1548 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1549 which means that the `encoding' of the result can be `STRING'.
1550 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1551 the result should be `COMPOUND_TEXT'. */
1553 static unsigned char *
1554 x_encode_text (Lisp_Object string, Lisp_Object coding_system, int selectionp, int *text_bytes, int *stringp, int *freep)
1556 int result = string_xstring_p (string);
1557 struct coding_system coding;
1559 if (result == 0)
1561 /* No multibyte character in OBJ. We need not encode it. */
1562 *text_bytes = SBYTES (string);
1563 *stringp = 1;
1564 *freep = 0;
1565 return SDATA (string);
1568 setup_coding_system (coding_system, &coding);
1569 coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK);
1570 /* We suppress producing escape sequences for composition. */
1571 coding.common_flags &= ~CODING_ANNOTATION_MASK;
1572 coding.dst_bytes = SCHARS (string) * 2;
1573 coding.destination = (unsigned char *) xmalloc (coding.dst_bytes);
1574 encode_coding_object (&coding, string, 0, 0,
1575 SCHARS (string), SBYTES (string), Qnil);
1576 *text_bytes = coding.produced;
1577 *stringp = (result == 1 || !EQ (coding_system, Qcompound_text));
1578 *freep = 1;
1579 return coding.destination;
1583 /* Set the WM name to NAME for frame F. Also set the icon name.
1584 If the frame already has an icon name, use that, otherwise set the
1585 icon name to NAME. */
1587 static void
1588 x_set_name_internal (FRAME_PTR f, Lisp_Object name)
1590 if (FRAME_X_WINDOW (f))
1592 BLOCK_INPUT;
1594 XTextProperty text, icon;
1595 int bytes, stringp;
1596 int do_free_icon_value = 0, do_free_text_value = 0;
1597 Lisp_Object coding_system;
1598 Lisp_Object encoded_name;
1599 Lisp_Object encoded_icon_name;
1600 struct gcpro gcpro1;
1602 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1603 we use it before x_encode_text that may return string data. */
1604 GCPRO1 (name);
1605 encoded_name = ENCODE_UTF_8 (name);
1606 UNGCPRO;
1608 coding_system = Qcompound_text;
1609 /* Note: Encoding strategy
1611 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1612 text.encoding. But, there are non-internationalized window
1613 managers which don't support that encoding. So, if NAME
1614 contains only ASCII and 8859-1 characters, encode it by
1615 iso-latin-1, and use "STRING" in text.encoding hoping that
1616 such window managers at least analyze this format correctly,
1617 i.e. treat 8-bit bytes as 8859-1 characters.
1619 We may also be able to use "UTF8_STRING" in text.encoding
1620 in the future which can encode all Unicode characters.
1621 But, for the moment, there's no way to know that the
1622 current window manager supports it or not.
1624 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1625 properties. Per the EWMH specification, those two properties
1626 are always UTF8_STRING. This matches what gtk_window_set_title()
1627 does in the USE_GTK case. */
1628 text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp,
1629 &do_free_text_value);
1630 text.encoding = (stringp ? XA_STRING
1631 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
1632 text.format = 8;
1633 text.nitems = bytes;
1635 if (!STRINGP (f->icon_name))
1637 icon = text;
1638 encoded_icon_name = encoded_name;
1640 else
1642 /* See the above comment "Note: Encoding strategy". */
1643 icon.value = x_encode_text (f->icon_name, coding_system, 0,
1644 &bytes, &stringp, &do_free_icon_value);
1645 icon.encoding = (stringp ? XA_STRING
1646 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
1647 icon.format = 8;
1648 icon.nitems = bytes;
1650 encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
1653 #ifdef USE_GTK
1654 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1655 (char *) SDATA (encoded_name));
1656 #else /* not USE_GTK */
1657 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text);
1658 XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
1659 FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_name,
1660 FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
1661 8, PropModeReplace,
1662 (char *) SDATA (encoded_name),
1663 SBYTES (encoded_name));
1664 #endif /* not USE_GTK */
1666 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon);
1667 XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
1668 FRAME_X_DISPLAY_INFO (f)->Xatom_net_wm_icon_name,
1669 FRAME_X_DISPLAY_INFO (f)->Xatom_UTF8_STRING,
1670 8, PropModeReplace,
1671 (char *) SDATA (encoded_icon_name),
1672 SBYTES (encoded_icon_name));
1674 if (do_free_icon_value)
1675 xfree (icon.value);
1676 if (do_free_text_value)
1677 xfree (text.value);
1679 UNBLOCK_INPUT;
1683 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1684 x_id_name.
1686 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1687 name; if NAME is a string, set F's name to NAME and set
1688 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1690 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1691 suggesting a new name, which lisp code should override; if
1692 F->explicit_name is set, ignore the new name; otherwise, set it. */
1694 void
1695 x_set_name (struct frame *f, Lisp_Object name, int explicit)
1697 /* Make sure that requests from lisp code override requests from
1698 Emacs redisplay code. */
1699 if (explicit)
1701 /* If we're switching from explicit to implicit, we had better
1702 update the mode lines and thereby update the title. */
1703 if (f->explicit_name && NILP (name))
1704 update_mode_lines = 1;
1706 f->explicit_name = ! NILP (name);
1708 else if (f->explicit_name)
1709 return;
1711 /* If NAME is nil, set the name to the x_id_name. */
1712 if (NILP (name))
1714 /* Check for no change needed in this very common case
1715 before we do any consing. */
1716 if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
1717 SDATA (f->name)))
1718 return;
1719 name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
1721 else
1722 CHECK_STRING (name);
1724 /* Don't change the name if it's already NAME. */
1725 if (! NILP (Fstring_equal (name, f->name)))
1726 return;
1728 f->name = name;
1730 /* For setting the frame title, the title parameter should override
1731 the name parameter. */
1732 if (! NILP (f->title))
1733 name = f->title;
1735 x_set_name_internal (f, name);
1738 /* This function should be called when the user's lisp code has
1739 specified a name for the frame; the name will override any set by the
1740 redisplay code. */
1741 void
1742 x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
1744 x_set_name (f, arg, 1);
1747 /* This function should be called by Emacs redisplay code to set the
1748 name; names set this way will never override names set by the user's
1749 lisp code. */
1750 void
1751 x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
1753 x_set_name (f, arg, 0);
1756 /* Change the title of frame F to NAME.
1757 If NAME is nil, use the frame name as the title. */
1759 void
1760 x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
1762 /* Don't change the title if it's already NAME. */
1763 if (EQ (name, f->title))
1764 return;
1766 update_mode_lines = 1;
1768 f->title = name;
1770 if (NILP (name))
1771 name = f->name;
1772 else
1773 CHECK_STRING (name);
1775 x_set_name_internal (f, name);
1778 void
1779 x_set_scroll_bar_default_width (struct frame *f)
1781 int wid = FRAME_COLUMN_WIDTH (f);
1783 #ifdef USE_TOOLKIT_SCROLL_BARS
1784 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1785 int width = 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM;
1786 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (width + wid - 1) / wid;
1787 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = width;
1788 #else
1789 /* Make the actual width at least 14 pixels and a multiple of a
1790 character width. */
1791 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
1793 /* Use all of that space (aside from required margins) for the
1794 scroll bar. */
1795 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 0;
1796 #endif
1800 /* Record in frame F the specified or default value according to ALIST
1801 of the parameter named PROP (a Lisp symbol). If no value is
1802 specified for PROP, look for an X default for XPROP on the frame
1803 named NAME. If that is not found either, use the value DEFLT. */
1805 static Lisp_Object
1806 x_default_scroll_bar_color_parameter (struct frame *f,
1807 Lisp_Object alist, Lisp_Object prop,
1808 const char *xprop, const char *xclass,
1809 int foreground_p)
1811 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
1812 Lisp_Object tem;
1814 tem = x_get_arg (dpyinfo, alist, prop, xprop, xclass, RES_TYPE_STRING);
1815 if (EQ (tem, Qunbound))
1817 #ifdef USE_TOOLKIT_SCROLL_BARS
1819 /* See if an X resource for the scroll bar color has been
1820 specified. */
1821 tem = display_x_get_resource (dpyinfo,
1822 build_string (foreground_p
1823 ? "foreground"
1824 : "background"),
1825 empty_unibyte_string,
1826 build_string ("verticalScrollBar"),
1827 empty_unibyte_string);
1828 if (!STRINGP (tem))
1830 /* If nothing has been specified, scroll bars will use a
1831 toolkit-dependent default. Because these defaults are
1832 difficult to get at without actually creating a scroll
1833 bar, use nil to indicate that no color has been
1834 specified. */
1835 tem = Qnil;
1838 #else /* not USE_TOOLKIT_SCROLL_BARS */
1840 tem = Qnil;
1842 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1845 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
1846 return tem;
1852 #ifdef USE_X_TOOLKIT
1854 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1855 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1856 already be present because of the toolkit (Motif adds some of them,
1857 for example, but Xt doesn't). */
1859 static void
1860 hack_wm_protocols (FRAME_PTR f, Widget widget)
1862 Display *dpy = XtDisplay (widget);
1863 Window w = XtWindow (widget);
1864 int need_delete = 1;
1865 int need_focus = 1;
1866 int need_save = 1;
1868 BLOCK_INPUT;
1870 Atom type;
1871 unsigned char *catoms;
1872 int format = 0;
1873 unsigned long nitems = 0;
1874 unsigned long bytes_after;
1876 if ((XGetWindowProperty (dpy, w,
1877 FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
1878 (long)0, (long)100, False, XA_ATOM,
1879 &type, &format, &nitems, &bytes_after,
1880 &catoms)
1881 == Success)
1882 && format == 32 && type == XA_ATOM)
1884 Atom *atoms = (Atom *) catoms;
1885 while (nitems > 0)
1887 nitems--;
1888 if (atoms[nitems]
1889 == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window)
1890 need_delete = 0;
1891 else if (atoms[nitems]
1892 == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus)
1893 need_focus = 0;
1894 else if (atoms[nitems]
1895 == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself)
1896 need_save = 0;
1899 if (catoms)
1900 XFree (catoms);
1903 Atom props [10];
1904 int count = 0;
1905 if (need_delete)
1906 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
1907 if (need_focus)
1908 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus;
1909 if (need_save)
1910 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
1911 if (count)
1912 XChangeProperty (dpy, w, FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
1913 XA_ATOM, 32, PropModeAppend,
1914 (unsigned char *) props, count);
1916 UNBLOCK_INPUT;
1918 #endif
1922 /* Support routines for XIC (X Input Context). */
1924 #ifdef HAVE_X_I18N
1926 static XFontSet xic_create_xfontset (struct frame *);
1927 static XIMStyle best_xim_style (XIMStyles *, XIMStyles *);
1930 /* Supported XIM styles, ordered by preference. */
1932 static XIMStyle supported_xim_styles[] =
1934 XIMPreeditPosition | XIMStatusArea,
1935 XIMPreeditPosition | XIMStatusNothing,
1936 XIMPreeditPosition | XIMStatusNone,
1937 XIMPreeditNothing | XIMStatusArea,
1938 XIMPreeditNothing | XIMStatusNothing,
1939 XIMPreeditNothing | XIMStatusNone,
1940 XIMPreeditNone | XIMStatusArea,
1941 XIMPreeditNone | XIMStatusNothing,
1942 XIMPreeditNone | XIMStatusNone,
1947 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1949 const char xic_defaut_fontset[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1951 /* Create an Xt fontset spec from the name of a base font.
1952 If `motif' is True use the Motif syntax. */
1953 char *
1954 xic_create_fontsetname (const char *base_fontname, int motif)
1956 const char *sep = motif ? ";" : ",";
1957 char *fontsetname;
1959 /* Make a fontset name from the base font name. */
1960 if (xic_defaut_fontset == base_fontname)
1961 { /* There is no base font name, use the default. */
1962 int len = strlen (base_fontname) + 2;
1963 fontsetname = xmalloc (len);
1964 memset (fontsetname, 0, len);
1965 strcpy (fontsetname, base_fontname);
1967 else
1969 /* Make a fontset name from the base font name.
1970 The font set will be made of the following elements:
1971 - the base font.
1972 - the base font where the charset spec is replaced by -*-*.
1973 - the same but with the family also replaced with -*-*-. */
1974 const char *p = base_fontname;
1975 int i;
1977 for (i = 0; *p; p++)
1978 if (*p == '-') i++;
1979 if (i != 14)
1980 { /* As the font name doesn't conform to XLFD, we can't
1981 modify it to generalize it to allcs and allfamilies.
1982 Use the specified font plus the default. */
1983 int len = strlen (base_fontname) + strlen (xic_defaut_fontset) + 3;
1984 fontsetname = xmalloc (len);
1985 memset (fontsetname, 0, len);
1986 strcpy (fontsetname, base_fontname);
1987 strcat (fontsetname, sep);
1988 strcat (fontsetname, xic_defaut_fontset);
1990 else
1992 int len;
1993 const char *p1 = NULL, *p2 = NULL, *p3 = NULL;
1994 char *font_allcs = NULL;
1995 char *font_allfamilies = NULL;
1996 char *font_all = NULL;
1997 const char *allcs = "*-*-*-*-*-*-*";
1998 const char *allfamilies = "-*-*-";
1999 const char *all = "*-*-*-*-";
2000 char *base;
2002 for (i = 0, p = base_fontname; i < 8; p++)
2004 if (*p == '-')
2006 i++;
2007 if (i == 3)
2008 p1 = p + 1;
2009 else if (i == 7)
2010 p2 = p + 1;
2011 else if (i == 6)
2012 p3 = p + 1;
2015 /* If base_fontname specifies ADSTYLE, make it a
2016 wildcard. */
2017 if (*p3 != '*')
2019 int diff = (p2 - p3) - 2;
2021 base = alloca (strlen (base_fontname) + 1);
2022 memcpy (base, base_fontname, p3 - base_fontname);
2023 base[p3 - base_fontname] = '*';
2024 base[(p3 - base_fontname) + 1] = '-';
2025 strcpy (base + (p3 - base_fontname) + 2, p2);
2026 p = base + (p - base_fontname) - diff;
2027 p1 = base + (p1 - base_fontname);
2028 p2 = base + (p2 - base_fontname) - diff;
2029 base_fontname = base;
2032 /* Build the font spec that matches all charsets. */
2033 len = p - base_fontname + strlen (allcs) + 1;
2034 font_allcs = (char *) alloca (len);
2035 memset (font_allcs, 0, len);
2036 memcpy (font_allcs, base_fontname, p - base_fontname);
2037 strcat (font_allcs, allcs);
2039 /* Build the font spec that matches all families and
2040 add-styles. */
2041 len = p - p1 + strlen (allcs) + strlen (allfamilies) + 1;
2042 font_allfamilies = (char *) alloca (len);
2043 memset (font_allfamilies, 0, len);
2044 strcpy (font_allfamilies, allfamilies);
2045 memcpy (font_allfamilies + strlen (allfamilies), p1, p - p1);
2046 strcat (font_allfamilies, allcs);
2048 /* Build the font spec that matches all. */
2049 len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1;
2050 font_all = (char *) alloca (len);
2051 memset (font_all, 0, len);
2052 strcpy (font_all, allfamilies);
2053 strcat (font_all, all);
2054 memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2);
2055 strcat (font_all, allcs);
2057 /* Build the actual font set name. */
2058 len = strlen (base_fontname) + strlen (font_allcs)
2059 + strlen (font_allfamilies) + strlen (font_all) + 5;
2060 fontsetname = xmalloc (len);
2061 memset (fontsetname, 0, len);
2062 strcpy (fontsetname, base_fontname);
2063 strcat (fontsetname, sep);
2064 strcat (fontsetname, font_allcs);
2065 strcat (fontsetname, sep);
2066 strcat (fontsetname, font_allfamilies);
2067 strcat (fontsetname, sep);
2068 strcat (fontsetname, font_all);
2071 if (motif)
2072 strcat (fontsetname, ":");
2073 return fontsetname;
2076 #ifdef DEBUG_XIC_FONTSET
2077 static void
2078 print_fontset_result (xfs, name, missing_list, missing_count)
2079 XFontSet xfs;
2080 char *name;
2081 char **missing_list;
2082 int missing_count;
2084 if (xfs)
2085 fprintf (stderr, "XIC Fontset created: %s\n", name);
2086 else
2088 fprintf (stderr, "XIC Fontset failed: %s\n", name);
2089 while (missing_count-- > 0)
2091 fprintf (stderr, " missing: %s\n", *missing_list);
2092 missing_list++;
2097 #endif
2099 static XFontSet
2100 xic_create_xfontset (struct frame *f)
2102 XFontSet xfs = NULL;
2103 struct font *font = FRAME_FONT (f);
2104 int pixel_size = font->pixel_size;
2105 Lisp_Object rest, frame;
2107 /* See if there is another frame already using same fontset. */
2108 FOR_EACH_FRAME (rest, frame)
2110 struct frame *cf = XFRAME (frame);
2112 if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
2113 && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
2114 && FRAME_FONT (f)
2115 && FRAME_FONT (f)->pixel_size == pixel_size)
2117 xfs = FRAME_XIC_FONTSET (cf);
2118 break;
2122 if (! xfs)
2124 char buf[256];
2125 char **missing_list;
2126 int missing_count;
2127 char *def_string;
2128 const char *xlfd_format = "-*-*-medium-r-normal--%d-*-*-*-*-*";
2130 sprintf (buf, xlfd_format, pixel_size);
2131 missing_list = NULL;
2132 xfs = XCreateFontSet (FRAME_X_DISPLAY (f), buf,
2133 &missing_list, &missing_count, &def_string);
2134 #ifdef DEBUG_XIC_FONTSET
2135 print_fontset_result (xfs, buf, missing_list, missing_count);
2136 #endif
2137 if (missing_list)
2138 XFreeStringList (missing_list);
2139 if (! xfs)
2141 /* List of pixel sizes most likely available. Find one that
2142 is closest to pixel_size. */
2143 int sizes[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
2144 int *smaller, *larger;
2146 for (smaller = sizes; smaller[1]; smaller++)
2147 if (smaller[1] >= pixel_size)
2148 break;
2149 larger = smaller + 1;
2150 if (*larger == pixel_size)
2151 larger++;
2152 while (*smaller || *larger)
2154 int this_size;
2156 if (! *larger)
2157 this_size = *smaller--;
2158 else if (! *smaller)
2159 this_size = *larger++;
2160 else if (pixel_size - *smaller < *larger - pixel_size)
2161 this_size = *smaller--;
2162 else
2163 this_size = *larger++;
2164 sprintf (buf, xlfd_format, this_size);
2165 missing_list = NULL;
2166 xfs = XCreateFontSet (FRAME_X_DISPLAY (f), buf,
2167 &missing_list, &missing_count, &def_string);
2168 #ifdef DEBUG_XIC_FONTSET
2169 print_fontset_result (xfs, buf, missing_list, missing_count);
2170 #endif
2171 if (missing_list)
2172 XFreeStringList (missing_list);
2173 if (xfs)
2174 break;
2177 if (! xfs)
2179 const char *last_resort = "-*-*-*-r-normal--*-*-*-*-*-*";
2181 missing_list = NULL;
2182 xfs = XCreateFontSet (FRAME_X_DISPLAY (f), last_resort,
2183 &missing_list, &missing_count, &def_string);
2184 #ifdef DEBUG_XIC_FONTSET
2185 print_fontset_result (xfs, last_resort, missing_list, missing_count);
2186 #endif
2187 if (missing_list)
2188 XFreeStringList (missing_list);
2193 return xfs;
2196 /* Free the X fontset of frame F if it is the last frame using it. */
2198 void
2199 xic_free_xfontset (struct frame *f)
2201 Lisp_Object rest, frame;
2202 int shared_p = 0;
2204 if (!FRAME_XIC_FONTSET (f))
2205 return;
2207 /* See if there is another frame sharing the same fontset. */
2208 FOR_EACH_FRAME (rest, frame)
2210 struct frame *cf = XFRAME (frame);
2211 if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
2212 && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
2213 && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f))
2215 shared_p = 1;
2216 break;
2220 if (!shared_p)
2221 /* The fontset is not used anymore. It is safe to free it. */
2222 XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
2224 if (FRAME_XIC_BASE_FONTNAME (f))
2225 xfree (FRAME_XIC_BASE_FONTNAME (f));
2226 FRAME_XIC_BASE_FONTNAME (f) = NULL;
2227 FRAME_XIC_FONTSET (f) = NULL;
2231 /* Value is the best input style, given user preferences USER (already
2232 checked to be supported by Emacs), and styles supported by the
2233 input method XIM. */
2235 static XIMStyle
2236 best_xim_style (XIMStyles *user, XIMStyles *xim)
2238 int i, j;
2240 for (i = 0; i < user->count_styles; ++i)
2241 for (j = 0; j < xim->count_styles; ++j)
2242 if (user->supported_styles[i] == xim->supported_styles[j])
2243 return user->supported_styles[i];
2245 /* Return the default style. */
2246 return XIMPreeditNothing | XIMStatusNothing;
2249 /* Create XIC for frame F. */
2251 static XIMStyle xic_style;
2253 void
2254 create_frame_xic (struct frame *f)
2256 XIM xim;
2257 XIC xic = NULL;
2258 XFontSet xfs = NULL;
2260 if (FRAME_XIC (f))
2261 return;
2263 /* Create X fontset. */
2264 xfs = xic_create_xfontset (f);
2265 xim = FRAME_X_XIM (f);
2266 if (xim)
2268 XRectangle s_area;
2269 XPoint spot;
2270 XVaNestedList preedit_attr;
2271 XVaNestedList status_attr;
2273 s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1;
2274 spot.x = 0; spot.y = 1;
2276 /* Determine XIC style. */
2277 if (xic_style == 0)
2279 XIMStyles supported_list;
2280 supported_list.count_styles = (sizeof supported_xim_styles
2281 / sizeof supported_xim_styles[0]);
2282 supported_list.supported_styles = supported_xim_styles;
2283 xic_style = best_xim_style (&supported_list,
2284 FRAME_X_XIM_STYLES (f));
2287 preedit_attr = XVaCreateNestedList (0,
2288 XNFontSet, xfs,
2289 XNForeground,
2290 FRAME_FOREGROUND_PIXEL (f),
2291 XNBackground,
2292 FRAME_BACKGROUND_PIXEL (f),
2293 (xic_style & XIMPreeditPosition
2294 ? XNSpotLocation
2295 : NULL),
2296 &spot,
2297 NULL);
2298 status_attr = XVaCreateNestedList (0,
2299 XNArea,
2300 &s_area,
2301 XNFontSet,
2302 xfs,
2303 XNForeground,
2304 FRAME_FOREGROUND_PIXEL (f),
2305 XNBackground,
2306 FRAME_BACKGROUND_PIXEL (f),
2307 NULL);
2309 xic = XCreateIC (xim,
2310 XNInputStyle, xic_style,
2311 XNClientWindow, FRAME_X_WINDOW (f),
2312 XNFocusWindow, FRAME_X_WINDOW (f),
2313 XNStatusAttributes, status_attr,
2314 XNPreeditAttributes, preedit_attr,
2315 NULL);
2316 XFree (preedit_attr);
2317 XFree (status_attr);
2320 FRAME_XIC (f) = xic;
2321 FRAME_XIC_STYLE (f) = xic_style;
2322 FRAME_XIC_FONTSET (f) = xfs;
2326 /* Destroy XIC and free XIC fontset of frame F, if any. */
2328 void
2329 free_frame_xic (struct frame *f)
2331 if (FRAME_XIC (f) == NULL)
2332 return;
2334 XDestroyIC (FRAME_XIC (f));
2335 xic_free_xfontset (f);
2337 FRAME_XIC (f) = NULL;
2341 /* Place preedit area for XIC of window W's frame to specified
2342 pixel position X/Y. X and Y are relative to window W. */
2344 void
2345 xic_set_preeditarea (struct window *w, int x, int y)
2347 struct frame *f = XFRAME (w->frame);
2348 XVaNestedList attr;
2349 XPoint spot;
2351 spot.x = WINDOW_TO_FRAME_PIXEL_X (w, x) + WINDOW_LEFT_FRINGE_WIDTH (w);
2352 spot.y = WINDOW_TO_FRAME_PIXEL_Y (w, y) + FONT_BASE (FRAME_FONT (f));
2353 attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
2354 XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL);
2355 XFree (attr);
2359 /* Place status area for XIC in bottom right corner of frame F.. */
2361 void
2362 xic_set_statusarea (struct frame *f)
2364 XIC xic = FRAME_XIC (f);
2365 XVaNestedList attr;
2366 XRectangle area;
2367 XRectangle *needed;
2369 /* Negotiate geometry of status area. If input method has existing
2370 status area, use its current size. */
2371 area.x = area.y = area.width = area.height = 0;
2372 attr = XVaCreateNestedList (0, XNAreaNeeded, &area, NULL);
2373 XSetICValues (xic, XNStatusAttributes, attr, NULL);
2374 XFree (attr);
2376 attr = XVaCreateNestedList (0, XNAreaNeeded, &needed, NULL);
2377 XGetICValues (xic, XNStatusAttributes, attr, NULL);
2378 XFree (attr);
2380 if (needed->width == 0) /* Use XNArea instead of XNAreaNeeded */
2382 attr = XVaCreateNestedList (0, XNArea, &needed, NULL);
2383 XGetICValues (xic, XNStatusAttributes, attr, NULL);
2384 XFree (attr);
2387 area.width = needed->width;
2388 area.height = needed->height;
2389 area.x = FRAME_PIXEL_WIDTH (f) - area.width - FRAME_INTERNAL_BORDER_WIDTH (f);
2390 area.y = (FRAME_PIXEL_HEIGHT (f) - area.height
2391 - FRAME_MENUBAR_HEIGHT (f)
2392 - FRAME_TOOLBAR_TOP_HEIGHT (f)
2393 - FRAME_INTERNAL_BORDER_WIDTH (f));
2394 XFree (needed);
2396 attr = XVaCreateNestedList (0, XNArea, &area, NULL);
2397 XSetICValues (xic, XNStatusAttributes, attr, NULL);
2398 XFree (attr);
2402 /* Set X fontset for XIC of frame F, using base font name
2403 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2405 void
2406 xic_set_xfontset (struct frame *f, const char *base_fontname)
2408 XVaNestedList attr;
2409 XFontSet xfs;
2411 xic_free_xfontset (f);
2413 xfs = xic_create_xfontset (f);
2415 attr = XVaCreateNestedList (0, XNFontSet, xfs, NULL);
2416 if (FRAME_XIC_STYLE (f) & XIMPreeditPosition)
2417 XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL);
2418 if (FRAME_XIC_STYLE (f) & XIMStatusArea)
2419 XSetICValues (FRAME_XIC (f), XNStatusAttributes, attr, NULL);
2420 XFree (attr);
2422 FRAME_XIC_FONTSET (f) = xfs;
2425 #endif /* HAVE_X_I18N */
2429 #ifdef USE_X_TOOLKIT
2431 /* Create and set up the X widget for frame F. */
2433 static void
2434 x_window (struct frame *f, long window_prompting, int minibuffer_only)
2436 XClassHint class_hints;
2437 XSetWindowAttributes attributes;
2438 unsigned long attribute_mask;
2439 Widget shell_widget;
2440 Widget pane_widget;
2441 Widget frame_widget;
2442 Arg al [25];
2443 int ac;
2445 BLOCK_INPUT;
2447 /* Use the resource name as the top-level widget name
2448 for looking up resources. Make a non-Lisp copy
2449 for the window manager, so GC relocation won't bother it.
2451 Elsewhere we specify the window name for the window manager. */
2454 char *str = (char *) SDATA (Vx_resource_name);
2455 f->namebuf = (char *) xmalloc (strlen (str) + 1);
2456 strcpy (f->namebuf, str);
2459 ac = 0;
2460 XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
2461 XtSetArg (al[ac], XtNinput, 1); ac++;
2462 XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
2463 XtSetArg (al[ac], XtNborderWidth, f->border_width); ac++;
2464 XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
2465 XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
2466 XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
2467 shell_widget = XtAppCreateShell (f->namebuf, EMACS_CLASS,
2468 applicationShellWidgetClass,
2469 FRAME_X_DISPLAY (f), al, ac);
2471 f->output_data.x->widget = shell_widget;
2472 /* maybe_set_screen_title_format (shell_widget); */
2474 pane_widget = lw_create_widget ("main", "pane", widget_id_tick++,
2475 (widget_value *) NULL,
2476 shell_widget, False,
2477 (lw_callback) NULL,
2478 (lw_callback) NULL,
2479 (lw_callback) NULL,
2480 (lw_callback) NULL);
2482 ac = 0;
2483 XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
2484 XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
2485 XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
2486 XtSetArg (al[ac], XtNborderWidth, 0); ac++;
2487 XtSetValues (pane_widget, al, ac);
2488 f->output_data.x->column_widget = pane_widget;
2490 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2491 the emacs screen when changing menubar. This reduces flickering. */
2493 ac = 0;
2494 XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
2495 XtSetArg (al[ac], XtNshowGrip, 0); ac++;
2496 XtSetArg (al[ac], XtNallowResize, 1); ac++;
2497 XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
2498 XtSetArg (al[ac], XtNemacsFrame, f); ac++;
2499 XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
2500 XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
2501 XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
2502 XtSetArg (al[ac], XtNborderWidth, 0); ac++;
2503 frame_widget = XtCreateWidget (f->namebuf, emacsFrameClass, pane_widget,
2504 al, ac);
2506 f->output_data.x->edit_widget = frame_widget;
2508 XtManageChild (frame_widget);
2510 /* Do some needed geometry management. */
2512 int len;
2513 char *tem, shell_position[32];
2514 Arg al[10];
2515 int ac = 0;
2516 int extra_borders = 0;
2517 int menubar_size
2518 = (f->output_data.x->menubar_widget
2519 ? (f->output_data.x->menubar_widget->core.height
2520 + f->output_data.x->menubar_widget->core.border_width)
2521 : 0);
2523 #if 0 /* Experimentally, we now get the right results
2524 for -geometry -0-0 without this. 24 Aug 96, rms. */
2525 if (FRAME_EXTERNAL_MENU_BAR (f))
2527 Dimension ibw = 0;
2528 XtVaGetValues (pane_widget, XtNinternalBorderWidth, &ibw, NULL);
2529 menubar_size += ibw;
2531 #endif
2533 f->output_data.x->menubar_height = menubar_size;
2535 #ifndef USE_LUCID
2536 /* Motif seems to need this amount added to the sizes
2537 specified for the shell widget. The Athena/Lucid widgets don't.
2538 Both conclusions reached experimentally. -- rms. */
2539 XtVaGetValues (f->output_data.x->edit_widget, XtNinternalBorderWidth,
2540 &extra_borders, NULL);
2541 extra_borders *= 2;
2542 #endif
2544 /* Convert our geometry parameters into a geometry string
2545 and specify it.
2546 Note that we do not specify here whether the position
2547 is a user-specified or program-specified one.
2548 We pass that information later, in x_wm_set_size_hints. */
2550 int left = f->left_pos;
2551 int xneg = window_prompting & XNegative;
2552 int top = f->top_pos;
2553 int yneg = window_prompting & YNegative;
2554 if (xneg)
2555 left = -left;
2556 if (yneg)
2557 top = -top;
2559 if (window_prompting & USPosition)
2560 sprintf (shell_position, "=%dx%d%c%d%c%d",
2561 FRAME_PIXEL_WIDTH (f) + extra_borders,
2562 FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders,
2563 (xneg ? '-' : '+'), left,
2564 (yneg ? '-' : '+'), top);
2565 else
2567 sprintf (shell_position, "=%dx%d",
2568 FRAME_PIXEL_WIDTH (f) + extra_borders,
2569 FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders);
2571 /* Setting x and y when the position is not specified in
2572 the geometry string will set program position in the WM hints.
2573 If Emacs had just one program position, we could set it in
2574 fallback resources, but since each make-frame call can specify
2575 different program positions, this is easier. */
2576 XtSetArg (al[ac], XtNx, left); ac++;
2577 XtSetArg (al[ac], XtNy, top); ac++;
2581 len = strlen (shell_position) + 1;
2582 /* We don't free this because we don't know whether
2583 it is safe to free it while the frame exists.
2584 It isn't worth the trouble of arranging to free it
2585 when the frame is deleted. */
2586 tem = (char *) xmalloc (len);
2587 strncpy (tem, shell_position, len);
2588 XtSetArg (al[ac], XtNgeometry, tem); ac++;
2589 XtSetValues (shell_widget, al, ac);
2592 XtManageChild (pane_widget);
2593 XtRealizeWidget (shell_widget);
2595 if (FRAME_X_EMBEDDED_P (f))
2596 XReparentWindow (FRAME_X_DISPLAY (f), XtWindow (shell_widget),
2597 f->output_data.x->parent_desc, 0, 0);
2599 FRAME_X_WINDOW (f) = XtWindow (frame_widget);
2601 validate_x_resource_name ();
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), XtWindow (shell_widget), &class_hints);
2607 #ifdef HAVE_X_I18N
2608 FRAME_XIC (f) = NULL;
2609 if (use_xim)
2610 create_frame_xic (f);
2611 #endif
2613 f->output_data.x->wm_hints.input = True;
2614 f->output_data.x->wm_hints.flags |= InputHint;
2615 XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2616 &f->output_data.x->wm_hints);
2618 hack_wm_protocols (f, shell_widget);
2620 #ifdef HACK_EDITRES
2621 XtAddEventHandler (shell_widget, 0, True, _XEditResCheckMessages, 0);
2622 #endif
2624 /* Do a stupid property change to force the server to generate a
2625 PropertyNotify event so that the event_stream server timestamp will
2626 be initialized to something relevant to the time we created the window.
2628 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
2629 FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
2630 XA_ATOM, 32, PropModeAppend,
2631 (unsigned char*) NULL, 0);
2633 /* Make all the standard events reach the Emacs frame. */
2634 attributes.event_mask = STANDARD_EVENT_SET;
2636 #ifdef HAVE_X_I18N
2637 if (FRAME_XIC (f))
2639 /* XIM server might require some X events. */
2640 unsigned long fevent = NoEventMask;
2641 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2642 attributes.event_mask |= fevent;
2644 #endif /* HAVE_X_I18N */
2646 attribute_mask = CWEventMask;
2647 XChangeWindowAttributes (XtDisplay (shell_widget), XtWindow (shell_widget),
2648 attribute_mask, &attributes);
2650 XtMapWidget (frame_widget);
2652 /* x_set_name normally ignores requests to set the name if the
2653 requested name is the same as the current name. This is the one
2654 place where that assumption isn't correct; f->name is set, but
2655 the X server hasn't been told. */
2657 Lisp_Object name;
2658 int explicit = f->explicit_name;
2660 f->explicit_name = 0;
2661 name = f->name;
2662 f->name = Qnil;
2663 x_set_name (f, name, explicit);
2666 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2667 f->output_data.x->current_cursor
2668 = f->output_data.x->text_cursor);
2670 UNBLOCK_INPUT;
2672 /* This is a no-op, except under Motif. Make sure main areas are
2673 set to something reasonable, in case we get an error later. */
2674 lw_set_main_areas (pane_widget, 0, frame_widget);
2677 #else /* not USE_X_TOOLKIT */
2678 #ifdef USE_GTK
2679 void
2680 x_window (FRAME_PTR f)
2682 if (! xg_create_frame_widgets (f))
2683 error ("Unable to create window");
2685 #ifdef HAVE_X_I18N
2686 FRAME_XIC (f) = NULL;
2687 if (use_xim)
2689 BLOCK_INPUT;
2690 create_frame_xic (f);
2691 if (FRAME_XIC (f))
2693 /* XIM server might require some X events. */
2694 unsigned long fevent = NoEventMask;
2695 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2697 if (fevent != NoEventMask)
2699 XSetWindowAttributes attributes;
2700 XWindowAttributes wattr;
2701 unsigned long attribute_mask;
2703 XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2704 &wattr);
2705 attributes.event_mask = wattr.your_event_mask | fevent;
2706 attribute_mask = CWEventMask;
2707 XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2708 attribute_mask, &attributes);
2711 UNBLOCK_INPUT;
2713 #endif
2716 #else /*! USE_GTK */
2717 /* Create and set up the X window for frame F. */
2719 void
2720 x_window (struct frame *f)
2722 XClassHint class_hints;
2723 XSetWindowAttributes attributes;
2724 unsigned long attribute_mask;
2726 attributes.background_pixel = FRAME_BACKGROUND_PIXEL (f);
2727 attributes.border_pixel = f->output_data.x->border_pixel;
2728 attributes.bit_gravity = StaticGravity;
2729 attributes.backing_store = NotUseful;
2730 attributes.save_under = True;
2731 attributes.event_mask = STANDARD_EVENT_SET;
2732 attributes.colormap = FRAME_X_COLORMAP (f);
2733 attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
2734 | CWColormap);
2736 BLOCK_INPUT;
2737 FRAME_X_WINDOW (f)
2738 = XCreateWindow (FRAME_X_DISPLAY (f),
2739 f->output_data.x->parent_desc,
2740 f->left_pos,
2741 f->top_pos,
2742 FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f),
2743 f->border_width,
2744 CopyFromParent, /* depth */
2745 InputOutput, /* class */
2746 FRAME_X_VISUAL (f),
2747 attribute_mask, &attributes);
2749 #ifdef HAVE_X_I18N
2750 if (use_xim)
2752 create_frame_xic (f);
2753 if (FRAME_XIC (f))
2755 /* XIM server might require some X events. */
2756 unsigned long fevent = NoEventMask;
2757 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2758 attributes.event_mask |= fevent;
2759 attribute_mask = CWEventMask;
2760 XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2761 attribute_mask, &attributes);
2764 #endif /* HAVE_X_I18N */
2766 validate_x_resource_name ();
2768 class_hints.res_name = (char *) SDATA (Vx_resource_name);
2769 class_hints.res_class = (char *) SDATA (Vx_resource_class);
2770 XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints);
2772 /* The menubar is part of the ordinary display;
2773 it does not count in addition to the height of the window. */
2774 f->output_data.x->menubar_height = 0;
2776 /* This indicates that we use the "Passive Input" input model.
2777 Unless we do this, we don't get the Focus{In,Out} events that we
2778 need to draw the cursor correctly. Accursed bureaucrats.
2779 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2781 f->output_data.x->wm_hints.input = True;
2782 f->output_data.x->wm_hints.flags |= InputHint;
2783 XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2784 &f->output_data.x->wm_hints);
2785 f->output_data.x->wm_hints.icon_pixmap = None;
2787 /* Request "save yourself" and "delete window" commands from wm. */
2789 Atom protocols[2];
2790 protocols[0] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
2791 protocols[1] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
2792 XSetWMProtocols (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), protocols, 2);
2795 /* x_set_name normally ignores requests to set the name if the
2796 requested name is the same as the current name. This is the one
2797 place where that assumption isn't correct; f->name is set, but
2798 the X server hasn't been told. */
2800 Lisp_Object name;
2801 int explicit = f->explicit_name;
2803 f->explicit_name = 0;
2804 name = f->name;
2805 f->name = Qnil;
2806 x_set_name (f, name, explicit);
2809 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2810 f->output_data.x->current_cursor
2811 = f->output_data.x->text_cursor);
2813 UNBLOCK_INPUT;
2815 if (FRAME_X_WINDOW (f) == 0)
2816 error ("Unable to create window");
2819 #endif /* not USE_GTK */
2820 #endif /* not USE_X_TOOLKIT */
2822 /* Verify that the icon position args for this window are valid. */
2824 static void
2825 x_icon_verify (struct frame *f, Lisp_Object parms)
2827 Lisp_Object icon_x, icon_y;
2829 /* Set the position of the icon. Note that twm groups all
2830 icons in an icon window. */
2831 icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
2832 icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
2833 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
2835 CHECK_NUMBER (icon_x);
2836 CHECK_NUMBER (icon_y);
2838 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2839 error ("Both left and top icon corners of icon must be specified");
2842 /* Handle the icon stuff for this window. Perhaps later we might
2843 want an x_set_icon_position which can be called interactively as
2844 well. */
2846 static void
2847 x_icon (struct frame *f, Lisp_Object parms)
2849 Lisp_Object icon_x, icon_y;
2850 #if 0
2851 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2852 #endif
2854 /* Set the position of the icon. Note that twm groups all
2855 icons in an icon window. */
2856 icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
2857 icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
2858 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
2860 CHECK_NUMBER (icon_x);
2861 CHECK_NUMBER (icon_y);
2863 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2864 error ("Both left and top icon corners of icon must be specified");
2866 BLOCK_INPUT;
2868 if (! EQ (icon_x, Qunbound))
2869 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y));
2871 #if 0 /* x_get_arg removes the visibility parameter as a side effect,
2872 but x_create_frame still needs it. */
2873 /* Start up iconic or window? */
2874 x_wm_set_window_state
2875 (f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL),
2876 Qicon)
2877 ? IconicState
2878 : NormalState));
2879 #endif
2881 x_text_icon (f, (char *) SDATA ((!NILP (f->icon_name)
2882 ? f->icon_name
2883 : f->name)));
2885 UNBLOCK_INPUT;
2888 /* Make the GCs needed for this window, setting the
2889 background, border and mouse colors; also create the
2890 mouse cursor and the gray border tile. */
2892 static void
2893 x_make_gc (struct frame *f)
2895 XGCValues gc_values;
2897 BLOCK_INPUT;
2899 /* Create the GCs of this frame.
2900 Note that many default values are used. */
2902 gc_values.foreground = FRAME_FOREGROUND_PIXEL (f);
2903 gc_values.background = FRAME_BACKGROUND_PIXEL (f);
2904 gc_values.line_width = 0; /* Means 1 using fast algorithm. */
2905 f->output_data.x->normal_gc
2906 = XCreateGC (FRAME_X_DISPLAY (f),
2907 FRAME_X_WINDOW (f),
2908 GCLineWidth | GCForeground | GCBackground,
2909 &gc_values);
2911 /* Reverse video style. */
2912 gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
2913 gc_values.background = FRAME_FOREGROUND_PIXEL (f);
2914 f->output_data.x->reverse_gc
2915 = XCreateGC (FRAME_X_DISPLAY (f),
2916 FRAME_X_WINDOW (f),
2917 GCForeground | GCBackground | GCLineWidth,
2918 &gc_values);
2920 /* Cursor has cursor-color background, background-color foreground. */
2921 gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
2922 gc_values.background = f->output_data.x->cursor_pixel;
2923 gc_values.fill_style = FillOpaqueStippled;
2924 f->output_data.x->cursor_gc
2925 = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2926 (GCForeground | GCBackground
2927 | GCFillStyle | GCLineWidth),
2928 &gc_values);
2930 /* Reliefs. */
2931 f->output_data.x->white_relief.gc = 0;
2932 f->output_data.x->black_relief.gc = 0;
2934 /* Create the gray border tile used when the pointer is not in
2935 the frame. Since this depends on the frame's pixel values,
2936 this must be done on a per-frame basis. */
2937 f->output_data.x->border_tile
2938 = (XCreatePixmapFromBitmapData
2939 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
2940 gray_bits, gray_width, gray_height,
2941 FRAME_FOREGROUND_PIXEL (f),
2942 FRAME_BACKGROUND_PIXEL (f),
2943 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
2945 UNBLOCK_INPUT;
2949 /* Free what was allocated in x_make_gc. */
2951 void
2952 x_free_gcs (struct frame *f)
2954 Display *dpy = FRAME_X_DISPLAY (f);
2956 BLOCK_INPUT;
2958 if (f->output_data.x->normal_gc)
2960 XFreeGC (dpy, f->output_data.x->normal_gc);
2961 f->output_data.x->normal_gc = 0;
2964 if (f->output_data.x->reverse_gc)
2966 XFreeGC (dpy, f->output_data.x->reverse_gc);
2967 f->output_data.x->reverse_gc = 0;
2970 if (f->output_data.x->cursor_gc)
2972 XFreeGC (dpy, f->output_data.x->cursor_gc);
2973 f->output_data.x->cursor_gc = 0;
2976 if (f->output_data.x->border_tile)
2978 XFreePixmap (dpy, f->output_data.x->border_tile);
2979 f->output_data.x->border_tile = 0;
2982 UNBLOCK_INPUT;
2986 /* Handler for signals raised during x_create_frame and
2987 x_create_top_frame. FRAME is the frame which is partially
2988 constructed. */
2990 static Lisp_Object
2991 unwind_create_frame (Lisp_Object frame)
2993 struct frame *f = XFRAME (frame);
2995 /* If frame is already dead, nothing to do. This can happen if the
2996 display is disconnected after the frame has become official, but
2997 before x_create_frame removes the unwind protect. */
2998 if (!FRAME_LIVE_P (f))
2999 return Qnil;
3001 /* If frame is ``official'', nothing to do. */
3002 if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame))
3004 #if GLYPH_DEBUG
3005 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3006 #endif
3008 x_free_frame_resources (f);
3010 #if GLYPH_DEBUG
3011 /* Check that reference counts are indeed correct. */
3012 xassert (dpyinfo->reference_count == dpyinfo_refcount);
3013 xassert (dpyinfo->image_cache->refcount == image_cache_refcount);
3014 #endif
3015 return Qt;
3018 return Qnil;
3022 static void
3023 x_default_font_parameter (struct frame *f, Lisp_Object parms)
3025 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3026 Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
3027 RES_TYPE_STRING);
3028 Lisp_Object font = Qnil;
3029 if (EQ (font_param, Qunbound))
3030 font_param = Qnil;
3032 if (NILP (font_param))
3034 /* System font should take precedendce over X resources. We suggest this
3035 regardless of font-use-system-font because .emacs may not have been
3036 read yet. */
3037 const char *system_font = xsettings_get_system_font ();
3038 if (system_font)
3040 char *name = xstrdup (system_font);
3041 font = font_open_by_name (f, name);
3042 free (name);
3046 if (NILP (font))
3047 font = !NILP (font_param) ? font_param
3048 : x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING);
3050 if (! FONTP (font) && ! STRINGP (font))
3052 const char *names[]
3054 #ifdef HAVE_XFT
3055 /* This will find the normal Xft font. */
3056 "monospace-10",
3057 #endif
3058 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
3059 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
3060 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
3061 /* This was formerly the first thing tried, but it finds
3062 too many fonts and takes too long. */
3063 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
3064 /* If those didn't work, look for something which will
3065 at least work. */
3066 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
3067 "fixed",
3068 NULL };
3069 int i;
3071 for (i = 0; names[i]; i++)
3073 font = font_open_by_name (f, names[i]);
3074 if (! NILP (font))
3075 break;
3077 if (NILP (font))
3078 error ("No suitable font was found");
3080 else if (!NILP (font_param))
3082 /* Remember the explicit font parameter, so we can re-apply it after
3083 we've applied the `default' face settings. */
3084 x_set_frame_parameters (f, Fcons (Fcons (Qfont_param, font_param), Qnil));
3087 /* This call will make X resources override any system font setting. */
3088 x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
3092 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint, Sx_wm_set_size_hint,
3093 0, 1, 0,
3094 doc: /* Send the size hints for frame FRAME to the window manager.
3095 If FRAME is nil, use the selected frame. */)
3096 (Lisp_Object frame)
3098 struct frame *f;
3099 if (NILP (frame))
3100 frame = selected_frame;
3101 f = XFRAME (frame);
3102 BLOCK_INPUT;
3103 if (FRAME_X_P (f))
3104 x_wm_set_size_hint (f, 0, 0);
3105 UNBLOCK_INPUT;
3106 return Qnil;
3109 static void
3110 set_machine_and_pid_properties (struct frame *f)
3112 long pid = (long) getpid ();
3114 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
3115 XSetWMProperties (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), NULL, NULL,
3116 NULL, 0, NULL, NULL, NULL);
3117 XChangeProperty (FRAME_X_DISPLAY (f),
3118 FRAME_OUTER_WINDOW (f),
3119 XInternAtom (FRAME_X_DISPLAY (f),
3120 "_NET_WM_PID",
3121 False),
3122 XA_CARDINAL, 32, PropModeReplace,
3123 (unsigned char *) &pid, 1);
3126 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
3127 1, 1, 0,
3128 doc: /* Make a new X window, which is called a "frame" in Emacs terms.
3129 Return an Emacs frame object.
3130 PARMS is an alist of frame parameters.
3131 If the parameters specify that the frame should not have a minibuffer,
3132 and do not specify a specific minibuffer window to use,
3133 then `default-minibuffer-frame' must be a frame whose minibuffer can
3134 be shared by the new frame.
3136 This function is an internal primitive--use `make-frame' instead. */)
3137 (Lisp_Object parms)
3139 struct frame *f;
3140 Lisp_Object frame, tem;
3141 Lisp_Object name;
3142 int minibuffer_only = 0;
3143 long window_prompting = 0;
3144 int width, height;
3145 int count = SPECPDL_INDEX ();
3146 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3147 Lisp_Object display;
3148 struct x_display_info *dpyinfo = NULL;
3149 Lisp_Object parent;
3150 struct kboard *kb;
3152 parms = Fcopy_alist (parms);
3154 /* Use this general default value to start with
3155 until we know if this frame has a specified name. */
3156 Vx_resource_name = Vinvocation_name;
3158 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_NUMBER);
3159 if (EQ (display, Qunbound))
3160 display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING);
3161 if (EQ (display, Qunbound))
3162 display = Qnil;
3163 dpyinfo = check_x_display_info (display);
3164 kb = dpyinfo->terminal->kboard;
3166 if (!dpyinfo->terminal->name)
3167 error ("Terminal is not live, can't create new frames on it");
3169 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
3170 if (!STRINGP (name)
3171 && ! EQ (name, Qunbound)
3172 && ! NILP (name))
3173 error ("Invalid frame name--not a string or nil");
3175 if (STRINGP (name))
3176 Vx_resource_name = name;
3178 /* See if parent window is specified. */
3179 parent = x_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER);
3180 if (EQ (parent, Qunbound))
3181 parent = Qnil;
3182 if (! NILP (parent))
3183 CHECK_NUMBER (parent);
3185 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
3186 /* No need to protect DISPLAY because that's not used after passing
3187 it to make_frame_without_minibuffer. */
3188 frame = Qnil;
3189 GCPRO4 (parms, parent, name, frame);
3190 tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
3191 RES_TYPE_SYMBOL);
3192 if (EQ (tem, Qnone) || NILP (tem))
3193 f = make_frame_without_minibuffer (Qnil, kb, display);
3194 else if (EQ (tem, Qonly))
3196 f = make_minibuffer_frame ();
3197 minibuffer_only = 1;
3199 else if (WINDOWP (tem))
3200 f = make_frame_without_minibuffer (tem, kb, display);
3201 else
3202 f = make_frame (1);
3204 XSETFRAME (frame, f);
3206 /* Note that X Windows does support scroll bars. */
3207 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
3209 f->terminal = dpyinfo->terminal;
3210 f->terminal->reference_count++;
3212 f->output_method = output_x_window;
3213 f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
3214 memset (f->output_data.x, 0, sizeof (struct x_output));
3215 f->output_data.x->icon_bitmap = -1;
3216 FRAME_FONTSET (f) = -1;
3217 f->output_data.x->scroll_bar_foreground_pixel = -1;
3218 f->output_data.x->scroll_bar_background_pixel = -1;
3219 #ifdef USE_TOOLKIT_SCROLL_BARS
3220 f->output_data.x->scroll_bar_top_shadow_pixel = -1;
3221 f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
3222 #endif /* USE_TOOLKIT_SCROLL_BARS */
3224 f->icon_name
3225 = x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
3226 RES_TYPE_STRING);
3227 if (! STRINGP (f->icon_name))
3228 f->icon_name = Qnil;
3230 FRAME_X_DISPLAY_INFO (f) = dpyinfo;
3232 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
3233 record_unwind_protect (unwind_create_frame, frame);
3234 #if GLYPH_DEBUG
3235 image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
3236 dpyinfo_refcount = dpyinfo->reference_count;
3237 #endif /* GLYPH_DEBUG */
3239 /* These colors will be set anyway later, but it's important
3240 to get the color reference counts right, so initialize them! */
3242 Lisp_Object black;
3243 struct gcpro gcpro1;
3245 /* Function x_decode_color can signal an error. Make
3246 sure to initialize color slots so that we won't try
3247 to free colors we haven't allocated. */
3248 FRAME_FOREGROUND_PIXEL (f) = -1;
3249 FRAME_BACKGROUND_PIXEL (f) = -1;
3250 f->output_data.x->cursor_pixel = -1;
3251 f->output_data.x->cursor_foreground_pixel = -1;
3252 f->output_data.x->border_pixel = -1;
3253 f->output_data.x->mouse_pixel = -1;
3255 black = build_string ("black");
3256 GCPRO1 (black);
3257 FRAME_FOREGROUND_PIXEL (f)
3258 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3259 FRAME_BACKGROUND_PIXEL (f)
3260 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3261 f->output_data.x->cursor_pixel
3262 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3263 f->output_data.x->cursor_foreground_pixel
3264 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3265 f->output_data.x->border_pixel
3266 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3267 f->output_data.x->mouse_pixel
3268 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3269 UNGCPRO;
3272 /* Specify the parent under which to make this X window. */
3274 if (!NILP (parent))
3276 f->output_data.x->parent_desc = (Window) XFASTINT (parent);
3277 f->output_data.x->explicit_parent = 1;
3279 else
3281 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
3282 f->output_data.x->explicit_parent = 0;
3285 /* Set the name; the functions to which we pass f expect the name to
3286 be set. */
3287 if (EQ (name, Qunbound) || NILP (name))
3289 f->name = build_string (dpyinfo->x_id_name);
3290 f->explicit_name = 0;
3292 else
3294 f->name = name;
3295 f->explicit_name = 1;
3296 /* use the frame's title when getting resources for this frame. */
3297 specbind (Qx_resource_name, name);
3300 f->resx = dpyinfo->resx;
3301 f->resy = dpyinfo->resy;
3303 #ifdef HAVE_FREETYPE
3304 #ifdef HAVE_XFT
3305 register_font_driver (&xftfont_driver, f);
3306 #else /* not HAVE_XFT */
3307 register_font_driver (&ftxfont_driver, f);
3308 #endif /* not HAVE_XFT */
3309 #endif /* HAVE_FREETYPE */
3310 register_font_driver (&xfont_driver, f);
3312 x_default_parameter (f, parms, Qfont_backend, Qnil,
3313 "fontBackend", "FontBackend", RES_TYPE_STRING);
3315 /* Extract the window parameters from the supplied values
3316 that are needed to determine window geometry. */
3317 x_default_font_parameter (f, parms);
3318 if (!FRAME_FONT (f))
3320 delete_frame (frame, Qnoelisp);
3321 error ("Invalid frame font");
3324 /* Frame contents get displaced if an embedded X window has a border. */
3325 if (! FRAME_X_EMBEDDED_P (f))
3326 x_default_parameter (f, parms, Qborder_width, make_number (0),
3327 "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
3329 /* This defaults to 1 in order to match xterm. We recognize either
3330 internalBorderWidth or internalBorder (which is what xterm calls
3331 it). */
3332 if (NILP (Fassq (Qinternal_border_width, parms)))
3334 Lisp_Object value;
3336 value = x_get_arg (dpyinfo, parms, Qinternal_border_width,
3337 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
3338 if (! EQ (value, Qunbound))
3339 parms = Fcons (Fcons (Qinternal_border_width, value),
3340 parms);
3342 x_default_parameter (f, parms, Qinternal_border_width,
3343 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3344 make_number (0),
3345 #else
3346 make_number (1),
3347 #endif
3348 "internalBorderWidth", "internalBorderWidth",
3349 RES_TYPE_NUMBER);
3350 x_default_parameter (f, parms, Qvertical_scroll_bars,
3351 #if defined(USE_GTK) && defined(USE_TOOLKIT_SCROLL_BARS)
3352 Qright,
3353 #else
3354 Qleft,
3355 #endif
3356 "verticalScrollBars", "ScrollBars",
3357 RES_TYPE_SYMBOL);
3359 /* Also do the stuff which must be set before the window exists. */
3360 x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
3361 "foreground", "Foreground", RES_TYPE_STRING);
3362 x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
3363 "background", "Background", RES_TYPE_STRING);
3364 x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
3365 "pointerColor", "Foreground", RES_TYPE_STRING);
3366 x_default_parameter (f, parms, Qborder_color, build_string ("black"),
3367 "borderColor", "BorderColor", RES_TYPE_STRING);
3368 x_default_parameter (f, parms, Qscreen_gamma, Qnil,
3369 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
3370 x_default_parameter (f, parms, Qline_spacing, Qnil,
3371 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
3372 x_default_parameter (f, parms, Qleft_fringe, Qnil,
3373 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
3374 x_default_parameter (f, parms, Qright_fringe, Qnil,
3375 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
3377 x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground,
3378 "scrollBarForeground",
3379 "ScrollBarForeground", 1);
3380 x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background,
3381 "scrollBarBackground",
3382 "ScrollBarBackground", 0);
3384 /* Init faces before x_default_parameter is called for scroll-bar
3385 parameters because that function calls x_set_scroll_bar_width,
3386 which calls change_frame_size, which calls Fset_window_buffer,
3387 which runs hooks, which call Fvertical_motion. At the end, we
3388 end up in init_iterator with a null face cache, which should not
3389 happen. */
3390 init_frame_faces (f);
3392 /* The X resources controlling the menu-bar and tool-bar are
3393 processed specially at startup, and reflected in the mode
3394 variables; ignore them here. */
3395 x_default_parameter (f, parms, Qmenu_bar_lines,
3396 NILP (Vmenu_bar_mode)
3397 ? make_number (0) : make_number (1),
3398 NULL, NULL, RES_TYPE_NUMBER);
3399 x_default_parameter (f, parms, Qtool_bar_lines,
3400 NILP (Vtool_bar_mode)
3401 ? make_number (0) : make_number (1),
3402 NULL, NULL, RES_TYPE_NUMBER);
3404 x_default_parameter (f, parms, Qbuffer_predicate, Qnil,
3405 "bufferPredicate", "BufferPredicate",
3406 RES_TYPE_SYMBOL);
3407 x_default_parameter (f, parms, Qtitle, Qnil,
3408 "title", "Title", RES_TYPE_STRING);
3409 x_default_parameter (f, parms, Qwait_for_wm, Qt,
3410 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN);
3411 x_default_parameter (f, parms, Qfullscreen, Qnil,
3412 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
3413 x_default_parameter (f, parms, Qtool_bar_position,
3414 f->tool_bar_position, 0, 0, RES_TYPE_SYMBOL);
3416 /* Compute the size of the X window. */
3417 window_prompting = x_figure_window_size (f, parms, 1);
3419 tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
3420 f->no_split = minibuffer_only || EQ (tem, Qt);
3422 x_icon_verify (f, parms);
3424 /* Create the X widget or window. */
3425 #ifdef USE_X_TOOLKIT
3426 x_window (f, window_prompting, minibuffer_only);
3427 #else
3428 x_window (f);
3429 #endif
3431 x_icon (f, parms);
3432 x_make_gc (f);
3434 /* Now consider the frame official. */
3435 FRAME_X_DISPLAY_INFO (f)->reference_count++;
3436 Vframe_list = Fcons (frame, Vframe_list);
3438 /* We need to do this after creating the X window, so that the
3439 icon-creation functions can say whose icon they're describing. */
3440 x_default_parameter (f, parms, Qicon_type, Qt,
3441 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
3443 x_default_parameter (f, parms, Qauto_raise, Qnil,
3444 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
3445 x_default_parameter (f, parms, Qauto_lower, Qnil,
3446 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
3447 x_default_parameter (f, parms, Qcursor_type, Qbox,
3448 "cursorType", "CursorType", RES_TYPE_SYMBOL);
3449 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
3450 "scrollBarWidth", "ScrollBarWidth",
3451 RES_TYPE_NUMBER);
3452 x_default_parameter (f, parms, Qalpha, Qnil,
3453 "alpha", "Alpha", RES_TYPE_NUMBER);
3455 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3456 Change will not be effected unless different from the current
3457 FRAME_LINES (f). */
3458 width = FRAME_COLS (f);
3459 height = FRAME_LINES (f);
3461 SET_FRAME_COLS (f, 0);
3462 FRAME_LINES (f) = 0;
3463 change_frame_size (f, height, width, 1, 0, 0);
3465 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3466 /* Create the menu bar. */
3467 if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
3469 /* If this signals an error, we haven't set size hints for the
3470 frame and we didn't make it visible. */
3471 initialize_frame_menubar (f);
3473 #ifndef USE_GTK
3474 /* This is a no-op, except under Motif where it arranges the
3475 main window for the widgets on it. */
3476 lw_set_main_areas (f->output_data.x->column_widget,
3477 f->output_data.x->menubar_widget,
3478 f->output_data.x->edit_widget);
3479 #endif /* not USE_GTK */
3481 #endif /* USE_X_TOOLKIT || USE_GTK */
3483 /* Tell the server what size and position, etc, we want, and how
3484 badly we want them. This should be done after we have the menu
3485 bar so that its size can be taken into account. */
3486 BLOCK_INPUT;
3487 x_wm_set_size_hint (f, window_prompting, 0);
3488 UNBLOCK_INPUT;
3490 /* Make the window appear on the frame and enable display, unless
3491 the caller says not to. However, with explicit parent, Emacs
3492 cannot control visibility, so don't try. */
3493 if (! f->output_data.x->explicit_parent)
3495 Lisp_Object visibility;
3497 visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
3498 RES_TYPE_SYMBOL);
3499 if (EQ (visibility, Qunbound))
3500 visibility = Qt;
3502 if (EQ (visibility, Qicon))
3503 x_iconify_frame (f);
3504 else if (! NILP (visibility))
3505 x_make_frame_visible (f);
3506 else
3507 /* Must have been Qnil. */
3511 BLOCK_INPUT;
3513 /* Set machine name and pid for the purpose of window managers. */
3514 set_machine_and_pid_properties(f);
3516 /* Set the WM leader property. GTK does this itself, so this is not
3517 needed when using GTK. */
3518 if (dpyinfo->client_leader_window != 0)
3520 XChangeProperty (FRAME_X_DISPLAY (f),
3521 FRAME_OUTER_WINDOW (f),
3522 dpyinfo->Xatom_wm_client_leader,
3523 XA_WINDOW, 32, PropModeReplace,
3524 (unsigned char *) &dpyinfo->client_leader_window, 1);
3527 UNBLOCK_INPUT;
3529 /* Initialize `default-minibuffer-frame' in case this is the first
3530 frame on this terminal. */
3531 if (FRAME_HAS_MINIBUF_P (f)
3532 && (!FRAMEP (kb->Vdefault_minibuffer_frame)
3533 || !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame))))
3534 kb->Vdefault_minibuffer_frame = frame;
3536 /* All remaining specified parameters, which have not been "used"
3537 by x_get_arg and friends, now go in the misc. alist of the frame. */
3538 for (tem = parms; CONSP (tem); tem = XCDR (tem))
3539 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
3540 f->param_alist = Fcons (XCAR (tem), f->param_alist);
3542 UNGCPRO;
3544 /* Make sure windows on this frame appear in calls to next-window
3545 and similar functions. */
3546 Vwindow_list = Qnil;
3548 return unbind_to (count, frame);
3552 /* FRAME is used only to get a handle on the X display. We don't pass the
3553 display info directly because we're called from frame.c, which doesn't
3554 know about that structure. */
3556 Lisp_Object
3557 x_get_focus_frame (struct frame *frame)
3559 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (frame);
3560 Lisp_Object xfocus;
3561 if (! dpyinfo->x_focus_frame)
3562 return Qnil;
3564 XSETFRAME (xfocus, dpyinfo->x_focus_frame);
3565 return xfocus;
3569 /* In certain situations, when the window manager follows a
3570 click-to-focus policy, there seems to be no way around calling
3571 XSetInputFocus to give another frame the input focus .
3573 In an ideal world, XSetInputFocus should generally be avoided so
3574 that applications don't interfere with the window manager's focus
3575 policy. But I think it's okay to use when it's clearly done
3576 following a user-command. */
3578 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
3579 doc: /* Set the input focus to FRAME.
3580 FRAME nil means use the selected frame. */)
3581 (Lisp_Object frame)
3583 struct frame *f = check_x_frame (frame);
3584 Display *dpy = FRAME_X_DISPLAY (f);
3586 BLOCK_INPUT;
3587 x_catch_errors (dpy);
3588 XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
3589 RevertToParent, CurrentTime);
3590 x_ewmh_activate_frame (f);
3591 x_uncatch_errors ();
3592 UNBLOCK_INPUT;
3594 return Qnil;
3598 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
3599 doc: /* Internal function called by `color-defined-p', which see
3600 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3601 (Lisp_Object color, Lisp_Object frame)
3603 XColor foo;
3604 FRAME_PTR f = check_x_frame (frame);
3606 CHECK_STRING (color);
3608 if (x_defined_color (f, SDATA (color), &foo, 0))
3609 return Qt;
3610 else
3611 return Qnil;
3614 DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
3615 doc: /* Internal function called by `color-values', which see. */)
3616 (Lisp_Object color, Lisp_Object frame)
3618 XColor foo;
3619 FRAME_PTR f = check_x_frame (frame);
3621 CHECK_STRING (color);
3623 if (x_defined_color (f, SDATA (color), &foo, 0))
3624 return list3 (make_number (foo.red),
3625 make_number (foo.green),
3626 make_number (foo.blue));
3627 else
3628 return Qnil;
3631 DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
3632 doc: /* Internal function called by `display-color-p', which see. */)
3633 (Lisp_Object terminal)
3635 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3637 if (dpyinfo->n_planes <= 2)
3638 return Qnil;
3640 switch (dpyinfo->visual->class)
3642 case StaticColor:
3643 case PseudoColor:
3644 case TrueColor:
3645 case DirectColor:
3646 return Qt;
3648 default:
3649 return Qnil;
3653 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
3654 0, 1, 0,
3655 doc: /* Return t if the X display supports shades of gray.
3656 Note that color displays do support shades of gray.
3657 The optional argument TERMINAL specifies which display to ask about.
3658 TERMINAL should be a terminal object, a frame or a display name (a string).
3659 If omitted or nil, that stands for the selected frame's display. */)
3660 (Lisp_Object terminal)
3662 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3664 if (dpyinfo->n_planes <= 1)
3665 return Qnil;
3667 switch (dpyinfo->visual->class)
3669 case StaticColor:
3670 case PseudoColor:
3671 case TrueColor:
3672 case DirectColor:
3673 case StaticGray:
3674 case GrayScale:
3675 return Qt;
3677 default:
3678 return Qnil;
3682 DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
3683 0, 1, 0,
3684 doc: /* Return the width in pixels of the X display TERMINAL.
3685 The optional argument TERMINAL specifies which display to ask about.
3686 TERMINAL should be a terminal object, a frame or a display name (a string).
3687 If omitted or nil, that stands for the selected frame's display. */)
3688 (Lisp_Object terminal)
3690 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3692 return make_number (x_display_pixel_width (dpyinfo));
3695 DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
3696 Sx_display_pixel_height, 0, 1, 0,
3697 doc: /* Return the height in pixels of the X display TERMINAL.
3698 The optional argument TERMINAL specifies which display to ask about.
3699 TERMINAL should be a terminal object, a frame or a display name (a string).
3700 If omitted or nil, that stands for the selected frame's display. */)
3701 (Lisp_Object terminal)
3703 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3705 return make_number (x_display_pixel_height (dpyinfo));
3708 DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
3709 0, 1, 0,
3710 doc: /* Return the number of bitplanes of the X display TERMINAL.
3711 The optional argument TERMINAL specifies which display to ask about.
3712 TERMINAL should be a terminal object, a frame or a display name (a string).
3713 If omitted or nil, that stands for the selected frame's display. */)
3714 (Lisp_Object terminal)
3716 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3718 return make_number (dpyinfo->n_planes);
3721 DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
3722 0, 1, 0,
3723 doc: /* Return the number of color cells of the X display TERMINAL.
3724 The optional argument TERMINAL specifies which display to ask about.
3725 TERMINAL should be a terminal object, a frame or a display name (a string).
3726 If omitted or nil, that stands for the selected frame's display. */)
3727 (Lisp_Object terminal)
3729 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3731 int nr_planes = DisplayPlanes (dpyinfo->display,
3732 XScreenNumberOfScreen (dpyinfo->screen));
3734 /* Truncate nr_planes to 24 to avoid integer overflow.
3735 Some displays says 32, but only 24 bits are actually significant.
3736 There are only very few and rare video cards that have more than
3737 24 significant bits. Also 24 bits is more than 16 million colors,
3738 it "should be enough for everyone". */
3739 if (nr_planes > 24) nr_planes = 24;
3741 return make_number (1 << nr_planes);
3744 DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
3745 Sx_server_max_request_size,
3746 0, 1, 0,
3747 doc: /* Return the maximum request size of the X server of display TERMINAL.
3748 The optional argument TERMINAL specifies which display to ask about.
3749 TERMINAL should be a terminal object, a frame or a display name (a string).
3750 If omitted or nil, that stands for the selected frame's display. */)
3751 (Lisp_Object terminal)
3753 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3755 return make_number (MAXREQUEST (dpyinfo->display));
3758 DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
3759 doc: /* Return the "vendor ID" string of the X server of display TERMINAL.
3760 \(Labelling every distributor as a "vendor" embodies the false assumption
3761 that operating systems cannot be developed and distributed noncommercially.)
3762 The optional argument TERMINAL specifies which display to ask about.
3763 TERMINAL should be a terminal object, a frame or a display name (a string).
3764 If omitted or nil, that stands for the selected frame's display. */)
3765 (Lisp_Object terminal)
3767 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3768 const char *vendor = ServerVendor (dpyinfo->display);
3770 if (! vendor) vendor = "";
3771 return build_string (vendor);
3774 DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
3775 doc: /* Return the version numbers of the X server of display TERMINAL.
3776 The value is a list of three integers: the major and minor
3777 version numbers of the X Protocol in use, and the distributor-specific release
3778 number. See also the function `x-server-vendor'.
3780 The optional argument TERMINAL specifies which display to ask about.
3781 TERMINAL should be a terminal object, a frame or a display name (a string).
3782 If omitted or nil, that stands for the selected frame's display. */)
3783 (Lisp_Object terminal)
3785 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3786 Display *dpy = dpyinfo->display;
3788 return Fcons (make_number (ProtocolVersion (dpy)),
3789 Fcons (make_number (ProtocolRevision (dpy)),
3790 Fcons (make_number (VendorRelease (dpy)), Qnil)));
3793 DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
3794 doc: /* Return the number of screens on the X server of display TERMINAL.
3795 The optional argument TERMINAL specifies which display to ask about.
3796 TERMINAL should be a terminal object, a frame or a display name (a string).
3797 If omitted or nil, that stands for the selected frame's display. */)
3798 (Lisp_Object terminal)
3800 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3802 return make_number (ScreenCount (dpyinfo->display));
3805 DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
3806 doc: /* Return the height in millimeters of the X display TERMINAL.
3807 The optional argument TERMINAL specifies which display to ask about.
3808 TERMINAL should be a terminal object, a frame or a display name (a string).
3809 If omitted or nil, that stands for the selected frame's display. */)
3810 (Lisp_Object terminal)
3812 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3814 return make_number (HeightMMOfScreen (dpyinfo->screen));
3817 DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
3818 doc: /* Return the width in millimeters of the X display TERMINAL.
3819 The optional argument TERMINAL specifies which display to ask about.
3820 TERMINAL should be a terminal object, a frame or a display name (a string).
3821 If omitted or nil, that stands for the selected frame's display. */)
3822 (Lisp_Object terminal)
3824 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3826 return make_number (WidthMMOfScreen (dpyinfo->screen));
3829 DEFUN ("x-display-backing-store", Fx_display_backing_store,
3830 Sx_display_backing_store, 0, 1, 0,
3831 doc: /* Return an indication of whether X display TERMINAL does backing store.
3832 The value may be `always', `when-mapped', or `not-useful'.
3833 The optional argument TERMINAL specifies which display to ask about.
3834 TERMINAL should be a terminal object, a frame or a display name (a string).
3835 If omitted or nil, that stands for the selected frame's display. */)
3836 (Lisp_Object terminal)
3838 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3839 Lisp_Object result;
3841 switch (DoesBackingStore (dpyinfo->screen))
3843 case Always:
3844 result = intern ("always");
3845 break;
3847 case WhenMapped:
3848 result = intern ("when-mapped");
3849 break;
3851 case NotUseful:
3852 result = intern ("not-useful");
3853 break;
3855 default:
3856 error ("Strange value for BackingStore parameter of screen");
3857 result = Qnil;
3860 return result;
3863 DEFUN ("x-display-visual-class", Fx_display_visual_class,
3864 Sx_display_visual_class, 0, 1, 0,
3865 doc: /* Return the visual class of the X display TERMINAL.
3866 The value is one of the symbols `static-gray', `gray-scale',
3867 `static-color', `pseudo-color', `true-color', or `direct-color'.
3869 The optional argument TERMINAL specifies which display to ask about.
3870 TERMINAL should a terminal object, a frame or a display name (a string).
3871 If omitted or nil, that stands for the selected frame's display. */)
3872 (Lisp_Object terminal)
3874 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3875 Lisp_Object result;
3877 switch (dpyinfo->visual->class)
3879 case StaticGray:
3880 result = intern ("static-gray");
3881 break;
3882 case GrayScale:
3883 result = intern ("gray-scale");
3884 break;
3885 case StaticColor:
3886 result = intern ("static-color");
3887 break;
3888 case PseudoColor:
3889 result = intern ("pseudo-color");
3890 break;
3891 case TrueColor:
3892 result = intern ("true-color");
3893 break;
3894 case DirectColor:
3895 result = intern ("direct-color");
3896 break;
3897 default:
3898 error ("Display has an unknown visual class");
3899 result = Qnil;
3902 return result;
3905 DEFUN ("x-display-save-under", Fx_display_save_under,
3906 Sx_display_save_under, 0, 1, 0,
3907 doc: /* Return t if the X display TERMINAL supports the save-under feature.
3908 The optional argument TERMINAL specifies which display to ask about.
3909 TERMINAL should be a terminal object, a frame or a display name (a string).
3910 If omitted or nil, that stands for the selected frame's display. */)
3911 (Lisp_Object terminal)
3913 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3915 if (DoesSaveUnders (dpyinfo->screen) == True)
3916 return Qt;
3917 else
3918 return Qnil;
3922 x_pixel_width (register struct frame *f)
3924 return FRAME_PIXEL_WIDTH (f);
3928 x_pixel_height (register struct frame *f)
3930 return FRAME_PIXEL_HEIGHT (f);
3934 x_char_width (register struct frame *f)
3936 return FRAME_COLUMN_WIDTH (f);
3940 x_char_height (register struct frame *f)
3942 return FRAME_LINE_HEIGHT (f);
3946 x_screen_planes (register struct frame *f)
3948 return FRAME_X_DISPLAY_INFO (f)->n_planes;
3953 /************************************************************************
3954 X Displays
3955 ************************************************************************/
3958 /* Mapping visual names to visuals. */
3960 static struct visual_class
3962 const char *name;
3963 int class;
3965 visual_classes[] =
3967 {"StaticGray", StaticGray},
3968 {"GrayScale", GrayScale},
3969 {"StaticColor", StaticColor},
3970 {"PseudoColor", PseudoColor},
3971 {"TrueColor", TrueColor},
3972 {"DirectColor", DirectColor},
3973 {NULL, 0}
3977 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3979 /* Value is the screen number of screen SCR. This is a substitute for
3980 the X function with the same name when that doesn't exist. */
3983 XScreenNumberOfScreen (scr)
3984 register Screen *scr;
3986 Display *dpy = scr->display;
3987 int i;
3989 for (i = 0; i < dpy->nscreens; ++i)
3990 if (scr == dpy->screens + i)
3991 break;
3993 return i;
3996 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3999 /* Select the visual that should be used on display DPYINFO. Set
4000 members of DPYINFO appropriately. Called from x_term_init. */
4002 void
4003 select_visual (struct x_display_info *dpyinfo)
4005 Display *dpy = dpyinfo->display;
4006 Screen *screen = dpyinfo->screen;
4007 Lisp_Object value;
4009 /* See if a visual is specified. */
4010 value = display_x_get_resource (dpyinfo,
4011 build_string ("visualClass"),
4012 build_string ("VisualClass"),
4013 Qnil, Qnil);
4014 if (STRINGP (value))
4016 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4017 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4018 depth, a decimal number. NAME is compared with case ignored. */
4019 char *s = (char *) alloca (SBYTES (value) + 1);
4020 char *dash;
4021 int i, class = -1;
4022 XVisualInfo vinfo;
4024 strcpy (s, SDATA (value));
4025 dash = strchr (s, '-');
4026 if (dash)
4028 dpyinfo->n_planes = atoi (dash + 1);
4029 *dash = '\0';
4031 else
4032 /* We won't find a matching visual with depth 0, so that
4033 an error will be printed below. */
4034 dpyinfo->n_planes = 0;
4036 /* Determine the visual class. */
4037 for (i = 0; visual_classes[i].name; ++i)
4038 if (xstrcasecmp (s, visual_classes[i].name) == 0)
4040 class = visual_classes[i].class;
4041 break;
4044 /* Look up a matching visual for the specified class. */
4045 if (class == -1
4046 || !XMatchVisualInfo (dpy, XScreenNumberOfScreen (screen),
4047 dpyinfo->n_planes, class, &vinfo))
4048 fatal ("Invalid visual specification `%s'", SDATA (value));
4050 dpyinfo->visual = vinfo.visual;
4052 else
4054 int n_visuals;
4055 XVisualInfo *vinfo, vinfo_template;
4057 dpyinfo->visual = DefaultVisualOfScreen (screen);
4059 vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual);
4060 vinfo_template.screen = XScreenNumberOfScreen (screen);
4061 vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask,
4062 &vinfo_template, &n_visuals);
4063 if (n_visuals <= 0)
4064 fatal ("Can't get proper X visual info");
4066 dpyinfo->n_planes = vinfo->depth;
4067 XFree ((char *) vinfo);
4072 /* Return the X display structure for the display named NAME.
4073 Open a new connection if necessary. */
4075 struct x_display_info *
4076 x_display_info_for_name (Lisp_Object name)
4078 Lisp_Object names;
4079 struct x_display_info *dpyinfo;
4081 CHECK_STRING (name);
4083 #if 0
4084 if (! EQ (Vinitial_window_system, intern ("x")))
4085 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4086 #endif
4088 for (dpyinfo = x_display_list, names = x_display_name_list;
4089 dpyinfo;
4090 dpyinfo = dpyinfo->next, names = XCDR (names))
4092 Lisp_Object tem;
4093 tem = Fstring_equal (XCAR (XCAR (names)), name);
4094 if (!NILP (tem))
4095 return dpyinfo;
4098 /* Use this general default value to start with. */
4099 Vx_resource_name = Vinvocation_name;
4101 validate_x_resource_name ();
4103 dpyinfo = x_term_init (name, (char *)0,
4104 (char *) SDATA (Vx_resource_name));
4106 if (dpyinfo == 0)
4107 error ("Cannot connect to X server %s", SDATA (name));
4109 x_in_use = 1;
4110 XSETFASTINT (Vwindow_system_version, 11);
4112 return dpyinfo;
4116 DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
4117 1, 3, 0,
4118 doc: /* Open a connection to a display server.
4119 DISPLAY is the name of the display to connect to.
4120 Optional second arg XRM-STRING is a string of resources in xrdb format.
4121 If the optional third arg MUST-SUCCEED is non-nil,
4122 terminate Emacs if we can't open the connection.
4123 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4124 (Lisp_Object display, Lisp_Object xrm_string, Lisp_Object must_succeed)
4126 unsigned char *xrm_option;
4127 struct x_display_info *dpyinfo;
4129 CHECK_STRING (display);
4130 if (! NILP (xrm_string))
4131 CHECK_STRING (xrm_string);
4133 #if 0
4134 if (! EQ (Vinitial_window_system, intern ("x")))
4135 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4136 #endif
4138 if (! NILP (xrm_string))
4139 xrm_option = (unsigned char *) SDATA (xrm_string);
4140 else
4141 xrm_option = (unsigned char *) 0;
4143 validate_x_resource_name ();
4145 /* This is what opens the connection and sets x_current_display.
4146 This also initializes many symbols, such as those used for input. */
4147 dpyinfo = x_term_init (display, xrm_option,
4148 (char *) SDATA (Vx_resource_name));
4150 if (dpyinfo == 0)
4152 if (!NILP (must_succeed))
4153 fatal ("Cannot connect to X server %s.\n\
4154 Check the DISPLAY environment variable or use `-d'.\n\
4155 Also use the `xauth' program to verify that you have the proper\n\
4156 authorization information needed to connect the X server.\n\
4157 An insecure way to solve the problem may be to use `xhost'.\n",
4158 SDATA (display));
4159 else
4160 error ("Cannot connect to X server %s", SDATA (display));
4163 x_in_use = 1;
4165 XSETFASTINT (Vwindow_system_version, 11);
4166 return Qnil;
4169 DEFUN ("x-close-connection", Fx_close_connection,
4170 Sx_close_connection, 1, 1, 0,
4171 doc: /* Close the connection to TERMINAL's X server.
4172 For TERMINAL, specify a terminal object, a frame or a display name (a
4173 string). If TERMINAL is nil, that stands for the selected frame's
4174 terminal. */)
4175 (Lisp_Object terminal)
4177 struct x_display_info *dpyinfo = check_x_display_info (terminal);
4179 if (dpyinfo->reference_count > 0)
4180 error ("Display still has frames on it");
4182 x_delete_terminal (dpyinfo->terminal);
4184 return Qnil;
4187 DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
4188 doc: /* Return the list of display names that Emacs has connections to. */)
4189 (void)
4191 Lisp_Object tail, result;
4193 result = Qnil;
4194 for (tail = x_display_name_list; CONSP (tail); tail = XCDR (tail))
4195 result = Fcons (XCAR (XCAR (tail)), result);
4197 return result;
4200 DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0,
4201 doc: /* If ON is non-nil, report X errors as soon as the erring request is made.
4202 This function only has an effect on X Windows. With MS Windows, it is
4203 defined but does nothing.
4205 If ON is nil, allow buffering of requests.
4206 Turning on synchronization prohibits the Xlib routines from buffering
4207 requests and seriously degrades performance, but makes debugging much
4208 easier.
4209 The optional second argument TERMINAL specifies which display to act on.
4210 TERMINAL should be a terminal object, a frame or a display name (a string).
4211 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4212 (Lisp_Object on, Lisp_Object terminal)
4214 struct x_display_info *dpyinfo = check_x_display_info (terminal);
4216 XSynchronize (dpyinfo->display, !EQ (on, Qnil));
4218 return Qnil;
4221 /* Wait for responses to all X commands issued so far for frame F. */
4223 void
4224 x_sync (FRAME_PTR f)
4226 BLOCK_INPUT;
4227 XSync (FRAME_X_DISPLAY (f), False);
4228 UNBLOCK_INPUT;
4232 /***********************************************************************
4233 Window properties
4234 ***********************************************************************/
4236 DEFUN ("x-change-window-property", Fx_change_window_property,
4237 Sx_change_window_property, 2, 6, 0,
4238 doc: /* Change window property PROP to VALUE on the X window of FRAME.
4239 PROP must be a string. VALUE may be a string or a list of conses,
4240 numbers and/or strings. If an element in the list is a string, it is
4241 converted to an atom and the value of the atom is used. If an element
4242 is a cons, it is converted to a 32 bit number where the car is the 16
4243 top bits and the cdr is the lower 16 bits.
4245 FRAME nil or omitted means use the selected frame.
4246 If TYPE is given and non-nil, it is the name of the type of VALUE.
4247 If TYPE is not given or nil, the type is STRING.
4248 FORMAT gives the size in bits of each element if VALUE is a list.
4249 It must be one of 8, 16 or 32.
4250 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4251 If OUTER_P is non-nil, the property is changed for the outer X window of
4252 FRAME. Default is to change on the edit X window. */)
4253 (Lisp_Object prop, Lisp_Object value, Lisp_Object frame, Lisp_Object type, Lisp_Object format, Lisp_Object outer_p)
4255 struct frame *f = check_x_frame (frame);
4256 Atom prop_atom;
4257 Atom target_type = XA_STRING;
4258 int element_format = 8;
4259 unsigned char *data;
4260 int nelements;
4261 Window w;
4263 CHECK_STRING (prop);
4265 if (! NILP (format))
4267 CHECK_NUMBER (format);
4268 element_format = XFASTINT (format);
4270 if (element_format != 8 && element_format != 16
4271 && element_format != 32)
4272 error ("FORMAT must be one of 8, 16 or 32");
4275 if (CONSP (value))
4277 nelements = x_check_property_data (value);
4278 if (nelements == -1)
4279 error ("Bad data in VALUE, must be number, string or cons");
4281 if (element_format == 8)
4282 data = (unsigned char *) xmalloc (nelements);
4283 else if (element_format == 16)
4284 data = (unsigned char *) xmalloc (nelements*2);
4285 else /* format == 32 */
4286 /* The man page for XChangeProperty:
4287 "If the specified format is 32, the property data must be a
4288 long array."
4289 This applies even if long is more than 64 bits. The X library
4290 converts to 32 bits before sending to the X server. */
4291 data = (unsigned char *) xmalloc (nelements * sizeof(long));
4293 x_fill_property_data (FRAME_X_DISPLAY (f), value, data, element_format);
4295 else
4297 CHECK_STRING (value);
4298 data = SDATA (value);
4299 nelements = SCHARS (value);
4302 BLOCK_INPUT;
4303 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
4304 if (! NILP (type))
4306 CHECK_STRING (type);
4307 target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False);
4310 if (! NILP (outer_p)) w = FRAME_OUTER_WINDOW (f);
4311 else w = FRAME_X_WINDOW (f);
4313 XChangeProperty (FRAME_X_DISPLAY (f), w,
4314 prop_atom, target_type, element_format, PropModeReplace,
4315 data, nelements);
4317 if (CONSP (value)) xfree (data);
4319 /* Make sure the property is set when we return. */
4320 XFlush (FRAME_X_DISPLAY (f));
4321 UNBLOCK_INPUT;
4323 return value;
4327 DEFUN ("x-delete-window-property", Fx_delete_window_property,
4328 Sx_delete_window_property, 1, 2, 0,
4329 doc: /* Remove window property PROP from X window of FRAME.
4330 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4331 (Lisp_Object prop, Lisp_Object frame)
4333 struct frame *f = check_x_frame (frame);
4334 Atom prop_atom;
4336 CHECK_STRING (prop);
4337 BLOCK_INPUT;
4338 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
4339 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), prop_atom);
4341 /* Make sure the property is removed when we return. */
4342 XFlush (FRAME_X_DISPLAY (f));
4343 UNBLOCK_INPUT;
4345 return prop;
4349 DEFUN ("x-window-property", Fx_window_property, Sx_window_property,
4350 1, 6, 0,
4351 doc: /* Value is the value of window property PROP on FRAME.
4352 If FRAME is nil or omitted, use the selected frame.
4354 On MS Windows, this function only accepts the PROP and FRAME arguments.
4356 On X Windows, the following optional arguments are also accepted:
4357 If TYPE is nil or omitted, get the property as a string.
4358 Otherwise TYPE is the name of the atom that denotes the type expected.
4359 If SOURCE is non-nil, get the property on that window instead of from
4360 FRAME. The number 0 denotes the root window.
4361 If DELETE_P is non-nil, delete the property after retreiving it.
4362 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4364 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4365 no value of TYPE (always string in the MS Windows case). */)
4366 (Lisp_Object prop, Lisp_Object frame, Lisp_Object type, Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p)
4368 struct frame *f = check_x_frame (frame);
4369 Atom prop_atom;
4370 int rc;
4371 Lisp_Object prop_value = Qnil;
4372 unsigned char *tmp_data = NULL;
4373 Atom actual_type;
4374 Atom target_type = XA_STRING;
4375 int actual_format;
4376 unsigned long actual_size, bytes_remaining;
4377 Window target_window = FRAME_X_WINDOW (f);
4378 struct gcpro gcpro1;
4380 GCPRO1 (prop_value);
4381 CHECK_STRING (prop);
4383 if (! NILP (source))
4385 if (NUMBERP (source))
4387 if (FLOATP (source))
4388 target_window = (Window) XFLOAT (source);
4389 else
4390 target_window = XFASTINT (source);
4392 if (target_window == 0)
4393 target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
4395 else if (CONSP (source))
4396 target_window = cons_to_long (source);
4399 BLOCK_INPUT;
4400 if (STRINGP (type))
4402 if (strcmp ("AnyPropertyType", SDATA (type)) == 0)
4403 target_type = AnyPropertyType;
4404 else
4405 target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False);
4408 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
4409 rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window,
4410 prop_atom, 0, 0, False, target_type,
4411 &actual_type, &actual_format, &actual_size,
4412 &bytes_remaining, &tmp_data);
4413 if (rc == Success)
4415 int size = bytes_remaining;
4417 XFree (tmp_data);
4418 tmp_data = NULL;
4420 rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window,
4421 prop_atom, 0, bytes_remaining,
4422 ! NILP (delete_p), target_type,
4423 &actual_type, &actual_format,
4424 &actual_size, &bytes_remaining,
4425 &tmp_data);
4426 if (rc == Success && tmp_data)
4428 /* The man page for XGetWindowProperty says:
4429 "If the returned format is 32, the returned data is represented
4430 as a long array and should be cast to that type to obtain the
4431 elements."
4432 This applies even if long is more than 32 bits, the X library
4433 converts from 32 bit elements received from the X server to long
4434 and passes the long array to us. Thus, for that case memcpy can not
4435 be used. We convert to a 32 bit type here, because so much code
4436 assume on that.
4438 The bytes and offsets passed to XGetWindowProperty refers to the
4439 property and those are indeed in 32 bit quantities if format is
4440 32. */
4442 if (actual_format == 32 && actual_format < BITS_PER_LONG)
4444 unsigned long i;
4445 int *idata = (int *) tmp_data;
4446 long *ldata = (long *) tmp_data;
4448 for (i = 0; i < actual_size; ++i)
4449 idata[i] = (int) ldata[i];
4452 if (NILP (vector_ret_p))
4453 prop_value = make_string (tmp_data, size);
4454 else
4455 prop_value = x_property_data_to_lisp (f,
4456 tmp_data,
4457 actual_type,
4458 actual_format,
4459 actual_size);
4462 if (tmp_data) XFree (tmp_data);
4465 UNBLOCK_INPUT;
4466 UNGCPRO;
4467 return prop_value;
4472 /***********************************************************************
4473 Busy cursor
4474 ***********************************************************************/
4476 /* Timer function of hourglass_atimer. TIMER is equal to
4477 hourglass_atimer.
4479 Display an hourglass pointer on all frames by mapping the frames'
4480 hourglass_window. Set the hourglass_p flag in the frames'
4481 output_data.x structure to indicate that an hourglass cursor is
4482 shown on the frames. */
4484 void
4485 show_hourglass (struct atimer *timer)
4487 /* The timer implementation will cancel this timer automatically
4488 after this function has run. Set hourglass_atimer to null
4489 so that we know the timer doesn't have to be canceled. */
4490 hourglass_atimer = NULL;
4492 if (!hourglass_shown_p)
4494 Lisp_Object rest, frame;
4496 BLOCK_INPUT;
4498 FOR_EACH_FRAME (rest, frame)
4500 struct frame *f = XFRAME (frame);
4502 if (FRAME_LIVE_P (f) && FRAME_X_P (f) && FRAME_X_DISPLAY (f))
4504 Display *dpy = FRAME_X_DISPLAY (f);
4506 #ifdef USE_X_TOOLKIT
4507 if (f->output_data.x->widget)
4508 #else
4509 if (FRAME_OUTER_WINDOW (f))
4510 #endif
4512 f->output_data.x->hourglass_p = 1;
4514 if (!f->output_data.x->hourglass_window)
4516 unsigned long mask = CWCursor;
4517 XSetWindowAttributes attrs;
4518 #ifdef USE_GTK
4519 Window parent = FRAME_X_WINDOW (f);
4520 #else
4521 Window parent = FRAME_OUTER_WINDOW (f);
4522 #endif
4523 attrs.cursor = f->output_data.x->hourglass_cursor;
4525 f->output_data.x->hourglass_window
4526 = XCreateWindow (dpy, parent,
4527 0, 0, 32000, 32000, 0, 0,
4528 InputOnly,
4529 CopyFromParent,
4530 mask, &attrs);
4533 XMapRaised (dpy, f->output_data.x->hourglass_window);
4534 XFlush (dpy);
4539 hourglass_shown_p = 1;
4540 UNBLOCK_INPUT;
4545 /* Hide the hourglass pointer on all frames, if it is currently
4546 shown. */
4548 void
4549 hide_hourglass (void)
4551 if (hourglass_shown_p)
4553 Lisp_Object rest, frame;
4555 BLOCK_INPUT;
4556 FOR_EACH_FRAME (rest, frame)
4558 struct frame *f = XFRAME (frame);
4560 if (FRAME_X_P (f)
4561 /* Watch out for newly created frames. */
4562 && f->output_data.x->hourglass_window)
4564 XUnmapWindow (FRAME_X_DISPLAY (f),
4565 f->output_data.x->hourglass_window);
4566 /* Sync here because XTread_socket looks at the
4567 hourglass_p flag that is reset to zero below. */
4568 XSync (FRAME_X_DISPLAY (f), False);
4569 f->output_data.x->hourglass_p = 0;
4573 hourglass_shown_p = 0;
4574 UNBLOCK_INPUT;
4580 /***********************************************************************
4581 Tool tips
4582 ***********************************************************************/
4584 static Lisp_Object x_create_tip_frame (struct x_display_info *,
4585 Lisp_Object, Lisp_Object);
4586 static void compute_tip_xy (struct frame *, Lisp_Object, Lisp_Object,
4587 Lisp_Object, int, int, int *, int *);
4589 /* The frame of a currently visible tooltip. */
4591 Lisp_Object tip_frame;
4593 /* If non-nil, a timer started that hides the last tooltip when it
4594 fires. */
4596 Lisp_Object tip_timer;
4597 Window tip_window;
4599 /* If non-nil, a vector of 3 elements containing the last args
4600 with which x-show-tip was called. See there. */
4602 Lisp_Object last_show_tip_args;
4604 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
4606 Lisp_Object Vx_max_tooltip_size;
4609 static Lisp_Object
4610 unwind_create_tip_frame (Lisp_Object frame)
4612 Lisp_Object deleted;
4614 deleted = unwind_create_frame (frame);
4615 if (EQ (deleted, Qt))
4617 tip_window = None;
4618 tip_frame = Qnil;
4621 return deleted;
4625 /* Create a frame for a tooltip on the display described by DPYINFO.
4626 PARMS is a list of frame parameters. TEXT is the string to
4627 display in the tip frame. Value is the frame.
4629 Note that functions called here, esp. x_default_parameter can
4630 signal errors, for instance when a specified color name is
4631 undefined. We have to make sure that we're in a consistent state
4632 when this happens. */
4634 static Lisp_Object
4635 x_create_tip_frame (struct x_display_info *dpyinfo,
4636 Lisp_Object parms,
4637 Lisp_Object text)
4639 struct frame *f;
4640 Lisp_Object frame, tem;
4641 Lisp_Object name;
4642 long window_prompting = 0;
4643 int width, height;
4644 int count = SPECPDL_INDEX ();
4645 struct gcpro gcpro1, gcpro2, gcpro3;
4646 int face_change_count_before = face_change_count;
4647 Lisp_Object buffer;
4648 struct buffer *old_buffer;
4650 check_x ();
4652 if (!dpyinfo->terminal->name)
4653 error ("Terminal is not live, can't create new frames on it");
4655 parms = Fcopy_alist (parms);
4657 /* Get the name of the frame to use for resource lookup. */
4658 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
4659 if (!STRINGP (name)
4660 && !EQ (name, Qunbound)
4661 && !NILP (name))
4662 error ("Invalid frame name--not a string or nil");
4664 frame = Qnil;
4665 GCPRO3 (parms, name, frame);
4666 f = make_frame (1);
4667 XSETFRAME (frame, f);
4669 buffer = Fget_buffer_create (build_string (" *tip*"));
4670 Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil);
4671 old_buffer = current_buffer;
4672 set_buffer_internal_1 (XBUFFER (buffer));
4673 current_buffer->truncate_lines = Qnil;
4674 specbind (Qinhibit_read_only, Qt);
4675 specbind (Qinhibit_modification_hooks, Qt);
4676 Ferase_buffer ();
4677 Finsert (1, &text);
4678 set_buffer_internal_1 (old_buffer);
4680 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
4681 record_unwind_protect (unwind_create_tip_frame, frame);
4683 f->terminal = dpyinfo->terminal;
4684 f->terminal->reference_count++;
4686 /* By setting the output method, we're essentially saying that
4687 the frame is live, as per FRAME_LIVE_P. If we get a signal
4688 from this point on, x_destroy_window might screw up reference
4689 counts etc. */
4690 f->output_method = output_x_window;
4691 f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
4692 memset (f->output_data.x, 0, sizeof (struct x_output));
4693 f->output_data.x->icon_bitmap = -1;
4694 FRAME_FONTSET (f) = -1;
4695 f->output_data.x->scroll_bar_foreground_pixel = -1;
4696 f->output_data.x->scroll_bar_background_pixel = -1;
4697 #ifdef USE_TOOLKIT_SCROLL_BARS
4698 f->output_data.x->scroll_bar_top_shadow_pixel = -1;
4699 f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
4700 #endif /* USE_TOOLKIT_SCROLL_BARS */
4701 f->icon_name = Qnil;
4702 FRAME_X_DISPLAY_INFO (f) = dpyinfo;
4703 #if GLYPH_DEBUG
4704 image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
4705 dpyinfo_refcount = dpyinfo->reference_count;
4706 #endif /* GLYPH_DEBUG */
4707 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
4708 f->output_data.x->explicit_parent = 0;
4710 /* These colors will be set anyway later, but it's important
4711 to get the color reference counts right, so initialize them! */
4713 Lisp_Object black;
4714 struct gcpro gcpro1;
4716 /* Function x_decode_color can signal an error. Make
4717 sure to initialize color slots so that we won't try
4718 to free colors we haven't allocated. */
4719 FRAME_FOREGROUND_PIXEL (f) = -1;
4720 FRAME_BACKGROUND_PIXEL (f) = -1;
4721 f->output_data.x->cursor_pixel = -1;
4722 f->output_data.x->cursor_foreground_pixel = -1;
4723 f->output_data.x->border_pixel = -1;
4724 f->output_data.x->mouse_pixel = -1;
4726 black = build_string ("black");
4727 GCPRO1 (black);
4728 FRAME_FOREGROUND_PIXEL (f)
4729 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4730 FRAME_BACKGROUND_PIXEL (f)
4731 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4732 f->output_data.x->cursor_pixel
4733 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4734 f->output_data.x->cursor_foreground_pixel
4735 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4736 f->output_data.x->border_pixel
4737 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4738 f->output_data.x->mouse_pixel
4739 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4740 UNGCPRO;
4743 /* Set the name; the functions to which we pass f expect the name to
4744 be set. */
4745 if (EQ (name, Qunbound) || NILP (name))
4747 f->name = build_string (dpyinfo->x_id_name);
4748 f->explicit_name = 0;
4750 else
4752 f->name = name;
4753 f->explicit_name = 1;
4754 /* use the frame's title when getting resources for this frame. */
4755 specbind (Qx_resource_name, name);
4758 f->resx = dpyinfo->resx;
4759 f->resy = dpyinfo->resy;
4761 register_font_driver (&xfont_driver, f);
4762 #ifdef HAVE_FREETYPE
4763 #ifdef HAVE_XFT
4764 register_font_driver (&xftfont_driver, f);
4765 #else /* not HAVE_XFT */
4766 register_font_driver (&ftxfont_driver, f);
4767 #endif /* not HAVE_XFT */
4768 #endif /* HAVE_FREETYPE */
4770 x_default_parameter (f, parms, Qfont_backend, Qnil,
4771 "fontBackend", "FontBackend", RES_TYPE_STRING);
4773 /* Extract the window parameters from the supplied values that are
4774 needed to determine window geometry. */
4775 x_default_font_parameter (f, parms);
4777 x_default_parameter (f, parms, Qborder_width, make_number (0),
4778 "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
4780 /* This defaults to 2 in order to match xterm. We recognize either
4781 internalBorderWidth or internalBorder (which is what xterm calls
4782 it). */
4783 if (NILP (Fassq (Qinternal_border_width, parms)))
4785 Lisp_Object value;
4787 value = x_get_arg (dpyinfo, parms, Qinternal_border_width,
4788 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
4789 if (! EQ (value, Qunbound))
4790 parms = Fcons (Fcons (Qinternal_border_width, value),
4791 parms);
4794 x_default_parameter (f, parms, Qinternal_border_width, make_number (1),
4795 "internalBorderWidth", "internalBorderWidth",
4796 RES_TYPE_NUMBER);
4798 /* Also do the stuff which must be set before the window exists. */
4799 x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
4800 "foreground", "Foreground", RES_TYPE_STRING);
4801 x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
4802 "background", "Background", RES_TYPE_STRING);
4803 x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
4804 "pointerColor", "Foreground", RES_TYPE_STRING);
4805 x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
4806 "cursorColor", "Foreground", RES_TYPE_STRING);
4807 x_default_parameter (f, parms, Qborder_color, build_string ("black"),
4808 "borderColor", "BorderColor", RES_TYPE_STRING);
4810 /* Init faces before x_default_parameter is called for scroll-bar
4811 parameters because that function calls x_set_scroll_bar_width,
4812 which calls change_frame_size, which calls Fset_window_buffer,
4813 which runs hooks, which call Fvertical_motion. At the end, we
4814 end up in init_iterator with a null face cache, which should not
4815 happen. */
4816 init_frame_faces (f);
4818 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
4820 window_prompting = x_figure_window_size (f, parms, 0);
4823 XSetWindowAttributes attrs;
4824 unsigned long mask;
4825 Atom type = FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type_tooltip;
4827 BLOCK_INPUT;
4828 mask = CWBackPixel | CWOverrideRedirect | CWEventMask;
4829 if (DoesSaveUnders (dpyinfo->screen))
4830 mask |= CWSaveUnder;
4832 /* Window managers look at the override-redirect flag to determine
4833 whether or net to give windows a decoration (Xlib spec, chapter
4834 3.2.8). */
4835 attrs.override_redirect = True;
4836 attrs.save_under = True;
4837 attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f);
4838 /* Arrange for getting MapNotify and UnmapNotify events. */
4839 attrs.event_mask = StructureNotifyMask;
4840 tip_window
4841 = FRAME_X_WINDOW (f)
4842 = XCreateWindow (FRAME_X_DISPLAY (f),
4843 FRAME_X_DISPLAY_INFO (f)->root_window,
4844 /* x, y, width, height */
4845 0, 0, 1, 1,
4846 /* Border. */
4847 f->border_width,
4848 CopyFromParent, InputOutput, CopyFromParent,
4849 mask, &attrs);
4850 XChangeProperty (FRAME_X_DISPLAY (f), tip_window,
4851 FRAME_X_DISPLAY_INFO (f)->Xatom_net_window_type,
4852 XA_ATOM, 32, PropModeReplace,
4853 (unsigned char *)&type, 1);
4854 UNBLOCK_INPUT;
4857 x_make_gc (f);
4859 x_default_parameter (f, parms, Qauto_raise, Qnil,
4860 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
4861 x_default_parameter (f, parms, Qauto_lower, Qnil,
4862 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
4863 x_default_parameter (f, parms, Qcursor_type, Qbox,
4864 "cursorType", "CursorType", RES_TYPE_SYMBOL);
4866 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4867 Change will not be effected unless different from the current
4868 FRAME_LINES (f). */
4869 width = FRAME_COLS (f);
4870 height = FRAME_LINES (f);
4871 SET_FRAME_COLS (f, 0);
4872 FRAME_LINES (f) = 0;
4873 change_frame_size (f, height, width, 1, 0, 0);
4875 /* Add `tooltip' frame parameter's default value. */
4876 if (NILP (Fframe_parameter (frame, Qtooltip)))
4877 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtooltip, Qt), Qnil));
4879 /* FIXME - can this be done in a similar way to normal frames?
4880 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
4882 /* Set the `display-type' frame parameter before setting up faces. */
4884 Lisp_Object disptype;
4886 if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1)
4887 disptype = intern ("mono");
4888 else if (FRAME_X_DISPLAY_INFO (f)->visual->class == GrayScale
4889 || FRAME_X_DISPLAY_INFO (f)->visual->class == StaticGray)
4890 disptype = intern ("grayscale");
4891 else
4892 disptype = intern ("color");
4894 if (NILP (Fframe_parameter (frame, Qdisplay_type)))
4895 Fmodify_frame_parameters (frame, Fcons (Fcons (Qdisplay_type, disptype),
4896 Qnil));
4899 /* Set up faces after all frame parameters are known. This call
4900 also merges in face attributes specified for new frames.
4902 Frame parameters may be changed if .Xdefaults contains
4903 specifications for the default font. For example, if there is an
4904 `Emacs.default.attributeBackground: pink', the `background-color'
4905 attribute of the frame get's set, which let's the internal border
4906 of the tooltip frame appear in pink. Prevent this. */
4908 Lisp_Object bg = Fframe_parameter (frame, Qbackground_color);
4910 /* Set tip_frame here, so that */
4911 tip_frame = frame;
4912 call2 (Qface_set_after_frame_default, frame, Qnil);
4914 if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
4915 Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg),
4916 Qnil));
4919 f->no_split = 1;
4921 UNGCPRO;
4923 /* It is now ok to make the frame official even if we get an error
4924 below. And the frame needs to be on Vframe_list or making it
4925 visible won't work. */
4926 Vframe_list = Fcons (frame, Vframe_list);
4928 /* Now that the frame is official, it counts as a reference to
4929 its display. */
4930 FRAME_X_DISPLAY_INFO (f)->reference_count++;
4932 /* Setting attributes of faces of the tooltip frame from resources
4933 and similar will increment face_change_count, which leads to the
4934 clearing of all current matrices. Since this isn't necessary
4935 here, avoid it by resetting face_change_count to the value it
4936 had before we created the tip frame. */
4937 face_change_count = face_change_count_before;
4939 /* Discard the unwind_protect. */
4940 return unbind_to (count, frame);
4944 /* Compute where to display tip frame F. PARMS is the list of frame
4945 parameters for F. DX and DY are specified offsets from the current
4946 location of the mouse. WIDTH and HEIGHT are the width and height
4947 of the tooltip. Return coordinates relative to the root window of
4948 the display in *ROOT_X, and *ROOT_Y. */
4950 static void
4951 compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object dy, int width, int height, int *root_x, int *root_y)
4953 Lisp_Object left, top;
4954 int win_x, win_y;
4955 Window root, child;
4956 unsigned pmask;
4958 /* User-specified position? */
4959 left = Fcdr (Fassq (Qleft, parms));
4960 top = Fcdr (Fassq (Qtop, parms));
4962 /* Move the tooltip window where the mouse pointer is. Resize and
4963 show it. */
4964 if (!INTEGERP (left) || !INTEGERP (top))
4966 BLOCK_INPUT;
4967 XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
4968 &root, &child, root_x, root_y, &win_x, &win_y, &pmask);
4969 UNBLOCK_INPUT;
4972 if (INTEGERP (top))
4973 *root_y = XINT (top);
4974 else if (*root_y + XINT (dy) <= 0)
4975 *root_y = 0; /* Can happen for negative dy */
4976 else if (*root_y + XINT (dy) + height
4977 <= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f)))
4978 /* It fits below the pointer */
4979 *root_y += XINT (dy);
4980 else if (height + XINT (dy) <= *root_y)
4981 /* It fits above the pointer. */
4982 *root_y -= height + XINT (dy);
4983 else
4984 /* Put it on the top. */
4985 *root_y = 0;
4987 if (INTEGERP (left))
4988 *root_x = XINT (left);
4989 else if (*root_x + XINT (dx) <= 0)
4990 *root_x = 0; /* Can happen for negative dx */
4991 else if (*root_x + XINT (dx) + width
4992 <= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f)))
4993 /* It fits to the right of the pointer. */
4994 *root_x += XINT (dx);
4995 else if (width + XINT (dx) <= *root_x)
4996 /* It fits to the left of the pointer. */
4997 *root_x -= width + XINT (dx);
4998 else
4999 /* Put it left-justified on the screen--it ought to fit that way. */
5000 *root_x = 0;
5004 DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
5005 doc: /* Show STRING in a "tooltip" window on frame FRAME.
5006 A tooltip window is a small X window displaying a string.
5008 This is an internal function; Lisp code should call `tooltip-show'.
5010 FRAME nil or omitted means use the selected frame.
5012 PARMS is an optional list of frame parameters which can be used to
5013 change the tooltip's appearance.
5015 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5016 means use the default timeout of 5 seconds.
5018 If the list of frame parameters PARMS contains a `left' parameters,
5019 the tooltip is displayed at that x-position. Otherwise it is
5020 displayed at the mouse position, with offset DX added (default is 5 if
5021 DX isn't specified). Likewise for the y-position; if a `top' frame
5022 parameter is specified, it determines the y-position of the tooltip
5023 window, otherwise it is displayed at the mouse position, with offset
5024 DY added (default is -10).
5026 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5027 Text larger than the specified size is clipped. */)
5028 (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
5030 struct frame *f;
5031 struct window *w;
5032 int root_x, root_y;
5033 struct buffer *old_buffer;
5034 struct text_pos pos;
5035 int i, width, height, seen_reversed_p;
5036 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
5037 int old_windows_or_buffers_changed = windows_or_buffers_changed;
5038 int count = SPECPDL_INDEX ();
5040 specbind (Qinhibit_redisplay, Qt);
5042 GCPRO4 (string, parms, frame, timeout);
5044 CHECK_STRING (string);
5045 if (SCHARS (string) == 0)
5046 string = make_unibyte_string (" ", 1);
5048 f = check_x_frame (frame);
5049 if (NILP (timeout))
5050 timeout = make_number (5);
5051 else
5052 CHECK_NATNUM (timeout);
5054 if (NILP (dx))
5055 dx = make_number (5);
5056 else
5057 CHECK_NUMBER (dx);
5059 if (NILP (dy))
5060 dy = make_number (-10);
5061 else
5062 CHECK_NUMBER (dy);
5064 #ifdef USE_GTK
5065 if (x_gtk_use_system_tooltips)
5067 int ok;
5069 /* Hide a previous tip, if any. */
5070 Fx_hide_tip ();
5072 BLOCK_INPUT;
5073 if ((ok = xg_prepare_tooltip (f, string, &width, &height)) != 0)
5075 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
5076 xg_show_tooltip (f, root_x, root_y);
5077 /* This is used in Fx_hide_tip. */
5078 XSETFRAME (tip_frame, f);
5080 UNBLOCK_INPUT;
5081 if (ok) goto start_timer;
5083 #endif /* USE_GTK */
5085 if (NILP (last_show_tip_args))
5086 last_show_tip_args = Fmake_vector (make_number (3), Qnil);
5088 if (!NILP (tip_frame))
5090 Lisp_Object last_string = AREF (last_show_tip_args, 0);
5091 Lisp_Object last_frame = AREF (last_show_tip_args, 1);
5092 Lisp_Object last_parms = AREF (last_show_tip_args, 2);
5094 if (EQ (frame, last_frame)
5095 && !NILP (Fequal (last_string, string))
5096 && !NILP (Fequal (last_parms, parms)))
5098 struct frame *f = XFRAME (tip_frame);
5100 /* Only DX and DY have changed. */
5101 if (!NILP (tip_timer))
5103 Lisp_Object timer = tip_timer;
5104 tip_timer = Qnil;
5105 call1 (Qcancel_timer, timer);
5108 BLOCK_INPUT;
5109 compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f),
5110 FRAME_PIXEL_HEIGHT (f), &root_x, &root_y);
5111 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5112 root_x, root_y);
5113 UNBLOCK_INPUT;
5114 goto start_timer;
5118 /* Hide a previous tip, if any. */
5119 Fx_hide_tip ();
5121 ASET (last_show_tip_args, 0, string);
5122 ASET (last_show_tip_args, 1, frame);
5123 ASET (last_show_tip_args, 2, parms);
5125 /* Add default values to frame parameters. */
5126 if (NILP (Fassq (Qname, parms)))
5127 parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
5128 if (NILP (Fassq (Qinternal_border_width, parms)))
5129 parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms);
5130 if (NILP (Fassq (Qborder_width, parms)))
5131 parms = Fcons (Fcons (Qborder_width, make_number (1)), parms);
5132 if (NILP (Fassq (Qborder_color, parms)))
5133 parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms);
5134 if (NILP (Fassq (Qbackground_color, parms)))
5135 parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")),
5136 parms);
5138 /* Create a frame for the tooltip, and record it in the global
5139 variable tip_frame. */
5140 frame = x_create_tip_frame (FRAME_X_DISPLAY_INFO (f), parms, string);
5141 f = XFRAME (frame);
5143 /* Set up the frame's root window. */
5144 w = XWINDOW (FRAME_ROOT_WINDOW (f));
5145 w->left_col = w->top_line = make_number (0);
5147 if (CONSP (Vx_max_tooltip_size)
5148 && INTEGERP (XCAR (Vx_max_tooltip_size))
5149 && XINT (XCAR (Vx_max_tooltip_size)) > 0
5150 && INTEGERP (XCDR (Vx_max_tooltip_size))
5151 && XINT (XCDR (Vx_max_tooltip_size)) > 0)
5153 w->total_cols = XCAR (Vx_max_tooltip_size);
5154 w->total_lines = XCDR (Vx_max_tooltip_size);
5156 else
5158 w->total_cols = make_number (80);
5159 w->total_lines = make_number (40);
5162 FRAME_TOTAL_COLS (f) = XINT (w->total_cols);
5163 adjust_glyphs (f);
5164 w->pseudo_window_p = 1;
5166 /* Display the tooltip text in a temporary buffer. */
5167 old_buffer = current_buffer;
5168 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer));
5169 current_buffer->truncate_lines = Qnil;
5170 clear_glyph_matrix (w->desired_matrix);
5171 clear_glyph_matrix (w->current_matrix);
5172 SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
5173 try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
5175 /* Compute width and height of the tooltip. */
5176 width = height = seen_reversed_p = 0;
5177 for (i = 0; i < w->desired_matrix->nrows; ++i)
5179 struct glyph_row *row = &w->desired_matrix->rows[i];
5180 struct glyph *last;
5181 int row_width;
5183 /* Stop at the first empty row at the end. */
5184 if (!row->enabled_p || !row->displays_text_p)
5185 break;
5187 /* Let the row go over the full width of the frame. */
5188 row->full_width_p = 1;
5190 row_width = row->pixel_width;
5191 if (row->used[TEXT_AREA])
5193 /* There's a glyph at the end of rows that is used to place
5194 the cursor there. Don't include the width of this glyph. */
5195 if (!row->reversed_p)
5197 last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
5198 if (INTEGERP (last->object))
5199 row_width -= last->pixel_width;
5201 else
5203 /* There could be a stretch glyph at the beginning of R2L
5204 rows that is produced by extend_face_to_end_of_line.
5205 Don't count that glyph. */
5206 struct glyph *g = row->glyphs[TEXT_AREA];
5208 if (g->type == STRETCH_GLYPH && INTEGERP (g->object))
5210 row_width -= g->pixel_width;
5211 seen_reversed_p = 1;
5216 height += row->height;
5217 width = max (width, row_width);
5220 /* If we've seen partial-length R2L rows, we need to re-adjust the
5221 tool-tip frame width and redisplay it again, to avoid over-wide
5222 tips due to the stretch glyph that extends R2L lines to full
5223 width of the frame. */
5224 if (seen_reversed_p)
5226 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5227 not in pixels. */
5228 width /= WINDOW_FRAME_COLUMN_WIDTH (w);
5229 w->total_cols = make_number (width);
5230 FRAME_TOTAL_COLS (f) = width;
5231 adjust_glyphs (f);
5232 clear_glyph_matrix (w->desired_matrix);
5233 clear_glyph_matrix (w->current_matrix);
5234 try_window (FRAME_ROOT_WINDOW (f), pos, 0);
5235 width = height = 0;
5236 /* Recompute width and height of the tooltip. */
5237 for (i = 0; i < w->desired_matrix->nrows; ++i)
5239 struct glyph_row *row = &w->desired_matrix->rows[i];
5240 struct glyph *last;
5241 int row_width;
5243 if (!row->enabled_p || !row->displays_text_p)
5244 break;
5245 row->full_width_p = 1;
5246 row_width = row->pixel_width;
5247 if (row->used[TEXT_AREA] && !row->reversed_p)
5249 last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
5250 if (INTEGERP (last->object))
5251 row_width -= last->pixel_width;
5254 height += row->height;
5255 width = max (width, row_width);
5259 /* Add the frame's internal border to the width and height the X
5260 window should have. */
5261 height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
5262 width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
5264 /* Move the tooltip window where the mouse pointer is. Resize and
5265 show it. */
5266 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
5268 BLOCK_INPUT;
5269 XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5270 root_x, root_y, width, height);
5271 XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
5272 UNBLOCK_INPUT;
5274 /* Draw into the window. */
5275 w->must_be_updated_p = 1;
5276 update_single_window (w, 1);
5278 /* Restore original current buffer. */
5279 set_buffer_internal_1 (old_buffer);
5280 windows_or_buffers_changed = old_windows_or_buffers_changed;
5282 start_timer:
5283 /* Let the tip disappear after timeout seconds. */
5284 tip_timer = call3 (intern ("run-at-time"), timeout, Qnil,
5285 intern ("x-hide-tip"));
5287 UNGCPRO;
5288 return unbind_to (count, Qnil);
5292 DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
5293 doc: /* Hide the current tooltip window, if there is any.
5294 Value is t if tooltip was open, nil otherwise. */)
5295 (void)
5297 int count;
5298 Lisp_Object deleted, frame, timer;
5299 struct gcpro gcpro1, gcpro2;
5300 struct frame *f;
5302 /* Return quickly if nothing to do. */
5303 if (NILP (tip_timer) && NILP (tip_frame))
5304 return Qnil;
5306 frame = tip_frame;
5307 timer = tip_timer;
5308 GCPRO2 (frame, timer);
5309 tip_frame = tip_timer = deleted = Qnil;
5311 count = SPECPDL_INDEX ();
5312 specbind (Qinhibit_redisplay, Qt);
5313 specbind (Qinhibit_quit, Qt);
5315 if (!NILP (timer))
5316 call1 (Qcancel_timer, timer);
5318 #ifdef USE_GTK
5319 /* When using system tooltip, tip_frame is the Emacs frame on which
5320 the tip is shown. */
5321 f = XFRAME (frame);
5322 if (FRAME_LIVE_P (f) && xg_hide_tooltip (f))
5323 frame = Qnil;
5324 #endif
5326 if (FRAMEP (frame))
5328 delete_frame (frame, Qnil);
5329 deleted = Qt;
5331 #ifdef USE_LUCID
5332 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5333 redisplay procedure is not called when a tip frame over menu
5334 items is unmapped. Redisplay the menu manually... */
5336 Widget w;
5337 f = SELECTED_FRAME ();
5338 w = f->output_data.x->menubar_widget;
5340 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen)
5341 && w != NULL)
5343 BLOCK_INPUT;
5344 xlwmenu_redisplay (w);
5345 UNBLOCK_INPUT;
5348 #endif /* USE_LUCID */
5351 UNGCPRO;
5352 return unbind_to (count, deleted);
5357 /***********************************************************************
5358 File selection dialog
5359 ***********************************************************************/
5361 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog,
5362 Sx_uses_old_gtk_dialog,
5363 0, 0, 0,
5364 doc: /* Return t if the old Gtk+ file selection dialog is used. */)
5365 (void)
5367 #ifdef USE_GTK
5368 if (use_dialog_box
5369 && use_file_dialog
5370 && have_menus_p ()
5371 && xg_uses_old_file_dialog ())
5372 return Qt;
5373 #endif
5374 return Qnil;
5378 #ifdef USE_MOTIF
5379 /* Callback for "OK" and "Cancel" on file selection dialog. */
5381 static void
5382 file_dialog_cb (Widget widget, XtPointer client_data, XtPointer call_data)
5384 int *result = (int *) client_data;
5385 XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data;
5386 *result = cb->reason;
5390 /* Callback for unmapping a file selection dialog. This is used to
5391 capture the case where a dialog is closed via a window manager's
5392 closer button, for example. Using a XmNdestroyCallback didn't work
5393 in this case. */
5395 static void
5396 file_dialog_unmap_cb (Widget widget, XtPointer client_data, XtPointer call_data)
5398 int *result = (int *) client_data;
5399 *result = XmCR_CANCEL;
5402 static Lisp_Object
5403 clean_up_file_dialog (Lisp_Object arg)
5405 struct Lisp_Save_Value *p = XSAVE_VALUE (arg);
5406 Widget dialog = (Widget) p->pointer;
5408 /* Clean up. */
5409 BLOCK_INPUT;
5410 XtUnmanageChild (dialog);
5411 XtDestroyWidget (dialog);
5412 x_menu_set_in_use (0);
5413 UNBLOCK_INPUT;
5415 return Qnil;
5419 DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
5420 doc: /* Read file name, prompting with PROMPT in directory DIR.
5421 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5422 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5423 or directory must exist.
5425 This function is only defined on MS Windows, and X Windows with the
5426 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5427 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5428 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
5430 int result;
5431 struct frame *f = SELECTED_FRAME ();
5432 Lisp_Object file = Qnil;
5433 Lisp_Object decoded_file;
5434 Widget dialog, text, help;
5435 Arg al[10];
5436 int ac = 0;
5437 XmString dir_xmstring, pattern_xmstring;
5438 int count = SPECPDL_INDEX ();
5439 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5441 check_x ();
5443 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5445 if (popup_activated ())
5446 error ("Trying to use a menu from within a menu-entry");
5448 CHECK_STRING (prompt);
5449 CHECK_STRING (dir);
5451 /* Prevent redisplay. */
5452 specbind (Qinhibit_redisplay, Qt);
5454 BLOCK_INPUT;
5456 /* Create the dialog with PROMPT as title, using DIR as initial
5457 directory and using "*" as pattern. */
5458 dir = Fexpand_file_name (dir, Qnil);
5459 dir_xmstring = XmStringCreateLocalized (SDATA (dir));
5460 pattern_xmstring = XmStringCreateLocalized ("*");
5462 XtSetArg (al[ac], XmNtitle, SDATA (prompt)); ++ac;
5463 XtSetArg (al[ac], XmNdirectory, dir_xmstring); ++ac;
5464 XtSetArg (al[ac], XmNpattern, pattern_xmstring); ++ac;
5465 XtSetArg (al[ac], XmNresizePolicy, XmRESIZE_GROW); ++ac;
5466 XtSetArg (al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ++ac;
5467 dialog = XmCreateFileSelectionDialog (f->output_data.x->widget,
5468 "fsb", al, ac);
5469 XmStringFree (dir_xmstring);
5470 XmStringFree (pattern_xmstring);
5472 /* Add callbacks for OK and Cancel. */
5473 XtAddCallback (dialog, XmNokCallback, file_dialog_cb,
5474 (XtPointer) &result);
5475 XtAddCallback (dialog, XmNcancelCallback, file_dialog_cb,
5476 (XtPointer) &result);
5477 XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb,
5478 (XtPointer) &result);
5480 /* Remove the help button since we can't display help. */
5481 help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON);
5482 XtUnmanageChild (help);
5484 /* Mark OK button as default. */
5485 XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON),
5486 XmNshowAsDefault, True, NULL);
5488 /* If MUSTMATCH is non-nil, disable the file entry field of the
5489 dialog, so that the user must select a file from the files list
5490 box. We can't remove it because we wouldn't have a way to get at
5491 the result file name, then. */
5492 text = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT);
5493 if (!NILP (mustmatch))
5495 Widget label;
5496 label = XmFileSelectionBoxGetChild (dialog, XmDIALOG_SELECTION_LABEL);
5497 XtSetSensitive (text, False);
5498 XtSetSensitive (label, False);
5501 /* Manage the dialog, so that list boxes get filled. */
5502 XtManageChild (dialog);
5504 if (STRINGP (default_filename))
5506 XmString default_xmstring;
5507 Widget wtext = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT);
5508 Widget list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST);
5510 XmTextPosition last_pos = XmTextFieldGetLastPosition (wtext);
5511 XmTextFieldReplace (wtext, 0, last_pos,
5512 (SDATA (Ffile_name_nondirectory (default_filename))));
5514 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5515 must include the path for this to work. */
5517 default_xmstring = XmStringCreateLocalized (SDATA (default_filename));
5519 if (XmListItemExists (list, default_xmstring))
5521 int item_pos = XmListItemPos (list, default_xmstring);
5522 /* Select the item and scroll it into view. */
5523 XmListSelectPos (list, item_pos, True);
5524 XmListSetPos (list, item_pos);
5527 XmStringFree (default_xmstring);
5530 record_unwind_protect (clean_up_file_dialog, make_save_value (dialog, 0));
5532 /* Process events until the user presses Cancel or OK. */
5533 x_menu_set_in_use (1);
5534 result = 0;
5535 while (result == 0)
5537 XEvent event;
5538 x_menu_wait_for_event (0);
5539 XtAppNextEvent (Xt_app_con, &event);
5540 if (event.type == KeyPress
5541 && FRAME_X_DISPLAY (f) == event.xkey.display)
5543 KeySym keysym = XLookupKeysym (&event.xkey, 0);
5545 /* Pop down on C-g. */
5546 if (keysym == XK_g && (event.xkey.state & ControlMask) != 0)
5547 XtUnmanageChild (dialog);
5550 (void) x_dispatch_event (&event, FRAME_X_DISPLAY (f));
5553 /* Get the result. */
5554 if (result == XmCR_OK)
5556 XmString text;
5557 String data;
5559 XtVaGetValues (dialog, XmNtextString, &text, NULL);
5560 XmStringGetLtoR (text, XmFONTLIST_DEFAULT_TAG, &data);
5561 XmStringFree (text);
5562 file = build_string (data);
5563 XtFree (data);
5565 else
5566 file = Qnil;
5568 UNBLOCK_INPUT;
5569 UNGCPRO;
5571 /* Make "Cancel" equivalent to C-g. */
5572 if (NILP (file))
5573 Fsignal (Qquit, Qnil);
5575 decoded_file = DECODE_FILE (file);
5577 return unbind_to (count, decoded_file);
5580 #endif /* USE_MOTIF */
5582 #ifdef USE_GTK
5584 static Lisp_Object
5585 clean_up_dialog (Lisp_Object arg)
5587 x_menu_set_in_use (0);
5589 return Qnil;
5592 DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
5593 doc: /* Read file name, prompting with PROMPT in directory DIR.
5594 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5595 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5596 or directory must exist.
5598 This function is only defined on MS Windows, and X Windows with the
5599 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5600 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5601 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
5603 FRAME_PTR f = SELECTED_FRAME ();
5604 char *fn;
5605 Lisp_Object file = Qnil;
5606 Lisp_Object decoded_file;
5607 int count = SPECPDL_INDEX ();
5608 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5609 char *cdef_file;
5611 check_x ();
5613 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5615 if (popup_activated ())
5616 error ("Trying to use a menu from within a menu-entry");
5618 CHECK_STRING (prompt);
5619 CHECK_STRING (dir);
5621 /* Prevent redisplay. */
5622 specbind (Qinhibit_redisplay, Qt);
5623 record_unwind_protect (clean_up_dialog, Qnil);
5625 BLOCK_INPUT;
5627 if (STRINGP (default_filename))
5628 cdef_file = SDATA (default_filename);
5629 else
5630 cdef_file = SDATA (dir);
5632 fn = xg_get_file_name (f, SDATA (prompt), cdef_file,
5633 ! NILP (mustmatch),
5634 ! NILP (only_dir_p));
5636 if (fn)
5638 file = build_string (fn);
5639 xfree (fn);
5642 UNBLOCK_INPUT;
5643 UNGCPRO;
5645 /* Make "Cancel" equivalent to C-g. */
5646 if (NILP (file))
5647 Fsignal (Qquit, Qnil);
5649 decoded_file = DECODE_FILE (file);
5651 return unbind_to (count, decoded_file);
5655 #ifdef HAVE_FREETYPE
5657 DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0,
5658 doc: /* Read a font name using a GTK font selection dialog.
5659 Return a GTK-style font string corresponding to the selection.
5661 If FRAME is omitted or nil, it defaults to the selected frame. */)
5662 (Lisp_Object frame, Lisp_Object ignored)
5664 FRAME_PTR f = check_x_frame (frame);
5665 char *name;
5666 Lisp_Object font;
5667 Lisp_Object font_param;
5668 char *default_name = NULL;
5669 struct gcpro gcpro1, gcpro2;
5670 int count = SPECPDL_INDEX ();
5672 check_x ();
5674 if (popup_activated ())
5675 error ("Trying to use a menu from within a menu-entry");
5677 /* Prevent redisplay. */
5678 specbind (Qinhibit_redisplay, Qt);
5679 record_unwind_protect (clean_up_dialog, Qnil);
5681 BLOCK_INPUT;
5683 GCPRO2(font_param, font);
5685 XSETFONT (font, FRAME_FONT (f));
5686 font_param = Ffont_get (font, intern (":name"));
5687 if (STRINGP (font_param))
5688 default_name = xstrdup (SDATA (font_param));
5689 else
5691 font_param = Fframe_parameter (frame, Qfont_param);
5692 if (STRINGP (font_param))
5693 default_name = xstrdup (SDATA (font_param));
5696 if (default_name == NULL && x_last_font_name != NULL)
5697 default_name = xstrdup (x_last_font_name);
5699 /* Convert fontconfig names to Gtk names, i.e. remove - before number */
5700 if (default_name)
5702 char *p = strrchr (default_name, '-');
5703 if (p)
5705 char *ep = p+1;
5706 while (isdigit (*ep))
5707 ++ep;
5708 if (*ep == '\0') *p = ' ';
5712 name = xg_get_font_name (f, default_name);
5713 xfree (default_name);
5715 if (name)
5717 font = build_string (name);
5718 g_free (x_last_font_name);
5719 x_last_font_name = name;
5722 UNBLOCK_INPUT;
5724 if (NILP (font))
5725 Fsignal (Qquit, Qnil);
5727 return unbind_to (count, font);
5729 #endif /* HAVE_FREETYPE */
5731 #endif /* USE_GTK */
5734 /***********************************************************************
5735 Keyboard
5736 ***********************************************************************/
5738 #ifdef HAVE_XKBGETKEYBOARD
5739 #include <X11/XKBlib.h>
5740 #include <X11/keysym.h>
5741 #endif
5743 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p,
5744 Sx_backspace_delete_keys_p, 0, 1, 0,
5745 doc: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5746 FRAME nil means use the selected frame.
5747 Value is t if we know that both keys are present, and are mapped to the
5748 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
5749 present and mapped to the usual X keysyms. */)
5750 (Lisp_Object frame)
5752 #ifdef HAVE_XKBGETKEYBOARD
5753 XkbDescPtr kb;
5754 struct frame *f = check_x_frame (frame);
5755 Display *dpy = FRAME_X_DISPLAY (f);
5756 Lisp_Object have_keys;
5757 int major, minor, op, event, error;
5759 BLOCK_INPUT;
5761 /* Check library version in case we're dynamically linked. */
5762 major = XkbMajorVersion;
5763 minor = XkbMinorVersion;
5764 if (!XkbLibraryVersion (&major, &minor))
5766 UNBLOCK_INPUT;
5767 return Qlambda;
5770 /* Check that the server supports XKB. */
5771 major = XkbMajorVersion;
5772 minor = XkbMinorVersion;
5773 if (!XkbQueryExtension (dpy, &op, &event, &error, &major, &minor))
5775 UNBLOCK_INPUT;
5776 return Qlambda;
5779 /* In this code we check that the keyboard has physical keys with names
5780 that start with BKSP (Backspace) and DELE (Delete), and that they
5781 generate keysym XK_BackSpace and XK_Delete respectively.
5782 This function is used to test if normal-erase-is-backspace should be
5783 turned on.
5784 An alternative approach would be to just check if XK_BackSpace and
5785 XK_Delete are mapped to any key. But if any of those are mapped to
5786 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
5787 user doesn't know about it, it is better to return false here.
5788 It is more obvious to the user what to do if she/he has two keys
5789 clearly marked with names/symbols and one key does something not
5790 expected (i.e. she/he then tries the other).
5791 The cases where Backspace/Delete is mapped to some other key combination
5792 are rare, and in those cases, normal-erase-is-backspace can be turned on
5793 manually. */
5795 have_keys = Qnil;
5796 kb = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd);
5797 if (kb)
5799 int delete_keycode = 0, backspace_keycode = 0, i;
5801 if (XkbGetNames (dpy, XkbAllNamesMask, kb) == Success)
5803 for (i = kb->min_key_code;
5804 (i < kb->max_key_code
5805 && (delete_keycode == 0 || backspace_keycode == 0));
5806 ++i)
5808 /* The XKB symbolic key names can be seen most easily in
5809 the PS file generated by `xkbprint -label name
5810 $DISPLAY'. */
5811 if (memcmp ("DELE", kb->names->keys[i].name, 4) == 0)
5812 delete_keycode = i;
5813 else if (memcmp ("BKSP", kb->names->keys[i].name, 4) == 0)
5814 backspace_keycode = i;
5817 XkbFreeNames (kb, 0, True);
5820 XkbFreeClientMap (kb, 0, True);
5822 if (delete_keycode
5823 && backspace_keycode
5824 && XKeysymToKeycode (dpy, XK_Delete) == delete_keycode
5825 && XKeysymToKeycode (dpy, XK_BackSpace) == backspace_keycode)
5826 have_keys = Qt;
5828 UNBLOCK_INPUT;
5829 return have_keys;
5830 #else /* not HAVE_XKBGETKEYBOARD */
5831 return Qlambda;
5832 #endif /* not HAVE_XKBGETKEYBOARD */
5837 /***********************************************************************
5838 Initialization
5839 ***********************************************************************/
5841 /* Keep this list in the same order as frame_parms in frame.c.
5842 Use 0 for unsupported frame parameters. */
5844 frame_parm_handler x_frame_parm_handlers[] =
5846 x_set_autoraise,
5847 x_set_autolower,
5848 x_set_background_color,
5849 x_set_border_color,
5850 x_set_border_width,
5851 x_set_cursor_color,
5852 x_set_cursor_type,
5853 x_set_font,
5854 x_set_foreground_color,
5855 x_set_icon_name,
5856 x_set_icon_type,
5857 x_set_internal_border_width,
5858 x_set_menu_bar_lines,
5859 x_set_mouse_color,
5860 x_explicitly_set_name,
5861 x_set_scroll_bar_width,
5862 x_set_title,
5863 x_set_unsplittable,
5864 x_set_vertical_scroll_bars,
5865 x_set_visibility,
5866 x_set_tool_bar_lines,
5867 x_set_scroll_bar_foreground,
5868 x_set_scroll_bar_background,
5869 x_set_screen_gamma,
5870 x_set_line_spacing,
5871 x_set_fringe_width,
5872 x_set_fringe_width,
5873 x_set_wait_for_wm,
5874 x_set_fullscreen,
5875 x_set_font_backend,
5876 x_set_alpha,
5877 x_set_sticky,
5878 x_set_tool_bar_position,
5881 void
5882 syms_of_xfns (void)
5884 /* This is zero if not using X windows. */
5885 x_in_use = 0;
5887 /* The section below is built by the lisp expression at the top of the file,
5888 just above where these variables are declared. */
5889 /*&&& init symbols here &&&*/
5890 Qnone = intern_c_string ("none");
5891 staticpro (&Qnone);
5892 Qsuppress_icon = intern_c_string ("suppress-icon");
5893 staticpro (&Qsuppress_icon);
5894 Qundefined_color = intern_c_string ("undefined-color");
5895 staticpro (&Qundefined_color);
5896 Qcompound_text = intern_c_string ("compound-text");
5897 staticpro (&Qcompound_text);
5898 Qcancel_timer = intern_c_string ("cancel-timer");
5899 staticpro (&Qcancel_timer);
5900 Qfont_param = intern_c_string ("font-parameter");
5901 staticpro (&Qfont_param);
5902 /* This is the end of symbol initialization. */
5904 /* Text property `display' should be nonsticky by default. */
5905 Vtext_property_default_nonsticky
5906 = Fcons (Fcons (Qdisplay, Qt), Vtext_property_default_nonsticky);
5909 Fput (Qundefined_color, Qerror_conditions,
5910 pure_cons (Qundefined_color, pure_cons (Qerror, Qnil)));
5911 Fput (Qundefined_color, Qerror_message,
5912 make_pure_c_string ("Undefined color"));
5914 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape,
5915 doc: /* The shape of the pointer when over text.
5916 Changing the value does not affect existing frames
5917 unless you set the mouse color. */);
5918 Vx_pointer_shape = Qnil;
5920 #if 0 /* This doesn't really do anything. */
5921 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape,
5922 doc: /* The shape of the pointer when not over text.
5923 This variable takes effect when you create a new frame
5924 or when you set the mouse color. */);
5925 #endif
5926 Vx_nontext_pointer_shape = Qnil;
5928 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape,
5929 doc: /* The shape of the pointer when Emacs is busy.
5930 This variable takes effect when you create a new frame
5931 or when you set the mouse color. */);
5932 Vx_hourglass_pointer_shape = Qnil;
5934 #if 0 /* This doesn't really do anything. */
5935 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape,
5936 doc: /* The shape of the pointer when over the mode line.
5937 This variable takes effect when you create a new frame
5938 or when you set the mouse color. */);
5939 #endif
5940 Vx_mode_pointer_shape = Qnil;
5942 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5943 &Vx_sensitive_text_pointer_shape,
5944 doc: /* The shape of the pointer when over mouse-sensitive text.
5945 This variable takes effect when you create a new frame
5946 or when you set the mouse color. */);
5947 Vx_sensitive_text_pointer_shape = Qnil;
5949 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5950 &Vx_window_horizontal_drag_shape,
5951 doc: /* Pointer shape to use for indicating a window can be dragged horizontally.
5952 This variable takes effect when you create a new frame
5953 or when you set the mouse color. */);
5954 Vx_window_horizontal_drag_shape = Qnil;
5956 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel,
5957 doc: /* A string indicating the foreground color of the cursor box. */);
5958 Vx_cursor_fore_pixel = Qnil;
5960 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size,
5961 doc: /* Maximum size for tooltips.
5962 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
5963 Vx_max_tooltip_size = Fcons (make_number (80), make_number (40));
5965 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager,
5966 doc: /* Non-nil if no X window manager is in use.
5967 Emacs doesn't try to figure this out; this is always nil
5968 unless you set it to something else. */);
5969 /* We don't have any way to find this out, so set it to nil
5970 and maybe the user would like to set it to t. */
5971 Vx_no_window_manager = Qnil;
5973 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5974 &Vx_pixel_size_width_font_regexp,
5975 doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5977 Since Emacs gets width of a font matching with this regexp from
5978 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5979 such a font. This is especially effective for such large fonts as
5980 Chinese, Japanese, and Korean. */);
5981 Vx_pixel_size_width_font_regexp = Qnil;
5983 /* This is not ifdef:ed, so other builds than GTK can customize it. */
5984 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", &x_gtk_use_old_file_dialog,
5985 doc: /* *Non-nil means prompt with the old GTK file selection dialog.
5986 If nil or if the file selection dialog is not available, the new GTK file
5987 chooser is used instead. To turn off all file dialogs set the
5988 variable `use-file-dialog'. */);
5989 x_gtk_use_old_file_dialog = 0;
5991 DEFVAR_BOOL ("x-gtk-show-hidden-files", &x_gtk_show_hidden_files,
5992 doc: /* *If non-nil, the GTK file chooser will by default show hidden files.
5993 Note that this is just the default, there is a toggle button on the file
5994 chooser to show or not show hidden files on a case by case basis. */);
5995 x_gtk_show_hidden_files = 0;
5997 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", &x_gtk_file_dialog_help_text,
5998 doc: /* *If non-nil, the GTK file chooser will show additional help text.
5999 If more space for files in the file chooser dialog is wanted, set this to nil
6000 to turn the additional text off. */);
6001 x_gtk_file_dialog_help_text = 1;
6003 DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", &x_gtk_whole_detached_tool_bar,
6004 doc: /* *If non-nil, a detached tool bar is shown in full.
6005 The default is to just show an arrow and pressing on that arrow shows
6006 the tool bar buttons. */);
6007 x_gtk_whole_detached_tool_bar = 0;
6009 DEFVAR_BOOL ("x-gtk-use-system-tooltips", &x_gtk_use_system_tooltips,
6010 doc: /* *If non-nil with a Gtk+ built Emacs, the Gtk+ toolip is used.
6011 Otherwise use Emacs own tooltip implementation.
6012 When using Gtk+ tooltips, the tooltip face is not used. */);
6013 x_gtk_use_system_tooltips = 1;
6015 Fprovide (intern_c_string ("x"), Qnil);
6017 #ifdef USE_X_TOOLKIT
6018 Fprovide (intern_c_string ("x-toolkit"), Qnil);
6019 #ifdef USE_MOTIF
6020 Fprovide (intern_c_string ("motif"), Qnil);
6022 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string,
6023 doc: /* Version info for LessTif/Motif. */);
6024 Vmotif_version_string = build_string (XmVERSION_STRING);
6025 #endif /* USE_MOTIF */
6026 #endif /* USE_X_TOOLKIT */
6028 #ifdef USE_GTK
6029 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6030 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6031 But for a user it is a toolkit for X, and indeed, configure
6032 accepts --with-x-toolkit=gtk. */
6033 Fprovide (intern_c_string ("x-toolkit"), Qnil);
6034 Fprovide (intern_c_string ("gtk"), Qnil);
6035 Fprovide (intern_c_string ("move-toolbar"), Qnil);
6037 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string,
6038 doc: /* Version info for GTK+. */);
6040 char gtk_version[40];
6041 g_snprintf (gtk_version, sizeof (gtk_version), "%u.%u.%u",
6042 GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
6043 Vgtk_version_string = make_pure_string (gtk_version, strlen (gtk_version), strlen (gtk_version), 0);
6045 #endif /* USE_GTK */
6047 /* X window properties. */
6048 defsubr (&Sx_change_window_property);
6049 defsubr (&Sx_delete_window_property);
6050 defsubr (&Sx_window_property);
6052 defsubr (&Sxw_display_color_p);
6053 defsubr (&Sx_display_grayscale_p);
6054 defsubr (&Sxw_color_defined_p);
6055 defsubr (&Sxw_color_values);
6056 defsubr (&Sx_server_max_request_size);
6057 defsubr (&Sx_server_vendor);
6058 defsubr (&Sx_server_version);
6059 defsubr (&Sx_display_pixel_width);
6060 defsubr (&Sx_display_pixel_height);
6061 defsubr (&Sx_display_mm_width);
6062 defsubr (&Sx_display_mm_height);
6063 defsubr (&Sx_display_screens);
6064 defsubr (&Sx_display_planes);
6065 defsubr (&Sx_display_color_cells);
6066 defsubr (&Sx_display_visual_class);
6067 defsubr (&Sx_display_backing_store);
6068 defsubr (&Sx_display_save_under);
6069 defsubr (&Sx_wm_set_size_hint);
6070 defsubr (&Sx_create_frame);
6071 defsubr (&Sx_open_connection);
6072 defsubr (&Sx_close_connection);
6073 defsubr (&Sx_display_list);
6074 defsubr (&Sx_synchronize);
6075 defsubr (&Sx_focus_frame);
6076 defsubr (&Sx_backspace_delete_keys_p);
6078 /* Setting callback functions for fontset handler. */
6079 check_window_system_func = check_x;
6081 defsubr (&Sx_show_tip);
6082 defsubr (&Sx_hide_tip);
6083 tip_timer = Qnil;
6084 staticpro (&tip_timer);
6085 tip_frame = Qnil;
6086 staticpro (&tip_frame);
6088 last_show_tip_args = Qnil;
6089 staticpro (&last_show_tip_args);
6091 defsubr (&Sx_uses_old_gtk_dialog);
6092 #if defined (USE_MOTIF) || defined (USE_GTK)
6093 defsubr (&Sx_file_dialog);
6094 #endif
6096 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6097 defsubr (&Sx_select_font);
6098 x_last_font_name = NULL;
6099 #endif
6102 #endif /* HAVE_X_WINDOWS */