1 /* Functions for the X window system.
2 Copyright (C) 1989, 92, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
31 /* This makes the fields of a Display accessible, in Xlib header files. */
33 #define XLIB_ILLEGAL_ACCESS
40 #include "intervals.h"
41 #include "dispextern.h"
43 #include "blockinput.h"
49 #include "termhooks.h"
55 #include <sys/types.h>
59 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
60 #include "bitmaps/gray.xbm"
62 #include <X11/bitmaps/gray>
65 #include "[.bitmaps]gray.xbm"
69 #include <X11/Shell.h>
72 #include <X11/Xaw/Paned.h>
73 #include <X11/Xaw/Label.h>
74 #endif /* USE_MOTIF */
77 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
86 #include "../lwlib/lwlib.h"
90 #include <Xm/DialogS.h>
91 #include <Xm/FileSB.h>
94 /* Do the EDITRES protocol if running X11R5
95 Exception: HP-UX (at least version A.09.05) has X11R5 without EditRes */
97 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
99 extern void _XEditResCheckMessages ();
100 #endif /* R5 + Athena */
102 /* Unique id counter for widgets created by the Lucid Widget Library. */
104 extern LWLIB_ID widget_id_tick
;
107 /* This is part of a kludge--see lwlib/xlwmenu.c. */
108 extern XFontStruct
*xlwmenu_default_font
;
111 extern void free_frame_menubar ();
112 extern double atof ();
116 /* LessTif/Motif version info. */
118 static Lisp_Object Vmotif_version_string
;
120 #endif /* USE_MOTIF */
122 #endif /* USE_X_TOOLKIT */
125 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
127 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
130 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
131 it, and including `bitmaps/gray' more than once is a problem when
132 config.h defines `static' as an empty replacement string. */
134 int gray_bitmap_width
= gray_width
;
135 int gray_bitmap_height
= gray_height
;
136 char *gray_bitmap_bits
= gray_bits
;
138 /* The name we're using in resource queries. Most often "emacs". */
140 Lisp_Object Vx_resource_name
;
142 /* The application class we're using in resource queries.
145 Lisp_Object Vx_resource_class
;
147 /* Non-zero means we're allowed to display an hourglass cursor. */
149 int display_hourglass_p
;
151 /* The background and shape of the mouse pointer, and shape when not
152 over text or in the modeline. */
154 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
155 Lisp_Object Vx_hourglass_pointer_shape
;
157 /* The shape when over mouse-sensitive text. */
159 Lisp_Object Vx_sensitive_text_pointer_shape
;
161 /* If non-nil, the pointer shape to indicate that windows can be
162 dragged horizontally. */
164 Lisp_Object Vx_window_horizontal_drag_shape
;
166 /* Color of chars displayed in cursor box. */
168 Lisp_Object Vx_cursor_fore_pixel
;
170 /* Nonzero if using X. */
174 /* Non nil if no window manager is in use. */
176 Lisp_Object Vx_no_window_manager
;
178 /* Search path for bitmap files. */
180 Lisp_Object Vx_bitmap_file_path
;
182 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
184 Lisp_Object Vx_pixel_size_width_font_regexp
;
186 Lisp_Object Qauto_raise
;
187 Lisp_Object Qauto_lower
;
188 Lisp_Object Qborder_color
;
189 Lisp_Object Qborder_width
;
190 extern Lisp_Object Qbox
;
191 Lisp_Object Qcursor_color
;
192 Lisp_Object Qcursor_type
;
193 Lisp_Object Qgeometry
;
194 Lisp_Object Qicon_left
;
195 Lisp_Object Qicon_top
;
196 Lisp_Object Qicon_type
;
197 Lisp_Object Qicon_name
;
198 Lisp_Object Qinternal_border_width
;
201 Lisp_Object Qmouse_color
;
203 Lisp_Object Qouter_window_id
;
204 Lisp_Object Qparent_id
;
205 Lisp_Object Qscroll_bar_width
;
206 Lisp_Object Qsuppress_icon
;
207 extern Lisp_Object Qtop
;
208 Lisp_Object Qundefined_color
;
209 Lisp_Object Qvertical_scroll_bars
;
210 Lisp_Object Qvisibility
;
211 Lisp_Object Qwindow_id
;
212 Lisp_Object Qx_frame_parameter
;
213 Lisp_Object Qx_resource_name
;
214 Lisp_Object Quser_position
;
215 Lisp_Object Quser_size
;
216 extern Lisp_Object Qdisplay
;
217 Lisp_Object Qscroll_bar_foreground
, Qscroll_bar_background
;
218 Lisp_Object Qscreen_gamma
, Qline_spacing
, Qcenter
;
219 Lisp_Object Qcompound_text
, Qcancel_timer
;
220 Lisp_Object Qwait_for_wm
;
221 Lisp_Object Qfullscreen
;
222 Lisp_Object Qfullwidth
;
223 Lisp_Object Qfullheight
;
224 Lisp_Object Qfullboth
;
226 /* The below are defined in frame.c. */
228 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
229 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
, Qbuffer_predicate
, Qtitle
;
230 extern Lisp_Object Qtool_bar_lines
;
232 extern Lisp_Object Vwindow_system_version
;
234 Lisp_Object Qface_set_after_frame_default
;
237 int image_cache_refcount
, dpyinfo_refcount
;
242 /* Error if we are not connected to X. */
248 error ("X windows are not in use or not initialized");
251 /* Nonzero if we can use mouse menus.
252 You should not call this unless HAVE_MENUS is defined. */
260 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
261 and checking validity for X. */
264 check_x_frame (frame
)
270 frame
= selected_frame
;
271 CHECK_LIVE_FRAME (frame
);
274 error ("Non-X frame used");
278 /* Let the user specify an X display with a frame.
279 nil stands for the selected frame--or, if that is not an X frame,
280 the first X display on the list. */
282 static struct x_display_info
*
283 check_x_display_info (frame
)
286 struct x_display_info
*dpyinfo
= NULL
;
290 struct frame
*sf
= XFRAME (selected_frame
);
292 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
293 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
294 else if (x_display_list
!= 0)
295 dpyinfo
= x_display_list
;
297 error ("X windows are not in use or not initialized");
299 else if (STRINGP (frame
))
300 dpyinfo
= x_display_info_for_name (frame
);
303 FRAME_PTR f
= check_x_frame (frame
);
304 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
311 /* Return the Emacs frame-object corresponding to an X window.
312 It could be the frame's main window or an icon window. */
314 /* This function can be called during GC, so use GC_xxx type test macros. */
317 x_window_to_frame (dpyinfo
, wdesc
)
318 struct x_display_info
*dpyinfo
;
321 Lisp_Object tail
, frame
;
324 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
327 if (!GC_FRAMEP (frame
))
330 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
332 if (f
->output_data
.x
->hourglass_window
== wdesc
)
335 if ((f
->output_data
.x
->edit_widget
336 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
337 /* A tooltip frame? */
338 || (!f
->output_data
.x
->edit_widget
339 && FRAME_X_WINDOW (f
) == wdesc
)
340 || f
->output_data
.x
->icon_desc
== wdesc
)
342 #else /* not USE_X_TOOLKIT */
343 if (FRAME_X_WINDOW (f
) == wdesc
344 || f
->output_data
.x
->icon_desc
== wdesc
)
346 #endif /* not USE_X_TOOLKIT */
352 /* Like x_window_to_frame but also compares the window with the widget's
356 x_any_window_to_frame (dpyinfo
, wdesc
)
357 struct x_display_info
*dpyinfo
;
360 Lisp_Object tail
, frame
;
361 struct frame
*f
, *found
;
365 for (tail
= Vframe_list
; GC_CONSP (tail
) && !found
; tail
= XCDR (tail
))
368 if (!GC_FRAMEP (frame
))
372 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
374 /* This frame matches if the window is any of its widgets. */
375 x
= f
->output_data
.x
;
376 if (x
->hourglass_window
== wdesc
)
380 if (wdesc
== XtWindow (x
->widget
)
381 || wdesc
== XtWindow (x
->column_widget
)
382 || wdesc
== XtWindow (x
->edit_widget
))
384 /* Match if the window is this frame's menubar. */
385 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
388 else if (FRAME_X_WINDOW (f
) == wdesc
)
389 /* A tooltip frame. */
397 /* Likewise, but exclude the menu bar widget. */
400 x_non_menubar_window_to_frame (dpyinfo
, wdesc
)
401 struct x_display_info
*dpyinfo
;
404 Lisp_Object tail
, frame
;
408 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
411 if (!GC_FRAMEP (frame
))
414 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
416 x
= f
->output_data
.x
;
417 /* This frame matches if the window is any of its widgets. */
418 if (x
->hourglass_window
== wdesc
)
422 if (wdesc
== XtWindow (x
->widget
)
423 || wdesc
== XtWindow (x
->column_widget
)
424 || wdesc
== XtWindow (x
->edit_widget
))
427 else if (FRAME_X_WINDOW (f
) == wdesc
)
428 /* A tooltip frame. */
434 /* Likewise, but consider only the menu bar widget. */
437 x_menubar_window_to_frame (dpyinfo
, wdesc
)
438 struct x_display_info
*dpyinfo
;
441 Lisp_Object tail
, frame
;
445 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
448 if (!GC_FRAMEP (frame
))
451 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
453 x
= f
->output_data
.x
;
454 /* Match if the window is this frame's menubar. */
455 if (x
->menubar_widget
456 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
462 /* Return the frame whose principal (outermost) window is WDESC.
463 If WDESC is some other (smaller) window, we return 0. */
466 x_top_window_to_frame (dpyinfo
, wdesc
)
467 struct x_display_info
*dpyinfo
;
470 Lisp_Object tail
, frame
;
474 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
477 if (!GC_FRAMEP (frame
))
480 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
482 x
= f
->output_data
.x
;
486 /* This frame matches if the window is its topmost widget. */
487 if (wdesc
== XtWindow (x
->widget
))
489 #if 0 /* I don't know why it did this,
490 but it seems logically wrong,
491 and it causes trouble for MapNotify events. */
492 /* Match if the window is this frame's menubar. */
493 if (x
->menubar_widget
494 && wdesc
== XtWindow (x
->menubar_widget
))
498 else if (FRAME_X_WINDOW (f
) == wdesc
)
504 #endif /* USE_X_TOOLKIT */
508 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
509 id, which is just an int that this section returns. Bitmaps are
510 reference counted so they can be shared among frames.
512 Bitmap indices are guaranteed to be > 0, so a negative number can
513 be used to indicate no bitmap.
515 If you use x_create_bitmap_from_data, then you must keep track of
516 the bitmaps yourself. That is, creating a bitmap from the same
517 data more than once will not be caught. */
520 /* Functions to access the contents of a bitmap, given an id. */
523 x_bitmap_height (f
, id
)
527 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
531 x_bitmap_width (f
, id
)
535 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
539 x_bitmap_pixmap (f
, id
)
543 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
547 /* Allocate a new bitmap record. Returns index of new record. */
550 x_allocate_bitmap_record (f
)
553 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
556 if (dpyinfo
->bitmaps
== NULL
)
558 dpyinfo
->bitmaps_size
= 10;
560 = (struct x_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct x_bitmap_record
));
561 dpyinfo
->bitmaps_last
= 1;
565 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
566 return ++dpyinfo
->bitmaps_last
;
568 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
569 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
572 dpyinfo
->bitmaps_size
*= 2;
574 = (struct x_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
575 dpyinfo
->bitmaps_size
* sizeof (struct x_bitmap_record
));
576 return ++dpyinfo
->bitmaps_last
;
579 /* Add one reference to the reference count of the bitmap with id ID. */
582 x_reference_bitmap (f
, id
)
586 ++FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
589 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
592 x_create_bitmap_from_data (f
, bits
, width
, height
)
595 unsigned int width
, height
;
597 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
601 bitmap
= XCreateBitmapFromData (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
602 bits
, width
, height
);
607 id
= x_allocate_bitmap_record (f
);
608 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
609 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
610 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
611 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
612 dpyinfo
->bitmaps
[id
- 1].height
= height
;
613 dpyinfo
->bitmaps
[id
- 1].width
= width
;
618 /* Create bitmap from file FILE for frame F. */
621 x_create_bitmap_from_file (f
, file
)
625 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
626 unsigned int width
, height
;
628 int xhot
, yhot
, result
, id
;
633 /* Look for an existing bitmap with the same name. */
634 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
636 if (dpyinfo
->bitmaps
[id
].refcount
637 && dpyinfo
->bitmaps
[id
].file
638 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) SDATA (file
)))
640 ++dpyinfo
->bitmaps
[id
].refcount
;
645 /* Search bitmap-file-path for the file, if appropriate. */
646 fd
= openp (Vx_bitmap_file_path
, file
, Qnil
, &found
, Qnil
);
651 filename
= (char *) SDATA (found
);
653 result
= XReadBitmapFile (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
654 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
655 if (result
!= BitmapSuccess
)
658 id
= x_allocate_bitmap_record (f
);
659 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
660 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
661 dpyinfo
->bitmaps
[id
- 1].file
662 = (char *) xmalloc (SBYTES (file
) + 1);
663 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
664 dpyinfo
->bitmaps
[id
- 1].height
= height
;
665 dpyinfo
->bitmaps
[id
- 1].width
= width
;
666 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, SDATA (file
));
671 /* Remove reference to bitmap with id number ID. */
674 x_destroy_bitmap (f
, id
)
678 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
682 --dpyinfo
->bitmaps
[id
- 1].refcount
;
683 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
686 XFreePixmap (FRAME_X_DISPLAY (f
), dpyinfo
->bitmaps
[id
- 1].pixmap
);
687 if (dpyinfo
->bitmaps
[id
- 1].file
)
689 xfree (dpyinfo
->bitmaps
[id
- 1].file
);
690 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
697 /* Free all the bitmaps for the display specified by DPYINFO. */
700 x_destroy_all_bitmaps (dpyinfo
)
701 struct x_display_info
*dpyinfo
;
704 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
705 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
707 XFreePixmap (dpyinfo
->display
, dpyinfo
->bitmaps
[i
].pixmap
);
708 if (dpyinfo
->bitmaps
[i
].file
)
709 xfree (dpyinfo
->bitmaps
[i
].file
);
711 dpyinfo
->bitmaps_last
= 0;
714 /* Connect the frame-parameter names for X frames
715 to the ways of passing the parameter values to the window system.
717 The name of a parameter, as a Lisp symbol,
718 has an `x-frame-parameter' property which is an integer in Lisp
719 that is an index in this table. */
721 struct x_frame_parm_table
724 void (*setter
) P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
727 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
728 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
729 static void x_change_window_heights
P_ ((Lisp_Object
, int));
730 static void x_disable_image
P_ ((struct frame
*, struct image
*));
731 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
732 static void x_set_line_spacing
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
733 static void x_set_wait_for_wm
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
734 static void x_set_fullscreen
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
735 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
736 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
737 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
738 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
739 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
740 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
741 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
742 static void x_set_fringe_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
743 void x_set_font
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
744 void x_set_border_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
745 void x_set_internal_border_width
P_ ((struct frame
*, Lisp_Object
,
747 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
748 void x_set_autoraise
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
749 void x_set_autolower
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
750 void x_set_vertical_scroll_bars
P_ ((struct frame
*, Lisp_Object
,
752 void x_set_visibility
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
753 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
754 void x_set_scroll_bar_width
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
755 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
756 void x_set_unsplittable
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
757 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
758 void x_set_scroll_bar_foreground
P_ ((struct frame
*, Lisp_Object
,
760 void x_set_scroll_bar_background
P_ ((struct frame
*, Lisp_Object
,
762 static Lisp_Object x_default_scroll_bar_color_parameter
P_ ((struct frame
*,
767 static void x_set_screen_gamma
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
768 static void x_edge_detection
P_ ((struct frame
*, struct image
*, Lisp_Object
,
770 static void init_color_table
P_ ((void));
771 static void free_color_table
P_ ((void));
772 static unsigned long *colors_in_color_table
P_ ((int *n
));
773 static unsigned long lookup_rgb_color
P_ ((struct frame
*f
, int r
, int g
, int b
));
774 static unsigned long lookup_pixel_color
P_ ((struct frame
*f
, unsigned long p
));
778 static struct x_frame_parm_table x_frame_parms
[] =
780 {"auto-raise", x_set_autoraise
},
781 {"auto-lower", x_set_autolower
},
782 {"background-color", x_set_background_color
},
783 {"border-color", x_set_border_color
},
784 {"border-width", x_set_border_width
},
785 {"cursor-color", x_set_cursor_color
},
786 {"cursor-type", x_set_cursor_type
},
787 {"font", x_set_font
},
788 {"foreground-color", x_set_foreground_color
},
789 {"icon-name", x_set_icon_name
},
790 {"icon-type", x_set_icon_type
},
791 {"internal-border-width", x_set_internal_border_width
},
792 {"menu-bar-lines", x_set_menu_bar_lines
},
793 {"mouse-color", x_set_mouse_color
},
794 {"name", x_explicitly_set_name
},
795 {"scroll-bar-width", x_set_scroll_bar_width
},
796 {"title", x_set_title
},
797 {"unsplittable", x_set_unsplittable
},
798 {"vertical-scroll-bars", x_set_vertical_scroll_bars
},
799 {"visibility", x_set_visibility
},
800 {"tool-bar-lines", x_set_tool_bar_lines
},
801 {"scroll-bar-foreground", x_set_scroll_bar_foreground
},
802 {"scroll-bar-background", x_set_scroll_bar_background
},
803 {"screen-gamma", x_set_screen_gamma
},
804 {"line-spacing", x_set_line_spacing
},
805 {"left-fringe", x_set_fringe_width
},
806 {"right-fringe", x_set_fringe_width
},
807 {"wait-for-wm", x_set_wait_for_wm
},
808 {"fullscreen", x_set_fullscreen
},
812 /* Attach the `x-frame-parameter' properties to
813 the Lisp symbol names of parameters relevant to X. */
816 init_x_parm_symbols ()
820 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
821 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
826 /* Really try to move where we want to be in case of fullscreen. Some WMs
827 moves the window where we tell them. Some (mwm, twm) moves the outer
828 window manager window there instead.
829 Try to compensate for those WM here. */
831 x_fullscreen_move (f
, new_top
, new_left
)
836 if (new_top
!= f
->output_data
.x
->top_pos
837 || new_left
!= f
->output_data
.x
->left_pos
)
839 int move_x
= new_left
+ f
->output_data
.x
->x_pixels_outer_diff
;
840 int move_y
= new_top
+ f
->output_data
.x
->y_pixels_outer_diff
;
842 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_MOVE_WAIT
;
843 x_set_offset (f
, move_x
, move_y
, 1);
847 /* Change the parameters of frame F as specified by ALIST.
848 If a parameter is not specially recognized, do nothing special;
849 otherwise call the `x_set_...' function for that parameter.
850 Except for certain geometry properties, always call store_frame_param
851 to store the new value in the parameter alist. */
854 x_set_frame_parameters (f
, alist
)
860 /* If both of these parameters are present, it's more efficient to
861 set them both at once. So we wait until we've looked at the
862 entire list before we set them. */
866 Lisp_Object left
, top
;
868 /* Same with these. */
869 Lisp_Object icon_left
, icon_top
;
871 /* Record in these vectors all the parms specified. */
875 int left_no_change
= 0, top_no_change
= 0;
876 int icon_left_no_change
= 0, icon_top_no_change
= 0;
877 int fullscreen_is_being_set
= 0;
879 struct gcpro gcpro1
, gcpro2
;
882 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
885 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
886 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
888 /* Extract parm names and values into those vectors. */
891 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
896 parms
[i
] = Fcar (elt
);
897 values
[i
] = Fcdr (elt
);
900 /* TAIL and ALIST are not used again below here. */
903 GCPRO2 (*parms
, *values
);
907 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
908 because their values appear in VALUES and strings are not valid. */
909 top
= left
= Qunbound
;
910 icon_left
= icon_top
= Qunbound
;
912 /* Provide default values for HEIGHT and WIDTH. */
913 if (FRAME_NEW_WIDTH (f
))
914 width
= FRAME_NEW_WIDTH (f
);
916 width
= FRAME_WIDTH (f
);
918 if (FRAME_NEW_HEIGHT (f
))
919 height
= FRAME_NEW_HEIGHT (f
);
921 height
= FRAME_HEIGHT (f
);
923 /* Process foreground_color and background_color before anything else.
924 They are independent of other properties, but other properties (e.g.,
925 cursor_color) are dependent upon them. */
926 /* Process default font as well, since fringe widths depends on it. */
927 /* Also, process fullscreen, width and height depend upon that */
928 for (p
= 0; p
< i
; p
++)
930 Lisp_Object prop
, val
;
934 if (EQ (prop
, Qforeground_color
)
935 || EQ (prop
, Qbackground_color
)
937 || EQ (prop
, Qfullscreen
))
939 register Lisp_Object param_index
, old_value
;
941 old_value
= get_frame_param (f
, prop
);
942 fullscreen_is_being_set
|= EQ (prop
, Qfullscreen
);
944 if (NILP (Fequal (val
, old_value
)))
946 store_frame_param (f
, prop
, val
);
948 param_index
= Fget (prop
, Qx_frame_parameter
);
949 if (NATNUMP (param_index
)
950 && (XFASTINT (param_index
)
951 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
952 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
957 /* Now process them in reverse of specified order. */
958 for (i
--; i
>= 0; i
--)
960 Lisp_Object prop
, val
;
965 if (EQ (prop
, Qwidth
) && NUMBERP (val
))
966 width
= XFASTINT (val
);
967 else if (EQ (prop
, Qheight
) && NUMBERP (val
))
968 height
= XFASTINT (val
);
969 else if (EQ (prop
, Qtop
))
971 else if (EQ (prop
, Qleft
))
973 else if (EQ (prop
, Qicon_top
))
975 else if (EQ (prop
, Qicon_left
))
977 else if (EQ (prop
, Qforeground_color
)
978 || EQ (prop
, Qbackground_color
)
980 || EQ (prop
, Qfullscreen
))
981 /* Processed above. */
985 register Lisp_Object param_index
, old_value
;
987 old_value
= get_frame_param (f
, prop
);
989 store_frame_param (f
, prop
, val
);
991 param_index
= Fget (prop
, Qx_frame_parameter
);
992 if (NATNUMP (param_index
)
993 && (XFASTINT (param_index
)
994 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
995 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
999 /* Don't die if just one of these was set. */
1000 if (EQ (left
, Qunbound
))
1003 if (f
->output_data
.x
->left_pos
< 0)
1004 left
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.x
->left_pos
), Qnil
));
1006 XSETINT (left
, f
->output_data
.x
->left_pos
);
1008 if (EQ (top
, Qunbound
))
1011 if (f
->output_data
.x
->top_pos
< 0)
1012 top
= Fcons (Qplus
, Fcons (make_number (f
->output_data
.x
->top_pos
), Qnil
));
1014 XSETINT (top
, f
->output_data
.x
->top_pos
);
1017 /* If one of the icon positions was not set, preserve or default it. */
1018 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
1020 icon_left_no_change
= 1;
1021 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
1022 if (NILP (icon_left
))
1023 XSETINT (icon_left
, 0);
1025 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
1027 icon_top_no_change
= 1;
1028 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
1029 if (NILP (icon_top
))
1030 XSETINT (icon_top
, 0);
1033 if (FRAME_VISIBLE_P (f
) && fullscreen_is_being_set
)
1035 /* If the frame is visible already and the fullscreen parameter is
1036 being set, it is too late to set WM manager hints to specify
1038 Here we first get the width, height and position that applies to
1039 fullscreen. We then move the frame to the appropriate
1040 position. Resize of the frame is taken care of in the code after
1041 this if-statement. */
1042 int new_left
, new_top
;
1044 x_fullscreen_adjust (f
, &width
, &height
, &new_top
, &new_left
);
1045 x_fullscreen_move (f
, new_top
, new_left
);
1048 /* Don't set these parameters unless they've been explicitly
1049 specified. The window might be mapped or resized while we're in
1050 this function, and we don't want to override that unless the lisp
1051 code has asked for it.
1053 Don't set these parameters unless they actually differ from the
1054 window's current parameters; the window may not actually exist
1059 check_frame_size (f
, &height
, &width
);
1061 XSETFRAME (frame
, f
);
1063 if (width
!= FRAME_WIDTH (f
)
1064 || height
!= FRAME_HEIGHT (f
)
1065 || FRAME_NEW_HEIGHT (f
) || FRAME_NEW_WIDTH (f
))
1066 Fset_frame_size (frame
, make_number (width
), make_number (height
));
1068 if ((!NILP (left
) || !NILP (top
))
1069 && ! (left_no_change
&& top_no_change
)
1070 && ! (NUMBERP (left
) && XINT (left
) == f
->output_data
.x
->left_pos
1071 && NUMBERP (top
) && XINT (top
) == f
->output_data
.x
->top_pos
))
1076 /* Record the signs. */
1077 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
1078 if (EQ (left
, Qminus
))
1079 f
->output_data
.x
->size_hint_flags
|= XNegative
;
1080 else if (INTEGERP (left
))
1082 leftpos
= XINT (left
);
1084 f
->output_data
.x
->size_hint_flags
|= XNegative
;
1086 else if (CONSP (left
) && EQ (XCAR (left
), Qminus
)
1087 && CONSP (XCDR (left
))
1088 && INTEGERP (XCAR (XCDR (left
))))
1090 leftpos
= - XINT (XCAR (XCDR (left
)));
1091 f
->output_data
.x
->size_hint_flags
|= XNegative
;
1093 else if (CONSP (left
) && EQ (XCAR (left
), Qplus
)
1094 && CONSP (XCDR (left
))
1095 && INTEGERP (XCAR (XCDR (left
))))
1097 leftpos
= XINT (XCAR (XCDR (left
)));
1100 if (EQ (top
, Qminus
))
1101 f
->output_data
.x
->size_hint_flags
|= YNegative
;
1102 else if (INTEGERP (top
))
1104 toppos
= XINT (top
);
1106 f
->output_data
.x
->size_hint_flags
|= YNegative
;
1108 else if (CONSP (top
) && EQ (XCAR (top
), Qminus
)
1109 && CONSP (XCDR (top
))
1110 && INTEGERP (XCAR (XCDR (top
))))
1112 toppos
= - XINT (XCAR (XCDR (top
)));
1113 f
->output_data
.x
->size_hint_flags
|= YNegative
;
1115 else if (CONSP (top
) && EQ (XCAR (top
), Qplus
)
1116 && CONSP (XCDR (top
))
1117 && INTEGERP (XCAR (XCDR (top
))))
1119 toppos
= XINT (XCAR (XCDR (top
)));
1123 /* Store the numeric value of the position. */
1124 f
->output_data
.x
->top_pos
= toppos
;
1125 f
->output_data
.x
->left_pos
= leftpos
;
1127 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
1129 /* Actually set that position, and convert to absolute. */
1130 x_set_offset (f
, leftpos
, toppos
, -1);
1133 if ((!NILP (icon_left
) || !NILP (icon_top
))
1134 && ! (icon_left_no_change
&& icon_top_no_change
))
1135 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
1141 /* Store the screen positions of frame F into XPTR and YPTR.
1142 These are the positions of the containing window manager window,
1143 not Emacs's own window. */
1146 x_real_positions (f
, xptr
, yptr
)
1150 int win_x
, win_y
, outer_x
, outer_y
;
1151 int real_x
= 0, real_y
= 0;
1153 Window win
= f
->output_data
.x
->parent_desc
;
1159 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
1161 if (win
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
1162 win
= FRAME_OUTER_WINDOW (f
);
1164 /* This loop traverses up the containment tree until we hit the root
1165 window. Window managers may intersect many windows between our window
1166 and the root window. The window we find just before the root window
1167 should be the outer WM window. */
1170 Window wm_window
, rootw
;
1171 Window
*tmp_children
;
1172 unsigned int tmp_nchildren
;
1175 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
1176 &wm_window
, &tmp_children
, &tmp_nchildren
);
1178 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
1180 /* Don't free tmp_children if XQueryTree failed. */
1184 XFree ((char *) tmp_children
);
1186 if (wm_window
== rootw
|| had_errors
)
1195 Window child
, rootw
;
1197 /* Get the real coordinates for the WM window upper left corner */
1198 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
1199 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
1201 /* Translate real coordinates to coordinates relative to our
1202 window. For our window, the upper left corner is 0, 0.
1203 Since the upper left corner of the WM window is outside
1204 our window, win_x and win_y will be negative:
1206 ------------------ ---> x
1208 | ----------------- v y
1211 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
1213 /* From-window, to-window. */
1214 FRAME_X_DISPLAY_INFO (f
)->root_window
,
1217 /* From-position, to-position. */
1218 real_x
, real_y
, &win_x
, &win_y
,
1223 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
1230 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
1232 /* From-window, to-window. */
1233 FRAME_X_DISPLAY_INFO (f
)->root_window
,
1234 FRAME_OUTER_WINDOW (f
),
1236 /* From-position, to-position. */
1237 real_x
, real_y
, &outer_x
, &outer_y
,
1243 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
1246 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
1250 if (had_errors
) return;
1252 f
->output_data
.x
->x_pixels_diff
= -win_x
;
1253 f
->output_data
.x
->y_pixels_diff
= -win_y
;
1254 f
->output_data
.x
->x_pixels_outer_diff
= -outer_x
;
1255 f
->output_data
.x
->y_pixels_outer_diff
= -outer_y
;
1261 /* Insert a description of internally-recorded parameters of frame X
1262 into the parameter alist *ALISTPTR that is to be given to the user.
1263 Only parameters that are specific to the X window system
1264 and whose values are not correctly recorded in the frame's
1265 param_alist need to be considered here. */
1268 x_report_frame_params (f
, alistptr
)
1270 Lisp_Object
*alistptr
;
1275 /* Represent negative positions (off the top or left screen edge)
1276 in a way that Fmodify_frame_parameters will understand correctly. */
1277 XSETINT (tem
, f
->output_data
.x
->left_pos
);
1278 if (f
->output_data
.x
->left_pos
>= 0)
1279 store_in_alist (alistptr
, Qleft
, tem
);
1281 store_in_alist (alistptr
, Qleft
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1283 XSETINT (tem
, f
->output_data
.x
->top_pos
);
1284 if (f
->output_data
.x
->top_pos
>= 0)
1285 store_in_alist (alistptr
, Qtop
, tem
);
1287 store_in_alist (alistptr
, Qtop
, Fcons (Qplus
, Fcons (tem
, Qnil
)));
1289 store_in_alist (alistptr
, Qborder_width
,
1290 make_number (f
->output_data
.x
->border_width
));
1291 store_in_alist (alistptr
, Qinternal_border_width
,
1292 make_number (f
->output_data
.x
->internal_border_width
));
1293 store_in_alist (alistptr
, Qleft_fringe
,
1294 make_number (f
->output_data
.x
->left_fringe_width
));
1295 store_in_alist (alistptr
, Qright_fringe
,
1296 make_number (f
->output_data
.x
->right_fringe_width
));
1297 store_in_alist (alistptr
, Qscroll_bar_width
,
1298 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
1300 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
1301 ? make_number (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
1302 /* nil means "use default width"
1303 for non-toolkit scroll bar.
1304 ruler-mode.el depends on this. */
1306 sprintf (buf
, "%ld", (long) FRAME_X_WINDOW (f
));
1307 store_in_alist (alistptr
, Qwindow_id
,
1308 build_string (buf
));
1309 #ifdef USE_X_TOOLKIT
1310 /* Tooltip frame may not have this widget. */
1311 if (f
->output_data
.x
->widget
)
1313 sprintf (buf
, "%ld", (long) FRAME_OUTER_WINDOW (f
));
1314 store_in_alist (alistptr
, Qouter_window_id
,
1315 build_string (buf
));
1316 store_in_alist (alistptr
, Qicon_name
, f
->icon_name
);
1317 FRAME_SAMPLE_VISIBILITY (f
);
1318 store_in_alist (alistptr
, Qvisibility
,
1319 (FRAME_VISIBLE_P (f
) ? Qt
1320 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
1321 store_in_alist (alistptr
, Qdisplay
,
1322 XCAR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
1324 if (f
->output_data
.x
->parent_desc
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
1327 XSETFASTINT (tem
, f
->output_data
.x
->parent_desc
);
1328 store_in_alist (alistptr
, Qparent_id
, tem
);
1333 /* Gamma-correct COLOR on frame F. */
1336 gamma_correct (f
, color
)
1342 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
1343 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
1344 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
1349 /* Decide if color named COLOR_NAME is valid for use on frame F. If
1350 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
1351 allocate the color. Value is zero if COLOR_NAME is invalid, or
1352 no color could be allocated. */
1355 x_defined_color (f
, color_name
, color
, alloc_p
)
1362 Display
*dpy
= FRAME_X_DISPLAY (f
);
1363 Colormap cmap
= FRAME_X_COLORMAP (f
);
1366 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
1367 if (success_p
&& alloc_p
)
1368 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
1375 /* Return the pixel color value for color COLOR_NAME on frame F. If F
1376 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
1377 Signal an error if color can't be allocated. */
1380 x_decode_color (f
, color_name
, mono_color
)
1382 Lisp_Object color_name
;
1387 CHECK_STRING (color_name
);
1389 #if 0 /* Don't do this. It's wrong when we're not using the default
1390 colormap, it makes freeing difficult, and it's probably not
1391 an important optimization. */
1392 if (strcmp (SDATA (color_name
), "black") == 0)
1393 return BLACK_PIX_DEFAULT (f
);
1394 else if (strcmp (SDATA (color_name
), "white") == 0)
1395 return WHITE_PIX_DEFAULT (f
);
1398 /* Return MONO_COLOR for monochrome frames. */
1399 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
1402 /* x_defined_color is responsible for coping with failures
1403 by looking for a near-miss. */
1404 if (x_defined_color (f
, SDATA (color_name
), &cdef
, 1))
1407 Fsignal (Qerror
, Fcons (build_string ("Undefined color"),
1408 Fcons (color_name
, Qnil
)));
1414 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
1415 the previous value of that parameter, NEW_VALUE is the new value. */
1418 x_set_line_spacing (f
, new_value
, old_value
)
1420 Lisp_Object new_value
, old_value
;
1422 if (NILP (new_value
))
1423 f
->extra_line_spacing
= 0;
1424 else if (NATNUMP (new_value
))
1425 f
->extra_line_spacing
= XFASTINT (new_value
);
1427 Fsignal (Qerror
, Fcons (build_string ("Invalid line-spacing"),
1428 Fcons (new_value
, Qnil
)));
1429 if (FRAME_VISIBLE_P (f
))
1434 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
1435 the previous value of that parameter, NEW_VALUE is the new value.
1436 See also the comment of wait_for_wm in struct x_output. */
1439 x_set_wait_for_wm (f
, new_value
, old_value
)
1441 Lisp_Object new_value
, old_value
;
1443 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
1447 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
1448 the previous value of that parameter, NEW_VALUE is the new value. */
1451 x_set_fullscreen (f
, new_value
, old_value
)
1453 Lisp_Object new_value
, old_value
;
1455 if (NILP (new_value
))
1456 f
->output_data
.x
->want_fullscreen
= FULLSCREEN_NONE
;
1457 else if (EQ (new_value
, Qfullboth
))
1458 f
->output_data
.x
->want_fullscreen
= FULLSCREEN_BOTH
;
1459 else if (EQ (new_value
, Qfullwidth
))
1460 f
->output_data
.x
->want_fullscreen
= FULLSCREEN_WIDTH
;
1461 else if (EQ (new_value
, Qfullheight
))
1462 f
->output_data
.x
->want_fullscreen
= FULLSCREEN_HEIGHT
;
1466 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
1467 the previous value of that parameter, NEW_VALUE is the new
1471 x_set_screen_gamma (f
, new_value
, old_value
)
1473 Lisp_Object new_value
, old_value
;
1475 if (NILP (new_value
))
1477 else if (NUMBERP (new_value
) && XFLOATINT (new_value
) > 0)
1478 /* The value 0.4545 is the normal viewing gamma. */
1479 f
->gamma
= 1.0 / (0.4545 * XFLOATINT (new_value
));
1481 Fsignal (Qerror
, Fcons (build_string ("Invalid screen-gamma"),
1482 Fcons (new_value
, Qnil
)));
1484 clear_face_cache (0);
1488 /* Functions called only from `x_set_frame_param'
1489 to set individual parameters.
1491 If FRAME_X_WINDOW (f) is 0,
1492 the frame is being created and its X-window does not exist yet.
1493 In that case, just record the parameter's new value
1494 in the standard place; do not attempt to change the window. */
1497 x_set_foreground_color (f
, arg
, oldval
)
1499 Lisp_Object arg
, oldval
;
1501 struct x_output
*x
= f
->output_data
.x
;
1502 unsigned long fg
, old_fg
;
1504 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1505 old_fg
= x
->foreground_pixel
;
1506 x
->foreground_pixel
= fg
;
1508 if (FRAME_X_WINDOW (f
) != 0)
1510 Display
*dpy
= FRAME_X_DISPLAY (f
);
1513 XSetForeground (dpy
, x
->normal_gc
, fg
);
1514 XSetBackground (dpy
, x
->reverse_gc
, fg
);
1516 if (x
->cursor_pixel
== old_fg
)
1518 unload_color (f
, x
->cursor_pixel
);
1519 x
->cursor_pixel
= x_copy_color (f
, fg
);
1520 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
1525 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
1527 if (FRAME_VISIBLE_P (f
))
1531 unload_color (f
, old_fg
);
1535 x_set_background_color (f
, arg
, oldval
)
1537 Lisp_Object arg
, oldval
;
1539 struct x_output
*x
= f
->output_data
.x
;
1542 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1543 unload_color (f
, x
->background_pixel
);
1544 x
->background_pixel
= bg
;
1546 if (FRAME_X_WINDOW (f
) != 0)
1548 Display
*dpy
= FRAME_X_DISPLAY (f
);
1551 XSetBackground (dpy
, x
->normal_gc
, bg
);
1552 XSetForeground (dpy
, x
->reverse_gc
, bg
);
1553 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
1554 XSetForeground (dpy
, x
->cursor_gc
, bg
);
1556 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
1557 toolkit scroll bars. */
1560 for (bar
= FRAME_SCROLL_BARS (f
);
1562 bar
= XSCROLL_BAR (bar
)->next
)
1564 Window window
= SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
));
1565 XSetWindowBackground (dpy
, window
, bg
);
1568 #endif /* USE_TOOLKIT_SCROLL_BARS */
1571 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
1573 if (FRAME_VISIBLE_P (f
))
1579 x_set_mouse_color (f
, arg
, oldval
)
1581 Lisp_Object arg
, oldval
;
1583 struct x_output
*x
= f
->output_data
.x
;
1584 Display
*dpy
= FRAME_X_DISPLAY (f
);
1585 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
1586 Cursor hourglass_cursor
, horizontal_drag_cursor
;
1588 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1589 unsigned long mask_color
= x
->background_pixel
;
1591 /* Don't let pointers be invisible. */
1592 if (mask_color
== pixel
)
1594 x_free_colors (f
, &pixel
, 1);
1595 pixel
= x_copy_color (f
, x
->foreground_pixel
);
1598 unload_color (f
, x
->mouse_pixel
);
1599 x
->mouse_pixel
= pixel
;
1603 /* It's not okay to crash if the user selects a screwy cursor. */
1604 count
= x_catch_errors (dpy
);
1606 if (!NILP (Vx_pointer_shape
))
1608 CHECK_NUMBER (Vx_pointer_shape
);
1609 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
1612 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
1613 x_check_errors (dpy
, "bad text pointer cursor: %s");
1615 if (!NILP (Vx_nontext_pointer_shape
))
1617 CHECK_NUMBER (Vx_nontext_pointer_shape
);
1619 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
1622 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
1623 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
1625 if (!NILP (Vx_hourglass_pointer_shape
))
1627 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
1629 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
1632 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
1633 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
1635 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
1636 if (!NILP (Vx_mode_pointer_shape
))
1638 CHECK_NUMBER (Vx_mode_pointer_shape
);
1639 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
1642 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
1643 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
1645 if (!NILP (Vx_sensitive_text_pointer_shape
))
1647 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1649 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
1652 cross_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
1654 if (!NILP (Vx_window_horizontal_drag_shape
))
1656 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1657 horizontal_drag_cursor
1658 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
1661 horizontal_drag_cursor
1662 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
1664 /* Check and report errors with the above calls. */
1665 x_check_errors (dpy
, "can't set cursor shape: %s");
1666 x_uncatch_errors (dpy
, count
);
1669 XColor fore_color
, back_color
;
1671 fore_color
.pixel
= x
->mouse_pixel
;
1672 x_query_color (f
, &fore_color
);
1673 back_color
.pixel
= mask_color
;
1674 x_query_color (f
, &back_color
);
1676 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
1677 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
1678 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
1679 XRecolorCursor (dpy
, cross_cursor
, &fore_color
, &back_color
);
1680 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
1681 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1684 if (FRAME_X_WINDOW (f
) != 0)
1685 XDefineCursor (dpy
, FRAME_X_WINDOW (f
), cursor
);
1687 if (cursor
!= x
->text_cursor
1688 && x
->text_cursor
!= 0)
1689 XFreeCursor (dpy
, x
->text_cursor
);
1690 x
->text_cursor
= cursor
;
1692 if (nontext_cursor
!= x
->nontext_cursor
1693 && x
->nontext_cursor
!= 0)
1694 XFreeCursor (dpy
, x
->nontext_cursor
);
1695 x
->nontext_cursor
= nontext_cursor
;
1697 if (hourglass_cursor
!= x
->hourglass_cursor
1698 && x
->hourglass_cursor
!= 0)
1699 XFreeCursor (dpy
, x
->hourglass_cursor
);
1700 x
->hourglass_cursor
= hourglass_cursor
;
1702 if (mode_cursor
!= x
->modeline_cursor
1703 && x
->modeline_cursor
!= 0)
1704 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1705 x
->modeline_cursor
= mode_cursor
;
1707 if (cross_cursor
!= x
->cross_cursor
1708 && x
->cross_cursor
!= 0)
1709 XFreeCursor (dpy
, x
->cross_cursor
);
1710 x
->cross_cursor
= cross_cursor
;
1712 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1713 && x
->horizontal_drag_cursor
!= 0)
1714 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1715 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1720 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1724 x_set_cursor_color (f
, arg
, oldval
)
1726 Lisp_Object arg
, oldval
;
1728 unsigned long fore_pixel
, pixel
;
1729 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1730 struct x_output
*x
= f
->output_data
.x
;
1732 if (!NILP (Vx_cursor_fore_pixel
))
1734 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1735 WHITE_PIX_DEFAULT (f
));
1736 fore_pixel_allocated_p
= 1;
1739 fore_pixel
= x
->background_pixel
;
1741 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1742 pixel_allocated_p
= 1;
1744 /* Make sure that the cursor color differs from the background color. */
1745 if (pixel
== x
->background_pixel
)
1747 if (pixel_allocated_p
)
1749 x_free_colors (f
, &pixel
, 1);
1750 pixel_allocated_p
= 0;
1753 pixel
= x
->mouse_pixel
;
1754 if (pixel
== fore_pixel
)
1756 if (fore_pixel_allocated_p
)
1758 x_free_colors (f
, &fore_pixel
, 1);
1759 fore_pixel_allocated_p
= 0;
1761 fore_pixel
= x
->background_pixel
;
1765 unload_color (f
, x
->cursor_foreground_pixel
);
1766 if (!fore_pixel_allocated_p
)
1767 fore_pixel
= x_copy_color (f
, fore_pixel
);
1768 x
->cursor_foreground_pixel
= fore_pixel
;
1770 unload_color (f
, x
->cursor_pixel
);
1771 if (!pixel_allocated_p
)
1772 pixel
= x_copy_color (f
, pixel
);
1773 x
->cursor_pixel
= pixel
;
1775 if (FRAME_X_WINDOW (f
) != 0)
1778 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1779 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1782 if (FRAME_VISIBLE_P (f
))
1784 x_update_cursor (f
, 0);
1785 x_update_cursor (f
, 1);
1789 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1792 /* Set the border-color of frame F to value described by ARG.
1793 ARG can be a string naming a color.
1794 The border-color is used for the border that is drawn by the X server.
1795 Note that this does not fully take effect if done before
1796 F has an x-window; it must be redone when the window is created.
1798 Note: this is done in two routines because of the way X10 works.
1800 Note: under X11, this is normally the province of the window manager,
1801 and so emacs' border colors may be overridden. */
1804 x_set_border_color (f
, arg
, oldval
)
1806 Lisp_Object arg
, oldval
;
1811 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1812 x_set_border_pixel (f
, pix
);
1813 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1816 /* Set the border-color of frame F to pixel value PIX.
1817 Note that this does not fully take effect if done before
1818 F has an x-window. */
1821 x_set_border_pixel (f
, pix
)
1825 unload_color (f
, f
->output_data
.x
->border_pixel
);
1826 f
->output_data
.x
->border_pixel
= pix
;
1828 if (FRAME_X_WINDOW (f
) != 0 && f
->output_data
.x
->border_width
> 0)
1831 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1832 (unsigned long)pix
);
1835 if (FRAME_VISIBLE_P (f
))
1843 x_set_cursor_type (f
, arg
, oldval
)
1845 Lisp_Object arg
, oldval
;
1847 set_frame_cursor_types (f
, arg
);
1849 /* Make sure the cursor gets redrawn. */
1850 cursor_type_changed
= 1;
1854 x_set_icon_type (f
, arg
, oldval
)
1856 Lisp_Object arg
, oldval
;
1862 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1865 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1870 result
= x_text_icon (f
,
1871 (char *) SDATA ((!NILP (f
->icon_name
)
1875 result
= x_bitmap_icon (f
, arg
);
1880 error ("No icon window available");
1883 XFlush (FRAME_X_DISPLAY (f
));
1887 /* Return non-nil if frame F wants a bitmap icon. */
1895 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
1903 x_set_icon_name (f
, arg
, oldval
)
1905 Lisp_Object arg
, oldval
;
1911 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1914 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1919 if (f
->output_data
.x
->icon_bitmap
!= 0)
1924 result
= x_text_icon (f
,
1925 (char *) SDATA ((!NILP (f
->icon_name
)
1934 error ("No icon window available");
1937 XFlush (FRAME_X_DISPLAY (f
));
1942 x_set_font (f
, arg
, oldval
)
1944 Lisp_Object arg
, oldval
;
1947 Lisp_Object fontset_name
;
1949 int old_fontset
= f
->output_data
.x
->fontset
;
1953 fontset_name
= Fquery_fontset (arg
, Qnil
);
1956 result
= (STRINGP (fontset_name
)
1957 ? x_new_fontset (f
, SDATA (fontset_name
))
1958 : x_new_font (f
, SDATA (arg
)));
1961 if (EQ (result
, Qnil
))
1962 error ("Font `%s' is not defined", SDATA (arg
));
1963 else if (EQ (result
, Qt
))
1964 error ("The characters of the given font have varying widths");
1965 else if (STRINGP (result
))
1967 if (STRINGP (fontset_name
))
1969 /* Fontset names are built from ASCII font names, so the
1970 names may be equal despite there was a change. */
1971 if (old_fontset
== f
->output_data
.x
->fontset
)
1974 else if (!NILP (Fequal (result
, oldval
)))
1977 store_frame_param (f
, Qfont
, result
);
1978 recompute_basic_faces (f
);
1983 do_pending_window_change (0);
1985 /* Don't call `face-set-after-frame-default' when faces haven't been
1986 initialized yet. This is the case when called from
1987 Fx_create_frame. In that case, the X widget or window doesn't
1988 exist either, and we can end up in x_report_frame_params with a
1989 null widget which gives a segfault. */
1990 if (FRAME_FACE_CACHE (f
))
1992 XSETFRAME (frame
, f
);
1993 call1 (Qface_set_after_frame_default
, frame
);
1998 x_set_fringe_width (f
, new_value
, old_value
)
2000 Lisp_Object new_value
, old_value
;
2002 x_compute_fringe_widths (f
, 1);
2006 x_set_border_width (f
, arg
, oldval
)
2008 Lisp_Object arg
, oldval
;
2012 if (XINT (arg
) == f
->output_data
.x
->border_width
)
2015 if (FRAME_X_WINDOW (f
) != 0)
2016 error ("Cannot change the border width of a window");
2018 f
->output_data
.x
->border_width
= XINT (arg
);
2022 x_set_internal_border_width (f
, arg
, oldval
)
2024 Lisp_Object arg
, oldval
;
2026 int old
= f
->output_data
.x
->internal_border_width
;
2029 f
->output_data
.x
->internal_border_width
= XINT (arg
);
2030 if (f
->output_data
.x
->internal_border_width
< 0)
2031 f
->output_data
.x
->internal_border_width
= 0;
2033 #ifdef USE_X_TOOLKIT
2034 if (f
->output_data
.x
->edit_widget
)
2035 widget_store_internal_border (f
->output_data
.x
->edit_widget
);
2038 if (f
->output_data
.x
->internal_border_width
== old
)
2041 if (FRAME_X_WINDOW (f
) != 0)
2043 x_set_window_size (f
, 0, f
->width
, f
->height
);
2044 SET_FRAME_GARBAGED (f
);
2045 do_pending_window_change (0);
2048 SET_FRAME_GARBAGED (f
);
2052 x_set_visibility (f
, value
, oldval
)
2054 Lisp_Object value
, oldval
;
2057 XSETFRAME (frame
, f
);
2060 Fmake_frame_invisible (frame
, Qt
);
2061 else if (EQ (value
, Qicon
))
2062 Ficonify_frame (frame
);
2064 Fmake_frame_visible (frame
);
2068 /* Change window heights in windows rooted in WINDOW by N lines. */
2071 x_change_window_heights (window
, n
)
2075 struct window
*w
= XWINDOW (window
);
2077 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
2078 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
2080 if (INTEGERP (w
->orig_top
))
2081 XSETFASTINT (w
->orig_top
, XFASTINT (w
->orig_top
) + n
);
2082 if (INTEGERP (w
->orig_height
))
2083 XSETFASTINT (w
->orig_height
, XFASTINT (w
->orig_height
) - n
);
2085 /* Handle just the top child in a vertical split. */
2086 if (!NILP (w
->vchild
))
2087 x_change_window_heights (w
->vchild
, n
);
2089 /* Adjust all children in a horizontal split. */
2090 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
2092 w
= XWINDOW (window
);
2093 x_change_window_heights (window
, n
);
2098 x_set_menu_bar_lines (f
, value
, oldval
)
2100 Lisp_Object value
, oldval
;
2103 #ifndef USE_X_TOOLKIT
2104 int olines
= FRAME_MENU_BAR_LINES (f
);
2107 /* Right now, menu bars don't work properly in minibuf-only frames;
2108 most of the commands try to apply themselves to the minibuffer
2109 frame itself, and get an error because you can't switch buffers
2110 in or split the minibuffer window. */
2111 if (FRAME_MINIBUF_ONLY_P (f
))
2114 if (INTEGERP (value
))
2115 nlines
= XINT (value
);
2119 /* Make sure we redisplay all windows in this frame. */
2120 windows_or_buffers_changed
++;
2122 #ifdef USE_X_TOOLKIT
2123 FRAME_MENU_BAR_LINES (f
) = 0;
2126 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
2127 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
2128 /* Make sure next redisplay shows the menu bar. */
2129 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
2133 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
2134 free_frame_menubar (f
);
2135 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
2137 f
->output_data
.x
->menubar_widget
= 0;
2139 #else /* not USE_X_TOOLKIT */
2140 FRAME_MENU_BAR_LINES (f
) = nlines
;
2141 x_change_window_heights (f
->root_window
, nlines
- olines
);
2142 #endif /* not USE_X_TOOLKIT */
2147 /* Set the number of lines used for the tool bar of frame F to VALUE.
2148 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
2149 is the old number of tool bar lines. This function changes the
2150 height of all windows on frame F to match the new tool bar height.
2151 The frame's height doesn't change. */
2154 x_set_tool_bar_lines (f
, value
, oldval
)
2156 Lisp_Object value
, oldval
;
2158 int delta
, nlines
, root_height
;
2159 Lisp_Object root_window
;
2161 /* Treat tool bars like menu bars. */
2162 if (FRAME_MINIBUF_ONLY_P (f
))
2165 /* Use VALUE only if an integer >= 0. */
2166 if (INTEGERP (value
) && XINT (value
) >= 0)
2167 nlines
= XFASTINT (value
);
2171 /* Make sure we redisplay all windows in this frame. */
2172 ++windows_or_buffers_changed
;
2174 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
2176 /* Don't resize the tool-bar to more than we have room for. */
2177 root_window
= FRAME_ROOT_WINDOW (f
);
2178 root_height
= XINT (XWINDOW (root_window
)->height
);
2179 if (root_height
- delta
< 1)
2181 delta
= root_height
- 1;
2182 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
2185 FRAME_TOOL_BAR_LINES (f
) = nlines
;
2186 x_change_window_heights (root_window
, delta
);
2189 /* We also have to make sure that the internal border at the top of
2190 the frame, below the menu bar or tool bar, is redrawn when the
2191 tool bar disappears. This is so because the internal border is
2192 below the tool bar if one is displayed, but is below the menu bar
2193 if there isn't a tool bar. The tool bar draws into the area
2194 below the menu bar. */
2195 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
2199 clear_current_matrices (f
);
2200 updating_frame
= NULL
;
2203 /* If the tool bar gets smaller, the internal border below it
2204 has to be cleared. It was formerly part of the display
2205 of the larger tool bar, and updating windows won't clear it. */
2208 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2209 int width
= PIXEL_WIDTH (f
);
2210 int y
= nlines
* CANON_Y_UNIT (f
);
2213 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2214 0, y
, width
, height
, False
);
2217 if (WINDOWP (f
->tool_bar_window
))
2218 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
2223 /* Set the foreground color for scroll bars on frame F to VALUE.
2224 VALUE should be a string, a color name. If it isn't a string or
2225 isn't a valid color name, do nothing. OLDVAL is the old value of
2226 the frame parameter. */
2229 x_set_scroll_bar_foreground (f
, value
, oldval
)
2231 Lisp_Object value
, oldval
;
2233 unsigned long pixel
;
2235 if (STRINGP (value
))
2236 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
2240 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
2241 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
2243 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
2244 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
2246 /* Remove all scroll bars because they have wrong colors. */
2247 if (condemn_scroll_bars_hook
)
2248 (*condemn_scroll_bars_hook
) (f
);
2249 if (judge_scroll_bars_hook
)
2250 (*judge_scroll_bars_hook
) (f
);
2252 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
2258 /* Set the background color for scroll bars on frame F to VALUE VALUE
2259 should be a string, a color name. If it isn't a string or isn't a
2260 valid color name, do nothing. OLDVAL is the old value of the frame
2264 x_set_scroll_bar_background (f
, value
, oldval
)
2266 Lisp_Object value
, oldval
;
2268 unsigned long pixel
;
2270 if (STRINGP (value
))
2271 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
2275 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
2276 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
2278 #ifdef USE_TOOLKIT_SCROLL_BARS
2279 /* Scrollbar shadow colors. */
2280 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
2282 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
2283 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2285 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
2287 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
2288 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2290 #endif /* USE_TOOLKIT_SCROLL_BARS */
2292 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
2293 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
2295 /* Remove all scroll bars because they have wrong colors. */
2296 if (condemn_scroll_bars_hook
)
2297 (*condemn_scroll_bars_hook
) (f
);
2298 if (judge_scroll_bars_hook
)
2299 (*judge_scroll_bars_hook
) (f
);
2301 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
2307 /* Encode Lisp string STRING as a text in a format appropriate for
2308 XICCC (X Inter Client Communication Conventions).
2310 If STRING contains only ASCII characters, do no conversion and
2311 return the string data of STRING. Otherwise, encode the text by
2312 CODING_SYSTEM, and return a newly allocated memory area which
2313 should be freed by `xfree' by a caller.
2315 SELECTIONP non-zero means the string is being encoded for an X
2316 selection, so it is safe to run pre-write conversions (which
2319 Store the byte length of resulting text in *TEXT_BYTES.
2321 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
2322 which means that the `encoding' of the result can be `STRING'.
2323 Otherwise store 0 in *STRINGP, which means that the `encoding' of
2324 the result should be `COMPOUND_TEXT'. */
2327 x_encode_text (string
, coding_system
, selectionp
, text_bytes
, stringp
)
2328 Lisp_Object string
, coding_system
;
2329 int *text_bytes
, *stringp
;
2332 unsigned char *str
= SDATA (string
);
2333 int chars
= SCHARS (string
);
2334 int bytes
= SBYTES (string
);
2338 struct coding_system coding
;
2339 extern Lisp_Object Qcompound_text_with_extensions
;
2341 charset_info
= find_charset_in_text (str
, chars
, bytes
, NULL
, Qnil
);
2342 if (charset_info
== 0)
2344 /* No multibyte character in OBJ. We need not encode it. */
2345 *text_bytes
= bytes
;
2350 setup_coding_system (coding_system
, &coding
);
2352 && SYMBOLP (coding
.pre_write_conversion
)
2353 && !NILP (Ffboundp (coding
.pre_write_conversion
)))
2355 string
= run_pre_post_conversion_on_str (string
, &coding
, 1);
2356 str
= SDATA (string
);
2357 chars
= SCHARS (string
);
2358 bytes
= SBYTES (string
);
2360 coding
.src_multibyte
= 1;
2361 coding
.dst_multibyte
= 0;
2362 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
2363 if (coding
.type
== coding_type_iso2022
)
2364 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
2365 /* We suppress producing escape sequences for composition. */
2366 coding
.composing
= COMPOSITION_DISABLED
;
2367 bufsize
= encoding_buffer_size (&coding
, bytes
);
2368 buf
= (unsigned char *) xmalloc (bufsize
);
2369 encode_coding (&coding
, str
, buf
, bytes
, bufsize
);
2370 *text_bytes
= coding
.produced
;
2371 *stringp
= (charset_info
== 1
2372 || (!EQ (coding_system
, Qcompound_text
)
2373 && !EQ (coding_system
, Qcompound_text_with_extensions
)));
2378 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
2381 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2382 name; if NAME is a string, set F's name to NAME and set
2383 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2385 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2386 suggesting a new name, which lisp code should override; if
2387 F->explicit_name is set, ignore the new name; otherwise, set it. */
2390 x_set_name (f
, name
, explicit)
2395 /* Make sure that requests from lisp code override requests from
2396 Emacs redisplay code. */
2399 /* If we're switching from explicit to implicit, we had better
2400 update the mode lines and thereby update the title. */
2401 if (f
->explicit_name
&& NILP (name
))
2402 update_mode_lines
= 1;
2404 f
->explicit_name
= ! NILP (name
);
2406 else if (f
->explicit_name
)
2409 /* If NAME is nil, set the name to the x_id_name. */
2412 /* Check for no change needed in this very common case
2413 before we do any consing. */
2414 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
2417 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
2420 CHECK_STRING (name
);
2422 /* Don't change the name if it's already NAME. */
2423 if (! NILP (Fstring_equal (name
, f
->name
)))
2428 /* For setting the frame title, the title parameter should override
2429 the name parameter. */
2430 if (! NILP (f
->title
))
2433 if (FRAME_X_WINDOW (f
))
2438 XTextProperty text
, icon
;
2440 Lisp_Object coding_system
;
2442 coding_system
= Qcompound_text
;
2443 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
2444 text
.encoding
= (stringp
? XA_STRING
2445 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
2447 text
.nitems
= bytes
;
2449 if (NILP (f
->icon_name
))
2455 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
2457 icon
.encoding
= (stringp
? XA_STRING
2458 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
2460 icon
.nitems
= bytes
;
2462 #ifdef USE_X_TOOLKIT
2463 XSetWMName (FRAME_X_DISPLAY (f
),
2464 XtWindow (f
->output_data
.x
->widget
), &text
);
2465 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
2467 #else /* not USE_X_TOOLKIT */
2468 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
2469 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &icon
);
2470 #endif /* not USE_X_TOOLKIT */
2471 if (!NILP (f
->icon_name
)
2472 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
2474 if (text
.value
!= (unsigned char *) SDATA (name
))
2477 #else /* not HAVE_X11R4 */
2478 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2480 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2482 #endif /* not HAVE_X11R4 */
2487 /* This function should be called when the user's lisp code has
2488 specified a name for the frame; the name will override any set by the
2491 x_explicitly_set_name (f
, arg
, oldval
)
2493 Lisp_Object arg
, oldval
;
2495 x_set_name (f
, arg
, 1);
2498 /* This function should be called by Emacs redisplay code to set the
2499 name; names set this way will never override names set by the user's
2502 x_implicitly_set_name (f
, arg
, oldval
)
2504 Lisp_Object arg
, oldval
;
2506 x_set_name (f
, arg
, 0);
2509 /* Change the title of frame F to NAME.
2510 If NAME is nil, use the frame name as the title.
2512 If EXPLICIT is non-zero, that indicates that lisp code is setting the
2513 name; if NAME is a string, set F's name to NAME and set
2514 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
2516 If EXPLICIT is zero, that indicates that Emacs redisplay code is
2517 suggesting a new name, which lisp code should override; if
2518 F->explicit_name is set, ignore the new name; otherwise, set it. */
2521 x_set_title (f
, name
, old_name
)
2523 Lisp_Object name
, old_name
;
2525 /* Don't change the title if it's already NAME. */
2526 if (EQ (name
, f
->title
))
2529 update_mode_lines
= 1;
2536 CHECK_STRING (name
);
2538 if (FRAME_X_WINDOW (f
))
2543 XTextProperty text
, icon
;
2545 Lisp_Object coding_system
;
2547 coding_system
= Qcompound_text
;
2548 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
2549 text
.encoding
= (stringp
? XA_STRING
2550 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
2552 text
.nitems
= bytes
;
2554 if (NILP (f
->icon_name
))
2560 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
2562 icon
.encoding
= (stringp
? XA_STRING
2563 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
2565 icon
.nitems
= bytes
;
2567 #ifdef USE_X_TOOLKIT
2568 XSetWMName (FRAME_X_DISPLAY (f
),
2569 XtWindow (f
->output_data
.x
->widget
), &text
);
2570 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
2572 #else /* not USE_X_TOOLKIT */
2573 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
2574 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &icon
);
2575 #endif /* not USE_X_TOOLKIT */
2576 if (!NILP (f
->icon_name
)
2577 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
2579 if (text
.value
!= (unsigned char *) SDATA (name
))
2582 #else /* not HAVE_X11R4 */
2583 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2585 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2587 #endif /* not HAVE_X11R4 */
2593 x_set_autoraise (f
, arg
, oldval
)
2595 Lisp_Object arg
, oldval
;
2597 f
->auto_raise
= !EQ (Qnil
, arg
);
2601 x_set_autolower (f
, arg
, oldval
)
2603 Lisp_Object arg
, oldval
;
2605 f
->auto_lower
= !EQ (Qnil
, arg
);
2609 x_set_unsplittable (f
, arg
, oldval
)
2611 Lisp_Object arg
, oldval
;
2613 f
->no_split
= !NILP (arg
);
2617 x_set_vertical_scroll_bars (f
, arg
, oldval
)
2619 Lisp_Object arg
, oldval
;
2621 if ((EQ (arg
, Qleft
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
2622 || (EQ (arg
, Qright
) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
2623 || (NILP (arg
) && FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
2624 || (!NILP (arg
) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
)))
2626 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
)
2628 ? vertical_scroll_bar_none
2630 ? vertical_scroll_bar_right
2631 : vertical_scroll_bar_left
);
2633 /* We set this parameter before creating the X window for the
2634 frame, so we can get the geometry right from the start.
2635 However, if the window hasn't been created yet, we shouldn't
2636 call x_set_window_size. */
2637 if (FRAME_X_WINDOW (f
))
2638 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2639 do_pending_window_change (0);
2644 x_set_scroll_bar_width (f
, arg
, oldval
)
2646 Lisp_Object arg
, oldval
;
2648 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
2652 #ifdef USE_TOOLKIT_SCROLL_BARS
2653 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
2654 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2655 FRAME_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
2656 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = width
;
2658 /* Make the actual width at least 14 pixels and a multiple of a
2660 FRAME_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
2662 /* Use all of that space (aside from required margins) for the
2664 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = 0;
2667 if (FRAME_X_WINDOW (f
))
2668 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2669 do_pending_window_change (0);
2671 else if (INTEGERP (arg
) && XINT (arg
) > 0
2672 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
2674 if (XFASTINT (arg
) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
2675 XSETINT (arg
, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
+ 1);
2677 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
2678 FRAME_SCROLL_BAR_COLS (f
) = (XFASTINT (arg
) + wid
-1) / wid
;
2679 if (FRAME_X_WINDOW (f
))
2680 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
2683 change_frame_size (f
, 0, FRAME_WIDTH (f
), 0, 0, 0);
2684 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.hpos
= 0;
2685 XWINDOW (FRAME_SELECTED_WINDOW (f
))->cursor
.x
= 0;
2690 /* Subroutines of creating an X frame. */
2692 /* Make sure that Vx_resource_name is set to a reasonable value.
2693 Fix it up, or set it to `emacs' if it is too hopeless. */
2696 validate_x_resource_name ()
2699 /* Number of valid characters in the resource name. */
2701 /* Number of invalid characters in the resource name. */
2706 if (!STRINGP (Vx_resource_class
))
2707 Vx_resource_class
= build_string (EMACS_CLASS
);
2709 if (STRINGP (Vx_resource_name
))
2711 unsigned char *p
= SDATA (Vx_resource_name
);
2714 len
= SBYTES (Vx_resource_name
);
2716 /* Only letters, digits, - and _ are valid in resource names.
2717 Count the valid characters and count the invalid ones. */
2718 for (i
= 0; i
< len
; i
++)
2721 if (! ((c
>= 'a' && c
<= 'z')
2722 || (c
>= 'A' && c
<= 'Z')
2723 || (c
>= '0' && c
<= '9')
2724 || c
== '-' || c
== '_'))
2731 /* Not a string => completely invalid. */
2732 bad_count
= 5, good_count
= 0;
2734 /* If name is valid already, return. */
2738 /* If name is entirely invalid, or nearly so, use `emacs'. */
2740 || (good_count
== 1 && bad_count
> 0))
2742 Vx_resource_name
= build_string ("emacs");
2746 /* Name is partly valid. Copy it and replace the invalid characters
2747 with underscores. */
2749 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
2751 for (i
= 0; i
< len
; i
++)
2753 int c
= SREF (new, i
);
2754 if (! ((c
>= 'a' && c
<= 'z')
2755 || (c
>= 'A' && c
<= 'Z')
2756 || (c
>= '0' && c
<= '9')
2757 || c
== '-' || c
== '_'))
2763 extern char *x_get_string_resource ();
2765 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
2766 doc
: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
2767 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
2768 class, where INSTANCE is the name under which Emacs was invoked, or
2769 the name specified by the `-name' or `-rn' command-line arguments.
2771 The optional arguments COMPONENT and SUBCLASS add to the key and the
2772 class, respectively. You must specify both of them or neither.
2773 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
2774 and the class is `Emacs.CLASS.SUBCLASS'. */)
2775 (attribute
, class, component
, subclass
)
2776 Lisp_Object attribute
, class, component
, subclass
;
2778 register char *value
;
2784 CHECK_STRING (attribute
);
2785 CHECK_STRING (class);
2787 if (!NILP (component
))
2788 CHECK_STRING (component
);
2789 if (!NILP (subclass
))
2790 CHECK_STRING (subclass
);
2791 if (NILP (component
) != NILP (subclass
))
2792 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2794 validate_x_resource_name ();
2796 /* Allocate space for the components, the dots which separate them,
2797 and the final '\0'. Make them big enough for the worst case. */
2798 name_key
= (char *) alloca (SBYTES (Vx_resource_name
)
2799 + (STRINGP (component
)
2800 ? SBYTES (component
) : 0)
2801 + SBYTES (attribute
)
2804 class_key
= (char *) alloca (SBYTES (Vx_resource_class
)
2806 + (STRINGP (subclass
)
2807 ? SBYTES (subclass
) : 0)
2810 /* Start with emacs.FRAMENAME for the name (the specific one)
2811 and with `Emacs' for the class key (the general one). */
2812 strcpy (name_key
, SDATA (Vx_resource_name
));
2813 strcpy (class_key
, SDATA (Vx_resource_class
));
2815 strcat (class_key
, ".");
2816 strcat (class_key
, SDATA (class));
2818 if (!NILP (component
))
2820 strcat (class_key
, ".");
2821 strcat (class_key
, SDATA (subclass
));
2823 strcat (name_key
, ".");
2824 strcat (name_key
, SDATA (component
));
2827 strcat (name_key
, ".");
2828 strcat (name_key
, SDATA (attribute
));
2830 value
= x_get_string_resource (check_x_display_info (Qnil
)->xrdb
,
2831 name_key
, class_key
);
2833 if (value
!= (char *) 0)
2834 return build_string (value
);
2839 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
2842 display_x_get_resource (dpyinfo
, attribute
, class, component
, subclass
)
2843 struct x_display_info
*dpyinfo
;
2844 Lisp_Object attribute
, class, component
, subclass
;
2846 register char *value
;
2850 CHECK_STRING (attribute
);
2851 CHECK_STRING (class);
2853 if (!NILP (component
))
2854 CHECK_STRING (component
);
2855 if (!NILP (subclass
))
2856 CHECK_STRING (subclass
);
2857 if (NILP (component
) != NILP (subclass
))
2858 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
2860 validate_x_resource_name ();
2862 /* Allocate space for the components, the dots which separate them,
2863 and the final '\0'. Make them big enough for the worst case. */
2864 name_key
= (char *) alloca (SBYTES (Vx_resource_name
)
2865 + (STRINGP (component
)
2866 ? SBYTES (component
) : 0)
2867 + SBYTES (attribute
)
2870 class_key
= (char *) alloca (SBYTES (Vx_resource_class
)
2872 + (STRINGP (subclass
)
2873 ? SBYTES (subclass
) : 0)
2876 /* Start with emacs.FRAMENAME for the name (the specific one)
2877 and with `Emacs' for the class key (the general one). */
2878 strcpy (name_key
, SDATA (Vx_resource_name
));
2879 strcpy (class_key
, SDATA (Vx_resource_class
));
2881 strcat (class_key
, ".");
2882 strcat (class_key
, SDATA (class));
2884 if (!NILP (component
))
2886 strcat (class_key
, ".");
2887 strcat (class_key
, SDATA (subclass
));
2889 strcat (name_key
, ".");
2890 strcat (name_key
, SDATA (component
));
2893 strcat (name_key
, ".");
2894 strcat (name_key
, SDATA (attribute
));
2896 value
= x_get_string_resource (dpyinfo
->xrdb
, name_key
, class_key
);
2898 if (value
!= (char *) 0)
2899 return build_string (value
);
2904 /* Used when C code wants a resource value. */
2907 x_get_resource_string (attribute
, class)
2908 char *attribute
, *class;
2912 struct frame
*sf
= SELECTED_FRAME ();
2914 /* Allocate space for the components, the dots which separate them,
2915 and the final '\0'. */
2916 name_key
= (char *) alloca (SBYTES (Vinvocation_name
)
2917 + strlen (attribute
) + 2);
2918 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
2919 + strlen (class) + 2);
2921 sprintf (name_key
, "%s.%s",
2922 SDATA (Vinvocation_name
),
2924 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
2926 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf
)->xrdb
,
2927 name_key
, class_key
);
2930 /* Types we might convert a resource string into. */
2940 /* Return the value of parameter PARAM.
2942 First search ALIST, then Vdefault_frame_alist, then the X defaults
2943 database, using ATTRIBUTE as the attribute name and CLASS as its class.
2945 Convert the resource to the type specified by desired_type.
2947 If no default is specified, return Qunbound. If you call
2948 x_get_arg, make sure you deal with Qunbound in a reasonable way,
2949 and don't let it get stored in any Lisp-visible variables! */
2952 x_get_arg (dpyinfo
, alist
, param
, attribute
, class, type
)
2953 struct x_display_info
*dpyinfo
;
2954 Lisp_Object alist
, param
;
2957 enum resource_types type
;
2959 register Lisp_Object tem
;
2961 tem
= Fassq (param
, alist
);
2963 tem
= Fassq (param
, Vdefault_frame_alist
);
2969 tem
= display_x_get_resource (dpyinfo
,
2970 build_string (attribute
),
2971 build_string (class),
2979 case RES_TYPE_NUMBER
:
2980 return make_number (atoi (SDATA (tem
)));
2982 case RES_TYPE_FLOAT
:
2983 return make_float (atof (SDATA (tem
)));
2985 case RES_TYPE_BOOLEAN
:
2986 tem
= Fdowncase (tem
);
2987 if (!strcmp (SDATA (tem
), "on")
2988 || !strcmp (SDATA (tem
), "true"))
2993 case RES_TYPE_STRING
:
2996 case RES_TYPE_SYMBOL
:
2997 /* As a special case, we map the values `true' and `on'
2998 to Qt, and `false' and `off' to Qnil. */
3001 lower
= Fdowncase (tem
);
3002 if (!strcmp (SDATA (lower
), "on")
3003 || !strcmp (SDATA (lower
), "true"))
3005 else if (!strcmp (SDATA (lower
), "off")
3006 || !strcmp (SDATA (lower
), "false"))
3009 return Fintern (tem
, Qnil
);
3022 /* Like x_get_arg, but also record the value in f->param_alist. */
3025 x_get_and_record_arg (f
, alist
, param
, attribute
, class, type
)
3027 Lisp_Object alist
, param
;
3030 enum resource_types type
;
3034 value
= x_get_arg (FRAME_X_DISPLAY_INFO (f
), alist
, param
,
3035 attribute
, class, type
);
3037 store_frame_param (f
, param
, value
);
3042 /* Record in frame F the specified or default value according to ALIST
3043 of the parameter named PROP (a Lisp symbol).
3044 If no value is specified for PROP, look for an X default for XPROP
3045 on the frame named NAME.
3046 If that is not found either, use the value DEFLT. */
3049 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
3056 enum resource_types type
;
3060 tem
= x_get_arg (FRAME_X_DISPLAY_INFO (f
), alist
, prop
, xprop
, xclass
, type
);
3061 if (EQ (tem
, Qunbound
))
3063 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3068 /* Record in frame F the specified or default value according to ALIST
3069 of the parameter named PROP (a Lisp symbol). If no value is
3070 specified for PROP, look for an X default for XPROP on the frame
3071 named NAME. If that is not found either, use the value DEFLT. */
3074 x_default_scroll_bar_color_parameter (f
, alist
, prop
, xprop
, xclass
,
3083 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3086 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
3087 if (EQ (tem
, Qunbound
))
3089 #ifdef USE_TOOLKIT_SCROLL_BARS
3091 /* See if an X resource for the scroll bar color has been
3093 tem
= display_x_get_resource (dpyinfo
,
3094 build_string (foreground_p
3098 build_string ("verticalScrollBar"),
3102 /* If nothing has been specified, scroll bars will use a
3103 toolkit-dependent default. Because these defaults are
3104 difficult to get at without actually creating a scroll
3105 bar, use nil to indicate that no color has been
3110 #else /* not USE_TOOLKIT_SCROLL_BARS */
3114 #endif /* not USE_TOOLKIT_SCROLL_BARS */
3117 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
3123 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
3124 doc
: /* Parse an X-style geometry string STRING.
3125 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3126 The properties returned may include `top', `left', `height', and `width'.
3127 The value of `left' or `top' may be an integer,
3128 or a list (+ N) meaning N pixels relative to top/left corner,
3129 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3134 unsigned int width
, height
;
3137 CHECK_STRING (string
);
3139 geometry
= XParseGeometry ((char *) SDATA (string
),
3140 &x
, &y
, &width
, &height
);
3143 if (!!(geometry
& XValue
) != !!(geometry
& YValue
))
3144 error ("Must specify both x and y position, or neither");
3148 if (geometry
& XValue
)
3150 Lisp_Object element
;
3152 if (x
>= 0 && (geometry
& XNegative
))
3153 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
3154 else if (x
< 0 && ! (geometry
& XNegative
))
3155 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
3157 element
= Fcons (Qleft
, make_number (x
));
3158 result
= Fcons (element
, result
);
3161 if (geometry
& YValue
)
3163 Lisp_Object element
;
3165 if (y
>= 0 && (geometry
& YNegative
))
3166 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
3167 else if (y
< 0 && ! (geometry
& YNegative
))
3168 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
3170 element
= Fcons (Qtop
, make_number (y
));
3171 result
= Fcons (element
, result
);
3174 if (geometry
& WidthValue
)
3175 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
3176 if (geometry
& HeightValue
)
3177 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
3182 /* Calculate the desired size and position of this window,
3183 and return the flags saying which aspects were specified.
3185 This function does not make the coordinates positive. */
3187 #define DEFAULT_ROWS 40
3188 #define DEFAULT_COLS 80
3191 x_figure_window_size (f
, parms
)
3195 register Lisp_Object tem0
, tem1
, tem2
;
3196 long window_prompting
= 0;
3197 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3199 /* Default values if we fall through.
3200 Actually, if that happens we should get
3201 window manager prompting. */
3202 SET_FRAME_WIDTH (f
, DEFAULT_COLS
);
3203 f
->height
= DEFAULT_ROWS
;
3204 /* Window managers expect that if program-specified
3205 positions are not (0,0), they're intentional, not defaults. */
3206 f
->output_data
.x
->top_pos
= 0;
3207 f
->output_data
.x
->left_pos
= 0;
3209 tem0
= x_get_arg (dpyinfo
, parms
, Qheight
, 0, 0, RES_TYPE_NUMBER
);
3210 tem1
= x_get_arg (dpyinfo
, parms
, Qwidth
, 0, 0, RES_TYPE_NUMBER
);
3211 tem2
= x_get_arg (dpyinfo
, parms
, Quser_size
, 0, 0, RES_TYPE_NUMBER
);
3212 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3214 if (!EQ (tem0
, Qunbound
))
3216 CHECK_NUMBER (tem0
);
3217 f
->height
= XINT (tem0
);
3219 if (!EQ (tem1
, Qunbound
))
3221 CHECK_NUMBER (tem1
);
3222 SET_FRAME_WIDTH (f
, XINT (tem1
));
3224 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
3225 window_prompting
|= USSize
;
3227 window_prompting
|= PSize
;
3230 f
->output_data
.x
->vertical_scroll_bar_extra
3231 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
3233 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
3235 x_compute_fringe_widths (f
, 0);
3237 f
->output_data
.x
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3238 f
->output_data
.x
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3240 tem0
= x_get_arg (dpyinfo
, parms
, Qtop
, 0, 0, RES_TYPE_NUMBER
);
3241 tem1
= x_get_arg (dpyinfo
, parms
, Qleft
, 0, 0, RES_TYPE_NUMBER
);
3242 tem2
= x_get_arg (dpyinfo
, parms
, Quser_position
, 0, 0, RES_TYPE_NUMBER
);
3243 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
3245 if (EQ (tem0
, Qminus
))
3247 f
->output_data
.x
->top_pos
= 0;
3248 window_prompting
|= YNegative
;
3250 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qminus
)
3251 && CONSP (XCDR (tem0
))
3252 && INTEGERP (XCAR (XCDR (tem0
))))
3254 f
->output_data
.x
->top_pos
= - XINT (XCAR (XCDR (tem0
)));
3255 window_prompting
|= YNegative
;
3257 else if (CONSP (tem0
) && EQ (XCAR (tem0
), Qplus
)
3258 && CONSP (XCDR (tem0
))
3259 && INTEGERP (XCAR (XCDR (tem0
))))
3261 f
->output_data
.x
->top_pos
= XINT (XCAR (XCDR (tem0
)));
3263 else if (EQ (tem0
, Qunbound
))
3264 f
->output_data
.x
->top_pos
= 0;
3267 CHECK_NUMBER (tem0
);
3268 f
->output_data
.x
->top_pos
= XINT (tem0
);
3269 if (f
->output_data
.x
->top_pos
< 0)
3270 window_prompting
|= YNegative
;
3273 if (EQ (tem1
, Qminus
))
3275 f
->output_data
.x
->left_pos
= 0;
3276 window_prompting
|= XNegative
;
3278 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qminus
)
3279 && CONSP (XCDR (tem1
))
3280 && INTEGERP (XCAR (XCDR (tem1
))))
3282 f
->output_data
.x
->left_pos
= - XINT (XCAR (XCDR (tem1
)));
3283 window_prompting
|= XNegative
;
3285 else if (CONSP (tem1
) && EQ (XCAR (tem1
), Qplus
)
3286 && CONSP (XCDR (tem1
))
3287 && INTEGERP (XCAR (XCDR (tem1
))))
3289 f
->output_data
.x
->left_pos
= XINT (XCAR (XCDR (tem1
)));
3291 else if (EQ (tem1
, Qunbound
))
3292 f
->output_data
.x
->left_pos
= 0;
3295 CHECK_NUMBER (tem1
);
3296 f
->output_data
.x
->left_pos
= XINT (tem1
);
3297 if (f
->output_data
.x
->left_pos
< 0)
3298 window_prompting
|= XNegative
;
3301 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
3302 window_prompting
|= USPosition
;
3304 window_prompting
|= PPosition
;
3307 if (f
->output_data
.x
->want_fullscreen
!= FULLSCREEN_NONE
)
3312 /* It takes both for some WM:s to place it where we want */
3313 window_prompting
= USPosition
| PPosition
;
3314 x_fullscreen_adjust (f
, &width
, &height
, &top
, &left
);
3317 f
->output_data
.x
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
3318 f
->output_data
.x
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
3319 f
->output_data
.x
->left_pos
= left
;
3320 f
->output_data
.x
->top_pos
= top
;
3323 return window_prompting
;
3326 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
3329 XSetWMProtocols (dpy
, w
, protocols
, count
)
3336 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
3337 if (prop
== None
) return False
;
3338 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
3339 (unsigned char *) protocols
, count
);
3342 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
3344 #ifdef USE_X_TOOLKIT
3346 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
3347 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
3348 already be present because of the toolkit (Motif adds some of them,
3349 for example, but Xt doesn't). */
3352 hack_wm_protocols (f
, widget
)
3356 Display
*dpy
= XtDisplay (widget
);
3357 Window w
= XtWindow (widget
);
3358 int need_delete
= 1;
3364 Atom type
, *atoms
= 0;
3366 unsigned long nitems
= 0;
3367 unsigned long bytes_after
;
3369 if ((XGetWindowProperty (dpy
, w
,
3370 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
3371 (long)0, (long)100, False
, XA_ATOM
,
3372 &type
, &format
, &nitems
, &bytes_after
,
3373 (unsigned char **) &atoms
)
3375 && format
== 32 && type
== XA_ATOM
)
3379 if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
3381 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
3383 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
3386 if (atoms
) XFree ((char *) atoms
);
3392 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
3394 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
3396 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
3398 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
3399 XA_ATOM
, 32, PropModeAppend
,
3400 (unsigned char *) props
, count
);
3408 /* Support routines for XIC (X Input Context). */
3412 static XFontSet xic_create_xfontset
P_ ((struct frame
*, char *));
3413 static XIMStyle best_xim_style
P_ ((XIMStyles
*, XIMStyles
*));
3416 /* Supported XIM styles, ordered by preferenc. */
3418 static XIMStyle supported_xim_styles
[] =
3420 XIMPreeditPosition
| XIMStatusArea
,
3421 XIMPreeditPosition
| XIMStatusNothing
,
3422 XIMPreeditPosition
| XIMStatusNone
,
3423 XIMPreeditNothing
| XIMStatusArea
,
3424 XIMPreeditNothing
| XIMStatusNothing
,
3425 XIMPreeditNothing
| XIMStatusNone
,
3426 XIMPreeditNone
| XIMStatusArea
,
3427 XIMPreeditNone
| XIMStatusNothing
,
3428 XIMPreeditNone
| XIMStatusNone
,
3433 /* Create an X fontset on frame F with base font name
3437 xic_create_xfontset (f
, base_fontname
)
3439 char *base_fontname
;
3442 char **missing_list
;
3446 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
),
3447 base_fontname
, &missing_list
,
3448 &missing_count
, &def_string
);
3450 XFreeStringList (missing_list
);
3452 /* No need to free def_string. */
3457 /* Value is the best input style, given user preferences USER (already
3458 checked to be supported by Emacs), and styles supported by the
3459 input method XIM. */
3462 best_xim_style (user
, xim
)
3468 for (i
= 0; i
< user
->count_styles
; ++i
)
3469 for (j
= 0; j
< xim
->count_styles
; ++j
)
3470 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
3471 return user
->supported_styles
[i
];
3473 /* Return the default style. */
3474 return XIMPreeditNothing
| XIMStatusNothing
;
3477 /* Create XIC for frame F. */
3479 static XIMStyle xic_style
;
3482 create_frame_xic (f
)
3487 XFontSet xfs
= NULL
;
3492 xim
= FRAME_X_XIM (f
);
3497 XVaNestedList preedit_attr
;
3498 XVaNestedList status_attr
;
3499 char *base_fontname
;
3502 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
3503 spot
.x
= 0; spot
.y
= 1;
3504 /* Create X fontset. */
3505 fontset
= FRAME_FONTSET (f
);
3507 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
3510 /* Determine the base fontname from the ASCII font name of
3512 char *ascii_font
= (char *) SDATA (fontset_ascii (fontset
));
3513 char *p
= ascii_font
;
3516 for (i
= 0; *p
; p
++)
3519 /* As the font name doesn't conform to XLFD, we can't
3520 modify it to get a suitable base fontname for the
3522 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
3525 int len
= strlen (ascii_font
) + 1;
3528 for (i
= 0, p
= ascii_font
; i
< 8; p
++)
3537 base_fontname
= (char *) alloca (len
);
3538 bzero (base_fontname
, len
);
3539 strcpy (base_fontname
, "-*-*-");
3540 bcopy (p1
, base_fontname
+ 5, p
- p1
);
3541 strcat (base_fontname
, "*-*-*-*-*-*-*");
3544 xfs
= xic_create_xfontset (f
, base_fontname
);
3546 /* Determine XIC style. */
3549 XIMStyles supported_list
;
3550 supported_list
.count_styles
= (sizeof supported_xim_styles
3551 / sizeof supported_xim_styles
[0]);
3552 supported_list
.supported_styles
= supported_xim_styles
;
3553 xic_style
= best_xim_style (&supported_list
,
3554 FRAME_X_XIM_STYLES (f
));
3557 preedit_attr
= XVaCreateNestedList (0,
3560 FRAME_FOREGROUND_PIXEL (f
),
3562 FRAME_BACKGROUND_PIXEL (f
),
3563 (xic_style
& XIMPreeditPosition
3568 status_attr
= XVaCreateNestedList (0,
3574 FRAME_FOREGROUND_PIXEL (f
),
3576 FRAME_BACKGROUND_PIXEL (f
),
3579 xic
= XCreateIC (xim
,
3580 XNInputStyle
, xic_style
,
3581 XNClientWindow
, FRAME_X_WINDOW(f
),
3582 XNFocusWindow
, FRAME_X_WINDOW(f
),
3583 XNStatusAttributes
, status_attr
,
3584 XNPreeditAttributes
, preedit_attr
,
3586 XFree (preedit_attr
);
3587 XFree (status_attr
);
3590 FRAME_XIC (f
) = xic
;
3591 FRAME_XIC_STYLE (f
) = xic_style
;
3592 FRAME_XIC_FONTSET (f
) = xfs
;
3596 /* Destroy XIC and free XIC fontset of frame F, if any. */
3602 if (FRAME_XIC (f
) == NULL
)
3605 XDestroyIC (FRAME_XIC (f
));
3606 if (FRAME_XIC_FONTSET (f
))
3607 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
3609 FRAME_XIC (f
) = NULL
;
3610 FRAME_XIC_FONTSET (f
) = NULL
;
3614 /* Place preedit area for XIC of window W's frame to specified
3615 pixel position X/Y. X and Y are relative to window W. */
3618 xic_set_preeditarea (w
, x
, y
)
3622 struct frame
*f
= XFRAME (w
->frame
);
3626 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
);
3627 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
3628 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
3629 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
3634 /* Place status area for XIC in bottom right corner of frame F.. */
3637 xic_set_statusarea (f
)
3640 XIC xic
= FRAME_XIC (f
);
3645 /* Negotiate geometry of status area. If input method has existing
3646 status area, use its current size. */
3647 area
.x
= area
.y
= area
.width
= area
.height
= 0;
3648 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
3649 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
3652 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
3653 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
3656 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
3658 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
3659 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
3663 area
.width
= needed
->width
;
3664 area
.height
= needed
->height
;
3665 area
.x
= PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
3666 area
.y
= (PIXEL_HEIGHT (f
) - area
.height
3667 - FRAME_MENUBAR_HEIGHT (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
));
3670 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
3671 XSetICValues(xic
, XNStatusAttributes
, attr
, NULL
);
3676 /* Set X fontset for XIC of frame F, using base font name
3677 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
3680 xic_set_xfontset (f
, base_fontname
)
3682 char *base_fontname
;
3687 xfs
= xic_create_xfontset (f
, base_fontname
);
3689 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
3690 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
3691 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
3692 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
3693 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
3696 if (FRAME_XIC_FONTSET (f
))
3697 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
3698 FRAME_XIC_FONTSET (f
) = xfs
;
3701 #endif /* HAVE_X_I18N */
3705 #ifdef USE_X_TOOLKIT
3707 /* Create and set up the X widget for frame F. */
3710 x_window (f
, window_prompting
, minibuffer_only
)
3712 long window_prompting
;
3713 int minibuffer_only
;
3715 XClassHint class_hints
;
3716 XSetWindowAttributes attributes
;
3717 unsigned long attribute_mask
;
3718 Widget shell_widget
;
3720 Widget frame_widget
;
3726 /* Use the resource name as the top-level widget name
3727 for looking up resources. Make a non-Lisp copy
3728 for the window manager, so GC relocation won't bother it.
3730 Elsewhere we specify the window name for the window manager. */
3733 char *str
= (char *) SDATA (Vx_resource_name
);
3734 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
3735 strcpy (f
->namebuf
, str
);
3739 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
3740 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
3741 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
3742 XtSetArg (al
[ac
], XtNborderWidth
, f
->output_data
.x
->border_width
); ac
++;
3743 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
3744 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
3745 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
3746 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
3747 applicationShellWidgetClass
,
3748 FRAME_X_DISPLAY (f
), al
, ac
);
3750 f
->output_data
.x
->widget
= shell_widget
;
3751 /* maybe_set_screen_title_format (shell_widget); */
3753 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
3754 (widget_value
*) NULL
,
3755 shell_widget
, False
,
3759 (lw_callback
) NULL
);
3762 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
3763 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
3764 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
3765 XtSetValues (pane_widget
, al
, ac
);
3766 f
->output_data
.x
->column_widget
= pane_widget
;
3768 /* mappedWhenManaged to false tells to the paned window to not map/unmap
3769 the emacs screen when changing menubar. This reduces flickering. */
3772 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
3773 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
3774 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
3775 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
3776 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
3777 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
3778 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
3779 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
3780 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
3783 f
->output_data
.x
->edit_widget
= frame_widget
;
3785 XtManageChild (frame_widget
);
3787 /* Do some needed geometry management. */
3790 char *tem
, shell_position
[32];
3793 int extra_borders
= 0;
3795 = (f
->output_data
.x
->menubar_widget
3796 ? (f
->output_data
.x
->menubar_widget
->core
.height
3797 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
3800 #if 0 /* Experimentally, we now get the right results
3801 for -geometry -0-0 without this. 24 Aug 96, rms. */
3802 if (FRAME_EXTERNAL_MENU_BAR (f
))
3805 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
3806 menubar_size
+= ibw
;
3810 f
->output_data
.x
->menubar_height
= menubar_size
;
3813 /* Motif seems to need this amount added to the sizes
3814 specified for the shell widget. The Athena/Lucid widgets don't.
3815 Both conclusions reached experimentally. -- rms. */
3816 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
3817 &extra_borders
, NULL
);
3821 /* Convert our geometry parameters into a geometry string
3823 Note that we do not specify here whether the position
3824 is a user-specified or program-specified one.
3825 We pass that information later, in x_wm_set_size_hints. */
3827 int left
= f
->output_data
.x
->left_pos
;
3828 int xneg
= window_prompting
& XNegative
;
3829 int top
= f
->output_data
.x
->top_pos
;
3830 int yneg
= window_prompting
& YNegative
;
3836 if (window_prompting
& USPosition
)
3837 sprintf (shell_position
, "=%dx%d%c%d%c%d",
3838 PIXEL_WIDTH (f
) + extra_borders
,
3839 PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
3840 (xneg
? '-' : '+'), left
,
3841 (yneg
? '-' : '+'), top
);
3843 sprintf (shell_position
, "=%dx%d",
3844 PIXEL_WIDTH (f
) + extra_borders
,
3845 PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
3848 len
= strlen (shell_position
) + 1;
3849 /* We don't free this because we don't know whether
3850 it is safe to free it while the frame exists.
3851 It isn't worth the trouble of arranging to free it
3852 when the frame is deleted. */
3853 tem
= (char *) xmalloc (len
);
3854 strncpy (tem
, shell_position
, len
);
3855 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
3856 XtSetValues (shell_widget
, al
, ac
);
3859 XtManageChild (pane_widget
);
3860 XtRealizeWidget (shell_widget
);
3862 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
3864 validate_x_resource_name ();
3866 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
3867 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
3868 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
3871 FRAME_XIC (f
) = NULL
;
3873 create_frame_xic (f
);
3877 f
->output_data
.x
->wm_hints
.input
= True
;
3878 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
3879 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3880 &f
->output_data
.x
->wm_hints
);
3882 hack_wm_protocols (f
, shell_widget
);
3885 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
3888 /* Do a stupid property change to force the server to generate a
3889 PropertyNotify event so that the event_stream server timestamp will
3890 be initialized to something relevant to the time we created the window.
3892 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
3893 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
3894 XA_ATOM
, 32, PropModeAppend
,
3895 (unsigned char*) NULL
, 0);
3897 /* Make all the standard events reach the Emacs frame. */
3898 attributes
.event_mask
= STANDARD_EVENT_SET
;
3903 /* XIM server might require some X events. */
3904 unsigned long fevent
= NoEventMask
;
3905 XGetICValues(FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
3906 attributes
.event_mask
|= fevent
;
3908 #endif /* HAVE_X_I18N */
3910 attribute_mask
= CWEventMask
;
3911 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
3912 attribute_mask
, &attributes
);
3914 XtMapWidget (frame_widget
);
3916 /* x_set_name normally ignores requests to set the name if the
3917 requested name is the same as the current name. This is the one
3918 place where that assumption isn't correct; f->name is set, but
3919 the X server hasn't been told. */
3922 int explicit = f
->explicit_name
;
3924 f
->explicit_name
= 0;
3927 x_set_name (f
, name
, explicit);
3930 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3931 f
->output_data
.x
->text_cursor
);
3935 /* This is a no-op, except under Motif. Make sure main areas are
3936 set to something reasonable, in case we get an error later. */
3937 lw_set_main_areas (pane_widget
, 0, frame_widget
);
3940 #else /* not USE_X_TOOLKIT */
3942 /* Create and set up the X window for frame F. */
3949 XClassHint class_hints
;
3950 XSetWindowAttributes attributes
;
3951 unsigned long attribute_mask
;
3953 attributes
.background_pixel
= f
->output_data
.x
->background_pixel
;
3954 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
3955 attributes
.bit_gravity
= StaticGravity
;
3956 attributes
.backing_store
= NotUseful
;
3957 attributes
.save_under
= True
;
3958 attributes
.event_mask
= STANDARD_EVENT_SET
;
3959 attributes
.colormap
= FRAME_X_COLORMAP (f
);
3960 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
3965 = XCreateWindow (FRAME_X_DISPLAY (f
),
3966 f
->output_data
.x
->parent_desc
,
3967 f
->output_data
.x
->left_pos
,
3968 f
->output_data
.x
->top_pos
,
3969 PIXEL_WIDTH (f
), PIXEL_HEIGHT (f
),
3970 f
->output_data
.x
->border_width
,
3971 CopyFromParent
, /* depth */
3972 InputOutput
, /* class */
3974 attribute_mask
, &attributes
);
3978 create_frame_xic (f
);
3981 /* XIM server might require some X events. */
3982 unsigned long fevent
= NoEventMask
;
3983 XGetICValues(FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
3984 attributes
.event_mask
|= fevent
;
3985 attribute_mask
= CWEventMask
;
3986 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3987 attribute_mask
, &attributes
);
3990 #endif /* HAVE_X_I18N */
3992 validate_x_resource_name ();
3994 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
3995 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
3996 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
3998 /* The menubar is part of the ordinary display;
3999 it does not count in addition to the height of the window. */
4000 f
->output_data
.x
->menubar_height
= 0;
4002 /* This indicates that we use the "Passive Input" input model.
4003 Unless we do this, we don't get the Focus{In,Out} events that we
4004 need to draw the cursor correctly. Accursed bureaucrats.
4005 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
4007 f
->output_data
.x
->wm_hints
.input
= True
;
4008 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
4009 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4010 &f
->output_data
.x
->wm_hints
);
4011 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
4013 /* Request "save yourself" and "delete window" commands from wm. */
4016 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
4017 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
4018 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
4021 /* x_set_name normally ignores requests to set the name if the
4022 requested name is the same as the current name. This is the one
4023 place where that assumption isn't correct; f->name is set, but
4024 the X server hasn't been told. */
4027 int explicit = f
->explicit_name
;
4029 f
->explicit_name
= 0;
4032 x_set_name (f
, name
, explicit);
4035 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4036 f
->output_data
.x
->text_cursor
);
4040 if (FRAME_X_WINDOW (f
) == 0)
4041 error ("Unable to create window");
4044 #endif /* not USE_X_TOOLKIT */
4046 /* Handle the icon stuff for this window. Perhaps later we might
4047 want an x_set_icon_position which can be called interactively as
4055 Lisp_Object icon_x
, icon_y
;
4056 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4058 /* Set the position of the icon. Note that twm groups all
4059 icons in an icon window. */
4060 icon_x
= x_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
4061 icon_y
= x_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
4062 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
4064 CHECK_NUMBER (icon_x
);
4065 CHECK_NUMBER (icon_y
);
4067 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
4068 error ("Both left and top icon corners of icon must be specified");
4072 if (! EQ (icon_x
, Qunbound
))
4073 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
4075 /* Start up iconic or window? */
4076 x_wm_set_window_state
4077 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
4082 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
4089 /* Make the GCs needed for this window, setting the
4090 background, border and mouse colors; also create the
4091 mouse cursor and the gray border tile. */
4093 static char cursor_bits
[] =
4095 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4096 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4097 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4098 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
4105 XGCValues gc_values
;
4109 /* Create the GCs of this frame.
4110 Note that many default values are used. */
4113 gc_values
.font
= f
->output_data
.x
->font
->fid
;
4114 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
4115 gc_values
.background
= f
->output_data
.x
->background_pixel
;
4116 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
4117 f
->output_data
.x
->normal_gc
4118 = XCreateGC (FRAME_X_DISPLAY (f
),
4120 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
4123 /* Reverse video style. */
4124 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
4125 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
4126 f
->output_data
.x
->reverse_gc
4127 = XCreateGC (FRAME_X_DISPLAY (f
),
4129 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
4132 /* Cursor has cursor-color background, background-color foreground. */
4133 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
4134 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
4135 gc_values
.fill_style
= FillOpaqueStippled
;
4137 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
4138 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4139 cursor_bits
, 16, 16);
4140 f
->output_data
.x
->cursor_gc
4141 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4142 (GCFont
| GCForeground
| GCBackground
4143 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
4147 f
->output_data
.x
->white_relief
.gc
= 0;
4148 f
->output_data
.x
->black_relief
.gc
= 0;
4150 /* Create the gray border tile used when the pointer is not in
4151 the frame. Since this depends on the frame's pixel values,
4152 this must be done on a per-frame basis. */
4153 f
->output_data
.x
->border_tile
4154 = (XCreatePixmapFromBitmapData
4155 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
4156 gray_bits
, gray_width
, gray_height
,
4157 f
->output_data
.x
->foreground_pixel
,
4158 f
->output_data
.x
->background_pixel
,
4159 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
4165 /* Free what was was allocated in x_make_gc. */
4171 Display
*dpy
= FRAME_X_DISPLAY (f
);
4175 if (f
->output_data
.x
->normal_gc
)
4177 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
4178 f
->output_data
.x
->normal_gc
= 0;
4181 if (f
->output_data
.x
->reverse_gc
)
4183 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
4184 f
->output_data
.x
->reverse_gc
= 0;
4187 if (f
->output_data
.x
->cursor_gc
)
4189 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
4190 f
->output_data
.x
->cursor_gc
= 0;
4193 if (f
->output_data
.x
->border_tile
)
4195 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
4196 f
->output_data
.x
->border_tile
= 0;
4203 /* Handler for signals raised during x_create_frame and
4204 x_create_top_frame. FRAME is the frame which is partially
4208 unwind_create_frame (frame
)
4211 struct frame
*f
= XFRAME (frame
);
4213 /* If frame is ``official'', nothing to do. */
4214 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
4217 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
4220 x_free_frame_resources (f
);
4222 /* Check that reference counts are indeed correct. */
4223 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
4224 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
4232 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
4234 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
4235 Returns an Emacs frame object.
4236 ALIST is an alist of frame parameters.
4237 If the parameters specify that the frame should not have a minibuffer,
4238 and do not specify a specific minibuffer window to use,
4239 then `default-minibuffer-frame' must be a frame whose minibuffer can
4240 be shared by the new frame.
4242 This function is an internal primitive--use `make-frame' instead. */)
4247 Lisp_Object frame
, tem
;
4249 int minibuffer_only
= 0;
4250 long window_prompting
= 0;
4252 int count
= SPECPDL_INDEX ();
4253 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4254 Lisp_Object display
;
4255 struct x_display_info
*dpyinfo
= NULL
;
4261 /* Use this general default value to start with
4262 until we know if this frame has a specified name. */
4263 Vx_resource_name
= Vinvocation_name
;
4265 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
4266 if (EQ (display
, Qunbound
))
4268 dpyinfo
= check_x_display_info (display
);
4270 kb
= dpyinfo
->kboard
;
4272 kb
= &the_only_kboard
;
4275 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4277 && ! EQ (name
, Qunbound
)
4279 error ("Invalid frame name--not a string or nil");
4282 Vx_resource_name
= name
;
4284 /* See if parent window is specified. */
4285 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
4286 if (EQ (parent
, Qunbound
))
4288 if (! NILP (parent
))
4289 CHECK_NUMBER (parent
);
4291 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
4292 /* No need to protect DISPLAY because that's not used after passing
4293 it to make_frame_without_minibuffer. */
4295 GCPRO4 (parms
, parent
, name
, frame
);
4296 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
4298 if (EQ (tem
, Qnone
) || NILP (tem
))
4299 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
4300 else if (EQ (tem
, Qonly
))
4302 f
= make_minibuffer_frame ();
4303 minibuffer_only
= 1;
4305 else if (WINDOWP (tem
))
4306 f
= make_frame_without_minibuffer (tem
, kb
, display
);
4310 XSETFRAME (frame
, f
);
4312 /* Note that X Windows does support scroll bars. */
4313 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
4315 f
->output_method
= output_x_window
;
4316 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
4317 bzero (f
->output_data
.x
, sizeof (struct x_output
));
4318 f
->output_data
.x
->icon_bitmap
= -1;
4319 f
->output_data
.x
->fontset
= -1;
4320 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4321 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4322 #ifdef USE_TOOLKIT_SCROLL_BARS
4323 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4324 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4325 #endif /* USE_TOOLKIT_SCROLL_BARS */
4326 record_unwind_protect (unwind_create_frame
, frame
);
4329 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
4331 if (! STRINGP (f
->icon_name
))
4332 f
->icon_name
= Qnil
;
4334 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4336 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
4337 dpyinfo_refcount
= dpyinfo
->reference_count
;
4338 #endif /* GLYPH_DEBUG */
4340 FRAME_KBOARD (f
) = kb
;
4343 /* These colors will be set anyway later, but it's important
4344 to get the color reference counts right, so initialize them! */
4347 struct gcpro gcpro1
;
4349 /* Function x_decode_color can signal an error. Make
4350 sure to initialize color slots so that we won't try
4351 to free colors we haven't allocated. */
4352 f
->output_data
.x
->foreground_pixel
= -1;
4353 f
->output_data
.x
->background_pixel
= -1;
4354 f
->output_data
.x
->cursor_pixel
= -1;
4355 f
->output_data
.x
->cursor_foreground_pixel
= -1;
4356 f
->output_data
.x
->border_pixel
= -1;
4357 f
->output_data
.x
->mouse_pixel
= -1;
4359 black
= build_string ("black");
4361 f
->output_data
.x
->foreground_pixel
4362 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4363 f
->output_data
.x
->background_pixel
4364 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4365 f
->output_data
.x
->cursor_pixel
4366 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4367 f
->output_data
.x
->cursor_foreground_pixel
4368 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4369 f
->output_data
.x
->border_pixel
4370 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4371 f
->output_data
.x
->mouse_pixel
4372 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4376 /* Specify the parent under which to make this X window. */
4380 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
4381 f
->output_data
.x
->explicit_parent
= 1;
4385 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4386 f
->output_data
.x
->explicit_parent
= 0;
4389 /* Set the name; the functions to which we pass f expect the name to
4391 if (EQ (name
, Qunbound
) || NILP (name
))
4393 f
->name
= build_string (dpyinfo
->x_id_name
);
4394 f
->explicit_name
= 0;
4399 f
->explicit_name
= 1;
4400 /* use the frame's title when getting resources for this frame. */
4401 specbind (Qx_resource_name
, name
);
4404 /* Extract the window parameters from the supplied values
4405 that are needed to determine window geometry. */
4409 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4412 /* First, try whatever font the caller has specified. */
4415 tem
= Fquery_fontset (font
, Qnil
);
4417 font
= x_new_fontset (f
, SDATA (tem
));
4419 font
= x_new_font (f
, SDATA (font
));
4422 /* Try out a font which we hope has bold and italic variations. */
4423 if (!STRINGP (font
))
4424 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
4425 if (!STRINGP (font
))
4426 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4427 if (! STRINGP (font
))
4428 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4429 if (! STRINGP (font
))
4430 /* This was formerly the first thing tried, but it finds too many fonts
4431 and takes too long. */
4432 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
4433 /* If those didn't work, look for something which will at least work. */
4434 if (! STRINGP (font
))
4435 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
4437 if (! STRINGP (font
))
4438 font
= build_string ("fixed");
4440 x_default_parameter (f
, parms
, Qfont
, font
,
4441 "font", "Font", RES_TYPE_STRING
);
4445 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
4446 whereby it fails to get any font. */
4447 xlwmenu_default_font
= f
->output_data
.x
->font
;
4450 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
4451 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4453 /* This defaults to 1 in order to match xterm. We recognize either
4454 internalBorderWidth or internalBorder (which is what xterm calls
4456 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4460 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4461 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4462 if (! EQ (value
, Qunbound
))
4463 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4466 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4467 "internalBorderWidth", "internalBorderWidth",
4469 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
4470 "verticalScrollBars", "ScrollBars",
4473 /* Also do the stuff which must be set before the window exists. */
4474 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4475 "foreground", "Foreground", RES_TYPE_STRING
);
4476 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4477 "background", "Background", RES_TYPE_STRING
);
4478 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4479 "pointerColor", "Foreground", RES_TYPE_STRING
);
4480 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4481 "cursorColor", "Foreground", RES_TYPE_STRING
);
4482 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4483 "borderColor", "BorderColor", RES_TYPE_STRING
);
4484 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
4485 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
4486 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
4487 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
4488 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
4489 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
4490 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
4491 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
4493 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
4494 "scrollBarForeground",
4495 "ScrollBarForeground", 1);
4496 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
4497 "scrollBarBackground",
4498 "ScrollBarBackground", 0);
4500 /* Init faces before x_default_parameter is called for scroll-bar
4501 parameters because that function calls x_set_scroll_bar_width,
4502 which calls change_frame_size, which calls Fset_window_buffer,
4503 which runs hooks, which call Fvertical_motion. At the end, we
4504 end up in init_iterator with a null face cache, which should not
4506 init_frame_faces (f
);
4508 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
4509 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
4510 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
4511 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
4512 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
4513 "bufferPredicate", "BufferPredicate",
4515 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
4516 "title", "Title", RES_TYPE_STRING
);
4517 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
4518 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
4519 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
4520 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
4522 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4524 /* Add the tool-bar height to the initial frame height so that the
4525 user gets a text display area of the size he specified with -g or
4526 via .Xdefaults. Later changes of the tool-bar height don't
4527 change the frame size. This is done so that users can create
4528 tall Emacs frames without having to guess how tall the tool-bar
4530 if (FRAME_TOOL_BAR_LINES (f
))
4532 int margin
, relief
, bar_height
;
4534 relief
= (tool_bar_button_relief
>= 0
4535 ? tool_bar_button_relief
4536 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
4538 if (INTEGERP (Vtool_bar_button_margin
)
4539 && XINT (Vtool_bar_button_margin
) > 0)
4540 margin
= XFASTINT (Vtool_bar_button_margin
);
4541 else if (CONSP (Vtool_bar_button_margin
)
4542 && INTEGERP (XCDR (Vtool_bar_button_margin
))
4543 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
4544 margin
= XFASTINT (XCDR (Vtool_bar_button_margin
));
4548 bar_height
= DEFAULT_TOOL_BAR_IMAGE_HEIGHT
+ 2 * margin
+ 2 * relief
;
4549 f
->height
+= (bar_height
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
4552 /* Compute the size of the X window. */
4553 window_prompting
= x_figure_window_size (f
, parms
);
4555 if (window_prompting
& XNegative
)
4557 if (window_prompting
& YNegative
)
4558 f
->output_data
.x
->win_gravity
= SouthEastGravity
;
4560 f
->output_data
.x
->win_gravity
= NorthEastGravity
;
4564 if (window_prompting
& YNegative
)
4565 f
->output_data
.x
->win_gravity
= SouthWestGravity
;
4567 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
4570 f
->output_data
.x
->size_hint_flags
= window_prompting
;
4572 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
4573 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
4575 /* Create the X widget or window. */
4576 #ifdef USE_X_TOOLKIT
4577 x_window (f
, window_prompting
, minibuffer_only
);
4585 /* Now consider the frame official. */
4586 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
4587 Vframe_list
= Fcons (frame
, Vframe_list
);
4589 /* We need to do this after creating the X window, so that the
4590 icon-creation functions can say whose icon they're describing. */
4591 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
4592 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
4594 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4595 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4596 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4597 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4598 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4599 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4600 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
4601 "scrollBarWidth", "ScrollBarWidth",
4604 /* Dimensions, especially f->height, must be done via change_frame_size.
4605 Change will not be effected unless different from the current
4611 SET_FRAME_WIDTH (f
, 0);
4612 change_frame_size (f
, height
, width
, 1, 0, 0);
4614 /* Set up faces after all frame parameters are known. This call
4615 also merges in face attributes specified for new frames. If we
4616 don't do this, the `menu' face for instance won't have the right
4617 colors, and the menu bar won't appear in the specified colors for
4619 call1 (Qface_set_after_frame_default
, frame
);
4621 #ifdef USE_X_TOOLKIT
4622 /* Create the menu bar. */
4623 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
4625 /* If this signals an error, we haven't set size hints for the
4626 frame and we didn't make it visible. */
4627 initialize_frame_menubar (f
);
4629 /* This is a no-op, except under Motif where it arranges the
4630 main window for the widgets on it. */
4631 lw_set_main_areas (f
->output_data
.x
->column_widget
,
4632 f
->output_data
.x
->menubar_widget
,
4633 f
->output_data
.x
->edit_widget
);
4635 #endif /* USE_X_TOOLKIT */
4637 /* Tell the server what size and position, etc, we want, and how
4638 badly we want them. This should be done after we have the menu
4639 bar so that its size can be taken into account. */
4641 x_wm_set_size_hint (f
, window_prompting
, 0);
4644 /* Make the window appear on the frame and enable display, unless
4645 the caller says not to. However, with explicit parent, Emacs
4646 cannot control visibility, so don't try. */
4647 if (! f
->output_data
.x
->explicit_parent
)
4649 Lisp_Object visibility
;
4651 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
4653 if (EQ (visibility
, Qunbound
))
4656 if (EQ (visibility
, Qicon
))
4657 x_iconify_frame (f
);
4658 else if (! NILP (visibility
))
4659 x_make_frame_visible (f
);
4661 /* Must have been Qnil. */
4667 /* Make sure windows on this frame appear in calls to next-window
4668 and similar functions. */
4669 Vwindow_list
= Qnil
;
4671 return unbind_to (count
, frame
);
4675 /* FRAME is used only to get a handle on the X display. We don't pass the
4676 display info directly because we're called from frame.c, which doesn't
4677 know about that structure. */
4680 x_get_focus_frame (frame
)
4681 struct frame
*frame
;
4683 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
4685 if (! dpyinfo
->x_focus_frame
)
4688 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
4693 /* In certain situations, when the window manager follows a
4694 click-to-focus policy, there seems to be no way around calling
4695 XSetInputFocus to give another frame the input focus .
4697 In an ideal world, XSetInputFocus should generally be avoided so
4698 that applications don't interfere with the window manager's focus
4699 policy. But I think it's okay to use when it's clearly done
4700 following a user-command. */
4702 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
4703 doc
: /* Set the input focus to FRAME.
4704 FRAME nil means use the selected frame. */)
4708 struct frame
*f
= check_x_frame (frame
);
4709 Display
*dpy
= FRAME_X_DISPLAY (f
);
4713 count
= x_catch_errors (dpy
);
4714 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4715 RevertToParent
, CurrentTime
);
4716 x_uncatch_errors (dpy
, count
);
4723 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
4724 doc
: /* Internal function called by `color-defined-p', which see. */)
4726 Lisp_Object color
, frame
;
4729 FRAME_PTR f
= check_x_frame (frame
);
4731 CHECK_STRING (color
);
4733 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
4739 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
4740 doc
: /* Internal function called by `color-values', which see. */)
4742 Lisp_Object color
, frame
;
4745 FRAME_PTR f
= check_x_frame (frame
);
4747 CHECK_STRING (color
);
4749 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
4753 rgb
[0] = make_number (foo
.red
);
4754 rgb
[1] = make_number (foo
.green
);
4755 rgb
[2] = make_number (foo
.blue
);
4756 return Flist (3, rgb
);
4762 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
4763 doc
: /* Internal function called by `display-color-p', which see. */)
4765 Lisp_Object display
;
4767 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4769 if (dpyinfo
->n_planes
<= 2)
4772 switch (dpyinfo
->visual
->class)
4785 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
4787 doc
: /* Return t if the X display supports shades of gray.
4788 Note that color displays do support shades of gray.
4789 The optional argument DISPLAY specifies which display to ask about.
4790 DISPLAY should be either a frame or a display name (a string).
4791 If omitted or nil, that stands for the selected frame's display. */)
4793 Lisp_Object display
;
4795 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4797 if (dpyinfo
->n_planes
<= 1)
4800 switch (dpyinfo
->visual
->class)
4815 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
4817 doc
: /* Returns the width in pixels of the X display DISPLAY.
4818 The optional argument DISPLAY specifies which display to ask about.
4819 DISPLAY should be either a frame or a display name (a string).
4820 If omitted or nil, that stands for the selected frame's display. */)
4822 Lisp_Object display
;
4824 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4826 return make_number (dpyinfo
->width
);
4829 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
4830 Sx_display_pixel_height
, 0, 1, 0,
4831 doc
: /* Returns the height in pixels of the X display DISPLAY.
4832 The optional argument DISPLAY specifies which display to ask about.
4833 DISPLAY should be either a frame or a display name (a string).
4834 If omitted or nil, that stands for the selected frame's display. */)
4836 Lisp_Object display
;
4838 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4840 return make_number (dpyinfo
->height
);
4843 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
4845 doc
: /* Returns the number of bitplanes of the X display DISPLAY.
4846 The optional argument DISPLAY specifies which display to ask about.
4847 DISPLAY should be either a frame or a display name (a string).
4848 If omitted or nil, that stands for the selected frame's display. */)
4850 Lisp_Object display
;
4852 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4854 return make_number (dpyinfo
->n_planes
);
4857 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
4859 doc
: /* Returns the number of color cells of the X display DISPLAY.
4860 The optional argument DISPLAY specifies which display to ask about.
4861 DISPLAY should be either a frame or a display name (a string).
4862 If omitted or nil, that stands for the selected frame's display. */)
4864 Lisp_Object display
;
4866 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4868 return make_number (DisplayCells (dpyinfo
->display
,
4869 XScreenNumberOfScreen (dpyinfo
->screen
)));
4872 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
4873 Sx_server_max_request_size
,
4875 doc
: /* Returns the maximum request size of the X server of display DISPLAY.
4876 The optional argument DISPLAY specifies which display to ask about.
4877 DISPLAY should be either a frame or a display name (a string).
4878 If omitted or nil, that stands for the selected frame's display. */)
4880 Lisp_Object display
;
4882 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4884 return make_number (MAXREQUEST (dpyinfo
->display
));
4887 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
4888 doc
: /* Returns the vendor ID string of the X server of display DISPLAY.
4889 The optional argument DISPLAY specifies which display to ask about.
4890 DISPLAY should be either a frame or a display name (a string).
4891 If omitted or nil, that stands for the selected frame's display. */)
4893 Lisp_Object display
;
4895 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4896 char *vendor
= ServerVendor (dpyinfo
->display
);
4898 if (! vendor
) vendor
= "";
4899 return build_string (vendor
);
4902 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
4903 doc
: /* Returns the version numbers of the X server of display DISPLAY.
4904 The value is a list of three integers: the major and minor
4905 version numbers of the X Protocol in use, and the vendor-specific release
4906 number. See also the function `x-server-vendor'.
4908 The optional argument DISPLAY specifies which display to ask about.
4909 DISPLAY should be either a frame or a display name (a string).
4910 If omitted or nil, that stands for the selected frame's display. */)
4912 Lisp_Object display
;
4914 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4915 Display
*dpy
= dpyinfo
->display
;
4917 return Fcons (make_number (ProtocolVersion (dpy
)),
4918 Fcons (make_number (ProtocolRevision (dpy
)),
4919 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
4922 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
4923 doc
: /* Return the number of screens on the X server of display DISPLAY.
4924 The optional argument DISPLAY specifies which display to ask about.
4925 DISPLAY should be either a frame or a display name (a string).
4926 If omitted or nil, that stands for the selected frame's display. */)
4928 Lisp_Object display
;
4930 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4932 return make_number (ScreenCount (dpyinfo
->display
));
4935 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
4936 doc
: /* Return the height in millimeters of the X display DISPLAY.
4937 The optional argument DISPLAY specifies which display to ask about.
4938 DISPLAY should be either a frame or a display name (a string).
4939 If omitted or nil, that stands for the selected frame's display. */)
4941 Lisp_Object display
;
4943 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4945 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
4948 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
4949 doc
: /* Return the width in millimeters of the X display DISPLAY.
4950 The optional argument DISPLAY specifies which display to ask about.
4951 DISPLAY should be either a frame or a display name (a string).
4952 If omitted or nil, that stands for the selected frame's display. */)
4954 Lisp_Object display
;
4956 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4958 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
4961 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
4962 Sx_display_backing_store
, 0, 1, 0,
4963 doc
: /* Returns an indication of whether X display DISPLAY does backing store.
4964 The value may be `always', `when-mapped', or `not-useful'.
4965 The optional argument DISPLAY specifies which display to ask about.
4966 DISPLAY should be either a frame or a display name (a string).
4967 If omitted or nil, that stands for the selected frame's display. */)
4969 Lisp_Object display
;
4971 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4974 switch (DoesBackingStore (dpyinfo
->screen
))
4977 result
= intern ("always");
4981 result
= intern ("when-mapped");
4985 result
= intern ("not-useful");
4989 error ("Strange value for BackingStore parameter of screen");
4996 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
4997 Sx_display_visual_class
, 0, 1, 0,
4998 doc
: /* Return the visual class of the X display DISPLAY.
4999 The value is one of the symbols `static-gray', `gray-scale',
5000 `static-color', `pseudo-color', `true-color', or `direct-color'.
5002 The optional argument DISPLAY specifies which display to ask about.
5003 DISPLAY should be either a frame or a display name (a string).
5004 If omitted or nil, that stands for the selected frame's display. */)
5006 Lisp_Object display
;
5008 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
5011 switch (dpyinfo
->visual
->class)
5014 result
= intern ("static-gray");
5017 result
= intern ("gray-scale");
5020 result
= intern ("static-color");
5023 result
= intern ("pseudo-color");
5026 result
= intern ("true-color");
5029 result
= intern ("direct-color");
5032 error ("Display has an unknown visual class");
5039 DEFUN ("x-display-save-under", Fx_display_save_under
,
5040 Sx_display_save_under
, 0, 1, 0,
5041 doc
: /* Returns t if the X display DISPLAY supports the save-under feature.
5042 The optional argument DISPLAY specifies which display to ask about.
5043 DISPLAY should be either a frame or a display name (a string).
5044 If omitted or nil, that stands for the selected frame's display. */)
5046 Lisp_Object display
;
5048 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
5050 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
5058 register struct frame
*f
;
5060 return PIXEL_WIDTH (f
);
5065 register struct frame
*f
;
5067 return PIXEL_HEIGHT (f
);
5072 register struct frame
*f
;
5074 return FONT_WIDTH (f
->output_data
.x
->font
);
5079 register struct frame
*f
;
5081 return f
->output_data
.x
->line_height
;
5086 register struct frame
*f
;
5088 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
5093 /************************************************************************
5095 ************************************************************************/
5098 /* Mapping visual names to visuals. */
5100 static struct visual_class
5107 {"StaticGray", StaticGray
},
5108 {"GrayScale", GrayScale
},
5109 {"StaticColor", StaticColor
},
5110 {"PseudoColor", PseudoColor
},
5111 {"TrueColor", TrueColor
},
5112 {"DirectColor", DirectColor
},
5117 #ifndef HAVE_XSCREENNUMBEROFSCREEN
5119 /* Value is the screen number of screen SCR. This is a substitute for
5120 the X function with the same name when that doesn't exist. */
5123 XScreenNumberOfScreen (scr
)
5124 register Screen
*scr
;
5126 Display
*dpy
= scr
->display
;
5129 for (i
= 0; i
< dpy
->nscreens
; ++i
)
5130 if (scr
== dpy
->screens
+ i
)
5136 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
5139 /* Select the visual that should be used on display DPYINFO. Set
5140 members of DPYINFO appropriately. Called from x_term_init. */
5143 select_visual (dpyinfo
)
5144 struct x_display_info
*dpyinfo
;
5146 Display
*dpy
= dpyinfo
->display
;
5147 Screen
*screen
= dpyinfo
->screen
;
5150 /* See if a visual is specified. */
5151 value
= display_x_get_resource (dpyinfo
,
5152 build_string ("visualClass"),
5153 build_string ("VisualClass"),
5155 if (STRINGP (value
))
5157 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
5158 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
5159 depth, a decimal number. NAME is compared with case ignored. */
5160 char *s
= (char *) alloca (SBYTES (value
) + 1);
5165 strcpy (s
, SDATA (value
));
5166 dash
= index (s
, '-');
5169 dpyinfo
->n_planes
= atoi (dash
+ 1);
5173 /* We won't find a matching visual with depth 0, so that
5174 an error will be printed below. */
5175 dpyinfo
->n_planes
= 0;
5177 /* Determine the visual class. */
5178 for (i
= 0; visual_classes
[i
].name
; ++i
)
5179 if (xstricmp (s
, visual_classes
[i
].name
) == 0)
5181 class = visual_classes
[i
].class;
5185 /* Look up a matching visual for the specified class. */
5187 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
5188 dpyinfo
->n_planes
, class, &vinfo
))
5189 fatal ("Invalid visual specification `%s'", SDATA (value
));
5191 dpyinfo
->visual
= vinfo
.visual
;
5196 XVisualInfo
*vinfo
, vinfo_template
;
5198 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
5201 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
5203 vinfo_template
.visualid
= dpyinfo
->visual
->visualid
;
5205 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
5206 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
5207 &vinfo_template
, &n_visuals
);
5209 fatal ("Can't get proper X visual info");
5211 dpyinfo
->n_planes
= vinfo
->depth
;
5212 XFree ((char *) vinfo
);
5217 /* Return the X display structure for the display named NAME.
5218 Open a new connection if necessary. */
5220 struct x_display_info
*
5221 x_display_info_for_name (name
)
5225 struct x_display_info
*dpyinfo
;
5227 CHECK_STRING (name
);
5229 if (! EQ (Vwindow_system
, intern ("x")))
5230 error ("Not using X Windows");
5232 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
5234 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
5237 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
5242 /* Use this general default value to start with. */
5243 Vx_resource_name
= Vinvocation_name
;
5245 validate_x_resource_name ();
5247 dpyinfo
= x_term_init (name
, (char *)0,
5248 (char *) SDATA (Vx_resource_name
));
5251 error ("Cannot connect to X server %s", SDATA (name
));
5254 XSETFASTINT (Vwindow_system_version
, 11);
5260 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
5262 doc
: /* Open a connection to an X server.
5263 DISPLAY is the name of the display to connect to.
5264 Optional second arg XRM-STRING is a string of resources in xrdb format.
5265 If the optional third arg MUST-SUCCEED is non-nil,
5266 terminate Emacs if we can't open the connection. */)
5267 (display
, xrm_string
, must_succeed
)
5268 Lisp_Object display
, xrm_string
, must_succeed
;
5270 unsigned char *xrm_option
;
5271 struct x_display_info
*dpyinfo
;
5273 CHECK_STRING (display
);
5274 if (! NILP (xrm_string
))
5275 CHECK_STRING (xrm_string
);
5277 if (! EQ (Vwindow_system
, intern ("x")))
5278 error ("Not using X Windows");
5280 if (! NILP (xrm_string
))
5281 xrm_option
= (unsigned char *) SDATA (xrm_string
);
5283 xrm_option
= (unsigned char *) 0;
5285 validate_x_resource_name ();
5287 /* This is what opens the connection and sets x_current_display.
5288 This also initializes many symbols, such as those used for input. */
5289 dpyinfo
= x_term_init (display
, xrm_option
,
5290 (char *) SDATA (Vx_resource_name
));
5294 if (!NILP (must_succeed
))
5295 fatal ("Cannot connect to X server %s.\n\
5296 Check the DISPLAY environment variable or use `-d'.\n\
5297 Also use the `xauth' program to verify that you have the proper\n\
5298 authorization information needed to connect the X server.\n\
5299 An insecure way to solve the problem may be to use `xhost'.\n",
5302 error ("Cannot connect to X server %s", SDATA (display
));
5307 XSETFASTINT (Vwindow_system_version
, 11);
5311 DEFUN ("x-close-connection", Fx_close_connection
,
5312 Sx_close_connection
, 1, 1, 0,
5313 doc
: /* Close the connection to DISPLAY's X server.
5314 For DISPLAY, specify either a frame or a display name (a string).
5315 If DISPLAY is nil, that stands for the selected frame's display. */)
5317 Lisp_Object display
;
5319 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
5322 if (dpyinfo
->reference_count
> 0)
5323 error ("Display still has frames on it");
5326 /* Free the fonts in the font table. */
5327 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
5328 if (dpyinfo
->font_table
[i
].name
)
5330 if (dpyinfo
->font_table
[i
].name
!= dpyinfo
->font_table
[i
].full_name
)
5331 xfree (dpyinfo
->font_table
[i
].full_name
);
5332 xfree (dpyinfo
->font_table
[i
].name
);
5333 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
5336 x_destroy_all_bitmaps (dpyinfo
);
5337 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
5339 #ifdef USE_X_TOOLKIT
5340 XtCloseDisplay (dpyinfo
->display
);
5342 XCloseDisplay (dpyinfo
->display
);
5345 x_delete_display (dpyinfo
);
5351 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
5352 doc
: /* Return the list of display names that Emacs has connections to. */)
5355 Lisp_Object tail
, result
;
5358 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
5359 result
= Fcons (XCAR (XCAR (tail
)), result
);
5364 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
5365 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
5366 If ON is nil, allow buffering of requests.
5367 Turning on synchronization prohibits the Xlib routines from buffering
5368 requests and seriously degrades performance, but makes debugging much
5370 The optional second argument DISPLAY specifies which display to act on.
5371 DISPLAY should be either a frame or a display name (a string).
5372 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
5374 Lisp_Object display
, on
;
5376 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
5378 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
5383 /* Wait for responses to all X commands issued so far for frame F. */
5390 XSync (FRAME_X_DISPLAY (f
), False
);
5395 /***********************************************************************
5397 ***********************************************************************/
5399 /* Value is the number of elements of vector VECTOR. */
5401 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
5403 /* List of supported image types. Use define_image_type to add new
5404 types. Use lookup_image_type to find a type for a given symbol. */
5406 static struct image_type
*image_types
;
5408 /* The symbol `image' which is the car of the lists used to represent
5411 extern Lisp_Object Qimage
;
5413 /* The symbol `xbm' which is used as the type symbol for XBM images. */
5419 extern Lisp_Object QCwidth
, QCheight
, QCforeground
, QCbackground
, QCfile
;
5420 extern Lisp_Object QCdata
, QCtype
;
5421 Lisp_Object QCascent
, QCmargin
, QCrelief
;
5422 Lisp_Object QCconversion
, QCcolor_symbols
, QCheuristic_mask
;
5423 Lisp_Object QCindex
, QCmatrix
, QCcolor_adjustment
, QCmask
;
5425 /* Other symbols. */
5427 Lisp_Object Qlaplace
, Qemboss
, Qedge_detection
, Qheuristic
;
5429 /* Time in seconds after which images should be removed from the cache
5430 if not displayed. */
5432 Lisp_Object Vimage_cache_eviction_delay
;
5434 /* Function prototypes. */
5436 static void define_image_type
P_ ((struct image_type
*type
));
5437 static struct image_type
*lookup_image_type
P_ ((Lisp_Object symbol
));
5438 static void image_error
P_ ((char *format
, Lisp_Object
, Lisp_Object
));
5439 static void x_laplace
P_ ((struct frame
*, struct image
*));
5440 static void x_emboss
P_ ((struct frame
*, struct image
*));
5441 static int x_build_heuristic_mask
P_ ((struct frame
*, struct image
*,
5445 /* Define a new image type from TYPE. This adds a copy of TYPE to
5446 image_types and adds the symbol *TYPE->type to Vimage_types. */
5449 define_image_type (type
)
5450 struct image_type
*type
;
5452 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
5453 The initialized data segment is read-only. */
5454 struct image_type
*p
= (struct image_type
*) xmalloc (sizeof *p
);
5455 bcopy (type
, p
, sizeof *p
);
5456 p
->next
= image_types
;
5458 Vimage_types
= Fcons (*p
->type
, Vimage_types
);
5462 /* Look up image type SYMBOL, and return a pointer to its image_type
5463 structure. Value is null if SYMBOL is not a known image type. */
5465 static INLINE
struct image_type
*
5466 lookup_image_type (symbol
)
5469 struct image_type
*type
;
5471 for (type
= image_types
; type
; type
= type
->next
)
5472 if (EQ (symbol
, *type
->type
))
5479 /* Value is non-zero if OBJECT is a valid Lisp image specification. A
5480 valid image specification is a list whose car is the symbol
5481 `image', and whose rest is a property list. The property list must
5482 contain a value for key `:type'. That value must be the name of a
5483 supported image type. The rest of the property list depends on the
5487 valid_image_p (object
)
5492 if (CONSP (object
) && EQ (XCAR (object
), Qimage
))
5496 for (tem
= XCDR (object
); CONSP (tem
); tem
= XCDR (tem
))
5497 if (EQ (XCAR (tem
), QCtype
))
5500 if (CONSP (tem
) && SYMBOLP (XCAR (tem
)))
5502 struct image_type
*type
;
5503 type
= lookup_image_type (XCAR (tem
));
5505 valid_p
= type
->valid_p (object
);
5516 /* Log error message with format string FORMAT and argument ARG.
5517 Signaling an error, e.g. when an image cannot be loaded, is not a
5518 good idea because this would interrupt redisplay, and the error
5519 message display would lead to another redisplay. This function
5520 therefore simply displays a message. */
5523 image_error (format
, arg1
, arg2
)
5525 Lisp_Object arg1
, arg2
;
5527 add_to_log (format
, arg1
, arg2
);
5532 /***********************************************************************
5533 Image specifications
5534 ***********************************************************************/
5536 enum image_value_type
5538 IMAGE_DONT_CHECK_VALUE_TYPE
,
5540 IMAGE_STRING_OR_NIL_VALUE
,
5542 IMAGE_POSITIVE_INTEGER_VALUE
,
5543 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
,
5544 IMAGE_NON_NEGATIVE_INTEGER_VALUE
,
5546 IMAGE_INTEGER_VALUE
,
5547 IMAGE_FUNCTION_VALUE
,
5552 /* Structure used when parsing image specifications. */
5554 struct image_keyword
5556 /* Name of keyword. */
5559 /* The type of value allowed. */
5560 enum image_value_type type
;
5562 /* Non-zero means key must be present. */
5565 /* Used to recognize duplicate keywords in a property list. */
5568 /* The value that was found. */
5573 static int parse_image_spec
P_ ((Lisp_Object
, struct image_keyword
*,
5575 static Lisp_Object image_spec_value
P_ ((Lisp_Object
, Lisp_Object
, int *));
5578 /* Parse image spec SPEC according to KEYWORDS. A valid image spec
5579 has the format (image KEYWORD VALUE ...). One of the keyword/
5580 value pairs must be `:type TYPE'. KEYWORDS is a vector of
5581 image_keywords structures of size NKEYWORDS describing other
5582 allowed keyword/value pairs. Value is non-zero if SPEC is valid. */
5585 parse_image_spec (spec
, keywords
, nkeywords
, type
)
5587 struct image_keyword
*keywords
;
5594 if (!CONSP (spec
) || !EQ (XCAR (spec
), Qimage
))
5597 plist
= XCDR (spec
);
5598 while (CONSP (plist
))
5600 Lisp_Object key
, value
;
5602 /* First element of a pair must be a symbol. */
5604 plist
= XCDR (plist
);
5608 /* There must follow a value. */
5611 value
= XCAR (plist
);
5612 plist
= XCDR (plist
);
5614 /* Find key in KEYWORDS. Error if not found. */
5615 for (i
= 0; i
< nkeywords
; ++i
)
5616 if (strcmp (keywords
[i
].name
, SDATA (SYMBOL_NAME (key
))) == 0)
5622 /* Record that we recognized the keyword. If a keywords
5623 was found more than once, it's an error. */
5624 keywords
[i
].value
= value
;
5625 ++keywords
[i
].count
;
5627 if (keywords
[i
].count
> 1)
5630 /* Check type of value against allowed type. */
5631 switch (keywords
[i
].type
)
5633 case IMAGE_STRING_VALUE
:
5634 if (!STRINGP (value
))
5638 case IMAGE_STRING_OR_NIL_VALUE
:
5639 if (!STRINGP (value
) && !NILP (value
))
5643 case IMAGE_SYMBOL_VALUE
:
5644 if (!SYMBOLP (value
))
5648 case IMAGE_POSITIVE_INTEGER_VALUE
:
5649 if (!INTEGERP (value
) || XINT (value
) <= 0)
5653 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
:
5654 if (INTEGERP (value
) && XINT (value
) >= 0)
5657 && INTEGERP (XCAR (value
)) && INTEGERP (XCDR (value
))
5658 && XINT (XCAR (value
)) >= 0 && XINT (XCDR (value
)) >= 0)
5662 case IMAGE_ASCENT_VALUE
:
5663 if (SYMBOLP (value
) && EQ (value
, Qcenter
))
5665 else if (INTEGERP (value
)
5666 && XINT (value
) >= 0
5667 && XINT (value
) <= 100)
5671 case IMAGE_NON_NEGATIVE_INTEGER_VALUE
:
5672 if (!INTEGERP (value
) || XINT (value
) < 0)
5676 case IMAGE_DONT_CHECK_VALUE_TYPE
:
5679 case IMAGE_FUNCTION_VALUE
:
5680 value
= indirect_function (value
);
5682 || COMPILEDP (value
)
5683 || (CONSP (value
) && EQ (XCAR (value
), Qlambda
)))
5687 case IMAGE_NUMBER_VALUE
:
5688 if (!INTEGERP (value
) && !FLOATP (value
))
5692 case IMAGE_INTEGER_VALUE
:
5693 if (!INTEGERP (value
))
5697 case IMAGE_BOOL_VALUE
:
5698 if (!NILP (value
) && !EQ (value
, Qt
))
5707 if (EQ (key
, QCtype
) && !EQ (type
, value
))
5711 /* Check that all mandatory fields are present. */
5712 for (i
= 0; i
< nkeywords
; ++i
)
5713 if (keywords
[i
].mandatory_p
&& keywords
[i
].count
== 0)
5716 return NILP (plist
);
5720 /* Return the value of KEY in image specification SPEC. Value is nil
5721 if KEY is not present in SPEC. if FOUND is not null, set *FOUND
5722 to 1 if KEY was found in SPEC, set it to 0 otherwise. */
5725 image_spec_value (spec
, key
, found
)
5726 Lisp_Object spec
, key
;
5731 xassert (valid_image_p (spec
));
5733 for (tail
= XCDR (spec
);
5734 CONSP (tail
) && CONSP (XCDR (tail
));
5735 tail
= XCDR (XCDR (tail
)))
5737 if (EQ (XCAR (tail
), key
))
5741 return XCAR (XCDR (tail
));
5751 DEFUN ("image-size", Fimage_size
, Simage_size
, 1, 3, 0,
5752 doc
: /* Return the size of image SPEC as pair (WIDTH . HEIGHT).
5753 PIXELS non-nil means return the size in pixels, otherwise return the
5754 size in canonical character units.
5755 FRAME is the frame on which the image will be displayed. FRAME nil
5756 or omitted means use the selected frame. */)
5757 (spec
, pixels
, frame
)
5758 Lisp_Object spec
, pixels
, frame
;
5763 if (valid_image_p (spec
))
5765 struct frame
*f
= check_x_frame (frame
);
5766 int id
= lookup_image (f
, spec
);
5767 struct image
*img
= IMAGE_FROM_ID (f
, id
);
5768 int width
= img
->width
+ 2 * img
->hmargin
;
5769 int height
= img
->height
+ 2 * img
->vmargin
;
5772 size
= Fcons (make_float ((double) width
/ CANON_X_UNIT (f
)),
5773 make_float ((double) height
/ CANON_Y_UNIT (f
)));
5775 size
= Fcons (make_number (width
), make_number (height
));
5778 error ("Invalid image specification");
5784 DEFUN ("image-mask-p", Fimage_mask_p
, Simage_mask_p
, 1, 2, 0,
5785 doc
: /* Return t if image SPEC has a mask bitmap.
5786 FRAME is the frame on which the image will be displayed. FRAME nil
5787 or omitted means use the selected frame. */)
5789 Lisp_Object spec
, frame
;
5794 if (valid_image_p (spec
))
5796 struct frame
*f
= check_x_frame (frame
);
5797 int id
= lookup_image (f
, spec
);
5798 struct image
*img
= IMAGE_FROM_ID (f
, id
);
5803 error ("Invalid image specification");
5810 /***********************************************************************
5811 Image type independent image structures
5812 ***********************************************************************/
5814 static struct image
*make_image
P_ ((Lisp_Object spec
, unsigned hash
));
5815 static void free_image
P_ ((struct frame
*f
, struct image
*img
));
5818 /* Allocate and return a new image structure for image specification
5819 SPEC. SPEC has a hash value of HASH. */
5821 static struct image
*
5822 make_image (spec
, hash
)
5826 struct image
*img
= (struct image
*) xmalloc (sizeof *img
);
5828 xassert (valid_image_p (spec
));
5829 bzero (img
, sizeof *img
);
5830 img
->type
= lookup_image_type (image_spec_value (spec
, QCtype
, NULL
));
5831 xassert (img
->type
!= NULL
);
5833 img
->data
.lisp_val
= Qnil
;
5834 img
->ascent
= DEFAULT_IMAGE_ASCENT
;
5840 /* Free image IMG which was used on frame F, including its resources. */
5849 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
5851 /* Remove IMG from the hash table of its cache. */
5853 img
->prev
->next
= img
->next
;
5855 c
->buckets
[img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
] = img
->next
;
5858 img
->next
->prev
= img
->prev
;
5860 c
->images
[img
->id
] = NULL
;
5862 /* Free resources, then free IMG. */
5863 img
->type
->free (f
, img
);
5869 /* Prepare image IMG for display on frame F. Must be called before
5870 drawing an image. */
5873 prepare_image_for_display (f
, img
)
5879 /* We're about to display IMG, so set its timestamp to `now'. */
5881 img
->timestamp
= EMACS_SECS (t
);
5883 /* If IMG doesn't have a pixmap yet, load it now, using the image
5884 type dependent loader function. */
5885 if (img
->pixmap
== None
&& !img
->load_failed_p
)
5886 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
5890 /* Value is the number of pixels for the ascent of image IMG when
5891 drawn in face FACE. */
5894 image_ascent (img
, face
)
5898 int height
= img
->height
+ img
->vmargin
;
5901 if (img
->ascent
== CENTERED_IMAGE_ASCENT
)
5904 /* This expression is arranged so that if the image can't be
5905 exactly centered, it will be moved slightly up. This is
5906 because a typical font is `top-heavy' (due to the presence
5907 uppercase letters), so the image placement should err towards
5908 being top-heavy too. It also just generally looks better. */
5909 ascent
= (height
+ face
->font
->ascent
- face
->font
->descent
+ 1) / 2;
5911 ascent
= height
/ 2;
5914 ascent
= height
* img
->ascent
/ 100.0;
5920 /* Image background colors. */
5922 static unsigned long
5923 four_corners_best (ximg
, width
, height
)
5925 unsigned long width
, height
;
5927 unsigned long corners
[4], best
;
5930 /* Get the colors at the corners of ximg. */
5931 corners
[0] = XGetPixel (ximg
, 0, 0);
5932 corners
[1] = XGetPixel (ximg
, width
- 1, 0);
5933 corners
[2] = XGetPixel (ximg
, width
- 1, height
- 1);
5934 corners
[3] = XGetPixel (ximg
, 0, height
- 1);
5936 /* Choose the most frequently found color as background. */
5937 for (i
= best_count
= 0; i
< 4; ++i
)
5941 for (j
= n
= 0; j
< 4; ++j
)
5942 if (corners
[i
] == corners
[j
])
5946 best
= corners
[i
], best_count
= n
;
5952 /* Return the `background' field of IMG. If IMG doesn't have one yet,
5953 it is guessed heuristically. If non-zero, XIMG is an existing XImage
5954 object to use for the heuristic. */
5957 image_background (img
, f
, ximg
)
5962 if (! img
->background_valid
)
5963 /* IMG doesn't have a background yet, try to guess a reasonable value. */
5965 int free_ximg
= !ximg
;
5968 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
5969 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
5971 img
->background
= four_corners_best (ximg
, img
->width
, img
->height
);
5974 XDestroyImage (ximg
);
5976 img
->background_valid
= 1;
5979 return img
->background
;
5982 /* Return the `background_transparent' field of IMG. If IMG doesn't
5983 have one yet, it is guessed heuristically. If non-zero, MASK is an
5984 existing XImage object to use for the heuristic. */
5987 image_background_transparent (img
, f
, mask
)
5992 if (! img
->background_transparent_valid
)
5993 /* IMG doesn't have a background yet, try to guess a reasonable value. */
5997 int free_mask
= !mask
;
6000 mask
= XGetImage (FRAME_X_DISPLAY (f
), img
->mask
,
6001 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
6003 img
->background_transparent
6004 = !four_corners_best (mask
, img
->width
, img
->height
);
6007 XDestroyImage (mask
);
6010 img
->background_transparent
= 0;
6012 img
->background_transparent_valid
= 1;
6015 return img
->background_transparent
;
6019 /***********************************************************************
6020 Helper functions for X image types
6021 ***********************************************************************/
6023 static void x_clear_image_1
P_ ((struct frame
*, struct image
*, int,
6025 static void x_clear_image
P_ ((struct frame
*f
, struct image
*img
));
6026 static unsigned long x_alloc_image_color
P_ ((struct frame
*f
,
6028 Lisp_Object color_name
,
6029 unsigned long dflt
));
6032 /* Clear X resources of image IMG on frame F. PIXMAP_P non-zero means
6033 free the pixmap if any. MASK_P non-zero means clear the mask
6034 pixmap if any. COLORS_P non-zero means free colors allocated for
6035 the image, if any. */
6038 x_clear_image_1 (f
, img
, pixmap_p
, mask_p
, colors_p
)
6041 int pixmap_p
, mask_p
, colors_p
;
6043 if (pixmap_p
&& img
->pixmap
)
6045 XFreePixmap (FRAME_X_DISPLAY (f
), img
->pixmap
);
6047 img
->background_valid
= 0;
6050 if (mask_p
&& img
->mask
)
6052 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
6054 img
->background_transparent_valid
= 0;
6057 if (colors_p
&& img
->ncolors
)
6059 x_free_colors (f
, img
->colors
, img
->ncolors
);
6060 xfree (img
->colors
);
6066 /* Free X resources of image IMG which is used on frame F. */
6069 x_clear_image (f
, img
)
6074 x_clear_image_1 (f
, img
, 1, 1, 1);
6079 /* Allocate color COLOR_NAME for image IMG on frame F. If color
6080 cannot be allocated, use DFLT. Add a newly allocated color to
6081 IMG->colors, so that it can be freed again. Value is the pixel
6084 static unsigned long
6085 x_alloc_image_color (f
, img
, color_name
, dflt
)
6088 Lisp_Object color_name
;
6092 unsigned long result
;
6094 xassert (STRINGP (color_name
));
6096 if (x_defined_color (f
, SDATA (color_name
), &color
, 1))
6098 /* This isn't called frequently so we get away with simply
6099 reallocating the color vector to the needed size, here. */
6102 (unsigned long *) xrealloc (img
->colors
,
6103 img
->ncolors
* sizeof *img
->colors
);
6104 img
->colors
[img
->ncolors
- 1] = color
.pixel
;
6105 result
= color
.pixel
;
6115 /***********************************************************************
6117 ***********************************************************************/
6119 static void cache_image
P_ ((struct frame
*f
, struct image
*img
));
6120 static void postprocess_image
P_ ((struct frame
*, struct image
*));
6123 /* Return a new, initialized image cache that is allocated from the
6124 heap. Call free_image_cache to free an image cache. */
6126 struct image_cache
*
6129 struct image_cache
*c
= (struct image_cache
*) xmalloc (sizeof *c
);
6132 bzero (c
, sizeof *c
);
6134 c
->images
= (struct image
**) xmalloc (c
->size
* sizeof *c
->images
);
6135 size
= IMAGE_CACHE_BUCKETS_SIZE
* sizeof *c
->buckets
;
6136 c
->buckets
= (struct image
**) xmalloc (size
);
6137 bzero (c
->buckets
, size
);
6142 /* Free image cache of frame F. Be aware that X frames share images
6146 free_image_cache (f
)
6149 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
6154 /* Cache should not be referenced by any frame when freed. */
6155 xassert (c
->refcount
== 0);
6157 for (i
= 0; i
< c
->used
; ++i
)
6158 free_image (f
, c
->images
[i
]);
6162 FRAME_X_IMAGE_CACHE (f
) = NULL
;
6167 /* Clear image cache of frame F. FORCE_P non-zero means free all
6168 images. FORCE_P zero means clear only images that haven't been
6169 displayed for some time. Should be called from time to time to
6170 reduce the number of loaded images. If image-eviction-seconds is
6171 non-nil, this frees images in the cache which weren't displayed for
6172 at least that many seconds. */
6175 clear_image_cache (f
, force_p
)
6179 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
6181 if (c
&& INTEGERP (Vimage_cache_eviction_delay
))
6188 old
= EMACS_SECS (t
) - XFASTINT (Vimage_cache_eviction_delay
);
6190 /* Block input so that we won't be interrupted by a SIGIO
6191 while being in an inconsistent state. */
6194 for (i
= nfreed
= 0; i
< c
->used
; ++i
)
6196 struct image
*img
= c
->images
[i
];
6198 && (force_p
|| img
->timestamp
< old
))
6200 free_image (f
, img
);
6205 /* We may be clearing the image cache because, for example,
6206 Emacs was iconified for a longer period of time. In that
6207 case, current matrices may still contain references to
6208 images freed above. So, clear these matrices. */
6211 Lisp_Object tail
, frame
;
6213 FOR_EACH_FRAME (tail
, frame
)
6215 struct frame
*f
= XFRAME (frame
);
6217 && FRAME_X_IMAGE_CACHE (f
) == c
)
6218 clear_current_matrices (f
);
6221 ++windows_or_buffers_changed
;
6229 DEFUN ("clear-image-cache", Fclear_image_cache
, Sclear_image_cache
,
6231 doc
: /* Clear the image cache of FRAME.
6232 FRAME nil or omitted means use the selected frame.
6233 FRAME t means clear the image caches of all frames. */)
6241 FOR_EACH_FRAME (tail
, frame
)
6242 if (FRAME_X_P (XFRAME (frame
)))
6243 clear_image_cache (XFRAME (frame
), 1);
6246 clear_image_cache (check_x_frame (frame
), 1);
6252 /* Compute masks and transform image IMG on frame F, as specified
6253 by the image's specification, */
6256 postprocess_image (f
, img
)
6260 /* Manipulation of the image's mask. */
6263 Lisp_Object conversion
, spec
;
6268 /* `:heuristic-mask t'
6270 means build a mask heuristically.
6271 `:heuristic-mask (R G B)'
6272 `:mask (heuristic (R G B))'
6273 means build a mask from color (R G B) in the
6276 means remove a mask, if any. */
6278 mask
= image_spec_value (spec
, QCheuristic_mask
, NULL
);
6280 x_build_heuristic_mask (f
, img
, mask
);
6285 mask
= image_spec_value (spec
, QCmask
, &found_p
);
6287 if (EQ (mask
, Qheuristic
))
6288 x_build_heuristic_mask (f
, img
, Qt
);
6289 else if (CONSP (mask
)
6290 && EQ (XCAR (mask
), Qheuristic
))
6292 if (CONSP (XCDR (mask
)))
6293 x_build_heuristic_mask (f
, img
, XCAR (XCDR (mask
)));
6295 x_build_heuristic_mask (f
, img
, XCDR (mask
));
6297 else if (NILP (mask
) && found_p
&& img
->mask
)
6299 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
6305 /* Should we apply an image transformation algorithm? */
6306 conversion
= image_spec_value (spec
, QCconversion
, NULL
);
6307 if (EQ (conversion
, Qdisabled
))
6308 x_disable_image (f
, img
);
6309 else if (EQ (conversion
, Qlaplace
))
6311 else if (EQ (conversion
, Qemboss
))
6313 else if (CONSP (conversion
)
6314 && EQ (XCAR (conversion
), Qedge_detection
))
6317 tem
= XCDR (conversion
);
6319 x_edge_detection (f
, img
,
6320 Fplist_get (tem
, QCmatrix
),
6321 Fplist_get (tem
, QCcolor_adjustment
));
6327 /* Return the id of image with Lisp specification SPEC on frame F.
6328 SPEC must be a valid Lisp image specification (see valid_image_p). */
6331 lookup_image (f
, spec
)
6335 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
6339 struct gcpro gcpro1
;
6342 /* F must be a window-system frame, and SPEC must be a valid image
6344 xassert (FRAME_WINDOW_P (f
));
6345 xassert (valid_image_p (spec
));
6349 /* Look up SPEC in the hash table of the image cache. */
6350 hash
= sxhash (spec
, 0);
6351 i
= hash
% IMAGE_CACHE_BUCKETS_SIZE
;
6353 for (img
= c
->buckets
[i
]; img
; img
= img
->next
)
6354 if (img
->hash
== hash
&& !NILP (Fequal (img
->spec
, spec
)))
6357 /* If not found, create a new image and cache it. */
6360 extern Lisp_Object Qpostscript
;
6363 img
= make_image (spec
, hash
);
6364 cache_image (f
, img
);
6365 img
->load_failed_p
= img
->type
->load (f
, img
) == 0;
6367 /* If we can't load the image, and we don't have a width and
6368 height, use some arbitrary width and height so that we can
6369 draw a rectangle for it. */
6370 if (img
->load_failed_p
)
6374 value
= image_spec_value (spec
, QCwidth
, NULL
);
6375 img
->width
= (INTEGERP (value
)
6376 ? XFASTINT (value
) : DEFAULT_IMAGE_WIDTH
);
6377 value
= image_spec_value (spec
, QCheight
, NULL
);
6378 img
->height
= (INTEGERP (value
)
6379 ? XFASTINT (value
) : DEFAULT_IMAGE_HEIGHT
);
6383 /* Handle image type independent image attributes
6384 `:ascent ASCENT', `:margin MARGIN', `:relief RELIEF',
6385 `:background COLOR'. */
6386 Lisp_Object ascent
, margin
, relief
, bg
;
6388 ascent
= image_spec_value (spec
, QCascent
, NULL
);
6389 if (INTEGERP (ascent
))
6390 img
->ascent
= XFASTINT (ascent
);
6391 else if (EQ (ascent
, Qcenter
))
6392 img
->ascent
= CENTERED_IMAGE_ASCENT
;
6394 margin
= image_spec_value (spec
, QCmargin
, NULL
);
6395 if (INTEGERP (margin
) && XINT (margin
) >= 0)
6396 img
->vmargin
= img
->hmargin
= XFASTINT (margin
);
6397 else if (CONSP (margin
) && INTEGERP (XCAR (margin
))
6398 && INTEGERP (XCDR (margin
)))
6400 if (XINT (XCAR (margin
)) > 0)
6401 img
->hmargin
= XFASTINT (XCAR (margin
));
6402 if (XINT (XCDR (margin
)) > 0)
6403 img
->vmargin
= XFASTINT (XCDR (margin
));
6406 relief
= image_spec_value (spec
, QCrelief
, NULL
);
6407 if (INTEGERP (relief
))
6409 img
->relief
= XINT (relief
);
6410 img
->hmargin
+= abs (img
->relief
);
6411 img
->vmargin
+= abs (img
->relief
);
6414 if (! img
->background_valid
)
6416 bg
= image_spec_value (img
->spec
, QCbackground
, NULL
);
6420 = x_alloc_image_color (f
, img
, bg
,
6421 FRAME_BACKGROUND_PIXEL (f
));
6422 img
->background_valid
= 1;
6426 /* Do image transformations and compute masks, unless we
6427 don't have the image yet. */
6428 if (!EQ (*img
->type
->type
, Qpostscript
))
6429 postprocess_image (f
, img
);
6433 xassert (!interrupt_input_blocked
);
6436 /* We're using IMG, so set its timestamp to `now'. */
6437 EMACS_GET_TIME (now
);
6438 img
->timestamp
= EMACS_SECS (now
);
6442 /* Value is the image id. */
6447 /* Cache image IMG in the image cache of frame F. */
6450 cache_image (f
, img
)
6454 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
6457 /* Find a free slot in c->images. */
6458 for (i
= 0; i
< c
->used
; ++i
)
6459 if (c
->images
[i
] == NULL
)
6462 /* If no free slot found, maybe enlarge c->images. */
6463 if (i
== c
->used
&& c
->used
== c
->size
)
6466 c
->images
= (struct image
**) xrealloc (c
->images
,
6467 c
->size
* sizeof *c
->images
);
6470 /* Add IMG to c->images, and assign IMG an id. */
6476 /* Add IMG to the cache's hash table. */
6477 i
= img
->hash
% IMAGE_CACHE_BUCKETS_SIZE
;
6478 img
->next
= c
->buckets
[i
];
6480 img
->next
->prev
= img
;
6482 c
->buckets
[i
] = img
;
6486 /* Call FN on every image in the image cache of frame F. Used to mark
6487 Lisp Objects in the image cache. */
6490 forall_images_in_image_cache (f
, fn
)
6492 void (*fn
) P_ ((struct image
*img
));
6494 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
))
6496 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
6500 for (i
= 0; i
< c
->used
; ++i
)
6509 /***********************************************************************
6511 ***********************************************************************/
6513 static int x_create_x_image_and_pixmap
P_ ((struct frame
*, int, int, int,
6514 XImage
**, Pixmap
*));
6515 static void x_destroy_x_image
P_ ((XImage
*));
6516 static void x_put_x_image
P_ ((struct frame
*, XImage
*, Pixmap
, int, int));
6519 /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on
6520 frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created.
6521 Set (*XIMG)->data to a raster of WIDTH x HEIGHT pixels allocated
6522 via xmalloc. Print error messages via image_error if an error
6523 occurs. Value is non-zero if successful. */
6526 x_create_x_image_and_pixmap (f
, width
, height
, depth
, ximg
, pixmap
)
6528 int width
, height
, depth
;
6532 Display
*display
= FRAME_X_DISPLAY (f
);
6533 Screen
*screen
= FRAME_X_SCREEN (f
);
6534 Window window
= FRAME_X_WINDOW (f
);
6536 xassert (interrupt_input_blocked
);
6539 depth
= DefaultDepthOfScreen (screen
);
6540 *ximg
= XCreateImage (display
, DefaultVisualOfScreen (screen
),
6541 depth
, ZPixmap
, 0, NULL
, width
, height
,
6542 depth
> 16 ? 32 : depth
> 8 ? 16 : 8, 0);
6545 image_error ("Unable to allocate X image", Qnil
, Qnil
);
6549 /* Allocate image raster. */
6550 (*ximg
)->data
= (char *) xmalloc ((*ximg
)->bytes_per_line
* height
);
6552 /* Allocate a pixmap of the same size. */
6553 *pixmap
= XCreatePixmap (display
, window
, width
, height
, depth
);
6554 if (*pixmap
== None
)
6556 x_destroy_x_image (*ximg
);
6558 image_error ("Unable to create X pixmap", Qnil
, Qnil
);
6566 /* Destroy XImage XIMG. Free XIMG->data. */
6569 x_destroy_x_image (ximg
)
6572 xassert (interrupt_input_blocked
);
6577 XDestroyImage (ximg
);
6582 /* Put XImage XIMG into pixmap PIXMAP on frame F. WIDTH and HEIGHT
6583 are width and height of both the image and pixmap. */
6586 x_put_x_image (f
, ximg
, pixmap
, width
, height
)
6594 xassert (interrupt_input_blocked
);
6595 gc
= XCreateGC (FRAME_X_DISPLAY (f
), pixmap
, 0, NULL
);
6596 XPutImage (FRAME_X_DISPLAY (f
), pixmap
, gc
, ximg
, 0, 0, 0, 0, width
, height
);
6597 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
6602 /***********************************************************************
6604 ***********************************************************************/
6606 static Lisp_Object x_find_image_file
P_ ((Lisp_Object
));
6607 static char *slurp_file
P_ ((char *, int *));
6610 /* Find image file FILE. Look in data-directory, then
6611 x-bitmap-file-path. Value is the full name of the file found, or
6612 nil if not found. */
6615 x_find_image_file (file
)
6618 Lisp_Object file_found
, search_path
;
6619 struct gcpro gcpro1
, gcpro2
;
6623 search_path
= Fcons (Vdata_directory
, Vx_bitmap_file_path
);
6624 GCPRO2 (file_found
, search_path
);
6626 /* Try to find FILE in data-directory, then x-bitmap-file-path. */
6627 fd
= openp (search_path
, file
, Qnil
, &file_found
, Qnil
);
6639 /* Read FILE into memory. Value is a pointer to a buffer allocated
6640 with xmalloc holding FILE's contents. Value is null if an error
6641 occurred. *SIZE is set to the size of the file. */
6644 slurp_file (file
, size
)
6652 if (stat (file
, &st
) == 0
6653 && (fp
= fopen (file
, "r")) != NULL
6654 && (buf
= (char *) xmalloc (st
.st_size
),
6655 fread (buf
, 1, st
.st_size
, fp
) == st
.st_size
))
6676 /***********************************************************************
6678 ***********************************************************************/
6680 static int xbm_scan
P_ ((char **, char *, char *, int *));
6681 static int xbm_load
P_ ((struct frame
*f
, struct image
*img
));
6682 static int xbm_load_image
P_ ((struct frame
*f
, struct image
*img
,
6684 static int xbm_image_p
P_ ((Lisp_Object object
));
6685 static int xbm_read_bitmap_data
P_ ((char *, char *, int *, int *,
6687 static int xbm_file_p
P_ ((Lisp_Object
));
6690 /* Indices of image specification fields in xbm_format, below. */
6692 enum xbm_keyword_index
6710 /* Vector of image_keyword structures describing the format
6711 of valid XBM image specifications. */
6713 static struct image_keyword xbm_format
[XBM_LAST
] =
6715 {":type", IMAGE_SYMBOL_VALUE
, 1},
6716 {":file", IMAGE_STRING_VALUE
, 0},
6717 {":width", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
6718 {":height", IMAGE_POSITIVE_INTEGER_VALUE
, 0},
6719 {":data", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6720 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
6721 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0},
6722 {":ascent", IMAGE_ASCENT_VALUE
, 0},
6723 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
6724 {":relief", IMAGE_INTEGER_VALUE
, 0},
6725 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6726 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
6727 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0}
6730 /* Structure describing the image type XBM. */
6732 static struct image_type xbm_type
=
6741 /* Tokens returned from xbm_scan. */
6750 /* Return non-zero if OBJECT is a valid XBM-type image specification.
6751 A valid specification is a list starting with the symbol `image'
6752 The rest of the list is a property list which must contain an
6755 If the specification specifies a file to load, it must contain
6756 an entry `:file FILENAME' where FILENAME is a string.
6758 If the specification is for a bitmap loaded from memory it must
6759 contain `:width WIDTH', `:height HEIGHT', and `:data DATA', where
6760 WIDTH and HEIGHT are integers > 0. DATA may be:
6762 1. a string large enough to hold the bitmap data, i.e. it must
6763 have a size >= (WIDTH + 7) / 8 * HEIGHT
6765 2. a bool-vector of size >= WIDTH * HEIGHT
6767 3. a vector of strings or bool-vectors, one for each line of the
6770 4. A string containing an in-memory XBM file. WIDTH and HEIGHT
6771 may not be specified in this case because they are defined in the
6774 Both the file and data forms may contain the additional entries
6775 `:background COLOR' and `:foreground COLOR'. If not present,
6776 foreground and background of the frame on which the image is
6777 displayed is used. */
6780 xbm_image_p (object
)
6783 struct image_keyword kw
[XBM_LAST
];
6785 bcopy (xbm_format
, kw
, sizeof kw
);
6786 if (!parse_image_spec (object
, kw
, XBM_LAST
, Qxbm
))
6789 xassert (EQ (kw
[XBM_TYPE
].value
, Qxbm
));
6791 if (kw
[XBM_FILE
].count
)
6793 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_DATA
].count
)
6796 else if (kw
[XBM_DATA
].count
&& xbm_file_p (kw
[XBM_DATA
].value
))
6798 /* In-memory XBM file. */
6799 if (kw
[XBM_WIDTH
].count
|| kw
[XBM_HEIGHT
].count
|| kw
[XBM_FILE
].count
)
6807 /* Entries for `:width', `:height' and `:data' must be present. */
6808 if (!kw
[XBM_WIDTH
].count
6809 || !kw
[XBM_HEIGHT
].count
6810 || !kw
[XBM_DATA
].count
)
6813 data
= kw
[XBM_DATA
].value
;
6814 width
= XFASTINT (kw
[XBM_WIDTH
].value
);
6815 height
= XFASTINT (kw
[XBM_HEIGHT
].value
);
6817 /* Check type of data, and width and height against contents of
6823 /* Number of elements of the vector must be >= height. */
6824 if (XVECTOR (data
)->size
< height
)
6827 /* Each string or bool-vector in data must be large enough
6828 for one line of the image. */
6829 for (i
= 0; i
< height
; ++i
)
6831 Lisp_Object elt
= XVECTOR (data
)->contents
[i
];
6836 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
)
6839 else if (BOOL_VECTOR_P (elt
))
6841 if (XBOOL_VECTOR (elt
)->size
< width
)
6848 else if (STRINGP (data
))
6851 < (width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
* height
)
6854 else if (BOOL_VECTOR_P (data
))
6856 if (XBOOL_VECTOR (data
)->size
< width
* height
)
6867 /* Scan a bitmap file. FP is the stream to read from. Value is
6868 either an enumerator from enum xbm_token, or a character for a
6869 single-character token, or 0 at end of file. If scanning an
6870 identifier, store the lexeme of the identifier in SVAL. If
6871 scanning a number, store its value in *IVAL. */
6874 xbm_scan (s
, end
, sval
, ival
)
6883 /* Skip white space. */
6884 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
6889 else if (isdigit (c
))
6891 int value
= 0, digit
;
6893 if (c
== '0' && *s
< end
)
6896 if (c
== 'x' || c
== 'X')
6903 else if (c
>= 'a' && c
<= 'f')
6904 digit
= c
- 'a' + 10;
6905 else if (c
>= 'A' && c
<= 'F')
6906 digit
= c
- 'A' + 10;
6909 value
= 16 * value
+ digit
;
6912 else if (isdigit (c
))
6916 && (c
= *(*s
)++, isdigit (c
)))
6917 value
= 8 * value
+ c
- '0';
6924 && (c
= *(*s
)++, isdigit (c
)))
6925 value
= 10 * value
+ c
- '0';
6933 else if (isalpha (c
) || c
== '_')
6937 && (c
= *(*s
)++, (isalnum (c
) || c
== '_')))
6944 else if (c
== '/' && **s
== '*')
6946 /* C-style comment. */
6948 while (**s
&& (**s
!= '*' || *(*s
+ 1) != '/'))
6961 /* Replacement for XReadBitmapFileData which isn't available under old
6962 X versions. CONTENTS is a pointer to a buffer to parse; END is the
6963 buffer's end. Set *WIDTH and *HEIGHT to the width and height of
6964 the image. Return in *DATA the bitmap data allocated with xmalloc.
6965 Value is non-zero if successful. DATA null means just test if
6966 CONTENTS looks like an in-memory XBM file. */
6969 xbm_read_bitmap_data (contents
, end
, width
, height
, data
)
6970 char *contents
, *end
;
6971 int *width
, *height
;
6972 unsigned char **data
;
6975 char buffer
[BUFSIZ
];
6978 int bytes_per_line
, i
, nbytes
;
6984 LA1 = xbm_scan (&s, end, buffer, &value)
6986 #define expect(TOKEN) \
6987 if (LA1 != (TOKEN)) \
6992 #define expect_ident(IDENT) \
6993 if (LA1 == XBM_TK_IDENT && strcmp (buffer, (IDENT)) == 0) \
6998 *width
= *height
= -1;
7001 LA1
= xbm_scan (&s
, end
, buffer
, &value
);
7003 /* Parse defines for width, height and hot-spots. */
7007 expect_ident ("define");
7008 expect (XBM_TK_IDENT
);
7010 if (LA1
== XBM_TK_NUMBER
);
7012 char *p
= strrchr (buffer
, '_');
7013 p
= p
? p
+ 1 : buffer
;
7014 if (strcmp (p
, "width") == 0)
7016 else if (strcmp (p
, "height") == 0)
7019 expect (XBM_TK_NUMBER
);
7022 if (*width
< 0 || *height
< 0)
7024 else if (data
== NULL
)
7027 /* Parse bits. Must start with `static'. */
7028 expect_ident ("static");
7029 if (LA1
== XBM_TK_IDENT
)
7031 if (strcmp (buffer
, "unsigned") == 0)
7034 expect_ident ("char");
7036 else if (strcmp (buffer
, "short") == 0)
7040 if (*width
% 16 && *width
% 16 < 9)
7043 else if (strcmp (buffer
, "char") == 0)
7051 expect (XBM_TK_IDENT
);
7057 bytes_per_line
= (*width
+ 7) / 8 + padding_p
;
7058 nbytes
= bytes_per_line
* *height
;
7059 p
= *data
= (char *) xmalloc (nbytes
);
7063 for (i
= 0; i
< nbytes
; i
+= 2)
7066 expect (XBM_TK_NUMBER
);
7069 if (!padding_p
|| ((i
+ 2) % bytes_per_line
))
7072 if (LA1
== ',' || LA1
== '}')
7080 for (i
= 0; i
< nbytes
; ++i
)
7083 expect (XBM_TK_NUMBER
);
7087 if (LA1
== ',' || LA1
== '}')
7112 /* Load XBM image IMG which will be displayed on frame F from buffer
7113 CONTENTS. END is the end of the buffer. Value is non-zero if
7117 xbm_load_image (f
, img
, contents
, end
)
7120 char *contents
, *end
;
7123 unsigned char *data
;
7126 rc
= xbm_read_bitmap_data (contents
, end
, &img
->width
, &img
->height
, &data
);
7129 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
7130 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
7131 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
7134 xassert (img
->width
> 0 && img
->height
> 0);
7136 /* Get foreground and background colors, maybe allocate colors. */
7137 value
= image_spec_value (img
->spec
, QCforeground
, NULL
);
7139 foreground
= x_alloc_image_color (f
, img
, value
, foreground
);
7140 value
= image_spec_value (img
->spec
, QCbackground
, NULL
);
7143 background
= x_alloc_image_color (f
, img
, value
, background
);
7144 img
->background
= background
;
7145 img
->background_valid
= 1;
7149 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f
),
7152 img
->width
, img
->height
,
7153 foreground
, background
,
7157 if (img
->pixmap
== None
)
7159 x_clear_image (f
, img
);
7160 image_error ("Unable to create X pixmap for `%s'", img
->spec
, Qnil
);
7166 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
7172 /* Value is non-zero if DATA looks like an in-memory XBM file. */
7179 return (STRINGP (data
)
7180 && xbm_read_bitmap_data (SDATA (data
),
7187 /* Fill image IMG which is used on frame F with pixmap data. Value is
7188 non-zero if successful. */
7196 Lisp_Object file_name
;
7198 xassert (xbm_image_p (img
->spec
));
7200 /* If IMG->spec specifies a file name, create a non-file spec from it. */
7201 file_name
= image_spec_value (img
->spec
, QCfile
, NULL
);
7202 if (STRINGP (file_name
))
7207 struct gcpro gcpro1
;
7209 file
= x_find_image_file (file_name
);
7211 if (!STRINGP (file
))
7213 image_error ("Cannot find image file `%s'", file_name
, Qnil
);
7218 contents
= slurp_file (SDATA (file
), &size
);
7219 if (contents
== NULL
)
7221 image_error ("Error loading XBM image `%s'", img
->spec
, Qnil
);
7226 success_p
= xbm_load_image (f
, img
, contents
, contents
+ size
);
7231 struct image_keyword fmt
[XBM_LAST
];
7234 unsigned long foreground
= FRAME_FOREGROUND_PIXEL (f
);
7235 unsigned long background
= FRAME_BACKGROUND_PIXEL (f
);
7238 int in_memory_file_p
= 0;
7240 /* See if data looks like an in-memory XBM file. */
7241 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
7242 in_memory_file_p
= xbm_file_p (data
);
7244 /* Parse the image specification. */
7245 bcopy (xbm_format
, fmt
, sizeof fmt
);
7246 parsed_p
= parse_image_spec (img
->spec
, fmt
, XBM_LAST
, Qxbm
);
7249 /* Get specified width, and height. */
7250 if (!in_memory_file_p
)
7252 img
->width
= XFASTINT (fmt
[XBM_WIDTH
].value
);
7253 img
->height
= XFASTINT (fmt
[XBM_HEIGHT
].value
);
7254 xassert (img
->width
> 0 && img
->height
> 0);
7257 /* Get foreground and background colors, maybe allocate colors. */
7258 if (fmt
[XBM_FOREGROUND
].count
7259 && STRINGP (fmt
[XBM_FOREGROUND
].value
))
7260 foreground
= x_alloc_image_color (f
, img
, fmt
[XBM_FOREGROUND
].value
,
7262 if (fmt
[XBM_BACKGROUND
].count
7263 && STRINGP (fmt
[XBM_BACKGROUND
].value
))
7264 background
= x_alloc_image_color (f
, img
, fmt
[XBM_BACKGROUND
].value
,
7267 if (in_memory_file_p
)
7268 success_p
= xbm_load_image (f
, img
, SDATA (data
),
7277 int nbytes
= (img
->width
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
7279 p
= bits
= (char *) alloca (nbytes
* img
->height
);
7280 for (i
= 0; i
< img
->height
; ++i
, p
+= nbytes
)
7282 Lisp_Object line
= XVECTOR (data
)->contents
[i
];
7284 bcopy (SDATA (line
), p
, nbytes
);
7286 bcopy (XBOOL_VECTOR (line
)->data
, p
, nbytes
);
7289 else if (STRINGP (data
))
7290 bits
= SDATA (data
);
7292 bits
= XBOOL_VECTOR (data
)->data
;
7294 /* Create the pixmap. */
7295 depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
7297 = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f
),
7300 img
->width
, img
->height
,
7301 foreground
, background
,
7307 image_error ("Unable to create pixmap for XBM image `%s'",
7309 x_clear_image (f
, img
);
7319 /***********************************************************************
7321 ***********************************************************************/
7325 static int xpm_image_p
P_ ((Lisp_Object object
));
7326 static int xpm_load
P_ ((struct frame
*f
, struct image
*img
));
7327 static int xpm_valid_color_symbols_p
P_ ((Lisp_Object
));
7329 #include "X11/xpm.h"
7331 /* The symbol `xpm' identifying XPM-format images. */
7335 /* Indices of image specification fields in xpm_format, below. */
7337 enum xpm_keyword_index
7353 /* Vector of image_keyword structures describing the format
7354 of valid XPM image specifications. */
7356 static struct image_keyword xpm_format
[XPM_LAST
] =
7358 {":type", IMAGE_SYMBOL_VALUE
, 1},
7359 {":file", IMAGE_STRING_VALUE
, 0},
7360 {":data", IMAGE_STRING_VALUE
, 0},
7361 {":ascent", IMAGE_ASCENT_VALUE
, 0},
7362 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
7363 {":relief", IMAGE_INTEGER_VALUE
, 0},
7364 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7365 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7366 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7367 {":color-symbols", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
7368 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
7371 /* Structure describing the image type XBM. */
7373 static struct image_type xpm_type
=
7383 /* Define ALLOC_XPM_COLORS if we can use Emacs' own color allocation
7384 functions for allocating image colors. Our own functions handle
7385 color allocation failures more gracefully than the ones on the XPM
7388 #if defined XpmAllocColor && defined XpmFreeColors && defined XpmColorClosure
7389 #define ALLOC_XPM_COLORS
7392 #ifdef ALLOC_XPM_COLORS
7394 static void xpm_init_color_cache
P_ ((struct frame
*, XpmAttributes
*));
7395 static void xpm_free_color_cache
P_ ((void));
7396 static int xpm_lookup_color
P_ ((struct frame
*, char *, XColor
*));
7397 static int xpm_color_bucket
P_ ((char *));
7398 static struct xpm_cached_color
*xpm_cache_color
P_ ((struct frame
*, char *,
7401 /* An entry in a hash table used to cache color definitions of named
7402 colors. This cache is necessary to speed up XPM image loading in
7403 case we do color allocations ourselves. Without it, we would need
7404 a call to XParseColor per pixel in the image. */
7406 struct xpm_cached_color
7408 /* Next in collision chain. */
7409 struct xpm_cached_color
*next
;
7411 /* Color definition (RGB and pixel color). */
7418 /* The hash table used for the color cache, and its bucket vector
7421 #define XPM_COLOR_CACHE_BUCKETS 1001
7422 struct xpm_cached_color
**xpm_color_cache
;
7424 /* Initialize the color cache. */
7427 xpm_init_color_cache (f
, attrs
)
7429 XpmAttributes
*attrs
;
7431 size_t nbytes
= XPM_COLOR_CACHE_BUCKETS
* sizeof *xpm_color_cache
;
7432 xpm_color_cache
= (struct xpm_cached_color
**) xmalloc (nbytes
);
7433 memset (xpm_color_cache
, 0, nbytes
);
7434 init_color_table ();
7436 if (attrs
->valuemask
& XpmColorSymbols
)
7441 for (i
= 0; i
< attrs
->numsymbols
; ++i
)
7442 if (XParseColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
7443 attrs
->colorsymbols
[i
].value
, &color
))
7445 color
.pixel
= lookup_rgb_color (f
, color
.red
, color
.green
,
7447 xpm_cache_color (f
, attrs
->colorsymbols
[i
].name
, &color
, -1);
7453 /* Free the color cache. */
7456 xpm_free_color_cache ()
7458 struct xpm_cached_color
*p
, *next
;
7461 for (i
= 0; i
< XPM_COLOR_CACHE_BUCKETS
; ++i
)
7462 for (p
= xpm_color_cache
[i
]; p
; p
= next
)
7468 xfree (xpm_color_cache
);
7469 xpm_color_cache
= NULL
;
7470 free_color_table ();
7474 /* Return the bucket index for color named COLOR_NAME in the color
7478 xpm_color_bucket (color_name
)
7484 for (s
= color_name
; *s
; ++s
)
7486 return h
%= XPM_COLOR_CACHE_BUCKETS
;
7490 /* On frame F, cache values COLOR for color with name COLOR_NAME.
7491 BUCKET, if >= 0, is a precomputed bucket index. Value is the cache
7494 static struct xpm_cached_color
*
7495 xpm_cache_color (f
, color_name
, color
, bucket
)
7502 struct xpm_cached_color
*p
;
7505 bucket
= xpm_color_bucket (color_name
);
7507 nbytes
= sizeof *p
+ strlen (color_name
);
7508 p
= (struct xpm_cached_color
*) xmalloc (nbytes
);
7509 strcpy (p
->name
, color_name
);
7511 p
->next
= xpm_color_cache
[bucket
];
7512 xpm_color_cache
[bucket
] = p
;
7517 /* Look up color COLOR_NAME for frame F in the color cache. If found,
7518 return the cached definition in *COLOR. Otherwise, make a new
7519 entry in the cache and allocate the color. Value is zero if color
7520 allocation failed. */
7523 xpm_lookup_color (f
, color_name
, color
)
7528 struct xpm_cached_color
*p
;
7529 int h
= xpm_color_bucket (color_name
);
7531 for (p
= xpm_color_cache
[h
]; p
; p
= p
->next
)
7532 if (strcmp (p
->name
, color_name
) == 0)
7537 else if (XParseColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
7540 color
->pixel
= lookup_rgb_color (f
, color
->red
, color
->green
,
7542 p
= xpm_cache_color (f
, color_name
, color
, h
);
7549 /* Callback for allocating color COLOR_NAME. Called from the XPM lib.
7550 CLOSURE is a pointer to the frame on which we allocate the
7551 color. Return in *COLOR the allocated color. Value is non-zero
7555 xpm_alloc_color (dpy
, cmap
, color_name
, color
, closure
)
7562 return xpm_lookup_color ((struct frame
*) closure
, color_name
, color
);
7566 /* Callback for freeing NPIXELS colors contained in PIXELS. CLOSURE
7567 is a pointer to the frame on which we allocate the color. Value is
7568 non-zero if successful. */
7571 xpm_free_colors (dpy
, cmap
, pixels
, npixels
, closure
)
7581 #endif /* ALLOC_XPM_COLORS */
7584 /* Value is non-zero if COLOR_SYMBOLS is a valid color symbols list
7585 for XPM images. Such a list must consist of conses whose car and
7589 xpm_valid_color_symbols_p (color_symbols
)
7590 Lisp_Object color_symbols
;
7592 while (CONSP (color_symbols
))
7594 Lisp_Object sym
= XCAR (color_symbols
);
7596 || !STRINGP (XCAR (sym
))
7597 || !STRINGP (XCDR (sym
)))
7599 color_symbols
= XCDR (color_symbols
);
7602 return NILP (color_symbols
);
7606 /* Value is non-zero if OBJECT is a valid XPM image specification. */
7609 xpm_image_p (object
)
7612 struct image_keyword fmt
[XPM_LAST
];
7613 bcopy (xpm_format
, fmt
, sizeof fmt
);
7614 return (parse_image_spec (object
, fmt
, XPM_LAST
, Qxpm
)
7615 /* Either `:file' or `:data' must be present. */
7616 && fmt
[XPM_FILE
].count
+ fmt
[XPM_DATA
].count
== 1
7617 /* Either no `:color-symbols' or it's a list of conses
7618 whose car and cdr are strings. */
7619 && (fmt
[XPM_COLOR_SYMBOLS
].count
== 0
7620 || xpm_valid_color_symbols_p (fmt
[XPM_COLOR_SYMBOLS
].value
)));
7624 /* Load image IMG which will be displayed on frame F. Value is
7625 non-zero if successful. */
7633 XpmAttributes attrs
;
7634 Lisp_Object specified_file
, color_symbols
;
7636 /* Configure the XPM lib. Use the visual of frame F. Allocate
7637 close colors. Return colors allocated. */
7638 bzero (&attrs
, sizeof attrs
);
7639 attrs
.visual
= FRAME_X_VISUAL (f
);
7640 attrs
.colormap
= FRAME_X_COLORMAP (f
);
7641 attrs
.valuemask
|= XpmVisual
;
7642 attrs
.valuemask
|= XpmColormap
;
7644 #ifdef ALLOC_XPM_COLORS
7645 /* Allocate colors with our own functions which handle
7646 failing color allocation more gracefully. */
7647 attrs
.color_closure
= f
;
7648 attrs
.alloc_color
= xpm_alloc_color
;
7649 attrs
.free_colors
= xpm_free_colors
;
7650 attrs
.valuemask
|= XpmAllocColor
| XpmFreeColors
| XpmColorClosure
;
7651 #else /* not ALLOC_XPM_COLORS */
7652 /* Let the XPM lib allocate colors. */
7653 attrs
.valuemask
|= XpmReturnAllocPixels
;
7654 #ifdef XpmAllocCloseColors
7655 attrs
.alloc_close_colors
= 1;
7656 attrs
.valuemask
|= XpmAllocCloseColors
;
7657 #else /* not XpmAllocCloseColors */
7658 attrs
.closeness
= 600;
7659 attrs
.valuemask
|= XpmCloseness
;
7660 #endif /* not XpmAllocCloseColors */
7661 #endif /* ALLOC_XPM_COLORS */
7663 /* If image specification contains symbolic color definitions, add
7664 these to `attrs'. */
7665 color_symbols
= image_spec_value (img
->spec
, QCcolor_symbols
, NULL
);
7666 if (CONSP (color_symbols
))
7669 XpmColorSymbol
*xpm_syms
;
7672 attrs
.valuemask
|= XpmColorSymbols
;
7674 /* Count number of symbols. */
7675 attrs
.numsymbols
= 0;
7676 for (tail
= color_symbols
; CONSP (tail
); tail
= XCDR (tail
))
7679 /* Allocate an XpmColorSymbol array. */
7680 size
= attrs
.numsymbols
* sizeof *xpm_syms
;
7681 xpm_syms
= (XpmColorSymbol
*) alloca (size
);
7682 bzero (xpm_syms
, size
);
7683 attrs
.colorsymbols
= xpm_syms
;
7685 /* Fill the color symbol array. */
7686 for (tail
= color_symbols
, i
= 0;
7688 ++i
, tail
= XCDR (tail
))
7690 Lisp_Object name
= XCAR (XCAR (tail
));
7691 Lisp_Object color
= XCDR (XCAR (tail
));
7692 xpm_syms
[i
].name
= (char *) alloca (SCHARS (name
) + 1);
7693 strcpy (xpm_syms
[i
].name
, SDATA (name
));
7694 xpm_syms
[i
].value
= (char *) alloca (SCHARS (color
) + 1);
7695 strcpy (xpm_syms
[i
].value
, SDATA (color
));
7699 /* Create a pixmap for the image, either from a file, or from a
7700 string buffer containing data in the same format as an XPM file. */
7701 #ifdef ALLOC_XPM_COLORS
7702 xpm_init_color_cache (f
, &attrs
);
7705 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
7706 if (STRINGP (specified_file
))
7708 Lisp_Object file
= x_find_image_file (specified_file
);
7709 if (!STRINGP (file
))
7711 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
7715 rc
= XpmReadFileToPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7716 SDATA (file
), &img
->pixmap
, &img
->mask
,
7721 Lisp_Object buffer
= image_spec_value (img
->spec
, QCdata
, NULL
);
7722 rc
= XpmCreatePixmapFromBuffer (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7724 &img
->pixmap
, &img
->mask
,
7728 if (rc
== XpmSuccess
)
7730 #ifdef ALLOC_XPM_COLORS
7731 img
->colors
= colors_in_color_table (&img
->ncolors
);
7732 #else /* not ALLOC_XPM_COLORS */
7735 img
->ncolors
= attrs
.nalloc_pixels
;
7736 img
->colors
= (unsigned long *) xmalloc (img
->ncolors
7737 * sizeof *img
->colors
);
7738 for (i
= 0; i
< attrs
.nalloc_pixels
; ++i
)
7740 img
->colors
[i
] = attrs
.alloc_pixels
[i
];
7741 #ifdef DEBUG_X_COLORS
7742 register_color (img
->colors
[i
]);
7745 #endif /* not ALLOC_XPM_COLORS */
7747 img
->width
= attrs
.width
;
7748 img
->height
= attrs
.height
;
7749 xassert (img
->width
> 0 && img
->height
> 0);
7751 /* The call to XpmFreeAttributes below frees attrs.alloc_pixels. */
7752 XpmFreeAttributes (&attrs
);
7759 image_error ("Error opening XPM file (%s)", img
->spec
, Qnil
);
7762 case XpmFileInvalid
:
7763 image_error ("Invalid XPM file (%s)", img
->spec
, Qnil
);
7767 image_error ("Out of memory (%s)", img
->spec
, Qnil
);
7770 case XpmColorFailed
:
7771 image_error ("Color allocation error (%s)", img
->spec
, Qnil
);
7775 image_error ("Unknown error (%s)", img
->spec
, Qnil
);
7780 #ifdef ALLOC_XPM_COLORS
7781 xpm_free_color_cache ();
7783 return rc
== XpmSuccess
;
7786 #endif /* HAVE_XPM != 0 */
7789 /***********************************************************************
7791 ***********************************************************************/
7793 /* An entry in the color table mapping an RGB color to a pixel color. */
7798 unsigned long pixel
;
7800 /* Next in color table collision list. */
7801 struct ct_color
*next
;
7804 /* The bucket vector size to use. Must be prime. */
7808 /* Value is a hash of the RGB color given by R, G, and B. */
7810 #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
7812 /* The color hash table. */
7814 struct ct_color
**ct_table
;
7816 /* Number of entries in the color table. */
7818 int ct_colors_allocated
;
7820 /* Initialize the color table. */
7825 int size
= CT_SIZE
* sizeof (*ct_table
);
7826 ct_table
= (struct ct_color
**) xmalloc (size
);
7827 bzero (ct_table
, size
);
7828 ct_colors_allocated
= 0;
7832 /* Free memory associated with the color table. */
7838 struct ct_color
*p
, *next
;
7840 for (i
= 0; i
< CT_SIZE
; ++i
)
7841 for (p
= ct_table
[i
]; p
; p
= next
)
7852 /* Value is a pixel color for RGB color R, G, B on frame F. If an
7853 entry for that color already is in the color table, return the
7854 pixel color of that entry. Otherwise, allocate a new color for R,
7855 G, B, and make an entry in the color table. */
7857 static unsigned long
7858 lookup_rgb_color (f
, r
, g
, b
)
7862 unsigned hash
= CT_HASH_RGB (r
, g
, b
);
7863 int i
= hash
% CT_SIZE
;
7866 for (p
= ct_table
[i
]; p
; p
= p
->next
)
7867 if (p
->r
== r
&& p
->g
== g
&& p
->b
== b
)
7880 cmap
= FRAME_X_COLORMAP (f
);
7881 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
7885 ++ct_colors_allocated
;
7887 p
= (struct ct_color
*) xmalloc (sizeof *p
);
7891 p
->pixel
= color
.pixel
;
7892 p
->next
= ct_table
[i
];
7896 return FRAME_FOREGROUND_PIXEL (f
);
7903 /* Look up pixel color PIXEL which is used on frame F in the color
7904 table. If not already present, allocate it. Value is PIXEL. */
7906 static unsigned long
7907 lookup_pixel_color (f
, pixel
)
7909 unsigned long pixel
;
7911 int i
= pixel
% CT_SIZE
;
7914 for (p
= ct_table
[i
]; p
; p
= p
->next
)
7915 if (p
->pixel
== pixel
)
7924 cmap
= FRAME_X_COLORMAP (f
);
7925 color
.pixel
= pixel
;
7926 x_query_color (f
, &color
);
7927 rc
= x_alloc_nearest_color (f
, cmap
, &color
);
7931 ++ct_colors_allocated
;
7933 p
= (struct ct_color
*) xmalloc (sizeof *p
);
7938 p
->next
= ct_table
[i
];
7942 return FRAME_FOREGROUND_PIXEL (f
);
7949 /* Value is a vector of all pixel colors contained in the color table,
7950 allocated via xmalloc. Set *N to the number of colors. */
7952 static unsigned long *
7953 colors_in_color_table (n
)
7958 unsigned long *colors
;
7960 if (ct_colors_allocated
== 0)
7967 colors
= (unsigned long *) xmalloc (ct_colors_allocated
7969 *n
= ct_colors_allocated
;
7971 for (i
= j
= 0; i
< CT_SIZE
; ++i
)
7972 for (p
= ct_table
[i
]; p
; p
= p
->next
)
7973 colors
[j
++] = p
->pixel
;
7981 /***********************************************************************
7983 ***********************************************************************/
7985 static XColor
*x_to_xcolors
P_ ((struct frame
*, struct image
*, int));
7986 static void x_from_xcolors
P_ ((struct frame
*, struct image
*, XColor
*));
7987 static void x_detect_edges
P_ ((struct frame
*, struct image
*, int[9], int));
7989 /* Non-zero means draw a cross on images having `:conversion
7992 int cross_disabled_images
;
7994 /* Edge detection matrices for different edge-detection
7997 static int emboss_matrix
[9] = {
7999 2, -1, 0, /* y - 1 */
8001 0, 1, -2 /* y + 1 */
8004 static int laplace_matrix
[9] = {
8006 1, 0, 0, /* y - 1 */
8008 0, 0, -1 /* y + 1 */
8011 /* Value is the intensity of the color whose red/green/blue values
8014 #define COLOR_INTENSITY(R, G, B) ((2 * (R) + 3 * (G) + (B)) / 6)
8017 /* On frame F, return an array of XColor structures describing image
8018 IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
8019 non-zero means also fill the red/green/blue members of the XColor
8020 structures. Value is a pointer to the array of XColors structures,
8021 allocated with xmalloc; it must be freed by the caller. */
8024 x_to_xcolors (f
, img
, rgb_p
)
8033 colors
= (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *colors
);
8035 /* Get the X image IMG->pixmap. */
8036 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
8037 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
8039 /* Fill the `pixel' members of the XColor array. I wished there
8040 were an easy and portable way to circumvent XGetPixel. */
8042 for (y
= 0; y
< img
->height
; ++y
)
8046 for (x
= 0; x
< img
->width
; ++x
, ++p
)
8047 p
->pixel
= XGetPixel (ximg
, x
, y
);
8050 x_query_colors (f
, row
, img
->width
);
8053 XDestroyImage (ximg
);
8058 /* Create IMG->pixmap from an array COLORS of XColor structures, whose
8059 RGB members are set. F is the frame on which this all happens.
8060 COLORS will be freed; an existing IMG->pixmap will be freed, too. */
8063 x_from_xcolors (f
, img
, colors
)
8073 init_color_table ();
8075 x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 0,
8078 for (y
= 0; y
< img
->height
; ++y
)
8079 for (x
= 0; x
< img
->width
; ++x
, ++p
)
8081 unsigned long pixel
;
8082 pixel
= lookup_rgb_color (f
, p
->red
, p
->green
, p
->blue
);
8083 XPutPixel (oimg
, x
, y
, pixel
);
8087 x_clear_image_1 (f
, img
, 1, 0, 1);
8089 x_put_x_image (f
, oimg
, pixmap
, img
->width
, img
->height
);
8090 x_destroy_x_image (oimg
);
8091 img
->pixmap
= pixmap
;
8092 img
->colors
= colors_in_color_table (&img
->ncolors
);
8093 free_color_table ();
8097 /* On frame F, perform edge-detection on image IMG.
8099 MATRIX is a nine-element array specifying the transformation
8100 matrix. See emboss_matrix for an example.
8102 COLOR_ADJUST is a color adjustment added to each pixel of the
8106 x_detect_edges (f
, img
, matrix
, color_adjust
)
8109 int matrix
[9], color_adjust
;
8111 XColor
*colors
= x_to_xcolors (f
, img
, 1);
8115 for (i
= sum
= 0; i
< 9; ++i
)
8116 sum
+= abs (matrix
[i
]);
8118 #define COLOR(A, X, Y) ((A) + (Y) * img->width + (X))
8120 new = (XColor
*) xmalloc (img
->width
* img
->height
* sizeof *new);
8122 for (y
= 0; y
< img
->height
; ++y
)
8124 p
= COLOR (new, 0, y
);
8125 p
->red
= p
->green
= p
->blue
= 0xffff/2;
8126 p
= COLOR (new, img
->width
- 1, y
);
8127 p
->red
= p
->green
= p
->blue
= 0xffff/2;
8130 for (x
= 1; x
< img
->width
- 1; ++x
)
8132 p
= COLOR (new, x
, 0);
8133 p
->red
= p
->green
= p
->blue
= 0xffff/2;
8134 p
= COLOR (new, x
, img
->height
- 1);
8135 p
->red
= p
->green
= p
->blue
= 0xffff/2;
8138 for (y
= 1; y
< img
->height
- 1; ++y
)
8140 p
= COLOR (new, 1, y
);
8142 for (x
= 1; x
< img
->width
- 1; ++x
, ++p
)
8144 int r
, g
, b
, y1
, x1
;
8147 for (y1
= y
- 1; y1
< y
+ 2; ++y1
)
8148 for (x1
= x
- 1; x1
< x
+ 2; ++x1
, ++i
)
8151 XColor
*t
= COLOR (colors
, x1
, y1
);
8152 r
+= matrix
[i
] * t
->red
;
8153 g
+= matrix
[i
] * t
->green
;
8154 b
+= matrix
[i
] * t
->blue
;
8157 r
= (r
/ sum
+ color_adjust
) & 0xffff;
8158 g
= (g
/ sum
+ color_adjust
) & 0xffff;
8159 b
= (b
/ sum
+ color_adjust
) & 0xffff;
8160 p
->red
= p
->green
= p
->blue
= COLOR_INTENSITY (r
, g
, b
);
8165 x_from_xcolors (f
, img
, new);
8171 /* Perform the pre-defined `emboss' edge-detection on image IMG
8179 x_detect_edges (f
, img
, emboss_matrix
, 0xffff / 2);
8183 /* Perform the pre-defined `laplace' edge-detection on image IMG
8191 x_detect_edges (f
, img
, laplace_matrix
, 45000);
8195 /* Perform edge-detection on image IMG on frame F, with specified
8196 transformation matrix MATRIX and color-adjustment COLOR_ADJUST.
8198 MATRIX must be either
8200 - a list of at least 9 numbers in row-major form
8201 - a vector of at least 9 numbers
8203 COLOR_ADJUST nil means use a default; otherwise it must be a
8207 x_edge_detection (f
, img
, matrix
, color_adjust
)
8210 Lisp_Object matrix
, color_adjust
;
8218 i
< 9 && CONSP (matrix
) && NUMBERP (XCAR (matrix
));
8219 ++i
, matrix
= XCDR (matrix
))
8220 trans
[i
] = XFLOATINT (XCAR (matrix
));
8222 else if (VECTORP (matrix
) && ASIZE (matrix
) >= 9)
8224 for (i
= 0; i
< 9 && NUMBERP (AREF (matrix
, i
)); ++i
)
8225 trans
[i
] = XFLOATINT (AREF (matrix
, i
));
8228 if (NILP (color_adjust
))
8229 color_adjust
= make_number (0xffff / 2);
8231 if (i
== 9 && NUMBERP (color_adjust
))
8232 x_detect_edges (f
, img
, trans
, (int) XFLOATINT (color_adjust
));
8236 /* Transform image IMG on frame F so that it looks disabled. */
8239 x_disable_image (f
, img
)
8243 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8245 if (dpyinfo
->n_planes
>= 2)
8247 /* Color (or grayscale). Convert to gray, and equalize. Just
8248 drawing such images with a stipple can look very odd, so
8249 we're using this method instead. */
8250 XColor
*colors
= x_to_xcolors (f
, img
, 1);
8252 const int h
= 15000;
8253 const int l
= 30000;
8255 for (p
= colors
, end
= colors
+ img
->width
* img
->height
;
8259 int i
= COLOR_INTENSITY (p
->red
, p
->green
, p
->blue
);
8260 int i2
= (0xffff - h
- l
) * i
/ 0xffff + l
;
8261 p
->red
= p
->green
= p
->blue
= i2
;
8264 x_from_xcolors (f
, img
, colors
);
8267 /* Draw a cross over the disabled image, if we must or if we
8269 if (dpyinfo
->n_planes
< 2 || cross_disabled_images
)
8271 Display
*dpy
= FRAME_X_DISPLAY (f
);
8274 gc
= XCreateGC (dpy
, img
->pixmap
, 0, NULL
);
8275 XSetForeground (dpy
, gc
, BLACK_PIX_DEFAULT (f
));
8276 XDrawLine (dpy
, img
->pixmap
, gc
, 0, 0,
8277 img
->width
- 1, img
->height
- 1);
8278 XDrawLine (dpy
, img
->pixmap
, gc
, 0, img
->height
- 1,
8284 gc
= XCreateGC (dpy
, img
->mask
, 0, NULL
);
8285 XSetForeground (dpy
, gc
, WHITE_PIX_DEFAULT (f
));
8286 XDrawLine (dpy
, img
->mask
, gc
, 0, 0,
8287 img
->width
- 1, img
->height
- 1);
8288 XDrawLine (dpy
, img
->mask
, gc
, 0, img
->height
- 1,
8296 /* Build a mask for image IMG which is used on frame F. FILE is the
8297 name of an image file, for error messages. HOW determines how to
8298 determine the background color of IMG. If it is a list '(R G B)',
8299 with R, G, and B being integers >= 0, take that as the color of the
8300 background. Otherwise, determine the background color of IMG
8301 heuristically. Value is non-zero if successful. */
8304 x_build_heuristic_mask (f
, img
, how
)
8309 Display
*dpy
= FRAME_X_DISPLAY (f
);
8310 XImage
*ximg
, *mask_img
;
8311 int x
, y
, rc
, use_img_background
;
8312 unsigned long bg
= 0;
8316 XFreePixmap (FRAME_X_DISPLAY (f
), img
->mask
);
8318 img
->background_transparent_valid
= 0;
8321 /* Create an image and pixmap serving as mask. */
8322 rc
= x_create_x_image_and_pixmap (f
, img
->width
, img
->height
, 1,
8323 &mask_img
, &img
->mask
);
8327 /* Get the X image of IMG->pixmap. */
8328 ximg
= XGetImage (dpy
, img
->pixmap
, 0, 0, img
->width
, img
->height
,
8331 /* Determine the background color of ximg. If HOW is `(R G B)'
8332 take that as color. Otherwise, use the image's background color. */
8333 use_img_background
= 1;
8339 for (i
= 0; i
< 3 && CONSP (how
) && NATNUMP (XCAR (how
)); ++i
)
8341 rgb
[i
] = XFASTINT (XCAR (how
)) & 0xffff;
8345 if (i
== 3 && NILP (how
))
8347 char color_name
[30];
8348 sprintf (color_name
, "#%04x%04x%04x", rgb
[0], rgb
[1], rgb
[2]);
8349 bg
= x_alloc_image_color (f
, img
, build_string (color_name
), 0);
8350 use_img_background
= 0;
8354 if (use_img_background
)
8355 bg
= four_corners_best (ximg
, img
->width
, img
->height
);
8357 /* Set all bits in mask_img to 1 whose color in ximg is different
8358 from the background color bg. */
8359 for (y
= 0; y
< img
->height
; ++y
)
8360 for (x
= 0; x
< img
->width
; ++x
)
8361 XPutPixel (mask_img
, x
, y
, XGetPixel (ximg
, x
, y
) != bg
);
8363 /* Fill in the background_transparent field while we have the mask handy. */
8364 image_background_transparent (img
, f
, mask_img
);
8366 /* Put mask_img into img->mask. */
8367 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
8368 x_destroy_x_image (mask_img
);
8369 XDestroyImage (ximg
);
8376 /***********************************************************************
8377 PBM (mono, gray, color)
8378 ***********************************************************************/
8380 static int pbm_image_p
P_ ((Lisp_Object object
));
8381 static int pbm_load
P_ ((struct frame
*f
, struct image
*img
));
8382 static int pbm_scan_number
P_ ((unsigned char **, unsigned char *));
8384 /* The symbol `pbm' identifying images of this type. */
8388 /* Indices of image specification fields in gs_format, below. */
8390 enum pbm_keyword_index
8406 /* Vector of image_keyword structures describing the format
8407 of valid user-defined image specifications. */
8409 static struct image_keyword pbm_format
[PBM_LAST
] =
8411 {":type", IMAGE_SYMBOL_VALUE
, 1},
8412 {":file", IMAGE_STRING_VALUE
, 0},
8413 {":data", IMAGE_STRING_VALUE
, 0},
8414 {":ascent", IMAGE_ASCENT_VALUE
, 0},
8415 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8416 {":relief", IMAGE_INTEGER_VALUE
, 0},
8417 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8418 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8419 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8420 {":foreground", IMAGE_STRING_OR_NIL_VALUE
, 0},
8421 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
8424 /* Structure describing the image type `pbm'. */
8426 static struct image_type pbm_type
=
8436 /* Return non-zero if OBJECT is a valid PBM image specification. */
8439 pbm_image_p (object
)
8442 struct image_keyword fmt
[PBM_LAST
];
8444 bcopy (pbm_format
, fmt
, sizeof fmt
);
8446 if (!parse_image_spec (object
, fmt
, PBM_LAST
, Qpbm
))
8449 /* Must specify either :data or :file. */
8450 return fmt
[PBM_DATA
].count
+ fmt
[PBM_FILE
].count
== 1;
8454 /* Scan a decimal number from *S and return it. Advance *S while
8455 reading the number. END is the end of the string. Value is -1 at
8459 pbm_scan_number (s
, end
)
8460 unsigned char **s
, *end
;
8462 int c
= 0, val
= -1;
8466 /* Skip white-space. */
8467 while (*s
< end
&& (c
= *(*s
)++, isspace (c
)))
8472 /* Skip comment to end of line. */
8473 while (*s
< end
&& (c
= *(*s
)++, c
!= '\n'))
8476 else if (isdigit (c
))
8478 /* Read decimal number. */
8480 while (*s
< end
&& (c
= *(*s
)++, isdigit (c
)))
8481 val
= 10 * val
+ c
- '0';
8492 /* Load PBM image IMG for use on frame F. */
8500 int width
, height
, max_color_idx
= 0;
8502 Lisp_Object file
, specified_file
;
8503 enum {PBM_MONO
, PBM_GRAY
, PBM_COLOR
} type
;
8504 struct gcpro gcpro1
;
8505 unsigned char *contents
= NULL
;
8506 unsigned char *end
, *p
;
8509 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
8513 if (STRINGP (specified_file
))
8515 file
= x_find_image_file (specified_file
);
8516 if (!STRINGP (file
))
8518 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8523 contents
= slurp_file (SDATA (file
), &size
);
8524 if (contents
== NULL
)
8526 image_error ("Error reading `%s'", file
, Qnil
);
8532 end
= contents
+ size
;
8537 data
= image_spec_value (img
->spec
, QCdata
, NULL
);
8539 end
= p
+ SBYTES (data
);
8542 /* Check magic number. */
8543 if (end
- p
< 2 || *p
++ != 'P')
8545 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
8555 raw_p
= 0, type
= PBM_MONO
;
8559 raw_p
= 0, type
= PBM_GRAY
;
8563 raw_p
= 0, type
= PBM_COLOR
;
8567 raw_p
= 1, type
= PBM_MONO
;
8571 raw_p
= 1, type
= PBM_GRAY
;
8575 raw_p
= 1, type
= PBM_COLOR
;
8579 image_error ("Not a PBM image: `%s'", img
->spec
, Qnil
);
8583 /* Read width, height, maximum color-component. Characters
8584 starting with `#' up to the end of a line are ignored. */
8585 width
= pbm_scan_number (&p
, end
);
8586 height
= pbm_scan_number (&p
, end
);
8588 if (type
!= PBM_MONO
)
8590 max_color_idx
= pbm_scan_number (&p
, end
);
8591 if (raw_p
&& max_color_idx
> 255)
8592 max_color_idx
= 255;
8597 || (type
!= PBM_MONO
&& max_color_idx
< 0))
8600 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0,
8601 &ximg
, &img
->pixmap
))
8604 /* Initialize the color hash table. */
8605 init_color_table ();
8607 if (type
== PBM_MONO
)
8610 struct image_keyword fmt
[PBM_LAST
];
8611 unsigned long fg
= FRAME_FOREGROUND_PIXEL (f
);
8612 unsigned long bg
= FRAME_BACKGROUND_PIXEL (f
);
8614 /* Parse the image specification. */
8615 bcopy (pbm_format
, fmt
, sizeof fmt
);
8616 parse_image_spec (img
->spec
, fmt
, PBM_LAST
, Qpbm
);
8618 /* Get foreground and background colors, maybe allocate colors. */
8619 if (fmt
[PBM_FOREGROUND
].count
8620 && STRINGP (fmt
[PBM_FOREGROUND
].value
))
8621 fg
= x_alloc_image_color (f
, img
, fmt
[PBM_FOREGROUND
].value
, fg
);
8622 if (fmt
[PBM_BACKGROUND
].count
8623 && STRINGP (fmt
[PBM_BACKGROUND
].value
))
8625 bg
= x_alloc_image_color (f
, img
, fmt
[PBM_BACKGROUND
].value
, bg
);
8626 img
->background
= bg
;
8627 img
->background_valid
= 1;
8630 for (y
= 0; y
< height
; ++y
)
8631 for (x
= 0; x
< width
; ++x
)
8641 g
= pbm_scan_number (&p
, end
);
8643 XPutPixel (ximg
, x
, y
, g
? fg
: bg
);
8648 for (y
= 0; y
< height
; ++y
)
8649 for (x
= 0; x
< width
; ++x
)
8653 if (type
== PBM_GRAY
)
8654 r
= g
= b
= raw_p
? *p
++ : pbm_scan_number (&p
, end
);
8663 r
= pbm_scan_number (&p
, end
);
8664 g
= pbm_scan_number (&p
, end
);
8665 b
= pbm_scan_number (&p
, end
);
8668 if (r
< 0 || g
< 0 || b
< 0)
8672 XDestroyImage (ximg
);
8673 image_error ("Invalid pixel value in image `%s'",
8678 /* RGB values are now in the range 0..max_color_idx.
8679 Scale this to the range 0..0xffff supported by X. */
8680 r
= (double) r
* 65535 / max_color_idx
;
8681 g
= (double) g
* 65535 / max_color_idx
;
8682 b
= (double) b
* 65535 / max_color_idx
;
8683 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
8687 /* Store in IMG->colors the colors allocated for the image, and
8688 free the color table. */
8689 img
->colors
= colors_in_color_table (&img
->ncolors
);
8690 free_color_table ();
8692 /* Maybe fill in the background field while we have ximg handy. */
8693 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
8694 IMAGE_BACKGROUND (img
, f
, ximg
);
8696 /* Put the image into a pixmap. */
8697 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
8698 x_destroy_x_image (ximg
);
8701 img
->height
= height
;
8710 /***********************************************************************
8712 ***********************************************************************/
8718 /* Function prototypes. */
8720 static int png_image_p
P_ ((Lisp_Object object
));
8721 static int png_load
P_ ((struct frame
*f
, struct image
*img
));
8723 /* The symbol `png' identifying images of this type. */
8727 /* Indices of image specification fields in png_format, below. */
8729 enum png_keyword_index
8744 /* Vector of image_keyword structures describing the format
8745 of valid user-defined image specifications. */
8747 static struct image_keyword png_format
[PNG_LAST
] =
8749 {":type", IMAGE_SYMBOL_VALUE
, 1},
8750 {":data", IMAGE_STRING_VALUE
, 0},
8751 {":file", IMAGE_STRING_VALUE
, 0},
8752 {":ascent", IMAGE_ASCENT_VALUE
, 0},
8753 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
8754 {":relief", IMAGE_INTEGER_VALUE
, 0},
8755 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8756 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8757 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
8758 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
8761 /* Structure describing the image type `png'. */
8763 static struct image_type png_type
=
8773 /* Return non-zero if OBJECT is a valid PNG image specification. */
8776 png_image_p (object
)
8779 struct image_keyword fmt
[PNG_LAST
];
8780 bcopy (png_format
, fmt
, sizeof fmt
);
8782 if (!parse_image_spec (object
, fmt
, PNG_LAST
, Qpng
))
8785 /* Must specify either the :data or :file keyword. */
8786 return fmt
[PNG_FILE
].count
+ fmt
[PNG_DATA
].count
== 1;
8790 /* Error and warning handlers installed when the PNG library
8794 my_png_error (png_ptr
, msg
)
8795 png_struct
*png_ptr
;
8798 xassert (png_ptr
!= NULL
);
8799 image_error ("PNG error: %s", build_string (msg
), Qnil
);
8800 longjmp (png_ptr
->jmpbuf
, 1);
8805 my_png_warning (png_ptr
, msg
)
8806 png_struct
*png_ptr
;
8809 xassert (png_ptr
!= NULL
);
8810 image_error ("PNG warning: %s", build_string (msg
), Qnil
);
8813 /* Memory source for PNG decoding. */
8815 struct png_memory_storage
8817 unsigned char *bytes
; /* The data */
8818 size_t len
; /* How big is it? */
8819 int index
; /* Where are we? */
8823 /* Function set as reader function when reading PNG image from memory.
8824 PNG_PTR is a pointer to the PNG control structure. Copy LENGTH
8825 bytes from the input to DATA. */
8828 png_read_from_memory (png_ptr
, data
, length
)
8829 png_structp png_ptr
;
8833 struct png_memory_storage
*tbr
8834 = (struct png_memory_storage
*) png_get_io_ptr (png_ptr
);
8836 if (length
> tbr
->len
- tbr
->index
)
8837 png_error (png_ptr
, "Read error");
8839 bcopy (tbr
->bytes
+ tbr
->index
, data
, length
);
8840 tbr
->index
= tbr
->index
+ length
;
8843 /* Load PNG image IMG for use on frame F. Value is non-zero if
8851 Lisp_Object file
, specified_file
;
8852 Lisp_Object specified_data
;
8854 XImage
*ximg
, *mask_img
= NULL
;
8855 struct gcpro gcpro1
;
8856 png_struct
*png_ptr
= NULL
;
8857 png_info
*info_ptr
= NULL
, *end_info
= NULL
;
8858 FILE *volatile fp
= NULL
;
8860 png_byte
* volatile pixels
= NULL
;
8861 png_byte
** volatile rows
= NULL
;
8862 png_uint_32 width
, height
;
8863 int bit_depth
, color_type
, interlace_type
;
8865 png_uint_32 row_bytes
;
8867 double screen_gamma
, image_gamma
;
8869 struct png_memory_storage tbr
; /* Data to be read */
8871 /* Find out what file to load. */
8872 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
8873 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
8877 if (NILP (specified_data
))
8879 file
= x_find_image_file (specified_file
);
8880 if (!STRINGP (file
))
8882 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
8887 /* Open the image file. */
8888 fp
= fopen (SDATA (file
), "rb");
8891 image_error ("Cannot open image file `%s'", file
, Qnil
);
8897 /* Check PNG signature. */
8898 if (fread (sig
, 1, sizeof sig
, fp
) != sizeof sig
8899 || !png_check_sig (sig
, sizeof sig
))
8901 image_error ("Not a PNG file: `%s'", file
, Qnil
);
8909 /* Read from memory. */
8910 tbr
.bytes
= SDATA (specified_data
);
8911 tbr
.len
= SBYTES (specified_data
);
8914 /* Check PNG signature. */
8915 if (tbr
.len
< sizeof sig
8916 || !png_check_sig (tbr
.bytes
, sizeof sig
))
8918 image_error ("Not a PNG image: `%s'", img
->spec
, Qnil
);
8923 /* Need to skip past the signature. */
8924 tbr
.bytes
+= sizeof (sig
);
8927 /* Initialize read and info structs for PNG lib. */
8928 png_ptr
= png_create_read_struct (PNG_LIBPNG_VER_STRING
, NULL
,
8929 my_png_error
, my_png_warning
);
8932 if (fp
) fclose (fp
);
8937 info_ptr
= png_create_info_struct (png_ptr
);
8940 png_destroy_read_struct (&png_ptr
, NULL
, NULL
);
8941 if (fp
) fclose (fp
);
8946 end_info
= png_create_info_struct (png_ptr
);
8949 png_destroy_read_struct (&png_ptr
, &info_ptr
, NULL
);
8950 if (fp
) fclose (fp
);
8955 /* Set error jump-back. We come back here when the PNG library
8956 detects an error. */
8957 if (setjmp (png_ptr
->jmpbuf
))
8961 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
8964 if (fp
) fclose (fp
);
8969 /* Read image info. */
8970 if (!NILP (specified_data
))
8971 png_set_read_fn (png_ptr
, (void *) &tbr
, png_read_from_memory
);
8973 png_init_io (png_ptr
, fp
);
8975 png_set_sig_bytes (png_ptr
, sizeof sig
);
8976 png_read_info (png_ptr
, info_ptr
);
8977 png_get_IHDR (png_ptr
, info_ptr
, &width
, &height
, &bit_depth
, &color_type
,
8978 &interlace_type
, NULL
, NULL
);
8980 /* If image contains simply transparency data, we prefer to
8981 construct a clipping mask. */
8982 if (png_get_valid (png_ptr
, info_ptr
, PNG_INFO_tRNS
))
8987 /* This function is easier to write if we only have to handle
8988 one data format: RGB or RGBA with 8 bits per channel. Let's
8989 transform other formats into that format. */
8991 /* Strip more than 8 bits per channel. */
8992 if (bit_depth
== 16)
8993 png_set_strip_16 (png_ptr
);
8995 /* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha channel
8997 png_set_expand (png_ptr
);
8999 /* Convert grayscale images to RGB. */
9000 if (color_type
== PNG_COLOR_TYPE_GRAY
9001 || color_type
== PNG_COLOR_TYPE_GRAY_ALPHA
)
9002 png_set_gray_to_rgb (png_ptr
);
9004 screen_gamma
= (f
->gamma
? 1 / f
->gamma
/ 0.45455 : 2.2);
9006 /* Tell the PNG lib to handle gamma correction for us. */
9008 #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
9009 if (png_get_sRGB (png_ptr
, info_ptr
, &intent
))
9010 /* The libpng documentation says this is right in this case. */
9011 png_set_gamma (png_ptr
, screen_gamma
, 0.45455);
9014 if (png_get_gAMA (png_ptr
, info_ptr
, &image_gamma
))
9015 /* Image contains gamma information. */
9016 png_set_gamma (png_ptr
, screen_gamma
, image_gamma
);
9018 /* Use the standard default for the image gamma. */
9019 png_set_gamma (png_ptr
, screen_gamma
, 0.45455);
9021 /* Handle alpha channel by combining the image with a background
9022 color. Do this only if a real alpha channel is supplied. For
9023 simple transparency, we prefer a clipping mask. */
9026 png_color_16
*image_bg
;
9027 Lisp_Object specified_bg
9028 = image_spec_value (img
->spec
, QCbackground
, NULL
);
9030 if (STRINGP (specified_bg
))
9031 /* The user specified `:background', use that. */
9034 if (x_defined_color (f
, SDATA (specified_bg
), &color
, 0))
9036 png_color_16 user_bg
;
9038 bzero (&user_bg
, sizeof user_bg
);
9039 user_bg
.red
= color
.red
;
9040 user_bg
.green
= color
.green
;
9041 user_bg
.blue
= color
.blue
;
9043 png_set_background (png_ptr
, &user_bg
,
9044 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
9047 else if (png_get_bKGD (png_ptr
, info_ptr
, &image_bg
))
9048 /* Image contains a background color with which to
9049 combine the image. */
9050 png_set_background (png_ptr
, image_bg
,
9051 PNG_BACKGROUND_GAMMA_FILE
, 1, 1.0);
9054 /* Image does not contain a background color with which
9055 to combine the image data via an alpha channel. Use
9056 the frame's background instead. */
9059 png_color_16 frame_background
;
9061 cmap
= FRAME_X_COLORMAP (f
);
9062 color
.pixel
= FRAME_BACKGROUND_PIXEL (f
);
9063 x_query_color (f
, &color
);
9065 bzero (&frame_background
, sizeof frame_background
);
9066 frame_background
.red
= color
.red
;
9067 frame_background
.green
= color
.green
;
9068 frame_background
.blue
= color
.blue
;
9070 png_set_background (png_ptr
, &frame_background
,
9071 PNG_BACKGROUND_GAMMA_SCREEN
, 0, 1.0);
9075 /* Update info structure. */
9076 png_read_update_info (png_ptr
, info_ptr
);
9078 /* Get number of channels. Valid values are 1 for grayscale images
9079 and images with a palette, 2 for grayscale images with transparency
9080 information (alpha channel), 3 for RGB images, and 4 for RGB
9081 images with alpha channel, i.e. RGBA. If conversions above were
9082 sufficient we should only have 3 or 4 channels here. */
9083 channels
= png_get_channels (png_ptr
, info_ptr
);
9084 xassert (channels
== 3 || channels
== 4);
9086 /* Number of bytes needed for one row of the image. */
9087 row_bytes
= png_get_rowbytes (png_ptr
, info_ptr
);
9089 /* Allocate memory for the image. */
9090 pixels
= (png_byte
*) xmalloc (row_bytes
* height
* sizeof *pixels
);
9091 rows
= (png_byte
**) xmalloc (height
* sizeof *rows
);
9092 for (i
= 0; i
< height
; ++i
)
9093 rows
[i
] = pixels
+ i
* row_bytes
;
9095 /* Read the entire image. */
9096 png_read_image (png_ptr
, rows
);
9097 png_read_end (png_ptr
, info_ptr
);
9104 /* Create the X image and pixmap. */
9105 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
,
9109 /* Create an image and pixmap serving as mask if the PNG image
9110 contains an alpha channel. */
9113 && !x_create_x_image_and_pixmap (f
, width
, height
, 1,
9114 &mask_img
, &img
->mask
))
9116 x_destroy_x_image (ximg
);
9117 XFreePixmap (FRAME_X_DISPLAY (f
), img
->pixmap
);
9122 /* Fill the X image and mask from PNG data. */
9123 init_color_table ();
9125 for (y
= 0; y
< height
; ++y
)
9127 png_byte
*p
= rows
[y
];
9129 for (x
= 0; x
< width
; ++x
)
9136 XPutPixel (ximg
, x
, y
, lookup_rgb_color (f
, r
, g
, b
));
9138 /* An alpha channel, aka mask channel, associates variable
9139 transparency with an image. Where other image formats
9140 support binary transparency---fully transparent or fully
9141 opaque---PNG allows up to 254 levels of partial transparency.
9142 The PNG library implements partial transparency by combining
9143 the image with a specified background color.
9145 I'm not sure how to handle this here nicely: because the
9146 background on which the image is displayed may change, for
9147 real alpha channel support, it would be necessary to create
9148 a new image for each possible background.
9150 What I'm doing now is that a mask is created if we have
9151 boolean transparency information. Otherwise I'm using
9152 the frame's background color to combine the image with. */
9157 XPutPixel (mask_img
, x
, y
, *p
> 0);
9163 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
9164 /* Set IMG's background color from the PNG image, unless the user
9168 if (png_get_bKGD (png_ptr
, info_ptr
, &bg
))
9170 img
->background
= lookup_rgb_color (f
, bg
->red
, bg
->green
, bg
->blue
);
9171 img
->background_valid
= 1;
9175 /* Remember colors allocated for this image. */
9176 img
->colors
= colors_in_color_table (&img
->ncolors
);
9177 free_color_table ();
9180 png_destroy_read_struct (&png_ptr
, &info_ptr
, &end_info
);
9185 img
->height
= height
;
9187 /* Maybe fill in the background field while we have ximg handy. */
9188 IMAGE_BACKGROUND (img
, f
, ximg
);
9190 /* Put the image into the pixmap, then free the X image and its buffer. */
9191 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
9192 x_destroy_x_image (ximg
);
9194 /* Same for the mask. */
9197 /* Fill in the background_transparent field while we have the mask
9199 image_background_transparent (img
, f
, mask_img
);
9201 x_put_x_image (f
, mask_img
, img
->mask
, img
->width
, img
->height
);
9202 x_destroy_x_image (mask_img
);
9209 #endif /* HAVE_PNG != 0 */
9213 /***********************************************************************
9215 ***********************************************************************/
9219 /* Work around a warning about HAVE_STDLIB_H being redefined in
9221 #ifdef HAVE_STDLIB_H
9222 #define HAVE_STDLIB_H_1
9223 #undef HAVE_STDLIB_H
9224 #endif /* HAVE_STLIB_H */
9226 #include <jpeglib.h>
9230 #ifdef HAVE_STLIB_H_1
9231 #define HAVE_STDLIB_H 1
9234 static int jpeg_image_p
P_ ((Lisp_Object object
));
9235 static int jpeg_load
P_ ((struct frame
*f
, struct image
*img
));
9237 /* The symbol `jpeg' identifying images of this type. */
9241 /* Indices of image specification fields in gs_format, below. */
9243 enum jpeg_keyword_index
9252 JPEG_HEURISTIC_MASK
,
9258 /* Vector of image_keyword structures describing the format
9259 of valid user-defined image specifications. */
9261 static struct image_keyword jpeg_format
[JPEG_LAST
] =
9263 {":type", IMAGE_SYMBOL_VALUE
, 1},
9264 {":data", IMAGE_STRING_VALUE
, 0},
9265 {":file", IMAGE_STRING_VALUE
, 0},
9266 {":ascent", IMAGE_ASCENT_VALUE
, 0},
9267 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9268 {":relief", IMAGE_INTEGER_VALUE
, 0},
9269 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9270 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9271 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9272 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
9275 /* Structure describing the image type `jpeg'. */
9277 static struct image_type jpeg_type
=
9287 /* Return non-zero if OBJECT is a valid JPEG image specification. */
9290 jpeg_image_p (object
)
9293 struct image_keyword fmt
[JPEG_LAST
];
9295 bcopy (jpeg_format
, fmt
, sizeof fmt
);
9297 if (!parse_image_spec (object
, fmt
, JPEG_LAST
, Qjpeg
))
9300 /* Must specify either the :data or :file keyword. */
9301 return fmt
[JPEG_FILE
].count
+ fmt
[JPEG_DATA
].count
== 1;
9305 struct my_jpeg_error_mgr
9307 struct jpeg_error_mgr pub
;
9308 jmp_buf setjmp_buffer
;
9313 my_error_exit (cinfo
)
9316 struct my_jpeg_error_mgr
*mgr
= (struct my_jpeg_error_mgr
*) cinfo
->err
;
9317 longjmp (mgr
->setjmp_buffer
, 1);
9321 /* Init source method for JPEG data source manager. Called by
9322 jpeg_read_header() before any data is actually read. See
9323 libjpeg.doc from the JPEG lib distribution. */
9326 our_init_source (cinfo
)
9327 j_decompress_ptr cinfo
;
9332 /* Fill input buffer method for JPEG data source manager. Called
9333 whenever more data is needed. We read the whole image in one step,
9334 so this only adds a fake end of input marker at the end. */
9337 our_fill_input_buffer (cinfo
)
9338 j_decompress_ptr cinfo
;
9340 /* Insert a fake EOI marker. */
9341 struct jpeg_source_mgr
*src
= cinfo
->src
;
9342 static JOCTET buffer
[2];
9344 buffer
[0] = (JOCTET
) 0xFF;
9345 buffer
[1] = (JOCTET
) JPEG_EOI
;
9347 src
->next_input_byte
= buffer
;
9348 src
->bytes_in_buffer
= 2;
9353 /* Method to skip over NUM_BYTES bytes in the image data. CINFO->src
9354 is the JPEG data source manager. */
9357 our_skip_input_data (cinfo
, num_bytes
)
9358 j_decompress_ptr cinfo
;
9361 struct jpeg_source_mgr
*src
= (struct jpeg_source_mgr
*) cinfo
->src
;
9365 if (num_bytes
> src
->bytes_in_buffer
)
9366 ERREXIT (cinfo
, JERR_INPUT_EOF
);
9368 src
->bytes_in_buffer
-= num_bytes
;
9369 src
->next_input_byte
+= num_bytes
;
9374 /* Method to terminate data source. Called by
9375 jpeg_finish_decompress() after all data has been processed. */
9378 our_term_source (cinfo
)
9379 j_decompress_ptr cinfo
;
9384 /* Set up the JPEG lib for reading an image from DATA which contains
9385 LEN bytes. CINFO is the decompression info structure created for
9386 reading the image. */
9389 jpeg_memory_src (cinfo
, data
, len
)
9390 j_decompress_ptr cinfo
;
9394 struct jpeg_source_mgr
*src
;
9396 if (cinfo
->src
== NULL
)
9398 /* First time for this JPEG object? */
9399 cinfo
->src
= (struct jpeg_source_mgr
*)
9400 (*cinfo
->mem
->alloc_small
) ((j_common_ptr
) cinfo
, JPOOL_PERMANENT
,
9401 sizeof (struct jpeg_source_mgr
));
9402 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
9403 src
->next_input_byte
= data
;
9406 src
= (struct jpeg_source_mgr
*) cinfo
->src
;
9407 src
->init_source
= our_init_source
;
9408 src
->fill_input_buffer
= our_fill_input_buffer
;
9409 src
->skip_input_data
= our_skip_input_data
;
9410 src
->resync_to_restart
= jpeg_resync_to_restart
; /* Use default method. */
9411 src
->term_source
= our_term_source
;
9412 src
->bytes_in_buffer
= len
;
9413 src
->next_input_byte
= data
;
9417 /* Load image IMG for use on frame F. Patterned after example.c
9418 from the JPEG lib. */
9425 struct jpeg_decompress_struct cinfo
;
9426 struct my_jpeg_error_mgr mgr
;
9427 Lisp_Object file
, specified_file
;
9428 Lisp_Object specified_data
;
9429 FILE * volatile fp
= NULL
;
9431 int row_stride
, x
, y
;
9432 XImage
*ximg
= NULL
;
9434 unsigned long *colors
;
9436 struct gcpro gcpro1
;
9438 /* Open the JPEG file. */
9439 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9440 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9444 if (NILP (specified_data
))
9446 file
= x_find_image_file (specified_file
);
9447 if (!STRINGP (file
))
9449 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
9454 fp
= fopen (SDATA (file
), "r");
9457 image_error ("Cannot open `%s'", file
, Qnil
);
9463 /* Customize libjpeg's error handling to call my_error_exit when an
9464 error is detected. This function will perform a longjmp. */
9465 cinfo
.err
= jpeg_std_error (&mgr
.pub
);
9466 mgr
.pub
.error_exit
= my_error_exit
;
9468 if ((rc
= setjmp (mgr
.setjmp_buffer
)) != 0)
9472 /* Called from my_error_exit. Display a JPEG error. */
9473 char buffer
[JMSG_LENGTH_MAX
];
9474 cinfo
.err
->format_message ((j_common_ptr
) &cinfo
, buffer
);
9475 image_error ("Error reading JPEG image `%s': %s", img
->spec
,
9476 build_string (buffer
));
9479 /* Close the input file and destroy the JPEG object. */
9481 fclose ((FILE *) fp
);
9482 jpeg_destroy_decompress (&cinfo
);
9484 /* If we already have an XImage, free that. */
9485 x_destroy_x_image (ximg
);
9487 /* Free pixmap and colors. */
9488 x_clear_image (f
, img
);
9494 /* Create the JPEG decompression object. Let it read from fp.
9495 Read the JPEG image header. */
9496 jpeg_create_decompress (&cinfo
);
9498 if (NILP (specified_data
))
9499 jpeg_stdio_src (&cinfo
, (FILE *) fp
);
9501 jpeg_memory_src (&cinfo
, SDATA (specified_data
),
9502 SBYTES (specified_data
));
9504 jpeg_read_header (&cinfo
, TRUE
);
9506 /* Customize decompression so that color quantization will be used.
9507 Start decompression. */
9508 cinfo
.quantize_colors
= TRUE
;
9509 jpeg_start_decompress (&cinfo
);
9510 width
= img
->width
= cinfo
.output_width
;
9511 height
= img
->height
= cinfo
.output_height
;
9513 /* Create X image and pixmap. */
9514 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
9515 longjmp (mgr
.setjmp_buffer
, 2);
9517 /* Allocate colors. When color quantization is used,
9518 cinfo.actual_number_of_colors has been set with the number of
9519 colors generated, and cinfo.colormap is a two-dimensional array
9520 of color indices in the range 0..cinfo.actual_number_of_colors.
9521 No more than 255 colors will be generated. */
9525 if (cinfo
.out_color_components
> 2)
9526 ir
= 0, ig
= 1, ib
= 2;
9527 else if (cinfo
.out_color_components
> 1)
9528 ir
= 0, ig
= 1, ib
= 0;
9530 ir
= 0, ig
= 0, ib
= 0;
9532 /* Use the color table mechanism because it handles colors that
9533 cannot be allocated nicely. Such colors will be replaced with
9534 a default color, and we don't have to care about which colors
9535 can be freed safely, and which can't. */
9536 init_color_table ();
9537 colors
= (unsigned long *) alloca (cinfo
.actual_number_of_colors
9540 for (i
= 0; i
< cinfo
.actual_number_of_colors
; ++i
)
9542 /* Multiply RGB values with 255 because X expects RGB values
9543 in the range 0..0xffff. */
9544 int r
= cinfo
.colormap
[ir
][i
] << 8;
9545 int g
= cinfo
.colormap
[ig
][i
] << 8;
9546 int b
= cinfo
.colormap
[ib
][i
] << 8;
9547 colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
9550 /* Remember those colors actually allocated. */
9551 img
->colors
= colors_in_color_table (&img
->ncolors
);
9552 free_color_table ();
9556 row_stride
= width
* cinfo
.output_components
;
9557 buffer
= cinfo
.mem
->alloc_sarray ((j_common_ptr
) &cinfo
, JPOOL_IMAGE
,
9559 for (y
= 0; y
< height
; ++y
)
9561 jpeg_read_scanlines (&cinfo
, buffer
, 1);
9562 for (x
= 0; x
< cinfo
.output_width
; ++x
)
9563 XPutPixel (ximg
, x
, y
, colors
[buffer
[0][x
]]);
9567 jpeg_finish_decompress (&cinfo
);
9568 jpeg_destroy_decompress (&cinfo
);
9570 fclose ((FILE *) fp
);
9572 /* Maybe fill in the background field while we have ximg handy. */
9573 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
9574 IMAGE_BACKGROUND (img
, f
, ximg
);
9576 /* Put the image into the pixmap. */
9577 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
9578 x_destroy_x_image (ximg
);
9583 #endif /* HAVE_JPEG */
9587 /***********************************************************************
9589 ***********************************************************************/
9595 static int tiff_image_p
P_ ((Lisp_Object object
));
9596 static int tiff_load
P_ ((struct frame
*f
, struct image
*img
));
9598 /* The symbol `tiff' identifying images of this type. */
9602 /* Indices of image specification fields in tiff_format, below. */
9604 enum tiff_keyword_index
9613 TIFF_HEURISTIC_MASK
,
9619 /* Vector of image_keyword structures describing the format
9620 of valid user-defined image specifications. */
9622 static struct image_keyword tiff_format
[TIFF_LAST
] =
9624 {":type", IMAGE_SYMBOL_VALUE
, 1},
9625 {":data", IMAGE_STRING_VALUE
, 0},
9626 {":file", IMAGE_STRING_VALUE
, 0},
9627 {":ascent", IMAGE_ASCENT_VALUE
, 0},
9628 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9629 {":relief", IMAGE_INTEGER_VALUE
, 0},
9630 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9631 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9632 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9633 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
9636 /* Structure describing the image type `tiff'. */
9638 static struct image_type tiff_type
=
9648 /* Return non-zero if OBJECT is a valid TIFF image specification. */
9651 tiff_image_p (object
)
9654 struct image_keyword fmt
[TIFF_LAST
];
9655 bcopy (tiff_format
, fmt
, sizeof fmt
);
9657 if (!parse_image_spec (object
, fmt
, TIFF_LAST
, Qtiff
))
9660 /* Must specify either the :data or :file keyword. */
9661 return fmt
[TIFF_FILE
].count
+ fmt
[TIFF_DATA
].count
== 1;
9665 /* Reading from a memory buffer for TIFF images Based on the PNG
9666 memory source, but we have to provide a lot of extra functions.
9669 We really only need to implement read and seek, but I am not
9670 convinced that the TIFF library is smart enough not to destroy
9671 itself if we only hand it the function pointers we need to
9676 unsigned char *bytes
;
9684 tiff_read_from_memory (data
, buf
, size
)
9689 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
9691 if (size
> src
->len
- src
->index
)
9693 bcopy (src
->bytes
+ src
->index
, buf
, size
);
9700 tiff_write_from_memory (data
, buf
, size
)
9710 tiff_seek_in_memory (data
, off
, whence
)
9715 tiff_memory_source
*src
= (tiff_memory_source
*) data
;
9720 case SEEK_SET
: /* Go from beginning of source. */
9724 case SEEK_END
: /* Go from end of source. */
9725 idx
= src
->len
+ off
;
9728 case SEEK_CUR
: /* Go from current position. */
9729 idx
= src
->index
+ off
;
9732 default: /* Invalid `whence'. */
9736 if (idx
> src
->len
|| idx
< 0)
9745 tiff_close_memory (data
)
9754 tiff_mmap_memory (data
, pbase
, psize
)
9759 /* It is already _IN_ memory. */
9765 tiff_unmap_memory (data
, base
, size
)
9770 /* We don't need to do this. */
9775 tiff_size_of_memory (data
)
9778 return ((tiff_memory_source
*) data
)->len
;
9783 tiff_error_handler (title
, format
, ap
)
9784 const char *title
, *format
;
9790 len
= sprintf (buf
, "TIFF error: %s ", title
);
9791 vsprintf (buf
+ len
, format
, ap
);
9792 add_to_log (buf
, Qnil
, Qnil
);
9797 tiff_warning_handler (title
, format
, ap
)
9798 const char *title
, *format
;
9804 len
= sprintf (buf
, "TIFF warning: %s ", title
);
9805 vsprintf (buf
+ len
, format
, ap
);
9806 add_to_log (buf
, Qnil
, Qnil
);
9810 /* Load TIFF image IMG for use on frame F. Value is non-zero if
9818 Lisp_Object file
, specified_file
;
9819 Lisp_Object specified_data
;
9821 int width
, height
, x
, y
;
9825 struct gcpro gcpro1
;
9826 tiff_memory_source memsrc
;
9828 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
9829 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
9833 TIFFSetErrorHandler (tiff_error_handler
);
9834 TIFFSetWarningHandler (tiff_warning_handler
);
9836 if (NILP (specified_data
))
9838 /* Read from a file */
9839 file
= x_find_image_file (specified_file
);
9840 if (!STRINGP (file
))
9842 image_error ("Cannot find image file `%s'", file
, Qnil
);
9847 /* Try to open the image file. */
9848 tiff
= TIFFOpen (SDATA (file
), "r");
9851 image_error ("Cannot open `%s'", file
, Qnil
);
9858 /* Memory source! */
9859 memsrc
.bytes
= SDATA (specified_data
);
9860 memsrc
.len
= SBYTES (specified_data
);
9863 tiff
= TIFFClientOpen ("memory_source", "r", &memsrc
,
9864 (TIFFReadWriteProc
) tiff_read_from_memory
,
9865 (TIFFReadWriteProc
) tiff_write_from_memory
,
9866 tiff_seek_in_memory
,
9868 tiff_size_of_memory
,
9874 image_error ("Cannot open memory source for `%s'", img
->spec
, Qnil
);
9880 /* Get width and height of the image, and allocate a raster buffer
9881 of width x height 32-bit values. */
9882 TIFFGetField (tiff
, TIFFTAG_IMAGEWIDTH
, &width
);
9883 TIFFGetField (tiff
, TIFFTAG_IMAGELENGTH
, &height
);
9884 buf
= (uint32
*) xmalloc (width
* height
* sizeof *buf
);
9886 rc
= TIFFReadRGBAImage (tiff
, width
, height
, buf
, 0);
9890 image_error ("Error reading TIFF image `%s'", img
->spec
, Qnil
);
9896 /* Create the X image and pixmap. */
9897 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
9904 /* Initialize the color table. */
9905 init_color_table ();
9907 /* Process the pixel raster. Origin is in the lower-left corner. */
9908 for (y
= 0; y
< height
; ++y
)
9910 uint32
*row
= buf
+ y
* width
;
9912 for (x
= 0; x
< width
; ++x
)
9914 uint32 abgr
= row
[x
];
9915 int r
= TIFFGetR (abgr
) << 8;
9916 int g
= TIFFGetG (abgr
) << 8;
9917 int b
= TIFFGetB (abgr
) << 8;
9918 XPutPixel (ximg
, x
, height
- 1 - y
, lookup_rgb_color (f
, r
, g
, b
));
9922 /* Remember the colors allocated for the image. Free the color table. */
9923 img
->colors
= colors_in_color_table (&img
->ncolors
);
9924 free_color_table ();
9927 img
->height
= height
;
9929 /* Maybe fill in the background field while we have ximg handy. */
9930 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
9931 IMAGE_BACKGROUND (img
, f
, ximg
);
9933 /* Put the image into the pixmap, then free the X image and its buffer. */
9934 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
9935 x_destroy_x_image (ximg
);
9942 #endif /* HAVE_TIFF != 0 */
9946 /***********************************************************************
9948 ***********************************************************************/
9952 #include <gif_lib.h>
9954 static int gif_image_p
P_ ((Lisp_Object object
));
9955 static int gif_load
P_ ((struct frame
*f
, struct image
*img
));
9957 /* The symbol `gif' identifying images of this type. */
9961 /* Indices of image specification fields in gif_format, below. */
9963 enum gif_keyword_index
9979 /* Vector of image_keyword structures describing the format
9980 of valid user-defined image specifications. */
9982 static struct image_keyword gif_format
[GIF_LAST
] =
9984 {":type", IMAGE_SYMBOL_VALUE
, 1},
9985 {":data", IMAGE_STRING_VALUE
, 0},
9986 {":file", IMAGE_STRING_VALUE
, 0},
9987 {":ascent", IMAGE_ASCENT_VALUE
, 0},
9988 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
9989 {":relief", IMAGE_INTEGER_VALUE
, 0},
9990 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9991 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9992 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
9993 {":image", IMAGE_NON_NEGATIVE_INTEGER_VALUE
, 0},
9994 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
9997 /* Structure describing the image type `gif'. */
9999 static struct image_type gif_type
=
10009 /* Return non-zero if OBJECT is a valid GIF image specification. */
10012 gif_image_p (object
)
10013 Lisp_Object object
;
10015 struct image_keyword fmt
[GIF_LAST
];
10016 bcopy (gif_format
, fmt
, sizeof fmt
);
10018 if (!parse_image_spec (object
, fmt
, GIF_LAST
, Qgif
))
10021 /* Must specify either the :data or :file keyword. */
10022 return fmt
[GIF_FILE
].count
+ fmt
[GIF_DATA
].count
== 1;
10026 /* Reading a GIF image from memory
10027 Based on the PNG memory stuff to a certain extent. */
10031 unsigned char *bytes
;
10038 /* Make the current memory source available to gif_read_from_memory.
10039 It's done this way because not all versions of libungif support
10040 a UserData field in the GifFileType structure. */
10041 static gif_memory_source
*current_gif_memory_src
;
10044 gif_read_from_memory (file
, buf
, len
)
10049 gif_memory_source
*src
= current_gif_memory_src
;
10051 if (len
> src
->len
- src
->index
)
10054 bcopy (src
->bytes
+ src
->index
, buf
, len
);
10060 /* Load GIF image IMG for use on frame F. Value is non-zero if
10068 Lisp_Object file
, specified_file
;
10069 Lisp_Object specified_data
;
10070 int rc
, width
, height
, x
, y
, i
;
10072 ColorMapObject
*gif_color_map
;
10073 unsigned long pixel_colors
[256];
10075 struct gcpro gcpro1
;
10077 int ino
, image_left
, image_top
, image_width
, image_height
;
10078 gif_memory_source memsrc
;
10079 unsigned char *raster
;
10081 specified_file
= image_spec_value (img
->spec
, QCfile
, NULL
);
10082 specified_data
= image_spec_value (img
->spec
, QCdata
, NULL
);
10086 if (NILP (specified_data
))
10088 file
= x_find_image_file (specified_file
);
10089 if (!STRINGP (file
))
10091 image_error ("Cannot find image file `%s'", specified_file
, Qnil
);
10096 /* Open the GIF file. */
10097 gif
= DGifOpenFileName (SDATA (file
));
10100 image_error ("Cannot open `%s'", file
, Qnil
);
10107 /* Read from memory! */
10108 current_gif_memory_src
= &memsrc
;
10109 memsrc
.bytes
= SDATA (specified_data
);
10110 memsrc
.len
= SBYTES (specified_data
);
10113 gif
= DGifOpen(&memsrc
, gif_read_from_memory
);
10116 image_error ("Cannot open memory source `%s'", img
->spec
, Qnil
);
10122 /* Read entire contents. */
10123 rc
= DGifSlurp (gif
);
10124 if (rc
== GIF_ERROR
)
10126 image_error ("Error reading `%s'", img
->spec
, Qnil
);
10127 DGifCloseFile (gif
);
10132 image
= image_spec_value (img
->spec
, QCindex
, NULL
);
10133 ino
= INTEGERP (image
) ? XFASTINT (image
) : 0;
10134 if (ino
>= gif
->ImageCount
)
10136 image_error ("Invalid image number `%s' in image `%s'",
10138 DGifCloseFile (gif
);
10143 width
= img
->width
= max (gif
->SWidth
, gif
->Image
.Left
+ gif
->Image
.Width
);
10144 height
= img
->height
= max (gif
->SHeight
, gif
->Image
.Top
+ gif
->Image
.Height
);
10146 /* Create the X image and pixmap. */
10147 if (!x_create_x_image_and_pixmap (f
, width
, height
, 0, &ximg
, &img
->pixmap
))
10149 DGifCloseFile (gif
);
10154 /* Allocate colors. */
10155 gif_color_map
= gif
->SavedImages
[ino
].ImageDesc
.ColorMap
;
10156 if (!gif_color_map
)
10157 gif_color_map
= gif
->SColorMap
;
10158 init_color_table ();
10159 bzero (pixel_colors
, sizeof pixel_colors
);
10161 for (i
= 0; i
< gif_color_map
->ColorCount
; ++i
)
10163 int r
= gif_color_map
->Colors
[i
].Red
<< 8;
10164 int g
= gif_color_map
->Colors
[i
].Green
<< 8;
10165 int b
= gif_color_map
->Colors
[i
].Blue
<< 8;
10166 pixel_colors
[i
] = lookup_rgb_color (f
, r
, g
, b
);
10169 img
->colors
= colors_in_color_table (&img
->ncolors
);
10170 free_color_table ();
10172 /* Clear the part of the screen image that are not covered by
10173 the image from the GIF file. Full animated GIF support
10174 requires more than can be done here (see the gif89 spec,
10175 disposal methods). Let's simply assume that the part
10176 not covered by a sub-image is in the frame's background color. */
10177 image_top
= gif
->SavedImages
[ino
].ImageDesc
.Top
;
10178 image_left
= gif
->SavedImages
[ino
].ImageDesc
.Left
;
10179 image_width
= gif
->SavedImages
[ino
].ImageDesc
.Width
;
10180 image_height
= gif
->SavedImages
[ino
].ImageDesc
.Height
;
10182 for (y
= 0; y
< image_top
; ++y
)
10183 for (x
= 0; x
< width
; ++x
)
10184 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
10186 for (y
= image_top
+ image_height
; y
< height
; ++y
)
10187 for (x
= 0; x
< width
; ++x
)
10188 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
10190 for (y
= image_top
; y
< image_top
+ image_height
; ++y
)
10192 for (x
= 0; x
< image_left
; ++x
)
10193 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
10194 for (x
= image_left
+ image_width
; x
< width
; ++x
)
10195 XPutPixel (ximg
, x
, y
, FRAME_BACKGROUND_PIXEL (f
));
10198 /* Read the GIF image into the X image. We use a local variable
10199 `raster' here because RasterBits below is a char *, and invites
10200 problems with bytes >= 0x80. */
10201 raster
= (unsigned char *) gif
->SavedImages
[ino
].RasterBits
;
10203 if (gif
->SavedImages
[ino
].ImageDesc
.Interlace
)
10205 static int interlace_start
[] = {0, 4, 2, 1};
10206 static int interlace_increment
[] = {8, 8, 4, 2};
10208 int row
= interlace_start
[0];
10212 for (y
= 0; y
< image_height
; y
++)
10214 if (row
>= image_height
)
10216 row
= interlace_start
[++pass
];
10217 while (row
>= image_height
)
10218 row
= interlace_start
[++pass
];
10221 for (x
= 0; x
< image_width
; x
++)
10223 int i
= raster
[(y
* image_width
) + x
];
10224 XPutPixel (ximg
, x
+ image_left
, row
+ image_top
,
10228 row
+= interlace_increment
[pass
];
10233 for (y
= 0; y
< image_height
; ++y
)
10234 for (x
= 0; x
< image_width
; ++x
)
10236 int i
= raster
[y
* image_width
+ x
];
10237 XPutPixel (ximg
, x
+ image_left
, y
+ image_top
, pixel_colors
[i
]);
10241 DGifCloseFile (gif
);
10243 /* Maybe fill in the background field while we have ximg handy. */
10244 if (NILP (image_spec_value (img
->spec
, QCbackground
, NULL
)))
10245 IMAGE_BACKGROUND (img
, f
, ximg
);
10247 /* Put the image into the pixmap, then free the X image and its buffer. */
10248 x_put_x_image (f
, ximg
, img
->pixmap
, width
, height
);
10249 x_destroy_x_image (ximg
);
10255 #endif /* HAVE_GIF != 0 */
10259 /***********************************************************************
10261 ***********************************************************************/
10263 static int gs_image_p
P_ ((Lisp_Object object
));
10264 static int gs_load
P_ ((struct frame
*f
, struct image
*img
));
10265 static void gs_clear_image
P_ ((struct frame
*f
, struct image
*img
));
10267 /* The symbol `postscript' identifying images of this type. */
10269 Lisp_Object Qpostscript
;
10271 /* Keyword symbols. */
10273 Lisp_Object QCloader
, QCbounding_box
, QCpt_width
, QCpt_height
;
10275 /* Indices of image specification fields in gs_format, below. */
10277 enum gs_keyword_index
10295 /* Vector of image_keyword structures describing the format
10296 of valid user-defined image specifications. */
10298 static struct image_keyword gs_format
[GS_LAST
] =
10300 {":type", IMAGE_SYMBOL_VALUE
, 1},
10301 {":pt-width", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
10302 {":pt-height", IMAGE_POSITIVE_INTEGER_VALUE
, 1},
10303 {":file", IMAGE_STRING_VALUE
, 1},
10304 {":loader", IMAGE_FUNCTION_VALUE
, 0},
10305 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE
, 1},
10306 {":ascent", IMAGE_ASCENT_VALUE
, 0},
10307 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR
, 0},
10308 {":relief", IMAGE_INTEGER_VALUE
, 0},
10309 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10310 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10311 {":mask", IMAGE_DONT_CHECK_VALUE_TYPE
, 0},
10312 {":background", IMAGE_STRING_OR_NIL_VALUE
, 0}
10315 /* Structure describing the image type `ghostscript'. */
10317 static struct image_type gs_type
=
10327 /* Free X resources of Ghostscript image IMG which is used on frame F. */
10330 gs_clear_image (f
, img
)
10334 /* IMG->data.ptr_val may contain a recorded colormap. */
10335 xfree (img
->data
.ptr_val
);
10336 x_clear_image (f
, img
);
10340 /* Return non-zero if OBJECT is a valid Ghostscript image
10344 gs_image_p (object
)
10345 Lisp_Object object
;
10347 struct image_keyword fmt
[GS_LAST
];
10351 bcopy (gs_format
, fmt
, sizeof fmt
);
10353 if (!parse_image_spec (object
, fmt
, GS_LAST
, Qpostscript
))
10356 /* Bounding box must be a list or vector containing 4 integers. */
10357 tem
= fmt
[GS_BOUNDING_BOX
].value
;
10360 for (i
= 0; i
< 4; ++i
, tem
= XCDR (tem
))
10361 if (!CONSP (tem
) || !INTEGERP (XCAR (tem
)))
10366 else if (VECTORP (tem
))
10368 if (XVECTOR (tem
)->size
!= 4)
10370 for (i
= 0; i
< 4; ++i
)
10371 if (!INTEGERP (XVECTOR (tem
)->contents
[i
]))
10381 /* Load Ghostscript image IMG for use on frame F. Value is non-zero
10390 Lisp_Object window_and_pixmap_id
= Qnil
, loader
, pt_height
, pt_width
;
10391 struct gcpro gcpro1
, gcpro2
;
10393 double in_width
, in_height
;
10394 Lisp_Object pixel_colors
= Qnil
;
10396 /* Compute pixel size of pixmap needed from the given size in the
10397 image specification. Sizes in the specification are in pt. 1 pt
10398 = 1/72 in, xdpi and ydpi are stored in the frame's X display
10400 pt_width
= image_spec_value (img
->spec
, QCpt_width
, NULL
);
10401 in_width
= XFASTINT (pt_width
) / 72.0;
10402 img
->width
= in_width
* FRAME_X_DISPLAY_INFO (f
)->resx
;
10403 pt_height
= image_spec_value (img
->spec
, QCpt_height
, NULL
);
10404 in_height
= XFASTINT (pt_height
) / 72.0;
10405 img
->height
= in_height
* FRAME_X_DISPLAY_INFO (f
)->resy
;
10407 /* Create the pixmap. */
10408 xassert (img
->pixmap
== None
);
10409 img
->pixmap
= XCreatePixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10410 img
->width
, img
->height
,
10411 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)));
10415 image_error ("Unable to create pixmap for `%s'", img
->spec
, Qnil
);
10419 /* Call the loader to fill the pixmap. It returns a process object
10420 if successful. We do not record_unwind_protect here because
10421 other places in redisplay like calling window scroll functions
10422 don't either. Let the Lisp loader use `unwind-protect' instead. */
10423 GCPRO2 (window_and_pixmap_id
, pixel_colors
);
10425 sprintf (buffer
, "%lu %lu",
10426 (unsigned long) FRAME_X_WINDOW (f
),
10427 (unsigned long) img
->pixmap
);
10428 window_and_pixmap_id
= build_string (buffer
);
10430 sprintf (buffer
, "%lu %lu",
10431 FRAME_FOREGROUND_PIXEL (f
),
10432 FRAME_BACKGROUND_PIXEL (f
));
10433 pixel_colors
= build_string (buffer
);
10435 XSETFRAME (frame
, f
);
10436 loader
= image_spec_value (img
->spec
, QCloader
, NULL
);
10438 loader
= intern ("gs-load-image");
10440 img
->data
.lisp_val
= call6 (loader
, frame
, img
->spec
,
10441 make_number (img
->width
),
10442 make_number (img
->height
),
10443 window_and_pixmap_id
,
10446 return PROCESSP (img
->data
.lisp_val
);
10450 /* Kill the Ghostscript process that was started to fill PIXMAP on
10451 frame F. Called from XTread_socket when receiving an event
10452 telling Emacs that Ghostscript has finished drawing. */
10455 x_kill_gs_process (pixmap
, f
)
10459 struct image_cache
*c
= FRAME_X_IMAGE_CACHE (f
);
10463 /* Find the image containing PIXMAP. */
10464 for (i
= 0; i
< c
->used
; ++i
)
10465 if (c
->images
[i
]->pixmap
== pixmap
)
10468 /* Should someone in between have cleared the image cache, for
10469 instance, give up. */
10473 /* Kill the GS process. We should have found PIXMAP in the image
10474 cache and its image should contain a process object. */
10475 img
= c
->images
[i
];
10476 xassert (PROCESSP (img
->data
.lisp_val
));
10477 Fkill_process (img
->data
.lisp_val
, Qnil
);
10478 img
->data
.lisp_val
= Qnil
;
10480 /* On displays with a mutable colormap, figure out the colors
10481 allocated for the image by looking at the pixels of an XImage for
10483 class = FRAME_X_VISUAL (f
)->class;
10484 if (class != StaticColor
&& class != StaticGray
&& class != TrueColor
)
10490 /* Try to get an XImage for img->pixmep. */
10491 ximg
= XGetImage (FRAME_X_DISPLAY (f
), img
->pixmap
,
10492 0, 0, img
->width
, img
->height
, ~0, ZPixmap
);
10497 /* Initialize the color table. */
10498 init_color_table ();
10500 /* For each pixel of the image, look its color up in the
10501 color table. After having done so, the color table will
10502 contain an entry for each color used by the image. */
10503 for (y
= 0; y
< img
->height
; ++y
)
10504 for (x
= 0; x
< img
->width
; ++x
)
10506 unsigned long pixel
= XGetPixel (ximg
, x
, y
);
10507 lookup_pixel_color (f
, pixel
);
10510 /* Record colors in the image. Free color table and XImage. */
10511 img
->colors
= colors_in_color_table (&img
->ncolors
);
10512 free_color_table ();
10513 XDestroyImage (ximg
);
10515 #if 0 /* This doesn't seem to be the case. If we free the colors
10516 here, we get a BadAccess later in x_clear_image when
10517 freeing the colors. */
10518 /* We have allocated colors once, but Ghostscript has also
10519 allocated colors on behalf of us. So, to get the
10520 reference counts right, free them once. */
10522 x_free_colors (f
, img
->colors
, img
->ncolors
);
10526 image_error ("Cannot get X image of `%s'; colors will not be freed",
10532 /* Now that we have the pixmap, compute mask and transform the
10533 image if requested. */
10535 postprocess_image (f
, img
);
10541 /***********************************************************************
10543 ***********************************************************************/
10545 DEFUN ("x-change-window-property", Fx_change_window_property
,
10546 Sx_change_window_property
, 2, 3, 0,
10547 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
10548 PROP and VALUE must be strings. FRAME nil or omitted means use the
10549 selected frame. Value is VALUE. */)
10550 (prop
, value
, frame
)
10551 Lisp_Object frame
, prop
, value
;
10553 struct frame
*f
= check_x_frame (frame
);
10556 CHECK_STRING (prop
);
10557 CHECK_STRING (value
);
10560 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
10561 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10562 prop_atom
, XA_STRING
, 8, PropModeReplace
,
10563 SDATA (value
), SCHARS (value
));
10565 /* Make sure the property is set when we return. */
10566 XFlush (FRAME_X_DISPLAY (f
));
10573 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
10574 Sx_delete_window_property
, 1, 2, 0,
10575 doc
: /* Remove window property PROP from X window of FRAME.
10576 FRAME nil or omitted means use the selected frame. Value is PROP. */)
10578 Lisp_Object prop
, frame
;
10580 struct frame
*f
= check_x_frame (frame
);
10583 CHECK_STRING (prop
);
10585 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
10586 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
10588 /* Make sure the property is removed when we return. */
10589 XFlush (FRAME_X_DISPLAY (f
));
10596 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
10598 doc
: /* Value is the value of window property PROP on FRAME.
10599 If FRAME is nil or omitted, use the selected frame. Value is nil
10600 if FRAME hasn't a property with name PROP or if PROP has no string
10603 Lisp_Object prop
, frame
;
10605 struct frame
*f
= check_x_frame (frame
);
10608 Lisp_Object prop_value
= Qnil
;
10609 char *tmp_data
= NULL
;
10612 unsigned long actual_size
, bytes_remaining
;
10614 CHECK_STRING (prop
);
10616 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
10617 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10618 prop_atom
, 0, 0, False
, XA_STRING
,
10619 &actual_type
, &actual_format
, &actual_size
,
10620 &bytes_remaining
, (unsigned char **) &tmp_data
);
10623 int size
= bytes_remaining
;
10628 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10629 prop_atom
, 0, bytes_remaining
,
10631 &actual_type
, &actual_format
,
10632 &actual_size
, &bytes_remaining
,
10633 (unsigned char **) &tmp_data
);
10634 if (rc
== Success
&& tmp_data
)
10635 prop_value
= make_string (tmp_data
, size
);
10646 /***********************************************************************
10648 ***********************************************************************/
10650 /* If non-null, an asynchronous timer that, when it expires, displays
10651 an hourglass cursor on all frames. */
10653 static struct atimer
*hourglass_atimer
;
10655 /* Non-zero means an hourglass cursor is currently shown. */
10657 static int hourglass_shown_p
;
10659 /* Number of seconds to wait before displaying an hourglass cursor. */
10661 static Lisp_Object Vhourglass_delay
;
10663 /* Default number of seconds to wait before displaying an hourglass
10666 #define DEFAULT_HOURGLASS_DELAY 1
10668 /* Function prototypes. */
10670 static void show_hourglass
P_ ((struct atimer
*));
10671 static void hide_hourglass
P_ ((void));
10674 /* Cancel a currently active hourglass timer, and start a new one. */
10680 int secs
, usecs
= 0;
10682 cancel_hourglass ();
10684 if (INTEGERP (Vhourglass_delay
)
10685 && XINT (Vhourglass_delay
) > 0)
10686 secs
= XFASTINT (Vhourglass_delay
);
10687 else if (FLOATP (Vhourglass_delay
)
10688 && XFLOAT_DATA (Vhourglass_delay
) > 0)
10691 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
10692 secs
= XFASTINT (tem
);
10693 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
10696 secs
= DEFAULT_HOURGLASS_DELAY
;
10698 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
10699 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
10700 show_hourglass
, NULL
);
10704 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
10708 cancel_hourglass ()
10710 if (hourglass_atimer
)
10712 cancel_atimer (hourglass_atimer
);
10713 hourglass_atimer
= NULL
;
10716 if (hourglass_shown_p
)
10721 /* Timer function of hourglass_atimer. TIMER is equal to
10724 Display an hourglass pointer on all frames by mapping the frames'
10725 hourglass_window. Set the hourglass_p flag in the frames'
10726 output_data.x structure to indicate that an hourglass cursor is
10727 shown on the frames. */
10730 show_hourglass (timer
)
10731 struct atimer
*timer
;
10733 /* The timer implementation will cancel this timer automatically
10734 after this function has run. Set hourglass_atimer to null
10735 so that we know the timer doesn't have to be canceled. */
10736 hourglass_atimer
= NULL
;
10738 if (!hourglass_shown_p
)
10740 Lisp_Object rest
, frame
;
10744 FOR_EACH_FRAME (rest
, frame
)
10746 struct frame
*f
= XFRAME (frame
);
10748 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
10750 Display
*dpy
= FRAME_X_DISPLAY (f
);
10752 #ifdef USE_X_TOOLKIT
10753 if (f
->output_data
.x
->widget
)
10755 if (FRAME_OUTER_WINDOW (f
))
10758 f
->output_data
.x
->hourglass_p
= 1;
10760 if (!f
->output_data
.x
->hourglass_window
)
10762 unsigned long mask
= CWCursor
;
10763 XSetWindowAttributes attrs
;
10765 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
10767 f
->output_data
.x
->hourglass_window
10768 = XCreateWindow (dpy
, FRAME_OUTER_WINDOW (f
),
10769 0, 0, 32000, 32000, 0, 0,
10775 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
10781 hourglass_shown_p
= 1;
10787 /* Hide the hourglass pointer on all frames, if it is currently
10793 if (hourglass_shown_p
)
10795 Lisp_Object rest
, frame
;
10798 FOR_EACH_FRAME (rest
, frame
)
10800 struct frame
*f
= XFRAME (frame
);
10803 /* Watch out for newly created frames. */
10804 && f
->output_data
.x
->hourglass_window
)
10806 XUnmapWindow (FRAME_X_DISPLAY (f
),
10807 f
->output_data
.x
->hourglass_window
);
10808 /* Sync here because XTread_socket looks at the
10809 hourglass_p flag that is reset to zero below. */
10810 XSync (FRAME_X_DISPLAY (f
), False
);
10811 f
->output_data
.x
->hourglass_p
= 0;
10815 hourglass_shown_p
= 0;
10822 /***********************************************************************
10824 ***********************************************************************/
10826 static Lisp_Object x_create_tip_frame
P_ ((struct x_display_info
*,
10827 Lisp_Object
, Lisp_Object
));
10828 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
10829 Lisp_Object
, int, int, int *, int *));
10831 /* The frame of a currently visible tooltip. */
10833 Lisp_Object tip_frame
;
10835 /* If non-nil, a timer started that hides the last tooltip when it
10838 Lisp_Object tip_timer
;
10841 /* If non-nil, a vector of 3 elements containing the last args
10842 with which x-show-tip was called. See there. */
10844 Lisp_Object last_show_tip_args
;
10846 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
10848 Lisp_Object Vx_max_tooltip_size
;
10852 unwind_create_tip_frame (frame
)
10855 Lisp_Object deleted
;
10857 deleted
= unwind_create_frame (frame
);
10858 if (EQ (deleted
, Qt
))
10868 /* Create a frame for a tooltip on the display described by DPYINFO.
10869 PARMS is a list of frame parameters. TEXT is the string to
10870 display in the tip frame. Value is the frame.
10872 Note that functions called here, esp. x_default_parameter can
10873 signal errors, for instance when a specified color name is
10874 undefined. We have to make sure that we're in a consistent state
10875 when this happens. */
10878 x_create_tip_frame (dpyinfo
, parms
, text
)
10879 struct x_display_info
*dpyinfo
;
10880 Lisp_Object parms
, text
;
10883 Lisp_Object frame
, tem
;
10885 long window_prompting
= 0;
10887 int count
= SPECPDL_INDEX ();
10888 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10890 int face_change_count_before
= face_change_count
;
10891 Lisp_Object buffer
;
10892 struct buffer
*old_buffer
;
10896 /* Use this general default value to start with until we know if
10897 this frame has a specified name. */
10898 Vx_resource_name
= Vinvocation_name
;
10900 #ifdef MULTI_KBOARD
10901 kb
= dpyinfo
->kboard
;
10903 kb
= &the_only_kboard
;
10906 /* Get the name of the frame to use for resource lookup. */
10907 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
10908 if (!STRINGP (name
)
10909 && !EQ (name
, Qunbound
)
10911 error ("Invalid frame name--not a string or nil");
10912 Vx_resource_name
= name
;
10915 GCPRO3 (parms
, name
, frame
);
10916 f
= make_frame (1);
10917 XSETFRAME (frame
, f
);
10919 buffer
= Fget_buffer_create (build_string (" *tip*"));
10920 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
);
10921 old_buffer
= current_buffer
;
10922 set_buffer_internal_1 (XBUFFER (buffer
));
10923 current_buffer
->truncate_lines
= Qnil
;
10925 Finsert (1, &text
);
10926 set_buffer_internal_1 (old_buffer
);
10928 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
10929 record_unwind_protect (unwind_create_tip_frame
, frame
);
10931 /* By setting the output method, we're essentially saying that
10932 the frame is live, as per FRAME_LIVE_P. If we get a signal
10933 from this point on, x_destroy_window might screw up reference
10935 f
->output_method
= output_x_window
;
10936 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
10937 bzero (f
->output_data
.x
, sizeof (struct x_output
));
10938 f
->output_data
.x
->icon_bitmap
= -1;
10939 f
->output_data
.x
->fontset
= -1;
10940 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
10941 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
10942 #ifdef USE_TOOLKIT_SCROLL_BARS
10943 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
10944 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
10945 #endif /* USE_TOOLKIT_SCROLL_BARS */
10946 f
->icon_name
= Qnil
;
10947 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
10949 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
10950 dpyinfo_refcount
= dpyinfo
->reference_count
;
10951 #endif /* GLYPH_DEBUG */
10952 #ifdef MULTI_KBOARD
10953 FRAME_KBOARD (f
) = kb
;
10955 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
10956 f
->output_data
.x
->explicit_parent
= 0;
10958 /* These colors will be set anyway later, but it's important
10959 to get the color reference counts right, so initialize them! */
10962 struct gcpro gcpro1
;
10964 black
= build_string ("black");
10966 f
->output_data
.x
->foreground_pixel
10967 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10968 f
->output_data
.x
->background_pixel
10969 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10970 f
->output_data
.x
->cursor_pixel
10971 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10972 f
->output_data
.x
->cursor_foreground_pixel
10973 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10974 f
->output_data
.x
->border_pixel
10975 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10976 f
->output_data
.x
->mouse_pixel
10977 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
10981 /* Set the name; the functions to which we pass f expect the name to
10983 if (EQ (name
, Qunbound
) || NILP (name
))
10985 f
->name
= build_string (dpyinfo
->x_id_name
);
10986 f
->explicit_name
= 0;
10991 f
->explicit_name
= 1;
10992 /* use the frame's title when getting resources for this frame. */
10993 specbind (Qx_resource_name
, name
);
10996 /* Extract the window parameters from the supplied values that are
10997 needed to determine window geometry. */
11001 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
11004 /* First, try whatever font the caller has specified. */
11005 if (STRINGP (font
))
11007 tem
= Fquery_fontset (font
, Qnil
);
11009 font
= x_new_fontset (f
, SDATA (tem
));
11011 font
= x_new_font (f
, SDATA (font
));
11014 /* Try out a font which we hope has bold and italic variations. */
11015 if (!STRINGP (font
))
11016 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
11017 if (!STRINGP (font
))
11018 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
11019 if (! STRINGP (font
))
11020 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
11021 if (! STRINGP (font
))
11022 /* This was formerly the first thing tried, but it finds too many fonts
11023 and takes too long. */
11024 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
11025 /* If those didn't work, look for something which will at least work. */
11026 if (! STRINGP (font
))
11027 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
11029 if (! STRINGP (font
))
11030 font
= build_string ("fixed");
11032 x_default_parameter (f
, parms
, Qfont
, font
,
11033 "font", "Font", RES_TYPE_STRING
);
11036 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
11037 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
11039 /* This defaults to 2 in order to match xterm. We recognize either
11040 internalBorderWidth or internalBorder (which is what xterm calls
11042 if (NILP (Fassq (Qinternal_border_width
, parms
)))
11046 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
11047 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
11048 if (! EQ (value
, Qunbound
))
11049 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
11053 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
11054 "internalBorderWidth", "internalBorderWidth",
11057 /* Also do the stuff which must be set before the window exists. */
11058 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
11059 "foreground", "Foreground", RES_TYPE_STRING
);
11060 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
11061 "background", "Background", RES_TYPE_STRING
);
11062 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
11063 "pointerColor", "Foreground", RES_TYPE_STRING
);
11064 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
11065 "cursorColor", "Foreground", RES_TYPE_STRING
);
11066 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
11067 "borderColor", "BorderColor", RES_TYPE_STRING
);
11069 /* Init faces before x_default_parameter is called for scroll-bar
11070 parameters because that function calls x_set_scroll_bar_width,
11071 which calls change_frame_size, which calls Fset_window_buffer,
11072 which runs hooks, which call Fvertical_motion. At the end, we
11073 end up in init_iterator with a null face cache, which should not
11075 init_frame_faces (f
);
11077 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
11078 window_prompting
= x_figure_window_size (f
, parms
);
11080 if (window_prompting
& XNegative
)
11082 if (window_prompting
& YNegative
)
11083 f
->output_data
.x
->win_gravity
= SouthEastGravity
;
11085 f
->output_data
.x
->win_gravity
= NorthEastGravity
;
11089 if (window_prompting
& YNegative
)
11090 f
->output_data
.x
->win_gravity
= SouthWestGravity
;
11092 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11095 f
->output_data
.x
->size_hint_flags
= window_prompting
;
11097 XSetWindowAttributes attrs
;
11098 unsigned long mask
;
11101 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
11102 if (DoesSaveUnders (dpyinfo
->screen
))
11103 mask
|= CWSaveUnder
;
11105 /* Window managers look at the override-redirect flag to determine
11106 whether or net to give windows a decoration (Xlib spec, chapter
11108 attrs
.override_redirect
= True
;
11109 attrs
.save_under
= True
;
11110 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
11111 /* Arrange for getting MapNotify and UnmapNotify events. */
11112 attrs
.event_mask
= StructureNotifyMask
;
11114 = FRAME_X_WINDOW (f
)
11115 = XCreateWindow (FRAME_X_DISPLAY (f
),
11116 FRAME_X_DISPLAY_INFO (f
)->root_window
,
11117 /* x, y, width, height */
11121 CopyFromParent
, InputOutput
, CopyFromParent
,
11128 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
11129 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
11130 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
11131 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
11132 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
11133 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
11135 /* Dimensions, especially f->height, must be done via change_frame_size.
11136 Change will not be effected unless different from the current
11139 height
= f
->height
;
11141 SET_FRAME_WIDTH (f
, 0);
11142 change_frame_size (f
, height
, width
, 1, 0, 0);
11144 /* Add `tooltip' frame parameter's default value. */
11145 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
11146 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
11149 /* Set up faces after all frame parameters are known. This call
11150 also merges in face attributes specified for new frames.
11152 Frame parameters may be changed if .Xdefaults contains
11153 specifications for the default font. For example, if there is an
11154 `Emacs.default.attributeBackground: pink', the `background-color'
11155 attribute of the frame get's set, which let's the internal border
11156 of the tooltip frame appear in pink. Prevent this. */
11158 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
11160 /* Set tip_frame here, so that */
11162 call1 (Qface_set_after_frame_default
, frame
);
11164 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
11165 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
11173 /* It is now ok to make the frame official even if we get an error
11174 below. And the frame needs to be on Vframe_list or making it
11175 visible won't work. */
11176 Vframe_list
= Fcons (frame
, Vframe_list
);
11178 /* Now that the frame is official, it counts as a reference to
11180 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
11182 /* Setting attributes of faces of the tooltip frame from resources
11183 and similar will increment face_change_count, which leads to the
11184 clearing of all current matrices. Since this isn't necessary
11185 here, avoid it by resetting face_change_count to the value it
11186 had before we created the tip frame. */
11187 face_change_count
= face_change_count_before
;
11189 /* Discard the unwind_protect. */
11190 return unbind_to (count
, frame
);
11194 /* Compute where to display tip frame F. PARMS is the list of frame
11195 parameters for F. DX and DY are specified offsets from the current
11196 location of the mouse. WIDTH and HEIGHT are the width and height
11197 of the tooltip. Return coordinates relative to the root window of
11198 the display in *ROOT_X, and *ROOT_Y. */
11201 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
11203 Lisp_Object parms
, dx
, dy
;
11205 int *root_x
, *root_y
;
11207 Lisp_Object left
, top
;
11209 Window root
, child
;
11212 /* User-specified position? */
11213 left
= Fcdr (Fassq (Qleft
, parms
));
11214 top
= Fcdr (Fassq (Qtop
, parms
));
11216 /* Move the tooltip window where the mouse pointer is. Resize and
11218 if (!INTEGERP (left
) || !INTEGERP (top
))
11221 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
11222 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
11226 if (INTEGERP (top
))
11227 *root_y
= XINT (top
);
11228 else if (*root_y
+ XINT (dy
) - height
< 0)
11229 *root_y
-= XINT (dy
);
11233 *root_y
+= XINT (dy
);
11236 if (INTEGERP (left
))
11237 *root_x
= XINT (left
);
11238 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
11239 /* It fits to the right of the pointer. */
11240 *root_x
+= XINT (dx
);
11241 else if (width
+ XINT (dx
) <= *root_x
)
11242 /* It fits to the left of the pointer. */
11243 *root_x
-= width
+ XINT (dx
);
11245 /* Put it left-justified on the screen--it ought to fit that way. */
11250 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
11251 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
11252 A tooltip window is a small X window displaying a string.
11254 FRAME nil or omitted means use the selected frame.
11256 PARMS is an optional list of frame parameters which can be used to
11257 change the tooltip's appearance.
11259 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
11260 means use the default timeout of 5 seconds.
11262 If the list of frame parameters PARAMS contains a `left' parameters,
11263 the tooltip is displayed at that x-position. Otherwise it is
11264 displayed at the mouse position, with offset DX added (default is 5 if
11265 DX isn't specified). Likewise for the y-position; if a `top' frame
11266 parameter is specified, it determines the y-position of the tooltip
11267 window, otherwise it is displayed at the mouse position, with offset
11268 DY added (default is -10).
11270 A tooltip's maximum size is specified by `x-max-tooltip-size'.
11271 Text larger than the specified size is clipped. */)
11272 (string
, frame
, parms
, timeout
, dx
, dy
)
11273 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
11277 int root_x
, root_y
;
11278 struct buffer
*old_buffer
;
11279 struct text_pos pos
;
11280 int i
, width
, height
;
11281 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
11282 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
11283 int count
= SPECPDL_INDEX ();
11285 specbind (Qinhibit_redisplay
, Qt
);
11287 GCPRO4 (string
, parms
, frame
, timeout
);
11289 CHECK_STRING (string
);
11290 f
= check_x_frame (frame
);
11291 if (NILP (timeout
))
11292 timeout
= make_number (5);
11294 CHECK_NATNUM (timeout
);
11297 dx
= make_number (5);
11302 dy
= make_number (-10);
11306 if (NILP (last_show_tip_args
))
11307 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
11309 if (!NILP (tip_frame
))
11311 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
11312 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
11313 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
11315 if (EQ (frame
, last_frame
)
11316 && !NILP (Fequal (last_string
, string
))
11317 && !NILP (Fequal (last_parms
, parms
)))
11319 struct frame
*f
= XFRAME (tip_frame
);
11321 /* Only DX and DY have changed. */
11322 if (!NILP (tip_timer
))
11324 Lisp_Object timer
= tip_timer
;
11326 call1 (Qcancel_timer
, timer
);
11330 compute_tip_xy (f
, parms
, dx
, dy
, PIXEL_WIDTH (f
),
11331 PIXEL_HEIGHT (f
), &root_x
, &root_y
);
11332 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11339 /* Hide a previous tip, if any. */
11342 ASET (last_show_tip_args
, 0, string
);
11343 ASET (last_show_tip_args
, 1, frame
);
11344 ASET (last_show_tip_args
, 2, parms
);
11346 /* Add default values to frame parameters. */
11347 if (NILP (Fassq (Qname
, parms
)))
11348 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
11349 if (NILP (Fassq (Qinternal_border_width
, parms
)))
11350 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
11351 if (NILP (Fassq (Qborder_width
, parms
)))
11352 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
11353 if (NILP (Fassq (Qborder_color
, parms
)))
11354 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
11355 if (NILP (Fassq (Qbackground_color
, parms
)))
11356 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
11359 /* Create a frame for the tooltip, and record it in the global
11360 variable tip_frame. */
11361 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
11362 f
= XFRAME (frame
);
11364 /* Set up the frame's root window. */
11365 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
11366 w
->left
= w
->top
= make_number (0);
11368 if (CONSP (Vx_max_tooltip_size
)
11369 && INTEGERP (XCAR (Vx_max_tooltip_size
))
11370 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
11371 && INTEGERP (XCDR (Vx_max_tooltip_size
))
11372 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
11374 w
->width
= XCAR (Vx_max_tooltip_size
);
11375 w
->height
= XCDR (Vx_max_tooltip_size
);
11379 w
->width
= make_number (80);
11380 w
->height
= make_number (40);
11383 f
->window_width
= XINT (w
->width
);
11385 w
->pseudo_window_p
= 1;
11387 /* Display the tooltip text in a temporary buffer. */
11388 old_buffer
= current_buffer
;
11389 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
11390 current_buffer
->truncate_lines
= Qnil
;
11391 clear_glyph_matrix (w
->desired_matrix
);
11392 clear_glyph_matrix (w
->current_matrix
);
11393 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
11394 try_window (FRAME_ROOT_WINDOW (f
), pos
);
11396 /* Compute width and height of the tooltip. */
11397 width
= height
= 0;
11398 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
11400 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
11401 struct glyph
*last
;
11404 /* Stop at the first empty row at the end. */
11405 if (!row
->enabled_p
|| !row
->displays_text_p
)
11408 /* Let the row go over the full width of the frame. */
11409 row
->full_width_p
= 1;
11411 /* There's a glyph at the end of rows that is used to place
11412 the cursor there. Don't include the width of this glyph. */
11413 if (row
->used
[TEXT_AREA
])
11415 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
11416 row_width
= row
->pixel_width
- last
->pixel_width
;
11419 row_width
= row
->pixel_width
;
11421 height
+= row
->height
;
11422 width
= max (width
, row_width
);
11425 /* Add the frame's internal border to the width and height the X
11426 window should have. */
11427 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
11428 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
11430 /* Move the tooltip window where the mouse pointer is. Resize and
11432 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
11435 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11436 root_x
, root_y
, width
, height
);
11437 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11440 /* Draw into the window. */
11441 w
->must_be_updated_p
= 1;
11442 update_single_window (w
, 1);
11444 /* Restore original current buffer. */
11445 set_buffer_internal_1 (old_buffer
);
11446 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
11449 /* Let the tip disappear after timeout seconds. */
11450 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
11451 intern ("x-hide-tip"));
11454 return unbind_to (count
, Qnil
);
11458 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
11459 doc
: /* Hide the current tooltip window, if there is any.
11460 Value is t if tooltip was open, nil otherwise. */)
11464 Lisp_Object deleted
, frame
, timer
;
11465 struct gcpro gcpro1
, gcpro2
;
11467 /* Return quickly if nothing to do. */
11468 if (NILP (tip_timer
) && NILP (tip_frame
))
11473 GCPRO2 (frame
, timer
);
11474 tip_frame
= tip_timer
= deleted
= Qnil
;
11476 count
= SPECPDL_INDEX ();
11477 specbind (Qinhibit_redisplay
, Qt
);
11478 specbind (Qinhibit_quit
, Qt
);
11481 call1 (Qcancel_timer
, timer
);
11483 if (FRAMEP (frame
))
11485 Fdelete_frame (frame
, Qnil
);
11489 /* Bloodcurdling hack alert: The Lucid menu bar widget's
11490 redisplay procedure is not called when a tip frame over menu
11491 items is unmapped. Redisplay the menu manually... */
11493 struct frame
*f
= SELECTED_FRAME ();
11494 Widget w
= f
->output_data
.x
->menubar_widget
;
11495 extern void xlwmenu_redisplay
P_ ((Widget
));
11497 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
11501 xlwmenu_redisplay (w
);
11505 #endif /* USE_LUCID */
11509 return unbind_to (count
, deleted
);
11514 /***********************************************************************
11515 File selection dialog
11516 ***********************************************************************/
11520 /* Callback for "OK" and "Cancel" on file selection dialog. */
11523 file_dialog_cb (widget
, client_data
, call_data
)
11525 XtPointer call_data
, client_data
;
11527 int *result
= (int *) client_data
;
11528 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
11529 *result
= cb
->reason
;
11533 /* Callback for unmapping a file selection dialog. This is used to
11534 capture the case where a dialog is closed via a window manager's
11535 closer button, for example. Using a XmNdestroyCallback didn't work
11539 file_dialog_unmap_cb (widget
, client_data
, call_data
)
11541 XtPointer call_data
, client_data
;
11543 int *result
= (int *) client_data
;
11544 *result
= XmCR_CANCEL
;
11548 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
11549 doc
: /* Read file name, prompting with PROMPT in directory DIR.
11550 Use a file selection dialog.
11551 Select DEFAULT-FILENAME in the dialog's file selection box, if
11552 specified. Don't let the user enter a file name in the file
11553 selection dialog's entry field, if MUSTMATCH is non-nil. */)
11554 (prompt
, dir
, default_filename
, mustmatch
)
11555 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
11558 struct frame
*f
= SELECTED_FRAME ();
11559 Lisp_Object file
= Qnil
;
11560 Widget dialog
, text
, list
, help
;
11563 extern XtAppContext Xt_app_con
;
11564 XmString dir_xmstring
, pattern_xmstring
;
11565 int count
= SPECPDL_INDEX ();
11566 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
11568 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
11569 CHECK_STRING (prompt
);
11570 CHECK_STRING (dir
);
11572 /* Prevent redisplay. */
11573 specbind (Qinhibit_redisplay
, Qt
);
11577 /* Create the dialog with PROMPT as title, using DIR as initial
11578 directory and using "*" as pattern. */
11579 dir
= Fexpand_file_name (dir
, Qnil
);
11580 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
11581 pattern_xmstring
= XmStringCreateLocalized ("*");
11583 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
11584 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
11585 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
11586 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
11587 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
11588 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
11590 XmStringFree (dir_xmstring
);
11591 XmStringFree (pattern_xmstring
);
11593 /* Add callbacks for OK and Cancel. */
11594 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
11595 (XtPointer
) &result
);
11596 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
11597 (XtPointer
) &result
);
11598 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
11599 (XtPointer
) &result
);
11601 /* Disable the help button since we can't display help. */
11602 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
11603 XtSetSensitive (help
, False
);
11605 /* Mark OK button as default. */
11606 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
11607 XmNshowAsDefault
, True
, NULL
);
11609 /* If MUSTMATCH is non-nil, disable the file entry field of the
11610 dialog, so that the user must select a file from the files list
11611 box. We can't remove it because we wouldn't have a way to get at
11612 the result file name, then. */
11613 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
11614 if (!NILP (mustmatch
))
11617 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
11618 XtSetSensitive (text
, False
);
11619 XtSetSensitive (label
, False
);
11622 /* Manage the dialog, so that list boxes get filled. */
11623 XtManageChild (dialog
);
11625 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
11626 must include the path for this to work. */
11627 list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
11628 if (STRINGP (default_filename
))
11630 XmString default_xmstring
;
11634 = XmStringCreateLocalized (SDATA (default_filename
));
11636 if (!XmListItemExists (list
, default_xmstring
))
11638 /* Add a new item if DEFAULT_FILENAME is not in the list. */
11639 XmListAddItem (list
, default_xmstring
, 0);
11643 item_pos
= XmListItemPos (list
, default_xmstring
);
11644 XmStringFree (default_xmstring
);
11646 /* Select the item and scroll it into view. */
11647 XmListSelectPos (list
, item_pos
, True
);
11648 XmListSetPos (list
, item_pos
);
11651 /* Process events until the user presses Cancel or OK. Block
11652 and unblock input here so that we get a chance of processing
11656 while (result
== 0)
11659 XtAppProcessEvent (Xt_app_con
, XtIMAll
);
11664 /* Get the result. */
11665 if (result
== XmCR_OK
)
11670 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
11671 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
11672 XmStringFree (text
);
11673 file
= build_string (data
);
11680 XtUnmanageChild (dialog
);
11681 XtDestroyWidget (dialog
);
11685 /* Make "Cancel" equivalent to C-g. */
11687 Fsignal (Qquit
, Qnil
);
11689 return unbind_to (count
, file
);
11692 #endif /* USE_MOTIF */
11696 /***********************************************************************
11698 ***********************************************************************/
11700 #ifdef HAVE_XKBGETKEYBOARD
11701 #include <X11/XKBlib.h>
11702 #include <X11/keysym.h>
11705 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
11706 Sx_backspace_delete_keys_p
, 0, 1, 0,
11707 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
11708 FRAME nil means use the selected frame.
11709 Value is t if we know that both keys are present, and are mapped to the
11710 usual X keysyms. */)
11714 #ifdef HAVE_XKBGETKEYBOARD
11716 struct frame
*f
= check_x_frame (frame
);
11717 Display
*dpy
= FRAME_X_DISPLAY (f
);
11718 Lisp_Object have_keys
;
11719 int major
, minor
, op
, event
, error
;
11723 /* Check library version in case we're dynamically linked. */
11724 major
= XkbMajorVersion
;
11725 minor
= XkbMinorVersion
;
11726 if (!XkbLibraryVersion (&major
, &minor
))
11732 /* Check that the server supports XKB. */
11733 major
= XkbMajorVersion
;
11734 minor
= XkbMinorVersion
;
11735 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
11742 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
11745 int delete_keycode
= 0, backspace_keycode
= 0, i
;
11747 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
11749 for (i
= kb
->min_key_code
;
11750 (i
< kb
->max_key_code
11751 && (delete_keycode
== 0 || backspace_keycode
== 0));
11754 /* The XKB symbolic key names can be seen most easily in
11755 the PS file generated by `xkbprint -label name
11757 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
11758 delete_keycode
= i
;
11759 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
11760 backspace_keycode
= i
;
11763 XkbFreeNames (kb
, 0, True
);
11766 XkbFreeClientMap (kb
, 0, True
);
11769 && backspace_keycode
11770 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
11771 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
11776 #else /* not HAVE_XKBGETKEYBOARD */
11778 #endif /* not HAVE_XKBGETKEYBOARD */
11783 /***********************************************************************
11785 ***********************************************************************/
11790 /* This is zero if not using X windows. */
11793 /* The section below is built by the lisp expression at the top of the file,
11794 just above where these variables are declared. */
11795 /*&&& init symbols here &&&*/
11796 Qauto_raise
= intern ("auto-raise");
11797 staticpro (&Qauto_raise
);
11798 Qauto_lower
= intern ("auto-lower");
11799 staticpro (&Qauto_lower
);
11800 Qborder_color
= intern ("border-color");
11801 staticpro (&Qborder_color
);
11802 Qborder_width
= intern ("border-width");
11803 staticpro (&Qborder_width
);
11804 Qcursor_color
= intern ("cursor-color");
11805 staticpro (&Qcursor_color
);
11806 Qcursor_type
= intern ("cursor-type");
11807 staticpro (&Qcursor_type
);
11808 Qgeometry
= intern ("geometry");
11809 staticpro (&Qgeometry
);
11810 Qicon_left
= intern ("icon-left");
11811 staticpro (&Qicon_left
);
11812 Qicon_top
= intern ("icon-top");
11813 staticpro (&Qicon_top
);
11814 Qicon_type
= intern ("icon-type");
11815 staticpro (&Qicon_type
);
11816 Qicon_name
= intern ("icon-name");
11817 staticpro (&Qicon_name
);
11818 Qinternal_border_width
= intern ("internal-border-width");
11819 staticpro (&Qinternal_border_width
);
11820 Qleft
= intern ("left");
11821 staticpro (&Qleft
);
11822 Qright
= intern ("right");
11823 staticpro (&Qright
);
11824 Qmouse_color
= intern ("mouse-color");
11825 staticpro (&Qmouse_color
);
11826 Qnone
= intern ("none");
11827 staticpro (&Qnone
);
11828 Qparent_id
= intern ("parent-id");
11829 staticpro (&Qparent_id
);
11830 Qscroll_bar_width
= intern ("scroll-bar-width");
11831 staticpro (&Qscroll_bar_width
);
11832 Qsuppress_icon
= intern ("suppress-icon");
11833 staticpro (&Qsuppress_icon
);
11834 Qundefined_color
= intern ("undefined-color");
11835 staticpro (&Qundefined_color
);
11836 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
11837 staticpro (&Qvertical_scroll_bars
);
11838 Qvisibility
= intern ("visibility");
11839 staticpro (&Qvisibility
);
11840 Qwindow_id
= intern ("window-id");
11841 staticpro (&Qwindow_id
);
11842 Qouter_window_id
= intern ("outer-window-id");
11843 staticpro (&Qouter_window_id
);
11844 Qx_frame_parameter
= intern ("x-frame-parameter");
11845 staticpro (&Qx_frame_parameter
);
11846 Qx_resource_name
= intern ("x-resource-name");
11847 staticpro (&Qx_resource_name
);
11848 Quser_position
= intern ("user-position");
11849 staticpro (&Quser_position
);
11850 Quser_size
= intern ("user-size");
11851 staticpro (&Quser_size
);
11852 Qscroll_bar_foreground
= intern ("scroll-bar-foreground");
11853 staticpro (&Qscroll_bar_foreground
);
11854 Qscroll_bar_background
= intern ("scroll-bar-background");
11855 staticpro (&Qscroll_bar_background
);
11856 Qscreen_gamma
= intern ("screen-gamma");
11857 staticpro (&Qscreen_gamma
);
11858 Qline_spacing
= intern ("line-spacing");
11859 staticpro (&Qline_spacing
);
11860 Qcenter
= intern ("center");
11861 staticpro (&Qcenter
);
11862 Qcompound_text
= intern ("compound-text");
11863 staticpro (&Qcompound_text
);
11864 Qcancel_timer
= intern ("cancel-timer");
11865 staticpro (&Qcancel_timer
);
11866 Qwait_for_wm
= intern ("wait-for-wm");
11867 staticpro (&Qwait_for_wm
);
11868 Qfullscreen
= intern ("fullscreen");
11869 staticpro (&Qfullscreen
);
11870 Qfullwidth
= intern ("fullwidth");
11871 staticpro (&Qfullwidth
);
11872 Qfullheight
= intern ("fullheight");
11873 staticpro (&Qfullheight
);
11874 Qfullboth
= intern ("fullboth");
11875 staticpro (&Qfullboth
);
11876 /* This is the end of symbol initialization. */
11878 /* Text property `display' should be nonsticky by default. */
11879 Vtext_property_default_nonsticky
11880 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
11883 Qlaplace
= intern ("laplace");
11884 staticpro (&Qlaplace
);
11885 Qemboss
= intern ("emboss");
11886 staticpro (&Qemboss
);
11887 Qedge_detection
= intern ("edge-detection");
11888 staticpro (&Qedge_detection
);
11889 Qheuristic
= intern ("heuristic");
11890 staticpro (&Qheuristic
);
11891 QCmatrix
= intern (":matrix");
11892 staticpro (&QCmatrix
);
11893 QCcolor_adjustment
= intern (":color-adjustment");
11894 staticpro (&QCcolor_adjustment
);
11895 QCmask
= intern (":mask");
11896 staticpro (&QCmask
);
11898 Qface_set_after_frame_default
= intern ("face-set-after-frame-default");
11899 staticpro (&Qface_set_after_frame_default
);
11901 Fput (Qundefined_color
, Qerror_conditions
,
11902 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
11903 Fput (Qundefined_color
, Qerror_message
,
11904 build_string ("Undefined color"));
11906 init_x_parm_symbols ();
11908 DEFVAR_BOOL ("cross-disabled-images", &cross_disabled_images
,
11909 doc
: /* Non-nil means always draw a cross over disabled images.
11910 Disabled images are those having an `:conversion disabled' property.
11911 A cross is always drawn on black & white displays. */);
11912 cross_disabled_images
= 0;
11914 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
11915 doc
: /* List of directories to search for bitmap files for X. */);
11916 Vx_bitmap_file_path
= decode_env_path ((char *) 0, PATH_BITMAPS
);
11918 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
11919 doc
: /* The shape of the pointer when over text.
11920 Changing the value does not affect existing frames
11921 unless you set the mouse color. */);
11922 Vx_pointer_shape
= Qnil
;
11924 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
11925 doc
: /* The name Emacs uses to look up X resources.
11926 `x-get-resource' uses this as the first component of the instance name
11927 when requesting resource values.
11928 Emacs initially sets `x-resource-name' to the name under which Emacs
11929 was invoked, or to the value specified with the `-name' or `-rn'
11930 switches, if present.
11932 It may be useful to bind this variable locally around a call
11933 to `x-get-resource'. See also the variable `x-resource-class'. */);
11934 Vx_resource_name
= Qnil
;
11936 DEFVAR_LISP ("x-resource-class", &Vx_resource_class
,
11937 doc
: /* The class Emacs uses to look up X resources.
11938 `x-get-resource' uses this as the first component of the instance class
11939 when requesting resource values.
11941 Emacs initially sets `x-resource-class' to "Emacs".
11943 Setting this variable permanently is not a reasonable thing to do,
11944 but binding this variable locally around a call to `x-get-resource'
11945 is a reasonable practice. See also the variable `x-resource-name'. */);
11946 Vx_resource_class
= build_string (EMACS_CLASS
);
11948 #if 0 /* This doesn't really do anything. */
11949 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
11950 doc
: /* The shape of the pointer when not over text.
11951 This variable takes effect when you create a new frame
11952 or when you set the mouse color. */);
11954 Vx_nontext_pointer_shape
= Qnil
;
11956 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
11957 doc
: /* The shape of the pointer when Emacs is busy.
11958 This variable takes effect when you create a new frame
11959 or when you set the mouse color. */);
11960 Vx_hourglass_pointer_shape
= Qnil
;
11962 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
11963 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
11964 display_hourglass_p
= 1;
11966 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
11967 doc
: /* *Seconds to wait before displaying an hourglass pointer.
11968 Value must be an integer or float. */);
11969 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
11971 #if 0 /* This doesn't really do anything. */
11972 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
11973 doc
: /* The shape of the pointer when over the mode line.
11974 This variable takes effect when you create a new frame
11975 or when you set the mouse color. */);
11977 Vx_mode_pointer_shape
= Qnil
;
11979 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
11980 &Vx_sensitive_text_pointer_shape
,
11981 doc
: /* The shape of the pointer when over mouse-sensitive text.
11982 This variable takes effect when you create a new frame
11983 or when you set the mouse color. */);
11984 Vx_sensitive_text_pointer_shape
= Qnil
;
11986 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
11987 &Vx_window_horizontal_drag_shape
,
11988 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
11989 This variable takes effect when you create a new frame
11990 or when you set the mouse color. */);
11991 Vx_window_horizontal_drag_shape
= Qnil
;
11993 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
11994 doc
: /* A string indicating the foreground color of the cursor box. */);
11995 Vx_cursor_fore_pixel
= Qnil
;
11997 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
11998 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
11999 Text larger than this is clipped. */);
12000 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
12002 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
12003 doc
: /* Non-nil if no X window manager is in use.
12004 Emacs doesn't try to figure this out; this is always nil
12005 unless you set it to something else. */);
12006 /* We don't have any way to find this out, so set it to nil
12007 and maybe the user would like to set it to t. */
12008 Vx_no_window_manager
= Qnil
;
12010 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
12011 &Vx_pixel_size_width_font_regexp
,
12012 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
12014 Since Emacs gets width of a font matching with this regexp from
12015 PIXEL_SIZE field of the name, font finding mechanism gets faster for
12016 such a font. This is especially effective for such large fonts as
12017 Chinese, Japanese, and Korean. */);
12018 Vx_pixel_size_width_font_regexp
= Qnil
;
12020 DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay
,
12021 doc
: /* Time after which cached images are removed from the cache.
12022 When an image has not been displayed this many seconds, remove it
12023 from the image cache. Value must be an integer or nil with nil
12024 meaning don't clear the cache. */);
12025 Vimage_cache_eviction_delay
= make_number (30 * 60);
12027 #ifdef USE_X_TOOLKIT
12028 Fprovide (intern ("x-toolkit"), Qnil
);
12030 Fprovide (intern ("motif"), Qnil
);
12032 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
12033 doc
: /* Version info for LessTif/Motif. */);
12034 Vmotif_version_string
= build_string (XmVERSION_STRING
);
12035 #endif /* USE_MOTIF */
12036 #endif /* USE_X_TOOLKIT */
12038 defsubr (&Sx_get_resource
);
12040 /* X window properties. */
12041 defsubr (&Sx_change_window_property
);
12042 defsubr (&Sx_delete_window_property
);
12043 defsubr (&Sx_window_property
);
12045 defsubr (&Sxw_display_color_p
);
12046 defsubr (&Sx_display_grayscale_p
);
12047 defsubr (&Sxw_color_defined_p
);
12048 defsubr (&Sxw_color_values
);
12049 defsubr (&Sx_server_max_request_size
);
12050 defsubr (&Sx_server_vendor
);
12051 defsubr (&Sx_server_version
);
12052 defsubr (&Sx_display_pixel_width
);
12053 defsubr (&Sx_display_pixel_height
);
12054 defsubr (&Sx_display_mm_width
);
12055 defsubr (&Sx_display_mm_height
);
12056 defsubr (&Sx_display_screens
);
12057 defsubr (&Sx_display_planes
);
12058 defsubr (&Sx_display_color_cells
);
12059 defsubr (&Sx_display_visual_class
);
12060 defsubr (&Sx_display_backing_store
);
12061 defsubr (&Sx_display_save_under
);
12062 defsubr (&Sx_parse_geometry
);
12063 defsubr (&Sx_create_frame
);
12064 defsubr (&Sx_open_connection
);
12065 defsubr (&Sx_close_connection
);
12066 defsubr (&Sx_display_list
);
12067 defsubr (&Sx_synchronize
);
12068 defsubr (&Sx_focus_frame
);
12069 defsubr (&Sx_backspace_delete_keys_p
);
12071 /* Setting callback functions for fontset handler. */
12072 get_font_info_func
= x_get_font_info
;
12074 #if 0 /* This function pointer doesn't seem to be used anywhere.
12075 And the pointer assigned has the wrong type, anyway. */
12076 list_fonts_func
= x_list_fonts
;
12079 load_font_func
= x_load_font
;
12080 find_ccl_program_func
= x_find_ccl_program
;
12081 query_font_func
= x_query_font
;
12082 set_frame_fontset_func
= x_set_font
;
12083 check_window_system_func
= check_x
;
12086 Qxbm
= intern ("xbm");
12088 QCconversion
= intern (":conversion");
12089 staticpro (&QCconversion
);
12090 QCheuristic_mask
= intern (":heuristic-mask");
12091 staticpro (&QCheuristic_mask
);
12092 QCcolor_symbols
= intern (":color-symbols");
12093 staticpro (&QCcolor_symbols
);
12094 QCascent
= intern (":ascent");
12095 staticpro (&QCascent
);
12096 QCmargin
= intern (":margin");
12097 staticpro (&QCmargin
);
12098 QCrelief
= intern (":relief");
12099 staticpro (&QCrelief
);
12100 Qpostscript
= intern ("postscript");
12101 staticpro (&Qpostscript
);
12102 QCloader
= intern (":loader");
12103 staticpro (&QCloader
);
12104 QCbounding_box
= intern (":bounding-box");
12105 staticpro (&QCbounding_box
);
12106 QCpt_width
= intern (":pt-width");
12107 staticpro (&QCpt_width
);
12108 QCpt_height
= intern (":pt-height");
12109 staticpro (&QCpt_height
);
12110 QCindex
= intern (":index");
12111 staticpro (&QCindex
);
12112 Qpbm
= intern ("pbm");
12116 Qxpm
= intern ("xpm");
12121 Qjpeg
= intern ("jpeg");
12122 staticpro (&Qjpeg
);
12126 Qtiff
= intern ("tiff");
12127 staticpro (&Qtiff
);
12131 Qgif
= intern ("gif");
12136 Qpng
= intern ("png");
12140 defsubr (&Sclear_image_cache
);
12141 defsubr (&Simage_size
);
12142 defsubr (&Simage_mask_p
);
12144 hourglass_atimer
= NULL
;
12145 hourglass_shown_p
= 0;
12147 defsubr (&Sx_show_tip
);
12148 defsubr (&Sx_hide_tip
);
12150 staticpro (&tip_timer
);
12152 staticpro (&tip_frame
);
12154 last_show_tip_args
= Qnil
;
12155 staticpro (&last_show_tip_args
);
12158 defsubr (&Sx_file_dialog
);
12166 image_types
= NULL
;
12167 Vimage_types
= Qnil
;
12169 define_image_type (&xbm_type
);
12170 define_image_type (&gs_type
);
12171 define_image_type (&pbm_type
);
12174 define_image_type (&xpm_type
);
12178 define_image_type (&jpeg_type
);
12182 define_image_type (&tiff_type
);
12186 define_image_type (&gif_type
);
12190 define_image_type (&png_type
);
12194 #endif /* HAVE_X_WINDOWS */